From 701db5b4222637e9d03bc482abfcbfdb0c4a9395 Mon Sep 17 00:00:00 2001 From: Helana Nady Date: Thu, 16 May 2024 22:48:34 +0300 Subject: [PATCH] :zap: Added condition to check first UMLjointTime (#73) * :zap: Added condition to check first UMLjointTime * :art: Auto formatted files --------- Co-authored-by: AhmedSobhy01 --- UnitClasses/HealableUnit.cpp | 13 ++++++++++--- UnitClasses/HealableUnit.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/UnitClasses/HealableUnit.cpp b/UnitClasses/HealableUnit.cpp index 65a5c91..c50b46f 100644 --- a/UnitClasses/HealableUnit.cpp +++ b/UnitClasses/HealableUnit.cpp @@ -2,7 +2,7 @@ #include "../Game.h" HealableUnit::HealableUnit(Game* gamePtr, UnitType unitType, double health, int power, int attackCapacity) - : Unit(gamePtr, unitType, health, power, attackCapacity), UMLjoinTime(0) + : Unit(gamePtr, unitType, health, power, attackCapacity), UMLjoinTime(-1) {} bool HealableUnit::needsHeal() const @@ -22,6 +22,11 @@ bool HealableUnit::isHealed() const return health > initialHealth * 0.2; } +bool HealableUnit::hasBeenInUMLbefore() const +{ + return UMLjoinTime != -1; +} + void HealableUnit::receiveHeal(double UHP) { // Infected units get twice the time to get healed @@ -33,5 +38,7 @@ void HealableUnit::receiveHeal(double UHP) void HealableUnit::setUMLjoinTime(int UMLjoinTime) { - this->UMLjoinTime = UMLjoinTime; -} \ No newline at end of file + // Check if it's the unit first time to join uml + if (!hasBeenInUMLbefore()) + this->UMLjoinTime = UMLjoinTime; +} diff --git a/UnitClasses/HealableUnit.h b/UnitClasses/HealableUnit.h index 0be24c3..cf2c020 100644 --- a/UnitClasses/HealableUnit.h +++ b/UnitClasses/HealableUnit.h @@ -17,6 +17,7 @@ class HealableUnit: public Unit bool needsHeal() const; // Check if the unit is eligible for healing bool hasWaitedForTooLong() const; // Decides whether to kill or heal the unit based on its wait time bool isHealed() const; // Checks if the unit's health has increased enough + bool hasBeenInUMLbefore() const; // Check if it has been inside uml before or not void receiveHeal(double); // Increase the health of the unit by "UHP"