RebuildHoleBehavior.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: RebuildHoleBehavior.h ////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, June 2002
  25. // Desc: GLA Hole behavior that reconstructs a building after death
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __REBUILD_HOLE_BEHAVIOR_H_
  29. #define __REBUILD_HOLE_BEHAVIOR_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "GameLogic/Module/BehaviorModule.h"
  32. #include "GameLogic/Module/DieModule.h"
  33. #include "GameLogic/Module/UpdateModule.h"
  34. //-------------------------------------------------------------------------------------------------
  35. // ------------------------------------------------------------------------------------------------
  36. class RebuildHoleBehaviorModuleData : public UpdateModuleData
  37. {
  38. public:
  39. RebuildHoleBehaviorModuleData( void );
  40. static void buildFieldParse( MultiIniFieldParse &p );
  41. Real m_workerRespawnDelay; ///< delay in frames from death of object till respawn of worker
  42. Real m_holeHealthRegenPercentPerSecond; ///< the hole recovers this % of the max hit points per second
  43. AsciiString m_workerTemplateName; ///< name of worker object
  44. private:
  45. };
  46. // ------------------------------------------------------------------------------------------------
  47. // ------------------------------------------------------------------------------------------------
  48. class RebuildHoleBehaviorInterface
  49. {
  50. public:
  51. virtual void startRebuildProcess( const ThingTemplate *rebuild, ObjectID spawnerID ) = 0;
  52. virtual ObjectID getSpawnerID( void ) = 0;
  53. virtual ObjectID getReconstructedBuildingID( void ) = 0;
  54. virtual const ThingTemplate* getRebuildTemplate() const = 0;
  55. };
  56. //-------------------------------------------------------------------------------------------------
  57. //-------------------------------------------------------------------------------------------------
  58. class RebuildHoleBehavior : public UpdateModule,
  59. public DieModuleInterface,
  60. public RebuildHoleBehaviorInterface
  61. {
  62. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( RebuildHoleBehavior, "RebuildHoleBehavior" )
  63. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( RebuildHoleBehavior, RebuildHoleBehaviorModuleData )
  64. public:
  65. RebuildHoleBehavior( Thing *thing, const ModuleData *moduleData );
  66. // virtual destructor prototype provided by memory pool declaration
  67. virtual RebuildHoleBehaviorInterface* getRebuildHoleBehaviorInterface() { return this; }
  68. static Int getInterfaceMask( void ) { return UpdateModule::getInterfaceMask() | (MODULEINTERFACE_DIE); }
  69. // BehaviorModule
  70. virtual DieModuleInterface* getDie( void ) { return this; }
  71. // UpdateModuleInterface
  72. virtual UpdateSleepTime update( void );
  73. // DieModuleInterface
  74. virtual void onDie( const DamageInfo *damageInfo );
  75. // RebuildHole specific methods
  76. virtual void startRebuildProcess( const ThingTemplate *rebuild, ObjectID spawnerID );
  77. virtual ObjectID getSpawnerID( void ) { return m_spawnerObjectID; }
  78. virtual ObjectID getReconstructedBuildingID( void ) { return m_reconstructingID; }
  79. virtual const ThingTemplate* getRebuildTemplate() const { return m_rebuildTemplate; }
  80. void transferBombs( Object *reconstruction );
  81. // interface acquisition
  82. static RebuildHoleBehaviorInterface* getRebuildHoleBehaviorInterfaceFromObject( Object *obj );
  83. protected:
  84. void newWorkerRespawnProcess( Object *existingWorker ); ///< start the worker respawn process (again if existingWorker is non NULL)
  85. ObjectID m_workerID; ///< id of the worker that will rebuild us
  86. ObjectID m_reconstructingID; ///< ID of the object we're reconstructing
  87. ObjectID m_spawnerObjectID; ///< Object that was killed and therefore the object that created this hole
  88. UnsignedInt m_workerWaitCounter; ///< when this reaches zero we spawn a worker after death
  89. const ThingTemplate *m_workerTemplate; ///< template of the worker to make
  90. const ThingTemplate *m_rebuildTemplate; ///< what we are rebuilding
  91. };
  92. #endif // end __REBUILD_HOLE_BEHAVIOR_H_