GameStatistics.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * GameSTatistics.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../GameConstants.h"
  12. #include "../ResourceSet.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. struct PlayerState;
  15. class CGameState;
  16. class CGHeroInstance;
  17. class CGMine;
  18. struct DLL_LINKAGE StatisticDataSetEntry
  19. {
  20. std::string map;
  21. time_t timestamp;
  22. int day;
  23. PlayerColor player;
  24. TeamID team;
  25. bool isHuman;
  26. EPlayerStatus status;
  27. TResources resources;
  28. int numberHeroes;
  29. int numberTowns;
  30. int numberArtifacts;
  31. si64 armyStrength;
  32. int income;
  33. float mapExploredRatio;
  34. float obeliskVisitedRatio;
  35. std::map<EGameResID, int> numMines;
  36. int score;
  37. int maxHeroLevel;
  38. int numBattlesNeutral;
  39. int numBattlesPlayer;
  40. int numWinBattlesNeutral;
  41. int numWinBattlesPlayer;
  42. int numHeroSurrendered;
  43. int numHeroEscaped;
  44. template <typename Handler> void serialize(Handler &h)
  45. {
  46. h & map;
  47. h & timestamp;
  48. h & day;
  49. h & player;
  50. h & team;
  51. h & isHuman;
  52. h & status;
  53. h & resources;
  54. h & numberHeroes;
  55. h & numberTowns;
  56. h & numberArtifacts;
  57. h & armyStrength;
  58. h & income;
  59. h & mapExploredRatio;
  60. h & obeliskVisitedRatio;
  61. h & numMines;
  62. h & score;
  63. h & maxHeroLevel;
  64. h & numBattlesNeutral;
  65. h & numBattlesPlayer;
  66. h & numWinBattlesNeutral;
  67. h & numWinBattlesPlayer;
  68. h & numHeroSurrendered;
  69. h & numHeroEscaped;
  70. }
  71. };
  72. class DLL_LINKAGE StatisticDataSet
  73. {
  74. std::vector<StatisticDataSetEntry> data;
  75. public:
  76. void add(StatisticDataSetEntry entry);
  77. static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs);
  78. std::string toCsv();
  79. struct ValueStorage
  80. {
  81. std::map<PlayerColor, int> numBattlesNeutral;
  82. std::map<PlayerColor, int> numBattlesPlayer;
  83. std::map<PlayerColor, int> numWinBattlesNeutral;
  84. std::map<PlayerColor, int> numWinBattlesPlayer;
  85. std::map<PlayerColor, int> numHeroSurrendered;
  86. std::map<PlayerColor, int> numHeroEscaped;
  87. template <typename Handler> void serialize(Handler &h)
  88. {
  89. h & numBattlesNeutral;
  90. h & numBattlesPlayer;
  91. h & numWinBattlesNeutral;
  92. h & numWinBattlesPlayer;
  93. h & numHeroSurrendered;
  94. h & numHeroEscaped;
  95. }
  96. };
  97. ValueStorage values;
  98. template <typename Handler> void serialize(Handler &h)
  99. {
  100. h & data;
  101. h & values;
  102. }
  103. };
  104. class DLL_LINKAGE Statistic
  105. {
  106. static std::vector<const CGMine *> getMines(const CGameState * gs, const PlayerState * ps);
  107. public:
  108. static int getNumberOfArts(const PlayerState * ps);
  109. static si64 getArmyStrength(const PlayerState * ps, bool withTownGarrison = false);
  110. static int getIncome(const CGameState * gs, const PlayerState * ps);
  111. static float getMapExploredRatio(const CGameState * gs, PlayerColor player);
  112. static const CGHeroInstance * findBestHero(const CGameState * gs, const PlayerColor & color);
  113. static std::vector<std::vector<PlayerColor>> getRank(std::vector<std::pair<PlayerColor, si64>> stats);
  114. static int getObeliskVisited(const CGameState * gs, const TeamID & t);
  115. static float getObeliskVisitedRatio(const CGameState * gs, const TeamID & t);
  116. static std::map<EGameResID, int> getNumMines(const CGameState * gs, const PlayerState * ps);
  117. };
  118. VCMI_LIB_NAMESPACE_END