g_active.cpp 178 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805
  1. // leave this line at the top for all g_xxxx.cpp files...
  2. #include "g_headers.h"
  3. #include "g_local.h"
  4. #include "g_functions.h"
  5. #include "..\cgame\cg_local.h"
  6. #include "Q3_Interface.h"
  7. #include "wp_saber.h"
  8. #include "g_vehicles.h"
  9. #ifdef _DEBUG
  10. #include <float.h>
  11. #endif //_DEBUG
  12. #define SLOWDOWN_DIST 128.0f
  13. #define MIN_NPC_SPEED 16.0f
  14. #ifdef _XBOX
  15. int g_lastFireTime = 0;
  16. #endif
  17. extern void VehicleExplosionDelay( gentity_t *self );
  18. extern qboolean Q3_TaskIDPending( gentity_t *ent, taskID_t taskType );
  19. extern void G_MaintainFormations(gentity_t *self);
  20. extern void BG_CalculateOffsetAngles( gentity_t *ent, usercmd_t *ucmd );//in bg_pangles.cpp
  21. extern void TryUse( gentity_t *ent );
  22. extern void ChangeWeapon( gentity_t *ent, int newWeapon );
  23. extern void ScoreBoardReset(void);
  24. extern void WP_SaberReflectCheck( gentity_t *self, usercmd_t *ucmd );
  25. extern void WP_SaberUpdate( gentity_t *self, usercmd_t *ucmd );
  26. extern void WP_SaberStartMissileBlockCheck( gentity_t *self, usercmd_t *ucmd );
  27. extern void WP_ForcePowersUpdate( gentity_t *self, usercmd_t *ucmd );
  28. extern gentity_t *SeekerAcquiresTarget ( gentity_t *ent, vec3_t pos );
  29. extern void FireSeeker( gentity_t *owner, gentity_t *target, vec3_t origin, vec3_t dir );
  30. extern qboolean InFront( vec3_t spot, vec3_t from, vec3_t fromAngles, float threshHold = 0.0f );
  31. extern float DotToSpot( vec3_t spot, vec3_t from, vec3_t fromAngles );
  32. extern void NPC_SetLookTarget( gentity_t *self, int entNum, int clearTime );
  33. extern qboolean PM_LockAngles( gentity_t *ent, usercmd_t *ucmd );
  34. extern qboolean PM_AdjustAnglesToGripper( gentity_t *gent, usercmd_t *cmd );
  35. extern qboolean PM_AdjustAnglesToPuller( gentity_t *ent, gentity_t *puller, usercmd_t *ucmd, qboolean faceAway );
  36. extern qboolean PM_AdjustAngleForWallRun( gentity_t *ent, usercmd_t *ucmd, qboolean doMove );
  37. extern qboolean PM_AdjustAngleForWallRunUp( gentity_t *ent, usercmd_t *ucmd, qboolean doMove );
  38. extern qboolean PM_AdjustAnglesForSpinningFlip( gentity_t *ent, usercmd_t *ucmd, qboolean anglesOnly );
  39. extern qboolean PM_AdjustAnglesForBackAttack( gentity_t *ent, usercmd_t *ucmd );
  40. extern qboolean PM_AdjustAnglesForSaberLock( gentity_t *ent, usercmd_t *ucmd );
  41. extern qboolean PM_AdjustAnglesForKnockdown( gentity_t *ent, usercmd_t *ucmd, qboolean angleClampOnly );
  42. extern qboolean PM_AdjustAnglesForDualJumpAttack( gentity_t *ent, usercmd_t *ucmd );
  43. extern qboolean PM_AdjustAnglesForLongJump( gentity_t *ent, usercmd_t *ucmd );
  44. extern qboolean PM_AdjustAnglesForGrapple( gentity_t *ent, usercmd_t *ucmd );
  45. extern qboolean PM_AdjustAngleForWallJump( gentity_t *ent, usercmd_t *ucmd, qboolean doMove );
  46. extern qboolean PM_AdjustAnglesForBFKick( gentity_t *ent, usercmd_t *ucmd, vec3_t fwdAngs, qboolean aimFront );
  47. extern qboolean PM_AdjustAnglesForStabDown( gentity_t *ent, usercmd_t *ucmd );
  48. extern qboolean PM_AdjustAnglesForSpinProtect( gentity_t *ent, usercmd_t *ucmd );
  49. extern qboolean PM_AdjustAnglesForWallRunUpFlipAlt( gentity_t *ent, usercmd_t *ucmd );
  50. extern qboolean PM_AdjustAnglesForHeldByMonster( gentity_t *ent, gentity_t *monster, usercmd_t *ucmd );
  51. extern qboolean PM_HasAnimation( gentity_t *ent, int animation );
  52. extern qboolean PM_LeapingSaberAnim( int anim );
  53. extern qboolean PM_SpinningSaberAnim( int anim );
  54. extern qboolean PM_SaberInAttack( int move );
  55. extern qboolean PM_KickingAnim( int anim );
  56. extern int PM_AnimLength( int index, animNumber_t anim );
  57. extern qboolean PM_InKnockDown( playerState_t *ps );
  58. extern qboolean PM_InGetUp( playerState_t *ps );
  59. extern qboolean PM_InRoll( playerState_t *ps );
  60. extern void PM_CmdForRoll( playerState_t *ps, usercmd_t *pCmd );
  61. extern qboolean PM_InAttackRoll( int anim );
  62. extern qboolean PM_CrouchAnim( int anim );
  63. extern qboolean PM_FlippingAnim( int anim );
  64. extern qboolean PM_InCartwheel( int anim );
  65. extern qboolean PM_StandingAnim( int anim );
  66. extern qboolean PM_InForceGetUp( playerState_t *ps );
  67. extern qboolean PM_GetupAnimNoMove( int legsAnim );
  68. extern qboolean PM_SuperBreakLoseAnim( int anim );
  69. extern qboolean PM_SuperBreakWinAnim( int anim );
  70. extern qboolean PM_CanRollFromSoulCal( playerState_t *ps );
  71. extern qboolean BG_FullBodyTauntAnim( int anim );
  72. extern qboolean FlyingCreature( gentity_t *ent );
  73. extern Vehicle_t *G_IsRidingVehicle( gentity_t *ent );
  74. extern void G_AttachToVehicle( gentity_t *ent, usercmd_t **ucmd );
  75. extern void G_GetBoltPosition( gentity_t *self, int boltIndex, vec3_t pos, int modelIndex = 0 );
  76. extern void G_UpdateEmplacedWeaponData( gentity_t *ent );
  77. extern void RunEmplacedWeapon( gentity_t *ent, usercmd_t **ucmd );
  78. extern qboolean G_PointInBounds( const vec3_t point, const vec3_t mins, const vec3_t maxs );
  79. extern void NPC_SetPainEvent( gentity_t *self );
  80. extern qboolean G_HasKnockdownAnims( gentity_t *ent );
  81. extern int G_GetEntsNearBolt( gentity_t *self, gentity_t **radiusEnts, float radius, int boltIndex, vec3_t boltOrg );
  82. extern qboolean PM_InOnGroundAnim ( playerState_t *ps );
  83. extern qboolean PM_LockedAnim( int anim );
  84. extern qboolean WP_SabersCheckLock2( gentity_t *attacker, gentity_t *defender, sabersLockMode_t lockMode );
  85. extern qboolean G_JediInNormalAI( gentity_t *ent );
  86. extern bool in_camera;
  87. extern qboolean player_locked;
  88. extern qboolean stop_icarus;
  89. extern qboolean MatrixMode;
  90. extern cvar_t *g_spskill;
  91. extern cvar_t *g_timescale;
  92. extern cvar_t *g_saberMoveSpeed;
  93. extern cvar_t *g_saberAutoBlocking;
  94. extern cvar_t *g_speederControlScheme;
  95. extern cvar_t *d_slowmodeath;
  96. extern cvar_t *g_debugMelee;
  97. extern vmCvar_t cg_thirdPersonAlpha;
  98. extern vmCvar_t cg_thirdPersonAutoAlpha;
  99. void ClientEndPowerUps( gentity_t *ent );
  100. int G_FindLookItem( gentity_t *self )
  101. {
  102. //FIXME: should be a more intelligent way of doing this, like auto aim?
  103. //closest, most in front... did damage to... took damage from? How do we know who the player is focusing on?
  104. gentity_t *ent;
  105. int bestEntNum = ENTITYNUM_NONE;
  106. gentity_t *entityList[MAX_GENTITIES];
  107. int numListedEntities;
  108. vec3_t center, mins, maxs, fwdangles, forward, dir;
  109. int i, e;
  110. float radius = 256;
  111. float rating, bestRating = 0.0f;
  112. //FIXME: no need to do this in 1st person?
  113. fwdangles[1] = self->client->ps.viewangles[1];
  114. AngleVectors( fwdangles, forward, NULL, NULL );
  115. VectorCopy( self->currentOrigin, center );
  116. for ( i = 0 ; i < 3 ; i++ )
  117. {
  118. mins[i] = center[i] - radius;
  119. maxs[i] = center[i] + radius;
  120. }
  121. numListedEntities = gi.EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  122. if ( !numListedEntities )
  123. {
  124. return ENTITYNUM_NONE;
  125. }
  126. for ( e = 0 ; e < numListedEntities ; e++ )
  127. {
  128. ent = entityList[ e ];
  129. if ( !ent->item )
  130. {
  131. continue;
  132. }
  133. if ( ent->s.eFlags&EF_NODRAW )
  134. {
  135. continue;
  136. }
  137. if ( (ent->spawnflags&4/*ITMSF_MONSTER*/) )
  138. {//NPCs only
  139. continue;
  140. }
  141. if ( !BG_CanItemBeGrabbed( &ent->s, &self->client->ps ) )
  142. {//don't need it
  143. continue;
  144. }
  145. if ( !gi.inPVS( self->currentOrigin, ent->currentOrigin ) )
  146. {//not even potentially visible
  147. continue;
  148. }
  149. if ( !G_ClearLOS( self, self->client->renderInfo.eyePoint, ent ) )
  150. {//can't see him
  151. continue;
  152. }
  153. //rate him based on how close & how in front he is
  154. VectorSubtract( ent->currentOrigin, center, dir );
  155. rating = (1.0f-(VectorNormalize( dir )/radius));
  156. rating *= DotProduct( forward, dir );
  157. if ( ent->item->giType == IT_HOLDABLE && ent->item->giTag == INV_SECURITY_KEY )
  158. {//security keys are of the highest importance
  159. rating *= 2.0f;
  160. }
  161. if ( rating > bestRating )
  162. {
  163. bestEntNum = ent->s.number;
  164. bestRating = rating;
  165. }
  166. }
  167. return bestEntNum;
  168. }
  169. extern void CG_SetClientViewAngles( vec3_t angles, qboolean overrideViewEnt );
  170. qboolean G_ClearViewEntity( gentity_t *ent )
  171. {
  172. if ( !ent->client->ps.viewEntity )
  173. return qfalse;
  174. if ( ent->client->ps.viewEntity > 0 && ent->client->ps.viewEntity < ENTITYNUM_NONE )
  175. {
  176. if ( &g_entities[ent->client->ps.viewEntity] )
  177. {
  178. g_entities[ent->client->ps.viewEntity].svFlags &= ~SVF_BROADCAST;
  179. if ( g_entities[ent->client->ps.viewEntity].NPC )
  180. {
  181. g_entities[ent->client->ps.viewEntity].NPC->controlledTime = 0;
  182. SetClientViewAngle( &g_entities[ent->client->ps.viewEntity], g_entities[ent->client->ps.viewEntity].currentAngles );
  183. G_SetAngles( &g_entities[ent->client->ps.viewEntity], g_entities[ent->client->ps.viewEntity].currentAngles );
  184. VectorCopy( g_entities[ent->client->ps.viewEntity].currentAngles, g_entities[ent->client->ps.viewEntity].NPC->lastPathAngles );
  185. g_entities[ent->client->ps.viewEntity].NPC->desiredYaw = g_entities[ent->client->ps.viewEntity].currentAngles[YAW];
  186. }
  187. }
  188. CG_SetClientViewAngles( ent->pos4, qtrue );
  189. SetClientViewAngle( ent, ent->pos4 );
  190. }
  191. ent->client->ps.viewEntity = 0;
  192. return qtrue;
  193. }
  194. void G_SetViewEntity( gentity_t *self, gentity_t *viewEntity )
  195. {
  196. if ( !self || !self->client || !viewEntity )
  197. {
  198. return;
  199. }
  200. if ( self->s.number == 0 && cg.zoomMode )
  201. {
  202. // yeah, it should really toggle them so it plays the end sound....
  203. cg.zoomMode = 0;
  204. }
  205. if ( viewEntity->s.number == self->client->ps.viewEntity )
  206. {
  207. return;
  208. }
  209. //clear old one first
  210. G_ClearViewEntity( self );
  211. //set new one
  212. self->client->ps.viewEntity = viewEntity->s.number;
  213. viewEntity->svFlags |= SVF_BROADCAST;
  214. //remember current angles
  215. VectorCopy( self->client->ps.viewangles, self->pos4 );
  216. if ( viewEntity->client )
  217. {
  218. //vec3_t clear = {0,0,0};
  219. CG_SetClientViewAngles( viewEntity->client->ps.viewangles, qtrue );
  220. //SetClientViewAngle( self, viewEntity->client->ps.viewangles );
  221. //SetClientViewAngle( viewEntity, clear );
  222. /*
  223. VectorCopy( viewEntity->client->ps.viewangles, self->client->ps.viewangles );
  224. for ( int i = 0; i < 3; i++ )
  225. {
  226. self->client->ps.delta_angles[i] = viewEntity->client->ps.delta_angles[i];
  227. }
  228. */
  229. }
  230. if ( !self->s.number )
  231. {
  232. CG_CenterPrint( "@SP_INGAME_EXIT_VIEW", SCREEN_HEIGHT * 0.87 );
  233. }
  234. }
  235. qboolean G_ControlledByPlayer( gentity_t *self )
  236. {
  237. if ( self && self->NPC && self->NPC->controlledTime > level.time )
  238. {//being controlled
  239. gentity_t *controller = &g_entities[0];
  240. if ( controller->client && controller->client->ps.viewEntity == self->s.number )
  241. {//we're the player's viewEntity
  242. return qtrue;
  243. }
  244. }
  245. return qfalse;
  246. }
  247. qboolean G_ValidateLookEnemy( gentity_t *self, gentity_t *enemy )
  248. {
  249. if ( !enemy )
  250. {
  251. return qfalse;
  252. }
  253. if ( enemy->flags&FL_NOTARGET )
  254. {
  255. return qfalse;
  256. }
  257. if ( (enemy->s.eFlags&EF_NODRAW) )
  258. {
  259. return qfalse;
  260. }
  261. if ( !enemy || enemy == self || !enemy->inuse )
  262. {
  263. return qfalse;
  264. }
  265. if ( !enemy->client || !enemy->NPC )
  266. {//not valid
  267. if ( (enemy->svFlags&SVF_NONNPC_ENEMY)
  268. && enemy->s.weapon == WP_TURRET
  269. && enemy->noDamageTeam != self->client->playerTeam
  270. && enemy->health > 0 )
  271. {//a turret
  272. //return qtrue;
  273. }
  274. else
  275. {
  276. return qfalse;
  277. }
  278. }
  279. else
  280. {
  281. if ( self->client->playerTeam != TEAM_FREE//evil player hates everybody
  282. && enemy->client->playerTeam == self->client->playerTeam )
  283. {//on same team
  284. return qfalse;
  285. }
  286. Vehicle_t *pVeh = G_IsRidingVehicle( self );
  287. if ( pVeh && pVeh == enemy->m_pVehicle )
  288. {
  289. return qfalse;
  290. }
  291. if ( enemy->health <= 0 && ((level.time-enemy->s.time) > 3000||!InFront(enemy->currentOrigin,self->currentOrigin,self->client->ps.viewangles,0.2f)||DistanceHorizontal(enemy->currentOrigin,self->currentOrigin)>16384))//>128
  292. {//corpse, been dead too long or too out of sight to be interesting
  293. if ( !enemy->message )
  294. {
  295. return qfalse;
  296. }
  297. }
  298. }
  299. if ( (!InFront( enemy->currentOrigin, self->currentOrigin, self->client->ps.viewangles, 0.0f) || !G_ClearLOS( self, self->client->renderInfo.eyePoint, enemy ) )
  300. && ( DistanceHorizontalSquared( enemy->currentOrigin, self->currentOrigin ) > 65536 || fabs(enemy->currentOrigin[2]-self->currentOrigin[2]) > 384 ) )
  301. {//(not in front or not clear LOS) & greater than 256 away
  302. return qfalse;
  303. }
  304. //LOS?
  305. return qtrue;
  306. }
  307. void G_ChooseLookEnemy( gentity_t *self, usercmd_t *ucmd )
  308. {
  309. //FIXME: should be a more intelligent way of doing this, like auto aim?
  310. //closest, most in front... did damage to... took damage from? How do we know who the player is focusing on?
  311. gentity_t *ent, *bestEnt = NULL;
  312. gentity_t *entityList[MAX_GENTITIES];
  313. int numListedEntities;
  314. vec3_t center, mins, maxs, fwdangles, forward, dir;
  315. int i, e;
  316. float radius = 256;
  317. float rating, bestRating = 0.0f;
  318. //FIXME: no need to do this in 1st person?
  319. fwdangles[0] = 0; //Must initialize data!
  320. fwdangles[1] = self->client->ps.viewangles[1];
  321. fwdangles[2] = 0;
  322. AngleVectors( fwdangles, forward, NULL, NULL );
  323. VectorCopy( self->currentOrigin, center );
  324. for ( i = 0 ; i < 3 ; i++ )
  325. {
  326. mins[i] = center[i] - radius;
  327. maxs[i] = center[i] + radius;
  328. }
  329. numListedEntities = gi.EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  330. if ( !numListedEntities )
  331. {//should we clear the enemy?
  332. return;
  333. }
  334. for ( e = 0 ; e < numListedEntities ; e++ )
  335. {
  336. ent = entityList[ e ];
  337. if ( !gi.inPVS( self->currentOrigin, ent->currentOrigin ) )
  338. {//not even potentially visible
  339. continue;
  340. }
  341. if ( !G_ValidateLookEnemy( self, ent ) )
  342. {//doesn't meet criteria of valid look enemy (don't check current since we would have done that before this func's call
  343. continue;
  344. }
  345. if ( !G_ClearLOS( self, self->client->renderInfo.eyePoint, ent ) )
  346. {//can't see him
  347. continue;
  348. }
  349. //rate him based on how close & how in front he is
  350. VectorSubtract( ent->currentOrigin, center, dir );
  351. rating = (1.0f-(VectorNormalize( dir )/radius));
  352. rating *= DotProduct( forward, dir )+1.0f;
  353. if ( ent->health <= 0 )
  354. {
  355. if ( (ucmd->buttons&BUTTON_ATTACK)
  356. || (ucmd->buttons&BUTTON_ALT_ATTACK)
  357. || (ucmd->buttons&BUTTON_FORCE_FOCUS) )
  358. {//if attacking, don't consider dead enemies
  359. continue;
  360. }
  361. if ( ent->message )
  362. {//keyholder
  363. rating *= 0.5f;
  364. }
  365. else
  366. {
  367. rating *= 0.1f;
  368. }
  369. }
  370. if ( ent->s.weapon == WP_SABER )
  371. {
  372. rating *= 2.0f;
  373. }
  374. if ( ent->enemy == self )
  375. {//he's mad at me, he's more important
  376. rating *= 2.0f;
  377. }
  378. else if ( ent->NPC && ent->NPC->blockedSpeechDebounceTime > level.time - 6000 )
  379. {//he's detected me, he's more important
  380. if ( ent->NPC->blockedSpeechDebounceTime > level.time + 4000 )
  381. {
  382. rating *= 1.5f;
  383. }
  384. else
  385. {//from 1.0f to 1.5f
  386. rating += rating * ((float)(ent->NPC->blockedSpeechDebounceTime-level.time) + 6000.0f)/20000.0f;
  387. }
  388. }
  389. /*
  390. if ( g_crosshairEntNum == ent && !self->enemy )
  391. {//we don't have an enemy and we are aiming at this guy
  392. rading *= 2.0f;
  393. }
  394. */
  395. if ( rating > bestRating )
  396. {
  397. bestEnt = ent;
  398. bestRating = rating;
  399. }
  400. }
  401. if ( bestEnt )
  402. {
  403. self->enemy = bestEnt;
  404. }
  405. }
  406. /*
  407. ===============
  408. G_DamageFeedback
  409. Called just before a snapshot is sent to the given player.
  410. Totals up all damage and generates both the player_state_t
  411. damage values to that client for pain blends and kicks, and
  412. global pain sound events for all clients.
  413. ===============
  414. */
  415. void P_DamageFeedback( gentity_t *player ) {
  416. gclient_t *client;
  417. float count;
  418. vec3_t angles;
  419. client = player->client;
  420. if ( client->ps.pm_type == PM_DEAD ) {
  421. return;
  422. }
  423. // total points of damage shot at the player this frame
  424. count = client->damage_blood + client->damage_armor;
  425. if ( count == 0 ) {
  426. return; // didn't take any damage
  427. }
  428. if ( count > 255 ) {
  429. count = 255;
  430. }
  431. // send the information to the client
  432. // world damage (falling, slime, etc) uses a special code
  433. // to make the blend blob centered instead of positional
  434. if ( client->damage_fromWorld )
  435. {
  436. client->ps.damagePitch = 255;
  437. client->ps.damageYaw = 255;
  438. client->damage_fromWorld = false;
  439. }
  440. else
  441. {
  442. vectoangles( client->damage_from, angles );
  443. client->ps.damagePitch = angles[PITCH]/360.0 * 256;
  444. client->ps.damageYaw = angles[YAW]/360.0 * 256;
  445. }
  446. client->ps.damageCount = count;
  447. //
  448. // clear totals
  449. //
  450. client->damage_blood = 0;
  451. client->damage_armor = 0;
  452. }
  453. /*
  454. =============
  455. P_WorldEffects
  456. Check for lava / slime contents and drowning
  457. =============
  458. */
  459. extern void WP_ForcePowerStart( gentity_t *self, forcePowers_t forcePower, int overrideAmt );
  460. void P_WorldEffects( gentity_t *ent ) {
  461. int mouthContents = 0;
  462. if ( ent->client->noclip )
  463. {
  464. ent->client->airOutTime = level.time + 12000; // don't need air
  465. return;
  466. }
  467. if ( !in_camera )
  468. {
  469. #ifndef _XBOX
  470. if (gi.totalMapContents() & (CONTENTS_WATER|CONTENTS_SLIME))
  471. {
  472. mouthContents = gi.pointcontents( ent->client->renderInfo.eyePoint, ent->s.number );
  473. }
  474. #endif // _XBOX
  475. }
  476. //
  477. // check for drowning
  478. //
  479. #ifdef _XBOX
  480. // using waterlevel 3 should be good enough
  481. // this saves us from doing an expensive trace
  482. if ( ent->waterlevel == 3 )
  483. #else
  484. if ( (mouthContents&(CONTENTS_WATER|CONTENTS_SLIME)) )
  485. #endif // _XBOX
  486. {
  487. if ( ent->client->NPC_class == CLASS_SWAMPTROOPER )
  488. {//they have air tanks
  489. ent->client->airOutTime = level.time + 12000; // don't need air
  490. ent->damage = 2;
  491. }
  492. else if ( ent->client->airOutTime < level.time)
  493. {// if out of air, start drowning
  494. // drown!
  495. ent->client->airOutTime += 1000;
  496. if ( ent->health > 0 ) {
  497. // take more damage the longer underwater
  498. ent->damage += 2;
  499. if (ent->damage > 15)
  500. ent->damage = 15;
  501. // play a gurp sound instead of a normal pain sound
  502. if (ent->health <= ent->damage)
  503. {
  504. G_AddEvent( ent, EV_WATER_DROWN, 0 );
  505. }
  506. else
  507. {
  508. G_AddEvent( ent, Q_irand(EV_WATER_GURP1, EV_WATER_GURP2), 0 );
  509. }
  510. // don't play a normal pain sound
  511. ent->painDebounceTime = level.time + 200;
  512. G_Damage (ent, NULL, NULL, NULL, NULL,
  513. ent->damage, DAMAGE_NO_ARMOR, MOD_WATER);
  514. }
  515. }
  516. }
  517. else
  518. {
  519. ent->client->airOutTime = level.time + 12000;
  520. ent->damage = 2;
  521. }
  522. //
  523. // check for sizzle damage (move to pmove?)
  524. //
  525. if (ent->waterlevel &&
  526. (ent->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) ) {
  527. if (ent->health > 0
  528. && ent->painDebounceTime < level.time ) {
  529. if (ent->watertype & CONTENTS_LAVA) {
  530. G_Damage (ent, NULL, NULL, NULL, NULL,
  531. 15*ent->waterlevel, 0, MOD_LAVA);
  532. }
  533. if (ent->watertype & CONTENTS_SLIME) {
  534. G_Damage (ent, NULL, NULL, NULL, NULL,
  535. 1, 0, MOD_SLIME);
  536. }
  537. }
  538. }
  539. if ((ent->health > 0) &&
  540. (ent->painDebounceTime < level.time) &&
  541. gi.WE_IsOutsideCausingPain(ent->currentOrigin) &&
  542. TIMER_Done(ent, "AcidPainDebounce"))
  543. {
  544. if (ent->NPC && ent->client && (ent->client->ps.forcePowersKnown&(1<< FP_PROTECT)))
  545. {
  546. if (!(ent->client->ps.forcePowersActive & (1<<FP_PROTECT)))
  547. {
  548. WP_ForcePowerStart( ent, FP_PROTECT, 0 );
  549. }
  550. }
  551. else
  552. {
  553. G_Damage (ent, NULL, NULL, NULL, NULL, 1, 0, MOD_SLIME);
  554. }
  555. }
  556. // Poisoned?
  557. if ((ent->client->poisonDamage) && (ent->client->poisonTime < level.time))
  558. {
  559. ent->client->poisonDamage -= 2;
  560. ent->client->poisonTime = level.time + 1000;
  561. G_Damage( ent, NULL, NULL, 0, 0, 2, DAMAGE_NO_KNOCKBACK|DAMAGE_NO_ARMOR, MOD_UNKNOWN );//FIXME: MOD_POISON?
  562. if (ent->client->poisonDamage<0)
  563. {
  564. ent->client->poisonDamage = 0;
  565. }
  566. }
  567. //in space?
  568. if (ent->client->inSpaceIndex && ent->client->inSpaceIndex != ENTITYNUM_NONE)
  569. { //we're in space, check for suffocating and for exiting
  570. gentity_t *spacetrigger = &g_entities[ent->client->inSpaceIndex];
  571. if (!spacetrigger->inuse ||
  572. !G_PointInBounds(ent->client->ps.origin, spacetrigger->absmin, spacetrigger->absmax))
  573. { //no longer in space then I suppose
  574. ent->client->inSpaceIndex = 0;
  575. }
  576. else
  577. { //check for suffocation
  578. if (ent->client->inSpaceSuffocation < level.time)
  579. { //suffocate!
  580. if (ent->health > 0)
  581. { //if they're still alive..
  582. G_Damage(ent, spacetrigger, spacetrigger, NULL, ent->client->ps.origin, Q_irand(20, 40), DAMAGE_NO_ARMOR, MOD_SUICIDE);
  583. if (ent->health > 0)
  584. { //did that last one kill them?
  585. //play the choking sound
  586. G_SoundOnEnt( ent, CHAN_VOICE, va( "*choke%d.wav", Q_irand( 1, 3 ) ) );
  587. int anim = BOTH_CHOKE3; //left-handed choke
  588. if ( ent->client->ps.weapon == WP_NONE || ent->client->ps.weapon == WP_MELEE )
  589. {
  590. anim = BOTH_CHOKE1; //two-handed choke
  591. }
  592. //make them grasp their throat
  593. NPC_SetAnim( ent, SETANIM_BOTH, BOTH_CHOKE1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  594. }
  595. }
  596. ent->client->inSpaceSuffocation = level.time + Q_irand(1000, 2000);
  597. }
  598. }
  599. }
  600. }
  601. /*
  602. ===============
  603. G_SetClientSound
  604. ===============
  605. */
  606. void G_SetClientSound( gentity_t *ent ) {
  607. // if (ent->waterlevel && (ent->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) )
  608. // ent->s.loopSound = G_SoundIndex("sound/weapons/stasis/electricloop.wav");
  609. // else
  610. // ent->s.loopSound = 0;
  611. }
  612. //==============================================================
  613. extern void G_Knockdown( gentity_t *self, gentity_t *attacker, const vec3_t pushDir, float strength, qboolean breakSaberLock );
  614. extern void G_StartMatrixEffect( gentity_t *ent, int meFlags = 0, int length = 1000, float timeScale = 0.0f, int spinTime = 0 );
  615. void G_GetMassAndVelocityForEnt( gentity_t *ent, float *mass, vec3_t velocity )
  616. {
  617. if( ent->client )
  618. {
  619. VectorCopy( ent->client->ps.velocity, velocity );
  620. *mass = ent->mass;
  621. }
  622. else
  623. {
  624. VectorCopy( ent->s.pos.trDelta, velocity );
  625. if ( ent->s.pos.trType == TR_GRAVITY )
  626. {
  627. velocity[2] -= 0.25f * g_gravity->value;
  628. }
  629. if( !ent->mass )
  630. {
  631. *mass = 1;
  632. }
  633. else if ( ent->mass <= 10 )
  634. {
  635. *mass = 10;
  636. }
  637. else
  638. {
  639. *mass = ent->mass;///10;
  640. }
  641. }
  642. }
  643. void DoImpact( gentity_t *self, gentity_t *other, qboolean damageSelf, trace_t *trace )
  644. {
  645. float magnitude, my_mass;
  646. bool thrown = false;
  647. vec3_t velocity;
  648. Vehicle_t *pSelfVeh = NULL;
  649. Vehicle_t *pOtherVeh = NULL;
  650. // See if either of these guys are vehicles, if so, keep a pointer to the vehicle npc.
  651. if ( self->client && self->client->NPC_class == CLASS_VEHICLE )
  652. {
  653. pSelfVeh = self->m_pVehicle;
  654. }
  655. if ( other->client && other->client->NPC_class == CLASS_VEHICLE )
  656. {
  657. pOtherVeh = other->m_pVehicle;
  658. }
  659. G_GetMassAndVelocityForEnt( self, &my_mass, velocity );
  660. if ( pSelfVeh )
  661. {
  662. magnitude = VectorLength( velocity ) * pSelfVeh->m_pVehicleInfo->mass / 50.0f;
  663. }
  664. else
  665. {
  666. magnitude = VectorLength( velocity ) * my_mass / 50;
  667. }
  668. //if vehicle hit another vehicle, factor in their data, too
  669. // TODO: Bring this back in later on, it's not critical right now...
  670. /* if ( self->client && self->client->NPC_class == CLASS_VEHICLE )
  671. {//we're in a vehicle
  672. if ( other->client && other->client->ps.vehicleIndex != VEHICLE_NONE )
  673. {//they're in a vehicle
  674. float o_mass;
  675. vec3_t o_velocity;
  676. G_GetMassAndVelocityForEnt( other, &o_mass, o_velocity );
  677. //now combine
  678. if ( DotProduct( o_velocity, velocity ) < 0 )
  679. {//were heading towards each other, this is going to be a STRONG impact...
  680. vec3_t velocityMod;
  681. //incorportate mass into each velocity to get directional force
  682. VectorScale( velocity, my_mass/50, velocityMod );
  683. VectorScale( o_velocity, o_mass/50, o_velocity );
  684. //figure out the overall magnitude of those 2 directed forces impacting
  685. magnitude = (DotProduct( o_velocity, velocityMod ) * -1.0f)/500.0f;
  686. }
  687. }
  688. }*/
  689. // Check For Vehicle On Vehicle Impact (Ramming)
  690. //-----------------------------------------------
  691. if ( pSelfVeh &&
  692. pSelfVeh->m_pVehicleInfo->type!=VH_ANIMAL &&
  693. pOtherVeh &&
  694. pSelfVeh->m_pVehicleInfo==pOtherVeh->m_pVehicleInfo
  695. )
  696. {
  697. gentity_t* attacker = self;
  698. Vehicle_t* attackerVeh = pSelfVeh;
  699. gentity_t* victim = other;
  700. Vehicle_t* victimVeh = pOtherVeh;
  701. // Is The Attacker Actually Not Attacking?
  702. //-----------------------------------------
  703. if (!(attackerVeh->m_ulFlags&VEH_STRAFERAM))
  704. {
  705. // Ok, So Is The Victim Actually Attacking?
  706. //------------------------------------------
  707. if (victimVeh->m_ulFlags&VEH_STRAFERAM)
  708. {
  709. // Ah, Ok. Swap Who Is The Attacker Then
  710. //----------------------------------------
  711. attacker = other;
  712. attackerVeh = pOtherVeh;
  713. victim = self;
  714. victimVeh = pSelfVeh;
  715. }
  716. else
  717. {
  718. // No Attackers, So Stop
  719. //-----------------------
  720. attacker = victim = 0;
  721. }
  722. }
  723. if (attacker && victim)
  724. {
  725. // float maxMoveSpeed = pSelfVeh->m_pVehicleInfo->speedMax;
  726. // float minLockingSpeed = maxMoveSpeed * 0.75;
  727. vec3_t attackerMoveDir;
  728. float attackerMoveSpeed;
  729. vec3_t victimMoveDir;
  730. float victimMoveSpeed;
  731. vec3_t victimTowardAttacker;
  732. float victimTowardAttackerDistance;
  733. vec3_t victimRight;
  734. float victimRightAccuracy;
  735. VectorCopy(attacker->client->ps.velocity, attackerMoveDir);
  736. VectorCopy(victim->client->ps.velocity, victimMoveDir);
  737. attackerMoveSpeed = VectorNormalize(attackerMoveDir);
  738. victimMoveSpeed = VectorNormalize(victimMoveDir);
  739. AngleVectors(victim->currentAngles, 0, victimRight, 0);
  740. VectorSubtract(victim->currentOrigin, attacker->currentOrigin, victimTowardAttacker);
  741. victimTowardAttackerDistance = VectorNormalize(victimTowardAttacker);
  742. victimRightAccuracy = DotProduct(victimTowardAttacker, victimRight);
  743. if (
  744. fabsf(victimRightAccuracy)>0.25 // Must Be Exactly Right Or Left
  745. // && victimTowardAttackerDistance<100.0f // Must Be Close Enough
  746. // && attackerMoveSpeed>minLockingSpeed // Must be moving fast enough
  747. // && fabsf(attackerMoveSpeed - victimMoveSpeed)<100 // Both must be going about the same speed
  748. )
  749. {
  750. thrown = true;
  751. vec3_t victimRight;
  752. vec3_t victimAngles;
  753. VectorCopy(victim->currentAngles, victimAngles);
  754. victimAngles[2] = 0;
  755. AngleVectors(victimAngles, 0, victimRight, 0);
  756. if (attackerVeh->m_fStrafeTime<0)
  757. {
  758. VectorScale(victimRight, -1.0f, victimRight);
  759. }
  760. if ( !(victim->flags&FL_NO_KNOCKBACK) )
  761. {
  762. G_Throw(victim, victimRight, 250);
  763. }
  764. // if (false)
  765. // {
  766. // VectorMA(victim->currentOrigin, 250.0f, victimRight, victimRight);
  767. // CG_DrawEdge(victim->currentOrigin, victimRight, EDGE_IMPACT_POSSIBLE);
  768. // }
  769. if (victimVeh->m_pVehicleInfo->iImpactFX)
  770. {
  771. G_PlayEffect(victimVeh->m_pVehicleInfo->iImpactFX, victim->currentOrigin, trace->plane.normal );
  772. }
  773. }
  774. }
  775. }
  776. if ( !self->client || self->client->ps.lastOnGround+300<level.time || ( self->client->ps.lastOnGround+100 < level.time ) )
  777. {
  778. vec3_t dir1, dir2;
  779. float force = 0, dot;
  780. qboolean vehicleHitOwner = qfalse;
  781. if ( other->material == MAT_GLASS || other->material == MAT_GLASS_METAL || other->material == MAT_GRATE1 || ((other->svFlags&SVF_BBRUSH)&&(other->spawnflags&8/*THIN*/)) )//(other->absmax[0]-other->absmin[0]<=32||other->absmax[1]-other->absmin[1]<=32||other->absmax[2]-other->absmin[2]<=32)) )
  782. {//glass and thin breakable brushes (axially aligned only, unfortunately) take more impact damage
  783. magnitude *= 2;
  784. }
  785. // See if the vehicle has crashed into the ground.
  786. if ( pSelfVeh && pSelfVeh->m_pVehicleInfo->type!=VH_ANIMAL)
  787. {
  788. if ((magnitude >= 80) && (self->painDebounceTime < level.time))
  789. {
  790. // Setup Some Variables
  791. //----------------------
  792. vec3_t vehFwd;
  793. VectorCopy(velocity, vehFwd);
  794. float vehSpeed = VectorNormalize(vehFwd);
  795. float vehToughnessAgainstOther = pSelfVeh->m_pVehicleInfo->toughness;
  796. float vehHitPercent = fabsf(DotProduct(vehFwd, trace->plane.normal));
  797. int vehDFlags = DAMAGE_NO_ARMOR;
  798. bool vehPilotedByPlayer = (pSelfVeh->m_pPilot && pSelfVeh->m_pPilot->s.number<MAX_CLIENTS);
  799. bool vehInTurbo = (pSelfVeh->m_iTurboTime>level.time);
  800. self->painDebounceTime = level.time + 200;
  801. // Modify Magnitude By Hit Percent And Toughness Against Other
  802. //-------------------------------------------------------------
  803. if (pSelfVeh->m_ulFlags & VEH_OUTOFCONTROL)
  804. {
  805. vehToughnessAgainstOther *= 0.01f; // If Out Of Control, No Damage Resistance
  806. }
  807. else
  808. {
  809. if (vehPilotedByPlayer)
  810. {
  811. vehToughnessAgainstOther *= 1.5f;
  812. }
  813. if (other && other->client)
  814. {
  815. vehToughnessAgainstOther *= 15.0f; // Very Tough against other clients (NPCS, Player, etc)
  816. }
  817. }
  818. if (vehToughnessAgainstOther>0.0f)
  819. {
  820. magnitude *= (vehHitPercent / vehToughnessAgainstOther);
  821. }
  822. else
  823. {
  824. magnitude *= vehHitPercent;
  825. }
  826. // If We Hit Architecture
  827. //------------------------
  828. if (!other || !other->client)
  829. {
  830. // Turbo Hurts
  831. //-------------
  832. if (vehInTurbo)
  833. {
  834. magnitude *= 5.0f;
  835. }
  836. else if (trace->plane.normal[2]>0.75f && vehHitPercent<0.2f)
  837. {
  838. magnitude /= 10.0f;
  839. }
  840. // If No Pilot, Blow This Thing Now
  841. //----------------------------------
  842. if (vehHitPercent>0.9f && !pSelfVeh->m_pPilot && vehSpeed>1000.0f)
  843. {
  844. vehDFlags |= DAMAGE_IMPACT_DIE;
  845. }
  846. // If Out Of Control, And We Hit A Wall Or Landed Or Head On
  847. //------------------------------------------------------------
  848. if ((pSelfVeh->m_ulFlags&VEH_OUTOFCONTROL) && (vehHitPercent>0.5f || trace->plane.normal[2]<0.5f || velocity[2]<-50.0f))
  849. {
  850. vehDFlags |= DAMAGE_IMPACT_DIE;
  851. }
  852. // If This Is A Direct Impact (Debounced By 4 Seconds)
  853. //-----------------------------------------------------
  854. if (vehHitPercent>0.9f && (level.time - self->lastImpact)>2000 && vehSpeed>300.0f)
  855. {
  856. self->lastImpact = level.time;
  857. // The Player Has Harder Requirements to Explode
  858. //-----------------------------------------------
  859. if (vehPilotedByPlayer)
  860. {
  861. if ((vehHitPercent>0.99f && vehSpeed>1000.0f && !Q_irand(0,30)) ||
  862. (vehHitPercent>0.999f && vehInTurbo))
  863. {
  864. vehDFlags |= DAMAGE_IMPACT_DIE;
  865. }
  866. }
  867. else if (player && G_IsRidingVehicle(player) &&
  868. (Distance(self->currentOrigin, player->currentOrigin)<800.0f) &&
  869. (vehInTurbo || !Q_irand(0,1) || vehHitPercent>0.999f))
  870. {
  871. vehDFlags |= DAMAGE_IMPACT_DIE;
  872. }
  873. }
  874. // Make Sure He Dies This Time. I will accept no excuses.
  875. //---------------------------------------------------------
  876. if (vehDFlags&DAMAGE_IMPACT_DIE)
  877. {
  878. // If close enough To The PLayer
  879. if (player &&
  880. G_IsRidingVehicle(player) &&
  881. self->owner &&
  882. Distance(self->currentOrigin, player->currentOrigin)<500.0f)
  883. {
  884. player->lastEnemy = self->owner;
  885. G_StartMatrixEffect(player, MEF_LOOK_AT_ENEMY|MEF_NO_RANGEVAR|MEF_NO_VERTBOB|MEF_NO_SPIN, 1000);
  886. }
  887. magnitude = 100000.0f;
  888. }
  889. }
  890. if (magnitude>10.0f)
  891. {
  892. // Play The Impact Effect
  893. //------------------------
  894. if (pSelfVeh->m_pVehicleInfo->iImpactFX && vehSpeed>100.0f)
  895. {
  896. G_PlayEffect( pSelfVeh->m_pVehicleInfo->iImpactFX, self->currentOrigin, trace->plane.normal );
  897. }
  898. // Set The Crashing Flag And Pain Debounce Time
  899. //----------------------------------------------
  900. pSelfVeh->m_ulFlags |= VEH_CRASHING;
  901. }
  902. G_Damage( self, player, player, NULL, self->currentOrigin, magnitude, vehDFlags, MOD_FALLING );//FIXME: MOD_IMPACT
  903. }
  904. if ( self->owner == other || self->activator == other )
  905. {//hit owner/activator
  906. if ( self->m_pVehicle && !self->m_pVehicle->m_pVehicleInfo->Inhabited( self->m_pVehicle ) )
  907. {//empty swoop
  908. if ( self->client->respawnTime - level.time < 1000 )
  909. {//just spawned in a second ago
  910. //don't actually damage or throw him...
  911. vehicleHitOwner = qtrue;
  912. }
  913. }
  914. }
  915. //if 2 vehicles on same side hit each other, tone it down
  916. //NOTE: we do this here because we still want the impact effect
  917. if ( pOtherVeh )
  918. {
  919. if ( self->client->playerTeam == other->client->playerTeam )
  920. {
  921. magnitude /= 25;
  922. }
  923. }
  924. }
  925. else if ( self->client
  926. && (PM_InKnockDown( &self->client->ps )||(self->client->ps.eFlags&EF_FORCE_GRIPPED))
  927. && magnitude >= 120 )
  928. {//FORCE-SMACKED into something
  929. if ( TIMER_Done( self, "impactEffect" ) )
  930. {
  931. G_PlayEffect( G_EffectIndex( "env/impact_dustonly" ), trace->endpos, trace->plane.normal );
  932. G_Sound( self, G_SoundIndex( va( "sound/weapons/melee/punch%d", Q_irand( 1, 4 ) ) ) );
  933. TIMER_Set( self, "impactEffect", 1000 );
  934. }
  935. }
  936. //damage them
  937. if ( magnitude >= 100 && other->s.number < ENTITYNUM_WORLD )
  938. {
  939. VectorCopy( velocity, dir1 );
  940. VectorNormalize( dir1 );
  941. if( VectorCompare( other->currentOrigin, vec3_origin ) )
  942. {//a brush with no origin
  943. VectorCopy ( dir1, dir2 );
  944. }
  945. else
  946. {
  947. VectorSubtract( other->currentOrigin, self->currentOrigin, dir2 );
  948. VectorNormalize( dir2 );
  949. }
  950. dot = DotProduct( dir1, dir2 );
  951. if ( dot >= 0.2 )
  952. {
  953. force = dot;
  954. }
  955. else
  956. {
  957. force = 0;
  958. }
  959. force *= (magnitude/50);
  960. int cont = gi.pointcontents( other->absmax, other->s.number );
  961. if( (cont&CONTENTS_WATER) )
  962. {//water absorbs 2/3 velocity
  963. force *= 0.33333f;
  964. }
  965. if ( self->NPC && other->s.number == ENTITYNUM_WORLD )
  966. {//NPCs take less damage
  967. force *= 0.5f;
  968. }
  969. if ( self->s.number >= MAX_CLIENTS && self->client && (PM_InKnockDown( &self->client->ps )||self->client->ps.eFlags&EF_FORCE_GRIPPED) )
  970. {//NPC: I was knocked down or being gripped, impact should be harder
  971. //FIXME: what if I was just thrown - force pushed/pulled or thrown from a grip?
  972. force *= 10;
  973. }
  974. //FIXME: certain NPCs/entities should be TOUGH - like Ion Cannons, AT-STs, Mark1 droids, etc.
  975. if ( pOtherVeh )
  976. {//if hit another vehicle, take their toughness into account, too
  977. force /= pOtherVeh->m_pVehicleInfo->toughness;
  978. }
  979. if( ( (force >= 1 || pSelfVeh) && other->s.number>=MAX_CLIENTS ) || force >= 10)
  980. {
  981. /*
  982. dprint("Damage other (");
  983. dprint(loser.classname);
  984. dprint("): ");
  985. dprint(ftos(force));
  986. dprint("\n");
  987. */
  988. if ( other->svFlags & SVF_GLASS_BRUSH )
  989. {
  990. other->splashRadius = (float)(self->maxs[0] - self->mins[0])/4.0f;
  991. }
  992. if ( pSelfVeh )
  993. {//if in a vehicle when land on someone, always knockdown, throw, damage
  994. if ( !vehicleHitOwner )
  995. {//didn't hit owner
  996. // If the player was hit don't make the damage so bad...
  997. if ( other && other->s.number<MAX_CLIENTS )
  998. {
  999. force *= 0.5f;
  1000. }
  1001. //Hmm, maybe knockdown?
  1002. if ( !(other->flags&FL_NO_KNOCKBACK) )
  1003. {
  1004. G_Throw( other, dir2, force );
  1005. }
  1006. G_Knockdown( other, self, dir2, force, qtrue );
  1007. G_Damage( other, self, self, velocity, self->currentOrigin, force, DAMAGE_NO_ARMOR|DAMAGE_EXTRA_KNOCKBACK, MOD_IMPACT );
  1008. }
  1009. }
  1010. else if ( self->forcePushTime > level.time - 1000//was force pushed/pulled in the last 1600 milliseconds
  1011. && self->forcePuller == other->s.number>=MAX_CLIENTS )//hit the person who pushed/pulled me
  1012. {//ignore the impact
  1013. }
  1014. else if ( other->takedamage )
  1015. {
  1016. if ( !self->client || other->s.number<MAX_CLIENTS || !other->client )
  1017. {//aw, fuck it, clients no longer take impact damage from other clients, unless you're the player
  1018. if ( other->client //he's a client
  1019. && self->client //I'm a client
  1020. && other->client->ps.forceGripEntityNum == self->s.number )//he's force-gripping me
  1021. {//don't damage the other guy if he's gripping me
  1022. }
  1023. else
  1024. {
  1025. G_Damage( other, self, self, velocity, self->currentOrigin, floor(force), DAMAGE_NO_ARMOR, MOD_IMPACT );
  1026. }
  1027. }
  1028. else
  1029. {
  1030. GEntity_PainFunc( other, self, self, self->currentOrigin, force, MOD_IMPACT );
  1031. //Hmm, maybe knockdown?
  1032. if (!thrown)
  1033. {
  1034. if ( !(other->flags&FL_NO_KNOCKBACK) )
  1035. {
  1036. G_Throw( other, dir2, force );
  1037. }
  1038. }
  1039. }
  1040. if ( other->health > 0 )
  1041. {//still alive?
  1042. //TODO: if someone was thrown through the air (in a knockdown or being gripped)
  1043. // and they hit me hard enough, knock me down
  1044. if ( other->client )
  1045. {
  1046. if ( self->client )
  1047. {
  1048. if ( PM_InKnockDown( &self->client->ps ) || (self->client->ps.eFlags&EF_FORCE_GRIPPED) )
  1049. {
  1050. G_Knockdown( other, self, dir2, Q_irand( 200, 400 ), qtrue );
  1051. }
  1052. }
  1053. else if ( self->forcePuller != ENTITYNUM_NONE
  1054. && g_entities[self->forcePuller].client
  1055. && self->mass > Q_irand( 50, 100 ) )
  1056. {
  1057. G_Knockdown( other, &g_entities[self->forcePuller], dir2, Q_irand( 200, 400 ), qtrue );
  1058. }
  1059. }
  1060. }
  1061. }
  1062. else
  1063. {
  1064. //Hmm, maybe knockdown?
  1065. if (!thrown)
  1066. {
  1067. if ( !(other->flags&FL_NO_KNOCKBACK) )
  1068. {
  1069. G_Throw( other, dir2, force );
  1070. }
  1071. }
  1072. }
  1073. }
  1074. }
  1075. if ( damageSelf && self->takedamage && !(self->flags&FL_NO_IMPACT_DMG))
  1076. {
  1077. //Now damage me
  1078. //FIXME: more lenient falling damage, especially for when driving a vehicle
  1079. if ( pSelfVeh && self->client->ps.forceJumpZStart )
  1080. {//we were force-jumping
  1081. if ( self->currentOrigin[2] >= self->client->ps.forceJumpZStart )
  1082. {//we landed at same height or higher than we landed
  1083. magnitude = 0;
  1084. }
  1085. else
  1086. {//FIXME: take off some of it, at least?
  1087. magnitude = (self->client->ps.forceJumpZStart-self->currentOrigin[2])/3;
  1088. }
  1089. }
  1090. if( ( magnitude >= 100 + self->health
  1091. && self->s.number >= MAX_CLIENTS
  1092. && self->s.weapon != WP_SABER )
  1093. || self->client->NPC_class == CLASS_VEHICLE
  1094. || ( magnitude >= 700 ) )//health here is used to simulate structural integrity
  1095. {
  1096. if ( (self->s.weapon == WP_SABER || self->s.number<MAX_CLIENTS || (self->client&&(self->client->NPC_class==CLASS_BOBAFETT||self->client->NPC_class==CLASS_ROCKETTROOPER))) && self->client && self->client->ps.groundEntityNum < ENTITYNUM_NONE && magnitude < 1000 )
  1097. {//players and jedi take less impact damage
  1098. //allow for some lenience on high falls
  1099. magnitude /= 2;
  1100. }
  1101. //drop it some (magic number... sigh)
  1102. magnitude /= 40;
  1103. //If damage other, subtract half of that damage off of own injury
  1104. if ( other->bmodel && other->material != MAT_GLASS )
  1105. {//take off only a little because we broke architecture (not including glass), that should hurt
  1106. magnitude = magnitude - force/8;
  1107. }
  1108. else
  1109. {//take off half damage we did to it
  1110. magnitude = magnitude - force/2;
  1111. }
  1112. if ( pSelfVeh )
  1113. {
  1114. //FIXME: if hit another vehicle, take their toughness into
  1115. // account, too? Or should their toughness only matter
  1116. // when they hit me?
  1117. magnitude /= pSelfVeh->m_pVehicleInfo->toughness * 1000.0f;
  1118. if ( other->bmodel && other->material != MAT_GLASS )
  1119. {//broke through some architecture, take a good amount of damage
  1120. }
  1121. else if ( pOtherVeh )
  1122. {//they're tougher
  1123. //magnitude /= 4.0f;//FIXME: get the toughness of other from vehicles.cfg
  1124. }
  1125. else
  1126. {//take some off because of give
  1127. //NOTE: this covers all other entities and impact with world...
  1128. //FIXME: certain NPCs/entities should be TOUGH - like Ion Cannons, AT-STs, Mark1 droids, etc.
  1129. magnitude /= 10.0f;
  1130. }
  1131. if ( magnitude < 1.0f )
  1132. {
  1133. magnitude = 0;
  1134. }
  1135. }
  1136. if ( magnitude >= 1 )
  1137. {
  1138. //FIXME: Put in a thingtype impact sound function
  1139. /*
  1140. dprint("Damage self (");
  1141. dprint(self.classname);
  1142. dprint("): ");
  1143. dprint(ftos(magnitude));
  1144. dprint("\n");
  1145. */
  1146. if ( self->NPC && self->s.weapon == WP_SABER )
  1147. {//FIXME: for now Jedi take no falling damage, but really they should if pushed off?
  1148. magnitude = 0;
  1149. }
  1150. G_Damage( self, NULL, NULL, NULL, self->currentOrigin, magnitude/2, DAMAGE_NO_ARMOR, MOD_FALLING );//FIXME: MOD_IMPACT
  1151. }
  1152. }
  1153. }
  1154. //FIXME: slow my velocity some?
  1155. /*
  1156. if(self.flags&FL_ONGROUND)
  1157. self.last_onground=time;
  1158. */
  1159. }
  1160. }
  1161. /*
  1162. ==============
  1163. ClientImpacts
  1164. ==============
  1165. */
  1166. void ClientImpacts( gentity_t *ent, pmove_t *pm ) {
  1167. int i, j;
  1168. trace_t trace;
  1169. gentity_t *other;
  1170. memset( &trace, 0, sizeof( trace ) );
  1171. for (i=0 ; i<pm->numtouch ; i++) {
  1172. for (j=0 ; j<i ; j++) {
  1173. if (pm->touchents[j] == pm->touchents[i] ) {
  1174. break;
  1175. }
  1176. }
  1177. if (j != i) {
  1178. continue; // duplicated
  1179. }
  1180. other = &g_entities[ pm->touchents[i] ];
  1181. if ( ( ent->NPC != NULL ) && ( ent->e_TouchFunc != touchF_NULL ) ) { // last check unneccessary
  1182. GEntity_TouchFunc( ent, other, &trace );
  1183. }
  1184. if ( other->e_TouchFunc == touchF_NULL ) { // not needed, but I'll leave it I guess (cache-hit issues)
  1185. continue;
  1186. }
  1187. GEntity_TouchFunc( other, ent, &trace );
  1188. }
  1189. }
  1190. /*
  1191. ============
  1192. G_TouchTriggersLerped
  1193. Find all trigger entities that ent's current position touches.
  1194. Spectators will only interact with teleporters.
  1195. This version checks at 6 unit steps between last and current origins
  1196. ============
  1197. */
  1198. void G_TouchTriggersLerped( gentity_t *ent ) {
  1199. int i, num;
  1200. float dist, curDist = 0;
  1201. gentity_t *touch[MAX_GENTITIES], *hit;
  1202. trace_t trace;
  1203. vec3_t end, mins, maxs, diff;
  1204. const vec3_t range = { 40, 40, 52 };
  1205. qboolean touched[MAX_GENTITIES];
  1206. qboolean done = qfalse;
  1207. if ( !ent->client ) {
  1208. return;
  1209. }
  1210. // dead NPCs don't activate triggers!
  1211. if ( ent->client->ps.stats[STAT_HEALTH] <= 0 )
  1212. {
  1213. if ( ent->s.number>=MAX_CLIENTS )
  1214. {
  1215. return;
  1216. }
  1217. }
  1218. #ifdef _DEBUG
  1219. for ( int j = 0; j < 3; j++ )
  1220. {
  1221. assert( !_isnan(ent->currentOrigin[j]));
  1222. assert( !_isnan(ent->lastOrigin[j]));
  1223. }
  1224. #endif// _DEBUG
  1225. VectorSubtract( ent->currentOrigin, ent->lastOrigin, diff );
  1226. dist = VectorNormalize( diff );
  1227. #ifdef _DEBUG
  1228. assert( (dist<1024) && "insane distance in G_TouchTriggersLerped!" );
  1229. #endif// _DEBUG
  1230. if ( dist > 1024 )
  1231. {
  1232. return;
  1233. }
  1234. memset (touched, qfalse, sizeof(touched) );
  1235. for ( curDist = 0; !done && ent->maxs[1]>0; curDist += (float)ent->maxs[1]/2.0f )
  1236. {
  1237. if ( curDist >= dist )
  1238. {
  1239. VectorCopy( ent->currentOrigin, end );
  1240. done = qtrue;
  1241. }
  1242. else
  1243. {
  1244. VectorMA( ent->lastOrigin, curDist, diff, end );
  1245. }
  1246. VectorSubtract( end, range, mins );
  1247. VectorAdd( end, range, maxs );
  1248. num = gi.EntitiesInBox( mins, maxs, touch, MAX_GENTITIES );
  1249. // can't use ent->absmin, because that has a one unit pad
  1250. VectorAdd( end, ent->mins, mins );
  1251. VectorAdd( end, ent->maxs, maxs );
  1252. for ( i=0 ; i<num ; i++ ) {
  1253. hit = touch[i];
  1254. if ( (hit->e_TouchFunc == touchF_NULL) && (ent->e_TouchFunc == touchF_NULL) ) {
  1255. continue;
  1256. }
  1257. if ( !( hit->contents & CONTENTS_TRIGGER ) ) {
  1258. continue;
  1259. }
  1260. if ( touched[i] == qtrue ) {
  1261. continue;//already touched this move
  1262. }
  1263. if ( ent->client->ps.stats[STAT_HEALTH] <= 0 )
  1264. {
  1265. if ( Q_stricmp( "trigger_teleport", hit->classname ) || !(hit->spawnflags&16/*TTSF_DEAD_OK*/) )
  1266. {//dead clients can only touch tiogger_teleports that are marked as touchable
  1267. continue;
  1268. }
  1269. }
  1270. // use seperate code for determining if an item is picked up
  1271. // so you don't have to actually contact its bounding box
  1272. /*
  1273. if ( hit->s.eType == ET_ITEM ) {
  1274. if ( !BG_PlayerTouchesItem( &ent->client->ps, &hit->s, level.time ) ) {
  1275. continue;
  1276. }
  1277. } else */
  1278. {
  1279. if ( !gi.EntityContact( mins, maxs, hit ) ) {
  1280. continue;
  1281. }
  1282. }
  1283. touched[i] = qtrue;
  1284. memset( &trace, 0, sizeof(trace) );
  1285. if ( hit->e_TouchFunc != touchF_NULL ) {
  1286. GEntity_TouchFunc(hit, ent, &trace);
  1287. }
  1288. //WTF? Why would a trigger ever fire off the NPC's touch func??!!!
  1289. /*
  1290. if ( ( ent->NPC != NULL ) && ( ent->e_TouchFunc != touchF_NULL ) ) {
  1291. GEntity_TouchFunc( ent, hit, &trace );
  1292. }
  1293. */
  1294. }
  1295. }
  1296. }
  1297. /*
  1298. ============
  1299. G_TouchTriggers
  1300. Find all trigger entities that ent's current position touches.
  1301. Spectators will only interact with teleporters.
  1302. ============
  1303. */
  1304. void G_TouchTriggers( gentity_t *ent ) {
  1305. int i, num;
  1306. gentity_t *touch[MAX_GENTITIES], *hit;
  1307. trace_t trace;
  1308. vec3_t mins, maxs;
  1309. const vec3_t range = { 40, 40, 52 };
  1310. if ( !ent->client ) {
  1311. return;
  1312. }
  1313. // dead clients don't activate triggers!
  1314. if ( ent->client->ps.stats[STAT_HEALTH] <= 0 ) {
  1315. return;
  1316. }
  1317. VectorSubtract( ent->client->ps.origin, range, mins );
  1318. VectorAdd( ent->client->ps.origin, range, maxs );
  1319. num = gi.EntitiesInBox( mins, maxs, touch, MAX_GENTITIES );
  1320. // can't use ent->absmin, because that has a one unit pad
  1321. VectorAdd( ent->client->ps.origin, ent->mins, mins );
  1322. VectorAdd( ent->client->ps.origin, ent->maxs, maxs );
  1323. for ( i=0 ; i<num ; i++ ) {
  1324. hit = touch[i];
  1325. if ( (hit->e_TouchFunc == touchF_NULL) && (ent->e_TouchFunc == touchF_NULL) ) {
  1326. continue;
  1327. }
  1328. if ( !( hit->contents & CONTENTS_TRIGGER ) ) {
  1329. continue;
  1330. }
  1331. // use seperate code for determining if an item is picked up
  1332. // so you don't have to actually contact its bounding box
  1333. /*
  1334. if ( hit->s.eType == ET_ITEM ) {
  1335. if ( !BG_PlayerTouchesItem( &ent->client->ps, &hit->s, level.time ) ) {
  1336. continue;
  1337. }
  1338. } else */
  1339. {
  1340. if ( !gi.EntityContact( mins, maxs, hit ) ) {
  1341. continue;
  1342. }
  1343. }
  1344. memset( &trace, 0, sizeof(trace) );
  1345. if ( hit->e_TouchFunc != touchF_NULL ) {
  1346. GEntity_TouchFunc(hit, ent, &trace);
  1347. }
  1348. if ( ( ent->NPC != NULL ) && ( ent->e_TouchFunc != touchF_NULL ) ) {
  1349. GEntity_TouchFunc( ent, hit, &trace );
  1350. }
  1351. }
  1352. }
  1353. /*
  1354. ============
  1355. G_MoverTouchTriggers
  1356. Find all trigger entities that ent's current position touches.
  1357. Spectators will only interact with teleporters.
  1358. ============
  1359. */
  1360. void G_MoverTouchPushTriggers( gentity_t *ent, vec3_t oldOrg )
  1361. {
  1362. int i, num;
  1363. float step, stepSize, dist;
  1364. gentity_t *touch[MAX_GENTITIES], *hit;
  1365. trace_t trace;
  1366. vec3_t mins, maxs, dir, size, checkSpot;
  1367. const vec3_t range = { 40, 40, 52 };
  1368. // non-moving movers don't hit triggers!
  1369. if ( !VectorLengthSquared( ent->s.pos.trDelta ) )
  1370. {
  1371. return;
  1372. }
  1373. VectorSubtract( ent->mins, ent->maxs, size );
  1374. stepSize = VectorLength( size );
  1375. if ( stepSize < 1 )
  1376. {
  1377. stepSize = 1;
  1378. }
  1379. VectorSubtract( ent->currentOrigin, oldOrg, dir );
  1380. dist = VectorNormalize( dir );
  1381. for ( step = 0; step <= dist; step += stepSize )
  1382. {
  1383. VectorMA( ent->currentOrigin, step, dir, checkSpot );
  1384. VectorSubtract( checkSpot, range, mins );
  1385. VectorAdd( checkSpot, range, maxs );
  1386. num = gi.EntitiesInBox( mins, maxs, touch, MAX_GENTITIES );
  1387. // can't use ent->absmin, because that has a one unit pad
  1388. VectorAdd( checkSpot, ent->mins, mins );
  1389. VectorAdd( checkSpot, ent->maxs, maxs );
  1390. for ( i=0 ; i<num ; i++ )
  1391. {
  1392. hit = touch[i];
  1393. if ( hit->s.eType != ET_PUSH_TRIGGER )
  1394. {
  1395. continue;
  1396. }
  1397. if ( hit->e_TouchFunc == touchF_NULL )
  1398. {
  1399. continue;
  1400. }
  1401. if ( !( hit->contents & CONTENTS_TRIGGER ) )
  1402. {
  1403. continue;
  1404. }
  1405. if ( !gi.EntityContact( mins, maxs, hit ) )
  1406. {
  1407. continue;
  1408. }
  1409. memset( &trace, 0, sizeof(trace) );
  1410. if ( hit->e_TouchFunc != touchF_NULL )
  1411. {
  1412. GEntity_TouchFunc(hit, ent, &trace);
  1413. }
  1414. }
  1415. }
  1416. }
  1417. void G_MatchPlayerWeapon( gentity_t *ent )
  1418. {
  1419. if ( g_entities[0].inuse && g_entities[0].client )
  1420. {//player is around
  1421. int newWeap;
  1422. if ( g_entities[0].client->ps.weapon > WP_CONCUSSION )
  1423. {
  1424. newWeap = WP_BLASTER_PISTOL;
  1425. }
  1426. else
  1427. {
  1428. newWeap = g_entities[0].client->ps.weapon;
  1429. }
  1430. if ( newWeap != WP_NONE && ent->client->ps.weapon != newWeap )
  1431. {
  1432. G_RemoveWeaponModels( ent );
  1433. ent->client->ps.stats[STAT_WEAPONS] = ( 1 << newWeap );
  1434. ent->client->ps.ammo[weaponData[newWeap].ammoIndex] = 999;
  1435. ChangeWeapon( ent, newWeap );
  1436. ent->client->ps.weapon = newWeap;
  1437. ent->client->ps.weaponstate = WEAPON_READY;
  1438. if ( newWeap == WP_SABER )
  1439. {
  1440. //FIXME: AddSound/Sight Event
  1441. int numSabers = WP_SaberInitBladeData( ent );
  1442. WP_SaberAddG2SaberModels( ent );
  1443. for ( int saberNum = 0; saberNum < numSabers; saberNum++ )
  1444. {
  1445. //G_CreateG2AttachedWeaponModel( ent, ent->client->ps.saber[saberNum].model, ent->handRBolt, 0 );
  1446. ent->client->ps.saber[saberNum].type = g_entities[0].client->ps.saber[saberNum].type;
  1447. for ( int bladeNum = 0; bladeNum < ent->client->ps.saber[saberNum].numBlades; bladeNum++ )
  1448. {
  1449. ent->client->ps.saber[saberNum].blade[0].active = g_entities[0].client->ps.saber[saberNum].blade[bladeNum].active;
  1450. ent->client->ps.saber[saberNum].blade[0].length = g_entities[0].client->ps.saber[saberNum].blade[bladeNum].length;
  1451. }
  1452. }
  1453. ent->client->ps.saberAnimLevel = g_entities[0].client->ps.saberAnimLevel;
  1454. ent->client->ps.saberStylesKnown = g_entities[0].client->ps.saberStylesKnown;
  1455. }
  1456. else
  1457. {
  1458. G_CreateG2AttachedWeaponModel( ent, weaponData[newWeap].weaponMdl, ent->handRBolt, 0 );
  1459. }
  1460. }
  1461. }
  1462. }
  1463. void G_NPCMunroMatchPlayerWeapon( gentity_t *ent )
  1464. {
  1465. //special uber hack for cinematic players to match player's weapon
  1466. if ( !in_camera )
  1467. {
  1468. if ( ent && ent->client && ent->NPC && (ent->NPC->aiFlags&NPCAI_MATCHPLAYERWEAPON) )
  1469. {//we're a Player NPC
  1470. G_MatchPlayerWeapon( ent );
  1471. }
  1472. }
  1473. }
  1474. /*
  1475. ==================
  1476. ClientTimerActions
  1477. Actions that happen once a second
  1478. ==================
  1479. */
  1480. void ClientTimerActions( gentity_t *ent, int msec ) {
  1481. gclient_t *client;
  1482. client = ent->client;
  1483. client->timeResidual += msec;
  1484. while ( client->timeResidual >= 1000 )
  1485. {
  1486. client->timeResidual -= 1000;
  1487. if ( ent->s.weapon != WP_NONE )
  1488. {
  1489. ent->client->sess.missionStats.weaponUsed[ent->s.weapon]++;
  1490. }
  1491. // if we've got the seeker powerup, see if we can shoot it at someone
  1492. /* if ( ent->client->ps.powerups[PW_SEEKER] > level.time )
  1493. {
  1494. vec3_t seekerPos, dir;
  1495. gentity_t *enemy = SeekerAcquiresTarget( ent, seekerPos );
  1496. if ( enemy != NULL ) // set the client's enemy to a valid target
  1497. {
  1498. FireSeeker( ent, enemy, seekerPos, dir );
  1499. gentity_t *tent;
  1500. tent = G_TempEntity( seekerPos, EV_POWERUP_SEEKER_FIRE );
  1501. VectorCopy( dir, tent->pos1 );
  1502. tent->s.eventParm = ent->s.number;
  1503. }
  1504. }*/
  1505. if ( (ent->flags&FL_OVERCHARGED_HEALTH) )
  1506. {//need to gradually reduce health back to max
  1507. if ( ent->health > ent->client->ps.stats[STAT_MAX_HEALTH] )
  1508. {//decrement it
  1509. ent->health--;
  1510. ent->client->ps.stats[STAT_HEALTH] = ent->health;
  1511. }
  1512. else
  1513. {//done
  1514. ent->flags &= ~FL_OVERCHARGED_HEALTH;
  1515. }
  1516. }
  1517. }
  1518. }
  1519. /*
  1520. ====================
  1521. ClientIntermissionThink
  1522. ====================
  1523. */
  1524. static qboolean ClientCinematicThink( gclient_t *client ) {
  1525. client->ps.eFlags &= ~EF_FIRING;
  1526. // swap button actions
  1527. client->oldbuttons = client->buttons;
  1528. client->buttons = client->usercmd.buttons;
  1529. if ( client->buttons & ( BUTTON_USE ) & ( client->oldbuttons ^ client->buttons ) ) {
  1530. return( qtrue );
  1531. }
  1532. return( qfalse );
  1533. }
  1534. /*
  1535. ================
  1536. ClientEvents
  1537. Events will be passed on to the clients for presentation,
  1538. but any server game effects are handled here
  1539. ================
  1540. */
  1541. extern void WP_SabersDamageTrace( gentity_t *ent, qboolean noEffects = qfalse );
  1542. extern void WP_SaberUpdateOldBladeData( gentity_t *ent );
  1543. void ClientEvents( gentity_t *ent, int oldEventSequence ) {
  1544. int i;
  1545. int event;
  1546. gclient_t *client;
  1547. //int damage;
  1548. qboolean fired;
  1549. client = ent->client;
  1550. fired = qfalse;
  1551. for ( i = oldEventSequence ; i < client->ps.eventSequence ; i++ ) {
  1552. event = client->ps.events[ i & (MAX_PS_EVENTS-1) ];
  1553. switch ( event ) {
  1554. case EV_FALL_MEDIUM:
  1555. case EV_FALL_FAR://these come from bg_pmove, PM_CrashLand
  1556. if ( ent->s.eType != ET_PLAYER ) {
  1557. break; // not in the player model
  1558. }
  1559. /*
  1560. //FIXME: isn't there a more accurate way to calculate damage from falls?
  1561. if ( event == EV_FALL_FAR )
  1562. {
  1563. damage = 50;
  1564. }
  1565. else
  1566. {
  1567. damage = 25;
  1568. }
  1569. ent->painDebounceTime = level.time + 200; // no normal pain sound
  1570. G_Damage (ent, NULL, NULL, NULL, NULL, damage, 0, MOD_FALLING);
  1571. */
  1572. break;
  1573. case EV_FIRE_WEAPON:
  1574. #ifndef FINAL_BUILD
  1575. if ( fired ) {
  1576. gi.Printf( "DOUBLE EV_FIRE_WEAPON AND-OR EV_ALT_FIRE!!\n" );
  1577. }
  1578. #endif
  1579. fired = qtrue;
  1580. FireWeapon( ent, qfalse );
  1581. #ifdef _XBOX
  1582. extern int Sys_Milliseconds();
  1583. if (ent->s.clientNum == 0)
  1584. g_lastFireTime = Sys_Milliseconds();
  1585. #endif
  1586. break;
  1587. case EV_ALT_FIRE:
  1588. #ifndef FINAL_BUILD
  1589. if ( fired ) {
  1590. gi.Printf( "DOUBLE EV_FIRE_WEAPON AND-OR EV_ALT_FIRE!!\n" );
  1591. }
  1592. #endif
  1593. fired = qtrue;
  1594. FireWeapon( ent, qtrue );
  1595. #ifdef _XBOX
  1596. if (ent->s.clientNum == 0)
  1597. g_lastFireTime = Sys_Milliseconds();
  1598. #endif
  1599. break;
  1600. default:
  1601. break;
  1602. }
  1603. }
  1604. //by the way, if you have your saber in hand and it's on, do the damage trace
  1605. if ( client->ps.weapon == WP_SABER )
  1606. {
  1607. if ( g_timescale->value >= 1.0f || !(client->ps.forcePowersActive&(1<<FP_SPEED)) )
  1608. {
  1609. int wait = FRAMETIME/2;
  1610. //sanity check
  1611. if ( client->ps.saberDamageDebounceTime - level.time > wait )
  1612. {//when you unpause the game with force speed on, the time gets *really* wiggy...
  1613. client->ps.saberDamageDebounceTime = level.time + wait;
  1614. }
  1615. if ( client->ps.saberDamageDebounceTime <= level.time )
  1616. {
  1617. WP_SabersDamageTrace( ent );
  1618. WP_SaberUpdateOldBladeData( ent );
  1619. /*
  1620. if ( g_timescale->value&&client->ps.clientNum==0&&!player_locked&&!MatrixMode&&client->ps.forcePowersActive&(1<<FP_SPEED) )
  1621. {
  1622. wait = floor( (float)wait*g_timescale->value );
  1623. }
  1624. */
  1625. client->ps.saberDamageDebounceTime = level.time + wait;
  1626. }
  1627. }
  1628. }
  1629. }
  1630. void G_ThrownDeathAnimForDeathAnim( gentity_t *hitEnt, vec3_t impactPoint )
  1631. {
  1632. int anim = -1;
  1633. if ( !hitEnt || !hitEnt->client )
  1634. {
  1635. return;
  1636. }
  1637. switch ( hitEnt->client->ps.legsAnim )
  1638. {
  1639. case BOTH_DEATH9://fall to knees, fall over
  1640. case BOTH_DEATH10://fall to knees, fall over
  1641. case BOTH_DEATH11://fall to knees, fall over
  1642. case BOTH_DEATH13://stumble back, fall over
  1643. case BOTH_DEATH17://jerky fall to knees, fall over
  1644. case BOTH_DEATH18://grab gut, fall to knees, fall over
  1645. case BOTH_DEATH19://grab gut, fall to knees, fall over
  1646. case BOTH_DEATH20://grab shoulder, fall forward
  1647. case BOTH_DEATH21://grab shoulder, fall forward
  1648. case BOTH_DEATH3://knee collapse, twist & fall forward
  1649. case BOTH_DEATH7://knee collapse, twist & fall forward
  1650. {
  1651. vec3_t dir2Impact, fwdAngles, facing;
  1652. VectorSubtract( impactPoint, hitEnt->currentOrigin, dir2Impact );
  1653. dir2Impact[2] = 0;
  1654. VectorNormalize( dir2Impact );
  1655. VectorSet( fwdAngles, 0, hitEnt->client->ps.viewangles[YAW], 0 );
  1656. AngleVectors( fwdAngles, facing, NULL, NULL );
  1657. float dot = DotProduct( facing, dir2Impact );//-1 = hit in front, 0 = hit on side, 1 = hit in back
  1658. if ( dot > 0.5f )
  1659. {//kicked in chest, fly backward
  1660. switch ( Q_irand( 0, 4 ) )
  1661. {//FIXME: don't start at beginning of anim?
  1662. case 0:
  1663. anim = BOTH_DEATH1;//thrown backwards
  1664. break;
  1665. case 1:
  1666. anim = BOTH_DEATH2;//fall backwards
  1667. break;
  1668. case 2:
  1669. anim = BOTH_DEATH15;//roll over backwards
  1670. break;
  1671. case 3:
  1672. anim = BOTH_DEATH22;//fast fall back
  1673. break;
  1674. case 4:
  1675. anim = BOTH_DEATH23;//fast fall back
  1676. break;
  1677. }
  1678. }
  1679. else if ( dot < -0.5f )
  1680. {//kicked in back, fly forward
  1681. switch ( Q_irand( 0, 5 ) )
  1682. {//FIXME: don't start at beginning of anim?
  1683. case 0:
  1684. anim = BOTH_DEATH14;
  1685. break;
  1686. case 1:
  1687. anim = BOTH_DEATH24;
  1688. break;
  1689. case 2:
  1690. anim = BOTH_DEATH25;
  1691. break;
  1692. case 3:
  1693. anim = BOTH_DEATH4;//thrown forwards
  1694. break;
  1695. case 4:
  1696. anim = BOTH_DEATH5;//thrown forwards
  1697. break;
  1698. case 5:
  1699. anim = BOTH_DEATH16;//thrown forwards
  1700. break;
  1701. }
  1702. }
  1703. else
  1704. {//hit on side, spin
  1705. switch ( Q_irand( 0, 2 ) )
  1706. {//FIXME: don't start at beginning of anim?
  1707. case 0:
  1708. anim = BOTH_DEATH12;
  1709. break;
  1710. case 1:
  1711. anim = BOTH_DEATH14;
  1712. break;
  1713. case 2:
  1714. anim = BOTH_DEATH15;
  1715. break;
  1716. case 3:
  1717. anim = BOTH_DEATH6;
  1718. break;
  1719. case 4:
  1720. anim = BOTH_DEATH8;
  1721. break;
  1722. }
  1723. }
  1724. }
  1725. break;
  1726. }
  1727. if ( anim != -1 )
  1728. {
  1729. NPC_SetAnim( hitEnt, SETANIM_BOTH, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  1730. }
  1731. }
  1732. gentity_t *G_KickTrace( gentity_t *ent, vec3_t kickDir, float kickDist, vec3_t kickEnd, int kickDamage, float kickPush, qboolean doSoundOnWalls )
  1733. {
  1734. vec3_t traceOrg, traceEnd, kickMins={-2,-2,-2}, kickMaxs={2,2,2};
  1735. trace_t trace;
  1736. gentity_t *hitEnt = NULL;
  1737. //FIXME: variable kick height?
  1738. if ( kickEnd && !VectorCompare( kickEnd, vec3_origin ) )
  1739. {//they passed us the end point of the trace, just use that
  1740. //this makes the trace flat
  1741. VectorSet( traceOrg, ent->currentOrigin[0], ent->currentOrigin[1], kickEnd[2] );
  1742. VectorCopy( kickEnd, traceEnd );
  1743. }
  1744. else
  1745. {//extrude
  1746. VectorSet( traceOrg, ent->currentOrigin[0], ent->currentOrigin[1], ent->currentOrigin[2]+ent->maxs[2]*0.5f );
  1747. VectorMA( traceOrg, kickDist, kickDir, traceEnd );
  1748. }
  1749. gi.trace( &trace, traceOrg, kickMins, kickMaxs, traceEnd, ent->s.number, MASK_SHOT );//clipmask ok?
  1750. if ( trace.fraction < 1.0f && !trace.startsolid && !trace.allsolid && trace.entityNum < ENTITYNUM_NONE )
  1751. {
  1752. hitEnt = &g_entities[trace.entityNum];
  1753. if ( ent->client->ps.lastKickedEntNum != trace.entityNum )
  1754. {
  1755. TIMER_Remove( ent, "kickSoundDebounce" );
  1756. ent->client->ps.lastKickedEntNum = trace.entityNum;
  1757. }
  1758. if ( hitEnt )
  1759. {//we hit an entity
  1760. if ( hitEnt->client )
  1761. {
  1762. if ( !(hitEnt->client->ps.pm_flags&PMF_TIME_KNOCKBACK)
  1763. && TIMER_Done( hitEnt, "kickedDebounce" ) )//not already flying through air? Intended to stop multiple hits, but...
  1764. {//FIXME: this should not always work
  1765. if ( PM_InKnockDown( &hitEnt->client->ps )
  1766. && !PM_InGetUp( &hitEnt->client->ps ) )
  1767. {//don't hit people who are knocked down or being knocked down (okay to hit people getting up, though)
  1768. return NULL;
  1769. }
  1770. if ( PM_InRoll( &hitEnt->client->ps ) )
  1771. {//can't hit people who are rolling
  1772. return NULL;
  1773. }
  1774. //don't hit same ent more than once per kick
  1775. if ( hitEnt->takedamage )
  1776. {//hurt it
  1777. G_Damage( hitEnt, ent, ent, kickDir, trace.endpos, kickDamage, DAMAGE_NO_KNOCKBACK|DAMAGE_NO_KILL, MOD_MELEE );
  1778. }
  1779. //do kick hit sound and impact effect
  1780. if ( TIMER_Done( ent, "kickSoundDebounce" ) )
  1781. {
  1782. if ( ent->client->ps.torsoAnim == BOTH_A7_HILT )
  1783. {
  1784. G_Sound( ent, G_SoundIndex( "sound/movers/objects/saber_slam" ) );
  1785. }
  1786. else
  1787. {
  1788. vec3_t fxOrg, fxDir;
  1789. VectorCopy( kickDir, fxDir );
  1790. VectorMA( trace.endpos, Q_flrand( 5.0f, 10.0f ), fxDir, fxOrg );
  1791. VectorScale( fxDir, -1, fxDir );
  1792. G_PlayEffect( G_EffectIndex( "melee/kick_impact" ), fxOrg, fxDir );
  1793. //G_Sound( ent, G_SoundIndex( va( "sound/weapons/melee/punch%d", Q_irand( 1, 4 ) ) ) );
  1794. }
  1795. TIMER_Set( ent, "kickSoundDebounce", 2000 );
  1796. }
  1797. TIMER_Set( hitEnt, "kickedDebounce", 1000 );
  1798. if ( ent->client->ps.torsoAnim == BOTH_A7_HILT )
  1799. {//hit in head
  1800. if ( hitEnt->health > 0 )
  1801. {//knock down
  1802. if ( kickPush >= 150.0f/*75.0f*/ && !Q_irand( 0, 1 ) )
  1803. {//knock them down
  1804. if ( !(hitEnt->flags&FL_NO_KNOCKBACK) )
  1805. {
  1806. G_Throw( hitEnt, kickDir, kickPush/3.0f );
  1807. }
  1808. G_Knockdown( hitEnt, ent, kickDir, 300, qtrue );
  1809. }
  1810. else
  1811. {//force them to play a pain anim
  1812. if ( hitEnt->s.number < MAX_CLIENTS )
  1813. {
  1814. NPC_SetPainEvent( hitEnt );
  1815. }
  1816. else
  1817. {
  1818. GEntity_PainFunc( hitEnt, ent, ent, hitEnt->currentOrigin, 0, MOD_MELEE );
  1819. }
  1820. }
  1821. //just so we don't hit him again...
  1822. hitEnt->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  1823. hitEnt->client->ps.pm_time = 100;
  1824. }
  1825. else
  1826. {
  1827. if ( !(hitEnt->flags&FL_NO_KNOCKBACK) )
  1828. {
  1829. G_Throw( hitEnt, kickDir, kickPush );
  1830. }
  1831. //see if we should play a better looking death on them
  1832. G_ThrownDeathAnimForDeathAnim( hitEnt, trace.endpos );
  1833. }
  1834. }
  1835. else if ( ent->client->ps.legsAnim == BOTH_GETUP_BROLL_B
  1836. || ent->client->ps.legsAnim == BOTH_GETUP_BROLL_F
  1837. || ent->client->ps.legsAnim == BOTH_GETUP_FROLL_B
  1838. || ent->client->ps.legsAnim == BOTH_GETUP_FROLL_F )
  1839. {
  1840. if ( hitEnt->health > 0 )
  1841. {//knock down
  1842. if ( hitEnt->client->ps.groundEntityNum == ENTITYNUM_NONE )
  1843. {//he's in the air? Send him flying back
  1844. if ( !(hitEnt->flags&FL_NO_KNOCKBACK) )
  1845. {
  1846. G_Throw( hitEnt, kickDir, kickPush );
  1847. }
  1848. }
  1849. else
  1850. {
  1851. //just so we don't hit him again...
  1852. hitEnt->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  1853. hitEnt->client->ps.pm_time = 100;
  1854. }
  1855. //knock them down
  1856. G_Knockdown( hitEnt, ent, kickDir, 300, qtrue );
  1857. }
  1858. else
  1859. {
  1860. if ( !(hitEnt->flags&FL_NO_KNOCKBACK) )
  1861. {
  1862. G_Throw( hitEnt, kickDir, kickPush );
  1863. }
  1864. //see if we should play a better looking death on them
  1865. G_ThrownDeathAnimForDeathAnim( hitEnt, trace.endpos );
  1866. }
  1867. }
  1868. else if ( hitEnt->health <= 0 )
  1869. {//we kicked a dead guy
  1870. //throw harder - FIXME: no matter how hard I push them, they don't go anywhere... corpses use less physics???
  1871. if ( !(hitEnt->flags&FL_NO_KNOCKBACK) )
  1872. {
  1873. G_Throw( hitEnt, kickDir, kickPush*4 );
  1874. }
  1875. //see if we should play a better looking death on them
  1876. G_ThrownDeathAnimForDeathAnim( hitEnt, trace.endpos );
  1877. }
  1878. else
  1879. {
  1880. if ( !(hitEnt->flags&FL_NO_KNOCKBACK) )
  1881. {
  1882. G_Throw( hitEnt, kickDir, kickPush );
  1883. }
  1884. if ( kickPush >= 150.0f/*75.0f*/ && !Q_irand( 0, 2 ) )
  1885. {
  1886. G_Knockdown( hitEnt, ent, kickDir, 300, qtrue );
  1887. }
  1888. else
  1889. {
  1890. G_Knockdown( hitEnt, ent, kickDir, kickPush, qtrue );
  1891. }
  1892. }
  1893. }
  1894. }
  1895. else
  1896. {//FIXME: don't do this in repeated frames... only allow 1 frame in kick to hit wall? The most extended one? Pass in a bool on that frame.
  1897. if ( doSoundOnWalls )
  1898. {//do kick hit sound and impact effect
  1899. if ( TIMER_Done( ent, "kickSoundDebounce" ) )
  1900. {
  1901. if ( ent->client->ps.torsoAnim == BOTH_A7_HILT )
  1902. {
  1903. G_Sound( ent, G_SoundIndex( "sound/movers/objects/saber_slam" ) );
  1904. }
  1905. else
  1906. {
  1907. G_PlayEffect( G_EffectIndex( "melee/kick_impact" ), trace.endpos, trace.plane.normal );
  1908. //G_Sound( ent, G_SoundIndex( va( "sound/weapons/melee/punch%d", Q_irand( 1, 4 ) ) ) );
  1909. }
  1910. TIMER_Set( ent, "kickSoundDebounce", 2000 );
  1911. }
  1912. }
  1913. }
  1914. }
  1915. }
  1916. return (hitEnt);
  1917. }
  1918. qboolean G_CheckRollSafety( gentity_t *self, int anim, float testDist )
  1919. {
  1920. vec3_t forward, right, testPos, angles;
  1921. trace_t trace;
  1922. int contents = (CONTENTS_SOLID|CONTENTS_BOTCLIP);
  1923. if ( !self || !self->client )
  1924. {
  1925. return qfalse;
  1926. }
  1927. if ( self->s.number < MAX_CLIENTS )
  1928. {//player
  1929. contents |= CONTENTS_PLAYERCLIP;
  1930. }
  1931. else
  1932. {//NPC
  1933. contents |= CONTENTS_MONSTERCLIP;
  1934. }
  1935. if ( PM_InAttackRoll( self->client->ps.legsAnim ) )
  1936. {//we don't care if people are in the way, we'll knock them down!
  1937. contents &= ~CONTENTS_BODY;
  1938. }
  1939. angles[PITCH] = angles[ROLL] = 0;
  1940. angles[YAW] = self->client->ps.viewangles[YAW];//Add ucmd.angles[YAW]?
  1941. AngleVectors( angles, forward, right, NULL );
  1942. switch ( anim )
  1943. {
  1944. case BOTH_GETUP_BROLL_R:
  1945. case BOTH_GETUP_FROLL_R:
  1946. VectorMA( self->currentOrigin, testDist, right, testPos );
  1947. break;
  1948. case BOTH_GETUP_BROLL_L:
  1949. case BOTH_GETUP_FROLL_L:
  1950. VectorMA( self->currentOrigin, -testDist, right, testPos );
  1951. break;
  1952. case BOTH_GETUP_BROLL_F:
  1953. case BOTH_GETUP_FROLL_F:
  1954. VectorMA( self->currentOrigin, testDist, forward, testPos );
  1955. break;
  1956. case BOTH_GETUP_BROLL_B:
  1957. case BOTH_GETUP_FROLL_B:
  1958. VectorMA( self->currentOrigin, -testDist, forward, testPos );
  1959. break;
  1960. default://FIXME: add normal rolls? Make generic for any forced-movement anim?
  1961. return qtrue;
  1962. break;
  1963. }
  1964. gi.trace( &trace, self->currentOrigin, self->mins, self->maxs, testPos, self->s.number, contents );
  1965. if ( trace.fraction < 1.0f
  1966. || trace.allsolid
  1967. || trace.startsolid )
  1968. {//inside something or will hit something
  1969. return qfalse;
  1970. }
  1971. return qtrue;
  1972. }
  1973. void G_CamPullBackForLegsAnim( gentity_t *ent, qboolean useTorso = qfalse )
  1974. {
  1975. if ( (ent->s.number < MAX_CLIENTS||G_ControlledByPlayer(ent)) )
  1976. {
  1977. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (useTorso?(animNumber_t)ent->client->ps.torsoAnim:(animNumber_t)ent->client->ps.legsAnim) );
  1978. float elapsedTime = (float)(animLength-(useTorso?ent->client->ps.torsoAnimTimer:ent->client->ps.legsAnimTimer));
  1979. float backDist = 0;
  1980. if ( elapsedTime < animLength/2.0f )
  1981. {//starting anim
  1982. backDist = (elapsedTime/animLength)*120.0f;
  1983. }
  1984. else
  1985. {//ending anim
  1986. backDist = ((animLength-elapsedTime)/animLength)*120.0f;
  1987. }
  1988. cg.overrides.active |= CG_OVERRIDE_3RD_PERSON_RNG;
  1989. cg.overrides.thirdPersonRange = cg_thirdPersonRange.value+backDist;
  1990. }
  1991. }
  1992. void G_CamCircleForLegsAnim( gentity_t *ent )
  1993. {
  1994. if ( (ent->s.number < MAX_CLIENTS||G_ControlledByPlayer(ent)) )
  1995. {
  1996. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.legsAnim );
  1997. float elapsedTime = (float)(animLength-ent->client->ps.legsAnimTimer);
  1998. float angle = 0;
  1999. angle = (elapsedTime/animLength)*360.0f;
  2000. cg.overrides.active |= CG_OVERRIDE_3RD_PERSON_ANG;
  2001. cg.overrides.thirdPersonAngle = cg_thirdPersonAngle.value+angle;
  2002. }
  2003. }
  2004. qboolean G_GrabClient( gentity_t *ent, usercmd_t *ucmd )
  2005. {
  2006. gentity_t *bestEnt = NULL, *radiusEnts[ 128 ];
  2007. int numEnts;
  2008. const float radius = 100.0f;
  2009. const float radiusSquared = (radius*radius);
  2010. float bestDistSq = (radiusSquared+1.0f), distSq;
  2011. int i;
  2012. vec3_t boltOrg;
  2013. numEnts = G_GetEntsNearBolt( ent, radiusEnts, radius, ent->handRBolt, boltOrg );
  2014. for ( i = 0; i < numEnts; i++ )
  2015. {
  2016. if ( !radiusEnts[i]->inuse )
  2017. {
  2018. continue;
  2019. }
  2020. if ( radiusEnts[i] == ent )
  2021. {//Skip the rancor ent
  2022. continue;
  2023. }
  2024. if ( !radiusEnts[i]->inuse || radiusEnts[i]->health <= 0 )
  2025. {//must be alive
  2026. continue;
  2027. }
  2028. if ( radiusEnts[i]->client == NULL )
  2029. {//must be a client
  2030. continue;
  2031. }
  2032. if ( (radiusEnts[i]->client->ps.eFlags&EF_HELD_BY_RANCOR)
  2033. ||(radiusEnts[i]->client->ps.eFlags&EF_HELD_BY_WAMPA)
  2034. ||(radiusEnts[i]->client->ps.eFlags&EF_HELD_BY_SAND_CREATURE) )
  2035. {//can't be one being held
  2036. continue;
  2037. }
  2038. if ( PM_LockedAnim( radiusEnts[i]->client->ps.torsoAnim )
  2039. || PM_LockedAnim( radiusEnts[i]->client->ps.legsAnim ) )
  2040. {//don't interrupt
  2041. continue;
  2042. }
  2043. if ( radiusEnts[i]->client->ps.groundEntityNum == ENTITYNUM_NONE )
  2044. {//must be on ground
  2045. continue;
  2046. }
  2047. if ( PM_InOnGroundAnim( &radiusEnts[i]->client->ps ) )
  2048. {//must be standing up
  2049. continue;
  2050. }
  2051. if ( fabs(radiusEnts[i]->currentOrigin[2]-ent->currentOrigin[2])>8.0f )
  2052. {//have to be close in Z
  2053. continue;
  2054. }
  2055. if ( !PM_HasAnimation( radiusEnts[i], BOTH_PLAYER_PA_1 ) )
  2056. {//doesn't have matching anims
  2057. continue;
  2058. }
  2059. distSq = DistanceSquared( radiusEnts[i]->currentOrigin, boltOrg );
  2060. if ( distSq < bestDistSq )
  2061. {
  2062. bestDistSq = distSq;
  2063. bestEnt = radiusEnts[i];
  2064. }
  2065. }
  2066. if ( bestEnt != NULL )
  2067. {
  2068. int lockType = LOCK_KYLE_GRAB1;
  2069. if ( ucmd->forwardmove > 0 )
  2070. {
  2071. lockType = LOCK_KYLE_GRAB3;
  2072. }
  2073. else if ( ucmd->forwardmove < 0 )
  2074. {
  2075. lockType = LOCK_KYLE_GRAB2;
  2076. }
  2077. WP_SabersCheckLock2( ent, bestEnt, (sabersLockMode_t)lockType );
  2078. return qtrue;
  2079. }
  2080. return qfalse;
  2081. }
  2082. qboolean G_PullAttack( gentity_t *ent, usercmd_t *ucmd )
  2083. {
  2084. qboolean overridAngles = qfalse;
  2085. if ( ent->client->ps.torsoAnim == BOTH_PULL_IMPALE_STAB
  2086. || ent->client->ps.torsoAnim == BOTH_PULL_IMPALE_SWING )
  2087. {//pulling
  2088. if ( ent->NPC )
  2089. {
  2090. VectorClear( ent->client->ps.moveDir );
  2091. }
  2092. overridAngles = (PM_LockAngles( ent, ucmd )?qtrue:overridAngles);
  2093. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2094. }
  2095. else if ( ent->client->ps.torsoAnim == BOTH_PULLED_INAIR_B
  2096. || ent->client->ps.torsoAnim == BOTH_PULLED_INAIR_F )
  2097. {//being pulled
  2098. gentity_t *puller = &g_entities[ent->client->ps.pullAttackEntNum];
  2099. if ( puller
  2100. && puller->inuse
  2101. && puller->client
  2102. && ( puller->client->ps.torsoAnim == BOTH_PULL_IMPALE_STAB
  2103. || puller->client->ps.torsoAnim == BOTH_PULL_IMPALE_SWING ) )
  2104. {
  2105. vec3_t pullDir;
  2106. vec3_t pullPos;
  2107. //calc where to pull me to
  2108. /*
  2109. VectorCopy( puller->client->ps.saber[0].blade[0].muzzlePoint, pullPos );
  2110. VectorMA( pullPos, puller->client->ps.saber[0].blade[0].length*0.5f, puller->client->ps.saber[0].blade[0].muzzleDir, pullPos );
  2111. */
  2112. vec3_t pullerFwd;
  2113. AngleVectors( puller->client->ps.viewangles, pullerFwd, NULL, NULL );
  2114. VectorMA( puller->currentOrigin, (puller->maxs[0]*1.5f)+16.0f, pullerFwd, pullPos );
  2115. //pull me towards that pos
  2116. VectorSubtract( pullPos, ent->currentOrigin, pullDir );
  2117. float pullDist = VectorNormalize( pullDir );
  2118. int sweetSpotTime = (puller->client->ps.torsoAnim == BOTH_PULL_IMPALE_STAB)?1250:1350;
  2119. float pullLength = PM_AnimLength( puller->client->clientInfo.animFileIndex, (animNumber_t)puller->client->ps.torsoAnim )-sweetSpotTime;
  2120. if ( pullLength <= 0.25f )
  2121. {
  2122. pullLength = 0.25f;
  2123. }
  2124. //float pullTimeRemaining = ent->client->ps.pullAttackTime - level.time;
  2125. //float pullSpeed = pullDist * (pullTimeRemaining/pullLength);
  2126. float pullSpeed = (pullDist*1000.0f)/pullLength;
  2127. VectorScale( pullDir, pullSpeed, ent->client->ps.velocity );
  2128. //slide, if necessary
  2129. ent->client->ps.pm_flags |= PMF_TIME_NOFRICTION;
  2130. ent->client->ps.pm_time = 100;
  2131. //make it so I don't actually hurt them when pulled at them...
  2132. ent->forcePuller = puller->s.number;
  2133. ent->forcePushTime = level.time + 100; // let the push effect last for 100 more ms
  2134. //look at him
  2135. PM_AdjustAnglesToPuller( ent, puller, ucmd, qboolean(ent->client->ps.legsAnim==BOTH_PULLED_INAIR_B) );
  2136. overridAngles = qtrue;
  2137. //don't move
  2138. if ( ent->NPC )
  2139. {
  2140. VectorClear( ent->client->ps.moveDir );
  2141. }
  2142. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2143. }
  2144. }
  2145. return overridAngles;
  2146. }
  2147. void G_FixMins( gentity_t *ent )
  2148. {
  2149. //do a trace to make sure it's okay
  2150. float downdist = (DEFAULT_MINS_2-ent->mins[2]);
  2151. vec3_t end={ent->currentOrigin[0],ent->currentOrigin[1],ent->currentOrigin[2]+downdist};
  2152. trace_t trace;
  2153. gi.trace( &trace, ent->currentOrigin, ent->mins, ent->maxs, end, ent->s.number, ent->clipmask );
  2154. if ( !trace.allsolid && !trace.startsolid )
  2155. {
  2156. if ( trace.fraction >= 1.0f )
  2157. {//all clear
  2158. //drop the bottom of my bbox back down
  2159. ent->mins[2] = DEFAULT_MINS_2;
  2160. if ( ent->client )
  2161. {
  2162. ent->client->ps.pm_flags &= ~PMF_FIX_MINS;
  2163. }
  2164. }
  2165. else
  2166. {//move me up so the bottom of my bbox will be where the trace ended, at least
  2167. //need to trace up, too
  2168. float updist = ((1.0f-trace.fraction) * -downdist);
  2169. end[2] = ent->currentOrigin[2]+updist;
  2170. gi.trace( &trace, ent->currentOrigin, ent->mins, ent->maxs, end, ent->s.number, ent->clipmask );
  2171. if ( !trace.allsolid && !trace.startsolid )
  2172. {
  2173. if ( trace.fraction >= 1.0f )
  2174. {//all clear
  2175. //move me up
  2176. ent->currentOrigin[2] += updist;
  2177. //drop the bottom of my bbox back down
  2178. ent->mins[2] = DEFAULT_MINS_2;
  2179. G_SetOrigin( ent, ent->currentOrigin );
  2180. gi.linkentity( ent );
  2181. if ( ent->client )
  2182. {
  2183. ent->client->ps.pm_flags &= ~PMF_FIX_MINS;
  2184. }
  2185. }
  2186. else
  2187. {//crap, no room to expand!
  2188. if ( ent->client->ps.legsAnimTimer <= 200 )
  2189. {//at the end of the anim, and we can't leave ourselves like this
  2190. //so drop the maxs, put the mins back and move us up
  2191. ent->maxs[2] += downdist;
  2192. ent->currentOrigin[2] -= downdist;
  2193. ent->mins[2] = DEFAULT_MINS_2;
  2194. G_SetOrigin( ent, ent->currentOrigin );
  2195. gi.linkentity( ent );
  2196. //this way we'll be in a crouch when we're done
  2197. ent->client->ps.legsAnimTimer = ent->client->ps.torsoAnimTimer = 0;
  2198. ent->client->ps.pm_flags |= PMF_DUCKED;
  2199. //FIXME: do we need to set a crouch anim here?
  2200. if ( ent->client )
  2201. {
  2202. ent->client->ps.pm_flags &= ~PMF_FIX_MINS;
  2203. }
  2204. }
  2205. }
  2206. }//crap, stuck
  2207. }
  2208. }//crap, stuck!
  2209. }
  2210. qboolean G_CheckClampUcmd( gentity_t *ent, usercmd_t *ucmd )
  2211. {
  2212. qboolean overridAngles = qfalse;
  2213. if ( ent->client->NPC_class == CLASS_PROTOCOL
  2214. || ent->client->NPC_class == CLASS_R2D2
  2215. || ent->client->NPC_class == CLASS_R5D2
  2216. || ent->client->NPC_class == CLASS_GONK
  2217. || ent->client->NPC_class == CLASS_MOUSE )
  2218. {//these droids *cannot* strafe (looks bad)
  2219. if ( ucmd->rightmove )
  2220. {
  2221. //clear the strafe
  2222. ucmd->rightmove = 0;
  2223. //movedir is invalid now, but PM_WalkMove will rebuild it from the ucmds, with the appropriate speed
  2224. VectorClear( ent->client->ps.moveDir );
  2225. }
  2226. }
  2227. if ( ent->client->ps.pullAttackEntNum < ENTITYNUM_WORLD
  2228. && ent->client->ps.pullAttackTime > level.time )
  2229. {
  2230. return G_PullAttack( ent, ucmd );
  2231. }
  2232. if ( (ent->s.number < MAX_CLIENTS||G_ControlledByPlayer(ent))
  2233. && ent->s.weapon == WP_MELEE
  2234. && ent->client->ps.torsoAnim == BOTH_KYLE_GRAB )
  2235. {//see if we grabbed enemy
  2236. if ( ent->client->ps.torsoAnimTimer <= 200 )
  2237. {//close to end of anim
  2238. if ( G_GrabClient( ent, ucmd ) )
  2239. {//grabbed someone!
  2240. }
  2241. else
  2242. {//missed
  2243. NPC_SetAnim( ent, SETANIM_BOTH, BOTH_KYLE_MISS, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  2244. ent->client->ps.weaponTime = ent->client->ps.torsoAnimTimer;
  2245. }
  2246. }
  2247. ucmd->rightmove = ucmd->forwardmove = ucmd->upmove = 0;
  2248. }
  2249. if ( (!ent->s.number&&ent->aimDebounceTime>level.time)
  2250. || (ent->client->ps.pm_time && (ent->client->ps.pm_flags&PMF_TIME_KNOCKBACK))
  2251. || ent->forcePushTime > level.time )
  2252. {//being knocked back, can't do anything!
  2253. ucmd->buttons = 0;
  2254. ucmd->forwardmove = 0;
  2255. ucmd->rightmove = 0;
  2256. ucmd->upmove = 0;
  2257. if ( ent->NPC )
  2258. {
  2259. VectorClear( ent->client->ps.moveDir );
  2260. }
  2261. }
  2262. overridAngles = (PM_AdjustAnglesForKnockdown( ent, ucmd, qfalse )?qtrue:overridAngles);
  2263. if ( PM_GetupAnimNoMove( ent->client->ps.legsAnim ) )
  2264. {
  2265. ucmd->forwardmove = ucmd->rightmove = 0;//ucmd->upmove = ?
  2266. }
  2267. //check saberlock
  2268. if ( ent->client->ps.saberLockTime > level.time )
  2269. {//in saberlock
  2270. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2271. if ( ent->client->ps.saberLockTime - level.time > SABER_LOCK_DELAYED_TIME )
  2272. {//2 second delay before either can push
  2273. //FIXME: base on difficulty
  2274. ucmd->buttons = 0;
  2275. }
  2276. else
  2277. {
  2278. ucmd->buttons &= ~(ucmd->buttons&~BUTTON_ATTACK);
  2279. }
  2280. overridAngles = (PM_AdjustAnglesForSaberLock( ent, ucmd )?qtrue:overridAngles);
  2281. if ( ent->NPC )
  2282. {
  2283. VectorClear( ent->client->ps.moveDir );
  2284. }
  2285. }
  2286. //check force drain
  2287. if ( (ent->client->ps.forcePowersActive&(1<<FP_DRAIN)) )
  2288. {//draining
  2289. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2290. ucmd->buttons &= ~(BUTTON_ATTACK|BUTTON_ALT_ATTACK|BUTTON_FORCE_FOCUS);
  2291. if ( ent->NPC )
  2292. {
  2293. VectorClear( ent->client->ps.moveDir );
  2294. }
  2295. }
  2296. if ( ent->client->ps.saberMove == LS_A_LUNGE )
  2297. {//can't move during lunge
  2298. ucmd->rightmove = ucmd->upmove = 0;
  2299. if ( ent->client->ps.legsAnimTimer > 500 && (ent->s.number || !player_locked) )
  2300. {
  2301. ucmd->forwardmove = 127;
  2302. }
  2303. else
  2304. {
  2305. ucmd->forwardmove = 0;
  2306. }
  2307. if ( ent->NPC )
  2308. {//invalid now
  2309. VectorClear( ent->client->ps.moveDir );
  2310. }
  2311. }
  2312. if ( ent->client->ps.legsAnim == BOTH_FORCEWALLRUNFLIP_ALT
  2313. && ent->client->ps.legsAnimTimer )
  2314. {
  2315. vec3_t vFwd, fwdAng = {0,ent->currentAngles[YAW],0};
  2316. AngleVectors( fwdAng, vFwd, NULL, NULL );
  2317. if ( ent->client->ps.groundEntityNum == ENTITYNUM_NONE )
  2318. {
  2319. float savZ = ent->client->ps.velocity[2];
  2320. VectorScale( vFwd, 100, ent->client->ps.velocity );
  2321. ent->client->ps.velocity[2] = savZ;
  2322. }
  2323. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2324. overridAngles = (PM_AdjustAnglesForWallRunUpFlipAlt( ent, ucmd )?qtrue:overridAngles);
  2325. }
  2326. if ( ent->client->ps.saberMove == LS_A_JUMP_T__B_ )
  2327. {//can't move during leap
  2328. if ( ent->client->ps.groundEntityNum != ENTITYNUM_NONE || (!ent->s.number && player_locked) )
  2329. {//hit the ground
  2330. ucmd->forwardmove = 0;
  2331. }
  2332. ucmd->rightmove = ucmd->upmove = 0;
  2333. if ( ent->NPC )
  2334. {//invalid now
  2335. VectorClear( ent->client->ps.moveDir );
  2336. }
  2337. }
  2338. if ( ent->client->ps.saberMove == LS_A_BACKFLIP_ATK
  2339. && ent->client->ps.legsAnim == BOTH_JUMPATTACK7 )
  2340. {//backflip attack
  2341. if ( ent->client->ps.legsAnimTimer > 800 //not at end
  2342. && PM_AnimLength( ent->client->clientInfo.animFileIndex, BOTH_JUMPATTACK7 ) - ent->client->ps.legsAnimTimer >= 400 )//not in beginning
  2343. {//middle of anim
  2344. if ( ent->client->ps.groundEntityNum != ENTITYNUM_NONE )
  2345. {//still on ground?
  2346. vec3_t yawAngles, backDir;
  2347. //push backwards some?
  2348. VectorSet( yawAngles, 0, ent->client->ps.viewangles[YAW]+180, 0 );
  2349. AngleVectors( yawAngles, backDir, 0, 0 );
  2350. VectorScale( backDir, 100, ent->client->ps.velocity );
  2351. //jump!
  2352. ent->client->ps.velocity[2] = 180;
  2353. ent->client->ps.forceJumpZStart = ent->client->ps.origin[2];//so we don't take damage if we land at same height
  2354. ent->client->ps.pm_flags |= PMF_JUMPING|PMF_SLOW_MO_FALL;
  2355. //FIXME: NPCs yell?
  2356. G_AddEvent( ent, EV_JUMP, 0 );
  2357. G_SoundOnEnt( ent, CHAN_BODY, "sound/weapons/force/jump.wav" );
  2358. ucmd->upmove = 0;//clear any actual jump command
  2359. }
  2360. }
  2361. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2362. if ( ent->NPC )
  2363. {//invalid now
  2364. VectorClear( ent->client->ps.moveDir );
  2365. }
  2366. }
  2367. if ( ent->client->ps.legsAnim == BOTH_JUMPATTACK6
  2368. && ent->client->ps.legsAnimTimer > 0 )
  2369. {
  2370. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2371. //FIXME: don't slide off people/obstacles?
  2372. if ( ent->client->ps.legsAnimTimer >= 100 //not at end
  2373. && PM_AnimLength( ent->client->clientInfo.animFileIndex, BOTH_JUMPATTACK6 ) - ent->client->ps.legsAnimTimer >= 250 )//not in beginning
  2374. {//middle of anim
  2375. //push forward
  2376. ucmd->forwardmove = 127;
  2377. }
  2378. if ( (ent->client->ps.legsAnimTimer >= 900 //not at end
  2379. && PM_AnimLength( ent->client->clientInfo.animFileIndex, BOTH_JUMPATTACK6 ) - ent->client->ps.legsAnimTimer >= 950 ) //not in beginning
  2380. || ( ent->client->ps.legsAnimTimer >= 1600
  2381. && PM_AnimLength( ent->client->clientInfo.animFileIndex, BOTH_JUMPATTACK6 ) - ent->client->ps.legsAnimTimer >= 400 ) )//not in beginning
  2382. {//one of the two jumps
  2383. if ( ent->client->ps.groundEntityNum != ENTITYNUM_NONE )
  2384. {//still on ground?
  2385. //jump!
  2386. ent->client->ps.velocity[2] = 250;
  2387. ent->client->ps.forceJumpZStart = ent->client->ps.origin[2];//so we don't take damage if we land at same height
  2388. ent->client->ps.pm_flags |= PMF_JUMPING;//|PMF_SLOW_MO_FALL;
  2389. //FIXME: NPCs yell?
  2390. G_AddEvent( ent, EV_JUMP, 0 );
  2391. G_SoundOnEnt( ent, CHAN_BODY, "sound/weapons/force/jump.wav" );
  2392. }
  2393. else
  2394. {//FIXME: if this is the second jump, maybe we should just stop the anim?
  2395. }
  2396. }
  2397. //else
  2398. {//disallow turning unless in the middle frame when you're on the ground
  2399. //overridAngles = (PM_AdjustAnglesForDualJumpAttack( ent, ucmd )?qtrue:overridAngles);
  2400. }
  2401. //dynamically reduce bounding box to let character sail over heads of enemies
  2402. if ( ( ent->client->ps.legsAnimTimer >= 1450
  2403. && PM_AnimLength( ent->client->clientInfo.animFileIndex, BOTH_JUMPATTACK6 ) - ent->client->ps.legsAnimTimer >= 400 )
  2404. ||(ent->client->ps.legsAnimTimer >= 400
  2405. && PM_AnimLength( ent->client->clientInfo.animFileIndex, BOTH_JUMPATTACK6 ) - ent->client->ps.legsAnimTimer >= 1100 ) )
  2406. {//in a part of the anim that we're pretty much sideways in, raise up the mins
  2407. ent->mins[2] = 0;
  2408. ent->client->ps.pm_flags |= PMF_FIX_MINS;
  2409. }
  2410. else if ( (ent->client->ps.pm_flags&PMF_FIX_MINS) )
  2411. {//drop the mins back down
  2412. G_FixMins( ent );
  2413. }
  2414. if ( ent->NPC )
  2415. {//invalid now
  2416. VectorClear( ent->client->ps.moveDir );
  2417. }
  2418. }
  2419. else if ( (ent->client->ps.pm_flags&PMF_FIX_MINS) )
  2420. {
  2421. G_FixMins( ent );
  2422. }
  2423. if ( ( ent->client->ps.legsAnim == BOTH_BUTTERFLY_FL1
  2424. && ent->client->ps.saberMove == LS_JUMPATTACK_STAFF_LEFT )
  2425. || ( ent->client->ps.legsAnim == BOTH_BUTTERFLY_FR1
  2426. && ent->client->ps.saberMove == LS_JUMPATTACK_STAFF_RIGHT )
  2427. || ( ent->client->ps.legsAnim == BOTH_BUTTERFLY_RIGHT
  2428. && ent->client->ps.saberMove == LS_BUTTERFLY_RIGHT )
  2429. || ( ent->client->ps.legsAnim == BOTH_BUTTERFLY_LEFT
  2430. && ent->client->ps.saberMove == LS_BUTTERFLY_LEFT ) )
  2431. {//forward flip/spin attack
  2432. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2433. /*if ( ent->client->ps.legsAnim == BOTH_BUTTERFLY_FL1
  2434. || ent->client->ps.legsAnim == BOTH_BUTTERFLY_FR1
  2435. || ent->client->ps.legsAnim == BOTH_BUTTERFLY_LEFT
  2436. || ent->client->ps.legsAnim == BOTH_BUTTERFLY RIGHT )*/
  2437. {
  2438. //FIXME: don't slide off people/obstacles?
  2439. if ( ent->client->ps.legsAnim != BOTH_BUTTERFLY_LEFT
  2440. && ent->client->ps.legsAnim != BOTH_BUTTERFLY_RIGHT )
  2441. {
  2442. if ( ent->client->ps.legsAnimTimer >= 100 //not at end
  2443. && PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.legsAnim ) - ent->client->ps.legsAnimTimer >= 250 )//not in beginning
  2444. {//middle of anim
  2445. //push forward
  2446. ucmd->forwardmove = 127;
  2447. }
  2448. }
  2449. if ( ent->client->ps.legsAnimTimer >= 1700 && ent->client->ps.legsAnimTimer < 1800 )
  2450. {//one of the two jumps
  2451. if ( ent->client->ps.groundEntityNum != ENTITYNUM_NONE )
  2452. {//still on ground?
  2453. //jump!
  2454. ent->client->ps.velocity[2] = 250;
  2455. ent->client->ps.forceJumpZStart = ent->client->ps.origin[2];//so we don't take damage if we land at same height
  2456. ent->client->ps.pm_flags |= PMF_JUMPING;//|PMF_SLOW_MO_FALL;
  2457. //FIXME: NPCs yell?
  2458. G_AddEvent( ent, EV_JUMP, 0 );
  2459. G_SoundOnEnt( ent, CHAN_BODY, "sound/weapons/force/jump.wav" );
  2460. }
  2461. else
  2462. {//FIXME: if this is the second jump, maybe we should just stop the anim?
  2463. }
  2464. }
  2465. //disallow turning unless in the middle frame when you're on the ground
  2466. //overridAngles = (PM_AdjustAnglesForDualJumpAttack( ent, ucmd )?qtrue:overridAngles);
  2467. }
  2468. if ( ent->NPC )
  2469. {//invalid now
  2470. VectorClear( ent->client->ps.moveDir );
  2471. }
  2472. }
  2473. if ( ent->client->ps.legsAnim == BOTH_A7_SOULCAL
  2474. && ent->client->ps.saberMove == LS_STAFF_SOULCAL )
  2475. {//forward spinning staff attack
  2476. ucmd->upmove = 0;
  2477. if ( PM_CanRollFromSoulCal( &ent->client->ps ) )
  2478. {
  2479. ucmd->upmove = -127;
  2480. }
  2481. else
  2482. {
  2483. ucmd->rightmove = 0;
  2484. //FIXME: don't slide off people/obstacles?
  2485. if ( ent->client->ps.legsAnimTimer >= 2750 )
  2486. {//not at end
  2487. //push forward
  2488. ucmd->forwardmove = 64;
  2489. }
  2490. else
  2491. {
  2492. ucmd->forwardmove = 0;
  2493. }
  2494. }
  2495. if ( ent->client->ps.legsAnimTimer >= 2650
  2496. && ent->client->ps.legsAnimTimer < 2850 )
  2497. {//the jump
  2498. if ( ent->client->ps.groundEntityNum != ENTITYNUM_NONE )
  2499. {//still on ground?
  2500. //jump!
  2501. ent->client->ps.velocity[2] = 250;
  2502. ent->client->ps.forceJumpZStart = ent->client->ps.origin[2];//so we don't take damage if we land at same height
  2503. ent->client->ps.pm_flags |= PMF_JUMPING;//|PMF_SLOW_MO_FALL;
  2504. //FIXME: NPCs yell?
  2505. G_AddEvent( ent, EV_JUMP, 0 );
  2506. G_SoundOnEnt( ent, CHAN_BODY, "sound/weapons/force/jump.wav" );
  2507. }
  2508. }
  2509. if ( ent->NPC )
  2510. {//invalid now
  2511. VectorClear( ent->client->ps.moveDir );
  2512. }
  2513. }
  2514. if ( ent->client->ps.torsoAnim == BOTH_LK_DL_S_T_SB_1_W )
  2515. {
  2516. G_CamPullBackForLegsAnim( ent, qtrue );
  2517. }
  2518. if ( ent->client->ps.torsoAnim == BOTH_A6_FB
  2519. || ent->client->ps.torsoAnim == BOTH_A6_LR )
  2520. {//can't turn or move during dual attack
  2521. if ( ent->NPC )
  2522. {
  2523. VectorClear( ent->client->ps.moveDir );
  2524. }
  2525. overridAngles = (PM_LockAngles( ent, ucmd )?qtrue:overridAngles);
  2526. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2527. }
  2528. else if ( ent->client->ps.legsAnim == BOTH_ROLL_STAB )
  2529. {
  2530. if ( ent->NPC )
  2531. {
  2532. VectorClear( ent->client->ps.moveDir );
  2533. }
  2534. overridAngles = (PM_LockAngles( ent, ucmd )?qtrue:overridAngles);
  2535. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2536. if ( ent->client->ps.legsAnimTimer )
  2537. {
  2538. ucmd->upmove = -127;
  2539. }
  2540. if ( ent->client->ps.dualSabers && ent->client->ps.saber[1].Active() )
  2541. {
  2542. G_CamPullBackForLegsAnim( ent );
  2543. }
  2544. }
  2545. else if ( PM_SuperBreakLoseAnim( ent->client->ps.torsoAnim ) )
  2546. {//can't turn during Kyle's grappling
  2547. if ( ent->NPC )
  2548. {
  2549. VectorClear( ent->client->ps.moveDir );
  2550. }
  2551. overridAngles = (PM_LockAngles( ent, ucmd )?qtrue:overridAngles);
  2552. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2553. if ( ent->client->ps.legsAnim == BOTH_LK_DL_ST_T_SB_1_L )
  2554. {
  2555. PM_CmdForRoll( &ent->client->ps, ucmd );
  2556. if ( ent->NPC )
  2557. {//invalid now
  2558. VectorClear( ent->client->ps.moveDir );
  2559. }
  2560. ent->client->ps.speed = 400;
  2561. }
  2562. }
  2563. else if ( ent->client->ps.torsoAnim==BOTH_FORCE_DRAIN_GRAB_START
  2564. || ent->client->ps.torsoAnim==BOTH_FORCE_DRAIN_GRAB_HOLD
  2565. || ent->client->ps.torsoAnim==BOTH_FORCE_DRAIN_GRAB_END
  2566. || ent->client->ps.legsAnim==BOTH_FORCE_DRAIN_GRABBED )
  2567. {//can't turn or move
  2568. if ( ent->s.number < MAX_CLIENTS
  2569. || G_ControlledByPlayer(ent) )
  2570. {//player
  2571. float forceDrainAngle = 90.0f;
  2572. if ( ent->client->ps.torsoAnim == BOTH_FORCE_DRAIN_GRAB_START )
  2573. {//starting drain
  2574. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.torsoAnim );
  2575. float elapsedTime = (float)(animLength-ent->client->ps.legsAnimTimer);
  2576. float angle = (elapsedTime/animLength)*forceDrainAngle;
  2577. cg.overrides.active |= CG_OVERRIDE_3RD_PERSON_ANG;
  2578. cg.overrides.thirdPersonAngle = cg_thirdPersonAngle.value+angle;
  2579. }
  2580. else if ( ent->client->ps.torsoAnim == BOTH_FORCE_DRAIN_GRAB_HOLD )
  2581. {//draining
  2582. cg.overrides.active |= CG_OVERRIDE_3RD_PERSON_ANG;
  2583. cg.overrides.thirdPersonAngle = cg_thirdPersonAngle.value+forceDrainAngle;
  2584. }
  2585. else if ( ent->client->ps.torsoAnim == BOTH_FORCE_DRAIN_GRAB_END )
  2586. {//ending drain
  2587. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.torsoAnim );
  2588. float elapsedTime = (float)(animLength-ent->client->ps.legsAnimTimer);
  2589. float angle = forceDrainAngle-((elapsedTime/animLength)*forceDrainAngle);
  2590. cg.overrides.active |= CG_OVERRIDE_3RD_PERSON_ANG;
  2591. cg.overrides.thirdPersonAngle = cg_thirdPersonAngle.value+angle;
  2592. }
  2593. }
  2594. if ( ent->NPC )
  2595. {
  2596. VectorClear( ent->client->ps.moveDir );
  2597. }
  2598. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2599. overridAngles = PM_LockAngles( ent, ucmd )?qtrue:overridAngles;
  2600. }
  2601. else if ( ent->client->ps.legsAnim==BOTH_PLAYER_PA_1
  2602. || ent->client->ps.legsAnim==BOTH_PLAYER_PA_2
  2603. || ent->client->ps.legsAnim==BOTH_PLAYER_PA_3
  2604. || ent->client->ps.legsAnim==BOTH_PLAYER_PA_3_FLY
  2605. || ent->client->ps.legsAnim==BOTH_KYLE_PA_1
  2606. || ent->client->ps.legsAnim==BOTH_KYLE_PA_2
  2607. || ent->client->ps.legsAnim==BOTH_KYLE_PA_3 )
  2608. {//can't turn during Kyle's grappling
  2609. if ( ent->NPC )
  2610. {
  2611. VectorClear( ent->client->ps.moveDir );
  2612. }
  2613. overridAngles = PM_AdjustAnglesForGrapple( ent, ucmd )?qtrue:overridAngles;
  2614. //if ( g_debugMelee->integer )
  2615. {//actually do some damage during sequence
  2616. int damage = 0;
  2617. int dflags = (DAMAGE_NO_KNOCKBACK|DAMAGE_NO_ARMOR|DAMAGE_NO_KILL);
  2618. if ( TIMER_Done( ent, "grappleDamageDebounce" ) )
  2619. {
  2620. switch ( ent->client->ps.legsAnim )
  2621. {
  2622. case BOTH_PLAYER_PA_1:
  2623. if ( ent->client->ps.legsAnimTimer <= 3150
  2624. && ent->client->ps.legsAnimTimer > 3050 )
  2625. {
  2626. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2627. if ( ent->s.number < MAX_CLIENTS )
  2628. {//special case
  2629. damage = Q_irand( 1, 3 );
  2630. }
  2631. else
  2632. {
  2633. damage = Q_irand( 3, 5 );
  2634. }
  2635. }
  2636. if ( ent->client->ps.legsAnimTimer <= 1150
  2637. && ent->client->ps.legsAnimTimer > 10500 )
  2638. {
  2639. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2640. if ( ent->s.number < MAX_CLIENTS )
  2641. {//special case
  2642. damage = Q_irand( 3, 5 );
  2643. }
  2644. else
  2645. {
  2646. damage = Q_irand( 5, 8 );
  2647. }
  2648. }
  2649. if ( ent->client->ps.legsAnimTimer <= 100 )
  2650. {
  2651. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2652. if ( ent->s.number < MAX_CLIENTS )
  2653. {//special case
  2654. damage = Q_irand( 5, 8 );
  2655. }
  2656. else
  2657. {
  2658. damage = Q_irand( 10, 20 );
  2659. }
  2660. dflags &= ~DAMAGE_NO_KILL;
  2661. }
  2662. break;
  2663. case BOTH_PLAYER_PA_2:
  2664. if ( ent->client->ps.legsAnimTimer <= 5700
  2665. && ent->client->ps.legsAnimTimer > 5600 )
  2666. {
  2667. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2668. if ( ent->s.number < MAX_CLIENTS )
  2669. {//special case
  2670. damage = Q_irand( 3, 6 );
  2671. }
  2672. else
  2673. {
  2674. damage = Q_irand( 7, 10 );
  2675. }
  2676. }
  2677. if ( ent->client->ps.legsAnimTimer <= 5200
  2678. && ent->client->ps.legsAnimTimer > 5100 )
  2679. {
  2680. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2681. if ( ent->s.number < MAX_CLIENTS )
  2682. {//special case
  2683. damage = Q_irand( 1, 3 );
  2684. }
  2685. else
  2686. {
  2687. damage = Q_irand( 3, 5 );
  2688. }
  2689. }
  2690. if ( ent->client->ps.legsAnimTimer <= 4550
  2691. && ent->client->ps.legsAnimTimer > 4450 )
  2692. {
  2693. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2694. if ( ent->s.number < MAX_CLIENTS )
  2695. {//special case
  2696. damage = Q_irand( 3, 6 );
  2697. }
  2698. else
  2699. {
  2700. damage = Q_irand( 10, 15 );
  2701. }
  2702. }
  2703. if ( ent->client->ps.legsAnimTimer <= 3550
  2704. && ent->client->ps.legsAnimTimer > 3450 )
  2705. {
  2706. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2707. if ( ent->s.number < MAX_CLIENTS )
  2708. {//special case
  2709. damage = Q_irand( 3, 6 );
  2710. }
  2711. else
  2712. {
  2713. damage = Q_irand( 10, 20 );
  2714. }
  2715. dflags &= ~DAMAGE_NO_KILL;
  2716. }
  2717. break;
  2718. case BOTH_PLAYER_PA_3:
  2719. if ( ent->client->ps.legsAnimTimer <= 3800
  2720. && ent->client->ps.legsAnimTimer > 3700 )
  2721. {
  2722. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2723. if ( ent->s.number < MAX_CLIENTS )
  2724. {//special case
  2725. damage = Q_irand( 2, 5 );
  2726. }
  2727. else
  2728. {
  2729. damage = Q_irand( 5, 8 );
  2730. }
  2731. }
  2732. if ( ent->client->ps.legsAnimTimer <= 3100
  2733. && ent->client->ps.legsAnimTimer > 3000 )
  2734. {
  2735. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2736. if ( ent->s.number < MAX_CLIENTS )
  2737. {//special case
  2738. damage = Q_irand( 2, 5 );
  2739. }
  2740. else
  2741. {
  2742. damage = Q_irand( 5, 8 );
  2743. }
  2744. }
  2745. if ( ent->client->ps.legsAnimTimer <= 1650
  2746. && ent->client->ps.legsAnimTimer > 1550 )
  2747. {
  2748. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2749. if ( ent->s.number < MAX_CLIENTS )
  2750. {//special case
  2751. damage = Q_irand( 3, 6 );
  2752. }
  2753. else
  2754. {
  2755. damage = Q_irand( 7, 12 );
  2756. }
  2757. }
  2758. break;
  2759. case BOTH_PLAYER_PA_3_FLY:
  2760. /*
  2761. if ( ent->s.number < MAX_CLIENTS )
  2762. {//special case
  2763. if ( ent->client->ps.legsAnimTimer > PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME
  2764. && ent->client->ps.legsAnimTimer <= PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME + 100 )
  2765. {
  2766. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2767. damage = Q_irand( 4, 8 );
  2768. dflags &= ~DAMAGE_NO_KILL;
  2769. }
  2770. }
  2771. else*/ if ( ent->client->ps.legsAnimTimer <= 100 )
  2772. {
  2773. TIMER_Set( ent, "grappleDamageDebounce", 150 );
  2774. damage = Q_irand( 10, 20 );
  2775. dflags &= ~DAMAGE_NO_KILL;
  2776. }
  2777. break;
  2778. }
  2779. if ( damage )
  2780. {
  2781. G_Damage( ent, ent->enemy, ent->enemy, NULL, ent->currentOrigin, damage, dflags, MOD_MELEE );//MOD_IMPACT?
  2782. }
  2783. }
  2784. }
  2785. qboolean clearMove = qtrue;
  2786. int endOfAnimTime = 100;
  2787. if ( ent->s.number < MAX_CLIENTS
  2788. && ent->client->ps.legsAnim == BOTH_PLAYER_PA_3_FLY )
  2789. {//player holds extra long so you have more time to decide to do the quick getup
  2790. //endOfAnimTime += PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME;
  2791. if ( ent->client->ps.legsAnimTimer <= endOfAnimTime )//PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME )
  2792. {
  2793. clearMove = qfalse;
  2794. }
  2795. }
  2796. if ( clearMove )
  2797. {
  2798. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  2799. }
  2800. if ( ent->client->ps.legsAnimTimer <= endOfAnimTime )
  2801. {//pretty much done with the anim, so get up now
  2802. if ( ent->client->ps.legsAnim==BOTH_PLAYER_PA_3 )
  2803. {
  2804. vec3_t ang = {10,ent->currentAngles[YAW],0};
  2805. vec3_t throwDir;
  2806. AngleVectors( ang, throwDir, NULL, NULL );
  2807. if ( !(ent->flags&FL_NO_KNOCKBACK) )
  2808. {
  2809. G_Throw( ent, throwDir, -100 );
  2810. }
  2811. ent->client->ps.legsAnimTimer = ent->client->ps.torsoAnimTimer = 0;
  2812. NPC_SetAnim( ent, SETANIM_BOTH, BOTH_PLAYER_PA_3_FLY, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  2813. ent->client->ps.weaponTime = ent->client->ps.legsAnimTimer;
  2814. /*
  2815. if ( ent->s.number < MAX_CLIENTS )
  2816. {//player holds extra long so you have more time to decide to do the quick getup
  2817. ent->client->ps.legsAnimTimer += PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME;
  2818. ent->client->ps.torsoAnimTimer += PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME;
  2819. }
  2820. */
  2821. //force-thrown - FIXME: start earlier?
  2822. ent->forcePushTime = level.time + 500;
  2823. }
  2824. else if ( ent->client->ps.legsAnim==BOTH_PLAYER_PA_1 )
  2825. {
  2826. vec3_t ang = {10,ent->currentAngles[YAW],0};
  2827. vec3_t throwDir;
  2828. AngleVectors( ang, throwDir, NULL, NULL );
  2829. if ( !(ent->flags&FL_NO_KNOCKBACK) )
  2830. {
  2831. G_Throw( ent, throwDir, -100 );
  2832. }
  2833. ent->client->ps.legsAnimTimer = ent->client->ps.torsoAnimTimer = 0;
  2834. NPC_SetAnim( ent, SETANIM_BOTH, BOTH_KNOCKDOWN2, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  2835. ent->client->ps.weaponTime = ent->client->ps.legsAnimTimer;
  2836. if ( ent->s.number < MAX_CLIENTS )
  2837. {//player holds extra long so you have more time to decide to do the quick getup
  2838. ent->client->ps.legsAnimTimer += PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME;
  2839. ent->client->ps.torsoAnimTimer += PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME;
  2840. }
  2841. }
  2842. //FIXME: should end so you can do a getup
  2843. /*
  2844. else if ( ent->client->ps.legsAnim==BOTH_PLAYER_PA_2 )
  2845. {
  2846. ent->client->ps.legsAnimTimer = ent->client->ps.torsoAnimTimer = 0;
  2847. NPC_SetAnim( ent, SETANIM_BOTH, BOTH_GETUP1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  2848. ent->client->ps.weaponTime = ent->client->ps.legsAnimTimer;
  2849. }
  2850. */
  2851. }
  2852. if ( d_slowmodeath->integer <= 3
  2853. && ent->s.number < MAX_CLIENTS )
  2854. {//no matrix effect, so slide the camera back and to the side
  2855. G_CamPullBackForLegsAnim( ent );
  2856. G_CamCircleForLegsAnim( ent );
  2857. }
  2858. }
  2859. else if ( ent->client->ps.legsAnim == BOTH_FORCELONGLEAP_START
  2860. || ent->client->ps.legsAnim == BOTH_FORCELONGLEAP_ATTACK
  2861. || ent->client->ps.legsAnim == BOTH_FORCELONGLEAP_LAND )
  2862. {//can't turn during force leap
  2863. if ( ent->NPC )
  2864. {
  2865. VectorClear( ent->client->ps.moveDir );
  2866. }
  2867. overridAngles = PM_AdjustAnglesForLongJump( ent, ucmd )?qtrue:overridAngles;
  2868. }
  2869. else if ( PM_KickingAnim( ent->client->ps.legsAnim )
  2870. || ent->client->ps.legsAnim == BOTH_ARIAL_F1
  2871. || ent->client->ps.legsAnim == BOTH_ARIAL_LEFT
  2872. || ent->client->ps.legsAnim == BOTH_ARIAL_RIGHT
  2873. || ent->client->ps.legsAnim == BOTH_CARTWHEEL_LEFT
  2874. || ent->client->ps.legsAnim == BOTH_CARTWHEEL_RIGHT
  2875. || ent->client->ps.legsAnim == BOTH_JUMPATTACK7
  2876. || ent->client->ps.legsAnim == BOTH_BUTTERFLY_FL1
  2877. || ent->client->ps.legsAnim == BOTH_BUTTERFLY_FR1
  2878. || ent->client->ps.legsAnim == BOTH_BUTTERFLY_RIGHT
  2879. || ent->client->ps.legsAnim == BOTH_BUTTERFLY_LEFT
  2880. || ent->client->ps.legsAnim == BOTH_A7_SOULCAL )
  2881. {//can't move, check for damage frame
  2882. if ( PM_KickingAnim( ent->client->ps.legsAnim ) )
  2883. {
  2884. ucmd->forwardmove = ucmd->rightmove = 0;
  2885. if ( ent->NPC )
  2886. {
  2887. VectorClear( ent->client->ps.moveDir );
  2888. }
  2889. }
  2890. vec3_t kickDir={0,0,0}, kickDir2={0,0,0}, kickEnd={0,0,0}, kickEnd2={0,0,0}, fwdAngs = {0,ent->client->ps.viewangles[YAW],0};
  2891. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.legsAnim );
  2892. float elapsedTime = (float)(animLength-ent->client->ps.legsAnimTimer);
  2893. float remainingTime = (animLength-elapsedTime);
  2894. float kickDist = (ent->maxs[0]*1.5f)+STAFF_KICK_RANGE+8.0f;//fudge factor of 8
  2895. float kickDist2 = kickDist;
  2896. int kickDamage = Q_irand( 3, 8 );
  2897. int kickDamage2 = Q_irand( 3, 8 );
  2898. int kickPush = Q_flrand( 100.0f, 200.0f );//Q_flrand( 50.0f, 100.0f );
  2899. int kickPush2 = Q_flrand( 100.0f, 200.0f );//Q_flrand( 50.0f, 100.0f );
  2900. qboolean doKick = qfalse;
  2901. qboolean doKick2 = qfalse;
  2902. qboolean kickSoundOnWalls = qfalse;
  2903. //HMM... or maybe trace from origin to footRBolt/footLBolt? Which one? G2 trace? Will do hitLoc, if so...
  2904. if ( ent->client->ps.torsoAnim == BOTH_A7_HILT )
  2905. {
  2906. if ( elapsedTime >= 250 && remainingTime >= 250 )
  2907. {//front
  2908. doKick = qtrue;
  2909. if ( ent->handRBolt != -1 )
  2910. {//actually trace to a bolt
  2911. G_GetBoltPosition( ent, ent->handRBolt, kickEnd );
  2912. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  2913. kickDir[2] = 0;//ah, flatten it, I guess...
  2914. VectorNormalize( kickDir );
  2915. }
  2916. else
  2917. {//guess
  2918. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  2919. }
  2920. }
  2921. }
  2922. else
  2923. {
  2924. switch ( ent->client->ps.legsAnim )
  2925. {
  2926. case BOTH_A7_SOULCAL:
  2927. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  2928. if ( elapsedTime >= 1400 && elapsedTime <= 1500 )
  2929. {//right leg
  2930. doKick = qtrue;
  2931. if ( ent->footRBolt != -1 )
  2932. {//actually trace to a bolt
  2933. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  2934. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  2935. kickDir[2] = 0;//ah, flatten it, I guess...
  2936. VectorNormalize( kickDir );
  2937. }
  2938. else
  2939. {//guess
  2940. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  2941. }
  2942. }
  2943. break;
  2944. case BOTH_ARIAL_F1:
  2945. if ( elapsedTime >= 550 && elapsedTime <= 1000 )
  2946. {//right leg
  2947. doKick = qtrue;
  2948. if ( ent->footRBolt != -1 )
  2949. {//actually trace to a bolt
  2950. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  2951. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  2952. kickDir[2] = 0;//ah, flatten it, I guess...
  2953. VectorNormalize( kickDir );
  2954. }
  2955. else
  2956. {//guess
  2957. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  2958. }
  2959. }
  2960. if ( elapsedTime >= 800 && elapsedTime <= 1200 )
  2961. {//left leg
  2962. doKick2 = qtrue;
  2963. if ( ent->footLBolt != -1 )
  2964. {//actually trace to a bolt
  2965. G_GetBoltPosition( ent, ent->footLBolt, kickEnd2 );
  2966. VectorSubtract( kickEnd2, ent->currentOrigin, kickDir2 );
  2967. kickDir2[2] = 0;//ah, flatten it, I guess...
  2968. VectorNormalize( kickDir2 );
  2969. }
  2970. else
  2971. {//guess
  2972. AngleVectors( fwdAngs, kickDir2, NULL, NULL );
  2973. }
  2974. }
  2975. break;
  2976. case BOTH_ARIAL_LEFT:
  2977. case BOTH_ARIAL_RIGHT:
  2978. if ( elapsedTime >= 200 && elapsedTime <= 600 )
  2979. {//lead leg
  2980. int footBolt = (ent->client->ps.legsAnim==BOTH_ARIAL_LEFT)?ent->footRBolt:ent->footLBolt;//mirrored anims
  2981. doKick = qtrue;
  2982. if ( footBolt != -1 )
  2983. {//actually trace to a bolt
  2984. G_GetBoltPosition( ent, footBolt, kickEnd );
  2985. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  2986. kickDir[2] = 0;//ah, flatten it, I guess...
  2987. VectorNormalize( kickDir );
  2988. }
  2989. else
  2990. {//guess
  2991. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  2992. }
  2993. }
  2994. if ( elapsedTime >= 400 && elapsedTime <= 850 )
  2995. {//trailing leg
  2996. int footBolt = (ent->client->ps.legsAnim==BOTH_ARIAL_LEFT)?ent->footLBolt:ent->footRBolt;//mirrored anims
  2997. doKick2 = qtrue;
  2998. if ( footBolt != -1 )
  2999. {//actually trace to a bolt
  3000. G_GetBoltPosition( ent, footBolt, kickEnd2 );
  3001. VectorSubtract( kickEnd2, ent->currentOrigin, kickDir2 );
  3002. kickDir2[2] = 0;//ah, flatten it, I guess...
  3003. VectorNormalize( kickDir2 );
  3004. }
  3005. else
  3006. {//guess
  3007. AngleVectors( fwdAngs, kickDir2, NULL, NULL );
  3008. }
  3009. }
  3010. break;
  3011. case BOTH_CARTWHEEL_LEFT:
  3012. case BOTH_CARTWHEEL_RIGHT:
  3013. if ( elapsedTime >= 200 && elapsedTime <= 600 )
  3014. {//lead leg
  3015. int footBolt = (ent->client->ps.legsAnim==BOTH_CARTWHEEL_LEFT)?ent->footRBolt:ent->footLBolt;//mirrored anims
  3016. doKick = qtrue;
  3017. if ( footBolt != -1 )
  3018. {//actually trace to a bolt
  3019. G_GetBoltPosition( ent, footBolt, kickEnd );
  3020. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3021. kickDir[2] = 0;//ah, flatten it, I guess...
  3022. VectorNormalize( kickDir );
  3023. }
  3024. else
  3025. {//guess
  3026. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3027. }
  3028. }
  3029. if ( elapsedTime >= 350 && elapsedTime <= 650 )
  3030. {//trailing leg
  3031. int footBolt = (ent->client->ps.legsAnim==BOTH_CARTWHEEL_LEFT)?ent->footLBolt:ent->footRBolt;//mirrored anims
  3032. doKick2 = qtrue;
  3033. if ( footBolt != -1 )
  3034. {//actually trace to a bolt
  3035. G_GetBoltPosition( ent, footBolt, kickEnd2 );
  3036. VectorSubtract( kickEnd2, ent->currentOrigin, kickDir2 );
  3037. kickDir2[2] = 0;//ah, flatten it, I guess...
  3038. VectorNormalize( kickDir2 );
  3039. }
  3040. else
  3041. {//guess
  3042. AngleVectors( fwdAngs, kickDir2, NULL, NULL );
  3043. }
  3044. }
  3045. break;
  3046. case BOTH_JUMPATTACK7:
  3047. if ( elapsedTime >= 300 && elapsedTime <= 900 )
  3048. {//right knee
  3049. doKick = qtrue;
  3050. if ( ent->kneeRBolt != -1 )
  3051. {//actually trace to a bolt
  3052. G_GetBoltPosition( ent, ent->kneeRBolt, kickEnd );
  3053. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3054. kickDir[2] = 0;//ah, flatten it, I guess...
  3055. VectorNormalize( kickDir );
  3056. }
  3057. else
  3058. {//guess
  3059. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3060. }
  3061. }
  3062. if ( elapsedTime >= 600 && elapsedTime <= 900 )
  3063. {//left leg
  3064. doKick2 = qtrue;
  3065. if ( ent->footLBolt != -1 )
  3066. {//actually trace to a bolt
  3067. G_GetBoltPosition( ent, ent->footLBolt, kickEnd2 );
  3068. VectorSubtract( kickEnd2, ent->currentOrigin, kickDir2 );
  3069. kickDir2[2] = 0;//ah, flatten it, I guess...
  3070. VectorNormalize( kickDir2 );
  3071. }
  3072. else
  3073. {//guess
  3074. AngleVectors( fwdAngs, kickDir2, NULL, NULL );
  3075. }
  3076. }
  3077. break;
  3078. case BOTH_BUTTERFLY_FL1:
  3079. case BOTH_BUTTERFLY_FR1:
  3080. if ( elapsedTime >= 950 && elapsedTime <= 1300 )
  3081. {//lead leg
  3082. int footBolt = (ent->client->ps.legsAnim==BOTH_BUTTERFLY_FL1)?ent->footRBolt:ent->footLBolt;//mirrored anims
  3083. doKick = qtrue;
  3084. if ( footBolt != -1 )
  3085. {//actually trace to a bolt
  3086. G_GetBoltPosition( ent, footBolt, kickEnd );
  3087. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3088. kickDir[2] = 0;//ah, flatten it, I guess...
  3089. VectorNormalize( kickDir );
  3090. }
  3091. else
  3092. {//guess
  3093. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3094. }
  3095. }
  3096. if ( elapsedTime >= 1150 && elapsedTime <= 1600 )
  3097. {//trailing leg
  3098. int footBolt = (ent->client->ps.legsAnim==BOTH_BUTTERFLY_FL1)?ent->footLBolt:ent->footRBolt;//mirrored anims
  3099. doKick2 = qtrue;
  3100. if ( footBolt != -1 )
  3101. {//actually trace to a bolt
  3102. G_GetBoltPosition( ent, footBolt, kickEnd2 );
  3103. VectorSubtract( kickEnd2, ent->currentOrigin, kickDir2 );
  3104. kickDir2[2] = 0;//ah, flatten it, I guess...
  3105. VectorNormalize( kickDir2 );
  3106. }
  3107. else
  3108. {//guess
  3109. AngleVectors( fwdAngs, kickDir2, NULL, NULL );
  3110. }
  3111. }
  3112. break;
  3113. case BOTH_BUTTERFLY_LEFT:
  3114. case BOTH_BUTTERFLY_RIGHT:
  3115. if ( (elapsedTime >= 100 && elapsedTime <= 450)
  3116. || (elapsedTime >= 1100 && elapsedTime <= 1350) )
  3117. {//lead leg
  3118. int footBolt = (ent->client->ps.legsAnim==BOTH_BUTTERFLY_LEFT)?ent->footLBolt:ent->footRBolt;//mirrored anims
  3119. doKick = qtrue;
  3120. if ( footBolt != -1 )
  3121. {//actually trace to a bolt
  3122. G_GetBoltPosition( ent, footBolt, kickEnd );
  3123. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3124. kickDir[2] = 0;//ah, flatten it, I guess...
  3125. VectorNormalize( kickDir );
  3126. }
  3127. else
  3128. {//guess
  3129. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3130. }
  3131. }
  3132. if ( elapsedTime >= 900 && elapsedTime <= 1600 )
  3133. {//trailing leg
  3134. int footBolt = (ent->client->ps.legsAnim==BOTH_BUTTERFLY_LEFT)?ent->footRBolt:ent->footLBolt;//mirrored anims
  3135. doKick2 = qtrue;
  3136. if ( footBolt != -1 )
  3137. {//actually trace to a bolt
  3138. G_GetBoltPosition( ent, footBolt, kickEnd2 );
  3139. VectorSubtract( kickEnd2, ent->currentOrigin, kickDir2 );
  3140. kickDir2[2] = 0;//ah, flatten it, I guess...
  3141. VectorNormalize( kickDir2 );
  3142. }
  3143. else
  3144. {//guess
  3145. AngleVectors( fwdAngs, kickDir2, NULL, NULL );
  3146. }
  3147. }
  3148. break;
  3149. case BOTH_GETUP_BROLL_B:
  3150. case BOTH_GETUP_BROLL_F:
  3151. case BOTH_GETUP_FROLL_B:
  3152. case BOTH_GETUP_FROLL_F:
  3153. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  3154. if ( elapsedTime >= 250 && remainingTime >= 250 )
  3155. {//front
  3156. doKick = qtrue;
  3157. if ( ent->footRBolt != -1 )
  3158. {//actually trace to a bolt
  3159. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3160. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3161. kickDir[2] = 0;//ah, flatten it, I guess...
  3162. VectorNormalize( kickDir );
  3163. }
  3164. else
  3165. {//guess
  3166. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3167. }
  3168. }
  3169. if ( ent->client->ps.legsAnim == BOTH_GETUP_BROLL_B
  3170. || ent->client->ps.legsAnim == BOTH_GETUP_FROLL_B )
  3171. {//rolling back, pull back the view
  3172. G_CamPullBackForLegsAnim( ent );
  3173. }
  3174. break;
  3175. case BOTH_A7_KICK_F_AIR:
  3176. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  3177. kickSoundOnWalls = qtrue;
  3178. if ( elapsedTime >= 100 && remainingTime >= 500 )
  3179. {//front
  3180. doKick = qtrue;
  3181. if ( ent->footRBolt != -1 )
  3182. {//actually trace to a bolt
  3183. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3184. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3185. kickDir[2] = 0;//ah, flatten it, I guess...
  3186. VectorNormalize( kickDir );
  3187. }
  3188. else
  3189. {//guess
  3190. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3191. }
  3192. }
  3193. break;
  3194. case BOTH_A7_KICK_F:
  3195. kickSoundOnWalls = qtrue;
  3196. //FIXME: push forward?
  3197. if ( elapsedTime >= 250 && remainingTime >= 250 )
  3198. {//front
  3199. doKick = qtrue;
  3200. if ( ent->footRBolt != -1 )
  3201. {//actually trace to a bolt
  3202. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3203. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3204. kickDir[2] = 0;//ah, flatten it, I guess...
  3205. VectorNormalize( kickDir );
  3206. }
  3207. else
  3208. {//guess
  3209. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3210. }
  3211. }
  3212. break;
  3213. case BOTH_A7_KICK_B_AIR:
  3214. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  3215. kickSoundOnWalls = qtrue;
  3216. if ( elapsedTime >= 100 && remainingTime >= 400 )
  3217. {//back
  3218. doKick = qtrue;
  3219. if ( ent->footRBolt != -1 )
  3220. {//actually trace to a bolt
  3221. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3222. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3223. kickDir[2] = 0;//ah, flatten it, I guess...
  3224. VectorNormalize( kickDir );
  3225. }
  3226. else
  3227. {//guess
  3228. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3229. VectorScale( kickDir, -1, kickDir );
  3230. }
  3231. }
  3232. break;
  3233. case BOTH_A7_KICK_B:
  3234. kickSoundOnWalls = qtrue;
  3235. if ( elapsedTime >= 250 && remainingTime >= 250 )
  3236. {//back
  3237. doKick = qtrue;
  3238. if ( ent->footRBolt != -1 )
  3239. {//actually trace to a bolt
  3240. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3241. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3242. kickDir[2] = 0;//ah, flatten it, I guess...
  3243. VectorNormalize( kickDir );
  3244. }
  3245. else
  3246. {//guess
  3247. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3248. VectorScale( kickDir, -1, kickDir );
  3249. }
  3250. }
  3251. break;
  3252. case BOTH_A7_KICK_R_AIR:
  3253. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  3254. kickSoundOnWalls = qtrue;
  3255. if ( elapsedTime >= 150 && remainingTime >= 300 )
  3256. {//left
  3257. doKick = qtrue;
  3258. if ( ent->footLBolt != -1 )
  3259. {//actually trace to a bolt
  3260. G_GetBoltPosition( ent, ent->footLBolt, kickEnd );
  3261. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3262. kickDir[2] = 0;//ah, flatten it, I guess...
  3263. VectorNormalize( kickDir );
  3264. }
  3265. else
  3266. {//guess
  3267. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3268. VectorScale( kickDir, -1, kickDir );
  3269. }
  3270. }
  3271. break;
  3272. case BOTH_A7_KICK_R:
  3273. kickSoundOnWalls = qtrue;
  3274. //FIXME: push right?
  3275. if ( elapsedTime >= 250 && remainingTime >= 250 )
  3276. {//right
  3277. doKick = qtrue;
  3278. if ( ent->footRBolt != -1 )
  3279. {//actually trace to a bolt
  3280. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3281. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3282. kickDir[2] = 0;//ah, flatten it, I guess...
  3283. VectorNormalize( kickDir );
  3284. }
  3285. else
  3286. {//guess
  3287. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3288. }
  3289. }
  3290. break;
  3291. case BOTH_A7_KICK_L_AIR:
  3292. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  3293. kickSoundOnWalls = qtrue;
  3294. if ( elapsedTime >= 150 && remainingTime >= 300 )
  3295. {//left
  3296. doKick = qtrue;
  3297. if ( ent->footLBolt != -1 )
  3298. {//actually trace to a bolt
  3299. G_GetBoltPosition( ent, ent->footLBolt, kickEnd );
  3300. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3301. kickDir[2] = 0;//ah, flatten it, I guess...
  3302. VectorNormalize( kickDir );
  3303. }
  3304. else
  3305. {//guess
  3306. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3307. VectorScale( kickDir, -1, kickDir );
  3308. }
  3309. }
  3310. break;
  3311. case BOTH_A7_KICK_L:
  3312. kickSoundOnWalls = qtrue;
  3313. //FIXME: push left?
  3314. if ( elapsedTime >= 250 && remainingTime >= 250 )
  3315. {//left
  3316. doKick = qtrue;
  3317. if ( ent->footLBolt != -1 )
  3318. {//actually trace to a bolt
  3319. G_GetBoltPosition( ent, ent->footLBolt, kickEnd );
  3320. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3321. kickDir[2] = 0;//ah, flatten it, I guess...
  3322. VectorNormalize( kickDir );
  3323. }
  3324. else
  3325. {//guess
  3326. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3327. VectorScale( kickDir, -1, kickDir );
  3328. }
  3329. }
  3330. break;
  3331. case BOTH_A7_KICK_S:
  3332. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  3333. if ( ent->footRBolt != -1 )
  3334. {//actually trace to a bolt
  3335. if ( elapsedTime >= 550
  3336. && elapsedTime <= 1050 )
  3337. {
  3338. doKick = qtrue;
  3339. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3340. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3341. kickDir[2] = 0;//ah, flatten it, I guess...
  3342. VectorNormalize( kickDir );
  3343. //NOTE: have to fudge this a little because it's not getting enough range with the anim as-is
  3344. VectorMA( kickEnd, 8.0f, kickDir, kickEnd );
  3345. }
  3346. }
  3347. else
  3348. {//guess
  3349. if ( elapsedTime >= 400 && elapsedTime < 500 )
  3350. {//front
  3351. doKick = qtrue;
  3352. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3353. }
  3354. else if ( elapsedTime >= 500 && elapsedTime < 600 )
  3355. {//front-right?
  3356. doKick = qtrue;
  3357. fwdAngs[YAW] += 45;
  3358. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3359. }
  3360. else if ( elapsedTime >= 600 && elapsedTime < 700 )
  3361. {//right
  3362. doKick = qtrue;
  3363. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3364. }
  3365. else if ( elapsedTime >= 700 && elapsedTime < 800 )
  3366. {//back-right?
  3367. doKick = qtrue;
  3368. fwdAngs[YAW] += 45;
  3369. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3370. }
  3371. else if ( elapsedTime >= 800 && elapsedTime < 900 )
  3372. {//back
  3373. doKick = qtrue;
  3374. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3375. VectorScale( kickDir, -1, kickDir );
  3376. }
  3377. else if ( elapsedTime >= 900 && elapsedTime < 1000 )
  3378. {//back-left?
  3379. doKick = qtrue;
  3380. fwdAngs[YAW] += 45;
  3381. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3382. }
  3383. else if ( elapsedTime >= 1000 && elapsedTime < 1100 )
  3384. {//left
  3385. doKick = qtrue;
  3386. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3387. VectorScale( kickDir, -1, kickDir );
  3388. }
  3389. else if ( elapsedTime >= 1100 && elapsedTime < 1200 )
  3390. {//front-left?
  3391. doKick = qtrue;
  3392. fwdAngs[YAW] += 45;
  3393. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3394. VectorScale( kickDir, -1, kickDir );
  3395. }
  3396. }
  3397. break;
  3398. case BOTH_A7_KICK_BF:
  3399. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  3400. if ( elapsedTime < 1500 )
  3401. {//auto-aim!
  3402. overridAngles = PM_AdjustAnglesForBFKick( ent, ucmd, fwdAngs, qboolean(elapsedTime<850) )?qtrue:overridAngles;
  3403. //FIXME: if we haven't done the back kick yet and there's no-one there to
  3404. // kick anymore, go into some anim that returns us to our base stance
  3405. }
  3406. if ( ent->footRBolt != -1 )
  3407. {//actually trace to a bolt
  3408. if ( ( elapsedTime >= 750 && elapsedTime < 850 )
  3409. || ( elapsedTime >= 1400 && elapsedTime < 1500 ) )
  3410. {//right, though either would do
  3411. doKick = qtrue;
  3412. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3413. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3414. kickDir[2] = 0;//ah, flatten it, I guess...
  3415. VectorNormalize( kickDir );
  3416. //NOTE: have to fudge this a little because it's not getting enough range with the anim as-is
  3417. VectorMA( kickEnd, 8, kickDir, kickEnd );
  3418. }
  3419. }
  3420. else
  3421. {//guess
  3422. if ( elapsedTime >= 250 && elapsedTime < 350 )
  3423. {//front
  3424. doKick = qtrue;
  3425. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3426. }
  3427. else if ( elapsedTime >= 350 && elapsedTime < 450 )
  3428. {//back
  3429. doKick = qtrue;
  3430. AngleVectors( fwdAngs, kickDir, NULL, NULL );
  3431. VectorScale( kickDir, -1, kickDir );
  3432. }
  3433. }
  3434. break;
  3435. case BOTH_A7_KICK_RL:
  3436. kickSoundOnWalls = qtrue;
  3437. kickPush = Q_flrand( 150.0f, 250.0f );//Q_flrand( 75.0f, 125.0f );
  3438. //FIXME: auto aim at enemies on the side of us?
  3439. //overridAngles = PM_AdjustAnglesForRLKick( ent, ucmd, fwdAngs, qboolean(elapsedTime<850) )?qtrue:overridAngles;
  3440. if ( elapsedTime >= 250 && elapsedTime < 350 )
  3441. {//right
  3442. doKick = qtrue;
  3443. if ( ent->footRBolt != -1 )
  3444. {//actually trace to a bolt
  3445. G_GetBoltPosition( ent, ent->footRBolt, kickEnd );
  3446. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3447. kickDir[2] = 0;//ah, flatten it, I guess...
  3448. VectorNormalize( kickDir );
  3449. //NOTE: have to fudge this a little because it's not getting enough range with the anim as-is
  3450. VectorMA( kickEnd, 8, kickDir, kickEnd );
  3451. }
  3452. else
  3453. {//guess
  3454. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3455. }
  3456. }
  3457. else if ( elapsedTime >= 350 && elapsedTime < 450 )
  3458. {//left
  3459. doKick = qtrue;
  3460. if ( ent->footLBolt != -1 )
  3461. {//actually trace to a bolt
  3462. G_GetBoltPosition( ent, ent->footLBolt, kickEnd );
  3463. VectorSubtract( kickEnd, ent->currentOrigin, kickDir );
  3464. kickDir[2] = 0;//ah, flatten it, I guess...
  3465. VectorNormalize( kickDir );
  3466. //NOTE: have to fudge this a little because it's not getting enough range with the anim as-is
  3467. VectorMA( kickEnd, 8, kickDir, kickEnd );
  3468. }
  3469. else
  3470. {//guess
  3471. AngleVectors( fwdAngs, NULL, kickDir, NULL );
  3472. VectorScale( kickDir, -1, kickDir );
  3473. }
  3474. }
  3475. break;
  3476. }
  3477. }
  3478. if ( doKick )
  3479. {
  3480. G_KickTrace( ent, kickDir, kickDist, kickEnd, kickDamage, kickPush, kickSoundOnWalls );
  3481. }
  3482. if ( doKick2 )
  3483. {
  3484. G_KickTrace( ent, kickDir2, kickDist2, kickEnd2, kickDamage2, kickPush2, kickSoundOnWalls );
  3485. }
  3486. }
  3487. else if ( ent->client->ps.saberMove == LS_DUAL_FB )
  3488. {
  3489. //pull back the view
  3490. G_CamPullBackForLegsAnim( ent );
  3491. }
  3492. else if ( ent->client->ps.saberMove == LS_A_BACK || ent->client->ps.saberMove == LS_A_BACK_CR
  3493. || ent->client->ps.saberMove == LS_A_BACKSTAB )
  3494. {//can't move or turn during back attacks
  3495. ucmd->forwardmove = ucmd->rightmove = 0;
  3496. if ( ent->NPC )
  3497. {
  3498. VectorClear( ent->client->ps.moveDir );
  3499. }
  3500. if ( (overridAngles = (PM_AdjustAnglesForBackAttack( ent, ucmd )?qtrue:overridAngles)) == qtrue )
  3501. {
  3502. //pull back the view
  3503. G_CamPullBackForLegsAnim( ent );
  3504. }
  3505. }
  3506. else if ( ent->client->ps.torsoAnim == BOTH_WALL_FLIP_BACK1
  3507. || ent->client->ps.torsoAnim == BOTH_WALL_FLIP_BACK2
  3508. || ent->client->ps.legsAnim == BOTH_FORCEWALLRUNFLIP_END
  3509. || ent->client->ps.legsAnim == BOTH_FORCEWALLREBOUND_BACK )
  3510. {
  3511. //pull back the view
  3512. G_CamPullBackForLegsAnim( ent );
  3513. }
  3514. else if ( ent->client->ps.torsoAnim == BOTH_A6_SABERPROTECT )
  3515. {
  3516. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  3517. if ( ent->NPC )
  3518. {
  3519. VectorClear( ent->client->ps.moveDir );
  3520. ent->client->ps.forceJumpCharge = 0;
  3521. }
  3522. if ( !ent->s.number )
  3523. {
  3524. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.torsoAnim );
  3525. float elapsedTime = (float)(animLength-ent->client->ps.torsoAnimTimer);
  3526. float backDist = 0;
  3527. if ( elapsedTime <= 300.0f )
  3528. {//starting anim
  3529. backDist = (elapsedTime/300.0f)*90.0f;
  3530. }
  3531. else if ( ent->client->ps.torsoAnimTimer <= 300.0f )
  3532. {//ending anim
  3533. backDist = (ent->client->ps.torsoAnimTimer/300.0f)*90.0f;
  3534. }
  3535. else
  3536. {//in middle of anim
  3537. backDist = 90.0f;
  3538. }
  3539. //back off and look down
  3540. cg.overrides.active |= (CG_OVERRIDE_3RD_PERSON_RNG|CG_OVERRIDE_3RD_PERSON_POF);
  3541. cg.overrides.thirdPersonRange = cg_thirdPersonRange.value+backDist;
  3542. cg.overrides.thirdPersonPitchOffset = cg_thirdPersonPitchOffset.value+(backDist/2.0f);
  3543. }
  3544. overridAngles = (PM_AdjustAnglesForSpinProtect( ent, ucmd )?qtrue:overridAngles);
  3545. }
  3546. else if ( ent->client->ps.legsAnim == BOTH_A3_SPECIAL )
  3547. {//push forward
  3548. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.torsoAnim );
  3549. float elapsedTime = (float)(animLength-ent->client->ps.torsoAnimTimer);
  3550. ucmd->upmove = ucmd->rightmove = 0;
  3551. ucmd->forwardmove = 0;
  3552. if ( elapsedTime >= 350 && elapsedTime < 1500 )
  3553. {//push forward
  3554. ucmd->forwardmove = 64;
  3555. ent->client->ps.speed = 200.0f;
  3556. }
  3557. //FIXME: pull back camera?
  3558. }
  3559. else if ( ent->client->ps.legsAnim == BOTH_A2_SPECIAL )
  3560. {//push forward
  3561. ucmd->upmove = ucmd->rightmove = 0;
  3562. ucmd->forwardmove = 0;
  3563. if ( ent->client->ps.legsAnimTimer > 200.0f )
  3564. {
  3565. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.torsoAnim );
  3566. float elapsedTime = (float)(animLength-ent->client->ps.torsoAnimTimer);
  3567. if ( elapsedTime < 750
  3568. || (elapsedTime >= 1650 && elapsedTime < 2400) )
  3569. {//push forward
  3570. ucmd->forwardmove = 64;
  3571. ent->client->ps.speed = 200.0f;
  3572. }
  3573. }
  3574. //FIXME: pull back camera?
  3575. }//FIXME: fast special?
  3576. else if ( ent->client->ps.legsAnim == BOTH_A1_SPECIAL
  3577. && (ucmd->forwardmove || ucmd->rightmove || (VectorCompare( ent->client->ps.moveDir, vec3_origin )&&ent->client->ps.speed>0)) )
  3578. {//moving during full-body fast special
  3579. ent->client->ps.legsAnimTimer = 0;//don't hold this legsAnim, allow them to run
  3580. //FIXME: just add this to the list of overridable special moves in PM_Footsteps?
  3581. }
  3582. else if ( ent->client->ps.legsAnim == BOTH_FLIP_LAND )
  3583. {//moving during full-body fast special
  3584. float animLength = PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)ent->client->ps.torsoAnim );
  3585. float elapsedTime = (float)(animLength-ent->client->ps.torsoAnimTimer);
  3586. ucmd->upmove = ucmd->rightmove = ucmd->forwardmove = 0;
  3587. if ( elapsedTime > 600 && elapsedTime < 800
  3588. && ent->client->ps.groundEntityNum != ENTITYNUM_NONE )
  3589. {//jump - FIXME: how do we stop double-jumps?
  3590. ent->client->ps.pm_flags |= PMF_JUMP_HELD;
  3591. ent->client->ps.groundEntityNum = ENTITYNUM_NONE;
  3592. ent->client->ps.jumpZStart = ent->currentOrigin[2];
  3593. ent->client->ps.velocity[2] = JUMP_VELOCITY;
  3594. G_AddEvent( ent, EV_JUMP, 0 );
  3595. }
  3596. }
  3597. else if ( ( PM_SuperBreakWinAnim( ent->client->ps.torsoAnim )
  3598. || PM_SuperBreakLoseAnim( ent->client->ps.torsoAnim ) )
  3599. && ent->client->ps.torsoAnimTimer )
  3600. {//can't move or turn
  3601. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  3602. if ( ent->NPC )
  3603. {
  3604. VectorClear( ent->client->ps.moveDir );
  3605. ent->client->ps.forceJumpCharge = 0;
  3606. }
  3607. overridAngles = (PM_LockAngles( ent, ucmd )?qtrue:overridAngles);
  3608. }
  3609. else if ( BG_FullBodyTauntAnim( ent->client->ps.legsAnim )
  3610. && BG_FullBodyTauntAnim( ent->client->ps.torsoAnim ) )
  3611. {
  3612. if ( (ucmd->buttons&BUTTON_ATTACK)
  3613. || (ucmd->buttons&BUTTON_ALT_ATTACK)
  3614. || (ucmd->buttons&BUTTON_USE_FORCE)
  3615. || (ucmd->buttons&BUTTON_FORCEGRIP)
  3616. || (ucmd->buttons&BUTTON_FORCE_LIGHTNING)
  3617. || (ucmd->buttons&BUTTON_FORCE_DRAIN)
  3618. || ucmd->upmove )
  3619. {//stop the anim
  3620. if ( ent->client->ps.legsAnim == BOTH_MEDITATE
  3621. && ent->client->ps.torsoAnim == BOTH_MEDITATE )
  3622. {
  3623. NPC_SetAnim( ent, SETANIM_BOTH, BOTH_MEDITATE_END, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD, 0 );
  3624. }
  3625. else
  3626. {
  3627. ent->client->ps.legsAnimTimer = ent->client->ps.torsoAnimTimer = 0;
  3628. }
  3629. }
  3630. else
  3631. {
  3632. if ( ent->client->ps.legsAnim == BOTH_MEDITATE )
  3633. {
  3634. if ( ent->client->ps.legsAnimTimer < 100 )
  3635. {
  3636. ent->client->ps.legsAnimTimer = 100;
  3637. }
  3638. }
  3639. if ( ent->client->ps.torsoAnim == BOTH_MEDITATE )
  3640. {
  3641. if ( ent->client->ps.torsoAnimTimer < 100 )
  3642. {
  3643. ent->client->ps.legsAnimTimer = 100;
  3644. }
  3645. }
  3646. if ( ent->client->ps.legsAnimTimer > 0 || ent->client->ps.torsoAnimTimer > 0 )
  3647. {
  3648. ucmd->rightmove = 0;
  3649. ucmd->upmove = 0;
  3650. ucmd->forwardmove = 0;
  3651. ucmd->buttons = 0;
  3652. if ( ent->NPC )
  3653. {
  3654. VectorClear( ent->client->ps.moveDir );
  3655. ent->client->ps.forceJumpCharge = 0;
  3656. }
  3657. overridAngles = (PM_LockAngles( ent, ucmd )?qtrue:overridAngles);
  3658. }
  3659. }
  3660. }
  3661. else if ( ent->client->ps.legsAnim == BOTH_MEDITATE_END
  3662. && ent->client->ps.legsAnimTimer > 0 )
  3663. {
  3664. ucmd->rightmove = 0;
  3665. ucmd->upmove = 0;
  3666. ucmd->forwardmove = 0;
  3667. ucmd->buttons = 0;
  3668. if ( ent->NPC )
  3669. {
  3670. VectorClear( ent->client->ps.moveDir );
  3671. ent->client->ps.forceJumpCharge = 0;
  3672. }
  3673. overridAngles = (PM_LockAngles( ent, ucmd )?qtrue:overridAngles);
  3674. }
  3675. else if ( !ent->s.number )
  3676. {
  3677. if ( ent->client->NPC_class != CLASS_ATST )
  3678. {
  3679. // Not in a vehicle.
  3680. if ( ent->s.m_iVehicleNum == 0 )
  3681. {
  3682. if ( !MatrixMode )
  3683. {
  3684. cg.overrides.active &= ~(CG_OVERRIDE_3RD_PERSON_RNG|CG_OVERRIDE_3RD_PERSON_POF|CG_OVERRIDE_3RD_PERSON_ANG);
  3685. cg.overrides.thirdPersonRange = 0;
  3686. }
  3687. }
  3688. }
  3689. }
  3690. if ( PM_InRoll( &ent->client->ps ) )
  3691. {
  3692. if ( ent->s.number >= MAX_CLIENTS || !player_locked )
  3693. {
  3694. //FIXME: NPCs should try to face us during this roll, so they roll around us...?
  3695. PM_CmdForRoll( &ent->client->ps, ucmd );
  3696. if ( ent->s.number >= MAX_CLIENTS )
  3697. {//make sure it doesn't roll me off a ledge
  3698. if ( !G_CheckRollSafety( ent, ent->client->ps.legsAnim, 24 ) )
  3699. {//crap! I guess all we can do is stop... UGH
  3700. ucmd->rightmove = ucmd->forwardmove = 0;
  3701. }
  3702. }
  3703. }
  3704. if ( ent->NPC )
  3705. {//invalid now
  3706. VectorClear( ent->client->ps.moveDir );
  3707. }
  3708. ent->client->ps.speed = 400;
  3709. }
  3710. if ( PM_InCartwheel( ent->client->ps.legsAnim ) )
  3711. {//can't keep moving in cartwheel
  3712. if ( ent->client->ps.legsAnimTimer > 100 )
  3713. {//still have time left in the anim
  3714. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  3715. if ( ent->NPC )
  3716. {//invalid now
  3717. VectorClear( ent->client->ps.moveDir );
  3718. }
  3719. if ( ent->s.number || !player_locked )
  3720. {
  3721. switch ( ent->client->ps.legsAnim )
  3722. {
  3723. case BOTH_ARIAL_LEFT:
  3724. case BOTH_CARTWHEEL_LEFT:
  3725. ucmd->rightmove = -127;
  3726. break;
  3727. case BOTH_ARIAL_RIGHT:
  3728. case BOTH_CARTWHEEL_RIGHT:
  3729. ucmd->rightmove = 127;
  3730. break;
  3731. case BOTH_ARIAL_F1:
  3732. ucmd->forwardmove = 127;
  3733. break;
  3734. default:
  3735. break;
  3736. }
  3737. }
  3738. }
  3739. }
  3740. if ( ent->client->ps.legsAnim == BOTH_BUTTERFLY_LEFT
  3741. || ent->client->ps.legsAnim == BOTH_BUTTERFLY_RIGHT )
  3742. {
  3743. if ( ent->client->ps.legsAnimTimer > 100 )
  3744. {//still have time left in the anim
  3745. ucmd->forwardmove = ucmd->rightmove = ucmd->upmove = 0;
  3746. if ( ent->NPC )
  3747. {//invalid now
  3748. VectorClear( ent->client->ps.moveDir );
  3749. }
  3750. if ( ent->s.number || !player_locked )
  3751. {
  3752. if ( ent->client->ps.legsAnimTimer > 450 )
  3753. {
  3754. switch ( ent->client->ps.legsAnim )
  3755. {
  3756. case BOTH_BUTTERFLY_LEFT:
  3757. ucmd->rightmove = -127;
  3758. break;
  3759. case BOTH_BUTTERFLY_RIGHT:
  3760. ucmd->rightmove = 127;
  3761. break;
  3762. default:
  3763. break;
  3764. }
  3765. }
  3766. }
  3767. }
  3768. }
  3769. overridAngles = (PM_AdjustAnglesForStabDown( ent, ucmd )?qtrue:overridAngles);
  3770. overridAngles = (PM_AdjustAngleForWallJump( ent, ucmd, qtrue )?qtrue:overridAngles);
  3771. overridAngles = (PM_AdjustAngleForWallRunUp( ent, ucmd, qtrue )?qtrue:overridAngles);
  3772. overridAngles = (PM_AdjustAngleForWallRun( ent, ucmd, qtrue )?qtrue:overridAngles);
  3773. return overridAngles;
  3774. }
  3775. void BG_AddPushVecToUcmd( gentity_t *self, usercmd_t *ucmd )
  3776. {
  3777. vec3_t forward, right, moveDir;
  3778. float pushSpeed, fMove, rMove;
  3779. if ( !self->client )
  3780. {
  3781. return;
  3782. }
  3783. pushSpeed = VectorLengthSquared(self->client->pushVec);
  3784. if(!pushSpeed)
  3785. {//not being pushed
  3786. return;
  3787. }
  3788. AngleVectors(self->client->ps.viewangles, forward, right, NULL);
  3789. VectorScale(forward, ucmd->forwardmove/127.0f * self->client->ps.speed, moveDir);
  3790. VectorMA(moveDir, ucmd->rightmove/127.0f * self->client->ps.speed, right, moveDir);
  3791. //moveDir is now our intended move velocity
  3792. VectorAdd(moveDir, self->client->pushVec, moveDir);
  3793. self->client->ps.speed = VectorNormalize(moveDir);
  3794. //moveDir is now our intended move velocity plus our push Vector
  3795. fMove = 127.0 * DotProduct(forward, moveDir);
  3796. rMove = 127.0 * DotProduct(right, moveDir);
  3797. ucmd->forwardmove = floor(fMove);//If in the same dir , will be positive
  3798. ucmd->rightmove = floor(rMove);//If in the same dir , will be positive
  3799. if ( self->client->pushVecTime < level.time )
  3800. {
  3801. VectorClear( self->client->pushVec );
  3802. }
  3803. }
  3804. void NPC_Accelerate( gentity_t *ent, qboolean fullWalkAcc, qboolean fullRunAcc )
  3805. {
  3806. if ( !ent->client || !ent->NPC )
  3807. {
  3808. return;
  3809. }
  3810. if ( !ent->NPC->stats.acceleration )
  3811. {//No acceleration means just start and stop
  3812. ent->NPC->currentSpeed = ent->NPC->desiredSpeed;
  3813. }
  3814. //FIXME: in cinematics always accel/decel?
  3815. else if ( ent->NPC->desiredSpeed <= ent->NPC->stats.walkSpeed )
  3816. {//Only accelerate if at walkSpeeds
  3817. if ( ent->NPC->desiredSpeed > ent->NPC->currentSpeed + ent->NPC->stats.acceleration )
  3818. {
  3819. //ent->client->ps.friction = 0;
  3820. ent->NPC->currentSpeed += ent->NPC->stats.acceleration;
  3821. }
  3822. else if ( ent->NPC->desiredSpeed > ent->NPC->currentSpeed )
  3823. {
  3824. //ent->client->ps.friction = 0;
  3825. ent->NPC->currentSpeed = ent->NPC->desiredSpeed;
  3826. }
  3827. else if ( fullWalkAcc && ent->NPC->desiredSpeed < ent->NPC->currentSpeed - ent->NPC->stats.acceleration )
  3828. {//decelerate even when walking
  3829. ent->NPC->currentSpeed -= ent->NPC->stats.acceleration;
  3830. }
  3831. else if ( ent->NPC->desiredSpeed < ent->NPC->currentSpeed )
  3832. {//stop on a dime
  3833. ent->NPC->currentSpeed = ent->NPC->desiredSpeed;
  3834. }
  3835. }
  3836. else// if ( ent->NPC->desiredSpeed > ent->NPC->stats.walkSpeed )
  3837. {//Only decelerate if at runSpeeds
  3838. if ( fullRunAcc && ent->NPC->desiredSpeed > ent->NPC->currentSpeed + ent->NPC->stats.acceleration )
  3839. {//Accelerate to runspeed
  3840. //ent->client->ps.friction = 0;
  3841. ent->NPC->currentSpeed += ent->NPC->stats.acceleration;
  3842. }
  3843. else if ( ent->NPC->desiredSpeed > ent->NPC->currentSpeed )
  3844. {//accelerate instantly
  3845. //ent->client->ps.friction = 0;
  3846. ent->NPC->currentSpeed = ent->NPC->desiredSpeed;
  3847. }
  3848. else if ( fullRunAcc && ent->NPC->desiredSpeed < ent->NPC->currentSpeed - ent->NPC->stats.acceleration )
  3849. {
  3850. ent->NPC->currentSpeed -= ent->NPC->stats.acceleration;
  3851. }
  3852. else if ( ent->NPC->desiredSpeed < ent->NPC->currentSpeed )
  3853. {
  3854. ent->NPC->currentSpeed = ent->NPC->desiredSpeed;
  3855. }
  3856. }
  3857. }
  3858. /*
  3859. -------------------------
  3860. NPC_GetWalkSpeed
  3861. -------------------------
  3862. */
  3863. static int NPC_GetWalkSpeed( gentity_t *ent )
  3864. {
  3865. int walkSpeed = 0;
  3866. if ( ( ent->client == NULL ) || ( ent->NPC == NULL ) )
  3867. return 0;
  3868. switch ( ent->client->playerTeam )
  3869. {
  3870. case TEAM_PLAYER: //To shutup compiler, will add entries later (this is stub code)
  3871. default:
  3872. walkSpeed = ent->NPC->stats.walkSpeed;
  3873. break;
  3874. }
  3875. return walkSpeed;
  3876. }
  3877. /*
  3878. -------------------------
  3879. NPC_GetRunSpeed
  3880. -------------------------
  3881. */
  3882. #define BORG_RUN_INCR 25
  3883. #define SPECIES_RUN_INCR 25
  3884. #define STASIS_RUN_INCR 20
  3885. #define WARBOT_RUN_INCR 20
  3886. static int NPC_GetRunSpeed( gentity_t *ent )
  3887. {
  3888. int runSpeed = 0;
  3889. if ( ( ent->client == NULL ) || ( ent->NPC == NULL ) )
  3890. return 0;
  3891. /*
  3892. switch ( ent->client->playerTeam )
  3893. {
  3894. case TEAM_BORG:
  3895. runSpeed = ent->NPC->stats.runSpeed;
  3896. runSpeed += BORG_RUN_INCR * (g_spskill->integer%3);
  3897. break;
  3898. case TEAM_8472:
  3899. runSpeed = ent->NPC->stats.runSpeed;
  3900. runSpeed += SPECIES_RUN_INCR * (g_spskill->integer%3);
  3901. break;
  3902. case TEAM_STASIS:
  3903. runSpeed = ent->NPC->stats.runSpeed;
  3904. runSpeed += STASIS_RUN_INCR * (g_spskill->integer%3);
  3905. break;
  3906. case TEAM_BOTS:
  3907. runSpeed = ent->NPC->stats.runSpeed;
  3908. break;
  3909. default:
  3910. runSpeed = ent->NPC->stats.runSpeed;
  3911. break;
  3912. }
  3913. */
  3914. // team no longer indicates species/race. Use NPC_class to adjust speed for specific npc types
  3915. switch( ent->client->NPC_class)
  3916. {
  3917. case CLASS_PROBE: // droid cases here to shut-up compiler
  3918. case CLASS_GONK:
  3919. case CLASS_R2D2:
  3920. case CLASS_R5D2:
  3921. case CLASS_MARK1:
  3922. case CLASS_MARK2:
  3923. case CLASS_PROTOCOL:
  3924. case CLASS_ATST: // hmm, not really your average droid
  3925. case CLASS_MOUSE:
  3926. case CLASS_SEEKER:
  3927. case CLASS_REMOTE:
  3928. runSpeed = ent->NPC->stats.runSpeed;
  3929. break;
  3930. default:
  3931. runSpeed = ent->NPC->stats.runSpeed;
  3932. break;
  3933. }
  3934. return runSpeed;
  3935. }
  3936. void G_HeldByMonster( gentity_t *ent, usercmd_t **ucmd )
  3937. {
  3938. if ( ent && ent->activator && ent->activator->inuse && ent->activator->health > 0 )
  3939. {
  3940. gentity_t *monster = ent->activator;
  3941. //take the monster's waypoint as your own
  3942. ent->waypoint = monster->waypoint;
  3943. //update the actual origin of the victim
  3944. mdxaBone_t boltMatrix;
  3945. // Getting the bolt here
  3946. int boltIndex = monster->gutBolt;//default to being held in his mouth
  3947. if ( monster->count == 1 )
  3948. {//being held in hand rather than the mouth, so use *that* bolt
  3949. boltIndex = monster->handRBolt;
  3950. }
  3951. vec3_t monAngles = {0};
  3952. monAngles[YAW] = monster->currentAngles[YAW];//only use YAW when passing angles to G2
  3953. gi.G2API_GetBoltMatrix( monster->ghoul2, monster->playerModel, boltIndex,
  3954. &boltMatrix, monAngles, monster->currentOrigin, (cg.time?cg.time:level.time),
  3955. NULL, monster->s.modelScale );
  3956. // Storing ent position, bolt position, and bolt axis
  3957. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, ent->client->ps.origin );
  3958. gi.linkentity( ent );
  3959. //lock view angles
  3960. PM_AdjustAnglesForHeldByMonster( ent, monster, *ucmd );
  3961. if ( monster->client && monster->client->NPC_class == CLASS_WAMPA )
  3962. {//can only hit attack button
  3963. (*ucmd)->buttons &= ~((*ucmd)->buttons&~BUTTON_ATTACK);
  3964. }
  3965. }
  3966. else if (ent)
  3967. {//doh, my captor died!
  3968. ent->activator = NULL;
  3969. if (ent->client)
  3970. {
  3971. ent->client->ps.eFlags &= ~(EF_HELD_BY_WAMPA|EF_HELD_BY_RANCOR);
  3972. }
  3973. }
  3974. // don't allow movement, weapon switching, and most kinds of button presses
  3975. (*ucmd)->forwardmove = 0;
  3976. (*ucmd)->rightmove = 0;
  3977. (*ucmd)->upmove = 0;
  3978. }
  3979. // yes... so stop skipping...
  3980. void G_StopCinematicSkip( void )
  3981. {
  3982. gi.cvar_set("skippingCinematic", "0");
  3983. gi.cvar_set("timescale", "1");
  3984. }
  3985. void G_StartCinematicSkip( void )
  3986. {
  3987. if (cinematicSkipScript[0])
  3988. {
  3989. Quake3Game()->RunScript( &g_entities[0], cinematicSkipScript );
  3990. cinematicSkipScript[0] = 0;
  3991. gi.cvar_set("skippingCinematic", "1");
  3992. gi.cvar_set("timescale", "100");
  3993. }
  3994. else
  3995. {
  3996. // no... so start skipping...
  3997. gi.cvar_set("skippingCinematic", "1");
  3998. gi.cvar_set("timescale", "100");
  3999. }
  4000. }
  4001. void G_CheckClientIdle( gentity_t *ent, usercmd_t *ucmd )
  4002. {
  4003. if ( !ent || !ent->client || ent->health <= 0 )
  4004. {
  4005. return;
  4006. }
  4007. if ( !ent->s.number && ( !cg.renderingThirdPerson || cg.zoomMode ) )
  4008. {
  4009. if ( ent->client->idleTime < level.time )
  4010. {
  4011. ent->client->idleTime = level.time;
  4012. }
  4013. return;
  4014. }
  4015. if ( !VectorCompare( vec3_origin, ent->client->ps.velocity )
  4016. || ucmd->buttons || ucmd->forwardmove || ucmd->rightmove || ucmd->upmove
  4017. || !PM_StandingAnim( ent->client->ps.legsAnim )
  4018. || ent->enemy
  4019. || ent->client->ps.legsAnimTimer
  4020. || ent->client->ps.torsoAnimTimer )
  4021. {//FIXME: also check for turning?
  4022. if ( !VectorCompare( vec3_origin, ent->client->ps.velocity )
  4023. || ucmd->buttons || ucmd->forwardmove || ucmd->rightmove || ucmd->upmove
  4024. || ent->enemy )
  4025. {
  4026. //if in an idle, break out
  4027. switch ( ent->client->ps.legsAnim )
  4028. {
  4029. case BOTH_STAND1IDLE1:
  4030. case BOTH_STAND2IDLE1:
  4031. case BOTH_STAND2IDLE2:
  4032. case BOTH_STAND3IDLE1:
  4033. case BOTH_STAND5IDLE1:
  4034. ent->client->ps.legsAnimTimer = 0;
  4035. break;
  4036. }
  4037. switch ( ent->client->ps.torsoAnim )
  4038. {
  4039. case BOTH_STAND1IDLE1:
  4040. case BOTH_STAND2IDLE1:
  4041. case BOTH_STAND2IDLE2:
  4042. case BOTH_STAND3IDLE1:
  4043. case BOTH_STAND5IDLE1:
  4044. ent->client->ps.torsoAnimTimer = 0;
  4045. break;
  4046. }
  4047. }
  4048. //
  4049. if ( ent->client->idleTime < level.time )
  4050. {
  4051. ent->client->idleTime = level.time;
  4052. }
  4053. }
  4054. else if ( level.time - ent->client->idleTime > 5000 )
  4055. {//been idle for 5 seconds
  4056. int idleAnim = -1;
  4057. switch ( ent->client->ps.legsAnim )
  4058. {
  4059. case BOTH_STAND1:
  4060. idleAnim = BOTH_STAND1IDLE1;
  4061. break;
  4062. case BOTH_STAND2:
  4063. idleAnim = Q_irand(BOTH_STAND2IDLE1,BOTH_STAND2IDLE2);
  4064. break;
  4065. case BOTH_STAND3:
  4066. idleAnim = BOTH_STAND3IDLE1;
  4067. break;
  4068. case BOTH_STAND5:
  4069. idleAnim = BOTH_STAND5IDLE1;
  4070. break;
  4071. }
  4072. if ( idleAnim != -1 && PM_HasAnimation( ent, idleAnim ) )
  4073. {
  4074. NPC_SetAnim( ent, SETANIM_BOTH, idleAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  4075. //don't idle again after this anim for a while
  4076. ent->client->idleTime = level.time + PM_AnimLength( ent->client->clientInfo.animFileIndex, (animNumber_t)idleAnim ) + Q_irand( 0, 2000 );
  4077. }
  4078. }
  4079. }
  4080. void G_CheckMovingLoopingSounds( gentity_t *ent, usercmd_t *ucmd )
  4081. {
  4082. if ( ent->client )
  4083. {
  4084. if ( (ent->NPC&&!VectorCompare( vec3_origin, ent->client->ps.moveDir ))//moving using moveDir
  4085. || ucmd->forwardmove || ucmd->rightmove//moving using ucmds
  4086. || (ucmd->upmove&&FlyingCreature( ent ))//flier using ucmds to move
  4087. || (FlyingCreature( ent )&&!VectorCompare( vec3_origin, ent->client->ps.velocity )&&ent->health>0))//flier using velocity to move
  4088. {
  4089. switch( ent->client->NPC_class )
  4090. {
  4091. case CLASS_R2D2:
  4092. ent->s.loopSound = G_SoundIndex( "sound/chars/r2d2/misc/r2_move_lp.wav" );
  4093. break;
  4094. case CLASS_R5D2:
  4095. ent->s.loopSound = G_SoundIndex( "sound/chars/r2d2/misc/r2_move_lp2.wav" );
  4096. break;
  4097. case CLASS_MARK2:
  4098. ent->s.loopSound = G_SoundIndex( "sound/chars/mark2/misc/mark2_move_lp" );
  4099. break;
  4100. case CLASS_MOUSE:
  4101. ent->s.loopSound = G_SoundIndex( "sound/chars/mouse/misc/mouse_lp" );
  4102. break;
  4103. case CLASS_PROBE:
  4104. ent->s.loopSound = G_SoundIndex( "sound/chars/probe/misc/probedroidloop" );
  4105. }
  4106. }
  4107. else
  4108. {//not moving under your own control, stop loopSound
  4109. if ( ent->client->NPC_class == CLASS_R2D2 || ent->client->NPC_class == CLASS_R5D2
  4110. || ent->client->NPC_class == CLASS_MARK2 || ent->client->NPC_class == CLASS_MOUSE
  4111. || ent->client->NPC_class == CLASS_PROBE )
  4112. {
  4113. ent->s.loopSound = 0;
  4114. }
  4115. }
  4116. }
  4117. }
  4118. /*
  4119. ==============
  4120. ClientAlterSpeed
  4121. This function is called ONLY from ClientThinkReal, and is responsible for setting client ps.speed
  4122. ==============
  4123. */
  4124. void ClientAlterSpeed(gentity_t *ent, usercmd_t *ucmd, qboolean controlledByPlayer, float vehicleFrameTimeModifier)
  4125. {
  4126. gclient_t *client = ent->client;
  4127. Vehicle_t *pVeh = NULL;
  4128. if ( ent->client && ent->client->NPC_class == CLASS_VEHICLE )
  4129. {
  4130. pVeh = ent->m_pVehicle;
  4131. }
  4132. // set speed
  4133. // This may be wrong: If we're an npc and we are in a vehicle???
  4134. if ( ent->NPC != NULL && ent->client && ( ent->s.m_iVehicleNum != 0 )/*&& ent->client->NPC_class == CLASS_VEHICLE*/ )
  4135. {//we don't actually scale the ucmd, we use actual speeds
  4136. //FIXME: swoop should keep turning (and moving forward?) for a little bit?
  4137. if ( ent->NPC->combatMove == qfalse )
  4138. {
  4139. if ( !(ucmd->buttons & BUTTON_USE) )
  4140. {//Not leaning
  4141. qboolean Flying = (ucmd->upmove && ent->client->moveType == MT_FLYSWIM);
  4142. qboolean Climbing = (ucmd->upmove && ent->watertype&CONTENTS_LADDER );
  4143. client->ps.friction = 6;
  4144. if ( ucmd->forwardmove || ucmd->rightmove || Flying )
  4145. {
  4146. //if ( ent->NPC->behaviorState != BS_FORMATION )
  4147. {//In - Formation NPCs set thier desiredSpeed themselves
  4148. if ( ucmd->buttons & BUTTON_WALKING )
  4149. {
  4150. ent->NPC->desiredSpeed = NPC_GetWalkSpeed( ent );//ent->NPC->stats.walkSpeed;
  4151. }
  4152. else//running
  4153. {
  4154. ent->NPC->desiredSpeed = NPC_GetRunSpeed( ent );//ent->NPC->stats.runSpeed;
  4155. }
  4156. if ( ent->NPC->currentSpeed >= 80 && !controlledByPlayer )
  4157. {//At higher speeds, need to slow down close to stuff
  4158. //Slow down as you approach your goal
  4159. // if ( ent->NPC->distToGoal < SLOWDOWN_DIST && client->race != RACE_BORG && !(ent->NPC->aiFlags&NPCAI_NO_SLOWDOWN) )//128
  4160. if ( ent->NPC->distToGoal < SLOWDOWN_DIST && !(ent->NPC->aiFlags&NPCAI_NO_SLOWDOWN) )//128
  4161. {
  4162. if ( ent->NPC->desiredSpeed > MIN_NPC_SPEED )
  4163. {
  4164. float slowdownSpeed = ((float)ent->NPC->desiredSpeed) * ent->NPC->distToGoal / SLOWDOWN_DIST;
  4165. ent->NPC->desiredSpeed = ceil(slowdownSpeed);
  4166. if ( ent->NPC->desiredSpeed < MIN_NPC_SPEED )
  4167. {//don't slow down too much
  4168. ent->NPC->desiredSpeed = MIN_NPC_SPEED;
  4169. }
  4170. }
  4171. }
  4172. }
  4173. }
  4174. }
  4175. else if ( Climbing )
  4176. {
  4177. ent->NPC->desiredSpeed = ent->NPC->stats.walkSpeed;
  4178. }
  4179. else
  4180. {//We want to stop
  4181. ent->NPC->desiredSpeed = 0;
  4182. }
  4183. NPC_Accelerate( ent, qfalse, qfalse );
  4184. if ( ent->NPC->currentSpeed <= 24 && ent->NPC->desiredSpeed < ent->NPC->currentSpeed )
  4185. {//No-one walks this slow
  4186. client->ps.speed = ent->NPC->currentSpeed = 0;//Full stop
  4187. ucmd->forwardmove = 0;
  4188. ucmd->rightmove = 0;
  4189. }
  4190. else
  4191. {
  4192. if ( ent->NPC->currentSpeed <= ent->NPC->stats.walkSpeed )
  4193. {//Play the walkanim
  4194. ucmd->buttons |= BUTTON_WALKING;
  4195. }
  4196. else
  4197. {
  4198. ucmd->buttons &= ~BUTTON_WALKING;
  4199. }
  4200. if ( ent->NPC->currentSpeed > 0 )
  4201. {//We should be moving
  4202. if ( Climbing || Flying )
  4203. {
  4204. if ( !ucmd->upmove )
  4205. {//We need to force them to take a couple more steps until stopped
  4206. ucmd->upmove = ent->NPC->last_ucmd.upmove;//was last_upmove;
  4207. }
  4208. }
  4209. else if ( !ucmd->forwardmove && !ucmd->rightmove )
  4210. {//We need to force them to take a couple more steps until stopped
  4211. ucmd->forwardmove = ent->NPC->last_ucmd.forwardmove;//was last_forwardmove;
  4212. ucmd->rightmove = ent->NPC->last_ucmd.rightmove;//was last_rightmove;
  4213. }
  4214. }
  4215. client->ps.speed = ent->NPC->currentSpeed;
  4216. if ( player && player->client && player->client->ps.viewEntity == ent->s.number )
  4217. {
  4218. }
  4219. else
  4220. {
  4221. //Slow down on turns - don't orbit!!!
  4222. float turndelta = 0;
  4223. // if the NPC is locked into a Yaw, we want to check the lockedDesiredYaw...otherwise the NPC can't walk backwards, because it always thinks it trying to turn according to desiredYaw
  4224. if( client->renderInfo.renderFlags & RF_LOCKEDANGLE ) // yeah I know the RF_ flag is a pretty ugly hack...
  4225. {
  4226. turndelta = (180 - fabs( AngleDelta( ent->currentAngles[YAW], ent->NPC->lockedDesiredYaw ) ))/180;
  4227. }
  4228. else
  4229. {
  4230. turndelta = (180 - fabs( AngleDelta( ent->currentAngles[YAW], ent->NPC->desiredYaw ) ))/180;
  4231. }
  4232. if ( turndelta < 0.75f )
  4233. {
  4234. client->ps.speed = 0;
  4235. }
  4236. else if ( ent->NPC->distToGoal < 100 && turndelta < 1.0 )
  4237. {//Turn is greater than 45 degrees or closer than 100 to goal
  4238. client->ps.speed = floor(((float)(client->ps.speed))*turndelta);
  4239. }
  4240. }
  4241. }
  4242. }
  4243. }
  4244. else
  4245. {
  4246. ent->NPC->desiredSpeed = ( ucmd->buttons & BUTTON_WALKING ) ? NPC_GetWalkSpeed( ent ) : NPC_GetRunSpeed( ent );
  4247. client->ps.speed = ent->NPC->desiredSpeed;
  4248. }
  4249. }
  4250. else
  4251. {//Client sets ucmds and such for speed alterations
  4252. {
  4253. client->ps.speed = g_speed->value;//default is 320
  4254. /*if ( !ent->s.number && ent->painDebounceTime>level.time )
  4255. {
  4256. client->ps.speed *= 0.25f;
  4257. }
  4258. else */if (ent->client->ps.heldClient < ENTITYNUM_WORLD)
  4259. {
  4260. client->ps.speed *= 0.3f;
  4261. }
  4262. else if ( PM_SaberInAttack( ent->client->ps.saberMove ) && ucmd->forwardmove < 0 )
  4263. {//if running backwards while attacking, don't run as fast.
  4264. switch( client->ps.saberAnimLevel )
  4265. {
  4266. case SS_FAST:
  4267. client->ps.speed *= 0.75f;
  4268. break;
  4269. case SS_MEDIUM:
  4270. case SS_DUAL:
  4271. case SS_STAFF:
  4272. client->ps.speed *= 0.60f;
  4273. break;
  4274. case SS_STRONG:
  4275. client->ps.speed *= 0.45f;
  4276. break;
  4277. }
  4278. if ( g_saberMoveSpeed->value != 1.0f )
  4279. {
  4280. client->ps.speed *= g_saberMoveSpeed->value;
  4281. }
  4282. }
  4283. else if ( PM_LeapingSaberAnim( client->ps.legsAnim ) )
  4284. {//no mod on speed when leaping
  4285. //FIXME: maybe jump?
  4286. }
  4287. else if ( PM_SpinningSaberAnim( client->ps.legsAnim ) )
  4288. {
  4289. client->ps.speed *= 0.5f;
  4290. if ( g_saberMoveSpeed->value != 1.0f )
  4291. {
  4292. client->ps.speed *= g_saberMoveSpeed->value;
  4293. }
  4294. }
  4295. else if ( client->ps.weapon == WP_SABER && ( ucmd->buttons & BUTTON_ATTACK ) )
  4296. {//if attacking with saber while running, drop your speed
  4297. //FIXME: should be weaponTime? Or in certain anims?
  4298. switch( client->ps.saberAnimLevel )
  4299. {
  4300. case SS_MEDIUM:
  4301. case SS_DUAL:
  4302. case SS_STAFF:
  4303. client->ps.speed *= 0.85f;
  4304. break;
  4305. case SS_STRONG:
  4306. client->ps.speed *= 0.70f;
  4307. break;
  4308. }
  4309. if ( g_saberMoveSpeed->value != 1.0f )
  4310. {
  4311. client->ps.speed *= g_saberMoveSpeed->value;
  4312. }
  4313. }
  4314. }
  4315. }
  4316. if ( client->NPC_class == CLASS_ATST && client->ps.legsAnim == BOTH_RUN1START )
  4317. {//HACK: when starting to move as atst, ramp up speed
  4318. //float animLength = PM_AnimLength( client->clientInfo.animFileIndex, (animNumber_t)client->ps.legsAnim);
  4319. //client->ps.speed *= ( animLength - client->ps.legsAnimTimer)/animLength;
  4320. if ( client->ps.legsAnimTimer > 100 )
  4321. {
  4322. client->ps.speed = 0;
  4323. }
  4324. }
  4325. //Apply forced movement
  4326. if ( client->forced_forwardmove )
  4327. {
  4328. ucmd->forwardmove = client->forced_forwardmove;
  4329. if ( !client->ps.speed )
  4330. {
  4331. if ( ent->NPC != NULL )
  4332. {
  4333. client->ps.speed = ent->NPC->stats.runSpeed;
  4334. }
  4335. else
  4336. {
  4337. client->ps.speed = g_speed->value;//default is 320
  4338. }
  4339. }
  4340. }
  4341. if ( client->forced_rightmove )
  4342. {
  4343. ucmd->rightmove = client->forced_rightmove;
  4344. if ( !client->ps.speed )
  4345. {
  4346. if ( ent->NPC != NULL )
  4347. {
  4348. client->ps.speed = ent->NPC->stats.runSpeed;
  4349. }
  4350. else
  4351. {
  4352. client->ps.speed = g_speed->value;//default is 320
  4353. }
  4354. }
  4355. }
  4356. if ( !pVeh )
  4357. {
  4358. if ( ucmd->forwardmove < 0 && !(ucmd->buttons&BUTTON_WALKING) && client->ps.groundEntityNum != ENTITYNUM_NONE )
  4359. {//running backwards is slower than running forwards
  4360. client->ps.speed *= 0.75;
  4361. }
  4362. if (client->ps.forceRageRecoveryTime > level.time )
  4363. {
  4364. client->ps.speed *= 0.75;
  4365. }
  4366. }
  4367. }
  4368. extern qboolean ForceDrain2(gentity_t *ent);
  4369. extern void ForceGrip(gentity_t *ent);
  4370. extern void ForceLightning(gentity_t *ent);
  4371. extern void ForceProtect(gentity_t *ent);
  4372. extern void ForceRage(gentity_t *ent);
  4373. extern void ForceSeeing(gentity_t *ent);
  4374. extern void ForceTelepathy(gentity_t *ent);
  4375. extern void ForceAbsorb(gentity_t *ent);
  4376. extern void ForceHeal(gentity_t *ent);
  4377. static void ProcessGenericCmd(gentity_t *ent, byte cmd)
  4378. {
  4379. switch(cmd) {
  4380. case 0:
  4381. break;
  4382. case GENCMD_FORCE_DRAIN:
  4383. ForceDrain2(ent);
  4384. break;
  4385. case GENCMD_FORCE_THROW:
  4386. ForceThrow(ent, qfalse);
  4387. break;
  4388. case GENCMD_FORCE_SPEED:
  4389. ForceSpeed(ent);
  4390. break;
  4391. case GENCMD_FORCE_PULL:
  4392. ForceThrow(ent, qtrue);
  4393. break;
  4394. case GENCMD_FORCE_DISTRACT:
  4395. ForceTelepathy(ent);
  4396. break;
  4397. case GENCMD_FORCE_GRIP:
  4398. ForceGrip(ent);
  4399. break;
  4400. case GENCMD_FORCE_LIGHTNING:
  4401. ForceLightning(ent);
  4402. break;
  4403. case GENCMD_FORCE_RAGE:
  4404. ForceRage(ent);
  4405. break;
  4406. case GENCMD_FORCE_PROTECT:
  4407. ForceProtect(ent);
  4408. break;
  4409. case GENCMD_FORCE_ABSORB:
  4410. ForceAbsorb(ent);
  4411. break;
  4412. case GENCMD_FORCE_SEEING:
  4413. ForceSeeing(ent);
  4414. break;
  4415. case GENCMD_FORCE_HEAL:
  4416. ForceHeal(ent);
  4417. break;
  4418. }
  4419. }
  4420. /*
  4421. ==============
  4422. ClientThink
  4423. This will be called once for each client frame, which will
  4424. usually be a couple times for each server frame on fast clients.
  4425. ==============
  4426. */
  4427. extern int G_FindLocalInterestPoint( gentity_t *self );
  4428. extern float G_CanJumpToEnemyVeh(Vehicle_t *pVeh, const usercmd_t *pUmcd );
  4429. extern void Cbuf_ExecuteText( int exec_when, const char *text );
  4430. void ClientThink_real( gentity_t *ent, usercmd_t *ucmd )
  4431. {
  4432. gclient_t *client;
  4433. pmove_t pm;
  4434. vec3_t oldOrigin;
  4435. int oldEventSequence;
  4436. int msec;
  4437. qboolean inSpinFlipAttack = PM_AdjustAnglesForSpinningFlip( ent, ucmd, qfalse );
  4438. qboolean controlledByPlayer = qfalse;
  4439. Vehicle_t *pVeh = NULL;
  4440. if ( ent->client && ent->client->NPC_class == CLASS_VEHICLE )
  4441. {
  4442. pVeh = ent->m_pVehicle;
  4443. }
  4444. //Don't let the player do anything if in a camera
  4445. if ( (ent->s.eFlags&EF_HELD_BY_RANCOR)
  4446. || (ent->s.eFlags&EF_HELD_BY_WAMPA) )
  4447. {
  4448. G_HeldByMonster( ent, &ucmd );
  4449. }
  4450. if ( ent->s.number == 0 )
  4451. {
  4452. extern cvar_t *g_skippingcin;
  4453. if ( ent->s.eFlags & EF_LOCKED_TO_WEAPON )
  4454. {
  4455. G_UpdateEmplacedWeaponData( ent );
  4456. RunEmplacedWeapon( ent, &ucmd );
  4457. }
  4458. if ( ent->client->ps.saberLockTime > level.time && ent->client->ps.saberLockEnemy != ENTITYNUM_NONE )
  4459. {
  4460. NPC_SetLookTarget( ent, ent->client->ps.saberLockEnemy, level.time+1000 );
  4461. }
  4462. if ( ent->client->renderInfo.lookTargetClearTime < level.time //NOTE: here this is used as a debounce, not an actual timer
  4463. && ent->health > 0 //must be alive
  4464. && (!ent->enemy || ent->client->ps.saberMove != LS_A_BACKSTAB) )//don't update if in backstab unless don't currently have an enemy
  4465. {//NOTE: doesn't keep updating to nearest enemy once you're dead
  4466. int newLookTarget;
  4467. if ( !G_ValidateLookEnemy( ent, ent->enemy ) )
  4468. {
  4469. ent->enemy = NULL;
  4470. }
  4471. //FIXME: make this a little prescient?
  4472. G_ChooseLookEnemy( ent, ucmd );
  4473. if ( ent->enemy )
  4474. {//target
  4475. newLookTarget = ent->enemy->s.number;
  4476. //so we don't change our minds in the next 1 second
  4477. ent->client->renderInfo.lookTargetClearTime = level.time+1000;
  4478. ent->client->renderInfo.lookMode = LM_ENT;
  4479. }
  4480. else
  4481. {//no target
  4482. //FIXME: what about sightalerts and missiles?
  4483. newLookTarget = ENTITYNUM_NONE;
  4484. newLookTarget = G_FindLocalInterestPoint( ent );
  4485. if ( newLookTarget != ENTITYNUM_NONE )
  4486. {//found something of interest
  4487. ent->client->renderInfo.lookMode = LM_INTEREST;
  4488. }
  4489. else
  4490. {//okay, no interesting things and no enemies, so look for items
  4491. newLookTarget = G_FindLookItem( ent );
  4492. ent->client->renderInfo.lookMode = LM_ENT;
  4493. }
  4494. }
  4495. if ( ent->client->renderInfo.lookTarget != newLookTarget )
  4496. {//transitioning
  4497. NPC_SetLookTarget( ent, newLookTarget, level.time+1000 );
  4498. }
  4499. }
  4500. if ( in_camera )
  4501. {
  4502. // watch the code here, you MUST "return" within this IF(), *unless* you're stopping the cinematic skip.
  4503. //
  4504. if ( ClientCinematicThink(ent->client) )
  4505. {
  4506. if (g_skippingcin->integer) // already doing cinematic skip?
  4507. {// yes... so stop skipping...
  4508. G_StopCinematicSkip();
  4509. }
  4510. else
  4511. {// no... so start skipping...
  4512. G_StartCinematicSkip();
  4513. return;
  4514. }
  4515. }
  4516. else
  4517. {
  4518. return;
  4519. }
  4520. }
  4521. // If he's riding the vehicle...
  4522. else if ( ent->s.m_iVehicleNum != 0 && ent->health > 0 )
  4523. {
  4524. }
  4525. else
  4526. {
  4527. if ( g_skippingcin->integer )
  4528. {//We're skipping the cinematic and it's over now
  4529. gi.cvar_set("timescale", "1");
  4530. gi.cvar_set("skippingCinematic", "0");
  4531. }
  4532. if ( ent->client->ps.pm_type == PM_DEAD && cg.missionStatusDeadTime < level.time )
  4533. {//mission status screen is up because player is dead, stop all scripts
  4534. if (Q_stricmpn(level.mapname,"_holo",5)) {
  4535. stop_icarus = qtrue;
  4536. }
  4537. }
  4538. }
  4539. // // Don't allow the player to adjust the pitch when they are in third person overhead cam.
  4540. //extern vmCvar_t cg_thirdPerson;
  4541. // if ( cg_thirdPerson.integer == 2 )
  4542. // {
  4543. // ucmd->angles[PITCH] = 0;
  4544. // }
  4545. if ( cg.zoomMode == 2 )
  4546. {
  4547. // Any kind of movement when the player is NOT ducked when the disruptor gun is zoomed will cause us to auto-magically un-zoom
  4548. if ( ( (ucmd->forwardmove||ucmd->rightmove)
  4549. && ucmd->upmove >= 0 //crouching-moving is ok
  4550. && !(ucmd->buttons&BUTTON_USE)/*leaning is ok*/
  4551. )
  4552. || ucmd->upmove > 0 //jumping not allowed
  4553. )
  4554. {
  4555. // already zooming, so must be wanting to turn it off
  4556. G_Sound( ent, G_SoundIndex( "sound/weapons/disruptor/zoomend.wav" ));
  4557. #ifdef _IMMERSION
  4558. G_Force( ent, G_ForceIndex( "fffx/weapons/disruptor/zoomend", FF_CHANNEL_WEAPON ) );
  4559. #endif // _IMMERSION
  4560. cg.zoomMode = 0;
  4561. cg.zoomTime = cg.time;
  4562. cg.zoomLocked = qfalse;
  4563. }
  4564. }
  4565. if ( (player_locked
  4566. || (ent->client->ps.eFlags&EF_FORCE_GRIPPED)
  4567. || (ent->client->ps.eFlags&EF_FORCE_DRAINED)
  4568. || (ent->client->ps.legsAnim==BOTH_PLAYER_PA_1)
  4569. || (ent->client->ps.legsAnim==BOTH_PLAYER_PA_2)
  4570. || (ent->client->ps.legsAnim==BOTH_PLAYER_PA_3))
  4571. && ent->client->ps.pm_type < PM_DEAD ) // unless dead
  4572. {//lock out player control
  4573. if ( !player_locked )
  4574. {
  4575. VectorClear( ucmd->angles );
  4576. }
  4577. ucmd->forwardmove = 0;
  4578. ucmd->rightmove = 0;
  4579. ucmd->buttons = 0;
  4580. ucmd->upmove = 0;
  4581. PM_AdjustAnglesToGripper( ent, ucmd );
  4582. }
  4583. if ( ent->client->ps.leanofs )
  4584. {//no shooting while leaning
  4585. ucmd->buttons &= ~BUTTON_ATTACK;
  4586. if ( ent->client->ps.weapon != WP_DISRUPTOR )
  4587. {//can still zoom around corners
  4588. ucmd->buttons &= ~BUTTON_ALT_ATTACK;
  4589. }
  4590. }
  4591. }
  4592. else
  4593. {
  4594. if ( ent->s.eFlags & EF_LOCKED_TO_WEAPON )
  4595. {
  4596. G_UpdateEmplacedWeaponData( ent );
  4597. }
  4598. if ( player && player->client && player->client->ps.viewEntity == ent->s.number )
  4599. {
  4600. controlledByPlayer = qtrue;
  4601. int sav_weapon = ucmd->weapon;
  4602. memcpy( ucmd, &player->client->usercmd, sizeof( usercmd_t ) );
  4603. ucmd->weapon = sav_weapon;
  4604. ent->client->usercmd = *ucmd;
  4605. }
  4606. // Transfer over our driver's commands to us (the vehicle).
  4607. if ( ent->owner && ent->client && ent->client->NPC_class == CLASS_VEHICLE )
  4608. {
  4609. memcpy( ucmd, &ent->owner->client->usercmd, sizeof( usercmd_t ) );
  4610. ucmd->buttons &= ~BUTTON_USE;//Vehicles NEVER try to use ANYTHING!!!
  4611. //ucmd->weapon = ent->client->ps.weapon; // but keep our weapon.
  4612. ent->client->usercmd = *ucmd;
  4613. }
  4614. G_NPCMunroMatchPlayerWeapon( ent );
  4615. }
  4616. // If we are a vehicle, update ourself.
  4617. if ( pVeh
  4618. && (pVeh->m_pVehicleInfo->Inhabited(pVeh)
  4619. || pVeh->m_iBoarding!=0
  4620. || pVeh->m_pVehicleInfo->type!=VH_ANIMAL) )
  4621. {
  4622. pVeh->m_pVehicleInfo->Update( pVeh, ucmd );
  4623. }
  4624. else if ( ent->client )
  4625. {//this is any client that is not a vehicle (OR: is a vehicle and it not being ridden, is not being boarded, or is a TaunTaun...!
  4626. if ( ent->client->NPC_class == CLASS_GONK ||
  4627. ent->client->NPC_class == CLASS_MOUSE ||
  4628. ent->client->NPC_class == CLASS_R2D2 ||
  4629. ent->client->NPC_class == CLASS_R5D2 )
  4630. {//no jumping or strafing in these guys
  4631. ucmd->upmove = ucmd->rightmove = 0;
  4632. }
  4633. else if ( ent->client->NPC_class == CLASS_ATST || ent->client->NPC_class == CLASS_RANCOR )
  4634. {//no jumping in atst
  4635. if (ent->client->ps.pm_type != PM_NOCLIP)
  4636. {
  4637. ucmd->upmove = 0;
  4638. }
  4639. if ( ent->client->ps.groundEntityNum != ENTITYNUM_NONE )
  4640. {//ATST crushes anything underneath it
  4641. gentity_t *under = &g_entities[ent->client->ps.groundEntityNum];
  4642. if ( under && under->health && under->takedamage )
  4643. {
  4644. vec3_t down = {0,0,-1};
  4645. //FIXME: we'll be doing traces down from each foot, so we'll have a real impact origin
  4646. G_Damage( under, ent, ent, down, under->currentOrigin, 100, 0, MOD_CRUSH );
  4647. }
  4648. //so they know to run like hell when I get close
  4649. //FIXME: project this in the direction I'm moving?
  4650. if ( ent->client->NPC_class != CLASS_RANCOR && !Q_irand( 0, 10 ) )
  4651. {//not so often...
  4652. AddSoundEvent( ent, ent->currentOrigin, ent->maxs[1]*5, AEL_DANGER, qfalse, qtrue );
  4653. AddSightEvent( ent, ent->currentOrigin, ent->maxs[1]*5, AEL_DANGER, 100 );
  4654. }
  4655. }
  4656. }
  4657. else if ( ent->client->ps.groundEntityNum < ENTITYNUM_WORLD && !ent->client->ps.forceJumpCharge )
  4658. {//standing on an entity and not currently force jumping
  4659. gentity_t *groundEnt = &g_entities[ent->client->ps.groundEntityNum];
  4660. if ( groundEnt && groundEnt->client )
  4661. {
  4662. // If you landed on a speeder or animal vehicle...
  4663. if ( groundEnt->client && groundEnt->client->NPC_class == CLASS_VEHICLE )
  4664. {
  4665. if ( ent->client->NPC_class != CLASS_VEHICLE )
  4666. {//um... vehicles shouldn't ride other vehicles, mmkay?
  4667. if ( (groundEnt->m_pVehicle->m_pVehicleInfo->type == VH_ANIMAL && PM_HasAnimation( ent, BOTH_VT_IDLE ))
  4668. || (groundEnt->m_pVehicle->m_pVehicleInfo->type == VH_SPEEDER && PM_HasAnimation( ent, BOTH_VS_IDLE )) )
  4669. {
  4670. //groundEnt->m_pVehicle->m_iBoarding = -3; // Land From Behind
  4671. groundEnt->m_pVehicle->m_pVehicleInfo->Board( groundEnt->m_pVehicle, ent );
  4672. }
  4673. }
  4674. }
  4675. else if ( groundEnt->client && groundEnt->client->NPC_class == CLASS_SAND_CREATURE
  4676. && G_HasKnockdownAnims( ent ) )
  4677. {//step on a sand creature = *you* fall down
  4678. G_Knockdown( ent, groundEnt, vec3_origin, 300, qtrue );
  4679. }
  4680. else if ( groundEnt->client && groundEnt->client->NPC_class == CLASS_RANCOR )
  4681. {//step on a Rancor, it bucks & throws you off
  4682. if ( groundEnt->client->ps.legsAnim != BOTH_ATTACK3
  4683. && groundEnt->client->ps.legsAnim != BOTH_ATTACK4
  4684. && groundEnt->client->ps.legsAnim != BOTH_BUCK_RIDER )
  4685. {//don't interrupt special anims
  4686. vec3_t throwDir, right;
  4687. AngleVectors( groundEnt->currentAngles, throwDir, right, NULL );
  4688. VectorScale(throwDir,-1,throwDir);
  4689. VectorMA( throwDir, Q_flrand( -0.5f, 0.5f), right, throwDir );
  4690. throwDir[2] = 0.2f;
  4691. VectorNormalize( throwDir );
  4692. if ( !(ent->flags&FL_NO_KNOCKBACK) )
  4693. {
  4694. G_Throw( ent, throwDir, Q_flrand( 50, 200 ) );
  4695. }
  4696. if ( G_HasKnockdownAnims( ent ) )
  4697. {
  4698. G_Knockdown( ent, groundEnt, vec3_origin, 300, qtrue );
  4699. }
  4700. NPC_SetAnim( groundEnt, SETANIM_BOTH, BOTH_BUCK_RIDER, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD);
  4701. }
  4702. }
  4703. else if ( groundEnt->client->ps.groundEntityNum != ENTITYNUM_NONE &&
  4704. groundEnt->health > 0 && !PM_InRoll( &groundEnt->client->ps )
  4705. && !(groundEnt->client->ps.eFlags&EF_LOCKED_TO_WEAPON)
  4706. && !(groundEnt->client->ps.eFlags&EF_HELD_BY_RANCOR)
  4707. && !(groundEnt->client->ps.eFlags&EF_HELD_BY_WAMPA)
  4708. && !(groundEnt->client->ps.eFlags&EF_HELD_BY_SAND_CREATURE)
  4709. && !inSpinFlipAttack )
  4710. {//landed on a live client who is on the ground, jump off them and knock them down
  4711. qboolean forceKnockdown = qfalse;
  4712. // If in a vehicle when land on someone, always knockdown.
  4713. if ( pVeh )
  4714. {
  4715. forceKnockdown = qtrue;
  4716. }
  4717. else if ( ent->s.number
  4718. && ent->NPC
  4719. && ent->client->ps.forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_0 )//ent->s.weapon == WP_SABER )
  4720. {//force-jumper landed on someone
  4721. //don't jump off, too many ledges, plus looks weird
  4722. if ( groundEnt->client->playerTeam != ent->client->playerTeam )
  4723. {//don't knock down own guys
  4724. forceKnockdown = (qboolean)(Q_irand( 0, RANK_CAPTAIN+4 )<ent->NPC->rank);
  4725. }
  4726. //now what... push the groundEnt out of the way?
  4727. if ( !ent->client->ps.velocity[0]
  4728. && !ent->client->ps.velocity[1] )
  4729. {//not moving, shove us a little
  4730. vec3_t slideFwd;
  4731. AngleVectors( ent->client->ps.viewangles, slideFwd, NULL, NULL );
  4732. slideFwd[2] = 0.0f;
  4733. VectorNormalize( slideFwd );
  4734. ent->client->ps.velocity[0] = slideFwd[0]*10.0f;
  4735. ent->client->ps.velocity[1] = slideFwd[1]*10.0f;
  4736. }
  4737. //slide for a little
  4738. ent->client->ps.pm_flags |= PMF_TIME_NOFRICTION;
  4739. ent->client->ps.pm_time = 100;
  4740. }
  4741. else if ( ent->health > 0 )
  4742. {
  4743. if ( !PM_InRoll( &ent->client->ps )
  4744. && !PM_FlippingAnim( ent->client->ps.legsAnim ) )
  4745. {
  4746. if ( ent->s.number && ent->s.weapon == WP_SABER )
  4747. {
  4748. ent->client->ps.forceJumpCharge = 320;//FIXME: calc this intelligently?
  4749. }
  4750. else if ( !ucmd->upmove )
  4751. {//if not ducking (which should cause a roll), then jump
  4752. ucmd->upmove = 127;
  4753. }
  4754. if ( !ucmd->forwardmove && !ucmd->rightmove )
  4755. {// If not moving, don't want to jump straight up
  4756. //FIXME: trace for clear di?
  4757. if ( !Q_irand( 0, 3 ) )
  4758. {
  4759. ucmd->forwardmove = 127;
  4760. }
  4761. else if ( !Q_irand( 0, 3 ) )
  4762. {
  4763. ucmd->forwardmove = -127;
  4764. }
  4765. else if ( !Q_irand( 0, 1 ) )
  4766. {
  4767. ucmd->rightmove = 127;
  4768. }
  4769. else
  4770. {
  4771. ucmd->rightmove = -127;
  4772. }
  4773. }
  4774. if ( !ent->s.number && ucmd->upmove < 0 )
  4775. {//player who should roll- force it
  4776. int rollAnim = BOTH_ROLL_F;
  4777. if ( ucmd->forwardmove >= 0 )
  4778. {
  4779. rollAnim = BOTH_ROLL_F;
  4780. }
  4781. else if ( ucmd->forwardmove < 0 )
  4782. {
  4783. rollAnim = BOTH_ROLL_B;
  4784. }
  4785. else if ( ucmd->rightmove > 0 )
  4786. {
  4787. rollAnim = BOTH_ROLL_R;
  4788. }
  4789. else if ( ucmd->rightmove < 0 )
  4790. {
  4791. rollAnim = BOTH_ROLL_L;
  4792. }
  4793. NPC_SetAnim(ent,SETANIM_BOTH,rollAnim,SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD);
  4794. G_AddEvent( ent, EV_ROLL, 0 );
  4795. ent->client->ps.saberMove = LS_NONE;
  4796. }
  4797. }
  4798. }
  4799. else
  4800. {//a corpse? Shit
  4801. //Hmm, corpses should probably *always* knockdown...
  4802. forceKnockdown = qtrue;
  4803. ent->clipmask &= ~CONTENTS_BODY;
  4804. }
  4805. //FIXME: need impact sound event
  4806. GEntity_PainFunc( groundEnt, ent, ent, groundEnt->currentOrigin, 0, MOD_CRUSH );
  4807. if ( !forceKnockdown
  4808. && groundEnt->client->NPC_class == CLASS_DESANN
  4809. && ent->client->NPC_class != CLASS_LUKE )
  4810. {//can't knock down desann unless you're luke
  4811. //FIXME: should he smack you away like Galak Mech?
  4812. }
  4813. else if ( forceKnockdown //forced
  4814. || ent->client->NPC_class == CLASS_DESANN //desann always knocks people down
  4815. || ( ( (groundEnt->s.number&&(groundEnt->s.weapon!=WP_SABER||!groundEnt->NPC||groundEnt->NPC->rank<Q_irand(RANK_CIVILIAN,RANK_CAPTAIN+1))) //an NPC who is either not a saber user or passed the rank-based probability test
  4816. || ((!ent->s.number||G_ControlledByPlayer(groundEnt)) && !Q_irand( 0, 3 )&&cg.renderingThirdPerson&&!cg.zoomMode) )//or a player in third person, 25% of the time
  4817. && groundEnt->client->playerTeam != ent->client->playerTeam//and not on the same team
  4818. && ent->client->ps.legsAnim != BOTH_JUMPATTACK6 ) )//not in the sideways-spinning jump attack
  4819. {
  4820. int knockAnim = BOTH_KNOCKDOWN1;
  4821. if ( PM_CrouchAnim( groundEnt->client->ps.legsAnim ) )
  4822. {//knockdown from crouch
  4823. knockAnim = BOTH_KNOCKDOWN4;
  4824. }
  4825. else
  4826. {
  4827. vec3_t gEFwd, gEAngles = {0,groundEnt->client->ps.viewangles[YAW],0};
  4828. AngleVectors( gEAngles, gEFwd, NULL, NULL );
  4829. if ( DotProduct( ent->client->ps.velocity, gEFwd ) > 50 )
  4830. {//pushing him forward
  4831. knockAnim = BOTH_KNOCKDOWN3;
  4832. }
  4833. }
  4834. NPC_SetAnim( groundEnt, SETANIM_BOTH, knockAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  4835. }
  4836. }
  4837. }
  4838. }
  4839. }
  4840. client = ent->client;
  4841. // mark the time, so the connection sprite can be removed
  4842. client->lastCmdTime = level.time;
  4843. client->pers.lastCommand = *ucmd;
  4844. // sanity check the command time to prevent speedup cheating
  4845. if ( ucmd->serverTime > level.time + 200 )
  4846. {
  4847. ucmd->serverTime = level.time + 200;
  4848. }
  4849. if ( ucmd->serverTime < level.time - 1000 )
  4850. {
  4851. ucmd->serverTime = level.time - 1000;
  4852. }
  4853. msec = ucmd->serverTime - client->ps.commandTime;
  4854. if ( msec < 1 )
  4855. {
  4856. msec = 1;
  4857. }
  4858. if ( msec > 200 )
  4859. {
  4860. msec = 200;
  4861. }
  4862. if ( client->noclip )
  4863. {
  4864. client->ps.pm_type = PM_NOCLIP;
  4865. }
  4866. else if ( client->ps.stats[STAT_HEALTH] <= 0 )
  4867. {
  4868. client->ps.pm_type = PM_DEAD;
  4869. }
  4870. else
  4871. {
  4872. client->ps.pm_type = PM_NORMAL;
  4873. }
  4874. //FIXME: if global gravity changes this should update everyone's personal gravity...
  4875. if ( !(ent->svFlags & SVF_CUSTOM_GRAVITY) )
  4876. {
  4877. if (ent->client->inSpaceIndex)
  4878. { //in space, so no gravity...
  4879. client->ps.gravity = 0.0f;
  4880. }
  4881. else
  4882. {
  4883. client->ps.gravity = g_gravity->value;
  4884. }
  4885. }
  4886. if (!USENEWNAVSYSTEM || ent->s.number==0)
  4887. {
  4888. ClientAlterSpeed(ent, ucmd, controlledByPlayer, 0);
  4889. }
  4890. //FIXME: need to do this before check to avoid walls and cliffs (or just cliffs?)
  4891. BG_AddPushVecToUcmd( ent, ucmd );
  4892. G_CheckClampUcmd( ent, ucmd );
  4893. WP_ForcePowersUpdate( ent, ucmd );
  4894. //if we have the saber in hand, check for starting a block to reflect shots
  4895. if ( ent->s.number < MAX_CLIENTS//player
  4896. || ( ent->NPC && G_JediInNormalAI( ent ) ) )//NPC jedi not in a special AI mode
  4897. {
  4898. WP_SaberStartMissileBlockCheck( ent, ucmd );
  4899. }
  4900. // Update the position of the saber, and check to see if we're throwing it
  4901. if ( client->ps.saberEntityNum != ENTITYNUM_NONE )
  4902. {
  4903. int updates = 1;
  4904. if ( ent->NPC )
  4905. {
  4906. updates = 3;//simulate player update rate?
  4907. }
  4908. for ( int update = 0; update < updates; update++ )
  4909. {
  4910. WP_SaberUpdate( ent, ucmd );
  4911. }
  4912. }
  4913. //NEED to do this every frame, since these overrides do not go into the save/load data
  4914. if ( ent->client && ent->s.m_iVehicleNum != 0 && !ent->s.number && !MatrixMode)
  4915. {//FIXME: extern and read from g_vehicleInfo?
  4916. Vehicle_t *pPlayerVeh = ent->owner->m_pVehicle;
  4917. if ( pPlayerVeh && pPlayerVeh->m_pVehicleInfo->cameraOverride )
  4918. {
  4919. // Vehicle Camera Overrides
  4920. //--------------------------
  4921. cg.overrides.active |= ( CG_OVERRIDE_3RD_PERSON_RNG | CG_OVERRIDE_FOV | CG_OVERRIDE_3RD_PERSON_VOF | CG_OVERRIDE_3RD_PERSON_POF );
  4922. cg.overrides.thirdPersonRange = pPlayerVeh->m_pVehicleInfo->cameraRange;
  4923. cg.overrides.fov = pPlayerVeh->m_pVehicleInfo->cameraFOV;
  4924. cg.overrides.thirdPersonVertOffset = pPlayerVeh->m_pVehicleInfo->cameraVertOffset;
  4925. cg.overrides.thirdPersonPitchOffset = pPlayerVeh->m_pVehicleInfo->cameraPitchOffset;
  4926. if ( pPlayerVeh->m_pVehicleInfo->cameraAlpha )
  4927. {
  4928. cg.overrides.active |= CG_OVERRIDE_3RD_PERSON_APH;
  4929. }
  4930. // If In A Speeder (NOT DURING TURBO)
  4931. //------------------------------------
  4932. if ((level.time>pPlayerVeh->m_iTurboTime) && pPlayerVeh->m_pVehicleInfo->type==VH_SPEEDER)
  4933. {
  4934. // If Using Strafe And Use Keys
  4935. //------------------------------
  4936. if ((pPlayerVeh->m_ucmd.rightmove!=0) &&
  4937. // (pPlayerVeh->m_pParentEntity->client->ps.speed>=0) &&
  4938. (pPlayerVeh->m_ucmd.buttons&BUTTON_USE)
  4939. )
  4940. {
  4941. cg.overrides.active |= CG_OVERRIDE_3RD_PERSON_ANG; // Turn On Angle Offset
  4942. cg.overrides.thirdPersonRange *= -2; // Camera In Front Of Player
  4943. cg.overrides.thirdPersonAngle = (pPlayerVeh->m_ucmd.rightmove>0)?(20):(-20);
  4944. }
  4945. // Auto Pullback Of Camera To Show Enemy
  4946. //---------------------------------------
  4947. else
  4948. {
  4949. cg.overrides.active &= ~CG_OVERRIDE_3RD_PERSON_ANG; // Turn Off Angle Offset
  4950. if (ent->enemy)
  4951. {
  4952. vec3_t actorDirection;
  4953. vec3_t enemyDirection;
  4954. AngleVectors(ent->currentAngles, actorDirection, 0, 0);
  4955. VectorSubtract(ent->enemy->currentOrigin, ent->currentOrigin, enemyDirection);
  4956. float enemyDistance = VectorNormalize(enemyDirection);
  4957. if (enemyDistance>cg.overrides.thirdPersonRange && enemyDistance<400 && DotProduct(actorDirection, enemyDirection)<-0.5f)
  4958. {
  4959. cg.overrides.thirdPersonRange = enemyDistance;
  4960. }
  4961. }
  4962. }
  4963. }
  4964. }
  4965. }
  4966. else if ( client->ps.eFlags&EF_IN_ATST )
  4967. {
  4968. cg.overrides.active |= (CG_OVERRIDE_3RD_PERSON_RNG|CG_OVERRIDE_3RD_PERSON_POF|CG_OVERRIDE_3RD_PERSON_VOF);
  4969. cg.overrides.thirdPersonRange = 240;
  4970. if ( cg_thirdPersonAutoAlpha.integer )
  4971. {
  4972. if ( ent->health > 0 && ent->client->ps.viewangles[PITCH] < 15 && ent->client->ps.viewangles[PITCH] > 0 )
  4973. {
  4974. cg.overrides.active |= CG_OVERRIDE_3RD_PERSON_APH;
  4975. if ( cg.overrides.thirdPersonAlpha > 0.525f )
  4976. {
  4977. cg.overrides.thirdPersonAlpha -= 0.025f;
  4978. }
  4979. else if ( cg.overrides.thirdPersonAlpha > 0.5f )
  4980. {
  4981. cg.overrides.thirdPersonAlpha = 0.5f;
  4982. }
  4983. }
  4984. else if ( cg.overrides.active&CG_OVERRIDE_3RD_PERSON_APH )
  4985. {
  4986. if ( cg.overrides.thirdPersonAlpha > cg_thirdPersonAlpha.value )
  4987. {
  4988. cg.overrides.active &= ~CG_OVERRIDE_3RD_PERSON_APH;
  4989. }
  4990. else if ( cg.overrides.thirdPersonAlpha < cg_thirdPersonAlpha.value-0.1f )
  4991. {
  4992. cg.overrides.thirdPersonAlpha += 0.1f;
  4993. }
  4994. else if ( cg.overrides.thirdPersonAlpha < cg_thirdPersonAlpha.value )
  4995. {
  4996. cg.overrides.thirdPersonAlpha = cg_thirdPersonAlpha.value;
  4997. cg.overrides.active &= ~CG_OVERRIDE_3RD_PERSON_APH;
  4998. }
  4999. }
  5000. }
  5001. if ( ent->client->ps.viewangles[PITCH] > 0 )
  5002. {
  5003. cg.overrides.thirdPersonPitchOffset = ent->client->ps.viewangles[PITCH]*-0.75;
  5004. cg.overrides.thirdPersonVertOffset = 300+ent->client->ps.viewangles[PITCH]*-10;
  5005. if ( cg.overrides.thirdPersonVertOffset < 0 )
  5006. {
  5007. cg.overrides.thirdPersonVertOffset = 0;
  5008. }
  5009. }
  5010. else if ( ent->client->ps.viewangles[PITCH] < 0 )
  5011. {
  5012. cg.overrides.thirdPersonPitchOffset = ent->client->ps.viewangles[PITCH]*-0.75;
  5013. cg.overrides.thirdPersonVertOffset = 300+ent->client->ps.viewangles[PITCH]*-5;
  5014. if ( cg.overrides.thirdPersonVertOffset > 300 )
  5015. {
  5016. cg.overrides.thirdPersonVertOffset = 300;
  5017. }
  5018. }
  5019. else
  5020. {
  5021. cg.overrides.thirdPersonPitchOffset = 0;
  5022. cg.overrides.thirdPersonVertOffset = 200;
  5023. }
  5024. }
  5025. //play/stop any looping sounds tied to controlled movement
  5026. G_CheckMovingLoopingSounds( ent, ucmd );
  5027. //remember your last angles
  5028. VectorCopy ( ent->client->ps.viewangles, ent->lastAngles );
  5029. // set up for pmove
  5030. oldEventSequence = client->ps.eventSequence;
  5031. memset( &pm, 0, sizeof(pm) );
  5032. pm.gent = ent;
  5033. pm.ps = &client->ps;
  5034. pm.cmd = *ucmd;
  5035. // pm.tracemask = MASK_PLAYERSOLID; // used differently for navgen
  5036. pm.tracemask = ent->clipmask;
  5037. pm.trace = gi.trace;
  5038. pm.pointcontents = gi.pointcontents;
  5039. pm.debugLevel = g_debugMove->integer;
  5040. pm.noFootsteps = 0;//( g_dmflags->integer & DF_NO_FOOTSTEPS ) > 0;
  5041. if ( ent->client && ent->NPC )
  5042. {
  5043. pm.cmd.weapon = ent->client->ps.weapon;
  5044. }
  5045. VectorCopy( client->ps.origin, oldOrigin );
  5046. #ifdef _XBOX
  5047. // if we're an npc then set the waterlevel
  5048. // based on the entity structure
  5049. // otherwise, zero it
  5050. if(ent->s.number != 0)
  5051. {
  5052. pm.waterlevel = ent->waterlevel;
  5053. pm.watertype = ent->watertype;
  5054. }
  5055. else
  5056. {
  5057. pm.waterlevel = 0;
  5058. pm.watertype = 0;
  5059. }
  5060. #endif
  5061. // perform a pmove
  5062. Pmove( &pm );
  5063. pm.gent = 0;
  5064. ProcessGenericCmd(ent, pm.cmd.generic_cmd);
  5065. // save results of pmove
  5066. if ( ent->client->ps.eventSequence != oldEventSequence )
  5067. {
  5068. ent->eventTime = level.time;
  5069. {
  5070. int seq;
  5071. seq = (ent->client->ps.eventSequence-1) & (MAX_PS_EVENTS-1);
  5072. ent->s.event = ent->client->ps.events[ seq ] | ( ( ent->client->ps.eventSequence & 3 ) << 8 );
  5073. ent->s.eventParm = ent->client->ps.eventParms[ seq ];
  5074. }
  5075. }
  5076. PlayerStateToEntityState( &ent->client->ps, &ent->s );
  5077. VectorCopy ( ent->currentOrigin, ent->lastOrigin );
  5078. #if 1
  5079. // use the precise origin for linking
  5080. VectorCopy( ent->client->ps.origin, ent->currentOrigin );
  5081. #else
  5082. //We don't use prediction anymore, so screw this
  5083. // use the snapped origin for linking so it matches client predicted versions
  5084. VectorCopy( ent->s.pos.trBase, ent->currentOrigin );
  5085. #endif
  5086. //Had to leave this in, some legacy code must still be using s.angles
  5087. //Shouldn't interfere with interpolation of angles, should it?
  5088. VectorCopy(ent->client->ps.viewangles , ent->currentAngles );
  5089. // if (pVeh)
  5090. // {
  5091. // gi.Printf("%d\n", ucmd->angles[2]);
  5092. // }
  5093. VectorCopy( pm.mins, ent->mins );
  5094. VectorCopy( pm.maxs, ent->maxs );
  5095. #ifdef _XBOX
  5096. // if this is the player then set the ent water level
  5097. // npcs are updated elsewhere
  5098. if(ent->s.number == 0)
  5099. {
  5100. ent->waterlevel = pm.waterlevel;
  5101. ent->watertype = pm.watertype;
  5102. }
  5103. #else
  5104. ent->waterlevel = pm.waterlevel;
  5105. ent->watertype = pm.watertype;
  5106. #endif
  5107. _VectorCopy( ucmd->angles, client->pers.cmd_angles );
  5108. // execute client events
  5109. ClientEvents( ent, oldEventSequence );
  5110. if ( pm.useEvent )
  5111. {
  5112. //TODO: Use
  5113. TryUse( ent );
  5114. }
  5115. // link entity now, after any personal teleporters have been used
  5116. gi.linkentity( ent );
  5117. ent->client->hiddenDist = 0;
  5118. if ( !ent->client->noclip )
  5119. {
  5120. G_TouchTriggersLerped( ent );
  5121. }
  5122. // touch other objects
  5123. ClientImpacts( ent, &pm );
  5124. // swap and latch button actions
  5125. client->oldbuttons = client->buttons;
  5126. client->buttons = ucmd->buttons;
  5127. client->latched_buttons |= client->buttons & ~client->oldbuttons;
  5128. // check for respawning
  5129. if ( client->ps.stats[STAT_HEALTH] <= 0 )
  5130. {
  5131. if( client->ps.clientNum == 0 )
  5132. {
  5133. Cbuf_ExecuteText(EXEC_NOW, "-moveup");
  5134. Cbuf_ExecuteText(EXEC_NOW, "-movedown");
  5135. Cbuf_ExecuteText(EXEC_NOW, "-hotswap1");
  5136. Cbuf_ExecuteText(EXEC_NOW, "-hotswap2");
  5137. Cbuf_ExecuteText(EXEC_NOW, "-hotswap3");
  5138. Cbuf_ExecuteText(EXEC_NOW, "-attack");
  5139. Cbuf_ExecuteText(EXEC_NOW, "-altattack");
  5140. Cbuf_ExecuteText(EXEC_NOW, "-use");
  5141. Cbuf_ExecuteText(EXEC_NOW, "-useforce");
  5142. }
  5143. // wait for the attack button to be pressed
  5144. if ( ent->NPC == NULL && level.time > client->respawnTime )
  5145. {
  5146. // don't allow respawn if they are still flying through the
  5147. // air, unless 10 extra seconds have passed, meaning something
  5148. // strange is going on, like the corpse is caught in a wind tunnel
  5149. /*
  5150. if ( level.time < client->respawnTime + 10000 )
  5151. {
  5152. if ( client->ps.groundEntityNum == ENTITYNUM_NONE )
  5153. {
  5154. return;
  5155. }
  5156. }
  5157. */
  5158. // pressing attack or use is the normal respawn method
  5159. //if ( ucmd->buttons & ( BUTTON_ATTACK ) )
  5160. //{
  5161. // respawn( ent );
  5162. //}
  5163. }
  5164. if ( ent
  5165. && !ent->s.number
  5166. && ent->enemy
  5167. && ent->enemy != ent
  5168. && ent->enemy->s.number < ENTITYNUM_WORLD
  5169. && ent->enemy->inuse
  5170. && !(cg.overrides.active&CG_OVERRIDE_3RD_PERSON_ANG) )
  5171. {//keep facing enemy
  5172. vec3_t deadDir;
  5173. float deadYaw;
  5174. VectorSubtract( ent->enemy->currentOrigin, ent->currentOrigin, deadDir );
  5175. deadYaw = AngleNormalize180( vectoyaw ( deadDir ) );
  5176. if ( deadYaw > ent->client->ps.stats[STAT_DEAD_YAW] + 1 )
  5177. {
  5178. ent->client->ps.stats[STAT_DEAD_YAW]++;
  5179. }
  5180. else if ( deadYaw < ent->client->ps.stats[STAT_DEAD_YAW] - 1 )
  5181. {
  5182. ent->client->ps.stats[STAT_DEAD_YAW]--;
  5183. }
  5184. else
  5185. {
  5186. ent->client->ps.stats[STAT_DEAD_YAW] = deadYaw;
  5187. }
  5188. }
  5189. return;
  5190. }
  5191. // perform once-a-second actions
  5192. ClientTimerActions( ent, msec );
  5193. ClientEndPowerUps( ent );
  5194. //try some idle anims on ent if getting no input and not moving for some time
  5195. G_CheckClientIdle( ent, ucmd );
  5196. extern void FF_XboxSaberRumble( void );
  5197. if(ent->s.number == 0) // player
  5198. {
  5199. if(ent->client->ps.saberLockTime > level.time)
  5200. {
  5201. FF_XboxSaberRumble();
  5202. }
  5203. }
  5204. }
  5205. /*
  5206. ==================
  5207. ClientThink
  5208. A new command has arrived from the client
  5209. ==================
  5210. */
  5211. extern void PM_CheckForceUseButton( gentity_t *ent, usercmd_t *ucmd );
  5212. extern qboolean PM_GentCantJump( gentity_t *gent );
  5213. extern qboolean PM_WeaponOkOnVehicle( int weapon );
  5214. void ClientThink( int clientNum, usercmd_t *ucmd ) {
  5215. gentity_t *ent;
  5216. qboolean restore_ucmd = qfalse;
  5217. usercmd_t sav_ucmd = {0};
  5218. ent = g_entities + clientNum;
  5219. if ( ent->s.number<MAX_CLIENTS )
  5220. {
  5221. if ( ent->client->ps.viewEntity > 0 && ent->client->ps.viewEntity < ENTITYNUM_WORLD )
  5222. {//you're controlling another NPC
  5223. gentity_t *controlled = &g_entities[ent->client->ps.viewEntity];
  5224. qboolean freed = qfalse;
  5225. if ( controlled->NPC
  5226. && controlled->NPC->controlledTime
  5227. && ent->client->ps.forcePowerLevel[FP_TELEPATHY] > FORCE_LEVEL_3 )
  5228. {//An NPC I'm controlling with mind trick
  5229. if ( controlled->NPC->controlledTime < level.time )
  5230. {//time's up!
  5231. G_ClearViewEntity( ent );
  5232. freed = qtrue;
  5233. }
  5234. }
  5235. else if ( controlled->client //an NPC
  5236. && PM_GentCantJump( controlled ) //that cannot jump
  5237. && controlled->client->moveType != MT_FLYSWIM ) //and does not use upmove to fly
  5238. {//these types use jump to get out
  5239. if ( ucmd->upmove > 0 )
  5240. {//jumping gets you out of it FIXME: check some other button instead... like ESCAPE... so you could even have total control over an NPC?
  5241. G_ClearViewEntity( ent );
  5242. ucmd->upmove = 0;//ucmd->buttons = 0;
  5243. //stop player from doing anything for a half second after
  5244. ent->aimDebounceTime = level.time + 500;
  5245. freed = qtrue;
  5246. }
  5247. }
  5248. if ( !freed )
  5249. {//still controlling, save off my ucmd and clear it for my actual run through pmove
  5250. restore_ucmd = qtrue;
  5251. memcpy( &sav_ucmd, ucmd, sizeof( usercmd_t ) );
  5252. memset( ucmd, 0, sizeof( usercmd_t ) );
  5253. //to keep pointing in same dir, need to set ucmd->angles
  5254. ucmd->angles[PITCH] = ANGLE2SHORT( ent->client->ps.viewangles[PITCH] ) - ent->client->ps.delta_angles[PITCH];
  5255. ucmd->angles[YAW] = ANGLE2SHORT( ent->client->ps.viewangles[YAW] ) - ent->client->ps.delta_angles[YAW];
  5256. ucmd->angles[ROLL] = 0;
  5257. if ( controlled->NPC )
  5258. {
  5259. VectorClear( controlled->client->ps.moveDir );
  5260. controlled->client->ps.speed = (sav_ucmd.buttons&BUTTON_WALKING)?controlled->NPC->stats.walkSpeed:controlled->NPC->stats.runSpeed;
  5261. }
  5262. }
  5263. else
  5264. {
  5265. ucmd->angles[PITCH] = ANGLE2SHORT( ent->client->ps.viewangles[PITCH] ) - ent->client->ps.delta_angles[PITCH];
  5266. ucmd->angles[YAW] = ANGLE2SHORT( ent->client->ps.viewangles[YAW] ) - ent->client->ps.delta_angles[YAW];
  5267. ucmd->angles[ROLL] = 0;
  5268. }
  5269. }
  5270. else if ( ent->client->NPC_class == CLASS_ATST )
  5271. {
  5272. if ( ucmd->upmove > 0 )
  5273. {//get out of ATST
  5274. GEntity_UseFunc( ent->activator, ent, ent );
  5275. ucmd->upmove = 0;//ucmd->buttons = 0;
  5276. }
  5277. }
  5278. PM_CheckForceUseButton( ent, ucmd );
  5279. }
  5280. Vehicle_t *pVeh = NULL;
  5281. // Rider logic.
  5282. // NOTE: Maybe this should be extracted into a RiderUpdate() within the vehicle.
  5283. if ( ( pVeh = G_IsRidingVehicle( ent ) ) != 0 )
  5284. {
  5285. // If we're still in the vehicle...
  5286. if ( pVeh->m_pVehicleInfo->UpdateRider( pVeh, ent, ucmd ) )
  5287. {
  5288. restore_ucmd = qtrue;
  5289. memcpy( &sav_ucmd, ucmd, sizeof( usercmd_t ) );
  5290. memset( ucmd, 0, sizeof( usercmd_t ) );
  5291. //to keep pointing in same dir, need to set ucmd->angles
  5292. //ucmd->angles[PITCH] = ANGLE2SHORT( ent->client->ps.viewangles[PITCH] ) - ent->client->ps.delta_angles[PITCH];
  5293. //ucmd->angles[YAW] = ANGLE2SHORT( ent->client->ps.viewangles[YAW] ) - ent->client->ps.delta_angles[YAW];
  5294. //ucmd->angles[ROLL] = 0;
  5295. ucmd->angles[PITCH] = sav_ucmd.angles[PITCH];
  5296. ucmd->angles[YAW] = sav_ucmd.angles[YAW];
  5297. ucmd->angles[ROLL] = sav_ucmd.angles[ROLL];
  5298. //if ( sav_ucmd.weapon != ent->client->ps.weapon && PM_WeaponOkOnVehicle( sav_ucmd.weapon ) )
  5299. {//trying to change weapons to a valid weapon for this vehicle, to preserve this weapon change command
  5300. ucmd->weapon = sav_ucmd.weapon;
  5301. }
  5302. //else
  5303. {//keep our current weapon
  5304. // ucmd->weapon = ent->client->ps.weapon;
  5305. // if ( ent->client->ps.weapon != WP_NONE )
  5306. {//not changing weapons and we are using one of our weapons, not using vehicle weapon
  5307. //so we actually want to do our fire weapon on us, not the vehicle
  5308. ucmd->buttons = (sav_ucmd.buttons&(BUTTON_ATTACK|BUTTON_ALT_ATTACK));
  5309. // sav_ucmd.buttons &= ~ucmd->buttons;
  5310. }
  5311. }
  5312. }
  5313. }
  5314. ent->client->usercmd = *ucmd;
  5315. // if ( !g_syncronousClients->integer )
  5316. {
  5317. ClientThink_real( ent, ucmd );
  5318. }
  5319. // If a vehicle, make sure to attach our driver and passengers here (after we pmove, which is done in Think_Real))
  5320. if ( ent->client && ent->client->NPC_class == CLASS_VEHICLE )
  5321. {
  5322. pVeh = ent->m_pVehicle;
  5323. pVeh->m_pVehicleInfo->AttachRiders( pVeh );
  5324. }
  5325. // ClientThink_real can end up freeing this ent, need to check
  5326. if ( restore_ucmd && ent->client )
  5327. {//restore ucmd for later so NPC you're controlling can refer to them
  5328. memcpy( &ent->client->usercmd, &sav_ucmd, sizeof( usercmd_t ) );
  5329. }
  5330. if ( ent->s.number )
  5331. {//NPCs drown, burn from lava, etc, also
  5332. P_WorldEffects( ent );
  5333. }
  5334. }
  5335. void ClientEndPowerUps( gentity_t *ent )
  5336. {
  5337. int i;
  5338. if ( ent == NULL || ent->client == NULL )
  5339. {
  5340. return;
  5341. }
  5342. // turn off any expired powerups
  5343. for ( i = 0 ; i < MAX_POWERUPS ; i++ )
  5344. {
  5345. if ( ent->client->ps.powerups[ i ] < level.time )
  5346. {
  5347. ent->client->ps.powerups[ i ] = 0;
  5348. }
  5349. }
  5350. }
  5351. /*
  5352. ==============
  5353. ClientEndFrame
  5354. Called at the end of each server frame for each connected client
  5355. A fast client will have multiple ClientThink for each ClientEdFrame,
  5356. while a slow client may have multiple ClientEndFrame between ClientThink.
  5357. ==============
  5358. */
  5359. void ClientEndFrame( gentity_t *ent )
  5360. {
  5361. //
  5362. // If the end of unit layout is displayed, don't give
  5363. // the player any normal movement attributes
  5364. //
  5365. // burn from lava, etc
  5366. P_WorldEffects (ent);
  5367. // apply all the damage taken this frame
  5368. P_DamageFeedback (ent);
  5369. // add the EF_CONNECTION flag if we haven't gotten commands recently
  5370. /*
  5371. if ( level.time - ent->client->lastCmdTime > 1000 ) {
  5372. ent->s.eFlags |= EF_CONNECTION;
  5373. } else {
  5374. ent->s.eFlags &= ~EF_CONNECTION;
  5375. }
  5376. */
  5377. ent->client->ps.stats[STAT_HEALTH] = ent->health; // FIXME: get rid of ent->health...
  5378. // G_SetClientSound (ent);
  5379. }