diff --git a/inGameAppState.cpp b/inGameAppState.cpp index 8f800a1..c852c1c 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -62,7 +62,7 @@ namespace battleship{ Map *map = Map::getSingleton(); map->load(mapName); - map->loadPlayerGameObjects(); + map->loadPlayersGameObjects(); Camera *cam = Root::getSingleton()->getCamera(); cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); diff --git a/map.cpp b/map.cpp index dca7b06..4894858 100755 --- a/map.cpp +++ b/map.cpp @@ -420,52 +420,59 @@ namespace battleship{ } } - //TODO move minimap loading elsewhere - void Map::loadPlayerGameObjects(){ - vector players = Game::getSingleton()->getPlayers(true); + void Map::loadPlayerGameObjects(Player *player, sol::table playerTbl){ + string resDepInd = "resourceDeposits"; sol::state_view SOL_LUA_VIEW = generateView(); - string playerInd = "players"; + sol::table resDepTbl = playerTbl["resourceDeposits"]; + int numNpcObjs = resDepTbl.size(); - for(int i = 0; i < players.size(); i++){ - string resDepInd = "resourceDeposits"; - SOL_LUA_VIEW.script("numResourceDeposits = #" + mapTable + "." + playerInd + "[" + to_string(i + 1) + "]." + resDepInd); - int numNpcObjs = SOL_LUA_VIEW["numResourceDeposits"]; - Player *player = players[i]; + for(int j = 0; j < numNpcObjs; j++){ + sol::table npcObjTable = resDepTbl[j + 1]; + int id = npcObjTable["id"]; - for(int j = 0; j < numNpcObjs; j++){ - sol::table npcObjTable = SOL_LUA_VIEW[mapTable][playerInd][i + 1][resDepInd][j + 1]; - int id = npcObjTable["id"]; + sol::table posTable = npcObjTable["pos"]; + Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]); - sol::table posTable = npcObjTable["pos"]; - Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]); + sol::table rotTable = npcObjTable["rot"]; + Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]); + int initAmmount = resDepTbl[j + 1]["initAmmount"]; - sol::table rotTable = npcObjTable["rot"]; - Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]); - int initAmmount = SOL_LUA_VIEW[mapTable][playerInd][i + 1][resDepInd][j + 1]["initAmmount"]; - - player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot, initAmmount)); - } - - //int spawnPointId = SOL_LUA_STATE[mapTable]["spawnPointInd"][i + 1][spawnPointId]; - string unitInd = "units"; - SOL_LUA_VIEW.script("numUnits = #" + mapTable + "." + playerInd + "[" + to_string(i + 1) + "]." + unitInd); - int numUnits = SOL_LUA_VIEW["numUnits"]; - - for(int j = 0; j < numUnits; j++){ - sol::table unitTable = SOL_LUA_VIEW[mapTable][playerInd][i + 1][unitInd][j + 1]; - - string posInd = "pos"; - Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]); - - string rotInd = "rot"; - Quaternion rot = Quaternion(unitTable[rotInd]["w"], unitTable[rotInd]["x"], unitTable[rotInd]["x"], unitTable[rotInd]["x"]); - - int id = unitTable["id"]; - int buildStatus = unitTable["buildStatus"].get_or(0); - player->addUnit(GameObjectFactory::createUnit(player, id, pos, rot, buildStatus)); - } + player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot, initAmmount)); } + string unitInd = "units"; + sol::table unitsTbl = playerTbl["units"]; + int numUnits = unitsTbl.size(); + + for(int j = 0; j < numUnits; j++){ + sol::table unitTable = unitsTbl[j + 1]; + + string posInd = "pos"; + Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]); + + string rotInd = "rot"; + Quaternion rot = Quaternion(unitTable[rotInd]["w"], unitTable[rotInd]["x"], unitTable[rotInd]["x"], unitTable[rotInd]["x"]); + + int id = unitTable["id"]; + int buildStatus = unitTable["buildStatus"].get_or(0); + player->addUnit(GameObjectFactory::createUnit(player, id, pos, rot, buildStatus)); + } + } + + //TODO move minimap loading elsewhere + void Map::loadPlayersGameObjects(){ + Game *game = Game::getSingleton(); + vector choosablePlayers = game->getPlayers(false); + sol::state_view SOL_LUA_VIEW = generateView(); + + for(int i = 0; i < choosablePlayers.size(); i++){ + sol::table playerTbl = SOL_LUA_VIEW[mapTable]["choosablePlayers"][i + 1]; + loadPlayerGameObjects(choosablePlayers[i], playerTbl); + } + + sol::table civPlayerTbl = SOL_LUA_VIEW[mapTable]["civilianPlayer"]; + loadPlayerGameObjects(game->getCivilianPlayer(), civPlayerTbl); + Minimap::getSingleton()->load(); } diff --git a/map.h b/map.h index 8846271..0268e62 100755 --- a/map.h +++ b/map.h @@ -8,6 +8,8 @@ #include #include +#include + namespace vb01{ class Model; class Material; @@ -76,7 +78,7 @@ namespace battleship{ std::vector raycastTerrain(vb01::Vector3, vb01::Vector3, bool); int getCellId(vb01::Vector3, bool = true); bool isPointWithinTerrainObject(vb01::Vector3, int); - void loadPlayerGameObjects(); + void loadPlayersGameObjects(); int getNumMapSpawnPoints(std::string = ""); std::vector getSurroundingCells(vb01::Vector3, int); void blockCells(Unit*); @@ -111,6 +113,7 @@ namespace battleship{ void loadLights(); void loadSkybox(); void loadCells(); + void loadPlayerGameObjects(Player*, sol::table); void loadTerrainObject(int); void unloadTerrainObjects(); void unloadCells(); @@ -121,5 +124,4 @@ namespace battleship{ template int bsearch(std::vector, T, float); }; } - #endif diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index f4d63f1..9228217 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -73,7 +73,7 @@ namespace battleship{ for(int i = 0; i < numPlayers; i++) game->addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1))); - map->loadPlayerGameObjects(); + map->loadPlayersGameObjects(); } }