TEAM.H 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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/TEAM.H 1 3/03/97 10:25a 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 : TEAM.H *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 12/11/94 *
  26. * *
  27. * Last Update : December 11, 1994 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #ifndef TEAM_H
  33. #define TEAM_H
  34. #include "wwfile.h"
  35. #include "teamtype.h"
  36. #include "abstract.h"
  37. /*
  38. ** Units are only allowed to stray a certain distance away from their
  39. ** team. When they exceed this distance, some sort of fixup must be
  40. ** done.
  41. */
  42. #define STRAY_DISTANCE 2
  43. struct TeamFormDataStruct
  44. {
  45. MPHType TeamMaxSpeed[MAX_TEAMS];
  46. SpeedType TeamSpeed[MAX_TEAMS];
  47. };
  48. class TeamClass : public AbstractClass
  49. {
  50. public:
  51. /*
  52. ** This specifies the type of team this is.
  53. */
  54. CCPtr<TeamTypeClass> Class;
  55. /*
  56. ** This specifies the owner of this team.
  57. */
  58. CCPtr<HouseClass> House;
  59. /*
  60. ** This flag forces the team into active state regardless of whether it
  61. ** is understrength or not.
  62. */
  63. unsigned IsForcedActive:1;
  64. /*
  65. ** This flag is set to true when the team initiates into active mode. The
  66. ** flag is never cleared. By examining this flag, it is possible to determine
  67. ** if the team has ever launched into active mode.
  68. */
  69. unsigned IsHasBeen:1;
  70. /*
  71. ** If the team is full strength, then this flag is true. A full strength
  72. ** team will not try to recruit members.
  73. */
  74. unsigned IsFullStrength:1;
  75. /*
  76. ** A team that is below half strength has this flag true. It means that the
  77. ** the team should hide back at the owner's base and try to recruit
  78. ** members.
  79. */
  80. unsigned IsUnderStrength:1;
  81. /*
  82. ** If a team is not understrength but is not yet full strength, then
  83. ** the team is regrouping. If this flag is set and the team becomes
  84. ** full strength, the all members of the team will become initiated
  85. ** and this flag will be reset.
  86. */
  87. unsigned IsReforming:1;
  88. /*
  89. ** This bit should be set if a team is determined to have lagging
  90. ** units in its formation.
  91. */
  92. unsigned IsLagging:1;
  93. /*
  94. ** If a team member was removed or added, then this flag will be set to true. The
  95. ** team system uses this flag to tell whether it should recalculate the team
  96. ** under strength or full strength flags. This process does not need to occur
  97. ** EVERY time a unit added or deleted from a team, just every so often if the
  98. ** team has been changed.
  99. */
  100. unsigned IsAltered:1;
  101. unsigned JustAltered:1;
  102. /*
  103. ** If the team is working on it's primary mission (it is past the build up stage)
  104. ** then this flag will be true. The transition between "moving" and "stationary"
  105. ** stages usually requires some action on the team's part.
  106. */
  107. unsigned IsMoving:1;
  108. /*
  109. ** When the team determines that the next mission should be advanced to, it will
  110. ** set this flag to true. Mission advance will either change the behavior of the
  111. ** team or cause it to disband.
  112. */
  113. unsigned IsNextMission:1;
  114. /*
  115. ** If at least one member of this team successfully left the map, then this
  116. ** flag will be set. At the time the team is terminated, if this flag is true, then
  117. ** if there are any triggers that depend upon this team leaving, they will be
  118. ** sprung.
  119. */
  120. unsigned IsLeaveMap:1;
  121. /*
  122. ** Records whether the team is suspended from production.
  123. */
  124. unsigned Suspended:1;
  125. /*
  126. ** A team will have a center point. This is the point used to determine if
  127. ** any member of the team is "too far" from the team and must return. This
  128. ** center point is usually calculated as the average position of all the
  129. ** team members.
  130. */
  131. TARGET Zone;
  132. /*
  133. ** This is the target value of the team member that is closest to the
  134. ** destination of the team. The implied location serves as the
  135. ** regroup point for the unit as it is moving.
  136. */
  137. TARGET ClosestMember;
  138. /*
  139. ** This is the target of the team. Typically, it is a unit or structure, but
  140. ** for the case of teams with a movement mission, it might represent a
  141. ** destination cell.
  142. */
  143. TARGET MissionTarget;
  144. TARGET Target;
  145. /*
  146. ** This is the total number of members in this team.
  147. */
  148. int Total;
  149. /*
  150. ** This is the teams combined risk value
  151. */
  152. int Risk;
  153. /*
  154. ** If this team is assigned a formation, then the formation type
  155. ** will be stored here. If the formation type is FORMATION_NONE, then
  156. ** the team is a loose grouping -- just like C&C.
  157. */
  158. FormationType Formation;
  159. /*
  160. ** This is the amount of time the team is suspended for.
  161. */
  162. CDTimerClass<FrameTimerClass> SuspendTimer;
  163. /*
  164. ** If there is a trigger that should be attached to every member of this team, then
  165. ** it is pointed to by this.
  166. */
  167. CCPtr<TriggerClass> Trigger;
  168. //------------------------------------------------------------
  169. TeamClass(TeamTypeClass const * team=0, HouseClass * owner=0);
  170. TeamClass(NoInitClass const & x) : AbstractClass(x), Class(x), House(x), SuspendTimer(x), Trigger(x), TimeOut(x), Member(x) {};
  171. virtual ~TeamClass(void);
  172. static void operator delete(void *ptr);
  173. static void * operator new(size_t size);
  174. static void * operator new(size_t, void * ptr) {return(ptr);};
  175. static void Init(void);
  176. static void Suspend_Teams(int priority, HouseClass const * house);
  177. void Debug_Dump(MonoClass * mono) const;
  178. /*
  179. ** File I/O.
  180. */
  181. bool Load(Straw & file);
  182. bool Save(Pipe & file) const;
  183. void Code_Pointers(void);
  184. void Decode_Pointers(void);
  185. bool Is_Empty(void) const {return(Member == (void*)NULL);}
  186. bool Has_Entered_Map(void) const;
  187. void Force_Active(void) {IsForcedActive = true;IsUnderStrength=false;};
  188. bool Remove(FootClass *, int typeindex=-1);
  189. void Detach(TARGET target, bool all);
  190. void AI(void);
  191. void Took_Damage(FootClass * obj, ResultType result, TechnoClass * source);
  192. bool Add(FootClass *);
  193. bool Can_Add(FootClass * obj, int & typeindex) const;
  194. void Assign_Mission_Target(TARGET new_target);
  195. bool Is_Leaving_Map(void) const;
  196. void Scan_Limit(void);
  197. private:
  198. /*
  199. ** The current mission index into the mission list is recorded here.
  200. */
  201. int CurrentMission;
  202. /*
  203. ** Some missions will time out. This is the timer that keeps track of the
  204. ** time to transition between missions.
  205. */
  206. CDTimerClass<FrameTimerClass> TimeOut;
  207. int TMission_Formation(void);
  208. int TMission_Attack(void);
  209. int TMission_Spy(void);
  210. int TMission_Follow(void);
  211. int TMission_Loop(void);
  212. int TMission_Load(void);
  213. int TMission_Unload(void);
  214. int TMission_Invulnerable(void);
  215. int TMission_Set_Global(void);
  216. int TMission_Patrol(void);
  217. int TMission_Deploy(void);
  218. bool Coordinate_Regroup(void);
  219. void Coordinate_Attack(void);
  220. void Coordinate_Move(void);
  221. bool Coordinate_Conscript(FootClass * unit);
  222. void Coordinate_Do(void);
  223. void Calc_Center(TARGET &center, TARGET &obj_center) const;
  224. int Recruit(int typeindex);
  225. bool Is_A_Member(void const * who) const;
  226. bool Lagging_Units(void);
  227. FootClass * Fetch_A_Leader(void) const;
  228. /*
  229. ** Points to the first member in the list of members for this team.
  230. */
  231. SmartPtr<FootClass> Member;
  232. unsigned char Quantity[TeamTypeClass::MAX_TEAM_CLASSCOUNT];
  233. /*
  234. ** Some additional padding in case we need to add data to the class and maintain backwards compatibility for save/load
  235. */
  236. unsigned char SaveLoadPadding[32];
  237. };
  238. #endif