Skip to content
Permalink
Browse files
Looting
  • Loading branch information
titiger committed Jul 22, 2014
1 parent af634f2 commit 082f3472ee2f4e58cd1379030dfacdafd5682e23
Showing with 19 additions and 19 deletions.
  1. +2 −2 source/glest_game/type_instances/unit.cpp
  2. +7 −7 source/glest_game/types/unit_type.cpp
  3. +6 −6 source/glest_game/types/unit_type.h
  4. +4 −4 source/glest_game/world/unit_updater.cpp
@@ -35,8 +35,8 @@ using namespace Shared::Util;

namespace Glest{ namespace Game{

const int CHANGE_COMMAND_SPEED = 325;
const int MIN_FRAMECOUNT_CHANGE_COMMAND_SPEED = 160;
const uint CHANGE_COMMAND_SPEED = 325;
const uint MIN_FRAMECOUNT_CHANGE_COMMAND_SPEED = 160;

//Mutex Unit::mutexDeletedUnits;
//map<void *,bool> Unit::deletedUnits;
@@ -597,7 +597,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
if(parametersNode->hasChild("resources-death")) {
const XmlNode *deathResourcesNode= parametersNode->getChild("resources-death");

for(int i=0; i < deathResourcesNode->getChildCount(); ++i){
for(uint i=0; i < deathResourcesNode->getChildCount(); ++i){
const XmlNode *resourceNode= deathResourcesNode->getChild("resource", i);
string name= resourceNode->getAttribute("name")->getRestrictedValue();

@@ -613,11 +613,11 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
resource.setAmountValue(0);
}

if(resourceNode->hasAttribute("faction-amount-percentage")) {
resource.setAmountPercentage(resourceNode->getAttribute("faction-amount-percentage")->getIntValue());
if(resourceNode->hasAttribute("amount-faction-percent")) {
resource.setAmountFactionPercent(resourceNode->getAttribute("amount-faction-percent")->getIntValue());
}
else {
resource.setAmountPercentage(0);
resource.setAmountFactionPercent(0);
}

if(resourceNode->hasAttribute("loss-value")) {
@@ -627,11 +627,11 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
resource.setLossValue(0);
}

if(resourceNode->hasAttribute("faction-loss-percentage")) {
resource.setLossPercentage(resourceNode->getAttribute("faction-loss-percentage")->getIntValue());
if(resourceNode->hasAttribute("loss-faction-percent")) {
resource.setLossFactionPercent(resourceNode->getAttribute("loss-faction-percent")->getIntValue());
}
else {
resource.setLossPercentage(0);
resource.setLossFactionPercent(0);
}

if(resourceNode->hasAttribute("allow-negative")) {
@@ -73,9 +73,9 @@ class LootableResource {
private:
const ResourceType *type;
int amountValue;
int amountPercentage;
int amountFactionPercent;
int lossValue;
int lossPercentage;
int lossFactionPercent;
bool negativeAllowed;

public:
@@ -85,14 +85,14 @@ class LootableResource {
int getAmountValue() const {return amountValue;}
void setAmountValue(int amountValue) {this->amountValue=amountValue;}

int getAmountPercentage() const {return amountPercentage;}
void setAmountPercentage(int amountPercentage) {this->amountPercentage=amountPercentage;}
int getAmountFactionPercent() const {return amountFactionPercent;}
void setAmountFactionPercent(int amountPercentage) {this->amountFactionPercent=amountPercentage;}

int getLossValue() const {return lossValue;}
void setLossValue(int lossValue) {this->lossValue=lossValue;}

int getLossPercentage() const {return lossPercentage;}
void setLossPercentage(int lossPercentage) {this->lossPercentage=lossPercentage;}
int getLossFactionPercent() const {return lossFactionPercent;}
void setLossFactionPercent(int lossPercentage) {this->lossFactionPercent=lossPercentage;}

bool isNegativeAllowed() const {return negativeAllowed;}
void setNegativeAllowed(bool negativeAllowed) {this->negativeAllowed=negativeAllowed;}
@@ -2603,16 +2603,16 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
}

if(resource.isNegativeAllowed()) {
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -(factionTotalResource * resource.getLossPercentage() / 100));
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -(factionTotalResource * resource.getLossFactionPercent() / 100));
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -resource.getLossValue());
attacker->getFaction()->incResourceAmount(resource.getResourceType(), factionTotalResource * resource.getAmountPercentage() / 100);
attacker->getFaction()->incResourceAmount(resource.getResourceType(), factionTotalResource * resource.getAmountFactionPercent() / 100);
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)(factionTotalResource * resource.getLossPercentage() / 100, factionTotalResource));
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -(std::min)(factionTotalResource * resource.getLossFactionPercent() / 100, factionTotalResource));
attacked->getFaction()->incResourceAmount(resource.getResourceType(), -(std::min)(resource.getLossValue(), factionTotalResource));
attacker->getFaction()->incResourceAmount(resource.getResourceType(), (std::min)(factionTotalResource * resource.getAmountPercentage() / 100, factionTotalResource));
attacker->getFaction()->incResourceAmount(resource.getResourceType(), (std::min)(factionTotalResource * resource.getAmountFactionPercent() / 100, factionTotalResource));
attacker->getFaction()->incResourceAmount(resource.getResourceType(), (std::min)(resource.getAmountValue(), factionTotalResource));
}
}

0 comments on commit 082f347

Please sign in to comment.