dude.cpp 183 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // dude.cpp
  19. // Project: Postal
  20. //
  21. // This module implements the CDude class, which is the main, player-controlled
  22. // character in the game.
  23. //
  24. // History:
  25. // 01/12/97 MJR Started.
  26. //
  27. // 01/15/97 BRH Changed 3D to 2D render position to subtract the
  28. // Y rather than Add it.
  29. //
  30. // 01/23/97 JMI Now calls CRealm::GetLayerFromAttrib() in Render() to
  31. // get on the proper layer.
  32. //
  33. // 01/31/97 BRH Added the ability to throw Grenades.
  34. //
  35. // 01/29/97 JMI Now Load() and Save() call the base class versions.
  36. //
  37. // 02/04/97 JMI Changed LoadDib() call to Load() (which now supports
  38. // loading of DIBs).
  39. //
  40. // 02/07/97 BRH Changed to using the single frame 3D wire frame
  41. // instead of the 2D sprite.
  42. //
  43. // 02/07/97 JMI Added XRay flag to dude.
  44. //
  45. // 02/07/97 JMI GetResources() never closed its RFile. Fixed.
  46. //
  47. // 02/07/97 JMI Now CScene has its own pipeline, so we don't need ours
  48. // anymore. And we don't need to set any of that schtuff
  49. // up. Removed all the pipeline initialization stuff.
  50. //
  51. // 02/10/97 JMI Added the 3D animation for walking (or is it running?).
  52. //
  53. // 02/11/97 JMI Added the 3D animation for throwing and an associated
  54. // rigid body transform for a grenade.
  55. //
  56. // 02/12/97 JMI Forgot to set m_pGrenade->m_dRot again on release so the
  57. // grenade would have correct trajectory even if the dude
  58. // had rotated since the start of the throw. Fixed.
  59. //
  60. // 02/12/97 JMI Now animates backwards for running backwards.
  61. //
  62. // 02/13/97 JMI Changing RForm3d to RSop.
  63. //
  64. // 02/13/97 JMI Now the dude maps his textures to the palette on load.
  65. //
  66. // 02/14/97 JMI Removed Remap(). This'll now be done by a utility before
  67. // we even load the textures.
  68. // Also, changed the direction and rotation the guy does.
  69. // Currently, his position is hosed but I need to check it
  70. // in to get it at home.
  71. //
  72. // 02/17/97 JMI Now uses actual standing anim for standing state.
  73. // Changed resource filenames to not use two '.'s.
  74. // Now uses new m_pRealm->m_scene.TransformPtsToRealm() func
  75. // to get relative position of grenade on release.
  76. // For the mapping from 3D to 2D, now does not take radius
  77. // into account b/c the scene actually draws relative to the
  78. // origin.
  79. // Added UpdateRadius() function to get the current
  80. // m_sSphereRadius of the guy. But this is incorrect b/c
  81. // we should not be using m_sSphereRadius, but instead some-
  82. // thing like m_sCylinderR and m_sCylinderH to determine
  83. // the xray position, EditRect(), and EditHotSpot().
  84. //
  85. // 02/17/97 JMI Now changes the lighting if the lighting bit is set in the
  86. // checked attribute zone.
  87. //
  88. // 02/18/97 MJR Tuned guy turning and running speeds, added use of "shift"
  89. // key to run faster, switched all animations over to newly
  90. // existant main-guy versions.
  91. //
  92. // 02/18/97 JMI Added firing of bullets.
  93. // Also, removed #if 0, #elif 0, .... blocks.
  94. // Also, added dieing animation and die state.
  95. // Now goes into Die state when hit in response to several
  96. // messages.
  97. //
  98. // 02/19/97 JMI Now passes more masks to FireDeluxe() and uses Character
  99. // bit.
  100. // Also, does not subtract 90 before blitting.
  101. //
  102. // 02/19/97 JMI Slowed bullets to MAX_BULLETS_PER_SEC.
  103. //
  104. // 02/19/97 JMI Enhanced SetState(). Not it checks via its current state
  105. // if it's okay to change to the new state, and if it's okay,
  106. // cleans up the old state, sets the new state, and returns
  107. // true, if successful.
  108. //
  109. // 02/19/97 JMI Added shoot while still and while running.
  110. //
  111. // 02/19/97 JMI Changed main_rungun.* to main_run.* for running anim b/c
  112. // main_rungun looked too much like main_runshoot.
  113. // Also, now cannot rotate at user request when dead.
  114. // Now has a running and standing shooting anim.
  115. // Encapsulated release of grenade into ReleaseGrenade() so
  116. // it can be reused.
  117. // Fixed a bunch of little things in SetState().
  118. //
  119. // 02/19/97 JMI Brightness tuned slightly due to everything seeming to
  120. // change in brightness after tonight's assets fest.
  121. //
  122. // 02/19/97 JMI Added damage state.
  123. //
  124. // 02/20/97 MJR Added use of new input functions as part of enabling
  125. // multiplayer network mode.
  126. //
  127. // 02/20/97 JMI Changed bit masks to FireDeluxe so CDudes can shoot any
  128. // other characters.
  129. //
  130. // 02/20/97 JMI Now processes delete message.
  131. //
  132. // 02/20/97 JMI Added blood and now sets m_sprite flags only once (in
  133. // Init()).
  134. //
  135. // 02/21/97 JMI Had forgotten to release the 3d/main_shot.* resource.
  136. // Fixed.
  137. //
  138. // 02/21/97 JMI ThrowRelease was allowing any state change when it was the
  139. // current state.
  140. // Also, now if the dude changes animations during a throw,
  141. // the grenade just drops instead of exploding immediately.
  142. //
  143. // 02/21/97 JMI The grenade now rolls off randomly when dropped accidently.
  144. //
  145. // 02/23/97 JMI Now any state can jump out of damage state.
  146. //
  147. // 02/24/97 JMI Use 3D 'link'-like pt for bullet start position.
  148. //
  149. // 02/24/97 JMI Better blood splat and added blood pool.
  150. //
  151. // 02/24/97 JMI No longer sets the m_type member of the m_sprite b/c it
  152. // is set by m_sprite's constructor.
  153. //
  154. // 02/24/97 JMI Now State_Damage cannot interrupt State_Damage which looks
  155. // a lot better. It would look even better still, I think,
  156. // if the shot animation was a little shorter/faster.
  157. //
  158. // 02/24/97 JMI Now tweaks angle slightly before calling FireDeluxe() so
  159. // the gun does not aim perfectly.
  160. //
  161. // 02/24/97 JMI Added on-fire state.
  162. //
  163. // 02/24/97 JMI Tweaked on-fire state.
  164. //
  165. // 02/24/97 JMI Changed reference to CAnimThing's m_pthingSendMsg member to
  166. // m_u16IdSendMsg.
  167. //
  168. // 02/24/97 JMI No longer bleeds due to fire.
  169. //
  170. // 02/25/97 JMI Added new burning yell sound.
  171. //
  172. // 02/26/97 JMI Now <Control> fires weapon and <Alt> throws grenade.
  173. //
  174. // 03/03/97 JMI Added m_statePersistent.
  175. // Now sets m_statePersistent if State_Damage interrupts
  176. // State_Burning.
  177. //
  178. // 03/03/97 JMI Now passes CSmash::Dead as a bit that FireDeluxe() will not
  179. // hit.
  180. // Now sets m_smash.m_bits to include CSmash::Dead when we
  181. // reach State_Dead and removes it again when be leave
  182. // State_Dead.
  183. //
  184. // 03/03/97 JMI Added states for strafing and multiweapon logic.
  185. // Currently, loads run and shoot for strafe anims which
  186. // should do until the strafe equivalents are ready.
  187. //
  188. // 03/03/97 JMI Changed m_pGrenade to m_pWeapon (a CWeapon* instead of
  189. // a CGrenade*) so more weapons can be handled generically.
  190. //
  191. // 03/03/97 JMI Now CDude is based upon CCharacter.
  192. // Not much base class functionality utilized yet, though.
  193. //
  194. // 03/04/97 JMI Now utilizes more of the base class functionality.
  195. // All CCharacter::Edit*() functions are used.
  196. // Now uses real strafe animations.
  197. // Moved stuff I was incorrectly doing in Render() into
  198. // Update() so CDude now uses CCharacter::Render().
  199. // Update() now uses functions in CCharacter (i.e.,
  200. // UpdateVelocities(), GetNewPosition(), and
  201. // MakeValidPosition() ) to process acceleration,
  202. // velocities, and positions.
  203. //
  204. // 03/04/97 JMI Got rid of #if 0'd out code in Update().
  205. //
  206. // 03/04/97 JMI Now utilizes message overrides from CCharacter.
  207. //
  208. // 03/04/97 JMI Removed UpdateRadius().
  209. // Now calls CCharacter::UpdateFirePosition() to keep fire
  210. // position up to date.
  211. // Converted all rspMod360() calls to new calling convention.
  212. // Removed m_panimthing for fire (now uses base class fire).
  213. // Removed ProcessMessages() (now base class is fine).
  214. //
  215. // 03/05/97 JMI Was checking for fire gone incorrectly. Fixed.
  216. //
  217. // 03/05/97 JMI Now fires weapons (except SemiAutomatic) through base class.
  218. // Eventually, might move that to base class too??
  219. //
  220. // 03/05/97 JMI Removed ReleaseWeapon() now uses CCharacter::ShootWeapon().
  221. //
  222. // 03/05/97 JMI m_pWeapon no longer referenced.
  223. // Uses new multishot animation for when he's been shot.
  224. //
  225. // 03/05/97 JMI Removed ms_apt3dAttribCheck (these points are now stored
  226. // and checked in CCharacer).
  227. // Added Suicide.
  228. //
  229. // 03/06/97 JMI Drag no longer gets set to zero when velocity reaches zero
  230. // by this class (now handled by base class).
  231. // Added override to OnSuicideMsg().
  232. // Added a little fudge to BrainSplat location.
  233. //
  234. // 03/06/97 JMI No longer does hack to get ID from m_pWeapon since the base
  235. // class now stores the ID in m_u16IdWeapon (and does not
  236. // rely on m_pWeapon to reference the weapon).
  237. //
  238. // 03/06/97 JMI Now sets his velocity to 0.0 when committing suicide.
  239. //
  240. // 03/06/97 JMI Changed fudge factor delay for suicide brain splat to
  241. // 1400 ms (was 700 ms).
  242. //
  243. // 03/06/97 JMI User can no longer influence velocity when dude is being
  244. // shot.
  245. //
  246. // 03/13/97 JMI Added EditModify() member function.
  247. // Also, added m_sNumFireBombs/Missiles/Napalms.
  248. // Load now takes a version number.
  249. //
  250. // 03/13/97 JMI Added file format version 2 load stuff:
  251. // m_sNumFireBombs/Missiles/Napalms.
  252. // Now considers amount of particular weapon left before
  253. // firing it.
  254. //
  255. // 03/13/97 JMI Added DrawStatus() member function.
  256. // Now can run out of bullets.
  257. // BUG: Wierd glitchiness when firing empty gun and running
  258. // which is exaggerated by the distance between shots. Longer
  259. // times between empty shots seem to cause more noticable
  260. // glitches.
  261. //
  262. // 03/13/97 JMI Dude now takes additional burn damage while on fire.
  263. //
  264. // 03/14/97 JMI Changed the fire angle sway to 20 (was 10).
  265. //
  266. // 03/14/97 JMI Added very simple jump.
  267. //
  268. // 03/21/97 JMI Added launching animation.
  269. //
  270. // 03/21/97 JMI Now deletes launched weapon when launch is interrupted.
  271. // Also, added a minimum time to the got shot animation.
  272. //
  273. // 03/24/97 JMI Now utilize new input rotation embedded in UINPUT value.
  274. //
  275. // 03/25/97 JMI Now uses main_runnogun*.* for run animation.
  276. //
  277. // 03/26/97 JMI Changed STATUS_FONT_SIZE from 30 to 24.
  278. //
  279. // 03/26/97 JMI When I added the rotation value built into the UINPUT,
  280. // and then ignored the rotation value when dying, the net
  281. // effect was the guy would snap to rotation 0, when dying.
  282. // Fixed.
  283. // Also, when I switched to having the guy get damaged
  284. // more than just once by the same fire, it caused the dude
  285. // to react to fire even if we was previously dead. Fixed.
  286. //
  287. // 03/27/97 JMI Added many animations.
  288. //
  289. // 03/27/97 JMI Timing for blown up animation was being done through the
  290. // rigid body transform for some unknown reason. Fixed.
  291. //
  292. // 03/27/97 JMI Can no longer move forward when ducking, exploding,
  293. // or getting up from explosion.
  294. //
  295. // 03/28/97 JMI Now dude will enter the blown up animation, even if he is
  296. // dead (returning to the dead anim).
  297. // Also, now damage anim will loop.
  298. //
  299. // 03/31/97 JMI Took out INPUT_* macro definitions since input.h now
  300. // defines them correctly.
  301. //
  302. // 04/01/97 JMI UINPUT now stores the delta rotation in the first 10 bits
  303. // as 0..720 representing delta values between -360 and 360.
  304. //
  305. // 04/02/97 JMI Changed all resource animation names to use the
  306. // CREATERESNAMES macro that some were already using.
  307. //
  308. // 04/02/97 JMI OnExplosionMsg() now beefs up his vertical velocity due to
  309. // the explosion, if a successful state change occurs.
  310. //
  311. // 04/03/97 JMI Added additional link point for shooting from nealing pos.
  312. //
  313. // 04/03/97 JMI Changed font color to RGB. The index is gotten on Init().
  314. //
  315. // 04/03/97 JMI Hard coded ms_u8FontBackIndex to RSP_BLACK_INDEX.
  316. //
  317. // 04/03/97 JMI Now that PrepareWeapon() returns the pointer to the new
  318. // weapon or NULL. The return value should not be compared to
  319. // 0 for success (now that indicates failure).
  320. //
  321. // 04/03/97 JMI Now, if the rise state is entered before the ducking anim
  322. // was finished, he jumps into the rise anim at the inverse of
  323. // his relative position in the duck anim so he appears to
  324. // rise back starting at the position he was in during the
  325. // duck. It looks suprisingly good thanks to the consistency
  326. // of the art.
  327. // Also, if shoot is requested while ducking, the dude auto-
  328. // magically switches to rising state first. Firing cannot
  329. // override rising, so it is not entered until the rise is
  330. // complete.
  331. //
  332. // 04/07/97 JMI Added jumps, landings, and fall components.
  333. //
  334. // 04/08/97 JMI He was not responding to State_Delete. Now he deletes self
  335. // at the end of Update().
  336. //
  337. // 04/14/97 BRH Added CSmash::Item to the type of things that bullets could
  338. // hit, so he can shoot barrels.
  339. //
  340. // 04/14/97 JMI Now DrawStatus() will only display <= 100% health.
  341. //
  342. // 04/18/97 JMI Changed EXPLOSION_VERTICAL_VEL_MULTIPLIER from 1.5 to 1.0
  343. // which should basically make is vertical explosion velocity
  344. // the same as all the other characters.
  345. //
  346. // 04/21/97 JMI Changed EXPLOSION_VERTICAL_VEL_MULTIPLIER from 1.0 to 1.3.
  347. //
  348. // 04/21/97 JMI Incorporated Mike's new crawler thinger for smooth rubbin'
  349. // and slidin' up against schtuff.
  350. // The nubs can be heavily tuned.
  351. //
  352. // 04/21/97 JMI Added override of WhileBlownUp().
  353. //
  354. // 04/22/97 BRH In the burning state, he used to check to see when the
  355. // fire object was dead. Now since the fire changes to smoke,
  356. // he was running around on smoke. So I added a call to
  357. // IsBurning so that he knows when he can resume normal
  358. // control.
  359. //
  360. // 04/22/97 JMI Moved the setup of the font stuff to startup when the
  361. // palette for the hood should already have been set. This
  362. // way we get the correct colors for the DrawStatus().
  363. //
  364. // 04/22/97 JMI Fixed my use of shadow even though currently that code does
  365. // not get used.
  366. // Also, changed STATUS_FONT_SIZE from 24 to 26 which is a
  367. // currently cached scale for the g_fontBig.
  368. // Also, disabled jump for current demo for GT.
  369. //
  370. // 04/22/97 JMI Dude can no longer get up after dying.
  371. //
  372. // 04/23/97 JMI Now just uses a test version of IsPathClear().
  373. //
  374. // 04/23/97 JMI Now our bullets can hit Characters, Miscs, Mines,
  375. // Barrels, and Fire.
  376. //
  377. // 04/23/97 JMI Disabled IsPathClear() test.
  378. //
  379. // 04/24/97 JMI Added shotgun weapon components.
  380. //
  381. // 04/25/97 JMI ShootWeapon() now decrements m_sNumShells.
  382. // Also, previously when the guy was reacting to being shot,
  383. // he couldn't die.
  384. //
  385. // 04/25/97 JMI Added a state for executing dudes.
  386. //
  387. // 04/25/97 JMI Can no longer move forward or back or turn while executing.
  388. //
  389. // 04/25/97 JMI Added flame thrower weapon support. Required fuel ammo
  390. // info and special case on release of flamage.
  391. //
  392. // 04/25/97 JMI Removed input for flame thrower for temp even though it will
  393. // soon rock.
  394. //
  395. // 04/27/97 JMI Changed link point for execute and re-enabled flame thrower.
  396. // Also, execute now checks amount of bullets.
  397. //
  398. // 04/28/97 JMI Removed PrepareWeapon() override since the base class
  399. // version now handles bullet oriented weapons.
  400. // Also, moved FireBullets() to base class, CCharacter.
  401. //
  402. // 04/29/97 JMI Changed CAnim3D::Get()'s over to new version that does not
  403. // require an array of char pointers.
  404. // Added m_animPickPut for picking up and putting things down.
  405. // Also, added mine weapon. You cannot choose the type now,
  406. // though (it's the default which is proximity).
  407. //
  408. // 04/29/97 JMI I was unnecessarily making the dude go into State_Rise
  409. // after the State_PutDown animation finished. But, as it
  410. // turns out, the m_animPickPut already contains a rise
  411. // which makes things a bit easier.
  412. //
  413. // 04/29/97 JMI Flame thrower would only work while not moving. Fixed.
  414. //
  415. // 04/30/97 JMI Changed Mine enum value to ProximityMine, TimedMine,
  416. // RemoteMine, and BouncingBettyMine.
  417. //
  418. // 04/30/97 JMI Changed m_animPickPut to use 'hand' instead of 'guntip'.
  419. //
  420. // 05/01/97 JMI Now his animation speed for his run is in ratio to
  421. // RUN_ANIM_VELOCITY and he enters the stand state when his
  422. // speed falls below MIN_RUN_VEL and there's no user
  423. // acceleration.
  424. // Also, fixed some transition bugs involving
  425. // strafing/standing/shooting to strafing/running/shooting and
  426. // everything in between.
  427. //
  428. // 05/02/97 JMI Now plays sample g_smidExecute1 or g_smidExecute2, if
  429. // he actually hits someone during execute.
  430. //
  431. // 05/02/97 JMI Uses new inputs where weapons are a value stored in 4 bits.
  432. //
  433. // 05/08/97 JMI Now shows status change even if the weapon pressed is
  434. // already the current weapon.
  435. // Added the NoWeapon weapon.
  436. //
  437. // 05/09/97 JMI Changed MAX_BULLETS_PER_SEC from 10 to 6.
  438. // Added flame thrower noises.
  439. //
  440. // 05/12/97 JRD Added a call to SpewTriggers on dude move to alert Pylons
  441. //
  442. // 05/13/97 JMI Changed INPUT_WALK (was INPUT_RUN) from functioning as a
  443. // 'fast' key to a 'slow' key.
  444. // Also, I made the slow key affect the rate the dude turns
  445. // by dividing the input rotation delta by SLOW_TURN_DIVISOR.
  446. // Also, added ability to fire the heatseeker.
  447. //
  448. // 05/14/97 JMI Dude can now pick up and cash in on power ups.
  449. // Also, added Message() which allows you to add messages
  450. // to the dude's status display.
  451. //
  452. // 05/22/97 JMI Added CDudeAnim3D so we could use Get() but have it not
  453. // load textures (they are loaded separately so the dude
  454. // color can be changed by the user).
  455. //
  456. // 05/23/97 JMI Update() was nearly a thousand lines and that was just
  457. // too damned much. So I broke it up a bit.
  458. // Also, changed FireCurrentWeapon() to ArmWeapon() which
  459. // takes as a parameter the weapon to fire.
  460. //
  461. // 05/23/97 JMI Changed all the CAnim3D::Get()s to take the new
  462. // pszEventName parameter.
  463. //
  464. // 05/23/97 JMI Changed names of loaded textures to "main_color%02d" (was
  465. // "main_%d".
  466. //
  467. // 05/23/97 JMI Now loads the "main_missile" event data and uses it to
  468. // show and release the missile.
  469. // Consequently, most of the time the missile seems to be in
  470. // the wrong spot and kills us almost immediately... .
  471. //
  472. // 05/25/97 JMI Restored main_missile anim to NOT using events b/c those
  473. // events happend so much earlier than the old FUDGE method,
  474. // the dude kills himself with the missiles.
  475. //
  476. // 05/26/97 JMI Now will only repeat shot state every
  477. // MIN_CANNOT_BE_SHOT_DURATION ms (will groan and get bloody
  478. // though).
  479. // Also, will only yell due to being shot or blown up every
  480. // MIN_BETWEEN_YELLS ms.
  481. //
  482. // 05/26/97 JMI Added m_sOrigHitPoints so dude can show percentage based
  483. // on initial hitpoints.
  484. //
  485. // 05/27/97 JMI Changed 'beers' to 'health'.
  486. //
  487. // 05/29/97 JMI Made it so the dude can go from blownup state to blownup
  488. // state repeatedly (not sure why I limited it before).
  489. // Attempted to make it so the dude does not cry out in
  490. // pain while blowing up.
  491. // Added a Revive() function which is the best way to revive
  492. // a dude that has died.
  493. // Added a timer for changing weapons that use the same input.
  494. //
  495. // 05/29/97 JMI Now the INPUT_JUMP doubles as a revive (when he is dead).
  496. //
  497. // 05/29/97 JMI Fixed comparison on mine delay timer that caused mines to
  498. // be unselectable.
  499. //
  500. // 05/30/97 JMI Added SprayCannon weapon.
  501. //
  502. // 05/30/97 JMI Changed SHELLS_PER_SPRAY_CANNON_FIRE to 4 (was 2) and
  503. // disabled the flame thrower.
  504. //
  505. // 05/30/97 JMI Fixed Spray Cannon so it won't fire if there's less than
  506. // SHELLS_PER_SPRAY_CANNON_FIRE shells.
  507. //
  508. // 06/02/97 JMI Added climb state.
  509. //
  510. // 06/02/97 JMI Removed climb state.
  511. //
  512. // 06/03/97 JMI Changed EXPLOSION_VERTICAL_VEL_MULTIPLIER from 1.3 to 1.0.
  513. //
  514. // 06/03/97 JMI Got rid of 2d brain splat anim and replaced with CChunk
  515. // pieces.
  516. // Also, changed weapon used to shotgun.
  517. //
  518. // 06/03/97 JMI Changed event name from 'mainmissile' to 'mainevent' and
  519. // changed the suicide to use the event for when to fire the
  520. // gun (and splat is brains). Also, now uses the 'head'
  521. // transform for the location of the source of the brain
  522. // splat.
  523. //
  524. // 06/05/97 JMI Removed m_sHitPoints and m_sNum*. Now uses CThing3d's
  525. // m_stockpile instead.
  526. // Changed EditModify() to bring up the user settings for
  527. // m_stockpile when the 'StockPile...' button is pressed.
  528. //
  529. // 06/05/97 JMI Now rotates at a reduced rate when standing still.
  530. // Also, fixed bug with divisors when input for rotation
  531. // is nullified.
  532. //
  533. // 06/06/97 JMI Now utilizes CPowerUps' new CStockPile and GetDescription().
  534. // Also, reduced status font size so we can see moreat 640x480
  535. // (from 26 to 15).
  536. //
  537. // 06/07/97 JMI Now Revive() will try to use a CWarp.
  538. //
  539. // 06/08/97 BRH Added targeting sprite to the dude and using it
  540. // when calling IlluminateTarget() to display which enemy
  541. // or item is being targeted. Temporarily disabled the
  542. // targeting aid. Still need to add a key to toggle
  543. // m_bTargetingHelpEnabled and the position of the target
  544. // sprite needs to be adjusted.
  545. //
  546. // 06/09/97 BRH Adjusted the target position on the child and enabled
  547. // the targeting help.
  548. //
  549. // 06/09/97 JMI Now Revive() empties the message queue b/c we don't want
  550. // him responding to things that happened in his old location
  551. // (i.e., his location before he warped in).
  552. // Removed m_inputLast and m_lLastWeaponChangeTime which are
  553. // no longer necessary now that we can use the auto-repeat
  554. // feature with the new event driven rspGetKeyStatusArray()
  555. // used by input.cpp.
  556. // Added idle animation components.
  557. //
  558. // 06/09/97 BRH Hid the target when the option is disabled. Set the
  559. // default state to disabled.
  560. //
  561. // 06/09/97 JMI Disabled the SprayCannon.
  562. //
  563. // 06/09/97 JMI Changed INPUT_WALK to INPUT_RUN.
  564. //
  565. // 06/10/97 BRH Sends WeaponSelect and WeaponFire messages to CDemon
  566. // so that comments can be made about these actions.
  567. //
  568. // 06/09/97 JMI Added weapon selection feedback specific to whether weapons
  569. // are loaded or empty.
  570. //
  571. // 06/10/97 JMI Changed SLOW_TURN_DIVISOR from 1.5 to 1.25.
  572. //
  573. // 06/10/97 JMI Got rid of the SLOW_TURN_DIVISOR and added a second rate
  574. // inside of input to vary the rate.
  575. //
  576. // 06/10/97 JMI Now notifies demon of suicides.
  577. //
  578. // 06/11/97 JMI Commented out code that starts idle animation.
  579. // Also, made suicide zero your hitpoints.
  580. //
  581. // 06/11/97 JMI Revive() now drops a powerup before warping dude.
  582. //
  583. // 06/12/97 JMI Dude now checks to make sure he has the proper weapon to
  584. // fire the requested ammo.
  585. // Added handy functions, SetWeapon(), NextWeapon(), and
  586. // PrevWeapon().
  587. //
  588. // 06/12/97 JMI Added powerup responses to inputs 10 to 14.
  589. //
  590. // 06/12/97 JMI Adjusted some of the cheat powerups that were silly, silly
  591. // amounts.
  592. //
  593. // 06/12/97 JMI Made launch and throw anims use the events to show and
  594. // release weapons.
  595. // Now registers suicide death with Score module (but will
  596. // probably have to add m_pRealm as a parm once that accepts
  597. // it).
  598. // Now napalm launches from the missile launcher.
  599. // Also, re-enabled idle animation.
  600. //
  601. // 06/12/97 JMI Added ms_apszAmmoNames to differentiate between weapons
  602. // and ammo strings.
  603. //
  604. // 06/12/97 JMI Now DrawStatus() only draws once per StatusChange() call.
  605. //
  606. // 06/13/97 JMI Now State_ThrowRelease, State_LaunchRelease, and
  607. // State_PutDown all use WhileHoldingWeapon() to unhide and
  608. // release the weapon at the appropriate event driven times.
  609. //
  610. // 06/13/97 JMI Now correctly uses columns and word wrap with its m_print.
  611. //
  612. // 06/14/97 JMI Now picks up powerups when you run over them.
  613. //
  614. // 06/15/97 JMI Now minimizes total stockpile after adding in powerups.
  615. // Now initializes stockpiles since CStockPile no longer has
  616. // a constructor (I wanted it to be aggregatable).
  617. //
  618. // 06/16/97 JMI Now plays a sound when his torso hits the ground when dying.
  619. //
  620. // 06/16/97 JMI The target now alpha blits.
  621. //
  622. // 06/16/97 JMI Added MessageChange() and m_lMsgUpdateDoneTime.
  623. //
  624. // 06/16/97 JMI Plays audible feedback via powerup when powerups picked up.
  625. // Up, up, up, up.
  626. //
  627. // 06/16/97 JMI Added parms to make ShootWeapon() comply with virtual
  628. // base class version.
  629. // Also, fixed bug where, when out of bullets, we went ahead
  630. // and fired anyways.
  631. //
  632. // 06/16/97 JMI Now applies resets shot timer when a shot kills us.
  633. //
  634. // MJR Changed strafe speed.
  635. //
  636. // JMI Now registers death when he enters the State_Dead.
  637. //
  638. // 06/17/97 JMI Changed the hit the ground noise event val to 2 (was 1).
  639. //
  640. // JMI Added PlayStep() which is commented out b/c of sound probs.
  641. // Added m_u8LastEvent and OnExecute().
  642. //
  643. // JMI Added NULL in call to PlaySample() corresponding to new
  644. // param.
  645. //
  646. // 06/17/97 JMI Converted all occurrences of rand() to GetRand() and
  647. // srand() to SeedRand().
  648. //
  649. // 06/24/97 JMI Now notifies the demon of suicide in SetState() (used to
  650. // be in OnSuicideMsg() which is not the only way a suicide
  651. // can be initiated).
  652. // Also, now SetWeapon() only sends a message to the demon
  653. // if the new weapon has ammo.
  654. //
  655. // 06/25/97 JMI Added FindExecutee() which is called to find an executee
  656. // before entering the execute state. If none is found, we
  657. // do not enter the state. If we do enter the state, while
  658. // he is leading up to the shooting portion of the animation,
  659. // he turns toward the executee. When he fires at the
  660. // executee, it does not use FireBullets() but instead merely
  661. // creates a muzzle flare and sound for feedback and sends a
  662. // message to the executee telling him he's been shot.
  663. //
  664. // 06/25/97 JMI Now calls PrepareShadow() in Init() which loads and sets up
  665. // a shadow sprite.
  666. // Also, now prints 'you are dead' when you are out of
  667. // hitpoints.
  668. //
  669. // 06/25/97 JMI Replaced m_lStatusUpdateDoneTime with
  670. // m_lNextStatusUpdateTime and removed m_bUpdateStatus.
  671. // Also, changed SHELLS_PER_SPRAY_CANNON_FIRE from 4 to 1.
  672. // ms_apszAmmoNames[] now contain the sprintf format
  673. // specifiers to provide greater to control to each type over
  674. // whether to display a number and/or where to display it.
  675. // The machine gun no longer uses up bullets. So, once you
  676. // have bullets, you never run out.
  677. // Now hitting the rocket key while the rocket is selected
  678. // switches to heatseekers and vice-versa.
  679. // Now switches to the machine gun when you run out of
  680. // a particular weapon.
  681. //
  682. // 06/26/97 JMI The 'You are dead' message now flashes.
  683. // Target now goes away when you are dead.
  684. // Also, changed 'You are dead' to something else to get
  685. // Steve inspired enough to think of a cool one.
  686. //
  687. // 06/26/97 JMI Now handles throw weapons the same way launch weapons are
  688. // handled when leaving the animation early. That is, they
  689. // no longer drop, but, instead, just get deleted via a
  690. // message.
  691. //
  692. // 06/26/97 JMI Re-activated foot step sound.
  693. //
  694. // 06/27/97 JMI If the dude cannot move (i.e., MakeValidPos() fails), he
  695. // resets his velocity, acceleration, and drag to zero.
  696. // The only possible problem that I know of with this is that,
  697. // if there's an external force that's causing him to push up
  698. // against terrain, even if he is fighting the force by run-
  699. // ning against it, he won't be able to accelerate until the
  700. // force dissipates. Currently, though, all external forces
  701. // have drag.
  702. //
  703. // 06/28/97 JMI Now scales the Dude's Z through the realm before calling
  704. // SpewTriggers().
  705. //
  706. // 06/29/97 JMI Now uses the new name for the function that scales the Z
  707. // through the realm (MapZ3DtoY2D (was ScaleZ) ).
  708. //
  709. // 06/30/97 BRH Cached sound effects during the load so they will be
  710. // ready for their first use.
  711. //
  712. // 07/01/97 JMI Changed name of animation file for strafe from 'sidestep'
  713. // to 'strafe' and strafe and shoot from 'sideshoot' to
  714. // 'strafe'.
  715. // Added new rigid bodies to CDudeAnim3D and moved its
  716. // function defs into dude.cpp.
  717. // Also, added m_idFlagItem.
  718. //
  719. // 07/01/97 JMI Strafing was not playing anim backwards for left strafe
  720. // when shooting.
  721. // Also, a bug caused the strafe to not go backwards for
  722. // the regular (non-shooting) strafe if m_dRot was less than
  723. // 90.
  724. //
  725. // 07/02/97 BRH Changed the flamethrower to use CFirestreamID rather than
  726. // CFireballID.
  727. //
  728. // 07/03/97 JMI Now uses SetGuiToNotify() to make a button able to end a
  729. // DoGui() session.
  730. //
  731. // 07/04/97 BRH Made the Dude drop the flag if he gets blownup, burned or
  732. // he dies, also it tries to use the current animation's
  733. // rigid body transform for the release point but if it doesn't
  734. // have one it will just use the guy's position.
  735. //
  736. // 07/07/97 JMI DrawStatus() now returns true if it drew to the provide
  737. // image.
  738. //
  739. // 07/08/97 BRH Changed some of the animation names that were too long
  740. // for the delicate MacOS. Also changed hand transform
  741. // and backpack animation names.
  742. //
  743. // 07/09/97 JMI Changed MAX_STEPUP_THRESHOLD to use CThing3d's macro enum
  744. // MaxStepUpThreshold.
  745. //
  746. // 07/09/97 JMI Now uses m_pRealm->Make2dResPath() to get the fullpath
  747. // for 2D image components.
  748. //
  749. // 07/10/97 JMI Now uses "lfhand" for main rigid body for pick put anim.
  750. //
  751. // 07/10/97 JMI Changed names of loaded textures from "main_color%02d" to
  752. // "main_%d". Also, now it's zero based instead of 1 based.
  753. //
  754. // 07/12/97 JMI Now m_pRealm->m_bMultiplayer must be true in order to
  755. // Revive() a CDude.
  756. //
  757. // 07/13/97 JMI Set ms_dAccUser and ms_dAccDrag to 1000.0 each so the Dude
  758. // will start and stop nearly immediately.
  759. // Attempt to adjust the RUN_ANIM_VELOCITY but got nowhere.
  760. // Somebody who's better at judging distances should do that.
  761. //
  762. // 07/14/97 JMI Now applies damange to dude in OnBurnMsg() after doing all
  763. // other processing. The problem was that, when he was being
  764. // damaged before other processing, he would die if the damage
  765. // was great enough and then the other processing would not
  766. // be done.
  767. // Also, only destroys his fire when exiting the burning state
  768. // to go to other than the die state.
  769. //
  770. // 07/14/97 JMI Was subtracting from fuel for flamethrower in both
  771. // ArmWeapon() and ShootWeapon().
  772. //
  773. // 07/15/97 JMI Moved CDude() and ~CDude() from dude.h to dude.cpp.
  774. // Also, ShootWeapon() no longer checks for out of fuel con-
  775. // dition as this is done in ArmWeapon().
  776. //
  777. // 07/15/97 JMI Now dude will leave portions of powerups that he doesn't
  778. // need.
  779. //
  780. // 07/15/97 JMI Added TakePowerup().
  781. //
  782. // 07/16/97 JMI Made DropPowerUp() return the newly created powerup.
  783. // Added CreateCheat() which trims the amount the dude cannot
  784. // use from the stockpile and passes that to DropPowerUp().
  785. //
  786. // 07/16/97 JMI Changed the order of the weapons.
  787. //
  788. // 07/17/97 JMI Changed m_psnd to m_siLastPlayInstance.
  789. // Now uses new SampleMaster interface for volume and play
  790. // instance reference.
  791. //
  792. // 07/18/97 JMI Now uses StopLoopingSample() to stop looping the flame-
  793. // thrower sound (instead of GetInstanceChannel() ).
  794. //
  795. // 07/18/97 JMI Got rid of bogus immitation PlaySample functions.
  796. // Now there is one PlaySample() function. Also, you now
  797. // MUST specify a category and you don't have to specify a
  798. // SoundInstance ptr to specify a volume.
  799. //
  800. // 07/18/97 JMI Now updates font colors based on hood background's palette
  801. // rather than the RSPiX system palette.
  802. //
  803. // 07/19/97 JMI In previous fix, forgot to change the increment value for
  804. // the palette red, green, & blue arrays.
  805. // Also, now we pass our GUI to the stockpile editor.
  806. // Also, now Revive() allows revival in single player mode if
  807. // the dude has health greater than 0.
  808. // Also, the 'give health' cheat can now be activated while
  809. // dead.
  810. //
  811. // 07/20/97 BRH Added a few more sample caches for weapon selection and
  812. // powerup pickups.
  813. //
  814. // 07/20/97 JMI Now, if there's nothing the dude needs out of a powerup,
  815. // he plays a feedback sample and throws the powerup anyways.
  816. //
  817. // 07/20/97 JMI Spray cannon is now governed by MAX_SPRAYS_PER_SEC (10).
  818. //
  819. // 07/21/97 JMI Now TakePowerUp() returns the powerup if it persisted.
  820. // CreateCheat() now immediately hands the created powerup
  821. // to TakePowerUp() so there's no chance we'll miss it.
  822. // Also, TakePowerUp() will use the max stockpile for
  823. // backpacks not only if the dude has a backpack but, also,
  824. // if the dude will have a backpack (i.e., if there's one in
  825. // the powerup).
  826. // Also, added ms_apszWeaponStatusFormats[].
  827. // Now, if you have ammo but no weapon, it reports that you
  828. // have ammo but no weapon. Ingenious.
  829. //
  830. // 07/21/97 JMI Added OnWeaponDestroyed() override of CCharacter version.
  831. // Also, Update() now calls CCharacter version.
  832. // Also, ShootWeapon() now decrements ammo supplies (not
  833. // ArmWeapon() ).
  834. // Also, added m_weaponShooting.
  835. // Removed SHELLS_PER_SPRAY_CANNON_FIRE.
  836. //
  837. // 07/22/97 JMI Now can never run out of machine gun bullets again.
  838. //
  839. // 07/23/97 JMI Changed MIN_CANNOT_BE_SHOT_DURATION to 3000 (was 1500) ms.
  840. //
  841. // 07/23/97 JMI Added DefHasNapalmLauncher enum and added strings to in-
  842. // corporate new napalm launcher (used to be launched by the
  843. // missile launcher).
  844. //
  845. // 07/25/97 JMI Removed PickUp input.
  846. // Added option to Revive() to allow him to revive in-place
  847. // (rather than warping in).
  848. // Added m_bDead and IsDead() which are true when the dude
  849. // is dead.
  850. // Now uses m_bDead in most cases that m_state == State_Dead
  851. // and m_smash.m_bits & CSmash::Dead were used.
  852. //
  853. // 07/25/97 JMI Added StartAnim() which starts a CAnimThing.
  854. // Added visual feedback (bullet CChunks that fly off) when
  855. // wearing the kevlar layers.
  856. //
  857. // 07/27/97 JMI Now, like the chunks, ricochets appear on the appropriate
  858. // part of the dude's torso (based on the angle of the bullet).
  859. // It might make sense to eventually put the height of the shot
  860. // in the shot message so we can place the splat at the
  861. // appropriate height giving more feedback as to what's/who's
  862. // shooting us. It'd also be neat to adjust the damage based on
  863. // the vertical position.
  864. // Also, now StartAnim() does not call CRealm::Make2dResPath()
  865. // on passed in paths since CAnimThing does this
  866. // automatically.
  867. //
  868. // 07/28/97 JMI Now checks m_bDead (instead of m_stockpile.m_sHitPoints) to
  869. // determine if dude is dead in DrawStatus().
  870. // Also, only bobbles powerups when alive.
  871. //
  872. // 07/28/97 JMI Fixed resurection w/o powerup that would occur sometimes.
  873. // There are only two ways to leave the Die state, BlowUp and
  874. // Dead. Sometimes he would get blown up while dying skipping
  875. // ever getting his m_bDead flag set. Now the Die state sets
  876. // this flag as well since we know we want him to die if he
  877. // enters the die state.
  878. // Since, once his dead flag is set, he can accept the
  879. // resurection cheat, there's some misleading feedback in the
  880. // Die state if that cheat is entered.
  881. // To avoid this problem we could not set the flag and instead
  882. // set the persistent state to State_Dead so that when he's
  883. // done blowing up he'll go to the dead state, but setting the
  884. // flag seems much more likely to make sure he dies.
  885. //
  886. // 07/29/97 JMI Added GetCurrentWeapon().
  887. //
  888. // 07/30/97 JMI Added DeathWad components.
  889. // Now displays a random message from g_apszDeathMessages[]
  890. // when dead.
  891. //
  892. // 07/30/97 JMI Now the death wad cheat enables the death wad option in the
  893. // editor.
  894. //
  895. // 08/01/97 BRH CreateCheat() now sends a message to the CDemon to let
  896. // it know that a cheat code was entered so the Demon can
  897. // mock the player. Also added it in the revive case.
  898. // Also took out loading of .hot files since they aren't used
  899. // and will soon be deleted from the directories.
  900. // Changed fire damage to be based on difficulty setting.
  901. //
  902. // 08/04/97 JMI Now Damage() function will set m_bDead even if
  903. // SetState(State_Die) fails. This way, he'll die when he
  904. // comes out of the explosion state (he cannot go to die from
  905. // explode (unless explode is done) b/c that would look really
  906. // wrong).
  907. //
  908. // 08/04/97 JMI Added array of weapon anims, m_aanimWeapons[], and
  909. // a sprite for showing the current weapon, m_spriteWeapon.
  910. // Now changes weapons visually based on current weapon type.
  911. //
  912. // 08/04/97 JMI Now uses Jeff's rspDegDelta() to better determine which
  913. // direction to turn when executing.
  914. //
  915. // 08/05/97 JMI Changed reference of m_pRealm->m_bMultiplayer to
  916. // m_pRealm->m_flags.bMultiplayer.
  917. // Changed "rthand" to "gun" for right hand rigid body trans-
  918. // form.
  919. //
  920. // 08/05/97 JMI Added an ID to Message(). The idea being that, when the
  921. // same message ID is specified w/i a certain amount of time,
  922. // the more recent message is ignored.
  923. //
  924. // 08/06/97 JMI Now OnExecute(), TrackExecutee(), and FindExecutee() can
  925. // work with any CThing that defines GetX/Y/Z() (not just
  926. // CThing3d's).
  927. //
  928. // 08/07/97 JMI Added DoubleBarrel components.
  929. //
  930. // 08/07/97 JMI Forgot a break in switch in GetWeaponInfo().
  931. //
  932. // 08/07/97 JMI Added m_animBackpack and m_spriteBackpack for his backpack
  933. // when he has it.
  934. //
  935. // 08/07/97 JMI Removed commented out hot channel stuff from CDudeAnim3D.
  936. // Added release of backpack anim in FreeResources().
  937. //
  938. // 08/08/97 JMI Now that CCharacter handles flamer noise, this class now
  939. // longer has to (and doesn't).
  940. //
  941. // 08/08/97 JMI Added TossPowerUp().
  942. // Also, changed TakePowerup() to TakePowerUp().
  943. // Now, when he enters the dead state in multiplayer mode,
  944. // he drops his schtuff.
  945. //
  946. // 08/08/97 JMI Majorly condensed code segments for detaching flag by
  947. // calling DetachChild() which does most of what we were doing
  948. // here. Also, removed some conditions that were checking to
  949. // make sure m_panimCur and m_panimCur->m_ptransRigid were
  950. // valid but they were not very useful since if m_panimCur were
  951. // NULL we'd be fucked AND m_ptransRigid was not the
  952. // rigid body transforms being used for the flag anyways (we're
  953. // using m_ptransLeft).
  954. //
  955. // 08/09/97 JMI Draws dead frame into background just before reviving.
  956. //
  957. // 08/10/97 JMI Added StrafeLeft and StrafeRight inputs.
  958. // Also, changed Jump to Revive and INPUT_JUMP to INPUT_REVIVE.
  959. //
  960. // 08/10/97 JMI Changed doubles dDistX and Z to shorts sDistX and Z. The
  961. // compiler seemed to lock up when inlining was enabled and we
  962. // passed these two doubles to rspATan. With a different
  963. // function it worked fine and with one of the vars as a short
  964. // it worked fine. /shrug Looking for a VC patch.
  965. //
  966. // 08/10/97 JMI Added m_dLastCrawledToPosX, Z which are the last position
  967. // successfully crawled to by the crawler (except on the
  968. // first iteration where they are simply set to the dude's
  969. // starting point). In TRACENASSERT mode, an ASSERT is
  970. // generated if the position gets modified by other than the
  971. // crawler. In release mode, it sets him back to the last
  972. // successful crawled position.
  973. // Added a function to set m_dX, Y, & Z, SetPosition().
  974. //
  975. // 08/12/97 BRH Added CSmash::Ducking bits to the smash when he is
  976. // ducking down. When he is ducking, he won't get hit
  977. // by the missiles.
  978. //
  979. // 08/12/97 JMI Removed unused anims: m_animJump, JumpForward, Land,
  980. // LandForward, Fall.
  981. //
  982. // 08/13/97 JMI Temporarily shows particle effects regardless of user
  983. // setting in multiplayer mode.
  984. //
  985. // 08/14/97 JMI Switched references to g_GameSettings.m_sDifficulty to
  986. // m_pRealm->m_flags.sDifficulty.
  987. //
  988. // 08/14/97 BRH Added static collision bits to be passed as the default
  989. // bits for weapons that the dude shoots. The default
  990. // arguments in the ShootWeapon are unreliable and may
  991. // get set to the bits of the base class default args.
  992. // Also changed call of WhileHoldingWeapon to include
  993. // these default collision bits.
  994. //
  995. // 08/15/97 BRH Set the XrayAll flag when the Dude is dead, so if he
  996. // dies behind opaque, you will be able to see that he is
  997. // dead.
  998. //
  999. // 08/17/97 JMI Changed to only find writhers as executees and will
  1000. // definitely hit the executee.
  1001. //
  1002. // 08/17/97 JMI Removed all occurrences of the SetXRayAll() call as this
  1003. // would not be a good place to do that since this dude is
  1004. // not necessarily the local dude. Soon we will change Play
  1005. // to do it since it knows that.
  1006. //
  1007. // 08/17/97 JMI Got rid of m_szMessages and all message related functions
  1008. // and variables from CDude since we are now using the toolbar
  1009. // for dude status feedback to the user. This includes:
  1010. // MsgTypeInfo, m_lNextStatusUpdateTime, m_lMsgUpdateDoneTime,
  1011. // m_print, m_bClearedStatus, m_szMessages[], m_sDeadMsgNum,
  1012. // ms_amtfMessages[], ms_u8FontForeIndex, ms_u8FontBackIndex,
  1013. // ms_u8FontShadowIndex, DrawStatus(), StatusChange(),
  1014. // MessageChange(), Message(), UpdateFontColors(),
  1015. // CPowerUp::ms_apszPowerUpTypeNames[],
  1016. // CPowerUp::GetDescription(), and some strings and a string
  1017. // array in localize.*.
  1018. //
  1019. // 08/18/97 JMI Now applies no randomization to CChunks and instead allows
  1020. // CChunk::Setup() to apply its own randomization based on
  1021. // sway values passed to it. Also, CChunk::Construct() will
  1022. // now fail if particles are disabled so we don't need to
  1023. // check for that anymore.
  1024. //
  1025. // 08/18/97 JMI Moved StartAnim() from CDude to CThing3d so more things
  1026. // could use it.
  1027. //
  1028. // 08/18/97 JMI Added m_bInvincible which gets set via cheat.
  1029. // Added many cheats and revamped originals. There is one
  1030. // left.
  1031. //
  1032. // 08/18/97 JMI Added cheat code for sales people.
  1033. //
  1034. // 08/18/97 JMI Changed Revive() to call DeadRender3D() (which used to be
  1035. // known/called as just another Render() overload).
  1036. //
  1037. // 08/19/97 JMI No longer shoots CSmash::Misc items.
  1038. //
  1039. // 08/24/97 BRH Forwards the burn message to the child flag so that it
  1040. // can react. Before he was dropping the flag when blown up
  1041. // or burned, but only telling the flag when it was blown up,
  1042. // so if you got burned while holding the flag, the flag was
  1043. // in the wrong state and never looked for anyone to pick it
  1044. // up again. So the flag would be stuck in place and you could
  1045. // not grab it again.
  1046. //
  1047. // 08/24/97 JMI Now instead of setting his brightness to zero in the dead
  1048. // state, he clears it in Revive(). This way he stays charred
  1049. // even when laying there dead or being blown up but cannot
  1050. // come back to life charred.
  1051. //
  1052. // 08/24/97 JMI Now INPUT_WEAPON_0 is no weapon and INPUT_WEAPON_10 is
  1053. // mines.
  1054. //
  1055. // 08/28/97 BRH Moved the caching of samples to Init() now that the
  1056. // Load function is not being called now that the warps
  1057. // create a dude. Also added OnPutMeDowmMsg handler function
  1058. // that the flag sends when it wants to be set down (on the
  1059. // flagbase).
  1060. //
  1061. // 08/30/97 JMI Removed m_idFlagItem (now uses the sprite list and, for
  1062. // flag child sprites, updates them all).
  1063. //
  1064. // 09/01/97 JMI Now ArmWeapon() sets m_weaponShooting to NoWeapon if it
  1065. // fails to arm a weapon (either b/c of no ammo or the shoot
  1066. // state is not attainable).
  1067. //
  1068. // 09/01/97 JMI Previous changed was hosing the shotgun so I made it a
  1069. // little less strict.
  1070. //
  1071. // 09/02/97 JMI Now targets CSmash::Sentry in ms_u32CollideBitsInclude.
  1072. //
  1073. // 09/07/97 MJR Fixed bug in DropAllFlags() that didn't read the message
  1074. // properly.
  1075. //
  1076. // 09/08/97 JMI Added Kevlar type for pieces of kevlar vest that
  1077. // splatter off of dudes with vest.
  1078. //
  1079. // 11/21/97 JMI Now varies whether CSmash::Good is a desirable target to
  1080. // our weapons based on the realm's multiplayer cooperative
  1081. // flag.
  1082. // Removed version of ShootWeapon() that took 3 default
  1083. // parameters and replaced it with a version that takes no
  1084. // parameters so we could control the defaults from within the
  1085. // CPP.
  1086. // Also, now sets CWeapons' detection bits explicitly via
  1087. // SetDetectionBits() to NOT seek other players in Cooperative
  1088. // multiplayer mode.
  1089. //
  1090. // 12/08/97 JMI Added an option for DropPowerUp() to only drop the
  1091. // currently selected weapon.
  1092. // Also, now sets m_sHitPoints to zero before calling
  1093. // SetState(State_Dead) which was previously generating a
  1094. // health powerup if m_sHitPoints was greater than zero which
  1095. // was the case for suicide.
  1096. //
  1097. // 12/09/97 JMI Now drops all weapons when reviving in single player mode.
  1098. // In general, drops all weapons when reviving at location of
  1099. // death and drops only the current weapon when reviving via
  1100. // a warp (the warp gives you additional stuff).
  1101. //
  1102. ////////////////////////////////////////////////////////////////////////////////
  1103. #define DUDE_CPP
  1104. #include "RSPiX.h"
  1105. #include <math.h>
  1106. #include "dude.h"
  1107. #include "grenade.h"
  1108. #include "game.h"
  1109. #include "SampleMaster.h"
  1110. #include "input.h"
  1111. #include "AnimThing.h"
  1112. #include "reality.h"
  1113. #include "fire.h"
  1114. #include "TriggerRegions.h"
  1115. #include "PowerUp.h"
  1116. #include "chunk.h"
  1117. #include "warp.h"
  1118. #include "score.h"
  1119. #include "CompileOptions.h" // For sales cheat.
  1120. #include "play.h"
  1121. //#ifdef MOBILE
  1122. bool demoCompat = false; //Set in Play.cpp
  1123. //#endif
  1124. #if defined(ALLOW_TWINSTICK)
  1125. void GetDudeVelocity(double* d_Velocity, double* d_Angle);
  1126. extern bool GetDudeFireAngle(double* d_Angle);
  1127. #endif
  1128. ////////////////////////////////////////////////////////////////////////////////
  1129. // Macros/types/etc.
  1130. ////////////////////////////////////////////////////////////////////////////////
  1131. // Determines the number of elements in the passed array at compile time.
  1132. #define NUM_ELEMENTS(a) (sizeof(a) / sizeof(a[0]) )
  1133. // Tunable bullet parameters.
  1134. #define MAX_BULLETS_PER_SEC 6
  1135. #define MS_BETWEEN_BULLETS (1000 / MAX_BULLETS_PER_SEC)
  1136. #define MAX_SPRAYS_PER_SEC 10
  1137. #define MS_BETWEEN_SPRAYS (1000 / MAX_SPRAYS_PER_SEC)
  1138. #define MAX_FLAMES_PER_SEC 1000
  1139. #define MS_BETWEEN_FLAMETHROWS (1000 / MAX_FLAMES_PER_SEC)
  1140. #define MODIFY_GUI_FILE "res/editor/EditDude.gui"
  1141. // Random amount the fire angle can adjust.
  1142. #define FIRE_ANGLE_Y_SWAY 15
  1143. #define FIRE_ANGLE_Z_SWAY 10
  1144. // Maximum the guy can tweak your angle while you're on fire.
  1145. #define ON_FIRE_ROT_TWEAKAGE 22
  1146. #define ON_FIRE_VEL_TWEAKAGE ((short)ms_dMaxVelForeFast)
  1147. // Amount per damage pt that translate to velocity.
  1148. #define VEL_PER_DAMAGE 0.5
  1149. // Gets a random between -range / 2 and range / 2.
  1150. #define RAND_SWAY(sway) ((GetRand() % sway) - sway / 2)
  1151. // Velocity for strafing.
  1152. #define STRAFE_VEL 60.0
  1153. #define EXPLOSION_VERTICAL_VEL_MULTIPLIER 1.0
  1154. // Amount of time to suffer from shot.
  1155. #define MIN_SHOT_DURATION 500
  1156. // Amount of time before we can suffer another shot.
  1157. #define MIN_CANNOT_BE_SHOT_DURATION 3000
  1158. // Minimum duration between yells (for blown up and shot).
  1159. #define MIN_BETWEEN_YELLS 750 // Current yell ('groan_male1.wav') is 640 ms.
  1160. // IDs for GUIs.
  1161. #define GUI_ID_STOCKPILE 3
  1162. // The color range that is the same on all hoods.
  1163. #define CONSTANT_COLOR_START_INDEX 95
  1164. #define NUM_CONSTANT_COLOR_INDICES (256 - CONSTANT_COLOR_START_INDEX)
  1165. // Size of font used for status updates.
  1166. #define STATUS_FONT_SIZE 15
  1167. // 0 for any of these colors is transparent.
  1168. #define STATUS_FONT_FORE_RED 128
  1169. #define STATUS_FONT_FORE_GREEN 0
  1170. #define STATUS_FONT_FORE_BLUE 0
  1171. #define STATUS_FONT_BACK_RED 0
  1172. #define STATUS_FONT_BACK_GREEN 0
  1173. #define STATUS_FONT_BACK_BLUE 0
  1174. #define STATUS_FONT_SHADOW_RED 127
  1175. #define STATUS_FONT_SHADOW_GREEN 127
  1176. #define STATUS_FONT_SHADOW_BLUE 127
  1177. #define STATUS_PRINT_X 0
  1178. #define STATUS_PRINT_Y 0
  1179. #define STATUS_UPDATE_DURATION 5000 // In ms.
  1180. #define MESSAGE_UPDATE_DURATION 3000 // In ms.
  1181. #define SHADOW_DEPTH_X 1
  1182. #define SHADOW_DEPTH_Y 1
  1183. // Rate at which run animation was made to travel in pixels per second.
  1184. // This is used to compute a ratio to the current speed. The resulting
  1185. // ratio is used to tune the animation rate dynamically.
  1186. #define RUN_ANIM_VELOCITY 85.0 // Pix/Sec.
  1187. // When below this speed, the dude will not be in his running anim.
  1188. #define MIN_RUN_VEL 40.0 // Pix/Sec.
  1189. // Maximum springiness for crawler.
  1190. #define MAX_CRAWLER_PUSH_X 1.5
  1191. #define MAX_CRAWLER_PUSH_Z 1.5
  1192. // Time between cycling weapons that are chosen using the same input.
  1193. #define WEAPON_CYCLE_TIME 250
  1194. // Ladder tolerance.
  1195. #define LADDER_DIR_TOLERANCE 20 // +/- this amount in degrees.
  1196. #define BRAIN_SPLAT_NUM_CHUNKS 200
  1197. #define BRAIN_SPLAT_SWAY 30
  1198. // Reduced rate for standing still rotation.
  1199. #define STILL_TURN_DIVISOR 2.0
  1200. // Handy macro to define char* array with one 'base' name.
  1201. #define CREATERESNAMES(var, base, rigid) \
  1202. static char* var[] = \
  1203. { \
  1204. "3d/main_" #base ".sop", \
  1205. "3d/main_" #base ".mesh", \
  1206. "3d/main_" #base ".tex", \
  1207. "3d/main_" #base ".hot", \
  1208. "3d/main_" #base ".bounds", \
  1209. "3d/main_" #base ".floor", \
  1210. "3d/main_" #base "_" #rigid ".trans", \
  1211. NULL, /* Safety */ \
  1212. };
  1213. #define TARGETING_FILE "target.img"
  1214. // IDLE_ANIM_TIMEOUT is NOT evaluated every frame.
  1215. #define IDLE_ANIM_TIMEOUT (5000 + (GetRand() % 5000) )
  1216. #define IDLE_ANIM_LOOPS 1
  1217. // This is multiplied our current number of kevlar layers and the
  1218. // result is divided into the bullet damage to produce the damage
  1219. // the dude receives.
  1220. #define KEVLAR_PROTECTION_MULTIPLIER 3
  1221. // Alpha level used when blit'ing the target crosshairs.
  1222. #define TARGET_ALPHA_LEVEL 100
  1223. // Max distance to writher when executing.
  1224. #define EXECUTE_RADIUS 50
  1225. // Time between constant status updates in milliseconds.
  1226. #define STATUS_UPDATE_DELAY 500 // In ms.
  1227. // Max lag time between a known status change and the next update.
  1228. #define MAX_STATUS_LAG 250 // In ms.
  1229. // These may not be correct for now, but just to get them up and running:
  1230. // These are the names of the rigid body transforms that are loaded for
  1231. // every dude animation.
  1232. #define LEFT_HAND_RIGID_ANIM_NAME "lfhand"
  1233. #define RIGHT_HAND_RIGID_ANIM_NAME "gun"
  1234. #define BACK_RIGID_ANIM_NAME "backpack"
  1235. // This value indicates no strafe motion and must be a totally invalid
  1236. // strafe angle value.
  1237. #define INVALID_STRAFE_ANGLE 0x7fff
  1238. #define VEST_HIT_SWAY 10
  1239. #define VEST_HIT_RES_NAME "Ricochet.aan"
  1240. // This is the distance in realm units from the dude's center
  1241. // to the outside of his jacket. This is used to adjust things
  1242. // like ricochets off of his kevlar vest around the outside of
  1243. // his torso.
  1244. #define TORSO_RADIUS 5
  1245. // The minimum square distance the dude wants to be back from
  1246. // his target point when executing.
  1247. #define MIN_SQR_DISTANCE_TO_EXECUTEE 250.0
  1248. // The backpack animation basename.
  1249. #define BACKPACK_RES_NAME "3d/backpack"
  1250. #define COLLISION_BITS_INCLUDE (ms_u32CollideBitsInclude)
  1251. #define COLLISION_BITS_DONTCARE (ms_u32CollideBitsDontcare | (m_pRealm->m_flags.bCoopMode ? 0 : CSmash::Good) )
  1252. #define COLLISION_BITS_EXCLUDE (ms_u32CollideBitsExclude | (m_pRealm->m_flags.bCoopMode ? CSmash::Good : 0) )
  1253. ////////////////////////////////////////////////////////////////////////////////
  1254. // Variables/data
  1255. ////////////////////////////////////////////////////////////////////////////////
  1256. // These are default values -- actually values are set using the editor!
  1257. double CDude::ms_dAccUser = 1000.0; //150.0; // Acceleration due to user
  1258. double CDude::ms_dAccDrag = 1000.0; //110.0; // Acceleration due to drag
  1259. double CDude::ms_dMaxVelFore = 85.0; // Maximum forward velocity
  1260. double CDude::ms_dMaxVelBack = -60.0; // Maximum backward velocity
  1261. double CDude::ms_dMaxVelForeFast = 120.0; // Maximum forward velocity
  1262. double CDude::ms_dMaxVelBackFast = -90.0; // Maximum backward velocity
  1263. double CDude::ms_dDegPerSec = 240.0; // Degrees of rotation per second
  1264. double CDude::ms_dVertVelJump = 100.0; // Velocity of jump.
  1265. U32 CDude::ms_u32CollideBitsInclude = CSmash::Character | CSmash::Barrel | CSmash::SpecialBarrel | CSmash::Sentry;
  1266. U32 CDude::ms_u32CollideBitsDontcare = CSmash::Bad;
  1267. U32 CDude::ms_u32CollideBitsExclude = 0;
  1268. // Let this auto-init to 0
  1269. short CDude::ms_sFileCount;
  1270. // Weapon details database.
  1271. CDude::WeaponDetails CDude::ms_awdWeapons[NumWeaponTypes] =
  1272. {
  1273. // NoWeapon.
  1274. {
  1275. "No Weapon", // Weapon name.
  1276. "bare hands", // Ammo name.
  1277. " No Weapon", // Status format.
  1278. NULL, // Weapon resource name.
  1279. 1, // Min ammo required.
  1280. },
  1281. // SemiAutomatic.
  1282. {
  1283. "Machine Gun", // Weapon name.
  1284. "Bullets", // Ammo name.
  1285. " Machine Gun", // Status format.
  1286. "3d/machinegun", // Weapon resource name.
  1287. 1, // Min ammo required.
  1288. },
  1289. // ShotGun.
  1290. {
  1291. "Shotgun", // Weapon name.
  1292. "Shells", // Ammo name.
  1293. " Shotgun -- %d Shells", // Status format.
  1294. "3d/shotgun", // Weapon resource name.
  1295. 1, // Min ammo required.
  1296. },
  1297. // SprayCannon.
  1298. {
  1299. "Spray Cannon", // Weapon name.
  1300. "Shells", // Ammo name.
  1301. " Spray Cannon -- %d Shells", // Status format.
  1302. "3d/spraygun", // Weapon resource name.
  1303. 1, // Min ammo required.
  1304. },
  1305. // Grenade.
  1306. {
  1307. "Grenades", // Weapon name.
  1308. "Grenades", // Ammo name.
  1309. " %d Grenades", // Status format.
  1310. NULL, // Weapon resource name.
  1311. 1, // Min ammo required.
  1312. },
  1313. // Rocket.
  1314. {
  1315. "Missile Launcher", // Weapon name.
  1316. "Missiles", // Ammo name.
  1317. " Missile Launcher -- %d Missiles", // Status format.
  1318. "3d/launcher", // Weapon resource name.
  1319. 1, // Min ammo required.
  1320. },
  1321. // Heatseeker.
  1322. {
  1323. "Missile Launcher", // Weapon name.
  1324. "Heatseekers", // Ammo name.
  1325. " Missile Launcher -- %d Heatseekers", // Status format.
  1326. "3d/launcher", // Weapon resource name.
  1327. 1, // Min ammo required.
  1328. },
  1329. // FireBomb.
  1330. {
  1331. "Cocktails", // Weapon name.
  1332. "Cocktails", // Ammo name.
  1333. " %d Cocktails", // Status format.
  1334. NULL, // Weapon resource name.
  1335. 1, // Min ammo required.
  1336. },
  1337. // Napalm.
  1338. {
  1339. "Napalm Launcher", // Weapon name.
  1340. "Napalm Canisters", // Ammo name.
  1341. " Napalm Launcher -- %d Canisters", // Status format.
  1342. "3d/napalmer", // Weapon resource name.
  1343. 1, // Min ammo required.
  1344. },
  1345. // Fuel.
  1346. {
  1347. "Flame Thrower", // Weapon name.
  1348. "Fuel Canisters", // Ammo name.
  1349. " Flamer -- %d Fuel Canisters", // Status format.
  1350. "3d/flmthrower", // Weapon resource name.
  1351. 1, // Min ammo required.
  1352. },
  1353. // ProximityMine.
  1354. {
  1355. "Proximity Mines", // Weapon name.
  1356. "Proximity Mines", // Ammo name.
  1357. " %d Proximity Mines", // Status format.
  1358. NULL, // Weapon resource name.
  1359. 1, // Min ammo required.
  1360. },
  1361. // TimedMine.
  1362. {
  1363. "Timed Mines", // Weapon name.
  1364. "Timed Mines", // Ammo name.
  1365. " %d Timed Mines", // Status format.
  1366. NULL, // Weapon resource name.
  1367. 1, // Min ammo required.
  1368. },
  1369. // RemoteMine.
  1370. {
  1371. "Remote Mines", // Weapon name.
  1372. "Remote Mines", // Ammo name.
  1373. " %d Remote Mines", // Status format.
  1374. NULL, // Weapon resource name.
  1375. 1, // Min ammo required.
  1376. },
  1377. // BouncingBettyMine.
  1378. {
  1379. "Bouncing Bettys", // Weapon name.
  1380. "Bouncing Bettys", // Ammo name.
  1381. " %d Bouncing Bettys", // Status format.
  1382. NULL, // Weapon resource name.
  1383. 1, // Min ammo required.
  1384. },
  1385. // DeathWad.
  1386. {
  1387. "Wad Launcher", // Weapon name.
  1388. "Wads", // Ammo name.
  1389. " Wad -- %d missiles, %d napalm canisters, %d fuel canisters, %d grenades", // Status format.
  1390. "3d/napalmer", // Weapon resource name.
  1391. 1, // Min ammo required.
  1392. },
  1393. // DoubleBarrel.
  1394. {
  1395. "Double Barrel", // Weapon name.
  1396. "Shells", // Ammo name.
  1397. " Double Barrel -- %d Shells", // Status format.
  1398. "3d/shotgun", // Weapon resource name.
  1399. 2, // Min ammo required.
  1400. },
  1401. };
  1402. // Dude's default stockpile.
  1403. CStockPile CDude::ms_stockpileDefault =
  1404. {
  1405. DefHitPoints, // m_sHitPoints
  1406. DefNumGrenades, // m_sNumGrenades
  1407. DefNumFireBombs, // m_sNumFireBombs
  1408. DefNumMissiles, // m_sNumMissiles
  1409. DefNumNapalms, // m_sNumNapalms
  1410. DefNumBullets, // m_sNumBullets
  1411. DefNumShells, // m_sNumShells
  1412. DefNumFuel, // m_sNumFuel
  1413. DefNumMines, // m_sNumMines
  1414. DefNumHeatseekers, // m_sNumHeatseekers
  1415. DefHasMachineGun, // m_sMachineGun
  1416. DefHasLauncher, // m_sMissileLauncher
  1417. DefHasShotgun, // m_sShotGun
  1418. DefHasSprayCannon, // m_sSprayCannon
  1419. DefHasFlamer, // m_sFlameThrower
  1420. DefHasNapalmLauncher, // m_sNapalmLauncher.
  1421. DefHasDeathWadLauncher, // m_sDeathWadLauncher.
  1422. DefHasDoubleBarrel, // m_sDoubleBarrel.
  1423. DefKevlarLayers, // m_sKevlarLayers
  1424. DefHasBackpack, // m_sBackpack
  1425. };
  1426. // Nubs (a CCrawler tool). These are the realtive points on the X/Z plane that
  1427. // define the hard and soft 'springs' that deflect the dude from terrain
  1428. // obstacles.
  1429. static CCrawler::Nub ms_anubs[] =
  1430. {
  1431. // Hard nubs
  1432. { 8, 0, 1, 180, 1.0 },
  1433. { 6, -6, 1, 225, 1.0 },
  1434. { 0, -8, 1, 270, 1.0 },
  1435. { -6, -6, 1, 315, 1.0 },
  1436. { -8, 0, 1, 0, 1.0 },
  1437. { -6, 6, 1, 45, 1.0 },
  1438. { 0, 8, 1, 90, 1.0 },
  1439. { 6, 6, 1, 135, 1.0 },
  1440. // Soft nubs
  1441. { 12, 0, 0, 180, 1.0 },
  1442. { 9, -9, 0, 225, 1.0 },
  1443. { 0, -12, 0, 270, 1.0 },
  1444. { -9, -9, 0, 315, 1.0 },
  1445. { -12, 0, 0, 0, 1.0 },
  1446. { -9, 9, 0, 45, 1.0 },
  1447. { 0, 12, 0, 90, 1.0 },
  1448. { 9, 9, 0, 135, 1.0 }
  1449. };
  1450. ////////////////////////////////////////////////////////////////////////////////
  1451. // Get the various components of this animation from the resource names
  1452. // specified in the provided array of pointers to strings.
  1453. ////////////////////////////////////////////////////////////////////////////////
  1454. // virtual // Overridden here.
  1455. short CDude::CDudeAnim3D::Get( // Returns 0 on success.
  1456. char* pszBaseFileName, // In: Base string for resource filenames.
  1457. char* pszRigidName, // In: String to add for rigid transform channel
  1458. // or NULL for none.
  1459. char* pszEventName, // In: String to add for event states channel
  1460. // or NULL for none.
  1461. short sLoopFlags) // In: Looping flags to apply to all channels
  1462. // in this anim.
  1463. {
  1464. short sRes;
  1465. char szResName[RSP_MAX_PATH];
  1466. sprintf(szResName, "%s.sop", pszBaseFileName);
  1467. sRes = rspGetResource(&g_resmgrGame, szResName, &m_psops);
  1468. sprintf(szResName, "%s.mesh", pszBaseFileName);
  1469. sRes |= rspGetResource(&g_resmgrGame, szResName, &m_pmeshes);
  1470. sprintf(szResName, "%s.bounds", pszBaseFileName);
  1471. sRes |= rspGetResource(&g_resmgrGame, szResName, &m_pbounds);
  1472. if (pszRigidName != NULL)
  1473. {
  1474. sprintf(szResName, "%s_%s.trans", pszBaseFileName, pszRigidName);
  1475. sRes |= rspGetResource(&g_resmgrGame, szResName, &m_ptransRigid);
  1476. }
  1477. if (pszEventName != NULL)
  1478. {
  1479. sprintf(szResName, "%s_%s.event", pszBaseFileName, pszEventName);
  1480. sRes |= rspGetResource(&g_resmgrGame, szResName, &m_pevent);
  1481. }
  1482. // We always load these transforms.
  1483. sprintf(szResName, "%s_" LEFT_HAND_RIGID_ANIM_NAME ".trans", pszBaseFileName);
  1484. sRes |= rspGetResource(&g_resmgrGame, szResName, &m_ptransLeft);
  1485. sprintf(szResName, "%s_" RIGHT_HAND_RIGID_ANIM_NAME ".trans", pszBaseFileName);
  1486. sRes |= rspGetResource(&g_resmgrGame, szResName, &m_ptransRight);
  1487. sprintf(szResName, "%s_" BACK_RIGID_ANIM_NAME ".trans", pszBaseFileName);
  1488. sRes |= rspGetResource(&g_resmgrGame, szResName, &m_ptransBack);
  1489. // If successful . . .
  1490. if (sRes == 0)
  1491. {
  1492. m_psops->SetLooping(sLoopFlags);
  1493. m_pmeshes->SetLooping(sLoopFlags);
  1494. m_pbounds->SetLooping(sLoopFlags);
  1495. if (m_ptransRigid != NULL)
  1496. m_ptransRigid->SetLooping(sLoopFlags);
  1497. if (m_pevent != NULL)
  1498. m_pevent->SetLooping(sLoopFlags);
  1499. m_ptransLeft->SetLooping(sLoopFlags);
  1500. m_ptransRight->SetLooping(sLoopFlags);
  1501. m_ptransBack->SetLooping(sLoopFlags);
  1502. }
  1503. return sRes;
  1504. }
  1505. ////////////////////////////////////////////////////////////////////////////////
  1506. // Release all resources.
  1507. ////////////////////////////////////////////////////////////////////////////////
  1508. // virtual // Overridden here.
  1509. void CDude::CDudeAnim3D::Release(void) // Returns nothing.
  1510. {
  1511. rspReleaseResource(&g_resmgrGame, &m_psops);
  1512. rspReleaseResource(&g_resmgrGame, &m_pmeshes);
  1513. rspReleaseResource(&g_resmgrGame, &m_pbounds);
  1514. if (m_ptransRigid != NULL)
  1515. rspReleaseResource(&g_resmgrGame, &m_ptransRigid);
  1516. if (m_pevent != NULL)
  1517. rspReleaseResource(&g_resmgrGame, &m_pevent);
  1518. rspReleaseResource(&g_resmgrGame, &m_ptransLeft);
  1519. rspReleaseResource(&g_resmgrGame, &m_ptransRight);
  1520. rspReleaseResource(&g_resmgrGame, &m_ptransBack);
  1521. }
  1522. ////////////////////////////////////////////////////////////////////////////////
  1523. // Constructor.
  1524. ////////////////////////////////////////////////////////////////////////////////
  1525. CDude::CDude(CRealm* pRealm)
  1526. : CCharacter(pRealm, CDudeID)
  1527. {
  1528. m_statePersistent = State_Stand;
  1529. // Set default stockpile.
  1530. m_stockpile.Copy(&ms_stockpileDefault);
  1531. m_weapontypeCur = SemiAutomatic;
  1532. m_weaponShooting = NoWeapon;
  1533. m_lLastShotTime = 0;
  1534. m_lLastYellTime = 0;
  1535. m_u16IdChild = CIdBank::IdNil;
  1536. m_sTextureIndex = 0;
  1537. m_u8LastEvent = 0;
  1538. m_idVictim = CIdBank::IdNil;
  1539. m_bDead = false;
  1540. m_bInvincible = false;
  1541. // Base the dude number of the number of dude's in the realm. Note that
  1542. // this number already includes this dude, so we subtract 1 from so the
  1543. // assigned dude numbers will start at 0.
  1544. ASSERT(m_pRealm->m_asClassNumThings[CDudeID] > 0);
  1545. m_sDudeNum = m_pRealm->m_asClassNumThings[CDudeID] - 1;
  1546. }
  1547. ////////////////////////////////////////////////////////////////////////////////
  1548. // Destructor
  1549. ////////////////////////////////////////////////////////////////////////////////
  1550. CDude::~CDude()
  1551. {
  1552. // Kill dude
  1553. Kill();
  1554. }
  1555. ////////////////////////////////////////////////////////////////////////////////
  1556. // Load object (should call base class version!)
  1557. ////////////////////////////////////////////////////////////////////////////////
  1558. short CDude::Load( // Returns 0 if successfull, non-zero otherwise
  1559. RFile* pFile, // In: File to load from
  1560. bool bEditMode, // In: True for edit mode, false otherwise
  1561. short sFileCount, // In: File count (unique per file, never 0)
  1562. ULONG ulFileVersion) // In: File version being loaded.
  1563. {
  1564. short sResult = 0;
  1565. // In most cases, the base class Load() should be called.
  1566. sResult = CCharacter::Load(pFile, bEditMode, sFileCount, ulFileVersion);
  1567. if (sResult == 0)
  1568. {
  1569. // Load common data just once per file (not with each object)
  1570. if (ms_sFileCount != sFileCount)
  1571. {
  1572. ms_sFileCount = sFileCount;
  1573. switch (ulFileVersion)
  1574. {
  1575. default: // Newer versions where this format has not changed.
  1576. case 1:
  1577. // Load static data
  1578. pFile->Read(&ms_dAccUser);
  1579. pFile->Read(&ms_dAccDrag);
  1580. pFile->Read(&ms_dMaxVelFore);
  1581. pFile->Read(&ms_dMaxVelBack);
  1582. pFile->Read(&ms_dMaxVelForeFast);
  1583. pFile->Read(&ms_dMaxVelBackFast);
  1584. pFile->Read(&ms_dDegPerSec);
  1585. break;
  1586. }
  1587. }
  1588. switch (ulFileVersion)
  1589. {
  1590. default: // Newer versions where this format has not changed.
  1591. case 16:
  1592. // Nothing to load here.
  1593. break;
  1594. case 15:
  1595. case 14:
  1596. case 13:
  1597. pFile->Read(&m_stockpile.m_sNumHeatseekers);
  1598. pFile->Read(&m_stockpile.m_sNumMines);
  1599. case 12:
  1600. case 11:
  1601. case 10:
  1602. pFile->Read(&m_stockpile.m_sNumFuel);
  1603. case 9:
  1604. pFile->Read(&m_stockpile.m_sNumShells);
  1605. case 8:
  1606. case 7:
  1607. case 6:
  1608. case 5:
  1609. case 4:
  1610. case 3:
  1611. case 2:
  1612. pFile->Read(&m_stockpile.m_sNumBullets);
  1613. pFile->Read(&m_stockpile.m_sNumFireBombs);
  1614. pFile->Read(&m_stockpile.m_sNumMissiles);
  1615. pFile->Read(&m_stockpile.m_sNumNapalms);
  1616. case 1:
  1617. {
  1618. pFile->Read(&m_stockpile.m_sNumGrenades);
  1619. U32 u32Temp;
  1620. pFile->Read(&u32Temp);
  1621. m_state = (CCharacter::State)u32Temp;
  1622. break;
  1623. }
  1624. }
  1625. // Make sure there were no file errors or format errors . . .
  1626. if (!pFile->Error() && sResult == 0)
  1627. {
  1628. // Init dude
  1629. sResult = Init();
  1630. }
  1631. else
  1632. {
  1633. sResult = -1;
  1634. TRACE("CDude::Load(): Error reading from file!\n");
  1635. }
  1636. }
  1637. else
  1638. {
  1639. TRACE("CDude::Load(): CCharacter::Load() failed.\n");
  1640. }
  1641. return sResult;
  1642. }
  1643. ////////////////////////////////////////////////////////////////////////////////
  1644. // Save object (should call base class version!)
  1645. ////////////////////////////////////////////////////////////////////////////////
  1646. short CDude::Save( // Returns 0 if successfull, non-zero otherwise
  1647. RFile* pFile, // In: File to save to
  1648. short sFileCount) // In: File count (unique per file, never 0)
  1649. {
  1650. short sResult = 0;
  1651. // In most cases, the base class Save() should be called.
  1652. sResult = CCharacter::Save(pFile, sFileCount);
  1653. if (sResult == 0)
  1654. {
  1655. // Save common data just once per file (not with each object)
  1656. if (ms_sFileCount != sFileCount)
  1657. {
  1658. ms_sFileCount = sFileCount;
  1659. // Save static data.
  1660. pFile->Write(&ms_dAccUser);
  1661. pFile->Write(&ms_dAccDrag);
  1662. pFile->Write(&ms_dMaxVelFore);
  1663. pFile->Write(&ms_dMaxVelBack);
  1664. pFile->Write(&ms_dMaxVelForeFast);
  1665. pFile->Write(&ms_dMaxVelBackFast);
  1666. pFile->Write(&ms_dDegPerSec);
  1667. }
  1668. // Save object data.
  1669. sResult = pFile->Error();
  1670. }
  1671. else
  1672. {
  1673. TRACE("CDude::Save(): CCharacter::Save() failed.\n");
  1674. }
  1675. return sResult;
  1676. }
  1677. ////////////////////////////////////////////////////////////////////////////////
  1678. // Startup object
  1679. ////////////////////////////////////////////////////////////////////////////////
  1680. short CDude::Startup(void) // Returns 0 if successfull, non-zero otherwise
  1681. {
  1682. short sResult = CCharacter::Startup();
  1683. // Init other stuff
  1684. m_lNextBulletTime = m_pRealm->m_time.GetGameTime() + MS_BETWEEN_BULLETS;
  1685. // Set start position for crawler verification.
  1686. m_dLastCrawledToPosX = m_dX;
  1687. m_dLastCrawledToPosZ = m_dZ;
  1688. return sResult;
  1689. }
  1690. ////////////////////////////////////////////////////////////////////////////////
  1691. // Shutdown object
  1692. ////////////////////////////////////////////////////////////////////////////////
  1693. short CDude::Shutdown(void) // Returns 0 if successfull, non-zero otherwise
  1694. {
  1695. short sResult = CCharacter::Shutdown();
  1696. return sResult;
  1697. }
  1698. ////////////////////////////////////////////////////////////////////////////////
  1699. // Suspend object
  1700. ////////////////////////////////////////////////////////////////////////////////
  1701. void CDude::Suspend(void)
  1702. {
  1703. if (m_sSuspend == 0)
  1704. {
  1705. // Store current delta so we can restore it.
  1706. long lCurTime = m_pRealm->m_time.GetGameTime();
  1707. m_lNextBulletTime = lCurTime - m_lNextBulletTime;
  1708. }
  1709. CCharacter::Suspend();
  1710. }
  1711. ////////////////////////////////////////////////////////////////////////////////
  1712. // Resume object
  1713. ////////////////////////////////////////////////////////////////////////////////
  1714. void CDude::Resume(void)
  1715. {
  1716. CCharacter::Resume();
  1717. if (m_sSuspend == 0)
  1718. {
  1719. long lCurTime = m_pRealm->m_time.GetGameTime();
  1720. m_lNextBulletTime = lCurTime - m_lNextBulletTime;
  1721. }
  1722. }
  1723. ////////////////////////////////////////////////////////////////////////////////
  1724. // Update object
  1725. ////////////////////////////////////////////////////////////////////////////////
  1726. void CDude::Update(void)
  1727. {
  1728. if (!m_sSuspend)
  1729. {
  1730. // Get new time
  1731. long lThisTime = m_pRealm->m_time.GetGameTime();
  1732. // Advance the animation timer.
  1733. long lDifTime = lThisTime - m_lAnimPrevUpdateTime;
  1734. m_lAnimTime += lDifTime;
  1735. // Update prev time.
  1736. m_lAnimPrevUpdateTime = lThisTime;
  1737. // Process Input ////////////////////////////////////////////////////////
  1738. double dMaxForeVel;
  1739. double dMaxBackVel;
  1740. short sStrafeAngle = INVALID_STRAFE_ANGLE; // Angle of motion from strafing.
  1741. ProcessInput(
  1742. &dMaxForeVel,
  1743. &dMaxBackVel,
  1744. &sStrafeAngle
  1745. );
  1746. // Process Forces ///////////////////////////////////////////////////////
  1747. switch (m_state)
  1748. {
  1749. case State_BlownUp:
  1750. break;
  1751. default:
  1752. ProcessForces(
  1753. lThisTime,
  1754. dMaxForeVel,
  1755. dMaxBackVel,
  1756. sStrafeAngle);
  1757. break;
  1758. }
  1759. // Specific transitions by state dependent on motion ////////////////////
  1760. switch (m_state)
  1761. {
  1762. default: // Catch all. Go to idle if NYI state.
  1763. case State_Idle:
  1764. break;
  1765. case State_Dead:
  1766. case State_Strafe:
  1767. case State_StrafeAndShoot:
  1768. case State_Stand:
  1769. case State_Shooting:
  1770. // If there's any movement . . .
  1771. if (m_dAcc != 0.0)
  1772. {
  1773. // Move to running.
  1774. switch (m_state)
  1775. {
  1776. case State_Stand:
  1777. case State_Strafe:
  1778. SetState(State_Run);
  1779. break;
  1780. case State_StrafeAndShoot:
  1781. case State_Shooting:
  1782. SetState(State_RunAndShoot);
  1783. break;
  1784. }
  1785. }
  1786. else
  1787. {
  1788. // If there's strafe motion . . .
  1789. if (sStrafeAngle != INVALID_STRAFE_ANGLE)
  1790. {
  1791. switch (m_state)
  1792. {
  1793. case State_Stand:
  1794. SetState(State_Strafe);
  1795. break;
  1796. case State_Shooting:
  1797. SetState(State_StrafeAndShoot);
  1798. break;
  1799. case State_Strafe:
  1800. case State_StrafeAndShoot:
  1801. break;
  1802. }
  1803. }
  1804. else
  1805. {
  1806. switch (m_state)
  1807. {
  1808. case State_Stand:
  1809. case State_Shooting:
  1810. break;
  1811. case State_Strafe:
  1812. SetState(State_Stand);
  1813. break;
  1814. case State_StrafeAndShoot:
  1815. SetState(State_Shooting);
  1816. break;
  1817. }
  1818. }
  1819. }
  1820. break;
  1821. case State_Burning:
  1822. {
  1823. // Tweak out.
  1824. m_dRot = rspMod360(m_dRot + RAND_SWAY(ON_FIRE_ROT_TWEAKAGE) );
  1825. m_dVel += RAND_SWAY(ON_FIRE_VEL_TWEAKAGE) + ON_FIRE_VEL_TWEAKAGE / 4; // **FUDGE**
  1826. }
  1827. // Intentional fall through.
  1828. case State_Run:
  1829. case State_RunAndShoot:
  1830. // If there's little movement . . .
  1831. if ((m_dVel < MIN_RUN_VEL && m_dVel > -MIN_RUN_VEL && m_dAcc == 0.0))
  1832. {
  1833. // If not strafing . . .
  1834. if (sStrafeAngle == INVALID_STRAFE_ANGLE)
  1835. {
  1836. // Move to standing.
  1837. switch (m_state)
  1838. {
  1839. case State_Run:
  1840. SetState(State_Stand);
  1841. break;
  1842. case State_RunAndShoot:
  1843. SetState(State_Shooting);
  1844. break;
  1845. case State_Burning:
  1846. break;
  1847. }
  1848. }
  1849. else // We are strafing in some way.
  1850. {
  1851. // Move to standing.
  1852. switch (m_state)
  1853. {
  1854. case State_Run:
  1855. SetState(State_Strafe);
  1856. break;
  1857. case State_RunAndShoot:
  1858. SetState(State_StrafeAndShoot);
  1859. break;
  1860. case State_Burning:
  1861. break;
  1862. }
  1863. }
  1864. }
  1865. else
  1866. {
  1867. if (GetInput(m_sDudeNum) & INPUT_RUN)
  1868. {
  1869. if (StatsAreAllowed)
  1870. {
  1871. Stat_TimeRunning += lDifTime;
  1872. if (Stat_TimeRunning >= (60 * 5 * 1000))
  1873. UnlockAchievement(ACHIEVEMENT_RUN_5_MINUTES);
  1874. }
  1875. }
  1876. }
  1877. break;
  1878. case State_Throw:
  1879. case State_ThrowRelease:
  1880. case State_ThrowDone:
  1881. case State_ThrowFinish:
  1882. case State_Launch:
  1883. case State_LaunchRelease:
  1884. case State_LaunchDone:
  1885. case State_LaunchFinish:
  1886. // Let's just say you can't move while throwing/launching.
  1887. m_dVel = 0.0;
  1888. m_dAcc = 0.0;
  1889. m_dDrag = 0.0;
  1890. break;
  1891. }
  1892. // Service message queue ////////////////////////////////////////////////
  1893. ProcessMessages();
  1894. // Switch on state.
  1895. switch (m_state)
  1896. {
  1897. case State_Stand:
  1898. {
  1899. #if 1 // No idle anim currently.
  1900. // If we've been idle for a while . . .
  1901. if (m_lAnimTime > m_lNextIdleTime)
  1902. {
  1903. // Toggle anim.
  1904. if (m_panimCur == &m_animStand)
  1905. {
  1906. // Switch to idle.
  1907. m_panimCur = &m_animIdle;
  1908. // Set next timeout.
  1909. m_lNextIdleTime = m_animIdle.m_psops->TotalTime() * IDLE_ANIM_LOOPS;
  1910. }
  1911. else
  1912. {
  1913. // Switch to stand.
  1914. m_panimCur = &m_animStand;
  1915. // Set next timeout.
  1916. m_lNextIdleTime = IDLE_ANIM_TIMEOUT;
  1917. }
  1918. // Reset anim timer.
  1919. m_lAnimTime = 0;
  1920. m_lAnimPrevUpdateTime = lThisTime;
  1921. }
  1922. #endif
  1923. break;
  1924. }
  1925. case State_Throw:
  1926. {
  1927. #if 1
  1928. U8 u8Event = *( (U8*)(m_panimCur->m_pevent->GetAtTime(m_lAnimTime) ) );
  1929. // Check for release point in animation . . .
  1930. if (u8Event > 0)
  1931. {
  1932. CWeapon* pweapon;
  1933. if (m_pRealm->m_idbank.GetThingByID((CThing**)&pweapon, m_u16IdWeapon) == 0)
  1934. {
  1935. if (pweapon->m_eState == CWeapon::State_Hide)
  1936. {
  1937. // Unhide grenade.
  1938. pweapon->m_eState = CWeapon::State_Idle;
  1939. }
  1940. else if (u8Event > 1)
  1941. {
  1942. // Release projectile.
  1943. // Go to State_ThrowRelease which is purely transitional to State_ThrowFinish.
  1944. SetState(State_ThrowRelease);
  1945. }
  1946. }
  1947. else
  1948. {
  1949. if (u8Event > 1)
  1950. {
  1951. // Release projectile.
  1952. // Go to State_ThrowRelease which is purely transitional to State_ThrowFinish.
  1953. SetState(State_ThrowRelease);
  1954. }
  1955. }
  1956. }
  1957. #else
  1958. if (WhileHoldingWeapon(
  1959. COLLISION_BITS_INCLUDE,
  1960. COLLISION_BITS_DONTCARE,
  1961. COLLISION_BITS_EXCLUDE) == true)
  1962. {
  1963. // Go to State_ThrowFinish.
  1964. SetState(State_ThrowFinish);
  1965. }
  1966. #endif
  1967. break;
  1968. }
  1969. case State_ThrowRelease:
  1970. {
  1971. ShootWeapon();
  1972. // Finish animation.
  1973. SetState(State_ThrowFinish);
  1974. break;
  1975. }
  1976. case State_ThrowDone:
  1977. case State_LaunchDone:
  1978. // Move on.
  1979. SetState(State_Persistent);
  1980. break;
  1981. case State_LaunchRelease:
  1982. {
  1983. ShootWeapon();
  1984. // Finish animation.
  1985. SetState(State_LaunchFinish);
  1986. break;
  1987. }
  1988. case State_ThrowFinish:
  1989. // Check for end of throw animation.
  1990. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  1991. {
  1992. // This will let us know to be done with throwing on the next Update.
  1993. SetState(State_ThrowDone);
  1994. }
  1995. break;
  1996. case State_Run:
  1997. {
  1998. // Remove adjustment made above.
  1999. m_lAnimTime -= lDifTime;
  2000. // Tune the time. Note that this is automathematically negative when
  2001. // velocity is negative.
  2002. long lDifAnimTime = lDifTime * (m_dVel / RUN_ANIM_VELOCITY);
  2003. m_lAnimTime += lDifAnimTime;
  2004. // Play step noise if event has changed.
  2005. PlayStep();
  2006. break;
  2007. }
  2008. case State_RunAndShoot:
  2009. {
  2010. // Remove adjustment made above.
  2011. m_lAnimTime -= lDifTime;
  2012. // Tune the time. Note that this is automathematically negative when
  2013. // velocity is negative.
  2014. long lDifAnimTime = lDifTime * (m_dVel / RUN_ANIM_VELOCITY);
  2015. m_lAnimTime += lDifAnimTime;
  2016. // Play step noise if event has changed.
  2017. PlayStep();
  2018. if (lThisTime >= m_lNextBulletTime)
  2019. {
  2020. // Shoot.
  2021. ShootWeapon();
  2022. }
  2023. break;
  2024. }
  2025. case State_Shooting:
  2026. // If out of bullets . . .
  2027. if (m_stockpile.m_sNumBullets <= 0)
  2028. {
  2029. // Don't animate.
  2030. m_lAnimTime -= lDifTime;
  2031. }
  2032. if (lThisTime >= m_lNextBulletTime)
  2033. {
  2034. // Shoot.
  2035. ShootWeapon();
  2036. }
  2037. break;
  2038. case State_StrafeAndShoot:
  2039. // If going left of forwards . . .
  2040. if (m_dRot - sStrafeAngle < 0)
  2041. {
  2042. // Subtract twice the time to make up for fact that it was already added once above
  2043. m_lAnimTime -= lDifTime * 2;
  2044. }
  2045. // Play step noise if event has changed.
  2046. PlayStep();
  2047. if (lThisTime >= m_lNextBulletTime)
  2048. {
  2049. // Shoot.
  2050. ShootWeapon();
  2051. }
  2052. break;
  2053. case State_Strafe:
  2054. // If going left of forwards . . .
  2055. if (m_dRot - sStrafeAngle < 0)
  2056. {
  2057. // Subtract twice the time to make up for fact that it was already added once above
  2058. m_lAnimTime -= lDifTime * 2;
  2059. }
  2060. // Play step noise if event has changed.
  2061. PlayStep();
  2062. break;
  2063. case State_Shot:
  2064. // Check for end of damage animation . . .
  2065. // if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2066. // Instead check for minimum duration since last shot time . . .
  2067. if (lThisTime > m_lLastShotTime + MIN_SHOT_DURATION)
  2068. {
  2069. // Stand.
  2070. SetState(State_Persistent);
  2071. }
  2072. break;
  2073. case State_BlownUp:
  2074. // Check for end . . .
  2075. if (WhileBlownUp() == false)
  2076. {
  2077. SetState(State_GetUp);
  2078. }
  2079. break;
  2080. case State_Suicide:
  2081. // Check for moment of firing weapon . . .
  2082. if (*((U8*)(m_panimCur->m_pevent->GetAtTime(m_lAnimTime))) > 0
  2083. && m_bBrainSplatted == false) // ***FUDGE***
  2084. {
  2085. // Play shot fire.
  2086. PlaySample(g_smidShotgun, SampleMaster::Weapon);
  2087. // Play shot received.
  2088. PlaySample(g_smidDyingYell, SampleMaster::Voices);
  2089. // Start gore.
  2090. StartBrainSplat();
  2091. // Remember.
  2092. m_bBrainSplatted = true;
  2093. // Register the kill.
  2094. ScoreRegisterKill(m_pRealm, GetInstanceID(), m_u16InstanceId);
  2095. // Note that he's dead
  2096. m_bDead = true;
  2097. }
  2098. // Intentional fall through to State_Die.
  2099. case State_Die:
  2100. // Check for end of die animation . . .
  2101. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2102. {
  2103. // Make sure we're dead for reals. Do this before the SetState()
  2104. // so we doesn't end up dropping any health.
  2105. m_stockpile.m_sHitPoints = 0;
  2106. // Go to dead.
  2107. SetState(State_Dead);
  2108. // If he is carying the flag item, then he should drop it.
  2109. DropAllFlags(NULL);
  2110. }
  2111. else if (m_bGenericEvent1 == false)
  2112. {
  2113. U8 u8Event = *( (U8*)(m_panimCur->m_pevent->GetAtTime(m_lAnimTime) ) );
  2114. if (u8Event > 1) // ***FUDGE***
  2115. {
  2116. PlaySample(g_smidBodyImpact2, SampleMaster::Unspecified);
  2117. m_bGenericEvent1 = true;
  2118. }
  2119. }
  2120. break;
  2121. case State_Burning:
  2122. {
  2123. // Play step noise if event has changed.
  2124. PlayStep();
  2125. CThing* pthingFire;
  2126. // If the fire's gone . . .
  2127. if (m_pRealm->m_idbank.GetThingByID(&pthingFire, m_u16IdFire) == 0)
  2128. {
  2129. if (!((CFire*) (pthingFire))->IsBurning())
  2130. // Stand.
  2131. SetState(State_Stand);
  2132. }
  2133. else
  2134. {
  2135. // Stand.
  2136. SetState(State_Stand);
  2137. }
  2138. break;
  2139. }
  2140. case State_Launch:
  2141. #if 0
  2142. {
  2143. U8 u8Event = *( (U8*)(m_panimCur->m_pevent->GetAtTime(m_lAnimTime) ) );
  2144. // Check for launch point in animation . . .
  2145. if (u8Event > 0)
  2146. {
  2147. CWeapon* pweapon;
  2148. if (m_pRealm->m_idbank.GetThingByID((CThing**)&pweapon, m_u16IdWeapon) == 0)
  2149. {
  2150. if (pweapon->m_eState == CWeapon::State_Hide)
  2151. {
  2152. // Unhide missile.
  2153. pweapon->m_eState = CWeapon::State_Idle;
  2154. }
  2155. else if (u8Event > 1)
  2156. {
  2157. // Release missile.
  2158. // Go to State_LaunchRelase which is purely transitional to State_LaunchFinish.
  2159. SetState(State_LaunchRelease);
  2160. }
  2161. }
  2162. else
  2163. {
  2164. if (u8Event > 1)
  2165. {
  2166. // Release missile.
  2167. // Go to State_LaunchRelase which is purely transitional to State_LaunchFinish.
  2168. SetState(State_LaunchRelease);
  2169. }
  2170. }
  2171. }
  2172. }
  2173. #else
  2174. if (WhileHoldingWeapon(
  2175. COLLISION_BITS_INCLUDE,
  2176. COLLISION_BITS_DONTCARE,
  2177. COLLISION_BITS_EXCLUDE) == true)
  2178. {
  2179. // Go to State_LaunchFinish.
  2180. SetState(State_LaunchFinish);
  2181. }
  2182. #endif
  2183. break;
  2184. case State_LaunchFinish:
  2185. // Check for end of launch animation . . .
  2186. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2187. {
  2188. // Go to State_LaunchDone which is purely transitional to State_Stand.
  2189. SetState(State_LaunchDone);
  2190. }
  2191. break;
  2192. case State_GetUp:
  2193. // check for end of getup anim . . .
  2194. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2195. {
  2196. // Go to last persistent state. Usually stand.
  2197. SetState(State_Persistent);
  2198. }
  2199. break;
  2200. case State_Rise:
  2201. // check for end of rise anim . . .
  2202. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2203. {
  2204. // Go to last persistent state. Usually stand.
  2205. SetState(State_Persistent);
  2206. }
  2207. break;
  2208. case State_Jump:
  2209. case State_JumpForward:
  2210. if (m_lAnimTime > 750 && m_bJumpVerticalTrigger == false)
  2211. {
  2212. // Go up.
  2213. m_dExtVertVel = ms_dVertVelJump;
  2214. m_bJumpVerticalTrigger = true;
  2215. }
  2216. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2217. {
  2218. // Go to fall state.
  2219. SetState(State_Fall);
  2220. }
  2221. else
  2222. {
  2223. break;
  2224. }
  2225. // Intentional fall through to State_Fall.
  2226. case State_Fall:
  2227. // If we've reached the ground . . .
  2228. if (m_bAboveTerrain == false)
  2229. {
  2230. // Go to land state.
  2231. SetState((m_dVel == 0.0) ? State_Land : State_LandForward);
  2232. }
  2233. break;
  2234. case State_Land:
  2235. case State_LandForward:
  2236. // Return to last persistent state.
  2237. SetState(State_Persistent);
  2238. break;
  2239. case State_Execute:
  2240. // check for end of execute anim . . .
  2241. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2242. {
  2243. // Go to last persistent state. Usually stand.
  2244. SetState(State_Persistent);
  2245. UnlockAchievement(ACHIEVEMENT_PERFORM_FIRST_EXECUTION);
  2246. if (StatsAreAllowed) Stat_Executions++;
  2247. }
  2248. // If before point of firing . . .
  2249. else if (m_lAnimTime < 1350) // ***FUDGE***.
  2250. {
  2251. // Track executee. If we lost 'em . . .
  2252. if (TrackExecutee(lDifTime / 1000.0) == false)
  2253. {
  2254. // Go to last persistent state. Usually stand.
  2255. SetState(State_Persistent);
  2256. }
  2257. }
  2258. // If in point of firing . . .
  2259. else if (m_lAnimTime < 1950) // ***FUDGE***.
  2260. {
  2261. #if 1
  2262. if (lThisTime >= m_lNextBulletTime)
  2263. {
  2264. OnExecute();
  2265. }
  2266. #else
  2267. if (lThisTime >= m_lNextBulletTime)
  2268. {
  2269. ArmWeapon(SemiAutomatic);
  2270. ShootWeapon();
  2271. }
  2272. #endif
  2273. }
  2274. break;
  2275. case State_PutDown:
  2276. #if 0
  2277. // Check for end of anim . . .
  2278. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2279. {
  2280. // Go to last persistent state. Usually stand.
  2281. SetState(State_Persistent);
  2282. }
  2283. else
  2284. {
  2285. U8 u8Event = *( (U8*)(m_panimCur->m_pevent->GetAtTime(m_lAnimTime) ) );
  2286. // Check for show point in anim . . .
  2287. if (u8Event > 0)
  2288. {
  2289. // Check for drop point in animation . . .
  2290. if (u8Event > 1)
  2291. {
  2292. if (m_u16IdWeapon != CIdBank::IdNil)
  2293. {
  2294. ShootWeapon();
  2295. }
  2296. }
  2297. }
  2298. #else
  2299. if (WhileHoldingWeapon(
  2300. COLLISION_BITS_INCLUDE,
  2301. COLLISION_BITS_DONTCARE,
  2302. COLLISION_BITS_EXCLUDE) == true)
  2303. {
  2304. // Go to State_ObjectReleased.
  2305. SetState(State_ObjectReleased);
  2306. }
  2307. break;
  2308. case State_ObjectReleased:
  2309. // Check for end of anim . . .
  2310. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2311. {
  2312. // Go to last persistent state. Usually stand.
  2313. SetState(State_Persistent);
  2314. }
  2315. #endif
  2316. break;
  2317. case State_PickUp:
  2318. {
  2319. CPowerUp* ppowerup;
  2320. // Check for end of anim . . .
  2321. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  2322. {
  2323. // If we still have the picked up item . . .
  2324. if (m_pRealm->m_idbank.GetThingByID((CThing**)&ppowerup, m_u16IdChild) == 0)
  2325. {
  2326. TakePowerUp(&ppowerup);
  2327. m_u16IdChild = CIdBank::IdNil;
  2328. }
  2329. // Go to last persistent state. Usually stand.
  2330. SetState(State_Persistent);
  2331. }
  2332. else if (m_lAnimTime > 500 && m_bGenericEvent1 == false)
  2333. {
  2334. // This should be QuickCheckClosest, when available . . .
  2335. CSmash* psmash = NULL; // Safety.
  2336. if (m_pRealm->m_smashatorium.QuickCheck( // Returns true if collision detected, false otherwise
  2337. &m_smash, // In: CSmash to check
  2338. CSmash::PowerUp, // In: Bits that must be 1 to collide with a given CSmash
  2339. 0, // In: Bits that you don't care about
  2340. 0, // In: Bits that must be 0 to collide with a given CSmash
  2341. &psmash) == true) // Out: Thing being smashed into if any (unless 0)
  2342. {
  2343. ASSERT(psmash->m_pThing != NULL);
  2344. // Make it blit as a child.
  2345. ASSERT(psmash->m_pThing->GetClassID() == CPowerUpID);
  2346. ppowerup = (CPowerUp*)psmash->m_pThing;
  2347. if (ppowerup->Grab(&m_sprite) == 0)
  2348. {
  2349. // Store/Identify child.
  2350. m_u16IdChild = ppowerup->GetInstanceID();
  2351. }
  2352. // Note we already did this.
  2353. m_bGenericEvent1 = true;
  2354. }
  2355. }
  2356. else if (m_pRealm->m_idbank.GetThingByID((CThing**)&ppowerup, m_u16IdChild) == 0)
  2357. {
  2358. // Position powerup.
  2359. PositionChild(
  2360. &(ppowerup->m_sprite), // In: Child sprite to detach.
  2361. (RTransform*) m_panimCur->m_ptransRigid->GetAtTime(m_lAnimTime), // In: Transform specifying position.
  2362. &(ppowerup->m_dX), // Out: New position of child.
  2363. &(ppowerup->m_dY), // Out: New position of child.
  2364. &(ppowerup->m_dZ) ); // Out: New position of child.
  2365. }
  2366. break;
  2367. }
  2368. }
  2369. // Update sphere.
  2370. m_smash.m_sphere.sphere.X = m_dX;
  2371. // Fudge center of sphere as half way up the dude.
  2372. // Doesn't work if dude's feet leave the origin.
  2373. m_smash.m_sphere.sphere.Y = m_dY + m_sprite.m_sRadius;
  2374. m_smash.m_sphere.sphere.Z = m_dZ;
  2375. m_smash.m_sphere.sphere.lRadius = m_sprite.m_sRadius;
  2376. // Update the smash.
  2377. m_pRealm->m_smashatorium.Update(&m_smash);
  2378. // Check for powerups.
  2379. CSmash* psmash = NULL; // Safety.
  2380. if (m_pRealm->m_smashatorium.QuickCheck( // Returns true if collision detected, false otherwise
  2381. &m_smash, // In: CSmash to check
  2382. CSmash::PowerUp, // In: Bits that must be 1 to collide with a given CSmash
  2383. 0, // In: Bits that you don't care about
  2384. 0, // In: Bits that must be 0 to collide with a given CSmash
  2385. &psmash) == true) // Out: Thing being smashed into if any (unless 0)
  2386. {
  2387. ASSERT(psmash->m_pThing != NULL);
  2388. ASSERT(psmash->m_pThing->GetClassID() == CPowerUpID);
  2389. CPowerUp* ppowerup = (CPowerUp*)psmash->m_pThing;
  2390. // If we're not dead or the powerup contains health . . .
  2391. if (m_bDead == false || ppowerup->m_stockpile.m_sHitPoints > 0)
  2392. {
  2393. TakePowerUp(&ppowerup);
  2394. }
  2395. }
  2396. // Save time for next time
  2397. m_lPrevTime = lThisTime;
  2398. // Call the targeting aid function
  2399. ShowTarget();
  2400. // Call base class //////////////////////////////////////////////////////
  2401. CCharacter::Update();
  2402. // If requested to delete self . . .
  2403. if (m_state == State_Delete)
  2404. {
  2405. // Good bye.
  2406. delete this;
  2407. }
  2408. }
  2409. }
  2410. ////////////////////////////////////////////////////////////////////////////////
  2411. // Attempts user motivated state transitions.
  2412. ////////////////////////////////////////////////////////////////////////////////
  2413. void CDude::ProcessInput( // Returns nothing.
  2414. double* pdMaxForeVel, // Out: Maximum forward velocity.
  2415. double* pdMaxBackVel, // Out: Maximum backward velocity.
  2416. short* psStrafeAngle) // Out: Strafe angle.
  2417. {
  2418. UINPUT input = 0;
  2419. // Get user input
  2420. input = GetInput(m_sDudeNum);
  2421. bool bCanMove = true; // Flags for twinstick input so they don't override death, etc. states
  2422. bool bCanFire = true;
  2423. switch (m_state)
  2424. {
  2425. case State_Dead:
  2426. // Let's take jump as 'revive' . . .
  2427. if (input & INPUT_REVIVE)
  2428. {
  2429. // It's alive; alive!
  2430. Revive();
  2431. }
  2432. // Allow only one input (life cheat) . . .
  2433. if ( (input & INPUT_WEAPONS_MASK) == INPUT_CHEAT_15)
  2434. {
  2435. input = INPUT_CHEAT_15;
  2436. }
  2437. else
  2438. {
  2439. // No other user control during these states.
  2440. input = 0;
  2441. bCanMove = false;
  2442. bCanFire = false;
  2443. }
  2444. break;
  2445. case State_Die:
  2446. case State_Suicide:
  2447. // No user control during these states.
  2448. input = 0;
  2449. bCanMove = false;
  2450. bCanFire = false;
  2451. break;
  2452. case State_BlownUp:
  2453. case State_Rise:
  2454. case State_GetUp:
  2455. case State_PutDown:
  2456. case State_ObjectReleased:
  2457. case State_PickUp:
  2458. // No user control during these states other than to change weapon.
  2459. input &= INPUT_WEAPONS_MASK;
  2460. bCanMove = false;
  2461. bCanFire = false;
  2462. break;
  2463. case State_Throw:
  2464. case State_ThrowRelease:
  2465. case State_ThrowDone:
  2466. case State_ThrowFinish:
  2467. case State_Launch:
  2468. case State_LaunchRelease:
  2469. case State_LaunchDone:
  2470. case State_LaunchFinish:
  2471. //case State_Shot:
  2472. // No influence on velocity during these states.
  2473. input &= ~(INPUT_FORWARD | INPUT_BACKWARD | INPUT_REVIVE | INPUT_DUCK | INPUT_MOVE_UP | INPUT_MOVE_DOWN | INPUT_MOVE_LEFT | INPUT_MOVE_RIGHT);
  2474. bCanMove = false;
  2475. bCanFire = false;
  2476. break;
  2477. case State_Execute:
  2478. case State_Duck:
  2479. // No rotation or jumping.
  2480. input &= ~(INPUT_LEFT | INPUT_RIGHT | INPUT_REVIVE | INPUT_ROT_MASK | INPUT_FORWARD | INPUT_BACKWARD | INPUT_MOVE_UP | INPUT_MOVE_DOWN | INPUT_MOVE_LEFT | INPUT_MOVE_RIGHT);
  2481. bCanMove = false;
  2482. bCanFire = false;
  2483. break;
  2484. }
  2485. // Change weapon . . .
  2486. WeaponType wtNew = m_weapontypeCur;
  2487. switch (input & INPUT_WEAPONS_MASK)
  2488. {
  2489. case INPUT_WEAPON_1:
  2490. case INPUT_WEAPON_2:
  2491. case INPUT_WEAPON_3:
  2492. case INPUT_WEAPON_4:
  2493. case INPUT_WEAPON_5:
  2494. //#ifdef MOBILE //We want weapon 5 to toggle weapon
  2495. if (!demoCompat)
  2496. {
  2497. if (((input & INPUT_WEAPONS_MASK) == INPUT_WEAPON_5)
  2498. && (m_weapontypeCur == Rocket))
  2499. {
  2500. wtNew = Heatseeker;
  2501. break;
  2502. }
  2503. }
  2504. //#endif
  2505. case INPUT_WEAPON_6:
  2506. case INPUT_WEAPON_7:
  2507. case INPUT_WEAPON_8:
  2508. case INPUT_WEAPON_9:
  2509. wtNew = (WeaponType)(NoWeapon + ( ( (input & INPUT_WEAPONS_MASK) - INPUT_WEAPON_0) >> INPUT_WEAPONS_BIT) );
  2510. break;
  2511. case INPUT_WEAPON_0:
  2512. switch (m_weapontypeCur)
  2513. {
  2514. case NoWeapon:
  2515. if (m_stockpile.m_sDeathWadLauncher)
  2516. {
  2517. wtNew = DeathWad;
  2518. break;
  2519. }
  2520. case DeathWad:
  2521. if (m_stockpile.m_sDoubleBarrel)
  2522. {
  2523. wtNew = DoubleBarrel;
  2524. break;
  2525. }
  2526. case DoubleBarrel:
  2527. default:
  2528. wtNew = NoWeapon;
  2529. break;
  2530. }
  2531. break;
  2532. case INPUT_WEAPON_10:
  2533. switch (m_weapontypeCur)
  2534. {
  2535. default:
  2536. wtNew = ProximityMine;
  2537. break;
  2538. case ProximityMine:
  2539. wtNew = TimedMine;
  2540. break;
  2541. case TimedMine:
  2542. #if 0 // Remote mines are not very useful currently.
  2543. wtNew = RemoteMine;
  2544. break;
  2545. case RemoteMine:
  2546. #endif
  2547. wtNew = BouncingBettyMine;
  2548. break;
  2549. }
  2550. break;
  2551. // 'Cheats' ////////////////////////////////////////////////////
  2552. case INPUT_CHEAT_11: // Restore health.
  2553. {
  2554. CStockPile stockpile = { 0, };
  2555. stockpile.m_sHitPoints = MAX(0, m_sOrigHitPoints - m_stockpile.m_sHitPoints);
  2556. CreateCheat(&stockpile);
  2557. break;
  2558. }
  2559. case INPUT_CHEAT_12: // Full kevlar.
  2560. {
  2561. CStockPile stockpile = { 0, };
  2562. stockpile.m_sKevlarLayers = CStockPile::ms_stockpileBackPackMax.m_sKevlarLayers;
  2563. CreateCheat(&stockpile);
  2564. break;
  2565. }
  2566. case INPUT_CHEAT_13: // Backpack.
  2567. {
  2568. CStockPile stockpile = { 0, };
  2569. stockpile.m_sBackpack = 1;
  2570. CreateCheat(&stockpile);
  2571. break;
  2572. }
  2573. case INPUT_CHEAT_14: // Full weaponry, full ammo, backpack, and full kevlar.
  2574. {
  2575. CStockPile stockpile = { 0, };
  2576. stockpile.m_sHitPoints = MAX(0, m_sOrigHitPoints - m_stockpile.m_sHitPoints);
  2577. stockpile.m_sNumGrenades = CStockPile::ms_stockpileBackPackMax.m_sNumGrenades;
  2578. stockpile.m_sNumFireBombs = CStockPile::ms_stockpileBackPackMax.m_sNumFireBombs;
  2579. stockpile.m_sNumMissiles = CStockPile::ms_stockpileBackPackMax.m_sNumMissiles;
  2580. stockpile.m_sNumNapalms = CStockPile::ms_stockpileBackPackMax.m_sNumNapalms;
  2581. stockpile.m_sNumBullets = CStockPile::ms_stockpileBackPackMax.m_sNumBullets;
  2582. stockpile.m_sNumShells = CStockPile::ms_stockpileBackPackMax.m_sNumShells;
  2583. stockpile.m_sNumMines = CStockPile::ms_stockpileBackPackMax.m_sNumMines;
  2584. stockpile.m_sNumHeatseekers = CStockPile::ms_stockpileBackPackMax.m_sNumHeatseekers;
  2585. stockpile.m_sNumFuel = CStockPile::ms_stockpileBackPackMax.m_sNumFuel;
  2586. stockpile.m_sMachineGun = 1;
  2587. stockpile.m_sMissileLauncher = 1;
  2588. stockpile.m_sShotGun = 1;
  2589. stockpile.m_sSprayCannon = 1;
  2590. stockpile.m_sFlameThrower = 1;
  2591. stockpile.m_sNapalmLauncher = 1;
  2592. stockpile.m_sKevlarLayers = CStockPile::ms_stockpileMax.m_sKevlarLayers;
  2593. stockpile.m_sBackpack = 1;
  2594. CreateCheat(&stockpile);
  2595. break;
  2596. }
  2597. case INPUT_CHEAT_15: // Revive.
  2598. {
  2599. UnlockAchievement(ACHIEVEMENT_ENABLE_CHEATS);
  2600. Flag_Achievements |= FLAG_USED_CHEATS;
  2601. Revive(false);
  2602. // Let the demon know they entered a cheat code
  2603. GameMessage msg;
  2604. msg.msg_Cheater.eType = typeCheater;
  2605. msg.msg_Cheater.sPriority = 0;
  2606. CThing* pDemon = m_pRealm->m_aclassHeads[CThing::CDemonID].GetNext();
  2607. if (pDemon)
  2608. SendThingMessage(&msg, pDemon);
  2609. break;
  2610. }
  2611. case INPUT_CHEAT_16: // DeathWadLauncher and ammo.
  2612. {
  2613. CStockPile stockpile = { 0, };
  2614. stockpile.m_sNumGrenades = CStockPile::ms_stockpileBackPackMax.m_sNumGrenades;
  2615. stockpile.m_sNumMissiles = CStockPile::ms_stockpileBackPackMax.m_sNumMissiles;
  2616. stockpile.m_sNumNapalms = CStockPile::ms_stockpileBackPackMax.m_sNumNapalms;
  2617. stockpile.m_sNumFuel = CStockPile::ms_stockpileBackPackMax.m_sNumFuel;
  2618. stockpile.m_sDeathWadLauncher = 1;
  2619. CreateCheat(&stockpile);
  2620. // Enable death wad launcher in editor as well.
  2621. CStockPile::ms_sEnableDeathWad = TRUE;
  2622. break;
  2623. }
  2624. case INPUT_CHEAT_17: // DoubleBarrel and shells.
  2625. {
  2626. CStockPile stockpile = { 0, };
  2627. stockpile.m_sNumShells = CStockPile::ms_stockpileBackPackMax.m_sNumShells;
  2628. stockpile.m_sDoubleBarrel = 1;
  2629. CreateCheat(&stockpile);
  2630. // Enable Double Barrel in editor as well.
  2631. CStockPile::ms_sEnableDoubleBarrel = TRUE;
  2632. break;
  2633. }
  2634. case INPUT_CHEAT_18: // Mighty Mouse mode.
  2635. {
  2636. UnlockAchievement(ACHIEVEMENT_ENABLE_CHEATS);
  2637. Flag_Achievements |= FLAG_USED_CHEATS;
  2638. // Modify hood's scale.
  2639. m_pRealm->m_phood->m_dScale3d -= 0.10;
  2640. // Let the hood setup the pipeline.
  2641. m_pRealm->m_phood->SetupPipeline();
  2642. break;
  2643. }
  2644. case INPUT_CHEAT_19: // Shell weapons and ammo.
  2645. {
  2646. CStockPile stockpile = { 0, };
  2647. stockpile.m_sNumShells = CStockPile::ms_stockpileBackPackMax.m_sNumShells;
  2648. stockpile.m_sShotGun = 1;
  2649. stockpile.m_sSprayCannon = 1;
  2650. CreateCheat(&stockpile);
  2651. break;
  2652. }
  2653. case INPUT_CHEAT_20: // Explosive weapons and ammo.
  2654. {
  2655. CStockPile stockpile = { 0, };
  2656. stockpile.m_sNumGrenades = CStockPile::ms_stockpileBackPackMax.m_sNumGrenades;
  2657. stockpile.m_sNumMissiles = CStockPile::ms_stockpileBackPackMax.m_sNumMissiles;
  2658. stockpile.m_sNumHeatseekers = CStockPile::ms_stockpileBackPackMax.m_sNumHeatseekers;
  2659. stockpile.m_sMissileLauncher = 1;
  2660. CreateCheat(&stockpile);
  2661. break;
  2662. }
  2663. case INPUT_CHEAT_21: // Flame weapons and ammo.
  2664. {
  2665. CStockPile stockpile = { 0, };
  2666. stockpile.m_sNumFireBombs = CStockPile::ms_stockpileBackPackMax.m_sNumFireBombs;
  2667. stockpile.m_sNumNapalms = CStockPile::ms_stockpileBackPackMax.m_sNumNapalms;
  2668. stockpile.m_sNumFuel = CStockPile::ms_stockpileBackPackMax.m_sNumFuel;
  2669. stockpile.m_sNapalmLauncher = 1;
  2670. stockpile.m_sFlameThrower = 1;
  2671. CreateCheat(&stockpile);
  2672. break;
  2673. }
  2674. case INPUT_CHEAT_22: // Shotgun and shells.
  2675. {
  2676. CStockPile stockpile = { 0, };
  2677. stockpile.m_sNumShells = CStockPile::ms_stockpileBackPackMax.m_sNumShells;
  2678. stockpile.m_sShotGun = 1;
  2679. CreateCheat(&stockpile);
  2680. break;
  2681. }
  2682. case INPUT_CHEAT_23: // Spray cannon and shells.
  2683. {
  2684. CStockPile stockpile = { 0, };
  2685. stockpile.m_sNumShells = CStockPile::ms_stockpileBackPackMax.m_sNumShells;
  2686. stockpile.m_sSprayCannon = 1;
  2687. CreateCheat(&stockpile);
  2688. break;
  2689. }
  2690. case INPUT_CHEAT_24: // Grenades and cocktails.
  2691. {
  2692. CStockPile stockpile = { 0, };
  2693. stockpile.m_sNumGrenades = CStockPile::ms_stockpileBackPackMax.m_sNumGrenades;
  2694. stockpile.m_sNumFireBombs = CStockPile::ms_stockpileBackPackMax.m_sNumFireBombs;
  2695. CreateCheat(&stockpile);
  2696. break;
  2697. }
  2698. case INPUT_CHEAT_25: // Missile launcher and missiles (including heatseekers).
  2699. {
  2700. CStockPile stockpile = { 0, };
  2701. stockpile.m_sNumMissiles = CStockPile::ms_stockpileBackPackMax.m_sNumMissiles;
  2702. stockpile.m_sNumHeatseekers = CStockPile::ms_stockpileBackPackMax.m_sNumHeatseekers;
  2703. stockpile.m_sMissileLauncher = 1;
  2704. CreateCheat(&stockpile);
  2705. break;
  2706. }
  2707. case INPUT_CHEAT_26: // Napalm launcher and napalm canisters.
  2708. {
  2709. CStockPile stockpile = { 0, };
  2710. stockpile.m_sNumNapalms = CStockPile::ms_stockpileBackPackMax.m_sNumNapalms;
  2711. stockpile.m_sNapalmLauncher = 1;
  2712. CreateCheat(&stockpile);
  2713. break;
  2714. }
  2715. case INPUT_CHEAT_27: // Flame thrower and fuel canisters.
  2716. {
  2717. CStockPile stockpile = { 0, };
  2718. stockpile.m_sNumFuel = CStockPile::ms_stockpileBackPackMax.m_sNumFuel;
  2719. stockpile.m_sFlameThrower = 1;
  2720. CreateCheat(&stockpile);
  2721. break;
  2722. }
  2723. case INPUT_CHEAT_28: // Mines.
  2724. {
  2725. CStockPile stockpile = { 0, };
  2726. stockpile.m_sNumMines = CStockPile::ms_stockpileBackPackMax.m_sNumMines;
  2727. CreateCheat(&stockpile);
  2728. break;
  2729. }
  2730. case INPUT_CHEAT_29: // Unused except for SALES demo.
  2731. {
  2732. #ifdef SALES_DEMO
  2733. CStockPile stockpile = { 0, };
  2734. stockpile.m_sHitPoints = MAX(0, m_sOrigHitPoints - m_stockpile.m_sHitPoints);
  2735. stockpile.m_sNumGrenades = CStockPile::ms_stockpileBackPackMax.m_sNumGrenades;
  2736. stockpile.m_sNumFireBombs = CStockPile::ms_stockpileBackPackMax.m_sNumFireBombs;
  2737. stockpile.m_sNumMissiles = CStockPile::ms_stockpileBackPackMax.m_sNumMissiles;
  2738. stockpile.m_sNumNapalms = CStockPile::ms_stockpileBackPackMax.m_sNumNapalms;
  2739. stockpile.m_sNumBullets = CStockPile::ms_stockpileBackPackMax.m_sNumBullets;
  2740. stockpile.m_sNumShells = CStockPile::ms_stockpileBackPackMax.m_sNumShells;
  2741. stockpile.m_sNumMines = CStockPile::ms_stockpileBackPackMax.m_sNumMines;
  2742. stockpile.m_sNumHeatseekers = CStockPile::ms_stockpileBackPackMax.m_sNumHeatseekers;
  2743. stockpile.m_sNumFuel = CStockPile::ms_stockpileBackPackMax.m_sNumFuel;
  2744. stockpile.m_sMachineGun = 1;
  2745. stockpile.m_sMissileLauncher = 1;
  2746. stockpile.m_sShotGun = 1;
  2747. stockpile.m_sSprayCannon = 1;
  2748. stockpile.m_sFlameThrower = 1;
  2749. stockpile.m_sNapalmLauncher = 1;
  2750. stockpile.m_sKevlarLayers = CStockPile::ms_stockpileMax.m_sKevlarLayers;
  2751. stockpile.m_sBackpack = 1;
  2752. CreateCheat(&stockpile);
  2753. // Also, make invincible.
  2754. m_bInvincible = true;
  2755. // Also, allow level advance.
  2756. g_bEnableLevelAdvanceWithoutGoal = true;
  2757. #endif
  2758. break;
  2759. }
  2760. case INPUT_CHEAT_30: // Toggle invincibility.
  2761. {
  2762. UnlockAchievement(ACHIEVEMENT_ENABLE_CHEATS);
  2763. Flag_Achievements |= FLAG_USED_CHEATS;
  2764. m_bInvincible = !m_bInvincible;
  2765. break;
  2766. }
  2767. }
  2768. // "Twinstick" style inputs.
  2769. if (!demoCompat)
  2770. {
  2771. if ((input & INPUT_MOVE_UP) || (input & INPUT_MOVE_DOWN) || (input & INPUT_MOVE_LEFT) || (input & INPUT_MOVE_RIGHT)
  2772. || (input & INPUT_FIRE_UP) || (input & INPUT_FIRE_DOWN) || (input & INPUT_FIRE_LEFT) || (input & INPUT_FIRE_RIGHT))
  2773. {
  2774. // Say we're using twinstick mode
  2775. m_bUseRotTS = true;
  2776. // Turn off the normal movement inputs if present
  2777. input &= ~(INPUT_FORWARD | INPUT_BACKWARD | INPUT_LEFT | INPUT_RIGHT);
  2778. // Determine movement direction
  2779. if (bCanMove)
  2780. {
  2781. if ((input & INPUT_MOVE_UP) || (input & INPUT_MOVE_DOWN) || (input & INPUT_MOVE_LEFT) || (input & INPUT_MOVE_RIGHT))
  2782. {
  2783. // Set up acceleration
  2784. m_dAcc = ms_dAccUser;
  2785. m_dDrag = 0;
  2786. // Say which direction we want to go
  2787. if (input & INPUT_MOVE_UP)
  2788. m_dRotTS = 90 + (input & INPUT_MOVE_LEFT ? 45 : 0) + (input & INPUT_MOVE_RIGHT ? -45 : 0);
  2789. else if (input & INPUT_MOVE_DOWN)
  2790. m_dRotTS = -90 + (input & INPUT_MOVE_LEFT ? -45 : 0) + (input & INPUT_MOVE_RIGHT ? 45 : 0);
  2791. else if (input & INPUT_MOVE_LEFT)
  2792. m_dRotTS = 180;
  2793. else if (input & INPUT_MOVE_RIGHT)
  2794. m_dRotTS = 0;
  2795. }
  2796. else
  2797. {
  2798. m_dAcc = 0;
  2799. if (m_dVel > 0)
  2800. m_dDrag = ms_dAccDrag;
  2801. else if (m_dVel < 0)
  2802. m_dDrag = -ms_dAccDrag;
  2803. }
  2804. }
  2805. // Determine fire direction
  2806. if (bCanFire)
  2807. {
  2808. if ((input & INPUT_FIRE_UP) || (input & INPUT_FIRE_DOWN) || (input & INPUT_FIRE_LEFT) || (input & INPUT_FIRE_RIGHT))
  2809. {
  2810. // Say we're firing our weapon
  2811. input |= INPUT_FIRE;
  2812. // Then point in the correct direction
  2813. if (input & INPUT_FIRE_UP)
  2814. m_dRot = 90 + (input & INPUT_FIRE_LEFT ? 45 : 0) + (input & INPUT_FIRE_RIGHT ? -45 : 0);
  2815. else if (input & INPUT_FIRE_DOWN)
  2816. m_dRot = -90 + (input & INPUT_FIRE_LEFT ? -45 : 0) + (input & INPUT_FIRE_RIGHT ? 45 : 0);
  2817. else if (input & INPUT_FIRE_LEFT)
  2818. m_dRot = 180;
  2819. else if (input & INPUT_FIRE_RIGHT)
  2820. m_dRot = 0;
  2821. }
  2822. else
  2823. // otherwise, point in the direction we're going
  2824. m_dRot = m_dRotTS;
  2825. }
  2826. }
  2827. //else
  2828. //m_bUseRotTS = false;
  2829. }
  2830. #ifdef ALLOW_TWINSTICK
  2831. if (!demoCompat)
  2832. {
  2833. GetDudeVelocity(&m_dJoyMoveVel, &m_dJoyMoveAngle);
  2834. if (!bCanMove)
  2835. m_dJoyMoveVel = 0;
  2836. m_dJoyFireAngle = 0.f;
  2837. m_bJoyFire = (bCanFire && GetDudeFireAngle(&m_dJoyFireAngle));
  2838. if (m_dJoyMoveVel > 0 || m_bJoyFire)
  2839. {
  2840. // Setup movement
  2841. if (m_dJoyMoveVel > 0)
  2842. {
  2843. // Say we're using twinstick mode
  2844. m_bUseRotTS = true;
  2845. // Turn off the normal movement inputs if present
  2846. input &= ~(INPUT_FORWARD | INPUT_BACKWARD | INPUT_LEFT | INPUT_RIGHT);
  2847. // Set up acceleration
  2848. m_dAcc = ms_dAccUser;
  2849. m_dDrag = 0;
  2850. // Say which direction we want to go
  2851. m_dRotTS = m_dJoyMoveAngle;
  2852. }
  2853. else
  2854. {
  2855. // Setup drag
  2856. m_dAcc = 0;
  2857. if (m_dVel > 0)
  2858. m_dDrag = ms_dAccDrag;
  2859. else if (m_dVel < 0)
  2860. m_dDrag = -ms_dAccDrag;
  2861. }
  2862. // Setup firing
  2863. if (m_bJoyFire)
  2864. {
  2865. // Say we're firing our weapon
  2866. //input |= INPUT_FIRE;
  2867. // Then point in the correct direction
  2868. m_dRot = m_dJoyFireAngle;
  2869. }
  2870. else
  2871. // otherwise, point in the direction we're going
  2872. m_dRot = m_dJoyMoveAngle;
  2873. }
  2874. }
  2875. #endif
  2876. //TRACE("TSD Acc %f MA %f AA %f Fire %i\n", m_dAcc, m_dRotTS, m_dRot, m_bJoyFire);
  2877. //TRACE("JoyVel %f JoyAngle %f Fire %i FireAngle %f\n", m_dJoyMoveVel, m_dJoyMoveAngle, m_bJoyFire, m_dJoyFireAngle);
  2878. //#ifdef MOBILE
  2879. if (!demoCompat)
  2880. {
  2881. //#endif // MOBILE
  2882. if (input & INPUT_WEAPON_NEXT)
  2883. {
  2884. input &= ~(INPUT_FIRE);
  2885. NextWeapon();
  2886. }
  2887. if (input & INPUT_WEAPON_PREV)
  2888. {
  2889. input &= ~(INPUT_FIRE);
  2890. PrevWeapon();
  2891. }
  2892. //#ifdef MOBILE
  2893. }
  2894. //#endif // MOBILE
  2895. // If a weapon key was pressed . . .
  2896. if (input & INPUT_WEAPONS_MASK)
  2897. {
  2898. // If weapon was available . . .
  2899. if (SetWeapon(wtNew) == true)
  2900. {
  2901. }
  2902. }
  2903. // See if the guy fires his weapon . . .
  2904. // Check for general weapon fire . . .
  2905. if (input & INPUT_FIRE)
  2906. {
  2907. // If not ducking . . .
  2908. if (m_state != State_Duck)
  2909. {
  2910. ArmWeapon();
  2911. }
  2912. else
  2913. {
  2914. // We should get up first.
  2915. SetState(State_Rise);
  2916. }
  2917. // Ducking is not a user option when rising for or firing.
  2918. input &= ~INPUT_DUCK;
  2919. }
  2920. else
  2921. {
  2922. // If currently shooting . . .
  2923. switch (m_state)
  2924. {
  2925. case State_Shooting:
  2926. SetState(State_Stand);
  2927. break;
  2928. case State_RunAndShoot:
  2929. SetState(State_Run);
  2930. break;
  2931. case State_StrafeAndShoot:
  2932. SetState(State_Strafe);
  2933. break;
  2934. }
  2935. }
  2936. #ifdef MOBILE
  2937. if (!demoCompat)
  2938. {
  2939. if (input & INPUT_STRAFE)
  2940. {
  2941. if (input & INPUT_LEFT)
  2942. {
  2943. *psStrafeAngle = m_dRot + 90;
  2944. }
  2945. else if (input & INPUT_RIGHT)
  2946. {
  2947. *psStrafeAngle = m_dRot - 90;
  2948. }
  2949. }
  2950. {
  2951. short sRotDelta = (short)(input & INPUT_ROT_MASK);
  2952. if (sRotDelta != 0)
  2953. sRotDelta -= 360;
  2954. if (input & INPUT_ROT_IS_ABS)
  2955. m_dRot = (double) sRotDelta;
  2956. else
  2957. m_dRot += (double) sRotDelta;
  2958. // If there was any rotation while standing . . .
  2959. if (sRotDelta != 0 && m_state == State_Stand)
  2960. {
  2961. // Reset stand state (to make sure idle anim doesn't kick (or gets turned
  2962. // off if we're already in it) ).
  2963. SetState(State_Stand);
  2964. }
  2965. }
  2966. }
  2967. else
  2968. {
  2969. #endif
  2970. if (input & INPUT_STRAFE)
  2971. {
  2972. if (input & INPUT_LEFT)
  2973. {
  2974. *psStrafeAngle = m_dRot + 90;
  2975. }
  2976. else if (input & INPUT_RIGHT)
  2977. {
  2978. *psStrafeAngle = m_dRot - 90;
  2979. }
  2980. }
  2981. else if (input & INPUT_STRAFE_LEFT)
  2982. *psStrafeAngle = m_dRot + 90;
  2983. else if (input & INPUT_STRAFE_RIGHT)
  2984. *psStrafeAngle = m_dRot - 90;
  2985. else
  2986. {
  2987. short sRotDelta = (short)(input & INPUT_ROT_MASK);
  2988. if (sRotDelta != 0)
  2989. sRotDelta -= 360;
  2990. // Adjust by input delta.
  2991. m_dRot += (double) sRotDelta;
  2992. //printf("dRotDelta == (%f), m_dRot == (%f)\n", (float) dRotDelta, (float) m_dRot);
  2993. // If there was any rotation while standing . . .
  2994. if (sRotDelta != 0 && m_state == State_Stand)
  2995. {
  2996. // Reset stand state (to make sure idle anim doesn't kick (or gets turned
  2997. // off if we're already in it) ).
  2998. SetState(State_Stand);
  2999. }
  3000. }
  3001. #ifdef MOBILE
  3002. }
  3003. #endif
  3004. // Set acceleration based on user input (forward has precedance over reverse)
  3005. if (input & INPUT_FORWARD)
  3006. {
  3007. m_dAcc = ms_dAccUser;
  3008. m_dDrag = 0;
  3009. m_bUseRotTS = false;
  3010. }
  3011. else if (input & INPUT_BACKWARD)
  3012. {
  3013. m_dAcc = -ms_dAccUser;
  3014. m_dDrag = 0;
  3015. m_bUseRotTS = false;
  3016. }
  3017. else if (!demoCompat && !((input & INPUT_MOVE_UP) || (input & INPUT_MOVE_DOWN) || (input & INPUT_MOVE_LEFT) || (input & INPUT_MOVE_RIGHT) || m_dJoyMoveVel > 0))
  3018. {
  3019. m_dAcc = 0;
  3020. // If traveling forward . . .
  3021. if (m_dVel > 0.0)
  3022. {
  3023. m_dDrag = -ms_dAccDrag;
  3024. }
  3025. else if (m_dVel < 0.0)
  3026. {
  3027. m_dDrag = ms_dAccDrag;
  3028. }
  3029. }
  3030. // Limit to maximum velocity, which depends on whether "slow" key is being pressed
  3031. if (input & INPUT_RUN)
  3032. {
  3033. *pdMaxForeVel = ms_dMaxVelForeFast;
  3034. *pdMaxBackVel = ms_dMaxVelBackFast;
  3035. }
  3036. else
  3037. {
  3038. *pdMaxForeVel = ms_dMaxVelFore;
  3039. *pdMaxBackVel = ms_dMaxVelBack;
  3040. }
  3041. // If jump specified . . .
  3042. if ((input & INPUT_REVIVE) && 0) // ***TEMPORARILY DISABLED***
  3043. {
  3044. // If on the ground . . .
  3045. if (m_bAboveTerrain == false)
  3046. {
  3047. // If moving forward of our own power. . .
  3048. if (m_dVel > 0.0)
  3049. {
  3050. SetState(State_JumpForward);
  3051. }
  3052. else
  3053. {
  3054. SetState(State_Jump);
  3055. }
  3056. }
  3057. }
  3058. // If duck specified . . .
  3059. if (input & INPUT_DUCK)
  3060. {
  3061. SetState(State_Duck);
  3062. }
  3063. else
  3064. {
  3065. if (m_state == State_Duck)
  3066. {
  3067. SetState(State_Rise);
  3068. }
  3069. }
  3070. // If suicide specified . . .
  3071. if (input & INPUT_SUICIDE)
  3072. {
  3073. // If we have the appropriate weapon . . .
  3074. if (m_stockpile.m_sMachineGun)
  3075. {
  3076. SetState(State_Suicide);
  3077. }
  3078. else
  3079. {
  3080. // Audible user feedback.
  3081. PlaySample(g_smidGeneralBeep, SampleMaster::UserFeedBack);
  3082. }
  3083. }
  3084. // If execute specified . . .
  3085. if (input & INPUT_EXECUTE)
  3086. {
  3087. // If not already executing . . .
  3088. if (m_state != State_Execute)
  3089. {
  3090. // If we have the appropriate weapon . . .
  3091. if (m_stockpile.m_sMachineGun)
  3092. {
  3093. // If there's someone close enough to execute . . .
  3094. if (FindExecutee() == true)
  3095. {
  3096. // Do it.
  3097. SetState(State_Execute);
  3098. }
  3099. }
  3100. else
  3101. {
  3102. // Audible user feedback.
  3103. PlaySample(g_smidGeneralBeep, SampleMaster::UserFeedBack);
  3104. }
  3105. }
  3106. }
  3107. }
  3108. ////////////////////////////////////////////////////////////////////////////////
  3109. // Applies accelerations, velocities, reacts to terrain obstructions, etc.
  3110. ////////////////////////////////////////////////////////////////////////////////
  3111. void CDude::ProcessForces( // Returns nothing.
  3112. long lCurTime, // In: Current game time.
  3113. double dMaxForeVel, // Out: Maximum forward velocity.
  3114. double dMaxBackVel, // Out: Maximum backward velocity.
  3115. short sStrafeAngle) // Out: Strafe angle.
  3116. {
  3117. double dNewX, dNewY, dNewZ;
  3118. // Calculate elapsed time in seconds.
  3119. double dSeconds = (double)(lCurTime - m_lPrevTime) / 1000.0;
  3120. #ifdef MOBILE
  3121. if (!demoCompat)
  3122. {
  3123. TwinStickInfo analogInfo = AndroidGetMovment();
  3124. if (analogInfo.velocity)
  3125. {
  3126. UpdateVelocities(dSeconds, dMaxForeVel * analogInfo.velocity, dMaxBackVel * analogInfo.velocity);
  3127. GetNewPositionAngle(&dNewX, &dNewY, &dNewZ, dSeconds,analogInfo.movmentAngle);
  3128. }
  3129. else
  3130. {
  3131. // Update Velocities ////////////////////////////////////////////////////////
  3132. UpdateVelocities(dSeconds, dMaxForeVel, dMaxBackVel);
  3133. // Get New Position /////////////////////////////////////////////////////////
  3134. GetNewPosition(&dNewX, &dNewY, &dNewZ, dSeconds);
  3135. //GetNewPositionAngle(&dNewX, &dNewY, &dNewZ, dSeconds,angle_for_postal);
  3136. }
  3137. }
  3138. else
  3139. {
  3140. // Update Velocities ////////////////////////////////////////////////////////
  3141. UpdateVelocities(dSeconds, dMaxForeVel, dMaxBackVel);
  3142. // Get New Position /////////////////////////////////////////////////////////
  3143. GetNewPosition(&dNewX, &dNewY, &dNewZ, dSeconds);
  3144. }
  3145. #else
  3146. // Update Velocities ////////////////////////////////////////////////////////
  3147. #if defined(ALLOW_TWINSTICK)
  3148. if (!demoCompat && m_dJoyMoveVel != 0)
  3149. UpdateVelocities(dSeconds, dMaxForeVel * m_dJoyMoveVel, dMaxBackVel * m_dJoyMoveVel);
  3150. else
  3151. #endif // ALLOW_TWINSTICK
  3152. UpdateVelocities(dSeconds, dMaxForeVel, dMaxBackVel);
  3153. // Get New Position /////////////////////////////////////////////////////////
  3154. if (!demoCompat && m_bUseRotTS)
  3155. GetNewPositionAngle(&dNewX, &dNewY, &dNewZ, dSeconds, m_dRotTS);
  3156. else
  3157. GetNewPosition(&dNewX, &dNewY, &dNewZ, dSeconds);
  3158. #endif // MOBILE
  3159. // If strafing . . .
  3160. if (sStrafeAngle != INVALID_STRAFE_ANGLE)
  3161. {
  3162. // Add strafe.
  3163. sStrafeAngle = rspMod360(sStrafeAngle);
  3164. double dStrafeDistance = (STRAFE_VEL * dSeconds);
  3165. dNewX += COSQ[sStrafeAngle] * dStrafeDistance;
  3166. dNewZ -= SINQ[sStrafeAngle] * dStrafeDistance;
  3167. }
  3168. // Validate New Position ////////////////////////////////////////////////////
  3169. if (MakeValidPosition(&dNewX, &dNewY, &dNewZ, MaxStepUpThreshold) == true)
  3170. {
  3171. // Update Values /////////////////////////////////////////////////////////
  3172. m_dX = dNewX;
  3173. m_dY = dNewY;
  3174. m_dZ = dNewZ;
  3175. // Map through view angle which is the angle of the trigger plane.
  3176. // (it is created by the user in the editor parallel with the
  3177. // screen).
  3178. double dTriggerY;
  3179. m_pRealm->MapZ3DtoY2D(m_dZ, &dTriggerY);
  3180. // Spew triggers.
  3181. SpewTriggers(m_pRealm, GetInstanceID(), m_dX, dTriggerY);
  3182. UpdateFirePosition();
  3183. }
  3184. else
  3185. {
  3186. // Restore Values ////////////////////////////////////////////////////////
  3187. // Didn't actually move and, therefore, did not actually accelerate.
  3188. // Restore velocities.
  3189. // m_dVel -= m_dDeltaVel;
  3190. // m_dExtHorzVel -= m_dExtHorzDeltaVel;
  3191. m_dExtVertVel -= m_dExtVertDeltaVel;
  3192. }
  3193. }
  3194. ////////////////////////////////////////////////////////////////////////////////
  3195. // Render object
  3196. ////////////////////////////////////////////////////////////////////////////////
  3197. void CDude::Render(void)
  3198. {
  3199. // Use user's chosen texture.
  3200. m_panimCur->m_ptextures = m_aptextures[m_sTextureIndex];
  3201. // Call base class.
  3202. CCharacter::Render();
  3203. // Update children, if any . . .
  3204. CFlag* pflag = GetNextFlag(NULL);
  3205. while (pflag)
  3206. {
  3207. PositionChild(
  3208. pflag->GetSprite(),
  3209. ((CDudeAnim3D*) m_panimCur)->m_ptransLeft->GetAtTime(m_lAnimTime), // In: Transform specifying position.
  3210. NULL,
  3211. NULL,
  3212. NULL);
  3213. // Update flag's position so it can correctly collision detect.
  3214. pflag->m_dX = m_dX;
  3215. pflag->m_dY = m_dY;
  3216. pflag->m_dZ = m_dZ;
  3217. // For asthetics, rotate it a bit.
  3218. pflag->m_dRot = rspMod360(pflag->m_dRot + RAND_SWAY(10) );
  3219. // Get next.
  3220. pflag = GetNextFlag(pflag);
  3221. }
  3222. // Get anim . . .
  3223. CAnim3D* panimWeapon = NULL; // Safety.
  3224. switch (m_state)
  3225. {
  3226. case State_Suicide:
  3227. case State_Execute:
  3228. panimWeapon = &(m_aanimWeapons[SemiAutomatic]);
  3229. break;
  3230. default:
  3231. panimWeapon = &(m_aanimWeapons[m_weapontypeCur]);
  3232. break;
  3233. }
  3234. // If we have a visible weapon . . .
  3235. if (panimWeapon->m_pmeshes)
  3236. {
  3237. // Show weapon sprite.
  3238. m_spriteWeapon.m_sInFlags &= ~CSprite::InHidden;
  3239. m_spriteWeapon.m_pmesh = panimWeapon->m_pmeshes->GetAtTime(m_lAnimTime);
  3240. m_spriteWeapon.m_psop = panimWeapon->m_psops->GetAtTime(m_lAnimTime);
  3241. m_spriteWeapon.m_ptex = panimWeapon->m_ptextures->GetAtTime(m_lAnimTime);
  3242. m_spriteWeapon.m_psphere = panimWeapon->m_pbounds->GetAtTime(m_lAnimTime);
  3243. m_spriteWeapon.m_ptrans = ((CDudeAnim3D*)m_panimCur)->m_ptransRight->GetAtTime(m_lAnimTime);
  3244. }
  3245. else
  3246. {
  3247. // Hide weapon sprite.
  3248. m_spriteWeapon.m_sInFlags |= CSprite::InHidden;
  3249. }
  3250. // If we have a backpack . . .
  3251. if (m_stockpile.m_sBackpack)
  3252. {
  3253. // Show backpack sprite.
  3254. m_spriteBackpack.m_sInFlags &= ~CSprite::InHidden;
  3255. ASSERT(m_animBackpack.m_pmeshes);
  3256. m_spriteBackpack.m_pmesh = m_animBackpack.m_pmeshes->GetAtTime(m_lAnimTime);
  3257. m_spriteBackpack.m_psop = m_animBackpack.m_psops->GetAtTime(m_lAnimTime);
  3258. m_spriteBackpack.m_ptex = m_animBackpack.m_ptextures->GetAtTime(m_lAnimTime);
  3259. m_spriteBackpack.m_psphere = m_animBackpack.m_pbounds->GetAtTime(m_lAnimTime);
  3260. m_spriteBackpack.m_ptrans = ((CDudeAnim3D*)m_panimCur)->m_ptransBack->GetAtTime(m_lAnimTime);
  3261. }
  3262. else
  3263. {
  3264. // Hide bakcpack sprite.
  3265. m_spriteBackpack.m_sInFlags |= CSprite::InHidden;
  3266. }
  3267. }
  3268. ////////////////////////////////////////////////////////////////////////////////
  3269. // Called by editor to init new object at specified position
  3270. ////////////////////////////////////////////////////////////////////////////////
  3271. short CDude::EditNew( // Returns 0 if successfull, non-zero otherwise
  3272. short sX, // In: New x coord
  3273. short sY, // In: New y coord
  3274. short sZ) // In: New z coord
  3275. {
  3276. short sResult = CCharacter::EditNew(sX, sY, sZ);
  3277. // Init dude
  3278. sResult = Init();
  3279. return sResult;
  3280. }
  3281. ////////////////////////////////////////////////////////////////////////////////
  3282. // Helper inline to get a GUI, set its text to the value, and recompose it.
  3283. ////////////////////////////////////////////////////////////////////////////////
  3284. inline
  3285. void SetText( // Returns nothing.
  3286. RGuiItem* pguiRoot, // In: Root GUI.
  3287. long lId, // In: ID of GUI to set text.
  3288. long lVal) // In: Value to set text to.
  3289. {
  3290. RGuiItem* pgui = pguiRoot->GetItemFromId(lId);
  3291. if (pgui != NULL)
  3292. {
  3293. pgui->SetText("%ld", lVal);
  3294. pgui->Compose();
  3295. }
  3296. }
  3297. ////////////////////////////////////////////////////////////////////////////////
  3298. // Called by editor to modify object
  3299. ////////////////////////////////////////////////////////////////////////////////
  3300. short CDude::EditModify(void) // Returns 0 if successfull, non-zero otherwise.
  3301. {
  3302. short sResult = CCharacter::EditModify();
  3303. if (sResult == 0)
  3304. {
  3305. RGuiItem* pgui = RGuiItem::LoadInstantiate(FullPathVD(MODIFY_GUI_FILE) );
  3306. if (pgui)
  3307. {
  3308. sResult = m_stockpile.UserEdit(pgui);
  3309. if (sResult == 0)
  3310. {
  3311. // Get values from dialog:
  3312. // Currently none.
  3313. // Success.
  3314. }
  3315. else
  3316. {
  3317. TRACE("EditModify(): m_stockpile.UserEdit() failed.\n");
  3318. }
  3319. delete pgui;
  3320. }
  3321. else
  3322. {
  3323. TRACE("EditModify(): Failed to open GUI \"%s\".\n", MODIFY_GUI_FILE);
  3324. sResult = -2;
  3325. }
  3326. }
  3327. else
  3328. {
  3329. TRACE("EditModify(): Base class EditModify() failed.\n");
  3330. sResult = -1;
  3331. }
  3332. return sResult;
  3333. }
  3334. ////////////////////////////////////////////////////////////////////////////////
  3335. // Init dude
  3336. ////////////////////////////////////////////////////////////////////////////////
  3337. short CDude::Init(void) // Returns 0 if successfull, non-zero otherwise
  3338. {
  3339. short sResult = 0;
  3340. m_lPrevTime = m_pRealm->m_time.GetGameTime();
  3341. m_lNextBulletTime = m_lPrevTime;
  3342. // Get resources
  3343. sResult = GetResources();
  3344. // Prepare shadow (get resources and setup sprite).
  3345. sResult |= PrepareShadow();
  3346. // Setup stand state.
  3347. SetState(State_Stand);
  3348. m_smash.m_bits = CSmash::Good | CSmash::Character;
  3349. m_smash.m_pThing = this;
  3350. // No special flags.
  3351. m_sprite.m_sInFlags = 0;
  3352. // Targeting flag initially starts out as Hidden
  3353. m_TargetSprite.m_sInFlags = CSprite::InHidden;
  3354. // Set alpha blendage.
  3355. m_TargetSprite.m_sAlphaLevel = TARGET_ALPHA_LEVEL;
  3356. // This can be changed with the toggle, and should probably be
  3357. // set initially by the preferences file.
  3358. m_bTargetingHelpEnabled = false;
  3359. // Setup weapon sprite.
  3360. m_spriteWeapon.m_sInFlags = 0;
  3361. m_spriteWeapon.m_pthing = this;
  3362. m_sprite.AddChild(&m_spriteWeapon);
  3363. // Setup backpack sprite.
  3364. m_spriteBackpack.m_sInFlags = 0;
  3365. m_spriteBackpack.m_pthing = this;
  3366. m_sprite.AddChild(&m_spriteBackpack);
  3367. // Setup our crawler.
  3368. m_crawler.m_prealm = m_pRealm;
  3369. m_crawler.m_sVertTolerance = MaxStepUpThreshold;
  3370. m_crawler.Setup(
  3371. sizeof(ms_anubs)/sizeof(ms_anubs[0]),
  3372. ms_anubs,
  3373. MAX_CRAWLER_PUSH_X,
  3374. MAX_CRAWLER_PUSH_Z);
  3375. // Store initial hit points.
  3376. m_sOrigHitPoints = m_stockpile.m_sHitPoints;
  3377. // Start with a weapon.
  3378. m_weapontypeCur = NoWeapon;
  3379. NextWeapon();
  3380. // Cache gun sound effects since the gun has no preload
  3381. CacheSample(g_smidRicochet1);
  3382. CacheSample(g_smidRicochet2);
  3383. CacheSample(g_smidBulletFire);
  3384. CacheSample(g_smidShotgun);
  3385. // Cache your own sound effects
  3386. CacheSample(g_smidDyingYell);
  3387. CacheSample(g_smidBodyImpact2);
  3388. CacheSample(g_smidOutOfBullets);
  3389. CacheSample(g_smidBulletIntoVest);
  3390. CacheSample(g_smidBlownupYell);
  3391. CacheSample(g_smidBurningMainGuy);
  3392. CacheSample(g_smidEmptyWeapon);
  3393. CacheSample(g_smidLoadedWeapon);
  3394. CacheSample(g_smidStep);
  3395. CacheSample(g_smidPickedUpWeapon);
  3396. return sResult;
  3397. }
  3398. ////////////////////////////////////////////////////////////////////////////////
  3399. // Kill dude
  3400. ////////////////////////////////////////////////////////////////////////////////
  3401. void CDude::Kill(void)
  3402. {
  3403. // Remove the target sprite, if there.
  3404. m_pRealm->m_scene.RemoveSprite(&m_TargetSprite);
  3405. // Free resources
  3406. FreeResources();
  3407. }
  3408. ////////////////////////////////////////////////////////////////////////////////
  3409. // Get all required resources
  3410. ////////////////////////////////////////////////////////////////////////////////
  3411. short CDude::GetResources(void) // Returns 0 if successfull, non-zero otherwise
  3412. {
  3413. short sResult = 0;
  3414. // Anim base name Rigid name Event name Loop flags
  3415. // =================== ============= =========== ===========
  3416. sResult = m_animRun.Get ("3d/main_runnogun", NULL, "mainevent", RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3417. sResult |= m_animThrow.Get ("3d/main_grenade", "maingrenade", "mainevent", 0);
  3418. sResult |= m_animStand.Get ("3d/main_bobbing", NULL, NULL, RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3419. sResult |= m_animDie.Get ("3d/main_die", NULL, "mainevent", 0);
  3420. sResult |= m_animShoot.Get ("3d/main_shoot", "guntip", NULL, RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3421. sResult |= m_animRunShoot.Get ("3d/main_runshoot", "guntip", "mainevent", RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3422. sResult |= m_animDamage.Get ("3d/main_multi", NULL, NULL, RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3423. sResult |= m_animBurning.Get ("3d/main_onfire", NULL, "mainevent", RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3424. sResult |= m_animStrafe.Get ("3d/main_strafe", NULL, "mainevent", RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3425. sResult |= m_animStrafeShoot.Get("3d/main_strafe", "guntip", "mainevent", RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3426. sResult |= m_animSuicide.Get ("3d/main_suicide", "bhead", "mainevent", 0);
  3427. sResult |= m_animLaunch.Get ("3d/main_missile", "mainmissile", "mainevent", 0);
  3428. sResult |= m_animBlownUp.Get ("3d/main_blownup", NULL, NULL, 0);
  3429. sResult |= m_animGetUp.Get ("3d/main_getup", NULL, NULL, 0);
  3430. sResult |= m_animDuck.Get ("3d/main_duck", NULL, NULL, 0);
  3431. sResult |= m_animRise.Get ("3d/main_rise", NULL, NULL, 0);
  3432. sResult |= m_animExecute.Get ("3d/main_execute", "guntip", NULL, 0);
  3433. sResult |= m_animPickPut.Get ("3d/main_pickput", "lfhand", "mainevent", 0);
  3434. sResult |= m_animIdle.Get ("3d/main_idle", NULL, NULL, 0);
  3435. // Get the different textures this dude could have.
  3436. short i;
  3437. char szResName[RSP_MAX_PATH];
  3438. for (i = 0; i < MaxTextures && sResult == 0; i++)
  3439. {
  3440. sprintf(szResName, "3d/main_color%d.tex", i);
  3441. sResult |= rspGetResource(&g_resmgrGame, szResName, &(m_aptextures[i]) );
  3442. }
  3443. // Get the different weapons this dude could use.
  3444. for (i = NoWeapon; i < NumWeaponTypes; i++)
  3445. {
  3446. if (ms_awdWeapons[i].pszWeaponResName)
  3447. {
  3448. sResult |= m_aanimWeapons[i].Get(ms_awdWeapons[i].pszWeaponResName, NULL, NULL, NULL, RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3449. }
  3450. }
  3451. // Get the backpack.
  3452. sResult |= m_animBackpack.Get(BACKPACK_RES_NAME, NULL, NULL, NULL, RChannel_LoopAtStart | RChannel_LoopAtEnd);
  3453. // Get the targeting sprite
  3454. sResult |= rspGetResource(&g_resmgrGame, m_pRealm->Make2dResPath(TARGETING_FILE), &(m_TargetSprite.m_pImage), RFile::LittleEndian);
  3455. return sResult;
  3456. }
  3457. ////////////////////////////////////////////////////////////////////////////////
  3458. // Free all resources
  3459. ////////////////////////////////////////////////////////////////////////////////
  3460. void CDude::FreeResources(void)
  3461. {
  3462. // Release resources for animations.
  3463. m_animRun.Release();
  3464. m_animThrow.Release();
  3465. m_animStand.Release();
  3466. m_animDie.Release();
  3467. m_animShoot.Release();
  3468. m_animRunShoot.Release();
  3469. m_animDamage.Release();
  3470. m_animBurning.Release();
  3471. m_animStrafe.Release();
  3472. m_animStrafeShoot.Release();
  3473. m_animSuicide.Release();
  3474. m_animLaunch.Release();
  3475. m_animBlownUp.Release();
  3476. m_animGetUp.Release();
  3477. m_animDuck.Release();
  3478. m_animRise.Release();
  3479. m_animExecute.Release();
  3480. m_animPickPut.Release();
  3481. m_animIdle.Release();
  3482. // Release the different textures.
  3483. short i;
  3484. for (i = 0; i < MaxTextures; i++)
  3485. {
  3486. rspReleaseResource(&g_resmgrGame, &(m_aptextures[i]) );
  3487. }
  3488. // Release the different weapons this dude could use.
  3489. for (i = NoWeapon; i < NumWeaponTypes; i++)
  3490. {
  3491. if (m_aanimWeapons[i].m_pmeshes)
  3492. {
  3493. m_aanimWeapons[i].Release();
  3494. }
  3495. }
  3496. // Release the backpack.
  3497. m_animBackpack.Release();
  3498. // Release the targeting image
  3499. rspReleaseResource(&g_resmgrGame, &(m_TargetSprite.m_pImage));
  3500. }
  3501. ////////////////////////////////////////////////////////////////////////////////
  3502. // Sets a new state based on supplied state enum. Will set animation ptr
  3503. // to proper animation for state and reset animation timer.
  3504. ////////////////////////////////////////////////////////////////////////////////
  3505. bool CDude::SetState( // Returns true if new state realized, false otherwise.
  3506. State state) // New state.
  3507. {
  3508. bool bRealizeNewState = true; // Assume we can enter state.
  3509. State stateOld = m_state; // Remember current state.
  3510. // If persistent state specified . . .
  3511. if (state == State_Persistent)
  3512. {
  3513. // Use last persistent state.
  3514. state = m_statePersistent;
  3515. }
  3516. // See if the state can be realized.
  3517. switch (m_state)
  3518. {
  3519. case State_Idle:
  3520. // Any new state is okay.
  3521. break;
  3522. case State_Stand:
  3523. // Any new state is okay.
  3524. break;
  3525. case State_Run:
  3526. // Any new state is okay.
  3527. break;
  3528. case State_ThrowDone:
  3529. break;
  3530. case State_Throw:
  3531. case State_ThrowRelease:
  3532. case State_ThrowFinish:
  3533. switch (state)
  3534. {
  3535. case State_ThrowRelease:
  3536. case State_ThrowFinish:
  3537. case State_ThrowDone:
  3538. case State_Die:
  3539. case State_Shot:
  3540. case State_BlownUp:
  3541. case State_Burning:
  3542. break;
  3543. default:
  3544. bRealizeNewState = false;
  3545. break;
  3546. }
  3547. break;
  3548. case State_Launch:
  3549. case State_LaunchRelease:
  3550. case State_LaunchFinish:
  3551. switch (state)
  3552. {
  3553. case State_Die:
  3554. case State_Shot:
  3555. case State_BlownUp:
  3556. case State_Burning:
  3557. case State_LaunchRelease:
  3558. case State_LaunchFinish:
  3559. case State_LaunchDone:
  3560. break;
  3561. default:
  3562. bRealizeNewState = false;
  3563. break;
  3564. }
  3565. break;
  3566. case State_LaunchDone:
  3567. break;
  3568. case State_Die:
  3569. switch (state)
  3570. {
  3571. case State_Dead:
  3572. case State_BlownUp:
  3573. break;
  3574. default:
  3575. bRealizeNewState = false;
  3576. break;
  3577. }
  3578. break;
  3579. case State_Dead:
  3580. switch (state)
  3581. {
  3582. case State_Die:
  3583. case State_Shot:
  3584. case State_Burning:
  3585. bRealizeNewState = false;
  3586. break;
  3587. case State_BlownUp:
  3588. break;
  3589. default:
  3590. break;
  3591. }
  3592. break;
  3593. case State_Shooting:
  3594. switch (state)
  3595. {
  3596. case State_Duck:
  3597. bRealizeNewState = false;
  3598. break;
  3599. }
  3600. break;
  3601. case State_RunAndShoot:
  3602. // Can go anywhere from here.
  3603. break;
  3604. case State_Shot:
  3605. switch (state)
  3606. {
  3607. case State_Shot:
  3608. bRealizeNewState = false;
  3609. break;
  3610. case State_BlownUp:
  3611. case State_Die:
  3612. break;
  3613. default:
  3614. // Check for minimum duration since last shot time . . .
  3615. if (m_pRealm->m_time.GetGameTime() < m_lLastShotTime + MIN_SHOT_DURATION)
  3616. {
  3617. bRealizeNewState = false;
  3618. }
  3619. break;
  3620. }
  3621. break;
  3622. case State_BlownUp:
  3623. switch (state)
  3624. {
  3625. case State_BlownUp:
  3626. break;
  3627. default:
  3628. // Check for end of blown up state . . .
  3629. if (m_lAnimTime < m_panimCur->m_psops->TotalTime())
  3630. {
  3631. bRealizeNewState = false;
  3632. }
  3633. break;
  3634. }
  3635. break;
  3636. case State_Burning:
  3637. switch (state)
  3638. {
  3639. case State_Shot:
  3640. case State_BlownUp:
  3641. // Ok, but come back to this state.
  3642. m_statePersistent = m_state;
  3643. break;
  3644. case State_Die:
  3645. case State_Stand:
  3646. // Don't come back.
  3647. m_statePersistent = State_Stand;
  3648. break;
  3649. default:
  3650. bRealizeNewState = false;
  3651. break;
  3652. }
  3653. break;
  3654. case State_Suicide:
  3655. switch (state)
  3656. {
  3657. case State_Dead:
  3658. break;
  3659. default:
  3660. // Cannot leave this state except to die.
  3661. bRealizeNewState = false;
  3662. break;
  3663. }
  3664. break;
  3665. case State_GetUp:
  3666. // Can only switch states due to violence or anim done.
  3667. switch (state)
  3668. {
  3669. case State_Die:
  3670. case State_Shot:
  3671. case State_BlownUp:
  3672. case State_Burning:
  3673. break;
  3674. default:
  3675. // Check for end of get up state . . .
  3676. if (m_lAnimTime < m_panimCur->m_psops->TotalTime())
  3677. {
  3678. bRealizeNewState = false;
  3679. }
  3680. break;
  3681. }
  3682. break;
  3683. case State_Duck:
  3684. // Can go to any other state.
  3685. break;
  3686. case State_Rise:
  3687. // Can go to any other state.
  3688. break;
  3689. case State_Jump:
  3690. case State_JumpForward:
  3691. // Only landing and falling?...damage? blown up? Not sure yet.
  3692. break;
  3693. case State_Fall:
  3694. break;
  3695. case State_Land:
  3696. break;
  3697. case State_LandForward:
  3698. break;
  3699. case State_Execute:
  3700. break;
  3701. case State_PutDown:
  3702. break;
  3703. case State_ObjectReleased:
  3704. break;
  3705. case State_PickUp:
  3706. break;
  3707. }
  3708. // If new state realized . . .
  3709. if (bRealizeNewState == true)
  3710. {
  3711. // Clean up old state.
  3712. switch (stateOld)
  3713. {
  3714. case State_Idle: // No cleaning necessary.
  3715. case State_Stand:
  3716. case State_Die:
  3717. case State_Run:
  3718. case State_Shot:
  3719. case State_Suicide:
  3720. case State_GetUp:
  3721. break;
  3722. case State_Duck:
  3723. // Clear the ducking bit
  3724. m_smash.m_bits &= ~CSmash::Ducking;
  3725. break;
  3726. case State_Dead:
  3727. break;
  3728. case State_Burning:
  3729. // If not coming back to this state . . .
  3730. if (stateOld != m_statePersistent)
  3731. {
  3732. // If the new state is die . . .
  3733. if (state == State_Die)
  3734. {
  3735. // Keep the fire.
  3736. }
  3737. else
  3738. {
  3739. // If there's a fire burning . . .
  3740. CThing* pthingFire;
  3741. if (m_pRealm->m_idbank.GetThingByID(&pthingFire, m_u16IdFire) == 0)
  3742. {
  3743. // Send it a delete message.
  3744. GameMessage msg;
  3745. msg.msg_ObjectDelete.eType = typeObjectDelete;
  3746. msg.msg_ObjectDelete.sPriority = 0;
  3747. SendThingMessage(&msg, pthingFire);
  3748. }
  3749. }
  3750. }
  3751. break;
  3752. case State_PickUp:
  3753. {
  3754. // If there's a powerup that we haven't let go of . . .
  3755. CPowerUp* ppowerup;
  3756. if (m_pRealm->m_idbank.GetThingByID((CThing**)&ppowerup, m_u16IdChild) == 0)
  3757. {
  3758. ppowerup->Drop(m_dX, m_dY, m_dZ);
  3759. }
  3760. break;
  3761. }
  3762. case State_Throw:
  3763. case State_ThrowDone:
  3764. case State_ThrowRelease:
  3765. case State_ThrowFinish:
  3766. case State_PutDown:
  3767. {
  3768. // If there's a weapon that we haven't let go of . . .
  3769. CWeapon* pweapon;
  3770. if (m_pRealm->m_idbank.GetThingByID((CThing**)&pweapon, m_u16IdWeapon) == 0 && state != State_ThrowRelease)
  3771. {
  3772. // It should drop like a rock.
  3773. pweapon->m_dHorizVel = (GetRand() % (short)CGrenade::ms_dThrowHorizVel); // NOTE: ****USING RAND()****
  3774. pweapon->m_dRot = GetRand() % 360;
  3775. ShootWeapon();
  3776. // Delete it!
  3777. GameMessage msg;
  3778. msg.msg_ObjectDelete.eType = typeObjectDelete;
  3779. msg.msg_ObjectDelete.sPriority = 0;
  3780. SendThingMessage(&msg, pweapon);
  3781. }
  3782. break;
  3783. }
  3784. case State_Launch:
  3785. case State_LaunchDone:
  3786. case State_LaunchRelease:
  3787. case State_LaunchFinish:
  3788. case State_Shooting:
  3789. case State_RunAndShoot:
  3790. case State_StrafeAndShoot:
  3791. {
  3792. // Abort weapon launch.
  3793. // If there's a weapon that we haven't launched . . .
  3794. CWeapon* pweapon;
  3795. if (m_pRealm->m_idbank.GetThingByID((CThing**)&pweapon, m_u16IdWeapon) == 0 && state != State_LaunchRelease)
  3796. {
  3797. // Done with it.
  3798. ShootWeapon();
  3799. // Delete it!
  3800. GameMessage msg;
  3801. msg.msg_ObjectDelete.eType = typeObjectDelete;
  3802. msg.msg_ObjectDelete.sPriority = 0;
  3803. SendThingMessage(&msg, pweapon);
  3804. }
  3805. break;
  3806. }
  3807. case State_BlownUp:
  3808. // If dead . . .
  3809. if (m_bDead == true)
  3810. {
  3811. // Simon says, "die."
  3812. state = State_Dead;
  3813. }
  3814. break;
  3815. case State_Execute:
  3816. m_idVictim = CIdBank::IdNil;
  3817. break;
  3818. }
  3819. // Setup new state.
  3820. m_state = state;
  3821. switch (state)
  3822. {
  3823. case State_Idle:
  3824. m_panimCur = NULL;
  3825. // Make sure we're not in the render list.
  3826. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  3827. break;
  3828. case State_Stand:
  3829. m_statePersistent = State_Stand;
  3830. m_panimCur = &m_animStand;
  3831. m_lAnimTime = 0;
  3832. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3833. m_lNextIdleTime = IDLE_ANIM_TIMEOUT;
  3834. break;
  3835. case State_Run:
  3836. if (stateOld != State_Run)
  3837. {
  3838. m_panimCur = &m_animRun;
  3839. m_lAnimTime = 0;
  3840. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3841. m_u8LastEvent = 0;
  3842. }
  3843. break;
  3844. case State_Throw:
  3845. m_panimCur = &m_animThrow;
  3846. m_lAnimTime = 0;
  3847. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3848. break;
  3849. case State_ThrowDone:
  3850. // This state is transitional only.
  3851. break;
  3852. case State_ThrowRelease:
  3853. // This state marks the release of the thrown object.
  3854. break;
  3855. case State_ThrowFinish:
  3856. // During this state the throw animation is played to finish.
  3857. // The thrown item has been released already.
  3858. break;
  3859. case State_Die:
  3860. m_panimCur = &m_animDie;
  3861. m_lAnimTime = 0;
  3862. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3863. // Ahhhhhhhhhh....
  3864. PlaySample(g_smidDyingYell, SampleMaster::Voices);
  3865. m_bGenericEvent1 = false;
  3866. // Make sure he ends up dead.
  3867. m_bDead = true;
  3868. break;
  3869. case State_Dead:
  3870. {
  3871. // If not already dead . . .
  3872. if (m_bDead == false)
  3873. {
  3874. // Note deadness.
  3875. m_bDead = true;
  3876. }
  3877. // Add in our Dead smash bit.
  3878. m_smash.m_bits |= CSmash::Dead;
  3879. // If in multiplayer . . .
  3880. if (m_pRealm->m_flags.bMultiplayer == true)
  3881. {
  3882. // Drop powerup.
  3883. // Create powerup . . .
  3884. CPowerUp* ppowerup = DropPowerUp(&m_stockpile, true);
  3885. if (ppowerup)
  3886. {
  3887. // Clear my stockpile.
  3888. m_stockpile.Zero();
  3889. // Toss it, baby.
  3890. TossPowerUp(ppowerup, 30);
  3891. }
  3892. }
  3893. break;
  3894. }
  3895. case State_Shooting:
  3896. // If not already in this state . . .
  3897. if (stateOld != State_Shooting)
  3898. {
  3899. m_panimCur = &m_animShoot;
  3900. m_lAnimTime = 0;
  3901. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3902. }
  3903. break;
  3904. case State_RunAndShoot:
  3905. // If not already in this state . . .
  3906. if (stateOld != State_RunAndShoot)
  3907. {
  3908. m_panimCur = &m_animRunShoot;
  3909. m_lAnimTime = 0;
  3910. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3911. m_u8LastEvent = 0;
  3912. }
  3913. break;
  3914. case State_Shot:
  3915. m_panimCur = &m_animDamage;
  3916. m_lAnimTime = 0;
  3917. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3918. break;
  3919. case State_BlownUp:
  3920. m_panimCur = &m_animBlownUp;
  3921. m_lAnimTime = 0;
  3922. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3923. m_bGenericEvent1 = false;
  3924. break;
  3925. case State_Burning:
  3926. // If not already in this state . . .
  3927. if (stateOld != State_Burning)
  3928. {
  3929. m_panimCur = &m_animBurning;
  3930. m_lAnimTime = 0;
  3931. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3932. m_u8LastEvent = 0;
  3933. }
  3934. break;
  3935. case State_Strafe:
  3936. // If not already in this state . . .
  3937. if (stateOld != State_Strafe)
  3938. {
  3939. m_panimCur = &m_animStrafe;
  3940. m_lAnimTime = 0;
  3941. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3942. m_u8LastEvent = 0;
  3943. }
  3944. break;
  3945. case State_StrafeAndShoot:
  3946. // If not already in this state . . .
  3947. if (stateOld != State_StrafeAndShoot)
  3948. {
  3949. m_panimCur = &m_animStrafeShoot;
  3950. m_lAnimTime = 0;
  3951. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3952. m_u8LastEvent = 0;
  3953. }
  3954. break;
  3955. case State_Suicide:
  3956. {
  3957. if (StatsAreAllowed) Stat_Suicides++;
  3958. UnlockAchievement(ACHIEVEMENT_COMMIT_SUICIDE);
  3959. m_panimCur = &m_animSuicide;
  3960. m_lAnimTime = 0;
  3961. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3962. m_bBrainSplatted = false;
  3963. m_bGenericEvent1 = false;
  3964. m_dVel = 0.0;
  3965. // Let the demon know.
  3966. GameMessage msg;
  3967. msg.msg_Suicide.eType = typeSuicide;
  3968. msg.msg_Suicide.sPriority = 0;
  3969. CThing* pDemon = m_pRealm->m_aclassHeads[CThing::CDemonID].GetNext();
  3970. if (pDemon)
  3971. SendThingMessage(&msg, pDemon);
  3972. break;
  3973. }
  3974. case State_Launch:
  3975. m_panimCur = &m_animLaunch;
  3976. m_lAnimTime = 0;
  3977. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3978. break;
  3979. case State_LaunchRelease:
  3980. // This state marks the release of the launched object.
  3981. break;
  3982. case State_LaunchFinish:
  3983. // During this state the launch animation is played to finish.
  3984. // The launched item has been released already.
  3985. break;
  3986. case State_LaunchDone:
  3987. // This state is transitional only.
  3988. break;
  3989. case State_GetUp:
  3990. m_panimCur = &m_animGetUp;
  3991. m_lAnimTime = 0;
  3992. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  3993. break;
  3994. case State_Duck:
  3995. // Set the ducking bits so missiles won't hit him.
  3996. m_smash.m_bits |= CSmash::Ducking;
  3997. if (stateOld != State_Duck)
  3998. {
  3999. m_panimCur = &m_animDuck;
  4000. m_lAnimTime = 0;
  4001. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  4002. }
  4003. break;
  4004. case State_Rise:
  4005. // If not already in this state . . .
  4006. if (stateOld != State_Rise)
  4007. {
  4008. // If we were just in the duck state . . .
  4009. if (stateOld == State_Duck)
  4010. {
  4011. // We want to only rise based on how ducked we are.
  4012. // If we duck at the same rate we rise, there's a relation
  4013. // between the times of the animations.
  4014. // If not past the end of the duck . . .
  4015. if (m_lAnimTime < m_animDuck.m_psops->TotalTime())
  4016. {
  4017. ASSERT(m_animDuck.m_psops->TotalTime() != 0);
  4018. // Get the ratio between the two animations total times.
  4019. float fRatio = (float)m_animRise.m_psops->TotalTime()
  4020. / (float)m_animDuck.m_psops->TotalTime();
  4021. // Invert the time in the new animations time base.
  4022. m_lAnimTime = m_animRise.m_psops->TotalTime() - m_lAnimTime * fRatio;
  4023. }
  4024. else
  4025. {
  4026. m_lAnimTime = 0;
  4027. }
  4028. }
  4029. else
  4030. {
  4031. m_lAnimTime = 0;
  4032. }
  4033. m_panimCur = &m_animRise;
  4034. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  4035. }
  4036. break;
  4037. case State_Jump:
  4038. if (stateOld != State_Jump)
  4039. {
  4040. // m_panimCur = &m_animJump;
  4041. ASSERT(0); // No longer a valid state.
  4042. m_lAnimTime = 0;
  4043. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  4044. // Clear trigger.
  4045. m_bJumpVerticalTrigger = false;
  4046. }
  4047. break;
  4048. case State_JumpForward:
  4049. if (stateOld != State_JumpForward)
  4050. {
  4051. // m_panimCur = &m_animJumpForward;
  4052. ASSERT(0); // No longer a valid state.
  4053. m_lAnimTime = 0;
  4054. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  4055. // Clear trigger.
  4056. m_bJumpVerticalTrigger = false;
  4057. }
  4058. break;
  4059. case State_Execute:
  4060. if (stateOld != State_Execute)
  4061. {
  4062. m_panimCur = &m_animExecute;
  4063. m_lAnimTime = 0;
  4064. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  4065. m_bGenericEvent1 = false;
  4066. PlaySample(g_smidExecution, SampleMaster::UserFeedBack);
  4067. }
  4068. break;
  4069. case State_PutDown:
  4070. if (stateOld != State_PutDown)
  4071. {
  4072. m_panimCur = &m_animPickPut;
  4073. m_lAnimTime = 0;
  4074. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  4075. }
  4076. break;
  4077. case State_ObjectReleased:
  4078. // Use current anim settings.
  4079. break;
  4080. case State_PickUp:
  4081. if (stateOld != State_PickUp)
  4082. {
  4083. m_panimCur = &m_animPickPut;
  4084. m_lAnimTime = 0;
  4085. m_lAnimPrevUpdateTime = m_pRealm->m_time.GetGameTime();
  4086. m_bGenericEvent1 = false;
  4087. }
  4088. break;
  4089. }
  4090. }
  4091. return bRealizeNewState;
  4092. }
  4093. ////////////////////////////////////////////////////////////////////////////////
  4094. // Gets info on specified weapon.
  4095. ////////////////////////////////////////////////////////////////////////////////
  4096. void CDude::GetWeaponInfo( // Returns nothing.
  4097. WeaponType weapon, // In: Weapon type to query.
  4098. ClassIDType* pidWeapon, // Out: CThing class ID of weapon.
  4099. short** ppsNum) // Out: Ptr to the weapon's counter.
  4100. {
  4101. static short sSafetyNum = 0;
  4102. short *psNumLeft = &sSafetyNum;
  4103. // Switch on weapon type . . .
  4104. switch (weapon)
  4105. {
  4106. case NoWeapon:
  4107. *pidWeapon = 0;
  4108. *ppsNum = &sSafetyNum;
  4109. break;
  4110. case Grenade:
  4111. *pidWeapon = CGrenadeID;
  4112. *ppsNum = &m_stockpile.m_sNumGrenades;
  4113. break;
  4114. case FireBomb:
  4115. *pidWeapon = CFirebombID;
  4116. *ppsNum = &m_stockpile.m_sNumFireBombs;
  4117. break;
  4118. case Rocket:
  4119. *pidWeapon = CRocketID;
  4120. *ppsNum = &m_stockpile.m_sNumMissiles;
  4121. break;
  4122. case Napalm:
  4123. *pidWeapon = CNapalmID;
  4124. *ppsNum = &m_stockpile.m_sNumNapalms;
  4125. break;
  4126. case SemiAutomatic:
  4127. *pidWeapon = CMachineGunID;
  4128. *ppsNum = &m_stockpile.m_sNumBullets;
  4129. break;
  4130. case ShotGun:
  4131. *pidWeapon = CShotGunID;
  4132. *ppsNum = &m_stockpile.m_sNumShells;
  4133. break;
  4134. case FlameThrower:
  4135. *pidWeapon = CFirestreamID; //CFireballID;
  4136. *ppsNum = &m_stockpile.m_sNumFuel;
  4137. break;
  4138. case ProximityMine:
  4139. *pidWeapon = CProximityMineID;
  4140. *ppsNum = &m_stockpile.m_sNumMines;
  4141. break;
  4142. case TimedMine:
  4143. *pidWeapon = CTimedMineID;
  4144. *ppsNum = &m_stockpile.m_sNumMines;
  4145. break;
  4146. case RemoteMine:
  4147. *pidWeapon = CRemoteControlMineID;
  4148. *ppsNum = &m_stockpile.m_sNumMines;
  4149. break;
  4150. case BouncingBettyMine:
  4151. *pidWeapon = CBouncingBettyMineID;
  4152. *ppsNum = &m_stockpile.m_sNumMines;
  4153. break;
  4154. case Heatseeker:
  4155. *pidWeapon = CHeatseekerID;
  4156. *ppsNum = &m_stockpile.m_sNumHeatseekers;
  4157. break;
  4158. case SprayCannon:
  4159. *pidWeapon = CAssaultWeaponID;
  4160. *ppsNum = &m_stockpile.m_sNumShells;
  4161. break;
  4162. case DeathWad:
  4163. *pidWeapon = CDeathWadID;
  4164. *ppsNum = &m_stockpile.m_sNumMissiles;
  4165. break;
  4166. case DoubleBarrel:
  4167. *pidWeapon = CDoubleBarrelID;
  4168. *ppsNum = &m_stockpile.m_sNumShells;
  4169. break;
  4170. default:
  4171. TRACE("GetWeaponInfo(): Query on invalid weapon (%d).\n", (short)weapon);
  4172. break;
  4173. }
  4174. }
  4175. ////////////////////////////////////////////////////////////////////////////////
  4176. // Fire specified weapon type.
  4177. ////////////////////////////////////////////////////////////////////////////////
  4178. void CDude::ArmWeapon( // Returns nothing.
  4179. WeaponType weapon /*= CurrentWeapon*/) // In: Weapon to fire.
  4180. {
  4181. // If firing not in progress . . .
  4182. if (m_u16IdWeapon == CIdBank::IdNil)
  4183. {
  4184. // If no specific weapon . . .
  4185. if (weapon == CurrentWeapon)
  4186. {
  4187. weapon = m_weapontypeCur;
  4188. }
  4189. // Get current weapon and stockpile.
  4190. short* psNumLeft;
  4191. GetWeaponInfo(weapon, &m_eWeaponType, &psNumLeft);
  4192. ULONG weaponFlag = 0;
  4193. switch (weapon)
  4194. {
  4195. case Grenade: weaponFlag = FLAG_USED_GRENADE; break;
  4196. case FireBomb: weaponFlag = FLAG_USED_MOLOTOV; break;
  4197. case Rocket: weaponFlag = FLAG_USED_ROCKET; break;
  4198. case Napalm: weaponFlag = FLAG_USED_NAPALM; break;
  4199. case SemiAutomatic: weaponFlag = FLAG_USED_M16; break;
  4200. case ShotGun: weaponFlag = FLAG_USED_SHOTGUN; break;
  4201. case FlameThrower: weaponFlag = FLAG_USED_FLAMETHROWER; break;
  4202. case ProximityMine: weaponFlag = FLAG_USED_PROXIMITY_MINE; break;
  4203. case TimedMine: weaponFlag = FLAG_USED_TIMED_MINE; break;
  4204. case RemoteMine: weaponFlag = FLAG_USED_REMOTE_MINE; break;
  4205. case BouncingBettyMine: weaponFlag = FLAG_USED_BETTY_MINE; break;
  4206. case Heatseeker: weaponFlag = FLAG_USED_HEATSEEKER; break;
  4207. case SprayCannon: weaponFlag = FLAG_USED_SPRAY_CANNON; break;
  4208. case DeathWad: weaponFlag = FLAG_USED_DEATHWAD; break;
  4209. case DoubleBarrel: weaponFlag = FLAG_USED_DBL_SHOTGUN; break;
  4210. }
  4211. State stateShoot = State_Throw;
  4212. switch (weapon)
  4213. {
  4214. case FlameThrower:
  4215. case SemiAutomatic:
  4216. case SprayCannon:
  4217. if ((m_dVel >= MIN_RUN_VEL || m_dVel <= -MIN_RUN_VEL || m_dAcc != 0.0))
  4218. {
  4219. stateShoot = State_RunAndShoot;
  4220. }
  4221. else
  4222. {
  4223. switch (m_state)
  4224. {
  4225. case State_Strafe:
  4226. case State_StrafeAndShoot:
  4227. stateShoot = State_StrafeAndShoot;
  4228. break;
  4229. case State_Execute:
  4230. stateShoot = State_Execute;
  4231. break;
  4232. default:
  4233. stateShoot = State_Shooting;
  4234. break;
  4235. }
  4236. }
  4237. break;
  4238. case ShotGun:
  4239. case DoubleBarrel:
  4240. stateShoot = State_Launch;
  4241. break;
  4242. case Grenade:
  4243. case FireBomb:
  4244. stateShoot = State_Throw;
  4245. break;
  4246. case Napalm:
  4247. case Rocket:
  4248. case Heatseeker:
  4249. case DeathWad:
  4250. stateShoot = State_Launch;
  4251. break;
  4252. case ProximityMine:
  4253. case TimedMine:
  4254. case RemoteMine:
  4255. case BouncingBettyMine:
  4256. stateShoot = State_PutDown;
  4257. break;
  4258. }
  4259. // If we have any of this weapon . . .
  4260. if (*psNumLeft >= ms_awdWeapons[weapon].sMinAmmoRequired)
  4261. {
  4262. // Enter our weapon launch state.
  4263. if (SetState(stateShoot) == true)
  4264. {
  4265. if (GetInputMode() != INPUT_MODE_PLAYBACK) // don't let demo mode set these flags, or the endgame will ruin achievements.
  4266. {
  4267. Flag_Achievements |= weaponFlag;
  4268. if ((Flag_Achievements & FLAG_MASK_WEAPONS) == FLAG_MASK_WEAPONS)
  4269. UnlockAchievement(ACHIEVEMENT_USE_EVERY_WEAPON);
  4270. }
  4271. // Remember the type of ammo we're shooting.
  4272. m_weaponShooting = weapon;
  4273. CWeapon* pweapon = PrepareWeapon();
  4274. if (pweapon != NULL)
  4275. {
  4276. GameMessage msg;
  4277. msg.msg_WeaponFire.eType = typeWeaponFire;
  4278. msg.msg_WeaponFire.sPriority = 0;
  4279. msg.msg_WeaponFire.sWeapon = (short) weapon;
  4280. CThing* pDemon = m_pRealm->m_aclassHeads[CThing::CDemonID].GetNext();
  4281. if (pDemon)
  4282. SendThingMessage(&msg, pDemon);
  4283. }
  4284. }
  4285. else
  4286. {
  4287. // Note that we were unable to arm a weapon.
  4288. // m_weaponShooting = NoWeapon;
  4289. }
  4290. }
  4291. else
  4292. {
  4293. // Switch to the old faithful.
  4294. SetWeapon(SemiAutomatic);
  4295. // Note that we were unable to arm a weapon.
  4296. m_weaponShooting = NoWeapon;
  4297. }
  4298. }
  4299. }
  4300. ////////////////////////////////////////////////////////////////////////////////
  4301. // Shoot current weapon.
  4302. // This should be done when the character releases the weapon it's
  4303. // shooting.
  4304. ////////////////////////////////////////////////////////////////////////////////
  4305. CWeapon* CDude::ShootWeapon(void) // Returns the weapoin ptr or NULL.
  4306. {
  4307. return ShootWeapon(
  4308. COLLISION_BITS_INCLUDE,
  4309. COLLISION_BITS_DONTCARE,
  4310. COLLISION_BITS_EXCLUDE);
  4311. }
  4312. ////////////////////////////////////////////////////////////////////////////////
  4313. // Shoot current weapon.
  4314. // This should be done when the character releases the weapon it's
  4315. // shooting.
  4316. // (virtual).
  4317. ////////////////////////////////////////////////////////////////////////////////
  4318. CWeapon* CDude::ShootWeapon( // Returns the weapon ptr or NULL.
  4319. CSmash::Bits bitsInclude /*= ms_u32CollideBitsInclude*/,
  4320. CSmash::Bits bitsDontcare /*= ms_u32CollideBitsDontcare*/,
  4321. CSmash::Bits bitsExclude /*= ms_u32CollideBitsExclude*/)
  4322. {
  4323. bool bShootWeapon = true; // Assume we should shoot the weapon.
  4324. CWeapon* pweapon = NULL; // Assume nothing.
  4325. // If the weapon is in an invalid position . . .
  4326. if (ValidateWeaponPosition() == false)
  4327. {
  4328. bShootWeapon = false;
  4329. }
  4330. if (m_weaponShooting != NoWeapon && bShootWeapon == true)
  4331. {
  4332. // Get the weapon info.
  4333. ClassIDType idWeapon;
  4334. short* psNumLeft;
  4335. GetWeaponInfo(m_weaponShooting, &idWeapon, &psNumLeft);
  4336. // ASSERT(idWeapon == m_eWeaponType);
  4337. switch (m_eWeaponType)
  4338. {
  4339. case CFirestreamID: //CFireballID:
  4340. if (m_u16IdWeapon != CIdBank::IdNil)
  4341. {
  4342. }
  4343. else
  4344. {
  4345. bShootWeapon = false;
  4346. }
  4347. break;
  4348. case CShotGunID:
  4349. if (m_stockpile.m_sNumShells > 0)
  4350. {
  4351. }
  4352. else
  4353. {
  4354. // Don't fire.
  4355. bShootWeapon = false;
  4356. }
  4357. break;
  4358. case CDoubleBarrelID:
  4359. if (m_stockpile.m_sNumShells > 1)
  4360. {
  4361. // Subtract one now (another will be taken soon -- cheezy... I know).
  4362. m_stockpile.m_sNumShells--;
  4363. }
  4364. else
  4365. {
  4366. // Don't fire.
  4367. bShootWeapon = false;
  4368. }
  4369. break;
  4370. case CAssaultWeaponID:
  4371. if (m_stockpile.m_sNumShells > 0)
  4372. {
  4373. // Note time of next fire.
  4374. m_lNextBulletTime = m_pRealm->m_time.GetGameTime() + MS_BETWEEN_SPRAYS;
  4375. }
  4376. else
  4377. {
  4378. // Note time of next fire.
  4379. m_lNextBulletTime = m_pRealm->m_time.GetGameTime() + MS_BETWEEN_SPRAYS * 3;
  4380. // Feedback.
  4381. PlaySample(g_smidOutOfBullets, SampleMaster::Weapon);
  4382. // Don't fire.
  4383. bShootWeapon = false;
  4384. }
  4385. break;
  4386. case CMachineGunID:
  4387. // Cannot run out of bullets.
  4388. // Note time of next fire.
  4389. m_lNextBulletTime = m_pRealm->m_time.GetGameTime() + MS_BETWEEN_BULLETS;
  4390. // If we have any of this weapon . . .
  4391. if (m_stockpile.m_sNumBullets < CStockPile::ms_stockpileMax.m_sNumBullets)
  4392. {
  4393. // Success.
  4394. m_stockpile.m_sNumBullets = CStockPile::ms_stockpileMax.m_sNumBullets;
  4395. }
  4396. break;
  4397. }
  4398. // If we actually want to shoot the weapon . . .
  4399. if (bShootWeapon)
  4400. {
  4401. // Deduct ammo.
  4402. *psNumLeft = *psNumLeft - 1;
  4403. pweapon = CCharacter::ShootWeapon(bitsInclude, bitsDontcare, bitsExclude);
  4404. // If a weapon was returned . . .
  4405. if (pweapon)
  4406. {
  4407. // Set the detection bits (not all weapons use these). The only one
  4408. // I know of currently is the heatseeker.
  4409. pweapon->SetDetectionBits(
  4410. CSmash::Character,
  4411. 0,
  4412. m_pRealm->m_flags.bCoopMode ? CSmash::Good : 0);
  4413. }
  4414. }
  4415. }
  4416. return pweapon;
  4417. }
  4418. ////////////////////////////////////////////////////////////////////////////////
  4419. // Receive damage.
  4420. ////////////////////////////////////////////////////////////////////////////////
  4421. void CDude::Damage( // Returns nothing.
  4422. short sHitPoints, // Hit points of damage to do.
  4423. U16 u16ShooterId) // In: Thing responsible for damage.
  4424. {
  4425. // Remember if already dead . . .
  4426. bool bDead = m_bDead;
  4427. if (m_bInvincible == false)
  4428. {
  4429. if (StatsAreAllowed) Stat_DamageTaken += sHitPoints;
  4430. m_stockpile.m_sHitPoints -= sHitPoints;
  4431. // If out of life . . .
  4432. if (m_stockpile.m_sHitPoints <= 0)
  4433. {
  4434. m_stockpile.m_sHitPoints = 0;
  4435. if (m_state != State_Die && m_state != State_Dead)
  4436. {
  4437. // Go to die.
  4438. SetState(State_Die);
  4439. // Even if we fail to enter the die state (like, if we're being
  4440. // blown up). Be dead.
  4441. m_bDead = true;
  4442. // If he wasn't already dead when he entered here, then register the kill.
  4443. if (bDead == false)
  4444. ScoreRegisterKill(m_pRealm, GetInstanceID(), u16ShooterId);
  4445. }
  4446. }
  4447. }
  4448. }
  4449. ////////////////////////////////////////////////////////////////////////////////
  4450. // Start the brain splat anim on its way.
  4451. ////////////////////////////////////////////////////////////////////////////////
  4452. void CDude::StartBrainSplat(void) // Returns nothing.
  4453. {
  4454. double dBrainX, dBrainY, dBrainZ;
  4455. GetLinkPoint( // Returns nothing.
  4456. m_panimCur->m_ptransRigid->GetAtTime(m_lAnimTime), // In: Transform specifying point.
  4457. &dBrainX, // Out: Point specified.
  4458. &dBrainY, // Out: Point specified.
  4459. &dBrainZ); // Out: Point specified.
  4460. // Make absolute by adding dude's position to relative position.
  4461. dBrainX += m_dX;
  4462. dBrainY += m_dY;
  4463. dBrainZ += m_dZ;
  4464. // Create blood chunks.
  4465. short i;
  4466. for (i = 0; i < BRAIN_SPLAT_NUM_CHUNKS; i++)
  4467. {
  4468. // Create blood particles . . .
  4469. CChunk* pchunk = NULL; // Initialized for safety.
  4470. // Note that this will fail if particles are disabled.
  4471. if (CThing::Construct(CChunkID, m_pRealm, (CThing**)&pchunk) == 0)
  4472. {
  4473. pchunk->Setup(
  4474. dBrainX, // Source position.
  4475. dBrainY, // Source position.
  4476. dBrainZ, // Source position.
  4477. m_dRot - 180, // Angle of velocity.
  4478. BRAIN_SPLAT_SWAY, // Angle sway.
  4479. 40, // Velocity (X/Z plane).
  4480. 80, // Velocity (X/Z plane) sway.
  4481. 50, // Velocity (Vertical).
  4482. 100, // Velocity (Vertical) sway.
  4483. CChunk::Blood); // Type of chunk.
  4484. }
  4485. }
  4486. }
  4487. ////////////////////////////////////////////////////////////////////////////////
  4488. // Determines if supplied position is valid tweaking it if necessary.
  4489. // (virtual).
  4490. ////////////////////////////////////////////////////////////////////////////////
  4491. bool CDude::MakeValidPosition( // Returns true, if new position was valid.
  4492. // Returns false, if could not reach new position.
  4493. double* pdNewX, // In: x position to validate.
  4494. // Out: New x position.
  4495. double* pdNewY, // In: y position to validate.
  4496. // Out: New y position.
  4497. double* pdNewZ, // In: z position to validate.
  4498. // Out: New z position.
  4499. short sVertTolerance /*= 0*/) // Vertical tolerance.
  4500. {
  4501. bool bValidatedPosition = false; // Assume failure.
  4502. double dCrawlerNewX;
  4503. double dCrawlerNewY;
  4504. double dCrawlerNewZ;
  4505. short sTerrainH;
  4506. // Make sure the position has not changed since our crawlage.
  4507. ASSERT(m_dX == m_dLastCrawledToPosX);
  4508. ASSERT(m_dZ == m_dLastCrawledToPosZ);
  4509. // Restore invalid movements to last good crawl position.
  4510. // The crawler cannot keep us out of things unless it is the only
  4511. // thing responsible for the movement.
  4512. if (m_dX != m_dLastCrawledToPosX)
  4513. m_dX = m_dLastCrawledToPosX;
  4514. if (m_dZ != m_dLastCrawledToPosZ)
  4515. m_dZ = m_dLastCrawledToPosZ;
  4516. // Ask crawler for valid position as close as possible to new position
  4517. if (m_crawler.Move( // Returns 0 if successfull, non-zero otherwise
  4518. m_dX, // In: Position #1 xcoord
  4519. m_dY, // In: Position #1 ycoord
  4520. m_dZ, // In: Position #1 zcoord
  4521. *pdNewX, // In: Position #2 xcoord
  4522. *pdNewY, // In: Position #2 ycoord
  4523. *pdNewZ, // In: Position #2 zcoord
  4524. &dCrawlerNewX, // Out: Final position xcoord
  4525. &dCrawlerNewY, // Out: Final position ycoord
  4526. &dCrawlerNewZ, // Out: Final position zcoord
  4527. &sTerrainH) // Out: Terrain height at new location
  4528. == 0)
  4529. {
  4530. // Success.
  4531. bValidatedPosition = true;
  4532. *pdNewX = dCrawlerNewX;
  4533. *pdNewY = dCrawlerNewY;
  4534. *pdNewZ = dCrawlerNewZ;
  4535. // Stored crawled to position on X/Z plane.
  4536. m_dLastCrawledToPosX = dCrawlerNewX;
  4537. m_dLastCrawledToPosZ = dCrawlerNewZ;
  4538. // If we're gonna be at or below ground level . . .
  4539. if (sTerrainH >= *pdNewY)
  4540. {
  4541. // Get outta there!
  4542. *pdNewY = sTerrainH;
  4543. // Update vertical delta.
  4544. m_dExtVertDeltaVel += -m_dExtVertVel;
  4545. // Reset vertical velocity.
  4546. m_dExtVertVel = 0.0;
  4547. m_bAboveTerrain = false;
  4548. }
  4549. else
  4550. {
  4551. m_bAboveTerrain = true;
  4552. }
  4553. }
  4554. else
  4555. {
  4556. // Failure. Homer, I can't seem to move under my own power.
  4557. m_dVel = 0.0;
  4558. m_dAcc = 0.0;
  4559. m_dDrag = 0.0;
  4560. }
  4561. return bValidatedPosition;
  4562. }
  4563. ////////////////////////////////////////////////////////////////////////////////
  4564. // Message handlers.
  4565. ////////////////////////////////////////////////////////////////////////////////
  4566. ////////////////////////////////////////////////////////////////////////////////
  4567. // Handles a msg_Shot.
  4568. // (virtual).
  4569. ////////////////////////////////////////////////////////////////////////////////
  4570. void CDude::OnShotMsg( // Returns nothing.
  4571. Shot_Message* pshotmsg) // In: Message to handle.
  4572. {
  4573. // Remember if already dead . . .
  4574. bool bDead = m_bDead;
  4575. if (StatsAreAllowed)
  4576. {
  4577. Stat_HitsTaken++;
  4578. if (Stat_HitsTaken >= 10000)
  4579. UnlockAchievement(ACHIEVEMENT_TAKE_10000_HITS);
  4580. }
  4581. // Give the msg to CThing3d before we alter it.
  4582. CThing3d::OnShotMsg(pshotmsg);
  4583. short sInitKevlarLayers = m_stockpile.m_sKevlarLayers;
  4584. if (m_stockpile.m_sKevlarLayers > 0)
  4585. {
  4586. pshotmsg->sDamage /= m_stockpile.m_sKevlarLayers * KEVLAR_PROTECTION_MULTIPLIER;
  4587. // Choclate melts vest.
  4588. m_stockpile.m_sKevlarLayers = MAX((short)(m_stockpile.m_sKevlarLayers - (GetRand() & 0x3)), (short)0);
  4589. }
  4590. CCharacter::OnShotMsg(pshotmsg);
  4591. // If we're taking damage . . .
  4592. if (pshotmsg->sDamage > 0)
  4593. {
  4594. Damage(pshotmsg->sDamage, pshotmsg->u16ShooterID);
  4595. // Check for mininum duration since last shot time . . .
  4596. if ( m_pRealm->m_time.GetGameTime() > m_lLastShotTime + MIN_CANNOT_BE_SHOT_DURATION
  4597. || m_state == State_Stand)
  4598. {
  4599. if (SetState(State_Shot) == true)
  4600. {
  4601. m_lLastShotTime = m_pRealm->m_time.GetGameTime();
  4602. }
  4603. }
  4604. }
  4605. // If we have protection . . .
  4606. if (sInitKevlarLayers > 0)
  4607. {
  4608. // Audible and visual feedback.
  4609. PlaySample(g_smidBulletIntoVest, SampleMaster::Weapon);
  4610. double dHitY = m_dY + m_sprite.m_sRadius + RAND_SWAY(VEST_HIT_SWAY);
  4611. // X/Z position depends on angle of shot (it is opposite).
  4612. short sDeflectionAngle = rspMod360(pshotmsg->sAngle + 180);
  4613. double dHitX = m_dX + COSQ[sDeflectionAngle] * TORSO_RADIUS;
  4614. double dHitZ = m_dZ - SINQ[sDeflectionAngle] * TORSO_RADIUS;
  4615. StartAnim(VEST_HIT_RES_NAME, dHitX, dHitY, dHitZ, false);
  4616. // Create a kevlar peice.
  4617. CChunk* pchunk = NULL; // Initialized for safety.
  4618. // Note that this will fail if particles are disabled.
  4619. if (CThing::Construct(CChunkID, m_pRealm, (CThing**)&pchunk) == 0)
  4620. {
  4621. pchunk->Setup(
  4622. dHitX, // Source position.
  4623. dHitY, // Source position.
  4624. dHitZ, // Source position.
  4625. sDeflectionAngle, // Angle of velocity.
  4626. 0, // Angle sway.
  4627. 40, // Velocity (X/Z plane).
  4628. 80, // Velocity (X/Z plane) sway.
  4629. 50, // Velocity (Vertical).
  4630. 100, // Velocity (Vertical) sway.
  4631. CChunk::Kevlar); // Type of chunk.
  4632. }
  4633. }
  4634. // If still alive . . .
  4635. if (m_bDead == false)
  4636. {
  4637. if (m_pRealm->m_time.GetGameTime() > m_lLastYellTime + MIN_BETWEEN_YELLS)
  4638. {
  4639. // If we took damage . . .
  4640. if (pshotmsg->sDamage > 0)
  4641. {
  4642. PlaySample(g_smidBlownupYell, SampleMaster::Voices);
  4643. m_lLastYellTime = m_pRealm->m_time.GetGameTime();
  4644. }
  4645. }
  4646. }
  4647. else
  4648. {
  4649. // If not previously dead or dying . . .
  4650. if (bDead == false && m_state != State_Die)
  4651. {
  4652. // Ahhhhhhhhhh....
  4653. PlaySample(g_smidDyingYell, SampleMaster::Voices);
  4654. m_lLastYellTime = m_pRealm->m_time.GetGameTime();
  4655. }
  4656. }
  4657. }
  4658. ////////////////////////////////////////////////////////////////////////////////
  4659. // Handles an Explosion_Message.
  4660. // (virtual).
  4661. ////////////////////////////////////////////////////////////////////////////////
  4662. void CDude::OnExplosionMsg( // Returns nothing.
  4663. Explosion_Message* pexplosionmsg) // In: Message to handle.
  4664. {
  4665. // Remember if already dead . . .
  4666. bool bDead = m_bDead;
  4667. CCharacter::OnExplosionMsg(pexplosionmsg);
  4668. if (SetState(State_BlownUp) == true)
  4669. {
  4670. // Let's increase his vertical just a bit.
  4671. m_dExtVertVel *= EXPLOSION_VERTICAL_VEL_MULTIPLIER;
  4672. Damage(pexplosionmsg->sDamage, pexplosionmsg->u16ShooterID);
  4673. // If he is carying a flag item, then he should drop it and
  4674. // pass the explosion message on to the flags so they can react.
  4675. DropAllFlags( (GameMessage*)pexplosionmsg);
  4676. // If still alive . . .
  4677. if (m_bDead == false)
  4678. {
  4679. if (m_pRealm->m_time.GetGameTime() > m_lLastYellTime + MIN_BETWEEN_YELLS)
  4680. {
  4681. PlaySample(g_smidBlownupYell, SampleMaster::Voices);
  4682. m_lLastYellTime = m_pRealm->m_time.GetGameTime();
  4683. }
  4684. }
  4685. else
  4686. {
  4687. // If not previously dead . . .
  4688. if (bDead == false)
  4689. {
  4690. // Ahhhhhhhhhh....
  4691. PlaySample(g_smidDyingYell, SampleMaster::Voices);
  4692. m_lLastYellTime = m_pRealm->m_time.GetGameTime();
  4693. }
  4694. }
  4695. }
  4696. m_lLastShotTime = m_pRealm->m_time.GetGameTime();
  4697. }
  4698. ////////////////////////////////////////////////////////////////////////////////
  4699. // Handles a Burn_Message.
  4700. // (virtual).
  4701. ////////////////////////////////////////////////////////////////////////////////
  4702. void CDude::OnBurnMsg( // Returns nothing.
  4703. Burn_Message* pburnmsg) // In: Message to handle.
  4704. {
  4705. if (SetState(State_Burning) == true)
  4706. {
  4707. CCharacter::OnBurnMsg(pburnmsg);
  4708. PlaySample(g_smidBurningMainGuy, SampleMaster::Voices);
  4709. // If he is carying a flag item, then he should drop them.
  4710. DropAllFlags( (GameMessage*)pburnmsg);
  4711. }
  4712. short sDamage = MAX((short) 1, (short) ((double) pburnmsg->sDamage * (((double) m_pRealm->m_flags.sDifficulty) / 10.0)));
  4713. Damage(sDamage, pburnmsg->u16ShooterID);
  4714. }
  4715. ////////////////////////////////////////////////////////////////////////////////
  4716. // Handles a PutMeDown_Message
  4717. // (virtual)
  4718. ////////////////////////////////////////////////////////////////////////////////
  4719. void CDude::OnPutMeDownMsg( // Returns nothing
  4720. PutMeDown_Message* pputmedownmsg)
  4721. {
  4722. // If he is carrying the flag item, then he should put it down
  4723. if (pputmedownmsg->u16FlagInstanceID != CIdBank::IdNil)
  4724. {
  4725. // Detatch child and update its position
  4726. CThing3d* pthing3d = DetachChild(
  4727. &(pputmedownmsg->u16FlagInstanceID),
  4728. ((CDudeAnim3D*) m_panimCur)->m_ptransLeft->GetAtTime(m_lAnimTime) );
  4729. if (pthing3d)
  4730. {
  4731. pthing3d->m_dX = m_dX;
  4732. pthing3d->m_dY = m_dY;
  4733. pthing3d->m_dZ = m_dZ;
  4734. pthing3d->m_state = State_Die;
  4735. }
  4736. }
  4737. }
  4738. ////////////////////////////////////////////////////////////////////////////////
  4739. // Handles an ObjectDelete_Message.
  4740. // (virtual).
  4741. ////////////////////////////////////////////////////////////////////////////////
  4742. void CDude::OnDeleteMsg( // Returns nothing.
  4743. ObjectDelete_Message* pdeletemsg) // In: Message to handle.
  4744. {
  4745. CCharacter::OnDeleteMsg(pdeletemsg);
  4746. SetState(State_Delete);
  4747. }
  4748. ////////////////////////////////////////////////////////////////////////////////
  4749. // Handles a Suicide_Message.
  4750. // (virtual).
  4751. ////////////////////////////////////////////////////////////////////////////////
  4752. void CDude::OnSuicideMsg( // Returns nothing.
  4753. Suicide_Message* psuicidemsg) // In: Message to handle.
  4754. {
  4755. CCharacter::OnSuicideMsg(psuicidemsg);
  4756. SetState(State_Suicide);
  4757. }
  4758. ////////////////////////////////////////////////////////////////////////////////
  4759. // Implements basic functionality while being blown up and returns true
  4760. // until the state is completed.
  4761. // (virtual).
  4762. ////////////////////////////////////////////////////////////////////////////////
  4763. bool CDude::WhileBlownUp(void) // Returns true until state is complete.
  4764. {
  4765. bool bStatePersists = true; // Assume not done.
  4766. double dNewX, dNewY, dNewZ;
  4767. // Get time from last call in seconds.
  4768. long lCurTime = m_pRealm->m_time.GetGameTime();
  4769. double dSeconds = double(lCurTime - m_lPrevTime) / 1000.0;
  4770. // Update Velocities ////////////////////////////////////////////////////////
  4771. UpdateVelocities(dSeconds, ms_dMaxVelForeFast, ms_dMaxVelBackFast);
  4772. // Get New Position /////////////////////////////////////////////////////////
  4773. GetNewPosition(&dNewX, &dNewY, &dNewZ, dSeconds);
  4774. // Validate New Position ////////////////////////////////////////////////////
  4775. if (MakeValidPosition(&dNewX, &dNewY, &dNewZ, MaxStepUpThreshold) == true)
  4776. {
  4777. // Update Values /////////////////////////////////////////////////////////
  4778. m_dX = dNewX;
  4779. m_dY = dNewY;
  4780. m_dZ = dNewZ;
  4781. UpdateFirePosition();
  4782. }
  4783. else
  4784. {
  4785. // Restore Values ////////////////////////////////////////////////////////
  4786. // Didn't actually move and, therefore, did not actually accelerate.
  4787. // Restore velocities.
  4788. // m_dVel -= m_dDeltaVel;
  4789. // m_dExtHorzVel -= m_dExtHorzDeltaVel;
  4790. m_dExtVertVel -= m_dExtVertDeltaVel;
  4791. }
  4792. // If it was above the ground last time and is now below the ground, it must have
  4793. // hit the ground and the blown up state is complete
  4794. if (m_bAboveTerrain == false)
  4795. {
  4796. // If not yet triggered . . .
  4797. if (m_bGenericEvent1 == false)
  4798. {
  4799. PlaySample(g_smidBodyImpact2, SampleMaster::Unspecified);
  4800. m_bGenericEvent1 = true;
  4801. }
  4802. // Make sure its done with current animation also
  4803. if (m_lAnimTime > m_panimCur->m_psops->TotalTime())
  4804. {
  4805. bStatePersists = false;
  4806. }
  4807. }
  4808. return bStatePersists;
  4809. }
  4810. ////////////////////////////////////////////////////////////////////////////////
  4811. // Execute the nearest writhing guy, if any.
  4812. ////////////////////////////////////////////////////////////////////////////////
  4813. void CDude::OnExecute(void) // Returns nothing.
  4814. {
  4815. // Update execution point via link point.
  4816. double dMuzzleX, dMuzzleY, dMuzzleZ;
  4817. GetLinkPoint( // Returns nothing.
  4818. m_panimCur->m_ptransRigid->GetAtTime(m_lAnimTime), // In: Transform specifying point.
  4819. &dMuzzleX, // Out: Point speicfied.
  4820. &dMuzzleY, // Out: Point speicfied.
  4821. &dMuzzleZ); // Out: Point speicfied.
  4822. // Get current weapon and stockpile.
  4823. short* psNumLeft;
  4824. ClassIDType idWeapon;
  4825. GetWeaponInfo(SemiAutomatic, &idWeapon, &psNumLeft);
  4826. if (*psNumLeft > 0)
  4827. {
  4828. // Muzzle flare and sound feedback.
  4829. m_bullets.Flare(
  4830. m_dRot,
  4831. m_dX + dMuzzleX,
  4832. m_dY + dMuzzleY,
  4833. m_dZ + dMuzzleZ,
  4834. m_pRealm);
  4835. // Shoot this thing.
  4836. GameMessage msg;
  4837. msg.msg_Shot.eType = typeShot;
  4838. msg.msg_Shot.sPriority = 0;
  4839. msg.msg_Shot.sAngle = m_dRot;
  4840. msg.msg_Shot.u16ShooterID = m_u16InstanceId;
  4841. msg.msg_Shot.sDamage = 10;
  4842. // Send it the message.
  4843. SendThingMessage(&msg, m_idVictim);
  4844. // Note time of next fire.
  4845. m_lNextBulletTime = m_pRealm->m_time.GetGameTime() + MS_BETWEEN_BULLETS;
  4846. // Deduct a shot.
  4847. *psNumLeft = *psNumLeft - 1;
  4848. }
  4849. else
  4850. {
  4851. // Feedback.
  4852. PlaySample(g_smidOutOfBullets, SampleMaster::Weapon);
  4853. }
  4854. }
  4855. ////////////////////////////////////////////////////////////////////////////////
  4856. // Implements one-time functionality for when a weapon is destroyed while
  4857. // we were moving it (i.e., before we let go or ShootWeapon()'ed it).
  4858. // This can occur when a weapon, while traveling along our rigid body,
  4859. // enters terrain.
  4860. ////////////////////////////////////////////////////////////////////////////////
  4861. // virtual (overridden here).
  4862. void CDude::OnWeaponDestroyed(void)
  4863. {
  4864. // Feedback that we aborted. Perhaps different by state?
  4865. PlaySample(g_smidGeneralBeep, SampleMaster::UserFeedBack);
  4866. // Finish.
  4867. switch (m_state)
  4868. {
  4869. case State_Throw:
  4870. case State_ThrowRelease:
  4871. case State_ThrowFinish:
  4872. SetState(State_ThrowDone);
  4873. break;
  4874. case State_Launch:
  4875. case State_LaunchRelease:
  4876. case State_LaunchFinish:
  4877. SetState(State_LaunchDone);
  4878. break;
  4879. default:
  4880. // Be done with our state.
  4881. SetState(State_Persistent);
  4882. break;
  4883. }
  4884. m_weaponShooting = NoWeapon;
  4885. }
  4886. ////////////////////////////////////////////////////////////////////////////////
  4887. // Revive a dead dude. This is a more graceful way than just setting
  4888. // his state. This will restore stockpile and make him animate out of
  4889. // a warp point.
  4890. ////////////////////////////////////////////////////////////////////////////////
  4891. void CDude::Revive( // Returns nothing.
  4892. bool bWarpIn /*= true*/) // In: true, to warp in, false to just get up.
  4893. {
  4894. // Must be dead, lying there still in multiplayer mode (or we could be cheating) . . .
  4895. if ( m_bDead == true
  4896. && (m_pRealm->m_flags.bMultiplayer == true || bWarpIn == false) )
  4897. {
  4898. // Drop that fire.
  4899. m_u16IdFire = CIdBank::IdNil;
  4900. // Let's not be responding to old news.
  4901. m_MessageQueue.Empty();
  4902. // Create powerup . . .
  4903. // NOTE that if the dude is going to be warped in (that is, he is going to get
  4904. // reloaded with stuff from the warp), he only drops his current weapon and all
  4905. // his ammo. If he is not going to be warped in (that is, he will NOT get
  4906. // any stuff from a warp), he drops all his stuff so he can pick it back up.
  4907. DropPowerUp(&m_stockpile, bWarpIn);
  4908. // Clear my stockpile.
  4909. m_stockpile.Zero();
  4910. // Have a life.
  4911. m_stockpile.m_sHitPoints = m_sOrigHitPoints;
  4912. m_smash.m_bits &= ~CSmash::Dead;
  4913. m_bDead = false;
  4914. m_sBrightness = 0;
  4915. CDude* pdude = this;
  4916. if (bWarpIn == true)
  4917. {
  4918. // It would be best if this only occurred when we're in the dead state
  4919. // and, hence, on the proper animation.
  4920. // This should flag us to other situations.
  4921. ASSERT(m_state == State_Dead);
  4922. // Render current dead frame into background to stay.
  4923. m_pRealm->m_scene.DeadRender3D(
  4924. m_pRealm->m_phood->m_pimBackground, // Destination image.
  4925. &m_sprite, // Tree of 3D sprites to render.
  4926. m_pRealm->m_phood); // Dst clip rect.
  4927. // First try to find a warp in point . . .
  4928. if (CWarp::WarpInAnywhere(
  4929. m_pRealm,
  4930. &pdude,
  4931. CWarp::CopyStockPile) == 0)
  4932. {
  4933. // Force to base weapon
  4934. SetWeapon(SemiAutomatic, true);
  4935. NextWeapon();
  4936. // Run on screen or out of building or whatever.
  4937. SetState(State_Run);
  4938. m_dVel = ms_dMaxVelForeFast;
  4939. }
  4940. else
  4941. {
  4942. // Just get up, you rogue.
  4943. SetState(State_GetUp);
  4944. }
  4945. }
  4946. else
  4947. {
  4948. // Just get up, you rogue.
  4949. SetState(State_GetUp);
  4950. }
  4951. }
  4952. }
  4953. ////////////////////////////////////////////////////////////////////////////////
  4954. // ShowTarget - If the targeting aid is turned on, then this will put the
  4955. // targeting sprite on the target.
  4956. ////////////////////////////////////////////////////////////////////////////////
  4957. void CDude::ShowTarget()
  4958. {
  4959. if (m_bTargetingHelpEnabled && m_bDead == false)
  4960. {
  4961. // sAngle must be between 0 and 359.
  4962. short sRotY = rspMod360((short) m_dRot);
  4963. short sRangeXZ = 100;
  4964. short sRadius = 20;
  4965. float fRateX = COSQ[sRotY] * sRangeXZ;
  4966. float fRateZ = -SINQ[sRotY] * sRangeXZ;
  4967. float fRateY = 0.0; // If we ever want vertical movement . . .
  4968. // Set initial position to first point to check (NEVER checks original position).
  4969. float fPosX = m_dX + fRateX;
  4970. float fPosY = m_dY + fRateY;
  4971. float fPosZ = m_dZ + fRateZ;
  4972. if (m_TargetSprite.m_psprParent)
  4973. m_TargetSprite.m_psprParent->RemoveChild(&m_TargetSprite);
  4974. ((CThing3d*)this)->m_sprite.AddChild(&m_TargetSprite);
  4975. // Map from 3d to 2d coords
  4976. Map3Dto2D(
  4977. fRateX - m_sprite.m_sRadius / 2,
  4978. m_sprite.m_sRadius * 2,
  4979. fRateZ,
  4980. &m_TargetSprite.m_sX2,
  4981. &m_TargetSprite.m_sY2);
  4982. m_TargetSprite.m_sInFlags &= ~CSprite::InHidden;
  4983. m_TargetSprite.m_sLayer = CRealm::LayerSprite16;
  4984. }
  4985. else
  4986. m_TargetSprite.m_sInFlags |= CSprite::InHidden;
  4987. }
  4988. /*
  4989. void CDude::ShowTarget(void)
  4990. {
  4991. if (m_bTargetingHelpEnabled && m_bDead == false)
  4992. {
  4993. CThing* pTargetThing = NULL;
  4994. if (IlluminateTarget((short) m_dX,
  4995. (short) m_dY,
  4996. (short) m_dZ,
  4997. (short) m_dRot,
  4998. 300,
  4999. 20,
  5000. CSmash::Character,
  5001. CSmash::Good | CSmash::Bad,
  5002. 0,
  5003. &pTargetThing,
  5004. &m_smash))
  5005. {
  5006. if (m_TargetSprite.m_psprParent)
  5007. m_TargetSprite.m_psprParent->RemoveChild(&m_TargetSprite);
  5008. ((CThing3d*) pTargetThing)->m_sprite.AddChild(&m_TargetSprite);
  5009. // Map from 3d to 2d coords
  5010. Map3Dto2D(
  5011. (short) 0,
  5012. (short) 30,
  5013. (short) 0,
  5014. &m_TargetSprite.m_sX2,
  5015. &m_TargetSprite.m_sY2);
  5016. m_TargetSprite.m_sInFlags &= ~CSprite::InHidden;
  5017. }
  5018. else
  5019. {
  5020. m_TargetSprite.m_sInFlags |= CSprite::InHidden;
  5021. }
  5022. }
  5023. else
  5024. m_TargetSprite.m_sInFlags |= CSprite::InHidden;
  5025. }
  5026. */
  5027. ////////////////////////////////////////////////////////////////////////////////
  5028. // Next weapon please.
  5029. ////////////////////////////////////////////////////////////////////////////////
  5030. void CDude::NextWeapon(void)
  5031. {
  5032. short sNumTried = 0;
  5033. short sCurWeapon = m_weapontypeCur;
  5034. while (sNumTried < NumWeaponTypes)
  5035. {
  5036. sNumTried++;
  5037. sCurWeapon++;
  5038. if (sCurWeapon == NumWeaponTypes)
  5039. {
  5040. sCurWeapon = NoWeapon + 1;
  5041. }
  5042. if (SetWeapon((WeaponType)sCurWeapon, false) == true)
  5043. {
  5044. break;
  5045. }
  5046. }
  5047. if (sNumTried == NumWeaponTypes)
  5048. {
  5049. SetWeapon(NoWeapon, false);
  5050. }
  5051. PlaySample(g_smidLoadedWeapon, SampleMaster::UserFeedBack);
  5052. }
  5053. ////////////////////////////////////////////////////////////////////////////////
  5054. // Previous weapon please.
  5055. ////////////////////////////////////////////////////////////////////////////////
  5056. void CDude::PrevWeapon(void)
  5057. {
  5058. short sNumTried = 0;
  5059. short sCurWeapon = m_weapontypeCur;
  5060. while (sNumTried < NumWeaponTypes)
  5061. {
  5062. sNumTried++;
  5063. sCurWeapon--;
  5064. if (sCurWeapon == NoWeapon)
  5065. {
  5066. sCurWeapon = NumWeaponTypes - 1;
  5067. }
  5068. if (SetWeapon((WeaponType)sCurWeapon, false) == true)
  5069. {
  5070. break;
  5071. }
  5072. }
  5073. if (sNumTried == NumWeaponTypes)
  5074. {
  5075. SetWeapon(NoWeapon, false);
  5076. }
  5077. PlaySample(g_smidLoadedWeapon, SampleMaster::UserFeedBack);
  5078. }
  5079. ////////////////////////////////////////////////////////////////////////////////
  5080. // Set the current weapon.
  5081. ////////////////////////////////////////////////////////////////////////////////
  5082. bool CDude::SetWeapon( // Returns true if weapon could be set as current.
  5083. WeaponType weapon, // In: New weapon to attempt to make the current.
  5084. bool bSetIfNoAmmo /*= true*/) // In: true to set weapon (even if no ammo).
  5085. {
  5086. bool bSetWeapon = true; // Assume we could set the weapon.
  5087. switch (weapon)
  5088. {
  5089. case NoWeapon:
  5090. break;
  5091. case SemiAutomatic:
  5092. if (m_stockpile.m_sMachineGun == 0)
  5093. {
  5094. bSetWeapon = false;
  5095. }
  5096. break;
  5097. case Grenade:
  5098. break;
  5099. case FireBomb:
  5100. break;
  5101. case Rocket:
  5102. if (m_stockpile.m_sMissileLauncher == 0)
  5103. {
  5104. bSetWeapon = false;
  5105. }
  5106. break;
  5107. case Napalm:
  5108. if (m_stockpile.m_sNapalmLauncher == 0)
  5109. {
  5110. bSetWeapon = false;
  5111. }
  5112. break;
  5113. case ShotGun:
  5114. if (m_stockpile.m_sShotGun == 0)
  5115. {
  5116. bSetWeapon = false;
  5117. }
  5118. break;
  5119. case SprayCannon:
  5120. if (m_stockpile.m_sSprayCannon == 0)
  5121. {
  5122. bSetWeapon = false;
  5123. }
  5124. break;
  5125. case FlameThrower:
  5126. if (m_stockpile.m_sFlameThrower == 0)
  5127. {
  5128. bSetWeapon = false;
  5129. }
  5130. break;
  5131. case BouncingBettyMine:
  5132. case ProximityMine:
  5133. case TimedMine:
  5134. // case RemoteMine: //Fixed crash when changing weapons and firing at the same time
  5135. break;
  5136. case Heatseeker:
  5137. if (m_stockpile.m_sMissileLauncher == 0)
  5138. {
  5139. bSetWeapon = false;
  5140. }
  5141. break;
  5142. case DeathWad:
  5143. if (m_stockpile.m_sDeathWadLauncher == 0)
  5144. {
  5145. bSetWeapon = false;
  5146. }
  5147. break;
  5148. case DoubleBarrel:
  5149. if (m_stockpile.m_sDoubleBarrel == 0)
  5150. {
  5151. bSetWeapon = false;
  5152. }
  5153. break;
  5154. default:
  5155. bSetWeapon = false;
  5156. break;
  5157. }
  5158. // Get info on this weapon.
  5159. ClassIDType idDummy;
  5160. short* psNum;
  5161. GetWeaponInfo(weapon, &idDummy, &psNum);
  5162. // If weapon was available . . .
  5163. if (bSetWeapon == true)
  5164. {
  5165. // If we have no ammo for this one . . .
  5166. if (*psNum <= 0)
  5167. {
  5168. // If set we cannot set when no ammo . . .
  5169. if (bSetIfNoAmmo == false)
  5170. {
  5171. bSetWeapon = false;
  5172. }
  5173. else
  5174. {
  5175. PlaySample(g_smidEmptyWeapon, SampleMaster::UserFeedBack);
  5176. }
  5177. }
  5178. else
  5179. {
  5180. if (bSetIfNoAmmo == true)
  5181. {
  5182. PlaySample(g_smidLoadedWeapon, SampleMaster::UserFeedBack);
  5183. }
  5184. }
  5185. // If able to change weapons . . .
  5186. if (bSetWeapon == true)
  5187. {
  5188. // Set new weapon.
  5189. m_weapontypeCur = weapon;
  5190. // If we have ammo . . .
  5191. if (*psNum > 0)
  5192. {
  5193. GameMessage msg;
  5194. msg.msg_WeaponSelect.eType = typeWeaponSelect;
  5195. msg.msg_WeaponSelect.sPriority = 0;
  5196. msg.msg_WeaponSelect.sWeapon = (short) m_weapontypeCur;
  5197. CThing* pDemon = m_pRealm->m_aclassHeads[CThing::CDemonID].GetNext();
  5198. if (pDemon)
  5199. SendThingMessage(&msg, pDemon);
  5200. }
  5201. }
  5202. }
  5203. else
  5204. {
  5205. if (bSetIfNoAmmo == true)
  5206. {
  5207. PlaySample(g_smidEmptyWeapon, SampleMaster::UserFeedBack);
  5208. }
  5209. }
  5210. return bSetWeapon;
  5211. }
  5212. ////////////////////////////////////////////////////////////////////////////////
  5213. // Drop a powerup with the settings described by the specified stockpile.
  5214. ////////////////////////////////////////////////////////////////////////////////
  5215. CPowerUp* CDude::DropPowerUp( // Returns new powerup on success; NULL on failure.
  5216. CStockPile* pstockpile, // In: Settings for powerup.
  5217. bool bCurWeaponOnly) // In: true, if only the current weapon should be
  5218. // in the powerup; false, if all.
  5219. {
  5220. CPowerUp* ppowerup = NULL;
  5221. // If not empty . . .
  5222. if (pstockpile->IsEmpty() == false)
  5223. {
  5224. // Create powerup . . .
  5225. if (ConstructWithID(CPowerUpID, m_pRealm, (CThing**)&ppowerup) == 0)
  5226. {
  5227. // Put stockpile into powerup.
  5228. ppowerup->m_stockpile.Copy(pstockpile);
  5229. if (bCurWeaponOnly)
  5230. {
  5231. // Note whether we had the weapon. Not sure how it would be possible
  5232. // but just in case we can somehow have a weapon selected that we do
  5233. // hot have.
  5234. short sHasWeapon = ppowerup->m_stockpile.GetWeapon(m_weapontypeCur);
  5235. // Remove all but our current weapon.
  5236. short sIndex;
  5237. for (sIndex = SemiAutomatic; sIndex <= DoubleBarrel; sIndex++)
  5238. {
  5239. // Zero.
  5240. ppowerup->m_stockpile.GetWeapon(sIndex) = 0;
  5241. }
  5242. // Add back our currently selected weapon.
  5243. ppowerup->m_stockpile.GetWeapon(m_weapontypeCur) = sHasWeapon;
  5244. }
  5245. // Place powerup at our feet.
  5246. ppowerup->Setup(m_dX, m_dY, m_dZ);
  5247. }
  5248. }
  5249. return ppowerup;
  5250. }
  5251. ////////////////////////////////////////////////////////////////////////////////
  5252. // Play a step noise if the event is different from the last.
  5253. ////////////////////////////////////////////////////////////////////////////////
  5254. void CDude::PlayStep(void) // Returns nothing.
  5255. {
  5256. #if 1
  5257. // If there is an event channel . . .
  5258. if (m_panimCur->m_pevent != NULL)
  5259. {
  5260. // If the current event is different from the last . . .
  5261. U8 u8Event = *((U8*)(m_panimCur->m_pevent->GetAtTime(m_lAnimTime)) );
  5262. if (u8Event > 0 && u8Event != m_u8LastEvent)
  5263. {
  5264. PlaySample(g_smidStep, SampleMaster::Unspecified);
  5265. m_u8LastEvent = u8Event;
  5266. }
  5267. }
  5268. #endif
  5269. }
  5270. ////////////////////////////////////////////////////////////////////////////////
  5271. // Find someone to execute.
  5272. ////////////////////////////////////////////////////////////////////////////////
  5273. bool CDude::FindExecutee(void) // Returns true, if we found one; false, otherwise.
  5274. {
  5275. bool bFoundOne = false; // Assume not found.
  5276. CSmash* psmashee = NULL; // Safety.
  5277. // Find the closest person including writhers.
  5278. if (m_pRealm->m_smashatorium.QuickCheckClosest(
  5279. &m_smash, // In: CSmash to check
  5280. /* CSmash::Character
  5281. | CSmash::Misc
  5282. | CSmash::Barrel
  5283. | CSmash::Mine
  5284. | */CSmash::AlmostDead, // In: Bits we can hit.
  5285. 0, // In: Bits that you don't care about
  5286. 0, // In: Bits that must be 0 to collide with a given CSmash
  5287. &psmashee) == true)
  5288. {
  5289. // We can handle anyone that wants to reveal their location . . .
  5290. // This can be done via the GetX/Y/Z() functions or their smash . . .
  5291. if ( (psmashee->m_pThing->GetX() != CThing::InvalidPosition
  5292. && psmashee->m_pThing->GetY() != CThing::InvalidPosition
  5293. && psmashee->m_pThing->GetZ() != CThing::InvalidPosition)
  5294. || psmashee->m_pThing->GetSprite() )
  5295. {
  5296. // Found one.
  5297. bFoundOne = true;
  5298. // Remember who.
  5299. m_idVictim = psmashee->m_pThing->GetInstanceID();
  5300. }
  5301. }
  5302. return bFoundOne;
  5303. }
  5304. ////////////////////////////////////////////////////////////////////////////////
  5305. // Track executee.
  5306. ////////////////////////////////////////////////////////////////////////////////
  5307. bool CDude::TrackExecutee( // Returns true to persist, false, if we lost the target.
  5308. double dSeconds) // In: Seconds since last iteration.
  5309. {
  5310. bool bPersist = true; // Assume we'll persist.
  5311. // Get pointer to target.
  5312. CThing* pthing;
  5313. if (m_pRealm->m_idbank.GetThingByID(&pthing, m_idVictim) == 0)
  5314. {
  5315. double dVictimX;
  5316. double dVictimZ;
  5317. // Try to use smash position first, then resort to thing position.
  5318. CSmash* psmash = pthing->GetSmash();
  5319. if (psmash != NULL)
  5320. {
  5321. // This is generally more accurate for an execution point.
  5322. dVictimX = psmash->m_sphere.sphere.X;
  5323. dVictimZ = psmash->m_sphere.sphere.Z;
  5324. }
  5325. else
  5326. {
  5327. // This'll do though.
  5328. dVictimX = pthing->GetX();
  5329. dVictimZ = pthing->GetZ();
  5330. }
  5331. short sDistX = dVictimX - m_dX;
  5332. short sDistZ = m_dZ - dVictimZ;
  5333. double dSqrDistanceXZ = ABS2(sDistX, sDistZ);
  5334. // Determine angle to target.
  5335. double dRot = rspATan(sDistZ, sDistX);
  5336. // Determine which rotation direction to target is smaller.
  5337. double dDelta = rspDegDelta(m_dRot, dRot);
  5338. // If turning counter clockwise . . .
  5339. if (dDelta > 0.0)
  5340. {
  5341. m_dRot += MIN(dDelta, g_InputSettings.m_dStillFastDegreesPerSec * dSeconds);
  5342. }
  5343. else
  5344. {
  5345. m_dRot += MAX(dDelta, -g_InputSettings.m_dStillFastDegreesPerSec * dSeconds);
  5346. }
  5347. #if 1
  5348. // If too close . . .
  5349. if (dSqrDistanceXZ < MIN_SQR_DISTANCE_TO_EXECUTEE)
  5350. {
  5351. // Back up.
  5352. m_dVel = dSqrDistanceXZ - MIN_SQR_DISTANCE_TO_EXECUTEE;
  5353. }
  5354. #else
  5355. // Another solution, if we don't like the above, is to take
  5356. // the gun and use a transform we create (rather than the
  5357. // rigid body one) and aim the gun directly at the target
  5358. // point.
  5359. #endif
  5360. }
  5361. else
  5362. {
  5363. // Lost our target. Continuing is futile.
  5364. m_idVictim = CIdBank::IdNil;
  5365. bPersist = false;
  5366. }
  5367. return bPersist;
  5368. }
  5369. ////////////////////////////////////////////////////////////////////////////////
  5370. // Take a powerup.
  5371. ////////////////////////////////////////////////////////////////////////////////
  5372. void CDude::TakePowerUp( // Returns nothing.
  5373. CPowerUp** pppowerup) // In: Power up to take from.
  5374. // Out: Ptr to powerup, if it persisted; NULL otherwise.
  5375. {
  5376. CStockPile* pspMax;
  5377. // Note if we do or will have the backpack.
  5378. if (m_stockpile.m_sBackpack || (*pppowerup)->m_stockpile.m_sBackpack)
  5379. {
  5380. pspMax = &CStockPile::ms_stockpileBackPackMax;
  5381. }
  5382. else
  5383. {
  5384. pspMax = &CStockPile::ms_stockpileMax;
  5385. }
  5386. // Create a stockpile of the amount we can take from the powerup.
  5387. CStockPile spTake;
  5388. spTake.Copy(pspMax);
  5389. spTake.Sub(&m_stockpile);
  5390. // Intersect the amount we can take with the amount available.
  5391. spTake.Intersect( &( (*pppowerup)->m_stockpile) );
  5392. // If we got anything . . .
  5393. if (spTake.IsEmpty() == false)
  5394. {
  5395. // Cash it in.
  5396. m_stockpile.Add( &spTake );
  5397. // If in MP mode, empty the powerup so it goes away. Otherwise, just remove what we took
  5398. if (m_pRealm->m_flags.bMultiplayer)
  5399. (*pppowerup)->m_stockpile.Zero();
  5400. else
  5401. (*pppowerup)->m_stockpile.Sub( &spTake );
  5402. // Play feedback.
  5403. (*pppowerup)->PickUpFeedback();
  5404. // Store its ID so we can attempt to get it if it does persist.
  5405. U16 idInstance = (*pppowerup)->GetInstanceID();
  5406. // Let powerup decide if it should persist.
  5407. (*pppowerup)->RepaginateNow();
  5408. // If it persisted . . .
  5409. if (m_pRealm->m_idbank.GetThingByID((CThing**)pppowerup, idInstance) == 0)
  5410. {
  5411. ASSERT( (*pppowerup)->GetClassID() == CPowerUpID);
  5412. }
  5413. else
  5414. {
  5415. *pppowerup = NULL;
  5416. }
  5417. }
  5418. else
  5419. {
  5420. // Temp feedback for needed nothing from the weapon.
  5421. PlaySample(g_smidOutOfBullets, SampleMaster::UserFeedBack);
  5422. // If in MP mode, eat the powerup
  5423. if (m_pRealm->m_flags.bMultiplayer)
  5424. {
  5425. (*pppowerup)->m_stockpile.Zero();
  5426. (*pppowerup)->RepaginateNow();
  5427. *pppowerup = NULL;
  5428. }
  5429. }
  5430. // If it still exists . . .
  5431. if (*pppowerup)
  5432. {
  5433. // Store its ID so we can attempt to get it if it does persist.
  5434. U16 idInstance = (*pppowerup)->GetInstanceID();
  5435. // Toss it.
  5436. TossPowerUp(*pppowerup, 130);
  5437. // If it persisted . . .
  5438. if (m_pRealm->m_idbank.GetThingByID((CThing**)pppowerup, idInstance) == 0)
  5439. {
  5440. ASSERT( (*pppowerup)->GetClassID() == CPowerUpID);
  5441. }
  5442. else
  5443. {
  5444. *pppowerup = NULL;
  5445. }
  5446. }
  5447. }
  5448. ////////////////////////////////////////////////////////////////////////////////
  5449. // Create a cheat powerup.
  5450. ////////////////////////////////////////////////////////////////////////////////
  5451. CPowerUp* CDude::CreateCheat( // Returns new powerup on success; NULL on failure.
  5452. CStockPile* pstockpile) // In: Settings for powerup.
  5453. {
  5454. // First deduct from the cheat powerup what we cannot use.
  5455. CStockPile spUsable;
  5456. spUsable.Copy( m_stockpile.m_sBackpack ? &CStockPile::ms_stockpileBackPackMax : &CStockPile::ms_stockpileMax );
  5457. spUsable.Sub( &m_stockpile );
  5458. // Intersect with the supplied.
  5459. spUsable.Intersect(pstockpile);
  5460. // Finally, drop it.
  5461. // If it contains anything . . .
  5462. CPowerUp* ppowerup;
  5463. if (spUsable.IsEmpty() == false)
  5464. {
  5465. ppowerup = DropPowerUp( &spUsable, false );
  5466. if (ppowerup)
  5467. {
  5468. // Take it right away.
  5469. TakePowerUp(&ppowerup);
  5470. }
  5471. }
  5472. else
  5473. {
  5474. ppowerup = NULL;
  5475. }
  5476. UnlockAchievement(ACHIEVEMENT_ENABLE_CHEATS);
  5477. Flag_Achievements |= FLAG_USED_CHEATS;
  5478. // Let the demon know.that they are cheating
  5479. GameMessage msg;
  5480. msg.msg_Cheater.eType = typeCheater;
  5481. msg.msg_Cheater.sPriority = 0;
  5482. CThing* pDemon = m_pRealm->m_aclassHeads[CThing::CDemonID].GetNext();
  5483. if (pDemon)
  5484. SendThingMessage(&msg, pDemon);
  5485. return ppowerup;
  5486. }
  5487. ////////////////////////////////////////////////////////////////////////////////
  5488. // Break a powerup open and toss it.
  5489. ////////////////////////////////////////////////////////////////////////////////
  5490. void CDude::TossPowerUp( // Returns nothing.
  5491. CPowerUp* ppowerup, // In: Powerup to toss.
  5492. short sVelocity) // In: Velocity of toss.
  5493. {
  5494. // Blow it up.
  5495. GameMessage msg;
  5496. msg.msg_Explosion.eType = typeExplosion;
  5497. msg.msg_Explosion.sPriority = 0;
  5498. msg.msg_Explosion.sDamage = 0;
  5499. msg.msg_Explosion.sX = m_dX;
  5500. msg.msg_Explosion.sY = m_dY;
  5501. msg.msg_Explosion.sZ = m_dZ;
  5502. msg.msg_Explosion.sVelocity = sVelocity;
  5503. msg.msg_Explosion.u16ShooterID = GetInstanceID();
  5504. SendThingMessage(&msg, msg.msg_Explosion.sPriority, ppowerup);
  5505. }
  5506. ////////////////////////////////////////////////////////////////////////////////
  5507. // Get the current weapon the dude has ready to use.
  5508. ////////////////////////////////////////////////////////////////////////////////
  5509. CDude::WeaponType CDude::GetCurrentWeapon(void)
  5510. {
  5511. return m_weapontypeCur;
  5512. }
  5513. ////////////////////////////////////////////////////////////////////////////////
  5514. // Sets the dude's position. It is very important that the dude is not
  5515. // moved by outside things, other than the warp.
  5516. ////////////////////////////////////////////////////////////////////////////////
  5517. void CDude::SetPosition( // Returns nothing.
  5518. double dX, // In: New position for dude.
  5519. double dY, // In: New position for dude.
  5520. double dZ) // In: New position for dude.
  5521. {
  5522. // Set position and update crawler position.
  5523. m_dLastCrawledToPosX = m_dX = dX;
  5524. m_dY = dY;
  5525. m_dLastCrawledToPosZ = m_dZ = dZ;
  5526. }
  5527. ////////////////////////////////////////////////////////////////////////////////
  5528. // Get the next child flag item after the specified flag item.
  5529. ////////////////////////////////////////////////////////////////////////////////
  5530. CFlag* CDude::GetNextFlag( // Returns the next flag item after pflag.
  5531. CFlag* pflag) // In: The flag to get the follower of.
  5532. // NULL for first child flag.
  5533. {
  5534. CFlag* pflagNext = NULL;
  5535. CSprite* psprite = pflag ? pflag->m_sprite.m_psprNext : m_sprite.m_psprHeadChild;
  5536. while (psprite && pflagNext == NULL)
  5537. {
  5538. // If this sprite names its owner . . .
  5539. CThing* pthing = psprite->m_pthing;
  5540. if (pthing)
  5541. {
  5542. // If it is a flag . . .
  5543. if (pthing->GetClassID() == CFlagID)
  5544. {
  5545. pflagNext = (CFlag*)pthing;
  5546. }
  5547. }
  5548. // Next Please.
  5549. psprite = psprite->m_psprNext;
  5550. }
  5551. return pflagNext;
  5552. }
  5553. ////////////////////////////////////////////////////////////////////////////////
  5554. // Drop all child flag items.
  5555. ////////////////////////////////////////////////////////////////////////////////
  5556. void CDude::DropAllFlags( // Returns nothing.
  5557. GameMessage* pmsg) // In: Message to pass to flags.
  5558. {
  5559. GameMessage msg;
  5560. // If no message specified . . .
  5561. if (pmsg == NULL)
  5562. {
  5563. msg.msg_Explosion.eType = typeExplosion;
  5564. msg.msg_Explosion.sPriority = 0;
  5565. msg.msg_Explosion.sDamage = 10;
  5566. msg.msg_Explosion.sX = (short) m_dX;
  5567. msg.msg_Explosion.sY = (short) m_dY;
  5568. msg.msg_Explosion.sZ = (short) m_dZ;
  5569. msg.msg_Explosion.sVelocity = 30;
  5570. msg.msg_Explosion.u16ShooterID = GetInstanceID();
  5571. pmsg = &msg;
  5572. }
  5573. else
  5574. {
  5575. // If it is an explosion message . . .
  5576. if (pmsg->msg_Generic.eType == typeExplosion)
  5577. {
  5578. // Copy it so we can tweak it.
  5579. msg = *pmsg;
  5580. }
  5581. }
  5582. // Loop through all child flags and send them a message and remove them.
  5583. CFlag* pflag = GetNextFlag(NULL);
  5584. CFlag* pflagNext;
  5585. while (pflag)
  5586. {
  5587. // Get the next now b/c this won't be a sibling after we detach it.
  5588. pflagNext = GetNextFlag(pflag);
  5589. U16 u16IdFlag = pflag->GetInstanceID();
  5590. // Detach the flag.
  5591. DetachChild(
  5592. &u16IdFlag,
  5593. ((CDudeAnim3D*) m_panimCur)->m_ptransLeft->GetAtTime(m_lAnimTime) );
  5594. // Move it to our position rather than the transformed position b/c we
  5595. // don't know if that's a valid position but we do know that our position
  5596. // is.
  5597. pflag->m_dX = m_dX;
  5598. pflag->m_dY = m_dY;
  5599. pflag->m_dZ = m_dZ;
  5600. // If it's an explosion . . .
  5601. if (pmsg->msg_Generic.eType == typeExplosion)
  5602. {
  5603. // Tweak the message a little.
  5604. pmsg->msg_Explosion.sX = (short) m_dX + RAND_SWAY(30);
  5605. pmsg->msg_Explosion.sZ = (short) m_dZ + RAND_SWAY(30);
  5606. }
  5607. // Forward the specified message.
  5608. SendThingMessage(
  5609. pmsg,
  5610. pflag);
  5611. // Next please.
  5612. pflag = pflagNext;
  5613. }
  5614. }
  5615. ////////////////////////////////////////////////////////////////////////////////
  5616. // EOF
  5617. ////////////////////////////////////////////////////////////////////////////////