Skip to content
Permalink
Browse files
Replace resource storage when morphing a unit instead of adding it.
 "replace-storage" switch from morph command is removed too,
as it was not used and is quite useless now.
https://forum.megaglest.org/index.php?topic=9244.0
  • Loading branch information
titiger committed Jan 16, 2015
1 parent 7006c26 commit 667b043393ace7c0a28bfc5988960d2f25b238ac
@@ -1354,7 +1354,7 @@ void Faction::removeUnit(Unit *unit){
//assert(false);
}

void Faction::addStore(const UnitType *unitType, bool replaceStorage) {
void Faction::addStore(const UnitType *unitType) {
assert(unitType != NULL);
for(int newUnitStoredResourceIndex = 0;
newUnitStoredResourceIndex < unitType->getStoredResourceCount();
@@ -1367,12 +1367,7 @@ void Faction::addStore(const UnitType *unitType, bool replaceStorage) {
Resource *storedResource= &store[currentStoredResourceIndex];

if(storedResource->getType() == newUnitStoredResource->getType()) {
if(replaceStorage == true) {
storedResource->setAmount(newUnitStoredResource->getAmount());
}
else {
storedResource->setAmount(storedResource->getAmount() + newUnitStoredResource->getAmount());
}
storedResource->setAmount(storedResource->getAmount() + newUnitStoredResource->getAmount());
}
}
}
@@ -329,7 +329,7 @@ class Faction {
Unit *findUnit(int id) const;
void addUnit(Unit *unit);
void removeUnit(Unit *unit);
void addStore(const UnitType *unitType, bool replaceStorage);
void addStore(const UnitType *unitType);
void removeStore(const UnitType *unitType);

//resources
@@ -1999,7 +1999,7 @@ void Unit::born(const CommandType *ct) {
throw megaglest_runtime_error(szBuf);
}

faction->addStore(type,false);
faction->addStore(type);
faction->applyStaticProduction(type,ct);
setCurrSkill(scStop);

@@ -3672,7 +3672,10 @@ bool Unit::morph(const MorphCommandType *mct) {
map->putUnitCells(this, this->pos);

this->faction->applyDiscount(morphUnitType, mct->getDiscount());
this->faction->addStore(this->type,mct->getReplaceStorage());
// add new storage
this->faction->addStore(this->type);
// remove former storage
this->faction->removeStore(this->preMorph_type);
this->faction->applyStaticProduction(morphUnitType,mct);

this->level= NULL;
@@ -852,7 +852,6 @@ MorphCommandType::MorphCommandType(){
morphUnit=NULL;
discount=0;
ignoreResourceRequirements = false;
replaceStorage = false;
}

void MorphCommandType::update(UnitUpdater *unitUpdater, Unit *unit, int frameIndex) const {
@@ -882,11 +881,6 @@ 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__);
}

@@ -418,7 +418,6 @@ class MorphCommandType: public CommandType {
const UnitType* morphUnit;
int discount;
bool ignoreResourceRequirements;
bool replaceStorage;

public:
MorphCommandType();
@@ -437,7 +436,6 @@ class MorphCommandType: public CommandType {
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; }
};

0 comments on commit 667b043

Please sign in to comment.