From 9356ba15eff631cd96adcd0cec64ab6e655f980a Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sat, 4 Sep 2010 14:49:15 +0000 Subject: [PATCH] * minor improvements for campaigns --- client/CPreGame.cpp | 7 +++++ client/CPreGame.h | 2 ++ hch/CCampaignHandler.cpp | 1 + lib/CGameState.cpp | 68 +++++++++++++++++++++------------------- server/CGameHandler.cpp | 10 +++++- 5 files changed, 55 insertions(+), 33 deletions(-) diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index c43b3edbf..6245aea8d 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -2804,6 +2804,13 @@ void CBonusSelection::startMap() void CBonusSelection::selectBonus( int id ) { sInfo.choosenCampaignBonus = id; + + const CCampaignScenario &scenario = ourCampaign->camp->scenarios[sInfo.whichMapInCampaign]; + const std::vector & bonDescs = scenario.travelOptions.bonusesToChoose; + if (bonDescs[id].type == 8) //hero crossover + { + setPlayer(sInfo.playerInfos[0], bonDescs[id].info1); //TODO: substitute with appropriate color + } } void CBonusSelection::changeDiff( bool increase ) diff --git a/client/CPreGame.h b/client/CPreGame.h index bf51b8457..059966189 100644 --- a/client/CPreGame.h +++ b/client/CPreGame.h @@ -355,6 +355,8 @@ class CBonusSelection : public CIntObject CHighlightableButtonsGroup * bonuses; public: + void bonusSelectionChanges(int choosenBonus); + StartInfo sInfo; CDefHandler *sFlags; diff --git a/hch/CCampaignHandler.cpp b/hch/CCampaignHandler.cpp index 34bb53c22..4cb7ed8e9 100644 --- a/hch/CCampaignHandler.cpp +++ b/hch/CCampaignHandler.cpp @@ -470,6 +470,7 @@ bool CCampaignScenario::isNotVoid() const void CCampaignScenario::prepareCrossoverHeroes( std::vector heroes ) { crossoverHeroes = heroes; + if (!(travelOptions.whatHeroKeeps & 1)) { diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index c6cee41cb..1ce065e7e 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1376,22 +1376,6 @@ 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; @@ -1658,6 +1642,14 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) CScenarioTravel::STravelBonus bonus = campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus]; + + std::vector Xheroes; + if (bonus.type == 8) //hero crossover + { + Xheroes = campaign->camp->scenarios[bonus.info2].crossoverHeroes; + } + + //selecting heroes by type for(int g=0; gobjects.size(); ++g) { CGObjectInstance * obj = map->objects[g]; @@ -1668,31 +1660,43 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) 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 + if(hp->subID != 0xFF) //select by type { + bool found = false; BOOST_FOREACH(CGHeroInstance * ghi, Xheroes) { if (ghi->subID == hp->subID) { + found = true; HLP::replaceHero(this, g, ghi); + Xheroes -= ghi; break; } } + if (!found) + { + //TODO: create new hero of this type + } + } + } + + //selecting heroes by power + + std::sort(Xheroes.begin(), Xheroes.end(), HLP::heroPowerSorter); + 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; + + if (hp->subID == 0xFF) //select by power + { + HLP::replaceHero(this, g, Xheroes[hp->power - 1]); + //we don't have to remove hero from Xheroes because it would destroy the order and duplicates shouldn't happen } } } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 77f0ba986..9f4b4c2d4 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -4757,7 +4757,15 @@ void CGameHandler::checkLossVictory( ui8 player ) if(gs->campaign) { - gs->campaign->mapConquered(gs->map->heroes); + std::vector hes; + BOOST_FOREACH(CGHeroInstance * ghi, gs->map->heroes) + { + if (ghi->tempOwner == 0 /*TODO: insert human player's color*/) + { + hes.push_back(ghi); + } + } + gs->campaign->mapConquered(hes); UpdateCampaignState ucs; ucs.camp = gs->campaign;