diff --git a/assets/ai_scripts/john.lua b/assets/ai_scripts/john.lua index 9f00b788..43a5deff 100644 --- a/assets/ai_scripts/john.lua +++ b/assets/ai_scripts/john.lua @@ -132,12 +132,10 @@ end ------ Update function Update(mapinfo) log("NEW FRAME") - x = getDanger() - p = getPath(0, 0, 16, 16); - for i, c in ipairs(p) do - print(c.x) - print(c.y) - end + local dangerMap = getDanger() + local path = getPath(0, 0, 16, 16); + local player = getPlayer(); + local playerRound = getPlayerRound(); ---- sjould send Map Danger and MaxX MaxY --MaxX = 0 --MaxY = 0 diff --git a/sources/Map/LuaMap.cpp b/sources/Map/LuaMap.cpp index 868eb01c..f7ce19d9 100644 --- a/sources/Map/LuaMap.cpp +++ b/sources/Map/LuaMap.cpp @@ -192,6 +192,34 @@ namespace BBM return 1; } + int LuaMap::getPlayer(lua_State *L) + { + LuaG::State state(L); + const LuaMap *map = (const LuaMap *) lua_topointer(L, lua_upvalueindex(1)); + lua_newtable(L); + lua_pushstring(L, "x"); + lua_pushnumber(L, map->_player.x); + lua_settable(L, -3); + lua_pushstring(L, "y"); + lua_pushnumber(L, map->_player.y); + lua_settable(L, -3); + return 1; + } + + int LuaMap::getPlayerRound(lua_State *L) + { + LuaG::State state(L); + const LuaMap *map = (const LuaMap *) lua_topointer(L, lua_upvalueindex(1)); + lua_newtable(L); + lua_pushstring(L, "x"); + lua_pushnumber(L, map->_roundedPlayer.x); + lua_settable(L, -3); + lua_pushstring(L, "y"); + lua_pushnumber(L, map->_roundedPlayer.y); + lua_settable(L, -3); + return 1; + } + int LuaMap::getClosestSafeSpace(lua_State *L) { LuaG::State state(L); diff --git a/sources/Map/LuaMap.hpp b/sources/Map/LuaMap.hpp index 318b5864..c2da5e27 100644 --- a/sources/Map/LuaMap.hpp +++ b/sources/Map/LuaMap.hpp @@ -39,6 +39,12 @@ namespace BBM //! @brief get array of nodes, path from a to b static int getPath(lua_State *L); + //! @brief get player pos + static int getPlayer(lua_State *L); + + //! @brief get rounded player pos + static int getPlayerRound(lua_State *L); + //! @brief get closest safe space of player static int getClosestSafeSpace(lua_State *L); diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index b533ab14..ca659d4c 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -83,6 +83,14 @@ namespace BBM lua_pushlightuserdata(state.getState(), &_luamap); lua_pushcclosure(state.getState(), LuaMap::getPath, 1); lua_setglobal(state.getState(), "getPath"); + + lua_pushlightuserdata(state.getState(), &_luamap); + lua_pushcclosure(state.getState(), LuaMap::getPlayer, 1); + lua_setglobal(state.getState(), "getPlayer"); + + lua_pushlightuserdata(state.getState(), &_luamap); + lua_pushcclosure(state.getState(), LuaMap::getPlayerRound, 1); + lua_setglobal(state.getState(), "getPlayerRound"); } void IAControllableSystem::onFixedUpdate(WAL::ViewEntity &entity)