From 341e9cd302d0a9a4413f317dec1ab424b34f7171 Mon Sep 17 00:00:00 2001 From: Bluub Date: Fri, 18 Jun 2021 21:34:54 +0200 Subject: [PATCH] running on top when near a bomb --- assets/ai_scripts/john.lua | 9 +++++++-- sources/Map/LuaMap.cpp | 12 +++++++++++- sources/Map/LuaMap.hpp | 2 ++ .../System/IAControllable/IAControllableSystem.cpp | 11 +++++++++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/assets/ai_scripts/john.lua b/assets/ai_scripts/john.lua index 43a5deff..4896a8e3 100644 --- a/assets/ai_scripts/john.lua +++ b/assets/ai_scripts/john.lua @@ -130,12 +130,17 @@ function getPathToSafeSpace(player) end ------ Update -function Update(mapinfo) +function Update() log("NEW FRAME") + print("a") local dangerMap = getDanger() - local path = getPath(0, 0, 16, 16); + --local path = getPath(0, 0, 16, 16); local player = getPlayer(); local playerRound = getPlayerRound(); + PrintMap(dangerMap, 17, 17); + if isPlayerInDanger() then + return 1, 1, false, false + end ---- sjould send Map Danger and MaxX MaxY --MaxX = 0 --MaxY = 0 diff --git a/sources/Map/LuaMap.cpp b/sources/Map/LuaMap.cpp index f7ce19d9..81c36bc7 100644 --- a/sources/Map/LuaMap.cpp +++ b/sources/Map/LuaMap.cpp @@ -42,7 +42,7 @@ namespace BBM void LuaMap::setPlayer(Vector3f pos) { - _player = Vector2f(pos.x, pos.y); + _player = Vector2f(pos.x, pos.z); _roundedPlayer = Vector2f(std::round(_player.x), std::round(_player.y)); } @@ -226,4 +226,14 @@ namespace BBM const LuaMap *map = (const LuaMap *) lua_topointer(L, lua_upvalueindex(1)); return 1; } + + int LuaMap::isPlayerInDanger(lua_State *L) + { + auto y = lua_tonumber(L, -1); + auto x = lua_tonumber(L, -2); + LuaG::State state(L); + const LuaMap *map = (const LuaMap *) lua_topointer(L, lua_upvalueindex(1)); + lua_pushboolean(L, map->_danger[map->_roundedPlayer.y][map->_roundedPlayer.x] > 0); + return 1; + } } \ No newline at end of file diff --git a/sources/Map/LuaMap.hpp b/sources/Map/LuaMap.hpp index c2da5e27..fed70ba3 100644 --- a/sources/Map/LuaMap.hpp +++ b/sources/Map/LuaMap.hpp @@ -48,6 +48,8 @@ namespace BBM //! @brief get closest safe space of player static int getClosestSafeSpace(lua_State *L); + static int isPlayerInDanger(lua_State *L); + //! @brief map blocks in 2D grid std::vector> _map; diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index ca659d4c..260efe84 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -91,6 +91,10 @@ namespace BBM lua_pushlightuserdata(state.getState(), &_luamap); lua_pushcclosure(state.getState(), LuaMap::getPlayerRound, 1); lua_setglobal(state.getState(), "getPlayerRound"); + + lua_pushlightuserdata(state.getState(), &_luamap); + lua_pushcclosure(state.getState(), LuaMap::isPlayerInDanger, 1); + lua_setglobal(state.getState(), "isPlayerInDanger"); } void IAControllableSystem::onFixedUpdate(WAL::ViewEntity &entity) @@ -106,10 +110,13 @@ namespace BBM ia.registered = true; } UpdateMapInfos(entity); + std::cout << _luamap._player << std::endl << std::flush; ia._state.getGlobal("Update"); - if (!lua_isfunction(ia._state.getState(), -1)) + if (!lua_isfunction(ia._state.getState(), -1)) { + std::cout << "a" << std::flush; return; - ia._state.callFunction(1, 4); + } + ia._state.callFunction(0, 4); controllable.bomb = ia._state.getReturnBool(); controllable.select = ia._state.getReturnBool(); controllable.move.y = ia._state.getReturnNumber();