1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

- Fixed mantis (starting another scenario crashes VCMI for now)

- Refactoring
This commit is contained in:
beegee1 2013-12-16 18:39:56 +00:00
parent 7d7e65a316
commit b9b25ef552
8 changed files with 312 additions and 256 deletions

@ -1535,6 +1535,14 @@ CAdventureOptions::CAdventureOptions():
} }
void CAdventureOptions::showScenarioInfo() void CAdventureOptions::showScenarioInfo()
{
auto campState = LOCPLINT->cb->getStartInfo()->campState;
if(campState)
{
GH.pushInt(new CBonusSelection(campState));
}
else
{ {
GH.pushInt(new CScenarioInfo(LOCPLINT->cb->getMapHeader(), LOCPLINT->cb->getStartInfo())); GH.pushInt(new CScenarioInfo(LOCPLINT->cb->getMapHeader(), LOCPLINT->cb->getStartInfo()));
} }
}

@ -886,6 +886,13 @@ static void listenForEvents()
startGame(&si); startGame(&si);
} }
break; break;
case PREPARE_RESTART_CAMPAIGN:
{
auto si = reinterpret_cast<StartInfo *>(ev.user.data1);
endGame();
startGame(si);
}
break;
case RETURN_TO_MENU_LOAD: case RETURN_TO_MENU_LOAD:
endGame(); endGame();
CGPreGame::create(); CGPreGame::create();

@ -78,7 +78,8 @@ enum
STOP_CLIENT = 3, STOP_CLIENT = 3,
RESTART_GAME, RESTART_GAME,
RETURN_TO_MENU_LOAD, RETURN_TO_MENU_LOAD,
FULLSCREEN_TOGGLED FULLSCREEN_TOGGLED,
PREPARE_RESTART_CAMPAIGN
}; };
/// Central class for managing user interface logic /// Central class for managing user interface logic

@ -3119,6 +3119,13 @@ void CBonusSelection::init()
diffLb = nullptr; diffLb = nullptr;
diffRb = nullptr; diffRb = nullptr;
bonuses = nullptr; bonuses = nullptr;
selectedMap = 0;
// Initialize start info
startInfo.mapname = ourCampaign->camp->header.filename;
startInfo.mode = StartInfo::CAMPAIGN;
startInfo.campState = ourCampaign;
startInfo.turnTime = 0;
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP", static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP",
@ -3137,6 +3144,7 @@ void CBonusSelection::init()
blitAt(panel, 456, 6, background); blitAt(panel, 456, 6, background);
startB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::startMap, this), 475, 536, "CBBEGIB.DEF", SDLK_RETURN); startB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::startMap, this), 475, 536, "CBBEGIB.DEF", SDLK_RETURN);
restartB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::restartMap, this), 475, 536, "CBRESTB.DEF", SDLK_RETURN);
backB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::goBack, this), 624, 536, "CBCANCB.DEF", SDLK_ESCAPE); backB = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::goBack, this), 624, 536, "CBCANCB.DEF", SDLK_ESCAPE);
//campaign name //campaign name
@ -3151,11 +3159,11 @@ void CBonusSelection::init()
//campaign description //campaign description
graphics->fonts[FONT_SMALL]->renderTextLeft(background, CGI->generaltexth->allTexts[38], Colors::YELLOW, Point(481, 63)); graphics->fonts[FONT_SMALL]->renderTextLeft(background, CGI->generaltexth->allTexts[38], Colors::YELLOW, Point(481, 63));
cmpgDesc = new CTextBox(ourCampaign->camp->header.description, Rect(480, 86, 286, 117), 1); campaignDescription = new CTextBox(ourCampaign->camp->header.description, Rect(480, 86, 286, 117), 1);
//cmpgDesc->showAll(background); //campaignDescription->showAll(background);
//map description //map description
mapDesc = new CTextBox("", Rect(480, 280, 286, 117), 1); mapDescription = new CTextBox("", Rect(480, 280, 286, 117), 1);
//bonus choosing //bonus choosing
graphics->fonts[FONT_MEDIUM]->renderTextLeft(background, CGI->generaltexth->allTexts[71], Colors::WHITE, Point(511, 432)); graphics->fonts[FONT_MEDIUM]->renderTextLeft(background, CGI->generaltexth->allTexts[71], Colors::WHITE, Point(511, 432));
@ -3181,15 +3189,6 @@ void CBonusSelection::init()
} }
} }
//unlock if no bonuses -- it's acceptable
// //init campaign state if necessary
// if (ourCampaign->campaignName.size() == 0)
// {
// ourCampaign->initNewCampaign(sInfo);
// }
//allies / enemies //allies / enemies
graphics->fonts[FONT_SMALL]->renderTextLeft(background, CGI->generaltexth->allTexts[390] + ":", Colors::WHITE, Point(486, 407)); graphics->fonts[FONT_SMALL]->renderTextLeft(background, CGI->generaltexth->allTexts[390] + ":", Colors::WHITE, Point(486, 407));
graphics->fonts[FONT_SMALL]->renderTextLeft(background, CGI->generaltexth->allTexts[391] + ":", Colors::WHITE, Point(619, 407)); graphics->fonts[FONT_SMALL]->renderTextLeft(background, CGI->generaltexth->allTexts[391] + ":", Colors::WHITE, Point(619, 407));
@ -3215,26 +3214,22 @@ void CBonusSelection::init()
//difficulty selection buttons //difficulty selection buttons
if (ourCampaign->camp->header.difficultyChoosenByPlayer) if (ourCampaign->camp->header.difficultyChoosenByPlayer)
{ {
diffLb = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::changeDiff, this, false), 694, 508, "SCNRBLF.DEF"); diffLb = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::decreaseDifficulty, this), 694, 508, "SCNRBLF.DEF");
diffRb = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::changeDiff, this, true), 738, 508, "SCNRBRT.DEF"); diffRb = new CAdventureMapButton("", "", boost::bind(&CBonusSelection::increaseDifficulty, this), 738, 508, "SCNRBRT.DEF");
} }
//load miniflags //load miniflags
sFlags = CDefHandler::giveDef("ITGFLAGS.DEF"); sFlags = CDefHandler::giveDef("ITGFLAGS.DEF");
} }
CBonusSelection::CBonusSelection(shared_ptr<CCampaignState> _ourCampaign) : ourCampaign(_ourCampaign)
CBonusSelection::CBonusSelection(shared_ptr<CCampaignState> _ourCampaign)
: ourCampaign(std::move(_ourCampaign))
{ {
init(); init();
} }
CBonusSelection::CBonusSelection( std::string campaignFName ) CBonusSelection::CBonusSelection(const std::string & campaignFName)
{ {
ourCampaign = make_shared<CCampaignState>(CCampaignHandler::getCampaign(campaignFName)); ourCampaign = make_shared<CCampaignState>(CCampaignHandler::getCampaign(campaignFName));
sInfo.campState = ourCampaign;
init(); init();
} }
@ -3295,31 +3290,43 @@ void CBonusSelection::loadPositionsOfGraphics()
assert(idx == CGI->generaltexth->campaignMapNames.size()); assert(idx == CGI->generaltexth->campaignMapNames.size());
} }
void CBonusSelection::selectMap( int whichOne, bool initialSelect ) void CBonusSelection::selectMap(int mapNr, bool initialSelect)
{ {
if(initialSelect || ourCampaign->currentMap != whichOne) if(initialSelect || selectedMap != mapNr)
{ {
sInfo.difficulty = ourCampaign->camp->scenarios[whichOne].difficulty; // initialize restart / start button
sInfo.mapname = ourCampaign->camp->header.filename; if(!ourCampaign->currentMap || *ourCampaign->currentMap != mapNr)
sInfo.mode = StartInfo::CAMPAIGN; {
sInfo.campState = ourCampaign; // draw start button
ourCampaign->currentMap = whichOne; restartB->disable();
startB->enable();
}
else
{
// draw restart button
startB->disable();
restartB->enable();
}
startInfo.difficulty = ourCampaign->camp->scenarios[mapNr].difficulty;
selectedMap = mapNr;
selectedBonus = boost::none;
//get header //get header
delete ourHeader; delete ourHeader;
std::string & headerStr = ourCampaign->camp->mapPieces.find(whichOne)->second; std::string & headerStr = ourCampaign->camp->mapPieces.find(mapNr)->second;
auto buffer = reinterpret_cast<const ui8 *>(headerStr.data()); auto buffer = reinterpret_cast<const ui8 *>(headerStr.data());
ourHeader = CMapService::loadMapHeader(buffer, headerStr.size()).release(); ourHeader = CMapService::loadMapHeader(buffer, headerStr.size()).release();
std::map<ui8, std::string> names; std::map<ui8, std::string> names;
names[1] = settings["general"]["playerName"].String(); names[1] = settings["general"]["playerName"].String();
updateStartInfo(ourCampaign->camp->header.filename, sInfo, ourHeader, names); updateStartInfo(ourCampaign->camp->header.filename, startInfo, ourHeader, names);
sInfo.turnTime = 0;
sInfo.difficulty = ourCampaign->camp->scenarios[whichOne].difficulty;
mapDesc->setText(ourHeader->description); mapDescription->setText(ourHeader->description);
updateBonusSelection(); updateBonusSelection();
GH.totalRedraw();
} }
} }
@ -3338,7 +3345,7 @@ void CBonusSelection::show(SDL_Surface * to)
//map description //map description
printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, Colors::YELLOW, to); printAtLoc(CGI->generaltexth->allTexts[496], 481, 253, FONT_SMALL, Colors::YELLOW, to);
mapDesc->showAll(to); //showAll because CTextBox has no show() mapDescription->showAll(to); //showAll because CTextBox has no show()
//map size icon //map size icon
int temp; int temp;
@ -3367,7 +3374,7 @@ void CBonusSelection::show(SDL_Surface * to)
int ex = 629 + graphics->fonts[FONT_SMALL]->getStringWidth(CGI->generaltexth->allTexts[391]); int ex = 629 + graphics->fonts[FONT_SMALL]->getStringWidth(CGI->generaltexth->allTexts[391]);
TeamID myT; TeamID myT;
myT = ourHeader->players[playerColor.getNum()].team; myT = ourHeader->players[playerColor.getNum()].team;
for (auto i = sInfo.playerInfos.cbegin(); i != sInfo.playerInfos.cend(); i++) for (auto i = startInfo.playerInfos.cbegin(); i != startInfo.playerInfos.cend(); i++)
{ {
int *myx = ((i->first == playerColor || ourHeader->players[i->first.getNum()].team == myT) ? &fx : &ex); int *myx = ((i->first == playerColor || ourHeader->players[i->first.getNum()].team == myT) ? &fx : &ex);
blitAtLoc(sFlags->ourImages[i->first.getNum()].bitmap, *myx, 405, to); blitAtLoc(sFlags->ourImages[i->first.getNum()].bitmap, *myx, 405, to);
@ -3375,7 +3382,7 @@ void CBonusSelection::show(SDL_Surface * to)
} }
//difficulty //difficulty
blitAtLoc(diffPics[sInfo.difficulty], 709, 455, to); blitAtLoc(diffPics[startInfo.difficulty], 709, 455, to);
CIntObject::show(to); CIntObject::show(to);
} }
@ -3394,7 +3401,7 @@ void CBonusSelection::updateBonusSelection()
//resource - BORES.DEF //resource - BORES.DEF
//player - CREST58.DEF //player - CREST58.DEF
//hero - PORTRAITSLARGE (HPL###.BMPs) //hero - PORTRAITSLARGE (HPL###.BMPs)
const CCampaignScenario &scenario = ourCampaign->camp->scenarios[sInfo.campState->currentMap]; const CCampaignScenario &scenario = ourCampaign->camp->scenarios[selectedMap];
const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose; const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
updateStartButtonState(-1); updateStartButtonState(-1);
@ -3431,7 +3438,7 @@ void CBonusSelection::updateBonusSelection()
case CScenarioTravel::STravelBonus::BUILDING: case CScenarioTravel::STravelBonus::BUILDING:
{ {
int faction = -1; int faction = -1;
for(auto & elem : sInfo.playerInfos) for(auto & elem : startInfo.playerInfos)
{ {
if (elem.second.playerID) if (elem.second.playerID)
{ {
@ -3571,16 +3578,28 @@ void CBonusSelection::updateBonusSelection()
bonusButton->borderColor = brightYellow; bonusButton->borderColor = brightYellow;
bonuses->addButton(bonusButton); bonuses->addButton(bonusButton);
} }
// set bonus if already chosen
if(vstd::contains(ourCampaign->chosenCampaignBonuses, selectedMap))
{
bonuses->select(ourCampaign->chosenCampaignBonuses[selectedMap], false);
}
}
void CBonusSelection::updateCampaignState()
{
ourCampaign->currentMap = selectedMap;
ourCampaign->chosenCampaignBonuses[selectedMap] = *selectedBonus;
} }
void CBonusSelection::startMap() void CBonusSelection::startMap()
{ {
auto si = new StartInfo(sInfo); updateCampaignState();
const CCampaignScenario & scenario = ourCampaign->camp->scenarios[ourCampaign->currentMap]; logGlobal->infoStream() << "Starting scenario " << selectedMap;
logGlobal->infoStream() << "Starting scenario " << int(ourCampaign->currentMap);
const CCampaignScenario & scenario = ourCampaign->camp->scenarios[selectedMap];
auto si = new StartInfo(startInfo);
auto exitCb = [si]() auto exitCb = [si]()
{ {
CGP->showLoadingScreen(boost::bind(&startGame, si, (CConnection *)nullptr)); CGP->showLoadingScreen(boost::bind(&startGame, si, (CConnection *)nullptr));
@ -3596,26 +3615,41 @@ void CBonusSelection::startMap()
} }
} }
void CBonusSelection::restartMap()
{
updateCampaignState();
auto si = new StartInfo(startInfo); // copy before this object will be destroyed
GH.popIntTotally(this);
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [si]
{
SDL_Event event;
event.type = SDL_USEREVENT;
event.user.code = PREPARE_RESTART_CAMPAIGN;
event.user.data1 = si;
SDL_PushEvent(&event);
}, 0);
}
void CBonusSelection::selectBonus(int id) void CBonusSelection::selectBonus(int id)
{ {
// Total redraw is needed because the border around the bonus images // Total redraw is needed because the border around the bonus images
// have to be undrawn/drawn. // have to be undrawn/drawn.
if (!vstd::contains(sInfo.campState->chosenCampaignBonuses, sInfo.campState->currentMap) if (!selectedBonus || *selectedBonus != id)
|| id != sInfo.campState->currentBonusID())
{ {
sInfo.campState->chosenCampaignBonuses[sInfo.campState->currentMap] = id; selectedBonus = id;
GH.totalRedraw(); GH.totalRedraw();
updateStartButtonState(id); updateStartButtonState(id);
} }
const CCampaignScenario &scenario = ourCampaign->camp->scenarios[sInfo.campState->currentMap]; const CCampaignScenario &scenario = ourCampaign->camp->scenarios[selectedMap];
const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose; const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
if (bonDescs[id].type == CScenarioTravel::STravelBonus::HERO) if (bonDescs[id].type == CScenarioTravel::STravelBonus::HERO)
{ {
std::map<ui8, std::string> names; std::map<ui8, std::string> names;
names[1] = settings["general"]["playerName"].String(); names[1] = settings["general"]["playerName"].String();
for(auto & elem : sInfo.playerInfos) for(auto & elem : startInfo.playerInfos)
{ {
if(elem.first == PlayerColor(bonDescs[id].info1)) if(elem.first == PlayerColor(bonDescs[id].info1))
::setPlayer(elem.second, 1, names); ::setPlayer(elem.second, 1, names);
@ -3625,25 +3659,27 @@ void CBonusSelection::selectBonus( int id )
} }
} }
void CBonusSelection::changeDiff( bool increase ) void CBonusSelection::increaseDifficulty()
{ {
if (increase) startInfo.difficulty = std::min(startInfo.difficulty + 1, 4);
{
sInfo.difficulty = std::min(sInfo.difficulty + 1, 4);
} }
else
void CBonusSelection::decreaseDifficulty()
{ {
sInfo.difficulty = std::max(sInfo.difficulty - 1, 0); startInfo.difficulty = std::max(startInfo.difficulty - 1, 0);
}
} }
void CBonusSelection::updateStartButtonState(int selected /*= -1*/) void CBonusSelection::updateStartButtonState(int selected /*= -1*/)
{ {
if(selected == -1) if(selected == -1)
startB->setState( ourCampaign->getCurrentScenario().travelOptions.bonusesToChoose.size() ? CButtonBase::BLOCKED : CButtonBase::NORMAL); {
startB->setState(ourCampaign->camp->scenarios[selectedMap].travelOptions.bonusesToChoose.size() ? CButtonBase::BLOCKED : CButtonBase::NORMAL);
}
else if(startB->getState() == CButtonBase::BLOCKED) else if(startB->getState() == CButtonBase::BLOCKED)
{
startB->setState(CButtonBase::NORMAL); startB->setState(CButtonBase::NORMAL);
} }
}
CBonusSelection::CRegion::CRegion( CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber ) CBonusSelection::CRegion::CRegion( CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber )
: owner(_owner), accessible(_accessible), selectable(_selectable), myNumber(_myNumber) : owner(_owner), accessible(_accessible), selectable(_selectable), myNumber(_myNumber)

@ -452,12 +452,15 @@ public:
/// Campaign screen where you can choose one out of three starting bonuses /// Campaign screen where you can choose one out of three starting bonuses
class CBonusSelection : public CIntObject class CBonusSelection : public CIntObject
{ {
SDL_Surface * background; public:
CAdventureMapButton * startB, * backB; CBonusSelection(const std::string & campaignFName);
CBonusSelection(shared_ptr<CCampaignState> _ourCampaign);
~CBonusSelection();
//campaign & map descriptions: void showAll(SDL_Surface * to) override;
CTextBox * cmpgDesc, * mapDesc; void show(SDL_Surface * to) override;
private:
struct SCampPositions struct SCampPositions
{ {
std::string campPrefix; std::string campPrefix;
@ -473,8 +476,6 @@ class CBonusSelection : public CIntObject
}; };
std::vector<SCampPositions> campDescriptions;
class CRegion : public CIntObject class CRegion : public CIntObject
{ {
CBonusSelection * owner; CBonusSelection * owner;
@ -482,6 +483,7 @@ class CBonusSelection : public CIntObject
bool accessible; //false if region should be striped bool accessible; //false if region should be striped
bool selectable; //true if region should be selectable bool selectable; //true if region should be selectable
int myNumber; //number of region int myNumber; //number of region
public: public:
std::string rclickText; std::string rclickText;
CRegion(CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber); CRegion(CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber);
@ -492,40 +494,40 @@ class CBonusSelection : public CIntObject
void show(SDL_Surface * to); void show(SDL_Surface * to);
}; };
std::vector<CRegion *> regions;
CRegion * highlightedRegion;
void loadPositionsOfGraphics();
shared_ptr<CCampaignState> ourCampaign;
CMapHeader *ourHeader;
CDefHandler *sizes; //icons of map sizes
SDL_Surface* diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this)
CAdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty
void changeDiff(bool increase); //if false, then decrease
void updateStartButtonState(int selected = -1); //-1 -- no bonus is selected
//bonus selection
void updateBonusSelection();
CHighlightableButtonsGroup * bonuses;
public:
StartInfo sInfo;
CDefHandler *sFlags;
void selectMap(int whichOne, bool initialSelect);
void selectBonus(int id);
void init(); void init();
void loadPositionsOfGraphics();
void updateStartButtonState(int selected = -1); //-1 -- no bonus is selected
void updateBonusSelection();
void updateCampaignState();
CBonusSelection(std::string campaignFName); // Event handlers
CBonusSelection(shared_ptr<CCampaignState> _ourCampaign);
~CBonusSelection();
void showAll(SDL_Surface * to);
void show(SDL_Surface * to);
void goBack(); void goBack();
void startMap(); void startMap();
void restartMap();
void selectMap(int mapNr, bool initialSelect);
void selectBonus(int id);
void increaseDifficulty();
void decreaseDifficulty();
// GUI components
SDL_Surface * background;
CAdventureMapButton * startB, * restartB, * backB;
CTextBox * campaignDescription, * mapDescription;
std::vector<SCampPositions> campDescriptions;
std::vector<CRegion *> regions;
CRegion * highlightedRegion;
CHighlightableButtonsGroup * bonuses;
SDL_Surface * diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this)
CAdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty
CDefHandler * sizes; //icons of map sizes
CDefHandler * sFlags;
// Data
shared_ptr<CCampaignState> ourCampaign;
int selectedMap;
boost::optional<int> selectedBonus;
StartInfo startInfo;
CMapHeader * ourHeader;
}; };
/// Campaign selection screen /// Campaign selection screen

@ -807,7 +807,7 @@ void CGameState::init(StartInfo * si)
{ {
continue; continue;
} }
auto bb = new Bonus(Bonus::PERMANENT, Bonus::PRIMARY_SKILL, Bonus::CAMPAIGN_BONUS, val, scenarioOps->campState->currentMap, g); auto bb = new Bonus(Bonus::PERMANENT, Bonus::PRIMARY_SKILL, Bonus::CAMPAIGN_BONUS, val, *scenarioOps->campState->currentMap, g);
hero->addNewBonus(bb); hero->addNewBonus(bb);
} }
} }
@ -886,9 +886,9 @@ void CGameState::init(StartInfo * si)
{ {
logGlobal->infoStream() << "Open campaign map file: " << scenarioOps->campState->currentMap; logGlobal->infoStream() << "Open campaign map file: " << scenarioOps->campState->currentMap;
auto campaign = scenarioOps->campState; auto campaign = scenarioOps->campState;
assert(vstd::contains(campaign->camp->mapPieces, scenarioOps->campState->currentMap)); assert(vstd::contains(campaign->camp->mapPieces, *scenarioOps->campState->currentMap));
std::string & mapContent = campaign->camp->mapPieces[scenarioOps->campState->currentMap]; std::string & mapContent = campaign->camp->mapPieces[*scenarioOps->campState->currentMap];
auto buffer = reinterpret_cast<const ui8 *>(mapContent.data()); auto buffer = reinterpret_cast<const ui8 *>(mapContent.data());
map = CMapService::loadMap(buffer, mapContent.size()).release(); map = CMapService::loadMap(buffer, mapContent.size()).release();
} }

@ -433,16 +433,16 @@ bool CScenarioTravel::STravelBonus::isBonusForHero() const
void CCampaignState::mapConquered( const std::vector<CGHeroInstance*> & heroes ) void CCampaignState::mapConquered( const std::vector<CGHeroInstance*> & heroes )
{ {
camp->scenarios[currentMap].prepareCrossoverHeroes(heroes); camp->scenarios[*currentMap].prepareCrossoverHeroes(heroes);
mapsConquered.push_back(currentMap); mapsConquered.push_back(*currentMap);
mapsRemaining -= currentMap; mapsRemaining -= *currentMap;
camp->scenarios[currentMap].conquered = true; camp->scenarios[*currentMap].conquered = true;
} }
boost::optional<CScenarioTravel::STravelBonus> CCampaignState::getBonusForCurrentMap() const boost::optional<CScenarioTravel::STravelBonus> CCampaignState::getBonusForCurrentMap() const
{ {
auto bonuses = getCurrentScenario().travelOptions.bonusesToChoose; auto bonuses = getCurrentScenario().travelOptions.bonusesToChoose;
assert(chosenCampaignBonuses.count(currentMap) || bonuses.size() == 0); assert(chosenCampaignBonuses.count(*currentMap) || bonuses.size() == 0);
if(bonuses.size()) if(bonuses.size())
return bonuses[currentBonusID()]; return bonuses[currentBonusID()];
else else
@ -451,16 +451,18 @@ boost::optional<CScenarioTravel::STravelBonus> CCampaignState::getBonusForCurren
const CCampaignScenario & CCampaignState::getCurrentScenario() const const CCampaignScenario & CCampaignState::getCurrentScenario() const
{ {
return camp->scenarios[currentMap]; return camp->scenarios[*currentMap];
} }
ui8 CCampaignState::currentBonusID() const ui8 CCampaignState::currentBonusID() const
{ {
return chosenCampaignBonuses.at(currentMap); return chosenCampaignBonuses.at(*currentMap);
} }
CCampaignState::CCampaignState() CCampaignState::CCampaignState()
{} {
}
CCampaignState::CCampaignState( unique_ptr<CCampaign> _camp ) : camp(std::move(_camp)) CCampaignState::CCampaignState( unique_ptr<CCampaign> _camp ) : camp(std::move(_camp))
{ {

@ -149,9 +149,9 @@ public:
unique_ptr<CCampaign> camp; unique_ptr<CCampaign> camp;
std::string campaignName; std::string campaignName;
std::vector<ui8> mapsConquered, mapsRemaining; std::vector<ui8> mapsConquered, mapsRemaining;
ui8 currentMap; boost::optional<si32> currentMap;
std::map<ui8, ui8> chosenCampaignBonuses; //used only for mode CAMPAIGN std::map<ui8, ui8> chosenCampaignBonuses;
//void initNewCampaign(const StartInfo &si); //void initNewCampaign(const StartInfo &si);
void mapConquered(const std::vector<CGHeroInstance*> & heroes); void mapConquered(const std::vector<CGHeroInstance*> & heroes);