UNIT.H 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. ** Command & Conquer Red Alert(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. /* $Header: /CounterStrike/UNIT.H 1 3/03/97 10:26a Joe_bostic $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : UNIT.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 14, 1994 *
  30. * *
  31. * Last Update : April 14, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef UNIT_H
  37. #define UNIT_H
  38. #include "drive.h"
  39. #include "radio.h"
  40. #include "cargo.h"
  41. #include "mission.h"
  42. #include "target.h"
  43. /****************************************************************************
  44. ** For each instance of a unit (vehicle) in the game, there is one of
  45. ** these structures. This structure holds information that is specific
  46. ** and dynamic for a particular unit.
  47. */
  48. class UnitClass : public DriveClass
  49. {
  50. public:
  51. /*
  52. ** This points to the static control data that gives 'this' unit its characteristics.
  53. */
  54. CCPtr<UnitTypeClass> Class;
  55. /*
  56. ** This records the house flag that this object is currently carrying.
  57. */
  58. HousesType Flagged;
  59. /*
  60. ** This flag is used for when the harvester dumps ore, to track its
  61. ** special animation.
  62. */
  63. unsigned IsDumping:1;
  64. /*
  65. ** This is a count of the # of loads of the various minerals that the
  66. ** unit has harvested.
  67. */
  68. unsigned Gold:5;
  69. unsigned Gems:5;
  70. /*
  71. ** This flag tells a unit that, if after reaching its destination, it
  72. ** should scatter away. It's meant to help a LST unload its units by
  73. ** having its previous passengers get out of the way.
  74. */
  75. unsigned IsToScatter:1;
  76. /*
  77. ** This records the number of "loads" of Tiberium the unit is carrying. Only
  78. ** harvesters use this field.
  79. */
  80. int Tiberium;
  81. /*
  82. ** This is the area where a mobile gap generator stores the previously-held
  83. ** shroud values for the cells surrounding itself.
  84. */
  85. unsigned long ShroudBits;
  86. /*
  87. ** This is the center coordinate for the mobile gap generator, as to
  88. ** what cells should be revealed (according to ShroudBits)
  89. */
  90. CELL ShroudCenter;
  91. /*
  92. ** This is the timer that controls the reload rate. The MSAM rocket
  93. ** launcher is the primary user of this.
  94. */
  95. CDTimerClass<FrameTimerClass> Reload;
  96. /*
  97. ** This is the facing of the turret. It can be, and usually is,
  98. ** rotated independently of the body it is attached to.
  99. */
  100. FacingClass SecondaryFacing;
  101. /*---------------------------------------------------------------------
  102. ** Constructors, Destructors, and overloaded operators.
  103. */
  104. static void * operator new(size_t size);
  105. static void * operator new(size_t , void * ptr) {return(ptr);};
  106. static void operator delete(void *ptr);
  107. UnitClass(UnitType classid, HousesType house);
  108. UnitClass(NoInitClass const & x) : DriveClass(x), Class(x), Reload(x), SecondaryFacing(x) {};
  109. operator UnitType(void) const {return Class->Type;};
  110. virtual ~UnitClass(void);
  111. /*---------------------------------------------------------------------
  112. ** Member function prototypes.
  113. */
  114. virtual ObjectTypeClass const & Class_Of(void) const;
  115. static void Init(void);
  116. bool Goto_Clear_Spot(void);
  117. bool Try_To_Deploy(void);
  118. virtual void Scatter(COORDINATE threat, bool forced=false, bool nokidding=false);
  119. bool Tiberium_Check(CELL &center, int x, int y);
  120. bool Flag_Attach(HousesType house);
  121. bool Flag_Remove(void);
  122. bool Goto_Tiberium(int radius);
  123. bool Harvesting(void);
  124. void APC_Close_Door(void);
  125. void APC_Open_Door(void);
  126. /*
  127. ** Query functions.
  128. */
  129. bool Should_Crush_It(TechnoClass const * it) const;
  130. int Credit_Load(void) const;
  131. virtual DirType Turret_Facing(void) const {if (Class->IsTurretEquipped) return(SecondaryFacing.Current());return(PrimaryFacing.Current());}
  132. int Shape_Number(void) const;
  133. virtual int Pip_Count(void) const;
  134. virtual InfantryType Crew_Type(void) const;
  135. virtual DirType Fire_Direction(void) const;
  136. virtual bool Ok_To_Move(DirType facing) const;
  137. virtual FireErrorType Can_Fire(TARGET target, int which) const;
  138. virtual fixed Tiberium_Load(void) const;
  139. /*
  140. ** Coordinate inquiry functions. These are used for both display and
  141. ** combat purposes.
  142. */
  143. virtual COORDINATE Sort_Y(void) const;
  144. /*
  145. ** Object entry and exit from the game system.
  146. */
  147. virtual bool Limbo(void);
  148. virtual bool Unlimbo(COORDINATE , DirType facing=DIR_N);
  149. /*
  150. ** Display and rendering support functionality. Supports imagery and how
  151. ** object interacts with the map and thus indirectly controls rendering.
  152. */
  153. virtual short const * Overlap_List(bool redraw=false) const;
  154. virtual void Draw_It(int x, int y, WindowNumberType window) const;
  155. /*
  156. ** User I/O.
  157. */
  158. virtual ActionType What_Action(CELL cell) const;
  159. virtual ActionType What_Action(ObjectClass const * object) const;
  160. virtual void Active_Click_With(ActionType action, ObjectClass * object);
  161. virtual void Active_Click_With(ActionType action, CELL cell);
  162. /*
  163. ** Combat related.
  164. */
  165. virtual ResultType Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source=0, bool forced=false);
  166. virtual BulletClass * Fire_At(TARGET target, int which=0);
  167. /*
  168. ** Driver control support functions. These are used to control cell
  169. ** occupation flags and driver instructions.
  170. */
  171. virtual bool Start_Driver(COORDINATE & coord);
  172. /*
  173. ** AI.
  174. */
  175. virtual TARGET Greatest_Threat(ThreatType threat) const;
  176. virtual DirType Desired_Load_Dir(ObjectClass * passenger, CELL & moveto) const;
  177. virtual RadioMessageType Receive_Message(RadioClass * from, RadioMessageType message, long & param);
  178. virtual void AI(void);
  179. virtual int Mission_Guard_Area(void);
  180. virtual int Mission_Unload(void);
  181. virtual int Mission_Guard(void);
  182. virtual int Mission_Harvest(void);
  183. virtual int Mission_Hunt(void);
  184. virtual int Mission_Repair(void);
  185. virtual int Mission_Move(void);
  186. void Rotation_AI(void);
  187. void Firing_AI(void);
  188. void Reload_AI(void);
  189. bool Edge_Of_World_AI(void);
  190. /*
  191. ** Scenario and debug support.
  192. */
  193. #ifdef CHEAT_KEYS
  194. virtual void Debug_Dump(MonoClass *mono) const;
  195. #endif
  196. /*
  197. ** Movement and animation.
  198. */
  199. virtual void Assign_Destination(TARGET target);
  200. virtual void Overrun_Square(CELL cell, bool threaten=true);
  201. virtual void Approach_Target(void);
  202. virtual int Offload_Tiberium_Bail(void);
  203. virtual void Enter_Idle_Mode(bool initial=false);
  204. virtual MoveType Can_Enter_Cell(CELL cell, FacingType facing=FACING_NONE) const;
  205. virtual void Per_Cell_Process(PCPType why);
  206. void Exit_Repair(void);
  207. void Shroud_Regen(void);
  208. /*
  209. ** File I/O.
  210. */
  211. static void Read_INI(CCINIClass & ini);
  212. static void Write_INI(CCINIClass & ini);
  213. static char *INI_Name(void) {return "UNITS";};
  214. bool Load(Straw & file);
  215. bool Save(Pipe & file) const;
  216. };
  217. #endif