UNIT.H 9.4 KB

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