From aff704d1cabac7f267d719262be2a6a6a0571996 Mon Sep 17 00:00:00 2001 From: beegee1 Date: Tue, 31 Dec 2013 16:58:11 +0000 Subject: [PATCH] - Fixed mantis #1643 --- lib/CGameState.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index bb2dd4bef..d03edaa96 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -2742,11 +2742,18 @@ std::vector > CGameState::generateC { 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(int g = 0; g < map->objects.size(); ++g) { CGObjectInstance * obj = map->objects[g]; - if (obj->ID == Obj::HERO_PLACEHOLDER) + if (obj && obj->ID == Obj::HERO_PLACEHOLDER) { CGHeroPlaceholder * hp = static_cast(obj); @@ -2766,10 +2773,7 @@ std::vector > CGameState::generateC } if(!found) { - auto nh = new CGHeroInstance(); - nh->subID = hp->subID; - nh->initHeroDefInfo(); - campaignHeroReplacements.push_back(std::make_pair(nh, gid)); + removeHeroPlaceholder(hp); } } } @@ -2786,7 +2790,7 @@ std::vector > CGameState::generateC for(int g = 0; g < map->objects.size(); ++g) { CGObjectInstance * obj = map->objects[g]; - if(obj->ID == Obj::HERO_PLACEHOLDER) + if(obj && obj->ID == Obj::HERO_PLACEHOLDER) { CGHeroPlaceholder * hp = dynamic_cast(obj); if(hp->subID == 0xFF) //select by power @@ -2809,9 +2813,7 @@ std::vector > CGameState::generateC } else { - map->removeBlockVisTiles(heroPlaceholder, true); - delete heroPlaceholder; - map->objects[heroPlaceholder->id.getNum()] = nullptr; + removeHeroPlaceholder(heroPlaceholder); } } @@ -2828,7 +2830,7 @@ void CGameState::replaceHeroesPlaceholders(const std::vectorid = obj.second; heroToPlace->tempOwner = placeholder->tempOwner; heroToPlace->pos = placeholder->pos; - heroToPlace->type = VLC->heroh->heroes[heroToPlace->type->ID.getNum()]; //TODO is this reasonable? either old type can be still used or it can be deleted? + heroToPlace->type = VLC->heroh->heroes[heroToPlace->subID]; for(auto &&i : heroToPlace->stacks) i.second->type = VLC->creh->creatures[i.second->getCreatureID()];