BehaviorModule.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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: BehaviorModule.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson
  25. // Desc:
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __BehaviorModule_H_
  29. #define __BehaviorModule_H_
  30. #include "Common/GameType.h"
  31. #include "Common/Module.h"
  32. //-------------------------------------------------------------------------------------------------
  33. class Team;
  34. class ThingTemplate;
  35. //-------------------------------------------------------------------------------------------------
  36. class BodyModuleInterface;
  37. class CollideModuleInterface;
  38. class ContainModuleInterface;
  39. class CreateModuleInterface;
  40. class DamageModuleInterface;
  41. class DestroyModuleInterface;
  42. class DieModuleInterface;
  43. class SpecialPowerModuleInterface;
  44. class UpdateModuleInterface;
  45. class UpgradeModuleInterface;
  46. //-------------------------------------------------------------------------------------------------
  47. class ParkingPlaceBehaviorInterface;
  48. class RebuildHoleBehaviorInterface;
  49. class BridgeBehaviorInterface;
  50. class BridgeTowerBehaviorInterface;
  51. class BridgeScaffoldBehaviorInterface;
  52. class OverchargeBehaviorInterface;
  53. class TransportPassengerInterface;
  54. class CaveInterface;
  55. class LandMineInterface;
  56. class ProjectileUpdateInterface;
  57. class AIUpdateInterface;
  58. class ExitInterface;
  59. class DockUpdateInterface;
  60. class RailedTransportDockUpdateInterface;
  61. class SpecialPowerUpdateInterface;
  62. class SlavedUpdateInterface;
  63. class SpawnBehaviorInterface;
  64. class CountermeasuresBehaviorInterface;
  65. class SlowDeathBehaviorInterface;
  66. class PowerPlantUpdateInterface;
  67. class ProductionUpdateInterface;
  68. class HordeUpdateInterface;
  69. class SpecialPowerTemplate;
  70. class WeaponTemplate;
  71. class DamageInfo;
  72. class ParticleSystemTemplate;
  73. class StealthUpdate;
  74. class SpyVisionUpdate;
  75. //-------------------------------------------------------------------------------------------------
  76. class BehaviorModuleData : public ModuleData
  77. {
  78. public:
  79. BehaviorModuleData()
  80. {
  81. }
  82. static void buildFieldParse(MultiIniFieldParse& p)
  83. {
  84. ModuleData::buildFieldParse(p);
  85. }
  86. };
  87. //-------------------------------------------------------------------------------------------------
  88. class BehaviorModuleInterface
  89. {
  90. public:
  91. virtual BodyModuleInterface* getBody() = 0;
  92. virtual CollideModuleInterface* getCollide() = 0;
  93. virtual ContainModuleInterface* getContain() = 0;
  94. virtual CreateModuleInterface* getCreate() = 0;
  95. virtual DamageModuleInterface* getDamage() = 0;
  96. virtual DestroyModuleInterface* getDestroy() = 0;
  97. virtual DieModuleInterface* getDie() = 0;
  98. virtual SpecialPowerModuleInterface* getSpecialPower() = 0;
  99. virtual UpdateModuleInterface* getUpdate() = 0;
  100. virtual UpgradeModuleInterface* getUpgrade() = 0;
  101. // interface acquisition
  102. virtual ParkingPlaceBehaviorInterface* getParkingPlaceBehaviorInterface() = 0;
  103. virtual RebuildHoleBehaviorInterface* getRebuildHoleBehaviorInterface() = 0;
  104. virtual BridgeBehaviorInterface* getBridgeBehaviorInterface() = 0;
  105. virtual BridgeTowerBehaviorInterface* getBridgeTowerBehaviorInterface() = 0;
  106. virtual BridgeScaffoldBehaviorInterface* getBridgeScaffoldBehaviorInterface() = 0;
  107. virtual OverchargeBehaviorInterface* getOverchargeBehaviorInterface() = 0;
  108. virtual TransportPassengerInterface* getTransportPassengerInterface() = 0;
  109. virtual CaveInterface* getCaveInterface() = 0;
  110. virtual LandMineInterface* getLandMineInterface() = 0;
  111. virtual DieModuleInterface* getEjectPilotDieInterface() = 0;
  112. // move from UpdateModuleInterface (srj)
  113. virtual ProjectileUpdateInterface* getProjectileUpdateInterface() = 0;
  114. virtual AIUpdateInterface* getAIUpdateInterface() = 0;
  115. virtual ExitInterface* getUpdateExitInterface() = 0;
  116. virtual DockUpdateInterface* getDockUpdateInterface() = 0;
  117. virtual RailedTransportDockUpdateInterface *getRailedTransportDockUpdateInterface( void ) = 0;
  118. virtual SlowDeathBehaviorInterface* getSlowDeathBehaviorInterface() = 0;
  119. virtual SpecialPowerUpdateInterface* getSpecialPowerUpdateInterface() = 0;
  120. virtual SlavedUpdateInterface* getSlavedUpdateInterface() = 0;
  121. virtual ProductionUpdateInterface* getProductionUpdateInterface() = 0;
  122. virtual HordeUpdateInterface* getHordeUpdateInterface() = 0;
  123. virtual PowerPlantUpdateInterface* getPowerPlantUpdateInterface() = 0;
  124. virtual SpawnBehaviorInterface* getSpawnBehaviorInterface() = 0;
  125. virtual CountermeasuresBehaviorInterface* getCountermeasuresBehaviorInterface() = 0;
  126. virtual const CountermeasuresBehaviorInterface* getCountermeasuresBehaviorInterface() const = 0;
  127. };
  128. //-------------------------------------------------------------------------------------------------
  129. class BehaviorModule : public ObjectModule, public BehaviorModuleInterface
  130. {
  131. MEMORY_POOL_GLUE_ABC( BehaviorModule )
  132. public:
  133. BehaviorModule( Thing *thing, const ModuleData* moduleData );
  134. // virtual destructor prototype defined by MemoryPoolObject
  135. static Int getInterfaceMask() { return 0; }
  136. static ModuleType getModuleType() { return MODULETYPE_BEHAVIOR; }
  137. virtual BodyModuleInterface* getBody() { return NULL; }
  138. virtual CollideModuleInterface* getCollide() { return NULL; }
  139. virtual ContainModuleInterface* getContain() { return NULL; }
  140. virtual CreateModuleInterface* getCreate() { return NULL; }
  141. virtual DamageModuleInterface* getDamage() { return NULL; }
  142. virtual DestroyModuleInterface* getDestroy() { return NULL; }
  143. virtual DieModuleInterface* getDie() { return NULL; }
  144. virtual SpecialPowerModuleInterface* getSpecialPower() { return NULL; }
  145. virtual UpdateModuleInterface* getUpdate() { return NULL; }
  146. virtual UpgradeModuleInterface* getUpgrade() { return NULL; }
  147. virtual StealthUpdate* getStealth() { return NULL; }
  148. virtual SpyVisionUpdate* getSpyVisionUpdate() { return NULL; }
  149. virtual ParkingPlaceBehaviorInterface* getParkingPlaceBehaviorInterface() { return NULL; }
  150. virtual RebuildHoleBehaviorInterface* getRebuildHoleBehaviorInterface() { return NULL; }
  151. virtual BridgeBehaviorInterface* getBridgeBehaviorInterface() { return NULL; }
  152. virtual BridgeTowerBehaviorInterface* getBridgeTowerBehaviorInterface() { return NULL; }
  153. virtual BridgeScaffoldBehaviorInterface* getBridgeScaffoldBehaviorInterface() { return NULL; }
  154. virtual OverchargeBehaviorInterface* getOverchargeBehaviorInterface() { return NULL; }
  155. virtual TransportPassengerInterface* getTransportPassengerInterface() { return NULL; }
  156. virtual CaveInterface* getCaveInterface() { return NULL; }
  157. virtual LandMineInterface* getLandMineInterface() { return NULL; }
  158. virtual DieModuleInterface* getEjectPilotDieInterface() { return NULL; }
  159. // interface acquisition (moved from UpdateModule)
  160. virtual ProjectileUpdateInterface* getProjectileUpdateInterface() { return NULL; }
  161. virtual AIUpdateInterface* getAIUpdateInterface() { return NULL; }
  162. virtual ExitInterface* getUpdateExitInterface() { return NULL; }
  163. virtual DockUpdateInterface* getDockUpdateInterface() { return NULL; }
  164. virtual RailedTransportDockUpdateInterface *getRailedTransportDockUpdateInterface( void ) { return NULL; }
  165. virtual SlowDeathBehaviorInterface* getSlowDeathBehaviorInterface() { return NULL; }
  166. virtual SpecialPowerUpdateInterface* getSpecialPowerUpdateInterface() { return NULL; }
  167. virtual SlavedUpdateInterface* getSlavedUpdateInterface() { return NULL; }
  168. virtual ProductionUpdateInterface* getProductionUpdateInterface() { return NULL; }
  169. virtual HordeUpdateInterface* getHordeUpdateInterface() { return NULL; }
  170. virtual PowerPlantUpdateInterface* getPowerPlantUpdateInterface() { return NULL; }
  171. virtual SpawnBehaviorInterface* getSpawnBehaviorInterface() { return NULL; }
  172. virtual CountermeasuresBehaviorInterface* getCountermeasuresBehaviorInterface() { return NULL; }
  173. virtual const CountermeasuresBehaviorInterface* getCountermeasuresBehaviorInterface() const { return NULL; }
  174. protected:
  175. // snapshot methods
  176. virtual void crc( Xfer *xfer );
  177. virtual void xfer( Xfer *xfer );
  178. virtual void loadPostProcess( void );
  179. };
  180. inline BehaviorModule::BehaviorModule( Thing *thing, const ModuleData* moduleData ) : ObjectModule( thing, moduleData ) { }
  181. inline BehaviorModule::~BehaviorModule() { }
  182. enum RunwayReservationType
  183. {
  184. RESERVATION_TAKEOFF,
  185. RESERVATION_LANDING,
  186. };
  187. //-------------------------------------------------------------------------------------------------
  188. class ParkingPlaceBehaviorInterface
  189. {
  190. public:
  191. struct PPInfo
  192. {
  193. Coord3D parkingSpace;
  194. Real parkingOrientation;
  195. Coord3D runwayPrep;
  196. Coord3D runwayStart;
  197. Coord3D runwayEnd;
  198. Coord3D runwayExit;
  199. Coord3D runwayLandingStart;
  200. Coord3D runwayLandingEnd;
  201. Coord3D runwayApproach;
  202. Coord3D hangarInternal;
  203. Real runwayTakeoffDist;
  204. Real hangarInternalOrient;
  205. };
  206. virtual Bool shouldReserveDoorWhenQueued(const ThingTemplate* thing) const = 0;
  207. virtual Bool hasAvailableSpaceFor(const ThingTemplate* thing) const = 0;
  208. virtual Bool hasReservedSpace(ObjectID id) const = 0;
  209. virtual Int getSpaceIndex( ObjectID id ) const = 0;
  210. virtual Bool reserveSpace(ObjectID id, Real parkingOffset, PPInfo* info) = 0;
  211. virtual void releaseSpace(ObjectID id) = 0;
  212. virtual Bool reserveRunway(ObjectID id, Bool forLanding) = 0;
  213. virtual void calcPPInfo( ObjectID id, PPInfo *info ) = 0;
  214. virtual void releaseRunway(ObjectID id) = 0;
  215. virtual Int getRunwayCount() const = 0;
  216. virtual ObjectID getRunwayReservation( Int r, RunwayReservationType type = RESERVATION_TAKEOFF ) = 0;
  217. virtual void transferRunwayReservationToNextInLineForTakeoff(ObjectID id) = 0;
  218. virtual Real getApproachHeight() const = 0;
  219. virtual Real getLandingDeckHeightOffset() const = 0;
  220. virtual void setHealee(Object* healee, Bool add) = 0;
  221. virtual void killAllParkedUnits() = 0;
  222. virtual void defectAllParkedUnits(Team* newTeam, UnsignedInt detectionTime) = 0;
  223. virtual Bool calcBestParkingAssignment( ObjectID id, Coord3D *pos, Int *oldIndex = NULL, Int *newIndex = NULL ) = 0;
  224. virtual const std::vector<Coord3D>* getTaxiLocations( ObjectID id ) const = 0;
  225. virtual const std::vector<Coord3D>* getCreationLocations( ObjectID id ) const = 0;
  226. };
  227. //-------------------------------------------------------------------------------------------------
  228. class TransportPassengerInterface
  229. {
  230. public:
  231. virtual Bool tryToEvacuate( Bool exposeStealthedUnits ) = 0; ///< Will try to kick everybody out with game checks, and will return whether anyone made it
  232. };
  233. //-------------------------------------------------------------------------------------------------
  234. class CaveInterface
  235. {
  236. public:
  237. virtual void tryToSetCaveIndex( Int newIndex ) = 0; ///< Called by script as an alternative to instancing separate objects. 'Try', because can fail.
  238. virtual void setOriginalTeam( Team *oldTeam ) = 0; ///< This is a distributed Garrison in terms of capturing, so when one node triggers the change, he needs to tell everyone, so anyone can do the un-change.
  239. };
  240. //-------------------------------------------------------------------------------------------------
  241. class LandMineInterface
  242. {
  243. public:
  244. virtual void setScootParms(const Coord3D& start, const Coord3D& end) = 0;
  245. virtual void disarm() = 0;
  246. };
  247. //-------------------------------------------------------------------------------------------------
  248. #endif