From db91ca6b9e0fdab9e7abab3bda170072d7c6704c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 4 Nov 2011 04:51:12 +0000 Subject: [PATCH] allow attack boost to apply to self via attribute include-self="true" --- source/glest_game/types/skill_type.cpp | 128 ++++++++++--------- source/glest_game/types/skill_type.h | 2 + source/shared_lib/include/xml/xml_parser.h | 2 + source/shared_lib/sources/xml/xml_parser.cpp | 11 ++ 4 files changed, 86 insertions(+), 57 deletions(-) diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index f9d3c20b..f790f71b 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -36,6 +36,7 @@ AttackBoost::AttackBoost() { targetType = abtFaction; unitParticleSystemTypeForSourceUnit = NULL; unitParticleSystemTypeForAffectedUnit = NULL; + includeSelf = false; } AttackBoost::~AttackBoost() { @@ -48,27 +49,16 @@ AttackBoost::~AttackBoost() { bool AttackBoost::isAffected(const Unit *source, const Unit *dest) const { bool result = false; - if(enabled == true && source != NULL && dest != NULL && source != dest) { + if(enabled == true && + source != NULL && dest != NULL && + (includeSelf == true || source != dest)) { bool destUnitMightApply = false; - // All units are affected (including enemies) - if(targetType == abtAll) { - destUnitMightApply = (boostUnitList.empty() == true); - - // Specify which units are affected - for(unsigned int i = 0; i < boostUnitList.size(); ++i) { - const UnitType *ut = boostUnitList[i]; - if(dest->getType()->getId() == ut->getId()) { - destUnitMightApply = true; - break; - } - } - + if(source == dest && includeSelf == true) { + destUnitMightApply = true; } - // Only same faction units are affected - else if(targetType == abtFaction) { - //if(boostUnitList.empty() == true) { - if(source->getFactionIndex() == dest->getFactionIndex()) { - //destUnitMightApply = true; + else { + // All units are affected (including enemies) + if(targetType == abtAll) { destUnitMightApply = (boostUnitList.empty() == true); // Specify which units are affected @@ -81,15 +71,62 @@ bool AttackBoost::isAffected(const Unit *source, const Unit *dest) const { } } - //} - } - // Only ally units are affected - else if(targetType == abtAlly) { - //if(boostUnitList.empty() == true) { - if(source->isAlly(dest) == true) { - //destUnitMightApply = true; - destUnitMightApply = (boostUnitList.empty() == true); + // Only same faction units are affected + else if(targetType == abtFaction) { + //if(boostUnitList.empty() == true) { + if(source->getFactionIndex() == dest->getFactionIndex()) { + //destUnitMightApply = true; + destUnitMightApply = (boostUnitList.empty() == true); + // Specify which units are affected + for(unsigned int i = 0; i < boostUnitList.size(); ++i) { + const UnitType *ut = boostUnitList[i]; + if(dest->getType()->getId() == ut->getId()) { + destUnitMightApply = true; + break; + } + } + + } + //} + } + // Only ally units are affected + else if(targetType == abtAlly) { + //if(boostUnitList.empty() == true) { + if(source->isAlly(dest) == true) { + //destUnitMightApply = true; + destUnitMightApply = (boostUnitList.empty() == true); + + // Specify which units are affected + for(unsigned int i = 0; i < boostUnitList.size(); ++i) { + const UnitType *ut = boostUnitList[i]; + if(dest->getType()->getId() == ut->getId()) { + destUnitMightApply = true; + break; + } + } + } + //} + } + // Only foe units are affected + else if(targetType == abtFoe) { + //if(boostUnitList.empty() == true) { + if(source->isAlly(dest) == false) { + //destUnitMightApply = true; + destUnitMightApply = (boostUnitList.empty() == true); + + // Specify which units are affected + for(unsigned int i = 0; i < boostUnitList.size(); ++i) { + const UnitType *ut = boostUnitList[i]; + if(dest->getType()->getId() == ut->getId()) { + destUnitMightApply = true; + break; + } + } + } + //} + } + else if(targetType == abtUnitTypes) { // Specify which units are affected for(unsigned int i = 0; i < boostUnitList.size(); ++i) { const UnitType *ut = boostUnitList[i]; @@ -99,35 +136,6 @@ bool AttackBoost::isAffected(const Unit *source, const Unit *dest) const { } } } - //} - } - // Only foe units are affected - else if(targetType == abtFoe) { - //if(boostUnitList.empty() == true) { - if(source->isAlly(dest) == false) { - //destUnitMightApply = true; - destUnitMightApply = (boostUnitList.empty() == true); - - // Specify which units are affected - for(unsigned int i = 0; i < boostUnitList.size(); ++i) { - const UnitType *ut = boostUnitList[i]; - if(dest->getType()->getId() == ut->getId()) { - destUnitMightApply = true; - break; - } - } - } - //} - } - else if(targetType == abtUnitTypes) { - // Specify which units are affected - for(unsigned int i = 0; i < boostUnitList.size(); ++i) { - const UnitType *ut = boostUnitList[i]; - if(dest->getType()->getId() == ut->getId()) { - destUnitMightApply = true; - break; - } - } } if(destUnitMightApply == true) { @@ -268,10 +276,16 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, 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(); - string targetType = attackBoostNode->getChild("target")->getAttribute("value")->getValue(); + 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; diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index daf5764a..a42cdd8e 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -96,6 +96,8 @@ public: UnitParticleSystemType *unitParticleSystemTypeForSourceUnit; UnitParticleSystemType *unitParticleSystemTypeForAffectedUnit; + bool includeSelf; + bool isAffected(const Unit *source, const Unit *dest) const; }; diff --git a/source/shared_lib/include/xml/xml_parser.h b/source/shared_lib/include/xml/xml_parser.h index 98f724e6..856ed4f0 100644 --- a/source/shared_lib/include/xml/xml_parser.h +++ b/source/shared_lib/include/xml/xml_parser.h @@ -112,6 +112,8 @@ public: XmlAttribute *getAttribute(unsigned int i) const; XmlAttribute *getAttribute(const string &name,bool mustExist=true) const; + bool hasAttribute(const string &name) const; + XmlNode *getChild(unsigned int i) const; XmlNode *getChild(const string &childName, unsigned int childIndex=0) const; vector getChildList(const string &childName) const; diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index a0de3bc0..7b46ca1d 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -314,6 +314,17 @@ XmlAttribute *XmlNode::getAttribute(const string &name,bool mustExist) const { return NULL; } +bool XmlNode::hasAttribute(const string &name) const { + bool result = false; + for(unsigned int i = 0; i < attributes.size(); ++i) { + if(attributes[i]->getName() == name) { + result = true; + break; + } + } + return result; +} + XmlNode *XmlNode::getChild(unsigned int i) const { assert(!superNode); if(i >= children.size()) {