Eva.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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: GameClient/Eva.h /////////////////////////////////////////////////////////////////////////
  24. // Author: John K. McDonald, Jr.
  25. // DO NOT DISTRIBUTE
  26. #pragma once
  27. #ifndef __EVA_H__
  28. #define __EVA_H__
  29. #include "Common/SubsystemInterface.h"
  30. #include "Common/AudioEventRTS.h"
  31. class Player;
  32. class INI;
  33. //------------------------------------------------------------------------------------ Eva Messages
  34. // Keep in sync with TheEvaMessageNames AND Eva::s_shouldPlayFuncs
  35. enum EvaMessage
  36. {
  37. EVA_Invalid = -1,
  38. EVA_FIRST = 0,
  39. EVA_LowPower = EVA_FIRST,
  40. EVA_InsufficientFunds,
  41. EVA_SuperweaponDetected_Own_ParticleCannon,
  42. EVA_SuperweaponDetected_Own_Nuke,
  43. EVA_SuperweaponDetected_Own_ScudStorm,
  44. EVA_SuperweaponDetected_Ally_ParticleCannon,
  45. EVA_SuperweaponDetected_Ally_Nuke,
  46. EVA_SuperweaponDetected_Ally_ScudStorm,
  47. EVA_SuperweaponDetected_Enemy_ParticleCannon,
  48. EVA_SuperweaponDetected_Enemy_Nuke,
  49. EVA_SuperweaponDetected_Enemy_ScudStorm,
  50. EVA_SuperweaponLaunched_Own_ParticleCannon,
  51. EVA_SuperweaponLaunched_Own_Nuke,
  52. EVA_SuperweaponLaunched_Own_ScudStorm,
  53. EVA_SuperweaponLaunched_Ally_ParticleCannon,
  54. EVA_SuperweaponLaunched_Ally_Nuke,
  55. EVA_SuperweaponLaunched_Ally_ScudStorm,
  56. EVA_SuperweaponLaunched_Enemy_ParticleCannon,
  57. EVA_SuperweaponLaunched_Enemy_Nuke,
  58. EVA_SuperweaponLaunched_Enemy_ScudStorm,
  59. EVA_SuperweaponReady_Own_ParticleCannon,
  60. EVA_SuperweaponReady_Own_Nuke,
  61. EVA_SuperweaponReady_Own_ScudStorm,
  62. EVA_SuperweaponReady_Ally_ParticleCannon,
  63. EVA_SuperweaponReady_Ally_Nuke,
  64. EVA_SuperweaponReady_Ally_ScudStorm,
  65. EVA_SuperweaponReady_Enemy_ParticleCannon,
  66. EVA_SuperweaponReady_Enemy_Nuke,
  67. EVA_SuperweaponReady_Enemy_ScudStorm,
  68. EVA_BuldingLost,
  69. EVA_BaseUnderAttack,
  70. EVA_AllyUnderAttack,
  71. EVA_BeaconDetected,
  72. EVA_EnemyBlackLotusDetected,
  73. EVA_EnemyJarmenKellDetected,
  74. EVA_EnemyColonelBurtonDetected,
  75. EVA_OwnBlackLotusDetected,
  76. EVA_OwnJarmenKellDetected,
  77. EVA_OwnColonelBurtonDetected,
  78. EVA_UnitLost,
  79. EVA_GeneralLevelUp,
  80. EVA_VehicleStolen,
  81. EVA_BuildingStolen,
  82. EVA_CashStolen,
  83. EVA_UpgradeComplete,
  84. EVA_BuildingBeingStolen,
  85. EVA_BuildingSabotaged,
  86. EVA_SuperweaponLaunched_Own_GPS_Scrambler,
  87. EVA_SuperweaponLaunched_Ally_GPS_Scrambler,
  88. EVA_SuperweaponLaunched_Enemy_GPS_Scrambler,
  89. EVA_SuperweaponLaunched_Own_Sneak_Attack,
  90. EVA_SuperweaponLaunched_Ally_Sneak_Attack,
  91. EVA_SuperweaponLaunched_Enemy_Sneak_Attack,
  92. EVA_COUNT,
  93. };
  94. extern const char *TheEvaMessageNames[];
  95. //------------------------------------------------------------------------------------ EvaCheckInfo
  96. struct EvaSideSounds
  97. {
  98. AsciiString m_side;
  99. std::vector<AsciiString> m_soundNames;
  100. static const FieldParse s_evaSideSounds[]; ///< the parse table for INI definition
  101. const FieldParse *getFieldParse( void ) const { return s_evaSideSounds; }
  102. };
  103. //------------------------------------------------------------------------------------ EvaCheckInfo
  104. class EvaCheckInfo : public MemoryPoolObject
  105. {
  106. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(EvaCheckInfo, "EvaCheckInfo")
  107. public:
  108. EvaMessage m_message;
  109. UnsignedInt m_framesBetweenChecks;
  110. UnsignedInt m_framesToExpire;
  111. UnsignedInt m_priority; // higher priority is more important, and will be played in preference to lower preference
  112. std::vector<EvaSideSounds> m_evaSideSounds;
  113. EvaCheckInfo();
  114. static const FieldParse s_evaEventInfo[]; ///< the parse table for INI definition
  115. const FieldParse *getFieldParse( void ) const { return s_evaEventInfo; }
  116. };
  117. EMPTY_DTOR(EvaCheckInfo)
  118. //---------------------------------------------------------------------------------------- EvaCheck
  119. struct EvaCheck
  120. {
  121. enum { TRIGGEREDON_NOT = (UnsignedInt)-1 };
  122. enum { NEXT_CHECK_NOW = 0 };
  123. const EvaCheckInfo *m_evaInfo;
  124. UnsignedInt m_triggeredOnFrame;
  125. UnsignedInt m_timeForNextCheck;
  126. Bool m_alreadyPlayed;
  127. EvaCheck();
  128. };
  129. //-------------------------------------------------------------------------------- ShouldPlayStruct
  130. typedef Bool (*ShouldPlayFunc)( Player *localPlayer );
  131. //--------------------------------------------------------------------------------------------- Eva
  132. class Eva : public SubsystemInterface
  133. {
  134. private:
  135. static const ShouldPlayFunc s_shouldPlayFuncs[];
  136. typedef std::vector<EvaCheckInfo *> EvaCheckInfoPtrVec;
  137. typedef EvaCheckInfoPtrVec::iterator EvaCheckInfoPtrVecIt;
  138. EvaCheckInfoPtrVec m_allCheckInfos;
  139. typedef std::vector<EvaCheck> EvaCheckVec;
  140. typedef EvaCheckVec::iterator EvaCheckVecIt;
  141. // This list contains things that either want to play,
  142. // or have played and are waiting till they are allowed to check again to play.
  143. EvaCheckVec m_checks;
  144. // This is the one speech we're allowed to be playing. If its playing, it always has priority
  145. AudioEventRTS m_evaSpeech;
  146. Player *m_localPlayer;
  147. // Variables for condition checks go here.
  148. Int m_previousBuildingCount;
  149. Int m_previousUnitCount;
  150. mutable EvaMessage m_messageBeingTested; // Used by the generic hooks so they can figure out which flag to test.
  151. Bool m_shouldPlay[EVA_COUNT]; // These aren't all used, but some of them are.
  152. Bool m_enabled;
  153. public:
  154. Eva();
  155. virtual ~Eva();
  156. public: // From SubsystemInterface
  157. virtual void init();
  158. virtual void reset();
  159. virtual void update();
  160. static EvaMessage nameToMessage(const AsciiString& name);
  161. static AsciiString messageToName(EvaMessage message);
  162. EvaCheckInfo *newEvaCheckInfo(AsciiString name);
  163. const EvaCheckInfo *getEvaCheckInfo(AsciiString name);
  164. void setShouldPlay(EvaMessage messageToPlay);
  165. void setEvaEnabled(Bool enabled);
  166. // Parse EvaMessage enum name in INI
  167. static void parseEvaMessageFromIni( INI * ini, void *instance, void *store, const void* userData );
  168. protected: // Note: These are all protected. They should *NEVER* be made public. They are for internal use only
  169. Bool isTimeForCheck(EvaMessage messageToTest, UnsignedInt currentFrame) const;
  170. Bool messageShouldPlay(EvaMessage messageToTest, UnsignedInt currentFrame) const;
  171. // As soon as you want the logic of these to be public, make a logical representation and have these call that instead.
  172. static Bool shouldPlayLowPower( Player *localPlayer );
  173. static Bool shouldPlayGenericHandler( Player * );
  174. void playMessage(EvaMessage messageToTest, UnsignedInt currentFrame);
  175. void processPlayingMessages(UnsignedInt currentFrame);
  176. };
  177. extern Eva *TheEva;
  178. #endif /* __EVA_H__ */