Eva.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. ** Command & Conquer Generals(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. //------------------------------------------------------------------------------------ Eva Messages
  33. // Keep in sync with TheEvaMessageNames AND Eva::s_shouldPlayFuncs
  34. enum EvaMessage
  35. {
  36. EVA_FIRST = 0,
  37. EVA_LowPower = EVA_FIRST,
  38. EVA_InsufficientFunds,
  39. EVA_SuperweaponDetected_ParticleCannon,
  40. EVA_SuperweaponDetected_Nuke,
  41. EVA_SuperweaponDetected_ScudStorm,
  42. EVA_SuperweaponLaunched_ParticleCannon,
  43. EVA_SuperweaponLaunched_Nuke,
  44. EVA_SuperweaponLaunched_ScudStorm,
  45. EVA_BuldingLost,
  46. EVA_BaseUnderAttack,
  47. EVA_AllyUnderAttack,
  48. EVA_BeaconDetected,
  49. EVA_UnitLost,
  50. EVA_GeneralLevelUp,
  51. EVA_VehicleStolen,
  52. EVA_BuildingStolen,
  53. EVA_CashStolen,
  54. EVA_UpgradeComplete,
  55. EVA_BuildingBeingStolen,
  56. EVA_COUNT,
  57. };
  58. extern const char *TheEvaMessageNames[];
  59. //------------------------------------------------------------------------------------ EvaCheckInfo
  60. struct EvaSideSounds
  61. {
  62. AsciiString m_side;
  63. std::vector<AsciiString> m_soundNames;
  64. static const FieldParse s_evaSideSounds[]; ///< the parse table for INI definition
  65. const FieldParse *getFieldParse( void ) const { return s_evaSideSounds; }
  66. };
  67. //------------------------------------------------------------------------------------ EvaCheckInfo
  68. class EvaCheckInfo : public MemoryPoolObject
  69. {
  70. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(EvaCheckInfo, "EvaCheckInfo")
  71. public:
  72. EvaMessage m_message;
  73. UnsignedInt m_framesBetweenChecks;
  74. UnsignedInt m_framesToExpire;
  75. UnsignedInt m_priority; // higher priority is more important, and will be played in preference to lower preference
  76. std::vector<EvaSideSounds> m_evaSideSounds;
  77. EvaCheckInfo();
  78. static const FieldParse s_evaEventInfo[]; ///< the parse table for INI definition
  79. const FieldParse *getFieldParse( void ) const { return s_evaEventInfo; }
  80. };
  81. EMPTY_DTOR(EvaCheckInfo)
  82. //---------------------------------------------------------------------------------------- EvaCheck
  83. struct EvaCheck
  84. {
  85. enum { TRIGGEREDON_NOT = (UnsignedInt)-1 };
  86. enum { NEXT_CHECK_NOW = 0 };
  87. const EvaCheckInfo *m_evaInfo;
  88. UnsignedInt m_triggeredOnFrame;
  89. UnsignedInt m_timeForNextCheck;
  90. Bool m_alreadyPlayed;
  91. EvaCheck();
  92. };
  93. //-------------------------------------------------------------------------------- ShouldPlayStruct
  94. typedef Bool (*ShouldPlayFunc)( Player *localPlayer );
  95. //--------------------------------------------------------------------------------------------- Eva
  96. class Eva : public SubsystemInterface
  97. {
  98. private:
  99. static const ShouldPlayFunc s_shouldPlayFuncs[];
  100. typedef std::vector<EvaCheckInfo *> EvaCheckInfoPtrVec;
  101. typedef EvaCheckInfoPtrVec::iterator EvaCheckInfoPtrVecIt;
  102. EvaCheckInfoPtrVec m_allCheckInfos;
  103. typedef std::vector<EvaCheck> EvaCheckVec;
  104. typedef EvaCheckVec::iterator EvaCheckVecIt;
  105. // This list contains things that either want to play,
  106. // or have played and are waiting till they are allowed to check again to play.
  107. EvaCheckVec m_checks;
  108. // This is the one speech we're allowed to be playing. If its playing, it always has priority
  109. AudioEventRTS m_evaSpeech;
  110. Player *m_localPlayer;
  111. // Variables for condition checks go here.
  112. Int m_previousBuildingCount;
  113. Int m_previousUnitCount;
  114. mutable EvaMessage m_messageBeingTested; // Used by the generic hooks so they can figure out which flag to test.
  115. Bool m_shouldPlay[EVA_COUNT]; // These aren't all used, but some of them are.
  116. Bool m_enabled;
  117. public:
  118. Eva();
  119. virtual ~Eva();
  120. public: // From SubsystemInterface
  121. virtual void init();
  122. virtual void reset();
  123. virtual void update();
  124. static EvaMessage nameToMessage(const AsciiString& name);
  125. static AsciiString messageToName(EvaMessage message);
  126. EvaCheckInfo *newEvaCheckInfo(AsciiString name);
  127. const EvaCheckInfo *getEvaCheckInfo(AsciiString name);
  128. void setShouldPlay(EvaMessage messageToPlay);
  129. void setEvaEnabled(Bool enabled);
  130. protected: // Note: These are all protected. They should *NEVER* be made public. They are for internal use only
  131. Bool isTimeForCheck(EvaMessage messageToTest, UnsignedInt currentFrame) const;
  132. Bool messageShouldPlay(EvaMessage messageToTest, UnsignedInt currentFrame) const;
  133. // As soon as you want the logic of these to be public, make a logical representation and have these call that instead.
  134. static Bool shouldPlayLowPower( Player *localPlayer );
  135. static Bool shouldPlayGenericHandler( Player * );
  136. void playMessage(EvaMessage messageToTest, UnsignedInt currentFrame);
  137. void processPlayingMessages(UnsignedInt currentFrame);
  138. };
  139. extern Eva *TheEva;
  140. #endif /* __EVA_H__ */