From 8f081e53ab873ab8170172aad67c929bd36ac205 Mon Sep 17 00:00:00 2001 From: Bluub Date: Sun, 20 Jun 2021 21:28:42 +0200 Subject: [PATCH] get radius, get enemies get enemies round --- assets/ai_scripts/john.lua | 16 +++++++ sources/Map/LuaMap.cpp | 48 +++++++++++++++++++ sources/Map/LuaMap.hpp | 12 +++++ .../IAControllable/IAControllableSystem.cpp | 9 +++- 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/assets/ai_scripts/john.lua b/assets/ai_scripts/john.lua index f0a01d06..a77ad6f0 100644 --- a/assets/ai_scripts/john.lua +++ b/assets/ai_scripts/john.lua @@ -137,6 +137,22 @@ function Update() end end + local enemies = getEnemies() + local enemiesRound = getEnemiesRound() + + log("enemies") + for i, v in ipairs(enemies) do + log("enemy") + log(v.x) + log(v.y) + end + log("enemies ROUND") + for i, v in ipairs(enemiesRound) do + log("enemy ROUND") + log(v.x) + log(v.y) + end + log("player") log(player.x) log(player.y) diff --git a/sources/Map/LuaMap.cpp b/sources/Map/LuaMap.cpp index 33ffdc3b..04232bd1 100644 --- a/sources/Map/LuaMap.cpp +++ b/sources/Map/LuaMap.cpp @@ -319,6 +319,54 @@ namespace BBM return 1; } + int LuaMap::getRadius(lua_State *L) + { + LuaG::State state(L); + const LuaMap *map = reinterpret_cast(state.getPointer(state.getFirstUpValueIdx())); + state.push(map->currRadius); + return 1; + } + + int LuaMap::getEnemies(lua_State *L) + { + LuaG::State state(L); + const LuaMap *map = reinterpret_cast(state.getPointer(state.getFirstUpValueIdx())); + int index = 1; + state.newTable(); + for (auto &r : map->_enemies) { + state.push(index++); + state.newTable(); + state.push("x"); + state.push(r.x); + state.setTable(); + state.push("y"); + state.push(r.y); + state.setTable(); + state.setTable(); + } + return 1; + } + + int LuaMap::getEnemiesRound(lua_State *L) + { + LuaG::State state(L); + const LuaMap *map = reinterpret_cast(state.getPointer(state.getFirstUpValueIdx())); + int index = 1; + state.newTable(); + for (auto &r : map->_enemies) { + state.push(index++); + state.newTable(); + state.push("x"); + state.push(std::round(r.x)); + state.setTable(); + state.push("y"); + state.push(std::round(r.y)); + state.setTable(); + state.setTable(); + } + return 1; return 1; + } + int LuaMap::canPutBomb(lua_State *L) { LuaG::State state(L); diff --git a/sources/Map/LuaMap.hpp b/sources/Map/LuaMap.hpp index 43719e39..46765d20 100644 --- a/sources/Map/LuaMap.hpp +++ b/sources/Map/LuaMap.hpp @@ -63,6 +63,15 @@ namespace BBM //! @brief Check if current player can put a bomb with an escape static int canPutBomb(lua_State *L); + //! @brief Get current explosion radius of the player + static int getRadius(lua_State *L); + + //! @brief Get enemies position + static int getEnemies(lua_State *L); + + //! @brief Get enemies position rounded + static int getEnemiesRound(lua_State *L); + //! @brief map blocks in 2D grid std::vector> _map; @@ -72,6 +81,9 @@ namespace BBM //! @brief player position Vector2f _player; + //! @brief other players position + std::vector _enemies; + //! @brief rounded player position Vector2f _roundedPlayer; diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index 6d67c3bb..55056b3e 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -19,11 +19,13 @@ namespace BBM void IAControllableSystem::UpdateMapInfos(WAL::ViewEntity &entity) { - _players.clear(); + _luamap._enemies.clear(); if (!_wal.getScene()) return; for (auto &[other, pos, _] : _wal.getScene()->view()) { - _players.push_back(MapInfo(pos.position, MapGenerator::NOTHING)); + if (other == entity) + continue; + _luamap._enemies.push_back(Vector2f(pos.position.x, pos.position.z)); } if (_cached) return; @@ -86,6 +88,9 @@ namespace BBM state.registerClosure(&_luamap, "getBlockType", LuaMap::getBlockType); state.registerClosure(&_luamap, "getClosestSafeSpace", LuaMap::getClosestSafeSpace); state.registerClosure(&_luamap, "canPutBombSafe", LuaMap::canPutBomb); + state.registerClosure(&_luamap, "getRadius", LuaMap::getRadius); + state.registerClosure(&_luamap, "getEnemies", LuaMap::getEnemies); + state.registerClosure(&_luamap, "getEnemiesRound", LuaMap::getEnemiesRound); } void IAControllableSystem::onFixedUpdate(WAL::ViewEntity &entity)