瀏覽代碼

Minor changes.

Michał W. Urbańczyk 15 年之前
父節點
當前提交
4aa60cd40e
共有 10 個文件被更改,包括 54 次插入33 次删除
  1. 2 0
      StartInfo.h
  2. 3 3
      client/CMT.cpp
  3. 13 5
      client/CPlayerInterface.cpp
  4. 1 0
      client/CPlayerInterface.h
  5. 2 2
      client/CPreGame.cpp
  6. 11 0
      hch/CArtHandler.cpp
  7. 1 0
      hch/CArtHandler.h
  8. 1 1
      hch/CCampaignHandler.cpp
  9. 19 21
      lib/CGameState.cpp
  10. 1 1
      server/CVCMIServer.cpp

+ 2 - 0
StartInfo.h

@@ -51,6 +51,8 @@ struct PlayerSettings
 
 struct StartInfo
 {
+	enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN};
+
 	ui8 mode; //0 - new game; 1 - load game; 2 - campaign
 	ui8 difficulty; //0=easy; 4=impossible
 	std::map<int, PlayerSettings> playerInfos; //color indexed

+ 3 - 3
client/CMT.cpp

@@ -639,11 +639,11 @@ void startGame(StartInfo * options)
 	CPlayerInterface::howManyPeople = 0;
 	switch(options->mode) //new game
 	{
-	case 0:
-	case 2:
+	case StartInfo::NEW_GAME:
+	case StartInfo::CAMPAIGN:
 		client->newGame(NULL, options);
 		break;
-	case 1:
+	case StartInfo::LOAD_GAME:
 		std::string fname = options->mapname;
 		boost::algorithm::erase_last(fname,".vlgm1");
 		client->loadGame(fname);

+ 13 - 5
client/CPlayerInterface.cpp

@@ -1818,12 +1818,12 @@ void CPlayerInterface::gameOver(ui8 player, bool victory )
 		howManyPeople--;
 		if(!howManyPeople) //all human players eliminated
 		{
- 			//return to main menu
-			SDL_Event event;
-			event.type = SDL_USEREVENT;
-			event.user.code = 2;
-			SDL_PushEvent(&event);
+			if(cb->getStartInfo()->mode != StartInfo::CAMPAIGN)
+				requestReturningToMainMenu();
+			
+			//TODO next campaign scenario
 		}
+
 	}
 	else
 	{
@@ -2083,6 +2083,14 @@ void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
 		showShipyardDialog(obj);
 }
 
+void CPlayerInterface::requestReturningToMainMenu()
+{
+	SDL_Event event;
+	event.type = SDL_USEREVENT;
+	event.user.code = 2;
+	SDL_PushEvent(&event);
+}
+
 CPlayerInterface::SpellbookLastSetting::SpellbookLastSetting()
 {
 	spellbookLastPageBattle = spellbokLastPageAdvmap = 0;

+ 1 - 0
client/CPlayerInterface.h

@@ -244,6 +244,7 @@ public:
 	void acceptTurn(); //used during hot seat after your turn message is close
 	void tryDiggging(const CGHeroInstance *h);
 	void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard; 
+	void requestReturningToMainMenu();
 
 	CPlayerInterface(int Player);//c-tor
 	~CPlayerInterface();//d-tor

+ 2 - 2
client/CPreGame.cpp

@@ -337,7 +337,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, bool MultiPlayer)
 	sInfo.difficulty = 1;
 	current = NULL;
 
-	sInfo.mode = (Type == CMenuScreen::newGame ? 0 : 1);
+	sInfo.mode = (Type == CMenuScreen::newGame ? StartInfo::NEW_GAME : StartInfo::LOAD_GAME);
 	sInfo.turnTime = 0;
 	curTab = NULL;
 
@@ -2363,7 +2363,7 @@ void CBonusSelection::selectMap( int whichOne )
 {
 	sInfo.difficulty = ourCampaign->camp->scenarios[whichOne].difficulty;
 	sInfo.mapname = ourCampaign->camp->header.filename;
-	sInfo.mode = 2;
+	sInfo.mode = StartInfo::CAMPAIGN;
 
 	//get header
 	int i = 0;

+ 11 - 0
hch/CArtHandler.cpp

@@ -805,4 +805,15 @@ void CArtHandler::clearHlpLists()
 	minors.clear();
 	majors.clear();
 	relics.clear();
+}
+
+void CArtHandler::initAllowedArtifactsList(const std::vector<ui8> &allowed)
+{
+	allowedArtifacts.clear();
+	clearHlpLists();
+	for (int i=0; i<144; ++i) //yes, 144
+	{
+		if (allowed[i])
+			allowedArtifacts.push_back(artifacts[i]);
+	}
 }

+ 1 - 0
hch/CArtHandler.h

@@ -74,6 +74,7 @@ public:
 	bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();}
 	void equipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID, ui32 artifactID);
 	void unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID);
+	void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
 	static int convertMachineID(int id, bool creToArt);
 	CArtHandler();
 	~CArtHandler();

+ 1 - 1
hch/CCampaignHandler.cpp

@@ -470,7 +470,7 @@ bool CScenarioTravel::STravelBonus::isBonusForHero() const
 
 void CCampaignState::initNewCampaign( const StartInfo &si )
 {
-	assert(si.mode == 2);
+	assert(si.mode == StartInfo::CAMPAIGN);
 	campaignName = si.mapname;
 	currentMap = si.whichMapInCampaign;
 

+ 19 - 21
lib/CGameState.cpp

@@ -1267,33 +1267,31 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 		}
 
 	};
-	VLC->arth->allowedArtifacts.clear();
-	VLC->arth->clearHlpLists();
+
 	switch(si->mode)
 	{
-	case 0:
+	case StartInfo::NEW_GAME:
 		map = new Mapa(si->mapname);
-		for (int i=0; i<144; ++i) //yes, 144
-		{
-			if (map->allowedArtifact[i])
-				VLC->arth->allowedArtifacts.push_back(VLC->arth->artifacts[i]);
-		}
 		break;
-	case 2:
-		campaign = new CCampaignState();
-		campaign->initNewCampaign(*si);
-		std::string &mapContent = campaign->camp->mapPieces[si->whichMapInCampaign];
-		map = new Mapa();
-		map->initFromBytes((const unsigned char*)mapContent.c_str());
-		for (int i=0; i<144; ++i)
+	case StartInfo::CAMPAIGN:
 		{
-			if (map->allowedArtifact[i])
-				VLC->arth->allowedArtifacts.push_back(VLC->arth->artifacts[i]);
+			assert(vstd::contains(campaign->camp->mapPieces, si->whichMapInCampaign));
+			campaign = new CCampaignState();
+			campaign->initNewCampaign(*si);
+
+			std::string &mapContent = campaign->camp->mapPieces[si->whichMapInCampaign];
+			map = new Mapa();
+			map->initFromBytes((const unsigned char*)mapContent.c_str());
 		}
 		break;
+	default:
+		tlog1 << "Wrong mode: " << (int)si->mode << std::endl;
+		return;
 	}
+	VLC->arth->initAllowedArtifactsList(map->allowedArtifact);
 	tlog0 << "Map loaded!" << std::endl;
 
+
 	//tlog0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
 	if(checksum)
 	{
@@ -1434,7 +1432,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 			map->objects.push_back(nnn);
 			map->addBlockVisTiles(nnn);
 			//give campaign bonus
-			if (si->mode == 2 && getPlayer(nnn->tempOwner)->human)
+			if (si->mode == StartInfo::CAMPAIGN && getPlayer(nnn->tempOwner)->human)
 			{
 				HLP::giveCampaignBonusToHero(nnn, si, campaign->camp->scenarios[si->whichMapInCampaign].travelOptions);
 			}
@@ -1482,7 +1480,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 	}
 
 	//give start resource bonus in case of campaign
-	if (si->mode == 2)
+	if (si->mode == StartInfo::CAMPAIGN)
 	{
 		CScenarioTravel::STravelBonus chosenBonus = 
 			campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus];
@@ -1566,7 +1564,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 		hpool.pavailable[map->disposedHeroes[i].ID] = map->disposedHeroes[i].players;
 	}
 
-	if (si->mode == 2) //give campaign bonuses for specific / best hero
+	if (si->mode == StartInfo::CAMPAIGN) //give campaign bonuses for specific / best hero
 	{
 
 		CScenarioTravel::STravelBonus chosenBonus = 
@@ -1763,7 +1761,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 	}
 
 	//campaign bonuses for towns
-	if (si->mode == 2)
+	if (si->mode == StartInfo::CAMPAIGN)
 	{
 		CScenarioTravel::STravelBonus chosenBonus = 
 			campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus];

+ 1 - 1
server/CVCMIServer.cpp

@@ -81,7 +81,7 @@ void CVCMIServer::newGame(CConnection *c)
 	FILE * f = fopen(si->mapname.c_str(),"r");
 	problem = !f;
 #endif
-	if(problem && si->mode == 0) //TODO some checking for campaigns
+	if(problem && si->mode == StartInfo::NEW_GAME) //TODO some checking for campaigns
 	{
 		*c << ui8(problem); //WRONG!
 		return;