- added support for morph command type to use:
<replace-storage value="true" />
This commit is contained in:
parent
8e2da49b84
commit
e31192db9f
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -846,6 +846,7 @@ MorphCommandType::MorphCommandType(){
|
|||
morphUnit=NULL;
|
||||
discount=0;
|
||||
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;
|
||||
|
|
|
@ -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; }
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue