From 0f36095dc73ab5dcd1b58087c612ada2122c42b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 30 Oct 2010 18:54:59 +0000 Subject: [PATCH] Less "crashy" campaigns. --- lib/CGameState.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 108dbc4eb..3515adffd 100644 --- a/lib/CGameState.cpp +++ b/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 {