Procházet zdrojové kódy

fix campaign highscores

Laserlicht před 1 rokem
rodič
revize
53c0d20a57

+ 6 - 14
client/CServerHandler.cpp

@@ -161,11 +161,6 @@ CServerHandler::CServerHandler()
 	registerTypesLobbyPacks(*applier);
 	registerTypesLobbyPacks(*applier);
 }
 }
 
 
-void CServerHandler::setHighScoreCalc(const std::shared_ptr<HighScoreCalculation> &newHighScoreCalc)
-{
-	campaignScoreCalculator = newHighScoreCalc;
-}
-
 void CServerHandler::threadRunNetwork()
 void CServerHandler::threadRunNetwork()
 {
 {
 	logGlobal->info("Starting network thread");
 	logGlobal->info("Starting network thread");
@@ -655,7 +650,7 @@ void CServerHandler::startGameplay(VCMI_LIB_WRAP_NAMESPACE(CGameState) * gameSta
 		break;
 		break;
 	case EStartMode::CAMPAIGN:
 	case EStartMode::CAMPAIGN:
 		if(si->campState->conqueredScenarios().empty())
 		if(si->campState->conqueredScenarios().empty())
-			campaignScoreCalculator.reset();
+			si->campState->highscoreParameters.clear();
 		client->newGame(gameState);
 		client->newGame(gameState);
 		break;
 		break;
 	case EStartMode::LOAD_GAME:
 	case EStartMode::LOAD_GAME:
@@ -756,19 +751,16 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
 	if (!cs)
 	if (!cs)
 		ourCampaign = si->campState;
 		ourCampaign = si->campState;
 
 
-	if(campaignScoreCalculator == nullptr)
-	{
-		campaignScoreCalculator = std::make_shared<HighScoreCalculation>();
-		campaignScoreCalculator->isCampaign = true;
-		campaignScoreCalculator->parameters.clear();
-	}
 	param.campaignName = cs->getNameTranslated();
 	param.campaignName = cs->getNameTranslated();
-	campaignScoreCalculator->parameters.push_back(param);
+	cs->highscoreParameters.push_back(param);
+	auto campaignScoreCalculator = std::make_shared<HighScoreCalculation>();
+	campaignScoreCalculator->isCampaign = true;
+	campaignScoreCalculator->parameters = cs->highscoreParameters;
 
 
 	endGameplay();
 	endGameplay();
 
 
 	auto & epilogue = ourCampaign->scenario(*ourCampaign->lastScenario()).epilog;
 	auto & epilogue = ourCampaign->scenario(*ourCampaign->lastScenario()).epilog;
-	auto finisher = [this, ourCampaign]()
+	auto finisher = [this, ourCampaign, campaignScoreCalculator]()
 	{
 	{
 		if(ourCampaign->campaignSet != "" && ourCampaign->isCampaignFinished())
 		if(ourCampaign->campaignSet != "" && ourCampaign->isCampaignFinished())
 		{
 		{

+ 0 - 2
client/CServerHandler.h

@@ -105,7 +105,6 @@ class CServerHandler final : public IServerAPI, public LobbyInfo, public INetwor
 	std::unique_ptr<IServerRunner> serverRunner;
 	std::unique_ptr<IServerRunner> serverRunner;
 	std::shared_ptr<CMapInfo> mapToStart;
 	std::shared_ptr<CMapInfo> mapToStart;
 	std::vector<std::string> localPlayerNames;
 	std::vector<std::string> localPlayerNames;
-	std::shared_ptr<HighScoreCalculation> campaignScoreCalculator;
 
 
 	boost::thread threadNetwork;
 	boost::thread threadNetwork;
 
 
@@ -219,7 +218,6 @@ public:
 
 
 	void visitForLobby(CPackForLobby & lobbyPack);
 	void visitForLobby(CPackForLobby & lobbyPack);
 	void visitForClient(CPackForClient & clientPack);
 	void visitForClient(CPackForClient & clientPack);
-	void setHighScoreCalc(const std::shared_ptr<HighScoreCalculation> &newHighScoreCalc);
 };
 };
 
 
 extern CServerHandler * CSH;
 extern CServerHandler * CSH;

+ 1 - 0
client/mainmenu/CHighScoreScreen.cpp

@@ -32,6 +32,7 @@
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/constants/EntityIdentifiers.h"
 #include "../../lib/constants/EntityIdentifiers.h"
+#include "../../lib/gameState/HighScore.h"
 
 
 auto HighScoreCalculation::calculate()
 auto HighScoreCalculation::calculate()
 {
 {

+ 2 - 15
client/mainmenu/CHighScoreScreen.h

@@ -9,6 +9,7 @@
  */
  */
 #pragma once
 #pragma once
 #include "../windows/CWindowObject.h"
 #include "../windows/CWindowObject.h"
+#include "../../lib/gameState/HighScore.h"
 
 
 class CButton;
 class CButton;
 class CLabel;
 class CLabel;
@@ -20,24 +21,10 @@ class CFilledTexture;
 
 
 class TransparentFilledRectangle;
 class TransparentFilledRectangle;
 
 
-class HighScoreParameter
-{
-public:
-	int difficulty;
-	int day;
-	int townAmount;
-	bool usedCheat;
-	bool hasGrail;
-	bool allDefeated;
-	std::string campaignName;
-	std::string scenarioName;
-	std::string playerName;
-};
-
 class HighScoreCalculation
 class HighScoreCalculation
 {
 {
 public:
 public:
-	std::vector<HighScoreParameter> parameters = std::vector<HighScoreParameter>();
+	std::vector<HighScoreParameter> parameters;
 	bool isCampaign = false;
 	bool isCampaign = false;
 
 
 	auto calculate();
 	auto calculate();

+ 1 - 0
lib/CMakeLists.txt

@@ -463,6 +463,7 @@ set(lib_MAIN_HEADERS
 	gameState/CGameState.h
 	gameState/CGameState.h
 	gameState/CGameStateCampaign.h
 	gameState/CGameStateCampaign.h
 	gameState/EVictoryLossCheckResult.h
 	gameState/EVictoryLossCheckResult.h
+	gameState/HighScore.h
 	gameState/InfoAboutArmy.h
 	gameState/InfoAboutArmy.h
 	gameState/RumorState.h
 	gameState/RumorState.h
 	gameState/SThievesGuildInfo.h
 	gameState/SThievesGuildInfo.h

+ 5 - 0
lib/campaign/CampaignState.h

@@ -15,6 +15,7 @@
 #include "../texts/TextLocalizationContainer.h"
 #include "../texts/TextLocalizationContainer.h"
 #include "CampaignConstants.h"
 #include "CampaignConstants.h"
 #include "CampaignScenarioPrologEpilog.h"
 #include "CampaignScenarioPrologEpilog.h"
+#include "../gameState/HighScore.h"
 
 
 VCMI_LIB_NAMESPACE_BEGIN
 VCMI_LIB_NAMESPACE_BEGIN
 
 
@@ -318,6 +319,8 @@ public:
 
 
 	std::string campaignSet;
 	std::string campaignSet;
 
 
+	std::vector<HighScoreParameter> highscoreParameters;
+
 	template <typename Handler> void serialize(Handler &h)
 	template <typename Handler> void serialize(Handler &h)
 	{
 	{
 		h & static_cast<Campaign&>(*this);
 		h & static_cast<Campaign&>(*this);
@@ -330,6 +333,8 @@ public:
 		h & campaignSet;
 		h & campaignSet;
 		if (h.version >= Handler::Version::CAMPAIGN_MAP_TRANSLATIONS)
 		if (h.version >= Handler::Version::CAMPAIGN_MAP_TRANSLATIONS)
 			h & mapTranslations;
 			h & mapTranslations;
+		if (h.version >= Handler::Version::HIGHSCORE_PARAMETERS)
+			h & highscoreParameters;
 	}
 	}
 };
 };
 
 

+ 41 - 0
lib/gameState/HighScore.h

@@ -0,0 +1,41 @@
+/*
+ * HighScore.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+#pragma once
+
+VCMI_LIB_NAMESPACE_BEGIN
+
+class DLL_LINKAGE HighScoreParameter
+{
+public:
+	int difficulty;
+	int day;
+	int townAmount;
+	bool usedCheat;
+	bool hasGrail;
+	bool allDefeated;
+	std::string campaignName;
+	std::string scenarioName;
+	std::string playerName;
+
+	template <typename Handler> void serialize(Handler &h)
+	{
+		h & difficulty;
+		h & day;
+		h & townAmount;
+		h & usedCheat;
+		h & hasGrail;
+		h & allDefeated;
+		h & campaignName;
+		h & scenarioName;
+		h & playerName;
+	}
+};
+
+VCMI_LIB_NAMESPACE_END

+ 2 - 1
lib/serializer/ESerializationVersion.h

@@ -57,6 +57,7 @@ enum class ESerializationVersion : int32_t
 	SIMPLE_TEXT_CONTAINER_SERIALIZATION, // 847 - text container is serialized using common routine instead of custom approach
 	SIMPLE_TEXT_CONTAINER_SERIALIZATION, // 847 - text container is serialized using common routine instead of custom approach
 	MAP_FORMAT_ADDITIONAL_INFOS, // 848 - serialize new infos in map format
 	MAP_FORMAT_ADDITIONAL_INFOS, // 848 - serialize new infos in map format
 	REMOVE_LIB_RNG, // 849 - removed random number generators from library classes
 	REMOVE_LIB_RNG, // 849 - removed random number generators from library classes
+	HIGHSCORE_PARAMETERS, // 850 - saves parameter for campaign
 
 
-	CURRENT = REMOVE_LIB_RNG
+	CURRENT = HIGHSCORE_PARAMETERS
 };
 };