From 22e119770ae9b7a59eef22a5a35feb643d7ddaa7 Mon Sep 17 00:00:00 2001 From: beegee1 Date: Fri, 3 Jan 2014 16:36:22 +0000 Subject: [PATCH] Fixed mantis #1645 --- lib/CGameState.cpp | 35 +++++++++++++++++++---------------- lib/CGameState.h | 9 ++++++--- lib/mapping/MapFormatH3M.cpp | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index e9071764b..73e1c601d 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1104,12 +1104,12 @@ void CGameState::placeCampaignHeroes() } // replace heroes placeholders - auto campaignScenario = getCampaignScenarioForCrossoverHeroes(); + auto sourceCrossoverHeroes = getCrossoverHeroesFromPreviousScenario(); - if(campaignScenario) + if(!sourceCrossoverHeroes.empty()) { logGlobal->debugStream() << "\tPrepare crossover heroes"; - auto crossoverHeroes = prepareCrossoverHeroes(campaignScenario); + auto crossoverHeroes = prepareCrossoverHeroes(sourceCrossoverHeroes, scenarioOps->campState->getCurrentScenario().travelOptions); logGlobal->debugStream() << "\tGenerate list of hero placeholders"; const auto campaignHeroReplacements = generateCampaignHeroesToReplace(crossoverHeroes); @@ -1176,33 +1176,32 @@ void CGameState::placeStartingHero(PlayerColor playerColor, HeroTypeID heroTypeI map->getEditManager()->insertObject(hero, townPos); } -const CCampaignScenario * CGameState::getCampaignScenarioForCrossoverHeroes() const +std::vector CGameState::getCrossoverHeroesFromPreviousScenario() const { - const CCampaignScenario * campaignScenario = nullptr; + std::vector crossoverHeroes; auto campaignState = scenarioOps->campState; auto bonus = campaignState->getBonusForCurrentMap(); if (bonus->type == CScenarioTravel::STravelBonus::HEROES_FROM_PREVIOUS_SCENARIO) { - campaignScenario = &campaignState->camp->scenarios[bonus->info2]; + crossoverHeroes = campaignState->camp->scenarios[bonus->info2].crossoverHeroes; } else { 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 CGameState::prepareCrossoverHeroes(const CCampaignScenario * campaignScenario) +std::vector CGameState::prepareCrossoverHeroes(const std::vector & sourceCrossoverHeroes, const CScenarioTravel & travelOptions) { - auto crossoverHeroes = campaignScenario->crossoverHeroes; //TODO hero instances need to be copied, warning not trivial - const auto & travelOptions = campaignScenario->travelOptions; + auto crossoverHeroes = sourceCrossoverHeroes; //TODO deep copy hero instances - if (!(travelOptions.whatHeroKeeps & 1)) + if(!(travelOptions.whatHeroKeeps & 1)) { //trimming experience for(CGHeroInstance * cgh : crossoverHeroes) @@ -1210,7 +1209,8 @@ std::vector CGameState::prepareCrossoverHeroes(const CCampaign cgh->initExp(); } } - if (!(travelOptions.whatHeroKeeps & 2)) + + if(!(travelOptions.whatHeroKeeps & 2)) { //trimming prim skills for(CGHeroInstance * cgh : crossoverHeroes) @@ -1225,7 +1225,8 @@ std::vector CGameState::prepareCrossoverHeroes(const CCampaign } } } - if (!(travelOptions.whatHeroKeeps & 4)) + + if(!(travelOptions.whatHeroKeeps & 4)) { //trimming sec skills for(CGHeroInstance * cgh : crossoverHeroes) @@ -1233,7 +1234,8 @@ std::vector CGameState::prepareCrossoverHeroes(const CCampaign cgh->secSkills = cgh->type->secSkillsInit; } } - if (!(travelOptions.whatHeroKeeps & 8)) + + if(!(travelOptions.whatHeroKeeps & 8)) { //trimming spells for(CGHeroInstance * cgh : crossoverHeroes) @@ -1242,7 +1244,8 @@ std::vector CGameState::prepareCrossoverHeroes(const CCampaign cgh->eraseArtSlot(ArtifactPosition(ArtifactPosition::SPELLBOOK)); // spellbook will also be removed } } - if (!(travelOptions.whatHeroKeeps & 16)) + + if(!(travelOptions.whatHeroKeeps & 16)) { //trimming artifacts for(CGHeroInstance * hero : crossoverHeroes) diff --git a/lib/CGameState.h b/lib/CGameState.h index 6efadcf48..ff94976b8 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -61,6 +61,7 @@ struct QuestInfo; class CQuest; class CCampaignScenario; struct EventCondition; +class CScenarioTravel; namespace boost { @@ -471,10 +472,12 @@ private: void randomizeObject(CGObjectInstance *cur); void initPlayerStates(); void placeCampaignHeroes(); - const CCampaignScenario * getCampaignScenarioForCrossoverHeroes() const; - std::vector prepareCrossoverHeroes(const CCampaignScenario * campaignScenario); + std::vector getCrossoverHeroesFromPreviousScenario() const; - // 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 prepareCrossoverHeroes(const std::vector & sourceCrossoverHeroes, const CScenarioTravel & travelOptions); + + /// returns heroes and placeholders in where heroes will be put std::vector > generateCampaignHeroesToReplace(std::vector & crossoverHeroes); void replaceHeroesPlaceholders(const std::vector > &campHeroReplacements); diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index 2252414cc..27154b9cc 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -1621,7 +1621,7 @@ void CMapLoaderH3M::readObjects() } 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(nobj)); } }