Przeglądaj źródła

* minor improvements for campaigns

mateuszb 15 lat temu
rodzic
commit
9356ba15ef

+ 7 - 0
client/CPreGame.cpp

@@ -2804,6 +2804,13 @@ void CBonusSelection::startMap()
 void CBonusSelection::selectBonus( int id )
 void CBonusSelection::selectBonus( int id )
 {
 {
 	sInfo.choosenCampaignBonus = id;
 	sInfo.choosenCampaignBonus = id;
+
+	const CCampaignScenario &scenario = ourCampaign->camp->scenarios[sInfo.whichMapInCampaign];
+	const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
+	if (bonDescs[id].type == 8) //hero crossover
+	{
+		setPlayer(sInfo.playerInfos[0], bonDescs[id].info1); //TODO: substitute with appropriate color
+	}
 }
 }
 
 
 void CBonusSelection::changeDiff( bool increase )
 void CBonusSelection::changeDiff( bool increase )

+ 2 - 0
client/CPreGame.h

@@ -355,6 +355,8 @@ class CBonusSelection : public CIntObject
 	CHighlightableButtonsGroup * bonuses;
 	CHighlightableButtonsGroup * bonuses;
 
 
 public:
 public:
+	void bonusSelectionChanges(int choosenBonus);
+
 	StartInfo sInfo;
 	StartInfo sInfo;
 	CDefHandler *sFlags;
 	CDefHandler *sFlags;
 
 

+ 1 - 0
hch/CCampaignHandler.cpp

@@ -470,6 +470,7 @@ bool CCampaignScenario::isNotVoid() const
 void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> heroes )
 void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> heroes )
 {
 {
 	crossoverHeroes = heroes;
 	crossoverHeroes = heroes;
+
 	
 	
 	if (!(travelOptions.whatHeroKeeps & 1))
 	if (!(travelOptions.whatHeroKeeps & 1))
 	{
 	{

+ 36 - 32
lib/CGameState.cpp

@@ -1376,22 +1376,6 @@ CGameState::~CGameState()
 	capitols.clear();
 	capitols.clear();
 }
 }
 
 
-namespace HHLP
-{
-	class HeroRemoverHelper
-	{
-	public:
-		si32 allowedplayer;
-		HeroRemoverHelper(si32 player) : allowedplayer(player)
-		{
-		}
-		bool operator()(const CGHeroInstance * cgh)
-		{
-			return cgh->tempOwner != allowedplayer;
-		}
-	};
-}
-
 void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 {
 {
 	VLC->creh->globalEffects = &globalEffects;
 	VLC->creh->globalEffects = &globalEffects;
@@ -1658,6 +1642,14 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 		CScenarioTravel::STravelBonus bonus =
 		CScenarioTravel::STravelBonus bonus =
 			campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus];
 			campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus];
 
 
+
+		std::vector<CGHeroInstance *> Xheroes;
+		if (bonus.type == 8) //hero crossover
+		{
+			Xheroes = campaign->camp->scenarios[bonus.info2].crossoverHeroes;
+		}
+
+		//selecting heroes by type
 		for(int g=0; g<map->objects.size(); ++g)
 		for(int g=0; g<map->objects.size(); ++g)
 		{
 		{
 			CGObjectInstance * obj = map->objects[g];
 			CGObjectInstance * obj = map->objects[g];
@@ -1668,31 +1660,43 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 			CGHeroPlaceholder * hp = static_cast<CGHeroPlaceholder*>(obj);
 			CGHeroPlaceholder * hp = static_cast<CGHeroPlaceholder*>(obj);
 			CGHeroInstance * substitution = NULL;
 			CGHeroInstance * substitution = NULL;
 
 
-			std::vector<CGHeroInstance *> Xheroes;
-			if (bonus.type == 8) //hero crossover
-			{
-				Xheroes = campaign->camp->scenarios[bonus.info2].crossoverHeroes;
-				std::remove_if(Xheroes.begin(), Xheroes.end(), HHLP::HeroRemoverHelper(bonus.info1));
-			}
-			else if (bonus.type == 9) //starting hero
-			{
-			}
-
-			if (hp->subID == 0xFF) //select by power
-			{
-				std::sort(Xheroes.begin(), Xheroes.end(), HLP::heroPowerSorter);
-				HLP::replaceHero(this, g, Xheroes[hp->power - 1]);
-			}
-			else //select by type
+			if(hp->subID != 0xFF) //select by type
 			{
 			{
+				bool found = false;
 				BOOST_FOREACH(CGHeroInstance * ghi, Xheroes)
 				BOOST_FOREACH(CGHeroInstance * ghi, Xheroes)
 				{
 				{
 					if (ghi->subID == hp->subID)
 					if (ghi->subID == hp->subID)
 					{
 					{
+						found = true;
 						HLP::replaceHero(this, g, ghi);
 						HLP::replaceHero(this, g, ghi);
+						Xheroes -= ghi;
 						break;
 						break;
 					}
 					}
 				}
 				}
+				if (!found)
+				{
+					//TODO: create new hero of this type
+				}
+			}
+		}
+
+		//selecting heroes by power
+
+		std::sort(Xheroes.begin(), Xheroes.end(), HLP::heroPowerSorter);
+		for(int g=0; g<map->objects.size(); ++g)
+		{
+			CGObjectInstance * obj = map->objects[g];
+			if (obj->ID != 214) //not a placeholder
+			{
+				continue;
+			}
+			CGHeroPlaceholder * hp = static_cast<CGHeroPlaceholder*>(obj);
+			CGHeroInstance * substitution = NULL;
+
+			if (hp->subID == 0xFF) //select by power
+			{
+				HLP::replaceHero(this, g, Xheroes[hp->power - 1]);
+				//we don't have to remove hero from Xheroes because it would destroy the order and duplicates shouldn't happen
 			}
 			}
 		}
 		}
 	}
 	}

+ 9 - 1
server/CGameHandler.cpp

@@ -4757,7 +4757,15 @@ void CGameHandler::checkLossVictory( ui8 player )
 
 
 		if(gs->campaign)
 		if(gs->campaign)
 		{
 		{
-			gs->campaign->mapConquered(gs->map->heroes);
+			std::vector<CGHeroInstance *> hes;
+			BOOST_FOREACH(CGHeroInstance * ghi, gs->map->heroes)
+			{
+				if (ghi->tempOwner == 0 /*TODO: insert human player's color*/)
+				{
+					hes.push_back(ghi);
+				}
+			}
+			gs->campaign->mapConquered(hes);
 
 
 			UpdateCampaignState ucs;
 			UpdateCampaignState ucs;
 			ucs.camp = gs->campaign;
 			ucs.camp = gs->campaign;