diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 8fce20484..aa1414628 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1090,19 +1090,6 @@ void CGameState::placeCampaignHeroes() logGlobal->debug("\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->instanceNames.erase(obj->instanceName); - map->objects[heroPlaceholder->id.getNum()] = nullptr; - delete heroPlaceholder; - } - } - // now add removed heroes again with unused type ID for(auto hero : removedHeroes) { @@ -1135,6 +1122,19 @@ void CGameState::placeCampaignHeroes() } } } + + // 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->instanceNames.erase(obj->instanceName); + map->objects[heroPlaceholder->id.getNum()] = nullptr; + delete heroPlaceholder; + } + } } void CGameState::placeStartingHero(PlayerColor playerColor, HeroTypeID heroTypeId, int3 townPos) @@ -2905,9 +2905,16 @@ void CGameState::replaceHeroesPlaceholders(const std::vectorartifactsInBackpack) fixArtifact(i.artifact); + map->removeBlockVisTiles(heroPlaceholder, true); + map->objects[heroPlaceholder->id.getNum()] = nullptr; + map->instanceNames.erase(heroPlaceholder->instanceName); + map->heroesOnMap.push_back(heroToPlace); map->objects[heroToPlace->id.getNum()] = heroToPlace; map->addBlockVisTiles(heroToPlace); + map->instanceNames[heroToPlace->instanceName] = heroToPlace; + + delete heroPlaceholder; scenarioOps->campState->getCurrentScenario().placedCrossoverHeroes.push_back(CCampaignState::crossoverSerialize(heroToPlace)); }