mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Fixed #993, tent code cleanups.
This commit is contained in:
parent
d0816a7924
commit
84630a0984
@ -3171,8 +3171,8 @@ bool CStack::isValidTarget(bool allowDead/* = false*/) const /*alive non-turret
|
|||||||
|
|
||||||
bool CStack::canBeHealed() const
|
bool CStack::canBeHealed() const
|
||||||
{
|
{
|
||||||
return firstHPleft != MaxHealth()
|
return firstHPleft < MaxHealth()
|
||||||
&& alive()
|
&& isValidTarget()
|
||||||
&& !hasBonusOfType(Bonus::SIEGE_WEAPON);
|
&& !hasBonusOfType(Bonus::SIEGE_WEAPON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3540,7 +3540,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
|||||||
complain("There is either no healer, no destination, or healer cannot heal :P");
|
complain("There is either no healer, no destination, or healer cannot heal :P");
|
||||||
}
|
}
|
||||||
int maxHealable = destStack->MaxHealth() - destStack->firstHPleft;
|
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);
|
int healed = std::min(maxHealable, maxiumHeal);
|
||||||
|
|
||||||
@ -3554,8 +3554,8 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
|||||||
shr.lifeDrain = (ui8)false;
|
shr.lifeDrain = (ui8)false;
|
||||||
shr.tentHealing = (ui8)true;
|
shr.tentHealing = (ui8)true;
|
||||||
shr.drainedFrom = ba.stackNumber;
|
shr.drainedFrom = ba.stackNumber;
|
||||||
StacksHealedOrResurrected::HealInfo hi;
|
|
||||||
|
|
||||||
|
StacksHealedOrResurrected::HealInfo hi;
|
||||||
hi.healedHP = healed;
|
hi.healedHP = healed;
|
||||||
hi.lowLevelResurrection = 0;
|
hi.lowLevelResurrection = 0;
|
||||||
hi.stackID = destStack->ID;
|
hi.stackID = destStack->ID;
|
||||||
@ -5845,50 +5845,38 @@ void CGameHandler::runBattle()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(next->getCreature()->idNumber == 147 && (!curOwner || curOwner->getSecSkillLevel(CGHeroInstance::FIRST_AID) == 0)) //first aid tent, hero has no first aid
|
|
||||||
{
|
|
||||||
BattleAction heal;
|
|
||||||
|
|
||||||
std::vector< const CStack * > possibleStacks, secondPriority;
|
if(next->getCreature()->idNumber == 147) //first aid tent
|
||||||
for (int v=0; v<gs->curB->stacks.size(); ++v)
|
|
||||||
{
|
{
|
||||||
const CStack * cstack = gs->curB->stacks[v];
|
std::vector< const CStack * > possibleStacks;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(possibleStacks.size() == 0 && secondPriority.size() == 0)
|
//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())
|
||||||
{
|
{
|
||||||
//nothing to heal
|
|
||||||
makeStackDoNothing(next);
|
makeStackDoNothing(next);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//heal random creature
|
|
||||||
const CStack * toBeHealed = NULL;
|
|
||||||
if (possibleStacks.size() > 0)
|
|
||||||
toBeHealed = possibleStacks[ rand()%possibleStacks.size() ];
|
|
||||||
else
|
|
||||||
toBeHealed = secondPriority[ rand()%secondPriority.size() ];
|
|
||||||
|
|
||||||
|
if(!curOwner || curOwner->getSecSkillLevel(CGHeroInstance::FIRST_AID) == 0) //no hero or hero has no first aid
|
||||||
|
{
|
||||||
|
range::random_shuffle(possibleStacks);
|
||||||
|
const CStack * toBeHealed = possibleStacks.front();
|
||||||
|
|
||||||
|
BattleAction heal;
|
||||||
heal.actionType = BattleAction::STACK_HEAL;
|
heal.actionType = BattleAction::STACK_HEAL;
|
||||||
heal.additionalInfo = 0;
|
heal.additionalInfo = 0;
|
||||||
heal.destinationTile = toBeHealed->position;
|
heal.destinationTile = toBeHealed->position;
|
||||||
heal.side = !next->attackerOwned;
|
heal.side = !next->attackerOwned;
|
||||||
heal.stackNumber = next->ID;
|
heal.stackNumber = next->ID;
|
||||||
|
|
||||||
makeBattleAction(heal);
|
makeBattleAction(heal);
|
||||||
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int numberOfAsks = 1;
|
int numberOfAsks = 1;
|
||||||
bool breakOuter = false;
|
bool breakOuter = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user