P_PSPR.C 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457
  1. //**************************************************************************
  2. //**
  3. //** p_pspr.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: p_pspr.c,v $
  6. //** $Revision: 1.105 $
  7. //** $Date: 96/01/06 03:23:35 $
  8. //** $Author: bgokey $
  9. //**
  10. //**************************************************************************
  11. // HEADER FILES ------------------------------------------------------------
  12. #include "h2def.h"
  13. #include "p_local.h"
  14. #include "soundst.h"
  15. // MACROS ------------------------------------------------------------------
  16. #define LOWERSPEED FRACUNIT*6
  17. #define RAISESPEED FRACUNIT*6
  18. #define WEAPONBOTTOM 128*FRACUNIT
  19. #define WEAPONTOP 32*FRACUNIT
  20. // TYPES -------------------------------------------------------------------
  21. // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  22. extern void P_ExplodeMissile(mobj_t *mo);
  23. extern void A_UnHideThing(mobj_t *actor);
  24. // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
  25. // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
  26. // EXTERNAL DATA DECLARATIONS ----------------------------------------------
  27. extern fixed_t FloatBobOffsets[64];
  28. // PUBLIC DATA DEFINITIONS -------------------------------------------------
  29. fixed_t bulletslope;
  30. weaponinfo_t WeaponInfo[NUMWEAPONS][NUMCLASSES] =
  31. {
  32. { // First Weapons
  33. { // Fighter First Weapon - Punch
  34. MANA_NONE, // mana
  35. S_PUNCHUP, // upstate
  36. S_PUNCHDOWN, // downstate
  37. S_PUNCHREADY, // readystate
  38. S_PUNCHATK1_1, // atkstate
  39. S_PUNCHATK1_1, // holdatkstate
  40. S_NULL // flashstate
  41. },
  42. { // Cleric First Weapon - Mace
  43. MANA_NONE, // mana
  44. S_CMACEUP, // upstate
  45. S_CMACEDOWN, // downstate
  46. S_CMACEREADY, // readystate
  47. S_CMACEATK_1, // atkstate
  48. S_CMACEATK_1, // holdatkstate
  49. S_NULL // flashstate
  50. },
  51. { // Mage First Weapon - Wand
  52. MANA_NONE,
  53. S_MWANDUP,
  54. S_MWANDDOWN,
  55. S_MWANDREADY,
  56. S_MWANDATK_1,
  57. S_MWANDATK_1,
  58. S_NULL
  59. },
  60. { // Pig - Snout
  61. MANA_NONE, // mana
  62. S_SNOUTUP, // upstate
  63. S_SNOUTDOWN, // downstate
  64. S_SNOUTREADY, // readystate
  65. S_SNOUTATK1, // atkstate
  66. S_SNOUTATK1, // holdatkstate
  67. S_NULL // flashstate
  68. }
  69. },
  70. { // Second Weapons
  71. { // Fighter - Axe
  72. MANA_NONE, // mana
  73. S_FAXEUP, // upstate
  74. S_FAXEDOWN, // downstate
  75. S_FAXEREADY, // readystate
  76. S_FAXEATK_1, // atkstate
  77. S_FAXEATK_1, // holdatkstate
  78. S_NULL // flashstate
  79. },
  80. { // Cleric - Serpent Staff
  81. MANA_1, // mana
  82. S_CSTAFFUP, // upstate
  83. S_CSTAFFDOWN, // downstate
  84. S_CSTAFFREADY, // readystate
  85. S_CSTAFFATK_1, // atkstate
  86. S_CSTAFFATK_1, // holdatkstate
  87. S_NULL // flashstate
  88. },
  89. { // Mage - Cone of shards
  90. MANA_1, // mana
  91. S_CONEUP, // upstate
  92. S_CONEDOWN, // downstate
  93. S_CONEREADY, // readystate
  94. S_CONEATK1_1, // atkstate
  95. S_CONEATK1_3, // holdatkstate
  96. S_NULL // flashstate
  97. },
  98. { // Pig - Snout
  99. MANA_NONE, // mana
  100. S_SNOUTUP, // upstate
  101. S_SNOUTDOWN, // downstate
  102. S_SNOUTREADY, // readystate
  103. S_SNOUTATK1, // atkstate
  104. S_SNOUTATK1, // holdatkstate
  105. S_NULL // flashstate
  106. }
  107. },
  108. { // Third Weapons
  109. { // Fighter - Hammer
  110. MANA_NONE, // mana
  111. S_FHAMMERUP, // upstate
  112. S_FHAMMERDOWN, // downstate
  113. S_FHAMMERREADY, // readystate
  114. S_FHAMMERATK_1, // atkstate
  115. S_FHAMMERATK_1, // holdatkstate
  116. S_NULL // flashstate
  117. },
  118. { // Cleric - Flame Strike
  119. MANA_2, // mana
  120. S_CFLAMEUP, // upstate
  121. S_CFLAMEDOWN, // downstate
  122. S_CFLAMEREADY1, // readystate
  123. S_CFLAMEATK_1, // atkstate
  124. S_CFLAMEATK_1, // holdatkstate
  125. S_NULL // flashstate
  126. },
  127. { // Mage - Lightning
  128. MANA_2, // mana
  129. S_MLIGHTNINGUP, // upstate
  130. S_MLIGHTNINGDOWN, // downstate
  131. S_MLIGHTNINGREADY, // readystate
  132. S_MLIGHTNINGATK_1, // atkstate
  133. S_MLIGHTNINGATK_1, // holdatkstate
  134. S_NULL // flashstate
  135. },
  136. { // Pig - Snout
  137. MANA_NONE, // mana
  138. S_SNOUTUP, // upstate
  139. S_SNOUTDOWN, // downstate
  140. S_SNOUTREADY, // readystate
  141. S_SNOUTATK1, // atkstate
  142. S_SNOUTATK1, // holdatkstate
  143. S_NULL // flashstate
  144. }
  145. },
  146. { // Fourth Weapons
  147. { // Fighter - Rune Sword
  148. MANA_BOTH, // mana
  149. S_FSWORDUP, // upstate
  150. S_FSWORDDOWN, // downstate
  151. S_FSWORDREADY, // readystate
  152. S_FSWORDATK_1, // atkstate
  153. S_FSWORDATK_1, // holdatkstate
  154. S_NULL // flashstate
  155. },
  156. { // Cleric - Holy Symbol
  157. MANA_BOTH, // mana
  158. S_CHOLYUP, // upstate
  159. S_CHOLYDOWN, // downstate
  160. S_CHOLYREADY, // readystate
  161. S_CHOLYATK_1, // atkstate
  162. S_CHOLYATK_1, // holdatkstate
  163. S_NULL // flashstate
  164. },
  165. { // Mage - Staff
  166. MANA_BOTH, // mana
  167. S_MSTAFFUP, // upstate
  168. S_MSTAFFDOWN, // downstate
  169. S_MSTAFFREADY, // readystate
  170. S_MSTAFFATK_1, // atkstate
  171. S_MSTAFFATK_1, // holdatkstate
  172. S_NULL // flashstate
  173. },
  174. { // Pig - Snout
  175. MANA_NONE, // mana
  176. S_SNOUTUP, // upstate
  177. S_SNOUTDOWN, // downstate
  178. S_SNOUTREADY, // readystate
  179. S_SNOUTATK1, // atkstate
  180. S_SNOUTATK1, // holdatkstate
  181. S_NULL // flashstate
  182. }
  183. }
  184. };
  185. // PRIVATE DATA DEFINITIONS ------------------------------------------------
  186. static int WeaponManaUse[NUMCLASSES][NUMWEAPONS] =
  187. {
  188. { 0, 2, 3, 14 },
  189. { 0, 1, 4, 18 },
  190. { 0, 3, 5, 15 },
  191. { 0, 0, 0, 0 }
  192. };
  193. // CODE --------------------------------------------------------------------
  194. //---------------------------------------------------------------------------
  195. //
  196. // PROC P_SetPsprite
  197. //
  198. //---------------------------------------------------------------------------
  199. void P_SetPsprite(player_t *player, int position, statenum_t stnum)
  200. {
  201. pspdef_t *psp;
  202. state_t *state;
  203. psp = &player->psprites[position];
  204. do
  205. {
  206. if(!stnum)
  207. { // Object removed itself.
  208. psp->state = NULL;
  209. break;
  210. }
  211. state = &states[stnum];
  212. psp->state = state;
  213. psp->tics = state->tics; // could be 0
  214. if(state->misc1)
  215. { // Set coordinates.
  216. psp->sx = state->misc1<<FRACBITS;
  217. }
  218. if(state->misc2)
  219. {
  220. psp->sy = state->misc2<<FRACBITS;
  221. }
  222. if(state->action)
  223. { // Call action routine.
  224. state->action(player, psp);
  225. if(!psp->state)
  226. {
  227. break;
  228. }
  229. }
  230. stnum = psp->state->nextstate;
  231. } while(!psp->tics); // An initial state of 0 could cycle through.
  232. }
  233. //---------------------------------------------------------------------------
  234. //
  235. // PROC P_SetPspriteNF
  236. //
  237. // Identical to P_SetPsprite, without calling the action function
  238. //---------------------------------------------------------------------------
  239. void P_SetPspriteNF(player_t *player, int position, statenum_t stnum)
  240. {
  241. pspdef_t *psp;
  242. state_t *state;
  243. psp = &player->psprites[position];
  244. do
  245. {
  246. if(!stnum)
  247. { // Object removed itself.
  248. psp->state = NULL;
  249. break;
  250. }
  251. state = &states[stnum];
  252. psp->state = state;
  253. psp->tics = state->tics; // could be 0
  254. if(state->misc1)
  255. { // Set coordinates.
  256. psp->sx = state->misc1<<FRACBITS;
  257. }
  258. if(state->misc2)
  259. {
  260. psp->sy = state->misc2<<FRACBITS;
  261. }
  262. stnum = psp->state->nextstate;
  263. } while(!psp->tics); // An initial state of 0 could cycle through.
  264. }
  265. /*
  266. =================
  267. =
  268. = P_CalcSwing
  269. =
  270. =================
  271. */
  272. /*
  273. fixed_t swingx, swingy;
  274. void P_CalcSwing (player_t *player)
  275. {
  276. fixed_t swing;
  277. int angle;
  278. // OPTIMIZE: tablify this
  279. swing = player->bob;
  280. angle = (FINEANGLES/70*leveltime)&FINEMASK;
  281. swingx = FixedMul ( swing, finesine[angle]);
  282. angle = (FINEANGLES/70*leveltime+FINEANGLES/2)&FINEMASK;
  283. swingy = -FixedMul ( swingx, finesine[angle]);
  284. }
  285. */
  286. //---------------------------------------------------------------------------
  287. //
  288. // PROC P_ActivateMorphWeapon
  289. //
  290. //---------------------------------------------------------------------------
  291. void P_ActivateMorphWeapon(player_t *player)
  292. {
  293. player->pendingweapon = WP_NOCHANGE;
  294. player->psprites[ps_weapon].sy = WEAPONTOP;
  295. player->readyweapon = WP_FIRST; // Snout is the first weapon
  296. P_SetPsprite(player, ps_weapon, S_SNOUTREADY);
  297. }
  298. //---------------------------------------------------------------------------
  299. //
  300. // PROC P_PostMorphWeapon
  301. //
  302. //---------------------------------------------------------------------------
  303. void P_PostMorphWeapon(player_t *player, weapontype_t weapon)
  304. {
  305. player->pendingweapon = WP_NOCHANGE;
  306. player->readyweapon = weapon;
  307. player->psprites[ps_weapon].sy = WEAPONBOTTOM;
  308. P_SetPsprite(player, ps_weapon, WeaponInfo[weapon][player->class].upstate);
  309. }
  310. //---------------------------------------------------------------------------
  311. //
  312. // PROC P_BringUpWeapon
  313. //
  314. // Starts bringing the pending weapon up from the bottom of the screen.
  315. //
  316. //---------------------------------------------------------------------------
  317. void P_BringUpWeapon(player_t *player)
  318. {
  319. statenum_t new;
  320. if(player->pendingweapon == WP_NOCHANGE)
  321. {
  322. player->pendingweapon = player->readyweapon;
  323. }
  324. if(player->class == PCLASS_FIGHTER && player->pendingweapon == WP_SECOND
  325. && player->mana[MANA_1])
  326. {
  327. new = S_FAXEUP_G;
  328. }
  329. else
  330. {
  331. new = WeaponInfo[player->pendingweapon][player->class].upstate;
  332. }
  333. player->pendingweapon = WP_NOCHANGE;
  334. player->psprites[ps_weapon].sy = WEAPONBOTTOM;
  335. P_SetPsprite(player, ps_weapon, new);
  336. }
  337. //---------------------------------------------------------------------------
  338. //
  339. // FUNC P_CheckMana
  340. //
  341. // Returns true if there is enough mana to shoot. If not, selects the
  342. // next weapon to use.
  343. //
  344. //---------------------------------------------------------------------------
  345. boolean P_CheckMana(player_t *player)
  346. {
  347. manatype_t mana;
  348. int count;
  349. mana = WeaponInfo[player->readyweapon][player->class].mana;
  350. count = WeaponManaUse[player->class][player->readyweapon];
  351. if(mana == MANA_BOTH)
  352. {
  353. if(player->mana[MANA_1] >= count && player->mana[MANA_2] >= count)
  354. {
  355. return true;
  356. }
  357. }
  358. else if(mana == MANA_NONE || player->mana[mana] >= count)
  359. {
  360. return(true);
  361. }
  362. // out of mana, pick a weapon to change to
  363. do
  364. {
  365. if(player->weaponowned[WP_THIRD]
  366. && player->mana[MANA_2] >= WeaponManaUse[player->class][WP_THIRD])
  367. {
  368. player->pendingweapon = WP_THIRD;
  369. }
  370. else if(player->weaponowned[WP_SECOND]
  371. && player->mana[MANA_1] >= WeaponManaUse[player->class][WP_SECOND])
  372. {
  373. player->pendingweapon = WP_SECOND;
  374. }
  375. else if(player->weaponowned[WP_FOURTH]
  376. && player->mana[MANA_1] >= WeaponManaUse[player->class][WP_FOURTH]
  377. && player->mana[MANA_2] >= WeaponManaUse[player->class][WP_FOURTH])
  378. {
  379. player->pendingweapon = WP_FOURTH;
  380. }
  381. else
  382. {
  383. player->pendingweapon = WP_FIRST;
  384. }
  385. } while(player->pendingweapon == WP_NOCHANGE);
  386. P_SetPsprite(player, ps_weapon,
  387. WeaponInfo[player->readyweapon][player->class].downstate);
  388. return(false);
  389. }
  390. //---------------------------------------------------------------------------
  391. //
  392. // PROC P_FireWeapon
  393. //
  394. //---------------------------------------------------------------------------
  395. void P_FireWeapon(player_t *player)
  396. {
  397. statenum_t attackState;
  398. if(!P_CheckMana(player))
  399. {
  400. return;
  401. }
  402. P_SetMobjState(player->mo, PStateAttack[player->class]); // S_PLAY_ATK1);
  403. if(player->class == PCLASS_FIGHTER && player->readyweapon == WP_SECOND
  404. && player->mana[MANA_1] > 0)
  405. { // Glowing axe
  406. attackState = S_FAXEATK_G1;
  407. }
  408. else
  409. {
  410. attackState = player->refire ?
  411. WeaponInfo[player->readyweapon][player->class].holdatkstate
  412. : WeaponInfo[player->readyweapon][player->class].atkstate;
  413. }
  414. P_SetPsprite(player, ps_weapon, attackState);
  415. P_NoiseAlert(player->mo, player->mo);
  416. }
  417. //---------------------------------------------------------------------------
  418. //
  419. // PROC P_DropWeapon
  420. //
  421. // The player died, so put the weapon away.
  422. //
  423. //---------------------------------------------------------------------------
  424. void P_DropWeapon(player_t *player)
  425. {
  426. P_SetPsprite(player, ps_weapon,
  427. WeaponInfo[player->readyweapon][player->class].downstate);
  428. }
  429. //---------------------------------------------------------------------------
  430. //
  431. // PROC A_WeaponReady
  432. //
  433. // The player can fire the weapon or change to another weapon at this time.
  434. //
  435. //---------------------------------------------------------------------------
  436. void A_WeaponReady(player_t *player, pspdef_t *psp)
  437. {
  438. int angle;
  439. // Change player from attack state
  440. if(player->mo->state >= &states[PStateAttack[player->class]]
  441. && player->mo->state <= &states[PStateAttackEnd[player->class]])
  442. {
  443. P_SetMobjState(player->mo, PStateNormal[player->class]);
  444. }
  445. // Put the weapon away if the player has a pending weapon or has
  446. // died.
  447. if(player->pendingweapon != WP_NOCHANGE || !player->health)
  448. {
  449. P_SetPsprite(player, ps_weapon,
  450. WeaponInfo[player->readyweapon][player->class].downstate);
  451. return;
  452. }
  453. // Check for fire.
  454. if(player->cmd.buttons&BT_ATTACK)
  455. {
  456. player->attackdown = true;
  457. P_FireWeapon(player);
  458. return;
  459. }
  460. else
  461. {
  462. player->attackdown = false;
  463. }
  464. if(!player->morphTics)
  465. {
  466. // Bob the weapon based on movement speed.
  467. angle = (128*leveltime)&FINEMASK;
  468. psp->sx = FRACUNIT+FixedMul(player->bob, finecosine[angle]);
  469. angle &= FINEANGLES/2-1;
  470. psp->sy = WEAPONTOP+FixedMul(player->bob, finesine[angle]);
  471. }
  472. }
  473. //---------------------------------------------------------------------------
  474. //
  475. // PROC A_ReFire
  476. //
  477. // The player can re fire the weapon without lowering it entirely.
  478. //
  479. //---------------------------------------------------------------------------
  480. void A_ReFire(player_t *player, pspdef_t *psp)
  481. {
  482. if((player->cmd.buttons&BT_ATTACK)
  483. && player->pendingweapon == WP_NOCHANGE && player->health)
  484. {
  485. player->refire++;
  486. P_FireWeapon(player);
  487. }
  488. else
  489. {
  490. player->refire = 0;
  491. P_CheckMana(player);
  492. }
  493. }
  494. //---------------------------------------------------------------------------
  495. //
  496. // PROC A_Lower
  497. //
  498. //---------------------------------------------------------------------------
  499. void A_Lower(player_t *player, pspdef_t *psp)
  500. {
  501. if(player->morphTics)
  502. {
  503. psp->sy = WEAPONBOTTOM;
  504. }
  505. else
  506. {
  507. psp->sy += LOWERSPEED;
  508. }
  509. if(psp->sy < WEAPONBOTTOM)
  510. { // Not lowered all the way yet
  511. return;
  512. }
  513. if(player->playerstate == PST_DEAD)
  514. { // Player is dead, so don't bring up a pending weapon
  515. psp->sy = WEAPONBOTTOM;
  516. return;
  517. }
  518. if(!player->health)
  519. { // Player is dead, so keep the weapon off screen
  520. P_SetPsprite(player, ps_weapon, S_NULL);
  521. return;
  522. }
  523. player->readyweapon = player->pendingweapon;
  524. P_BringUpWeapon(player);
  525. }
  526. //---------------------------------------------------------------------------
  527. //
  528. // PROC A_Raise
  529. //
  530. //---------------------------------------------------------------------------
  531. void A_Raise(player_t *player, pspdef_t *psp)
  532. {
  533. psp->sy -= RAISESPEED;
  534. if(psp->sy > WEAPONTOP)
  535. { // Not raised all the way yet
  536. return;
  537. }
  538. psp->sy = WEAPONTOP;
  539. if(player->class == PCLASS_FIGHTER && player->readyweapon == WP_SECOND
  540. && player->mana[MANA_1])
  541. {
  542. P_SetPsprite(player, ps_weapon, S_FAXEREADY_G);
  543. }
  544. else
  545. {
  546. P_SetPsprite(player, ps_weapon,
  547. WeaponInfo[player->readyweapon][player->class].readystate);
  548. }
  549. }
  550. /*
  551. ===============
  552. =
  553. = P_BulletSlope
  554. =
  555. = Sets a slope so a near miss is at aproximately the height of the
  556. = intended target
  557. =
  558. ===============
  559. */
  560. /*
  561. void P_BulletSlope (mobj_t *mo)
  562. {
  563. angle_t an;
  564. //
  565. // see which target is to be aimed at
  566. //
  567. an = mo->angle;
  568. bulletslope = P_AimLineAttack (mo, an, 16*64*FRACUNIT);
  569. if (!linetarget)
  570. {
  571. an += 1<<26;
  572. bulletslope = P_AimLineAttack (mo, an, 16*64*FRACUNIT);
  573. if (!linetarget)
  574. {
  575. an -= 2<<26;
  576. bulletslope = P_AimLineAttack (mo, an, 16*64*FRACUNIT);
  577. }
  578. if (!linetarget)
  579. {
  580. an += 1<<26;
  581. bulletslope = (mo->player->lookdir<<FRACBITS)/173;
  582. }
  583. }
  584. }
  585. */
  586. //****************************************************************************
  587. //
  588. // WEAPON ATTACKS
  589. //
  590. //****************************************************************************
  591. //============================================================================
  592. //
  593. // AdjustPlayerAngle
  594. //
  595. //============================================================================
  596. #define MAX_ANGLE_ADJUST (5*ANGLE_1)
  597. void AdjustPlayerAngle(mobj_t *pmo)
  598. {
  599. angle_t angle;
  600. int difference;
  601. angle = R_PointToAngle2(pmo->x, pmo->y, linetarget->x, linetarget->y);
  602. difference = (int)angle-(int)pmo->angle;
  603. if(abs(difference) > MAX_ANGLE_ADJUST)
  604. {
  605. pmo->angle += difference > 0 ? MAX_ANGLE_ADJUST : -MAX_ANGLE_ADJUST;
  606. }
  607. else
  608. {
  609. pmo->angle = angle;
  610. }
  611. }
  612. //============================================================================
  613. //
  614. // A_SnoutAttack
  615. //
  616. //============================================================================
  617. void A_SnoutAttack(player_t *player, pspdef_t *psp)
  618. {
  619. angle_t angle;
  620. int damage;
  621. int slope;
  622. damage = 3+(P_Random()&3);
  623. angle = player->mo->angle;
  624. slope = P_AimLineAttack(player->mo, angle, MELEERANGE);
  625. PuffType = MT_SNOUTPUFF;
  626. PuffSpawned = NULL;
  627. P_LineAttack(player->mo, angle, MELEERANGE, slope, damage);
  628. S_StartSound(player->mo, SFX_PIG_ACTIVE1+(P_Random()&1));
  629. if(linetarget)
  630. {
  631. AdjustPlayerAngle(player->mo);
  632. // player->mo->angle = R_PointToAngle2(player->mo->x,
  633. // player->mo->y, linetarget->x, linetarget->y);
  634. if(PuffSpawned)
  635. { // Bit something
  636. S_StartSound(player->mo, SFX_PIG_ATTACK);
  637. }
  638. }
  639. }
  640. //============================================================================
  641. //
  642. // A_FHammerAttack
  643. //
  644. //============================================================================
  645. #define HAMMER_RANGE (MELEERANGE+MELEERANGE/2)
  646. void A_FHammerAttack(player_t *player, pspdef_t *psp)
  647. {
  648. angle_t angle;
  649. mobj_t *pmo=player->mo;
  650. int damage;
  651. fixed_t power;
  652. int slope;
  653. int i;
  654. damage = 60+(P_Random()&63);
  655. power = 10*FRACUNIT;
  656. PuffType = MT_HAMMERPUFF;
  657. for(i = 0; i < 16; i++)
  658. {
  659. angle = pmo->angle+i*(ANG45/32);
  660. slope = P_AimLineAttack(pmo, angle, HAMMER_RANGE);
  661. if(linetarget)
  662. {
  663. P_LineAttack(pmo, angle, HAMMER_RANGE, slope, damage);
  664. AdjustPlayerAngle(pmo);
  665. if (linetarget->flags&MF_COUNTKILL || linetarget->player)
  666. {
  667. P_ThrustMobj(linetarget, angle, power);
  668. }
  669. pmo->special1 = false; // Don't throw a hammer
  670. goto hammerdone;
  671. }
  672. angle = pmo->angle-i*(ANG45/32);
  673. slope = P_AimLineAttack(pmo, angle, HAMMER_RANGE);
  674. if(linetarget)
  675. {
  676. P_LineAttack(pmo, angle, HAMMER_RANGE, slope, damage);
  677. AdjustPlayerAngle(pmo);
  678. if (linetarget->flags&MF_COUNTKILL || linetarget->player)
  679. {
  680. P_ThrustMobj(linetarget, angle, power);
  681. }
  682. pmo->special1 = false; // Don't throw a hammer
  683. goto hammerdone;
  684. }
  685. }
  686. // didn't find any targets in meleerange, so set to throw out a hammer
  687. PuffSpawned = NULL;
  688. angle = pmo->angle;
  689. slope = P_AimLineAttack(pmo, angle, HAMMER_RANGE);
  690. P_LineAttack(pmo, angle, HAMMER_RANGE, slope, damage);
  691. if(PuffSpawned)
  692. {
  693. pmo->special1 = false;
  694. }
  695. else
  696. {
  697. pmo->special1 = true;
  698. }
  699. hammerdone:
  700. if(player->mana[MANA_2] <
  701. WeaponManaUse[player->class][player->readyweapon])
  702. { // Don't spawn a hammer if the player doesn't have enough mana
  703. pmo->special1 = false;
  704. }
  705. return;
  706. }
  707. //============================================================================
  708. //
  709. // A_FHammerThrow
  710. //
  711. //============================================================================
  712. void A_FHammerThrow(player_t *player, pspdef_t *psp)
  713. {
  714. mobj_t *mo;
  715. if(!player->mo->special1)
  716. {
  717. return;
  718. }
  719. player->mana[MANA_2] -= WeaponManaUse[player->class][player->readyweapon];
  720. mo = P_SpawnPlayerMissile(player->mo, MT_HAMMER_MISSILE);
  721. if(mo)
  722. {
  723. mo->special1 = 0;
  724. }
  725. }
  726. //============================================================================
  727. //
  728. // A_FSwordAttack
  729. //
  730. //============================================================================
  731. void A_FSwordAttack(player_t *player, pspdef_t *psp)
  732. {
  733. mobj_t *pmo;
  734. player->mana[MANA_1] -= WeaponManaUse[player->class][player->readyweapon];
  735. player->mana[MANA_2] -= WeaponManaUse[player->class][player->readyweapon];
  736. pmo = player->mo;
  737. P_SPMAngleXYZ(pmo, pmo->x, pmo->y, pmo->z-10*FRACUNIT, MT_FSWORD_MISSILE,
  738. pmo->angle+ANG45/4);
  739. P_SPMAngleXYZ(pmo, pmo->x, pmo->y, pmo->z-5*FRACUNIT, MT_FSWORD_MISSILE,
  740. pmo->angle+ANG45/8);
  741. P_SPMAngleXYZ(pmo, pmo->x, pmo->y, pmo->z, MT_FSWORD_MISSILE, pmo->angle);
  742. P_SPMAngleXYZ(pmo, pmo->x, pmo->y, pmo->z+5*FRACUNIT, MT_FSWORD_MISSILE,
  743. pmo->angle-ANG45/8);
  744. P_SPMAngleXYZ(pmo, pmo->x, pmo->y, pmo->z+10*FRACUNIT, MT_FSWORD_MISSILE,
  745. pmo->angle-ANG45/4);
  746. S_StartSound(pmo, SFX_FIGHTER_SWORD_FIRE);
  747. }
  748. //============================================================================
  749. //
  750. // A_FSwordAttack2
  751. //
  752. //============================================================================
  753. void A_FSwordAttack2(mobj_t *actor)
  754. {
  755. angle_t angle = actor->angle;
  756. P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE,angle+ANG45/4, 0);
  757. P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE,angle+ANG45/8, 0);
  758. P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE,angle, 0);
  759. P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE,angle-ANG45/8, 0);
  760. P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE,angle-ANG45/4, 0);
  761. S_StartSound(actor, SFX_FIGHTER_SWORD_FIRE);
  762. }
  763. //============================================================================
  764. //
  765. // A_FSwordFlames
  766. //
  767. //============================================================================
  768. void A_FSwordFlames(mobj_t *actor)
  769. {
  770. int i;
  771. for(i = 1+(P_Random()&3); i; i--)
  772. {
  773. P_SpawnMobj(actor->x+((P_Random()-128)<<12), actor->y
  774. +((P_Random()-128)<<12), actor->z+((P_Random()-128)<<11),
  775. MT_FSWORD_FLAME);
  776. }
  777. }
  778. //============================================================================
  779. //
  780. // A_MWandAttack
  781. //
  782. //============================================================================
  783. void A_MWandAttack(player_t *player, pspdef_t *psp)
  784. {
  785. mobj_t *mo;
  786. mo = P_SpawnPlayerMissile(player->mo, MT_MWAND_MISSILE);
  787. if(mo)
  788. {
  789. mo->thinker.function = P_BlasterMobjThinker;
  790. }
  791. S_StartSound(player->mo, SFX_MAGE_WAND_FIRE);
  792. }
  793. // ===== Mage Lightning Weapon =====
  794. //============================================================================
  795. //
  796. // A_LightningReady
  797. //
  798. //============================================================================
  799. void A_LightningReady(player_t *player, pspdef_t *psp)
  800. {
  801. A_WeaponReady(player, psp);
  802. if(P_Random() < 160)
  803. {
  804. S_StartSound(player->mo, SFX_MAGE_LIGHTNING_READY);
  805. }
  806. }
  807. //============================================================================
  808. //
  809. // A_LightningClip
  810. //
  811. //============================================================================
  812. #define ZAGSPEED FRACUNIT
  813. void A_LightningClip(mobj_t *actor)
  814. {
  815. mobj_t *cMo;
  816. mobj_t *target;
  817. int zigZag;
  818. if(actor->type == MT_LIGHTNING_FLOOR)
  819. {
  820. actor->z = actor->floorz;
  821. target = (mobj_t *)((mobj_t *)actor->special2)->special1;
  822. }
  823. else if(actor->type == MT_LIGHTNING_CEILING)
  824. {
  825. actor->z = actor->ceilingz-actor->height;
  826. target = (mobj_t *)actor->special1;
  827. }
  828. if(actor->type == MT_LIGHTNING_FLOOR)
  829. { // floor lightning zig-zags, and forces the ceiling lightning to mimic
  830. cMo = (mobj_t *)actor->special2;
  831. zigZag = P_Random();
  832. if((zigZag > 128 && actor->special1 < 2) || actor->special1 < -2)
  833. {
  834. P_ThrustMobj(actor, actor->angle+ANG90, ZAGSPEED);
  835. if(cMo)
  836. {
  837. P_ThrustMobj(cMo, actor->angle+ANG90, ZAGSPEED);
  838. }
  839. actor->special1++;
  840. }
  841. else
  842. {
  843. P_ThrustMobj(actor, actor->angle-ANG90, ZAGSPEED);
  844. if(cMo)
  845. {
  846. P_ThrustMobj(cMo, cMo->angle-ANG90, ZAGSPEED);
  847. }
  848. actor->special1--;
  849. }
  850. }
  851. if(target)
  852. {
  853. if(target->health <= 0)
  854. {
  855. P_ExplodeMissile(actor);
  856. }
  857. else
  858. {
  859. actor->angle = R_PointToAngle2(actor->x, actor->y, target->x,
  860. target->y);
  861. actor->momx = 0;
  862. actor->momy = 0;
  863. P_ThrustMobj(actor, actor->angle, actor->info->speed>>1);
  864. }
  865. }
  866. }
  867. //============================================================================
  868. //
  869. // A_LightningZap
  870. //
  871. //============================================================================
  872. void A_LightningZap(mobj_t *actor)
  873. {
  874. mobj_t *mo;
  875. fixed_t deltaZ;
  876. A_LightningClip(actor);
  877. actor->health -= 8;
  878. if(actor->health <= 0)
  879. {
  880. P_SetMobjState(actor, actor->info->deathstate);
  881. return;
  882. }
  883. if(actor->type == MT_LIGHTNING_FLOOR)
  884. {
  885. deltaZ = 10*FRACUNIT;
  886. }
  887. else
  888. {
  889. deltaZ = -10*FRACUNIT;
  890. }
  891. mo = P_SpawnMobj(actor->x+((P_Random()-128)*actor->radius/256),
  892. actor->y+((P_Random()-128)*actor->radius/256),
  893. actor->z+deltaZ, MT_LIGHTNING_ZAP);
  894. if(mo)
  895. {
  896. mo->special2 = (int)actor;
  897. mo->momx = actor->momx;
  898. mo->momy = actor->momy;
  899. mo->target = actor->target;
  900. if(actor->type == MT_LIGHTNING_FLOOR)
  901. {
  902. mo->momz = 20*FRACUNIT;
  903. }
  904. else
  905. {
  906. mo->momz = -20*FRACUNIT;
  907. }
  908. }
  909. /*
  910. mo = P_SpawnMobj(actor->x+((P_Random()-128)*actor->radius/256),
  911. actor->y+((P_Random()-128)*actor->radius/256),
  912. actor->z+deltaZ, MT_LIGHTNING_ZAP);
  913. if(mo)
  914. {
  915. mo->special2 = (int)actor;
  916. mo->momx = actor->momx;
  917. mo->momy = actor->momy;
  918. mo->target = actor->target;
  919. if(actor->type == MT_LIGHTNING_FLOOR)
  920. {
  921. mo->momz = 16*FRACUNIT;
  922. }
  923. else
  924. {
  925. mo->momz = -16*FRACUNIT;
  926. }
  927. }
  928. */
  929. if(actor->type == MT_LIGHTNING_FLOOR && P_Random() < 160)
  930. {
  931. S_StartSound(actor, SFX_MAGE_LIGHTNING_CONTINUOUS);
  932. }
  933. }
  934. //============================================================================
  935. //
  936. // A_MLightningAttack2
  937. //
  938. //============================================================================
  939. void A_MLightningAttack2(mobj_t *actor)
  940. {
  941. mobj_t *fmo, *cmo;
  942. fmo = P_SpawnPlayerMissile(actor, MT_LIGHTNING_FLOOR);
  943. cmo = P_SpawnPlayerMissile(actor, MT_LIGHTNING_CEILING);
  944. if(fmo)
  945. {
  946. fmo->special1 = 0;
  947. fmo->special2 = (int)cmo;
  948. A_LightningZap(fmo);
  949. }
  950. if(cmo)
  951. {
  952. cmo->special1 = 0; // mobj that it will track
  953. cmo->special2 = (int)fmo;
  954. A_LightningZap(cmo);
  955. }
  956. S_StartSound(actor, SFX_MAGE_LIGHTNING_FIRE);
  957. }
  958. //============================================================================
  959. //
  960. // A_MLightningAttack
  961. //
  962. //============================================================================
  963. void A_MLightningAttack(player_t *player, pspdef_t *psp)
  964. {
  965. A_MLightningAttack2(player->mo);
  966. player->mana[MANA_2] -= WeaponManaUse[player->class][player->readyweapon];
  967. }
  968. //============================================================================
  969. //
  970. // A_ZapMimic
  971. //
  972. //============================================================================
  973. void A_ZapMimic(mobj_t *actor)
  974. {
  975. mobj_t *mo;
  976. mo = (mobj_t *)actor->special2;
  977. if(mo)
  978. {
  979. if(mo->state >= &states[mo->info->deathstate]
  980. || mo->state == &states[S_FREETARGMOBJ])
  981. {
  982. P_ExplodeMissile(actor);
  983. }
  984. else
  985. {
  986. actor->momx = mo->momx;
  987. actor->momy = mo->momy;
  988. }
  989. }
  990. }
  991. //============================================================================
  992. //
  993. // A_LastZap
  994. //
  995. //============================================================================
  996. void A_LastZap(mobj_t *actor)
  997. {
  998. mobj_t *mo;
  999. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_LIGHTNING_ZAP);
  1000. if(mo)
  1001. {
  1002. P_SetMobjState(mo, S_LIGHTNING_ZAP_X1);
  1003. mo->momz = 40*FRACUNIT;
  1004. }
  1005. }
  1006. //============================================================================
  1007. //
  1008. // A_LightningRemove
  1009. //
  1010. //============================================================================
  1011. void A_LightningRemove(mobj_t *actor)
  1012. {
  1013. mobj_t *mo;
  1014. mo = (mobj_t *)actor->special2;
  1015. if(mo)
  1016. {
  1017. mo->special2 = 0;
  1018. P_ExplodeMissile(mo);
  1019. }
  1020. }
  1021. //============================================================================
  1022. //
  1023. // MStaffSpawn
  1024. //
  1025. //============================================================================
  1026. void MStaffSpawn(mobj_t *pmo, angle_t angle)
  1027. {
  1028. mobj_t *mo;
  1029. mo = P_SPMAngle(pmo, MT_MSTAFF_FX2, angle);
  1030. if (mo)
  1031. {
  1032. mo->target = pmo;
  1033. mo->special1 = (int)P_RoughMonsterSearch(mo, 10);
  1034. }
  1035. }
  1036. //============================================================================
  1037. //
  1038. // A_MStaffAttack
  1039. //
  1040. //============================================================================
  1041. void A_MStaffAttack(player_t *player, pspdef_t *psp)
  1042. {
  1043. angle_t angle;
  1044. mobj_t *pmo;
  1045. player->mana[MANA_1] -= WeaponManaUse[player->class][player->readyweapon];
  1046. player->mana[MANA_2] -= WeaponManaUse[player->class][player->readyweapon];
  1047. pmo = player->mo;
  1048. angle = pmo->angle;
  1049. MStaffSpawn(pmo, angle);
  1050. MStaffSpawn(pmo, angle-ANGLE_1*5);
  1051. MStaffSpawn(pmo, angle+ANGLE_1*5);
  1052. S_StartSound(player->mo, SFX_MAGE_STAFF_FIRE);
  1053. if(player == &players[consoleplayer])
  1054. {
  1055. player->damagecount = 0;
  1056. player->bonuscount = 0;
  1057. I_SetPalette((byte *)W_CacheLumpNum(W_GetNumForName("playpal"),
  1058. PU_CACHE)+STARTSCOURGEPAL*768);
  1059. }
  1060. }
  1061. //============================================================================
  1062. //
  1063. // A_MStaffPalette
  1064. //
  1065. //============================================================================
  1066. void A_MStaffPalette(player_t *player, pspdef_t *psp)
  1067. {
  1068. int pal;
  1069. if(player == &players[consoleplayer])
  1070. {
  1071. pal = STARTSCOURGEPAL+psp->state-(&states[S_MSTAFFATK_2]);
  1072. if(pal == STARTSCOURGEPAL+3)
  1073. { // reset back to original playpal
  1074. pal = 0;
  1075. }
  1076. I_SetPalette((byte *)W_CacheLumpNum(W_GetNumForName("playpal"),
  1077. PU_CACHE)+pal*768);
  1078. }
  1079. }
  1080. //============================================================================
  1081. //
  1082. // A_MStaffWeave
  1083. //
  1084. //============================================================================
  1085. void A_MStaffWeave(mobj_t *actor)
  1086. {
  1087. fixed_t newX, newY;
  1088. int weaveXY, weaveZ;
  1089. int angle;
  1090. weaveXY = actor->special2>>16;
  1091. weaveZ = actor->special2&0xFFFF;
  1092. angle = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  1093. newX = actor->x-FixedMul(finecosine[angle],
  1094. FloatBobOffsets[weaveXY]<<2);
  1095. newY = actor->y-FixedMul(finesine[angle],
  1096. FloatBobOffsets[weaveXY]<<2);
  1097. weaveXY = (weaveXY+6)&63;
  1098. newX += FixedMul(finecosine[angle],
  1099. FloatBobOffsets[weaveXY]<<2);
  1100. newY += FixedMul(finesine[angle],
  1101. FloatBobOffsets[weaveXY]<<2);
  1102. P_TryMove(actor, newX, newY);
  1103. actor->z -= FloatBobOffsets[weaveZ]<<1;
  1104. weaveZ = (weaveZ+3)&63;
  1105. actor->z += FloatBobOffsets[weaveZ]<<1;
  1106. if(actor->z <= actor->floorz)
  1107. {
  1108. actor->z = actor->floorz+FRACUNIT;
  1109. }
  1110. actor->special2 = weaveZ+(weaveXY<<16);
  1111. }
  1112. //============================================================================
  1113. //
  1114. // A_MStaffTrack
  1115. //
  1116. //============================================================================
  1117. void A_MStaffTrack(mobj_t *actor)
  1118. {
  1119. if ((actor->special1 == 0) && (P_Random()<50))
  1120. {
  1121. actor->special1 = (int)P_RoughMonsterSearch(actor, 10);
  1122. }
  1123. P_SeekerMissile(actor, ANGLE_1*2, ANGLE_1*10);
  1124. }
  1125. //============================================================================
  1126. //
  1127. // MStaffSpawn2 - for use by mage class boss
  1128. //
  1129. //============================================================================
  1130. void MStaffSpawn2(mobj_t *actor, angle_t angle)
  1131. {
  1132. mobj_t *mo;
  1133. mo = P_SpawnMissileAngle(actor, MT_MSTAFF_FX2, angle, 0);
  1134. if (mo)
  1135. {
  1136. mo->target = actor;
  1137. mo->special1 = (int)P_RoughMonsterSearch(mo, 10);
  1138. }
  1139. }
  1140. //============================================================================
  1141. //
  1142. // A_MStaffAttack2 - for use by mage class boss
  1143. //
  1144. //============================================================================
  1145. void A_MStaffAttack2(mobj_t *actor)
  1146. {
  1147. angle_t angle;
  1148. angle = actor->angle;
  1149. MStaffSpawn2(actor, angle);
  1150. MStaffSpawn2(actor, angle-ANGLE_1*5);
  1151. MStaffSpawn2(actor, angle+ANGLE_1*5);
  1152. S_StartSound(actor, SFX_MAGE_STAFF_FIRE);
  1153. }
  1154. //============================================================================
  1155. //
  1156. // A_FPunchAttack
  1157. //
  1158. //============================================================================
  1159. void A_FPunchAttack(player_t *player, pspdef_t *psp)
  1160. {
  1161. angle_t angle;
  1162. int damage;
  1163. int slope;
  1164. mobj_t *pmo = player->mo;
  1165. fixed_t power;
  1166. int i;
  1167. damage = 40+(P_Random()&15);
  1168. power = 2*FRACUNIT;
  1169. PuffType = MT_PUNCHPUFF;
  1170. for(i = 0; i < 16; i++)
  1171. {
  1172. angle = pmo->angle+i*(ANG45/16);
  1173. slope = P_AimLineAttack(pmo, angle, 2*MELEERANGE);
  1174. if(linetarget)
  1175. {
  1176. player->mo->special1++;
  1177. if(pmo->special1 == 3)
  1178. {
  1179. damage <<= 1;
  1180. power = 6*FRACUNIT;
  1181. PuffType = MT_HAMMERPUFF;
  1182. }
  1183. P_LineAttack(pmo, angle, 2*MELEERANGE, slope, damage);
  1184. if (linetarget->flags&MF_COUNTKILL || linetarget->player)
  1185. {
  1186. P_ThrustMobj(linetarget, angle, power);
  1187. }
  1188. AdjustPlayerAngle(pmo);
  1189. goto punchdone;
  1190. }
  1191. angle = pmo->angle-i*(ANG45/16);
  1192. slope = P_AimLineAttack(pmo, angle, 2*MELEERANGE);
  1193. if(linetarget)
  1194. {
  1195. pmo->special1++;
  1196. if(pmo->special1 == 3)
  1197. {
  1198. damage <<= 1;
  1199. power = 6*FRACUNIT;
  1200. PuffType = MT_HAMMERPUFF;
  1201. }
  1202. P_LineAttack(pmo, angle, 2*MELEERANGE, slope, damage);
  1203. if (linetarget->flags&MF_COUNTKILL || linetarget->player)
  1204. {
  1205. P_ThrustMobj(linetarget, angle, power);
  1206. }
  1207. AdjustPlayerAngle(pmo);
  1208. goto punchdone;
  1209. }
  1210. }
  1211. // didn't find any creatures, so try to strike any walls
  1212. pmo->special1 = 0;
  1213. angle = pmo->angle;
  1214. slope = P_AimLineAttack(pmo, angle, MELEERANGE);
  1215. P_LineAttack(pmo, angle, MELEERANGE, slope, damage);
  1216. punchdone:
  1217. if(pmo->special1 == 3)
  1218. {
  1219. pmo->special1 = 0;
  1220. P_SetPsprite(player, ps_weapon, S_PUNCHATK2_1);
  1221. S_StartSound(pmo, SFX_FIGHTER_GRUNT);
  1222. }
  1223. return;
  1224. }
  1225. //============================================================================
  1226. //
  1227. // A_FAxeAttack
  1228. //
  1229. //============================================================================
  1230. #define AXERANGE 2.25*MELEERANGE
  1231. void A_FAxeAttack(player_t *player, pspdef_t *psp)
  1232. {
  1233. angle_t angle;
  1234. mobj_t *pmo=player->mo;
  1235. fixed_t power;
  1236. int damage;
  1237. int slope;
  1238. int i;
  1239. int useMana;
  1240. damage = 40+(P_Random()&15)+(P_Random()&7);
  1241. power = 0;
  1242. if(player->mana[MANA_1] > 0)
  1243. {
  1244. damage <<= 1;
  1245. power = 6*FRACUNIT;
  1246. PuffType = MT_AXEPUFF_GLOW;
  1247. useMana = 1;
  1248. }
  1249. else
  1250. {
  1251. PuffType = MT_AXEPUFF;
  1252. useMana = 0;
  1253. }
  1254. for(i = 0; i < 16; i++)
  1255. {
  1256. angle = pmo->angle+i*(ANG45/16);
  1257. slope = P_AimLineAttack(pmo, angle, AXERANGE);
  1258. if(linetarget)
  1259. {
  1260. P_LineAttack(pmo, angle, AXERANGE, slope, damage);
  1261. if (linetarget->flags&MF_COUNTKILL || linetarget->player)
  1262. {
  1263. P_ThrustMobj(linetarget, angle, power);
  1264. }
  1265. AdjustPlayerAngle(pmo);
  1266. useMana++;
  1267. goto axedone;
  1268. }
  1269. angle = pmo->angle-i*(ANG45/16);
  1270. slope = P_AimLineAttack(pmo, angle, AXERANGE);
  1271. if(linetarget)
  1272. {
  1273. P_LineAttack(pmo, angle, AXERANGE, slope, damage);
  1274. if (linetarget->flags&MF_COUNTKILL)
  1275. {
  1276. P_ThrustMobj(linetarget, angle, power);
  1277. }
  1278. AdjustPlayerAngle(pmo);
  1279. useMana++;
  1280. goto axedone;
  1281. }
  1282. }
  1283. // didn't find any creatures, so try to strike any walls
  1284. pmo->special1 = 0;
  1285. angle = pmo->angle;
  1286. slope = P_AimLineAttack(pmo, angle, MELEERANGE);
  1287. P_LineAttack(pmo, angle, MELEERANGE, slope, damage);
  1288. axedone:
  1289. if(useMana == 2)
  1290. {
  1291. player->mana[MANA_1] -=
  1292. WeaponManaUse[player->class][player->readyweapon];
  1293. if(player->mana[MANA_1] <= 0)
  1294. {
  1295. P_SetPsprite(player, ps_weapon, S_FAXEATK_5);
  1296. }
  1297. }
  1298. return;
  1299. }
  1300. //===========================================================================
  1301. //
  1302. // A_CMaceAttack
  1303. //
  1304. //===========================================================================
  1305. void A_CMaceAttack(player_t *player, pspdef_t *psp)
  1306. {
  1307. angle_t angle;
  1308. int damage;
  1309. int slope;
  1310. int i;
  1311. damage = 25+(P_Random()&15);
  1312. PuffType = MT_HAMMERPUFF;
  1313. for(i = 0; i < 16; i++)
  1314. {
  1315. angle = player->mo->angle+i*(ANG45/16);
  1316. slope = P_AimLineAttack(player->mo, angle, 2*MELEERANGE);
  1317. if(linetarget)
  1318. {
  1319. P_LineAttack(player->mo, angle, 2*MELEERANGE, slope,
  1320. damage);
  1321. AdjustPlayerAngle(player->mo);
  1322. // player->mo->angle = R_PointToAngle2(player->mo->x,
  1323. // player->mo->y, linetarget->x, linetarget->y);
  1324. goto macedone;
  1325. }
  1326. angle = player->mo->angle-i*(ANG45/16);
  1327. slope = P_AimLineAttack(player->mo, angle, 2*MELEERANGE);
  1328. if(linetarget)
  1329. {
  1330. P_LineAttack(player->mo, angle, 2*MELEERANGE, slope,
  1331. damage);
  1332. AdjustPlayerAngle(player->mo);
  1333. // player->mo->angle = R_PointToAngle2(player->mo->x,
  1334. // player->mo->y, linetarget->x, linetarget->y);
  1335. goto macedone;
  1336. }
  1337. }
  1338. // didn't find any creatures, so try to strike any walls
  1339. player->mo->special1 = 0;
  1340. angle = player->mo->angle;
  1341. slope = P_AimLineAttack(player->mo, angle, MELEERANGE);
  1342. P_LineAttack(player->mo, angle, MELEERANGE, slope,
  1343. damage);
  1344. macedone:
  1345. return;
  1346. }
  1347. //============================================================================
  1348. //
  1349. // A_CStaffCheck
  1350. //
  1351. //============================================================================
  1352. void A_CStaffCheck(player_t *player, pspdef_t *psp)
  1353. {
  1354. mobj_t *pmo;
  1355. int damage;
  1356. int newLife;
  1357. angle_t angle;
  1358. int slope;
  1359. int i;
  1360. pmo = player->mo;
  1361. damage = 20+(P_Random()&15);
  1362. PuffType = MT_CSTAFFPUFF;
  1363. for(i = 0; i < 3; i++)
  1364. {
  1365. angle = pmo->angle+i*(ANG45/16);
  1366. slope = P_AimLineAttack(pmo, angle, 1.5*MELEERANGE);
  1367. if(linetarget)
  1368. {
  1369. P_LineAttack(pmo, angle, 1.5*MELEERANGE, slope, damage);
  1370. pmo->angle = R_PointToAngle2(pmo->x, pmo->y,
  1371. linetarget->x, linetarget->y);
  1372. if((linetarget->player || linetarget->flags&MF_COUNTKILL)
  1373. && (!(linetarget->flags2&(MF2_DORMANT+MF2_INVULNERABLE))))
  1374. {
  1375. newLife = player->health+(damage>>3);
  1376. newLife = newLife > 100 ? 100 : newLife;
  1377. pmo->health = player->health = newLife;
  1378. P_SetPsprite(player, ps_weapon, S_CSTAFFATK2_1);
  1379. }
  1380. player->mana[MANA_1] -=
  1381. WeaponManaUse[player->class][player->readyweapon];
  1382. break;
  1383. }
  1384. angle = pmo->angle-i*(ANG45/16);
  1385. slope = P_AimLineAttack(player->mo, angle, 1.5*MELEERANGE);
  1386. if(linetarget)
  1387. {
  1388. P_LineAttack(pmo, angle, 1.5*MELEERANGE, slope, damage);
  1389. pmo->angle = R_PointToAngle2(pmo->x, pmo->y,
  1390. linetarget->x, linetarget->y);
  1391. if(linetarget->player || linetarget->flags&MF_COUNTKILL)
  1392. {
  1393. newLife = player->health+(damage>>4);
  1394. newLife = newLife > 100 ? 100 : newLife;
  1395. pmo->health = player->health = newLife;
  1396. P_SetPsprite(player, ps_weapon, S_CSTAFFATK2_1);
  1397. }
  1398. player->mana[MANA_1] -=
  1399. WeaponManaUse[player->class][player->readyweapon];
  1400. break;
  1401. }
  1402. }
  1403. }
  1404. //============================================================================
  1405. //
  1406. // A_CStaffAttack
  1407. //
  1408. //============================================================================
  1409. void A_CStaffAttack(player_t *player, pspdef_t *psp)
  1410. {
  1411. mobj_t *mo;
  1412. mobj_t *pmo;
  1413. player->mana[MANA_1] -= WeaponManaUse[player->class][player->readyweapon];
  1414. pmo = player->mo;
  1415. mo = P_SPMAngle(pmo, MT_CSTAFF_MISSILE, pmo->angle-(ANG45/15));
  1416. if(mo)
  1417. {
  1418. mo->special2 = 32;
  1419. }
  1420. mo = P_SPMAngle(pmo, MT_CSTAFF_MISSILE, pmo->angle+(ANG45/15));
  1421. if(mo)
  1422. {
  1423. mo->special2 = 0;
  1424. }
  1425. S_StartSound(player->mo, SFX_CLERIC_CSTAFF_FIRE);
  1426. }
  1427. //============================================================================
  1428. //
  1429. // A_CStaffMissileSlither
  1430. //
  1431. //============================================================================
  1432. void A_CStaffMissileSlither(mobj_t *actor)
  1433. {
  1434. fixed_t newX, newY;
  1435. int weaveXY;
  1436. int angle;
  1437. weaveXY = actor->special2;
  1438. angle = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  1439. newX = actor->x-FixedMul(finecosine[angle],
  1440. FloatBobOffsets[weaveXY]);
  1441. newY = actor->y-FixedMul(finesine[angle],
  1442. FloatBobOffsets[weaveXY]);
  1443. weaveXY = (weaveXY+3)&63;
  1444. newX += FixedMul(finecosine[angle],
  1445. FloatBobOffsets[weaveXY]);
  1446. newY += FixedMul(finesine[angle],
  1447. FloatBobOffsets[weaveXY]);
  1448. P_TryMove(actor, newX, newY);
  1449. actor->special2 = weaveXY;
  1450. }
  1451. //============================================================================
  1452. //
  1453. // A_CStaffInitBlink
  1454. //
  1455. //============================================================================
  1456. void A_CStaffInitBlink(player_t *player, pspdef_t *psp)
  1457. {
  1458. player->mo->special1 = (P_Random()>>1)+20;
  1459. }
  1460. //============================================================================
  1461. //
  1462. // A_CStaffCheckBlink
  1463. //
  1464. //============================================================================
  1465. void A_CStaffCheckBlink(player_t *player, pspdef_t *psp)
  1466. {
  1467. if(!--player->mo->special1)
  1468. {
  1469. P_SetPsprite(player, ps_weapon, S_CSTAFFBLINK1);
  1470. player->mo->special1 = (P_Random()+50)>>2;
  1471. }
  1472. }
  1473. //============================================================================
  1474. //
  1475. // A_CFlameAttack
  1476. //
  1477. //============================================================================
  1478. #define FLAMESPEED (0.45*FRACUNIT)
  1479. #define CFLAMERANGE (12*64*FRACUNIT)
  1480. void A_CFlameAttack(player_t *player, pspdef_t *psp)
  1481. {
  1482. mobj_t *mo;
  1483. mo = P_SpawnPlayerMissile(player->mo, MT_CFLAME_MISSILE);
  1484. if(mo)
  1485. {
  1486. mo->thinker.function = P_BlasterMobjThinker;
  1487. mo->special1 = 2;
  1488. }
  1489. player->mana[MANA_2] -= WeaponManaUse[player->class][player->readyweapon];
  1490. S_StartSound(player->mo, SFX_CLERIC_FLAME_FIRE);
  1491. }
  1492. //============================================================================
  1493. //
  1494. // A_CFlamePuff
  1495. //
  1496. //============================================================================
  1497. void A_CFlamePuff(mobj_t *actor)
  1498. {
  1499. A_UnHideThing(actor);
  1500. actor->momx = 0;
  1501. actor->momy = 0;
  1502. actor->momz = 0;
  1503. S_StartSound(actor, SFX_CLERIC_FLAME_EXPLODE);
  1504. }
  1505. //============================================================================
  1506. //
  1507. // A_CFlameMissile
  1508. //
  1509. //============================================================================
  1510. void A_CFlameMissile(mobj_t *actor)
  1511. {
  1512. int i;
  1513. int an, an90;
  1514. fixed_t dist;
  1515. mobj_t *mo;
  1516. A_UnHideThing(actor);
  1517. S_StartSound(actor, SFX_CLERIC_FLAME_EXPLODE);
  1518. if(BlockingMobj && BlockingMobj->flags&MF_SHOOTABLE)
  1519. { // Hit something, so spawn the flame circle around the thing
  1520. dist = BlockingMobj->radius+18*FRACUNIT;
  1521. for(i = 0; i < 4; i++)
  1522. {
  1523. an = (i*ANG45)>>ANGLETOFINESHIFT;
  1524. an90 = (i*ANG45+ANG90)>>ANGLETOFINESHIFT;
  1525. mo = P_SpawnMobj(BlockingMobj->x+FixedMul(dist, finecosine[an]),
  1526. BlockingMobj->y+FixedMul(dist, finesine[an]),
  1527. BlockingMobj->z+5*FRACUNIT, MT_CIRCLEFLAME);
  1528. if(mo)
  1529. {
  1530. mo->angle = an<<ANGLETOFINESHIFT;
  1531. mo->target = actor->target;
  1532. mo->momx = mo->special1 = FixedMul(FLAMESPEED, finecosine[an]);
  1533. mo->momy = mo->special2 = FixedMul(FLAMESPEED, finesine[an]);
  1534. mo->tics -= P_Random()&3;
  1535. }
  1536. mo = P_SpawnMobj(BlockingMobj->x-FixedMul(dist, finecosine[an]),
  1537. BlockingMobj->y-FixedMul(dist, finesine[an]),
  1538. BlockingMobj->z+5*FRACUNIT, MT_CIRCLEFLAME);
  1539. if(mo)
  1540. {
  1541. mo->angle = ANG180+(an<<ANGLETOFINESHIFT);
  1542. mo->target = actor->target;
  1543. mo->momx = mo->special1 = FixedMul(-FLAMESPEED,
  1544. finecosine[an]);
  1545. mo->momy = mo->special2 = FixedMul(-FLAMESPEED, finesine[an]);
  1546. mo->tics -= P_Random()&3;
  1547. }
  1548. }
  1549. P_SetMobjState(actor, S_FLAMEPUFF2_1);
  1550. }
  1551. }
  1552. /*
  1553. void A_CFlameAttack(player_t *player, pspdef_t *psp)
  1554. {
  1555. mobj_t *pmo;
  1556. angle_t angle;
  1557. int damage;
  1558. int i;
  1559. int an, an90;
  1560. fixed_t dist;
  1561. mobj_t *mo;
  1562. pmo = player->mo;
  1563. P_BulletSlope(pmo);
  1564. damage = 25+HITDICE(3);
  1565. angle = pmo->angle;
  1566. if(player->refire)
  1567. {
  1568. angle += (P_Random()-P_Random())<<17;
  1569. }
  1570. P_AimLineAttack(pmo, angle, CFLAMERANGE); // Correctly set linetarget
  1571. if(!linetarget)
  1572. {
  1573. angle += ANGLE_1*2;
  1574. P_AimLineAttack(pmo, angle, CFLAMERANGE);
  1575. if(!linetarget)
  1576. {
  1577. angle -= ANGLE_1*4;
  1578. P_AimLineAttack(pmo, angle, CFLAMERANGE);
  1579. if(!linetarget)
  1580. {
  1581. angle += ANGLE_1*2;
  1582. }
  1583. }
  1584. }
  1585. if(linetarget)
  1586. {
  1587. PuffType = MT_FLAMEPUFF2;
  1588. }
  1589. else
  1590. {
  1591. PuffType = MT_FLAMEPUFF;
  1592. }
  1593. P_LineAttack(pmo, angle, CFLAMERANGE, bulletslope, damage);
  1594. if(linetarget)
  1595. { // Hit something, so spawn the flame circle around the thing
  1596. dist = linetarget->radius+18*FRACUNIT;
  1597. for(i = 0; i < 4; i++)
  1598. {
  1599. an = (i*ANG45)>>ANGLETOFINESHIFT;
  1600. an90 = (i*ANG45+ANG90)>>ANGLETOFINESHIFT;
  1601. mo = P_SpawnMobj(linetarget->x+FixedMul(dist, finecosine[an]),
  1602. linetarget->y+FixedMul(dist, finesine[an]),
  1603. linetarget->z+5*FRACUNIT, MT_CIRCLEFLAME);
  1604. if(mo)
  1605. {
  1606. mo->angle = an<<ANGLETOFINESHIFT;
  1607. mo->target = pmo;
  1608. mo->momx = mo->special1 = FixedMul(FLAMESPEED, finecosine[an]);
  1609. mo->momy = mo->special2 = FixedMul(FLAMESPEED, finesine[an]);
  1610. mo->tics -= P_Random()&3;
  1611. }
  1612. mo = P_SpawnMobj(linetarget->x-FixedMul(dist, finecosine[an]),
  1613. linetarget->y-FixedMul(dist, finesine[an]),
  1614. linetarget->z+5*FRACUNIT, MT_CIRCLEFLAME);
  1615. if(mo)
  1616. {
  1617. mo->angle = ANG180+(an<<ANGLETOFINESHIFT);
  1618. mo->target = pmo;
  1619. mo->momx = mo->special1 = FixedMul(-FLAMESPEED,
  1620. finecosine[an]);
  1621. mo->momy = mo->special2 = FixedMul(-FLAMESPEED, finesine[an]);
  1622. mo->tics -= P_Random()&3;
  1623. }
  1624. }
  1625. }
  1626. // Create a line of flames from the player to the flame puff
  1627. CFlameCreateFlames(player->mo);
  1628. player->mana[MANA_2] -= WeaponManaUse[player->class][player->readyweapon];
  1629. S_StartSound(player->mo, SFX_CLERIC_FLAME_FIRE);
  1630. }
  1631. */
  1632. //============================================================================
  1633. //
  1634. // A_CFlameRotate
  1635. //
  1636. //============================================================================
  1637. #define FLAMEROTSPEED 2*FRACUNIT
  1638. void A_CFlameRotate(mobj_t *actor)
  1639. {
  1640. int an;
  1641. an = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  1642. actor->momx = actor->special1+FixedMul(FLAMEROTSPEED, finecosine[an]);
  1643. actor->momy = actor->special2+FixedMul(FLAMEROTSPEED, finesine[an]);
  1644. actor->angle += ANG90/15;
  1645. }
  1646. //============================================================================
  1647. //
  1648. // A_CHolyAttack3
  1649. //
  1650. // Spawns the spirits
  1651. //============================================================================
  1652. void A_CHolyAttack3(mobj_t *actor)
  1653. {
  1654. P_SpawnMissile(actor, actor->target, MT_HOLY_MISSILE);
  1655. S_StartSound(actor, SFX_CHOLY_FIRE);
  1656. }
  1657. //============================================================================
  1658. //
  1659. // A_CHolyAttack2
  1660. //
  1661. // Spawns the spirits
  1662. //============================================================================
  1663. void A_CHolyAttack2(mobj_t *actor)
  1664. {
  1665. int j;
  1666. int i;
  1667. mobj_t *mo;
  1668. mobj_t *tail, *next;
  1669. for(j = 0; j < 4; j++)
  1670. {
  1671. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_HOLY_FX);
  1672. if(!mo)
  1673. {
  1674. continue;
  1675. }
  1676. switch(j)
  1677. { // float bob index
  1678. case 0:
  1679. mo->special2 = P_Random()&7; // upper-left
  1680. break;
  1681. case 1:
  1682. mo->special2 = 32+(P_Random()&7); // upper-right
  1683. break;
  1684. case 2:
  1685. mo->special2 = (32+(P_Random()&7))<<16; // lower-left
  1686. break;
  1687. case 3:
  1688. mo->special2 = ((32+(P_Random()&7))<<16)+32+(P_Random()&7);
  1689. break;
  1690. }
  1691. mo->z = actor->z;
  1692. mo->angle = actor->angle+(ANGLE_45+ANGLE_45/2)-ANGLE_45*j;
  1693. P_ThrustMobj(mo, mo->angle, mo->info->speed);
  1694. mo->target = actor->target;
  1695. mo->args[0] = 10; // initial turn value
  1696. mo->args[1] = 0; // initial look angle
  1697. if(deathmatch)
  1698. { // Ghosts last slightly less longer in DeathMatch
  1699. mo->health = 85;
  1700. }
  1701. if(linetarget)
  1702. {
  1703. mo->special1 = (int)linetarget;
  1704. mo->flags |= MF_NOCLIP|MF_SKULLFLY;
  1705. mo->flags &= ~MF_MISSILE;
  1706. }
  1707. tail = P_SpawnMobj(mo->x, mo->y, mo->z, MT_HOLY_TAIL);
  1708. tail->special2 = (int)mo; // parent
  1709. for(i = 1; i < 3; i++)
  1710. {
  1711. next = P_SpawnMobj(mo->x, mo->y, mo->z, MT_HOLY_TAIL);
  1712. P_SetMobjState(next, next->info->spawnstate+1);
  1713. tail->special1 = (int)next;
  1714. tail = next;
  1715. }
  1716. tail->special1 = 0; // last tail bit
  1717. }
  1718. }
  1719. //============================================================================
  1720. //
  1721. // A_CHolyAttack
  1722. //
  1723. //============================================================================
  1724. void A_CHolyAttack(player_t *player, pspdef_t *psp)
  1725. {
  1726. mobj_t *mo;
  1727. player->mana[MANA_1] -= WeaponManaUse[player->class][player->readyweapon];
  1728. player->mana[MANA_2] -= WeaponManaUse[player->class][player->readyweapon];
  1729. mo = P_SpawnPlayerMissile(player->mo, MT_HOLY_MISSILE);
  1730. if(player == &players[consoleplayer])
  1731. {
  1732. player->damagecount = 0;
  1733. player->bonuscount = 0;
  1734. I_SetPalette((byte *)W_CacheLumpNum(W_GetNumForName("playpal"),
  1735. PU_CACHE)+STARTHOLYPAL*768);
  1736. }
  1737. S_StartSound(player->mo, SFX_CHOLY_FIRE);
  1738. }
  1739. //============================================================================
  1740. //
  1741. // A_CHolyPalette
  1742. //
  1743. //============================================================================
  1744. void A_CHolyPalette(player_t *player, pspdef_t *psp)
  1745. {
  1746. int pal;
  1747. if(player == &players[consoleplayer])
  1748. {
  1749. pal = STARTHOLYPAL+psp->state-(&states[S_CHOLYATK_6]);
  1750. if(pal == STARTHOLYPAL+3)
  1751. { // reset back to original playpal
  1752. pal = 0;
  1753. }
  1754. I_SetPalette((byte *)W_CacheLumpNum(W_GetNumForName("playpal"),
  1755. PU_CACHE)+pal*768);
  1756. }
  1757. }
  1758. //============================================================================
  1759. //
  1760. // CHolyFindTarget
  1761. //
  1762. //============================================================================
  1763. static void CHolyFindTarget(mobj_t *actor)
  1764. {
  1765. mobj_t *target;
  1766. if(target = P_RoughMonsterSearch(actor, 6))
  1767. {
  1768. actor->special1 = (int)target;
  1769. actor->flags |= MF_NOCLIP|MF_SKULLFLY;
  1770. actor->flags &= ~MF_MISSILE;
  1771. }
  1772. }
  1773. //============================================================================
  1774. //
  1775. // CHolySeekerMissile
  1776. //
  1777. // Similar to P_SeekerMissile, but seeks to a random Z on the target
  1778. //============================================================================
  1779. static void CHolySeekerMissile(mobj_t *actor, angle_t thresh, angle_t turnMax)
  1780. {
  1781. int dir;
  1782. int dist;
  1783. angle_t delta;
  1784. angle_t angle;
  1785. mobj_t *target;
  1786. fixed_t newZ;
  1787. fixed_t deltaZ;
  1788. target = (mobj_t *)actor->special1;
  1789. if(target == NULL)
  1790. {
  1791. return;
  1792. }
  1793. if(!(target->flags&MF_SHOOTABLE)
  1794. || (!(target->flags&MF_COUNTKILL) && !target->player))
  1795. { // Target died/target isn't a player or creature
  1796. actor->special1 = 0;
  1797. actor->flags &= ~(MF_NOCLIP|MF_SKULLFLY);
  1798. actor->flags |= MF_MISSILE;
  1799. CHolyFindTarget(actor);
  1800. return;
  1801. }
  1802. dir = P_FaceMobj(actor, target, &delta);
  1803. if(delta > thresh)
  1804. {
  1805. delta >>= 1;
  1806. if(delta > turnMax)
  1807. {
  1808. delta = turnMax;
  1809. }
  1810. }
  1811. if(dir)
  1812. { // Turn clockwise
  1813. actor->angle += delta;
  1814. }
  1815. else
  1816. { // Turn counter clockwise
  1817. actor->angle -= delta;
  1818. }
  1819. angle = actor->angle>>ANGLETOFINESHIFT;
  1820. actor->momx = FixedMul(actor->info->speed, finecosine[angle]);
  1821. actor->momy = FixedMul(actor->info->speed, finesine[angle]);
  1822. if(!(leveltime&15)
  1823. || actor->z > target->z+(target->height)
  1824. || actor->z+actor->height < target->z)
  1825. {
  1826. newZ = target->z+((P_Random()*target->height)>>8);
  1827. deltaZ = newZ-actor->z;
  1828. if(abs(deltaZ) > 15*FRACUNIT)
  1829. {
  1830. if(deltaZ > 0)
  1831. {
  1832. deltaZ = 15*FRACUNIT;
  1833. }
  1834. else
  1835. {
  1836. deltaZ = -15*FRACUNIT;
  1837. }
  1838. }
  1839. dist = P_AproxDistance(target->x-actor->x, target->y-actor->y);
  1840. dist = dist/actor->info->speed;
  1841. if(dist < 1)
  1842. {
  1843. dist = 1;
  1844. }
  1845. actor->momz = deltaZ/dist;
  1846. }
  1847. return;
  1848. }
  1849. //============================================================================
  1850. //
  1851. // A_CHolyWeave
  1852. //
  1853. //============================================================================
  1854. static void CHolyWeave(mobj_t *actor)
  1855. {
  1856. fixed_t newX, newY;
  1857. int weaveXY, weaveZ;
  1858. int angle;
  1859. weaveXY = actor->special2>>16;
  1860. weaveZ = actor->special2&0xFFFF;
  1861. angle = (actor->angle+ANG90)>>ANGLETOFINESHIFT;
  1862. newX = actor->x-FixedMul(finecosine[angle],
  1863. FloatBobOffsets[weaveXY]<<2);
  1864. newY = actor->y-FixedMul(finesine[angle],
  1865. FloatBobOffsets[weaveXY]<<2);
  1866. weaveXY = (weaveXY+(P_Random()%5))&63;
  1867. newX += FixedMul(finecosine[angle],
  1868. FloatBobOffsets[weaveXY]<<2);
  1869. newY += FixedMul(finesine[angle],
  1870. FloatBobOffsets[weaveXY]<<2);
  1871. P_TryMove(actor, newX, newY);
  1872. actor->z -= FloatBobOffsets[weaveZ]<<1;
  1873. weaveZ = (weaveZ+(P_Random()%5))&63;
  1874. actor->z += FloatBobOffsets[weaveZ]<<1;
  1875. actor->special2 = weaveZ+(weaveXY<<16);
  1876. }
  1877. //============================================================================
  1878. //
  1879. // A_CHolySeek
  1880. //
  1881. //============================================================================
  1882. void A_CHolySeek(mobj_t *actor)
  1883. {
  1884. actor->health--;
  1885. if(actor->health <= 0)
  1886. {
  1887. actor->momx >>= 2;
  1888. actor->momy >>= 2;
  1889. actor->momz = 0;
  1890. P_SetMobjState(actor, actor->info->deathstate);
  1891. actor->tics -= P_Random()&3;
  1892. return;
  1893. }
  1894. if(actor->special1)
  1895. {
  1896. CHolySeekerMissile(actor, actor->args[0]*ANGLE_1,
  1897. actor->args[0]*ANGLE_1*2);
  1898. if(!((leveltime+7)&15))
  1899. {
  1900. actor->args[0] = 5+(P_Random()/20);
  1901. }
  1902. }
  1903. CHolyWeave(actor);
  1904. }
  1905. //============================================================================
  1906. //
  1907. // CHolyTailFollow
  1908. //
  1909. //============================================================================
  1910. static void CHolyTailFollow(mobj_t *actor, fixed_t dist)
  1911. {
  1912. mobj_t *child;
  1913. int an;
  1914. fixed_t oldDistance, newDistance;
  1915. child = (mobj_t *)actor->special1;
  1916. if(child)
  1917. {
  1918. an = R_PointToAngle2(actor->x, actor->y, child->x,
  1919. child->y)>>ANGLETOFINESHIFT;
  1920. oldDistance = P_AproxDistance(child->x-actor->x, child->y-actor->y);
  1921. if(P_TryMove(child, actor->x+FixedMul(dist, finecosine[an]),
  1922. actor->y+FixedMul(dist, finesine[an])))
  1923. {
  1924. newDistance = P_AproxDistance(child->x-actor->x,
  1925. child->y-actor->y)-FRACUNIT;
  1926. if(oldDistance < FRACUNIT)
  1927. {
  1928. if(child->z < actor->z)
  1929. {
  1930. child->z = actor->z-dist;
  1931. }
  1932. else
  1933. {
  1934. child->z = actor->z+dist;
  1935. }
  1936. }
  1937. else
  1938. {
  1939. child->z = actor->z+FixedMul(FixedDiv(newDistance,
  1940. oldDistance), child->z-actor->z);
  1941. }
  1942. }
  1943. CHolyTailFollow(child, dist-FRACUNIT);
  1944. }
  1945. }
  1946. //============================================================================
  1947. //
  1948. // CHolyTailRemove
  1949. //
  1950. //============================================================================
  1951. static void CHolyTailRemove(mobj_t *actor)
  1952. {
  1953. mobj_t *child;
  1954. child = (mobj_t *)actor->special1;
  1955. if(child)
  1956. {
  1957. CHolyTailRemove(child);
  1958. }
  1959. P_RemoveMobj(actor);
  1960. }
  1961. //============================================================================
  1962. //
  1963. // A_CHolyTail
  1964. //
  1965. //============================================================================
  1966. void A_CHolyTail(mobj_t *actor)
  1967. {
  1968. mobj_t *parent;
  1969. parent = (mobj_t *)actor->special2;
  1970. if(parent)
  1971. {
  1972. if(parent->state >= &states[parent->info->deathstate])
  1973. { // Ghost removed, so remove all tail parts
  1974. CHolyTailRemove(actor);
  1975. return;
  1976. }
  1977. else if(P_TryMove(actor, parent->x-FixedMul(14*FRACUNIT,
  1978. finecosine[parent->angle>>ANGLETOFINESHIFT]),
  1979. parent->y-FixedMul(14*FRACUNIT,
  1980. finesine[parent->angle>>ANGLETOFINESHIFT])))
  1981. {
  1982. actor->z = parent->z-5*FRACUNIT;
  1983. }
  1984. CHolyTailFollow(actor, 10*FRACUNIT);
  1985. }
  1986. }
  1987. //============================================================================
  1988. //
  1989. // A_CHolyCheckScream
  1990. //
  1991. //============================================================================
  1992. void A_CHolyCheckScream(mobj_t *actor)
  1993. {
  1994. A_CHolySeek(actor);
  1995. if(P_Random() < 20)
  1996. {
  1997. S_StartSound(actor, SFX_SPIRIT_ACTIVE);
  1998. }
  1999. if(!actor->special1)
  2000. {
  2001. CHolyFindTarget(actor);
  2002. }
  2003. }
  2004. //============================================================================
  2005. //
  2006. // A_CHolySpawnPuff
  2007. //
  2008. //============================================================================
  2009. void A_CHolySpawnPuff(mobj_t *actor)
  2010. {
  2011. P_SpawnMobj(actor->x, actor->y, actor->z, MT_HOLY_MISSILE_PUFF);
  2012. }
  2013. //----------------------------------------------------------------------------
  2014. //
  2015. // PROC A_FireConePL1
  2016. //
  2017. //----------------------------------------------------------------------------
  2018. #define SHARDSPAWN_LEFT 1
  2019. #define SHARDSPAWN_RIGHT 2
  2020. #define SHARDSPAWN_UP 4
  2021. #define SHARDSPAWN_DOWN 8
  2022. void A_FireConePL1(player_t *player, pspdef_t *psp)
  2023. {
  2024. angle_t angle;
  2025. int damage;
  2026. int slope;
  2027. int i;
  2028. mobj_t *pmo,*mo;
  2029. int conedone=false;
  2030. pmo = player->mo;
  2031. player->mana[MANA_1] -= WeaponManaUse[player->class][player->readyweapon];
  2032. S_StartSound(pmo, SFX_MAGE_SHARDS_FIRE);
  2033. damage = 90+(P_Random()&15);
  2034. for(i = 0; i < 16; i++)
  2035. {
  2036. angle = pmo->angle+i*(ANG45/16);
  2037. slope = P_AimLineAttack(pmo, angle, MELEERANGE);
  2038. if(linetarget)
  2039. {
  2040. pmo->flags2 |= MF2_ICEDAMAGE;
  2041. P_DamageMobj(linetarget, pmo, pmo, damage);
  2042. pmo->flags2 &= ~MF2_ICEDAMAGE;
  2043. conedone = true;
  2044. break;
  2045. }
  2046. }
  2047. // didn't find any creatures, so fire projectiles
  2048. if (!conedone)
  2049. {
  2050. mo = P_SpawnPlayerMissile(pmo, MT_SHARDFX1);
  2051. if (mo)
  2052. {
  2053. mo->special1 = SHARDSPAWN_LEFT|SHARDSPAWN_DOWN|SHARDSPAWN_UP
  2054. |SHARDSPAWN_RIGHT;
  2055. mo->special2 = 3; // Set sperm count (levels of reproductivity)
  2056. mo->target = pmo;
  2057. mo->args[0] = 3; // Mark Initial shard as super damage
  2058. }
  2059. }
  2060. }
  2061. void A_ShedShard(mobj_t *actor)
  2062. {
  2063. mobj_t *mo;
  2064. int spawndir = actor->special1;
  2065. int spermcount = actor->special2;
  2066. if (spermcount <= 0) return; // No sperm left
  2067. actor->special2 = 0;
  2068. spermcount--;
  2069. // every so many calls, spawn a new missile in it's set directions
  2070. if (spawndir & SHARDSPAWN_LEFT)
  2071. {
  2072. mo=P_SpawnMissileAngleSpeed(actor, MT_SHARDFX1, actor->angle+(ANG45/9),
  2073. 0, (20+2*spermcount)<<FRACBITS);
  2074. if (mo)
  2075. {
  2076. mo->special1 = SHARDSPAWN_LEFT;
  2077. mo->special2 = spermcount;
  2078. mo->momz = actor->momz;
  2079. mo->target = actor->target;
  2080. mo->args[0] = (spermcount==3)?2:0;
  2081. }
  2082. }
  2083. if (spawndir & SHARDSPAWN_RIGHT)
  2084. {
  2085. mo=P_SpawnMissileAngleSpeed(actor, MT_SHARDFX1, actor->angle-(ANG45/9),
  2086. 0, (20+2*spermcount)<<FRACBITS);
  2087. if (mo)
  2088. {
  2089. mo->special1 = SHARDSPAWN_RIGHT;
  2090. mo->special2 = spermcount;
  2091. mo->momz = actor->momz;
  2092. mo->target = actor->target;
  2093. mo->args[0] = (spermcount==3)?2:0;
  2094. }
  2095. }
  2096. if (spawndir & SHARDSPAWN_UP)
  2097. {
  2098. mo=P_SpawnMissileAngleSpeed(actor, MT_SHARDFX1, actor->angle,
  2099. 0, (15+2*spermcount)<<FRACBITS);
  2100. if (mo)
  2101. {
  2102. mo->momz = actor->momz;
  2103. mo->z += 8*FRACUNIT;
  2104. if (spermcount & 1) // Every other reproduction
  2105. mo->special1 = SHARDSPAWN_UP | SHARDSPAWN_LEFT | SHARDSPAWN_RIGHT;
  2106. else
  2107. mo->special1 = SHARDSPAWN_UP;
  2108. mo->special2 = spermcount;
  2109. mo->target = actor->target;
  2110. mo->args[0] = (spermcount==3)?2:0;
  2111. }
  2112. }
  2113. if (spawndir & SHARDSPAWN_DOWN)
  2114. {
  2115. mo=P_SpawnMissileAngleSpeed(actor, MT_SHARDFX1, actor->angle,
  2116. 0, (15+2*spermcount)<<FRACBITS);
  2117. if (mo)
  2118. {
  2119. mo->momz = actor->momz;
  2120. mo->z -= 4*FRACUNIT;
  2121. if (spermcount & 1) // Every other reproduction
  2122. mo->special1 = SHARDSPAWN_DOWN | SHARDSPAWN_LEFT | SHARDSPAWN_RIGHT;
  2123. else
  2124. mo->special1 = SHARDSPAWN_DOWN;
  2125. mo->special2 = spermcount;
  2126. mo->target = actor->target;
  2127. mo->args[0] = (spermcount==3)?2:0;
  2128. }
  2129. }
  2130. }
  2131. //----------------------------------------------------------------------------
  2132. //
  2133. // PROC A_HideInCeiling
  2134. //
  2135. //----------------------------------------------------------------------------
  2136. /*
  2137. void A_HideInCeiling(mobj_t *actor)
  2138. {
  2139. actor->z = actor->ceilingz+4*FRACUNIT;
  2140. }
  2141. */
  2142. //----------------------------------------------------------------------------
  2143. //
  2144. // PROC A_FloatPuff
  2145. //
  2146. //----------------------------------------------------------------------------
  2147. /*
  2148. void A_FloatPuff(mobj_t *puff)
  2149. {
  2150. puff->momz += 1.8*FRACUNIT;
  2151. }
  2152. */
  2153. void A_Light0(player_t *player, pspdef_t *psp)
  2154. {
  2155. player->extralight = 0;
  2156. }
  2157. /*
  2158. void A_Light1(player_t *player, pspdef_t *psp)
  2159. {
  2160. player->extralight = 1;
  2161. }
  2162. */
  2163. /*
  2164. void A_Light2(player_t *player, pspdef_t *psp)
  2165. {
  2166. player->extralight = 2;
  2167. }
  2168. */
  2169. //------------------------------------------------------------------------
  2170. //
  2171. // PROC P_SetupPsprites
  2172. //
  2173. // Called at start of level for each player
  2174. //
  2175. //------------------------------------------------------------------------
  2176. void P_SetupPsprites(player_t *player)
  2177. {
  2178. int i;
  2179. // Remove all psprites
  2180. for(i = 0; i < NUMPSPRITES; i++)
  2181. {
  2182. player->psprites[i].state = NULL;
  2183. }
  2184. // Spawn the ready weapon
  2185. player->pendingweapon = player->readyweapon;
  2186. P_BringUpWeapon(player);
  2187. }
  2188. //------------------------------------------------------------------------
  2189. //
  2190. // PROC P_MovePsprites
  2191. //
  2192. // Called every tic by player thinking routine
  2193. //
  2194. //------------------------------------------------------------------------
  2195. void P_MovePsprites(player_t *player)
  2196. {
  2197. int i;
  2198. pspdef_t *psp;
  2199. state_t *state;
  2200. psp = &player->psprites[0];
  2201. for(i = 0; i < NUMPSPRITES; i++, psp++)
  2202. {
  2203. if((state = psp->state) != 0) // a null state means not active
  2204. {
  2205. // drop tic count and possibly change state
  2206. if(psp->tics != -1) // a -1 tic count never changes
  2207. {
  2208. psp->tics--;
  2209. if(!psp->tics)
  2210. {
  2211. P_SetPsprite(player, i, psp->state->nextstate);
  2212. }
  2213. }
  2214. }
  2215. }
  2216. player->psprites[ps_flash].sx = player->psprites[ps_weapon].sx;
  2217. player->psprites[ps_flash].sy = player->psprites[ps_weapon].sy;
  2218. }