A_ACTION.C 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. //**************************************************************************
  2. //**
  3. //** a_action.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: a_action.c,v $
  6. //** $Revision: 1.86 $
  7. //** $Date: 96/03/22 13:15:33 $
  8. //** $Author: bgokey $
  9. //**
  10. //**************************************************************************
  11. // HEADER FILES ------------------------------------------------------------
  12. #include "h2def.h"
  13. #include "p_local.h"
  14. #include "soundst.h"
  15. // MACROS ------------------------------------------------------------------
  16. // TYPES -------------------------------------------------------------------
  17. // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  18. // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
  19. // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
  20. // EXTERNAL DATA DECLARATIONS ----------------------------------------------
  21. extern fixed_t FloatBobOffsets[64];
  22. // PUBLIC DATA DEFINITIONS -------------------------------------------------
  23. int orbitTableX[256]=
  24. {
  25. 983025, 982725, 981825, 980340, 978255, 975600, 972330, 968490,
  26. 964065, 959070, 953475, 947325, 940590, 933300, 925440, 917025,
  27. 908055, 898545, 888495, 877905, 866775, 855135, 842985, 830310,
  28. 817155, 803490, 789360, 774735, 759660, 744120, 728130, 711690,
  29. 694845, 677565, 659880, 641805, 623340, 604500, 585285, 565725,
  30. 545820, 525600, 505050, 484200, 463065, 441645, 419955, 398010,
  31. 375840, 353430, 330810, 307995, 285000, 261825, 238485, 215010,
  32. 191400, 167685, 143865, 119955, 95970, 71940, 47850, 23745,
  33. -375, -24495, -48600, -72690, -96720, -120705, -144600, -168420,
  34. -192150, -215745, -239220, -262545, -285720, -308715, -331530, -354135,
  35. -376530, -398700, -420630, -442320, -463725, -484860, -505695, -526230,
  36. -546450, -566340, -585885, -605085, -623925, -642375, -660435, -678105,
  37. -695370, -712215, -728625, -744600, -760125, -775200, -789795, -803925,
  38. -817575, -830715, -843375, -855510, -867135, -878235, -888810, -898845,
  39. -908340, -917295, -925695, -933540, -940815, -947520, -953670, -959235,
  40. -964215, -968625, -972450, -975690, -978330, -980400, -981870, -982740,
  41. -983025, -982725, -981825, -980340, -978255, -975600, -972330, -968490,
  42. -964065, -959070, -953475, -947325, -940590, -933300, -925440, -917025,
  43. -908055, -898545, -888495, -877905, -866775, -855135, -842985, -830310,
  44. -817155, -803490, -789360, -774735, -759660, -744120, -728130, -711690,
  45. -694845, -677565, -659880, -641805, -623340, -604485, -585285, -565725,
  46. -545820, -525600, -505050, -484200, -463065, -441645, -419955, -398010,
  47. -375840, -353430, -330810, -307995, -285000, -261825, -238485, -215010,
  48. -191400, -167685, -143865, -119955, -95970, -71940, -47850, -23745,
  49. 375, 24495, 48600, 72690, 96720, 120705, 144600, 168420,
  50. 192150, 215745, 239220, 262545, 285720, 308715, 331530, 354135,
  51. 376530, 398700, 420630, 442320, 463725, 484860, 505695, 526230,
  52. 546450, 566340, 585885, 605085, 623925, 642375, 660435, 678105,
  53. 695370, 712215, 728625, 744600, 760125, 775200, 789795, 803925,
  54. 817575, 830715, 843375, 855510, 867135, 878235, 888810, 898845,
  55. 908340, 917295, 925695, 933540, 940815, 947520, 953670, 959235,
  56. 964215, 968625, 972450, 975690, 978330, 980400, 981870, 982740
  57. };
  58. int orbitTableY[256]=
  59. {
  60. 375, 24495, 48600, 72690, 96720, 120705, 144600, 168420,
  61. 192150, 215745, 239220, 262545, 285720, 308715, 331530, 354135,
  62. 376530, 398700, 420630, 442320, 463725, 484860, 505695, 526230,
  63. 546450, 566340, 585885, 605085, 623925, 642375, 660435, 678105,
  64. 695370, 712215, 728625, 744600, 760125, 775200, 789795, 803925,
  65. 817575, 830715, 843375, 855510, 867135, 878235, 888810, 898845,
  66. 908340, 917295, 925695, 933540, 940815, 947520, 953670, 959235,
  67. 964215, 968625, 972450, 975690, 978330, 980400, 981870, 982740,
  68. 983025, 982725, 981825, 980340, 978255, 975600, 972330, 968490,
  69. 964065, 959070, 953475, 947325, 940590, 933300, 925440, 917025,
  70. 908055, 898545, 888495, 877905, 866775, 855135, 842985, 830310,
  71. 817155, 803490, 789360, 774735, 759660, 744120, 728130, 711690,
  72. 694845, 677565, 659880, 641805, 623340, 604500, 585285, 565725,
  73. 545820, 525600, 505050, 484200, 463065, 441645, 419955, 398010,
  74. 375840, 353430, 330810, 307995, 285000, 261825, 238485, 215010,
  75. 191400, 167685, 143865, 119955, 95970, 71940, 47850, 23745,
  76. -375, -24495, -48600, -72690, -96720, -120705, -144600, -168420,
  77. -192150, -215745, -239220, -262545, -285720, -308715, -331530, -354135,
  78. -376530, -398700, -420630, -442320, -463725, -484860, -505695, -526230,
  79. -546450, -566340, -585885, -605085, -623925, -642375, -660435, -678105,
  80. -695370, -712215, -728625, -744600, -760125, -775200, -789795, -803925,
  81. -817575, -830715, -843375, -855510, -867135, -878235, -888810, -898845,
  82. -908340, -917295, -925695, -933540, -940815, -947520, -953670, -959235,
  83. -964215, -968625, -972450, -975690, -978330, -980400, -981870, -982740,
  84. -983025, -982725, -981825, -980340, -978255, -975600, -972330, -968490,
  85. -964065, -959070, -953475, -947325, -940590, -933300, -925440, -917025,
  86. -908055, -898545, -888495, -877905, -866775, -855135, -842985, -830310,
  87. -817155, -803490, -789360, -774735, -759660, -744120, -728130, -711690,
  88. -694845, -677565, -659880, -641805, -623340, -604485, -585285, -565725,
  89. -545820, -525600, -505050, -484200, -463065, -441645, -419955, -398010,
  90. -375840, -353430, -330810, -307995, -285000, -261825, -238485, -215010,
  91. -191400, -167685, -143865, -119955, -95970, -71940, -47850, -23745
  92. };
  93. // PRIVATE DATA DEFINITIONS ------------------------------------------------
  94. // CODE --------------------------------------------------------------------
  95. //--------------------------------------------------------------------------
  96. //
  97. // Environmental Action routines
  98. //
  99. //--------------------------------------------------------------------------
  100. //==========================================================================
  101. //
  102. // A_DripBlood
  103. //
  104. //==========================================================================
  105. /*
  106. void A_DripBlood(mobj_t *actor)
  107. {
  108. mobj_t *mo;
  109. mo = P_SpawnMobj(actor->x+((P_Random()-P_Random())<<11),
  110. actor->y+((P_Random()-P_Random())<<11), actor->z, MT_BLOOD);
  111. mo->momx = (P_Random()-P_Random())<<10;
  112. mo->momy = (P_Random()-P_Random())<<10;
  113. mo->flags2 |= MF2_LOGRAV;
  114. }
  115. */
  116. //============================================================================
  117. //
  118. // A_PotteryExplode
  119. //
  120. //============================================================================
  121. void A_PotteryExplode(mobj_t *actor)
  122. {
  123. mobj_t *mo=NULL;
  124. int i;
  125. for(i = (P_Random()&3)+3; i; i--)
  126. {
  127. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_POTTERYBIT1);
  128. P_SetMobjState(mo, mo->info->spawnstate+(P_Random()%5));
  129. if(mo)
  130. {
  131. mo->momz = ((P_Random()&7)+5)*(3*FRACUNIT/4);
  132. mo->momx = (P_Random()-P_Random())<<(FRACBITS-6);
  133. mo->momy = (P_Random()-P_Random())<<(FRACBITS-6);
  134. }
  135. }
  136. S_StartSound(mo, SFX_POTTERY_EXPLODE);
  137. if(actor->args[0])
  138. { // Spawn an item
  139. if(!nomonsters
  140. || !(mobjinfo[TranslateThingType[actor->args[0]]].flags&MF_COUNTKILL))
  141. { // Only spawn monsters if not -nomonsters
  142. P_SpawnMobj(actor->x, actor->y, actor->z,
  143. TranslateThingType[actor->args[0]]);
  144. }
  145. }
  146. P_RemoveMobj(actor);
  147. }
  148. //============================================================================
  149. //
  150. // A_PotteryChooseBit
  151. //
  152. //============================================================================
  153. void A_PotteryChooseBit(mobj_t *actor)
  154. {
  155. P_SetMobjState(actor, actor->info->deathstate+(P_Random()%5)+1);
  156. actor->tics = 256+(P_Random()<<1);
  157. }
  158. //============================================================================
  159. //
  160. // A_PotteryCheck
  161. //
  162. //============================================================================
  163. void A_PotteryCheck(mobj_t *actor)
  164. {
  165. int i;
  166. mobj_t *pmo;
  167. if(!netgame)
  168. {
  169. pmo = players[consoleplayer].mo;
  170. if(P_CheckSight(actor, pmo) && (abs(R_PointToAngle2(pmo->x,
  171. pmo->y, actor->x, actor->y)-pmo->angle) <= ANGLE_45))
  172. { // Previous state (pottery bit waiting state)
  173. P_SetMobjState(actor, actor->state-&states[0]-1);
  174. }
  175. else
  176. {
  177. return;
  178. }
  179. }
  180. else
  181. {
  182. for(i = 0; i < MAXPLAYERS; i++)
  183. {
  184. if(!playeringame[i])
  185. {
  186. continue;
  187. }
  188. pmo = players[i].mo;
  189. if(P_CheckSight(actor, pmo) && (abs(R_PointToAngle2(pmo->x,
  190. pmo->y, actor->x, actor->y)-pmo->angle) <= ANGLE_45))
  191. { // Previous state (pottery bit waiting state)
  192. P_SetMobjState(actor, actor->state-&states[0]-1);
  193. return;
  194. }
  195. }
  196. }
  197. }
  198. //============================================================================
  199. //
  200. // A_CorpseBloodDrip
  201. //
  202. //============================================================================
  203. void A_CorpseBloodDrip(mobj_t *actor)
  204. {
  205. if(P_Random() > 128)
  206. {
  207. return;
  208. }
  209. P_SpawnMobj(actor->x, actor->y, actor->z+actor->height/2,
  210. MT_CORPSEBLOODDRIP);
  211. }
  212. //============================================================================
  213. //
  214. // A_CorpseExplode
  215. //
  216. //============================================================================
  217. void A_CorpseExplode(mobj_t *actor)
  218. {
  219. mobj_t *mo;
  220. int i;
  221. for(i = (P_Random()&3)+3; i; i--)
  222. {
  223. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_CORPSEBIT);
  224. P_SetMobjState(mo, mo->info->spawnstate+(P_Random()%3));
  225. if(mo)
  226. {
  227. mo->momz = ((P_Random()&7)+5)*(3*FRACUNIT/4);
  228. mo->momx = (P_Random()-P_Random())<<(FRACBITS-6);
  229. mo->momy = (P_Random()-P_Random())<<(FRACBITS-6);
  230. }
  231. }
  232. // Spawn a skull
  233. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_CORPSEBIT);
  234. P_SetMobjState(mo, S_CORPSEBIT_4);
  235. if(mo)
  236. {
  237. mo->momz = ((P_Random()&7)+5)*(3*FRACUNIT/4);
  238. mo->momx = (P_Random()-P_Random())<<(FRACBITS-6);
  239. mo->momy = (P_Random()-P_Random())<<(FRACBITS-6);
  240. S_StartSound(mo, SFX_FIRED_DEATH);
  241. }
  242. P_RemoveMobj(actor);
  243. }
  244. //============================================================================
  245. //
  246. // A_LeafSpawn
  247. //
  248. //============================================================================
  249. void A_LeafSpawn(mobj_t *actor)
  250. {
  251. mobj_t *mo;
  252. int i;
  253. for(i = (P_Random()&3)+1; i; i--)
  254. {
  255. mo = P_SpawnMobj(actor->x+((P_Random()-P_Random())<<14), actor->y+
  256. ((P_Random()-P_Random())<<14), actor->z+(P_Random()<<14),
  257. MT_LEAF1+(P_Random()&1));
  258. if(mo)
  259. {
  260. P_ThrustMobj(mo, actor->angle, (P_Random()<<9)+3*FRACUNIT);
  261. mo->target = actor;
  262. mo->special1 = 0;
  263. }
  264. }
  265. }
  266. //============================================================================
  267. //
  268. // A_LeafThrust
  269. //
  270. //============================================================================
  271. void A_LeafThrust(mobj_t *actor)
  272. {
  273. if(P_Random() > 96)
  274. {
  275. return;
  276. }
  277. actor->momz += (P_Random()<<9)+FRACUNIT;
  278. }
  279. //============================================================================
  280. //
  281. // A_LeafCheck
  282. //
  283. //============================================================================
  284. void A_LeafCheck(mobj_t *actor)
  285. {
  286. actor->special1++;
  287. if(actor->special1 >= 20)
  288. {
  289. P_SetMobjState(actor, S_NULL);
  290. return;
  291. }
  292. if(P_Random() > 64)
  293. {
  294. if(!actor->momx && !actor->momy)
  295. {
  296. P_ThrustMobj(actor, actor->target->angle,
  297. (P_Random()<<9)+FRACUNIT);
  298. }
  299. return;
  300. }
  301. P_SetMobjState(actor, S_LEAF1_8);
  302. actor->momz = (P_Random()<<9)+FRACUNIT;
  303. P_ThrustMobj(actor, actor->target->angle, (P_Random()<<9)+2*FRACUNIT);
  304. actor->flags |= MF_MISSILE;
  305. }
  306. /*
  307. #define ORBIT_RADIUS (15*FRACUNIT)
  308. void GenerateOrbitTable(void)
  309. {
  310. int angle;
  311. for (angle=0; angle<256; angle++)
  312. {
  313. orbitTableX[angle] = FixedMul(ORBIT_RADIUS, finecosine[angle<<5]);
  314. orbitTableY[angle] = FixedMul(ORBIT_RADIUS, finesine[angle<<5]);
  315. }
  316. printf("int orbitTableX[256]=\n{\n");
  317. for (angle=0; angle<256; angle+=8)
  318. {
  319. printf("%d, %d, %d, %d, %d, %d, %d, %d,\n",
  320. orbitTableX[angle],
  321. orbitTableX[angle+1],
  322. orbitTableX[angle+2],
  323. orbitTableX[angle+3],
  324. orbitTableX[angle+4],
  325. orbitTableX[angle+5],
  326. orbitTableX[angle+6],
  327. orbitTableX[angle+7]);
  328. }
  329. printf("};\n\n");
  330. printf("int orbitTableY[256]=\n{\n");
  331. for (angle=0; angle<256; angle+=8)
  332. {
  333. printf("%d, %d, %d, %d, %d, %d, %d, %d,\n",
  334. orbitTableY[angle],
  335. orbitTableY[angle+1],
  336. orbitTableY[angle+2],
  337. orbitTableY[angle+3],
  338. orbitTableY[angle+4],
  339. orbitTableY[angle+5],
  340. orbitTableY[angle+6],
  341. orbitTableY[angle+7]);
  342. }
  343. printf("};\n");
  344. }
  345. */
  346. // New bridge stuff
  347. // Parent
  348. // special1 true == removing from world
  349. //
  350. // Child
  351. // target pointer to center mobj
  352. // args[0] angle of ball
  353. void A_BridgeOrbit(mobj_t *actor)
  354. {
  355. if (actor->target->special1)
  356. {
  357. P_SetMobjState(actor, S_NULL);
  358. }
  359. actor->args[0]+=3;
  360. actor->x = actor->target->x + orbitTableX[actor->args[0]];
  361. actor->y = actor->target->y + orbitTableY[actor->args[0]];
  362. actor->z = actor->target->z;
  363. }
  364. void A_BridgeInit(mobj_t *actor)
  365. {
  366. byte startangle;
  367. mobj_t *ball1, *ball2, *ball3;
  368. fixed_t cx,cy,cz;
  369. // GenerateOrbitTable();
  370. cx = actor->x;
  371. cy = actor->y;
  372. cz = actor->z;
  373. startangle = P_Random();
  374. actor->special1 = 0;
  375. // Spawn triad into world
  376. ball1 = P_SpawnMobj(cx, cy, cz, MT_BRIDGEBALL);
  377. ball1->args[0] = startangle;
  378. ball1->target = actor;
  379. ball2 = P_SpawnMobj(cx, cy, cz, MT_BRIDGEBALL);
  380. ball2->args[0] = (startangle+85)&255;
  381. ball2->target = actor;
  382. ball3 = P_SpawnMobj(cx, cy, cz, MT_BRIDGEBALL);
  383. ball3->args[0] = (startangle+170)&255;
  384. ball3->target = actor;
  385. A_BridgeOrbit(ball1);
  386. A_BridgeOrbit(ball2);
  387. A_BridgeOrbit(ball3);
  388. }
  389. void A_BridgeRemove(mobj_t *actor)
  390. {
  391. actor->special1 = true; // Removing the bridge
  392. actor->flags &= ~MF_SOLID;
  393. P_SetMobjState(actor, S_FREE_BRIDGE1);
  394. }
  395. //==========================================================================
  396. //
  397. // A_GhostOn
  398. //
  399. //==========================================================================
  400. /*
  401. void A_GhostOn(mobj_t *actor)
  402. {
  403. actor->flags |= MF_SHADOW;
  404. }
  405. */
  406. //==========================================================================
  407. //
  408. // A_GhostOff
  409. //
  410. //==========================================================================
  411. /*
  412. void A_GhostOff(mobj_t *actor)
  413. {
  414. actor->flags &= ~MF_SHADOW;
  415. }
  416. */
  417. //==========================================================================
  418. //
  419. // A_HideThing
  420. //
  421. //==========================================================================
  422. void A_HideThing(mobj_t *actor)
  423. {
  424. actor->flags2 |= MF2_DONTDRAW;
  425. }
  426. //==========================================================================
  427. //
  428. // A_UnHideThing
  429. //
  430. //==========================================================================
  431. void A_UnHideThing(mobj_t *actor)
  432. {
  433. actor->flags2 &= ~MF2_DONTDRAW;
  434. }
  435. //==========================================================================
  436. //
  437. // A_SetShootable
  438. //
  439. //==========================================================================
  440. void A_SetShootable(mobj_t *actor)
  441. {
  442. actor->flags2 &= ~MF2_NONSHOOTABLE;
  443. actor->flags |= MF_SHOOTABLE;
  444. }
  445. //==========================================================================
  446. //
  447. // A_UnSetShootable
  448. //
  449. //==========================================================================
  450. void A_UnSetShootable(mobj_t *actor)
  451. {
  452. actor->flags2 |= MF2_NONSHOOTABLE;
  453. actor->flags &= ~MF_SHOOTABLE;
  454. }
  455. //==========================================================================
  456. //
  457. // A_SetAltShadow
  458. //
  459. //==========================================================================
  460. void A_SetAltShadow(mobj_t *actor)
  461. {
  462. actor->flags &= ~MF_SHADOW;
  463. actor->flags |= MF_ALTSHADOW;
  464. }
  465. //==========================================================================
  466. //
  467. // A_UnSetAltShadow
  468. //
  469. //==========================================================================
  470. /*
  471. void A_UnSetAltShadow(mobj_t *actor)
  472. {
  473. actor->flags &= ~MF_ALTSHADOW;
  474. }
  475. */
  476. //--------------------------------------------------------------------------
  477. //
  478. // Sound Action Routines
  479. //
  480. //--------------------------------------------------------------------------
  481. //==========================================================================
  482. //
  483. // A_ContMobjSound
  484. //
  485. //==========================================================================
  486. void A_ContMobjSound(mobj_t *actor)
  487. {
  488. switch(actor->type)
  489. {
  490. case MT_SERPENTFX:
  491. S_StartSound(actor, SFX_SERPENTFX_CONTINUOUS);
  492. break;
  493. case MT_HAMMER_MISSILE:
  494. S_StartSound(actor, SFX_FIGHTER_HAMMER_CONTINUOUS);
  495. break;
  496. case MT_QUAKE_FOCUS:
  497. S_StartSound(actor, SFX_EARTHQUAKE);
  498. break;
  499. default:
  500. break;
  501. }
  502. }
  503. //==========================================================================
  504. //
  505. // PROC A_ESound
  506. //
  507. //==========================================================================
  508. void A_ESound(mobj_t *mo)
  509. {
  510. int sound;
  511. switch(mo->type)
  512. {
  513. case MT_SOUNDWIND:
  514. sound = SFX_WIND;
  515. break;
  516. default:
  517. sound = SFX_NONE;
  518. break;
  519. }
  520. S_StartSound(mo, sound);
  521. }
  522. //==========================================================================
  523. // Summon Minotaur -- see p_enemy for variable descriptions
  524. //==========================================================================
  525. void A_Summon(mobj_t *actor)
  526. {
  527. mobj_t *mo;
  528. mobj_t *master;
  529. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_MINOTAUR);
  530. if (mo)
  531. {
  532. if(P_TestMobjLocation(mo) == false || !actor->special1)
  533. { // Didn't fit - change back to artifact
  534. P_SetMobjState(mo, S_NULL);
  535. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_SUMMONMAULATOR);
  536. if (mo) mo->flags2 |= MF2_DROPPED;
  537. return;
  538. }
  539. memcpy((void *)mo->args, &leveltime, sizeof(leveltime));
  540. master = (mobj_t *)actor->special1;
  541. if (master->flags&MF_CORPSE)
  542. { // Master dead
  543. mo->special1 = 0; // No master
  544. }
  545. else
  546. {
  547. mo->special1 = actor->special1; // Pointer to master (mobj_t *)
  548. P_GivePower(master->player, pw_minotaur);
  549. }
  550. // Make smoke puff
  551. P_SpawnMobj(actor->x, actor->y, actor->z, MT_MNTRSMOKE);
  552. S_StartSound(actor, SFX_MAULATOR_ACTIVE);
  553. }
  554. }
  555. //==========================================================================
  556. // Fog Variables:
  557. //
  558. // args[0] Speed (0..10) of fog
  559. // args[1] Angle of spread (0..128)
  560. // args[2] Frequency of spawn (1..10)
  561. // args[3] Lifetime countdown
  562. // args[4] Boolean: fog moving?
  563. // special1 Internal: Counter for spawn frequency
  564. // special2 Internal: Index into floatbob table
  565. //
  566. //==========================================================================
  567. void A_FogSpawn(mobj_t *actor)
  568. {
  569. mobj_t *mo=NULL;
  570. angle_t delta;
  571. if (actor->special1-- > 0) return;
  572. actor->special1 = actor->args[2]; // Reset frequency count
  573. switch(P_Random()%3)
  574. {
  575. case 0:
  576. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_FOGPATCHS);
  577. break;
  578. case 1:
  579. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_FOGPATCHM);
  580. break;
  581. case 2:
  582. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_FOGPATCHL);
  583. break;
  584. }
  585. if (mo)
  586. {
  587. delta = actor->args[1];
  588. if (delta==0) delta=1;
  589. mo->angle = actor->angle + (((P_Random()%delta)-(delta>>1))<<24);
  590. mo->target = actor;
  591. if (actor->args[0] < 1) actor->args[0] = 1;
  592. mo->args[0] = (P_Random() % (actor->args[0]))+1; // Random speed
  593. mo->args[3] = actor->args[3]; // Set lifetime
  594. mo->args[4] = 1; // Set to moving
  595. mo->special2 = P_Random()&63;
  596. }
  597. }
  598. void A_FogMove(mobj_t *actor)
  599. {
  600. int speed = actor->args[0]<<FRACBITS;
  601. angle_t angle;
  602. int weaveindex;
  603. if (!(actor->args[4])) return;
  604. if (actor->args[3]-- <= 0)
  605. {
  606. P_SetMobjStateNF(actor, actor->info->deathstate);
  607. return;
  608. }
  609. if ((actor->args[3] % 4) == 0)
  610. {
  611. weaveindex = actor->special2;
  612. actor->z += FloatBobOffsets[weaveindex]>>1;
  613. actor->special2 = (weaveindex+1)&63;
  614. }
  615. angle = actor->angle>>ANGLETOFINESHIFT;
  616. actor->momx = FixedMul(speed, finecosine[angle]);
  617. actor->momy = FixedMul(speed, finesine[angle]);
  618. }
  619. //===========================================================================
  620. //
  621. // A_PoisonBagInit
  622. //
  623. //===========================================================================
  624. void A_PoisonBagInit(mobj_t *actor)
  625. {
  626. mobj_t *mo;
  627. mo = P_SpawnMobj(actor->x, actor->y, actor->z+28*FRACUNIT,
  628. MT_POISONCLOUD);
  629. if(!mo)
  630. {
  631. return;
  632. }
  633. mo->momx = 1; // missile objects must move to impact other objects
  634. mo->special1 = 24+(P_Random()&7);
  635. mo->special2 = 0;
  636. mo->target = actor->target;
  637. mo->radius = 20*FRACUNIT;
  638. mo->height = 30*FRACUNIT;
  639. mo->flags &= ~MF_NOCLIP;
  640. }
  641. //===========================================================================
  642. //
  643. // A_PoisonBagCheck
  644. //
  645. //===========================================================================
  646. void A_PoisonBagCheck(mobj_t *actor)
  647. {
  648. if(!--actor->special1)
  649. {
  650. P_SetMobjState(actor, S_POISONCLOUD_X1);
  651. }
  652. else
  653. {
  654. return;
  655. }
  656. }
  657. //===========================================================================
  658. //
  659. // A_PoisonBagDamage
  660. //
  661. //===========================================================================
  662. void A_PoisonBagDamage(mobj_t *actor)
  663. {
  664. int bobIndex;
  665. extern void A_Explode(mobj_t *actor);
  666. A_Explode(actor);
  667. bobIndex = actor->special2;
  668. actor->z += FloatBobOffsets[bobIndex]>>4;
  669. actor->special2 = (bobIndex+1)&63;
  670. }
  671. //===========================================================================
  672. //
  673. // A_PoisonShroom
  674. //
  675. //===========================================================================
  676. void A_PoisonShroom(mobj_t *actor)
  677. {
  678. actor->tics = 128+(P_Random()<<1);
  679. }
  680. //===========================================================================
  681. //
  682. // A_CheckThrowBomb
  683. //
  684. //===========================================================================
  685. void A_CheckThrowBomb(mobj_t *actor)
  686. {
  687. if(abs(actor->momx) < 1.5*FRACUNIT && abs(actor->momy) < 1.5*FRACUNIT
  688. && actor->momz < 2*FRACUNIT
  689. && actor->state == &states[S_THROWINGBOMB6])
  690. {
  691. P_SetMobjState(actor, S_THROWINGBOMB7);
  692. actor->z = actor->floorz;
  693. actor->momz = 0;
  694. actor->flags2 &= ~MF2_FLOORBOUNCE;
  695. actor->flags &= ~MF_MISSILE;
  696. }
  697. if(!--actor->health)
  698. {
  699. P_SetMobjState(actor, actor->info->deathstate);
  700. }
  701. }
  702. //===========================================================================
  703. // Quake variables
  704. //
  705. // args[0] Intensity on richter scale (2..9)
  706. // args[1] Duration in tics
  707. // args[2] Radius for damage
  708. // args[3] Radius for tremor
  709. // args[4] TID of map thing for focus of quake
  710. //
  711. //===========================================================================
  712. //===========================================================================
  713. //
  714. // A_LocalQuake
  715. //
  716. //===========================================================================
  717. boolean A_LocalQuake(byte *args, mobj_t *actor)
  718. {
  719. mobj_t *focus, *target;
  720. int lastfound=0;
  721. int success=false;
  722. actor=actor; // suppress warning
  723. // Find all quake foci
  724. do
  725. {
  726. target = P_FindMobjFromTID(args[4], &lastfound);
  727. if (target)
  728. {
  729. focus = P_SpawnMobj(target->x,
  730. target->y,
  731. target->z, MT_QUAKE_FOCUS);
  732. if (focus)
  733. {
  734. focus->args[0] = args[0];
  735. focus->args[1] = args[1]>>1; // decremented every 2 tics
  736. focus->args[2] = args[2];
  737. focus->args[3] = args[3];
  738. focus->args[4] = args[4];
  739. success = true;
  740. }
  741. }
  742. }while(target != NULL);
  743. return(success);
  744. }
  745. //===========================================================================
  746. //
  747. // A_Quake
  748. //
  749. //===========================================================================
  750. int localQuakeHappening[MAXPLAYERS];
  751. void A_Quake(mobj_t *actor)
  752. {
  753. angle_t an;
  754. player_t *player;
  755. mobj_t *victim;
  756. int richters = actor->args[0];
  757. int playnum;
  758. fixed_t dist;
  759. if (actor->args[1]-- > 0)
  760. {
  761. for (playnum=0; playnum < MAXPLAYERS; playnum++)
  762. {
  763. player = &players[playnum];
  764. if (!playeringame[playnum]) continue;
  765. victim = player->mo;
  766. dist = P_AproxDistance(actor->x - victim->x,
  767. actor->y - victim->y) >> (FRACBITS+6);
  768. // Tested in tile units (64 pixels)
  769. if (dist < actor->args[3]) // In tremor radius
  770. {
  771. localQuakeHappening[playnum] = richters;
  772. }
  773. // Check if in damage radius
  774. if ((dist < actor->args[2]) &&
  775. (victim->z <= victim->floorz))
  776. {
  777. if (P_Random() < 50)
  778. {
  779. P_DamageMobj(victim, NULL, NULL, HITDICE(1));
  780. }
  781. // Thrust player around
  782. an = victim->angle + ANGLE_1*P_Random();
  783. P_ThrustMobj(victim,an,richters<<(FRACBITS-1));
  784. }
  785. }
  786. }
  787. else
  788. {
  789. for (playnum=0; playnum < MAXPLAYERS; playnum++)
  790. {
  791. localQuakeHappening[playnum] = false;
  792. }
  793. P_SetMobjState(actor, S_NULL);
  794. }
  795. }
  796. //===========================================================================
  797. //
  798. // Teleport other stuff
  799. //
  800. //===========================================================================
  801. #define TELEPORT_LIFE 1
  802. void A_TeloSpawnA(mobj_t *actor)
  803. {
  804. mobj_t *mo;
  805. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_TELOTHER_FX2);
  806. if (mo)
  807. {
  808. mo->special1 = TELEPORT_LIFE; // Lifetime countdown
  809. mo->angle = actor->angle;
  810. mo->target = actor->target;
  811. mo->momx = actor->momx>>1;
  812. mo->momy = actor->momy>>1;
  813. mo->momz = actor->momz>>1;
  814. }
  815. }
  816. void A_TeloSpawnB(mobj_t *actor)
  817. {
  818. mobj_t *mo;
  819. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_TELOTHER_FX3);
  820. if (mo)
  821. {
  822. mo->special1 = TELEPORT_LIFE; // Lifetime countdown
  823. mo->angle = actor->angle;
  824. mo->target = actor->target;
  825. mo->momx = actor->momx>>1;
  826. mo->momy = actor->momy>>1;
  827. mo->momz = actor->momz>>1;
  828. }
  829. }
  830. void A_TeloSpawnC(mobj_t *actor)
  831. {
  832. mobj_t *mo;
  833. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_TELOTHER_FX4);
  834. if (mo)
  835. {
  836. mo->special1 = TELEPORT_LIFE; // Lifetime countdown
  837. mo->angle = actor->angle;
  838. mo->target = actor->target;
  839. mo->momx = actor->momx>>1;
  840. mo->momy = actor->momy>>1;
  841. mo->momz = actor->momz>>1;
  842. }
  843. }
  844. void A_TeloSpawnD(mobj_t *actor)
  845. {
  846. mobj_t *mo;
  847. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_TELOTHER_FX5);
  848. if (mo)
  849. {
  850. mo->special1 = TELEPORT_LIFE; // Lifetime countdown
  851. mo->angle = actor->angle;
  852. mo->target = actor->target;
  853. mo->momx = actor->momx>>1;
  854. mo->momy = actor->momy>>1;
  855. mo->momz = actor->momz>>1;
  856. }
  857. }
  858. void A_CheckTeleRing(mobj_t *actor)
  859. {
  860. if (actor->special1-- <= 0)
  861. {
  862. P_SetMobjState(actor, actor->info->deathstate);
  863. }
  864. }
  865. // Dirt stuff
  866. void P_SpawnDirt(mobj_t *actor, fixed_t radius)
  867. {
  868. fixed_t x,y,z;
  869. int dtype=0;
  870. mobj_t *mo;
  871. angle_t angle;
  872. angle = P_Random()<<5; // <<24 >>19
  873. x = actor->x + FixedMul(radius,finecosine[angle]);
  874. y = actor->y + FixedMul(radius,finesine[angle]);
  875. // x = actor->x + ((P_Random()-P_Random())%radius)<<FRACBITS;
  876. // y = actor->y + ((P_Random()-P_Random()<<FRACBITS)%radius);
  877. z = actor->z + (P_Random()<<9) + FRACUNIT;
  878. switch(P_Random()%6)
  879. {
  880. case 0:
  881. dtype = MT_DIRT1;
  882. break;
  883. case 1:
  884. dtype = MT_DIRT2;
  885. break;
  886. case 2:
  887. dtype = MT_DIRT3;
  888. break;
  889. case 3:
  890. dtype = MT_DIRT4;
  891. break;
  892. case 4:
  893. dtype = MT_DIRT5;
  894. break;
  895. case 5:
  896. dtype = MT_DIRT6;
  897. break;
  898. }
  899. mo = P_SpawnMobj(x,y,z,dtype);
  900. if (mo)
  901. {
  902. mo->momz = P_Random()<<10;
  903. }
  904. }
  905. //===========================================================================
  906. //
  907. // Thrust floor stuff
  908. //
  909. // Thrust Spike Variables
  910. // special1 pointer to dirt clump mobj
  911. // special2 speed of raise
  912. // args[0] 0 = lowered, 1 = raised
  913. // args[1] 0 = normal, 1 = bloody
  914. //===========================================================================
  915. void A_ThrustInitUp(mobj_t *actor)
  916. {
  917. actor->special2 = 5; // Raise speed
  918. actor->args[0] = 1; // Mark as up
  919. actor->floorclip = 0;
  920. actor->flags = MF_SOLID;
  921. actor->flags2 = MF2_NOTELEPORT|MF2_FLOORCLIP;
  922. actor->special1 = 0L;
  923. }
  924. void A_ThrustInitDn(mobj_t *actor)
  925. {
  926. mobj_t *mo;
  927. actor->special2 = 5; // Raise speed
  928. actor->args[0] = 0; // Mark as down
  929. actor->floorclip = actor->info->height;
  930. actor->flags = 0;
  931. actor->flags2 = MF2_NOTELEPORT|MF2_FLOORCLIP|MF2_DONTDRAW;
  932. mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_DIRTCLUMP);
  933. actor->special1 = (int)mo;
  934. }
  935. void A_ThrustRaise(mobj_t *actor)
  936. {
  937. if (A_RaiseMobj(actor))
  938. { // Reached it's target height
  939. actor->args[0] = 1;
  940. if (actor->args[1])
  941. P_SetMobjStateNF(actor, S_BTHRUSTINIT2_1);
  942. else
  943. P_SetMobjStateNF(actor, S_THRUSTINIT2_1);
  944. }
  945. // Lose the dirt clump
  946. if ((actor->floorclip < actor->height) && actor->special1)
  947. {
  948. P_RemoveMobj( (mobj_t *)actor->special1 );
  949. actor->special1 = 0;
  950. }
  951. // Spawn some dirt
  952. if (P_Random()<40)
  953. P_SpawnDirt(actor, actor->radius);
  954. actor->special2++; // Increase raise speed
  955. }
  956. void A_ThrustLower(mobj_t *actor)
  957. {
  958. if (A_SinkMobj(actor))
  959. {
  960. actor->args[0] = 0;
  961. if (actor->args[1])
  962. P_SetMobjStateNF(actor, S_BTHRUSTINIT1_1);
  963. else
  964. P_SetMobjStateNF(actor, S_THRUSTINIT1_1);
  965. }
  966. }
  967. void A_ThrustBlock(mobj_t *actor)
  968. {
  969. actor->flags |= MF_SOLID;
  970. }
  971. void A_ThrustImpale(mobj_t *actor)
  972. {
  973. // Impale all shootables in radius
  974. PIT_ThrustSpike(actor);
  975. }
  976. //===========================================================================
  977. //
  978. // A_SoAExplode - Suit of Armor Explode
  979. //
  980. //===========================================================================
  981. void A_SoAExplode(mobj_t *actor)
  982. {
  983. mobj_t *mo;
  984. int i;
  985. for(i = 0; i < 10; i++)
  986. {
  987. mo = P_SpawnMobj(actor->x+((P_Random()-128)<<12),
  988. actor->y+((P_Random()-128)<<12),
  989. actor->z+(P_Random()*actor->height/256), MT_ZARMORCHUNK);
  990. P_SetMobjState(mo, mo->info->spawnstate+i);
  991. if(mo)
  992. {
  993. mo->momz = ((P_Random()&7)+5)*FRACUNIT;
  994. mo->momx = (P_Random()-P_Random())<<(FRACBITS-6);
  995. mo->momy = (P_Random()-P_Random())<<(FRACBITS-6);
  996. }
  997. }
  998. if(actor->args[0])
  999. { // Spawn an item
  1000. if(!nomonsters
  1001. || !(mobjinfo[TranslateThingType[actor->args[0]]].flags&MF_COUNTKILL))
  1002. { // Only spawn monsters if not -nomonsters
  1003. P_SpawnMobj(actor->x, actor->y, actor->z,
  1004. TranslateThingType[actor->args[0]]);
  1005. }
  1006. }
  1007. S_StartSound(mo, SFX_SUITOFARMOR_BREAK);
  1008. P_RemoveMobj(actor);
  1009. }
  1010. //===========================================================================
  1011. //
  1012. // A_BellReset1
  1013. //
  1014. //===========================================================================
  1015. void A_BellReset1(mobj_t *actor)
  1016. {
  1017. actor->flags |= MF_NOGRAVITY;
  1018. actor->height <<= 2;
  1019. }
  1020. //===========================================================================
  1021. //
  1022. // A_BellReset2
  1023. //
  1024. //===========================================================================
  1025. void A_BellReset2(mobj_t *actor)
  1026. {
  1027. actor->flags |= MF_SHOOTABLE;
  1028. actor->flags &= ~MF_CORPSE;
  1029. actor->health = 5;
  1030. }
  1031. //===========================================================================
  1032. //
  1033. // A_FlameCheck
  1034. //
  1035. //===========================================================================
  1036. void A_FlameCheck(mobj_t *actor)
  1037. {
  1038. if(!actor->args[0]--) // Called every 8 tics
  1039. {
  1040. P_SetMobjState(actor, S_NULL);
  1041. }
  1042. }
  1043. //===========================================================================
  1044. // Bat Spawner Variables
  1045. // special1 frequency counter
  1046. // special2
  1047. // args[0] frequency of spawn (1=fastest, 10=slowest)
  1048. // args[1] spread angle (0..255)
  1049. // args[2]
  1050. // args[3] duration of bats (in octics)
  1051. // args[4] turn amount per move (in degrees)
  1052. //
  1053. // Bat Variables
  1054. // special2 lifetime counter
  1055. // args[4] turn amount per move (in degrees)
  1056. //===========================================================================
  1057. void A_BatSpawnInit(mobj_t *actor)
  1058. {
  1059. actor->special1 = 0; // Frequency count
  1060. }
  1061. void A_BatSpawn(mobj_t *actor)
  1062. {
  1063. mobj_t *mo;
  1064. int delta;
  1065. angle_t angle;
  1066. // Countdown until next spawn
  1067. if (actor->special1-- > 0) return;
  1068. actor->special1 = actor->args[0]; // Reset frequency count
  1069. delta = actor->args[1];
  1070. if (delta==0) delta=1;
  1071. angle = actor->angle + (((P_Random()%delta)-(delta>>1))<<24);
  1072. mo = P_SpawnMissileAngle(actor, MT_BAT, angle, 0);
  1073. if (mo)
  1074. {
  1075. mo->args[0] = P_Random()&63; // floatbob index
  1076. mo->args[4] = actor->args[4]; // turn degrees
  1077. mo->special2 = actor->args[3]<<3; // Set lifetime
  1078. mo->target = actor;
  1079. }
  1080. }
  1081. void A_BatMove(mobj_t *actor)
  1082. {
  1083. angle_t newangle;
  1084. fixed_t speed;
  1085. if (actor->special2 < 0)
  1086. {
  1087. P_SetMobjState(actor, actor->info->deathstate);
  1088. }
  1089. actor->special2 -= 2; // Called every 2 tics
  1090. if (P_Random()<128)
  1091. {
  1092. newangle = actor->angle + ANGLE_1*actor->args[4];
  1093. }
  1094. else
  1095. {
  1096. newangle = actor->angle - ANGLE_1*actor->args[4];
  1097. }
  1098. // Adjust momentum vector to new direction
  1099. newangle >>= ANGLETOFINESHIFT;
  1100. speed = FixedMul(actor->info->speed, P_Random()<<10);
  1101. actor->momx = FixedMul(speed, finecosine[newangle]);
  1102. actor->momy = FixedMul(speed, finesine[newangle]);
  1103. if (P_Random()<15)
  1104. S_StartSound(actor, SFX_BAT_SCREAM);
  1105. // Handle Z movement
  1106. actor->z = actor->target->z + 2*FloatBobOffsets[actor->args[0]];
  1107. actor->args[0] = (actor->args[0]+3)&63;
  1108. }
  1109. //===========================================================================
  1110. //
  1111. // A_TreeDeath
  1112. //
  1113. //===========================================================================
  1114. void A_TreeDeath(mobj_t *actor)
  1115. {
  1116. if(!(actor->flags2&MF2_FIREDAMAGE))
  1117. {
  1118. actor->height <<= 2;
  1119. actor->flags |= MF_SHOOTABLE;
  1120. actor->flags &= ~(MF_CORPSE+MF_DROPOFF);
  1121. actor->health = 35;
  1122. return;
  1123. }
  1124. else
  1125. {
  1126. P_SetMobjState(actor, actor->info->meleestate);
  1127. }
  1128. }
  1129. //===========================================================================
  1130. //
  1131. // A_NoGravity
  1132. //
  1133. //===========================================================================
  1134. void A_NoGravity(mobj_t *actor)
  1135. {
  1136. actor->flags |= MF_NOGRAVITY;
  1137. }