From b441143a73af44414924c34899dacb09fa04e62a Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sun, 1 Aug 2010 14:40:34 +0000 Subject: [PATCH] * monster campaign bonus handled * selecting / displaying difficulty --- client/CPreGame.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- client/CPreGame.h | 3 +++ lib/CGameState.cpp | 26 +++++++++++++++++++------- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 5e3ea289b..77cf7b07d 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -2193,7 +2193,8 @@ void CHotSeatPlayers::enterSelectionScreen() } CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap ) -: ourCampaign(_ourCampaign), whichMap(_whichMap), highlightedRegion(NULL), ourHeader(NULL), bonuses(NULL) +: ourCampaign(_ourCampaign), whichMap(_whichMap), highlightedRegion(NULL), ourHeader(NULL), bonuses(NULL), + diffLb(NULL), diffRb(NULL) { OBJ_CONSTRUCTION; static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP", @@ -2262,6 +2263,23 @@ CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap //difficulty printAtLoc("Difficulty", 691, 431, FONT_MEDIUM, zwykly, background); //Difficulty + {//difficulty pics + for (int b=0; b(b+3) + ".DEF"); + SDL_Surface * surfToDuplicate = cde->ourImages[0].bitmap; + diffPics[b] = SDL_ConvertSurface(surfToDuplicate, surfToDuplicate->format, + surfToDuplicate->flags); + + delete cde; + } + } + //difficulty selection buttons + if (ourCampaign->header.difficultyChoosenByPlayer) + { + diffLb = new AdventureMapButton("", "", bind(&CBonusSelection::changeDiff, this, false), 694, 508, "SCNRBLF.DEF"); + diffRb = new AdventureMapButton("", "", bind(&CBonusSelection::changeDiff, this, true), 738, 508, "SCNRBRT.DEF"); + } //load miniflags sFlags = CDefHandler::giveDef("ITGFLAGS.DEF"); @@ -2274,6 +2292,10 @@ CBonusSelection::~CBonusSelection() delete sizes; delete ourHeader; delete sFlags; + for (int b=0; bscenarios[whichOne].difficulty; mapDesc->setTxt(ourHeader->description); @@ -2395,6 +2418,9 @@ void CBonusSelection::show( SDL_Surface * to ) *myx += sFlags->ourImages[i->color].bitmap->w; } + //difficulty + blitAt(diffPics[sInfo.difficulty], 709, 455, to); + CIntObject::show(to); } @@ -2592,6 +2618,7 @@ void CBonusSelection::updateBonusSelection() void CBonusSelection::startMap() { StartInfo *si = new StartInfo(sInfo); + //don't pop - we should get back to this screen GH.popInts(3); curOpts = NULL; ::startGame(si); @@ -2602,6 +2629,18 @@ void CBonusSelection::selectBonus( int id ) sInfo.choosenCampaignBonus = id; } +void CBonusSelection::changeDiff( bool increase ) +{ + if (increase) + { + sInfo.difficulty = std::min(sInfo.difficulty + 1, 4); + } + else + { + sInfo.difficulty = std::max(sInfo.difficulty - 1, 0); + } +} + CBonusSelection::CRegion::CRegion( CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber ) : owner(_owner), accessible(_accessible), selectable(_selectable), myNumber(_myNumber) { diff --git a/client/CPreGame.h b/client/CPreGame.h index c3cb336a7..d6134abe9 100644 --- a/client/CPreGame.h +++ b/client/CPreGame.h @@ -319,6 +319,9 @@ class CBonusSelection : public CIntObject const CCampaign * ourCampaign; CMapHeader *ourHeader; CDefHandler *sizes; //icons of map sizes + SDL_Surface * diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this) + AdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty + void changeDiff(bool increase); //if false, then decrease int whichMap; //bonus selection diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index e47d7e09d..2815851ad 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1198,11 +1198,11 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) { struct HLP { - //heroType: FFFD means 'most powerful' and FFFE means 'generated' - static void giveCampaignBonusToHero(CGHeroInstance * hero, si32 heroType, const StartInfo * si, const CScenarioTravel & st ) + //it's assumed that given hero should receive the bonus + static void giveCampaignBonusToHero(CGHeroInstance * hero, const StartInfo * si, const CScenarioTravel & st ) { const CScenarioTravel::STravelBonus & curBonus = st.bonusesToChoose[si->choosenCampaignBonus]; - if(curBonus.isBonusForHero() && curBonus.info1 == heroType) + if(curBonus.isBonusForHero()) { //apply bonus switch (curBonus.type) @@ -1211,7 +1211,19 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) hero->spells.insert(curBonus.info2); break; case 1: //monster - //TODO + { + CCreatureSet newArmy = hero->getArmy(); + for(int i=0; isetArmy(newArmy); + } break; case 3: //artifact hero->giveArtifact(curBonus.info2); @@ -1411,7 +1423,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) //give campaign bonus if (si->mode == 2 && getPlayer(nnn->tempOwner)->human) { - HLP::giveCampaignBonusToHero(nnn, 0xFFFE, si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions); + HLP::giveCampaignBonusToHero(nnn, si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions); } } } @@ -1579,7 +1591,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) maxB = b; } } - HLP::giveCampaignBonusToHero(heroes[maxB], 0xFFFD, si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions); + HLP::giveCampaignBonusToHero(heroes[maxB], si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions); } else //specific hero { @@ -1587,7 +1599,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) { if (heroes[b]->subID == chosenBonus.info1) { - HLP::giveCampaignBonusToHero(heroes[b], chosenBonus.info1, si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions); + HLP::giveCampaignBonusToHero(heroes[b], si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions); break; } }