INFANTRY.CPP 176 KB

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