From 55a45619261fd0baa6a8aafa954684a16d8993d9 Mon Sep 17 00:00:00 2001 From: beegee1 Date: Wed, 26 Feb 2014 19:51:44 +0000 Subject: [PATCH] - fixed mantis #1729 --- lib/CGameState.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 348d82a7f..1a0ecaacd 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1231,15 +1231,25 @@ CGameState::CrossoverHeroesList CGameState::getCrossoverHeroesFromPreviousScenar // remove heroes which didn't reached the end of the scenario, but were available at the start for(auto hero : lostCrossoverHeroes) { - range::remove_if(crossoverHeroes.heroesFromAnyPreviousScenarios, CGObjectInstanceBySubIdFinder(hero)); + crossoverHeroes.heroesFromAnyPreviousScenarios.erase(range::remove_if(crossoverHeroes.heroesFromAnyPreviousScenarios, + CGObjectInstanceBySubIdFinder(hero)), crossoverHeroes.heroesFromAnyPreviousScenarios.end()); } // now add heroes which completed the scenario for(auto hero : scenario.crossoverHeroes) { // add new heroes and replace old heroes with newer ones - range::remove_if(crossoverHeroes.heroesFromAnyPreviousScenarios, CGObjectInstanceBySubIdFinder(hero)); - crossoverHeroes.heroesFromAnyPreviousScenarios.push_back(hero); + auto it = range::find_if(crossoverHeroes.heroesFromAnyPreviousScenarios, CGObjectInstanceBySubIdFinder(hero)); + if (it != crossoverHeroes.heroesFromAnyPreviousScenarios.end()) + { + // replace old hero with newer one + crossoverHeroes.heroesFromAnyPreviousScenarios[it - crossoverHeroes.heroesFromAnyPreviousScenarios.begin()] = hero; + } + else + { + // add new hero + crossoverHeroes.heroesFromAnyPreviousScenarios.push_back(hero); + } } } }