ScoreKeeper.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: ScoreKeeper.h /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Jun 2002
  34. //
  35. // Filename: ScoreKeeper.h
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: Header file for the scorekeeper class
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. #pragma once
  44. #ifndef __SCOREKEEPER_H_
  45. #define __SCOREKEEPER_H_
  46. //-----------------------------------------------------------------------------
  47. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  48. //-----------------------------------------------------------------------------
  49. //-----------------------------------------------------------------------------
  50. // USER INCLUDES //////////////////////////////////////////////////////////////
  51. //-----------------------------------------------------------------------------
  52. #include "Common/Snapshot.h"
  53. //-----------------------------------------------------------------------------
  54. // FORWARD REFERENCES /////////////////////////////////////////////////////////
  55. //-----------------------------------------------------------------------------
  56. class Object;
  57. class ThingTemplate;
  58. //-----------------------------------------------------------------------------
  59. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  60. //-----------------------------------------------------------------------------
  61. class ScoreKeeper : public Snapshot
  62. {
  63. public:
  64. ScoreKeeper( void );
  65. ~ScoreKeeper( void );
  66. void reset( Int playerIdx ); ///< Zero out the variables
  67. Int calculateScore( void ); ///< Performs the equation to calculate the score
  68. void addMoneySpent( Int money ); ///< Adds money to the amount spent
  69. void addMoneyEarned( Int money ); ///< Adds money to the earned amount
  70. void addObjectBuilt( const Object *o );
  71. void addObjectDestroyed( const Object *o );
  72. void addObjectLost( const Object *o );
  73. void addObjectCaptured( const Object *o );
  74. void removeObjectBuilt( const Object *o );
  75. Int getTotalMoneyEarned( void ) { return m_totalMoneyEarned; }
  76. Int getTotalMoneySpent( void ) { return m_totalMoneySpent; }
  77. Int getTotalUnitsDestroyed( void );
  78. Int getTotalUnitsBuilt( void ) { return m_totalUnitsBuilt; }
  79. Int getTotalUnitsLost( void ) { return m_totalUnitsLost; }
  80. Int getTotalBuildingsDestroyed( void );
  81. Int getTotalBuildingsBuilt( void ) { return m_totalBuildingsBuilt; }
  82. Int getTotalBuildingsLost( void ) { return m_totalBuildingsLost; }
  83. Int getTotalTechBuildingsCaptured( void ) { return m_totalTechBuildingsCaptured; }
  84. Int getTotalFactionBuildingsCaptured( void ) { return m_totalFactionBuildingsCaptured; }
  85. Int getTotalObjectsBuilt( const ThingTemplate *pTemplate ); // get a count of objects built matching a specific thing template
  86. // for battle honor calculation. done once at the end of each online game
  87. Int getTotalUnitsBuilt( KindOfMaskType validMask, KindOfMaskType invalidMask );
  88. protected:
  89. // snapshot methods
  90. virtual void crc( Xfer *xfer );
  91. virtual void xfer( Xfer *xfer );
  92. virtual void loadPostProcess( void );
  93. private:
  94. Int m_totalMoneyEarned; ///< The total money that was harvested, refined, received in crates
  95. Int m_totalMoneySpent; ///< The total money spent on units, buildings, repairs
  96. Int m_totalUnitsDestroyed[MAX_PLAYER_COUNT]; ///< The total number of enimies that we've killed
  97. Int m_totalUnitsBuilt; ///< The total number of units we've created (created meaning that we built from a building)
  98. Int m_totalUnitsLost; ///< The total number of our units lost
  99. Int m_totalBuildingsDestroyed[MAX_PLAYER_COUNT]; ///< The total number of Buildings we've destroyed
  100. Int m_totalBuildingsBuilt; ///< The total number of buildings we've constructed
  101. Int m_totalBuildingsLost; ///< The total number of our buildings lost
  102. Int m_totalTechBuildingsCaptured; ///< The total number of tech buildings captured
  103. Int m_totalFactionBuildingsCaptured; ///< The total number of faction buildings captured
  104. Int m_currentScore; ///< Based off the stats, this is the current score
  105. Int m_myPlayerIdx; ///< We need to not score kills on ourselves... so we need to know who we are
  106. typedef std::map<const ThingTemplate *, Int> ObjectCountMap;
  107. typedef ObjectCountMap::iterator ObjectCountMapIt;
  108. ObjectCountMap m_objectsBuilt; ///< How many and what kinds of objects did we build
  109. ObjectCountMap m_objectsDestroyed[MAX_PLAYER_COUNT]; ///< How many and what kinds and who's did we kill
  110. ObjectCountMap m_objectsLost; ///< how many and what kinds of objects did we loose
  111. ObjectCountMap m_objectsCaptured;
  112. void xferObjectCountMap( Xfer *xfer, ObjectCountMap *map );
  113. };
  114. //-----------------------------------------------------------------------------
  115. // INLINING ///////////////////////////////////////////////////////////////////
  116. //-----------------------------------------------------------------------------
  117. inline void ScoreKeeper::addMoneySpent( Int money ) { m_totalMoneySpent += money; }
  118. inline void ScoreKeeper::addMoneyEarned( Int money ) { m_totalMoneyEarned += money; }
  119. //-----------------------------------------------------------------------------
  120. // EXTERNALS //////////////////////////////////////////////////////////////////
  121. //-----------------------------------------------------------------------------
  122. #endif // __SCOREKEEPER_H_