GameStatistics.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. int numberDwellings;
  32. si64 armyStrength;
  33. si64 totalExperience;
  34. int income;
  35. float mapExploredRatio;
  36. float obeliskVisitedRatio;
  37. std::map<EGameResID, int> numMines;
  38. int score;
  39. int maxHeroLevel;
  40. int numBattlesNeutral;
  41. int numBattlesPlayer;
  42. int numWinBattlesNeutral;
  43. int numWinBattlesPlayer;
  44. int numHeroSurrendered;
  45. int numHeroEscaped;
  46. template <typename Handler> void serialize(Handler &h)
  47. {
  48. h & map;
  49. h & timestamp;
  50. h & day;
  51. h & player;
  52. h & team;
  53. h & isHuman;
  54. h & status;
  55. h & resources;
  56. h & numberHeroes;
  57. h & numberTowns;
  58. h & numberArtifacts;
  59. h & numberDwellings;
  60. h & armyStrength;
  61. h & totalExperience;
  62. h & income;
  63. h & mapExploredRatio;
  64. h & obeliskVisitedRatio;
  65. h & numMines;
  66. h & score;
  67. h & maxHeroLevel;
  68. h & numBattlesNeutral;
  69. h & numBattlesPlayer;
  70. h & numWinBattlesNeutral;
  71. h & numWinBattlesPlayer;
  72. h & numHeroSurrendered;
  73. h & numHeroEscaped;
  74. }
  75. };
  76. class DLL_LINKAGE StatisticDataSet
  77. {
  78. std::vector<StatisticDataSetEntry> data;
  79. public:
  80. void add(StatisticDataSetEntry entry);
  81. static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs);
  82. std::string toCsv();
  83. struct ValueStorage
  84. {
  85. std::map<PlayerColor, int> numBattlesNeutral;
  86. std::map<PlayerColor, int> numBattlesPlayer;
  87. std::map<PlayerColor, int> numWinBattlesNeutral;
  88. std::map<PlayerColor, int> numWinBattlesPlayer;
  89. std::map<PlayerColor, int> numHeroSurrendered;
  90. std::map<PlayerColor, int> numHeroEscaped;
  91. template <typename Handler> void serialize(Handler &h)
  92. {
  93. h & numBattlesNeutral;
  94. h & numBattlesPlayer;
  95. h & numWinBattlesNeutral;
  96. h & numWinBattlesPlayer;
  97. h & numHeroSurrendered;
  98. h & numHeroEscaped;
  99. }
  100. };
  101. ValueStorage values;
  102. template <typename Handler> void serialize(Handler &h)
  103. {
  104. h & data;
  105. h & values;
  106. }
  107. };
  108. class DLL_LINKAGE Statistic
  109. {
  110. static std::vector<const CGMine *> getMines(const CGameState * gs, const PlayerState * ps);
  111. public:
  112. static int getNumberOfArts(const PlayerState * ps);
  113. static si64 getArmyStrength(const PlayerState * ps, bool withTownGarrison = false);
  114. static si64 getTotalExperience(const PlayerState * ps);
  115. static int getIncome(const CGameState * gs, const PlayerState * ps);
  116. static float getMapExploredRatio(const CGameState * gs, PlayerColor player);
  117. static const CGHeroInstance * findBestHero(const CGameState * gs, const PlayerColor & color);
  118. static std::vector<std::vector<PlayerColor>> getRank(std::vector<std::pair<PlayerColor, si64>> stats);
  119. static int getObeliskVisited(const CGameState * gs, const TeamID & t);
  120. static float getObeliskVisitedRatio(const CGameState * gs, const TeamID & t);
  121. static std::map<EGameResID, int> getNumMines(const CGameState * gs, const PlayerState * ps);
  122. };
  123. VCMI_LIB_NAMESPACE_END