1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fix the initial creature spells at battle start

Before: built-in spells appear on first move of the creature
After: all built-in spells appear before the first move but after tactics

Example: Air Shield for experienced skeletons
This commit is contained in:
Vadim Markovtsev 2016-10-28 23:37:45 +02:00
parent ab7a0d64eb
commit dccc25268c
2 changed files with 53 additions and 43 deletions

View File

@ -4371,6 +4371,35 @@ bool CGameHandler::makeCustomAction(BattleAction &ba)
return false;
}
void CGameHandler::stackAppearTrigger(const CStack *st)
{
auto bl = *(st->getBonuses(Selector::type(Bonus::ENCHANTED)));
for (auto b : bl)
{
SetStackEffect sse;
int val = bl.valOfBonuses(Selector::typeSubtype(b->type, b->subtype));
if (val > 3)
{
for (auto s : gs->curB->battleGetAllStacks())
{
if (battleMatchOwner(st, s, true) && s->isValidTarget()) //all allied
sse.stacks.push_back (s->ID);
}
}
else
sse.stacks.push_back (st->ID);
Bonus pseudoBonus;
pseudoBonus.sid = b->subtype;
pseudoBonus.val = ((val > 3) ? (val - 3) : val);
pseudoBonus.turnsRemain = 50;
st->stackEffectToFeature(sse.effect, pseudoBonus);
if (sse.effect.size())
sendAndApply(&sse);
}
}
void CGameHandler::stackTurnTrigger(const CStack *st)
{
BattleTriggerEffect bte;
@ -4380,6 +4409,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
bte.additionalInfo = 0;
if (st->alive())
{
stackAppearTrigger(st);
//unbind
if (st->hasBonus(Selector::type(Bonus::BIND_EFFECT)))
{
@ -4502,31 +4532,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
cast = true;
}
};
}
bl = *(st->getBonuses(Selector::type(Bonus::ENCHANTED)));
for (auto b : bl)
{
SetStackEffect sse;
int val = bl.valOfBonuses (Selector::typeSubtype(b->type, b->subtype));
if (val > 3)
{
for (auto s : gs->curB->battleGetAllStacks())
{
if (battleMatchOwner(st, s, true) && s->isValidTarget()) //all allied
sse.stacks.push_back (s->ID);
}
}
else
sse.stacks.push_back (st->ID);
Bonus pseudoBonus;
pseudoBonus.sid = b->subtype;
pseudoBonus.val = ((val > 3) ? (val - 3) : val);
pseudoBonus.turnsRemain = 50;
st->stackEffectToFeature (sse.effect, pseudoBonus);
if (sse.effect.size())
sendAndApply (&sse);
}
}
}
@ -5515,8 +5521,7 @@ bool CGameHandler::swapStacks(const StackLocation &sl1, const StackLocation &sl2
}
}
void CGameHandler::runBattle()
{
void CGameHandler::runBattle() {
setBattle(gs->curB);
assert(gs->curB);
//TODO: pre-tactic stuff, call scripts etc.
@ -5527,6 +5532,12 @@ void CGameHandler::runBattle()
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
}
//initial stacks appearance triggers, e.g. built-in bonus spells
for (auto stack : gs->curB->stacks)
{
stackAppearTrigger(stack);
}
//spells opening battle
for (int i = 0; i < 2; ++i)
{
@ -5575,7 +5586,6 @@ void CGameHandler::runBattle()
const CStack *next;
while (!battleResult.get() && (next = curB.getNextStack()) && next->willMove())
{
std::set <const CStack *> stacksToRemove;
for (auto stack : curB.stacks)
{
@ -5778,7 +5788,6 @@ void CGameHandler::runBattle()
)
{
if (getRandomGenerator().nextInt(23) < nextStackMorale) //this stack hasn't got morale this turn
{
BattleTriggerEffect bte;
bte.stackID = next->ID;

View File

@ -199,6 +199,7 @@ public:
bool makeBattleAction(BattleAction &ba);
bool makeAutomaticAction(const CStack *stack, BattleAction &ba); //used when action is taken by stack without volition of player (eg. unguided catapult attack)
bool makeCustomAction(BattleAction &ba);
void stackAppearTrigger(const CStack *stack);
void stackTurnTrigger(const CStack *stack);
void handleDamageFromObstacle(const CObstacleInstance &obstacle, const CStack * curStack); //checks if obstacle is land mine and handles possible consequences
void removeObstacle(const CObstacleInstance &obstacle);