Converted floats to ints

As discussed with Titi, this may prevent some issues with multiplayer
getting out of sync due to different floating point calculations.
This commit is contained in:
Mike Hoffert 2014-07-19 19:03:33 -06:00
parent 9883bf7656
commit f0801b3c33
3 changed files with 12 additions and 12 deletions

View File

@ -614,7 +614,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
}
if(resourceNode->hasAttribute("amount-percentage")) {
resource.setAmountPercentage(resourceNode->getAttribute("amount-percentage")->getFloatValue());
resource.setAmountPercentage(resourceNode->getAttribute("amount-percentage")->getIntValue());
}
else {
resource.setAmountPercentage(0);
@ -628,7 +628,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
}
if(resourceNode->hasAttribute("loss-percentage")) {
resource.setLossPercentage(resourceNode->getAttribute("loss-percentage")->getFloatValue());
resource.setLossPercentage(resourceNode->getAttribute("loss-percentage")->getIntValue());
}
else {
resource.setLossPercentage(0);

View File

@ -73,9 +73,9 @@ class LootableResource {
private:
const ResourceType *type;
int amountValue;
double amountPercentage;
int amountPercentage;
int lossValue;
double lossPercentage;
int lossPercentage;
bool negativeAllowed;
public:
@ -85,14 +85,14 @@ public:
int getAmountValue() const {return amountValue;}
void setAmountValue(int amountValue) {this->amountValue=amountValue;}
double getAmountPercentage() const {return amountPercentage;}
void setAmountPercentage(double amountPercentage) {this->amountPercentage=amountPercentage;}
int getAmountPercentage() const {return amountPercentage;}
void setAmountPercentage(int amountPercentage) {this->amountPercentage=amountPercentage;}
int getLossValue() const {return lossValue;}
void setLossValue(int lossValue) {this->lossValue=lossValue;}
double getLossPercentage() const {return lossPercentage;}
void setLossPercentage(double lossPercentage) {this->lossPercentage=lossPercentage;}
int getLossPercentage() const {return lossPercentage;}
void setLossPercentage(int lossPercentage) {this->lossPercentage=lossPercentage;}
bool isNegativeAllowed() const {return negativeAllowed;}
void setNegativeAllowed(bool negativeAllowed) {this->negativeAllowed=negativeAllowed;}

View File

@ -2589,16 +2589,16 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
}
if(resource.isNegativeAllowed()) {
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -resource.getLossPercentage() * factionTotalResource);
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -(factionTotalResource * 100 / resource.getLossPercentage()));
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -resource.getLossValue());
attacker->getFaction()->incResourceAmount(resource.getResourceType(), resource.getAmountPercentage() * factionTotalResource);
attacker->getFaction()->incResourceAmount(resource.getResourceType(), factionTotalResource * 100 / resource.getAmountPercentage());
attacker->getFaction()->incResourceAmount(resource.getResourceType(), resource.getAmountValue());
}
// Can't take more resources than the faction has, otherwise we end up in the negatives
else {
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -(std::min)(static_cast<int>(resource.getLossPercentage() * factionTotalResource), factionTotalResource));
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -(std::min)(factionTotalResource * 100 / resource.getLossPercentage(), factionTotalResource));
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -(std::min)(resource.getLossValue(), factionTotalResource));
attacker->getFaction()->incResourceAmount(resource.getResourceType(), (std::min)(static_cast<int>(resource.getAmountPercentage() * factionTotalResource), factionTotalResource));
attacker->getFaction()->incResourceAmount(resource.getResourceType(), (std::min)(factionTotalResource * 100 / resource.getAmountPercentage(), factionTotalResource));
attacker->getFaction()->incResourceAmount(resource.getResourceType(), (std::min)(resource.getAmountValue(), factionTotalResource));
}
}