From ef0cf706b39c82b1df18c36f91a6859d63a46708 Mon Sep 17 00:00:00 2001 From: Mike Hoffert Date: Sat, 19 Jul 2014 18:59:11 -0600 Subject: [PATCH] Converted percentages to use int instead of float May help prevent floating point calculation errors in multiplayer. --- source/glest_game/type_instances/unit.cpp | 4 ++-- source/glest_game/types/unit_type.cpp | 4 ++-- source/glest_game/types/unit_type.h | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 9ba9d44b..74e75b49 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1959,7 +1959,7 @@ void Unit::born(const CommandType *ct) { this->hp= type->getStartHpValue(); } else { - this->hp= type->getStartHpPercentage() * type->getTotalMaxHp(&totalUpgrade); + this->hp= type->getTotalMaxHp(&totalUpgrade) * 100 / type->getStartHpPercentage(); } if(original_hp != this->hp) { @@ -1975,7 +1975,7 @@ void Unit::born(const CommandType *ct) { this->ep= type->getStartEpValue(); } else { - this->ep= type->getStartEpPercentage() * type->getTotalMaxEp(&totalUpgrade); + this->ep= type->getTotalMaxEp(&totalUpgrade) * 100 / type->getStartEpPercentage(); } } diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index c8e0be10..7d926fb8 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -271,7 +271,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, //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(); + startHpPercentage= parametersNode->getChild("max-hp")->getAttribute("start-percentage")->getIntValue(); startHpType= stPercentage; } @@ -301,7 +301,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, //startEpPercentage -- the *relative* value to use for starting EP if(parametersNode->getChild("max-ep")->hasAttribute("start-percentage")) { - startEpPercentage= parametersNode->getChild("max-ep")->getAttribute("start-percentage")->getFloatValue(); + startEpPercentage= parametersNode->getChild("max-ep")->getAttribute("start-percentage")->getIntValue(); startEpType= stPercentage; } addItemToVault(&(this->startEpPercentage),this->startEpPercentage); diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index d623eec0..afe5cc05 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -110,12 +110,12 @@ private: int id; int maxHp; int startHpValue; - double startHpPercentage; + int startHpPercentage; StartType startHpType; int hpRegeneration; int maxEp; int startEpValue; - double startEpPercentage; + int startEpPercentage; StartType startEpType; int epRegeneration; int maxUnitCount; @@ -190,12 +190,12 @@ public: 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 int 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;} - inline double getStartEpPercentage() const {return startEpPercentage;} + inline int getStartEpPercentage() const {return startEpPercentage;} inline StartType getStartEpType() const {return startEpType;} inline int getMaxUnitCount() const {return maxUnitCount;} inline bool getField(Field field) const {return fields[field];}