BridgeBehavior.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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: BridgeBehavior.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, July 2002
  25. // Desc: Behavior module for bridges
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __BRIDGE_BEHAVIOR_H_
  29. #define __BRIDGE_BEHAVIOR_H_
  30. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/AudioEventRTS.h"
  32. #include "GameClient/TerrainRoads.h"
  33. #include "GameLogic/Module/BehaviorModule.h"
  34. #include "GameLogic/Module/DamageModule.h"
  35. #include "GameLogic/Module/Diemodule.h"
  36. #include "GameLogic/Module/UpdateModule.h"
  37. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  38. enum BridgeTowerType;
  39. class FXList;
  40. class ObjectCreationList;
  41. class Bridge;
  42. class BridgeInfo;
  43. // TYPES //////////////////////////////////////////////////////////////////////////////////////////
  44. // ------------------------------------------------------------------------------------------------
  45. struct TimeAndLocationInfo
  46. {
  47. UnsignedInt delay; ///< how long to wait to execute this
  48. AsciiString boneName; ///< which bone to execute at
  49. };
  50. // ------------------------------------------------------------------------------------------------
  51. struct BridgeFXInfo
  52. {
  53. const FXList *fx;
  54. TimeAndLocationInfo timeAndLocationInfo;
  55. };
  56. // ------------------------------------------------------------------------------------------------
  57. struct BridgeOCLInfo
  58. {
  59. const ObjectCreationList *ocl;
  60. TimeAndLocationInfo timeAndLocationInfo;
  61. };
  62. // ------------------------------------------------------------------------------------------------
  63. typedef std::list< BridgeFXInfo > BridgeFXList;
  64. typedef std::list< BridgeOCLInfo > BridgeOCLList;
  65. typedef std::list< ObjectID > ObjectIDList;
  66. typedef ObjectIDList::iterator ObjectIDListIterator;
  67. // ------------------------------------------------------------------------------------------------
  68. // ------------------------------------------------------------------------------------------------
  69. class BridgeBehaviorInterface
  70. {
  71. public:
  72. virtual void setTower( BridgeTowerType towerType, Object *tower ) = 0;
  73. virtual ObjectID getTowerID( BridgeTowerType towerType ) = 0;
  74. virtual void createScaffolding( void ) = 0;
  75. virtual void removeScaffolding( void ) = 0;
  76. virtual Bool isScaffoldInMotion( void ) = 0;
  77. virtual Bool isScaffoldPresent( void ) = 0;
  78. };
  79. // ------------------------------------------------------------------------------------------------
  80. // ------------------------------------------------------------------------------------------------
  81. class BridgeBehaviorModuleData : public BehaviorModuleData
  82. {
  83. public:
  84. BridgeBehaviorModuleData( void );
  85. ~BridgeBehaviorModuleData( void );
  86. static void buildFieldParse( MultiIniFieldParse &p );
  87. Real m_lateralScaffoldSpeed;
  88. Real m_verticalScaffoldSpeed;
  89. BridgeFXList m_fx; ///< list of FX lists to execute
  90. BridgeOCLList m_ocl; ///< list of OCL to execute
  91. static void parseFX( INI *ini, void *instance, void *store, const void* userData );
  92. static void parseOCL( INI *ini, void *instance, void *store, const void* userData );
  93. };
  94. // ------------------------------------------------------------------------------------------------
  95. // ------------------------------------------------------------------------------------------------
  96. class BridgeBehavior : public UpdateModule,
  97. public BridgeBehaviorInterface,
  98. public DamageModuleInterface,
  99. public DieModuleInterface
  100. {
  101. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( BridgeBehavior, BridgeBehaviorModuleData );
  102. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( BridgeBehavior, "BridgeBehavior" )
  103. public:
  104. BridgeBehavior( Thing *thing, const ModuleData* moduleData );
  105. // virtual destructor prototype provided by memory pool declaration
  106. // module methods
  107. static Int getInterfaceMask( void ) { return (MODULEINTERFACE_DAMAGE) |
  108. (MODULEINTERFACE_DIE) |
  109. (MODULEINTERFACE_UPDATE); }
  110. virtual BridgeBehaviorInterface* getBridgeBehaviorInterface( void ) { return this; }
  111. virtual void onDelete( void );
  112. // Damage methods
  113. virtual DamageModuleInterface* getDamage( void ) { return this; }
  114. virtual void onDamage( DamageInfo *damageInfo );
  115. virtual void onHealing( DamageInfo *damageInfo );
  116. virtual void onBodyDamageStateChange( const DamageInfo* damageInfo,
  117. BodyDamageType oldState,
  118. BodyDamageType newState );
  119. // Die methods
  120. virtual DieModuleInterface* getDie( void ) { return this; }
  121. virtual void onDie( const DamageInfo *damageInfo );
  122. // Update methods
  123. virtual UpdateModuleInterface *getUpdate( void ) { return this; }
  124. virtual UpdateSleepTime update( void );
  125. // our own methods
  126. static BridgeBehaviorInterface *getBridgeBehaviorInterfaceFromObject( Object *obj );
  127. virtual void setTower( BridgeTowerType towerType, Object *tower ); ///< connect tower to us
  128. virtual ObjectID getTowerID( BridgeTowerType towerType ); ///< retrive one of our towers
  129. virtual void createScaffolding( void ); ///< create scaffolding around bridge
  130. virtual void removeScaffolding( void ); ///< remove scaffolding around bridge
  131. virtual Bool isScaffoldInMotion( void ); ///< is scaffold in motion
  132. virtual Bool isScaffoldPresent( void ) { return m_scaffoldPresent; }
  133. protected:
  134. void resolveFX( void );
  135. void handleObjectsOnBridgeOnDie( void );
  136. void doAreaEffects( TerrainRoadType *bridgeTemplate, Bridge *bridge,
  137. const ObjectCreationList *ocl, const FXList *fx );
  138. void setScaffoldData( Object *obj,
  139. Real *angle,
  140. Real *sunkenHeight,
  141. const Coord3D *riseToPos,
  142. const Coord3D *buildPos,
  143. const Coord3D *bridgeCenter );
  144. void getRandomSurfacePosition( TerrainRoadType *bridgeTemplate,
  145. const BridgeInfo *bridgeInfo,
  146. Coord3D *pos );
  147. ObjectID m_towerID[ BRIDGE_MAX_TOWERS ]; ///< the towers that are a part of us
  148. // got damaged fx stuff
  149. const ObjectCreationList *m_damageToOCL[ BODYDAMAGETYPE_COUNT ][ MAX_BRIDGE_BODY_FX ];
  150. const FXList *m_damageToFX[ BODYDAMAGETYPE_COUNT ][ MAX_BRIDGE_BODY_FX ];
  151. AudioEventRTS m_damageToSound[ BODYDAMAGETYPE_COUNT ];
  152. // got repaired fx stuff
  153. const ObjectCreationList *m_repairToOCL[ BODYDAMAGETYPE_COUNT ][ MAX_BRIDGE_BODY_FX ];
  154. const FXList *m_repairToFX[ BODYDAMAGETYPE_COUNT ][ MAX_BRIDGE_BODY_FX ];
  155. AudioEventRTS m_repairToSound[ BODYDAMAGETYPE_COUNT ];
  156. Bool m_fxResolved; ///< TRUE until we've loaded our fx pointers and sounds
  157. Bool m_scaffoldPresent; ///< TRUE when we have repair scaffolding visible
  158. ObjectIDList m_scaffoldObjectIDList; ///< list of scaffold object IDs
  159. UnsignedInt m_deathFrame; ///< frame we died on
  160. };
  161. #endif // end __BRIDGE_DAMAGE_H_