MinefieldBehavior.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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: MinefieldBehavior.h ////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, June 2002
  25. // Desc: Minefield behavior
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __MinefieldBEHAVIOR_H_
  29. #define __MinefieldBEHAVIOR_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/CollideModule.h"
  33. #include "GameLogic/Module/UpdateModule.h"
  34. #include "GameLogic/Module/DamageModule.h"
  35. #include "GameLogic/Module/DieModule.h"
  36. #include "GameLogic/ObjectCreationList.h"
  37. //-------------------------------------------------------------------------------------------------
  38. // ------------------------------------------------------------------------------------------------
  39. class MinefieldBehaviorModuleData : public UpdateModuleData
  40. {
  41. public:
  42. MinefieldBehaviorModuleData();
  43. static void buildFieldParse( MultiIniFieldParse &p );
  44. const WeaponTemplate* m_detonationWeapon; ///< what happens when we detonate
  45. Int m_detonatedBy; ///< can we be triggered by allies, etc?
  46. Bool m_stopsRegenAfterCreatorDies;
  47. Bool m_regenerates; ///< if t, can't be killed normally
  48. Bool m_workersDetonate; ///< if f, workers don't detonate mines
  49. UnsignedInt m_creatorDeathCheckRate; ///< if above is true, how often to check
  50. UnsignedInt m_scootFromStartingPointTime; ///< if nonzero, gradually scoot to dest pt
  51. UnsignedInt m_numVirtualMines; ///< num of "virtual" mines we have
  52. Real m_repeatDetonateMoveThresh;
  53. Real m_healthPercentToDrainPerSecond;
  54. const ObjectCreationList* m_ocl; ///< object creaton list to make
  55. };
  56. //-------------------------------------------------------------------------------------------------
  57. //-------------------------------------------------------------------------------------------------
  58. class MinefieldBehavior : public UpdateModule,
  59. public CollideModuleInterface,
  60. public DamageModuleInterface,
  61. public DieModuleInterface,
  62. public LandMineInterface
  63. {
  64. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( MinefieldBehavior, "MinefieldBehavior" )
  65. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( MinefieldBehavior, MinefieldBehaviorModuleData )
  66. public:
  67. MinefieldBehavior( Thing *thing, const ModuleData *moduleData );
  68. // virtual destructor prototype provided by memory pool declaration
  69. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_COLLIDE) | (MODULEINTERFACE_DAMAGE) | (MODULEINTERFACE_DIE); }
  70. // BehaviorModule
  71. virtual CollideModuleInterface* getCollide() { return this; }
  72. virtual LandMineInterface* getLandMineInterface() { return this; }
  73. virtual DamageModuleInterface* getDamage() { return this; }
  74. virtual DieModuleInterface* getDie() { return this; }
  75. // DamageModuleInterface
  76. virtual void onDamage( DamageInfo *damageInfo );
  77. virtual void onHealing( DamageInfo *damageInfo );
  78. virtual void onBodyDamageStateChange(const DamageInfo* damageInfo, BodyDamageType oldState, BodyDamageType newState) { }
  79. // DieModuleInterface
  80. virtual void onDie( const DamageInfo *damageInfo );
  81. // UpdateModuleInterface
  82. virtual UpdateSleepTime update();
  83. // CollideModuleInterface
  84. virtual void onCollide( Object *other, const Coord3D *loc, const Coord3D *normal );
  85. virtual Bool wouldLikeToCollideWith(const Object* other) const { return false; }
  86. virtual Bool isHijackedVehicleCrateCollide() const { return false; }
  87. virtual Bool isCarBombCrateCollide() const { return false; }
  88. virtual Bool isRailroad() const { return false;}
  89. virtual Bool isSalvageCrateCollide() const { return false; }
  90. virtual Bool isSabotageBuildingCrateCollide() const { return FALSE; }
  91. // Minefield specific methods
  92. virtual void setScootParms(const Coord3D& start, const Coord3D& end);
  93. virtual void disarm();
  94. private:
  95. // mines are small, so we can get by with a small fixed number here
  96. enum { MAX_IMMUNITY = 3 };
  97. struct ImmuneInfo
  98. {
  99. ObjectID id;
  100. UnsignedInt collideTime;
  101. };
  102. struct DetonatorInfo
  103. {
  104. ObjectID id;
  105. Coord3D where;
  106. };
  107. UnsignedInt m_nextDeathCheckFrame;
  108. UnsignedInt m_scootFramesLeft;
  109. Coord3D m_scootVel;
  110. Coord3D m_scootAccel;
  111. UnsignedInt m_virtualMinesRemaining;
  112. ImmuneInfo m_immunes[MAX_IMMUNITY];
  113. std::vector<DetonatorInfo> m_detonators;
  114. Bool m_ignoreDamage;
  115. Bool m_regenerates;
  116. Bool m_draining;
  117. void detonateOnce(const Coord3D& position);
  118. UpdateSleepTime calcSleepTime();
  119. };
  120. #endif // end __MinefieldBEHAVIOR_H_