From 4d6f39d257e37cc3b74792c976e60936c4c03b14 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 26 Jun 2011 07:06:32 +0000 Subject: [PATCH] - added support for multipliers in attack-boost --- source/glest_game/type_instances/unit.cpp | 6 +- source/glest_game/type_instances/upgrade.cpp | 2 +- source/glest_game/types/command_type.cpp | 28 +- source/glest_game/types/skill_type.cpp | 12 +- source/glest_game/types/upgrade_type.cpp | 374 ++++++++++++++++--- source/glest_game/types/upgrade_type.h | 57 ++- 6 files changed, 404 insertions(+), 75 deletions(-) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 021b9283..b067d703 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1491,7 +1491,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { effect.source = source; //if(boost->isAffected(source, this)) { - totalUpgrade.apply(&boost->boostUpgrade); + totalUpgrade.apply(&boost->boostUpgrade, this); checkItemInVault(&this->hp,this->hp); hp += boost->boostUpgrade.getMaxHp(); @@ -1524,7 +1524,7 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) { //printf("DE-APPLYING ATTACK BOOST to unit [%s - %d] from unit [%s - %d]\n",this->getType()->getName().c_str(),this->getId(),source->getType()->getName().c_str(),source->getId()); //if(boost->isAffected(source, this)) { - totalUpgrade.deapply(&boost->boostUpgrade); + totalUpgrade.deapply(&boost->boostUpgrade, this); checkItemInVault(&this->hp,this->hp); hp -= boost->boostUpgrade.getMaxHp(); @@ -1830,7 +1830,7 @@ void Unit::applyUpgrade(const UpgradeType *upgradeType){ } if(upgradeType->isAffected(type)){ - totalUpgrade.sum(upgradeType); + totalUpgrade.sum(upgradeType, this); checkItemInVault(&this->hp,this->hp); hp += upgradeType->getMaxHp(); diff --git a/source/glest_game/type_instances/upgrade.cpp b/source/glest_game/type_instances/upgrade.cpp index 8a661417..8ad1a01f 100644 --- a/source/glest_game/type_instances/upgrade.cpp +++ b/source/glest_game/type_instances/upgrade.cpp @@ -213,7 +213,7 @@ void UpgradeManager::computeTotalUpgrade(const Unit *unit, TotalUpgrade *totalUp if((*it)->getFactionIndex() == unit->getFactionIndex() && (*it)->getType()->isAffected(unit->getType()) && (*it)->getState()==usUpgraded) - totalUpgrade->sum((*it)->getType()); + totalUpgrade->sum((*it)->getType(), unit); } } diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index d5752705..ae2f7e7e 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -153,8 +153,8 @@ string MoveCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ str= name+"\n"; str+= lang.get("WalkSpeed")+": "+ intToStr(moveSkillType->getSpeed()); - if(totalUpgrade->getMoveSpeed()!=0){ - str+= "+" + intToStr(totalUpgrade->getMoveSpeed()); + if(totalUpgrade->getMoveSpeed(moveSkillType) != 0) { + str+= "+" + intToStr(totalUpgrade->getMoveSpeed(moveSkillType)); } str+="\n"; if(moveSkillType->getEpCost()!=0){ @@ -218,8 +218,8 @@ string AttackCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ str+= intToStr(attackSkillType->getAttackStrength()-attackSkillType->getAttackVar()); str+= "..."; str+= intToStr(attackSkillType->getAttackStrength()+attackSkillType->getAttackVar()); - if(totalUpgrade->getAttackStrength()!=0){ - str+= "+"+intToStr(totalUpgrade->getAttackStrength()); + if(totalUpgrade->getAttackStrength(attackSkillType) != 0) { + str+= "+"+intToStr(totalUpgrade->getAttackStrength(attackSkillType)); } str+= " ("+ attackSkillType->getAttackType()->getName() +")"; str+= "\n"; @@ -231,8 +231,8 @@ string AttackCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ //attack distance str+= lang.get("AttackDistance")+": "+intToStr(attackSkillType->getAttackRange()); - if(totalUpgrade->getAttackRange()!=0){ - str+= "+"+intToStr(totalUpgrade->getAttackRange()!=0); + if(totalUpgrade->getAttackRange(attackSkillType) != 0) { + str+= "+"+intToStr(totalUpgrade->getAttackRange(attackSkillType) != 0); } str+="\n"; @@ -249,8 +249,8 @@ string AttackCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ //movement speed str+= lang.get("WalkSpeed")+": "+ intToStr(moveSkillType->getSpeed()) ; - if(totalUpgrade->getMoveSpeed()!=0){ - str+= "+"+intToStr(totalUpgrade->getMoveSpeed()); + if(totalUpgrade->getMoveSpeed(moveSkillType) != 0) { + str+= "+"+intToStr(totalUpgrade->getMoveSpeed(moveSkillType)); } str+="\n"; @@ -310,8 +310,8 @@ string AttackStoppedCommandType::getDesc(const TotalUpgrade *totalUpgrade) const str+= intToStr(attackSkillType->getAttackStrength()-attackSkillType->getAttackVar()); str+="..."; str+= intToStr(attackSkillType->getAttackStrength()+attackSkillType->getAttackVar()); - if(totalUpgrade->getAttackStrength()!=0) - str+= "+"+intToStr(totalUpgrade->getAttackStrength()); + if(totalUpgrade->getAttackStrength(attackSkillType) != 0) + str+= "+"+intToStr(totalUpgrade->getAttackStrength(attackSkillType)); str+= " ("+ attackSkillType->getAttackType()->getName() +")"; str+="\n"; @@ -322,8 +322,8 @@ string AttackStoppedCommandType::getDesc(const TotalUpgrade *totalUpgrade) const //attack distance str+= lang.get("AttackDistance")+": "+intToStr(attackSkillType->getAttackRange()); - if(totalUpgrade->getAttackRange()!=0){ - str+= "+"+intToStr(totalUpgrade->getAttackRange()!=0); + if(totalUpgrade->getAttackRange(attackSkillType) != 0) { + str+= "+"+intToStr(totalUpgrade->getAttackRange(attackSkillType) != 0); } str+="\n"; @@ -636,8 +636,8 @@ string ProduceCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{ //prod speed str+= lang.get("ProductionSpeed")+": "+ intToStr(produceSkillType->getSpeed()); - if(totalUpgrade->getProdSpeed()!=0){ - str+="+" + intToStr(totalUpgrade->getProdSpeed()); + if(totalUpgrade->getProdSpeed(produceSkillType)!=0){ + str+="+" + intToStr(totalUpgrade->getProdSpeed(produceSkillType)); } str+="\n"; diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 7e785136..0703c5fd 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -381,7 +381,7 @@ string MoveSkillType::toString() const{ } int MoveSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{ - int result = speed + totalUpgrade->getMoveSpeed(); + int result = speed + totalUpgrade->getMoveSpeed(this); result = max(0,result); return result; } @@ -523,13 +523,13 @@ string AttackSkillType::toString() const{ //get totals int AttackSkillType::getTotalAttackStrength(const TotalUpgrade *totalUpgrade) const{ - int result = attackStrength + totalUpgrade->getAttackStrength(); + int result = attackStrength + totalUpgrade->getAttackStrength(this); result = max(0,result); return result; } int AttackSkillType::getTotalAttackRange(const TotalUpgrade *totalUpgrade) const{ - int result = attackRange + totalUpgrade->getAttackRange(); + int result = attackRange + totalUpgrade->getAttackRange(this); result = max(0,result); return result; } @@ -583,7 +583,7 @@ string ProduceSkillType::toString() const{ } int ProduceSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{ - int result = speed + totalUpgrade->getProdSpeed(); + int result = speed + totalUpgrade->getProdSpeed(this); result = max(0,result); return result; } @@ -601,7 +601,7 @@ string UpgradeSkillType::toString() const{ } int UpgradeSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{ - int result = speed + totalUpgrade->getProdSpeed(); + int result = speed + totalUpgrade->getProdSpeed(this); result = max(0,result); return result; } @@ -631,7 +631,7 @@ string MorphSkillType::toString() const{ } int MorphSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{ - int result = speed + totalUpgrade->getProdSpeed(); + int result = speed + totalUpgrade->getProdSpeed(this); result = max(0,result); return result; } diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 4a449347..222dcab7 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -39,14 +39,139 @@ namespace Glest{ namespace Game{ void UpgradeTypeBase::load(const XmlNode *upgradeNode) { //values + maxHpIsMultiplier = false; maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue(); + if(upgradeNode->getChild("max-hp")->getAttribute("value-percent-multipler",false) != NULL) { + maxHpIsMultiplier = upgradeNode->getChild("max-hp")->getAttribute("value-percent-multipler")->getBoolValue(); + + //printf("Found maxHpIsMultiplier = %d\n",maxHpIsMultiplier); + } + + maxEpIsMultiplier = false; maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue(); + if(upgradeNode->getChild("max-ep")->getAttribute("value-percent-multipler",false) != NULL) { + maxEpIsMultiplier = upgradeNode->getChild("max-ep")->getAttribute("value-percent-multipler")->getBoolValue(); + + //printf("Found maxEpIsMultiplier = %d\n",maxEpIsMultiplier); + } + + sightIsMultiplier = false; sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue(); + if(upgradeNode->getChild("sight")->getAttribute("value-percent-multipler",false) != NULL) { + sightIsMultiplier = upgradeNode->getChild("sight")->getAttribute("value-percent-multipler")->getBoolValue(); + + //printf("Found sightIsMultiplier = %d\n",sightIsMultiplier); + } + + attackStrengthIsMultiplier = false; attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue(); + if(upgradeNode->getChild("attack-strenght")->getAttribute("value-percent-multipler",false) != NULL) { + attackStrengthIsMultiplier = upgradeNode->getChild("attack-strenght")->getAttribute("value-percent-multipler")->getBoolValue(); + + //printf("Found attackStrengthIsMultiplier = %d\n",attackStrengthIsMultiplier); + } + + attackRangeIsMultiplier = false; attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue(); + if(upgradeNode->getChild("attack-range")->getAttribute("value-percent-multipler",false) != NULL) { + attackRangeIsMultiplier = upgradeNode->getChild("attack-range")->getAttribute("value-percent-multipler")->getBoolValue(); + + //printf("Found attackRangeIsMultiplier = %d\n",attackRangeIsMultiplier); + } + + armorIsMultiplier = false; armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue(); + if(upgradeNode->getChild("armor")->getAttribute("value-percent-multipler",false) != NULL) { + armorIsMultiplier = upgradeNode->getChild("armor")->getAttribute("value-percent-multipler")->getBoolValue(); + + //printf("Found armorIsMultiplier = %d\n",armorIsMultiplier); + } + + moveSpeedIsMultiplier = false; moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue(); + if(upgradeNode->getChild("move-speed")->getAttribute("value-percent-multipler",false) != NULL) { + moveSpeedIsMultiplier = upgradeNode->getChild("move-speed")->getAttribute("value-percent-multipler")->getBoolValue(); + + //printf("Found moveSpeedIsMultiplier = %d\n",moveSpeedIsMultiplier); + } + + prodSpeedIsMultiplier = false; prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue(); + if(upgradeNode->getChild("production-speed")->getAttribute("value-percent-multipler",false) != NULL) { + prodSpeedIsMultiplier = upgradeNode->getChild("production-speed")->getAttribute("value-percent-multipler")->getBoolValue(); + + //printf("Found prodSpeedIsMultiplier = %d\n",prodSpeedIsMultiplier); + } +} + +int UpgradeTypeBase::getAttackStrength(const AttackSkillType *st) const { + if(attackStrengthIsMultiplier == false || st == NULL) { + return attackStrength; + } + else { + int result = 0; + if(attackStrengthMultiplierValueList.find(st->getName()) != attackStrengthMultiplierValueList.end()) { + result = attackStrengthMultiplierValueList.find(st->getName())->second; + } + return result; + } +} +int UpgradeTypeBase::getAttackRange(const AttackSkillType *st) const { + if(attackRangeIsMultiplier == false || st == NULL) { + return attackRange; + } + else { + int result = 0; + if(attackRangeMultiplierValueList.find(st->getName()) != attackRangeMultiplierValueList.end()) { + result = attackRangeMultiplierValueList.find(st->getName())->second; + } + return result; + } +} + +int UpgradeTypeBase::getMoveSpeed(const MoveSkillType *st) const { + if(moveSpeedIsMultiplier == false || st == NULL) { + //printf("getMoveSpeed moveSpeedIsMultiplier OFF st [%p]\n",st); + return moveSpeed; + } + else { + int result = 0; + if(moveSpeedIsMultiplierValueList.find(st->getName()) != moveSpeedIsMultiplierValueList.end()) { + result = moveSpeedIsMultiplierValueList.find(st->getName())->second; + } + + //printf("getMoveSpeed moveSpeedIsMultiplier mst->getSpeed() = %d for skill [%s] result = %d\n",st->getSpeed(),st->getName().c_str(),result); + return result; + } +} + +int UpgradeTypeBase::getProdSpeed(const SkillType *st) const { + if(prodSpeedIsMultiplier == false || st == NULL) { + return prodSpeed; + } + else { + int result = 0; + if(dynamic_cast(st) != NULL) { + if(prodSpeedProduceIsMultiplierValueList.find(st->getName()) != prodSpeedProduceIsMultiplierValueList.end()) { + result = prodSpeedProduceIsMultiplierValueList.find(st->getName())->second; + } + } + else if(dynamic_cast(st) != NULL) { + if(prodSpeedUpgradeIsMultiplierValueList.find(st->getName()) != prodSpeedUpgradeIsMultiplierValueList.end()) { + result = prodSpeedUpgradeIsMultiplierValueList.find(st->getName())->second; + } + } + else if(dynamic_cast(st) != NULL) { + if(prodSpeedMorphIsMultiplierValueList.find(st->getName()) != prodSpeedMorphIsMultiplierValueList.end()) { + result = prodSpeedMorphIsMultiplierValueList.find(st->getName())->second; + } + } + else { + throw runtime_error("Unsupported skilltype in getProdSpeed!"); + } + + return result; + } } bool UpgradeType::isAffected(const UnitType *unitType) const{ @@ -166,14 +291,6 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, sortedItems.clear(); //values -// maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue(); -// maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue(); -// sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue(); -// attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue(); -// attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue(); -// armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue(); -// moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue(); -// prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue(); UpgradeTypeBase::load(upgradeNode); } catch(const exception &e){ @@ -247,45 +364,214 @@ void TotalUpgrade::reset() { prodSpeed=0; } -void TotalUpgrade::sum(const UpgradeTypeBase *ut) { - maxHp+= ut->getMaxHp(); - //maxHp = max(0,maxHp); - maxEp+= ut->getMaxEp(); - //maxEp = max(0,maxEp); - sight+= ut->getSight(); - //sight = max(0,sight); - armor+= ut->getArmor(); - //armor = max(0,armor); - attackStrength+= ut->getAttackStrength(); - //attackStrength = max(0,attackStrength); - attackRange+= ut->getAttackRange(); - //attackRange = max(0,attackRange); - moveSpeed+= ut->getMoveSpeed(); - //moveSpeed = max(0,moveSpeed); - prodSpeed+= ut->getProdSpeed(); - //prodSpeed = max(0,prodSpeed); +void TotalUpgrade::sum(const UpgradeTypeBase *ut, const Unit *unit) { + maxHpIsMultiplier = ut->getMaxHpIsMultiplier(); + sightIsMultiplier = ut->getSightIsMultiplier(); + maxEpIsMultiplier = ut->getMaxEpIsMultiplier(); + armorIsMultiplier = ut->getArmorIsMultiplier(); + attackStrengthIsMultiplier = ut->getAttackStrengthIsMultiplier(); + attackRangeIsMultiplier = ut->getAttackRangeIsMultiplier(); + moveSpeedIsMultiplier = ut->getMoveSpeedIsMultiplier(); + prodSpeedIsMultiplier = ut->getProdSpeedIsMultiplier(); + + if(ut->getMaxHpIsMultiplier() == true) { + maxHp += (unit->getHp() * (ut->getMaxHp() / 100)); + } + else { + maxHp += ut->getMaxHp(); + } + + if(ut->getMaxEpIsMultiplier() == true) { + maxEp += (unit->getEp() * (ut->getMaxEp() / 100)); + } + else { + maxEp += ut->getMaxEp(); + } + + if(ut->getSightIsMultiplier() == true) { + sight += (unit->getType()->getSight() * (ut->getSight() / 100)); + } + else { + sight += ut->getSight(); + } + + if(ut->getArmorIsMultiplier() == true) { + armor += (unit->getType()->getArmor() * (ut->getArmor() / 100)); + } + else { + armor += ut->getArmor(); + } + + if(ut->getAttackStrengthIsMultiplier() == true) { + for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { + const SkillType *skillType = unit->getType()->getSkillType(i); + const AttackSkillType *ast = dynamic_cast(skillType); + if(ast != NULL) { + attackStrengthMultiplierValueList[ast->getName()] += (ast->getAttackStrength() * (ut->getAttackStrength(NULL) / 100)); + } + } + } + else { + attackStrength += ut->getAttackStrength(NULL); + } + + if(ut->getAttackRangeIsMultiplier() == true) { + for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { + const SkillType *skillType = unit->getType()->getSkillType(i); + const AttackSkillType *ast = dynamic_cast(skillType); + if(ast != NULL) { + attackRangeMultiplierValueList[ast->getName()] += (ast->getAttackRange() * (ut->getAttackRange(NULL) / 100)); + } + } + } + else { + attackRange += ut->getAttackRange(NULL); + } + + if(ut->getMoveSpeedIsMultiplier() == true) { + //printf("BEFORE Applying moveSpeedIsMultiplier\n"); + + for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { + const SkillType *skillType = unit->getType()->getSkillType(i); + const MoveSkillType *mst = dynamic_cast(skillType); + if(mst != NULL) { + moveSpeedIsMultiplierValueList[mst->getName()] += (mst->getSpeed() * (ut->getMoveSpeed(NULL) / 100)); + + //printf("Applying moveSpeedIsMultiplier for unit [%s - %d], mst->getSpeed() = %d ut->getMoveSpeed(NULL) = %d newmoveSpeed = %d for skill [%s]\n",unit->getType()->getName().c_str(),unit->getId(), mst->getSpeed(),ut->getMoveSpeed(NULL),moveSpeedIsMultiplierValueList[mst->getName()],mst->getName().c_str()); + } + } + + //printf("AFTER Applying moveSpeedIsMultiplierd\n"); + } + else { + moveSpeed += ut->getMoveSpeed(NULL); + } + + if(ut->getProdSpeedIsMultiplier() == true) { + for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { + const SkillType *skillType = unit->getType()->getSkillType(i); + const ProduceSkillType *pst = dynamic_cast(skillType); + if(pst != NULL) { + prodSpeedProduceIsMultiplierValueList[pst->getName()] += (pst->getSpeed() * (ut->getProdSpeed(NULL) / 100)); + } + const UpgradeSkillType *ust = dynamic_cast(skillType); + if(ust != NULL) { + prodSpeedUpgradeIsMultiplierValueList[ust->getName()] += (ust->getSpeed() * (ut->getProdSpeed(NULL) / 100)); + } + const MorphSkillType *mst = dynamic_cast(skillType); + if(mst != NULL) { + prodSpeedMorphIsMultiplierValueList[mst->getName()] += (mst->getSpeed() * (ut->getProdSpeed(NULL) / 100)); + } + } + } + else { + prodSpeed += ut->getProdSpeed(NULL); + } +} + +void TotalUpgrade::apply(const UpgradeTypeBase *ut, const Unit *unit) { + sum(ut, unit); +} + +void TotalUpgrade::deapply(const UpgradeTypeBase *ut,const Unit *unit) { + if(ut->getMaxHpIsMultiplier() == true) { + maxHp -= (unit->getHp() * (ut->getMaxHp() / 100)); + } + else { + maxHp -= ut->getMaxHp(); + } + + if(ut->getMaxEpIsMultiplier() == true) { + maxEp -= (unit->getEp() * (ut->getMaxEp() / 100)); + } + else { + maxEp -= ut->getMaxEp(); + } + + if(ut->getSightIsMultiplier() == true) { + sight -= (unit->getType()->getSight() * (ut->getSight() / 100)); + } + else { + sight -= ut->getSight(); + } + + if(ut->getArmorIsMultiplier() == true) { + armor -= (unit->getType()->getArmor() * (ut->getArmor() / 100)); + } + else { + armor -= ut->getArmor(); + } + + if(ut->getAttackStrengthIsMultiplier() == true) { + for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { + const SkillType *skillType = unit->getType()->getSkillType(i); + const AttackSkillType *ast = dynamic_cast(skillType); + if(ast != NULL) { + attackStrengthMultiplierValueList[ast->getName()] -= (ast->getAttackStrength() * (ut->getAttackStrength(NULL) / 100)); + } + } + } + else { + attackStrength -= ut->getAttackStrength(NULL); + } + + if(ut->getAttackRangeIsMultiplier() == true) { + for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { + const SkillType *skillType = unit->getType()->getSkillType(i); + const AttackSkillType *ast = dynamic_cast(skillType); + if(ast != NULL) { + attackRangeMultiplierValueList[ast->getName()] -= (ast->getAttackRange() * (ut->getAttackRange(NULL) / 100)); + } + } + } + else { + attackRange -= ut->getAttackRange(NULL); + } + + if(ut->getMoveSpeedIsMultiplier() == true) { + //printf("BEFORE Applying moveSpeedIsMultiplier, moveSpeed = %d, ut->getMoveSpeed() = %d\n",moveSpeed,ut->getMoveSpeed()); + + for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { + const SkillType *skillType = unit->getType()->getSkillType(i); + const MoveSkillType *mst = dynamic_cast(skillType); + if(mst != NULL) { + moveSpeedIsMultiplierValueList[mst->getName()] -= (mst->getSpeed() * (ut->getMoveSpeed(NULL) / 100)); + } + } + + //printf("AFTER Applying moveSpeedIsMultiplier, moveSpeed = %d\n",moveSpeed); + } + else { + moveSpeed -= ut->getMoveSpeed(NULL); + } + + if(ut->getProdSpeedIsMultiplier() == true) { + for(unsigned int i = 0; i < unit->getType()->getSkillTypeCount(); ++i) { + const SkillType *skillType = unit->getType()->getSkillType(i); + const ProduceSkillType *pst = dynamic_cast(skillType); + if(pst != NULL) { + prodSpeedProduceIsMultiplierValueList[pst->getName()] -= (pst->getSpeed() * (ut->getProdSpeed(NULL) / 100)); + } + const UpgradeSkillType *ust = dynamic_cast(skillType); + if(ust != NULL) { + prodSpeedUpgradeIsMultiplierValueList[ust->getName()] -= (ust->getSpeed() * (ut->getProdSpeed(NULL) / 100)); + } + const MorphSkillType *mst = dynamic_cast(skillType); + if(mst != NULL) { + prodSpeedMorphIsMultiplierValueList[mst->getName()] -= (mst->getSpeed() * (ut->getProdSpeed(NULL) / 100)); + } + } + } + else { + prodSpeed -= ut->getProdSpeed(NULL); + } } void TotalUpgrade::incLevel(const UnitType *ut) { - maxHp+= ut->getMaxHp()*50/100; - maxEp+= ut->getMaxEp()*50/100; - sight+= ut->getSight()*20/100; - armor+= ut->getArmor()*50/100; -} - -void TotalUpgrade::apply(const UpgradeTypeBase *ut) { - sum(ut); -} - -void TotalUpgrade::deapply(const UpgradeTypeBase *ut) { - maxHp-= ut->getMaxHp(); - maxEp-= ut->getMaxEp(); - sight-= ut->getSight(); - armor-= ut->getArmor(); - attackStrength-= ut->getAttackStrength(); - attackRange-= ut->getAttackRange(); - moveSpeed-= ut->getMoveSpeed(); - prodSpeed-= ut->getProdSpeed(); + maxHp += ut->getMaxHp()*50/100; + maxEp += ut->getMaxEp()*50/100; + sight += ut->getSight()*20/100; + armor += ut->getArmor()*50/100; } }}//end namespace diff --git a/source/glest_game/types/upgrade_type.h b/source/glest_game/types/upgrade_type.h index 664c218d..fbdd7ebe 100644 --- a/source/glest_game/types/upgrade_type.h +++ b/source/glest_game/types/upgrade_type.h @@ -27,6 +27,11 @@ namespace Glest { namespace Game { class TechTree; class FactionType; class UnitType; +class Unit; +class SkillType; +class AttackSkillType; +class MoveSkillType; +class ProduceSkillType; // =============================== // class UpgradeTypeBase @@ -35,23 +40,53 @@ class UnitType; class UpgradeTypeBase { protected: int maxHp; + bool maxHpIsMultiplier; + int sight; + bool sightIsMultiplier; + int maxEp; + bool maxEpIsMultiplier; + int armor; + bool armorIsMultiplier; + int attackStrength; + bool attackStrengthIsMultiplier; + std::map attackStrengthMultiplierValueList; + int attackRange; + bool attackRangeIsMultiplier; + std::map attackRangeMultiplierValueList; + int moveSpeed; + bool moveSpeedIsMultiplier; + std::map moveSpeedIsMultiplierValueList; + int prodSpeed; + bool prodSpeedIsMultiplier; + std::map prodSpeedProduceIsMultiplierValueList; + std::map prodSpeedUpgradeIsMultiplierValueList; + std::map prodSpeedMorphIsMultiplierValueList; public: int getMaxHp() const {return maxHp;} + bool getMaxHpIsMultiplier() const {return maxHpIsMultiplier;} int getSight() const {return sight;} + bool getSightIsMultiplier() const {return sightIsMultiplier;} int getMaxEp() const {return maxEp;} + bool getMaxEpIsMultiplier() const {return maxEpIsMultiplier;} int getArmor() const {return armor;} - int getAttackStrength() const {return attackStrength;} - int getAttackRange() const {return attackRange;} - int getMoveSpeed() const {return moveSpeed;} - int getProdSpeed() const {return prodSpeed;} + bool getArmorIsMultiplier() const {return armorIsMultiplier;} + + int getAttackStrength(const AttackSkillType *st) const; + bool getAttackStrengthIsMultiplier() const {return attackStrengthIsMultiplier;} + int getAttackRange(const AttackSkillType *st) const; + bool getAttackRangeIsMultiplier() const {return attackRangeIsMultiplier;} + int getMoveSpeed(const MoveSkillType *st) const; + bool getMoveSpeedIsMultiplier() const {return moveSpeedIsMultiplier;} + int getProdSpeed(const SkillType *st) const; + bool getProdSpeedIsMultiplier() const {return prodSpeedIsMultiplier;} void load(const XmlNode *upgradeNode); @@ -59,13 +94,21 @@ public: std::string result = ""; result += "maxHp = " + intToStr(maxHp); + result += "maxHpIsMultiplier = " + intToStr(maxHpIsMultiplier); result += " sight = " + intToStr(sight); + result += "sightIsMultiplier = " + intToStr(sightIsMultiplier); result += " maxEp = " + intToStr(maxEp); + result += "maxEpIsMultiplier = " + intToStr(maxEpIsMultiplier); result += " armor = " + intToStr(armor); + result += "armorIsMultiplier = " + intToStr(armorIsMultiplier); result += " attackStrength = " + intToStr(attackStrength); + result += "attackStrengthIsMultiplier = " + intToStr(attackStrengthIsMultiplier); result += " attackRange = " + intToStr(attackRange); + result += "attackRangeIsMultiplier = " + intToStr(attackRangeIsMultiplier); result += " moveSpeed = " + intToStr(moveSpeed); + result += "moveSpeedIsMultiplier = " + intToStr(moveSpeedIsMultiplier); result += " prodSpeed = " + intToStr(prodSpeed); + result += "prodSpeedIsMultiplier = " + intToStr(prodSpeedIsMultiplier); return result; } @@ -103,11 +146,11 @@ public: TotalUpgrade(); void reset(); - void sum(const UpgradeTypeBase *ut); + void sum(const UpgradeTypeBase *ut, const Unit *unit); void incLevel(const UnitType *ut); - void apply(const UpgradeTypeBase *ut); - void deapply(const UpgradeTypeBase *ut); + void apply(const UpgradeTypeBase *ut, const Unit *unit); + void deapply(const UpgradeTypeBase *ut, const Unit *unit); }; }}//end namespace