FOOT.CPP 122 KB

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