BuildAssistant.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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: BuildAssistant.h /////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, February 2002
  25. // Desc: Singleton class to encapsulate some of the more common functions or rules
  26. // that apply to building structures and units
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. #pragma once
  29. #ifndef __BUILDASSISTANT_H_
  30. #define __BUILDASSISTANT_H_
  31. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  32. #include "Common/STLTypedefs.h"
  33. #include "Lib/BaseType.h"
  34. #include "Common/SubsystemInterface.h"
  35. #include "GameLogic/Object.h"
  36. // FORWARD DECLARATIONS ///////////////////////////////////////////////////////////////////////////
  37. class ThingTemplate;
  38. class Player;
  39. class Object;
  40. // ------------------------------------------------------------------------------------------------
  41. // this enum is used for the construction percent of objects
  42. enum { CONSTRUCTION_COMPLETE = -1 };
  43. typedef void (*IterateFootprintFunc)( const Coord3D *samplePoint, void *userData );
  44. // ------------------------------------------------------------------------------------------------
  45. class ObjectSellInfo : public MemoryPoolObject
  46. {
  47. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( ObjectSellInfo, "ObjectSellInfo" )
  48. public:
  49. ObjectSellInfo( void );
  50. // virtual destructor prototypes provided by memory pool object
  51. ObjectID m_id; ///< id of object to sell
  52. UnsignedInt m_sellFrame; ///< frame the sell occurred on
  53. };
  54. // ------------------------------------------------------------------------------------------------
  55. typedef std::list<ObjectSellInfo *> ObjectSellList;
  56. typedef ObjectSellList::iterator ObjectSellListIterator;
  57. //-------------------------------------------------------------------------------------------------
  58. /** Return codes for queries about being able to build */
  59. //-------------------------------------------------------------------------------------------------
  60. enum CanMakeType
  61. {
  62. CANMAKE_OK,
  63. CANMAKE_NO_PREREQ,
  64. CANMAKE_NO_MONEY,
  65. CANMAKE_FACTORY_IS_DISABLED,
  66. CANMAKE_QUEUE_FULL, // production bldg has full production queue
  67. CANMAKE_PARKING_PLACES_FULL, // production bldg has finite slots for existing units
  68. CANMAKE_MAXED_OUT_FOR_PLAYER // player has as many as they are allowed at once (eg, Black Lotus
  69. };
  70. //-------------------------------------------------------------------------------------------------
  71. /** Return codes for queries about legal build locations */
  72. //-------------------------------------------------------------------------------------------------
  73. enum LegalBuildCode
  74. {
  75. LBC_OK = 0,
  76. LBC_RESTRICTED_TERRAIN,
  77. LBC_NOT_FLAT_ENOUGH,
  78. LBC_OBJECTS_IN_THE_WAY,
  79. LBC_NO_CLEAR_PATH,
  80. LBC_SHROUD,
  81. LBC_TOO_CLOSE_TO_SUPPLIES,
  82. LBC_GENERIC_FAILURE,
  83. };
  84. //-------------------------------------------------------------------------------------------------
  85. //-------------------------------------------------------------------------------------------------
  86. class BuildAssistant : public SubsystemInterface
  87. {
  88. public:
  89. struct TileBuildInfo
  90. {
  91. Int tilesUsed;
  92. Coord3D *positions;
  93. };
  94. enum LocalLegalToBuildOptions
  95. {
  96. TERRAIN_RESTRICTIONS = 0x00000001, ///< Check for basic terrain restrictions
  97. CLEAR_PATH = 0x00000002, ///< Must be able to path find to location
  98. NO_OBJECT_OVERLAP = 0X00000004, ///< Can't overlap enemy objects, or locally controled objects that can't move out of the way
  99. USE_QUICK_PATHFIND = 0x00000008, ///< Use the quick pathfind method for CLEAR_PATH
  100. SHROUD_REVEALED = 0x00000010, ///< Check to make sure the shroud is revealed
  101. NO_ENEMY_OBJECT_OVERLAP = 0x00000020, ///< Can't overlap enemy objects only.
  102. IGNORE_STEALTHED = 0x00000040, ///< Units that we can't see are legal to "build" on. (when moving mouse around)
  103. FAIL_STEALTHED_WITHOUT_FEEDBACK = 0x00000080 ///< USE WITH IGNORE_STEALTHED except it will fail without BIB feedback (when clicking to place).
  104. };
  105. public:
  106. BuildAssistant( void );
  107. virtual ~BuildAssistant( void );
  108. virtual void init( void ); ///< for subsytem
  109. virtual void reset( void ); ///< for subsytem
  110. virtual void update( void ); ///< for subsytem
  111. /// iterate the "footprint" area of a structure at the given "sample resolution"
  112. void iterateFootprint( const ThingTemplate *build,
  113. Real buildOrientation,
  114. const Coord3D *worldPos,
  115. Real sampleResolution,
  116. IterateFootprintFunc func,
  117. void *funcUserData );
  118. /// create object from a build and put it in the world now
  119. virtual Object *buildObjectNow( Object *constructorObject, const ThingTemplate *what,
  120. const Coord3D *pos, Real angle, Player *owningPlayer );
  121. /// using the "line placement" for objects (like walls etc) create that line of objects line
  122. virtual void buildObjectLineNow( Object *constructorObject, const ThingTemplate *what,
  123. const Coord3D *start, const Coord3D *end, Real angle,
  124. Player *owningPlayer );
  125. /// query if we can build at this location
  126. virtual LegalBuildCode isLocationLegalToBuild( const Coord3D *worldPos,
  127. const ThingTemplate *build,
  128. Real angle, // angle to construct 'build' at
  129. UnsignedInt options, // use LocationLegalToBuildOptions
  130. Object *builderObject,
  131. Player *player);
  132. /// query if we can build at this location
  133. virtual LegalBuildCode isLocationClearOfObjects( const Coord3D *worldPos,
  134. const ThingTemplate *build,
  135. Real angle, // angle to construct 'build' a
  136. Object *builderObject,
  137. UnsignedInt options,
  138. Player *thePlayer);
  139. /// Adds bib highlighting for this location.
  140. virtual void addBibs( const Coord3D *worldPos,
  141. const ThingTemplate *build );
  142. /// tiling wall object helper function, we can use this to "tile" walls when building
  143. virtual TileBuildInfo *buildTiledLocations( const ThingTemplate *thingBeingTiled,
  144. Real angle, // angle to consturct thing being tiled
  145. const Coord3D *start, const Coord3D *end,
  146. Real tilingSize, Int maxTiles,
  147. Object *builderObject );
  148. /// return the "scratch pad" array that can be used to create a line of build locations
  149. virtual inline Coord3D *getBuildLocations( void ) { return m_buildPositions; }
  150. /// is the template a line build object, like a wall
  151. virtual Bool isLineBuildTemplate( const ThingTemplate *tTemplate );
  152. /// are all the requirements for making this unit satisfied
  153. virtual CanMakeType canMakeUnit( Object *builder, const ThingTemplate *whatToBuild ) const;
  154. /// are all the requirements for making this unit (except available cash) are satisfied
  155. virtual Bool isPossibleToMakeUnit( Object *builder, const ThingTemplate *whatToBuild ) const;
  156. /// sell an object
  157. virtual void sellObject( Object *obj );
  158. void xferTheSellList(Xfer *xfer );
  159. protected:
  160. /// some objects will be "cleared" automatically when constructing
  161. Bool isRemovableForConstruction( Object *obj );
  162. /// clear the area of removable objects for construction
  163. void clearRemovableForConstruction( const ThingTemplate *whatToBuild,
  164. const Coord3D *pos, Real angle );
  165. /// will move objects that can move out of the way.
  166. /// will return false if there are objects that cannot be moved out of the way.
  167. Bool moveObjectsForConstruction( const ThingTemplate *whatToBuild,
  168. const Coord3D *pos, Real angle, Player *playerToBuild );
  169. Coord3D *m_buildPositions; ///< array used to create a line of build locations (think walls)
  170. Int m_buildPositionSize; ///< number of elements in the build position array
  171. ObjectSellList m_sellList; ///< list of objects currently going through the "sell process"
  172. }; // end BuildAssistant
  173. // EXTERN /////////////////////////////////////////////////////////////////////////////////////////
  174. extern BuildAssistant *TheBuildAssistant;
  175. #endif // __BUILDASSISTANT_H_