StealthUpdate.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: StealthUpdate.h //////////////////////////////////////////////////////////////////////////
  24. // Author: Kris Morness, May 2002
  25. // Desc: An update that checks for a status bit to stealth the owning object
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __STEALTH_UPDATE_H_
  29. #define __STEALTH_UPDATE_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/UpdateModule.h"
  32. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  33. class Thing;
  34. enum StealthLookType;
  35. enum EvaMessage;
  36. class FXList;
  37. enum
  38. {
  39. STEALTH_NOT_WHILE_ATTACKING = 0x00000001,
  40. STEALTH_NOT_WHILE_MOVING = 0x00000002,
  41. STEALTH_NOT_WHILE_USING_ABILITY = 0x00000004,
  42. STEALTH_NOT_WHILE_FIRING_PRIMARY = 0x00000008,
  43. STEALTH_NOT_WHILE_FIRING_SECONDARY = 0x00000010,
  44. STEALTH_NOT_WHILE_FIRING_TERTIARY = 0x00000020,
  45. STEALTH_ONLY_WITH_BLACK_MARKET = 0x00000040,
  46. STEALTH_NOT_WHILE_TAKING_DAMAGE = 0x00000080,
  47. STEALTH_NOT_WHILE_FIRING_WEAPON = (STEALTH_NOT_WHILE_FIRING_PRIMARY | STEALTH_NOT_WHILE_FIRING_SECONDARY | STEALTH_NOT_WHILE_FIRING_TERTIARY),
  48. STEALTH_NOT_WHILE_RIDERS_ATTACKING = 0x00000100,
  49. };
  50. #ifdef DEFINE_STEALTHLEVEL_NAMES
  51. static const char *TheStealthLevelNames[] =
  52. {
  53. "ATTACKING",
  54. "MOVING",
  55. "USING_ABILITY",
  56. "FIRING_PRIMARY",
  57. "FIRING_SECONDARY",
  58. "FIRING_TERTIARY",
  59. "NO_BLACK_MARKET",
  60. "TAKING_DAMAGE",
  61. "RIDERS_ATTACKING",
  62. NULL
  63. };
  64. #endif
  65. #define INVALID_OPACITY -1.0f
  66. //-------------------------------------------------------------------------------------------------
  67. class StealthUpdateModuleData : public UpdateModuleData
  68. {
  69. public:
  70. ObjectStatusMaskType m_hintDetectableStates;
  71. ObjectStatusMaskType m_requiredStatus;
  72. ObjectStatusMaskType m_forbiddenStatus;
  73. FXList *m_disguiseRevealFX;
  74. FXList *m_disguiseFX;
  75. Real m_stealthSpeed;
  76. Real m_friendlyOpacityMin;
  77. Real m_friendlyOpacityMax;
  78. Real m_revealDistanceFromTarget;
  79. UnsignedInt m_disguiseTransitionFrames;
  80. UnsignedInt m_disguiseRevealTransitionFrames;
  81. UnsignedInt m_pulseFrames;
  82. UnsignedInt m_stealthDelay;
  83. UnsignedInt m_stealthLevel;
  84. UnsignedInt m_blackMarketCheckFrames;
  85. EvaMessage m_enemyDetectionEvaEvent;
  86. EvaMessage m_ownDetectionEvaEvent;
  87. Bool m_innateStealth;
  88. Bool m_orderIdleEnemiesToAttackMeUponReveal;
  89. Bool m_teamDisguised;
  90. Bool m_useRiderStealth;
  91. Bool m_grantedBySpecialPower;
  92. StealthUpdateModuleData();
  93. static void buildFieldParse(MultiIniFieldParse& p);
  94. };
  95. //-------------------------------------------------------------------------------------------------
  96. class StealthUpdate : public UpdateModule
  97. {
  98. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( StealthUpdate, "StealthUpdate" )
  99. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( StealthUpdate, StealthUpdateModuleData );
  100. public:
  101. StealthUpdate( Thing *thing, const ModuleData* moduleData );
  102. // virtual destructor prototype provided by memory pool declaration
  103. virtual StealthUpdate* getStealth() { return this; }
  104. virtual UpdateSleepTime update();
  105. //Still gets called, even if held -ML
  106. virtual DisabledMaskType getDisabledTypesToProcess() const { return MAKE_DISABLED_MASK( DISABLED_HELD ); }
  107. // ??? ugh
  108. Bool isDisguised() const { return m_disguiseAsTemplate != NULL; }
  109. Int getDisguisedPlayerIndex() const { return m_disguiseAsPlayerIndex; }
  110. const ThingTemplate *getDisguisedTemplate() { return m_disguiseAsTemplate; }
  111. void markAsDetected( UnsignedInt numFrames = 0 );
  112. void disguiseAsObject( const Object *target ); //wrapper function for ease.
  113. Real getFriendlyOpacity() const;
  114. UnsignedInt getStealthDelay() const { return getStealthUpdateModuleData()->m_stealthDelay; }
  115. UnsignedInt getStealthLevel() const { return getStealthUpdateModuleData()->m_stealthLevel; }
  116. EvaMessage getEnemyDetectionEvaEvent() const { return getStealthUpdateModuleData()->m_enemyDetectionEvaEvent; }
  117. EvaMessage getOwnDetectionEvaEvent() const { return getStealthUpdateModuleData()->m_ownDetectionEvaEvent; }
  118. Bool getOrderIdleEnemiesToAttackMeUponReveal() const { return getStealthUpdateModuleData()->m_orderIdleEnemiesToAttackMeUponReveal; }
  119. Object* calcStealthOwner(); //Is it me that can stealth or is it my rider?
  120. Bool allowedToStealth( Object *stealthOwner ) const;
  121. void receiveGrant( Bool active = TRUE, UnsignedInt frames = 0 );
  122. Bool isGrantedBySpecialPower( void ) { return getStealthUpdateModuleData()->m_grantedBySpecialPower; }
  123. Bool isTemporaryGrant() { return m_framesGranted > 0; }
  124. protected:
  125. StealthLookType calcStealthedStatusForPlayer(const Object* obj, const Player* player);
  126. Bool canDisguise() const { return getStealthUpdateModuleData()->m_teamDisguised; }
  127. Real getRevealDistanceFromTarget() const { return getStealthUpdateModuleData()->m_revealDistanceFromTarget; }
  128. void hintDetectableWhileUnstealthed( void ) ;
  129. void changeVisualDisguise();
  130. UpdateSleepTime calcSleepTime() const;
  131. private:
  132. UnsignedInt m_stealthAllowedFrame;
  133. UnsignedInt m_detectionExpiresFrame;
  134. mutable UnsignedInt m_nextBlackMarketCheckFrame;
  135. Bool m_enabled;
  136. Real m_pulsePhaseRate;
  137. Real m_pulsePhase;
  138. //Disguise only members
  139. Int m_disguiseAsPlayerIndex; //The player team we are wanting to disguise as (might not actually be disguised yet).
  140. const ThingTemplate *m_disguiseAsTemplate; //The disguise template (might not actually be using it yet)
  141. UnsignedInt m_disguiseTransitionFrames; //How many frames are left before transition is complete.
  142. Bool m_disguiseHalfpointReached; //In the middle of the transition, we will switch drawables!
  143. Bool m_transitioningToDisguise; //Set when we are disguising -- clear when we're transitioning out of.
  144. Bool m_disguised; //We're disguised as far as other players are concerned.
  145. UnsignedInt m_framesGranted; //0 means forever... everything else is number of frames before stealth lost.
  146. // runtime xfer members (does not need saving)
  147. Bool m_xferRestoreDisguise; //Tells us we need to restore our disguise
  148. WeaponSetType m_requiresWeaponSetType;
  149. };
  150. #endif