1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-01 00:45:26 +02:00

Fixed mantis #1645

This commit is contained in:
beegee1
2014-01-03 16:36:22 +00:00
parent 339e1cd98b
commit 22e119770a
3 changed files with 26 additions and 20 deletions

View File

@ -1104,12 +1104,12 @@ void CGameState::placeCampaignHeroes()
} }
// replace heroes placeholders // replace heroes placeholders
auto campaignScenario = getCampaignScenarioForCrossoverHeroes(); auto sourceCrossoverHeroes = getCrossoverHeroesFromPreviousScenario();
if(campaignScenario) if(!sourceCrossoverHeroes.empty())
{ {
logGlobal->debugStream() << "\tPrepare crossover heroes"; logGlobal->debugStream() << "\tPrepare crossover heroes";
auto crossoverHeroes = prepareCrossoverHeroes(campaignScenario); auto crossoverHeroes = prepareCrossoverHeroes(sourceCrossoverHeroes, scenarioOps->campState->getCurrentScenario().travelOptions);
logGlobal->debugStream() << "\tGenerate list of hero placeholders"; logGlobal->debugStream() << "\tGenerate list of hero placeholders";
const auto campaignHeroReplacements = generateCampaignHeroesToReplace(crossoverHeroes); const auto campaignHeroReplacements = generateCampaignHeroesToReplace(crossoverHeroes);
@ -1176,31 +1176,30 @@ void CGameState::placeStartingHero(PlayerColor playerColor, HeroTypeID heroTypeI
map->getEditManager()->insertObject(hero, townPos); map->getEditManager()->insertObject(hero, townPos);
} }
const CCampaignScenario * CGameState::getCampaignScenarioForCrossoverHeroes() const std::vector<CGHeroInstance *> CGameState::getCrossoverHeroesFromPreviousScenario() const
{ {
const CCampaignScenario * campaignScenario = nullptr; std::vector<CGHeroInstance *> crossoverHeroes;
auto campaignState = scenarioOps->campState; auto campaignState = scenarioOps->campState;
auto bonus = campaignState->getBonusForCurrentMap(); auto bonus = campaignState->getBonusForCurrentMap();
if (bonus->type == CScenarioTravel::STravelBonus::HEROES_FROM_PREVIOUS_SCENARIO) if (bonus->type == CScenarioTravel::STravelBonus::HEROES_FROM_PREVIOUS_SCENARIO)
{ {
campaignScenario = &campaignState->camp->scenarios[bonus->info2]; crossoverHeroes = campaignState->camp->scenarios[bonus->info2].crossoverHeroes;
} }
else else
{ {
if(!campaignState->mapsConquered.empty()) if(!campaignState->mapsConquered.empty())
{ {
campaignScenario = &campaignState->camp->scenarios[campaignState->mapsConquered.back()]; crossoverHeroes = campaignState->camp->scenarios[campaignState->mapsConquered.back()].crossoverHeroes;
} }
} }
return campaignScenario; return std::move(crossoverHeroes);
} }
std::vector<CGHeroInstance *> CGameState::prepareCrossoverHeroes(const CCampaignScenario * campaignScenario) std::vector<CGHeroInstance *> CGameState::prepareCrossoverHeroes(const std::vector<CGHeroInstance *> & sourceCrossoverHeroes, const CScenarioTravel & travelOptions)
{ {
auto crossoverHeroes = campaignScenario->crossoverHeroes; //TODO hero instances need to be copied, warning not trivial auto crossoverHeroes = sourceCrossoverHeroes; //TODO deep copy hero instances
const auto & travelOptions = campaignScenario->travelOptions;
if(!(travelOptions.whatHeroKeeps & 1)) if(!(travelOptions.whatHeroKeeps & 1))
{ {
@ -1210,6 +1209,7 @@ std::vector<CGHeroInstance *> CGameState::prepareCrossoverHeroes(const CCampaign
cgh->initExp(); cgh->initExp();
} }
} }
if(!(travelOptions.whatHeroKeeps & 2)) if(!(travelOptions.whatHeroKeeps & 2))
{ {
//trimming prim skills //trimming prim skills
@ -1225,6 +1225,7 @@ std::vector<CGHeroInstance *> CGameState::prepareCrossoverHeroes(const CCampaign
} }
} }
} }
if(!(travelOptions.whatHeroKeeps & 4)) if(!(travelOptions.whatHeroKeeps & 4))
{ {
//trimming sec skills //trimming sec skills
@ -1233,6 +1234,7 @@ std::vector<CGHeroInstance *> CGameState::prepareCrossoverHeroes(const CCampaign
cgh->secSkills = cgh->type->secSkillsInit; cgh->secSkills = cgh->type->secSkillsInit;
} }
} }
if(!(travelOptions.whatHeroKeeps & 8)) if(!(travelOptions.whatHeroKeeps & 8))
{ {
//trimming spells //trimming spells
@ -1242,6 +1244,7 @@ std::vector<CGHeroInstance *> CGameState::prepareCrossoverHeroes(const CCampaign
cgh->eraseArtSlot(ArtifactPosition(ArtifactPosition::SPELLBOOK)); // spellbook will also be removed cgh->eraseArtSlot(ArtifactPosition(ArtifactPosition::SPELLBOOK)); // spellbook will also be removed
} }
} }
if(!(travelOptions.whatHeroKeeps & 16)) if(!(travelOptions.whatHeroKeeps & 16))
{ {
//trimming artifacts //trimming artifacts

View File

@ -61,6 +61,7 @@ struct QuestInfo;
class CQuest; class CQuest;
class CCampaignScenario; class CCampaignScenario;
struct EventCondition; struct EventCondition;
class CScenarioTravel;
namespace boost namespace boost
{ {
@ -471,10 +472,12 @@ private:
void randomizeObject(CGObjectInstance *cur); void randomizeObject(CGObjectInstance *cur);
void initPlayerStates(); void initPlayerStates();
void placeCampaignHeroes(); void placeCampaignHeroes();
const CCampaignScenario * getCampaignScenarioForCrossoverHeroes() const; std::vector<CGHeroInstance *> getCrossoverHeroesFromPreviousScenario() const;
std::vector<CGHeroInstance *> prepareCrossoverHeroes(const CCampaignScenario * campaignScenario);
// returns heroes and placeholders in where heroes will be put /// gets prepared and copied hero instances with crossover heroes from prev. scenario and travel options from current scenario
std::vector<CGHeroInstance *> prepareCrossoverHeroes(const std::vector<CGHeroInstance *> & sourceCrossoverHeroes, const CScenarioTravel & travelOptions);
/// returns heroes and placeholders in where heroes will be put
std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > generateCampaignHeroesToReplace(std::vector<CGHeroInstance *> & crossoverHeroes); std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > generateCampaignHeroesToReplace(std::vector<CGHeroInstance *> & crossoverHeroes);
void replaceHeroesPlaceholders(const std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > &campHeroReplacements); void replaceHeroesPlaceholders(const std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > &campHeroReplacements);

View File

@ -1621,7 +1621,7 @@ void CMapLoaderH3M::readObjects()
} }
if(nobj->ID == Obj::HERO) if(nobj->ID == Obj::HERO)
{ {
logGlobal->infoStream() << "Hero: " << VLC->heroh->heroes[nobj->subID]->name << " at " << objPos; logGlobal->debugStream() << "Hero: " << VLC->heroh->heroes[nobj->subID]->name << " at " << objPos;
map->heroesOnMap.push_back(static_cast<CGHeroInstance*>(nobj)); map->heroesOnMap.push_back(static_cast<CGHeroInstance*>(nobj));
} }
} }