allow attack boost to apply to self via attribute include-self="true"

This commit is contained in:
Mark Vejvoda 2011-11-04 04:51:12 +00:00
parent cbdde66999
commit db91ca6b9e
4 changed files with 86 additions and 57 deletions

View File

@ -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;

View File

@ -96,6 +96,8 @@ public:
UnitParticleSystemType *unitParticleSystemTypeForSourceUnit;
UnitParticleSystemType *unitParticleSystemTypeForAffectedUnit;
bool includeSelf;
bool isAffected(const Unit *source, const Unit *dest) const;
};

View File

@ -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<XmlNode *> getChildList(const string &childName) const;

View File

@ -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()) {