FOOT.CPP 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636
  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/FOOT.CPP 2 3/06/97 1:46p 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 : FOOT.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : April 22, 1994 *
  26. * *
  27. * Last Update : October 5, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * FootClass::AI -- Handle general movement AI. *
  32. * FootClass::Active_Click_With -- Initiates attack or move according to target clicked on. *
  33. * FootClass::Active_Click_With -- Performs action as a result of left mouse click. *
  34. * FootClass::Adjust_Dest -- Adjust candidate movement cell to account for formation. *
  35. * FootClass::Approach_Target -- Sets the navigation computer to approach target object. *
  36. * FootClass::Assign_Destination -- Assigns specified destination to NavCom. *
  37. * FootClass::Basic_Path -- Finds the basic path for a ground object. *
  38. * FootClass::Body_Facing -- Set the body rotation/facing. *
  39. * FootClass::Can_Demolish -- Checks to see if this object can be sold back. *
  40. * FootClass::Can_Enter_Cell -- Checks to see if the object can enter cell specified. *
  41. * FootClass::Clear_Navigation_List -- Clears out the navigation queue. *
  42. * FootClass::Death_Announcement -- Announces the death of a unit. *
  43. * FootClass::Debug_Dump -- Displays the status of the FootClass to the mono monitor. *
  44. * FootClass::Detach -- Detaches a target from tracking systems. *
  45. * FootClass::Detach_All -- Removes this object from the game system. *
  46. * FootClass::Enters_Building -- When unit enters a building for some reason. *
  47. * FootClass::FootClass -- Normal constructor for the foot class object. *
  48. * FootClass::Greatest_Threat -- Fetches the greatest threat to this object. *
  49. * FootClass::Handle_Navigation_List -- Processes the navigation queue. *
  50. * FootClass::Is_Allowed_To_Leave_Map -- Checks to see if it can leave the map and the game. *
  51. * FootClass::Is_On_Priority_Mission -- Checks to see if this object should be given priority*
  52. * FootClass::Is_Recruitable -- Determine if this object is recruitable as a team members. *
  53. * FootClass::Likely_Coord -- Fetches the coordinate the object will be at shortly. *
  54. * FootClass::Mark -- Unit interface to map rendering system. *
  55. * FootClass::Mission_Attack -- AI for heading towards and firing upon target. *
  56. * FootClass::Mission_Capture -- Handles the capture mission. *
  57. * FootClass::Mission_Enter -- Enter (cooperatively) mission handler. *
  58. * FootClass::Mission_Guard_Area -- Causes unit to guard an area about twice weapon range. *
  59. * FootClass::Mission_Hunt -- Handles the default hunt order. *
  60. * FootClass::Mission_Move -- AI process for moving a vehicle to its destination. *
  61. * FootClass::Mission_Retreat -- Handle reatreat from map mission for mobile objects. *
  62. * FootClass::Offload_Tiberium_Bail -- Fetches the Tiberium to offload per step. *
  63. * FootClass::Override_Mission -- temporarily overrides a units mission *
  64. * FootClass::Per_Cell_Process -- Perform action based on once-per-cell condition. *
  65. * FootClass::Queue_Navigation_List -- Add a target to the objects navigation list. *
  66. * FootClass::Receive_Message -- Movement related radio messages are handled here. *
  67. * FootClass::Rescue_Mission -- Calls this unit to the rescue. *
  68. * FootClass::Restore_Mission -- Restores an overridden mission *
  69. * FootClass::Sell_Back -- Causes this object to be sold back. *
  70. * FootClass::Set_Speed -- Initiate unit movement physics. *
  71. * FootClass::Sort_Y -- Determine the sort coordinate for foot class objects. *
  72. * FootClass::Start_Driver -- This starts the driver heading to the destination desired. *
  73. * FootClass::Stop_Driver -- This routine clears the driving state of the object. *
  74. * FootClass::Stun -- Prepares a ground travelling object for removal. *
  75. * FootClass::Take_Damage -- Handles taking damage to this object. *
  76. * FootClass::Unlimbo -- Unlimbos object and performs special fixups. *
  77. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  78. #include "function.h"
  79. /***********************************************************************************************
  80. * FootClass::FootClass -- Default constructor for foot class objects. *
  81. * *
  82. * This is the default constructor for FootClass objects. It sets the foot class values to *
  83. * their default starting settings. *
  84. * *
  85. * INPUT: none *
  86. * *
  87. * OUTPUT: none *
  88. * *
  89. * WARNINGS: none *
  90. * *
  91. * HISTORY: *
  92. * 11/23/1994 JLB : Created. *
  93. *=============================================================================================*/
  94. FootClass::FootClass(RTTIType rtti, int id, HousesType house) :
  95. TechnoClass(rtti, id, house),
  96. IsScanLimited(false),
  97. IsInitiated(false),
  98. IsNewNavCom(false),
  99. IsPlanningToLook(false),
  100. IsDeploying(false),
  101. IsFiring(false),
  102. IsRotating(false),
  103. IsDriving(false),
  104. IsUnloading(false),
  105. IsFormationMove(false),
  106. IsNavQueueLoop(false),
  107. IsScattering(false),
  108. IsMovingOntoBridge(false),
  109. Speed(0),
  110. SpeedBias(1),
  111. XFormOffset(0x80000000),
  112. YFormOffset(0x80000000),
  113. NavCom(TARGET_NONE),
  114. SuspendedNavCom(TARGET_NONE),
  115. Team(0),
  116. Group(255),
  117. Member(0),
  118. PathThreshhold(MOVE_CLOAK),
  119. PathDelay(0),
  120. TryTryAgain(PATH_RETRY),
  121. BaseAttackTimer(0),
  122. FormationSpeed(SPEED_FOOT),
  123. FormationMaxSpeed(MPH_IMMOBILE),
  124. HeadToCoord(0)
  125. {
  126. Path[0] = FACING_NONE;
  127. for (int index = 0; index < ARRAY_SIZE(NavQueue); index++) {
  128. NavQueue[index] = TARGET_NONE;
  129. }
  130. }
  131. #ifdef CHEAT_KEYS
  132. /***********************************************************************************************
  133. * FootClass::Debug_Dump -- Displays the status of the FootClass to the mono monitor. *
  134. * *
  135. * This routine is used to output the current status of the foot class to the mono *
  136. * monitor. Through this display bugs may be tracked down or eliminated. *
  137. * *
  138. * INPUT: none *
  139. * *
  140. * OUTPUT: none *
  141. * *
  142. * WARNINGS: none *
  143. * *
  144. * HISTORY: *
  145. * 06/02/1994 JLB : Created. *
  146. * 07/04/1995 JLB : Handles aircraft special case. *
  147. *=============================================================================================*/
  148. void FootClass::Debug_Dump(MonoClass * mono) const
  149. {
  150. assert(IsActive);
  151. mono->Fill_Attrib(53, 13, 12, 1, IsInitiated ? MonoClass::INVERSE : MonoClass::NORMAL);
  152. mono->Fill_Attrib(1, 18, 12, 1, IsPlanningToLook ? MonoClass::INVERSE : MonoClass::NORMAL);
  153. mono->Fill_Attrib(53, 14, 12, 1, IsDeploying ? MonoClass::INVERSE : MonoClass::NORMAL);
  154. mono->Fill_Attrib(53, 15, 12, 1, IsFiring ? MonoClass::INVERSE : MonoClass::NORMAL);
  155. mono->Fill_Attrib(53, 16, 12, 1, IsRotating ? MonoClass::INVERSE : MonoClass::NORMAL);
  156. mono->Fill_Attrib(53, 17, 12, 1, IsDriving ? MonoClass::INVERSE : MonoClass::NORMAL);
  157. mono->Fill_Attrib(53, 18, 12, 1, IsUnloading ? MonoClass::INVERSE : MonoClass::NORMAL);
  158. mono->Fill_Attrib(27, 18, 12, 1, IsFormationMove ? MonoClass::INVERSE : MonoClass::NORMAL);
  159. mono->Set_Cursor(45, 1);mono->Printf("%02X", Speed);
  160. if (NavCom) {
  161. mono->Set_Cursor(29, 5);
  162. mono->Printf("%08X", NavCom);
  163. }
  164. if (SuspendedNavCom) {
  165. mono->Set_Cursor(38, 5);
  166. mono->Printf("%08X", SuspendedNavCom);
  167. }
  168. if (Team) Team->Debug_Dump(mono);
  169. if (Group != 255) {
  170. mono->Set_Cursor(59, 1);mono->Printf("%d", Group);
  171. }
  172. static char const * _p2c[9] = {"-","0","1","2","3","4","5","6","7"};
  173. for (int index = 0; index < min(12, ARRAY_SIZE(Path)); index++) {
  174. mono->Set_Cursor(54+index, 3);
  175. mono->Printf("%s", _p2c[((ABS((int)Path[index]+1)) % ARRAY_SIZE(_p2c))]);
  176. }
  177. mono->Set_Cursor(54, 5);mono->Printf("%2d", PathThreshhold);
  178. mono->Set_Cursor(72, 3);mono->Printf("%4d", (long)PathDelay);
  179. mono->Set_Cursor(67, 3);mono->Printf("%3d", TryTryAgain);
  180. if (HeadToCoord) {
  181. mono->Set_Cursor(60, 5);mono->Printf("%08X", HeadToCoord);
  182. }
  183. TechnoClass::Debug_Dump(mono);
  184. }
  185. #endif
  186. /***********************************************************************************************
  187. * FootClass::Set_Speed -- Initiate unit movement physics. *
  188. * *
  189. * This routine is used to set a unit's velocity control structure. *
  190. * The game will then process the unit's movement during the momentum *
  191. * physics calculation. *
  192. * *
  193. * INPUT: unit -- Pointer to the unit to alter. *
  194. * *
  195. * speed -- Throttle setting (0=stop, 255=full throttle). *
  196. * *
  197. * OUTPUT: none *
  198. * *
  199. * WARNINGS: none *
  200. * *
  201. * HISTORY: *
  202. * 09/07/1992 JLB : Created. *
  203. * 09/24/1993 JLB : Revised for faster speed. *
  204. * 04/02/1994 JLB : Revised for new system. *
  205. * 04/15/1994 JLB : Converted to member function. *
  206. * 07/21/1994 JLB : Simplified. *
  207. *=============================================================================================*/
  208. void FootClass::Set_Speed(int speed)
  209. {
  210. assert(IsActive);
  211. speed &= 0xFF;
  212. ((unsigned char &)Speed) = speed;
  213. }
  214. /***********************************************************************************************
  215. * FootClass::Mark -- Unit interface to map rendering system. *
  216. * *
  217. * This routine is the interface function for units as they relate to *
  218. * the map rendering system. Whenever a unit's imagery changes, this *
  219. * function is called. *
  220. * *
  221. * INPUT: mark -- Type of image change (MARK_UP, _DOWN, _CHANGE) *
  222. * MARK_UP -- Unit is removed. *
  223. * MARK_CHANGE -- Unit alters image but doesn't move. *
  224. * MARK_DOWN -- Unit is overlaid onto existing icons. *
  225. * *
  226. * OUTPUT: bool; Did the marking operation succeed? Failure could be the result of marking *
  227. * down when it is already down, or visa versa. *
  228. * *
  229. * WARNINGS: none *
  230. * *
  231. * HISTORY: *
  232. * 09/14/1991 JLB : Created. *
  233. * 04/15/1994 JLB : Converted to member function. *
  234. * 12/23/1994 JLB : Performs low level check before processing. *
  235. *=============================================================================================*/
  236. bool FootClass::Mark(MarkType mark)
  237. {
  238. assert(this != 0);
  239. assert(IsActive);
  240. if (TechnoClass::Mark(mark)) {
  241. // short list[32];
  242. CELL cell = Coord_Cell(Coord);
  243. #ifndef PARTIAL
  244. if (In_Which_Layer() != LAYER_GROUND && (mark == MARK_UP || mark == MARK_DOWN)) mark = MARK_CHANGE;
  245. #endif
  246. /*
  247. ** Inform the map of the refresh, occupation, and overlap
  248. ** request.
  249. */
  250. switch (mark) {
  251. case MARK_UP:
  252. Map.Pick_Up(cell, this);
  253. break;
  254. case MARK_DOWN:
  255. Map.Place_Down(cell, this);
  256. break;
  257. case MARK_CHANGE_REDRAW:
  258. Map.Refresh_Cells(cell, Overlap_List(true));
  259. Map.Refresh_Cells(cell, Occupy_List());
  260. break;
  261. default:
  262. Map.Refresh_Cells(cell, Overlap_List());
  263. Map.Refresh_Cells(cell, Occupy_List());
  264. break;
  265. }
  266. return(true);
  267. }
  268. return(false);
  269. }
  270. /***********************************************************************************************
  271. * FootClass::Basic_Path -- Finds the basic path for a ground object. *
  272. * *
  273. * This is a common routine used by both infantry and other ground travelling units. It *
  274. * will fill in the unit's basic path to the NavCom destination. *
  275. * *
  276. * INPUT: none *
  277. * *
  278. * OUTPUT: bool; Was a path found? A failure to find a path means either the target cannot *
  279. * be found or the terrain prohibits the unit's movement. *
  280. * *
  281. * WARNINGS: none *
  282. * *
  283. * HISTORY: *
  284. * 10/17/1994 JLB : Created. *
  285. *=============================================================================================*/
  286. bool FootClass::Basic_Path(void)
  287. {
  288. assert(IsActive);
  289. PathType * path; // Pointer to path control structure.
  290. CELL cell;
  291. int skip_path = false;
  292. Path[0] = FACING_NONE;
  293. if (Target_Legal(NavCom)) {
  294. cell = As_Cell(NavCom);
  295. /*
  296. ** When the navigation computer is set to a location that is impassible, then
  297. ** find a nearby cell that can be entered and try to head toward that instead.
  298. ** EXCEPT when that cell is very close -- then just bail.
  299. */
  300. int dist = Distance(NavCom);
  301. int checkdist = Team.Is_Valid() ? Rule.StrayDistance : Rule.CloseEnoughDistance;
  302. if (Can_Enter_Cell(cell) > MOVE_CLOAK && dist > checkdist) {
  303. CELL cell2 = Map.Nearby_Location(cell, Techno_Type_Class()->Speed, Map[Coord].Zones[Techno_Type_Class()->MZone], Techno_Type_Class()->MZone);
  304. if (cell2 != 0 && ::Distance(Cell_Coord(cell), Cell_Coord(cell2)) < dist) cell = cell2;
  305. }
  306. if (What_Am_I() == RTTI_INFANTRY) {
  307. CELL mycell = Coord_Cell(Center_Coord());
  308. ObjectClass * obj = Map[mycell].Cell_Occupier();
  309. while (obj) {
  310. if (obj != this && obj->What_Am_I() == RTTI_INFANTRY) {
  311. InfantryClass * inf = (InfantryClass *)obj;
  312. if (inf->NavCom == NavCom && inf->Path[0] != FACING_NONE) {
  313. if (Coord_Cell(inf->Head_To_Coord()) == Coord_Cell(inf->Coord)) {
  314. Mem_Copy(&inf->Path[1], Path, sizeof(Path)-sizeof(Path[0]));
  315. } else {
  316. Mem_Copy(inf->Path, Path, sizeof(Path));
  317. }
  318. if (Path[0] != FACING_NONE) {
  319. skip_path = true;
  320. }
  321. break;
  322. }
  323. }
  324. obj = obj->Next;
  325. }
  326. }
  327. if (!skip_path) {
  328. Mark(MARK_UP);
  329. Path[0] = FACING_NONE; // Probably not necessary, but...
  330. /*
  331. ** Try to find a path to the destination. If a failure occurs, then keep trying
  332. ** with greater determination until either a complete failure occurs, or a decent
  333. ** path was found.
  334. */
  335. bool found1=false; // Found a best path yet?
  336. PathType path1;
  337. FacingType workpath1[200]; // Staging area for path list.
  338. // FacingType workpath2[200]; // Staging area for path list.
  339. MoveType maxtype = MOVE_TEMP;
  340. if (!House->IsHuman) {
  341. maxtype = MOVE_TEMP;
  342. // maxtype = MOVE_DESTROYABLE;
  343. } else {
  344. /*
  345. ** For simple movement missions by the human player, then don't
  346. ** consider friendly units as passable if close to the destination.
  347. ** This will prevent a human controlled unit from just sitting next
  348. ** to a destination just because there is another friendly unit
  349. ** occupying the destination location.
  350. */
  351. if (Mission == MISSION_MOVE && Distance(NavCom) < Rule.CloseEnoughDistance) {
  352. maxtype = MOVE_DESTROYABLE;
  353. }
  354. }
  355. /*
  356. ** Try to find a path to the destination. If there is a path
  357. ** failure, then try a more severe path method until the
  358. ** maximum severity is reached.
  359. */
  360. for (;;) {
  361. path = Find_Path(cell, &workpath1[0], sizeof(workpath1), PathThreshhold);
  362. if (path && path->Cost) {
  363. memcpy(&path1, path, sizeof(path1));
  364. found1 = true;
  365. break;
  366. }
  367. /*
  368. ** A valid path was not found. Try the next greater path severity
  369. ** level if the severity can be increased. If not, then consider this
  370. ** a total failure.
  371. */
  372. PathThreshhold++;
  373. if (PathThreshhold > maxtype) break;
  374. }
  375. #ifdef NEVER
  376. /*
  377. ** Determine if ANY path could be calculated by first examining the most
  378. ** aggressive case. If this fails, then no path will succeed. Further
  379. ** scanning is unnecessary.
  380. */
  381. path = Find_Path(cell, &workpath1[0], sizeof(workpath1), maxtype);
  382. if (path && path->Cost) {
  383. memcpy(&path1, path, sizeof(path1));
  384. found1 = true;
  385. /*
  386. ** Scan for the best path possible. If this succeeds, then do a simple
  387. ** comparison with the most aggressive path. If they are very close, then
  388. ** go with the best (easiest) path method.
  389. */
  390. path = Find_Path(cell, &workpath2[0], sizeof(workpath2), MOVE_CLOAK);
  391. if (path && path->Cost && path->Cost < max((path1.Cost + (path1.Cost/2)), 3)) {
  392. memcpy(&path1, path, sizeof(path1));
  393. memcpy(workpath1, workpath2, sizeof(workpath1));
  394. } else {
  395. /*
  396. ** The easiest path method didn't result in a satisfactory path. Scan through
  397. ** the rest of the path options, looking for the best one.
  398. */
  399. for (MoveType move = (MoveType)(MOVE_CLOAK+1); move < (MoveType)(maxtype-1); move++) {
  400. // for (MoveType move = MOVE_MOVING_BLOCK; move < maxtype-1; move++) {
  401. path = Find_Path(cell, &workpath2[0], sizeof(workpath2), move);
  402. if (path && path->Cost && path->Cost < max((path1.Cost + (path1.Cost/2)), 3)) {
  403. memcpy(&path1, path, sizeof(path1));
  404. memcpy(workpath1, workpath2, sizeof(workpath1));
  405. }
  406. }
  407. }
  408. }
  409. #endif
  410. /*
  411. ** If a good path was found, then record it in the object's path
  412. ** list.
  413. */
  414. if (found1) {
  415. Fixup_Path(&path1);
  416. memcpy(&Path[0], &workpath1[0], min(path->Length, (int)sizeof(Path)));
  417. }
  418. Mark(MARK_DOWN);
  419. }
  420. PathDelay = Rule.PathDelay * TICKS_PER_MINUTE;
  421. if (Path[0] != FACING_NONE) return(true);
  422. /*
  423. ** If a basic path couldn't be determined, then abort the navigation process.
  424. */
  425. Stop_Driver();
  426. }
  427. return(false);
  428. }
  429. /***********************************************************************************************
  430. * FootClass::Mission_Move -- AI process for moving a vehicle to its destination. *
  431. * *
  432. * This simple AI script handles moving the vehicle to its desired destination. Since *
  433. * simple movement is handled directly by the engine, this routine merely waits until *
  434. * the unit has reached its destination, and then causes the unit to enter idle mode. *
  435. * *
  436. * INPUT: none *
  437. * *
  438. * OUTPUT: Returns with the delay before calling this routine again. *
  439. * *
  440. * WARNINGS: none *
  441. * *
  442. * HISTORY: *
  443. * 07/18/1994 JLB : Created. *
  444. * 10/02/1996 JLB : Player controlled or human owned units don't scan for targets. *
  445. *=============================================================================================*/
  446. int FootClass::Mission_Move(void)
  447. {
  448. assert(IsActive);
  449. if (!Target_Legal(NavCom) && !IsDriving && MissionQueue == MISSION_NONE) {
  450. Enter_Idle_Mode();
  451. return(1);
  452. }
  453. // if (!Target_Legal(TarCom) && !House->IsPlayerControl && !House->IsHuman) {
  454. if (!Target_Legal(TarCom) && !House->IsPlayerControl && !House->IsHuman && (!Team.Is_Valid() || !Team->Class->IsSuicide)) {
  455. Target_Something_Nearby(THREAT_RANGE);
  456. }
  457. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  458. }
  459. /***********************************************************************************************
  460. * FootClass::Mission_Capture -- Handles the capture mission. *
  461. * *
  462. * Capture missions are nearly the same as normal movement missions. The only difference *
  463. * is that the final destination is handled in a special way so that it is not marked as *
  464. * impassable. This allows the object (usually infantry) the ability to walk onto the *
  465. * object and thus capture it. *
  466. * *
  467. * INPUT: none *
  468. * *
  469. * OUTPUT: Returns with the number of game ticks to delay before calling this routine. *
  470. * *
  471. * WARNINGS: none *
  472. * *
  473. * HISTORY: *
  474. * 03/19/1995 JLB : Created. *
  475. *=============================================================================================*/
  476. int FootClass::Mission_Capture(void)
  477. {
  478. assert(IsActive);
  479. /*
  480. ** If there is a valid TarCom but the NavCom isn't set, then set the NavCom accordingly.
  481. */
  482. if (Is_Target_Building(TarCom) && !Target_Legal(NavCom) && What_Am_I() == RTTI_INFANTRY && ((InfantryClass *)this)->Class->IsBomber) {
  483. Assign_Destination(TarCom);
  484. }
  485. if (!Target_Legal(NavCom) /*&& !In_Radio_Contact()*/) {
  486. Enter_Idle_Mode();
  487. if (Map[Center_Coord()].Cell_Building()) {
  488. Scatter(0, true);
  489. }
  490. }
  491. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  492. }
  493. /***********************************************************************************************
  494. * FootClass::Mission_Attack -- AI for heading towards and firing upon target. *
  495. * *
  496. * This AI routine handles heading to within range of the target and then firing upon *
  497. * it until it is destroyed. If the target is destroyed, then the unit will change *
  498. * missions to match its "idle mode" of operation (usually guarding). *
  499. * *
  500. * INPUT: none *
  501. * *
  502. * OUTPUT: Returns with the delay before calling this routine again. *
  503. * *
  504. * WARNINGS: none *
  505. * *
  506. * HISTORY: *
  507. * 07/18/1994 JLB : Created. *
  508. *=============================================================================================*/
  509. int FootClass::Mission_Attack(void)
  510. {
  511. assert(IsActive);
  512. if (Target_Legal(TarCom)) {
  513. Approach_Target();
  514. } else {
  515. Enter_Idle_Mode();
  516. }
  517. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  518. }
  519. /***********************************************************************************************
  520. * FootClass::Mission_Guard -- Handles the AI for guarding in place. *
  521. * *
  522. * Units that are performing stationary guard duty use this AI process. They will sit *
  523. * still and target any enemies that get within range. *
  524. * *
  525. * INPUT: none *
  526. * *
  527. * OUTPUT: Returns with the delay before calling this routine again. *
  528. * *
  529. * WARNINGS: none *
  530. * *
  531. * HISTORY: *
  532. * 07/18/1994 JLB : Created. *
  533. *=============================================================================================*/
  534. int FootClass::Mission_Guard(void)
  535. {
  536. assert(IsActive);
  537. /*
  538. ** If this unit is on an impassable cell for any reason, it needs to scatter immediately
  539. */
  540. if (What_Am_I() == RTTI_INFANTRY || What_Am_I() == RTTI_UNIT) {
  541. LandType land = Map[Coord].Land_Type();
  542. if (!Target_Legal(NavCom) && (land == LAND_ROCK || land == LAND_WATER || land == LAND_RIVER)) {
  543. Scatter(0, true, true);
  544. Shorten_Mission_Timer();
  545. }
  546. }
  547. if (!Target_Something_Nearby(THREAT_RANGE)) {
  548. Random_Animate();
  549. }
  550. int dtime = MissionControl[Mission].Normal_Delay();
  551. if (What_Am_I() == RTTI_VESSEL) {
  552. switch (((VesselClass *)this)->Class->Type) {
  553. case VESSEL_DD:
  554. case VESSEL_PT:
  555. dtime = MissionControl[Mission].AA_Delay();
  556. break;
  557. case VESSEL_CA:
  558. dtime *= 2;
  559. break;
  560. default:
  561. break;
  562. }
  563. }
  564. if (What_Am_I() == RTTI_INFANTRY) {
  565. /*
  566. ** If this is a bomber type infantry and the current target is a building, then go into
  567. ** sabotage mode if not already.
  568. */
  569. if (!House->IsHuman && Is_Target_Building(TarCom) && ((InfantryClass *)this)->Class->IsBomber && Mission != MISSION_SABOTAGE) {
  570. Assign_Mission(MISSION_SABOTAGE);
  571. }
  572. switch (((InfantryClass *)this)->Class->Type) {
  573. case INFANTRY_E1:
  574. case INFANTRY_E3:
  575. dtime = MissionControl[Mission].AA_Delay();
  576. break;
  577. default:
  578. break;
  579. }
  580. }
  581. return((Arm != 0) ? (int)Arm : (dtime+Random_Pick(0, 2)));
  582. }
  583. /***********************************************************************************************
  584. * FootClass::Mission_Hunt -- Handles the default hunt order. *
  585. * *
  586. * This routine is the default hunt order for game objects. It handles searching for a *
  587. * nearby object and heading toward it. The act of targeting will cause it to attack *
  588. * the target it selects. *
  589. * *
  590. * INPUT: none *
  591. * *
  592. * OUTPUT: Returns the game tick delay before calling this routine again. *
  593. * *
  594. * WARNINGS: none *
  595. * *
  596. * HISTORY: *
  597. * 10/17/1994 JLB : Created. *
  598. *=============================================================================================*/
  599. int FootClass::Mission_Hunt(void)
  600. {
  601. assert(IsActive);
  602. if (!Target_Something_Nearby(THREAT_NORMAL)) {
  603. #if(0)
  604. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  605. if (What_Am_I() == RTTI_INFANTRY && *(InfantryClass *)this == INFANTRY_GENERAL && House->Class->House==HOUSE_UKRAINE && Scen.Scenario==47) {
  606. for(int index=0; index < Buildings.Count(); index++) {
  607. if(Buildings.Ptr(index)->IsOwnedByPlayer) {
  608. Assign_Target(Buildings.Ptr(index)->As_Target());
  609. break;
  610. }
  611. }
  612. for(index=0; index < Units.Count(); index++) {
  613. if(Units.Ptr(index)->IsOwnedByPlayer) {
  614. Assign_Target(Units.Ptr(index)->As_Target());
  615. break;
  616. }
  617. }
  618. for(index=0; index < Infantry.Count(); index++) {
  619. if(Infantry.Ptr(index)->IsOwnedByPlayer) {
  620. Assign_Target(Infantry.Ptr(index)->As_Target());
  621. break;
  622. }
  623. }
  624. for(index=0; index < Aircraft.Count(); index++) {
  625. if(Aircraft.Ptr(index)->IsOwnedByPlayer) {
  626. Assign_Target(Aircraft.Ptr(index)->As_Target());
  627. break;
  628. }
  629. }
  630. }
  631. #endif
  632. #endif
  633. Random_Animate();
  634. } else {
  635. if (What_Am_I() == RTTI_INFANTRY && ( ((InfantryTypeClass const &)Class_Of()).Type == INFANTRY_RENOVATOR || ((InfantryTypeClass const &)Class_Of()).Type == INFANTRY_THIEF) ) {
  636. Assign_Destination(TarCom);
  637. Assign_Mission(MISSION_CAPTURE);
  638. } else {
  639. if (What_Am_I() == RTTI_INFANTRY && ((InfantryClass *)this)->Class->IsBomber && Is_Target_Building(TarCom)) {
  640. Assign_Destination(TarCom);
  641. Assign_Mission(MISSION_SABOTAGE);
  642. } else {
  643. Approach_Target();
  644. }
  645. }
  646. }
  647. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  648. }
  649. /***********************************************************************************************
  650. * FootClass::Stop_Driver -- This routine clears the driving state of the object. *
  651. * *
  652. * This is the counterpart routine to the Start_Driver function. It clears the driving *
  653. * status flags and destination coordinate record. *
  654. * *
  655. * INPUT: none *
  656. * *
  657. * OUTPUT: bool; Was driving stopped? *
  658. * *
  659. * WARNINGS: none *
  660. * *
  661. * HISTORY: *
  662. * 10/17/1994 JLB : Created. *
  663. * 12/12/1994 JLB : Greatly simplified. *
  664. *=============================================================================================*/
  665. bool FootClass::Stop_Driver(void)
  666. {
  667. assert(IsActive);
  668. if (HeadToCoord) {
  669. HeadToCoord = NULL;
  670. Set_Speed(0);
  671. IsDriving = false;
  672. IsMovingOntoBridge = false;
  673. return(true);
  674. }
  675. return(false);
  676. }
  677. /***********************************************************************************************
  678. * FootClass::Start_Driver -- This starts the driver heading to the destination desired. *
  679. * *
  680. * Before a unit can move it must be started by this routine. This routine handles *
  681. * reserving the cell and setting the driving flag. *
  682. * *
  683. * INPUT: headto -- The coordinate of the immediate drive destination. This is one cell *
  684. * away from the unit's current location. *
  685. * *
  686. * OUTPUT: bool; Was driving initiated? *
  687. * *
  688. * WARNINGS: none *
  689. * *
  690. * HISTORY: *
  691. * 10/17/1994 JLB : Created. *
  692. * 12/12/1994 JLB : Uses simple spot index finder. *
  693. *=============================================================================================*/
  694. bool FootClass::Start_Driver(COORDINATE &headto)
  695. {
  696. assert(IsActive);
  697. Stop_Driver();
  698. if (headto) {
  699. HeadToCoord = headto;
  700. IsDriving = true;
  701. CellClass * cellptr = &Map[headto];
  702. TemplateType ttype = cellptr->TType;
  703. IsMovingOntoBridge = (ttype >= TEMPLATE_BRIDGE1 && ttype <= TEMPLATE_BRIDGE2D) || (ttype >= TEMPLATE_BRIDGE_1A && ttype <= TEMPLATE_BRIDGE_3F);
  704. /*
  705. ** Check for crate goodie finder here.
  706. */
  707. if (Map[headto].Goodie_Check(this)) {
  708. return(true);
  709. }
  710. if (!IsActive) return(false);
  711. HeadToCoord = NULL;
  712. IsDriving = false;
  713. }
  714. return(false);
  715. }
  716. /***********************************************************************************************
  717. * FootClass::Sort_Y -- Determine the sort coordinate for foot class objects. *
  718. * *
  719. * This routine will determine the sort coordinate for foot class object. This coordinate *
  720. * is usually the coordinate of the object. The exception is if the object is tethered. *
  721. * In this case (presumes offloading to the north), the sorting coordinate is adjusted *
  722. * so that the object will be drawn on top of the transport unit. *
  723. * *
  724. * INPUT: none *
  725. * *
  726. * OUTPUT: Returns with the coordinate to use for sorting. *
  727. * *
  728. * WARNINGS: none *
  729. * *
  730. * HISTORY: *
  731. * 10/17/1994 JLB : Created. *
  732. * 11/04/1994 JLB : Sort value is different when unloading from aircraft. *
  733. *=============================================================================================*/
  734. COORDINATE FootClass::Sort_Y(void) const
  735. {
  736. assert(IsActive);
  737. if (IsUnloading) {
  738. return(Coord_Add(Coord, 0x01000000L));
  739. }
  740. if (In_Radio_Contact() && IsTethered && Contact_With_Whom()->What_Am_I() == RTTI_UNIT) {
  741. return(Coord_Add(Coord, 0x01000000L));
  742. }
  743. return(Coord_Add(Coord, 0x00300000L));
  744. }
  745. /***********************************************************************************************
  746. * FootClass::Stun -- Prepares a ground travelling object for removal. *
  747. * *
  748. * This routine clears the units' navigation computer in preparation for removal from the *
  749. * game. This is probably called as a result of unit destruction in combat. Clearing the *
  750. * navigation computer ensures that the normal AI process won't start it moving again while *
  751. * the object is undergoing any death animations. *
  752. * *
  753. * INPUT: none *
  754. * *
  755. * OUTPUT: none *
  756. * *
  757. * WARNINGS: none *
  758. * *
  759. * HISTORY: *
  760. * 12/23/1994 JLB : Created. *
  761. *=============================================================================================*/
  762. void FootClass::Stun(void)
  763. {
  764. assert(IsActive);
  765. Assign_Destination(TARGET_NONE);
  766. Path[0] = FACING_NONE;
  767. Stop_Driver();
  768. TechnoClass::Stun();
  769. }
  770. /***********************************************************************************************
  771. * FootClass::Approach_Target -- Sets the navigation computer to approach target object. *
  772. * *
  773. * This routine will set the navigation computer to approach the target indicated by the *
  774. * targeting computer. It is through this function that the unit nears the target so *
  775. * that weapon firing may occur. *
  776. * *
  777. * INPUT: none *
  778. * *
  779. * OUTPUT: none *
  780. * *
  781. * WARNINGS: none *
  782. * *
  783. * HISTORY: *
  784. * 05/31/1994 JLB : Created. *
  785. * 12/13/1994 JLB : Made part of TechnoClass. *
  786. * 12/22/1994 JLB : Enhanced search algorithm. *
  787. * 05/20/1995 JLB : Always approaches if the object is off the map. *
  788. *=============================================================================================*/
  789. void FootClass::Approach_Target(void)
  790. {
  791. assert(IsActive);
  792. /*
  793. ** Determine that if there is an existing target it is still legal
  794. ** and within range.
  795. */
  796. if (Target_Legal(TarCom)) {
  797. int primary = What_Weapon_Should_I_Use(TarCom);
  798. /*
  799. ** If the target is too far away then head toward it.
  800. */
  801. int maxrange = Weapon_Range(primary);
  802. // int maxrange = max(Weapon_Range(0), Weapon_Range(1));
  803. if (!Target_Legal(NavCom) && (!In_Range(TarCom, primary) || !IsLocked)) {
  804. // if (!Target_Legal(NavCom) && (Distance(TarCom) > maxrange || !IsLocked)) {
  805. /*
  806. ** If the object that we are attacking is a building adjust the unit's
  807. ** max range so that people can stand far away from the buildings and
  808. ** hit them.
  809. */
  810. BuildingClass * obj = As_Building(TarCom);
  811. if (obj) {
  812. maxrange += ((obj->Class->Width() + obj->Class->Height()) * (0x100 / 4));
  813. }
  814. /*
  815. ** Adjust the max range of an infantry unit for where he is standing
  816. ** in the room.
  817. */
  818. maxrange -= 0x00B7;
  819. #ifdef OBSOLETE
  820. if (What_Am_I() == RTTI_INFANTRY) {
  821. maxrange -= 0x0111;
  822. } else {
  823. maxrange -= 0x00B7;
  824. }
  825. #endif
  826. maxrange = max(maxrange, 0);
  827. COORDINATE tcoord = ::As_Coord(TarCom);
  828. COORDINATE trycoord = 0;
  829. CELL tcell = Coord_Cell(tcoord);
  830. CELL trycell = tcell;
  831. DirType dir = Direction256(tcoord, Center_Coord());
  832. bool found = false;
  833. /*
  834. ** Sweep through the cells between the target and the unit, looking for
  835. ** a cell that the unit can enter but which is also within weapon range
  836. ** of the target. If after a reasonable search, no appropriate cell could
  837. ** be found, then the target will be assigned as the movement destination
  838. ** and let "the chips fall where they may."
  839. */
  840. for (int range = maxrange; range > 0x0080; range -= 0x0100) {
  841. static int _angles[] = {0, 8, -8, 16, -16, 24, -24, 32, -32, 48, -48, 64, -64};
  842. for (int index = 0; index < (sizeof(_angles)/sizeof(_angles[0])); index++) {
  843. trycoord = Coord_Move(tcoord, (DirType)(dir + _angles[index]), range);
  844. if (::Distance(trycoord, tcoord) < range) {
  845. trycell = Coord_Cell(trycoord);
  846. if (Map.In_Radar(trycell) && Map[trycell].Is_Clear_To_Move(Techno_Type_Class()->Speed, false, false, Map[Coord].Zones[Techno_Type_Class()->MZone], Techno_Type_Class()->MZone)) {
  847. // if (Can_Enter_Cell(trycell) <= MOVE_CLOAK && Map.In_Radar(trycell)) {
  848. found = true;
  849. break;
  850. }
  851. }
  852. }
  853. if (found) break;
  854. }
  855. /*
  856. ** If a suitable intermediate location was found, then head toward it.
  857. ** Otherwise, head toward the enemy unit directly.
  858. ** Infantry always head towards the target since they can enter a cell
  859. ** in range, but still not be able to hit the target if the spot is out of range.
  860. */
  861. if (What_Am_I() == RTTI_INFANTRY) {
  862. Assign_Destination(TarCom);
  863. } else if (found) {
  864. Assign_Destination(::As_Target(trycell));
  865. } else {
  866. trycell = Map.Nearby_Location(trycell, Techno_Type_Class()->Speed, Map[Coord].Zones[Techno_Type_Class()->MZone], Techno_Type_Class()->MZone);
  867. Assign_Destination(::As_Target(trycell));
  868. // Assign_Destination(TarCom);
  869. }
  870. }
  871. }
  872. }
  873. /***********************************************************************************************
  874. * FootClass::Mission_Guard_Area -- Causes unit to guard an area about twice weapon range. *
  875. * *
  876. * This mission routine causes the unit to scan for targets out to twice its weapon range *
  877. * from the home point. If a target was found, then it will be attacked. The unit will *
  878. * chase the target until it gets up to to its weapon range from the home position. *
  879. * In that case, it will return to home position and start scanning for another target. *
  880. * *
  881. * INPUT: none *
  882. * *
  883. * OUTPUT: Returns with time delay before calling this routine again. *
  884. * *
  885. * WARNINGS: none *
  886. * *
  887. * HISTORY: *
  888. * 12/23/1994 JLB : Created. *
  889. * 07/27/1995 JLB : Greatly simplified. *
  890. *=============================================================================================*/
  891. int FootClass::Mission_Guard_Area(void)
  892. {
  893. assert(IsActive);
  894. /*
  895. ** If this unit is on an impassable cell for any reason, it needs to scatter immediately
  896. */
  897. if (What_Am_I() == RTTI_INFANTRY || What_Am_I() == RTTI_UNIT) {
  898. LandType land = Map[Coord].Land_Type();
  899. if (!Target_Legal(NavCom) && (land == LAND_ROCK || land == LAND_WATER || land == LAND_RIVER)) {
  900. Scatter(0, true, true);
  901. Shorten_Mission_Timer();
  902. }
  903. }
  904. if (What_Am_I() == RTTI_UNIT && ((UnitClass *)this)->Class->IsToHarvest) {
  905. Assign_Mission(MISSION_HARVEST);
  906. return(1+Random_Pick(1, 10));
  907. }
  908. /*
  909. ** Ensure that the archive target is valid.
  910. */
  911. if (!Target_Legal(ArchiveTarget)) {
  912. ArchiveTarget = ::As_Target(Coord);
  913. }
  914. /*
  915. ** Ensure units aren't trying to guard cells off the map.
  916. */
  917. if (Target_Legal(NavCom) && Is_Target_Cell(NavCom)) {
  918. CELL cell = As_Cell(NavCom);
  919. int x = Cell_X(cell);
  920. int y = Cell_Y(cell);
  921. if (x < Map.MapCellX || y < Map.MapCellY || x >= (Map.MapCellX + Map.MapCellWidth) || y >= (Map.MapCellY + Map.MapCellHeight)) {
  922. Assign_Target(TARGET_NONE);
  923. Assign_Destination(TARGET_NONE);
  924. ArchiveTarget = ::As_Target(Coord);
  925. }
  926. }
  927. /*
  928. ** If this is a bomber type infantry and the current target is a building, then go into
  929. ** sabotage mode if not already.
  930. */
  931. if (!House->IsHuman && What_Am_I() == RTTI_INFANTRY && Is_Target_Building(TarCom) && ((InfantryClass *)this)->Class->IsBomber && Mission != MISSION_SABOTAGE) {
  932. Assign_Mission(MISSION_SABOTAGE);
  933. return(1);
  934. }
  935. /*
  936. ** Make sure that the unit has not strayed too far from the home position.
  937. ** If it has, then race back to it.
  938. */
  939. int maxrange = Threat_Range(1)/2;
  940. if (!IsFiring && !Target_Legal(NavCom) && Distance(ArchiveTarget) > maxrange) {
  941. Assign_Target(TARGET_NONE);
  942. Assign_Destination(ArchiveTarget);
  943. }
  944. if (!Target_Legal(TarCom)) {
  945. COORDINATE old = Coord;
  946. Coord = As_Coord(ArchiveTarget);
  947. Target_Something_Nearby(THREAT_AREA);
  948. Coord = old;
  949. if (Target_Legal(TarCom)) {
  950. return(1);
  951. }
  952. Random_Animate();
  953. } else {
  954. Approach_Target();
  955. }
  956. int dtime = MissionControl[Mission].Normal_Delay();
  957. if (What_Am_I() == RTTI_AIRCRAFT) {
  958. dtime *= 2;
  959. }
  960. return(dtime + Random_Pick(1, 5));
  961. }
  962. /***********************************************************************************************
  963. * FootClass::Unlimbo -- Unlimbos object and performs special fixups. *
  964. * *
  965. * This routine will make sure that the home position for the foot class object gets *
  966. * reset. This is necessary since the home position may change depending on the unit's *
  967. * transition between limbo and non-limbo condition. *
  968. * *
  969. * INPUT: coord -- The coordinate to unlimbo the unit at. *
  970. * *
  971. * dir -- The initial direction to give the unit. *
  972. * *
  973. * OUTPUT: bool; Was the unit unlimboed successfully? *
  974. * *
  975. * WARNINGS: none *
  976. * *
  977. * HISTORY: *
  978. * 12/23/1994 JLB : Created. *
  979. *=============================================================================================*/
  980. bool FootClass::Unlimbo(COORDINATE coord, DirType dir)
  981. {
  982. assert(IsActive);
  983. /*
  984. ** Try to unlimbo the unit.
  985. */
  986. if (TechnoClass::Unlimbo(coord, dir)) {
  987. /*
  988. ** Mobile units are always revealed to the house that owns them.
  989. */
  990. Revealed(House);
  991. /*
  992. ** Start in a still (non-moving) state.
  993. */
  994. Path[0] = FACING_NONE;
  995. return(true);
  996. }
  997. return(false);
  998. }
  999. /***********************************************************************************************
  1000. * FootClass::Take_Damage -- Handles taking damage to this object. *
  1001. * *
  1002. * This routine intercepts the damage assigned to this object and if this object is *
  1003. * a member of a team, it informs the team that the damage has occurred. The team may *
  1004. * change it's priority or action based on this event. *
  1005. * *
  1006. * INPUT: damage -- The damage points inflicted on the unit. *
  1007. * *
  1008. * distance -- The distance from the point of damage to the unit itself. *
  1009. * *
  1010. * warhead -- The type of damage that is inflicted. *
  1011. * *
  1012. * source -- The perpetrator of the damage. By knowing who caused the damage, *
  1013. * the team know's who to "get even with". *
  1014. * *
  1015. * OUTPUT: Returns with the result type of the damage. *
  1016. * *
  1017. * WARNINGS: none *
  1018. * *
  1019. * HISTORY: *
  1020. * 12/30/1994 JLB : Created. *
  1021. *=============================================================================================*/
  1022. ResultType FootClass::Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source, bool forced)
  1023. {
  1024. assert(IsActive);
  1025. ResultType result = TechnoClass::Take_Damage(damage, distance, warhead, source, forced);
  1026. if (result != RESULT_NONE && Team) {
  1027. Team->Took_Damage(this, result, source);
  1028. } else {
  1029. if (result != RESULT_DESTROYED && result != RESULT_NONE) {
  1030. /*
  1031. ** Determine if the target that is currently being attacked has a weapon that can
  1032. ** do harm to a ground based unit. This information is needed so that an appropriate
  1033. ** response will occur when damage is taken.
  1034. */
  1035. // bool tweap = false;
  1036. // if (As_Techno(TarCom)) {
  1037. // tweap = (As_Techno(TarCom)->Techno_Type_Class()->PrimaryWeapon != NULL);
  1038. // }
  1039. /*
  1040. ** This ensures that if a unit is in sticky mode, then it will snap out of
  1041. ** it when it takes damage.
  1042. */
  1043. if (source != NULL && MissionControl[Mission].IsNoThreat && !MissionControl[Mission].IsZombie) {
  1044. Enter_Idle_Mode();
  1045. }
  1046. /*
  1047. ** If this object is not part of a team and it can retaliate for the damage, then have
  1048. ** it try to do so. This prevents it from just sitting there and taking damage.
  1049. */
  1050. if (Is_Allowed_To_Retaliate(source)) {
  1051. int primary = What_Weapon_Should_I_Use(source->As_Target());
  1052. if (In_Range(source, primary) || !House->IsHuman) {
  1053. Assign_Target(source->As_Target());
  1054. }
  1055. if (Mission == MISSION_AMBUSH) {
  1056. Assign_Mission(MISSION_HUNT);
  1057. }
  1058. /*
  1059. ** Simple retaliation cannot occur because the source of the damage
  1060. ** is too far away. If scatter logic is enabled, then scatter now.
  1061. */
  1062. if (!Target_Legal(TarCom) && !Target_Legal(NavCom) && Rule.IsScatter) {
  1063. Scatter(0, true);
  1064. }
  1065. } else {
  1066. /*
  1067. ** If this object isn't doing anything important, then scatter.
  1068. */
  1069. if (MissionControl[Mission].IsScatter && !IsTethered && !IsDriving && !Target_Legal(TarCom) && !Target_Legal(NavCom) && What_Am_I() != RTTI_AIRCRAFT && What_Am_I() != RTTI_VESSEL) {
  1070. if (!House->IsHuman || Rule.IsScatter) {
  1071. Scatter(0, true);
  1072. }
  1073. }
  1074. }
  1075. }
  1076. }
  1077. return(result);
  1078. }
  1079. /***********************************************************************************************
  1080. * FootClass::Active_Click_With -- Initiates attack or move according to target clicked on. *
  1081. * *
  1082. * At this level, the object is known to have the ability to attack or move to the *
  1083. * target specified (in theory). Perform the attack or move as indicated. *
  1084. * *
  1085. * INPUT: target -- The target clicked upon that will precipitate action. *
  1086. * *
  1087. * OUTPUT: Returns with the type of action performed. *
  1088. * *
  1089. * WARNINGS: none *
  1090. * *
  1091. * HISTORY: *
  1092. * 01/06/1995 JLB : Created. *
  1093. *=============================================================================================*/
  1094. void FootClass::Active_Click_With(ActionType action, ObjectClass * object)
  1095. {
  1096. assert(IsActive);
  1097. assert(object != NULL);
  1098. switch (action) {
  1099. case ACTION_GUARD_AREA:
  1100. if (Can_Player_Fire() && Can_Player_Move()) {
  1101. if (What_Am_I() == RTTI_INFANTRY &&
  1102. ((InfantryClass *)this)->Class->IsBomber &&
  1103. object->What_Am_I() == RTTI_BUILDING &&
  1104. !House->Is_Ally(object)) {
  1105. Player_Assign_Mission(MISSION_SABOTAGE, TARGET_NONE, object->As_Target());
  1106. } else {
  1107. Player_Assign_Mission(MISSION_GUARD_AREA, object->As_Target());
  1108. }
  1109. }
  1110. break;
  1111. case ACTION_SELF:
  1112. Player_Assign_Mission(MISSION_UNLOAD);
  1113. break;
  1114. case ACTION_ATTACK:
  1115. if (Can_Player_Fire()) {
  1116. Player_Assign_Mission(MISSION_ATTACK, object->As_Target());
  1117. }
  1118. break;
  1119. case ACTION_ENTER:
  1120. if (Can_Player_Move() && object && object->Is_Techno() /*&& !((RadioClass *)object)->In_Radio_Contact()*/) {
  1121. Player_Assign_Mission(MISSION_ENTER, TARGET_NONE, object->As_Target());
  1122. }
  1123. break;
  1124. case ACTION_CAPTURE:
  1125. if (Can_Player_Move()) {
  1126. Player_Assign_Mission(MISSION_CAPTURE, TARGET_NONE, object->As_Target());
  1127. }
  1128. break;
  1129. case ACTION_SABOTAGE:
  1130. if (Can_Player_Move()) {
  1131. Player_Assign_Mission(MISSION_SABOTAGE, TARGET_NONE, object->As_Target());
  1132. }
  1133. break;
  1134. case ACTION_NOMOVE:
  1135. case ACTION_MOVE:
  1136. if (Can_Player_Move()) {
  1137. TARGET targ = object->As_Target();
  1138. /*
  1139. ** If the destination object is not the same zone, then pick a nearby location.
  1140. */
  1141. if (object->What_Am_I() != RTTI_AIRCRAFT && Techno_Type_Class()->Speed != SPEED_WINGED && Map[Coord].Zones[Techno_Type_Class()->MZone] != Map[object->Center_Coord()].Zones[Techno_Type_Class()->MZone]) {
  1142. #ifdef FIXIT_MINE_PASSABLE
  1143. // Fixes units not driving onto mines.
  1144. if (Can_Enter_Cell(Coord_Cell(object->Center_Coord())) > MOVE_OK) {
  1145. targ = ::As_Target(Map.Nearby_Location(Coord_Cell(object->Center_Coord()), Techno_Type_Class()->Speed, Map[Coord].Zones[Techno_Type_Class()->MZone], Techno_Type_Class()->MZone));
  1146. }
  1147. #else
  1148. targ = ::As_Target(Map.Nearby_Location(Coord_Cell(object->Center_Coord()), Techno_Type_Class()->Speed, Map[Coord].Zones[Techno_Type_Class()->MZone], Techno_Type_Class()->MZone));
  1149. #endif
  1150. }
  1151. Player_Assign_Mission(MISSION_MOVE, TARGET_NONE, targ);
  1152. }
  1153. break;
  1154. case ACTION_NO_DEPLOY:
  1155. Speak(VOX_DEPLOY);
  1156. break;
  1157. default:
  1158. break;
  1159. }
  1160. }
  1161. /***********************************************************************************************
  1162. * FootClass::Active_Click_With -- Performs action as a result of left mouse click. *
  1163. * *
  1164. * This routine performs the action requested when the left mouse button was clicked over *
  1165. * a cell. Typically, this is just a move command. *
  1166. * *
  1167. * INPUT: action -- The predetermined action that should occur. *
  1168. * *
  1169. * cell -- The cell number that the action should occur at. *
  1170. * *
  1171. * OUTPUT: none *
  1172. * *
  1173. * WARNINGS: none *
  1174. * *
  1175. * HISTORY: *
  1176. * 01/19/1995 JLB : Created. *
  1177. *=============================================================================================*/
  1178. void FootClass::Active_Click_With(ActionType action, CELL cell)
  1179. {
  1180. assert(IsActive);
  1181. action = What_Action(cell);
  1182. switch (action) {
  1183. case ACTION_HARVEST:
  1184. Player_Assign_Mission(MISSION_HARVEST, TARGET_NONE, ::As_Target(cell));
  1185. break;
  1186. case ACTION_MOVE:
  1187. if (AllowVoice) {
  1188. COORDINATE coord = Map.Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y());
  1189. OutList.Add(EventClass(ANIM_MOVE_FLASH, PlayerPtr->Class->House, coord, 1 << PlayerPtr->Class->House));
  1190. }
  1191. // Fall into next case.
  1192. case ACTION_NOMOVE:
  1193. //using function for IsVisible so we have different results for different players - JAS 2019/09/30
  1194. if (What_Am_I() != RTTI_AIRCRAFT || Map[cell].Is_Visible(PlayerPtr)) {
  1195. /*
  1196. ** Find the closest same-zoned cell to where the unit currently is.
  1197. ** This will allow the unit to come as close to the destination cell
  1198. ** as is reasonably possible, when clicking on an impassable cell
  1199. ** (as is likely when clicking in the shroud.) It looks for the
  1200. ** nearest cell using an expanding-radius box, and ignores cells
  1201. ** off the edge of the map.
  1202. */
  1203. CellClass const * cellptr = &Map[::As_Cell(::As_Target(Center_Coord()))];
  1204. if (What_Am_I() != RTTI_AIRCRAFT) {
  1205. if (Can_Enter_Cell(Coord_Cell(Center_Coord())) == MOVE_OK) {
  1206. cell = Map.Nearby_Location(cell, Techno_Type_Class()->Speed, cellptr->Zones[Techno_Type_Class()->MZone], Techno_Type_Class()->MZone);
  1207. } else {
  1208. cell = Map.Nearby_Location(cell, Techno_Type_Class()->Speed);
  1209. }
  1210. #ifdef OBSOLETE
  1211. cell = Map.Nearby_Location(cell, Techno_Type_Class()->Speed, cellptr->Zones[Techno_Type_Class()->MZone], Techno_Type_Class()->MZone);
  1212. #endif
  1213. }
  1214. Player_Assign_Mission(MISSION_MOVE, TARGET_NONE, ::As_Target(cell));
  1215. }
  1216. break;
  1217. case ACTION_ATTACK:
  1218. Player_Assign_Mission(MISSION_ATTACK, ::As_Target(cell));
  1219. break;
  1220. /*
  1221. ** Engineer attempting to capture bridge to repair it
  1222. */
  1223. case ACTION_CAPTURE:
  1224. if (Can_Player_Move()) {
  1225. Player_Assign_Mission(MISSION_CAPTURE, TARGET_NONE, ::As_Target(cell));
  1226. }
  1227. break;
  1228. case ACTION_SABOTAGE:
  1229. Player_Assign_Mission(MISSION_SABOTAGE, TARGET_NONE, ::As_Target(cell) );
  1230. break;
  1231. // MBL 05.15.2020 - Adding support for CTRL+ALT clicking the ground to have units move to an area and guard it
  1232. case ACTION_GUARD_AREA:
  1233. if (Can_Player_Fire() && Can_Player_Move()) {
  1234. Player_Assign_Mission(MISSION_GUARD_AREA, ::As_Target(cell));
  1235. }
  1236. break;
  1237. // END MBL 05.15.2020
  1238. }
  1239. }
  1240. /***********************************************************************************************
  1241. * FootClass::Per_Cell_Process -- Perform action based on once-per-cell condition. *
  1242. * *
  1243. * This routine is called as this object moves from cell to cell. When the center of the *
  1244. * cell is reached, check to see if any trigger should be sprung. For moving units, reduce *
  1245. * the path to the distance to the target. This forces path recalculation in an effort to *
  1246. * avoid units passing each other. *
  1247. * *
  1248. * INPUT: why -- Specifies the circumstances under which this routine was called. *
  1249. * *
  1250. * OUTPUT: none *
  1251. * *
  1252. * WARNINGS: none *
  1253. * *
  1254. * HISTORY: *
  1255. * 05/08/1995 JLB : Created. *
  1256. * 07/08/1995 JLB : Handles generic enter trigger event. *
  1257. * 07/16/1995 JLB : If next to a scanner and cloaked, then shimmer. *
  1258. *=============================================================================================*/
  1259. void FootClass::Per_Cell_Process(PCPType why)
  1260. {
  1261. assert(IsActive);
  1262. if (why == PCP_END) {
  1263. IsScattering = false;
  1264. /*
  1265. ** Clear any unloading flag if necessary.
  1266. */
  1267. IsUnloading = false;
  1268. /*
  1269. ** If adjacent to an enemy techno that has the ability to reveal a sub,
  1270. ** then shimmer the cloaked object.
  1271. */
  1272. if (Cloak == CLOAKED) {
  1273. for (FacingType face = FACING_N; face < FACING_COUNT; face++) {
  1274. CELL cell = Adjacent_Cell(Coord_Cell(Coord), face);
  1275. if (Map.In_Radar(cell)) {
  1276. TechnoClass const * techno = Map[cell].Cell_Techno();
  1277. if (techno && !techno->House->Is_Ally(this) && techno->Techno_Type_Class()->IsScanner) {
  1278. Do_Shimmer();
  1279. break;
  1280. }
  1281. }
  1282. }
  1283. }
  1284. /*
  1285. ** Shorten the path if the target is now within weapon range of this
  1286. ** unit and this unit is on an attack type mission. But only if the target
  1287. ** is slow enough for leading to make sense.
  1288. */
  1289. if (Target_Legal(TarCom) && (What_Am_I() != RTTI_INFANTRY || !((InfantryClass *)this)->Class->IsDog)) {
  1290. int primary = What_Weapon_Should_I_Use(TarCom);
  1291. bool inrange = In_Range(TarCom, primary);
  1292. TechnoClass const * techno = As_Techno(TarCom);
  1293. if (techno != NULL && techno->Is_Foot()) {
  1294. FootClass const * foot = (FootClass const *)techno;
  1295. MPHType speed = ((TechnoTypeClass const &)techno->Class_Of()).MaxSpeed;
  1296. COORDINATE rangecoord = (speed > MPH_SLOW) ? foot->Likely_Coord() : foot->Target_Coord();
  1297. inrange = In_Range(rangecoord, primary);
  1298. }
  1299. if ((Mission == MISSION_RESCUE || Mission == MISSION_GUARD_AREA || Mission == MISSION_ATTACK || Mission == MISSION_HUNT) && inrange) {
  1300. Assign_Destination(TARGET_NONE);
  1301. Path[0] = FACING_NONE;
  1302. }
  1303. }
  1304. /*
  1305. ** Trigger event associated with the player entering the cell.
  1306. */
  1307. if (Cloak != CLOAKED) {
  1308. TriggerClass * trigger = Map[Coord].Trigger;
  1309. if (trigger != NULL) {
  1310. trigger->Spring(TEVENT_PLAYER_ENTERED, this, Coord_Cell(Coord));
  1311. if (!IsActive) return;
  1312. }
  1313. /*
  1314. ** Check for horizontal trigger crossing.
  1315. */
  1316. int x = Cell_X(Coord_Cell(Coord));
  1317. int y = Cell_Y(Coord_Cell(Coord));
  1318. int index;
  1319. for (index = 0; index < Map.MapCellWidth; index++) {
  1320. trigger = Map[XY_Cell(index+Map.MapCellX, y)].Trigger;
  1321. if (trigger != NULL) {
  1322. if (trigger->Class->Event1.Event == TEVENT_CROSS_HORIZONTAL || (trigger->Class->EventControl != MULTI_ONLY && trigger->Class->Event2.Event == TEVENT_CROSS_HORIZONTAL)) {
  1323. trigger->Spring(TEVENT_CROSS_HORIZONTAL, this, Coord_Cell(Coord));
  1324. if (!IsActive) return;
  1325. }
  1326. }
  1327. }
  1328. /*
  1329. ** Check for vertical trigger crossing.
  1330. */
  1331. for (index = 0; index < Map.MapCellHeight; index++) {
  1332. trigger = Map[XY_Cell(x, index+Map.MapCellY)].Trigger;
  1333. if (trigger != NULL) {
  1334. if (trigger->Class->Event1.Event == TEVENT_CROSS_VERTICAL || (trigger->Class->EventControl != MULTI_ONLY && trigger->Class->Event2.Event == TEVENT_CROSS_VERTICAL)) {
  1335. trigger->Spring(TEVENT_CROSS_VERTICAL, this, Coord_Cell(Coord));
  1336. if (!IsActive) return;
  1337. }
  1338. }
  1339. }
  1340. /*
  1341. ** Check for zone entry trigger events.
  1342. */
  1343. for (MapTriggerID = 0; MapTriggerID < MapTriggers.Count(); MapTriggerID++) {
  1344. trigger = MapTriggers[MapTriggerID];
  1345. if (trigger->Class->Event1.Event == TEVENT_ENTERS_ZONE || (trigger->Class->EventControl != MULTI_ONLY && trigger->Class->Event2.Event == TEVENT_ENTERS_ZONE)) {
  1346. if (Map[trigger->Cell].Zones[Techno_Type_Class()->MZone] == Map[Coord].Zones[Techno_Type_Class()->MZone]) {
  1347. trigger->Spring(TEVENT_ENTERS_ZONE, this, Coord_Cell(Coord));
  1348. if (!IsActive) return;
  1349. }
  1350. }
  1351. }
  1352. /*
  1353. ** If any of these triggers cause this unit to be destroyed, then
  1354. ** stop all further processing for this unit.
  1355. */
  1356. if (!IsActive) return;
  1357. }
  1358. #ifdef OBSOLETE
  1359. /*
  1360. ** Flag any gap generators to re-draw
  1361. */
  1362. for (int index = 0; index <Buildings.Count(); index++) {
  1363. BuildingClass * obj = Buildings.Ptr(index);
  1364. if (obj && *obj == STRUCT_GAP && !obj->IsInLimbo && (HouseClass *)obj->House != PlayerPtr) {
  1365. int dist = Distance(obj) / CELL_LEPTON_W;
  1366. if (dist < (6 + Rule.GapShroudRadius) ) {
  1367. // if (dist < (6 + obj->Class->SightRange) ) {
  1368. obj->IsJamming = false; // lie so it'll re-jam now
  1369. }
  1370. }
  1371. }
  1372. #endif
  1373. }
  1374. TechnoClass::Per_Cell_Process(why);
  1375. }
  1376. /***************************************************************************
  1377. * FootClass::Override_Mission -- temporarily overrides a units mission *
  1378. * *
  1379. * *
  1380. * *
  1381. * INPUT: MissionType mission - the mission we want to override *
  1382. * TARGET tarcom - the new target we want to override *
  1383. * TARGET navcom - the new navigation point to override *
  1384. * *
  1385. * OUTPUT: none *
  1386. * *
  1387. * WARNINGS: If a mission is already overridden, the current mission is *
  1388. * just re-assigned. *
  1389. * *
  1390. * HISTORY: *
  1391. * 04/28/1995 PWG : Created. *
  1392. *=========================================================================*/
  1393. void FootClass::Override_Mission(MissionType mission, TARGET tarcom, TARGET navcom)
  1394. {
  1395. assert(IsActive);
  1396. SuspendedNavCom = NavCom;
  1397. TechnoClass::Override_Mission(mission, tarcom, navcom);
  1398. Assign_Destination(navcom);
  1399. }
  1400. /***************************************************************************
  1401. * FootClass::Restore_Mission -- Restores an overridden mission *
  1402. * *
  1403. * INPUT: none *
  1404. * *
  1405. * OUTPUT: none *
  1406. * *
  1407. * WARNINGS: none *
  1408. * *
  1409. * HISTORY: *
  1410. * 04/28/1995 PWG : Created. *
  1411. *=========================================================================*/
  1412. bool FootClass::Restore_Mission(void)
  1413. {
  1414. assert(IsActive);
  1415. if (TechnoClass::Restore_Mission()) {
  1416. Assign_Destination(SuspendedNavCom);
  1417. return(true);
  1418. }
  1419. return(false);
  1420. }
  1421. /***********************************************************************************************
  1422. * FootClass::Receive_Message -- Movement related radio messages are handled here. *
  1423. * *
  1424. * This routine handles radio message that are related to movement. These are used for *
  1425. * complex coordinated maneuvers. *
  1426. * *
  1427. * INPUT: from -- Pointer to the originator of this radio message. *
  1428. * *
  1429. * message -- The radio message that is being received. *
  1430. * *
  1431. * param -- The optional parameter (could be a movement destination). *
  1432. * *
  1433. * OUTPUT: Returns with the radio response appropriate to the message received. Usually the *
  1434. * response is RADIO_ROGER. *
  1435. * *
  1436. * WARNINGS: none *
  1437. * *
  1438. * HISTORY: *
  1439. * 05/14/1995 JLB : Created. *
  1440. *=============================================================================================*/
  1441. RadioMessageType FootClass::Receive_Message(RadioClass * from, RadioMessageType message, long & param)
  1442. {
  1443. assert(IsActive);
  1444. switch (message) {
  1445. /*
  1446. ** Answers if this object is located on top of a service depot.
  1447. */
  1448. case RADIO_ON_DEPOT:
  1449. if (Map[Center_Coord()].Cell_Building() != NULL) {
  1450. BuildingClass const * building = Map[Center_Coord()].Cell_Building();
  1451. if (*building == STRUCT_REPAIR) {
  1452. return(RADIO_ROGER);
  1453. }
  1454. }
  1455. return(RADIO_NEGATIVE);
  1456. /*
  1457. ** Intercept the repair request and if this object is moving, then no repair
  1458. ** is possible.
  1459. */
  1460. case RADIO_REPAIR:
  1461. if (Target_Legal(NavCom)) return(RADIO_NEGATIVE);
  1462. break;
  1463. /*
  1464. ** Something bad has happened to the object in contact with. Abort any coordinated
  1465. ** activity with this object. Basically, ... run away! Run away!
  1466. */
  1467. case RADIO_RUN_AWAY:
  1468. if (In_Radio_Contact()) {
  1469. if (NavCom == Contact_With_Whom()->As_Target()) {
  1470. Assign_Destination(TARGET_NONE);
  1471. }
  1472. }
  1473. if (Mission == MISSION_SLEEP) {
  1474. Assign_Mission(MISSION_GUARD);
  1475. Commence();
  1476. }
  1477. if (Mission == MISSION_ENTER) {
  1478. Assign_Mission(MISSION_GUARD);
  1479. }
  1480. if (!IsRotating && !Target_Legal(NavCom)) {
  1481. Scatter(0, true, true);
  1482. }
  1483. break;
  1484. /*
  1485. ** Checks to see if this unit needs to move somewhere. If it is already in motion,
  1486. ** then it doesn't need further movement instructions.
  1487. */
  1488. case RADIO_NEED_TO_MOVE:
  1489. param = (long)NavCom;
  1490. if (!Target_Legal(NavCom)) {
  1491. return(RADIO_ROGER);
  1492. }
  1493. return(RADIO_NEGATIVE);
  1494. /*
  1495. ** Radio request to move to location specified. Typically this is used
  1496. ** for complex loading and unloading missions.
  1497. */
  1498. case RADIO_MOVE_HERE:
  1499. if (NavCom != (TARGET)param) {
  1500. if (::As_Target(Coord_Cell(Coord)) == (TARGET)param) {
  1501. return(RADIO_YEA_NOW_WHAT);
  1502. } else {
  1503. if (Mission == MISSION_GUARD && MissionQueue == MISSION_NONE) {
  1504. Assign_Mission(MISSION_MOVE);
  1505. }
  1506. Assign_Destination((TARGET)param);
  1507. Shorten_Mission_Timer();
  1508. }
  1509. }
  1510. return(RADIO_ROGER);
  1511. /*
  1512. ** Requests if this unit is trying to cooperatively load up. Typically, this occurs
  1513. ** for passengers and when vehicles need to be repaired.
  1514. */
  1515. case RADIO_TRYING_TO_LOAD:
  1516. if (Mission == MISSION_ENTER || MissionQueue == MISSION_ENTER) {
  1517. TechnoClass::Receive_Message(from, message, param);
  1518. return(RADIO_ROGER);
  1519. }
  1520. break;
  1521. }
  1522. return(TechnoClass::Receive_Message(from, message, param));
  1523. }
  1524. /***********************************************************************************************
  1525. * FootClass::Mission_Enter -- Enter (cooperatively) mission handler. *
  1526. * *
  1527. * This mission handler will cooperatively coordinate the object to maneuver into the *
  1528. * object it is in radio contact with. This is used by infantry when they wish to load *
  1529. * into an APC as well as by vehicles when they wish to enter a repair facility. *
  1530. * *
  1531. * INPUT: none *
  1532. * *
  1533. * OUTPUT: Returns the number of game ticks before this routine should be called again. *
  1534. * *
  1535. * WARNINGS: none *
  1536. * *
  1537. * HISTORY: *
  1538. * 05/15/1995 JLB : Created. *
  1539. * 09/22/1995 JLB : Modified to handle the "on hold" condition. *
  1540. *=============================================================================================*/
  1541. int FootClass::Mission_Enter(void)
  1542. {
  1543. assert(IsActive);
  1544. /*
  1545. ** Find out who to coordinate with. If in radio contact, then this the transporter is
  1546. ** defined. If not in radio contact, then try the archive target value to see if that
  1547. ** is suitable.
  1548. */
  1549. TechnoClass * contact = Contact_With_Whom();
  1550. if (contact == NULL) {
  1551. contact = As_Techno(ArchiveTarget);
  1552. }
  1553. /*
  1554. ** If in contact, then let the transporter handle the movement coordination.
  1555. */
  1556. if (contact != NULL) {
  1557. /*
  1558. ** If the transport says to "bug off", then abort the enter mission. The transport may
  1559. ** likely say all is 'ok' with the "RADIO ROGER", then try again later.
  1560. */
  1561. if (Transmit_Message(RADIO_DOCKING, contact) != RADIO_ROGER && !IsTethered) {
  1562. Transmit_Message(RADIO_OVER_OUT);
  1563. Enter_Idle_Mode();
  1564. }
  1565. } else {
  1566. /*
  1567. ** Since there is no potential object to enter, then abort this
  1568. ** mission with some default standby mission.
  1569. */
  1570. if (MissionQueue == MISSION_NONE) {
  1571. /*
  1572. ** If this is a harvester, then return to harvesting.
  1573. ** Set a hacky target so we know to skip to the proper state.
  1574. */
  1575. if (What_Am_I() == RTTI_UNIT && ((UnitClass*)this)->Class->IsToHarvest) {
  1576. Assign_Mission(MISSION_HARVEST);
  1577. Assign_Target(As_Target());
  1578. Assign_Destination(TARGET_NONE);
  1579. } else {
  1580. Enter_Idle_Mode();
  1581. }
  1582. }
  1583. }
  1584. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  1585. }
  1586. /***********************************************************************************************
  1587. * FootClass::Assign_Destination -- Assigns specified destination to NavCom. *
  1588. * *
  1589. * This routine will assign the specified target to the navigation computer. No legality *
  1590. * checks are performed. *
  1591. * *
  1592. * INPUT: target -- The target value to assign to the navigation computer. *
  1593. * *
  1594. * OUTPUT: none *
  1595. * *
  1596. * WARNINGS: none *
  1597. * *
  1598. * HISTORY: *
  1599. * 07/08/1995 JLB : Created. *
  1600. *=============================================================================================*/
  1601. void FootClass::Assign_Destination(TARGET target)
  1602. {
  1603. assert(IsActive);
  1604. NavCom = target;
  1605. /*
  1606. ** Presume that the easiest path is tried first. As the findpath proceeds, when
  1607. ** a failure occurs, this threshhold will be increased until path failure
  1608. ** cannot be prevent. At this point, all movement should cease.
  1609. */
  1610. PathThreshhold = MOVE_CLOAK;
  1611. }
  1612. /***********************************************************************************************
  1613. * FootClass::Detach_All -- Removes this object from the game system. *
  1614. * *
  1615. * This routine will remove this object from the game system. This routine is called when *
  1616. * this object is about to be deleted. All other objects should no longer reference this *
  1617. * object in that case. *
  1618. * *
  1619. * INPUT: none *
  1620. * *
  1621. * OUTPUT: none *
  1622. * *
  1623. * WARNINGS: none *
  1624. * *
  1625. * HISTORY: *
  1626. * 07/08/1995 JLB : Created. *
  1627. *=============================================================================================*/
  1628. void FootClass::Detach_All(bool all)
  1629. {
  1630. assert(IsActive);
  1631. if (Team && !ScenarioInit) {
  1632. Team->Remove(this);
  1633. Team = NULL;
  1634. }
  1635. TechnoClass::Detach_All(all);
  1636. }
  1637. /***********************************************************************************************
  1638. * FootClass::Rescue_Mission -- Calls this unit to the rescue. *
  1639. * *
  1640. * This routine is called when the house determines that it should attack the specified *
  1641. * target. This routine will determine if it can attack the target specified and if so, *
  1642. * the amount of power it can throw at it. This returned power value is used to allow *
  1643. * intelligent distribution of retaliation. *
  1644. * *
  1645. * INPUT: target -- The target that this object just might be assigned to attack and thus *
  1646. * how much power it can bring to bear should be returned. *
  1647. * *
  1648. * OUTPUT: Returns with the amount of power that this object can bring to bear against the *
  1649. * potential target specified. *
  1650. * *
  1651. * WARNINGS: none *
  1652. * *
  1653. * HISTORY: *
  1654. * 07/08/1995 JLB : Created. *
  1655. *=============================================================================================*/
  1656. int FootClass::Rescue_Mission(TARGET tarcom)
  1657. {
  1658. assert(IsActive);
  1659. /*
  1660. ** If the target specified is not legal, then it cannot be attacked. Always return
  1661. ** zero in this case.
  1662. */
  1663. if (!Target_Legal(tarcom)) return(0);
  1664. /*
  1665. ** If the unit is already assigned to destroy the tarcom then we need
  1666. ** to return a negative value which tells the computer to lower the
  1667. ** desired threat rating.
  1668. */
  1669. if (TarCom == tarcom) {
  1670. return(-Risk());
  1671. }
  1672. /*
  1673. ** If the unit is currently attacking a target that has a weapon then we
  1674. ** cannot abandon it as it will destroy us if we return to base.
  1675. */
  1676. if (Target_Legal(TarCom)) {
  1677. TechnoClass * techno = As_Techno(TarCom);
  1678. if (techno != NULL && techno->Is_Weapon_Equipped()) {
  1679. return(0);
  1680. }
  1681. }
  1682. /*
  1683. ** If the unit is in a harvest mission or is currently attacking
  1684. ** something, or is not very effective, then it will be of no help
  1685. ** at all.
  1686. */
  1687. if (Team.Is_Valid() || Mission == MISSION_HARVEST || !Risk()) {
  1688. return(0);
  1689. }
  1690. /*
  1691. ** Find the distance to the target modified by the range. If the
  1692. ** the distance is 0, then things are ok.
  1693. */
  1694. int dist = Distance(tarcom) - Weapon_Range(0);
  1695. int threat = Risk() * 1024;
  1696. int speed = -1;
  1697. if (dist > 0) {
  1698. /*
  1699. ** Next we need to figure out how fast the unit moves because this
  1700. ** decreases the distance penalty.
  1701. */
  1702. speed = max((unsigned)Techno_Type_Class()->MaxSpeed, (unsigned)1);
  1703. int ratio = (speed > 0) ? Max(dist / speed, 1) : 1;
  1704. /*
  1705. ** Finally modify the threat by the distance the unit is away.
  1706. */
  1707. threat = max(threat/ratio, 1);
  1708. }
  1709. return(threat);
  1710. }
  1711. /***********************************************************************************************
  1712. * FootClass::Death_Announcement -- Announces the death of a unit. *
  1713. * *
  1714. * This routine is called when a unit (infantry, vehicle, or aircraft) is destroyed. *
  1715. * *
  1716. * INPUT: source -- The perpetrator of this death. *
  1717. * *
  1718. * OUTPUT: none *
  1719. * *
  1720. * WARNINGS: none *
  1721. * *
  1722. * HISTORY: *
  1723. * 07/01/1995 JLB : Created. *
  1724. *=============================================================================================*/
  1725. void FootClass::Death_Announcement(TechnoClass const * ) const
  1726. {
  1727. assert(IsActive);
  1728. //if (IsOwnedByPlayer) {
  1729. if ((Session.Type == GAME_GLYPHX_MULTIPLAYER && House->IsHuman) || (Session.Type != GAME_GLYPHX_MULTIPLAYER && IsOwnedByPlayer)) {
  1730. if (What_Am_I() == RTTI_VESSEL) {
  1731. // Speak(VOX_SHIP_LOST); // MBL 02.06.2020
  1732. Speak(VOX_SHIP_LOST, House, Center_Coord());
  1733. } else {
  1734. // Speak(VOX_UNIT_LOST); // MBL 02.06.2020
  1735. Speak(VOX_UNIT_LOST, House, Center_Coord());
  1736. }
  1737. }
  1738. }
  1739. /***********************************************************************************************
  1740. * FootClass::Greatest_Threat -- Fetches the greatest threat to this object. *
  1741. * *
  1742. * This routine will return with the greatest threat (best target) for this object. For *
  1743. * movable ground object, they won't automatically return ANY target if this object is *
  1744. * cloaked. Otherwise, cloaking is relatively useless. *
  1745. * *
  1746. * INPUT: method -- The request method (bit flags) to use when scanning for a target. *
  1747. * *
  1748. * OUTPUT: Returns with the best target to attack. If there is no target that qualifies, then *
  1749. * TARGET_NONE is returned. *
  1750. * *
  1751. * WARNINGS: none *
  1752. * *
  1753. * HISTORY: *
  1754. * 07/08/1995 JLB : Created. *
  1755. * 07/10/1996 JLB : Handles scan range limitation. *
  1756. *=============================================================================================*/
  1757. TARGET FootClass::Greatest_Threat(ThreatType method) const
  1758. {
  1759. assert(IsActive);
  1760. /*
  1761. ** If the scan is forced to be limited, then limit the scan now.
  1762. */
  1763. if (IsScanLimited) {
  1764. method = method & ~THREAT_AREA;
  1765. method = method | THREAT_RANGE;
  1766. }
  1767. /*
  1768. ** If this object can cloak, then it won't select a target automatically.
  1769. */
  1770. if (House->IsHuman && IsCloakable && Mission == MISSION_GUARD) {
  1771. return(TARGET_NONE);
  1772. }
  1773. if (!(method & (THREAT_INFANTRY|THREAT_VEHICLES|THREAT_BUILDINGS|THREAT_TIBERIUM|THREAT_BOATS|THREAT_CIVILIANS|THREAT_POWER|THREAT_FAKES|THREAT_FACTORIES|THREAT_BASE_DEFENSE))) {
  1774. if (What_Am_I() != RTTI_VESSEL) {
  1775. method = method | THREAT_GROUND;
  1776. } else {
  1777. method = method | THREAT_BOATS|THREAT_GROUND;
  1778. }
  1779. }
  1780. /*
  1781. ** Perform the search for the target.
  1782. */
  1783. TARGET target = TechnoClass::Greatest_Threat(method);
  1784. /*
  1785. ** If no target could be located and this object is under scan range
  1786. ** restrictions, then this restriction must be lifted now.
  1787. */
  1788. if (IsScanLimited && target == TARGET_NONE) {
  1789. const_cast<FootClass*>(this)->IsScanLimited = false; // const_cast ST - 5/8/2019
  1790. }
  1791. /*
  1792. ** Return with final target found.
  1793. */
  1794. return(target);
  1795. }
  1796. /***********************************************************************************************
  1797. * FootClass::Detach -- Detaches a target from tracking systems. *
  1798. * *
  1799. * This routine will detach the specified target from the tracking systems of this object. *
  1800. * It will be removed from the navigation computer and any queued mission record. *
  1801. * *
  1802. * INPUT: target -- The target to be removed from this object. *
  1803. * *
  1804. * all -- Is the unit really about to be eliminated? If this is true then even *
  1805. * friendly contact (i.e., radio) must be eliminated. *
  1806. * *
  1807. * OUTPUT: none *
  1808. * *
  1809. * WARNINGS: none *
  1810. * *
  1811. * HISTORY: *
  1812. * 07/18/1995 JLB : Created. *
  1813. * 07/24/1996 JLB : Removes target from NavQueue list. *
  1814. *=============================================================================================*/
  1815. void FootClass::Detach(TARGET target, bool all)
  1816. {
  1817. assert(IsActive);
  1818. TechnoClass::Detach(target, all);
  1819. if (!SpecialFlag) {
  1820. if (ArchiveTarget == target) {
  1821. ArchiveTarget = TARGET_NONE;
  1822. }
  1823. }
  1824. if (SuspendedNavCom == target) {
  1825. SuspendedNavCom = TARGET_NONE;
  1826. SuspendedMission = MISSION_NONE;
  1827. }
  1828. /*
  1829. ** If the navigation computer is assigned to the target, then the navigation
  1830. ** computer must be cleared.
  1831. */
  1832. if (NavCom == target) {
  1833. NavCom = TARGET_NONE;
  1834. Path[0] = FACING_NONE;
  1835. Restore_Mission();
  1836. }
  1837. /*
  1838. ** Remove the target from the NavQueue list as well.
  1839. */
  1840. int loop_count = 0;
  1841. for (int index = 0; index < ARRAY_SIZE(NavQueue); index++) {
  1842. if (NavQueue[index] == target) {
  1843. NavQueue[index] = TARGET_NONE;
  1844. if (index < ARRAY_SIZE(NavQueue)-1) {
  1845. memmove(&NavQueue[index], &NavQueue[index+1], ((ARRAY_SIZE(NavQueue)-index)-1) * sizeof(NavQueue[0]));
  1846. NavQueue[ARRAY_SIZE(NavQueue)-1] = TARGET_NONE;
  1847. index--;
  1848. }
  1849. }
  1850. /*
  1851. ** Extra safety check
  1852. */
  1853. loop_count++;
  1854. if (loop_count > ARRAY_SIZE(NavQueue)) {
  1855. break;
  1856. }
  1857. }
  1858. /*
  1859. ** If targeting the specified object and this unit is obviously heading
  1860. ** toward the target to get within range, then abort the path.
  1861. */
  1862. if (TarCom == target && House->IsHuman) {
  1863. Path[0] = FACING_NONE;
  1864. }
  1865. }
  1866. /***********************************************************************************************
  1867. * FootClass::Offload_Tiberium_Bail -- Fetches the Tiberium to offload per step. *
  1868. * *
  1869. * This routine is called when a packet/package/bail of Tiberium needs to be offloaded *
  1870. * from the object. This function is overridden for those objects that can contain *
  1871. * Tiberium. *
  1872. * *
  1873. * INPUT: none *
  1874. * *
  1875. * OUTPUT: Returns with the number of credits offloaded from the object. *
  1876. * *
  1877. * WARNINGS: This routine must be called multiple times in order to completely offload the *
  1878. * Tiberium. When this routine return 0, all Tiberium has been offloaded. *
  1879. * *
  1880. * HISTORY: *
  1881. * 07/19/1995 JLB : Created. *
  1882. *=============================================================================================*/
  1883. int FootClass::Offload_Tiberium_Bail(void)
  1884. {
  1885. assert(IsActive);
  1886. return(0);
  1887. }
  1888. /***********************************************************************************************
  1889. * FootClass::Can_Enter_Cell -- Checks to see if the object can enter cell specified. *
  1890. * *
  1891. * This routine examines the specified cell to see if the object can enter it. This *
  1892. * function is to be overridden for objects that could have the possibility of not being *
  1893. * allowed to enter the cell. Typical objects at the FootClass level always return *
  1894. * MOVE_OK. *
  1895. * *
  1896. * INPUT: cell -- The cell to examine. *
  1897. * *
  1898. * facing -- The direction that this cell might be entered from. *
  1899. * *
  1900. * OUTPUT: Returns with the move check result type. This will be MOVE_OK if there is not *
  1901. * blockage. There are various other values that represent other blockage types. *
  1902. * The value returned will indicated the most severe reason why entry into the cell *
  1903. * is blocked. *
  1904. * *
  1905. * WARNINGS: none *
  1906. * *
  1907. * HISTORY: *
  1908. * 07/19/1995 JLB : Created. *
  1909. *=============================================================================================*/
  1910. MoveType FootClass::Can_Enter_Cell(CELL , FacingType) const
  1911. {
  1912. assert(IsActive);
  1913. return MOVE_OK;
  1914. }
  1915. /***********************************************************************************************
  1916. * FootClass::Can_Demolish -- Checks to see if this object can be sold back. *
  1917. * *
  1918. * This routine determines if it is legal to sell the object back. A foot class object can *
  1919. * only be sold back if it is sitting on a repair bay. *
  1920. * *
  1921. * INPUT: none *
  1922. * *
  1923. * OUTPUT: Was the object successfully sold back? *
  1924. * *
  1925. * WARNINGS: none *
  1926. * *
  1927. * HISTORY: *
  1928. * 08/13/1995 JLB : Created. *
  1929. *=============================================================================================*/
  1930. bool FootClass::Can_Demolish(void) const
  1931. {
  1932. assert(IsActive);
  1933. StructType sell_struct = STRUCT_NONE;
  1934. switch (What_Am_I()) {
  1935. case RTTI_UNIT:
  1936. sell_struct = STRUCT_REPAIR;
  1937. break;
  1938. case RTTI_AIRCRAFT:
  1939. sell_struct = STRUCT_AIRSTRIP;
  1940. break;
  1941. default:
  1942. break;
  1943. }
  1944. if (sell_struct != STRUCT_NONE) {
  1945. if (In_Radio_Contact() &&
  1946. Contact_With_Whom()->What_Am_I() == RTTI_BUILDING &&
  1947. *((BuildingClass *)Contact_With_Whom()) == sell_struct &&
  1948. Distance(Contact_With_Whom()) < 0x0080) {
  1949. return(true);
  1950. }
  1951. }
  1952. return(TechnoClass::Can_Demolish());
  1953. }
  1954. /***********************************************************************************************
  1955. * FootClass::Sell_Back -- Causes this object to be sold back. *
  1956. * *
  1957. * When an object is sold back, a certain amount of money is refunded to the owner and then *
  1958. * the object is removed from the game system. *
  1959. * *
  1960. * INPUT: control -- The action to perform. The only supported action is "1", which means *
  1961. * to sell back. *
  1962. * *
  1963. * OUTPUT: none *
  1964. * *
  1965. * WARNINGS: none *
  1966. * *
  1967. * HISTORY: *
  1968. * 08/13/1995 JLB : Created. *
  1969. *=============================================================================================*/
  1970. void FootClass::Sell_Back(int control)
  1971. {
  1972. assert(IsActive);
  1973. if (control != 0) {
  1974. if (House == PlayerPtr) {
  1975. Speak(VOX_UNIT_SOLD);
  1976. Sound_Effect(VOC_CASHTURN);
  1977. }
  1978. House->Refund_Money(Refund_Amount());
  1979. Stun();
  1980. Limbo();
  1981. delete this;
  1982. }
  1983. }
  1984. /***********************************************************************************************
  1985. * FootClass::Likely_Coord -- Fetches the coordinate the object will be at shortly. *
  1986. * *
  1987. * This routine comes in handy when determining where a travelling object will be at *
  1988. * when considering the amount of time it would take for a normal unit to travel one cell. *
  1989. * Using this information, an intelligent "approach target" logic can be employed. *
  1990. * *
  1991. * INPUT: none *
  1992. * *
  1993. * OUTPUT: Returns with the coordinate the object is at or soon will be. *
  1994. * *
  1995. * WARNINGS: none *
  1996. * *
  1997. * HISTORY: *
  1998. * 08/13/1995 JLB : Created. *
  1999. *=============================================================================================*/
  2000. COORDINATE FootClass::Likely_Coord(void) const
  2001. {
  2002. assert(IsActive);
  2003. if (Head_To_Coord()) {
  2004. return(Head_To_Coord());
  2005. }
  2006. return(Target_Coord());
  2007. }
  2008. /***********************************************************************************************
  2009. * FootClass::Adjust_Dest -- Adjust candidate movement cell to account for formation. *
  2010. * *
  2011. * This routine modify the specified cell if the unit is part of a formation. The *
  2012. * adjustment will take into consideration the formation relative offset from the *
  2013. * (presumed) center cell specified. *
  2014. * *
  2015. * INPUT: cell -- The cell to presume as the desired center point of the formation. *
  2016. * *
  2017. * OUTPUT: Returns with the cell that should be used as the actual destination. If this *
  2018. * object is part of a formation, then the cell location will be appropriately *
  2019. * adjusted. *
  2020. * *
  2021. * WARNINGS: none *
  2022. * *
  2023. * HISTORY: *
  2024. * 03/11/1996 JLB : Created. *
  2025. *=============================================================================================*/
  2026. CELL FootClass::Adjust_Dest(CELL cell) const
  2027. {
  2028. assert(IsActive);
  2029. if (IsFormationMove) {
  2030. int xdest = Cell_X(cell);
  2031. int ydest = Cell_Y(cell);
  2032. int newx = Bound(XFormOffset + xdest, Map.MapCellX, Map.MapCellX + Map.MapCellWidth -1);
  2033. int newy = Bound(YFormOffset + ydest, Map.MapCellY, Map.MapCellY + Map.MapCellHeight -1);
  2034. cell = XY_Cell(newx, newy);
  2035. }
  2036. return(cell);
  2037. }
  2038. /***********************************************************************************************
  2039. * FootClass::Handle_Navigation_List -- Processes the navigation queue. *
  2040. * *
  2041. * This routine will process the navigation queue. If the queue is present and valid and *
  2042. * there is currently no navigation target assigned to this object, then the first entry *
  2043. * of the queue will be assigned. The remaining entries will move down. If the queue is *
  2044. * to be processed as a circular list, then the first entry is appended to the end. *
  2045. * *
  2046. * INPUT: none *
  2047. * *
  2048. * OUTPUT: none *
  2049. * *
  2050. * WARNINGS: This routine might end up assigning a movement destination. *
  2051. * *
  2052. * HISTORY: *
  2053. * 07/18/1996 JLB : Created. *
  2054. *=============================================================================================*/
  2055. void FootClass::Handle_Navigation_List(void)
  2056. {
  2057. /*
  2058. ** The navigation queue only needs to be processed if there is
  2059. ** currently no navigation target for this object.
  2060. */
  2061. if (!Target_Legal(NavCom)) {
  2062. TARGET target = NavQueue[0];
  2063. /*
  2064. ** Check to see if the navigation queue even exists and
  2065. ** has at least one valid entry. If it does, then process it by
  2066. ** assigning the object's NavCom to the first entry on the list.
  2067. */
  2068. if (Target_Legal(target)) {
  2069. Assign_Destination(target);
  2070. memmove(&NavQueue[0], &NavQueue[1], sizeof(NavQueue)-sizeof(NavQueue[0]));
  2071. NavQueue[ARRAY_SIZE(NavQueue)-1] = TARGET_NONE;
  2072. /*
  2073. ** If the navigation queue is to loop (indefinately), then append the
  2074. ** target value from the first part to the end of the queue.
  2075. */
  2076. if (IsNavQueueLoop) {
  2077. for (int index = 0; index < ARRAY_SIZE(NavQueue); index++) {
  2078. if (NavQueue[index] == TARGET_NONE) {
  2079. NavQueue[index] = target;
  2080. break;
  2081. }
  2082. }
  2083. }
  2084. }
  2085. }
  2086. }
  2087. /***********************************************************************************************
  2088. * FootClass::Queue_Navigation_List -- Add a target to the objects navigation list. *
  2089. * *
  2090. * This routine will append the destination target to the object's NavQueue list. After *
  2091. * doing so, if the object is not doing anything important, then it will be started on *
  2092. * that destination. This is functionally the same as Assign_Destination, but it stores *
  2093. * the target to the NavQueue first. *
  2094. * *
  2095. * INPUT: target -- The movement target destination to append the queue. *
  2096. * *
  2097. * OUTPUT: none *
  2098. * *
  2099. * WARNINGS: The queue is of finite size and any queue requests that would exceed that size *
  2100. * are ignored. If there are no queue entries pending and the unit is not *
  2101. * otherwise occupied, then the queue target might be carried directly into the *
  2102. * NavCom. *
  2103. * *
  2104. * HISTORY: *
  2105. * 07/18/1996 JLB : Created. *
  2106. *=============================================================================================*/
  2107. void FootClass::Queue_Navigation_List(TARGET target)
  2108. {
  2109. if (Target_Legal(target)) {
  2110. int count;
  2111. for (count = 0; count < ARRAY_SIZE(NavQueue); count++) {
  2112. if (!Target_Legal(NavQueue[count])) break;
  2113. }
  2114. /*
  2115. ** If the target is this object itself, then this indicates that the
  2116. ** queue list is to be processed as a loop. Otherwise, just tack the
  2117. ** navigation target to the end of the list.
  2118. */
  2119. if (target == As_Target() && count > 0) {
  2120. IsNavQueueLoop = true;
  2121. } else {
  2122. if (count == 0) {
  2123. IsNavQueueLoop = false;
  2124. }
  2125. if (count < ARRAY_SIZE(NavQueue)) {
  2126. NavQueue[count] = target;
  2127. }
  2128. }
  2129. /*
  2130. ** If this object isn't doing anything, then start acting on the
  2131. ** navigation queue now.
  2132. */
  2133. if (!Target_Legal(NavCom) && Mission == MISSION_GUARD) {
  2134. Enter_Idle_Mode();
  2135. }
  2136. }
  2137. }
  2138. /***********************************************************************************************
  2139. * FootClass::Clear_Navigation_List -- Clears out the navigation queue. *
  2140. * *
  2141. * This routine will clear out any values in the navigation queue. This is the preferred *
  2142. * way of aborting a navigation queue for a unit. If the unit is already travelling, it *
  2143. * won't be interrupted by this routine. *
  2144. * *
  2145. * INPUT: none *
  2146. * *
  2147. * OUTPUT: none *
  2148. * *
  2149. * WARNINGS: This will clear the navigation list but not the navigation computer. Thus a *
  2150. * unit will still travel to its current immediate destination. *
  2151. * *
  2152. * HISTORY: *
  2153. * 07/30/1996 JLB : Created. *
  2154. *=============================================================================================*/
  2155. void FootClass::Clear_Navigation_List(void)
  2156. {
  2157. for (int index = 0; index < ARRAY_SIZE(NavQueue); index++) {
  2158. NavQueue[index] = TARGET_NONE;
  2159. }
  2160. }
  2161. /***********************************************************************************************
  2162. * FootClass::Is_Allowed_To_Leave_Map -- Checks to see if it can leave the map and the game. *
  2163. * *
  2164. * This routine will determine if this object has permission to leave the map and thus *
  2165. * leave the game. Typical objects with this permission are transports used to drop of *
  2166. * reinforcements. *
  2167. * *
  2168. * INPUT: none *
  2169. * *
  2170. * OUTPUT: bool; Does this object have permission to travel off the map edge and leave the *
  2171. * game? *
  2172. * *
  2173. * WARNINGS: none *
  2174. * *
  2175. * HISTORY: *
  2176. * 08/05/1996 JLB : Created. *
  2177. *=============================================================================================*/
  2178. bool FootClass::Is_Allowed_To_Leave_Map(void) const
  2179. {
  2180. /*
  2181. ** If the unit hasn't entered the map yet, then don't allow leave the game.
  2182. */
  2183. if (!IsLocked) return(false);
  2184. /*
  2185. ** A unit that isn't marked as a loaner is a gift to the player. Such objects can never
  2186. ** leave the map unless they are part of a team that gives it special permision.
  2187. */
  2188. if (!IsALoaner && Mission != MISSION_RETREAT && (!Team.Is_Valid() || !Team->Is_Leaving_Map())) return(false);
  2189. return(true);
  2190. }
  2191. /***********************************************************************************************
  2192. * FootClass::Is_Recruitable -- Determine if this object is recruitable as a team members. *
  2193. * *
  2194. * This will examine this object to determine if it is suitable as a team recruit. Some *
  2195. * objects are disqualified if they are otherwise premptively occupied. *
  2196. * *
  2197. * INPUT: house -- Pointer to the house that is trying to recruit this object. *
  2198. * *
  2199. * OUTPUT: bool; Is this object suitable for recruitment by a team. *
  2200. * *
  2201. * WARNINGS: none *
  2202. * *
  2203. * HISTORY: *
  2204. * 09/14/1996 JLB : Created. *
  2205. *=============================================================================================*/
  2206. bool FootClass::Is_Recruitable(HouseClass const * house) const
  2207. {
  2208. /*
  2209. ** If not of the correct house presuasion, then recruitment is not allowed.
  2210. */
  2211. if (house != NULL && house != House) {
  2212. return(false);
  2213. }
  2214. /*
  2215. ** If the object is not a playing member of the game, then don't consider it available.
  2216. */
  2217. if (IsInLimbo) {
  2218. return(false);
  2219. }
  2220. /*
  2221. ** If it is already part of another team, then it is not available for
  2222. ** general recruitment.
  2223. */
  2224. if (Team.Is_Valid()) {
  2225. return(false);
  2226. }
  2227. /*
  2228. ** If it is currently in a mission the precludes recruitment into a team, then
  2229. ** return with this information.
  2230. */
  2231. if (!Is_Recruitable_Mission(Mission)) {
  2232. return(false);
  2233. }
  2234. /*
  2235. ** It was not disqualified for general team recruitment, so return that
  2236. ** it is available.
  2237. */
  2238. return(true);
  2239. }
  2240. /***********************************************************************************************
  2241. * FootClass::AI -- Handle general movement AI. *
  2242. * *
  2243. * This basically just sees if this object is within weapon range of the target and if *
  2244. * so, it will stop movement so that firing may commence. This prevents the occasional *
  2245. * case of an attacker driving right up to the defender before firing. *
  2246. * *
  2247. * INPUT: none *
  2248. * *
  2249. * OUTPUT: none *
  2250. * *
  2251. * WARNINGS: none *
  2252. * *
  2253. * HISTORY: *
  2254. * 09/17/1996 JLB : Created. *
  2255. *=============================================================================================*/
  2256. void FootClass::AI(void)
  2257. {
  2258. TechnoClass::AI();
  2259. // FootClass::Per_Cell_Process does this function already.
  2260. #ifdef OBSOLETE
  2261. if (IsActive) {
  2262. if (!IsScattering && !IsTethered && !IsInLimbo && What_Am_I() != RTTI_AIRCRAFT && Target_Legal(TarCom) && In_Range(TarCom)) {
  2263. Assign_Destination(TARGET_NONE);
  2264. }
  2265. }
  2266. #endif
  2267. }
  2268. /***********************************************************************************************
  2269. * FootClass::Is_On_Priority_Mission -- Checks to see if this object should be given priority. *
  2270. * *
  2271. * Some objects are on an important mission that must succeed. If the object is on such *
  2272. * a mission, then it will be more aggressive in its movement action. *
  2273. * *
  2274. * INPUT: none *
  2275. * *
  2276. * OUTPUT: bool; Is this object on a priority mission? *
  2277. * *
  2278. * WARNINGS: none *
  2279. * *
  2280. * HISTORY: *
  2281. * 09/30/1996 JLB : Created. *
  2282. *=============================================================================================*/
  2283. bool FootClass::Is_On_Priority_Mission(void) const
  2284. {
  2285. if (Mission == MISSION_ENTER) return(true);
  2286. return(false);
  2287. }
  2288. /***********************************************************************************************
  2289. * FootClass::Mission_Retreat -- Handle reatreat from map mission for mobile objects. *
  2290. * *
  2291. * This will try to make this mobile object leave the map. It does this by assigning a *
  2292. * movement destination that is located off the edge of the map. *
  2293. * *
  2294. * INPUT: none *
  2295. * *
  2296. * OUTPUT: Returns with the number of game frames to delay before calling this routine *
  2297. * again. *
  2298. * *
  2299. * WARNINGS: none *
  2300. * *
  2301. * HISTORY: *
  2302. * 10/05/1996 JLB : Created. *
  2303. *=============================================================================================*/
  2304. int FootClass::Mission_Retreat(void)
  2305. {
  2306. assert(IsActive);
  2307. enum {
  2308. FIND_EDGE,
  2309. TRAVELLING
  2310. };
  2311. switch (Status) {
  2312. /*
  2313. ** Find a suitable edge to travel to and then assign destination there.
  2314. */
  2315. case FIND_EDGE:
  2316. if (Target_Legal(NavCom)) {
  2317. Status = TRAVELLING;
  2318. } else {
  2319. CELL cell = 0;
  2320. /*
  2321. ** If this is part of a team, then pick the edge where the team as likely
  2322. ** entered from.
  2323. */
  2324. if (Team.Is_Valid() && Team->Class->Origin != -1) {
  2325. cell = Map.Calculated_Cell(House->Control.Edge, Team->Class->Origin, Coord_Cell(Center_Coord()), Techno_Type_Class()->Speed);
  2326. }
  2327. /*
  2328. ** If an edge hasn't been found, then try to find one that is not based on any
  2329. ** team information.
  2330. */
  2331. if (cell == 0) {
  2332. cell = Map.Calculated_Cell(House->Control.Edge, -1, Coord_Cell(Center_Coord()), Techno_Type_Class()->Speed);
  2333. }
  2334. assert(cell == 0); // An edge cell must be found!
  2335. Assign_Destination(::As_Target(cell));
  2336. Status = TRAVELLING;
  2337. }
  2338. break;
  2339. /*
  2340. ** While travelling, monitor that all is proceeding according to plan.
  2341. */
  2342. case TRAVELLING:
  2343. if (!Target_Legal(NavCom)) {
  2344. Status = FIND_EDGE;
  2345. }
  2346. break;
  2347. }
  2348. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  2349. }