Преглед изворни кода

Likely fixed duplicated random heroes

Ivan Savenko пре 10 година
родитељ
комит
89bf3592e3
2 измењених фајлова са 16 додато и 12 уклоњено
  1. 8 4
      lib/CGameState.cpp
  2. 8 8
      lib/StartInfo.h

+ 8 - 4
lib/CGameState.cpp

@@ -1383,7 +1383,8 @@ void CGameState::placeStartingHeroes()
 			}
 
 			int heroTypeId = pickNextHeroType(playerColor);
-			if(playerSettingPair.second.hero == -1) playerSettingPair.second.hero = heroTypeId;
+			if(playerSettingPair.second.hero == -1)
+				playerSettingPair.second.hero = heroTypeId;
 
 			placeStartingHero(playerColor, HeroTypeID(heroTypeId), playerInfo.posOfMainTown);
 		}
@@ -2770,7 +2771,7 @@ CGHeroInstance * CGameState::getUsedHero(HeroTypeID hid) const
 {
 	for(auto hero : map->heroesOnMap)  //heroes instances initialization
 	{
-		if(hero->subID == hid.getNum())
+		if(hero->type && hero->type->ID == hid)
 		{
 			return hero;
 		}
@@ -2778,9 +2779,12 @@ CGHeroInstance * CGameState::getUsedHero(HeroTypeID hid) const
 
 	for(auto obj : map->objects) //prisons
 	{
-		if(obj && obj->ID == Obj::PRISON && obj->subID == hid.getNum())
+		if(obj && obj->ID == Obj::PRISON )
 		{
-			return dynamic_cast<CGHeroInstance *>(obj.get());
+			auto hero = dynamic_cast<CGHeroInstance *>(obj.get());
+			assert(hero);
+			if ( hero->type && hero->type->ID == hid )
+				return hero;
 		}
 	}
 

+ 8 - 8
lib/StartInfo.h

@@ -31,7 +31,7 @@ struct PlayerSettings
 	Ebonus bonus;
 	si16 castle;
 	si32 hero,
-	     heroPortrait; //-1 if default, else ID
+		 heroPortrait; //-1 if default, else ID
 
 	std::string heroName;
 	PlayerColor color; //from 0 - 
@@ -70,13 +70,13 @@ struct StartInfo
 {
 	enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, DUEL, INVALID = 255};
 
-	EMode mode;
-	ui8 difficulty; //0=easy; 4=impossible
-
-	typedef std::map<PlayerColor, PlayerSettings> TPlayerInfos;
-	TPlayerInfos playerInfos; //color indexed
-
-	ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
+	EMode mode;
+	ui8 difficulty; //0=easy; 4=impossible
+
+	typedef std::map<PlayerColor, PlayerSettings> TPlayerInfos;
+	TPlayerInfos playerInfos; //color indexed
+
+	ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack)
 	ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
 	ui32 mapfileChecksum; //0 if not relevant
 	ui8 turnTime; //in minutes, 0=unlimited