INFANTRY.CPP 167 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150
  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/INFANTRY.CPP 2 3/03/97 10:35p 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 : INFANTRY.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : August 15, 1994 *
  30. * *
  31. * Last Update : October 28, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * InfantryClass::AI -- Handles the infantry non-graphic related AI processing. *
  36. * InfantryClass::Active_Click_With -- Handles action when clicking with infantry soldier. *
  37. * InfantryClass::Assign_Destination -- Gives the infantry a movement destination. *
  38. * InfantryClass::Assign_Target -- Gives the infantry a combat target. *
  39. * InfantryClass::Can_Enter_Cell -- Determines if the infantry can enter the cell specified. *
  40. * InfantryClass::Can_Fire -- Can the infantry fire its weapon? *
  41. * InfantryClass::Class_Of -- Returns the class reference for this object. *
  42. * InfantryClass::Clear_Occupy_Bit -- Clears occupy bit and given cell *
  43. * InfantryClass::Debug_Dump -- Displays debug information about infantry unit. *
  44. * InfantryClass::Detach -- Removes the specified target from targeting computer. *
  45. * InfantryClass::Do_Action -- Launches the infantry into an animation sequence. *
  46. * InfantryClass::Doing_AI -- Handles the animation AI processing. *
  47. * InfantryClass::Draw_It -- Draws a unit object. *
  48. * InfantryClass::Edge_Of_World_AI -- Detects when infantry has left the map. *
  49. * InfantryClass::Enter_Idle_Mode -- The infantry unit enters idle mode by this routine. *
  50. * InfantryClass::Fear_AI -- Process any fear related affects on this infantry. *
  51. * InfantryClass::Fire_At -- Fires projectile from infantry unit. *
  52. * InfantryClass::Firing_AI -- Handles firing and combat AI for the infantry. *
  53. * InfantryClass::Full_Name -- Fetches the full name of the infantry unit. *
  54. * InfantryClass::Get_Image_Data -- Fetches the image data for this infantry unit. *
  55. * InfantryClass::Greatest_Threat -- Determines greatest threat (target) for infantry unit. *
  56. * InfantryClass::InfantryClass -- The constructor for infantry objects. *
  57. * InfantryClass::Init -- Initialize the infantry object system. *
  58. * InfantryClass::Is_Ready_To_Random_Anima -- Checks to see if it is ready to perform an idle*
  59. * InfantryClass::Limbo -- Performs cleanup operations needed when limboing. *
  60. * InfantryClass::Mission_Attack -- Intercept attack mission for special handling. *
  61. * InfantryClass::Movement_AI -- This routine handles all infantry movement logic. *
  62. * InfantryClass::Overlap_List -- The list of cells that the infantry overlaps, but doesn't o*
  63. * InfantryClass::Paradrop -- Handles paradropping infantry. *
  64. * InfantryClass::Per_Cell_Process -- Handles special operations that occur once per cell. *
  65. * InfantryClass::Random_Animate -- Randomly animate the infantry (maybe) *
  66. * InfantryClass::Read_INI -- Reads units from scenario INI file. *
  67. * InfantryClass::Response_Attack -- Plays infantry audio response to attack order. *
  68. * InfantryClass::Response_Move -- Plays infantry response to movement order. *
  69. * InfantryClass::Response_Select -- Plays infantry audio response due to being selected. *
  70. * InfantryClass::Scatter -- Causes the infantry to scatter to nearby cell. *
  71. * InfantryClass::Set_Occupy_Bit -- Sets the occupy bit cell and bit pos *
  72. * InfantryClass::Set_Primary_Facing -- Change infantry primary facing -- always and instantl*
  73. * InfantryClass::Shape_Number -- Fetch the shape number for this infantry. *
  74. * InfantryClass::Start_Driver -- Handles giving immediate destination and move orders. *
  75. * InfantryClass::Stop_Driver -- Stops the infantry from moving any further. *
  76. * InfantryClass::Take_Damage -- Applies damage to the infantry unit. *
  77. * InfantryClass::Unlimbo -- Unlimbo infantry unit in legal sub-location. *
  78. * InfantryClass::What_Action -- Determines what action to perform for the cell specified. *
  79. * InfantryClass::What_Action -- Infantry units might be able to capture -- check. *
  80. * InfantryClass::Write_INI -- Store the infantry to the INI database. *
  81. * InfantryClass::operator delete -- Returns the infantry object back to the free pool *
  82. * InfantryClass::operator new -- Allocates an infantry object from the free pool. *
  83. * InfantryClass::~InfantryClass -- Default destructor for infantry units. *
  84. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  85. #include "function.h"
  86. int const InfantryClass::HumanShape[32] = {0,0,7,7,7,7,6,6,6,6,5,5,5,5,5,4,4,4,3,3,3,3,2,2,2,2,1,1,1,1,1,0};
  87. /***************************************************************************
  88. ** This is the array of constant data associated with infantry maneuvers. It
  89. ** specifies the frame rate as well as if the animation can be aborted.
  90. */
  91. // interruptible, mobile, randomstart, rate
  92. DoStruct const InfantryClass::MasterDoControls[DO_COUNT] = {
  93. {true, false, false, 0}, // DO_STAND_READY
  94. {true, false, false, 0}, // DO_STAND_GUARD
  95. {true, false, false, 0}, // DO_PRONE
  96. {true, true, true, 2}, // DO_WALK
  97. {true, false, false, 1}, // DO_FIRE_WEAPON
  98. {false, true, false, 2}, // DO_LIE_DOWN
  99. {true, true, true, 2}, // DO_CRAWL
  100. {false, false, false, 3}, // DO_GET_UP
  101. {true, false, false, 1}, // DO_FIRE_PRONE
  102. {true, false, false, 2}, // DO_IDLE1
  103. {true, false, false, 2}, // DO_IDLE2
  104. {false, false, false, 2}, // DO_GUN_DEATH
  105. {false, false, false, 2}, // DO_EXPLOSION_DEATH
  106. {false, false, false, 2}, // DO_EXPLOSION2_DEATH
  107. {false, false, false, 2}, // DO_GRENADE_DEATH
  108. {false, false, false, 2}, // DO_FIRE_DEATH
  109. {false, false, false, 2}, // DO_GESTURE1
  110. {false, false, false, 2}, // DO_SALUTE1
  111. {false, false, false, 2}, // DO_GESTURE2
  112. {false, false, false, 2}, // DO_SALUTE2
  113. {false, false, false, 2}, // DO_DOG_MAUL
  114. };
  115. #ifdef CHEAT_KEYS
  116. /***********************************************************************************************
  117. * InfantryClass::Debug_Dump -- Displays debug information about infantry unit. *
  118. * *
  119. * This routine is used by the debug version to display pertinent information about the *
  120. * infantry unit. *
  121. * *
  122. * INPUT: mono -- The monochrome screen to display the debug information to. *
  123. * *
  124. * OUTPUT: none *
  125. * *
  126. * WARNINGS: none *
  127. * *
  128. * HISTORY: *
  129. * 09/01/1994 JLB : Created. *
  130. *=============================================================================================*/
  131. void InfantryClass::Debug_Dump(MonoClass * mono) const
  132. {
  133. assert(Infantry.ID(this) == ID);
  134. assert(IsActive);
  135. mono->Set_Cursor(0, 0);
  136. mono->Print(Text_String(TXT_DEBUG_INFANTRY));
  137. mono->Set_Cursor(1, 11);mono->Printf("%3d", Doing);
  138. mono->Set_Cursor(8, 11);mono->Printf("%3d", Fear);
  139. mono->Fill_Attrib(66, 13, 12, 1, IsTechnician ? MonoClass::INVERSE : MonoClass::NORMAL);
  140. mono->Fill_Attrib(66, 14, 12, 1, IsStoked ? MonoClass::INVERSE : MonoClass::NORMAL);
  141. mono->Fill_Attrib(66, 15, 12, 1, IsProne ? MonoClass::INVERSE : MonoClass::NORMAL);
  142. FootClass::Debug_Dump(mono);
  143. }
  144. #endif
  145. /***********************************************************************************************
  146. * InfantryClass::InfantryClass -- The constructor for infantry objects. *
  147. * *
  148. * This is the constructor used when creating an infantry unit. All values are required *
  149. * except for facing and position. If these are absent, then the infantry is created in *
  150. * a state of limbo -- not placed upon the map. *
  151. * *
  152. * INPUT: see below... *
  153. * *
  154. * OUTPUT: none *
  155. * *
  156. * WARNINGS: none *
  157. * *
  158. * HISTORY: *
  159. * 09/01/1994 JLB : Created. *
  160. *=============================================================================================*/
  161. InfantryClass::InfantryClass(InfantryType classid, HousesType house) :
  162. FootClass(RTTI_INFANTRY, Infantry.ID(this), house),
  163. Class(InfantryTypes.Ptr((int)classid)),
  164. Doing(DO_NOTHING),
  165. Comment(0),
  166. IsTechnician(false),
  167. IsStoked(false),
  168. IsProne(false),
  169. IsZoneCheat(false),
  170. WasSelected(false),
  171. Fear(FEAR_NONE)
  172. {
  173. House->Tracking_Add(this);
  174. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  175. IsCloakable = Class->IsCloakable;
  176. #endif
  177. /*
  178. ** For two shooters, clear out the second shot flag -- it will be set the first time
  179. ** the object fires. For non two shooters, set the flag since it will never be cleared
  180. ** and the second shot flag tells the system that normal rearm times apply -- this is
  181. ** what is desired for non two shooters.
  182. */
  183. if (Class->Is_Two_Shooter()) {
  184. IsSecondShot = false;
  185. } else {
  186. IsSecondShot = true;
  187. }
  188. Strength = Class->MaxStrength;
  189. /*
  190. ** Civilians carry much less ammo than soldiers do.
  191. */
  192. Ammo = Class->MaxAmmo;
  193. }
  194. /***********************************************************************************************
  195. * InfantryClass::~InfantryClass -- Default destructor for infantry units. *
  196. * *
  197. * This is the default destructor for infantry type units. It will put the infantry into *
  198. * a limbo state if it isn't already in that state and the game is still active. *
  199. * *
  200. * INPUT: none *
  201. * *
  202. * OUTPUT: none *
  203. * *
  204. * WARNINGS: none *
  205. * *
  206. * HISTORY: *
  207. * 01/10/1995 JLB : Created. *
  208. *=============================================================================================*/
  209. InfantryClass::~InfantryClass(void)
  210. {
  211. if (GameActive && Class.Is_Valid()) {
  212. /*
  213. ** Remove this member from any team it may be associated with. This must occur at the
  214. ** top most level of the inheritance hierarchy because it may call virtual functions.
  215. */
  216. if (Team.Is_Valid()) {
  217. Team->Remove(this);
  218. Team = NULL;
  219. }
  220. House->Tracking_Remove(this);
  221. Limbo();
  222. }
  223. ID = -1;
  224. }
  225. /***********************************************************************************************
  226. * InfantryClass::operator new -- Allocates an infantry object from the free pool. *
  227. * *
  228. * This will allocate an infantry object from the infantry object free pool. If there is *
  229. * no available slot, then NULL is returned. *
  230. * *
  231. * INPUT: none *
  232. * *
  233. * OUTPUT: Returns with a pointer to the allocated infantry object or NULL if none could be *
  234. * allocated. *
  235. * *
  236. * WARNINGS: none *
  237. * *
  238. * HISTORY: *
  239. * 09/01/1994 JLB : Created. *
  240. *=============================================================================================*/
  241. void * InfantryClass::operator new(size_t)
  242. {
  243. void * ptr = Infantry.Allocate();
  244. if (ptr != NULL) {
  245. ((InfantryClass *)ptr)->IsActive = true;
  246. }
  247. return(ptr);
  248. }
  249. /***********************************************************************************************
  250. * InfantryClass::operator delete -- Returns the infantry object back to the free pool *
  251. * *
  252. * This routine is used return an infantry object back to the system. *
  253. * *
  254. * INPUT: ptr -- Pointer to the infantry object to delete. *
  255. * *
  256. * OUTPUT: none *
  257. * *
  258. * WARNINGS: none *
  259. * *
  260. * HISTORY: *
  261. * 09/08/1994 JLB : Created. *
  262. *=============================================================================================*/
  263. void InfantryClass::operator delete(void * ptr)
  264. {
  265. if (ptr != NULL) {
  266. ((InfantryClass *)ptr)->IsActive = false;
  267. }
  268. Infantry.Free((InfantryClass *)ptr);
  269. }
  270. /***********************************************************************************************
  271. * InfantryClass::Take_Damage -- Applies damage to the infantry unit. *
  272. * *
  273. * This routine applies the damage specified to the infantry object. It is possible that *
  274. * this routine will DESTROY the infantry unit in the process. *
  275. * *
  276. * INPUT: damage -- The damage points to inflict. *
  277. * *
  278. * distance -- The distance from the damage center point to the object's center point.*
  279. * *
  280. * warhead -- The warhead type that is inflicting the damage. *
  281. * *
  282. * source -- Who is responsible for inflicting the damage. *
  283. * *
  284. * OUTPUT: bool; Was the infantry unit destroyed by this damage? *
  285. * *
  286. * WARNINGS: Since the infantry unit could be destroyed by this routine, be sure to check *
  287. * for this in the code that follows the call to Take_Damage(). *
  288. * *
  289. * HISTORY: *
  290. * 09/08/1994 JLB : Created. *
  291. * 11/22/1994 JLB : Shares base damage handler for techno objects. *
  292. * 03/31/1995 JLB : Revenge factor. *
  293. *=============================================================================================*/
  294. ResultType InfantryClass::Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source, int forced)
  295. {
  296. assert(Infantry.ID(this) == ID);
  297. assert(IsActive);
  298. ResultType res = RESULT_NONE;
  299. /*
  300. ** Prone infantry take only half damage, but never below one damage point.
  301. */
  302. if (IsProne && damage > 0) {
  303. damage = damage * Rule.ProneDamageBias;
  304. }
  305. /*
  306. ** If we're taking damage from a dog, we have to decide if we're the
  307. ** target of the dog. Dogs don't spill collateral damage onto anyone
  308. ** else, so if we're the target of a valid dog, take full damage, but if
  309. ** we're not the target, or the dog doesn't exist, then take no damage.
  310. */
  311. if (source != NULL && source->What_Am_I() == RTTI_INFANTRY && ((InfantryClass *)source)->Class->IsDog) {
  312. if (source->TarCom == As_Target()) {
  313. damage = Strength;
  314. } else {
  315. damage = 0;
  316. }
  317. }
  318. res = FootClass::Take_Damage(damage, distance, warhead, source, forced);
  319. /*
  320. ** hack for dog: if you're hit by a dog, and you're the target, your
  321. ** damage gets upped to max.
  322. */
  323. if (res == RESULT_NONE) return(res);
  324. if (res == RESULT_DESTROYED) {
  325. if (*this == INFANTRY_TANYA) {
  326. IsTanyaDead = true;
  327. }
  328. Death_Announcement(source);
  329. Stop_Driver();
  330. Stun();
  331. Mission = MISSION_NONE;
  332. Assign_Mission(MISSION_GUARD);
  333. Commence();
  334. VocType sound;
  335. VocType altsound;
  336. sound = Sim_Random_Pick(VOC_SCREAM1, VOC_SCREAM11);
  337. altsound = VOC_YELL1;
  338. if (*this == INFANTRY_TANYA) {
  339. sound = altsound = VOC_TANYA_DIE;
  340. }
  341. if (Class->IsDog) {
  342. sound = altsound = VOC_DOG_HURT;
  343. }
  344. /*
  345. ** The type of warhead determines the animation the infantry
  346. ** will perform when killed.
  347. */
  348. bool delthis = false;
  349. TARGET us = As_Target();
  350. switch (WarheadTypeClass::As_Pointer(warhead)->InfantryDeath) {
  351. default:
  352. case 0:
  353. delthis = true;
  354. break;
  355. case 1:
  356. Sound_Effect(sound, Coord);
  357. Do_Action(DO_GUN_DEATH, true);
  358. break;
  359. case 2:
  360. Sound_Effect(sound, Coord);
  361. Do_Action(DO_EXPLOSION_DEATH, true);
  362. break;
  363. case 3:
  364. Sound_Effect(sound, Coord);
  365. Do_Action(DO_GRENADE_DEATH, true);
  366. break;
  367. case 4:
  368. Sound_Effect(altsound, Coord);
  369. Do_Action(DO_FIRE_DEATH, true);
  370. break;
  371. case 5:
  372. Sound_Effect(sound, Coord);
  373. AnimType anim = ANIM_ELECT_DIE;
  374. if (Class->IsDog) anim = ANIM_DOG_ELECT_DIE;
  375. new AnimClass(anim, Coord);
  376. delthis = true;
  377. break;
  378. }
  379. if (delthis) {
  380. delete this;
  381. }
  382. return(res);
  383. }
  384. /*
  385. ** When infantry gets hit, it gets scared.
  386. */
  387. if (res != RESULT_DESTROYED) {
  388. COORDINATE source_coord = (source) ? source->Coord : NULL;
  389. /*
  390. ** If an engineer is damaged and it is just sitting there, then tell it
  391. ** to go do something since it will definitely die if it doesn't.
  392. */
  393. if (!House->IsHuman && *this == INFANTRY_RENOVATOR && (Mission == MISSION_GUARD || Mission == MISSION_GUARD_AREA)) {
  394. Assign_Mission(MISSION_HUNT);
  395. }
  396. if (source != NULL) {
  397. Scatter(source_coord);
  398. }
  399. if (source != NULL && Fear < FEAR_SCARED) {
  400. if (Class->IsFraidyCat) {
  401. Fear = FEAR_PANIC;
  402. } else {
  403. Fear = FEAR_SCARED;
  404. }
  405. } else {
  406. /*
  407. ** Increase the fear of the infantry by a bit. The fear increases more
  408. ** quickly if the infantry is damaged.
  409. */
  410. int morefear = FEAR_ANXIOUS;
  411. if (Health_Ratio() > Rule.ConditionRed) morefear /= 2;
  412. if (Health_Ratio() > Rule.ConditionYellow) morefear /= 2;
  413. Fear = FearType(min((int)Fear + morefear, FEAR_MAXIMUM));
  414. }
  415. }
  416. return(res);
  417. }
  418. /***********************************************************************************************
  419. * InfantryClass::Shape_Number -- Fetch the shape number for this infantry. *
  420. * *
  421. * This will determine the shape number to use for this infantry soldier. The shape number *
  422. * is relative to the shape file associated with this infantry unit. *
  423. * *
  424. * INPUT: none *
  425. * *
  426. * OUTPUT: Returns with the shape number for this infantry object to be used when drawing. *
  427. * *
  428. * WARNINGS: none *
  429. * *
  430. * HISTORY: *
  431. * 07/29/1996 JLB : Created. *
  432. *=============================================================================================*/
  433. int InfantryClass::Shape_Number(void) const
  434. {
  435. /*
  436. ** Fetch the shape pointer to use for the infantry. This is controlled by what
  437. ** choreograph sequence the infantry is performing, it's facing, and whether it
  438. ** is prone.
  439. */
  440. DoType doit = Doing;
  441. if (doit == DO_NOTHING) doit = DO_STAND_READY;
  442. /*
  443. ** The infantry shape is always modulo the number of animation frames
  444. ** of the action stage that the infantry is doing.
  445. */
  446. int shapenum = Fetch_Stage() % max(Class->DoControls[doit].Count, 1);
  447. /*
  448. ** If facing makes a difference, then the shape number will be incremented
  449. ** by the facing accordingly.
  450. */
  451. if (Class->DoControls[doit].Jump) {
  452. shapenum += HumanShape[Dir_To_32(PrimaryFacing.Current())] * Class->DoControls[doit].Jump;
  453. }
  454. /*
  455. ** Finally, the shape number is biased according to the starting frame number for
  456. ** that action in the infantry shape file.
  457. */
  458. shapenum += Class->DoControls[doit].Frame;
  459. /*
  460. ** Return with the final infantry shape number.
  461. */
  462. return(shapenum);
  463. }
  464. /***********************************************************************************************
  465. * InfantryClass::Draw_It -- Draws a unit object. *
  466. * *
  467. * This routine is the one that actually draws a unit object. It displays the unit *
  468. * according to its current state flags and centered at the location specified. *
  469. * *
  470. * INPUT: x,y -- The X and Y coordinate of where to draw the unit. *
  471. * *
  472. * window -- The clipping window to use. *
  473. * *
  474. * OUTPUT: none *
  475. * *
  476. * WARNINGS: none *
  477. * *
  478. * HISTORY: *
  479. * 06/20/1994 JLB : Created. *
  480. * 06/27/1994 JLB : Takes a window parameter. *
  481. * 08/15/1994 JLB : Converted to infantry support. *
  482. * 08/14/1996 JLB : Simplified. *
  483. *=============================================================================================*/
  484. void InfantryClass::Draw_It(int x, int y, WindowNumberType window) const
  485. {
  486. assert(Infantry.ID(this) == ID);
  487. assert(IsActive);
  488. /*
  489. ** Verify the legality of the unit class by seeing if there is shape imagery for it. If
  490. ** there is no shape image, then it certainly can't be drawn -- bail.
  491. */
  492. void const * shapefile = Get_Image_Data();
  493. if (shapefile == NULL) return;
  494. y += 4;
  495. x -= 2;
  496. /*
  497. ** Actually draw the root body of the unit.
  498. */
  499. Techno_Draw_Object(shapefile, Shape_Number(), x, y, window);
  500. FootClass::Draw_It(x, y, window);
  501. }
  502. /***********************************************************************************************
  503. * InfantryClass::Per_Cell_Process -- Handles special operations that occur once per cell. *
  504. * *
  505. * This routine will handle any special operations that need to be performed once each *
  506. * cell travelled. This includes radioing a transport that it is now clear and the *
  507. * transport is free to leave. *
  508. * *
  509. * INPUT: why -- Specifies the circumstances under which this routine was called. *
  510. * *
  511. * OUTPUT: none *
  512. * *
  513. * WARNINGS: none *
  514. * *
  515. * HISTORY: *
  516. * 09/08/1994 JLB : Created. *
  517. * 03/01/1995 JLB : Capture building options. *
  518. * 05/31/1995 JLB : Capture is always successful now. *
  519. *=============================================================================================*/
  520. void InfantryClass::Per_Cell_Process(PCPType why)
  521. {
  522. assert(Infantry.ID(this) == ID);
  523. assert(IsActive);
  524. BStart(BENCH_PCP);
  525. CellClass * cellptr = &Map[Coord];
  526. if (why == PCP_END) {
  527. /*
  528. ** If the infantry unit is entering a cell that contains the building it is trying to
  529. ** capture, then capture it.
  530. */
  531. if (Mission == MISSION_CAPTURE) {
  532. TechnoClass * tech = cellptr->Cell_Building();
  533. if (tech == NULL) tech = cellptr->Cell_Techno();
  534. if (tech != NULL && (tech->As_Target() == NavCom || tech->As_Target() == TarCom)) {
  535. if (*this == INFANTRY_RENOVATOR) {
  536. /*
  537. ** An engineer will either mega-repair a friendly or allied
  538. ** building or it will damage/capture an enemy building. Whether
  539. ** it damages or captures depends on how badly damaged the
  540. ** enemy building is.
  541. */
  542. #ifdef FIXIT_ENGINEER_CAPTURE
  543. if (House->Is_Ally(tech)) {
  544. #else
  545. if (tech->House->Is_Ally(House)) {
  546. #endif
  547. tech->Renovate();
  548. } else {
  549. bool iscapturable = false;
  550. if (tech->What_Am_I() == RTTI_BUILDING) {
  551. iscapturable = ((BuildingClass *)tech)->Class->IsCaptureable;
  552. }
  553. #ifdef FIXIT_ENGINEER // checked - ajw 9/28/98
  554. if (tech->Health_Ratio() <= EngineerCaptureLevel && iscapturable) {
  555. #else
  556. if (tech->Health_Ratio() <= Rule.ConditionRed && iscapturable) {
  557. #endif
  558. if (tech->Trigger.Is_Valid()) {
  559. tech->Trigger->Spring(TEVENT_PLAYER_ENTERED, this);
  560. }
  561. tech->House->IsThieved = true;
  562. tech->Captured(House);
  563. } else {
  564. #ifdef FIXIT_ENGINEER // checked - ajw 9/28/98
  565. int damage = min( (tech->Techno_Type_Class()->MaxStrength) * EngineerDamage, tech->Strength-1);
  566. #else
  567. int damage = min( (tech->Techno_Type_Class()->MaxStrength) / 3, tech->Strength-1);
  568. #endif
  569. tech->Take_Damage(damage, 0, WARHEAD_HE, this, true);
  570. }
  571. BEnd(BENCH_PCP);
  572. delete this;
  573. return;
  574. }
  575. } else {
  576. if (*this != INFANTRY_SPY && tech->Trigger.Is_Valid()) {
  577. tech->Trigger->Spring(TEVENT_PLAYER_ENTERED, this);
  578. }
  579. if (*this == INFANTRY_SPY) {
  580. int housespy = (1 << (House->Class->House));
  581. // tech->House->IsSpied = true;
  582. if (tech->Trigger.Is_Valid()) {
  583. tech->Trigger->Spring(TEVENT_SPIED, this);
  584. }
  585. if (IsOwnedByPlayer) Speak(VOX_BUILDING_INFILTRATED);
  586. tech->Mark(MARK_OVERLAP_UP);
  587. tech->SpiedBy |= housespy;
  588. tech->Mark(MARK_OVERLAP_DOWN);
  589. if (tech->What_Am_I() == RTTI_BUILDING) {
  590. StructType build = *(BuildingClass *)tech;
  591. if (build == STRUCT_RADAR /* || build == STRUCT_EYE */ ) {
  592. tech->House->RadarSpied |= housespy;
  593. }
  594. // If they're spying on a sub pen, give 'em a sonar pulse
  595. if (build == STRUCT_SUB_PEN) {
  596. House->SuperWeapon[SPC_SONAR_PULSE].Enable(false, true, false);
  597. if (IsOwnedByPlayer) {
  598. Map.Add(RTTI_SPECIAL, SPC_SONAR_PULSE);
  599. Map.Column[1].Flag_To_Redraw();
  600. }
  601. }
  602. }
  603. } else {
  604. if (*this == INFANTRY_THIEF) { // Thief just raided a storage facility
  605. tech->House->IsThieved = true;
  606. if (tech->What_Am_I() == RTTI_BUILDING) {
  607. BuildingClass * bldg = (BuildingClass *)tech;
  608. if (bldg->Class->Capacity) {
  609. /*
  610. ** If we just raided a storage facility (refinery or silo)
  611. ** then give the thief up to half the capacity of the
  612. ** storage facility.
  613. */
  614. if (IsOwnedByPlayer || bldg->IsOwnedByPlayer) Speak(VOX_MONEY_STOLEN);
  615. #ifdef OBSOLETE
  616. long capacity = bldg->Class->Capacity * 256;
  617. capacity /= (bldg->House->Tiberium+1);
  618. int bldgcap = bldg->Class->Capacity;
  619. long cash = (bldgcap * 256) / (capacity+1);
  620. if (cash > (bldgcap / 2)) cash = bldgcap / 2;
  621. #else
  622. long cash = bldg->House->Available_Money() / 2;
  623. #endif
  624. bldg->House->Spend_Money(cash);
  625. House->Refund_Money(cash);
  626. }
  627. }
  628. }
  629. }
  630. }
  631. BEnd(BENCH_PCP);
  632. delete this;
  633. return;
  634. } else {
  635. #ifdef OBSOLETE
  636. // are we trying to repair a bridge?
  637. if (Is_Target_Cell(TarCom) ) {
  638. CELL cell = Coord_Cell(Coord);
  639. if (cell == ::As_Cell(NavCom)) {
  640. TemplateType tt = cellptr->TType;
  641. int icon = cellptr->TIcon;
  642. int w = TemplateTypeClass::As_Reference(cellptr->TType).Width;
  643. int h = TemplateTypeClass::As_Reference(cellptr->TType).Height;
  644. cell -= icon % w;
  645. cell -= MAP_CELL_W * (icon / w);
  646. if (tt == TEMPLATE_BRIDGE1D || tt == TEMPLATE_BRIDGE2D) {
  647. new TemplateClass(TemplateType(cellptr->TType-1), cell);
  648. Map.Zone_Reset(MZONEF_ALL);
  649. delete this;
  650. return;
  651. } else {
  652. // Trying to repair multi-segment bridge. Look for the
  653. // start tile, then fix it, and determine the direction to
  654. // go in and repair it all that way.
  655. TemplateType newtt = TEMPLATE_BRIDGE_1A;
  656. int xmov = -1; // coords to move to for next template
  657. int ymov = 2;
  658. bool valid = false;
  659. switch (tt) {
  660. case TEMPLATE_BRIDGE_1B:
  661. case TEMPLATE_BRIDGE_1C:
  662. valid = true;
  663. break;
  664. case TEMPLATE_BRIDGE_2B:
  665. case TEMPLATE_BRIDGE_2C:
  666. newtt = TEMPLATE_BRIDGE_2A;
  667. xmov = 2;
  668. ymov = -1;
  669. valid = true;
  670. break;
  671. case TEMPLATE_BRIDGE_3C:
  672. case TEMPLATE_BRIDGE_3D:
  673. newtt = TEMPLATE_BRIDGE_3A;
  674. valid = true;
  675. break;
  676. case TEMPLATE_BRIDGE_3E:
  677. newtt = TEMPLATE_BRIDGE_3A;
  678. xmov = 2;
  679. ymov = -1;
  680. valid = true;
  681. break;
  682. }
  683. // Did we find a valid repairable bridge piece?
  684. if (valid) {
  685. bool doing = true;
  686. while (doing) {
  687. new TemplateClass(TemplateType(newtt), cell);
  688. cell += (MAP_CELL_W * ymov) + xmov;
  689. if (xmov < 0) {
  690. xmov = -1;
  691. ymov = 1;
  692. } else {
  693. xmov = 1;
  694. ymov = -1;
  695. }
  696. cellptr = &Map[cell];
  697. tt = cellptr->TType;
  698. if ((tt >= TEMPLATE_BRIDGE_3B && tt <= TEMPLATE_BRIDGE_3F) ||
  699. tt == TEMPLATE_BRIDGE_1B || tt == TEMPLATE_BRIDGE_1C ||
  700. tt == TEMPLATE_BRIDGE_2B || tt == TEMPLATE_BRIDGE_2C ) {
  701. if (tt >= TEMPLATE_BRIDGE_3B) {
  702. newtt = TEMPLATE_BRIDGE_3A;
  703. } else {
  704. if (tt < TEMPLATE_BRIDGE_2A) {
  705. newtt = TEMPLATE_BRIDGE_1A;
  706. } else {
  707. newtt = TEMPLATE_BRIDGE_2A;
  708. }
  709. }
  710. icon = cellptr->TIcon;
  711. w = TemplateTypeClass::As_Reference(cellptr->TType).Width;
  712. h = TemplateTypeClass::As_Reference(cellptr->TType).Height;
  713. cell -= icon % w;
  714. cell -= MAP_CELL_W * (icon / w);
  715. } else {
  716. doing = false;
  717. }
  718. }
  719. Map.Zone_Reset(MZONEF_ALL);
  720. delete this;
  721. return;
  722. }
  723. }
  724. }
  725. } else {
  726. #endif
  727. if (!Target_Legal(NavCom)) {
  728. Enter_Idle_Mode();
  729. if (Map[Coord].Cell_Building()) {
  730. Scatter(0, true);
  731. }
  732. }
  733. #ifdef OBSOLETE
  734. }
  735. #endif
  736. }
  737. }
  738. /*
  739. ** Infantry entering a transport vehicle will break radio contact
  740. ** at attach itself to the transporter.
  741. */
  742. TechnoClass * techno = Contact_With_Whom();
  743. if (Mission == MISSION_ENTER && techno != NULL && Coord_Cell(Coord) == Coord_Cell(techno->Coord) && techno == As_Techno(NavCom)) {
  744. if (Transmit_Message(RADIO_IM_IN) == RADIO_ATTACH) {
  745. Limbo();
  746. techno->Attach(this);
  747. }
  748. BEnd(BENCH_PCP);
  749. return;
  750. }
  751. /*
  752. ** If the infantry unit is entering a cell that contains the building it is trying to
  753. ** sabotage, then sabotage it.
  754. */
  755. if (Mission == MISSION_SABOTAGE) {
  756. BuildingClass * building = cellptr->Cell_Building();
  757. if (building != NULL && building->As_Target() == NavCom) {
  758. if (!building->IronCurtainCountDown && building->Mission != MISSION_DECONSTRUCTION) {
  759. building->IsGoingToBlow = true;
  760. building->Clicked_As_Target((Rule.C4Delay * TICKS_PER_MINUTE) / 2);
  761. building->CountDown = Rule.C4Delay * TICKS_PER_MINUTE;
  762. building->WhomToRepay = As_Target();
  763. }
  764. NavCom = TARGET_NONE;
  765. Do_Uncloak();
  766. Arm = Rearm_Delay(true);
  767. Scatter(building->Center_Coord(), true, true); // RUN AWAY!
  768. BEnd(BENCH_PCP);
  769. return;
  770. } else {
  771. if (::As_Target(Coord_Cell(Center_Coord())) == NavCom) {
  772. Explosion_Damage(Coord, Rule.BridgeStrength, this, WARHEAD_HE);
  773. Stop_Driver();
  774. Scatter(Adjacent_Cell(Coord, PrimaryFacing), true, true);
  775. Assign_Mission(MISSION_MOVE);
  776. CELL cell = Coord_Cell(Center_Coord());
  777. CellClass * cellptr = &Map[cell];
  778. if (!Target_Legal(NavCom) || Map[As_Cell(NavCom)].Land_Type() == LAND_WATER) {
  779. Mark(MARK_DOWN); // Needed only so that Tanya will get destroyed by the explosion.
  780. }
  781. Explosion_Damage(Coord, Rule.BridgeStrength, NULL, WARHEAD_HE);
  782. Explosion_Damage(Coord, Rule.BridgeStrength, NULL, WARHEAD_HE);
  783. if (!IsActive) {
  784. BEnd(BENCH_PCP);
  785. return;
  786. }
  787. Mark(MARK_DOWN);
  788. }
  789. }
  790. }
  791. /*
  792. ** If this unit is on a teather, then cut it at this time so that
  793. ** the "parent" unit is free to proceed. Note that the parent
  794. ** unit might actually be a building.
  795. */
  796. if (IsTethered) {
  797. Transmit_Message(RADIO_UNLOADED);
  798. if (House->ActLike == HOUSE_USSR || House->ActLike == HOUSE_UKRAINE) {
  799. Do_Action(DO_GESTURE1);
  800. } else {
  801. Do_Action(DO_GESTURE2);
  802. }
  803. /*
  804. ** Special voice play.
  805. */
  806. if (*this == INFANTRY_TANYA) {
  807. Sound_Effect(VOC_TANYA_LAUGH, Coord);
  808. }
  809. /*
  810. ** If the cell is now full of infantry, tell them all to scatter
  811. ** in order to make room for more.
  812. */
  813. if ((cellptr->Flag.Composite & 0x01F) == 0x01F) {
  814. cellptr->Incoming(0, true, true);
  815. // cellptr->Incoming(0, true);
  816. }
  817. }
  818. /*
  819. ** When the infantry reaches the center of the cell, it may begin a new mission.
  820. */
  821. if (MissionQueue == MISSION_NONE && !Target_Legal(NavCom) && !Target_Legal(TarCom) && !In_Radio_Contact()) {
  822. Enter_Idle_Mode();
  823. }
  824. Commence();
  825. /*
  826. ** If entering a cell with a land mine in it, blow up the mine.
  827. */
  828. BuildingClass * bldng = cellptr->Cell_Building();
  829. if (bldng != NULL && *bldng == STRUCT_APMINE) {
  830. /*
  831. ** Show the animation and get rid of the land mine
  832. */
  833. COORDINATE blcoord = bldng->Center_Coord();
  834. new AnimClass(Combat_Anim(Rule.APMineDamage, WARHEAD_HE, cellptr->Land_Type()), blcoord);
  835. delete bldng;
  836. int damage;
  837. for (int index = 0; index < Infantry.Count(); index++) {
  838. InfantryClass * obj = Infantry.Ptr(index);
  839. if (obj != NULL && !obj->IsInLimbo) {
  840. int dist = ::Distance(obj->Coord, blcoord);
  841. if (dist <= 0xC0) {
  842. damage = Rule.APMineDamage;
  843. obj->Take_Damage(damage, 0, WARHEAD_HE);
  844. }
  845. }
  846. }
  847. if (!IsActive) {
  848. BEnd(BENCH_PCP);
  849. return;
  850. }
  851. }
  852. Look(true);
  853. #if 1
  854. /*
  855. ** If after all is said and done, the unit finishes its move on an impassable cell, then
  856. ** it must presume that it is in the case of a unit driving onto a bridge that blows up
  857. ** before the unit completes it's move. In such a case the unit should have been destroyed
  858. ** anyway, so blow it up now.
  859. */
  860. LandType land = Map[Coord].Land_Type();
  861. if (!IsDriving && !Class->IsBomber && (land == LAND_ROCK || land == LAND_WATER || land == LAND_RIVER)) {
  862. int damage = Strength;
  863. Take_Damage(damage, 0, WARHEAD_AP, NULL, true);
  864. return;
  865. }
  866. #endif
  867. }
  868. if (IsActive) {
  869. FootClass::Per_Cell_Process(why);
  870. }
  871. BEnd(BENCH_PCP);
  872. }
  873. /***********************************************************************************************
  874. * InfantryClass::Detach -- Removes the specified target from targeting computer. *
  875. * *
  876. * This is a support routine that removes the target specified from any targeting or *
  877. * navigation computers. When a target is destroyed or removed from the game system, *
  878. * the target must be removed from any tracking systems of the other units. This routine *
  879. * handles removal for infantry units. *
  880. * *
  881. * INPUT: target -- The target to remove from the infantry unit's tracking systems. *
  882. * *
  883. * all -- Is the target going away for good as opposed to just cloaking/hiding? *
  884. * *
  885. * OUTPUT: none *
  886. * *
  887. * WARNINGS: none *
  888. * *
  889. * HISTORY: *
  890. * 09/08/1994 JLB : Created. *
  891. *=============================================================================================*/
  892. void InfantryClass::Detach(TARGET target, bool all)
  893. {
  894. assert(Infantry.ID(this) == ID);
  895. assert(IsActive);
  896. if (TarCom == target) {
  897. Mark(MARK_OVERLAP_UP);
  898. IsFiring = false;
  899. Mark(MARK_OVERLAP_DOWN);
  900. }
  901. FootClass::Detach(target, all);
  902. }
  903. /***********************************************************************************************
  904. * InfantryClass::Init -- Initialize the infantry object system. *
  905. * *
  906. * This routine will force the infantry object system into its empty initial state. It *
  907. * is called when the scenario needs to be cleared in preparation for a scenario load. *
  908. * *
  909. * INPUT: none *
  910. * *
  911. * OUTPUT: none *
  912. * *
  913. * WARNINGS: none *
  914. * *
  915. * HISTORY: *
  916. * 09/08/1994 JLB : Created. *
  917. *=============================================================================================*/
  918. void InfantryClass::Init(void)
  919. {
  920. Infantry.Free_All();
  921. }
  922. /***********************************************************************************************
  923. * InfantryClass::Assign_Destination -- Gives the infantry a movement destination. *
  924. * *
  925. * This routine updates the infantry's navigation computer so that the infantry will *
  926. * travel to the destination target specified. *
  927. * *
  928. * INPUT: target -- The target to have the infantry unit move to. *
  929. * *
  930. * OUTPUT: none *
  931. * *
  932. * WARNINGS: none *
  933. * *
  934. * HISTORY: *
  935. * 09/08/1994 JLB : Created. *
  936. *=============================================================================================*/
  937. void InfantryClass::Assign_Destination(TARGET target)
  938. {
  939. assert(Infantry.ID(this) == ID);
  940. assert(IsActive);
  941. /*
  942. ** Special flag so that infantry will start heading in the right direction immediately.
  943. */
  944. if (IsDriving && !IsFormationMove && Target_Legal(target) && Map[Center_Coord()].Is_Clear_To_Move(Class->Speed, true, false)) {
  945. Stop_Driver();
  946. }
  947. /*
  948. ** When telling an infantry soldier to move to a location twice, then this
  949. ** means that movement is more important than safety. Get up and run!
  950. */
  951. if (House->IsHuman && Target_Legal(target) && NavCom == target && IsProne && !Class->IsFraidyCat && !Class->IsDog) {
  952. Do_Action(DO_GET_UP);
  953. }
  954. /*
  955. ** If telling a dog to attack a human, start the dog running
  956. */
  957. TechnoClass * tech = As_Techno(target);
  958. /*
  959. ** Handle entry logic here.
  960. */
  961. if (Mission == MISSION_ENTER || MissionQueue == MISSION_ENTER) {
  962. /*
  963. ** If not already in radio contact (presumed with the transport), then
  964. ** either try to establish contact if allowed, or just move close and
  965. ** wait until radio contact can be established.
  966. */
  967. if (!In_Radio_Contact()) {
  968. TechnoClass * techno = As_Techno(target);
  969. if (techno != NULL) {
  970. /*
  971. ** Determine if the transport is already in radio contact. If so, then just move
  972. ** toward the transport and try to establish contact at a later time.
  973. */
  974. if (techno->In_Radio_Contact()) {
  975. // TCTCTC -- call for an update from the transport to get a good rendezvous position.
  976. ArchiveTarget = target;
  977. } else {
  978. if (Transmit_Message(RADIO_HELLO, techno) == RADIO_ROGER) {
  979. if (Transmit_Message(RADIO_DOCKING) != RADIO_ROGER) {
  980. Transmit_Message(RADIO_OVER_OUT);
  981. } else {
  982. //BG: keep retransmitted navcom from radio-move-here.
  983. return;
  984. }
  985. }
  986. }
  987. }
  988. } else {
  989. Path[0] = FACING_NONE;
  990. }
  991. } else {
  992. Path[0] = FACING_NONE;
  993. }
  994. FootClass::Assign_Destination(target);
  995. }
  996. /***********************************************************************************************
  997. * InfantryClass::Assign_Target -- Gives the infantry a combat target. *
  998. * *
  999. * This routine will update the infantry's targeting computer so that it will try to *
  1000. * attack the target specified. This might result in it moving to be within range and thus *
  1001. * also cause adjustment of the navigation computer. *
  1002. * *
  1003. * INPUT: target -- The target that this infantry should attack. *
  1004. * *
  1005. * OUTPUT: none *
  1006. * *
  1007. * WARNINGS: none *
  1008. * *
  1009. * HISTORY: *
  1010. * 09/08/1994 JLB : Created. *
  1011. * 06/30/1995 JLB : Tries to capture target if possible. *
  1012. *=============================================================================================*/
  1013. void InfantryClass::Assign_Target(TARGET target)
  1014. {
  1015. assert(Infantry.ID(this) == ID);
  1016. assert(IsActive);
  1017. Path[0] = FACING_NONE;
  1018. if (Class->IsDog) {
  1019. if (::As_Object(target) && ::As_Object(target)->What_Am_I() != RTTI_INFANTRY) {
  1020. target = TARGET_NONE;
  1021. }
  1022. }
  1023. FootClass::Assign_Target(target);
  1024. /*
  1025. ** If this is an infantry that can only capture, then also assign its destination to the
  1026. ** target specified.
  1027. */
  1028. if (!Target_Legal(NavCom) && Class->IsCapture && !Is_Weapon_Equipped()) {
  1029. BuildingClass const * building = As_Building(target);
  1030. if (building != NULL && building->Class->IsCaptureable) {
  1031. Assign_Destination(target);
  1032. }
  1033. }
  1034. }
  1035. /***********************************************************************************************
  1036. * InfantryClass::AI -- Handles the infantry non-graphic related AI processing. *
  1037. * *
  1038. * This routine is used to handle the non-graphic AI processing the infantry requires. *
  1039. * Call this routine ONCE per game frame. *
  1040. * *
  1041. * INPUT: none *
  1042. * *
  1043. * OUTPUT: none *
  1044. * *
  1045. * WARNINGS: none *
  1046. * *
  1047. * HISTORY: *
  1048. * 09/08/1994 JLB : Created. *
  1049. * 08/14/1996 JLB : Simplified. *
  1050. *=============================================================================================*/
  1051. void InfantryClass::AI(void)
  1052. {
  1053. assert(Infantry.ID(this) == ID);
  1054. assert(IsActive);
  1055. FootClass::AI();
  1056. if (!IsActive) {
  1057. return;
  1058. }
  1059. if (IsUnloading) Mark(MARK_CHANGE_REDRAW);
  1060. /*
  1061. ** Infantry that are not on the ground should always be redrawn. Such is
  1062. ** the case when they are parachuting to the ground.
  1063. */
  1064. if (In_Which_Layer() != LAYER_GROUND) {
  1065. Mark(MARK_CHANGE);
  1066. }
  1067. /*
  1068. ** Special hack to make sure that if this infantry is in firing animation, but the
  1069. ** stage class isn't set, then abort the firing flag.
  1070. */
  1071. if (IsFiring && Fetch_Rate() == 0) {
  1072. Mark(MARK_OVERLAP_UP);
  1073. IsFiring = false;
  1074. Do_Action(DO_STAND_READY);
  1075. Mark(MARK_OVERLAP_DOWN);
  1076. }
  1077. /*
  1078. ** Delete this unit if it finds itself off the edge of the map and it is in
  1079. ** guard or other static mission mode.
  1080. */
  1081. if (Edge_Of_World_AI()) {
  1082. return;
  1083. }
  1084. /*
  1085. ** Act on new orders if the unit is at a good position to do so.
  1086. */
  1087. if (!IsFiring && !IsFalling && !IsDriving && (Doing == DO_NOTHING || MasterDoControls[Doing].Interrupt)) {
  1088. if (Mission == MISSION_NONE && MissionQueue == MISSION_NONE) Enter_Idle_Mode();
  1089. Commence();
  1090. }
  1091. /*
  1092. ** Special hack to make sure the dog never attacks a cell.
  1093. */
  1094. if (Class->IsDog && Target_Legal(TarCom) && Is_Target_Cell(TarCom)) {
  1095. Assign_Target(TARGET_NONE);
  1096. }
  1097. /*
  1098. ** Handle any infantry fear logic or related actions.
  1099. */
  1100. Fear_AI();
  1101. /*
  1102. ** Special victory dance action.
  1103. */
  1104. if (!Target_Legal(NavCom) && !IsProne && IsStoked && Comment == 0) {
  1105. IsStoked = false;
  1106. Do_Action(Percent_Chance(50) ? DO_GESTURE1 : DO_GESTURE2);
  1107. }
  1108. /*
  1109. ** Determine if this infantry unit should fire off an
  1110. ** attack or not.
  1111. */
  1112. Firing_AI();
  1113. /*
  1114. ** Handle the completion of the animation sequence.
  1115. */
  1116. Doing_AI();
  1117. /*
  1118. ** Perform movement operations at this time.
  1119. */
  1120. Movement_AI();
  1121. }
  1122. /***********************************************************************************************
  1123. * InfantryClass::Can_Enter_Cell -- Determines if the infantry can enter the cell specified. *
  1124. * *
  1125. * This routine is used to examine the cell specified and determine if the infantry is *
  1126. * allowed to enter it. It is used by the path finding algorithm. *
  1127. * *
  1128. * INPUT: cell -- The cell to examine. *
  1129. * *
  1130. * OUTPUT: Returns the type of blockage in the cell. *
  1131. * *
  1132. * WARNINGS: none *
  1133. * *
  1134. * HISTORY: *
  1135. * 09/01/1994 JLB : Created. *
  1136. *=============================================================================================*/
  1137. MoveType InfantryClass::Can_Enter_Cell(CELL cell, FacingType ) const
  1138. {
  1139. assert(Infantry.ID(this) == ID);
  1140. assert(IsActive);
  1141. /*
  1142. ** If we are moving into an illegal cell, then we can't do that.
  1143. */
  1144. if ((unsigned)cell >= MAP_CELL_TOTAL) return(MOVE_NO);
  1145. /*
  1146. ** If moving off the edge of the map, then consider that an illegal move.
  1147. */
  1148. if (!ScenarioInit && !Map.In_Radar(cell) && !Is_Allowed_To_Leave_Map()) {
  1149. return(MOVE_NO);
  1150. }
  1151. CellClass * cellptr = &Map[cell];
  1152. /*
  1153. ** Walls are considered impassable for infantry UNLESS the wall has a hole
  1154. ** in it.
  1155. */
  1156. if (cellptr->Overlay != OVERLAY_NONE) {
  1157. OverlayTypeClass const & otype = OverlayTypeClass::As_Reference(cellptr->Overlay);
  1158. if (otype.IsCrate && !((Session.Type == GAME_NORMAL) ? House->IsPlayerControl : House->IsHuman) && Session.Type == GAME_NORMAL) {
  1159. return(MOVE_NO);
  1160. }
  1161. if (otype.IsWall) {
  1162. if ((cellptr->OverlayData / 16) != otype.DamageLevels) {
  1163. /*
  1164. ** If the wall can be destroyed, then return this fact instead of
  1165. ** a complete failure to enter.
  1166. */
  1167. if (Is_Weapon_Equipped() && Class->PrimaryWeapon->Is_Wall_Destroyer()) {
  1168. return(MOVE_DESTROYABLE);
  1169. }
  1170. return(MOVE_NO);
  1171. }
  1172. }
  1173. }
  1174. /*
  1175. ** Loop through all of the objects in the square setting a bit
  1176. ** for how they affect movement.
  1177. */
  1178. MoveType retval = MOVE_OK;
  1179. ObjectClass * obj = cellptr->Cell_Occupier();
  1180. while (obj != NULL) {
  1181. if (obj != this) {
  1182. /*
  1183. ** Always allow movement if the cell is the object to be captured or sabotaged.
  1184. */
  1185. if (((Mission == MISSION_ENTER && In_Radio_Contact()) || Mission == MISSION_CAPTURE || Mission == MISSION_SABOTAGE) &&
  1186. (obj->As_Target() == NavCom || obj->As_Target() == TarCom)) {
  1187. return(MOVE_OK);
  1188. }
  1189. /*
  1190. ** Guard area should not allow the guarding unit to enter the cell with the
  1191. ** guarded unit.
  1192. */
  1193. if (Mission == MISSION_GUARD_AREA && ArchiveTarget == obj->As_Target() && Is_Target_Unit(ArchiveTarget)) {
  1194. return(MOVE_NO);
  1195. }
  1196. /*
  1197. ** If object is a land mine, allow movement
  1198. */
  1199. if (obj->What_Am_I() == RTTI_BUILDING) {
  1200. if ((*(BuildingClass *)obj) == STRUCT_AVMINE) {
  1201. obj = obj->Next;
  1202. continue;
  1203. } else {
  1204. if (!Rule.IsMineAware || !((BuildingClass *)obj)->House->Is_Ally(House)) {
  1205. if ((*(BuildingClass *)obj) == STRUCT_APMINE) {
  1206. obj = obj->Next;
  1207. continue;
  1208. }
  1209. }
  1210. }
  1211. }
  1212. /*
  1213. ** Special case check so that a landed aircraft that is in radio contact, will not block
  1214. ** a capture attempt. It is presumed that this case happens when a helicopter is landed
  1215. ** at a helipad.
  1216. */
  1217. // if ((Mission != MISSION_CAPTURE && Mission != MISSION_SABOTAGE) || obj->What_Am_I() != RTTI_AIRCRAFT || !((AircraftClass *)obj)->In_Radio_Contact()) {
  1218. /*
  1219. ** Special check to always allow entry into the building that this infantry
  1220. ** is trying to capture.
  1221. */
  1222. // if (obj->What_Am_I() == RTTI_BUILDING || obj->What_Am_I() == RTTI_AIRCRAFT || obj->What_Am_I() == RTTI_UNIT) {
  1223. // if ((Mission == MISSION_CAPTURE || Mission == MISSION_SABOTAGE) && (obj->As_Target() == NavCom || obj->As_Target() == TarCom)) {
  1224. // return(MOVE_OK);
  1225. // }
  1226. // }
  1227. /*
  1228. ** Special check to always allow entry into the building that this infantry
  1229. ** is trying to capture.
  1230. */
  1231. if (Mission == MISSION_ENTER && obj->As_Target() == NavCom && IsTethered) {
  1232. return(MOVE_OK);
  1233. }
  1234. /*
  1235. ** Allied objects block movement using different rules than for enemy
  1236. ** objects.
  1237. */
  1238. if (House->Is_Ally(obj) || ScenarioInit) {
  1239. switch (obj->What_Am_I()) {
  1240. /*
  1241. ** A unit blocks as either a moving blockage or a stationary temp blockage.
  1242. ** This depends on whether the unit is currently moving or not.
  1243. */
  1244. case RTTI_UNIT:
  1245. if (((UnitClass *)obj)->IsDriving || Target_Legal(((UnitClass *)obj)->NavCom)) {
  1246. if (retval < MOVE_MOVING_BLOCK) retval = MOVE_MOVING_BLOCK;
  1247. } else {
  1248. if (retval < MOVE_TEMP) retval = MOVE_TEMP;
  1249. }
  1250. break;
  1251. /*
  1252. ** Aircraft and buildings always block movement. If for some reason there is an
  1253. ** allied terrain object, that blocks movement as well.
  1254. */
  1255. case RTTI_TERRAIN:
  1256. case RTTI_AIRCRAFT:
  1257. case RTTI_BUILDING:
  1258. return(MOVE_NO);
  1259. default:
  1260. break;
  1261. }
  1262. } else {
  1263. /*
  1264. ** Cloaked enemy objects are not considered if this is a Find_Path()
  1265. ** call.
  1266. */
  1267. if (!obj->Is_Techno() || ((TechnoClass *)obj)->Cloak != CLOAKED) {
  1268. /*
  1269. ** Any non-allied blockage is considered impassible if the infantry
  1270. ** is not equipped with a weapon.
  1271. */
  1272. if (Combat_Damage() <= 0) return(MOVE_NO);
  1273. /*
  1274. ** Some kinds of terrain are considered destroyable if the infantry is equipped
  1275. ** with the weapon that can destroy it. Otherwise, the terrain is considered
  1276. ** impassable.
  1277. */
  1278. switch (obj->What_Am_I()) {
  1279. case RTTI_TERRAIN:
  1280. #ifdef OBSOLETE
  1281. if (((TerrainClass *)obj)->Class->Armor == ARMOR_WOOD &&
  1282. Class->PrimaryWeapon->WarheadPtr->IsWoodDestroyer) {
  1283. if (retval < MOVE_DESTROYABLE) retval = MOVE_DESTROYABLE;
  1284. } else {
  1285. return(MOVE_NO);
  1286. }
  1287. break;
  1288. #else
  1289. return(MOVE_NO);
  1290. #endif
  1291. case RTTI_INFANTRY:
  1292. if ( *(InfantryClass *)obj == INFANTRY_SPY && !Class->IsDog) {
  1293. retval = MOVE_TEMP;
  1294. break;
  1295. }
  1296. // otherwise, fall thru.
  1297. default:
  1298. if (retval < MOVE_DESTROYABLE) retval = MOVE_DESTROYABLE;
  1299. break;
  1300. }
  1301. } else {
  1302. if (retval < MOVE_CLOAK) retval = MOVE_CLOAK;
  1303. }
  1304. }
  1305. // }
  1306. }
  1307. /*
  1308. ** Move to next object in chain.
  1309. */
  1310. obj = obj->Next;
  1311. }
  1312. /*
  1313. ** If foot soldiers cannot travel on the cell -- consider it impassable.
  1314. */
  1315. if (retval == MOVE_OK && !IsTethered && Ground[cellptr->Land_Type()].Cost[SPEED_FOOT] == 0) {
  1316. #ifdef OBSOLETE
  1317. /*
  1318. ** Special case - if it's an engineer, and the cell under consideration
  1319. ** is his NavCom, and his mission is mission_capture, then he's most
  1320. ** likely moving to his final destination to repair a bridge, so we
  1321. ** should let him.
  1322. */
  1323. if (*this == INFANTRY_RENOVATOR && Is_Target_Cell(TarCom) && (cell == ::As_Cell(NavCom)) && (cellptr->TType == TEMPLATE_BRIDGE1D || cellptr->TType == TEMPLATE_BRIDGE2D || (cellptr->TType >= TEMPLATE_BRIDGE_1C && cellptr->TType <= TEMPLATE_BRIDGE_3E) ) ) {
  1324. return(MOVE_OK);
  1325. }
  1326. #endif
  1327. return(MOVE_NO);
  1328. }
  1329. /*
  1330. ** if a unit has the cell reserved then we just can't go in there.
  1331. */
  1332. if (retval == MOVE_OK && cellptr->Flag.Occupy.Vehicle) {
  1333. return(MOVE_NO);
  1334. }
  1335. /*
  1336. ** if a block of infantry has the cell reserved then there are two
  1337. ** possibilities...
  1338. */
  1339. if (cellptr->InfType != HOUSE_NONE) {
  1340. if (House->Is_Ally(cellptr->InfType)) {
  1341. if ((cellptr->Flag.Composite & 0x1F) == 0x1f) {
  1342. if (retval < MOVE_MOVING_BLOCK) retval = MOVE_MOVING_BLOCK;
  1343. }
  1344. } else {
  1345. if (Combat_Damage() > 0) {
  1346. if (retval < MOVE_DESTROYABLE) {
  1347. retval = MOVE_DESTROYABLE;
  1348. }
  1349. } else {
  1350. return(MOVE_NO);
  1351. }
  1352. }
  1353. }
  1354. /*
  1355. ** If it is still ok to move the infantry, then perform the last check
  1356. ** to see if the cell is already full of infantry.
  1357. */
  1358. if (retval == MOVE_OK && (cellptr->Flag.Composite & 0x1F) == 0x1F) {
  1359. return(MOVE_NO);
  1360. }
  1361. /*
  1362. ** Return with the most severe reason why this cell would be impassable.
  1363. */
  1364. return(retval);
  1365. }
  1366. /***********************************************************************************************
  1367. * InfantryClass::Overlap_List -- The list of cells that the infantry overlaps, but doesn't occ*
  1368. * *
  1369. * This is a rendering support routine that will return a pointer to a list of cell offsets *
  1370. * that specify the cells the infantry unit is currently overlapping (graphic wise) but *
  1371. * is not considered to occupy. This list is used to update the map display. *
  1372. * *
  1373. * INPUT: none *
  1374. * *
  1375. * OUTPUT: Returns a pointer to an offset list for cells that the unit overlaps but doesn't *
  1376. * occupy. *
  1377. * *
  1378. * WARNINGS: none *
  1379. * *
  1380. * HISTORY: *
  1381. * 09/01/1994 JLB : Created. *
  1382. *=============================================================================================*/
  1383. #ifdef PARTIAL
  1384. short const * InfantryClass::Overlap_List(bool redraw) const
  1385. #else
  1386. short const * InfantryClass::Overlap_List(bool ) const
  1387. #endif
  1388. {
  1389. assert(Infantry.ID(this) == ID);
  1390. assert(IsActive);
  1391. if (Class->IsDog) {
  1392. return(Coord_Spillage_List(Coord, 24 + (Doing == DO_DOG_MAUL ? 40 : 0) + (Doing >= DO_GUN_DEATH && Doing <= DO_FIRE_DEATH ? 40 : 0) ));
  1393. } else {
  1394. /*
  1395. ** The default infantry rectangle will be as large as the largest shape the infantry
  1396. ** can be.
  1397. */
  1398. #ifdef PARTIAL
  1399. Rect rect(-16, -24, 32, 36);
  1400. /*
  1401. ** If this is for a visual change redraw, then the overlap list will be based
  1402. ** on the actual dimensions of the shape data. If the dimensions have already
  1403. ** been calculated then use them, otherwise, use the default large rectangle
  1404. ** previously created.
  1405. */
  1406. if (Height == 0 && !IsSelected && redraw && Class->DimensionData != NULL) {
  1407. int shapenum = Shape_Number();
  1408. if (!Class->DimensionData[shapenum].Is_Valid()) {
  1409. Class->DimensionData[shapenum] = Shape_Dimensions(Get_Image_Data(), shapenum);
  1410. }
  1411. rect = Class->DimensionData[shapenum];
  1412. rect.Y += 4;
  1413. rect.X -= 2;
  1414. }
  1415. return(Coord_Spillage_List(Coord, rect, true));
  1416. #else
  1417. static Rect rect(-16, -24, 32, 36);
  1418. return(Coord_Spillage_List(Coord, rect, true));
  1419. #endif
  1420. // return(Coord_Spillage_List(Coord, 24 /*+ ((Doing > DO_WALK || IsSelected)?12:0)*/ ));
  1421. }
  1422. }
  1423. /***********************************************************************************************
  1424. * InfantryClass::Can_Fire -- Can the infantry fire its weapon? *
  1425. * *
  1426. * Determines if the infantry unit can fire on the target. If it can't fire, then the *
  1427. * reason why is returned. *
  1428. * *
  1429. * INPUT: target -- The target to determine if the infantry can fire upon. *
  1430. * *
  1431. * OUTPUT: Returns the fire error type that indicates if the infantry can fire and if it *
  1432. * can't, why not. *
  1433. * *
  1434. * WARNINGS: none *
  1435. * *
  1436. * HISTORY: *
  1437. * 09/01/1994 JLB : Created. *
  1438. * 06/27/1995 JLB : Flame thrower can fire while prone now. *
  1439. *=============================================================================================*/
  1440. FireErrorType InfantryClass::Can_Fire(TARGET target, int which) const
  1441. {
  1442. assert(Infantry.ID(this) == ID);
  1443. assert(IsActive);
  1444. /*
  1445. ** Don't allow firing if the infantry is still firing on previous target.
  1446. */
  1447. // if (IsFiring) return(FIRE_REARM);
  1448. /*
  1449. ** If a medic is shooting at a healed target, let's declare the target
  1450. ** illegal so he won't be constantly healing healed infantrymen.
  1451. */
  1452. if (Combat_Damage() < 0) {
  1453. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1454. TechnoClass * targ = As_Techno(target);
  1455. #else
  1456. InfantryClass * targ = As_Infantry(target);
  1457. #endif
  1458. if (targ == NULL || targ->Health_Ratio() >= Rule.ConditionGreen) {
  1459. return(FIRE_ILLEGAL);
  1460. }
  1461. }
  1462. /*
  1463. ** If this unit cannot fire while moving, then bail.
  1464. */
  1465. if (IsDriving || (Target_Legal(NavCom) && Doing != DO_NOTHING && !MasterDoControls[Doing].Interrupt)) {
  1466. return(FIRE_MOVING);
  1467. }
  1468. return(FootClass::Can_Fire(target, which));
  1469. }
  1470. /***********************************************************************************************
  1471. * InfantryClass::Enter_Idle_Mode -- The infantry unit enters idle mode by this routine. *
  1472. * *
  1473. * Use this routine when the infantry unit as accomplished its task and needs to find *
  1474. * something to do. The default behavior is to enter some idle state such as guarding. *
  1475. * *
  1476. * INPUT: initial -- Is this called when the unit just leaves a factory or is initially *
  1477. * or is initially placed on the map? *
  1478. * *
  1479. * OUTPUT: none *
  1480. * *
  1481. * WARNINGS: none *
  1482. * *
  1483. * HISTORY: *
  1484. * 09/01/1994 JLB : Created. *
  1485. *=============================================================================================*/
  1486. void InfantryClass::Enter_Idle_Mode(bool )
  1487. {
  1488. assert(Infantry.ID(this) == ID);
  1489. assert(IsActive);
  1490. MissionType order = MISSION_GUARD;
  1491. if (Target_Legal(TarCom)) {
  1492. order = MISSION_ATTACK;
  1493. if (Mission == MISSION_SABOTAGE) {
  1494. order = MISSION_SABOTAGE;
  1495. }
  1496. if (Mission == MISSION_CAPTURE) {
  1497. order = MISSION_CAPTURE;
  1498. }
  1499. } else {
  1500. Handle_Navigation_List();
  1501. if (Target_Legal(NavCom)) {
  1502. order = MISSION_MOVE;
  1503. if (Mission == MISSION_CAPTURE) {
  1504. order = MISSION_CAPTURE;
  1505. }
  1506. if (Mission == MISSION_SABOTAGE) {
  1507. order = MISSION_SABOTAGE;
  1508. }
  1509. } else {
  1510. if (Mission == MISSION_GUARD || Mission == MISSION_GUARD_AREA || MissionControl[Mission].IsZombie || MissionControl[Mission].IsParalyzed) {
  1511. return;
  1512. }
  1513. if (Class->IsDog) {
  1514. if (House->IsHuman || Team.Is_Valid()) {
  1515. order = MISSION_GUARD;
  1516. } else {
  1517. order = MISSION_GUARD_AREA;
  1518. ArchiveTarget = ::As_Target(Coord_Cell(Center_Coord()));
  1519. }
  1520. } else {
  1521. if (House->IsHuman || Team.Is_Valid()) {
  1522. order = MISSION_GUARD;
  1523. } else {
  1524. if (House->IQ < Rule.IQGuardArea) {
  1525. order = MISSION_GUARD;
  1526. } else {
  1527. if (Is_Weapon_Equipped()) {
  1528. order = MISSION_GUARD_AREA;
  1529. } else {
  1530. order = MISSION_GUARD;
  1531. }
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. Assign_Mission(order);
  1538. }
  1539. /***********************************************************************************************
  1540. * InfantryClass::Random_Animate -- Randomly animate the infantry (maybe) *
  1541. * *
  1542. * This routine is the random animator initiator for infantry units. This routine should *
  1543. * be called regularly. On occasion, it will cause the infantry to go into an idle *
  1544. * animation. *
  1545. * *
  1546. * INPUT: none *
  1547. * *
  1548. * OUTPUT: none *
  1549. * *
  1550. * WARNINGS: none *
  1551. * *
  1552. * HISTORY: *
  1553. * 09/01/1994 JLB : Created. *
  1554. * 12/13/1994 JLB : Does random facing change. *
  1555. * 07/02/1995 JLB : Nikoomba special effects. *
  1556. *=============================================================================================*/
  1557. bool InfantryClass::Random_Animate(void)
  1558. {
  1559. assert(Infantry.ID(this) == ID);
  1560. assert(IsActive);
  1561. if (Is_Ready_To_Random_Animate()) {
  1562. IdleTimer = Random_Pick(Rule.RandomAnimateTime * (TICKS_PER_MINUTE/2), Rule.RandomAnimateTime * (TICKS_PER_MINUTE*2));
  1563. /*
  1564. ** Scared infantry will always follow the golden rule of civilians;
  1565. ** "When in darkness or in doubt, run in circles, scream, and shout!"
  1566. */
  1567. if (Class->IsFraidyCat && !House->IsHuman && Fear > FEAR_ANXIOUS) {
  1568. Scatter(NULL, true);
  1569. return(true);
  1570. }
  1571. switch (Random_Pick(0, 10)) {
  1572. case 0:
  1573. if (Class->IsDog) {
  1574. Do_Action(DO_IDLE1);
  1575. }
  1576. break;
  1577. case 1:
  1578. Do_Action(DO_SALUTE1);
  1579. break;
  1580. case 2:
  1581. Do_Action(DO_SALUTE2);
  1582. break;
  1583. case 3:
  1584. Do_Action(DO_GESTURE1);
  1585. break;
  1586. case 4:
  1587. Do_Action(DO_GESTURE2);
  1588. break;
  1589. case 5:
  1590. Do_Action(DO_IDLE1);
  1591. break;
  1592. case 6:
  1593. Mark(MARK_CHANGE_REDRAW);
  1594. PrimaryFacing.Set(Facing_Dir(Random_Pick(FACING_N, FACING_NW)));
  1595. Mark(MARK_CHANGE_REDRAW);
  1596. break;
  1597. case 7:
  1598. Do_Action(DO_IDLE2);
  1599. Mark(MARK_CHANGE_REDRAW);
  1600. PrimaryFacing.Set(Facing_Dir(Random_Pick(FACING_N, FACING_NW)));
  1601. Mark(MARK_CHANGE_REDRAW);
  1602. if (!IsSelected && IsOwnedByPlayer && *this == INFANTRY_TANYA && Sim_Random_Pick(0, 2) == 0) {
  1603. Sound_Effect(VOC_TANYA_SHAKE, Coord);
  1604. }
  1605. break;
  1606. /*
  1607. ** On occasion, civilian types will wander about.
  1608. */
  1609. case 8:
  1610. Mark(MARK_CHANGE_REDRAW);
  1611. PrimaryFacing.Set(Facing_Dir(Random_Pick(FACING_N, FACING_NW)));
  1612. Mark(MARK_CHANGE_REDRAW);
  1613. if (!House->IsHuman && Class->IsFraidyCat) {
  1614. Scatter(NULL, true);
  1615. }
  1616. break;
  1617. case 9:
  1618. case 10:
  1619. Mark(MARK_CHANGE_REDRAW);
  1620. PrimaryFacing.Set(Facing_Dir(Random_Pick(FACING_N, FACING_NW)));
  1621. Mark(MARK_CHANGE_REDRAW);
  1622. }
  1623. return(true);
  1624. }
  1625. return(false);
  1626. }
  1627. /***********************************************************************************************
  1628. * InfantryClass::Scatter -- Causes the infantry to scatter to nearby cell. *
  1629. * *
  1630. * This routine is used when the infantry should scatter to a nearby cell. Scattering *
  1631. * occurs as an occasional consequence of being fired upon. It is one of the features *
  1632. * that makes infantry so "charming". *
  1633. * *
  1634. * INPUT: threat -- The coordinate source of the threat that is causing the infantry to *
  1635. * scatter. If the threat isn't from a particular direction, then this *
  1636. * parameter will be NULL. *
  1637. * *
  1638. * forced -- The threat is real and a serious effort to scatter should be made. *
  1639. * *
  1640. * nokidding-- The scatter should affect the player's infantry even if it otherwise *
  1641. * wouldn't have. *
  1642. * *
  1643. * OUTPUT: none *
  1644. * *
  1645. * WARNINGS: none *
  1646. * *
  1647. * HISTORY: *
  1648. * 09/24/1994 JLB : Created. *
  1649. * 12/12/1994 JLB : Flame thrower infantry always scatter. *
  1650. * 08/02/1996 JLB : Added the nokidding parameter *
  1651. *=============================================================================================*/
  1652. void InfantryClass::Scatter(COORDINATE threat, bool forced, bool nokidding)
  1653. {
  1654. assert(Infantry.ID(this) == ID);
  1655. assert(IsActive);
  1656. /*
  1657. ** A unit that is in the process of going somewhere will never scatter.
  1658. */
  1659. if (IsDriving) forced = false;
  1660. /*
  1661. ** Certain missions prevent scattering regardless of whether it would be
  1662. ** a good idea or not.
  1663. */
  1664. if (!MissionControl[Mission].IsScatter && !forced) return;
  1665. /*
  1666. ** If the infantry is currently engaged in legitimate combat, then don't
  1667. ** scatter unless forced to.
  1668. */
  1669. if (!Class->IsFraidyCat && Target_Legal(TarCom) && !forced) return;
  1670. /*
  1671. ** Don't scatter if performing an action that can't be interrupted.
  1672. */
  1673. if (Doing != DO_NOTHING && !MasterDoControls[Doing].Interrupt) return;
  1674. /*
  1675. ** For human players, don't scatter the infantry, if the special
  1676. ** flag has not been enabled that allows infantry scatter.
  1677. */
  1678. if (!Rule.IsScatter && !nokidding && House->IsHuman && !forced && !Team.Is_Valid()) return;
  1679. if (forced || Class->IsFraidyCat /*|| !(Random_Pick(1, 4) == 1)*/) {
  1680. FacingType toface;
  1681. if (threat) {
  1682. toface = Dir_Facing(Direction8(threat, Coord));
  1683. toface = toface + FacingType(Random_Pick(0, 4)-2);
  1684. } else {
  1685. COORDINATE coord = Coord_Fraction(Center_Coord());
  1686. if (coord != 0x00800080L) {
  1687. toface = Dir_Facing((DirType)Desired_Facing8(0x0080, 0x0080, Coord_X(coord), Coord_Y(coord)));
  1688. } else {
  1689. toface = Dir_Facing(PrimaryFacing.Current());
  1690. }
  1691. toface = toface + FacingType(Random_Pick(0, 4)-2);
  1692. }
  1693. CELL newcell = 0;
  1694. CELL altcell = 0;
  1695. for (FacingType face = FACING_N; face < FACING_COUNT; face++) {
  1696. FacingType newface = toface + face;
  1697. newcell = Adjacent_Cell(Coord_Cell(Coord), newface);
  1698. if (Map.In_Radar(newcell) && Can_Enter_Cell(newcell) == MOVE_OK) {
  1699. if (altcell == 0) altcell = newcell;
  1700. if (!Map[newcell].Is_Bridge_Here()) break;
  1701. // Assign_Mission(MISSION_MOVE);
  1702. // Assign_Destination(::As_Target(newcell));
  1703. }
  1704. }
  1705. if (face == FACING_COUNT) {
  1706. newcell = 0;
  1707. }
  1708. if (newcell == 0) {
  1709. newcell = altcell;
  1710. }
  1711. if (newcell != 0) {
  1712. Assign_Mission(MISSION_MOVE);
  1713. Assign_Destination(::As_Target(newcell));
  1714. }
  1715. }
  1716. }
  1717. /***********************************************************************************************
  1718. * InfantryClass::Do_Action -- Launches the infantry into an animation sequence. *
  1719. * *
  1720. * This starts the infantry into a choreographed animation sequence. These sequences can *
  1721. * be as simple as standing up or lying down, but can also be complex, such as dying or *
  1722. * performing some idle animation. *
  1723. * *
  1724. * INPUT: todo -- The choreographed sequence to start. *
  1725. * *
  1726. * force -- Force starting this animation even if the current animation is flagged *
  1727. * as uninterruptible. This is necessary for death animations. *
  1728. * *
  1729. * OUTPUT: bool; Was the animation started? *
  1730. * *
  1731. * WARNINGS: none *
  1732. * *
  1733. * HISTORY: *
  1734. * 09/24/1994 JLB : Created. *
  1735. *=============================================================================================*/
  1736. bool InfantryClass::Do_Action(DoType todo, bool force)
  1737. {
  1738. assert(Infantry.ID(this) == ID);
  1739. assert(IsActive);
  1740. if (todo == DO_NOTHING || Class->DoControls[todo].Count == 0) {
  1741. return(false);
  1742. }
  1743. if (*this == INFANTRY_SPY && todo >= DO_GESTURE1) {
  1744. todo = (DoType)(DO_IDLE1 + Random_Pick(0,1));
  1745. }
  1746. if (todo != Doing && (Doing == DO_NOTHING || force || MasterDoControls[Doing].Interrupt)) {
  1747. Mark(MARK_OVERLAP_UP);
  1748. Doing = todo;
  1749. Mark(MARK_OVERLAP_DOWN);
  1750. if (todo == DO_IDLE1 || todo == DO_IDLE2) {
  1751. Set_Rate(Options.Normalize_Delay(MasterDoControls[Doing].Rate));
  1752. } else {
  1753. Set_Rate(MasterDoControls[Doing].Rate);
  1754. }
  1755. Set_Stage(0);
  1756. /*
  1757. ** Kludge to make sure that if infantry is in the dying animation, it isn't still
  1758. ** moving as well.
  1759. */
  1760. if (Strength == 0) {
  1761. Stop_Driver();
  1762. }
  1763. /*
  1764. ** Since the animation sequence might be interrupted. Set any flags
  1765. ** necessary so that if interrupted, the affect on the infantry is
  1766. ** still accomplished.
  1767. */
  1768. switch (todo) {
  1769. case DO_LIE_DOWN:
  1770. IsProne = true;
  1771. break;
  1772. case DO_GET_UP:
  1773. IsProne = false;
  1774. break;
  1775. default:
  1776. break;
  1777. }
  1778. return(true);
  1779. }
  1780. return(false);
  1781. }
  1782. /***********************************************************************************************
  1783. * InfantryClass::Stop_Driver -- Stops the infantry from moving any further. *
  1784. * *
  1785. * This is used to stop the infantry from animating in movement. This function will stop *
  1786. * the infantry moving and revert it to either a prone or standing. *
  1787. * *
  1788. * INPUT: none *
  1789. * *
  1790. * OUTPUT: bool; Was the driving stopped? *
  1791. * *
  1792. * WARNINGS: none *
  1793. * *
  1794. * HISTORY: *
  1795. * 09/24/1994 JLB : Created. *
  1796. *=============================================================================================*/
  1797. bool InfantryClass::Stop_Driver(void)
  1798. {
  1799. assert(Infantry.ID(this) == ID);
  1800. assert(IsActive);
  1801. if (Head_To_Coord()) {
  1802. /*
  1803. ** Remove the "reservation" bit in the destination location.
  1804. */
  1805. Clear_Occupy_Bit(Head_To_Coord());
  1806. }
  1807. /*
  1808. ** Set the occupation bit at the current location.
  1809. */
  1810. Set_Occupy_Bit(Coord);
  1811. if (Class->IsDog) {
  1812. Do_Action(DO_STAND_READY);
  1813. } else {
  1814. if (IsProne) {
  1815. Do_Action(DO_PRONE);
  1816. } else {
  1817. Do_Action(DO_STAND_READY);
  1818. }
  1819. }
  1820. if (Can_Enter_Cell(Coord_Cell(Coord)) == MOVE_OK) {
  1821. IsZoneCheat = false;
  1822. } else {
  1823. IsZoneCheat = true;
  1824. }
  1825. return(FootClass::Stop_Driver());
  1826. }
  1827. /***********************************************************************************************
  1828. * InfantryClass::Start_Driver -- Handles giving immediate destination and move orders. *
  1829. * *
  1830. * Use this routine to being the infantry moving toward the destination specified. The *
  1831. * destination is first checked to see if there is a free spot available. Then the infantry *
  1832. * reserves that spot and begins movement toward it. *
  1833. * *
  1834. * INPUT: headto -- The coordinate location desired for the infantry to head to. *
  1835. * *
  1836. * OUTPUT: bool; Was the infantry successfully started on its journey? Failure may be because *
  1837. * the specified destination could not contain the infantry unit. *
  1838. * *
  1839. * WARNINGS: none *
  1840. * *
  1841. * HISTORY: *
  1842. * 12/21/1994 JLB : Created. *
  1843. * 05/14/1995 JLB : Tries to move to closest spot possible. *
  1844. * 05/15/1995 JLB : Uses closest spot if moving onto transport. *
  1845. *=============================================================================================*/
  1846. bool InfantryClass::Start_Driver(COORDINATE & headto)
  1847. {
  1848. assert(Infantry.ID(this) == ID);
  1849. assert(IsActive);
  1850. COORDINATE old = headto;
  1851. /*
  1852. ** Convert the head to coordinate to a legal sub-position location.
  1853. */
  1854. headto = Map[headto].Closest_Free_Spot(Coord_Move(headto, Direction(headto)+DIR_S, 0x007C));
  1855. if (!headto && Can_Enter_Cell(Coord_Cell(old)) == MOVE_OK) {
  1856. headto = Map[old].Closest_Free_Spot(Coord_Move(old, Direction(headto)+DIR_S, 0x0080), true);
  1857. }
  1858. /*
  1859. ** If the infantry started moving, then fixup the occupation bits.
  1860. */
  1861. if (headto && FootClass::Start_Driver(headto)) {
  1862. if (!IsActive) return(false);
  1863. /*
  1864. ** Remove the occupation bit from the infantry's current location.
  1865. */
  1866. Clear_Occupy_Bit(Coord);
  1867. /*
  1868. ** Set the occupation bit for the new headto location.
  1869. */
  1870. Set_Occupy_Bit(headto);
  1871. return(true);
  1872. }
  1873. return(false);
  1874. }
  1875. /***********************************************************************************************
  1876. * InfantryClass::Limbo -- Performs cleanup operations needed when limboing. *
  1877. * *
  1878. * This routine will clean up the infantry occupation bits (as necessary) as well as stop *
  1879. * the infantry movement process when it gets limboed. *
  1880. * *
  1881. * INPUT: none *
  1882. * *
  1883. * OUTPUT: bool; Was the infantry unit limboed? *
  1884. * *
  1885. * WARNINGS: none *
  1886. * *
  1887. * HISTORY: *
  1888. * 12/22/1994 JLB : Created. *
  1889. *=============================================================================================*/
  1890. bool InfantryClass::Limbo(void)
  1891. {
  1892. assert(Infantry.ID(this) == ID);
  1893. assert(IsActive);
  1894. if (!IsInLimbo) {
  1895. Stop_Driver();
  1896. Clear_Occupy_Bit(Coord);
  1897. }
  1898. return(FootClass::Limbo());
  1899. }
  1900. /***********************************************************************************************
  1901. * InfantryClass::Fire_At -- Fires projectile from infantry unit. *
  1902. * *
  1903. * Use this routine when the infantry unit wishes to fire a projectile. This routine *
  1904. * will launch the projectile and perform any other necessary infantry specific operations. *
  1905. * *
  1906. * INPUT: target -- The target of the attack. *
  1907. * *
  1908. * which -- Which weapon to use for firing. 0=primary, 1=secondary. *
  1909. * *
  1910. * OUTPUT: Returns with pointer to the projectile launched. If none could be launched, then *
  1911. * NULL is returned. If there is already the maximum bullet objects in play, then *
  1912. * this could happen. *
  1913. * *
  1914. * WARNINGS: none *
  1915. * *
  1916. * HISTORY: *
  1917. * 12/26/1994 JLB : Created. *
  1918. *=============================================================================================*/
  1919. BulletClass * InfantryClass::Fire_At(TARGET target, int which)
  1920. {
  1921. assert(Infantry.ID(this) == ID);
  1922. assert(IsActive);
  1923. Mark(MARK_OVERLAP_UP);
  1924. IsFiring = false;
  1925. Mark(MARK_OVERLAP_DOWN);
  1926. BulletClass * bullet = FootClass::Fire_At(target, which);
  1927. if (bullet != NULL && !IsInLimbo) {
  1928. /*
  1929. ** For fraidycat infantry that run out of ammo, always go into
  1930. ** a maximum fear state at that time.
  1931. */
  1932. if (Class->IsFraidyCat && !Ammo) {
  1933. Fear = FEAR_MAXIMUM;
  1934. if (Mission == MISSION_ATTACK || Mission == MISSION_HUNT) {
  1935. Assign_Mission(MISSION_GUARD);
  1936. }
  1937. }
  1938. }
  1939. return(bullet);
  1940. }
  1941. /***********************************************************************************************
  1942. * InfantryClass::Unlimbo -- Unlimbo infantry unit in legal sub-location. *
  1943. * *
  1944. * This will attempt to unlimbo the infantry unit at the designated coordinate, but will *
  1945. * ensure that the coordinate is a legal subposition. *
  1946. * *
  1947. * INPUT: coord -- The coordinate to unlimbo the infantry at. *
  1948. * *
  1949. * facing -- The desired initial facing for the infantry unit. *
  1950. * *
  1951. * strength -- The desired initial strength for the infantry unit. *
  1952. * *
  1953. * mission -- The desired initial mission for the infantry unit. *
  1954. * *
  1955. * OUTPUT: bool; Was the infantry unlimboed successfully? *
  1956. * *
  1957. * WARNINGS: none *
  1958. * *
  1959. * HISTORY: *
  1960. * 12/26/1994 JLB : Created. *
  1961. *=============================================================================================*/
  1962. bool InfantryClass::Unlimbo(COORDINATE coord, DirType facing)
  1963. {
  1964. assert(Infantry.ID(this) == ID);
  1965. assert(IsActive);
  1966. /*
  1967. ** Make sure that the infantry start in a legal position on the map.
  1968. */
  1969. coord = Map[coord].Closest_Free_Spot(coord, ScenarioInit);
  1970. if (coord == NULL) {
  1971. return(false);
  1972. }
  1973. if (FootClass::Unlimbo(coord, facing)) {
  1974. /*
  1975. ** Ensure that the owning house knows about the
  1976. ** new object.
  1977. */
  1978. House->IScan |= (1L << Class->Type);
  1979. House->ActiveIScan |= (1L << Class->Type);
  1980. /*
  1981. ** If there is no sight range, then this object isn't discovered by the player unless
  1982. ** it actually appears in a cell mapped by the player.
  1983. */
  1984. if (Class->SightRange == 0) {
  1985. IsDiscoveredByPlayer = false;
  1986. }
  1987. Set_Occupy_Bit(coord);
  1988. return(true);
  1989. }
  1990. return(false);
  1991. }
  1992. /***********************************************************************************************
  1993. * InfantryClass::Greatest_Threat -- Determines greatest threat (target) for infantry unit. *
  1994. * *
  1995. * This routine intercepts the Greatest_Threat request and adds the appropriate target *
  1996. * types to search for. For regular infantry, this consists of all the ground types. For *
  1997. * rocket launching infantry, this also includes aircraft. *
  1998. * *
  1999. * INPUT: threat -- The basic threat control value. *
  2000. * *
  2001. * OUTPUT: Returns with the best target for this infantry unit to attack. If no suitable *
  2002. * target could be found, then TARGET_NONE is returned. *
  2003. * *
  2004. * WARNINGS: none *
  2005. * *
  2006. * HISTORY: *
  2007. * 01/01/1995 JLB : Created. *
  2008. * 09/28/1995 JLB : Engineers try to recapture buildings first. *
  2009. *=============================================================================================*/
  2010. TARGET InfantryClass::Greatest_Threat(ThreatType threat) const
  2011. {
  2012. assert(Infantry.ID(this) == ID);
  2013. assert(IsActive);
  2014. /*
  2015. ** Engineers consider only buildings that can be captured as being a threat. All others
  2016. ** are ignored. If there is a building that needs to be recaptured and it is nearby
  2017. ** then automatically head toward it to recapture it.
  2018. */
  2019. if (!House->IsHuman && Class->IsCapture && !Is_Weapon_Equipped()) {
  2020. if (House->ToCapture != TARGET_NONE && Distance(House->ToCapture) < 0x0F00) {
  2021. return(House->ToCapture);
  2022. }
  2023. threat = threat | THREAT_CAPTURE;
  2024. }
  2025. if (!Is_Weapon_Equipped()) {
  2026. if (!Class->IsCapture && *this != INFANTRY_RENOVATOR && *this != INFANTRY_SPY && *this != INFANTRY_THIEF) {
  2027. return(TARGET_NONE);
  2028. }
  2029. }
  2030. /*
  2031. ** Special hack to make Tanya not auto-fire if controlled by a
  2032. ** human player.
  2033. */
  2034. if (*this == INFANTRY_TANYA && House->IsHuman) {
  2035. return(TARGET_NONE);
  2036. }
  2037. if (Class->PrimaryWeapon != NULL) {
  2038. threat = threat | Class->PrimaryWeapon->Allowed_Threats();
  2039. }
  2040. if (Class->SecondaryWeapon != NULL) {
  2041. threat = threat | Class->SecondaryWeapon->Allowed_Threats();
  2042. }
  2043. /*
  2044. ** Organic weapon types don't consider anything but infantry to be a threat. Such
  2045. ** weapon types would be the dog jaw and the medic first aid kit.
  2046. */
  2047. if (Is_Weapon_Equipped() && Class->PrimaryWeapon->WarheadPtr->IsOrganic) {
  2048. threat = threat & ~(THREAT_BUILDINGS|THREAT_VEHICLES|THREAT_BOATS|THREAT_AIR);
  2049. }
  2050. /*
  2051. ** Human controlled infantry don't automatically fire upon buildings.
  2052. */
  2053. if (Is_Weapon_Equipped() && House->IsHuman) {
  2054. threat = threat & ~THREAT_BUILDINGS;
  2055. }
  2056. /*
  2057. ** If this is a bomber type, then allow buildings to be considered a threat.
  2058. */
  2059. if (Class->IsBomber && !House->IsHuman) {
  2060. threat = threat | THREAT_BUILDINGS;
  2061. }
  2062. /*
  2063. ** Special hack: if it's a thief, then the only possible objects to
  2064. ** consider are tiberium-processing objects (silos & refineries).
  2065. */
  2066. if (*this == INFANTRY_THIEF) {
  2067. threat = threat | THREAT_CAPTURE | THREAT_TIBERIUM;
  2068. // threat = (ThreatType)(THREAT_CAPTURE | THREAT_TIBERIUM);
  2069. }
  2070. return(FootClass::Greatest_Threat(threat));
  2071. }
  2072. /***********************************************************************************************
  2073. * InfantryClass::Response_Select -- Plays infantry audio response due to being selected. *
  2074. * *
  2075. * This routine handles playing an audio response as a result of the player selecting the *
  2076. * infantry unit. This occurs prior to giving it an order and may not be followed by any *
  2077. * order at all. *
  2078. * *
  2079. * INPUT: none *
  2080. * *
  2081. * OUTPUT: none *
  2082. * *
  2083. * WARNINGS: none *
  2084. * *
  2085. * HISTORY: *
  2086. * 01/01/1995 JLB : Created. *
  2087. * 05/05/1995 JLB : Rambo response types added. *
  2088. *=============================================================================================*/
  2089. void InfantryClass::Response_Select(void)
  2090. {
  2091. assert(Infantry.ID(this) == ID);
  2092. assert(IsActive);
  2093. if (!AllowVoice) return;
  2094. if (Class->IsCivilian && *this != INFANTRY_EINSTEIN) {
  2095. VocType response = VOC_NONE;
  2096. if (Class->IsFemale) {
  2097. response = VOC_GIRL_YEAH;
  2098. } else {
  2099. response = VOC_GUY_YEAH;
  2100. }
  2101. Sound_Effect(response, fixed(1), ID+1);
  2102. } else {
  2103. static VocType _eng_response[] = {VOC_ENG_YES,VOC_ENG_ENG};
  2104. static VocType _ein_response[] = {VOC_E_AH};
  2105. static VocType _dog_response[] = {VOC_DOG_YES};
  2106. static VocType _spy_response[] = {VOC_SPY_COMMANDER,VOC_SPY_YESSIR};
  2107. static VocType _medic_response[] = {VOC_MED_REPORTING,VOC_MED_YESSIR};
  2108. static VocType _tanya_response[] = {VOC_TANYA_YEA,VOC_TANYA_YES,VOC_TANYA_WHATS};
  2109. static VocType _thief_response[] = {VOC_THIEF_YEA,VOC_THIEF_WHAT};
  2110. static VocType _default_response[] = {VOC_ACKNOWL,VOC_REPORT,VOC_REPORT,VOC_YESSIR,VOC_YESSIR,VOC_READY,VOC_AWAIT};
  2111. static VocType _stavros[] = {VOC_STAVCMDR,VOC_STAVYES};
  2112. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2113. static VocType _mechanic_response[] = {VOC_MECHHOWDY1,VOC_MECHHUH1,VOC_MECHLAFF1};
  2114. static VocType _shock_response[] = {VOC_STYES1,VOC_STJUMP1,VOC_STJUICE1};
  2115. #endif
  2116. int size = 0;
  2117. VocType * response = NULL;
  2118. HousesType house = PlayerPtr->ActLike;
  2119. switch (Class->Type) {
  2120. case INFANTRY_GENERAL:
  2121. if (house != HOUSE_USSR && house != HOUSE_BAD) {
  2122. response = _stavros;
  2123. size = ARRAY_SIZE(_stavros);
  2124. } else {
  2125. response = _default_response;
  2126. size = ARRAY_SIZE(_default_response);
  2127. }
  2128. house = HOUSE_USSR;
  2129. break;
  2130. case INFANTRY_DOG:
  2131. response = _dog_response;
  2132. size = ARRAY_SIZE(_dog_response);
  2133. break;
  2134. case INFANTRY_EINSTEIN:
  2135. response = _ein_response;
  2136. size = ARRAY_SIZE(_ein_response);
  2137. break;
  2138. case INFANTRY_SPY:
  2139. response = _spy_response;
  2140. size = ARRAY_SIZE(_spy_response);
  2141. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2142. if(house == HOUSE_USSR) {
  2143. response = _default_response;
  2144. size = ARRAY_SIZE(_default_response);
  2145. }
  2146. #endif
  2147. break;
  2148. case INFANTRY_MEDIC:
  2149. response = _medic_response;
  2150. size = ARRAY_SIZE(_medic_response);
  2151. break;
  2152. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2153. case INFANTRY_MECHANIC:
  2154. response = _mechanic_response;
  2155. size = ARRAY_SIZE(_mechanic_response);
  2156. break;
  2157. case INFANTRY_SHOCK:
  2158. response = _shock_response;
  2159. size = ARRAY_SIZE(_shock_response);
  2160. break;
  2161. #endif
  2162. case INFANTRY_TANYA:
  2163. response = _tanya_response;
  2164. size = ARRAY_SIZE(_tanya_response);
  2165. break;
  2166. case INFANTRY_THIEF:
  2167. response = _thief_response;
  2168. size = ARRAY_SIZE(_thief_response);
  2169. break;
  2170. case INFANTRY_RENOVATOR:
  2171. response = _eng_response;
  2172. size = ARRAY_SIZE(_eng_response);
  2173. break;
  2174. default:
  2175. response = _default_response;
  2176. size = ARRAY_SIZE(_default_response);
  2177. break;
  2178. }
  2179. if (response != NULL) {
  2180. Sound_Effect(response[Sim_Random_Pick(0, size-1)], fixed(1), ID+1, 0, house);
  2181. }
  2182. }
  2183. }
  2184. /***********************************************************************************************
  2185. * InfantryClass::Response_Move -- Plays infantry response to movement order. *
  2186. * *
  2187. * When the infantry is given the order to move, this routine handles the audio response *
  2188. * generated by the infantry unit. *
  2189. * *
  2190. * INPUT: none *
  2191. * *
  2192. * OUTPUT: none *
  2193. * *
  2194. * WARNINGS: none *
  2195. * *
  2196. * HISTORY: *
  2197. * 01/01/1995 JLB : Created. *
  2198. * 05/05/1995 JLB : Rambo response types added. *
  2199. *=============================================================================================*/
  2200. void InfantryClass::Response_Move(void)
  2201. {
  2202. assert(Infantry.ID(this) == ID);
  2203. assert(IsActive);
  2204. if (!AllowVoice) return;
  2205. if (Class->IsCivilian && *this != INFANTRY_EINSTEIN) {
  2206. VocType response;
  2207. if (Class->IsFemale) {
  2208. response = VOC_GIRL_OKAY;
  2209. } else {
  2210. response = VOC_GUY_OKAY;
  2211. }
  2212. Sound_Effect(response, fixed(1), ID+1);
  2213. } else {
  2214. static VocType _eng_response[] = {VOC_ENG_AFFIRM,VOC_ENG_AFFIRM};
  2215. static VocType _ein_response[] = {VOC_E_OK,VOC_E_YES};
  2216. static VocType _dog_response[] = {VOC_DOG_BARK};
  2217. static VocType _spy_response[] = {VOC_SPY_ONWAY,VOC_SPY_KING,VOC_SPY_INDEED};
  2218. static VocType _medic_response[] = {VOC_MED_AFFIRM,VOC_MED_MOVEOUT};
  2219. #ifdef ENGLISH
  2220. static VocType _tanya_response[] = {VOC_TANYA_THERE,VOC_TANYA_ROCK};
  2221. #else
  2222. static VocType _tanya_response[] = {VOC_TANYA_THERE,VOC_TANYA_GIVE};
  2223. #endif
  2224. static VocType _thief_response[] = {VOC_THIEF_MOVEOUT,VOC_THIEF_OKAY,VOC_THIEF_AFFIRM};
  2225. static VocType _default_response[] = {VOC_ROGER,VOC_RIGHT_AWAY,VOC_UGOTIT,VOC_AFFIRM,VOC_AFFIRM};
  2226. static VocType _stavros[] = {VOC_STAVMOV,VOC_STAVCRSE};
  2227. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2228. static VocType _mechanic[] = {VOC_MECHYES1,VOC_MECHRISE1,VOC_MECHHEAR1,VOC_MECHBOSS1};
  2229. static VocType _shock[] = {VOC_STPOWER1,VOC_STDANCE1,VOC_STCHRGE1};
  2230. #endif
  2231. int size = 0;
  2232. VocType * response = NULL;
  2233. HousesType house = PlayerPtr->ActLike;
  2234. switch (Class->Type) {
  2235. case INFANTRY_GENERAL:
  2236. if (house != HOUSE_USSR && house != HOUSE_BAD) {
  2237. response = _stavros;
  2238. size = ARRAY_SIZE(_stavros);
  2239. } else {
  2240. response = _default_response;
  2241. size = ARRAY_SIZE(_default_response);
  2242. }
  2243. house = HOUSE_USSR;
  2244. break;
  2245. case INFANTRY_DOG:
  2246. response = _dog_response;
  2247. size = ARRAY_SIZE(_dog_response);
  2248. break;
  2249. case INFANTRY_EINSTEIN:
  2250. response = _ein_response;
  2251. size = ARRAY_SIZE(_ein_response);
  2252. break;
  2253. case INFANTRY_RENOVATOR:
  2254. response = _eng_response;
  2255. size = ARRAY_SIZE(_eng_response);
  2256. break;
  2257. case INFANTRY_SPY:
  2258. response = _spy_response;
  2259. size = ARRAY_SIZE(_spy_response);
  2260. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2261. if(house == HOUSE_USSR) {
  2262. response = _default_response;
  2263. size = ARRAY_SIZE(_default_response);
  2264. }
  2265. #endif
  2266. break;
  2267. case INFANTRY_MEDIC:
  2268. response = _medic_response;
  2269. size = ARRAY_SIZE(_medic_response);
  2270. break;
  2271. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2272. case INFANTRY_MECHANIC:
  2273. response = _mechanic;
  2274. size = ARRAY_SIZE(_mechanic);
  2275. break;
  2276. case INFANTRY_SHOCK:
  2277. response = _shock;
  2278. size = ARRAY_SIZE(_shock);
  2279. break;
  2280. #endif
  2281. case INFANTRY_TANYA:
  2282. response = _tanya_response;
  2283. size = ARRAY_SIZE(_tanya_response);
  2284. break;
  2285. case INFANTRY_THIEF:
  2286. response = _thief_response;
  2287. size = ARRAY_SIZE(_thief_response);
  2288. break;
  2289. default:
  2290. response = _default_response;
  2291. size = ARRAY_SIZE(_default_response);
  2292. break;
  2293. }
  2294. if (response != NULL) {
  2295. Sound_Effect(response[Sim_Random_Pick(0, size-1)], fixed(1), ID+1, 0, house);
  2296. }
  2297. }
  2298. }
  2299. /***********************************************************************************************
  2300. * InfantryClass::Response_Attack -- Plays infantry audio response to attack order. *
  2301. * *
  2302. * When the player gives an infantry unit the order to attack, this routine handles *
  2303. * the audio response by that unit. *
  2304. * *
  2305. * INPUT: none *
  2306. * *
  2307. * OUTPUT: none *
  2308. * *
  2309. * WARNINGS: none *
  2310. * *
  2311. * HISTORY: *
  2312. * 01/01/1995 JLB : Created. *
  2313. * 05/05/1995 JLB : Rambo response types added. *
  2314. *=============================================================================================*/
  2315. void InfantryClass::Response_Attack(void)
  2316. {
  2317. assert(Infantry.ID(this) == ID);
  2318. assert(IsActive);
  2319. if (!AllowVoice) return;
  2320. if (Class->IsCivilian && *this != INFANTRY_EINSTEIN) {
  2321. VocType response;
  2322. if (Class->IsFemale) {
  2323. response = VOC_GIRL_OKAY;
  2324. } else {
  2325. response = VOC_GUY_OKAY;
  2326. }
  2327. Sound_Effect(response, fixed(1), ID+1);
  2328. } else {
  2329. static VocType _eng_response[] = {VOC_ENG_AFFIRM,VOC_ENG_AFFIRM};
  2330. static VocType _dog_response[] = {VOC_DOG_GROWL2};
  2331. static VocType _ein_response[] = {VOC_E_OK,VOC_E_YES};
  2332. static VocType _spy_response[] = {VOC_SPY_ONWAY,VOC_SPY_KING,VOC_SPY_INDEED};
  2333. static VocType _medic_response[] = {VOC_MED_AFFIRM,VOC_MED_MOVEOUT};
  2334. #ifdef ENGLISH
  2335. static VocType _tanya_response[] = {VOC_TANYA_CHEW,VOC_TANYA_CHING,VOC_TANYA_LAUGH};
  2336. #else
  2337. static VocType _tanya_response[] = {VOC_TANYA_CHEW,VOC_TANYA_CHING,VOC_TANYA_LAUGH,VOC_TANYA_ROCK};
  2338. #endif
  2339. static VocType _thief_response[] = {VOC_NONE};
  2340. static VocType _default_response[] = {VOC_RIGHT_AWAY,VOC_AFFIRM,VOC_AFFIRM,VOC_UGOTIT,VOC_NO_PROB,VOC_YESSIR,VOC_YESSIR,VOC_YESSIR};
  2341. static VocType _stavros[] = {VOC_STAVCRSE};
  2342. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2343. static VocType _mechanic[] = {VOC_MECHYEEHAW1,VOC_MECHHOTDIG1,VOC_MECHWRENCH1};
  2344. static VocType _shock[] = {VOC_STLIGHT1,VOC_STBURN1,VOC_STCRISP1,VOC_STSHOCK1};
  2345. #endif
  2346. int size = 0;
  2347. VocType * response = NULL;
  2348. HousesType house = PlayerPtr->ActLike;
  2349. switch (Class->Type) {
  2350. case INFANTRY_GENERAL:
  2351. if (house != HOUSE_USSR && house != HOUSE_BAD) {
  2352. response = _stavros;
  2353. size = ARRAY_SIZE(_stavros);
  2354. } else {
  2355. response = _default_response;
  2356. size = ARRAY_SIZE(_default_response);
  2357. }
  2358. house = HOUSE_USSR;
  2359. break;
  2360. case INFANTRY_DOG:
  2361. response = _dog_response;
  2362. size = ARRAY_SIZE(_dog_response);
  2363. break;
  2364. case INFANTRY_SPY:
  2365. response = _spy_response;
  2366. size = ARRAY_SIZE(_spy_response);
  2367. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2368. if(house == HOUSE_USSR) {
  2369. response = _default_response;
  2370. size = ARRAY_SIZE(_default_response);
  2371. }
  2372. #endif
  2373. break;
  2374. case INFANTRY_EINSTEIN:
  2375. response = _ein_response;
  2376. size = ARRAY_SIZE(_ein_response);
  2377. break;
  2378. case INFANTRY_RENOVATOR:
  2379. response = _eng_response;
  2380. size = ARRAY_SIZE(_eng_response);
  2381. break;
  2382. case INFANTRY_MEDIC:
  2383. response = _medic_response;
  2384. size = ARRAY_SIZE(_medic_response);
  2385. break;
  2386. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2387. case INFANTRY_MECHANIC:
  2388. response = _mechanic;
  2389. size = ARRAY_SIZE(_mechanic);
  2390. break;
  2391. case INFANTRY_SHOCK:
  2392. response = _shock;
  2393. size = ARRAY_SIZE(_shock);
  2394. break;
  2395. #endif
  2396. case INFANTRY_TANYA:
  2397. response = _tanya_response;
  2398. size = ARRAY_SIZE(_tanya_response);
  2399. break;
  2400. case INFANTRY_THIEF:
  2401. response = _thief_response;
  2402. size = ARRAY_SIZE(_thief_response);
  2403. break;
  2404. default:
  2405. response = _default_response;
  2406. size = ARRAY_SIZE(_default_response);
  2407. break;
  2408. }
  2409. if (response != NULL) {
  2410. Sound_Effect(response[Sim_Random_Pick(0, size-1)], fixed(1), ID+1, 0, house);
  2411. }
  2412. }
  2413. }
  2414. /***********************************************************************************************
  2415. * InfantryClass::What_Action -- Infantry units might be able to capture -- check. *
  2416. * *
  2417. * This routine checks to see if the infantry unit can capture the specified object rather *
  2418. * than merely attacking it. If this is the case, then ACTION_CAPTURE will be returned. *
  2419. * *
  2420. * INPUT: object -- The object that the mouse is currently over. *
  2421. * *
  2422. * OUTPUT: Returns the action that will be performed if the mouse were clicked over the *
  2423. * object specified. *
  2424. * *
  2425. * WARNINGS: none *
  2426. * *
  2427. * HISTORY: *
  2428. * 03/01/1995 JLB : Created. *
  2429. *=============================================================================================*/
  2430. ActionType InfantryClass::What_Action(ObjectClass const * object) const
  2431. {
  2432. assert(Infantry.ID(this) == ID);
  2433. assert(IsActive);
  2434. assert(object != NULL);
  2435. ActionType action = FootClass::What_Action(object);
  2436. /*
  2437. ** If this is an engineer/renovator, we have to make some adjustments.
  2438. ** If the cursor is over an enemy building, return action-none. If it's
  2439. ** over a friendly building, we have to return action-capture so he can
  2440. ** renovate it.
  2441. ** However, abort the whole thing if the building is a barrel or mine.
  2442. */
  2443. if (*this == INFANTRY_RENOVATOR && object->What_Am_I() == RTTI_BUILDING && House->IsPlayerControl) {
  2444. BuildingClass const * bldg = (BuildingClass *)object;
  2445. if (bldg->Class->IsRepairable) {
  2446. if (House->Is_Ally(bldg)) {
  2447. if (bldg->Health_Ratio() == 1) {
  2448. return(ACTION_NO_GREPAIR);
  2449. }
  2450. return(ACTION_GREPAIR);
  2451. } else {
  2452. if (bldg->Class->IsCaptureable) {
  2453. #ifdef FIXIT_ENGINEER // checked - ajw 9/28/98
  2454. if (bldg->Health_Ratio() <= EngineerCaptureLevel) {
  2455. #else
  2456. if (bldg->Health_Ratio() <= Rule.ConditionRed) {
  2457. #endif
  2458. return(ACTION_CAPTURE);
  2459. }
  2460. return(ACTION_DAMAGE);
  2461. }
  2462. // if (bldg->Health_Ratio() <= Rule.ConditionRed && bldg->Class->IsCaptureable) {
  2463. }
  2464. }
  2465. }
  2466. /*
  2467. ** If this is a medic, and the cursor's over a friendly infantryman,
  2468. ** execute an action-attack. In CSII, if this is a mechanic and the
  2469. ** cursor's over a friendly vehicle, execute an action-attack.
  2470. */
  2471. if (Combat_Damage() < 0 && House->IsPlayerControl) {
  2472. if (House->Is_Ally(object)) {
  2473. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2474. if( (object->What_Am_I() == RTTI_INFANTRY && object != this && *this == INFANTRY_MEDIC) ||
  2475. (*this == INFANTRY_MECHANIC && (object->What_Am_I() == RTTI_UNIT || object->What_Am_I() == RTTI_AIRCRAFT) ) ) {
  2476. if (object->Health_Ratio() < Rule.ConditionGreen) {
  2477. // If it's a mechanic force-moving into an APC, don't try to heal it.
  2478. if(*this == INFANTRY_MECHANIC && object->What_Am_I() == RTTI_UNIT && *(UnitClass *)object == UNIT_APC && (Keyboard->Down(Options.KeyForceMove1) || Keyboard->Down(Options.KeyForceMove2)) ) {
  2479. } else {
  2480. return(ACTION_HEAL);
  2481. }
  2482. }
  2483. }
  2484. #else
  2485. if(object->What_Am_I() == RTTI_INFANTRY && object != this) {
  2486. if (object->Health_Ratio() < Rule.ConditionGreen) {
  2487. return(ACTION_HEAL);
  2488. }
  2489. }
  2490. #endif
  2491. if(!object->Is_Techno() || !((TechnoClass *)object)->Techno_Type_Class()->Max_Passengers()) {
  2492. if (action == ACTION_GUARD_AREA || action == ACTION_MOVE) {
  2493. return(action);
  2494. }
  2495. return(ACTION_SELECT);
  2496. }
  2497. } else {
  2498. return(ACTION_NOMOVE);
  2499. }
  2500. }
  2501. #ifdef OBSOLETE
  2502. /*
  2503. ** See if it's a thief attacking an enemy vehicle, let him CAPTURE it.
  2504. */
  2505. if (*this == INFANTRY_THIEF && object->What_Am_I() == RTTI_UNIT) {
  2506. if (((UnitClass *)object)->House != House) {
  2507. return(ACTION_CAPTURE);
  2508. }
  2509. }
  2510. #endif
  2511. /*
  2512. ** Dogs can only attack infantrymen
  2513. */
  2514. if (Class->IsDog && action == ACTION_ATTACK && object->What_Am_I() != RTTI_INFANTRY) {
  2515. action = ACTION_NONE;
  2516. }
  2517. /*
  2518. ** See if it's a commando, and if he's attacking a building,
  2519. ** have him return ACTION_SABOTAGE instead
  2520. */
  2521. if (Class->IsBomber && action == ACTION_ATTACK && object->What_Am_I() == RTTI_BUILDING) {
  2522. BuildingClass const * obj = (BuildingClass *)object;
  2523. /*
  2524. ** Hack: Tanya should shoot barrels, bomb other structures.
  2525. */
  2526. if (obj->Class->IsRepairable) {
  2527. // if (*obj != STRUCT_BARREL && *obj != STRUCT_BARREL3) {
  2528. return(ACTION_SABOTAGE);
  2529. } else {
  2530. return(ACTION_ATTACK);
  2531. }
  2532. }
  2533. /*
  2534. ** See if this infantry is trying to move onto where a land mine is.
  2535. */
  2536. if (action == ACTION_NONE && object->What_Am_I() == RTTI_BUILDING && House->IsPlayerControl) {
  2537. StructType blah = *((BuildingClass *)object);
  2538. if (blah == STRUCT_AVMINE || blah == STRUCT_APMINE) return(ACTION_MOVE);
  2539. }
  2540. /*
  2541. ** There is no self-select action available for infantry types.
  2542. */
  2543. if (action == ACTION_SELF) {
  2544. action = ACTION_NONE;
  2545. }
  2546. /*
  2547. ** Check to see if it can enter a transporter.
  2548. */
  2549. if (
  2550. House->Is_Ally(object) &&
  2551. House->IsPlayerControl && object->Is_Techno()) {
  2552. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  2553. if (object->What_Am_I() != RTTI_VESSEL || *(VesselClass *)object != VESSEL_CARRIER) {
  2554. #endif
  2555. switch (((InfantryClass *)this)->Transmit_Message(RADIO_CAN_LOAD, (TechnoClass*)object)) {
  2556. case RADIO_ROGER:
  2557. action = ACTION_ENTER;
  2558. break;
  2559. case RADIO_NEGATIVE:
  2560. action = ACTION_NO_ENTER;
  2561. break;
  2562. default:
  2563. break;
  2564. }
  2565. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  2566. }
  2567. #endif
  2568. }
  2569. if (Class->IsCapture && action == ACTION_ATTACK) {
  2570. if (!House->Is_Ally(object) && (
  2571. //Disable capturing of helicopters (object->What_Am_I() == RTTI_AIRCRAFT && ((AircraftClass *)object)->Pip_Count() == 0 && *((AircraftClass *)object) == AIRCRAFT_TRANSPORT) ||
  2572. (object->What_Am_I() == RTTI_BUILDING && ((BuildingClass *)object)->Class->IsCaptureable) )
  2573. ) {
  2574. if (*this == INFANTRY_THIEF && (object->What_Am_I() == RTTI_BUILDING && ((BuildingClass *)object)->Class->Capacity == 0)) {
  2575. action = ACTION_NONE;
  2576. } else {
  2577. /*
  2578. ** If we're trying to capture a building, make sure we can get
  2579. ** to it. Find an adjacent cell that's the same zone as us.
  2580. ** The target circumstance is a naval yard that doesn't touch
  2581. ** the shore - a total island. In that case, we can't capture
  2582. ** it, so we shouldn't show the action-capture cursor.
  2583. */
  2584. action = ACTION_CAPTURE;
  2585. if (object->What_Am_I() == RTTI_BUILDING) {
  2586. CELL cell = ::As_Cell(object->As_Target());
  2587. int targzone = Map[::As_Cell(As_Target())].Zones[Class->MZone];
  2588. short const *list = ((BuildingClass *)object)->Class->Occupy_List(false);
  2589. bool found = false;
  2590. while (*list != REFRESH_EOL && !found) {
  2591. CELL newcell = cell + *list++;
  2592. for (FacingType i=FACING_N; i < FACING_COUNT; i++) {
  2593. if (Map[Adjacent_Cell(newcell, i)].Zones[Class->MZone] == targzone) {
  2594. found = true;
  2595. break;
  2596. }
  2597. }
  2598. }
  2599. if (!found) {
  2600. action = ACTION_NONE;
  2601. }
  2602. }
  2603. }
  2604. } else {
  2605. if (!Is_Weapon_Equipped()) {
  2606. action = ACTION_NONE;
  2607. }
  2608. }
  2609. }
  2610. /*
  2611. ** If it doesn't know what to do with the object, then just
  2612. ** say it can't move there.
  2613. */
  2614. if (action == ACTION_NONE) action = ACTION_NOMOVE;
  2615. return(action);
  2616. }
  2617. /***********************************************************************************************
  2618. * InfantryClass::Active_Click_With -- Handles action when clicking with infantry soldier. *
  2619. * *
  2620. * This routine is called when the player clicks over an object while this infantry soldier *
  2621. * is selected. Capture attempts are prohibited if the infantry cannot capture. The *
  2622. * command might respond if told to sabotage something. *
  2623. * *
  2624. * INPUT: action -- The action that is nominally to be performed. *
  2625. * *
  2626. * object -- The object over which the mouse was clicked. *
  2627. * *
  2628. * OUTPUT: none *
  2629. * *
  2630. * WARNINGS: none *
  2631. * *
  2632. * HISTORY: *
  2633. * 05/08/1995 JLB : Created. *
  2634. *=============================================================================================*/
  2635. void InfantryClass::Active_Click_With(ActionType action, ObjectClass * object)
  2636. {
  2637. assert(Infantry.ID(this) == ID);
  2638. assert(IsActive);
  2639. action = What_Action(object);
  2640. switch (action) {
  2641. case ACTION_GREPAIR:
  2642. case ACTION_DAMAGE:
  2643. case ACTION_CAPTURE:
  2644. action = ACTION_CAPTURE;
  2645. break;
  2646. case ACTION_HEAL:
  2647. action = ACTION_ATTACK;
  2648. break;
  2649. // case ACTION_ENTER:
  2650. // action = ACTION_MOVE;
  2651. // break;
  2652. case ACTION_SABOTAGE:
  2653. case ACTION_ATTACK:
  2654. case ACTION_GUARD_AREA:
  2655. case ACTION_MOVE:
  2656. action = action;
  2657. break;
  2658. default:
  2659. // action = ACTION_NONE;
  2660. break;
  2661. }
  2662. FootClass::Active_Click_With(action, object);
  2663. }
  2664. /***********************************************************************************************
  2665. * InfantryClass::Set_Occupy_Bit -- Sets the occupy bit cell and bit pos *
  2666. * *
  2667. * INPUT: CELL - the cell we are setting the bit in *
  2668. * *
  2669. * int - the spot index we are setting the bit for *
  2670. * *
  2671. * OUTPUT: none *
  2672. * *
  2673. * HISTORY: *
  2674. * 06/08/1995 PWG : Created. *
  2675. *=============================================================================================*/
  2676. void InfantryClass::Set_Occupy_Bit(CELL cell, int spot_index)
  2677. {
  2678. assert(Infantry.ID(this) == ID);
  2679. assert(IsActive);
  2680. /*
  2681. ** Set the occupy position for the spot that we passed in
  2682. */
  2683. Map[cell].Flag.Composite |= (1 << spot_index);
  2684. /*
  2685. ** Record the type of infantry that now owns the cell
  2686. */
  2687. Map[cell].InfType = Owner();
  2688. }
  2689. /***************************************************************************
  2690. * InfantryClass::Clear_Occupy_Bit -- Clears occupy bit and given cell *
  2691. * *
  2692. * INPUT: *
  2693. * *
  2694. * OUTPUT: *
  2695. * *
  2696. * WARNINGS: *
  2697. * *
  2698. * HISTORY: *
  2699. * 06/08/1995 PWG : Created. *
  2700. *=========================================================================*/
  2701. void InfantryClass::Clear_Occupy_Bit(CELL cell, int spot_index)
  2702. {
  2703. assert(Infantry.ID(this) == ID);
  2704. assert(IsActive);
  2705. /*
  2706. ** Clear the occupy bit for the infantry in that cell
  2707. */
  2708. Map[cell].Flag.Composite &= ~(1 << spot_index);
  2709. /*
  2710. ** If he was the last infantry recorded in the cell then
  2711. ** remove the infantry ownership flag.
  2712. */
  2713. if (!(Map[cell].Flag.Composite & 0x1F)) {
  2714. Map[cell].InfType = HOUSE_NONE;
  2715. }
  2716. }
  2717. /***********************************************************************************************
  2718. * InfantryClass::Full_Name -- Fetches the full name of the infantry unit. *
  2719. * *
  2720. * This routine will return with the full name (as a text number) for this infantry *
  2721. * unit. Typically, this is the normal name, but in cases of civilian type survivors from *
  2722. * a building explosion, it might be a technician instead. In such a case, the special *
  2723. * technician name number is returned instead. *
  2724. * *
  2725. * INPUT: none *
  2726. * *
  2727. * OUTPUT: Returns with the full name to use for this infantry unit. *
  2728. * *
  2729. * WARNINGS: none *
  2730. * *
  2731. * HISTORY: *
  2732. * 06/30/1995 JLB : Created. *
  2733. * 10/28/1996 JLB : Spy returns "enemy soldier" text name. *
  2734. *=============================================================================================*/
  2735. int InfantryClass::Full_Name(void) const
  2736. {
  2737. assert(Infantry.ID(this) == ID);
  2738. assert(IsActive);
  2739. if (IsTechnician) {
  2740. return(TXT_TECHNICIAN);
  2741. }
  2742. if (*this == INFANTRY_SPY && !House->IsPlayerControl) {
  2743. return(TXT_E1);
  2744. }
  2745. return(Class->Full_Name());
  2746. }
  2747. /***********************************************************************************************
  2748. * InfantryClass::Mission_Attack -- Intercept attack mission for special handling. *
  2749. * *
  2750. * This routine intercepts the normal attack mission and if an engineer is detected and the *
  2751. * target is a building, then the engineer will be automatically assigned the capture *
  2752. * mission. In other cases, the normal attack logic will proceed. *
  2753. * *
  2754. * INPUT: none *
  2755. * *
  2756. * OUTPUT: Returns with the number of game frames to delay before calling this routine again. *
  2757. * *
  2758. * WARNINGS: none *
  2759. * *
  2760. * HISTORY: *
  2761. * 08/07/1995 JLB : Created. *
  2762. * 04/15/1996 BWG : Engineers can only attack their own house's buildings now. *
  2763. * 05/29/1996 JLB : Engineers can now damage/capture enemy buildings. *
  2764. *=============================================================================================*/
  2765. int InfantryClass::Mission_Attack(void)
  2766. {
  2767. assert(Infantry.ID(this) == ID);
  2768. assert(IsActive);
  2769. if (Class->IsBomber && As_Building(TarCom)) {
  2770. Assign_Destination(TarCom);
  2771. Assign_Mission(MISSION_SABOTAGE);
  2772. return(1);
  2773. }
  2774. if (Class->IsCapture && As_Building(TarCom) != NULL) {
  2775. Assign_Destination(TarCom);
  2776. Assign_Mission(MISSION_CAPTURE);
  2777. return(1);
  2778. }
  2779. return(FootClass::Mission_Attack());
  2780. }
  2781. /***********************************************************************************************
  2782. * InfantryClass::What_Action -- Determines what action to perform for the cell specified. *
  2783. * *
  2784. * This routine will determine what action to perform if the mouse was clicked on the cell *
  2785. * specified. This is just a courier function since the lower level classes actually *
  2786. * perform the work. The need for this routine at this level is due to the existence of *
  2787. * a similarly named function at this level as well. C++ namespace rules require this *
  2788. * function courier to be in place or an error will result. *
  2789. * *
  2790. * INPUT: cell -- The cell that the mouse might be clicked upon. *
  2791. * *
  2792. * OUTPUT: Returns with the action that would be given to this infantry unit if the mouse *
  2793. * were clicked at the cell specified. *
  2794. * *
  2795. * WARNINGS: none *
  2796. * *
  2797. * HISTORY: *
  2798. * 09/21/1995 JLB : Created. *
  2799. *=============================================================================================*/
  2800. ActionType InfantryClass::What_Action(CELL cell) const
  2801. {
  2802. assert(Infantry.ID(this) == ID);
  2803. assert(IsActive);
  2804. ActionType action = FootClass::What_Action(cell);
  2805. /*
  2806. ** Dogs can only attack infantrymen
  2807. */
  2808. if (Class->IsDog && action == ACTION_ATTACK) {
  2809. action = ACTION_NONE;
  2810. }
  2811. /*
  2812. ** If this is a medic, and the cursor's over a friendly infantryman,
  2813. ** execute an action-attack.
  2814. */
  2815. if (Combat_Damage() < 0 && House->IsPlayerControl) {
  2816. if (action == ACTION_ATTACK) {
  2817. action = ACTION_NOMOVE;
  2818. }
  2819. }
  2820. /*
  2821. ** Demolitioners may destroy a bridge
  2822. */
  2823. if (Class->IsBomber && action == ACTION_MOVE && !Special.IsCaptureTheFlag) {
  2824. switch (Map[cell].TType) {
  2825. case TEMPLATE_BRIDGE1:
  2826. case TEMPLATE_BRIDGE2:
  2827. case TEMPLATE_BRIDGE1H:
  2828. case TEMPLATE_BRIDGE2H:
  2829. case TEMPLATE_BRIDGE_1A:
  2830. case TEMPLATE_BRIDGE_1B:
  2831. case TEMPLATE_BRIDGE_2A:
  2832. case TEMPLATE_BRIDGE_2B:
  2833. // case TEMPLATE_BRIDGE_3A:
  2834. // case TEMPLATE_BRIDGE_3B:
  2835. return(ACTION_SABOTAGE);
  2836. }
  2837. }
  2838. #ifdef OBSOLETE
  2839. /*
  2840. ** Engineers may repair a destroyed bridge.
  2841. */
  2842. if (*this == INFANTRY_RENOVATOR && action == ACTION_NOMOVE) {
  2843. /*
  2844. ** If they're pointing on the wrong side of the bridge, ignore it
  2845. ** 'cause we can't get there.
  2846. */
  2847. TemplateType tt = Map[cell].TType;
  2848. if (tt == TEMPLATE_BRIDGE1D || tt == TEMPLATE_BRIDGE2D ||
  2849. tt == TEMPLATE_BRIDGE_1C || tt == TEMPLATE_BRIDGE_2C ||
  2850. (tt >= TEMPLATE_BRIDGE_3C && tt <= TEMPLATE_BRIDGE_3E) ) {
  2851. /*
  2852. ** We know they're pointing at a destroyed bridge cell. If the cell
  2853. ** they're pointing at is surrounded by impassables, return this
  2854. ** cell as impassable. But, if any cell surrounding this cell is
  2855. ** passable, return that this is a capturable cell.
  2856. */
  2857. if (Map[cell].Land_Type() == LAND_ROCK) {
  2858. if (tt == TEMPLATE_BRIDGE_3C) return(ACTION_CAPTURE);
  2859. if (tt == TEMPLATE_BRIDGE_3C) return(ACTION_CAPTURE);
  2860. int y = Cell_Y(cell);
  2861. if (y) {
  2862. LandType above = Map[(CELL)(cell-(MAP_CELL_W-1))].Land_Type();
  2863. if (above == LAND_CLEAR || above == LAND_ROAD) {
  2864. if (Map[(CELL)(cell-(MAP_CELL_W-1))].Zone == Map[As_Cell(As_Target())].Zone) {
  2865. return(ACTION_CAPTURE);
  2866. }
  2867. return(ACTION_NOMOVE);
  2868. }
  2869. }
  2870. if (y < MAP_CELL_H) {
  2871. LandType below = Map[(CELL)(cell + MAP_CELL_W-1)].Land_Type();
  2872. if (below == LAND_CLEAR || below == LAND_ROAD) {
  2873. if (Map[(CELL)(cell+MAP_CELL_W-1)].Zone == Map[As_Cell(As_Target())].Zone) {
  2874. return(ACTION_CAPTURE);
  2875. }
  2876. return(ACTION_NOMOVE);
  2877. }
  2878. }
  2879. }
  2880. return(ACTION_NOMOVE);
  2881. }
  2882. }
  2883. #endif
  2884. return(action);
  2885. }
  2886. /***********************************************************************************************
  2887. * InfantryClass::Class_Of -- Returns the class reference for this object. *
  2888. * *
  2889. * This routine will return a reference to the infantry type class object that describes *
  2890. * this infantry's characteristics. *
  2891. * *
  2892. * INPUT: none *
  2893. * *
  2894. * OUTPUT: Returns with a reference to the InfantryTypeClass object associated with this *
  2895. * infantry object. *
  2896. * *
  2897. * WARNINGS: none *
  2898. * *
  2899. * HISTORY: *
  2900. * 09/21/1995 JLB : Created. *
  2901. *=============================================================================================*/
  2902. ObjectTypeClass const & InfantryClass::Class_Of(void) const
  2903. {
  2904. assert(Infantry.ID(this) == ID);
  2905. assert(IsActive);
  2906. return(*Class);
  2907. }
  2908. /***********************************************************************************************
  2909. * InfantryClass::Read_INI -- Reads units from scenario INI file. *
  2910. * *
  2911. * This routine is used to read all the starting units from the *
  2912. * scenario control INI file. The units are created and placed on the *
  2913. * map by this routine. *
  2914. * *
  2915. * INI entry format: *
  2916. * Housename, Typename, Strength, Cellnum, CellSublocation, Missionname, *
  2917. * Facingnum, Triggername *
  2918. * *
  2919. * INPUT: buffer -- Pointer to the loaded scenario INI file. *
  2920. * *
  2921. * OUTPUT: none *
  2922. * *
  2923. * WARNINGS: none *
  2924. * *
  2925. * HISTORY: *
  2926. * 05/24/1994 JLB : Created. *
  2927. *=============================================================================================*/
  2928. void InfantryClass::Read_INI(CCINIClass & ini)
  2929. {
  2930. InfantryClass * infantry; // Working infantry pointer.
  2931. HousesType inhouse; // Infantry house.
  2932. InfantryType classid; // Infantry class.
  2933. char buf[128];
  2934. char * validation;
  2935. DirType dir;
  2936. TriggerTypeClass * tp;
  2937. int len = ini.Entry_Count(INI_Name());
  2938. for (int index = 0; index < len; index++) {
  2939. char const * entry = ini.Get_Entry(INI_Name(), index);
  2940. /*
  2941. ** Get an infantry entry
  2942. */
  2943. ini.Get_String(INI_Name(), entry, NULL, buf, sizeof(buf));
  2944. /*
  2945. ** 1st token: house name.
  2946. */
  2947. inhouse = HouseTypeClass::From_Name(strtok(buf, ",\n\r"));
  2948. if (inhouse != HOUSE_NONE) {
  2949. /*
  2950. ** 2nd token: infantry type name.
  2951. */
  2952. classid = InfantryTypeClass::From_Name(strtok(NULL, ",\n\r"));
  2953. if (classid != INFANTRY_NONE) {
  2954. infantry = new InfantryClass(classid, inhouse);
  2955. if (infantry != NULL) {
  2956. /*
  2957. ** 3rd token: strength.
  2958. */
  2959. int strength = atoi(strtok(NULL, ",\n\r"));
  2960. /*
  2961. ** 4th token: cell #.
  2962. */
  2963. CELL cell = atoi(strtok(NULL, ",\n\r"));
  2964. COORDINATE coord = Cell_Coord(cell);
  2965. /*
  2966. ** 5th token: cell sub-location.
  2967. */
  2968. int sub = atoi(strtok(NULL, ","));
  2969. coord = Coord_Add(Coord_Whole(coord), StoppingCoordAbs[ sub ]);
  2970. /*
  2971. ** Fetch the mission and facing.
  2972. */
  2973. MissionType mission = MissionClass::Mission_From_Name(strtok(NULL, ",\n\r"));
  2974. validation = strtok(NULL, ",\n\r");
  2975. if (validation) {
  2976. dir = (DirType)atoi(validation);
  2977. validation = strtok(NULL, ",\n\r");
  2978. if (validation) {
  2979. tp = TriggerTypeClass::From_Name(validation);
  2980. } else {
  2981. tp = NULL;
  2982. }
  2983. } else {
  2984. dir = (DirType)0;
  2985. tp = NULL;
  2986. }
  2987. infantry->Trigger = NULL;
  2988. if (tp != NULL) {
  2989. TriggerClass * tt = Find_Or_Make(tp);
  2990. if (tt != NULL) {
  2991. tt->AttachCount++;
  2992. infantry->Trigger = tt;
  2993. }
  2994. }
  2995. if (infantry->Unlimbo(coord, dir)) {
  2996. infantry->Strength = infantry->Class_Of().MaxStrength * fixed(strength, 256);
  2997. if (infantry->Strength > infantry->Class->MaxStrength-3) infantry->Strength = infantry->Class->MaxStrength;
  2998. // infantry->Strength = Fixed_To_Cardinal(infantry->Class_Of().MaxStrength, strength);
  2999. if (Session.Type == GAME_NORMAL || infantry->House->IsHuman) {
  3000. infantry->Assign_Mission(mission);
  3001. infantry->Commence();
  3002. } else {
  3003. infantry->Enter_Idle_Mode();
  3004. }
  3005. } else {
  3006. /*
  3007. ** If the infantry could not be unlimboed, then this is a big error.
  3008. ** Delete the infantry.
  3009. */
  3010. delete infantry;
  3011. }
  3012. }
  3013. }
  3014. }
  3015. }
  3016. }
  3017. /***********************************************************************************************
  3018. * InfantryClass::Write_INI -- Store the infantry to the INI database. *
  3019. * *
  3020. * This will store all the infantry objects to the INI database specified. *
  3021. * *
  3022. * INPUT: ini -- Reference to the INI database to store the infantry data to. *
  3023. * *
  3024. * OUTPUT: none *
  3025. * *
  3026. * WARNINGS: none *
  3027. * *
  3028. * HISTORY: *
  3029. * 07/03/1996 JLB : Created. *
  3030. *=============================================================================================*/
  3031. void InfantryClass::Write_INI(CCINIClass & ini)
  3032. {
  3033. /*
  3034. ** First, clear out all existing infantry data from the ini file.
  3035. */
  3036. ini.Clear(INI_Name());
  3037. /*
  3038. ** Write the infantry data out.
  3039. */
  3040. for (int index = 0; index < Infantry.Count(); index++) {
  3041. InfantryClass * infantry = Infantry.Ptr(index);
  3042. if (!infantry->IsInLimbo) {
  3043. char uname[10];
  3044. char buf[128];
  3045. sprintf(uname, "%d", index);
  3046. sprintf(buf, "%s,%s,%d,%u,%d,%s,%d,%s",
  3047. infantry->House->Class->IniName,
  3048. infantry->Class->IniName,
  3049. infantry->Health_Ratio()*256,
  3050. Coord_Cell(infantry->Coord),
  3051. CellClass::Spot_Index(infantry->Coord),
  3052. MissionClass::Mission_Name((infantry->Mission == MISSION_NONE) ?
  3053. infantry->MissionQueue : infantry->Mission),
  3054. infantry->PrimaryFacing.Current(),
  3055. infantry->Trigger.Is_Valid() ? infantry->Trigger->Class->IniName : "None"
  3056. );
  3057. ini.Put_String(INI_Name(), uname, buf);
  3058. }
  3059. }
  3060. }
  3061. /***********************************************************************************************
  3062. * InfantryClass::Fear_AI -- Process any fear related affects on this infantry. *
  3063. * *
  3064. * Use this routine to handle the fear logic for this infantry. It will slowly increase *
  3065. * the bravery of the infantry as well as cause it to stand up or lie down as appropriate. *
  3066. * It will even handle the special fraidy cat logic for civilian infantry. *
  3067. * *
  3068. * INPUT: none *
  3069. * *
  3070. * OUTPUT: none *
  3071. * *
  3072. * WARNINGS: Only call this once per game logic loop per infantry unit. *
  3073. * *
  3074. * HISTORY: *
  3075. * 07/29/1996 JLB : Created. *
  3076. *=============================================================================================*/
  3077. void InfantryClass::Fear_AI(void)
  3078. {
  3079. /*
  3080. ** After a time, the infantry will gain courage.
  3081. */
  3082. if (Fear > 0) {
  3083. Fear--;
  3084. /*
  3085. ** When an armed civilian becomes unafraid, he will then reload
  3086. ** another clip into his pistol.
  3087. */
  3088. if (Fear == 0 && Ammo == 0 && Is_Weapon_Equipped()) {
  3089. Ammo = Class->MaxAmmo;
  3090. }
  3091. /*
  3092. ** Stand up if brave and lie down if afraid.
  3093. */
  3094. if (IsProne) {
  3095. if (Fear < FEAR_ANXIOUS) {
  3096. Do_Action(DO_GET_UP);
  3097. }
  3098. } else {
  3099. /*
  3100. ** Drop to the ground if anxious. Don't drop to the ground while moving
  3101. ** and the special elite flag is active.
  3102. */
  3103. if (!Class->IsDog && Height == 0 && Fear >= FEAR_ANXIOUS && ((!Target_Legal(NavCom) && !IsDriving))) {
  3104. Do_Action(DO_LIE_DOWN);
  3105. }
  3106. }
  3107. }
  3108. /*
  3109. ** When in darkness or in doubt,
  3110. ** run in circles, scream, and shout.
  3111. */
  3112. if (Class->IsFraidyCat && Fear > FEAR_ANXIOUS && !IsFalling && !IsDriving && !Target_Legal(NavCom)) {
  3113. Scatter(0, true);
  3114. }
  3115. }
  3116. /***********************************************************************************************
  3117. * InfantryClass::Edge_Of_World_AI -- Detects when infantry has left the map. *
  3118. * *
  3119. * This routine will detect when the infantry has left the edge of the world and will *
  3120. * delete it as necessary. *
  3121. * *
  3122. * INPUT: none *
  3123. * *
  3124. * OUTPUT: bool; Was the infantry unit deleted by this routine? *
  3125. * *
  3126. * WARNINGS: Be sure the check the return value and if true, abort any further processing *
  3127. * for this infantry unit. *
  3128. * *
  3129. * HISTORY: *
  3130. * 07/29/1996 JLB : Created. *
  3131. *=============================================================================================*/
  3132. bool InfantryClass::Edge_Of_World_AI(void)
  3133. {
  3134. /*
  3135. ** Delete this unit if it finds itself off the edge of the map and it is in
  3136. ** guard or other static mission mode.
  3137. */
  3138. if (Team.Is_Valid() && IsLocked) Team->IsLeaveMap = true;
  3139. if (!Team.Is_Valid() && Mission == MISSION_GUARD && !Map.In_Radar(Coord_Cell(Coord))) {
  3140. Stun();
  3141. delete this;
  3142. return(true);
  3143. }
  3144. return(false);
  3145. }
  3146. /***********************************************************************************************
  3147. * InfantryClass::Firing_AI -- Handles firing and combat AI for the infantry. *
  3148. * *
  3149. * This will examine the infantry and determine what firing action is required. It will *
  3150. * search for targets, starting firing animations, and launch bullets as necessary. *
  3151. * *
  3152. * INPUT: none *
  3153. * *
  3154. * OUTPUT: none *
  3155. * *
  3156. * WARNINGS: Only call this routine once per infantry per game logic loop. *
  3157. * *
  3158. * HISTORY: *
  3159. * 07/29/1996 JLB : Created. *
  3160. *=============================================================================================*/
  3161. void InfantryClass::Firing_AI(void)
  3162. {
  3163. if (Target_Legal(TarCom)) {
  3164. int primary = What_Weapon_Should_I_Use(TarCom);
  3165. if (!IsFiring) {
  3166. switch (Can_Fire(TarCom, primary)) {
  3167. case FIRE_ILLEGAL:
  3168. if (Combat_Damage(primary) < 0) {
  3169. ObjectClass * targ= As_Object(TarCom);
  3170. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  3171. if (targ) {
  3172. if( (targ->What_Am_I() == RTTI_INFANTRY && *this == INFANTRY_MEDIC) ||
  3173. (*this == INFANTRY_MECHANIC && (targ->What_Am_I() == RTTI_AIRCRAFT || targ->What_Am_I() == RTTI_UNIT )) ) {
  3174. if (targ->Health_Ratio() >= Rule.ConditionGreen) {
  3175. Assign_Target(TARGET_NONE);
  3176. }
  3177. }
  3178. } else {
  3179. Assign_Target(TARGET_NONE);
  3180. }
  3181. #else
  3182. if (targ && targ->What_Am_I() == RTTI_INFANTRY) {
  3183. if (targ->Health_Ratio() >= Rule.ConditionGreen) {
  3184. Assign_Target(TARGET_NONE);
  3185. }
  3186. } else {
  3187. Assign_Target(TARGET_NONE);
  3188. }
  3189. #endif
  3190. }
  3191. break;
  3192. case FIRE_CLOAKED:
  3193. Do_Uncloak();
  3194. break;
  3195. case FIRE_OK:
  3196. /*
  3197. ** Start firing animation.
  3198. */
  3199. if (IsProne) {
  3200. Do_Action(DO_FIRE_PRONE);
  3201. } else {
  3202. Do_Action(DO_FIRE_WEAPON);
  3203. }
  3204. Mark(MARK_OVERLAP_UP);
  3205. IsFiring = true;
  3206. Mark(MARK_OVERLAP_DOWN);
  3207. PrimaryFacing.Set(Direction8(Center_Coord(), As_Coord(TarCom)));
  3208. /*
  3209. ** If the target is in range, and the NavCom is the same, then just
  3210. ** stop and keep firing.
  3211. */
  3212. if (TarCom == NavCom) {
  3213. NavCom = TARGET_NONE;
  3214. Path[0] = FACING_NONE;
  3215. }
  3216. break;
  3217. }
  3218. }
  3219. /*
  3220. ** If in the middle of firing animation, then only
  3221. ** process that. Infantry cannot fire and move simultaneously.
  3222. ** At some point in the firing animation process, a projectile
  3223. ** will be launched. When the required animation frames have
  3224. ** been completed, the firing animation stops.
  3225. */
  3226. int firestage = Class->FireLaunch;
  3227. if (IsProne) firestage = Class->ProneLaunch;
  3228. if (IsFiring && Fetch_Stage() == firestage) {
  3229. Fire_At(TarCom, primary);
  3230. /*
  3231. ** Run away from slowly approaching projectiles.
  3232. */
  3233. if (Class->PrimaryWeapon->MaxSpeed < Rule.Incoming) {
  3234. Map[::As_Cell(TarCom)].Incoming(Coord, true);
  3235. }
  3236. /*
  3237. ** If it's a dog, get rid of him (he'll be re-created when he hits)
  3238. */
  3239. if (Class->IsDog) {
  3240. WasSelected = IsSelected;
  3241. ScenarioInit++;
  3242. Limbo();
  3243. ScenarioInit--;
  3244. }
  3245. }
  3246. } else {
  3247. if (IsFiring) {
  3248. Mark(MARK_OVERLAP_UP);
  3249. IsFiring = false;
  3250. Mark(MARK_OVERLAP_DOWN);
  3251. }
  3252. }
  3253. }
  3254. /***********************************************************************************************
  3255. * InfantryClass::Doing_AI -- Handles the animation AI processing. *
  3256. * *
  3257. * Infantry can be in one of many different animation sequences. At the conclusion of each *
  3258. * sequence, the infantry will quite likely transition to a new animation state. This *
  3259. * routine handles detecting when that trasition should occur and starting the infantry *
  3260. * into its new state. *
  3261. * *
  3262. * INPUT: none *
  3263. * *
  3264. * OUTPUT: none *
  3265. * *
  3266. * WARNINGS: Only call this routine once per infantry unit per game logic loop. *
  3267. * *
  3268. * HISTORY: *
  3269. * 07/29/1996 JLB : Created. *
  3270. *=============================================================================================*/
  3271. void InfantryClass::Doing_AI(void)
  3272. {
  3273. if (Doing == DO_NOTHING || Fetch_Stage() >= Class->DoControls[Doing].Count) {
  3274. switch (Doing) {
  3275. default:
  3276. if (IsDriving) {
  3277. if (Class->IsDog) {
  3278. /*
  3279. ** Dog crawl animation is actually the run animation.
  3280. */
  3281. if (Target_Legal(TarCom)) {
  3282. Do_Action(DO_CRAWL, true);
  3283. } else {
  3284. Do_Action(DO_WALK, true);
  3285. }
  3286. } else {
  3287. if (IsProne) {
  3288. Do_Action(DO_CRAWL, true);
  3289. } else {
  3290. Do_Action(DO_WALK, true);
  3291. }
  3292. }
  3293. } else {
  3294. if (Class->IsDog) {
  3295. Do_Action(DO_STAND_READY, true);
  3296. } else {
  3297. if (IsProne) {
  3298. Do_Action(DO_PRONE, true);
  3299. } else {
  3300. Do_Action(DO_STAND_READY, true);
  3301. }
  3302. }
  3303. }
  3304. break;
  3305. case DO_DOG_MAUL:
  3306. Do_Action(DO_STAND_READY, true);
  3307. break;
  3308. case DO_GUN_DEATH:
  3309. case DO_EXPLOSION_DEATH:
  3310. case DO_EXPLOSION2_DEATH:
  3311. case DO_GRENADE_DEATH:
  3312. case DO_FIRE_DEATH:
  3313. if (Fetch_Stage() >= Class->DoControls[Doing].Count) {
  3314. if (Doing == DO_GUN_DEATH && !Class->IsDog && Height==0) {
  3315. new AnimClass(ANIM_CORPSE1, Coord_Add(Center_Coord(), XYP_Coord(-2, 4)));
  3316. }
  3317. if (Doing == DO_GRENADE_DEATH && !Class->IsDog && Height==0) {
  3318. new AnimClass(ANIM_CORPSE1, Coord_Add(Center_Coord(), XYP_Coord(-10, 3)));
  3319. }
  3320. if (Doing == DO_EXPLOSION_DEATH && !Class->IsDog && Height==0) {
  3321. new AnimClass(ANIM_CORPSE3, Coord_Add(Center_Coord(), XYP_Coord(-2, 4)));
  3322. }
  3323. if (Doing == DO_EXPLOSION2_DEATH && !Class->IsDog && Height==0) {
  3324. new AnimClass(ANIM_CORPSE2, Center_Coord());
  3325. }
  3326. delete this;
  3327. return;
  3328. }
  3329. }
  3330. }
  3331. }
  3332. /***********************************************************************************************
  3333. * InfantryClass::Movement_AI -- This routine handles all infantry movement logic. *
  3334. * *
  3335. * It examines the infantry state and determines what movement action should be initiated *
  3336. * or processed. It handles the actual movement of the infantry as well as any path finding *
  3337. * or infantry startup logic. *
  3338. * *
  3339. * INPUT: none *
  3340. * *
  3341. * OUTPUT: none *
  3342. * *
  3343. * WARNINGS: Only call this routine once per infantry unit per game logic loop. *
  3344. * *
  3345. * HISTORY: *
  3346. * 07/29/1996 JLB : Created. *
  3347. *=============================================================================================*/
  3348. void InfantryClass::Movement_AI(void)
  3349. {
  3350. /*
  3351. ** Special hack check to ensure that infantry will never get stuck in a movement order if
  3352. ** there is no place to go.
  3353. */
  3354. if (Mission == MISSION_MOVE && !Target_Legal(NavCom)) {
  3355. Enter_Idle_Mode();
  3356. }
  3357. if (!IsFiring && !IsFalling && Doing != DO_DOG_MAUL) {
  3358. if (!IsDriving) {
  3359. /*
  3360. ** When in guard mode, never allow a valid navcom.
  3361. */
  3362. if (Mission == MISSION_GUARD && MissionQueue == MISSION_NONE && Target_Legal(NavCom)) {
  3363. Assign_Destination(TARGET_NONE);
  3364. // if (IsTethered) Scatter(0, true);
  3365. }
  3366. /*
  3367. ** Double check to make sure it doesn't have a movement destination into a zone
  3368. ** that it can't travel to. In such a case, abort the movement process by clearing
  3369. ** the navigation computer.
  3370. */
  3371. if ((!IsZoneCheat || Can_Enter_Cell(Coord_Cell(Coord)) != MOVE_NO) && !IsDriving && !IsTethered && Target_Legal(NavCom) && IsLocked && Map[Coord].Zones[Class->MZone] != Map[As_Cell(NavCom)].Zones[Class->MZone]) {
  3372. // hack: if it's tanya, spy, or engineer, let 'em move there anyway.
  3373. if (!Class->IsCapture && Mission != MISSION_ENTER) {
  3374. // if (*this != INFANTRY_TANYA && *this != INFANTRY_SPY && *this != INFANTRY_RENOVATOR) {
  3375. Assign_Destination(TARGET_NONE);
  3376. }
  3377. }
  3378. /*
  3379. ** A head to coordinate is needed. If there is no path
  3380. ** available, then create one.
  3381. */
  3382. if (Target_Legal(NavCom) && Strength && Mission != MISSION_GUARD) {
  3383. /*
  3384. ** Determine if the next cell in the list is available
  3385. ** to be entered. If not, then abort the path and try
  3386. ** again.
  3387. */
  3388. if (Path[0] != FACING_NONE && Can_Enter_Cell(Adjacent_Cell(Coord_Cell(Center_Coord()), Path[0])) != MOVE_OK) {
  3389. Path[0] = FACING_NONE;
  3390. }
  3391. /*
  3392. ** Check to see if the target is closer than expected. This occurs
  3393. ** when heading toward a moving object and that object is heading
  3394. ** toward the unit. Shorten the precalculated path to be no longer
  3395. ** than the distance to the target.
  3396. */
  3397. int d = Lepton_To_Cell(Distance(NavCom));
  3398. if (d < CONQUER_PATH_MAX) {
  3399. Path[d] = FACING_NONE;
  3400. }
  3401. /*
  3402. ** Find a path to follow if one isn't already calculated.
  3403. */
  3404. if (Path[0] == FACING_NONE) {
  3405. /*
  3406. ** Calculate the path from the current location to the
  3407. ** destination indicated by the navigation computer. If there
  3408. ** was a fundamental error with finding a path, then this
  3409. ** indicates that basic path & movement logic needs to be
  3410. ** aborted.
  3411. */
  3412. if (PathDelay != 0) {
  3413. return;
  3414. }
  3415. if (!Basic_Path()) {
  3416. /*
  3417. ** Check to ensure that if a computer controlled unit is in
  3418. ** hunt mode, but cannot reach the target it would like to,
  3419. ** abort the target tracking and let the normal hunt logic
  3420. ** assign a new one.
  3421. */
  3422. if (!House->IsHuman && Mission == MISSION_HUNT) {
  3423. Assign_Destination(TARGET_NONE);
  3424. Assign_Target(TARGET_NONE);
  3425. } else {
  3426. /*
  3427. ** If the infantry unit is close enough to the target, then
  3428. ** tell it to stop.
  3429. */
  3430. if (Distance(NavCom) < Rule.CloseEnoughDistance && !IsTethered) {
  3431. Assign_Destination(TARGET_NONE);
  3432. } else {
  3433. /*
  3434. ** Update the try try again counter so that this
  3435. ** infantry unit will try again at a later time.
  3436. */
  3437. if (TryTryAgain) {
  3438. TryTryAgain--;
  3439. } else {
  3440. if (IsNewNavCom) Sound_Effect(VOC_SCOLD);
  3441. IsNewNavCom = false;
  3442. /*
  3443. ** Abort the target and destination process since the path
  3444. ** could not be found. In such a case, processing should stop
  3445. ** or else the game will bog down with repeated path failures.
  3446. ** Only perform the abort of the target is in a different zone.
  3447. */
  3448. if ((!IsZoneCheat || Can_Enter_Cell(Coord_Cell(Coord)) != MOVE_NO) && IsLocked && Target_Legal(NavCom) && Map[As_Cell(NavCom)].Zones[Class->MZone] != Map[Coord].Zones[Class->MZone]) {
  3449. Assign_Destination(TARGET_NONE);
  3450. }
  3451. if (IsLocked && Target_Legal(TarCom) && Map[As_Cell(TarCom)].Zones[Class->MZone] != Map[Coord].Zones[Class->MZone]) {
  3452. Assign_Target(TARGET_NONE);
  3453. }
  3454. }
  3455. }
  3456. }
  3457. Stop_Driver();
  3458. return;
  3459. }
  3460. TryTryAgain = PATH_RETRY;
  3461. }
  3462. /*
  3463. ** Determine the coordinate to head to based on the infantry's
  3464. ** current location and the next location in the path.
  3465. */
  3466. COORDINATE acoord = Adjacent_Cell(Coord, Path[0]);
  3467. CELL acell = Coord_Cell(acoord);
  3468. if (Can_Enter_Cell(acell) != MOVE_OK) {
  3469. if ((Mission == MISSION_MOVE || Mission == MISSION_ENTER) && !IsTethered /*&& House->IsHuman*/ && Distance(NavCom) < Rule.CloseEnoughDistance) {
  3470. Assign_Destination(TARGET_NONE);
  3471. } else {
  3472. /*
  3473. ** If blocked by a moving block then just exit start of move and
  3474. ** try again next tick.
  3475. */
  3476. if (Can_Enter_Cell(acell) == MOVE_DESTROYABLE) {
  3477. if (Map[acell].Cell_Object()) {
  3478. if (!House->Is_Ally(Map[acell].Cell_Object())) {
  3479. Override_Mission(MISSION_ATTACK, Map[acell].Cell_Object()->As_Target(), TARGET_NONE);
  3480. }
  3481. } else {
  3482. if (Map[acell].Overlay != OVERLAY_NONE && OverlayTypeClass::As_Reference(Map[acell].Overlay).IsWall) {
  3483. Override_Mission(MISSION_ATTACK, ::As_Target(acell), TARGET_NONE);
  3484. }
  3485. }
  3486. }
  3487. }
  3488. Path[0] = FACING_NONE;
  3489. Stop_Driver();
  3490. if (IsNewNavCom) Sound_Effect(VOC_SCOLD);
  3491. IsNewNavCom = false;
  3492. } else {
  3493. if (Start_Driver(acoord)) {
  3494. if (!IsActive) return;
  3495. PrimaryFacing.Set(Direction8(Center_Coord(), Head_To_Coord()));
  3496. if (IsFormationMove) {
  3497. Set_Speed(Ground[Map[Coord].Land_Type()].Cost[FormationSpeed] * 256);
  3498. } else {
  3499. Set_Speed(0xFF);
  3500. }
  3501. if (Class->IsDog) {
  3502. /*
  3503. ** Dog crawl animation is actually the run animation.
  3504. */
  3505. if (Target_Legal(TarCom)) {
  3506. Do_Action(DO_CRAWL);
  3507. } else {
  3508. Do_Action(DO_WALK);
  3509. }
  3510. } else {
  3511. if (IsProne) {
  3512. Do_Action(DO_CRAWL);
  3513. } else {
  3514. Do_Action(DO_WALK);
  3515. }
  3516. }
  3517. }
  3518. }
  3519. }
  3520. } else {
  3521. /*
  3522. ** The infantry knows where it should be headed, so head there. Check
  3523. ** to see if the infantry is "close enough" to the desired location that
  3524. ** it should just consider itself to have arrived. In this case, force
  3525. ** the infantry to the destination location and mark this path step
  3526. ** as complete.
  3527. */
  3528. Mark(MARK_UP);
  3529. if (Distance(Head_To_Coord()) < 0x0010) {
  3530. memcpy(&Path[0], &Path[1], sizeof(Path)-sizeof(Path[0]));
  3531. Path[(sizeof(Path)/sizeof(Path[0]))-1] = FACING_NONE;
  3532. Coord = Head_To_Coord();
  3533. Per_Cell_Process(PCP_END);
  3534. if (!IsActive || IsInLimbo) return;
  3535. Stop_Driver();
  3536. if (!IsActive || IsInLimbo) return;
  3537. if (Coord_Cell(Coord) == As_Cell(NavCom)) {
  3538. NavCom = TARGET_NONE;
  3539. if (Mission == MISSION_MOVE) {
  3540. Enter_Idle_Mode();
  3541. }
  3542. //Stop_Driver();
  3543. Path[0] = FACING_NONE;
  3544. }
  3545. } else {
  3546. int movespeed = Speed;
  3547. /*
  3548. ** When prone, the infantry moves at half speed or double
  3549. ** speed. This depends on whether the infantry actually has
  3550. ** prone animation stages. Civilians don't, and so they
  3551. ** run instead.
  3552. */
  3553. if (Class->IsDog && Target_Legal(TarCom)) {
  3554. movespeed *= 2;
  3555. }
  3556. if (IsProne && !Class->IsDog) {
  3557. if ((Class->IsFraidyCat && !Class->IsCrawling) ) {
  3558. movespeed = Speed*2;
  3559. } else {
  3560. movespeed = Speed/2;
  3561. }
  3562. }
  3563. if (IsTethered) {
  3564. Transmit_Message(RADIO_REDRAW);
  3565. }
  3566. /*
  3567. ** Advance the infantry as far as it should go.
  3568. */
  3569. MPHType maxspeed = MPHType(min(Class->MaxSpeed * SpeedBias * House->GroundspeedBias, MPH_LIGHT_SPEED));
  3570. if (IsFormationMove) maxspeed = FormationMaxSpeed;
  3571. Coord = Coord_Move(Coord, Direction(Head_To_Coord()), maxspeed * fixed(movespeed, 256));
  3572. }
  3573. Mark(MARK_DOWN);
  3574. }
  3575. IsNewNavCom = false;
  3576. }
  3577. }
  3578. /***********************************************************************************************
  3579. * InfantryClass::Get_Image_Data -- Fetches the image data for this infantry unit. *
  3580. * *
  3581. * The image data for the infantry differs from normal if this is a spy. A spy always *
  3582. * appears like a minigunner to the non-owning players. *
  3583. * *
  3584. * INPUT: none *
  3585. * *
  3586. * OUTPUT: Returns with a pointer to the image data to use for this infantry soldier. *
  3587. * *
  3588. * WARNINGS: none *
  3589. * *
  3590. * HISTORY: *
  3591. * 08/06/1996 JLB : Created. *
  3592. *=============================================================================================*/
  3593. void const * InfantryClass::Get_Image_Data(void) const
  3594. {
  3595. if (!IsOwnedByPlayer && *this == INFANTRY_SPY) {
  3596. return(MFCD::Retrieve("E1.SHP"));
  3597. }
  3598. return(TechnoClass::Get_Image_Data());
  3599. }
  3600. /***********************************************************************************************
  3601. * InfantryClass::Is_Ready_To_Random_Anima -- Checks to see if it is ready to perform an idle *
  3602. * *
  3603. * This routine will examine this infantry and determine if it is allowed and ready to *
  3604. * perform an idle animation. The conditions under which idle animations can be performed *
  3605. * are restrictive. Hence this routine. *
  3606. * *
  3607. * INPUT: none *
  3608. * *
  3609. * OUTPUT: bool; Is this infantry ready to do an idle animation? *
  3610. * *
  3611. * WARNINGS: none *
  3612. * *
  3613. * HISTORY: *
  3614. * 10/01/1996 JLB : Created. *
  3615. *=============================================================================================*/
  3616. bool InfantryClass::Is_Ready_To_Random_Animate(void) const
  3617. {
  3618. /*
  3619. ** See if the base classes (more rudimentary checking) determines that idle animations
  3620. ** cannot occur. If they cannot, then return with the failure code.
  3621. */
  3622. if (!FootClass::Is_Ready_To_Random_Animate()) {
  3623. return(false);
  3624. }
  3625. /*
  3626. ** While the infantry is in the air (such as when paradropping), it won't be allowed
  3627. ** to idle animate.
  3628. */
  3629. if (Height > 0) {
  3630. return(false);
  3631. }
  3632. /*
  3633. ** When the infantry is walking or otherwise engauged in travel, it won't idle animate.
  3634. */
  3635. if (IsDriving) {
  3636. return(false);
  3637. }
  3638. /*
  3639. ** When prone, idle animations cannot occur. This is primarily because there are no prone
  3640. ** idle animations.
  3641. */
  3642. if (IsProne) {
  3643. return(false);
  3644. }
  3645. /*
  3646. ** When firing, the infantry should not perform any idle animations.
  3647. */
  3648. if (IsFiring) {
  3649. return(false);
  3650. }
  3651. /*
  3652. ** Only if the infantry is in guard or ready stance is idle animations allowed. This is
  3653. ** because the idle animations start and end with these frames.
  3654. */
  3655. if (Doing != DO_STAND_GUARD && Doing != DO_STAND_READY) {
  3656. return(false);
  3657. }
  3658. /*
  3659. ** Since no reason was found to indicate it is not a good time to idle
  3660. ** animate, then it must be a good time to do so.
  3661. */
  3662. return(true);
  3663. }
  3664. /***********************************************************************************************
  3665. * InfantryClass::Paradrop -- Handles paradropping infantry. *
  3666. * *
  3667. * This routine will paradrop this soldier at the location specified. It will cause the *
  3668. * soldier to hunt if controlled by the computer and to guard if controlledy by the *
  3669. * human. *
  3670. * *
  3671. * INPUT: coord -- The coordinate to paradrop the soldier to. *
  3672. * *
  3673. * OUTPUT: bool; Was the paradrop successful? *
  3674. * *
  3675. * WARNINGS: none *
  3676. * *
  3677. * HISTORY: *
  3678. * 10/19/1996 JLB : Created. *
  3679. *=============================================================================================*/
  3680. bool InfantryClass::Paradrop(COORDINATE coord)
  3681. {
  3682. if (FootClass::Paradrop(coord)) {
  3683. if (House->IsHuman) {
  3684. Assign_Mission(MISSION_GUARD);
  3685. } else {
  3686. Assign_Mission(MISSION_HUNT);
  3687. }
  3688. return(true);
  3689. }
  3690. return(false);
  3691. }