AssaultTransportAIUpdate.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. // AssaultTransportAIUpdate.h ////////////
  24. // Author: Kris Morness, December 2002
  25. // Desc: State machine that allows assault transports (troop crawler) to deploy
  26. // troops, order them to attack, then return. Can do extra things like ordering
  27. // injured troops to return to the transport for healing purposes.
  28. #pragma once
  29. #ifndef __ASSAULT_TRANSPORT_AI_UPDATE_H
  30. #define __ASSAULT_TRANSPORT_AI_UPDATE_H
  31. #include "Common/StateMachine.h"
  32. #include "GameLogic/Module/AIUpdate.h"
  33. //-------------------------------------------------------------------------------------------------
  34. enum AssaultStateTypes
  35. {
  36. IDLE, ///< Not doing anything.
  37. ASSAULTING, ///< Transport is waiting while troops do fighting.
  38. };
  39. #define MAX_TRANSPORT_SLOTS 10
  40. //-------------------------------------------------------------------------------------------------
  41. class AssaultTransportAIUpdateModuleData : public AIUpdateModuleData
  42. {
  43. public:
  44. Real m_membersGetHealedAtLifeRatio;
  45. Real m_clearRangeRequiredToContinueAttackMove;
  46. AssaultTransportAIUpdateModuleData()
  47. {
  48. m_membersGetHealedAtLifeRatio = 0.0f;
  49. m_clearRangeRequiredToContinueAttackMove = 50.0f;
  50. }
  51. static void buildFieldParse(MultiIniFieldParse& p)
  52. {
  53. AIUpdateModuleData::buildFieldParse(p);
  54. static const FieldParse dataFieldParse[] =
  55. {
  56. { "MembersGetHealedAtLifeRatio", INI::parseReal, NULL, offsetof( AssaultTransportAIUpdateModuleData, m_membersGetHealedAtLifeRatio ) },
  57. { "ClearRangeRequiredToContinueAttackMove", INI::parseReal, NULL, offsetof( AssaultTransportAIUpdateModuleData, m_clearRangeRequiredToContinueAttackMove ) },
  58. { 0, 0, 0, 0 }
  59. };
  60. p.add(dataFieldParse);
  61. }
  62. };
  63. class AssaultTransportAIInterface
  64. {
  65. public:
  66. virtual void beginAssault( const Object *designatedTarget ) const = 0;
  67. };
  68. //-------------------------------------------------------------------------------------------------
  69. class AssaultTransportAIUpdate : public AIUpdateInterface, public AssaultTransportAIInterface
  70. {
  71. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( AssaultTransportAIUpdate, "AssaultTransportAIUpdate" )
  72. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( AssaultTransportAIUpdate, AssaultTransportAIUpdateModuleData )
  73. private:
  74. public:
  75. AssaultTransportAIUpdate( Thing *thing, const ModuleData* moduleData );
  76. // virtual destructor prototype provided by memory pool declaration
  77. virtual void aiDoCommand(const AICommandParms* parms);
  78. virtual Bool isIdle() const;
  79. virtual UpdateSleepTime update();
  80. virtual AssaultTransportAIInterface* getAssaultTransportAIInterface() { return this; }
  81. virtual const AssaultTransportAIInterface* getAssaultTransportAIInterface() const { return this; }
  82. virtual void beginAssault( const Object *designatedTarget ) const;
  83. UpdateSleepTime calcSleepTime();
  84. void reset();
  85. Bool isMemberWounded( const Object *member ) const; //Member requires medical attention?
  86. Bool isMemberHealthy( const Object *member ) const; //Member has full health?
  87. void retrieveMembers();
  88. void giveFinalOrders();
  89. Bool isAttackPointless() const;
  90. protected:
  91. ObjectID m_memberIDs[ MAX_TRANSPORT_SLOTS ];
  92. Bool m_memberHealing[ MAX_TRANSPORT_SLOTS ];
  93. Bool m_newMember[ MAX_TRANSPORT_SLOTS ];
  94. Coord3D m_attackMoveGoalPos;
  95. mutable ObjectID m_designatedTarget;
  96. AssaultStateTypes m_state;
  97. UnsignedInt m_framesRemaining;
  98. Int m_currentMembers;
  99. Bool m_isAttackMove;
  100. Bool m_isAttackObject;
  101. Bool m_newOccupantsAreNewMembers;
  102. };
  103. #endif