MobMemberSlavedUpdate.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. // MobMemberSlavedUpdate.h /////////////////////////////////////////////////////////////
  24. // Will obey to spawner... or die trying... used by angry mob members
  25. // Author: Mark Lorenzen, August 2002
  26. #pragma once
  27. #ifndef _MOBMEMBER_SLAVED_UPDATE_H_
  28. #define _MOBMEMBER_SLAVED_UPDATE_H_
  29. #define MM_SLAVED_UPDATE_RATE (LOGICFRAMES_PER_SECOND / 8) ///< This is a low priority module that only needs to be called every this many frames
  30. #define MIN_SQUIRRELLINESS (0.01f)
  31. #define MAX_SQUIRRELLINESS (1.0f)
  32. #define CATCH_UP_RADIUS_MAX (50)
  33. #define CATCH_UP_RADIUS_MIN (25)
  34. #define DEFAULT_MUST_CATCH_UP_RADIUS (CATCH_UP_RADIUS_MAX)
  35. #define DEFAULT_NO_NEED_TO_CATCH_UP_RADIUS (CATCH_UP_RADIUS_MIN)
  36. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  37. #include "Common/INI.h"
  38. #include "GameLogic/Module/UpdateModule.h"
  39. class DamageInfo;
  40. enum ModelConditionFlagType;
  41. //-------------------------------------------------------------------------------------------------
  42. class MobMemberSlavedUpdateModuleData : public UpdateModuleData
  43. {
  44. public:
  45. //Example: Currently used by scout drones owned by rangers AND stinger soldiers owned by stinger sites.
  46. Int m_mustCatchUpRadius; //Distance from master I'm allowed when he's idle. If I go too far away, I'll come back.
  47. Int m_noNeedToCatchUpRadius; //Allowable wander distance from master while guarding master.
  48. Real m_squirrellinessRatio;
  49. UnsignedInt m_catchUpCrisisBailTime; //after this many consecutive frames outside the catchup radius, I will teleport to the nexus
  50. MobMemberSlavedUpdateModuleData()
  51. {
  52. m_mustCatchUpRadius = DEFAULT_MUST_CATCH_UP_RADIUS;
  53. m_noNeedToCatchUpRadius = DEFAULT_NO_NEED_TO_CATCH_UP_RADIUS;
  54. m_squirrellinessRatio = 0;
  55. m_catchUpCrisisBailTime = 999999;//default to very large number
  56. }
  57. static void buildFieldParse(MultiIniFieldParse& p)
  58. {
  59. UpdateModuleData::buildFieldParse(p);
  60. static const FieldParse dataFieldParse[] =
  61. {
  62. { "MustCatchUpRadius", INI::parseInt, NULL, offsetof( MobMemberSlavedUpdateModuleData, m_mustCatchUpRadius ) },
  63. { "CatchUpCrisisBailTime", INI::parseUnsignedInt, NULL, offsetof( MobMemberSlavedUpdateModuleData, m_catchUpCrisisBailTime ) },
  64. { "NoNeedToCatchUpRadius", INI::parseInt, NULL, offsetof( MobMemberSlavedUpdateModuleData, m_noNeedToCatchUpRadius ) },
  65. { "Squirrelliness", INI::parseReal, NULL, offsetof( MobMemberSlavedUpdateModuleData, m_squirrellinessRatio ) },
  66. { 0, 0, 0, 0 }
  67. };
  68. p.add(dataFieldParse);
  69. }
  70. };
  71. enum MobStates
  72. {
  73. MOB_STATE_NONE,
  74. MOB_STATE_IDLE,
  75. MOB_STATE_CATCHUP_NOW,
  76. MOB_STATE_CATCHING_UP,
  77. MOB_STATE_ATTACK,
  78. };
  79. //-------------------------------------------------------------------------------------------------
  80. class MobMemberSlavedUpdate : public UpdateModule, public SlavedUpdateInterface
  81. {
  82. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( MobMemberSlavedUpdate, "MobMemberSlavedUpdate" )
  83. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( MobMemberSlavedUpdate, MobMemberSlavedUpdateModuleData )
  84. public:
  85. MobMemberSlavedUpdate( Thing *thing, const ModuleData* moduleData );
  86. // virtual destructor prototype provided by memory pool declaration
  87. virtual SlavedUpdateInterface* getSlavedUpdateInterface() { return this; }// hee hee... behaves just like slavedupdate
  88. virtual ObjectID getSlaverID() const { return m_slaver; }
  89. virtual void onEnslave( const Object *slaver );
  90. virtual void onSlaverDie( const DamageInfo *info );
  91. virtual void onSlaverDamage( const DamageInfo *info );
  92. virtual void onObjectCreated();
  93. virtual Bool isSelfTasking() const { return m_isSelfTasking; };
  94. void doCatchUpLogic( Coord3D *pinnedPosition );
  95. void setMobState( MobStates state ) { m_mobState = state; };
  96. MobStates getMobState( void ) { return m_mobState; };
  97. virtual UpdateSleepTime update(); ///< Deciding whether or not to make new guys
  98. private:
  99. void startSlavedEffects( const Object *slaver ); ///< We have been marked as Slaved, so we can't be selected or move too far or other stuff
  100. void stopSlavedEffects(); ///< We are no longer slaved.
  101. ObjectID m_slaver; ///< To whom we are enslaved
  102. Int m_framesToWait;
  103. MobStates m_mobState;
  104. RGBColor m_personalColor;
  105. ObjectID m_primaryVictimID;
  106. Real m_squirrellinessRatio;
  107. Bool m_isSelfTasking;
  108. UnsignedInt m_catchUpCrisisTimer;// how many consecutive frames have I remained outside the catchup radius
  109. //This is a failsafe to make sure that an individual mobmember does not get isolated from his buddies
  110. // thus causing the mob to become invincible, since they will continue to bud around the nexus
  111. };
  112. #endif //_MOBMEMBER_AI_UPDATE_H_