Browse Source

Less "crashy" campaigns.

Michał W. Urbańczyk 15 years ago
parent
commit
0f36095dc7
1 changed files with 8 additions and 2 deletions
  1. 8 2
      lib/CGameState.cpp

+ 8 - 2
lib/CGameState.cpp

@@ -1703,7 +1703,10 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 
 			if (hp->subID == 0xFF) //select by power
 			{
-				HLP::replaceHero(this, g, Xheroes[hp->power - 1]);
+				if(Xheroes.size() > hp->power - 1)
+					HLP::replaceHero(this, g, Xheroes[hp->power - 1]);
+				else
+					tlog2 << "Warning, to hero to replace!\n";
 				//we don't have to remove hero from Xheroes because it would destroy the order and duplicates shouldn't happen
 			}
 		}
@@ -1863,7 +1866,10 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 						maxB = b;
 					}
 				}
-				HLP::giveCampaignBonusToHero(heroes[maxB], scenarioOps, campaign->camp->scenarios[scenarioOps->whichMapInCampaign].travelOptions);
+				if(maxB < 0)
+					tlog2 << "Warning - cannot give bonus to hero cause there are no heroes!\n";
+				else
+					HLP::giveCampaignBonusToHero(heroes[maxB], scenarioOps, campaign->camp->scenarios[scenarioOps->whichMapInCampaign].travelOptions);
 			}
 			else //specific hero
 			{