diff --git a/client/mainmenu/CStatisticScreen.cpp b/client/mainmenu/CStatisticScreen.cpp index 208928fb6..5b860475f 100644 --- a/client/mainmenu/CStatisticScreen.cpp +++ b/client/mainmenu/CStatisticScreen.cpp @@ -30,11 +30,17 @@ #include "../widgets/Slider.h" #include "../../lib/gameState/GameStatistics.h" +#include "../../lib/gameState/CGameState.h" #include "../../lib/texts/CGeneralTextHandler.h" #include "../../lib/texts/TextOperations.h" #include +std::string CStatisticScreen::getDay(int d) +{ + return std::to_string(CGameState::getDate(d, Date::MONTH)) + "/" + std::to_string(CGameState::getDate(d, Date::WEEK)) + "/" + std::to_string(CGameState::getDate(d, Date::DAY_OF_WEEK)); +} + CStatisticScreen::CStatisticScreen(StatisticDataSet stat) : CWindowObject(BORDERED), statistic(stat) { @@ -98,7 +104,7 @@ TData CStatisticScreen::extractData(StatisticDataSet stat, std::functionplayerColors[tmpColor.getNum()], std::vector(tmpColorSet)); + plotData.push_back({graphics->playerColors[tmpColor.getNum()], std::vector(tmpColorSet)}); tmpColorSet.clear(); } @@ -108,7 +114,7 @@ TData CStatisticScreen::extractData(StatisticDataSet stat, std::functionplayerColors[tmpColor.getNum()], std::vector(tmpColorSet)); + plotData.push_back({graphics->playerColors[tmpColor.getNum()], std::vector(tmpColorSet)}); return plotData; } @@ -224,7 +230,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet }, { CGI->generaltexth->translate("vcmi.statisticWindow.param.daysSurvived"), [this](PlayerColor color){ - return std::to_string(playerDataFilter(color).size()); + return CStatisticScreen::getDay(playerDataFilter(color).size()); } }, { @@ -430,9 +436,11 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons, Point p = chartArea.topLeft() + Point(-5, chartArea.h + 10); layout.push_back(std::make_shared(p.x, p.y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, "0")); p = chartArea.topLeft() + Point(chartArea.w + 10, chartArea.h + 10); - layout.push_back(std::make_shared(p.x, p.y, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, std::to_string(maxDay))); + layout.push_back(std::make_shared(p.x, p.y, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CStatisticScreen::getDay(maxDay))); p = chartArea.topLeft() + Point(-5, -10); layout.push_back(std::make_shared(p.x, p.y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, std::to_string((int)maxVal))); + p = chartArea.bottomLeft() + Point(chartArea.w / 2, + 20); + layout.push_back(std::make_shared(p.x, p.y, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->translate("core.genrltxt.64"))); } void LineChart::updateStatusBar(const Point & cursorPosition) @@ -444,7 +452,7 @@ void LineChart::updateStatusBar(const Point & cursorPosition) { float x = ((float)maxDay / (float)chartArea.w) * ((float)cursorPosition.x - (float)r.x) + 1.0f; float y = maxVal - ((float)maxVal / (float)chartArea.h) * ((float)cursorPosition.y - (float)r.y); - statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + std::to_string((int)x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + ((int)y > 0 ? std::to_string((int)y) : std::to_string(y))); + statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + CStatisticScreen::getDay(x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + ((int)y > 0 ? std::to_string((int)y) : std::to_string(y))); } GH.windows().totalRedraw(); } diff --git a/client/mainmenu/CStatisticScreen.h b/client/mainmenu/CStatisticScreen.h index c4c208bf5..32b8883d7 100644 --- a/client/mainmenu/CStatisticScreen.h +++ b/client/mainmenu/CStatisticScreen.h @@ -20,8 +20,8 @@ class ComboBox; class CSlider; class IImage; -using TData = std::map>; -using TIcons = std::map>>>; +using TData = std::vector>>; +using TIcons = std::vector>>>>; class CStatisticScreen : public CWindowObject { @@ -69,6 +69,7 @@ class CStatisticScreen : public CWindowObject void onSelectButton(); public: CStatisticScreen(StatisticDataSet stat); + static std::string getDay(int day); }; class StatisticSelector : public CWindowObject diff --git a/lib/Color.h b/lib/Color.h index 4a9fc41d9..6ad89513a 100644 --- a/lib/Color.h +++ b/lib/Color.h @@ -49,11 +49,6 @@ public: , a(ALPHA_OPAQUE) {} - bool operator <(const ColorRGBA &val) const - { - return (r + g + b) < (val.r + val.g + val.b); - } - template void serialize(Handler &h) { diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index 7598801b6..ce75c0cf2 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -129,26 +129,26 @@ HeroTypeID CGameState::pickUnusedHeroTypeRandomly(const PlayerColor & owner) throw std::runtime_error("Can not allocate hero. All heroes are already used."); } -int CGameState::getDate(Date mode) const +int CGameState::getDate(int d, Date mode) { int temp; switch (mode) { case Date::DAY: - return day; + return d; case Date::DAY_OF_WEEK: //day of week - temp = (day)%7; // 1 - Monday, 7 - Sunday + temp = (d)%7; // 1 - Monday, 7 - Sunday return temp ? temp : 7; case Date::WEEK: //current week - temp = ((day-1)/7)+1; + temp = ((d-1)/7)+1; if (!(temp%4)) return 4; else return (temp%4); case Date::MONTH: //current month - return ((day-1)/28)+1; + return ((d-1)/28)+1; case Date::DAY_OF_MONTH: //day of month - temp = (day)%28; + temp = (d)%28; if (temp) return temp; else return 28; @@ -156,6 +156,11 @@ int CGameState::getDate(Date mode) const return 0; } +int CGameState::getDate(Date mode) const +{ + return getDate(day, mode); +} + CGameState::CGameState() { gs = this; diff --git a/lib/gameState/CGameState.h b/lib/gameState/CGameState.h index c63f5cc52..06de90720 100644 --- a/lib/gameState/CGameState.h +++ b/lib/gameState/CGameState.h @@ -138,6 +138,7 @@ public: bool isVisible(int3 pos, const std::optional & player) const override; bool isVisible(const CGObjectInstance * obj, const std::optional & player) const override; + static int getDate(int day, Date mode); int getDate(Date mode=Date::DAY) const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month // ----- getters, setters ----- diff --git a/lib/gameState/GameStatistics.cpp b/lib/gameState/GameStatistics.cpp index c66f00035..8551e18de 100644 --- a/lib/gameState/GameStatistics.cpp +++ b/lib/gameState/GameStatistics.cpp @@ -75,7 +75,6 @@ StatisticDataSetEntry StatisticDataSet::createEntry(const PlayerState * ps, cons data.tradeVolume = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).tradeVolume : TResources(); data.eventCapturedTown = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastCapturedTownDay == gs->getDate(Date::DAY) : false; data.eventDefeatedStrongestHero = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastDefeatedStrongestHeroDay == gs->getDate(Date::DAY) : false; - data.eventRansackingDragonUtopia = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastRansackingDragonUtopiaDay == gs->getDate(Date::DAY) : false; data.movementPointsUsed = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).movementPointsUsed : 0; return data; @@ -116,7 +115,6 @@ std::string StatisticDataSet::toCsv(std::string sep) ss << "NumHeroEscaped" << sep; ss << "EventCapturedTown" << sep; ss << "EventDefeatedStrongestHero" << sep; - ss << "EventRansackingDragonUtopia" << sep; ss << "MovementPointsUsed"; for(auto & resource : resources) ss << sep << GameConstants::RESOURCE_NAMES[resource]; @@ -161,7 +159,6 @@ std::string StatisticDataSet::toCsv(std::string sep) ss << entry.numHeroEscaped << sep; ss << entry.eventCapturedTown << sep; ss << entry.eventDefeatedStrongestHero << sep; - ss << entry.eventRansackingDragonUtopia << sep; ss << entry.movementPointsUsed; for(auto & resource : resources) ss << sep << entry.resources[resource]; diff --git a/lib/gameState/GameStatistics.h b/lib/gameState/GameStatistics.h index 7d5abbe25..fafddeaa5 100644 --- a/lib/gameState/GameStatistics.h +++ b/lib/gameState/GameStatistics.h @@ -55,7 +55,6 @@ struct DLL_LINKAGE StatisticDataSetEntry TResources tradeVolume; bool eventCapturedTown; bool eventDefeatedStrongestHero; - bool eventRansackingDragonUtopia; si64 movementPointsUsed; template void serialize(Handler &h) @@ -97,7 +96,6 @@ struct DLL_LINKAGE StatisticDataSetEntry { h & eventCapturedTown; h & eventDefeatedStrongestHero; - h & eventRansackingDragonUtopia; } h & movementPointsUsed; } @@ -125,7 +123,6 @@ public: si64 movementPointsUsed; int lastCapturedTownDay; int lastDefeatedStrongestHeroDay; - int lastRansackingDragonUtopiaDay; template void serialize(Handler &h) { @@ -143,7 +140,6 @@ public: { h & lastCapturedTownDay; h & lastDefeatedStrongestHeroDay; - h & lastRansackingDragonUtopiaDay; } } }; diff --git a/lib/mapObjects/CBank.cpp b/lib/mapObjects/CBank.cpp index 43737f887..8177b56af 100644 --- a/lib/mapObjects/CBank.cpp +++ b/lib/mapObjects/CBank.cpp @@ -275,10 +275,6 @@ void CBank::doVisit(const CGHeroInstance * hero) const //grant resources if (bankConfig) { - // add statistics - if(ID.toEnum() == Obj::DRAGON_UTOPIA) - cb->gameState()->statistic.accumulatedValues[hero->getOwner()].lastRansackingDragonUtopiaDay = cb->gameState()->getDate(Date::DAY); - for (GameResID it : GameResID::ALL_RESOURCES()) { if (bankConfig->resources[it] != 0)