1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- Fixed #1674 (Xeron should be re-created on AB campaign)

- Remove all hero placeholders after placing campaign heroes
This commit is contained in:
beegee1 2014-02-19 19:14:32 +00:00
parent 8683b982c7
commit 8a9f2781c2

View File

@ -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<CGHeroPlaceholder *>(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::CampaignHeroReplacement> CGameState::generateCampaignHer
{
std::vector<CampaignHeroReplacement> 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::CampaignHeroReplacement> 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::CampaignHeroReplacement> CGameState::generateCampaignHer
{
campaignHeroReplacements.push_back(CampaignHeroReplacement(crossoverHeroes.heroesFromPreviousScenario[i], heroPlaceholder->id));
}
else
{
removeHeroPlaceholder(heroPlaceholder);
}
}
return campaignHeroReplacements;