Przeglądaj źródła

* changes in campaign handling

mateuszb 12 lat temu
rodzic
commit
169cf3558d

+ 9 - 8
lib/CGameState.cpp

@@ -1092,12 +1092,12 @@ void CGameState::init(StartInfo * si)
 
 	/*************************replace hero placeholders*****************************/
 	tlog4 << "\tReplacing hero placeholders";
-	std::vector<std::tuple<CGHeroInstance*, int> > campHeroReplacements; //instance, id in vector
+	std::vector<std::pair<CGHeroInstance*, int> > 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<CGHeroInstance *> Xheroes;
+			std::vector<CGHeroInstance*> 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; g<map->objects.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)

+ 29 - 0
lib/Connection.h

@@ -738,6 +738,19 @@ public:
 		VariantVisitorSaver<Serializer> visitor(*this->This());
 		boost::apply_visitor(visitor, data);
 	}
+	template <typename T>
+	void saveSerializable(const boost::optional<T> &data)
+	{
+		if(data)
+		{
+			*this << (ui8)1;
+			*this << *data;
+		}
+		else
+		{
+			*this << (ui8)0;
+		}
+	}
 	template <typename E>
 	void saveEnum(const E &data)
 	{
@@ -1102,6 +1115,22 @@ public:
 			assert(0);
 		//TODO write more if needed, general solution would be much longer
 	}
+	template <typename T>
+	void loadSerializable(boost::optional<T> & data)
+	{
+		ui8 present;
+		*this >> present;
+		if(present)
+		{
+			T t;
+			*this >> t;
+			data = t;
+		}
+		else
+		{
+			data = boost::optional<T>();
+		}
+	}
 	void loadSerializable(CStackInstance *&s)
 	{
 		if(sendStackInstanceByIds)

+ 3 - 3
lib/Mapping/CCampaignHandler.cpp

@@ -323,7 +323,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> he
 {
 	crossoverHeroes = heroes;
 
-	
+
 	if (!(travelOptions.whatHeroKeeps & 1))
 	{
 		//trimming experience
@@ -341,7 +341,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> 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<CGHeroInstance *> he
 				const ArtSlotInfo *info = hero->getSlot(i);
 				if (!info)
 					continue;
-				
+
 				const CArtifactInstance *art = info->artifact;
 				if (!art)//FIXME: check spellbook and catapult behaviour
 					continue;

+ 4 - 1
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<CGHeroInstance*> crossoverHeroes;
+	std::vector<CGHeroInstance *> crossoverHeroes;
 
 	void loadPreconditionRegions(ui32 regions);
 	void prepareCrossoverHeroes(std::vector<CGHeroInstance *> heroes);