1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +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
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<CGHeroInstance *> CGameState::getCrossoverHeroesFromPreviousScenario() const
{
const CCampaignScenario * campaignScenario = nullptr;
std::vector<CGHeroInstance *> 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<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
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<CGHeroInstance *> 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<CGHeroInstance *> 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<CGHeroInstance *> 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<CGHeroInstance *> 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)

View File

@ -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<CGHeroInstance *> prepareCrossoverHeroes(const CCampaignScenario * campaignScenario);
std::vector<CGHeroInstance *> 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<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);
void replaceHeroesPlaceholders(const std::vector<std::pair<CGHeroInstance*, ObjectInstanceID> > &campHeroReplacements);

View File

@ -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<CGHeroInstance*>(nobj));
}
}