Browse Source

CGTownInstance: erase all stacks when town is captured by enemy

Arseniy Shestakov 9 years ago
parent
commit
9428f865d3
2 changed files with 10 additions and 0 deletions
  1. 9 0
      lib/mapObjects/CGTownInstance.cpp
  2. 1 0
      lib/mapObjects/CGTownInstance.h

+ 9 - 0
lib/mapObjects/CGTownInstance.cpp

@@ -802,6 +802,14 @@ void CGTownInstance::removeCapitols (PlayerColor owner) const
 	}
 }
 
+void CGTownInstance::clearArmy() const
+{
+	while(!stacks.empty())
+	{
+		cb->eraseStack(StackLocation(this, stacks.begin()->first));
+	}
+}
+
 int CGTownInstance::getBoatType() const
 {
 	switch (town->faction->alignment)
@@ -1162,6 +1170,7 @@ void CGTownInstance::battleFinished(const CGHeroInstance *hero, const BattleResu
 {
 	if(result.winner == 0)
 	{
+		clearArmy();
 		removeCapitols(hero->getOwner());
 		cb->setOwner (this, hero->tempOwner); //give control after checkout is done
 		FoWChange fw;

+ 1 - 0
lib/mapObjects/CGTownInstance.h

@@ -239,6 +239,7 @@ public:
 
 	void mergeGarrisonOnSiege() const; // merge garrison into army of visiting hero
 	void removeCapitols (PlayerColor owner) const;
+	void clearArmy() const;
 	void addHeroToStructureVisitors(const CGHeroInstance *h, si32 structureInstanceID) const; //hero must be visiting or garrisoned in town
 
 	CGTownInstance();