From 63e3313e6b6bb9e9fa6030229ad9f797e23d1480 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 22 Nov 2012 01:52:01 +0000 Subject: [PATCH] - bugfix for attack-boosts on morphed units --- source/glest_game/type_instances/unit.cpp | 30 +++++++++++++++++++++++ source/glest_game/type_instances/unit.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 5e5347e1..fe5bcdf0 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -2679,6 +2679,25 @@ void Unit::checkUnitLevel() { } } +void Unit::morphAttackBoosts(Unit *unit) { + // Remove any units that were previously in range + if(currentAttackBoostOriginatorEffect.currentAttackBoostUnits.empty() == false && currentAttackBoostOriginatorEffect.skillType != NULL) { + for(int i = currentAttackBoostOriginatorEffect.currentAttackBoostUnits.size() - 1; i >= 0; --i) { + // Remove attack boost upgrades from unit + + int findUnitId = currentAttackBoostOriginatorEffect.currentAttackBoostUnits[i]; + Unit *affectedUnit = game->getWorld()->findUnitById(findUnitId); + if(affectedUnit != NULL && affectedUnit->getId() == unit->getId()) { + affectedUnit->deapplyAttackBoost(currentAttackBoostOriginatorEffect.skillType->getAttackBoost(), this); + + currentAttackBoostOriginatorEffect.currentAttackBoostUnits.erase(currentAttackBoostOriginatorEffect.currentAttackBoostUnits.begin() + i); + } + + //printf("- #1 DE-APPLY ATTACK BOOST from unit [%s - %d]\n",affectedUnit->getType()->getName().c_str(),affectedUnit->getId()); + } + } +} + bool Unit::morph(const MorphCommandType *mct){ if(mct == NULL) { @@ -2703,6 +2722,17 @@ bool Unit::morph(const MorphCommandType *mct){ map->clearUnitCells(this, pos, true); faction->deApplyStaticCosts(type,mct); + //printf("Now unapply attack-boost for unit [%d - %s]\n",this->getId(),this->getType()->getName().c_str()); + // De apply attack boosts for morphed unit + for(int i = currentAttackBoostEffects.size() - 1; i >= 0; --i) { + UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; + if(effect != NULL) { + Unit *sourceUnit = game->getWorld()->findUnitById(effect->source->getId()); + sourceUnit->morphAttackBoosts(this); + } + } + + checkItemInVault(&this->hp,this->hp); hp += morphUnitType->getMaxHp() - type->getMaxHp(); addItemToVault(&this->hp,this->hp); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 5588bdaf..ed77e41d 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -741,6 +741,8 @@ private: void checkCustomizedParticleTriggers(bool force); bool checkModelStateInfoForNewHpValue(); void checkUnitLevel(); + + void morphAttackBoosts(Unit *unit); }; }}// end namespace