From 84630a098427849012ae127908e02ec77b3e516c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sun, 10 Jun 2012 13:07:08 +0000 Subject: [PATCH] Fixed #993, tent code cleanups. --- lib/BattleState.cpp | 4 ++-- server/CGameHandler.cpp | 46 +++++++++++++++-------------------------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index e4fbe3fb1..c262fbd92 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -3171,8 +3171,8 @@ bool CStack::isValidTarget(bool allowDead/* = false*/) const /*alive non-turret bool CStack::canBeHealed() const { - return firstHPleft != MaxHealth() - && alive() + return firstHPleft < MaxHealth() + && isValidTarget() && !hasBonusOfType(Bonus::SIEGE_WEAPON); } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 96aff8518..6da4e8451 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3540,7 +3540,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) complain("There is either no healer, no destination, or healer cannot heal :P"); } int maxHealable = destStack->MaxHealth() - destStack->firstHPleft; - int maxiumHeal = healer->count * std::max(10, attackingHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, 27)); + int maxiumHeal = healer->count * std::max(10, attackingHero->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, CGHeroInstance::FIRST_AID)); int healed = std::min(maxHealable, maxiumHeal); @@ -3554,8 +3554,8 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) shr.lifeDrain = (ui8)false; shr.tentHealing = (ui8)true; shr.drainedFrom = ba.stackNumber; - StacksHealedOrResurrected::HealInfo hi; + StacksHealedOrResurrected::HealInfo hi; hi.healedHP = healed; hi.lowLevelResurrection = 0; hi.stackID = destStack->ID; @@ -5845,49 +5845,37 @@ void CGameHandler::runBattle() continue; } - if(next->getCreature()->idNumber == 147 && (!curOwner || curOwner->getSecSkillLevel(CGHeroInstance::FIRST_AID) == 0)) //first aid tent, hero has no first aid + + if(next->getCreature()->idNumber == 147) //first aid tent { - BattleAction heal; + std::vector< const CStack * > possibleStacks; - std::vector< const CStack * > possibleStacks, secondPriority; - for (int v=0; vcurB->stacks.size(); ++v) - { - const CStack * cstack = gs->curB->stacks[v]; - if (cstack->owner == next->owner && cstack->firstHPleft < cstack->MaxHealth() && cstack->isValidTarget()) //it's friendly and not fully healthy - { - if (cstack->hasBonusOfType(Bonus::SIEGE_WEAPON)) - secondPriority.push_back(cstack); - else - possibleStacks.push_back(cstack); - } - } + //is there any clean algorithm for that? (boost.range seems to lack copy_if) + BOOST_FOREACH(const CStack *s, battleGetAllStacks()) + if(s->owner == next->owner && s->canBeHealed()) + possibleStacks.push_back(s); - if(possibleStacks.size() == 0 && secondPriority.size() == 0) + if(!possibleStacks.size()) { - //nothing to heal makeStackDoNothing(next); - continue; } - else + + if(!curOwner || curOwner->getSecSkillLevel(CGHeroInstance::FIRST_AID) == 0) //no hero or hero has no first aid { - //heal random creature - const CStack * toBeHealed = NULL; - if (possibleStacks.size() > 0) - toBeHealed = possibleStacks[ rand()%possibleStacks.size() ]; - else - toBeHealed = secondPriority[ rand()%secondPriority.size() ]; - + range::random_shuffle(possibleStacks); + const CStack * toBeHealed = possibleStacks.front(); + + BattleAction heal; heal.actionType = BattleAction::STACK_HEAL; heal.additionalInfo = 0; heal.destinationTile = toBeHealed->position; heal.side = !next->attackerOwned; heal.stackNumber = next->ID; - makeBattleAction(heal); + continue; } - continue; } int numberOfAsks = 1;