GameStatistics.h 3.9 KB

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