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

Commander can now die in a battle and will be automatically rised when visiting town.

This commit is contained in:
DjWarmonger 2012-07-17 08:52:27 +00:00
parent 9ebf56ff03
commit b86706d58c
4 changed files with 34 additions and 5 deletions

View File

@ -2046,8 +2046,18 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
}
}
else
{
if (h->commander && !h->commander->alive) //rise commander. TODO: interactive script
{
SetCommanderProperty scp;
scp.heroid = h->id;
scp.which = SetCommanderProperty::ALIVE;
scp.amount = 1;
cb->sendAndApply (&scp);
}
cb->heroVisitCastle(id, h->id);
}
}
void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const
{

View File

@ -1031,13 +1031,11 @@ DLL_LINKAGE void BattleObstaclePlaced::applyGs( CGameState *gs )
void BattleResult::applyGs( CGameState *gs )
{
//stack with SUMMONED flag but coming from garrison -> most likely resurrected, needs to be removed
//TODO: switch commander status to dead
BOOST_FOREACH (CStack *s, gs->curB->stacks)
{
if (s->base && s->base->armyObj && vstd::contains(s->state, EBattleStackState::SUMMONED))
{
//stack with SUMMONED flag but coming from garrison -> most likely resurrected, needs to be removed
assert(&s->base->armyObj->getStack(s->slot) == s->base);
const_cast<CArmedInstance*>(s->base->armyObj)->eraseStack(s->slot);
}

View File

@ -6077,6 +6077,8 @@ void CGameHandler::removeObstacle(const CObstacleInstance &obstacle)
CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance *army, BattleInfo *bat)
{
heroWithDeadCommander = -1;
int color = army->tempOwner;
if(color == 254)
color = GameConstants::NEUTRAL_PLAYER;
@ -6094,6 +6096,16 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance *army, BattleI
else
newStackCounts.push_back(std::pair<StackLocation, int>(sl, 0));
}
if (st->base && !st->count)
{
auto c = dynamic_cast <const CCommanderInstance *>(st->base);
if (c) //switch commander status to dead
{
auto h = dynamic_cast <const CGHeroInstance *>(army);
if (h && h->commander == c)
heroWithDeadCommander = army->id; //TODO: unify commander handling
}
}
}
}
@ -6106,4 +6118,12 @@ void CasualtiesAfterBattle::takeFromArmy(CGameHandler *gh)
else
gh->eraseStack(ncount.first, true);
}
if (heroWithDeadCommander > -1)
{
SetCommanderProperty scp;
scp.heroid = heroWithDeadCommander;
scp.which = SetCommanderProperty::ALIVE;
scp.amount = 0;
gh->sendAndApply (&scp);
}
}

View File

@ -75,6 +75,7 @@ struct CasualtiesAfterBattle
typedef std::pair<StackLocation, int> TStackAndItsNewCount;
enum {ERASE = -1};
std::vector<TStackAndItsNewCount> newStackCounts;
si32 heroWithDeadCommander; //TODO: unify stack loactions
CasualtiesAfterBattle(const CArmedInstance *army, BattleInfo *bat);
void takeFromArmy(CGameHandler *gh);