瀏覽代碼

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

DjWarmonger 13 年之前
父節點
當前提交
b86706d58c
共有 4 個文件被更改,包括 34 次插入5 次删除
  1. 10 0
      lib/CObjectHandler.cpp
  2. 3 5
      lib/NetPacksLib.cpp
  3. 20 0
      server/CGameHandler.cpp
  4. 1 0
      server/CGameHandler.h

+ 10 - 0
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

+ 3 - 5
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<CArmedInstance*>(s->base->armyObj)->eraseStack(s->slot);
 		}

+ 20 - 0
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<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);
+	}
 }

+ 1 - 0
server/CGameHandler.h

@@ -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);