From b86706d58c98b7b6fd8b5bb20de0baa79a42002d Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Tue, 17 Jul 2012 08:52:27 +0000 Subject: [PATCH] Commander can now die in a battle and will be automatically rised when visiting town. --- lib/CObjectHandler.cpp | 10 ++++++++++ lib/NetPacksLib.cpp | 8 +++----- server/CGameHandler.cpp | 20 ++++++++++++++++++++ server/CGameHandler.h | 1 + 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 95ac1702a..0b47b0a12 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -2046,7 +2046,17 @@ 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 diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 0ccdafd0d..c274cbab4 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -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) + BOOST_FOREACH (CStack *s, gs->curB->stacks) { - if(s->base && s->base->armyObj && vstd::contains(s->state, EBattleStackState::SUMMONED)) + 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(s->base->armyObj)->eraseStack(s->slot); } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 7f6f0302a..c20b9f1f0 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -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(sl, 0)); } + if (st->base && !st->count) + { + auto c = dynamic_cast (st->base); + if (c) //switch commander status to dead + { + auto h = dynamic_cast (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); + } } diff --git a/server/CGameHandler.h b/server/CGameHandler.h index c08dba2b2..f83bd982d 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -75,6 +75,7 @@ struct CasualtiesAfterBattle typedef std::pair TStackAndItsNewCount; enum {ERASE = -1}; std::vector newStackCounts; + si32 heroWithDeadCommander; //TODO: unify stack loactions CasualtiesAfterBattle(const CArmedInstance *army, BattleInfo *bat); void takeFromArmy(CGameHandler *gh);