From 0039354c15a2e98b68d88319f14214783cd75d1c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 11 Nov 2011 04:17:55 +0000 Subject: [PATCH] - added name to attack-boosts and shared attack boosts per unit type --- source/glest_game/type_instances/unit.cpp | 2 +- source/glest_game/types/skill_type.cpp | 227 ++++++++++++---------- source/glest_game/types/skill_type.h | 27 ++- source/glest_game/types/tech_tree.cpp | 12 ++ source/glest_game/types/tech_tree.h | 2 + source/glest_game/types/unit_type.cpp | 9 +- 6 files changed, 172 insertions(+), 107 deletions(-) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 632a8358..957d5298 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1875,7 +1875,7 @@ bool Unit::unitHasAttackBoost(const AttackBoost *boost, const Unit *source) cons bool result = false; for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { const UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; - if( effect != NULL && effect->boost == boost && + if( effect != NULL && effect->boost->name == boost->name && effect->source->getType()->getId() == source->getType()->getId()) { result = true; break; diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index f790f71b..16530e0d 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -28,6 +28,7 @@ using namespace Shared::Graphics; namespace Glest{ namespace Game{ +int SkillType::nextAttackBoostId = 0; AttackBoost::AttackBoost() { enabled = false; @@ -163,8 +164,115 @@ SkillType::~SkillType() { } } -void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, - const FactionType *ft, std::map > > &loadedFileList, +const XmlNode * SkillType::findAttackBoostDetails(string attackBoostName, + const XmlNode *attackBoostsNode,const XmlNode *attackBoostNode) { + const XmlNode *result = attackBoostNode; + + if(attackBoostsNode != NULL && attackBoostName != "") { + for(int i = 0; i < attackBoostsNode->getChildCount(); ++i) { + const XmlNode *abn= attackBoostsNode->getChild("attack-boost", i); + + string sharedName = abn->getAttribute("name")->getRestrictedValue(); + if(sharedName == attackBoostName) { + result = abn; + break; + } + } + + } + + return result; +} + +void SkillType::loadAttackBoost(const XmlNode *attackBoostsNode, const XmlNode *attackBoostNode, + const FactionType *ft, string parentLoader, const string & dir, + string currentPath, std::map > > & loadedFileList, + const TechTree *tt) { + + attackBoost.enabled = true; + if(attackBoostNode->hasAttribute("name") == true) { + attackBoost.name = attackBoostNode->getAttribute("name")->getRestrictedValue(); + + attackBoostNode = findAttackBoostDetails(attackBoost.name,attackBoostsNode,attackBoostNode); + } + else { + attackBoost.name = "attack-boost-autoname-" + intToStr(getNextAttackBoostId()); + } + string targetType = attackBoostNode->getChild("target")->getAttribute("value")->getValue(); + attackBoost.allowMultipleBoosts = attackBoostNode->getChild("allow-multiple-boosts")->getAttribute("value")->getBoolValue(); + attackBoost.radius = attackBoostNode->getChild("radius")->getAttribute("value")->getIntValue(); + attackBoost.includeSelf = false; + + if(attackBoostNode->getChild("target")->hasAttribute("include-self") == true) { + attackBoost.includeSelf = attackBoostNode->getChild("target")->getAttribute("include-self")->getBoolValue(); + } + if(targetType == "ally") { + attackBoost.targetType = abtAlly; + for(int i = 0;i < attackBoostNode->getChild("target")->getChildCount();++i) { + const XmlNode *boostUnitNode = attackBoostNode->getChild("target")->getChild("unit-type", i); + attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); + } + } + else if(targetType == "foe") { + attackBoost.targetType = abtFoe; + for(int i = 0;i < attackBoostNode->getChild("target")->getChildCount();++i) { + const XmlNode *boostUnitNode = attackBoostNode->getChild("target")->getChild("unit-type", i); + attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); + } + } + else if(targetType == "faction") { + attackBoost.targetType = abtFaction; + for(int i = 0;i < attackBoostNode->getChild("target")->getChildCount();++i) { + const XmlNode *boostUnitNode = attackBoostNode->getChild("target")->getChild("unit-type", i); + attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); + } + } + else if(targetType == "unit-types") { + attackBoost.targetType = abtUnitTypes; + for(int i = 0;i < attackBoostNode->getChild("target")->getChildCount();++i) { + const XmlNode *boostUnitNode = attackBoostNode->getChild("target")->getChild("unit-type", i); + attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); + } + } + else if(targetType == "all") { + attackBoost.targetType = abtAll; + for(int i = 0;i < attackBoostNode->getChild("target")->getChildCount();++i) { + const XmlNode *boostUnitNode = attackBoostNode->getChild("target")->getChild("unit-type", i); + attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); + } + } + else { + char szBuf[4096] = ""; + sprintf(szBuf, "Unsupported target [%s] specified for attack boost for skill [%s] in [%s]", targetType.c_str(), name.c_str(), parentLoader.c_str()); + throw runtime_error(szBuf); + } + + attackBoost.boostUpgrade.load(attackBoostNode); + if(attackBoostNode->hasChild("particles") == true) { + const XmlNode *particleNode = attackBoostNode->getChild("particles"); + bool particleEnabled = particleNode->getAttribute("value")->getBoolValue(); + if(particleEnabled == true) { + if(particleNode->hasChild("originator-particle-file") == true){ + const XmlNode *particleFileNode = particleNode->getChild("originator-particle-file"); + string path = particleFileNode->getAttribute("path")->getRestrictedValue(); + attackBoost.unitParticleSystemTypeForSourceUnit = new UnitParticleSystemType(); + attackBoost.unitParticleSystemTypeForSourceUnit->load(particleFileNode, dir, currentPath + path, &Renderer::getInstance(), loadedFileList, parentLoader, tt->getPath()); + loadedFileList[currentPath + path].push_back(make_pair(parentLoader, particleFileNode->getAttribute("path")->getRestrictedValue())); + } + if(particleNode->hasChild("affected-particle-file") == true) { + const XmlNode *particleFileNode = particleNode->getChild("affected-particle-file"); + string path = particleFileNode->getAttribute("path")->getRestrictedValue(); + attackBoost.unitParticleSystemTypeForAffectedUnit = new UnitParticleSystemType(); + attackBoost.unitParticleSystemTypeForAffectedUnit->load(particleFileNode, dir, currentPath + path, &Renderer::getInstance(), loadedFileList, parentLoader, tt->getPath()); + loadedFileList[currentPath + path].push_back(make_pair(parentLoader, particleFileNode->getAttribute("path")->getRestrictedValue())); + } + } + } +} + +void SkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, + const string &dir, const TechTree *tt, const FactionType *ft, + std::map > > &loadedFileList, string parentLoader) { //name name= sn->getChild("name")->getAttribute("value")->getRestrictedValue(); @@ -272,91 +380,8 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, // attack-boost if(sn->hasChild("attack-boost") == true) { //printf("$$FOUND ATTACK BOOST FOR [%s]\n",parentLoader.c_str()); - - attackBoost.enabled = true; - const XmlNode *attackBoostNode = sn->getChild("attack-boost"); - string targetType = attackBoostNode->getChild("target")->getAttribute("value")->getValue(); - - attackBoost.allowMultipleBoosts = attackBoostNode->getChild("allow-multiple-boosts")->getAttribute("value")->getBoolValue(); - attackBoost.radius = attackBoostNode->getChild("radius")->getAttribute("value")->getIntValue(); - - attackBoost.includeSelf = false; - if(attackBoostNode->getChild("target")->hasAttribute("include-self") == true) { - attackBoost.includeSelf = attackBoostNode->getChild("target")->getAttribute("include-self")->getBoolValue(); - } - - if(targetType == "ally") { - attackBoost.targetType = abtAlly; - - for(int i = 0; i < attackBoostNode->getChild("target")->getChildCount(); ++i) { - const XmlNode *boostUnitNode= attackBoostNode->getChild("target")->getChild("unit-type", i); - attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); - } - } - else if(targetType == "foe") { - attackBoost.targetType = abtFoe; - - for(int i = 0; i < attackBoostNode->getChild("target")->getChildCount(); ++i) { - const XmlNode *boostUnitNode= attackBoostNode->getChild("target")->getChild("unit-type", i); - attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); - } - } - else if(targetType == "faction") { - attackBoost.targetType = abtFaction; - - for(int i = 0; i < attackBoostNode->getChild("target")->getChildCount(); ++i) { - const XmlNode *boostUnitNode= attackBoostNode->getChild("target")->getChild("unit-type", i); - attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); - } - } - else if(targetType == "unit-types") { - attackBoost.targetType = abtUnitTypes; - - for(int i = 0; i < attackBoostNode->getChild("target")->getChildCount(); ++i) { - const XmlNode *boostUnitNode= attackBoostNode->getChild("target")->getChild("unit-type", i); - attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); - } - } - else if(targetType == "all") { - attackBoost.targetType = abtAll; - - for(int i = 0; i < attackBoostNode->getChild("target")->getChildCount(); ++i) { - const XmlNode *boostUnitNode= attackBoostNode->getChild("target")->getChild("unit-type", i); - attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue())); - } - } - else { - char szBuf[4096]=""; - sprintf(szBuf,"Unsupported target [%s] specified for attack boost for skill [%s] in [%s]",targetType.c_str(),name.c_str(),parentLoader.c_str()); - throw runtime_error(szBuf); - } - - attackBoost.boostUpgrade.load(attackBoostNode); - - //particles - if(attackBoostNode->hasChild("particles") == true) { - const XmlNode *particleNode= attackBoostNode->getChild("particles"); - bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); - if(particleEnabled == true) { - if(particleNode->hasChild("originator-particle-file") == true) { - const XmlNode *particleFileNode= particleNode->getChild("originator-particle-file"); - string path= particleFileNode->getAttribute("path")->getRestrictedValue(); - attackBoost.unitParticleSystemTypeForSourceUnit = new UnitParticleSystemType(); - attackBoost.unitParticleSystemTypeForSourceUnit->load(particleFileNode, dir, currentPath + path, &Renderer::getInstance(), - loadedFileList,parentLoader,tt->getPath()); - loadedFileList[currentPath + path].push_back(make_pair(parentLoader,particleFileNode->getAttribute("path")->getRestrictedValue())); - } - if(particleNode->hasChild("affected-particle-file") == true) { - const XmlNode *particleFileNode= particleNode->getChild("affected-particle-file"); - string path= particleFileNode->getAttribute("path")->getRestrictedValue(); - attackBoost.unitParticleSystemTypeForAffectedUnit = new UnitParticleSystemType(); - attackBoost.unitParticleSystemTypeForAffectedUnit->load(particleFileNode, dir, currentPath + path, &Renderer::getInstance(), - loadedFileList,parentLoader,tt->getPath()); - loadedFileList[currentPath + path].push_back(make_pair(parentLoader,particleFileNode->getAttribute("path")->getRestrictedValue())); - } - } - } + loadAttackBoost(attackBoostsNode, attackBoostNode, ft, parentLoader, dir, currentPath, loadedFileList, tt); } } @@ -534,10 +559,11 @@ AttackSkillType::~AttackSkillType() { deleteValues(projSounds.getSounds().begin(), projSounds.getSounds().end()); } -void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, +void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, + const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader) { - SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + SkillType::load(sn, attackBoostsNode,dir, tt, ft, loadedFileList, parentLoader); string currentPath = dir; endPathWithSlash(currentPath); @@ -697,10 +723,11 @@ ProduceSkillType::ProduceSkillType(){ animProgressBound=false; } -void ProduceSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, +void ProduceSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, + const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader) { - SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + SkillType::load(sn, attackBoostsNode,dir, tt, ft, loadedFileList, parentLoader); if(sn->hasChild("anim-progress-bound")){ animProgressBound= sn->getChild("anim-progress-bound")->getAttribute("value")->getBoolValue(); @@ -730,10 +757,11 @@ UpgradeSkillType::UpgradeSkillType(){ animProgressBound=false; } -void UpgradeSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, +void UpgradeSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, + const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader) { - SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + SkillType::load(sn, attackBoostsNode,dir, tt, ft, loadedFileList, parentLoader); if(sn->hasChild("anim-progress-bound")){ animProgressBound= sn->getChild("anim-progress-bound")->getAttribute("value")->getBoolValue(); @@ -762,10 +790,11 @@ BeBuiltSkillType::BeBuiltSkillType(){ animProgressBound=false; } -void BeBuiltSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, +void BeBuiltSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, + const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader) { - SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + SkillType::load(sn, attackBoostsNode,dir, tt, ft, loadedFileList, parentLoader); if(sn->hasChild("anim-progress-bound")){ animProgressBound= sn->getChild("anim-progress-bound")->getAttribute("value")->getBoolValue(); @@ -792,10 +821,11 @@ MorphSkillType::MorphSkillType(){ animProgressBound=false; } -void MorphSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, +void MorphSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, + const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader) { - SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + SkillType::load(sn, attackBoostsNode,dir, tt, ft, loadedFileList, parentLoader); if(sn->hasChild("anim-progress-bound")){ animProgressBound= sn->getChild("anim-progress-bound")->getAttribute("value")->getBoolValue(); @@ -824,10 +854,11 @@ DieSkillType::DieSkillType(){ fade=false; } -void DieSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, +void DieSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, + const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader) { - SkillType::load(sn, dir, tt, ft, loadedFileList, parentLoader); + SkillType::load(sn, attackBoostsNode,dir, tt, ft, loadedFileList, parentLoader); fade= sn->getChild("fade")->getAttribute("value")->getBoolValue(); } diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index a42cdd8e..6db38581 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -97,6 +97,7 @@ public: UnitParticleSystemType *unitParticleSystemTypeForAffectedUnit; bool includeSelf; + string name; bool isAffected(const Unit *source, const Unit *dest) const; }; @@ -131,18 +132,30 @@ protected: RandomGen random; AttackBoost attackBoost; + static int nextAttackBoostId; + static int getNextAttackBoostId() { return ++nextAttackBoostId; } + + const XmlNode * findAttackBoostDetails(string attackBoostName, + const XmlNode *attackBoostsNode,const XmlNode *attackBoostNode); + void loadAttackBoost(const XmlNode *attackBoostsNode, + const XmlNode *attackBoostNode, const FactionType *ft, + string parentLoader, const string & dir, string currentPath, + std::map > > & loadedFileList, const TechTree *tt); + public: UnitParticleSystemTypes unitParticleSystemTypes; public: //varios virtual ~SkillType(); - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader); bool CanCycleNextRandomAnimation(const int *animationRandomCycleCount) const; + static void resetNextAttackBoostId() { nextAttackBoostId=0; } + //get const string &getName() const {return name;} SkillClass getClass() const {return skillClass;} @@ -213,7 +226,7 @@ private: public: AttackSkillType(); ~AttackSkillType(); - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader); virtual string toString() const; @@ -285,7 +298,7 @@ private: public: ProduceSkillType(); bool getAnimProgressBound() const {return animProgressBound;} - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader); @@ -304,7 +317,7 @@ private: public: UpgradeSkillType(); bool getAnimProgressBound() const {return animProgressBound;} - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader); @@ -326,7 +339,7 @@ public: BeBuiltSkillType(); bool getAnimProgressBound() const {return animProgressBound;} - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader); virtual string toString() const; @@ -344,7 +357,7 @@ public: MorphSkillType(); bool getAnimProgressBound() const {return animProgressBound;} - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader); @@ -364,7 +377,7 @@ public: DieSkillType(); bool getFade() const {return fade;} - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + virtual void load(const XmlNode *sn, const XmlNode *attackBoostsNode, const string &dir, const TechTree *tt, const FactionType *ft, std::map > > &loadedFileList, string parentLoader); virtual string toString() const; diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index 1f795e7e..7d636dd2 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -32,6 +32,18 @@ namespace Glest{ namespace Game{ // class TechTree // ===================================================== +TechTree::TechTree() { + SkillType::resetNextAttackBoostId(); + + name=""; + treePath=""; + + resourceTypes.clear(); + factionTypes.clear(); + armorTypes.clear(); + attackTypes.clear(); +} + Checksum TechTree::loadTech(const vector pathList, const string &techName, set &factions, Checksum* checksum, std::map > > &loadedFileList) { name = ""; diff --git a/source/glest_game/types/tech_tree.h b/source/glest_game/types/tech_tree.h index 2d893a9f..928b76e5 100644 --- a/source/glest_game/types/tech_tree.h +++ b/source/glest_game/types/tech_tree.h @@ -53,6 +53,8 @@ public: set &factions, Checksum* checksum, std::map > > &loadedFileList); void load(const string &dir, set &factions, Checksum* checksum, Checksum *techtreeChecksum, std::map > > &loadedFileList); + + TechTree(); ~TechTree(); Checksum * getChecksumValue() { return &checksumValue; } diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 8659e800..827d02e7 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -512,6 +512,12 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, } //skills + + const XmlNode *attackBoostsNode= NULL; + if(unitNode->hasChild("attack-boosts") == true) { + attackBoostsNode=unitNode->getChild("attack-boosts"); + } + const XmlNode *skillsNode= unitNode->getChild("skills"); skillTypes.resize(skillsNode->getChildCount()); for(int i = 0; i < skillTypes.size(); ++i) { @@ -519,7 +525,8 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const XmlNode *typeNode= sn->getChild("type"); string classId= typeNode->getAttribute("value")->getRestrictedValue(); SkillType *skillType= SkillTypeFactory::getInstance().newInstance(classId); - skillType->load(sn, dir, techTree, factionType, loadedFileList,sourceXMLFile); + + skillType->load(sn, attackBoostsNode, dir, techTree, factionType, loadedFileList,sourceXMLFile); skillTypes[i]= skillType; }