PlayerList.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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: PlayerList.h ////////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: PlayerList.h
  36. //
  37. // Created: Steven Johnson, October 2001
  38. //
  39. // Desc: @todo
  40. //
  41. //-----------------------------------------------------------------------------
  42. #pragma once
  43. #ifndef _PLAYERLIST_H_
  44. #define _PLAYERLIST_H_
  45. #include "Common/SubsystemInterface.h"
  46. #include "Common/GameCommon.h"
  47. #include "Common/NameKeyGenerator.h"
  48. #include "Common/Snapshot.h"
  49. class DataChunkInput;
  50. struct DataChunkInfo;
  51. class DataChunkOutput;
  52. class Player;
  53. class Team;
  54. class TeamFactory;
  55. //-------------------------------------------------------------------------------------------------
  56. enum AllowPlayerRelationship
  57. {
  58. ALLOW_SAME_PLAYER = 0x01, ///< allow only objects of the same player as m_obj
  59. ALLOW_ALLIES = 0x02, ///< allow objects that m_obj considers allies
  60. ALLOW_ENEMIES = 0x04, ///< allow objects that m_obj considers enemy
  61. ALLOW_NEUTRAL = 0x08 ///< allow objects that m_obj considers neutral
  62. };
  63. //-------------------------------------------------------------------------------------------------
  64. /**
  65. This is a singleton class that maintains the list of Players.
  66. */
  67. class PlayerList : public SubsystemInterface,
  68. public Snapshot
  69. {
  70. public:
  71. PlayerList();
  72. ~PlayerList();
  73. // subsystem methods
  74. virtual void init( void );
  75. virtual void reset( void );
  76. virtual void update( void );
  77. virtual void newGame( void ); // called during GameLogic::startNewGame()
  78. virtual void newMap( void ); // Called after a new map is loaded.
  79. void teamAboutToBeDeleted(Team* team);
  80. /**
  81. return the total number of players (including the neutral player).
  82. */
  83. inline Int getPlayerCount() { return m_playerCount; }
  84. /**
  85. return the nth player. Note that players are in an arbitrary order.
  86. you should generally only use this if you want to iterate thru
  87. all players, NOT to get a specific player!
  88. */
  89. Player *getNthPlayer(Int i);
  90. /**
  91. return the "neutral" Player. there is always a player that is "neutral" wrt
  92. all other players (this is so that everything can be associated with a nonnull
  93. Player, to simplify the universe). This will never return null.
  94. */
  95. Player *getNeutralPlayer() { DEBUG_ASSERTCRASH(m_players[0] != NULL, ("null neutral")); return m_players[0]; }
  96. /**
  97. return the Player with the given internal name, or null if none found.
  98. */
  99. Player *findPlayerWithNameKey(NameKeyType key);
  100. /**
  101. Return the "local" player (ie, the human playing the game).
  102. This will never return null.
  103. */
  104. inline Player *getLocalPlayer() { DEBUG_ASSERTCRASH(m_local != NULL, ("null m_local")); return m_local; }
  105. /**
  106. Set the local player. You cannot set it to null; if you pass null, you'll
  107. end up setting the local player to be the neutral player.
  108. */
  109. void setLocalPlayer(Player *player);
  110. /**
  111. Return the player matching the player mask
  112. */
  113. Player *getPlayerFromMask( PlayerMaskType mask );
  114. /**
  115. Get each player in numerical order that this mask represents.
  116. Note that maskToAdjust will be adjusted by removing the associated player's mask from it.
  117. */
  118. Player *getEachPlayerFromMask( PlayerMaskType& maskToAdjust );
  119. Team *validateTeam( AsciiString owner );
  120. /**
  121. a convenience routine to quickly clear the entered/exited flags on all teams.
  122. */
  123. void updateTeamStates(void);
  124. /**
  125. a convenience routine to return the players who srcPlayer considers to have one of the
  126. relationships specified in allowedRelationships. Note that allowedRelationships should be
  127. a bitwise OR of AllowPlayerRelationship flags.
  128. */
  129. PlayerMaskType getPlayersWithRelationship( Int srcPlayerIndex, UnsignedInt allowedRelationships );
  130. protected:
  131. // snapshot methods
  132. virtual void crc( Xfer *xfer );
  133. virtual void xfer( Xfer *xfer );
  134. virtual void loadPostProcess( void );
  135. private:
  136. Player *m_local;
  137. Int m_playerCount;
  138. Player *m_players[MAX_PLAYER_COUNT];
  139. };
  140. // ----------------------------------------------------------------------------------------------
  141. extern PlayerList *ThePlayerList; ///< singleton instance of PlayerList
  142. #endif // _PLAYERLIST_H_