From 34b4e09927c00c1105250089b23c279f218974fb Mon Sep 17 00:00:00 2001 From: mateuszb Date: Mon, 30 Aug 2010 14:52:18 +0000 Subject: [PATCH] * minor changes - hero crossover in campaigns --- lib/CGameState.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 55b9828fe..38dec6030 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1203,6 +1203,22 @@ CGameState::~CGameState() capitols.clear(); } +namespace HHLP +{ + class HeroRemoverHelper + { + public: + si32 allowedplayer; + HeroRemoverHelper(si32 player) : allowedplayer(player) + { + } + bool operator()(const CGHeroInstance * cgh) + { + return cgh->tempOwner != allowedplayer; + } + }; +} + void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) { VLC->creh->globalEffects = &globalEffects; @@ -1276,6 +1292,18 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) return ret; } + static void replaceHero( CGameState * gs, int objId, CGHeroInstance * ghi ) + { + ghi->id = objId; + gs->map->objects[objId] = ghi; + gs->map->heroes.push_back(ghi); + } + + //sort in descending order by power + static bool heroPowerSorter(const CGHeroInstance * a, const CGHeroInstance * b) + { + return a->getHeroStrength() > b->getHeroStrength(); + } }; switch(si->mode) @@ -1449,6 +1477,53 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) } } + /*************************replace hero placeholders*****************************/ + + if (campaign) + { + + CScenarioTravel::STravelBonus bonus = + campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus]; + + for(int g=0; gobjects.size(); ++g) + { + CGObjectInstance * obj = map->objects[g]; + if (obj->ID != 214) //not a placeholder + { + continue; + } + CGHeroPlaceholder * hp = static_cast(obj); + CGHeroInstance * substitution = NULL; + + std::vector Xheroes; + if (bonus.type == 8) //hero crossover + { + Xheroes = campaign->camp->scenarios[bonus.info2].crossoverHeroes; + std::remove_if(Xheroes.begin(), Xheroes.end(), HHLP::HeroRemoverHelper(bonus.info1)); + } + else if (bonus.type == 9) //starting hero + { + } + + if (hp->subID == 0xFF) //select by power + { + std::sort(Xheroes.begin(), Xheroes.end(), HLP::heroPowerSorter); + HLP::replaceHero(this, g, Xheroes[hp->power - 1]); + } + else //select by type + { + BOOST_FOREACH(CGHeroInstance * ghi, Xheroes) + { + if (ghi->subID == hp->subID) + { + HLP::replaceHero(this, g, ghi); + break; + } + } + } + } + } + /******************RESOURCES****************************************************/ std::vector startresAI, startresHuman; std::ifstream tis(DATA_DIR "/config/startres.txt");