P_ENEMY.C 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309
  1. //**************************************************************************
  2. //**
  3. //** p_enemy.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: p_enemy.c,v $
  6. //** $Revision: 1.170 $
  7. //** $Date: 96/01/06 03:23:28 $
  8. //** $Author: bgokey $
  9. //**
  10. //**************************************************************************
  11. #include "h2def.h"
  12. #include "p_local.h"
  13. #include "soundst.h"
  14. // Macros
  15. // Types
  16. // Private Data
  17. // External Data
  18. extern fixed_t FloatBobOffsets[64];
  19. //----------------------------------------------------------------------------
  20. //
  21. // PROC P_RecursiveSound
  22. //
  23. //----------------------------------------------------------------------------
  24. mobj_t *soundtarget;
  25. void P_RecursiveSound(sector_t *sec, int soundblocks)
  26. {
  27. int i;
  28. line_t *check;
  29. sector_t *other;
  30. // Wake up all monsters in this sector
  31. if(sec->validcount == validcount && sec->soundtraversed <= soundblocks+1)
  32. { // Already flooded
  33. return;
  34. }
  35. sec->validcount = validcount;
  36. sec->soundtraversed = soundblocks+1;
  37. sec->soundtarget = soundtarget;
  38. for(i = 0; i < sec->linecount; i++)
  39. {
  40. check = sec->lines[i];
  41. if(!(check->flags&ML_TWOSIDED))
  42. {
  43. continue;
  44. }
  45. P_LineOpening(check);
  46. if(openrange <= 0)
  47. { // Closed door
  48. continue;
  49. }
  50. if(sides[check->sidenum[0]].sector == sec)
  51. {
  52. other = sides[check->sidenum[1]].sector;
  53. }
  54. else
  55. {
  56. other = sides[check->sidenum[0]].sector;
  57. }
  58. if(check->flags&ML_SOUNDBLOCK)
  59. {
  60. if(!soundblocks)
  61. {
  62. P_RecursiveSound(other, 1);
  63. }
  64. }
  65. else
  66. {
  67. P_RecursiveSound(other, soundblocks);
  68. }
  69. }
  70. }
  71. //----------------------------------------------------------------------------
  72. //
  73. // PROC P_NoiseAlert
  74. //
  75. // If a monster yells at a player, it will alert other monsters to the
  76. // player.
  77. //
  78. //----------------------------------------------------------------------------
  79. void P_NoiseAlert(mobj_t *target, mobj_t *emmiter)
  80. {
  81. soundtarget = target;
  82. validcount++;
  83. P_RecursiveSound(emmiter->subsector->sector, 0);
  84. }
  85. //----------------------------------------------------------------------------
  86. //
  87. // FUNC P_CheckMeleeRange
  88. //
  89. //----------------------------------------------------------------------------
  90. boolean P_CheckMeleeRange(mobj_t *actor)
  91. {
  92. mobj_t *mo;
  93. fixed_t dist;
  94. if(!actor->target)
  95. {
  96. return(false);
  97. }
  98. mo = actor->target;
  99. dist = P_AproxDistance(mo->x-actor->x, mo->y-actor->y);
  100. if(dist >= MELEERANGE)
  101. {
  102. return(false);
  103. }
  104. if(!P_CheckSight(actor, mo))
  105. {
  106. return(false);
  107. }
  108. if(mo->z > actor->z+actor->height)
  109. { // Target is higher than the attacker
  110. return(false);
  111. }
  112. else if(actor->z > mo->z+mo->height)
  113. { // Attacker is higher
  114. return(false);
  115. }
  116. return(true);
  117. }
  118. //----------------------------------------------------------------------------
  119. //
  120. // FUNC P_CheckMeleeRange2
  121. //
  122. //----------------------------------------------------------------------------
  123. boolean P_CheckMeleeRange2(mobj_t *actor)
  124. {
  125. mobj_t *mo;
  126. fixed_t dist;
  127. if(!actor->target)
  128. {
  129. return(false);
  130. }
  131. mo = actor->target;
  132. dist = P_AproxDistance(mo->x-actor->x, mo->y-actor->y);
  133. if(dist >= MELEERANGE*2 || dist < MELEERANGE)
  134. {
  135. return(false);
  136. }
  137. if(!P_CheckSight(actor, mo))
  138. {
  139. return(false);
  140. }
  141. if(mo->z > actor->z+actor->height)
  142. { // Target is higher than the attacker
  143. return(false);
  144. }
  145. else if(actor->z > mo->z+mo->height)
  146. { // Attacker is higher
  147. return(false);
  148. }
  149. return(true);
  150. }
  151. //----------------------------------------------------------------------------
  152. //
  153. // FUNC P_CheckMissileRange
  154. //
  155. //----------------------------------------------------------------------------
  156. boolean P_CheckMissileRange(mobj_t *actor)
  157. {
  158. fixed_t dist;
  159. if(!P_CheckSight(actor, actor->target))
  160. {
  161. return(false);
  162. }
  163. if(actor->flags&MF_JUSTHIT)
  164. { // The target just hit the enemy, so fight back!
  165. actor->flags &= ~MF_JUSTHIT;
  166. return(true);
  167. }
  168. if(actor->reactiontime)
  169. { // Don't attack yet
  170. return(false);
  171. }
  172. dist = (P_AproxDistance(actor->x-actor->target->x,
  173. actor->y-actor->target->y)>>FRACBITS)-64;
  174. if(!actor->info->meleestate)
  175. { // No melee attack, so fire more frequently
  176. dist -= 128;
  177. }
  178. if(dist > 200)
  179. {
  180. dist = 200;
  181. }
  182. if(P_Random() < dist)
  183. {
  184. return(false);
  185. }
  186. return(true);
  187. }
  188. /*
  189. ================
  190. =
  191. = P_Move
  192. =
  193. = Move in the current direction
  194. = returns false if the move is blocked
  195. ================
  196. */
  197. fixed_t xspeed[8] = {FRACUNIT,47000,0,-47000,-FRACUNIT,-47000,0,47000};
  198. fixed_t yspeed[8] = {0,47000,FRACUNIT,47000,0,-47000,-FRACUNIT,-47000};
  199. #define MAXSPECIALCROSS 8
  200. extern line_t *spechit[MAXSPECIALCROSS];
  201. extern int numspechit;
  202. boolean P_Move(mobj_t *actor)
  203. {
  204. fixed_t tryx, tryy;
  205. line_t *ld;
  206. boolean good;
  207. if(actor->flags2&MF2_BLASTED) return(true);
  208. if(actor->movedir == DI_NODIR)
  209. {
  210. return(false);
  211. }
  212. tryx = actor->x+actor->info->speed*xspeed[actor->movedir];
  213. tryy = actor->y+actor->info->speed*yspeed[actor->movedir];
  214. if(!P_TryMove(actor, tryx, tryy))
  215. { // open any specials
  216. if(actor->flags&MF_FLOAT && floatok)
  217. { // must adjust height
  218. if(actor->z < tmfloorz)
  219. {
  220. actor->z += FLOATSPEED;
  221. }
  222. else
  223. {
  224. actor->z -= FLOATSPEED;
  225. }
  226. actor->flags |= MF_INFLOAT;
  227. return(true);
  228. }
  229. if(!numspechit)
  230. {
  231. return false;
  232. }
  233. actor->movedir = DI_NODIR;
  234. good = false;
  235. while(numspechit--)
  236. {
  237. ld = spechit[numspechit];
  238. // if the special isn't a door that can be opened, return false
  239. if(P_ActivateLine(ld, actor, 0, SPAC_USE))
  240. {
  241. good = true;
  242. }
  243. /* Old version before use/cross/impact specials were combined
  244. if(P_UseSpecialLine(actor, ld))
  245. {
  246. good = true;
  247. }
  248. */
  249. }
  250. return(good);
  251. }
  252. else
  253. {
  254. actor->flags &= ~MF_INFLOAT;
  255. }
  256. if(!(actor->flags&MF_FLOAT))
  257. {
  258. if(actor->z > actor->floorz)
  259. {
  260. P_HitFloor(actor);
  261. }
  262. actor->z = actor->floorz;
  263. }
  264. return(true);
  265. }
  266. //----------------------------------------------------------------------------
  267. //
  268. // FUNC P_TryWalk
  269. //
  270. // Attempts to move actor in its current (ob->moveangle) direction.
  271. // If blocked by either a wall or an actor returns FALSE.
  272. // If move is either clear of block only by a door, returns TRUE and sets.
  273. // If a door is in the way, an OpenDoor call is made to start it opening.
  274. //
  275. //----------------------------------------------------------------------------
  276. boolean P_TryWalk(mobj_t *actor)
  277. {
  278. if(!P_Move(actor))
  279. {
  280. return(false);
  281. }
  282. actor->movecount = P_Random()&15;
  283. return(true);
  284. }
  285. /*
  286. ================
  287. =
  288. = P_NewChaseDir
  289. =
  290. ================
  291. */
  292. dirtype_t opposite[] =
  293. {DI_WEST, DI_SOUTHWEST, DI_SOUTH, DI_SOUTHEAST, DI_EAST, DI_NORTHEAST,
  294. DI_NORTH, DI_NORTHWEST, DI_NODIR};
  295. dirtype_t diags[] = {DI_NORTHWEST,DI_NORTHEAST,DI_SOUTHWEST,DI_SOUTHEAST};
  296. void P_NewChaseDir (mobj_t *actor)
  297. {
  298. fixed_t deltax,deltay;
  299. dirtype_t d[3];
  300. dirtype_t tdir, olddir, turnaround;
  301. if (!actor->target)
  302. I_Error ("P_NewChaseDir: called with no target");
  303. olddir = actor->movedir;
  304. turnaround=opposite[olddir];
  305. deltax = actor->target->x - actor->x;
  306. deltay = actor->target->y - actor->y;
  307. if (deltax>10*FRACUNIT)
  308. d[1]= DI_EAST;
  309. else if (deltax<-10*FRACUNIT)
  310. d[1]= DI_WEST;
  311. else
  312. d[1]=DI_NODIR;
  313. if (deltay<-10*FRACUNIT)
  314. d[2]= DI_SOUTH;
  315. else if (deltay>10*FRACUNIT)
  316. d[2]= DI_NORTH;
  317. else
  318. d[2]=DI_NODIR;
  319. // try direct route
  320. if (d[1] != DI_NODIR && d[2] != DI_NODIR)
  321. {
  322. actor->movedir = diags[((deltay<0)<<1)+(deltax>0)];
  323. if (actor->movedir != turnaround && P_TryWalk(actor))
  324. return;
  325. }
  326. // try other directions
  327. if (P_Random() > 200 || abs(deltay)>abs(deltax))
  328. {
  329. tdir=d[1];
  330. d[1]=d[2];
  331. d[2]=tdir;
  332. }
  333. if (d[1]==turnaround)
  334. d[1]=DI_NODIR;
  335. if (d[2]==turnaround)
  336. d[2]=DI_NODIR;
  337. if (d[1]!=DI_NODIR)
  338. {
  339. actor->movedir = d[1];
  340. if (P_TryWalk(actor))
  341. return; /*either moved forward or attacked*/
  342. }
  343. if (d[2]!=DI_NODIR)
  344. {
  345. actor->movedir =d[2];
  346. if (P_TryWalk(actor))
  347. return;
  348. }
  349. /* there is no direct path to the player, so pick another direction */
  350. if (olddir!=DI_NODIR)
  351. {
  352. actor->movedir =olddir;
  353. if (P_TryWalk(actor))
  354. return;
  355. }
  356. if (P_Random()&1) /*randomly determine direction of search*/
  357. {
  358. for (tdir=DI_EAST ; tdir<=DI_SOUTHEAST ; tdir++)
  359. {
  360. if (tdir!=turnaround)
  361. {
  362. actor->movedir =tdir;
  363. if ( P_TryWalk(actor) )
  364. return;
  365. }
  366. }
  367. }
  368. else
  369. {
  370. for (tdir=DI_SOUTHEAST ; tdir >= DI_EAST;tdir--)
  371. {
  372. if (tdir!=turnaround)
  373. {
  374. actor->movedir =tdir;
  375. if ( P_TryWalk(actor) )
  376. return;
  377. }
  378. }
  379. }
  380. if (turnaround != DI_NODIR)
  381. {
  382. actor->movedir =turnaround;
  383. if ( P_TryWalk(actor) )
  384. return;
  385. }
  386. actor->movedir = DI_NODIR; // can't move
  387. }
  388. //---------------------------------------------------------------------------
  389. //
  390. // FUNC P_LookForMonsters
  391. //
  392. //---------------------------------------------------------------------------
  393. #define MONS_LOOK_RANGE (16*64*FRACUNIT)
  394. #define MONS_LOOK_LIMIT 64
  395. boolean P_LookForMonsters(mobj_t *actor)
  396. {
  397. int count;
  398. mobj_t *mo;
  399. thinker_t *think;
  400. if(!P_CheckSight(players[0].mo, actor))
  401. { // Player can't see monster
  402. return(false);
  403. }
  404. count = 0;
  405. for(think = thinkercap.next; think != &thinkercap; think = think->next)
  406. {
  407. if(think->function != P_MobjThinker)
  408. { // Not a mobj thinker
  409. continue;
  410. }
  411. mo = (mobj_t *)think;
  412. if(!(mo->flags&MF_COUNTKILL) || (mo == actor) || (mo->health <= 0))
  413. { // Not a valid monster
  414. continue;
  415. }
  416. if(P_AproxDistance(actor->x-mo->x, actor->y-mo->y)
  417. > MONS_LOOK_RANGE)
  418. { // Out of range
  419. continue;
  420. }
  421. if(P_Random() < 16)
  422. { // Skip
  423. continue;
  424. }
  425. if(count++ > MONS_LOOK_LIMIT)
  426. { // Stop searching
  427. return(false);
  428. }
  429. if(!P_CheckSight(actor, mo))
  430. { // Out of sight
  431. continue;
  432. }
  433. if (actor->type == MT_MINOTAUR)
  434. {
  435. if ((mo->type == MT_MINOTAUR) &&
  436. (mo->target != ((player_t *)actor->special1)->mo))
  437. {
  438. continue;
  439. }
  440. }
  441. // Found a target monster
  442. actor->target = mo;
  443. return(true);
  444. }
  445. return(false);
  446. }
  447. /*
  448. ================
  449. =
  450. = P_LookForPlayers
  451. =
  452. = If allaround is false, only look 180 degrees in front
  453. = returns true if a player is targeted
  454. ================
  455. */
  456. boolean P_LookForPlayers(mobj_t *actor, boolean allaround)
  457. {
  458. int c;
  459. int stop;
  460. player_t *player;
  461. sector_t *sector;
  462. angle_t an;
  463. fixed_t dist;
  464. if(!netgame && players[0].health <= 0)
  465. { // Single player game and player is dead, look for monsters
  466. return(P_LookForMonsters(actor));
  467. }
  468. sector = actor->subsector->sector;
  469. c = 0;
  470. stop = (actor->lastlook-1)&3;
  471. for( ; ; actor->lastlook = (actor->lastlook+1)&3 )
  472. {
  473. if (!playeringame[actor->lastlook])
  474. continue;
  475. if (c++ == 2 || actor->lastlook == stop)
  476. return false; // done looking
  477. player = &players[actor->lastlook];
  478. if (player->health <= 0)
  479. continue; // dead
  480. if (!P_CheckSight (actor, player->mo))
  481. continue; // out of sight
  482. if (!allaround)
  483. {
  484. an = R_PointToAngle2 (actor->x, actor->y,
  485. player->mo->x, player->mo->y) - actor->angle;
  486. if (an > ANG90 && an < ANG270)
  487. {
  488. dist = P_AproxDistance (player->mo->x - actor->x,
  489. player->mo->y - actor->y);
  490. // if real close, react anyway
  491. if (dist > MELEERANGE)
  492. continue; // behind back
  493. }
  494. }
  495. if(player->mo->flags&MF_SHADOW)
  496. { // Player is invisible
  497. if((P_AproxDistance(player->mo->x-actor->x,
  498. player->mo->y-actor->y) > 2*MELEERANGE)
  499. && P_AproxDistance(player->mo->momx, player->mo->momy)
  500. < 5*FRACUNIT)
  501. { // Player is sneaking - can't detect
  502. return(false);
  503. }
  504. if(P_Random() < 225)
  505. { // Player isn't sneaking, but still didn't detect
  506. return(false);
  507. }
  508. }
  509. if (actor->type == MT_MINOTAUR)
  510. {
  511. if(((player_t *)(actor->special1)) == player)
  512. {
  513. continue; // Don't target master
  514. }
  515. }
  516. actor->target = player->mo;
  517. return(true);
  518. }
  519. return(false);
  520. }
  521. /*
  522. ===============================================================================
  523. ACTION ROUTINES
  524. ===============================================================================
  525. */
  526. /*
  527. ==============
  528. =
  529. = A_Look
  530. =
  531. = Stay in state until a player is sighted
  532. =
  533. ==============
  534. */
  535. void A_Look (mobj_t *actor)
  536. {
  537. mobj_t *targ;
  538. actor->threshold = 0; // any shot will wake up
  539. targ = actor->subsector->sector->soundtarget;
  540. if (targ && (targ->flags & MF_SHOOTABLE) )
  541. {
  542. actor->target = targ;
  543. if ( actor->flags & MF_AMBUSH )
  544. {
  545. if (P_CheckSight (actor, actor->target))
  546. goto seeyou;
  547. }
  548. else
  549. goto seeyou;
  550. }
  551. if (!P_LookForPlayers (actor, false) )
  552. return;
  553. // go into chase state
  554. seeyou:
  555. if (actor->info->seesound)
  556. {
  557. int sound;
  558. sound = actor->info->seesound;
  559. if(actor->flags2&MF2_BOSS)
  560. { // Full volume
  561. S_StartSound(NULL, sound);
  562. }
  563. else
  564. {
  565. S_StartSound(actor, sound);
  566. }
  567. }
  568. P_SetMobjState(actor, actor->info->seestate);
  569. }
  570. /*
  571. ==============
  572. =
  573. = A_Chase
  574. =
  575. = Actor has a melee attack, so it tries to close as fast as possible
  576. =
  577. ==============
  578. */
  579. void A_Chase(mobj_t *actor)
  580. {
  581. int delta;
  582. if(actor->reactiontime)
  583. {
  584. actor->reactiontime--;
  585. }
  586. // Modify target threshold
  587. if(actor->threshold)
  588. {
  589. actor->threshold--;
  590. }
  591. if(gameskill == sk_nightmare)
  592. { // Monsters move faster in nightmare mode
  593. actor->tics -= actor->tics/2;
  594. if(actor->tics < 3)
  595. {
  596. actor->tics = 3;
  597. }
  598. }
  599. //
  600. // turn towards movement direction if not there yet
  601. //
  602. if(actor->movedir < 8)
  603. {
  604. actor->angle &= (7<<29);
  605. delta = actor->angle-(actor->movedir << 29);
  606. if(delta > 0)
  607. {
  608. actor->angle -= ANG90/2;
  609. }
  610. else if(delta < 0)
  611. {
  612. actor->angle += ANG90/2;
  613. }
  614. }
  615. if(!actor->target || !(actor->target->flags&MF_SHOOTABLE))
  616. { // look for a new target
  617. if(P_LookForPlayers(actor, true))
  618. { // got a new target
  619. return;
  620. }
  621. P_SetMobjState(actor, actor->info->spawnstate);
  622. return;
  623. }
  624. //
  625. // don't attack twice in a row
  626. //
  627. if(actor->flags & MF_JUSTATTACKED)
  628. {
  629. actor->flags &= ~MF_JUSTATTACKED;
  630. if (gameskill != sk_nightmare)
  631. P_NewChaseDir (actor);
  632. return;
  633. }
  634. //
  635. // check for melee attack
  636. //
  637. if (actor->info->meleestate && P_CheckMeleeRange (actor))
  638. {
  639. if(actor->info->attacksound)
  640. {
  641. S_StartSound (actor, actor->info->attacksound);
  642. }
  643. P_SetMobjState (actor, actor->info->meleestate);
  644. return;
  645. }
  646. //
  647. // check for missile attack
  648. //
  649. if (actor->info->missilestate)
  650. {
  651. if (gameskill < sk_nightmare && actor->movecount)
  652. goto nomissile;
  653. if (!P_CheckMissileRange (actor))
  654. goto nomissile;
  655. P_SetMobjState (actor, actor->info->missilestate);
  656. actor->flags |= MF_JUSTATTACKED;
  657. return;
  658. }
  659. nomissile:
  660. //
  661. // possibly choose another target
  662. //
  663. if (netgame && !actor->threshold && !P_CheckSight (actor, actor->target) )
  664. {
  665. if (P_LookForPlayers(actor,true))
  666. return; // got a new target
  667. }
  668. //
  669. // chase towards player
  670. //
  671. if (--actor->movecount<0 || !P_Move (actor))
  672. {
  673. P_NewChaseDir (actor);
  674. }
  675. //
  676. // make active sound
  677. //
  678. if(actor->info->activesound && P_Random() < 3)
  679. {
  680. if(actor->type == MT_BISHOP && P_Random() < 128)
  681. {
  682. S_StartSound(actor, actor->info->seesound);
  683. }
  684. else if(actor->type == MT_PIG)
  685. {
  686. S_StartSound(actor, SFX_PIG_ACTIVE1+(P_Random()&1));
  687. }
  688. else if(actor->flags2&MF2_BOSS)
  689. {
  690. S_StartSound(NULL, actor->info->activesound);
  691. }
  692. else
  693. {
  694. S_StartSound(actor, actor->info->activesound);
  695. }
  696. }
  697. }
  698. //----------------------------------------------------------------------------
  699. //
  700. // PROC A_FaceTarget
  701. //
  702. //----------------------------------------------------------------------------
  703. void A_FaceTarget(mobj_t *actor)
  704. {
  705. if(!actor->target)
  706. {
  707. return;
  708. }
  709. actor->flags &= ~MF_AMBUSH;
  710. actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x,
  711. actor->target->y);
  712. if(actor->target->flags&MF_SHADOW)
  713. { // Target is a ghost
  714. actor->angle += (P_Random()-P_Random())<<21;
  715. }
  716. }
  717. //----------------------------------------------------------------------------
  718. //
  719. // PROC A_Pain
  720. //
  721. //----------------------------------------------------------------------------
  722. void A_Pain(mobj_t *actor)
  723. {
  724. if(actor->info->painsound)
  725. {
  726. S_StartSound(actor, actor->info->painsound);
  727. }
  728. }
  729. //============================================================================
  730. //
  731. // A_SetInvulnerable
  732. //
  733. //============================================================================
  734. void A_SetInvulnerable(mobj_t *actor)
  735. {
  736. actor->flags2 |= MF2_INVULNERABLE;
  737. }
  738. //============================================================================
  739. //
  740. // A_UnSetInvulnerable
  741. //
  742. //============================================================================
  743. void A_UnSetInvulnerable(mobj_t *actor)
  744. {
  745. actor->flags2 &= ~MF2_INVULNERABLE;
  746. }
  747. //============================================================================
  748. //
  749. // A_SetReflective
  750. //
  751. //============================================================================
  752. void A_SetReflective(mobj_t *actor)
  753. {
  754. actor->flags2 |= MF2_REFLECTIVE;
  755. if ((actor->type == MT_CENTAUR) ||
  756. (actor->type == MT_CENTAURLEADER))
  757. {
  758. A_SetInvulnerable(actor);
  759. }
  760. }
  761. //============================================================================
  762. //
  763. // A_UnSetReflective
  764. //
  765. //============================================================================
  766. void A_UnSetReflective(mobj_t *actor)
  767. {
  768. actor->flags2 &= ~MF2_REFLECTIVE;
  769. if ((actor->type == MT_CENTAUR) ||
  770. (actor->type == MT_CENTAURLEADER))
  771. {
  772. A_UnSetInvulnerable(actor);
  773. }
  774. }
  775. //----------------------------------------------------------------------------
  776. //
  777. // FUNC P_UpdateMorphedMonster
  778. //
  779. // Returns true if the pig morphs.
  780. //
  781. //----------------------------------------------------------------------------
  782. boolean P_UpdateMorphedMonster(mobj_t *actor, int tics)
  783. {
  784. mobj_t *fog;
  785. fixed_t x;
  786. fixed_t y;
  787. fixed_t z;
  788. mobjtype_t moType;
  789. mobj_t *mo;
  790. mobj_t oldMonster;
  791. actor->special1 -= tics;
  792. if(actor->special1 > 0)
  793. {
  794. return(false);
  795. }
  796. moType = actor->special2;
  797. switch(moType)
  798. {
  799. case MT_WRAITHB: // These must remain morphed
  800. case MT_SERPENT:
  801. case MT_SERPENTLEADER:
  802. case MT_MINOTAUR:
  803. return(false);
  804. default:
  805. break;
  806. }
  807. x = actor->x;
  808. y = actor->y;
  809. z = actor->z;
  810. oldMonster = *actor; // Save pig vars
  811. P_RemoveMobjFromTIDList(actor);
  812. P_SetMobjState(actor, S_FREETARGMOBJ);
  813. mo = P_SpawnMobj(x, y, z, moType);
  814. if(P_TestMobjLocation(mo) == false)
  815. { // Didn't fit
  816. P_RemoveMobj(mo);
  817. mo = P_SpawnMobj(x, y, z, oldMonster.type);
  818. mo->angle = oldMonster.angle;
  819. mo->flags = oldMonster.flags;
  820. mo->health = oldMonster.health;
  821. mo->target = oldMonster.target;
  822. mo->special = oldMonster.special;
  823. mo->special1 = 5*35; // Next try in 5 seconds
  824. mo->special2 = moType;
  825. mo->tid = oldMonster.tid;
  826. memcpy(mo->args, oldMonster.args, 5);
  827. P_InsertMobjIntoTIDList(mo, oldMonster.tid);
  828. return(false);
  829. }
  830. mo->angle = oldMonster.angle;
  831. mo->target = oldMonster.target;
  832. mo->tid = oldMonster.tid;
  833. mo->special = oldMonster.special;
  834. memcpy(mo->args, oldMonster.args, 5);
  835. P_InsertMobjIntoTIDList(mo, oldMonster.tid);
  836. fog = P_SpawnMobj(x, y, z+TELEFOGHEIGHT, MT_TFOG);
  837. S_StartSound(fog, SFX_TELEPORT);
  838. return(true);
  839. }
  840. //----------------------------------------------------------------------------
  841. //
  842. // PROC A_PigLook
  843. //
  844. //----------------------------------------------------------------------------
  845. void A_PigLook(mobj_t *actor)
  846. {
  847. if(P_UpdateMorphedMonster(actor, 10))
  848. {
  849. return;
  850. }
  851. A_Look(actor);
  852. }
  853. //----------------------------------------------------------------------------
  854. //
  855. // PROC A_PigChase
  856. //
  857. //----------------------------------------------------------------------------
  858. void A_PigChase(mobj_t *actor)
  859. {
  860. if(P_UpdateMorphedMonster(actor, 3))
  861. {
  862. return;
  863. }
  864. A_Chase(actor);
  865. }
  866. //============================================================================
  867. //
  868. // A_PigAttack
  869. //
  870. //============================================================================
  871. void A_PigAttack(mobj_t *actor)
  872. {
  873. if(P_UpdateMorphedMonster(actor, 18))
  874. {
  875. return;
  876. }
  877. if(!actor->target)
  878. {
  879. return;
  880. }
  881. if(P_CheckMeleeRange(actor))
  882. {
  883. P_DamageMobj(actor->target, actor, actor, 2+(P_Random()&1));
  884. S_StartSound(actor, SFX_PIG_ATTACK);
  885. }
  886. }
  887. //============================================================================
  888. //
  889. // A_PigPain
  890. //
  891. //============================================================================
  892. void A_PigPain(mobj_t *actor)
  893. {
  894. A_Pain(actor);
  895. if(actor->z <= actor->floorz)
  896. {
  897. actor->momz = 3.5*FRACUNIT;
  898. }
  899. }
  900. void FaceMovementDirection(mobj_t *actor)
  901. {
  902. switch(actor->movedir)
  903. {
  904. case DI_EAST:
  905. actor->angle = 0<<24;
  906. break;
  907. case DI_NORTHEAST:
  908. actor->angle = 32<<24;
  909. break;
  910. case DI_NORTH:
  911. actor->angle = 64<<24;
  912. break;
  913. case DI_NORTHWEST:
  914. actor->angle = 96<<24;
  915. break;
  916. case DI_WEST:
  917. actor->angle = 128<<24;
  918. break;
  919. case DI_SOUTHWEST:
  920. actor->angle = 160<<24;
  921. break;
  922. case DI_SOUTH:
  923. actor->angle = 192<<24;
  924. break;
  925. case DI_SOUTHEAST:
  926. actor->angle = 224<<24;
  927. break;
  928. }
  929. }
  930. //----------------------------------------------------------------------------
  931. //
  932. // Minotaur variables
  933. //
  934. // special1 pointer to player that spawned it (mobj_t)
  935. // special2 internal to minotaur AI
  936. // args[0] args[0]-args[3] together make up minotaur start time
  937. // args[1] |
  938. // args[2] |
  939. // args[3] V
  940. // args[4] charge duration countdown
  941. //----------------------------------------------------------------------------
  942. void A_MinotaurFade0(mobj_t *actor)
  943. {
  944. actor->flags &= ~MF_ALTSHADOW;
  945. actor->flags |= MF_SHADOW;
  946. }
  947. void A_MinotaurFade1(mobj_t *actor)
  948. {
  949. // Second level of transparency
  950. actor->flags &= ~MF_SHADOW;
  951. actor->flags |= MF_ALTSHADOW;
  952. }
  953. void A_MinotaurFade2(mobj_t *actor)
  954. {
  955. // Make fully visible
  956. actor->flags &= ~MF_SHADOW;
  957. actor->flags &= ~MF_ALTSHADOW;
  958. }
  959. //----------------------------------------------------------------------------
  960. //
  961. // A_MinotaurRoam -
  962. //
  963. //
  964. //----------------------------------------------------------------------------
  965. void A_MinotaurLook(mobj_t *actor);
  966. void A_MinotaurRoam(mobj_t *actor)
  967. {
  968. unsigned int *starttime = (unsigned int *)actor->args;
  969. actor->flags &= ~MF_SHADOW; // In case pain caused him to
  970. actor->flags &= ~MF_ALTSHADOW; // skip his fade in.
  971. if ((leveltime - *starttime) >= MAULATORTICS)
  972. {
  973. P_DamageMobj(actor,NULL,NULL,10000);
  974. return;
  975. }
  976. if (P_Random()<30)
  977. A_MinotaurLook(actor); // adjust to closest target
  978. if (P_Random()<6)
  979. {
  980. //Choose new direction
  981. actor->movedir = P_Random() % 8;
  982. FaceMovementDirection(actor);
  983. }
  984. if (!P_Move(actor))
  985. {
  986. // Turn
  987. if (P_Random() & 1)
  988. actor->movedir = (++actor->movedir)%8;
  989. else
  990. actor->movedir = (actor->movedir+7)%8;
  991. FaceMovementDirection(actor);
  992. }
  993. }
  994. //----------------------------------------------------------------------------
  995. //
  996. // PROC A_MinotaurLook
  997. //
  998. // Look for enemy of player
  999. //----------------------------------------------------------------------------
  1000. #define MINOTAUR_LOOK_DIST (16*54*FRACUNIT)
  1001. void A_MinotaurLook(mobj_t *actor)
  1002. {
  1003. mobj_t *mo=NULL;
  1004. player_t *player;
  1005. thinker_t *think;
  1006. fixed_t dist;
  1007. int i;
  1008. mobj_t *master = (mobj_t *)(actor->special1);
  1009. actor->target = NULL;
  1010. if (deathmatch) // Quick search for players
  1011. {
  1012. for (i=0; i<MAXPLAYERS; i++)
  1013. {
  1014. if (!playeringame[i]) continue;
  1015. player = &players[i];
  1016. mo = player->mo;
  1017. if (mo == master) continue;
  1018. if (mo->health <= 0) continue;
  1019. dist = P_AproxDistance(actor->x - mo->x, actor->y - mo->y);
  1020. if (dist > MINOTAUR_LOOK_DIST) continue;
  1021. actor->target = mo;
  1022. break;
  1023. }
  1024. }
  1025. if (!actor->target) // Near player monster search
  1026. {
  1027. if (master && (master->health>0) && (master->player))
  1028. mo = P_RoughMonsterSearch(master, 20);
  1029. else
  1030. mo = P_RoughMonsterSearch(actor, 20);
  1031. actor->target = mo;
  1032. }
  1033. if (!actor->target) // Normal monster search
  1034. {
  1035. for(think = thinkercap.next; think != &thinkercap; think = think->next)
  1036. {
  1037. if(think->function != P_MobjThinker) continue;
  1038. mo = (mobj_t *)think;
  1039. if (!(mo->flags&MF_COUNTKILL)) continue;
  1040. if (mo->health <= 0) continue;
  1041. if (!(mo->flags&MF_SHOOTABLE)) continue;
  1042. dist = P_AproxDistance(actor->x - mo->x, actor->y - mo->y);
  1043. if (dist > MINOTAUR_LOOK_DIST) continue;
  1044. if ((mo == master) || (mo == actor)) continue;
  1045. if ((mo->type == MT_MINOTAUR) &&
  1046. (mo->special1 == actor->special1)) continue;
  1047. actor->target = mo;
  1048. break; // Found mobj to attack
  1049. }
  1050. }
  1051. if (actor->target)
  1052. {
  1053. P_SetMobjStateNF(actor, S_MNTR_WALK1);
  1054. }
  1055. else
  1056. {
  1057. P_SetMobjStateNF(actor, S_MNTR_ROAM1);
  1058. }
  1059. }
  1060. void A_MinotaurChase(mobj_t *actor)
  1061. {
  1062. unsigned int *starttime = (unsigned int *)actor->args;
  1063. actor->flags &= ~MF_SHADOW; // In case pain caused him to
  1064. actor->flags &= ~MF_ALTSHADOW; // skip his fade in.
  1065. if ((leveltime - *starttime) >= MAULATORTICS)
  1066. {
  1067. P_DamageMobj(actor,NULL,NULL,10000);
  1068. return;
  1069. }
  1070. if (P_Random()<30)
  1071. A_MinotaurLook(actor); // adjust to closest target
  1072. if (!actor->target || (actor->target->health <= 0) ||
  1073. !(actor->target->flags&MF_SHOOTABLE))
  1074. { // look for a new target
  1075. P_SetMobjState(actor, S_MNTR_LOOK1);
  1076. return;
  1077. }
  1078. FaceMovementDirection(actor);
  1079. actor->reactiontime=0;
  1080. // Melee attack
  1081. if (actor->info->meleestate && P_CheckMeleeRange(actor))
  1082. {
  1083. if(actor->info->attacksound)
  1084. {
  1085. S_StartSound (actor, actor->info->attacksound);
  1086. }
  1087. P_SetMobjState (actor, actor->info->meleestate);
  1088. return;
  1089. }
  1090. // Missile attack
  1091. if (actor->info->missilestate && P_CheckMissileRange(actor))
  1092. {
  1093. P_SetMobjState (actor, actor->info->missilestate);
  1094. return;
  1095. }
  1096. // chase towards target
  1097. if (!P_Move(actor))
  1098. {
  1099. P_NewChaseDir(actor);
  1100. }
  1101. // Active sound
  1102. if(actor->info->activesound && P_Random() < 6)
  1103. {
  1104. S_StartSound(actor, actor->info->activesound);
  1105. }
  1106. }
  1107. //----------------------------------------------------------------------------
  1108. //
  1109. // PROC A_MinotaurAtk1
  1110. //
  1111. // Melee attack.
  1112. //
  1113. //----------------------------------------------------------------------------
  1114. void A_MinotaurAtk1(mobj_t *actor)
  1115. {
  1116. if (!actor->target) return;
  1117. S_StartSound(actor, SFX_MAULATOR_HAMMER_SWING);
  1118. if(P_CheckMeleeRange(actor))
  1119. {
  1120. P_DamageMobj(actor->target, actor, actor, HITDICE(4));
  1121. }
  1122. }
  1123. //----------------------------------------------------------------------------
  1124. //
  1125. // PROC A_MinotaurDecide
  1126. //
  1127. // Choose a missile attack.
  1128. //
  1129. //----------------------------------------------------------------------------
  1130. #define MNTR_CHARGE_SPEED (23*FRACUNIT)
  1131. void A_MinotaurDecide(mobj_t *actor)
  1132. {
  1133. angle_t angle;
  1134. mobj_t *target = actor->target;
  1135. int dist;
  1136. if (!target) return;
  1137. dist = P_AproxDistance(actor->x-target->x, actor->y-target->y);
  1138. if(target->z+target->height > actor->z
  1139. && target->z+target->height < actor->z+actor->height
  1140. && dist < 16*64*FRACUNIT
  1141. && dist > 1*64*FRACUNIT
  1142. && P_Random() < 230)
  1143. { // Charge attack
  1144. // Don't call the state function right away
  1145. P_SetMobjStateNF(actor, S_MNTR_ATK4_1);
  1146. actor->flags |= MF_SKULLFLY;
  1147. A_FaceTarget(actor);
  1148. angle = actor->angle>>ANGLETOFINESHIFT;
  1149. actor->momx = FixedMul(MNTR_CHARGE_SPEED, finecosine[angle]);
  1150. actor->momy = FixedMul(MNTR_CHARGE_SPEED, finesine[angle]);
  1151. actor->args[4] = 35/2; // Charge duration
  1152. }
  1153. else if(target->z == target->floorz
  1154. && dist < 9*64*FRACUNIT
  1155. && P_Random() < 100)
  1156. { // Floor fire attack
  1157. P_SetMobjState(actor, S_MNTR_ATK3_1);
  1158. actor->special2 = 0;
  1159. }
  1160. else
  1161. { // Swing attack
  1162. A_FaceTarget(actor);
  1163. // Don't need to call P_SetMobjState because the current state
  1164. // falls through to the swing attack
  1165. }
  1166. }
  1167. //----------------------------------------------------------------------------
  1168. //
  1169. // PROC A_MinotaurCharge
  1170. //
  1171. //----------------------------------------------------------------------------
  1172. void A_MinotaurCharge(mobj_t *actor)
  1173. {
  1174. mobj_t *puff;
  1175. if (!actor->target) return;
  1176. if(actor->args[4] > 0)
  1177. {
  1178. puff = P_SpawnMobj(actor->x, actor->y, actor->z, MT_PUNCHPUFF);
  1179. puff->momz = 2*FRACUNIT;
  1180. actor->args[4]--;
  1181. }
  1182. else
  1183. {
  1184. actor->flags &= ~MF_SKULLFLY;
  1185. P_SetMobjState(actor, actor->info->seestate);
  1186. }
  1187. }
  1188. //----------------------------------------------------------------------------
  1189. //
  1190. // PROC A_MinotaurAtk2
  1191. //
  1192. // Swing attack.
  1193. //
  1194. //----------------------------------------------------------------------------
  1195. void A_MinotaurAtk2(mobj_t *actor)
  1196. {
  1197. mobj_t *mo;
  1198. angle_t angle;
  1199. fixed_t momz;
  1200. if(!actor->target) return;
  1201. S_StartSound(actor, SFX_MAULATOR_HAMMER_SWING);
  1202. if(P_CheckMeleeRange(actor))
  1203. {
  1204. P_DamageMobj(actor->target, actor, actor, HITDICE(3));
  1205. return;
  1206. }
  1207. mo = P_SpawnMissile(actor, actor->target, MT_MNTRFX1);
  1208. if(mo)
  1209. {
  1210. //S_StartSound(mo, sfx_minat2);
  1211. momz = mo->momz;
  1212. angle = mo->angle;
  1213. P_SpawnMissileAngle(actor, MT_MNTRFX1, angle-(ANG45/8), momz);
  1214. P_SpawnMissileAngle(actor, MT_MNTRFX1, angle+(ANG45/8), momz);
  1215. P_SpawnMissileAngle(actor, MT_MNTRFX1, angle-(ANG45/16), momz);
  1216. P_SpawnMissileAngle(actor, MT_MNTRFX1, angle+(ANG45/16), momz);
  1217. }
  1218. }
  1219. //----------------------------------------------------------------------------
  1220. //
  1221. // PROC A_MinotaurAtk3
  1222. //
  1223. // Floor fire attack.
  1224. //
  1225. //----------------------------------------------------------------------------
  1226. void A_MinotaurAtk3(mobj_t *actor)
  1227. {
  1228. mobj_t *mo;
  1229. player_t *player;
  1230. if(!actor->target)
  1231. {
  1232. return;
  1233. }
  1234. if(P_CheckMeleeRange(actor))
  1235. {
  1236. P_DamageMobj(actor->target, actor, actor, HITDICE(3));
  1237. if((player = actor->target->player) != NULL)
  1238. { // Squish the player
  1239. player->deltaviewheight = -16*FRACUNIT;
  1240. }
  1241. }
  1242. else
  1243. {
  1244. mo = P_SpawnMissile(actor, actor->target, MT_MNTRFX2);
  1245. if(mo != NULL)
  1246. {
  1247. S_StartSound(mo, SFX_MAULATOR_HAMMER_HIT);
  1248. }
  1249. }
  1250. if(P_Random() < 192 && actor->special2 == 0)
  1251. {
  1252. P_SetMobjState(actor, S_MNTR_ATK3_4);
  1253. actor->special2 = 1;
  1254. }
  1255. }
  1256. //----------------------------------------------------------------------------
  1257. //
  1258. // PROC A_MntrFloorFire
  1259. //
  1260. //----------------------------------------------------------------------------
  1261. void A_MntrFloorFire(mobj_t *actor)
  1262. {
  1263. mobj_t *mo;
  1264. actor->z = actor->floorz;
  1265. mo = P_SpawnMobj(actor->x+((P_Random()-P_Random())<<10),
  1266. actor->y+((P_Random()-P_Random())<<10), ONFLOORZ, MT_MNTRFX3);
  1267. mo->target = actor->target;
  1268. mo->momx = 1; // Force block checking
  1269. P_CheckMissileSpawn(mo);
  1270. }
  1271. //----------------------------------------------------------------------------
  1272. //
  1273. // PROC A_Scream
  1274. //
  1275. //----------------------------------------------------------------------------
  1276. void A_Scream(mobj_t *actor)
  1277. {
  1278. int sound;
  1279. S_StopSound(actor);
  1280. if(actor->player)
  1281. {
  1282. if(actor->player->morphTics)
  1283. {
  1284. S_StartSound(actor, actor->info->deathsound);
  1285. }
  1286. else
  1287. {
  1288. // Handle the different player death screams
  1289. if(actor->momz <= -39*FRACUNIT)
  1290. { // Falling splat
  1291. sound = SFX_PLAYER_FALLING_SPLAT;
  1292. }
  1293. else if(actor->health > -50)
  1294. { // Normal death sound
  1295. switch(actor->player->class)
  1296. {
  1297. case PCLASS_FIGHTER:
  1298. sound = SFX_PLAYER_FIGHTER_NORMAL_DEATH;
  1299. break;
  1300. case PCLASS_CLERIC:
  1301. sound = SFX_PLAYER_CLERIC_NORMAL_DEATH;
  1302. break;
  1303. case PCLASS_MAGE:
  1304. sound = SFX_PLAYER_MAGE_NORMAL_DEATH;
  1305. break;
  1306. default:
  1307. sound = SFX_NONE;
  1308. break;
  1309. }
  1310. }
  1311. else if(actor->health > -100)
  1312. { // Crazy death sound
  1313. switch(actor->player->class)
  1314. {
  1315. case PCLASS_FIGHTER:
  1316. sound = SFX_PLAYER_FIGHTER_CRAZY_DEATH;
  1317. break;
  1318. case PCLASS_CLERIC:
  1319. sound = SFX_PLAYER_CLERIC_CRAZY_DEATH;
  1320. break;
  1321. case PCLASS_MAGE:
  1322. sound = SFX_PLAYER_MAGE_CRAZY_DEATH;
  1323. break;
  1324. default:
  1325. sound = SFX_NONE;
  1326. break;
  1327. }
  1328. }
  1329. else
  1330. { // Extreme death sound
  1331. switch(actor->player->class)
  1332. {
  1333. case PCLASS_FIGHTER:
  1334. sound = SFX_PLAYER_FIGHTER_EXTREME1_DEATH;
  1335. break;
  1336. case PCLASS_CLERIC:
  1337. sound = SFX_PLAYER_CLERIC_EXTREME1_DEATH;
  1338. break;
  1339. case PCLASS_MAGE:
  1340. sound = SFX_PLAYER_MAGE_EXTREME1_DEATH;
  1341. break;
  1342. default:
  1343. sound = SFX_NONE;
  1344. break;
  1345. }
  1346. sound += P_Random()%3; // Three different extreme deaths
  1347. }
  1348. S_StartSound(actor, sound);
  1349. }
  1350. }
  1351. else
  1352. {
  1353. S_StartSound(actor, actor->info->deathsound);
  1354. }
  1355. }
  1356. //---------------------------------------------------------------------------
  1357. //
  1358. // PROC P_DropItem
  1359. //
  1360. //---------------------------------------------------------------------------
  1361. /*
  1362. void P_DropItem(mobj_t *source, mobjtype_t type, int special, int chance)
  1363. {
  1364. mobj_t *mo;
  1365. if(P_Random() > chance)
  1366. {
  1367. return;
  1368. }
  1369. mo = P_SpawnMobj(source->x, source->y,
  1370. source->z+(source->height>>1), type);
  1371. mo->momx = (P_Random()-P_Random())<<8;
  1372. mo->momy = (P_Random()-P_Random())<<8;
  1373. mo->momz = FRACUNIT*5+(P_Random()<<10);
  1374. mo->flags2 |= MF2_DROPPED;
  1375. mo->health = special;
  1376. }
  1377. */
  1378. //----------------------------------------------------------------------------
  1379. //
  1380. // PROC A_NoBlocking
  1381. //
  1382. //----------------------------------------------------------------------------
  1383. void A_NoBlocking(mobj_t *actor)
  1384. {
  1385. actor->flags &= ~MF_SOLID;
  1386. // Check for monsters dropping things
  1387. /* switch(actor->type)
  1388. {
  1389. // Add the monster dropped items here
  1390. case MT_MUMMYLEADERGHOST:
  1391. P_DropItem(actor, MT_AMGWNDWIMPY, 3, 84);
  1392. break;
  1393. default:
  1394. break;
  1395. }
  1396. */
  1397. }
  1398. //----------------------------------------------------------------------------
  1399. //
  1400. // PROC A_Explode
  1401. //
  1402. // Handles a bunch of exploding things.
  1403. //
  1404. //----------------------------------------------------------------------------
  1405. void A_Explode(mobj_t *actor)
  1406. {
  1407. int damage;
  1408. int distance;
  1409. boolean damageSelf;
  1410. damage = 128;
  1411. distance = 128;
  1412. damageSelf = true;
  1413. switch(actor->type)
  1414. {
  1415. case MT_FIREBOMB: // Time Bombs
  1416. actor->z += 32*FRACUNIT;
  1417. actor->flags &= ~MF_SHADOW;
  1418. break;
  1419. case MT_MNTRFX2: // Minotaur floor fire
  1420. damage = 24;
  1421. break;
  1422. case MT_BISHOP: // Bishop radius death
  1423. damage = 25+(P_Random()&15);
  1424. break;
  1425. case MT_HAMMER_MISSILE: // Fighter Hammer
  1426. damage = 128;
  1427. damageSelf = false;
  1428. break;
  1429. case MT_FSWORD_MISSILE: // Fighter Runesword
  1430. damage = 64;
  1431. damageSelf = false;
  1432. break;
  1433. case MT_CIRCLEFLAME: // Cleric Flame secondary flames
  1434. damage = 20;
  1435. damageSelf = false;
  1436. break;
  1437. case MT_SORCBALL1: // Sorcerer balls
  1438. case MT_SORCBALL2:
  1439. case MT_SORCBALL3:
  1440. distance = 255;
  1441. damage = 255;
  1442. actor->args[0] = 1; // don't play bounce
  1443. break;
  1444. case MT_SORCFX1: // Sorcerer spell 1
  1445. damage = 30;
  1446. break;
  1447. case MT_SORCFX4: // Sorcerer spell 4
  1448. damage = 20;
  1449. break;
  1450. case MT_TREEDESTRUCTIBLE:
  1451. damage = 10;
  1452. break;
  1453. case MT_DRAGON_FX2:
  1454. damage = 80;
  1455. damageSelf = false;
  1456. break;
  1457. case MT_MSTAFF_FX:
  1458. damage = 64;
  1459. distance = 192;
  1460. damageSelf = false;
  1461. break;
  1462. case MT_MSTAFF_FX2:
  1463. damage = 80;
  1464. distance = 192;
  1465. damageSelf = false;
  1466. break;
  1467. case MT_POISONCLOUD:
  1468. damage = 4;
  1469. distance = 40;
  1470. break;
  1471. case MT_ZXMAS_TREE:
  1472. case MT_ZSHRUB2:
  1473. damage = 30;
  1474. distance = 64;
  1475. break;
  1476. default:
  1477. break;
  1478. }
  1479. P_RadiusAttack(actor, actor->target, damage, distance, damageSelf);
  1480. if(actor->z <= actor->floorz+(distance<<FRACBITS)
  1481. && actor->type != MT_POISONCLOUD)
  1482. {
  1483. P_HitFloor(actor);
  1484. }
  1485. }
  1486. //----------------------------------------------------------------------------
  1487. //
  1488. // PROC P_Massacre
  1489. //
  1490. // Kills all monsters.
  1491. //
  1492. //----------------------------------------------------------------------------
  1493. int P_Massacre(void)
  1494. {
  1495. int count;
  1496. mobj_t *mo;
  1497. thinker_t *think;
  1498. count = 0;
  1499. for(think = thinkercap.next; think != &thinkercap;
  1500. think = think->next)
  1501. {
  1502. if(think->function != P_MobjThinker)
  1503. { // Not a mobj thinker
  1504. continue;
  1505. }
  1506. mo = (mobj_t *)think;
  1507. if((mo->flags&MF_COUNTKILL) && (mo->health > 0))
  1508. {
  1509. mo->flags2 &= ~(MF2_NONSHOOTABLE+MF2_INVULNERABLE);
  1510. mo->flags |= MF_SHOOTABLE;
  1511. P_DamageMobj(mo, NULL, NULL, 10000);
  1512. count++;
  1513. }
  1514. }
  1515. return count;
  1516. }
  1517. //----------------------------------------------------------------------------
  1518. //
  1519. // PROC A_SkullPop
  1520. //
  1521. //----------------------------------------------------------------------------
  1522. void A_SkullPop(mobj_t *actor)
  1523. {
  1524. mobj_t *mo;
  1525. player_t *player;
  1526. if(!actor->player)
  1527. {
  1528. return;
  1529. }
  1530. actor->flags &= ~MF_SOLID;
  1531. mo = P_SpawnMobj(actor->x, actor->y, actor->z+48*FRACUNIT,
  1532. MT_BLOODYSKULL);
  1533. //mo->target = actor;
  1534. mo->momx = (P_Random()-P_Random())<<9;
  1535. mo->momy = (P_Random()-P_Random())<<9;
  1536. mo->momz = FRACUNIT*2+(P_Random()<<6);
  1537. // Attach player mobj to bloody skull
  1538. player = actor->player;
  1539. actor->player = NULL;
  1540. actor->special1 = player->class;
  1541. mo->player = player;
  1542. mo->health = actor->health;
  1543. mo->angle = actor->angle;
  1544. player->mo = mo;
  1545. player->lookdir = 0;
  1546. player->damagecount = 32;
  1547. }
  1548. //----------------------------------------------------------------------------
  1549. //
  1550. // PROC A_CheckSkullFloor
  1551. //
  1552. //----------------------------------------------------------------------------
  1553. void A_CheckSkullFloor(mobj_t *actor)
  1554. {
  1555. if(actor->z <= actor->floorz)
  1556. {
  1557. P_SetMobjState(actor, S_BLOODYSKULLX1);
  1558. S_StartSound(actor, SFX_DRIP);
  1559. }
  1560. }
  1561. //----------------------------------------------------------------------------
  1562. //
  1563. // PROC A_CheckSkullDone
  1564. //
  1565. //----------------------------------------------------------------------------
  1566. void A_CheckSkullDone(mobj_t *actor)
  1567. {
  1568. if(actor->special2 == 666)
  1569. {
  1570. P_SetMobjState(actor, S_BLOODYSKULLX2);
  1571. }
  1572. }
  1573. //----------------------------------------------------------------------------
  1574. //
  1575. // PROC A_CheckBurnGone
  1576. //
  1577. //----------------------------------------------------------------------------
  1578. void A_CheckBurnGone(mobj_t *actor)
  1579. {
  1580. if(actor->special2 == 666)
  1581. {
  1582. P_SetMobjState(actor, S_PLAY_FDTH20);
  1583. }
  1584. }
  1585. //----------------------------------------------------------------------------
  1586. //
  1587. // PROC A_FreeTargMobj
  1588. //
  1589. //----------------------------------------------------------------------------
  1590. void A_FreeTargMobj(mobj_t *mo)
  1591. {
  1592. mo->momx = mo->momy = mo->momz = 0;
  1593. mo->z = mo->ceilingz+4*FRACUNIT;
  1594. mo->flags &= ~(MF_SHOOTABLE|MF_FLOAT|MF_SKULLFLY|MF_SOLID|MF_COUNTKILL);
  1595. mo->flags |= MF_CORPSE|MF_DROPOFF|MF_NOGRAVITY;
  1596. mo->flags2 &= ~(MF2_PASSMOBJ|MF2_LOGRAV);
  1597. mo->flags2 |= MF2_DONTDRAW;
  1598. mo->player = NULL;
  1599. mo->health = -1000; // Don't resurrect
  1600. }
  1601. //----------------------------------------------------------------------------
  1602. //
  1603. // CorpseQueue Routines
  1604. //
  1605. //----------------------------------------------------------------------------
  1606. // Corpse queue for monsters - this should be saved out
  1607. #define CORPSEQUEUESIZE 64
  1608. mobj_t *corpseQueue[CORPSEQUEUESIZE];
  1609. int corpseQueueSlot;
  1610. // throw another corpse on the queue
  1611. void A_QueueCorpse(mobj_t *actor)
  1612. {
  1613. mobj_t *corpse;
  1614. if(corpseQueueSlot >= CORPSEQUEUESIZE)
  1615. { // Too many corpses - remove an old one
  1616. corpse = corpseQueue[corpseQueueSlot%CORPSEQUEUESIZE];
  1617. if (corpse) P_RemoveMobj(corpse);
  1618. }
  1619. corpseQueue[corpseQueueSlot%CORPSEQUEUESIZE] = actor;
  1620. corpseQueueSlot++;
  1621. }
  1622. // Remove a mobj from the queue (for resurrection)
  1623. void A_DeQueueCorpse(mobj_t *actor)
  1624. {
  1625. int slot;
  1626. for (slot=0; slot<CORPSEQUEUESIZE; slot++)
  1627. {
  1628. if (corpseQueue[slot] == actor)
  1629. {
  1630. corpseQueue[slot] = NULL;
  1631. break;
  1632. }
  1633. }
  1634. }
  1635. void P_InitCreatureCorpseQueue(boolean corpseScan)
  1636. {
  1637. thinker_t *think;
  1638. mobj_t *mo;
  1639. // Initialize queue
  1640. corpseQueueSlot=0;
  1641. memset(corpseQueue, 0, sizeof(mobj_t *)*CORPSEQUEUESIZE);
  1642. if (!corpseScan) return;
  1643. // Search mobj list for corpses and place them in this queue
  1644. for(think = thinkercap.next; think != &thinkercap; think = think->next)
  1645. {
  1646. if(think->function != P_MobjThinker) continue;
  1647. mo = (mobj_t *)think;
  1648. if (!(mo->flags&MF_CORPSE)) continue; // Must be a corpse
  1649. if (mo->flags&MF_ICECORPSE) continue; // Not ice corpses
  1650. // Only corpses that call A_QueueCorpse from death routine
  1651. switch(mo->type)
  1652. {
  1653. case MT_CENTAUR:
  1654. case MT_CENTAURLEADER:
  1655. case MT_DEMON:
  1656. case MT_DEMON2:
  1657. case MT_WRAITH:
  1658. case MT_WRAITHB:
  1659. case MT_BISHOP:
  1660. case MT_ETTIN:
  1661. case MT_PIG:
  1662. case MT_CENTAUR_SHIELD:
  1663. case MT_CENTAUR_SWORD:
  1664. case MT_DEMONCHUNK1:
  1665. case MT_DEMONCHUNK2:
  1666. case MT_DEMONCHUNK3:
  1667. case MT_DEMONCHUNK4:
  1668. case MT_DEMONCHUNK5:
  1669. case MT_DEMON2CHUNK1:
  1670. case MT_DEMON2CHUNK2:
  1671. case MT_DEMON2CHUNK3:
  1672. case MT_DEMON2CHUNK4:
  1673. case MT_DEMON2CHUNK5:
  1674. case MT_FIREDEMON_SPLOTCH1:
  1675. case MT_FIREDEMON_SPLOTCH2:
  1676. A_QueueCorpse(mo); // Add corpse to queue
  1677. break;
  1678. default:
  1679. break;
  1680. }
  1681. }
  1682. }
  1683. //----------------------------------------------------------------------------
  1684. //
  1685. // PROC A_AddPlayerCorpse
  1686. //
  1687. //----------------------------------------------------------------------------
  1688. #define BODYQUESIZE 32
  1689. mobj_t *bodyque[BODYQUESIZE];
  1690. int bodyqueslot;
  1691. void A_AddPlayerCorpse(mobj_t *actor)
  1692. {
  1693. if(bodyqueslot >= BODYQUESIZE)
  1694. { // Too many player corpses - remove an old one
  1695. P_RemoveMobj(bodyque[bodyqueslot%BODYQUESIZE]);
  1696. }
  1697. bodyque[bodyqueslot%BODYQUESIZE] = actor;
  1698. bodyqueslot++;
  1699. }
  1700. //============================================================================
  1701. //
  1702. // A_SerpentUnHide
  1703. //
  1704. //============================================================================
  1705. void A_SerpentUnHide(mobj_t *actor)
  1706. {
  1707. actor->flags2 &= ~MF2_DONTDRAW;
  1708. actor->floorclip = 24*FRACUNIT;
  1709. }
  1710. //============================================================================
  1711. //
  1712. // A_SerpentHide
  1713. //
  1714. //============================================================================
  1715. void A_SerpentHide(mobj_t *actor)
  1716. {
  1717. actor->flags2 |= MF2_DONTDRAW;
  1718. actor->floorclip = 0;
  1719. }
  1720. //============================================================================
  1721. //
  1722. // A_SerpentChase
  1723. //
  1724. //============================================================================
  1725. void A_SerpentChase(mobj_t *actor)
  1726. {
  1727. int delta;
  1728. int oldX, oldY, oldFloor;
  1729. if(actor->reactiontime)
  1730. {
  1731. actor->reactiontime--;
  1732. }
  1733. // Modify target threshold
  1734. if(actor->threshold)
  1735. {
  1736. actor->threshold--;
  1737. }
  1738. if(gameskill == sk_nightmare)
  1739. { // Monsters move faster in nightmare mode
  1740. actor->tics -= actor->tics/2;
  1741. if(actor->tics < 3)
  1742. {
  1743. actor->tics = 3;
  1744. }
  1745. }
  1746. //
  1747. // turn towards movement direction if not there yet
  1748. //
  1749. if(actor->movedir < 8)
  1750. {
  1751. actor->angle &= (7<<29);
  1752. delta = actor->angle-(actor->movedir << 29);
  1753. if(delta > 0)
  1754. {
  1755. actor->angle -= ANG90/2;
  1756. }
  1757. else if(delta < 0)
  1758. {
  1759. actor->angle += ANG90/2;
  1760. }
  1761. }
  1762. if(!actor->target || !(actor->target->flags&MF_SHOOTABLE))
  1763. { // look for a new target
  1764. if(P_LookForPlayers(actor, true))
  1765. { // got a new target
  1766. return;
  1767. }
  1768. P_SetMobjState(actor, actor->info->spawnstate);
  1769. return;
  1770. }
  1771. //
  1772. // don't attack twice in a row
  1773. //
  1774. if(actor->flags & MF_JUSTATTACKED)
  1775. {
  1776. actor->flags &= ~MF_JUSTATTACKED;
  1777. if (gameskill != sk_nightmare)
  1778. P_NewChaseDir (actor);
  1779. return;
  1780. }
  1781. //
  1782. // check for melee attack
  1783. //
  1784. if (actor->info->meleestate && P_CheckMeleeRange (actor))
  1785. {
  1786. if(actor->info->attacksound)
  1787. {
  1788. S_StartSound (actor, actor->info->attacksound);
  1789. }
  1790. P_SetMobjState (actor, actor->info->meleestate);
  1791. return;
  1792. }
  1793. //
  1794. // possibly choose another target
  1795. //
  1796. if (netgame && !actor->threshold && !P_CheckSight (actor, actor->target) )
  1797. {
  1798. if (P_LookForPlayers(actor,true))
  1799. return; // got a new target
  1800. }
  1801. //
  1802. // chase towards player
  1803. //
  1804. oldX = actor->x;
  1805. oldY = actor->y;
  1806. oldFloor = actor->subsector->sector->floorpic;
  1807. if (--actor->movecount<0 || !P_Move (actor))
  1808. {
  1809. P_NewChaseDir (actor);
  1810. }
  1811. if(actor->subsector->sector->floorpic != oldFloor)
  1812. {
  1813. P_TryMove(actor, oldX, oldY);
  1814. P_NewChaseDir (actor);
  1815. }
  1816. //
  1817. // make active sound
  1818. //
  1819. if(actor->info->activesound && P_Random() < 3)
  1820. {
  1821. S_StartSound(actor, actor->info->activesound);
  1822. }
  1823. }
  1824. //============================================================================
  1825. //
  1826. // A_SerpentRaiseHump
  1827. //
  1828. // Raises the hump above the surface by raising the floorclip level
  1829. //============================================================================
  1830. void A_SerpentRaiseHump(mobj_t *actor)
  1831. {
  1832. actor->floorclip -= 4*FRACUNIT;
  1833. }
  1834. //============================================================================
  1835. //
  1836. // A_SerpentLowerHump
  1837. //
  1838. //============================================================================
  1839. void A_SerpentLowerHump(mobj_t *actor)
  1840. {
  1841. actor->floorclip += 4*FRACUNIT;
  1842. }
  1843. //============================================================================
  1844. //
  1845. // A_SerpentHumpDecide
  1846. //
  1847. // Decided whether to hump up, or if the mobj is a serpent leader,
  1848. // to missile attack
  1849. //============================================================================
  1850. void A_SerpentHumpDecide(mobj_t *actor)
  1851. {
  1852. if(actor->type == MT_SERPENTLEADER)
  1853. {
  1854. if(P_Random() > 30)
  1855. {
  1856. return;
  1857. }
  1858. else if(P_Random() < 40)
  1859. { // Missile attack
  1860. P_SetMobjState(actor, S_SERPENT_SURFACE1);
  1861. return;
  1862. }
  1863. }
  1864. else if(P_Random() > 3)
  1865. {
  1866. return;
  1867. }
  1868. if(!P_CheckMeleeRange(actor))
  1869. { // The hump shouldn't occur when within melee range
  1870. if(actor->type == MT_SERPENTLEADER && P_Random() < 128)
  1871. {
  1872. P_SetMobjState(actor, S_SERPENT_SURFACE1);
  1873. }
  1874. else
  1875. {
  1876. P_SetMobjState(actor, S_SERPENT_HUMP1);
  1877. S_StartSound(actor, SFX_SERPENT_ACTIVE);
  1878. }
  1879. }
  1880. }
  1881. //============================================================================
  1882. //
  1883. // A_SerpentBirthScream
  1884. //
  1885. //============================================================================
  1886. void A_SerpentBirthScream(mobj_t *actor)
  1887. {
  1888. S_StartSound(actor, SFX_SERPENT_BIRTH);
  1889. }
  1890. //============================================================================
  1891. //
  1892. // A_SerpentDiveSound
  1893. //
  1894. //============================================================================
  1895. void A_SerpentDiveSound(mobj_t *actor)
  1896. {
  1897. S_StartSound(actor, SFX_SERPENT_ACTIVE);
  1898. }
  1899. //============================================================================
  1900. //
  1901. // A_SerpentWalk
  1902. //
  1903. // Similar to A_Chase, only has a hardcoded entering of meleestate
  1904. //============================================================================
  1905. void A_SerpentWalk(mobj_t *actor)
  1906. {
  1907. int delta;
  1908. if(actor->reactiontime)
  1909. {
  1910. actor->reactiontime--;
  1911. }
  1912. // Modify target threshold
  1913. if(actor->threshold)
  1914. {
  1915. actor->threshold--;
  1916. }
  1917. if(gameskill == sk_nightmare)
  1918. { // Monsters move faster in nightmare mode
  1919. actor->tics -= actor->tics/2;
  1920. if(actor->tics < 3)
  1921. {
  1922. actor->tics = 3;
  1923. }
  1924. }
  1925. //
  1926. // turn towards movement direction if not there yet
  1927. //
  1928. if(actor->movedir < 8)
  1929. {
  1930. actor->angle &= (7<<29);
  1931. delta = actor->angle-(actor->movedir << 29);
  1932. if(delta > 0)
  1933. {
  1934. actor->angle -= ANG90/2;
  1935. }
  1936. else if(delta < 0)
  1937. {
  1938. actor->angle += ANG90/2;
  1939. }
  1940. }
  1941. if(!actor->target || !(actor->target->flags&MF_SHOOTABLE))
  1942. { // look for a new target
  1943. if(P_LookForPlayers(actor, true))
  1944. { // got a new target
  1945. return;
  1946. }
  1947. P_SetMobjState(actor, actor->info->spawnstate);
  1948. return;
  1949. }
  1950. //
  1951. // don't attack twice in a row
  1952. //
  1953. if(actor->flags & MF_JUSTATTACKED)
  1954. {
  1955. actor->flags &= ~MF_JUSTATTACKED;
  1956. if (gameskill != sk_nightmare)
  1957. P_NewChaseDir (actor);
  1958. return;
  1959. }
  1960. //
  1961. // check for melee attack
  1962. //
  1963. if (actor->info->meleestate && P_CheckMeleeRange (actor))
  1964. {
  1965. if (actor->info->attacksound)
  1966. {
  1967. S_StartSound (actor, actor->info->attacksound);
  1968. }
  1969. P_SetMobjState(actor, S_SERPENT_ATK1);
  1970. return;
  1971. }
  1972. //
  1973. // possibly choose another target
  1974. //
  1975. if (netgame && !actor->threshold && !P_CheckSight (actor, actor->target) )
  1976. {
  1977. if (P_LookForPlayers(actor,true))
  1978. return; // got a new target
  1979. }
  1980. //
  1981. // chase towards player
  1982. //
  1983. if (--actor->movecount<0 || !P_Move (actor))
  1984. {
  1985. P_NewChaseDir (actor);
  1986. }
  1987. }
  1988. //============================================================================
  1989. //
  1990. // A_SerpentCheckForAttack
  1991. //
  1992. //============================================================================
  1993. void A_SerpentCheckForAttack(mobj_t *actor)
  1994. {
  1995. if(!actor->target)
  1996. {
  1997. return;
  1998. }
  1999. if(actor->type == MT_SERPENTLEADER)
  2000. {
  2001. if(!P_CheckMeleeRange(actor))
  2002. {
  2003. P_SetMobjState(actor, S_SERPENT_ATK1);
  2004. return;
  2005. }
  2006. }
  2007. if(P_CheckMeleeRange2(actor))
  2008. {
  2009. P_SetMobjState(actor, S_SERPENT_WALK1);
  2010. }
  2011. else if(P_CheckMeleeRange(actor))
  2012. {
  2013. if(P_Random() < 32)
  2014. {
  2015. P_SetMobjState(actor, S_SERPENT_WALK1);
  2016. }
  2017. else
  2018. {
  2019. P_SetMobjState(actor, S_SERPENT_ATK1);
  2020. }
  2021. }
  2022. }
  2023. //============================================================================
  2024. //
  2025. // A_SerpentChooseAttack
  2026. //
  2027. //============================================================================
  2028. void A_SerpentChooseAttack(mobj_t *actor)
  2029. {
  2030. if(!actor->target || P_CheckMeleeRange(actor))
  2031. {
  2032. return;
  2033. }
  2034. if(actor->type == MT_SERPENTLEADER)
  2035. {
  2036. P_SetMobjState(actor, S_SERPENT_MISSILE1);
  2037. }
  2038. }
  2039. //============================================================================
  2040. //
  2041. // A_SerpentMeleeAttack
  2042. //
  2043. //============================================================================
  2044. void A_SerpentMeleeAttack(mobj_t *actor)
  2045. {
  2046. if(!actor->target)
  2047. {
  2048. return;
  2049. }
  2050. if(P_CheckMeleeRange(actor))
  2051. {
  2052. P_DamageMobj(actor->target, actor, actor, HITDICE(5));
  2053. S_StartSound(actor, SFX_SERPENT_MELEEHIT);
  2054. }
  2055. if(P_Random() < 96)
  2056. {
  2057. A_SerpentCheckForAttack(actor);
  2058. }
  2059. }
  2060. //============================================================================
  2061. //
  2062. // A_SerpentMissileAttack
  2063. //
  2064. //============================================================================
  2065. void A_SerpentMissileAttack(mobj_t *actor)
  2066. {
  2067. mobj_t *mo;
  2068. if(!actor->target)
  2069. {
  2070. return;
  2071. }
  2072. mo = P_SpawnMissile(actor, actor->target, MT_SERPENTFX);
  2073. }
  2074. //============================================================================
  2075. //
  2076. // A_SerpentHeadPop
  2077. //
  2078. //============================================================================
  2079. void A_SerpentHeadPop(mobj_t *actor)
  2080. {
  2081. P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT, MT_SERPENT_HEAD);
  2082. }
  2083. //============================================================================
  2084. //
  2085. // A_SerpentSpawnGibs
  2086. //
  2087. //============================================================================
  2088. void A_SerpentSpawnGibs(mobj_t *actor)
  2089. {
  2090. mobj_t *mo;
  2091. mo = P_SpawnMobj(actor->x+((P_Random()-128)<<12),
  2092. actor->y+((P_Random()-128)<<12), actor->floorz+FRACUNIT,
  2093. MT_SERPENT_GIB1);
  2094. if(mo)
  2095. {
  2096. mo->momx = (P_Random()-128)<<6;
  2097. mo->momy = (P_Random()-128)<<6;
  2098. mo->floorclip = 6*FRACUNIT;
  2099. }
  2100. mo = P_SpawnMobj(actor->x+((P_Random()-128)<<12),
  2101. actor->y+((P_Random()-128)<<12), actor->floorz+FRACUNIT,
  2102. MT_SERPENT_GIB2);
  2103. if(mo)
  2104. {
  2105. mo->momx = (P_Random()-128)<<6;
  2106. mo->momy = (P_Random()-128)<<6;
  2107. mo->floorclip = 6*FRACUNIT;
  2108. }
  2109. mo = P_SpawnMobj(actor->x+((P_Random()-128)<<12),
  2110. actor->y+((P_Random()-128)<<12), actor->floorz+FRACUNIT,
  2111. MT_SERPENT_GIB3);
  2112. if(mo)
  2113. {
  2114. mo->momx = (P_Random()-128)<<6;
  2115. mo->momy = (P_Random()-128)<<6;
  2116. mo->floorclip = 6*FRACUNIT;
  2117. }
  2118. }
  2119. //============================================================================
  2120. //
  2121. // A_FloatGib
  2122. //
  2123. //============================================================================
  2124. void A_FloatGib(mobj_t *actor)
  2125. {
  2126. actor->floorclip -= FRACUNIT;
  2127. }
  2128. //============================================================================
  2129. //
  2130. // A_SinkGib
  2131. //
  2132. //============================================================================
  2133. void A_SinkGib(mobj_t *actor)
  2134. {
  2135. actor->floorclip += FRACUNIT;
  2136. }
  2137. //============================================================================
  2138. //
  2139. // A_DelayGib
  2140. //
  2141. //============================================================================
  2142. void A_DelayGib(mobj_t *actor)
  2143. {
  2144. actor->tics -= P_Random()>>2;
  2145. }
  2146. //============================================================================
  2147. //
  2148. // A_SerpentHeadCheck
  2149. //
  2150. //============================================================================
  2151. void A_SerpentHeadCheck(mobj_t *actor)
  2152. {
  2153. if(actor->z <= actor->floorz)
  2154. {
  2155. if(P_GetThingFloorType(actor) >= FLOOR_LIQUID)
  2156. {
  2157. P_HitFloor(actor);
  2158. P_SetMobjState(actor, S_NULL);
  2159. }
  2160. else
  2161. {
  2162. P_SetMobjState(actor, S_SERPENT_HEAD_X1);
  2163. }
  2164. }
  2165. }
  2166. //============================================================================
  2167. //
  2168. // A_CentaurAttack
  2169. //
  2170. //============================================================================
  2171. void A_CentaurAttack(mobj_t *actor)
  2172. {
  2173. if(!actor->target)
  2174. {
  2175. return;
  2176. }
  2177. if(P_CheckMeleeRange(actor))
  2178. {
  2179. P_DamageMobj(actor->target, actor, actor, P_Random()%7+3);
  2180. }
  2181. }
  2182. //============================================================================
  2183. //
  2184. // A_CentaurAttack2
  2185. //
  2186. //============================================================================
  2187. void A_CentaurAttack2(mobj_t *actor)
  2188. {
  2189. if(!actor->target)
  2190. {
  2191. return;
  2192. }
  2193. P_SpawnMissile(actor, actor->target, MT_CENTAUR_FX);
  2194. S_StartSound(actor, SFX_CENTAURLEADER_ATTACK);
  2195. }
  2196. //============================================================================
  2197. //
  2198. // A_CentaurDropStuff
  2199. //
  2200. // Spawn shield/sword sprites when the centaur pulps //============================================================================
  2201. void A_CentaurDropStuff(mobj_t *actor)
  2202. {
  2203. mobj_t *mo;
  2204. angle_t angle;
  2205. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2206. MT_CENTAUR_SHIELD);
  2207. if(mo)
  2208. {
  2209. angle = actor->angle+ANG90;
  2210. mo->momz = FRACUNIT*8+(P_Random()<<10);
  2211. mo->momx = FixedMul(((P_Random()-128)<<11)+FRACUNIT,
  2212. finecosine[angle>>ANGLETOFINESHIFT]);
  2213. mo->momy = FixedMul(((P_Random()-128)<<11)+FRACUNIT,
  2214. finesine[angle>>ANGLETOFINESHIFT]);
  2215. mo->target = actor;
  2216. }
  2217. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2218. MT_CENTAUR_SWORD);
  2219. if(mo)
  2220. {
  2221. angle = actor->angle-ANG90;
  2222. mo->momz = FRACUNIT*8+(P_Random()<<10);
  2223. mo->momx = FixedMul(((P_Random()-128)<<11)+FRACUNIT,
  2224. finecosine[angle>>ANGLETOFINESHIFT]);
  2225. mo->momy = FixedMul(((P_Random()-128)<<11)+FRACUNIT,
  2226. finesine[angle>>ANGLETOFINESHIFT]);
  2227. mo->target = actor;
  2228. }
  2229. }
  2230. //============================================================================
  2231. //
  2232. // A_CentaurDefend
  2233. //
  2234. //============================================================================
  2235. void A_CentaurDefend(mobj_t *actor)
  2236. {
  2237. A_FaceTarget(actor);
  2238. if(P_CheckMeleeRange(actor) && P_Random() < 32)
  2239. {
  2240. A_UnSetInvulnerable(actor);
  2241. P_SetMobjState(actor, actor->info->meleestate);
  2242. }
  2243. }
  2244. //============================================================================
  2245. //
  2246. // A_BishopAttack
  2247. //
  2248. //============================================================================
  2249. void A_BishopAttack(mobj_t *actor)
  2250. {
  2251. if(!actor->target)
  2252. {
  2253. return;
  2254. }
  2255. S_StartSound(actor, actor->info->attacksound);
  2256. if(P_CheckMeleeRange(actor))
  2257. {
  2258. P_DamageMobj(actor->target, actor, actor, HITDICE(4));
  2259. return;
  2260. }
  2261. actor->special1 = (P_Random()&3)+5;
  2262. }
  2263. //============================================================================
  2264. //
  2265. // A_BishopAttack2
  2266. //
  2267. // Spawns one of a string of bishop missiles
  2268. //============================================================================
  2269. void A_BishopAttack2(mobj_t *actor)
  2270. {
  2271. mobj_t *mo;
  2272. if(!actor->target || !actor->special1)
  2273. {
  2274. actor->special1 = 0;
  2275. P_SetMobjState(actor, S_BISHOP_WALK1);
  2276. return;
  2277. }
  2278. mo = P_SpawnMissile(actor, actor->target, MT_BISH_FX);
  2279. if(mo)
  2280. {
  2281. mo->special1 = (int)actor->target;
  2282. mo->special2 = 16; // High word == x/y, Low word == z
  2283. }
  2284. actor->special1--;
  2285. }
  2286. //============================================================================
  2287. //
  2288. // A_BishopMissileWeave
  2289. //
  2290. //============================================================================
  2291. void A_BishopMissileWeave(mobj_t *actor)
  2292. {
  2293. fixed_t newX, newY;
  2294. int weaveXY, weaveZ;
  2295. int angle;
  2296. weaveXY = actor->special2>>16;
  2297. weaveZ = actor->special2&0xFFFF;
  2298. angle = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  2299. newX = actor->x-FixedMul(finecosine[angle],
  2300. FloatBobOffsets[weaveXY]<<1);
  2301. newY = actor->y-FixedMul(finesine[angle],
  2302. FloatBobOffsets[weaveXY]<<1);
  2303. weaveXY = (weaveXY+2)&63;
  2304. newX += FixedMul(finecosine[angle],
  2305. FloatBobOffsets[weaveXY]<<1);
  2306. newY += FixedMul(finesine[angle],
  2307. FloatBobOffsets[weaveXY]<<1);
  2308. P_TryMove(actor, newX, newY);
  2309. actor->z -= FloatBobOffsets[weaveZ];
  2310. weaveZ = (weaveZ+2)&63;
  2311. actor->z += FloatBobOffsets[weaveZ];
  2312. actor->special2 = weaveZ+(weaveXY<<16);
  2313. }
  2314. //============================================================================
  2315. //
  2316. // A_BishopMissileSeek
  2317. //
  2318. //============================================================================
  2319. void A_BishopMissileSeek(mobj_t *actor)
  2320. {
  2321. P_SeekerMissile(actor, ANGLE_1*2, ANGLE_1*3);
  2322. }
  2323. //============================================================================
  2324. //
  2325. // A_BishopDecide
  2326. //
  2327. //============================================================================
  2328. void A_BishopDecide(mobj_t *actor)
  2329. {
  2330. if(P_Random() < 220)
  2331. {
  2332. return;
  2333. }
  2334. else
  2335. {
  2336. P_SetMobjState(actor, S_BISHOP_BLUR1);
  2337. }
  2338. }
  2339. //============================================================================
  2340. //
  2341. // A_BishopDoBlur
  2342. //
  2343. //============================================================================
  2344. void A_BishopDoBlur(mobj_t *actor)
  2345. {
  2346. actor->special1 = (P_Random()&3)+3; // Random number of blurs
  2347. if(P_Random() < 120)
  2348. {
  2349. P_ThrustMobj(actor, actor->angle+ANG90, 11*FRACUNIT);
  2350. }
  2351. else if(P_Random() > 125)
  2352. {
  2353. P_ThrustMobj(actor, actor->angle-ANG90, 11*FRACUNIT);
  2354. }
  2355. else
  2356. { // Thrust forward
  2357. P_ThrustMobj(actor, actor->angle, 11*FRACUNIT);
  2358. }
  2359. S_StartSound(actor, SFX_BISHOP_BLUR);
  2360. }
  2361. //============================================================================
  2362. //
  2363. // A_BishopSpawnBlur
  2364. //
  2365. //============================================================================
  2366. void A_BishopSpawnBlur(mobj_t *actor)
  2367. {
  2368. mobj_t *mo;
  2369. if(!--actor->special1)
  2370. {
  2371. actor->momx = 0;
  2372. actor->momy = 0;
  2373. if(P_Random() > 96)
  2374. {
  2375. P_SetMobjState(actor, S_BISHOP_WALK1);
  2376. }
  2377. else
  2378. {
  2379. P_SetMobjState(actor, S_BISHOP_ATK1);
  2380. }
  2381. }
  2382. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_BISHOPBLUR);
  2383. if(mo)
  2384. {
  2385. mo->angle = actor->angle;
  2386. }
  2387. }
  2388. //============================================================================
  2389. //
  2390. // A_BishopChase
  2391. //
  2392. //============================================================================
  2393. void A_BishopChase(mobj_t *actor)
  2394. {
  2395. actor->z -= FloatBobOffsets[actor->special2]>>1;
  2396. actor->special2 = (actor->special2+4)&63;
  2397. actor->z += FloatBobOffsets[actor->special2]>>1;
  2398. }
  2399. //============================================================================
  2400. //
  2401. // A_BishopPuff
  2402. //
  2403. //============================================================================
  2404. void A_BishopPuff(mobj_t *actor)
  2405. {
  2406. mobj_t *mo;
  2407. mo = P_SpawnMobj(actor->x, actor->y, actor->z+40*FRACUNIT,
  2408. MT_BISHOP_PUFF);
  2409. if(mo)
  2410. {
  2411. mo->momz = FRACUNIT/2;
  2412. }
  2413. }
  2414. //============================================================================
  2415. //
  2416. // A_BishopPainBlur
  2417. //
  2418. //============================================================================
  2419. void A_BishopPainBlur(mobj_t *actor)
  2420. {
  2421. mobj_t *mo;
  2422. if(P_Random() < 64)
  2423. {
  2424. P_SetMobjState(actor, S_BISHOP_BLUR1);
  2425. return;
  2426. }
  2427. mo = P_SpawnMobj(actor->x+((P_Random()-P_Random())<<12), actor->y
  2428. +((P_Random()-P_Random())<<12), actor->z+((P_Random()-P_Random())<<11),
  2429. MT_BISHOPPAINBLUR);
  2430. if(mo)
  2431. {
  2432. mo->angle = actor->angle;
  2433. }
  2434. }
  2435. //============================================================================
  2436. //
  2437. // DragonSeek
  2438. //
  2439. //============================================================================
  2440. static void DragonSeek(mobj_t *actor, angle_t thresh, angle_t turnMax)
  2441. {
  2442. int dir;
  2443. int dist;
  2444. angle_t delta;
  2445. angle_t angle;
  2446. mobj_t *target;
  2447. int search;
  2448. int i;
  2449. int bestArg;
  2450. angle_t bestAngle;
  2451. angle_t angleToSpot, angleToTarget;
  2452. mobj_t *mo;
  2453. target = (mobj_t *)actor->special1;
  2454. if(target == NULL)
  2455. {
  2456. return;
  2457. }
  2458. dir = P_FaceMobj(actor, target, &delta);
  2459. if(delta > thresh)
  2460. {
  2461. delta >>= 1;
  2462. if(delta > turnMax)
  2463. {
  2464. delta = turnMax;
  2465. }
  2466. }
  2467. if(dir)
  2468. { // Turn clockwise
  2469. actor->angle += delta;
  2470. }
  2471. else
  2472. { // Turn counter clockwise
  2473. actor->angle -= delta;
  2474. }
  2475. angle = actor->angle>>ANGLETOFINESHIFT;
  2476. actor->momx = FixedMul(actor->info->speed, finecosine[angle]);
  2477. actor->momy = FixedMul(actor->info->speed, finesine[angle]);
  2478. if(actor->z+actor->height < target->z
  2479. || target->z+target->height < actor->z)
  2480. {
  2481. dist = P_AproxDistance(target->x-actor->x, target->y-actor->y);
  2482. dist = dist/actor->info->speed;
  2483. if(dist < 1)
  2484. {
  2485. dist = 1;
  2486. }
  2487. actor->momz = (target->z-actor->z)/dist;
  2488. }
  2489. else
  2490. {
  2491. dist = P_AproxDistance(target->x-actor->x, target->y-actor->y);
  2492. dist = dist/actor->info->speed;
  2493. }
  2494. if(target->flags&MF_SHOOTABLE && P_Random() < 64)
  2495. { // attack the destination mobj if it's attackable
  2496. mobj_t *oldTarget;
  2497. if(abs(actor->angle-R_PointToAngle2(actor->x, actor->y,
  2498. target->x, target->y)) < ANGLE_45/2)
  2499. {
  2500. oldTarget = actor->target;
  2501. actor->target = target;
  2502. if(P_CheckMeleeRange(actor))
  2503. {
  2504. P_DamageMobj(actor->target, actor, actor, HITDICE(10));
  2505. S_StartSound(actor, SFX_DRAGON_ATTACK);
  2506. }
  2507. else if(P_Random() < 128 && P_CheckMissileRange(actor))
  2508. {
  2509. P_SpawnMissile(actor, target, MT_DRAGON_FX);
  2510. S_StartSound(actor, SFX_DRAGON_ATTACK);
  2511. }
  2512. actor->target = oldTarget;
  2513. }
  2514. }
  2515. if(dist < 4)
  2516. { // Hit the target thing
  2517. if(actor->target && P_Random() < 200)
  2518. {
  2519. bestArg = -1;
  2520. bestAngle = ANGLE_MAX;
  2521. angleToTarget = R_PointToAngle2(actor->x, actor->y,
  2522. actor->target->x, actor->target->y);
  2523. for(i = 0; i < 5; i++)
  2524. {
  2525. if(!target->args[i])
  2526. {
  2527. continue;
  2528. }
  2529. search = -1;
  2530. mo = P_FindMobjFromTID(target->args[i], &search);
  2531. angleToSpot = R_PointToAngle2(actor->x, actor->y,
  2532. mo->x, mo->y);
  2533. if(abs(angleToSpot-angleToTarget) < bestAngle)
  2534. {
  2535. bestAngle = abs(angleToSpot-angleToTarget);
  2536. bestArg = i;
  2537. }
  2538. }
  2539. if(bestArg != -1)
  2540. {
  2541. search = -1;
  2542. actor->special1 = (int)P_FindMobjFromTID(target->args[bestArg],
  2543. &search);
  2544. }
  2545. }
  2546. else
  2547. {
  2548. do
  2549. {
  2550. i = (P_Random()>>2)%5;
  2551. } while(!target->args[i]);
  2552. search = -1;
  2553. actor->special1 = (int)P_FindMobjFromTID(target->args[i], &search);
  2554. }
  2555. }
  2556. }
  2557. //============================================================================
  2558. //
  2559. // A_DragonInitFlight
  2560. //
  2561. //============================================================================
  2562. void A_DragonInitFlight(mobj_t *actor)
  2563. {
  2564. int search;
  2565. search = -1;
  2566. do
  2567. { // find the first tid identical to the dragon's tid
  2568. actor->special1 = (int)P_FindMobjFromTID(actor->tid, &search);
  2569. if(search == -1)
  2570. {
  2571. P_SetMobjState(actor, actor->info->spawnstate);
  2572. return;
  2573. }
  2574. } while(actor->special1 == (int)actor);
  2575. P_RemoveMobjFromTIDList(actor);
  2576. }
  2577. //============================================================================
  2578. //
  2579. // A_DragonFlight
  2580. //
  2581. //============================================================================
  2582. void A_DragonFlight(mobj_t *actor)
  2583. {
  2584. angle_t angle;
  2585. DragonSeek(actor, 4*ANGLE_1, 8*ANGLE_1);
  2586. if(actor->target)
  2587. {
  2588. if(!(actor->target->flags&MF_SHOOTABLE))
  2589. { // target died
  2590. actor->target = NULL;
  2591. return;
  2592. }
  2593. angle = R_PointToAngle2(actor->x, actor->y, actor->target->x,
  2594. actor->target->y);
  2595. if(abs(actor->angle-angle) < ANGLE_45/2 && P_CheckMeleeRange(actor))
  2596. {
  2597. P_DamageMobj(actor->target, actor, actor, HITDICE(8));
  2598. S_StartSound(actor, SFX_DRAGON_ATTACK);
  2599. }
  2600. else if(abs(actor->angle-angle) <= ANGLE_1*20)
  2601. {
  2602. P_SetMobjState(actor, actor->info->missilestate);
  2603. S_StartSound(actor, SFX_DRAGON_ATTACK);
  2604. }
  2605. }
  2606. else
  2607. {
  2608. P_LookForPlayers(actor, true);
  2609. }
  2610. }
  2611. //============================================================================
  2612. //
  2613. // A_DragonFlap
  2614. //
  2615. //============================================================================
  2616. void A_DragonFlap(mobj_t *actor)
  2617. {
  2618. A_DragonFlight(actor);
  2619. if(P_Random() < 240)
  2620. {
  2621. S_StartSound(actor, SFX_DRAGON_WINGFLAP);
  2622. }
  2623. else
  2624. {
  2625. S_StartSound(actor, actor->info->activesound);
  2626. }
  2627. }
  2628. //============================================================================
  2629. //
  2630. // A_DragonAttack
  2631. //
  2632. //============================================================================
  2633. void A_DragonAttack(mobj_t *actor)
  2634. {
  2635. mobj_t *mo;
  2636. mo = P_SpawnMissile(actor, actor->target, MT_DRAGON_FX);
  2637. }
  2638. //============================================================================
  2639. //
  2640. // A_DragonFX2
  2641. //
  2642. //============================================================================
  2643. void A_DragonFX2(mobj_t *actor)
  2644. {
  2645. mobj_t *mo;
  2646. int i;
  2647. int delay;
  2648. delay = 16+(P_Random()>>3);
  2649. for(i = 1+(P_Random()&3); i; i--)
  2650. {
  2651. mo = P_SpawnMobj(actor->x+((P_Random()-128)<<14),
  2652. actor->y+((P_Random()-128)<<14), actor->z+((P_Random()-128)<<12),
  2653. MT_DRAGON_FX2);
  2654. if(mo)
  2655. {
  2656. mo->tics = delay+(P_Random()&3)*i*2;
  2657. mo->target = actor->target;
  2658. }
  2659. }
  2660. }
  2661. //============================================================================
  2662. //
  2663. // A_DragonPain
  2664. //
  2665. //============================================================================
  2666. void A_DragonPain(mobj_t *actor)
  2667. {
  2668. A_Pain(actor);
  2669. if(!actor->special1)
  2670. { // no destination spot yet
  2671. P_SetMobjState(actor, S_DRAGON_INIT);
  2672. }
  2673. }
  2674. //============================================================================
  2675. //
  2676. // A_DragonCheckCrash
  2677. //
  2678. //============================================================================
  2679. void A_DragonCheckCrash(mobj_t *actor)
  2680. {
  2681. if(actor->z <= actor->floorz)
  2682. {
  2683. P_SetMobjState(actor, S_DRAGON_CRASH1);
  2684. }
  2685. }
  2686. //============================================================================
  2687. // Demon AI
  2688. //============================================================================
  2689. //
  2690. // A_DemonAttack1 (melee)
  2691. //
  2692. void A_DemonAttack1(mobj_t *actor)
  2693. {
  2694. if(P_CheckMeleeRange(actor))
  2695. {
  2696. P_DamageMobj(actor->target, actor, actor, HITDICE(2));
  2697. }
  2698. }
  2699. //
  2700. // A_DemonAttack2 (missile)
  2701. //
  2702. void A_DemonAttack2(mobj_t *actor)
  2703. {
  2704. mobj_t *mo;
  2705. int fireBall;
  2706. if(actor->type == MT_DEMON)
  2707. {
  2708. fireBall = MT_DEMONFX1;
  2709. }
  2710. else
  2711. {
  2712. fireBall = MT_DEMON2FX1;
  2713. }
  2714. mo = P_SpawnMissile(actor, actor->target, fireBall);
  2715. if (mo)
  2716. {
  2717. mo->z += 30*FRACUNIT;
  2718. S_StartSound(actor, SFX_DEMON_MISSILE_FIRE);
  2719. }
  2720. }
  2721. //
  2722. // A_DemonDeath
  2723. //
  2724. void A_DemonDeath(mobj_t *actor)
  2725. {
  2726. mobj_t *mo;
  2727. angle_t angle;
  2728. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2729. MT_DEMONCHUNK1);
  2730. if(mo)
  2731. {
  2732. angle = actor->angle+ANG90;
  2733. mo->momz = 8*FRACUNIT;
  2734. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2735. finecosine[angle>>ANGLETOFINESHIFT]);
  2736. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2737. finesine[angle>>ANGLETOFINESHIFT]);
  2738. mo->target = actor;
  2739. }
  2740. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2741. MT_DEMONCHUNK2);
  2742. if(mo)
  2743. {
  2744. angle = actor->angle-ANG90;
  2745. mo->momz = 8*FRACUNIT;
  2746. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2747. finecosine[angle>>ANGLETOFINESHIFT]);
  2748. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2749. finesine[angle>>ANGLETOFINESHIFT]);
  2750. mo->target = actor;
  2751. }
  2752. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2753. MT_DEMONCHUNK3);
  2754. if(mo)
  2755. {
  2756. angle = actor->angle-ANG90;
  2757. mo->momz = 8*FRACUNIT;
  2758. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2759. finecosine[angle>>ANGLETOFINESHIFT]);
  2760. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2761. finesine[angle>>ANGLETOFINESHIFT]);
  2762. mo->target = actor;
  2763. }
  2764. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2765. MT_DEMONCHUNK4);
  2766. if(mo)
  2767. {
  2768. angle = actor->angle-ANG90;
  2769. mo->momz = 8*FRACUNIT;
  2770. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2771. finecosine[angle>>ANGLETOFINESHIFT]);
  2772. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2773. finesine[angle>>ANGLETOFINESHIFT]);
  2774. mo->target = actor;
  2775. }
  2776. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2777. MT_DEMONCHUNK5);
  2778. if(mo)
  2779. {
  2780. angle = actor->angle-ANG90;
  2781. mo->momz = 8*FRACUNIT;
  2782. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2783. finecosine[angle>>ANGLETOFINESHIFT]);
  2784. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2785. finesine[angle>>ANGLETOFINESHIFT]);
  2786. mo->target = actor;
  2787. }
  2788. }
  2789. //===========================================================================
  2790. //
  2791. // A_Demon2Death
  2792. //
  2793. //===========================================================================
  2794. void A_Demon2Death(mobj_t *actor)
  2795. {
  2796. mobj_t *mo;
  2797. angle_t angle;
  2798. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2799. MT_DEMON2CHUNK1);
  2800. if(mo)
  2801. {
  2802. angle = actor->angle+ANG90;
  2803. mo->momz = 8*FRACUNIT;
  2804. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2805. finecosine[angle>>ANGLETOFINESHIFT]);
  2806. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2807. finesine[angle>>ANGLETOFINESHIFT]);
  2808. mo->target = actor;
  2809. }
  2810. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2811. MT_DEMON2CHUNK2);
  2812. if(mo)
  2813. {
  2814. angle = actor->angle-ANG90;
  2815. mo->momz = 8*FRACUNIT;
  2816. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2817. finecosine[angle>>ANGLETOFINESHIFT]);
  2818. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2819. finesine[angle>>ANGLETOFINESHIFT]);
  2820. mo->target = actor;
  2821. }
  2822. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2823. MT_DEMON2CHUNK3);
  2824. if(mo)
  2825. {
  2826. angle = actor->angle-ANG90;
  2827. mo->momz = 8*FRACUNIT;
  2828. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2829. finecosine[angle>>ANGLETOFINESHIFT]);
  2830. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2831. finesine[angle>>ANGLETOFINESHIFT]);
  2832. mo->target = actor;
  2833. }
  2834. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2835. MT_DEMON2CHUNK4);
  2836. if(mo)
  2837. {
  2838. angle = actor->angle-ANG90;
  2839. mo->momz = 8*FRACUNIT;
  2840. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2841. finecosine[angle>>ANGLETOFINESHIFT]);
  2842. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2843. finesine[angle>>ANGLETOFINESHIFT]);
  2844. mo->target = actor;
  2845. }
  2846. mo = P_SpawnMobj(actor->x, actor->y, actor->z+45*FRACUNIT,
  2847. MT_DEMON2CHUNK5);
  2848. if(mo)
  2849. {
  2850. angle = actor->angle-ANG90;
  2851. mo->momz = 8*FRACUNIT;
  2852. mo->momx = FixedMul((P_Random()<<10)+FRACUNIT,
  2853. finecosine[angle>>ANGLETOFINESHIFT]);
  2854. mo->momy = FixedMul((P_Random()<<10)+FRACUNIT,
  2855. finesine[angle>>ANGLETOFINESHIFT]);
  2856. mo->target = actor;
  2857. }
  2858. }
  2859. //
  2860. // A_SinkMobj
  2861. // Sink a mobj incrementally into the floor
  2862. //
  2863. boolean A_SinkMobj(mobj_t *actor)
  2864. {
  2865. if (actor->floorclip < actor->info->height)
  2866. {
  2867. switch(actor->type)
  2868. {
  2869. case MT_THRUSTFLOOR_DOWN:
  2870. case MT_THRUSTFLOOR_UP:
  2871. actor->floorclip += 6*FRACUNIT;
  2872. break;
  2873. default:
  2874. actor->floorclip += FRACUNIT;
  2875. break;
  2876. }
  2877. return false;
  2878. }
  2879. return true;
  2880. }
  2881. //
  2882. // A_RaiseMobj
  2883. // Raise a mobj incrementally from the floor to
  2884. //
  2885. boolean A_RaiseMobj(mobj_t *actor)
  2886. {
  2887. int done = true;
  2888. // Raise a mobj from the ground
  2889. if (actor->floorclip > 0)
  2890. {
  2891. switch(actor->type)
  2892. {
  2893. case MT_WRAITHB:
  2894. actor->floorclip -= 2*FRACUNIT;
  2895. break;
  2896. case MT_THRUSTFLOOR_DOWN:
  2897. case MT_THRUSTFLOOR_UP:
  2898. actor->floorclip -= actor->special2*FRACUNIT;
  2899. break;
  2900. default:
  2901. actor->floorclip -= 2*FRACUNIT;
  2902. break;
  2903. }
  2904. if (actor->floorclip <= 0)
  2905. {
  2906. actor->floorclip = 0;
  2907. done=true;
  2908. }
  2909. else
  2910. {
  2911. done = false;
  2912. }
  2913. }
  2914. return done; // Reached target height
  2915. }
  2916. //============================================================================
  2917. // Wraith Variables
  2918. //
  2919. // special1 Internal index into floatbob
  2920. // special2
  2921. //============================================================================
  2922. //
  2923. // A_WraithInit
  2924. //
  2925. void A_WraithInit(mobj_t *actor)
  2926. {
  2927. actor->z += 48<<FRACBITS;
  2928. actor->special1 = 0; // index into floatbob
  2929. }
  2930. void A_WraithRaiseInit(mobj_t *actor)
  2931. {
  2932. actor->flags2 &= ~MF2_DONTDRAW;
  2933. actor->flags2 &= ~MF2_NONSHOOTABLE;
  2934. actor->flags |= MF_SHOOTABLE|MF_SOLID;
  2935. actor->floorclip = actor->info->height;
  2936. }
  2937. void A_WraithRaise(mobj_t *actor)
  2938. {
  2939. if (A_RaiseMobj(actor))
  2940. {
  2941. // Reached it's target height
  2942. P_SetMobjState(actor,S_WRAITH_CHASE1);
  2943. }
  2944. P_SpawnDirt(actor, actor->radius);
  2945. }
  2946. void A_WraithMelee(mobj_t *actor)
  2947. {
  2948. int amount;
  2949. // Steal health from target and give to player
  2950. if(P_CheckMeleeRange(actor) && (P_Random()<220))
  2951. {
  2952. amount = HITDICE(2);
  2953. P_DamageMobj(actor->target, actor, actor, amount);
  2954. actor->health += amount;
  2955. }
  2956. }
  2957. void A_WraithMissile(mobj_t *actor)
  2958. {
  2959. mobj_t *mo;
  2960. mo = P_SpawnMissile(actor, actor->target, MT_WRAITHFX1);
  2961. if (mo)
  2962. {
  2963. S_StartSound(actor, SFX_WRAITH_MISSILE_FIRE);
  2964. }
  2965. }
  2966. //
  2967. // A_WraithFX2 - spawns sparkle tail of missile
  2968. //
  2969. void A_WraithFX2(mobj_t *actor)
  2970. {
  2971. mobj_t *mo;
  2972. angle_t angle;
  2973. int i;
  2974. for (i=0; i<2; i++)
  2975. {
  2976. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_WRAITHFX2);
  2977. if(mo)
  2978. {
  2979. if (P_Random()<128)
  2980. {
  2981. angle = actor->angle+(P_Random()<<22);
  2982. }
  2983. else
  2984. {
  2985. angle = actor->angle-(P_Random()<<22);
  2986. }
  2987. mo->momz = 0;
  2988. mo->momx = FixedMul((P_Random()<<7)+FRACUNIT,
  2989. finecosine[angle>>ANGLETOFINESHIFT]);
  2990. mo->momy = FixedMul((P_Random()<<7)+FRACUNIT,
  2991. finesine[angle>>ANGLETOFINESHIFT]);
  2992. mo->target = actor;
  2993. mo->floorclip = 10*FRACUNIT;
  2994. }
  2995. }
  2996. }
  2997. // Spawn an FX3 around the actor during attacks
  2998. void A_WraithFX3(mobj_t *actor)
  2999. {
  3000. mobj_t *mo;
  3001. int numdropped=P_Random()%15;
  3002. int i;
  3003. for (i=0; i<numdropped; i++)
  3004. {
  3005. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_WRAITHFX3);
  3006. if(mo)
  3007. {
  3008. mo->x += (P_Random()-128)<<11;
  3009. mo->y += (P_Random()-128)<<11;
  3010. mo->z += (P_Random()<<10);
  3011. mo->target = actor;
  3012. }
  3013. }
  3014. }
  3015. // Spawn an FX4 during movement
  3016. void A_WraithFX4(mobj_t *actor)
  3017. {
  3018. mobj_t *mo;
  3019. int chance = P_Random();
  3020. int spawn4,spawn5;
  3021. if (chance < 10)
  3022. {
  3023. spawn4 = true;
  3024. spawn5 = false;
  3025. }
  3026. else if (chance < 20)
  3027. {
  3028. spawn4 = false;
  3029. spawn5 = true;
  3030. }
  3031. else if (chance < 25)
  3032. {
  3033. spawn4 = true;
  3034. spawn5 = true;
  3035. }
  3036. else
  3037. {
  3038. spawn4 = false;
  3039. spawn5 = false;
  3040. }
  3041. if (spawn4)
  3042. {
  3043. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_WRAITHFX4);
  3044. if(mo)
  3045. {
  3046. mo->x += (P_Random()-128)<<12;
  3047. mo->y += (P_Random()-128)<<12;
  3048. mo->z += (P_Random()<<10);
  3049. mo->target = actor;
  3050. }
  3051. }
  3052. if (spawn5)
  3053. {
  3054. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_WRAITHFX5);
  3055. if(mo)
  3056. {
  3057. mo->x += (P_Random()-128)<<11;
  3058. mo->y += (P_Random()-128)<<11;
  3059. mo->z += (P_Random()<<10);
  3060. mo->target = actor;
  3061. }
  3062. }
  3063. }
  3064. void A_WraithLook(mobj_t *actor)
  3065. {
  3066. // A_WraithFX4(actor); // too expensive
  3067. A_Look(actor);
  3068. }
  3069. void A_WraithChase(mobj_t *actor)
  3070. {
  3071. int weaveindex = actor->special1;
  3072. actor->z += FloatBobOffsets[weaveindex];
  3073. actor->special1 = (weaveindex+2)&63;
  3074. // if (actor->floorclip > 0)
  3075. // {
  3076. // P_SetMobjState(actor, S_WRAITH_RAISE2);
  3077. // return;
  3078. // }
  3079. A_Chase(actor);
  3080. A_WraithFX4(actor);
  3081. }
  3082. //============================================================================
  3083. // Ettin AI
  3084. //============================================================================
  3085. void A_EttinAttack(mobj_t *actor)
  3086. {
  3087. if(P_CheckMeleeRange(actor))
  3088. {
  3089. P_DamageMobj(actor->target, actor, actor, HITDICE(2));
  3090. }
  3091. }
  3092. void A_DropMace(mobj_t *actor)
  3093. {
  3094. mobj_t *mo;
  3095. mo = P_SpawnMobj(actor->x, actor->y,
  3096. actor->z+(actor->height>>1), MT_ETTIN_MACE);
  3097. if (mo)
  3098. {
  3099. mo->momx = (P_Random()-128)<<11;
  3100. mo->momy = (P_Random()-128)<<11;
  3101. mo->momz = FRACUNIT*10+(P_Random()<<10);
  3102. mo->target = actor;
  3103. }
  3104. }
  3105. //============================================================================
  3106. // Fire Demon AI
  3107. //
  3108. // special1 index into floatbob
  3109. // special2 whether strafing or not
  3110. //============================================================================
  3111. void A_FiredSpawnRock(mobj_t *actor)
  3112. {
  3113. mobj_t *mo;
  3114. int x,y,z;
  3115. int rtype;
  3116. switch(P_Random()%5)
  3117. {
  3118. case 0:
  3119. rtype = MT_FIREDEMON_FX1;
  3120. break;
  3121. case 1:
  3122. rtype = MT_FIREDEMON_FX2;
  3123. break;
  3124. case 2:
  3125. rtype = MT_FIREDEMON_FX3;
  3126. break;
  3127. case 3:
  3128. rtype = MT_FIREDEMON_FX4;
  3129. break;
  3130. case 4:
  3131. rtype = MT_FIREDEMON_FX5;
  3132. break;
  3133. }
  3134. x = actor->x + ((P_Random()-128) << 12);
  3135. y = actor->y + ((P_Random()-128) << 12);
  3136. z = actor->z + ((P_Random()) << 11);
  3137. mo = P_SpawnMobj(x,y,z,rtype);
  3138. if (mo)
  3139. {
  3140. mo->target = actor;
  3141. mo->momx = (P_Random()-128)<<10;
  3142. mo->momy = (P_Random()-128)<<10;
  3143. mo->momz = (P_Random()<<10);
  3144. mo->special1 = 2; // Number bounces
  3145. }
  3146. // Initialize fire demon
  3147. actor->special2 = 0;
  3148. actor->flags &= ~MF_JUSTATTACKED;
  3149. }
  3150. void A_FiredRocks(mobj_t *actor)
  3151. {
  3152. A_FiredSpawnRock(actor);
  3153. A_FiredSpawnRock(actor);
  3154. A_FiredSpawnRock(actor);
  3155. A_FiredSpawnRock(actor);
  3156. A_FiredSpawnRock(actor);
  3157. }
  3158. void A_FiredAttack(mobj_t *actor)
  3159. {
  3160. mobj_t *mo;
  3161. mo = P_SpawnMissile(actor, actor->target, MT_FIREDEMON_FX6);
  3162. if (mo) S_StartSound(actor, SFX_FIRED_ATTACK);
  3163. }
  3164. void A_SmBounce(mobj_t *actor)
  3165. {
  3166. // give some more momentum (x,y,&z)
  3167. actor->z = actor->floorz + FRACUNIT;
  3168. actor->momz = (2*FRACUNIT) + (P_Random()<<10);
  3169. actor->momx = P_Random()%3<<FRACBITS;
  3170. actor->momy = P_Random()%3<<FRACBITS;
  3171. }
  3172. #define FIREDEMON_ATTACK_RANGE 64*8*FRACUNIT
  3173. void A_FiredChase(mobj_t *actor)
  3174. {
  3175. int weaveindex = actor->special1;
  3176. mobj_t *target = actor->target;
  3177. angle_t ang;
  3178. fixed_t dist;
  3179. if(actor->reactiontime) actor->reactiontime--;
  3180. if(actor->threshold) actor->threshold--;
  3181. // Float up and down
  3182. actor->z += FloatBobOffsets[weaveindex];
  3183. actor->special1 = (weaveindex+2)&63;
  3184. // Insure it stays above certain height
  3185. if (actor->z < actor->floorz + (64*FRACUNIT))
  3186. {
  3187. actor->z += 2*FRACUNIT;
  3188. }
  3189. if(!actor->target || !(actor->target->flags&MF_SHOOTABLE))
  3190. { // Invalid target
  3191. P_LookForPlayers(actor,true);
  3192. return;
  3193. }
  3194. // Strafe
  3195. if (actor->special2 > 0)
  3196. {
  3197. actor->special2--;
  3198. }
  3199. else
  3200. {
  3201. actor->special2 = 0;
  3202. actor->momx = actor->momy = 0;
  3203. dist = P_AproxDistance(actor->x - target->x, actor->y - target->y);
  3204. if (dist < FIREDEMON_ATTACK_RANGE)
  3205. {
  3206. if (P_Random()<30)
  3207. {
  3208. ang = R_PointToAngle2(actor->x, actor->y, target->x, target->y);
  3209. if (P_Random()<128)
  3210. ang += ANGLE_90;
  3211. else
  3212. ang -= ANGLE_90;
  3213. ang>>=ANGLETOFINESHIFT;
  3214. actor->momx = FixedMul(8*FRACUNIT, finecosine[ang]);
  3215. actor->momy = FixedMul(8*FRACUNIT, finesine[ang]);
  3216. actor->special2 = 3; // strafe time
  3217. }
  3218. }
  3219. }
  3220. FaceMovementDirection(actor);
  3221. // Normal movement
  3222. if (!actor->special2)
  3223. {
  3224. if (--actor->movecount<0 || !P_Move (actor))
  3225. {
  3226. P_NewChaseDir (actor);
  3227. }
  3228. }
  3229. // Do missile attack
  3230. if (!(actor->flags&MF_JUSTATTACKED))
  3231. {
  3232. if (P_CheckMissileRange(actor) && (P_Random()<20))
  3233. {
  3234. P_SetMobjState (actor, actor->info->missilestate);
  3235. actor->flags |= MF_JUSTATTACKED;
  3236. return;
  3237. }
  3238. }
  3239. else
  3240. {
  3241. actor->flags &= ~MF_JUSTATTACKED;
  3242. }
  3243. // make active sound
  3244. if(actor->info->activesound && P_Random() < 3)
  3245. {
  3246. S_StartSound(actor, actor->info->activesound);
  3247. }
  3248. }
  3249. void A_FiredSplotch(mobj_t *actor)
  3250. {
  3251. mobj_t *mo;
  3252. mo = P_SpawnMobj(actor->x,actor->y,actor->z, MT_FIREDEMON_SPLOTCH1);
  3253. if (mo)
  3254. {
  3255. mo->momx = (P_Random()-128)<<11;
  3256. mo->momy = (P_Random()-128)<<11;
  3257. mo->momz = FRACUNIT*3 + (P_Random()<<10);
  3258. }
  3259. mo = P_SpawnMobj(actor->x,actor->y,actor->z, MT_FIREDEMON_SPLOTCH2);
  3260. if (mo)
  3261. {
  3262. mo->momx = (P_Random()-128)<<11;
  3263. mo->momy = (P_Random()-128)<<11;
  3264. mo->momz = FRACUNIT*3 + (P_Random()<<10);
  3265. }
  3266. }
  3267. //============================================================================
  3268. //
  3269. // A_IceGuyLook
  3270. //
  3271. //============================================================================
  3272. void A_IceGuyLook(mobj_t *actor)
  3273. {
  3274. fixed_t dist;
  3275. fixed_t an;
  3276. A_Look(actor);
  3277. if(P_Random() < 64)
  3278. {
  3279. dist = ((P_Random()-128)*actor->radius)>>7;
  3280. an = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  3281. P_SpawnMobj(actor->x+FixedMul(dist, finecosine[an]),
  3282. actor->y+FixedMul(dist, finesine[an]), actor->z+60*FRACUNIT,
  3283. MT_ICEGUY_WISP1+(P_Random()&1));
  3284. }
  3285. }
  3286. //============================================================================
  3287. //
  3288. // A_IceGuyChase
  3289. //
  3290. //============================================================================
  3291. void A_IceGuyChase(mobj_t *actor)
  3292. {
  3293. fixed_t dist;
  3294. fixed_t an;
  3295. mobj_t *mo;
  3296. A_Chase(actor);
  3297. if(P_Random() < 128)
  3298. {
  3299. dist = ((P_Random()-128)*actor->radius)>>7;
  3300. an = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  3301. mo = P_SpawnMobj(actor->x+FixedMul(dist, finecosine[an]),
  3302. actor->y+FixedMul(dist, finesine[an]), actor->z+60*FRACUNIT,
  3303. MT_ICEGUY_WISP1+(P_Random()&1));
  3304. if(mo)
  3305. {
  3306. mo->momx = actor->momx;
  3307. mo->momy = actor->momy;
  3308. mo->momz = actor->momz;
  3309. mo->target = actor;
  3310. }
  3311. }
  3312. }
  3313. //============================================================================
  3314. //
  3315. // A_IceGuyAttack
  3316. //
  3317. //============================================================================
  3318. void A_IceGuyAttack(mobj_t *actor)
  3319. {
  3320. fixed_t an;
  3321. if(!actor->target)
  3322. {
  3323. return;
  3324. }
  3325. an = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  3326. P_SpawnMissileXYZ(actor->x+FixedMul(actor->radius>>1,
  3327. finecosine[an]), actor->y+FixedMul(actor->radius>>1,
  3328. finesine[an]), actor->z+40*FRACUNIT, actor, actor->target,
  3329. MT_ICEGUY_FX);
  3330. an = (actor->angle-ANG90)>>ANGLETOFINESHIFT;
  3331. P_SpawnMissileXYZ(actor->x+FixedMul(actor->radius>>1,
  3332. finecosine[an]), actor->y+FixedMul(actor->radius>>1,
  3333. finesine[an]), actor->z+40*FRACUNIT, actor, actor->target,
  3334. MT_ICEGUY_FX);
  3335. S_StartSound(actor, actor->info->attacksound);
  3336. }
  3337. //============================================================================
  3338. //
  3339. // A_IceGuyMissilePuff
  3340. //
  3341. //============================================================================
  3342. void A_IceGuyMissilePuff(mobj_t *actor)
  3343. {
  3344. mobj_t *mo;
  3345. mo = P_SpawnMobj(actor->x, actor->y, actor->z+2*FRACUNIT, MT_ICEFX_PUFF);
  3346. }
  3347. //============================================================================
  3348. //
  3349. // A_IceGuyDie
  3350. //
  3351. //============================================================================
  3352. void A_IceGuyDie(mobj_t *actor)
  3353. {
  3354. void A_FreezeDeathChunks(mobj_t *actor);
  3355. actor->momx = 0;
  3356. actor->momy = 0;
  3357. actor->momz = 0;
  3358. actor->height <<= 2;
  3359. A_FreezeDeathChunks(actor);
  3360. }
  3361. //============================================================================
  3362. //
  3363. // A_IceGuyMissileExplode
  3364. //
  3365. //============================================================================
  3366. void A_IceGuyMissileExplode(mobj_t *actor)
  3367. {
  3368. mobj_t *mo;
  3369. int i;
  3370. for(i = 0; i < 8; i++)
  3371. {
  3372. mo = P_SpawnMissileAngle(actor, MT_ICEGUY_FX2, i*ANG45, -0.3*FRACUNIT);
  3373. if(mo)
  3374. {
  3375. mo->target = actor->target;
  3376. }
  3377. }
  3378. }
  3379. //============================================================================
  3380. //
  3381. // Sorcerer stuff
  3382. //
  3383. // Sorcerer Variables
  3384. // special1 Angle of ball 1 (all others relative to that)
  3385. // special2 which ball to stop at in stop mode (MT_???)
  3386. // args[0] Denfense time
  3387. // args[1] Number of full rotations since stopping mode
  3388. // args[2] Target orbit speed for acceleration/deceleration
  3389. // args[3] Movement mode (see SORC_ macros)
  3390. // args[4] Current ball orbit speed
  3391. // Sorcerer Ball Variables
  3392. // special1 Previous angle of ball (for woosh)
  3393. // special2 Countdown of rapid fire (FX4)
  3394. // args[0] If set, don't play the bounce sound when bouncing
  3395. //============================================================================
  3396. #define SORCBALL_INITIAL_SPEED 7
  3397. #define SORCBALL_TERMINAL_SPEED 25
  3398. #define SORCBALL_SPEED_ROTATIONS 5
  3399. #define SORC_DEFENSE_TIME 255
  3400. #define SORC_DEFENSE_HEIGHT 45
  3401. #define BOUNCE_TIME_UNIT (35/2)
  3402. #define SORCFX4_RAPIDFIRE_TIME (6*3) // 3 seconds
  3403. #define SORCFX4_SPREAD_ANGLE 20
  3404. #define SORC_DECELERATE 0
  3405. #define SORC_ACCELERATE 1
  3406. #define SORC_STOPPING 2
  3407. #define SORC_FIRESPELL 3
  3408. #define SORC_STOPPED 4
  3409. #define SORC_NORMAL 5
  3410. #define SORC_FIRING_SPELL 6
  3411. #define BALL1_ANGLEOFFSET 0
  3412. #define BALL2_ANGLEOFFSET (ANGLE_MAX/3)
  3413. #define BALL3_ANGLEOFFSET ((ANGLE_MAX/3)*2)
  3414. void A_SorcBallOrbit(mobj_t *actor);
  3415. void A_SorcSpinBalls(mobj_t *actor);
  3416. void A_SpeedBalls(mobj_t *actor);
  3417. void A_SlowBalls(mobj_t *actor);
  3418. void A_StopBalls(mobj_t *actor);
  3419. void A_AccelBalls(mobj_t *actor);
  3420. void A_DecelBalls(mobj_t *actor);
  3421. void A_SorcBossAttack(mobj_t *actor);
  3422. void A_SpawnFizzle(mobj_t *actor);
  3423. void A_CastSorcererSpell(mobj_t *actor);
  3424. void A_SorcUpdateBallAngle(mobj_t *actor);
  3425. void A_BounceCheck(mobj_t *actor);
  3426. void A_SorcFX1Seek(mobj_t *actor);
  3427. void A_SorcOffense1(mobj_t *actor);
  3428. void A_SorcOffense2(mobj_t *actor);
  3429. // Spawn spinning balls above head - actor is sorcerer
  3430. void A_SorcSpinBalls(mobj_t *actor)
  3431. {
  3432. mobj_t *mo;
  3433. fixed_t z;
  3434. A_SlowBalls(actor);
  3435. actor->args[0] = 0; // Currently no defense
  3436. actor->args[3] = SORC_NORMAL;
  3437. actor->args[4] = SORCBALL_INITIAL_SPEED; // Initial orbit speed
  3438. actor->special1 = ANGLE_1;
  3439. z = actor->z - actor->floorclip + actor->info->height;
  3440. mo = P_SpawnMobj(actor->x, actor->y, z, MT_SORCBALL1);
  3441. if (mo)
  3442. {
  3443. mo->target = actor;
  3444. mo->special2 = SORCFX4_RAPIDFIRE_TIME;
  3445. }
  3446. mo = P_SpawnMobj(actor->x, actor->y, z, MT_SORCBALL2);
  3447. if (mo) mo->target = actor;
  3448. mo = P_SpawnMobj(actor->x, actor->y, z, MT_SORCBALL3);
  3449. if (mo) mo->target = actor;
  3450. }
  3451. //
  3452. // A_SorcBallOrbit() ==========================================
  3453. //
  3454. void A_SorcBallOrbit(mobj_t *actor)
  3455. {
  3456. int x,y;
  3457. angle_t angle, baseangle;
  3458. int mode = actor->target->args[3];
  3459. mobj_t *parent = (mobj_t *)actor->target;
  3460. int dist = parent->radius - (actor->radius<<1);
  3461. angle_t prevangle = actor->special1;
  3462. if (actor->target->health <= 0)
  3463. P_SetMobjState(actor, actor->info->painstate);
  3464. baseangle = (angle_t)parent->special1;
  3465. switch(actor->type)
  3466. {
  3467. case MT_SORCBALL1:
  3468. angle = baseangle + BALL1_ANGLEOFFSET;
  3469. break;
  3470. case MT_SORCBALL2:
  3471. angle = baseangle + BALL2_ANGLEOFFSET;
  3472. break;
  3473. case MT_SORCBALL3:
  3474. angle = baseangle + BALL3_ANGLEOFFSET;
  3475. break;
  3476. default:
  3477. I_Error("corrupted sorcerer");
  3478. break;
  3479. }
  3480. actor->angle = angle;
  3481. angle >>= ANGLETOFINESHIFT;
  3482. switch(mode)
  3483. {
  3484. case SORC_NORMAL: // Balls rotating normally
  3485. A_SorcUpdateBallAngle(actor);
  3486. break;
  3487. case SORC_DECELERATE: // Balls decelerating
  3488. A_DecelBalls(actor);
  3489. A_SorcUpdateBallAngle(actor);
  3490. break;
  3491. case SORC_ACCELERATE: // Balls accelerating
  3492. A_AccelBalls(actor);
  3493. A_SorcUpdateBallAngle(actor);
  3494. break;
  3495. case SORC_STOPPING: // Balls stopping
  3496. if ((parent->special2 == actor->type) &&
  3497. (parent->args[1] > SORCBALL_SPEED_ROTATIONS) &&
  3498. (abs(angle - (parent->angle>>ANGLETOFINESHIFT)) < (30<<5)))
  3499. {
  3500. // Can stop now
  3501. actor->target->args[3] = SORC_FIRESPELL;
  3502. actor->target->args[4] = 0;
  3503. // Set angle so ball angle == sorcerer angle
  3504. switch(actor->type)
  3505. {
  3506. case MT_SORCBALL1:
  3507. parent->special1 = (int)(parent->angle -
  3508. BALL1_ANGLEOFFSET);
  3509. break;
  3510. case MT_SORCBALL2:
  3511. parent->special1 = (int)(parent->angle -
  3512. BALL2_ANGLEOFFSET);
  3513. break;
  3514. case MT_SORCBALL3:
  3515. parent->special1 = (int)(parent->angle -
  3516. BALL3_ANGLEOFFSET);
  3517. break;
  3518. default:
  3519. break;
  3520. }
  3521. }
  3522. else
  3523. {
  3524. A_SorcUpdateBallAngle(actor);
  3525. }
  3526. break;
  3527. case SORC_FIRESPELL: // Casting spell
  3528. if (parent->special2 == actor->type)
  3529. {
  3530. // Put sorcerer into special throw spell anim
  3531. if (parent->health > 0)
  3532. P_SetMobjStateNF(parent, S_SORC_ATTACK1);
  3533. if (actor->type==MT_SORCBALL1 && P_Random()<200)
  3534. {
  3535. S_StartSound(NULL, SFX_SORCERER_SPELLCAST);
  3536. actor->special2 = SORCFX4_RAPIDFIRE_TIME;
  3537. actor->args[4] = 128;
  3538. parent->args[3] = SORC_FIRING_SPELL;
  3539. }
  3540. else
  3541. {
  3542. A_CastSorcererSpell(actor);
  3543. parent->args[3] = SORC_STOPPED;
  3544. }
  3545. }
  3546. break;
  3547. case SORC_FIRING_SPELL:
  3548. if (parent->special2 == actor->type)
  3549. {
  3550. if (actor->special2-- <= 0)
  3551. {
  3552. // Done rapid firing
  3553. parent->args[3] = SORC_STOPPED;
  3554. // Back to orbit balls
  3555. if (parent->health > 0)
  3556. P_SetMobjStateNF(parent, S_SORC_ATTACK4);
  3557. }
  3558. else
  3559. {
  3560. // Do rapid fire spell
  3561. A_SorcOffense2(actor);
  3562. }
  3563. }
  3564. break;
  3565. case SORC_STOPPED: // Balls stopped
  3566. default:
  3567. break;
  3568. }
  3569. if ((angle < prevangle) && (parent->args[4]==SORCBALL_TERMINAL_SPEED))
  3570. {
  3571. parent->args[1]++; // Bump rotation counter
  3572. // Completed full rotation - make woosh sound
  3573. S_StartSound(actor, SFX_SORCERER_BALLWOOSH);
  3574. }
  3575. actor->special1 = angle; // Set previous angle
  3576. x = parent->x + FixedMul(dist, finecosine[angle]);
  3577. y = parent->y + FixedMul(dist, finesine[angle]);
  3578. actor->x = x;
  3579. actor->y = y;
  3580. actor->z = parent->z - parent->floorclip + parent->info->height;
  3581. }
  3582. //
  3583. // Set balls to speed mode - actor is sorcerer
  3584. //
  3585. void A_SpeedBalls(mobj_t *actor)
  3586. {
  3587. actor->args[3] = SORC_ACCELERATE; // speed mode
  3588. actor->args[2] = SORCBALL_TERMINAL_SPEED; // target speed
  3589. }
  3590. //
  3591. // Set balls to slow mode - actor is sorcerer
  3592. //
  3593. void A_SlowBalls(mobj_t *actor)
  3594. {
  3595. actor->args[3] = SORC_DECELERATE; // slow mode
  3596. actor->args[2] = SORCBALL_INITIAL_SPEED; // target speed
  3597. }
  3598. //
  3599. // Instant stop when rotation gets to ball in special2
  3600. // actor is sorcerer
  3601. //
  3602. void A_StopBalls(mobj_t *actor)
  3603. {
  3604. int chance = P_Random();
  3605. actor->args[3] = SORC_STOPPING; // stopping mode
  3606. actor->args[1] = 0; // Reset rotation counter
  3607. if ((actor->args[0] <= 0) && (chance < 200))
  3608. {
  3609. actor->special2 = MT_SORCBALL2; // Blue
  3610. }
  3611. else if((actor->health < (actor->info->spawnhealth >> 1)) &&
  3612. (chance < 200))
  3613. {
  3614. actor->special2 = MT_SORCBALL3; // Green
  3615. }
  3616. else
  3617. {
  3618. actor->special2 = MT_SORCBALL1; // Yellow
  3619. }
  3620. }
  3621. //
  3622. // Increase ball orbit speed - actor is ball
  3623. //
  3624. void A_AccelBalls(mobj_t *actor)
  3625. {
  3626. mobj_t *sorc = actor->target;
  3627. if (sorc->args[4] < sorc->args[2])
  3628. {
  3629. sorc->args[4]++;
  3630. }
  3631. else
  3632. {
  3633. sorc->args[3] = SORC_NORMAL;
  3634. if (sorc->args[4] >= SORCBALL_TERMINAL_SPEED)
  3635. {
  3636. // Reached terminal velocity - stop balls
  3637. A_StopBalls(sorc);
  3638. }
  3639. }
  3640. }
  3641. // Decrease ball orbit speed - actor is ball
  3642. void A_DecelBalls(mobj_t *actor)
  3643. {
  3644. mobj_t *sorc = actor->target;
  3645. if (sorc->args[4] > sorc->args[2])
  3646. {
  3647. sorc->args[4]--;
  3648. }
  3649. else
  3650. {
  3651. sorc->args[3] = SORC_NORMAL;
  3652. }
  3653. }
  3654. // Update angle if first ball - actor is ball
  3655. void A_SorcUpdateBallAngle(mobj_t *actor)
  3656. {
  3657. if (actor->type == MT_SORCBALL1)
  3658. {
  3659. actor->target->special1 += ANGLE_1*actor->target->args[4];
  3660. }
  3661. }
  3662. // actor is ball
  3663. void A_CastSorcererSpell(mobj_t *actor)
  3664. {
  3665. mobj_t *mo;
  3666. int spell = actor->type;
  3667. angle_t ang1,ang2;
  3668. fixed_t z;
  3669. mobj_t *parent = actor->target;
  3670. S_StartSound(NULL, SFX_SORCERER_SPELLCAST);
  3671. // Put sorcerer into throw spell animation
  3672. if (parent->health > 0) P_SetMobjStateNF(parent, S_SORC_ATTACK4);
  3673. switch(spell)
  3674. {
  3675. case MT_SORCBALL1: // Offensive
  3676. A_SorcOffense1(actor);
  3677. break;
  3678. case MT_SORCBALL2: // Defensive
  3679. z = parent->z - parent->floorclip +
  3680. SORC_DEFENSE_HEIGHT*FRACUNIT;
  3681. mo = P_SpawnMobj(actor->x, actor->y, z, MT_SORCFX2);
  3682. parent->flags2 |= MF2_REFLECTIVE|MF2_INVULNERABLE;
  3683. parent->args[0] = SORC_DEFENSE_TIME;
  3684. if (mo) mo->target = parent;
  3685. break;
  3686. case MT_SORCBALL3: // Reinforcements
  3687. ang1 = actor->angle - ANGLE_45;
  3688. ang2 = actor->angle + ANGLE_45;
  3689. if(actor->health < (actor->info->spawnhealth/3))
  3690. { // Spawn 2 at a time
  3691. mo = P_SpawnMissileAngle(parent, MT_SORCFX3, ang1, 4*FRACUNIT);
  3692. if (mo) mo->target = parent;
  3693. mo = P_SpawnMissileAngle(parent, MT_SORCFX3, ang2, 4*FRACUNIT);
  3694. if (mo) mo->target = parent;
  3695. }
  3696. else
  3697. {
  3698. if (P_Random() < 128)
  3699. ang1 = ang2;
  3700. mo = P_SpawnMissileAngle(parent, MT_SORCFX3, ang1, 4*FRACUNIT);
  3701. if (mo) mo->target = parent;
  3702. }
  3703. break;
  3704. default:
  3705. break;
  3706. }
  3707. }
  3708. /*
  3709. void A_SpawnReinforcements(mobj_t *actor)
  3710. {
  3711. mobj_t *parent = actor->target;
  3712. mobj_t *mo;
  3713. angle_t ang;
  3714. ang = ANGLE_1 * P_Random();
  3715. mo = P_SpawnMissileAngle(actor, MT_SORCFX3, ang, 5*FRACUNIT);
  3716. if (mo) mo->target = parent;
  3717. }
  3718. */
  3719. // actor is ball
  3720. void A_SorcOffense1(mobj_t *actor)
  3721. {
  3722. mobj_t *mo;
  3723. angle_t ang1,ang2;
  3724. mobj_t *parent=(mobj_t *)actor->target;
  3725. ang1 = actor->angle + ANGLE_1*70;
  3726. ang2 = actor->angle - ANGLE_1*70;
  3727. mo = P_SpawnMissileAngle(parent, MT_SORCFX1, ang1, 0);
  3728. if (mo)
  3729. {
  3730. mo->target = parent;
  3731. mo->special1 = (int)parent->target;
  3732. mo->args[4] = BOUNCE_TIME_UNIT;
  3733. mo->args[3] = 15; // Bounce time in seconds
  3734. }
  3735. mo = P_SpawnMissileAngle(parent, MT_SORCFX1, ang2, 0);
  3736. if (mo)
  3737. {
  3738. mo->target = parent;
  3739. mo->special1 = (int)parent->target;
  3740. mo->args[4] = BOUNCE_TIME_UNIT;
  3741. mo->args[3] = 15; // Bounce time in seconds
  3742. }
  3743. }
  3744. // Actor is ball
  3745. void A_SorcOffense2(mobj_t *actor)
  3746. {
  3747. angle_t ang1;
  3748. mobj_t *mo;
  3749. int delta, index;
  3750. mobj_t *parent = actor->target;
  3751. mobj_t *dest = parent->target;
  3752. int dist;
  3753. index = actor->args[4] << 5;
  3754. actor->args[4] += 15;
  3755. delta = (finesine[index])*SORCFX4_SPREAD_ANGLE;
  3756. delta = (delta>>FRACBITS)*ANGLE_1;
  3757. ang1 = actor->angle + delta;
  3758. mo = P_SpawnMissileAngle(parent, MT_SORCFX4, ang1, 0);
  3759. if (mo)
  3760. {
  3761. mo->special2 = 35*5/2; // 5 seconds
  3762. dist = P_AproxDistance(dest->x - mo->x, dest->y - mo->y);
  3763. dist = dist/mo->info->speed;
  3764. if(dist < 1) dist = 1;
  3765. mo->momz = (dest->z-mo->z)/dist;
  3766. }
  3767. }
  3768. // Resume ball spinning
  3769. void A_SorcBossAttack(mobj_t *actor)
  3770. {
  3771. actor->args[3] = SORC_ACCELERATE;
  3772. actor->args[2] = SORCBALL_INITIAL_SPEED;
  3773. }
  3774. // spell cast magic fizzle
  3775. void A_SpawnFizzle(mobj_t *actor)
  3776. {
  3777. fixed_t x,y,z;
  3778. fixed_t dist = 5*FRACUNIT;
  3779. angle_t angle = actor->angle >> ANGLETOFINESHIFT;
  3780. fixed_t speed = actor->info->speed;
  3781. angle_t rangle;
  3782. mobj_t *mo;
  3783. int ix;
  3784. x = actor->x + FixedMul(dist,finecosine[angle]);
  3785. y = actor->y + FixedMul(dist,finesine[angle]);
  3786. z = actor->z - actor->floorclip + (actor->height>>1);
  3787. for (ix=0; ix<5; ix++)
  3788. {
  3789. mo = P_SpawnMobj(x,y,z,MT_SORCSPARK1);
  3790. if (mo)
  3791. {
  3792. rangle = angle + ((P_Random()%5) << 1);
  3793. mo->momx = FixedMul(P_Random()%speed,finecosine[rangle]);
  3794. mo->momy = FixedMul(P_Random()%speed,finesine[rangle]);
  3795. mo->momz = FRACUNIT*2;
  3796. }
  3797. }
  3798. }
  3799. //============================================================================
  3800. // Yellow spell - offense
  3801. //============================================================================
  3802. void A_SorcFX1Seek(mobj_t *actor)
  3803. {
  3804. A_BounceCheck(actor);
  3805. P_SeekerMissile(actor,ANGLE_1*2,ANGLE_1*6);
  3806. }
  3807. //============================================================================
  3808. // Blue spell - defense
  3809. //============================================================================
  3810. //
  3811. // FX2 Variables
  3812. // special1 current angle
  3813. // special2
  3814. // args[0] 0 = CW, 1 = CCW
  3815. // args[1]
  3816. //============================================================================
  3817. // Split ball in two
  3818. void A_SorcFX2Split(mobj_t *actor)
  3819. {
  3820. mobj_t *mo;
  3821. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_SORCFX2);
  3822. if (mo)
  3823. {
  3824. mo->target = actor->target;
  3825. mo->args[0] = 0; // CW
  3826. mo->special1 = actor->angle; // Set angle
  3827. P_SetMobjStateNF(mo, S_SORCFX2_ORBIT1);
  3828. }
  3829. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_SORCFX2);
  3830. if (mo)
  3831. {
  3832. mo->target = actor->target;
  3833. mo->args[0] = 1; // CCW
  3834. mo->special1 = actor->angle; // Set angle
  3835. P_SetMobjStateNF(mo, S_SORCFX2_ORBIT1);
  3836. }
  3837. P_SetMobjStateNF(actor, S_NULL);
  3838. }
  3839. // Orbit FX2 about sorcerer
  3840. void A_SorcFX2Orbit(mobj_t *actor)
  3841. {
  3842. angle_t angle;
  3843. fixed_t x,y,z;
  3844. mobj_t *parent = actor->target;
  3845. fixed_t dist = parent->info->radius;
  3846. if ((parent->health <= 0) || // Sorcerer is dead
  3847. (!parent->args[0])) // Time expired
  3848. {
  3849. P_SetMobjStateNF(actor, actor->info->deathstate);
  3850. parent->args[0] = 0;
  3851. parent->flags2 &= ~MF2_REFLECTIVE;
  3852. parent->flags2 &= ~MF2_INVULNERABLE;
  3853. }
  3854. if (actor->args[0] && (parent->args[0]-- <= 0)) // Time expired
  3855. {
  3856. P_SetMobjStateNF(actor, actor->info->deathstate);
  3857. parent->args[0] = 0;
  3858. parent->flags2 &= ~MF2_REFLECTIVE;
  3859. }
  3860. // Move to new position based on angle
  3861. if (actor->args[0]) // Counter clock-wise
  3862. {
  3863. actor->special1 += ANGLE_1*10;
  3864. angle = ((angle_t)actor->special1) >> ANGLETOFINESHIFT;
  3865. x = parent->x + FixedMul(dist, finecosine[angle]);
  3866. y = parent->y + FixedMul(dist, finesine[angle]);
  3867. z = parent->z - parent->floorclip + SORC_DEFENSE_HEIGHT*FRACUNIT;
  3868. z += FixedMul(15*FRACUNIT,finecosine[angle]);
  3869. // Spawn trailer
  3870. P_SpawnMobj(x,y,z, MT_SORCFX2_T1);
  3871. }
  3872. else // Clock wise
  3873. {
  3874. actor->special1 -= ANGLE_1*10;
  3875. angle = ((angle_t)actor->special1) >> ANGLETOFINESHIFT;
  3876. x = parent->x + FixedMul(dist, finecosine[angle]);
  3877. y = parent->y + FixedMul(dist, finesine[angle]);
  3878. z = parent->z - parent->floorclip + SORC_DEFENSE_HEIGHT*FRACUNIT;
  3879. z += FixedMul(20*FRACUNIT,finesine[angle]);
  3880. // Spawn trailer
  3881. P_SpawnMobj(x,y,z, MT_SORCFX2_T1);
  3882. }
  3883. actor->x = x;
  3884. actor->y = y;
  3885. actor->z = z;
  3886. }
  3887. //============================================================================
  3888. // Green spell - spawn bishops
  3889. //============================================================================
  3890. void A_SpawnBishop(mobj_t *actor)
  3891. {
  3892. mobj_t *mo;
  3893. mo=P_SpawnMobj(actor->x, actor->y, actor->z, MT_BISHOP);
  3894. if(mo)
  3895. {
  3896. if(!P_TestMobjLocation(mo))
  3897. {
  3898. P_SetMobjState(mo, S_NULL);
  3899. }
  3900. }
  3901. P_SetMobjState(actor, S_NULL);
  3902. }
  3903. /*
  3904. void A_SmokePuffEntry(mobj_t *actor)
  3905. {
  3906. P_SpawnMobj(actor->x, actor->y, actor->z, MT_MNTRSMOKE);
  3907. }
  3908. */
  3909. void A_SmokePuffExit(mobj_t *actor)
  3910. {
  3911. P_SpawnMobj(actor->x, actor->y, actor->z, MT_MNTRSMOKEEXIT);
  3912. }
  3913. void A_SorcererBishopEntry(mobj_t *actor)
  3914. {
  3915. P_SpawnMobj(actor->x, actor->y, actor->z, MT_SORCFX3_EXPLOSION);
  3916. S_StartSound(actor, actor->info->seesound);
  3917. }
  3918. //============================================================================
  3919. // FX4 - rapid fire balls
  3920. //============================================================================
  3921. void A_SorcFX4Check(mobj_t *actor)
  3922. {
  3923. if (actor->special2-- <= 0)
  3924. {
  3925. P_SetMobjStateNF(actor, actor->info->deathstate);
  3926. }
  3927. }
  3928. //============================================================================
  3929. // Ball death - spawn stuff
  3930. //============================================================================
  3931. void A_SorcBallPop(mobj_t *actor)
  3932. {
  3933. S_StartSound(NULL, SFX_SORCERER_BALLPOP);
  3934. actor->flags &= ~MF_NOGRAVITY;
  3935. actor->flags2 |= MF2_LOGRAV;
  3936. actor->momx = ((P_Random()%10)-5) << FRACBITS;
  3937. actor->momy = ((P_Random()%10)-5) << FRACBITS;
  3938. actor->momz = (2+(P_Random()%3)) << FRACBITS;
  3939. actor->special2 = 4*FRACUNIT; // Initial bounce factor
  3940. actor->args[4] = BOUNCE_TIME_UNIT; // Bounce time unit
  3941. actor->args[3] = 5; // Bounce time in seconds
  3942. }
  3943. void A_BounceCheck(mobj_t *actor)
  3944. {
  3945. if (actor->args[4]-- <= 0)
  3946. {
  3947. if (actor->args[3]-- <= 0)
  3948. {
  3949. P_SetMobjState(actor, actor->info->deathstate);
  3950. switch(actor->type)
  3951. {
  3952. case MT_SORCBALL1:
  3953. case MT_SORCBALL2:
  3954. case MT_SORCBALL3:
  3955. S_StartSound(NULL, SFX_SORCERER_BIGBALLEXPLODE);
  3956. break;
  3957. case MT_SORCFX1:
  3958. S_StartSound(NULL, SFX_SORCERER_HEADSCREAM);
  3959. break;
  3960. default:
  3961. break;
  3962. }
  3963. }
  3964. else
  3965. {
  3966. actor->args[4] = BOUNCE_TIME_UNIT;
  3967. }
  3968. }
  3969. }
  3970. //============================================================================
  3971. // Class Bosses
  3972. //============================================================================
  3973. #define CLASS_BOSS_STRAFE_RANGE 64*10*FRACUNIT
  3974. void A_FastChase(mobj_t *actor)
  3975. {
  3976. int delta;
  3977. fixed_t dist;
  3978. angle_t ang;
  3979. mobj_t *target;
  3980. if(actor->reactiontime)
  3981. {
  3982. actor->reactiontime--;
  3983. }
  3984. // Modify target threshold
  3985. if(actor->threshold)
  3986. {
  3987. actor->threshold--;
  3988. }
  3989. if(gameskill == sk_nightmare)
  3990. { // Monsters move faster in nightmare mode
  3991. actor->tics -= actor->tics/2;
  3992. if(actor->tics < 3)
  3993. {
  3994. actor->tics = 3;
  3995. }
  3996. }
  3997. //
  3998. // turn towards movement direction if not there yet
  3999. //
  4000. if(actor->movedir < 8)
  4001. {
  4002. actor->angle &= (7<<29);
  4003. delta = actor->angle-(actor->movedir << 29);
  4004. if(delta > 0)
  4005. {
  4006. actor->angle -= ANG90/2;
  4007. }
  4008. else if(delta < 0)
  4009. {
  4010. actor->angle += ANG90/2;
  4011. }
  4012. }
  4013. if(!actor->target || !(actor->target->flags&MF_SHOOTABLE))
  4014. { // look for a new target
  4015. if(P_LookForPlayers(actor, true))
  4016. { // got a new target
  4017. return;
  4018. }
  4019. P_SetMobjState(actor, actor->info->spawnstate);
  4020. return;
  4021. }
  4022. //
  4023. // don't attack twice in a row
  4024. //
  4025. if(actor->flags & MF_JUSTATTACKED)
  4026. {
  4027. actor->flags &= ~MF_JUSTATTACKED;
  4028. if (gameskill != sk_nightmare)
  4029. P_NewChaseDir (actor);
  4030. return;
  4031. }
  4032. // Strafe
  4033. if (actor->special2 > 0)
  4034. {
  4035. actor->special2--;
  4036. }
  4037. else
  4038. {
  4039. target = actor->target;
  4040. actor->special2 = 0;
  4041. actor->momx = actor->momy = 0;
  4042. dist=P_AproxDistance(actor->x - target->x,
  4043. actor->y - target->y);
  4044. if (dist < CLASS_BOSS_STRAFE_RANGE)
  4045. {
  4046. if (P_Random()<100)
  4047. {
  4048. ang = R_PointToAngle2(actor->x, actor->y,
  4049. target->x, target->y);
  4050. if (P_Random()<128)
  4051. ang += ANGLE_90;
  4052. else
  4053. ang -= ANGLE_90;
  4054. ang>>=ANGLETOFINESHIFT;
  4055. actor->momx = FixedMul(13*FRACUNIT, finecosine[ang]);
  4056. actor->momy = FixedMul(13*FRACUNIT, finesine[ang]);
  4057. actor->special2 = 3; // strafe time
  4058. }
  4059. }
  4060. }
  4061. //
  4062. // check for missile attack
  4063. //
  4064. if (actor->info->missilestate)
  4065. {
  4066. if (gameskill < sk_nightmare && actor->movecount)
  4067. goto nomissile;
  4068. if (!P_CheckMissileRange (actor))
  4069. goto nomissile;
  4070. P_SetMobjState (actor, actor->info->missilestate);
  4071. actor->flags |= MF_JUSTATTACKED;
  4072. return;
  4073. }
  4074. nomissile:
  4075. //
  4076. // possibly choose another target
  4077. //
  4078. if (netgame && !actor->threshold && !P_CheckSight (actor, actor->target) )
  4079. {
  4080. if (P_LookForPlayers(actor,true))
  4081. return; // got a new target
  4082. }
  4083. //
  4084. // chase towards player
  4085. //
  4086. if (!actor->special2)
  4087. {
  4088. if (--actor->movecount<0 || !P_Move (actor))
  4089. {
  4090. P_NewChaseDir (actor);
  4091. }
  4092. }
  4093. }
  4094. void A_FighterAttack(mobj_t *actor)
  4095. {
  4096. extern void A_FSwordAttack2(mobj_t *actor);
  4097. if(!actor->target) return;
  4098. A_FSwordAttack2(actor);
  4099. }
  4100. void A_ClericAttack(mobj_t *actor)
  4101. {
  4102. extern void A_CHolyAttack3(mobj_t *actor);
  4103. if(!actor->target) return;
  4104. A_CHolyAttack3(actor);
  4105. }
  4106. void A_MageAttack(mobj_t *actor)
  4107. {
  4108. extern void A_MStaffAttack2(mobj_t *actor);
  4109. if(!actor->target) return;
  4110. A_MStaffAttack2(actor);
  4111. }
  4112. void A_ClassBossHealth(mobj_t *actor)
  4113. {
  4114. if (netgame && !deathmatch) // co-op only
  4115. {
  4116. if (!actor->special1)
  4117. {
  4118. actor->health *= 5;
  4119. actor->special1 = true; // has been initialized
  4120. }
  4121. }
  4122. }
  4123. //===========================================================================
  4124. //
  4125. // A_CheckFloor - Checks if an object hit the floor
  4126. //
  4127. //===========================================================================
  4128. void A_CheckFloor(mobj_t *actor)
  4129. {
  4130. if(actor->z <= actor->floorz)
  4131. {
  4132. actor->z = actor->floorz;
  4133. actor->flags2 &= ~MF2_LOGRAV;
  4134. P_SetMobjState(actor, actor->info->deathstate);
  4135. }
  4136. }
  4137. //============================================================================
  4138. //
  4139. // A_FreezeDeath
  4140. //
  4141. //============================================================================
  4142. void A_FreezeDeath(mobj_t *actor)
  4143. {
  4144. actor->tics = 75+P_Random()+P_Random();
  4145. actor->flags |= MF_SOLID|MF_SHOOTABLE|MF_NOBLOOD;
  4146. actor->flags2 |= MF2_PUSHABLE|MF2_TELESTOMP|MF2_PASSMOBJ|MF2_SLIDE;
  4147. actor->height <<= 2;
  4148. S_StartSound(actor, SFX_FREEZE_DEATH);
  4149. if(actor->player)
  4150. {
  4151. actor->player->damagecount = 0;
  4152. actor->player->poisoncount = 0;
  4153. actor->player->bonuscount = 0;
  4154. if(actor->player == &players[consoleplayer])
  4155. {
  4156. SB_PaletteFlash(false);
  4157. }
  4158. }
  4159. else if(actor->flags&MF_COUNTKILL && actor->special)
  4160. { // Initiate monster death actions
  4161. P_ExecuteLineSpecial(actor->special, actor->args, NULL, 0, actor);
  4162. }
  4163. }
  4164. //============================================================================
  4165. //
  4166. // A_IceSetTics
  4167. //
  4168. //============================================================================
  4169. void A_IceSetTics(mobj_t *actor)
  4170. {
  4171. int floor;
  4172. actor->tics = 70+(P_Random()&63);
  4173. floor = P_GetThingFloorType(actor);
  4174. if(floor == FLOOR_LAVA)
  4175. {
  4176. actor->tics >>= 2;
  4177. }
  4178. else if(floor == FLOOR_ICE)
  4179. {
  4180. actor->tics <<= 1;
  4181. }
  4182. }
  4183. //============================================================================
  4184. //
  4185. // A_IceCheckHeadDone
  4186. //
  4187. //============================================================================
  4188. void A_IceCheckHeadDone(mobj_t *actor)
  4189. {
  4190. if(actor->special2 == 666)
  4191. {
  4192. P_SetMobjState(actor, S_ICECHUNK_HEAD2);
  4193. }
  4194. }
  4195. //============================================================================
  4196. //
  4197. // A_FreezeDeathChunks
  4198. //
  4199. //============================================================================
  4200. void A_FreezeDeathChunks(mobj_t *actor)
  4201. {
  4202. int i;
  4203. mobj_t *mo;
  4204. if(actor->momx || actor->momy || actor->momz)
  4205. {
  4206. actor->tics = 105;
  4207. return;
  4208. }
  4209. S_StartSound(actor, SFX_FREEZE_SHATTER);
  4210. for(i = 12+(P_Random()&15); i >= 0; i--)
  4211. {
  4212. mo = P_SpawnMobj(actor->x+(((P_Random()-128)*actor->radius)>>7),
  4213. actor->y+(((P_Random()-128)*actor->radius)>>7),
  4214. actor->z+(P_Random()*actor->height/255), MT_ICECHUNK);
  4215. P_SetMobjState(mo, mo->info->spawnstate+(P_Random()%3));
  4216. if(mo)
  4217. {
  4218. mo->momz = FixedDiv(mo->z-actor->z, actor->height)<<2;
  4219. mo->momx = (P_Random()-P_Random())<<(FRACBITS-7);
  4220. mo->momy = (P_Random()-P_Random())<<(FRACBITS-7);
  4221. A_IceSetTics(mo); // set a random tic wait
  4222. }
  4223. }
  4224. for(i = 12+(P_Random()&15); i >= 0; i--)
  4225. {
  4226. mo = P_SpawnMobj(actor->x+(((P_Random()-128)*actor->radius)>>7),
  4227. actor->y+(((P_Random()-128)*actor->radius)>>7),
  4228. actor->z+(P_Random()*actor->height/255), MT_ICECHUNK);
  4229. P_SetMobjState(mo, mo->info->spawnstate+(P_Random()%3));
  4230. if(mo)
  4231. {
  4232. mo->momz = FixedDiv(mo->z-actor->z, actor->height)<<2;
  4233. mo->momx = (P_Random()-P_Random())<<(FRACBITS-7);
  4234. mo->momy = (P_Random()-P_Random())<<(FRACBITS-7);
  4235. A_IceSetTics(mo); // set a random tic wait
  4236. }
  4237. }
  4238. if(actor->player)
  4239. { // attach the player's view to a chunk of ice
  4240. mo = P_SpawnMobj(actor->x, actor->y, actor->z+VIEWHEIGHT, MT_ICECHUNK);
  4241. P_SetMobjState(mo, S_ICECHUNK_HEAD);
  4242. mo->momz = FixedDiv(mo->z-actor->z, actor->height)<<2;
  4243. mo->momx = (P_Random()-P_Random())<<(FRACBITS-7);
  4244. mo->momy = (P_Random()-P_Random())<<(FRACBITS-7);
  4245. mo->flags2 |= MF2_ICEDAMAGE; // used to force blue palette
  4246. mo->flags2 &= ~MF2_FLOORCLIP;
  4247. mo->player = actor->player;
  4248. actor->player = NULL;
  4249. mo->health = actor->health;
  4250. mo->angle = actor->angle;
  4251. mo->player->mo = mo;
  4252. mo->player->lookdir = 0;
  4253. }
  4254. P_RemoveMobjFromTIDList(actor);
  4255. P_SetMobjState(actor, S_FREETARGMOBJ);
  4256. actor->flags2 |= MF2_DONTDRAW;
  4257. }
  4258. //===========================================================================
  4259. // Korax Variables
  4260. // special1 last teleport destination
  4261. // special2 set if "below half" script not yet run
  4262. //
  4263. // Korax Scripts (reserved)
  4264. // 249 Tell scripts that we are below half health
  4265. // 250-254 Control scripts
  4266. // 255 Death script
  4267. //
  4268. // Korax TIDs (reserved)
  4269. // 245 Reserved for Korax himself
  4270. // 248 Initial teleport destination
  4271. // 249 Teleport destination
  4272. // 250-254 For use in respective control scripts
  4273. // 255 For use in death script (spawn spots)
  4274. //===========================================================================
  4275. #define KORAX_SPIRIT_LIFETIME (5*(35/5)) // 5 seconds
  4276. #define KORAX_COMMAND_HEIGHT (120*FRACUNIT)
  4277. #define KORAX_COMMAND_OFFSET (27*FRACUNIT)
  4278. void KoraxFire1(mobj_t *actor, int type);
  4279. void KoraxFire2(mobj_t *actor, int type);
  4280. void KoraxFire3(mobj_t *actor, int type);
  4281. void KoraxFire4(mobj_t *actor, int type);
  4282. void KoraxFire5(mobj_t *actor, int type);
  4283. void KoraxFire6(mobj_t *actor, int type);
  4284. void KSpiritInit(mobj_t *spirit, mobj_t *korax);
  4285. #define KORAX_TID (245)
  4286. #define KORAX_FIRST_TELEPORT_TID (248)
  4287. #define KORAX_TELEPORT_TID (249)
  4288. void A_KoraxChase(mobj_t *actor)
  4289. {
  4290. mobj_t *spot;
  4291. int lastfound;
  4292. byte args[3]={0,0,0};
  4293. if ((!actor->special2) &&
  4294. (actor->health <= (actor->info->spawnhealth/2)))
  4295. {
  4296. lastfound = 0;
  4297. spot = P_FindMobjFromTID(KORAX_FIRST_TELEPORT_TID, &lastfound);
  4298. if (spot)
  4299. {
  4300. P_Teleport(actor, spot->x, spot->y, spot->angle, true);
  4301. }
  4302. P_StartACS(249, 0, args, actor, NULL, 0);
  4303. actor->special2 = 1; // Don't run again
  4304. return;
  4305. }
  4306. if (!actor->target) return;
  4307. if (P_Random()<30)
  4308. {
  4309. P_SetMobjState(actor, actor->info->missilestate);
  4310. }
  4311. else if (P_Random()<30)
  4312. {
  4313. S_StartSound(NULL, SFX_KORAX_ACTIVE);
  4314. }
  4315. // Teleport away
  4316. if (actor->health < (actor->info->spawnhealth>>1))
  4317. {
  4318. if (P_Random()<10)
  4319. {
  4320. lastfound = actor->special1;
  4321. spot = P_FindMobjFromTID(KORAX_TELEPORT_TID, &lastfound);
  4322. actor->special1 = lastfound;
  4323. if (spot)
  4324. {
  4325. P_Teleport(actor, spot->x, spot->y, spot->angle, true);
  4326. }
  4327. }
  4328. }
  4329. }
  4330. void A_KoraxStep(mobj_t *actor)
  4331. {
  4332. A_Chase(actor);
  4333. }
  4334. void A_KoraxStep2(mobj_t *actor)
  4335. {
  4336. S_StartSound(NULL, SFX_KORAX_STEP);
  4337. A_Chase(actor);
  4338. }
  4339. void A_KoraxBonePop(mobj_t *actor)
  4340. {
  4341. fixed_t x,y,z;
  4342. mobj_t *mo;
  4343. byte args[5];
  4344. args[0]=args[1]=args[2]=args[3]=args[4]=0;
  4345. x=actor->x, y=actor->y, z=actor->z;
  4346. // Spawn 6 spirits equalangularly
  4347. mo = P_SpawnMissileAngle(actor,MT_KORAX_SPIRIT1, ANGLE_60*0, 5*FRACUNIT);
  4348. if (mo) KSpiritInit(mo,actor);
  4349. mo = P_SpawnMissileAngle(actor,MT_KORAX_SPIRIT2, ANGLE_60*1, 5*FRACUNIT);
  4350. if (mo) KSpiritInit(mo,actor);
  4351. mo = P_SpawnMissileAngle(actor,MT_KORAX_SPIRIT3, ANGLE_60*2, 5*FRACUNIT);
  4352. if (mo) KSpiritInit(mo,actor);
  4353. mo = P_SpawnMissileAngle(actor,MT_KORAX_SPIRIT4, ANGLE_60*3, 5*FRACUNIT);
  4354. if (mo) KSpiritInit(mo,actor);
  4355. mo = P_SpawnMissileAngle(actor,MT_KORAX_SPIRIT5, ANGLE_60*4, 5*FRACUNIT);
  4356. if (mo) KSpiritInit(mo,actor);
  4357. mo = P_SpawnMissileAngle(actor,MT_KORAX_SPIRIT6, ANGLE_60*5, 5*FRACUNIT);
  4358. if (mo) KSpiritInit(mo,actor);
  4359. P_StartACS(255, 0, args, actor, NULL, 0); // Death script
  4360. }
  4361. void KSpiritInit(mobj_t *spirit, mobj_t *korax)
  4362. {
  4363. int i;
  4364. mobj_t *tail, *next;
  4365. spirit->health = KORAX_SPIRIT_LIFETIME;
  4366. spirit->special1 = (int)korax; // Swarm around korax
  4367. spirit->special2 = 32+(P_Random()&7); // Float bob index
  4368. spirit->args[0] = 10; // initial turn value
  4369. spirit->args[1] = 0; // initial look angle
  4370. // Spawn a tail for spirit
  4371. tail = P_SpawnMobj(spirit->x, spirit->y, spirit->z, MT_HOLY_TAIL);
  4372. tail->special2 = (int)spirit; // parent
  4373. for(i = 1; i < 3; i++)
  4374. {
  4375. next = P_SpawnMobj(spirit->x, spirit->y, spirit->z, MT_HOLY_TAIL);
  4376. P_SetMobjState(next, next->info->spawnstate+1);
  4377. tail->special1 = (int)next;
  4378. tail = next;
  4379. }
  4380. tail->special1 = 0; // last tail bit
  4381. }
  4382. void A_KoraxDecide(mobj_t *actor)
  4383. {
  4384. if (P_Random()<220)
  4385. {
  4386. P_SetMobjState(actor, S_KORAX_MISSILE1);
  4387. }
  4388. else
  4389. {
  4390. P_SetMobjState(actor, S_KORAX_COMMAND1);
  4391. }
  4392. }
  4393. void A_KoraxMissile(mobj_t *actor)
  4394. {
  4395. int type = P_Random()%6;
  4396. int sound;
  4397. S_StartSound(actor, SFX_KORAX_ATTACK);
  4398. switch(type)
  4399. {
  4400. case 0:
  4401. type = MT_WRAITHFX1;
  4402. sound = SFX_WRAITH_MISSILE_FIRE;
  4403. break;
  4404. case 1:
  4405. type = MT_DEMONFX1;
  4406. sound = SFX_DEMON_MISSILE_FIRE;
  4407. break;
  4408. case 2:
  4409. type = MT_DEMON2FX1;
  4410. sound = SFX_DEMON_MISSILE_FIRE;
  4411. break;
  4412. case 3:
  4413. type = MT_FIREDEMON_FX6;
  4414. sound = SFX_FIRED_ATTACK;
  4415. break;
  4416. case 4:
  4417. type = MT_CENTAUR_FX;
  4418. sound = SFX_CENTAURLEADER_ATTACK;
  4419. break;
  4420. case 5:
  4421. type = MT_SERPENTFX;
  4422. sound = SFX_CENTAURLEADER_ATTACK;
  4423. break;
  4424. }
  4425. // Fire all 6 missiles at once
  4426. S_StartSound(NULL, sound);
  4427. KoraxFire1(actor, type);
  4428. KoraxFire2(actor, type);
  4429. KoraxFire3(actor, type);
  4430. KoraxFire4(actor, type);
  4431. KoraxFire5(actor, type);
  4432. KoraxFire6(actor, type);
  4433. }
  4434. // Call action code scripts (250-254)
  4435. void A_KoraxCommand(mobj_t *actor)
  4436. {
  4437. byte args[5];
  4438. fixed_t x,y,z;
  4439. angle_t ang;
  4440. int numcommands;
  4441. S_StartSound(actor, SFX_KORAX_COMMAND);
  4442. // Shoot stream of lightning to ceiling
  4443. ang = (actor->angle - ANGLE_90) >> ANGLETOFINESHIFT;
  4444. x=actor->x + FixedMul(KORAX_COMMAND_OFFSET,finecosine[ang]);
  4445. y=actor->y + FixedMul(KORAX_COMMAND_OFFSET,finesine[ang]);
  4446. z=actor->z + KORAX_COMMAND_HEIGHT;
  4447. P_SpawnMobj(x,y,z, MT_KORAX_BOLT);
  4448. args[0]=args[1]=args[2]=args[3]=args[4]=0;
  4449. if (actor->health <= (actor->info->spawnhealth >> 1))
  4450. {
  4451. numcommands = 5;
  4452. }
  4453. else
  4454. {
  4455. numcommands = 4;
  4456. }
  4457. switch(P_Random() % numcommands)
  4458. {
  4459. case 0:
  4460. P_StartACS(250, 0, args, actor, NULL, 0);
  4461. break;
  4462. case 1:
  4463. P_StartACS(251, 0, args, actor, NULL, 0);
  4464. break;
  4465. case 2:
  4466. P_StartACS(252, 0, args, actor, NULL, 0);
  4467. break;
  4468. case 3:
  4469. P_StartACS(253, 0, args, actor, NULL, 0);
  4470. break;
  4471. case 4:
  4472. P_StartACS(254, 0, args, actor, NULL, 0);
  4473. break;
  4474. }
  4475. }
  4476. #define KORAX_DELTAANGLE (85*ANGLE_1)
  4477. #define KORAX_ARM_EXTENSION_SHORT (40*FRACUNIT)
  4478. #define KORAX_ARM_EXTENSION_LONG (55*FRACUNIT)
  4479. #define KORAX_ARM1_HEIGHT (108*FRACUNIT)
  4480. #define KORAX_ARM2_HEIGHT (82*FRACUNIT)
  4481. #define KORAX_ARM3_HEIGHT (54*FRACUNIT)
  4482. #define KORAX_ARM4_HEIGHT (104*FRACUNIT)
  4483. #define KORAX_ARM5_HEIGHT (86*FRACUNIT)
  4484. #define KORAX_ARM6_HEIGHT (53*FRACUNIT)
  4485. // Arm projectiles
  4486. // arm positions numbered:
  4487. // 1 top left
  4488. // 2 middle left
  4489. // 3 lower left
  4490. // 4 top right
  4491. // 5 middle right
  4492. // 6 lower right
  4493. // Arm 1 projectile
  4494. void KoraxFire1(mobj_t *actor, int type)
  4495. {
  4496. mobj_t *mo;
  4497. angle_t ang;
  4498. fixed_t x,y,z;
  4499. ang = (actor->angle - KORAX_DELTAANGLE) >> ANGLETOFINESHIFT;
  4500. x = actor->x + FixedMul(KORAX_ARM_EXTENSION_SHORT, finecosine[ang]);
  4501. y = actor->y + FixedMul(KORAX_ARM_EXTENSION_SHORT, finesine[ang]);
  4502. z = actor->z - actor->floorclip + KORAX_ARM1_HEIGHT;
  4503. mo = P_SpawnKoraxMissile(x,y,z,actor, actor->target, type);
  4504. }
  4505. // Arm 2 projectile
  4506. void KoraxFire2(mobj_t *actor, int type)
  4507. {
  4508. mobj_t *mo;
  4509. angle_t ang;
  4510. fixed_t x,y,z;
  4511. ang = (actor->angle - KORAX_DELTAANGLE) >> ANGLETOFINESHIFT;
  4512. x = actor->x + FixedMul(KORAX_ARM_EXTENSION_LONG, finecosine[ang]);
  4513. y = actor->y + FixedMul(KORAX_ARM_EXTENSION_LONG, finesine[ang]);
  4514. z = actor->z - actor->floorclip + KORAX_ARM2_HEIGHT;
  4515. mo = P_SpawnKoraxMissile(x,y,z,actor, actor->target, type);
  4516. }
  4517. // Arm 3 projectile
  4518. void KoraxFire3(mobj_t *actor, int type)
  4519. {
  4520. mobj_t *mo;
  4521. angle_t ang;
  4522. fixed_t x,y,z;
  4523. ang = (actor->angle - KORAX_DELTAANGLE) >> ANGLETOFINESHIFT;
  4524. x = actor->x + FixedMul(KORAX_ARM_EXTENSION_LONG, finecosine[ang]);
  4525. y = actor->y + FixedMul(KORAX_ARM_EXTENSION_LONG, finesine[ang]);
  4526. z = actor->z - actor->floorclip + KORAX_ARM3_HEIGHT;
  4527. mo = P_SpawnKoraxMissile(x,y,z,actor, actor->target, type);
  4528. }
  4529. // Arm 4 projectile
  4530. void KoraxFire4(mobj_t *actor, int type)
  4531. {
  4532. mobj_t *mo;
  4533. angle_t ang;
  4534. fixed_t x,y,z;
  4535. ang = (actor->angle + KORAX_DELTAANGLE) >> ANGLETOFINESHIFT;
  4536. x = actor->x + FixedMul(KORAX_ARM_EXTENSION_SHORT, finecosine[ang]);
  4537. y = actor->y + FixedMul(KORAX_ARM_EXTENSION_SHORT, finesine[ang]);
  4538. z = actor->z - actor->floorclip + KORAX_ARM4_HEIGHT;
  4539. mo = P_SpawnKoraxMissile(x,y,z,actor, actor->target, type);
  4540. }
  4541. // Arm 5 projectile
  4542. void KoraxFire5(mobj_t *actor, int type)
  4543. {
  4544. mobj_t *mo;
  4545. angle_t ang;
  4546. fixed_t x,y,z;
  4547. ang = (actor->angle + KORAX_DELTAANGLE) >> ANGLETOFINESHIFT;
  4548. x = actor->x + FixedMul(KORAX_ARM_EXTENSION_LONG, finecosine[ang]);
  4549. y = actor->y + FixedMul(KORAX_ARM_EXTENSION_LONG, finesine[ang]);
  4550. z = actor->z - actor->floorclip + KORAX_ARM5_HEIGHT;
  4551. mo = P_SpawnKoraxMissile(x,y,z,actor, actor->target, type);
  4552. }
  4553. // Arm 6 projectile
  4554. void KoraxFire6(mobj_t *actor, int type)
  4555. {
  4556. mobj_t *mo;
  4557. angle_t ang;
  4558. fixed_t x,y,z;
  4559. ang = (actor->angle + KORAX_DELTAANGLE) >> ANGLETOFINESHIFT;
  4560. x = actor->x + FixedMul(KORAX_ARM_EXTENSION_LONG, finecosine[ang]);
  4561. y = actor->y + FixedMul(KORAX_ARM_EXTENSION_LONG, finesine[ang]);
  4562. z = actor->z - actor->floorclip + KORAX_ARM6_HEIGHT;
  4563. mo = P_SpawnKoraxMissile(x,y,z,actor, actor->target, type);
  4564. }
  4565. void A_KSpiritWeave(mobj_t *actor)
  4566. {
  4567. fixed_t newX, newY;
  4568. int weaveXY, weaveZ;
  4569. int angle;
  4570. weaveXY = actor->special2>>16;
  4571. weaveZ = actor->special2&0xFFFF;
  4572. angle = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  4573. newX = actor->x-FixedMul(finecosine[angle],
  4574. FloatBobOffsets[weaveXY]<<2);
  4575. newY = actor->y-FixedMul(finesine[angle],
  4576. FloatBobOffsets[weaveXY]<<2);
  4577. weaveXY = (weaveXY+(P_Random()%5))&63;
  4578. newX += FixedMul(finecosine[angle],
  4579. FloatBobOffsets[weaveXY]<<2);
  4580. newY += FixedMul(finesine[angle],
  4581. FloatBobOffsets[weaveXY]<<2);
  4582. P_TryMove(actor, newX, newY);
  4583. actor->z -= FloatBobOffsets[weaveZ]<<1;
  4584. weaveZ = (weaveZ+(P_Random()%5))&63;
  4585. actor->z += FloatBobOffsets[weaveZ]<<1;
  4586. actor->special2 = weaveZ+(weaveXY<<16);
  4587. }
  4588. void A_KSpiritSeeker(mobj_t *actor, angle_t thresh, angle_t turnMax)
  4589. {
  4590. int dir;
  4591. int dist;
  4592. angle_t delta;
  4593. angle_t angle;
  4594. mobj_t *target;
  4595. fixed_t newZ;
  4596. fixed_t deltaZ;
  4597. target = (mobj_t *)actor->special1;
  4598. if(target == NULL)
  4599. {
  4600. return;
  4601. }
  4602. dir = P_FaceMobj(actor, target, &delta);
  4603. if(delta > thresh)
  4604. {
  4605. delta >>= 1;
  4606. if(delta > turnMax)
  4607. {
  4608. delta = turnMax;
  4609. }
  4610. }
  4611. if(dir)
  4612. { // Turn clockwise
  4613. actor->angle += delta;
  4614. }
  4615. else
  4616. { // Turn counter clockwise
  4617. actor->angle -= delta;
  4618. }
  4619. angle = actor->angle>>ANGLETOFINESHIFT;
  4620. actor->momx = FixedMul(actor->info->speed, finecosine[angle]);
  4621. actor->momy = FixedMul(actor->info->speed, finesine[angle]);
  4622. if(!(leveltime&15)
  4623. || actor->z > target->z+(target->info->height)
  4624. || actor->z+actor->height < target->z)
  4625. {
  4626. newZ = target->z+((P_Random()*target->info->height)>>8);
  4627. deltaZ = newZ-actor->z;
  4628. if(abs(deltaZ) > 15*FRACUNIT)
  4629. {
  4630. if(deltaZ > 0)
  4631. {
  4632. deltaZ = 15*FRACUNIT;
  4633. }
  4634. else
  4635. {
  4636. deltaZ = -15*FRACUNIT;
  4637. }
  4638. }
  4639. dist = P_AproxDistance(target->x-actor->x, target->y-actor->y);
  4640. dist = dist/actor->info->speed;
  4641. if(dist < 1)
  4642. {
  4643. dist = 1;
  4644. }
  4645. actor->momz = deltaZ/dist;
  4646. }
  4647. return;
  4648. }
  4649. void A_KSpiritRoam(mobj_t *actor)
  4650. {
  4651. if (actor->health-- <= 0)
  4652. {
  4653. S_StartSound(actor, SFX_SPIRIT_DIE);
  4654. P_SetMobjState(actor, S_KSPIRIT_DEATH1);
  4655. }
  4656. else
  4657. {
  4658. if (actor->special1)
  4659. {
  4660. A_KSpiritSeeker(actor, actor->args[0]*ANGLE_1,
  4661. actor->args[0]*ANGLE_1*2);
  4662. }
  4663. A_KSpiritWeave(actor);
  4664. if (P_Random()<50)
  4665. {
  4666. S_StartSound(NULL, SFX_SPIRIT_ACTIVE);
  4667. }
  4668. }
  4669. }
  4670. void A_KBolt(mobj_t *actor)
  4671. {
  4672. // Countdown lifetime
  4673. if (actor->special1-- <= 0)
  4674. {
  4675. P_SetMobjState(actor, S_NULL);
  4676. }
  4677. }
  4678. #define KORAX_BOLT_HEIGHT 48*FRACUNIT
  4679. #define KORAX_BOLT_LIFETIME 3
  4680. void A_KBoltRaise(mobj_t *actor)
  4681. {
  4682. mobj_t *mo;
  4683. fixed_t z;
  4684. // Spawn a child upward
  4685. z = actor->z + KORAX_BOLT_HEIGHT;
  4686. if ((z + KORAX_BOLT_HEIGHT) < actor->ceilingz)
  4687. {
  4688. mo = P_SpawnMobj(actor->x, actor->y, z, MT_KORAX_BOLT);
  4689. if (mo)
  4690. {
  4691. mo->special1 = KORAX_BOLT_LIFETIME;
  4692. }
  4693. }
  4694. else
  4695. {
  4696. // Maybe cap it off here
  4697. }
  4698. }