diff --git a/engineer.cpp b/engineer.cpp index bb84c6e..3d7cbd2 100644 --- a/engineer.cpp +++ b/engineer.cpp @@ -21,8 +21,10 @@ namespace battleship{ structure->incrementBuildStatus(); lastIncrementTime = getTime(); } - else if(structure->getBuildStatus() >= 100) + else if(structure->getBuildStatus() >= 100){ removeOrder(0); + player->incStructuresBuilt(); + } } } else{ diff --git a/factory.cpp b/factory.cpp index 6e0c7bb..b8c9d68 100644 --- a/factory.cpp +++ b/factory.cpp @@ -55,6 +55,8 @@ namespace battleship{ unitQueue.erase(unitQueue.begin()); trainingStatus = 0; + + player->incVehiclesBuilt(); } } } diff --git a/player.h b/player.h index 6fd3613..da37316 100755 --- a/player.h +++ b/player.h @@ -55,12 +55,12 @@ namespace battleship{ inline int getNumStructuresBuilt(){return structuresBuilt;} inline int getNumStructuresDestroyed(){return structuresDestroyed;} inline int getNumStructuresLost(){return structuresLost;} - inline void setNumVehiclesBuilt(int vb){vehiclesBuilt = vb;} - inline void setNumVehiclesDestroyed(int vd){vehiclesDestroyed = vd;} - inline void setNumVehiclesLost(int vl){vehiclesLost = vl;} - inline void setNumStructuresBuilt(int sb){structuresBuilt = sb;} - inline void setNumStructuresDestroyed(int sd){structuresDestroyed = sd;} - inline void setNumStructuresLost(int sl){structuresLost = sl;} + inline void incVehiclesBuilt(){vehiclesBuilt++;} + inline void incVehiclesDestroyed(){vehiclesDestroyed++;} + inline void incVehiclesLost(){vehiclesLost++;} + inline void incStructuresBuilt(){structuresBuilt++;} + inline void incStructuresDestroyed(){structuresDestroyed++;} + inline void incStructuresLost(){structuresLost++;} inline vb01::Vector3 getColor(){return color;} inline std::string getName(){return name;} private: diff --git a/resourceDeposit.cpp b/resourceDeposit.cpp index 9bd6da4..a59b023 100644 --- a/resourceDeposit.cpp +++ b/resourceDeposit.cpp @@ -9,4 +9,8 @@ namespace battleship{ placeAt(pos); orientAt(rot); } + + ResourceDeposit::~ResourceDeposit(){ + destroyModel(); + } } diff --git a/resourceDeposit.h b/resourceDeposit.h index 14ca75e..be11fad 100644 --- a/resourceDeposit.h +++ b/resourceDeposit.h @@ -7,6 +7,7 @@ namespace battleship{ class ResourceDeposit : public GameObject{ public: ResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion); + ~ResourceDeposit(); private: }; } diff --git a/statsButton.cpp b/statsButton.cpp index 7ac4da2..912ec45 100644 --- a/statsButton.cpp +++ b/statsButton.cpp @@ -15,15 +15,8 @@ namespace battleship{ StatsButton::StatsButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, true, imagePath){} void StatsButton::addPlayerDataGuiElements(int playerId){ - string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"; - Player *player = Game::getSingleton()->getPlayer(playerId); - - Root *root = Root::getSingleton(); - Material *mat = new Material(root->getLibPath() + "text"); - mat->addBoolUniform("texturingEnabled", false); - mat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1)); - const int numPairs = 7; + Player *player = Game::getSingleton()->getPlayer(playerId); pair unitDataPairs[numPairs]{ make_pair("pl", stringToWstring(player->getName())), make_pair("vb", to_wstring(player->getNumVehiclesBuilt())), @@ -33,8 +26,11 @@ namespace battleship{ make_pair("sd", to_wstring(player->getNumStructuresDestroyed())), make_pair("sl", to_wstring(player->getNumStructuresLost())), }; + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); Vector3 plCol = player->getColor(); + Root *root = Root::getSingleton(); + string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"; for(int i = 0; i < numPairs; i++){ Text *category = guiManager->getText(unitDataPairs[i].first); diff --git a/unit.cpp b/unit.cpp index e5a3ee0..ca2b6c7 100755 --- a/unit.cpp +++ b/unit.cpp @@ -145,9 +145,23 @@ namespace battleship{ Unit *targetUnit = orders[0].targets[0].unit; - if(targetUnit) + if(targetUnit){ targetUnit->takeDamage(damage); + if(targetUnit->getHealth() <= DEATH_HP){ + Player *targUnitPlayer = targetUnit->getPlayer(); + + if(targetUnit->isVehicle()){ + player->incVehiclesDestroyed(); + targUnitPlayer->incVehiclesLost(); + } + else{ + player->incStructuresDestroyed(); + targUnitPlayer->incStructuresLost(); + } + } + } + lastFireTime = getTime(); } @@ -187,7 +201,7 @@ namespace battleship{ for(GarrisonSlot &slot : garrisonSlots) displayUnitStats(slot.foreground, slot.background, (int)((bool)slot.vehicle), (int)true, mainPlayerSelecting, slot.offset); - if (health <= 0) + if (health <= DEATH_HP) blowUp(); } diff --git a/unit.h b/unit.h index 355af91..d09999a 100755 --- a/unit.h +++ b/unit.h @@ -91,6 +91,7 @@ namespace battleship{ inline UnitClass getUnitClass() {return unitClass;} inline void takeDamage(int damage) {health -= damage;} inline int getPlayerId() {return playerId;} + inline int getHealth(){return health;} inline bool isVehicle(){return gameBase::generateView()["units"]["isVehicle"][id + 1];} inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;} private: @@ -99,7 +100,7 @@ namespace battleship{ void init(); inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;} - const int orderVecDispLength = 2000; + const int orderVecDispLength = 2000, DEATH_HP = 0; sf::SoundBuffer *selectionSfxBuffer; sf::Sound *selectionSfx = nullptr; vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr;