mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
fix campaign highscores
This commit is contained in:
@@ -161,11 +161,6 @@ CServerHandler::CServerHandler()
|
||||
registerTypesLobbyPacks(*applier);
|
||||
}
|
||||
|
||||
void CServerHandler::setHighScoreCalc(const std::shared_ptr<HighScoreCalculation> &newHighScoreCalc)
|
||||
{
|
||||
campaignScoreCalculator = newHighScoreCalc;
|
||||
}
|
||||
|
||||
void CServerHandler::threadRunNetwork()
|
||||
{
|
||||
logGlobal->info("Starting network thread");
|
||||
@@ -655,7 +650,7 @@ void CServerHandler::startGameplay(VCMI_LIB_WRAP_NAMESPACE(CGameState) * gameSta
|
||||
break;
|
||||
case EStartMode::CAMPAIGN:
|
||||
if(si->campState->conqueredScenarios().empty())
|
||||
campaignScoreCalculator.reset();
|
||||
si->campState->highscoreParameters.clear();
|
||||
client->newGame(gameState);
|
||||
break;
|
||||
case EStartMode::LOAD_GAME:
|
||||
@@ -756,19 +751,16 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
|
||||
if (!cs)
|
||||
ourCampaign = si->campState;
|
||||
|
||||
if(campaignScoreCalculator == nullptr)
|
||||
{
|
||||
campaignScoreCalculator = std::make_shared<HighScoreCalculation>();
|
||||
campaignScoreCalculator->isCampaign = true;
|
||||
campaignScoreCalculator->parameters.clear();
|
||||
}
|
||||
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();
|
||||
|
||||
auto & epilogue = ourCampaign->scenario(*ourCampaign->lastScenario()).epilog;
|
||||
auto finisher = [this, ourCampaign]()
|
||||
auto finisher = [this, ourCampaign, campaignScoreCalculator]()
|
||||
{
|
||||
if(ourCampaign->campaignSet != "" && ourCampaign->isCampaignFinished())
|
||||
{
|
||||
|
||||
@@ -105,7 +105,6 @@ class CServerHandler final : public IServerAPI, public LobbyInfo, public INetwor
|
||||
std::unique_ptr<IServerRunner> serverRunner;
|
||||
std::shared_ptr<CMapInfo> mapToStart;
|
||||
std::vector<std::string> localPlayerNames;
|
||||
std::shared_ptr<HighScoreCalculation> campaignScoreCalculator;
|
||||
|
||||
boost::thread threadNetwork;
|
||||
|
||||
@@ -219,7 +218,6 @@ public:
|
||||
|
||||
void visitForLobby(CPackForLobby & lobbyPack);
|
||||
void visitForClient(CPackForClient & clientPack);
|
||||
void setHighScoreCalc(const std::shared_ptr<HighScoreCalculation> &newHighScoreCalc);
|
||||
};
|
||||
|
||||
extern CServerHandler * CSH;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
#include "../../lib/CCreatureHandler.h"
|
||||
#include "../../lib/constants/EntityIdentifiers.h"
|
||||
#include "../../lib/gameState/HighScore.h"
|
||||
|
||||
auto HighScoreCalculation::calculate()
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
#include "../windows/CWindowObject.h"
|
||||
#include "../../lib/gameState/HighScore.h"
|
||||
|
||||
class CButton;
|
||||
class CLabel;
|
||||
@@ -20,24 +21,10 @@ class CFilledTexture;
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
std::vector<HighScoreParameter> parameters = std::vector<HighScoreParameter>();
|
||||
std::vector<HighScoreParameter> parameters;
|
||||
bool isCampaign = false;
|
||||
|
||||
auto calculate();
|
||||
|
||||
@@ -463,6 +463,7 @@ set(lib_MAIN_HEADERS
|
||||
gameState/CGameState.h
|
||||
gameState/CGameStateCampaign.h
|
||||
gameState/EVictoryLossCheckResult.h
|
||||
gameState/HighScore.h
|
||||
gameState/InfoAboutArmy.h
|
||||
gameState/RumorState.h
|
||||
gameState/SThievesGuildInfo.h
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "../texts/TextLocalizationContainer.h"
|
||||
#include "CampaignConstants.h"
|
||||
#include "CampaignScenarioPrologEpilog.h"
|
||||
#include "../gameState/HighScore.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@@ -318,6 +319,8 @@ public:
|
||||
|
||||
std::string campaignSet;
|
||||
|
||||
std::vector<HighScoreParameter> highscoreParameters;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
h & static_cast<Campaign&>(*this);
|
||||
@@ -330,6 +333,8 @@ public:
|
||||
h & campaignSet;
|
||||
if (h.version >= Handler::Version::CAMPAIGN_MAP_TRANSLATIONS)
|
||||
h & mapTranslations;
|
||||
if (h.version >= Handler::Version::HIGHSCORE_PARAMETERS)
|
||||
h & highscoreParameters;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
41
lib/gameState/HighScore.h
Normal file
41
lib/gameState/HighScore.h
Normal file
@@ -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
|
||||
@@ -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
|
||||
MAP_FORMAT_ADDITIONAL_INFOS, // 848 - serialize new infos in map format
|
||||
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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user