BuildAssistant.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. ** Command & Conquer Generals(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. };
  83. //-------------------------------------------------------------------------------------------------
  84. //-------------------------------------------------------------------------------------------------
  85. class BuildAssistant : public SubsystemInterface
  86. {
  87. public:
  88. struct TileBuildInfo
  89. {
  90. Int tilesUsed;
  91. Coord3D *positions;
  92. };
  93. enum LocalLegalToBuildOptions
  94. {
  95. TERRAIN_RESTRICTIONS = 0x00000001, ///< Check for basic terrain restrictions
  96. CLEAR_PATH = 0x00000002, ///< Must be able to path find to location
  97. NO_OBJECT_OVERLAP = 0X00000004, ///< Can't overlap enemy objects, or locally controled objects that can't move out of the way
  98. USE_QUICK_PATHFIND = 0x00000008, ///< Use the quick pathfind method for CLEAR_PATH
  99. SHROUD_REVEALED = 0x00000010, ///< Check to make sure the shroud is revealed
  100. NO_ENEMY_OBJECT_OVERLAP=0x00000020, ///< Can't overlap enemy objects only.
  101. };
  102. public:
  103. BuildAssistant( void );
  104. virtual ~BuildAssistant( void );
  105. virtual void init( void ); ///< for subsytem
  106. virtual void reset( void ); ///< for subsytem
  107. virtual void update( void ); ///< for subsytem
  108. /// iterate the "footprint" area of a structure at the given "sample resolution"
  109. void iterateFootprint( const ThingTemplate *build,
  110. Real buildOrientation,
  111. const Coord3D *worldPos,
  112. Real sampleResolution,
  113. IterateFootprintFunc func,
  114. void *funcUserData );
  115. /// create object from a build and put it in the world now
  116. virtual Object *buildObjectNow( Object *constructorObject, const ThingTemplate *what,
  117. const Coord3D *pos, Real angle, Player *owningPlayer );
  118. /// using the "line placement" for objects (like walls etc) create that line of objects line
  119. virtual void buildObjectLineNow( Object *constructorObject, const ThingTemplate *what,
  120. const Coord3D *start, const Coord3D *end, Real angle,
  121. Player *owningPlayer );
  122. /// query if we can build at this location
  123. virtual LegalBuildCode isLocationLegalToBuild( const Coord3D *worldPos,
  124. const ThingTemplate *build,
  125. Real angle, // angle to construct 'build' at
  126. UnsignedInt options, // use LocationLegalToBuildOptions
  127. Object *builderObject,
  128. Player *player);
  129. /// query if we can build at this location
  130. virtual Bool isLocationClearOfObjects( const Coord3D *worldPos,
  131. const ThingTemplate *build,
  132. Real angle, // angle to construct 'build' a
  133. Object *builderObject,
  134. UnsignedInt options,
  135. Player *thePlayer);
  136. /// Adds bib highlighting for this location.
  137. virtual void addBibs( const Coord3D *worldPos,
  138. const ThingTemplate *build );
  139. /// tiling wall object helper function, we can use this to "tile" walls when building
  140. virtual TileBuildInfo *buildTiledLocations( const ThingTemplate *thingBeingTiled,
  141. Real angle, // angle to consturct thing being tiled
  142. const Coord3D *start, const Coord3D *end,
  143. Real tilingSize, Int maxTiles,
  144. Object *builderObject );
  145. /// return the "scratch pad" array that can be used to create a line of build locations
  146. virtual inline Coord3D *getBuildLocations( void ) { return m_buildPositions; }
  147. /// is the template a line build object, like a wall
  148. virtual Bool isLineBuildTemplate( const ThingTemplate *tTemplate );
  149. /// are all the requirements for making this unit satisfied
  150. virtual CanMakeType canMakeUnit( Object *builder, const ThingTemplate *whatToBuild ) const;
  151. /// are all the requirements for making this unit (except available cash) are satisfied
  152. virtual Bool isPossibleToMakeUnit( Object *builder, const ThingTemplate *whatToBuild ) const;
  153. /// sell an object
  154. virtual void sellObject( Object *obj );
  155. void xferTheSellList(Xfer *xfer );
  156. protected:
  157. /// some objects will be "cleared" automatically when constructing
  158. Bool isRemovableForConstruction( Object *obj );
  159. /// clear the area of removable objects for construction
  160. void clearRemovableForConstruction( const ThingTemplate *whatToBuild,
  161. const Coord3D *pos, Real angle );
  162. /// will move objects that can move out of the way.
  163. /// will return false if there are objects that cannot be moved out of the way.
  164. Bool moveObjectsForConstruction( const ThingTemplate *whatToBuild,
  165. const Coord3D *pos, Real angle, Player *playerToBuild );
  166. Coord3D *m_buildPositions; ///< array used to create a line of build locations (think walls)
  167. Int m_buildPositionSize; ///< number of elements in the build position array
  168. ObjectSellList m_sellList; ///< list of objects currently going through the "sell process"
  169. }; // end BuildAssistant
  170. // EXTERN /////////////////////////////////////////////////////////////////////////////////////////
  171. extern BuildAssistant *TheBuildAssistant;
  172. #endif // __BUILDASSISTANT_H_