Implemented rest of resource amount/loss attrs
This commit is contained in:
parent
23deb957a7
commit
df0d7aaac9
|
@ -598,14 +598,40 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
|
||||||
|
|
||||||
for(int i=0; i < deathResourcesNode->getChildCount(); ++i){
|
for(int i=0; i < deathResourcesNode->getChildCount(); ++i){
|
||||||
const XmlNode *resourceNode= deathResourcesNode->getChild("resource", i);
|
const XmlNode *resourceNode= deathResourcesNode->getChild("resource", i);
|
||||||
|
|
||||||
// TODO: Add rest of attributes and make appropriate ones optional
|
|
||||||
string name= resourceNode->getAttribute("name")->getRestrictedValue();
|
string name= resourceNode->getAttribute("name")->getRestrictedValue();
|
||||||
int amountValue= resourceNode->getAttribute("amount-value")->getIntValue();
|
|
||||||
|
|
||||||
LootableResource resource;
|
LootableResource resource;
|
||||||
resource.setResourceType(techTree->getResourceType(name));
|
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);
|
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
|
//image
|
||||||
const XmlNode *imageNode= parametersNode->getChild("image");
|
const XmlNode *imageNode= parametersNode->getChild("image");
|
||||||
image= Renderer::getInstance().newTexture2D(rsGame);
|
image= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
|
|
|
@ -2573,10 +2573,22 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
|
||||||
attacker->incKills(attacked->getTeam());
|
attacker->incKills(attacked->getTeam());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add looting here
|
|
||||||
int lootableResourceCount = attacked->getType()->getLootableResourceCount();
|
int lootableResourceCount = attacked->getType()->getLootableResourceCount();
|
||||||
for(int i = 0; i < lootableResourceCount; i++) {
|
for(int i = 0; i < lootableResourceCount; i++) {
|
||||||
LootableResource resource = attacked->getType()->getLootableResource(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());
|
attacker->getFaction()->incResourceAmount(resource.getResourceType(), resource.getAmountValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue