GenerateMinefieldBehavior.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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: GenerateMinefieldBehavior.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, December 2001
  25. // Desc: Update that will count down a lifetime and destroy object when it reaches zero
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __GenerateMinefieldBehavior_H_
  29. #define __GenerateMinefieldBehavior_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/DieModule.h"
  33. #include "GameLogic/Module/UpgradeModule.h"
  34. #include "GameLogic/Module/UpdateModule.h"
  35. //-------------------------------------------------------------------------------------------------
  36. class GenerateMinefieldBehaviorModuleData : public BehaviorModuleData
  37. {
  38. public:
  39. UpgradeMuxData m_upgradeMuxData;
  40. AsciiString m_mineName;
  41. AsciiString m_mineNameUpgraded;
  42. AsciiString m_mineUpgradeTrigger;
  43. const FXList* m_genFX;
  44. Real m_distanceAroundObject;
  45. Real m_minesPerSquareFoot;
  46. Real m_randomJitter;
  47. Real m_skipIfThisMuchUnderStructure;
  48. Bool m_onDeath;
  49. Bool m_borderOnly;
  50. Bool m_alwaysCircular;
  51. Bool m_upgradable;
  52. Bool m_smartBorder;
  53. Bool m_smartBorderSkipInterior;
  54. GenerateMinefieldBehaviorModuleData();
  55. static void buildFieldParse(MultiIniFieldParse& p);
  56. private:
  57. };
  58. //-------------------------------------------------------------------------------------------------
  59. //-------------------------------------------------------------------------------------------------
  60. class GenerateMinefieldBehavior : public UpdateModule,
  61. public DieModuleInterface,
  62. public UpgradeMux
  63. {
  64. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( GenerateMinefieldBehavior, "GenerateMinefieldBehavior" )
  65. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( GenerateMinefieldBehavior, GenerateMinefieldBehaviorModuleData )
  66. public:
  67. GenerateMinefieldBehavior( Thing *thing, const ModuleData* moduleData );
  68. // virtual destructor prototype provided by memory pool declaration
  69. // module methods
  70. static Int getInterfaceMask() { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_DIE) | (MODULEINTERFACE_UPGRADE); }
  71. // BehaviorModule
  72. virtual DieModuleInterface* getDie() { return this; }
  73. virtual UpgradeModuleInterface* getUpgrade() { return this; }
  74. virtual UpdateSleepTime update();
  75. // DamageModuleInterface
  76. virtual void onDie( const DamageInfo *damageInfo );
  77. void setMinefieldTarget(const Coord3D* pos);
  78. protected:
  79. virtual void upgradeImplementation();
  80. virtual Bool isSubObjectsUpgrade() { return false; }
  81. virtual void getUpgradeActivationMasks(UpgradeMaskType& activation, UpgradeMaskType& conflicting) const
  82. {
  83. getGenerateMinefieldBehaviorModuleData()->m_upgradeMuxData.getUpgradeActivationMasks(activation, conflicting);
  84. }
  85. virtual void performUpgradeFX()
  86. {
  87. getGenerateMinefieldBehaviorModuleData()->m_upgradeMuxData.performUpgradeFX(getObject());
  88. }
  89. virtual void processUpgradeRemoval()
  90. {
  91. // I can't take it any more. Let the record show that I think the UpgradeMux multiple inheritence is CRAP.
  92. getGenerateMinefieldBehaviorModuleData()->m_upgradeMuxData.muxDataProcessUpgradeRemoval(getObject());
  93. }
  94. virtual Bool requiresAllActivationUpgrades() const
  95. {
  96. return getGenerateMinefieldBehaviorModuleData()->m_upgradeMuxData.m_requiresAllTriggers;
  97. }
  98. private:
  99. Coord3D m_target;
  100. Bool m_hasTarget;
  101. Bool m_generated;
  102. Bool m_upgraded;
  103. std::list<ObjectID> m_mineList;
  104. const Coord3D* getMinefieldTarget() const;
  105. void placeMines();
  106. void placeMinesInFootprint(const GeometryInfo& geom, const ThingTemplate* mineTemplate);
  107. void placeMinesAroundCircle(const Coord3D& pos, Real radius, const ThingTemplate* mineTemplate);
  108. void placeMinesAlongLine(const Coord3D& posStart, const Coord3D& posEnd, const ThingTemplate* mineTemplate, Bool skipOneAtStart);
  109. void placeMinesAroundRect(const Coord3D& pos, Real majorRadius, Real minorRadius, const ThingTemplate* mineTemplate);
  110. Object* placeMineAt(const Coord3D& pt, const ThingTemplate* mineTemplate, Team* team, const Object* producer);
  111. };
  112. #endif // __GenerateMinefieldBehavior_H_