From e31192db9f0802844f276a5fc85c4d37ab1d207e Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 11 Oct 2013 02:15:49 +0000 Subject: [PATCH] - added support for morph command type to use: --- source/glest_game/type_instances/faction.cpp | 25 ++++++++++++++------ source/glest_game/type_instances/faction.h | 2 +- source/glest_game/type_instances/unit.cpp | 5 ++-- source/glest_game/types/command_type.cpp | 9 ++++++- source/glest_game/types/command_type.h | 2 ++ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index e85a2d89..721c7722 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -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; igetStoredResourceCount(); ++i){ - const Resource *r= unitType->getStoredResource(i); - for(int j=0; jgetType() == 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()); + } } } } diff --git a/source/glest_game/type_instances/faction.h b/source/glest_game/type_instances/faction.h index 8e190376..404b0809 100644 --- a/source/glest_game/type_instances/faction.h +++ b/source/glest_game/type_instances/faction.h @@ -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 diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index b4971a43..13d5e2de 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -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; diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index e459af12..9a313e1f 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -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; diff --git a/source/glest_game/types/command_type.h b/source/glest_game/types/command_type.h index 4335050d..27c77c99 100644 --- a/source/glest_game/types/command_type.h +++ b/source/glest_game/types/command_type.h @@ -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; } };