diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 30ecffa32..6a1249b0a 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1092,12 +1092,12 @@ void CGameState::init(StartInfo * si) /*************************replace hero placeholders*****************************/ tlog4 << "\tReplacing hero placeholders"; - std::vector > campHeroReplacements; //instance, id in vector + std::vector > campHeroReplacements; //instance, id in vector if (scenarioOps->campState) { auto replaceHero = [&](int objId, CGHeroInstance * ghi) { - campHeroReplacements.push_back(std::make_tuple(ghi, objId)); + campHeroReplacements.push_back(std::make_pair(ghi, objId)); // ghi->tempOwner = getHumanPlayerInfo()[0]->color; // ghi->id = objId; // gs->map->objects[objId] = ghi; @@ -1109,7 +1109,7 @@ void CGameState::init(StartInfo * si) if(bonus.is_initialized()) { - std::vector Xheroes; + std::vector Xheroes; if (bonus->type == CScenarioTravel::STravelBonus::PLAYER_PREV_SCENARIO) { Xheroes = campaign->camp->scenarios[bonus->info2].crossoverHeroes; @@ -1128,7 +1128,7 @@ void CGameState::init(StartInfo * si) if(hp->subID != 0xFF) //select by type { bool found = false; - BOOST_FOREACH(CGHeroInstance * ghi, Xheroes) + BOOST_FOREACH(auto ghi, Xheroes) { if (ghi->subID == hp->subID) { @@ -1153,6 +1153,7 @@ void CGameState::init(StartInfo * si) { return a->getHeroStrength() > b->getHeroStrength(); }); //sort, descending strength + for(int g=0; gobjects.size(); ++g) { CGObjectInstance * obj = map->objects[g]; @@ -1257,10 +1258,10 @@ void CGameState::init(StartInfo * si) BOOST_FOREACH(auto obj, campHeroReplacements) { - CGHeroInstance * hero = new CGHeroInstance(), - * oldHero = std::get<0>(obj); + CGHeroInstance * hero = new CGHeroInstance(); + CGHeroInstance * oldHero = obj.first; hero->initHero(oldHero->subID); - hero->id = std::get<1>(obj); + hero->id = obj.second; map->objects[hero->id] = hero; map->heroes.push_back(hero); const auto & travelOptions = scenarioOps->campState->getCurrentScenario().travelOptions; @@ -1278,7 +1279,7 @@ void CGameState::init(StartInfo * si) hero->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) && Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val = oldHero->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) && - Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val; + Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val; } } if (travelOptions.whatHeroKeeps & 4) diff --git a/lib/Connection.h b/lib/Connection.h index cd0bdb747..ab6d714e0 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -738,6 +738,19 @@ public: VariantVisitorSaver visitor(*this->This()); boost::apply_visitor(visitor, data); } + template + void saveSerializable(const boost::optional &data) + { + if(data) + { + *this << (ui8)1; + *this << *data; + } + else + { + *this << (ui8)0; + } + } template void saveEnum(const E &data) { @@ -1102,6 +1115,22 @@ public: assert(0); //TODO write more if needed, general solution would be much longer } + template + void loadSerializable(boost::optional & data) + { + ui8 present; + *this >> present; + if(present) + { + T t; + *this >> t; + data = t; + } + else + { + data = boost::optional(); + } + } void loadSerializable(CStackInstance *&s) { if(sendStackInstanceByIds) diff --git a/lib/Mapping/CCampaignHandler.cpp b/lib/Mapping/CCampaignHandler.cpp index c678c743f..0a1530117 100644 --- a/lib/Mapping/CCampaignHandler.cpp +++ b/lib/Mapping/CCampaignHandler.cpp @@ -323,7 +323,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector he { crossoverHeroes = heroes; - + if (!(travelOptions.whatHeroKeeps & 1)) { //trimming experience @@ -341,7 +341,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector he { cgh->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) && Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val - = cgh->type->heroClass->primarySkillInitial[g]; + = cgh->type->heroClass->primarySkillInitial[g]; } } } @@ -372,7 +372,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector he const ArtSlotInfo *info = hero->getSlot(i); if (!info) continue; - + const CArtifactInstance *art = info->artifact; if (!art)//FIXME: check spellbook and catapult behaviour continue; diff --git a/lib/Mapping/CCampaignHandler.h b/lib/Mapping/CCampaignHandler.h index 0664c06b7..2145096c2 100644 --- a/lib/Mapping/CCampaignHandler.h +++ b/lib/Mapping/CCampaignHandler.h @@ -1,5 +1,8 @@ #pragma once +#include "../../Global.h" +#include "../../lib/GameConstants.h" + /* * CCampaignHandler.h, part of VCMI engine * @@ -106,7 +109,7 @@ public: CScenarioTravel travelOptions; - std::vector crossoverHeroes; + std::vector crossoverHeroes; void loadPreconditionRegions(ui32 regions); void prepareCrossoverHeroes(std::vector heroes);