diff --git a/ai_scripts/john.lua b/ai_scripts/john.lua index adb71290..ac9c5de1 100644 --- a/ai_scripts/john.lua +++ b/ai_scripts/john.lua @@ -5,6 +5,10 @@ local debug = true --local debug = false if not debug then log = function() end +else + log = function(a) + print(a) + end end function PrintMap(map, maxX, maxZ) @@ -45,10 +49,10 @@ function Update(player, infos, players) end end local myMap = CreateMyMap(infos, maxX, maxZ); - if (isInExplosionRange()) then - --play defensive RUN - else - --play offensive - end + --if (isInExplosionRange()) then + -- --play defensive RUN + --else + -- --play offensive + --end return 1, 1, false, false; end \ No newline at end of file diff --git a/lib/LuaGate/LuaGate.cpp b/lib/LuaGate/LuaGate.cpp new file mode 100644 index 00000000..33180dae --- /dev/null +++ b/lib/LuaGate/LuaGate.cpp @@ -0,0 +1,34 @@ +// +// Created by Louis Auzuret on 10/06/21 +// + +#include "LuaGate.hpp" + +namespace LuaG +{ + State::State() + : _state(luaL_newstate()) + { + luaL_openlibs(_state); + } + + State::~State() + { + lua_close(_state); + } + + LuaState *State::getState(void) + { + return _state; + } + + void State::dofile(std::string filepath) + { + luaL_dofile(_state, filepath.c_str()); + } + + void State::dostring(std::string str) + { + luaL_dostring(_state, str.c_str()); + } +} \ No newline at end of file diff --git a/lib/LuaGate/LuaGate.hpp b/lib/LuaGate/LuaGate.hpp new file mode 100644 index 00000000..6d372439 --- /dev/null +++ b/lib/LuaGate/LuaGate.hpp @@ -0,0 +1,37 @@ +// +// Created by Louis Auzuret on 10/06/21 +// + +#include +#include "lua.hpp" + +namespace LuaG +{ + class State + { + private: + LuaState *_state; + public: + //! @brief ctor + State(); + + //! @brief dtor + ~State(); + + //! @brief No copy constrructor + State &State(State &) = delete; + + //! @brief No assign operator + State &operator() = delete; + + //! @brief Get Lua state + LuaState *getState(void); + + //! @brief Execute a file in this state + void dofile(std::string filepath); + + //! @brief Execute a string in this state + void dostring(std::string str); + + } +} \ No newline at end of file diff --git a/sources/System/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index db68e3c0..60217ff3 100644 --- a/sources/System/Collision/CollisionSystem.cpp +++ b/sources/System/Collision/CollisionSystem.cpp @@ -7,7 +7,6 @@ #include "Component/Collision/CollisionComponent.hpp" #include "System/Collision/CollisionSystem.hpp" #include "Scene/Scene.hpp" - namespace BBM { CollisionSystem::CollisionSystem(WAL::Wal &wal) diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index 40e963d5..51342a09 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -11,7 +11,7 @@ namespace BBM { IAControllableSystem::IAControllableSystem(WAL::Wal &wal) - : System(wal), _wal(wal) + : System(wal), _wal(wal), _map(), _players(), _cached(false) { } /* float IAControllableSystem::getReturnNumber(lua_State *state) @@ -45,6 +45,8 @@ namespace BBM { if (_cached) return; + if (!_wal.scene.get()) + return; for (auto &[other, pos, _] : _wal.scene->view>()) _map.push_back(MapInfo(pos.position, MapGenerator::BREAKABLE)); for (auto &[other, pos, _] : _wal.scene->view>()) @@ -58,6 +60,8 @@ namespace BBM continue; _players.push_back(MapInfo(pos.position, MapGenerator::NOTHING)); } + //for (auto &[other, pos, bomb] : _wal.getScene()->view()) + // _bombs.push_back(std::make_pair(pos.position, bomb.explosionRadius)); _cached = true; } @@ -69,7 +73,7 @@ namespace BBM auto &pos = entity.get(); MapInfo player(pos.position, MapGenerator::NOTHING); - UpdateMapInfos(static_cast(entity)); + //UpdateMapInfos(static_cast(entity)); luabridge::LuaRef updateFunc = luabridge::getGlobal(ia.state, "Update"); if (!updateFunc.isFunction()) return; @@ -91,6 +95,7 @@ namespace BBM { _cached = false; _map.clear(); + _bombs.clear(); _players.clear(); } diff --git a/sources/System/IAControllable/IAControllableSystem.hpp b/sources/System/IAControllable/IAControllableSystem.hpp index 3a56ab62..06c8c0d7 100644 --- a/sources/System/IAControllable/IAControllableSystem.hpp +++ b/sources/System/IAControllable/IAControllableSystem.hpp @@ -26,6 +26,8 @@ namespace BBM //! @brief All players in the map std::vector _players; + std::vector> _bombs; + //! @brief void UpdateMapInfos(WAL::Entity entity); public: