diff --git a/ability.h b/ability.h index d3c92b0..c45f7dc 100644 --- a/ability.h +++ b/ability.h @@ -18,7 +18,8 @@ namespace battleship{ LOAD_SPEED, DRAW_RATE, DRAW_SPEED, - HACK_RANGE + HACK_RANGE, + UNIT_UNLOCK }; Type type; diff --git a/game.cpp b/game.cpp index fe17b11..5fd9e7a 100644 --- a/game.cpp +++ b/game.cpp @@ -265,7 +265,7 @@ namespace battleship{ Ability ability; ability.type = techTable["type"]; - ability.ammount = techTable["ammount"].get_or(0); + ability.ammount = techTable["ammount"].get_or(0.0); ability.gameObjType = techTable["gameObjType"]; ability.gameObjIds = parseTechTable(i, techKey, "numGameObjIds", "gameObjIds"); abilities.push_back(ability); @@ -287,4 +287,17 @@ namespace battleship{ return ammount; } + + bool Game::isUnitUnlocked(vector techResearch, int unitId){ + for(int techId : techResearch){ + for(int abilId : technologies[techId].abilities){ + vector ids = abilities[abilId].gameObjIds; + + if(find(ids.begin(), ids.end(), unitId) != ids.end()) + return true; + } + } + + return false; + } } diff --git a/game.h b/game.h index af76b46..ae42ab8 100644 --- a/game.h +++ b/game.h @@ -27,12 +27,14 @@ namespace battleship{ void changeUnitPlayer(Unit*, Player*); void initTechnologies(); float calcAbilFromTech(Ability::Type, std::vector, int, int); + bool isUnitUnlocked(std::vector, int); inline void addFx(Fx f){fx.push_back(f);} inline void addPlayer(Player *pl){players.push_back(pl);} inline std::vector& getPlayers(){return players;} inline Player* getPlayer(int id){return players[id];} inline int getNumPlayers(){return players.size();} inline Technology getTechnology(int id){return technologies[id];} + inline Ability getAbility(int id){return abilities[id];} private: Game(){} void resetLuaGameObjects(); diff --git a/player.cpp b/player.cpp index 2195442..cec2871 100755 --- a/player.cpp +++ b/player.cpp @@ -183,4 +183,8 @@ namespace battleship{ return ucUnits; } + + void Player::addTechnology(int techId){ + technologies.push_back(techId); + } } diff --git a/player.h b/player.h index a6a8a2e..e14e2c7 100755 --- a/player.h +++ b/player.h @@ -26,6 +26,7 @@ namespace battleship{ void selectUnits(std::vector); std::vector getUnitsById(int, int = -1); std::vector getUnitsByClass(UnitClass, int = -1); + void addTechnology(int); inline void deselectUnits(){selectedUnits.clear();} inline Unit* getSelectedUnit(int id){return selectedUnits[id];} inline std::vector getSelectedUnits(){return selectedUnits;} @@ -74,7 +75,6 @@ namespace battleship{ inline vb01::Vector3 getColor(){return color;} inline std::string getName(){return name;} inline std::vector getTechnologies(){return technologies;} - inline void addTechnology(int tid){technologies.push_back(tid);} private: bool cpuPlayer = false; std::vector technologies; diff --git a/unit.cpp b/unit.cpp index 27b67f0..833d6a2 100755 --- a/unit.cpp +++ b/unit.cpp @@ -184,7 +184,7 @@ namespace battleship{ for(int i = 0; i < numBuildableUnits; i++){ sol::table buTable = unitTable[tblName][i + 1]; - buildableUnits.push_back(BuildableUnit(buTable["id"], buTable["buildable"])); + buildableUnits.push_back(BuildableUnit(buTable["id"], game->isUnitUnlocked(currTechs, id) | (bool)buTable["buildable"])); } } }