DefaultProductionExitUpdate.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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: DefaultProductionExitUpdate.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, January, 2002
  25. // Desc: Hand off produced Units to me so I can Exit them into the world with my specific style
  26. // This instance simply spits the guy out at a point.
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. #pragma once
  29. #ifndef _DEFAULT_PRODUCTION_EXIT_UPDATE_H
  30. #define _DEFAULT_PRODUCTION_EXIT_UPDATE_H
  31. #include "GameLogic/Module/UpdateModule.h"
  32. #include "Common/INI.h"
  33. #include "Lib/BaseType.h"
  34. class Object;
  35. //-------------------------------------------------------------------------------------------------
  36. class DefaultProductionExitUpdateModuleData : public UpdateModuleData
  37. {
  38. public:
  39. Coord3D m_unitCreatePoint;
  40. Coord3D m_naturalRallyPoint;
  41. Bool m_useSpawnRallyPoint;
  42. DefaultProductionExitUpdateModuleData()
  43. {
  44. m_unitCreatePoint.zero();
  45. m_naturalRallyPoint.zero();
  46. m_useSpawnRallyPoint = false;
  47. }
  48. static void buildFieldParse(MultiIniFieldParse& p)
  49. {
  50. UpdateModuleData::buildFieldParse(p);
  51. static const FieldParse dataFieldParse[] =
  52. {
  53. { "UnitCreatePoint", INI::parseCoord3D, NULL, offsetof( DefaultProductionExitUpdateModuleData, m_unitCreatePoint ) },
  54. { "NaturalRallyPoint", INI::parseCoord3D, NULL, offsetof( DefaultProductionExitUpdateModuleData, m_naturalRallyPoint ) },
  55. { "UseSpawnRallyPoint", INI::parseBool, NULL, offsetof( DefaultProductionExitUpdateModuleData, m_useSpawnRallyPoint ) },
  56. { 0, 0, 0, 0 }
  57. };
  58. p.add(dataFieldParse);
  59. }
  60. };
  61. //-------------------------------------------------------------------------------------------------
  62. class DefaultProductionExitUpdate : public UpdateModule, public ExitInterface
  63. {
  64. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( DefaultProductionExitUpdate, "DefaultProductionExitUpdate" )
  65. MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( DefaultProductionExitUpdate, DefaultProductionExitUpdateModuleData )
  66. public:
  67. virtual ExitInterface* getUpdateExitInterface() { return this; }
  68. DefaultProductionExitUpdate( Thing *thing, const ModuleData* moduleData );
  69. // virtual destructor prototype provided by memory pool declaration
  70. // Required funcs to fufill interface requirements
  71. virtual Bool isExitBusy() const {return FALSE;} ///< Contain style exiters are getting the ability to space out exits, so ask this before reserveDoor as a kind of no-commitment check.
  72. virtual ExitDoorType reserveDoorForExit( const ThingTemplate* objType, Object *specificObject ) { return DOOR_1; }
  73. virtual void exitObjectViaDoor( Object *newObj, ExitDoorType exitDoor );
  74. virtual void unreserveDoorForExit( ExitDoorType exitDoor ) { /* nothing */ }
  75. virtual void exitObjectByBudding( Object *newObj, Object *budHost ) { return; }
  76. virtual void setRallyPoint( const Coord3D *pos ); ///< define a "rally point" for units to move towards
  77. virtual const Coord3D *getRallyPoint( void ) const; ///< define a "rally point" for units to move towards
  78. virtual Bool useSpawnRallyPoint( void ) const;
  79. virtual Bool getNaturalRallyPoint( Coord3D& rallyPoint, Bool offset = TRUE ) const; ///< get the natural "rally point" for units to move towards
  80. virtual Bool getExitPosition( Coord3D& exitPosition ) const; ///< access to the "Door" position of the production object
  81. virtual UpdateSleepTime update() { return UPDATE_SLEEP_FOREVER; }
  82. protected:
  83. Coord3D m_rallyPoint; ///< Where units should move to after they have reached the "natural" rally point
  84. Bool m_rallyPointExists; ///< Only move to the rally point if this is true
  85. };
  86. //-------------------------------------------------------------------------------------------------
  87. inline void DefaultProductionExitUpdate::setRallyPoint( const Coord3D *pos )
  88. {
  89. m_rallyPoint = *pos;
  90. m_rallyPointExists = true;
  91. }
  92. //-------------------------------------------------------------------------------------------------
  93. inline const Coord3D *DefaultProductionExitUpdate::getRallyPoint( void ) const
  94. {
  95. if (m_rallyPointExists)
  96. return &m_rallyPoint;
  97. return NULL;
  98. }
  99. //-------------------------------------------------------------------------------------------------
  100. inline Bool DefaultProductionExitUpdate::useSpawnRallyPoint( void ) const
  101. {
  102. // Check if the building has requested spawn units (like those that are airdropped)
  103. // to use the rally points of the building.
  104. if (getDefaultProductionExitUpdateModuleData()->m_useSpawnRallyPoint)
  105. return TRUE;
  106. else
  107. return FALSE;
  108. }
  109. #endif