soldier.cpp 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/soldier.cpp $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 3/29/02 4:58p $*
  29. * *
  30. * $Revision:: 570 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "soldier.h"
  36. #include "debug.h"
  37. #include "pscene.h"
  38. #include "combat.h"
  39. #include "weapons.h"
  40. #include "damage.h"
  41. #include "humanphys.h"
  42. #include "animcontrol.h"
  43. #include "rendobj.h"
  44. #include "wwpacket.h"
  45. #include "assets.h"
  46. #include "gameobjmanager.h"
  47. #include "vehicle.h"
  48. #include "c4.h"
  49. #include "objlibrary.h"
  50. #include "physicalgameobj.h"
  51. #include "persistfactory.h"
  52. #include "combatchunkid.h"
  53. #include "definition.h"
  54. #include "simpledefinitionfactory.h"
  55. #include "wwhack.h"
  56. #include "surfaceeffects.h"
  57. #include "weaponmanager.h"
  58. #include "weaponbag.h"
  59. #include "physcoltest.h"
  60. #include "htree.h"
  61. #include "animobj.h"
  62. #include "wwaudio.h"
  63. #include "soldierobserver.h"
  64. #include "playertype.h"
  65. #include "crandom.h"
  66. #include "ccamera.h"
  67. #include "bitpackids.h"
  68. #include "translatedb.h"
  69. #include "translateobj.h"
  70. #include "hlod.h"
  71. #include "audiblesound.h"
  72. #include "wwprofile.h"
  73. #include "globalsettings.h"
  74. #include "colors.h"
  75. #include "input.h"
  76. #include "gametype.h"
  77. #include "messagewindow.h"
  78. #include "conversationmgr.h"
  79. #include "activeconversation.h"
  80. #include "bones.h"
  81. #include "dynamicspeechanim.h"
  82. #include "hudinfo.h"
  83. #include "powerup.h"
  84. #include "diaglog.h"
  85. #include "vistable.h"
  86. #include "crandom.h"
  87. #include "transitioneffect.h"
  88. #include "combatmaterialeffectmanager.h"
  89. #include "explosion.h"
  90. #include "playerdata.h"
  91. #include "encyclopediamgr.h"
  92. #include "apppackettypes.h"
  93. #include "hud.h"
  94. #include "unitcoordinationzonemgr.h"
  95. #include "specialbuilds.h"
  96. #include "weaponview.h"
  97. #include "ffactory.h"
  98. #include "realcrc.h"
  99. /*
  100. **
  101. */
  102. #define GUN_BONE_NAME "GUNBONE"
  103. #define BACK_GUN_BONE_NAME "BACKGUNBONE"
  104. #define POKE_ANGLE DEG_TO_RAD( 22 )
  105. #define AMBUSH_DAMAGE_SCALE 1
  106. const float EMOT_ICON_HEIGHT = 2.0F;
  107. /*
  108. ** SoldierGameObjDef
  109. */
  110. DECLARE_FORCE_LINK( Soldier )
  111. SimplePersistFactoryClass<SoldierGameObjDef, CHUNKID_GAME_OBJECT_DEF_SOLDIER> _SoldierGameObjDefPersistFactory;
  112. DECLARE_DEFINITION_FACTORY(SoldierGameObjDef, CLASSID_GAME_OBJECT_DEF_SOLDIER, "Soldier") _SoldierGameObjDefDefFactory;
  113. SoldierGameObjDef::SoldierGameObjDef( void ) :
  114. TurnRate( DEG_TO_RADF( 360.0f ) ),
  115. JumpVelocity( 2 ),
  116. SkeletonHeight( 0 ),
  117. SkeletonWidth( 0 ),
  118. UseInnateBehavior( true ),
  119. InnateAggressiveness( 0.5f ),
  120. InnateTakeCoverProbability( 0.5f ),
  121. InnateIsStationary( false ),
  122. HumanAnimOverrideDefID( 0 ),
  123. HumanLoiterCollectionDefID( 0 ),
  124. DeathSoundPresetID( 0 )
  125. {
  126. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_ANGLE, TurnRate );
  127. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_FLOAT, JumpVelocity );
  128. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_FLOAT, SkeletonHeight );
  129. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_FLOAT, SkeletonWidth );
  130. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_BOOL, UseInnateBehavior );
  131. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_FLOAT, InnateAggressiveness );
  132. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_FLOAT, InnateTakeCoverProbability );
  133. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_BOOL, InnateIsStationary );
  134. EDITABLE_PARAM( SoldierGameObjDef, ParameterClass::TYPE_FILENAME, FirstPersonHands );
  135. GENERIC_DEFID_PARAM( SoldierGameObjDef, HumanAnimOverrideDefID, CLASSID_GLOBAL_SETTINGS_DEF_HUMAN_ANIM_OVERRIDE );
  136. GENERIC_DEFID_PARAM( SoldierGameObjDef, HumanLoiterCollectionDefID, CLASSID_GLOBAL_SETTINGS_DEF_HUMAN_LOITER );
  137. GENERIC_DEFID_PARAM( SoldierGameObjDef, DeathSoundPresetID, CLASSID_SOUND );
  138. MODEL_DEF_PARAM( SoldierGameObjDef, PhysDefID, "HumanPhysDef" );
  139. //
  140. // We want soldiers to use innate conversations by default
  141. //
  142. AllowInnateConversations = true;
  143. return ;
  144. }
  145. uint32 SoldierGameObjDef::Get_Class_ID (void) const
  146. {
  147. return CLASSID_GAME_OBJECT_DEF_SOLDIER;
  148. }
  149. PersistClass * SoldierGameObjDef::Create( void ) const
  150. {
  151. SoldierGameObj * obj = new SoldierGameObj;
  152. obj->Init( *this );
  153. return obj;
  154. }
  155. enum {
  156. CHUNKID_DEF_PARENT = 909991656,
  157. CHUNKID_DEF_VARIABLES,
  158. CHUNKID_DEF_DIALOG_ENTRY,
  159. MICROCHUNKID_DEF_TURN_RATE = 1,
  160. MICROCHUNKID_DEF_JUMP_VELOCITY,
  161. MICROCHUNKID_DEF_SKELETON_HEIGHT,
  162. MICROCHUNKID_DEF_SKELETON_WIDTH,
  163. MICROCHUNKID_DEF_USE_INNATE_BEHAVIOR,
  164. MICROCHUNKID_DEF_INNATE_AGGRESSIVENESS,
  165. MICROCHUNKID_DEF_INNATE_TAKE_COVER_PROB,
  166. XXXMICROCHUNKID_DEF_INNATE_ESCORT_ID,
  167. XXXMICROCHUNKID_DEF_INNATE_ESCORT_RANGE,
  168. MICROCHUNKID_DEF_FIRST_PERSON_HANDS,
  169. XXXMICROCHUNKID_DEF_CORPSE_PERSIST_TIME,
  170. MICROCHUNKID_DEF_USE_INNATE_CONVERSATIONS,
  171. MICROCHUNKID_DEF_INNATE_IS_STATIONARY,
  172. MICROCHUNKID_DEF_ORATOR_TYPE,
  173. MICROCHUNKID_DEF_HUMAN_ANIM_OVERRIDE_DEF_ID,
  174. MICROCHUNKID_DEF_DEATH_SOUND_PRESET,
  175. MICROCHUNKID_DEF_HUMAN_LOITER_COLLECTION_DEF_ID,
  176. };
  177. bool SoldierGameObjDef::Save( ChunkSaveClass & csave )
  178. {
  179. csave.Begin_Chunk( CHUNKID_DEF_PARENT );
  180. SmartGameObjDef::Save( csave );
  181. csave.End_Chunk();
  182. //
  183. // Save the dialog entries
  184. //
  185. for (int index = 0; index < DIALOG_MAX; index ++) {
  186. csave.Begin_Chunk( CHUNKID_DEF_DIALOG_ENTRY );
  187. DialogList[index].Save (csave);
  188. csave.End_Chunk();
  189. }
  190. csave.Begin_Chunk( CHUNKID_DEF_VARIABLES );
  191. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_TURN_RATE, TurnRate );
  192. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_JUMP_VELOCITY, JumpVelocity );
  193. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_SKELETON_HEIGHT, SkeletonHeight );
  194. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_SKELETON_WIDTH, SkeletonWidth );
  195. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_USE_INNATE_BEHAVIOR, UseInnateBehavior );
  196. //WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_USE_INNATE_CONVERSATIONS, UseInnateConversations );
  197. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_INNATE_AGGRESSIVENESS, InnateAggressiveness );
  198. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_INNATE_TAKE_COVER_PROB, InnateTakeCoverProbability );
  199. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_INNATE_IS_STATIONARY, InnateIsStationary );
  200. WRITE_MICRO_CHUNK_WWSTRING( csave, MICROCHUNKID_DEF_FIRST_PERSON_HANDS, FirstPersonHands );
  201. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_HUMAN_ANIM_OVERRIDE_DEF_ID, HumanAnimOverrideDefID );
  202. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_HUMAN_LOITER_COLLECTION_DEF_ID, HumanLoiterCollectionDefID );
  203. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DEF_DEATH_SOUND_PRESET, DeathSoundPresetID );
  204. csave.End_Chunk();
  205. return true;
  206. }
  207. bool SoldierGameObjDef::Load( ChunkLoadClass &cload )
  208. {
  209. int dialog_index = 0;
  210. while (cload.Open_Chunk()) {
  211. switch(cload.Cur_Chunk_ID()) {
  212. case CHUNKID_DEF_PARENT:
  213. SmartGameObjDef::Load( cload );
  214. break;
  215. case CHUNKID_DEF_DIALOG_ENTRY:
  216. if (dialog_index < DIALOG_MAX) {
  217. DialogList[dialog_index++].Load (cload);
  218. }
  219. break;
  220. case CHUNKID_DEF_VARIABLES:
  221. while (cload.Open_Micro_Chunk()) {
  222. switch(cload.Cur_Micro_Chunk_ID()) {
  223. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_TURN_RATE, TurnRate );
  224. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_JUMP_VELOCITY, JumpVelocity );
  225. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_SKELETON_HEIGHT, SkeletonHeight );
  226. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_SKELETON_WIDTH, SkeletonWidth );
  227. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_USE_INNATE_BEHAVIOR, UseInnateBehavior );
  228. //READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_USE_INNATE_CONVERSATIONS, UseInnateConversations );
  229. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_INNATE_AGGRESSIVENESS, InnateAggressiveness );
  230. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_INNATE_TAKE_COVER_PROB, InnateTakeCoverProbability );
  231. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_INNATE_IS_STATIONARY, InnateIsStationary );
  232. READ_MICRO_CHUNK_WWSTRING( cload, MICROCHUNKID_DEF_FIRST_PERSON_HANDS, FirstPersonHands );
  233. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_ORATOR_TYPE, OratorType );
  234. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_HUMAN_ANIM_OVERRIDE_DEF_ID, HumanAnimOverrideDefID );
  235. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_HUMAN_LOITER_COLLECTION_DEF_ID, HumanLoiterCollectionDefID );
  236. READ_MICRO_CHUNK( cload, MICROCHUNKID_DEF_DEATH_SOUND_PRESET, DeathSoundPresetID );
  237. default:
  238. //Debug_Say(( "Unrecognized SoldierDef Variable chunkID\n" ));
  239. break;
  240. }
  241. cload.Close_Micro_Chunk();
  242. }
  243. break;
  244. default:
  245. Debug_Say(( "Unrecognized SoldierDef chunkID\n" ));
  246. break;
  247. }
  248. cload.Close_Chunk();
  249. }
  250. return true;
  251. }
  252. const PersistFactoryClass & SoldierGameObjDef::Get_Factory (void) const
  253. {
  254. return _SoldierGameObjDefPersistFactory;
  255. }
  256. /*
  257. ** SolderGameObj
  258. */
  259. SimplePersistFactoryClass<SoldierGameObj, CHUNKID_GAME_OBJECT_SOLDIER> _SoldierGameObjPersistFactory;
  260. const PersistFactoryClass & SoldierGameObj::Get_Factory (void) const
  261. {
  262. return _SoldierGameObjPersistFactory;
  263. }
  264. //------------------------------------------------------------------------------------
  265. bool SoldierGameObj::DisplayDebugBoxForGhostCollision = false;
  266. //------------------------------------------------------------------------------------
  267. SoldierGameObj::SoldierGameObj() :
  268. WeaponRenderModel( NULL ),
  269. BackWeaponRenderModel( NULL ),
  270. BackFlagRenderModel( NULL ),
  271. WeaponAnimControl( NULL ),
  272. TransitionCompletionData( NULL ),
  273. Vehicle( NULL ),
  274. LegFacing( 0 ),
  275. SyncLegs( false ),
  276. LastLegMode( 0 ),
  277. HeadLookDuration( 0 ),
  278. HeadRotation( 0,0,0 ),
  279. HeadLookTarget( 0,0,0 ),
  280. HeadLookAngle( 0,0,0 ),
  281. HeadLookAngleTimer( 0 ),
  282. InnateEnableBits( 0xFFFFFFFF ),
  283. InnateObserver( NULL ),
  284. // FlameTimer( 0 ),
  285. SpecialDamageMode(ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_NONE),
  286. SpecialDamageTimer( 0 ),
  287. GenerateIdleFacialAnimTimer( 0 ),
  288. KeyRing( 0 ),
  289. InFlyMode( false ),
  290. IsVisible( true ),
  291. CurrentSpeech( NULL ),
  292. AIState( AI_STATE_IDLE ),
  293. SpeechAnim( NULL ),
  294. HeadModel( NULL ),
  295. EmotIconModel( NULL ),
  296. EmotIconTimer( 0 ),
  297. LadderUpMask( false ),
  298. LadderDownMask( false ),
  299. SpecialDamageEffect( NULL ),
  300. HealingEffect( NULL ),
  301. ReloadingTilt(0),
  302. WaterWake(NULL),
  303. WeaponChanged( false )
  304. {
  305. // All Humans need a HuamnAnimControl
  306. Set_Anim_Control( new HumanAnimControlClass );
  307. Set_App_Packet_Type(APPPACKETTYPE_SOLDIER);
  308. // create a water wake object
  309. WaterWake = SurfaceEffectsManager::Create_Persistant_Emitter();
  310. }
  311. //------------------------------------------------------------------------------------
  312. SoldierGameObj::~SoldierGameObj()
  313. {
  314. if ( HealingEffect != NULL ) {
  315. Peek_Human_Phys()->Remove_Effect_From_Me( HealingEffect );
  316. REF_PTR_RELEASE( HealingEffect );
  317. }
  318. Set_Special_Damage_Mode( ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_NONE );
  319. Set_Emot_Icon (NULL, 0);
  320. REF_PTR_RELEASE( HeadModel );
  321. REF_PTR_RELEASE( SpeechAnim );
  322. REF_PTR_RELEASE( CurrentSpeech );
  323. if (CombatManager::I_Am_Server()) {
  324. CombatManager::On_Soldier_Death(this);
  325. }
  326. Set_Weapon_Model( NULL );
  327. if ( BackWeaponRenderModel != NULL ) {
  328. Peek_Model()->Remove_Sub_Object(BackWeaponRenderModel);
  329. BackWeaponRenderModel->Release_Ref();
  330. BackWeaponRenderModel = NULL;
  331. }
  332. if ( BackFlagRenderModel != NULL ) {
  333. Peek_Model()->Remove_Sub_Object(BackFlagRenderModel);
  334. BackFlagRenderModel->Release_Ref();
  335. BackFlagRenderModel = NULL;
  336. }
  337. if ( WeaponAnimControl != NULL ) {
  338. delete WeaponAnimControl;
  339. WeaponAnimControl = NULL;
  340. }
  341. if (Vehicle != NULL) {
  342. // Remove myself from the vehicle !
  343. Vehicle->Remove_Occupant(this);
  344. }
  345. COMBAT_SCENE->Remove_Object( Peek_Physical_Object() );
  346. if ( Is_Human_Controlled() ) {
  347. GameObjManager::Remove_Star( this );
  348. }
  349. Reset_RenderObjs();
  350. if (WaterWake != NULL) {
  351. SurfaceEffectsManager::Destroy_Persistant_Emitter( WaterWake );
  352. WaterWake = NULL;
  353. }
  354. return ;
  355. }
  356. //------------------------------------------------------------------------------------
  357. void SoldierGameObj::Init( void )
  358. {
  359. Re_Init( Get_Definition() );
  360. return ;
  361. }
  362. void SoldierGameObj::Init( const SoldierGameObjDef & definition )
  363. {
  364. SmartGameObj::Init( definition );
  365. Copy_Settings( definition );
  366. return ;
  367. }
  368. void SoldierGameObj::Copy_Settings( const SoldierGameObjDef & definition )
  369. {
  370. HumanState.Init( Peek_Human_Phys() );
  371. HumanState.Set_Anim_Control( (HumanAnimControlClass *)Get_Anim_Control() ); // Must set the anim control after the phys object
  372. //HumanState.Set_Human_Anim_Override( "HAO Test" );
  373. if ( Get_Definition().HumanAnimOverrideDefID != 0 ) {
  374. HumanState.Set_Human_Anim_Override( Get_Definition().HumanAnimOverrideDefID );
  375. }
  376. if ( Get_Definition().HumanLoiterCollectionDefID != 0 ) {
  377. HumanState.Set_Human_Loiter_Collection( Get_Definition().HumanLoiterCollectionDefID );
  378. }
  379. Adjust_Skeleton( definition.SkeletonHeight, definition.SkeletonWidth );
  380. // All characters force their heads and hands to use the same LOD level as their body.
  381. RenderObjClass * model = Peek_Human_Phys()->Peek_Model();
  382. if (model != NULL) {
  383. model->Set_Sub_Objects_Match_LOD(true);
  384. }
  385. if ( InnateObserver == NULL &&
  386. Get_Definition().UseInnateBehavior &&
  387. Is_Controlled_By_Me () == false ) {
  388. InnateObserver = new SoldierObserverClass;
  389. Insert_Observer( InnateObserver );
  390. }
  391. //
  392. // Copy the dialog entries from the definition
  393. //
  394. for( int index = 0; index < DIALOG_MAX; index ++ ) {
  395. DialogList[index] = definition.DialogList[index];
  396. }
  397. //
  398. // Put the soldier in its own collision group
  399. //
  400. Peek_Physical_Object ()->Set_Collision_Group( SOLDIER_COLLISION_GROUP );
  401. Prepare_Speech_Framework ();
  402. return ;
  403. }
  404. void SoldierGameObj::Prepare_Speech_Framework( void )
  405. {
  406. //
  407. // Make sure we have an allocated animation to use for speech
  408. //
  409. if ( SpeechAnim == NULL) {
  410. HeadModel = Find_Head_Model();
  411. //
  412. // Dig out the skeleton name for the head model
  413. //
  414. if (HeadModel != NULL) {
  415. const HTreeClass *htree = HeadModel->Get_HTree ();
  416. if (htree != NULL) {
  417. StringClass skeleton_name = htree->Get_Name ();
  418. //
  419. // Generate the animation
  420. //
  421. SpeechAnim = new DynamicSpeechAnimClass (skeleton_name);
  422. GenerateIdleFacialAnimTimer = 0;
  423. }
  424. }
  425. }
  426. return ;
  427. }
  428. void SoldierGameObj::Re_Init( const SoldierGameObjDef & definition )
  429. {
  430. if ( this == COMBAT_STAR ) {
  431. HUDClass::Force_Weapon_Chart_Update();
  432. WeaponViewClass::Reset();
  433. }
  434. //
  435. // Remove the object from the world (just to be safe)
  436. //
  437. COMBAT_SCENE->Remove_Object( Peek_Physical_Object() );
  438. //
  439. // Reset the weapon model
  440. //
  441. Set_Weapon_Model( NULL );
  442. if ( BackWeaponRenderModel != NULL ) {
  443. Peek_Model()->Remove_Sub_Object(BackWeaponRenderModel);
  444. BackWeaponRenderModel->Release_Ref();
  445. BackWeaponRenderModel = NULL;
  446. }
  447. if ( BackFlagRenderModel != NULL ) {
  448. Peek_Model()->Remove_Sub_Object(BackFlagRenderModel);
  449. BackFlagRenderModel->Release_Ref();
  450. BackFlagRenderModel = NULL;
  451. }
  452. if ( WeaponAnimControl != NULL ) {
  453. delete WeaponAnimControl;
  454. WeaponAnimControl = NULL;
  455. }
  456. //
  457. // Re-initialize the base class
  458. //
  459. SmartGameObj::Re_Init( definition );
  460. //
  461. // Free some of the data we will be re-initializing
  462. //
  463. REF_PTR_RELEASE( HeadModel );
  464. REF_PTR_RELEASE( SpeechAnim );
  465. REF_PTR_RELEASE( CurrentSpeech );
  466. HumanState.Reset();
  467. //
  468. // Copy any internal settings from the definition
  469. //
  470. Copy_Settings( definition );
  471. //
  472. // "Dirty" the object for networking
  473. //
  474. Set_Object_Dirty_Bit( NetworkObjectClass::BIT_RARE, true );
  475. // When class changes, update for new weapon
  476. if ( this == COMBAT_STAR ) {
  477. HUDClass::Reset();
  478. }
  479. return ;
  480. }
  481. //------------------------------------------------------------------------------------
  482. const SoldierGameObjDef & SoldierGameObj::Get_Definition( void ) const
  483. {
  484. return (const SoldierGameObjDef &)BaseGameObj::Get_Definition();
  485. }
  486. void SoldierGameObj::Set_Control_Owner(int control_owner)
  487. {
  488. if ( Is_Human_Controlled() ) {
  489. GameObjManager::Remove_Star( this );
  490. }
  491. SmartGameObj::Set_Control_Owner(control_owner);
  492. if ( Is_Human_Controlled() ) {
  493. GameObjManager::Add_Star( this );
  494. }
  495. }
  496. /*
  497. ** Soldier Save and Load
  498. */
  499. enum {
  500. CHUNKID_PARENT = 909991656,
  501. CHUNKID_VARIABLES,
  502. CHUNKID_WEAPON_ANIM,
  503. CHUNKID_HUMAN_STATE,
  504. XXXCHUNKID_C4_TIMER,
  505. XXXCHUNKID_WEAPON_MODEL,
  506. CHUNKID_TRANSITION_COMPLETION_DATA,
  507. CHUNKID_DIALOG_ENTRY,
  508. CHUNKID_RENDER_OBJS,
  509. CHUNKID_SPECIAL_DAMAGE_DAMAGER,
  510. MICROCHUNKID_DETONATE_C4 = 1,
  511. MICROCHUNKID_LEG_FACING,
  512. MICROCHUNKID_SYNC_LEGS,
  513. MICROCHUNKID_ANIMATION_NAME,
  514. MICROCHUNKID_VEHICLE,
  515. XXX_MICROCHUNKID_TRANSITION,
  516. XXX_MICROCHUNKID_FORCE_FACING,
  517. MICROCHUNKID_INNATE_ENABLE_BITS,
  518. MICROCHUNKID_INNATE_OBSERVER_PTR,
  519. MICROCHUNKID_LAST_LEG_MODE,
  520. MICROCHUNKID_HEAD_LOOK_DURATION,
  521. MICROCHUNKID_HEAD_ROTATION,
  522. MICROCHUNKID_LOOK_TARGET,
  523. XXXMICROCHUNKID_FLAME_TIMER,
  524. MICROCHUNKID_KEY_RING,
  525. MICROCHUNKID_AI_STATE,
  526. XXX_MICROCHUNKID_IN_CONVERSATION,
  527. MICROCHUNKID_LOOK_ANGLE,
  528. MICROCHUNKID_LOOK_ANGLE_TIMER,
  529. XXX_MICROCHUNKID_ACTIVE_CONVERSATION,
  530. MICROCHUNKID_WEAPON_MODEL,
  531. MICROCHUNKID_SPECIAL_DAMAGE_MODE,
  532. MICROCHUNKID_SPECIAL_DAMAGE_TIMER,
  533. MICROCHUNKID_IS_USING_GHOST_COLLISION
  534. };
  535. //------------------------------------------------------------------------------------
  536. bool SoldierGameObj::Save( ChunkSaveClass & csave )
  537. {
  538. csave.Begin_Chunk( CHUNKID_PARENT );
  539. SmartGameObj::Save( csave );
  540. csave.End_Chunk();
  541. //
  542. // Save the dialog entries
  543. //
  544. for (int index = 0; index < DIALOG_MAX; index ++) {
  545. csave.Begin_Chunk( CHUNKID_DIALOG_ENTRY );
  546. DialogList[index].Save (csave);
  547. csave.End_Chunk();
  548. }
  549. csave.Begin_Chunk( CHUNKID_VARIABLES );
  550. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_DETONATE_C4, DetonateC4 );
  551. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_LEG_FACING, LegFacing );
  552. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_SYNC_LEGS, SyncLegs );
  553. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_KEY_RING, KeyRing );
  554. // WRITE_MICRO_CHUNK( csave, MICROCHUNKID_FORCE_FACING, ForceFacing );
  555. if ( Vehicle != NULL ) {
  556. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_VEHICLE, Vehicle );
  557. }
  558. csave.Begin_Micro_Chunk( MICROCHUNKID_ANIMATION_NAME );
  559. char anim_string[80];
  560. strcpy( anim_string, AnimationName );
  561. csave.Write( anim_string, strlen( anim_string ) + 1);
  562. csave.End_Micro_Chunk();
  563. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_INNATE_ENABLE_BITS, InnateEnableBits );
  564. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_INNATE_OBSERVER_PTR, InnateObserver );
  565. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_LAST_LEG_MODE, LastLegMode );
  566. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_HEAD_LOOK_DURATION, HeadLookDuration );
  567. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_HEAD_ROTATION, HeadRotation );
  568. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_LOOK_TARGET, HeadLookTarget );
  569. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_LOOK_ANGLE, HeadLookAngle );
  570. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_LOOK_ANGLE_TIMER, HeadLookAngleTimer );
  571. // WRITE_MICRO_CHUNK( csave, MICROCHUNKID_FLAME_TIMER, FlameTimer );
  572. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_SPECIAL_DAMAGE_MODE, SpecialDamageMode );
  573. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_SPECIAL_DAMAGE_TIMER, SpecialDamageTimer );
  574. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_AI_STATE, AIState );
  575. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_WEAPON_MODEL, WeaponRenderModel );
  576. WRITE_MICRO_CHUNK( csave, MICROCHUNKID_IS_USING_GHOST_COLLISION, IsUsingGhostCollision );
  577. csave.End_Chunk();
  578. if ( WeaponAnimControl ) {
  579. csave.Begin_Chunk( CHUNKID_WEAPON_ANIM );
  580. WeaponAnimControl->Save( csave );
  581. csave.End_Chunk();
  582. }
  583. csave.Begin_Chunk( CHUNKID_HUMAN_STATE );
  584. HumanState.Save( csave );
  585. csave.End_Chunk();
  586. if ( TransitionCompletionData ) {
  587. csave.Begin_Chunk( CHUNKID_TRANSITION_COMPLETION_DATA );
  588. TransitionCompletionData->Save( csave );
  589. csave.End_Chunk();
  590. }
  591. for ( int i = 0; i < RenderObjList.Count(); i++ ) {
  592. csave.Begin_Chunk( CHUNKID_RENDER_OBJS );
  593. csave.Begin_Chunk(RenderObjList[i]->Get_Factory().Chunk_ID());
  594. RenderObjList[i]->Get_Factory().Save( csave, RenderObjList[i] );
  595. csave.End_Chunk();
  596. csave.End_Chunk();
  597. }
  598. if ( SpecialDamageDamager.Get_Ptr() != NULL ) {
  599. csave.Begin_Chunk( CHUNKID_SPECIAL_DAMAGE_DAMAGER );
  600. SpecialDamageDamager.Save( csave );
  601. csave.End_Chunk();
  602. }
  603. return true;
  604. }
  605. //------------------------------------------------------------------------------------
  606. bool SoldierGameObj::Load( ChunkLoadClass &cload )
  607. {
  608. char anim_string[80];
  609. int dialog_index = 0;
  610. WWASSERT( Vehicle == NULL );
  611. while (cload.Open_Chunk()) {
  612. switch(cload.Cur_Chunk_ID()) {
  613. case CHUNKID_PARENT:
  614. SmartGameObj::Load( cload );
  615. break;
  616. case CHUNKID_DIALOG_ENTRY:
  617. if (dialog_index < DIALOG_MAX) {
  618. DialogList[dialog_index++].Load (cload);
  619. }
  620. break;
  621. case CHUNKID_VARIABLES:
  622. while (cload.Open_Micro_Chunk()) {
  623. switch(cload.Cur_Micro_Chunk_ID()) {
  624. READ_MICRO_CHUNK( cload, MICROCHUNKID_DETONATE_C4, DetonateC4 );
  625. READ_MICRO_CHUNK( cload, MICROCHUNKID_LEG_FACING, LegFacing );
  626. READ_MICRO_CHUNK( cload, MICROCHUNKID_SYNC_LEGS, SyncLegs );
  627. READ_MICRO_CHUNK( cload, MICROCHUNKID_VEHICLE, Vehicle );
  628. READ_MICRO_CHUNK( cload, MICROCHUNKID_KEY_RING, KeyRing );
  629. // READ_MICRO_CHUNK( cload, MICROCHUNKID_FORCE_FACING, ForceFacing );
  630. case MICROCHUNKID_ANIMATION_NAME:
  631. cload.Read( anim_string, cload.Cur_Micro_Chunk_Length() );
  632. AnimationName = anim_string;
  633. break;
  634. case MICROCHUNKID_INNATE_OBSERVER_PTR:
  635. cload.Read( &InnateObserver, sizeof (InnateObserver) );
  636. if ( InnateObserver != NULL ) {
  637. REQUEST_POINTER_REMAP( (void **)&InnateObserver );
  638. }
  639. break;
  640. READ_MICRO_CHUNK( cload, MICROCHUNKID_INNATE_ENABLE_BITS, InnateEnableBits );
  641. READ_MICRO_CHUNK( cload, MICROCHUNKID_LAST_LEG_MODE, LastLegMode );
  642. READ_MICRO_CHUNK( cload, MICROCHUNKID_HEAD_LOOK_DURATION, HeadLookDuration );
  643. READ_MICRO_CHUNK( cload, MICROCHUNKID_HEAD_ROTATION, HeadRotation );
  644. READ_MICRO_CHUNK( cload, MICROCHUNKID_LOOK_TARGET, HeadLookTarget );
  645. READ_MICRO_CHUNK( cload, MICROCHUNKID_LOOK_ANGLE, HeadLookAngle );
  646. READ_MICRO_CHUNK( cload, MICROCHUNKID_LOOK_ANGLE_TIMER, HeadLookAngleTimer );
  647. // READ_MICRO_CHUNK( cload, MICROCHUNKID_FLAME_TIMER, FlameTimer );
  648. READ_MICRO_CHUNK( cload, MICROCHUNKID_SPECIAL_DAMAGE_MODE, SpecialDamageMode );
  649. READ_MICRO_CHUNK( cload, MICROCHUNKID_SPECIAL_DAMAGE_TIMER, SpecialDamageTimer );
  650. READ_MICRO_CHUNK( cload, MICROCHUNKID_AI_STATE, AIState );
  651. READ_MICRO_CHUNK( cload, MICROCHUNKID_WEAPON_MODEL, WeaponRenderModel );
  652. READ_MICRO_CHUNK( cload, MICROCHUNKID_IS_USING_GHOST_COLLISION, IsUsingGhostCollision );
  653. default:
  654. Debug_Say(( "Unrecognized Soldier Variable chunkID\n" ));
  655. break;
  656. }
  657. cload.Close_Micro_Chunk();
  658. }
  659. if ( Vehicle != NULL ) {
  660. REQUEST_POINTER_REMAP( (void **)&Vehicle );
  661. }
  662. break;
  663. case CHUNKID_WEAPON_ANIM:
  664. Set_Weapon_Animation( NULL ); // Get the anim control built
  665. WeaponAnimControl->Load( cload );
  666. break;
  667. case CHUNKID_HUMAN_STATE:
  668. HumanState.Load( cload );
  669. break;
  670. case CHUNKID_RENDER_OBJS:
  671. cload.Open_Chunk();
  672. PersistFactoryClass * factory;
  673. factory = SaveLoadSystemClass::Find_Persist_Factory(cload.Cur_Chunk_ID());
  674. WWASSERT(factory != NULL);
  675. if (factory != NULL) {
  676. RenderObjClass * robj = (RenderObjClass *)factory->Load(cload);
  677. Add_RenderObj( robj );
  678. robj->Release_Ref();
  679. }
  680. cload.Close_Chunk();
  681. break;
  682. case CHUNKID_TRANSITION_COMPLETION_DATA:
  683. WWASSERT( TransitionCompletionData == NULL );
  684. TransitionCompletionData = new TransitionCompletionDataStruct();
  685. TransitionCompletionData->Load( cload );
  686. break;
  687. case CHUNKID_SPECIAL_DAMAGE_DAMAGER:
  688. SpecialDamageDamager.Load( cload );
  689. break;
  690. default:
  691. Debug_Say(( "Unrecognized SoldierGameObj chunkID\n" ));
  692. break;
  693. }
  694. cload.Close_Chunk();
  695. }
  696. if ( WeaponRenderModel != NULL ) {
  697. REQUEST_REF_COUNTED_POINTER_REMAP( (RefCountClass **)&WeaponRenderModel );
  698. }
  699. SaveLoadSystemClass::Register_Post_Load_Callback(this);
  700. return true;
  701. }
  702. //------------------------------------------------------------------------------------
  703. void SoldierGameObj::On_Post_Load( void )
  704. {
  705. HumanState.Set_Anim_Control( (HumanAnimControlClass *)Get_Anim_Control() ); // Must set the anim control after the phys object
  706. SmartGameObj::On_Post_Load();
  707. if ( Peek_Model() && (WeaponRenderModel != NULL) ) {
  708. Peek_Model()->Add_Sub_Object_To_Bone( WeaponRenderModel, GUN_BONE_NAME );
  709. }
  710. Adjust_Skeleton( Get_Definition().SkeletonHeight, Get_Definition().SkeletonWidth );
  711. // Fixup BackWeaponRenderModel
  712. Update_Back_Gun();
  713. // Hide if in vehicle
  714. if ( Is_In_Vehicle() && Peek_Model() != NULL ) {
  715. Peek_Model()->Set_Hidden( true );
  716. }
  717. //
  718. // Make sure we have an allocated animation to use for speech
  719. //
  720. Prepare_Speech_Framework ();
  721. return ;
  722. }
  723. //-----------------------------------------------------------------------------
  724. CollisionReactionType SoldierGameObj::Collision_Occurred(const CollisionEventClass & event)
  725. {
  726. // Debug_Say(( "Soldier Collision %p %p\n", this, event.OtherObj ));
  727. // Detect squishing...
  728. if ( event.OtherObj != NULL && event.OtherObj->Get_Observer() != NULL ) {
  729. PhysicalGameObj * obj = ((CombatPhysObserverClass *)event.OtherObj->Get_Observer())->As_PhysicalGameObj();
  730. if ( obj && obj->As_VehicleGameObj() ) {
  731. // if ( !Is_Teammate( obj ) ) { // never squish teammates
  732. if ( Is_Enemy( obj ) ) { // only squish enemies
  733. Vector3 vel;
  734. if ( event.OtherObj->As_MoveablePhysClass() != NULL ) {
  735. event.OtherObj->As_MoveablePhysClass()->Get_Velocity( &vel );
  736. Vector3 my_pos;
  737. Vector3 vehicle_pos;
  738. Get_Position(&my_pos);
  739. obj->Get_Position(&vehicle_pos);
  740. // only squish if velocity is high enough, and velocity is towards the soldier
  741. if ( (vel.Length() > obj->As_VehicleGameObj()->Get_Squish_Velocity() ) &&
  742. (Vector3::Dot_Product(vel,my_pos - vehicle_pos) > 0.0f) )
  743. {
  744. if ( HumanState.Get_State() != HumanStateClass::DEATH ) {
  745. // We need to pick a better warhead to damage with
  746. SmartGameObj * damager = obj->As_VehicleGameObj()->Get_Driver();
  747. if ( damager == NULL ) {
  748. damager = obj->As_VehicleGameObj();
  749. }
  750. OffenseObjectClass offense( 10000, 1, damager );
  751. Apply_Damage_Extended( offense, 10000.0f, vel, NULL );
  752. // Play the squish sound
  753. // Stats
  754. if (( obj->As_VehicleGameObj()->Get_Driver() != NULL ) &&
  755. ( obj->As_VehicleGameObj()->Get_Driver()->Get_Player_Data() != NULL ) ) {
  756. obj->As_VehicleGameObj()->Get_Driver()->Get_Player_Data()->Stats_Add_Squish();
  757. }
  758. }
  759. }
  760. }
  761. }
  762. }
  763. }
  764. return COLLISION_REACTION_DEFAULT;
  765. }
  766. /*
  767. **
  768. */
  769. void SoldierGameObj::Export_Creation( BitStreamClass &packet )
  770. {
  771. //TSS091001
  772. //WWDEBUG_SAY((">>>>> SoldierGameObj::Export_Creation id %d\n", Get_ID()));
  773. SmartGameObj::Export_Creation( packet );
  774. return ;
  775. }
  776. /*
  777. **
  778. */
  779. void SoldierGameObj::Import_Creation( BitStreamClass &packet )
  780. {
  781. SmartGameObj::Import_Creation( packet );
  782. //TSS091001
  783. //WWDEBUG_SAY((">>>>> SoldierGameObj::Import_Creation id %d\n", Get_ID()));
  784. /*
  785. //
  786. // Setup the speed settings for this soldier
  787. //
  788. float speed_factor = CombatManager::Get_Max_Speed_Pc( this ) / 100.0f;
  789. Set_Max_Speed( speed_factor * Get_Max_Speed() );
  790. */
  791. return ;
  792. }
  793. /*
  794. **
  795. */
  796. void SoldierGameObj::Export_Rare( BitStreamClass &packet )
  797. {
  798. SmartGameObj::Export_Rare( packet );
  799. //
  800. // Add our definition ID to the packet
  801. //
  802. uint32 definition_id = Get_Definition ().Get_ID ();
  803. packet.Add( definition_id );
  804. }
  805. /*
  806. **
  807. */
  808. void SoldierGameObj::Import_Rare( BitStreamClass &packet )
  809. {
  810. Set_Weapon_Model (NULL);
  811. // If we are changing to the same def, the above line made us lose our weapon model, and we won't get it back.
  812. // The next line makes us get it back.
  813. Get_Weapon_Bag()->Force_Changed();
  814. SmartGameObj::Import_Rare( packet );
  815. //
  816. // Read the definition ID from the packet
  817. //
  818. uint32 definition_id = 0;
  819. packet.Get( definition_id );
  820. //
  821. // Did our definition change?
  822. //
  823. if (definition_id != Get_Definition ().Get_ID ()) {
  824. DefinitionClass *definition = DefinitionMgrClass::Find_Definition (definition_id);
  825. //
  826. // Did we find the right definition?
  827. //
  828. if (definition != NULL && definition->Get_Class_ID() == CLASSID_GAME_OBJECT_DEF_SOLDIER) {
  829. SoldierGameObjDef *soldier_def = reinterpret_cast<SoldierGameObjDef *> (definition);
  830. //
  831. // Re-initialize ourselves
  832. //
  833. Re_Init (*soldier_def);
  834. }
  835. }
  836. return ;
  837. }
  838. /*
  839. **
  840. */
  841. void SoldierGameObj::Export_Occasional( BitStreamClass &packet )
  842. {
  843. SmartGameObj::Export_Occasional( packet );
  844. //
  845. // What weapon is being held?
  846. //
  847. #if 0 //(gth) moving this back to Frequent to fix the game, re-optimize later...
  848. WeaponClass * p_weapon = Get_Weapon();
  849. bool has_weapon = (p_weapon != NULL);
  850. packet.Add(has_weapon);
  851. if (has_weapon) {
  852. packet.Add(p_weapon->Get_ID());
  853. packet.Add(p_weapon->Get_Total_Rounds());
  854. }
  855. #endif
  856. WWASSERT(WeaponBag != NULL);
  857. WeaponBag->Export_Weapon_List(packet);
  858. //packet.Add(CtfTeamFlag, BITPACK_CTF_TEAM_FLAG);
  859. }
  860. /*
  861. **
  862. */
  863. void SoldierGameObj::Import_Occasional( BitStreamClass &packet )
  864. {
  865. WWASSERT(CombatManager::I_Am_Only_Client());
  866. SmartGameObj::Import_Occasional( packet );
  867. //
  868. // Held weapon
  869. //
  870. #if 0 // (gth) moving back to "Frequent" to fix the game, re-optimize later?
  871. bool has_weapon = packet.Get(has_weapon);
  872. if (has_weapon) {
  873. WWASSERT(!packet.Is_Flushed());
  874. int weapon_id = packet.Get(weapon_id);
  875. int rounds = packet.Get(rounds);
  876. if ((Get_Weapon() == NULL) || (weapon_id != Get_Weapon()->Get_ID())) {
  877. WeaponBag->Select_Weapon_ID(weapon_id);
  878. }
  879. if (Get_Weapon() != NULL) {
  880. // If this weapon is currently being fired, ignore the server rounds count packet
  881. // This should help the jittery rounds count
  882. if ( !Get_Weapon()->Is_Triggered() ) {
  883. Get_Weapon()->Set_Total_Rounds( rounds );
  884. }
  885. }
  886. } else {
  887. if (Get_Weapon() != NULL) {
  888. Get_Weapon_Bag()->Deselect();
  889. }
  890. }
  891. #endif
  892. //
  893. // Weapon list
  894. //
  895. WWASSERT(WeaponBag != NULL);
  896. WeaponBag->Import_Weapon_List(packet);
  897. /*
  898. //
  899. // Flag pickup/drop
  900. //
  901. int ctf_team_flag = packet.Get(ctf_team_flag, BITPACK_CTF_TEAM_FLAG);
  902. if (CtfTeamFlag != ctf_team_flag) {
  903. CombatManager::Change_Flag_Status(this, ctf_team_flag);
  904. }
  905. */
  906. }
  907. /*
  908. **
  909. */
  910. void SoldierGameObj::Export_Frequent(BitStreamClass & packet)
  911. {
  912. /**/
  913. //TSS101601
  914. bool in_vehicle = (Get_State() == HumanStateClass::IN_VEHICLE);
  915. packet.Add(in_vehicle);
  916. if (in_vehicle)
  917. {
  918. // Just do the control info
  919. SmartGameObj::Export_Frequent(packet);
  920. return;
  921. }
  922. /**/
  923. //
  924. // What weapon is being held?
  925. // (gth) moved this back into frequent to fix the game, re-optimize later
  926. //
  927. WeaponClass * p_weapon = Get_Weapon();
  928. bool has_weapon = (p_weapon != NULL);
  929. packet.Add(has_weapon);
  930. if (has_weapon) {
  931. packet.Add(p_weapon->Get_ID());
  932. packet.Add(p_weapon->Get_Total_Rounds());
  933. }
  934. //
  935. // Export Position and state
  936. //
  937. Vector3 position;
  938. Get_Position(&position);
  939. #ifdef MULTIPLAYERDEMO
  940. //
  941. // Mix up the packet order to make demo/non-demo code more incompatible.
  942. //
  943. packet.Add(position.Y, BITPACK_WORLD_POSITION_Y);
  944. packet.Add(position.Z, BITPACK_WORLD_POSITION_Z);
  945. packet.Add(position.X, BITPACK_WORLD_POSITION_X);
  946. #else
  947. packet.Add(position.X, BITPACK_WORLD_POSITION_X);
  948. packet.Add(position.Y, BITPACK_WORLD_POSITION_Y);
  949. packet.Add(position.Z, BITPACK_WORLD_POSITION_Z);
  950. #endif
  951. packet.Add((int) HumanState.Get_State(), BITPACK_HUMAN_STATE);
  952. packet.Add(HumanState.Get_Sub_State(), BITPACK_HUMAN_SUB_STATE);
  953. if (HumanState.Get_State() == HumanStateClass::AIRBORNE) {
  954. // velocity is only needed for jumping
  955. Vector3 velocity;
  956. Get_Velocity(velocity);
  957. packet.Add(velocity.X);
  958. packet.Add(velocity.Y);
  959. packet.Add(velocity.Z);
  960. }
  961. if ((Get_State() == HumanStateClass::TRANSITION) ||
  962. (Get_State() == HumanStateClass::ANIMATION) ||
  963. (Get_State() == HumanStateClass::IN_VEHICLE)) {
  964. packet.Add_Terminated_String(AnimationName);
  965. // Debug_Say(( "In Transition %s\n", TransitionName ));
  966. }
  967. bool is_special_damage = SpecialDamageMode != ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_NONE;
  968. packet.Add(is_special_damage);
  969. if ( is_special_damage ) {
  970. packet.Add( SpecialDamageMode );
  971. }
  972. SmartGameObj::Export_Frequent(packet);
  973. }
  974. /*
  975. **
  976. */
  977. void SoldierGameObj::Import_Frequent( BitStreamClass & packet )
  978. {
  979. WWASSERT(CombatManager::I_Am_Only_Client());
  980. /**/
  981. //TSS101601
  982. bool in_vehicle = packet.Get(in_vehicle);
  983. if (in_vehicle)
  984. {
  985. // Just get control info
  986. SmartGameObj::Import_Frequent(packet);
  987. return;
  988. }
  989. /**/
  990. //
  991. // What weapon is being held?
  992. // (gth) moved this back into frequent to fix the game, re-optimize later
  993. //
  994. bool has_weapon = packet.Get(has_weapon);
  995. if (has_weapon) {
  996. WWASSERT(!packet.Is_Flushed());
  997. int weapon_id = packet.Get(weapon_id);
  998. int rounds = packet.Get(rounds);
  999. if ((Get_Weapon() == NULL) || (weapon_id != Get_Weapon()->Get_ID())) {
  1000. WeaponBag->Select_Weapon_ID(weapon_id);
  1001. }
  1002. if (Get_Weapon() != NULL) {
  1003. // If this weapon is currently being fired, ignore the server rounds count packet
  1004. // This should help the jittery rounds count
  1005. if ( !Get_Weapon()->Is_Triggered() ) {
  1006. Get_Weapon()->Set_Total_Rounds( rounds );
  1007. }
  1008. }
  1009. } else {
  1010. if (Get_Weapon() != NULL) {
  1011. Get_Weapon_Bag()->Deselect();
  1012. }
  1013. }
  1014. //
  1015. // Position
  1016. //
  1017. Vector3 sc_position;
  1018. #ifdef MULTIPLAYERDEMO
  1019. //
  1020. // Mix up the packet order to make demo/non-demo code more incompatible.
  1021. //
  1022. packet.Get(sc_position.Y, BITPACK_WORLD_POSITION_Y);
  1023. packet.Get(sc_position.Z, BITPACK_WORLD_POSITION_Z);
  1024. packet.Get(sc_position.X, BITPACK_WORLD_POSITION_X);
  1025. #else
  1026. packet.Get(sc_position.X, BITPACK_WORLD_POSITION_X);
  1027. packet.Get(sc_position.Y, BITPACK_WORLD_POSITION_Y);
  1028. packet.Get(sc_position.Z, BITPACK_WORLD_POSITION_Z);
  1029. #endif
  1030. // Bump Z up to the top of the possible values due to packing
  1031. // we assume the max error is half of the resolution
  1032. float max_error = cEncoderList::Get_Encoder_Type_Entry( BITPACK_WORLD_POSITION_Z ).Get_Resolution() / 2.0f;
  1033. sc_position.Z += max_error;
  1034. Interpret_Sc_Position_Data(sc_position);
  1035. //
  1036. // State and substate
  1037. //
  1038. int h_state = packet.Get(h_state, BITPACK_HUMAN_STATE);
  1039. HumanStateClass::HumanStateType state =
  1040. (HumanStateClass::HumanStateType) h_state;
  1041. int sub_state = packet.Get(sub_state, BITPACK_HUMAN_SUB_STATE);
  1042. //
  1043. // Velocity (if airborne)
  1044. //
  1045. Vector3 velocity;
  1046. if (state == HumanStateClass::AIRBORNE) {
  1047. packet.Get(velocity.X);
  1048. packet.Get(velocity.Y);
  1049. packet.Get(velocity.Z);
  1050. }
  1051. if (HumanState.Is_Locked()) {
  1052. packet.Flush();
  1053. return;
  1054. }
  1055. #if 0
  1056. if ( Get_State() == HumanStateClass::TRANSITION ) {
  1057. Debug_Say(( "Ignoring Transitioning!\n" ));
  1058. packet.Flush();
  1059. return;
  1060. }
  1061. #endif
  1062. char trans_name[80] = "";
  1063. if ( ( state == HumanStateClass::TRANSITION ) ||
  1064. ( state == HumanStateClass::ANIMATION ) ||
  1065. ( state == HumanStateClass::IN_VEHICLE ) ) {
  1066. packet.Get_Terminated_String(trans_name, sizeof(trans_name));
  1067. }
  1068. Interpret_Sc_State_Data(state, sub_state, trans_name, velocity, sc_position);
  1069. bool is_special_damage;
  1070. packet.Get(is_special_damage);
  1071. int mode = ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_NONE;
  1072. if ( is_special_damage ) {
  1073. packet.Get(mode);
  1074. }
  1075. if ( mode != SpecialDamageMode ) {
  1076. Set_Special_Damage_Mode( (ArmorWarheadManager::SpecialDamageType)mode );
  1077. }
  1078. if (Get_State() == HumanStateClass::DIVE) {
  1079. packet.Flush();
  1080. } else {
  1081. SmartGameObj::Import_Frequent(packet);
  1082. }
  1083. WWASSERT(packet.Is_Flushed());
  1084. }
  1085. //-----------------------------------------------------------------------------
  1086. void SoldierGameObj::Import_State_Cs(BitStreamClass & packet)
  1087. {
  1088. bool is_sniping = packet.Get( is_sniping );
  1089. if ( is_sniping != Is_Sniping() ) {
  1090. // Take sniping state from client
  1091. // Debug_Say(( "Fixing Sniper State\n" ));
  1092. HumanState.Toggle_State_Flag( HumanStateClass::SNIPING_FLAG );
  1093. }
  1094. bool checking = packet.Get( checking );
  1095. if ( checking ) {
  1096. int check = packet.Get( check );
  1097. if ( check != Check() ) {
  1098. // React to cheating
  1099. if ( Get_Player_Data() ) {
  1100. Get_Player_Data()->Inc_Punish_Timer( TimeManager::Get_Frame_Seconds() ) ;
  1101. }
  1102. }
  1103. }
  1104. SmartGameObj::Import_State_Cs(packet);
  1105. }
  1106. //-----------------------------------------------------------------------------
  1107. void SoldierGameObj::Export_State_Cs(BitStreamClass & packet)
  1108. {
  1109. bool is_sniping = Is_Sniping();
  1110. packet.Add( is_sniping );
  1111. bool checking = Control.Get_Boolean( ControlClass::BOOLEAN_ACTION );
  1112. packet.Add( checking );
  1113. if ( checking ) {
  1114. int check = Check();
  1115. packet.Add( check );
  1116. }
  1117. SmartGameObj::Export_State_Cs(packet);
  1118. }
  1119. //-----------------------------------------------------------------------------
  1120. int SoldierGameObj::Check(void)
  1121. {
  1122. Matrix3D tm(1);
  1123. #define UNINITIALLIZED_CRC 0x78629140
  1124. static int crc = UNINITIALLIZED_CRC;
  1125. tm.Rotate_X( 1.4f );
  1126. if ( crc == UNINITIALLIZED_CRC ) {
  1127. char * filelist[] = {
  1128. "laif`wp-gga", //"objects.ddb",
  1129. "bqnlq-jmj", //"armor.ini",
  1130. "almfp-jmj", //"bones.ini",
  1131. "pvqeb`ffeef`wp-jmj", //"surfaceeffects.ini",
  1132. "`bnfqbp-jmj", //"cameras.ini",
  1133. "`\\mlg\\nd\\o3-t0g", //"c_nod_mg_l0.w3d",
  1134. "`\\mlg\\qh\\o3-t0g", //"c_nod_rk_l0.w3d",
  1135. "`\\mlg\\eo\\o3-t0g", //"c_nod_fl_l0.w3d",
  1136. "`\\mlg\\fm\\o3-t0g", //"c_nod_en_l0.w3d",
  1137. "`\\mlg\\ndl\\o3-t0g", //"c_nod_mgo_l0.w3d",
  1138. "`\\mlg\\qhl\\o3-t0g", //"c_nod_rko_l0.w3d",
  1139. "`\\mlg\\`kfnw\\o3-t0g", //"c_nod_chemt_l0.w3d",
  1140. "`\\mlg\\pmjsfq\\o3-t0g", //"c_nod_sniper_l0.w3d",
  1141. "`\\mlg\\qplog\\o3-t0g", //"c_nod_rsold_l0.w3d",
  1142. "`\\mlg\\pwowk\\o3-t0g", //"c_nod_stlth_l0.w3d",
  1143. "`\\mlg\\pbhv\\o3-t0g", //"c_nod_saku_l0.w3d",
  1144. "`\\mlg\\pbhv1\\o3-t0g", //"c_nod_saku2_l0.w3d",
  1145. "`\\mlg\\qbu\\o3-t0g", //"c_nod_rav_l0.w3d",
  1146. "`\\mlg\\nqbu\\o3-t0g", //"c_nod_mrav_l0.w3d",
  1147. "`\\mlg\\ngy\\o3-t0g", //"c_nod_mdz_l0.w3d",
  1148. "`\\mlg\\ngy1\\o3-t0g", //"c_nod_mdz2_l0.w3d",
  1149. "`\\mlg\\w`\\o3-t0g", //"c_nod_tc_l0.w3d",
  1150. "`\\mlg\\nvwbmw\\o3-t0g", //"c_nod_mutant_l0.w3d",
  1151. "`\\mlg\\npog\\o3-t0g", //"c_nod_msld_l0.w3d",
  1152. "`\\mlg\\pplog\\o3-t0g", //"c_nod_ssold_l0.w3d",
  1153. "`\\mlg\\sfwn\\o3-t0g", //"c_nod_petm_l0.w3d",
  1154. "`\\mlg\\hbmf\\o3-t0g", //"c_nod_kane_l0.w3d",
  1155. "`\\dgj\\nd\\o3-t0g", //"c_gdi_mg_l0.w3d",
  1156. "`\\dgj\\qh\\o3-t0g", //"c_gdi_rk_l0.w3d",
  1157. "`\\dgj\\dq\\o3-t0g", //"c_gdi_gr_l0.w3d",
  1158. "`\\dgj\\fm\\o3-t0g", //"c_gdi_en_l0.w3d",
  1159. "`\\dgj\\ndl\\o3-t0g", //"c_gdi_mgo_l0.w3d",
  1160. "`\\dgj\\qhl\\o3-t0g", //"c_gdi_rko_l0.w3d",
  1161. "`\\dgj\\pzg\\o3-t0g", //"c_gdi_syd_l0.w3d",
  1162. "`\\dgj\\gfbg\\o3-t0g", //"c_gdi_dead_l0.w3d",
  1163. "`\\dgj\\dvm\\o3-t0g", //"c_gdi_gun_l0.w3d",
  1164. "`\\dgj\\sw`k\\o3-t0g", //"c_gdi_ptch_l0.w3d",
  1165. "`\\kbul`\\o3-t0g", //"c_havoc_l0.w3d",
  1166. "`\\kbul`m\\o3-t0g", //"c_havocn_l0.w3d",
  1167. "`\\kbul`t\\o3-t0g", //"c_havocw_l0.w3d",
  1168. "`\\kbul`g\\o3-t0g", //"c_havocd_l0.w3d",
  1169. "`\\dgj\\pzg\\o3-t0g", //"c_gdi_syd_l0.w3d",
  1170. "`\\dgj\\pzg1\\o3-t0g", //"c_gdi_syd2_l0.w3d",
  1171. "`\\dgj\\nlaj\\o3-t0g", //"c_gdi_mobi_l0.w3d",
  1172. "`\\dgj\\klwt\\o3-t0g", //"c_gdi_hotw_l0.w3d",
  1173. "`\\dgj\\ow\\o3-t0g", //"c_gdi_lt_l0.w3d",
  1174. "`\\mlg\\sfwq\\o3-t0g", //"c_nod_petr_l0.w3d",
  1175. "`\\oldbm\\o3-t0g", //"c_logan_l0.w3d",
  1176. "`\\dgj\\ol`hf\\o3-t0g", //"c_gdi_locke_l0.w3d",
  1177. "u\\mlg\\avddz-t0g", //"v_nod_buggy.w3d",
  1178. "u\\mlg\\bs`\\n-t0g", //"v_nod_apc_m.w3d",
  1179. "u\\mlg\\bqwoqz-t0g", //"v_nod_artlry.w3d",
  1180. "u\\mlg\\eobnf-t0g", //"v_nod_flame.w3d",
  1181. "u\\mlg\\owbmh-t0g", //"v_nod_ltank.w3d",
  1182. "u\\mlg\\pwowk-t0g", //"v_nod_stlth.w3d",
  1183. "u\\mlg\\wqmpsw\\n-t0g", //"v_nod_trnspt_m.w3d",
  1184. "u\\mlg\\bsb`kf\\n-t0g", //"v_nod_apache_m.w3d",
  1185. "u\\`kbnfoflm-t0g", //"v_chameleon.w3d",
  1186. "u\\dgj\\kvnuff-t0g", //"v_gdi_humvee.w3d",
  1187. "u\\dgj\\bs`\\n-t0g", //"v_gdi_apc_m.w3d",
  1188. "u\\dgj\\nqop-t0g", //"v_gdi_mrls.w3d",
  1189. "u\\dgj\\nfgwmh-t0g", //"v_gdi_medtnk.w3d",
  1190. "u\\dgj\\nbnnwk-t0g", //"v_gdi_mammth.w3d",
  1191. "u\\sj`hvs32-t0g", //"v_pickup01.w3d",
  1192. "u\\pfgbm32-t0g", //"v_sedan01.w3d",
  1193. "u\\dgj\\lq`b\\n-t0g", //"v_gdi_orca_m.w3d",
  1194. "u\\dgj\\wqmpsw\\n-t0g", //"v_gdi_trnspt_m.w3d",
  1195. };
  1196. #define NUM_CRC_FILES (sizeof( filelist ) / sizeof( filelist[0] ) )
  1197. crc = 0;
  1198. tm.Rotate_Y( 2.8f );
  1199. for ( int i = 0; i < NUM_CRC_FILES; i++ ) {
  1200. StringClass name = filelist[i];
  1201. // Obfuscate name
  1202. char * n = &name[0];
  1203. while ( *n ) *n++ ^= 0x3;
  1204. tm.Rotate_Z( 3.6f );
  1205. // Debug_Say(( " \"%s\",\n", name ));
  1206. FileClass * file = _TheFileFactory->Get_File( name );
  1207. tm.Pre_Rotate_X( 0.3f );
  1208. if ( file && file->Is_Available() ) {
  1209. int size = file->Size();
  1210. tm.Pre_Rotate_Y( 0.4f );
  1211. file->Open();
  1212. tm.Pre_Rotate_Z( 0.5f );
  1213. while ( size > 0 ) {
  1214. unsigned char buffer[ 4096 ];
  1215. int amount = min( (int)size, (int)sizeof(buffer) );
  1216. tm.Translate_X( 3.1f );
  1217. amount = file->Read( buffer, amount );
  1218. tm.Translate_Y( 4.6f );
  1219. crc = CRC_Memory( buffer, amount, crc );
  1220. tm.Translate_Z( 8.2f );
  1221. size -= amount;
  1222. }
  1223. file->Close();
  1224. } else {
  1225. // Debug_Say(( "***%s not found\n", name ));
  1226. }
  1227. tm.Rotate_X( 1.4f );
  1228. }
  1229. }
  1230. return crc;
  1231. }
  1232. //-----------------------------------------------------------------------------
  1233. /*
  1234. **
  1235. */
  1236. bool _UseLatencyInterpret = true;
  1237. //-----------------------------------------------------------------------------
  1238. void SoldierGameObj::Interpret_Sc_Position_Data( const Vector3 & sc_position)
  1239. {
  1240. Vector3 position = sc_position;
  1241. // Only use the latency code for the star
  1242. if ( _UseLatencyInterpret && (this == COMBAT_STAR) ) {
  1243. Peek_Human_Phys()->Network_Latency_State_Update(sc_position,Vector3(0,0,0));
  1244. return;
  1245. }
  1246. WWASSERT(CombatManager::I_Am_Only_Client());
  1247. if (Get_State() == HumanStateClass::TRANSITION) {
  1248. //
  1249. // Pop
  1250. //
  1251. // Set_Position(sc_position);
  1252. Peek_Human_Phys()->Network_State_Update(sc_position,Vector3(0,0,0));
  1253. } else {
  1254. Vector3 current_position;
  1255. Get_Position(&current_position);
  1256. Vector3 pos_error = current_position - sc_position;
  1257. //TSS081501
  1258. if (Is_In_Elevator()) {
  1259. position.Z = current_position.Z;
  1260. }
  1261. // Set_Position(sc_position);
  1262. Peek_Human_Phys()->Network_State_Update(position,Vector3(0,0,0));
  1263. }
  1264. }
  1265. //-----------------------------------------------------------------------------
  1266. void SoldierGameObj::Interpret_Sc_State_Data(
  1267. HumanStateClass::HumanStateType state, int sub_state,
  1268. LPCSTR trans_name, const Vector3 & velocity, const Vector3 & sc_position)
  1269. {
  1270. WWASSERT(CombatManager::I_Am_Only_Client());
  1271. if ( ( Get_State() != state ) || ( Get_Sub_State() != sub_state ) ){
  1272. if ( ( Get_State() == HumanStateClass::TRANSITION ) && // If in TRANSITION, don't switch to TRANSITION_COMPLETE
  1273. ( state == HumanStateClass::TRANSITION_COMPLETE ) ) {
  1274. // do nothing
  1275. } else if ( ( Get_State() == HumanStateClass::UPRIGHT ) && // If UPRIGHT, don't switch to LAND
  1276. ( state == HumanStateClass::LAND ) ) {
  1277. // do nothing
  1278. } else {
  1279. if (Is_Controlled_By_Me() &&
  1280. ((( Get_State() == HumanStateClass::UPRIGHT ) || ( Get_State() == HumanStateClass::AIRBORNE ) || ( Get_State() == HumanStateClass::LAND )) &&
  1281. (( state == HumanStateClass::UPRIGHT ) || ( state == HumanStateClass::AIRBORNE ) || ( state == HumanStateClass::LAND )) )) {
  1282. // do nothing
  1283. // } else if (Is_Controlled_By_Me() == false) {
  1284. } else {
  1285. // take the new state
  1286. if (state == HumanStateClass::TRANSITION) {
  1287. Start_Transition_Animation( trans_name, NULL );
  1288. AnimationName = trans_name;
  1289. } else if (state == HumanStateClass::ANIMATION) {
  1290. AnimationName = trans_name;
  1291. HumanState.Start_Scripted_Animation( AnimationName, true, false );
  1292. } else if (state == HumanStateClass::IN_VEHICLE) {
  1293. HumanState.Force_Animation( trans_name, false );
  1294. AnimationName = trans_name;
  1295. }
  1296. //TSS2001
  1297. // if (state != HumanStateClass::IN_VEHICLE) {
  1298. HumanState.Set_State( state, sub_state );
  1299. // }
  1300. }
  1301. }
  1302. }
  1303. if (( state == HumanStateClass::AIRBORNE ) && ( this != COMBAT_STAR ) ) {
  1304. Peek_Human_Phys()->Set_In_Contact( false );
  1305. Peek_Human_Phys()->Set_Velocity( velocity );
  1306. Peek_Human_Phys()->Set_Position( sc_position );
  1307. }
  1308. }
  1309. //-----------------------------------------------------------------------------
  1310. int SoldierGameObj::Tally_Vis_Visible_Soldiers( void )
  1311. {
  1312. int retcode = -1;
  1313. Vector3 position;
  1314. Get_Position(&position);
  1315. position.Z += 1.5f;
  1316. WWASSERT(COMBAT_SCENE != NULL);
  1317. VisTableClass * pvs = COMBAT_SCENE->Get_Vis_Table(position);
  1318. if (pvs != NULL) {
  1319. retcode = 0;
  1320. for (
  1321. SLNode<SmartGameObj> * smart_objnode = GameObjManager::Get_Smart_Game_Obj_List()->Head();
  1322. smart_objnode != NULL;
  1323. smart_objnode = smart_objnode->Next()) {
  1324. SoldierGameObj * p_soldier = smart_objnode->Data()->As_SoldierGameObj();
  1325. if (p_soldier != NULL) {
  1326. PhysClass * phys_obj = p_soldier->Peek_Physical_Object();
  1327. if (phys_obj != NULL && pvs->Get_Bit(phys_obj->Get_Vis_Object_ID())) {
  1328. retcode++;
  1329. }
  1330. }
  1331. }
  1332. }
  1333. return retcode;
  1334. }
  1335. //-----------------------------------------------------------------------------
  1336. bool SoldierGameObj::Is_In_Elevator( void )
  1337. {
  1338. HumanPhysClass * p_human_phys = Peek_Human_Phys();
  1339. return
  1340. p_human_phys != NULL &&
  1341. p_human_phys->Peek_Carrier_Object() != NULL &&
  1342. p_human_phys->Peek_Carrier_Object()->As_ElevatorPhysClass() != NULL;
  1343. }
  1344. //-----------------------------------------------------------------------------
  1345. float SoldierGameObj::Get_Max_Speed( void )
  1346. {
  1347. return Peek_Human_Phys()->Get_Normalized_Speed();
  1348. }
  1349. //------------------------------------------------------------------------------------
  1350. void SoldierGameObj::Set_Max_Speed( float speed )
  1351. {
  1352. Peek_Human_Phys()->Set_Normalized_Speed( speed );
  1353. }
  1354. //------------------------------------------------------------------------------------
  1355. float SoldierGameObj::Get_Turn_Rate( void )
  1356. {
  1357. return Get_Definition().TurnRate;
  1358. }
  1359. //------------------------------------------------------------------------------------
  1360. void SoldierGameObj::Generate_Control( void )
  1361. {
  1362. switch( Get_State() ) {
  1363. case HumanStateClass::DEATH:
  1364. // case HumanStateClass::WOUNDED:
  1365. // case HumanStateClass::DESTROY:
  1366. Clear_Control();
  1367. break;
  1368. default:
  1369. SmartGameObj::Generate_Control();
  1370. break;
  1371. }
  1372. }
  1373. //------------------------------------------------------------------------------------
  1374. void SoldierGameObj::Apply_Control( void )
  1375. {
  1376. // if gameplay not permitted, skip
  1377. if ( !CombatManager::Is_Gameplay_Permitted() ) {
  1378. Clear_Control();
  1379. Controller.Reset();
  1380. return;
  1381. }
  1382. #ifdef WWDEBUG
  1383. // Change the control before applying
  1384. if ( IS_SOLOPLAY && Is_Human_Controlled() && Input::Get_State( INPUT_FUNCTION_DEBUG_RAPID_MOVE ) ) {
  1385. if ( InFlyMode ) {
  1386. Control.Set_Analog( ControlClass::ANALOG_MOVE_UP,
  1387. Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD ) );
  1388. Control.Set_Analog( ControlClass::ANALOG_MOVE_FORWARD, 0 );
  1389. } else {
  1390. Control.Set_Analog( ControlClass::ANALOG_MOVE_FORWARD,
  1391. Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD ) * 10 );
  1392. }
  1393. }
  1394. #endif
  1395. if ( Get_State() == HumanStateClass::IN_VEHICLE ) {
  1396. // Handle Vehicle Gunner Toggle
  1397. if ( Get_Vehicle() && Get_Vehicle()->Get_Driver() == this ) {
  1398. if ( Control.Get_Boolean( ControlClass::BOOLEAN_VEHICLE_TOGGLE_GUNNER ) ) {
  1399. Get_Vehicle()->Toggle_Driver_Is_Gunner();
  1400. }
  1401. }
  1402. if ( CombatManager::I_Am_Server() ) // Server authoritative
  1403. // if ( CombatManager::I_Am_Server() ||
  1404. // (Is_Controlled_By_Me() && TransitionCompletionData == NULL) )
  1405. {
  1406. if ( Control.Get_Boolean( ControlClass::BOOLEAN_ACTION ) ) {
  1407. TransitionManager::Check( this, true );
  1408. }
  1409. }
  1410. return;
  1411. }
  1412. if ( ( Get_State() == HumanStateClass::TRANSITION ) ||
  1413. ( Get_State() == HumanStateClass::ANIMATION ) ||
  1414. ( Get_State() == HumanStateClass::DESTROY ) ||
  1415. ( Get_State() == HumanStateClass::DEATH ) ||
  1416. ( Get_State() == HumanStateClass::ON_FIRE ) ||
  1417. ( Get_State() == HumanStateClass::ON_CHEM ) ||
  1418. ( Get_State() == HumanStateClass::ON_CNC_FIRE ) ||
  1419. ( Get_State() == HumanStateClass::ON_CNC_CHEM ) ||
  1420. ( Get_State() == HumanStateClass::ON_ELECTRIC ) ) {
  1421. // Force exit of the corpse mode
  1422. if ( Get_State() == HumanStateClass::DESTROY && Is_Human_Controlled() ) {
  1423. if ( Control.Get_Boolean( ControlClass::BOOLEAN_WEAPON_FIRE_PRIMARY ) ) {
  1424. HumanState.Set_State_Timer( 1000 ); // Done!
  1425. }
  1426. }
  1427. // Debug_Say(( "No Control in transition\n" ));
  1428. Clear_Control();
  1429. // Controller.Reset();
  1430. // return;
  1431. }
  1432. if ( Get_State() == HumanStateClass::DIVE ) {
  1433. Clear_Control();
  1434. SmartGameObj::Apply_Control();
  1435. Vector3 forced_move(0,0,0);
  1436. int sub_state = HumanState.Get_Sub_State();
  1437. if ( sub_state & HumanStateClass::SUB_STATE_FORWARD ) forced_move = Vector3( 0.5f,0,0 );
  1438. if ( sub_state & HumanStateClass::SUB_STATE_BACKWARD ) forced_move = Vector3( -0.5f,0,0 );
  1439. if ( sub_state & HumanStateClass::SUB_STATE_LEFT ) forced_move = Vector3( 0,0.5f,0 );
  1440. if ( sub_state & HumanStateClass::SUB_STATE_RIGHT ) forced_move = Vector3( 0,-0.5f,0 );
  1441. Controller.Set_Move_Forward( forced_move.X );
  1442. Controller.Set_Move_Left( forced_move.Y );
  1443. Controller.Set_Move_Up( forced_move.Z );
  1444. return;
  1445. }
  1446. #define CLIMB_SCALE 0.3f
  1447. // Skip all this if control is clear?!?!?!
  1448. if ( Get_State() == HumanStateClass::LADDER ) {
  1449. // Convert Forward motion to Up motion
  1450. float up_down = CLIMB_SCALE * Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD );
  1451. if ( Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD ) == 0 ) {
  1452. LadderUpMask = false;
  1453. LadderDownMask = false;
  1454. }
  1455. if ( LadderUpMask ) {
  1456. up_down = MIN( up_down, 0 );
  1457. }
  1458. if ( LadderDownMask ) {
  1459. up_down = MAX( up_down, 0 );
  1460. }
  1461. // when on ladder, clear all velocity
  1462. Control.Set_Analog( ControlClass::ANALOG_MOVE_UP, up_down );
  1463. // Can't clear this, or we wont be able to climb next net frame!!!
  1464. // Control.Set_Analog( ControlClass::ANALOG_MOVE_FORWARD, 0 );
  1465. Control.Set_Analog( ControlClass::ANALOG_MOVE_LEFT, 0 );
  1466. Control.Set_Analog( ControlClass::ANALOG_TURN_LEFT, 0 );
  1467. Control.Set_Boolean( ControlClass::BOOLEAN_JUMP, 0 );
  1468. } else {
  1469. LadderUpMask = false;
  1470. LadderDownMask = false;
  1471. // no move up
  1472. if ( !InFlyMode ) {
  1473. Control.Set_Analog( ControlClass::ANALOG_MOVE_UP, 0 );
  1474. }
  1475. }
  1476. #if 0
  1477. if ( Control.Get_Boolean( ControlClass::BOOLEAN_CROUCH ) ) {
  1478. if ( HumanState.Is_Sub_State_Adjustable() ) {
  1479. // HumanState.Set_Sub_State( Get_Sub_State() ^ HumanStateClass::CROUCHED );
  1480. HumanState.Toggle_State_Flag( HumanStateClass::CROUCHED_FLAG );
  1481. if ( this == COMBAT_STAR ) {
  1482. Vector3 pos;
  1483. Get_Position( &pos );
  1484. if ( Is_Crouched() ) {
  1485. DIAG_LOG(( "COEN", "%1.2f; %1.2f; %1.2f", pos.X, pos.Y, pos.Z ));
  1486. } else {
  1487. DIAG_LOG(( "COEX", "%1.2f; %1.2f; %1.2f", pos.X, pos.Y, pos.Z ));
  1488. }
  1489. }
  1490. }
  1491. }
  1492. #else
  1493. if ( HumanState.Is_Sub_State_Adjustable() ) {
  1494. bool new_state = Control.Get_Boolean( ControlClass::BOOLEAN_CROUCH );
  1495. bool old_state = HumanState.Get_State_Flag( HumanStateClass::CROUCHED_FLAG );
  1496. if ( new_state != old_state ) {
  1497. HumanState.Toggle_State_Flag( HumanStateClass::CROUCHED_FLAG );
  1498. if ( this == COMBAT_STAR ) {
  1499. Vector3 pos;
  1500. Get_Position( &pos );
  1501. if ( Is_Crouched() ) {
  1502. DIAG_LOG(( "COEN", "%1.2f; %1.2f; %1.2f", pos.X, pos.Y, pos.Z ));
  1503. } else {
  1504. DIAG_LOG(( "COEX", "%1.2f; %1.2f; %1.2f", pos.X, pos.Y, pos.Z ));
  1505. }
  1506. }
  1507. }
  1508. }
  1509. #endif
  1510. /*
  1511. if ( CombatManager::I_Am_Server() &&
  1512. Control.Get_Boolean(ControlClass::BOOLEAN_DROP_FLAG) ) {
  1513. CombatManager::Soldier_Drops_Flag(this);
  1514. }
  1515. */
  1516. DetonateC4 = false;
  1517. if ( Get_Weapon() && Control.Get_Boolean( ControlClass::BOOLEAN_WEAPON_USE ) ) {
  1518. if ( Get_Weapon()->Get_Style() == WEAPON_HOLD_STYLE_C4 ) {
  1519. DetonateC4 = true;
  1520. }
  1521. if ( Get_Weapon()->Get_Can_Snipe() ) {
  1522. if ( HumanState.Is_Sub_State_Adjustable() ) {
  1523. HumanState.Toggle_State_Flag( HumanStateClass::SNIPING_FLAG );
  1524. }
  1525. }
  1526. }
  1527. #if 0
  1528. if ( Is_Sniping() ) {
  1529. // No motion for snipers (I don't know if this should be in Soldier.cpp)
  1530. // (But then, Sniper mode means nothing for plain soldiers, only for players)
  1531. // Don't clear the move forward, just don't allow the controller to have
  1532. // any move forward. This was not alowing sniper zoom
  1533. // Control.Set_Analog( ControlClass::ANALOG_MOVE_FORWARD, 0 );
  1534. Control.Set_Analog( ControlClass::ANALOG_MOVE_LEFT, 0 );
  1535. Control.Set_Boolean( ControlClass::BOOLEAN_JUMP, 0 );
  1536. Control.Set_Boolean( ControlClass::BOOLEAN_CROUCH, 0 );
  1537. Control.Set_Boolean( ControlClass::BOOLEAN_DIVE_FORWARD, 0 );
  1538. Control.Set_Boolean( ControlClass::BOOLEAN_DIVE_BACKWARD, 0 );
  1539. Control.Set_Boolean( ControlClass::BOOLEAN_DIVE_LEFT, 0 );
  1540. Control.Set_Boolean( ControlClass::BOOLEAN_DIVE_RIGHT, 0 );
  1541. Control.Set_Boolean( ControlClass::BOOLEAN_ACTION, 0 ); // stop ladder
  1542. }
  1543. #endif
  1544. if ( Is_Sniping() || Is_On_Ladder() ) {
  1545. // No diving for snipers or on ladders
  1546. Control.Set_Boolean( ControlClass::BOOLEAN_DIVE_FORWARD, 0 );
  1547. Control.Set_Boolean( ControlClass::BOOLEAN_DIVE_BACKWARD, 0 );
  1548. Control.Set_Boolean( ControlClass::BOOLEAN_DIVE_LEFT, 0 );
  1549. Control.Set_Boolean( ControlClass::BOOLEAN_DIVE_RIGHT, 0 );
  1550. }
  1551. bool dove = false;
  1552. // Can only dive if upright
  1553. if ( Get_State() == HumanStateClass::UPRIGHT ) {
  1554. if ( Control.Get_Boolean( ControlClass::BOOLEAN_DIVE_FORWARD ) ) {
  1555. HumanState.Set_State( HumanStateClass::DIVE, HumanStateClass::SUB_STATE_FORWARD );
  1556. dove = true;
  1557. }
  1558. if ( Control.Get_Boolean( ControlClass::BOOLEAN_DIVE_BACKWARD ) ) {
  1559. HumanState.Set_State( HumanStateClass::DIVE, HumanStateClass::SUB_STATE_BACKWARD );
  1560. dove = true;
  1561. }
  1562. if ( Control.Get_Boolean( ControlClass::BOOLEAN_DIVE_LEFT ) ) {
  1563. HumanState.Set_State( HumanStateClass::DIVE, HumanStateClass::SUB_STATE_LEFT );
  1564. dove = true;
  1565. }
  1566. if ( Control.Get_Boolean( ControlClass::BOOLEAN_DIVE_RIGHT ) ) {
  1567. HumanState.Set_State( HumanStateClass::DIVE, HumanStateClass::SUB_STATE_RIGHT );
  1568. dove = true;
  1569. }
  1570. if ( dove && this == COMBAT_STAR ) {
  1571. Vector3 pos;
  1572. Get_Position( &pos );
  1573. DefenseObjectClass * defense = Get_Defense_Object();
  1574. const char * weapon_name = "";
  1575. int ammo = 0;
  1576. if ( Get_Weapon() != NULL ) {
  1577. weapon_name = Get_Weapon()->Get_Definition()->Get_Name();
  1578. ammo = Get_Weapon()->Get_Total_Rounds();
  1579. }
  1580. DIAG_LOG(( "ROUS", "%1.2f; %1.2f; %1.2f; %1.2f; %1.2f; %s; %d", pos.X, pos.Y, pos.Z, defense->Get_Shield_Strength(), defense->Get_Health(), weapon_name, ammo ));
  1581. }
  1582. }
  1583. // Handle facing
  1584. float amount = Control.Get_Analog( ControlClass::ANALOG_TURN_LEFT );
  1585. if ( COMBAT_STAR == this ) { // Star gets turning from the camera
  1586. amount = 0;
  1587. }
  1588. if ( amount != 0 ) {
  1589. float heading = Peek_Human_Phys()->Get_Heading();
  1590. heading += amount * Get_Turn_Rate() * TimeManager::Get_Frame_Seconds();
  1591. heading = WWMath::Wrap( heading, DEG_TO_RADF( -180.0f ), DEG_TO_RADF( 180.0f ) );
  1592. Peek_Human_Phys()->Set_Heading(heading);
  1593. Control.Set_Analog(ControlClass::ANALOG_TURN_LEFT,0.0f);
  1594. if ( !Is_Human_Controlled() ) { // human players don't use turn anims
  1595. HumanState.Set_Turn_Velocity( amount ); // play the leg turning anim
  1596. }
  1597. }
  1598. // Let parent class handle the rest
  1599. SmartGameObj::Apply_Control();
  1600. #if 01
  1601. // Have to Move_Up after after Apply control, but BOOLEAN_JUMP is cleared
  1602. if ( Control.Get_Boolean( ControlClass::BOOLEAN_JUMP ) ) {
  1603. if ( Get_State() != HumanStateClass::AIRBORNE ) {
  1604. Controller.Set_Move_Up( Get_Definition().JumpVelocity );
  1605. }
  1606. if ( this == COMBAT_STAR ) {
  1607. Vector3 pos;
  1608. Get_Position( &pos );
  1609. DefenseObjectClass * defense = Get_Defense_Object();
  1610. const char * weapon_name = "";
  1611. int ammo = 0;
  1612. if ( Get_Weapon() != NULL ) {
  1613. weapon_name = Get_Weapon()->Get_Definition()->Get_Name();
  1614. ammo = Get_Weapon()->Get_Total_Rounds();
  1615. }
  1616. DIAG_LOG(( "JUUS", "%1.2f; %1.2f; %1.2f; %1.2f; %1.2f; %s; %d", pos.X, pos.Y, pos.Z, defense->Get_Shield_Strength(), defense->Get_Health(), weapon_name, ammo ));
  1617. }
  1618. }
  1619. #else
  1620. static float jump_timer = 0;
  1621. // Have to Move_Up after after Apply control, but BOOLEAN_JUMP is cleared
  1622. if ( Control.Get_Boolean( ControlClass::BOOLEAN_JUMP ) ) {
  1623. if ( Get_State() != HumanStateClass::AIRBORNE ) {
  1624. HumanState.Set_State( HumanStateClass::AIRBORNE, HumanState.Get_Sub_State() );
  1625. jump_timer = 0.2f;
  1626. }
  1627. }
  1628. if ( jump_timer > 0 ) {
  1629. jump_timer -= TimeManager::Get_Frame_Seconds();
  1630. if ( jump_timer <= 0 ) {
  1631. Controller.Set_Move_Up( Get_Definition().JumpVelocity );
  1632. }
  1633. }
  1634. #endif
  1635. #if 0
  1636. if ( Is_Sniping() ) {
  1637. // Dont allow move forward. It may have been requested by the
  1638. // Control, because we can't clear it if it must persist for
  1639. // network sniper zoom. So just clear it here.
  1640. Controller.Set_Move_Forward( 0 );
  1641. }
  1642. #else
  1643. if ( Is_Sniping() ) {
  1644. // Dont allow move forward. It may have been requested by the
  1645. // Control, because we can't clear it if it must persist for
  1646. // network sniper zoom. So just clear it here.
  1647. Controller.Set_Move_Forward( WWMath::Clamp( Controller.Get_Move_Forward(), -0.25f, 0.25f ) );
  1648. Controller.Set_Move_Left( WWMath::Clamp( Controller.Get_Move_Left(), -0.25f, 0.25f ) );
  1649. }
  1650. #endif
  1651. if ( Get_State() == HumanStateClass::LADDER ) {
  1652. // When on ladder, you can't move forward
  1653. // Same rules as above wrt the network persistence
  1654. Controller.Set_Move_Forward( 0 );
  1655. }
  1656. if ( ( Get_State() == HumanStateClass::UPRIGHT ) && Is_Crouched() ) {
  1657. float crouch_speed = GlobalSettingsDef::Get_Global_Settings ()->Get_Soldier_Crouch_Speed();
  1658. Controller.Set_Move_Forward( Controller.Get_Move_Forward() * crouch_speed );
  1659. Controller.Set_Move_Left( Controller.Get_Move_Left() * crouch_speed );
  1660. } else if ( Control.Get_Boolean( ControlClass::BOOLEAN_WALK ) ) {
  1661. float walk_speed = GlobalSettingsDef::Get_Global_Settings ()->Get_Soldier_Walk_Speed();
  1662. Controller.Set_Move_Forward( Controller.Get_Move_Forward() * walk_speed );
  1663. Controller.Set_Move_Left( Controller.Get_Move_Left() * walk_speed );
  1664. }
  1665. if ( this == COMBAT_STAR ) {
  1666. static bool was_walking = false;
  1667. if ( Control.Get_Boolean( ControlClass::BOOLEAN_WALK ) != was_walking ) {
  1668. Vector3 pos;
  1669. Get_Position( &pos );
  1670. if ( !was_walking ) {
  1671. DIAG_LOG(( "WAEN", "%1.2f; %1.2f; %1.2f", pos.X, pos.Y, pos.Z ));
  1672. } else {
  1673. DIAG_LOG(( "WAEX", "%1.2f; %1.2f; %1.2f", pos.X, pos.Y, pos.Z ));
  1674. }
  1675. was_walking = Control.Get_Boolean( ControlClass::BOOLEAN_WALK );
  1676. }
  1677. }
  1678. if ( this == COMBAT_STAR && Control.Get_Boolean( ControlClass::BOOLEAN_ACTION ) ) {
  1679. Vector3 pos;
  1680. COMBAT_STAR->Get_Position( &pos );
  1681. DIAG_LOG(( "ACPR", "%1.2f; %1.2f; %1.2f", pos.X, pos.Y, pos.Z ));
  1682. }
  1683. if ( CombatManager::I_Am_Server() ||
  1684. (Is_Controlled_By_Me() && TransitionCompletionData == NULL) )
  1685. {
  1686. bool action_triggered = Control.Get_Boolean( ControlClass::BOOLEAN_ACTION );
  1687. /// Transitions only trigger on server
  1688. bool transition_triggered = false;
  1689. if ( CombatManager::I_Am_Server() ) {
  1690. transition_triggered = TransitionManager::Check( this, action_triggered );
  1691. }
  1692. if ( !transition_triggered ) {
  1693. if ( action_triggered ) {
  1694. //
  1695. // Lookup the current target
  1696. //
  1697. // DamageableGameObj *damageable_target = HUDInfo::Get_Weapon_Target_Object();
  1698. DamageableGameObj *damageable_target = HUDInfo::Get_Info_Object();
  1699. if ( damageable_target != NULL ) {
  1700. PhysicalGameObj *physical_target = damageable_target->As_PhysicalGameObj();
  1701. if ( physical_target != NULL ) {
  1702. Vector3 target_pos;
  1703. physical_target->Get_Position( &target_pos );
  1704. Vector3 my_pos;
  1705. Get_Position( &my_pos );
  1706. //
  1707. // Check to see if the target is within the "poke" range
  1708. //
  1709. if ( (target_pos - my_pos).Length() <= 2 ) {
  1710. //
  1711. // Notify all the observers
  1712. //
  1713. if ( CombatManager::I_Am_Server () ) {
  1714. const GameObjObserverList & observer_list = physical_target->Get_Observers();
  1715. for( int index = 0; index < observer_list.Count(); index++ ) {
  1716. observer_list[ index ]->Poked( physical_target, this );
  1717. }
  1718. }
  1719. //
  1720. // Was the player the soldier who did the poking?
  1721. //
  1722. if ( COMBAT_STAR == this ) {
  1723. //
  1724. // Display this object in the encyclopedia
  1725. //
  1726. EncyclopediaMgrClass::Reveal_Object( damageable_target );
  1727. //
  1728. // Check for player terminal access
  1729. //
  1730. if ( physical_target->As_SimpleGameObj () != NULL ) {
  1731. //
  1732. // Is this a player terminal?
  1733. //
  1734. PlayerTerminalClass::TYPE type = PlayerTerminalClass::TYPE_NONE;
  1735. type = (physical_target->As_SimpleGameObj())->Get_Definition().Get_Player_Terminal_Type();
  1736. if (type != PlayerTerminalClass::TYPE_NONE) {
  1737. //
  1738. // Show the player terminal
  1739. //
  1740. PlayerTerminalClass::Get_Instance()->Display_Terminal( this, type );
  1741. }
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. }
  1748. } else {
  1749. // We started a transition, clear the control
  1750. Controller.Reset();
  1751. }
  1752. }
  1753. // Override the following controls
  1754. if ( IS_SOLOPLAY && Is_Human_Controlled() && Input::Get_State( INPUT_FUNCTION_DEBUG_RAPID_MOVE ) ) {
  1755. if ( Control.Get_Boolean( ControlClass::BOOLEAN_JUMP ) ) {
  1756. Controller.Set_Move_Up( Get_Definition().JumpVelocity );
  1757. }
  1758. }
  1759. }
  1760. //------------------------------------------------------------------------------------
  1761. void SoldierGameObj::Handle_Legs( void )
  1762. {
  1763. #if 0
  1764. if ( Get_State() != HumanStateClass::UPRIGHT ) {
  1765. LegFacing = Get_Facing();
  1766. SyncLegs = false;
  1767. }
  1768. // If Moving, clear LegFacing
  1769. if ((Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD ) != 0.0f ) ||
  1770. (Control.Get_Analog( ControlClass::ANALOG_MOVE_LEFT ) != 0.0f )) {
  1771. LegFacing = Get_Facing();
  1772. SyncLegs = false;
  1773. } else {
  1774. #define CLAMP_DEGREES 60
  1775. #define SYNC_DEGREES 35
  1776. #define SYNC_RATE 75
  1777. #define FLIP_RATE 720
  1778. // find the leg difference;
  1779. LegFacing = WWMath::Wrap( LegFacing, DEG_TO_RADF( -180 ), DEG_TO_RADF( 180 ) );
  1780. float legs_rotation = Get_Facing() - LegFacing;
  1781. legs_rotation = WWMath::Wrap( legs_rotation, DEG_TO_RADF( -180 ), DEG_TO_RADF( 180 ) );
  1782. // Clamp to with 90
  1783. legs_rotation = WWMath::Clamp( legs_rotation, DEG_TO_RADF( -CLAMP_DEGREES ), DEG_TO_RADF( CLAMP_DEGREES ) );
  1784. LegFacing = Get_Facing() - legs_rotation;
  1785. LegFacing = WWMath::Wrap( LegFacing, DEG_TO_RADF( -180 ), DEG_TO_RADF( 180 ) );
  1786. // if legs are more than 30 degrees off, start correcting
  1787. if ( WWMath::Fabs( legs_rotation ) > DEG_TO_RAD( SYNC_DEGREES ) ) {
  1788. SyncLegs = true;
  1789. }
  1790. SyncLegs = true;
  1791. // if syncing, start moving legs to match rotation
  1792. if ( SyncLegs ) {
  1793. float move = DEG_TO_RAD( SYNC_RATE ) * TimeManager::Get_Frame_Seconds() *
  1794. WWMath::Sign( legs_rotation );
  1795. if ( WWMath::Fabs( move ) >= WWMath::Fabs( legs_rotation ) ) {
  1796. move = legs_rotation; // Complete syncing
  1797. SyncLegs = false;
  1798. } else {
  1799. LegFacing += move;
  1800. if ( !Is_Human_Controlled() ) { // human players don't use turn anims
  1801. HumanState.Set_Turn_Velocity( move ); // Also, play the leg turning anim
  1802. }
  1803. }
  1804. }
  1805. }
  1806. if ( !SyncLegs ) {
  1807. HumanState.Set_Turn_Velocity( 0 );
  1808. }
  1809. // I'm making this staic for now, because all human
  1810. // skeletons have the bone at the same index
  1811. static int root_bone = -1;
  1812. if ( root_bone == -1 ) { // Get root bone index
  1813. root_bone = Peek_Model()->Get_Bone_Index( "root" );
  1814. }
  1815. static int torso_bone = -1;
  1816. if ( torso_bone == -1 ) { // Get torso bone index
  1817. torso_bone = Peek_Model()->Get_Bone_Index( "thorax" );
  1818. }
  1819. // Update the model
  1820. float legs_rotation = Get_Facing() - LegFacing;
  1821. if ( legs_rotation ) {
  1822. WWASSERT( root_bone != -1 );
  1823. WWASSERT( torso_bone != -1 );
  1824. if ( !Peek_Model()->Is_Bone_Captured( root_bone ) ) {
  1825. Peek_Model()->Capture_Bone( root_bone );
  1826. }
  1827. if ( !Peek_Model()->Is_Bone_Captured( torso_bone ) ) {
  1828. Peek_Model()->Capture_Bone( torso_bone );
  1829. }
  1830. // LOOK INTO RELATIVE_CONTROL_BONE
  1831. Matrix3D root_adjust(1); // adjust it
  1832. root_adjust.Rotate_Z( -legs_rotation );
  1833. Peek_Model()->Control_Bone( root_bone, root_adjust );
  1834. Matrix3D legs_adjust(1); // adjust it
  1835. legs_adjust.Rotate_Z( legs_rotation );
  1836. Peek_Model()->Control_Bone( torso_bone, legs_adjust );
  1837. } else { // no adjustment, release
  1838. if ( Peek_Model()->Is_Bone_Captured( root_bone ) ) {
  1839. Peek_Model()->Release_Bone( root_bone );
  1840. }
  1841. if ( Peek_Model()->Is_Bone_Captured( torso_bone ) ) {
  1842. Peek_Model()->Release_Bone( torso_bone );
  1843. }
  1844. }
  1845. #else
  1846. #if 0
  1847. float legs_rotation = 0;
  1848. // Compare the facing to the motion, set leg_racing to the difference
  1849. Vector3 move( Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD ), Control.Get_Analog( ControlClass::ANALOG_MOVE_LEFT ), 0 );
  1850. if ( move.Length() > 0 ) {
  1851. float move_direction = ::WWMath::Atan2( -move.Y, move.X );
  1852. float diff = move_direction;
  1853. diff += 2*DEG_TO_RADF( 360 ) + DEG_TO_RADF( 45 );
  1854. diff -= WWMath::Floor( diff / DEG_TO_RADF( 90 ) ) * DEG_TO_RADF( 90 );
  1855. diff -= DEG_TO_RADF( 45 );
  1856. legs_rotation = diff;
  1857. Debug_Say(( "Move (%1.1f) %1.1f %1.1f %1.1f %1.1f\n", RAD_TO_DEG(diff), move.X, move.Y, move.Z, RAD_TO_DEG( move_direction ) ));
  1858. }
  1859. // I'm making this staic for now, because all human
  1860. // skeletons have the bone at the same index
  1861. static int root_bone = -1;
  1862. if ( root_bone == -1 ) { // Get root bone index
  1863. root_bone = Peek_Model()->Get_Bone_Index( "c spine" );
  1864. }
  1865. static int torso_bone = -1;
  1866. if ( torso_bone == -1 ) { // Get torso bone index
  1867. torso_bone = Peek_Model()->Get_Bone_Index( "c spine1" );
  1868. }
  1869. if ( legs_rotation ) {
  1870. WWASSERT( root_bone != -1 );
  1871. WWASSERT( torso_bone != -1 );
  1872. if ( !Peek_Model()->Is_Bone_Captured( root_bone ) ) {
  1873. Peek_Model()->Capture_Bone( root_bone );
  1874. }
  1875. if ( !Peek_Model()->Is_Bone_Captured( torso_bone ) ) {
  1876. Peek_Model()->Capture_Bone( torso_bone );
  1877. }
  1878. Matrix3D root_adjust(1); // adjust it
  1879. root_adjust.Rotate_X( legs_rotation );
  1880. Peek_Model()->Control_Bone( root_bone, root_adjust );
  1881. Matrix3D legs_adjust(1); // adjust it
  1882. legs_adjust.Rotate_X( -legs_rotation );
  1883. Peek_Model()->Control_Bone( torso_bone, legs_adjust );
  1884. } else { // no adjustment, release
  1885. if ( Peek_Model()->Is_Bone_Captured( root_bone ) ) {
  1886. Peek_Model()->Release_Bone( root_bone );
  1887. }
  1888. if ( Peek_Model()->Is_Bone_Captured( torso_bone ) ) {
  1889. Peek_Model()->Release_Bone( torso_bone );
  1890. }
  1891. }
  1892. #endif
  1893. #endif
  1894. bool do_steps = false;
  1895. if ( Is_On_Ladder() ) {
  1896. do_steps = (Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD ) != 0.0f );
  1897. } else {
  1898. do_steps = ((Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD ) != 0.0f ) ||
  1899. (Control.Get_Analog( ControlClass::ANALOG_MOVE_LEFT ) != 0.0f ));
  1900. }
  1901. // Footsteps
  1902. if (!Is_Sniping() && !InFlyMode && CombatManager::Is_Gameplay_Permitted() && do_steps && Is_Control_Enabled() ) {
  1903. bool leg_mode = HumanState.Get_Leg_Mode();
  1904. // Watch for the legs to reach certain percentage completions
  1905. if ( leg_mode != LastLegMode ) {
  1906. int my_type = SurfaceEffectsManager::HITTER_TYPE_FOOTSTEP_RUN;
  1907. if ( Is_Crouched() ) {
  1908. my_type = SurfaceEffectsManager::HITTER_TYPE_FOOTSTEP_CROUCHED;
  1909. } else if ( HumanState.Get_Sub_State() & HumanStateClass::SUB_STATE_SLOW ) {
  1910. my_type = SurfaceEffectsManager::HITTER_TYPE_FOOTSTEP_WALK;
  1911. }
  1912. int ground_type = Peek_Human_Phys()->Get_Contact_Surface_Type();
  1913. // Try effects on ladders again BMG
  1914. /**/if ( Is_On_Ladder() ) {
  1915. my_type = SurfaceEffectsManager::HITTER_TYPE_FOOTSTEP_LADDER;
  1916. ground_type = SURFACE_TYPE_LIGHT_METAL;
  1917. }/**/
  1918. Matrix3D tm;
  1919. tm = Get_Transform();
  1920. if ( Control.Get_Analog( ControlClass::ANALOG_MOVE_FORWARD ) != 0.0f ) {
  1921. tm.Rotate_Z( DEG_TO_RAD( -90 ) );
  1922. }
  1923. float offset = leg_mode ? -0.15f : 0.1f;
  1924. tm.Translate( Vector3( offset, 0.3f, 0 ) );
  1925. bool allow_emitters = !Is_Stealthed();
  1926. SurfaceEffectsManager::Apply_Effect( ground_type, my_type, tm, NULL, this, true, allow_emitters);
  1927. LastLegMode = leg_mode;
  1928. }
  1929. }
  1930. }
  1931. static float _shake_delay = 0;
  1932. static float _cry_delay = 0;
  1933. static char * _profile_name = "Soldier Think";
  1934. //------------------------------------------------------------------------------------
  1935. void SoldierGameObj::Think( void )
  1936. {
  1937. { WWPROFILE( _profile_name );
  1938. if ( this == COMBAT_STAR ) {
  1939. _shake_delay -= TimeManager::Get_Frame_Seconds();
  1940. _cry_delay -= TimeManager::Get_Frame_Seconds();
  1941. }
  1942. /*
  1943. ActionClass * p_action = Get_Action();
  1944. WWASSERT(p_action != NULL);
  1945. */
  1946. //
  1947. // Simply check to see if this soldier has entered a coordination zone (which bound
  1948. // the entrances/exits of ladders and elevators). If so, then disable
  1949. // collision between them and all other soldiers.
  1950. //
  1951. Vector3 position;
  1952. {
  1953. WWPROFILE("Coordination Zone");
  1954. Get_Position( &position );
  1955. if ( UnitCoordinationZoneMgr::Is_Unit_In_Zone( position ) ) {
  1956. Enable_Ghost_Collision( true );
  1957. } else if ( Is_Safe_To_Disable_Ghost_Collision( position ) ) {
  1958. Enable_Ghost_Collision( false );
  1959. }
  1960. }
  1961. //
  1962. // Display a debug box to show the ghosted collision as ncessary
  1963. //
  1964. if ( DisplayDebugBoxForGhostCollision &&
  1965. (Peek_Physical_Object ()->Get_Collision_Group() == SOLDIER_GHOST_COLLISION_GROUP))
  1966. {
  1967. WWPROFILE("Add_Debug_AABox");
  1968. AABoxClass soldier_box;
  1969. soldier_box.Center = position + Vector3( 0, 0, 1.0F );
  1970. soldier_box.Extent.Set( 0.3F, 0.3F, 1.0F );
  1971. PhysicsSceneClass::Get_Instance ()->Add_Debug_AABox( soldier_box, Vector3( 1.0F, 0.0F, 0.25F ) );
  1972. }
  1973. // Stats
  1974. if ( Get_Player_Data() != NULL ) {
  1975. WWPROFILE("Stats");
  1976. Get_Player_Data()->Stats_Add_Game_Time( TimeManager::Get_Frame_Seconds() );
  1977. Get_Player_Data()->Stats_Set_Final_Health( Get_Defense_Object()->Get_Health() );
  1978. if ( Get_Vehicle() != NULL ) {
  1979. Get_Player_Data()->Stats_Add_Vehicle_Time( TimeManager::Get_Frame_Seconds() );
  1980. }
  1981. }
  1982. //
  1983. // Update the soldier's facing
  1984. //
  1985. {
  1986. WWPROFILE("Update_Locked_Facing");
  1987. Update_Locked_Facing();
  1988. }
  1989. /*
  1990. //
  1991. // In CTF a flag-bearer may not be permitted to use weapons
  1992. // This code will deselect the weapon if that is the case.
  1993. //
  1994. if (CombatManager::I_Am_Server() && Get_Weapon() != NULL &&
  1995. !CombatManager::Is_Firing_Enabled(this)) {
  1996. Get_Weapon_Bag()->Deselect();
  1997. }
  1998. */
  1999. // Handle_Legs moved form Apply_Control because clients don't run it for server objects
  2000. {
  2001. WWPROFILE("Handle_Legs");
  2002. Handle_Legs();
  2003. }
  2004. /*
  2005. if (CombatManager::I_Am_Server()) {
  2006. TransitionManager::Check( this );
  2007. }*/
  2008. }
  2009. {
  2010. WWPROFILE( "Embedded smart think in soldier" );
  2011. SmartGameObj::Think(); // Perform smart object thinking ( apply controls )
  2012. }
  2013. {
  2014. WWPROFILE( _profile_name );
  2015. if ( CombatManager::I_Am_Server() ) {
  2016. WWPROFILE("Handle C4");
  2017. // Handle C4 in a special way. When C4 is fired, the human plays
  2018. // a crouching animation, and starts a c4 placement timer.
  2019. if ( Get_Weapon() &&
  2020. (Get_Weapon()->Get_Style() == WEAPON_HOLD_STYLE_C4) &&
  2021. (Get_Weapon()->Is_Firing()) &&
  2022. (Get_State() == HumanStateClass::UPRIGHT) ) {
  2023. AnimationName = "s_a_human.h_a_j12c";
  2024. HumanState.Start_Scripted_Animation( AnimationName, true, false );
  2025. }
  2026. }
  2027. if ( Get_State() != HumanStateClass::IN_VEHICLE ) {
  2028. WWPROFILE("Vehicle");
  2029. // This may try to change controls, so can't be in Post_Think
  2030. HumanState.Update_Weapon( Get_Weapon(), WeaponBag->Is_Changed() );
  2031. if ( WeaponBag->Is_Changed() ) {
  2032. WeaponChanged = true;
  2033. WeaponBag->Reset_Changed();
  2034. }
  2035. // HumanState.Update_Aiming( Get_Weapon_Tilt(), Get_Weapon_Turn() );
  2036. HumanState.Update_State();
  2037. // Remove C4 from hand if empty
  2038. if ( Get_Weapon() && WeaponRenderModel ) {
  2039. if ( Get_Weapon()->Get_Style() == WEAPON_HOLD_STYLE_C4 || Get_Weapon()->Get_Style() == WEAPON_HOLD_STYLE_BEACON ) {
  2040. WeaponRenderModel->Set_Hidden( !Get_Weapon()->Is_Loaded() );
  2041. } else {
  2042. WeaponRenderModel->Set_Hidden( false );
  2043. }
  2044. }
  2045. } else {
  2046. // Debug_Say(( "No state update in vehicle\n" ));
  2047. }
  2048. /*
  2049. ** Special Death
  2050. */
  2051. // ArmorWarheadManager::SpecialDamageType SpecialDamageMode;
  2052. // float SpecialDamageTimer;
  2053. if ( SpecialDamageMode != ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_NONE &&
  2054. SpecialDamageTimer > 0 ) {
  2055. WWPROFILE("Special Damage");
  2056. float previous_timer = SpecialDamageTimer;
  2057. SpecialDamageTimer -= TimeManager::Get_Frame_Seconds();
  2058. // Once a second, make an explosion
  2059. if ( (int)SpecialDamageTimer != (int)previous_timer ) {
  2060. StringClass explosion_name = ArmorWarheadManager::Get_Special_Damage_Explosion( SpecialDamageMode );
  2061. if ( !explosion_name.Is_Empty() ) {
  2062. ExplosionDefinitionClass * def = (ExplosionDefinitionClass *)DefinitionMgrClass::Find_Typed_Definition( explosion_name, CLASSID_DEF_EXPLOSION );
  2063. if ( def != NULL) {
  2064. Vector3 pos = Get_Bullseye_Position();
  2065. ExplosionManager::Create_Explosion_At( def->Get_ID(), pos, NULL );
  2066. }
  2067. }
  2068. }
  2069. // Fix to allow taking fire damage in CNC
  2070. // if ( Get_Defense_Object()->Get_Health() > 0 && Allow_Special_Damage_State_Lock () ) {
  2071. if ( Get_Defense_Object()->Get_Health() > 0 &&
  2072. (Allow_Special_Damage_State_Lock () || Is_Human_Controlled() ) ) {
  2073. // do damage
  2074. WarheadType warhead = ArmorWarheadManager::Get_Special_Damage_Warhead( SpecialDamageMode );
  2075. float damage = ArmorWarheadManager::Get_Special_Damage_Scale( SpecialDamageMode ) *
  2076. TimeManager::Get_Frame_Seconds();
  2077. OffenseObjectClass off( damage, warhead, (ArmedGameObj*)SpecialDamageDamager.Get_Ptr() );
  2078. // Apply_Damage( off, 1 );
  2079. Apply_Damage_Extended( off, 1 );
  2080. }
  2081. if ( HumanState.Get_State() != HumanStateClass::DEATH ) {
  2082. // if dead, play death
  2083. if ( Get_Defense_Object()->Get_Health() <= 0 ) {
  2084. HumanState.Set_State( HumanStateClass::DEATH,
  2085. SpecialDamageMode - ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_FIRE + HumanStateClass::OUCH_FIRE );
  2086. }
  2087. if ( SpecialDamageTimer <= 0 ) { // Stop the flame
  2088. // HumanState.Set_State( HumanStateClass::UPRIGHT );
  2089. Set_Special_Damage_Mode( ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_NONE );
  2090. }
  2091. }
  2092. }
  2093. if (Get_State() == HumanStateClass::DESTROY) {
  2094. if ( HumanState.Get_State_Timer() > CORPSE_PERSIST_TIME ) {
  2095. // If Human Controlled, drop a backpack
  2096. if ( Is_Human_Controlled() ) {
  2097. // PowerUpGameObj::Create_Backpack( this ); // No more backpacks
  2098. }
  2099. Set_Delete_Pending();
  2100. }
  2101. }
  2102. // ClientOnlys doen't handle TRANSITION_COMPLETE
  2103. if ( !CombatManager::I_Am_Only_Client() || Is_Controlled_By_Me()) {
  2104. if ( Get_State() == HumanStateClass::TRANSITION_COMPLETE ) {
  2105. if ( TransitionCompletionData != NULL ) {
  2106. // Debug_Say(( "Ended Transition %p\n", Transition ));
  2107. // We just completed a transition, notify
  2108. TransitionInstanceClass::End( this, TransitionCompletionData );
  2109. TransitionCompletionData = NULL;
  2110. } else {
  2111. // Debug_Say(( "Ended Unknown Transition %p\n", Transition ));
  2112. HumanState.Set_State( HumanStateClass::UPRIGHT );
  2113. }
  2114. }
  2115. }
  2116. //
  2117. // Remove the emot icon (if necessary)
  2118. //
  2119. {
  2120. WWPROFILE("EmotIcon");
  2121. EmotIconTimer -= TimeManager::Get_Frame_Seconds();
  2122. if ( EmotIconTimer <= 0 ) {
  2123. //
  2124. // Remove the emoticon
  2125. //
  2126. if ( EmotIconModel != NULL && EmotIconModel->Is_In_Scene() ) {
  2127. EmotIconModel->Remove();
  2128. REF_PTR_RELEASE( EmotIconModel );
  2129. }
  2130. } else if ( EmotIconModel != NULL ) {
  2131. //
  2132. // Put the icon over the soldier's head
  2133. //
  2134. Matrix3D tm = Get_Transform();
  2135. tm.Set_Translation (tm.Get_Translation() + Vector3 (0, 0, EMOT_ICON_HEIGHT));
  2136. EmotIconModel->Set_Transform( tm );
  2137. }
  2138. }
  2139. //
  2140. // Should we change the idle facial animation?
  2141. //
  2142. GenerateIdleFacialAnimTimer -= TimeManager::Get_Frame_Seconds();
  2143. if ( GenerateIdleFacialAnimTimer <= 0 ) {
  2144. WWPROFILE("FacialAnims");
  2145. //
  2146. // Change the facial animation
  2147. //
  2148. if ( HeadModel != NULL ) {
  2149. // Don't stop a playing script animation
  2150. if ( ( HeadModel->Peek_Animation() == NULL ) ||
  2151. (HeadModel->Peek_Animation() == SpeechAnim ) ) {
  2152. SpeechAnim->Generate_Idle_Animation( 20, 0.5F );
  2153. HeadModel->Set_Animation( SpeechAnim, 0, RenderObjClass::ANIM_MODE_LOOP );
  2154. }
  2155. }
  2156. //
  2157. // Reset the timer
  2158. //
  2159. GenerateIdleFacialAnimTimer = 100.0F;
  2160. }
  2161. /*
  2162. if (!Is_Destroy()) {
  2163. CombatManager::Set_Soldier_Tint(this);
  2164. }
  2165. */
  2166. // Apply Surface damage
  2167. {
  2168. WWPROFILE("Apply_Damage");
  2169. if ( Peek_Human_Phys() ) {
  2170. SurfaceEffectsManager::Apply_Damage( Peek_Human_Phys()->Get_Contact_Surface_Type(), this );
  2171. }
  2172. }
  2173. // Update the water wake
  2174. // - If our feet are not on "underwater dirt" we don't even check for water
  2175. // - Otherwise, do a ray cast to find the water surface, if it hits
  2176. {
  2177. WWPROFILE("Water");
  2178. bool in_water = false;
  2179. Vector3 p0 = Get_Transform().Get_Translation();
  2180. Vector3 p1 = Get_Bullseye_Position();
  2181. int hit_type = SurfaceEffectsManager::HITTER_TYPE_FOOTSTEP_RUN;
  2182. if ( Is_Crouched() ) {
  2183. hit_type = SurfaceEffectsManager::HITTER_TYPE_FOOTSTEP_CROUCHED;
  2184. } else if ( HumanState.Get_Sub_State() & HumanStateClass::SUB_STATE_SLOW ) {
  2185. hit_type = SurfaceEffectsManager::HITTER_TYPE_FOOTSTEP_WALK;
  2186. }
  2187. Vector3 vel;
  2188. Peek_Human_Phys()->Get_Velocity(&vel);
  2189. if ((Peek_Human_Phys()->Get_Contact_Surface_Type() == SURFACE_TYPE_UNDERWATER_DIRT) &&
  2190. (vel.Length2() > 0.1f))
  2191. {
  2192. // Raycast to find water surface
  2193. CastResultStruct res;
  2194. LineSegClass ray(p0,p1);
  2195. PhysRayCollisionTestClass raytest(ray,&res,BULLET_COLLISION_GROUP,COLLISION_TYPE_PROJECTILE);
  2196. Peek_Human_Phys()->Inc_Ignore_Counter();
  2197. COMBAT_SCENE->Cast_Ray(raytest);
  2198. Peek_Human_Phys()->Dec_Ignore_Counter();
  2199. // if found update emitter
  2200. if ((res.Fraction < 1.0f) && (res.SurfaceType == SURFACE_TYPE_WATER_PERMEABLE)) {
  2201. Vector3 point;
  2202. ray.Compute_Point(res.Fraction,&point);
  2203. SurfaceEffectsManager::Update_Persistant_Emitter( WaterWake,
  2204. res.SurfaceType,
  2205. hit_type,
  2206. Matrix3D(point));
  2207. in_water = true;
  2208. }
  2209. }
  2210. if (!in_water) {
  2211. SurfaceEffectsManager::Update_Persistant_Emitter( WaterWake,
  2212. SURFACE_TYPE_DEFAULT,
  2213. hit_type,
  2214. Matrix3D(p0));
  2215. }
  2216. }
  2217. // Punish update
  2218. if ( Get_Player_Data() && Get_Player_Data()->Get_Punish_Timer() > 0 ) {
  2219. Get_Player_Data()->Inc_Punish_Timer( TimeManager::Get_Frame_Seconds() ) ;
  2220. }
  2221. }
  2222. }
  2223. //------------------------------------------------------------------------------------
  2224. void SoldierGameObj::Post_Think( void )
  2225. {
  2226. if ( Get_State() == HumanStateClass::IN_VEHICLE ) {
  2227. SmartGameObj::Post_Think();
  2228. return;
  2229. }
  2230. { WWPROFILE( "Soldier PostThink" );
  2231. HumanState.Post_Think();
  2232. bool update_weapon = false;
  2233. if ( WeaponChanged ) {
  2234. WeaponChanged = false;
  2235. Update_Back_Gun();
  2236. update_weapon = true;
  2237. }
  2238. if ( ( Get_Weapon() != NULL ) && ( Get_Weapon()->Is_Model_Update_Needed() ) ) {
  2239. update_weapon = true;
  2240. Get_Weapon()->Reset_Model_Update(); // reset model update needed
  2241. }
  2242. if ( update_weapon ) {
  2243. if ( Get_Weapon() != NULL ) {
  2244. Set_Weapon_Model( Get_Weapon()->Get_Model_Name() );
  2245. } else {
  2246. Set_Weapon_Model( NULL );
  2247. }
  2248. }
  2249. // if ( Get_Weapon()->Is_Anim_Update_Needed() ) {
  2250. // Set_Weapon_Animation( Get_Weapon()->Get_Anim_Name() );
  2251. // Get_Weapon()->Reset_Anim_Update(); // reset model anim update needed
  2252. // }
  2253. if (WeaponAnimControl) {
  2254. WeaponAnimControl->Update( TimeManager::Get_Frame_Seconds() ); // update the animation control
  2255. }
  2256. Handle_Head_look();
  2257. if ( Get_Weapon() != NULL && Get_State() == HumanStateClass::ON_FIRE ) {
  2258. Get_Weapon()->Set_Primary_Triggered( false );
  2259. Get_Weapon()->Set_Secondary_Triggered( false );
  2260. }
  2261. }
  2262. SmartGameObj::Post_Think();
  2263. Update_Healing_Effect();
  2264. }
  2265. //------------------------------------------------------------------------------------
  2266. const Matrix3D & SoldierGameObj::Get_Muzzle( int index )
  2267. {
  2268. static Matrix3D _muzzle(1);
  2269. if ( WeaponRenderModel != NULL ) {
  2270. Matrix3D true_muzzle = WeaponRenderModel->Get_Bone_Transform( "muzzlea0" );
  2271. Vector3 muzzle_pos = true_muzzle.Get_Translation();
  2272. _muzzle.Obj_Look_At( muzzle_pos, Get_Targeting_Pos(), 0 );
  2273. if ( !Is_Human_Controlled() ) {
  2274. // If the bullet is not close to going down the muzzle, force it to be
  2275. Vector3 to_target = _muzzle.Get_X_Vector();
  2276. Vector3 down_muzzle = true_muzzle.Get_X_Vector();
  2277. float cos = Vector3::Dot_Product( to_target, down_muzzle );
  2278. if ( cos < WWMath::Cos( DEG_TO_RADF( 20 ) ) ) {
  2279. _muzzle = true_muzzle;
  2280. }
  2281. }
  2282. }
  2283. return _muzzle;
  2284. }
  2285. static int head_bone = -1;
  2286. static int neck_bone = -1;
  2287. //------------------------------------------------------------------------------------
  2288. Matrix3D SoldierGameObj::Get_Look_Transform(void)
  2289. {
  2290. if ( head_bone != -1 ) {
  2291. // Convert from CS head convention back to normal
  2292. Matrix3D tm = Peek_Model()->Get_Bone_Transform( head_bone );
  2293. tm.Rotate_Z( DEG_TO_RAD( 90 ) );
  2294. tm.Rotate_X( DEG_TO_RAD( 90 ) );
  2295. return tm;
  2296. }
  2297. return Get_Transform();
  2298. }
  2299. //------------------------------------------------------------------------------------
  2300. #define HEAD_TURN_LIMIT DEG_TO_RADF( 70 )
  2301. #define HEAD_TILT_LIMIT DEG_TO_RADF( 20 )
  2302. void SoldierGameObj::Look_Random( float time )
  2303. {
  2304. if ( time == 0 && HeadLookDuration != 0 ) {
  2305. HeadLookDuration = 0.0001f; // maybe done next time...
  2306. } else {
  2307. HeadLookDuration = time;
  2308. }
  2309. HeadLookAngleTimer = 0;
  2310. HeadLookAngle = Vector3( 1,1,1 );
  2311. }
  2312. ////////////////////////////////////////////////////////////////
  2313. // Clamp_Angle
  2314. ////////////////////////////////////////////////////////////////
  2315. static inline float
  2316. Clamp_Angle (float angle, float min_angle, float max_angle)
  2317. {
  2318. //
  2319. // Make sure all the parameters are in the same range
  2320. //
  2321. angle = WWMath::Wrap (angle, 0, DEG_TO_RADF (360));
  2322. min_angle = WWMath::Wrap (min_angle, 0, DEG_TO_RADF (360));
  2323. max_angle = WWMath::Wrap (max_angle, 0, DEG_TO_RADF (360));
  2324. float result = angle;
  2325. if (min_angle <= max_angle) {
  2326. //
  2327. // Handle the 'typical' case where there is no 360-mark wrap-around
  2328. //
  2329. if (angle < min_angle) {
  2330. result = min_angle;
  2331. } else if (angle > max_angle) {
  2332. result = max_angle;
  2333. }
  2334. } else {
  2335. //
  2336. // Handle the 360-mark wrap-around case
  2337. //
  2338. if (angle < min_angle && angle > max_angle) {
  2339. float min_delta = min_angle - angle;
  2340. float max_delta = angle - max_angle;
  2341. //
  2342. // Which edge is the angle closer to?
  2343. //
  2344. if (min_delta < max_delta) {
  2345. result = min_angle;
  2346. } else {
  2347. result = max_angle;
  2348. }
  2349. }
  2350. }
  2351. return result;
  2352. }
  2353. void SoldierGameObj::Handle_Head_look( void )
  2354. {
  2355. if ( Peek_Model ()->Get_HTree () == NULL ) {
  2356. return ;
  2357. }
  2358. //
  2359. // Get the head bone
  2360. //
  2361. if ( head_bone == -1 || neck_bone == -1) {
  2362. head_bone = Peek_Model()->Get_Bone_Index( "C HEAD" );
  2363. neck_bone = Peek_Model()->Get_Bone_Index( "C NECK" );
  2364. WWASSERT( head_bone != -1 );
  2365. WWASSERT( neck_bone != -1 );
  2366. }
  2367. if ( HeadLookDuration > 0 ) {
  2368. HeadLookDuration -= TimeManager::Get_Frame_Seconds();
  2369. // Should we be returning to look ahead?
  2370. bool returning = HeadLookDuration < 0;
  2371. //Matrix3D head(1);
  2372. Vector3 desired_head_rotation( 0,0,0 );
  2373. if ( !returning ) {
  2374. if ( HeadLookAngle.Length() > 0.001f ) {
  2375. HeadLookAngleTimer -= TimeManager::Get_Frame_Seconds();
  2376. if ( HeadLookAngleTimer < 0 ) {
  2377. HeadLookAngle = Vector3(
  2378. FreeRandom.Get_Float( -HEAD_TURN_LIMIT, HEAD_TURN_LIMIT ),
  2379. FreeRandom.Get_Float( -HEAD_TILT_LIMIT, HEAD_TILT_LIMIT ) ,0);
  2380. // Debug_Say(( "New Look Turn %f Tilt %f\n", RAD_TO_DEG(HeadLookAngle.X), RAD_TO_DEG(HeadLookAngle.Y) ));
  2381. HeadLookAngleTimer = FreeRandom.Get_Float( 2, 5 );
  2382. }
  2383. desired_head_rotation = HeadLookAngle;
  2384. } else {
  2385. //
  2386. // Release the captured bone, this will have the effect of causing the Get_Bone_Transform ()
  2387. // methods to return the un-modified (due to being controlled) transform of the bone.
  2388. //
  2389. /*if ( Peek_Model()->Is_Bone_Captured( head_bone ) ) {
  2390. Peek_Model()->Release_Bone( head_bone );
  2391. }*/
  2392. ///
  2393. // Get the transform that has been used to modify the head bone...
  2394. //
  2395. const HTreeClass *htree = Peek_Model()->Get_HTree();
  2396. WWASSERT( htree != NULL );
  2397. Matrix3D bone_control_tm( 1 );
  2398. htree->Get_Bone_Control( head_bone, bone_control_tm );
  2399. //
  2400. // Get the inverse of the head-bone transform
  2401. //
  2402. Matrix3D inv_bone_control_tm;
  2403. bone_control_tm.Get_Orthogonal_Inverse (inv_bone_control_tm);
  2404. //
  2405. // Get the head to world and neck to world transforms
  2406. //
  2407. Matrix3D cur_head = Peek_Model()->Get_Bone_Transform( head_bone );
  2408. Matrix3D cur_neck = Peek_Model()->Get_Bone_Transform( neck_bone );
  2409. //
  2410. // Strip off the control transform from last frame
  2411. //
  2412. cur_head = cur_head * inv_bone_control_tm;
  2413. //
  2414. // Get the world to neck transform
  2415. //
  2416. Matrix3D world_to_neck_tm;
  2417. cur_neck.Get_Orthogonal_Inverse (world_to_neck_tm);
  2418. //
  2419. // Build a head to neck transform
  2420. //
  2421. Matrix3D head_to_neck_tm = world_to_neck_tm * cur_head;
  2422. //
  2423. // Get the target relative to the head
  2424. //
  2425. Vector3 relative_head_target;
  2426. Matrix3D::Inverse_Transform_Vector( cur_head, HeadLookTarget, &relative_head_target );
  2427. //
  2428. // Determine the 'twist' and lookup/down angles.
  2429. // Note: Currently in the head bone coordinate system, the X axis is the same
  2430. // as the Z axis in object space, the Y axis is the same as the X axis in object space,
  2431. // and the Z axis is the same as the Y axis in object space.
  2432. //
  2433. desired_head_rotation.X = WWMath::Atan2( relative_head_target.Z, relative_head_target.Y );
  2434. desired_head_rotation.Z = -WWMath::Fast_Asin( relative_head_target.X / relative_head_target.Length() );
  2435. desired_head_rotation.Y = 0;
  2436. //
  2437. // Determine how far to allow the character to turn and tilt his/her head.
  2438. // These boundaries are based on the "absolute" amount the person can turn
  2439. // their head, this has to take into consideration the amount that the current
  2440. // animation is turning the head and the amount we need to turn to look at the target.
  2441. //
  2442. Vector3 temp_vec = head_to_neck_tm.Get_Y_Vector ();
  2443. float curr_rot_x = ::atan2 (temp_vec.Z, temp_vec.Y);
  2444. float curr_rot_z = ::atan2 (temp_vec.X, temp_vec.Y);
  2445. float min_twist = ((-HEAD_TURN_LIMIT) - curr_rot_x);
  2446. float max_twist = (HEAD_TURN_LIMIT - curr_rot_x);
  2447. float min_tilt = ((-HEAD_TILT_LIMIT) - curr_rot_z);
  2448. float max_tilt = (HEAD_TILT_LIMIT - curr_rot_z);
  2449. //
  2450. // Clamp the rotations
  2451. //
  2452. desired_head_rotation.X = WWMath::Clamp( desired_head_rotation.X, min_twist, max_twist);
  2453. desired_head_rotation.Z = WWMath::Clamp( desired_head_rotation.Z, min_tilt, max_tilt);
  2454. }
  2455. }
  2456. #define HEAD_TURN_RATE (DEG_TO_RAD( 360 )/2)
  2457. #define HEAD_TILT_RATE (DEG_TO_RAD( 180 )/2)
  2458. float max_turn = HEAD_TURN_RATE * TimeManager::Get_Frame_Seconds();
  2459. float max_tilt = HEAD_TILT_RATE * TimeManager::Get_Frame_Seconds();
  2460. HeadRotation.X += WWMath::Clamp( (desired_head_rotation.X - HeadRotation.X), -max_turn, max_turn );
  2461. HeadRotation.Z += WWMath::Clamp( (desired_head_rotation.Z - HeadRotation.Z), -max_tilt, max_tilt );
  2462. Matrix3D head(1);
  2463. head.Rotate_X( HeadRotation.X );
  2464. head.Rotate_Z( HeadRotation.Z );
  2465. if ( !Peek_Model()->Is_Bone_Captured( head_bone ) ) {
  2466. Peek_Model()->Capture_Bone( head_bone );
  2467. }
  2468. WWASSERT( Peek_Model()->Is_Bone_Captured( head_bone ) );
  2469. if ( Peek_Model()->Is_Bone_Captured( head_bone ) ) {
  2470. Peek_Model()->Control_Bone( head_bone, head );
  2471. }
  2472. HeadRotation.Z = 0;
  2473. if ( returning && HeadRotation.Length() > 0.001f ) {
  2474. HeadLookDuration = 0.0001f; // maybe done next time...
  2475. }
  2476. }
  2477. }
  2478. //------------------------------------------------------------------------------------
  2479. void SoldierGameObj::Set_Blended_Animation( const char *animation_name, bool looping, float frame_offset, bool play_backwards )
  2480. {
  2481. if ( animation_name == NULL ) {
  2482. HumanState.Stop_Scripted_Animation();
  2483. return;
  2484. }
  2485. // Humans ignore the start_frame parameter for now
  2486. AnimationName = animation_name;
  2487. HumanState.Start_Scripted_Animation( animation_name, true, looping );
  2488. Get_Anim_Control()->Set_Mode( looping ? ANIM_MODE_LOOP : ANIM_MODE_ONCE, frame_offset );
  2489. if ( play_backwards ) {
  2490. HAnimClass *anim = Get_Anim_Control()->Peek_Animation();
  2491. if ( anim != NULL ) {
  2492. int frame_count = anim->Get_Num_Frames();
  2493. Get_Anim_Control()->Set_Mode( ANIM_MODE_TARGET, frame_count - 1 );
  2494. Get_Anim_Control()->Set_Target_Frame( 0 );
  2495. }
  2496. }
  2497. return ;
  2498. }
  2499. //------------------------------------------------------------------------------------
  2500. void SoldierGameObj::Set_Animation( const char *animation_name, bool looping, float start_frame )
  2501. {
  2502. if ( animation_name == NULL ) {
  2503. // Debug_Say(( "Stoping Scripted Human Animation\n" ));
  2504. HumanState.Stop_Scripted_Animation();
  2505. // FIX AnimControl->UnLock_Animation();
  2506. return;
  2507. }
  2508. // Humans ignore the start_frame parameter for now
  2509. // Debug_Say(( "Starting Scripted Human Animation %s\n", animation_name ));
  2510. AnimationName = animation_name;
  2511. HumanState.Start_Scripted_Animation( animation_name, false, looping );
  2512. }
  2513. //------------------------------------------------------------------------------------
  2514. void SoldierGameObj::Start_Transition_Animation( const char * anim_name, TransitionCompletionDataStruct *data )
  2515. {
  2516. // Debug_Say(( "Starting Human Transition Animation %s\n", anim_name ));
  2517. //WWASSERT( TransitionCompletionData == NULL );
  2518. TransitionCompletionData = data;
  2519. AnimationName = anim_name;
  2520. HumanState.Start_Transition_Animation( anim_name, false );
  2521. }
  2522. //------------------------------------------------------------------------------------
  2523. void SoldierGameObj::Set_Weapon_Model( const char *model_name )
  2524. {
  2525. if ( WeaponRenderModel != NULL ) { // remove old gun model
  2526. if ( Peek_Model() != NULL ) {
  2527. Peek_Model()->Remove_Sub_Object(WeaponRenderModel); // Clean the bone
  2528. }
  2529. WeaponRenderModel->Release_Ref();
  2530. WeaponRenderModel = NULL;
  2531. }
  2532. if ( (model_name != NULL) && (*model_name != 0) ) {
  2533. //Debug_Say(( "Updating soldier Weapon model to %s!!!\n", model_name ));
  2534. StringClass stripped_name(true);
  2535. Get_Render_Obj_Name_From_Filename( stripped_name, model_name );
  2536. WeaponRenderModel = SoldierGameObj::Find_RenderObj( stripped_name );
  2537. if ( WeaponRenderModel == NULL ) {
  2538. WeaponRenderModel = Create_Render_Obj_From_Filename( model_name );
  2539. WWASSERT( WeaponRenderModel );
  2540. SET_REF_OWNER( WeaponRenderModel );
  2541. Add_RenderObj( WeaponRenderModel );
  2542. WeaponRenderModel->Release_Ref();
  2543. }
  2544. WeaponRenderModel->Add_Ref();
  2545. // Create and add new gun model
  2546. if ( Peek_Model() != NULL ) {
  2547. if ( WeaponRenderModel->Get_Container() != Peek_Model() ) {
  2548. Peek_Model()->Add_Sub_Object_To_Bone( WeaponRenderModel, GUN_BONE_NAME );
  2549. }
  2550. }
  2551. assert( Get_Weapon() );
  2552. Get_Weapon()->Set_Model( WeaponRenderModel ); // let the weapon know who's firing him
  2553. }
  2554. }
  2555. //------------------------------------------------------------------------------------
  2556. void SoldierGameObj::Set_Weapon_Animation( const char *anim_name )
  2557. {
  2558. if ( WeaponAnimControl == NULL ) {
  2559. WeaponAnimControl = new SimpleAnimControlClass;
  2560. if (WeaponRenderModel != NULL ) {
  2561. // Update Anim Control
  2562. WeaponAnimControl->Set_Model( WeaponRenderModel );
  2563. }
  2564. }
  2565. if ( WeaponAnimControl != NULL ) {
  2566. // Debug_Say(( "Updating soldier gun anim to \"%s\"!!!\n", anim_name ));
  2567. if ( ( anim_name != NULL ) && ( *anim_name != 0 ) ) {
  2568. WeaponAnimControl->Set_Animation( anim_name );
  2569. }
  2570. }
  2571. }
  2572. void SoldierGameObj::Set_Back_Weapon_Model( const char *model_name )
  2573. {
  2574. if ( BackWeaponRenderModel != NULL ) { // remove old gun model
  2575. if (Peek_Model() != NULL ) {
  2576. Peek_Model()->Remove_Sub_Object(BackWeaponRenderModel);
  2577. }
  2578. BackWeaponRenderModel->Release_Ref();
  2579. BackWeaponRenderModel = NULL;
  2580. }
  2581. if ( (model_name != NULL) && (*model_name != 0) ) {
  2582. // Create and add back gun model
  2583. StringClass stripped_name(true);
  2584. Get_Render_Obj_Name_From_Filename( stripped_name, model_name );
  2585. BackWeaponRenderModel = SoldierGameObj::Find_RenderObj( stripped_name );
  2586. if ( BackWeaponRenderModel == NULL ) {
  2587. BackWeaponRenderModel = Create_Render_Obj_From_Filename( model_name );
  2588. // WWASSERT( BackWeaponRenderModel );
  2589. if ( BackWeaponRenderModel != NULL ) {
  2590. SET_REF_OWNER( BackWeaponRenderModel );
  2591. Add_RenderObj( BackWeaponRenderModel );
  2592. BackWeaponRenderModel->Release_Ref();
  2593. }
  2594. }
  2595. if ( BackWeaponRenderModel != NULL ) {
  2596. BackWeaponRenderModel->Add_Ref();
  2597. if (Peek_Model() != NULL ) {
  2598. Peek_Model()->Add_Sub_Object_To_Bone( BackWeaponRenderModel, BACK_GUN_BONE_NAME );
  2599. }
  2600. } else {
  2601. Debug_Say(( "Missing Back Model %s", model_name ));
  2602. }
  2603. }
  2604. }
  2605. void SoldierGameObj::Set_Back_Flag_Model(const char *model_name,
  2606. const Vector3 & tint)
  2607. {
  2608. if ( BackFlagRenderModel != NULL ) { // remove old gun model
  2609. if (Peek_Model() != NULL ) {
  2610. Peek_Model()->Remove_Sub_Object(BackFlagRenderModel);
  2611. }
  2612. BackFlagRenderModel->Release_Ref();
  2613. BackFlagRenderModel = NULL;
  2614. }
  2615. if ( (model_name != NULL) && (*model_name != 0) ) {
  2616. // Create and add back gun model
  2617. BackFlagRenderModel = Create_Render_Obj_From_Filename( model_name );
  2618. if ( BackFlagRenderModel != NULL ) {
  2619. SET_REF_OWNER( BackFlagRenderModel );
  2620. /*
  2621. extern void Tint(RenderObjClass *robj, const Vector3 & color);
  2622. Tint(BackFlagRenderModel, tint);
  2623. */
  2624. if (Peek_Model() != NULL ) {
  2625. Peek_Model()->Add_Sub_Object_To_Bone( BackFlagRenderModel, BACK_GUN_BONE_NAME );
  2626. }
  2627. } else {
  2628. Debug_Say(( "Missing Back Model %s", model_name ));
  2629. }
  2630. }
  2631. }
  2632. void SoldierGameObj::Update_Back_Gun( void )
  2633. {
  2634. //Debug_Say(("CommandoGameObj::Update_Back_Gun\n"));
  2635. WeaponClass *next_weapon = WeaponBag->Get_Next_Weapon();
  2636. if ( next_weapon && ( next_weapon != Get_Weapon() ) ) {
  2637. Set_Back_Weapon_Model( next_weapon->Get_Back_Model_Name() );
  2638. } else {
  2639. Set_Back_Weapon_Model( NULL );
  2640. }
  2641. }
  2642. //------------------------------------------------------------------------------------
  2643. float SoldierGameObj::Get_Weapon_Height( void )
  2644. {
  2645. float height = 1.62f; // set to be at about eye level
  2646. if ( Is_Crouched() ) {
  2647. height -= 0.56f;
  2648. }
  2649. return height; // verticle offset, move to weapon
  2650. }
  2651. //------------------------------------------------------------------------------------
  2652. float SoldierGameObj::Get_Weapon_Length( void )
  2653. {
  2654. return 0.8f; // forward offset, move to weapon
  2655. }
  2656. //------------------------------------------------------------------------------------
  2657. bool SoldierGameObj::Internal_Set_Targeting( const Vector3 & target_pos, bool do_tilt )
  2658. {
  2659. WWPROFILE( "Soldier Set Targeting" );
  2660. if ( CombatManager::Is_Skeleton_Slider_Demo_Enabled() ) {
  2661. return false;
  2662. }
  2663. SmartGameObj::Set_Targeting( target_pos );
  2664. if ( ( Get_State() == HumanStateClass::DEATH ) ||
  2665. ( Get_State() == HumanStateClass::DESTROY ) ||
  2666. ( Get_State() == HumanStateClass::TRANSITION ) ||
  2667. ( Get_State() == HumanStateClass::LADDER ) ) {
  2668. // Debug_Say(( "Ignore Set Target in Transition \n" ));
  2669. return false;
  2670. }
  2671. if ( Get_State() == HumanStateClass::IN_VEHICLE ) {
  2672. if ( Vehicle != NULL ) {
  2673. if ( Vehicle->Get_Driver_Is_Gunner() ) {
  2674. if ( Vehicle->Get_Driver() == this ) {
  2675. Vehicle->Set_Targeting( target_pos );
  2676. }
  2677. } else {
  2678. if ( Vehicle->Get_Driver() == this && Vehicle->Get_Gunner() == NULL ) {
  2679. Vehicle->Set_Targeting( target_pos );
  2680. } else if ( Vehicle->Get_Gunner() == this ) {
  2681. Vehicle->Set_Targeting( target_pos );
  2682. }
  2683. }
  2684. }
  2685. return false;
  2686. }
  2687. Vector3 muzzle_pos;
  2688. Get_Position( &muzzle_pos );
  2689. muzzle_pos.Z += Get_Weapon_Height();
  2690. Vector3 rel_target_pos = target_pos - muzzle_pos;
  2691. // Set Tilt
  2692. float dist = rel_target_pos.Length();
  2693. float tilt = 0;
  2694. if ( dist && do_tilt ) {
  2695. tilt = WWMath::Fast_Asin( rel_target_pos.Z / dist );
  2696. }
  2697. // tilt = 0;
  2698. // Debug_Say(( "Tilt %f", tilt ));
  2699. bool is_complete = true;
  2700. // Set Facing
  2701. float cur_facing = Peek_Human_Phys()->Get_Heading();
  2702. float facing = WWMath::Atan2( rel_target_pos.Y, rel_target_pos.X );
  2703. float facing_dif = facing - cur_facing;
  2704. if ( WWMath::Fabs(facing_dif) > 0.001f ) {
  2705. WWPROFILE( "Facing" );
  2706. facing_dif = WWMath::Wrap( facing_dif, DEG_TO_RADF( -180.0f ), DEG_TO_RADF( 180.0f ) );
  2707. // Debug_Say(( "Must change %1.3f, from facing %1.3f to facing %1.3f\n", RAD_TO_DEG( facing_dif ), RAD_TO_DEG( cur_facing ), RAD_TO_DEG( facing ) ));
  2708. float change = facing_dif;
  2709. if ( !Is_Human_Controlled() ) { // human players don't use turn limits
  2710. float max_change = Get_Turn_Rate() * TimeManager::Get_Frame_Seconds();
  2711. // Turn more slowly when turning a small amount
  2712. if ( WWMath::Fabs( change ) < DEG_TO_RAD( 20 ) ) {
  2713. max_change *= 0.3f;
  2714. }
  2715. change = WWMath::Clamp( facing_dif, -max_change, max_change );
  2716. }
  2717. if ( !Is_Human_Controlled() ) { // human players don't use turn anims
  2718. HumanState.Set_Turn_Velocity( change ); // play the leg turning anim
  2719. }
  2720. is_complete = (change == facing_dif); // are we facing?
  2721. facing = cur_facing + change;
  2722. facing = WWMath::Wrap( facing, DEG_TO_RADF( -180.0f ), DEG_TO_RADF( 180.0f ) );
  2723. Peek_Human_Phys()->Set_Heading( facing );
  2724. }
  2725. if ( Is_Human_Controlled() && Get_State() != HumanStateClass::IN_VEHICLE ) {
  2726. #define TILT_DOWN_SPEED 4.0
  2727. float direction = -1;
  2728. if ( Get_Weapon() && Get_Weapon()->Is_Reloading() ) {
  2729. direction = 1;
  2730. }
  2731. ReloadingTilt += direction * TimeManager::Get_Frame_Seconds() * TILT_DOWN_SPEED;
  2732. ReloadingTilt = WWMath::Clamp( ReloadingTilt, 0, 1 );
  2733. if ( ReloadingTilt > 0 ) {
  2734. tilt = WWMath::Lerp( (float)tilt, DEG_TO_RADF( -90 ), ReloadingTilt );
  2735. }
  2736. }
  2737. HumanState.Update_Aiming( tilt, 0 ); // no turn
  2738. // facing = HumanState.Peek_Physical_Object()->Get_Heading();
  2739. // Debug_Say(( "Soldier Facing %f Tilt %f\n", RAD_TO_DEG( facing ), RAD_TO_DEG( WeaponTilt ) ));
  2740. // Debug_Say(( "rel_target_pos %f %f %f\n", rel_target_pos.X, rel_target_pos.Y, rel_target_pos.Z ));
  2741. return is_complete;
  2742. }
  2743. //------------------------------------------------------------------------------------
  2744. bool SoldierGameObj::Set_Targeting( const Vector3 & target_pos, bool do_tilt )
  2745. {
  2746. bool retval = false;
  2747. //
  2748. // Don't do the targetting if we are locked on an object
  2749. //
  2750. if ( FacingObject == NULL ) {
  2751. retval = Internal_Set_Targeting( target_pos, do_tilt );
  2752. }
  2753. return retval;
  2754. }
  2755. //------------------------------------------------------------------------------------
  2756. RenderObjClass * SoldierGameObj::Find_Head_Model( void )
  2757. {
  2758. RenderObjClass *head_model = NULL;
  2759. //
  2760. // Get a pointer to the HLod this object is using
  2761. //
  2762. RenderObjClass *model = Peek_Model ();
  2763. if ( model != NULL && model->Class_ID () == RenderObjClass::CLASSID_HLOD ) {
  2764. HLodClass *lod = reinterpret_cast<HLodClass *> ( model );
  2765. //
  2766. // Try to find the head-bone
  2767. //
  2768. int bone_index = lod->Get_Bone_Index ( "C HEAD" );
  2769. int obj_count = lod->Get_Num_Sub_Objects_On_Bone(bone_index);
  2770. //
  2771. // Try to find a model on the head bone that uses the human head skeleton
  2772. //
  2773. for (int index = 0; index < obj_count; index ++) {
  2774. RenderObjClass *render_obj = lod->Get_Sub_Object_On_Bone ( index, bone_index );
  2775. if (render_obj != NULL) {
  2776. const HTreeClass *htree = render_obj->Get_HTree();
  2777. if ( htree != NULL ) {
  2778. //
  2779. // Is this really a head model?
  2780. //
  2781. if ( ::stricmp (htree->Get_Name(), "S_A_HEAD") == 0 ||
  2782. ::stricmp (htree->Get_Name(), "S_B_HEAD") == 0)
  2783. {
  2784. head_model = render_obj;
  2785. break;
  2786. }
  2787. }
  2788. render_obj->Release_Ref ();
  2789. }
  2790. }
  2791. }
  2792. return head_model;
  2793. }
  2794. //------------------------------------------------------------------------------------
  2795. void SoldierGameObj::Set_Emot_Icon ( const char *model_name, float duration )
  2796. {
  2797. //
  2798. // Free the old emot icon
  2799. //
  2800. if ( EmotIconModel != NULL ) {
  2801. if ( EmotIconModel->Is_In_Scene() ) {
  2802. EmotIconModel->Remove ();
  2803. }
  2804. REF_PTR_RELEASE( EmotIconModel );
  2805. }
  2806. //
  2807. // Try to load the new emot icon model
  2808. //
  2809. if ( model_name != NULL ) {
  2810. //
  2811. // Create the new model
  2812. //
  2813. EmotIconModel = ::Create_Render_Obj_From_Filename( model_name );
  2814. if ( EmotIconModel != NULL ) {
  2815. //
  2816. // Determine what the animation name for the model is
  2817. //
  2818. const char *name = EmotIconModel->Get_Name ();
  2819. StringClass anim_name;
  2820. anim_name.Format ("%s.%s", name, name);
  2821. //
  2822. // Animate the model
  2823. //
  2824. HAnimClass *anim = WW3DAssetManager::Get_Instance ()->Get_HAnim( anim_name );
  2825. if ( anim != NULL ) {
  2826. EmotIconModel->Set_Animation( anim, 0.0F, RenderObjClass::ANIM_MODE_LOOP );
  2827. REF_PTR_RELEASE( anim );
  2828. }
  2829. //
  2830. // Put the icon a few meters above the soldier's head
  2831. //
  2832. Matrix3D tm = Get_Transform();
  2833. tm.Set_Translation (tm.Get_Translation() + Vector3 (0, 0, EMOT_ICON_HEIGHT));
  2834. EmotIconModel->Set_Transform( tm );
  2835. COMBAT_SCENE->Add_Render_Object( EmotIconModel );
  2836. EmotIconTimer = duration;
  2837. }
  2838. }
  2839. return ;
  2840. }
  2841. //------------------------------------------------------------------------------------
  2842. void SoldierGameObj::Say_Dialogue( int dialog_id )
  2843. {
  2844. WWASSERT( dialog_id >= 0 && dialog_id < DIALOG_MAX );
  2845. //
  2846. // Lookup the conversation we are starting
  2847. //
  2848. int conversation_id = DialogList[dialog_id].Get_Conversation();
  2849. if ( conversation_id > 0 ) {
  2850. //
  2851. // Start the conversation
  2852. //
  2853. ActiveConversationClass *conversation = ConversationMgrClass::Start_Conversation( this, conversation_id, true );
  2854. REF_PTR_RELEASE (conversation);
  2855. }
  2856. return ;
  2857. }
  2858. //------------------------------------------------------------------------------------
  2859. float SoldierGameObj::Say_Dynamic_Dialogue
  2860. (
  2861. int text_id,
  2862. SoldierGameObj * speaker,
  2863. AudibleSoundClass ** sound_obj_to_return
  2864. )
  2865. {
  2866. float duration = 2.0F;
  2867. //
  2868. // Lookup the translation object from the strings database
  2869. //
  2870. TDBObjClass *translate_obj = TranslateDBClass::Find_Object( text_id );
  2871. if (translate_obj != NULL) {
  2872. const WCHAR *string = translate_obj->Get_String ();
  2873. int sound_def_id = (int)translate_obj->Get_Sound_ID ();
  2874. const char *anim_name = translate_obj->Get_Animation_Name ();
  2875. //
  2876. // If this soldier was still talking from a previos call, then
  2877. // kill the old sound
  2878. //
  2879. if ( speaker != NULL ) {
  2880. speaker->Stop_Current_Speech();
  2881. }
  2882. //
  2883. // Play the sound effect
  2884. //
  2885. bool display_text = true;
  2886. if ( sound_def_id > 0 ) {
  2887. //
  2888. // Create the sound object
  2889. //
  2890. AudibleSoundClass *speech = WWAudioClass::Get_Instance ()->Create_Sound( sound_def_id );
  2891. if ( speech != NULL ) {
  2892. duration = (speech->Get_Duration() / 1000.0F);
  2893. //
  2894. // Return the sound object to the caller as necessary
  2895. //
  2896. if ( sound_obj_to_return != NULL ) {
  2897. (*sound_obj_to_return) = speech;
  2898. (*sound_obj_to_return)->Add_Ref();
  2899. }
  2900. //
  2901. // Either play the sound at the speaker's location
  2902. // or just play it as a 2D sample.
  2903. //
  2904. if ( speaker != NULL ) {
  2905. speech->Set_Transform( speaker->Get_Transform() );
  2906. speech->Add_To_Scene();
  2907. display_text = (speech->Is_Sound_Culled() == false);
  2908. } else {
  2909. //
  2910. // Play the sound
  2911. //
  2912. speech->Play();
  2913. }
  2914. }
  2915. //
  2916. // Update the speaker's internal sound object pointer
  2917. //
  2918. if ( speaker != NULL ) {
  2919. speaker->CurrentSpeech = speech;
  2920. } else {
  2921. REF_PTR_RELEASE (speech);
  2922. }
  2923. }
  2924. //
  2925. // Check to see if this string is commented out.
  2926. //
  2927. if( string != NULL && string[0] == L'/' && string[1] == L'/' ) {
  2928. string += 2;
  2929. display_text = false;
  2930. }
  2931. //
  2932. // Display the text on the screen
  2933. //
  2934. if ( display_text && string != NULL && string[0] != 0 ) {
  2935. float message_duration = max( duration, 5.0F );
  2936. CombatManager::Get_Message_Window ()->Add_Message( string, Vector3 (1, 1, 1),
  2937. speaker, message_duration );
  2938. }
  2939. //
  2940. // Play the facial animation (if one exists)
  2941. //
  2942. if ( speaker != NULL && speaker->HeadModel != NULL) {
  2943. HAnimClass *head_anim = NULL;
  2944. //
  2945. // Dig out the skeleton name for the head model
  2946. //
  2947. StringClass anim_root_name;
  2948. const HTreeClass *htree = speaker->HeadModel->Get_HTree ();
  2949. if (htree != NULL) {
  2950. anim_root_name = htree->Get_Name ();
  2951. anim_root_name += ".";
  2952. }
  2953. //
  2954. // Determine if we should use a pre-canned animation, or
  2955. // if we should build one dynamically
  2956. //
  2957. if ( anim_name == NULL || anim_name[0] == 0 ) {
  2958. //
  2959. // Build an animation dynamically
  2960. //
  2961. const char *english_string = translate_obj->Get_English_String();
  2962. if ( english_string != NULL && english_string[0] != 0 ) {
  2963. if (speaker->SpeechAnim->Generate_Animation( english_string, duration )) {
  2964. head_anim = speaker->SpeechAnim;
  2965. }
  2966. }
  2967. } else {
  2968. //
  2969. // Build a string containing the fully qualified animation name
  2970. //
  2971. StringClass full_anim_name;
  2972. if ( ::strchr( anim_name, '.' ) == 0 ) {
  2973. full_anim_name = anim_root_name;
  2974. full_anim_name += anim_name;
  2975. } else {
  2976. full_anim_name = anim_name;
  2977. }
  2978. head_anim = WW3DAssetManager::Get_Instance()->Get_HAnim( full_anim_name );
  2979. }
  2980. //
  2981. // Recreate the facial animation when the speech is complete
  2982. //
  2983. speaker->GenerateIdleFacialAnimTimer = duration + 1.0F;
  2984. //
  2985. // Play the animation on the head model (if one exists)
  2986. //
  2987. if ( speaker->HeadModel != NULL && head_anim != NULL ) {
  2988. speaker->HeadModel->Set_Animation( head_anim, 0, RenderObjClass::ANIM_MODE_ONCE );
  2989. }
  2990. }
  2991. }
  2992. return duration;
  2993. }
  2994. //------------------------------------------------------------------------------------
  2995. void SoldierGameObj::Stop_Current_Speech( void )
  2996. {
  2997. //
  2998. // Kill the current sound we are making (speech, scream, grunt, etc)
  2999. //
  3000. if ( CurrentSpeech != NULL ) {
  3001. GenerateIdleFacialAnimTimer = 0;
  3002. CurrentSpeech->Stop();
  3003. CurrentSpeech->Remove_From_Scene();
  3004. CurrentSpeech->Release_Ref();
  3005. CurrentSpeech = NULL;
  3006. }
  3007. return ;
  3008. }
  3009. //------------------------------------------------------------------------------------
  3010. void SoldierGameObj::Apply_Damage( const OffenseObjectClass & damager, float scale, int alternate_skin )
  3011. {
  3012. if ( !Is_In_Vehicle() ) {
  3013. SmartGameObj::Apply_Damage( damager, scale, alternate_skin );
  3014. }
  3015. }
  3016. //------------------------------------------------------------------------------------
  3017. void SoldierGameObj::Apply_Damage_Extended( const OffenseObjectClass & damager, float scale,
  3018. const Vector3 & direction, const char * collision_box_name )
  3019. {
  3020. // If negative damage, just apply
  3021. if ( Get_Defense_Object()->Is_Repair( damager ) ) {
  3022. // if ( damager.Get_Damage() * scale < 0 ) {
  3023. SmartGameObj::Apply_Damage_Extended( damager, scale, direction, collision_box_name );
  3024. // Add electric effect
  3025. if ( HealingEffect == NULL ) {
  3026. HealingEffect = CombatMaterialEffectManager::Get_Health_Effect();
  3027. if ( HealingEffect != NULL ) {
  3028. Peek_Human_Phys()->Add_Effect_To_Me( HealingEffect );
  3029. }
  3030. }
  3031. if ( HealingEffect != NULL ) {
  3032. HealingEffect->Set_Target_Parameter(0.495f); // go almost halfway
  3033. }
  3034. return;
  3035. }
  3036. // Do this after the repair effect
  3037. /* if ( !CombatManager::I_Am_Server() ) { Clients can apply damage
  3038. return;
  3039. }*/
  3040. if ( Is_In_Vehicle() ) {
  3041. return;
  3042. }
  3043. bool ambushed = false;
  3044. // Ambush Kill
  3045. if ( ( Get_AI_State() == AI_STATE_IDLE ) || ( Get_AI_State() == AI_STATE_SECONDARY_IDLE ) ) {
  3046. // Only ambush if there is an owner to the damage, and the target is human controlled
  3047. if ( damager.Get_Owner() != NULL && !Is_Human_Controlled() ) {
  3048. scale *= AMBUSH_DAMAGE_SCALE;
  3049. ambushed = true;
  3050. // Debug_Say(( "Ambush Damage!!\n" ));
  3051. }
  3052. }
  3053. bool anim_ok = true;
  3054. Reset_Hibernating(); // Wake up when damaged
  3055. int ouch_type = Get_Ouch_Type( direction, collision_box_name );
  3056. // Stats
  3057. PlayerDataClass * damager_data = NULL;
  3058. if ( damager.Get_Owner() && damager.Get_Owner()->As_SoldierGameObj() ) {
  3059. damager_data = damager.Get_Owner()->As_SoldierGameObj()->Get_Player_Data();
  3060. }
  3061. // Dont add stats for "non-directional" damage. E.g. standing in a tiberium
  3062. // field should not count as thousands of hits.
  3063. if (direction.Length2() > WWMATH_EPSILON) {
  3064. switch( ouch_type ) {
  3065. case HumanStateClass::HEAD_FROM_BEHIND:
  3066. case HumanStateClass::HEAD_FROM_FRONT:
  3067. if ( Get_Player_Data() != NULL ) {
  3068. Get_Player_Data()->Stats_Add_Head_Hit();
  3069. }
  3070. if ( damager_data != NULL ) {
  3071. damager_data->Stats_Add_Head_Shot();
  3072. }
  3073. break;
  3074. case HumanStateClass::TORSO_FROM_BEHIND:
  3075. case HumanStateClass::TORSO_FROM_FRONT:
  3076. if ( Get_Player_Data() != NULL ) {
  3077. Get_Player_Data()->Stats_Add_Torso_Hit();
  3078. }
  3079. if ( damager_data != NULL ) {
  3080. damager_data->Stats_Add_Torso_Shot();
  3081. }
  3082. break;
  3083. case HumanStateClass::LEFT_ARM_FROM_BEHIND:
  3084. case HumanStateClass::LEFT_ARM_FROM_FRONT:
  3085. case HumanStateClass::RIGHT_ARM_FROM_BEHIND:
  3086. case HumanStateClass::RIGHT_ARM_FROM_FRONT:
  3087. if ( Get_Player_Data() != NULL ) {
  3088. Get_Player_Data()->Stats_Add_Arm_Hit();
  3089. }
  3090. if ( damager_data != NULL ) {
  3091. damager_data->Stats_Add_Arm_Shot();
  3092. }
  3093. break;
  3094. case HumanStateClass::LEFT_LEG_FROM_BEHIND:
  3095. case HumanStateClass::LEFT_LEG_FROM_FRONT:
  3096. case HumanStateClass::RIGHT_LEG_FROM_BEHIND:
  3097. case HumanStateClass::RIGHT_LEG_FROM_FRONT:
  3098. if ( Get_Player_Data() != NULL ) {
  3099. Get_Player_Data()->Stats_Add_Leg_Hit();
  3100. }
  3101. if ( damager_data != NULL ) {
  3102. damager_data->Stats_Add_Leg_Shot();
  3103. }
  3104. break;
  3105. case HumanStateClass::GROIN:
  3106. if ( Get_Player_Data() != NULL ) {
  3107. Get_Player_Data()->Stats_Add_Crotch_Hit();
  3108. }
  3109. if ( damager_data != NULL ) {
  3110. damager_data->Stats_Add_Crotch_Shot();
  3111. }
  3112. break;
  3113. }
  3114. }
  3115. // Determine what (if any) dialogue to say
  3116. int dialogue_id = -1;
  3117. ArmedGameObj *damage_owner = damager.Get_Owner();
  3118. if( damage_owner != NULL ) {
  3119. // Were we injured by a friend or foe?
  3120. if ( Is_Enemy( damage_owner ) ) {
  3121. dialogue_id = DIALOG_ON_TAKE_DAMAGE_FROM_ENEMY;
  3122. } else {
  3123. dialogue_id = DIALOG_ON_TAKE_DAMAGE_FROM_FRIEND;
  3124. }
  3125. }
  3126. float health_before = Get_Defense_Object()->Get_Health();
  3127. float armor_before = Get_Defense_Object()->Get_Shield_Strength();
  3128. if ( collision_box_name != NULL ) {
  3129. char * start = ::strchr( collision_box_name, '.' );
  3130. if ( start != NULL ) {
  3131. start++;
  3132. float bone_scale = BonesManager::Get_Bone_Damage_Scale( start );
  3133. scale *= bone_scale;
  3134. }
  3135. }
  3136. // Update damage indicators
  3137. if ( this == COMBAT_STAR ) {
  3138. if ( Get_Defense_Object()->Would_Damage( damager ) && !damager.ForceServerDamage ) {
  3139. if ( direction.Length() == 0 ) {
  3140. for ( int i = 0; i < 8; i++ ) {
  3141. CombatManager::Show_Star_Damage_Direction( i );
  3142. }
  3143. // Set all
  3144. } else {
  3145. Vector3 relative_direction = Get_Transform().Inverse_Rotate_Vector( direction );
  3146. // Convert direction into 0 .. 7
  3147. float angle = ::WWMath::Atan2 ( relative_direction.Y, -relative_direction.X);
  3148. int dir = (int)(8.0f * angle / DEG_TO_RAD( 360 ) + 8.5f);
  3149. CombatManager::Show_Star_Damage_Direction( dir & 7 );
  3150. }
  3151. }
  3152. }
  3153. SmartGameObj::Apply_Damage_Extended( damager, scale, direction, collision_box_name );
  3154. float health = Get_Defense_Object()->Get_Health();
  3155. if ( this == COMBAT_STAR ) {
  3156. Vector3 pos;
  3157. COMBAT_STAR->Get_Position( &pos );
  3158. int hitter_id = 0;
  3159. const char * weapon_name = "";
  3160. if ( damager.Get_Owner() ) {
  3161. hitter_id = damager.Get_Owner()->Get_ID();
  3162. if ( damager.Get_Owner()->Get_Weapon() ) {
  3163. weapon_name = damager.Get_Owner()->Get_Weapon()->Get_Definition()->Get_Name();
  3164. }
  3165. }
  3166. const char * body_part = ( collision_box_name != NULL ) ? collision_box_name : "";
  3167. float armor = Get_Defense_Object()->Get_Shield_Strength();
  3168. DIAG_LOG(( "DRCE", "%s; %d; %s; %1.2f; %1.2f; %1.2f; %1.2f; %1.2f", weapon_name, hitter_id, body_part, armor, health, pos.X, pos.Y, pos.Z ));
  3169. }
  3170. if (( damager.Get_Owner() == COMBAT_STAR ) && ( COMBAT_STAR != NULL )) {
  3171. Vector3 pos;
  3172. COMBAT_STAR->Get_Position( &pos );
  3173. const char * weapon_name = "";
  3174. int ammo = 0;
  3175. if ( COMBAT_STAR->Get_Weapon() ) {
  3176. weapon_name = COMBAT_STAR->Get_Weapon()->Get_Definition()->Get_Name();
  3177. ammo = COMBAT_STAR->Get_Weapon()->Get_Total_Rounds();
  3178. }
  3179. int hittee_id = Get_ID();
  3180. const char * body_part = ( collision_box_name != NULL ) ? collision_box_name : "";
  3181. float armor = Get_Defense_Object()->Get_Shield_Strength();
  3182. Vector3 victim_pos;
  3183. Get_Position( &victim_pos );
  3184. const char * team_name = Player_Type_Name( Get_Player_Type() );
  3185. DIAG_LOG(( "DEFE", "%1.2f; %1.2f; %1.2f; %s; %d; %d; %s; %1.2f; %1.2f; %1.2f; %1.2f; %1.2f; %s ", pos.X, pos.Y, pos.Z, weapon_name, ammo, hittee_id, body_part, armor, health, victim_pos.X, victim_pos.Y, victim_pos.Z, team_name ));
  3186. }
  3187. if ( ambushed ) {
  3188. int victim_id = Get_ID();
  3189. Vector3 victim_pos;
  3190. Get_Position( &victim_pos );
  3191. Vector3 shooter_pos;
  3192. damager.Get_Owner()->Get_Position( &shooter_pos );
  3193. float armor = Get_Defense_Object()->Get_Shield_Strength();
  3194. DIAG_LOG(( "AMGE", "%1.2f; %1.2f; %1.2f; %d; %1.2f; %1.2f; %1.2f; %1.2f; %1.2f", victim_pos.X, victim_pos.Y, victim_pos.Z, victim_id, shooter_pos.X, shooter_pos.Y, shooter_pos.Z, armor, health ));
  3195. }
  3196. if (health == health_before && Get_Defense_Object()->Get_Shield_Strength() == armor_before) {
  3197. //
  3198. // No damage was applied.
  3199. // This is a hack.
  3200. //
  3201. // Handle zero health bug
  3202. if ( health > 0 ||
  3203. HumanState.Get_State() == HumanStateClass::DEATH ||
  3204. HumanState.Get_State() == HumanStateClass::DESTROY ) {
  3205. return;
  3206. } else {
  3207. Debug_Say(( "Solving Zero health Bug %f %d\n", health, HumanState.Get_State() ));
  3208. }
  3209. }
  3210. // Can't start special damage unless damage was done.
  3211. // Check for special damage
  3212. int warhead = damager.Get_Warhead();
  3213. ArmorWarheadManager::SpecialDamageType special_damage = ArmorWarheadManager::Get_Special_Damage_Type( warhead );
  3214. if ( special_damage != 0 ) {
  3215. float probability = ArmorWarheadManager::Get_Special_Damage_Probability( warhead );
  3216. if (health <= 0) {
  3217. probability = 1;
  3218. }
  3219. if ( FreeRandom.Get_Float() < probability ) {
  3220. // if skin is not impervious to the damage
  3221. int skin = Get_Defense_Object()->Get_Skin();
  3222. ArmorWarheadManager::SpecialDamageType special_damage = ArmorWarheadManager::Get_Special_Damage_Type( warhead );
  3223. if ( !ArmorWarheadManager::Is_Skin_Impervious( special_damage, skin ) ) {
  3224. Set_Special_Damage_Mode( special_damage, damager.Get_Owner() );
  3225. }
  3226. }
  3227. }
  3228. if ( this == COMBAT_STAR ) {
  3229. if ( _shake_delay < 0 ) {
  3230. _shake_delay = 0.6f; // don't shake/sound too fast
  3231. // And Shake the camera
  3232. Vector3 pos = COMBAT_CAMERA->Get_Transform().Get_Translation();
  3233. COMBAT_SCENE->Add_Camera_Shake( pos, 1, 0.5f, 0.05f );
  3234. }
  3235. anim_ok = false;
  3236. if ( _cry_delay < 0 ) {
  3237. _cry_delay = 2; // don't shake/sound too fast
  3238. anim_ok = true;
  3239. // Play ouch sound
  3240. AudibleSoundClass * sound = WWAudioClass::Get_Instance()->Create_Sound( "Take_Damage_Sound" );
  3241. if ( sound ) {
  3242. sound->Play();
  3243. sound->Release_Ref();
  3244. }
  3245. }
  3246. }
  3247. if ( health <= 0 ) {
  3248. // Check for creating visceroids
  3249. if ( IS_MISSION ) {
  3250. int warhead = damager.Get_Warhead();
  3251. float visceroid_probability = ArmorWarheadManager::Get_Visceroid_Probability( warhead );
  3252. if ( !Is_Human_Controlled() && visceroid_probability != 0 ) {
  3253. if ( FreeRandom.Get_Float() < visceroid_probability ) {
  3254. #define VISCEROID_NAME "Visceroid"
  3255. // Not from other visceroids
  3256. if ( ::stricmp( Get_Definition().Get_Name(), VISCEROID_NAME ) != 0 ) {
  3257. // Create a visceroid
  3258. PhysicalGameObj * vis = ObjectLibraryManager::Create_Object( VISCEROID_NAME );
  3259. if ( vis != NULL ) {
  3260. vis->Set_Transform( Get_Transform() );
  3261. vis->Start_Observers ();
  3262. Set_Delete_Pending(); // Kill me
  3263. Debug_Say(( "Made Visceroid\n" ));
  3264. }
  3265. }
  3266. }
  3267. }
  3268. }
  3269. Enable_Hibernation( false );
  3270. // Stats
  3271. SoldierGameObj * damager_owner = NULL;
  3272. if ( damager.Get_Owner() && damager.Get_Owner()->As_SoldierGameObj() ) {
  3273. damager_owner = damager.Get_Owner()->As_SoldierGameObj();
  3274. }
  3275. if ( damager_owner && damager_owner->Get_Player_Data() ) {
  3276. if ( Is_Teammate( damager_owner ) ) {
  3277. damager_owner->Get_Player_Data()->Stats_Add_Ally_Killed();
  3278. }
  3279. if ( Is_Enemy( damager_owner ) ) {
  3280. damager_owner->Get_Player_Data()->Stats_Add_Enemy_Killed();
  3281. }
  3282. if ( damager_owner->Get_Vehicle() ) {
  3283. damager_owner->Get_Player_Data()->Stats_Add_Kill_From_Vehicle();
  3284. }
  3285. }
  3286. if ( HumanState.Get_State() != HumanStateClass::DEATH ) {
  3287. if ( this == COMBAT_STAR ) {
  3288. CombatManager::Register_Star_Killer( damager.Get_Owner() );
  3289. }
  3290. // Play death animation
  3291. HumanState.Set_State( HumanStateClass::DEATH, ouch_type );
  3292. //
  3293. // Stop any sound we WERE making
  3294. //
  3295. Stop_Current_Speech ();
  3296. int death_sound_id = Get_Definition ().DeathSoundPresetID;
  3297. if (death_sound_id == 0) {
  3298. //
  3299. // Lookup the global death sound
  3300. //
  3301. GlobalSettingsDef *global_settings = GlobalSettingsDef::Get_Global_Settings ();
  3302. if (global_settings != NULL) {
  3303. death_sound_id = global_settings->Get_Death_Sound_ID();
  3304. }
  3305. }
  3306. //
  3307. // Reveal this object to the player's encyclopedia
  3308. //
  3309. if ( damager.Get_Owner () == COMBAT_STAR ) {
  3310. EncyclopediaMgrClass::Reveal_Object( this );
  3311. }
  3312. //
  3313. // Play the death sound
  3314. //
  3315. if (death_sound_id != 0) {
  3316. Matrix3D tm = Get_Transform();
  3317. RefCountedGameObjReference *owner_ref = new RefCountedGameObjReference(this);
  3318. WWAudioClass::Get_Instance()->Create_Instant_Sound( death_sound_id, tm, owner_ref );
  3319. REF_PTR_RELEASE(owner_ref);
  3320. }
  3321. // Play death explosion, since we don't call Completely_Damaged
  3322. if ( Get_Definition().KilledExplosion != 0 ) {
  3323. Vector3 pos;
  3324. Get_Position(&pos);
  3325. WWASSERT(pos.Is_Valid());// most likely candidate for explosion damage bug....?
  3326. ExplosionManager::Create_Explosion_At( Get_Definition().KilledExplosion, pos, damager.Get_Owner() ); // no one gets credit for this
  3327. }
  3328. //
  3329. // Queue the guy who killed us...
  3330. //
  3331. if ( damage_owner != NULL &&
  3332. damage_owner != this &&
  3333. damage_owner->As_SoldierGameObj () != NULL )
  3334. {
  3335. SoldierGameObj *our_killer = damage_owner->As_SoldierGameObj ();
  3336. //
  3337. // Were we killed by a friend or foe?
  3338. //
  3339. if ( Is_Enemy( damage_owner ) ) {
  3340. our_killer->Say_Dialogue( DIALOG_ON_KILLED_ENEMY );
  3341. } else {
  3342. our_killer->Say_Dialogue( DIALOG_ON_KILLED_FRIEND );
  3343. }
  3344. }
  3345. }
  3346. } else {
  3347. // Play wound animation
  3348. // If state is interruptable.....
  3349. if ( Get_State() == HumanStateClass::UPRIGHT && anim_ok ) {
  3350. HumanState.Set_State( HumanStateClass::WOUNDED, ouch_type );
  3351. }
  3352. }
  3353. if( CurrentSpeech == NULL && dialogue_id >= 0 ) {
  3354. Say_Dialogue( dialogue_id );
  3355. }
  3356. }
  3357. //------------------------------------------------------------------------------------
  3358. void SoldierGameObj::Exit_Ladder( void )
  3359. {
  3360. HumanState.Set_State( HumanStateClass::UPRIGHT );
  3361. }
  3362. //------------------------------------------------------------------------------------
  3363. void SoldierGameObj::Enter_Ladder( bool top )
  3364. {
  3365. HumanState.Set_State( HumanStateClass::LADDER );
  3366. if ( Is_Human_Controlled() ) {
  3367. if ( top ) {
  3368. LadderUpMask = true;
  3369. } else {
  3370. LadderDownMask = true;
  3371. }
  3372. }
  3373. }
  3374. //------------------------------------------------------------------------------------
  3375. HumanPhysClass *SoldierGameObj::Peek_Human_Phys( void ) const
  3376. {
  3377. WWASSERT( Peek_Physical_Object() );
  3378. WWASSERT( Peek_Physical_Object()->As_HumanPhysClass() );
  3379. return Peek_Physical_Object()->As_HumanPhysClass();
  3380. }
  3381. //------------------------------------------------------------------------------------
  3382. /*
  3383. ** Vehicles
  3384. */
  3385. void SoldierGameObj::Enter_Vehicle( VehicleGameObj * vehicle, const char * anim_name )
  3386. {
  3387. // WWASSERT( Get_State() != HumanStateClass::IN_VEHICLE );
  3388. Vehicle = vehicle;
  3389. HumanState.Set_State( HumanStateClass::IN_VEHICLE );
  3390. AnimationName = anim_name;
  3391. HumanState.Force_Animation( anim_name, false );
  3392. if ( this == COMBAT_STAR && vehicle != NULL ) {
  3393. Vector3 pos;
  3394. Vehicle->Get_Position( &pos );
  3395. int ammo = 0;
  3396. if ( vehicle->Get_Weapon() ) {
  3397. ammo = vehicle->Get_Weapon()->Get_Total_Rounds();
  3398. }
  3399. DefenseObjectClass * defense = vehicle->Get_Defense_Object();
  3400. DIAG_LOG(( "ENVE", "%1.2f; %1.2f; %1.2f; %1.2f; %1.2f; %d", pos.X, pos.Y, pos.Z, defense->Get_Shield_Strength(), defense->Get_Health(), ammo ));
  3401. }
  3402. }
  3403. //------------------------------------------------------------------------------------
  3404. void SoldierGameObj::Exit_Vehicle( void )
  3405. {
  3406. if ( this == COMBAT_STAR && Vehicle != NULL ) {
  3407. Vector3 pos;
  3408. Vehicle->Get_Position( &pos );
  3409. int ammo = 0;
  3410. if ( Vehicle->Get_Weapon() ) {
  3411. ammo = Vehicle->Get_Weapon()->Get_Total_Rounds();
  3412. }
  3413. DefenseObjectClass * defense = Vehicle->Get_Defense_Object();
  3414. DIAG_LOG(( "EXVE", "%1.2f; %1.2f; %1.2f; %1.2f; %1.2f; %d", pos.X, pos.Y, pos.Z, defense->Get_Shield_Strength(), defense->Get_Health(), ammo ));
  3415. }
  3416. Vehicle = NULL;
  3417. HumanState.Set_State( HumanStateClass::UPRIGHT );
  3418. }
  3419. void SoldierGameObj::Exit_Destroyed_Vehicle( int seat_num, const Vector3 & vehicle_pos )
  3420. {
  3421. Vehicle = NULL;
  3422. HumanState.Set_State( HumanStateClass::UPRIGHT );
  3423. Vector3 extent = Peek_Human_Phys()->Get_Collision_Box().Extent;
  3424. float width = MAX( extent.X, extent.Y ) * 1.1f;
  3425. if ( Peek_Model() ) {
  3426. Peek_Model()->Set_Hidden( false );
  3427. }
  3428. Vector3 offsets[4] = {
  3429. Vector3( -1.0f, -1.0f, 0 ),
  3430. Vector3( -1.0f, 1.0f, 0 ),
  3431. Vector3( 1.0f, -1.0f, 0 ),
  3432. Vector3( 1.0f, 1.0f, 0 ),
  3433. };
  3434. Vector3 pos = vehicle_pos + offsets[ seat_num & 3 ] * width;
  3435. Matrix3D tm( pos );
  3436. if ( Peek_Human_Phys()->Can_Teleport( tm ) ) {
  3437. Peek_Human_Phys()->Set_Position( pos );
  3438. } else {
  3439. Vector3 new_pos = pos;
  3440. Peek_Human_Phys()->Find_Teleport_Location( pos, 4, &new_pos );
  3441. Peek_Human_Phys()->Set_Position( new_pos );
  3442. }
  3443. }
  3444. //------------------------------------------------------------------------------------
  3445. bool SoldierGameObj::Is_Permitted_To_Enter_Vehicle(void)
  3446. {
  3447. if (!CombatManager::Is_Gameplay_Permitted()) {
  3448. //
  3449. // You can't enter a vehicle if there are no opponents, etc
  3450. //
  3451. return false;
  3452. }
  3453. /*
  3454. //
  3455. // A soldier cannot enter a vehicle if he is carrying a flag
  3456. //
  3457. if (CtfTeamFlag == NO_FLAG) {
  3458. return true;
  3459. } else {
  3460. return false;
  3461. }
  3462. */
  3463. return true;
  3464. }
  3465. //------------------------------------------------------------------------------------
  3466. void SoldierGameObj::Get_Velocity(Vector3 & vel)
  3467. {
  3468. Peek_Human_Phys()->Get_Velocity(&vel);
  3469. }
  3470. //------------------------------------------------------------------------------------
  3471. void SoldierGameObj::Set_Velocity(Vector3 & vel)
  3472. {
  3473. Peek_Human_Phys()->Set_Velocity(vel);
  3474. }
  3475. //------------------------------------------------------------------------------------
  3476. void SoldierGameObj::Give_All_Weapons(void)
  3477. {
  3478. //WWASSERT(CombatManager::I_Am_Server());
  3479. // WWASSERT(PlayerType != PLAYERTYPE_NEUTRAL);
  3480. // For all weapon defs with the AGiveWeaponsWeapon checked, Give It!
  3481. for ( WeaponDefinitionClass *weapon_def = (WeaponDefinitionClass *)DefinitionMgrClass::Get_First( CLASSID_DEF_WEAPON );
  3482. weapon_def != NULL;
  3483. weapon_def = (WeaponDefinitionClass *)DefinitionMgrClass::Get_Next( weapon_def, CLASSID_DEF_WEAPON ) ) {
  3484. if ( weapon_def->AGiveWeaponsWeapon ) {
  3485. WeaponBag->Add_Weapon( weapon_def->Get_Name(), -1 );
  3486. }
  3487. }
  3488. }
  3489. //------------------------------------------------------------------------------------
  3490. VehicleGameObj * SoldierGameObj::Get_Profile_Vehicle( void )
  3491. {
  3492. if (( Get_State() == HumanStateClass::IN_VEHICLE ) && Vehicle ) {
  3493. return Vehicle;
  3494. }
  3495. if (( Get_State() == HumanStateClass::TRANSITION ) &&
  3496. ( TransitionCompletionData != NULL )) {
  3497. if ( TransitionCompletionData->Type == TransitionDataClass::VEHICLE_ENTER ) {
  3498. return (VehicleGameObj *)TransitionCompletionData->Vehicle.Get_Ptr();
  3499. }
  3500. }
  3501. return NULL;
  3502. }
  3503. bool SoldierGameObj::Use_Ladder_View( void )
  3504. {
  3505. if ( Get_State() == HumanStateClass::LADDER ) {
  3506. return true;
  3507. }
  3508. if (( Get_State() == HumanStateClass::TRANSITION ) &&
  3509. ( TransitionCompletionData != NULL )) {
  3510. if (( TransitionCompletionData->Type == TransitionDataClass::LADDER_ENTER_TOP ) ||
  3511. ( TransitionCompletionData->Type == TransitionDataClass::LADDER_ENTER_BOTTOM )) {
  3512. return true;
  3513. }
  3514. }
  3515. return false;
  3516. }
  3517. //------------------------------------------------------------------------------------
  3518. void SoldierGameObj::Set_Model(const char *model_name)
  3519. {
  3520. Peek_Physical_Object()->Set_Model_By_Name(model_name);
  3521. HumanState.Set_Anim_Control( (HumanAnimControlClass *)Get_Anim_Control() ); // Must set the anim control after the phys object
  3522. }
  3523. //------------------------------------------------------------------------------------
  3524. Vector3 SoldierGameObj::Get_Bullseye_Position( void )
  3525. {
  3526. if ( Get_Vehicle() != NULL ) {
  3527. return Get_Vehicle()->Get_Bullseye_Position();
  3528. }
  3529. Vector3 pos;
  3530. Get_Position(&pos);
  3531. if ( Is_Crouched() ) {
  3532. pos.Z += 0.5f;
  3533. } else {
  3534. pos.Z += Get_Bullseye_Offset_Z();
  3535. }
  3536. // pos.Z += 1.2f;
  3537. return pos;
  3538. }
  3539. //------------------------------------------------------------------------------------
  3540. bool SoldierGameObj::Can_See(SoldierGameObj * p_soldier)
  3541. {
  3542. WWASSERT(p_soldier != NULL);
  3543. Vector3 ray_start = Get_Bullseye_Position();
  3544. Vector3 ray_end = p_soldier->Get_Bullseye_Position(); // This may a big high
  3545. Vector3 path = ray_end - ray_start;
  3546. if (path.Length() > 1) {
  3547. Vector3 offset = path;
  3548. offset.Normalize();
  3549. ray_start += offset;
  3550. }
  3551. LineSegClass ray(ray_start, ray_end);
  3552. CastResultStruct result;
  3553. PhysRayCollisionTestClass raytest(ray, &result,
  3554. BULLET_COLLISION_GROUP, COLLISION_TYPE_PHYSICAL);
  3555. WWASSERT(COMBAT_SCENE != NULL);
  3556. { WWPROFILE( "Cast Ray" );
  3557. COMBAT_SCENE->Cast_Ray(raytest);
  3558. }
  3559. bool can_see = false;
  3560. if (raytest.CollidedPhysObj != NULL) {
  3561. SmartGameObj * p_blocker = NULL;
  3562. if ( raytest.CollidedPhysObj->Get_Observer() != NULL ) {
  3563. PhysicalGameObj * p_obj = ((CombatPhysObserverClass *)raytest.CollidedPhysObj->Get_Observer())->As_PhysicalGameObj();
  3564. if ( p_obj != NULL ) {
  3565. p_blocker = p_obj->As_SmartGameObj();
  3566. }
  3567. }
  3568. if (p_blocker != NULL && p_blocker->Get_Control_Owner() ==
  3569. p_soldier->Get_Control_Owner()) {
  3570. can_see = true;
  3571. }
  3572. }
  3573. return can_see;
  3574. }
  3575. //------------------------------------------------------------------------------------
  3576. void SoldierGameObj::Adjust_Skeleton( float height, float width )
  3577. {
  3578. // Debug_Say(( "Height %f, width %f\n", height, width ));
  3579. // Only adjust male skeletons
  3580. Animatable3DObjClass * robj = (Animatable3DObjClass *)Peek_Model();
  3581. if ( !robj || !robj->Get_HTree() || robj->Get_HTree()->Get_Name()[2] != 'A' ) {
  3582. return;
  3583. }
  3584. HTreeClass * tree_base = NULL;
  3585. HTreeClass * tree_tall = NULL;
  3586. HTreeClass * tree_wide = NULL;
  3587. if ( tree_base == NULL ) {
  3588. tree_base = WW3DAssetManager::Get_Instance()->Get_HTree( "s_a_human" );
  3589. tree_tall = WW3DAssetManager::Get_Instance()->Get_HTree( "s_a_tall" );
  3590. tree_wide = WW3DAssetManager::Get_Instance()->Get_HTree( "s_a_wide" );
  3591. }
  3592. if ( ( tree_base != NULL ) && ( tree_tall != NULL ) && ( tree_wide != NULL ) ) {
  3593. HTreeClass *tree = HTreeClass::Create_Interpolated( tree_base, tree_tall, tree_wide,
  3594. height, width );
  3595. if ( tree ) {
  3596. robj->Set_HTree( tree );
  3597. delete tree;
  3598. }
  3599. }
  3600. }
  3601. /*
  3602. //------------------------------------------------------------------------------------
  3603. void SoldierGameObj::Set_Ctf_Team_Flag(int team)
  3604. {
  3605. WWASSERT(
  3606. team == NO_FLAG ||
  3607. team == PLAYERTYPE_NOD ||
  3608. team == PLAYERTYPE_GDI);
  3609. CtfTeamFlag = team;
  3610. Set_Object_Dirty_Bit( NetworkObjectClass::BIT_OCCASIONAL, true );
  3611. if (team == NO_FLAG) {
  3612. Set_Back_Flag_Model(NULL);
  3613. } else {
  3614. //Set_Back_Flag_Model("O_Flag.w3d", Get_Team_Color());
  3615. Set_Back_Flag_Model("O_Flag.w3d", Get_Color_For_Team(team));
  3616. }
  3617. }
  3618. */
  3619. /*
  3620. //------------------------------------------------------------------------------------
  3621. void SoldierGameObj::Set_Precision(void)
  3622. {
  3623. cEncoderList::Set_Precision(BITPACK_CTF_TEAM_FLAG, NO_FLAG, (int) PLAYERTYPE_GDI);
  3624. }
  3625. */
  3626. //------------------------------------------------------------------------------------
  3627. SoldierObserverClass * SoldierGameObj::Get_Innate_Controller( void )
  3628. {
  3629. if ( Get_Definition().UseInnateBehavior ) {
  3630. const GameObjObserverList & observer_list = Get_Observers();
  3631. for( int index = 0; index < observer_list.Count(); index++ ) {
  3632. if ( !strcmp( observer_list[ index ]->Get_Name(), "Innate Soldier" ) ) {
  3633. return (SoldierObserverClass *)observer_list[ index ];
  3634. }
  3635. }
  3636. }
  3637. return NULL;
  3638. }
  3639. //------------------------------------------------------------------------------------
  3640. const char * SoldierGameObj::Get_First_Person_Hands_Model_Name( void )
  3641. {
  3642. return Get_Definition().FirstPersonHands;
  3643. }
  3644. //------------------------------------------------------------------------------------
  3645. void SoldierGameObj::Get_Information( StringClass & string )
  3646. {
  3647. SmartGameObj::Get_Information( string );
  3648. HumanState.Get_Information( string );
  3649. SoldierObserverClass * innate = Get_Innate_Controller();
  3650. if ( innate ) {
  3651. innate->Get_Information( string );
  3652. StringClass disabled;
  3653. if (!Is_Innate_Enabled(SOLDIER_INNATE_EVENT_BULLET_HEARD)) {
  3654. disabled += "B";
  3655. }
  3656. if (!Is_Innate_Enabled(SOLDIER_INNATE_EVENT_GUNSHOT_HEARD)) {
  3657. disabled += "G";
  3658. }
  3659. if (!Is_Innate_Enabled(SOLDIER_INNATE_EVENT_FOOTSTEP_HEARD)) {
  3660. disabled += "F";
  3661. }
  3662. if (!Is_Innate_Enabled(SOLDIER_INNATE_EVENT_ENEMY_SEEN)) {
  3663. disabled += "S";
  3664. }
  3665. if (!Is_Innate_Enabled(SOLDIER_INNATE_ACTIONS)) {
  3666. disabled += "A";
  3667. }
  3668. if ( !disabled.Is_Empty() ) {
  3669. string += "Disabled:";
  3670. string += disabled;
  3671. string += "\n";
  3672. }
  3673. }
  3674. }
  3675. //------------------------------------------------------------------------------------
  3676. //void SoldierGameObj::Get_Extended_Information(StringClass & description)
  3677. void SoldierGameObj::Get_Description(StringClass & description)
  3678. {
  3679. StringClass line;
  3680. line.Format("ID: %d\n", Get_ID());
  3681. description += line;
  3682. line.Format("NAME: %s\n", Get_Definition().Get_Name());
  3683. description += line;
  3684. line.Format("TEAM: %d\n", Get_Player_Type());
  3685. description += line;
  3686. line.Format("CONTR: %d\n", Get_Control_Owner());
  3687. description += line;
  3688. Vector3 position;
  3689. Get_Position(&position);
  3690. line.Format("POS: %-5.2f, %-5.2f, %-5.2f\n", position.X, position.Y, position.Z);
  3691. description += line;
  3692. Vector3 target = Get_Targeting_Pos();
  3693. line.Format("TGT: %-5.2f, %-5.2f, %-5.2f\n", target.X, target.Y, target.Z);
  3694. description += line;
  3695. Vector3 velocity;
  3696. Get_Velocity(velocity);
  3697. line.Format("VEL: %-5.2f, %-5.2f, %-5.2f\n", velocity.X, velocity.Y, velocity.Z);
  3698. description += line;
  3699. WeaponClass * p_weapon = Get_Weapon();
  3700. if (p_weapon != NULL) {
  3701. line.Format("WEAP: %s\n", p_weapon->Get_Name());
  3702. description += line;
  3703. line.Format("TRNDS: %d\n", p_weapon->Get_Total_Rounds());
  3704. description += line;
  3705. }
  3706. line.Format("HLTH: %-5.2f\n", DefenseObject.Get_Health());
  3707. description += line;
  3708. line.Format("HMAX: %-5.2f\n", DefenseObject.Get_Health_Max());
  3709. description += line;
  3710. HumanPhysClass * p_human_phys = Peek_Human_Phys();
  3711. if (p_human_phys != NULL) {
  3712. line.Format("FACE: %-5.2f\n", p_human_phys->Get_Facing());
  3713. description += line;
  3714. }
  3715. line.Format("STATE: %s", Get_State_Name());
  3716. if (Is_Crouched()) {
  3717. line += " (Crouched)";
  3718. }
  3719. line += "\n";
  3720. description += line;
  3721. line.Format("ANIM: %s\n", AnimationName);
  3722. description += line;
  3723. if (Vehicle != NULL) {
  3724. line.Format("VEH: %d\n", Vehicle->Get_ID());
  3725. description += line;
  3726. }
  3727. const GameObjObserverList & observer_list = Get_Observers();
  3728. line.Format("#OBSV: %d\n", observer_list.Count());
  3729. description += line;
  3730. for (int index = 0; index < observer_list.Count(); index++) {
  3731. line.Format(" %s\n", observer_list[index]->Get_Name());
  3732. description += line;
  3733. }
  3734. line.Format("INNAT: %d\n", Is_Innate_Enabled());
  3735. description += line;
  3736. line.Format("HIB: %d\n", Is_Hibernating());
  3737. description += line;
  3738. line.Format("CTRL: %d, %d, %5.2f, %5.2f, %5.2f, %5.2f\n",
  3739. Control.Get_One_Time_Boolean_Bits(),
  3740. Control.Get_Continuous_Boolean_Bits(),
  3741. Control.Get_Analog(ControlClass::ANALOG_MOVE_FORWARD),
  3742. Control.Get_Analog(ControlClass::ANALOG_MOVE_LEFT),
  3743. Control.Get_Analog(ControlClass::ANALOG_MOVE_UP),
  3744. Control.Get_Analog(ControlClass::ANALOG_TURN_LEFT));
  3745. description += line;
  3746. ActionClass * p_action = Get_Action();
  3747. if (p_action != NULL)
  3748. {
  3749. line.Format("ACTCT: %d\n", p_action->Get_Act_Count());
  3750. description += line;
  3751. Vector3 move_loc = p_action->Get_Parameters().MoveLocation;
  3752. line.Format("MVLOC: (%5.2f, %5.2f, %5.2f)\n", move_loc.X, move_loc.Y, move_loc.Z);
  3753. description += line;
  3754. }
  3755. line.Format("stlth: %d\n", Is_Stealth_Enabled());
  3756. description += line;
  3757. line.Format(" on: %d\n", Is_Stealthed());
  3758. description += line;
  3759. line.Format("ISC: %d\n", Get_Import_State_Count());
  3760. description += line;
  3761. }
  3762. //------------------------------------------------------------------------------------
  3763. struct {
  3764. ArmorWarheadManager::SpecialDamageType Mode;
  3765. const char * EmitterName;
  3766. const char * BoneName;
  3767. } _SpecialDamageEmitters[] = {
  3768. { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_FIRE, "AG_FLAME01", "C SPINE" },
  3769. { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_SUPER_FIRE, "AG_FLAME01", "C SPINE" },
  3770. { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_SUPER_FIRE, "AG_FLAME01", "C L UPPERARM" },
  3771. { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_SUPER_FIRE, "AG_FLAME01", "C R UPPERARM" },
  3772. { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_SUPER_FIRE, "AG_FLAME01", "C L CALF" },
  3773. { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_SUPER_FIRE, "AG_FLAME01", "C R CALF" },
  3774. { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_SUPER_FIRE, "AG_FLAME01", "C NECK" },
  3775. // { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_FIRE, "E_FLAME01", "C L UPPERARM" },
  3776. // { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_FIRE, "E_FLAME01", "C R UPPERARM" },
  3777. { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_CHEM, "e_tib_dump", "C SPINE" },
  3778. // { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_CHEM, "e_tib_dump", "C L UPPERARM" },
  3779. // { ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_CHEM, "e_tib_dump", "C R UPPERARM" },
  3780. };
  3781. #define NUM_SPECIAL_DAMAGE_EMITTERS (sizeof(_SpecialDamageEmitters)/sizeof(_SpecialDamageEmitters[0]))
  3782. void SoldierGameObj::Set_Special_Damage_Mode( ArmorWarheadManager::SpecialDamageType mode, ArmedGameObj * damager )
  3783. {
  3784. // Check for turning off
  3785. if ( mode == ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_NONE ) {
  3786. // remove all subobjs from the bones used
  3787. for ( int emitter = 0; emitter < NUM_SPECIAL_DAMAGE_EMITTERS; emitter++ ) {
  3788. if ( _SpecialDamageEmitters[emitter].Mode == SpecialDamageMode ) {
  3789. int bone = Peek_Model()->Get_Bone_Index( _SpecialDamageEmitters[emitter].BoneName );
  3790. int sub_count = Peek_Model()->Get_Num_Sub_Objects_On_Bone( bone );
  3791. while ( --sub_count >= 0 ) {
  3792. RenderObjClass * sub = Peek_Model()->Get_Sub_Object_On_Bone( sub_count, bone );
  3793. if ( ::stricmp(sub->Get_Name(), _SpecialDamageEmitters[emitter].EmitterName ) == 0 ) {
  3794. Peek_Model()->Remove_Sub_Object( sub );
  3795. }
  3796. sub->Release_Ref();
  3797. }
  3798. }
  3799. }
  3800. if ( SpecialDamageEffect != NULL ) {
  3801. SpecialDamageEffect->Set_Target_Parameter(0);
  3802. SpecialDamageEffect->Enable_Remove_On_Complete(true);
  3803. REF_PTR_RELEASE( SpecialDamageEffect );
  3804. }
  3805. if ( !Is_Human_Controlled() && IS_MISSION ) {
  3806. if ( HumanState.Get_State() >= HumanStateClass::ON_FIRE &&
  3807. HumanState.Get_State() <= HumanStateClass::ON_CNC_CHEM ) {
  3808. HumanState.Set_State( HumanStateClass::UPRIGHT );
  3809. }
  3810. }
  3811. SpecialDamageDamager = NULL;
  3812. } else {
  3813. if ( mode != SpecialDamageMode ) {
  3814. // Remove old mode
  3815. Set_Special_Damage_Mode( ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_NONE );
  3816. if ( Allow_Special_Damage_State_Lock() && IS_MISSION && mode != ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_SUPER_FIRE ) {
  3817. HumanState.Set_State( (HumanStateClass::HumanStateType)( mode -
  3818. ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_FIRE + HumanStateClass::ON_FIRE ) );
  3819. }
  3820. // Add new emitters
  3821. for ( int emitter = 0; emitter < NUM_SPECIAL_DAMAGE_EMITTERS; emitter++ ) {
  3822. if ( _SpecialDamageEmitters[emitter].Mode == mode ) {
  3823. RenderObjClass * ro = WW3DAssetManager::Get_Instance()->Create_Render_Obj(
  3824. _SpecialDamageEmitters[emitter].EmitterName );
  3825. if ( ro != NULL ) {
  3826. Peek_Model()->Add_Sub_Object_To_Bone( ro, _SpecialDamageEmitters[emitter].BoneName );
  3827. ro->Release_Ref();
  3828. }
  3829. }
  3830. }
  3831. // Add electric effect
  3832. if ( mode == ArmorWarheadManager::SPECIAL_DAMAGE_TYPE_ELECTRIC ) {
  3833. WWASSERT( SpecialDamageEffect == NULL );
  3834. SpecialDamageEffect = CombatMaterialEffectManager::Get_Electrocution_Effect();
  3835. if ( SpecialDamageEffect != NULL ) {
  3836. SpecialDamageEffect->Set_Target_Parameter(0.49f); // go almost halfway
  3837. Peek_Human_Phys()->Add_Effect_To_Me( SpecialDamageEffect );
  3838. }
  3839. }
  3840. // Save Damager
  3841. SpecialDamageDamager = damager;
  3842. }
  3843. }
  3844. SpecialDamageMode = mode;
  3845. SpecialDamageTimer = ArmorWarheadManager::Get_Special_Damage_Duration( SpecialDamageMode );
  3846. }
  3847. //-----------------------------------------------------------------------------
  3848. void SoldierGameObj::Perturb_Position(float max_perturb)
  3849. {
  3850. //
  3851. // Jiggle the soldier to a non-intersecting position
  3852. //
  3853. Vector3 initial_position;
  3854. Get_Position(&initial_position);
  3855. Vector3 new_position;
  3856. WWASSERT(Peek_Human_Phys() != NULL);
  3857. bool succeeded = Peek_Human_Phys()->Find_Teleport_Location(
  3858. initial_position, max_perturb, &new_position);
  3859. if (succeeded) {
  3860. Set_Position(new_position);
  3861. }
  3862. }
  3863. /*
  3864. **
  3865. */
  3866. void SoldierGameObj::Toggle_Fly_Mode( void )
  3867. {
  3868. InFlyMode = !InFlyMode;
  3869. if ( InFlyMode ) {
  3870. HumanState.Set_State( HumanStateClass::DEBUG_FLY );
  3871. Peek_Physical_Object()->Set_Collision_Group( UNCOLLIDEABLE_GROUP );
  3872. } else {
  3873. HumanState.Set_State( HumanStateClass::UPRIGHT );
  3874. Peek_Physical_Object()->Set_Collision_Group( SOLDIER_COLLISION_GROUP );
  3875. }
  3876. }
  3877. /*
  3878. **
  3879. */
  3880. void SoldierGameObj::Set_AI_State( SoldierAIState state )
  3881. {
  3882. //
  3883. // Is the soldier changing states?
  3884. //
  3885. if ( AIState != state ) {
  3886. //
  3887. // Kill the conversation (if necessary)
  3888. //
  3889. if ( state >= AI_STATE_SEARCH && state > AIState &&
  3890. ActiveConversation != NULL &&
  3891. ActiveConversation->Is_Interruptable ())
  3892. {
  3893. ActiveConversation->Stop_Conversation (ACTION_COMPLETE_CONVERSATION_INTERRUPTED);
  3894. }
  3895. AIState = state;
  3896. }
  3897. return ;
  3898. }
  3899. /*
  3900. ** Soldiers maintain all RenderObjs they have created for later use and saving
  3901. ** This is used for weapon models
  3902. */
  3903. void SoldierGameObj::Add_RenderObj( RenderObjClass * obj )
  3904. {
  3905. RenderObjList.Add( obj );
  3906. obj->Add_Ref();
  3907. }
  3908. RenderObjClass * SoldierGameObj::Find_RenderObj( const char * name )
  3909. {
  3910. for ( int i = 0; i < RenderObjList.Count(); i++ ) {
  3911. if ( !stricmp( RenderObjList[i]->Get_Name(), name ) ) {
  3912. return RenderObjList[i];
  3913. }
  3914. }
  3915. return NULL;
  3916. }
  3917. void SoldierGameObj::Reset_RenderObjs( void )
  3918. {
  3919. while ( RenderObjList.Count() ) {
  3920. RenderObjList[0]->Release_Ref();
  3921. RenderObjList.Delete( 0 );
  3922. }
  3923. }
  3924. /*
  3925. //-----------------------------------------------------------------------------
  3926. void SoldierGameObj::Change_Flag_Status(int ctf_team_flag)
  3927. {
  3928. WWASSERT(CombatManager::I_Am_Only_Client());
  3929. if (ctf_team_flag == NO_FLAG) {
  3930. //
  3931. // We dropped a flag
  3932. //
  3933. WWASSERT(WWAudioClass::Get_Instance() != NULL);
  3934. WWAudioClass::Get_Instance()->Create_Instant_Sound("Drop_Flag", Get_Transform());
  3935. float speed_factor = 100 / (float) CombatManager::Get_Max_Speed_Pc(this);
  3936. Set_Max_Speed(speed_factor * Get_Max_Speed());
  3937. Set_Ctf_Team_Flag(ctf_team_flag);
  3938. } else {
  3939. //
  3940. // We picked up a flag
  3941. //
  3942. WWASSERT(WWAudioClass::Get_Instance() != NULL);
  3943. WWAudioClass::Get_Instance()->Create_Instant_Sound("Pick_Up_Flag", Get_Transform());
  3944. Set_Ctf_Team_Flag(ctf_team_flag);
  3945. float speed_factor = CombatManager::Get_Max_Speed_Pc(this) / 100.0f;
  3946. Set_Max_Speed(speed_factor * Get_Max_Speed());
  3947. }
  3948. }
  3949. */
  3950. /*
  3951. void SoldierGameObj::Interpret_Sc_Position_Data(Vector3 & sc_position)
  3952. {
  3953. WWASSERT(CombatManager::I_Am_Only_Client());
  3954. switch (CombatManager::Get_Client_Interpolation_Model()) {
  3955. case CLIENT_INTERPOLATION_SERVER_AUTHORITATIVE:
  3956. //
  3957. // Simplest case - pop to location given by server
  3958. //
  3959. //Set_Position(sc_position);
  3960. if (Get_State() == HumanStateClass::TRANSITION) {
  3961. //
  3962. // Pop
  3963. //
  3964. Set_Position(sc_position);
  3965. if (Get_Control_Owner() == CombatManager::Get_My_Id()) {
  3966. Debug_Say(("Popping own soldier at time %s\n", cMiscUtil::Get_Text_Time()));
  3967. }
  3968. } else {
  3969. Vector3 current_position;
  3970. Get_Position(&current_position);
  3971. Vector3 pos_error = current_position - sc_position;
  3972. if (pos_error.Length() > 2.0f) {
  3973. Set_Position(sc_position);
  3974. if (Get_Control_Owner() == CombatManager::Get_My_Id()) {
  3975. Debug_Say(("Popping own soldier at time %s\n", cMiscUtil::Get_Text_Time()));
  3976. }
  3977. }
  3978. }
  3979. break;
  3980. case CLIENT_INTERPOLATION_SERVER_AUTHORITATIVE_WITH_BLENDING:
  3981. if (Get_State() == HumanStateClass::TRANSITION) {
  3982. //
  3983. // Pop
  3984. //
  3985. Set_Position(sc_position);
  3986. } else {
  3987. //
  3988. // Blend to position given by server
  3989. //
  3990. Vector3 current_position;
  3991. Get_Position(&current_position);
  3992. Set_Position(0.50 * current_position + 0.50 * sc_position);
  3993. }
  3994. break;
  3995. case CLIENT_INTERPOLATION_PATHFIND: {
  3996. Vector3 current_position;
  3997. Get_Position(&current_position);
  3998. Vector3 pos_error = current_position - sc_position;
  3999. if (pos_error.Length() > 0.02f) {
  4000. if (Get_Control_Owner() == CombatManager::Get_My_Id()) {
  4001. if (pos_error.Length() > 2) {
  4002. //
  4003. // Client is authoritative over his own guy, unless error
  4004. // becomes significant. In this case, pop.
  4005. //
  4006. Set_Position(sc_position);
  4007. }
  4008. } else {
  4009. //if (pos_error.Length() > 20) {
  4010. // //
  4011. // // Pop
  4012. // //
  4013. // Set_Position(sc_position);
  4014. //} else {
  4015. //
  4016. // For NPC's the server could transmit the final destination as well as
  4017. // the proper location. Pop if appropriate to get as close to
  4018. // proper dest as possible, but pathfind instead to the final dest.
  4019. //
  4020. ActionParamsStruct parameters;
  4021. parameters.Priority = 1;
  4022. parameters.MoveLocation = sc_position;
  4023. parameters.MoveArrivedDistance = 0.1f;
  4024. WWASSERT(Get_Action() != NULL);
  4025. Get_Action()->Goto(parameters);
  4026. //}
  4027. }
  4028. }
  4029. break;
  4030. }
  4031. default:
  4032. WWASSERT(0);
  4033. }
  4034. }
  4035. */
  4036. /*
  4037. void SoldierGameObj::Think_Pathfind( void )
  4038. {
  4039. // CLIENT_PATHFINDING
  4040. //
  4041. // Pop pathfinding client-side soldiers at the earliest opportunity -
  4042. // as soon as we find them out of the camera fulcrum.
  4043. //
  4044. if (CombatManager::I_Am_Only_Client() &&
  4045. Get_Control_Owner() != CombatManager::Get_My_Id()) {
  4046. Vector3 current_position;
  4047. Get_Position(&current_position);
  4048. ActionClass * p_action = Get_Action();
  4049. WWASSERT(p_action != NULL);
  4050. const Vector3 height_offset(0, 0, 0.9f);
  4051. Vector3 from_position = current_position + height_offset;
  4052. Vector3 to_position = p_action->MovementLocation + height_offset;
  4053. //
  4054. // We can only pop if he is not presently in the camera fulcrum.
  4055. //
  4056. if (p_action->MovementAction != NULL &&
  4057. !CombatManager::Is_In_Camera_Frustrum(from_position)) {
  4058. if (!CombatManager::Is_In_Camera_Frustrum(to_position)) {
  4059. //
  4060. // If the correct position is also out of the fulcrum, pop
  4061. // all the way there.
  4062. //
  4063. Set_Position(p_action->MovementLocation);
  4064. p_action->Set_Movement(NULL);
  4065. } else {
  4066. //
  4067. // We are crossing into the fulcrum. Pop as close to the edge
  4068. // of the fulcrum as possible and pathfind from there.
  4069. //
  4070. //Debug_Say(("FRAME\n"));
  4071. bool is_finished = false;
  4072. do {
  4073. Vector3 next_pos;
  4074. p_action->Movement_Act(next_pos);
  4075. //if (CombatManager::Is_In_Camera_Frustrum(next_pos + height_offset)) {
  4076. // is_finished = true;
  4077. //
  4078. // //
  4079. // // Logically it would be better if the next line could be omitted.
  4080. // // However this seems to screw things up.
  4081. // //
  4082. // Set_Position(next_pos);
  4083. //
  4084. // //Debug_Say(("Finished skipping."));
  4085. //} else {
  4086. // Set_Position(next_pos);
  4087. //
  4088. // //Debug_Say(("Skipping to (%5.2f, %5.2f, %5.2f)\n",
  4089. // // next_pos.X, next_pos.Y, next_pos.Z));
  4090. //}
  4091. Set_Position(next_pos);
  4092. Vector3 adjusted_next_pos = next_pos + height_offset;
  4093. if (CombatManager::Is_In_Camera_Frustrum(adjusted_next_pos)) {
  4094. is_finished = true;
  4095. }
  4096. } while ((p_action->MovementAction != NULL) && !is_finished);
  4097. }
  4098. }
  4099. }
  4100. }
  4101. void SoldierGameObj::Think_Pathfind(void)
  4102. {
  4103. //
  4104. // Pop pathfinding client-side soldiers at the earliest opportunity -
  4105. // as soon as we find them out of the camera fulcrum.
  4106. //
  4107. if ((CombatManager::Get_Client_Interpolation_Model() == CLIENT_INTERPOLATION_PATHFIND) &&
  4108. CombatManager::I_Am_Only_Client() &&
  4109. Get_Control_Owner() != CombatManager::Get_My_Id()) {
  4110. Vector3 current_position;
  4111. Get_Position(&current_position);
  4112. ActionClass * p_action = Get_Action();
  4113. WWASSERT(p_action != NULL);
  4114. ActionParamsStruct parameters = p_action->Get_Parameters();
  4115. const Vector3 height_offset(0, 0, 0.9f);
  4116. Vector3 from_position = current_position + height_offset;
  4117. Vector3 to_position = parameters.MoveLocation + height_offset;
  4118. //
  4119. // We can only pop if he is not presently in the camera fulcrum.
  4120. //
  4121. if (!CombatManager::Is_In_Camera_Frustrum(from_position)) {
  4122. if (!CombatManager::Is_In_Camera_Frustrum(to_position)) {
  4123. //
  4124. // If the correct position is also out of the fulcrum, pop
  4125. // all the way there.
  4126. //
  4127. Set_Position(to_position);
  4128. } else {
  4129. //
  4130. // Keep popping until we are almost in the fulcrum.
  4131. //
  4132. Vector3 current_pos;
  4133. Get_Position(&current_pos);
  4134. Vector3 last_pos;
  4135. Vector3 test_pos;
  4136. do {
  4137. last_pos = current_pos;
  4138. p_action->Act();
  4139. Get_Position(&current_pos);
  4140. test_pos = current_pos + height_offset;
  4141. } while ((current_pos != last_pos) &&
  4142. !CombatManager::Is_In_Camera_Frustrum(test_pos));
  4143. Set_Position(last_pos);
  4144. }
  4145. }
  4146. }
  4147. }
  4148. */
  4149. void SoldierGameObj::Update_Healing_Effect( void )
  4150. {
  4151. if ( HealingEffect != NULL ) {
  4152. if (( HealingEffect->Get_Target_Parameter() >= 0.49f ) &&
  4153. ( HealingEffect->Get_Parameter() >= 0.49f ) ) {
  4154. HealingEffect->Set_Target_Parameter( 0 );
  4155. }
  4156. if (( HealingEffect->Get_Target_Parameter() == 0 ) &&
  4157. ( HealingEffect->Get_Parameter() == 0 ) ) {
  4158. Peek_Human_Phys()->Remove_Effect_From_Me( HealingEffect );
  4159. REF_PTR_RELEASE( HealingEffect );
  4160. }
  4161. }
  4162. }
  4163. void SoldierGameObj::Enable_Ghost_Collision( bool onoff )
  4164. {
  4165. bool is_using_ghost_collision = (Peek_Physical_Object ()->Get_Collision_Group() == SOLDIER_GHOST_COLLISION_GROUP);
  4166. if ( onoff == is_using_ghost_collision ) {
  4167. return ;
  4168. }
  4169. //
  4170. // Change the collision group as necessary
  4171. //
  4172. if ( onoff ) {
  4173. Peek_Physical_Object ()->Set_Collision_Group( SOLDIER_GHOST_COLLISION_GROUP );
  4174. } else {
  4175. Peek_Physical_Object ()->Set_Collision_Group( SOLDIER_COLLISION_GROUP );
  4176. }
  4177. return ;
  4178. }
  4179. bool SoldierGameObj::Is_Safe_To_Disable_Ghost_Collision( const Vector3 &curr_pos )
  4180. {
  4181. const Vector3 PERSONAL_SPACE_BOX_SIZE (1.5F, 1.5F, 1.0F);
  4182. const float HUMAN_HALF_HEIGHT = 1.0F;
  4183. bool retval = true;
  4184. //
  4185. // Build a box that represents the "personal" space around the soldier
  4186. //
  4187. Vector3 box_pos = curr_pos + Vector3 (0, 0, HUMAN_HALF_HEIGHT);
  4188. AABoxClass box (box_pos, PERSONAL_SPACE_BOX_SIZE);
  4189. //
  4190. // Collect all the dynamic objects in this box
  4191. //
  4192. NonRefPhysListClass obj_list;
  4193. PhysicsSceneClass::Get_Instance ()->Collect_Objects (box, false, true, &obj_list);
  4194. //
  4195. // Loop over all the collected objects
  4196. //
  4197. NonRefPhysListIterator it (&obj_list);
  4198. for (it.First(); !it.Is_Done(); it.Next()) {
  4199. PhysClass *phys_obj = it.Peek_Obj ();
  4200. PhysicalGameObj *game_obj = NULL;
  4201. if ( phys_obj->As_HumanPhysClass () && phys_obj->Get_Observer() != NULL ) {
  4202. game_obj = ((CombatPhysObserverClass *)phys_obj->Get_Observer())->As_PhysicalGameObj();
  4203. }
  4204. //
  4205. // Is this a living soldier?
  4206. //
  4207. if ( game_obj != NULL && game_obj != this &&
  4208. game_obj->As_SoldierGameObj() != NULL &&
  4209. game_obj->As_SoldierGameObj()->Is_Destroyed () == false)
  4210. {
  4211. Vector3 block_pos;
  4212. game_obj->Get_Position (&block_pos);
  4213. //
  4214. // Lets make sure the boxes really intersect
  4215. //
  4216. AABoxClass block_box (block_pos + Vector3 (0, 0, 1.0F), Vector3 (0.3F, 0.3F, 1.0F));
  4217. if (CollisionMath::Overlap_Test (box, block_box) != CollisionMath::OUTSIDE) {
  4218. //
  4219. // Is the boxes intersect, then it is NOT SAFE to disable ghost collision
  4220. // mode.
  4221. //
  4222. retval = false;
  4223. break;
  4224. }
  4225. }
  4226. }
  4227. return retval;
  4228. }
  4229. bool SoldierGameObj::Is_Soldier_Blocked( const Vector3 &curr_pos )
  4230. {
  4231. //
  4232. // Only do this for soldiers who meet our criteria
  4233. //
  4234. if ( (Get_Action () != NULL && Get_Action ()->Is_Busy ()) ||
  4235. Is_Destroyed () || (IS_SOLOPLAY == false))
  4236. {
  4237. return false;
  4238. }
  4239. const Vector3 PERSONAL_SPACE_BOX_SIZE (1.5F, 1.5F, 1.0F);
  4240. const float HUMAN_HALF_HEIGHT = 1.0F;
  4241. //
  4242. // Build a box that represents the "personal" space around the soldier
  4243. //
  4244. Vector3 box_pos = curr_pos + Vector3 (0, 0, HUMAN_HALF_HEIGHT);
  4245. AABoxClass box (box_pos, PERSONAL_SPACE_BOX_SIZE);
  4246. //
  4247. // Collect all the dynamic objects in this box
  4248. //
  4249. NonRefPhysListClass obj_list;
  4250. PhysicsSceneClass::Get_Instance ()->Collect_Objects (box, false, true, &obj_list);
  4251. uint32 my_id = Get_ID ();
  4252. uint32 smallest_id = my_id;
  4253. //
  4254. // Loop over all the collected objects
  4255. //
  4256. NonRefPhysListIterator it (&obj_list);
  4257. for (it.First(); !it.Is_Done(); it.Next()) {
  4258. PhysClass *phys_obj = it.Peek_Obj ();
  4259. PhysicalGameObj *game_obj = NULL;
  4260. if ( phys_obj->As_HumanPhysClass () && phys_obj->Get_Observer() != NULL ) {
  4261. game_obj = ((CombatPhysObserverClass *)phys_obj->Get_Observer())->As_PhysicalGameObj();
  4262. }
  4263. //
  4264. // Is this a living soldier?
  4265. //
  4266. if ( game_obj != NULL && game_obj != this &&
  4267. game_obj->As_SoldierGameObj() != NULL &&
  4268. game_obj->As_SoldierGameObj()->Is_Destroyed () == false)
  4269. {
  4270. Vector3 block_pos;
  4271. game_obj->Get_Position (&block_pos);
  4272. //
  4273. // Lets make sure the boxes really intersect
  4274. //
  4275. AABoxClass block_box (block_pos + Vector3 (0, 0, 1.0F), Vector3 (0.3F, 0.3F, 1.0F));
  4276. if (CollisionMath::Overlap_Test (box, block_box) != CollisionMath::OUTSIDE) {
  4277. if (game_obj->As_SmartGameObj ()->Is_Human_Controlled () == false) {
  4278. //
  4279. // Is this soldier moving?
  4280. //
  4281. ActionClass *curr_action = game_obj->As_SmartGameObj ()->Get_Action ();
  4282. Vector3 dest_pos = curr_action->Get_Parameters ().MoveLocation;
  4283. float distance = (block_pos - dest_pos).Length ();
  4284. if (distance > curr_action->Get_Parameters ().MoveArrivedDistance) {
  4285. //
  4286. // Is this the smallest ID so far?
  4287. //
  4288. uint32 curr_id = game_obj->Get_ID ();
  4289. if (curr_id < smallest_id) {
  4290. smallest_id = curr_id;
  4291. }
  4292. //
  4293. // Push the other guy out of the way (a little)
  4294. //
  4295. /*if (Is_Human_Controlled () || curr_id > my_id) {
  4296. Vector3 delta_vector = block_pos - curr_pos;
  4297. delta_vector.Normalize ();
  4298. SoldierGameObj *soldier = game_obj->As_SoldierGameObj ();
  4299. if (soldier->Peek_Human_Phys () != NULL) {
  4300. soldier->Peek_Human_Phys ()->Collide (delta_vector * TimeManager::Get_Frame_Seconds ());
  4301. }
  4302. }*/
  4303. }
  4304. }
  4305. }
  4306. }
  4307. }
  4308. return (smallest_id != my_id);
  4309. }
  4310. bool SoldierGameObj::Is_Targetable( void ) const
  4311. {
  4312. return (!(((SoldierGameObj*)this)->Is_In_Vehicle())) &&
  4313. SmartGameObj::Is_Targetable();
  4314. }
  4315. float SoldierGameObj::Get_Stealth_Fade_Distance(void) const
  4316. {
  4317. if (IS_MISSION) {
  4318. return GlobalSettingsDef::Get_Global_Settings()->Get_Stealth_Distance_Human();
  4319. } else {
  4320. return GlobalSettingsDef::Get_Global_Settings()->Get_MP_Stealth_Distance_Human();
  4321. }
  4322. }
  4323. void SoldierGameObj::Lock_Facing( PhysicalGameObj * game_obj, bool turn_body )
  4324. {
  4325. FacingObject = game_obj;
  4326. FacingAllowBodyTurn = turn_body;
  4327. //
  4328. // Stop facing if there's nothing to look at
  4329. //
  4330. if ( game_obj == NULL ) {
  4331. Cancel_Look_At();
  4332. }
  4333. return ;
  4334. }
  4335. void SoldierGameObj::Update_Locked_Facing( void )
  4336. {
  4337. if ( FacingObject != NULL ) {
  4338. //
  4339. // Get the position of the object we're "looking" at.
  4340. //
  4341. Vector3 pos;
  4342. FacingObject.Get_Ptr ()->Get_Position( &pos );
  4343. //
  4344. // If the object is a soldier, then look at his head
  4345. //
  4346. if ( FacingObject.Get_Ptr ()->As_PhysicalGameObj ()->As_SoldierGameObj () != NULL ) {
  4347. const float SOLDIER_HEIGHT = 1.7F;
  4348. pos.Z += SOLDIER_HEIGHT;
  4349. }
  4350. //
  4351. // Look at the object
  4352. //
  4353. Look_At( pos, 100.0F );
  4354. //
  4355. // If we can turn to face the object, do so...
  4356. //
  4357. if ( FacingAllowBodyTurn ) {
  4358. Internal_Set_Targeting( pos, false );
  4359. }
  4360. }
  4361. return ;
  4362. }
  4363. /*
  4364. if (CombatManager::I_Am_Server()) {
  4365. CombatManager::Soldier_Dies(this);
  4366. }
  4367. */