- added support for morph command type to use:

<replace-storage value="true" />
This commit is contained in:
Mark Vejvoda 2013-10-11 02:15:49 +00:00
parent 8e2da49b84
commit e31192db9f
5 changed files with 32 additions and 11 deletions

View File

@ -1177,14 +1177,25 @@ void Faction::removeUnit(Unit *unit){
//assert(false);
}
void Faction::addStore(const UnitType *unitType){
void Faction::addStore(const UnitType *unitType, bool replaceStorage) {
assert(unitType != NULL);
for(int i=0; i<unitType->getStoredResourceCount(); ++i){
const Resource *r= unitType->getStoredResource(i);
for(int j=0; j<store.size(); ++j){
Resource *storedResource= &store[j];
if(storedResource->getType() == r->getType()){
storedResource->setAmount(storedResource->getAmount() + r->getAmount());
for(int newUnitStoredResourceIndex = 0;
newUnitStoredResourceIndex < unitType->getStoredResourceCount();
++newUnitStoredResourceIndex) {
const Resource *newUnitStoredResource = unitType->getStoredResource(newUnitStoredResourceIndex);
for(int currentStoredResourceIndex = 0;
currentStoredResourceIndex < store.size();
++currentStoredResourceIndex) {
Resource *storedResource= &store[currentStoredResourceIndex];
if(storedResource->getType() == newUnitStoredResource->getType()) {
if(replaceStorage == true) {
storedResource->setAmount(newUnitStoredResource->getAmount());
}
else {
storedResource->setAmount(storedResource->getAmount() + newUnitStoredResource->getAmount());
}
}
}
}

View File

@ -324,7 +324,7 @@ public:
Unit *findUnit(int id) const;
void addUnit(Unit *unit);
void removeUnit(Unit *unit);
void addStore(const UnitType *unitType);
void addStore(const UnitType *unitType, bool replaceStorage);
void removeStore(const UnitType *unitType);
//resources

View File

@ -1737,7 +1737,7 @@ void Unit::born(const CommandType *ct) {
throw megaglest_runtime_error(szBuf);
}
faction->addStore(type);
faction->addStore(type,false);
faction->applyStaticProduction(type,ct);
setCurrSkill(scStop);
@ -3305,8 +3305,9 @@ bool Unit::morph(const MorphCommandType *mct) {
this->currField=morphUnitField;
computeTotalUpgrade();
map->putUnitCells(this, this->pos);
this->faction->applyDiscount(morphUnitType, mct->getDiscount());
this->faction->addStore(this->type);
this->faction->addStore(this->type,mct->getReplaceStorage());
this->faction->applyStaticProduction(morphUnitType,mct);
this->level= NULL;

View File

@ -845,7 +845,8 @@ MorphCommandType::MorphCommandType(){
morphSkillType=NULL;
morphUnit=NULL;
discount=0;
ignoreResourceRequirements=false;
ignoreResourceRequirements = false;
replaceStorage = false;
}
void MorphCommandType::update(UnitUpdater *unitUpdater, Unit *unit, int frameIndex) const {
@ -875,6 +876,11 @@ void MorphCommandType::load(int id, const XmlNode *n, const string &dir,
//printf("ignoreResourceRequirements = %d\n",ignoreResourceRequirements);
}
replaceStorage = false;
if(n->hasChild("replace-storage") == true) {
replaceStorage = n->getChild("replace-storage")->getAttribute("value")->getBoolValue();
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
@ -899,6 +905,7 @@ string MorphCommandType::getDesc(const TotalUpgrade *totalUpgrade, bool translat
}
str+= "\n"+getProduced()->getReqDesc(ignoreResourceRequirements,translatedValue);
str+=morphSkillType->getBoostDesc(translatedValue);
return str;

View File

@ -418,6 +418,7 @@ private:
const UnitType* morphUnit;
int discount;
bool ignoreResourceRequirements;
bool replaceStorage;
public:
MorphCommandType();
@ -436,6 +437,7 @@ public:
const UnitType *getMorphUnit() const {return morphUnit;}
int getDiscount() const {return discount;}
bool getIgnoreResourceRequirements() const {return ignoreResourceRequirements;}
bool getReplaceStorage() const {return replaceStorage;}
virtual bool usesPathfinder() const { return false; }
};