diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 6f3fb13d..f4327201 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -598,14 +598,40 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, for(int i=0; i < deathResourcesNode->getChildCount(); ++i){ const XmlNode *resourceNode= deathResourcesNode->getChild("resource", i); - - // TODO: Add rest of attributes and make appropriate ones optional string name= resourceNode->getAttribute("name")->getRestrictedValue(); - int amountValue= resourceNode->getAttribute("amount-value")->getIntValue(); LootableResource resource; resource.setResourceType(techTree->getResourceType(name)); - resource.setAmountValue(amountValue); + + // All attributes are optional, although nothing happens if they aren't used. They can + // be combined freely. Percentages will take affect before absolute values. + if(resourceNode->hasAttribute("amount-value")) { + resource.setAmountValue(resourceNode->getAttribute("amount-value")->getIntValue()); + } + else { + resource.setAmountValue(0); + } + + if(resourceNode->hasAttribute("amount-percentage")) { + resource.setAmountPercentage(resourceNode->getAttribute("amount-percentage")->getFloatValue()); + } + else { + resource.setAmountPercentage(0); + } + + if(resourceNode->hasAttribute("loss-value")) { + resource.setLossValue(resourceNode->getAttribute("loss-value")->getIntValue()); + } + else { + resource.setLossValue(0); + } + + if(resourceNode->hasAttribute("loss-percentage")) { + resource.setLossPercentage(resourceNode->getAttribute("loss-percentage")->getFloatValue()); + } + else { + resource.setLossPercentage(0); + } lootableResources.push_back(resource); @@ -613,11 +639,6 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, } } - // TODO: For debug purposes only -- remove - for(int i = 0; i < lootableResources.size(); i++) { - printf("Lootable resource %s has amount %d\n", lootableResources[i].getResourceType()->getName().c_str(), lootableResources[i].getAmountValue()); - } - //image const XmlNode *imageNode= parametersNode->getChild("image"); image= Renderer::getInstance().newTexture2D(rsGame); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 4ee4a4b6..08e4d139 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -2573,10 +2573,22 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac attacker->incKills(attacked->getTeam()); } - // TODO: Add looting here int lootableResourceCount = attacked->getType()->getLootableResourceCount(); for(int i = 0; i < lootableResourceCount; i++) { LootableResource resource = attacked->getType()->getLootableResource(i); + + // Figure out how much of the resource in question that the attacked unit's faction has + int factionTotalResource = 0; + for(int j = 0; j < attacked->getFaction()->getTechTree()->getResourceTypeCount(); j++) { + if(attacked->getFaction()->getTechTree()->getResourceType(j) == resource.getResourceType()) { + factionTotalResource = attacked->getFaction()->getResource(j)->getAmount(); + break; + } + } + + attacked->getFaction()->incResourceAmount(resource.getResourceType(), -resource.getLossPercentage() * factionTotalResource); + attacked->getFaction()->incResourceAmount(resource.getResourceType(), -resource.getLossValue()); + attacker->getFaction()->incResourceAmount(resource.getResourceType(), resource.getAmountPercentage() * factionTotalResource); attacker->getFaction()->incResourceAmount(resource.getResourceType(), resource.getAmountValue()); }