2
0
Эх сурвалжийг харах

* CBonusSelection will now work on CCampaignState instead of CCampaign; unfortunately there seems to be no elegant way to move that state between bonus selection screen and CGameState::init, so it's not yet moved.

mateuszb 15 жил өмнө
parent
commit
52319f5713

+ 4 - 4
client/CAdvmapInterface.cpp

@@ -1210,10 +1210,10 @@ townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlis
 
 	heroWindow = new CHeroWindow(LOCPLINT->playerID);
 
-	gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[0]));
-	gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[1]));
-	gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[2]));
-	gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[3]));
+	for (int g=0; g<ADVOPT.gemG.size(); ++g)
+	{
+		gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[g]));
+	}
 
 
 	setPlayer(LOCPLINT->playerID);

+ 4 - 4
client/CBattleInterface.cpp

@@ -1109,7 +1109,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
 	//create stack queue
 	bool embedQueue = screen->h < 700;
 	queue = new CStackQueue(embedQueue, this);
- 	if(!embedQueue && curInt->sysOpts.showQueue)
+	if(!embedQueue && curInt->sysOpts.showQueue)
 	{
 		pos.y += queue->pos.h / 2; //center whole window
 		queue->moveTo(Point(pos.x, pos.y - queue->pos.h));
@@ -1117,7 +1117,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
 // 		queue->pos.y = pos.y - queue->pos.h;
 //  		pos.h += queue->pos.h;
 //  		center();
- 	}
+	}
 	queue->update();
 
 	//preparing siege info
@@ -2188,7 +2188,7 @@ void CBattleInterface::bDefencef()
 		return;
 
 	if(activeStack != -1)
- 		giveCommand(3,0,activeStack);
+		giveCommand(3,0,activeStack);
 }
 
 void CBattleInterface::bConsoleUpf()
@@ -3028,7 +3028,7 @@ void CBattleInterface::showAliveStack(int ID, const std::map<int, CStack> & stac
 			FONT_TINY,
 			zwykly,
 			to
-        );
+		);
 	}
 }
 

+ 73 - 64
client/CPreGame.cpp

@@ -522,7 +522,8 @@ void CSelectionScreen::updateStartInfo( const CMapInfo * to, StartInfo & sInfo,
 void CSelectionScreen::startCampaign()
 {
 	CCampaign * ourCampaign = CCampaignHandler::getCampaign(curMap->filename, curMap->lodCmpgn);
-	GH.pushInt( new CBonusSelection(ourCampaign, 0) );
+	CCampaignState * campState = new CCampaignState();
+	GH.pushInt( new CBonusSelection(campState) );
 }
 
 void CSelectionScreen::startGame()
@@ -731,7 +732,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const boost::function<void(
 	txt = NULL;
 	tabType = Type;
 
- 	if (Type != CMenuScreen::campaignList)
+	if (Type != CMenuScreen::campaignList)
 	{
 		bg = new CPicture(BitmapHandler::loadBitmap("SCSELBCK.bmp"), 0, 0, true);
 		pos.w = bg->pos.w;
@@ -1446,46 +1447,46 @@ void OptionsTab::nextCastle( int player, int dir )
 	si32 &cur = s.castle;
 	ui32 allowed = curMap->mapHeader->players[s.color].allowedFactions;
 
- 	if (cur == -2) //no castle - no change
- 		return;
-
- 	if (cur == -1) //random => first/last available
- 	{
- 		int pom = (dir>0) ? (0) : (F_NUMBER-1); // last or first
- 		for (;pom >= 0  &&  pom < F_NUMBER;  pom+=dir)
- 		{
- 			if((1 << pom) & allowed)
- 			{
- 				cur=pom;
- 				break;
- 			}
- 		}
- 	}
- 	else // next/previous available
- 	{
- 		for (;;)
- 		{
+	if (cur == -2) //no castle - no change
+		return;
+
+	if (cur == -1) //random => first/last available
+	{
+		int pom = (dir>0) ? (0) : (F_NUMBER-1); // last or first
+		for (;pom >= 0  &&  pom < F_NUMBER;  pom+=dir)
+		{
+			if((1 << pom) & allowed)
+			{
+				cur=pom;
+				break;
+			}
+		}
+	}
+	else // next/previous available
+	{
+		for (;;)
+		{
 			cur+=dir;
 			if ((1 << cur) & allowed)
- 				break;
-
- 			if (cur >= F_NUMBER  ||  cur<0)
- 			{
- 				double p1 = log((double)allowed) / log(2.0f)+0.000001f;
- 				double check = p1 - ((int)p1);
- 				if (check < 0.001)
- 					cur = (int)p1;
- 				else
- 					cur = -1;
- 				break;
- 			}
- 		}
- 	}
+				break;
+
+			if (cur >= F_NUMBER  ||  cur<0)
+			{
+				double p1 = log((double)allowed) / log(2.0f)+0.000001f;
+				double check = p1 - ((int)p1);
+				if (check < 0.001)
+					cur = (int)p1;
+				else
+					cur = -1;
+				break;
+			}
+		}
+	}
 
 	if(s.hero >= 0)
 		s.hero = -1;
- 	if(cur < 0  &&  s.bonus == PlayerSettings::bresource)
- 		s.bonus = PlayerSettings::brandom;
+	if(cur < 0  &&  s.bonus == PlayerSettings::bresource)
+		s.bonus = PlayerSettings::brandom;
 
 	entries[player]->selectButtons();
 	redraw();
@@ -1628,15 +1629,15 @@ void OptionsTab::flagPressed( int player )
 						? vstd::findPos(playerNames, clicked.name) 
 						: -1;
 
- 		if(curNameID >= 0  &&  playerToRestore.second == curNameID) //player to restore is about to being replaced -> put him back to the old place
+		if(curNameID >= 0  &&  playerToRestore.second == curNameID) //player to restore is about to being replaced -> put him back to the old place
 		{
 			PlayerSettings &restPos = curOpts->playerInfos[playerToRestore.first];
- 			setPlayer(restPos, playerToRestore.second);
+			setPlayer(restPos, playerToRestore.second);
 			playerToRestore.first = playerToRestore.second = 0;
 		}
 
- 		//who will be put here?
- 		if(curNameID < 0) //if possible replace computer with unallocated player
+		//who will be put here?
+		if(curNameID < 0) //if possible replace computer with unallocated player
 		{
 			for(int i = 0; i < playerNames.size(); i++)
 			{
@@ -1648,7 +1649,7 @@ void OptionsTab::flagPressed( int player )
 			}
 		}
 
- 		setPlayer(clicked, ++curNameID); //simply next player
+		setPlayer(clicked, ++curNameID); //simply next player
 
 		//if that player was somewhere else, we need to replace him with computer
 		if(curNameID < playerNames.size())
@@ -2199,18 +2200,18 @@ void CHotSeatPlayers::enterSelectionScreen()
 	GH.pushInt(new CSelectionScreen(CMenuScreen::newGame));
 }
 
-CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap )
-: ourCampaign(_ourCampaign), whichMap(_whichMap), highlightedRegion(NULL), ourHeader(NULL), bonuses(NULL),
+CBonusSelection::CBonusSelection( CCampaignState * _ourCampaign )
+: ourCampaign(_ourCampaign), highlightedRegion(NULL), ourHeader(NULL), bonuses(NULL),
 	diffLb(NULL), diffRb(NULL)
 {
 	OBJ_CONSTRUCTION;
 	static const std::string bgNames [] = {"E1_BG.BMP", "G2_BG.BMP", "E2_BG.BMP", "G1_BG.BMP", "G3_BG.BMP", "N1_BG.BMP",
 		"S1_BG.BMP", "BR_BG.BMP", "IS_BG.BMP", "KR_BG.BMP", "NI_BG.BMP", "TA_BG.BMP", "AR_BG.BMP", "HS_BG.BMP",
 		"BB_BG.BMP", "NB_BG.BMP", "EL_BG.BMP", "RN_BG.BMP", "UA_BG.BMP", "SP_BG.BMP"};
-	
+
 	loadPositionsOfGraphics();
 
-	background = BitmapHandler::loadBitmap(bgNames[ourCampaign->header.mapVersion]);
+	background = BitmapHandler::loadBitmap(bgNames[ourCampaign->camp->header.mapVersion]);
 
 	SDL_Surface * panel = BitmapHandler::loadBitmap("CAMPBRF.BMP");
 
@@ -2220,8 +2221,8 @@ CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap
 	backB = new AdventureMapButton("", "", bind(&CBonusSelection::goBack, this), 624, 536, "CBCANCB.DEF", SDLK_ESCAPE);
 
 	//campaign name
-	if (ourCampaign->header.name.length())
-		printAtLoc(ourCampaign->header.name, 481, 28, FONT_BIG, tytulowy, background);
+	if (ourCampaign->camp->header.name.length())
+		printAtLoc(ourCampaign->camp->header.name, 481, 28, FONT_BIG, tytulowy, background);
 	else 
 		printAtLoc("Unnamed", 481, 28, FONT_BIG, tytulowy, background);
 
@@ -2232,7 +2233,7 @@ CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap
 	//campaign description
 	printAtLoc(CGI->generaltexth->allTexts[38], 481, 63, FONT_SMALL, tytulowy, background);
  
-	cmpgDesc = new CTextBox(ourCampaign->header.description, Rect(480, 86, 286, 117), 1);
+	cmpgDesc = new CTextBox(ourCampaign->camp->header.description, Rect(480, 86, 286, 117), 1);
 	cmpgDesc->showAll(background);
 
 	//map description
@@ -2243,25 +2244,31 @@ CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap
 	bonuses = new CHighlightableButtonsGroup(bind(&CBonusSelection::selectBonus, this, _1));
 
 	//set left part of window
-	for (int g=0; g<ourCampaign->scenarios.size(); ++g)
+	for (int g=0; g<ourCampaign->camp->scenarios.size(); ++g)
 	{
-		if(ourCampaign->conquerable(g))
+		if(ourCampaign->camp->conquerable(g))
 		{
 			regions.push_back(new CRegion(this, true, true, g));
-			regions[regions.size()-1]->rclickText = ourCampaign->scenarios[g].regionText;
+			regions[regions.size()-1]->rclickText = ourCampaign->camp->scenarios[g].regionText;
 			if (highlightedRegion == NULL)
 			{
 				highlightedRegion = regions.back();
 				selectMap(g);
 			}
 		}
-		else if (ourCampaign->scenarios[g].conquered) //display as striped
+		else if (ourCampaign->camp->scenarios[g].conquered) //display as striped
 		{
 			regions.push_back(new CRegion(this, false, false, g));
-			regions[regions.size()-1]->rclickText = ourCampaign->scenarios[g].regionText;
+			regions[regions.size()-1]->rclickText = ourCampaign->camp->scenarios[g].regionText;
 		}
 	}
 
+	//init campaign state if necessary
+	if (ourCampaign->campaignName.size() == 0)
+	{
+		ourCampaign->initNewCampaign(sInfo);
+	}
+
 	//allies / enemies
 	printAtLoc(CGI->generaltexth->allTexts[390] + ":", 486, 407, FONT_SMALL, zwykly, background); //Allies
 	printAtLoc(CGI->generaltexth->allTexts[391] + ":", 619, 407, FONT_SMALL, zwykly, background); //Enemies
@@ -2282,7 +2289,7 @@ CBonusSelection::CBonusSelection( const CCampaign * _ourCampaign, int _whichMap
 		}
 	}
 	//difficulty selection buttons
-	if (ourCampaign->header.difficultyChoosenByPlayer)
+	if (ourCampaign->camp->header.difficultyChoosenByPlayer)
 	{
 		diffLb = new AdventureMapButton("", "", bind(&CBonusSelection::changeDiff, this, false), 694, 508, "SCNRBLF.DEF");
 		diffRb = new AdventureMapButton("", "", bind(&CBonusSelection::changeDiff, this, true), 738, 508, "SCNRBRT.DEF");
@@ -2352,15 +2359,15 @@ void CBonusSelection::loadPositionsOfGraphics()
 
 void CBonusSelection::selectMap( int whichOne )
 {
-	sInfo.difficulty = ourCampaign->scenarios[whichOne].difficulty;
-	sInfo.mapname = ourCampaign->header.filename;
+	sInfo.difficulty = ourCampaign->camp->scenarios[whichOne].difficulty;
+	sInfo.mapname = ourCampaign->camp->header.filename;
 	sInfo.mode = 2;
 
 	//get header
 	int i = 0;
 	delete ourHeader;
 	ourHeader = new CMapHeader();
-	ourHeader->initFromMemory((const unsigned char*)ourCampaign->mapPieces.find(whichOne)->second.c_str(), i);
+	ourHeader->initFromMemory((const unsigned char*)ourCampaign->camp->mapPieces.find(whichOne)->second.c_str(), i);
 	CMapInfo *mapInfo = const_cast<CMapInfo *>(curMap);
 	mapInfo->mapHeader = ourHeader;
 	mapInfo->countPlayers();
@@ -2369,7 +2376,9 @@ void CBonusSelection::selectMap( int whichOne )
 	CSelectionScreen::updateStartInfo(curMap, sInfo, ourHeader);
 	sInfo.turnTime = 0;
 	sInfo.whichMapInCampaign = whichOne;
-	sInfo.difficulty = ourCampaign->scenarios[whichOne].difficulty;
+	sInfo.difficulty = ourCampaign->camp->scenarios[whichOne].difficulty;
+
+	ourCampaign->currentMap = whichOne;
 
 	mapDesc->setTxt(ourHeader->description);
 
@@ -2444,7 +2453,7 @@ void CBonusSelection::updateBonusSelection()
 	//resource - BORES.DEF
 	//player - ?
 	//hero -?
-	const CCampaignScenario &scenario = ourCampaign->scenarios[sInfo.whichMapInCampaign];
+	const CCampaignScenario &scenario = ourCampaign->camp->scenarios[sInfo.whichMapInCampaign];
 	const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
 
 	CDefEssential * twcp = CDefHandler::giveDefEss("TWCRPORT.DEF"); //for yellow border
@@ -2624,7 +2633,7 @@ void CBonusSelection::startMap()
 {
 	StartInfo *si = new StartInfo(sInfo);
 	//don't pop - we should get back to this screen
-	GH.popInts(3);
+	//GH.popInts(3);
 	curOpts = NULL;
 	::startGame(si);
 }
@@ -2656,7 +2665,7 @@ CBonusSelection::CRegion::CRegion( CBonusSelection * _owner, bool _accessible, b
 		{"R", "B", "N", "G", "O", "V", "T", "P"},
 		{"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"}};
 
-	const SCampPositions & campDsc = owner->campDescriptions[owner->ourCampaign->header.mapVersion];
+	const SCampPositions & campDsc = owner->campDescriptions[owner->ourCampaign->camp->header.mapVersion];
 	const SCampPositions::SRegionDesc & desc = campDsc.regions[myNumber];
 	pos.x = desc.xpos;
 	pos.y = desc.ypos;
@@ -2664,7 +2673,7 @@ CBonusSelection::CRegion::CRegion( CBonusSelection * _owner, bool _accessible, b
 	//loading of graphics
 
 	std::string prefix = campDsc.campPrefix + desc.infix + "_";
-	std::string suffix = colors[campDsc.colorSuffixLength - 1][owner->ourCampaign->scenarios[myNumber].regionColor];
+	std::string suffix = colors[campDsc.colorSuffixLength - 1][owner->ourCampaign->camp->scenarios[myNumber].regionColor];
 
 	static const std::string infix [] = {"En", "Se", "Co"};
 	for (int g = 0; g < ARRAY_COUNT(infix); g++)
@@ -2710,7 +2719,7 @@ void CBonusSelection::CRegion::clickRight( tribool down, bool previousState )
 
 void CBonusSelection::CRegion::show( SDL_Surface * to )
 {
-	const SCampPositions::SRegionDesc & desc = owner->campDescriptions[owner->ourCampaign->header.mapVersion].regions[myNumber];
+	const SCampPositions::SRegionDesc & desc = owner->campDescriptions[owner->ourCampaign->camp->header.mapVersion].regions[myNumber];
 	if (!accessible)
 	{
 		//show as striped

+ 3 - 3
client/CPreGame.h

@@ -24,6 +24,7 @@ class CTextInput;
 class CCampaign;
 class CGStatusBar;
 class CTextBox;
+class CCampaignState;
 
 class CMapInfo
 {
@@ -316,13 +317,12 @@ class CBonusSelection : public CIntObject
 	CRegion * highlightedRegion;
 
 	void loadPositionsOfGraphics();
-	const CCampaign * ourCampaign;
+	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)
 	AdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty
 	void changeDiff(bool increase); //if false, then decrease
-	int whichMap;
 
 	//bonus selection
 	void updateBonusSelection();
@@ -335,7 +335,7 @@ public:
 	void selectMap(int whichOne);
 	void selectBonus(int id);
 
-	CBonusSelection(const CCampaign * _ourCampaign, int _whichMap);
+	CBonusSelection(CCampaignState * _ourCampaign);
 	~CBonusSelection();
 
 	void showAll(SDL_Surface * to);

+ 15 - 0
hch/CCampaignHandler.cpp

@@ -7,6 +7,7 @@
 #include "CLodHandler.h"
 #include "../lib/VCMI_Lib.h"
 #include "CGeneralTextHandler.h"
+#include "../StartInfo.h"
 
 namespace fs = boost::filesystem;
 
@@ -466,3 +467,17 @@ bool CScenarioTravel::STravelBonus::isBonusForHero() const
 {
 	return type == 0 || type == 1 || type == 3 || type == 4 || type == 5 || type == 6;
 }
+
+void CCampaignState::initNewCampaign( const StartInfo &si )
+{
+	assert(si.mode == 2);
+	campaignName = si.mapname;
+	currentMap = si.whichMapInCampaign;
+
+	//check if campaign is in lod or not
+	bool inLod = campaignName.find('/') == std::string::npos;
+
+	camp = CCampaignHandler::getCampaign(campaignName, inLod); //TODO lod???
+	for (ui8 i = 0; i < camp->mapPieces.size(); i++)
+		mapsRemaining.push_back(i);
+}

+ 18 - 0
hch/CCampaignHandler.h

@@ -15,6 +15,8 @@
  *
  */
 
+struct StartInfo;
+
 class DLL_EXPORT CCampaignHeader
 {
 public:
@@ -122,6 +124,22 @@ public:
 	CCampaign();
 };
 
+class DLL_EXPORT CCampaignState
+{
+public:
+	CCampaign *camp;
+	std::string campaignName; 
+	std::vector<ui8> mapsConquered, mapsRemaining;
+	ui8 currentMap; 
+
+	void initNewCampaign(const StartInfo &si);
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & camp & campaignName & mapsRemaining & mapsConquered & currentMap;
+	}
+};
+
 class DLL_EXPORT CCampaignHandler
 {
 	static CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt );

+ 0 - 12
lib/CGameState.cpp

@@ -4233,16 +4233,4 @@ InfoAboutHero & InfoAboutHero::operator=( const InfoAboutHero & iah )
 	return *this;
 }
 
-void CCampaignState::initNewCampaign( const StartInfo &si )
-{
-	assert(si.mode == 2);
-	campaignName = si.mapname;
-	currentMap = si.whichMapInCampaign;
-	
-	//check if campaign is in lod or not
-	bool inLod = campaignName.find('/') == std::string::npos;
 
-	camp = CCampaignHandler::getCampaign(campaignName, inLod); //TODO lod???
-	for (ui8 i = 0; i < camp->mapPieces.size(); i++)
-		mapsRemaining.push_back(i);
-}

+ 1 - 16
lib/CGameState.h

@@ -60,6 +60,7 @@ class CSpell;
 struct TerrainTile;
 class CHeroClass;
 class CCampaign;
+class CCampaignState;
 
 namespace boost
 {
@@ -374,22 +375,6 @@ struct DLL_EXPORT CPathsInfo
 	~CPathsInfo();
 };
 
-class DLL_EXPORT CCampaignState
-{
-public:
-	CCampaign *camp;
-	std::string campaignName; 
-	std::vector<ui8> mapsConquered, mapsRemaining;
-	ui8 currentMap; 
-
-	void initNewCampaign(const StartInfo &si);
-
-	template <typename Handler> void serialize(Handler &h, const int version)
-	{
-		h & camp & campaignName & mapsRemaining & mapsConquered & currentMap;
-	}
-};
-
 class DLL_EXPORT CGameState
 {
 public:

+ 4 - 4
lib/HeroBonus.h

@@ -274,10 +274,10 @@ struct DLL_EXPORT Bonus
 	{
 		return hb.source==source && (id==0xffffff  ||  hb.id==id);
 	}
- 	inline bool operator == (const BonusType & cf) const
- 	{
- 		return type == cf;
- 	}
+	inline bool operator == (const BonusType & cf) const
+	{
+		return type == cf;
+	}
 	inline void ChangeBonusVal (const ui32 newVal)
 	{
 		val = newVal;