diff --git a/Assets/Scripts/main.lua b/Assets/Scripts/main.lua new file mode 100644 index 0000000..67aa084 --- /dev/null +++ b/Assets/Scripts/main.lua @@ -0,0 +1 @@ +players = {} diff --git a/Assets/Scripts/player.lua b/Assets/Scripts/player.lua new file mode 100644 index 0000000..a2bed43 --- /dev/null +++ b/Assets/Scripts/player.lua @@ -0,0 +1,12 @@ +Player = {} + +function Player:new(pl) + player = pl or {} + self.__index = self + setmetatable(player, self) + return player +end + +function Player:update() + print("id = " .. self.id) +end diff --git a/defConfigs.h b/defConfigs.h index e94f1aa..dcc5a67 100755 --- a/defConfigs.h +++ b/defConfigs.h @@ -31,7 +31,8 @@ namespace battleship{ scriptPathBase + "options.lua", scriptPathBase + "unitData.lua", scriptPathBase + "vehicleData.lua", - scriptPathBase + "structureData.lua" + scriptPathBase + "structureData.lua", + scriptPathBase + "player.lua" }; const static Bind staticBinds[numAppStates][maxStaticBinds]{ diff --git a/gameManager.cpp b/gameManager.cpp index a402cab..c118628 100755 --- a/gameManager.cpp +++ b/gameManager.cpp @@ -37,6 +37,7 @@ namespace battleship{ void GameManager::start() { LuaManager *luaManager = LuaManager::getSingleton(); + luaManager->buildScript(vector{path + "Scripts/main.lua"}); luaManager->buildScript(configData::scripts); string ind1 = "graphics", ind2 = "resolution"; diff --git a/inGameAppState.cpp b/inGameAppState.cpp index 0925279..0d5ea3d 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -182,7 +182,7 @@ namespace battleship{ } faction = factions[i][0] - 48; - Player *p = new Player(difficulty, faction); + Player *p = new Player(difficulty, faction, i); players.push_back(p); p->setId(players.size() - 1); } diff --git a/player.cpp b/player.cpp index b801ec3..7bf45e6 100755 --- a/player.cpp +++ b/player.cpp @@ -1,19 +1,28 @@ #include "player.h" +#include + using namespace vb01; +using namespace gameBase; using namespace std; namespace battleship{ - Player::Player(int difficulty, int faction, Vector3 spawnPoint) { + Player::Player(int difficulty, int faction, int id, Vector3 spawnPoint) { this->difficulty = difficulty; this->faction = faction; - this->spawnPoint=spawnPoint; + this->spawnPoint = spawnPoint; + this->id = id; + + LuaManager *lm = LuaManager::getSingleton(); + lm->executeCode("players[" + to_string(id + 1) + "] = Player:new({id = " + to_string(id + 1) + "})"); } Player::~Player() { } void Player::update() { + LuaManager *lm = LuaManager::getSingleton(); + lm->executeCode("players[" + to_string(id + 1) + "]:update()"); } void Player::issueOrder(Order::TYPE type, vector targets, bool append){ diff --git a/player.h b/player.h index 4fdf8b8..215e613 100755 --- a/player.h +++ b/player.h @@ -10,7 +10,7 @@ namespace battleship{ class Player { public: - Player(int, int, vb01::Vector3 = vb01::Vector3::VEC_ZERO); + Player(int, int, int, vb01::Vector3 = vb01::Vector3::VEC_ZERO); ~Player(); void update(); void issueOrder(Order::TYPE, std::vector, bool);