AIRCRAFT.CPP 182 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/AIRCRAFT.CPP 1 3/03/97 10:24a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : AIRCRAFT.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : July 22, 1994 *
  26. * *
  27. * Last Update : November 2, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * AircraftClass::AI -- Processes the normal non-graphic AI for the aircraft. *
  32. * AircraftClass::Active_Click_With -- Handles clicking over specified cell. *
  33. * AircraftClass::Active_Click_With -- Handles clicking over specified object. *
  34. * AircraftClass::AircraftClass -- The constructor for aircraft objects. *
  35. * AircraftClass::Can_Enter_Cell -- Determines if the aircraft can land at this location. *
  36. * AircraftClass::Can_Fire -- Checks to see if the aircraft can fire. *
  37. * AircraftClass::Cell_Seems_Ok -- Checks to see if a cell is good to enter. *
  38. * AircraftClass::Desired_Load_Dir -- Determines where passengers should line up. *
  39. * AircraftClass::Draw_It -- Renders an aircraft object at the location specified. *
  40. * AircraftClass::Draw_Rotors -- Draw rotor blades on the aircraft. *
  41. * AircraftClass::Edge_Of_World_AI -- Detect if aircraft has exited the map. *
  42. * AircraftClass::Enter_Idle_Mode -- Gives the aircraft an appropriate mission. *
  43. * AircraftClass::Exit_Object -- Unloads passenger from aircraft. *
  44. * AircraftClass::Fire_At -- Handles firing a projectile from an aircraft. *
  45. * AircraftClass::Fire_Direction -- Determines the direction of fire. *
  46. * AircraftClass::Good_Fire_Location -- Searches for and finds a good spot to fire from. *
  47. * AircraftClass::Good_LZ -- Locates a good spot ot land. *
  48. * AircraftClass::In_Which_Layer -- Calculates the display layer of the aircraft. *
  49. * AircraftClass::Init -- Initialize the aircraft system to an empty state. *
  50. * AircraftClass::Is_LZ_Clear -- Determines if landing zone is free for landing. *
  51. * AircraftClass::Landing_Takeoff_AI -- Handle aircraft take off and landing processing. *
  52. * AircraftClass::Look -- Aircraft will look if they are on the ground always. *
  53. * AircraftClass::Mission_Attack -- Handles the attack mission for aircraft. *
  54. * AircraftClass::Mission_Enter -- Control aircraft to fly to the helipad or repair center. *
  55. * AircraftClass::Mission_Guard -- Handles aircraft in guard mode. *
  56. * AircraftClass::Mission_Guard_Area -- Handles the aircraft guard area logic. *
  57. * AircraftClass::Mission_Hunt -- Maintains hunt AI for the aircraft. *
  58. * AircraftClass::Mission_Move -- Handles movement mission. *
  59. * AircraftClass::Mission_Retreat -- Handles the aircraft logic for leaving the battlefield. *
  60. * AircraftClass::Mission_Unload -- Handles unloading cargo. *
  61. * AircraftClass::Movement_AI -- Handles aircraft physical movement logic. *
  62. * AircraftClass::New_LZ -- Find a good landing zone. *
  63. * AircraftClass::Overlap_List -- Returns with list of cells the aircraft overlaps. *
  64. * AircraftClass::Paradrop_Cargo -- Drop a passenger by parachute. *
  65. * AircraftClass::Per_Cell_Process -- Handle the aircraft per cell process. *
  66. * AircraftClass::Pip_Count -- Returns the number of "objects" in aircraft. *
  67. * AircraftClass::Player_Assign_Mission -- Handles player input to assign a mission. *
  68. * AircraftClass::Pose_Dir -- Fetches the natural landing facing. *
  69. * AircraftClass::Process_Fly_To -- Handles state machine for flying to destination. *
  70. * AircraftClass::Process_Landing -- Landing process state machine handler. *
  71. * AircraftClass::Process_Take_Off -- State machine support for taking off. *
  72. * AircraftClass::Read_INI -- Reads aircraft object data from an INI file. *
  73. * AircraftClass::Receive_Message -- Handles receipt of radio messages. *
  74. * AircraftClass::Response_Attack -- Gives audio response to attack order. *
  75. * AircraftClass::Response_Move -- Gives audio response to move request. *
  76. * AircraftClass::Response_Select -- Gives audio response when selected. *
  77. * AircraftClass::Rotation_AI -- Handle aircraft body and flight rotation. *
  78. * AircraftClass::Scatter -- Causes the aircraft to move away a bit. *
  79. * AircraftClass::Set_Speed -- Sets the speed for the aircraft. *
  80. * AircraftClass::Shape_Number -- Fetch the shape number to use for the aircraft. *
  81. * AircraftClass::Sort_Y -- Figures the sorting coordinate. *
  82. * AircraftClass::Take_Damage -- Applies damage to the aircraft. *
  83. * AircraftClass::Unlimbo -- Removes an aircraft from the limbo state. *
  84. * AircraftClass::What_Action -- Determines what action to perform. *
  85. * AircraftClass::What_Action -- Determines what action to perform. *
  86. * AircraftClass::operator delete -- Deletes the aircraft object. *
  87. * AircraftClass::operator new -- Allocates a new aircraft object from the pool *
  88. * AircraftClass::~AircraftClass -- Destructor for aircraft object. *
  89. * _Counts_As_Civ_Evac -- Is the specified object a candidate for civilian evac logic? *
  90. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  91. #include "function.h"
  92. /***********************************************************************************************
  93. * _Counts_As_Civ_Evac -- Is the specified object a candidate for civilian evac logic? *
  94. * *
  95. * Examines the specified object to see if it qualifies to be a civilian evacuation. This *
  96. * can only occur if it is a civilian (or Tanya) and the special evacuation flag has been *
  97. * set in the scenario control structure. *
  98. * *
  99. * INPUT: candidate -- Candidate object to examine for civilian evacuation legality. *
  100. * *
  101. * OUTPUT: bool; Is the specified object considered a civilian that must be auto-evacuated? *
  102. * *
  103. * WARNINGS: none *
  104. * *
  105. * HISTORY: *
  106. * 06/24/1996 JLB : Created. *
  107. *=============================================================================================*/
  108. static bool _Counts_As_Civ_Evac(ObjectClass const * candidate)
  109. {
  110. /*
  111. ** If the candidate pointer is missing, then return with failure code.
  112. */
  113. if (candidate == NULL) return(false);
  114. /*
  115. ** Only infantry objects can be considered for civilian evacuation action.
  116. */
  117. if (candidate->What_Am_I() != RTTI_INFANTRY) return(false);
  118. /*
  119. ** Working infantry object pointer.
  120. */
  121. InfantryClass const * inf = (InfantryClass const *)candidate;
  122. /*
  123. ** Certain infantry types will always be considered a civilian evacuation candidate. These
  124. ** include the special one-time infantry that appear in some missions.
  125. */
  126. if (*inf == INFANTRY_EINSTEIN || *inf == INFANTRY_GENERAL || *inf == INFANTRY_DELPHI || *inf == INFANTRY_CHAN) return(true);
  127. /*
  128. ** Consider Tanya to be part of the civilian evacuation logic if the scenario is
  129. ** specially flagged for this.
  130. */
  131. if (Scen.IsTanyaEvac && *inf == INFANTRY_TANYA) return(true);
  132. /*
  133. ** If the infantry is not a civilian, then it isn't allowed to be a civilian evacuation.
  134. */
  135. if (!inf->Class->IsCivilian) return(false);
  136. /*
  137. ** Technicians look like civilians, but are not considered a legal evacuation candidate.
  138. */
  139. if (inf->IsTechnician) return(false);
  140. /*
  141. ** All tests pass, so return the success of the infantry as a civilian evacuation candidate.
  142. */
  143. return(true);
  144. }
  145. /***********************************************************************************************
  146. * AircraftClass::operator new -- Allocates a new aircraft object from the pool *
  147. * *
  148. * This routine will allocate an aircraft object from the free aircraft object pool. If *
  149. * there are no free object available, then this routine will fail (return NULL). *
  150. * *
  151. * INPUT: none *
  152. * *
  153. * OUTPUT: Returns with a pointer to the allocate aircraft object or NULL if none were *
  154. * available. *
  155. * *
  156. * WARNINGS: none *
  157. * *
  158. * HISTORY: *
  159. * 07/26/1994 JLB : Created. *
  160. *=============================================================================================*/
  161. void * AircraftClass::operator new(size_t)
  162. {
  163. void * ptr = Aircraft.Allocate();
  164. if (ptr) {
  165. ((AircraftClass *)ptr)->Set_Active();
  166. }
  167. return(ptr);
  168. }
  169. /***********************************************************************************************
  170. * AircraftClass::operator delete -- Deletes the aircraft object. *
  171. * *
  172. * This routine will return the aircraft object back to the free aircraft object pool. *
  173. * *
  174. * INPUT: ptr -- Pointer to the aircraft object to delete. *
  175. * *
  176. * OUTPUT: none *
  177. * *
  178. * WARNINGS: none *
  179. * *
  180. * HISTORY: *
  181. * 07/26/1994 JLB : Created. *
  182. *=============================================================================================*/
  183. void AircraftClass::operator delete(void * ptr)
  184. {
  185. if (ptr) {
  186. ((AircraftClass *)ptr)->IsActive = false;
  187. }
  188. Aircraft.Free((AircraftClass *)ptr);
  189. }
  190. /***********************************************************************************************
  191. * AircraftClass::AircraftClass -- The constructor for aircraft objects. *
  192. * *
  193. * This routine is the constructor for aircraft objects. An aircraft object can be *
  194. * created and possibly placed into the game system by this routine. *
  195. * *
  196. * INPUT: classid -- The type of aircraft to create. *
  197. * *
  198. * house -- The owner of this aircraft. *
  199. * *
  200. * OUTPUT: none *
  201. * *
  202. * WARNINGS: none *
  203. * *
  204. * HISTORY: *
  205. * 07/26/1994 JLB : Created. *
  206. *=============================================================================================*/
  207. AircraftClass::AircraftClass(AircraftType classid, HousesType house) :
  208. FootClass(RTTI_AIRCRAFT, Aircraft.ID(this), house),
  209. Class(AircraftTypes.Ptr((int)classid)),
  210. SecondaryFacing(PrimaryFacing),
  211. Passenger(false),
  212. IsLanding(false),
  213. IsTakingOff(false),
  214. IsHovering(false),
  215. Jitter(0),
  216. SightTimer(0),
  217. AttacksRemaining(1)
  218. {
  219. /*
  220. ** For two shooters, clear out the second shot flag -- it will be set the first time
  221. ** the object fires. For non two shooters, set the flag since it will never be cleared
  222. ** and the second shot flag tells the system that normal rearm times apply -- this is
  223. ** what is desired for non two shooters.
  224. */
  225. IsSecondShot = !Class->Is_Two_Shooter();
  226. House->Tracking_Add(this);
  227. Ammo = Class->MaxAmmo;
  228. Height = FLIGHT_LEVEL;
  229. Strength = Class->MaxStrength;
  230. NavCom = TARGET_NONE;
  231. /*
  232. ** Keep count of the number of units created. Dont track cargo planes as they are created
  233. ** automatically, not bought.
  234. */
  235. // if (/*classid != AIRCRAFT_CARGO && */ Session.Type == GAME_INTERNET) {
  236. // House->AircraftTotals->Increment_Unit_Total((int)classid);
  237. // }
  238. }
  239. /***********************************************************************************************
  240. * AircraftClass::Unlimbo -- Removes an aircraft from the limbo state. *
  241. * *
  242. * This routine is used to transition the aircraft from the limbo to the non limbo state. *
  243. * It occurs when the aircraft is placed on the map for whatever reason. When it is *
  244. * unlimboed, only then will normal game processing recognize it. *
  245. * *
  246. * INPUT: coord -- The coordinate that the aircraft should appear at. *
  247. * *
  248. * dir -- The direction it should start facing. *
  249. * *
  250. * strength (optional) -- sets initial strength *
  251. * *
  252. * mission (optional) -- sets initial mission *
  253. * *
  254. * OUTPUT: bool; Was the aircraft unlimboed successfully? *
  255. * *
  256. * WARNINGS: none *
  257. * *
  258. * HISTORY: *
  259. * 07/26/1994 JLB : Created. *
  260. *=============================================================================================*/
  261. bool AircraftClass::Unlimbo(COORDINATE coord, DirType dir)
  262. {
  263. assert(Aircraft.ID(this) == ID);
  264. assert(IsActive);
  265. if (FootClass::Unlimbo(coord, dir)) {
  266. if (*this == AIRCRAFT_BADGER || (Class->PrimaryWeapon != NULL && Class->PrimaryWeapon->IsCamera)) {
  267. IsALoaner = true;
  268. }
  269. /*
  270. ** Ensure that the owning house knows about the
  271. ** new object.
  272. */
  273. House->AScan |= (1L << Class->Type);
  274. House->ActiveAScan |= (1L << Class->Type);
  275. /*
  276. ** Hack it so that aircraft that are both passenger and cargo carrying
  277. ** will carry passengers at the expense of ammo.
  278. */
  279. if (Is_Something_Attached()) {
  280. Ammo = 0;
  281. Passenger = true;
  282. }
  283. /*
  284. ** Forces the body of the helicopter to face the correct direction.
  285. */
  286. SecondaryFacing = dir;
  287. /*
  288. ** Start rotor animation.
  289. */
  290. if (!Class->IsFixedWing) {
  291. Set_Rate(1);
  292. Set_Stage(0);
  293. }
  294. /*
  295. ** When starting at flight level, then give it speed. When landed
  296. ** then it must be stationary.
  297. */
  298. if (Height == FLIGHT_LEVEL) {
  299. Set_Speed(0xFF);
  300. } else {
  301. Set_Speed(0);
  302. }
  303. return(true);
  304. }
  305. return(false);
  306. }
  307. /***********************************************************************************************
  308. * AircraftClass::Shape_Number -- Fetch the shape number to use for the aircraft. *
  309. * *
  310. * This will determine what shape number to use for the aircraft in its current state. *
  311. * The shape number can be used for drawing or determine shape rectangle size. *
  312. * *
  313. * INPUT: none *
  314. * *
  315. * OUTPUT: Returns with the shape number to use for the aircraft body. *
  316. * *
  317. * WARNINGS: Some aircraft, particularly helicopters, require other shapes attached to it. *
  318. * *
  319. * HISTORY: *
  320. * 07/26/1996 JLB : Created. *
  321. *=============================================================================================*/
  322. int AircraftClass::Shape_Number(void) const
  323. {
  324. int shapenum = 0;
  325. switch (Class->Rotation) {
  326. case 32:
  327. shapenum = UnitClass::BodyShape[Dir_To_32(SecondaryFacing)];
  328. break;
  329. case 16:
  330. shapenum = UnitClass::BodyShape[Dir_To_16(SecondaryFacing)*2]/2;
  331. break;
  332. case 8:
  333. shapenum = UnitClass::BodyShape[Dir_To_8(SecondaryFacing)*4]/4;
  334. break;
  335. default:
  336. break;
  337. }
  338. /*
  339. ** If there is a door on this aircraft (Chinook), then adjust the
  340. ** shape number to match the door open state.
  341. */
  342. if (!Is_Door_Closed()) {
  343. shapenum = Class->Rotation + Door_Stage();
  344. }
  345. return(shapenum);
  346. }
  347. /***********************************************************************************************
  348. * AircraftClass::Draw_It -- Renders an aircraft object at the location specified. *
  349. * *
  350. * This routine is used to display the aircraft object at the coordinates specified. *
  351. * The tactical map display uses this routine for all aircraft rendering. *
  352. * *
  353. * INPUT: x,y -- The coordinates to render the aircraft at. *
  354. * *
  355. * window -- The window that the coordinates are based upon. *
  356. * *
  357. * OUTPUT: none *
  358. * *
  359. * WARNINGS: none *
  360. * *
  361. * HISTORY: *
  362. * 07/26/1994 JLB : Created. *
  363. *=============================================================================================*/
  364. void AircraftClass::Draw_It(int x, int y, WindowNumberType window) const
  365. {
  366. assert(Aircraft.ID(this) == ID);
  367. assert(IsActive);
  368. /*
  369. ** Verify the legality of the unit class.
  370. */
  371. void const * shapefile = Get_Image_Data();
  372. if (!shapefile) return;
  373. int shapenum = Shape_Number();
  374. /*
  375. ** Certain aircraft use algorithmic rotation for some stages. Set the
  376. ** rotation value accordingly. A rotation of DIR_N means no rotation at all.
  377. */
  378. DirType rotation = DIR_N;
  379. if (Class->Rotation == 16) {
  380. rotation = DirType(Rotation16[SecondaryFacing]);
  381. }
  382. #ifdef TOFIX
  383. /*
  384. ** The orca attack helicopter uses a special shape set when it is travelling
  385. ** forward above a certain speed.
  386. */
  387. if (*this == AIRCRAFT_HIND && Get_Speed() >= MPH_MEDIUM_FAST) {
  388. shapenum += Class->Rotation;
  389. }
  390. #endif
  391. /*
  392. ** Helicopters that are flying have a "bobbing" effect.
  393. */
  394. int jitter = 0;
  395. if (Height == FLIGHT_LEVEL && Get_Speed() < 3) {
  396. static int _jitter[] = {0,0,0,0,1,1,1,0,0,0,0,0,-1,-1,-1,0};
  397. jitter = _jitter[::Frame % 16];
  398. }
  399. // Virtual window needs to draw the body first so it's considered the primary object and the shadow is a sub-object
  400. if (window == WINDOW_VIRTUAL) {
  401. /*
  402. ** Draw the root body of the unit.
  403. */
  404. Techno_Draw_Object(shapefile, shapenum, x, y+jitter, window, rotation);
  405. /*
  406. ** Special manual shadow draw code.
  407. */
  408. if (Visual_Character() <= VISUAL_DARKEN) {
  409. CC_Draw_Shape(this, shapefile, shapenum, x+1, y+2, window, SHAPE_PREDATOR|SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING, DisplayClass::FadingShade, NULL);
  410. }
  411. } else {
  412. /*
  413. ** Special manual shadow draw code.
  414. */
  415. if (Visual_Character() <= VISUAL_DARKEN) {
  416. CC_Draw_Shape(this, shapefile, shapenum, x+1, y+2, window, SHAPE_PREDATOR|SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING, DisplayClass::FadingShade, NULL);
  417. }
  418. /*
  419. ** Draw the root body of the unit.
  420. */
  421. Techno_Draw_Object(shapefile, shapenum, x, y+jitter, window, rotation);
  422. }
  423. /*
  424. ** If this aircraft is equipped with rotor blades, then draw them at this time.
  425. */
  426. if (Class->IsRotorEquipped) {
  427. Draw_Rotors(x, y+jitter, window);
  428. }
  429. /*
  430. ** This draws any overlay graphics on the aircraft.
  431. */
  432. FootClass::Draw_It(x, y-Lepton_To_Pixel(Height), window);
  433. }
  434. /***********************************************************************************************
  435. * AircraftClass::Draw_Rotors -- Draw rotor blades on the aircraft. *
  436. * *
  437. * This routine will draw rotor blades on the aircraft. It is presumed that the aircraft *
  438. * has already been drawn at the X and Y pixel coordinates specified. *
  439. * *
  440. * INPUT: x,y -- The X and Y pixel coordinates to draw the rotor blades. *
  441. * *
  442. * OUTPUT: none *
  443. * *
  444. * WARNINGS: none *
  445. * *
  446. * HISTORY: *
  447. * 07/26/1996 JLB : Created. *
  448. *=============================================================================================*/
  449. void AircraftClass::Draw_Rotors(int x, int y, WindowNumberType window) const
  450. {
  451. ShapeFlags_Type flags = SHAPE_CENTER|SHAPE_WIN_REL;
  452. int shapenum;
  453. /*
  454. ** The rotor shape number depends on whether the helicopter is idling
  455. ** or not. A landed helicopter uses slow moving "idling" blades.
  456. */
  457. if (Height == 0) {
  458. shapenum = (Fetch_Stage()%8)+4;
  459. flags = flags | SHAPE_GHOST;
  460. } else {
  461. shapenum = Fetch_Stage()%4;
  462. flags = flags | SHAPE_FADING|SHAPE_PREDATOR;
  463. }
  464. if (*this == AIRCRAFT_TRANSPORT) {
  465. int _stretch[FACING_COUNT] = {8, 9, 10, 9, 8, 9, 10, 9};
  466. /*
  467. ** Dual rotors offset along flight axis.
  468. */
  469. short xx = x;
  470. short yy = y-Lepton_To_Pixel(Height);
  471. FacingType face = Dir_Facing(SecondaryFacing);
  472. Move_Point(xx, yy, SecondaryFacing.Current(), _stretch[face]);
  473. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  474. CC_Draw_Shape(this, "RROTOR", AircraftTypeClass::RRotorData, shapenum, xx, yy-2, window, flags, NULL, DisplayClass::UnitShadow);
  475. Move_Point(xx, yy, SecondaryFacing.Current()+DIR_S, _stretch[face]*2);
  476. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  477. CC_Draw_Shape(this, "LROTOR", AircraftTypeClass::LRotorData, shapenum, xx, yy-2, window, flags, NULL, DisplayClass::UnitShadow);
  478. } else {
  479. /*
  480. ** Single rotor centered about shape.
  481. */
  482. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  483. CC_Draw_Shape(this, "RROTOR", AircraftTypeClass::RRotorData, shapenum, x, ((y-Lepton_To_Pixel(Height))-2), window, flags, NULL, DisplayClass::UnitShadow);
  484. }
  485. }
  486. /***********************************************************************************************
  487. * AircraftClass::Read_INI -- Reads aircraft object data from an INI file. *
  488. * *
  489. * This routine is used to read the aircraft object data from the INI file buffer *
  490. * specified. This is used by the scenario loader code to interpret the INI file and *
  491. * create the specified objects therein. *
  492. * *
  493. * INPUT: buffer -- Pointer to the INI buffer. *
  494. * *
  495. * OUTPUT: none *
  496. * *
  497. * WARNINGS: none *
  498. * *
  499. * HISTORY: *
  500. * 07/26/1994 JLB : Created. *
  501. *=============================================================================================*/
  502. void AircraftClass::Read_INI(CCINIClass & ini)
  503. {
  504. AircraftClass * air; // Working unit pointer.
  505. HousesType inhouse; // Unit house.
  506. AircraftType classid; // Unit class.
  507. char buf[128];
  508. int counter = ini.Entry_Count(INI_Name());
  509. for (int index = 0; index < counter; index++) {
  510. char const * entry = ini.Get_Entry(INI_Name(), index);
  511. ini.Get_String(INI_Name(), entry, NULL, buf, sizeof(buf)-1);
  512. inhouse = HouseTypeClass::From_Name(strtok(buf, ","));
  513. if (inhouse != HOUSE_NONE) {
  514. classid = AircraftTypeClass::From_Name(strtok(NULL, ","));
  515. if (classid != AIRCRAFT_NONE) {
  516. if (HouseClass::As_Pointer(inhouse) != NULL) {
  517. air = new AircraftClass(classid, inhouse);
  518. if (air) {
  519. COORDINATE coord;
  520. int strength;
  521. DirType dir;
  522. /*
  523. ** Read the raw data.
  524. */
  525. char * token = strtok(NULL, ",");
  526. if (token) {
  527. strength = atoi(token);
  528. } else {
  529. strength = 0;
  530. }
  531. token = strtok(NULL, ",");
  532. if (token) {
  533. coord = Cell_Coord((CELL)atoi(token));
  534. } else {
  535. coord = 0xFFFFFFFFL;
  536. }
  537. token = strtok(NULL, ",");
  538. if (token) {
  539. dir = (DirType)atoi(token);
  540. } else {
  541. dir = DIR_N;
  542. }
  543. if (!Map.In_Radar(Coord_Cell(coord))) {
  544. delete air;
  545. } else {
  546. air->Strength = (int)air->Class->MaxStrength * fixed(strength, 256); // Cast this to (int). ST - 5/8/19
  547. if (air->Unlimbo(coord, dir)) {
  548. air->Assign_Mission(AircraftClass::Mission_From_Name(strtok(NULL, ",\n\r")));
  549. } else {
  550. delete air;
  551. }
  552. }
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. /***********************************************************************************************
  560. * AircraftClass::Mission_Hunt -- Maintains hunt AI for the aircraft. *
  561. * *
  562. * Hunt AI consists of finding a target and attacking it. If there is no target assigned *
  563. * and this unit doesn't automatically hunt for more targets, then it will change *
  564. * mission to a more passive (land and await further orders) type. *
  565. * *
  566. * INPUT: none *
  567. * *
  568. * OUTPUT: Returns with the number of ticks before calling this routine again. *
  569. * *
  570. * WARNINGS: none *
  571. * *
  572. * HISTORY: *
  573. * 07/26/1994 JLB : Created. *
  574. *=============================================================================================*/
  575. int AircraftClass::Mission_Hunt(void)
  576. {
  577. assert(Aircraft.ID(this) == ID);
  578. assert(IsActive);
  579. if (Class->IsFixedWing) {
  580. if (TarCom != NavCom) {
  581. Assign_Destination(TarCom);
  582. }
  583. enum {
  584. LOOK_FOR_TARGET,
  585. TAKE_OFF,
  586. FLY_TO_TARGET,
  587. DROP_BOMBS,
  588. REGROUP
  589. };
  590. switch (Status) {
  591. /*
  592. ** Acquiring target stage.
  593. */
  594. case LOOK_FOR_TARGET:
  595. if (Target_Legal(TarCom)) {
  596. Status = TAKE_OFF;
  597. return(1);
  598. } else {
  599. if (!Team.Is_Valid()) {
  600. if (Session.Type != GAME_NORMAL) {
  601. Assign_Target(Greatest_Threat(THREAT_TIBERIUM));
  602. }
  603. if (!Target_Legal(TarCom)) {
  604. Assign_Target(Greatest_Threat(THREAT_NORMAL));
  605. }
  606. /*
  607. ** If there is no target, then this aircraft should just do its normal thing.
  608. */
  609. if (!Target_Legal(TarCom) && !Team.Is_Valid()) {
  610. Enter_Idle_Mode();
  611. }
  612. }
  613. }
  614. break;
  615. /*
  616. ** Make the aircraft take off from the airstrip.
  617. */
  618. case TAKE_OFF:
  619. /*
  620. ** If the aircraft is high enough to begin its mission, then do so.
  621. */
  622. if (Process_Take_Off()) {
  623. IsTakingOff = false;
  624. Set_Speed(0xFF);
  625. /*
  626. ** After takeoff is complete, break radio contact.
  627. */
  628. if (In_Radio_Contact()/*KO && Map[Coord].Cell_Building() == Contact_With_Whom()*/) {
  629. Transmit_Message(RADIO_OVER_OUT);
  630. }
  631. Status = FLY_TO_TARGET;
  632. }
  633. return(1);
  634. /*
  635. ** Homing in on target stage.
  636. */
  637. case FLY_TO_TARGET:
  638. switch (Can_Fire(TarCom, 0)) {
  639. case FIRE_FACING:
  640. /*
  641. ** Catch the case where it is tightly circling the target. In that
  642. ** case, increase the delay so that it has a chance to fly away and
  643. ** break the circle cycle.
  644. */
  645. if (In_Range(TarCom, 0) || Passenger) {
  646. return(TICKS_PER_SECOND * 2);
  647. }
  648. if (!PrimaryFacing.Is_Rotating() && Target_Legal(TarCom)) {
  649. PrimaryFacing.Set_Desired(Direction(TarCom));
  650. }
  651. break;
  652. case FIRE_AMMO:
  653. Status = REGROUP;
  654. break;
  655. case FIRE_CANT:
  656. case FIRE_ILLEGAL:
  657. if (Mission == MISSION_ATTACK) {
  658. Status = REGROUP;
  659. } else {
  660. Status = LOOK_FOR_TARGET;
  661. }
  662. break;
  663. case FIRE_OK:
  664. Status = DROP_BOMBS;
  665. return(1);
  666. default:
  667. if (!PrimaryFacing.Is_Rotating() && Target_Legal(TarCom)) {
  668. PrimaryFacing.Set_Desired(Direction(TarCom));
  669. }
  670. break;
  671. }
  672. return(TICKS_PER_SECOND/2);
  673. /*
  674. ** Dropping a stream of bombs phase.
  675. */
  676. case DROP_BOMBS:
  677. TARGET targ;
  678. switch (Can_Fire(TarCom, 0)) {
  679. case FIRE_OK:
  680. targ = ::As_Target(Coord_Move(Center_Coord(), SecondaryFacing, Weapon_Range(0)-0x0200));
  681. if (Class->PrimaryWeapon != NULL) {
  682. if (Class->PrimaryWeapon->IsCamera) {
  683. Status = REGROUP;
  684. } else {
  685. Map[::As_Cell(TarCom)].Incoming(Coord, true);
  686. }
  687. /*
  688. ** Force the target to be the actual target if this aircraft is
  689. ** equipped with homing projectile.
  690. */
  691. if (Class->PrimaryWeapon->Bullet != NULL && Class->PrimaryWeapon->Bullet->ROT > 0) {
  692. targ = TarCom;
  693. }
  694. }
  695. Fire_At(targ, 0);
  696. if (Class->Is_Two_Shooter()) {
  697. Fire_At(targ, 0);
  698. }
  699. return(Arm);
  700. case FIRE_RANGE:
  701. case FIRE_FACING:
  702. Status = FLY_TO_TARGET;
  703. return(TICKS_PER_SECOND*4);
  704. case FIRE_ILLEGAL:
  705. if (Mission == MISSION_ATTACK) {
  706. Status = REGROUP;
  707. } else {
  708. Status = LOOK_FOR_TARGET;
  709. }
  710. break;
  711. case FIRE_CANT:
  712. Status = REGROUP;
  713. break;
  714. case FIRE_AMMO:
  715. AttacksRemaining--;
  716. Status = REGROUP;
  717. break;
  718. default:
  719. break;
  720. }
  721. return(1);
  722. /*
  723. ** Pull away to regroup for possibly another attack or a retreat.
  724. */
  725. case REGROUP:
  726. if (Ammo == 0) {
  727. AttacksRemaining = 0;
  728. if (Team.Is_Valid()) Team->Remove(this);
  729. Enter_Idle_Mode();
  730. }
  731. if (Mission == MISSION_ATTACK || (Class->PrimaryWeapon != NULL && Class->PrimaryWeapon->IsCamera) || (!AttacksRemaining && !Is_Something_Attached())) {
  732. if (IsALoaner) {
  733. if (Team) Team->Remove(this);
  734. Assign_Mission(MISSION_RETREAT);
  735. Commence();
  736. } else {
  737. if (!Team.Is_Valid()) Enter_Idle_Mode();
  738. }
  739. Commence();
  740. } else {
  741. Status = LOOK_FOR_TARGET;
  742. }
  743. break;
  744. default:
  745. break;
  746. }
  747. } else {
  748. if (!Ammo) {
  749. if (Team) Team->Remove(this);
  750. Enter_Idle_Mode();
  751. } else {
  752. if (!Target_Legal(TarCom)) {
  753. if (Session.Type != GAME_NORMAL) {
  754. Assign_Target(Greatest_Threat(THREAT_TIBERIUM));
  755. }
  756. if (!Target_Legal(TarCom)) {
  757. Assign_Target(Greatest_Threat(THREAT_NORMAL));
  758. }
  759. if (!Target_Legal(TarCom)) {
  760. Enter_Idle_Mode();
  761. return(1);
  762. }
  763. }
  764. Assign_Mission(MISSION_ATTACK);
  765. return(1);
  766. }
  767. }
  768. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  769. }
  770. /***********************************************************************************************
  771. * AircraftClass::AI -- Processes the normal non-graphic AI for the aircraft. *
  772. * *
  773. * This handles the non-graphic AI processing for the aircraft. This usually entails *
  774. * maintenance and other AI functions. *
  775. * *
  776. * INPUT: none *
  777. * *
  778. * OUTPUT: none *
  779. * *
  780. * WARNINGS: none *
  781. * *
  782. * HISTORY: *
  783. * 07/26/1994 JLB : Created. *
  784. *=============================================================================================*/
  785. void AircraftClass::AI(void)
  786. {
  787. assert(Aircraft.ID(this) == ID);
  788. assert(IsActive);
  789. /*
  790. ** A Mission change can always occur if the aircraft is landed or flying.
  791. */
  792. if (!IsLanding && !IsTakingOff) {
  793. Commence();
  794. }
  795. /*
  796. ** Perform any base class AI processing. If during this process, the aircraft was
  797. ** destroyed, then detect this and bail from this AI routine early.
  798. */
  799. FootClass::AI();
  800. if (!IsActive) {
  801. return;
  802. }
  803. /*
  804. ** A Mission change can always occur if the aircraft is landed or flying.
  805. */
  806. if (!IsLanding && !IsTakingOff) {
  807. Commence();
  808. }
  809. /*
  810. ** Handle any body rotation at this time. Body rotation can occur even if the
  811. ** flying object is not actually moving.
  812. */
  813. Rotation_AI();
  814. /*
  815. ** Handle any aircraft movement at this time.
  816. */
  817. Movement_AI();
  818. /*
  819. ** Any aircraft that is not in the ground layer must be redrawn. This is a
  820. ** performance hit, but there is no other choice. The cells under an aircraft
  821. ** do not know if there is an aircraft above it. Thus, it cannot flag the
  822. ** aircraft to redraw. As a consequence, all aircraft must redraw.
  823. */
  824. if (In_Which_Layer() != LAYER_GROUND) {
  825. Mark();
  826. }
  827. /*
  828. ** Perform sighting every so often as controlled by the sight timer.
  829. */
  830. //if (IsOwnedByPlayer && Class->SightRange && SightTimer == 0) { // Changed to facilitate client/server multiplayer. ST - 8/2/2019 2:29PM
  831. if (House->IsHuman && Class->SightRange && SightTimer == 0) {
  832. Look();
  833. SightTimer = TICKS_PER_SECOND;
  834. }
  835. /*
  836. ** Handle landing and taking off logic. Helicopters are prime users of this technique. The
  837. ** aircraft will either gain or lose altitude as appropriate. As the aircraft transitions
  838. ** between flying level and ground level, it will be moved into the appropriate render
  839. ** layer.
  840. */
  841. if (Landing_Takeoff_AI()) {
  842. return;
  843. }
  844. /*
  845. ** Always flag the map draw process to occur if there is an aircraft in the view.
  846. ** This ensures that it will be rendered even if there is nothing else that flagged
  847. ** the map to be redrawn.
  848. */
  849. if (Map.In_View(Coord_Cell(Coord))) {
  850. Map.Flag_To_Redraw(false);
  851. Map.DisplayClass::IsToRedraw = true;
  852. }
  853. /*
  854. ** When aircraft leave the edge of the map, they might get destroyed. This occurs if the
  855. ** aircraft is a non-player produced unit and it has completed its mission. A transport
  856. ** helicopter that has already delivered reinforcements is a good example of this.
  857. */
  858. if (Edge_Of_World_AI()) {
  859. return;
  860. }
  861. }
  862. /***********************************************************************************************
  863. * AircraftClass::Overlap_List -- Returns with list of cells the aircraft overlaps. *
  864. * *
  865. * When aircraft are flying, they can overlap quite a number of cells. These cells can *
  866. * be determined from the coordinate where the aircraft is centered and the size of the *
  867. * aircraft's shape. Landed aircraft are a special case and are usually much smaller *
  868. * than when flying. *
  869. * *
  870. * INPUT: none *
  871. * *
  872. * OUTPUT: Returns with a pointer to a cell offset list that specifies all cells that *
  873. * the aircraft overlaps given the aircraft's current state. *
  874. * *
  875. * WARNINGS: none *
  876. * *
  877. * HISTORY: *
  878. * 07/26/1994 JLB : Created. *
  879. *=============================================================================================*/
  880. short const * AircraftClass::Overlap_List(bool redraw) const
  881. {
  882. assert(Aircraft.ID(this) == ID);
  883. assert(IsActive);
  884. static short const _list[] = {
  885. -(MAP_CELL_W-1), -MAP_CELL_W, -(MAP_CELL_W+1),
  886. -1, 0, 1,
  887. (MAP_CELL_W-1), MAP_CELL_W, (MAP_CELL_W+1),
  888. -((MAP_CELL_W*2)-1), -(MAP_CELL_W*2), -((MAP_CELL_W*2)+1),
  889. -((MAP_CELL_W*3)-1), -(MAP_CELL_W*3), -((MAP_CELL_W*3)+1),
  890. REFRESH_EOL
  891. };
  892. static short const _listbadger[] = {
  893. -(MAP_CELL_W-2), -(MAP_CELL_W-1), -MAP_CELL_W, -(MAP_CELL_W+1), -(MAP_CELL_W+2),
  894. -2, -1, 0, 1, 2,
  895. (MAP_CELL_W-2), (MAP_CELL_W-1), MAP_CELL_W, (MAP_CELL_W+1), (MAP_CELL_W+2),
  896. -((MAP_CELL_W*2)-2), -((MAP_CELL_W*2)-1), -(MAP_CELL_W*2), -((MAP_CELL_W*2)+1), -((MAP_CELL_W*2)+2),
  897. -((MAP_CELL_W*3)-2), -((MAP_CELL_W*3)-1), -(MAP_CELL_W*3), -((MAP_CELL_W*3)+1), -((MAP_CELL_W*3)+2),
  898. REFRESH_EOL
  899. };
  900. if (redraw || Height != 0) {
  901. #ifdef PARTIAL
  902. Rect rect;
  903. if (!IsSelected && Class->DimensionData != NULL && Class->IsFixedWing) {
  904. int shapenum = min(Shape_Number(), Get_Build_Frame_Count(Class->Get_Image_Data())-1);
  905. if (!Class->DimensionData[shapenum].Is_Valid()) {
  906. Class->DimensionData[shapenum] = Shape_Dimensions(Class->Get_Image_Data(), shapenum);
  907. }
  908. rect = Class->DimensionData[shapenum];
  909. /*
  910. ** Increase the rectangle for the aircraft since the aircraft could
  911. ** have its shape algorithmically rotated.
  912. */
  913. rect.X -= 5;
  914. rect.Y -= 5;
  915. rect.Width += 10;
  916. rect.Height += 10;
  917. Rect hrect = rect;
  918. hrect.Y -= Lepton_To_Pixel(Height);
  919. return(Coord_Spillage_List(Coord, Union(rect, hrect), true));
  920. }
  921. #endif
  922. if (*this == AIRCRAFT_BADGER) {
  923. return(_listbadger);
  924. } else {
  925. return(_list);
  926. }
  927. }
  928. return(Class->Overlap_List());
  929. }
  930. /***********************************************************************************************
  931. * AircraftClass::Init -- Initialize the aircraft system to an empty state. *
  932. * *
  933. * This routine is used to clear out the aircraft allocation system. It is called in *
  934. * preparation for a scenario load or save game load. *
  935. * *
  936. * INPUT: none *
  937. * *
  938. * OUTPUT: none *
  939. * *
  940. * WARNINGS: none *
  941. * *
  942. * HISTORY: *
  943. * 09/24/1994 JLB : Created. *
  944. *=============================================================================================*/
  945. void AircraftClass::Init(void)
  946. {
  947. Aircraft.Free_All();
  948. }
  949. /***********************************************************************************************
  950. * AircraftClass::Mission_Unload -- Handles unloading cargo. *
  951. * *
  952. * This function is used to handle finding, heading toward, landing, and unloading the *
  953. * cargo from the aircraft. Once unloading of cargo has occurred, then the aircraft follows *
  954. * a different mission. *
  955. * *
  956. * INPUT: none *
  957. * *
  958. * OUTPUT: Returns the number of game ticks to delay before calling this function again. *
  959. * *
  960. * WARNINGS: none *
  961. * *
  962. * HISTORY: *
  963. * 10/31/94 JLB : Created. *
  964. *=============================================================================================*/
  965. int AircraftClass::Mission_Unload(void)
  966. {
  967. assert(Aircraft.ID(this) == ID);
  968. assert(IsActive);
  969. if (Class->IsFixedWing) {
  970. Assign_Target(NavCom);
  971. return(Mission_Hunt());
  972. } else {
  973. enum {
  974. SEARCH_FOR_LZ,
  975. FLY_TO_LZ,
  976. LAND_ON_LZ,
  977. UNLOAD_PASSENGERS,
  978. TAKE_OFF
  979. };
  980. switch (Status) {
  981. /*
  982. ** Search for an appropriate destination spot if one isn't already assigned.
  983. */
  984. case SEARCH_FOR_LZ:
  985. if (Height == 0 && (Target_Legal(NavCom) || Coord == As_Coord(NavCom))) {
  986. Status = UNLOAD_PASSENGERS;
  987. } else {
  988. if (!Is_LZ_Clear(NavCom)) {
  989. FootClass * foot = Attached_Object();
  990. if (foot != NULL && foot->Team && foot->Team->Class->Origin != -1) {
  991. Assign_Destination(::As_Target(Scen.Waypoint[foot->Team->Class->Origin]));
  992. } else {
  993. Assign_Destination(New_LZ(::As_Target(Scen.Waypoint[WAYPT_REINF])));
  994. if (Team.Is_Valid()) {
  995. Team->Assign_Mission_Target(NavCom);
  996. }
  997. }
  998. } else {
  999. if (Height == FLIGHT_LEVEL) {
  1000. Status = FLY_TO_LZ;
  1001. } else {
  1002. Status = TAKE_OFF;
  1003. }
  1004. }
  1005. }
  1006. break;
  1007. /*
  1008. ** Fly to destination.
  1009. */
  1010. case FLY_TO_LZ:
  1011. if (Is_LZ_Clear(NavCom)) {
  1012. int distance = Process_Fly_To(true, NavCom);
  1013. if (distance < 0x0100) {
  1014. SecondaryFacing.Set_Desired(Pose_Dir());
  1015. if (distance < 0x0010) {
  1016. Status = LAND_ON_LZ;
  1017. }
  1018. return(1);
  1019. } else {
  1020. SecondaryFacing.Set_Desired(PrimaryFacing.Desired());
  1021. return(5);
  1022. }
  1023. } else {
  1024. Status = SEARCH_FOR_LZ;
  1025. }
  1026. break;
  1027. /*
  1028. ** Landing phase. Just delay until landing is complete. At that time,
  1029. ** transition to the unloading phase.
  1030. */
  1031. case LAND_ON_LZ:
  1032. if (IsTakingOff) {
  1033. Status = TAKE_OFF;
  1034. } else {
  1035. if (Process_Landing()) {
  1036. Status = UNLOAD_PASSENGERS;
  1037. }
  1038. }
  1039. return(1);
  1040. /*
  1041. ** Hold while unloading passengers. When passengers are unloaded the order for this
  1042. ** transport gets changed to MISSION_RETREAT.
  1043. */
  1044. case UNLOAD_PASSENGERS:
  1045. if (!IsTethered) {
  1046. if (Is_Something_Attached()) {
  1047. FootClass * unit = (FootClass *)Detach_Object();
  1048. /*
  1049. ** First thing is to lift the transport off of the map so that the unlimbo
  1050. ** process for the passengers is more likely to succeed.
  1051. */
  1052. Map.Pick_Up(Coord_Cell(Coord), this);
  1053. if (!Exit_Object(unit)) {
  1054. delete unit;
  1055. }
  1056. /*
  1057. ** Restore the transport back down on the map.
  1058. */
  1059. Map.Place_Down(Coord_Cell(Coord), this);
  1060. if (!Is_Something_Attached()) {
  1061. Enter_Idle_Mode();
  1062. }
  1063. } else {
  1064. Enter_Idle_Mode();
  1065. }
  1066. }
  1067. break;
  1068. /*
  1069. ** Aircraft is now taking off. Once the aircraft reaches flying altitude then it
  1070. ** will either take off or look for another landing spot to try again.
  1071. */
  1072. case TAKE_OFF: {
  1073. if (Process_Take_Off()) {
  1074. if (Is_Something_Attached()) {
  1075. Status = SEARCH_FOR_LZ;
  1076. /*
  1077. ** Break off radio contact with the helipad it is taking off from.
  1078. */
  1079. if (In_Radio_Contact() && Map[Coord].Cell_Building() == Contact_With_Whom()) {
  1080. Transmit_Message(RADIO_OVER_OUT);
  1081. }
  1082. } else {
  1083. Enter_Idle_Mode();
  1084. }
  1085. }
  1086. return(1);
  1087. }
  1088. default:
  1089. break;
  1090. }
  1091. }
  1092. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  1093. }
  1094. /***********************************************************************************************
  1095. * AircraftClass::Is_LZ_Clear -- Determines if landing zone is free for landing. *
  1096. * *
  1097. * This routine examines the landing zone (as specified by the target parameter) in order *
  1098. * to determine if it is free to be landed upon. Call this routine when it is necessary *
  1099. * to double check this. Typically this occurs right before a helicopter lands and also *
  1100. * when determining the landing zone in the first place. *
  1101. * *
  1102. * INPUT: target -- The target that is the "landing zone". *
  1103. * *
  1104. * OUTPUT: bool; Is the landing zone clear for landing? *
  1105. * *
  1106. * WARNINGS: none *
  1107. * *
  1108. * HISTORY: *
  1109. * 10/31/94 JLB : Created. *
  1110. *=============================================================================================*/
  1111. bool AircraftClass::Is_LZ_Clear(TARGET target) const
  1112. {
  1113. assert(Aircraft.ID(this) == ID);
  1114. assert(IsActive);
  1115. if (!Target_Legal(target)) return(false);
  1116. CELL cell = ::As_Cell(target);
  1117. if (!Map.In_Radar(cell)) return(false);
  1118. /*
  1119. ** If the requested landing location is occupied, then only consider that location
  1120. ** legal if the occupying object is in radio contact with the aircraft. This presumes that
  1121. ** the two objects know what they are doing.
  1122. */
  1123. ObjectClass * object = Map[cell].Cell_Object();
  1124. if (object) {
  1125. if (object == this) return(true);
  1126. if (In_Radio_Contact() && Contact_With_Whom() == object) {
  1127. return(true);
  1128. }
  1129. return(false);
  1130. }
  1131. if (!Map[cell].Is_Clear_To_Move(SPEED_TRACK, false, false)) return(false);
  1132. return(true);
  1133. }
  1134. /***********************************************************************************************
  1135. * AircraftClass::Sort_Y -- Figures the sorting coordinate. *
  1136. * *
  1137. * This routine is used to determine the coordinate to use for sorting the aircraft. This *
  1138. * sorting value is used when the aircraft is on the ground. At that time the aircraft *
  1139. * must be rendered in proper relationship to the other ground objects. *
  1140. * *
  1141. * INPUT: none *
  1142. * *
  1143. * OUTPUT: Returns with the coordinate to use when sorting the aircraft with other ground *
  1144. * objects. *
  1145. * *
  1146. * WARNINGS: none *
  1147. * *
  1148. * HISTORY: *
  1149. * 11/02/1994 JLB : Created. *
  1150. *=============================================================================================*/
  1151. COORDINATE AircraftClass::Sort_Y(void) const
  1152. {
  1153. assert(Aircraft.ID(this) == ID);
  1154. assert(IsActive);
  1155. return(Coord_Add(Coord, 0x00800000L));
  1156. }
  1157. /***********************************************************************************************
  1158. * AircraftClass::Mission_Retreat -- Handles the aircraft logic for leaving the battlefield. *
  1159. * *
  1160. * This mission will be followed when the aircraft decides that it is time to leave the *
  1161. * battle. Typically, this occurs when a loaner transport has dropped off its load or when *
  1162. * an attack air vehicle has expended its ordinance. *
  1163. * *
  1164. * INPUT: none *
  1165. * *
  1166. * OUTPUT: Returns with the number of game ticks to delay before calling this routine again. *
  1167. * *
  1168. * WARNINGS: none *
  1169. * *
  1170. * HISTORY: *
  1171. * 03/19/1995 JLB : Created. *
  1172. * 08/13/1995 JLB : Handles aircraft altitude gain after takeoff logic. *
  1173. *=============================================================================================*/
  1174. int AircraftClass::Mission_Retreat(void)
  1175. {
  1176. assert(Aircraft.ID(this) == ID);
  1177. assert(IsActive);
  1178. if (Class->IsFixedWing) {
  1179. if (Class->IsFixedWing && Height < FLIGHT_LEVEL) {
  1180. Height += 1;
  1181. return(3);
  1182. }
  1183. return(TICKS_PER_SECOND*10);
  1184. }
  1185. enum {
  1186. TAKE_OFF,
  1187. FACE_MAP_EDGE,
  1188. KEEP_FLYING
  1189. };
  1190. switch (Status) {
  1191. /*
  1192. ** Take off if landed.
  1193. */
  1194. case TAKE_OFF:
  1195. if (Process_Take_Off()) {
  1196. Status = FACE_MAP_EDGE;
  1197. }
  1198. return(1);
  1199. /*
  1200. ** Set facing and speed toward the friendly map edge.
  1201. */
  1202. case FACE_MAP_EDGE:
  1203. Set_Speed(0xFF);
  1204. /*
  1205. ** Take advantage of the fact that the source map edge enumerations happen to
  1206. ** occur in a clockwise order and are the first four enumerations of the map
  1207. ** edge default for the house. If this value is masked and then shifted, a
  1208. ** normalized direction value results. Use this value to head the aircraft
  1209. ** toward the "friendly" map edge.
  1210. */
  1211. PrimaryFacing.Set_Desired((DirType)((House->Control.Edge & 0x03) << 6));
  1212. SecondaryFacing.Set_Desired(PrimaryFacing.Desired());
  1213. Status = KEEP_FLYING;
  1214. break;
  1215. /*
  1216. ** Just do nothing since we are headed toward the map edge. When the edge is
  1217. ** reached, the aircraft should be automatically eliminated.
  1218. */
  1219. case KEEP_FLYING:
  1220. break;
  1221. default:
  1222. break;
  1223. }
  1224. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  1225. }
  1226. /***********************************************************************************************
  1227. * AircraftClass::Exit_Object -- Unloads passenger from aircraft. *
  1228. * *
  1229. * This routine is called when the aircraft is to unload a passenger. The passenger must *
  1230. * be able to move under its own power. Typical situation is when a transport helicopter *
  1231. * is to unload an infantry unit. *
  1232. * *
  1233. * INPUT: unit -- Pointer to the unit that is to be unloaded from this aircraft. *
  1234. * *
  1235. * OUTPUT: bool; Was the unit unloaded successfully? *
  1236. * *
  1237. * WARNINGS: The unload process is merely started by this routine. Radio contact is *
  1238. * established with the unloading unit and when the unit is clear of the aircraft *
  1239. * the radio contact will be broken and then the aircraft is free to pursue *
  1240. * other. *
  1241. * *
  1242. * HISTORY: *
  1243. * 01/10/1995 JLB : Created. *
  1244. *=============================================================================================*/
  1245. int AircraftClass::Exit_Object(TechnoClass * unit)
  1246. {
  1247. assert(Aircraft.ID(this) == ID);
  1248. assert(IsActive);
  1249. static FacingType _toface[FACING_COUNT] = {FACING_S, FACING_SW, FACING_SE, FACING_NW, FACING_NE, FACING_N, FACING_W, FACING_E};
  1250. CELL cell;
  1251. /*
  1252. ** Find a free cell to drop the unit off at.
  1253. */
  1254. FacingType face;
  1255. for (face = FACING_N; face < FACING_COUNT; face++) {
  1256. cell = Adjacent_Cell(Coord_Cell(Coord), _toface[face]);
  1257. if (unit->Can_Enter_Cell(cell) == MOVE_OK) break;
  1258. }
  1259. // Should perform a check here to see if no cell could be found.
  1260. /*
  1261. ** If the passenger can be placed on the map, then start it moving toward the
  1262. ** destination cell and establish radio contact with the transport. This is used
  1263. ** to make sure that the transport waits until the passenger is clear before
  1264. ** unloading the next passenger or taking off.
  1265. */
  1266. if (unit->Unlimbo(Coord, Facing_Dir(_toface[face]))) {
  1267. unit->Assign_Mission(MISSION_MOVE);
  1268. unit->Assign_Destination(::As_Target(cell));
  1269. if (Transmit_Message(RADIO_HELLO, unit) == RADIO_ROGER) {
  1270. Transmit_Message(RADIO_UNLOAD);
  1271. }
  1272. unit->Look(false);
  1273. return(true);
  1274. }
  1275. return(false);
  1276. }
  1277. /***********************************************************************************************
  1278. * AircraftClass::Paradrop_Cargo -- Drop a passenger by parachute. *
  1279. * *
  1280. * Call this routine when a passenger needs to be dropped off by parachute. One passenger *
  1281. * is offloaded by a call to this routine. *
  1282. * *
  1283. * INPUT: none *
  1284. * *
  1285. * OUTPUT: Returns with the delay time that it is safe to wait before processing any further *
  1286. * paradrop actions. *
  1287. * *
  1288. * WARNINGS: none *
  1289. * *
  1290. * HISTORY: *
  1291. * 07/26/1996 JLB : Created. *
  1292. *=============================================================================================*/
  1293. int AircraftClass::Paradrop_Cargo(void)
  1294. {
  1295. FootClass * passenger = Detach_Object();
  1296. if (passenger) {
  1297. if (!passenger->Paradrop(Center_Coord())) {
  1298. Attach(passenger);
  1299. } else {
  1300. /*
  1301. ** Play a sound effect of the parachute opening.
  1302. */
  1303. Sound_Effect(VOC_CHUTE1, Coord);
  1304. if (Team.Is_Valid()) {
  1305. Team->Remove(passenger);
  1306. if (passenger->House->IsHuman) {
  1307. Assign_Mission(MISSION_GUARD);
  1308. } else {
  1309. Assign_Mission(MISSION_HUNT);
  1310. }
  1311. }
  1312. // Arm = Rearm_Delay(IsSecondShot);
  1313. Arm = 0;
  1314. }
  1315. }
  1316. return(Arm);
  1317. }
  1318. /***********************************************************************************************
  1319. * AircraftClass::Fire_At -- Handles firing a projectile from an aircraft. *
  1320. * *
  1321. * Sometimes, aircraft firing needs special handling. Example: for napalm bombs, the *
  1322. * bomb travels forward at nearly the speed of the delivery aircraft, not necessarily the *
  1323. * default speed defined in the BulletTypeClass structure. *
  1324. * *
  1325. * INPUT: target -- The target that the projectile is heading for. *
  1326. * *
  1327. * which -- Which weapon to use in the attack. 0=primary, 1=secondary. *
  1328. * *
  1329. * OUTPUT: Returns with a pointer to the bullet that was created as a result of this attack. *
  1330. * *
  1331. * WARNINGS: none *
  1332. * *
  1333. * HISTORY: *
  1334. * 03/19/1995 JLB : Created. *
  1335. *=============================================================================================*/
  1336. BulletClass * AircraftClass::Fire_At(TARGET target, int which)
  1337. {
  1338. assert(Aircraft.ID(this) == ID);
  1339. assert(IsActive);
  1340. /*
  1341. ** Passenger aircraft will actually paradrop their cargo instead of
  1342. ** firing their weapon.
  1343. */
  1344. if (Is_Something_Attached()) {
  1345. Paradrop_Cargo();
  1346. return(0);
  1347. }
  1348. /*
  1349. ** If the weapon is actually a camera, then perform the "snapshot" of the
  1350. ** ground instead of normal weapon fire.
  1351. */
  1352. if (Class->PrimaryWeapon != NULL && Class->PrimaryWeapon->IsCamera) {
  1353. if (Session.Type != GAME_GLYPHX_MULTIPLAYER) {
  1354. if (House->Is_Ally(PlayerPtr)) {
  1355. Map.Sight_From(Coord_Cell(Center_Coord()), 9, House, false);
  1356. }
  1357. } else {
  1358. for (int i = 0; i < Session.Players.Count(); i++) {
  1359. HousesType house_type = Session.Players[i]->Player.ID;
  1360. HouseClass *house = HouseClass::As_Pointer(house_type);
  1361. if (house == House || House->Is_Ally(house)) {
  1362. Map.Sight_From(Coord_Cell(Center_Coord()), 9, house, false);
  1363. }
  1364. }
  1365. }
  1366. Ammo = 0;
  1367. Arm = Rearm_Delay(IsSecondShot);
  1368. return(0);
  1369. }
  1370. BulletClass * bullet = FootClass::Fire_At(target, which);
  1371. if (bullet) {
  1372. /*
  1373. ** Aircraft reveal when firing
  1374. */
  1375. HouseClass *player = HouseClass::As_Pointer(Owner());
  1376. if (player != nullptr && player->IsHuman) {
  1377. Map.Sight_From(Coord_Cell(Center_Coord()), 1, player, false);
  1378. }
  1379. /*
  1380. ** Falling bullets move at a speed proportionate to the delivery craft.
  1381. */
  1382. if (bullet->Class->IsDropping) {
  1383. bullet->Fly_Speed(40, MPH_MEDIUM_SLOW); // TCTC To fix.
  1384. }
  1385. }
  1386. return(bullet);
  1387. }
  1388. /***********************************************************************************************
  1389. * AircraftClass::Take_Damage -- Applies damage to the aircraft. *
  1390. * *
  1391. * This routine is used to apply damage to the specified aircraft. This is where any *
  1392. * special crash animation will be initiated. *
  1393. * *
  1394. * INPUT: damage -- Reference to the damage that will be applied to the aircraft. *
  1395. * This value will be filled in with the actual damage that was *
  1396. * applied. *
  1397. * *
  1398. * distance -- Distance from the source of the explosion to this aircraft. *
  1399. * *
  1400. * warhead -- The warhead type that the damage occurs from. *
  1401. * *
  1402. * source -- Pointer to the originator of the damage. This can be used so that *
  1403. * proper "thank you" can be delivered. *
  1404. * *
  1405. * OUTPUT: Returns with the result of the damage as it affects this aircraft. *
  1406. * *
  1407. * WARNINGS: none *
  1408. * *
  1409. * HISTORY: *
  1410. * 05/26/1995 JLB : Created. *
  1411. *=============================================================================================*/
  1412. ResultType AircraftClass::Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source, bool forced)
  1413. {
  1414. assert(Aircraft.ID(this) == ID);
  1415. assert(IsActive);
  1416. ResultType res = RESULT_NONE;
  1417. /*
  1418. ** Flying aircraft take half damage.
  1419. */
  1420. if (Height) {
  1421. damage /= 2;
  1422. }
  1423. /*
  1424. ** Apply the damage to the aircraft.
  1425. */
  1426. res = FootClass::Take_Damage(damage, distance, warhead, source, forced);
  1427. /*
  1428. ** Special action is performed if the aircraft is killed -- the cargo is destroyed
  1429. ** as well.
  1430. */
  1431. switch (res) {
  1432. case RESULT_DESTROYED:
  1433. {
  1434. Kill_Cargo(source);
  1435. Death_Announcement();
  1436. COORDINATE coord = Target_Coord();
  1437. if (!(coord & HIGH_COORD_MASK)) {
  1438. new AnimClass(ANIM_FBALL1, coord);
  1439. }
  1440. /*
  1441. ** Parachute a survivor if possible.
  1442. */
  1443. if (Class->IsCrew && Percent_Chance(90) && Map[Center_Coord()].Is_Clear_To_Move(SPEED_FOOT, true, false)) {
  1444. InfantryClass * infantry = new InfantryClass(INFANTRY_E1, House->Class->House);
  1445. if (infantry != NULL) {
  1446. if (!infantry->Paradrop(Center_Coord())) {
  1447. delete infantry;
  1448. }
  1449. }
  1450. }
  1451. delete this;
  1452. }
  1453. break;
  1454. default:
  1455. case RESULT_HALF:
  1456. break;
  1457. }
  1458. return(res);
  1459. }
  1460. /***********************************************************************************************
  1461. * AircraftClass::Mission_Move -- Handles movement mission. *
  1462. * *
  1463. * This state machine routine is used when an aircraft (usually helicopter) is to move *
  1464. * from one location to another. It will handle any necessary take off and landing this *
  1465. * may require. *
  1466. * *
  1467. * INPUT: none *
  1468. * *
  1469. * OUTPUT: Returns with the number of game frames that should elapse before this routine *
  1470. * is called again. *
  1471. * *
  1472. * WARNINGS: none *
  1473. * *
  1474. * HISTORY: *
  1475. * 06/19/1995 JLB : Created. *
  1476. *=============================================================================================*/
  1477. int AircraftClass::Mission_Move(void)
  1478. {
  1479. assert(Aircraft.ID(this) == ID);
  1480. assert(IsActive);
  1481. if (Class->IsFixedWing) {
  1482. enum {
  1483. TAKE_OFF,
  1484. FLY_TOWARD_TARGET
  1485. };
  1486. switch (Status) {
  1487. int distance;
  1488. case TAKE_OFF:
  1489. /*
  1490. ** If the aircraft is high enough to begin its mission, then do so.
  1491. */
  1492. if (Process_Take_Off()) {
  1493. IsTakingOff = false;
  1494. Set_Speed(0xFF);
  1495. /*
  1496. ** After takeoff is complete, break radio contact.
  1497. */
  1498. if (In_Radio_Contact() && Map[Coord].Cell_Building() == Contact_With_Whom()) {
  1499. Transmit_Message(RADIO_OVER_OUT);
  1500. }
  1501. Status = FLY_TOWARD_TARGET;
  1502. }
  1503. return(1);
  1504. case FLY_TOWARD_TARGET:
  1505. PrimaryFacing.Set_Desired(Direction(NavCom));
  1506. distance = Distance(NavCom);
  1507. if (distance < 0x00C0) {
  1508. MissionType mission = MISSION_GUARD;
  1509. if (!IsALoaner) {
  1510. /*
  1511. ** Normal aircraft try to find a good landing spot to rest.
  1512. */
  1513. BuildingClass * building = Find_Docking_Bay(Class->Building, false);
  1514. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  1515. if (!Class->IsFixedWing) {
  1516. int dist = 0x7FFFFFFF;
  1517. if (building) dist=Distance(building);
  1518. for (int index = 0; index < Vessels.Count(); index++) {
  1519. VesselClass *ship = Vessels.Ptr(index);
  1520. if (ship != NULL && *ship == VESSEL_CARRIER && !ship->IsInLimbo && ship->IsActive && ship->House == House && ship->How_Many() < ship->Class->Max_Passengers() ) {
  1521. if (Distance(ship) < dist || !building) {
  1522. building = (BuildingClass *)ship;
  1523. dist = Distance(ship);
  1524. }
  1525. // break;
  1526. }
  1527. }
  1528. }
  1529. #endif
  1530. Assign_Destination(TARGET_NONE);
  1531. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  1532. if (building && (Transmit_Message(RADIO_HELLO, building) == RADIO_ROGER || building->What_Am_I() == RTTI_VESSEL) ) {
  1533. #else
  1534. if (building && Transmit_Message(RADIO_HELLO, building) == RADIO_ROGER) {
  1535. #endif
  1536. mission = MISSION_ENTER;
  1537. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  1538. if (building->What_Am_I() == RTTI_VESSEL) {
  1539. Assign_Destination(building->As_Target());
  1540. }
  1541. #endif
  1542. } else {
  1543. Assign_Destination(Good_LZ());
  1544. /*
  1545. ** If this aircraft has nowhere else to go, meaning that
  1546. ** there is no airfield available, then it has to crash.
  1547. */
  1548. if (Is_Target_Cell(NavCom)) {
  1549. if (Process_Landing()) {
  1550. Strength = 1;
  1551. int damage = Strength;
  1552. Take_Damage(damage, 0, WARHEAD_AP, 0, true);
  1553. return(1);
  1554. }
  1555. return(500);
  1556. }
  1557. mission = MISSION_MOVE;
  1558. }
  1559. Assign_Mission(mission);
  1560. Commence();
  1561. } else {
  1562. if (!Team.Is_Valid()) {
  1563. Enter_Idle_Mode();
  1564. }
  1565. }
  1566. return(1);
  1567. }
  1568. break;
  1569. default:
  1570. break;
  1571. }
  1572. return(5);
  1573. }
  1574. enum {
  1575. VALIDATE_LZ,
  1576. TAKE_OFF,
  1577. FLY_TO_LZ,
  1578. LAND
  1579. };
  1580. switch (Status) {
  1581. /*
  1582. ** Double check and change LZ if necessary.
  1583. */
  1584. case VALIDATE_LZ:
  1585. if (!Target_Legal(NavCom)) {
  1586. Enter_Idle_Mode();
  1587. } else {
  1588. if (!Is_LZ_Clear(NavCom) || !Cell_Seems_Ok(As_Cell(NavCom))) {
  1589. Assign_Destination(New_LZ(NavCom));
  1590. if (Team.Is_Valid()) {
  1591. Team->Assign_Mission_Target(NavCom);
  1592. }
  1593. } else {
  1594. Status = TAKE_OFF;
  1595. }
  1596. }
  1597. break;
  1598. /*
  1599. ** Take off if necessary.
  1600. */
  1601. case TAKE_OFF:
  1602. if (!Target_Legal(NavCom)) {
  1603. Status = VALIDATE_LZ;
  1604. } else {
  1605. if (Process_Take_Off()) {
  1606. /*
  1607. ** After takeoff is complete, break radio contact with any helipad that this
  1608. ** helicopter is taking off from.
  1609. */
  1610. if (In_Radio_Contact() && Map[Coord].Cell_Building() == Contact_With_Whom()) {
  1611. Transmit_Message(RADIO_OVER_OUT);
  1612. }
  1613. Status = FLY_TO_LZ;
  1614. }
  1615. return(1);
  1616. }
  1617. break;
  1618. /*
  1619. ** Fly toward target.
  1620. */
  1621. case FLY_TO_LZ:
  1622. if (Is_LZ_Clear(NavCom)) {
  1623. int distance = Process_Fly_To(true, NavCom);
  1624. if (distance < 0x0080) {
  1625. if (Target_Legal(TarCom)) {
  1626. SecondaryFacing.Set_Desired(Direction(TarCom));
  1627. } else {
  1628. SecondaryFacing.Set_Desired(Pose_Dir());
  1629. }
  1630. if (distance < 0x0010) {
  1631. Status = LAND;
  1632. }
  1633. return(1);
  1634. }
  1635. // SecondaryFacing.Set_Desired(::Direction(Fire_Coord(0), As_Coord(NavCom)));
  1636. SecondaryFacing.Set_Desired(Direction(NavCom));
  1637. } else {
  1638. Assign_Destination(New_LZ(NavCom));
  1639. if (Team.Is_Valid()) {
  1640. Team->Assign_Mission_Target(NavCom);
  1641. }
  1642. if (!Target_Legal(NavCom)) {
  1643. Status = LAND;
  1644. }
  1645. }
  1646. return(1);
  1647. /*
  1648. ** Land on target.
  1649. */
  1650. case LAND:
  1651. if (IsTakingOff) {
  1652. Assign_Destination(New_LZ(NavCom));
  1653. if (Team.Is_Valid()) {
  1654. Team->Assign_Mission_Target(NavCom);
  1655. }
  1656. Status = TAKE_OFF;
  1657. }
  1658. if (Process_Landing()) {
  1659. if (MissionQueue == MISSION_NONE) {
  1660. Enter_Idle_Mode();
  1661. }
  1662. }
  1663. return(1);
  1664. default:
  1665. break;
  1666. }
  1667. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  1668. }
  1669. /***********************************************************************************************
  1670. * AircraftClass::Enter_Idle_Mode -- Gives the aircraft an appropriate mission. *
  1671. * *
  1672. * Use this routine when the mission for the aircraft is in doubt. This routine will find *
  1673. * an appropriate mission for the aircraft and dispatch it. *
  1674. * *
  1675. * INPUT: initial -- Is this called when the unit just leaves a factory or is initially *
  1676. * or is initially placed on the map? *
  1677. * *
  1678. * OUTPUT: none *
  1679. * *
  1680. * WARNINGS: none *
  1681. * *
  1682. * HISTORY: *
  1683. * 06/05/1995 JLB : Created. *
  1684. *=============================================================================================*/
  1685. void AircraftClass::Enter_Idle_Mode(bool )
  1686. {
  1687. assert(Aircraft.ID(this) == ID);
  1688. assert(IsActive);
  1689. MissionType mission = (Class->IsFixedWing && IsALoaner && Class->PrimaryWeapon != NULL) ? MISSION_HUNT : MISSION_GUARD;
  1690. if (Class->IsFixedWing) {
  1691. if (In_Which_Layer() == LAYER_GROUND) {
  1692. if (IsALoaner) {
  1693. mission = MISSION_RETREAT;
  1694. } else {
  1695. Assign_Destination(TARGET_NONE);
  1696. Assign_Target(TARGET_NONE);
  1697. mission = MISSION_GUARD;
  1698. }
  1699. } else {
  1700. /*
  1701. ** If this transport is a loaner and part of a team, then remove it from
  1702. ** the team it is attached to.
  1703. */
  1704. if ((IsALoaner && House->IsHuman) || (!House->IsHuman && !Ammo)) {
  1705. if (Team.Is_Valid() && Team->Has_Entered_Map()) {
  1706. Team->Remove(this);
  1707. }
  1708. }
  1709. if (Team.Is_Valid()) return;
  1710. /*
  1711. ** Weapon equipped helicopters that run out of ammo and were
  1712. ** brought in as reinforcements will leave the map.
  1713. */
  1714. if (Mission != MISSION_ATTACK && IsALoaner && Ammo == 0 && Class->PrimaryWeapon != NULL) {
  1715. mission = MISSION_HUNT;
  1716. } else {
  1717. if (!IsALoaner) {
  1718. /*
  1719. ** Normal aircraft try to find a good landing spot to rest.
  1720. */
  1721. BuildingClass * building = NULL;
  1722. if (In_Radio_Contact() && Contact_With_Whom()->What_Am_I() == RTTI_BUILDING) {
  1723. building = (BuildingClass *)Contact_With_Whom();
  1724. } else {
  1725. building = Find_Docking_Bay(Class->Building, false);
  1726. if (Transmit_Message(RADIO_HELLO, building) != RADIO_ROGER) {
  1727. building = NULL;
  1728. }
  1729. }
  1730. Assign_Destination(TARGET_NONE);
  1731. if (building != NULL) {
  1732. if (Class->IsFixedWing) {
  1733. Status = 0; //BG - reset the mission status to avoid landing on the ground next to the airstrip
  1734. if (IsLanding) {
  1735. Process_Take_Off();
  1736. }
  1737. }
  1738. mission = MISSION_ENTER;
  1739. } else {
  1740. mission = MISSION_RETREAT;
  1741. }
  1742. }
  1743. }
  1744. }
  1745. } else {
  1746. if (In_Which_Layer() == LAYER_GROUND) {
  1747. if (IsALoaner) {
  1748. if (Is_Something_Attached()) {
  1749. /*
  1750. ** In the case of a computer controlled helicopter that hold passengers,
  1751. ** don't unload when landing. Wait for specific instructions from the
  1752. ** controlling team.
  1753. */
  1754. if (Team.Is_Valid()) {
  1755. // if (Team.Is_Valid() && !House->IsHuman) {
  1756. mission = MISSION_GUARD;
  1757. } else {
  1758. mission = MISSION_UNLOAD;
  1759. }
  1760. } else {
  1761. mission = MISSION_RETREAT;
  1762. }
  1763. } else {
  1764. Assign_Destination(TARGET_NONE);
  1765. Assign_Target(TARGET_NONE);
  1766. mission = MISSION_GUARD;
  1767. }
  1768. } else {
  1769. if (Is_Something_Attached()) {
  1770. if (IsALoaner) {
  1771. if (Team) {
  1772. mission = MISSION_GUARD;
  1773. } else {
  1774. mission = MISSION_UNLOAD;
  1775. Assign_Destination(Good_LZ());
  1776. }
  1777. } else {
  1778. Assign_Destination(Good_LZ());
  1779. mission = MISSION_MOVE;
  1780. }
  1781. } else {
  1782. /*
  1783. ** If this transport is a loaner and part of a team, then remove it from
  1784. ** the team it is attached to.
  1785. */
  1786. if ((IsALoaner && House->IsHuman) || (!House->IsHuman && !Ammo)) {
  1787. if (Team.Is_Valid() && Team->Has_Entered_Map()) {
  1788. Team->Remove(this);
  1789. }
  1790. }
  1791. if (Class->PrimaryWeapon != NULL) {
  1792. /*
  1793. ** Weapon equipped helicopters that run out of ammo and were
  1794. ** brought in as reinforcements will leave the map.
  1795. */
  1796. if (IsALoaner) {
  1797. /*
  1798. ** If it has no ammo, then break off of the team and leave the map.
  1799. ** If it can fight, then give it fighting orders.
  1800. */
  1801. if (Ammo == 0) {
  1802. if (Team.Is_Valid()) Team->Remove(this);
  1803. mission = MISSION_RETREAT;
  1804. } else {
  1805. if (!Team.Is_Valid()) {
  1806. mission = MISSION_HUNT;
  1807. }
  1808. }
  1809. } else {
  1810. /*
  1811. ** Normal aircraft try to find a good landing spot to rest.
  1812. */
  1813. BuildingClass * building = Find_Docking_Bay(Class->Building, false);
  1814. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  1815. if (!Class->IsFixedWing) {
  1816. int dist = 0x7FFFFFFF;
  1817. if (building) dist=Distance(building);
  1818. for (int index = 0; index < Vessels.Count(); index++) {
  1819. VesselClass *ship = Vessels.Ptr(index);
  1820. if (ship != NULL && *ship == VESSEL_CARRIER && !ship->IsInLimbo && ship->IsActive && ship->House == House && ship->How_Many() < ship->Class->Max_Passengers()/* && !ship->In_Radio_Contact()*/) {
  1821. if (Distance(ship) < dist || !building) {
  1822. building = (BuildingClass *)ship;
  1823. dist = Distance(ship);
  1824. }
  1825. // break;
  1826. }
  1827. }
  1828. }
  1829. #endif
  1830. Assign_Destination(TARGET_NONE);
  1831. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  1832. if (building && (Transmit_Message(RADIO_HELLO, building) == RADIO_ROGER || building->What_Am_I() == RTTI_VESSEL) ) {
  1833. #else
  1834. if (building && Transmit_Message(RADIO_HELLO, building) == RADIO_ROGER) {
  1835. #endif
  1836. mission = MISSION_ENTER;
  1837. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  1838. if (building->What_Am_I() == RTTI_VESSEL) {
  1839. Assign_Destination(building->As_Target());
  1840. }
  1841. #endif
  1842. } else {
  1843. Assign_Destination(Good_LZ());
  1844. mission = MISSION_MOVE;
  1845. }
  1846. }
  1847. } else {
  1848. if (Team) return;
  1849. Assign_Destination(Good_LZ());
  1850. mission = MISSION_MOVE;
  1851. }
  1852. }
  1853. }
  1854. }
  1855. Assign_Mission(mission);
  1856. Commence();
  1857. }
  1858. /***********************************************************************************************
  1859. * AircraftClass::Process_Fly_To -- Handles state machine for flying to destination. *
  1860. * *
  1861. * This support routine is used when the helicopter is to fly to the destination. It can *
  1862. * optionally slow the helicopter down as it approaches the destination. *
  1863. * *
  1864. * INPUT: slowdown -- Should the aircraft be slowed down when it approaches the dest? *
  1865. * *
  1866. * OUTPUT: Returns with the distance remaining between the aircraft and the destination. *
  1867. * *
  1868. * WARNINGS: Because the aircraft can move at a fast speed, the distance to target value *
  1869. * will probably never be zero. The likely case will be that the aircraft *
  1870. * overshoots the target. *
  1871. * *
  1872. * HISTORY: *
  1873. * 06/14/1995 JLB : Created. *
  1874. * 03/05/1996 JLB : Specifies destination target value. *
  1875. *=============================================================================================*/
  1876. int AircraftClass::Process_Fly_To(bool slowdown, TARGET dest)
  1877. {
  1878. assert(Aircraft.ID(this) == ID);
  1879. assert(IsActive);
  1880. if (Class->IsFixedWing) slowdown = false;
  1881. COORDINATE coord;
  1882. if (Is_Target_Building(dest)) {
  1883. coord = As_Building(dest)->Docking_Coord();
  1884. } else {
  1885. coord = As_Coord(dest);
  1886. }
  1887. int distance = Distance(coord);
  1888. PrimaryFacing.Set_Desired(Direction(coord));
  1889. if (slowdown) {
  1890. int speed = min(distance, 0x0300);
  1891. speed = Bound(speed/3, 0x0020, 0x00FF);
  1892. if (Speed != speed) {
  1893. Set_Speed(speed);
  1894. }
  1895. }
  1896. if (distance < 0x0010) {
  1897. if (slowdown) {
  1898. Set_Speed(0);
  1899. }
  1900. distance = 0;
  1901. }
  1902. return(distance);
  1903. }
  1904. #ifdef CHEAT_KEYS
  1905. /***********************************************************************************************
  1906. * AircraftClass::Debug_Dump -- Displays the status of the aircraft to the mono monitor. *
  1907. * *
  1908. * This displays the current status of the aircraft class to the mono monitor. By this *
  1909. * display bugs may be tracked down or prevented. *
  1910. * *
  1911. * INPUT: none *
  1912. * *
  1913. * OUTPUT: none *
  1914. * *
  1915. * WARNINGS: none *
  1916. * *
  1917. * HISTORY: *
  1918. * 06/02/1994 JLB : Created. *
  1919. *=============================================================================================*/
  1920. void AircraftClass::Debug_Dump(MonoClass * mono) const
  1921. {
  1922. assert(Aircraft.ID(this) == ID);
  1923. assert(IsActive);
  1924. mono->Set_Cursor(0, 0);
  1925. mono->Print(Text_String(TXT_DEBUG_AIRCRAFT));
  1926. mono->Set_Cursor(1, 11);mono->Printf("%3d", AttacksRemaining);
  1927. FootClass::Debug_Dump(mono);
  1928. }
  1929. #endif
  1930. /***********************************************************************************************
  1931. * AircraftClass::Active_Click_With -- Handles clicking over specified object. *
  1932. * *
  1933. * This routine is used when the player clicks over the speicifed object. It will assign *
  1934. * the appropriate mission to the aircraft. *
  1935. * *
  1936. * INPUT: action -- The action that was nominally determined by the What_Action function. *
  1937. * *
  1938. * object -- The object over which the mouse was clicked. *
  1939. * *
  1940. * OUTPUT: none *
  1941. * *
  1942. * WARNINGS: This routine will alter the game sequence and causes an event packet to be *
  1943. * propagated to all connected machines. *
  1944. * *
  1945. * HISTORY: *
  1946. * 06/19/1995 JLB : Created. *
  1947. *=============================================================================================*/
  1948. void AircraftClass::Active_Click_With(ActionType action, ObjectClass * object)
  1949. {
  1950. assert(Aircraft.ID(this) == ID);
  1951. assert(IsActive);
  1952. action = What_Action(object);
  1953. switch (action) {
  1954. case ACTION_NOMOVE:
  1955. return;
  1956. case ACTION_ENTER:
  1957. Player_Assign_Mission(MISSION_ENTER, TARGET_NONE, object->As_Target());
  1958. break;
  1959. case ACTION_SELF:
  1960. Player_Assign_Mission(MISSION_UNLOAD, TARGET_NONE, TARGET_NONE);
  1961. break;
  1962. default:
  1963. break;
  1964. }
  1965. FootClass::Active_Click_With(action, object);
  1966. }
  1967. /***********************************************************************************************
  1968. * AircraftClass::Active_Click_With -- Handles clicking over specified cell. *
  1969. * *
  1970. * This routine is used when the player clicks the mouse of the specified cell. It will *
  1971. * assign the appropriate mission to the aircraft. *
  1972. * *
  1973. * INPUT: action -- The action nominally determined by What_Action(). *
  1974. * *
  1975. * cell -- The cell over which the mouse was clicked. *
  1976. * *
  1977. * OUTPUT: none *
  1978. * *
  1979. * WARNINGS: This routine will affect the game sequence and causes an event object to be *
  1980. * propagated to all connected machines. *
  1981. * *
  1982. * HISTORY: *
  1983. * 06/19/1995 JLB : Created. *
  1984. *=============================================================================================*/
  1985. void AircraftClass::Active_Click_With(ActionType action, CELL cell)
  1986. {
  1987. assert(Aircraft.ID(this) == ID);
  1988. assert(IsActive);
  1989. FootClass::Active_Click_With(action, cell);
  1990. }
  1991. /***********************************************************************************************
  1992. * AircraftClass::Player_Assign_Mission -- Handles player input to assign a mission. *
  1993. * *
  1994. * This routine is called as a result of player input with the intent to change the *
  1995. * mission of the aircraft. *
  1996. * *
  1997. * INPUT: mission -- The mission requested of the aircraft. *
  1998. * *
  1999. * target -- The value to assign to the aircraft's targeting computer. *
  2000. * *
  2001. * dest. -- The value to assign to the aircraft's navigation computer. *
  2002. * *
  2003. * OUTPUT: none *
  2004. * *
  2005. * WARNINGS: The mission specified will be executed at an indeterminate future game frame. *
  2006. * This is controlled by net/modem propagation delay. *
  2007. * *
  2008. * HISTORY: *
  2009. * 06/19/1995 JLB : Created. *
  2010. *=============================================================================================*/
  2011. void AircraftClass::Player_Assign_Mission(MissionType mission, TARGET target, TARGET destination)
  2012. {
  2013. assert(Aircraft.ID(this) == ID);
  2014. assert(IsActive);
  2015. if (AllowVoice) {
  2016. if (mission == MISSION_ATTACK) {
  2017. Response_Attack();
  2018. } else {
  2019. Response_Move();
  2020. }
  2021. }
  2022. Queue_Mission(TargetClass(this), mission, target, destination);
  2023. }
  2024. /***********************************************************************************************
  2025. * AircraftClass::What_Action -- Determines what action to perform. *
  2026. * *
  2027. * This routine is used to determine what action will likely be performed if the mouse *
  2028. * were clicked over the object specified. The display system calls this routine to *
  2029. * control the mouse shape. *
  2030. * *
  2031. * INPUT: target -- Pointer to the object that the mouse is currently over. *
  2032. * *
  2033. * OUTPUT: Returns with the action that will occur if the mouse were clicked over the *
  2034. * object specified. *
  2035. * *
  2036. * WARNINGS: none *
  2037. * *
  2038. * HISTORY: *
  2039. * 06/19/1995 JLB : Created. *
  2040. *=============================================================================================*/
  2041. ActionType AircraftClass::What_Action(ObjectClass const * target) const
  2042. {
  2043. assert(Aircraft.ID(this) == ID);
  2044. assert(IsActive);
  2045. ActionType action = FootClass::What_Action(target);
  2046. if (action == ACTION_SELF && (!How_Many() || (Height > 0) || IsTethered)) {
  2047. action = ACTION_NONE;
  2048. }
  2049. if (action == ACTION_ATTACK && Class->PrimaryWeapon == NULL) {
  2050. action = ACTION_NONE;
  2051. }
  2052. if (House->IsPlayerControl && House->Is_Ally(target) && target->What_Am_I() == RTTI_BUILDING && ((AircraftClass *)this)->Transmit_Message(RADIO_CAN_LOAD, (TechnoClass*)target) == RADIO_ROGER) {
  2053. action = ACTION_ENTER;
  2054. }
  2055. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  2056. if (!Class->IsFixedWing && House->IsPlayerControl && House->Is_Ally(target) && target->What_Am_I() == RTTI_VESSEL && *(VesselClass *)target == VESSEL_CARRIER && ((AircraftClass *)this)->Transmit_Message(RADIO_CAN_LOAD, (TechnoClass*)target) == RADIO_ROGER) {
  2057. action = ACTION_ENTER;
  2058. }
  2059. #endif
  2060. if (Class->IsFixedWing && action == ACTION_MOVE) {
  2061. action = ACTION_NOMOVE;
  2062. }
  2063. if (action == ACTION_NONE) {
  2064. action = What_Action(Coord_Cell(target->Center_Coord()));
  2065. }
  2066. /*
  2067. ** Special return to friendly repair factory action.
  2068. */
  2069. if (House->IsPlayerControl && action == ACTION_SELECT && target->What_Am_I() == RTTI_BUILDING) {
  2070. BuildingClass * building = (BuildingClass *)target;
  2071. if (building->Class->Type == STRUCT_REPAIR && !building->In_Radio_Contact() && !building->Is_Something_Attached()) {
  2072. action = ACTION_ENTER;
  2073. }
  2074. }
  2075. return(action);
  2076. }
  2077. /***********************************************************************************************
  2078. * AircraftClass::What_Action -- Determines what action to perform. *
  2079. * *
  2080. * This routine will determine what action would occur if the mouse were clicked over the *
  2081. * cell specified. The display system calls this routine to determine what mouse shape *
  2082. * to use. *
  2083. * *
  2084. * INPUT: cell -- The cell over which the mouse is currently positioned. *
  2085. * *
  2086. * OUTPUT: Returns with the action that will be performed if the mouse were clicked at the *
  2087. * specified cell location. *
  2088. * *
  2089. * WARNINGS: none *
  2090. * *
  2091. * HISTORY: *
  2092. * 06/19/1995 JLB : Created. *
  2093. *=============================================================================================*/
  2094. ActionType AircraftClass::What_Action(CELL cell) const
  2095. {
  2096. assert(Aircraft.ID(this) == ID);
  2097. assert(IsActive);
  2098. ActionType action = FootClass::What_Action(cell);
  2099. //using function for IsVisible so we have different results for different players - JAS 2019/09/30
  2100. if ((action == ACTION_MOVE || action == ACTION_ATTACK) && !Map[cell].Is_Visible(PlayerPtr)) {
  2101. action = ACTION_NOMOVE;
  2102. }
  2103. if (action == ACTION_ATTACK && Class->PrimaryWeapon == NULL) {
  2104. action = ACTION_NONE;
  2105. }
  2106. if (Class->IsFixedWing && action == ACTION_MOVE) {
  2107. action = ACTION_NOMOVE;
  2108. }
  2109. return(action);
  2110. }
  2111. /***********************************************************************************************
  2112. * AircraftClass::Pose_Dir -- Fetches the natural landing facing. *
  2113. * *
  2114. * Use this routine to get the desired facing the aircraft should assume when landing. *
  2115. * *
  2116. * INPUT: none *
  2117. * *
  2118. * OUTPUT: Returns with the normal default facing the aircraft should have when landed. *
  2119. * *
  2120. * WARNINGS: none *
  2121. * *
  2122. * HISTORY: *
  2123. * 06/19/1995 JLB : Created. *
  2124. * 03/04/1996 JLB : Fixed wing aircraft always face down the runway. *
  2125. *=============================================================================================*/
  2126. DirType AircraftClass::Pose_Dir(void) const
  2127. {
  2128. assert(Aircraft.ID(this) == ID);
  2129. assert(IsActive);
  2130. if (*this == AIRCRAFT_TRANSPORT) {
  2131. return(DIR_N);
  2132. }
  2133. if (Class->IsFixedWing) {
  2134. return(DIR_E);
  2135. }
  2136. return(DIR_NE);
  2137. }
  2138. /***********************************************************************************************
  2139. * AircraftClass::Mission_Attack -- Handles the attack mission for aircraft. *
  2140. * *
  2141. * This routine is the state machine that handles the attack mission for aircraft. It will *
  2142. * handling homing in on and firing on the target in the aircraft's targeting computer. *
  2143. * *
  2144. * INPUT: none *
  2145. * *
  2146. * OUTPUT: Returns with the number of game ticks to pass before this routine must be called *
  2147. * again. *
  2148. * *
  2149. * WARNINGS: none *
  2150. * *
  2151. * HISTORY: *
  2152. * 06/19/1995 JLB : Created. *
  2153. * 09/22/1995 JLB : Fixes brain dead helicopter for Nod scen #7. *
  2154. *=============================================================================================*/
  2155. int AircraftClass::Mission_Attack(void)
  2156. {
  2157. assert(Aircraft.ID(this) == ID);
  2158. assert(IsActive);
  2159. if (Class->IsFixedWing) {
  2160. return(Mission_Hunt());
  2161. }
  2162. enum {
  2163. VALIDATE_AZ,
  2164. PICK_ATTACK_LOCATION,
  2165. TAKE_OFF,
  2166. FLY_TO_POSITION,
  2167. FIRE_AT_TARGET,
  2168. FIRE_AT_TARGET2,
  2169. RETURN_TO_BASE
  2170. };
  2171. switch (Status) {
  2172. /*
  2173. ** Double check target and validate the attack zone.
  2174. */
  2175. case VALIDATE_AZ:
  2176. if (!Target_Legal(TarCom)) {
  2177. Status = RETURN_TO_BASE;
  2178. } else {
  2179. Status = PICK_ATTACK_LOCATION;
  2180. }
  2181. break;
  2182. /*
  2183. ** Pick a good location to attack from.
  2184. */
  2185. case PICK_ATTACK_LOCATION:
  2186. if (!Target_Legal(TarCom)) {
  2187. Status = RETURN_TO_BASE;
  2188. } else {
  2189. Assign_Destination(Good_Fire_Location(TarCom));
  2190. if (Target_Legal(NavCom)) {
  2191. Status = TAKE_OFF;
  2192. } else {
  2193. Status = RETURN_TO_BASE;
  2194. }
  2195. }
  2196. break;
  2197. /*
  2198. ** Take off (if necessary).
  2199. */
  2200. case TAKE_OFF:
  2201. if (!Target_Legal(TarCom)) {
  2202. Status = RETURN_TO_BASE;
  2203. } else {
  2204. if (Process_Take_Off()) {
  2205. Status = FLY_TO_POSITION;
  2206. /*
  2207. ** Break off radio contact with the helipad it is taking off from.
  2208. */
  2209. if (In_Radio_Contact() && Map[Coord].Cell_Building() == Contact_With_Whom()) {
  2210. Transmit_Message(RADIO_OVER_OUT);
  2211. }
  2212. /*
  2213. ** Start flying toward the destination by skewing at first.
  2214. ** As the flight progresses, the body will rotate to face
  2215. ** the direction of travel.
  2216. */
  2217. int diff = SecondaryFacing.Difference(Direction(NavCom));
  2218. diff = Bound(diff, -128, 128);
  2219. PrimaryFacing = DirType((int)SecondaryFacing.Current()+diff);
  2220. }
  2221. return(1);
  2222. }
  2223. break;
  2224. /*
  2225. ** Fly to attack location.
  2226. */
  2227. case FLY_TO_POSITION:
  2228. if (Target_Legal(TarCom)) {
  2229. /*
  2230. ** If the navcom was cleared mysteriously, then try to pick
  2231. ** a new attack location. This is a likely event if the player
  2232. ** clicks on a new target while in flight to an existing target.
  2233. */
  2234. if (!Target_Legal(NavCom)) {
  2235. Status = PICK_ATTACK_LOCATION;
  2236. return(1);
  2237. }
  2238. int distance = Process_Fly_To(true, NavCom);
  2239. if (distance < 0x0200) {
  2240. SecondaryFacing.Set_Desired(Direction(TarCom));
  2241. if (distance < 0x0010) {
  2242. Status = FIRE_AT_TARGET;
  2243. Assign_Destination(TARGET_NONE);
  2244. }
  2245. } else {
  2246. SecondaryFacing.Set_Desired(::Direction(Fire_Coord(0), As_Coord(NavCom)));
  2247. return(1);
  2248. }
  2249. } else {
  2250. Status = RETURN_TO_BASE;
  2251. }
  2252. return(1);
  2253. /*
  2254. ** Fire at the target.
  2255. */
  2256. case FIRE_AT_TARGET:
  2257. if (!Target_Legal(TarCom)) {
  2258. Status = RETURN_TO_BASE;
  2259. return(1);
  2260. }
  2261. PrimaryFacing.Set_Desired(Direction(TarCom));
  2262. SecondaryFacing.Set_Desired(Direction(TarCom));
  2263. switch (Can_Fire(TarCom, 0)) {
  2264. case FIRE_CLOAKED:
  2265. Do_Uncloak();
  2266. break;
  2267. case FIRE_OK:
  2268. Fire_At(TarCom, 0);
  2269. Map[::As_Cell(TarCom)].Incoming(Coord, true);
  2270. Status = FIRE_AT_TARGET2;
  2271. break;
  2272. case FIRE_REARM:
  2273. case FIRE_FACING:
  2274. break;
  2275. default:
  2276. if (!Ammo) {
  2277. Status = RETURN_TO_BASE;
  2278. } else {
  2279. Status = FIRE_AT_TARGET2;
  2280. }
  2281. break;
  2282. }
  2283. return(1);
  2284. /*
  2285. ** Fire at the target.
  2286. */
  2287. case FIRE_AT_TARGET2:
  2288. if (!Target_Legal(TarCom)) {
  2289. Status = RETURN_TO_BASE;
  2290. return(1);
  2291. }
  2292. PrimaryFacing.Set_Desired(Direction(TarCom));
  2293. SecondaryFacing.Set_Desired(Direction(TarCom));
  2294. switch (Can_Fire(TarCom, 0)) {
  2295. case FIRE_CLOAKED:
  2296. Do_Uncloak();
  2297. break;
  2298. case FIRE_REARM:
  2299. break;
  2300. case FIRE_OK:
  2301. Fire_At(TarCom, 0);
  2302. Map[::As_Cell(TarCom)].Incoming(Coord, true);
  2303. if (Ammo) {
  2304. Status = Rule.IsCurleyShuffle ? PICK_ATTACK_LOCATION : FIRE_AT_TARGET;
  2305. } else {
  2306. Status = RETURN_TO_BASE;
  2307. }
  2308. break;
  2309. default:
  2310. if (!Ammo) {
  2311. Status = RETURN_TO_BASE;
  2312. } else {
  2313. if (!In_Range(TarCom)) {
  2314. Status = PICK_ATTACK_LOCATION;
  2315. } else {
  2316. Status = Rule.IsCurleyShuffle ? PICK_ATTACK_LOCATION : FIRE_AT_TARGET;
  2317. }
  2318. }
  2319. break;
  2320. }
  2321. break;
  2322. /*
  2323. ** Fly back to landing spot.
  2324. */
  2325. case RETURN_TO_BASE:
  2326. /*
  2327. ** Break off of firing at the target if there is no more
  2328. ** point in attacking it this mission. The player will
  2329. ** reassign a target for the next mission.
  2330. */
  2331. if (!Ammo && (IsALoaner || House->IsHuman)) {
  2332. Assign_Target(TARGET_NONE);
  2333. }
  2334. Assign_Destination(TARGET_NONE);
  2335. Enter_Idle_Mode();
  2336. break;
  2337. default:
  2338. break;
  2339. }
  2340. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  2341. }
  2342. /***********************************************************************************************
  2343. * AircraftClass::New_LZ -- Find a good landing zone. *
  2344. * *
  2345. * Use this routine to locate a good landing zone that is nearby the location specified. *
  2346. * By using this routine it is possible to assign the same landing zone to several *
  2347. * aircraft and they will land nearby without conflict. *
  2348. * *
  2349. * INPUT: oldlz -- Target value of desired landing zone (usually a cell target value). *
  2350. * *
  2351. * OUTPUT: Returns with the new good landing zone. It might be the same value passed in. *
  2352. * *
  2353. * WARNINGS: The landing zone might be a goodly distance away from the ideal if there is *
  2354. * extensive blocking terrain in the vicinity. *
  2355. * *
  2356. * HISTORY: *
  2357. * 06/19/1995 JLB : Created. *
  2358. *=============================================================================================*/
  2359. TARGET AircraftClass::New_LZ(TARGET oldlz) const
  2360. {
  2361. assert(Aircraft.ID(this) == ID);
  2362. assert(IsActive);
  2363. if (Target_Legal(oldlz) && (!Is_LZ_Clear(oldlz) || !Cell_Seems_Ok(As_Cell(oldlz)))) {
  2364. COORDINATE coord = As_Coord(oldlz);
  2365. /*
  2366. ** Scan outward in a series of concentric rings up to certain distance
  2367. ** in cells.
  2368. */
  2369. for (int radius = 0; radius < Rule.LZScanRadius / CELL_LEPTON_W; radius++) {
  2370. FacingType modifier = Random_Pick(FACING_N, FACING_NW);
  2371. CELL lastcell = -1;
  2372. /*
  2373. ** Perform a radius scan out from the original center location. Try to
  2374. ** find a cell that is allowed to be a legal LZ.
  2375. */
  2376. for (FacingType facing = FACING_N; facing < FACING_COUNT; facing++) {
  2377. CELL newcell = Coord_Cell(Coord_Move(coord, Facing_Dir(facing+modifier), radius * ICON_LEPTON_W));
  2378. if (Map.In_Radar(newcell)) {
  2379. TARGET newtarget = ::As_Target(newcell);
  2380. if (newcell != lastcell && Is_LZ_Clear(newtarget) && Cell_Seems_Ok(newcell)) {
  2381. return(newtarget);
  2382. }
  2383. lastcell = newcell;
  2384. }
  2385. }
  2386. }
  2387. }
  2388. return(oldlz);
  2389. }
  2390. /***********************************************************************************************
  2391. * AircraftClass::Receive_Message -- Handles receipt of radio messages. *
  2392. * *
  2393. * This routine receives all radio messages directed at this aircraft. It is used to handle *
  2394. * all inter-object coordination. Typically, this would be for transport helicopters and *
  2395. * other complex landing operations required of helicopters. *
  2396. * *
  2397. * INPUT: from -- The source of this radio message. *
  2398. * *
  2399. * message -- The message itself. *
  2400. * *
  2401. * param -- An optional parameter that may be used to transfer additional *
  2402. * data. *
  2403. * *
  2404. * OUTPUT: Returns with the radio response from the aircraft. *
  2405. * *
  2406. * WARNINGS: Some radio messages are handled by the base classes. *
  2407. * *
  2408. * HISTORY: *
  2409. * 06/19/1995 JLB : Created. *
  2410. *=============================================================================================*/
  2411. RadioMessageType AircraftClass::Receive_Message(RadioClass * from, RadioMessageType message, long & param)
  2412. {
  2413. assert(Aircraft.ID(this) == ID);
  2414. assert(IsActive);
  2415. switch (message) {
  2416. case RADIO_PREPARED:
  2417. if (Target_Legal(TarCom)) return(RADIO_NEGATIVE);
  2418. if ((Height == 0 && Ammo == Class->MaxAmmo) || (Height > 0 && Ammo > 0)) return(RADIO_ROGER);
  2419. return(RADIO_NEGATIVE);
  2420. /*
  2421. ** Something disastrous has happened to the object in contact with. Fall back
  2422. ** and regroup. This means that any landing process is immediately aborted.
  2423. */
  2424. case RADIO_RUN_AWAY:
  2425. if (IsLanding) {
  2426. IsLanding = false;
  2427. IsTakingOff = true;
  2428. }
  2429. if (Class->IsFixedWing) {
  2430. Assign_Destination(Good_LZ());
  2431. if (!Target_Legal(NavCom)) {
  2432. Assign_Mission(MISSION_RETREAT);
  2433. } else {
  2434. Assign_Mission(MISSION_MOVE);
  2435. }
  2436. } else {
  2437. Scatter(0, true);
  2438. }
  2439. break;
  2440. /*
  2441. ** The ground control requests that this specified landing spot be used.
  2442. */
  2443. case RADIO_MOVE_HERE:
  2444. FootClass::Receive_Message(from, message, param);
  2445. if (Is_Target_Building(param)) {
  2446. if (Transmit_Message(RADIO_CAN_LOAD, As_Techno(param)) != RADIO_ROGER) {
  2447. return(RADIO_NEGATIVE);
  2448. }
  2449. Assign_Mission(MISSION_ENTER);
  2450. Assign_Destination((TARGET)param);
  2451. } else {
  2452. Assign_Mission(MISSION_MOVE);
  2453. Assign_Destination((TARGET)param);
  2454. }
  2455. Commence();
  2456. return(RADIO_ROGER);
  2457. /*
  2458. ** Ground control is requesting if the aircraft requires navigation direction.
  2459. */
  2460. case RADIO_NEED_TO_MOVE:
  2461. FootClass::Receive_Message(from, message, param);
  2462. if (!Target_Legal(NavCom) && !IsTakingOff && !IsLanding) {
  2463. return(RADIO_ROGER);
  2464. }
  2465. return(RADIO_NEGATIVE);
  2466. /*
  2467. ** This message is sent by the passenger when it determines that it has
  2468. ** entered the transport.
  2469. */
  2470. case RADIO_IM_IN:
  2471. if (How_Many() == Class->Max_Passengers()) {
  2472. Close_Door(5, 4);
  2473. }
  2474. /*
  2475. ** If a civilian has entered the transport, then the transport will immediately
  2476. ** fly off the map.
  2477. */
  2478. if (_Counts_As_Civ_Evac(from)) {
  2479. Assign_Mission(MISSION_RETREAT);
  2480. }
  2481. return(RADIO_ATTACH);
  2482. /*
  2483. ** Docking maintenance message received. Check to see if new orders should be given
  2484. ** to the impatient unit.
  2485. */
  2486. case RADIO_DOCKING:
  2487. if (Class->Max_Passengers() > 0 && How_Many() < Class->Max_Passengers()) {
  2488. FootClass::Receive_Message(from, message, param);
  2489. if (!IsTethered && !IsLanding && !IsTakingOff && Height == 0) {
  2490. Open_Door(5, 4);
  2491. /*
  2492. ** If the potential passenger needs someplace to go, then figure out a good
  2493. ** spot and tell it to go.
  2494. */
  2495. if (Transmit_Message(RADIO_NEED_TO_MOVE, from) == RADIO_ROGER) {
  2496. CELL cell;
  2497. /*DirType dir =*/ Desired_Load_Dir(from, cell);
  2498. /*
  2499. ** If no adjacent free cells are detected, then passenger loading
  2500. ** cannot occur. Break radio contact.
  2501. */
  2502. if (cell == 0) {
  2503. Transmit_Message(RADIO_OVER_OUT, from);
  2504. } else {
  2505. param = (long)::As_Target(cell);
  2506. /*
  2507. ** Tell the potential passenger where it should go. If the passenger is
  2508. ** already at the staging location, then tell it to move onto the transport
  2509. ** directly.
  2510. */
  2511. if (Transmit_Message(RADIO_MOVE_HERE, param, from) == RADIO_YEA_NOW_WHAT) {
  2512. param = (long)As_Target();
  2513. Transmit_Message(RADIO_TETHER);
  2514. if (Transmit_Message(RADIO_MOVE_HERE, param, from) != RADIO_ROGER) {
  2515. Transmit_Message(RADIO_OVER_OUT, from);
  2516. } else {
  2517. Contact_With_Whom()->Unselect();
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. return(RADIO_ROGER);
  2524. }
  2525. break;
  2526. /*
  2527. ** Asks if the passenger can load on this transport.
  2528. */
  2529. case RADIO_CAN_LOAD:
  2530. if (Class->Max_Passengers() == 0 || from == NULL || !House->Is_Ally(from->Owner()) || Height > 0) return(RADIO_STATIC);
  2531. if (/*!In_Radio_Contact() &&*/ How_Many() < Class->Max_Passengers()) {
  2532. return(RADIO_ROGER);
  2533. }
  2534. return(RADIO_NEGATIVE);
  2535. default:
  2536. break;
  2537. }
  2538. /*
  2539. ** Let the base class take over processing this message.
  2540. */
  2541. return(FootClass::Receive_Message(from, message, param));
  2542. }
  2543. /***********************************************************************************************
  2544. * AircraftClass::Desired_Load_Dir -- Determines where passengers should line up. *
  2545. * *
  2546. * This routine is used by the transport helicopter to determine the location where the *
  2547. * infantry passengers should line up before loading. *
  2548. * *
  2549. * INPUT: object -- The object that is trying to load up on this transport. *
  2550. * *
  2551. * -- Reference to the cell that the passengers should move to before the *
  2552. * actual load process may begin. *
  2553. * *
  2554. * OUTPUT: Returns with the direction that the helicopter should face for the load operation. *
  2555. * *
  2556. * WARNINGS: none *
  2557. * *
  2558. * HISTORY: *
  2559. * 06/12/1995 JLB : Created. *
  2560. * 07/30/1995 JLB : Revamped to scan all adjacent cells. *
  2561. *=============================================================================================*/
  2562. DirType AircraftClass::Desired_Load_Dir(ObjectClass * object, CELL & moveto) const
  2563. {
  2564. assert(Aircraft.ID(this) == ID);
  2565. assert(IsActive);
  2566. CELL center = Coord_Cell(Center_Coord());
  2567. for (int sweep = FACING_N; sweep < FACING_S; sweep++) {
  2568. moveto = Adjacent_Cell(center, FacingType(FACING_S+sweep));
  2569. if (Map.In_Radar(moveto) && (Coord_Cell(object->Center_Coord()) == moveto || Map[moveto].Is_Clear_To_Move(SPEED_FOOT, false, false))) return(DIR_N);
  2570. moveto = Adjacent_Cell(center, FacingType(FACING_S-sweep));
  2571. if (Map.In_Radar(moveto) && (Coord_Cell(object->Center_Coord()) == moveto || Map[moveto].Is_Clear_To_Move(SPEED_FOOT, false, false))) return(DIR_N);
  2572. }
  2573. return(DIR_N);
  2574. }
  2575. /***********************************************************************************************
  2576. * AircraftClass::Process_Take_Off -- State machine support for taking off. *
  2577. * *
  2578. * This routine is used by the main game state machine processor. This utility routine *
  2579. * handles a helicopter as it transitions from landed to flying state. *
  2580. * *
  2581. * INPUT: none *
  2582. * *
  2583. * OUTPUT: Has the helicopter reached flight level now? *
  2584. * *
  2585. * WARNINGS: none *
  2586. * *
  2587. * HISTORY: *
  2588. * 06/12/1995 JLB : Created. *
  2589. *=============================================================================================*/
  2590. bool AircraftClass::Process_Take_Off(void)
  2591. {
  2592. assert(Aircraft.ID(this) == ID);
  2593. assert(IsActive);
  2594. IsLanding = false;
  2595. IsTakingOff = true;
  2596. if (Class->IsFixedWing) {
  2597. Set_Speed(0xFF);
  2598. if (Height == FLIGHT_LEVEL) {
  2599. return(true);
  2600. }
  2601. } else {
  2602. switch (Height) {
  2603. case 0:
  2604. Close_Door(5, 4);
  2605. PrimaryFacing = SecondaryFacing;
  2606. break;
  2607. case FLIGHT_LEVEL/2:
  2608. PrimaryFacing.Set_Desired(Direction(NavCom));
  2609. break;
  2610. case FLIGHT_LEVEL-(FLIGHT_LEVEL/3):
  2611. SecondaryFacing.Set_Desired(PrimaryFacing.Desired());
  2612. Set_Speed(0x20);
  2613. break;
  2614. case FLIGHT_LEVEL-(FLIGHT_LEVEL/5):
  2615. Set_Speed(0x40);
  2616. break;
  2617. case FLIGHT_LEVEL:
  2618. Set_Speed(0xFF);
  2619. IsTakingOff = false;
  2620. return(true);
  2621. default:
  2622. break;
  2623. }
  2624. }
  2625. return(false);
  2626. }
  2627. /***********************************************************************************************
  2628. * AircraftClass::Process_Landing -- Landing process state machine handler. *
  2629. * *
  2630. * This is a support routine that is called by the main state machine routines. This *
  2631. * routine is responsible for handling the helicopter as it transitions from flight to *
  2632. * landing. *
  2633. * *
  2634. * INPUT: none *
  2635. * *
  2636. * OUTPUT: Has the helicopter completely landed now? *
  2637. * *
  2638. * WARNINGS: none *
  2639. * *
  2640. * HISTORY: *
  2641. * 06/12/1995 JLB : Created. *
  2642. * 03/04/1996 JLB : Handles fixed wing aircraft. *
  2643. *=============================================================================================*/
  2644. bool AircraftClass::Process_Landing(void)
  2645. {
  2646. assert(Aircraft.ID(this) == ID);
  2647. assert(IsActive);
  2648. IsTakingOff = false;
  2649. IsLanding = true;
  2650. if (Class->IsFixedWing) {
  2651. int distance = Distance(NavCom);
  2652. if (distance > 0x0100) {
  2653. SecondaryFacing.Set_Desired(::Direction(Fire_Coord(0), As_Coord(NavCom)));
  2654. }
  2655. switch (Height) {
  2656. case 0:
  2657. Set_Speed(0);
  2658. IsLanding = false;
  2659. return(true);
  2660. default:
  2661. // if (distance*2 > Class->LandingSpeed) {
  2662. // Set_Speed(Class->LandingSpeed);
  2663. // } else {
  2664. // Set_Speed(distance/2);
  2665. // }
  2666. Set_Speed(Class->LandingSpeed / House->AirspeedBias);
  2667. break;
  2668. }
  2669. } else {
  2670. switch (Height) {
  2671. case 0:
  2672. IsLanding = false;
  2673. return(true);
  2674. case FLIGHT_LEVEL/2:
  2675. Set_Speed(0);
  2676. break;
  2677. case FLIGHT_LEVEL:
  2678. break;
  2679. default:
  2680. break;
  2681. }
  2682. }
  2683. return(false);
  2684. }
  2685. /***********************************************************************************************
  2686. * AircraftClass::Can_Enter_Cell -- Determines if the aircraft can land at this location. *
  2687. * *
  2688. * This routine is used when the passability of a cell needs to be determined. This is *
  2689. * necessary when scanning for a location that the aircraft can land. *
  2690. * *
  2691. * INPUT: cell -- The cell location to check for landing. *
  2692. * *
  2693. * OUTPUT: Returns a value indicating if the cell is a legal landing spot or not. *
  2694. * *
  2695. * WARNINGS: none *
  2696. * *
  2697. * HISTORY: *
  2698. * 06/12/1995 JLB : Created. *
  2699. *=============================================================================================*/
  2700. MoveType AircraftClass::Can_Enter_Cell(CELL cell, FacingType ) const
  2701. {
  2702. assert(Aircraft.ID(this) == ID);
  2703. assert(IsActive);
  2704. if (!Map.In_Radar(cell)) return(MOVE_NO);
  2705. CellClass * cellptr = &Map[cell];
  2706. ObjectClass const * occupier = cellptr->Cell_Occupier();
  2707. if (occupier == NULL ||
  2708. !occupier->Is_Techno() ||
  2709. ((TechnoClass *)occupier)->House->Is_Ally(House) ||
  2710. (!((TechnoClass *)occupier)->Is_Cloaked(this) &&
  2711. (ScenarioInit == 0 && (occupier->What_Am_I() != RTTI_BUILDING || !((BuildingClass*)occupier)->Class->IsInvisible)) )
  2712. ) {
  2713. if (!cellptr->Is_Clear_To_Move(SPEED_TRACK, false, false)) return(MOVE_NO);
  2714. }
  2715. if (Session.Type == GAME_NORMAL && IsOwnedByPlayer && !cellptr->IsMapped) {
  2716. return(MOVE_NO);
  2717. }
  2718. return(MOVE_OK);
  2719. }
  2720. /***********************************************************************************************
  2721. * AircraftClass::Good_Fire_Location -- Searches for and finds a good spot to fire from. *
  2722. * *
  2723. * Given the specified target, this routine will locate a good spot for the aircraft to *
  2724. * fire at the target. *
  2725. * *
  2726. * INPUT: target -- The target that is desired to be attacked. *
  2727. * *
  2728. * OUTPUT: Returns with the target location of the place that firing should be made from. *
  2729. * *
  2730. * WARNINGS: none *
  2731. * *
  2732. * HISTORY: *
  2733. * 06/12/1995 JLB : Created. *
  2734. * 06/14/1995 JLB : Finer resolution on ring scan. *
  2735. * 11/02/1996 JLB : Bias fire position to get closer to moving objects. *
  2736. *=============================================================================================*/
  2737. TARGET AircraftClass::Good_Fire_Location(TARGET target) const
  2738. {
  2739. assert(Aircraft.ID(this) == ID);
  2740. assert(IsActive);
  2741. if (Target_Legal(target)) {
  2742. int range = Weapon_Range(0);
  2743. COORDINATE tcoord = As_Coord(target);
  2744. CELL bestcell = 0;
  2745. CELL best2cell = 0;
  2746. int bestval = -1;
  2747. int best2val = -1;
  2748. /*
  2749. ** Try to get closer to a target that is moving.
  2750. */
  2751. COORDINATE altcoord = 0;
  2752. if (Is_Target_Object(target) && As_Object(target)->Is_Foot()) {
  2753. TARGET alttarg = ((FootClass *)As_Object(target))->NavCom;
  2754. if (Target_Legal(alttarg)) {
  2755. altcoord = As_Coord(alttarg);
  2756. }
  2757. }
  2758. for (int r = range-0x0100; r > 0x0100; r -= 0x0100) {
  2759. for (int face = 0; face < 255; face += 16) {
  2760. COORDINATE newcoord = Coord_Move(tcoord, (DirType)face, r);
  2761. CELL newcell = Coord_Cell(newcoord);
  2762. CELL actualcell = Coord_Cell(Coord_Sub(newcoord, XY_Coord(0, FLIGHT_LEVEL)));
  2763. //using function for IsVisible so we have different results for different players - JAS 2019/09/30
  2764. if (Map.In_Radar(actualcell) && (Session.Type != GAME_NORMAL || Map[newcell].Is_Visible(PlayerPtr)) && Cell_Seems_Ok(newcell, true)) {
  2765. int dist;
  2766. if (altcoord != 0) {
  2767. dist = ::Distance(newcoord, altcoord);
  2768. } else {
  2769. dist = Distance(newcoord);
  2770. }
  2771. if (bestval == -1 || dist < bestval) {
  2772. best2val = bestval;
  2773. best2cell = bestcell;
  2774. bestval = dist;
  2775. bestcell = newcell;
  2776. }
  2777. }
  2778. }
  2779. if (bestval != -1) break;
  2780. }
  2781. if (best2val == -1) {
  2782. best2cell = bestcell;
  2783. }
  2784. /*
  2785. ** If it found a good firing location, then return this location as
  2786. ** a target value.
  2787. */
  2788. if (bestval != -1) {
  2789. if (Percent_Chance(50)) {
  2790. return(::As_Target(bestcell));
  2791. } else {
  2792. return(::As_Target(best2cell));
  2793. }
  2794. }
  2795. }
  2796. return(TARGET_NONE);
  2797. }
  2798. /***********************************************************************************************
  2799. * AircraftClass::Cell_Seems_Ok -- Checks to see if a cell is good to enter. *
  2800. * *
  2801. * This routine examines the navigation computers of other aircraft in order to see if the *
  2802. * specified cell is safe to fly to. The intent of this routine is to avoid unnecessary *
  2803. * mid-air collisions. *
  2804. * *
  2805. * INPUT: cell -- The cell to examine for clear airspace. *
  2806. * *
  2807. * strict -- Should the scan consider the aircraft, that is making this check, a *
  2808. * blocking aircraft. Typically, the aircraft itself is not considered *
  2809. * a blockage -- an aircraft can always exist where it is currently *
  2810. * located. A strict check is useful for helicopters that need to move *
  2811. * around at the slightest provocation. *
  2812. * *
  2813. * OUTPUT: Is the specified cell free from airspace conflicts? *
  2814. * *
  2815. * WARNINGS: none *
  2816. * *
  2817. * HISTORY: *
  2818. * 06/19/1995 JLB : Created. *
  2819. *=============================================================================================*/
  2820. bool AircraftClass::Cell_Seems_Ok(CELL cell, bool strict) const
  2821. {
  2822. assert(Aircraft.ID(this) == ID);
  2823. assert(IsActive);
  2824. /*
  2825. ** Make sure that no other aircraft are heading to the selected location. If they
  2826. ** are, then don't consider the location as valid.
  2827. */
  2828. TARGET astarget = ::As_Target(cell);
  2829. for (int index = 0; index < Aircraft.Count(); index++) {
  2830. AircraftClass * air = Aircraft.Ptr(index);
  2831. if (air && (strict || air != this) && !air->IsInLimbo) {
  2832. if (Coord_Cell(air->Coord) == cell || air->NavCom == astarget) {
  2833. return(false);
  2834. }
  2835. }
  2836. }
  2837. return(true);
  2838. }
  2839. /***********************************************************************************************
  2840. * AircraftClass::Pip_Count -- Returns the number of "objects" in aircraft. *
  2841. * *
  2842. * This routine is used by the render logic to draw the little container "pips". This *
  2843. * corresponds to the number of passengers for a transport helicopter or the number of *
  2844. * shots remaining for an attack helicopter. *
  2845. * *
  2846. * INPUT: none *
  2847. * *
  2848. * OUTPUT: Returns with the number of "pips" to render on the aircraft. *
  2849. * *
  2850. * WARNINGS: none *
  2851. * *
  2852. * HISTORY: *
  2853. * 06/11/1995 JLB : Created. *
  2854. *=============================================================================================*/
  2855. int AircraftClass::Pip_Count(void) const
  2856. {
  2857. assert(Aircraft.ID(this) == ID);
  2858. assert(IsActive);
  2859. int retval = 0;
  2860. bool carrying_passengers = (Class->Max_Passengers() > 0) && ((*this != AIRCRAFT_BADGER) || (Mission != MISSION_HUNT));
  2861. if (carrying_passengers) {
  2862. retval = How_Many();
  2863. } else {
  2864. if (Ammo) {
  2865. retval = Class->Max_Pips() * fixed(Ammo, Class->MaxAmmo);
  2866. if (!retval) retval = 1;
  2867. }
  2868. }
  2869. return(retval);
  2870. }
  2871. /***********************************************************************************************
  2872. * AircraftClass::Mission_Enter -- Control aircraft to fly to the helipad or repair center. *
  2873. * *
  2874. * This routine is used when the aircraft needs to fly for either rearming or repairing. *
  2875. * It tries to establish contact with the support building. Once contact is established *
  2876. * the ground controller takes care of commanding the aircraft. *
  2877. * *
  2878. * INPUT: none *
  2879. * *
  2880. * OUTPUT: Returns with the delay before this routine should be called again. *
  2881. * *
  2882. * WARNINGS: none *
  2883. * *
  2884. * HISTORY: *
  2885. * 06/12/1995 JLB : Created. *
  2886. * 07/04/1995 JLB : Ground controller gives orders. *
  2887. *=============================================================================================*/
  2888. int AircraftClass::Mission_Enter(void)
  2889. {
  2890. assert(Aircraft.ID(this) == ID);
  2891. assert(IsActive);
  2892. enum {
  2893. INITIAL,
  2894. TAKEOFF,
  2895. ALTITUDE,
  2896. STACK,
  2897. DOWNWIND,
  2898. CROSSWIND,
  2899. TRAVEL,
  2900. LANDING
  2901. };
  2902. /*
  2903. ** Verify that it has a valid NavCom. If it doesn't then request one from the
  2904. ** building this building is trying to land upon. If that fails, then enter
  2905. ** idle mode.
  2906. */
  2907. if (!Target_Legal(NavCom) && In_Which_Layer() != LAYER_GROUND) {
  2908. if (Transmit_Message(RADIO_DOCKING) != RADIO_ROGER) {
  2909. Enter_Idle_Mode();
  2910. return(1);
  2911. }
  2912. }
  2913. switch (Status) {
  2914. case INITIAL:
  2915. if (Height < FLIGHT_LEVEL || IsLanding) {
  2916. Status = TAKEOFF;
  2917. } else {
  2918. Status = ALTITUDE;
  2919. }
  2920. break;
  2921. case TAKEOFF:
  2922. if (Process_Take_Off()) {
  2923. /*
  2924. ** After takeoff is complete, break radio contact with any helipad that this
  2925. ** helicopter is taking off from.
  2926. */
  2927. if (In_Radio_Contact() && Map[Coord].Cell_Building() == Contact_With_Whom()) {
  2928. Transmit_Message(RADIO_OVER_OUT);
  2929. }
  2930. Status = ALTITUDE;
  2931. }
  2932. break;
  2933. case ALTITUDE:
  2934. /*
  2935. ** Establish radio contact with the building this helicopter is trying
  2936. ** to land at.
  2937. */
  2938. if (In_Radio_Contact()) {
  2939. if (!Target_Legal(NavCom)) {
  2940. Transmit_Message(RADIO_DOCKING);
  2941. if (!Target_Legal(NavCom)) {
  2942. Enter_Idle_Mode();
  2943. return(1);
  2944. }
  2945. }
  2946. Status = STACK;
  2947. } else {
  2948. TechnoClass * tech = As_Techno(NavCom);
  2949. if (tech && Transmit_Message(RADIO_CAN_LOAD, tech) == RADIO_ROGER) {
  2950. Transmit_Message(RADIO_HELLO, tech);
  2951. Transmit_Message(RADIO_DOCKING);
  2952. Status = STACK;
  2953. } else {
  2954. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  2955. if (tech->What_Am_I() != RTTI_VESSEL) {
  2956. Assign_Destination(TARGET_NONE);
  2957. Enter_Idle_Mode();
  2958. }
  2959. #else
  2960. Assign_Destination(TARGET_NONE);
  2961. Enter_Idle_Mode();
  2962. #endif
  2963. }
  2964. }
  2965. break;
  2966. case STACK:
  2967. if (Class->IsFixedWing) {
  2968. int distance;
  2969. TARGET togo;
  2970. BuildingClass const * building = As_Building(NavCom);
  2971. if (building) {
  2972. togo = ::As_Target(building->Check_Point(CHECK_STACK));
  2973. } else {
  2974. togo = NavCom;
  2975. }
  2976. distance = Process_Fly_To(true, togo);
  2977. if (distance < 0x0080) {
  2978. Status = DOWNWIND;
  2979. }
  2980. } else {
  2981. Status = DOWNWIND;
  2982. }
  2983. break;
  2984. case DOWNWIND:
  2985. if (Class->IsFixedWing) {
  2986. int distance;
  2987. TARGET togo;
  2988. Set_Speed(200);
  2989. BuildingClass const * building = As_Building(NavCom);
  2990. if (building) {
  2991. togo = ::As_Target(building->Check_Point(CHECK_DOWNWIND));
  2992. } else {
  2993. togo = NavCom;
  2994. }
  2995. distance = Process_Fly_To(true, togo);
  2996. if (distance < 0x0080) {
  2997. Status = CROSSWIND;
  2998. }
  2999. } else {
  3000. Status = CROSSWIND;
  3001. }
  3002. break;
  3003. case CROSSWIND:
  3004. if (Class->IsFixedWing) {
  3005. int distance;
  3006. TARGET togo;
  3007. Set_Speed(140);
  3008. BuildingClass const * building = As_Building(NavCom);
  3009. if (building) {
  3010. togo = ::As_Target(building->Check_Point(CHECK_CROSSWIND));
  3011. } else {
  3012. togo = NavCom;
  3013. }
  3014. distance = Process_Fly_To(true, togo);
  3015. if (distance < 0x0080) {
  3016. Status = TRAVEL;
  3017. }
  3018. } else {
  3019. Status = TRAVEL;
  3020. }
  3021. break;
  3022. case TRAVEL:
  3023. Transmit_Message(RADIO_DOCKING);
  3024. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  3025. if (!In_Radio_Contact() && !Is_Target_Vessel(NavCom)) {
  3026. #else
  3027. if (!In_Radio_Contact()) {
  3028. #endif
  3029. Assign_Destination(TARGET_NONE);
  3030. Enter_Idle_Mode();
  3031. } else {
  3032. int distance = Process_Fly_To(true, NavCom);
  3033. if (Class->IsFixedWing) {
  3034. if (distance < 0x0400) {
  3035. Status = LANDING;
  3036. }
  3037. return(1);
  3038. } else {
  3039. if (distance < 0x0080) {
  3040. if (Target_Legal(TarCom)) {
  3041. SecondaryFacing.Set_Desired(Direction(TarCom));
  3042. } else {
  3043. SecondaryFacing.Set_Desired(Pose_Dir());
  3044. }
  3045. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  3046. if (Is_Target_Vessel(NavCom) && !In_Radio_Contact()) {
  3047. Enter_Idle_Mode();
  3048. break;
  3049. }
  3050. #endif
  3051. if (distance < 0x0010) {
  3052. Status = LANDING;
  3053. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  3054. if(Is_Target_Vessel(NavCom) && As_Vessel(NavCom)->NavCom) {
  3055. Status = TRAVEL;
  3056. }
  3057. #endif
  3058. }
  3059. break;
  3060. } else {
  3061. SecondaryFacing.Set_Desired(Direction(NavCom));
  3062. // SecondaryFacing.Set_Desired(::Direction(Fire_Coord(0), As_Coord(NavCom)));
  3063. }
  3064. }
  3065. return(3);
  3066. }
  3067. break;
  3068. case LANDING:
  3069. if (IsTakingOff && !Class->IsFixedWing) {
  3070. Assign_Destination(TARGET_NONE);
  3071. Enter_Idle_Mode();
  3072. }
  3073. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  3074. // If we were trying to land on a carrier and it moved, take off again
  3075. if ( As_Vessel(NavCom) && !In_Radio_Contact()) {
  3076. Status = INITIAL;
  3077. break;
  3078. }
  3079. #endif
  3080. if (Process_Landing()) {
  3081. switch (Transmit_Message(RADIO_IM_IN)) {
  3082. case RADIO_ROGER:
  3083. Assign_Mission(MISSION_GUARD);
  3084. break;
  3085. case RADIO_ATTACH:
  3086. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  3087. if(Contact_With_Whom()->What_Am_I() != RTTI_VESSEL) Limbo();
  3088. #else
  3089. Limbo();
  3090. #endif
  3091. Contact_With_Whom()->Attach(this);
  3092. break;
  3093. default:
  3094. Enter_Idle_Mode();
  3095. }
  3096. }
  3097. break;
  3098. default:
  3099. break;
  3100. }
  3101. return(1);
  3102. }
  3103. /***********************************************************************************************
  3104. * AircraftClass::Good_LZ -- Locates a good spot to land. *
  3105. * *
  3106. * This routine is used when helicopters need a place to land, but there are no obvious *
  3107. * spots (i.e., helipad) available. It will try to land near a friendly helipad or friendly *
  3108. * building if there are no helipads anywhere. In the event that there are no friendly *
  3109. * buildings anywhere on the map, then just land right where it is flying. *
  3110. * *
  3111. * INPUT: none *
  3112. * *
  3113. * OUTPUT: Returns with the target location where this aircraft should land. This value may *
  3114. * not be a clear cell, but the normal landing logic will resolve that problem. *
  3115. * *
  3116. * WARNINGS: none *
  3117. * *
  3118. * HISTORY: *
  3119. * 06/12/1995 JLB : Created. *
  3120. *=============================================================================================*/
  3121. TARGET AircraftClass::Good_LZ(void) const
  3122. {
  3123. assert(Aircraft.ID(this) == ID);
  3124. assert(IsActive);
  3125. /*
  3126. ** Scan through all of the buildings and try to land near
  3127. ** the helipad (if there is one) or the nearest friendly building.
  3128. */
  3129. CELL bestcell = 0;
  3130. int bestdist = -1;
  3131. for (int index = 0; index < Buildings.Count(); index++) {
  3132. BuildingClass * building = Buildings.Ptr(index);
  3133. if (building && !building->IsInLimbo && building->House == House) {
  3134. int dist = Distance(building);
  3135. if (*building == Class->Building) {
  3136. dist /= 4;
  3137. }
  3138. if (bestdist == -1 || dist < bestdist) {
  3139. bestdist = dist;
  3140. bestcell = Coord_Cell(building->Center_Coord());
  3141. }
  3142. }
  3143. }
  3144. /*
  3145. ** Return with the suitable location if one was found.
  3146. */
  3147. if (bestdist != -1) {
  3148. return(::As_Target(bestcell));
  3149. }
  3150. /*
  3151. ** No good location was found. Just try to land here.
  3152. */
  3153. return(::As_Target(Coord_Cell(Coord)));
  3154. }
  3155. /***********************************************************************************************
  3156. * AircraftClass::Set_Speed -- Sets the speed for the aircraft. *
  3157. * *
  3158. * This routine will set the speed for the aircraft. The speed is specified as a fraction *
  3159. * of full speed. *
  3160. * *
  3161. * INPUT: speed -- The fixed point fractional speed setting. 0x00 is stopped, 0xFF is full *
  3162. * speed. *
  3163. * *
  3164. * OUTPUT: none *
  3165. * *
  3166. * WARNINGS: none *
  3167. * *
  3168. * HISTORY: *
  3169. * 06/19/1995 JLB : Created. *
  3170. *=============================================================================================*/
  3171. void AircraftClass::Set_Speed(int speed)
  3172. {
  3173. assert(Aircraft.ID(this) == ID);
  3174. assert(IsActive);
  3175. FootClass::Set_Speed(speed);
  3176. MPHType sp = MPHType(min(Class->MaxSpeed * SpeedBias * House->AirspeedBias, MPH_LIGHT_SPEED));
  3177. Fly_Speed(speed, sp);
  3178. }
  3179. /***********************************************************************************************
  3180. * AircraftClass::Fire_Direction -- Determines the direction of fire. *
  3181. * *
  3182. * This routine will determine what direction a projectile would take if it were fired *
  3183. * from the aircraft. This is the direction that the aircraft's body is facing. *
  3184. * *
  3185. * INPUT: none *
  3186. * *
  3187. * OUTPUT: Returns with the direction of projectile fire. *
  3188. * *
  3189. * WARNINGS: none *
  3190. * *
  3191. * HISTORY: *
  3192. * 06/19/1995 JLB : Created. *
  3193. *=============================================================================================*/
  3194. DirType AircraftClass::Fire_Direction(void) const
  3195. {
  3196. assert(Aircraft.ID(this) == ID);
  3197. assert(IsActive);
  3198. return(SecondaryFacing.Current());
  3199. }
  3200. /***********************************************************************************************
  3201. * AircraftClass::~AircraftClass -- Destructor for aircraft object. *
  3202. * *
  3203. * This is the destructor for aircraft. It will limbo the aircraft if it isn't already *
  3204. * and also removes the aircraft from any team it may be attached to. *
  3205. * *
  3206. * INPUT: none *
  3207. * *
  3208. * OUTPUT: none *
  3209. * *
  3210. * WARNINGS: none *
  3211. * *
  3212. * HISTORY: *
  3213. * 06/24/1995 JLB : Created. *
  3214. *=============================================================================================*/
  3215. AircraftClass::~AircraftClass(void)
  3216. {
  3217. if (GameActive && Class) {
  3218. /*
  3219. ** Remove this member from any team it may be associated with. This must occur at the
  3220. ** top most level of the inheritance hierarchy because it may call virtual functions.
  3221. */
  3222. if (Team) {
  3223. Team->Remove(this);
  3224. Team = NULL;
  3225. }
  3226. House->Tracking_Remove(this);
  3227. /*
  3228. ** If there are any cargo members, delete them.
  3229. */
  3230. while (Is_Something_Attached()) {
  3231. delete Detach_Object();
  3232. }
  3233. AircraftClass::Limbo();
  3234. Class = 0;
  3235. }
  3236. ID = -1;
  3237. }
  3238. /***********************************************************************************************
  3239. * AircraftClass::Scatter -- Causes the aircraft to move away a bit. *
  3240. * *
  3241. * This routine will cause the aircraft to move away from its current location and then *
  3242. * enter some idle mode. Typically this is called when the aircraft is attacked while on *
  3243. * the ground. *
  3244. * *
  3245. * INPUT: none *
  3246. * *
  3247. * OUTPUT: none *
  3248. * *
  3249. * WARNINGS: none *
  3250. * *
  3251. * HISTORY: *
  3252. * 07/08/1995 JLB : Created. *
  3253. *=============================================================================================*/
  3254. void AircraftClass::Scatter(COORDINATE , bool, bool )
  3255. {
  3256. assert(Aircraft.ID(this) == ID);
  3257. assert(IsActive);
  3258. /*
  3259. ** Certain missions prevent scattering regardless of whether it would be
  3260. ** a good idea or not.
  3261. */
  3262. if (!MissionControl[Mission].IsScatter) return;
  3263. /*
  3264. ** Fixed wing aircraft never scatter.
  3265. */
  3266. if (Class->IsFixedWing) return;
  3267. if (IsLanding || Height == 0) {
  3268. IsLanding = false;
  3269. IsTakingOff = true;
  3270. }
  3271. Enter_Idle_Mode();
  3272. }
  3273. /***********************************************************************************************
  3274. * AircraftClass::Mission_Guard -- Handles aircraft in guard mode. *
  3275. * *
  3276. * Aircraft don't like to be in guard mode if in flight. If this situation is detected, *
  3277. * then figure out what the aircraft should be doing and go do it. *
  3278. * *
  3279. * INPUT: none *
  3280. * *
  3281. * OUTPUT: Returns with the number of game frames to delay before calling this routine again. *
  3282. * *
  3283. * WARNINGS: This routine typically calls the normal guard logic for ground units. *
  3284. * *
  3285. * HISTORY: *
  3286. * 07/18/1995 JLB : Created. *
  3287. * 10/10/1995 JLB : Hunts for harvesters that are unescorted. *
  3288. *=============================================================================================*/
  3289. int AircraftClass::Mission_Guard(void)
  3290. {
  3291. assert(Aircraft.ID(this) == ID);
  3292. assert(IsActive);
  3293. if (Height == FLIGHT_LEVEL) {
  3294. /*
  3295. ** If part of a team, then do nothing, since the team
  3296. ** handler will take care of giving this aircraft a
  3297. ** mission.
  3298. */
  3299. if (Team) {
  3300. if (Target_Legal(NavCom)) {
  3301. Assign_Mission(MISSION_MOVE);
  3302. }
  3303. return(MissionControl[Mission].Normal_Delay());
  3304. }
  3305. if (Class->PrimaryWeapon == NULL) {
  3306. Assign_Destination(::As_Target(Coord_Cell(Coord)));
  3307. Assign_Mission(MISSION_MOVE);
  3308. } else {
  3309. if (!Team.Is_Valid()) Enter_Idle_Mode();
  3310. }
  3311. return(1);
  3312. }
  3313. if (House->IsHuman) return(MissionControl[Mission].Normal_Delay());
  3314. /*
  3315. ** If the aircraft is very badly damaged, then it will search for a
  3316. ** repair bay first.
  3317. */
  3318. if (House->Available_Money() >= 100 && Health_Ratio() <= Rule.ConditionYellow) {
  3319. if (!In_Radio_Contact() ||
  3320. (Height == 0 &&
  3321. (Contact_With_Whom()->What_Am_I() != RTTI_BUILDING || *((BuildingClass *)Contact_With_Whom()) != STRUCT_REPAIR))) {
  3322. BuildingClass * building = Find_Docking_Bay(STRUCT_REPAIR, true);
  3323. if (building != NULL) {
  3324. Assign_Destination(building->As_Target());
  3325. Assign_Target(TARGET_NONE);
  3326. Assign_Mission(MISSION_ENTER);
  3327. return(1);
  3328. }
  3329. }
  3330. }
  3331. /*
  3332. ** If the aircraft cannot attack anything because of lack of ammo,
  3333. ** abort any normal guard logic in order to look for a helipad
  3334. ** to rearm.
  3335. */
  3336. if (Ammo == 0 && Is_Weapon_Equipped()) {
  3337. if (!In_Radio_Contact()) {
  3338. BuildingClass * building = Find_Docking_Bay(STRUCT_HELIPAD, false);
  3339. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  3340. if (!Class->IsFixedWing) {
  3341. int dist = 0x7FFFFFFF;
  3342. if (building) dist=Distance(building);
  3343. for (int index = 0; index < Vessels.Count(); index++) {
  3344. VesselClass *ship = Vessels.Ptr(index);
  3345. if (ship != NULL && *ship == VESSEL_CARRIER && !ship->IsInLimbo && ship->IsActive && ship->House == House && ship->How_Many() < ship->Class->Max_Passengers()) {
  3346. if (Distance(ship) < dist || !building) {
  3347. building = (BuildingClass *)ship;
  3348. dist = Distance(ship);
  3349. }
  3350. // break;
  3351. }
  3352. }
  3353. }
  3354. #endif
  3355. if (building != NULL) {
  3356. Assign_Destination(building->As_Target());
  3357. Assign_Target(TARGET_NONE);
  3358. Assign_Mission(MISSION_ENTER);
  3359. return(1);
  3360. }
  3361. }
  3362. }
  3363. /*
  3364. ** If the aircraft already has a target, then attack it if possible.
  3365. */
  3366. if (Target_Legal(TarCom)) {
  3367. Assign_Mission(MISSION_ATTACK);
  3368. return(1);
  3369. }
  3370. /*
  3371. ** Transport helicopters don't really do anything but just sit there.
  3372. */
  3373. if (!Is_Weapon_Equipped()) {
  3374. return(TICKS_PER_SECOND*3);
  3375. }
  3376. /*
  3377. ** Computer controlled helicopters will defend themselves by bouncing around
  3378. ** and looking for a free helipad.
  3379. */
  3380. if (Height == 0 && !In_Radio_Contact()) {
  3381. Scatter(0, true);
  3382. return(TICKS_PER_SECOND*3);
  3383. }
  3384. /*
  3385. ** Perform a special check to hunt for harvesters that are outside of the protective
  3386. ** shield of their base.
  3387. */
  3388. if (House->State != STATE_ATTACKED) {
  3389. TARGET target = House->Find_Juicy_Target(Coord);
  3390. if (Target_Legal(target)) {
  3391. Assign_Target(target);
  3392. Assign_Mission(MISSION_ATTACK);
  3393. }
  3394. }
  3395. return(FootClass::Mission_Guard());
  3396. }
  3397. /***********************************************************************************************
  3398. * AircraftClass::Mission_Guard_Area -- Handles the aircraft guard area logic. *
  3399. * *
  3400. * This routine handles area guard logic for aircraft. Aircraft require special handling *
  3401. * for this mode since they are to guard area only if they are in a position to do so. *
  3402. * Otherwise they just defend themselves. *
  3403. * *
  3404. * INPUT: none *
  3405. * *
  3406. * OUTPUT: Returns with the number of game frames to delay before calling this routine *
  3407. * again. *
  3408. * *
  3409. * WARNINGS: none *
  3410. * *
  3411. * HISTORY: *
  3412. * 08/10/1995 JLB : Created. *
  3413. *=============================================================================================*/
  3414. int AircraftClass::Mission_Guard_Area(void)
  3415. {
  3416. assert(Aircraft.ID(this) == ID);
  3417. assert(IsActive);
  3418. if (Height == FLIGHT_LEVEL) {
  3419. if (!Team.Is_Valid()) Enter_Idle_Mode();
  3420. return(1);
  3421. }
  3422. if (House->IsHuman) return(TICKS_PER_SECOND);
  3423. if (Height == 0 && !In_Radio_Contact()) {
  3424. Scatter(0, true);
  3425. return(TICKS_PER_SECOND*3);
  3426. }
  3427. if (Target_Legal(TarCom)) {
  3428. Assign_Mission(MISSION_ATTACK);
  3429. return(1);
  3430. }
  3431. return(FootClass::Mission_Guard_Area());
  3432. }
  3433. /***********************************************************************************************
  3434. * AircraftClass::Response_Attack -- Gives audio response to attack order. *
  3435. * *
  3436. * This routine is used to give an audio response to an attack order. *
  3437. * *
  3438. * INPUT: none *
  3439. * *
  3440. * OUTPUT: none *
  3441. * *
  3442. * WARNINGS: none *
  3443. * *
  3444. * HISTORY: *
  3445. * 08/10/1995 JLB : Created. *
  3446. *=============================================================================================*/
  3447. void AircraftClass::Response_Attack(void)
  3448. {
  3449. assert(Aircraft.ID(this) == ID);
  3450. assert(IsActive);
  3451. static VocType _response[] = {
  3452. VOC_AFFIRM,
  3453. VOC_ACKNOWL
  3454. };
  3455. VocType response = _response[Sim_Random_Pick(0, ARRAY_SIZE(_response)-1)];
  3456. if (AllowVoice) {
  3457. Sound_Effect(response, fixed(1), -(ID+1));
  3458. }
  3459. }
  3460. /***********************************************************************************************
  3461. * AircraftClass::Response_Move -- Gives audio response to move request. *
  3462. * *
  3463. * This routine is used to give an audio response to movement orders. *
  3464. * *
  3465. * INPUT: none *
  3466. * *
  3467. * OUTPUT: none *
  3468. * *
  3469. * WARNINGS: none *
  3470. * *
  3471. * HISTORY: *
  3472. * 08/10/1995 JLB : Created. *
  3473. *=============================================================================================*/
  3474. void AircraftClass::Response_Move(void)
  3475. {
  3476. assert(Aircraft.ID(this) == ID);
  3477. assert(IsActive);
  3478. static VocType _response[] = {
  3479. VOC_ACKNOWL,
  3480. VOC_AFFIRM
  3481. };
  3482. VocType response = _response[Sim_Random_Pick(0, ARRAY_SIZE(_response)-1)];
  3483. if (AllowVoice) {
  3484. Sound_Effect(response, fixed(1), -(ID+1));
  3485. }
  3486. }
  3487. /***********************************************************************************************
  3488. * AircraftClass::Response_Select -- Gives audio response when selected. *
  3489. * *
  3490. * This routine is called when an audio response for selection is desired. *
  3491. * *
  3492. * INPUT: none *
  3493. * *
  3494. * OUTPUT: none *
  3495. * *
  3496. * WARNINGS: none *
  3497. * *
  3498. * HISTORY: *
  3499. * 08/10/1995 JLB : Created. *
  3500. *=============================================================================================*/
  3501. void AircraftClass::Response_Select(void)
  3502. {
  3503. assert(Aircraft.ID(this) == ID);
  3504. assert(IsActive);
  3505. static VocType _response[] = {
  3506. VOC_VEHIC,
  3507. VOC_REPORT,
  3508. VOC_YESSIR,
  3509. VOC_YESSIR,
  3510. VOC_YESSIR,
  3511. VOC_AWAIT
  3512. };
  3513. VocType response = _response[Sim_Random_Pick(0, ARRAY_SIZE(_response)-1)];
  3514. if (AllowVoice) {
  3515. Sound_Effect(response, fixed(1), -(ID+1));
  3516. }
  3517. }
  3518. /***********************************************************************************************
  3519. * AircraftClass::Can_Fire -- Checks to see if the aircraft can fire. *
  3520. * *
  3521. * This routine is used to determine if the aircraft can fire its weapon at the target *
  3522. * specified. If it cannot, then the reason why is returned. *
  3523. * *
  3524. * INPUT: target -- The target that the aircraft might fire upon. *
  3525. * *
  3526. * which -- The weapon that will be used to fire. *
  3527. * *
  3528. * OUTPUT: Returns with the reason why it can't fire or with FIRE_OK. *
  3529. * *
  3530. * WARNINGS: none *
  3531. * *
  3532. * HISTORY: *
  3533. * 03/05/1996 JLB : Created. *
  3534. * 07/11/1996 JLB : Fixed for camera carrying aircraft. *
  3535. *=============================================================================================*/
  3536. FireErrorType AircraftClass::Can_Fire(TARGET target, int which) const
  3537. {
  3538. assert(Aircraft.ID(this) == ID);
  3539. assert(IsActive);
  3540. if (Passenger && !Is_Something_Attached()) {
  3541. return(FIRE_AMMO);
  3542. }
  3543. bool camera = (Class->PrimaryWeapon != NULL && Class->PrimaryWeapon->IsCamera);
  3544. bool fudge = (Passenger || (Class->PrimaryWeapon != NULL && Class->PrimaryWeapon->Bullet != NULL && Class->PrimaryWeapon->Bullet->IsParachuted));
  3545. if (fudge && !camera && !Ammo && !Passenger) {
  3546. return(FIRE_AMMO);
  3547. }
  3548. /*
  3549. ** Passenger aircraft that wish to 'fire' actually are requesting to
  3550. ** paradrop or 'throw out' the cargo. This is always allowed if the terrain under the
  3551. ** aircraft is generally clear.
  3552. */
  3553. if (camera || (fudge && Passenger && Is_Something_Attached())) {
  3554. if (Arm != 0) return(FIRE_REARM);
  3555. if (Distance(target) < (camera ? 0x0380 : 0x0200) && Map.In_Radar(Coord_Cell(Center_Coord()))) {
  3556. // if (Distance(target) < (camera ? 0x0380 : 0x0280) && Map.In_Radar(Coord_Cell(Center_Coord()))) {
  3557. return(FIRE_OK);
  3558. }
  3559. return(FIRE_RANGE);
  3560. }
  3561. FireErrorType canfire = FootClass::Can_Fire(target, which);
  3562. if (canfire == FIRE_OK) {
  3563. /*
  3564. ** Double check to make sure that the facing is roughly toward
  3565. ** the target. If the difference is too great, then firing is
  3566. ** temporarily postponed.
  3567. */
  3568. if (Class->IsFixedWing) {
  3569. int diff = PrimaryFacing.Difference(Direction(TarCom));
  3570. if (ABS(diff) > (fudge ? 16 : 8)) {
  3571. return(FIRE_FACING);
  3572. }
  3573. }
  3574. }
  3575. return(canfire);
  3576. }
  3577. /***********************************************************************************************
  3578. * AircraftClass::Landing_Takeoff_AI -- Handle aircraft take off and landing processing. *
  3579. * *
  3580. * This routine handles the tricky maneuver of taking off and landing. The process of *
  3581. * landing is not entirely safe and thus the aircraft may be destroyed as a consequence. *
  3582. * *
  3583. * INPUT: none *
  3584. * *
  3585. * OUTPUT: bool; Was the aircraft destroyed by this process? *
  3586. * *
  3587. * WARNINGS: Only call this routine once per aircraft per game logic loop. Be sure to *
  3588. * examine the return value and if true, abort all further processing of this *
  3589. * aircraft since it is now dead. *
  3590. * *
  3591. * HISTORY: *
  3592. * 07/29/1996 JLB : Created. *
  3593. *=============================================================================================*/
  3594. bool AircraftClass::Landing_Takeoff_AI(void)
  3595. {
  3596. /*
  3597. ** Handle landing and taking off logic. Helicopters are prime users of this technique. The
  3598. ** aircraft will either gain or lose altitude as appropriate. As the aircraft transitions
  3599. ** between flying level and ground level, it will be moved into the appropriate render
  3600. ** layer.
  3601. */
  3602. if (Is_Door_Closed() && (IsLanding || IsTakingOff)) {
  3603. LayerType layer = In_Which_Layer();
  3604. if (IsLanding) {
  3605. Mark(MARK_UP);
  3606. if (Height) Height -= Pixel_To_Lepton(1);
  3607. if (Height <= 0) {
  3608. Height = 0;
  3609. IsLanding = false;
  3610. Set_Speed(0);
  3611. /*
  3612. ** If the NavCom now equals the destination, then clear out the NavCom.
  3613. */
  3614. if (Coord_Cell(Center_Coord()) == As_Cell(NavCom)) {
  3615. Assign_Destination(TARGET_NONE);
  3616. }
  3617. /*
  3618. ** If a fixed-wing aircraft just landed on the ground, blow him up
  3619. */
  3620. if (Class->IsFixedWing && Mission != MISSION_ENTER) {
  3621. Strength = 1;
  3622. int damage = Strength;
  3623. Map.Remove(this, layer);
  3624. Take_Damage(damage, 0, WARHEAD_AP, 0, true);
  3625. return(true);
  3626. }
  3627. if (Target_Legal(NavCom) && As_Techno(NavCom) == Contact_With_Whom()) {
  3628. if (In_Radio_Contact() && Transmit_Message(RADIO_IM_IN) != RADIO_ROGER) {
  3629. Scatter(0, true);
  3630. }
  3631. }
  3632. }
  3633. Mark(MARK_DOWN);
  3634. }
  3635. if (IsTakingOff) {
  3636. Mark(MARK_UP);
  3637. // Map.Remove(this, layer);
  3638. Height += Pixel_To_Lepton(1);
  3639. if (Height >= FLIGHT_LEVEL) {
  3640. Height = FLIGHT_LEVEL;
  3641. IsTakingOff = false;
  3642. }
  3643. // Map.Submit(this, In_Which_Layer());
  3644. Mark(MARK_DOWN);
  3645. }
  3646. /*
  3647. ** Make adjustments for altitude by moving from one layer to another as
  3648. ** necessary.
  3649. */
  3650. if (layer != In_Which_Layer()) {
  3651. /*
  3652. ** When the aircraft is about to enter the ground layer, perform on last
  3653. ** check to see if it is legal to enter that location. If not, then
  3654. ** start the take off process. Let the normal logic handle this
  3655. ** change of plans.
  3656. */
  3657. bool ok = true;
  3658. if (In_Which_Layer() == LAYER_GROUND && !IsTakingOff && !Class->IsFixedWing) {
  3659. if (!Is_LZ_Clear(::As_Target(Coord_Cell(Coord)))) {
  3660. IsTakingOff = true;
  3661. Mark(MARK_UP);
  3662. Height += Pixel_To_Lepton(1);
  3663. Mark(MARK_DOWN);
  3664. ok = false;
  3665. }
  3666. }
  3667. if (ok) {
  3668. Map.Remove(this, layer);
  3669. Map.Submit(this, In_Which_Layer());
  3670. /*
  3671. ** When the aircraft is close to the ground, it should exist as a ground object.
  3672. ** This aspect is controlled by the Place_Down and Pick_Up functions.
  3673. */
  3674. if (In_Which_Layer() == LAYER_GROUND) {
  3675. Assign_Destination(TARGET_NONE); // Clear the navcom.
  3676. Transmit_Message(RADIO_TETHER);
  3677. Look();
  3678. // Map.Sight_From(Coord_Cell(Coord), 1, House, false);
  3679. } else {
  3680. Transmit_Message(RADIO_UNTETHER);
  3681. /*
  3682. ** If the navigation computer is not attached to the object this
  3683. ** aircraft is in radio contact with, then assume that radio
  3684. ** contact is now superfluous. Break radio contact.
  3685. */
  3686. if (In_Radio_Contact() && Target_Legal(NavCom) && NavCom != Contact_With_Whom()->As_Target()) {
  3687. Transmit_Message(RADIO_OVER_OUT);
  3688. }
  3689. }
  3690. }
  3691. }
  3692. }
  3693. return(false);
  3694. }
  3695. /***********************************************************************************************
  3696. * AircraftClass::Edge_Of_World_AI -- Detect if aircraft has exited the map. *
  3697. * *
  3698. * Certain aircraft will be eliminated when they leave the edge of the world presumably *
  3699. * after completing their mission. An exception is for aircraft that have been newly *
  3700. * created as reinforcements and have not yet completed their mission. *
  3701. * *
  3702. * INPUT: none *
  3703. * *
  3704. * OUTPUT: bool; Was the aircraft deleted by this routine? *
  3705. * *
  3706. * WARNINGS: Be sure to call this routine only once per aircraft per game logic loop. If *
  3707. * the return value is true, then abort any further processing of this aircraft *
  3708. * since it has been eliminated. *
  3709. * *
  3710. * HISTORY: *
  3711. * 07/29/1996 JLB : Created. *
  3712. *=============================================================================================*/
  3713. bool AircraftClass::Edge_Of_World_AI(void)
  3714. {
  3715. if (!Map.In_Radar(Coord_Cell(Coord))) {
  3716. if (Mission == MISSION_RETREAT /*|| (*this == AIRCRAFT_CARGO && !Is_Something_Attached())*/) {
  3717. /*
  3718. ** Check to see if there are any civilians aboard. If so, then flag the house
  3719. ** that the civilian evacuation trigger event has been fulfilled.
  3720. */
  3721. while (Is_Something_Attached()) {
  3722. FootClass * obj = Detach_Object();
  3723. /*
  3724. ** Flag the owning house that civ evacuation has occurred.
  3725. */
  3726. if (_Counts_As_Civ_Evac(obj)) {
  3727. obj->House->IsCivEvacuated = true;
  3728. }
  3729. if (obj->Team.Is_Valid()) obj->Team->IsLeaveMap = true;
  3730. #ifdef OLD
  3731. /*
  3732. ** Transport planes that leave can only be because they carry purchased
  3733. ** equipment and must be have their cost refunded.
  3734. */
  3735. if (*this == AIRCRAFT_CARGO) {
  3736. House->Refund_Money(obj->Class_Of().Cost_Of());
  3737. }
  3738. #endif
  3739. delete obj;
  3740. }
  3741. if (Team.Is_Valid()) {
  3742. Team->IsLeaveMap = true;
  3743. }
  3744. Stun();
  3745. delete this;
  3746. return(true);
  3747. }
  3748. } else {
  3749. IsLocked = true;
  3750. }
  3751. return(false);
  3752. }
  3753. /***********************************************************************************************
  3754. * AircraftClass::Movement_AI -- Handles aircraft physical movement logic. *
  3755. * *
  3756. * This routine manages the aircraft movement across the map. If any movement occurred, the *
  3757. * aircraft will be flagged to be redrawn. *
  3758. * *
  3759. * INPUT: none *
  3760. * *
  3761. * OUTPUT: none *
  3762. * *
  3763. * WARNINGS: Only call this routine once per aircraft per game logic loop. *
  3764. * *
  3765. * HISTORY: *
  3766. * 07/29/1996 JLB : Created. *
  3767. *=============================================================================================*/
  3768. void AircraftClass::Movement_AI(void)
  3769. {
  3770. /*
  3771. ** If for some strange reason, there is a valid NavCom, but this aircraft is not
  3772. ** in a movement order, then give it a movement order.
  3773. */
  3774. if (Target_Legal(NavCom) && Mission == MISSION_GUARD && MissionQueue == MISSION_NONE) {
  3775. Assign_Mission(MISSION_MOVE);
  3776. }
  3777. if (Speed != 0) {
  3778. if (In_Which_Layer() == LAYER_GROUND) {
  3779. Mark(MARK_UP);
  3780. Physics(Coord, PrimaryFacing);
  3781. Mark(MARK_DOWN);
  3782. } else {
  3783. Mark(MARK_CHANGE_REDRAW);
  3784. if (Physics(Coord, PrimaryFacing) != RESULT_NONE) {
  3785. Mark(MARK_CHANGE_REDRAW);
  3786. }
  3787. }
  3788. }
  3789. }
  3790. /***********************************************************************************************
  3791. * AircraftClass::Rotation_AI -- Handle aircraft body and flight rotation. *
  3792. * *
  3793. * This will process the aircraft visible body and flight model rotation operations. If *
  3794. * any rotation occurred, the aircraft will be flagged to be redrawn. *
  3795. * *
  3796. * INPUT: none *
  3797. * *
  3798. * OUTPUT: none *
  3799. * *
  3800. * WARNINGS: Only call this routine once per aircraft per game logic loop. *
  3801. * *
  3802. * HISTORY: *
  3803. * 07/29/1996 JLB : Created. *
  3804. *=============================================================================================*/
  3805. void AircraftClass::Rotation_AI(void)
  3806. {
  3807. if (PrimaryFacing.Is_Rotating()) {
  3808. Mark(MARK_CHANGE_REDRAW);
  3809. if (PrimaryFacing.Rotation_Adjust(Class->ROT)) {
  3810. Mark(MARK_CHANGE_REDRAW);
  3811. }
  3812. }
  3813. if (Class->IsFixedWing) {
  3814. SecondaryFacing = PrimaryFacing;
  3815. }
  3816. if (SecondaryFacing.Is_Rotating()) {
  3817. Mark(MARK_CHANGE_REDRAW);
  3818. if (SecondaryFacing.Rotation_Adjust(Class->ROT)) {
  3819. Mark(MARK_CHANGE_REDRAW);
  3820. }
  3821. }
  3822. }
  3823. /***********************************************************************************************
  3824. * AircraftClass::Per_Cell_Process -- Handle the aircraft per cell process. *
  3825. * *
  3826. * This is a seldom used function since its only purpose is to be called when an aircraft *
  3827. * lands on the ground. *
  3828. * *
  3829. * INPUT: why -- Why was this per cell process function called. *
  3830. * *
  3831. * OUTPUT: none *
  3832. * *
  3833. * WARNINGS: none *
  3834. * *
  3835. * HISTORY: *
  3836. * 09/15/1996 JLB : Created. *
  3837. *=============================================================================================*/
  3838. void AircraftClass::Per_Cell_Process(PCPType why)
  3839. {
  3840. BStart(BENCH_PCP);
  3841. FootClass::Per_Cell_Process(why);
  3842. BEnd(BENCH_PCP);
  3843. }
  3844. /***********************************************************************************************
  3845. * AircraftClass::Assign_Destination -- Assigns movement destination to the object. *
  3846. * *
  3847. * This routine is called when the object needs to have a new movement destination *
  3848. * assigned. Aircraft have their own version of this routine because a fixed-wing plane *
  3849. * trying to land will behave poorly if given a new destinatio while it's landing. * *
  3850. * *
  3851. * INPUT: destination -- The destination to assign to this object. *
  3852. * *
  3853. * OUTPUT: none *
  3854. * *
  3855. * WARNINGS: none *
  3856. * *
  3857. * HISTORY: *
  3858. * 07/24/1995 JLB : Created. *
  3859. *=============================================================================================*/
  3860. void AircraftClass::Assign_Destination(TARGET dest)
  3861. {
  3862. assert(IsActive);
  3863. if (dest == NavCom) return;
  3864. if (Target_Legal(dest) && Class->IsFixedWing && (IsLanding || (Target_Legal(NavCom) && dest != NavCom))) {
  3865. // if (Target_Legal(dest) /*&& Class->IsFixedWing*/ && (IsLanding || (Target_Legal(NavCom) && dest != NavCom))) {
  3866. // if (Class->IsFixedWing || As_Cell(dest) != Coord_Cell(Center_Coord())) {
  3867. Process_Take_Off();
  3868. Status = 0;
  3869. // }
  3870. }
  3871. FootClass::Assign_Destination(dest);
  3872. }
  3873. /***********************************************************************************************
  3874. * AircraftClass::In_Which_Layer -- Calculates the display layer of the aircraft. *
  3875. * *
  3876. * This examines the aircraft to determine what display layer it should be located *
  3877. * in. Fixed wing aircraft must always be in the top layer if they are flying even though *
  3878. * they may be low to the ground. *
  3879. * *
  3880. * INPUT: none *
  3881. * *
  3882. * OUTPUT: Returns with the layer that this aircraft resides in. *
  3883. * *
  3884. * WARNINGS: none *
  3885. * *
  3886. * HISTORY: *
  3887. * 10/20/1996 JLB : Created. *
  3888. *=============================================================================================*/
  3889. LayerType AircraftClass::In_Which_Layer(void) const
  3890. {
  3891. if (Class->IsFixedWing && Height > 0) {
  3892. return(LAYER_TOP);
  3893. }
  3894. return(FootClass::In_Which_Layer());
  3895. }
  3896. /***********************************************************************************************
  3897. * AircraftClass::Look -- Aircraft will look if they are on the ground always. *
  3898. * *
  3899. * Aircraft perform a look operation according to their sight range. If the aircraft is *
  3900. * on the ground, then it will look a distance of one cell regardless of what its *
  3901. * specified sight range is. *
  3902. * *
  3903. * INPUT: incremental -- Is this an incremental look? *
  3904. * *
  3905. * OUTPUT: none *
  3906. * *
  3907. * WARNINGS: none *
  3908. * *
  3909. * HISTORY: *
  3910. * 10/23/1996 JLB : Created. *
  3911. *=============================================================================================*/
  3912. void AircraftClass::Look(bool incremental)
  3913. {
  3914. assert(IsActive);
  3915. assert(!IsInLimbo);
  3916. int sight_range = Techno_Type_Class()->SightRange;
  3917. if (Height == 0) {
  3918. sight_range = 1;
  3919. }
  3920. if (sight_range) {
  3921. Map.Sight_From(Coord_Cell(Coord), sight_range, House, incremental);
  3922. }
  3923. }
  3924. unsigned AircraftClass::Spied_By() const
  3925. {
  3926. unsigned spiedby = FootClass::Spied_By();
  3927. /*
  3928. ** Aircraft inherit the spied by flags of the helipad they've landed on
  3929. */
  3930. BuildingClass* building = Map[Coord].Cell_Building();
  3931. if ((Height == 0) && In_Radio_Contact() && (building == Contact_With_Whom())) {
  3932. spiedby |= building->Spied_By();
  3933. }
  3934. return spiedby;
  3935. }