diff --git a/assets/ai_scripts/john.lua b/assets/ai_scripts/john.lua index 70e28041..2e3f525d 100644 --- a/assets/ai_scripts/john.lua +++ b/assets/ai_scripts/john.lua @@ -111,8 +111,10 @@ function getPathToSafeSpace(player) print("run to") print(res.x) print(res.y) - local path = getPath(player.x, player.y, res.x, res.y) - return path + + local p = {player} + table.insert(p, res) + return p end LastTarget = nil @@ -137,10 +139,10 @@ function Update() print(player.x) print(player.y) local player = getPlayerRound(); - local dangerMap = getDanger() - --PrintMap(dangerMap, 16, 16) if getDangerLevelPlayer() then print("INDANGER") + local dangerMap = getDanger() + PrintMap(dangerMap, 17, 17) local path = getPathToSafeSpace(player) if #path >= 2 then print("path found") diff --git a/sources/Map/LuaMap.cpp b/sources/Map/LuaMap.cpp index 2af1cfed..a52d98ea 100644 --- a/sources/Map/LuaMap.cpp +++ b/sources/Map/LuaMap.cpp @@ -139,6 +139,44 @@ namespace BBM Vector2f LuaMap::findSafeSpace(void) const { + int d = 1; + std::vector> distance(17, std::vector(17, -1)); + std::vector> direction(17, std::vector(17, -1)); + // -1 is empty, -2 is blocked + for (int i = 0; i < 17; i++) + for (int j = 0; j < 17; j++) + distance[i][j] = _map[i][j] == 0 ? -1 : -2; + distance[_roundedPlayer.y][_roundedPlayer.x] = 0; + for (int i = 0; i < 4; i++) { + Vector2f pos = _roundedPlayer + _dirs[i]; + if (pos.x < 0 || pos.x > 16 || pos.y < 0 || pos.y > 16) + continue; + distance[pos.y][pos.x] = 1; + direction[pos.y][pos.x] = i; + } + int finalDir = -1; + while (d < 6) { + for (int i = 0; i < 17; i++) { + for (int j = 0; j < 17; j++) { + if (distance[j][i] != d) + continue; + auto currentDir = direction[j][i]; + + for (int k = 0; k < 4; k++) { + Vector2f pos = Vector2f(i, j) + _dirs[k]; + if (pos.x < 0 || pos.x > 16 || pos.y < 0 || pos.y > 16) + continue; + if (distance[pos.y][pos.x] != -1) + continue; + if (_danger[pos.y][pos.x] == 0) + return _roundedPlayer + _dirs[currentDir]; + direction[pos.y][pos.x] = currentDir; + distance[pos.y][pos.x] = d + 1; + } + } + } + d++; + } return _roundedPlayer; } @@ -146,7 +184,7 @@ namespace BBM { LuaG::State state(L); int index = 1; - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); state.newTable(); for (int i = 0; i < 17; i++) { state.push(index++); @@ -166,7 +204,7 @@ namespace BBM { LuaG::State state(L); int index = 1; - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); state.newTable(); for (int i = 0; i < 17; i++) { state.push(index++); @@ -189,7 +227,7 @@ namespace BBM auto x2 = state.getNumber(-2); auto y1 = state.getNumber(-3); auto x1 = state.getNumber(-4); - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); Vector2f fst(x1, y1); Vector2f snd(x2, y2); auto path = map->pathfind(fst, snd); @@ -212,7 +250,7 @@ namespace BBM int LuaMap::getPlayer(lua_State *L) { LuaG::State state(L); - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); state.newTable(); state.push("x"); state.push(map->_player.x); @@ -226,7 +264,7 @@ namespace BBM int LuaMap::getPlayerRound(lua_State *L) { LuaG::State state(L); - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); state.newTable(); state.push("x"); state.push(map->_roundedPlayer.x); @@ -240,7 +278,7 @@ namespace BBM int LuaMap::getClosestSafeSpace(lua_State *L) { LuaG::State state(L); - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); Vector2f closest = map->findSafeSpace(); state.newTable(); state.push("x"); @@ -255,7 +293,7 @@ namespace BBM int LuaMap::getDangerLevelPlayer(lua_State *L) { LuaG::State state(L); - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); lua_pushboolean(L, map->_danger[map->_roundedPlayer.y][map->_roundedPlayer.x] > 0); return 1; } @@ -265,7 +303,7 @@ namespace BBM LuaG::State state(L); auto y = state.getNumber(-1); auto x = state.getNumber(-2); - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); state.push(map->_danger[y][x]); return 1; } @@ -275,7 +313,7 @@ namespace BBM LuaG::State state(L); auto y = state.getNumber(-1); auto x = state.getNumber(-2); - const LuaMap *map = (const LuaMap *) state.getPointer(state.getFirstUpValueIdx()); + const LuaMap *map = static_cast(state.getPointer(state.getFirstUpValueIdx())); state.push(map->_map[y][x]); return 1; } diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index 054e4574..ecc14a12 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -46,7 +46,9 @@ namespace BBM int dangerLevel = std::chrono::duration_cast(ringIn).count(); if (dangerLevel == 0) dangerLevel = 1; + radius++; _luamap._map[bombPos.z][bombPos.x] = 10; + std::cout << "bomb" << bombPos << std::endl << std::flush; _luamap._danger[bombPos.z][bombPos.x] = dangerLevel; for (auto i = 1; i < radius; i++) { pos = bombPos - Vector3f(i, 0, 0);