POWTruckAIUpdate.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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: POWTruckAIUpdate.h ///////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day
  25. // Desc: AI for the POW Truck
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __POW_TRUCK_AI_UPDATE_H_
  29. #define __POW_TRUCK_AI_UPDATE_H_
  30. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/AIUpdate.h"
  32. #ifdef ALLOW_SURRENDER
  33. // ------------------------------------------------------------------------------------------------
  34. /** NOTE: If you edit module data you must do it in both the Dozer *AND* the Worker */
  35. // ------------------------------------------------------------------------------------------------
  36. class POWTruckAIUpdateModuleData : public AIUpdateModuleData
  37. {
  38. public:
  39. POWTruckAIUpdateModuleData( void );
  40. static void buildFieldParse( MultiIniFieldParse &p );
  41. UnsignedInt m_boredTimeInFrames; ///< after this long we seek out targets in AUTOMATIC mode
  42. Real m_hangAroundPrisonDistance; ///< this close is considered "at the prison" for purposes of waiting
  43. };
  44. // ------------------------------------------------------------------------------------------------
  45. // ------------------------------------------------------------------------------------------------
  46. enum POWTruckTask // Stored in save file, do not renumber. jba.
  47. {
  48. POW_TRUCK_TASK_WAITING = 0, ///< Waiting for something to do
  49. POW_TRUCK_TASK_FIND_TARGET = 1, ///< We need to search out a target to collect
  50. POW_TRUCK_TASK_COLLECTING_TARGET = 2, ///< collecting a targeted POW
  51. POW_TRUCK_TASK_RETURNING_PRISONERS= 3 ///< return all POWs to base
  52. };
  53. // ------------------------------------------------------------------------------------------------
  54. // ------------------------------------------------------------------------------------------------
  55. class POWTruckAIUpdateInterface
  56. {
  57. public:
  58. virtual void setTask( POWTruckTask task, Object *taskObject = NULL ) = 0;
  59. virtual POWTruckTask getCurrentTask( void ) = 0;
  60. virtual void loadPrisoner( Object *prisoner ) = 0;
  61. virtual void unloadPrisonersToPrison( Object *prison ) = 0;
  62. };
  63. //-------------------------------------------------------------------------------------------------
  64. /** The Dozer AI Update interface. Dozers are workers that are capable of building all the
  65. * structures available to a player, as well as repairing building, and fortifying
  66. * civilian structures */
  67. //-------------------------------------------------------------------------------------------------
  68. class POWTruckAIUpdate : public AIUpdateInterface,
  69. public POWTruckAIUpdateInterface
  70. {
  71. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( POWTruckAIUpdate, "POWTruckAIUpdate" )
  72. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( POWTruckAIUpdate, POWTruckAIUpdateModuleData )
  73. public:
  74. POWTruckAIUpdate( Thing *thing, const ModuleData *moduleData );
  75. // virtual destructor prototype provided by memory pool declaration
  76. virtual void onDelete( void );
  77. virtual UpdateSleepTime update( void );
  78. // Pow truck ai interface
  79. virtual POWTruckAIUpdateInterface *getPOWTruckAIUpdateInterface( void ) { return this; }
  80. virtual POWTruckTask getCurrentTask( void ) { return m_currentTask; }
  81. virtual void loadPrisoner( Object *prisoner );
  82. virtual void unloadPrisonersToPrison( Object *prison );
  83. //
  84. // the following methods must be overridden so that if a player issues a command the dozer
  85. // can exit the internal state machine and do whatever the player says
  86. //
  87. virtual void aiDoCommand( const AICommandParms *parms );
  88. protected:
  89. virtual void setTask( POWTruckTask task, Object *taskObject = NULL ); ///< set our current task
  90. enum POWTruckAIMode // Stored in save file, do not renumber. jba.
  91. {
  92. AUTOMATIC = 0,
  93. MANUAL = 1
  94. };
  95. virtual void setAIMode( POWTruckAIMode mode ); ///< put truck in automatic or manual mode
  96. virtual void updateWaiting( void );
  97. virtual void updateFindTarget( void );
  98. virtual void updateCollectingTarget( void );
  99. virtual void updateReturnPrisoners( void );
  100. virtual Bool validateTarget( const Object *target ); ///< is 'target' a valid object to collect
  101. virtual void doReturnPrisoners( void ); ///< initiate a return prisoners to base
  102. virtual void doReturnToPrison( Object *prison ); ///< initiate a return to prison (no prisoner dump off)
  103. virtual Object *findBestPrison( void ); ///< find the best prison for us given our current position
  104. virtual Object *findBestTarget( void ); ///< find the best prisoner for us given our current situation
  105. // AIUpdateInterface implementations
  106. virtual void privatePickUpPrisoner( Object *prisoner, CommandSourceType cmdSource );
  107. virtual void privateReturnPrisoners( Object *prison, CommandSourceType cmdSource );
  108. POWTruckAIMode m_aiMode; ///< Type of AI, automatic or explicitly controlled be player
  109. POWTruckTask m_currentTask; ///< our current task
  110. ObjectID m_targetID; ///< Object ID of the target we're going to collect
  111. ObjectID m_prisonID; ///< Prison we're going back to
  112. UnsignedInt m_enteredWaitingFrame; ///< frame we entered the waiting task
  113. UnsignedInt m_lastFindFrame; ///< so that we don't search for targets too much
  114. };
  115. #endif
  116. #endif // end __POW_TRUCK_AI_UPDATE_H_