DeliverPayloadAIUpdate.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. // DeliverPayloadAIUpdate.h ////////////
  24. // Author: Graham Smallwood, March 2002
  25. // Desc: State machine that controls the approach and deployment of airborne cargo
  26. #pragma once
  27. #ifndef _DELIVER_PAYLOAD_AI_UPDATE_H_
  28. #define _DELIVER_PAYLOAD_AI_UPDATE_H_
  29. #include "Common/StateMachine.h"
  30. #include "GameLogic/Module/AIUpdate.h"
  31. #include "GameClient/RadiusDecal.h"
  32. class DeliverPayloadData;
  33. //-------------------------------------------------------------------------------------------------
  34. class DeliverPayloadStateMachine : public StateMachine
  35. {
  36. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( DeliverPayloadStateMachine, "DeliverPayloadStateMachine" );
  37. public:
  38. DeliverPayloadStateMachine( Object *owner );
  39. static Bool isOffMap( State *thisState, void* userData );
  40. protected:
  41. // snapshot interface
  42. virtual void crc( Xfer *xfer );
  43. virtual void xfer( Xfer *xfer );
  44. virtual void loadPostProcess();
  45. };
  46. //-------------------------------------------------------------------------------------------------
  47. class ApproachState : public State
  48. {
  49. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(ApproachState, "ApproachState")
  50. //Approaching the drop zone
  51. public:
  52. ApproachState( StateMachine *machine ) :State( machine, "ApproachState" ) {}
  53. virtual StateReturnType update();
  54. virtual StateReturnType onEnter();
  55. protected:
  56. // snapshot interface STUBBED - no member vars to save. jba.
  57. virtual void crc( Xfer *xfer ){};
  58. virtual void xfer( Xfer *xfer ){XferVersion cv = 1; XferVersion v = cv; xfer->xferVersion( &v, cv );}
  59. virtual void loadPostProcess(){};
  60. };
  61. EMPTY_DTOR(ApproachState)
  62. //-------------------------------------------------------------------------------------------------
  63. class DeliveringState : public State
  64. {
  65. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(DeliveringState, "DeliveringState")
  66. // Kickin' stuff out the door
  67. public:
  68. DeliveringState( StateMachine *machine ) :State( machine, "DeliveringState" )
  69. {
  70. m_dropDelayLeft = 0;
  71. m_didOpen = false;
  72. }
  73. virtual StateReturnType update();
  74. virtual StateReturnType onEnter();
  75. virtual void onExit( StateExitType status );
  76. protected:
  77. // snapshot interface
  78. virtual void crc( Xfer *xfer );
  79. virtual void xfer( Xfer *xfer );
  80. virtual void loadPostProcess();
  81. private:
  82. UnsignedInt m_dropDelayLeft;
  83. Bool m_didOpen;
  84. };
  85. EMPTY_DTOR(DeliveringState)
  86. //-------------------------------------------------------------------------------------------------
  87. class ConsiderNewApproachState : public State
  88. {
  89. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(ConsiderNewApproachState, "ConsiderNewApproachState")
  90. //Should I try again? Has own data to keep track.
  91. public:
  92. ConsiderNewApproachState( StateMachine *machine ) : State( machine, "ConsiderNewApproachState" ), m_numberEntriesToState(0) { }
  93. virtual StateReturnType update();
  94. virtual StateReturnType onEnter();
  95. virtual void onExit( StateExitType status );
  96. protected:
  97. // snapshot interface
  98. virtual void crc( Xfer *xfer );
  99. virtual void xfer( Xfer *xfer );
  100. virtual void loadPostProcess();
  101. private:
  102. Int m_numberEntriesToState;
  103. };
  104. EMPTY_DTOR(ConsiderNewApproachState)
  105. //-------------------------------------------------------------------------------------------------
  106. class RecoverFromOffMapState : public State
  107. {
  108. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(RecoverFromOffMapState, "RecoverFromOffMapState")
  109. public:
  110. RecoverFromOffMapState( StateMachine *machine ) : State( machine, "RecoverFromOffMapState" ), m_reEntryFrame(0) { }
  111. virtual StateReturnType update();
  112. virtual StateReturnType onEnter();
  113. protected:
  114. // snapshot interface
  115. virtual void crc( Xfer *xfer );
  116. virtual void xfer( Xfer *xfer );
  117. virtual void loadPostProcess();
  118. private:
  119. UnsignedInt m_reEntryFrame;
  120. };
  121. EMPTY_DTOR(RecoverFromOffMapState)
  122. //-------------------------------------------------------------------------------------------------
  123. class HeadOffMapState : public State
  124. {
  125. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(HeadOffMapState, "HeadOffMapState")
  126. //I'm outta here
  127. public:
  128. HeadOffMapState( StateMachine *machine ) :State( machine, "HeadOffMapState" ) { facingDirectionUponDelivery.zero(); }
  129. virtual StateReturnType update();
  130. virtual StateReturnType onEnter();
  131. protected:
  132. // snapshot interface STUBBED - no member vars to save. jba.
  133. virtual void crc( Xfer *xfer ){};
  134. virtual void xfer( Xfer *xfer ){XferVersion cv = 1; XferVersion v = cv; xfer->xferVersion( &v, cv );}
  135. virtual void loadPostProcess(){};
  136. Coord3D facingDirectionUponDelivery;
  137. };
  138. EMPTY_DTOR(HeadOffMapState)
  139. //-------------------------------------------------------------------------------------------------
  140. class CleanUpState : public State
  141. {
  142. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(CleanUpState, "CleanUpState")
  143. //Made it off map, delete ourselves
  144. public:
  145. CleanUpState( StateMachine *machine ) :State( machine, "CleanUpState" ) {}
  146. virtual StateReturnType update(){return STATE_CONTINUE;}
  147. virtual StateReturnType onEnter();
  148. protected:
  149. // snapshot interface STUBBED - no member vars to save. jba.
  150. virtual void crc( Xfer *xfer ){};
  151. virtual void xfer( Xfer *xfer ){XferVersion cv = 1; XferVersion v = cv; xfer->xferVersion( &v, cv );}
  152. virtual void loadPostProcess(){};
  153. };
  154. EMPTY_DTOR(CleanUpState)
  155. //-------------------------------------------------------------------------------------------------
  156. enum
  157. {
  158. APPROACH, ///< Flying towards target
  159. DELIVERING, ///< Delivering the payload to the target
  160. CONSIDER_NEW_APPROACH, ///< Deciding if I should reapproach to deliver more payload or go home
  161. RECOVER_FROM_OFF_MAP, ///< oops, went off the map, special recovery needed
  162. HEAD_OFF_MAP, ///< We're all done here, take off into the sunset
  163. CLEAN_UP, ///< Made it to the sunset. Delete peacefully, don't kill
  164. };
  165. //-------------------------------------------------------------------------------------------------
  166. class DeliverPayloadAIUpdateModuleData : public AIUpdateModuleData
  167. {
  168. public:
  169. UnsignedInt m_doorDelay;
  170. Real m_maxDistanceToTarget; ///< How far away from target I can unload, plus how far after target I need to turn around at
  171. Int m_maxNumberAttempts; ///< How many times I can re-approach
  172. UnsignedInt m_dropDelay; ///< How long to wait after entering Deliver state (to allow for doors opening)
  173. Coord3D m_dropOffset; ///< where to disgorge the guys, relative to me
  174. Coord3D m_dropVariance; ///< variance in dropping position among guys that I am dropping
  175. AsciiString m_putInContainerName;
  176. RadiusDecalTemplate m_deliveryDecalTemplate;
  177. Real m_deliveryDecalRadius;
  178. DeliverPayloadAIUpdateModuleData()
  179. {
  180. m_doorDelay = 0;
  181. m_maxDistanceToTarget = 0.0f;
  182. m_maxNumberAttempts = 0;
  183. m_dropDelay = 0;
  184. m_dropOffset.zero();
  185. m_dropVariance.zero();
  186. m_deliveryDecalRadius = 0;
  187. // Added By Sadullah Nader
  188. // Initialization missing and needed
  189. m_putInContainerName.clear();
  190. // End Add
  191. }
  192. static void buildFieldParse(MultiIniFieldParse& p)
  193. {
  194. AIUpdateModuleData::buildFieldParse(p);
  195. static const FieldParse dataFieldParse[] =
  196. {
  197. //These values represent script only reinforcements using deliverPayloadViaModuleData()!
  198. //***********************************************************************************
  199. //DO NOT ADD DATA HERE UNLESS YOU ARE SUPPORTING SCRIPTED TEAM REINFORCEMENT DELIVERY
  200. //THESE DATA VALUES ARE SPECIFIED ONLY BY FACTIONUNIT.INI
  201. //***********************************************************************************
  202. { "DoorDelay", INI::parseDurationUnsignedInt, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_doorDelay ) },
  203. { "PutInContainer", INI::parseAsciiString, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_putInContainerName ) },
  204. { "DeliveryDistance", INI::parseReal, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_maxDistanceToTarget ) },
  205. { "MaxAttempts", INI::parseInt, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_maxNumberAttempts ) },
  206. { "DropDelay", INI::parseDurationUnsignedInt, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_dropDelay ) },
  207. { "DropOffset", INI::parseCoord3D, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_dropOffset ) },
  208. { "DropVariance", INI::parseCoord3D, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_dropVariance ) },
  209. { "DeliveryDecal", RadiusDecalTemplate::parseRadiusDecalTemplate, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_deliveryDecalTemplate ) },
  210. { "DeliveryDecalRadius", INI::parseReal, NULL, offsetof( DeliverPayloadAIUpdateModuleData, m_deliveryDecalRadius ) },
  211. { 0, 0, 0, 0 }
  212. };
  213. p.add(dataFieldParse);
  214. }
  215. };
  216. //This data is set by DeliverPayloadNugget in ObjectCreationList. This struct contains
  217. //all the necessary information for DeliverPayloadAIUpdate to perform it's necessary
  218. //functions. If you add something here, make sure you add the parsing function inside
  219. //DeliverPayloadNugget.
  220. //***********************************************************************************
  221. //THESE DATA VALUES ARE SPECIFIED ONLY BY OBJECTCREATIONLIST.INI
  222. //***********************************************************************************
  223. class DeliverPayloadData
  224. {
  225. public:
  226. AsciiString m_visibleDropBoneName; ///< Where the payload is created (offset by current bone number 01-xx)
  227. AsciiString m_visibleSubObjectName; ///< Visible subobject to show or hide (offset by current drop number 01-xx)
  228. AsciiString m_visiblePayloadTemplateName;
  229. Real m_distToTarget;
  230. Real m_preOpenDistance;
  231. Int m_maxAttempts;
  232. Coord3D m_dropOffset;
  233. Coord3D m_dropVariance;
  234. UnsignedInt m_dropDelay;
  235. Bool m_fireWeapon;
  236. Bool m_selfDestructObject;
  237. Int m_visibleNumBones; ///< The number of visible bones to process.
  238. Real m_diveStartDistance;
  239. Real m_diveEndDistance;
  240. WeaponSlotType m_strafingWeaponSlot;
  241. Int m_visibleItemsDroppedPerInterval;
  242. Bool m_inheritTransportVelocity;
  243. Bool m_isParachuteDirectly; ///< Instead of parachuting to below the point of exit, go ahead and bunch up on the target
  244. Real m_exitPitchRate;
  245. const FXList *m_strafeFX;
  246. Real m_strafeLength;
  247. const WeaponTemplate *m_visiblePayloadWeaponTemplate;
  248. RadiusDecalTemplate m_deliveryDecalTemplate;
  249. Real m_deliveryDecalRadius;
  250. DeliverPayloadData()
  251. {
  252. m_distToTarget = 0.0f;
  253. m_preOpenDistance = 0.0f;
  254. m_maxAttempts = 1;
  255. m_dropOffset.zero();
  256. m_dropVariance.zero();
  257. m_dropDelay = 0;
  258. m_fireWeapon = false;
  259. m_visibleNumBones = 0;
  260. m_diveStartDistance = 0.0f;
  261. m_diveEndDistance = 0.0f;
  262. m_strafingWeaponSlot = (WeaponSlotType)-1;
  263. m_visibleItemsDroppedPerInterval = 0;
  264. m_inheritTransportVelocity = false;
  265. m_isParachuteDirectly = FALSE;
  266. m_exitPitchRate = 0.0f;
  267. m_strafeFX = NULL;
  268. m_strafeLength = 0.0f;
  269. m_visiblePayloadWeaponTemplate = NULL;
  270. m_selfDestructObject = FALSE;
  271. m_deliveryDecalRadius = 0;
  272. // Added By Sadullah Nader
  273. // Initialization missing and needed
  274. m_visibleDropBoneName.clear();
  275. m_visiblePayloadTemplateName.clear();
  276. m_visibleSubObjectName.clear();
  277. // End Add
  278. }
  279. static const FieldParse* getFieldParse();
  280. };
  281. //-------------------------------------------------------------------------------------------------
  282. class DeliverPayloadAIUpdate : public AIUpdateInterface
  283. {
  284. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( DeliverPayloadAIUpdate, "DeliverPayloadAIUpdate" )
  285. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( DeliverPayloadAIUpdate, DeliverPayloadAIUpdateModuleData )
  286. private:
  287. public:
  288. DeliverPayloadAIUpdate( Thing *thing, const ModuleData* moduleData );
  289. // virtual destructor prototype provided by memory pool declaration
  290. virtual AIFreeToExitType getAiFreeToExit(const Object* exiter) const;
  291. const Coord3D* getTargetPos() const { return &m_targetPos; }
  292. const Coord3D* getMoveToPos() const { return &m_moveToPos; }
  293. UnsignedInt getDoorDelay() const { return getDeliverPayloadAIUpdateModuleData()->m_doorDelay; }
  294. Bool isDeliveringPayload() const { return m_deliverPayloadStateMachine != NULL; }
  295. const ThingTemplate* getPutInContainerTemplateViaModuleData() const;
  296. Real getAllowedDistanceToTarget() const { return m_data.m_distToTarget; }
  297. Real getPreOpenDistance() const { return m_data.m_preOpenDistance; }
  298. Int getMaxNumberAttempts() const { return m_data.m_maxAttempts; }
  299. UnsignedInt getDropDelay() const { return m_data.m_dropDelay; }
  300. const Coord3D& getDropOffset() const { return m_data.m_dropOffset; }
  301. const Coord3D& getDropVariance() const { return m_data.m_dropVariance; }
  302. Bool isFireWeapon() const { return m_data.m_fireWeapon; }
  303. Int getVisibleItemsDelivered() const { return m_visibleItemsDelivered; }
  304. void setVisibleItemsDelivered( Int num ) { m_visibleItemsDelivered = num; }
  305. Bool isCloseEnoughToTarget();
  306. Bool isOffMap() const;
  307. Real calcMinTurnRadius(Real* timeToTravelThatDist) const;
  308. void deliverPayload( const Coord3D *moveToPos, const Coord3D *targetPos, const DeliverPayloadData *data );
  309. void deliverPayloadViaModuleData( const Coord3D *moveToPos );
  310. const DeliverPayloadData* getData() { return &m_data; }
  311. virtual UpdateSleepTime update();
  312. void killDeliveryDecal();
  313. void friend_setFreeToExit(Bool f) { m_freeToExit = f; }
  314. void friend_setAcceptingCommands(Bool f) { m_acceptingCommands = f; }
  315. protected:
  316. virtual AIStateMachine* makeStateMachine();
  317. virtual Bool isAllowedToRespondToAiCommands(const AICommandParms* parms) const;
  318. DeliverPayloadStateMachine* m_deliverPayloadStateMachine; ///< Controls my special logic
  319. Coord3D m_targetPos; ///< Where I plan to deliver my little friends, if obj is null
  320. Coord3D m_moveToPos; ///< Where I am moving to.
  321. DeliverPayloadData m_data;
  322. Int m_visibleItemsDelivered;
  323. RadiusDecal m_deliveryDecal;
  324. Real m_previousDistanceSqr;
  325. Bool m_freeToExit;
  326. Bool m_acceptingCommands;
  327. enum DiveState // Stored in save file as int, don't renumber! jba.
  328. {
  329. DIVESTATE_PREDIVE=0,
  330. DIVESTATE_DIVING=1,
  331. DIVESTATE_POSTDIVE=2,
  332. };
  333. DiveState m_diveState;
  334. };
  335. #endif