浏览代码

calc preperation

Laserlicht 2 年之前
父节点
当前提交
1a0f5cf159

+ 24 - 3
client/CPlayerInterface.cpp

@@ -66,6 +66,7 @@
 #include "../lib/CGeneralTextHandler.h"
 #include "../lib/CHeroHandler.h"
 #include "../lib/CPlayerState.h"
+#include "../lib/gameState/CGameState.h"
 #include "../lib/CStack.h"
 #include "../lib/CStopWatch.h"
 #include "../lib/CThreadHelper.h"
@@ -1686,17 +1687,37 @@ void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
 
 void CPlayerInterface::requestReturningToMainMenu(bool won)
 {
+	HighScoreParameter param;
+	param.difficulty = cb->getStartInfo()->difficulty;
+	param.day = cb->getDate();
+	param.townAmount = cb->howManyTowns();
+	param.usedCheat = cb->getPlayerState(*cb->getPlayerID())->enteredWinningCheatCode;
+	param.hasGrail = false;
+	for(const CGHeroInstance * h : cb->getHeroesInfo())
+		if(h->hasArt(ArtifactID::GRAIL))
+			param.hasGrail = true;
+	param.allDefeated = true;
+	for (PlayerColor player(0); player < PlayerColor::PLAYER_LIMIT; ++player)
+	{
+		auto ps = cb->getPlayerState(player);
+		if(ps && player != *cb->getPlayerID())
+			if(!ps->checkVanquished())
+				param.allDefeated = false;
+	}
+	HighScoreCalculation calc;
+	calc.parameters.push_back(param);
+
 	if(won && cb->getStartInfo()->campState)
-		CSH->startCampaignScenario(cb->getStartInfo()->campState);
+		CSH->startCampaignScenario(param, cb->getStartInfo()->campState);
 	else
 	{
 		GH.dispatchMainThread(
-			[won]()
+			[won, calc]()
 			{
 				CSH->endGameplay();
 				GH.defActionsDef = 63;
 				CMM->menu->switchToTab("main");
-				GH.windows().createAndPushWindow<CHighScoreInputScreen>(won);
+				GH.windows().createAndPushWindow<CHighScoreInputScreen>(won, calc);
 			}
 		);
 	}

+ 7 - 3
client/CServerHandler.cpp

@@ -669,14 +669,18 @@ void CServerHandler::endGameplay(bool closeConnection, bool restart)
 	saveSession->Bool() = false;
 }
 
-void CServerHandler::startCampaignScenario(std::shared_ptr<CampaignState> cs)
+void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared_ptr<CampaignState> cs)
 {
 	std::shared_ptr<CampaignState> ourCampaign = cs;
 
 	if (!cs)
+	{
 		ourCampaign = si->campState;
+		calc.parameters.clear();
+	}
+	calc.parameters.push_back(param);
 
-	GH.dispatchMainThread([ourCampaign]()
+	GH.dispatchMainThread([ourCampaign, this]()
 	{
 		CSH->campaignServerRestartLock.set(true);
 		CSH->endGameplay();
@@ -698,7 +702,7 @@ void CServerHandler::startCampaignScenario(std::shared_ptr<CampaignState> cs)
 			else
 			{
 				CMM->openCampaignScreen(ourCampaign->campaignSet);
-				GH.windows().createAndPushWindow<CHighScoreInputScreen>(true);
+				GH.windows().createAndPushWindow<CHighScoreInputScreen>(true, calc);
 			}
 		};
 		if(epilogue.hasPrologEpilog)

+ 5 - 1
client/CServerHandler.h

@@ -14,6 +14,8 @@
 #include "../lib/StartInfo.h"
 #include "../lib/CondSh.h"
 
+#include "mainmenu/CHighScoreScreen.h"
+
 VCMI_LIB_NAMESPACE_BEGIN
 
 class CConnection;
@@ -86,6 +88,8 @@ class CServerHandler : public IServerAPI, public LobbyInfo
 
 	std::vector<std::string> myNames;
 
+	HighScoreCalculation calc;
+
 	void threadHandleConnection();
 	void threadRunServer();
 	void onServerFinished();
@@ -159,7 +163,7 @@ public:
 
 	void startGameplay(VCMI_LIB_WRAP_NAMESPACE(CGameState) * gameState = nullptr);
 	void endGameplay(bool closeConnection = true, bool restart = false);
-	void startCampaignScenario(std::shared_ptr<CampaignState> cs = {});
+	void startCampaignScenario(HighScoreParameter param, std::shared_ptr<CampaignState> cs = {});
 	void showServerError(const std::string & txt) const;
 
 	// TODO: LobbyState must be updated within game so we should always know how many player interfaces our client handle

+ 6 - 1
client/mainmenu/CHighScoreScreen.cpp

@@ -28,6 +28,11 @@
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/constants/EntityIdentifiers.h"
 
+int HighScoreCalculation::calculate()
+{
+    return 0;
+}
+
 CHighScoreScreen::CHighScoreScreen()
 	: CWindowObject(BORDERED)
 {
@@ -168,7 +173,7 @@ void CHighScoreScreen::buttonExitClick()
     close();
 }
 
-CHighScoreInputScreen::CHighScoreInputScreen(bool won)
+CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc)
 	: CWindowObject(BORDERED), won(won)
 {
     addUsedEvents(LCLICK);

+ 19 - 1
client/mainmenu/CHighScoreScreen.h

@@ -16,6 +16,24 @@ class CMultiLineLabel;
 class CAnimImage;
 class CTextInput;
 
+class HighScoreParameter
+{
+public:
+    int difficulty;
+    int day;
+    int townAmount;
+    bool usedCheat;
+    bool hasGrail;
+    bool allDefeated;
+};
+
+class HighScoreCalculation
+{
+public:
+    std::vector<HighScoreParameter> parameters = std::vector<HighScoreParameter>();
+    int calculate();
+};
+
 class CHighScoreScreen : public CWindowObject
 {
     enum HighScorePage { SCENARIO, CAMPAIGN };
@@ -63,7 +81,7 @@ class CHighScoreInputScreen : public CWindowObject
     std::string video;
     bool won;
 public:
-	CHighScoreInputScreen(bool won);
+	CHighScoreInputScreen(bool won, HighScoreCalculation calc);
 
     void addEntry(std::string text);
 

+ 1 - 1
config/highscoreCreatures.json

@@ -117,6 +117,6 @@
         { "min" : 389, "max" : 391, "creature": "titan" },
         { "min" : 392, "max" : 394, "creature": "goldDragon" },
         { "min" : 395, "max" : 397, "creature": "blackDragon" },
-        { "min" : 398, "max" : 400, "creature": "archangel" }
+        { "min" : 398, "max" : 500, "creature": "archangel" }
     ]
 }