diff --git a/Assets/Models/Maps/water/water.lua b/Assets/Models/Maps/water/water.lua index bd8e541..cbc6dda 100644 --- a/Assets/Models/Maps/water/water.lua +++ b/Assets/Models/Maps/water/water.lua @@ -12,13 +12,13 @@ spawnPoints = { }, players = { { -resourceDeposits = { -{id = 0, pos = {x = 100.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000}, -{id = 0, pos = {x = -200.000000, y = 0.000000, z = 50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000}, -}, +resourceDeposits = {}, units = { +{id = 0, pos = {x = 290.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, {id = 1, pos = {x = 300.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, -{id = 18, pos = {x = 300.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, +{id = 2, pos = {x = 300.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, +--{id = 13, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, +--{id = 19, pos = {x = 300.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, } ,}, { @@ -27,9 +27,15 @@ spawnPoint = 0, units = { {id = 0, pos = {x = 300.000000, y = 0.000000, z = 450.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, {id = 1, pos = {x = -300.000000, y = 0.000000, z = -450.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, -{id = 13, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, } -,} +,}, +{ + resourceDeposits = { + {id = 0, pos = {x = 100.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000}, + {id = 0, pos = {x = -200.000000, y = 0.000000, z = 50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000}, + }, + units = {} +} }, numCells = 37306, cells = { diff --git a/activeGameState.cpp b/activeGameState.cpp index fdf9ccc..3b33167 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -337,7 +337,7 @@ namespace battleship{ void ActiveGameState::updateGameObjHoveredOn(){ vector gameObjs; - vector players = Game::getSingleton()->getPlayers(); + vector players = Game::getSingleton()->getPlayers(true); for(Player *pl : players){ vector resDeps = pl->getResourceDeposits(); @@ -482,7 +482,7 @@ namespace battleship{ vector units; - for (Player *p : Game::getSingleton()->getPlayers()) + for (Player *p : Game::getSingleton()->getPlayers(true)) for (Unit *u : p->getUnits()) units.push_back(u); diff --git a/extractor.cpp b/extractor.cpp index 412d4f8..2e5d0cc 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -12,21 +12,13 @@ namespace battleship{ using namespace gameBase; Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, ResourceDeposit *rd, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state){ - if(!rd){ - vector deposits; - - for(Player *pl : Game::getSingleton()->getPlayers()){ - vector dep = pl->getResourceDeposits(); - deposits.insert(deposits.end(), dep.begin(), dep.end()); - } - - for(ResourceDeposit *dep : deposits) + if(!rd) + for(ResourceDeposit *dep : Game::getSingleton()->getCivilianPlayer()->getResourceDeposits()) if(dep->getPos().getDistanceFrom(pos) < .001){ deposit = dep; deposit->setExtractor(this); break; } - } Vector2 size = Vector2(lenHpBar, 10); ammountBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); diff --git a/game.cpp b/game.cpp index 127d761..1427a4d 100644 --- a/game.cpp +++ b/game.cpp @@ -122,11 +122,11 @@ namespace battleship{ for(Projectile *proj : pl->getProjectiles()) gameObjs.push_back((GameObject*)proj); - - for(ResourceDeposit *dep : pl->getResourceDeposits()) - gameObjs.push_back((GameObject*)dep); } + for(ResourceDeposit *dep : civilianPlayer->getResourceDeposits()) + gameObjs.push_back((GameObject*)dep); + for(GameObject *obj : gameObjs) obj->reinit(); } @@ -276,4 +276,12 @@ namespace battleship{ return false; } + + vector Game::getPlayers(bool civPl){ + vector playersVec = players; + + if(civPl) playersVec.push_back(civilianPlayer); + + return playersVec; + } } diff --git a/game.h b/game.h index 38d077b..f9fde6e 100644 --- a/game.h +++ b/game.h @@ -27,11 +27,13 @@ namespace battleship{ void initTechnologies(); float calcAbilFromTech(Ability::Type, std::vector, int, int); bool isUnitUnlocked(std::vector, int); + std::vector getPlayers(bool = false); inline void setDebug(bool d){this->debug = d;} inline void addPlayer(Player *pl){players.push_back(pl);} inline bool isDebug(){return debug;} - inline std::vector& getPlayers(){return players;} inline Player* getPlayer(int id){return players[id];} + inline void setCivilianPlayer(Player *pl){this->civilianPlayer = pl;} + inline Player* getCivilianPlayer(){return civilianPlayer;} inline int getNumPlayers(){return players.size();} inline Technology getTechnology(int id){return technologies[id];} inline Ability getAbility(int id){return abilities[id];} @@ -44,6 +46,7 @@ namespace battleship{ std::vector technologies; std::vector abilities; std::vector players; + Player *civilianPlayer = nullptr; }; } diff --git a/gameObjectFrameController.cpp b/gameObjectFrameController.cpp index d3f2b16..a58de16 100644 --- a/gameObjectFrameController.cpp +++ b/gameObjectFrameController.cpp @@ -59,17 +59,9 @@ namespace battleship{ void GameObjectFrameController::snapToObj(GameObjectFrame &s, GameObject::Type type, int unitId, float maxDist){ if(s.getType() == GameObject::Type::UNIT && s.getId() == unitId){ s.status = GameObjectFrame::NOT_PLACEABLE; - vector players = Game::getSingleton()->getPlayers(); - vector deposits; - - for(Player *pl : players){ - vector deps = pl->getResourceDeposits(); - - for(ResourceDeposit *dep : deps) - deposits.push_back(dep); - } + Player *civPl = Game::getSingleton()->getCivilianPlayer(); - for(ResourceDeposit *dep : deposits){ + for(ResourceDeposit *dep : civPl->getResourceDeposits()){ Vector3 depPos = dep->getPos(); if(!dep->getExtractor() && s.getPos().getDistanceFrom(depPos) < maxDist){ diff --git a/map.cpp b/map.cpp index 8353a64..173546f 100755 --- a/map.cpp +++ b/map.cpp @@ -48,9 +48,8 @@ namespace battleship{ string refIconFile = SOL_STATE_VIEW["refIcon"]; string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Minimap/"; - for(Player *pl : Game::getSingleton()->getPlayers()) - for(ResourceDeposit *rd : pl->getResourceDeposits()) - depositIcons.push_back(initIcon(rd->getPos(), basePath + refIconFile)); + for(ResourceDeposit *rd : Game::getSingleton()->getCivilianPlayer()->getResourceDeposits()) + depositIcons.push_back(initIcon(rd->getPos(), basePath + refIconFile)); string camIconFile = SOL_STATE_VIEW["eyeIcon"]; camIcon = initIcon(Root::getSingleton()->getCamera()->getPosition(), basePath + camIconFile); @@ -107,7 +106,7 @@ namespace battleship{ Vector3 mapSize = Map::getSingleton()->getMapSize(); vector> unitMinimapPos; - for(Player *pl : Game::getSingleton()->getPlayers()) + for(Player *pl : Game::getSingleton()->getPlayers(true)) for(Unit *un : pl->getUnits()){ Vector2 coords = Vector2( int(un->getPos().x / mapSize.x * width), @@ -395,15 +394,15 @@ namespace battleship{ //TODO move minimap loading elsewhere void Map::loadPlayerGameObjects(){ - int numPlayers = Game::getSingleton()->getNumPlayers(); + vector players = Game::getSingleton()->getPlayers(true); sol::state_view SOL_LUA_VIEW = generateView(); string playerInd = "players"; - for(int i = 0; i < numPlayers; i++){ + 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 = Game::getSingleton()->getPlayer(i); + Player *player = players[i]; for(int j = 0; j < numNpcObjs; j++){ sol::table npcObjTable = SOL_LUA_VIEW[mapTable][playerInd][i + 1][resDepInd][j + 1]; @@ -587,7 +586,7 @@ namespace battleship{ } void Map::unloadPlayerObjects(){ - for(Player *pl : Game::getSingleton()->getPlayers()){ + for(Player *pl : Game::getSingleton()->getPlayers(true)){ while(pl->getNumUnits() > 0){ pl->removeUnit(0); } diff --git a/playButton.cpp b/playButton.cpp index 785f5ef..16feb73 100644 --- a/playButton.cpp +++ b/playButton.cpp @@ -66,6 +66,8 @@ namespace battleship{ string name = (cpuPlayer ? "CPU player #" + to_string(i) : "Player"); game->addPlayer(new Player(difficulty, faction, team, color, cpuPlayer, i, name)); } + + game->setCivilianPlayer(new Player(0, 0, 0, .5 * Vector3::VEC_IJK)); handleLoadingGui(new LoadingAppState(new InGameAppState(mapName), "inGame.lua")); } diff --git a/projectile.cpp b/projectile.cpp index 8298576..b10f147 100755 --- a/projectile.cpp +++ b/projectile.cpp @@ -76,7 +76,7 @@ namespace battleship{ } void Projectile::checkUnitCollision(){ - vector players = Game::getSingleton()->getPlayers(); + vector players = Game::getSingleton()->getPlayers(true); vector targetUnits; vector targetNodes;