- added support for multipliers in attack-boost

This commit is contained in:
Mark Vejvoda 2011-06-26 07:06:32 +00:00
parent 26bf93eeed
commit 4d6f39d257
6 changed files with 404 additions and 75 deletions

View File

@ -1491,7 +1491,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) {
effect.source = source; effect.source = source;
//if(boost->isAffected(source, this)) { //if(boost->isAffected(source, this)) {
totalUpgrade.apply(&boost->boostUpgrade); totalUpgrade.apply(&boost->boostUpgrade, this);
checkItemInVault(&this->hp,this->hp); checkItemInVault(&this->hp,this->hp);
hp += boost->boostUpgrade.getMaxHp(); 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()); //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)) { //if(boost->isAffected(source, this)) {
totalUpgrade.deapply(&boost->boostUpgrade); totalUpgrade.deapply(&boost->boostUpgrade, this);
checkItemInVault(&this->hp,this->hp); checkItemInVault(&this->hp,this->hp);
hp -= boost->boostUpgrade.getMaxHp(); hp -= boost->boostUpgrade.getMaxHp();
@ -1830,7 +1830,7 @@ void Unit::applyUpgrade(const UpgradeType *upgradeType){
} }
if(upgradeType->isAffected(type)){ if(upgradeType->isAffected(type)){
totalUpgrade.sum(upgradeType); totalUpgrade.sum(upgradeType, this);
checkItemInVault(&this->hp,this->hp); checkItemInVault(&this->hp,this->hp);
hp += upgradeType->getMaxHp(); hp += upgradeType->getMaxHp();

View File

@ -213,7 +213,7 @@ void UpgradeManager::computeTotalUpgrade(const Unit *unit, TotalUpgrade *totalUp
if((*it)->getFactionIndex() == unit->getFactionIndex() if((*it)->getFactionIndex() == unit->getFactionIndex()
&& (*it)->getType()->isAffected(unit->getType()) && (*it)->getType()->isAffected(unit->getType())
&& (*it)->getState()==usUpgraded) && (*it)->getState()==usUpgraded)
totalUpgrade->sum((*it)->getType()); totalUpgrade->sum((*it)->getType(), unit);
} }
} }

View File

@ -153,8 +153,8 @@ string MoveCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
str= name+"\n"; str= name+"\n";
str+= lang.get("WalkSpeed")+": "+ intToStr(moveSkillType->getSpeed()); str+= lang.get("WalkSpeed")+": "+ intToStr(moveSkillType->getSpeed());
if(totalUpgrade->getMoveSpeed()!=0){ if(totalUpgrade->getMoveSpeed(moveSkillType) != 0) {
str+= "+" + intToStr(totalUpgrade->getMoveSpeed()); str+= "+" + intToStr(totalUpgrade->getMoveSpeed(moveSkillType));
} }
str+="\n"; str+="\n";
if(moveSkillType->getEpCost()!=0){ if(moveSkillType->getEpCost()!=0){
@ -218,8 +218,8 @@ string AttackCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
str+= intToStr(attackSkillType->getAttackStrength()-attackSkillType->getAttackVar()); str+= intToStr(attackSkillType->getAttackStrength()-attackSkillType->getAttackVar());
str+= "..."; str+= "...";
str+= intToStr(attackSkillType->getAttackStrength()+attackSkillType->getAttackVar()); str+= intToStr(attackSkillType->getAttackStrength()+attackSkillType->getAttackVar());
if(totalUpgrade->getAttackStrength()!=0){ if(totalUpgrade->getAttackStrength(attackSkillType) != 0) {
str+= "+"+intToStr(totalUpgrade->getAttackStrength()); str+= "+"+intToStr(totalUpgrade->getAttackStrength(attackSkillType));
} }
str+= " ("+ attackSkillType->getAttackType()->getName() +")"; str+= " ("+ attackSkillType->getAttackType()->getName() +")";
str+= "\n"; str+= "\n";
@ -231,8 +231,8 @@ string AttackCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
//attack distance //attack distance
str+= lang.get("AttackDistance")+": "+intToStr(attackSkillType->getAttackRange()); str+= lang.get("AttackDistance")+": "+intToStr(attackSkillType->getAttackRange());
if(totalUpgrade->getAttackRange()!=0){ if(totalUpgrade->getAttackRange(attackSkillType) != 0) {
str+= "+"+intToStr(totalUpgrade->getAttackRange()!=0); str+= "+"+intToStr(totalUpgrade->getAttackRange(attackSkillType) != 0);
} }
str+="\n"; str+="\n";
@ -249,8 +249,8 @@ string AttackCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
//movement speed //movement speed
str+= lang.get("WalkSpeed")+": "+ intToStr(moveSkillType->getSpeed()) ; str+= lang.get("WalkSpeed")+": "+ intToStr(moveSkillType->getSpeed()) ;
if(totalUpgrade->getMoveSpeed()!=0){ if(totalUpgrade->getMoveSpeed(moveSkillType) != 0) {
str+= "+"+intToStr(totalUpgrade->getMoveSpeed()); str+= "+"+intToStr(totalUpgrade->getMoveSpeed(moveSkillType));
} }
str+="\n"; str+="\n";
@ -310,8 +310,8 @@ string AttackStoppedCommandType::getDesc(const TotalUpgrade *totalUpgrade) const
str+= intToStr(attackSkillType->getAttackStrength()-attackSkillType->getAttackVar()); str+= intToStr(attackSkillType->getAttackStrength()-attackSkillType->getAttackVar());
str+="..."; str+="...";
str+= intToStr(attackSkillType->getAttackStrength()+attackSkillType->getAttackVar()); str+= intToStr(attackSkillType->getAttackStrength()+attackSkillType->getAttackVar());
if(totalUpgrade->getAttackStrength()!=0) if(totalUpgrade->getAttackStrength(attackSkillType) != 0)
str+= "+"+intToStr(totalUpgrade->getAttackStrength()); str+= "+"+intToStr(totalUpgrade->getAttackStrength(attackSkillType));
str+= " ("+ attackSkillType->getAttackType()->getName() +")"; str+= " ("+ attackSkillType->getAttackType()->getName() +")";
str+="\n"; str+="\n";
@ -322,8 +322,8 @@ string AttackStoppedCommandType::getDesc(const TotalUpgrade *totalUpgrade) const
//attack distance //attack distance
str+= lang.get("AttackDistance")+": "+intToStr(attackSkillType->getAttackRange()); str+= lang.get("AttackDistance")+": "+intToStr(attackSkillType->getAttackRange());
if(totalUpgrade->getAttackRange()!=0){ if(totalUpgrade->getAttackRange(attackSkillType) != 0) {
str+= "+"+intToStr(totalUpgrade->getAttackRange()!=0); str+= "+"+intToStr(totalUpgrade->getAttackRange(attackSkillType) != 0);
} }
str+="\n"; str+="\n";
@ -636,8 +636,8 @@ string ProduceCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
//prod speed //prod speed
str+= lang.get("ProductionSpeed")+": "+ intToStr(produceSkillType->getSpeed()); str+= lang.get("ProductionSpeed")+": "+ intToStr(produceSkillType->getSpeed());
if(totalUpgrade->getProdSpeed()!=0){ if(totalUpgrade->getProdSpeed(produceSkillType)!=0){
str+="+" + intToStr(totalUpgrade->getProdSpeed()); str+="+" + intToStr(totalUpgrade->getProdSpeed(produceSkillType));
} }
str+="\n"; str+="\n";

View File

@ -381,7 +381,7 @@ string MoveSkillType::toString() const{
} }
int MoveSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{ int MoveSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{
int result = speed + totalUpgrade->getMoveSpeed(); int result = speed + totalUpgrade->getMoveSpeed(this);
result = max(0,result); result = max(0,result);
return result; return result;
} }
@ -523,13 +523,13 @@ string AttackSkillType::toString() const{
//get totals //get totals
int AttackSkillType::getTotalAttackStrength(const TotalUpgrade *totalUpgrade) const{ int AttackSkillType::getTotalAttackStrength(const TotalUpgrade *totalUpgrade) const{
int result = attackStrength + totalUpgrade->getAttackStrength(); int result = attackStrength + totalUpgrade->getAttackStrength(this);
result = max(0,result); result = max(0,result);
return result; return result;
} }
int AttackSkillType::getTotalAttackRange(const TotalUpgrade *totalUpgrade) const{ int AttackSkillType::getTotalAttackRange(const TotalUpgrade *totalUpgrade) const{
int result = attackRange + totalUpgrade->getAttackRange(); int result = attackRange + totalUpgrade->getAttackRange(this);
result = max(0,result); result = max(0,result);
return result; return result;
} }
@ -583,7 +583,7 @@ string ProduceSkillType::toString() const{
} }
int ProduceSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{ int ProduceSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{
int result = speed + totalUpgrade->getProdSpeed(); int result = speed + totalUpgrade->getProdSpeed(this);
result = max(0,result); result = max(0,result);
return result; return result;
} }
@ -601,7 +601,7 @@ string UpgradeSkillType::toString() const{
} }
int UpgradeSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{ int UpgradeSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{
int result = speed + totalUpgrade->getProdSpeed(); int result = speed + totalUpgrade->getProdSpeed(this);
result = max(0,result); result = max(0,result);
return result; return result;
} }
@ -631,7 +631,7 @@ string MorphSkillType::toString() const{
} }
int MorphSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{ int MorphSkillType::getTotalSpeed(const TotalUpgrade *totalUpgrade) const{
int result = speed + totalUpgrade->getProdSpeed(); int result = speed + totalUpgrade->getProdSpeed(this);
result = max(0,result); result = max(0,result);
return result; return result;
} }

View File

@ -39,14 +39,139 @@ namespace Glest{ namespace Game{
void UpgradeTypeBase::load(const XmlNode *upgradeNode) { void UpgradeTypeBase::load(const XmlNode *upgradeNode) {
//values //values
maxHpIsMultiplier = false;
maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue(); 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(); 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(); 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(); 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(); 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(); 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(); 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(); 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<const ProduceSkillType *>(st) != NULL) {
if(prodSpeedProduceIsMultiplierValueList.find(st->getName()) != prodSpeedProduceIsMultiplierValueList.end()) {
result = prodSpeedProduceIsMultiplierValueList.find(st->getName())->second;
}
}
else if(dynamic_cast<const UpgradeSkillType *>(st) != NULL) {
if(prodSpeedUpgradeIsMultiplierValueList.find(st->getName()) != prodSpeedUpgradeIsMultiplierValueList.end()) {
result = prodSpeedUpgradeIsMultiplierValueList.find(st->getName())->second;
}
}
else if(dynamic_cast<const MorphSkillType *>(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{ bool UpgradeType::isAffected(const UnitType *unitType) const{
@ -166,14 +291,6 @@ void UpgradeType::load(const string &dir, const TechTree *techTree,
sortedItems.clear(); sortedItems.clear();
//values //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); UpgradeTypeBase::load(upgradeNode);
} }
catch(const exception &e){ catch(const exception &e){
@ -247,45 +364,214 @@ void TotalUpgrade::reset() {
prodSpeed=0; prodSpeed=0;
} }
void TotalUpgrade::sum(const UpgradeTypeBase *ut) { void TotalUpgrade::sum(const UpgradeTypeBase *ut, const Unit *unit) {
maxHp+= ut->getMaxHp(); maxHpIsMultiplier = ut->getMaxHpIsMultiplier();
//maxHp = max(0,maxHp); sightIsMultiplier = ut->getSightIsMultiplier();
maxEp+= ut->getMaxEp(); maxEpIsMultiplier = ut->getMaxEpIsMultiplier();
//maxEp = max(0,maxEp); armorIsMultiplier = ut->getArmorIsMultiplier();
sight+= ut->getSight(); attackStrengthIsMultiplier = ut->getAttackStrengthIsMultiplier();
//sight = max(0,sight); attackRangeIsMultiplier = ut->getAttackRangeIsMultiplier();
armor+= ut->getArmor(); moveSpeedIsMultiplier = ut->getMoveSpeedIsMultiplier();
//armor = max(0,armor); prodSpeedIsMultiplier = ut->getProdSpeedIsMultiplier();
attackStrength+= ut->getAttackStrength();
//attackStrength = max(0,attackStrength); if(ut->getMaxHpIsMultiplier() == true) {
attackRange+= ut->getAttackRange(); maxHp += (unit->getHp() * (ut->getMaxHp() / 100));
//attackRange = max(0,attackRange); }
moveSpeed+= ut->getMoveSpeed(); else {
//moveSpeed = max(0,moveSpeed); maxHp += ut->getMaxHp();
prodSpeed+= ut->getProdSpeed(); }
//prodSpeed = max(0,prodSpeed);
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<const AttackSkillType *>(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<const AttackSkillType *>(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<const MoveSkillType *>(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<const ProduceSkillType *>(skillType);
if(pst != NULL) {
prodSpeedProduceIsMultiplierValueList[pst->getName()] += (pst->getSpeed() * (ut->getProdSpeed(NULL) / 100));
}
const UpgradeSkillType *ust = dynamic_cast<const UpgradeSkillType *>(skillType);
if(ust != NULL) {
prodSpeedUpgradeIsMultiplierValueList[ust->getName()] += (ust->getSpeed() * (ut->getProdSpeed(NULL) / 100));
}
const MorphSkillType *mst = dynamic_cast<const MorphSkillType *>(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<const AttackSkillType *>(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<const AttackSkillType *>(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<const MoveSkillType *>(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<const ProduceSkillType *>(skillType);
if(pst != NULL) {
prodSpeedProduceIsMultiplierValueList[pst->getName()] -= (pst->getSpeed() * (ut->getProdSpeed(NULL) / 100));
}
const UpgradeSkillType *ust = dynamic_cast<const UpgradeSkillType *>(skillType);
if(ust != NULL) {
prodSpeedUpgradeIsMultiplierValueList[ust->getName()] -= (ust->getSpeed() * (ut->getProdSpeed(NULL) / 100));
}
const MorphSkillType *mst = dynamic_cast<const MorphSkillType *>(skillType);
if(mst != NULL) {
prodSpeedMorphIsMultiplierValueList[mst->getName()] -= (mst->getSpeed() * (ut->getProdSpeed(NULL) / 100));
}
}
}
else {
prodSpeed -= ut->getProdSpeed(NULL);
}
} }
void TotalUpgrade::incLevel(const UnitType *ut) { void TotalUpgrade::incLevel(const UnitType *ut) {
maxHp+= ut->getMaxHp()*50/100; maxHp += ut->getMaxHp()*50/100;
maxEp+= ut->getMaxEp()*50/100; maxEp += ut->getMaxEp()*50/100;
sight+= ut->getSight()*20/100; sight += ut->getSight()*20/100;
armor+= ut->getArmor()*50/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();
} }
}}//end namespace }}//end namespace

View File

@ -27,6 +27,11 @@ namespace Glest { namespace Game {
class TechTree; class TechTree;
class FactionType; class FactionType;
class UnitType; class UnitType;
class Unit;
class SkillType;
class AttackSkillType;
class MoveSkillType;
class ProduceSkillType;
// =============================== // ===============================
// class UpgradeTypeBase // class UpgradeTypeBase
@ -35,23 +40,53 @@ class UnitType;
class UpgradeTypeBase { class UpgradeTypeBase {
protected: protected:
int maxHp; int maxHp;
bool maxHpIsMultiplier;
int sight; int sight;
bool sightIsMultiplier;
int maxEp; int maxEp;
bool maxEpIsMultiplier;
int armor; int armor;
bool armorIsMultiplier;
int attackStrength; int attackStrength;
bool attackStrengthIsMultiplier;
std::map<string,int> attackStrengthMultiplierValueList;
int attackRange; int attackRange;
bool attackRangeIsMultiplier;
std::map<string,int> attackRangeMultiplierValueList;
int moveSpeed; int moveSpeed;
bool moveSpeedIsMultiplier;
std::map<string,int> moveSpeedIsMultiplierValueList;
int prodSpeed; int prodSpeed;
bool prodSpeedIsMultiplier;
std::map<string,int> prodSpeedProduceIsMultiplierValueList;
std::map<string,int> prodSpeedUpgradeIsMultiplierValueList;
std::map<string,int> prodSpeedMorphIsMultiplierValueList;
public: public:
int getMaxHp() const {return maxHp;} int getMaxHp() const {return maxHp;}
bool getMaxHpIsMultiplier() const {return maxHpIsMultiplier;}
int getSight() const {return sight;} int getSight() const {return sight;}
bool getSightIsMultiplier() const {return sightIsMultiplier;}
int getMaxEp() const {return maxEp;} int getMaxEp() const {return maxEp;}
bool getMaxEpIsMultiplier() const {return maxEpIsMultiplier;}
int getArmor() const {return armor;} int getArmor() const {return armor;}
int getAttackStrength() const {return attackStrength;} bool getArmorIsMultiplier() const {return armorIsMultiplier;}
int getAttackRange() const {return attackRange;}
int getMoveSpeed() const {return moveSpeed;} int getAttackStrength(const AttackSkillType *st) const;
int getProdSpeed() const {return prodSpeed;} 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); void load(const XmlNode *upgradeNode);
@ -59,13 +94,21 @@ public:
std::string result = ""; std::string result = "";
result += "maxHp = " + intToStr(maxHp); result += "maxHp = " + intToStr(maxHp);
result += "maxHpIsMultiplier = " + intToStr(maxHpIsMultiplier);
result += " sight = " + intToStr(sight); result += " sight = " + intToStr(sight);
result += "sightIsMultiplier = " + intToStr(sightIsMultiplier);
result += " maxEp = " + intToStr(maxEp); result += " maxEp = " + intToStr(maxEp);
result += "maxEpIsMultiplier = " + intToStr(maxEpIsMultiplier);
result += " armor = " + intToStr(armor); result += " armor = " + intToStr(armor);
result += "armorIsMultiplier = " + intToStr(armorIsMultiplier);
result += " attackStrength = " + intToStr(attackStrength); result += " attackStrength = " + intToStr(attackStrength);
result += "attackStrengthIsMultiplier = " + intToStr(attackStrengthIsMultiplier);
result += " attackRange = " + intToStr(attackRange); result += " attackRange = " + intToStr(attackRange);
result += "attackRangeIsMultiplier = " + intToStr(attackRangeIsMultiplier);
result += " moveSpeed = " + intToStr(moveSpeed); result += " moveSpeed = " + intToStr(moveSpeed);
result += "moveSpeedIsMultiplier = " + intToStr(moveSpeedIsMultiplier);
result += " prodSpeed = " + intToStr(prodSpeed); result += " prodSpeed = " + intToStr(prodSpeed);
result += "prodSpeedIsMultiplier = " + intToStr(prodSpeedIsMultiplier);
return result; return result;
} }
@ -103,11 +146,11 @@ public:
TotalUpgrade(); TotalUpgrade();
void reset(); void reset();
void sum(const UpgradeTypeBase *ut); void sum(const UpgradeTypeBase *ut, const Unit *unit);
void incLevel(const UnitType *ut); void incLevel(const UnitType *ut);
void apply(const UpgradeTypeBase *ut); void apply(const UpgradeTypeBase *ut, const Unit *unit);
void deapply(const UpgradeTypeBase *ut); void deapply(const UpgradeTypeBase *ut, const Unit *unit);
}; };
}}//end namespace }}//end namespace