wp_saber.cpp 454 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777
  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 "anims.h"
  5. #include "b_local.h"
  6. #include "bg_local.h"
  7. #include "g_functions.h"
  8. #include "wp_saber.h"
  9. #include "g_vehicles.h"
  10. #include "../client/fffx.h"
  11. #define JK2_RAGDOLL_GRIPNOHEALTH
  12. #define MAX_SABER_VICTIMS 16
  13. static int victimEntityNum[MAX_SABER_VICTIMS];
  14. static float totalDmg[MAX_SABER_VICTIMS];
  15. static vec3_t dmgDir[MAX_SABER_VICTIMS];
  16. static vec3_t dmgSpot[MAX_SABER_VICTIMS];
  17. static float dmgFraction[MAX_SABER_VICTIMS];
  18. static int hitLoc[MAX_SABER_VICTIMS];
  19. static qboolean hitDismember[MAX_SABER_VICTIMS];
  20. static int hitDismemberLoc[MAX_SABER_VICTIMS];
  21. static vec3_t saberHitLocation, saberHitNormal={0,0,1.0};
  22. static float saberHitFraction;
  23. static float sabersCrossed;
  24. static int saberHitEntity;
  25. static int numVictims = 0;
  26. #define SABER_PITCH_HACK 90
  27. extern cvar_t *g_sex;
  28. extern cvar_t *g_timescale;
  29. extern cvar_t *g_dismemberment;
  30. extern cvar_t *g_debugSaberLock;
  31. extern cvar_t *g_saberLockRandomNess;
  32. extern cvar_t *d_slowmodeath;
  33. extern cvar_t *g_cheats;
  34. extern cvar_t *g_debugMelee;
  35. extern cvar_t *g_saberRestrictForce;
  36. extern qboolean Q3_TaskIDPending( gentity_t *ent, taskID_t taskType );
  37. extern qboolean G_ClearViewEntity( gentity_t *ent );
  38. extern void G_SetViewEntity( gentity_t *self, gentity_t *viewEntity );
  39. extern qboolean G_ControlledByPlayer( gentity_t *self );
  40. extern void G_AddVoiceEvent( gentity_t *self, int event, int speakDebounceTime );
  41. extern void CG_ChangeWeapon( int num );
  42. extern void G_AngerAlert( gentity_t *self );
  43. extern void G_ReflectMissile( gentity_t *ent, gentity_t *missile, vec3_t forward );
  44. extern int G_CheckLedgeDive( gentity_t *self, float checkDist, const vec3_t checkVel, qboolean tryOpposite, qboolean tryPerp );
  45. extern void G_BounceMissile( gentity_t *ent, trace_t *trace );
  46. extern qboolean G_PointInBounds( const vec3_t point, const vec3_t mins, const vec3_t maxs );
  47. extern void NPC_UseResponse( gentity_t *self, gentity_t *user, qboolean useWhenDone );
  48. extern void WP_FireDreadnoughtBeam( gentity_t *ent );
  49. extern void G_MissileImpacted( gentity_t *ent, gentity_t *other, vec3_t impactPos, vec3_t normal, int hitLoc=HL_NONE );
  50. extern evasionType_t Jedi_SaberBlockGo( gentity_t *self, usercmd_t *cmd, vec3_t pHitloc, vec3_t phitDir, gentity_t *incoming, float dist = 0.0f );
  51. extern void Jedi_RageStop( gentity_t *self );
  52. extern int PM_PickAnim( gentity_t *self, int minAnim, int maxAnim );
  53. extern void NPC_SetPainEvent( gentity_t *self );
  54. extern qboolean PM_SwimmingAnim( int anim );
  55. extern qboolean PM_InAnimForSaberMove( int anim, int saberMove );
  56. extern qboolean PM_SpinningSaberAnim( int anim );
  57. extern qboolean PM_SaberInSpecialAttack( int anim );
  58. extern qboolean PM_SaberInAttack( int move );
  59. extern qboolean PM_SaberInTransition( int move );
  60. extern qboolean PM_SaberInStart( int move );
  61. extern qboolean PM_SaberInTransitionAny( int move );
  62. extern qboolean PM_SaberInReturn( int move );
  63. extern qboolean PM_SaberInBounce( int move );
  64. extern qboolean PM_SaberInParry( int move );
  65. extern qboolean PM_SaberInKnockaway( int move );
  66. extern qboolean PM_SaberInBrokenParry( int move );
  67. extern qboolean PM_SpinningSaberAnim( int anim );
  68. extern saberMoveName_t PM_SaberBounceForAttack( int move );
  69. extern saberMoveName_t PM_BrokenParryForAttack( int move );
  70. extern saberMoveName_t PM_KnockawayForParry( int move );
  71. extern qboolean PM_FlippingAnim( int anim );
  72. extern qboolean PM_RollingAnim( int anim );
  73. extern qboolean PM_CrouchAnim( int anim );
  74. extern qboolean PM_SaberInIdle( int move );
  75. extern qboolean PM_SaberInReflect( int move );
  76. extern qboolean PM_InSpecialJump( int anim );
  77. extern qboolean PM_InKnockDown( playerState_t *ps );
  78. extern qboolean PM_ForceUsingSaberAnim( int anim );
  79. extern qboolean PM_SuperBreakLoseAnim( int anim );
  80. extern qboolean PM_SuperBreakWinAnim( int anim );
  81. extern qboolean PM_SaberLockBreakAnim( int anim );
  82. extern qboolean PM_InOnGroundAnim ( playerState_t *ps );
  83. extern qboolean PM_KnockDownAnim( int anim );
  84. extern qboolean PM_SaberInKata( saberMoveName_t saberMove );
  85. extern qboolean PM_StabDownAnim( int anim );
  86. extern int PM_PowerLevelForSaberAnim( playerState_t *ps, int saberNum = 0 );
  87. extern void PM_VelocityForSaberMove( playerState_t *ps, vec3_t throwDir );
  88. extern qboolean PM_VelocityForBlockedMove( playerState_t *ps, vec3_t throwDir );
  89. extern int Jedi_ReCalcParryTime( gentity_t *self, evasionType_t evasionType );
  90. extern qboolean Jedi_DodgeEvasion( gentity_t *self, gentity_t *shooter, trace_t *tr, int hitLoc );
  91. extern void Jedi_PlayDeflectSound( gentity_t *self );
  92. extern void Jedi_PlayBlockedPushSound( gentity_t *self );
  93. extern qboolean Jedi_WaitingAmbush( gentity_t *self );
  94. extern void Jedi_Ambush( gentity_t *self );
  95. extern qboolean Jedi_SaberBusy( gentity_t *self );
  96. extern qboolean Jedi_CultistDestroyer( gentity_t *self );
  97. extern qboolean Boba_Flying( gentity_t *self );
  98. extern void JET_FlyStart( gentity_t *self );
  99. extern void Boba_DoFlameThrower( gentity_t *self );
  100. extern Vehicle_t *G_IsRidingVehicle( gentity_t *ent );
  101. extern int SaberDroid_PowerLevelForSaberAnim( gentity_t *self );
  102. extern qboolean G_ValidEnemy( gentity_t *self, gentity_t *enemy );
  103. extern void G_StartMatrixEffect( gentity_t *ent, int meFlags = 0, int length = 1000, float timeScale = 0.0f, int spinTime = 0 );
  104. extern int PM_AnimLength( int index, animNumber_t anim );
  105. extern void G_Knockdown( gentity_t *self, gentity_t *attacker, const vec3_t pushDir, float strength, qboolean breakSaberLock );
  106. extern void G_KnockOffVehicle( gentity_t *pRider, gentity_t *self, qboolean bPull );
  107. extern qboolean PM_LockedAnim( int anim );
  108. extern qboolean Rosh_BeingHealed( gentity_t *self );
  109. extern qboolean G_OkayToLean( playerState_t *ps, usercmd_t *cmd, qboolean interruptOkay );
  110. int WP_AbsorbConversion(gentity_t *attacked, int atdAbsLevel, gentity_t *attacker, int atPower, int atPowerLevel, int atForceSpent);
  111. void WP_ForcePowerStart( gentity_t *self, forcePowers_t forcePower, int overrideAmt );
  112. void WP_ForcePowerStop( gentity_t *self, forcePowers_t forcePower );
  113. qboolean WP_ForcePowerUsable( gentity_t *self, forcePowers_t forcePower, int overrideAmt );
  114. void WP_SaberInFlightReflectCheck( gentity_t *self, usercmd_t *ucmd );
  115. void WP_SaberDrop( gentity_t *self, gentity_t *saber );
  116. qboolean WP_SaberLose( gentity_t *self, vec3_t throwDir );
  117. void WP_SaberReturn( gentity_t *self, gentity_t *saber );
  118. void WP_SaberBlock( gentity_t *saber, vec3_t hitloc, qboolean missleBlock );
  119. void WP_SaberBlockNonRandom( gentity_t *self, vec3_t hitloc, qboolean missileBlock );
  120. qboolean WP_ForcePowerAvailable( gentity_t *self, forcePowers_t forcePower, int overrideAmt );
  121. void WP_ForcePowerDrain( gentity_t *self, forcePowers_t forcePower, int overrideAmt );
  122. void WP_DeactivateSaber( gentity_t *self, qboolean clearLength = qfalse );
  123. qboolean FP_ForceDrainGrippableEnt( gentity_t *victim );
  124. extern cvar_t *g_saberAutoBlocking;
  125. extern cvar_t *g_saberRealisticCombat;
  126. extern cvar_t *g_saberDamageCapping;
  127. extern cvar_t *g_saberNewControlScheme;
  128. extern int g_crosshairEntNum;
  129. qboolean g_saberNoEffects = qfalse;
  130. int g_saberFlashTime = 0;
  131. vec3_t g_saberFlashPos = {0,0,0};
  132. int forcePowerDarkLight[NUM_FORCE_POWERS] = //0 == neutral
  133. { //nothing should be usable at rank 0..
  134. FORCE_LIGHTSIDE,//FP_HEAL,//instant
  135. 0,//FP_LEVITATION,//hold/duration
  136. 0,//FP_SPEED,//duration
  137. 0,//FP_PUSH,//hold/duration
  138. 0,//FP_PULL,//hold/duration
  139. FORCE_LIGHTSIDE,//FP_TELEPATHY,//instant
  140. FORCE_DARKSIDE,//FP_GRIP,//hold/duration
  141. FORCE_DARKSIDE,//FP_LIGHTNING,//hold/duration
  142. 0,//FP_SABERATTACK,
  143. 0,//FP_SABERDEFEND,
  144. 0,//FP_SABERTHROW,
  145. //new Jedi Academy powers
  146. FORCE_DARKSIDE,//FP_RAGE,//duration
  147. FORCE_LIGHTSIDE,//FP_PROTECT,//duration
  148. FORCE_LIGHTSIDE,//FP_ABSORB,//duration
  149. FORCE_DARKSIDE,//FP_DRAIN,//hold/duration
  150. 0,//FP_SEE,//duration
  151. //NUM_FORCE_POWERS
  152. };
  153. int forcePowerNeeded[NUM_FORCE_POWERS] =
  154. {
  155. 0,//FP_HEAL,//instant
  156. 10,//FP_LEVITATION,//hold/duration
  157. 50,//FP_SPEED,//duration
  158. 15,//FP_PUSH,//hold/duration
  159. 15,//FP_PULL,//hold/duration
  160. 20,//FP_TELEPATHY,//instant
  161. 1,//FP_GRIP,//hold/duration - FIXME: 30?
  162. 1,//FP_LIGHTNING,//hold/duration
  163. 20,//FP_SABERTHROW,
  164. 1,//FP_SABER_DEFENSE,
  165. 0,//FP_SABER_OFFENSE,
  166. //new Jedi Academy powers
  167. 50,//FP_RAGE,//duration - speed, invincibility and extra damage for short period, drains your health and leaves you weak and slow afterwards.
  168. 30,//FP_PROTECT,//duration - protect against physical/energy (level 1 stops blaster/energy bolts, level 2 stops projectiles, level 3 protects against explosions)
  169. 30,//FP_ABSORB,//duration - protect against dark force powers (grip, lightning, drain)
  170. 1,//FP_DRAIN,//hold/duration - drain force power for health
  171. 20//FP_SEE,//duration - detect/see hidden enemies
  172. //NUM_FORCE_POWERS
  173. };
  174. float forceJumpStrength[NUM_FORCE_POWER_LEVELS] =
  175. {
  176. JUMP_VELOCITY,//normal jump
  177. 420,
  178. 590,
  179. 840
  180. };
  181. float forceJumpHeight[NUM_FORCE_POWER_LEVELS] =
  182. {
  183. 32,//normal jump (+stepheight+crouchdiff = 66)
  184. 96,//(+stepheight+crouchdiff = 130)
  185. 192,//(+stepheight+crouchdiff = 226)
  186. 384//(+stepheight+crouchdiff = 418)
  187. };
  188. float forceJumpHeightMax[NUM_FORCE_POWER_LEVELS] =
  189. {
  190. 66,//normal jump (32+stepheight(18)+crouchdiff(24) = 74)
  191. 130,//(96+stepheight(18)+crouchdiff(24) = 138)
  192. 226,//(192+stepheight(18)+crouchdiff(24) = 234)
  193. 418//(384+stepheight(18)+crouchdiff(24) = 426)
  194. };
  195. float forcePushPullRadius[NUM_FORCE_POWER_LEVELS] =
  196. {
  197. 0,//none
  198. 384,//256,
  199. 448,//384,
  200. 512
  201. };
  202. float forcePushCone[NUM_FORCE_POWER_LEVELS] =
  203. {
  204. 1.0f,//none
  205. 1.0f,
  206. 0.8f,
  207. 0.6f
  208. };
  209. float forcePullCone[NUM_FORCE_POWER_LEVELS] =
  210. {
  211. 1.0f,//none
  212. 1.0f,
  213. 1.0f,
  214. 0.8f
  215. };
  216. float forceSpeedValue[NUM_FORCE_POWER_LEVELS] =
  217. {
  218. 1.0f,//none
  219. 0.75f,
  220. 0.5f,
  221. 0.25f
  222. };
  223. float forceSpeedRangeMod[NUM_FORCE_POWER_LEVELS] =
  224. {
  225. 0.0f,//none
  226. 30.0f,
  227. 45.0f,
  228. 60.0f
  229. };
  230. float forceSpeedFOVMod[NUM_FORCE_POWER_LEVELS] =
  231. {
  232. 0.0f,//none
  233. 20.0f,
  234. 30.0f,
  235. 40.0f
  236. };
  237. int forceGripDamage[NUM_FORCE_POWER_LEVELS] =
  238. {
  239. 0,//none
  240. 0,
  241. 6,
  242. 9
  243. };
  244. int mindTrickTime[NUM_FORCE_POWER_LEVELS] =
  245. {
  246. 0,//none
  247. 10000,//5000,
  248. 15000,//10000,
  249. 30000//15000
  250. };
  251. //NOTE: keep in synch with table below!!!
  252. int saberThrowDist[NUM_FORCE_POWER_LEVELS] =
  253. {
  254. 0,//none
  255. 256,
  256. 400,
  257. 400
  258. };
  259. //NOTE: keep in synch with table above!!!
  260. int saberThrowDistSquared[NUM_FORCE_POWER_LEVELS] =
  261. {
  262. 0,//none
  263. 65536,
  264. 160000,
  265. 160000
  266. };
  267. int parryDebounce[NUM_FORCE_POWER_LEVELS] =
  268. {
  269. 500,//if don't even have defense, can't use defense!
  270. 300,
  271. 150,
  272. 50
  273. };
  274. float saberAnimSpeedMod[NUM_FORCE_POWER_LEVELS] =
  275. {
  276. 0.0f,//if don't even have offense, can't use offense!
  277. 0.75f,
  278. 1.0f,
  279. 2.0f
  280. };
  281. stringID_table_t SaberStyleTable[] =
  282. {
  283. "NULL",SS_NONE,
  284. ENUM2STRING(SS_FAST),
  285. "fast",SS_FAST,
  286. ENUM2STRING(SS_MEDIUM),
  287. "medium",SS_MEDIUM,
  288. ENUM2STRING(SS_STRONG),
  289. "strong",SS_STRONG,
  290. ENUM2STRING(SS_DESANN),
  291. "desann",SS_DESANN,
  292. ENUM2STRING(SS_TAVION),
  293. "tavion",SS_TAVION,
  294. ENUM2STRING(SS_DUAL),
  295. "dual",SS_DUAL,
  296. ENUM2STRING(SS_STAFF),
  297. "staff",SS_STAFF,
  298. "", NULL
  299. };
  300. //SABER INITIALIZATION======================================================================
  301. void G_CreateG2AttachedWeaponModel( gentity_t *ent, const char *psWeaponModel, int boltNum, int weaponNum )
  302. {
  303. if (!psWeaponModel)
  304. {
  305. assert (psWeaponModel);
  306. return;
  307. }
  308. if ( ent->playerModel == -1 )
  309. {
  310. return;
  311. }
  312. if ( boltNum == -1 )
  313. {
  314. return;
  315. }
  316. if ( ent && ent->client && ent->client->NPC_class == CLASS_GALAKMECH )
  317. {//hack for galakmech, no weaponmodel
  318. ent->weaponModel[0] = ent->weaponModel[1] = -1;
  319. return;
  320. }
  321. if ( weaponNum < 0 || weaponNum >= MAX_INHAND_WEAPONS )
  322. {
  323. return;
  324. }
  325. char weaponModel[64];
  326. strcpy (weaponModel, psWeaponModel);
  327. if (char *spot = strstr(weaponModel, ".md3") ) {
  328. *spot = 0;
  329. spot = strstr(weaponModel, "_w");//i'm using the in view weapon array instead of scanning the item list, so put the _w back on
  330. if (!spot&&!strstr(weaponModel, "noweap"))
  331. {
  332. strcat (weaponModel, "_w");
  333. }
  334. strcat (weaponModel, ".glm"); //and change to ghoul2
  335. }
  336. // give us a saber model
  337. int wModelIndex = G_ModelIndex( weaponModel );
  338. if ( wModelIndex )
  339. {
  340. ent->weaponModel[weaponNum] = gi.G2API_InitGhoul2Model(ent->ghoul2, weaponModel, wModelIndex );
  341. if ( ent->weaponModel[weaponNum] != -1 )
  342. {
  343. // attach it to the hand
  344. gi.G2API_AttachG2Model(&ent->ghoul2[ent->weaponModel[weaponNum]], &ent->ghoul2[ent->playerModel],
  345. boltNum, ent->playerModel);
  346. // set up a bolt on the end so we can get where the sabre muzzle is - we can assume this is always bolt 0
  347. gi.G2API_AddBolt(&ent->ghoul2[ent->weaponModel[weaponNum]], "*flash");
  348. //gi.G2API_SetLodBias( &ent->ghoul2[ent->weaponModel[weaponNum]], 0 );
  349. }
  350. }
  351. }
  352. void WP_SaberAddG2SaberModels( gentity_t *ent, int specificSaberNum )
  353. {
  354. int saberNum = 0, maxSaber = 1;
  355. if ( specificSaberNum != -1 && specificSaberNum <= maxSaber )
  356. {
  357. saberNum = maxSaber = specificSaberNum;
  358. }
  359. for ( ; saberNum <= maxSaber; saberNum++ )
  360. {
  361. if ( ent->weaponModel[saberNum] > 0 )
  362. {//we already have a weapon model in this slot
  363. //remove it
  364. gi.G2API_SetSkin( &ent->ghoul2[ent->weaponModel[saberNum]], -1, 0 );
  365. gi.G2API_RemoveGhoul2Model( ent->ghoul2, ent->weaponModel[saberNum] );
  366. ent->weaponModel[saberNum] = -1;
  367. }
  368. if ( saberNum > 0 )
  369. {//second saber
  370. if ( !ent->client->ps.dualSabers
  371. || G_IsRidingVehicle( ent ) )
  372. {//only have one saber or riding a vehicle and can only use one saber
  373. return;
  374. }
  375. }
  376. else if ( saberNum == 0 )
  377. {//first saber
  378. if ( ent->client->ps.saberInFlight )
  379. {//it's still out there somewhere, don't add it
  380. //FIXME: call it back?
  381. continue;
  382. }
  383. }
  384. int handBolt = ((saberNum == 0) ? ent->handRBolt : ent->handLBolt);
  385. G_CreateG2AttachedWeaponModel( ent, ent->client->ps.saber[saberNum].model, handBolt, saberNum );
  386. if ( ent->client->ps.saber[saberNum].skin != NULL )
  387. {//if this saber has a customSkin, use it
  388. // lets see if it's out there
  389. int saberSkin = gi.RE_RegisterSkin( ent->client->ps.saber[saberNum].skin );
  390. if ( saberSkin )
  391. {
  392. // put it in the config strings
  393. // and set the ghoul2 model to use it
  394. gi.G2API_SetSkin( &ent->ghoul2[ent->weaponModel[saberNum]], G_SkinIndex( ent->client->ps.saber[saberNum].skin ), saberSkin );
  395. }
  396. }
  397. }
  398. }
  399. //----------------------------------------------------------
  400. void G_Throw( gentity_t *targ, const vec3_t newDir, float push )
  401. //----------------------------------------------------------
  402. {
  403. vec3_t kvel;
  404. float mass;
  405. if ( targ
  406. && targ->client
  407. && ( targ->client->NPC_class == CLASS_ATST
  408. || targ->client->NPC_class == CLASS_RANCOR
  409. || targ->client->NPC_class == CLASS_SAND_CREATURE ) )
  410. {//much to large to *ever* throw
  411. return;
  412. }
  413. if ( targ->physicsBounce > 0 ) //overide the mass
  414. {
  415. mass = targ->physicsBounce;
  416. }
  417. else
  418. {
  419. mass = 200;
  420. }
  421. if ( g_gravity->value > 0 )
  422. {
  423. VectorScale( newDir, g_knockback->value * (float)push / mass * 0.8, kvel );
  424. if ( !targ->client || targ->client->ps.groundEntityNum != ENTITYNUM_NONE )
  425. {//give them some z lift to get them off the ground
  426. kvel[2] = newDir[2] * g_knockback->value * (float)push / mass * 1.5;
  427. }
  428. }
  429. else
  430. {
  431. VectorScale( newDir, g_knockback->value * (float)push / mass, kvel );
  432. }
  433. if ( targ->client )
  434. {
  435. VectorAdd( targ->client->ps.velocity, kvel, targ->client->ps.velocity );
  436. }
  437. else if ( targ->s.pos.trType != TR_STATIONARY && targ->s.pos.trType != TR_LINEAR_STOP && targ->s.pos.trType != TR_NONLINEAR_STOP )
  438. {
  439. VectorAdd( targ->s.pos.trDelta, kvel, targ->s.pos.trDelta );
  440. VectorCopy( targ->currentOrigin, targ->s.pos.trBase );
  441. targ->s.pos.trTime = level.time;
  442. }
  443. // set the timer so that the other client can't cancel
  444. // out the movement immediately
  445. if ( targ->client && !targ->client->ps.pm_time )
  446. {
  447. int t;
  448. t = push * 2;
  449. if ( t < 50 )
  450. {
  451. t = 50;
  452. }
  453. if ( t > 200 )
  454. {
  455. t = 200;
  456. }
  457. targ->client->ps.pm_time = t;
  458. targ->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  459. }
  460. }
  461. int WP_SetSaberModel( gclient_t *client, class_t npcClass )
  462. {//FIXME: read from NPCs.cfg
  463. if ( client )
  464. {
  465. switch ( npcClass )
  466. {
  467. case CLASS_DESANN://Desann
  468. client->ps.saber[0].model = "models/weapons2/saber_desann/saber_w.glm";
  469. break;
  470. case CLASS_LUKE://Luke
  471. client->ps.saber[0].model = "models/weapons2/saber_luke/saber_w.glm";
  472. break;
  473. case CLASS_PLAYER://Kyle NPC and player
  474. case CLASS_KYLE://Kyle NPC and player
  475. client->ps.saber[0].model = "models/weapons2/saber/saber_w.glm";
  476. break;
  477. default://reborn and tavion and everyone else
  478. client->ps.saber[0].model = "models/weapons2/saber_reborn/saber_w.glm";
  479. break;
  480. }
  481. return ( G_ModelIndex( client->ps.saber[0].model ) );
  482. }
  483. else
  484. {
  485. switch ( npcClass )
  486. {
  487. case CLASS_DESANN://Desann
  488. return ( G_ModelIndex( "models/weapons2/saber_desann/saber_w.glm" ) );
  489. break;
  490. case CLASS_LUKE://Luke
  491. return ( G_ModelIndex( "models/weapons2/saber_luke/saber_w.glm" ) );
  492. break;
  493. case CLASS_PLAYER://Kyle NPC and player
  494. case CLASS_KYLE://Kyle NPC and player
  495. return ( G_ModelIndex( "models/weapons2/saber/saber_w.glm" ) );
  496. break;
  497. default://reborn and tavion and everyone else
  498. return ( G_ModelIndex( "models/weapons2/saber_reborn/saber_w.glm" ) );
  499. break;
  500. }
  501. }
  502. }
  503. void WP_SetSaberEntModelSkin( gentity_t *ent, gentity_t *saberent )
  504. {
  505. int saberModel = 0;
  506. qboolean newModel = qfalse;
  507. //FIXME: get saberModel from NPCs.cfg
  508. if ( !ent->client->ps.saber[0].model )
  509. {
  510. saberModel = WP_SetSaberModel( ent->client, ent->client->NPC_class );
  511. }
  512. else
  513. {
  514. //got saberModel from NPCs.cfg
  515. saberModel = G_ModelIndex( ent->client->ps.saber[0].model );
  516. }
  517. if ( saberModel && saberent->s.modelindex != saberModel )
  518. {
  519. if ( saberent->playerModel >= 0 )
  520. {//remove the old one, if there is one
  521. gi.G2API_RemoveGhoul2Model( saberent->ghoul2, saberent->playerModel );
  522. }
  523. //add the new one
  524. saberent->playerModel = gi.G2API_InitGhoul2Model( saberent->ghoul2, ent->client->ps.saber[0].model, saberModel);
  525. saberent->s.modelindex = saberModel;
  526. newModel = qtrue;
  527. }
  528. //set skin, too
  529. if ( ent->client->ps.saber[0].skin == NULL )
  530. {
  531. gi.G2API_SetSkin( &saberent->ghoul2[0], -1, 0 );
  532. }
  533. else
  534. {//if this saber has a customSkin, use it
  535. // lets see if it's out there
  536. int saberSkin = gi.RE_RegisterSkin( ent->client->ps.saber[0].skin );
  537. if ( saberSkin && (newModel || saberent->s.modelindex2 != saberSkin) )
  538. {
  539. // put it in the config strings
  540. // and set the ghoul2 model to use it
  541. gi.G2API_SetSkin( &saberent->ghoul2[0], G_SkinIndex( ent->client->ps.saber[0].skin ), saberSkin );
  542. saberent->s.modelindex2 = saberSkin;
  543. }
  544. }
  545. }
  546. void WP_SaberSwingSound( gentity_t *ent, int saberNum, swingType_t swingType )
  547. {
  548. int index = 1;
  549. if ( !ent || !ent->client )
  550. {
  551. return;
  552. }
  553. if ( swingType == SWING_FAST )
  554. {
  555. index = Q_irand( 1, 3 );
  556. }
  557. else if ( swingType == SWING_MEDIUM )
  558. {
  559. index = Q_irand( 4, 6 );
  560. }
  561. else if ( swingType == SWING_STRONG )
  562. {
  563. index = Q_irand( 7, 9 );
  564. }
  565. #ifdef _IMMERSION
  566. if ( ent->client->ps.saber[saberNum].type == SABER_SITH_SWORD )
  567. {
  568. G_SoundOnEnt( ent, CHAN_WEAPON, va( "sound/weapons/sword/swing%d.wav", Q_irand( 1, 4 ) ) );
  569. }
  570. else
  571. {
  572. G_SoundOnEnt( ent, CHAN_WEAPON, va( "sound/weapons/saber/saberhup%d.wav", index ) );
  573. }
  574. G_Force( ent, G_ForceIndex( va( "fffx/weapons/saber/saberhup%d", index ), FF_CHANNEL_WEAPON ) );
  575. #else
  576. if ( ent->client->ps.saber[saberNum].type == SABER_SITH_SWORD )
  577. {
  578. G_SoundOnEnt( ent, CHAN_WEAPON, va( "sound/weapons/sword/swing%d.wav", Q_irand( 1, 4 ) ) );
  579. }
  580. else
  581. {
  582. G_SoundOnEnt( ent, CHAN_WEAPON, va( "sound/weapons/saber/saberhup%d.wav", index ) );
  583. }
  584. #endif // _IMMERSION
  585. }
  586. void WP_SaberHitSound( gentity_t *ent, int saberNum )
  587. {
  588. int index = 1;
  589. if ( !ent || !ent->client )
  590. {
  591. return;
  592. }
  593. #ifdef _IMMERSION
  594. index = Q_irand( 1, 3 );
  595. if ( ent->client->ps.saber[saberNum].type == SABER_SITH_SWORD )
  596. {
  597. G_Sound( ent, G_SoundIndex( va( "sound/weapons/sword/stab%d.wav", Q_irand( 1, 4 ) ) ) );
  598. }
  599. else
  600. {
  601. G_Sound( ent, G_SoundIndex( va( "sound/weapons/saber/saberhit%d.wav", index ) ) );
  602. }
  603. G_Force( ent, G_ForceIndex( va( "fffx/weapons/saber/saberhit%d", index), FF_CHANNEL_WEAPON ) );
  604. #else
  605. if ( ent->client->ps.saber[saberNum].type == SABER_SITH_SWORD )
  606. {
  607. G_Sound( ent, G_SoundIndex( va( "sound/weapons/sword/stab%d.wav", Q_irand( 1, 4 ) ) ) );
  608. }
  609. else
  610. {
  611. G_Sound( ent, G_SoundIndex( va( "sound/weapons/saber/saberhit%d.wav", Q_irand( 1, 3 ) ) ) );
  612. }
  613. #endif // _IMMERSION
  614. if(ent->client && ent->client->ps.clientNum == 0)
  615. FF_Play(fffx_Laser1);
  616. }
  617. int WP_SaberInitBladeData( gentity_t *ent )
  618. {
  619. if ( !ent->client )
  620. {
  621. return 0;
  622. }
  623. if ( 1 )
  624. {
  625. VectorClear( ent->client->renderInfo.muzzlePoint );
  626. VectorClear( ent->client->renderInfo.muzzlePointOld );
  627. //VectorClear( ent->client->renderInfo.muzzlePointNext );
  628. VectorClear( ent->client->renderInfo.muzzleDir );
  629. VectorClear( ent->client->renderInfo.muzzleDirOld );
  630. //VectorClear( ent->client->renderInfo.muzzleDirNext );
  631. for ( int saberNum = 0; saberNum < MAX_SABERS; saberNum++ )
  632. {
  633. for ( int bladeNum = 0; bladeNum < MAX_BLADES; bladeNum++ )
  634. {
  635. VectorClear( ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint );
  636. VectorClear( ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePointOld );
  637. VectorClear( ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDir );
  638. VectorClear( ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDirOld );
  639. ent->client->ps.saber[saberNum].blade[bladeNum].lengthOld = ent->client->ps.saber[saberNum].blade[bladeNum].length = 0;
  640. if ( !ent->client->ps.saber[saberNum].blade[bladeNum].lengthMax )
  641. {
  642. if ( ent->client->NPC_class == CLASS_DESANN )
  643. {//longer saber
  644. ent->client->ps.saber[saberNum].blade[bladeNum].lengthMax = 48;
  645. }
  646. else if ( ent->client->NPC_class == CLASS_REBORN )
  647. {//shorter saber
  648. ent->client->ps.saber[saberNum].blade[bladeNum].lengthMax = 32;
  649. }
  650. else
  651. {//standard saber length
  652. ent->client->ps.saber[saberNum].blade[bladeNum].lengthMax = 40;
  653. }
  654. }
  655. }
  656. }
  657. ent->client->ps.saberLockEnemy = ENTITYNUM_NONE;
  658. ent->client->ps.saberLockTime = 0;
  659. if ( ent->s.number )
  660. {
  661. if ( !ent->client->ps.saberAnimLevel )
  662. {
  663. if ( ent->client->NPC_class == CLASS_DESANN )
  664. {
  665. ent->client->ps.saberAnimLevel = SS_DESANN;
  666. }
  667. else if ( ent->client->NPC_class == CLASS_TAVION )
  668. {
  669. ent->client->ps.saberAnimLevel = SS_TAVION;
  670. }
  671. else if ( ent->client->NPC_class == CLASS_ALORA )
  672. {
  673. ent->client->ps.saberAnimLevel = SS_DUAL;
  674. }
  675. //FIXME: CLASS_CULTIST instead of this Q_stricmpn?
  676. else if ( !Q_stricmpn( "cultist", ent->NPC_type, 7 ) )
  677. {//should already be set in the .npc file
  678. ent->client->ps.saberAnimLevel = Q_irand( SS_FAST, SS_STRONG );
  679. }
  680. else if ( ent->NPC && ent->client->playerTeam == TEAM_ENEMY && (ent->NPC->rank == RANK_CIVILIAN || ent->NPC->rank == RANK_LT_JG) )
  681. {//grunt and fencer always uses quick attacks
  682. ent->client->ps.saberAnimLevel = SS_FAST;
  683. }
  684. else if ( ent->NPC && ent->client->playerTeam == TEAM_ENEMY && (ent->NPC->rank == RANK_CREWMAN || ent->NPC->rank == RANK_ENSIGN) )
  685. {//acrobat & force-users always use medium attacks
  686. ent->client->ps.saberAnimLevel = SS_MEDIUM;
  687. }
  688. else if ( ent->client->playerTeam == TEAM_ENEMY && ent->client->NPC_class == CLASS_SHADOWTROOPER )
  689. {//shadowtroopers
  690. ent->client->ps.saberAnimLevel = Q_irand( SS_FAST, SS_STRONG );
  691. }
  692. else if ( ent->NPC && ent->client->playerTeam == TEAM_ENEMY && ent->NPC->rank == RANK_LT )
  693. {//boss always starts with strong attacks
  694. ent->client->ps.saberAnimLevel = SS_STRONG;
  695. }
  696. else if ( ent->client->NPC_class == CLASS_PLAYER )
  697. {
  698. ent->client->ps.saberAnimLevel = g_entities[0].client->ps.saberAnimLevel;
  699. }
  700. else
  701. {//?
  702. ent->client->ps.saberAnimLevel = Q_irand( SS_FAST, SS_STRONG );
  703. }
  704. }
  705. }
  706. else
  707. {
  708. if ( !ent->client->ps.saberAnimLevel )
  709. {//initialize, but don't reset
  710. if (ent->s.number < MAX_CLIENTS)
  711. {
  712. if (!ent->client->ps.saberStylesKnown)
  713. {
  714. ent->client->ps.saberStylesKnown = (1<<SS_MEDIUM);
  715. }
  716. if (ent->client->ps.saberStylesKnown & (1<<SS_FAST))
  717. {
  718. ent->client->ps.saberAnimLevel = SS_FAST;
  719. }
  720. else if (ent->client->ps.saberStylesKnown & (1<<SS_STRONG))
  721. {
  722. ent->client->ps.saberAnimLevel = SS_STRONG;
  723. }
  724. else
  725. {
  726. ent->client->ps.saberAnimLevel = SS_MEDIUM;
  727. }
  728. }
  729. else
  730. {
  731. ent->client->ps.saberAnimLevel = SS_MEDIUM;
  732. }
  733. }
  734. cg.saberAnimLevelPending = ent->client->ps.saberAnimLevel;
  735. if ( ent->client->sess.missionStats.weaponUsed[WP_SABER] <= 0 )
  736. {//let missionStats know that we actually do have the saber, even if we never use it
  737. ent->client->sess.missionStats.weaponUsed[WP_SABER] = 1;
  738. }
  739. }
  740. ent->client->ps.saberAttackChainCount = 0;
  741. if ( ent->client->ps.saberEntityNum <= 0 || ent->client->ps.saberEntityNum >= ENTITYNUM_WORLD )
  742. {//FIXME: if you do have a saber already, be sure to re-set the model if it's changed (say, via a script).
  743. gentity_t *saberent = G_Spawn();
  744. ent->client->ps.saberEntityNum = saberent->s.number;
  745. saberent->classname = "lightsaber";
  746. saberent->s.eType = ET_GENERAL;
  747. saberent->svFlags = SVF_USE_CURRENT_ORIGIN;
  748. saberent->s.weapon = WP_SABER;
  749. saberent->owner = ent;
  750. saberent->s.otherEntityNum = ent->s.number;
  751. //clear the enemy
  752. saberent->enemy = NULL;
  753. saberent->clipmask = MASK_SOLID | CONTENTS_LIGHTSABER;
  754. saberent->contents = CONTENTS_LIGHTSABER;//|CONTENTS_SHOTCLIP;
  755. VectorSet( saberent->mins, -3.0f, -3.0f, -3.0f );
  756. VectorSet( saberent->maxs, 3.0f, 3.0f, 3.0f );
  757. saberent->mass = 10;//necc?
  758. saberent->s.eFlags |= EF_NODRAW;
  759. saberent->svFlags |= SVF_NOCLIENT;
  760. /*
  761. Ghoul2 Insert Start
  762. */
  763. saberent->playerModel = -1;
  764. WP_SetSaberEntModelSkin( ent, saberent );
  765. // set up a bolt on the end so we can get where the sabre muzzle is - we can assume this is always bolt 0
  766. gi.G2API_AddBolt( &saberent->ghoul2[0], "*flash" );
  767. //gi.G2API_SetLodBias( &saberent->ghoul2[0], 0 );
  768. if ( ent->client->ps.dualSabers )
  769. {
  770. //int saber2 =
  771. G_ModelIndex( ent->client->ps.saber[1].model );
  772. //gi.G2API_InitGhoul2Model( saberent->ghoul2, ent->client->ps.saber[1].model, saber2 );
  773. // set up a bolt on the end so we can get where the sabre muzzle is - we can assume this is always bolt 0
  774. //gi.G2API_AddBolt( &saberent->ghoul2[0], "*flash" );
  775. //gi.G2API_SetLodBias( &saberent->ghoul2[0], 0 );
  776. }
  777. /*
  778. Ghoul2 Insert End
  779. */
  780. ent->client->ps.saberInFlight = qfalse;
  781. ent->client->ps.saberEntityDist = 0;
  782. ent->client->ps.saberEntityState = SES_LEAVING;
  783. ent->client->ps.saberMove = ent->client->ps.saberMoveNext = LS_NONE;
  784. //FIXME: need a think function to create alerts when turned on or is on, etc.
  785. }
  786. else
  787. {//already have one, might just be changing sabers, register the model and skin and use them if different from what we're using now.
  788. WP_SetSaberEntModelSkin( ent, &g_entities[ent->client->ps.saberEntityNum] );
  789. }
  790. }
  791. else
  792. {
  793. ent->client->ps.saberEntityNum = ENTITYNUM_NONE;
  794. ent->client->ps.saberInFlight = qfalse;
  795. ent->client->ps.saberEntityDist = 0;
  796. ent->client->ps.saberEntityState = SES_LEAVING;
  797. }
  798. if ( ent->client->ps.dualSabers )
  799. {
  800. return 2;
  801. }
  802. return 1;
  803. }
  804. void WP_SaberUpdateOldBladeData( gentity_t *ent )
  805. {
  806. if ( ent->client )
  807. {
  808. qboolean didEvent = qfalse;
  809. for ( int saberNum = 0; saberNum < 2; saberNum++ )
  810. {
  811. for ( int bladeNum = 0; bladeNum < ent->client->ps.saber[saberNum].numBlades; bladeNum++ )
  812. {
  813. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint, ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePointOld );
  814. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDir, ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDirOld );
  815. if ( !didEvent )
  816. {
  817. if ( ent->client->ps.saber[saberNum].blade[bladeNum].lengthOld <= 0 && ent->client->ps.saber[saberNum].blade[bladeNum].length > 0 )
  818. {//just turned on
  819. //do sound event
  820. vec3_t saberOrg;
  821. VectorCopy( g_entities[ent->client->ps.saberEntityNum].currentOrigin, saberOrg );
  822. if ( (!ent->client->ps.saberInFlight && ent->client->ps.groundEntityNum == ENTITYNUM_WORLD)//holding saber and on ground
  823. || g_entities[ent->client->ps.saberEntityNum].s.pos.trType == TR_STATIONARY )//saber out there somewhere and on ground
  824. {//a ground alert
  825. AddSoundEvent( ent, saberOrg, 256, AEL_SUSPICIOUS, qfalse, qtrue );
  826. }
  827. else
  828. {//an in-air alert
  829. AddSoundEvent( ent, saberOrg, 256, AEL_SUSPICIOUS );
  830. }
  831. didEvent = qtrue;
  832. }
  833. }
  834. ent->client->ps.saber[saberNum].blade[bladeNum].lengthOld = ent->client->ps.saber[saberNum].blade[bladeNum].length;
  835. }
  836. }
  837. VectorCopy( ent->client->renderInfo.muzzlePoint, ent->client->renderInfo.muzzlePointOld );
  838. VectorCopy( ent->client->renderInfo.muzzleDir, ent->client->renderInfo.muzzleDirOld );
  839. }
  840. }
  841. //SABER DAMAGE==============================================================================
  842. //SABER DAMAGE==============================================================================
  843. //SABER DAMAGE==============================================================================
  844. //SABER DAMAGE==============================================================================
  845. //SABER DAMAGE==============================================================================
  846. //SABER DAMAGE==============================================================================
  847. int WPDEBUG_SaberColor( saber_colors_t saberColor )
  848. {
  849. switch( (int)(saberColor) )
  850. {
  851. case SABER_RED:
  852. return 0x000000ff;
  853. break;
  854. case SABER_ORANGE:
  855. return 0x000088ff;
  856. break;
  857. case SABER_YELLOW:
  858. return 0x0000ffff;
  859. break;
  860. case SABER_GREEN:
  861. return 0x0000ff00;
  862. break;
  863. case SABER_BLUE:
  864. return 0x00ff0000;
  865. break;
  866. case SABER_PURPLE:
  867. return 0x00ff00ff;
  868. break;
  869. default:
  870. return 0x00ffffff;//white
  871. break;
  872. }
  873. }
  874. qboolean WP_GetSaberDeflectionAngle( gentity_t *attacker, gentity_t *defender )
  875. {
  876. vec3_t temp, att_SaberBase, att_StartPos, saberMidNext, att_HitDir, att_HitPos, def_BladeDir;
  877. float att_SaberHitLength, hitDot;
  878. if ( !attacker || !attacker->client || attacker->client->ps.saberInFlight || attacker->client->ps.SaberLength() <= 0 )
  879. {
  880. return qfalse;
  881. }
  882. if ( !defender || !defender->client || defender->client->ps.saberInFlight || defender->client->ps.SaberLength() <= 0 )
  883. {
  884. return qfalse;
  885. }
  886. if ( PM_SuperBreakLoseAnim( attacker->client->ps.torsoAnim )
  887. || PM_SuperBreakWinAnim( attacker->client->ps.torsoAnim ) )
  888. {
  889. return qfalse;
  890. }
  891. attacker->client->ps.saberBounceMove = LS_NONE;
  892. //get the attacker's saber base pos at time of impact
  893. VectorSubtract( attacker->client->renderInfo.muzzlePoint, attacker->client->renderInfo.muzzlePointOld, temp );
  894. VectorMA( attacker->client->renderInfo.muzzlePointOld, saberHitFraction, temp, att_SaberBase );
  895. //get the position along the length of the blade where the hit occured
  896. att_SaberHitLength = Distance( saberHitLocation, att_SaberBase )/attacker->client->ps.SaberLength();
  897. //now get the start of that midpoint in the swing and the actual impact point in the swing (shouldn't the latter just be saberHitLocation?)
  898. VectorMA( attacker->client->renderInfo.muzzlePointOld, att_SaberHitLength, attacker->client->renderInfo.muzzleDirOld, att_StartPos );
  899. VectorMA( attacker->client->renderInfo.muzzlePoint, att_SaberHitLength, attacker->client->renderInfo.muzzleDir, saberMidNext );
  900. VectorSubtract( saberMidNext, att_StartPos, att_HitDir );
  901. VectorMA( att_StartPos, saberHitFraction, att_HitDir, att_HitPos );
  902. VectorNormalize( att_HitDir );
  903. //get the defender's saber dir at time of impact
  904. VectorSubtract( defender->client->renderInfo.muzzleDirOld, defender->client->renderInfo.muzzleDir, temp );
  905. VectorMA( defender->client->renderInfo.muzzleDirOld, saberHitFraction, temp, def_BladeDir );
  906. //now compare
  907. hitDot = DotProduct( att_HitDir, def_BladeDir );
  908. if ( hitDot < 0.25f && hitDot > -0.25f )
  909. {//hit pretty much perpendicular, pop straight back
  910. attacker->client->ps.saberBounceMove = PM_SaberBounceForAttack( attacker->client->ps.saberMove );
  911. return qfalse;
  912. }
  913. else
  914. {//a deflection
  915. vec3_t att_Right, att_Up, att_DeflectionDir;
  916. float swingRDot, swingUDot;
  917. //get the direction of the deflection
  918. VectorScale( def_BladeDir, hitDot, att_DeflectionDir );
  919. //get our bounce straight back direction
  920. VectorScale( att_HitDir, -1.0f, temp );
  921. //add the bounce back and deflection
  922. VectorAdd( att_DeflectionDir, temp, att_DeflectionDir );
  923. //normalize the result to determine what direction our saber should bounce back toward
  924. VectorNormalize( att_DeflectionDir );
  925. //need to know the direction of the deflectoin relative to the attacker's facing
  926. VectorSet( temp, 0, attacker->client->ps.viewangles[YAW], 0 );//presumes no pitch!
  927. AngleVectors( temp, NULL, att_Right, att_Up );
  928. swingRDot = DotProduct( att_Right, att_DeflectionDir );
  929. swingUDot = DotProduct( att_Up, att_DeflectionDir );
  930. if ( swingRDot > 0.25f )
  931. {//deflect to right
  932. if ( swingUDot > 0.25f )
  933. {//deflect to top
  934. attacker->client->ps.saberBounceMove = LS_D1_TR;
  935. }
  936. else if ( swingUDot < -0.25f )
  937. {//deflect to bottom
  938. attacker->client->ps.saberBounceMove = LS_D1_BR;
  939. }
  940. else
  941. {//deflect horizontally
  942. attacker->client->ps.saberBounceMove = LS_D1__R;
  943. }
  944. }
  945. else if ( swingRDot < -0.25f )
  946. {//deflect to left
  947. if ( swingUDot > 0.25f )
  948. {//deflect to top
  949. attacker->client->ps.saberBounceMove = LS_D1_TL;
  950. }
  951. else if ( swingUDot < -0.25f )
  952. {//deflect to bottom
  953. attacker->client->ps.saberBounceMove = LS_D1_BL;
  954. }
  955. else
  956. {//deflect horizontally
  957. attacker->client->ps.saberBounceMove = LS_D1__L;
  958. }
  959. }
  960. else
  961. {//deflect in middle
  962. if ( swingUDot > 0.25f )
  963. {//deflect to top
  964. attacker->client->ps.saberBounceMove = LS_D1_T_;
  965. }
  966. else if ( swingUDot < -0.25f )
  967. {//deflect to bottom
  968. attacker->client->ps.saberBounceMove = LS_D1_B_;
  969. }
  970. else
  971. {//deflect horizontally? Well, no such thing as straight back in my face, so use top
  972. if ( swingRDot > 0 )
  973. {
  974. attacker->client->ps.saberBounceMove = LS_D1_TR;
  975. }
  976. else if ( swingRDot < 0 )
  977. {
  978. attacker->client->ps.saberBounceMove = LS_D1_TL;
  979. }
  980. else
  981. {
  982. attacker->client->ps.saberBounceMove = LS_D1_T_;
  983. }
  984. }
  985. }
  986. #ifndef FINAL_BUILD
  987. if ( d_saberCombat->integer )
  988. {
  989. gi.Printf( S_COLOR_BLUE"%s deflected from %s to %s\n", attacker->targetname, saberMoveData[attacker->client->ps.saberMove].name, saberMoveData[attacker->client->ps.saberBounceMove].name );
  990. }
  991. #endif
  992. return qtrue;
  993. }
  994. }
  995. void WP_SaberClearDamageForEntNum( int entityNum )
  996. {
  997. #ifndef FINAL_BUILD
  998. if ( d_saberCombat->integer )
  999. {
  1000. if ( entityNum )
  1001. {
  1002. Com_Printf( "clearing damage for entnum %d\n", entityNum );
  1003. }
  1004. }
  1005. #endif// FINAL_BUILD
  1006. if ( g_saberRealisticCombat->integer > 1 )
  1007. {
  1008. return;
  1009. }
  1010. for ( int i = 0; i < numVictims; i++ )
  1011. {
  1012. if ( victimEntityNum[i] == entityNum )
  1013. {
  1014. totalDmg[i] = 0;//no damage
  1015. hitLoc[i] = HL_NONE;
  1016. hitDismemberLoc[i] = HL_NONE;
  1017. hitDismember[i] = qfalse;
  1018. victimEntityNum[i] = ENTITYNUM_NONE;//like we never hit him
  1019. }
  1020. }
  1021. }
  1022. extern float damageModifier[];
  1023. extern float hitLocHealthPercentage[];
  1024. qboolean WP_SaberApplyDamage( gentity_t *ent, float baseDamage, int baseDFlags, qboolean brokenParry, saberType_t saberType, qboolean thrownSaber )
  1025. {
  1026. qboolean didDamage = qfalse;
  1027. gentity_t *victim;
  1028. int dFlags = baseDFlags;
  1029. float maxDmg;
  1030. if ( !numVictims )
  1031. {
  1032. return qfalse;
  1033. }
  1034. for ( int i = 0; i < numVictims; i++ )
  1035. {
  1036. dFlags = baseDFlags|DAMAGE_DEATH_KNOCKBACK|DAMAGE_NO_HIT_LOC;
  1037. if ( victimEntityNum[i] != ENTITYNUM_NONE && &g_entities[victimEntityNum[i]] != NULL )
  1038. { // Don't bother with this damage if the fraction is higher than the saber's fraction
  1039. if ( dmgFraction[i] < saberHitFraction || brokenParry )
  1040. {
  1041. victim = &g_entities[victimEntityNum[i]];
  1042. if ( !victim )
  1043. {
  1044. continue;
  1045. }
  1046. if ( victim->e_DieFunc == dieF_maglock_die )
  1047. {//*sigh*, special check for maglocks
  1048. vec3_t testFrom;
  1049. if ( ent->client->ps.saberInFlight )
  1050. {
  1051. VectorCopy( g_entities[ent->client->ps.saberEntityNum].currentOrigin, testFrom );
  1052. }
  1053. else
  1054. {
  1055. VectorCopy( ent->currentOrigin, testFrom );
  1056. }
  1057. testFrom[2] = victim->currentOrigin[2];
  1058. trace_t testTrace;
  1059. gi.trace( &testTrace, testFrom, vec3_origin, vec3_origin, victim->currentOrigin, ent->s.number, MASK_SHOT );
  1060. if ( testTrace.entityNum != victim->s.number )
  1061. {//can only damage maglocks if have a clear trace to the thing's origin
  1062. continue;
  1063. }
  1064. }
  1065. if ( totalDmg[i] > 0 )
  1066. {//actually want to do *some* damage here
  1067. if ( victim->client
  1068. && victim->client->NPC_class==CLASS_WAMPA
  1069. && victim->activator == ent )
  1070. {
  1071. }
  1072. else if ( PM_SuperBreakWinAnim( ent->client->ps.torsoAnim )
  1073. || PM_StabDownAnim( ent->client->ps.torsoAnim ) )
  1074. {//never cap the superbreak wins
  1075. }
  1076. else
  1077. {
  1078. if ( victim->client
  1079. && (victim->s.weapon == WP_SABER || (victim->client->NPC_class==CLASS_REBORN) || (victim->client->NPC_class==CLASS_WAMPA))
  1080. && !g_saberRealisticCombat->integer )
  1081. {//dmg vs other saber fighters is modded by hitloc and capped
  1082. totalDmg[i] *= damageModifier[hitLoc[i]];
  1083. if ( hitLoc[i] == HL_NONE )
  1084. {
  1085. maxDmg = 33*baseDamage;
  1086. }
  1087. else
  1088. {
  1089. maxDmg = 50*hitLocHealthPercentage[hitLoc[i]]*baseDamage;//*victim->client->ps.stats[STAT_MAX_HEALTH]*2.0f;
  1090. }
  1091. if ( maxDmg < totalDmg[i] )
  1092. {
  1093. totalDmg[i] = maxDmg;
  1094. }
  1095. //dFlags |= DAMAGE_NO_HIT_LOC;
  1096. }
  1097. //clamp the dmg
  1098. if ( victim->s.weapon != WP_SABER )
  1099. {//clamp the dmg between 25 and maxhealth
  1100. /*
  1101. if ( totalDmg[i] > victim->max_health )
  1102. {
  1103. totalDmg[i] = victim->max_health;
  1104. }
  1105. else */if ( totalDmg[i] < 25 )
  1106. {
  1107. totalDmg[i] = 25;
  1108. }
  1109. if ( totalDmg[i] > 100 )//+(50*g_spskill->integer) )
  1110. {//clamp using same adjustment as in NPC_Begin
  1111. totalDmg[i] = 100;//+(50*g_spskill->integer);
  1112. }
  1113. }
  1114. else
  1115. {//clamp the dmg between 5 and 100
  1116. if ( !victim->s.number && totalDmg[i] > 50 )
  1117. {//never do more than half full health damage to player
  1118. //prevents one-hit kills
  1119. totalDmg[i] = 50;
  1120. }
  1121. else if ( totalDmg[i] > 100 )
  1122. {
  1123. totalDmg[i] = 100;
  1124. }
  1125. else
  1126. {
  1127. if ( totalDmg[i] < 5 )
  1128. {
  1129. totalDmg[i] = 5;
  1130. }
  1131. }
  1132. }
  1133. }
  1134. if ( totalDmg[i] > 0 )
  1135. {
  1136. gentity_t *inflictor = ent;
  1137. didDamage = qtrue;
  1138. if ( baseDamage <= 0.1f )
  1139. {//just get their attention?
  1140. dFlags |= DAMAGE_NO_DAMAGE;
  1141. }
  1142. if( victim->client )
  1143. {
  1144. if ( victim->client->ps.pm_time > 0 && victim->client->ps.pm_flags & PMF_TIME_KNOCKBACK && victim->client->ps.velocity[2] > 0 )
  1145. {//already being knocked around
  1146. dFlags |= DAMAGE_NO_KNOCKBACK;
  1147. }
  1148. if ( g_dismemberment->integer >= 11381138 || g_saberRealisticCombat->integer )
  1149. {
  1150. dFlags |= DAMAGE_DISMEMBER;
  1151. if ( hitDismember[i] )
  1152. {
  1153. victim->client->dismembered = false;
  1154. }
  1155. }
  1156. else if ( hitDismember[i] )
  1157. {
  1158. dFlags |= DAMAGE_DISMEMBER;
  1159. }
  1160. if ( baseDamage <= 1.0f )
  1161. {//very mild damage
  1162. if ( victim->s.number == 0 || victim->client->ps.weapon == WP_SABER || victim->client->NPC_class == CLASS_GALAKMECH )
  1163. {//if it's the player or a saber-user, don't kill them with this blow
  1164. dFlags |= DAMAGE_NO_KILL;
  1165. }
  1166. }
  1167. }
  1168. else
  1169. {
  1170. if ( victim->takedamage )
  1171. {//some other breakable thing
  1172. //create a flash here
  1173. g_saberFlashTime = level.time-50;
  1174. VectorCopy( dmgSpot[i], g_saberFlashPos );
  1175. }
  1176. }
  1177. if ( !PM_SuperBreakWinAnim( ent->client->ps.torsoAnim )
  1178. && !PM_StabDownAnim( ent->client->ps.torsoAnim )
  1179. && !g_saberRealisticCombat->integer
  1180. && g_saberDamageCapping->integer )
  1181. {//never cap the superbreak wins
  1182. if ( victim->client
  1183. && victim->s.number >= MAX_CLIENTS )
  1184. {
  1185. if ( victim->client->NPC_class == CLASS_SHADOWTROOPER
  1186. || ( victim->NPC && (victim->NPC->aiFlags&NPCAI_BOSS_CHARACTER) ) )
  1187. {//hit a boss character
  1188. int maxDmg = ((3-g_spskill->integer)*5)+10;
  1189. if ( totalDmg[i] > maxDmg )
  1190. {
  1191. totalDmg[i] = maxDmg;
  1192. }
  1193. }
  1194. else if ( victim->client->ps.weapon == WP_SABER
  1195. || victim->client->NPC_class == CLASS_REBORN
  1196. || victim->client->NPC_class == CLASS_JEDI )
  1197. {//hit a non-boss saber-user
  1198. int maxDmg = ((3-g_spskill->integer)*15)+30;
  1199. if ( totalDmg[i] > maxDmg )
  1200. {
  1201. totalDmg[i] = maxDmg;
  1202. }
  1203. }
  1204. }
  1205. if ( victim->s.number < MAX_CLIENTS
  1206. && ent->NPC )
  1207. {
  1208. if ( (ent->NPC->aiFlags&NPCAI_BOSS_CHARACTER)
  1209. || (ent->NPC->aiFlags&NPCAI_SUBBOSS_CHARACTER)
  1210. || ent->client->NPC_class == CLASS_SHADOWTROOPER )
  1211. {//player hit by a boss character
  1212. int maxDmg = ((g_spskill->integer+1)*4)+3;
  1213. if ( totalDmg[i] > maxDmg )
  1214. {
  1215. totalDmg[i] = maxDmg;
  1216. }
  1217. }
  1218. else if ( g_spskill->integer < 3 ) //was < 2
  1219. {//player hit by any enemy //on easy or medium?
  1220. int maxDmg = ((g_spskill->integer+1)*10)+20;
  1221. if ( totalDmg[i] > maxDmg )
  1222. {
  1223. totalDmg[i] = maxDmg;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. //victim->hitLoc = hitLoc[i];
  1229. dFlags |= DAMAGE_NO_KNOCKBACK;//okay, let's try no knockback whatsoever...
  1230. dFlags &= ~DAMAGE_DEATH_KNOCKBACK;
  1231. if ( g_saberRealisticCombat->integer )
  1232. {
  1233. dFlags |= DAMAGE_NO_KNOCKBACK;
  1234. dFlags &= ~DAMAGE_DEATH_KNOCKBACK;
  1235. dFlags &= ~DAMAGE_NO_KILL;
  1236. }
  1237. if ( ent->client && !ent->s.number )
  1238. {
  1239. switch( hitLoc[i] )
  1240. {
  1241. case HL_FOOT_RT:
  1242. case HL_FOOT_LT:
  1243. case HL_LEG_RT:
  1244. case HL_LEG_LT:
  1245. ent->client->sess.missionStats.legAttacksCnt++;
  1246. break;
  1247. case HL_WAIST:
  1248. case HL_BACK_RT:
  1249. case HL_BACK_LT:
  1250. case HL_BACK:
  1251. case HL_CHEST_RT:
  1252. case HL_CHEST_LT:
  1253. case HL_CHEST:
  1254. ent->client->sess.missionStats.torsoAttacksCnt++;
  1255. break;
  1256. case HL_ARM_RT:
  1257. case HL_ARM_LT:
  1258. case HL_HAND_RT:
  1259. case HL_HAND_LT:
  1260. ent->client->sess.missionStats.armAttacksCnt++;
  1261. break;
  1262. default:
  1263. ent->client->sess.missionStats.otherAttacksCnt++;
  1264. break;
  1265. }
  1266. }
  1267. if ( saberType == SABER_SITH_SWORD )
  1268. {//do knockback
  1269. dFlags &= ~(DAMAGE_NO_KNOCKBACK|DAMAGE_DEATH_KNOCKBACK);
  1270. }
  1271. if ( thrownSaber )
  1272. {
  1273. inflictor = &g_entities[ent->client->ps.saberEntityNum];
  1274. }
  1275. G_Damage( victim, inflictor, ent, dmgDir[i], dmgSpot[i], ceil(totalDmg[i]), dFlags, MOD_SABER, hitDismemberLoc[i] );
  1276. #ifndef FINAL_BUILD
  1277. if ( d_saberCombat->integer )
  1278. {
  1279. if ( (dFlags&DAMAGE_NO_DAMAGE) )
  1280. {
  1281. gi.Printf( S_COLOR_RED"damage: fake, hitLoc %d\n", hitLoc[i] );
  1282. }
  1283. else
  1284. {
  1285. gi.Printf( S_COLOR_RED"damage: %4.2f, hitLoc %d\n", totalDmg[i], hitLoc[i] );
  1286. }
  1287. }
  1288. #endif
  1289. //do the effect
  1290. //G_PlayEffect( G_EffectIndex( "blood_sparks" ), dmgSpot[i], dmgDir[i] );
  1291. if ( ent->s.number == 0 )
  1292. {
  1293. AddSoundEvent( victim->owner, dmgSpot[i], 256, AEL_DISCOVERED );
  1294. AddSightEvent( victim->owner, dmgSpot[i], 512, AEL_DISCOVERED, 50 );
  1295. }
  1296. if ( ent->client )
  1297. {
  1298. if ( ent->enemy && ent->enemy == victim )
  1299. {//just so Jedi knows that he hit his enemy
  1300. ent->client->ps.saberEventFlags |= SEF_HITENEMY;
  1301. }
  1302. else
  1303. {
  1304. ent->client->ps.saberEventFlags |= SEF_HITOBJECT;
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. }
  1312. return didDamage;
  1313. }
  1314. void WP_SaberDamageAdd( float trDmg, int trVictimEntityNum, vec3_t trDmgDir, vec3_t trDmgSpot, float dmg, float fraction, int trHitLoc, qboolean trDismember, int trDismemberLoc )
  1315. {
  1316. int curVictim = 0;
  1317. if ( trVictimEntityNum < 0 || trVictimEntityNum >= ENTITYNUM_WORLD )
  1318. {
  1319. return;
  1320. }
  1321. if ( trDmg * dmg < 10.0f )
  1322. {//too piddly an amount of damage to really count?
  1323. //FIXME: but already did the effect, didn't we... sigh...
  1324. //return;
  1325. }
  1326. if ( trDmg )
  1327. {//did some damage to something
  1328. for ( int i = 0; i < numVictims; i++ )
  1329. {
  1330. if ( victimEntityNum[i] == trVictimEntityNum )
  1331. {//already hit this guy before
  1332. curVictim = i;
  1333. break;
  1334. }
  1335. }
  1336. if ( i == numVictims )
  1337. {//haven't hit his guy before
  1338. if ( numVictims + 1 >= MAX_SABER_VICTIMS )
  1339. {//can't add another victim at this time
  1340. return;
  1341. }
  1342. //add a new victim to the list
  1343. curVictim = numVictims;
  1344. victimEntityNum[numVictims++] = trVictimEntityNum;
  1345. }
  1346. float addDmg = trDmg*dmg;
  1347. if ( trHitLoc!=HL_NONE && (hitLoc[curVictim]==HL_NONE||hitLocHealthPercentage[trHitLoc]>hitLocHealthPercentage[hitLoc[curVictim]]) )
  1348. {//this hitLoc is more critical than the previous one this frame
  1349. hitLoc[curVictim] = trHitLoc;
  1350. }
  1351. totalDmg[curVictim] += addDmg;
  1352. if ( !VectorLengthSquared( dmgDir[curVictim] ) )
  1353. {
  1354. VectorCopy( trDmgDir, dmgDir[curVictim] );
  1355. }
  1356. if ( !VectorLengthSquared( dmgSpot[curVictim] ) )
  1357. {
  1358. VectorCopy( trDmgSpot, dmgSpot[curVictim] );
  1359. }
  1360. // Make sure we keep track of the fraction. Why?
  1361. // Well, if the saber hits something that stops it, the damage isn't done past that point.
  1362. dmgFraction[curVictim] = fraction;
  1363. if ( (trDismemberLoc != HL_NONE && hitDismemberLoc[curVictim] == HL_NONE)
  1364. || (!hitDismember[curVictim] && trDismember) )
  1365. {//either this is the first dismember loc we got or we got a loc before, but it wasn't a dismember loc, so take the new one
  1366. hitDismemberLoc[curVictim] = trDismemberLoc;
  1367. }
  1368. if ( trDismember )
  1369. {//we scored a dismemberment hit...
  1370. hitDismember[curVictim] = trDismember;
  1371. }
  1372. }
  1373. }
  1374. /*
  1375. WP_SabersIntersect
  1376. Breaks the two saber paths into 2 tris each and tests each tri for the first saber path against each of the other saber path's tris
  1377. FIXME: subdivide the arc into a consistant increment
  1378. FIXME: test the intersection to see if the sabers really did intersect (weren't going in the same direction and/or passed through same point at different times)?
  1379. */
  1380. extern qboolean tri_tri_intersect(vec3_t V0,vec3_t V1,vec3_t V2,vec3_t U0,vec3_t U1,vec3_t U2);
  1381. qboolean WP_SabersIntersect( gentity_t *ent1, int ent1SaberNum, int ent1BladeNum, gentity_t *ent2, qboolean checkDir )
  1382. {
  1383. vec3_t saberBase1, saberTip1, saberBaseNext1, saberTipNext1;
  1384. vec3_t saberBase2, saberTip2, saberBaseNext2, saberTipNext2;
  1385. int ent2SaberNum = 0, ent2BladeNum = 0;
  1386. vec3_t dir;
  1387. /*
  1388. #ifndef FINAL_BUILD
  1389. if ( d_saberCombat->integer )
  1390. {
  1391. gi.Printf( S_COLOR_GREEN"Doing precise saber intersection check\n" );
  1392. }
  1393. #endif
  1394. */
  1395. if ( !ent1 || !ent2 )
  1396. {
  1397. return qfalse;
  1398. }
  1399. if ( !ent1->client || !ent2->client )
  1400. {
  1401. return qfalse;
  1402. }
  1403. if ( ent1->client->ps.SaberLength() <= 0 || ent2->client->ps.SaberLength() <= 0 )
  1404. {
  1405. return qfalse;
  1406. }
  1407. for ( ent2SaberNum = 0; ent2SaberNum < MAX_SABERS; ent2SaberNum++ )
  1408. {
  1409. for ( ent2BladeNum = 0; ent2BladeNum < ent2->client->ps.saber[ent2SaberNum].numBlades; ent2BladeNum++ )
  1410. {
  1411. if ( ent2->client->ps.saber[ent2SaberNum].type != SABER_NONE
  1412. && ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].length > 0 )
  1413. {//valid saber and this blade is on
  1414. //if ( ent1->client->ps.saberInFlight )
  1415. {
  1416. VectorCopy( ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzlePointOld, saberBase1 );
  1417. VectorCopy( ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzlePoint, saberBaseNext1 );
  1418. VectorSubtract( ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzlePoint, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzlePointOld, dir );
  1419. VectorNormalize( dir );
  1420. VectorMA( saberBaseNext1, SABER_EXTRAPOLATE_DIST, dir, saberBaseNext1 );
  1421. VectorMA( saberBase1, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].length, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzleDirOld, saberTip1 );
  1422. VectorMA( saberBaseNext1, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].length, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzleDir, saberTipNext1 );
  1423. VectorSubtract( saberTipNext1, saberTip1, dir );
  1424. VectorNormalize( dir );
  1425. VectorMA( saberTipNext1, SABER_EXTRAPOLATE_DIST, dir, saberTipNext1 );
  1426. }
  1427. /*
  1428. else
  1429. {
  1430. VectorCopy( ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzlePoint, saberBase1 );
  1431. VectorCopy( ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzlePointNext, saberBaseNext1 );
  1432. VectorMA( saberBase1, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].length, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzleDir, saberTip1 );
  1433. VectorMA( saberBaseNext1, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].length, ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzleDirNext, saberTipNext1 );
  1434. }
  1435. */
  1436. //if ( ent2->client->ps.saberInFlight )
  1437. {
  1438. VectorCopy( ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzlePointOld, saberBase2 );
  1439. VectorCopy( ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzlePoint, saberBaseNext2 );
  1440. VectorSubtract( ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzlePoint, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzlePointOld, dir );
  1441. VectorNormalize( dir );
  1442. VectorMA( saberBaseNext2, SABER_EXTRAPOLATE_DIST, dir, saberBaseNext2 );
  1443. VectorMA( saberBase2, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].length, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzleDirOld, saberTip2 );
  1444. VectorMA( saberBaseNext2, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].length, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzleDir, saberTipNext2 );
  1445. VectorSubtract( saberTipNext2, saberTip2, dir );
  1446. VectorNormalize( dir );
  1447. VectorMA( saberTipNext2, SABER_EXTRAPOLATE_DIST, dir, saberTipNext2 );
  1448. }
  1449. /*
  1450. else
  1451. {
  1452. VectorCopy( ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzlePoint, saberBase2 );
  1453. VectorCopy( ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzlePointNext, saberBaseNext2 );
  1454. VectorMA( saberBase2, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].length, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzleDir, saberTip2 );
  1455. VectorMA( saberBaseNext2, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].length, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzleDirNext, saberTipNext2 );
  1456. }
  1457. */
  1458. if ( checkDir )
  1459. {//check the direction of the two swings to make sure the sabers are swinging towards each other
  1460. vec3_t saberDir1, saberDir2;
  1461. VectorSubtract( saberTipNext1, saberTip1, saberDir1 );
  1462. VectorSubtract( saberTipNext2, saberTip2, saberDir2 );
  1463. VectorNormalize( saberDir1 );
  1464. VectorNormalize( saberDir2 );
  1465. if ( DotProduct( saberDir1, saberDir2 ) > 0.6f )
  1466. {//sabers moving in same dir, probably didn't actually hit
  1467. continue;
  1468. }
  1469. //now check orientation of sabers, make sure they're not parallel or close to it
  1470. float dot = DotProduct( ent1->client->ps.saber[ent1SaberNum].blade[ent1BladeNum].muzzleDir, ent2->client->ps.saber[ent2SaberNum].blade[ent2BladeNum].muzzleDir );
  1471. if ( dot > 0.9f || dot < -0.9f )
  1472. {//too parallel to really block effectively?
  1473. continue;
  1474. }
  1475. }
  1476. if ( tri_tri_intersect( saberBase1, saberTip1, saberBaseNext1, saberBase2, saberTip2, saberBaseNext2 ) )
  1477. {
  1478. return qtrue;
  1479. }
  1480. if ( tri_tri_intersect( saberBase1, saberTip1, saberBaseNext1, saberBase2, saberTip2, saberTipNext2 ) )
  1481. {
  1482. return qtrue;
  1483. }
  1484. if ( tri_tri_intersect( saberBase1, saberTip1, saberTipNext1, saberBase2, saberTip2, saberBaseNext2 ) )
  1485. {
  1486. return qtrue;
  1487. }
  1488. if ( tri_tri_intersect( saberBase1, saberTip1, saberTipNext1, saberBase2, saberTip2, saberTipNext2 ) )
  1489. {
  1490. return qtrue;
  1491. }
  1492. }
  1493. }
  1494. }
  1495. return qfalse;
  1496. }
  1497. extern float ShortestLineSegBewteen2LineSegs( vec3_t start1, vec3_t end1, vec3_t start2, vec3_t end2, vec3_t close_pnt1, vec3_t close_pnt2 );
  1498. float WP_SabersDistance( gentity_t *ent1, gentity_t *ent2 )
  1499. {
  1500. vec3_t saberBaseNext1, saberTipNext1, saberPoint1;
  1501. vec3_t saberBaseNext2, saberTipNext2, saberPoint2;
  1502. /*
  1503. #ifndef FINAL_BUILD
  1504. if ( d_saberCombat->integer )
  1505. {
  1506. gi.Printf( S_COLOR_GREEN"Doing precise saber intersection check\n" );
  1507. }
  1508. #endif
  1509. */
  1510. if ( !ent1 || !ent2 )
  1511. {
  1512. return qfalse;
  1513. }
  1514. if ( !ent1->client || !ent2->client )
  1515. {
  1516. return qfalse;
  1517. }
  1518. if ( ent1->client->ps.SaberLength() <= 0 || ent2->client->ps.SaberLength() <= 0 )
  1519. {
  1520. return qfalse;
  1521. }
  1522. //FIXME: UGH, how do we make this work for multiply-bladed sabers?
  1523. //if ( ent1->client->ps.saberInFlight )
  1524. {
  1525. VectorCopy( ent1->client->ps.saber[0].blade[0].muzzlePoint, saberBaseNext1 );
  1526. VectorMA( saberBaseNext1, ent1->client->ps.saber[0].blade[0].length, ent1->client->ps.saber[0].blade[0].muzzleDir, saberTipNext1 );
  1527. }
  1528. /*
  1529. else
  1530. {
  1531. VectorCopy( ent1->client->ps.saber[0].blade[0].muzzlePointNext, saberBaseNext1 );
  1532. VectorMA( saberBaseNext1, ent1->client->ps.saber[0].blade[0].length, ent1->client->ps.saber[0].blade[0].muzzleDirNext, saberTipNext1 );
  1533. }
  1534. */
  1535. //if ( ent2->client->ps.saberInFlight )
  1536. {
  1537. VectorCopy( ent2->client->ps.saber[0].blade[0].muzzlePoint, saberBaseNext2 );
  1538. VectorMA( saberBaseNext2, ent2->client->ps.saber[0].blade[0].length, ent2->client->ps.saber[0].blade[0].muzzleDir, saberTipNext2 );
  1539. }
  1540. /*
  1541. else
  1542. {
  1543. VectorCopy( ent2->client->ps.saber[0].blade[0].muzzlePointNext, saberBaseNext2 );
  1544. VectorMA( saberBaseNext2, ent2->client->ps.saber[0].blade[0].length, ent2->client->ps.saber[0].blade[0].muzzleDirNext, saberTipNext2 );
  1545. }
  1546. */
  1547. float sabersDist = ShortestLineSegBewteen2LineSegs( saberBaseNext1, saberTipNext1, saberBaseNext2, saberTipNext2, saberPoint1, saberPoint2 );
  1548. //okay, this is a super hack, but makes saber collisions look better from the player point of view
  1549. /*
  1550. if ( sabersDist < 16.0f )
  1551. {
  1552. vec3_t saberDistDir, saberMidPoint, camLookDir;
  1553. VectorSubtract( saberPoint2, saberPoint1, saberDistDir );
  1554. VectorMA( saberPoint1, 0.5f, saberDistDir, saberMidPoint );
  1555. VectorSubtract( saberMidPoint, cg.refdef.vieworg, camLookDir );
  1556. VectorNormalize( saberDistDir );
  1557. VectorNormalize( camLookDir );
  1558. float dot = fabs(DotProduct( camLookDir, saberDistDir ));
  1559. sabersDist -= 8.0f*dot;
  1560. if ( sabersDist < 0.0f )
  1561. {
  1562. sabersDist = 0.0f;
  1563. }
  1564. }
  1565. */
  1566. #ifndef FINAL_BUILD
  1567. if ( d_saberCombat->integer > 2 )
  1568. {
  1569. G_DebugLine( saberPoint1, saberPoint2, FRAMETIME, 0x00ffffff, qtrue );
  1570. }
  1571. #endif
  1572. return sabersDist;
  1573. }
  1574. qboolean WP_SabersIntersection( gentity_t *ent1, gentity_t *ent2, vec3_t intersect )
  1575. {
  1576. vec3_t saberBaseNext1, saberTipNext1, saberPoint1;
  1577. vec3_t saberBaseNext2, saberTipNext2, saberPoint2;
  1578. int saberNum1, saberNum2, bladeNum1, bladeNum2;
  1579. float lineSegLength, bestLineSegLength = Q3_INFINITE;
  1580. if ( !ent1 || !ent2 )
  1581. {
  1582. return qfalse;
  1583. }
  1584. if ( !ent1->client || !ent2->client )
  1585. {
  1586. return qfalse;
  1587. }
  1588. if ( ent1->client->ps.SaberLength() <= 0 || ent2->client->ps.SaberLength() <= 0 )
  1589. {
  1590. return qfalse;
  1591. }
  1592. //UGH, had to make this work for multiply-bladed sabers
  1593. for ( saberNum1 = 0; saberNum1 < MAX_SABERS; saberNum1++ )
  1594. {
  1595. for ( bladeNum1 = 0; bladeNum1 < ent1->client->ps.saber[saberNum1].numBlades; bladeNum1++ )
  1596. {
  1597. if ( ent1->client->ps.saber[saberNum1].type != SABER_NONE
  1598. && ent1->client->ps.saber[saberNum1].blade[bladeNum1].length > 0 )
  1599. {//valid saber and this blade is on
  1600. for ( saberNum2 = 0; saberNum2 < MAX_SABERS; saberNum2++ )
  1601. {
  1602. for ( bladeNum2 = 0; bladeNum2 < ent2->client->ps.saber[saberNum2].numBlades; bladeNum2++ )
  1603. {
  1604. if ( ent2->client->ps.saber[saberNum2].type != SABER_NONE
  1605. && ent2->client->ps.saber[saberNum2].blade[bladeNum2].length > 0 )
  1606. {//valid saber and this blade is on
  1607. VectorCopy( ent1->client->ps.saber[saberNum1].blade[bladeNum1].muzzlePoint, saberBaseNext1 );
  1608. VectorMA( saberBaseNext1, ent1->client->ps.saber[saberNum1].blade[bladeNum1].length, ent1->client->ps.saber[saberNum1].blade[bladeNum1].muzzleDir, saberTipNext1 );
  1609. VectorCopy( ent2->client->ps.saber[saberNum2].blade[bladeNum2].muzzlePoint, saberBaseNext2 );
  1610. VectorMA( saberBaseNext2, ent2->client->ps.saber[saberNum2].blade[bladeNum2].length, ent2->client->ps.saber[saberNum2].blade[bladeNum2].muzzleDir, saberTipNext2 );
  1611. lineSegLength = ShortestLineSegBewteen2LineSegs( saberBaseNext1, saberTipNext1, saberBaseNext2, saberTipNext2, saberPoint1, saberPoint2 );
  1612. if ( lineSegLength < bestLineSegLength )
  1613. {
  1614. bestLineSegLength = lineSegLength;
  1615. VectorAdd( saberPoint1, saberPoint2, intersect );
  1616. VectorScale( intersect, 0.5, intersect );
  1617. }
  1618. }
  1619. }
  1620. }
  1621. }
  1622. }
  1623. }
  1624. if(ent1->client && ent1->client->ps.clientNum == 0)
  1625. FF_Play(fffx_Laser1);
  1626. return qtrue;
  1627. }
  1628. const char *hit_blood_sparks = "sparks/blood_sparks2"; // could have changed this effect directly, but this is just safer in case anyone anywhere else is using the old one for something?
  1629. const char *hit_sparks = "saber/saber_cut";
  1630. //extern char *hitLocName[];
  1631. qboolean WP_SaberDamageEffects( trace_t *tr, const vec3_t start, float length, float dmg, vec3_t dmgDir, vec3_t bladeDir, int enemyTeam, saberType_t saberType )
  1632. {
  1633. int hitEntNum[MAX_G2_COLLISIONS];
  1634. for ( int hen = 0; hen < MAX_G2_COLLISIONS; hen++ )
  1635. {
  1636. hitEntNum[hen] = ENTITYNUM_NONE;
  1637. }
  1638. //NOTE: = {0} does NOT work on anything but bytes?
  1639. float hitEntDmgAdd[MAX_G2_COLLISIONS] = {0};
  1640. float hitEntDmgSub[MAX_G2_COLLISIONS] = {0};
  1641. vec3_t hitEntPoint[MAX_G2_COLLISIONS];
  1642. vec3_t hitEntDir[MAX_G2_COLLISIONS];
  1643. float hitEntStartFrac[MAX_G2_COLLISIONS] = {0};
  1644. int trHitLoc[MAX_G2_COLLISIONS] = {HL_NONE};//same as 0
  1645. int trDismemberLoc[MAX_G2_COLLISIONS] = {HL_NONE};//same as 0
  1646. qboolean trDismember[MAX_G2_COLLISIONS] = {qfalse};//same as 0
  1647. int i,z;
  1648. int numHitEnts = 0;
  1649. float distFromStart,doDmg;
  1650. const char *hitEffect, *trSurfName;
  1651. gentity_t *hitEnt;
  1652. for (z=0; z < MAX_G2_COLLISIONS; z++)
  1653. {
  1654. if ( tr->G2CollisionMap[z].mEntityNum == -1 )
  1655. {//actually, completely break out of this for loop since nothing after this in the aray should ever be valid either
  1656. continue;//break;//
  1657. }
  1658. CCollisionRecord &coll = tr->G2CollisionMap[z];
  1659. //distFromStart = Distance( start, coll.mCollisionPosition );
  1660. distFromStart = coll.mDistance;
  1661. /*
  1662. //FIXME: (distFromStart/length) is not guaranteed to be from 0 to 1... *sigh*...
  1663. if ( length && saberHitFraction < 1.0f && (distFromStart/length) < 1.0f && (distFromStart/length) > saberHitFraction )
  1664. {//a saber was hit before this point, don't count it
  1665. #ifndef FINAL_BUILD
  1666. if ( d_saberCombat->integer )
  1667. {
  1668. gi.Printf( S_COLOR_MAGENTA"rejecting G2 collision- %4.2f farther than saberHitFraction %4.2f\n", (distFromStart/length), saberHitFraction );
  1669. }
  1670. #endif
  1671. continue;
  1672. }
  1673. */
  1674. for ( i = 0; i < numHitEnts; i++ )
  1675. {
  1676. if ( hitEntNum[i] == coll.mEntityNum )
  1677. {//we hit this ent before
  1678. //we'll want to add this dist
  1679. hitEntDmgAdd[i] = distFromStart;
  1680. break;
  1681. }
  1682. }
  1683. if ( i == numHitEnts )
  1684. {//first time we hit this ent
  1685. if ( numHitEnts == MAX_G2_COLLISIONS )
  1686. {//hit too many damn ents!
  1687. continue;
  1688. }
  1689. hitEntNum[numHitEnts] = coll.mEntityNum;
  1690. if ( !coll.mFlags )
  1691. {//hmm, we came out first, so we must have started inside
  1692. //we'll want to subtract this dist
  1693. hitEntDmgAdd[numHitEnts] = distFromStart;
  1694. }
  1695. else
  1696. {//we're entering the model
  1697. //we'll want to subtract this dist
  1698. hitEntDmgSub[numHitEnts] = distFromStart;
  1699. }
  1700. //keep track of how far in the damage was done
  1701. hitEntStartFrac[numHitEnts] = hitEntDmgSub[numHitEnts]/length;
  1702. //remember the entrance point
  1703. VectorCopy( coll.mCollisionPosition, hitEntPoint[numHitEnts] );
  1704. //remember the entrance dir
  1705. VectorCopy( coll.mCollisionNormal, hitEntDir[numHitEnts] );
  1706. VectorNormalize( hitEntDir[numHitEnts] );
  1707. //do the effect
  1708. //FIXME: check material rather than team?
  1709. hitEnt = &g_entities[hitEntNum[numHitEnts]];
  1710. hitEffect = hit_blood_sparks;
  1711. if ( hitEnt != NULL )
  1712. {
  1713. if ( hitEnt->client )
  1714. {
  1715. class_t npc_class = hitEnt->client->NPC_class;
  1716. if ( npc_class == CLASS_SEEKER || npc_class == CLASS_PROBE || npc_class == CLASS_MOUSE || npc_class == CLASS_REMOTE ||
  1717. npc_class == CLASS_GONK || npc_class == CLASS_R2D2 || npc_class == CLASS_R5D2 ||
  1718. npc_class == CLASS_PROTOCOL || npc_class == CLASS_MARK1 || npc_class == CLASS_MARK2 ||
  1719. npc_class == CLASS_INTERROGATOR || npc_class == CLASS_ATST || npc_class == CLASS_SENTRY )
  1720. {
  1721. hitEffect = hit_sparks;
  1722. }
  1723. }
  1724. else
  1725. {
  1726. // So sue me, this is the easiest way to check to see if this is the turbo laser from t2_wedge,
  1727. // in which case I don't want the saber effects goin off on it.
  1728. if ( (hitEnt->flags&FL_DMG_BY_HEAVY_WEAP_ONLY)
  1729. && hitEnt->takedamage == qfalse
  1730. && Q_stricmp( hitEnt->classname, "misc_turret" ) == 0 )
  1731. {
  1732. continue;
  1733. }
  1734. else
  1735. {
  1736. if ( dmg )
  1737. {//only do these effects if actually trying to damage the thing...
  1738. if ( (hitEnt->svFlags&SVF_BBRUSH)//a breakable brush
  1739. && ( (hitEnt->spawnflags&1)//INVINCIBLE
  1740. ||(hitEnt->flags&FL_DMG_BY_HEAVY_WEAP_ONLY) )//HEAVY weapon damage only
  1741. )
  1742. {//no hit effect (besides regular client-side one)
  1743. hitEffect = NULL;
  1744. }
  1745. else
  1746. {
  1747. hitEffect = hit_sparks;
  1748. }
  1749. }
  1750. }
  1751. }
  1752. }
  1753. //FIXME: play less if damage is less?
  1754. if ( !g_saberNoEffects )
  1755. {
  1756. if ( hitEffect != NULL )
  1757. {
  1758. G_PlayEffect( hitEffect, coll.mCollisionPosition, coll.mCollisionNormal );
  1759. // if(ent->client && ent->client->ps.clientNum == 0)
  1760. // FF_Play(fffx_Laser1);
  1761. }
  1762. /*
  1763. if ( hitEnt && hitEnt->client )
  1764. {
  1765. CG_AddGhoul2Mark( PGORE_DECAL02, Q_flrand(3.5, 4.0), coll.mCollisionPosition, hitEntDir[numHitEnts], hitEnt->s.number,
  1766. hitEnt->client->ps.origin, hitEnt->client->renderInfo.legsYaw, hitEnt->ghoul2 );
  1767. CG_AddGhoul2Mark( PGORE_DECAL03, Q_flrand(3.5, 4.0), coll.mCollisionPosition, hitEntDir[numHitEnts], hitEnt->s.number,
  1768. hitEnt->client->ps.origin, hitEnt->client->renderInfo.legsYaw, hitEnt->ghoul2 );
  1769. }
  1770. */
  1771. }
  1772. //Get the hit location based on surface name
  1773. if ( (hitLoc[hitEntNum[numHitEnts]] == HL_NONE && trHitLoc[numHitEnts] == HL_NONE)
  1774. || (hitDismemberLoc[hitEntNum[numHitEnts]] == HL_NONE && trDismemberLoc[numHitEnts] == HL_NONE)
  1775. || (!hitDismember[hitEntNum[numHitEnts]] && !trDismember[numHitEnts]) )
  1776. {//no hit loc set for this ent this damage cycle yet
  1777. //FIXME: find closest impact surf *first* (per ent), then call G_GetHitLocFromSurfName?
  1778. //FIXED: if hit multiple ents in this collision record, these trSurfName, trDismember and trDismemberLoc will get stomped/confused over the multiple ents I hit
  1779. trSurfName = gi.G2API_GetSurfaceName( &g_entities[coll.mEntityNum].ghoul2[coll.mModelIndex], coll.mSurfaceIndex );
  1780. trDismember[numHitEnts] = G_GetHitLocFromSurfName( &g_entities[coll.mEntityNum], trSurfName, &trHitLoc[numHitEnts], coll.mCollisionPosition, dmgDir, bladeDir, MOD_SABER, saberType );
  1781. if ( trDismember[numHitEnts] )
  1782. {
  1783. trDismemberLoc[numHitEnts] = trHitLoc[numHitEnts];
  1784. }
  1785. /*
  1786. if ( trDismember[numHitEnts] )
  1787. {
  1788. Com_Printf( S_COLOR_RED"Okay to dismember %s on ent %d\n", hitLocName[trDismemberLoc[numHitEnts]], hitEntNum[numHitEnts] );
  1789. }
  1790. else
  1791. {
  1792. Com_Printf( "Hit (no dismember) %s on ent %d\n", hitLocName[trHitLoc[numHitEnts]], hitEntNum[numHitEnts] );
  1793. }
  1794. */
  1795. }
  1796. numHitEnts++;
  1797. }
  1798. }
  1799. //now go through all the ents we hit and do the damage
  1800. for ( i = 0; i < numHitEnts; i++ )
  1801. {
  1802. doDmg = dmg;
  1803. if ( hitEntNum[i] != ENTITYNUM_NONE )
  1804. {
  1805. if ( doDmg < 10 )
  1806. {//base damage is less than 10
  1807. if ( hitEntNum[i] != 0 )
  1808. {//not the player
  1809. hitEnt = &g_entities[hitEntNum[i]];
  1810. if ( !hitEnt->client || (hitEnt->client->ps.weapon!=WP_SABER&&hitEnt->client->NPC_class!=CLASS_GALAKMECH&&hitEnt->client->playerTeam==enemyTeam) )
  1811. {//did *not* hit a jedi and did *not* hit the player
  1812. //make sure the base damage is high against non-jedi, feels better
  1813. doDmg = 10;
  1814. }
  1815. }
  1816. }
  1817. if ( !hitEntDmgAdd[i] && !hitEntDmgSub[i] )
  1818. {//spent entire time in model
  1819. //NOTE: will we even get a collision then?
  1820. doDmg *= length;
  1821. }
  1822. else if ( hitEntDmgAdd[i] && hitEntDmgSub[i] )
  1823. {//we did enter and exit
  1824. doDmg *= hitEntDmgAdd[i] - hitEntDmgSub[i];
  1825. }
  1826. else if ( !hitEntDmgAdd[i] )
  1827. {//we didn't exit, just entered
  1828. doDmg *= length - hitEntDmgSub[i];
  1829. }
  1830. else if ( !hitEntDmgSub[i] )
  1831. {//we didn't enter, only exited
  1832. doDmg *= hitEntDmgAdd[i];
  1833. }
  1834. if ( doDmg > 0 )
  1835. {
  1836. WP_SaberDamageAdd( 1.0, hitEntNum[i], hitEntDir[i], hitEntPoint[i], ceil(doDmg), hitEntStartFrac[i], trHitLoc[i], trDismember[i], trDismemberLoc[i] );
  1837. }
  1838. }
  1839. }
  1840. return (numHitEnts>0);
  1841. }
  1842. void WP_SaberKnockaway( gentity_t *attacker, trace_t *tr )
  1843. {
  1844. WP_SaberDrop( attacker, &g_entities[attacker->client->ps.saberEntityNum] );
  1845. G_Sound( &g_entities[attacker->client->ps.saberEntityNum], G_SoundIndex( va( "sound/weapons/saber/saberblock%d.wav", Q_irand(1, 9) ) ) );
  1846. G_PlayEffect( "saber/saber_block", tr->endpos );
  1847. saberHitFraction = tr->fraction;
  1848. #ifndef FINAL_BUILD
  1849. if ( d_saberCombat->integer )
  1850. {
  1851. gi.Printf( S_COLOR_MAGENTA"WP_SaberKnockaway: saberHitFraction %4.2f\n", saberHitFraction );
  1852. }
  1853. #endif
  1854. VectorCopy( tr->endpos, saberHitLocation );
  1855. saberHitEntity = tr->entityNum;
  1856. g_saberFlashTime = level.time-50;
  1857. VectorCopy( saberHitLocation, g_saberFlashPos );
  1858. //FIXME: make hitEnt play an attack anim or some other special anim when this happens
  1859. //gentity_t *hitEnt = &g_entities[tr->entityNum];
  1860. //NPC_SetAnim( hitEnt, SETANIM_BOTH, BOTH_KNOCKSABER, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  1861. }
  1862. qboolean G_InCinematicSaberAnim( gentity_t *self )
  1863. {
  1864. if ( self->NPC
  1865. && self->NPC->behaviorState == BS_CINEMATIC
  1866. && (self->client->ps.torsoAnim == BOTH_CIN_16 ||self->client->ps.torsoAnim == BOTH_CIN_17) )
  1867. {
  1868. return qtrue;
  1869. }
  1870. return qfalse;
  1871. }
  1872. #define SABER_COLLISION_DIST 6//was 2//was 4//was 8//was 16
  1873. extern qboolean InFront( vec3_t spot, vec3_t from, vec3_t fromAngles, float threshHold = 0.0f );
  1874. qboolean WP_SaberDamageForTrace( int ignore, vec3_t start, vec3_t end, float dmg,
  1875. vec3_t bladeDir, qboolean noGhoul, int attackStrength,
  1876. saberType_t saberType, qboolean extrapolate,
  1877. int saberNum, int bladeNum )
  1878. {
  1879. trace_t tr;
  1880. vec3_t dir;
  1881. int mask = (MASK_SHOT|CONTENTS_LIGHTSABER);
  1882. gentity_t *attacker = &g_entities[ignore];
  1883. vec3_t end2;
  1884. VectorCopy( end, end2 );
  1885. if ( extrapolate )
  1886. {
  1887. //NOTE: since we can no longer use the predicted point, extrapolate the trace some.
  1888. // this may allow saber hits that aren't actually hits, but it doesn't look too bad
  1889. vec3_t diff;
  1890. VectorSubtract( end, start, diff );
  1891. VectorNormalize( diff );
  1892. VectorMA( end2, SABER_EXTRAPOLATE_DIST, diff, end2 );
  1893. }
  1894. if ( !noGhoul )
  1895. {
  1896. if ( !attacker->s.number
  1897. || (attacker->client
  1898. && (attacker->client->playerTeam==TEAM_PLAYER
  1899. || attacker->client->NPC_class==CLASS_SHADOWTROOPER
  1900. || attacker->client->NPC_class==CLASS_ALORA
  1901. || (attacker->NPC && (attacker->NPC->aiFlags&NPCAI_BOSS_CHARACTER))
  1902. )
  1903. )
  1904. )//&&attackStrength==FORCE_LEVEL_3)
  1905. {//player,. player allies, shadowtroopers, tavion and desann use larger traces
  1906. vec3_t traceMins = {-2,-2,-2}, traceMaxs = {2,2,2};
  1907. gi.trace( &tr, start, traceMins, traceMaxs, end2, ignore, mask, G2_COLLIDE, 10 );//G2_SUPERSIZEDBBOX
  1908. }
  1909. /*
  1910. else if ( !attacker->s.number )
  1911. {
  1912. vec3_t traceMins = {-1,-1,-1}, traceMaxs = {1,1,1};
  1913. gi.trace( &tr, start, traceMins, traceMaxs, end2, ignore, mask, G2_COLLIDE, 10 );//G2_SUPERSIZEDBBOX
  1914. }
  1915. */
  1916. else
  1917. {//reborn use smaller traces
  1918. gi.trace( &tr, start, NULL, NULL, end2, ignore, mask, G2_COLLIDE, 10 );//G2_SUPERSIZEDBBOX
  1919. }
  1920. }
  1921. else
  1922. {
  1923. gi.trace( &tr, start, NULL, NULL, end2, ignore, mask, G2_NOCOLLIDE, 10 );
  1924. }
  1925. #ifndef FINAL_BUILD
  1926. if ( d_saberCombat->integer > 1 )
  1927. {
  1928. if ( attacker != NULL && attacker->client != NULL )
  1929. {
  1930. G_DebugLine(start, end2, FRAMETIME, WPDEBUG_SaberColor( attacker->client->ps.saber[0].blade[0].color ), qtrue);
  1931. }
  1932. }
  1933. #endif
  1934. if ( tr.entityNum == ENTITYNUM_NONE )
  1935. {
  1936. return qfalse;
  1937. }
  1938. if ( tr.entityNum == ENTITYNUM_WORLD )
  1939. {
  1940. return qtrue;
  1941. }
  1942. if ( &g_entities[tr.entityNum] )
  1943. {
  1944. gentity_t *hitEnt = &g_entities[tr.entityNum];
  1945. gentity_t *owner = g_entities[tr.entityNum].owner;
  1946. if ( hitEnt->contents & CONTENTS_LIGHTSABER )
  1947. {
  1948. if ( attacker && attacker->client && attacker->client->ps.saberInFlight )
  1949. {//thrown saber hit something
  1950. if ( owner
  1951. && owner->s.number
  1952. && owner->client
  1953. && owner->NPC
  1954. && owner->health > 0 )
  1955. {
  1956. if ( owner->client->NPC_class == CLASS_ALORA )
  1957. {//alora takes less damage
  1958. dmg *= 0.25f;
  1959. }
  1960. else if ( owner->client->NPC_class == CLASS_TAVION
  1961. /*|| (owner->client->NPC_class == CLASS_SHADOWTROOPER && !Q_irand( 0, g_spskill->integer*3 ))
  1962. || (Q_irand( -5, owner->NPC->rank ) > RANK_CIVILIAN && !Q_irand( 0, g_spskill->integer*3 ))*/ )
  1963. {//Tavion can toss a blocked thrown saber aside
  1964. WP_SaberKnockaway( attacker, &tr );
  1965. Jedi_PlayDeflectSound( owner );
  1966. return qfalse;
  1967. }
  1968. }
  1969. }
  1970. //FIXME: take target FP_SABER_DEFENSE and attacker FP_SABER_OFFENSE into account here somehow?
  1971. qboolean sabersIntersect = WP_SabersIntersect( attacker, saberNum, bladeNum, owner, qfalse );//qtrue );
  1972. float sabersDist;
  1973. if ( attacker && attacker->client && attacker->client->ps.saberInFlight
  1974. && owner && owner->s.number == 0 && (g_saberAutoBlocking->integer||attacker->client->ps.saberBlockingTime>level.time) )//NPC flying saber hit player's saber bounding box
  1975. {//players have g_saberAutoBlocking, do the more generous check against flying sabers
  1976. //FIXME: instead of hitting the player's saber bounding box
  1977. //and picking an anim afterwards, have him use AI similar
  1978. //to the AI the jedi use for picking a saber melee block...?
  1979. sabersDist = 0;
  1980. }
  1981. else
  1982. {//sabers must actually collide with the attacking saber
  1983. sabersDist = WP_SabersDistance( attacker, owner );
  1984. if ( attacker && attacker->client && attacker->client->ps.saberInFlight )
  1985. {
  1986. sabersDist /= 2.0f;
  1987. if ( sabersDist <= 16.0f )
  1988. {
  1989. sabersIntersect = qtrue;
  1990. }
  1991. }
  1992. #ifndef FINAL_BUILD
  1993. if ( d_saberCombat->integer > 1 )
  1994. {
  1995. gi.Printf( "sabersDist: %4.2f\n", sabersDist );
  1996. }
  1997. #endif//FINAL_BUILD
  1998. }
  1999. if ( sabersCrossed == -1 || sabersCrossed > sabersDist )
  2000. {
  2001. sabersCrossed = sabersDist;
  2002. }
  2003. float collisionDist;
  2004. if ( g_saberRealisticCombat->integer )
  2005. {
  2006. collisionDist = SABER_COLLISION_DIST;
  2007. }
  2008. else
  2009. {
  2010. collisionDist = SABER_COLLISION_DIST+6+g_spskill->integer*4;
  2011. }
  2012. {
  2013. if ( G_InCinematicSaberAnim( owner )
  2014. && G_InCinematicSaberAnim( attacker ) )
  2015. {
  2016. sabersIntersect = qtrue;
  2017. }
  2018. }
  2019. if ( owner && owner->client && (attacker != NULL)
  2020. && (sabersDist > collisionDist )//|| !InFront( attacker->currentOrigin, owner->currentOrigin, owner->client->ps.viewangles, 0.35f ))
  2021. && !sabersIntersect )//was qtrue, but missed too much?
  2022. {//swing came from behind and/or was not stopped by a lightsaber
  2023. //re-try the trace without checking for lightsabers
  2024. gi.trace ( &tr, start, NULL, NULL, end2, ignore, mask&~CONTENTS_LIGHTSABER, G2_NOCOLLIDE, 10 );
  2025. if ( tr.entityNum == ENTITYNUM_WORLD )
  2026. {
  2027. return qtrue;
  2028. }
  2029. if ( tr.entityNum == ENTITYNUM_NONE || &g_entities[tr.entityNum] == NULL )
  2030. {//didn't hit the owner
  2031. /*
  2032. if ( attacker
  2033. && attacker->client
  2034. && (PM_SaberInAttack( attacker->client->ps.saberMove ) || PM_SaberInStart( attacker->client->ps.saberMove ))
  2035. && DistanceSquared( tr.endpos, owner->currentOrigin ) < 10000 )
  2036. {
  2037. if ( owner->NPC
  2038. && !owner->client->ps.saberInFlight
  2039. && owner->client->ps.saberBlocked != BLOCKED_PARRY_BROKEN
  2040. && !Jedi_SaberBusy( owner ) )
  2041. {//owner parried, just make sure they're saber is in the right spot - only does this if they're not already doing something with saber
  2042. if ( g_spskill->integer && (g_spskill->integer > 1 || Q_irand( 0, 1 )))
  2043. {//if on easy, they don't cheat like this, if on medium, they cheat 50% of the time, if on hard, they always cheat
  2044. //FIXME: also take into account the owner's FP_DEFENSE?
  2045. if ( Q_irand( 0, owner->NPC->rank ) >= RANK_CIVILIAN )
  2046. {//lower-rank Jedi aren't as good blockers
  2047. vec3_t attDir;
  2048. VectorSubtract( end2, start, attDir );
  2049. VectorNormalize( attDir );
  2050. Jedi_SaberBlockGo( owner, owner->NPC->last_ucmd, start, attDir, NULL );
  2051. }
  2052. }
  2053. }
  2054. }
  2055. */
  2056. return qfalse; // Exit, but we didn't hit the wall.
  2057. }
  2058. #ifndef FINAL_BUILD
  2059. if ( d_saberCombat->integer > 1 )
  2060. {
  2061. if ( !attacker->s.number )
  2062. {
  2063. gi.Printf( S_COLOR_MAGENTA"%d saber hit owner through saber %4.2f, dist = %4.2f\n", level.time, saberHitFraction, sabersDist );
  2064. }
  2065. }
  2066. #endif//FINAL_BUILD
  2067. hitEnt = &g_entities[tr.entityNum];
  2068. owner = g_entities[tr.entityNum].owner;
  2069. }
  2070. else
  2071. {//hit a lightsaber
  2072. if ( (tr.fraction < saberHitFraction || tr.startsolid)
  2073. && sabersDist < (8.0f+g_spskill->value)*4.0f// 50.0f//16.0f
  2074. && (sabersIntersect || sabersDist < (4.0f+g_spskill->value)*2.0f) )//32.0f) )
  2075. { // This saber hit closer than the last one.
  2076. if ( (tr.allsolid || tr.startsolid) && owner && owner->client )
  2077. {//tr.fraction will be 0, unreliable... so calculate actual
  2078. float dist = Distance( start, end2 );
  2079. if ( dist )
  2080. {
  2081. float hitFrac = WP_SabersDistance( attacker, owner )/dist;
  2082. if ( hitFrac > 1.0f )
  2083. {//umm... minimum distance between sabers was longer than trace...?
  2084. hitFrac = 1.0f;
  2085. }
  2086. if ( hitFrac < saberHitFraction )
  2087. {
  2088. saberHitFraction = hitFrac;
  2089. }
  2090. }
  2091. else
  2092. {
  2093. saberHitFraction = 0.0f;
  2094. }
  2095. #ifndef FINAL_BUILD
  2096. if ( d_saberCombat->integer > 1 )
  2097. {
  2098. if ( !attacker->s.number )
  2099. {
  2100. gi.Printf( S_COLOR_GREEN"%d saber hit saber dist %4.2f allsolid %4.2f\n", level.time, sabersDist, saberHitFraction );
  2101. }
  2102. }
  2103. #endif//FINAL_BUILD
  2104. }
  2105. else
  2106. {
  2107. #ifndef FINAL_BUILD
  2108. if ( d_saberCombat->integer > 1 )
  2109. {
  2110. if ( !attacker->s.number )
  2111. {
  2112. gi.Printf( S_COLOR_BLUE"%d saber hit saber dist %4.2f, frac %4.2f\n", level.time, sabersDist, saberHitFraction );
  2113. }
  2114. saberHitFraction = tr.fraction;
  2115. }
  2116. #endif//FINAL_BUILD
  2117. }
  2118. #ifndef FINAL_BUILD
  2119. if ( d_saberCombat->integer )
  2120. {
  2121. gi.Printf( S_COLOR_MAGENTA"hit saber: saberHitFraction %4.2f, allsolid %d, startsolid %d\n", saberHitFraction, tr.allsolid, tr.startsolid );
  2122. }
  2123. #endif//FINAL_BUILD
  2124. VectorCopy(tr.endpos, saberHitLocation);
  2125. saberHitEntity = tr.entityNum;
  2126. }
  2127. /*
  2128. if ( owner
  2129. && owner->client
  2130. && attacker
  2131. && attacker->client
  2132. && (PM_SaberInAttack( attacker->client->ps.saberMove ) || PM_SaberInStart( attacker->client->ps.saberMove ))
  2133. && DistanceSquared( tr.endpos, owner->currentOrigin ) < 10000 )
  2134. {
  2135. if ( owner->NPC
  2136. && !owner->client->ps.saberInFlight
  2137. && owner->client->ps.saberBlocked != BLOCKED_PARRY_BROKEN
  2138. && !Jedi_SaberBusy( owner ) )
  2139. {//owner parried, just make sure they're saber is in the right spot - only does this if they're not already doing something with saber
  2140. if ( g_spskill->integer && (g_spskill->integer > 1 || Q_irand( 0, 1 )))
  2141. {//if on easy, they don't cheat like this, if on medium, they cheat 50% of the time, if on hard, they always cheat
  2142. //FIXME: also take into account the owner's FP_DEFENSE?
  2143. if ( Q_irand( 0, owner->NPC->rank ) >= RANK_CIVILIAN )
  2144. {//lower-rank Jedi aren't as good blockers
  2145. vec3_t attDir;
  2146. VectorSubtract( end2, start, attDir );
  2147. VectorNormalize( attDir );
  2148. Jedi_SaberBlockGo( owner, owner->NPC->last_ucmd, start, attDir, NULL );
  2149. }
  2150. }
  2151. }
  2152. }
  2153. */
  2154. //FIXME: check to see if we broke the saber
  2155. // go through the impacted surfaces and call WP_BreakSaber
  2156. // PROBLEM: saberEnt doesn't actually have a saber g2 model
  2157. // and/or isn't in same location as saber model attached
  2158. // to the client. We'd have to fake it somehow...
  2159. return qfalse; // Exit, but we didn't hit the wall.
  2160. }
  2161. }
  2162. else
  2163. {
  2164. #ifndef FINAL_BUILD
  2165. if ( d_saberCombat->integer > 1 )
  2166. {
  2167. if ( !attacker->s.number )
  2168. {
  2169. gi.Printf( S_COLOR_RED"%d saber hit owner directly %4.2f\n", level.time, saberHitFraction );
  2170. }
  2171. }
  2172. #endif//FINAL_BUILD
  2173. }
  2174. if ( attacker && attacker->client && attacker->client->ps.saberInFlight )
  2175. {//thrown saber hit something
  2176. if ( ( hitEnt && hitEnt->client && hitEnt->health > 0 && ( hitEnt->client->NPC_class == CLASS_DESANN || !Q_stricmp("Yoda",hitEnt->NPC_type) || hitEnt->client->NPC_class == CLASS_LUKE || hitEnt->client->NPC_class == CLASS_BOBAFETT || (hitEnt->client->ps.powerups[PW_GALAK_SHIELD] > 0) ) ) ||
  2177. ( owner && owner->client && owner->health > 0 && ( owner->client->NPC_class == CLASS_DESANN || !Q_stricmp("Yoda",owner->NPC_type) || owner->client->NPC_class == CLASS_LUKE || owner->client->NPC_class == CLASS_BOBAFETT || (owner->client->ps.powerups[PW_GALAK_SHIELD] > 0) ) ) )
  2178. {//Luke and Desann slap thrown sabers aside
  2179. //FIXME: control the direction of the thrown saber... if hit Galak's shield, bounce directly away from his origin?
  2180. WP_SaberKnockaway( attacker, &tr );
  2181. if ( hitEnt->client )
  2182. {
  2183. Jedi_PlayDeflectSound( hitEnt );
  2184. }
  2185. else
  2186. {
  2187. Jedi_PlayDeflectSound( owner );
  2188. }
  2189. return qfalse; // Exit, but we didn't hit the wall.
  2190. }
  2191. }
  2192. if ( hitEnt->takedamage )
  2193. {
  2194. //no team damage: if ( !hitEnt->client || attacker == NULL || !attacker->client || (hitEnt->client->playerTeam != attacker->client->playerTeam) )
  2195. {
  2196. //multiply the damage by the total distance of the swipe
  2197. VectorSubtract( end2, start, dir );
  2198. float len = VectorNormalize( dir );//VectorLength( dir );
  2199. if ( noGhoul || !hitEnt->ghoul2.size() )
  2200. {//we weren't doing a ghoul trace
  2201. const char *hitEffect = NULL;
  2202. if ( dmg >= 1.0 && hitEnt->bmodel )
  2203. {
  2204. dmg = 1.0;
  2205. }
  2206. if ( len > 1 )
  2207. {
  2208. dmg *= len;
  2209. }
  2210. #ifndef FINAL_BUILD
  2211. if ( d_saberCombat->integer > 1 )
  2212. {
  2213. if ( !(hitEnt->contents & CONTENTS_LIGHTSABER) )
  2214. {
  2215. gi.Printf( S_COLOR_GREEN"Hit ent, but no ghoul collisions\n" );
  2216. }
  2217. }
  2218. #endif
  2219. float trFrac, dmgFrac;
  2220. if ( tr.allsolid )
  2221. {//totally inside them
  2222. trFrac = 1.0;
  2223. dmgFrac = 0.0;
  2224. }
  2225. else if ( tr.startsolid )
  2226. {//started inside them
  2227. //we don't know how much was inside, we know it's less than all, so use half?
  2228. trFrac = 0.5;
  2229. dmgFrac = 0.0;
  2230. }
  2231. else
  2232. {//started outside them and hit them
  2233. //yeah. this doesn't account for coming out the other wide, but we can worry about that later (use ghoul2)
  2234. trFrac = (1.0f - tr.fraction);
  2235. dmgFrac = tr.fraction;
  2236. }
  2237. WP_SaberDamageAdd( trFrac, tr.entityNum, dir, tr.endpos, dmg, dmgFrac, HL_NONE, qfalse, HL_NONE );
  2238. if ( !tr.allsolid && !tr.startsolid )
  2239. {
  2240. VectorScale( dir, -1, dir );
  2241. }
  2242. if ( hitEnt != NULL )
  2243. {
  2244. if ( hitEnt->client )
  2245. {
  2246. //don't do blood sparks on non-living things
  2247. class_t npc_class = hitEnt->client->NPC_class;
  2248. if ( npc_class == CLASS_SEEKER || npc_class == CLASS_PROBE || npc_class == CLASS_MOUSE ||
  2249. npc_class == CLASS_GONK || npc_class == CLASS_R2D2 || npc_class == CLASS_R5D2 || npc_class == CLASS_REMOTE ||
  2250. npc_class == CLASS_PROTOCOL || npc_class == CLASS_MARK1 || npc_class == CLASS_MARK2 ||
  2251. npc_class == CLASS_INTERROGATOR || npc_class == CLASS_ATST || npc_class == CLASS_SENTRY )
  2252. {
  2253. hitEffect = hit_sparks;
  2254. }
  2255. }
  2256. else
  2257. {
  2258. if ( dmg )
  2259. {//only do these effects if actually trying to damage the thing...
  2260. if ( (hitEnt->svFlags&SVF_BBRUSH)//a breakable brush
  2261. && ( (hitEnt->spawnflags&1)//INVINCIBLE
  2262. ||(hitEnt->flags&FL_DMG_BY_HEAVY_WEAP_ONLY)//HEAVY weapon damage only
  2263. ||(hitEnt->NPC_targetname&&attacker&&attacker->targetname&&Q_stricmp(attacker->targetname,hitEnt->NPC_targetname)) ) )//only breakable by an entity who is not the attacker
  2264. {//no hit effect (besides regular client-side one)
  2265. }
  2266. else
  2267. {
  2268. hitEffect = hit_sparks;
  2269. }
  2270. }
  2271. }
  2272. }
  2273. if ( !g_saberNoEffects && hitEffect != NULL )
  2274. {
  2275. G_PlayEffect( hitEffect, tr.endpos, dir );//"saber_cut"
  2276. // if(ent->client && ent->client->ps.clientNum == 0)
  2277. // FF_Play(fffx_Laser1);
  2278. }
  2279. }
  2280. else
  2281. {//we were doing a ghoul trace
  2282. if ( !WP_SaberDamageEffects( &tr, start, len, dmg, dir, bladeDir, attacker->client->enemyTeam, saberType ) )
  2283. {//didn't hit a ghoul ent
  2284. /*
  2285. if ( && hitEnt->ghoul2.size() )
  2286. {//it was a ghoul2 model so we should have hit it
  2287. return qfalse;
  2288. }
  2289. */
  2290. }
  2291. }
  2292. }
  2293. }
  2294. }
  2295. return qfalse;
  2296. }
  2297. #define LOCK_IDEAL_DIST_TOP 32.0f
  2298. #define LOCK_IDEAL_DIST_CIRCLE 48.0f
  2299. #define LOCK_IDEAL_DIST_JKA 46.0f//all of the new saberlocks are 46.08 from each other because Richard Lico is da MAN
  2300. extern void PM_SetAnimFrame( gentity_t *gent, int frame, qboolean torso, qboolean legs );
  2301. extern qboolean ValidAnimFileIndex ( int index );
  2302. int G_SaberLockAnim( int attackerSaberStyle, int defenderSaberStyle, int topOrSide, int lockOrBreakOrSuperBreak, int winOrLose )
  2303. {
  2304. int baseAnim = -1;
  2305. if ( lockOrBreakOrSuperBreak == SABERLOCK_LOCK )
  2306. {//special case: if we're using the same style and locking
  2307. if ( attackerSaberStyle == defenderSaberStyle
  2308. || (attackerSaberStyle>=SS_FAST&&attackerSaberStyle<=SS_TAVION&&defenderSaberStyle>=SS_FAST&&defenderSaberStyle<=SS_TAVION) )
  2309. {//using same style
  2310. if ( winOrLose == SABERLOCK_LOSE )
  2311. {//you want the defender's stance...
  2312. switch ( defenderSaberStyle )
  2313. {
  2314. case SS_DUAL:
  2315. if ( topOrSide == SABERLOCK_TOP )
  2316. {
  2317. baseAnim = BOTH_LK_DL_DL_T_L_2;
  2318. }
  2319. else
  2320. {
  2321. baseAnim = BOTH_LK_DL_DL_S_L_2;
  2322. }
  2323. break;
  2324. case SS_STAFF:
  2325. if ( topOrSide == SABERLOCK_TOP )
  2326. {
  2327. baseAnim = BOTH_LK_ST_ST_T_L_2;
  2328. }
  2329. else
  2330. {
  2331. baseAnim = BOTH_LK_ST_ST_S_L_2;
  2332. }
  2333. break;
  2334. default:
  2335. if ( topOrSide == SABERLOCK_TOP )
  2336. {
  2337. baseAnim = BOTH_LK_S_S_T_L_2;
  2338. }
  2339. else
  2340. {
  2341. baseAnim = BOTH_LK_S_S_S_L_2;
  2342. }
  2343. break;
  2344. }
  2345. }
  2346. }
  2347. }
  2348. if ( baseAnim == -1 )
  2349. {
  2350. switch ( attackerSaberStyle )
  2351. {
  2352. case SS_DUAL:
  2353. switch ( defenderSaberStyle )
  2354. {
  2355. case SS_DUAL:
  2356. baseAnim = BOTH_LK_DL_DL_S_B_1_L;
  2357. break;
  2358. case SS_STAFF:
  2359. baseAnim = BOTH_LK_DL_ST_S_B_1_L;
  2360. break;
  2361. default://single
  2362. baseAnim = BOTH_LK_DL_S_S_B_1_L;
  2363. break;
  2364. }
  2365. break;
  2366. case SS_STAFF:
  2367. switch ( defenderSaberStyle )
  2368. {
  2369. case SS_DUAL:
  2370. baseAnim = BOTH_LK_ST_DL_S_B_1_L;
  2371. break;
  2372. case SS_STAFF:
  2373. baseAnim = BOTH_LK_ST_ST_S_B_1_L;
  2374. break;
  2375. default://single
  2376. baseAnim = BOTH_LK_ST_S_S_B_1_L;
  2377. break;
  2378. }
  2379. break;
  2380. default://single
  2381. switch ( defenderSaberStyle )
  2382. {
  2383. case SS_DUAL:
  2384. baseAnim = BOTH_LK_S_DL_S_B_1_L;
  2385. break;
  2386. case SS_STAFF:
  2387. baseAnim = BOTH_LK_S_ST_S_B_1_L;
  2388. break;
  2389. default://single
  2390. baseAnim = BOTH_LK_S_S_S_B_1_L;
  2391. break;
  2392. }
  2393. break;
  2394. }
  2395. //side lock or top lock?
  2396. if ( topOrSide == SABERLOCK_TOP )
  2397. {
  2398. baseAnim += 5;
  2399. }
  2400. //lock, break or superbreak?
  2401. if ( lockOrBreakOrSuperBreak == SABERLOCK_LOCK )
  2402. {
  2403. baseAnim += 2;
  2404. }
  2405. else
  2406. {//a break or superbreak
  2407. if ( lockOrBreakOrSuperBreak == SABERLOCK_SUPERBREAK )
  2408. {
  2409. baseAnim += 3;
  2410. }
  2411. //winner or loser?
  2412. if ( winOrLose == SABERLOCK_WIN )
  2413. {
  2414. baseAnim += 1;
  2415. }
  2416. }
  2417. }
  2418. return baseAnim;
  2419. }
  2420. qboolean G_CheckIncrementLockAnim( int anim, int winOrLose )
  2421. {
  2422. qboolean increment = qfalse;//???
  2423. //RULE: if you are the first style in the lock anim, you advance from LOSING position to WINNING position
  2424. // if you are the second style in the lock anim, you advance from WINNING position to LOSING position
  2425. switch ( anim )
  2426. {
  2427. //increment to win:
  2428. case BOTH_LK_DL_DL_S_L_1: //lock if I'm using dual vs. dual and I initiated
  2429. case BOTH_LK_DL_DL_S_L_2: //lock if I'm using dual vs. dual and other initiated
  2430. case BOTH_LK_DL_DL_T_L_1: //lock if I'm using dual vs. dual and I initiated
  2431. case BOTH_LK_DL_DL_T_L_2: //lock if I'm using dual vs. dual and other initiated
  2432. case BOTH_LK_DL_S_S_L_1: //lock if I'm using dual vs. a single
  2433. case BOTH_LK_DL_S_T_L_1: //lock if I'm using dual vs. a single
  2434. case BOTH_LK_DL_ST_S_L_1: //lock if I'm using dual vs. a staff
  2435. case BOTH_LK_DL_ST_T_L_1: //lock if I'm using dual vs. a staff
  2436. case BOTH_LK_S_S_S_L_1: //lock if I'm using single vs. a single and I initiated
  2437. case BOTH_LK_S_S_T_L_2: //lock if I'm using single vs. a single and other initiated
  2438. case BOTH_LK_ST_S_S_L_1: //lock if I'm using staff vs. a single
  2439. case BOTH_LK_ST_S_T_L_1: //lock if I'm using staff vs. a single
  2440. case BOTH_LK_ST_ST_T_L_1: //lock if I'm using staff vs. a staff and I initiated
  2441. case BOTH_LK_ST_ST_T_L_2: //lock if I'm using staff vs. a staff and other initiated
  2442. if ( winOrLose == SABERLOCK_WIN )
  2443. {
  2444. increment = qtrue;
  2445. }
  2446. else
  2447. {
  2448. increment = qfalse;
  2449. }
  2450. break;
  2451. //decrement to win:
  2452. case BOTH_LK_S_DL_S_L_1: //lock if I'm using single vs. a dual
  2453. case BOTH_LK_S_DL_T_L_1: //lock if I'm using single vs. a dual
  2454. case BOTH_LK_S_S_S_L_2: //lock if I'm using single vs. a single and other intitiated
  2455. case BOTH_LK_S_S_T_L_1: //lock if I'm using single vs. a single and I initiated
  2456. case BOTH_LK_S_ST_S_L_1: //lock if I'm using single vs. a staff
  2457. case BOTH_LK_S_ST_T_L_1: //lock if I'm using single vs. a staff
  2458. case BOTH_LK_ST_DL_S_L_1: //lock if I'm using staff vs. dual
  2459. case BOTH_LK_ST_DL_T_L_1: //lock if I'm using staff vs. dual
  2460. case BOTH_LK_ST_ST_S_L_1: //lock if I'm using staff vs. a staff and I initiated
  2461. case BOTH_LK_ST_ST_S_L_2: //lock if I'm using staff vs. a staff and other initiated
  2462. if ( winOrLose == SABERLOCK_WIN )
  2463. {
  2464. increment = qfalse;
  2465. }
  2466. else
  2467. {
  2468. increment = qtrue;
  2469. }
  2470. break;
  2471. default:
  2472. #ifndef FINAL_BUILD
  2473. Com_Printf( S_COLOR_RED"ERROR: unknown Saber Lock Anim: %s!!!\n", animTable[anim].name );
  2474. #endif
  2475. break;
  2476. }
  2477. return increment;
  2478. }
  2479. qboolean WP_SabersCheckLock2( gentity_t *attacker, gentity_t *defender, sabersLockMode_t lockMode )
  2480. {
  2481. animation_t *anim;
  2482. int attAnim, defAnim, advance = 0;
  2483. float attStart = 0.5f, defStart = 0.5f;
  2484. float idealDist = 48.0f;
  2485. //FIXME: this distances need to be modified by the lengths of the sabers involved...
  2486. //MATCH ANIMS
  2487. if ( lockMode == LOCK_KYLE_GRAB1
  2488. || lockMode == LOCK_KYLE_GRAB2
  2489. || lockMode == LOCK_KYLE_GRAB3 )
  2490. {
  2491. float numSpins = 1.0f;
  2492. idealDist = 46.0f;//42.0f;
  2493. attStart = defStart = 0.0f;
  2494. switch ( lockMode )
  2495. {
  2496. default:
  2497. case LOCK_KYLE_GRAB1:
  2498. attAnim = BOTH_KYLE_PA_1;
  2499. defAnim = BOTH_PLAYER_PA_1;
  2500. numSpins = 2.0f;
  2501. break;
  2502. case LOCK_KYLE_GRAB2:
  2503. attAnim = BOTH_KYLE_PA_3;
  2504. defAnim = BOTH_PLAYER_PA_3;
  2505. numSpins = 1.0f;
  2506. break;
  2507. case LOCK_KYLE_GRAB3:
  2508. attAnim = BOTH_KYLE_PA_2;
  2509. defAnim = BOTH_PLAYER_PA_2;
  2510. defender->forcePushTime = level.time + PM_AnimLength( defender->client->clientInfo.animFileIndex, BOTH_PLAYER_PA_2 );
  2511. numSpins = 3.0f;
  2512. break;
  2513. }
  2514. attacker->client->ps.SaberDeactivate();
  2515. defender->client->ps.SaberDeactivate();
  2516. if ( d_slowmodeath->integer > 3
  2517. && ( defender->s.number < MAX_CLIENTS
  2518. || attacker->s.number < MAX_CLIENTS ) )
  2519. {
  2520. if( ValidAnimFileIndex( attacker->client->clientInfo.animFileIndex ) )
  2521. {
  2522. int effectTime = PM_AnimLength( attacker->client->clientInfo.animFileIndex, (animNumber_t)attAnim );
  2523. int spinTime = floor((float)effectTime/numSpins);
  2524. int meFlags = (MEF_MULTI_SPIN);//MEF_NO_TIMESCALE|MEF_NO_VERTBOB|
  2525. if ( Q_irand( 0, 1 ) )
  2526. {
  2527. meFlags |= MEF_REVERSE_SPIN;
  2528. }
  2529. G_StartMatrixEffect( attacker, meFlags, effectTime, 0.75f, spinTime );
  2530. }
  2531. }
  2532. }
  2533. else if ( lockMode == LOCK_FORCE_DRAIN )
  2534. {
  2535. idealDist = 46.0f;//42.0f;
  2536. attStart = defStart = 0.0f;
  2537. attAnim = BOTH_FORCE_DRAIN_GRAB_START;
  2538. defAnim = BOTH_FORCE_DRAIN_GRABBED;
  2539. attacker->client->ps.SaberDeactivate();
  2540. defender->client->ps.SaberDeactivate();
  2541. }
  2542. else
  2543. {
  2544. if ( lockMode == LOCK_RANDOM )
  2545. {
  2546. lockMode = (sabersLockMode_t)Q_irand( (int)LOCK_FIRST, (int)(LOCK_RANDOM)-1 );
  2547. }
  2548. //FIXME: attStart% and idealDist will change per saber lock anim pairing... do we need a big table like in bg_panimate.cpp?
  2549. if ( attacker->client->ps.saberAnimLevel >= SS_FAST
  2550. && attacker->client->ps.saberAnimLevel <= SS_TAVION
  2551. && defender->client->ps.saberAnimLevel >= SS_FAST
  2552. && defender->client->ps.saberAnimLevel <= SS_TAVION )
  2553. {//2 single sabers? Just do it the old way...
  2554. switch ( lockMode )
  2555. {
  2556. case LOCK_TOP:
  2557. attAnim = BOTH_BF2LOCK;// - starts in middle
  2558. defAnim = BOTH_BF1LOCK;// - starts in middle
  2559. attStart = defStart = 0.5f;
  2560. idealDist = LOCK_IDEAL_DIST_TOP;
  2561. break;
  2562. case LOCK_DIAG_TR:
  2563. attAnim = BOTH_CCWCIRCLELOCK; //- starts in middle
  2564. defAnim = BOTH_CWCIRCLELOCK;// - starts in middle
  2565. attStart = defStart = 0.5f;
  2566. idealDist = LOCK_IDEAL_DIST_CIRCLE;
  2567. break;
  2568. case LOCK_DIAG_TL:
  2569. attAnim = BOTH_CWCIRCLELOCK;// - starts in middle
  2570. defAnim = BOTH_CCWCIRCLELOCK;// - starts in middle
  2571. attStart = defStart = 0.5f;
  2572. idealDist = LOCK_IDEAL_DIST_CIRCLE;
  2573. break;
  2574. case LOCK_DIAG_BR:
  2575. attAnim = BOTH_CWCIRCLELOCK;// - starts on left, to right
  2576. defAnim = BOTH_CCWCIRCLELOCK;// - starts on right, to left
  2577. attStart = defStart = 0.85f;//move to end of anim
  2578. idealDist = LOCK_IDEAL_DIST_CIRCLE;
  2579. break;
  2580. case LOCK_DIAG_BL:
  2581. attAnim = BOTH_CCWCIRCLELOCK;// - starts on right, to left
  2582. defAnim = BOTH_CWCIRCLELOCK;// - starts on left, to right
  2583. attStart = defStart = 0.85f;//move to end of anim
  2584. idealDist = LOCK_IDEAL_DIST_CIRCLE;
  2585. break;
  2586. case LOCK_R:
  2587. attAnim = BOTH_CWCIRCLELOCK;// - starts on left, to right
  2588. defAnim = BOTH_CCWCIRCLELOCK;// - starts on right, to left
  2589. attStart = defStart = 0.75f;//move to end of anim
  2590. idealDist = LOCK_IDEAL_DIST_CIRCLE;
  2591. break;
  2592. case LOCK_L:
  2593. attAnim = BOTH_CCWCIRCLELOCK;// - starts on right, to left
  2594. defAnim = BOTH_CWCIRCLELOCK;// - starts on left, to right
  2595. attStart = defStart = 0.75f;//move to end of anim
  2596. idealDist = LOCK_IDEAL_DIST_CIRCLE;
  2597. break;
  2598. default:
  2599. return qfalse;
  2600. break;
  2601. }
  2602. }
  2603. else
  2604. {//use the new system
  2605. idealDist = LOCK_IDEAL_DIST_JKA;//all of the new saberlocks are 46.08 from each other because Richard Lico is da MAN
  2606. if ( lockMode == LOCK_TOP )
  2607. {//top lock
  2608. attAnim = G_SaberLockAnim( attacker->client->ps.saberAnimLevel, defender->client->ps.saberAnimLevel, SABERLOCK_TOP, SABERLOCK_LOCK, SABERLOCK_WIN );
  2609. defAnim = G_SaberLockAnim( defender->client->ps.saberAnimLevel, attacker->client->ps.saberAnimLevel, SABERLOCK_TOP, SABERLOCK_LOCK, SABERLOCK_LOSE );
  2610. attStart = defStart = 0.5f;
  2611. }
  2612. else
  2613. {//side lock
  2614. switch ( lockMode )
  2615. {
  2616. case LOCK_DIAG_TR:
  2617. attAnim = G_SaberLockAnim( attacker->client->ps.saberAnimLevel, defender->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_WIN );
  2618. defAnim = G_SaberLockAnim( defender->client->ps.saberAnimLevel, attacker->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_LOSE );
  2619. attStart = defStart = 0.5f;
  2620. break;
  2621. case LOCK_DIAG_TL:
  2622. attAnim = G_SaberLockAnim( attacker->client->ps.saberAnimLevel, defender->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_LOSE );
  2623. defAnim = G_SaberLockAnim( defender->client->ps.saberAnimLevel, attacker->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_WIN );
  2624. attStart = defStart = 0.5f;
  2625. break;
  2626. case LOCK_DIAG_BR:
  2627. attAnim = G_SaberLockAnim( attacker->client->ps.saberAnimLevel, defender->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_WIN );
  2628. defAnim = G_SaberLockAnim( defender->client->ps.saberAnimLevel, attacker->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_LOSE );
  2629. if ( G_CheckIncrementLockAnim( attAnim, SABERLOCK_WIN ) )
  2630. {
  2631. attStart = 0.85f;//move to end of anim
  2632. }
  2633. else
  2634. {
  2635. attStart = 0.15f;//start at beginning of anim
  2636. }
  2637. if ( G_CheckIncrementLockAnim( defAnim, SABERLOCK_LOSE ) )
  2638. {
  2639. defStart = 0.85f;//start at end of anim
  2640. }
  2641. else
  2642. {
  2643. defStart = 0.15f;//start at beginning of anim
  2644. }
  2645. break;
  2646. case LOCK_DIAG_BL:
  2647. attAnim = G_SaberLockAnim( attacker->client->ps.saberAnimLevel, defender->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_LOSE );
  2648. defAnim = G_SaberLockAnim( defender->client->ps.saberAnimLevel, attacker->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_WIN );
  2649. if ( G_CheckIncrementLockAnim( attAnim, SABERLOCK_WIN ) )
  2650. {
  2651. attStart = 0.85f;//move to end of anim
  2652. }
  2653. else
  2654. {
  2655. attStart = 0.15f;//start at beginning of anim
  2656. }
  2657. if ( G_CheckIncrementLockAnim( defAnim, SABERLOCK_LOSE ) )
  2658. {
  2659. defStart = 0.85f;//start at end of anim
  2660. }
  2661. else
  2662. {
  2663. defStart = 0.15f;//start at beginning of anim
  2664. }
  2665. break;
  2666. case LOCK_R:
  2667. attAnim = G_SaberLockAnim( attacker->client->ps.saberAnimLevel, defender->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_LOSE );
  2668. defAnim = G_SaberLockAnim( defender->client->ps.saberAnimLevel, attacker->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_WIN );
  2669. if ( G_CheckIncrementLockAnim( attAnim, SABERLOCK_WIN ) )
  2670. {
  2671. attStart = 0.75f;//move to end of anim
  2672. }
  2673. else
  2674. {
  2675. attStart = 0.25f;//start at beginning of anim
  2676. }
  2677. if ( G_CheckIncrementLockAnim( defAnim, SABERLOCK_LOSE ) )
  2678. {
  2679. defStart = 0.75f;//start at end of anim
  2680. }
  2681. else
  2682. {
  2683. defStart = 0.25f;//start at beginning of anim
  2684. }
  2685. break;
  2686. case LOCK_L:
  2687. attAnim = G_SaberLockAnim( attacker->client->ps.saberAnimLevel, defender->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_WIN );
  2688. defAnim = G_SaberLockAnim( defender->client->ps.saberAnimLevel, attacker->client->ps.saberAnimLevel, SABERLOCK_SIDE, SABERLOCK_LOCK, SABERLOCK_LOSE );
  2689. //attacker starts with advantage
  2690. if ( G_CheckIncrementLockAnim( attAnim, SABERLOCK_WIN ) )
  2691. {
  2692. attStart = 0.75f;//move to end of anim
  2693. }
  2694. else
  2695. {
  2696. attStart = 0.25f;//start at beginning of anim
  2697. }
  2698. if ( G_CheckIncrementLockAnim( defAnim, SABERLOCK_LOSE ) )
  2699. {
  2700. defStart = 0.75f;//start at end of anim
  2701. }
  2702. else
  2703. {
  2704. defStart = 0.25f;//start at beginning of anim
  2705. }
  2706. break;
  2707. default:
  2708. return qfalse;
  2709. break;
  2710. }
  2711. }
  2712. }
  2713. }
  2714. //set the proper anims
  2715. NPC_SetAnim( attacker, SETANIM_BOTH, attAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  2716. NPC_SetAnim( defender, SETANIM_BOTH, defAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  2717. //don't let them store a kick for the whole saberlock....
  2718. attacker->client->ps.saberMoveNext = defender->client->ps.saberMoveNext = LS_NONE;
  2719. //
  2720. if ( attStart > 0.0f )
  2721. {
  2722. if( ValidAnimFileIndex( attacker->client->clientInfo.animFileIndex ) )
  2723. {
  2724. anim = &level.knownAnimFileSets[attacker->client->clientInfo.animFileIndex].animations[attAnim];
  2725. advance = floor( anim->numFrames*attStart );
  2726. PM_SetAnimFrame( attacker, anim->firstFrame + advance, qtrue, qtrue );
  2727. #ifndef FINAL_BUILD
  2728. if ( d_saberCombat->integer )
  2729. {
  2730. Com_Printf( "%s starting saber lock, anim = %s, %d frames to go!\n", attacker->NPC_type, animTable[attAnim].name, anim->numFrames-advance );
  2731. }
  2732. #endif
  2733. }
  2734. }
  2735. if ( defStart > 0.0f )
  2736. {
  2737. if( ValidAnimFileIndex( defender->client->clientInfo.animFileIndex ) )
  2738. {
  2739. anim = &level.knownAnimFileSets[defender->client->clientInfo.animFileIndex].animations[defAnim];
  2740. advance = ceil( anim->numFrames*defStart );
  2741. PM_SetAnimFrame( defender, anim->firstFrame + advance, qtrue, qtrue );//was anim->firstFrame + anim->numFrames - advance, but that's wrong since they are matched anims
  2742. #ifndef FINAL_BUILD
  2743. if ( d_saberCombat->integer )
  2744. {
  2745. Com_Printf( "%s starting saber lock, anim = %s, %d frames to go!\n", defender->NPC_type, animTable[defAnim].name, advance );
  2746. }
  2747. #endif
  2748. }
  2749. }
  2750. VectorClear( attacker->client->ps.velocity );
  2751. VectorClear( attacker->client->ps.moveDir );
  2752. VectorClear( defender->client->ps.velocity );
  2753. VectorClear( defender->client->ps.moveDir );
  2754. if ( lockMode == LOCK_KYLE_GRAB1
  2755. || lockMode == LOCK_KYLE_GRAB2
  2756. || lockMode == LOCK_KYLE_GRAB3
  2757. || lockMode == LOCK_FORCE_DRAIN )
  2758. {//not a real lock, just freeze them both in place
  2759. //can't move or attack
  2760. attacker->client->ps.pm_time = attacker->client->ps.weaponTime = attacker->client->ps.legsAnimTimer;
  2761. attacker->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  2762. attacker->painDebounceTime = level.time + attacker->client->ps.pm_time;
  2763. if ( lockMode != LOCK_FORCE_DRAIN )
  2764. {
  2765. defender->client->ps.torsoAnimTimer += 200;
  2766. defender->client->ps.legsAnimTimer += 200;
  2767. }
  2768. defender->client->ps.pm_time = defender->client->ps.weaponTime = defender->client->ps.legsAnimTimer;
  2769. defender->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  2770. if ( lockMode != LOCK_FORCE_DRAIN )
  2771. {
  2772. attacker->aimDebounceTime = level.time + attacker->client->ps.pm_time;
  2773. }
  2774. }
  2775. else
  2776. {
  2777. attacker->client->ps.saberLockTime = defender->client->ps.saberLockTime = level.time + SABER_LOCK_TIME;
  2778. attacker->client->ps.legsAnimTimer = attacker->client->ps.torsoAnimTimer = defender->client->ps.legsAnimTimer = defender->client->ps.torsoAnimTimer = SABER_LOCK_TIME;
  2779. //attacker->client->ps.weaponTime = defender->client->ps.weaponTime = SABER_LOCK_TIME;
  2780. attacker->client->ps.saberLockEnemy = defender->s.number;
  2781. defender->client->ps.saberLockEnemy = attacker->s.number;
  2782. }
  2783. //MATCH ANGLES
  2784. if ( lockMode == LOCK_KYLE_GRAB1
  2785. || lockMode == LOCK_KYLE_GRAB2
  2786. || lockMode == LOCK_KYLE_GRAB3 )
  2787. {//not a real lock, just set pitch to 0
  2788. attacker->client->ps.viewangles[PITCH] = defender->client->ps.viewangles[PITCH] = 0;
  2789. }
  2790. else
  2791. {
  2792. //FIXME: if zDiff in elevation, make lower look up and upper look down and move them closer?
  2793. float defPitchAdd = 0, zDiff = ((attacker->currentOrigin[2]+attacker->client->standheight)-(defender->currentOrigin[2]+defender->client->standheight));
  2794. if ( zDiff > 24 )
  2795. {
  2796. defPitchAdd = -30;
  2797. }
  2798. else if ( zDiff < -24 )
  2799. {
  2800. defPitchAdd = 30;
  2801. }
  2802. else
  2803. {
  2804. defPitchAdd = zDiff/24.0f*-30.0f;
  2805. }
  2806. if ( attacker->NPC && defender->NPC )
  2807. {//if 2 NPCs, just set pitch to 0
  2808. attacker->client->ps.viewangles[PITCH] = -defPitchAdd;
  2809. defender->client->ps.viewangles[PITCH] = defPitchAdd;
  2810. }
  2811. else
  2812. {//if a player is involved, clamp player's pitch and match NPC's to player
  2813. if ( !attacker->s.number )
  2814. {
  2815. //clamp to defPitch
  2816. if ( attacker->client->ps.viewangles[PITCH] > -defPitchAdd + 10 )
  2817. {
  2818. attacker->client->ps.viewangles[PITCH] = -defPitchAdd + 10;
  2819. }
  2820. else if ( attacker->client->ps.viewangles[PITCH] < -defPitchAdd-10 )
  2821. {
  2822. attacker->client->ps.viewangles[PITCH] = -defPitchAdd-10;
  2823. }
  2824. //clamp to sane numbers
  2825. if ( attacker->client->ps.viewangles[PITCH] > 50 )
  2826. {
  2827. attacker->client->ps.viewangles[PITCH] = 50;
  2828. }
  2829. else if ( attacker->client->ps.viewangles[PITCH] < -50 )
  2830. {
  2831. attacker->client->ps.viewangles[PITCH] = -50;
  2832. }
  2833. defender->client->ps.viewangles[PITCH] = attacker->client->ps.viewangles[PITCH]*-1;
  2834. defPitchAdd = defender->client->ps.viewangles[PITCH];
  2835. }
  2836. else if ( !defender->s.number )
  2837. {
  2838. //clamp to defPitch
  2839. if ( defender->client->ps.viewangles[PITCH] > defPitchAdd + 10 )
  2840. {
  2841. defender->client->ps.viewangles[PITCH] = defPitchAdd + 10;
  2842. }
  2843. else if ( defender->client->ps.viewangles[PITCH] < defPitchAdd-10 )
  2844. {
  2845. defender->client->ps.viewangles[PITCH] = defPitchAdd-10;
  2846. }
  2847. //clamp to sane numbers
  2848. if ( defender->client->ps.viewangles[PITCH] > 50 )
  2849. {
  2850. defender->client->ps.viewangles[PITCH] = 50;
  2851. }
  2852. else if ( defender->client->ps.viewangles[PITCH] < -50 )
  2853. {
  2854. defender->client->ps.viewangles[PITCH] = -50;
  2855. }
  2856. defPitchAdd = defender->client->ps.viewangles[PITCH];
  2857. attacker->client->ps.viewangles[PITCH] = defender->client->ps.viewangles[PITCH]*-1;
  2858. }
  2859. }
  2860. }
  2861. vec3_t attAngles, defAngles, defDir;
  2862. VectorSubtract( defender->currentOrigin, attacker->currentOrigin, defDir );
  2863. VectorCopy( attacker->client->ps.viewangles, attAngles );
  2864. attAngles[YAW] = vectoyaw( defDir );
  2865. SetClientViewAngle( attacker, attAngles );
  2866. defAngles[PITCH] = attAngles[PITCH]*-1;
  2867. defAngles[YAW] = AngleNormalize180( attAngles[YAW] + 180);
  2868. defAngles[ROLL] = 0;
  2869. SetClientViewAngle( defender, defAngles );
  2870. //MATCH POSITIONS
  2871. vec3_t newOrg;
  2872. /*
  2873. idealDist -= fabs(defPitchAdd)/8.0f;
  2874. */
  2875. float scale = (attacker->s.modelScale[0]+attacker->s.modelScale[1])*0.5f;
  2876. if ( scale && scale != 1.0f )
  2877. {
  2878. idealDist += 8*(scale-1.0f);
  2879. }
  2880. scale = (defender->s.modelScale[0]+defender->s.modelScale[1])*0.5f;
  2881. if ( scale && scale != 1.0f )
  2882. {
  2883. idealDist += 8*(scale-1.0f);
  2884. }
  2885. float diff = VectorNormalize( defDir ) - idealDist;//diff will be the total error in dist
  2886. //try to move attacker half the diff towards the defender
  2887. VectorMA( attacker->currentOrigin, diff*0.5f, defDir, newOrg );
  2888. trace_t trace;
  2889. gi.trace( &trace, attacker->currentOrigin, attacker->mins, attacker->maxs, newOrg, attacker->s.number, attacker->clipmask );
  2890. if ( !trace.startsolid && !trace.allsolid )
  2891. {
  2892. G_SetOrigin( attacker, trace.endpos );
  2893. gi.linkentity( attacker );
  2894. }
  2895. //now get the defender's dist and do it for him too
  2896. vec3_t attDir;
  2897. VectorSubtract( attacker->currentOrigin, defender->currentOrigin, attDir );
  2898. diff = VectorNormalize( attDir ) - idealDist;//diff will be the total error in dist
  2899. //try to move defender all of the remaining diff towards the attacker
  2900. VectorMA( defender->currentOrigin, diff, attDir, newOrg );
  2901. gi.trace( &trace, defender->currentOrigin, defender->mins, defender->maxs, newOrg, defender->s.number, defender->clipmask );
  2902. if ( !trace.startsolid && !trace.allsolid )
  2903. {
  2904. G_SetOrigin( defender, trace.endpos );
  2905. gi.linkentity( defender );
  2906. }
  2907. //DONE!
  2908. return qtrue;
  2909. }
  2910. qboolean WP_SabersCheckLock( gentity_t *ent1, gentity_t *ent2 )
  2911. {
  2912. if ( ent1->client->playerTeam == ent2->client->playerTeam )
  2913. {
  2914. return qfalse;
  2915. }
  2916. if ( ent1->client->NPC_class == CLASS_SABER_DROID
  2917. || ent2->client->NPC_class == CLASS_SABER_DROID )
  2918. {//they don't have saberlock anims
  2919. return qfalse;
  2920. }
  2921. if ( ent1->client->ps.groundEntityNum == ENTITYNUM_NONE ||
  2922. ent2->client->ps.groundEntityNum == ENTITYNUM_NONE )
  2923. {
  2924. return qfalse;
  2925. }
  2926. if ( !ent1->client->ps.saber[0].lockable || !ent2->client->ps.saber[0].lockable )
  2927. {//one of these sabers cannot lock (like a lance)
  2928. //FIXME: check the second sabers too?
  2929. return qfalse;
  2930. }
  2931. if ( ent1->painDebounceTime > level.time-1000 || ent2->painDebounceTime > level.time-1000 )
  2932. {//can't saberlock if you're not ready
  2933. return qfalse;
  2934. }
  2935. if ( fabs( ent1->currentOrigin[2]-ent2->currentOrigin[2]) > 18 )
  2936. {
  2937. return qfalse;
  2938. }
  2939. float dist = DistanceSquared(ent1->currentOrigin,ent2->currentOrigin);
  2940. if ( dist < 64 || dist > 6400 )//( dist < 128 || dist > 2304 )
  2941. {//between 8 and 80 from each other//was 16 and 48
  2942. return qfalse;
  2943. }
  2944. if ( !InFOV( ent1, ent2, 40, 180 ) || !InFOV( ent2, ent1, 40, 180 ) )
  2945. {
  2946. return qfalse;
  2947. }
  2948. //Check for certain anims that *cannot* lock
  2949. //FIXME: there should probably be a whole *list* of these, but I'll put them in as they come up
  2950. if ( ent1->client->ps.torsoAnim == BOTH_A2_STABBACK1 && ent1->client->ps.torsoAnimTimer > 300 )
  2951. {//can't lock when saber is behind you
  2952. return qfalse;
  2953. }
  2954. if ( ent2->client->ps.torsoAnim == BOTH_A2_STABBACK1 && ent2->client->ps.torsoAnimTimer > 300 )
  2955. {//can't lock when saber is behind you
  2956. return qfalse;
  2957. }
  2958. if ( PM_LockedAnim( ent1->client->ps.torsoAnim )
  2959. || PM_LockedAnim( ent2->client->ps.torsoAnim ) )
  2960. {//stuck doing something else
  2961. return qfalse;
  2962. }
  2963. if ( PM_SaberLockBreakAnim( ent1->client->ps.torsoAnim )
  2964. || PM_SaberLockBreakAnim( ent2->client->ps.torsoAnim ) )
  2965. {//still finishing the last lock break!
  2966. return qfalse;
  2967. }
  2968. //BR to TL lock
  2969. if ( ent1->client->ps.torsoAnim == BOTH_A1_BR_TL ||
  2970. ent1->client->ps.torsoAnim == BOTH_A2_BR_TL ||
  2971. ent1->client->ps.torsoAnim == BOTH_A3_BR_TL ||
  2972. ent1->client->ps.torsoAnim == BOTH_A4_BR_TL ||
  2973. ent1->client->ps.torsoAnim == BOTH_A5_BR_TL ||
  2974. ent1->client->ps.torsoAnim == BOTH_A6_BR_TL ||
  2975. ent1->client->ps.torsoAnim == BOTH_A7_BR_TL )
  2976. {//ent1 is attacking in the opposite diagonal
  2977. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_BR );
  2978. }
  2979. if ( ent2->client->ps.torsoAnim == BOTH_A1_BR_TL ||
  2980. ent2->client->ps.torsoAnim == BOTH_A2_BR_TL ||
  2981. ent2->client->ps.torsoAnim == BOTH_A3_BR_TL ||
  2982. ent2->client->ps.torsoAnim == BOTH_A4_BR_TL ||
  2983. ent2->client->ps.torsoAnim == BOTH_A5_BR_TL ||
  2984. ent2->client->ps.torsoAnim == BOTH_A6_BR_TL ||
  2985. ent2->client->ps.torsoAnim == BOTH_A7_BR_TL )
  2986. {//ent2 is attacking in the opposite diagonal
  2987. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_BR );
  2988. }
  2989. //BL to TR lock
  2990. if ( ent1->client->ps.torsoAnim == BOTH_A1_BL_TR ||
  2991. ent1->client->ps.torsoAnim == BOTH_A2_BL_TR ||
  2992. ent1->client->ps.torsoAnim == BOTH_A3_BL_TR ||
  2993. ent1->client->ps.torsoAnim == BOTH_A4_BL_TR ||
  2994. ent1->client->ps.torsoAnim == BOTH_A5_BL_TR ||
  2995. ent1->client->ps.torsoAnim == BOTH_A6_BL_TR ||
  2996. ent1->client->ps.torsoAnim == BOTH_A7_BL_TR )
  2997. {//ent1 is attacking in the opposite diagonal
  2998. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_BL );
  2999. }
  3000. if ( ent2->client->ps.torsoAnim == BOTH_A1_BL_TR ||
  3001. ent2->client->ps.torsoAnim == BOTH_A2_BL_TR ||
  3002. ent2->client->ps.torsoAnim == BOTH_A3_BL_TR ||
  3003. ent2->client->ps.torsoAnim == BOTH_A4_BL_TR ||
  3004. ent2->client->ps.torsoAnim == BOTH_A5_BL_TR ||
  3005. ent2->client->ps.torsoAnim == BOTH_A6_BL_TR ||
  3006. ent2->client->ps.torsoAnim == BOTH_A7_BL_TR )
  3007. {//ent2 is attacking in the opposite diagonal
  3008. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_BL );
  3009. }
  3010. //L to R lock
  3011. if ( ent1->client->ps.torsoAnim == BOTH_A1__L__R ||
  3012. ent1->client->ps.torsoAnim == BOTH_A2__L__R ||
  3013. ent1->client->ps.torsoAnim == BOTH_A3__L__R ||
  3014. ent1->client->ps.torsoAnim == BOTH_A4__L__R ||
  3015. ent1->client->ps.torsoAnim == BOTH_A5__L__R ||
  3016. ent1->client->ps.torsoAnim == BOTH_A6__L__R ||
  3017. ent1->client->ps.torsoAnim == BOTH_A7__L__R )
  3018. {//ent1 is attacking l to r
  3019. return WP_SabersCheckLock2( ent1, ent2, LOCK_L );
  3020. /*
  3021. if ( ent2BlockingPlayer )
  3022. {//player will block this anyway
  3023. return WP_SabersCheckLock2( ent1, ent2, LOCK_L );
  3024. }
  3025. if ( ent2->client->ps.torsoAnim == BOTH_A1_TL_BR ||
  3026. ent2->client->ps.torsoAnim == BOTH_A2_TL_BR ||
  3027. ent2->client->ps.torsoAnim == BOTH_A3_TL_BR ||
  3028. ent2->client->ps.torsoAnim == BOTH_A4_TL_BR ||
  3029. ent2->client->ps.torsoAnim == BOTH_A5_TL_BR ||
  3030. ent2->client->ps.torsoAnim == BOTH_A6_TL_BR ||
  3031. ent2->client->ps.torsoAnim == BOTH_A7_TL_BR ||
  3032. ent2->client->ps.torsoAnim == BOTH_P1_S1_TR ||
  3033. ent2->client->ps.torsoAnim == BOTH_P1_S1_BL )
  3034. {//ent2 is attacking or blocking on the r
  3035. return WP_SabersCheckLock2( ent1, ent2, LOCK_L );
  3036. }
  3037. if ( ent2Boss && !Q_irand( 0, 3 ) )
  3038. {
  3039. return WP_SabersCheckLock2( ent1, ent2, LOCK_L );
  3040. }
  3041. */
  3042. }
  3043. if ( ent2->client->ps.torsoAnim == BOTH_A1__L__R ||
  3044. ent2->client->ps.torsoAnim == BOTH_A2__L__R ||
  3045. ent2->client->ps.torsoAnim == BOTH_A3__L__R ||
  3046. ent2->client->ps.torsoAnim == BOTH_A4__L__R ||
  3047. ent2->client->ps.torsoAnim == BOTH_A5__L__R ||
  3048. ent2->client->ps.torsoAnim == BOTH_A6__L__R ||
  3049. ent2->client->ps.torsoAnim == BOTH_A7__L__R )
  3050. {//ent2 is attacking l to r
  3051. return WP_SabersCheckLock2( ent2, ent1, LOCK_L );
  3052. /*
  3053. if ( ent1BlockingPlayer )
  3054. {//player will block this anyway
  3055. return WP_SabersCheckLock2( ent2, ent1, LOCK_L );
  3056. }
  3057. if ( ent1->client->ps.torsoAnim == BOTH_A1_TL_BR ||
  3058. ent1->client->ps.torsoAnim == BOTH_A2_TL_BR ||
  3059. ent1->client->ps.torsoAnim == BOTH_A3_TL_BR ||
  3060. ent1->client->ps.torsoAnim == BOTH_A4_TL_BR ||
  3061. ent1->client->ps.torsoAnim == BOTH_A5_TL_BR ||
  3062. ent1->client->ps.torsoAnim == BOTH_A6_TL_BR ||
  3063. ent1->client->ps.torsoAnim == BOTH_A7_TL_BR ||
  3064. ent1->client->ps.torsoAnim == BOTH_P1_S1_TR ||
  3065. ent1->client->ps.torsoAnim == BOTH_P1_S1_BL )
  3066. {//ent1 is attacking or blocking on the r
  3067. return WP_SabersCheckLock2( ent2, ent1, LOCK_L );
  3068. }
  3069. if ( ent1Boss && !Q_irand( 0, 3 ) )
  3070. {
  3071. return WP_SabersCheckLock2( ent2, ent1, LOCK_L );
  3072. }
  3073. */
  3074. }
  3075. //R to L lock
  3076. if ( ent1->client->ps.torsoAnim == BOTH_A1__R__L ||
  3077. ent1->client->ps.torsoAnim == BOTH_A2__R__L ||
  3078. ent1->client->ps.torsoAnim == BOTH_A3__R__L ||
  3079. ent1->client->ps.torsoAnim == BOTH_A4__R__L ||
  3080. ent1->client->ps.torsoAnim == BOTH_A5__R__L ||
  3081. ent1->client->ps.torsoAnim == BOTH_A6__R__L ||
  3082. ent1->client->ps.torsoAnim == BOTH_A7__R__L )
  3083. {//ent1 is attacking r to l
  3084. return WP_SabersCheckLock2( ent1, ent2, LOCK_R );
  3085. /*
  3086. if ( ent2BlockingPlayer )
  3087. {//player will block this anyway
  3088. return WP_SabersCheckLock2( ent1, ent2, LOCK_R );
  3089. }
  3090. if ( ent2->client->ps.torsoAnim == BOTH_A1_TR_BL ||
  3091. ent2->client->ps.torsoAnim == BOTH_A2_TR_BL ||
  3092. ent2->client->ps.torsoAnim == BOTH_A3_TR_BL ||
  3093. ent2->client->ps.torsoAnim == BOTH_A4_TR_BL ||
  3094. ent2->client->ps.torsoAnim == BOTH_A5_TR_BL ||
  3095. ent2->client->ps.torsoAnim == BOTH_A6_TR_BL ||
  3096. ent2->client->ps.torsoAnim == BOTH_A7_TR_BL ||
  3097. ent2->client->ps.torsoAnim == BOTH_P1_S1_TL ||
  3098. ent2->client->ps.torsoAnim == BOTH_P1_S1_BR )
  3099. {//ent2 is attacking or blocking on the l
  3100. return WP_SabersCheckLock2( ent1, ent2, LOCK_R );
  3101. }
  3102. if ( ent2Boss && !Q_irand( 0, 3 ) )
  3103. {
  3104. return WP_SabersCheckLock2( ent1, ent2, LOCK_R );
  3105. }
  3106. */
  3107. }
  3108. if ( ent2->client->ps.torsoAnim == BOTH_A1__R__L ||
  3109. ent2->client->ps.torsoAnim == BOTH_A2__R__L ||
  3110. ent2->client->ps.torsoAnim == BOTH_A3__R__L ||
  3111. ent2->client->ps.torsoAnim == BOTH_A4__R__L ||
  3112. ent2->client->ps.torsoAnim == BOTH_A5__R__L ||
  3113. ent2->client->ps.torsoAnim == BOTH_A6__R__L ||
  3114. ent2->client->ps.torsoAnim == BOTH_A7__R__L )
  3115. {//ent2 is attacking r to l
  3116. return WP_SabersCheckLock2( ent2, ent1, LOCK_R );
  3117. /*
  3118. if ( ent1BlockingPlayer )
  3119. {//player will block this anyway
  3120. return WP_SabersCheckLock2( ent2, ent1, LOCK_R );
  3121. }
  3122. if ( ent1->client->ps.torsoAnim == BOTH_A1_TR_BL ||
  3123. ent1->client->ps.torsoAnim == BOTH_A2_TR_BL ||
  3124. ent1->client->ps.torsoAnim == BOTH_A3_TR_BL ||
  3125. ent1->client->ps.torsoAnim == BOTH_A4_TR_BL ||
  3126. ent1->client->ps.torsoAnim == BOTH_A5_TR_BL ||
  3127. ent1->client->ps.torsoAnim == BOTH_A6_TR_BL ||
  3128. ent1->client->ps.torsoAnim == BOTH_A7_TR_BL ||
  3129. ent1->client->ps.torsoAnim == BOTH_P1_S1_TL ||
  3130. ent1->client->ps.torsoAnim == BOTH_P1_S1_BR )
  3131. {//ent1 is attacking or blocking on the l
  3132. return WP_SabersCheckLock2( ent2, ent1, LOCK_R );
  3133. }
  3134. if ( ent1Boss && !Q_irand( 0, 3 ) )
  3135. {
  3136. return WP_SabersCheckLock2( ent2, ent1, LOCK_R );
  3137. }
  3138. */
  3139. }
  3140. //TR to BL lock
  3141. if ( ent1->client->ps.torsoAnim == BOTH_A1_TR_BL ||
  3142. ent1->client->ps.torsoAnim == BOTH_A2_TR_BL ||
  3143. ent1->client->ps.torsoAnim == BOTH_A3_TR_BL ||
  3144. ent1->client->ps.torsoAnim == BOTH_A4_TR_BL ||
  3145. ent1->client->ps.torsoAnim == BOTH_A5_TR_BL ||
  3146. ent1->client->ps.torsoAnim == BOTH_A6_TR_BL ||
  3147. ent1->client->ps.torsoAnim == BOTH_A7_TR_BL )
  3148. {//ent1 is attacking diagonally
  3149. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_TR );
  3150. /*
  3151. if ( ent2BlockingPlayer )
  3152. {//player will block this anyway
  3153. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_TR );
  3154. }
  3155. if ( ent2->client->ps.torsoAnim == BOTH_A1_TR_BL ||
  3156. ent2->client->ps.torsoAnim == BOTH_A2_TR_BL ||
  3157. ent2->client->ps.torsoAnim == BOTH_A3_TR_BL ||
  3158. ent2->client->ps.torsoAnim == BOTH_A4_TR_BL ||
  3159. ent2->client->ps.torsoAnim == BOTH_A5_TR_BL ||
  3160. ent2->client->ps.torsoAnim == BOTH_A6_TR_BL ||
  3161. ent2->client->ps.torsoAnim == BOTH_A7_TR_BL ||
  3162. ent2->client->ps.torsoAnim == BOTH_P1_S1_TL )
  3163. {//ent2 is attacking in the opposite diagonal
  3164. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_TR );
  3165. }
  3166. if ( ent2->client->ps.torsoAnim == BOTH_A1_BR_TL ||
  3167. ent2->client->ps.torsoAnim == BOTH_A2_BR_TL ||
  3168. ent2->client->ps.torsoAnim == BOTH_A3_BR_TL ||
  3169. ent2->client->ps.torsoAnim == BOTH_A4_BR_TL ||
  3170. ent2->client->ps.torsoAnim == BOTH_A5_BR_TL ||
  3171. ent2->client->ps.torsoAnim == BOTH_A6_BR_TL ||
  3172. ent2->client->ps.torsoAnim == BOTH_A7_BR_TL ||
  3173. ent2->client->ps.torsoAnim == BOTH_P1_S1_BL )
  3174. {//ent2 is attacking in the opposite diagonal
  3175. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_BL );
  3176. }
  3177. if ( ent2Boss && !Q_irand( 0, 3 ) )
  3178. {
  3179. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_TR );
  3180. }
  3181. */
  3182. }
  3183. if ( ent2->client->ps.torsoAnim == BOTH_A1_TR_BL ||
  3184. ent2->client->ps.torsoAnim == BOTH_A2_TR_BL ||
  3185. ent2->client->ps.torsoAnim == BOTH_A3_TR_BL ||
  3186. ent2->client->ps.torsoAnim == BOTH_A4_TR_BL ||
  3187. ent2->client->ps.torsoAnim == BOTH_A5_TR_BL ||
  3188. ent2->client->ps.torsoAnim == BOTH_A6_TR_BL ||
  3189. ent2->client->ps.torsoAnim == BOTH_A7_TR_BL )
  3190. {//ent2 is attacking diagonally
  3191. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_TR );
  3192. /*
  3193. if ( ent1BlockingPlayer )
  3194. {//player will block this anyway
  3195. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_TR );
  3196. }
  3197. if ( ent1->client->ps.torsoAnim == BOTH_A1_TR_BL ||
  3198. ent1->client->ps.torsoAnim == BOTH_A2_TR_BL ||
  3199. ent1->client->ps.torsoAnim == BOTH_A3_TR_BL ||
  3200. ent1->client->ps.torsoAnim == BOTH_A4_TR_BL ||
  3201. ent1->client->ps.torsoAnim == BOTH_A5_TR_BL ||
  3202. ent1->client->ps.torsoAnim == BOTH_A6_TR_BL ||
  3203. ent1->client->ps.torsoAnim == BOTH_A7_TR_BL ||
  3204. ent1->client->ps.torsoAnim == BOTH_P1_S1_TL )
  3205. {//ent1 is attacking in the opposite diagonal
  3206. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_TR );
  3207. }
  3208. if ( ent1->client->ps.torsoAnim == BOTH_A1_BR_TL ||
  3209. ent1->client->ps.torsoAnim == BOTH_A2_BR_TL ||
  3210. ent1->client->ps.torsoAnim == BOTH_A3_BR_TL ||
  3211. ent1->client->ps.torsoAnim == BOTH_A4_BR_TL ||
  3212. ent1->client->ps.torsoAnim == BOTH_A5_BR_TL ||
  3213. ent1->client->ps.torsoAnim == BOTH_A6_BR_TL ||
  3214. ent1->client->ps.torsoAnim == BOTH_A7_BR_TL ||
  3215. ent1->client->ps.torsoAnim == BOTH_P1_S1_BL )
  3216. {//ent1 is attacking in the opposite diagonal
  3217. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_BL );
  3218. }
  3219. if ( ent1Boss && !Q_irand( 0, 3 ) )
  3220. {
  3221. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_TR );
  3222. }
  3223. */
  3224. }
  3225. //TL to BR lock
  3226. if ( ent1->client->ps.torsoAnim == BOTH_A1_TL_BR ||
  3227. ent1->client->ps.torsoAnim == BOTH_A2_TL_BR ||
  3228. ent1->client->ps.torsoAnim == BOTH_A3_TL_BR ||
  3229. ent1->client->ps.torsoAnim == BOTH_A4_TL_BR ||
  3230. ent1->client->ps.torsoAnim == BOTH_A5_TL_BR ||
  3231. ent1->client->ps.torsoAnim == BOTH_A6_TL_BR ||
  3232. ent1->client->ps.torsoAnim == BOTH_A7_TL_BR )
  3233. {//ent1 is attacking diagonally
  3234. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_TL );
  3235. /*
  3236. if ( ent2BlockingPlayer )
  3237. {//player will block this anyway
  3238. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_TL );
  3239. }
  3240. if ( ent2->client->ps.torsoAnim == BOTH_A1_TL_BR ||
  3241. ent2->client->ps.torsoAnim == BOTH_A2_TL_BR ||
  3242. ent2->client->ps.torsoAnim == BOTH_A3_TL_BR ||
  3243. ent2->client->ps.torsoAnim == BOTH_A4_TL_BR ||
  3244. ent2->client->ps.torsoAnim == BOTH_A5_TL_BR ||
  3245. ent2->client->ps.torsoAnim == BOTH_A6_TL_BR ||
  3246. ent2->client->ps.torsoAnim == BOTH_A7_TL_BR ||
  3247. ent2->client->ps.torsoAnim == BOTH_P1_S1_TR )
  3248. {//ent2 is attacking in the opposite diagonal
  3249. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_TL );
  3250. }
  3251. if ( ent2->client->ps.torsoAnim == BOTH_A1_BL_TR ||
  3252. ent2->client->ps.torsoAnim == BOTH_A2_BL_TR ||
  3253. ent2->client->ps.torsoAnim == BOTH_A3_BL_TR ||
  3254. ent2->client->ps.torsoAnim == BOTH_A4_BL_TR ||
  3255. ent2->client->ps.torsoAnim == BOTH_A5_BL_TR ||
  3256. ent2->client->ps.torsoAnim == BOTH_A6_BL_TR ||
  3257. ent2->client->ps.torsoAnim == BOTH_A7_BL_TR ||
  3258. ent2->client->ps.torsoAnim == BOTH_P1_S1_BR )
  3259. {//ent2 is attacking in the opposite diagonal
  3260. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_BR );
  3261. }
  3262. if ( ent2Boss && !Q_irand( 0, 3 ) )
  3263. {
  3264. return WP_SabersCheckLock2( ent1, ent2, LOCK_DIAG_TL );
  3265. }
  3266. */
  3267. }
  3268. if ( ent2->client->ps.torsoAnim == BOTH_A1_TL_BR ||
  3269. ent2->client->ps.torsoAnim == BOTH_A2_TL_BR ||
  3270. ent2->client->ps.torsoAnim == BOTH_A3_TL_BR ||
  3271. ent2->client->ps.torsoAnim == BOTH_A4_TL_BR ||
  3272. ent2->client->ps.torsoAnim == BOTH_A5_TL_BR ||
  3273. ent2->client->ps.torsoAnim == BOTH_A6_TL_BR ||
  3274. ent2->client->ps.torsoAnim == BOTH_A7_TL_BR )
  3275. {//ent2 is attacking diagonally
  3276. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_TL );
  3277. /*
  3278. if ( ent1BlockingPlayer )
  3279. {//player will block this anyway
  3280. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_TL );
  3281. }
  3282. if ( ent1->client->ps.torsoAnim == BOTH_A1_TL_BR ||
  3283. ent1->client->ps.torsoAnim == BOTH_A2_TL_BR ||
  3284. ent1->client->ps.torsoAnim == BOTH_A3_TL_BR ||
  3285. ent1->client->ps.torsoAnim == BOTH_A4_TL_BR ||
  3286. ent1->client->ps.torsoAnim == BOTH_A5_TL_BR ||
  3287. ent1->client->ps.torsoAnim == BOTH_A6_TL_BR ||
  3288. ent1->client->ps.torsoAnim == BOTH_A7_TL_BR ||
  3289. ent1->client->ps.torsoAnim == BOTH_P1_S1_TR )
  3290. {//ent1 is attacking in the opposite diagonal
  3291. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_TL );
  3292. }
  3293. if ( ent1->client->ps.torsoAnim == BOTH_A1_BL_TR ||
  3294. ent1->client->ps.torsoAnim == BOTH_A2_BL_TR ||
  3295. ent1->client->ps.torsoAnim == BOTH_A3_BL_TR ||
  3296. ent1->client->ps.torsoAnim == BOTH_A4_BL_TR ||
  3297. ent1->client->ps.torsoAnim == BOTH_A5_BL_TR ||
  3298. ent1->client->ps.torsoAnim == BOTH_A6_BL_TR ||
  3299. ent1->client->ps.torsoAnim == BOTH_A7_BL_TR ||
  3300. ent1->client->ps.torsoAnim == BOTH_P1_S1_BR )
  3301. {//ent1 is attacking in the opposite diagonal
  3302. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_BR );
  3303. }
  3304. if ( ent1Boss && !Q_irand( 0, 3 ) )
  3305. {
  3306. return WP_SabersCheckLock2( ent2, ent1, LOCK_DIAG_TL );
  3307. }
  3308. */
  3309. }
  3310. //T to B lock
  3311. if ( ent1->client->ps.torsoAnim == BOTH_A1_T__B_ ||
  3312. ent1->client->ps.torsoAnim == BOTH_A2_T__B_ ||
  3313. ent1->client->ps.torsoAnim == BOTH_A3_T__B_ ||
  3314. ent1->client->ps.torsoAnim == BOTH_A4_T__B_ ||
  3315. ent1->client->ps.torsoAnim == BOTH_A5_T__B_ ||
  3316. ent1->client->ps.torsoAnim == BOTH_A6_T__B_ ||
  3317. ent1->client->ps.torsoAnim == BOTH_A7_T__B_ )
  3318. {//ent1 is attacking top-down
  3319. /*
  3320. if ( ent2->client->ps.torsoAnim == BOTH_P1_S1_T_ ||
  3321. ent2->client->ps.torsoAnim == BOTH_K1_S1_T_ )
  3322. */
  3323. {//ent2 is blocking at top
  3324. return WP_SabersCheckLock2( ent1, ent2, LOCK_TOP );
  3325. }
  3326. }
  3327. if ( ent2->client->ps.torsoAnim == BOTH_A1_T__B_ ||
  3328. ent2->client->ps.torsoAnim == BOTH_A2_T__B_ ||
  3329. ent2->client->ps.torsoAnim == BOTH_A3_T__B_ ||
  3330. ent2->client->ps.torsoAnim == BOTH_A4_T__B_ ||
  3331. ent2->client->ps.torsoAnim == BOTH_A5_T__B_ ||
  3332. ent2->client->ps.torsoAnim == BOTH_A6_T__B_ ||
  3333. ent2->client->ps.torsoAnim == BOTH_A7_T__B_ )
  3334. {//ent2 is attacking top-down
  3335. /*
  3336. if ( ent1->client->ps.torsoAnim == BOTH_P1_S1_T_ ||
  3337. ent1->client->ps.torsoAnim == BOTH_K1_S1_T_ )
  3338. */
  3339. {//ent1 is blocking at top
  3340. return WP_SabersCheckLock2( ent2, ent1, LOCK_TOP );
  3341. }
  3342. }
  3343. /*
  3344. if ( !Q_irand( 0, 10 ) )
  3345. {
  3346. return WP_SabersCheckLock2( ent1, ent2, LOCK_RANDOM );
  3347. }
  3348. */
  3349. return qfalse;
  3350. }
  3351. qboolean WP_SaberParry( gentity_t *victim, gentity_t *attacker )
  3352. {
  3353. if ( !victim || !victim->client || !attacker )
  3354. {
  3355. return qfalse;
  3356. }
  3357. if ( Rosh_BeingHealed( victim ) )
  3358. {
  3359. return qfalse;
  3360. }
  3361. if ( G_InCinematicSaberAnim( victim ) )
  3362. {
  3363. return qfalse;
  3364. }
  3365. if ( PM_SuperBreakLoseAnim( victim->client->ps.torsoAnim )
  3366. || PM_SuperBreakWinAnim( victim->client->ps.torsoAnim ) )
  3367. {
  3368. return qfalse;
  3369. }
  3370. if ( victim->s.number || g_saberAutoBlocking->integer || victim->client->ps.saberBlockingTime > level.time )
  3371. {//either an NPC or a player who is blocking
  3372. if ( !PM_SaberInTransitionAny( victim->client->ps.saberMove )
  3373. && !PM_SaberInBounce( victim->client->ps.saberMove )
  3374. && !PM_SaberInKnockaway( victim->client->ps.saberMove ) )
  3375. {//I'm not attacking, in transition or in a bounce or knockaway, so play a parry
  3376. WP_SaberBlockNonRandom( victim, saberHitLocation, qfalse );
  3377. }
  3378. victim->client->ps.saberEventFlags |= SEF_PARRIED;
  3379. //since it was parried, take away any damage done
  3380. //FIXME: what if the damage was done before the parry?
  3381. WP_SaberClearDamageForEntNum( victim->s.number );
  3382. //tell the victim to get mad at me
  3383. if ( victim->enemy != attacker && victim->client->playerTeam != attacker->client->playerTeam )
  3384. {//they're not mad at me and they're not on my team
  3385. G_ClearEnemy( victim );
  3386. G_SetEnemy( victim, attacker );
  3387. }
  3388. return qtrue;
  3389. }
  3390. return qfalse;
  3391. }
  3392. qboolean WP_BrokenParryKnockDown( gentity_t *victim )
  3393. {
  3394. if ( !victim || !victim->client )
  3395. {
  3396. return qfalse;
  3397. }
  3398. if ( PM_SuperBreakLoseAnim( victim->client->ps.torsoAnim )
  3399. || PM_SuperBreakWinAnim( victim->client->ps.torsoAnim ) )
  3400. {
  3401. return qfalse;
  3402. }
  3403. if ( victim->client->ps.saberMove == LS_PARRY_UP
  3404. || victim->client->ps.saberMove == LS_PARRY_UR
  3405. || victim->client->ps.saberMove == LS_PARRY_UL
  3406. || victim->client->ps.saberMove == LS_H1_BR
  3407. || victim->client->ps.saberMove == LS_H1_B_
  3408. || victim->client->ps.saberMove == LS_H1_BL )
  3409. {//knock their asses down!
  3410. int knockAnim = BOTH_KNOCKDOWN1;
  3411. if ( PM_CrouchAnim( victim->client->ps.legsAnim ) )
  3412. {
  3413. knockAnim = BOTH_KNOCKDOWN4;
  3414. }
  3415. NPC_SetAnim( victim, SETANIM_BOTH, knockAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  3416. G_AddEvent( victim, EV_PAIN, victim->health );
  3417. return qtrue;
  3418. }
  3419. return qfalse;
  3420. }
  3421. qboolean G_TryingKataAttack( gentity_t *self, usercmd_t *cmd )
  3422. {
  3423. if ( g_saberNewControlScheme->integer )
  3424. {//use the new control scheme: force focus button
  3425. if ( (cmd->buttons&BUTTON_FORCE_FOCUS) )
  3426. {
  3427. return qtrue;
  3428. }
  3429. else
  3430. {
  3431. return qfalse;
  3432. }
  3433. }
  3434. else //if ( self && self->client )
  3435. {//use the old control scheme
  3436. if ( (cmd->buttons&BUTTON_ALT_ATTACK) )
  3437. {//pressing alt-attack
  3438. //if ( !(self->client->ps.pm_flags&PMF_ALT_ATTACK_HELD) )
  3439. {//haven't been holding alt-attack
  3440. if ( (cmd->buttons&BUTTON_ATTACK) )
  3441. {//pressing attack
  3442. return qtrue;
  3443. }
  3444. }
  3445. }
  3446. }
  3447. return qfalse;
  3448. }
  3449. qboolean G_TryingPullAttack( gentity_t *self, usercmd_t *cmd, qboolean amPulling )
  3450. {
  3451. if ( g_saberNewControlScheme->integer )
  3452. {//use the new control scheme: force focus button
  3453. if ( (cmd->buttons&BUTTON_FORCE_FOCUS) )
  3454. {
  3455. if ( self && self->client )
  3456. {
  3457. if ( self->client->ps.forcePowerLevel[FP_PULL] >= FORCE_LEVEL_3 )
  3458. {//force pull 3
  3459. if ( amPulling
  3460. || (self->client->ps.forcePowersActive&(1<<FP_PULL))
  3461. || self->client->ps.forcePowerDebounce[FP_PULL] > level.time ) //force-pulling
  3462. {//pulling
  3463. return qtrue;
  3464. }
  3465. }
  3466. }
  3467. }
  3468. else
  3469. {
  3470. return qfalse;
  3471. }
  3472. }
  3473. else
  3474. {//use the old control scheme
  3475. if ( (cmd->buttons&BUTTON_ATTACK) )
  3476. {//pressing attack
  3477. if ( self && self->client )
  3478. {
  3479. if ( self->client->ps.forcePowerLevel[FP_PULL] >= FORCE_LEVEL_3 )
  3480. {//force pull 3
  3481. if ( amPulling
  3482. || (self->client->ps.forcePowersActive&(1<<FP_PULL))
  3483. || self->client->ps.forcePowerDebounce[FP_PULL] > level.time ) //force-pulling
  3484. {//pulling
  3485. return qtrue;
  3486. }
  3487. }
  3488. }
  3489. }
  3490. }
  3491. return qfalse;
  3492. }
  3493. qboolean G_TryingCartwheel( gentity_t *self, usercmd_t *cmd )
  3494. {
  3495. if ( g_saberNewControlScheme->integer )
  3496. {//use the new control scheme: force focus button
  3497. if ( (cmd->buttons&BUTTON_FORCE_FOCUS) )
  3498. {
  3499. return qtrue;
  3500. }
  3501. else
  3502. {
  3503. return qfalse;
  3504. }
  3505. }
  3506. else
  3507. {//use the old control scheme
  3508. if ( (cmd->buttons&BUTTON_ATTACK) )
  3509. {//pressing attack
  3510. if ( cmd->rightmove )
  3511. {
  3512. if ( self && self->client )
  3513. {
  3514. if ( cmd->upmove>0 //)
  3515. && self->client->ps.groundEntityNum != ENTITYNUM_NONE )
  3516. {//on ground, pressing jump
  3517. return qtrue;
  3518. }
  3519. else
  3520. {//just jumped?
  3521. if ( self->client->ps.groundEntityNum == ENTITYNUM_NONE
  3522. && level.time - self->client->ps.lastOnGround <= 250 //50//250
  3523. && (self->client->ps.pm_flags&PMF_JUMPING) )//jumping
  3524. {//just jumped this or last frame
  3525. return qtrue;
  3526. }
  3527. }
  3528. }
  3529. }
  3530. }
  3531. }
  3532. return qfalse;
  3533. }
  3534. qboolean G_TryingSpecial( gentity_t *self, usercmd_t *cmd )
  3535. {
  3536. if ( g_saberNewControlScheme->integer )
  3537. {//use the new control scheme: force focus button
  3538. if ( (cmd->buttons&BUTTON_FORCE_FOCUS) )
  3539. {
  3540. return qtrue;
  3541. }
  3542. else
  3543. {
  3544. return qfalse;
  3545. }
  3546. }
  3547. else
  3548. {//use the old control scheme
  3549. return qfalse;
  3550. }
  3551. }
  3552. qboolean G_TryingJumpAttack( gentity_t *self, usercmd_t *cmd )
  3553. {
  3554. if ( g_saberNewControlScheme->integer )
  3555. {//use the new control scheme: force focus button
  3556. if ( (cmd->buttons&BUTTON_FORCE_FOCUS) )
  3557. {
  3558. return qtrue;
  3559. }
  3560. else
  3561. {
  3562. return qfalse;
  3563. }
  3564. }
  3565. else
  3566. {//use the old control scheme
  3567. if ( (cmd->buttons&BUTTON_ATTACK) )
  3568. {//pressing attack
  3569. if ( cmd->upmove>0 )
  3570. {//pressing jump
  3571. return qtrue;
  3572. }
  3573. else if ( self && self->client )
  3574. {//just jumped?
  3575. if ( self->client->ps.groundEntityNum == ENTITYNUM_NONE
  3576. && level.time - self->client->ps.lastOnGround <= 250
  3577. && (self->client->ps.pm_flags&PMF_JUMPING) )//jumping
  3578. {//jumped within the last quarter second
  3579. return qtrue;
  3580. }
  3581. }
  3582. }
  3583. }
  3584. return qfalse;
  3585. }
  3586. qboolean G_TryingJumpForwardAttack( gentity_t *self, usercmd_t *cmd )
  3587. {
  3588. if ( g_saberNewControlScheme->integer )
  3589. {//use the new control scheme: force focus button
  3590. if ( (cmd->buttons&BUTTON_FORCE_FOCUS) )
  3591. {
  3592. return qtrue;
  3593. }
  3594. else
  3595. {
  3596. return qfalse;
  3597. }
  3598. }
  3599. else
  3600. {//use the old control scheme
  3601. if ( (cmd->buttons&BUTTON_ATTACK) )
  3602. {//pressing attack
  3603. if ( cmd->forwardmove > 0 )
  3604. {//moving forward
  3605. if ( self && self->client )
  3606. {
  3607. if ( cmd->upmove>0
  3608. && self->client->ps.groundEntityNum != ENTITYNUM_NONE )
  3609. {//pressing jump
  3610. return qtrue;
  3611. }
  3612. else
  3613. {//no slop on forward jumps - must be precise!
  3614. if ( self->client->ps.groundEntityNum == ENTITYNUM_NONE
  3615. && level.time - self->client->ps.lastOnGround <= 250 //50
  3616. && (self->client->ps.pm_flags&PMF_JUMPING) )//jumping
  3617. {//just jumped this or last frame
  3618. return qtrue;
  3619. }
  3620. }
  3621. }
  3622. }
  3623. }
  3624. }
  3625. return qfalse;
  3626. }
  3627. qboolean G_TryingLungeAttack( gentity_t *self, usercmd_t *cmd )
  3628. {
  3629. if ( g_saberNewControlScheme->integer )
  3630. {//use the new control scheme: force focus button
  3631. if ( (cmd->buttons&BUTTON_FORCE_FOCUS) )
  3632. {
  3633. return qtrue;
  3634. }
  3635. else
  3636. {
  3637. return qfalse;
  3638. }
  3639. }
  3640. else
  3641. {//use the old control scheme
  3642. if ( (cmd->buttons&BUTTON_ATTACK) )
  3643. {//pressing attack
  3644. if ( cmd->upmove<0 )
  3645. {//pressing crouch
  3646. return qtrue;
  3647. }
  3648. else if ( self && self->client )
  3649. {//just unducked?
  3650. if ( (self->client->ps.pm_flags&PMF_DUCKED) )
  3651. {//just unducking
  3652. return qtrue;
  3653. }
  3654. }
  3655. }
  3656. }
  3657. return qfalse;
  3658. }
  3659. //FIXME: for these below funcs, maybe in the old control scheme some moves should still cost power... if so, pass in the saberMove and use a switch statement
  3660. qboolean G_EnoughPowerForSpecialMove( int forcePower, int cost, qboolean kataMove )
  3661. {
  3662. if ( g_saberNewControlScheme->integer || kataMove )
  3663. {//special moves cost power
  3664. if ( forcePower >= cost )
  3665. {
  3666. return qtrue;
  3667. }
  3668. else
  3669. {
  3670. cg.forceHUDTotalFlashTime = level.time + 1000;
  3671. return qfalse;
  3672. }
  3673. }
  3674. else
  3675. {//old control scheme: uses no power, so just do it
  3676. return qtrue;
  3677. }
  3678. }
  3679. void G_DrainPowerForSpecialMove( gentity_t *self, forcePowers_t fp, int cost, qboolean kataMove )
  3680. {
  3681. if ( !self || !self->client || self->s.number >= MAX_CLIENTS )
  3682. {
  3683. return;
  3684. }
  3685. if ( g_saberNewControlScheme->integer || kataMove )
  3686. {//special moves cost power
  3687. WP_ForcePowerDrain( self, fp, cost );//drain the required force power
  3688. }
  3689. else
  3690. {//old control scheme: uses no power, so just do it
  3691. }
  3692. }
  3693. int G_CostForSpecialMove( int cost, qboolean kataMove )
  3694. {
  3695. if ( g_saberNewControlScheme->integer || kataMove )
  3696. {//special moves cost power
  3697. return cost;
  3698. }
  3699. else
  3700. {//old control scheme: uses no power, so just do it
  3701. return 0;
  3702. }
  3703. }
  3704. /*
  3705. ---------------------------------------------------------
  3706. void WP_SaberDamageTrace( gentity_t *ent, int saberNum, int bladeNum )
  3707. Constantly trace from the old blade pos to new, down the saber beam and do damage
  3708. FIXME: if the dot product of the old muzzle dir and the new muzzle dir is < 0.75, subdivide it and do multiple traces so we don't flatten out the arc!
  3709. ---------------------------------------------------------
  3710. */
  3711. #define MAX_SABER_SWING_INC 0.33f
  3712. void WP_SaberDamageTrace( gentity_t *ent, int saberNum, int bladeNum )
  3713. {
  3714. vec3_t mp1, mp2, md1, md2, baseOld, baseNew, baseDiff, endOld, endNew, bladePointOld, bladePointNew;
  3715. float tipDmgMod = 1.0f;
  3716. float baseDamage;
  3717. int baseDFlags = 0;
  3718. qboolean hit_wall = qfalse;
  3719. qboolean brokenParry = qfalse;
  3720. for ( int ven = 0; ven < MAX_SABER_VICTIMS; ven++ )
  3721. {
  3722. victimEntityNum[ven] = ENTITYNUM_NONE;
  3723. }
  3724. memset( totalDmg, 0, sizeof( totalDmg) );
  3725. memset( dmgDir, 0, sizeof( dmgDir ) );
  3726. memset( dmgSpot, 0, sizeof( dmgSpot ) );
  3727. memset( dmgFraction, 0, sizeof( dmgFraction ) );
  3728. memset( hitLoc, HL_NONE, sizeof( hitLoc ) );
  3729. memset( hitDismemberLoc, HL_NONE, sizeof( hitDismemberLoc ) );
  3730. memset( hitDismember, qfalse, sizeof( hitDismember ) );
  3731. numVictims = 0;
  3732. VectorClear(saberHitLocation);
  3733. VectorClear(saberHitNormal);
  3734. saberHitFraction = 1.0; // Closest saber hit. The saber can do no damage past this point.
  3735. saberHitEntity = ENTITYNUM_NONE;
  3736. sabersCrossed = -1;
  3737. if ( !ent->client )
  3738. {
  3739. return;
  3740. }
  3741. if ( !ent->s.number )
  3742. {//player never uses these
  3743. ent->client->ps.saberEventFlags &= ~SEF_EVENTS;
  3744. }
  3745. if ( ent->client->ps.saber[saberNum].blade[bladeNum].length <= 1 )//cen get down to 1 when in a wall
  3746. {//saber is not on
  3747. return;
  3748. }
  3749. if ( VectorCompare( ent->client->renderInfo.muzzlePointOld, vec3_origin ) || VectorCompare( ent->client->renderInfo.muzzleDirOld, vec3_origin ) )
  3750. {
  3751. //just started up the saber?
  3752. return;
  3753. }
  3754. int saberContents = gi.pointcontents( ent->client->renderInfo.muzzlePoint, ent->client->ps.saberEntityNum );
  3755. if ( (saberContents&CONTENTS_WATER)||
  3756. (saberContents&CONTENTS_SLIME)||
  3757. (saberContents&CONTENTS_LAVA) )
  3758. {//um... turn off? Or just set length to 1?
  3759. //FIXME: short-out effect/sound?
  3760. ent->client->ps.saber[saberNum].blade[bladeNum].active = qfalse;
  3761. return;
  3762. }
  3763. else if (!g_saberNoEffects && gi.WE_IsOutside(ent->client->renderInfo.muzzlePoint))
  3764. {
  3765. float chanceOfFizz = gi.WE_GetChanceOfSaberFizz();
  3766. if (chanceOfFizz>0 && Q_flrand(0.0f, 1.0f)<chanceOfFizz)
  3767. {
  3768. vec3_t end; /*normal = {0,0,1};//FIXME: opposite of rain angles?*/
  3769. VectorMA( ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint, ent->client->ps.saber[saberNum].blade[bladeNum].length*Q_flrand(0, 1), ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDir, end );
  3770. G_PlayEffect( "saber/fizz", end );
  3771. // if(ent->client && ent->client->ps.clientNum == 0)
  3772. // FF_Play(fffx_Laser1);
  3773. }
  3774. }
  3775. //FIXMEFIXMEFIXME: When in force speed (esp. lvl 3), need to interpolate this because
  3776. // we animate so much faster that the arc is pretty much flat...
  3777. int entPowerLevel = 0;
  3778. if ( ent->client->NPC_class == CLASS_SABER_DROID )
  3779. {
  3780. entPowerLevel = SaberDroid_PowerLevelForSaberAnim( ent );
  3781. }
  3782. else if ( !ent->s.number && (ent->client->ps.forcePowersActive&(1<<FP_SPEED)) )
  3783. {
  3784. entPowerLevel = FORCE_LEVEL_3;
  3785. }
  3786. else
  3787. {
  3788. entPowerLevel = PM_PowerLevelForSaberAnim( &ent->client->ps, saberNum );
  3789. }
  3790. if ( entPowerLevel )
  3791. {
  3792. if ( ent->client->ps.forceRageRecoveryTime > level.time )
  3793. {
  3794. entPowerLevel = FORCE_LEVEL_1;
  3795. }
  3796. else if ( ent->client->ps.forcePowersActive & (1 << FP_RAGE) )
  3797. {
  3798. entPowerLevel += ent->client->ps.forcePowerLevel[FP_RAGE];
  3799. }
  3800. }
  3801. if ( ent->client->ps.saberInFlight )
  3802. {//flying sabers are much more deadly
  3803. //unless you're dead
  3804. if ( ent->health <= 0 && g_saberRealisticCombat->integer < 2 )
  3805. {//so enemies don't keep trying to block it
  3806. //FIXME: still do damage, just not to humanoid clients who should try to avoid it
  3807. //baseDamage = 0.0f;
  3808. return;
  3809. }
  3810. //or unless returning
  3811. else if ( ent->client->ps.saberEntityState == SES_RETURNING
  3812. && ent->client->ps.saber[0].returnDamage == qfalse )//type != SABER_STAR )
  3813. {//special case, since we're returning, chances are if we hit something
  3814. //it's going to be butt-first. So do less damage.
  3815. baseDamage = 0.1f;
  3816. }
  3817. else
  3818. {
  3819. if ( !ent->s.number )
  3820. {//cheat for player
  3821. baseDamage = 10.0f;
  3822. }
  3823. else
  3824. {
  3825. baseDamage = 2.5f;
  3826. }
  3827. }
  3828. //Use old to current since can't predict it
  3829. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePointOld, mp1 );
  3830. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDirOld, md1 );
  3831. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint, mp2 );
  3832. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDir, md2 );
  3833. }
  3834. else
  3835. {
  3836. if ( ent->client->ps.torsoAnim == BOTH_A7_HILT )
  3837. {//no effects, no damage
  3838. return;
  3839. }
  3840. else if ( G_InCinematicSaberAnim( ent ) )
  3841. {
  3842. baseDFlags = DAMAGE_NO_KILL;
  3843. baseDamage = 0.1f;
  3844. }
  3845. else if ( ent->client->ps.saberMove == LS_READY
  3846. && !PM_SaberInSpecialAttack( ent->client->ps.torsoAnim ) )
  3847. {//just do effects
  3848. if ( g_saberRealisticCombat->integer < 2 )
  3849. {//don't kill with this hit
  3850. baseDFlags = DAMAGE_NO_KILL;
  3851. }
  3852. baseDamage = 0;
  3853. }
  3854. else if ( ent->client->ps.saberLockTime > level.time )
  3855. {//just do effects
  3856. baseDamage = 0;
  3857. }
  3858. else if ( ent->client->ps.saberBlocked > BLOCKED_NONE
  3859. || ( !PM_SaberInAttack( ent->client->ps.saberMove )
  3860. && !PM_SaberInSpecialAttack( ent->client->ps.torsoAnim )
  3861. && !PM_SaberInTransitionAny( ent->client->ps.saberMove )
  3862. )
  3863. )
  3864. {//don't do damage if parrying/reflecting/bouncing/deflecting or not actually attacking or in a transition to/from/between attacks
  3865. baseDamage = 0;
  3866. }
  3867. else
  3868. {//okay, in a saberMove that does damage
  3869. //make sure we're in the right anim
  3870. if ( !PM_SaberInSpecialAttack( ent->client->ps.torsoAnim )
  3871. && !PM_InAnimForSaberMove( ent->client->ps.torsoAnim, ent->client->ps.saberMove ) )
  3872. {//forced into some other animation somehow, like a pain or death?
  3873. baseDamage = 0;
  3874. }
  3875. else if ( ent->client->ps.weaponstate == WEAPON_FIRING && ent->client->ps.saberBlocked == BLOCKED_NONE &&
  3876. ( PM_SaberInAttack(ent->client->ps.saberMove) || PM_SaberInSpecialAttack( ent->client->ps.torsoAnim ) || PM_SpinningSaberAnim(ent->client->ps.torsoAnim) || entPowerLevel > FORCE_LEVEL_2 ) )// || ent->client->ps.saberAnimLevel == SS_STAFF ) )
  3877. {//normal attack swing swinging/spinning (or if using strong set), do normal damage //FIXME: or if using staff?
  3878. //FIXME: more damage for higher attack power levels?
  3879. // More damage based on length/color of saber?
  3880. //FIXME: Desann does double damage?
  3881. if ( g_saberRealisticCombat->integer )
  3882. {
  3883. switch ( entPowerLevel )
  3884. {
  3885. default:
  3886. case FORCE_LEVEL_3:
  3887. baseDamage = 10.0f;
  3888. break;
  3889. case FORCE_LEVEL_2:
  3890. baseDamage = 5.0f;
  3891. break;
  3892. case FORCE_LEVEL_0:
  3893. case FORCE_LEVEL_1:
  3894. baseDamage = 2.5f;
  3895. break;
  3896. }
  3897. }
  3898. else
  3899. {
  3900. if ( g_spskill->integer > 0
  3901. && ent->s.number < MAX_CLIENTS
  3902. && ( ent->client->ps.torsoAnim == BOTH_ROLL_STAB
  3903. || ent->client->ps.torsoAnim == BOTH_SPINATTACK6
  3904. || ent->client->ps.torsoAnim == BOTH_SPINATTACK7
  3905. || ent->client->ps.torsoAnim == BOTH_LUNGE2_B__T_ ) )
  3906. {//*sigh*, these anim do less damage since they're so easy to do
  3907. baseDamage = 2.5f;
  3908. }
  3909. else
  3910. {
  3911. baseDamage = 2.5f * (float)entPowerLevel;
  3912. }
  3913. }
  3914. }
  3915. else
  3916. {//saber is transitioning, defending or idle, don't do as much damage
  3917. //FIXME: strong attacks and returns should do damage and be unblockable
  3918. if ( g_timescale->value < 1.0 )
  3919. {//in slow mo or force speed, we need to do damage during the transitions
  3920. if ( g_saberRealisticCombat->integer )
  3921. {
  3922. switch ( entPowerLevel )
  3923. {
  3924. case FORCE_LEVEL_3:
  3925. baseDamage = 10.0f;
  3926. break;
  3927. case FORCE_LEVEL_2:
  3928. baseDamage = 5.0f;
  3929. break;
  3930. default:
  3931. case FORCE_LEVEL_1:
  3932. baseDamage = 2.5f;
  3933. break;
  3934. }
  3935. }
  3936. else
  3937. {
  3938. baseDamage = 2.5f * (float)entPowerLevel;
  3939. }
  3940. }
  3941. else// if ( !ent->s.number )
  3942. {//I have to do *some* damage in transitions or else you feel like a total gimp
  3943. baseDamage = 0.1f;
  3944. }
  3945. /*
  3946. else
  3947. {
  3948. baseDamage = 0;//was 1.0f;//was 0.25
  3949. }
  3950. */
  3951. }
  3952. }
  3953. //Use current to next since can predict it
  3954. //FIXME: if they're closer than the saber blade start, we don't want the
  3955. // arm to pass through them without any damage... so check the radius
  3956. // and push them away (do pain & knockback)
  3957. //FIXME: if going into/coming from a parry/reflection or going into a deflection, don't use old mp & dir? Otherwise, deflections will cut through?
  3958. //VectorCopy( ent->client->renderInfo.muzzlePoint, mp1 );
  3959. //VectorCopy( ent->client->renderInfo.muzzleDir, md1 );
  3960. //VectorCopy( ent->client->renderInfo.muzzlePointNext, mp2 );
  3961. //VectorCopy( ent->client->renderInfo.muzzleDirNext, md2 );
  3962. //prediction was causing gaps in swing (G2 problem) so *don't* predict
  3963. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePointOld, mp1 );
  3964. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDirOld, md1 );
  3965. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint, mp2 );
  3966. VectorCopy( ent->client->ps.saber[saberNum].blade[bladeNum].muzzleDir, md2 );
  3967. //NOTE: this is a test, may not be necc, as I can still swing right through someone without hitting them, somehow...
  3968. //see if anyone is so close that they're within the dist from my origin to the start of the saber
  3969. if ( ent->health > 0 && !ent->client->ps.saberLockTime && saberNum == 0 && bladeNum == 0
  3970. && !G_InCinematicSaberAnim( ent ) )
  3971. {//only do once - for first blade
  3972. trace_t trace;
  3973. gi.trace( &trace, ent->currentOrigin, vec3_origin, vec3_origin, mp1, ent->s.number, (MASK_SHOT&~(CONTENTS_CORPSE|CONTENTS_ITEM)) );
  3974. if ( trace.entityNum < ENTITYNUM_WORLD && (trace.entityNum > 0||ent->client->NPC_class == CLASS_DESANN) )//NPCs don't push player away, unless it's Desann
  3975. {//a valid ent
  3976. gentity_t *traceEnt = &g_entities[trace.entityNum];
  3977. if ( traceEnt
  3978. && traceEnt->client
  3979. && traceEnt->client->NPC_class != CLASS_RANCOR
  3980. && traceEnt->client->NPC_class != CLASS_ATST
  3981. && traceEnt->client->NPC_class != CLASS_WAMPA
  3982. && traceEnt->client->NPC_class != CLASS_SAND_CREATURE
  3983. && traceEnt->health > 0
  3984. && traceEnt->client->playerTeam != ent->client->playerTeam
  3985. && !PM_SuperBreakLoseAnim( traceEnt->client->ps.legsAnim )
  3986. && !PM_SuperBreakLoseAnim( traceEnt->client->ps.torsoAnim )
  3987. && !PM_SuperBreakWinAnim( traceEnt->client->ps.legsAnim )
  3988. && !PM_SuperBreakWinAnim( traceEnt->client->ps.torsoAnim )
  3989. && !PM_InKnockDown( &traceEnt->client->ps )
  3990. && !PM_LockedAnim( traceEnt->client->ps.legsAnim )
  3991. && !PM_LockedAnim( traceEnt->client->ps.torsoAnim )
  3992. && !G_InCinematicSaberAnim( traceEnt ))
  3993. {//enemy client, push them away
  3994. if ( !traceEnt->client->ps.saberLockTime
  3995. && !traceEnt->message
  3996. && !(traceEnt->flags&FL_NO_KNOCKBACK)
  3997. && (!traceEnt->NPC||traceEnt->NPC->jumpState!=JS_JUMPING) )
  3998. {//don't push people in saberlock or with security keys or who are in BS_JUMP
  3999. vec3_t hitDir;
  4000. VectorSubtract( trace.endpos, ent->currentOrigin, hitDir );
  4001. float totalDist = Distance( mp1, ent->currentOrigin );
  4002. float knockback = (totalDist-VectorNormalize( hitDir ))/totalDist * 200.0f;
  4003. hitDir[2] = 0;
  4004. //FIXME: do we need to call G_Throw? Seems unfair to put actual knockback on them, stops the attack
  4005. //G_Throw( traceEnt, hitDir, knockback );
  4006. VectorMA( traceEnt->client->ps.velocity, knockback, hitDir, traceEnt->client->ps.velocity );
  4007. traceEnt->client->ps.pm_time = 200;
  4008. traceEnt->client->ps.pm_flags |= PMF_TIME_NOFRICTION;
  4009. #ifndef FINAL_BUILD
  4010. if ( d_saberCombat->integer )
  4011. {
  4012. gi.Printf( "%s pushing away %s at %s\n", ent->NPC_type, traceEnt->NPC_type, vtos( traceEnt->client->ps.velocity ) );
  4013. }
  4014. #endif
  4015. }
  4016. }
  4017. }
  4018. }
  4019. }
  4020. //the thicker the blade, the more damage... the thinner, the less damage
  4021. baseDamage *= ent->client->ps.saber[saberNum].blade[bladeNum].radius/SABER_RADIUS_STANDARD;
  4022. if ( g_saberRealisticCombat->integer > 1 )
  4023. {//always do damage, and lots of it
  4024. if ( g_saberRealisticCombat->integer > 2 )
  4025. {//always do damage, and lots of it
  4026. baseDamage = 25.0f;
  4027. }
  4028. else if ( baseDamage > 0.1f )
  4029. {//only do super damage if we would have done damage according to normal rules
  4030. baseDamage = 25.0f;
  4031. }
  4032. }
  4033. else if ( ((!ent->s.number&&ent->client->ps.forcePowersActive&(1<<FP_SPEED))||ent->client->ps.forcePowersActive&(1<<FP_RAGE))
  4034. && g_timescale->value < 1.0f )
  4035. {
  4036. baseDamage *= (1.0f-g_timescale->value);
  4037. }
  4038. if ( baseDamage > 0.1f )
  4039. {
  4040. if ( (ent->client->ps.forcePowersActive&(1<<FP_RAGE)) )
  4041. {//add some damage if raged
  4042. baseDamage += ent->client->ps.forcePowerLevel[FP_RAGE] * 5.0f;
  4043. }
  4044. else if ( ent->client->ps.forceRageRecoveryTime )
  4045. {//halve it if recovering
  4046. baseDamage *= 0.5f;
  4047. }
  4048. }
  4049. // Get the old state of the blade
  4050. VectorCopy( mp1, baseOld );
  4051. VectorMA( baseOld, ent->client->ps.saber[saberNum].blade[bladeNum].length, md1, endOld );
  4052. // Get the future state of the blade
  4053. VectorCopy( mp2, baseNew );
  4054. VectorMA( baseNew, ent->client->ps.saber[saberNum].blade[bladeNum].length, md2, endNew );
  4055. sabersCrossed = -1;
  4056. if ( VectorCompare2( baseOld, baseNew ) && VectorCompare2( endOld, endNew ) )
  4057. {
  4058. hit_wall = WP_SaberDamageForTrace( ent->s.number, mp2, endNew, baseDamage*4, md2,
  4059. qfalse, entPowerLevel, ent->client->ps.saber[saberNum].type, qfalse,
  4060. saberNum, bladeNum );
  4061. }
  4062. else
  4063. {
  4064. float aveLength, step = 8, stepsize = 8;
  4065. vec3_t ma1, ma2, md2ang, curBase1, curBase2;
  4066. int xx;
  4067. //do the trace at the base first
  4068. hit_wall = WP_SaberDamageForTrace( ent->s.number, baseOld, baseNew, baseDamage, md2,
  4069. qfalse, entPowerLevel, ent->client->ps.saber[saberNum].type, qtrue,
  4070. saberNum, bladeNum );
  4071. //if hit a saber, shorten rest of traces to match
  4072. if ( saberHitFraction < 1.0 )
  4073. {
  4074. //adjust muzzleDir...
  4075. vec3_t ma1, ma2;
  4076. vectoangles( md1, ma1 );
  4077. vectoangles( md2, ma2 );
  4078. for ( xx = 0; xx < 3; xx++ )
  4079. {
  4080. md2ang[xx] = LerpAngle( ma1[xx], ma2[xx], saberHitFraction );
  4081. }
  4082. AngleVectors( md2ang, md2, NULL, NULL );
  4083. //shorten the base pos
  4084. VectorSubtract( mp2, mp1, baseDiff );
  4085. VectorMA( mp1, saberHitFraction, baseDiff, baseNew );
  4086. VectorMA( baseNew, ent->client->ps.saber[saberNum].blade[bladeNum].length, md2, endNew );
  4087. }
  4088. //If the angle diff in the blade is high, need to do it in chunks of 33 to avoid flattening of the arc
  4089. float dirInc, curDirFrac;
  4090. if ( PM_SaberInAttack( ent->client->ps.saberMove )
  4091. || PM_SaberInSpecialAttack( ent->client->ps.torsoAnim )
  4092. || PM_SpinningSaberAnim( ent->client->ps.torsoAnim )
  4093. || PM_InSpecialJump( ent->client->ps.torsoAnim )
  4094. || (g_timescale->value<1.0f&&PM_SaberInTransitionAny( ent->client->ps.saberMove )) )
  4095. {
  4096. curDirFrac = DotProduct( md1, md2 );
  4097. }
  4098. else
  4099. {
  4100. curDirFrac = 1.0f;
  4101. }
  4102. //NOTE: if saber spun at least 180 degrees since last damage trace, this is not reliable...!
  4103. if ( fabs(curDirFrac) < 1.0f - MAX_SABER_SWING_INC )
  4104. {//the saber blade spun more than 33 degrees since the last damage trace
  4105. curDirFrac = dirInc = 1.0f/((1.0f - curDirFrac)/MAX_SABER_SWING_INC);
  4106. }
  4107. else
  4108. {
  4109. curDirFrac = 1.0f;
  4110. dirInc = 0.0f;
  4111. }
  4112. qboolean hit_saber = qfalse;
  4113. vectoangles( md1, ma1 );
  4114. vectoangles( md2, ma2 );
  4115. vec3_t curMD1, curMD2;//, mdDiff, dirDiff;
  4116. //VectorSubtract( md2, md1, mdDiff );
  4117. VectorCopy( md1, curMD2 );
  4118. VectorCopy( baseOld, curBase2 );
  4119. while ( 1 )
  4120. {
  4121. VectorCopy( curMD2, curMD1 );
  4122. VectorCopy( curBase2, curBase1 );
  4123. if ( curDirFrac >= 1.0f )
  4124. {
  4125. VectorCopy( md2, curMD2 );
  4126. VectorCopy( baseNew, curBase2 );
  4127. }
  4128. else
  4129. {
  4130. for ( xx = 0; xx < 3; xx++ )
  4131. {
  4132. md2ang[xx] = LerpAngle( ma1[xx], ma2[xx], curDirFrac );
  4133. }
  4134. AngleVectors( md2ang, curMD2, NULL, NULL );
  4135. //VectorMA( md1, curDirFrac, mdDiff, curMD2 );
  4136. VectorSubtract( baseNew, baseOld, baseDiff );
  4137. VectorMA( baseOld, curDirFrac, baseDiff, curBase2 );
  4138. }
  4139. // Move up the blade in intervals of stepsize
  4140. for ( step = stepsize; step < ent->client->ps.saber[saberNum].blade[bladeNum].length && step < ent->client->ps.saber[saberNum].blade[bladeNum].lengthOld; step+=12 )
  4141. {
  4142. VectorMA( curBase1, step, curMD1, bladePointOld );
  4143. VectorMA( curBase2, step, curMD2, bladePointNew );
  4144. if ( WP_SaberDamageForTrace( ent->s.number, bladePointOld, bladePointNew, baseDamage, curMD2,
  4145. qfalse, entPowerLevel, ent->client->ps.saber[saberNum].type, qtrue,
  4146. saberNum, bladeNum ) )
  4147. {
  4148. hit_wall = qtrue;
  4149. }
  4150. //if hit a saber, shorten rest of traces to match
  4151. if ( saberHitFraction < 1.0 )
  4152. {
  4153. //adjust muzzle endpoint
  4154. VectorSubtract( mp2, mp1, baseDiff );
  4155. VectorMA( mp1, saberHitFraction, baseDiff, baseNew );
  4156. VectorMA( baseNew, ent->client->ps.saber[saberNum].blade[bladeNum].length, curMD2, endNew );
  4157. //adjust muzzleDir...
  4158. vec3_t curMA1, curMA2;
  4159. vectoangles( curMD1, curMA1 );
  4160. vectoangles( curMD2, curMA2 );
  4161. for ( xx = 0; xx < 3; xx++ )
  4162. {
  4163. md2ang[xx] = LerpAngle( curMA1[xx], curMA2[xx], saberHitFraction );
  4164. }
  4165. AngleVectors( md2ang, curMD2, NULL, NULL );
  4166. /*
  4167. VectorSubtract( curMD2, curMD1, dirDiff );
  4168. VectorMA( curMD1, saberHitFraction, dirDiff, curMD2 );
  4169. */
  4170. hit_saber = qtrue;
  4171. }
  4172. if (hit_wall)
  4173. {
  4174. break;
  4175. }
  4176. }
  4177. if ( hit_wall || hit_saber )
  4178. {
  4179. break;
  4180. }
  4181. if ( curDirFrac >= 1.0f )
  4182. {
  4183. break;
  4184. }
  4185. else
  4186. {
  4187. curDirFrac += dirInc;
  4188. if ( curDirFrac >= 1.0f )
  4189. {
  4190. curDirFrac = 1.0f;
  4191. }
  4192. }
  4193. }
  4194. //do the trace at the end last
  4195. //Special check- adjust for length of blade not being a multiple of 12
  4196. aveLength = (ent->client->ps.saber[saberNum].blade[bladeNum].lengthOld + ent->client->ps.saber[saberNum].blade[bladeNum].length)/2;
  4197. if ( step > aveLength )
  4198. {//less dmg if the last interval was not stepsize
  4199. tipDmgMod = (stepsize-(step-aveLength))/stepsize;
  4200. }
  4201. //NOTE: since this is the tip, we do not extrapolate the extra 16
  4202. if ( WP_SaberDamageForTrace( ent->s.number, endOld, endNew, tipDmgMod*baseDamage, md2,
  4203. qfalse, entPowerLevel, ent->client->ps.saber[saberNum].type, qfalse,
  4204. saberNum, bladeNum ) )
  4205. {
  4206. hit_wall = qtrue;
  4207. }
  4208. }
  4209. if ( (saberHitFraction < 1.0f||(sabersCrossed>=0&&sabersCrossed<=32.0f)) && (ent->client->ps.weaponstate == WEAPON_FIRING || ent->client->ps.saberInFlight || G_InCinematicSaberAnim( ent ) ) )
  4210. {// The saber (in-hand) hit another saber, mano.
  4211. qboolean inFlightSaberBlocked = qfalse;
  4212. qboolean collisionResolved = qfalse;
  4213. qboolean deflected = qfalse;
  4214. gentity_t *hitEnt = &g_entities[saberHitEntity];
  4215. gentity_t *hitOwner = NULL;
  4216. int hitOwnerPowerLevel = FORCE_LEVEL_0;
  4217. if ( hitEnt )
  4218. {
  4219. hitOwner = hitEnt->owner;
  4220. }
  4221. if ( hitOwner && hitOwner->client )
  4222. {
  4223. hitOwnerPowerLevel = PM_PowerLevelForSaberAnim( &hitOwner->client->ps );
  4224. /*
  4225. if ( entPowerLevel >= FORCE_LEVEL_3
  4226. && PM_SaberInSpecialAttack( ent->client->ps.torsoAnim ) )
  4227. {//a special "unblockable" attack
  4228. if ( hitOwner->client->NPC_class == CLASS_ALORA
  4229. || hitOwner->client->NPC_class == CLASS_SHADOWTROOPER
  4230. || (hitOwner->NPC&&(hitOwner->NPC->aiFlags&NPCAI_BOSS_CHARACTER)) )
  4231. {//these masters can even block unblockables (stops cheap kills)
  4232. entPowerLevel = FORCE_LEVEL_2;
  4233. }
  4234. }
  4235. */
  4236. }
  4237. //FIXME: check for certain anims, facing, etc, to make them lock into a sabers-locked pose
  4238. //SEF_LOCKED
  4239. if ( ent->client->ps.saberInFlight && saberNum == 0 &&
  4240. ent->client->ps.saber[saberNum].blade[bladeNum].active &&
  4241. ent->client->ps.saberEntityNum != ENTITYNUM_NONE &&
  4242. ent->client->ps.saberEntityState != SES_RETURNING )
  4243. {//saber was blocked, return it
  4244. inFlightSaberBlocked = qtrue;
  4245. }
  4246. //FIXME: based on strength, position and angle of attack & defense, decide if:
  4247. // defender and attacker lock sabers
  4248. // *defender's parry should hold and attack bounces (or deflects, based on angle of sabers)
  4249. // *defender's parry is somewhat broken and both bounce (or deflect)
  4250. // *defender's parry is broken and they bounce while attacker's attack deflects or carries through (especially if they're dead)
  4251. // defender is knocked down and attack goes through
  4252. //Check deflections and broken parries
  4253. if ( hitOwner && hitOwner->health > 0 && ent->health > 0 //both are alive
  4254. && !inFlightSaberBlocked && hitOwner->client && !hitOwner->client->ps.saberInFlight && !ent->client->ps.saberInFlight//both have sabers in-hand
  4255. && ent->client->ps.saberBlocked != BLOCKED_PARRY_BROKEN
  4256. && ent->client->ps.saberLockTime < level.time
  4257. && hitOwner->client->ps.saberLockTime < level.time )
  4258. {//2 in-hand sabers hit
  4259. //FIXME: defender should not parry or block at all if not in a saber anim... like, if in a roll or knockdown...
  4260. if ( baseDamage )
  4261. {//there is damage involved, not just effects
  4262. qboolean entAttacking = qfalse;
  4263. qboolean hitOwnerAttacking = qfalse;
  4264. qboolean entDefending = qfalse;
  4265. qboolean hitOwnerDefending = qfalse;
  4266. qboolean forceLock = qfalse;
  4267. if ( (ent->client->NPC_class == CLASS_KYLE && (ent->spawnflags&1) && hitOwner->s.number < MAX_CLIENTS )
  4268. || (hitOwner->client->NPC_class == CLASS_KYLE && (hitOwner->spawnflags&1) && ent->s.number < MAX_CLIENTS ) )
  4269. {//Player vs. Kyle Boss == lots of saberlocks
  4270. if ( !Q_irand( 0, 2 ) )
  4271. {
  4272. forceLock = qtrue;
  4273. }
  4274. }
  4275. if ( PM_SaberInAttack( ent->client->ps.saberMove ) || PM_SaberInSpecialAttack( ent->client->ps.torsoAnim ) )
  4276. {
  4277. entAttacking = qtrue;
  4278. }
  4279. else if ( entPowerLevel > FORCE_LEVEL_2 )
  4280. {//stronger styles count as attacking even if in a transition
  4281. if ( PM_SaberInTransitionAny( ent->client->ps.saberMove ) )
  4282. {
  4283. entAttacking = qtrue;
  4284. }
  4285. }
  4286. if ( PM_SaberInParry( ent->client->ps.saberMove )
  4287. || ent->client->ps.saberMove == LS_READY )
  4288. {
  4289. entDefending = qtrue;
  4290. }
  4291. if ( ent->client->ps.torsoAnim == BOTH_A1_SPECIAL
  4292. || ent->client->ps.torsoAnim == BOTH_A2_SPECIAL
  4293. || ent->client->ps.torsoAnim == BOTH_A3_SPECIAL )
  4294. {//parry/block/break-parry bonus for single-style kata moves
  4295. entPowerLevel++;
  4296. }
  4297. if ( entAttacking )
  4298. {//add twoHanded bonus and breakParryBonus to entPowerLevel here
  4299. //This makes staff too powerful
  4300. if ( ent->client->ps.saber[saberNum].twoHanded )
  4301. {
  4302. entPowerLevel++;
  4303. }
  4304. //FIXME: what if dualSabers && both sabers are hitting at same time?
  4305. entPowerLevel += ent->client->ps.saber[saberNum].breakParryBonus;
  4306. }
  4307. else if ( entDefending )
  4308. {//add twoHanded bonus and dualSaber bonus and parryBonus to entPowerLevel here
  4309. if ( ent->client->ps.saber[saberNum].twoHanded
  4310. || (ent->client->ps.dualSabers && ent->client->ps.saber[1].Active()) )
  4311. {
  4312. entPowerLevel++;
  4313. }
  4314. //FIXME: what about second saber if dualSabers?
  4315. entPowerLevel += ent->client->ps.saber[saberNum].parryBonus;
  4316. }
  4317. if ( PM_SaberInAttack( hitOwner->client->ps.saberMove ) || PM_SaberInSpecialAttack( hitOwner->client->ps.torsoAnim ) )
  4318. {
  4319. hitOwnerAttacking = qtrue;
  4320. }
  4321. else if ( hitOwnerPowerLevel > FORCE_LEVEL_2 )
  4322. {//stronger styles count as attacking even if in a transition
  4323. if ( PM_SaberInTransitionAny( hitOwner->client->ps.saberMove ) )
  4324. {
  4325. hitOwnerAttacking = qtrue;
  4326. }
  4327. }
  4328. if ( PM_SaberInParry( hitOwner->client->ps.saberMove )
  4329. || hitOwner->client->ps.saberMove == LS_READY )
  4330. {
  4331. hitOwnerDefending = qtrue;
  4332. }
  4333. if ( hitOwner->client->ps.torsoAnim == BOTH_A1_SPECIAL
  4334. || hitOwner->client->ps.torsoAnim == BOTH_A2_SPECIAL
  4335. || hitOwner->client->ps.torsoAnim == BOTH_A3_SPECIAL )
  4336. {//parry/block/break-parry bonus for single-style kata moves
  4337. hitOwnerPowerLevel++;
  4338. }
  4339. if ( hitOwnerAttacking )
  4340. {//add twoHanded bonus and breakParryBonus to entPowerLevel here
  4341. if ( hitOwner->client->ps.saber[0].twoHanded )
  4342. {
  4343. hitOwnerPowerLevel++;
  4344. }
  4345. hitOwnerPowerLevel += hitOwner->client->ps.saber[0].breakParryBonus;
  4346. if ( hitOwner->client->ps.dualSabers && Q_irand( 0, 1 ) )
  4347. {//FIXME: assumes both sabers are hitting at same time...?
  4348. hitOwnerPowerLevel += 1 + hitOwner->client->ps.saber[1].breakParryBonus;
  4349. }
  4350. }
  4351. else if ( hitOwnerDefending )
  4352. {//add twoHanded bonus and dualSaber bonus and parryBonus to entPowerLevel here
  4353. if ( hitOwner->client->ps.saber[0].twoHanded || (hitOwner->client->ps.dualSabers && hitOwner->client->ps.saber[1].Active()) )
  4354. {
  4355. hitOwnerPowerLevel++;
  4356. }
  4357. hitOwnerPowerLevel += hitOwner->client->ps.saber[0].parryBonus;
  4358. if ( hitOwner->client->ps.dualSabers && Q_irand( 0, 1 ) )
  4359. {//FIXME: assumes both sabers are defending at same time...?
  4360. hitOwnerPowerLevel += 1 + hitOwner->client->ps.saber[1].parryBonus;
  4361. }
  4362. }
  4363. if ( PM_SuperBreakLoseAnim( ent->client->ps.torsoAnim )
  4364. || PM_SuperBreakWinAnim( ent->client->ps.torsoAnim )
  4365. || PM_SuperBreakLoseAnim( hitOwner->client->ps.torsoAnim )
  4366. || PM_SuperBreakWinAnim( hitOwner->client->ps.torsoAnim ) )
  4367. {//don't mess with this
  4368. collisionResolved = qtrue;
  4369. }
  4370. else if ( entAttacking
  4371. && hitOwnerAttacking
  4372. && !Q_irand( 0, g_saberLockRandomNess->integer )
  4373. && ( g_debugSaberLock->integer || forceLock
  4374. || entPowerLevel == hitOwnerPowerLevel
  4375. || (entPowerLevel > FORCE_LEVEL_2 && hitOwnerPowerLevel > FORCE_LEVEL_2 )
  4376. || (entPowerLevel < FORCE_LEVEL_3 && hitOwnerPowerLevel < FORCE_LEVEL_3 && hitOwner->client->ps.forcePowerLevel[FP_SABER_OFFENSE] > FORCE_LEVEL_2 && Q_irand( 0, 3 ))
  4377. || (entPowerLevel < FORCE_LEVEL_2 && hitOwnerPowerLevel < FORCE_LEVEL_3 && hitOwner->client->ps.forcePowerLevel[FP_SABER_OFFENSE] > FORCE_LEVEL_1 && Q_irand( 0, 2 ))
  4378. || (hitOwnerPowerLevel < FORCE_LEVEL_3 && entPowerLevel < FORCE_LEVEL_3 && ent->client->ps.forcePowerLevel[FP_SABER_OFFENSE] > FORCE_LEVEL_2 && !Q_irand( 0, 1 ))
  4379. || (hitOwnerPowerLevel < FORCE_LEVEL_2 && entPowerLevel < FORCE_LEVEL_3 && ent->client->ps.forcePowerLevel[FP_SABER_OFFENSE] > FORCE_LEVEL_1 && !Q_irand( 0, 1 )))
  4380. && WP_SabersCheckLock( ent, hitOwner ) )
  4381. {
  4382. collisionResolved = qtrue;
  4383. }
  4384. else if ( hitOwnerAttacking
  4385. && entDefending
  4386. && !Q_irand( 0, g_saberLockRandomNess->integer*3 )
  4387. && (g_debugSaberLock->integer || forceLock ||
  4388. ((ent->client->ps.saberMove != LS_READY || (hitOwnerPowerLevel-ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE]) < Q_irand( -6, 0 ) )
  4389. && ((hitOwnerPowerLevel < FORCE_LEVEL_3 && ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE] > FORCE_LEVEL_2 )||
  4390. (hitOwnerPowerLevel < FORCE_LEVEL_2 && ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE] > FORCE_LEVEL_1 )||
  4391. (hitOwnerPowerLevel < FORCE_LEVEL_3 && ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE] > FORCE_LEVEL_0 && !Q_irand( 0, (hitOwnerPowerLevel-ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE]+1)*2 ))) ))
  4392. && WP_SabersCheckLock( hitOwner, ent ) )
  4393. {
  4394. collisionResolved = qtrue;
  4395. }
  4396. else if ( entAttacking && hitOwnerDefending )
  4397. {//I'm attacking hit, they're parrying
  4398. qboolean activeDefense = (hitOwner->s.number||g_saberAutoBlocking->integer||hitOwner->client->ps.saberBlockingTime > level.time);
  4399. if ( !Q_irand( 0, g_saberLockRandomNess->integer*3 )
  4400. && activeDefense
  4401. && (g_debugSaberLock->integer || forceLock ||
  4402. ((hitOwner->client->ps.saberMove != LS_READY || (entPowerLevel-hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE]) < Q_irand( -6, 0 ) )
  4403. && ( ( entPowerLevel < FORCE_LEVEL_3 && hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE] > FORCE_LEVEL_2 )
  4404. || ( entPowerLevel < FORCE_LEVEL_2 && hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE] > FORCE_LEVEL_1 )
  4405. || ( entPowerLevel < FORCE_LEVEL_3 && hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE] > FORCE_LEVEL_0 && !Q_irand( 0, (entPowerLevel-hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE]+1)*2 )) ) ))
  4406. && WP_SabersCheckLock( ent, hitOwner ) )
  4407. {
  4408. collisionResolved = qtrue;
  4409. }
  4410. else if ( saberHitFraction < 1.0f )
  4411. {//an actual collision
  4412. if ( entPowerLevel < FORCE_LEVEL_3 && activeDefense )
  4413. {//strong attacks cannot be deflected
  4414. //based on angle of attack & angle of defensive saber, see if I should deflect off in another dir rather than bounce back
  4415. deflected = WP_GetSaberDeflectionAngle( ent, hitOwner );
  4416. //just so Jedi knows that he was blocked
  4417. ent->client->ps.saberEventFlags |= SEF_BLOCKED;
  4418. }
  4419. //base parry breaks on animation (saber attack level), not FP_SABER_OFFENSE
  4420. if ( entPowerLevel < FORCE_LEVEL_3
  4421. //&& ent->client->ps.forcePowerLevel[FP_SABER_OFFENSE] < FORCE_LEVEL_3//if you have high saber offense, you cannot have your attack knocked away, regardless of what style you're using?
  4422. //&& hitOwner->client->ps.saberAnimLevel != FORCE_LEVEL_5
  4423. && activeDefense
  4424. && (hitOwnerPowerLevel > FORCE_LEVEL_2||(hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE]>FORCE_LEVEL_2&&Q_irand(0,hitOwner->client->ps.forcePowerLevel[FP_SABER_OFFENSE]))) )
  4425. {//knockaways can make fast-attacker go into a broken parry anim if the ent is using fast or med (but not Tavion)
  4426. //make me parry
  4427. WP_SaberParry( hitOwner, ent );
  4428. //turn the parry into a knockaway
  4429. hitOwner->client->ps.saberBounceMove = PM_KnockawayForParry( hitOwner->client->ps.saberBlocked );
  4430. //make them go into a broken parry
  4431. ent->client->ps.saberBounceMove = PM_BrokenParryForAttack( ent->client->ps.saberMove );
  4432. ent->client->ps.saberBlocked = BLOCKED_PARRY_BROKEN;
  4433. if ( saberNum == 0 )
  4434. {//FIXME: can only lose right-hand saber for now
  4435. if ( ent->client->ps.saber[saberNum].disarmable
  4436. && ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE] < FORCE_LEVEL_2
  4437. //&& (ent->s.number||g_saberRealisticCombat->integer)
  4438. && Q_irand( 0, hitOwner->client->ps.SaberDisarmBonus() ) > 0
  4439. && (hitOwner->s.number || g_saberAutoBlocking->integer || !Q_irand( 0, 2 )) )//if player defending and autoblocking is on, this is less likely to happen, so don't do the random check
  4440. {//knocked the saber right out of his hand! (never happens to player)
  4441. //Get a good velocity to send the saber in based on my parry move
  4442. vec3_t throwDir;
  4443. if ( !PM_VelocityForBlockedMove( &hitOwner->client->ps, throwDir ) )
  4444. {
  4445. PM_VelocityForSaberMove( &ent->client->ps, throwDir );
  4446. }
  4447. WP_SaberLose( ent, throwDir );
  4448. }
  4449. }
  4450. //just so Jedi knows that he was blocked
  4451. ent->client->ps.saberEventFlags |= SEF_BLOCKED;
  4452. #ifndef FINAL_BUILD
  4453. if ( d_saberCombat->integer )
  4454. {
  4455. gi.Printf( S_COLOR_RED"%s knockaway %s's attack, new move = %s, anim = %s\n", hitOwner->NPC_type, ent->NPC_type, saberMoveData[ent->client->ps.saberBounceMove].name, animTable[saberMoveData[ent->client->ps.saberBounceMove].animToUse].name );
  4456. }
  4457. #endif
  4458. }
  4459. else if ( !activeDefense//they're not defending
  4460. || (entPowerLevel > FORCE_LEVEL_2 //I hit hard
  4461. && hitOwnerPowerLevel < entPowerLevel)//they are defending, but their defense strength is lower than my attack...
  4462. || (!deflected && Q_irand( 0, PM_PowerLevelForSaberAnim( &ent->client->ps, saberNum ) - hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE]/*PM_PowerLevelForSaberAnim( &hitOwner->client->ps )*/ ) > 0 ) )
  4463. {//broke their parry altogether
  4464. if ( entPowerLevel > FORCE_LEVEL_2 || Q_irand( 0, ent->client->ps.forcePowerLevel[FP_SABER_OFFENSE] - hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE] ) )
  4465. {//chance of continuing with the attack (not bouncing back)
  4466. ent->client->ps.saberEventFlags &= ~SEF_BLOCKED;
  4467. ent->client->ps.saberBounceMove = LS_NONE;
  4468. brokenParry = qtrue;
  4469. }
  4470. //do some time-consuming saber-knocked-aside broken parry anim
  4471. hitOwner->client->ps.saberBlocked = BLOCKED_PARRY_BROKEN;
  4472. hitOwner->client->ps.saberBounceMove = LS_NONE;
  4473. //FIXME: for now, you always disarm the right-hand saber
  4474. if ( hitOwner->client->ps.saber[0].disarmable
  4475. && hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE] < FORCE_LEVEL_2
  4476. //&& (ent->s.number||g_saberRealisticCombat->integer)
  4477. && Q_irand( 0, 2-ent->client->ps.SaberDisarmBonus() ) <= 0 )
  4478. {//knocked the saber right out of his hand!
  4479. //get the right velocity for my attack direction
  4480. vec3_t throwDir;
  4481. PM_VelocityForSaberMove( &ent->client->ps, throwDir );
  4482. WP_SaberLose( hitOwner, throwDir );
  4483. if ( (ent->client->ps.saberAnimLevel == SS_STRONG && !Q_irand(0,3) )
  4484. || ( ent->client->ps.saberAnimLevel==SS_DESANN&&!Q_irand(0,1) ) )
  4485. {// a strong attack
  4486. if ( WP_BrokenParryKnockDown( hitOwner ) )
  4487. {
  4488. hitOwner->client->ps.saberBlocked = BLOCKED_NONE;
  4489. hitOwner->client->ps.saberBounceMove = LS_NONE;
  4490. }
  4491. }
  4492. }
  4493. else
  4494. {
  4495. if ( (ent->client->ps.saberAnimLevel == SS_STRONG && !Q_irand(0,5) )
  4496. || ( ent->client->ps.saberAnimLevel==SS_DESANN&&!Q_irand(0,3) ) )
  4497. {// a strong attack
  4498. if ( WP_BrokenParryKnockDown( hitOwner ) )
  4499. {
  4500. hitOwner->client->ps.saberBlocked = BLOCKED_NONE;
  4501. hitOwner->client->ps.saberBounceMove = LS_NONE;
  4502. }
  4503. }
  4504. }
  4505. #ifndef FINAL_BUILD
  4506. if ( d_saberCombat->integer )
  4507. {
  4508. if ( ent->client->ps.saberEventFlags&SEF_BLOCKED )
  4509. {
  4510. gi.Printf( S_COLOR_RED"%s parry broken (bounce/deflect)!\n", hitOwner->targetname );
  4511. }
  4512. else
  4513. {
  4514. gi.Printf( S_COLOR_RED"%s parry broken (follow-through)!\n", hitOwner->targetname );
  4515. }
  4516. }
  4517. #endif
  4518. }
  4519. else
  4520. {//just a parry, possibly the hitOwner can knockaway the ent
  4521. WP_SaberParry( hitOwner, ent );
  4522. if ( PM_SaberInBounce( ent->client->ps.saberMove ) //FIXME: saberMove not set until pmove!
  4523. && activeDefense
  4524. && hitOwner->client->ps.saberAnimLevel != SS_FAST //&& hitOwner->client->ps.saberAnimLevel != FORCE_LEVEL_5
  4525. && hitOwner->client->ps.forcePowerLevel[FP_SABER_DEFENSE] > FORCE_LEVEL_2 )
  4526. {//attacker bounced off, and defender has ability to do knockaways, so do one unless we're using fast attacks
  4527. //turn the parry into a knockaway
  4528. hitOwner->client->ps.saberBounceMove = PM_KnockawayForParry( hitOwner->client->ps.saberBlocked );
  4529. }
  4530. else if ( (ent->client->ps.saberAnimLevel == SS_STRONG && !Q_irand(0,6) )
  4531. || ( ent->client->ps.saberAnimLevel==SS_DESANN && !Q_irand(0,3) ) )
  4532. {// a strong attack can sometimes do a knockdown
  4533. //HMM... maybe only if they're moving backwards?
  4534. if ( WP_BrokenParryKnockDown( hitOwner ) )
  4535. {
  4536. hitOwner->client->ps.saberBlocked = BLOCKED_NONE;
  4537. hitOwner->client->ps.saberBounceMove = LS_NONE;
  4538. }
  4539. }
  4540. }
  4541. collisionResolved = qtrue;
  4542. }
  4543. }
  4544. /*
  4545. else if ( entDefending && hitOwnerAttacking )
  4546. {//I'm parrying, they're attacking
  4547. if ( hitOwnerPowerLevel < FORCE_LEVEL_3 )
  4548. {//strong attacks cannot be deflected
  4549. //based on angle of attack & angle of defensive saber, see if I should deflect off in another dir rather than bounce back
  4550. deflected = WP_GetSaberDeflectionAngle( hitOwner, ent );
  4551. //just so Jedi knows that he was blocked
  4552. hitOwner->client->ps.saberEventFlags |= SEF_BLOCKED;
  4553. }
  4554. //FIXME: base parry breaks on animation (saber attack level), not FP_SABER_OFFENSE
  4555. if ( hitOwnerPowerLevel > FORCE_LEVEL_2 || (!deflected && Q_irand( 0, PM_PowerLevelForSaberAnim( &hitOwner->client->ps ) - ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE] ) > 0 ) )
  4556. {//broke my parry altogether
  4557. if ( hitOwnerPowerLevel > FORCE_LEVEL_2 || Q_irand( 0, hitOwner->client->ps.forcePowerLevel[FP_SABER_OFFENSE] - ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE] ) )
  4558. {//chance of continuing with the attack (not bouncing back)
  4559. hitOwner->client->ps.saberEventFlags &= ~SEF_BLOCKED;
  4560. hitOwner->client->ps.saberBounceMove = LS_NONE;
  4561. }
  4562. //do some time-consuming saber-knocked-aside broken parry anim
  4563. ent->client->ps.saberBlocked = BLOCKED_PARRY_BROKEN;
  4564. #ifndef FINAL_BUILD
  4565. if ( d_saberCombat->integer )
  4566. {
  4567. if ( hitOwner->client->ps.saberEventFlags&SEF_BLOCKED )
  4568. {
  4569. gi.Printf( S_COLOR_RED"%s parry broken (bounce/deflect)!\n", ent->targetname );
  4570. }
  4571. else
  4572. {
  4573. gi.Printf( S_COLOR_RED"%s parry broken (follow-through)!\n", ent->targetname );
  4574. }
  4575. }
  4576. #endif
  4577. }
  4578. else
  4579. {
  4580. WP_SaberParry( ent, hitOwner );
  4581. }
  4582. collisionResolved = qtrue;
  4583. }
  4584. */
  4585. else
  4586. {//some other kind of in-hand saber collision
  4587. }
  4588. }
  4589. }
  4590. else
  4591. {//some kind of in-flight collision
  4592. }
  4593. if ( saberHitFraction < 1.0f )
  4594. {
  4595. if ( !collisionResolved && baseDamage )
  4596. {//some other kind of in-hand saber collision
  4597. //handle my reaction
  4598. if ( !ent->client->ps.saberInFlight
  4599. && ent->client->ps.saberLockTime < level.time )
  4600. {//my saber is in hand
  4601. if ( ent->client->ps.saberBlocked != BLOCKED_PARRY_BROKEN )
  4602. {
  4603. if ( PM_SaberInAttack( ent->client->ps.saberMove ) || PM_SaberInSpecialAttack( ent->client->ps.torsoAnim ) ||
  4604. (entPowerLevel > FORCE_LEVEL_2&&!PM_SaberInIdle(ent->client->ps.saberMove)&&!PM_SaberInParry(ent->client->ps.saberMove)&&!PM_SaberInReflect(ent->client->ps.saberMove)) )
  4605. {//in the middle of attacking
  4606. if ( entPowerLevel < FORCE_LEVEL_3 && hitOwner->health > 0 )
  4607. {//don't deflect/bounce in strong attack or when enemy is dead
  4608. WP_GetSaberDeflectionAngle( ent, hitOwner );
  4609. ent->client->ps.saberEventFlags |= SEF_BLOCKED;
  4610. //since it was blocked/deflected, take away any damage done
  4611. //FIXME: what if the damage was done before the parry?
  4612. WP_SaberClearDamageForEntNum( hitOwner->s.number );
  4613. }
  4614. }
  4615. else
  4616. {//saber collided when not attacking, parry it
  4617. //since it was blocked/deflected, take away any damage done
  4618. //FIXME: what if the damage was done before the parry?
  4619. WP_SaberClearDamageForEntNum( hitOwner->s.number );
  4620. /*
  4621. if ( ent->s.number || g_saberAutoBlocking->integer || ent->client->ps.saberBlockingTime > level.time )
  4622. {//either an NPC or a player who has blocking
  4623. if ( !PM_SaberInTransitionAny( ent->client->ps.saberMove ) && !PM_SaberInBounce( ent->client->ps.saberMove ) )
  4624. {//I'm not attacking, in transition or in a bounce, so play a parry
  4625. //just so Jedi knows that he parried something
  4626. WP_SaberBlockNonRandom( ent, saberHitLocation, qfalse );
  4627. }
  4628. ent->client->ps.saberEventFlags |= SEF_PARRIED;
  4629. }
  4630. */
  4631. }
  4632. }
  4633. else
  4634. {
  4635. //since it was blocked/deflected, take away any damage done
  4636. //FIXME: what if the damage was done before the parry?
  4637. WP_SaberClearDamageForEntNum( hitOwner->s.number );
  4638. }
  4639. }
  4640. else
  4641. {//nothing happens to *me* when my inFlight saber hits something
  4642. }
  4643. //handle their reaction
  4644. if ( hitOwner
  4645. && hitOwner->health > 0
  4646. && hitOwner->client
  4647. && !hitOwner->client->ps.saberInFlight
  4648. && hitOwner->client->ps.saberLockTime < level.time )
  4649. {//their saber is in hand
  4650. if ( PM_SaberInAttack( hitOwner->client->ps.saberMove ) || PM_SaberInSpecialAttack( hitOwner->client->ps.torsoAnim ) ||
  4651. (hitOwner->client->ps.saberAnimLevel > SS_MEDIUM&&!PM_SaberInIdle(hitOwner->client->ps.saberMove)&&!PM_SaberInParry(hitOwner->client->ps.saberMove)&&!PM_SaberInReflect(hitOwner->client->ps.saberMove)) )
  4652. {//in the middle of attacking
  4653. /*
  4654. if ( hitOwner->client->ps.saberAnimLevel < SS_STRONG )
  4655. {//don't deflect/bounce in strong attack
  4656. WP_GetSaberDeflectionAngle( hitOwner, ent );
  4657. hitOwner->client->ps.saberEventFlags |= SEF_BLOCKED;
  4658. }
  4659. */
  4660. }
  4661. else
  4662. {//saber collided when not attacking, parry it
  4663. if ( !PM_SaberInBrokenParry( hitOwner->client->ps.saberMove ) )
  4664. {//not currently in a broken parry
  4665. if ( !WP_SaberParry( hitOwner, ent ) )
  4666. {//FIXME: hitOwner can't parry, do some time-consuming saber-knocked-aside broken parry anim?
  4667. //hitOwner->client->ps.saberBlocked = BLOCKED_PARRY_BROKEN;
  4668. }
  4669. }
  4670. }
  4671. }
  4672. else
  4673. {//nothing happens to *hitOwner* when their inFlight saber hits something
  4674. }
  4675. }
  4676. //collision must have been handled by now
  4677. //Set the blocked attack bounce value in saberBlocked so we actually play our saberBounceMove anim
  4678. if ( ent->client->ps.saberEventFlags & SEF_BLOCKED )
  4679. {
  4680. if ( ent->client->ps.saberBlocked != BLOCKED_PARRY_BROKEN )
  4681. {
  4682. ent->client->ps.saberBlocked = BLOCKED_ATK_BOUNCE;
  4683. }
  4684. }
  4685. /*
  4686. if ( hitOwner && hitOwner->client->ps.saberEventFlags & SEF_BLOCKED )
  4687. {
  4688. hitOwner->client->ps.saberBlocked = BLOCKED_ATK_BOUNCE;
  4689. }
  4690. */
  4691. }
  4692. if ( saberHitFraction < 1.0f || collisionResolved )
  4693. {//either actually hit or locked
  4694. if ( ent->client->ps.saberLockTime < level.time )
  4695. {
  4696. if ( inFlightSaberBlocked )
  4697. {//FIXME: never hear this sound
  4698. G_Sound( &g_entities[ent->client->ps.saberEntityNum], G_SoundIndex( va( "sound/weapons/saber/saberbounce%d.wav", Q_irand(1,3) ) ) );
  4699. }
  4700. else
  4701. {
  4702. if ( deflected )
  4703. {
  4704. #ifdef _IMMERSION
  4705. int index = Q_irand(1,3);
  4706. G_Sound( ent, G_SoundIndex( va("sound/weapons/saber/saberbounce%d.wav", index) ) );
  4707. int ff = G_ForceIndex( va("fffx/weapons/saber/saberbounce%d", index), FF_CHANNEL_WEAPON );
  4708. if ( !ent->s.saberInFlight )
  4709. {
  4710. G_Force( ent, ff );
  4711. }
  4712. if ( hitOwner && !hitOwner->s.saberInFlight )
  4713. {
  4714. G_Force( hitOwner, ff );
  4715. }
  4716. #else
  4717. G_Sound( ent, G_SoundIndex( va( "sound/weapons/saber/saberbounce%d.wav", Q_irand(1,3) ) ) );
  4718. #endif // _IMMERSION
  4719. }
  4720. else
  4721. {
  4722. #ifdef _IMMERSION
  4723. int index = Q_irand(1, 9);
  4724. G_Sound( ent, G_SoundIndex( va( "sound/weapons/saber/saberblock%d.wav", index) ) );
  4725. int ff = G_ForceIndex( va("fffx/weapons/saber/saberblock%d", index), FF_CHANNEL_WEAPON );
  4726. if ( !ent->s.saberInFlight )
  4727. {
  4728. G_Force( ent, ff );
  4729. }
  4730. if ( hitOwner && !hitOwner->s.saberInFlight )
  4731. {
  4732. G_Force( hitOwner, ff );
  4733. }
  4734. #else
  4735. G_Sound( ent, G_SoundIndex( va( "sound/weapons/saber/saberblock%d.wav", Q_irand(1, 9) ) ) );
  4736. #endif // _IMMERSION
  4737. }
  4738. }
  4739. if ( !g_saberNoEffects )
  4740. {
  4741. G_PlayEffect( "saber/saber_block", saberHitLocation, saberHitNormal );
  4742. if(ent->client && ent->client->ps.clientNum == 0)
  4743. FF_Play(fffx_Laser1);
  4744. }
  4745. }
  4746. // Set the little screen flash - only when an attack is blocked
  4747. g_saberFlashTime = level.time-50;
  4748. VectorCopy( saberHitLocation, g_saberFlashPos );
  4749. }
  4750. if ( saberHitFraction < 1.0f )
  4751. {
  4752. if ( inFlightSaberBlocked )
  4753. {//we threw a saber and it was blocked, do any effects, etc.
  4754. int knockAway = 5;
  4755. if ( hitEnt
  4756. && hitOwner
  4757. && hitOwner->client
  4758. && (PM_SaberInAttack( hitOwner->client->ps.saberMove ) || PM_SaberInSpecialAttack( hitOwner->client->ps.torsoAnim ) || PM_SpinningSaberAnim( hitOwner->client->ps.torsoAnim )) )
  4759. {//if hit someone who was in an attack or spin anim, more likely to have in-flight saber knocked away
  4760. if ( hitOwnerPowerLevel > FORCE_LEVEL_2 )
  4761. {//strong attacks almost always knock it aside!
  4762. knockAway = 1;
  4763. }
  4764. else
  4765. {//33% chance
  4766. knockAway = 2;
  4767. }
  4768. knockAway -= hitOwner->client->ps.SaberDisarmBonus();
  4769. }
  4770. if ( Q_irand( 0, knockAway ) <= 0 || //random
  4771. ( hitOwner
  4772. && hitOwner->client
  4773. && hitOwner->NPC
  4774. && (hitOwner->NPC->aiFlags&NPCAI_BOSS_CHARACTER)
  4775. ) //or if blocked by a Boss character FIXME: or base on defense level?
  4776. )//FIXME: player should not auto-block a flying saber, let him override the parry with an attack to knock the saber from the air, rather than this random chance
  4777. {//knock it aside and turn it off
  4778. if ( !g_saberNoEffects )
  4779. {
  4780. G_PlayEffect( "saber/saber_cut", saberHitLocation, saberHitNormal );
  4781. if(ent->client && ent->client->ps.clientNum == 0)
  4782. FF_Play(fffx_Laser1);
  4783. }
  4784. if ( hitEnt )
  4785. {
  4786. vec3_t newDir;
  4787. VectorSubtract( g_entities[ent->client->ps.saberEntityNum].currentOrigin, hitEnt->currentOrigin, newDir );
  4788. VectorNormalize( newDir );
  4789. G_ReflectMissile( ent, &g_entities[ent->client->ps.saberEntityNum], newDir );
  4790. }
  4791. Jedi_PlayDeflectSound( hitOwner );
  4792. WP_SaberDrop( ent, &g_entities[ent->client->ps.saberEntityNum] );
  4793. }
  4794. else
  4795. {
  4796. if ( !Q_irand( 0, 2 ) && hitEnt )
  4797. {
  4798. vec3_t newDir;
  4799. VectorSubtract( g_entities[ent->client->ps.saberEntityNum].currentOrigin, hitEnt->currentOrigin, newDir );
  4800. VectorNormalize( newDir );
  4801. G_ReflectMissile( ent, &g_entities[ent->client->ps.saberEntityNum], newDir );
  4802. }
  4803. WP_SaberReturn( ent, &g_entities[ent->client->ps.saberEntityNum] );
  4804. }
  4805. }
  4806. }
  4807. }
  4808. if ( ent->client->ps.saberLockTime > level.time
  4809. && ent->s.number < ent->client->ps.saberLockEnemy
  4810. && !Q_irand( 0, 3 ) )
  4811. {//need to make some kind of effect
  4812. vec3_t hitNorm = {0,0,1};
  4813. if ( WP_SabersIntersection( ent, &g_entities[ent->client->ps.saberLockEnemy], g_saberFlashPos ) )
  4814. {
  4815. if ( Q_irand( 0, 10 ) )
  4816. {
  4817. if ( !g_saberNoEffects )
  4818. {
  4819. G_PlayEffect( "saber/saber_block", g_saberFlashPos, hitNorm );
  4820. if(ent->client && ent->client->ps.clientNum == 0)
  4821. FF_Play(fffx_Laser1);
  4822. }
  4823. }
  4824. else
  4825. {
  4826. g_saberFlashTime = level.time-50;
  4827. if ( !g_saberNoEffects )
  4828. {
  4829. G_PlayEffect( "saber/saber_cut", g_saberFlashPos, hitNorm );
  4830. if(ent->client && ent->client->ps.clientNum == 0)
  4831. FF_Play(fffx_Laser1);
  4832. }
  4833. }
  4834. #ifdef _IMMERSION
  4835. int index = Q_irand(1, 9);
  4836. G_Sound( ent, G_SoundIndex( va( "sound/weapons/saber/saberblock%d.wav", index ) ) );
  4837. int ff = G_ForceIndex( va("fffx/weapons/saber/saberblock%d", index), FF_CHANNEL_WEAPON );
  4838. if ( !ent->s.saberInFlight )
  4839. {
  4840. G_Force( ent, ff );
  4841. }
  4842. if ( !g_entities[ent->client->ps.saberLockEnemy].s.saberInFlight )
  4843. {
  4844. G_Force( &g_entities[ent->client->ps.saberLockEnemy], ff );
  4845. }
  4846. #else
  4847. G_Sound( ent, G_SoundIndex( va( "sound/weapons/saber/saberblock%d.wav", Q_irand(1, 9) ) ) );
  4848. #endif // _IMMERSION
  4849. }
  4850. }
  4851. if ( WP_SaberApplyDamage( ent, baseDamage, baseDFlags, brokenParry, ent->client->ps.saber[saberNum].type, (qboolean)(saberNum==0&&ent->client->ps.saberInFlight) ) )
  4852. {//actually did damage to something
  4853. #ifndef FINAL_BUILD
  4854. if ( d_saberCombat->integer )
  4855. {
  4856. gi.Printf( "base damage was %4.2f\n", baseDamage );
  4857. }
  4858. #endif
  4859. WP_SaberHitSound( ent, saberNum );
  4860. }
  4861. if ( hit_wall )
  4862. {
  4863. //just so Jedi knows that he hit a wall
  4864. ent->client->ps.saberEventFlags |= SEF_HITWALL;
  4865. if ( ent->s.number == 0 )
  4866. {
  4867. AddSoundEvent( ent, ent->currentOrigin, 128, AEL_DISCOVERED, qfalse, qtrue );//FIXME: is this impact on ground or not?
  4868. AddSightEvent( ent, ent->currentOrigin, 256, AEL_DISCOVERED, 50 );
  4869. }
  4870. }
  4871. }
  4872. void WP_SabersDamageTrace( gentity_t *ent, qboolean noEffects )
  4873. {
  4874. if ( !ent->client )
  4875. {
  4876. return;
  4877. }
  4878. if ( PM_SuperBreakLoseAnim( ent->client->ps.torsoAnim ) )
  4879. {
  4880. return;
  4881. }
  4882. // Saber 1.
  4883. g_saberNoEffects = noEffects;
  4884. for ( int i = 0; i < ent->client->ps.saber[0].numBlades; i++ )
  4885. {
  4886. // If the Blade is not active and the length is 0, don't trace it, try the next blade...
  4887. if ( !ent->client->ps.saber[0].blade[i].active && ent->client->ps.saber[0].blade[i].length == 0 )
  4888. continue;
  4889. if ( i != 0 )
  4890. {//not first blade
  4891. if ( ent->client->ps.saber[0].type == SABER_BROAD ||
  4892. ent->client->ps.saber[0].type == SABER_SAI ||
  4893. ent->client->ps.saber[0].type == SABER_CLAW )
  4894. {
  4895. g_saberNoEffects = qtrue;
  4896. }
  4897. }
  4898. WP_SaberDamageTrace( ent, 0, i );
  4899. }
  4900. // Saber 2.
  4901. g_saberNoEffects = noEffects;
  4902. if ( ent->client->ps.dualSabers )
  4903. {
  4904. for ( int i = 0; i < ent->client->ps.saber[1].numBlades; i++ )
  4905. {
  4906. // If the Blade is not active and the length is 0, don't trace it, try the next blade...
  4907. if ( !ent->client->ps.saber[1].blade[i].active && ent->client->ps.saber[1].blade[i].length == 0 )
  4908. continue;
  4909. if ( i != 0 )
  4910. {//not first blade
  4911. if ( ent->client->ps.saber[1].type == SABER_BROAD ||
  4912. ent->client->ps.saber[1].type == SABER_SAI ||
  4913. ent->client->ps.saber[1].type == SABER_CLAW )
  4914. {
  4915. g_saberNoEffects = qtrue;
  4916. }
  4917. }
  4918. WP_SaberDamageTrace( ent, 1, i );
  4919. }
  4920. }
  4921. g_saberNoEffects = qfalse;
  4922. }
  4923. //SABER THROWING============================================================================
  4924. //SABER THROWING============================================================================
  4925. //SABER THROWING============================================================================
  4926. //SABER THROWING============================================================================
  4927. //SABER THROWING============================================================================
  4928. //SABER THROWING============================================================================
  4929. /*
  4930. ================
  4931. WP_SaberImpact
  4932. ================
  4933. */
  4934. void WP_SaberImpact( gentity_t *owner, gentity_t *saber, trace_t *trace )
  4935. {
  4936. gentity_t *other;
  4937. other = &g_entities[trace->entityNum];
  4938. if ( other->takedamage && (other->svFlags&SVF_BBRUSH) )
  4939. {//a breakable brush? break it!
  4940. if ( (other->spawnflags&1)//INVINCIBLE
  4941. ||(other->flags&FL_DMG_BY_HEAVY_WEAP_ONLY) )//HEAVY weapon damage only
  4942. {//can't actually break it
  4943. //no hit effect (besides regular client-side one)
  4944. }
  4945. else if ( other->NPC_targetname &&
  4946. (!owner||!owner->targetname||Q_stricmp(owner->targetname,other->NPC_targetname)) )
  4947. {//only breakable by an entity who is not the attacker
  4948. //no hit effect (besides regular client-side one)
  4949. }
  4950. else
  4951. {
  4952. vec3_t dir;
  4953. VectorCopy( saber->s.pos.trDelta, dir );
  4954. VectorNormalize( dir );
  4955. int dmg = other->health*2;
  4956. if ( other->health > 50 && dmg > 20 && !(other->svFlags&SVF_GLASS_BRUSH) )
  4957. {
  4958. dmg = 20;
  4959. }
  4960. G_Damage( other, saber, owner, dir, trace->endpos, dmg, 0, MOD_SABER );
  4961. G_PlayEffect( "saber/saber_cut", trace->endpos, dir );
  4962. if(owner->client && owner->client->ps.clientNum == 0)
  4963. FF_Play(fffx_Laser1);
  4964. if ( owner->s.number == 0 )
  4965. {
  4966. AddSoundEvent( owner, trace->endpos, 256, AEL_DISCOVERED );
  4967. AddSightEvent( owner, trace->endpos, 512, AEL_DISCOVERED, 50 );
  4968. }
  4969. return;
  4970. }
  4971. }
  4972. if ( saber->s.pos.trType == TR_LINEAR )
  4973. {
  4974. //hit a wall? send it back
  4975. WP_SaberReturn( saber->owner, saber );
  4976. }
  4977. if ( other && !other->client && (other->contents&CONTENTS_LIGHTSABER) )//&& other->s.weapon == WP_SABER )
  4978. {//2 in-flight sabers collided!
  4979. //Big flash
  4980. //FIXME: bigger effect/sound?
  4981. //FIXME: STILL DOESNT WORK!!!
  4982. G_Sound( saber, G_SoundIndex( va( "sound/weapons/saber/saberblock%d.wav", Q_irand(1, 9) ) ) );
  4983. G_PlayEffect( "saber/saber_block", trace->endpos );
  4984. if(owner->client && owner->client->ps.clientNum == 0)
  4985. FF_Play(fffx_Laser1);
  4986. g_saberFlashTime = level.time-50;
  4987. VectorCopy( trace->endpos, g_saberFlashPos );
  4988. }
  4989. if ( owner && owner->s.number == 0 && owner->client )
  4990. {
  4991. //Add the event
  4992. if ( owner->client->ps.SaberLength() > 0 )
  4993. {//saber is on, very suspicious
  4994. if ( (!owner->client->ps.saberInFlight && owner->client->ps.groundEntityNum == ENTITYNUM_WORLD)//holding saber and on ground
  4995. || saber->s.pos.trType == TR_STATIONARY )//saber out there somewhere and on ground
  4996. {//an on-ground alert
  4997. AddSoundEvent( owner, saber->currentOrigin, 128, AEL_DISCOVERED, qfalse, qtrue );
  4998. }
  4999. else
  5000. {//an in-air alert
  5001. AddSoundEvent( owner, saber->currentOrigin, 128, AEL_DISCOVERED );
  5002. }
  5003. AddSightEvent( owner, saber->currentOrigin, 256, AEL_DISCOVERED, 50 );
  5004. }
  5005. else
  5006. {//saber is off, not as suspicious
  5007. AddSoundEvent( owner, saber->currentOrigin, 128, AEL_SUSPICIOUS );
  5008. AddSightEvent( owner, saber->currentOrigin, 256, AEL_SUSPICIOUS );
  5009. }
  5010. }
  5011. // check for bounce
  5012. if ( !other->takedamage && ( saber->s.eFlags & ( EF_BOUNCE | EF_BOUNCE_HALF ) ) )
  5013. {
  5014. // Check to see if there is a bounce count
  5015. if ( saber->bounceCount ) {
  5016. // decrement number of bounces and then see if it should be done bouncing
  5017. if ( --saber->bounceCount <= 0 ) {
  5018. // He (or she) will bounce no more (after this current bounce, that is).
  5019. saber->s.eFlags &= !( EF_BOUNCE | EF_BOUNCE_HALF );
  5020. if ( saber->s.pos.trType == TR_LINEAR && owner && owner->client && owner->client->ps.saberEntityState == SES_RETURNING )
  5021. {
  5022. WP_SaberDrop( saber->owner, saber );
  5023. }
  5024. return;
  5025. }
  5026. else
  5027. {//bounced and still have bounces left
  5028. if ( saber->s.pos.trType == TR_LINEAR && owner && owner->client && owner->client->ps.saberEntityState == SES_RETURNING )
  5029. {//under telekinetic control
  5030. if ( !gi.inPVS( saber->currentOrigin, owner->client->renderInfo.handRPoint ) )
  5031. {//not in the PVS of my master
  5032. saber->bounceCount -= 25;
  5033. }
  5034. }
  5035. }
  5036. }
  5037. if ( saber->s.pos.trType == TR_LINEAR && owner && owner->client && owner->client->ps.saberEntityState == SES_RETURNING )
  5038. {
  5039. //don't home for a few frames so we can get around this thing
  5040. trace_t bounceTr;
  5041. vec3_t end;
  5042. float owner_dist = Distance( owner->client->renderInfo.handRPoint, saber->currentOrigin );
  5043. VectorMA( saber->currentOrigin, 10, trace->plane.normal, end );
  5044. gi.trace( &bounceTr, saber->currentOrigin, saber->mins, saber->maxs, end, owner->s.number, saber->clipmask );
  5045. VectorCopy( bounceTr.endpos, saber->currentOrigin );
  5046. if ( owner_dist > 0 )
  5047. {
  5048. if ( owner_dist > 50 )
  5049. {
  5050. owner->client->ps.saberEntityDist = owner_dist-50;
  5051. }
  5052. else
  5053. {
  5054. owner->client->ps.saberEntityDist = 0;
  5055. }
  5056. }
  5057. return;
  5058. }
  5059. G_BounceMissile( saber, trace );
  5060. if ( saber->s.pos.trType == TR_GRAVITY )
  5061. {//bounced
  5062. //play a bounce sound
  5063. if ( owner
  5064. && owner->client
  5065. && owner->client->ps.saber[0].type == SABER_SITH_SWORD )
  5066. {
  5067. G_Sound( saber, G_SoundIndex( va( "sound/weapons/sword/fall%d.wav", Q_irand( 1, 7 ) ) ) );
  5068. }
  5069. else
  5070. {
  5071. G_Sound( saber, G_SoundIndex( va( "sound/weapons/saber/bounce%d.wav", Q_irand( 1, 3 ) ) ) );
  5072. }
  5073. //change rotation
  5074. VectorCopy( saber->currentAngles, saber->s.apos.trBase );
  5075. saber->s.apos.trType = TR_LINEAR;
  5076. saber->s.apos.trTime = level.time;
  5077. VectorSet( saber->s.apos.trDelta, Q_irand( -300, 300 ), Q_irand( -300, 300 ), Q_irand( -300, 300 ) );
  5078. }
  5079. //see if we stopped
  5080. else if ( saber->s.pos.trType == TR_STATIONARY )
  5081. {//stopped
  5082. //play a bounce sound
  5083. if ( owner
  5084. && owner->client
  5085. && owner->client->ps.saber[0].type == SABER_SITH_SWORD )
  5086. {
  5087. G_Sound( saber, G_SoundIndex( va( "sound/weapons/sword/fall%d.wav", Q_irand( 1, 7 ) ) ) );
  5088. }
  5089. else
  5090. {
  5091. G_Sound( saber, G_SoundIndex( va( "sound/weapons/saber/bounce%d.wav", Q_irand( 1, 3 ) ) ) );
  5092. }
  5093. //stop rotation
  5094. VectorClear( saber->s.apos.trDelta );
  5095. saber->currentAngles[0] = SABER_PITCH_HACK;
  5096. VectorCopy( saber->currentAngles, saber->s.apos.trBase );
  5097. //remember when it fell so it can return automagically
  5098. saber->aimDebounceTime = level.time;
  5099. }
  5100. }
  5101. else if ( other->client && other->health > 0
  5102. && ( (other->NPC && (other->NPC->aiFlags&NPCAI_BOSS_CHARACTER))
  5103. //|| other->client->NPC_class == CLASS_ALORA
  5104. || other->client->NPC_class == CLASS_BOBAFETT
  5105. || ( other->client->ps.powerups[PW_GALAK_SHIELD] > 0 ) ) )
  5106. {//Luke, Desann and Tavion slap thrown sabers aside
  5107. WP_SaberDrop( owner, saber );
  5108. G_Sound( saber, G_SoundIndex( va( "sound/weapons/saber/saberblock%d.wav", Q_irand(1, 9) ) ) );
  5109. G_PlayEffect( "saber/saber_block", trace->endpos );
  5110. if(owner->client && owner->client->ps.clientNum == 0)
  5111. FF_Play(fffx_Laser1);
  5112. g_saberFlashTime = level.time-50;
  5113. VectorCopy( trace->endpos, g_saberFlashPos );
  5114. //FIXME: make Luke/Desann/Tavion play an attack anim or some other special anim when this happens
  5115. Jedi_PlayDeflectSound( other );
  5116. }
  5117. }
  5118. extern float G_PointDistFromLineSegment( const vec3_t start, const vec3_t end, const vec3_t from );
  5119. void WP_SaberInFlightReflectCheck( gentity_t *self, usercmd_t *ucmd )
  5120. {
  5121. gentity_t *ent;
  5122. gentity_t *entityList[MAX_GENTITIES];
  5123. gentity_t *missile_list[MAX_GENTITIES];
  5124. int numListedEntities;
  5125. vec3_t mins, maxs;
  5126. int i, e, numSabers;
  5127. int ent_count = 0;
  5128. int radius = 180;
  5129. vec3_t center;
  5130. vec3_t tip;
  5131. vec3_t up = {0,0,1};
  5132. qboolean willHit = qfalse;
  5133. if ( self->NPC && (self->NPC->scriptFlags&SCF_IGNORE_ALERTS) )
  5134. {//don't react to things flying at me...
  5135. return;
  5136. }
  5137. //sanity checks: make sure we actually have a saberent
  5138. if ( self->client->ps.weapon != WP_SABER )
  5139. {
  5140. return;
  5141. }
  5142. if ( !self->client->ps.saberInFlight )
  5143. {
  5144. return;
  5145. }
  5146. if ( !self->client->ps.SaberLength() )
  5147. {
  5148. return;
  5149. }
  5150. if ( self->client->ps.saberEntityNum == ENTITYNUM_NONE )
  5151. {
  5152. return;
  5153. }
  5154. gentity_t *saberent = &g_entities[self->client->ps.saberEntityNum];
  5155. if ( !saberent )
  5156. {
  5157. return;
  5158. }
  5159. //okay, enough damn sanity checks
  5160. VectorCopy( saberent->currentOrigin, center );
  5161. for ( i = 0 ; i < 3 ; i++ )
  5162. {
  5163. mins[i] = center[i] - radius;
  5164. maxs[i] = center[i] + radius;
  5165. }
  5166. numListedEntities = gi.EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  5167. //FIXME: check visibility?
  5168. for ( e = 0 ; e < numListedEntities ; e++ )
  5169. {
  5170. ent = entityList[ e ];
  5171. if (ent == self)
  5172. continue;
  5173. if (ent->owner == self)
  5174. continue;
  5175. if ( !(ent->inuse) )
  5176. continue;
  5177. if ( ent->s.eType != ET_MISSILE )
  5178. {
  5179. if ( ent->client || ent->s.weapon != WP_SABER )
  5180. {//FIXME: wake up bad guys?
  5181. continue;
  5182. }
  5183. if ( ent->s.eFlags & EF_NODRAW )
  5184. {
  5185. continue;
  5186. }
  5187. if ( Q_stricmp( "lightsaber", ent->classname ) != 0 )
  5188. {//not a lightsaber
  5189. continue;
  5190. }
  5191. }
  5192. else
  5193. {//FIXME: make exploding missiles explode?
  5194. if ( ent->s.pos.trType == TR_STATIONARY )
  5195. {//nothing you can do with a stationary missile
  5196. continue;
  5197. }
  5198. if ( ent->splashDamage || ent->splashRadius )
  5199. {//can't deflect exploding missiles
  5200. if ( DistanceSquared( ent->currentOrigin, center ) < 256 )//16 squared
  5201. {
  5202. G_MissileImpacted( ent, saberent, ent->currentOrigin, up );
  5203. }
  5204. continue;
  5205. }
  5206. }
  5207. //don't deflect it if it's not within 16 units of the blade
  5208. //do this for all blades
  5209. willHit = qfalse;
  5210. numSabers = 1;
  5211. if ( self->client->ps.dualSabers )
  5212. {
  5213. numSabers = 2;
  5214. }
  5215. for ( int saberNum = 0; saberNum < numSabers; saberNum++ )
  5216. {
  5217. for ( int bladeNum = 0; bladeNum < self->client->ps.saber[saberNum].numBlades; bladeNum++ )
  5218. {
  5219. VectorMA( self->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint, self->client->ps.saber[saberNum].blade[bladeNum].length, self->client->ps.saber[saberNum].blade[bladeNum].muzzleDir, tip );
  5220. if( G_PointDistFromLineSegment( self->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint, tip, ent->currentOrigin ) <= 32 )
  5221. {
  5222. willHit = qtrue;
  5223. break;
  5224. }
  5225. }
  5226. if ( willHit )
  5227. {
  5228. break;
  5229. }
  5230. }
  5231. if ( !willHit )
  5232. {
  5233. continue;
  5234. }
  5235. // ok, we are within the radius, add us to the incoming list
  5236. missile_list[ent_count] = ent;
  5237. ent_count++;
  5238. }
  5239. if ( ent_count )
  5240. {
  5241. vec3_t fx_dir;
  5242. // we are done, do we have any to deflect?
  5243. if ( ent_count )
  5244. {
  5245. for ( int x = 0; x < ent_count; x++ )
  5246. {
  5247. if ( missile_list[x]->s.weapon == WP_SABER )
  5248. {//just send it back
  5249. if ( missile_list[x]->owner && missile_list[x]->owner->client && missile_list[x]->owner->client->ps.saber[0].Active() && missile_list[x]->s.pos.trType == TR_LINEAR && missile_list[x]->owner->client->ps.saberEntityState != SES_RETURNING )
  5250. {//it's on and being controlled
  5251. //FIXME: prevent it from damaging me?
  5252. WP_SaberReturn( missile_list[x]->owner, missile_list[x] );
  5253. VectorNormalize2( missile_list[x]->s.pos.trDelta, fx_dir );
  5254. G_PlayEffect( "saber/saber_block", missile_list[x]->currentOrigin, fx_dir );
  5255. if(ent->client && ent->client->ps.clientNum == 0)
  5256. FF_Play(fffx_Laser1);
  5257. if ( missile_list[x]->owner->client->ps.saberInFlight && self->client->ps.saberInFlight )
  5258. {
  5259. G_Sound( missile_list[x], G_SoundIndex( va( "sound/weapons/saber/saberblock%d.wav", Q_irand(1, 9) ) ) );
  5260. g_saberFlashTime = level.time-50;
  5261. gentity_t *saber = &g_entities[self->client->ps.saberEntityNum];
  5262. vec3_t org;
  5263. VectorSubtract( missile_list[x]->currentOrigin, saber->currentOrigin, org );
  5264. VectorMA( saber->currentOrigin, 0.5, org, org );
  5265. VectorCopy( org, g_saberFlashPos );
  5266. }
  5267. }
  5268. }
  5269. else
  5270. {//bounce it
  5271. vec3_t reflectAngle, forward;
  5272. if ( self->client && !self->s.number )
  5273. {
  5274. self->client->sess.missionStats.saberBlocksCnt++;
  5275. }
  5276. VectorCopy( saberent->s.apos.trBase, reflectAngle );
  5277. reflectAngle[PITCH] = Q_flrand( -90, 90 );
  5278. AngleVectors( reflectAngle, forward, NULL, NULL );
  5279. G_ReflectMissile( self, missile_list[x], forward );
  5280. //do an effect
  5281. VectorNormalize2( missile_list[x]->s.pos.trDelta, fx_dir );
  5282. G_PlayEffect( "blaster/deflect", missile_list[x]->currentOrigin, fx_dir );
  5283. if(ent->client && ent->client->ps.clientNum == 0)
  5284. FF_Play(fffx_Laser2);
  5285. }
  5286. }
  5287. }
  5288. }
  5289. }
  5290. qboolean WP_SaberValidateEnemy( gentity_t *self, gentity_t *enemy )
  5291. {
  5292. if ( !enemy )
  5293. {
  5294. return qfalse;
  5295. }
  5296. if ( !enemy || enemy == self || !enemy->inuse || !enemy->client )
  5297. {//not valid
  5298. return qfalse;
  5299. }
  5300. if ( enemy->health <= 0 )
  5301. {//corpse
  5302. return qfalse;
  5303. }
  5304. /*
  5305. if ( enemy->client->ps.weapon == WP_SABER
  5306. && enemy->client->ps.SaberActive() )
  5307. {//not other saber-users?
  5308. return qfalse;
  5309. }
  5310. */
  5311. if ( enemy->client->ps.forcePowersKnown )
  5312. {//not other jedi?
  5313. return qfalse;
  5314. }
  5315. if ( DistanceSquared( self->client->renderInfo.handRPoint, enemy->currentOrigin ) > saberThrowDistSquared[self->client->ps.forcePowerLevel[FP_SABERTHROW]] )
  5316. {//too far
  5317. return qfalse;
  5318. }
  5319. if ( (!InFront( enemy->currentOrigin, self->currentOrigin, self->client->ps.viewangles, 0.0f) || !G_ClearLOS( self, self->client->renderInfo.eyePoint, enemy ) )
  5320. && ( DistanceHorizontalSquared( enemy->currentOrigin, self->currentOrigin ) > 65536 || fabs(enemy->currentOrigin[2]-self->currentOrigin[2]) > 384 ) )
  5321. {//(not in front or not clear LOS) & greater than 256 away
  5322. return qfalse;
  5323. }
  5324. if ( enemy->client->playerTeam == self->client->playerTeam )
  5325. {//on same team
  5326. return qfalse;
  5327. }
  5328. //LOS?
  5329. return qtrue;
  5330. }
  5331. float WP_SaberRateEnemy( gentity_t *enemy, vec3_t center, vec3_t forward, float radius )
  5332. {
  5333. float rating;
  5334. vec3_t dir;
  5335. VectorSubtract( enemy->currentOrigin, center, dir );
  5336. rating = (1.0f-(VectorNormalize( dir )/radius));
  5337. rating *= DotProduct( forward, dir );
  5338. return rating;
  5339. }
  5340. gentity_t *WP_SaberFindEnemy( gentity_t *self, gentity_t *saber )
  5341. {
  5342. //FIXME: should be a more intelligent way of doing this, like auto aim?
  5343. //closest, most in front... did damage to... took damage from? How do we know who the player is focusing on?
  5344. gentity_t *ent, *bestEnt = NULL;
  5345. gentity_t *entityList[MAX_GENTITIES];
  5346. int numListedEntities;
  5347. vec3_t center, mins, maxs, fwdangles, forward;
  5348. int i, e;
  5349. float radius = 400;
  5350. float rating, bestRating = 0.0f;
  5351. //FIXME: no need to do this in 1st person?
  5352. fwdangles[1] = self->client->ps.viewangles[1];
  5353. AngleVectors( fwdangles, forward, NULL, NULL );
  5354. VectorCopy( saber->currentOrigin, center );
  5355. for ( i = 0 ; i < 3 ; i++ )
  5356. {
  5357. mins[i] = center[i] - radius;
  5358. maxs[i] = center[i] + radius;
  5359. }
  5360. //if the saber has an enemy from the last time it looked, init to that one
  5361. if ( WP_SaberValidateEnemy( self, saber->enemy ) )
  5362. {
  5363. if ( gi.inPVS( self->currentOrigin, saber->enemy->currentOrigin ) )
  5364. {//potentially visible
  5365. if ( G_ClearLOS( self, self->client->renderInfo.eyePoint, saber->enemy ) )
  5366. {//can see him
  5367. bestEnt = saber->enemy;
  5368. bestRating = WP_SaberRateEnemy( bestEnt, center, forward, radius );
  5369. }
  5370. }
  5371. }
  5372. //If I have an enemy, see if that's even better
  5373. if ( WP_SaberValidateEnemy( self, self->enemy ) )
  5374. {
  5375. float myEnemyRating = WP_SaberRateEnemy( self->enemy, center, forward, radius );
  5376. if ( myEnemyRating > bestRating )
  5377. {
  5378. if ( gi.inPVS( self->currentOrigin, self->enemy->currentOrigin ) )
  5379. {//potentially visible
  5380. if ( G_ClearLOS( self, self->client->renderInfo.eyePoint, self->enemy ) )
  5381. {//can see him
  5382. bestEnt = self->enemy;
  5383. bestRating = myEnemyRating;
  5384. }
  5385. }
  5386. }
  5387. }
  5388. numListedEntities = gi.EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  5389. if ( !numListedEntities )
  5390. {//should we clear the enemy?
  5391. return bestEnt;
  5392. }
  5393. for ( e = 0 ; e < numListedEntities ; e++ )
  5394. {
  5395. ent = entityList[ e ];
  5396. if ( ent == self || ent == saber || ent == bestEnt )
  5397. {
  5398. continue;
  5399. }
  5400. if ( !WP_SaberValidateEnemy( self, ent ) )
  5401. {//doesn't meet criteria of valid look enemy (don't check current since we would have done that before this func's call
  5402. continue;
  5403. }
  5404. if ( !gi.inPVS( self->currentOrigin, ent->currentOrigin ) )
  5405. {//not even potentially visible
  5406. continue;
  5407. }
  5408. if ( !G_ClearLOS( self, self->client->renderInfo.eyePoint, ent ) )
  5409. {//can't see him
  5410. continue;
  5411. }
  5412. //rate him based on how close & how in front he is
  5413. rating = WP_SaberRateEnemy( ent, center, forward, radius );
  5414. if ( rating > bestRating )
  5415. {
  5416. bestEnt = ent;
  5417. bestRating = rating;
  5418. }
  5419. }
  5420. return bestEnt;
  5421. }
  5422. void WP_RunSaber( gentity_t *self, gentity_t *saber )
  5423. {
  5424. vec3_t origin, oldOrg;
  5425. trace_t tr;
  5426. VectorCopy( saber->currentOrigin, oldOrg );
  5427. // get current position
  5428. EvaluateTrajectory( &saber->s.pos, level.time, origin );
  5429. // get current angles
  5430. EvaluateTrajectory( &saber->s.apos, level.time, saber->currentAngles );
  5431. // trace a line from the previous position to the current position,
  5432. // ignoring interactions with the missile owner
  5433. int clipmask = saber->clipmask;
  5434. if ( !self || !self->client || self->client->ps.SaberLength() <= 0 )
  5435. {//don't keep hitting other sabers when turned off
  5436. clipmask &= ~CONTENTS_LIGHTSABER;
  5437. }
  5438. gi.trace( &tr, saber->currentOrigin, saber->mins, saber->maxs, origin,
  5439. saber->owner ? saber->owner->s.number : ENTITYNUM_NONE, clipmask );
  5440. VectorCopy( tr.endpos, saber->currentOrigin );
  5441. if ( self->client->ps.SaberActive() )
  5442. {
  5443. if ( self->client->ps.saberInFlight || (self->client->ps.weaponTime&&!Q_irand( 0, 100 )) )
  5444. {//make enemies run from a lit saber in flight or from me when I'm attacking
  5445. if ( !Q_irand( 0, 10 ) )
  5446. {//not so often...
  5447. AddSightEvent( self, saber->currentOrigin, self->client->ps.SaberLength()*3, AEL_DANGER, 100 );
  5448. }
  5449. }
  5450. }
  5451. if ( tr.startsolid )
  5452. {
  5453. tr.fraction = 0;
  5454. }
  5455. gi.linkentity( saber );
  5456. //touch push triggers?
  5457. if ( tr.fraction != 1 )
  5458. {
  5459. WP_SaberImpact( self, saber, &tr );
  5460. }
  5461. if ( saber->s.pos.trType == TR_LINEAR )
  5462. {//home
  5463. //figure out where saber should be
  5464. vec3_t forward, saberHome, saberDest, fwdangles = {0};
  5465. VectorCopy( self->client->ps.viewangles, fwdangles );
  5466. if ( self->s.number )
  5467. {
  5468. fwdangles[0] -= 8;
  5469. }
  5470. else if ( cg.renderingThirdPerson )
  5471. {
  5472. fwdangles[0] -= 5;
  5473. }
  5474. if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] > FORCE_LEVEL_1
  5475. || self->client->ps.saberEntityState == SES_RETURNING
  5476. || VectorCompare( saber->s.pos.trDelta, vec3_origin ) )
  5477. {//control if it's returning or just starting
  5478. float saberSpeed = 500;//FIXME: based on force level?
  5479. float dist;
  5480. gentity_t *enemy = NULL;
  5481. AngleVectors( fwdangles, forward, NULL, NULL );
  5482. if ( self->client->ps.saberEntityDist < 100 )
  5483. {//make the saber head to my hand- the bolt it was attached to
  5484. VectorCopy( self->client->renderInfo.handRPoint, saberHome );
  5485. }
  5486. else
  5487. {//aim saber from eyes
  5488. VectorCopy( self->client->renderInfo.eyePoint, saberHome );
  5489. }
  5490. VectorMA( saberHome, self->client->ps.saberEntityDist, forward, saberDest );
  5491. if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] > FORCE_LEVEL_2
  5492. && self->client->ps.saberEntityState == SES_LEAVING )
  5493. {//max level
  5494. if ( self->enemy &&
  5495. !WP_SaberValidateEnemy( self, self->enemy ) )
  5496. {//if my enemy isn't valid to auto-aim at, don't autoaim
  5497. }
  5498. else
  5499. {
  5500. //pick an enemy
  5501. enemy = WP_SaberFindEnemy( self, saber );
  5502. if ( enemy )
  5503. {//home in on enemy
  5504. float enemyDist = Distance( self->client->renderInfo.handRPoint, enemy->currentOrigin );
  5505. VectorCopy( enemy->currentOrigin, saberDest );
  5506. saberDest[2] += enemy->maxs[2]/2.0f;//FIXME: when in a knockdown anim, the saber float above them... do we care?
  5507. self->client->ps.saberEntityDist = enemyDist;
  5508. //once you pick an enemy, stay with it!
  5509. saber->enemy = enemy;
  5510. //FIXME: lock onto that enemy for a minimum amount of time (unless they become invalid?)
  5511. }
  5512. }
  5513. }
  5514. //Make the saber head there
  5515. VectorSubtract( saberDest, saber->currentOrigin, saber->s.pos.trDelta );
  5516. dist = VectorNormalize( saber->s.pos.trDelta );
  5517. if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] > FORCE_LEVEL_2 && self->client->ps.saberEntityState == SES_LEAVING && !enemy )
  5518. {
  5519. if ( dist < 200 )
  5520. {
  5521. saberSpeed = 400 - (dist*2);
  5522. }
  5523. }
  5524. else if ( self->client->ps.saberEntityState == SES_LEAVING && dist < 50 )
  5525. {
  5526. saberSpeed = dist * 2 + 30;
  5527. if ( (enemy && dist > enemy->maxs[0]) || (!enemy && dist > 24) )
  5528. {//auto-tracking an enemy and we can't hit him
  5529. if ( saberSpeed < 120 )
  5530. {//clamp to a minimum speed
  5531. saberSpeed = 120;
  5532. }
  5533. }
  5534. }
  5535. /*
  5536. if ( self->client->ps.saberEntityState == SES_RETURNING )
  5537. {//FIXME: if returning, move faster?
  5538. saberSpeed = 800;
  5539. if ( dist < 200 )
  5540. {
  5541. saberSpeed -= 400 - (dist*2);
  5542. }
  5543. }
  5544. */
  5545. VectorScale( saber->s.pos.trDelta, saberSpeed, saber->s.pos.trDelta );
  5546. //SnapVector( saber->s.pos.trDelta ); // save net bandwidth
  5547. VectorCopy( saber->currentOrigin, saber->s.pos.trBase );
  5548. saber->s.pos.trTime = level.time;
  5549. saber->s.pos.trType = TR_LINEAR;
  5550. }
  5551. else
  5552. {
  5553. VectorCopy( saber->currentOrigin, saber->s.pos.trBase );
  5554. saber->s.pos.trTime = level.time;
  5555. saber->s.pos.trType = TR_LINEAR;
  5556. }
  5557. //if it's heading back, point it's base at us
  5558. if ( self->client->ps.saberEntityState == SES_RETURNING
  5559. && self->client->ps.saber[0].returnDamage == qfalse )//type != SABER_STAR )
  5560. {
  5561. fwdangles[0] += SABER_PITCH_HACK;
  5562. VectorCopy( fwdangles, saber->s.apos.trBase );
  5563. saber->s.apos.trTime = level.time;
  5564. saber->s.apos.trType = TR_INTERPOLATE;
  5565. VectorClear( saber->s.apos.trDelta );
  5566. }
  5567. }
  5568. }
  5569. qboolean WP_SaberLaunch( gentity_t *self, gentity_t *saber, qboolean thrown, qboolean noFail = qfalse )
  5570. {//FIXME: probably need a debounce time
  5571. vec3_t saberMins={-3.0f,-3.0f,-3.0f};
  5572. vec3_t saberMaxs={3.0f,3.0f,3.0f};
  5573. trace_t trace;
  5574. if ( self->client->NPC_class == CLASS_SABER_DROID )
  5575. {//saber droids can't drop their saber
  5576. return qfalse;
  5577. }
  5578. if ( !noFail )
  5579. {
  5580. if ( thrown )
  5581. {//this is a regular throw, so see if it's legal
  5582. if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] > FORCE_LEVEL_2 )
  5583. {
  5584. if ( !WP_ForcePowerUsable( self, FP_SABERTHROW, 20 ) )
  5585. {
  5586. return qfalse;
  5587. }
  5588. }
  5589. else
  5590. {
  5591. if ( !WP_ForcePowerUsable( self, FP_SABERTHROW, 0 ) )
  5592. {
  5593. return qfalse;
  5594. }
  5595. }
  5596. }
  5597. if ( !self->s.number && (cg.zoomMode || in_camera) )
  5598. {//can't saber throw when zoomed in or in cinematic
  5599. return qfalse;
  5600. }
  5601. //make sure it won't start in solid
  5602. gi.trace( &trace, self->client->renderInfo.handRPoint, saberMins, saberMaxs, self->client->renderInfo.handRPoint, saber->s.number, MASK_SOLID );
  5603. if ( trace.startsolid || trace.allsolid )
  5604. {
  5605. return qfalse;
  5606. }
  5607. //make sure I'm not throwing it on the other side of a door or wall or whatever
  5608. gi.trace( &trace, self->currentOrigin, vec3_origin, vec3_origin, self->client->renderInfo.handRPoint, self->s.number, MASK_SOLID );
  5609. if ( trace.startsolid || trace.allsolid || trace.fraction < 1.0f )
  5610. {
  5611. return qfalse;
  5612. }
  5613. if ( thrown )
  5614. {//this is a regular throw, so take force power
  5615. if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] > FORCE_LEVEL_2 )
  5616. {//at max skill, the cost increases as keep it out
  5617. WP_ForcePowerStart( self, FP_SABERTHROW, 10 );
  5618. }
  5619. else
  5620. {
  5621. WP_ForcePowerStart( self, FP_SABERTHROW, 0 );
  5622. }
  5623. }
  5624. }
  5625. //clear the enemy
  5626. saber->enemy = NULL;
  5627. //draw it
  5628. saber->s.eFlags &= ~EF_NODRAW;
  5629. saber->svFlags |= SVF_BROADCAST;
  5630. saber->svFlags &= ~SVF_NOCLIENT;
  5631. //place it
  5632. VectorCopy( self->client->renderInfo.handRPoint, saber->currentOrigin );//muzzlePoint
  5633. VectorCopy( saber->currentOrigin, saber->s.pos.trBase );
  5634. saber->s.pos.trTime = level.time;
  5635. saber->s.pos.trType = TR_LINEAR;
  5636. VectorClear( saber->s.pos.trDelta );
  5637. gi.linkentity( saber );
  5638. //spin it
  5639. VectorClear( saber->s.apos.trBase );
  5640. saber->s.apos.trTime = level.time;
  5641. saber->s.apos.trType = TR_LINEAR;
  5642. if ( self->health > 0 && thrown )
  5643. {//throwing it
  5644. saber->s.apos.trBase[1] = self->client->ps.viewangles[1];
  5645. saber->s.apos.trBase[0] = SABER_PITCH_HACK;
  5646. }
  5647. else
  5648. {//dropping it
  5649. vectoangles( self->client->renderInfo.muzzleDir, saber->s.apos.trBase );
  5650. }
  5651. VectorClear( saber->s.apos.trDelta );
  5652. switch ( self->client->ps.forcePowerLevel[FP_SABERTHROW] )
  5653. {//FIXME: make a table?
  5654. default:
  5655. case FORCE_LEVEL_1:
  5656. saber->s.apos.trDelta[1] = 600;
  5657. break;
  5658. case FORCE_LEVEL_2:
  5659. saber->s.apos.trDelta[1] = 800;
  5660. break;
  5661. case FORCE_LEVEL_3:
  5662. saber->s.apos.trDelta[1] = 1200;
  5663. break;
  5664. }
  5665. //Take it out of my hand
  5666. self->client->ps.saberInFlight = qtrue;
  5667. self->client->ps.saberEntityState = SES_LEAVING;
  5668. self->client->ps.saberEntityDist = saberThrowDist[self->client->ps.forcePowerLevel[FP_SABERTHROW]];
  5669. self->client->ps.saberThrowTime = level.time;
  5670. //if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] > FORCE_LEVEL_2 )
  5671. {
  5672. self->client->ps.forcePowerDebounce[FP_SABERTHROW] = level.time + 1000;//so we can keep it out for a minimum amount of time
  5673. }
  5674. if ( thrown )
  5675. {//this is a regular throw, so turn the saber on
  5676. //turn saber on
  5677. if ( self->client->ps.saber[0].singleBladeThrowable )//SaberStaff() )
  5678. {//only first blade can be on
  5679. if ( !self->client->ps.saber[0].blade[0].active )
  5680. {//turn on first one
  5681. self->client->ps.SaberBladeActivate( 0, 0 );
  5682. }
  5683. for ( int i = 1; i < self->client->ps.saber[0].numBlades; i++ )
  5684. {//turn off all others
  5685. if ( self->client->ps.saber[0].blade[i].active )
  5686. {
  5687. self->client->ps.SaberBladeActivate( 0, i, qfalse );
  5688. }
  5689. }
  5690. }
  5691. else
  5692. {//turn the sabers, all blades...?
  5693. self->client->ps.saber[0].Activate();
  5694. //self->client->ps.SaberActivate();
  5695. }
  5696. //turn on the saber trail
  5697. self->client->ps.saber[0].ActivateTrail( 150 );
  5698. }
  5699. //reset the mins
  5700. VectorCopy( saberMins, saber->mins );
  5701. VectorCopy( saberMaxs, saber->maxs );
  5702. saber->contents = 0;//CONTENTS_LIGHTSABER;
  5703. saber->clipmask = MASK_SOLID | CONTENTS_LIGHTSABER;
  5704. // remove the ghoul2 right-hand saber model on the player
  5705. if ( self->weaponModel[0] > 0 )
  5706. {
  5707. gi.G2API_RemoveGhoul2Model(self->ghoul2, self->weaponModel[0]);
  5708. self->weaponModel[0] = -1;
  5709. }
  5710. return qtrue;
  5711. }
  5712. qboolean WP_SaberLose( gentity_t *self, vec3_t throwDir )
  5713. {
  5714. if ( !self || !self->client || self->client->ps.saberEntityNum <= 0 )
  5715. {//WTF?!! We lost it already?
  5716. return qfalse;
  5717. }
  5718. if ( self->client->NPC_class == CLASS_SABER_DROID )
  5719. {//saber droids can't drop their saber
  5720. return qfalse;
  5721. }
  5722. gentity_t *dropped = &g_entities[self->client->ps.saberEntityNum];
  5723. if ( !self->client->ps.saberInFlight )
  5724. {//not alreay in air
  5725. /*
  5726. qboolean noForceThrow = qfalse;
  5727. //make it so we can throw it
  5728. self->client->ps.forcePowersKnown |= (1<<FP_SABERTHROW);
  5729. if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] < FORCE_LEVEL_1 )
  5730. {
  5731. noForceThrow = qtrue;
  5732. self->client->ps.forcePowerLevel[FP_SABERTHROW] = FORCE_LEVEL_1;
  5733. }
  5734. */
  5735. //throw it
  5736. if ( !WP_SaberLaunch( self, dropped, qfalse ) )
  5737. {//couldn't throw it
  5738. return qfalse;
  5739. }
  5740. /*
  5741. if ( noForceThrow )
  5742. {
  5743. self->client->ps.forcePowerLevel[FP_SABERTHROW] = FORCE_LEVEL_0;
  5744. }
  5745. */
  5746. }
  5747. if ( self->client->ps.saber[0].Active() )
  5748. {//on
  5749. //drop it instantly
  5750. WP_SaberDrop( self, dropped );
  5751. }
  5752. //optionally give it some thrown velocity
  5753. if ( throwDir && !VectorCompare( throwDir, vec3_origin ) )
  5754. {
  5755. VectorCopy( throwDir, dropped->s.pos.trDelta );
  5756. }
  5757. //don't pull it back on the next frame
  5758. if ( self->NPC )
  5759. {
  5760. self->NPC->last_ucmd.buttons &= ~BUTTON_ATTACK;
  5761. }
  5762. return qtrue;
  5763. }
  5764. void WP_SetSaberOrigin( gentity_t *self, vec3_t newOrg )
  5765. {
  5766. if ( !self || !self->client )
  5767. {
  5768. return;
  5769. }
  5770. if ( self->client->ps.saberEntityNum <= 0 || self->client->ps.saberEntityNum >= ENTITYNUM_WORLD )
  5771. {//no saber ent to reposition
  5772. return;
  5773. }
  5774. if ( self->client->NPC_class == CLASS_SABER_DROID )
  5775. {//saber droids can't drop their saber
  5776. return;
  5777. }
  5778. gentity_t *dropped = &g_entities[self->client->ps.saberEntityNum];
  5779. if ( !self->client->ps.saberInFlight )
  5780. {//not already in air
  5781. qboolean noForceThrow = qfalse;
  5782. //make it so we can throw it
  5783. self->client->ps.forcePowersKnown |= (1<<FP_SABERTHROW);
  5784. if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] < FORCE_LEVEL_1 )
  5785. {
  5786. noForceThrow = qtrue;
  5787. self->client->ps.forcePowerLevel[FP_SABERTHROW] = FORCE_LEVEL_1;
  5788. }
  5789. //throw it
  5790. if ( !WP_SaberLaunch( self, dropped, qfalse, qtrue ) )
  5791. {//couldn't throw it
  5792. return;
  5793. }
  5794. if ( noForceThrow )
  5795. {
  5796. self->client->ps.forcePowerLevel[FP_SABERTHROW] = FORCE_LEVEL_0;
  5797. }
  5798. }
  5799. VectorCopy( newOrg, dropped->s.origin );
  5800. VectorCopy( newOrg, dropped->currentOrigin );
  5801. VectorCopy( newOrg, dropped->s.pos.trBase );
  5802. //drop it instantly
  5803. WP_SaberDrop( self, dropped );
  5804. //don't pull it back on the next frame
  5805. if ( self->NPC )
  5806. {
  5807. self->NPC->last_ucmd.buttons &= ~BUTTON_ATTACK;
  5808. }
  5809. }
  5810. void WP_SaberCatch( gentity_t *self, gentity_t *saber, qboolean switchToSaber )
  5811. {//FIXME: probably need a debounce time
  5812. if ( self->health > 0 && !PM_SaberInBrokenParry( self->client->ps.saberMove ) && self->client->ps.saberBlocked != BLOCKED_PARRY_BROKEN )
  5813. {
  5814. //clear the enemy
  5815. saber->enemy = NULL;
  5816. //don't draw it
  5817. saber->s.eFlags |= EF_NODRAW;
  5818. saber->svFlags &= SVF_BROADCAST;
  5819. saber->svFlags |= SVF_NOCLIENT;
  5820. //take off any gravity stuff if we'd dropped it
  5821. saber->s.pos.trType = TR_LINEAR;
  5822. saber->s.eFlags &= ~EF_BOUNCE_HALF;
  5823. //Put it in my hand
  5824. self->client->ps.saberInFlight = qfalse;
  5825. self->client->ps.saberEntityState = SES_LEAVING;
  5826. //turn off the saber trail
  5827. self->client->ps.saber[0].DeactivateTrail( 75 );
  5828. //reset its contents/clipmask
  5829. saber->contents = CONTENTS_LIGHTSABER;// | CONTENTS_SHOTCLIP;
  5830. saber->clipmask = MASK_SHOT | CONTENTS_LIGHTSABER;
  5831. //play catch sound
  5832. G_Sound( saber, G_SoundIndex( "sound/weapons/saber/saber_catch.wav" ) );
  5833. //FIXME: if an NPC, don't turn it back on if no enemy or enemy is dead...
  5834. //if it's not our current weapon, make it our current weapon
  5835. if ( self->client->ps.weapon == WP_SABER )
  5836. {//only do the first saber since we only throw the first one
  5837. WP_SaberAddG2SaberModels( self, qfalse );
  5838. }
  5839. if ( switchToSaber )
  5840. {
  5841. if ( self->client->ps.weapon != WP_SABER )
  5842. {
  5843. CG_ChangeWeapon( WP_SABER );
  5844. }
  5845. else
  5846. {//if it's not active, turn it on
  5847. if ( self->client->ps.saber[0].singleBladeThrowable )//SaberStaff() )
  5848. {//only first blade can be on
  5849. if ( !self->client->ps.saber[0].blade[0].active )
  5850. {//only turn it on if first blade is off, otherwise, leave as-is
  5851. self->client->ps.saber[0].Activate();
  5852. }
  5853. }
  5854. else
  5855. {//turn all blades on
  5856. self->client->ps.saber[0].Activate();
  5857. }
  5858. }
  5859. }
  5860. }
  5861. }
  5862. void WP_SaberReturn( gentity_t *self, gentity_t *saber )
  5863. {
  5864. if ( PM_SaberInBrokenParry( self->client->ps.saberMove ) || self->client->ps.saberBlocked == BLOCKED_PARRY_BROKEN )
  5865. {
  5866. return;
  5867. }
  5868. if ( self && self->client )
  5869. {//still alive and stuff
  5870. //FIXME: when it's returning, flies butt first, but seems to do a lot of damage when going through people... hmm...
  5871. self->client->ps.saberEntityState = SES_RETURNING;
  5872. //turn down the saber trail
  5873. if ( self->client->ps.saber[0].returnDamage == qfalse )//type != SABER_STAR )
  5874. {
  5875. self->client->ps.saber[0].DeactivateTrail( 75 );
  5876. }
  5877. }
  5878. if ( !(saber->s.eFlags&EF_BOUNCE) )
  5879. {
  5880. saber->s.eFlags |= EF_BOUNCE;
  5881. saber->bounceCount = 300;
  5882. }
  5883. }
  5884. void WP_SaberDrop( gentity_t *self, gentity_t *saber )
  5885. {
  5886. //clear the enemy
  5887. saber->enemy = NULL;
  5888. saber->s.eFlags &= ~EF_BOUNCE;
  5889. saber->bounceCount = 0;
  5890. //make it fall
  5891. saber->s.pos.trType = TR_GRAVITY;
  5892. //make it bounce some
  5893. saber->s.eFlags |= EF_BOUNCE_HALF;
  5894. //make it spin
  5895. VectorCopy( saber->currentAngles, saber->s.apos.trBase );
  5896. saber->s.apos.trType = TR_LINEAR;
  5897. saber->s.apos.trTime = level.time;
  5898. VectorSet( saber->s.apos.trDelta, Q_irand( -300, 300 ), saber->s.apos.trDelta[1], Q_irand( -300, 300 ) );
  5899. if ( !saber->s.apos.trDelta[1] )
  5900. {
  5901. saber->s.apos.trDelta[1] = Q_irand( -300, 300 );
  5902. }
  5903. //force it to be ready to return
  5904. self->client->ps.saberEntityDist = 0;
  5905. self->client->ps.saberEntityState = SES_RETURNING;
  5906. //turn it off
  5907. self->client->ps.saber[0].Deactivate();
  5908. //turn off the saber trail
  5909. self->client->ps.saber[0].DeactivateTrail( 75 );
  5910. //play the saber turning off sound
  5911. G_SoundIndexOnEnt( saber, CHAN_AUTO, self->client->ps.saber[0].soundOff );
  5912. #ifdef _IMMERSION
  5913. if ( self->client->playerTeam == TEAM_PLAYER )
  5914. {
  5915. G_Force( self, G_ForceIndex( "fffx/weapons/saber/saberoff", FF_CHANNEL_WEAPON ) );
  5916. }
  5917. else
  5918. {
  5919. G_Force( self, G_ForceIndex( "fffx/weapons/saber/enemy_saber_off", FF_CHANNEL_WEAPON ) );
  5920. }
  5921. #endif // _IMMERSION
  5922. if ( self->health <= 0 )
  5923. {//owner is dead!
  5924. saber->s.time = level.time;//will make us free ourselves after a time
  5925. }
  5926. }
  5927. void WP_SaberPull( gentity_t *self, gentity_t *saber )
  5928. {
  5929. if ( PM_SaberInBrokenParry( self->client->ps.saberMove ) || self->client->ps.saberBlocked == BLOCKED_PARRY_BROKEN )
  5930. {
  5931. return;
  5932. }
  5933. if ( self->health > 0 )
  5934. {
  5935. //take off gravity
  5936. saber->s.pos.trType = TR_LINEAR;
  5937. //take off bounce
  5938. saber->s.eFlags &= EF_BOUNCE_HALF;
  5939. //play sound
  5940. G_Sound( self, G_SoundIndex( "sound/weapons/force/pull.wav" ) );
  5941. #ifdef _IMMERSION
  5942. G_Force( self, G_ForceIndex( "fffx/weapons/force/pull", FF_CHANNEL_WEAPON ) );
  5943. #endif // _IMMERSION
  5944. }
  5945. }
  5946. // Check if we are throwing it, launch it if needed, update position if needed.
  5947. void WP_SaberThrow( gentity_t *self, usercmd_t *ucmd )
  5948. {
  5949. static float MAX_SABER_DIST = 400;
  5950. vec3_t saberDiff;
  5951. trace_t tr;
  5952. //static float SABER_SPEED = 10;
  5953. gentity_t *saberent;
  5954. if ( self->client->ps.saberEntityNum <= 0 || self->client->ps.saberEntityNum >= ENTITYNUM_WORLD )
  5955. {//WTF?!! We lost it?
  5956. return;
  5957. }
  5958. if ( self->client->ps.torsoAnim == BOTH_LOSE_SABER )
  5959. {//can't catch it while it's being yanked from your hand!
  5960. return;
  5961. }
  5962. if ( !g_saberNewControlScheme->integer )
  5963. {
  5964. if ( PM_SaberInKata( (saberMoveName_t)self->client->ps.saberMove ) )
  5965. {//don't throw saber when in special attack (alt+attack)
  5966. return;
  5967. }
  5968. if ( (ucmd->buttons&BUTTON_ATTACK)
  5969. && (ucmd->buttons&BUTTON_ALT_ATTACK)
  5970. && !self->client->ps.saberInFlight )
  5971. {//trying to do special attack, don't throw it
  5972. return;
  5973. }
  5974. else if ( self->client->ps.torsoAnim == BOTH_A1_SPECIAL
  5975. || self->client->ps.torsoAnim == BOTH_A2_SPECIAL
  5976. || self->client->ps.torsoAnim == BOTH_A3_SPECIAL )
  5977. {//don't throw in these anims!
  5978. return;
  5979. }
  5980. }
  5981. saberent = &g_entities[self->client->ps.saberEntityNum];
  5982. VectorSubtract( self->client->renderInfo.handRPoint, saberent->currentOrigin, saberDiff );
  5983. //is our saber in flight?
  5984. if ( !self->client->ps.saberInFlight )
  5985. {//saber is not in flight right now
  5986. if ( self->client->ps.weapon != WP_SABER )
  5987. {//don't even have it out
  5988. return;
  5989. }
  5990. else if ( (ucmd->buttons&BUTTON_ALT_ATTACK) && !(self->client->ps.pm_flags&PMF_ALT_ATTACK_HELD) )
  5991. {//still holding it, not still holding attack from a previous throw, so throw it.
  5992. if ( !(self->client->ps.saberEventFlags&SEF_INWATER) && WP_SaberLaunch( self, saberent, qtrue ) )
  5993. {
  5994. if ( self->client && !self->s.number )
  5995. {
  5996. self->client->sess.missionStats.saberThrownCnt++;
  5997. }
  5998. //need to recalc this because we just moved it
  5999. VectorSubtract( self->client->renderInfo.handRPoint, saberent->currentOrigin, saberDiff );
  6000. }
  6001. else
  6002. {//couldn't throw it
  6003. return;
  6004. }
  6005. }
  6006. else
  6007. {//holding it, don't want to throw it, go away.
  6008. return;
  6009. }
  6010. }
  6011. else
  6012. {//inflight
  6013. //is our saber currently on it's way back to us?
  6014. if ( self->client->ps.saberEntityState == SES_RETURNING )
  6015. {//see if we're close enough to pick it up
  6016. if ( VectorLengthSquared( saberDiff ) <= 256 )//16 squared//G_BoundsOverlap( self->absmin, self->absmax, saberent->absmin, saberent->absmax ) )//
  6017. {//caught it
  6018. vec3_t axisPoint;
  6019. trace_t trace;
  6020. VectorCopy( self->currentOrigin, axisPoint );
  6021. axisPoint[2] = self->client->renderInfo.handRPoint[2];
  6022. gi.trace( &trace, axisPoint, vec3_origin, vec3_origin, self->client->renderInfo.handRPoint, self->s.number, MASK_SOLID );
  6023. if ( !trace.startsolid && trace.fraction >= 1.0f )
  6024. {//our hand isn't through a wall
  6025. WP_SaberCatch( self, saberent, qtrue );
  6026. //NPC_SetAnim( self, SETANIM_TORSO, TORSO_HANDRETRACT1, SETANIM_FLAG_OVERRIDE );
  6027. }
  6028. return;
  6029. }
  6030. }
  6031. if ( saberent->s.pos.trType != TR_STATIONARY )
  6032. {//saber is in flight, lerp it
  6033. WP_RunSaber( self, saberent );
  6034. }
  6035. else
  6036. {//it fell on the ground
  6037. if ( self->health <= 0 && level.time > saberent->s.time + 5000 )
  6038. {//make us free ourselves after a time
  6039. G_FreeEntity( saberent );
  6040. self->client->ps.saberEntityNum = ENTITYNUM_NONE;
  6041. return;
  6042. }
  6043. if ( (!self->s.number && level.time - saberent->aimDebounceTime > 15000)
  6044. || (self->s.number && level.time - saberent->aimDebounceTime > 5000) )
  6045. {//(only for player) been missing for 15 seconds, automagicially return
  6046. WP_SaberCatch( self, saberent, qfalse );
  6047. return;
  6048. }
  6049. }
  6050. }
  6051. //are we still trying to use the saber?
  6052. if ( self->client->ps.weapon != WP_SABER )
  6053. {//switched away
  6054. if ( !self->client->ps.saberInFlight )
  6055. {//wasn't throwing saber
  6056. return;
  6057. }
  6058. else if ( saberent->s.pos.trType == TR_LINEAR )
  6059. {//switched away while controlling it, just drop the saber
  6060. WP_SaberDrop( self, saberent );
  6061. return;
  6062. }
  6063. else
  6064. {//it's on the ground, see if it's inside us (touching)
  6065. if ( G_PointInBounds( saberent->currentOrigin, self->absmin, self->absmax ) )
  6066. {//it's in us, pick it up automatically
  6067. WP_SaberPull( self, saberent );
  6068. }
  6069. }
  6070. }
  6071. else if ( saberent->s.pos.trType != TR_LINEAR )
  6072. {//weapon is saber and not flying
  6073. if ( self->client->ps.saberInFlight )
  6074. {//we dropped it
  6075. if ( ucmd->buttons & BUTTON_ATTACK )//|| self->client->ps.weaponstate == WEAPON_RAISING )//ucmd->buttons & BUTTON_ALT_ATTACK ||
  6076. {//we actively want to pick it up or we just switched to it, so pull it back
  6077. gi.trace( &tr, saberent->currentOrigin, saberent->mins, saberent->maxs, self->client->renderInfo.handRPoint, self->s.number, MASK_SOLID );
  6078. if ( tr.allsolid || tr.startsolid || tr.fraction < 1.0f )
  6079. {//can't pick it up yet, no LOS
  6080. return;
  6081. }
  6082. //clear LOS, pick it up
  6083. WP_SaberPull( self, saberent );
  6084. }
  6085. else
  6086. {//see if it's inside us (touching)
  6087. if ( G_PointInBounds( saberent->currentOrigin, self->absmin, self->absmax ) )
  6088. {//it's in us, pick it up automatically
  6089. WP_SaberPull( self, saberent );
  6090. }
  6091. }
  6092. }
  6093. }
  6094. else if ( self->health <= 0 && self->client->ps.saberInFlight )
  6095. {//we died, drop it
  6096. WP_SaberDrop( self, saberent );
  6097. return;
  6098. }
  6099. else if ( !self->client->ps.saber[0].Active() && self->client->ps.saberEntityState != SES_RETURNING )
  6100. {//we turned it off, drop it
  6101. WP_SaberDrop( self, saberent );
  6102. return;
  6103. }
  6104. //TODO: if deactivate saber in flight, should it drop?
  6105. if ( saberent->s.pos.trType != TR_LINEAR )
  6106. {//don't home
  6107. return;
  6108. }
  6109. float saberDist = VectorLength( saberDiff );
  6110. if ( self->client->ps.saberEntityState == SES_LEAVING )
  6111. {//saber still flying forward
  6112. if ( self->client->ps.forcePowerLevel[FP_SABERTHROW] > FORCE_LEVEL_2 )
  6113. {//still holding it out
  6114. if ( !(ucmd->buttons&BUTTON_ALT_ATTACK) && self->client->ps.forcePowerDebounce[FP_SABERTHROW] < level.time )
  6115. {//done throwing, return to me
  6116. if ( self->client->ps.saber[0].Active() )
  6117. {//still on
  6118. WP_SaberReturn( self, saberent );
  6119. }
  6120. }
  6121. else if ( level.time - self->client->ps.saberThrowTime >= 100 )
  6122. {
  6123. if ( WP_ForcePowerAvailable( self, FP_SABERTHROW, 1 ) )
  6124. {
  6125. WP_ForcePowerDrain( self, FP_SABERTHROW, 1 );
  6126. self->client->ps.saberThrowTime = level.time;
  6127. }
  6128. else
  6129. {//out of force power, return to me
  6130. WP_SaberReturn( self, saberent );
  6131. }
  6132. }
  6133. }
  6134. else
  6135. {
  6136. if ( !(ucmd->buttons&BUTTON_ALT_ATTACK) && self->client->ps.forcePowerDebounce[FP_SABERTHROW] < level.time )
  6137. {//not holding button and has been out at least 1 second, return to me
  6138. if ( self->client->ps.saber[0].Active() )
  6139. {//still on
  6140. WP_SaberReturn( self, saberent );
  6141. }
  6142. }
  6143. else if ( level.time - self->client->ps.saberThrowTime > 3000
  6144. || (self->client->ps.forcePowerLevel[FP_SABERTHROW]==FORCE_LEVEL_1&&saberDist>=self->client->ps.saberEntityDist) )
  6145. {//been out too long, or saber throw 1 went too far, return to me
  6146. if ( self->client->ps.saber[0].Active() )
  6147. {//still on
  6148. WP_SaberReturn( self, saberent );
  6149. }
  6150. }
  6151. }
  6152. }
  6153. if ( self->client->ps.saberEntityState == SES_RETURNING )
  6154. {
  6155. if ( self->client->ps.saberEntityDist > 0 )
  6156. {
  6157. self->client->ps.saberEntityDist -= 25;
  6158. }
  6159. if ( self->client->ps.saberEntityDist < 0 )
  6160. {
  6161. self->client->ps.saberEntityDist = 0;
  6162. }
  6163. else if ( saberDist < self->client->ps.saberEntityDist )
  6164. {//if it's coming back to me, never push it away
  6165. self->client->ps.saberEntityDist = saberDist;
  6166. }
  6167. }
  6168. }
  6169. //SABER BLOCKING============================================================================
  6170. //SABER BLOCKING============================================================================
  6171. //SABER BLOCKING============================================================================
  6172. //SABER BLOCKING============================================================================
  6173. //SABER BLOCKING============================================================================
  6174. int WP_MissileBlockForBlock( int saberBlock )
  6175. {
  6176. switch( saberBlock )
  6177. {
  6178. case BLOCKED_UPPER_RIGHT:
  6179. return BLOCKED_UPPER_RIGHT_PROJ;
  6180. break;
  6181. case BLOCKED_UPPER_LEFT:
  6182. return BLOCKED_UPPER_LEFT_PROJ;
  6183. break;
  6184. case BLOCKED_LOWER_RIGHT:
  6185. return BLOCKED_LOWER_RIGHT_PROJ;
  6186. break;
  6187. case BLOCKED_LOWER_LEFT:
  6188. return BLOCKED_LOWER_LEFT_PROJ;
  6189. break;
  6190. case BLOCKED_TOP:
  6191. return BLOCKED_TOP_PROJ;
  6192. break;
  6193. }
  6194. return saberBlock;
  6195. }
  6196. void WP_SaberBlockNonRandom( gentity_t *self, vec3_t hitloc, qboolean missileBlock )
  6197. {
  6198. vec3_t diff, fwdangles={0,0,0}, right;
  6199. float rightdot;
  6200. float zdiff;
  6201. if ( self->client->ps.weaponstate == WEAPON_DROPPING ||
  6202. self->client->ps.weaponstate == WEAPON_RAISING )
  6203. {//don't block while changing weapons
  6204. return;
  6205. }
  6206. if ( PM_SuperBreakLoseAnim( self->client->ps.torsoAnim )
  6207. || PM_SuperBreakWinAnim( self->client->ps.torsoAnim ) )
  6208. {
  6209. return;
  6210. }
  6211. //NPCs don't auto-block
  6212. if ( !missileBlock && self->s.number != 0 && self->client->ps.saberBlocked != BLOCKED_NONE )
  6213. {
  6214. return;
  6215. }
  6216. VectorSubtract( hitloc, self->client->renderInfo.eyePoint, diff );
  6217. diff[2] = 0;
  6218. VectorNormalize( diff );
  6219. fwdangles[1] = self->client->ps.viewangles[1];
  6220. // Ultimately we might care if the shot was ahead or behind, but for now, just quadrant is fine.
  6221. AngleVectors( fwdangles, NULL, right, NULL );
  6222. rightdot = DotProduct(right, diff);
  6223. zdiff = hitloc[2] - self->client->renderInfo.eyePoint[2];
  6224. //FIXME: take torsoAngles into account?
  6225. if ( zdiff > -5 )//0 )//40 )
  6226. {
  6227. if ( rightdot > 0.3 )
  6228. {
  6229. self->client->ps.saberBlocked = BLOCKED_UPPER_RIGHT;
  6230. }
  6231. else if ( rightdot < -0.3 )
  6232. {
  6233. self->client->ps.saberBlocked = BLOCKED_UPPER_LEFT;
  6234. }
  6235. else
  6236. {
  6237. self->client->ps.saberBlocked = BLOCKED_TOP;
  6238. }
  6239. }
  6240. else if ( zdiff > -22 )//-20 )//20 )
  6241. {
  6242. if ( zdiff < -10 )//30 )
  6243. {//hmm, pretty low, but not low enough to use the low block, so we need to duck
  6244. //NPC should duck, but NPC should never get here
  6245. }
  6246. if ( rightdot > 0.1 )
  6247. {
  6248. self->client->ps.saberBlocked = BLOCKED_UPPER_RIGHT;
  6249. }
  6250. else if ( rightdot < -0.1 )
  6251. {
  6252. self->client->ps.saberBlocked = BLOCKED_UPPER_LEFT;
  6253. }
  6254. else
  6255. {//FIXME: this looks really weird if the shot is too low!
  6256. self->client->ps.saberBlocked = BLOCKED_TOP;
  6257. }
  6258. }
  6259. else
  6260. {
  6261. if ( rightdot >= 0 )
  6262. {
  6263. self->client->ps.saberBlocked = BLOCKED_LOWER_RIGHT;
  6264. }
  6265. else
  6266. {
  6267. self->client->ps.saberBlocked = BLOCKED_LOWER_LEFT;
  6268. }
  6269. }
  6270. #ifndef FINAL_BUILD
  6271. if ( d_saberCombat->integer )
  6272. {
  6273. if ( !self->s.number )
  6274. {
  6275. gi.Printf( "EyeZ: %4.2f HitZ: %4.2f zdiff: %4.2f rdot: %4.2f\n", self->client->renderInfo.eyePoint[2], hitloc[2], zdiff, rightdot );
  6276. switch ( self->client->ps.saberBlocked )
  6277. {
  6278. case BLOCKED_TOP:
  6279. gi.Printf( "BLOCKED_TOP\n" );
  6280. break;
  6281. case BLOCKED_UPPER_RIGHT:
  6282. gi.Printf( "BLOCKED_UPPER_RIGHT\n" );
  6283. break;
  6284. case BLOCKED_UPPER_LEFT:
  6285. gi.Printf( "BLOCKED_UPPER_LEFT\n" );
  6286. break;
  6287. case BLOCKED_LOWER_RIGHT:
  6288. gi.Printf( "BLOCKED_LOWER_RIGHT\n" );
  6289. break;
  6290. case BLOCKED_LOWER_LEFT:
  6291. gi.Printf( "BLOCKED_LOWER_LEFT\n" );
  6292. break;
  6293. default:
  6294. break;
  6295. }
  6296. }
  6297. }
  6298. #endif
  6299. if ( missileBlock )
  6300. {
  6301. self->client->ps.saberBlocked = WP_MissileBlockForBlock( self->client->ps.saberBlocked );
  6302. }
  6303. if ( self->client->ps.saberBlocked != BLOCKED_NONE )
  6304. {
  6305. int parryReCalcTime = Jedi_ReCalcParryTime( self, EVASION_PARRY );
  6306. if ( self->client->ps.forcePowerDebounce[FP_SABER_DEFENSE] < level.time + parryReCalcTime )
  6307. {
  6308. self->client->ps.forcePowerDebounce[FP_SABER_DEFENSE] = level.time + parryReCalcTime;
  6309. }
  6310. }
  6311. }
  6312. void WP_SaberBlock( gentity_t *saber, vec3_t hitloc, qboolean missileBlock )
  6313. {
  6314. gentity_t *playerent;
  6315. vec3_t diff, fwdangles={0,0,0}, right;
  6316. float rightdot;
  6317. float zdiff;
  6318. if (saber && saber->owner)
  6319. {
  6320. playerent = saber->owner;
  6321. if (!playerent->client)
  6322. {
  6323. return;
  6324. }
  6325. if ( playerent->client->ps.weaponstate == WEAPON_DROPPING ||
  6326. playerent->client->ps.weaponstate == WEAPON_RAISING )
  6327. {//don't block while changing weapons
  6328. return;
  6329. }
  6330. }
  6331. else
  6332. { // Bad entity passed.
  6333. return;
  6334. }
  6335. //temporarily disabling auto-blocking for NPCs...
  6336. if ( !missileBlock && playerent->s.number != 0 && playerent->client->ps.saberBlocked != BLOCKED_NONE )
  6337. {
  6338. return;
  6339. }
  6340. if ( PM_SuperBreakLoseAnim( playerent->client->ps.torsoAnim ) )
  6341. {
  6342. return;
  6343. }
  6344. VectorSubtract(hitloc, playerent->currentOrigin, diff);
  6345. VectorNormalize(diff);
  6346. fwdangles[1] = playerent->client->ps.viewangles[1];
  6347. // Ultimately we might care if the shot was ahead or behind, but for now, just quadrant is fine.
  6348. AngleVectors( fwdangles, NULL, right, NULL );
  6349. rightdot = DotProduct(right, diff) + Q_flrand(-0.2f,0.2f);
  6350. zdiff = hitloc[2] - playerent->currentOrigin[2] + Q_irand(-8,8);
  6351. // Figure out what quadrant the block was in.
  6352. if (zdiff > 24)
  6353. { // Attack from above
  6354. if (Q_irand(0,1))
  6355. {
  6356. playerent->client->ps.saberBlocked = BLOCKED_TOP;
  6357. }
  6358. else
  6359. {
  6360. playerent->client->ps.saberBlocked = BLOCKED_UPPER_LEFT;
  6361. }
  6362. }
  6363. else if (zdiff > 13)
  6364. { // The upper half has three viable blocks...
  6365. if (rightdot > 0.25)
  6366. { // In the right quadrant...
  6367. if (Q_irand(0,1))
  6368. {
  6369. playerent->client->ps.saberBlocked = BLOCKED_UPPER_LEFT;
  6370. }
  6371. else
  6372. {
  6373. playerent->client->ps.saberBlocked = BLOCKED_LOWER_LEFT;
  6374. }
  6375. }
  6376. else
  6377. {
  6378. switch(Q_irand(0,3))
  6379. {
  6380. case 0:
  6381. playerent->client->ps.saberBlocked = BLOCKED_UPPER_RIGHT;
  6382. break;
  6383. case 1:
  6384. case 2:
  6385. playerent->client->ps.saberBlocked = BLOCKED_LOWER_RIGHT;
  6386. break;
  6387. case 3:
  6388. playerent->client->ps.saberBlocked = BLOCKED_TOP;
  6389. break;
  6390. }
  6391. }
  6392. }
  6393. else
  6394. { // The lower half is a bit iffy as far as block coverage. Pick one of the "low" ones at random.
  6395. if (Q_irand(0,1))
  6396. {
  6397. playerent->client->ps.saberBlocked = BLOCKED_LOWER_RIGHT;
  6398. }
  6399. else
  6400. {
  6401. playerent->client->ps.saberBlocked = BLOCKED_LOWER_LEFT;
  6402. }
  6403. }
  6404. if ( missileBlock )
  6405. {
  6406. playerent->client->ps.saberBlocked = WP_MissileBlockForBlock( playerent->client->ps.saberBlocked );
  6407. }
  6408. }
  6409. void WP_SaberStartMissileBlockCheck( gentity_t *self, usercmd_t *ucmd )
  6410. {
  6411. float dist;
  6412. gentity_t *ent, *incoming = NULL;
  6413. gentity_t *entityList[MAX_GENTITIES];
  6414. int numListedEntities;
  6415. vec3_t mins, maxs;
  6416. int i, e;
  6417. float closestDist, radius = 256;
  6418. vec3_t forward, dir, missile_dir, fwdangles = {0};
  6419. trace_t trace;
  6420. vec3_t traceTo, entDir;
  6421. qboolean dodgeOnlySabers = qfalse;
  6422. if ( self->NPC && (self->NPC->scriptFlags&SCF_IGNORE_ALERTS) )
  6423. {//don't react to things flying at me...
  6424. return;
  6425. }
  6426. if ( self->health <= 0 )
  6427. {//dead don't try to block (NOTE: actual deflection happens in missile code)
  6428. return;
  6429. }
  6430. if ( PM_InKnockDown( &self->client->ps ) )
  6431. {//can't block when knocked down
  6432. return;
  6433. }
  6434. if ( PM_SuperBreakLoseAnim( self->client->ps.torsoAnim )
  6435. || PM_SuperBreakWinAnim( self->client->ps.torsoAnim ) )
  6436. {//can't block while in break anim
  6437. return;
  6438. }
  6439. if ( Rosh_BeingHealed( self ) )
  6440. {
  6441. return;
  6442. }
  6443. if ( self->client->NPC_class == CLASS_ROCKETTROOPER )
  6444. {//rockettrooper
  6445. if ( self->client->ps.groundEntityNum != ENTITYNUM_NONE )
  6446. {//must be in air
  6447. return;
  6448. }
  6449. if ( Q_irand( 0, 4-(g_spskill->integer*2) ) )
  6450. {//easier level guys do this less
  6451. return;
  6452. }
  6453. if ( Q_irand( 0, 3 ) )
  6454. {//base level: 25% chance of looking for something to dodge
  6455. if ( Q_irand( 0, 1 ) )
  6456. {//dodge sabers twice as frequently as other projectiles
  6457. dodgeOnlySabers = qtrue;
  6458. }
  6459. else
  6460. {
  6461. return;
  6462. }
  6463. }
  6464. }
  6465. if ( self->client->NPC_class == CLASS_BOBAFETT )
  6466. {//Boba doesn't dodge quite as much
  6467. if ( Q_irand( 0, 2-g_spskill->integer) )
  6468. {//easier level guys do this less
  6469. return;
  6470. }
  6471. }
  6472. if ( self->client->NPC_class != CLASS_BOBAFETT
  6473. && (self->client->NPC_class != CLASS_REBORN || self->s.weapon == WP_SABER)
  6474. && (self->client->NPC_class != CLASS_ROCKETTROOPER||!self->NPC||self->NPC->rank<RANK_LT)//if a rockettrooper, but not an officer, do these normal checks
  6475. )
  6476. {
  6477. if ( g_debugMelee->integer
  6478. && (ucmd->buttons & BUTTON_USE)
  6479. && cg.renderingThirdPerson
  6480. && G_OkayToLean( &self->client->ps, ucmd, qfalse )
  6481. && (self->client->ps.forcePowersActive&(1<<FP_SPEED)) )
  6482. {
  6483. }
  6484. else
  6485. {
  6486. if ( self->client->ps.weapon != WP_SABER )
  6487. {
  6488. return;
  6489. }
  6490. if ( self->client->ps.saberInFlight )
  6491. {
  6492. return;
  6493. }
  6494. if ( self->s.number < MAX_CLIENTS )
  6495. {
  6496. if ( !self->client->ps.SaberLength() )
  6497. {//player doesn't auto-activate
  6498. return;
  6499. }
  6500. if ( !g_saberAutoBlocking->integer && self->client->ps.saberBlockingTime<level.time )
  6501. {
  6502. return;
  6503. }
  6504. }
  6505. if ( !self->client->ps.saber[0].activeBlocking )
  6506. {//can't actively block with this saber type
  6507. return;
  6508. }
  6509. }
  6510. if ( !self->s.number )
  6511. {//don't do this if already attacking!
  6512. if ( ucmd->buttons & BUTTON_ATTACK
  6513. || PM_SaberInAttack( self->client->ps.saberMove )
  6514. || PM_SaberInSpecialAttack( self->client->ps.torsoAnim )
  6515. || PM_SaberInTransitionAny( self->client->ps.saberMove ))
  6516. {
  6517. return;
  6518. }
  6519. }
  6520. if ( self->client->ps.forcePowerLevel[FP_SABER_DEFENSE] < FORCE_LEVEL_1 )
  6521. {//you have not the SKILLZ
  6522. return;
  6523. }
  6524. if ( self->client->ps.forcePowerDebounce[FP_SABER_DEFENSE] > level.time )
  6525. {//can't block while already blocking
  6526. return;
  6527. }
  6528. if ( self->client->ps.forcePowersActive&(1<<FP_LIGHTNING) )
  6529. {//can't block while zapping
  6530. return;
  6531. }
  6532. if ( self->client->ps.forcePowersActive&(1<<FP_DRAIN) )
  6533. {//can't block while draining
  6534. return;
  6535. }
  6536. if ( self->client->ps.forcePowersActive&(1<<FP_PUSH) )
  6537. {//can't block while shoving
  6538. return;
  6539. }
  6540. if ( self->client->ps.forcePowersActive&(1<<FP_GRIP) )
  6541. {//can't block while gripping (FIXME: or should it break the grip? Pain should break the grip, I think...)
  6542. return;
  6543. }
  6544. }
  6545. fwdangles[1] = self->client->ps.viewangles[1];
  6546. AngleVectors( fwdangles, forward, NULL, NULL );
  6547. for ( i = 0 ; i < 3 ; i++ )
  6548. {
  6549. mins[i] = self->currentOrigin[i] - radius;
  6550. maxs[i] = self->currentOrigin[i] + radius;
  6551. }
  6552. numListedEntities = gi.EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  6553. closestDist = radius;
  6554. for ( e = 0 ; e < numListedEntities ; e++ )
  6555. {
  6556. ent = entityList[ e ];
  6557. if (ent == self)
  6558. continue;
  6559. if (ent->owner == self)
  6560. continue;
  6561. if ( !(ent->inuse) )
  6562. continue;
  6563. if ( dodgeOnlySabers )
  6564. {//only care about thrown sabers
  6565. if ( ent->client
  6566. || ent->s.weapon != WP_SABER
  6567. || !ent->classname
  6568. || !ent->classname[0]
  6569. || Q_stricmp( "lightsaber", ent->classname ) )
  6570. {//not a lightsaber, ignore it
  6571. continue;
  6572. }
  6573. }
  6574. if ( ent->s.eType != ET_MISSILE && !(ent->s.eFlags&EF_MISSILE_STICK) )
  6575. {//not a normal projectile
  6576. if ( ent->client || ent->s.weapon != WP_SABER )
  6577. {//FIXME: wake up bad guys?
  6578. continue;
  6579. }
  6580. if ( ent->s.eFlags & EF_NODRAW )
  6581. {
  6582. continue;
  6583. }
  6584. if ( Q_stricmp( "lightsaber", ent->classname ) != 0 )
  6585. {//not a lightsaber
  6586. //FIXME: what about general objects that are small in size- like rocks, etc...
  6587. continue;
  6588. }
  6589. //a lightsaber.. make sure it's on and inFlight
  6590. if ( !ent->owner || !ent->owner->client )
  6591. {
  6592. continue;
  6593. }
  6594. if ( !ent->owner->client->ps.saberInFlight )
  6595. {//not in flight
  6596. continue;
  6597. }
  6598. if ( ent->owner->client->ps.SaberLength() <= 0 )
  6599. {//not on
  6600. continue;
  6601. }
  6602. if ( ent->owner->health <= 0 && g_saberRealisticCombat->integer < 2 )
  6603. {//it's not doing damage, so ignore it
  6604. continue;
  6605. }
  6606. }
  6607. else
  6608. {
  6609. if ( ent->s.pos.trType == TR_STATIONARY && !self->s.number )
  6610. {//nothing you can do with a stationary missile if you're the player
  6611. continue;
  6612. }
  6613. }
  6614. float dot1, dot2;
  6615. //see if they're in front of me
  6616. VectorSubtract( ent->currentOrigin, self->currentOrigin, dir );
  6617. dist = VectorNormalize( dir );
  6618. //FIXME: handle detpacks, proximity mines and tripmines
  6619. if ( ent->s.weapon == WP_THERMAL )
  6620. {//thermal detonator!
  6621. if ( self->NPC && dist < ent->splashRadius )
  6622. {
  6623. if ( dist < ent->splashRadius &&
  6624. ent->nextthink < level.time + 600 &&
  6625. ent->count &&
  6626. self->client->ps.groundEntityNum != ENTITYNUM_NONE &&
  6627. (ent->s.pos.trType == TR_STATIONARY||
  6628. ent->s.pos.trType == TR_INTERPOLATE||
  6629. (dot1 = DotProduct( dir, forward )) < SABER_REFLECT_MISSILE_CONE||
  6630. !WP_ForcePowerUsable( self, FP_PUSH, 0 )) )
  6631. {//TD is close enough to hurt me, I'm on the ground and the thing is at rest or behind me and about to blow up, or I don't have force-push so force-jump!
  6632. //FIXME: sometimes this might make me just jump into it...?
  6633. self->client->ps.forceJumpCharge = 480;
  6634. }
  6635. else if ( self->client->NPC_class != CLASS_BOBAFETT
  6636. && (self->client->NPC_class != CLASS_REBORN || self->s.weapon == WP_SABER)
  6637. && self->client->NPC_class != CLASS_ROCKETTROOPER )
  6638. {//FIXME: check forcePushRadius[NPC->client->ps.forcePowerLevel[FP_PUSH]]
  6639. if ( !ent->owner || !OnSameTeam( self, ent->owner ) )
  6640. {
  6641. ForceThrow( self, qfalse );
  6642. }
  6643. }
  6644. }
  6645. continue;
  6646. }
  6647. else if ( ent->splashDamage && ent->splashRadius )
  6648. {//exploding missile
  6649. //FIXME: handle tripmines and detpacks somehow...
  6650. // maybe do a force-gesture that makes them explode?
  6651. // But what if we're within it's splashradius?
  6652. if ( !self->s.number )
  6653. {//players don't auto-handle these at all
  6654. continue;
  6655. }
  6656. else
  6657. {
  6658. if ( self->client->NPC_class == CLASS_BOBAFETT
  6659. || self->client->NPC_class == CLASS_ROCKETTROOPER )
  6660. {
  6661. /*
  6662. if ( ent->s.pos.trType == TR_STATIONARY && (ent->s.eFlags&EF_MISSILE_STICK) )
  6663. {//sorry, you're scrooged here
  6664. //FIXME: maybe jump or go up if on ground?
  6665. continue;
  6666. }
  6667. //else it's a rocket, try to evade it
  6668. */
  6669. //HMM... let's see what happens if these guys try to avoid tripmines and detpacks, too...?
  6670. }
  6671. else
  6672. {//normal Jedi
  6673. if ( ent->s.pos.trType == TR_STATIONARY && (ent->s.eFlags&EF_MISSILE_STICK)
  6674. && (self->client->NPC_class != CLASS_REBORN || self->s.weapon == WP_SABER) )
  6675. {//a placed explosive like a tripmine or detpack
  6676. if ( InFOV( ent->currentOrigin, self->client->renderInfo.eyePoint, self->client->ps.viewangles, 90, 90 ) )
  6677. {//in front of me
  6678. if ( G_ClearLOS( self, ent ) )
  6679. {//can see it
  6680. vec3_t throwDir;
  6681. //make the gesture
  6682. ForceThrow( self, qfalse );
  6683. //take it off the wall and toss it
  6684. ent->s.pos.trType = TR_GRAVITY;
  6685. ent->s.eType = ET_MISSILE;
  6686. ent->s.eFlags &= ~EF_MISSILE_STICK;
  6687. ent->s.eFlags |= EF_BOUNCE_HALF;
  6688. AngleVectors( ent->currentAngles, throwDir, NULL, NULL );
  6689. VectorMA( ent->currentOrigin, ent->maxs[0]+4, throwDir, ent->currentOrigin );
  6690. VectorCopy( ent->currentOrigin, ent->s.pos.trBase );
  6691. VectorScale( throwDir, 300, ent->s.pos.trDelta );
  6692. ent->s.pos.trDelta[2] += 150;
  6693. VectorMA( ent->s.pos.trDelta, 800, dir, ent->s.pos.trDelta );
  6694. ent->s.pos.trTime = level.time; // move a bit on the very first frame
  6695. VectorCopy( ent->currentOrigin, ent->s.pos.trBase );
  6696. ent->owner = self;
  6697. // make it explode, but with less damage
  6698. ent->splashDamage /= 3;
  6699. ent->splashRadius /= 3;
  6700. ent->e_ThinkFunc = thinkF_WP_Explode;
  6701. ent->nextthink = level.time + Q_irand( 500, 3000 );
  6702. }
  6703. }
  6704. }
  6705. else if ( dist < ent->splashRadius
  6706. && self->client->ps.groundEntityNum != ENTITYNUM_NONE
  6707. && ( DotProduct( dir, forward ) < SABER_REFLECT_MISSILE_CONE
  6708. || !WP_ForcePowerUsable( self, FP_PUSH, 0 ) ) )
  6709. {//NPCs try to evade it
  6710. self->client->ps.forceJumpCharge = 480;
  6711. }
  6712. else if ( (self->client->NPC_class != CLASS_REBORN || self->s.weapon == WP_SABER) )
  6713. {//else, try to force-throw it away
  6714. if ( !ent->owner || !OnSameTeam( self, ent->owner ) )
  6715. {
  6716. //FIXME: check forcePushRadius[NPC->client->ps.forcePowerLevel[FP_PUSH]]
  6717. ForceThrow( self, qfalse );
  6718. }
  6719. }
  6720. //otherwise, can't block it, so we're screwed
  6721. continue;
  6722. }
  6723. }
  6724. }
  6725. if ( ent->s.weapon != WP_SABER )
  6726. {//only block shots coming from behind
  6727. if ( (dot1 = DotProduct( dir, forward )) < SABER_REFLECT_MISSILE_CONE )
  6728. continue;
  6729. }
  6730. else if ( !self->s.number )
  6731. {//player never auto-blocks thrown sabers
  6732. continue;
  6733. }//NPCs always try to block sabers coming from behind!
  6734. //see if they're heading towards me
  6735. VectorCopy( ent->s.pos.trDelta, missile_dir );
  6736. VectorNormalize( missile_dir );
  6737. if ( (dot2 = DotProduct( dir, missile_dir )) > 0 )
  6738. continue;
  6739. //FIXME: must have a clear trace to me, too...
  6740. if ( dist < closestDist )
  6741. {
  6742. VectorCopy( self->currentOrigin, traceTo );
  6743. traceTo[2] = self->absmax[2] - 4;
  6744. gi.trace( &trace, ent->currentOrigin, ent->mins, ent->maxs, traceTo, ent->s.number, ent->clipmask );
  6745. if ( trace.allsolid || trace.startsolid || (trace.fraction < 1.0f && trace.entityNum != self->s.number && trace.entityNum != self->client->ps.saberEntityNum) )
  6746. {//okay, try one more check
  6747. VectorNormalize2( ent->s.pos.trDelta, entDir );
  6748. VectorMA( ent->currentOrigin, radius, entDir, traceTo );
  6749. gi.trace( &trace, ent->currentOrigin, ent->mins, ent->maxs, traceTo, ent->s.number, ent->clipmask );
  6750. if ( trace.allsolid || trace.startsolid || (trace.fraction < 1.0f && trace.entityNum != self->s.number && trace.entityNum != self->client->ps.saberEntityNum) )
  6751. {//can't hit me, ignore it
  6752. continue;
  6753. }
  6754. }
  6755. if ( self->s.number != 0 )
  6756. {//An NPC
  6757. if ( self->NPC && !self->enemy && ent->owner )
  6758. {
  6759. if ( ent->owner->health >= 0 && (!ent->owner->client || ent->owner->client->playerTeam != self->client->playerTeam) )
  6760. {
  6761. G_SetEnemy( self, ent->owner );
  6762. }
  6763. }
  6764. }
  6765. //FIXME: if NPC, predict the intersection between my current velocity/path and the missile's, see if it intersects my bounding box (+/-saberLength?), don't try to deflect unless it does?
  6766. closestDist = dist;
  6767. incoming = ent;
  6768. }
  6769. }
  6770. if ( incoming )
  6771. {
  6772. if ( self->NPC && !G_ControlledByPlayer( self ) )
  6773. {
  6774. if ( Jedi_WaitingAmbush( self ) )
  6775. {
  6776. Jedi_Ambush( self );
  6777. }
  6778. if ( ( self->client->NPC_class == CLASS_BOBAFETT || self->client->NPC_class == CLASS_ROCKETTROOPER )
  6779. && self->client->moveType == MT_FLYSWIM
  6780. && incoming->methodOfDeath != MOD_ROCKET_ALT )
  6781. {//a hovering Boba Fett, not a tracking rocket
  6782. if ( !Q_irand( 0, 1 ) )
  6783. {//strafe
  6784. self->NPC->standTime = 0;
  6785. self->client->ps.forcePowerDebounce[FP_SABER_DEFENSE] = level.time + Q_irand( 1000, 2000 );
  6786. }
  6787. if ( !Q_irand( 0, 1 ) )
  6788. {//go up/down
  6789. TIMER_Set( self, "heightChange", Q_irand( 1000, 3000 ) );
  6790. self->client->ps.forcePowerDebounce[FP_SABER_DEFENSE] = level.time + Q_irand( 1000, 2000 );
  6791. }
  6792. }
  6793. else if ( self->client->NPC_class != CLASS_ROCKETTROOPER
  6794. && Jedi_SaberBlockGo( self, &self->NPC->last_ucmd, NULL, NULL, incoming ) != EVASION_NONE )
  6795. {//make sure to turn on your saber if it's not on
  6796. if ( self->client->NPC_class != CLASS_BOBAFETT
  6797. && (self->client->NPC_class != CLASS_REBORN || self->s.weapon == WP_SABER) )
  6798. {
  6799. self->client->ps.SaberActivate();
  6800. }
  6801. }
  6802. }
  6803. else//player
  6804. {
  6805. if ( !(ucmd->buttons & BUTTON_USE) )//self->s.weapon == WP_SABER && self->client->ps.SaberActive() )
  6806. {
  6807. WP_SaberBlockNonRandom( self, incoming->currentOrigin, qtrue );
  6808. }
  6809. else
  6810. {
  6811. vec3_t diff, start, end;
  6812. float dist;
  6813. VectorSubtract( incoming->currentOrigin, self->currentOrigin, diff );
  6814. dist = VectorLength( diff );
  6815. VectorNormalize2( incoming->s.pos.trDelta, entDir );
  6816. VectorMA( incoming->currentOrigin, dist, entDir, start );
  6817. VectorCopy( self->currentOrigin, end );
  6818. end[2] += self->maxs[2]*0.75f;
  6819. gi.trace( &trace, start, incoming->mins, incoming->maxs, end, incoming->s.number, MASK_SHOT, G2_COLLIDE, 10 );
  6820. Jedi_DodgeEvasion( self, incoming->owner, &trace, HL_NONE );
  6821. }
  6822. if ( incoming->owner && incoming->owner->client && (!self->enemy || self->enemy->s.weapon != WP_SABER) )//keep enemy jedi over shooters
  6823. {
  6824. self->enemy = incoming->owner;
  6825. NPC_SetLookTarget( self, incoming->owner->s.number, level.time+1000 );
  6826. }
  6827. }
  6828. }
  6829. }
  6830. //GENERAL SABER============================================================================
  6831. //GENERAL SABER============================================================================
  6832. //GENERAL SABER============================================================================
  6833. //GENERAL SABER============================================================================
  6834. //GENERAL SABER============================================================================
  6835. void WP_SetSaberMove(gentity_t *self, short blocked)
  6836. {
  6837. self->client->ps.saberBlocked = blocked;
  6838. }
  6839. extern void CG_CubeOutline( vec3_t mins, vec3_t maxs, int time, unsigned int color, float alpha );
  6840. void WP_SaberUpdate( gentity_t *self, usercmd_t *ucmd )
  6841. {
  6842. //float swap;
  6843. float minsize = 16;
  6844. if(0)// if ( self->s.number != 0 )
  6845. {//for now only the player can do this // not anymore
  6846. return;
  6847. }
  6848. if ( !self->client )
  6849. {
  6850. return;
  6851. }
  6852. if ( self->client->ps.saberEntityNum < 0 || self->client->ps.saberEntityNum >= ENTITYNUM_WORLD )
  6853. {//never got one
  6854. return;
  6855. }
  6856. // Check if we are throwing it, launch it if needed, update position if needed.
  6857. WP_SaberThrow(self, ucmd);
  6858. //vec3_t saberloc;
  6859. //vec3_t sabermins={-8,-8,-8}, sabermaxs={8,8,8};
  6860. gentity_t *saberent;
  6861. if (self->client->ps.saberEntityNum <= 0)
  6862. {//WTF?!! We lost it?
  6863. return;
  6864. }
  6865. saberent = &g_entities[self->client->ps.saberEntityNum];
  6866. //FIXME: Based on difficulty level/jedi saber combat skill, make this bounding box fatter/smaller
  6867. if ( self->client->ps.saberBlocked != BLOCKED_NONE )
  6868. {//we're blocking, increase min size
  6869. minsize = 32;
  6870. }
  6871. if ( G_InCinematicSaberAnim( self ) )
  6872. {//fake some blocking
  6873. self->client->ps.saberBlocking = BLK_TIGHT;
  6874. if ( self->client->ps.saber[0].Active() )
  6875. {
  6876. self->client->ps.saber[0].ActivateTrail( 150 );
  6877. }
  6878. if ( self->client->ps.saber[1].Active() )
  6879. {
  6880. self->client->ps.saber[1].ActivateTrail( 150 );
  6881. }
  6882. }
  6883. //is our saber in flight?
  6884. if ( !self->client->ps.saberInFlight )
  6885. { // It isn't, which means we can update its position as we will.
  6886. Vehicle_t *pVeh = G_IsRidingVehicle( self );
  6887. if ( !self->client->ps.SaberActive()
  6888. || PM_InKnockDown( &self->client->ps )
  6889. || PM_SuperBreakLoseAnim( self->client->ps.torsoAnim )
  6890. || (pVeh && pVeh->m_pVehicleInfo && pVeh->m_pVehicleInfo->type != VH_ANIMAL && pVeh->m_pVehicleInfo->type != VH_FLIER) )//riding a vehicle that you cannot block shots on
  6891. {//can't block if saber isn't on
  6892. VectorClear(saberent->mins);
  6893. VectorClear(saberent->maxs);
  6894. G_SetOrigin(saberent, self->currentOrigin);
  6895. }
  6896. else if ( self->client->ps.saberBlocking == BLK_TIGHT || self->client->ps.saberBlocking == BLK_WIDE )
  6897. {//FIXME: keep bbox in front of player, even when wide?
  6898. vec3_t saberOrg;
  6899. if ( ( (self->s.number&&!Jedi_SaberBusy(self)&&!g_saberRealisticCombat->integer) || (self->s.number == 0 && self->client->ps.saberBlocking == BLK_WIDE && (g_saberAutoBlocking->integer||self->client->ps.saberBlockingTime>level.time)) )
  6900. && self->client->ps.weaponTime <= 0
  6901. && !G_InCinematicSaberAnim( self ) )
  6902. {//full-size blocking for non-attacking player with g_saberAutoBlocking on
  6903. vec3_t saberang={0,0,0}, fwd, sabermins={-8,-8,-8}, sabermaxs={8,8,8};
  6904. saberang[YAW] = self->client->ps.viewangles[YAW];
  6905. AngleVectors( saberang, fwd, NULL, NULL );
  6906. VectorMA( self->currentOrigin, 12, fwd, saberOrg );
  6907. VectorAdd( self->mins, sabermins, saberent->mins );
  6908. VectorAdd( self->maxs, sabermaxs, saberent->maxs );
  6909. saberent->contents = CONTENTS_LIGHTSABER;
  6910. G_SetOrigin( saberent, saberOrg );
  6911. }
  6912. else
  6913. {
  6914. vec3_t saberBase, saberTip;
  6915. int numSabers = 1;
  6916. if ( self->client->ps.dualSabers )
  6917. {
  6918. numSabers = 2;
  6919. }
  6920. for ( int saberNum = 0; saberNum < numSabers; saberNum++ )
  6921. {
  6922. for ( int bladeNum = 0; bladeNum < self->client->ps.saber[saberNum].numBlades; bladeNum++ )
  6923. {
  6924. VectorCopy( self->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint, saberBase );
  6925. VectorMA( saberBase, self->client->ps.saber[saberNum].blade[bladeNum].length, self->client->ps.saber[saberNum].blade[bladeNum].muzzleDir, saberTip );
  6926. VectorMA( saberBase, self->client->ps.saber[saberNum].blade[bladeNum].length*0.5, self->client->ps.saber[saberNum].blade[bladeNum].muzzleDir, saberOrg );
  6927. for ( int i = 0; i < 3; i++ )
  6928. {
  6929. /*
  6930. if ( saberTip[i] > self->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint[i] )
  6931. {
  6932. saberent->maxs[i] = saberTip[i] - saberOrg[i] + 8;//self->client->renderInfo.muzzlePoint[i];
  6933. saberent->mins[i] = self->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint[i] - saberOrg[i] - 8;
  6934. }
  6935. else //if ( saberTip[i] < self->client->renderInfo.muzzlePoint[i] )
  6936. {
  6937. saberent->maxs[i] = self->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint[i] - saberOrg[i] + 8;
  6938. saberent->mins[i] = saberTip[i] - saberOrg[i] - 8;//self->client->ps.saber[saberNum].blade[bladeNum].muzzlePoint[i];
  6939. }
  6940. */
  6941. float newSizeTip = (saberTip[i] - saberOrg[i]);
  6942. newSizeTip += (newSizeTip>=0)?8:-8;
  6943. float newSizeBase = (saberBase[i] - saberOrg[i]);
  6944. newSizeBase += (newSizeBase>=0)?8:-8;
  6945. if ( newSizeTip > saberent->maxs[i] )
  6946. {
  6947. saberent->maxs[i] = newSizeTip;
  6948. }
  6949. if ( newSizeBase > saberent->maxs[i] )
  6950. {
  6951. saberent->maxs[i] = newSizeBase;
  6952. }
  6953. if ( newSizeTip < saberent->mins[i] )
  6954. {
  6955. saberent->mins[i] = newSizeTip;
  6956. }
  6957. if ( newSizeBase < saberent->mins[i] )
  6958. {
  6959. saberent->mins[i] = newSizeBase;
  6960. }
  6961. }
  6962. }
  6963. }
  6964. if ( self->client->ps.weaponTime > 0
  6965. || self->s.number
  6966. || g_saberAutoBlocking->integer
  6967. || self->client->ps.saberBlockingTime > level.time )
  6968. {//if attacking or blocking (or an NPC), inflate to a minimum size
  6969. for ( int i = 0; i < 3; i++ )
  6970. {
  6971. if ( saberent->maxs[i] < minsize )
  6972. {
  6973. saberent->maxs[i] = minsize;
  6974. }
  6975. if ( saberent->mins[i] > -minsize )
  6976. {
  6977. saberent->mins[i] = -minsize;
  6978. }
  6979. }
  6980. }
  6981. saberent->contents = CONTENTS_LIGHTSABER;
  6982. G_SetOrigin( saberent, saberOrg );
  6983. }
  6984. }
  6985. /*
  6986. else if (self->client->ps.saberBlocking == BLK_WIDE)
  6987. { // Assuming that we are not swinging, the saber's bounding box should be around the player.
  6988. vec3_t saberang={0,0,0}, fwd;
  6989. saberang[YAW] = self->client->ps.viewangles[YAW];
  6990. AngleVectors( saberang, fwd, NULL, NULL );
  6991. VectorMA(self->currentOrigin, 12, fwd, saberloc);
  6992. VectorAdd(self->mins, sabermins, saberent->mins);
  6993. VectorAdd(self->maxs, sabermaxs, saberent->maxs);
  6994. saberent->contents = CONTENTS_LIGHTSABER;
  6995. G_SetOrigin( saberent, saberloc);
  6996. }
  6997. else if (self->client->ps.saberBlocking == BLK_TIGHT)
  6998. { // If the player is swinging, the bbox is around just the saber
  6999. VectorCopy(self->client->renderInfo.muzzlePoint, sabermins);
  7000. // Put the limits of the bbox around the saber size.
  7001. VectorMA(sabermins, self->client->ps.saberLength, self->client->renderInfo.muzzleDir, sabermaxs);
  7002. // Now make the mins into mins and the maxs into maxs
  7003. if (sabermins[0] > sabermaxs[0])
  7004. {
  7005. swap = sabermins[0];
  7006. sabermins[0] = sabermaxs[0];
  7007. sabermaxs[0] = swap;
  7008. }
  7009. if (sabermins[1] > sabermaxs[1])
  7010. {
  7011. swap = sabermins[1];
  7012. sabermins[1] = sabermaxs[1];
  7013. sabermaxs[1] = swap;
  7014. }
  7015. if (sabermins[2] > sabermaxs[2])
  7016. {
  7017. swap = sabermins[2];
  7018. sabermins[2] = sabermaxs[2];
  7019. sabermaxs[2] = swap;
  7020. }
  7021. // Now the loc is halfway between the (absolute) mins and maxs
  7022. VectorAdd(sabermins, sabermaxs, saberloc);
  7023. VectorScale(saberloc, 0.5, saberloc);
  7024. // Finally, turn the mins and maxs, which are absolute, into relative mins and maxs.
  7025. VectorSubtract(sabermins, saberloc, saberent->mins);
  7026. VectorSubtract(sabermaxs, saberloc, saberent->maxs);
  7027. saberent->contents = CONTENTS_LIGHTSABER;// | CONTENTS_SHOTCLIP;
  7028. G_SetOrigin( saberent, saberloc);
  7029. }
  7030. */
  7031. else
  7032. { // Otherwise there is no blocking possible.
  7033. VectorClear(saberent->mins);
  7034. VectorClear(saberent->maxs);
  7035. G_SetOrigin(saberent, self->currentOrigin);
  7036. }
  7037. saberent->clipmask = MASK_SHOT | CONTENTS_LIGHTSABER;
  7038. gi.linkentity(saberent);
  7039. }
  7040. else
  7041. {
  7042. WP_SaberInFlightReflectCheck( self, ucmd );
  7043. }
  7044. #ifndef FINAL_BUILD
  7045. if ( d_saberCombat->integer > 2 )
  7046. {
  7047. CG_CubeOutline( saberent->absmin, saberent->absmax, 50, WPDEBUG_SaberColor( self->client->ps.saber[0].blade[0].color ), 1 );
  7048. }
  7049. #endif
  7050. }
  7051. #define MAX_RADIUS_ENTS 256 //NOTE: This can cause entities to be lost
  7052. qboolean G_CheckEnemyPresence( gentity_t *ent, int dir, float radius, float tolerance )
  7053. {
  7054. gentity_t *radiusEnts[ MAX_RADIUS_ENTS ];
  7055. vec3_t mins, maxs;
  7056. int numEnts;
  7057. vec3_t checkDir, dir2checkEnt;
  7058. float dist;
  7059. switch( dir )
  7060. {
  7061. case DIR_RIGHT:
  7062. AngleVectors( ent->currentAngles, NULL, checkDir, NULL );
  7063. break;
  7064. case DIR_LEFT:
  7065. AngleVectors( ent->currentAngles, NULL, checkDir, NULL );
  7066. VectorScale( checkDir, -1, checkDir );
  7067. break;
  7068. case DIR_FRONT:
  7069. AngleVectors( ent->currentAngles, checkDir, NULL, NULL );
  7070. break;
  7071. case DIR_BACK:
  7072. AngleVectors( ent->currentAngles, checkDir, NULL, NULL );
  7073. VectorScale( checkDir, -1, checkDir );
  7074. break;
  7075. }
  7076. //Get all ents in range, see if they're living clients and enemies, then check dot to them...
  7077. //Setup the bbox to search in
  7078. for ( int i = 0; i < 3; i++ )
  7079. {
  7080. mins[i] = ent->currentOrigin[i] - radius;
  7081. maxs[i] = ent->currentOrigin[i] + radius;
  7082. }
  7083. //Get a number of entities in a given space
  7084. numEnts = gi.EntitiesInBox( mins, maxs, radiusEnts, MAX_RADIUS_ENTS );
  7085. for ( i = 0; i < numEnts; i++ )
  7086. {
  7087. //Don't consider self
  7088. if ( radiusEnts[i] == ent )
  7089. continue;
  7090. //Must be valid
  7091. if ( G_ValidEnemy( ent, radiusEnts[i] ) == qfalse )
  7092. continue;
  7093. VectorSubtract( radiusEnts[i]->currentOrigin, ent->currentOrigin, dir2checkEnt );
  7094. dist = VectorNormalize( dir2checkEnt );
  7095. if ( dist <= radius
  7096. && DotProduct( dir2checkEnt, checkDir ) >= tolerance )
  7097. {
  7098. //stop on the first one
  7099. return qtrue;
  7100. }
  7101. }
  7102. return qfalse;
  7103. }
  7104. //OTHER JEDI POWERS=========================================================================
  7105. //OTHER JEDI POWERS=========================================================================
  7106. //OTHER JEDI POWERS=========================================================================
  7107. //OTHER JEDI POWERS=========================================================================
  7108. //OTHER JEDI POWERS=========================================================================
  7109. extern gentity_t *TossClientItems( gentity_t *self );
  7110. extern void ChangeWeapon( gentity_t *ent, int newWeapon );
  7111. void WP_DropWeapon( gentity_t *dropper, vec3_t velocity )
  7112. {
  7113. if ( !dropper || !dropper->client )
  7114. {
  7115. return;
  7116. }
  7117. int replaceWeap = WP_NONE;
  7118. int oldWeap = dropper->s.weapon;
  7119. gentity_t *weapon = TossClientItems( dropper );
  7120. if ( oldWeap == WP_THERMAL && dropper->NPC )
  7121. {//Hmm, maybe all NPCs should go into melee? Not too many, though, or they mob you and look silly
  7122. replaceWeap = WP_MELEE;
  7123. }
  7124. if ( dropper->ghoul2.IsValid() )
  7125. {
  7126. if ( dropper->weaponModel[0] > 0 )
  7127. {//NOTE: guess you never drop the left-hand weapon, eh?
  7128. gi.G2API_RemoveGhoul2Model( dropper->ghoul2, dropper->weaponModel[0] );
  7129. dropper->weaponModel[0] = -1;
  7130. }
  7131. }
  7132. //FIXME: does this work on the player?
  7133. dropper->client->ps.stats[STAT_WEAPONS] |= ( 1 << replaceWeap );
  7134. if ( !dropper->s.number )
  7135. {
  7136. if ( oldWeap == WP_THERMAL )
  7137. {
  7138. dropper->client->ps.ammo[weaponData[oldWeap].ammoIndex] -= weaponData[oldWeap].energyPerShot;
  7139. }
  7140. else
  7141. {
  7142. dropper->client->ps.stats[STAT_WEAPONS] &= ~( 1 << oldWeap );
  7143. }
  7144. CG_ChangeWeapon( replaceWeap );
  7145. }
  7146. else
  7147. {
  7148. dropper->client->ps.stats[STAT_WEAPONS] &= ~( 1 << oldWeap );
  7149. }
  7150. ChangeWeapon( dropper, replaceWeap );
  7151. dropper->s.weapon = replaceWeap;
  7152. if ( dropper->NPC )
  7153. {
  7154. dropper->NPC->last_ucmd.weapon = replaceWeap;
  7155. }
  7156. if ( weapon != NULL && velocity && !VectorCompare( velocity, vec3_origin ) )
  7157. {//weapon should have a direction to it's throw
  7158. VectorScale( velocity, 3, weapon->s.pos.trDelta );//NOTE: Presumes it is moving already...?
  7159. if ( weapon->s.pos.trDelta[2] < 150 )
  7160. {//this is presuming you don't want them to drop the weapon down on you...
  7161. weapon->s.pos.trDelta[2] = 150;
  7162. }
  7163. //FIXME: gets stuck inside it's former owner...
  7164. weapon->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  7165. }
  7166. }
  7167. void WP_KnockdownTurret( gentity_t *self, gentity_t *pas )
  7168. {
  7169. //knock it over
  7170. VectorCopy( pas->currentOrigin, pas->s.pos.trBase );
  7171. pas->s.pos.trType = TR_LINEAR_STOP;
  7172. pas->s.pos.trDuration = 250;
  7173. pas->s.pos.trTime = level.time;
  7174. pas->s.pos.trDelta[2] = ( 12.0f / ( pas->s.pos.trDuration * 0.001f ) );
  7175. VectorCopy( pas->currentAngles, pas->s.apos.trBase );
  7176. pas->s.apos.trType = TR_LINEAR_STOP;
  7177. pas->s.apos.trDuration = 250;
  7178. pas->s.apos.trTime = level.time;
  7179. //FIXME: pick pitch/roll that always tilts it directly away from pusher
  7180. pas->s.apos.trDelta[PITCH] = ( 100.0f / ( pas->s.apos.trDuration * 0.001f ) );
  7181. //kill it
  7182. pas->count = 0;
  7183. pas->nextthink = -1;
  7184. G_Sound( pas, G_SoundIndex( "sound/chars/turret/shutdown.wav" ));
  7185. //push effect?
  7186. pas->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  7187. }
  7188. void WP_ForceThrowHazardTrooper( gentity_t *self, gentity_t *trooper, qboolean pull )
  7189. {
  7190. if ( !self || !self->client )
  7191. {
  7192. return;
  7193. }
  7194. if ( !trooper || !trooper->client )
  7195. {
  7196. return;
  7197. }
  7198. //all levels: see effect on them, they notice us
  7199. trooper->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  7200. if ( (pull&&self->client->ps.forcePowerLevel[FP_PULL]>FORCE_LEVEL_1)
  7201. || (!pull&&self->client->ps.forcePowerLevel[FP_PUSH]>FORCE_LEVEL_1) )
  7202. {//level 2: they stop for a couple seconds and make a sound
  7203. trooper->painDebounceTime = level.time + Q_irand( 1500, 2500 );
  7204. G_AddVoiceEvent( trooper, Q_irand(EV_PUSHED1, EV_PUSHED3), Q_irand( 1000, 3000 ) );
  7205. GEntity_PainFunc( trooper, self, self, trooper->currentOrigin, 0, MOD_MELEE );
  7206. if ( (pull&&self->client->ps.forcePowerLevel[FP_PULL]>FORCE_LEVEL_2)
  7207. || (!pull&&self->client->ps.forcePowerLevel[FP_PUSH]>FORCE_LEVEL_2) )
  7208. {//level 3: they actually play a pushed anim and stumble a bit
  7209. vec3_t hazAngles = {0,trooper->currentAngles[YAW],0};
  7210. int anim = -1;
  7211. if ( InFront( self->currentOrigin, trooper->currentOrigin, hazAngles ) )
  7212. {//I'm on front of him
  7213. if ( pull )
  7214. {
  7215. anim = BOTH_PAIN4;
  7216. }
  7217. else
  7218. {
  7219. anim = BOTH_PAIN1;
  7220. }
  7221. }
  7222. else
  7223. {//I'm behind him
  7224. if ( pull )
  7225. {
  7226. anim = BOTH_PAIN1;
  7227. }
  7228. else
  7229. {
  7230. anim = BOTH_PAIN4;
  7231. }
  7232. }
  7233. if ( anim != -1 )
  7234. {
  7235. if ( anim == BOTH_PAIN1 )
  7236. {//make them take a couple steps back
  7237. AngleVectors( hazAngles, trooper->client->ps.velocity, NULL, NULL );
  7238. VectorScale( trooper->client->ps.velocity, -40.0f, trooper->client->ps.velocity );
  7239. trooper->client->ps.pm_flags |= PMF_TIME_NOFRICTION;
  7240. }
  7241. else if ( anim == BOTH_PAIN4 )
  7242. {//make them stumble forward
  7243. AngleVectors( hazAngles, trooper->client->ps.velocity, NULL, NULL );
  7244. VectorScale( trooper->client->ps.velocity, 80.0f, trooper->client->ps.velocity );
  7245. trooper->client->ps.pm_flags |= PMF_TIME_NOFRICTION;
  7246. }
  7247. NPC_SetAnim( trooper, SETANIM_BOTH, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  7248. trooper->painDebounceTime += trooper->client->ps.torsoAnimTimer;
  7249. trooper->client->ps.pm_time = trooper->client->ps.torsoAnimTimer;
  7250. }
  7251. }
  7252. if ( trooper->NPC )
  7253. {
  7254. if ( trooper->NPC->shotTime < trooper->painDebounceTime )
  7255. {
  7256. trooper->NPC->shotTime = trooper->painDebounceTime;
  7257. }
  7258. }
  7259. trooper->client->ps.weaponTime = trooper->painDebounceTime-level.time;
  7260. }
  7261. else
  7262. {//level 1: no pain reaction, but they should still notice
  7263. if ( trooper->enemy == NULL//not mad at anyone
  7264. && trooper->client->playerTeam != self->client->playerTeam//not on our team
  7265. && !(trooper->svFlags&SVF_LOCKEDENEMY)//not locked on an enemy
  7266. && !(trooper->svFlags&SVF_IGNORE_ENEMIES)//not ignoring enemie
  7267. && !(self->flags&FL_NOTARGET) )//I'm not in notarget
  7268. {//not already mad at them and can get mad at them, do so
  7269. G_SetEnemy( trooper, self );
  7270. }
  7271. }
  7272. }
  7273. void WP_ResistForcePush( gentity_t *self, gentity_t *pusher, qboolean noPenalty )
  7274. {
  7275. int parts;
  7276. qboolean runningResist = qfalse;
  7277. if ( !self || self->health <= 0 || !self->client || !pusher || !pusher->client )
  7278. {
  7279. return;
  7280. }
  7281. if ( (!self->s.number
  7282. ||( self->NPC && (self->NPC->aiFlags&NPCAI_BOSS_CHARACTER) )
  7283. ||( self->client && self->client->NPC_class == CLASS_SHADOWTROOPER )
  7284. /*
  7285. || self->client->NPC_class == CLASS_DESANN
  7286. || !Q_stricmp("Yoda",self->NPC_type)
  7287. || self->client->NPC_class == CLASS_LUKE*/
  7288. )
  7289. && (VectorLengthSquared( self->client->ps.velocity ) > 10000 || self->client->ps.forcePowerLevel[FP_PUSH] >= FORCE_LEVEL_3 || self->client->ps.forcePowerLevel[FP_PULL] >= FORCE_LEVEL_3 ) )
  7290. {
  7291. runningResist = qtrue;
  7292. }
  7293. if ( !runningResist
  7294. && self->client->ps.groundEntityNum != ENTITYNUM_NONE
  7295. && !PM_SpinningSaberAnim( self->client->ps.legsAnim )
  7296. && !PM_FlippingAnim( self->client->ps.legsAnim )
  7297. && !PM_RollingAnim( self->client->ps.legsAnim )
  7298. && !PM_InKnockDown( &self->client->ps )
  7299. && !PM_CrouchAnim( self->client->ps.legsAnim ))
  7300. {//if on a surface and not in a spin or flip, play full body resist
  7301. parts = SETANIM_BOTH;
  7302. }
  7303. else
  7304. {//play resist just in torso
  7305. parts = SETANIM_TORSO;
  7306. }
  7307. //FIXME: don't interrupt big anims with this!
  7308. NPC_SetAnim( self, parts, BOTH_RESISTPUSH, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  7309. if ( !noPenalty )
  7310. {
  7311. if ( !runningResist )
  7312. {
  7313. VectorClear( self->client->ps.velocity );
  7314. //still stop them from attacking or moving for a bit, though
  7315. //FIXME: maybe push just a little (like, slide)?
  7316. self->client->ps.weaponTime = 1000;
  7317. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  7318. {
  7319. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  7320. }
  7321. self->client->ps.pm_time = self->client->ps.weaponTime;
  7322. self->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  7323. //play the full body push effect on me
  7324. self->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  7325. }
  7326. else
  7327. {
  7328. self->client->ps.weaponTime = 600;
  7329. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  7330. {
  7331. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  7332. }
  7333. }
  7334. }
  7335. //play my force push effect on my hand
  7336. //self->client->ps.powerups[PW_FORCE_PUSH] = level.time + self->client->ps.torsoAnimTimer + 500;
  7337. //reset to 0 in case it's still > 0 from a previous push
  7338. //self->client->pushEffectFadeTime = 0;
  7339. if ( !pusher //???
  7340. || pusher == self->enemy//my enemy tried to push me
  7341. || (pusher->client && pusher->client->playerTeam != self->client->playerTeam) )//someone not on my team tried to push me
  7342. {
  7343. Jedi_PlayBlockedPushSound( self );
  7344. }
  7345. }
  7346. extern qboolean Boba_StopKnockdown( gentity_t *self, gentity_t *pusher, const vec3_t pushDir, qboolean forceKnockdown );
  7347. extern qboolean Jedi_StopKnockdown( gentity_t *self, gentity_t *pusher, const vec3_t pushDir );
  7348. void WP_ForceKnockdown( gentity_t *self, gentity_t *pusher, qboolean pull, qboolean strongKnockdown, qboolean breakSaberLock )
  7349. {
  7350. if ( !self || !self->client || !pusher || !pusher->client )
  7351. {
  7352. return;
  7353. }
  7354. if ( self->client->NPC_class == CLASS_ROCKETTROOPER )
  7355. {
  7356. return;
  7357. }
  7358. else if ( PM_LockedAnim( self->client->ps.legsAnim ) )
  7359. {//stuck doing something else
  7360. return;
  7361. }
  7362. else if ( Rosh_BeingHealed( self ) )
  7363. {
  7364. return;
  7365. }
  7366. //break out of a saberLock?
  7367. if ( self->client->ps.saberLockTime > level.time )
  7368. {
  7369. if ( breakSaberLock
  7370. || (pusher && self->client->ps.saberLockEnemy == pusher->s.number) )
  7371. {
  7372. self->client->ps.saberLockTime = 0;
  7373. self->client->ps.saberLockEnemy = ENTITYNUM_NONE;
  7374. }
  7375. else
  7376. {
  7377. return;
  7378. }
  7379. }
  7380. if ( self->health > 0 )
  7381. {
  7382. if ( !self->s.number )
  7383. {
  7384. NPC_SetPainEvent( self );
  7385. }
  7386. else
  7387. {
  7388. GEntity_PainFunc( self, pusher, pusher, self->currentOrigin, 0, MOD_MELEE );
  7389. }
  7390. vec3_t pushDir;
  7391. if ( pull )
  7392. {
  7393. VectorSubtract( pusher->currentOrigin, self->currentOrigin, pushDir );
  7394. }
  7395. else
  7396. {
  7397. VectorSubtract( self->currentOrigin, pusher->currentOrigin, pushDir );
  7398. }
  7399. //FIXME: sometimes do this for some NPC force-users, too!
  7400. if ( Boba_StopKnockdown( self, pusher, pushDir, qtrue ) )
  7401. {//He can backflip instead of be knocked down
  7402. return;
  7403. }
  7404. else if ( Jedi_StopKnockdown( self, pusher, pushDir ) )
  7405. {//They can backflip instead of be knocked down
  7406. return;
  7407. }
  7408. G_CheckLedgeDive( self, 72, pushDir, qfalse, qfalse );
  7409. if ( !PM_SpinningSaberAnim( self->client->ps.legsAnim )
  7410. && !PM_FlippingAnim( self->client->ps.legsAnim )
  7411. && !PM_RollingAnim( self->client->ps.legsAnim )
  7412. && !PM_InKnockDown( &self->client->ps ) )
  7413. {
  7414. int knockAnim = BOTH_KNOCKDOWN1;//default knockdown
  7415. if ( pusher->client->NPC_class == CLASS_DESANN && self->client->NPC_class != CLASS_LUKE )
  7416. {//desann always knocks down, unless you're Luke
  7417. strongKnockdown = qtrue;
  7418. }
  7419. if ( !self->s.number
  7420. && !strongKnockdown
  7421. && ( (!pull&&(self->client->ps.forcePowerLevel[FP_PUSH]>FORCE_LEVEL_1||!g_spskill->integer)) || (pull&&(self->client->ps.forcePowerLevel[FP_PULL]>FORCE_LEVEL_1||!g_spskill->integer)) ) )
  7422. {//player only knocked down if pushed *hard*
  7423. if ( self->s.weapon == WP_SABER )
  7424. {//temp HACK: these are the only 2 pain anims that look good when holding a saber
  7425. knockAnim = PM_PickAnim( self, BOTH_PAIN2, BOTH_PAIN3 );
  7426. }
  7427. else
  7428. {
  7429. knockAnim = PM_PickAnim( self, BOTH_PAIN1, BOTH_PAIN18 );
  7430. }
  7431. }
  7432. else if ( PM_CrouchAnim( self->client->ps.legsAnim ) )
  7433. {//crouched knockdown
  7434. knockAnim = BOTH_KNOCKDOWN4;
  7435. }
  7436. else
  7437. {//plain old knockdown
  7438. vec3_t pLFwd, pLAngles = {0,self->client->ps.viewangles[YAW],0};
  7439. vec3_t sFwd, sAngles = {0,pusher->client->ps.viewangles[YAW],0};
  7440. AngleVectors( pLAngles, pLFwd, NULL, NULL );
  7441. AngleVectors( sAngles, sFwd, NULL, NULL );
  7442. if ( DotProduct( sFwd, pLFwd ) > 0.2f )
  7443. {//pushing him from behind
  7444. //FIXME: check to see if we're aiming below or above the waist?
  7445. if ( pull )
  7446. {
  7447. knockAnim = BOTH_KNOCKDOWN1;
  7448. }
  7449. else
  7450. {
  7451. knockAnim = BOTH_KNOCKDOWN3;
  7452. }
  7453. }
  7454. else
  7455. {//pushing him from front
  7456. if ( pull )
  7457. {
  7458. knockAnim = BOTH_KNOCKDOWN3;
  7459. }
  7460. else
  7461. {
  7462. knockAnim = BOTH_KNOCKDOWN1;
  7463. }
  7464. }
  7465. }
  7466. if ( knockAnim == BOTH_KNOCKDOWN1 && strongKnockdown )
  7467. {//push *hard*
  7468. knockAnim = BOTH_KNOCKDOWN2;
  7469. }
  7470. NPC_SetAnim( self, SETANIM_BOTH, knockAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  7471. if ( self->s.number >= MAX_CLIENTS )
  7472. {//randomize getup times - but not for boba
  7473. int addTime;
  7474. if ( self->client->NPC_class == CLASS_BOBAFETT )
  7475. {
  7476. addTime = Q_irand( -500, 0 );
  7477. }
  7478. else
  7479. {
  7480. addTime = Q_irand( -300, 300 );
  7481. }
  7482. self->client->ps.legsAnimTimer += addTime;
  7483. self->client->ps.torsoAnimTimer += addTime;
  7484. }
  7485. else
  7486. {//player holds extra long so you have more time to decide to do the quick getup
  7487. if ( PM_KnockDownAnim( self->client->ps.legsAnim ) )
  7488. {
  7489. self->client->ps.legsAnimTimer += PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME;
  7490. self->client->ps.torsoAnimTimer += PLAYER_KNOCKDOWN_HOLD_EXTRA_TIME;
  7491. }
  7492. }
  7493. //
  7494. if ( pusher->NPC && pusher->enemy == self )
  7495. {//pushed pushed down his enemy
  7496. G_AddVoiceEvent( pusher, Q_irand( EV_GLOAT1, EV_GLOAT3 ), 3000 );
  7497. pusher->NPC->blockedSpeechDebounceTime = level.time + 3000;
  7498. }
  7499. }
  7500. }
  7501. self->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  7502. }
  7503. qboolean WP_ForceThrowable( gentity_t *ent, gentity_t *forwardEnt, gentity_t *self, qboolean pull, float cone, float radius, vec3_t forward )
  7504. {
  7505. if (ent == self)
  7506. return qfalse;
  7507. if ( ent->owner == self && ent->s.weapon != WP_THERMAL )//can push your own thermals
  7508. return qfalse;
  7509. if ( !(ent->inuse) )
  7510. return qfalse;
  7511. if ( ent->NPC && ent->NPC->scriptFlags & SCF_NO_FORCE )
  7512. {
  7513. if ( ent->s.weapon == WP_SABER )
  7514. {//Hmm, should jedi do the resist behavior? If this is on, perhaps it's because of a cinematic?
  7515. WP_ResistForcePush( ent, self, qtrue );
  7516. }
  7517. return qfalse;
  7518. }
  7519. if ( (ent->flags&FL_FORCE_PULLABLE_ONLY) && !pull )
  7520. {//simple HACK: cannot force-push ammo rack items (because they may start in solid)
  7521. return qfalse;
  7522. }
  7523. //FIXME: don't push it if I already pushed it a little while ago
  7524. if ( ent->s.eType != ET_MISSILE )
  7525. {
  7526. if ( ent->client )
  7527. {
  7528. if ( ent->client->ps.pullAttackTime > level.time )
  7529. {
  7530. return qfalse;
  7531. }
  7532. }
  7533. if ( cone >= 1.0f )
  7534. {//must be pointing right at them
  7535. if ( ent != forwardEnt )
  7536. {//must be the person I'm looking right at
  7537. if ( ent->client && !pull
  7538. && ent->client->ps.forceGripEntityNum == self->s.number
  7539. && (self->s.eFlags&EF_FORCE_GRIPPED) )
  7540. {//this is the guy that's force-gripping me, use a wider cone regardless of force power level
  7541. }
  7542. else
  7543. {
  7544. if ( ent->client && !pull
  7545. && ent->client->ps.forceDrainEntityNum == self->s.number
  7546. && (self->s.eFlags&EF_FORCE_DRAINED) )
  7547. {//this is the guy that's force-draining me, use a wider cone regardless of force power level
  7548. }
  7549. else
  7550. {
  7551. return qfalse;
  7552. }
  7553. }
  7554. }
  7555. }
  7556. if ( ent->s.eType != ET_ITEM && ent->e_ThinkFunc != thinkF_G_RunObject )//|| !(ent->flags&FL_DROPPED_ITEM) )//was only dropped items
  7557. {
  7558. //FIXME: need pushable objects
  7559. if ( ent->s.eFlags & EF_NODRAW )
  7560. {
  7561. return qfalse;
  7562. }
  7563. if ( !ent->client )
  7564. {
  7565. if ( Q_stricmp( "lightsaber", ent->classname ) != 0 )
  7566. {//not a lightsaber
  7567. if ( !(ent->svFlags&SVF_GLASS_BRUSH) )
  7568. {//and not glass
  7569. if ( Q_stricmp( "func_door", ent->classname ) != 0 || !(ent->spawnflags & 2/*MOVER_FORCE_ACTIVATE*/) )
  7570. {//not a force-usable door
  7571. if ( Q_stricmp( "func_static", ent->classname ) != 0 || (!(ent->spawnflags&1/*F_PUSH*/)&&!(ent->spawnflags&2/*F_PULL*/)) || (ent->spawnflags&32/*SOLITARY*/) )
  7572. {//not a force-usable func_static or, it is one, but it's solitary, so you only press it when looking right at it
  7573. if ( Q_stricmp( "limb", ent->classname ) )
  7574. {//not a limb
  7575. if ( ent->s.weapon == WP_TURRET && !Q_stricmp( "PAS", ent->classname ) && ent->s.apos.trType == TR_STATIONARY )
  7576. {//can knock over placed turrets
  7577. if ( !self->s.number || self->enemy != ent )
  7578. {//only NPCs who are actively mad at this turret can push it over
  7579. return qfalse;
  7580. }
  7581. }
  7582. else
  7583. {
  7584. return qfalse;
  7585. }
  7586. }
  7587. }
  7588. }
  7589. else if ( ent->moverState != MOVER_POS1 && ent->moverState != MOVER_POS2 )
  7590. {//not at rest
  7591. return qfalse;
  7592. }
  7593. }
  7594. }
  7595. //return qfalse;
  7596. }
  7597. else if ( ent->client->NPC_class == CLASS_MARK1 )
  7598. {//can't push Mark1 unless push 3
  7599. if ( pull || self->client->ps.forcePowerLevel[FP_PUSH] < FORCE_LEVEL_3 )
  7600. {
  7601. return qfalse;
  7602. }
  7603. }
  7604. else if ( ent->client->NPC_class == CLASS_GALAKMECH
  7605. || ent->client->NPC_class == CLASS_ATST
  7606. || ent->client->NPC_class == CLASS_RANCOR
  7607. || ent->client->NPC_class == CLASS_WAMPA
  7608. || ent->client->NPC_class == CLASS_SAND_CREATURE )
  7609. {//can't push ATST or Galak or Rancor or Wampa
  7610. return qfalse;
  7611. }
  7612. else if ( ent->s.weapon == WP_EMPLACED_GUN )
  7613. {//FIXME: maybe can pull them out?
  7614. return qfalse;
  7615. }
  7616. else if ( ent->client->playerTeam == self->client->playerTeam && self->enemy && self->enemy != ent )
  7617. {//can't accidently push a teammate while in combat
  7618. return qfalse;
  7619. }
  7620. else if ( G_IsRidingVehicle( ent )
  7621. && (ent->s.eFlags&EF_NODRAW) )
  7622. {//can't push/pull anyone riding *inside* vehicle
  7623. return qfalse;
  7624. }
  7625. }
  7626. else if ( ent->s.eType == ET_ITEM
  7627. && ent->item
  7628. && ent->item->giType == IT_HOLDABLE
  7629. && ent->item->giTag == INV_SECURITY_KEY )
  7630. //&& (ent->flags&FL_DROPPED_ITEM) ???
  7631. {//dropped security keys can't be pushed? But placed ones can...? does this make any sense?
  7632. if ( !pull || self->s.number )
  7633. {//can't push, NPC's can't do anything to it
  7634. return qfalse;
  7635. }
  7636. else
  7637. {
  7638. if ( g_crosshairEntNum != ent->s.number )
  7639. {//player can pull it if looking *right* at it
  7640. if ( cone >= 1.0f )
  7641. {//we did a forwardEnt trace
  7642. if ( forwardEnt != ent )
  7643. {//must be pointing right at them
  7644. return qfalse;
  7645. }
  7646. }
  7647. else if ( forward )
  7648. {//do a forwardEnt trace
  7649. trace_t tr;
  7650. vec3_t end;
  7651. VectorMA( self->client->renderInfo.eyePoint, radius, forward, end );
  7652. gi.trace( &tr, self->client->renderInfo.eyePoint, vec3_origin, vec3_origin, end, self->s.number, MASK_OPAQUE|CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_ITEM|CONTENTS_CORPSE );//was MASK_SHOT, changed to match crosshair trace
  7653. if ( tr.entityNum != ent->s.number )
  7654. {//last chance
  7655. return qfalse;
  7656. }
  7657. }
  7658. }
  7659. }
  7660. }
  7661. }
  7662. else
  7663. {
  7664. switch ( ent->s.weapon )
  7665. {//only missiles with mass are force-pushable
  7666. case WP_SABER:
  7667. case WP_FLECHETTE:
  7668. case WP_ROCKET_LAUNCHER:
  7669. case WP_CONCUSSION:
  7670. case WP_THERMAL:
  7671. case WP_TRIP_MINE:
  7672. case WP_DET_PACK:
  7673. break;
  7674. //only alt-fire of this weapon is force-pushable
  7675. case WP_REPEATER:
  7676. if ( ent->methodOfDeath != MOD_REPEATER_ALT )
  7677. {//not an alt-fire missile
  7678. return qfalse;
  7679. }
  7680. break;
  7681. //everything else cannot be pushed
  7682. case WP_ATST_SIDE:
  7683. if ( ent->methodOfDeath != MOD_EXPLOSIVE )
  7684. {//not a rocket
  7685. return qfalse;
  7686. }
  7687. break;
  7688. default:
  7689. return qfalse;
  7690. break;
  7691. }
  7692. if ( ent->s.pos.trType == TR_STATIONARY && (ent->s.eFlags&EF_MISSILE_STICK) )
  7693. {//can't force-push/pull stuck missiles (detpacks, tripmines)
  7694. return qfalse;
  7695. }
  7696. if ( ent->s.pos.trType == TR_STATIONARY && ent->s.weapon != WP_THERMAL )
  7697. {//only thermal detonators can be pushed once stopped
  7698. return qfalse;
  7699. }
  7700. }
  7701. return qtrue;
  7702. }
  7703. bool dontPillarPush = false;
  7704. void ForceThrow( gentity_t *self, qboolean pull, qboolean fake )
  7705. {//FIXME: pass in a target ent so we (an NPC) can push/pull just one targeted ent.
  7706. //shove things in front of you away
  7707. float dist;
  7708. gentity_t *ent, *forwardEnt = NULL;
  7709. gentity_t *entityList[MAX_GENTITIES];
  7710. gentity_t *push_list[MAX_GENTITIES];
  7711. int numListedEntities = 0;
  7712. vec3_t mins, maxs;
  7713. vec3_t v;
  7714. int i, e;
  7715. int ent_count = 0;
  7716. int radius;
  7717. vec3_t center, ent_org, size, forward, right, end, dir, fwdangles = {0};
  7718. float dot1, cone;
  7719. trace_t tr;
  7720. int anim, hold, soundIndex, cost, actualCost;
  7721. qboolean noResist = qfalse;
  7722. #ifdef _IMMERSION
  7723. int forceIndex;
  7724. #endif // _IMMERSION
  7725. if ( self->health <= 0 )
  7726. {
  7727. return;
  7728. }
  7729. if ( self->client->ps.leanofs )
  7730. {//can't force-throw while leaning
  7731. return;
  7732. }
  7733. if ( self->client->ps.forcePowerDebounce[FP_PUSH] > level.time )
  7734. {//already pushing- now you can't haul someone across the room, sorry
  7735. return;
  7736. }
  7737. if ( self->client->ps.forcePowerDebounce[FP_PULL] > level.time )
  7738. {//already pulling- now you can't haul someone across the room, sorry
  7739. return;
  7740. }
  7741. if ( self->client->ps.pullAttackTime > level.time )
  7742. {//already pull-attacking
  7743. return;
  7744. }
  7745. if ( !self->s.number && (cg.zoomMode || in_camera) )
  7746. {//can't force throw/pull when zoomed in or in cinematic
  7747. return;
  7748. }
  7749. if ( self->client->ps.saberLockTime > level.time )
  7750. {
  7751. if ( pull || self->client->ps.forcePowerLevel[FP_PUSH] < FORCE_LEVEL_3 )
  7752. {//this can be a way to break out
  7753. return;
  7754. }
  7755. //else, I'm breaking my half of the saberlock
  7756. self->client->ps.saberLockTime = 0;
  7757. self->client->ps.saberLockEnemy = ENTITYNUM_NONE;
  7758. }
  7759. if ( self->client->ps.legsAnim == BOTH_KNOCKDOWN3
  7760. || (self->client->ps.torsoAnim == BOTH_FORCE_GETUP_F1 && self->client->ps.torsoAnimTimer > 400)
  7761. || (self->client->ps.torsoAnim == BOTH_FORCE_GETUP_F2 && self->client->ps.torsoAnimTimer > 900)
  7762. || (self->client->ps.torsoAnim == BOTH_GETUP3 && self->client->ps.torsoAnimTimer > 500)
  7763. || (self->client->ps.torsoAnim == BOTH_GETUP4 && self->client->ps.torsoAnimTimer > 300)
  7764. || (self->client->ps.torsoAnim == BOTH_GETUP5 && self->client->ps.torsoAnimTimer > 500) )
  7765. {//we're face-down, so we'd only be force-push/pulling the floor
  7766. return;
  7767. }
  7768. if ( pull )
  7769. {
  7770. radius = forcePushPullRadius[self->client->ps.forcePowerLevel[FP_PULL]];
  7771. }
  7772. else
  7773. {
  7774. radius = forcePushPullRadius[self->client->ps.forcePowerLevel[FP_PUSH]];
  7775. }
  7776. if ( !radius )
  7777. {//no ability to do this yet
  7778. return;
  7779. }
  7780. if ( pull )
  7781. {
  7782. cost = forcePowerNeeded[FP_PULL];
  7783. if ( !WP_ForcePowerUsable( self, FP_PULL, cost ) )
  7784. {
  7785. return;
  7786. }
  7787. //make sure this plays and that you cannot press fire for about 200ms after this
  7788. anim = BOTH_FORCEPULL;
  7789. soundIndex = G_SoundIndex( "sound/weapons/force/pull.wav" );
  7790. #ifdef _IMMERSION
  7791. forceIndex = G_ForceIndex( "fffx/weapons/force/pull", FF_CHANNEL_WEAPON );
  7792. #endif // _IMMERSION
  7793. hold = 200;
  7794. }
  7795. else
  7796. {
  7797. cost = forcePowerNeeded[FP_PUSH];
  7798. if ( !WP_ForcePowerUsable( self, FP_PUSH, cost ) )
  7799. {
  7800. return;
  7801. }
  7802. //make sure this plays and that you cannot press fire for about 1 second after this
  7803. anim = BOTH_FORCEPUSH;
  7804. soundIndex = G_SoundIndex( "sound/weapons/force/push.wav" );
  7805. #ifdef _IMMERSION
  7806. forceIndex = G_ForceIndex( "fffx/weapons/force/push", FF_CHANNEL_WEAPON );
  7807. #endif // _IMMERSION
  7808. hold = 650;
  7809. }
  7810. int parts = SETANIM_TORSO;
  7811. if ( !PM_InKnockDown( &self->client->ps ) )
  7812. {
  7813. if ( self->client->ps.saberLockTime > level.time )
  7814. {
  7815. self->client->ps.saberLockTime = 0;
  7816. self->painDebounceTime = level.time + 2000;
  7817. hold += 1000;
  7818. parts = SETANIM_BOTH;
  7819. }
  7820. else if ( !VectorLengthSquared( self->client->ps.velocity ) && !(self->client->ps.pm_flags&PMF_DUCKED))
  7821. {
  7822. parts = SETANIM_BOTH;
  7823. }
  7824. }
  7825. NPC_SetAnim( self, parts, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD|SETANIM_FLAG_RESTART );
  7826. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  7827. self->client->ps.saberBlocked = BLOCKED_NONE;
  7828. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  7829. {
  7830. hold = floor( hold*g_timescale->value );
  7831. }
  7832. self->client->ps.weaponTime = hold;//was 1000, but want to swing sooner
  7833. //do effect... FIXME: build-up or delay this until in proper part of anim
  7834. self->client->ps.powerups[PW_FORCE_PUSH] = level.time + self->client->ps.torsoAnimTimer + 500;
  7835. //reset to 0 in case it's still > 0 from a previous push
  7836. self->client->pushEffectFadeTime = 0;
  7837. G_Sound( self, soundIndex );
  7838. #ifdef _IMMERSION
  7839. G_Force( self, forceIndex );
  7840. #endif // _IMMERSION
  7841. if ( (!pull && self->client->ps.forcePowersForced&(1<<FP_PUSH))
  7842. || (pull && self->client->ps.forcePowersForced&(1<<FP_PULL))
  7843. || (pull&&self->client->NPC_class==CLASS_KYLE&&(self->spawnflags&1)&&TIMER_Done( self, "kyleTakesSaber" )) )
  7844. {
  7845. noResist = qtrue;
  7846. }
  7847. VectorCopy( self->client->ps.viewangles, fwdangles );
  7848. //fwdangles[1] = self->client->ps.viewangles[1];
  7849. AngleVectors( fwdangles, forward, right, NULL );
  7850. VectorCopy( self->currentOrigin, center );
  7851. if ( pull )
  7852. {
  7853. cone = forcePullCone[self->client->ps.forcePowerLevel[FP_PULL]];
  7854. }
  7855. else
  7856. {
  7857. cone = forcePushCone[self->client->ps.forcePowerLevel[FP_PUSH]];
  7858. }
  7859. // if ( cone >= 1.0f )
  7860. {//must be pointing right at them
  7861. VectorMA( self->client->renderInfo.eyePoint, radius, forward, end );
  7862. gi.trace( &tr, self->client->renderInfo.eyePoint, vec3_origin, vec3_origin, end, self->s.number, MASK_OPAQUE|CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_ITEM|CONTENTS_CORPSE );//was MASK_SHOT, changed to match crosshair trace
  7863. if ( tr.entityNum < ENTITYNUM_WORLD )
  7864. {//found something right in front of self,
  7865. forwardEnt = &g_entities[tr.entityNum];
  7866. if ( !forwardEnt->client && !Q_stricmp( "func_static", forwardEnt->classname ) )
  7867. {
  7868. if ( (forwardEnt->spawnflags&1/*F_PUSH*/)||(forwardEnt->spawnflags&2/*F_PULL*/) )
  7869. {//push/pullable
  7870. if ( (forwardEnt->spawnflags&32/*SOLITARY*/) )
  7871. {//can only push/pull ME, ignore all others
  7872. if ( forwardEnt->NPC_targetname == NULL
  7873. || (self->targetname&&Q_stricmp( forwardEnt->NPC_targetname, self->targetname ) == 0) )
  7874. {//anyone can push it or only 1 person can push it and it's me
  7875. push_list[0] = forwardEnt;
  7876. ent_count = numListedEntities = 1;
  7877. }
  7878. }
  7879. }
  7880. }
  7881. }
  7882. }
  7883. if ( forwardEnt )
  7884. {
  7885. if ( G_TryingPullAttack( self, &self->client->usercmd, qtrue ) )
  7886. {//we're going to try to do a pull attack on our forwardEnt
  7887. if ( WP_ForceThrowable( forwardEnt, forwardEnt, self, pull, cone, radius, forward ) )
  7888. {//we will actually pull-attack him, so don't pull him or anything else here
  7889. //activate the power, here, though, so the later check that actually does the pull attack knows we tried to pull
  7890. self->client->ps.forcePowersActive |= (1<<FP_PULL);
  7891. self->client->ps.forcePowerDebounce[FP_PULL] = level.time + 100; //force-pulling
  7892. return;
  7893. }
  7894. }
  7895. }
  7896. if ( !numListedEntities )
  7897. {
  7898. for ( i = 0 ; i < 3 ; i++ )
  7899. {
  7900. mins[i] = center[i] - radius;
  7901. maxs[i] = center[i] + radius;
  7902. }
  7903. numListedEntities = gi.EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  7904. for ( e = 0 ; e < numListedEntities ; e++ )
  7905. {
  7906. ent = entityList[ e ];
  7907. if ( !WP_ForceThrowable( ent, forwardEnt, self, pull, cone, radius, forward ) )
  7908. {
  7909. continue;
  7910. }
  7911. //this is all to see if we need to start a saber attack, if it's in flight, this doesn't matter
  7912. // find the distance from the edge of the bounding box
  7913. for ( i = 0 ; i < 3 ; i++ )
  7914. {
  7915. if ( center[i] < ent->absmin[i] )
  7916. {
  7917. v[i] = ent->absmin[i] - center[i];
  7918. } else if ( center[i] > ent->absmax[i] )
  7919. {
  7920. v[i] = center[i] - ent->absmax[i];
  7921. } else
  7922. {
  7923. v[i] = 0;
  7924. }
  7925. }
  7926. VectorSubtract( ent->absmax, ent->absmin, size );
  7927. VectorMA( ent->absmin, 0.5, size, ent_org );
  7928. //see if they're in front of me
  7929. VectorSubtract( ent_org, center, dir );
  7930. VectorNormalize( dir );
  7931. if ( cone < 1.0f )
  7932. {//must be within the forward cone
  7933. if ( ent->client && !pull
  7934. && ent->client->ps.forceGripEntityNum == self->s.number
  7935. && (self->s.eFlags&EF_FORCE_GRIPPED) )
  7936. {//this is the guy that's force-gripping me, use a wider cone regardless of force power level
  7937. if ( (dot1 = DotProduct( dir, forward )) < cone-0.3f )
  7938. continue;
  7939. }
  7940. else if ( ent->client && !pull
  7941. && ent->client->ps.forceDrainEntityNum == self->s.number
  7942. && (self->s.eFlags&EF_FORCE_DRAINED) )
  7943. {//this is the guy that's force-draining me, use a wider cone regardless of force power level
  7944. if ( (dot1 = DotProduct( dir, forward )) < cone-0.3f )
  7945. continue;
  7946. }
  7947. else if ( ent->s.eType == ET_MISSILE )//&& ent->s.eType != ET_ITEM && ent->e_ThinkFunc != thinkF_G_RunObject )
  7948. {//missiles are easier to force-push, never require direct trace (FIXME: maybe also items and general physics objects)
  7949. if ( (dot1 = DotProduct( dir, forward )) < cone-0.3f )
  7950. continue;
  7951. }
  7952. else if ( (dot1 = DotProduct( dir, forward )) < cone )
  7953. {
  7954. continue;
  7955. }
  7956. }
  7957. else if ( ent->s.eType == ET_MISSILE )
  7958. {//a missile and we're at force level 1... just use a small cone, but not ridiculously small
  7959. if ( (dot1 = DotProduct( dir, forward )) < 0.75f )
  7960. {
  7961. continue;
  7962. }
  7963. }//else is an NPC or brush entity that our forward trace would have to hit
  7964. dist = VectorLength( v );
  7965. //Now check and see if we can actually deflect it
  7966. //method1
  7967. //if within a certain range, deflect it
  7968. if ( ent->s.eType == ET_MISSILE && cone >= 1.0f )
  7969. {//smaller radius on missile checks at force push 1
  7970. if ( dist >= 192 )
  7971. {
  7972. continue;
  7973. }
  7974. }
  7975. else if ( dist >= radius )
  7976. {
  7977. continue;
  7978. }
  7979. //in PVS?
  7980. if ( !ent->bmodel && !gi.inPVS( ent_org, self->client->renderInfo.eyePoint ) )
  7981. {//must be in PVS
  7982. continue;
  7983. }
  7984. if ( ent != forwardEnt )
  7985. {//don't need to trace against forwardEnt again
  7986. //really should have a clear LOS to this thing...
  7987. gi.trace( &tr, self->client->renderInfo.eyePoint, vec3_origin, vec3_origin, ent_org, self->s.number, MASK_FORCE_PUSH );//was MASK_SHOT, but changed to match above trace and crosshair trace
  7988. if ( tr.fraction < 1.0f && tr.entityNum != ent->s.number )
  7989. {//must have clear LOS
  7990. continue;
  7991. }
  7992. }
  7993. // ok, we are within the radius, add us to the incoming list
  7994. push_list[ent_count] = ent;
  7995. ent_count++;
  7996. }
  7997. }
  7998. if ( ent_count )
  7999. {
  8000. for ( int x = 0; x < ent_count; x++ )
  8001. {
  8002. if ( push_list[x]->client )
  8003. {
  8004. vec3_t pushDir;
  8005. float knockback = pull?0:200;
  8006. //SIGH band-aid...
  8007. if ( push_list[x]->s.number >= MAX_CLIENTS
  8008. && self->s.number < MAX_CLIENTS )
  8009. {
  8010. if ( (push_list[x]->client->ps.forcePowersActive&(1<<FP_GRIP))
  8011. //&& push_list[x]->client->ps.forcePowerDebounce[FP_GRIP] < level.time
  8012. && push_list[x]->client->ps.forceGripEntityNum == self->s.number )
  8013. {
  8014. WP_ForcePowerStop( push_list[x], FP_GRIP );
  8015. }
  8016. if ( (push_list[x]->client->ps.forcePowersActive&(1<<FP_DRAIN))
  8017. //&& push_list[x]->client->ps.forcePowerDebounce[FP_DRAIN] < level.time
  8018. && push_list[x]->client->ps.forceDrainEntityNum == self->s.number )
  8019. {
  8020. WP_ForcePowerStop( push_list[x], FP_DRAIN );
  8021. }
  8022. }
  8023. if ( Rosh_BeingHealed( push_list[x] ) )
  8024. {
  8025. continue;
  8026. }
  8027. if ( push_list[x]->client->NPC_class == CLASS_HAZARD_TROOPER
  8028. && push_list[x]->health > 0 )
  8029. {//living hazard troopers resist push/pull
  8030. WP_ForceThrowHazardTrooper( self, push_list[x], pull );
  8031. continue;
  8032. }
  8033. if ( fake )
  8034. {//always resist
  8035. WP_ResistForcePush( push_list[x], self, qfalse );
  8036. continue;
  8037. }
  8038. //FIXMEFIXMEFIXMEFIXMEFIXME: extern a lot of this common code when I have the time!!!
  8039. int powerLevel, powerUse;
  8040. if (pull)
  8041. {
  8042. powerLevel = self->client->ps.forcePowerLevel[FP_PULL];
  8043. powerUse = FP_PULL;
  8044. }
  8045. else
  8046. {
  8047. powerLevel = self->client->ps.forcePowerLevel[FP_PUSH];
  8048. powerUse = FP_PUSH;
  8049. }
  8050. int modPowerLevel = WP_AbsorbConversion( push_list[x], push_list[x]->client->ps.forcePowerLevel[FP_ABSORB], self, powerUse, powerLevel, forcePowerNeeded[self->client->ps.forcePowerLevel[powerUse]] );
  8051. if (push_list[x]->client->NPC_class==CLASS_ASSASSIN_DROID ||
  8052. push_list[x]->client->NPC_class==CLASS_HAZARD_TROOPER)
  8053. {
  8054. modPowerLevel = 0; // devides throw by 10
  8055. }
  8056. //First, if this is the player we're push/pulling, see if he can counter it
  8057. if ( modPowerLevel != -1
  8058. && !noResist
  8059. && InFront( self->currentOrigin, push_list[x]->client->renderInfo.eyePoint, push_list[x]->client->ps.viewangles, 0.3f ) )
  8060. {//absorbed and I'm in front of them
  8061. //counter it
  8062. if ( push_list[x]->client->ps.forcePowerLevel[FP_ABSORB] > FORCE_LEVEL_2 )
  8063. {//no reaction at all
  8064. }
  8065. else
  8066. {
  8067. WP_ResistForcePush( push_list[x], self, qfalse );
  8068. push_list[x]->client->ps.saberMove = push_list[x]->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  8069. push_list[x]->client->ps.saberBlocked = BLOCKED_NONE;
  8070. }
  8071. continue;
  8072. }
  8073. else if ( !push_list[x]->s.number )
  8074. {//player
  8075. if ( !noResist
  8076. && push_list[x]->health > 0 //alive
  8077. && push_list[x]->client //client
  8078. && push_list[x]->client->ps.forceRageRecoveryTime < level.time //not recobering from rage
  8079. && push_list[x]->client->ps.torsoAnim != BOTH_FORCEGRIP_HOLD// BOTH_FORCEGRIP1//wasn't trying to grip anyone
  8080. //&& push_list[x]->client->ps.torsoAnim != BOTH_HUGGER1// wasn't trying to grip-drain anyone
  8081. && push_list[x]->client->ps.torsoAnim != BOTH_FORCE_DRAIN_GRAB_START// wasn't trying to grip-drain anyone
  8082. && push_list[x]->client->ps.torsoAnim != BOTH_FORCE_DRAIN_GRAB_HOLD// wasn't trying to grip-drain anyone
  8083. && ((self->client->NPC_class != CLASS_DESANN&&Q_stricmp("Yoda",self->NPC_type)) || !Q_irand( 0, 2 ) )//only 30% chance of resisting a Desann push
  8084. && push_list[x]->client->ps.groundEntityNum != ENTITYNUM_NONE//on the ground
  8085. && !PM_InKnockDown( &push_list[x]->client->ps )//not knocked down already
  8086. && push_list[x]->client->ps.saberLockTime < level.time//not involved in a saberLock
  8087. && push_list[x]->client->ps.weaponTime < level.time//not attacking or otherwise busy
  8088. && (push_list[x]->client->ps.weapon == WP_SABER||push_list[x]->client->ps.weapon == WP_MELEE) )//using saber or fists
  8089. {//trying to push or pull the player!
  8090. if ( push_list[x]->client->ps.powerups[PW_FORCE_PUSH] > level.time//player was pushing/pulling too
  8091. ||( pull && Q_irand( 0, (push_list[x]->client->ps.forcePowerLevel[FP_PULL] - self->client->ps.forcePowerLevel[FP_PULL])*2+1 ) > 0 )//player's pull is high enough
  8092. ||( !pull && Q_irand( 0, (push_list[x]->client->ps.forcePowerLevel[FP_PUSH] - self->client->ps.forcePowerLevel[FP_PUSH])*2+1 ) > 0 ) )//player's push is high enough
  8093. {//player's force push/pull is high enough to try to stop me
  8094. if ( InFront( self->currentOrigin, push_list[x]->client->renderInfo.eyePoint, push_list[x]->client->ps.viewangles, 0.3f ) )
  8095. {//I'm in front of player
  8096. WP_ResistForcePush( push_list[x], self, qfalse );
  8097. push_list[x]->client->ps.saberMove = push_list[x]->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  8098. push_list[x]->client->ps.saberBlocked = BLOCKED_NONE;
  8099. continue;
  8100. }
  8101. }
  8102. }
  8103. }
  8104. else if ( push_list[x]->client && Jedi_WaitingAmbush( push_list[x] ) )
  8105. {
  8106. WP_ForceKnockdown( push_list[x], self, pull, qtrue, qfalse );
  8107. continue;
  8108. }
  8109. G_KnockOffVehicle( push_list[x], self, pull );
  8110. if ( !pull
  8111. && push_list[x]->client->ps.forceDrainEntityNum == self->s.number
  8112. && (self->s.eFlags&EF_FORCE_DRAINED) )
  8113. {//stop them from draining me now, dammit!
  8114. WP_ForcePowerStop( push_list[x], FP_DRAIN );
  8115. }
  8116. //okay, everyone else (or player who couldn't resist it)...
  8117. if ( ((self->s.number == 0 && Q_irand( 0, 2 ) ) || Q_irand( 0, 2 ) ) && push_list[x]->client && push_list[x]->health > 0 //a living client
  8118. && push_list[x]->client->ps.weapon == WP_SABER //Jedi
  8119. && push_list[x]->health > 0 //alive
  8120. && push_list[x]->client->ps.forceRageRecoveryTime < level.time //not recobering from rage
  8121. && ((self->client->NPC_class != CLASS_DESANN&&Q_stricmp("Yoda",self->NPC_type)) || !Q_irand( 0, 2 ) )//only 30% chance of resisting a Desann push
  8122. && push_list[x]->client->ps.groundEntityNum != ENTITYNUM_NONE //on the ground
  8123. && InFront( self->currentOrigin, push_list[x]->currentOrigin, push_list[x]->client->ps.viewangles, 0.3f ) //I'm in front of him
  8124. && ( push_list[x]->client->ps.powerups[PW_FORCE_PUSH] > level.time ||//he's pushing too
  8125. (push_list[x]->s.number != 0 && push_list[x]->client->ps.weaponTime < level.time)//not the player and not attacking (NPC jedi auto-defend against pushes)
  8126. )
  8127. )
  8128. {//Jedi don't get pushed, they resist as long as they aren't already attacking and are on the ground
  8129. if ( push_list[x]->client->ps.saberLockTime > level.time )
  8130. {//they're in a lock
  8131. if ( push_list[x]->client->ps.saberLockEnemy != self->s.number )
  8132. {//they're not in a lock with me
  8133. continue;
  8134. }
  8135. else if ( pull || self->client->ps.forcePowerLevel[FP_PUSH] < FORCE_LEVEL_3 ||
  8136. push_list[x]->client->ps.forcePowerLevel[FP_PUSH] > FORCE_LEVEL_2 )
  8137. {//they're in a lock with me, but my push is too weak
  8138. continue;
  8139. }
  8140. else
  8141. {//we will knock them down
  8142. self->painDebounceTime = 0;
  8143. self->client->ps.weaponTime = 500;
  8144. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  8145. {
  8146. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  8147. }
  8148. }
  8149. }
  8150. int resistChance = Q_irand(0, 2);
  8151. if ( push_list[x]->s.number >= MAX_CLIENTS )
  8152. {//NPC
  8153. if ( g_spskill->integer == 1 )
  8154. {//stupid tweak for graham
  8155. resistChance = Q_irand(0, 3);
  8156. }
  8157. }
  8158. if ( noResist ||
  8159. ( !pull
  8160. && modPowerLevel == -1
  8161. && self->client->ps.forcePowerLevel[FP_PUSH] > FORCE_LEVEL_2
  8162. && !resistChance
  8163. && push_list[x]->client->ps.forcePowerLevel[FP_PUSH] < FORCE_LEVEL_3 )
  8164. )
  8165. {//a level 3 push can even knock down a jedi
  8166. if ( PM_InKnockDown( &push_list[x]->client->ps ) )
  8167. {//can't knock them down again
  8168. continue;
  8169. }
  8170. WP_ForceKnockdown( push_list[x], self, pull, qfalse, qtrue );
  8171. }
  8172. else
  8173. {
  8174. WP_ResistForcePush( push_list[x], self, qfalse );
  8175. }
  8176. }
  8177. else
  8178. {
  8179. //UGH: FIXME: for enemy jedi, they should probably always do force pull 3, and not your weapon (if player?)!
  8180. //shove them
  8181. if ( push_list[x]->NPC
  8182. && push_list[x]->NPC->jumpState == JS_JUMPING )
  8183. {//don't interrupt a scripted jump
  8184. //WP_ResistForcePush( push_list[x], self, qfalse );
  8185. push_list[x]->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  8186. continue;
  8187. }
  8188. if ( push_list[x]->s.number
  8189. && (push_list[x]->message || (push_list[x]->flags&FL_NO_KNOCKBACK)) )
  8190. {//an NPC who has a key
  8191. //don't push me... FIXME: maybe can pull the key off me?
  8192. WP_ForceKnockdown( push_list[x], self, pull, qfalse, qfalse );
  8193. continue;
  8194. }
  8195. if ( pull )
  8196. {
  8197. VectorSubtract( self->currentOrigin, push_list[x]->currentOrigin, pushDir );
  8198. if ( self->client->ps.forcePowerLevel[FP_PULL] >= FORCE_LEVEL_3
  8199. && self->client->NPC_class == CLASS_KYLE
  8200. && (self->spawnflags&1)
  8201. && TIMER_Done( self, "kyleTakesSaber" )
  8202. && push_list[x]->client
  8203. && push_list[x]->client->ps.weapon == WP_SABER
  8204. && !push_list[x]->client->ps.saberInFlight
  8205. && push_list[x]->client->ps.saberEntityNum < ENTITYNUM_WORLD
  8206. && !PM_InOnGroundAnim( &push_list[x]->client->ps ) )
  8207. {
  8208. vec3_t throwVec;
  8209. VectorScale( pushDir, 10.0f, throwVec );
  8210. WP_SaberLose( push_list[x], throwVec );
  8211. NPC_SetAnim( push_list[x], SETANIM_BOTH, BOTH_LOSE_SABER, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  8212. push_list[x]->client->ps.torsoAnimTimer += 500;
  8213. push_list[x]->client->ps.pm_time = push_list[x]->client->ps.weaponTime = push_list[x]->client->ps.torsoAnimTimer;
  8214. push_list[x]->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  8215. push_list[x]->client->ps.saberMove = LS_NONE;
  8216. push_list[x]->aimDebounceTime = level.time + push_list[x]->client->ps.torsoAnimTimer;
  8217. VectorClear( push_list[x]->client->ps.velocity );
  8218. VectorClear( push_list[x]->client->ps.moveDir );
  8219. //Kyle will stand around for a bit, too...
  8220. self->client->ps.pm_time = self->client->ps.weaponTime = 2000;
  8221. self->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  8222. self->painDebounceTime = level.time + self->client->ps.weaponTime;
  8223. TIMER_Set( self, "kyleTakesSaber", Q_irand( 60000, 180000 ) );//don't do this again for a while
  8224. G_AddVoiceEvent( self, Q_irand(EV_TAUNT1,EV_TAUNT3), Q_irand( 4000, 6000 ) );
  8225. VectorClear( self->client->ps.velocity );
  8226. VectorClear( self->client->ps.moveDir );
  8227. continue;
  8228. }
  8229. else if ( push_list[x]->NPC
  8230. && (push_list[x]->NPC->scriptFlags&SCF_DONT_FLEE) )
  8231. {//*SIGH*... if an NPC can't flee, they can't run after and pick up their weapon, do don't drop it
  8232. }
  8233. else if ( self->client->ps.forcePowerLevel[FP_PULL] > FORCE_LEVEL_1
  8234. && push_list[x]->client->NPC_class != CLASS_ROCKETTROOPER//rockettroopers never drop their weapon
  8235. && push_list[x]->client->NPC_class != CLASS_VEHICLE
  8236. && push_list[x]->client->NPC_class != CLASS_BOBAFETT
  8237. && push_list[x]->client->NPC_class != CLASS_TUSKEN
  8238. && push_list[x]->client->NPC_class != CLASS_HAZARD_TROOPER
  8239. && push_list[x]->client->NPC_class != CLASS_ASSASSIN_DROID
  8240. && push_list[x]->s.weapon != WP_SABER
  8241. && push_list[x]->s.weapon != WP_MELEE
  8242. && push_list[x]->s.weapon != WP_THERMAL
  8243. && push_list[x]->s.weapon != WP_CONCUSSION // so rax can't drop his
  8244. )
  8245. {//yank the weapon - NOTE: level 1 just knocks them down, not take weapon
  8246. //FIXME: weapon yank anim if not a knockdown?
  8247. if ( InFront( self->currentOrigin, push_list[x]->currentOrigin, push_list[x]->client->ps.viewangles, 0.0f ) )
  8248. {//enemy has to be facing me, too...
  8249. WP_DropWeapon( push_list[x], pushDir );
  8250. }
  8251. }
  8252. knockback += VectorNormalize( pushDir );
  8253. if ( knockback > 200 )
  8254. {
  8255. knockback = 200;
  8256. }
  8257. if ( self->client->ps.forcePowerLevel[FP_PULL] < FORCE_LEVEL_3 )
  8258. {//maybe just knock them down
  8259. knockback /= 3;
  8260. }
  8261. }
  8262. else
  8263. {
  8264. VectorSubtract( push_list[x]->currentOrigin, self->currentOrigin, pushDir );
  8265. knockback -= VectorNormalize( pushDir );
  8266. if ( knockback < 100 )
  8267. {
  8268. knockback = 100;
  8269. }
  8270. //scale for push level
  8271. if ( self->client->ps.forcePowerLevel[FP_PUSH] < FORCE_LEVEL_2 )
  8272. {//maybe just knock them down
  8273. knockback /= 3;
  8274. }
  8275. else if ( self->client->ps.forcePowerLevel[FP_PUSH] > FORCE_LEVEL_2 )
  8276. {//super-hard push
  8277. //Hmm, maybe in this case can even nudge/knockdown a jedi? Especially if close?
  8278. //knockback *= 5;
  8279. }
  8280. }
  8281. if ( modPowerLevel != -1 )
  8282. {
  8283. if ( !modPowerLevel )
  8284. {
  8285. knockback /= 10.0f;
  8286. }
  8287. else if ( modPowerLevel == 1 )
  8288. {
  8289. knockback /= 6.0f;
  8290. }
  8291. else// if ( modPowerLevel == 2 )
  8292. {
  8293. knockback /= 2.0f;
  8294. }
  8295. }
  8296. //actually push/pull the enemy
  8297. G_Throw( push_list[x], pushDir, knockback );
  8298. //make it so they don't actually hurt me when pulled at me...
  8299. push_list[x]->forcePuller = self->s.number;
  8300. if ( push_list[x]->client->ps.groundEntityNum != ENTITYNUM_NONE )
  8301. {//if on the ground, make sure they get shoved up some
  8302. if ( push_list[x]->client->ps.velocity[2] < knockback )
  8303. {
  8304. push_list[x]->client->ps.velocity[2] = knockback;
  8305. }
  8306. }
  8307. if ( push_list[x]->health > 0 )
  8308. {//target is still alive
  8309. if ( (push_list[x]->s.number||(cg.renderingThirdPerson&&!cg.zoomMode)) //NPC or 3rd person player
  8310. && ((!pull&&self->client->ps.forcePowerLevel[FP_PUSH] < FORCE_LEVEL_2 && push_list[x]->client->ps.forcePowerLevel[FP_PUSH] < FORCE_LEVEL_1) //level 1 push
  8311. || (pull && self->client->ps.forcePowerLevel[FP_PULL] < FORCE_LEVEL_2 && push_list[x]->client->ps.forcePowerLevel[FP_PULL] < FORCE_LEVEL_1)) )//level 1 pull
  8312. {//NPC or third person player (without force push/pull skill), and force push/pull level is at 1
  8313. WP_ForceKnockdown( push_list[x], self, pull, (!pull&&knockback>150), qfalse );
  8314. }
  8315. else if ( !push_list[x]->s.number )
  8316. {//player, have to force an anim on him
  8317. WP_ForceKnockdown( push_list[x], self, pull, (!pull&&knockback>150), qfalse );
  8318. }
  8319. else
  8320. {//NPC and force-push/pull at level 2 or higher
  8321. WP_ForceKnockdown( push_list[x], self, pull, (!pull&&knockback>100), qfalse );
  8322. }
  8323. }
  8324. push_list[x]->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  8325. }
  8326. }
  8327. else if ( !fake )
  8328. {//not a fake push/pull
  8329. if ( push_list[x]->s.weapon == WP_SABER && (push_list[x]->contents&CONTENTS_LIGHTSABER) )
  8330. {//a thrown saber, just send it back
  8331. /*
  8332. if ( pull )
  8333. {//steal it?
  8334. }
  8335. else */if ( push_list[x]->owner && push_list[x]->owner->client && push_list[x]->owner->client->ps.SaberActive() && push_list[x]->s.pos.trType == TR_LINEAR && push_list[x]->owner->client->ps.saberEntityState != SES_RETURNING )
  8336. {//it's on and being controlled
  8337. //FIXME: prevent it from damaging me?
  8338. if ( self->s.number == 0 || Q_irand( 0, 2 ) )
  8339. {//certain chance of throwing it aside and turning it off?
  8340. //give it some velocity away from me
  8341. //FIXME: maybe actually push or pull it?
  8342. if ( Q_irand( 0, 1 ) )
  8343. {
  8344. VectorScale( right, -1, right );
  8345. }
  8346. G_ReflectMissile( self, push_list[x], right );
  8347. //FIXME: isn't turning off!!!
  8348. WP_SaberDrop( push_list[x]->owner, push_list[x] );
  8349. }
  8350. else
  8351. {
  8352. WP_SaberReturn( push_list[x]->owner, push_list[x] );
  8353. }
  8354. //different effect?
  8355. }
  8356. }
  8357. else if ( push_list[x]->s.eType == ET_MISSILE
  8358. && push_list[x]->s.pos.trType != TR_STATIONARY
  8359. && (push_list[x]->s.pos.trType != TR_INTERPOLATE||push_list[x]->s.weapon != WP_THERMAL) )//rolling and stationary thermal detonators are dealt with below
  8360. {
  8361. vec3_t dir2Me;
  8362. VectorSubtract( self->currentOrigin, push_list[x]->currentOrigin, dir2Me );
  8363. float dot = DotProduct( push_list[x]->s.pos.trDelta, dir2Me );
  8364. if ( pull )
  8365. {//deflect rather than reflect?
  8366. }
  8367. else
  8368. {
  8369. if ( push_list[x]->s.eFlags&EF_MISSILE_STICK )
  8370. {//caught a sticky in-air
  8371. push_list[x]->s.eType = ET_MISSILE;
  8372. push_list[x]->s.eFlags &= ~EF_MISSILE_STICK;
  8373. push_list[x]->s.eFlags |= EF_BOUNCE_HALF;
  8374. push_list[x]->splashDamage /= 3;
  8375. push_list[x]->splashRadius /= 3;
  8376. push_list[x]->e_ThinkFunc = thinkF_WP_Explode;
  8377. push_list[x]->nextthink = level.time + Q_irand( 500, 3000 );
  8378. }
  8379. if ( dot >= 0 )
  8380. {//it's heading towards me
  8381. G_ReflectMissile( self, push_list[x], forward );
  8382. }
  8383. else
  8384. {
  8385. VectorScale( push_list[x]->s.pos.trDelta, 1.25f, push_list[x]->s.pos.trDelta );
  8386. }
  8387. //deflect sound
  8388. //G_Sound( push_list[x], G_SoundIndex( va("sound/weapons/blaster/reflect%d.wav", Q_irand( 1, 3 ) ) ) );
  8389. //push_list[x]->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  8390. }
  8391. if ( push_list[x]->s.eType == ET_MISSILE
  8392. && push_list[x]->s.weapon == WP_ROCKET_LAUNCHER
  8393. && push_list[x]->damage < 60 )
  8394. {//pushing away a rocket raises it's damage to the max for NPCs
  8395. push_list[x]->damage = 60;
  8396. }
  8397. }
  8398. else if ( push_list[x]->svFlags & SVF_GLASS_BRUSH )
  8399. {//break the glass
  8400. trace_t tr;
  8401. vec3_t pushDir;
  8402. float damage = 800;
  8403. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  8404. VectorNormalize( forward );
  8405. VectorMA( self->client->renderInfo.eyePoint, radius, forward, end );
  8406. gi.trace( &tr, self->client->renderInfo.eyePoint, vec3_origin, vec3_origin, end, self->s.number, MASK_SHOT );
  8407. if ( tr.entityNum != push_list[x]->s.number || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  8408. {//must be pointing right at it
  8409. continue;
  8410. }
  8411. if ( pull )
  8412. {
  8413. VectorSubtract( self->client->renderInfo.eyePoint, tr.endpos, pushDir );
  8414. }
  8415. else
  8416. {
  8417. VectorSubtract( tr.endpos, self->client->renderInfo.eyePoint, pushDir );
  8418. }
  8419. /*
  8420. VectorSubtract( push_list[x]->absmax, push_list[x]->absmin, size );
  8421. VectorMA( push_list[x]->absmin, 0.5, size, center );
  8422. if ( pull )
  8423. {
  8424. VectorSubtract( self->client->renderInfo.eyePoint, center, pushDir );
  8425. }
  8426. else
  8427. {
  8428. VectorSubtract( center, self->client->renderInfo.eyePoint, pushDir );
  8429. }
  8430. */
  8431. damage -= VectorNormalize( pushDir );
  8432. if ( damage < 200 )
  8433. {
  8434. damage = 200;
  8435. }
  8436. VectorScale( pushDir, damage, pushDir );
  8437. G_Damage( push_list[x], self, self, pushDir, tr.endpos, damage, 0, MOD_UNKNOWN );
  8438. }
  8439. else if ( !Q_stricmp( "func_static", push_list[x]->classname ) )
  8440. {//force-usable func_static
  8441. if ( !pull && (push_list[x]->spawnflags&1/*F_PUSH*/) )
  8442. {
  8443. if ( push_list[x]->NPC_targetname == NULL
  8444. || (self->targetname&&Q_stricmp( push_list[x]->NPC_targetname, self->targetname ) == 0) )
  8445. {//anyone can pull it or only 1 person can push it and it's me
  8446. if(push_list[x]->behaviorSet[BSET_USE] &&
  8447. !Q_stricmp(push_list[x]->behaviorSet[BSET_USE],
  8448. "kor2/pillar_push")) {
  8449. if(!dontPillarPush) {
  8450. GEntity_UseFunc( push_list[x], self, self );
  8451. }
  8452. dontPillarPush = true;
  8453. } else {
  8454. GEntity_UseFunc( push_list[x], self, self );
  8455. }
  8456. }
  8457. }
  8458. else if ( pull && (push_list[x]->spawnflags&2/*F_PULL*/) )
  8459. {
  8460. if ( push_list[x]->NPC_targetname == NULL
  8461. || (self->targetname&&Q_stricmp( push_list[x]->NPC_targetname, self->NPC_targetname ) == 0) )
  8462. {//anyone can push it or only 1 person can push it and it's me
  8463. GEntity_UseFunc( push_list[x], self, self );
  8464. }
  8465. }
  8466. }
  8467. else if ( !Q_stricmp( "func_door", push_list[x]->classname ) && (push_list[x]->spawnflags&2/*MOVER_FORCE_ACTIVATE*/) )
  8468. {//push/pull the door
  8469. vec3_t pos1, pos2;
  8470. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  8471. VectorNormalize( forward );
  8472. VectorMA( self->client->renderInfo.eyePoint, radius, forward, end );
  8473. gi.trace( &tr, self->client->renderInfo.eyePoint, vec3_origin, vec3_origin, end, self->s.number, MASK_SHOT );
  8474. if ( tr.entityNum != push_list[x]->s.number || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  8475. {//must be pointing right at it
  8476. continue;
  8477. }
  8478. if ( VectorCompare( vec3_origin, push_list[x]->s.origin ) )
  8479. {//does not have an origin brush, so pos1 & pos2 are relative to world origin, need to calc center
  8480. VectorSubtract( push_list[x]->absmax, push_list[x]->absmin, size );
  8481. VectorMA( push_list[x]->absmin, 0.5, size, center );
  8482. if ( (push_list[x]->spawnflags&1) && push_list[x]->moverState == MOVER_POS1 )
  8483. {//if at pos1 and started open, make sure we get the center where it *started* because we're going to add back in the relative values pos1 and pos2
  8484. VectorSubtract( center, push_list[x]->pos1, center );
  8485. }
  8486. else if ( !(push_list[x]->spawnflags&1) && push_list[x]->moverState == MOVER_POS2 )
  8487. {//if at pos2, make sure we get the center where it *started* because we're going to add back in the relative values pos1 and pos2
  8488. VectorSubtract( center, push_list[x]->pos2, center );
  8489. }
  8490. VectorAdd( center, push_list[x]->pos1, pos1 );
  8491. VectorAdd( center, push_list[x]->pos2, pos2 );
  8492. }
  8493. else
  8494. {//actually has an origin, pos1 and pos2 are absolute
  8495. VectorCopy( push_list[x]->currentOrigin, center );
  8496. VectorCopy( push_list[x]->pos1, pos1 );
  8497. VectorCopy( push_list[x]->pos2, pos2 );
  8498. }
  8499. if ( Distance( pos1, self->client->renderInfo.eyePoint ) < Distance( pos2, self->client->renderInfo.eyePoint ) )
  8500. {//pos1 is closer
  8501. if ( push_list[x]->moverState == MOVER_POS1 )
  8502. {//at the closest pos
  8503. if ( pull )
  8504. {//trying to pull, but already at closest point, so screw it
  8505. continue;
  8506. }
  8507. }
  8508. else if ( push_list[x]->moverState == MOVER_POS2 )
  8509. {//at farthest pos
  8510. if ( !pull )
  8511. {//trying to push, but already at farthest point, so screw it
  8512. continue;
  8513. }
  8514. }
  8515. }
  8516. else
  8517. {//pos2 is closer
  8518. if ( push_list[x]->moverState == MOVER_POS1 )
  8519. {//at the farthest pos
  8520. if ( !pull )
  8521. {//trying to push, but already at farthest point, so screw it
  8522. continue;
  8523. }
  8524. }
  8525. else if ( push_list[x]->moverState == MOVER_POS2 )
  8526. {//at closest pos
  8527. if ( pull )
  8528. {//trying to pull, but already at closest point, so screw it
  8529. continue;
  8530. }
  8531. }
  8532. }
  8533. GEntity_UseFunc( push_list[x], self, self );
  8534. }
  8535. else if ( push_list[x]->s.eType == ET_MISSILE/*thermal resting on ground*/
  8536. || push_list[x]->s.eType == ET_ITEM
  8537. || push_list[x]->e_ThinkFunc == thinkF_G_RunObject || Q_stricmp( "limb", push_list[x]->classname ) == 0 )
  8538. {//general object, toss it
  8539. vec3_t pushDir, kvel;
  8540. float knockback = pull?0:200;
  8541. float mass = 200;
  8542. if ( pull )
  8543. {
  8544. if ( push_list[x]->s.eType == ET_ITEM )
  8545. {//pull it to a little higher point
  8546. vec3_t adjustedOrg;
  8547. VectorCopy( self->currentOrigin, adjustedOrg );
  8548. adjustedOrg[2] += self->maxs[2]/3;
  8549. VectorSubtract( adjustedOrg, push_list[x]->currentOrigin, pushDir );
  8550. }
  8551. else if ( self->enemy //I have an enemy
  8552. //&& push_list[x]->s.eType != ET_ITEM //not an item
  8553. && self->client->ps.forcePowerLevel[FP_PUSH] > FORCE_LEVEL_2 //have push 3 or greater
  8554. && InFront(push_list[x]->currentOrigin, self->currentOrigin, self->currentAngles, 0.25f)//object is generally in front of me
  8555. && InFront(self->enemy->currentOrigin, self->currentOrigin, self->currentAngles, 0.75f)//enemy is pretty much right in front of me
  8556. && !InFront(push_list[x]->currentOrigin, self->enemy->currentOrigin, self->enemy->currentAngles, -0.25f)//object is generally behind enemy
  8557. //FIXME: check dist to enemy and clear LOS to enemy and clear Path between object and enemy?
  8558. && ( (self->NPC&&(noResist||Q_irand(0,RANK_CAPTAIN)<self->NPC->rank) )//NPC with enough skill
  8559. ||( self->s.number<MAX_CLIENTS ) )
  8560. )
  8561. {//if I have an auto-enemy & he's in front of me, push it toward him!
  8562. /*
  8563. if ( targetedObjectMassTotal + push_list[x]->mass > TARGETED_OBJECT_PUSH_MASS_MAX )
  8564. {//already pushed too many things
  8565. //FIXME: pick closest?
  8566. continue;
  8567. }
  8568. targetedObjectMassTotal += push_list[x]->mass;
  8569. */
  8570. VectorSubtract( self->enemy->currentOrigin, push_list[x]->currentOrigin, pushDir );
  8571. }
  8572. else
  8573. {
  8574. VectorSubtract( self->currentOrigin, push_list[x]->currentOrigin, pushDir );
  8575. }
  8576. knockback += VectorNormalize( pushDir );
  8577. if ( knockback > 200 )
  8578. {
  8579. knockback = 200;
  8580. }
  8581. if ( push_list[x]->s.eType == ET_ITEM
  8582. && push_list[x]->item
  8583. && push_list[x]->item->giType == IT_HOLDABLE
  8584. && push_list[x]->item->giTag == INV_SECURITY_KEY )
  8585. {//security keys are pulled with less enthusiasm
  8586. if ( knockback > 100 )
  8587. {
  8588. knockback = 100;
  8589. }
  8590. }
  8591. else if ( knockback > 200 )
  8592. {
  8593. knockback = 200;
  8594. }
  8595. }
  8596. else
  8597. {
  8598. if ( self->enemy //I have an enemy
  8599. && push_list[x]->s.eType != ET_ITEM //not an item
  8600. && self->client->ps.forcePowerLevel[FP_PUSH] > FORCE_LEVEL_2 //have push 3 or greater
  8601. && InFront(push_list[x]->currentOrigin, self->currentOrigin, self->currentAngles, 0.25f)//object is generally in front of me
  8602. && InFront(self->enemy->currentOrigin, self->currentOrigin, self->currentAngles, 0.75f)//enemy is pretty much right in front of me
  8603. && InFront(push_list[x]->currentOrigin, self->enemy->currentOrigin, self->enemy->currentAngles, 0.25f)//object is generally in front of enemy
  8604. //FIXME: check dist to enemy and clear LOS to enemy and clear Path between object and enemy?
  8605. && ( (self->NPC&&(noResist||Q_irand(0,RANK_CAPTAIN)<self->NPC->rank) )//NPC with enough skill
  8606. ||( self->s.number<MAX_CLIENTS ) )
  8607. )
  8608. {//if I have an auto-enemy & he's in front of me, push it toward him!
  8609. /*
  8610. if ( targetedObjectMassTotal + push_list[x]->mass > TARGETED_OBJECT_PUSH_MASS_MAX )
  8611. {//already pushed too many things
  8612. //FIXME: pick closest?
  8613. continue;
  8614. }
  8615. targetedObjectMassTotal += push_list[x]->mass;
  8616. */
  8617. VectorSubtract( self->enemy->currentOrigin, push_list[x]->currentOrigin, pushDir );
  8618. }
  8619. else
  8620. {
  8621. VectorSubtract( push_list[x]->currentOrigin, self->currentOrigin, pushDir );
  8622. }
  8623. knockback -= VectorNormalize( pushDir );
  8624. if ( knockback < 100 )
  8625. {
  8626. knockback = 100;
  8627. }
  8628. }
  8629. //FIXME: if pull a FL_FORCE_PULLABLE_ONLY, clear the flag, assuming it's no longer in solid? or check?
  8630. VectorCopy( push_list[x]->currentOrigin, push_list[x]->s.pos.trBase );
  8631. push_list[x]->s.pos.trTime = level.time; // move a bit on the very first frame
  8632. if ( push_list[x]->s.pos.trType != TR_INTERPOLATE )
  8633. {//don't do this to rolling missiles
  8634. push_list[x]->s.pos.trType = TR_GRAVITY;
  8635. }
  8636. if ( push_list[x]->e_ThinkFunc == thinkF_G_RunObject && push_list[x]->physicsBounce )
  8637. {//it's a pushable misc_model_breakable, use it's mass instead of our one-size-fits-all mass
  8638. mass = push_list[x]->physicsBounce;//same as push_list[x]->mass, right?
  8639. }
  8640. if ( mass < 50 )
  8641. {//???
  8642. mass = 50;
  8643. }
  8644. if ( g_gravity->value > 0 )
  8645. {
  8646. VectorScale( pushDir, g_knockback->value * knockback / mass * 0.8, kvel );
  8647. kvel[2] = pushDir[2] * g_knockback->value * knockback / mass * 1.5;
  8648. }
  8649. else
  8650. {
  8651. VectorScale( pushDir, g_knockback->value * knockback / mass, kvel );
  8652. }
  8653. VectorAdd( push_list[x]->s.pos.trDelta, kvel, push_list[x]->s.pos.trDelta );
  8654. if ( g_gravity->value > 0 )
  8655. {
  8656. if ( push_list[x]->s.pos.trDelta[2] < knockback )
  8657. {
  8658. push_list[x]->s.pos.trDelta[2] = knockback;
  8659. }
  8660. }
  8661. //no trDuration?
  8662. if ( push_list[x]->e_ThinkFunc != thinkF_G_RunObject )
  8663. {//objects spin themselves?
  8664. //spin it
  8665. //FIXME: messing with roll ruins the rotational center???
  8666. push_list[x]->s.apos.trTime = level.time;
  8667. push_list[x]->s.apos.trType = TR_LINEAR;
  8668. VectorClear( push_list[x]->s.apos.trDelta );
  8669. push_list[x]->s.apos.trDelta[1] = Q_irand( -800, 800 );
  8670. }
  8671. if ( Q_stricmp( "limb", push_list[x]->classname ) == 0 )
  8672. {//make sure it runs it's physics
  8673. push_list[x]->e_ThinkFunc = thinkF_LimbThink;
  8674. push_list[x]->nextthink = level.time + FRAMETIME;
  8675. }
  8676. push_list[x]->forcePushTime = level.time + 600; // let the push effect last for 600 ms
  8677. push_list[x]->forcePuller = self->s.number;//remember this regardless
  8678. if ( push_list[x]->item && push_list[x]->item->giTag == INV_SECURITY_KEY )
  8679. {
  8680. AddSightEvent( player, push_list[x]->currentOrigin, 128, AEL_DISCOVERED );//security keys are more important
  8681. }
  8682. else
  8683. {
  8684. AddSightEvent( player, push_list[x]->currentOrigin, 128, AEL_SUSPICIOUS );//hmm... or should this always be discovered?
  8685. }
  8686. }
  8687. else if ( push_list[x]->s.weapon == WP_TURRET
  8688. && !Q_stricmp( "PAS", push_list[x]->classname )
  8689. && push_list[x]->s.apos.trType == TR_STATIONARY )
  8690. {//a portable turret
  8691. WP_KnockdownTurret( self, push_list[x] );
  8692. }
  8693. }
  8694. }
  8695. if ( pull )
  8696. {
  8697. if ( self->client->ps.forcePowerLevel[FP_PULL] > FORCE_LEVEL_2 )
  8698. {//at level 3, can pull multiple, so it costs more
  8699. actualCost = forcePowerNeeded[FP_PULL]*ent_count;
  8700. if ( actualCost > 50 )
  8701. {
  8702. actualCost = 50;
  8703. }
  8704. else if ( actualCost < cost )
  8705. {
  8706. actualCost = cost;
  8707. }
  8708. }
  8709. else
  8710. {
  8711. actualCost = cost;
  8712. }
  8713. WP_ForcePowerStart( self, FP_PULL, actualCost );
  8714. }
  8715. else
  8716. {
  8717. if ( self->client->ps.forcePowerLevel[FP_PUSH] > FORCE_LEVEL_2 )
  8718. {//at level 3, can push multiple, so costs more
  8719. actualCost = forcePowerNeeded[FP_PUSH]*ent_count;
  8720. if ( actualCost > 50 )
  8721. {
  8722. actualCost = 50;
  8723. }
  8724. else if ( actualCost < cost )
  8725. {
  8726. actualCost = cost;
  8727. }
  8728. }
  8729. else if ( self->client->ps.forcePowerLevel[FP_PUSH] > FORCE_LEVEL_1 )
  8730. {//at level 2, can push multiple, so costs more
  8731. actualCost = floor(forcePowerNeeded[FP_PUSH]*ent_count/1.5f);
  8732. if ( actualCost > 50 )
  8733. {
  8734. actualCost = 50;
  8735. }
  8736. else if ( actualCost < cost )
  8737. {
  8738. actualCost = cost;
  8739. }
  8740. }
  8741. else
  8742. {
  8743. actualCost = cost;
  8744. }
  8745. WP_ForcePowerStart( self, FP_PUSH, actualCost );
  8746. }
  8747. }
  8748. else
  8749. {//didn't push or pull anything? don't penalize them too much
  8750. if ( pull )
  8751. {
  8752. WP_ForcePowerStart( self, FP_PULL, 5 );
  8753. }
  8754. else
  8755. {
  8756. WP_ForcePowerStart( self, FP_PUSH, 5 );
  8757. }
  8758. }
  8759. if ( pull )
  8760. {
  8761. if ( self->NPC )
  8762. {//NPCs can push more often
  8763. //FIXME: vary by rank and game skill?
  8764. self->client->ps.forcePowerDebounce[FP_PULL] = level.time + 200;
  8765. }
  8766. else
  8767. {
  8768. self->client->ps.forcePowerDebounce[FP_PULL] = level.time + self->client->ps.torsoAnimTimer + 500;
  8769. }
  8770. }
  8771. else
  8772. {
  8773. if ( self->NPC )
  8774. {//NPCs can push more often
  8775. //FIXME: vary by rank and game skill?
  8776. self->client->ps.forcePowerDebounce[FP_PUSH] = level.time + 200;
  8777. }
  8778. else
  8779. {
  8780. self->client->ps.forcePowerDebounce[FP_PUSH] = level.time + self->client->ps.torsoAnimTimer + 500;
  8781. }
  8782. }
  8783. }
  8784. void WP_DebounceForceDeactivateTime( gentity_t *self )
  8785. {
  8786. //FIXME: if these are interruptable, should they also drain power at a constant rate
  8787. // rather than just taking one lump sum of force power upfront?
  8788. if ( self && self->client )
  8789. {
  8790. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED)
  8791. || self->client->ps.forcePowersActive&(1<<FP_PROTECT)
  8792. || self->client->ps.forcePowersActive&(1<<FP_ABSORB)
  8793. || self->client->ps.forcePowersActive&(1<<FP_RAGE)
  8794. || self->client->ps.forcePowersActive&(1<<FP_SEE) )
  8795. {//already running another power that can be manually, stopped don't debounce so long
  8796. self->client->ps.forceAllowDeactivateTime = level.time + 500;
  8797. }
  8798. else
  8799. {//not running one of the interruptable powers
  8800. //FIXME: this should be shorter for force speed and rage (because of timescaling)
  8801. self->client->ps.forceAllowDeactivateTime = level.time + 1500;
  8802. }
  8803. }
  8804. }
  8805. void ForceSpeed( gentity_t *self, int duration )
  8806. {
  8807. if ( self->health <= 0 )
  8808. {
  8809. return;
  8810. }
  8811. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  8812. (self->client->ps.forcePowersActive & (1 << FP_SPEED)) )
  8813. {//stop using it
  8814. WP_ForcePowerStop( self, FP_SPEED );
  8815. return;
  8816. }
  8817. if ( !WP_ForcePowerUsable( self, FP_SPEED, 0 ) )
  8818. {
  8819. return;
  8820. }
  8821. if ( self->client->ps.saberLockTime > level.time )
  8822. {//FIXME: can this be a way to break out?
  8823. return;
  8824. }
  8825. WP_DebounceForceDeactivateTime( self );
  8826. WP_ForcePowerStart( self, FP_SPEED, 0 );
  8827. if ( duration )
  8828. {
  8829. self->client->ps.forcePowerDuration[FP_SPEED] = level.time + duration;
  8830. }
  8831. G_Sound( self, G_SoundIndex( "sound/weapons/force/speed.wav" ) );
  8832. #ifdef _IMMERSION
  8833. G_Force( self, G_ForceIndex( "fffx/weapons/force/speed", FF_CHANNEL_WEAPON ) );
  8834. #endif // _IMMERSION
  8835. }
  8836. void WP_StartForceHealEffects( gentity_t *self )
  8837. {
  8838. if ( self->ghoul2.size() )
  8839. {
  8840. if ( self->chestBolt != -1 )
  8841. {
  8842. G_PlayEffect( G_EffectIndex( "force/heal2" ), self->playerModel, self->chestBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8843. }
  8844. /*
  8845. if ( self->headBolt != -1 )
  8846. {
  8847. G_PlayEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->headBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8848. }
  8849. if ( self->cervicalBolt != -1 )
  8850. {
  8851. G_PlayEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->cervicalBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8852. }
  8853. if ( self->chestBolt != -1 )
  8854. {
  8855. G_PlayEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->chestBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8856. }
  8857. if ( self->gutBolt != -1 )
  8858. {
  8859. G_PlayEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->gutBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8860. }
  8861. if ( self->kneeLBolt != -1 )
  8862. {
  8863. G_PlayEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->kneeLBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8864. }
  8865. if ( self->kneeRBolt != -1 )
  8866. {
  8867. G_PlayEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->kneeRBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8868. }
  8869. if ( self->elbowLBolt != -1 )
  8870. {
  8871. G_PlayEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->elbowLBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8872. }
  8873. if ( self->elbowRBolt != -1 )
  8874. {
  8875. G_PlayEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->elbowRBolt, self->s.number, self->currentOrigin, 3000, qtrue );
  8876. }
  8877. */
  8878. }
  8879. }
  8880. void WP_StopForceHealEffects( gentity_t *self )
  8881. {
  8882. if ( self->ghoul2.size() )
  8883. {
  8884. if ( self->chestBolt != -1 )
  8885. {
  8886. G_StopEffect( G_EffectIndex( "force/heal2" ), self->playerModel, self->chestBolt, self->s.number );
  8887. }
  8888. /*
  8889. if ( self->headBolt != -1 )
  8890. {
  8891. G_StopEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->headBolt, self->s.number );
  8892. }
  8893. if ( self->cervicalBolt != -1 )
  8894. {
  8895. G_StopEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->cervicalBolt, self->s.number );
  8896. }
  8897. if ( self->chestBolt != -1 )
  8898. {
  8899. G_StopEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->chestBolt, self->s.number );
  8900. }
  8901. if ( self->gutBolt != -1 )
  8902. {
  8903. G_StopEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->gutBolt, self->s.number );
  8904. }
  8905. if ( self->kneeLBolt != -1 )
  8906. {
  8907. G_StopEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->kneeLBolt, self->s.number );
  8908. }
  8909. if ( self->kneeRBolt != -1 )
  8910. {
  8911. G_StopEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->kneeRBolt, self->s.number );
  8912. }
  8913. if ( self->elbowLBolt != -1 )
  8914. {
  8915. G_StopEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->elbowLBolt, self->s.number );
  8916. }
  8917. if ( self->elbowRBolt != -1 )
  8918. {
  8919. G_StopEffect( G_EffectIndex( "force/heal_joint" ), self->playerModel, self->elbowRBolt, self->s.number );
  8920. }
  8921. */
  8922. }
  8923. }
  8924. int FP_MaxForceHeal( gentity_t *self )
  8925. {
  8926. if ( self->s.number >= MAX_CLIENTS )
  8927. {
  8928. return MAX_FORCE_HEAL_HARD;
  8929. }
  8930. switch ( g_spskill->integer )
  8931. {
  8932. case 0://easy
  8933. return MAX_FORCE_HEAL_EASY;
  8934. break;
  8935. case 1://medium
  8936. return MAX_FORCE_HEAL_MEDIUM;
  8937. break;
  8938. case 2://hard
  8939. default:
  8940. return MAX_FORCE_HEAL_HARD;
  8941. break;
  8942. }
  8943. }
  8944. int FP_ForceHealInterval( gentity_t *self )
  8945. {
  8946. return (self->client->ps.forcePowerLevel[FP_HEAL]>FORCE_LEVEL_2)?50:FORCE_HEAL_INTERVAL;
  8947. }
  8948. void ForceHeal( gentity_t *self )
  8949. {
  8950. if ( self->health <= 0 || self->client->ps.stats[STAT_MAX_HEALTH] <= self->health )
  8951. {
  8952. return;
  8953. }
  8954. if ( !WP_ForcePowerUsable( self, FP_HEAL, 20 ) )
  8955. {//must have enough force power for at least 5 points of health
  8956. return;
  8957. }
  8958. if ( self->painDebounceTime > level.time || (self->client->ps.weaponTime&&self->client->ps.weapon!=WP_NONE) )
  8959. {//can't initiate a heal while taking pain or attacking
  8960. return;
  8961. }
  8962. if ( self->client->ps.saberLockTime > level.time )
  8963. {//FIXME: can this be a way to break out?
  8964. return;
  8965. }
  8966. /*
  8967. if ( self->client->ps.forcePowerLevel[FP_HEAL] > FORCE_LEVEL_2 )
  8968. {//instant heal
  8969. //no more than available force power
  8970. int max = self->client->ps.forcePower;
  8971. if ( max > MAX_FORCE_HEAL )
  8972. {//no more than max allowed
  8973. max = MAX_FORCE_HEAL;
  8974. }
  8975. if ( max > self->client->ps.stats[STAT_MAX_HEALTH] - self->health )
  8976. {//no more than what's missing
  8977. max = self->client->ps.stats[STAT_MAX_HEALTH] - self->health;
  8978. }
  8979. self->health += max;
  8980. WP_ForcePowerDrain( self, FP_HEAL, max );
  8981. G_SoundOnEnt( self, CHAN_VOICE, va( "sound/weapons/force/heal%d.mp3", Q_irand( 1, 4 ) ) );
  8982. }
  8983. else
  8984. */
  8985. {
  8986. //start health going up
  8987. //NPC_SetAnim( self, SETANIM_TORSO, ?, SETANIM_FLAG_OVERRIDE );
  8988. WP_ForcePowerStart( self, FP_HEAL, 0 );
  8989. if ( self->client->ps.forcePowerLevel[FP_HEAL] < FORCE_LEVEL_2 )
  8990. {//must meditate
  8991. //FIXME: holster weapon (select WP_NONE?)
  8992. //FIXME: BOTH_FORCEHEAL_START
  8993. NPC_SetAnim( self, SETANIM_BOTH, BOTH_FORCEHEAL_START, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  8994. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  8995. self->client->ps.saberBlocked = BLOCKED_NONE;
  8996. self->client->ps.torsoAnimTimer = self->client->ps.legsAnimTimer = FP_ForceHealInterval(self)*FP_MaxForceHeal(self) + 2000;//???
  8997. WP_DeactivateSaber( self );//turn off saber when meditating
  8998. }
  8999. else
  9000. {//just a quick gesture
  9001. /*
  9002. //Can't get an anim that looks good...
  9003. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCEHEAL_QUICK, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9004. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  9005. self->client->ps.saberBlocked = BLOCKED_NONE;
  9006. */
  9007. }
  9008. }
  9009. //FIXME: always play healing effect
  9010. G_SoundOnEnt( self, CHAN_ITEM, "sound/weapons/force/heal.mp3" );
  9011. #ifdef _IMMERSION
  9012. G_Force( self, G_ForceIndex( "fffx/weapons/force/heal", FF_CHANNEL_WEAPON ) );
  9013. #endif // _IMMERSION
  9014. }
  9015. extern void NPC_PlayConfusionSound( gentity_t *self );
  9016. extern void NPC_Jedi_PlayConfusionSound( gentity_t *self );
  9017. qboolean WP_CheckBreakControl( gentity_t *self )
  9018. {
  9019. if ( !self )
  9020. {
  9021. return qfalse;
  9022. }
  9023. if ( !self->s.number )
  9024. {//player
  9025. if ( self->client && self->client->ps.forcePowerLevel[FP_TELEPATHY] > FORCE_LEVEL_3 )
  9026. {//control-level
  9027. if ( self->client->ps.viewEntity > 0 && self->client->ps.viewEntity < ENTITYNUM_WORLD )
  9028. {//we are in a viewentity
  9029. gentity_t *controlled = &g_entities[self->client->ps.viewEntity];
  9030. if ( controlled->NPC && controlled->NPC->controlledTime > level.time )
  9031. {//it is an NPC we controlled
  9032. //clear it and return
  9033. G_ClearViewEntity( self );
  9034. return qtrue;
  9035. }
  9036. }
  9037. }
  9038. }
  9039. else
  9040. {//NPC
  9041. if ( self->NPC && self->NPC->controlledTime > level.time )
  9042. {//being controlled
  9043. gentity_t *controller = &g_entities[0];
  9044. if ( controller->client && controller->client->ps.viewEntity == self->s.number )
  9045. {//we are being controlled by player
  9046. if ( controller->client->ps.forcePowerLevel[FP_TELEPATHY] > FORCE_LEVEL_3 )
  9047. {//control-level mind trick
  9048. //clear the control and return
  9049. G_ClearViewEntity( controller );
  9050. return qtrue;
  9051. }
  9052. }
  9053. }
  9054. }
  9055. return qfalse;
  9056. }
  9057. extern bool Pilot_AnyVehiclesRegistered();
  9058. void ForceTelepathy( gentity_t *self )
  9059. {
  9060. trace_t tr;
  9061. vec3_t end, forward;
  9062. gentity_t *traceEnt;
  9063. qboolean targetLive = qfalse;
  9064. if ( WP_CheckBreakControl( self ) )
  9065. {
  9066. return;
  9067. }
  9068. if ( self->health <= 0 )
  9069. {
  9070. return;
  9071. }
  9072. //FIXME: if mind trick 3 and aiming at an enemy need more force power
  9073. if ( !WP_ForcePowerUsable( self, FP_TELEPATHY, 0 ) )
  9074. {
  9075. return;
  9076. }
  9077. if ( self->client->ps.weaponTime >= 800 )
  9078. {//just did one!
  9079. return;
  9080. }
  9081. if ( self->client->ps.saberLockTime > level.time )
  9082. {//FIXME: can this be a way to break out?
  9083. return;
  9084. }
  9085. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  9086. VectorNormalize( forward );
  9087. VectorMA( self->client->renderInfo.eyePoint, 2048, forward, end );
  9088. //Cause a distraction if enemy is not fighting
  9089. gi.trace( &tr, self->client->renderInfo.eyePoint, vec3_origin, vec3_origin, end, self->s.number, MASK_OPAQUE|CONTENTS_BODY );
  9090. if ( tr.entityNum == ENTITYNUM_NONE || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  9091. {
  9092. return;
  9093. }
  9094. traceEnt = &g_entities[tr.entityNum];
  9095. if( traceEnt->NPC && traceEnt->NPC->scriptFlags & SCF_NO_FORCE )
  9096. {
  9097. return;
  9098. }
  9099. if ( traceEnt && traceEnt->client )
  9100. {
  9101. switch ( traceEnt->client->NPC_class )
  9102. {
  9103. case CLASS_GALAKMECH://cant grip him, he's in armor
  9104. case CLASS_ATST://much too big to grip!
  9105. //no droids either
  9106. case CLASS_PROBE:
  9107. case CLASS_GONK:
  9108. case CLASS_R2D2:
  9109. case CLASS_R5D2:
  9110. case CLASS_MARK1:
  9111. case CLASS_MARK2:
  9112. case CLASS_MOUSE:
  9113. case CLASS_SEEKER:
  9114. case CLASS_REMOTE:
  9115. case CLASS_PROTOCOL:
  9116. case CLASS_ASSASSIN_DROID:
  9117. case CLASS_SABER_DROID:
  9118. case CLASS_BOBAFETT:
  9119. break;
  9120. case CLASS_RANCOR:
  9121. if ( !(traceEnt->spawnflags&1) )
  9122. {
  9123. targetLive = qtrue;
  9124. }
  9125. break;
  9126. default:
  9127. targetLive = qtrue;
  9128. break;
  9129. }
  9130. }
  9131. if ( targetLive
  9132. && traceEnt->NPC
  9133. && traceEnt->health > 0 )
  9134. {//hit an organic non-player
  9135. if ( G_ActivateBehavior( traceEnt, BSET_MINDTRICK ) )
  9136. {//activated a script on him
  9137. //FIXME: do the visual sparkles effect on their heads, still?
  9138. WP_ForcePowerStart( self, FP_TELEPATHY, 0 );
  9139. }
  9140. else if ( traceEnt->client->playerTeam != self->client->playerTeam )
  9141. {//an enemy
  9142. int override = 0;
  9143. if ( (traceEnt->NPC->scriptFlags&SCF_NO_MIND_TRICK) )
  9144. {
  9145. if ( traceEnt->client->NPC_class == CLASS_GALAKMECH )
  9146. {
  9147. G_AddVoiceEvent( traceEnt, Q_irand( EV_CONFUSE1, EV_CONFUSE3 ), Q_irand( 3000, 5000 ) );
  9148. }
  9149. }
  9150. else if ( self->client->ps.forcePowerLevel[FP_TELEPATHY] > FORCE_LEVEL_3 )
  9151. {//control them, even jedi
  9152. G_SetViewEntity( self, traceEnt );
  9153. traceEnt->NPC->controlledTime = level.time + 30000;
  9154. }
  9155. else if ( traceEnt->s.weapon != WP_SABER
  9156. && traceEnt->client->NPC_class != CLASS_REBORN )
  9157. {//haha! Jedi aren't easily confused!
  9158. if ( self->client->ps.forcePowerLevel[FP_TELEPATHY] > FORCE_LEVEL_2
  9159. && traceEnt->s.weapon != WP_NONE //don't charm people who aren't capable of fighting... like ugnaughts and droids, just confuse them
  9160. && traceEnt->client->NPC_class != CLASS_TUSKEN//don't charm them, just confuse them
  9161. && traceEnt->client->NPC_class != CLASS_NOGHRI//don't charm them, just confuse them
  9162. && !Pilot_AnyVehiclesRegistered() //also, don't charm guys when bikes are near
  9163. )
  9164. {//turn them to our side
  9165. //if mind trick 3 and aiming at an enemy need more force power
  9166. override = 50;
  9167. if ( self->client->ps.forcePower < 50 )
  9168. {
  9169. return;
  9170. }
  9171. if ( traceEnt->enemy )
  9172. {
  9173. G_ClearEnemy( traceEnt );
  9174. }
  9175. if ( traceEnt->NPC )
  9176. {
  9177. //traceEnt->NPC->tempBehavior = BS_FOLLOW_LEADER;
  9178. traceEnt->client->leader = self;
  9179. }
  9180. //FIXME: maybe pick an enemy right here?
  9181. //FIXME: does nothing to TEAM_FREE and TEAM_NEUTRALs!!!
  9182. team_t saveTeam = traceEnt->client->enemyTeam;
  9183. traceEnt->client->enemyTeam = traceEnt->client->playerTeam;
  9184. traceEnt->client->playerTeam = saveTeam;
  9185. //FIXME: need a *charmed* timer on this...? Or do TEAM_PLAYERS assume that "confusion" means they should switch to team_enemy when done?
  9186. traceEnt->NPC->charmedTime = level.time + mindTrickTime[self->client->ps.forcePowerLevel[FP_TELEPATHY]];
  9187. if ( traceEnt->ghoul2.size() && traceEnt->headBolt != -1 )
  9188. {//FIXME: what if already playing effect?
  9189. G_PlayEffect( G_EffectIndex( "force/confusion" ), traceEnt->playerModel, traceEnt->headBolt, traceEnt->s.number, traceEnt->currentOrigin, mindTrickTime[self->client->ps.forcePowerLevel[FP_TELEPATHY]], qtrue );
  9190. }
  9191. }
  9192. else
  9193. {//just confuse them
  9194. //somehow confuse them? Set don't fire to true for a while? Drop their aggression? Maybe just take their enemy away and don't let them pick one up for a while unless shot?
  9195. traceEnt->NPC->confusionTime = level.time + mindTrickTime[self->client->ps.forcePowerLevel[FP_TELEPATHY]];//confused for about 10 seconds
  9196. if ( traceEnt->ghoul2.size() && traceEnt->headBolt != -1 )
  9197. {//FIXME: what if already playing effect?
  9198. G_PlayEffect( G_EffectIndex( "force/confusion" ), traceEnt->playerModel, traceEnt->headBolt, traceEnt->s.number, traceEnt->currentOrigin, mindTrickTime[self->client->ps.forcePowerLevel[FP_TELEPATHY]], qtrue );
  9199. }
  9200. NPC_PlayConfusionSound( traceEnt );
  9201. if ( traceEnt->enemy )
  9202. {
  9203. G_ClearEnemy( traceEnt );
  9204. }
  9205. }
  9206. }
  9207. else
  9208. {
  9209. NPC_Jedi_PlayConfusionSound( traceEnt );
  9210. }
  9211. WP_ForcePowerStart( self, FP_TELEPATHY, override );
  9212. }
  9213. else if ( traceEnt->client->playerTeam == self->client->playerTeam )
  9214. {//an ally
  9215. //maybe just have him look at you? Respond? Take your enemy?
  9216. if ( traceEnt->client->ps.pm_type < PM_DEAD && traceEnt->NPC!=NULL && !(traceEnt->NPC->scriptFlags&SCF_NO_RESPONSE) )
  9217. {
  9218. NPC_UseResponse( traceEnt, self, qfalse );
  9219. WP_ForcePowerStart( self, FP_TELEPATHY, 1 );
  9220. }
  9221. }//NOTE: no effect on TEAM_NEUTRAL?
  9222. vec3_t eyeDir;
  9223. AngleVectors( traceEnt->client->renderInfo.eyeAngles, eyeDir, NULL, NULL );
  9224. VectorNormalize( eyeDir );
  9225. G_PlayEffect( "force/force_touch", traceEnt->client->renderInfo.eyePoint, eyeDir );
  9226. //make sure this plays and that you cannot press fire for about 1 second after this
  9227. //FIXME: BOTH_FORCEMINDTRICK or BOTH_FORCEDISTRACT
  9228. NPC_SetAnim( self, SETANIM_TORSO, BOTH_MINDTRICK1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_RESTART|SETANIM_FLAG_HOLD );
  9229. //FIXME: build-up or delay this until in proper part of anim
  9230. }
  9231. else
  9232. {
  9233. if ( self->client->ps.forcePowerLevel[FP_TELEPATHY] > FORCE_LEVEL_1 && tr.fraction * 2048 > 64 )
  9234. {//don't create a diversion less than 64 from you of if at power level 1
  9235. //use distraction anim instead
  9236. G_PlayEffect( G_EffectIndex( "force/force_touch" ), tr.endpos, tr.plane.normal );
  9237. //FIXME: these events don't seem to always be picked up...?
  9238. AddSoundEvent( self, tr.endpos, 512, AEL_SUSPICIOUS, qtrue, qtrue );
  9239. AddSightEvent( self, tr.endpos, 512, AEL_SUSPICIOUS, 50 );
  9240. WP_ForcePowerStart( self, FP_TELEPATHY, 0 );
  9241. }
  9242. NPC_SetAnim( self, SETANIM_TORSO, BOTH_MINDTRICK2, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_RESTART|SETANIM_FLAG_HOLD );
  9243. }
  9244. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  9245. self->client->ps.saberBlocked = BLOCKED_NONE;
  9246. self->client->ps.weaponTime = 1000;
  9247. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  9248. {
  9249. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  9250. }
  9251. }
  9252. //rww - RAGDOLL_BEGIN
  9253. //#define JK2_RAGDOLL_GRIPNOHEALTH
  9254. //rww - RAGDOLL_END
  9255. void ForceGrip( gentity_t *self )
  9256. {//FIXME: make enemy Jedi able to use this
  9257. trace_t tr;
  9258. vec3_t end, forward;
  9259. gentity_t *traceEnt = NULL;
  9260. if ( self->health <= 0 )
  9261. {
  9262. return;
  9263. }
  9264. if ( !self->s.number && (cg.zoomMode || in_camera) )
  9265. {//can't force grip when zoomed in or in cinematic
  9266. return;
  9267. }
  9268. if ( self->client->ps.leanofs )
  9269. {//can't force-grip while leaning
  9270. return;
  9271. }
  9272. if ( self->client->ps.forceGripEntityNum <= ENTITYNUM_WORLD )
  9273. {//already gripping
  9274. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 )
  9275. {
  9276. self->client->ps.forcePowerDuration[FP_GRIP] = level.time + 100;
  9277. self->client->ps.weaponTime = 1000;
  9278. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  9279. {
  9280. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  9281. }
  9282. }
  9283. return;
  9284. }
  9285. if ( !WP_ForcePowerUsable( self, FP_GRIP, 0 ) )
  9286. {//can't use it right now
  9287. return;
  9288. }
  9289. if ( self->client->ps.forcePower < 26 )
  9290. {//need 20 to start, 6 to hold it for any decent amount of time...
  9291. return;
  9292. }
  9293. if ( self->client->ps.weaponTime )
  9294. {//busy
  9295. return;
  9296. }
  9297. if ( self->client->ps.saberLockTime > level.time )
  9298. {//FIXME: can this be a way to break out?
  9299. return;
  9300. }
  9301. //Cause choking anim + health drain in ent in front of me
  9302. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCEGRIP_HOLD, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9303. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  9304. self->client->ps.saberBlocked = BLOCKED_NONE;
  9305. self->client->ps.weaponTime = 1000;
  9306. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  9307. {
  9308. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  9309. }
  9310. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  9311. VectorNormalize( forward );
  9312. VectorMA( self->client->renderInfo.handLPoint, FORCE_GRIP_DIST, forward, end );
  9313. if ( self->enemy )
  9314. {//I have an enemy
  9315. if ( !self->enemy->message
  9316. && !(self->flags&FL_NO_KNOCKBACK) )
  9317. {//don't auto-pickup guys with keys
  9318. if ( DistanceSquared( self->enemy->currentOrigin, self->currentOrigin ) < FORCE_GRIP_DIST_SQUARED )
  9319. {//close enough to grab
  9320. float minDot = 0.5f;
  9321. if ( self->s.number < MAX_CLIENTS )
  9322. {//player needs to be facing more directly
  9323. minDot = 0.2f;
  9324. }
  9325. if ( InFront( self->enemy->currentOrigin, self->client->renderInfo.eyePoint, self->client->ps.viewangles, minDot ) ) //self->s.number || //NPCs can always lift enemy since we assume they're looking at them...?
  9326. {//need to be facing the enemy
  9327. if ( gi.inPVS( self->enemy->currentOrigin, self->client->renderInfo.eyePoint ) )
  9328. {//must be in PVS
  9329. gi.trace( &tr, self->client->renderInfo.eyePoint, vec3_origin, vec3_origin, self->enemy->currentOrigin, self->s.number, MASK_SHOT );
  9330. if ( tr.fraction == 1.0f || tr.entityNum == self->enemy->s.number )
  9331. {//must have clear LOS
  9332. traceEnt = self->enemy;
  9333. }
  9334. }
  9335. }
  9336. }
  9337. }
  9338. }
  9339. if ( !traceEnt )
  9340. {//okay, trace straight ahead and see what's there
  9341. gi.trace( &tr, self->client->renderInfo.handLPoint, vec3_origin, vec3_origin, end, self->s.number, MASK_SHOT );
  9342. if ( tr.entityNum >= ENTITYNUM_WORLD || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  9343. {
  9344. return;
  9345. }
  9346. traceEnt = &g_entities[tr.entityNum];
  9347. }
  9348. //rww - RAGDOLL_BEGIN
  9349. #ifdef JK2_RAGDOLL_GRIPNOHEALTH
  9350. if ( !traceEnt || traceEnt == self/*???*/ || traceEnt->bmodel || (traceEnt->NPC && traceEnt->NPC->scriptFlags & SCF_NO_FORCE) )
  9351. {
  9352. return;
  9353. }
  9354. #else
  9355. //rww - RAGDOLL_END
  9356. if ( !traceEnt || traceEnt == self/*???*/ || traceEnt->bmodel || (traceEnt->health <= 0 && traceEnt->takedamage) || (traceEnt->NPC && traceEnt->NPC->scriptFlags & SCF_NO_FORCE) )
  9357. {
  9358. return;
  9359. }
  9360. //rww - RAGDOLL_BEGIN
  9361. #endif
  9362. //rww - RAGDOLL_END
  9363. if ( traceEnt->m_pVehicle != NULL )
  9364. {//is it a vehicle
  9365. //grab pilot if there is one
  9366. if ( traceEnt->m_pVehicle->m_pPilot != NULL
  9367. && traceEnt->m_pVehicle->m_pPilot->client != NULL )
  9368. {//grip the pilot
  9369. traceEnt = traceEnt->m_pVehicle->m_pPilot;
  9370. }
  9371. else
  9372. {//can't grip a vehicle
  9373. return;
  9374. }
  9375. }
  9376. if ( traceEnt->client )
  9377. {
  9378. if ( traceEnt->client->ps.forceJumpZStart )
  9379. {//can't catch them in mid force jump - FIXME: maybe base it on velocity?
  9380. return;
  9381. }
  9382. if ( traceEnt->client->ps.pullAttackTime > level.time )
  9383. {//can't grip someone who is being pull-attacked or is pull-attacking
  9384. return;
  9385. }
  9386. if ( !Q_stricmp("Yoda",traceEnt->NPC_type) )
  9387. {
  9388. Jedi_PlayDeflectSound( traceEnt );
  9389. ForceThrow( traceEnt, qfalse );
  9390. return;
  9391. }
  9392. if ( G_IsRidingVehicle( traceEnt )
  9393. && (traceEnt->s.eFlags&EF_NODRAW) )
  9394. {//riding *inside* vehicle
  9395. return;
  9396. }
  9397. switch ( traceEnt->client->NPC_class )
  9398. {
  9399. case CLASS_GALAKMECH://cant grip him, he's in armor
  9400. G_AddVoiceEvent( traceEnt, Q_irand(EV_PUSHED1, EV_PUSHED3), Q_irand( 3000, 5000 ) );
  9401. return;
  9402. break;
  9403. case CLASS_HAZARD_TROOPER://cant grip him, he's in armor
  9404. return;
  9405. break;
  9406. case CLASS_ATST://much too big to grip!
  9407. case CLASS_RANCOR://much too big to grip!
  9408. case CLASS_WAMPA://much too big to grip!
  9409. case CLASS_SAND_CREATURE://much too big to grip!
  9410. return;
  9411. break;
  9412. //no droids either...?
  9413. case CLASS_GONK:
  9414. case CLASS_R2D2:
  9415. case CLASS_R5D2:
  9416. case CLASS_MARK1:
  9417. case CLASS_MARK2:
  9418. case CLASS_MOUSE://?
  9419. case CLASS_PROTOCOL:
  9420. //*sigh*... in JK3, you'll be able to grab and move *anything*...
  9421. return;
  9422. break;
  9423. //not even combat droids? (No animation for being gripped...)
  9424. case CLASS_SABER_DROID:
  9425. case CLASS_ASSASSIN_DROID:
  9426. //*sigh*... in JK3, you'll be able to grab and move *anything*...
  9427. return;
  9428. break;
  9429. case CLASS_PROBE:
  9430. case CLASS_SEEKER:
  9431. case CLASS_REMOTE:
  9432. case CLASS_SENTRY:
  9433. case CLASS_INTERROGATOR:
  9434. //*sigh*... in JK3, you'll be able to grab and move *anything*...
  9435. return;
  9436. break;
  9437. case CLASS_DESANN://Desann cannot be gripped, he just pushes you back instantly
  9438. case CLASS_KYLE:
  9439. case CLASS_TAVION:
  9440. case CLASS_LUKE:
  9441. Jedi_PlayDeflectSound( traceEnt );
  9442. ForceThrow( traceEnt, qfalse );
  9443. return;
  9444. break;
  9445. case CLASS_REBORN:
  9446. case CLASS_SHADOWTROOPER:
  9447. case CLASS_ALORA:
  9448. case CLASS_JEDI:
  9449. if ( traceEnt->NPC && traceEnt->NPC->rank > RANK_CIVILIAN && self->client->ps.forcePowerLevel[FP_GRIP] < FORCE_LEVEL_2 )
  9450. {
  9451. Jedi_PlayDeflectSound( traceEnt );
  9452. ForceThrow( traceEnt, qfalse );
  9453. return;
  9454. }
  9455. break;
  9456. }
  9457. if ( traceEnt->s.weapon == WP_EMPLACED_GUN )
  9458. {//FIXME: maybe can pull them out?
  9459. return;
  9460. }
  9461. if ( self->enemy && traceEnt != self->enemy && traceEnt->client->playerTeam == self->client->playerTeam )
  9462. {//can't accidently grip your teammate in combat
  9463. return;
  9464. }
  9465. //=CHECKABSORB===
  9466. if ( -1 != WP_AbsorbConversion( traceEnt, traceEnt->client->ps.forcePowerLevel[FP_ABSORB], self, FP_GRIP, self->client->ps.forcePowerLevel[FP_GRIP], forcePowerNeeded[self->client->ps.forcePowerLevel[FP_GRIP]]) )
  9467. {
  9468. //WP_ForcePowerStop( self, FP_GRIP );
  9469. return;
  9470. }
  9471. //===============
  9472. }
  9473. else
  9474. {//can't grip non-clients... right?
  9475. //FIXME: Make it so objects flagged as "grabbable" are let through
  9476. //if ( Q_stricmp( "misc_model_breakable", traceEnt->classname ) || !(traceEnt->s.eFlags&EF_BOUNCE_HALF) || !traceEnt->physicsBounce )
  9477. {
  9478. return;
  9479. }
  9480. }
  9481. // Make sure to turn off Force Protection and Force Absorb.
  9482. if (self->client->ps.forcePowersActive & (1 << FP_PROTECT) )
  9483. {
  9484. WP_ForcePowerStop( self, FP_PROTECT );
  9485. }
  9486. if (self->client->ps.forcePowersActive & (1 << FP_ABSORB) )
  9487. {
  9488. WP_ForcePowerStop( self, FP_ABSORB );
  9489. }
  9490. WP_ForcePowerStart( self, FP_GRIP, 20 );
  9491. //FIXME: rule out other things?
  9492. //FIXME: Jedi resist, like the push and pull?
  9493. self->client->ps.forceGripEntityNum = traceEnt->s.number;
  9494. if ( traceEnt->client )
  9495. {
  9496. Vehicle_t *pVeh;
  9497. if ( ( pVeh = G_IsRidingVehicle( traceEnt ) ) != NULL )
  9498. {//riding vehicle? pull him off!
  9499. //FIXME: if in an AT-ST or X-Wing, shouldn't do this... :)
  9500. //pull him off of it
  9501. //((CVehicleNPC *)traceEnt->NPC)->Eject( traceEnt );
  9502. pVeh->m_pVehicleInfo->Eject( pVeh, traceEnt, qtrue );
  9503. //G_DriveVehicle( traceEnt, NULL, NULL );
  9504. }
  9505. G_AddVoiceEvent( traceEnt, Q_irand(EV_PUSHED1, EV_PUSHED3), 2000 );
  9506. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_2 || traceEnt->s.weapon == WP_SABER )
  9507. {//if we pick up & carry, drop their weap
  9508. if ( traceEnt->s.weapon
  9509. && traceEnt->client->NPC_class != CLASS_ROCKETTROOPER
  9510. && traceEnt->client->NPC_class != CLASS_VEHICLE
  9511. && traceEnt->client->NPC_class != CLASS_HAZARD_TROOPER
  9512. && traceEnt->client->NPC_class != CLASS_TUSKEN
  9513. && traceEnt->client->NPC_class != CLASS_BOBAFETT
  9514. && traceEnt->client->NPC_class != CLASS_ASSASSIN_DROID
  9515. && traceEnt->s.weapon != WP_CONCUSSION // so rax can't drop his
  9516. )
  9517. {
  9518. if ( traceEnt->client->NPC_class == CLASS_BOBAFETT )
  9519. {//he doesn't drop them, just puts it away
  9520. ChangeWeapon( traceEnt, WP_MELEE );
  9521. }
  9522. else if ( traceEnt->s.weapon == WP_MELEE )
  9523. {//they can't take that away from me, oh no...
  9524. }
  9525. else if ( traceEnt->NPC
  9526. && (traceEnt->NPC->scriptFlags&SCF_DONT_FLEE) )
  9527. {//*SIGH*... if an NPC can't flee, they can't run after and pick up their weapon, do don't drop it
  9528. }
  9529. else if ( traceEnt->s.weapon != WP_SABER )
  9530. {
  9531. WP_DropWeapon( traceEnt, NULL );
  9532. }
  9533. else
  9534. {
  9535. //turn it off?
  9536. traceEnt->client->ps.SaberDeactivate();
  9537. G_SoundOnEnt( traceEnt, CHAN_WEAPON, "sound/weapons/saber/saberoffquick.wav" );
  9538. #ifdef _IMMERSION
  9539. G_Force( traceEnt, G_ForceIndex( "fffx/weapons/saber/saberoffquick", FF_CHANNEL_WEAPON ) );
  9540. #endif // _IMMERSION
  9541. }
  9542. }
  9543. }
  9544. //else FIXME: need a one-armed choke if we're not on a high enough level to make them drop their gun
  9545. VectorCopy( traceEnt->client->renderInfo.headPoint, self->client->ps.forceGripOrg );
  9546. }
  9547. else
  9548. {
  9549. VectorCopy( traceEnt->currentOrigin, self->client->ps.forceGripOrg );
  9550. }
  9551. self->client->ps.forceGripOrg[2] += 48;//FIXME: define?
  9552. if ( self->client->ps.forcePowerLevel[FP_GRIP] < FORCE_LEVEL_2 )
  9553. {//just a duration
  9554. self->client->ps.forcePowerDebounce[FP_GRIP] = level.time + 250;
  9555. self->client->ps.forcePowerDuration[FP_GRIP] = level.time + 5000;
  9556. if ( self->m_pVehicle && self->m_pVehicle->m_pVehicleInfo->Inhabited( self->m_pVehicle ) )
  9557. {//empty vehicles don't make gripped noise
  9558. traceEnt->s.loopSound = G_SoundIndex( "sound/weapons/force/grip.mp3" );
  9559. }
  9560. #ifdef _IMMERSION
  9561. G_Force( self, G_ForceIndex( "fffx/weapons/force/gripcast", FF_CHANNEL_FORCE ) );
  9562. //G_Force( traceEnt, G_ForceIndex( "fffx/weapons/force/grip", FF_CHANNEL_DAMAGE ) );
  9563. #endif // _IMMERSION
  9564. }
  9565. else
  9566. {
  9567. if ( self->client->ps.forcePowerLevel[FP_GRIP] == FORCE_LEVEL_2 )
  9568. {//lifting sound? or always?
  9569. }
  9570. //if ( traceEnt->s.number )
  9571. {//picks them up for a second first
  9572. self->client->ps.forcePowerDebounce[FP_GRIP] = level.time + 1000;
  9573. }
  9574. /*
  9575. else
  9576. {//player should take damage right away
  9577. self->client->ps.forcePowerDebounce[FP_GRIP] = level.time + 250;
  9578. }
  9579. */
  9580. // force grip sound should only play when the target is alive?
  9581. // if (traceEnt->health>0)
  9582. // {
  9583. self->s.loopSound = G_SoundIndex( "sound/weapons/force/grip.mp3" );
  9584. // }
  9585. }
  9586. }
  9587. qboolean ForceLightningCheck2Handed( gentity_t *self )
  9588. {
  9589. if ( self && self->client )
  9590. {
  9591. if ( self->s.weapon == WP_NONE
  9592. || self->s.weapon == WP_MELEE
  9593. || (self->s.weapon == WP_SABER && !self->client->ps.SaberActive()) )
  9594. {
  9595. return qtrue;
  9596. }
  9597. }
  9598. return qfalse;
  9599. }
  9600. void ForceLightningAnim( gentity_t *self )
  9601. {
  9602. if ( !self || !self->client )
  9603. {
  9604. return;
  9605. }
  9606. //one-handed lightning 2 and above
  9607. int startAnim = BOTH_FORCELIGHTNING_START;
  9608. int holdAnim = BOTH_FORCELIGHTNING_HOLD;
  9609. if ( self->client->ps.forcePowerLevel[FP_LIGHTNING] >= FORCE_LEVEL_3
  9610. && ForceLightningCheck2Handed( self ) )
  9611. {//empty handed lightning 3
  9612. startAnim = BOTH_FORCE_2HANDEDLIGHTNING_START;
  9613. holdAnim = BOTH_FORCE_2HANDEDLIGHTNING_HOLD;
  9614. }
  9615. //FIXME: if standing still, play on whole body? Especially 2-handed version
  9616. if ( self->client->ps.torsoAnim == startAnim )
  9617. {
  9618. if ( !self->client->ps.torsoAnimTimer )
  9619. {
  9620. NPC_SetAnim( self, SETANIM_TORSO, holdAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9621. }
  9622. else
  9623. {
  9624. NPC_SetAnim( self, SETANIM_TORSO, startAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9625. }
  9626. }
  9627. else
  9628. {
  9629. NPC_SetAnim( self, SETANIM_TORSO, holdAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9630. }
  9631. }
  9632. void ForceLightning( gentity_t *self )
  9633. {
  9634. if ( self->health <= 0 )
  9635. {
  9636. return;
  9637. }
  9638. if ( !self->s.number && (cg.zoomMode || in_camera) )
  9639. {//can't force lightning when zoomed in or in cinematic
  9640. return;
  9641. }
  9642. if ( self->client->ps.leanofs )
  9643. {//can't force-lightning while leaning
  9644. return;
  9645. }
  9646. if ( self->client->ps.forcePower < 25 || !WP_ForcePowerUsable( self, FP_LIGHTNING, 0 ) )
  9647. {
  9648. return;
  9649. }
  9650. if ( self->client->ps.forcePowerDebounce[FP_LIGHTNING] > level.time )
  9651. {//stops it while using it and also after using it, up to 3 second delay
  9652. return;
  9653. }
  9654. if ( self->client->ps.saberLockTime > level.time )
  9655. {//FIXME: can this be a way to break out?
  9656. return;
  9657. }
  9658. // Make sure to turn off Force Protection and Force Absorb.
  9659. if (self->client->ps.forcePowersActive & (1 << FP_PROTECT) )
  9660. {
  9661. WP_ForcePowerStop( self, FP_PROTECT );
  9662. }
  9663. if (self->client->ps.forcePowersActive & (1 << FP_ABSORB) )
  9664. {
  9665. WP_ForcePowerStop( self, FP_ABSORB );
  9666. }
  9667. //Shoot lightning from hand
  9668. //make sure this plays and that you cannot press fire for about 1 second after this
  9669. if ( self->client->ps.forcePowerLevel[FP_LIGHTNING] < FORCE_LEVEL_2 )
  9670. {
  9671. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCELIGHTNING, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9672. }
  9673. else
  9674. {
  9675. ForceLightningAnim( self );
  9676. /*
  9677. if ( ForceLightningCheck2Handed( self ) )
  9678. {//empty handed lightning 3
  9679. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCE_2HANDEDLIGHTNING_START, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9680. }
  9681. else
  9682. {//one-handed lightning 3
  9683. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCELIGHTNING_START, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9684. }
  9685. */
  9686. }
  9687. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  9688. self->client->ps.saberBlocked = BLOCKED_NONE;
  9689. G_SoundOnEnt( self, CHAN_BODY, "sound/weapons/force/lightning.wav" );
  9690. #ifdef _IMMERSION
  9691. G_Force( self, G_ForceIndex( "fffx/weapons/force/lightning", FF_CHANNEL_WEAPON ) );
  9692. #endif // _IMMERSION
  9693. if ( self->client->ps.forcePowerLevel[FP_LIGHTNING] < FORCE_LEVEL_2 )
  9694. {//short burst
  9695. //G_SoundOnEnt( self, CHAN_BODY, "sound/weapons/force/lightning.wav" );
  9696. }
  9697. else
  9698. {//holding it
  9699. self->s.loopSound = G_SoundIndex( "sound/weapons/force/lightning2.wav" );
  9700. }
  9701. //FIXME: build-up or delay this until in proper part of anim
  9702. self->client->ps.weaponTime = self->client->ps.torsoAnimTimer;
  9703. WP_ForcePowerStart( self, FP_LIGHTNING, self->client->ps.torsoAnimTimer );
  9704. }
  9705. void ForceLightningDamage( gentity_t *self, gentity_t *traceEnt, vec3_t dir, float dist, float dot, vec3_t impactPoint )
  9706. {
  9707. if( traceEnt->NPC && traceEnt->NPC->scriptFlags & SCF_NO_FORCE )
  9708. {
  9709. return;
  9710. }
  9711. if ( traceEnt && traceEnt->takedamage )
  9712. {
  9713. if ( !traceEnt->client || traceEnt->client->playerTeam != self->client->playerTeam || self->enemy == traceEnt || traceEnt->enemy == self )
  9714. {//an enemy or object
  9715. int dmg;
  9716. //FIXME: check for client using FP_ABSORB
  9717. if ( self->client->ps.forcePowerLevel[FP_LIGHTNING] > FORCE_LEVEL_2 )
  9718. {//more damage if closer and more in front
  9719. dmg = 1;
  9720. if ( self->client->NPC_class == CLASS_REBORN
  9721. && self->client->ps.weapon == WP_NONE )
  9722. {//Cultist: looks fancy, but does less damage
  9723. }
  9724. else
  9725. {
  9726. if ( dist < 100 )
  9727. {
  9728. dmg += 2;
  9729. }
  9730. else if ( dist < 200 )
  9731. {
  9732. dmg += 1;
  9733. }
  9734. if ( dot > 0.9f )
  9735. {
  9736. dmg += 2;
  9737. }
  9738. else if ( dot > 0.7f )
  9739. {
  9740. dmg += 1;
  9741. }
  9742. }
  9743. if ( self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING
  9744. || self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING_START
  9745. || self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING_HOLD
  9746. || self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING_RELEASE )
  9747. {//jackin' 'em up, Palpatine-style
  9748. dmg *= 2;
  9749. }
  9750. }
  9751. else
  9752. {
  9753. dmg = Q_irand( 1, 3 );//*self->client->ps.forcePowerLevel[FP_LIGHTNING];
  9754. }
  9755. if ( traceEnt->client
  9756. && traceEnt->health > 0
  9757. && traceEnt->NPC
  9758. && (traceEnt->NPC->aiFlags&NPCAI_BOSS_CHARACTER) )
  9759. {//Luke, Desann Tavion and Kyle can shield themselves from the attack
  9760. //FIXME: shield effect or something?
  9761. int parts;
  9762. if ( traceEnt->client->ps.groundEntityNum != ENTITYNUM_NONE && !PM_SpinningSaberAnim( traceEnt->client->ps.legsAnim ) && !PM_FlippingAnim( traceEnt->client->ps.legsAnim ) && !PM_RollingAnim( traceEnt->client->ps.legsAnim ) )
  9763. {//if on a surface and not in a spin or flip, play full body resist
  9764. parts = SETANIM_BOTH;
  9765. }
  9766. else
  9767. {//play resist just in torso
  9768. parts = SETANIM_TORSO;
  9769. }
  9770. //FIXME: don't interrupt big anims with this!
  9771. NPC_SetAnim( traceEnt, parts, BOTH_RESISTPUSH, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  9772. Jedi_PlayDeflectSound( traceEnt );
  9773. dmg = Q_irand(0,1);
  9774. }
  9775. else if ( traceEnt->s.weapon == WP_SABER )
  9776. {//saber can block lightning
  9777. if ( traceEnt->client //a client
  9778. && !traceEnt->client->ps.saberInFlight//saber in hand
  9779. && ( traceEnt->client->ps.saberMove == LS_READY || PM_SaberInParry( traceEnt->client->ps.saberMove ) || PM_SaberInReturn( traceEnt->client->ps.saberMove ) )//not attacking with saber
  9780. && InFOV( self->currentOrigin, traceEnt->currentOrigin, traceEnt->client->ps.viewangles, 20, 35 ) //I'm in front of them
  9781. && !PM_InKnockDown( &traceEnt->client->ps ) //they're not in a knockdown
  9782. && !PM_SuperBreakLoseAnim( traceEnt->client->ps.torsoAnim )
  9783. && !PM_SuperBreakWinAnim( traceEnt->client->ps.torsoAnim )
  9784. && !PM_SaberInSpecialAttack( traceEnt->client->ps.torsoAnim )
  9785. && !PM_InSpecialJump( traceEnt->client->ps.torsoAnim )
  9786. && (!traceEnt->s.number||(traceEnt->NPC&&traceEnt->NPC->rank>=RANK_LT_COMM)) )//the player or a tough jedi/reborn
  9787. {
  9788. if ( Q_irand( 0, traceEnt->client->ps.forcePowerLevel[FP_SABER_DEFENSE]*3 ) > 0 )//more of a chance of defending if saber defense is high
  9789. {
  9790. dmg = 0;
  9791. }
  9792. if ( (traceEnt->client->ps.forcePowersActive&(1<<FP_ABSORB))
  9793. && traceEnt->client->ps.forcePowerLevel[FP_ABSORB] > FORCE_LEVEL_2 )
  9794. {//no parry, just absorb
  9795. }
  9796. else
  9797. {
  9798. //make them do a parry
  9799. traceEnt->client->ps.saberBlocked = BLOCKED_UPPER_LEFT;
  9800. int parryReCalcTime = Jedi_ReCalcParryTime( traceEnt, EVASION_PARRY );
  9801. if ( traceEnt->client->ps.forcePowerDebounce[FP_SABER_DEFENSE] < level.time + parryReCalcTime )
  9802. {
  9803. traceEnt->client->ps.forcePowerDebounce[FP_SABER_DEFENSE] = level.time + parryReCalcTime;
  9804. }
  9805. traceEnt->client->ps.weaponTime = Q_irand( 100, 300 );//hold this move - can't attack! - FIXME: unless dual sabers?
  9806. }
  9807. }
  9808. else if ( Q_irand( 0, 1 ) )
  9809. {//jedi less likely to be damaged
  9810. dmg = 0;
  9811. }
  9812. else
  9813. {
  9814. dmg = 1;
  9815. }
  9816. }
  9817. if ( traceEnt && traceEnt->client && traceEnt->client->ps.powerups[PW_GALAK_SHIELD] )
  9818. {
  9819. //has shield up
  9820. dmg = 0;
  9821. }
  9822. int modPowerLevel = -1;
  9823. if (traceEnt->client)
  9824. {
  9825. modPowerLevel = WP_AbsorbConversion(traceEnt, traceEnt->client->ps.forcePowerLevel[FP_ABSORB], self, FP_LIGHTNING, self->client->ps.forcePowerLevel[FP_LIGHTNING], 1);
  9826. }
  9827. if (modPowerLevel != -1)
  9828. {
  9829. if ( !modPowerLevel )
  9830. {
  9831. dmg = 0;
  9832. }
  9833. else if ( modPowerLevel == 1 )
  9834. {
  9835. dmg = floor((float)dmg/4.0f);
  9836. }
  9837. else if ( modPowerLevel == 2 )
  9838. {
  9839. dmg = floor((float)dmg/2.0f);
  9840. }
  9841. }
  9842. //FIXME: if ForceDrain, sap force power and add health to self, use different sound & effects
  9843. if ( dmg )
  9844. {
  9845. G_Damage( traceEnt, self, self, dir, impactPoint, dmg, 0, MOD_FORCE_LIGHTNING );
  9846. }
  9847. if ( traceEnt->client )
  9848. {
  9849. if ( !Q_irand( 0, 2 ) )
  9850. {
  9851. G_Sound( traceEnt, G_SoundIndex( va( "sound/weapons/force/lightninghit%d.wav", Q_irand( 1, 3 ) ) ) );
  9852. }
  9853. traceEnt->s.powerups |= ( 1 << PW_SHOCKED );
  9854. // If we are dead or we are a bot, we can do the full version
  9855. class_t npc_class = traceEnt->client->NPC_class;
  9856. if ( traceEnt->health <= 0 || ( npc_class == CLASS_SEEKER || npc_class == CLASS_PROBE ||
  9857. npc_class == CLASS_MOUSE || npc_class == CLASS_GONK || npc_class == CLASS_R2D2 || npc_class == CLASS_REMOTE ||
  9858. npc_class == CLASS_R5D2 || npc_class == CLASS_PROTOCOL || npc_class == CLASS_MARK1 ||
  9859. npc_class == CLASS_MARK2 || npc_class == CLASS_INTERROGATOR || npc_class == CLASS_ATST ) ||
  9860. npc_class == CLASS_SENTRY )
  9861. {
  9862. traceEnt->client->ps.powerups[PW_SHOCKED] = level.time + 4000;
  9863. }
  9864. else //short version
  9865. {
  9866. traceEnt->client->ps.powerups[PW_SHOCKED] = level.time + 500;
  9867. }
  9868. }
  9869. }
  9870. }
  9871. }
  9872. void ForceShootLightning( gentity_t *self )
  9873. {
  9874. trace_t tr;
  9875. vec3_t end, forward;
  9876. gentity_t *traceEnt;
  9877. if ( self->health <= 0 )
  9878. {
  9879. return;
  9880. }
  9881. if ( !self->s.number && cg.zoomMode )
  9882. {//can't force lightning when zoomed in
  9883. return;
  9884. }
  9885. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  9886. VectorNormalize( forward );
  9887. //FIXME: if lightning hits water, do water-only-flagged radius damage from that point
  9888. if ( self->client->ps.forcePowerLevel[FP_LIGHTNING] > FORCE_LEVEL_2 )
  9889. {//arc
  9890. vec3_t center, mins, maxs, dir, ent_org, size, v;
  9891. float radius = 512, dot, dist;
  9892. gentity_t *entityList[MAX_GENTITIES];
  9893. int e, numListedEntities, i;
  9894. VectorCopy( self->currentOrigin, center );
  9895. for ( i = 0 ; i < 3 ; i++ )
  9896. {
  9897. mins[i] = center[i] - radius;
  9898. maxs[i] = center[i] + radius;
  9899. }
  9900. numListedEntities = gi.EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  9901. for ( e = 0 ; e < numListedEntities ; e++ )
  9902. {
  9903. traceEnt = entityList[e];
  9904. if ( !traceEnt )
  9905. continue;
  9906. if ( traceEnt == self )
  9907. continue;
  9908. if ( traceEnt->owner == self && traceEnt->s.weapon != WP_THERMAL )//can push your own thermals
  9909. continue;
  9910. if ( !traceEnt->inuse )
  9911. continue;
  9912. if ( !traceEnt->takedamage )
  9913. continue;
  9914. /*
  9915. if ( traceEnt->health <= 0 )//no torturing corpses
  9916. continue;
  9917. */
  9918. //this is all to see if we need to start a saber attack, if it's in flight, this doesn't matter
  9919. // find the distance from the edge of the bounding box
  9920. for ( i = 0 ; i < 3 ; i++ )
  9921. {
  9922. if ( center[i] < traceEnt->absmin[i] )
  9923. {
  9924. v[i] = traceEnt->absmin[i] - center[i];
  9925. } else if ( center[i] > traceEnt->absmax[i] )
  9926. {
  9927. v[i] = center[i] - traceEnt->absmax[i];
  9928. } else
  9929. {
  9930. v[i] = 0;
  9931. }
  9932. }
  9933. VectorSubtract( traceEnt->absmax, traceEnt->absmin, size );
  9934. VectorMA( traceEnt->absmin, 0.5, size, ent_org );
  9935. //see if they're in front of me
  9936. //must be within the forward cone
  9937. VectorSubtract( ent_org, center, dir );
  9938. VectorNormalize( dir );
  9939. if ( (dot = DotProduct( dir, forward )) < 0.5 )
  9940. continue;
  9941. //must be close enough
  9942. dist = VectorLength( v );
  9943. if ( dist >= radius )
  9944. {
  9945. continue;
  9946. }
  9947. //in PVS?
  9948. if ( !traceEnt->bmodel && !gi.inPVS( ent_org, self->client->renderInfo.handLPoint ) )
  9949. {//must be in PVS
  9950. continue;
  9951. }
  9952. //Now check and see if we can actually hit it
  9953. gi.trace( &tr, self->client->renderInfo.handLPoint, vec3_origin, vec3_origin, ent_org, self->s.number, MASK_SHOT );
  9954. if ( tr.fraction < 1.0f && tr.entityNum != traceEnt->s.number )
  9955. {//must have clear LOS
  9956. continue;
  9957. }
  9958. // ok, we are within the radius, add us to the incoming list
  9959. //FIXME: maybe add up the ents and do more damage the less ents there are
  9960. // as if we're spreading out the damage?
  9961. ForceLightningDamage( self, traceEnt, dir, dist, dot, ent_org );
  9962. }
  9963. }
  9964. else
  9965. {//trace-line
  9966. int ignore = self->s.number;
  9967. int traces = 0;
  9968. vec3_t start;
  9969. VectorCopy( self->client->renderInfo.handLPoint, start );
  9970. VectorMA( self->client->renderInfo.handLPoint, 2048, forward, end );
  9971. while ( traces < 10 )
  9972. {//need to loop this in case we hit a Jedi who dodges the shot
  9973. gi.trace( &tr, start, vec3_origin, vec3_origin, end, ignore, MASK_SHOT, G2_RETURNONHIT, 10 );
  9974. if ( tr.entityNum == ENTITYNUM_NONE || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  9975. {
  9976. return;
  9977. }
  9978. traceEnt = &g_entities[tr.entityNum];
  9979. //NOTE: only NPCs do this auto-dodge
  9980. if ( traceEnt
  9981. && traceEnt->s.number >= MAX_CLIENTS
  9982. && traceEnt->client
  9983. && traceEnt->client->ps.forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_0 )//&& traceEnt->NPC
  9984. {//FIXME: need a more reliable way to know we hit a jedi?
  9985. if ( !Jedi_DodgeEvasion( traceEnt, self, &tr, HL_NONE ) )
  9986. {//act like we didn't even hit him
  9987. VectorCopy( tr.endpos, start );
  9988. ignore = tr.entityNum;
  9989. traces++;
  9990. continue;
  9991. }
  9992. }
  9993. //a Jedi is not dodging this shot
  9994. break;
  9995. }
  9996. traceEnt = &g_entities[tr.entityNum];
  9997. ForceLightningDamage( self, traceEnt, forward, 0, 0, tr.endpos );
  9998. }
  9999. }
  10000. void WP_DeactivateSaber( gentity_t *self, qboolean clearLength )
  10001. {
  10002. if ( !self || !self->client )
  10003. {
  10004. return;
  10005. }
  10006. //keep my saber off!
  10007. if ( self->client->ps.SaberActive() )
  10008. {
  10009. self->client->ps.SaberDeactivate();
  10010. if ( clearLength )
  10011. {
  10012. self->client->ps.SetSaberLength( 0 );
  10013. }
  10014. G_SoundIndexOnEnt( self, CHAN_WEAPON, self->client->ps.saber[0].soundOff );
  10015. #ifdef _IMMERSION
  10016. if ( !self->s.number )
  10017. {//this is kind of silly to try to do on an NPC
  10018. if ( self->client->playerTeam == TEAM_PLAYER )
  10019. {
  10020. G_Force( self, G_ForceIndex( "fffx/weapons/saber/saberoff", FF_CHANNEL_WEAPON ) );
  10021. }
  10022. else
  10023. {
  10024. G_Force( self, G_ForceIndex( "fffx/weapons/saber/enemy_saber_off", FF_CHANNEL_WEAPON ) );
  10025. }
  10026. }
  10027. #endif // _IMMERSION
  10028. }
  10029. }
  10030. static void ForceShootDrain( gentity_t *self );
  10031. void ForceDrainGrabStart( gentity_t *self )
  10032. {
  10033. NPC_SetAnim( self, SETANIM_BOTH, BOTH_FORCE_DRAIN_GRAB_START, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  10034. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  10035. self->client->ps.saberBlocked = BLOCKED_NONE;
  10036. self->client->ps.weaponTime = 1000;
  10037. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  10038. {
  10039. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  10040. }
  10041. //actually grabbing someone, so turn off the saber!
  10042. WP_DeactivateSaber( self, qtrue );
  10043. }
  10044. qboolean ForceDrain2( gentity_t *self )
  10045. {//FIXME: make enemy Jedi able to use this
  10046. trace_t tr;
  10047. vec3_t end, forward;
  10048. gentity_t *traceEnt = NULL;
  10049. if ( self->health <= 0 )
  10050. {
  10051. return qtrue;
  10052. }
  10053. if ( !self->s.number && (cg.zoomMode || in_camera) )
  10054. {//can't force grip when zoomed in or in cinematic
  10055. return qtrue;
  10056. }
  10057. if ( self->client->ps.leanofs )
  10058. {//can't force-drain while leaning
  10059. return qtrue;
  10060. }
  10061. /*
  10062. if ( self->client->ps.SaberLength() > 0 )
  10063. {//can't do this if saber is on!
  10064. return qfalse;
  10065. }
  10066. */
  10067. if ( self->client->ps.forceDrainEntityNum <= ENTITYNUM_WORLD )
  10068. {//already draining
  10069. //keep my saber off!
  10070. WP_DeactivateSaber( self, qtrue );
  10071. if ( self->client->ps.forcePowerLevel[FP_DRAIN] > FORCE_LEVEL_1 )
  10072. {
  10073. self->client->ps.forcePowerDuration[FP_DRAIN] = level.time + 100;
  10074. self->client->ps.weaponTime = 1000;
  10075. if ( self->client->ps.forcePowersActive&(1<<FP_SPEED) )
  10076. {
  10077. self->client->ps.weaponTime = floor( self->client->ps.weaponTime * g_timescale->value );
  10078. }
  10079. }
  10080. return qtrue;
  10081. }
  10082. if ( self->client->ps.forcePowerDebounce[FP_DRAIN] > level.time )
  10083. {//stops it while using it and also after using it, up to 3 second delay
  10084. return qtrue;
  10085. }
  10086. if ( self->client->ps.weaponTime > 0 )
  10087. {//busy
  10088. return qtrue;
  10089. }
  10090. if ( self->client->ps.forcePower < 25 || !WP_ForcePowerUsable( self, FP_DRAIN, 0 ) )
  10091. {
  10092. return qtrue;
  10093. }
  10094. if ( self->client->ps.saberLockTime > level.time )
  10095. {//in saberlock
  10096. return qtrue;
  10097. }
  10098. //NOTE: from here on, if it fails, it's okay to try a normal drain, so return qfalse
  10099. if ( self->client->ps.groundEntityNum == ENTITYNUM_NONE )
  10100. {//in air
  10101. return qfalse;
  10102. }
  10103. //Cause choking anim + health drain in ent in front of me
  10104. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  10105. VectorNormalize( forward );
  10106. VectorMA( self->client->renderInfo.eyePoint, FORCE_DRAIN_DIST, forward, end );
  10107. //okay, trace straight ahead and see what's there
  10108. gi.trace( &tr, self->client->renderInfo.eyePoint, vec3_origin, vec3_origin, end, self->s.number, MASK_SHOT );
  10109. if ( tr.entityNum >= ENTITYNUM_WORLD || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  10110. {
  10111. return qfalse;
  10112. }
  10113. traceEnt = &g_entities[tr.entityNum];
  10114. if ( !traceEnt || traceEnt == self/*???*/ || traceEnt->bmodel || (traceEnt->health <= 0 && traceEnt->takedamage) || (traceEnt->NPC && traceEnt->NPC->scriptFlags & SCF_NO_FORCE) )
  10115. {
  10116. return qfalse;
  10117. }
  10118. if ( traceEnt->client )
  10119. {
  10120. if ( traceEnt->client->ps.forceJumpZStart )
  10121. {//can't catch them in mid force jump - FIXME: maybe base it on velocity?
  10122. return qfalse;
  10123. }
  10124. if ( traceEnt->client->ps.groundEntityNum == ENTITYNUM_NONE )
  10125. {//can't catch them in mid air
  10126. return qfalse;
  10127. }
  10128. if ( !Q_stricmp("Yoda",traceEnt->NPC_type) )
  10129. {
  10130. Jedi_PlayDeflectSound( traceEnt );
  10131. ForceThrow( traceEnt, qfalse );
  10132. return qtrue;
  10133. }
  10134. switch ( traceEnt->client->NPC_class )
  10135. {
  10136. case CLASS_GALAKMECH://cant grab him, he's in armor
  10137. G_AddVoiceEvent( traceEnt, Q_irand(EV_PUSHED1, EV_PUSHED3), Q_irand( 3000, 5000 ) );
  10138. return qfalse;
  10139. break;
  10140. case CLASS_ROCKETTROOPER://cant grab him, he's in armor
  10141. case CLASS_HAZARD_TROOPER://cant grab him, he's in armor
  10142. return qfalse;
  10143. break;
  10144. case CLASS_ATST://much too big to grab!
  10145. return qfalse;
  10146. break;
  10147. //no droids either
  10148. case CLASS_GONK:
  10149. case CLASS_R2D2:
  10150. case CLASS_R5D2:
  10151. case CLASS_MARK1:
  10152. case CLASS_MARK2:
  10153. case CLASS_MOUSE:
  10154. case CLASS_PROTOCOL:
  10155. case CLASS_SABER_DROID:
  10156. case CLASS_ASSASSIN_DROID:
  10157. return qfalse;
  10158. break;
  10159. case CLASS_PROBE:
  10160. case CLASS_SEEKER:
  10161. case CLASS_REMOTE:
  10162. case CLASS_SENTRY:
  10163. case CLASS_INTERROGATOR:
  10164. return qfalse;
  10165. break;
  10166. case CLASS_DESANN://Desann cannot be gripped, he just pushes you back instantly
  10167. case CLASS_KYLE:
  10168. case CLASS_TAVION:
  10169. case CLASS_LUKE:
  10170. Jedi_PlayDeflectSound( traceEnt );
  10171. ForceThrow( traceEnt, qfalse );
  10172. return qtrue;
  10173. break;
  10174. case CLASS_REBORN:
  10175. case CLASS_SHADOWTROOPER:
  10176. //case CLASS_ALORA:
  10177. case CLASS_JEDI:
  10178. if ( traceEnt->NPC
  10179. && traceEnt->NPC->rank > RANK_CIVILIAN
  10180. && self->client->ps.forcePowerLevel[FP_DRAIN] < FORCE_LEVEL_2
  10181. && traceEnt->client->ps.weaponTime <= 0 )
  10182. {
  10183. ForceDrainGrabStart( self );
  10184. Jedi_PlayDeflectSound( traceEnt );
  10185. ForceThrow( traceEnt, qfalse );
  10186. return qtrue;
  10187. }
  10188. break;
  10189. }
  10190. if ( traceEnt->s.weapon == WP_EMPLACED_GUN )
  10191. {//FIXME: maybe can pull them out?
  10192. return qfalse;
  10193. }
  10194. if ( traceEnt != self->enemy && OnSameTeam(self, traceEnt) )
  10195. {//can't accidently grip-drain your teammate
  10196. return qfalse;
  10197. }
  10198. //=CHECKABSORB===
  10199. /*
  10200. if ( -1 != WP_AbsorbConversion( traceEnt, traceEnt->client->ps.forcePowerLevel[FP_ABSORB], self, FP_DRAIN, self->client->ps.forcePowerLevel[FP_DRAIN], forcePowerNeeded[self->client->ps.forcePowerLevel[FP_DRAIN]]) )
  10201. {
  10202. //WP_ForcePowerStop( self, FP_DRAIN );
  10203. return;
  10204. }
  10205. */
  10206. //===============
  10207. if ( !FP_ForceDrainGrippableEnt( traceEnt ) )
  10208. {
  10209. return qfalse;
  10210. }
  10211. }
  10212. else
  10213. {//can't drain non-clients
  10214. return qfalse;
  10215. }
  10216. ForceDrainGrabStart( self );
  10217. WP_ForcePowerStart( self, FP_DRAIN, 10 );
  10218. self->client->ps.forceDrainEntityNum = traceEnt->s.number;
  10219. // G_AddVoiceEvent( traceEnt, Q_irand(EV_PUSHED1, EV_PUSHED3), 2000 );
  10220. G_AddVoiceEvent( traceEnt, Q_irand(EV_CHOKE1, EV_CHOKE3), 2000 );
  10221. if ( /*self->client->ps.forcePowerLevel[FP_DRAIN] > FORCE_LEVEL_2 ||*/ traceEnt->s.weapon == WP_SABER )
  10222. {//if we pick up, turn off their weapon
  10223. WP_DeactivateSaber( traceEnt, qtrue );
  10224. }
  10225. /*
  10226. if ( self->client->ps.forcePowerLevel[FP_DRAIN] < FORCE_LEVEL_2 )
  10227. {//just a duration
  10228. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + 250;
  10229. self->client->ps.forcePowerDuration[FP_DRAIN] = level.time + 5000;
  10230. }
  10231. */
  10232. G_SoundOnEnt( self, CHAN_BODY, "sound/weapons/force/drain.mp3" );
  10233. // NPC_SetAnim( traceEnt, SETANIM_BOTH, BOTH_HUGGEE1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  10234. NPC_SetAnim( traceEnt, SETANIM_BOTH, BOTH_FORCE_DRAIN_GRABBED, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  10235. WP_SabersCheckLock2( self, traceEnt, LOCK_FORCE_DRAIN );
  10236. return qtrue;
  10237. }
  10238. void ForceDrain( gentity_t *self, qboolean triedDrain2 )
  10239. {
  10240. if ( self->health <= 0 )
  10241. {
  10242. return;
  10243. }
  10244. if ( !triedDrain2 && self->client->ps.weaponTime > 0 )
  10245. {
  10246. return;
  10247. }
  10248. if ( self->client->ps.forcePower < 25 || !WP_ForcePowerUsable( self, FP_DRAIN, 0 ) )
  10249. {
  10250. return;
  10251. }
  10252. if ( self->client->ps.forcePowerDebounce[FP_DRAIN] > level.time )
  10253. {//stops it while using it and also after using it, up to 3 second delay
  10254. return;
  10255. }
  10256. if ( self->client->ps.saberLockTime > level.time )
  10257. {//FIXME: can this be a way to break out?
  10258. return;
  10259. }
  10260. // Make sure to turn off Force Protection and Force Absorb.
  10261. if ( self->client->ps.forcePowersActive & (1 << FP_PROTECT) )
  10262. {
  10263. WP_ForcePowerStop( self, FP_PROTECT );
  10264. }
  10265. if ( self->client->ps.forcePowersActive & (1 << FP_ABSORB) )
  10266. {
  10267. WP_ForcePowerStop( self, FP_ABSORB );
  10268. }
  10269. G_SoundOnEnt( self, CHAN_BODY, "sound/weapons/force/drain.mp3" );
  10270. WP_ForcePowerStart( self, FP_DRAIN, 0 );
  10271. }
  10272. qboolean FP_ForceDrainableEnt( gentity_t *victim )
  10273. {
  10274. if ( !victim || !victim->client )
  10275. {
  10276. return qfalse;
  10277. }
  10278. switch ( victim->client->NPC_class )
  10279. {
  10280. case CLASS_SAND_CREATURE://??
  10281. case CLASS_ATST: // technically droid...
  10282. case CLASS_GONK: // droid
  10283. case CLASS_INTERROGATOR: // droid
  10284. case CLASS_MARK1: // droid
  10285. case CLASS_MARK2: // droid
  10286. case CLASS_GALAKMECH: // droid
  10287. case CLASS_MINEMONSTER:
  10288. case CLASS_MOUSE: // droid
  10289. case CLASS_PROBE: // droid
  10290. case CLASS_PROTOCOL: // droid
  10291. case CLASS_R2D2: // droid
  10292. case CLASS_R5D2: // droid
  10293. case CLASS_REMOTE:
  10294. case CLASS_SEEKER: // droid
  10295. case CLASS_SENTRY:
  10296. case CLASS_SABER_DROID:
  10297. case CLASS_ASSASSIN_DROID:
  10298. case CLASS_VEHICLE:
  10299. return qfalse;
  10300. break;
  10301. }
  10302. return qtrue;
  10303. }
  10304. qboolean FP_ForceDrainGrippableEnt( gentity_t *victim )
  10305. {
  10306. if ( !victim || !victim->client )
  10307. {
  10308. return qfalse;
  10309. }
  10310. if ( !FP_ForceDrainableEnt( victim ) )
  10311. {
  10312. return qfalse;
  10313. }
  10314. switch ( victim->client->NPC_class )
  10315. {
  10316. case CLASS_RANCOR:
  10317. case CLASS_SAND_CREATURE:
  10318. case CLASS_WAMPA:
  10319. case CLASS_LIZARD:
  10320. case CLASS_MINEMONSTER:
  10321. case CLASS_MURJJ:
  10322. case CLASS_SWAMP:
  10323. case CLASS_ROCKETTROOPER:
  10324. case CLASS_HAZARD_TROOPER:
  10325. return qfalse;
  10326. }
  10327. return qtrue;
  10328. }
  10329. void ForceDrainDamage( gentity_t *self, gentity_t *traceEnt, vec3_t dir, vec3_t impactPoint )
  10330. {
  10331. if ( traceEnt
  10332. && traceEnt->health > 0
  10333. && traceEnt->takedamage
  10334. && FP_ForceDrainableEnt( traceEnt ) )
  10335. {
  10336. if ( traceEnt->client
  10337. && (!OnSameTeam(self, traceEnt)||self->enemy==traceEnt)//don't drain an ally unless that is actually my current enemy
  10338. && self->client->ps.forceDrainTime < level.time )
  10339. {//an enemy or object
  10340. int modPowerLevel = -1;
  10341. int dmg = self->client->ps.forcePowerLevel[FP_DRAIN] + 1;
  10342. int dflags = (DAMAGE_NO_ARMOR|DAMAGE_NO_KNOCKBACK|DAMAGE_NO_HIT_LOC);//|DAMAGE_NO_KILL);
  10343. if ( traceEnt->s.number == self->client->ps.forceDrainEntityNum )
  10344. {//grabbing hold of them does more damage/drains more, and can actually kill them
  10345. dmg += 3;
  10346. dflags |= DAMAGE_IGNORE_TEAM;
  10347. //dflags &= ~DAMAGE_NO_KILL;
  10348. }
  10349. if (traceEnt->client)
  10350. {
  10351. //check for client using FP_ABSORB
  10352. modPowerLevel = WP_AbsorbConversion(traceEnt, traceEnt->client->ps.forcePowerLevel[FP_ABSORB], self, FP_DRAIN, self->client->ps.forcePowerLevel[FP_DRAIN], 0);
  10353. //Since this is drain, don't absorb any power, but nullify the affect it has
  10354. }
  10355. if ( modPowerLevel != -1 )
  10356. {
  10357. if ( !modPowerLevel )
  10358. {
  10359. dmg = 0;
  10360. }
  10361. else if ( modPowerLevel == 1 )
  10362. {
  10363. dmg = 1;
  10364. }
  10365. else if ( modPowerLevel == 2 )
  10366. {
  10367. dmg = 2;
  10368. }
  10369. }
  10370. if ( dmg )
  10371. {
  10372. int drain = 0;
  10373. if ( traceEnt->client->ps.forcePower )
  10374. {
  10375. if ( dmg > traceEnt->client->ps.forcePower )
  10376. {
  10377. drain = traceEnt->client->ps.forcePower;
  10378. dmg -= drain;
  10379. traceEnt->client->ps.forcePower = 0;
  10380. }
  10381. else
  10382. {
  10383. drain = dmg;
  10384. traceEnt->client->ps.forcePower -= (dmg);
  10385. dmg = 0;
  10386. }
  10387. }
  10388. /*
  10389. if ( (dflags&DAMAGE_NO_KILL) )
  10390. {//must cap damage
  10391. if ( traceEnt->health <= 1 )
  10392. {//can't drain more than they have
  10393. dmg = 0;
  10394. }
  10395. else if ( dmg >= traceEnt->health )
  10396. {//no more than they have, leaving one for them
  10397. dmg = traceEnt->health-1;
  10398. }
  10399. }
  10400. */
  10401. int maxHealth = self->client->ps.stats[STAT_MAX_HEALTH];
  10402. if ( self->client->ps.forcePowerLevel[FP_DRAIN] > FORCE_LEVEL_2 )
  10403. {//overcharge health
  10404. maxHealth = floor( (float)self->client->ps.stats[STAT_MAX_HEALTH] * 1.25f );
  10405. }
  10406. if (self->client->ps.stats[STAT_HEALTH] < maxHealth &&
  10407. self->health > 0 && self->client->ps.stats[STAT_HEALTH] > 0)
  10408. {
  10409. self->health += (drain+dmg);
  10410. if (self->health > maxHealth )
  10411. {
  10412. self->health = maxHealth;
  10413. }
  10414. self->client->ps.stats[STAT_HEALTH] = self->health;
  10415. if ( self->health > self->client->ps.stats[STAT_MAX_HEALTH] )
  10416. {
  10417. self->flags |= FL_OVERCHARGED_HEALTH;
  10418. }
  10419. }
  10420. if ( dmg )
  10421. {//do damage, too
  10422. G_Damage( traceEnt, self, self, dir, impactPoint, dmg, dflags, MOD_FORCE_DRAIN );
  10423. }
  10424. else if ( drain )
  10425. {
  10426. /*
  10427. if ( traceEnt->s.number == self->client->ps.forceDrainEntityNum
  10428. || traceEnt->s.number < MAX_CLIENTS )
  10429. {//grip-draining (or player - only does sound)
  10430. */
  10431. NPC_SetPainEvent( traceEnt );
  10432. /*
  10433. }
  10434. else
  10435. {
  10436. GEntity_PainFunc( traceEnt, self, self, impactPoint, 0, MOD_FORCE_DRAIN );
  10437. }
  10438. */
  10439. }
  10440. if ( !Q_irand( 0, 2 ) )
  10441. {
  10442. G_Sound( traceEnt, G_SoundIndex( "sound/weapons/force/drained.mp3" ) );
  10443. }
  10444. traceEnt->client->ps.forcePowerRegenDebounceTime = level.time + 800; //don't let the client being drained get force power back right away
  10445. }
  10446. }
  10447. }
  10448. }
  10449. qboolean WP_CheckForceDraineeStopMe( gentity_t *self, gentity_t *drainee )
  10450. {
  10451. if ( drainee->NPC
  10452. && drainee->client
  10453. && (drainee->client->ps.forcePowersKnown&(1<<FP_PUSH))
  10454. && level.time-(self->client->ps.forcePowerDebounce[FP_DRAIN]>self->client->ps.forcePowerLevel[FP_DRAIN]*500)//at level 1, I always get at least 500ms of drain, at level 3 I get 1500ms
  10455. && !Q_irand( 0, 100-(drainee->NPC->stats.evasion*10)-(g_spskill->integer*12) ) )
  10456. {//a jedi who broke free
  10457. ForceThrow( drainee, qfalse );
  10458. //FIXME: I need to go into some pushed back anim...
  10459. WP_ForcePowerStop( self, FP_DRAIN );
  10460. //can't drain again for 2 seconds
  10461. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + 4000;
  10462. return qtrue;
  10463. }
  10464. return qfalse;
  10465. }
  10466. void ForceShootDrain( gentity_t *self )
  10467. {
  10468. trace_t tr;
  10469. vec3_t end, forward;
  10470. gentity_t *traceEnt;
  10471. int numDrained = 0;
  10472. if ( self->health <= 0 )
  10473. {
  10474. return;
  10475. }
  10476. if ( self->client->ps.forcePowerDebounce[FP_DRAIN] <= level.time )
  10477. {
  10478. AngleVectors( self->client->ps.viewangles, forward, NULL, NULL );
  10479. VectorNormalize( forward );
  10480. if ( self->client->ps.forcePowerLevel[FP_DRAIN] > FORCE_LEVEL_2 )
  10481. {//arc
  10482. vec3_t center, mins, maxs, dir, ent_org, size, v;
  10483. float radius = MAX_DRAIN_DISTANCE, dot, dist;
  10484. gentity_t *entityList[MAX_GENTITIES];
  10485. int e, numListedEntities, i;
  10486. VectorCopy( self->client->ps.origin, center );
  10487. for ( i = 0 ; i < 3 ; i++ )
  10488. {
  10489. mins[i] = center[i] - radius;
  10490. maxs[i] = center[i] + radius;
  10491. }
  10492. numListedEntities = gi.EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
  10493. for ( e = 0 ; e < numListedEntities ; e++ )
  10494. {
  10495. traceEnt = entityList[e];
  10496. if ( !traceEnt )
  10497. continue;
  10498. if ( traceEnt == self )
  10499. continue;
  10500. if ( !traceEnt->inuse )
  10501. continue;
  10502. if ( !traceEnt->takedamage )
  10503. continue;
  10504. if ( traceEnt->health <= 0 )//no torturing corpses
  10505. continue;
  10506. if ( !traceEnt->client )
  10507. continue;
  10508. /*
  10509. if ( !traceEnt->client->ps.forcePower )
  10510. continue;
  10511. */
  10512. // if (traceEnt->client->ps.forceSide == FORCE_DARKSIDE) // We no longer care if the victim is dark or light
  10513. // continue;
  10514. if (self->enemy != traceEnt//not my enemy
  10515. && OnSameTeam(self, traceEnt))//on my team
  10516. continue;
  10517. //this is all to see if we need to start a saber attack, if it's in flight, this doesn't matter
  10518. // find the distance from the edge of the bounding box
  10519. for ( i = 0 ; i < 3 ; i++ )
  10520. {
  10521. if ( center[i] < traceEnt->absmin[i] )
  10522. {
  10523. v[i] = traceEnt->absmin[i] - center[i];
  10524. } else if ( center[i] > traceEnt->absmax[i] )
  10525. {
  10526. v[i] = center[i] - traceEnt->absmax[i];
  10527. } else
  10528. {
  10529. v[i] = 0;
  10530. }
  10531. }
  10532. VectorSubtract( traceEnt->absmax, traceEnt->absmin, size );
  10533. VectorMA( traceEnt->absmin, 0.5, size, ent_org );
  10534. //see if they're in front of me
  10535. //must be within the forward cone
  10536. VectorSubtract( ent_org, center, dir );
  10537. VectorNormalize( dir );
  10538. if ( (dot = DotProduct( dir, forward )) < 0.5 )
  10539. continue;
  10540. //must be close enough
  10541. dist = VectorLength( v );
  10542. if ( dist >= radius )
  10543. {
  10544. continue;
  10545. }
  10546. //in PVS?
  10547. if ( !traceEnt->bmodel && !gi.inPVS( ent_org, self->client->renderInfo.handLPoint ) )
  10548. {//must be in PVS
  10549. continue;
  10550. }
  10551. //Now check and see if we can actually hit it
  10552. gi.trace( &tr, self->client->ps.origin, vec3_origin, vec3_origin, ent_org, self->s.number, MASK_SHOT, G2_RETURNONHIT, 10 );
  10553. if ( tr.fraction < 1.0f && tr.entityNum != traceEnt->s.number )
  10554. {//must have clear LOS
  10555. continue;
  10556. }
  10557. if ( traceEnt
  10558. && traceEnt->s.number >= MAX_CLIENTS
  10559. && traceEnt->client
  10560. && traceEnt->client->ps.forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_0 )//&& traceEnt->NPC
  10561. {
  10562. if ( !Q_irand( 0, 4 ) && !Jedi_DodgeEvasion( traceEnt, self, &tr, HL_NONE ) )
  10563. {//act like we didn't even hit him
  10564. continue;
  10565. }
  10566. }
  10567. // ok, we are within the radius, add us to the incoming list
  10568. if ( WP_CheckForceDraineeStopMe( self, traceEnt ) )
  10569. {
  10570. continue;
  10571. }
  10572. ForceDrainDamage( self, traceEnt, dir, ent_org );
  10573. numDrained++;
  10574. }
  10575. }
  10576. else
  10577. {//trace-line
  10578. int ignore = self->s.number;
  10579. int traces = 0;
  10580. vec3_t start;
  10581. VectorCopy( self->client->renderInfo.handLPoint, start );
  10582. VectorMA( start, MAX_DRAIN_DISTANCE, forward, end );
  10583. while ( traces < 10 )
  10584. {//need to loop this in case we hit a Jedi who dodges the shot
  10585. gi.trace( &tr, start, vec3_origin, vec3_origin, end, ignore, MASK_SHOT, G2_RETURNONHIT, 10 );
  10586. if ( tr.entityNum == ENTITYNUM_NONE || tr.fraction == 1.0 || tr.allsolid || tr.startsolid )
  10587. {
  10588. //always take 1 force point per frame that we're shooting this
  10589. WP_ForcePowerDrain( self, FP_DRAIN, 1 );
  10590. return;
  10591. }
  10592. traceEnt = &g_entities[tr.entityNum];
  10593. //NOTE: only NPCs do this auto-dodge
  10594. if ( traceEnt
  10595. && traceEnt->s.number >= MAX_CLIENTS
  10596. && traceEnt->client
  10597. && traceEnt->client->ps.forcePowerLevel[FP_LEVITATION] > FORCE_LEVEL_0 )//&& traceEnt->NPC
  10598. {
  10599. if ( !Q_irand( 0, 2 ) && !Jedi_DodgeEvasion( traceEnt, self, &tr, HL_NONE ) )
  10600. {//act like we didn't even hit him
  10601. VectorCopy( tr.endpos, start );
  10602. ignore = tr.entityNum;
  10603. traces++;
  10604. continue;
  10605. }
  10606. }
  10607. //a Jedi is not dodging this shot
  10608. break;
  10609. }
  10610. traceEnt = &g_entities[tr.entityNum];
  10611. if ( !WP_CheckForceDraineeStopMe( self, traceEnt ) )
  10612. {
  10613. ForceDrainDamage( self, traceEnt, forward, tr.endpos );
  10614. }
  10615. numDrained = 1;
  10616. }
  10617. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + 200;//so we don't drain so damn fast!
  10618. }
  10619. self->client->ps.forcePowerRegenDebounceTime = level.time + 500;
  10620. if ( !numDrained )
  10621. {//always take 1 force point per frame that we're shooting this
  10622. WP_ForcePowerDrain( self, FP_DRAIN, 1 );
  10623. }
  10624. else
  10625. {
  10626. WP_ForcePowerDrain( self, FP_DRAIN, numDrained );//was 2, but...
  10627. }
  10628. return;
  10629. }
  10630. void ForceDrainEnt( gentity_t *self, gentity_t *drainEnt )
  10631. {
  10632. if ( self->health <= 0 )
  10633. {
  10634. return;
  10635. }
  10636. if ( self->client->ps.forcePowerDebounce[FP_DRAIN] <= level.time )
  10637. {
  10638. if ( !drainEnt )
  10639. return;
  10640. if ( drainEnt == self )
  10641. return;
  10642. if ( !drainEnt->inuse )
  10643. return;
  10644. if ( !drainEnt->takedamage )
  10645. return;
  10646. if ( drainEnt->health <= 0 )//no torturing corpses
  10647. return;
  10648. if ( !drainEnt->client )
  10649. return;
  10650. if (OnSameTeam(self, drainEnt))
  10651. return;
  10652. vec3_t fwd;
  10653. AngleVectors( self->client->ps.viewangles, fwd, NULL, NULL );
  10654. drainEnt->painDebounceTime = 0;
  10655. ForceDrainDamage( self, drainEnt, fwd, drainEnt->currentOrigin );
  10656. drainEnt->painDebounceTime = level.time + 2000;
  10657. if ( drainEnt->s.number )
  10658. {
  10659. if ( self->client->ps.forcePowerLevel[FP_DRAIN] > FORCE_LEVEL_2 )
  10660. {//do damage faster at level 3
  10661. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + Q_irand( 100, 500 );
  10662. }
  10663. else
  10664. {
  10665. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + Q_irand( 200, 800 );
  10666. }
  10667. }
  10668. else
  10669. {//player takes damage faster
  10670. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + Q_irand( 100, 500 );
  10671. }
  10672. }
  10673. self->client->ps.forcePowerRegenDebounceTime = level.time + 500;
  10674. }
  10675. void ForceSeeing( gentity_t *self )
  10676. {
  10677. if ( self->health <= 0 )
  10678. {
  10679. return;
  10680. }
  10681. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  10682. (self->client->ps.forcePowersActive & (1 << FP_SEE)) )
  10683. {
  10684. WP_ForcePowerStop( self, FP_SEE );
  10685. return;
  10686. }
  10687. if ( !WP_ForcePowerUsable( self, FP_SEE, 0 ) )
  10688. {
  10689. return;
  10690. }
  10691. WP_DebounceForceDeactivateTime( self );
  10692. WP_ForcePowerStart( self, FP_SEE, 0 );
  10693. G_SoundOnEnt( self, CHAN_ITEM, "sound/weapons/force/see.wav" );
  10694. }
  10695. void ForceProtect( gentity_t *self )
  10696. {
  10697. if ( self->health <= 0 )
  10698. {
  10699. return;
  10700. }
  10701. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  10702. (self->client->ps.forcePowersActive & (1 << FP_PROTECT)) )
  10703. {
  10704. WP_ForcePowerStop( self, FP_PROTECT );
  10705. return;
  10706. }
  10707. if ( !WP_ForcePowerUsable( self, FP_PROTECT, 0 ) )
  10708. {
  10709. return;
  10710. }
  10711. // Make sure to turn off Force Rage and Force Absorb.
  10712. if (self->client->ps.forcePowersActive & (1 << FP_RAGE) )
  10713. {
  10714. WP_ForcePowerStop( self, FP_RAGE );
  10715. }
  10716. WP_DebounceForceDeactivateTime( self );
  10717. WP_ForcePowerStart( self, FP_PROTECT, 0 );
  10718. if ( self->client->ps.saberLockTime < level.time )
  10719. {
  10720. if ( self->client->ps.forcePowerLevel[FP_PROTECT] < FORCE_LEVEL_3 )
  10721. {//animate
  10722. int parts = SETANIM_BOTH;
  10723. int anim = BOTH_FORCE_PROTECT;
  10724. if ( self->client->ps.forcePowerLevel[FP_PROTECT] > FORCE_LEVEL_1 )
  10725. {//level 2 only does it on torso (can keep running)
  10726. parts = SETANIM_TORSO;
  10727. anim = BOTH_FORCE_PROTECT_FAST;
  10728. }
  10729. else
  10730. {
  10731. if ( self->client->ps.groundEntityNum != ENTITYNUM_NONE )
  10732. {
  10733. VectorClear( self->client->ps.velocity );
  10734. }
  10735. if ( self->NPC )
  10736. {
  10737. VectorClear( self->client->ps.moveDir );
  10738. self->client->ps.speed = 0;
  10739. }
  10740. //FIXME: what if in air?
  10741. }
  10742. NPC_SetAnim( self, SETANIM_BOTH, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  10743. //don't move or attack during this anim
  10744. if ( self->client->ps.forcePowerLevel[FP_PROTECT] < FORCE_LEVEL_2 )
  10745. {
  10746. self->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  10747. self->client->ps.pm_time = self->client->ps.weaponTime = self->client->ps.torsoAnimTimer;
  10748. if ( self->s.number )
  10749. {//NPC
  10750. self->painDebounceTime = level.time + self->client->ps.torsoAnimTimer;
  10751. }
  10752. else
  10753. {//player
  10754. self->aimDebounceTime = level.time + self->client->ps.torsoAnimTimer;
  10755. }
  10756. }
  10757. else
  10758. {
  10759. self->client->ps.weaponTime = self->client->ps.torsoAnimTimer;
  10760. }
  10761. }
  10762. }
  10763. }
  10764. void ForceAbsorb( gentity_t *self )
  10765. {
  10766. if ( self->health <= 0 )
  10767. {
  10768. return;
  10769. }
  10770. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  10771. (self->client->ps.forcePowersActive & (1 << FP_ABSORB)) )
  10772. {
  10773. WP_ForcePowerStop( self, FP_ABSORB );
  10774. return;
  10775. }
  10776. if ( !WP_ForcePowerUsable( self, FP_ABSORB, 0 ) )
  10777. {
  10778. return;
  10779. }
  10780. // Make sure to turn off Force Rage and Force Protection.
  10781. if (self->client->ps.forcePowersActive & (1 << FP_RAGE) )
  10782. {
  10783. WP_ForcePowerStop( self, FP_RAGE );
  10784. }
  10785. WP_DebounceForceDeactivateTime( self );
  10786. WP_ForcePowerStart( self, FP_ABSORB, 0 );
  10787. if ( self->client->ps.saberLockTime < level.time )
  10788. {
  10789. if ( self->client->ps.forcePowerLevel[FP_ABSORB] < FORCE_LEVEL_3 )
  10790. {//must animate
  10791. int parts = SETANIM_BOTH;
  10792. if ( self->client->ps.forcePowerLevel[FP_ABSORB] > FORCE_LEVEL_1 )
  10793. {//level 2 only does it on torso (can keep running)
  10794. parts = SETANIM_TORSO;
  10795. }
  10796. else
  10797. {
  10798. if ( self->client->ps.groundEntityNum != ENTITYNUM_NONE )
  10799. {
  10800. VectorClear( self->client->ps.velocity );
  10801. }
  10802. if ( self->NPC )
  10803. {
  10804. VectorClear( self->client->ps.moveDir );
  10805. self->client->ps.speed = 0;
  10806. }
  10807. //FIXME: what if in air?
  10808. }
  10809. /*
  10810. //if in air, only do on torso - NOTE: or moving?
  10811. if ( self->client->ps.groundEntityNum == ENTITYNUM_NONE )//|| !VectorCompare( self->client->ps.velocity, vec3_origin ) )
  10812. {
  10813. parts = SETANIM_TORSO;
  10814. }
  10815. */
  10816. NPC_SetAnim( self, parts, BOTH_FORCE_ABSORB, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  10817. self->client->ps.weaponTime = self->client->ps.torsoAnimTimer;
  10818. if ( parts == SETANIM_BOTH )
  10819. {//can't move
  10820. self->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  10821. self->client->ps.pm_time = self->client->ps.legsAnimTimer = self->client->ps.torsoAnimTimer;// = self->client->ps.forcePowerDuration[FP_ABSORB];
  10822. if ( self->s.number )
  10823. {//NPC
  10824. self->painDebounceTime = level.time + self->client->ps.pm_time;//self->client->ps.forcePowerDuration[FP_ABSORB];
  10825. }
  10826. else
  10827. {//player
  10828. self->aimDebounceTime = level.time + self->client->ps.pm_time;//self->client->ps.forcePowerDuration[FP_ABSORB];
  10829. }
  10830. }
  10831. //stop saber
  10832. //WP_DeactivateSaber( self );//turn off saber when meditating
  10833. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  10834. self->client->ps.saberBlocked = BLOCKED_NONE;
  10835. }
  10836. }
  10837. }
  10838. void ForceRage( gentity_t *self )
  10839. {
  10840. if ( self->health <= 0 )
  10841. {
  10842. return;
  10843. }
  10844. //FIXME: prevent them from using any other force powers when raging?
  10845. if (self->client->ps.forceAllowDeactivateTime < level.time &&
  10846. (self->client->ps.forcePowersActive & (1 << FP_RAGE)) )
  10847. {
  10848. WP_ForcePowerStop( self, FP_RAGE );
  10849. return;
  10850. }
  10851. if ( !WP_ForcePowerUsable( self, FP_RAGE, 0 ) )
  10852. {
  10853. return;
  10854. }
  10855. if (self->client->ps.forceRageRecoveryTime >= level.time)
  10856. {
  10857. return;
  10858. }
  10859. if ( self->s.number < MAX_CLIENTS
  10860. && self->health < 25 )
  10861. {//have to have at least 25 health to start it
  10862. return;
  10863. }
  10864. if (self->health < 10)
  10865. {
  10866. return;
  10867. }
  10868. // Make sure to turn off Force Protection and Force Absorb.
  10869. if (self->client->ps.forcePowersActive & (1 << FP_PROTECT) )
  10870. {
  10871. WP_ForcePowerStop( self, FP_PROTECT );
  10872. }
  10873. if (self->client->ps.forcePowersActive & (1 << FP_ABSORB) )
  10874. {
  10875. WP_ForcePowerStop( self, FP_ABSORB );
  10876. }
  10877. WP_DebounceForceDeactivateTime( self );
  10878. WP_ForcePowerStart( self, FP_RAGE, 0 );
  10879. if ( self->client->ps.saberLockTime < level.time )
  10880. {
  10881. if ( self->client->ps.forcePowerLevel[FP_RAGE] < FORCE_LEVEL_3 )
  10882. {//must animate
  10883. if ( self->client->ps.forcePowerLevel[FP_RAGE] < FORCE_LEVEL_2 )
  10884. {//have to stand still for whole length of anim
  10885. //FIXME: if in air, only do on torso?
  10886. NPC_SetAnim( self, SETANIM_BOTH, BOTH_FORCE_RAGE, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  10887. //don't attack during this anim
  10888. self->client->ps.weaponTime = self->client->ps.torsoAnimTimer;
  10889. self->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  10890. self->client->ps.pm_time = self->client->ps.torsoAnimTimer;
  10891. if ( self->s.number )
  10892. {//NPC
  10893. self->painDebounceTime = level.time + self->client->ps.torsoAnimTimer;
  10894. }
  10895. else
  10896. {//player
  10897. self->aimDebounceTime = level.time + self->client->ps.torsoAnimTimer;
  10898. }
  10899. }
  10900. else
  10901. {
  10902. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCE_RAGE, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  10903. //don't attack during this anim
  10904. self->client->ps.weaponTime = self->client->ps.torsoAnimTimer;
  10905. }
  10906. //stop saber
  10907. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  10908. self->client->ps.saberBlocked = BLOCKED_NONE;
  10909. }
  10910. }
  10911. }
  10912. void ForceJumpCharge( gentity_t *self, usercmd_t *ucmd )
  10913. {
  10914. float forceJumpChargeInterval = forceJumpStrength[0] / (FORCE_JUMP_CHARGE_TIME/FRAMETIME);
  10915. if ( self->health <= 0 )
  10916. {
  10917. return;
  10918. }
  10919. if ( !self->s.number && cg.zoomMode )
  10920. {//can't force jump when zoomed in
  10921. return;
  10922. }
  10923. //need to play sound
  10924. if ( !self->client->ps.forceJumpCharge )
  10925. {//FIXME: this should last only as long as the actual charge-up
  10926. G_SoundOnEnt( self, CHAN_BODY, "sound/weapons/force/jumpbuild.wav" );
  10927. #ifdef _IMMERSION
  10928. G_Force( self, G_ForceIndex( "fffx/weapons/force/jumpbuild", FF_CHANNEL_WEAPON ) );
  10929. #endif // _IMMERSION
  10930. }
  10931. //Increment
  10932. self->client->ps.forceJumpCharge += forceJumpChargeInterval;
  10933. //clamp to max strength for current level
  10934. if ( self->client->ps.forceJumpCharge > forceJumpStrength[self->client->ps.forcePowerLevel[FP_LEVITATION]] )
  10935. {
  10936. self->client->ps.forceJumpCharge = forceJumpStrength[self->client->ps.forcePowerLevel[FP_LEVITATION]];
  10937. }
  10938. //clamp to max available force power
  10939. if ( self->client->ps.forceJumpCharge/forceJumpChargeInterval/(FORCE_JUMP_CHARGE_TIME/FRAMETIME)*forcePowerNeeded[FP_LEVITATION] > self->client->ps.forcePower )
  10940. {//can't use more than you have
  10941. self->client->ps.forceJumpCharge = self->client->ps.forcePower*forceJumpChargeInterval/(FORCE_JUMP_CHARGE_TIME/FRAMETIME);
  10942. }
  10943. //FIXME: a simple tap should always do at least a normal height's jump?
  10944. }
  10945. int WP_GetVelocityForForceJump( gentity_t *self, vec3_t jumpVel, usercmd_t *ucmd )
  10946. {
  10947. float pushFwd = 0, pushRt = 0;
  10948. vec3_t view, forward, right;
  10949. VectorCopy( self->client->ps.viewangles, view );
  10950. view[0] = 0;
  10951. AngleVectors( view, forward, right, NULL );
  10952. if ( ucmd->forwardmove && ucmd->rightmove )
  10953. {
  10954. if ( ucmd->forwardmove > 0 )
  10955. {
  10956. pushFwd = 50;
  10957. }
  10958. else
  10959. {
  10960. pushFwd = -50;
  10961. }
  10962. if ( ucmd->rightmove > 0 )
  10963. {
  10964. pushRt = 50;
  10965. }
  10966. else
  10967. {
  10968. pushRt = -50;
  10969. }
  10970. }
  10971. else if ( ucmd->forwardmove || ucmd->rightmove )
  10972. {
  10973. if ( ucmd->forwardmove > 0 )
  10974. {
  10975. pushFwd = 100;
  10976. }
  10977. else if ( ucmd->forwardmove < 0 )
  10978. {
  10979. pushFwd = -100;
  10980. }
  10981. else if ( ucmd->rightmove > 0 )
  10982. {
  10983. pushRt = 100;
  10984. }
  10985. else if ( ucmd->rightmove < 0 )
  10986. {
  10987. pushRt = -100;
  10988. }
  10989. }
  10990. VectorMA( self->client->ps.velocity, pushFwd, forward, jumpVel );
  10991. VectorMA( self->client->ps.velocity, pushRt, right, jumpVel );
  10992. jumpVel[2] += self->client->ps.forceJumpCharge;//forceJumpStrength;
  10993. if ( pushFwd > 0 && self->client->ps.forceJumpCharge > 200 )
  10994. {
  10995. return FJ_FORWARD;
  10996. }
  10997. else if ( pushFwd < 0 && self->client->ps.forceJumpCharge > 200 )
  10998. {
  10999. return FJ_BACKWARD;
  11000. }
  11001. else if ( pushRt > 0 && self->client->ps.forceJumpCharge > 200 )
  11002. {
  11003. return FJ_RIGHT;
  11004. }
  11005. else if ( pushRt < 0 && self->client->ps.forceJumpCharge > 200 )
  11006. {
  11007. return FJ_LEFT;
  11008. }
  11009. else
  11010. {//FIXME: jump straight up anim
  11011. return FJ_UP;
  11012. }
  11013. }
  11014. void ForceJump( gentity_t *self, usercmd_t *ucmd )
  11015. {
  11016. if ( self->client->ps.forcePowerDuration[FP_LEVITATION] > level.time )
  11017. {
  11018. return;
  11019. }
  11020. if ( !WP_ForcePowerUsable( self, FP_LEVITATION, 0 ) )
  11021. {
  11022. return;
  11023. }
  11024. if ( self->s.groundEntityNum == ENTITYNUM_NONE )
  11025. {
  11026. return;
  11027. }
  11028. if ( self->client->ps.pm_flags&PMF_JUMP_HELD )
  11029. {
  11030. return;
  11031. }
  11032. if ( self->health <= 0 )
  11033. {
  11034. return;
  11035. }
  11036. if ( !self->s.number && (cg.zoomMode || in_camera) )
  11037. {//can't force jump when zoomed in or in cinematic
  11038. return;
  11039. }
  11040. if ( self->client->ps.saberLockTime > level.time )
  11041. {//FIXME: can this be a way to break out?
  11042. return;
  11043. }
  11044. if ( self->client->NPC_class == CLASS_BOBAFETT
  11045. || self->client->NPC_class == CLASS_ROCKETTROOPER )
  11046. {
  11047. if ( self->client->ps.forceJumpCharge > 300 )
  11048. {
  11049. JET_FlyStart(NPC);
  11050. }
  11051. else
  11052. {
  11053. G_AddEvent( self, EV_JUMP, 0 );
  11054. }
  11055. }
  11056. else
  11057. {
  11058. G_SoundOnEnt( self, CHAN_BODY, "sound/weapons/force/jump.wav" );
  11059. }
  11060. #ifdef _IMMERSION
  11061. G_Force( self, G_ForceIndex( "fffx/weapons/force/jump", FF_CHANNEL_WEAPON ) );
  11062. #endif // _IMMERSION
  11063. float forceJumpChargeInterval = forceJumpStrength[self->client->ps.forcePowerLevel[FP_LEVITATION]]/(FORCE_JUMP_CHARGE_TIME/FRAMETIME);
  11064. int anim;
  11065. vec3_t jumpVel;
  11066. switch( WP_GetVelocityForForceJump( self, jumpVel, ucmd ) )
  11067. {
  11068. case FJ_FORWARD:
  11069. if ( ((self->client->NPC_class == CLASS_BOBAFETT||self->client->NPC_class == CLASS_ROCKETTROOPER) && self->client->ps.forceJumpCharge > 300 )
  11070. || ( self->NPC &&
  11071. self->NPC->rank != RANK_CREWMAN &&
  11072. self->NPC->rank <= RANK_LT_JG ) )
  11073. {//can't do acrobatics
  11074. anim = BOTH_FORCEJUMP1;
  11075. }
  11076. else
  11077. {
  11078. if ( self->client->NPC_class == CLASS_ALORA && Q_irand( 0, 3 ) )
  11079. {
  11080. anim = Q_irand( BOTH_ALORA_FLIP_1, BOTH_ALORA_FLIP_3 );
  11081. }
  11082. else
  11083. {
  11084. anim = BOTH_FLIP_F;
  11085. }
  11086. }
  11087. break;
  11088. case FJ_BACKWARD:
  11089. if ( ((self->client->NPC_class == CLASS_BOBAFETT||self->client->NPC_class == CLASS_ROCKETTROOPER) && self->client->ps.forceJumpCharge > 300 )
  11090. || ( self->NPC &&
  11091. self->NPC->rank != RANK_CREWMAN &&
  11092. self->NPC->rank <= RANK_LT_JG ) )
  11093. {//can't do acrobatics
  11094. anim = BOTH_FORCEJUMPBACK1;
  11095. }
  11096. else
  11097. {
  11098. anim = BOTH_FLIP_B;
  11099. }
  11100. break;
  11101. case FJ_RIGHT:
  11102. if ( ((self->client->NPC_class == CLASS_BOBAFETT||self->client->NPC_class == CLASS_ROCKETTROOPER) && self->client->ps.forceJumpCharge > 300 )
  11103. || ( self->NPC &&
  11104. self->NPC->rank != RANK_CREWMAN &&
  11105. self->NPC->rank <= RANK_LT_JG ) )
  11106. {//can't do acrobatics
  11107. anim = BOTH_FORCEJUMPRIGHT1;
  11108. }
  11109. else
  11110. {
  11111. anim = BOTH_FLIP_R;
  11112. }
  11113. break;
  11114. case FJ_LEFT:
  11115. if ( ((self->client->NPC_class == CLASS_BOBAFETT||self->client->NPC_class == CLASS_ROCKETTROOPER) && self->client->ps.forceJumpCharge > 300 )
  11116. || ( self->NPC &&
  11117. self->NPC->rank != RANK_CREWMAN &&
  11118. self->NPC->rank <= RANK_LT_JG ) )
  11119. {//can't do acrobatics
  11120. anim = BOTH_FORCEJUMPLEFT1;
  11121. }
  11122. else
  11123. {
  11124. anim = BOTH_FLIP_L;
  11125. }
  11126. break;
  11127. default:
  11128. case FJ_UP:
  11129. anim = BOTH_JUMP1;
  11130. break;
  11131. }
  11132. int parts = SETANIM_BOTH;
  11133. if ( self->client->ps.weaponTime )
  11134. {//FIXME: really only care if we're in a saber attack anim.. maybe trail length?
  11135. parts = SETANIM_LEGS;
  11136. }
  11137. NPC_SetAnim( self, parts, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11138. //FIXME: sound effect
  11139. self->client->ps.forceJumpZStart = self->currentOrigin[2];//remember this for when we land
  11140. VectorCopy( jumpVel, self->client->ps.velocity );
  11141. //wasn't allowing them to attack when jumping, but that was annoying
  11142. //self->client->ps.weaponTime = self->client->ps.torsoAnimTimer;
  11143. WP_ForcePowerStart( self, FP_LEVITATION, self->client->ps.forceJumpCharge/forceJumpChargeInterval/(FORCE_JUMP_CHARGE_TIME/FRAMETIME)*forcePowerNeeded[FP_LEVITATION] );
  11144. //self->client->ps.forcePowerDuration[FP_LEVITATION] = level.time + self->client->ps.weaponTime;
  11145. self->client->ps.forceJumpCharge = 0;
  11146. }
  11147. int WP_AbsorbConversion(gentity_t *attacked, int atdAbsLevel, gentity_t *attacker, int atPower, int atPowerLevel, int atForceSpent)
  11148. {
  11149. int getLevel = 0;
  11150. int addTot = 0;
  11151. if (atPower != FP_LIGHTNING &&
  11152. atPower != FP_DRAIN &&
  11153. atPower != FP_GRIP &&
  11154. atPower != FP_PUSH &&
  11155. atPower != FP_PULL)
  11156. { //Only these powers can be absorbed
  11157. return -1;
  11158. }
  11159. if (!atdAbsLevel)
  11160. { //looks like attacker doesn't have any absorb power
  11161. return -1;
  11162. }
  11163. if (!(attacked->client->ps.forcePowersActive & (1 << FP_ABSORB)))
  11164. { //absorb is not active
  11165. return -1;
  11166. }
  11167. //Subtract absorb power level from the offensive force power
  11168. getLevel = atPowerLevel;
  11169. getLevel -= atdAbsLevel;
  11170. if (getLevel < 0)
  11171. {
  11172. getLevel = 0;
  11173. }
  11174. //let the attacker absorb an amount of force used in this attack based on his level of absorb
  11175. addTot = (atForceSpent/3)*attacked->client->ps.forcePowerLevel[FP_ABSORB];
  11176. if (addTot < 1 && atForceSpent >= 1)
  11177. {
  11178. addTot = 1;
  11179. }
  11180. attacked->client->ps.forcePower += addTot;
  11181. if (attacked->client->ps.forcePower > 100)
  11182. {
  11183. attacked->client->ps.forcePower = 100;
  11184. }
  11185. G_SoundOnEnt( attacked, CHAN_ITEM, "sound/weapons/force/absorbhit.wav" );
  11186. return getLevel;
  11187. }
  11188. void WP_ForcePowerRegenerate( gentity_t *self, int overrideAmt )
  11189. {
  11190. if ( !self->client )
  11191. {
  11192. return;
  11193. }
  11194. if ( self->client->ps.forcePower < self->client->ps.forcePowerMax )
  11195. {
  11196. if ( overrideAmt )
  11197. {
  11198. self->client->ps.forcePower += overrideAmt;
  11199. }
  11200. else
  11201. {
  11202. self->client->ps.forcePower++;
  11203. }
  11204. if ( self->client->ps.forcePower > self->client->ps.forcePowerMax )
  11205. {
  11206. self->client->ps.forcePower = self->client->ps.forcePowerMax;
  11207. }
  11208. }
  11209. }
  11210. static bool infiniteForce = false;
  11211. bool Cheat_InfiniteForce( void )
  11212. {
  11213. infiniteForce = !infiniteForce;
  11214. return true;
  11215. }
  11216. void WP_ForcePowerDrain( gentity_t *self, forcePowers_t forcePower, int overrideAmt )
  11217. {
  11218. // PCs have infinite force power when the cheat is turned on
  11219. if ( self->NPC || infiniteForce )
  11220. {//For now, NPCs have infinite force power
  11221. return;
  11222. }
  11223. //take away the power
  11224. int drain = overrideAmt;
  11225. if ( !drain )
  11226. {
  11227. drain = forcePowerNeeded[forcePower];
  11228. }
  11229. if ( !drain )
  11230. {
  11231. return;
  11232. }
  11233. self->client->ps.forcePower -= drain;
  11234. if ( self->client->ps.forcePower < 0 )
  11235. {
  11236. self->client->ps.forcePower = 0;
  11237. }
  11238. }
  11239. void WP_ForcePowerStart( gentity_t *self, forcePowers_t forcePower, int overrideAmt )
  11240. {
  11241. int duration = 0;
  11242. //FIXME: debounce some of these?
  11243. self->client->ps.forcePowerDebounce[forcePower] = 0;
  11244. //and it in
  11245. //set up duration time
  11246. switch( (int)forcePower )
  11247. {
  11248. case FP_HEAL:
  11249. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11250. self->client->ps.forceHealCount = 0;
  11251. WP_StartForceHealEffects( self );
  11252. break;
  11253. case FP_LEVITATION:
  11254. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11255. break;
  11256. case FP_SPEED:
  11257. //duration is always 5 seconds, player time
  11258. duration = ceil(FORCE_SPEED_DURATION*forceSpeedValue[self->client->ps.forcePowerLevel[FP_SPEED]]);//FIXME: because the timescale scales down (not instant), this doesn't end up being exactly right...
  11259. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11260. self->s.loopSound = G_SoundIndex( "sound/weapons/force/speedloop.wav" );
  11261. if ( self->client->ps.forcePowerLevel[FP_SPEED] > FORCE_LEVEL_2 )
  11262. {//HACK: just using this as a timestamp for when the power started, setting debounce to current time shouldn't adversely affect anything else
  11263. self->client->ps.forcePowerDebounce[FP_SPEED] = level.time;
  11264. }
  11265. break;
  11266. case FP_PUSH:
  11267. break;
  11268. case FP_PULL:
  11269. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11270. break;
  11271. case FP_TELEPATHY:
  11272. break;
  11273. case FP_GRIP:
  11274. duration = 1000;
  11275. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11276. //HACK: just using this as a timestamp for when the power started, setting debounce to current time shouldn't adversely affect anything else
  11277. //self->client->ps.forcePowerDebounce[forcePower] = level.time;
  11278. break;
  11279. case FP_LIGHTNING:
  11280. duration = overrideAmt;
  11281. overrideAmt = 0;
  11282. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11283. break;
  11284. //new Jedi Academy force powers
  11285. case FP_RAGE:
  11286. //duration is always 5 seconds, player time
  11287. duration = ceil(FORCE_RAGE_DURATION*forceSpeedValue[self->client->ps.forcePowerLevel[FP_RAGE]-1]);//FIXME: because the timescale scales down (not instant), this doesn't end up being exactly right...
  11288. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11289. G_SoundOnEnt( self, CHAN_ITEM, "sound/weapons/force/rage.mp3" );
  11290. self->s.loopSound = G_SoundIndex( "sound/weapons/force/rageloop.wav" );
  11291. if ( self->chestBolt != -1 )
  11292. {
  11293. G_PlayEffect( G_EffectIndex( "force/rage2" ), self->playerModel, self->chestBolt, self->s.number, self->currentOrigin, duration, qtrue );
  11294. }
  11295. break;
  11296. case FP_DRAIN:
  11297. if ( self->client->ps.forcePowerLevel[forcePower] > FORCE_LEVEL_1
  11298. && self->client->ps.forceDrainEntityNum >= ENTITYNUM_WORLD )
  11299. {
  11300. duration = overrideAmt;
  11301. overrideAmt = 0;
  11302. //HACK: just using this as a timestamp for when the power started, setting debounce to current time shouldn't adversely affect anything else
  11303. self->client->ps.forcePowerDebounce[forcePower] = level.time;
  11304. }
  11305. else
  11306. {
  11307. duration = 1000;
  11308. }
  11309. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11310. break;
  11311. case FP_PROTECT:
  11312. switch ( self->client->ps.forcePowerLevel[FP_PROTECT] )
  11313. {
  11314. case FORCE_LEVEL_3:
  11315. duration = 20000;
  11316. break;
  11317. case FORCE_LEVEL_2:
  11318. duration = 15000;
  11319. break;
  11320. case FORCE_LEVEL_1:
  11321. default:
  11322. duration = 10000;
  11323. break;
  11324. }
  11325. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11326. G_SoundOnEnt( self, CHAN_ITEM, "sound/weapons/force/protect.mp3" );
  11327. self->s.loopSound = G_SoundIndex( "sound/weapons/force/protectloop.wav" );
  11328. break;
  11329. case FP_ABSORB:
  11330. duration = 20000;
  11331. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11332. G_SoundOnEnt( self, CHAN_ITEM, "sound/weapons/force/absorb.mp3" );
  11333. self->s.loopSound = G_SoundIndex( "sound/weapons/force/absorbloop.wav" );
  11334. break;
  11335. case FP_SEE:
  11336. if ( self->client->ps.forcePowerLevel[FP_SEE] == FORCE_LEVEL_1 )
  11337. {
  11338. duration = 5000;
  11339. }
  11340. else if ( self->client->ps.forcePowerLevel[FP_SEE] == FORCE_LEVEL_2 )
  11341. {
  11342. duration = 10000;
  11343. }
  11344. else// if ( self->client->ps.forcePowerLevel[FP_SEE] == FORCE_LEVEL_3 )
  11345. {
  11346. duration = 20000;
  11347. }
  11348. self->client->ps.forcePowersActive |= ( 1 << forcePower );
  11349. G_SoundOnEnt( self, CHAN_ITEM, "sound/weapons/force/see.mp3" );
  11350. self->s.loopSound = G_SoundIndex( "sound/weapons/force/seeloop.wav" );
  11351. break;
  11352. default:
  11353. break;
  11354. }
  11355. if ( duration )
  11356. {
  11357. self->client->ps.forcePowerDuration[forcePower] = level.time + duration;
  11358. }
  11359. else
  11360. {
  11361. self->client->ps.forcePowerDuration[forcePower] = 0;
  11362. }
  11363. WP_ForcePowerDrain( self, forcePower, overrideAmt );
  11364. if ( !self->s.number )
  11365. {
  11366. self->client->sess.missionStats.forceUsed[(int)forcePower]++;
  11367. }
  11368. }
  11369. qboolean WP_ForcePowerAvailable( gentity_t *self, forcePowers_t forcePower, int overrideAmt )
  11370. {
  11371. if ( forcePower == FP_LEVITATION )
  11372. {
  11373. return qtrue;
  11374. }
  11375. int drain = overrideAmt?overrideAmt:forcePowerNeeded[forcePower];
  11376. if ( !drain )
  11377. {
  11378. return qtrue;
  11379. }
  11380. if ( self->client->ps.forcePower < drain )
  11381. {
  11382. //G_AddEvent( self, EV_NOAMMO, 0 );
  11383. return qfalse;
  11384. }
  11385. return qtrue;
  11386. }
  11387. extern void CG_PlayerLockedWeaponSpeech( int jumping );
  11388. extern qboolean Rosh_TwinNearBy( gentity_t *self );
  11389. qboolean WP_ForcePowerUsable( gentity_t *self, forcePowers_t forcePower, int overrideAmt )
  11390. {
  11391. if ( !(self->client->ps.forcePowersKnown & ( 1 << forcePower )) )
  11392. {//don't know this power
  11393. return qfalse;
  11394. }
  11395. else if ( self->NPC && (self->NPC->aiFlags&NPCAI_ROSH) )
  11396. {
  11397. if ( ((1<<forcePower)&FORCE_POWERS_ROSH_FROM_TWINS) )
  11398. {//this is a force power we can only use when a twin is near us
  11399. if ( !Rosh_TwinNearBy( self ) )
  11400. {
  11401. return qfalse;
  11402. }
  11403. }
  11404. }
  11405. if ( self->client->ps.forcePowerLevel[forcePower] <= 0 )
  11406. {//can't use this power
  11407. return qfalse;
  11408. }
  11409. if( (self->flags&FL_LOCK_PLAYER_WEAPONS) ) // yes this locked weapons check also includes force powers, if we need a separate check later I'll make one
  11410. {
  11411. if ( self->s.number < MAX_CLIENTS )
  11412. {
  11413. CG_PlayerLockedWeaponSpeech( qfalse );
  11414. }
  11415. return qfalse;
  11416. }
  11417. if ( in_camera && self->s.number < MAX_CLIENTS )
  11418. {//player can't turn on force powers duing cinematics
  11419. return qfalse;
  11420. }
  11421. if ( PM_LockedAnim( self->client->ps.torsoAnim ) && self->client->ps.torsoAnimTimer )
  11422. {//no force powers during these special anims
  11423. return qfalse;
  11424. }
  11425. if ( PM_SuperBreakLoseAnim( self->client->ps.torsoAnim )
  11426. || PM_SuperBreakWinAnim( self->client->ps.torsoAnim ) )
  11427. {
  11428. return qfalse;
  11429. }
  11430. if ( (self->client->ps.forcePowersActive & ( 1 << forcePower )) )
  11431. {//already using this power
  11432. return qfalse;
  11433. }
  11434. /*
  11435. if ( !self->client->ps.forcePowerLevel[(int)(forcePower)] )
  11436. {
  11437. return qfalse;
  11438. }
  11439. */
  11440. if ( self->client->NPC_class == CLASS_ATST )
  11441. {//Doh! No force powers in an AT-ST!
  11442. return qfalse;
  11443. }
  11444. Vehicle_t *pVeh = NULL;
  11445. if ( (pVeh = G_IsRidingVehicle( self )) != NULL )
  11446. {//Doh! No force powers when flying a vehicle!
  11447. if ( pVeh->m_pVehicleInfo->numHands > 1 )
  11448. {//if in a two-handed vehicle
  11449. return qfalse;
  11450. }
  11451. }
  11452. if ( self->client->ps.viewEntity > 0 && self->client->ps.viewEntity < ENTITYNUM_WORLD )
  11453. {//Doh! No force powers when controlling an NPC
  11454. return qfalse;
  11455. }
  11456. if ( self->client->ps.eFlags & EF_LOCKED_TO_WEAPON )
  11457. {//Doh! No force powers when in an emplaced gun!
  11458. return qfalse;
  11459. }
  11460. if ( self->client->ps.saber[0].singleBladeThrowable//SaberStaff() //using staff
  11461. && !self->client->ps.dualSabers //only 1, in right hand
  11462. && !self->client->ps.saber[0].blade[1].active )//only first blade is on
  11463. {//allow power
  11464. //FIXME: externalize this condition seperately?
  11465. }
  11466. else
  11467. {
  11468. if ( forcePower == FP_SABERTHROW && !self->client->ps.saber[0].throwable )
  11469. {//cannot throw this kind of saber
  11470. return qfalse;
  11471. }
  11472. if ( self->client->ps.saber[0].Active() )
  11473. {
  11474. if ( self->client->ps.saber[0].twoHanded )
  11475. {
  11476. if ( g_saberRestrictForce->integer )
  11477. {
  11478. switch ( forcePower )
  11479. {
  11480. case FP_PUSH:
  11481. case FP_PULL:
  11482. case FP_TELEPATHY:
  11483. case FP_GRIP:
  11484. case FP_LIGHTNING:
  11485. case FP_DRAIN:
  11486. return qfalse;
  11487. break;
  11488. }
  11489. }
  11490. }
  11491. if ( self->client->ps.saber[0].twoHanded || (self->client->ps.dualSabers && self->client->ps.saber[1].Active()) )
  11492. {//this saber requires the use of two hands OR our other hand is using an active saber too
  11493. if ( (self->client->ps.saber[0].forceRestrictions&(1<<forcePower)) )
  11494. {//this power is verboten when using this saber
  11495. return qfalse;
  11496. }
  11497. }
  11498. }
  11499. if ( self->client->ps.dualSabers && self->client->ps.saber[1].Active() )
  11500. {
  11501. if ( g_saberRestrictForce->integer )
  11502. {
  11503. switch ( forcePower )
  11504. {
  11505. case FP_PUSH:
  11506. case FP_PULL:
  11507. case FP_TELEPATHY:
  11508. case FP_GRIP:
  11509. case FP_LIGHTNING:
  11510. case FP_DRAIN:
  11511. return qfalse;
  11512. break;
  11513. }
  11514. }
  11515. if ( (self->client->ps.saber[1].forceRestrictions&(1<<forcePower)) )
  11516. {//this power is verboten when using this saber
  11517. return qfalse;
  11518. }
  11519. }
  11520. }
  11521. return WP_ForcePowerAvailable( self, forcePower, overrideAmt );
  11522. }
  11523. void WP_ForcePowerStop( gentity_t *self, forcePowers_t forcePower )
  11524. {
  11525. gentity_t *gripEnt;
  11526. gentity_t *drainEnt;
  11527. if ( !(self->client->ps.forcePowersActive&(1<<forcePower)) )
  11528. {//umm, wasn't doing it, so...
  11529. return;
  11530. }
  11531. self->client->ps.forcePowersActive &= ~( 1 << forcePower );
  11532. switch( (int)forcePower )
  11533. {
  11534. case FP_HEAL:
  11535. //if ( self->client->ps.forcePowerLevel[FP_HEAL] < FORCE_LEVEL_3 )
  11536. {//wasn't an instant heal and heal is now done
  11537. if ( self->client->ps.forcePowerLevel[FP_HEAL] < FORCE_LEVEL_2 )
  11538. {//if in meditation pose, must come out of it
  11539. //FIXME: BOTH_FORCEHEAL_STOP
  11540. if ( self->client->ps.legsAnim == BOTH_FORCEHEAL_START )
  11541. {
  11542. NPC_SetAnim( self, SETANIM_LEGS, BOTH_FORCEHEAL_STOP, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11543. }
  11544. if ( self->client->ps.torsoAnim == BOTH_FORCEHEAL_START )
  11545. {
  11546. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCEHEAL_STOP, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11547. }
  11548. self->client->ps.saberMove = self->client->ps.saberBounceMove = LS_READY;//don't finish whatever saber anim you may have been in
  11549. self->client->ps.saberBlocked = BLOCKED_NONE;
  11550. }
  11551. }
  11552. WP_StopForceHealEffects( self );
  11553. if (self->health >= self->client->ps.stats[STAT_MAX_HEALTH]/3)
  11554. {
  11555. gi.G2API_ClearSkinGore(self->ghoul2);
  11556. }
  11557. break;
  11558. case FP_LEVITATION:
  11559. self->client->ps.forcePowerDebounce[FP_LEVITATION] = 0;
  11560. break;
  11561. case FP_SPEED:
  11562. if ( !self->s.number )
  11563. {//player using force speed
  11564. if ( g_timescale->value != 1.0 )
  11565. {
  11566. if ( !(self->client->ps.forcePowersActive&(1<<FP_RAGE))||self->client->ps.forcePowerLevel[FP_RAGE] < FORCE_LEVEL_2 )
  11567. {//not slowed down because of force rage
  11568. gi.cvar_set("timescale", "1");
  11569. }
  11570. }
  11571. }
  11572. //FIXME: reset my current anim, keeping current frame, but with proper anim speed
  11573. // otherwise, the anim will continue playing at high speed
  11574. self->s.loopSound = 0;
  11575. break;
  11576. case FP_PUSH:
  11577. break;
  11578. case FP_PULL:
  11579. break;
  11580. case FP_TELEPATHY:
  11581. break;
  11582. case FP_GRIP:
  11583. if ( self->NPC )
  11584. {
  11585. TIMER_Set( self, "gripping", -level.time );
  11586. }
  11587. if ( self->client->ps.forceGripEntityNum < ENTITYNUM_WORLD )
  11588. {
  11589. gripEnt = &g_entities[self->client->ps.forceGripEntityNum];
  11590. if ( gripEnt )
  11591. {
  11592. gripEnt->s.loopSound = 0;
  11593. if ( gripEnt->client )
  11594. {
  11595. gripEnt->client->ps.eFlags &= ~EF_FORCE_GRIPPED;
  11596. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 )
  11597. {//sanity-cap the velocity
  11598. float gripVel = VectorNormalize( gripEnt->client->ps.velocity );
  11599. if ( gripVel > 500.0f )
  11600. {
  11601. gripVel = 500.0f;
  11602. }
  11603. VectorScale( gripEnt->client->ps.velocity, gripVel, gripEnt->client->ps.velocity );
  11604. }
  11605. //FIXME: they probably dropped their weapon, should we make them flee? Or should AI handle no-weapon behavior?
  11606. //rww - RAGDOLL_BEGIN
  11607. #ifndef JK2_RAGDOLL_GRIPNOHEALTH
  11608. //rww - RAGDOLL_END
  11609. if ( gripEnt->health > 0 )
  11610. //rww - RAGDOLL_BEGIN
  11611. #endif
  11612. //rww - RAGDOLL_END
  11613. {
  11614. int holdTime = 500;
  11615. if ( gripEnt->health > 0 )
  11616. {
  11617. G_AddEvent( gripEnt, EV_WATER_CLEAR, 0 );
  11618. }
  11619. if ( gripEnt->client->ps.forcePowerDebounce[FP_PUSH] > level.time )
  11620. {//they probably pushed out of it
  11621. holdTime = 0;
  11622. }
  11623. else if ( gripEnt->s.weapon == WP_SABER )
  11624. {//jedi recover faster
  11625. holdTime = self->client->ps.forcePowerLevel[FP_GRIP]*200;
  11626. }
  11627. else
  11628. {
  11629. holdTime = self->client->ps.forcePowerLevel[FP_GRIP]*500;
  11630. }
  11631. //stop the anims soon, keep them locked in place for a bit
  11632. if ( gripEnt->client->ps.torsoAnim == BOTH_CHOKE1 || gripEnt->client->ps.torsoAnim == BOTH_CHOKE3 )
  11633. {//stop choking anim on torso
  11634. if ( gripEnt->client->ps.torsoAnimTimer > holdTime )
  11635. {
  11636. gripEnt->client->ps.torsoAnimTimer = holdTime;
  11637. }
  11638. }
  11639. if ( gripEnt->client->ps.legsAnim == BOTH_CHOKE1 || gripEnt->client->ps.legsAnim == BOTH_CHOKE3 )
  11640. {//stop choking anim on legs
  11641. gripEnt->client->ps.legsAnimTimer = 0;
  11642. if ( holdTime )
  11643. {
  11644. //lock them in place for a bit
  11645. gripEnt->client->ps.pm_time = gripEnt->client->ps.torsoAnimTimer;
  11646. gripEnt->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  11647. if ( gripEnt->s.number )
  11648. {//NPC
  11649. gripEnt->painDebounceTime = level.time + gripEnt->client->ps.torsoAnimTimer;
  11650. }
  11651. else
  11652. {//player
  11653. gripEnt->aimDebounceTime = level.time + gripEnt->client->ps.torsoAnimTimer;
  11654. }
  11655. }
  11656. }
  11657. if ( gripEnt->NPC )
  11658. {
  11659. if ( !(gripEnt->NPC->aiFlags&NPCAI_DIE_ON_IMPACT) )
  11660. {//not falling to their death
  11661. gripEnt->NPC->nextBStateThink = level.time + holdTime;
  11662. }
  11663. //if still alive after stopped gripping, let them wake others up
  11664. if ( gripEnt->health > 0 )
  11665. {
  11666. G_AngerAlert( gripEnt );
  11667. }
  11668. }
  11669. }
  11670. }
  11671. else
  11672. {
  11673. gripEnt->s.eFlags &= ~EF_FORCE_GRIPPED;
  11674. if ( gripEnt->s.eType == ET_MISSILE )
  11675. {//continue normal movement
  11676. if ( gripEnt->s.weapon == WP_THERMAL )
  11677. {
  11678. gripEnt->s.pos.trType = TR_INTERPOLATE;
  11679. }
  11680. else
  11681. {
  11682. gripEnt->s.pos.trType = TR_LINEAR;//FIXME: what about gravity-effected projectiles?
  11683. }
  11684. VectorCopy( gripEnt->currentOrigin, gripEnt->s.pos.trBase );
  11685. gripEnt->s.pos.trTime = level.time;
  11686. }
  11687. else
  11688. {//drop it
  11689. gripEnt->e_ThinkFunc = thinkF_G_RunObject;
  11690. gripEnt->nextthink = level.time + FRAMETIME;
  11691. gripEnt->s.pos.trType = TR_GRAVITY;
  11692. VectorCopy( gripEnt->currentOrigin, gripEnt->s.pos.trBase );
  11693. gripEnt->s.pos.trTime = level.time;
  11694. }
  11695. }
  11696. }
  11697. self->s.loopSound = 0;
  11698. self->client->ps.forceGripEntityNum = ENTITYNUM_NONE;
  11699. }
  11700. if ( self->client->ps.torsoAnim == BOTH_FORCEGRIP_HOLD )
  11701. {
  11702. NPC_SetAnim( self, SETANIM_BOTH, BOTH_FORCEGRIP_RELEASE, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11703. }
  11704. break;
  11705. case FP_LIGHTNING:
  11706. if ( self->NPC )
  11707. {
  11708. TIMER_Set( self, "holdLightning", -level.time );
  11709. }
  11710. if ( self->client->ps.torsoAnim == BOTH_FORCELIGHTNING_HOLD
  11711. || self->client->ps.torsoAnim == BOTH_FORCELIGHTNING_START )
  11712. {
  11713. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCELIGHTNING_RELEASE, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11714. }
  11715. else if ( self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING_HOLD
  11716. || self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING_START )
  11717. {
  11718. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCE_2HANDEDLIGHTNING_RELEASE, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11719. }
  11720. if ( self->client->ps.forcePowerLevel[FP_LIGHTNING] < FORCE_LEVEL_2 )
  11721. {//don't do it again for 3 seconds, minimum... FIXME: this should be automatic once regeneration is slower (normal)
  11722. self->client->ps.forcePowerDebounce[FP_LIGHTNING] = level.time + 3000;//FIXME: define?
  11723. }
  11724. else
  11725. {//stop the looping sound
  11726. self->client->ps.forcePowerDebounce[FP_LIGHTNING] = level.time + 1000;//FIXME: define?
  11727. self->s.loopSound = 0;
  11728. }
  11729. break;
  11730. case FP_RAGE:
  11731. self->client->ps.forceRageRecoveryTime = level.time + 10000;//recover for 10 seconds
  11732. if ( self->client->ps.forcePowerDuration[FP_RAGE] > level.time )
  11733. {//still had time left, we cut it short
  11734. self->client->ps.forceRageRecoveryTime -= (self->client->ps.forcePowerDuration[FP_RAGE] - level.time);//minus however much time you had left when you cut it short
  11735. }
  11736. if ( !self->s.number )
  11737. {//player using force speed
  11738. if ( g_timescale->value != 1.0 )
  11739. {
  11740. if ( !(self->client->ps.forcePowersActive&(1<<FP_SPEED)) )
  11741. {//not slowed down because of force speed
  11742. gi.cvar_set("timescale", "1");
  11743. }
  11744. }
  11745. }
  11746. //FIXME: reset my current anim, keeping current frame, but with proper anim speed
  11747. // otherwise, the anim will continue playing at high speed
  11748. self->s.loopSound = 0;
  11749. if ( self->NPC )
  11750. {
  11751. Jedi_RageStop( self );
  11752. }
  11753. if ( self->chestBolt != -1 )
  11754. {
  11755. G_StopEffect("force/rage2", self->playerModel, self->chestBolt, self->s.number );
  11756. }
  11757. break;
  11758. case FP_DRAIN:
  11759. if ( self->NPC )
  11760. {
  11761. TIMER_Set( self, "draining", -level.time );
  11762. }
  11763. if ( self->client->ps.forcePowerLevel[FP_DRAIN] < FORCE_LEVEL_2 )
  11764. {//don't do it again for 3 seconds, minimum... FIXME: this should be automatic once regeneration is slower (normal)
  11765. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + 3000;//FIXME: define?
  11766. }
  11767. else
  11768. {//stop the looping sound
  11769. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + 1000;//FIXME: define?
  11770. self->s.loopSound = 0;
  11771. }
  11772. //drop them
  11773. if ( self->client->ps.forceDrainEntityNum < ENTITYNUM_WORLD )
  11774. {
  11775. drainEnt = &g_entities[self->client->ps.forceDrainEntityNum];
  11776. if ( drainEnt )
  11777. {
  11778. if ( drainEnt->client )
  11779. {
  11780. drainEnt->client->ps.eFlags &= ~EF_FORCE_DRAINED;
  11781. //VectorClear( drainEnt->client->ps.velocity );
  11782. if ( drainEnt->health > 0 )
  11783. {
  11784. if ( drainEnt->client->ps.forcePowerDebounce[FP_PUSH] > level.time )
  11785. {//they probably pushed out of it
  11786. }
  11787. else
  11788. {
  11789. //NPC_SetAnim( drainEnt, SETANIM_BOTH, BOTH_HUGGEESTOP1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11790. if ( drainEnt->client->ps.torsoAnim != BOTH_FORCEPUSH )
  11791. {//don't stop the push
  11792. drainEnt->client->ps.torsoAnimTimer = 0;
  11793. }
  11794. drainEnt->client->ps.legsAnimTimer = 0;
  11795. }
  11796. if ( drainEnt->NPC )
  11797. {//if still alive after stopped draining, let them wake others up
  11798. G_AngerAlert( drainEnt );
  11799. }
  11800. }
  11801. else
  11802. {//leave the effect playing on them for a few seconds
  11803. //drainEnt->client->ps.eFlags |= EF_FORCE_DRAINED;
  11804. drainEnt->s.powerups |= ( 1 << PW_DRAINED );
  11805. drainEnt->client->ps.powerups[PW_DRAINED] = level.time + Q_irand( 1000, 4000 );
  11806. }
  11807. }
  11808. }
  11809. self->client->ps.forceDrainEntityNum = ENTITYNUM_NONE;
  11810. }
  11811. if ( self->client->ps.torsoAnim == BOTH_HUGGER1 )
  11812. {//old anim
  11813. NPC_SetAnim( self, SETANIM_BOTH, BOTH_HUGGERSTOP1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11814. }
  11815. else if ( self->client->ps.torsoAnim == BOTH_FORCE_DRAIN_GRAB_START
  11816. || self->client->ps.torsoAnim == BOTH_FORCE_DRAIN_GRAB_HOLD )
  11817. {//new anim
  11818. NPC_SetAnim( self, SETANIM_BOTH, BOTH_FORCE_DRAIN_GRAB_END, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11819. }
  11820. else if ( self->client->ps.torsoAnim == BOTH_FORCE_DRAIN_HOLD
  11821. || self->client->ps.torsoAnim == BOTH_FORCE_DRAIN_START )
  11822. {
  11823. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCE_DRAIN_RELEASE, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11824. }
  11825. break;
  11826. case FP_PROTECT:
  11827. self->s.loopSound = 0;
  11828. break;
  11829. case FP_ABSORB:
  11830. self->s.loopSound = 0;
  11831. if ( self->client->ps.legsAnim == BOTH_FORCE_ABSORB_START )
  11832. {
  11833. NPC_SetAnim( self, SETANIM_LEGS, BOTH_FORCE_ABSORB_END, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11834. }
  11835. if ( self->client->ps.torsoAnim == BOTH_FORCE_ABSORB_START )
  11836. {
  11837. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCE_ABSORB_END, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  11838. }
  11839. if ( self->client->ps.forcePowerLevel[FP_ABSORB] < FORCE_LEVEL_2 )
  11840. {//was stuck, free us in case we interrupted it or something
  11841. self->client->ps.weaponTime = 0;
  11842. self->client->ps.pm_flags &= ~PMF_TIME_KNOCKBACK;
  11843. self->client->ps.pm_time = 0;
  11844. if ( self->s.number )
  11845. {//NPC
  11846. self->painDebounceTime = 0;
  11847. }
  11848. else
  11849. {//player
  11850. self->aimDebounceTime = 0;
  11851. }
  11852. }
  11853. break;
  11854. case FP_SEE:
  11855. self->s.loopSound = 0;
  11856. break;
  11857. default:
  11858. break;
  11859. }
  11860. }
  11861. void WP_ForceForceThrow( gentity_t *thrower )
  11862. {
  11863. if ( !thrower || !thrower->client )
  11864. {
  11865. return;
  11866. }
  11867. qboolean removePush = qfalse;
  11868. qboolean relock = qfalse;
  11869. if ( !(thrower->client->ps.forcePowersKnown&(1<<FP_PUSH)) )
  11870. {//give them push just for this specific purpose
  11871. thrower->client->ps.forcePowersKnown |= (1<<FP_PUSH);
  11872. thrower->client->ps.forcePowerLevel[FP_PUSH] = FORCE_LEVEL_1;
  11873. removePush = qtrue;
  11874. }
  11875. if ( thrower->NPC
  11876. && (thrower->NPC->aiFlags&NPCAI_HEAL_ROSH)
  11877. && (thrower->flags&FL_LOCK_PLAYER_WEAPONS) )
  11878. {
  11879. thrower->flags &= ~FL_LOCK_PLAYER_WEAPONS;
  11880. relock = qtrue;
  11881. }
  11882. ForceThrow( thrower, qfalse );
  11883. if ( relock )
  11884. {
  11885. thrower->flags |= FL_LOCK_PLAYER_WEAPONS;
  11886. }
  11887. if ( thrower )
  11888. {//take it back off
  11889. thrower->client->ps.forcePowersKnown &= ~(1<<FP_PUSH);
  11890. thrower->client->ps.forcePowerLevel[FP_PUSH] = FORCE_LEVEL_0;
  11891. }
  11892. }
  11893. extern qboolean PM_ForceJumpingUp( gentity_t *gent );
  11894. static void WP_ForcePowerRun( gentity_t *self, forcePowers_t forcePower, usercmd_t *cmd )
  11895. {
  11896. float speed, newSpeed;
  11897. gentity_t *gripEnt, *drainEnt;
  11898. vec3_t angles, dir, gripOrg, gripEntOrg;
  11899. float dist;
  11900. extern usercmd_t ucmd;
  11901. switch( (int)forcePower )
  11902. {
  11903. case FP_HEAL:
  11904. if ( self->client->ps.forceHealCount >= FP_MaxForceHeal(self) || self->health >= self->client->ps.stats[STAT_MAX_HEALTH] )
  11905. {//fully healed or used up all 25
  11906. if ( !Q3_TaskIDPending( self, TID_CHAN_VOICE ) )
  11907. {
  11908. int index = Q_irand( 1, 4 );
  11909. if ( self->s.number < MAX_CLIENTS )
  11910. {
  11911. G_SoundOnEnt( self, CHAN_VOICE, va( "sound/weapons/force/heal%d_%c.mp3", index, g_sex->string[0] ) );
  11912. }
  11913. else if ( self->NPC )
  11914. {
  11915. if ( self->NPC->blockedSpeechDebounceTime <= level.time )
  11916. {//enough time has passed since our last speech
  11917. if ( Q3_TaskIDPending( self, TID_CHAN_VOICE ) )
  11918. {//not playing a scripted line
  11919. //say "Ahhh...."
  11920. if ( self->NPC->stats.sex == SEX_MALE
  11921. || self->NPC->stats.sex == SEX_NEUTRAL )
  11922. {
  11923. G_SoundOnEnt( self, CHAN_VOICE, va( "sound/weapons/force/heal%d_m.mp3", index ) );
  11924. }
  11925. else//all other sexes use female sounds
  11926. {
  11927. G_SoundOnEnt( self, CHAN_VOICE, va( "sound/weapons/force/heal%d_f.mp3", index ) );
  11928. }
  11929. }
  11930. }
  11931. }
  11932. #ifdef _IMMERSION
  11933. G_Force( self, G_ForceIndex( va( "fffx/weapons/force/heal%d", index ), FF_CHANNEL_WEAPON ) );
  11934. #endif // _IMMERSION
  11935. }
  11936. WP_ForcePowerStop( self, forcePower );
  11937. }
  11938. else if ( self->client->ps.forcePowerLevel[FP_HEAL] < FORCE_LEVEL_3 && ( (cmd->buttons&BUTTON_ATTACK) || (cmd->buttons&BUTTON_ALT_ATTACK) || self->painDebounceTime > level.time || (self->client->ps.weaponTime&&self->client->ps.weapon!=WP_NONE) ) )
  11939. {//attacked or was hit while healing...
  11940. //stop healing
  11941. WP_ForcePowerStop( self, forcePower );
  11942. }
  11943. else if ( self->client->ps.forcePowerLevel[FP_HEAL] < FORCE_LEVEL_2 && ( cmd->rightmove || cmd->forwardmove || cmd->upmove > 0 ) )
  11944. {//moved while healing... FIXME: also, in WP_ForcePowerStart, stop healing if any other force power is used
  11945. //stop healing
  11946. WP_ForcePowerStop( self, forcePower );
  11947. }
  11948. else if ( self->client->ps.forcePowerDebounce[FP_HEAL] < level.time )
  11949. {//time to heal again
  11950. if ( WP_ForcePowerAvailable( self, forcePower, 4 ) )
  11951. {//have available power
  11952. int healInterval = FP_ForceHealInterval( self );
  11953. int healAmount = 1;//hard, normal healing rate
  11954. if ( self->s.number < MAX_CLIENTS )
  11955. {
  11956. if ( g_spskill->integer == 1 )
  11957. {//medium, heal twice as fast
  11958. healAmount *= 2;
  11959. }
  11960. else if ( g_spskill->integer == 0 )
  11961. {//easy, heal 3 times as fast...
  11962. healAmount *= 3;
  11963. }
  11964. }
  11965. if ( self->health + healAmount > self->client->ps.stats[STAT_MAX_HEALTH] )
  11966. {
  11967. healAmount = self->client->ps.stats[STAT_MAX_HEALTH] - self->health;
  11968. }
  11969. self->health += healAmount;
  11970. self->client->ps.forceHealCount += healAmount;
  11971. self->client->ps.forcePowerDebounce[FP_HEAL] = level.time + healInterval;
  11972. WP_ForcePowerDrain( self, forcePower, 4 );
  11973. }
  11974. else
  11975. {//stop
  11976. WP_ForcePowerStop( self, forcePower );
  11977. }
  11978. }
  11979. break;
  11980. case FP_LEVITATION:
  11981. if ( self->client->ps.groundEntityNum != ENTITYNUM_NONE && !self->client->ps.forceJumpZStart )
  11982. {//done with jump
  11983. WP_ForcePowerStop( self, forcePower );
  11984. }
  11985. else
  11986. {
  11987. if ( PM_ForceJumpingUp( self ) )
  11988. {//holding jump in air
  11989. if ( cmd->upmove > 10 )
  11990. {//still trying to go up
  11991. if ( WP_ForcePowerAvailable( self, FP_LEVITATION, 1 ) )
  11992. {
  11993. if ( self->client->ps.forcePowerDebounce[FP_LEVITATION] < level.time )
  11994. {
  11995. WP_ForcePowerDrain( self, FP_LEVITATION, 5 );
  11996. self->client->ps.forcePowerDebounce[FP_LEVITATION] = level.time + 100;
  11997. }
  11998. self->client->ps.forcePowersActive |= ( 1 << FP_LEVITATION );
  11999. self->client->ps.forceJumpCharge = 1;//just used as a flag for the player, cleared when he lands
  12000. }
  12001. else
  12002. {//cut the jump short
  12003. WP_ForcePowerStop( self, forcePower );
  12004. }
  12005. }
  12006. else
  12007. {//cut the jump short
  12008. WP_ForcePowerStop( self, forcePower );
  12009. }
  12010. }
  12011. else
  12012. {
  12013. WP_ForcePowerStop( self, forcePower );
  12014. }
  12015. }
  12016. break;
  12017. case FP_SPEED:
  12018. speed = forceSpeedValue[self->client->ps.forcePowerLevel[FP_SPEED]];
  12019. if ( !self->s.number )
  12020. {//player using force speed
  12021. if ( !(self->client->ps.forcePowersActive&(1<<FP_RAGE))
  12022. || self->client->ps.forcePowerLevel[FP_SPEED] >= self->client->ps.forcePowerLevel[FP_RAGE] )
  12023. {//either not using rage or rage is at a lower level than speed
  12024. gi.cvar_set("timescale", va("%4.2f", speed));
  12025. if ( g_timescale->value > speed )
  12026. {
  12027. newSpeed = g_timescale->value - 0.05;
  12028. if ( newSpeed < speed )
  12029. {
  12030. newSpeed = speed;
  12031. }
  12032. gi.cvar_set("timescale", va("%4.2f", newSpeed));
  12033. }
  12034. }
  12035. }
  12036. break;
  12037. case FP_PUSH:
  12038. break;
  12039. case FP_PULL:
  12040. break;
  12041. case FP_TELEPATHY:
  12042. break;
  12043. case FP_GRIP:
  12044. if ( !WP_ForcePowerAvailable( self, FP_GRIP, 0 )
  12045. || (self->client->ps.forcePowerLevel[FP_GRIP]>FORCE_LEVEL_1&&!self->s.number&&!(cmd->buttons&BUTTON_FORCEGRIP)) )
  12046. {
  12047. WP_ForcePowerStop( self, FP_GRIP );
  12048. return;
  12049. }
  12050. else if ( self->client->ps.forceGripEntityNum >= 0 && self->client->ps.forceGripEntityNum < ENTITYNUM_WORLD )
  12051. {
  12052. gripEnt = &g_entities[self->client->ps.forceGripEntityNum];
  12053. if ( !gripEnt || !gripEnt->inuse )
  12054. {//invalid or freed ent
  12055. WP_ForcePowerStop( self, FP_GRIP );
  12056. return;
  12057. }
  12058. else
  12059. //rww - RAGDOLL_BEGIN
  12060. #ifndef JK2_RAGDOLL_GRIPNOHEALTH
  12061. //rww - RAGDOLL_END
  12062. if ( gripEnt->health <= 0 && gripEnt->takedamage )//FIXME: what about things that never had health or lose takedamage when they die?
  12063. {//either invalid ent, or dead ent
  12064. WP_ForcePowerStop( self, FP_GRIP );
  12065. return;
  12066. }
  12067. else
  12068. //rww - RAGDOLL_BEGIN
  12069. #endif
  12070. //rww - RAGDOLL_END
  12071. if ( self->client->ps.forcePowerLevel[FP_GRIP] == FORCE_LEVEL_1
  12072. && gripEnt->client
  12073. && gripEnt->client->ps.groundEntityNum == ENTITYNUM_NONE
  12074. && gripEnt->client->moveType != MT_FLYSWIM )
  12075. {
  12076. WP_ForcePowerStop( self, FP_GRIP );
  12077. return;
  12078. }
  12079. else if ( gripEnt->client && gripEnt->client->moveType == MT_FLYSWIM && VectorLengthSquared( gripEnt->client->ps.velocity ) > (300*300) )
  12080. {//flying creature broke free
  12081. WP_ForcePowerStop( self, FP_GRIP );
  12082. return;
  12083. }
  12084. else if ( gripEnt->client
  12085. && gripEnt->health>0 //dead dudes don't fly
  12086. && (gripEnt->client->NPC_class == CLASS_BOBAFETT || gripEnt->client->NPC_class == CLASS_ROCKETTROOPER)
  12087. && self->client->ps.forcePowerDebounce[FP_GRIP] < level.time
  12088. && !Q_irand( 0, 3 )
  12089. )
  12090. {//boba fett - fly away!
  12091. gripEnt->client->ps.forceJumpCharge = 0;//so we don't play the force flip anim
  12092. gripEnt->client->ps.velocity[2] = 250;
  12093. gripEnt->client->ps.forceJumpZStart = gripEnt->currentOrigin[2];//so we don't take damage if we land at same height
  12094. gripEnt->client->ps.pm_flags |= PMF_JUMPING;
  12095. G_AddEvent( gripEnt, EV_JUMP, 0 );
  12096. JET_FlyStart( gripEnt );
  12097. WP_ForcePowerStop( self, FP_GRIP );
  12098. return;
  12099. }
  12100. else if ( gripEnt->NPC
  12101. && gripEnt->client
  12102. && gripEnt->client->ps.forcePowersKnown
  12103. && (gripEnt->client->NPC_class==CLASS_REBORN||gripEnt->client->ps.weapon==WP_SABER)
  12104. && !Jedi_CultistDestroyer(gripEnt)
  12105. && !Q_irand( 0, 100-(gripEnt->NPC->stats.evasion*8)-(g_spskill->integer*20) ) )
  12106. {//a jedi who broke free FIXME: maybe have some minimum grip length- a reaction time?
  12107. WP_ForceForceThrow( gripEnt );
  12108. //FIXME: I need to go into some pushed back anim...
  12109. WP_ForcePowerStop( self, FP_GRIP );
  12110. return;
  12111. }
  12112. else if ( PM_SaberInAttack( self->client->ps.saberMove )
  12113. || PM_SaberInStart( self->client->ps.saberMove ) )
  12114. {//started an attack
  12115. WP_ForcePowerStop( self, FP_GRIP );
  12116. return;
  12117. }
  12118. else
  12119. {
  12120. int gripLevel = self->client->ps.forcePowerLevel[FP_GRIP];
  12121. if ( gripEnt->client )
  12122. {
  12123. gripLevel = WP_AbsorbConversion( gripEnt, gripEnt->client->ps.forcePowerLevel[FP_ABSORB], self, FP_GRIP, self->client->ps.forcePowerLevel[FP_GRIP], forcePowerNeeded[gripLevel] );
  12124. }
  12125. if ( !gripLevel )
  12126. {
  12127. WP_ForcePowerStop( self, forcePower );
  12128. return;
  12129. }
  12130. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 )
  12131. {//holding it
  12132. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCEGRIP_HOLD, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12133. if ( self->client->ps.torsoAnimTimer < 100 ){//we were already playing this anim, we didn't want to restart it, but we want to hold it for at least 100ms, sooo....
  12134. self->client->ps.torsoAnimTimer = 100;
  12135. }
  12136. }
  12137. //get their org
  12138. VectorCopy( self->client->ps.viewangles, angles );
  12139. angles[0] -= 10;
  12140. AngleVectors( angles, dir, NULL, NULL );
  12141. if ( gripEnt->client )
  12142. {//move
  12143. VectorCopy( gripEnt->client->renderInfo.headPoint, gripEntOrg );
  12144. }
  12145. else
  12146. {
  12147. VectorCopy( gripEnt->currentOrigin, gripEntOrg );
  12148. }
  12149. //how far are they
  12150. dist = Distance( self->client->renderInfo.handLPoint, gripEntOrg );
  12151. if ( self->client->ps.forcePowerLevel[FP_GRIP] == FORCE_LEVEL_2 &&
  12152. (!InFront( gripEntOrg, self->client->renderInfo.handLPoint, self->client->ps.viewangles, 0.3f ) ||
  12153. DistanceSquared( gripEntOrg, self->client->renderInfo.handLPoint ) > FORCE_GRIP_DIST_SQUARED))
  12154. {//must face them
  12155. WP_ForcePowerStop( self, FP_GRIP );
  12156. return;
  12157. }
  12158. //check for lift or carry
  12159. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_2
  12160. && (!gripEnt->client || (!gripEnt->message&&!(gripEnt->flags&FL_NO_KNOCKBACK))) )
  12161. {//carry
  12162. //cap dist
  12163. if ( dist > FORCE_GRIP_3_MAX_DIST )
  12164. {
  12165. dist = FORCE_GRIP_3_MAX_DIST;
  12166. }
  12167. else if ( dist < FORCE_GRIP_3_MIN_DIST )
  12168. {
  12169. dist = FORCE_GRIP_3_MIN_DIST;
  12170. }
  12171. VectorMA( self->client->renderInfo.handLPoint, dist, dir, gripOrg );
  12172. }
  12173. else if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 )
  12174. {//just lift
  12175. VectorCopy( self->client->ps.forceGripOrg, gripOrg );
  12176. }
  12177. else
  12178. {
  12179. VectorCopy( gripEnt->currentOrigin, gripOrg );
  12180. }
  12181. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 )
  12182. {//if holding him, make sure there's a clear LOS between my hand and him
  12183. trace_t gripTrace;
  12184. gi.trace( &gripTrace, self->client->renderInfo.handLPoint, NULL, NULL, gripEntOrg, ENTITYNUM_NONE, MASK_FORCE_PUSH );
  12185. if ( gripTrace.startsolid
  12186. || gripTrace.startsolid
  12187. || gripTrace.fraction < 1.0f )
  12188. {//no clear trace, drop them
  12189. WP_ForcePowerStop( self, FP_GRIP );
  12190. return;
  12191. }
  12192. }
  12193. //now move them
  12194. if ( gripEnt->client )
  12195. {
  12196. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 )
  12197. {//level 1 just holds them
  12198. VectorSubtract( gripOrg, gripEntOrg, gripEnt->client->ps.velocity );
  12199. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_2
  12200. && (!gripEnt->client || (!gripEnt->message&&!(gripEnt->flags&FL_NO_KNOCKBACK)) ) )
  12201. {//level 2 just lifts them
  12202. float gripDist = VectorNormalize( gripEnt->client->ps.velocity )/3.0f;
  12203. if ( gripDist < 20.0f )
  12204. {
  12205. if (gripDist<2.0f)
  12206. {
  12207. VectorClear(gripEnt->client->ps.velocity);
  12208. }
  12209. else
  12210. {
  12211. VectorScale( gripEnt->client->ps.velocity, (gripDist*gripDist), gripEnt->client->ps.velocity );
  12212. }
  12213. }
  12214. else
  12215. {
  12216. VectorScale( gripEnt->client->ps.velocity, (gripDist*gripDist), gripEnt->client->ps.velocity );
  12217. }
  12218. }
  12219. }
  12220. //stop them from thinking
  12221. gripEnt->client->ps.pm_time = 2000;
  12222. gripEnt->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  12223. if ( gripEnt->NPC )
  12224. {
  12225. if ( !(gripEnt->NPC->aiFlags&NPCAI_DIE_ON_IMPACT) )
  12226. {//not falling to their death
  12227. gripEnt->NPC->nextBStateThink = level.time + 2000;
  12228. }
  12229. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 )
  12230. {//level 1 just holds them
  12231. vectoangles( dir, angles );
  12232. gripEnt->NPC->desiredYaw = AngleNormalize180(angles[YAW]+180);
  12233. gripEnt->NPC->desiredPitch = -angles[PITCH];
  12234. SaveNPCGlobals();
  12235. SetNPCGlobals( gripEnt );
  12236. NPC_UpdateAngles( qtrue, qtrue );
  12237. gripEnt->NPC->last_ucmd.angles[0] = ucmd.angles[0];
  12238. gripEnt->NPC->last_ucmd.angles[1] = ucmd.angles[1];
  12239. gripEnt->NPC->last_ucmd.angles[2] = ucmd.angles[2];
  12240. RestoreNPCGlobals();
  12241. //FIXME: why does he turn back to his original angles once he dies or is let go?
  12242. }
  12243. }
  12244. else if ( !gripEnt->s.number )
  12245. {
  12246. //vectoangles( dir, angles );
  12247. //gripEnt->client->ps.viewangles[0] = -angles[0];
  12248. //gripEnt->client->ps.viewangles[1] = AngleNormalize180(angles[YAW]+180);
  12249. gripEnt->enemy = self;
  12250. NPC_SetLookTarget( gripEnt, self->s.number, level.time+1000 );
  12251. }
  12252. gripEnt->client->ps.eFlags |= EF_FORCE_GRIPPED;
  12253. //dammit! Make sure that saber stays off!
  12254. WP_DeactivateSaber( gripEnt );
  12255. }
  12256. else
  12257. {//move
  12258. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_1 )
  12259. {//level 1 just holds them
  12260. VectorCopy( gripEnt->currentOrigin, gripEnt->s.pos.trBase );
  12261. VectorSubtract( gripOrg, gripEntOrg, gripEnt->s.pos.trDelta );
  12262. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_2
  12263. && (!gripEnt->client || (!gripEnt->message&&!(gripEnt->flags&FL_NO_KNOCKBACK))) )
  12264. {//level 2 just lifts them
  12265. VectorScale( gripEnt->s.pos.trDelta, 10, gripEnt->s.pos.trDelta );
  12266. }
  12267. gripEnt->s.pos.trType = TR_LINEAR;
  12268. gripEnt->s.pos.trTime = level.time;
  12269. }
  12270. gripEnt->s.eFlags |= EF_FORCE_GRIPPED;
  12271. }
  12272. //Shouldn't this be discovered?
  12273. //AddSightEvent( self, gripOrg, 128, AEL_DANGER, 20 );
  12274. AddSightEvent( self, gripOrg, 128, AEL_DISCOVERED, 20 );
  12275. if ( self->client->ps.forcePowerDebounce[FP_GRIP] < level.time )
  12276. {
  12277. //GEntity_PainFunc( gripEnt, self, self, gripOrg, 0, MOD_CRUSH );
  12278. if ( !gripEnt->client
  12279. || gripEnt->client->NPC_class != CLASS_VEHICLE
  12280. || (gripEnt->m_pVehicle
  12281. && gripEnt->m_pVehicle->m_pVehicleInfo
  12282. && gripEnt->m_pVehicle->m_pVehicleInfo->type == VH_ANIMAL) )
  12283. {//we don't damage the empty vehicle
  12284. gripEnt->painDebounceTime = 0;
  12285. int gripDmg = forceGripDamage[self->client->ps.forcePowerLevel[FP_GRIP]];
  12286. if ( gripLevel != -1 )
  12287. {
  12288. if ( gripLevel == 1 )
  12289. {
  12290. gripDmg = floor((float)gripDmg/3.0f);
  12291. }
  12292. else //if ( gripLevel == 2 )
  12293. {
  12294. gripDmg = floor((float)gripDmg/1.5f);
  12295. }
  12296. }
  12297. G_Damage( gripEnt, self, self, dir, gripOrg, gripDmg, DAMAGE_NO_ARMOR, MOD_CRUSH );//MOD_???
  12298. }
  12299. if ( gripEnt->s.number )
  12300. {
  12301. if ( self->client->ps.forcePowerLevel[FP_GRIP] > FORCE_LEVEL_2 )
  12302. {//do damage faster at level 3
  12303. self->client->ps.forcePowerDebounce[FP_GRIP] = level.time + Q_irand( 150, 750 );
  12304. }
  12305. else
  12306. {
  12307. self->client->ps.forcePowerDebounce[FP_GRIP] = level.time + Q_irand( 250, 1000 );
  12308. }
  12309. }
  12310. else
  12311. {//player takes damage faster
  12312. self->client->ps.forcePowerDebounce[FP_GRIP] = level.time + Q_irand( 100, 600 );
  12313. }
  12314. if ( forceGripDamage[self->client->ps.forcePowerLevel[FP_GRIP]] > 0 )
  12315. {//no damage at level 1
  12316. WP_ForcePowerDrain( self, FP_GRIP, 3 );
  12317. }
  12318. if ( self->client->NPC_class == CLASS_KYLE
  12319. && (self->spawnflags&1) )
  12320. {//"Boss" Kyle
  12321. if ( gripEnt->client )
  12322. {
  12323. if ( !Q_irand( 0, 2 ) )
  12324. {//toss him aside!
  12325. vec3_t vRt;
  12326. AngleVectors( self->currentAngles, NULL, vRt, NULL );
  12327. //stop gripping
  12328. TIMER_Set( self, "gripping", -level.time );
  12329. WP_ForcePowerStop( self, FP_GRIP );
  12330. //now toss him
  12331. if ( Q_irand( 0, 1 ) )
  12332. {//throw him to my left
  12333. NPC_SetAnim( self, SETANIM_BOTH, BOTH_TOSS1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12334. VectorScale( vRt, -1500.0f, gripEnt->client->ps.velocity );
  12335. G_Knockdown( gripEnt, self, vRt, 500, qfalse );
  12336. }
  12337. else
  12338. {//throw him to my right
  12339. NPC_SetAnim( self, SETANIM_BOTH, BOTH_TOSS2, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12340. VectorScale( vRt, 1500.0f, gripEnt->client->ps.velocity );
  12341. G_Knockdown( gripEnt, self, vRt, 500, qfalse );
  12342. }
  12343. //don't do anything for a couple seconds
  12344. self->client->ps.weaponTime = self->client->ps.torsoAnimTimer + 2000;
  12345. self->painDebounceTime = level.time + self->client->ps.weaponTime;
  12346. //stop moving
  12347. VectorClear( self->client->ps.velocity );
  12348. VectorClear( self->client->ps.moveDir );
  12349. return;
  12350. }
  12351. }
  12352. }
  12353. }
  12354. else
  12355. {
  12356. //WP_ForcePowerDrain( self, FP_GRIP, 0 );
  12357. if ( !gripEnt->enemy )
  12358. {
  12359. if ( gripEnt->client
  12360. && gripEnt->client->playerTeam == TEAM_PLAYER
  12361. && self->s.number < MAX_CLIENTS
  12362. && self->client
  12363. && self->client->playerTeam == TEAM_PLAYER )
  12364. {//this shouldn't make allies instantly turn on you, let the damage->pain routine determine how allies should react to this
  12365. }
  12366. else
  12367. {
  12368. G_SetEnemy( gripEnt, self );
  12369. }
  12370. }
  12371. }
  12372. if ( gripEnt->client && gripEnt->health > 0 )
  12373. {
  12374. int anim = BOTH_CHOKE3; //left-handed choke
  12375. if ( gripEnt->client->ps.weapon == WP_NONE || gripEnt->client->ps.weapon == WP_MELEE )
  12376. {
  12377. anim = BOTH_CHOKE1; //two-handed choke
  12378. }
  12379. if ( self->client->ps.forcePowerLevel[FP_GRIP] < FORCE_LEVEL_2 )
  12380. {//still on ground, only set anim on torso
  12381. NPC_SetAnim( gripEnt, SETANIM_TORSO, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12382. }
  12383. else
  12384. {//in air, set on whole body
  12385. NPC_SetAnim( gripEnt, SETANIM_BOTH, anim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12386. }
  12387. gripEnt->painDebounceTime = level.time + 2000;
  12388. }
  12389. }
  12390. }
  12391. break;
  12392. case FP_LIGHTNING:
  12393. if ( self->client->ps.forcePowerLevel[FP_LIGHTNING] > FORCE_LEVEL_1 )
  12394. {//higher than level 1
  12395. if ( cmd->buttons & BUTTON_FORCE_LIGHTNING )
  12396. {//holding it keeps it going
  12397. self->client->ps.forcePowerDuration[FP_LIGHTNING] = level.time + 500;
  12398. ForceLightningAnim( self );
  12399. }
  12400. }
  12401. if ( !WP_ForcePowerAvailable( self, forcePower, 0 ) )
  12402. {
  12403. WP_ForcePowerStop( self, forcePower );
  12404. }
  12405. else
  12406. {
  12407. ForceShootLightning( self );
  12408. if ( self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING
  12409. || self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING_START
  12410. || self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING_HOLD
  12411. || self->client->ps.torsoAnim == BOTH_FORCE_2HANDEDLIGHTNING_RELEASE )
  12412. {//jackin' 'em up, Palpatine-style
  12413. //extra cost
  12414. WP_ForcePowerDrain( self, forcePower, 0 );
  12415. }
  12416. WP_ForcePowerDrain( self, forcePower, 0 );
  12417. }
  12418. break;
  12419. //new Jedi Academy force powers
  12420. case FP_RAGE:
  12421. if (self->health < 1)
  12422. {
  12423. WP_ForcePowerStop(self, forcePower);
  12424. break;
  12425. }
  12426. if (self->client->ps.forceRageDrainTime < level.time)
  12427. {
  12428. int addTime = 400;
  12429. self->health -= 2;
  12430. if (self->client->ps.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_1)
  12431. {
  12432. addTime = 100;
  12433. }
  12434. else if (self->client->ps.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_2)
  12435. {
  12436. addTime = 250;
  12437. }
  12438. else if (self->client->ps.forcePowerLevel[FP_RAGE] == FORCE_LEVEL_3)
  12439. {
  12440. addTime = 500;
  12441. }
  12442. self->client->ps.forceRageDrainTime = level.time + addTime;
  12443. }
  12444. if ( self->health < 1 )
  12445. {
  12446. self->health = 1;
  12447. //WP_ForcePowerStop( self, forcePower );
  12448. }
  12449. else
  12450. {
  12451. self->client->ps.stats[STAT_HEALTH] = self->health;
  12452. speed = forceSpeedValue[self->client->ps.forcePowerLevel[FP_RAGE]-1];
  12453. if ( !self->s.number )
  12454. {//player using force rage
  12455. if ( !(self->client->ps.forcePowersActive&(1<<FP_SPEED))
  12456. || self->client->ps.forcePowerLevel[FP_RAGE] > self->client->ps.forcePowerLevel[FP_SPEED]+1 )
  12457. {//either not using speed or speed is at a lower level than rage
  12458. gi.cvar_set("timescale", va("%4.2f", speed));
  12459. if ( g_timescale->value > speed )
  12460. {
  12461. newSpeed = g_timescale->value - 0.05;
  12462. if ( newSpeed < speed )
  12463. {
  12464. newSpeed = speed;
  12465. }
  12466. gi.cvar_set("timescale", va("%4.2f", newSpeed));
  12467. }
  12468. }
  12469. }
  12470. }
  12471. break;
  12472. case FP_DRAIN:
  12473. if ( cmd->buttons & BUTTON_FORCE_DRAIN )
  12474. {//holding it keeps it going
  12475. self->client->ps.forcePowerDuration[FP_DRAIN] = level.time + 500;
  12476. }
  12477. if ( !WP_ForcePowerAvailable( self, forcePower, 0 ) )
  12478. {//no more force power, stop
  12479. WP_ForcePowerStop( self, forcePower );
  12480. }
  12481. else if ( self->client->ps.forceDrainEntityNum >= 0 && self->client->ps.forceDrainEntityNum < ENTITYNUM_WORLD )
  12482. {//holding someone
  12483. if ( !WP_ForcePowerAvailable( self, FP_DRAIN, 0 )
  12484. || (self->client->ps.forcePowerLevel[FP_DRAIN]>FORCE_LEVEL_1
  12485. && !self->s.number
  12486. && !(cmd->buttons&BUTTON_FORCE_DRAIN)
  12487. && self->client->ps.forcePowerDuration[FP_DRAIN]<level.time) )
  12488. {
  12489. WP_ForcePowerStop( self, FP_DRAIN );
  12490. return;
  12491. }
  12492. else
  12493. {
  12494. drainEnt = &g_entities[self->client->ps.forceDrainEntityNum];
  12495. if ( !drainEnt )
  12496. {//invalid ent
  12497. WP_ForcePowerStop( self, FP_DRAIN );
  12498. return;
  12499. }
  12500. else if ( (drainEnt->health <= 0&&drainEnt->takedamage) )//FIXME: what about things that never had health or lose takedamage when they die?
  12501. {//dead ent
  12502. WP_ForcePowerStop( self, FP_DRAIN );
  12503. return;
  12504. }
  12505. else if ( drainEnt->client && drainEnt->client->moveType == MT_FLYSWIM && VectorLengthSquared( NPC->client->ps.velocity ) > (300*300) )
  12506. {//flying creature broke free
  12507. WP_ForcePowerStop( self, FP_DRAIN );
  12508. return;
  12509. }
  12510. else if ( drainEnt->client
  12511. && drainEnt->health>0 //dead dudes don't fly
  12512. && (drainEnt->client->NPC_class == CLASS_BOBAFETT || drainEnt->client->NPC_class == CLASS_ROCKETTROOPER)
  12513. && self->client->ps.forcePowerDebounce[FP_DRAIN] < level.time
  12514. && !Q_irand( 0, 10 ) )
  12515. {//boba fett - fly away!
  12516. drainEnt->client->ps.forceJumpCharge = 0;//so we don't play the force flip anim
  12517. drainEnt->client->ps.velocity[2] = 250;
  12518. drainEnt->client->ps.forceJumpZStart = drainEnt->currentOrigin[2];//so we don't take damage if we land at same height
  12519. drainEnt->client->ps.pm_flags |= PMF_JUMPING;
  12520. G_AddEvent( drainEnt, EV_JUMP, 0 );
  12521. JET_FlyStart( drainEnt );
  12522. WP_ForcePowerStop( self, FP_DRAIN );
  12523. return;
  12524. }
  12525. else if ( drainEnt->NPC
  12526. && drainEnt->client
  12527. && drainEnt->client->ps.forcePowersKnown
  12528. && (drainEnt->client->NPC_class==CLASS_REBORN||drainEnt->client->ps.weapon==WP_SABER)
  12529. && !Jedi_CultistDestroyer(drainEnt)
  12530. && level.time-(self->client->ps.forcePowerDebounce[FP_DRAIN]>self->client->ps.forcePowerLevel[FP_DRAIN]*500)//at level 1, I always get at least 500ms of drain, at level 3 I get 1500ms
  12531. && !Q_irand( 0, 100-(drainEnt->NPC->stats.evasion*8)-(g_spskill->integer*15) ) )
  12532. {//a jedi who broke free FIXME: maybe have some minimum grip length- a reaction time?
  12533. WP_ForceForceThrow( drainEnt );
  12534. //FIXME: I need to go into some pushed back anim...
  12535. WP_ForcePowerStop( self, FP_DRAIN );
  12536. //can't drain again for 2 seconds
  12537. self->client->ps.forcePowerDebounce[FP_DRAIN] = level.time + 4000;
  12538. return;
  12539. }
  12540. else
  12541. {
  12542. /*
  12543. int drainLevel = WP_AbsorbConversion( drainEnt, drainEnt->client->ps.forcePowerLevel[FP_ABSORB], self, FP_DRAIN, self->client->ps.forcePowerLevel[FP_DRAIN], forcePowerNeeded[self->client->ps.forcePowerLevel[FP_DRAIN]] );
  12544. if ( !drainLevel )
  12545. {
  12546. WP_ForcePowerStop( self, forcePower );
  12547. return;
  12548. }
  12549. */
  12550. //NPC_SetAnim( self, SETANIM_BOTH, BOTH_HUGGER1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12551. if ( self->client->ps.torsoAnim != BOTH_FORCE_DRAIN_GRAB_START
  12552. || !self->client->ps.torsoAnimTimer )
  12553. {
  12554. NPC_SetAnim( self, SETANIM_BOTH, BOTH_FORCE_DRAIN_GRAB_HOLD, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12555. }
  12556. if ( self->handLBolt != -1 )
  12557. {
  12558. G_PlayEffect( G_EffectIndex( "force/drain_hand" ), self->playerModel, self->handLBolt, self->s.number, self->currentOrigin, 200, qtrue );
  12559. }
  12560. if ( self->handRBolt != -1 )
  12561. {
  12562. G_PlayEffect( G_EffectIndex( "force/drain_hand" ), self->playerModel, self->handRBolt, self->s.number, self->currentOrigin, 200, qtrue );
  12563. }
  12564. //how far are they
  12565. dist = Distance( self->client->renderInfo.eyePoint, drainEnt->currentOrigin );
  12566. if ( DistanceSquared( drainEnt->currentOrigin, self->currentOrigin ) > FORCE_DRAIN_DIST_SQUARED )
  12567. {//must be close, got away somehow!
  12568. WP_ForcePowerStop( self, FP_DRAIN );
  12569. return;
  12570. }
  12571. //keep my saber off!
  12572. WP_DeactivateSaber( self, qtrue );
  12573. if ( drainEnt->client )
  12574. {
  12575. //now move them
  12576. VectorCopy( self->client->ps.viewangles, angles );
  12577. angles[0] = 0;
  12578. AngleVectors( angles, dir, NULL, NULL );
  12579. /*
  12580. VectorMA( self->currentOrigin, self->maxs[0], dir, drainEnt->client->ps.forceDrainOrg );
  12581. trace_t trace;
  12582. gi.trace( &trace, drainEnt->currentOrigin, drainEnt->mins, drainEnt->maxs, drainEnt->client->ps.forceDrainOrg, drainEnt->s.number, drainEnt->clipmask );
  12583. if ( !trace.startsolid && !trace.allsolid )
  12584. {
  12585. G_SetOrigin( drainEnt, trace.endpos );
  12586. gi.linkentity( drainEnt );
  12587. VectorClear( drainEnt->client->ps.velocity );
  12588. }
  12589. VectorMA( self->currentOrigin, self->maxs[0]*0.5f, dir, drainEnt->client->ps.forceDrainOrg );
  12590. */
  12591. //stop them from thinking
  12592. drainEnt->client->ps.pm_time = 2000;
  12593. drainEnt->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
  12594. if ( drainEnt->NPC )
  12595. {
  12596. if ( !(drainEnt->NPC->aiFlags&NPCAI_DIE_ON_IMPACT) )
  12597. {//not falling to their death
  12598. drainEnt->NPC->nextBStateThink = level.time + 2000;
  12599. }
  12600. vectoangles( dir, angles );
  12601. drainEnt->NPC->desiredYaw = AngleNormalize180(angles[YAW]+180);
  12602. drainEnt->NPC->desiredPitch = -angles[PITCH];
  12603. SaveNPCGlobals();
  12604. SetNPCGlobals( drainEnt );
  12605. NPC_UpdateAngles( qtrue, qtrue );
  12606. drainEnt->NPC->last_ucmd.angles[0] = ucmd.angles[0];
  12607. drainEnt->NPC->last_ucmd.angles[1] = ucmd.angles[1];
  12608. drainEnt->NPC->last_ucmd.angles[2] = ucmd.angles[2];
  12609. RestoreNPCGlobals();
  12610. //FIXME: why does he turn back to his original angles once he dies or is let go?
  12611. }
  12612. else if ( !drainEnt->s.number )
  12613. {
  12614. drainEnt->enemy = self;
  12615. NPC_SetLookTarget( drainEnt, self->s.number, level.time+1000 );
  12616. }
  12617. drainEnt->client->ps.eFlags |= EF_FORCE_DRAINED;
  12618. //dammit! Make sure that saber stays off!
  12619. WP_DeactivateSaber( drainEnt, qtrue );
  12620. }
  12621. //Shouldn't this be discovered?
  12622. AddSightEvent( self, drainEnt->currentOrigin, 128, AEL_DISCOVERED, 20 );
  12623. if ( self->client->ps.forcePowerDebounce[FP_DRAIN] < level.time )
  12624. {
  12625. int drainLevel = WP_AbsorbConversion( drainEnt, drainEnt->client->ps.forcePowerLevel[FP_ABSORB], self, FP_DRAIN, self->client->ps.forcePowerLevel[FP_DRAIN], forcePowerNeeded[self->client->ps.forcePowerLevel[FP_DRAIN]] );
  12626. if ( (drainLevel && drainLevel == -1)
  12627. || Q_irand( drainLevel, 3 ) < 3 )
  12628. {//the drain is being absorbed
  12629. ForceDrainEnt( self, drainEnt );
  12630. }
  12631. WP_ForcePowerDrain( self, FP_DRAIN, 3 );
  12632. }
  12633. else
  12634. {
  12635. if ( !Q_irand( 0, 4 ) )
  12636. {
  12637. WP_ForcePowerDrain( self, FP_DRAIN, 1 );
  12638. }
  12639. if ( !drainEnt->enemy )
  12640. {
  12641. G_SetEnemy( drainEnt, self );
  12642. }
  12643. }
  12644. if ( drainEnt->health > 0 )
  12645. {//still alive
  12646. //NPC_SetAnim( drainEnt, SETANIM_BOTH, BOTH_HUGGEE1, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12647. NPC_SetAnim( drainEnt, SETANIM_BOTH, BOTH_FORCE_DRAIN_GRABBED, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12648. }
  12649. }
  12650. }
  12651. }
  12652. else if ( self->client->ps.forcePowerLevel[forcePower] > FORCE_LEVEL_1 )
  12653. {//regular distance-drain
  12654. if ( cmd->buttons & BUTTON_FORCE_DRAIN )
  12655. {//holding it keeps it going
  12656. self->client->ps.forcePowerDuration[FP_DRAIN] = level.time + 500;
  12657. if ( self->client->ps.torsoAnim == BOTH_FORCE_DRAIN_START )
  12658. {
  12659. if ( !self->client->ps.torsoAnimTimer )
  12660. {
  12661. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCE_DRAIN_HOLD, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12662. }
  12663. else
  12664. {
  12665. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCE_DRAIN_START, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12666. }
  12667. }
  12668. else
  12669. {
  12670. NPC_SetAnim( self, SETANIM_TORSO, BOTH_FORCE_DRAIN_HOLD, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD );
  12671. }
  12672. }
  12673. if ( !WP_ForcePowerAvailable( self, forcePower, 0 ) )
  12674. {
  12675. WP_ForcePowerStop( self, forcePower );
  12676. }
  12677. else
  12678. {
  12679. ForceShootDrain( self );
  12680. }
  12681. }
  12682. break;
  12683. case FP_PROTECT:
  12684. break;
  12685. case FP_ABSORB:
  12686. break;
  12687. case FP_SEE:
  12688. break;
  12689. default:
  12690. break;
  12691. }
  12692. }
  12693. void WP_CheckForcedPowers( gentity_t *self, usercmd_t *ucmd )
  12694. {
  12695. for ( int forcePower = FP_FIRST; forcePower < NUM_FORCE_POWERS; forcePower++ )
  12696. {
  12697. if ( (self->client->ps.forcePowersForced&(1<<forcePower)) )
  12698. {
  12699. switch ( forcePower )
  12700. {
  12701. case FP_HEAL:
  12702. ForceHeal( self );
  12703. //do only once
  12704. self->client->ps.forcePowersForced &= ~(1<<forcePower);
  12705. break;
  12706. case FP_LEVITATION:
  12707. //nothing
  12708. break;
  12709. case FP_SPEED:
  12710. ForceSpeed( self );
  12711. //do only once
  12712. self->client->ps.forcePowersForced &= ~(1<<forcePower);
  12713. break;
  12714. case FP_PUSH:
  12715. ForceThrow( self, qfalse );
  12716. //do only once
  12717. self->client->ps.forcePowersForced &= ~(1<<forcePower);
  12718. break;
  12719. case FP_PULL:
  12720. ForceThrow( self, qtrue );
  12721. //do only once
  12722. self->client->ps.forcePowersForced &= ~(1<<forcePower);
  12723. break;
  12724. case FP_TELEPATHY:
  12725. //FIXME: target at enemy?
  12726. ForceTelepathy( self );
  12727. //do only once
  12728. self->client->ps.forcePowersForced &= ~(1<<forcePower);
  12729. break;
  12730. case FP_GRIP:
  12731. ucmd->buttons &= ~(BUTTON_ATTACK|BUTTON_ALT_ATTACK|BUTTON_FORCE_FOCUS|BUTTON_FORCE_DRAIN|BUTTON_FORCE_LIGHTNING);
  12732. ucmd->buttons |= BUTTON_FORCEGRIP;
  12733. //holds until cleared
  12734. break;
  12735. case FP_LIGHTNING:
  12736. ucmd->buttons &= ~(BUTTON_ATTACK|BUTTON_ALT_ATTACK|BUTTON_FORCE_FOCUS|BUTTON_FORCEGRIP|BUTTON_FORCE_DRAIN);
  12737. ucmd->buttons |= BUTTON_FORCE_LIGHTNING;
  12738. //holds until cleared
  12739. break;
  12740. case FP_SABERTHROW:
  12741. ucmd->buttons &= ~(BUTTON_ATTACK|BUTTON_FORCE_FOCUS|BUTTON_FORCEGRIP|BUTTON_FORCE_DRAIN|BUTTON_FORCE_LIGHTNING);
  12742. ucmd->buttons |= BUTTON_ALT_ATTACK;
  12743. //holds until cleared?
  12744. break;
  12745. case FP_SABER_DEFENSE:
  12746. //nothing
  12747. break;
  12748. case FP_SABER_OFFENSE:
  12749. //nothing
  12750. break;
  12751. case FP_RAGE:
  12752. ForceRage( self );
  12753. //do only once
  12754. self->client->ps.forcePowersForced &= ~(1<<forcePower);
  12755. break;
  12756. case FP_PROTECT:
  12757. ForceProtect( self );
  12758. //do only once
  12759. self->client->ps.forcePowersForced &= ~(1<<forcePower);
  12760. break;
  12761. case FP_ABSORB:
  12762. ForceAbsorb( self );
  12763. //do only once
  12764. self->client->ps.forcePowersForced &= ~(1<<forcePower);
  12765. break;
  12766. case FP_DRAIN:
  12767. ucmd->buttons &= ~(BUTTON_ATTACK|BUTTON_ALT_ATTACK|BUTTON_FORCE_FOCUS|BUTTON_FORCEGRIP|BUTTON_FORCE_LIGHTNING);
  12768. ucmd->buttons |= BUTTON_FORCE_DRAIN;
  12769. //holds until cleared
  12770. break;
  12771. case FP_SEE:
  12772. //nothing
  12773. break;
  12774. }
  12775. }
  12776. }
  12777. }
  12778. void WP_ForcePowersUpdate( gentity_t *self, usercmd_t *ucmd )
  12779. {
  12780. qboolean usingForce = qfalse;
  12781. int i;
  12782. //see if any force powers are running
  12783. if ( !self )
  12784. {
  12785. return;
  12786. }
  12787. if ( !self->client )
  12788. {
  12789. return;
  12790. }
  12791. if ( self->health <= 0 )
  12792. {//if dead, deactivate any active force powers
  12793. for ( i = 0; i < NUM_FORCE_POWERS; i++ )
  12794. {
  12795. if ( self->client->ps.forcePowerDuration[i] || (self->client->ps.forcePowersActive&( 1 << i )) )
  12796. {
  12797. WP_ForcePowerStop( self, (forcePowers_t)i );
  12798. self->client->ps.forcePowerDuration[i] = 0;
  12799. }
  12800. }
  12801. return;
  12802. }
  12803. WP_CheckForcedPowers( self, ucmd );
  12804. if ( !self->s.number )
  12805. {//player uses different kind of force-jump
  12806. }
  12807. else
  12808. {
  12809. /*
  12810. if ( ucmd->buttons & BUTTON_FORCEJUMP )
  12811. {//just charging up
  12812. ForceJumpCharge( self, ucmd );
  12813. }
  12814. else */
  12815. if ( self->client->ps.forceJumpCharge )
  12816. {//let go of charge button, have charge
  12817. //if leave the ground by some other means, cancel the force jump so we don't suddenly jump when we land.
  12818. if ( self->client->ps.groundEntityNum == ENTITYNUM_NONE
  12819. && !PM_SwimmingAnim( self->client->ps.legsAnim ) )
  12820. {//FIXME: stop sound?
  12821. //self->client->ps.forceJumpCharge = 0;
  12822. //FIXME: actually, we want this to still be cleared... don't clear it if the button isn't being pressed, but clear it if not holding button and not on ground.
  12823. }
  12824. else
  12825. {//still on ground, so jump
  12826. ForceJump( self, ucmd );
  12827. return;
  12828. }
  12829. }
  12830. }
  12831. if ( ucmd->buttons & BUTTON_FORCEGRIP )
  12832. {
  12833. ForceGrip( self );
  12834. }
  12835. if ( ucmd->buttons & BUTTON_FORCE_LIGHTNING )
  12836. {
  12837. ForceLightning( self );
  12838. }
  12839. if ( ucmd->buttons & BUTTON_FORCE_DRAIN )
  12840. {
  12841. if ( !ForceDrain2( self ) )
  12842. {//can't drain-grip someone right in front
  12843. if ( self->client->ps.forcePowerLevel[FP_DRAIN] > FORCE_LEVEL_1 )
  12844. {//try ranged
  12845. ForceDrain( self, qtrue );
  12846. }
  12847. }
  12848. }
  12849. for ( i = 0; i < NUM_FORCE_POWERS; i++ )
  12850. {
  12851. if ( self->client->ps.forcePowerDuration[i] )
  12852. {
  12853. if ( self->client->ps.forcePowerDuration[i] < level.time )
  12854. {
  12855. if ( (self->client->ps.forcePowersActive&( 1 << i )) )
  12856. {//turn it off
  12857. WP_ForcePowerStop( self, (forcePowers_t)i );
  12858. }
  12859. self->client->ps.forcePowerDuration[i] = 0;
  12860. }
  12861. }
  12862. if ( (self->client->ps.forcePowersActive&( 1 << i )) )
  12863. {
  12864. usingForce = qtrue;
  12865. WP_ForcePowerRun( self, (forcePowers_t)i, ucmd );
  12866. }
  12867. }
  12868. if ( self->client->ps.saberInFlight )
  12869. {//don't regen force power while throwing saber
  12870. if ( self->client->ps.saberEntityNum < ENTITYNUM_NONE && self->client->ps.saberEntityNum > 0 )//player is 0
  12871. {//
  12872. if ( &g_entities[self->client->ps.saberEntityNum] != NULL && g_entities[self->client->ps.saberEntityNum].s.pos.trType == TR_LINEAR )
  12873. {//fell to the ground and we're trying to pull it back
  12874. usingForce = qtrue;
  12875. }
  12876. }
  12877. }
  12878. if ( PM_ForceUsingSaberAnim( self->client->ps.torsoAnim ) )
  12879. {
  12880. usingForce = qtrue;
  12881. }
  12882. if ( !usingForce )
  12883. {//when not using the force, regenerate at 10 points per second
  12884. if ( self->client->ps.forcePowerRegenDebounceTime < level.time )
  12885. {
  12886. WP_ForcePowerRegenerate( self, self->client->ps.forcePowerRegenAmount );
  12887. self->client->ps.forcePowerRegenDebounceTime = level.time + self->client->ps.forcePowerRegenRate;
  12888. if ( self->client->ps.forceRageRecoveryTime >= level.time )
  12889. {//regen half as fast
  12890. self->client->ps.forcePowerRegenDebounceTime += self->client->ps.forcePowerRegenRate;
  12891. }
  12892. }
  12893. }
  12894. }
  12895. void WP_InitForcePowers( gentity_t *ent )
  12896. {
  12897. if ( !ent || !ent->client )
  12898. {
  12899. return;
  12900. }
  12901. if ( !ent->client->ps.forcePowerMax )
  12902. {
  12903. ent->client->ps.forcePowerMax = FORCE_POWER_MAX;
  12904. }
  12905. if ( !ent->client->ps.forcePowerRegenRate )
  12906. {
  12907. ent->client->ps.forcePowerRegenRate = 100;
  12908. }
  12909. ent->client->ps.forcePower = ent->client->ps.forcePowerMax;
  12910. ent->client->ps.forcePowerRegenDebounceTime = 0;
  12911. ent->client->ps.forceGripEntityNum = ent->client->ps.forceDrainEntityNum = ent->client->ps.pullAttackEntNum = ENTITYNUM_NONE;
  12912. ent->client->ps.forceRageRecoveryTime = 0;
  12913. ent->client->ps.forceDrainTime = 0;
  12914. ent->client->ps.pullAttackTime = 0;
  12915. if ( ent->s.number < MAX_CLIENTS )
  12916. {//player
  12917. if ( !g_cheats->integer )//devmaps give you all the FP
  12918. {
  12919. ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE] = FORCE_LEVEL_1;
  12920. ent->client->ps.forcePowerLevel[FP_SABER_OFFENSE] = FORCE_LEVEL_1;
  12921. }
  12922. else
  12923. {
  12924. ent->client->ps.forcePowersKnown = ( 1 << FP_HEAL )|( 1 << FP_LEVITATION )|( 1 << FP_SPEED )|( 1 << FP_PUSH )|( 1 << FP_PULL )|( 1 << FP_TELEPATHY )|( 1 << FP_GRIP )|( 1 << FP_LIGHTNING)|( 1 << FP_SABERTHROW)|( 1 << FP_SABER_DEFENSE )|( 1 << FP_SABER_OFFENSE )|( 1<< FP_RAGE )|( 1<< FP_DRAIN )|( 1<< FP_PROTECT )|( 1<< FP_ABSORB )|( 1<< FP_SEE );
  12925. ent->client->ps.forcePowerLevel[FP_HEAL] = FORCE_LEVEL_2;
  12926. ent->client->ps.forcePowerLevel[FP_LEVITATION] = FORCE_LEVEL_2;
  12927. ent->client->ps.forcePowerLevel[FP_PUSH] = FORCE_LEVEL_1;
  12928. ent->client->ps.forcePowerLevel[FP_PULL] = FORCE_LEVEL_1;
  12929. ent->client->ps.forcePowerLevel[FP_SABERTHROW] = FORCE_LEVEL_2;
  12930. ent->client->ps.forcePowerLevel[FP_SPEED] = FORCE_LEVEL_2;
  12931. ent->client->ps.forcePowerLevel[FP_LIGHTNING] = FORCE_LEVEL_1;
  12932. ent->client->ps.forcePowerLevel[FP_TELEPATHY] = FORCE_LEVEL_2;
  12933. ent->client->ps.forcePowerLevel[FP_RAGE] = FORCE_LEVEL_1;
  12934. ent->client->ps.forcePowerLevel[FP_PROTECT] = FORCE_LEVEL_1;
  12935. ent->client->ps.forcePowerLevel[FP_ABSORB] = FORCE_LEVEL_1;
  12936. ent->client->ps.forcePowerLevel[FP_DRAIN] = FORCE_LEVEL_1;
  12937. ent->client->ps.forcePowerLevel[FP_SEE] = FORCE_LEVEL_1;
  12938. ent->client->ps.forcePowerLevel[FP_SABER_DEFENSE] = FORCE_LEVEL_3;
  12939. ent->client->ps.forcePowerLevel[FP_SABER_OFFENSE] = FORCE_LEVEL_3;
  12940. ent->client->ps.forcePowerLevel[FP_GRIP] = FORCE_LEVEL_2;
  12941. }
  12942. }
  12943. }
  12944. // Xbox Saber cycling cheat:
  12945. bool Cheat_ChangeSaber( void )
  12946. {
  12947. // Need to extern these. We can't #include qcommon.h because some fuckwit
  12948. // used LS_NONE to mean both a lightstyle and a sabermove.
  12949. extern char *Cvar_VariableString( const char *var_name );
  12950. extern void Cbuf_ExecuteText( int exec_when, const char *text );
  12951. // First: If we have NO saber, don't do the cheat! (t2_dpred) Also, if
  12952. // client is invalid, we're probably in the UI, so don't do anything:
  12953. if( !(g_entities[0].client) ||
  12954. !(g_entities[0].client->ps.stats[STAT_WEAPONS] & (1 << WP_SABER)) )
  12955. return false;
  12956. // Saved copies of saber vars, so we use the same model when we cycle
  12957. static char singleType1[32] = { 0 };
  12958. static char singleType2[32] = { 0 };
  12959. static char staffType[32] = { 0 };
  12960. // Get current saber information
  12961. char *s1 = Cvar_VariableString( "g_saber" );
  12962. char *s2 = Cvar_VariableString( "g_saber2" );
  12963. if( g_entities[0].client->ps.saber[0].type == SABER_STAFF )
  12964. {
  12965. // We're using a staff right now. Copy type out:
  12966. Q_strncpyz( staffType, s1, sizeof(staffType), qtrue );
  12967. // If we don't have a remembered single type, put in default
  12968. if( !singleType1[0] )
  12969. Q_strncpyz( singleType1, "single_1", sizeof(singleType1), qtrue );
  12970. // Switch to single saber, all three styles known:
  12971. g_entities[0].client->ps.saberStylesKnown = (1 << SS_FAST) | (1 << SS_MEDIUM) | (1 << SS_STRONG);
  12972. Cbuf_ExecuteText( EXEC_NOW, va("saber %s\n", singleType1) );
  12973. }
  12974. else if( g_entities[0].client->ps.dualSabers )
  12975. {
  12976. // We're using two sabers right now. Copy types:
  12977. Q_strncpyz( singleType1, s1, sizeof(singleType1), qtrue );
  12978. Q_strncpyz( singleType2, s2, sizeof(singleType2), qtrue );
  12979. // If we don't have a remembered staff type, put in default:
  12980. if( !staffType[0] )
  12981. Q_strncpyz( staffType, "dual_1", sizeof(staffType), qtrue );
  12982. // Switch to staff:
  12983. g_entities[0].client->ps.saberStylesKnown = (1 << SS_STAFF);
  12984. Cbuf_ExecuteText( EXEC_NOW, va("saber %s\n", staffType) );
  12985. }
  12986. else
  12987. {
  12988. // We're using one saber right now. Copy type:
  12989. Q_strncpyz( singleType1, s1, sizeof(singleType1), qtrue );
  12990. // If we don't have a remembered second type, copy first as default:
  12991. if( !singleType2[0] )
  12992. Q_strncpyz( singleType2, singleType1, sizeof(singleType2), qtrue );
  12993. // Switch to dual:
  12994. g_entities[0].client->ps.saberStylesKnown = (1 << SS_DUAL);
  12995. Cbuf_ExecuteText( EXEC_NOW, va("saber %s %s\n", singleType1, singleType2) );
  12996. }
  12997. return true;
  12998. }