FOOT.H 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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/FOOT.H 1 3/03/97 10:24a 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 : FOOT.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 FOOT_H
  37. #define FOOT_H
  38. #include "target.h"
  39. #include "type.h"
  40. #include "techno.h"
  41. #include "ftimer.h"
  42. class UnitClass;
  43. class BuildingClass;
  44. /****************************************************************************
  45. ** Movable objects are handled by this class definition. Moveable objects
  46. ** cover everything except buildings.
  47. */
  48. class FootClass : public TechnoClass
  49. {
  50. public:
  51. /*
  52. ** This flag controls whether a range limiting effect should be in place. If
  53. ** true, then target scanning will be limited to the range of the object
  54. ** regardless of what was requested from the target scanning logic. This value
  55. ** is used for ships so that they won't permanently stick on a an attack mission
  56. ** for a target they can never get within range of. This value will toggle when
  57. ** a path cannot be generated and the target is not within range. It will also
  58. ** toggle when path limiting is true, but there is not target found within
  59. ** the limited range.
  60. */
  61. unsigned IsScanLimited:1;
  62. /*
  63. ** If this unit has officially joined the team's group, then this flag is
  64. ** true. A newly assigned unit to a team is not considered part of the
  65. ** team until it actually reaches the location where the team is. By
  66. ** using this flag, it allows a team to continue to intelligently attack
  67. ** a target without falling back to regroup the moment a distant member
  68. ** joins.
  69. */
  70. unsigned IsInitiated:1;
  71. /*
  72. ** When the player gives this object a navigation target AND that target
  73. ** does not result in any movement of the unit, then a beep should be
  74. ** sounded. This typically occurs when selecting an invalid location for
  75. ** movement. This flag is cleared if any movement was able to be performed.
  76. ** It never gets set for computer controlled units.
  77. */
  78. unsigned IsNewNavCom:1;
  79. /*
  80. ** There are certain cases where a unit should perform a full scan rather than
  81. ** the more efficient "ring scan". This situation occurs when a unit first
  82. ** appears on the map or when it finishes a multiple cell movement track.
  83. */
  84. unsigned IsPlanningToLook:1;
  85. /*
  86. ** Certain units have the ability to metamorphize into a building. When this
  87. ** operation begins, certain processes must occur. During these operations, this
  88. ** flag will be true. This ensures that any necessary special case code gets
  89. ** properly executed for this unit.
  90. */
  91. unsigned IsDeploying:1;
  92. /*
  93. ** This flag tells the system that the unit is doing a firing animation. This is
  94. ** critical to the firing logic.
  95. */
  96. unsigned IsFiring:1;
  97. /*
  98. ** This unit could be either rotating its body or rotating its turret. During the
  99. ** process of rotation, this flag is set. By examining this flag, unnecessary logic
  100. ** can be avoided.
  101. */
  102. unsigned IsRotating:1;
  103. /*
  104. ** If this object is current driving to a short range destination, this flag is
  105. ** true. A short range destination is either the next cell or the end of the
  106. ** current "curvy" track. An object that is driving is not allowed to do anything
  107. ** else until it reaches its destination. The exception is when infantry wish to
  108. ** head to a different destination, they are allowed to start immediately.
  109. */
  110. unsigned IsDriving:1;
  111. /*
  112. ** If this object is unloading from a hover transport, then this flag will be
  113. ** set to true. This handles the unusual case of an object disembarking from the
  114. ** hover lander yet not necessarily tethered but still located in an overlapping
  115. ** position. This flag will be cleared automatically when the object moves to the
  116. ** center of a cell.
  117. */
  118. unsigned IsUnloading:1;
  119. /*
  120. ** If this object is part of a formation, this bit will be set. The
  121. ** formation only occurs when every member of a team is selected, and
  122. ** only those members of the team are the ones selected.
  123. */
  124. unsigned IsFormationMove:1;
  125. /*
  126. ** If the navigation movement queue is to be looped rather than consumed, then
  127. ** this flag will be true. By looping, the unit will travel through the locations
  128. ** in the queue indefinately.
  129. */
  130. unsigned IsNavQueueLoop:1;
  131. /*
  132. ** If this object is scattering, then this flag will be true. While true, the
  133. ** NavCom should not be arbitrarily changed. This flag will automatcially be
  134. ** cleared when the object moves one cell.
  135. */
  136. unsigned IsScattering:1;
  137. /*
  138. ** This is the "throttle setting" of the unit. It is a fractional value with 0 = stop
  139. ** and 255 = full speed.
  140. */
  141. int Speed;
  142. /*
  143. ** This is the override speed adjuster. Normally, this is a fixed point
  144. ** value of 0x0100, but it can be modified by crate powerups.
  145. */
  146. fixed SpeedBias;
  147. /*
  148. ** For units in a formation, these values represent the distance from
  149. ** the target destination where the unit should move to. For example,
  150. ** in a horizontal line formation, XFormOffset would be set to some
  151. ** value, and YFormOffset would be zero.
  152. */
  153. int XFormOffset;
  154. int YFormOffset;
  155. /*
  156. **
  157. ** This is the desired destination of the unit. The unit will attempt to head
  158. ** toward this target (avoiding intervening obstacles).
  159. */
  160. TARGET NavCom;
  161. TARGET SuspendedNavCom;
  162. /*
  163. ** A sequence of move destinations can be given to a unit. The sequence is
  164. ** stores as an array of movement targets. The list is terminated with a
  165. ** TARGET_NONE.
  166. */
  167. TARGET NavQueue[10];
  168. /*
  169. ** This points to the team that "owns" this object. This pointer is used to
  170. ** quickly process the team when this object is the source of the change. An
  171. ** example would be if this object were to be destroyed, it would inform the
  172. ** team of this fact by using this pointer.
  173. */
  174. CCPtr<TeamClass> Team;
  175. /*
  176. ** If this object is part of a pseudo-team that the player is managing, then
  177. ** this will be set to the team number (0 - 9). If it is not part of any
  178. ** pseudo-team, then the number will be -1.
  179. */
  180. unsigned char Group;
  181. /*
  182. ** This points to the next member in the team that this object is part of. This
  183. ** is used to quickly process each team member when the team class is the source
  184. ** of the change. An example would be if the team decided that everyone is going
  185. ** to move to a new location, it would inform each of the objects by chaining
  186. ** through this pointer.
  187. */
  188. FootClass * Member;
  189. /*
  190. ** Since all objects derived from this class move according to a path list.
  191. ** This is the path list. It specifies, as a simple list of facings, the
  192. ** path that the object should follow in order to reach its destination.
  193. ** This path list is limited in size, so it might require several generations
  194. ** of path lists before the ultimate destination is reached. The game logic
  195. ** handles regenerating the path list as necessary.
  196. */
  197. FacingType Path[CONQUER_PATH_MAX];
  198. /*
  199. ** This value keeps track of how serious the unit is in trying to reach the
  200. ** destination specified. As blockages arise, this threshold will rise
  201. ** unit it reaches the point of complete failure. When that event occurs, the
  202. ** unit will realize that it cannot get to its specified destination and will
  203. ** try to perform some other action instead.
  204. */
  205. MoveType PathThreshhold;
  206. /*
  207. ** When there is a complete findpath failure, this timer is initialized so
  208. ** that a findpath won't be calculated until this timer expires.
  209. */
  210. CDTimerClass<FrameTimerClass> PathDelay;
  211. enum {PATH_RETRY=10};
  212. int TryTryAgain; // Number of retry attempts remaining.
  213. /*
  214. ** If the object has recently attacked a base, then this timer will not
  215. ** have expired yet. It is used so a building does not keep calling
  216. ** for help from the same attacker.
  217. */
  218. CDTimerClass<FrameTimerClass> BaseAttackTimer;
  219. /*
  220. ** For formation moves, this will be the override speed.
  221. */
  222. SpeedType FormationSpeed;
  223. /*
  224. ** For formation moves, this will be the override maximum speed.
  225. */
  226. MPHType FormationMaxSpeed;
  227. /*---------------------------------------------------------------------
  228. ** Constructors, Destructors, and overloaded operators.
  229. */
  230. FootClass(NoInitClass const & x) : TechnoClass(x), Team(x), PathDelay(x), BaseAttackTimer(x) {};
  231. FootClass(RTTIType rtti, int id, HousesType house);
  232. /*---------------------------------------------------------------------
  233. ** Member function prototypes.
  234. */
  235. bool Basic_Path(void);
  236. virtual RadioMessageType Receive_Message(RadioClass * from, RadioMessageType message, long & param);
  237. virtual bool Can_Demolish(void) const;
  238. bool Is_Recruitable(HouseClass const * house=NULL) const;
  239. bool Is_On_Priority_Mission(void) const;
  240. /*
  241. ** Coordinate inquiry functions. These are used for both display and
  242. ** combat purposes.
  243. */
  244. virtual COORDINATE Sort_Y(void) const;
  245. virtual COORDINATE Likely_Coord(void) const;
  246. /*
  247. ** Driver control support functions. These are used to control cell
  248. ** occupation flags and driver instructions.
  249. */
  250. COORDINATE Head_To_Coord(void) const {return (HeadToCoord);};
  251. virtual bool Start_Driver(COORDINATE &headto);
  252. virtual bool Stop_Driver(void);
  253. virtual void Assign_Destination(TARGET target);
  254. bool Is_Allowed_To_Leave_Map(void) const;
  255. /*
  256. ** Display and rendering support functionality. Supports imagery and how
  257. ** object interacts with the map and thus indirectly controls rendering.
  258. */
  259. virtual bool Unlimbo(COORDINATE , DirType dir = DIR_N);
  260. virtual bool Mark(MarkType mark=MARK_CHANGE);
  261. /*
  262. ** User I/O.
  263. */
  264. virtual void Active_Click_With(ActionType action, ObjectClass * object);
  265. virtual void Active_Click_With(ActionType action, CELL cell);
  266. /*
  267. ** Combat related.
  268. */
  269. virtual void Stun(void);
  270. virtual ResultType Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source=0, bool forced=false);
  271. virtual void Death_Announcement(TechnoClass const * source=0) const;
  272. /*
  273. ** AI.
  274. */
  275. virtual void AI(void);
  276. virtual void Sell_Back(int control);
  277. virtual int Offload_Tiberium_Bail(void);
  278. virtual TARGET Greatest_Threat(ThreatType method) const;
  279. virtual void Detach(TARGET target, bool all);
  280. virtual void Detach_All(bool all=true);
  281. virtual int Mission_Retreat(void);
  282. virtual int Mission_Enter(void);
  283. virtual int Mission_Move(void);
  284. virtual int Mission_Capture(void);
  285. virtual int Mission_Attack(void);
  286. virtual int Mission_Guard(void);
  287. virtual int Mission_Hunt(void);
  288. virtual int Mission_Guard_Area(void);
  289. /*
  290. ** Scenario and debug support.
  291. */
  292. #ifdef CHEAT_KEYS
  293. virtual void Debug_Dump(MonoClass *mono) const;
  294. #endif
  295. /*
  296. ** Movement and animation.
  297. */
  298. void Handle_Navigation_List(void);
  299. void Queue_Navigation_List(TARGET target);
  300. void Clear_Navigation_List(void);
  301. virtual void Per_Cell_Process(PCPType why);
  302. virtual void Approach_Target(void);
  303. virtual void Fixup_Path(PathType *) {};
  304. virtual void Set_Speed(int speed);
  305. virtual MoveType Can_Enter_Cell(CELL cell, FacingType from=FACING_NONE) const;
  306. int Optimize_Moves(PathType *path, MoveType threshhold);
  307. virtual void Override_Mission(MissionType mission, TARGET tarcom, TARGET navcom);
  308. virtual bool Restore_Mission(void);
  309. CELL Adjust_Dest(CELL cell) const;
  310. /*
  311. ** File I/O.
  312. */
  313. virtual void Code_Pointers(void);
  314. virtual void Decode_Pointers(void);
  315. CELL Safety_Point(CELL src, CELL dst, int start, int max);
  316. int Rescue_Mission(TARGET tarcom);
  317. private:
  318. int Passable_Cell(CELL cell, FacingType face, int threat, MoveType threshhold);
  319. PathType * Find_Path(CELL dest, FacingType *final_moves, int maxlen, MoveType threshhold);
  320. void Debug_Draw_Map(char const * txt, CELL start, CELL dest, bool pause);
  321. void Debug_Draw_Path(PathType *path);
  322. bool Follow_Edge(CELL start, CELL target, PathType *path, FacingType search, FacingType olddir, int threat, int threat_stage, int max_cells, MoveType threshhold);
  323. bool Register_Cell(PathType *path, CELL cell, FacingType dir, int cost, MoveType threshhold);
  324. bool Unravel_Loop(PathType *path, CELL &cell, FacingType &dir, int sx, int sy, int dx, int dy, MoveType threshhold);
  325. /*
  326. ** This is the coordinate that the unit is heading to
  327. ** as an immediate destination. This coordinate is never further
  328. ** than once cell (or track) from the unit's location. When this coordinate
  329. ** is reached, then the next location in the path list becomes the
  330. ** next HeadTo coordinate.
  331. */
  332. COORDINATE HeadToCoord;
  333. };
  334. #endif