From 8a9f2781c2e95f2665b8fb5299f8bf3573adb4d8 Mon Sep 17 00:00:00 2001 From: beegee1 Date: Wed, 19 Feb 2014 19:14:32 +0000 Subject: [PATCH] - Fixed #1674 (Xeron should be re-created on AB campaign) - Remove all hero placeholders after placing campaign heroes --- lib/CGameState.cpp | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 56fc616f6..901730a07 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1151,6 +1151,18 @@ void CGameState::placeCampaignHeroes() logGlobal->debugStream() << "\tReplace placeholders with heroes"; replaceHeroesPlaceholders(campaignHeroReplacements); + // remove hero placeholders on map + for(auto obj : map->objects) + { + if(obj && obj->ID == Obj::HERO_PLACEHOLDER) + { + auto heroPlaceholder = dynamic_cast(obj.get()); + map->removeBlockVisTiles(heroPlaceholder, true); + map->objects[heroPlaceholder->id.getNum()] = nullptr; + delete heroPlaceholder; + } + } + // now add removed heroes again with unused type ID for(auto hero : removedHeroes) { @@ -2798,13 +2810,6 @@ std::vector CGameState::generateCampaignHer { std::vector campaignHeroReplacements; - auto removeHeroPlaceholder = [this](CGHeroPlaceholder * heroPlaceholder) - { - map->removeBlockVisTiles(heroPlaceholder, true); - map->objects[heroPlaceholder->id.getNum()] = nullptr; - delete heroPlaceholder; - }; - //selecting heroes by type for(auto obj : map->objects) { @@ -2817,14 +2822,26 @@ std::vector CGameState::generateCampaignHer { return hero->subID == heroPlaceholder->subID; }); + + CGHeroInstance * hero = nullptr; if(it == crossoverHeroes.heroesFromAnyPreviousScenarios.end()) { - removeHeroPlaceholder(heroPlaceholder); + if(scenarioOps->campState->camp->header.mapVersion == 12) // AB:AB campaign + { + // special case for this campaign, not found heroes will be newly created + hero = new CGHeroInstance(); + hero->initHero(HeroTypeID(heroPlaceholder->subID)); + } } else { - campaignHeroReplacements.push_back(CampaignHeroReplacement(*it, obj->id)); - crossoverHeroes.removeHeroFromBothLists(*it); + hero = *it; + crossoverHeroes.removeHeroFromBothLists(hero); + } + + if(hero) + { + campaignHeroReplacements.push_back(CampaignHeroReplacement(hero, heroPlaceholder->id)); } } } @@ -2861,10 +2878,6 @@ std::vector CGameState::generateCampaignHer { campaignHeroReplacements.push_back(CampaignHeroReplacement(crossoverHeroes.heroesFromPreviousScenario[i], heroPlaceholder->id)); } - else - { - removeHeroPlaceholder(heroPlaceholder); - } } return campaignHeroReplacements;