diff --git a/ai_scripts/john.lua b/ai_scripts/john.lua index 5bec036a..304a89da 100644 --- a/ai_scripts/john.lua +++ b/ai_scripts/john.lua @@ -2,7 +2,13 @@ function Sum(a,b) return a + b; end -function Update(info) +function Update(infos) + for i, info in ipairs(infos) do + print (info.x); + print (info.y); + print (info.z); + 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/Map/MapInfo.cpp b/sources/Map/MapInfo.cpp index 45723f3a..f7c8f7c8 100644 --- a/sources/Map/MapInfo.cpp +++ b/sources/Map/MapInfo.cpp @@ -10,6 +10,10 @@ namespace BBM : x(pos.x), y(pos.y), z(pos.z), type(type) { } + MapInfo::MapInfo(const MapInfo &other) + : x(other.x), y(other.y), z(other.z), type(other.type) + { } + MapInfo &MapInfo::operator=(MapInfo &other) { this->x = other.x; diff --git a/sources/Map/MapInfo.hpp b/sources/Map/MapInfo.hpp index 472b1542..78d10a83 100644 --- a/sources/Map/MapInfo.hpp +++ b/sources/Map/MapInfo.hpp @@ -20,7 +20,7 @@ namespace BBM float z; //! @brief Type of the block - MapGenerator::BlockType type; + int type; //! @brief Constructor MapInfo(Vector3f pos, MapGenerator::BlockType type); @@ -29,7 +29,7 @@ namespace BBM ~MapInfo() = default; //! @brief Default copy constructor - MapInfo(MapInfo &) = default; + MapInfo(const MapInfo &); //! @brief Assignment operator MapInfo &operator=(MapInfo &); diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index 87ed564e..9e20998c 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -6,6 +6,8 @@ #include "Component/Controllable/ControllableComponent.hpp" #include "Component/IAControllable/IAControllableComponent.hpp" #include "System/IAControllable/IAControllableSystem.hpp" +#include +#include namespace BBM { @@ -44,18 +46,22 @@ namespace BBM { auto &ia = entity.get(); auto &controllable = entity.get(); - MapInfo info({1, 2, 3}, MapGenerator::NOTHING); + std::vector infos; luabridge::LuaRef updateFunc = luabridge::getGlobal(ia.state, "Update"); if (!updateFunc.isFunction()) - return; - luabridge::LuaResult res = updateFunc(info); + return; + luabridge::LuaResult res = updateFunc(infos); if (res.hasFailed() || res.size() != 4) return; - controllable.bomb = res[3]; - controllable.jump = res[2]; - controllable.move.y = res[1]; - controllable.move.x = res[0]; + if (res[3].isBool()) + controllable.bomb = res[3]; + if (res[2].isBool()) + controllable.jump = res[2]; + if (res[1].isNumber()) + controllable.move.y = res[1]; + if (res[0].isNumber()) + controllable.move.x = res[0]; } } \ No newline at end of file