DockUpdate.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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: DockUpdate.h /////////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood Feb 2002
  25. // Desc: Behavior common to all DockUpdates is here. Everything but action()
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef _DOCK_UPDATE_H_
  29. #define _DOCK_UPDATE_H_
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/INI.h"
  32. #include "Common/GameMemory.h"
  33. #include "Common/STLTypedefs.h"
  34. #include "GameLogic/Module/UpdateModule.h"
  35. enum
  36. {
  37. DEFAULT_APPROACH_VECTOR_SIZE = 10
  38. };
  39. enum
  40. {
  41. DYNAMIC_APPROACH_VECTOR_FLAG = -1
  42. };
  43. //-------------------------------------------------------------------------------------------------
  44. class DockUpdateModuleData : public UpdateModuleData
  45. {
  46. public:
  47. Int m_numberApproachPositionsData; // A positive number is an absolute, DYNAMIC_APPROACH_VECTOR_FLAG means dynamic vector
  48. Bool m_isAllowPassthrough;
  49. DockUpdateModuleData();
  50. static void buildFieldParse(MultiIniFieldParse& p);
  51. };
  52. //-------------------------------------------------------------------------------------------------
  53. class DockUpdate : public UpdateModule , public DockUpdateInterface
  54. {
  55. MEMORY_POOL_GLUE_ABC( DockUpdate )
  56. MAKE_STANDARD_MODULE_MACRO_ABC( DockUpdate )
  57. MAKE_STANDARD_MODULE_DATA_MACRO_ABC( DockUpdate, DockUpdateModuleData )
  58. public:
  59. DockUpdate( Thing *thing, const ModuleData* moduleData );
  60. // virtual destructor provided by memory pool object
  61. /** Returns true if it is okay for the docker to approach and prepare to dock.
  62. False could mean the queue is full, for example.
  63. */
  64. virtual Bool isClearToApproach( Object const* docker ) const;
  65. /** Give me a Queue point to drive to, and record that that point is taken.
  66. Returning NULL means there are none free
  67. */
  68. virtual Bool reserveApproachPosition( Object* docker, Coord3D *position, Int *index );
  69. /** Give me the next Queue point to drive to, and record that that point is taken.
  70. */
  71. virtual Bool advanceApproachPosition( Object* docker, Coord3D *position, Int *index );
  72. /** Return true when it is OK for docker to begin entering the dock
  73. The Dock will lift the restriction on one particular docker on its own,
  74. so you must continually ask.
  75. */
  76. virtual Bool isClearToEnter( Object const* docker ) const;
  77. /** Return true when it is OK for docker to request a new Approach position. The dock is in
  78. charge of keeping track of holes in the line, but the docker will remind us of their spot.
  79. */
  80. virtual Bool isClearToAdvance( Object const* docker, Int dockerIndex ) const;
  81. /** Give me the point that is the start of your docking path
  82. Returning NULL means there is none free
  83. All functions take docker as arg so we could have multiple docks on a building.
  84. Docker is not assumed, it is recorded and checked.
  85. */
  86. virtual void getEnterPosition( Object* docker, Coord3D *position );
  87. /** Give me the middle point of the dock process where the action() happens */
  88. virtual void getDockPosition( Object* docker, Coord3D *position );
  89. /** Give me the point to drive to when I am done */
  90. virtual void getExitPosition( Object* docker, Coord3D *position );
  91. virtual void onApproachReached( Object* docker ); ///< I have reached the Approach Point.
  92. virtual void onEnterReached( Object* docker ); ///< I have reached the Enter Point.
  93. virtual void onDockReached( Object* docker ); ///< I have reached the Dock point
  94. virtual void onExitReached( Object* docker ); ///< I have reached the exit. You are no longer busy
  95. //The fact that action() is not here is intentional. This object cannot exist. You must
  96. //derive off it and implement action().
  97. virtual void cancelDock( Object* docker ); ///< Clear me from any reserved points, and if I was the reason you were Busy, you aren't anymore.
  98. virtual Bool isDockOpen( void ) { return m_dockOpen; } ///< Is the dock open to accepting dockers
  99. virtual void setDockOpen( Bool open ) { m_dockOpen = open; } ///< Open/Close the dock
  100. virtual Bool isAllowPassthroughType(); ///< Not all docks allow you to path through them in your AIDock machine
  101. virtual Bool isRallyPointAfterDockType(){return FALSE;} ///< A minority of docks want to give you a final command to their rally point
  102. virtual void setDockCrippled( Bool setting ); ///< Game Logic can set me as inoperative. I get to decide what that means.
  103. virtual UpdateSleepTime update(); ///< In charge of lifting dock restriction for one registered as Approached if all is ready
  104. protected:
  105. // These are const data read from the drawable when first asked for them
  106. Coord3D m_enterPosition;
  107. Coord3D m_dockPosition;
  108. Coord3D m_exitPosition;
  109. Int m_numberApproachPositions;
  110. Int m_numberApproachPositionBones;
  111. // These are real variables local to my specific needs here in DockUpdate
  112. Bool m_positionsLoaded; ///< FALSE until we have loaded all the docking positions
  113. VecCoord3D m_approachPositions;
  114. ObjectIDVector m_approachPositionOwners; ///< Who is in or at least reserved each spot
  115. BoolVector m_approachPositionReached; ///< Which positions have actually been reached
  116. ObjectID m_activeDocker; ///< we could expand this to multiple dock paths since we always get docker in our methods
  117. Bool m_dockerInside; ///< This is true while our active docker is between Enter and Exit. This is shorter than activeDocker's lifetime as it doesn't include approach to enter
  118. Bool m_dockCrippled; ///< Has game logic set me as crippled?
  119. Bool m_dockOpen; ///< Is the dock open for dockers
  120. void loadDockPositions(); ///< load all the dock positions
  121. Coord3D computeApproachPosition( Int positionIndex, Object *forWhom ); ///< Do a smart lookup of this bone position
  122. };
  123. #endif