AIRCRAFT.CPP 179 KB

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