First, basic looting implementation
Only absolute values are obtained for now, no loss.
This commit is contained in:
parent
0a68e3a6a4
commit
23deb957a7
|
@ -592,6 +592,32 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
|
||||||
}
|
}
|
||||||
sortedItems.clear();
|
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
|
//image
|
||||||
const XmlNode *imageNode= parametersNode->getChild("image");
|
const XmlNode *imageNode= parametersNode->getChild("image");
|
||||||
image= Renderer::getInstance().newTexture2D(rsGame);
|
image= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
|
|
|
@ -63,6 +63,37 @@ public:
|
||||||
static const Level * loadGame(const XmlNode *rootNode, const UnitType *ut);
|
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
|
// class UnitType
|
||||||
//
|
//
|
||||||
|
@ -104,6 +135,7 @@ private:
|
||||||
typedef vector<CommandType*> CommandTypes;
|
typedef vector<CommandType*> CommandTypes;
|
||||||
typedef vector<Resource> StoredResources;
|
typedef vector<Resource> StoredResources;
|
||||||
typedef vector<Level> Levels;
|
typedef vector<Level> Levels;
|
||||||
|
typedef vector<LootableResource> LootableResources;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//basic
|
//basic
|
||||||
|
@ -151,6 +183,7 @@ private:
|
||||||
CommandTypes commandTypes;
|
CommandTypes commandTypes;
|
||||||
StoredResources storedResources;
|
StoredResources storedResources;
|
||||||
Levels levels;
|
Levels levels;
|
||||||
|
LootableResources lootableResources;
|
||||||
|
|
||||||
//meeting point
|
//meeting point
|
||||||
bool meetingPoint;
|
bool meetingPoint;
|
||||||
|
@ -220,6 +253,8 @@ public:
|
||||||
int getHeight() const {return height;}
|
int getHeight() const {return height;}
|
||||||
int getStoredResourceCount() const {return (int)storedResources.size();}
|
int getStoredResourceCount() const {return (int)storedResources.size();}
|
||||||
inline const Resource *getStoredResource(int i) const {return &storedResources[i];}
|
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;
|
bool getCellMapCell(int x, int y, CardinalDir facing) const;
|
||||||
inline bool getMeetingPoint() const {return meetingPoint;}
|
inline bool getMeetingPoint() const {return meetingPoint;}
|
||||||
inline bool getCountUnitDeathInStats() const {return countUnitDeathInStats;}
|
inline bool getCountUnitDeathInStats() const {return countUnitDeathInStats;}
|
||||||
|
|
|
@ -2573,6 +2573,13 @@ 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();
|
||||||
|
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()) {
|
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||||
case pfBasic:
|
case pfBasic:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue