SlavedUpdate.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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: SlavedUpdate.cpp /////////////////////////////////////////////////////////////////////////
  24. // Author: Matt Campbell, March 2002
  25. // Updated: Kris Morness, July 2002 -- Add support for advanced scout drone abilities
  26. // Desc: Slaved unit(s) remain close to their master. Used by scout drones, and used by stinger
  27. // soldiers that are close to a stinger site. It's important to note that any slaved units
  28. // can use any or all features, some of which are specialized.
  29. ///////////////////////////////////////////////////////////////////////////////////////////////////
  30. #pragma once
  31. #ifndef _SLAVED_UPDATE_H_
  32. #define _SLAVED_UPDATE_H_
  33. const Int SLAVED_UPDATE_RATE = LOGICFRAMES_PER_SECOND/4; ///< This is a low priority module that only needs to be called every this many frames
  34. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  35. #include "Common/INI.h"
  36. #include "GameLogic/Module/UpdateModule.h"
  37. class DamageInfo;
  38. enum ModelConditionFlagType;
  39. //-------------------------------------------------------------------------------------------------
  40. class SlavedUpdateModuleData : public UpdateModuleData
  41. {
  42. public:
  43. //Example: Currently used by scout drones owned by rangers AND stinger soldiers owned by stinger sites.
  44. Int m_guardMaxRange; //Distance from master I'm allowed when he's idle. If I go too far away, I'll come back.
  45. Int m_guardWanderRange; //Allowable wander distance from master while guarding master.
  46. //Example: Below are only currently used by various drones owned by rangers/vehicles
  47. Int m_attackRange; //When master attacks a target, I'll go to the target -- how far am I allowed to go in this case.
  48. Int m_attackWanderRange;//If I'm at the target point, how far can I wander from it.
  49. Int m_scoutRange; //If master is moving somewhere, I'll scout ahead -- how far am I allowed to go?
  50. Int m_scoutWanderRange; //If I'm at the scout point, how far can I wander from it.
  51. Int m_distToTargetToGrantRangeBonus; //How close I have to be to the master's target in order to grant master a range bonus.
  52. //Example: Below are used by battle drones
  53. Int m_repairRange;
  54. Real m_repairMinAltitude;
  55. Real m_repairMaxAltitude;
  56. Real m_repairRatePerSecond; //How fast I can repair
  57. Int m_repairWhenHealthBelowPercentage; //When should I prioritize repairing my master.
  58. Int m_minReadyFrames;
  59. Int m_maxReadyFrames;
  60. Int m_minWeldFrames;
  61. Int m_maxWeldFrames;
  62. AsciiString m_weldingSysName;
  63. AsciiString m_weldingFXBone;
  64. Bool m_stayOnSameLayerAsMaster;
  65. SlavedUpdateModuleData()
  66. {
  67. m_guardMaxRange = 0;
  68. m_guardWanderRange = 0;
  69. m_attackRange = 0;
  70. m_attackWanderRange = 0;
  71. m_scoutRange = 0;
  72. m_scoutWanderRange = 0;
  73. m_distToTargetToGrantRangeBonus = 0;
  74. m_repairRatePerSecond = 0.0f;
  75. m_repairWhenHealthBelowPercentage = 0;
  76. m_repairMinAltitude = 0.0f;
  77. m_repairMaxAltitude = 0.0f;
  78. m_minWeldFrames = 0;
  79. m_maxWeldFrames = 0;
  80. m_minReadyFrames = 0;
  81. m_maxReadyFrames = 0;
  82. m_stayOnSameLayerAsMaster = false;
  83. }
  84. static void buildFieldParse(MultiIniFieldParse& p)
  85. {
  86. UpdateModuleData::buildFieldParse(p);
  87. static const FieldParse dataFieldParse[] =
  88. {
  89. { "GuardMaxRange", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_guardMaxRange ) },
  90. { "GuardWanderRange", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_guardWanderRange ) },
  91. { "AttackRange", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_attackRange ) },
  92. { "AttackWanderRange", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_attackWanderRange ) },
  93. { "ScoutRange", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_scoutRange ) },
  94. { "ScoutWanderRange", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_scoutWanderRange ) },
  95. { "RepairRange", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_repairRange ) },
  96. { "RepairMinAltitude", INI::parseReal, NULL, offsetof( SlavedUpdateModuleData, m_repairMinAltitude ) },
  97. { "RepairMaxAltitude", INI::parseReal, NULL, offsetof( SlavedUpdateModuleData, m_repairMaxAltitude ) },
  98. { "DistToTargetToGrantRangeBonus", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_distToTargetToGrantRangeBonus ) },
  99. { "RepairRatePerSecond", INI::parseReal, NULL, offsetof( SlavedUpdateModuleData, m_repairRatePerSecond ) },
  100. { "RepairWhenBelowHealth%", INI::parseInt, NULL, offsetof( SlavedUpdateModuleData, m_repairWhenHealthBelowPercentage ) },
  101. { "RepairMinReadyTime", INI::parseDurationUnsignedInt, NULL, offsetof( SlavedUpdateModuleData, m_minReadyFrames ) },
  102. { "RepairMaxReadyTime", INI::parseDurationUnsignedInt, NULL, offsetof( SlavedUpdateModuleData, m_maxReadyFrames ) },
  103. { "RepairMinWeldTime", INI::parseDurationUnsignedInt, NULL, offsetof( SlavedUpdateModuleData, m_minWeldFrames ) },
  104. { "RepairMaxWeldTime", INI::parseDurationUnsignedInt, NULL, offsetof( SlavedUpdateModuleData, m_maxWeldFrames ) },
  105. { "RepairWeldingSys", INI::parseAsciiString, NULL, offsetof( SlavedUpdateModuleData, m_weldingSysName ) },
  106. { "RepairWeldingFXBone", INI::parseAsciiString, NULL, offsetof( SlavedUpdateModuleData, m_weldingFXBone ) },
  107. { "StayOnSameLayerAsMaster", INI::parseBool, NULL, offsetof( SlavedUpdateModuleData, m_stayOnSameLayerAsMaster ) },
  108. { 0, 0, 0, 0 }
  109. };
  110. p.add(dataFieldParse);
  111. }
  112. };
  113. enum RepairStates
  114. {
  115. REPAIRSTATE_NONE,
  116. REPAIRSTATE_UNPACKING,
  117. REPAIRSTATE_PACKING,
  118. REPAIRSTATE_READY,
  119. REPAIRSTATE_EXTENDING,
  120. REPAIRSTATE_RETRACTING,
  121. REPAIRSTATE_WELDING,
  122. };
  123. //-------------------------------------------------------------------------------------------------
  124. class SlavedUpdate : public UpdateModule, public SlavedUpdateInterface
  125. {
  126. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( SlavedUpdate, "SlavedUpdate" )
  127. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( SlavedUpdate, SlavedUpdateModuleData )
  128. public:
  129. SlavedUpdate( Thing *thing, const ModuleData* moduleData );
  130. // virtual destructor prototype provided by memory pool declaration
  131. virtual SlavedUpdateInterface* getSlavedUpdateInterface() { return this; }
  132. virtual ObjectID getSlaverID() const { return m_slaver; }
  133. virtual void onEnslave( const Object *slaver );
  134. virtual void onSlaverDie( const DamageInfo *info );
  135. virtual void onSlaverDamage( const DamageInfo *info );
  136. virtual void onObjectCreated();
  137. virtual Bool isSelfTasking() const { return FALSE; };
  138. void doScoutLogic( const Coord3D *mastersDestination );
  139. void doAttackLogic( const Object *target );
  140. void doGuardLogic( Coord3D *pinnedPosition );
  141. void doRepairLogic();
  142. void endRepair();
  143. void setRepairState( RepairStates repairState );
  144. void setRepairModelConditionStates( ModelConditionFlagType flag );
  145. void moveToNewRepairSpot();
  146. virtual UpdateSleepTime update(); ///< Deciding whether or not to make new guys
  147. private:
  148. void startSlavedEffects( const Object *slaver ); ///< We have been marked as Slaved, so we can't be selected or move too far or other stuff
  149. void stopSlavedEffects(); ///< We are no longer slaved.
  150. ObjectID m_slaver; ///< To whom we are enslaved
  151. Coord3D m_guardPointOffset; ///< Where we should go when not busy and still enslaved
  152. Int m_framesToWait;
  153. RepairStates m_repairState;
  154. Bool m_repairing;
  155. };
  156. #endif