diff --git a/ai_scripts/john.lua b/ai_scripts/john.lua index 304a89da..67eb2762 100644 --- a/ai_scripts/john.lua +++ b/ai_scripts/john.lua @@ -1,14 +1,16 @@ -function Sum(a,b) - return a + b; -end - -function Update(infos) +function Update(player, infos, players) + print(player.x); + print(player.y); + print(player.z); for i, info in ipairs(infos) do - print (info.x); - print (info.y); - print (info.z); - print (info.type); + --print("x"); + --print (info.x); + --print("y"); + --print (info.y); + --print("z"); + --print (info.z); + --print("type"); + --print (info.type); end return 1, 1, false, false; - --return info.x, info.y, (info.z ~= 1), (info.type ~= 0); end \ No newline at end of file diff --git a/sources/Component/Tag/TagComponent.hpp b/sources/Component/Tag/TagComponent.hpp index 25b6df37..fe07f70e 100644 --- a/sources/Component/Tag/TagComponent.hpp +++ b/sources/Component/Tag/TagComponent.hpp @@ -55,4 +55,5 @@ namespace BBM constexpr const char Breakable[] = "Breakable"; constexpr const char Hole[] = "Hole"; constexpr const char Bumper[] = "Bumper"; + constexpr const char Player[] = "Player"; } diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 9fb1fbd7..8f327f9c 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -96,6 +96,7 @@ namespace BBM .addComponent() .addComponent() .addComponent() + .addComponent("./ai_scripts/john.lua") .addComponent>() //.addComponent(0) .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3) diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index 83e52a68..822a93df 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -3,6 +3,7 @@ // #include "Map/MapInfo.hpp" +#include "Component/Tag/TagComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp" #include "Component/IAControllable/IAControllableComponent.hpp" #include "System/IAControllable/IAControllableSystem.hpp" @@ -12,46 +13,40 @@ namespace BBM { IAControllableSystem::IAControllableSystem(WAL::Wal &wal) - : System(wal) + : System(wal), _wal(wal) { } - float IAControllableSystem::getReturnNumber(lua_State *state) - { - float res = 0; - - if (lua_isnil(state, -1)) - return res; - if (!lua_isnumber(state, -1)) - return res; - res = lua_tonumber(state, -1); - lua_pop(state, 1); - - return res; - } - - bool IAControllableSystem::getReturnBool(lua_State *state) - { - bool res = false; - - if (lua_isnil(state, -1)) - return res; - if (!lua_isboolean(state, -1)) - return res; - res = lua_toboolean(state, -1); - lua_pop(state, 1); - return res; - } - - void IAControllableSystem::onFixedUpdate(WAL::ViewEntity &entity) + void IAControllableSystem::onFixedUpdate(WAL::ViewEntity &entity) { auto &ia = entity.get(); auto &controllable = entity.get(); + auto &pos = entity.get(); + MapInfo player(pos.position, MapGenerator::NOTHING); std::vector infos; + std::vector players; + + for (auto &[other, pos, _] : _wal.scene->view>()) + infos.push_back(MapInfo(pos.position, MapGenerator::BREAKABLE)); + + for (auto &[other, pos, _] : _wal.scene->view>()) + infos.push_back(MapInfo(pos.position, MapGenerator::UNBREAKABLE)); + + for (auto &[other, pos, _] : _wal.scene->view>()) + infos.push_back(MapInfo(pos.position, MapGenerator::BUMPER)); + + for (auto &[other, pos, _] : _wal.scene->view>()) + infos.push_back(MapInfo(pos.position, MapGenerator::HOLE)); + + for (auto &[other, pos, _] : _wal.scene->view>()) { + if (static_cast(entity).getUid() == other.getUid()) + continue; + players.push_back(MapInfo(pos.position, MapGenerator::NOTHING)); + } luabridge::LuaRef updateFunc = luabridge::getGlobal(ia.state, "Update"); if (!updateFunc.isFunction()) return; - luabridge::LuaResult res = updateFunc(infos); + luabridge::LuaResult res = updateFunc(player, infos, players); if (res.hasFailed() || res.size() != 4) return; diff --git a/sources/System/IAControllable/IAControllableSystem.hpp b/sources/System/IAControllable/IAControllableSystem.hpp index b851e800..03c60dea 100644 --- a/sources/System/IAControllable/IAControllableSystem.hpp +++ b/sources/System/IAControllable/IAControllableSystem.hpp @@ -9,16 +9,14 @@ namespace BBM { //! @brief A system to handle keyboard entities. - class IAControllableSystem : public WAL::System + class IAControllableSystem : public WAL::System { private: - //! @brief extract a number from the lua stack - float getReturnNumber(lua_State *state); - //! @brief extract a bool from the lua stack - bool getReturnBool(lua_State *state); + //! @brief Reference to wal to get Views + WAL::Wal &_wal; public: //! @inherit - void onFixedUpdate(WAL::ViewEntity &entity) override; + void onFixedUpdate(WAL::ViewEntity &entity) override; //! @brief A default constructor IAControllableSystem(WAL::Wal &wal);