فهرست منبع

Don't give a turn to player who is about to lose (days without town).

DjWarmonger 10 سال پیش
والد
کامیت
716c324695
3فایلهای تغییر یافته به همراه31 افزوده شده و 17 حذف شده
  1. 2 1
      lib/NetPacks.h
  2. 1 11
      lib/NetPacksLib.cpp
  3. 28 5
      server/CGameHandler.cpp

+ 2 - 1
lib/NetPacks.h

@@ -167,10 +167,11 @@ struct YourTurn : public CPackForClient //100
 	DLL_LINKAGE void applyGs(CGameState *gs);
 
 	PlayerColor player;
+	ui8 daysWithoutCastle;
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & player;
+		h & player & daysWithoutCastle;
 	}
 };
 

+ 1 - 11
lib/NetPacksLib.cpp

@@ -1623,18 +1623,8 @@ DLL_LINKAGE void YourTurn::applyGs( CGameState *gs )
 {
 	gs->currentPlayer = player;
 
-	//count days without town
 	auto & playerState = gs->players[player];
-	if(playerState.towns.empty())
-	{
-		if(playerState.daysWithoutCastle)
-			++(*playerState.daysWithoutCastle);
-		else playerState.daysWithoutCastle = 0;
-	}
-	else
-	{
-		playerState.daysWithoutCastle = boost::none;
-	}
+	playerState.daysWithoutCastle = daysWithoutCastle;
 }
 
 DLL_LINKAGE Component::Component(const CStackBasicDescriptor &stack)

+ 28 - 5
server/CGameHandler.cpp

@@ -1583,19 +1583,42 @@ void CGameHandler::run(bool resume)
 		}
 
 		resume = false;
-		for(; it != playerTurnOrder.end(); it++)
+		for (; it != playerTurnOrder.end(); it++)
 		{
 			auto playerColor = *it;
-			if(gs->players[playerColor].status == EPlayerStatus::INGAME)
+
+			auto playerState = gs->players[playerColor];
+			if (playerState.status == EPlayerStatus::INGAME)
 			{
-				states.setFlag(playerColor, &PlayerStatus::makingTurn, true);
+				states.setFlag (playerColor, &PlayerStatus::makingTurn, true);
+
+				//count days without town
+				if (playerState.towns.empty())
+				{
+					if (playerState.daysWithoutCastle)
+						++(*playerState.daysWithoutCastle);
+					else playerState.daysWithoutCastle = 0;
+				}
+				else
+				{
+					playerState.daysWithoutCastle = boost::none; //TODO: reset this immediatelly when player conquers any castle
+				}
+
+				//if player runs out of time, he shouldn't get the turn (especially AI)
+				checkVictoryLossConditionsForAll();
+
+				if (gs->players[playerColor].status != EPlayerStatus::INGAME)
+				{ //player lost at the beginning of his turn
+					continue;
+				}
 
 				YourTurn yt;
 				yt.player = playerColor;
+				//Change local daysWithoutCastle counter for local interface message //TODO: needed?
+				if (playerState.daysWithoutCastle)
+					yt.daysWithoutCastle = playerState.daysWithoutCastle.get();
 				applyAndSend(&yt);
 
-				checkVictoryLossConditionsForAll();
-
 				//wait till turn is done
 				boost::unique_lock<boost::mutex> lock(states.mx);
 				while(states.players.at(playerColor).makingTurn && !end2)