소스 검색

Remove heroes placeholders even in single scenarios

Ivan Savenko 2 년 전
부모
커밋
453d441562
3개의 변경된 파일18개의 추가작업 그리고 13개의 파일을 삭제
  1. 17 0
      lib/gameState/CGameState.cpp
  2. 1 0
      lib/gameState/CGameState.h
  3. 0 13
      lib/gameState/CGameStateCampaign.cpp

+ 17 - 0
lib/gameState/CGameState.cpp

@@ -512,6 +512,7 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, bool allow
 	initPlayerStates();
 	if (campaign)
 		campaign->placeCampaignHeroes();
+	removeHeroPlaceholders();
 	initGrailPosition();
 	initRandomFactionsForPlayers();
 	randomizeMapObjects();
@@ -858,6 +859,22 @@ void CGameState::placeStartingHeroes()
 	}
 }
 
+void CGameState::removeHeroPlaceholders()
+{
+	// remove any hero placeholders that remain on map after (potential) campaign heroes placement
+	for(auto obj : map->objects)
+	{
+		if(obj && obj->ID == Obj::HERO_PLACEHOLDER)
+		{
+			auto heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get());
+			map->removeBlockVisTiles(heroPlaceholder, true);
+			map->instanceNames.erase(obj->instanceName);
+			map->objects[heroPlaceholder->id.getNum()] = nullptr;
+			delete heroPlaceholder;
+		}
+	}
+}
+
 void CGameState::initStartingResources()
 {
 	logGlobal->debug("\tSetting up resources");

+ 1 - 0
lib/gameState/CGameState.h

@@ -220,6 +220,7 @@ private:
 	void initPlayerStates();
 	void placeStartingHeroes();
 	void placeStartingHero(const PlayerColor & playerColor, const HeroTypeID & heroTypeId, int3 townPos);
+	void removeHeroPlaceholders();
 	void initStartingResources();
 	void initHeroes();
 	void placeHeroesInTowns();

+ 0 - 13
lib/gameState/CGameStateCampaign.cpp

@@ -333,19 +333,6 @@ void CGameStateCampaign::placeCampaignHeroes()
 			gameState->map->getEditManager()->insertObject(hero);
 		}
 	}
-
-	// remove hero placeholders on map
-	for(auto obj : gameState->map->objects)
-	{
-		if(obj && obj->ID == Obj::HERO_PLACEHOLDER)
-		{
-			auto heroPlaceholder = dynamic_cast<CGHeroPlaceholder *>(obj.get());
-			gameState->map->removeBlockVisTiles(heroPlaceholder, true);
-			gameState->map->instanceNames.erase(obj->instanceName);
-			gameState->map->objects[heroPlaceholder->id.getNum()] = nullptr;
-			delete heroPlaceholder;
-		}
-	}
 }
 
 void CGameStateCampaign::giveCampaignBonusToHero(CGHeroInstance * hero)