TEAM.CPP 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. /*
  2. ** Command & Conquer(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: F:\projects\c&c\vcs\code\team.cpv 2.18 16 Oct 1995 16:48:34 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 : TEAM.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 12/11/94 *
  30. * *
  31. * Last Update : August 6, 1995 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * Assign_Mission_Target -- Sets teams mission target and clears old target *
  36. * TeamClass::Add -- Adds specified object to team. *
  37. * TeamClass::AI -- Process team logic. *
  38. * TeamClass::As_Target -- Converts this team object into a target number. *
  39. * TeamClass::Calc_Center -- Determines average location of team members. *
  40. * TeamClass::Control -- Updates control on a member unit. *
  41. * TeamClass::Coordinate_Attack -- Handles coordinating a team attack. *
  42. * TeamClass::Coordinate_Conscript -- Gives orders to new recruit. *
  43. * TeamClass::Coordinate_Move -- Handles team movement coordination. *
  44. * TeamClass::Coordinate_Regroup -- Handles team idling (regrouping). *
  45. * TeamClass::Coordinate_Unload -- Tells the team to unload passengers now. *
  46. * TeamClass::Detach -- Removes specified target from team tracking. *
  47. * TeamClass::Init -- Initializes the team objects for scenario preparation. *
  48. * TeamClass::Is_A_Member -- Tests if a unit is a member of a team *
  49. * TeamClass::Recruit -- Attempts to recruit members to the team for the given index ID. *
  50. * TeamClass::Remove -- Removes the specified object from the team. *
  51. * TeamClass::Suspend_Teams -- Suspends activity for low priority teams *
  52. * TeamClass::Took_Damage -- Informs the team when the team member takes damage. *
  53. * TeamClass::Validate -- validates team pointer *
  54. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  55. #include "function.h"
  56. #include "mission.h"
  57. /*
  58. ** This array records the number of teams in existance of each type.
  59. */
  60. unsigned char TeamClass::Number[TEAMTYPE_MAX];
  61. /*
  62. ** This array records the success rating of each of the team types.
  63. */
  64. unsigned char TeamClass::Success[TEAMTYPE_MAX];
  65. /*
  66. ** This contains the value of the Virtual Function Table Pointer
  67. */
  68. void * TeamClass::VTable;
  69. /***********************************************************************************************
  70. * TeamClass::Validate -- validates team pointer *
  71. * *
  72. * INPUT: *
  73. * none. *
  74. * *
  75. * OUTPUT: *
  76. * 1 = ok, 0 = error *
  77. * *
  78. * WARNINGS: *
  79. * none. *
  80. * *
  81. * HISTORY: *
  82. * 08/09/1995 BRR : Created. *
  83. *=============================================================================================*/
  84. #ifdef CHEAT_KEYS
  85. int TeamClass::Validate(void) const
  86. {
  87. int num;
  88. num = Teams.ID(this);
  89. if (num < 0 || num >= TEAM_MAX) {
  90. Validate_Error("TEAM");
  91. return (0);
  92. }
  93. else
  94. return (1);
  95. }
  96. #else
  97. #define Validate()
  98. #endif
  99. /***********************************************************************************************
  100. * TeamClass::Init -- Initializes the team objects for scenario preparation. *
  101. * *
  102. * This routine clears out the team object array in preparation for starting a new *
  103. * scenario. *
  104. * *
  105. * INPUT: none *
  106. * *
  107. * OUTPUT: none *
  108. * *
  109. * WARNINGS: none *
  110. * *
  111. * HISTORY: *
  112. * 12/29/1994 JLB : Created. *
  113. *=============================================================================================*/
  114. void TeamClass::Init(void)
  115. {
  116. TeamClass *ptr;
  117. Teams.Free_All();
  118. memset(Number, 0, sizeof(Number));
  119. memset(Success, 0, sizeof(Success));
  120. ptr = new TeamClass();
  121. VTable = ((void **)(((char *)ptr) + sizeof(AbstractClass) - 4))[0];
  122. delete ptr;
  123. }
  124. void * TeamClass::operator new (size_t)
  125. {
  126. void * ptr = Teams.Allocate();
  127. if (ptr) {
  128. ((TeamClass *)ptr)->IsActive = true;
  129. }
  130. return(ptr);
  131. }
  132. void TeamClass::operator delete(void * ptr)
  133. {
  134. if (ptr) {
  135. ((TeamClass *)ptr)->IsActive = false;
  136. }
  137. Teams.Free((TeamClass *)ptr);
  138. }
  139. TeamClass::~TeamClass(void)
  140. {
  141. if (GameActive && Class) {
  142. Number[TeamTypes.ID(Class)]--;
  143. while (Member) {
  144. Remove(Member);
  145. }
  146. if (Class->IsTransient && !Number[TeamTypes.ID(Class)]) {
  147. delete (TeamTypeClass *)Class;
  148. }
  149. }
  150. }
  151. TeamClass::TeamClass(TeamTypeClass const * type, HouseClass * owner) :
  152. Class(type),
  153. House(owner)
  154. {
  155. memset(Quantity, 0, sizeof(Quantity));
  156. IsAltered = true;
  157. IsForcedActive = false;
  158. IsFullStrength = false;
  159. IsUnderStrength = true;
  160. IsReforming = false;
  161. IsLagging = false;
  162. IsMoving = false;
  163. IsHasBeen = false;
  164. Center = 0;
  165. Target = TARGET_NONE;
  166. ObjectiveCenter = 0;
  167. MissionTarget = TARGET_NONE;
  168. Member = 0;
  169. Total = 0;
  170. Risk = 0;
  171. CurrentMission = -1;
  172. IsNextMission = true;
  173. TimeOut = 0;
  174. SuspendTimer.Clear();
  175. Suspended = false;
  176. Number[TeamTypes.ID(Class)]++;
  177. }
  178. /***************************************************************************
  179. * TeamClass::Assign_Mission_Target -- Sets mission target and clears old *
  180. * *
  181. * INPUT: *
  182. * *
  183. * OUTPUT: *
  184. * *
  185. * WARNINGS: *
  186. * *
  187. * HISTORY: *
  188. * 05/16/1995 PWG : Created. *
  189. *=========================================================================*/
  190. void TeamClass::Assign_Mission_Target(TARGET new_target)
  191. {
  192. Validate();
  193. /*
  194. ** First go through and find anyone who is currently targetting
  195. ** the old mission target and clear their Tarcom.
  196. */
  197. FootClass * unit = Member;
  198. while (unit) {
  199. bool tar = (unit->TarCom == MissionTarget);
  200. bool nav = (unit->NavCom == MissionTarget);
  201. if (tar || nav) {
  202. /*
  203. ** If the unit was doing something related to the team mission
  204. ** then we kick him into guard mode so that he is easy to change
  205. ** missions for.
  206. */
  207. unit->Assign_Mission(MISSION_GUARD);
  208. /*
  209. ** If the unit's tarcom is set to the old mission target, then
  210. ** clear it, so that it will be reset by whatever happens next.
  211. */
  212. if (nav) {
  213. unit->Assign_Destination(TARGET_NONE);
  214. }
  215. /*
  216. ** If the unit's navcom is set to the old mission target, then
  217. ** clear it, so that it will be reset by whatever happens next.
  218. */
  219. if (tar) {
  220. unit->Assign_Target(TARGET_NONE);
  221. }
  222. }
  223. unit = (FootClass *)unit->Member;
  224. }
  225. /*
  226. ** If there is not currently an override on the current mission target
  227. ** then assign both MissionTarget and Target to the new target. If
  228. ** there is an overide, allow the team to keep fighting the overide but
  229. ** make sure they pick up on the new mission when they are ready.
  230. */
  231. if (Target == MissionTarget || !Target_Legal(Target)) {
  232. MissionTarget = Target = new_target;
  233. } else {
  234. MissionTarget = new_target;
  235. }
  236. }
  237. /***********************************************************************************************
  238. * TeamClass::AI -- Process team logic. *
  239. * *
  240. * General purpose team logic is handled by this routine. It should be called once per *
  241. * active team per game tick. This routine handles recruitment and assigning orders to *
  242. * member units. *
  243. * *
  244. * INPUT: none *
  245. * *
  246. * OUTPUT: none *
  247. * *
  248. * WARNINGS: none *
  249. * *
  250. * HISTORY: *
  251. * 12/29/1994 JLB : Created. *
  252. * 01/06/1995 JLB : Choreographed gesture. *
  253. *=============================================================================================*/
  254. void TeamClass::AI(void)
  255. {
  256. Validate();
  257. int desired = 0;
  258. int old_under = IsUnderStrength;
  259. int old_full = IsFullStrength;
  260. /*
  261. ** If the team has been suspended then we need to check if its time for
  262. ** us to reactivate the team. If not, no team logic will be processed
  263. ** for this team.
  264. */
  265. if (Suspended) {
  266. if (!SuspendTimer.Expired()) {
  267. return;
  268. }
  269. Suspended = false;
  270. }
  271. /*
  272. ** If this team senses that its composition has been altered, then it should
  273. ** recalculate the under strength and full strength flags.
  274. */
  275. if (IsAltered) {
  276. for (int index = 0; index < Class->ClassCount; index++) {
  277. desired += Class->DesiredNum[index];
  278. }
  279. if (Total) {
  280. IsFullStrength = (Total == desired);
  281. /*
  282. ** Human controlled teams are always considered full strength. This ensures
  283. ** that no new team members will be recruited and the team won't go into
  284. ** regroup logic.
  285. */
  286. if (House->IsHuman) {
  287. IsUnderStrength = false;
  288. } else {
  289. /*
  290. ** Reinforcable teams will revert (or snap out of) the under strength
  291. ** mode when the members transition the magic 1/3 strength threshhold.
  292. */
  293. if (Class->IsReinforcable) {
  294. IsUnderStrength = (Total <= desired / 3);
  295. } else {
  296. /*
  297. ** Teams that are not flagged as reinforcable are never considered under
  298. ** strength if the team has already started its main mission. This
  299. ** ensures that once the team has started, it won't dally to pick up
  300. ** new members.
  301. */
  302. IsUnderStrength = !IsHasBeen;
  303. }
  304. }
  305. IsAltered = false;
  306. } else {
  307. IsUnderStrength = true;
  308. IsFullStrength = false;
  309. Center = 0;
  310. /*
  311. ** A team that exists on the player's side is automatically destroyed
  312. ** when there are no team members left. This team was created as a
  313. ** result of reinforcement logic and no longer needs to exist when there
  314. ** are no more team members.
  315. */
  316. if (House->IsHuman || IsHasBeen) {
  317. delete this;
  318. return;
  319. }
  320. }
  321. /*
  322. ** If the team has gone from under strength to no longer under
  323. ** strength than the team needs to reform.
  324. */
  325. if (old_under != IsUnderStrength) {
  326. IsReforming = true;
  327. }
  328. }
  329. /*
  330. ** If the team is under strength, then flag it to regroup.
  331. */
  332. if (IsMoving && IsUnderStrength) {
  333. IsMoving = false;
  334. CurrentMission = -1;
  335. if (Total) {
  336. Calc_Center(Center, ObjectiveCenter);
  337. /*
  338. ** When a team is badly damaged and needs to regroup it should
  339. ** pick a friendly building to go and regroup at. Its first preference
  340. ** should be somewhere near repair factory. If it cannot find a repair
  341. ** factory then it should pick another structure that is friendly to
  342. ** its side.
  343. */
  344. CELL dest = Center;
  345. int max = 0x7FFFFFFF;
  346. for (int index = 0; index < Buildings.Count(); index++) {
  347. BuildingClass * b = Buildings.Ptr(index);
  348. if (b && !b->IsInLimbo && b->House == House && b->Class->Primary == WEAPON_NONE) {
  349. CELL cell = Coord_Cell(b->Center_Coord());
  350. int dist = Map.Cell_Distance(cell, Center) * (Map.Cell_Threat(cell, House->Class->House) + 1);
  351. if (*b == STRUCT_REPAIR) {
  352. dist >>= 1;
  353. }
  354. if (dist < max) {
  355. cell = Member->Safety_Point(Center, cell, 2, 4);
  356. if (cell != -1) {
  357. max = dist;
  358. dest = cell;
  359. }
  360. }
  361. }
  362. }
  363. // Should calculate a regroup location.
  364. Target = ::As_Target(dest);
  365. Coordinate_Move();
  366. return;
  367. } else {
  368. Center = 0;
  369. }
  370. }
  371. /*
  372. ** Flag this team into action when it gets to full strength. Human owned teams are only
  373. ** used for reinforcement purposes -- always consider them at full strength.
  374. */
  375. if (!IsMoving && (IsFullStrength || IsForcedActive)) {
  376. IsMoving = true;
  377. IsHasBeen = true;
  378. IsUnderStrength = false;
  379. /*
  380. ** Infantry can do a gesture when they start their mission. Pick
  381. ** a gesture at random.
  382. */
  383. FootClass * techno = Member;
  384. DoType doaction = (Random_Pick(1, 2) == 1) ? DO_GESTURE1 : DO_GESTURE2;
  385. while (techno) {
  386. if (!techno->IsInLimbo && techno->What_Am_I() == RTTI_INFANTRY) {
  387. ((InfantryClass *)techno)->Do_Action(doaction);
  388. }
  389. if (IsReforming || IsForcedActive) {
  390. techno->IsInitiated = true;
  391. }
  392. techno = techno->Member;
  393. }
  394. CurrentMission = -1;
  395. IsNextMission = true;
  396. IsForcedActive = false;
  397. }
  398. /*
  399. ** If the team is moving or if there is no center position for
  400. ** the team, then the center position must be recalculated.
  401. */
  402. if (IsReforming || IsMoving || Center == 0) {
  403. Calc_Center(Center, ObjectiveCenter);
  404. }
  405. /*
  406. ** Try to recruit members if there is room to do so for this team.
  407. ** Only try to recruit members for a non player controlled team.
  408. */
  409. if (!IsMoving || (!IsFullStrength && Class->IsReinforcable) && !House->IsHuman) {
  410. for (int index = 0; index < Class->ClassCount; index++) {
  411. if (Quantity[index] < Class->DesiredNum[index]) {
  412. Recruit(index);
  413. }
  414. }
  415. }
  416. /*
  417. ** If there are no members of the team and the team has reached
  418. ** full strength at one time, then delete the team.
  419. */
  420. if (!Member && IsHasBeen) {
  421. delete this;
  422. return;
  423. }
  424. /*
  425. ** If the mission should be advanced to the next entry, then do so at
  426. ** this time. Various events may cause the mission to advance, but it
  427. ** all boils down to the following change-mission code.
  428. */
  429. if (IsMoving && !IsReforming && IsNextMission) {
  430. IsNextMission = false;
  431. CurrentMission++;
  432. if (CurrentMission < Class->MissionCount) {
  433. TeamMissionStruct const * mission = &Class->MissionList[CurrentMission];
  434. TimeOut = mission->Argument * (TICKS_PER_MINUTE/10);
  435. Target = TARGET_NONE;
  436. switch (mission->Mission) {
  437. case TMISSION_MOVECELL:
  438. Assign_Mission_Target(::As_Target((CELL)mission->Argument));
  439. break;
  440. case TMISSION_MOVE:
  441. case TMISSION_UNLOAD:
  442. Assign_Mission_Target(::As_Target((CELL)Waypoint[mission->Argument]));
  443. break;
  444. case TMISSION_ATTACKTARCOM:
  445. Assign_Mission_Target(mission->Argument);
  446. break;
  447. default:
  448. Assign_Mission_Target(TARGET_NONE);
  449. break;
  450. }
  451. } else {
  452. delete this;
  453. return;
  454. }
  455. }
  456. /*
  457. ** Perform mission of the team. This depends on the mission list.
  458. */
  459. if (Member && IsMoving && !IsReforming && !IsUnderStrength) {
  460. /*
  461. ** If the current Target has been dealt with but the mission target
  462. ** has not, then the current target needs to be reset to the mission
  463. ** target.
  464. */
  465. if (!Target_Legal(Target)) {
  466. Target = MissionTarget;
  467. }
  468. /*
  469. ** If the current mission is one that times out, then check for
  470. ** this case. If it has timed out then advance to the next
  471. ** mission in the list or disband the team.
  472. */
  473. TeamMissionStruct const * mission = &Class->MissionList[CurrentMission];
  474. switch (mission->Mission) {
  475. case TMISSION_ATTACKBASE:
  476. if (!Target_Legal(MissionTarget)) {
  477. Assign_Mission_Target(Member->Greatest_Threat(THREAT_BUILDINGS));
  478. if (!Target_Legal(MissionTarget)) IsNextMission = true;
  479. }
  480. Coordinate_Attack();
  481. break;
  482. case TMISSION_ATTACKUNITS:
  483. if (!Target_Legal(MissionTarget)) {
  484. Assign_Mission_Target(Member->Greatest_Threat(THREAT_VEHICLES|THREAT_INFANTRY));
  485. if (!Target_Legal(MissionTarget)) IsNextMission = true;
  486. }
  487. Coordinate_Attack();
  488. break;
  489. case TMISSION_ATTACKCIVILIANS:
  490. if (!Target_Legal(MissionTarget)) {
  491. Assign_Mission_Target(Member->Greatest_Threat(THREAT_CIVILIANS));
  492. if (!Target_Legal(MissionTarget)) IsNextMission = true;
  493. }
  494. Coordinate_Attack();
  495. break;
  496. case TMISSION_ATTACKTARCOM:
  497. case TMISSION_RAMPAGE:
  498. if (!Target_Legal(MissionTarget)) {
  499. Assign_Mission_Target(Member->Greatest_Threat(THREAT_NORMAL));
  500. if (!Target_Legal(MissionTarget)) IsNextMission = true;
  501. }
  502. Coordinate_Attack();
  503. break;
  504. case TMISSION_DEFENDBASE:
  505. Coordinate_Move();
  506. break;
  507. // case TMISSION_HARVEST:
  508. // Coordinate_Move();
  509. // break;
  510. case TMISSION_UNLOAD:
  511. Coordinate_Unload();
  512. break;
  513. case TMISSION_MOVE:
  514. Coordinate_Move();
  515. break;
  516. case TMISSION_RETREAT:
  517. Coordinate_Move();
  518. break;
  519. case TMISSION_GUARD:
  520. Coordinate_Regroup();
  521. break;
  522. case TMISSION_LOOP:
  523. CurrentMission = mission->Argument-1;
  524. IsNextMission = true;
  525. break;
  526. }
  527. /*
  528. ** Check for mission time out condition. If the mission does in fact time out, then
  529. ** flag it so that the team mission list will advance.
  530. */
  531. switch (mission->Mission) {
  532. case TMISSION_ATTACKBASE:
  533. case TMISSION_ATTACKUNITS:
  534. case TMISSION_ATTACKCIVILIANS:
  535. case TMISSION_RAMPAGE:
  536. case TMISSION_DEFENDBASE:
  537. case TMISSION_UNLOAD:
  538. case TMISSION_RETREAT:
  539. case TMISSION_GUARD:
  540. if (TimeOut.Expired()) {
  541. IsNextMission = true;
  542. }
  543. break;
  544. }
  545. } else {
  546. if (IsMoving) {
  547. IsReforming = !Coordinate_Regroup();
  548. } else {
  549. Coordinate_Move();
  550. }
  551. }
  552. }
  553. /***********************************************************************************************
  554. * TeamClass::Add -- Adds specified object to team. *
  555. * *
  556. * Use this routine to add the specified object to the team. The object is checked to make *
  557. * sure that it can be assigned to the team. If it can't, then the object will be left *
  558. * alone and false will be returned. *
  559. * *
  560. * INPUT: obj -- Pointer to the object that is to be assigned to this team. *
  561. * *
  562. * typeindex-- Optional value that specifies the index in the team type class array *
  563. * that this object belongs. *
  564. * *
  565. * OUTPUT: bool; Was the unit added to the team? *
  566. * *
  567. * WARNINGS: none *
  568. * *
  569. * HISTORY: *
  570. * 12/29/1994 JLB : Created. *
  571. * 01/02/1995 JLB : Initiation flag setup. *
  572. * 08/06/1995 JLB : Allows member stealing from lesser priority teams. *
  573. *=============================================================================================*/
  574. bool TeamClass::Add(FootClass * obj, int typeindex)
  575. {
  576. Validate();
  577. /*
  578. ** If this team doesn't accept new members, then don't accept this one either.
  579. */
  580. // if (!Class->IsReinforcable && IsMoving) {
  581. // return(false);
  582. // }
  583. if (!obj || !obj->Strength || (obj->IsInLimbo && !ScenarioInit) || obj->In_Radio_Contact() || obj->House != House) {
  584. return(false);
  585. }
  586. TeamClass * team = obj->Team;
  587. /*
  588. ** Trying to add the team member to itself is an error condition. Just return
  589. ** with success, since the end result is the same.
  590. */
  591. if (team == this) {
  592. return(true);
  593. }
  594. /*
  595. ** If the object is doing some mission that precludes it from joining
  596. ** a team then don't add it.
  597. */
  598. if (obj->Mission == MISSION_STICKY || obj->Mission == MISSION_SLEEP || obj->Mission == MISSION_GUARD_AREA || obj->Mission == MISSION_HUNT || obj->Mission == MISSION_HARVEST) {
  599. return(false);
  600. }
  601. /*
  602. ** If this object is part of another team, then check to make sure that it
  603. ** is permitted to leave the other team in order to join this one. If not,
  604. ** then no further processing is allowed -- bail.
  605. */
  606. if (team &&
  607. (/*team->Total >= Total || team->IsMoving ||*/
  608. team->Class->RecruitPriority >= Class->RecruitPriority)) {
  609. return(false);
  610. }
  611. /*
  612. ** If the proper team index was not provided, then find it in the type type class.
  613. ** On the chance that a match could not be found, then it is illegal to add this
  614. ** object to this team -- return with failure flag.
  615. */
  616. if (typeindex == -1) {
  617. for (typeindex = 0; typeindex < Class->ClassCount; typeindex++) {
  618. if (Class->Class[typeindex] == &obj->Class_Of()) {
  619. break;
  620. }
  621. }
  622. }
  623. /*
  624. ** If the team is already full of this type, then adding the object is not allowed.
  625. ** Return with a failure flag in this case.
  626. */
  627. if (Quantity[typeindex] >= Class->DesiredNum[typeindex]) {
  628. return(false);
  629. }
  630. /*
  631. ** All is ok to add the object to the team, but if the object is already part of
  632. ** another team, then it must be removed from that team first.
  633. */
  634. if (team) {
  635. team->Remove(obj);
  636. }
  637. /*
  638. ** Actually add the object to the team.
  639. */
  640. Quantity[typeindex]++;
  641. obj->IsInitiated = (Member == NULL);
  642. obj->Member = Member;
  643. Member = obj;
  644. obj->Team = this;
  645. Total++;
  646. Risk += obj->Risk();
  647. if (!Center) {
  648. Calc_Center(Center, ObjectiveCenter);
  649. }
  650. /*
  651. ** Return with success, since the object was added to the team.
  652. */
  653. IsAltered = true;
  654. return(true);
  655. }
  656. /***********************************************************************************************
  657. * TeamClass::Remove -- Removes the specified object from the team. *
  658. * *
  659. * Use this routine to remove an object from a team. Objects removed from the team are *
  660. * then available to be recruited by other teams, or even by the same team at a later time. *
  661. * *
  662. * INPUT: obj -- Pointer to the object that is to be removed from this team. *
  663. * *
  664. * typeindex-- Optional index of where this object type is specified in the type *
  665. * type class. This parameter can be omitted. It only serves to make *
  666. * the removal process faster. *
  667. * *
  668. * OUTPUT: bool; Was the object removed from this team? *
  669. * *
  670. * WARNINGS: none *
  671. * *
  672. * HISTORY: *
  673. * 12/29/1994 JLB : Created. *
  674. * 01/02/1995 JLB : Initiation tracking and team captain selection. *
  675. *=============================================================================================*/
  676. bool TeamClass::Remove(FootClass * obj, int typeindex)
  677. {
  678. Validate();
  679. /*
  680. ** Make sure that the object is in fact a member of this team. If not, then it can't
  681. ** be removed. Return success because the end result is the same.
  682. */
  683. if (obj->Team != this) {
  684. return(true);
  685. }
  686. /*
  687. ** If the proper team index was not provided, then find it in the type type class. The
  688. ** team type class will not be set if the appropriate type could not be found
  689. ** for this object. This indicates that the object was illegally added. Continue to
  690. ** process however, since removing this object from the team is a good idea.
  691. */
  692. if (typeindex == -1) {
  693. for (typeindex = 0; typeindex < Class->ClassCount; typeindex++) {
  694. if (Class->Class[typeindex] == &obj->Class_Of()) {
  695. break;
  696. }
  697. }
  698. }
  699. /*
  700. ** Decrement the counter for the team class. There is now one less of this object type.
  701. */
  702. if ((unsigned)typeindex < Class->ClassCount) {
  703. Quantity[typeindex]--;
  704. }
  705. /*
  706. ** Actually remove the object from the team. Scan through the team members
  707. ** looking for the one that matches the one specified. If it is found, it
  708. ** is unlinked from the member chain. During this scan, a check is made to
  709. ** ensure that at least one remaining member is still initiated. If not, then
  710. ** a new team captain must be chosen.
  711. */
  712. bool initiated = false;
  713. FootClass * prev = 0;
  714. FootClass * curr = Member;
  715. bool found = false;
  716. while (curr && (!found || !initiated)) {
  717. if (curr == obj) {
  718. if (prev) {
  719. prev->Member = curr->Member;
  720. } else {
  721. Member = curr->Member;
  722. }
  723. FootClass * temp = curr->Member;
  724. curr->Member = 0;
  725. curr->Team = 0;
  726. curr = temp;
  727. Total--;
  728. found = true;
  729. Risk -= obj->Risk();
  730. continue;
  731. }
  732. /*
  733. ** If this (remaining) member is initiated, then keep a record of this.
  734. */
  735. initiated |= curr->IsInitiated;
  736. prev = curr;
  737. curr = curr->Member;
  738. }
  739. /*
  740. ** If, after removing the team member, there are no initiated members left
  741. ** in the team, then just make the first remaining member of the team the
  742. ** team captain. Mark the center location of the team as invalid so that
  743. ** it will be centered around the captain.
  744. */
  745. if (!initiated && Member) {
  746. Member->IsInitiated = true;
  747. Center = 0;
  748. }
  749. /*
  750. ** Must record that the team composition has changed. At the next opportunity,
  751. ** the team members will be counted and appropriate AI adjustments made.
  752. */
  753. IsAltered = true;
  754. return(true);
  755. }
  756. /***********************************************************************************************
  757. * TeamClass::Recruit -- Attempts to recruit members to the team for the given index ID. *
  758. * *
  759. * This routine will take the given index ID and scan for available objects of that type *
  760. * to recruit to the team. Recruiting will continue until that object type has either *
  761. * been exhausted or if the team's requirment for that type has been filled. *
  762. * *
  763. * INPUT: typeindex -- The index for the object type to recruit. The index is used to *
  764. * look into the type type's array of object types that make up this *
  765. * team. *
  766. * *
  767. * OUTPUT: Returns with the number of objects added to this team. *
  768. * *
  769. * WARNINGS: none *
  770. * *
  771. * HISTORY: *
  772. * 12/29/1994 JLB : Created. *
  773. * 04/10/1995 JLB : Scans for units too. *
  774. *=============================================================================================*/
  775. int TeamClass::Recruit(int typeindex)
  776. {
  777. Validate();
  778. int added = 0; // Total number added to team.
  779. /*
  780. ** Quick check to see if recruiting is really allowed for this index or not.
  781. */
  782. if (Class->DesiredNum[typeindex] > Quantity[typeindex]) {
  783. /*
  784. ** For infantry objects, sweep through the infantry in the game looking for
  785. ** ones owned by the house that owns the team. When found, try to add.
  786. */
  787. if (Class->Class[typeindex]->What_Am_I() == RTTI_INFANTRYTYPE) {
  788. for (int index = 0; index < Infantry.Count(); index++) {
  789. InfantryClass * infantry = Infantry.Ptr(index);
  790. if (infantry->House == House && infantry->Class == Class->Class[typeindex]) {
  791. if (Add(infantry, typeindex)) {
  792. added++;
  793. }
  794. }
  795. /*
  796. ** If there is sufficient quantity of this type of object recruited to the
  797. ** team, then abort further scanning for members.
  798. */
  799. if (Quantity[typeindex] >= Class->DesiredNum[typeindex]) {
  800. break;
  801. }
  802. }
  803. }
  804. if (Class->Class[typeindex]->What_Am_I() == RTTI_UNITTYPE) {
  805. for (int index = 0; index < Units.Count(); index++) {
  806. UnitClass * unit = Units.Ptr(index);
  807. if (unit->House == House && unit->Class == Class->Class[typeindex]) {
  808. if (Add(unit, typeindex)) {
  809. added++;
  810. /*
  811. ** If a transport is added to the team, the occupants
  812. ** are added by default.
  813. */
  814. FootClass * f = unit->Attached_Object();
  815. while (f) {
  816. Add(f);
  817. f = (FootClass *)f->Next;
  818. }
  819. }
  820. }
  821. /*
  822. ** If there is sufficient quantity of this type of object recruited to the
  823. ** team, then abort further scanning for members.
  824. */
  825. if (Quantity[typeindex] >= Class->DesiredNum[typeindex]) {
  826. break;
  827. }
  828. }
  829. }
  830. }
  831. return(added);
  832. }
  833. /***********************************************************************************************
  834. * TeamClass::Detach -- Removes specified target from team tracking. *
  835. * *
  836. * When a target object is about to be removed from the game (e.g., it was killed), then *
  837. * any team that is looking at that target must abort from that target. *
  838. * *
  839. * INPUT: target -- The target object that is going to be removed from the game. *
  840. * *
  841. * all -- Is the target going away for good as opposed to just cloaking/hiding? *
  842. * *
  843. * OUTPUT: none *
  844. * *
  845. * WARNINGS: none *
  846. * *
  847. * HISTORY: *
  848. * 12/29/1994 JLB : Created. *
  849. *=============================================================================================*/
  850. void TeamClass::Detach(TARGET target, bool )
  851. {
  852. Validate();
  853. /*
  854. ** If the target to detatch matches the target of this team, then remove
  855. ** the target from this team's Tar/Nav com and let the chips fall
  856. ** where they may.
  857. */
  858. if (Target == target) {
  859. Target = TARGET_NONE;
  860. }
  861. if (MissionTarget == target) {
  862. MissionTarget = TARGET_NONE;
  863. }
  864. }
  865. /***********************************************************************************************
  866. * TeamClass::As_Target -- Converts this team object into a target number. *
  867. * *
  868. * This routine is used by the save/load code to produce a persistant identifier for this *
  869. * team object. *
  870. * *
  871. * INPUT: none *
  872. * *
  873. * OUTPUT: Returns the team represented as a target number. *
  874. * *
  875. * WARNINGS: none *
  876. * *
  877. * HISTORY: *
  878. * 06/14/1995 JLB : Created. *
  879. *=============================================================================================*/
  880. TARGET TeamClass::As_Target(void) const
  881. {
  882. Validate();
  883. return(Build_Target(KIND_TEAM, Teams.ID(this)));
  884. }
  885. /***********************************************************************************************
  886. * TeamClass::Calc_Center -- Determines average location of team members. *
  887. * *
  888. * Use this routine to calculate the "center" location of the team. This is the average *
  889. * position of all members of the team. Using this center value it is possible to tell *
  890. * if a team member is too far away and where to head to in order to group up. *
  891. * *
  892. * INPUT: none *
  893. * *
  894. * OUTPUT: Returns with the cell number of the team's center point. If the team contains *
  895. * no members, then the return value will be zero. *
  896. * *
  897. * WARNINGS: none *
  898. * *
  899. * HISTORY: *
  900. * 12/29/1994 JLB : Created. *
  901. *=============================================================================================*/
  902. void TeamClass::Calc_Center(CELL &center, CELL &obj_center) const
  903. {
  904. Validate();
  905. long x = 0;
  906. long y = 0;
  907. int dist = 0x7FFFFFFF;
  908. int quantity = 0;
  909. FootClass * unit;
  910. obj_center = 0;
  911. center = 0;
  912. unit = Member;
  913. while (unit) {
  914. if (unit->IsInitiated && !unit->IsInLimbo) {
  915. CELL c = Coord_Cell(unit->Center_Coord());
  916. if (unit->Distance(Target) < dist) {
  917. dist = unit->Distance(Target);
  918. obj_center = c;
  919. }
  920. x += Cell_X(c);
  921. y += Cell_Y(c);
  922. quantity++;
  923. }
  924. unit = unit->Member;
  925. }
  926. if (quantity) {
  927. x /= quantity;
  928. y /= quantity;
  929. CELL cell = XY_Cell((int)x, (int)y);
  930. center = cell;
  931. }
  932. }
  933. /***********************************************************************************************
  934. * TeamClass::Took_Damage -- Informs the team when the team member takes damage. *
  935. * *
  936. * This routine is used when a team member takes damage. Usually the team will react in *
  937. * some fashion to the attack. This reaction can range from running away to assigning this *
  938. * new target as the team's target. *
  939. * *
  940. * INPUT: obj -- The team member that was damaged. *
  941. * *
  942. * result -- The severity of the damage taken. *
  943. * *
  944. * source -- The purpetrator of the damage. *
  945. * *
  946. * OUTPUT: none *
  947. * *
  948. * WARNINGS: none *
  949. * *
  950. * HISTORY: *
  951. * 12/29/1994 JLB : Created. *
  952. *=============================================================================================*/
  953. void TeamClass::Took_Damage(FootClass * , ResultType result, TechnoClass * source)
  954. {
  955. Validate();
  956. if ((result != RESULT_NONE) && (!Class->IsSuicide)) {
  957. if (!IsMoving) {
  958. // Should run to a better hiding place or disband into a group of hunting units.
  959. } else {
  960. if (source && !Is_A_Member(source) && Member && Member->What_Am_I() != RTTI_AIRCRAFT) {
  961. if (Target != source->As_Target()) {
  962. /*
  963. ** Don't change target if the team's target is one that can fire as well. There is
  964. ** no point in endlessly shuffling between targets that have firepower.
  965. */
  966. if (Target_Legal(Target)) {
  967. TechnoClass * techno = As_Techno(Target);
  968. if (techno && ((TechnoTypeClass const &)techno->Class_Of()).Primary != WEAPON_NONE) {
  969. if (techno->In_Range(Cell_Coord(Center), 0)) {
  970. return;
  971. }
  972. }
  973. }
  974. Target = source->As_Target();
  975. }
  976. }
  977. }
  978. }
  979. }
  980. /***********************************************************************************************
  981. * TeamClass::Coordinate_Attack -- Handles coordinating a team attack. *
  982. * *
  983. * This function is called when the team knows what it should attack. This routine will *
  984. * give the necessary orders to the members of the team. *
  985. * *
  986. * INPUT: none *
  987. * *
  988. * OUTPUT: none *
  989. * *
  990. * WARNINGS: none *
  991. * *
  992. * HISTORY: *
  993. * 04/06/1995 JLB : Created. *
  994. *=============================================================================================*/
  995. void TeamClass::Coordinate_Attack(void)
  996. {
  997. Validate();
  998. if (!Target_Legal(Target)) {
  999. Target = MissionTarget;
  1000. }
  1001. if (!Target_Legal(Target)) {
  1002. IsNextMission = true;
  1003. } else {
  1004. FootClass * unit = Member;
  1005. while (unit) {
  1006. Coordinate_Conscript(unit);
  1007. if (unit->IsInitiated && !unit->IsInLimbo) {
  1008. if (unit->Mission != MISSION_ATTACK && unit->Mission != MISSION_ENTER && unit->Mission != MISSION_CAPTURE) {
  1009. unit->Assign_Mission(MISSION_ATTACK);
  1010. unit->Assign_Target(TARGET_NONE);
  1011. unit->Assign_Destination(TARGET_NONE);
  1012. }
  1013. if (unit->TarCom != Target) {
  1014. unit->Assign_Target(Target);
  1015. }
  1016. }
  1017. unit = unit->Member;
  1018. }
  1019. }
  1020. }
  1021. /***********************************************************************************************
  1022. * TeamClass::Coordinate_Regroup -- Handles team idling (regrouping). *
  1023. * *
  1024. * This routine is called when the team must delay at its current location. Team members *
  1025. * are grouped together by this function. It is called when the team needs to sit and *
  1026. * wait. *
  1027. * *
  1028. * INPUT: none *
  1029. * *
  1030. * OUTPUT: none *
  1031. * *
  1032. * WARNINGS: none *
  1033. * *
  1034. * HISTORY: *
  1035. * 04/06/1995 JLB : Created. *
  1036. *=============================================================================================*/
  1037. bool TeamClass::Coordinate_Regroup(void)
  1038. {
  1039. Validate();
  1040. FootClass * unit = Member;
  1041. bool retval = true;
  1042. /*
  1043. ** Regroup default logic.
  1044. */
  1045. while (unit) {
  1046. Coordinate_Conscript(unit);
  1047. if (unit->IsInitiated && !unit->IsInLimbo) {
  1048. if (unit->Distance(Center) > STRAY_DISTANCE && (unit->Mission != MISSION_GUARD_AREA || !Target_Legal(unit->TarCom))) {
  1049. if (unit->Mission != MISSION_MOVE || !Target_Legal(unit->NavCom) || ::Distance(As_Cell(unit->NavCom), Center) > STRAY_DISTANCE) {
  1050. unit->Assign_Mission(MISSION_MOVE);
  1051. unit->Assign_Destination(::As_Target(Center));
  1052. }
  1053. retval = false;
  1054. } else {
  1055. /*
  1056. ** This unit has gotten close enough to the team center so that it is
  1057. ** now considered intiated. An initiated unit is considered when calculating
  1058. ** the center of the team.
  1059. */
  1060. unit->IsInitiated = true;
  1061. /*
  1062. ** The team is regrouping, so just sit here and wait.
  1063. */
  1064. if (unit->Mission != MISSION_GUARD_AREA) {
  1065. unit->Assign_Mission(MISSION_GUARD);
  1066. unit->Assign_Destination(TARGET_NONE);
  1067. }
  1068. }
  1069. }
  1070. unit = unit->Member;
  1071. }
  1072. return(retval);
  1073. }
  1074. /***********************************************************************************************
  1075. * TeamClass::Coordinate_Move -- Handles team movement coordination. *
  1076. * *
  1077. * This routine is called when the team must move to a new location. Movement and grouping *
  1078. * commands associated with this task are initiated here. *
  1079. * *
  1080. * INPUT: none *
  1081. * *
  1082. * OUTPUT: none *
  1083. * *
  1084. * WARNINGS: none *
  1085. * *
  1086. * HISTORY: *
  1087. * 04/06/1995 JLB : Created. *
  1088. *=============================================================================================*/
  1089. void TeamClass::Coordinate_Move(void)
  1090. {
  1091. Validate();
  1092. FootClass * unit = Member;
  1093. bool finished = true;
  1094. if (!Target_Legal(Target)) {
  1095. Target = MissionTarget;
  1096. }
  1097. if (Target_Legal(Target)) {
  1098. if (!Lagging_Units()) {
  1099. while (unit) {
  1100. Coordinate_Conscript(unit);
  1101. if (unit->IsInitiated && !unit->IsInLimbo) {
  1102. if (unit->What_Am_I() != RTTI_AIRCRAFT && unit->Distance(Center) > STRAY_DISTANCE) {
  1103. IsLagging = true;
  1104. finished = false;
  1105. } else {
  1106. if ((unit->Distance(Target)/ICON_LEPTON_W) > STRAY_DISTANCE ||
  1107. (unit->What_Am_I() == RTTI_AIRCRAFT &&
  1108. ((AircraftClass *)unit)->Altitude > 0 &&
  1109. Class->MissionList[CurrentMission+1].Mission != TMISSION_MOVE)) {
  1110. if (unit->Mission != MISSION_MOVE) {
  1111. unit->Assign_Mission(MISSION_MOVE);
  1112. }
  1113. if (unit->NavCom != Target) {
  1114. unit->Assign_Destination(Target);
  1115. }
  1116. finished = false;
  1117. } else {
  1118. if (unit->Mission == MISSION_MOVE && !Target_Legal(unit->NavCom)) {
  1119. unit->Enter_Idle_Mode();
  1120. }
  1121. }
  1122. }
  1123. }
  1124. unit = unit->Member;
  1125. }
  1126. } else {
  1127. finished = false;
  1128. }
  1129. }
  1130. /*
  1131. ** If all the team members are close enough to the desired destination, then
  1132. ** move to the next mission.
  1133. */
  1134. if (finished && IsMoving) {
  1135. IsNextMission = true;
  1136. }
  1137. }
  1138. /***************************************************************************
  1139. * Lagging_Units -- processes units that cant keep up with the pack *
  1140. * *
  1141. * INPUT: none *
  1142. * *
  1143. * OUTPUT: none *
  1144. * *
  1145. * HISTORY: *
  1146. * 08/01/1995 PWG : Created. *
  1147. *=========================================================================*/
  1148. bool TeamClass::Lagging_Units(void)
  1149. {
  1150. Validate();
  1151. FootClass * unit = Member;
  1152. bool lag = false;
  1153. /*
  1154. ** If the IsLagging bit is not set, then obviously there are no lagging
  1155. ** units.
  1156. */
  1157. if (!IsLagging) return(false);
  1158. /*
  1159. ** Scan through all of the units, searching for units who are having
  1160. ** trouble keeping up with the pack.
  1161. */
  1162. while (unit) {
  1163. if (!unit->IsInLimbo) {
  1164. /*
  1165. ** If we find a unit who has fallen to far away from the center of
  1166. ** the pack, then we need to order that unit to catch up with the
  1167. ** first unit.
  1168. */
  1169. if (unit->Distance(ObjectiveCenter) > STRAY_DISTANCE) {
  1170. if (unit->Mission != MISSION_MOVE || !Target_Legal(unit->NavCom) || ::Distance(As_Cell(unit->NavCom), ObjectiveCenter) > STRAY_DISTANCE) {
  1171. unit->Assign_Mission(MISSION_MOVE);
  1172. unit->Assign_Destination(::As_Target(ObjectiveCenter));
  1173. }
  1174. lag = true;
  1175. } else {
  1176. /*
  1177. ** We need to order all of the other units to hold there
  1178. ** position until all lagging units catch up.
  1179. */
  1180. unit->Assign_Mission(MISSION_GUARD);
  1181. unit->Assign_Destination(TARGET_NONE);
  1182. }
  1183. }
  1184. unit = unit->Member;
  1185. }
  1186. /*
  1187. ** Once we have handled the loop we know whether there are any lagging
  1188. ** units or not.
  1189. */
  1190. IsLagging = lag;
  1191. return(lag);
  1192. }
  1193. /***********************************************************************************************
  1194. * TeamClass::Coordinate_Unload -- Tells the team to unload passengers now. *
  1195. * *
  1196. * This routine tells all transport vehicles to unload passengers now. *
  1197. * *
  1198. * INPUT: none *
  1199. * *
  1200. * OUTPUT: none *
  1201. * *
  1202. * WARNINGS: none *
  1203. * *
  1204. * HISTORY: *
  1205. * 06/14/1995 JLB : Created. *
  1206. *=============================================================================================*/
  1207. void TeamClass::Coordinate_Unload(void)
  1208. {
  1209. Validate();
  1210. FootClass * unit = Member;
  1211. bool finished = true;
  1212. while (unit) {
  1213. Coordinate_Conscript(unit);
  1214. if (unit->IsInitiated && !unit->IsInLimbo) {
  1215. if (unit->Is_Something_Attached()) {
  1216. /*
  1217. ** Loaner transports will break off of the team at this time. The normal
  1218. ** unload logic for the transport will proceed normally. The rest of the team
  1219. ** members will be in a dormant state until they are unloaded.
  1220. */
  1221. if (unit->IsALoaner) {
  1222. Remove(unit);
  1223. unit->Commence();
  1224. unit->Assign_Mission(MISSION_UNLOAD);
  1225. unit->Assign_Destination(Target);
  1226. } else {
  1227. if (unit->Mission != MISSION_UNLOAD) {
  1228. unit->Assign_Mission(MISSION_UNLOAD);
  1229. unit->Assign_Destination(Target);
  1230. }
  1231. }
  1232. finished = false;
  1233. }
  1234. }
  1235. unit = unit->Member;
  1236. }
  1237. if (finished) {
  1238. IsNextMission = true;
  1239. }
  1240. }
  1241. /***********************************************************************************************
  1242. * TeamClass::Coordinate_Conscript -- Gives orders to new recruit. *
  1243. * *
  1244. * This routine will give the movement orders to the conscript so that it will group *
  1245. * with the other members of the team. *
  1246. * *
  1247. * INPUT: unit -- Pointer to the conscript unit. *
  1248. * *
  1249. * OUTPUT: none *
  1250. * *
  1251. * WARNINGS: none *
  1252. * *
  1253. * HISTORY: *
  1254. * 04/06/1995 JLB : Created. *
  1255. *=============================================================================================*/
  1256. void TeamClass::Coordinate_Conscript(FootClass * unit)
  1257. {
  1258. Validate();
  1259. if (unit && !unit->IsInitiated && !unit->IsInLimbo) {
  1260. if (unit->Distance(Center) > STRAY_DISTANCE) {
  1261. if (!Target_Legal(unit->NavCom)) {
  1262. unit->Assign_Mission(MISSION_MOVE);
  1263. unit->Assign_Target(TARGET_NONE);
  1264. unit->Assign_Destination(::As_Target(Center));
  1265. }
  1266. } else {
  1267. /*
  1268. ** This unit has gotten close enough to the team center so that it is
  1269. ** now considered intiated. An initiated unit is considered when calculating
  1270. ** the center of the team.
  1271. */
  1272. unit->IsInitiated = true;
  1273. }
  1274. }
  1275. }
  1276. /***************************************************************************
  1277. * TeamClass::Is_A_Member -- Tests if a unit is a member of a team *
  1278. * *
  1279. * INPUT: none *
  1280. * *
  1281. * OUTPUT: none *
  1282. * *
  1283. * WARNINGS: *
  1284. * *
  1285. * HISTORY: *
  1286. * 05/16/1995 PWG : Created. *
  1287. *=========================================================================*/
  1288. bool TeamClass::Is_A_Member(void const * who) const
  1289. {
  1290. Validate();
  1291. FootClass * unit = Member;
  1292. while (unit) {
  1293. if (unit == who) {
  1294. return(true);
  1295. }
  1296. unit = unit->Member;
  1297. }
  1298. return(false);
  1299. }
  1300. /***************************************************************************
  1301. * TeamClass::Suspend_Teams -- Suspends activity for low priority teams *
  1302. * *
  1303. * INPUT: int priority - determines what is considered low priority. *
  1304. * *
  1305. * OUTPUT: *
  1306. * *
  1307. * WARNINGS: *
  1308. * *
  1309. * HISTORY: *
  1310. * 06/19/1995 PWG : Created. *
  1311. *=========================================================================*/
  1312. void TeamClass::Suspend_Teams(int priority)
  1313. {
  1314. for (int index = 0; index < Teams.Count(); index++) {
  1315. TeamClass *team = Teams.Ptr(index);
  1316. /*
  1317. ** If a team is below the "survival priority level", then it gets
  1318. ** destroyed. The team members are then free to be reassigned.
  1319. */
  1320. if (team && team->Class->RecruitPriority < priority) {
  1321. FootClass * unit = team->Member;
  1322. while (team->Member) {
  1323. team->Remove(team->Member);
  1324. }
  1325. team->IsAltered = true;
  1326. team->SuspendTimer = TICKS_PER_MINUTE*2;
  1327. team->Suspended = true;
  1328. }
  1329. }
  1330. }