Implemented starting value for HP

Same syntax as for EP:

    <max-hp value="1000" regeneration="1" start-percentage="1.0" />

Where `start-percentage` can be replaced by `start-value` to use an
absolute number. Note that unlike EP, HP defaults to the max-hp value
*before* upgrades are applied. This behavior is not changed. To make units
spawn with their fully upgraded HP, set their start-percentage to 1.0.
This commit is contained in:
Mike Hoffert 2014-07-19 10:57:34 -06:00
parent 94667b9ab9
commit 0a68e3a6a4
3 changed files with 50 additions and 1 deletions

View File

@ -1951,7 +1951,17 @@ void Unit::born(const CommandType *ct) {
checkItemInVault(&this->hp,this->hp);
int original_hp = this->hp;
this->hp= type->getMaxHp();
//set hp from start hp
checkItemInVault(&this->ep,this->ep);
if(type->getStartHpType() == UnitType::stValue) {
this->hp= type->getStartHpValue();
}
else {
this->hp= type->getStartHpPercentage() * type->getTotalMaxHp(&totalUpgrade);
}
if(original_hp != this->hp) {
//printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__);
game->getScriptManager()->onUnitTriggerEvent(this,utet_HPChanged);

View File

@ -125,6 +125,9 @@ UnitType::UnitType() : ProducibleType() {
epRegeneration= 0;
maxUnitCount= 0;
maxHp=0;
startHpValue=0;
startHpPercentage=1.0;
startHpType=stValue;
maxEp=0;
startEpValue=0;
startEpPercentage=0;
@ -250,6 +253,36 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
}
addItemToVault(&(this->epRegeneration),this->epRegeneration);
// Check that we don't use both start-value and start-percentage, as they are mutually
// exclusive
if(parametersNode->getChild("max-hp")->hasAttribute("start-value") &&
parametersNode->getChild("max-hp")->hasAttribute("start-percentage")) {
throw megaglest_runtime_error("Unit " + name +
" has both start-value and start-percentage for HP", validationMode);
}
//startHpValue -- the *absolute* value to use for starting HP
if(parametersNode->getChild("max-hp")->hasAttribute("start-value")) {
//checkItemInVault(&(this->startEp),this->startEp);
startHpValue= parametersNode->getChild("max-hp")->getAttribute("start-value")->getIntValue();
startHpType= stValue;
}
addItemToVault(&(this->startHpValue),this->startHpValue);
//startHpPercentage -- the *relative* value to use for starting HP
if(parametersNode->getChild("max-hp")->hasAttribute("start-percentage")) {
startHpPercentage= parametersNode->getChild("max-hp")->getAttribute("start-percentage")->getFloatValue();
startHpType= stPercentage;
}
// No start value set; use max HP before upgrades
if(!parametersNode->getChild("max-hp")->hasAttribute("start-value") &&
!parametersNode->getChild("max-hp")->hasAttribute("start-percentage")) {
startHpValue= parametersNode->getChild("max-hp")->getAttribute("value")->getIntValue();
startHpType= stValue;
}
addItemToVault(&(this->startHpPercentage),this->startHpPercentage);
// Check that we don't use both start-value and start-percentage, as they are mutually
// exclusive
if(parametersNode->getChild("max-ep")->hasAttribute("start-value") &&

View File

@ -109,6 +109,9 @@ private:
//basic
int id;
int maxHp;
int startHpValue;
double startHpPercentage;
StartType startHpType;
int hpRegeneration;
int maxEp;
int startEpValue;
@ -186,6 +189,9 @@ public:
inline int getId() const {return id;}
inline int getMaxHp() const {return maxHp;}
inline int getHpRegeneration() const {return hpRegeneration;}
inline int getStartHpValue() const {return startHpValue;}
inline double getStartHpPercentage() const {return startHpPercentage;}
inline StartType getStartHpType() const {return startHpType;}
inline int getMaxEp() const {return maxEp;}
inline int getEpRegeneration() const {return epRegeneration;}
inline int getStartEpValue() const {return startEpValue;}