First, basic looting implementation

Only absolute values are obtained for now, no loss.
This commit is contained in:
Mike Hoffert 2014-07-19 15:37:59 -06:00
parent 0a68e3a6a4
commit 23deb957a7
3 changed files with 68 additions and 0 deletions

View File

@ -592,6 +592,32 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
}
sortedItems.clear();
// Lootable resources
if(parametersNode->hasChild("resources-death")) {
const XmlNode *deathResourcesNode= parametersNode->getChild("resources-death");
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);
lootableResources.push_back(resource);
// TODO: Add checks for duplicate resources
}
}
// 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);

View File

@ -63,6 +63,37 @@ public:
static const Level * loadGame(const XmlNode *rootNode, const UnitType *ut);
};
// ===============================
// class LootResource
//
/// Stores information about a lootable resource. Lootable resources are stolen by the attacker on death.
// ===============================
class LootableResource {
private:
const ResourceType *type;
int amountValue;
double amountPercentage;
int lossValue;
double lossPercentage;
public:
const ResourceType* getResourceType() {return type;}
void setResourceType(const ResourceType *type) {this->type=type;}
int getAmountValue() {return amountValue;}
void setAmountValue(int amountValue) {this->amountValue=amountValue;}
double getAmountPercentage() {return amountPercentage;}
void setAmountPercentage(double amountPercentage) {this->amountPercentage=amountPercentage;}
int getLossValue() {return lossValue;}
void setLossValue(int lossValue) {this->lossValue=lossValue;}
double getLossPercentage() {return lossPercentage;}
void setLossPercentage(double lossPercentage) {this->lossPercentage=lossPercentage;}
};
// ===============================
// class UnitType
//
@ -104,6 +135,7 @@ private:
typedef vector<CommandType*> CommandTypes;
typedef vector<Resource> StoredResources;
typedef vector<Level> Levels;
typedef vector<LootableResource> LootableResources;
private:
//basic
@ -151,6 +183,7 @@ private:
CommandTypes commandTypes;
StoredResources storedResources;
Levels levels;
LootableResources lootableResources;
//meeting point
bool meetingPoint;
@ -220,6 +253,8 @@ public:
int getHeight() const {return height;}
int getStoredResourceCount() const {return (int)storedResources.size();}
inline const Resource *getStoredResource(int i) const {return &storedResources[i];}
int getLootableResourceCount() const {return lootableResources.size();}
inline const LootableResource getLootableResource(int i) const {return lootableResources.at(i);}
bool getCellMapCell(int x, int y, CardinalDir facing) const;
inline bool getMeetingPoint() const {return meetingPoint;}
inline bool getCountUnitDeathInStats() const {return countUnitDeathInStats;}

View File

@ -2573,6 +2573,13 @@ 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);
attacker->getFaction()->incResourceAmount(resource.getResourceType(), resource.getAmountValue());
}
switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic:
break;