diff --git a/StartInfo.h b/StartInfo.h index 6cd9961a9..5a8f15d96 100644 --- a/StartInfo.h +++ b/StartInfo.h @@ -51,6 +51,8 @@ struct PlayerSettings struct StartInfo { + enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN}; + ui8 mode; //0 - new game; 1 - load game; 2 - campaign ui8 difficulty; //0=easy; 4=impossible std::map playerInfos; //color indexed diff --git a/client/CMT.cpp b/client/CMT.cpp index ad0f8baa9..902ecbc64 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -639,11 +639,11 @@ void startGame(StartInfo * options) CPlayerInterface::howManyPeople = 0; switch(options->mode) //new game { - case 0: - case 2: + case StartInfo::NEW_GAME: + case StartInfo::CAMPAIGN: client->newGame(NULL, options); break; - case 1: + case StartInfo::LOAD_GAME: std::string fname = options->mapname; boost::algorithm::erase_last(fname,".vlgm1"); client->loadGame(fname); diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index f55e52177..974c951fe 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1818,12 +1818,12 @@ void CPlayerInterface::gameOver(ui8 player, bool victory ) howManyPeople--; if(!howManyPeople) //all human players eliminated { - //return to main menu - SDL_Event event; - event.type = SDL_USEREVENT; - event.user.code = 2; - SDL_PushEvent(&event); + if(cb->getStartInfo()->mode != StartInfo::CAMPAIGN) + requestReturningToMainMenu(); + + //TODO next campaign scenario } + } else { @@ -2083,6 +2083,14 @@ void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj) showShipyardDialog(obj); } +void CPlayerInterface::requestReturningToMainMenu() +{ + SDL_Event event; + event.type = SDL_USEREVENT; + event.user.code = 2; + SDL_PushEvent(&event); +} + CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting() { spellbookLastPageBattle = spellbokLastPageAdvmap = 0; diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index f495b8b67..6e84fc2f3 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -244,6 +244,7 @@ public: void acceptTurn(); //used during hot seat after your turn message is close void tryDiggging(const CGHeroInstance *h); void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard; + void requestReturningToMainMenu(); CPlayerInterface(int Player);//c-tor ~CPlayerInterface();//d-tor diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index fdd801445..8bf1fbd49 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -337,7 +337,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, bool MultiPlayer) sInfo.difficulty = 1; current = NULL; - sInfo.mode = (Type == CMenuScreen::newGame ? 0 : 1); + sInfo.mode = (Type == CMenuScreen::newGame ? StartInfo::NEW_GAME : StartInfo::LOAD_GAME); sInfo.turnTime = 0; curTab = NULL; @@ -2363,7 +2363,7 @@ void CBonusSelection::selectMap( int whichOne ) { sInfo.difficulty = ourCampaign->camp->scenarios[whichOne].difficulty; sInfo.mapname = ourCampaign->camp->header.filename; - sInfo.mode = 2; + sInfo.mode = StartInfo::CAMPAIGN; //get header int i = 0; diff --git a/hch/CArtHandler.cpp b/hch/CArtHandler.cpp index 4bb8b6e54..056c3de41 100644 --- a/hch/CArtHandler.cpp +++ b/hch/CArtHandler.cpp @@ -805,4 +805,15 @@ void CArtHandler::clearHlpLists() minors.clear(); majors.clear(); relics.clear(); +} + +void CArtHandler::initAllowedArtifactsList(const std::vector &allowed) +{ + allowedArtifacts.clear(); + clearHlpLists(); + for (int i=0; i<144; ++i) //yes, 144 + { + if (allowed[i]) + allowedArtifacts.push_back(artifacts[i]); + } } \ No newline at end of file diff --git a/hch/CArtHandler.h b/hch/CArtHandler.h index b74fa75e5..9b654bec7 100644 --- a/hch/CArtHandler.h +++ b/hch/CArtHandler.h @@ -74,6 +74,7 @@ public: bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();} void equipArtifact (std::map &artifWorn, ui16 slotID, ui32 artifactID); void unequipArtifact (std::map &artifWorn, ui16 slotID); + void initAllowedArtifactsList(const std::vector &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed static int convertMachineID(int id, bool creToArt); CArtHandler(); ~CArtHandler(); diff --git a/hch/CCampaignHandler.cpp b/hch/CCampaignHandler.cpp index e3740024b..1a8c5ffa1 100644 --- a/hch/CCampaignHandler.cpp +++ b/hch/CCampaignHandler.cpp @@ -470,7 +470,7 @@ bool CScenarioTravel::STravelBonus::isBonusForHero() const void CCampaignState::initNewCampaign( const StartInfo &si ) { - assert(si.mode == 2); + assert(si.mode == StartInfo::CAMPAIGN); campaignName = si.mapname; currentMap = si.whichMapInCampaign; diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index a8aed1e73..ea564f97b 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1267,33 +1267,31 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) } }; - VLC->arth->allowedArtifacts.clear(); - VLC->arth->clearHlpLists(); + switch(si->mode) { - case 0: + case StartInfo::NEW_GAME: map = new Mapa(si->mapname); - for (int i=0; i<144; ++i) //yes, 144 + break; + case StartInfo::CAMPAIGN: { - if (map->allowedArtifact[i]) - VLC->arth->allowedArtifacts.push_back(VLC->arth->artifacts[i]); - } - break; - case 2: - campaign = new CCampaignState(); - campaign->initNewCampaign(*si); - std::string &mapContent = campaign->camp->mapPieces[si->whichMapInCampaign]; - map = new Mapa(); - map->initFromBytes((const unsigned char*)mapContent.c_str()); - for (int i=0; i<144; ++i) - { - if (map->allowedArtifact[i]) - VLC->arth->allowedArtifacts.push_back(VLC->arth->artifacts[i]); + assert(vstd::contains(campaign->camp->mapPieces, si->whichMapInCampaign)); + campaign = new CCampaignState(); + campaign->initNewCampaign(*si); + + std::string &mapContent = campaign->camp->mapPieces[si->whichMapInCampaign]; + map = new Mapa(); + map->initFromBytes((const unsigned char*)mapContent.c_str()); } break; + default: + tlog1 << "Wrong mode: " << (int)si->mode << std::endl; + return; } + VLC->arth->initAllowedArtifactsList(map->allowedArtifact); tlog0 << "Map loaded!" << std::endl; + //tlog0 <<"Reading and detecting map file (together): "<objects.push_back(nnn); map->addBlockVisTiles(nnn); //give campaign bonus - if (si->mode == 2 && getPlayer(nnn->tempOwner)->human) + if (si->mode == StartInfo::CAMPAIGN && getPlayer(nnn->tempOwner)->human) { HLP::giveCampaignBonusToHero(nnn, si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions); } @@ -1482,7 +1480,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) } //give start resource bonus in case of campaign - if (si->mode == 2) + if (si->mode == StartInfo::CAMPAIGN) { CScenarioTravel::STravelBonus chosenBonus = campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus]; @@ -1566,7 +1564,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) hpool.pavailable[map->disposedHeroes[i].ID] = map->disposedHeroes[i].players; } - if (si->mode == 2) //give campaign bonuses for specific / best hero + if (si->mode == StartInfo::CAMPAIGN) //give campaign bonuses for specific / best hero { CScenarioTravel::STravelBonus chosenBonus = @@ -1763,7 +1761,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) } //campaign bonuses for towns - if (si->mode == 2) + if (si->mode == StartInfo::CAMPAIGN) { CScenarioTravel::STravelBonus chosenBonus = campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus]; diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 82e3b21d6..110365b72 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -81,7 +81,7 @@ void CVCMIServer::newGame(CConnection *c) FILE * f = fopen(si->mapname.c_str(),"r"); problem = !f; #endif - if(problem && si->mode == 0) //TODO some checking for campaigns + if(problem && si->mode == StartInfo::NEW_GAME) //TODO some checking for campaigns { *c << ui8(problem); //WRONG! return;