mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
statisic basic
This commit is contained in:
parent
b7b25bffd2
commit
fb171ab3a2
@ -355,6 +355,22 @@ void ClientCommandManager::handleGetScriptsCommand()
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClientCommandManager::handleGetStatistic()
|
||||
{
|
||||
printCommandMessage("Command accepted.\t");
|
||||
|
||||
const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / "statistic";
|
||||
boost::filesystem::create_directories(outPath);
|
||||
|
||||
const boost::filesystem::path filePath = outPath / (vstd::getDateTimeISO8601Basic(std::time(nullptr)) + ".csv");
|
||||
std::ofstream file(filePath.c_str());
|
||||
std::string csv = CSH->client->gameState()->statistic.toCsv();
|
||||
file << csv;
|
||||
|
||||
printCommandMessage("Writing statistic done :)\n");
|
||||
printCommandMessage("Statistic files can be found in " + outPath.string() + " directory\n");
|
||||
}
|
||||
|
||||
void ClientCommandManager::handleGetTextCommand()
|
||||
{
|
||||
printCommandMessage("Command accepted.\t");
|
||||
@ -597,6 +613,9 @@ void ClientCommandManager::processCommand(const std::string & message, bool call
|
||||
else if(message=="get scripts")
|
||||
handleGetScriptsCommand();
|
||||
|
||||
else if(message=="get statistic")
|
||||
handleGetStatistic();
|
||||
|
||||
else if(message=="get txt")
|
||||
handleGetTextCommand();
|
||||
|
||||
|
@ -57,6 +57,9 @@ class ClientCommandManager //take mantis #2292 issue about account if thinking a
|
||||
// Dumps all scripts in Extracted/Scripts
|
||||
void handleGetScriptsCommand();
|
||||
|
||||
// Dumps statistic in file
|
||||
void handleGetStatistic();
|
||||
|
||||
// Dumps all .txt files from DATA into Extracted/DATA
|
||||
void handleGetTextCommand();
|
||||
|
||||
|
@ -102,6 +102,7 @@ set(lib_MAIN_SRCS
|
||||
gameState/InfoAboutArmy.cpp
|
||||
gameState/RumorState.cpp
|
||||
gameState/TavernHeroesPool.cpp
|
||||
gameState/GameStatistics.cpp
|
||||
|
||||
mapObjectConstructors/AObjectTypeHandler.cpp
|
||||
mapObjectConstructors/CBankInstanceConstructor.cpp
|
||||
@ -468,6 +469,7 @@ set(lib_MAIN_HEADERS
|
||||
gameState/RumorState.h
|
||||
gameState/SThievesGuildInfo.h
|
||||
gameState/TavernHeroesPool.h
|
||||
gameState/GameStatistics.h
|
||||
gameState/TavernSlot.h
|
||||
gameState/QuestInfo.h
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "../ConstTransitivePtr.h"
|
||||
|
||||
#include "RumorState.h"
|
||||
#include "GameStatistics.h"
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -90,6 +91,8 @@ public:
|
||||
CBonusSystemNode globalEffects;
|
||||
RumorState currentRumor;
|
||||
|
||||
StatisticDataSet statistic;
|
||||
|
||||
static boost::shared_mutex mutex;
|
||||
|
||||
void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
|
||||
@ -167,6 +170,8 @@ public:
|
||||
h & currentRumor;
|
||||
h & campaign;
|
||||
h & allocatedArtifacts;
|
||||
if (h.version >= Handler::Version::STATISTICS)
|
||||
h & statistic;
|
||||
|
||||
BONUS_TREE_DESERIALIZATION_FIX
|
||||
}
|
||||
|
34
lib/gameState/GameStatistics.cpp
Normal file
34
lib/gameState/GameStatistics.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* GameStatistics.cpp, 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
|
||||
*
|
||||
*/
|
||||
#include "StdInc.h"
|
||||
#include "GameStatistics.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
void StatisticDataSet::add(StatisticDataSetEntry entry)
|
||||
{
|
||||
data.push_back(entry);
|
||||
}
|
||||
|
||||
std::string StatisticDataSet::toCsv()
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "Day" << ";" << "Player" << "\r\n";
|
||||
|
||||
for(auto & entry : data)
|
||||
{
|
||||
ss << entry.day << ";" << entry.player.getNum() << "\r\n";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
42
lib/gameState/GameStatistics.h
Normal file
42
lib/gameState/GameStatistics.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* GameSTatistics.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
|
||||
|
||||
#include "../GameConstants.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
struct DLL_LINKAGE StatisticDataSetEntry
|
||||
{
|
||||
int day;
|
||||
PlayerColor player;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
h & day;
|
||||
h & player;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_LINKAGE StatisticDataSet
|
||||
{
|
||||
std::vector<StatisticDataSetEntry> data;
|
||||
|
||||
public:
|
||||
void add(StatisticDataSetEntry entry);
|
||||
std::string toCsv();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
h & data;
|
||||
}
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@ -58,6 +58,7 @@ enum class ESerializationVersion : int32_t
|
||||
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
|
||||
STATISTICS, // 851 - removed random number generators from library classes
|
||||
|
||||
CURRENT = HIGHSCORE_PARAMETERS
|
||||
CURRENT = STATISTICS
|
||||
};
|
||||
|
@ -669,6 +669,22 @@ void CGameHandler::onPlayerTurnEnded(PlayerColor which)
|
||||
heroPool->onNewWeek(which);
|
||||
}
|
||||
|
||||
void CGameHandler::addStatistics()
|
||||
{
|
||||
for (auto & elem : gs->players)
|
||||
{
|
||||
if (elem.first == PlayerColor::NEUTRAL || !elem.first.isValidPlayer())
|
||||
continue;
|
||||
|
||||
StatisticDataSetEntry data;
|
||||
|
||||
data.day = getDate(Date::DAY);
|
||||
data.player = elem.first;
|
||||
|
||||
gameState()->statistic.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
void CGameHandler::onNewTurn()
|
||||
{
|
||||
logGlobal->trace("Turn %d", gs->day+1);
|
||||
@ -1002,6 +1018,8 @@ void CGameHandler::onNewTurn()
|
||||
}
|
||||
|
||||
synchronizeArtifactHandlerLists(); //new day events may have changed them. TODO better of managing that
|
||||
|
||||
addStatistics();
|
||||
}
|
||||
|
||||
void CGameHandler::start(bool resume)
|
||||
|
@ -226,6 +226,7 @@ public:
|
||||
void onPlayerTurnStarted(PlayerColor which);
|
||||
void onPlayerTurnEnded(PlayerColor which);
|
||||
void onNewTurn();
|
||||
void addStatistics();
|
||||
|
||||
void handleTimeEvents();
|
||||
void handleTownEvents(CGTownInstance *town, NewTurn &n);
|
||||
|
Loading…
Reference in New Issue
Block a user