Debian Codegraph @

prboom2/src/hexen/a_action.c

raw
1 //
2 // Copyright(C) 1993-1996 Id Software, Inc.
3 // Copyright(C) 1993-2008 Raven Software
4 // Copyright(C) 2005-2014 Simon Howard
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16
17 #include "doomdef.h"
18 #include "doomstat.h"
19 #include "m_random.h"
20 #include "sounds.h"
21 #include "s_sound.h"
22 #include "r_main.h"
23 #include "p_map.h"
24 #include "p_maputl.h"
25 #include "p_inter.h"
26 #include "p_enemy.h"
27 #include "p_tick.h"
28
29 #include "hexen/p_things.h"
30
31 #include "a_action.h"
32
33 int orbitTableX[256] = {
34 983025, 982725, 981825, 980340, 978255, 975600, 972330, 968490,
35 964065, 959070, 953475, 947325, 940590, 933300, 925440, 917025,
36 908055, 898545, 888495, 877905, 866775, 855135, 842985, 830310,
37 817155, 803490, 789360, 774735, 759660, 744120, 728130, 711690,
38 694845, 677565, 659880, 641805, 623340, 604500, 585285, 565725,
39 545820, 525600, 505050, 484200, 463065, 441645, 419955, 398010,
40 375840, 353430, 330810, 307995, 285000, 261825, 238485, 215010,
41 191400, 167685, 143865, 119955, 95970, 71940, 47850, 23745,
42 -375, -24495, -48600, -72690, -96720, -120705, -144600, -168420,
43 -192150, -215745, -239220, -262545, -285720, -308715, -331530, -354135,
44 -376530, -398700, -420630, -442320, -463725, -484860, -505695, -526230,
45 -546450, -566340, -585885, -605085, -623925, -642375, -660435, -678105,
46 -695370, -712215, -728625, -744600, -760125, -775200, -789795, -803925,
47 -817575, -830715, -843375, -855510, -867135, -878235, -888810, -898845,
48 -908340, -917295, -925695, -933540, -940815, -947520, -953670, -959235,
49 -964215, -968625, -972450, -975690, -978330, -980400, -981870, -982740,
50 -983025, -982725, -981825, -980340, -978255, -975600, -972330, -968490,
51 -964065, -959070, -953475, -947325, -940590, -933300, -925440, -917025,
52 -908055, -898545, -888495, -877905, -866775, -855135, -842985, -830310,
53 -817155, -803490, -789360, -774735, -759660, -744120, -728130, -711690,
54 -694845, -677565, -659880, -641805, -623340, -604485, -585285, -565725,
55 -545820, -525600, -505050, -484200, -463065, -441645, -419955, -398010,
56 -375840, -353430, -330810, -307995, -285000, -261825, -238485, -215010,
57 -191400, -167685, -143865, -119955, -95970, -71940, -47850, -23745,
58 375, 24495, 48600, 72690, 96720, 120705, 144600, 168420,
59 192150, 215745, 239220, 262545, 285720, 308715, 331530, 354135,
60 376530, 398700, 420630, 442320, 463725, 484860, 505695, 526230,
61 546450, 566340, 585885, 605085, 623925, 642375, 660435, 678105,
62 695370, 712215, 728625, 744600, 760125, 775200, 789795, 803925,
63 817575, 830715, 843375, 855510, 867135, 878235, 888810, 898845,
64 908340, 917295, 925695, 933540, 940815, 947520, 953670, 959235,
65 964215, 968625, 972450, 975690, 978330, 980400, 981870, 982740
66 };
67
68 int orbitTableY[256] = {
69 375, 24495, 48600, 72690, 96720, 120705, 144600, 168420,
70 192150, 215745, 239220, 262545, 285720, 308715, 331530, 354135,
71 376530, 398700, 420630, 442320, 463725, 484860, 505695, 526230,
72 546450, 566340, 585885, 605085, 623925, 642375, 660435, 678105,
73 695370, 712215, 728625, 744600, 760125, 775200, 789795, 803925,
74 817575, 830715, 843375, 855510, 867135, 878235, 888810, 898845,
75 908340, 917295, 925695, 933540, 940815, 947520, 953670, 959235,
76 964215, 968625, 972450, 975690, 978330, 980400, 981870, 982740,
77 983025, 982725, 981825, 980340, 978255, 975600, 972330, 968490,
78 964065, 959070, 953475, 947325, 940590, 933300, 925440, 917025,
79 908055, 898545, 888495, 877905, 866775, 855135, 842985, 830310,
80 817155, 803490, 789360, 774735, 759660, 744120, 728130, 711690,
81 694845, 677565, 659880, 641805, 623340, 604500, 585285, 565725,
82 545820, 525600, 505050, 484200, 463065, 441645, 419955, 398010,
83 375840, 353430, 330810, 307995, 285000, 261825, 238485, 215010,
84 191400, 167685, 143865, 119955, 95970, 71940, 47850, 23745,
85 -375, -24495, -48600, -72690, -96720, -120705, -144600, -168420,
86 -192150, -215745, -239220, -262545, -285720, -308715, -331530, -354135,
87 -376530, -398700, -420630, -442320, -463725, -484860, -505695, -526230,
88 -546450, -566340, -585885, -605085, -623925, -642375, -660435, -678105,
89 -695370, -712215, -728625, -744600, -760125, -775200, -789795, -803925,
90 -817575, -830715, -843375, -855510, -867135, -878235, -888810, -898845,
91 -908340, -917295, -925695, -933540, -940815, -947520, -953670, -959235,
92 -964215, -968625, -972450, -975690, -978330, -980400, -981870, -982740,
93 -983025, -982725, -981825, -980340, -978255, -975600, -972330, -968490,
94 -964065, -959070, -953475, -947325, -940590, -933300, -925440, -917025,
95 -908055, -898545, -888495, -877905, -866775, -855135, -842985, -830310,
96 -817155, -803490, -789360, -774735, -759660, -744120, -728130, -711690,
97 -694845, -677565, -659880, -641805, -623340, -604485, -585285, -565725,
98 -545820, -525600, -505050, -484200, -463065, -441645, -419955, -398010,
99 -375840, -353430, -330810, -307995, -285000, -261825, -238485, -215010,
100 -191400, -167685, -143865, -119955, -95970, -71940, -47850, -23745
101 };
102
103 extern fixed_t FloatBobOffsets[64];
104
105 void A_PotteryExplode(mobj_t * actor)
106 {
107 mobj_t *mo = NULL;
108 int i;
109
110 for (i = (P_Random(pr_hexen) & 3) + 3; i; i--)
111 {
112 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_POTTERYBIT1);
113 P_SetMobjState(mo, mo->info->spawnstate + (P_Random(pr_hexen) % 5));
114 mo->momz = ((P_Random(pr_hexen) & 7) + 5) * (3 * FRACUNIT / 4);
115 mo->momx = P_SubRandom() << (FRACBITS - 6);
116 mo->momy = P_SubRandom() << (FRACBITS - 6);
117 }
118 S_StartMobjSound(mo, hexen_sfx_pottery_explode);
119 if (actor->special_args[0])
120 { // Spawn an item
121 if (!nomonsters
122 || !(mobjinfo[TranslateThingType[actor->special_args[0]]].
123 flags & MF_COUNTKILL))
124 { // Only spawn monsters if not -nomonsters
125 P_SpawnMobj(actor->x, actor->y, actor->z,
126 TranslateThingType[actor->special_args[0]]);
127 }
128 }
129 P_RemoveMobj(actor);
130 }
131
132 void A_PotteryChooseBit(mobj_t * actor)
133 {
134 P_SetMobjState(actor, actor->info->deathstate + (P_Random(pr_hexen) % 5) + 1);
135 actor->tics = 256 + (P_Random(pr_hexen) << 1);
136 }
137
138 void A_PotteryCheck(mobj_t * actor)
139 {
140 int i;
141 mobj_t *pmo;
142
143 if (!netgame)
144 {
145 pmo = players[consoleplayer].mo;
146 if (P_CheckSight(actor, pmo)
147 && (abs((int)R_PointToAngle2(pmo->x, pmo->y, actor->x, actor->y)
148 - (int)pmo->angle) <= ANG45))
149 { // Previous state (pottery bit waiting state)
150 P_SetMobjState(actor, actor->state - &states[0] - 1);
151 }
152 else
153 {
154 return;
155 }
156 }
157 else
158 {
159 for (i = 0; i < g_maxplayers; i++)
160 {
161 if (!playeringame[i])
162 {
163 continue;
164 }
165 pmo = players[i].mo;
166 if (P_CheckSight(actor, pmo)
167 && (abs((int)R_PointToAngle2(pmo->x, pmo->y, actor->x, actor->y)
168 - (int)pmo->angle) <= ANG45))
169 { // Previous state (pottery bit waiting state)
170 P_SetMobjState(actor, actor->state - &states[0] - 1);
171 return;
172 }
173 }
174 }
175 }
176
177 void P_SpawnDirt(mobj_t * actor, fixed_t radius)
178 {
179 fixed_t x, y, z;
180 int dtype = 0;
181 mobj_t *mo;
182 angle_t angle;
183
184 angle = P_Random(pr_hexen) << 5; // <<24 >>19
185 x = actor->x + FixedMul(radius, finecosine[angle]);
186 y = actor->y + FixedMul(radius, finesine[angle]);
187 z = actor->z + (P_Random(pr_hexen) << 9) + FRACUNIT;
188 switch (P_Random(pr_hexen) % 6)
189 {
190 case 0:
191 dtype = HEXEN_MT_DIRT1;
192 break;
193 case 1:
194 dtype = HEXEN_MT_DIRT2;
195 break;
196 case 2:
197 dtype = HEXEN_MT_DIRT3;
198 break;
199 case 3:
200 dtype = HEXEN_MT_DIRT4;
201 break;
202 case 4:
203 dtype = HEXEN_MT_DIRT5;
204 break;
205 case 5:
206 dtype = HEXEN_MT_DIRT6;
207 break;
208 }
209 mo = P_SpawnMobj(x, y, z, dtype);
210 if (mo)
211 {
212 mo->momz = P_Random(pr_hexen) << 10;
213 }
214 }
215
216 void A_CorpseBloodDrip(mobj_t * actor)
217 {
218 if (P_Random(pr_hexen) > 128)
219 {
220 return;
221 }
222 P_SpawnMobj(actor->x, actor->y, actor->z + actor->height / 2,
223 HEXEN_MT_CORPSEBLOODDRIP);
224 }
225
226 void A_CorpseExplode(mobj_t * actor)
227 {
228 mobj_t *mo;
229 int i;
230
231 for (i = (P_Random(pr_hexen) & 3) + 3; i; i--)
232 {
233 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_CORPSEBIT);
234 P_SetMobjState(mo, mo->info->spawnstate + (P_Random(pr_hexen) % 3));
235 mo->momz = ((P_Random(pr_hexen) & 7) + 5) * (3 * FRACUNIT / 4);
236 mo->momx = P_SubRandom() << (FRACBITS - 6);
237 mo->momy = P_SubRandom() << (FRACBITS - 6);
238 }
239 // Spawn a skull
240 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_CORPSEBIT);
241 P_SetMobjState(mo, HEXEN_S_CORPSEBIT_4);
242 if (mo)
243 {
244 mo->momz = ((P_Random(pr_hexen) & 7) + 5) * (3 * FRACUNIT / 4);
245 mo->momx = P_SubRandom() << (FRACBITS - 6);
246 mo->momy = P_SubRandom() << (FRACBITS - 6);
247 S_StartMobjSound(mo, hexen_sfx_fired_death);
248 }
249 P_RemoveMobj(actor);
250 }
251
252 void A_LeafSpawn(mobj_t * actor)
253 {
254 mobj_t *mo;
255 int i;
256
257 for (i = (P_Random(pr_hexen) & 3) + 1; i; i--)
258 {
259 // Official release of Hexen's source code relies on unspecified behavior
260 // the in order of function's argument evaluation,
261 // see ISO-IEC 9899-1999, [6.5.2.2.10]
262 mobjtype_t type = HEXEN_MT_LEAF1 + (P_Random(pr_hexen) & 1);
263 fixed_t z = actor->z + (P_Random(pr_hexen) << 14);
264 fixed_t y = actor->y + (P_SubRandom() << 14);
265 fixed_t x = actor->x + (P_SubRandom() << 14);
266
267 mo = P_SpawnMobj(x, y, z, type);
268 if (mo)
269 {
270 P_ThrustMobj(mo, actor->angle, (P_Random(pr_hexen) << 9) + 3 * FRACUNIT);
271 P_SetTarget(&mo->target, actor);
272 mo->special1.i = 0;
273 }
274 }
275 }
276
277 void A_LeafThrust(mobj_t * actor)
278 {
279 if (P_Random(pr_hexen) > 96)
280 {
281 return;
282 }
283 actor->momz += (P_Random(pr_hexen) << 9) + FRACUNIT;
284 }
285
286 void A_LeafCheck(mobj_t * actor)
287 {
288 actor->special1.i++;
289 if (actor->special1.i >= 20)
290 {
291 P_SetMobjState(actor, HEXEN_S_NULL);
292 return;
293 }
294 if (P_Random(pr_hexen) > 64)
295 {
296 if (!actor->momx && !actor->momy)
297 {
298 P_ThrustMobj(actor, actor->target->angle,
299 (P_Random(pr_hexen) << 9) + FRACUNIT);
300 }
301 return;
302 }
303 P_SetMobjState(actor, HEXEN_S_LEAF1_8);
304 actor->momz = (P_Random(pr_hexen) << 9) + FRACUNIT;
305 P_ThrustMobj(actor, actor->target->angle,
306 (P_Random(pr_hexen) << 9) + 2 * FRACUNIT);
307 actor->flags |= MF_MISSILE;
308 }
309
310 void A_BridgeOrbit(mobj_t * actor)
311 {
312 if (actor->target->special1.i)
313 {
314 P_SetMobjState(actor, HEXEN_S_NULL);
315 }
316 actor->special_args[0] += 3;
317 actor->special_args[0] &= 0xff;
318 actor->x = actor->target->x + orbitTableX[actor->special_args[0]];
319 actor->y = actor->target->y + orbitTableY[actor->special_args[0]];
320 actor->z = actor->target->z;
321 }
322
323 void A_BridgeInit(mobj_t * actor)
324 {
325 byte startangle;
326 mobj_t *ball1, *ball2, *ball3;
327 fixed_t cx, cy, cz;
328
329 cx = actor->x;
330 cy = actor->y;
331 cz = actor->z;
332 startangle = P_Random(pr_hexen);
333 actor->special1.i = 0;
334
335 // Spawn triad into world
336 ball1 = P_SpawnMobj(cx, cy, cz, HEXEN_MT_BRIDGEBALL);
337 ball1->special_args[0] = startangle;
338 P_SetTarget(&ball1->target, actor);
339
340 ball2 = P_SpawnMobj(cx, cy, cz, HEXEN_MT_BRIDGEBALL);
341 ball2->special_args[0] = (startangle + 85) & 255;
342 P_SetTarget(&ball2->target, actor);
343
344 ball3 = P_SpawnMobj(cx, cy, cz, HEXEN_MT_BRIDGEBALL);
345 ball3->special_args[0] = (startangle + 170) & 255;
346 P_SetTarget(&ball3->target, actor);
347
348 A_BridgeOrbit(ball1);
349 A_BridgeOrbit(ball2);
350 A_BridgeOrbit(ball3);
351 }
352
353 void A_BridgeRemove(mobj_t * actor)
354 {
355 actor->special1.i = true; // Removing the bridge
356 actor->flags &= ~MF_SOLID;
357 P_SetMobjState(actor, HEXEN_S_FREE_BRIDGE1);
358 }
359
360 void A_SetShootable(mobj_t * actor)
361 {
362 actor->flags2 &= ~MF2_NONSHOOTABLE;
363 actor->flags |= MF_SHOOTABLE;
364 }
365
366 void A_UnSetShootable(mobj_t * actor)
367 {
368 actor->flags2 |= MF2_NONSHOOTABLE;
369 actor->flags &= ~MF_SHOOTABLE;
370 }
371
372 void A_SetAltShadow(mobj_t * actor)
373 {
374 actor->flags &= ~MF_SHADOW;
375 actor->flags |= MF_ALTSHADOW;
376 }
377
378 void A_Summon(mobj_t * actor)
379 {
380 mobj_t *mo;
381 mobj_t *master;
382
383 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_MINOTAUR);
384 if (mo)
385 {
386 if (P_TestMobjLocation(mo) == false || !actor->special1.m)
387 { // Didn't fit - change back to artifact
388 P_SetMobjState(mo, HEXEN_S_NULL);
389 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_SUMMONMAULATOR);
390 if (mo)
391 mo->flags |= MF_DROPPED;
392 return;
393 }
394
395 // An attempt to just use the int directly failed - it's not clear why
396 mo->special_args[0] = leveltime & 0xff;
397 mo->special_args[1] = (leveltime >> 8) & 0xff;
398 mo->special_args[2] = (leveltime >> 16) & 0xff;
399 mo->special_args[3] = (leveltime >> 24) & 0xff;
400 master = actor->special1.m;
401 if (master->flags & MF_CORPSE)
402 { // Master dead
403 P_SetTarget(&mo->special1.m, NULL); // No master
404 }
405 else
406 {
407 P_SetTarget(&mo->special1.m, actor->special1.m); // Pointer to master (mobj_t *)
408 P_GivePower(master->player, pw_minotaur);
409 }
410
411 // Make smoke puff
412 P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_MNTRSMOKE);
413 S_StartMobjSound(actor, hexen_sfx_maulator_active);
414 }
415 }
416
417 //==========================================================================
418 // Fog Variables:
419 //
420 // args[0] Speed (0..10) of fog
421 // args[1] Angle of spread (0..128)
422 // args[2] Frequency of spawn (1..10)
423 // args[3] Lifetime countdown
424 // args[4] Boolean: fog moving?
425 // special1 Internal: Counter for spawn frequency
426 // special2 Internal: Index into floatbob table
427 //
428 //==========================================================================
429
430 void A_FogSpawn(mobj_t * actor)
431 {
432 mobj_t *mo = NULL;
433 angle_t delta;
434
435 if (actor->special1.i-- > 0)
436 return;
437
438 actor->special1.i = actor->special_args[2]; // Reset frequency count
439
440 switch (P_Random(pr_hexen) % 3)
441 {
442 case 0:
443 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_FOGPATCHS);
444 break;
445 case 1:
446 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_FOGPATCHM);
447 break;
448 case 2:
449 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_FOGPATCHL);
450 break;
451 }
452
453 if (mo)
454 {
455 delta = actor->special_args[1];
456 if (delta == 0)
457 delta = 1;
458 mo->angle =
459 actor->angle + (((P_Random(pr_hexen) % delta) - (delta >> 1)) << 24);
460 P_SetTarget(&mo->target, actor);
461 if (actor->special_args[0] < 1)
462 actor->special_args[0] = 1;
463 mo->special_args[0] = (P_Random(pr_hexen) % (actor->special_args[0])) + 1; // Random speed
464 mo->special_args[3] = actor->special_args[3]; // Set lifetime
465 mo->special_args[4] = 1; // Set to moving
466 mo->special2.i = P_Random(pr_hexen) & 63;
467 }
468 }
469
470 void A_FogMove(mobj_t * actor)
471 {
472 int speed = actor->special_args[0] << FRACBITS;
473 angle_t angle;
474 int weaveindex;
475
476 if (!(actor->special_args[4]))
477 return;
478
479 if (actor->special_args[3]-- <= 0)
480 {
481 P_SetMobjStateNF(actor, actor->info->deathstate);
482 return;
483 }
484
485 if ((actor->special_args[3] % 4) == 0)
486 {
487 weaveindex = actor->special2.i;
488 actor->z += FloatBobOffsets[weaveindex] >> 1;
489 actor->special2.i = (weaveindex + 1) & 63;
490 }
491
492 angle = actor->angle >> ANGLETOFINESHIFT;
493 actor->momx = FixedMul(speed, finecosine[angle]);
494 actor->momy = FixedMul(speed, finesine[angle]);
495 }
496
497 void A_PoisonBagInit(mobj_t * actor)
498 {
499 mobj_t *mo;
500
501 mo = P_SpawnMobj(actor->x, actor->y, actor->z + 28 * FRACUNIT,
502 HEXEN_MT_POISONCLOUD);
503 if (!mo)
504 {
505 return;
506 }
507 mo->momx = 1; // missile objects must move to impact other objects
508 mo->special1.i = 24 + (P_Random(pr_hexen) & 7);
509 mo->special2.i = 0;
510 P_SetTarget(&mo->target, actor->target);
511 mo->radius = 20 * FRACUNIT;
512 mo->height = 30 * FRACUNIT;
513 mo->flags &= ~MF_NOCLIP;
514 }
515
516 void A_PoisonBagCheck(mobj_t * actor)
517 {
518 if (!--actor->special1.i)
519 {
520 P_SetMobjState(actor, HEXEN_S_POISONCLOUD_X1);
521 }
522 else
523 {
524 return;
525 }
526 }
527
528 void A_PoisonBagDamage(mobj_t * actor)
529 {
530 int bobIndex;
531
532 extern void A_Explode(mobj_t * actor);
533
534 A_Explode(actor);
535
536 bobIndex = actor->special2.i;
537 actor->z += FloatBobOffsets[bobIndex] >> 4;
538 actor->special2.i = (bobIndex + 1) & 63;
539 }
540
541 void A_PoisonShroom(mobj_t * actor)
542 {
543 actor->tics = 128 + (P_Random(pr_hexen) << 1);
544 }
545
546 void A_CheckThrowBomb(mobj_t * actor)
547 {
548 if (abs(actor->momx) < 1.5 * FRACUNIT && abs(actor->momy) < 1.5 * FRACUNIT
549 && actor->momz < 2 * FRACUNIT
550 && actor->state == &states[HEXEN_S_THROWINGBOMB6])
551 {
552 P_SetMobjState(actor, HEXEN_S_THROWINGBOMB7);
553 actor->z = actor->floorz;
554 actor->momz = 0;
555 actor->flags2 &= ~MF2_FLOORBOUNCE;
556 actor->flags &= ~MF_MISSILE;
557 }
558 if (!--actor->health)
559 {
560 P_SetMobjState(actor, actor->info->deathstate);
561 }
562 }
563
564 //===========================================================================
565 // Quake variables
566 //
567 // args[0] Intensity on richter scale (2..9)
568 // args[1] Duration in tics
569 // args[2] Radius for damage
570 // args[3] Radius for tremor
571 // args[4] TID of map thing for focus of quake
572 //
573 //===========================================================================
574
575 dboolean A_LocalQuake(byte * args, mobj_t * actor)
576 {
577 mobj_t *focus, *target;
578 int lastfound = 0;
579 int success = false;
580
581 // Find all quake foci
582 do
583 {
584 target = P_FindMobjFromTID(args[4], &lastfound);
585 if (target)
586 {
587 focus = P_SpawnMobj(target->x,
588 target->y, target->z, HEXEN_MT_QUAKE_FOCUS);
589 if (focus)
590 {
591 focus->special_args[0] = args[0];
592 focus->special_args[1] = args[1] >> 1; // decremented every 2 tics
593 focus->special_args[2] = args[2];
594 focus->special_args[3] = args[3];
595 focus->special_args[4] = args[4];
596 success = true;
597 }
598 }
599 }
600 while (target != NULL);
601
602 return (success);
603 }
604
605 int localQuakeHappening[MAX_MAXPLAYERS];
606
607 void A_Quake(mobj_t * actor)
608 {
609 angle_t an;
610 player_t *player;
611 mobj_t *victim;
612 int richters = actor->special_args[0];
613 int playnum;
614 fixed_t dist;
615
616 if (actor->special_args[1]-- > 0)
617 {
618 for (playnum = 0; playnum < g_maxplayers; playnum++)
619 {
620 player = &players[playnum];
621 if (!playeringame[playnum])
622 continue;
623
624 victim = player->mo;
625 dist = P_AproxDistance(actor->x - victim->x,
626 actor->y - victim->y) >> (FRACBITS + 6);
627 // Tested in tile units (64 pixels)
628 if (dist < actor->special_args[3]) // In tremor radius
629 {
630 localQuakeHappening[playnum] = richters;
631 }
632 // Check if in damage radius
633 if ((dist < actor->special_args[2]) && (victim->z <= victim->floorz))
634 {
635 if (P_Random(pr_hexen) < 50)
636 {
637 P_DamageMobj(victim, NULL, NULL, HITDICE(1));
638 }
639 // Thrust player around
640 an = victim->angle + ANG1 * P_Random(pr_hexen);
641 P_ThrustMobj(victim, an, richters << (FRACBITS - 1));
642 }
643 }
644 }
645 else
646 {
647 for (playnum = 0; playnum < g_maxplayers; playnum++)
648 {
649 localQuakeHappening[playnum] = false;
650 }
651 P_SetMobjState(actor, HEXEN_S_NULL);
652 }
653 }
654
655 #define TELEPORT_LIFE 1
656
657 void A_TeloSpawnA(mobj_t * actor)
658 {
659 mobj_t *mo;
660
661 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_TELOTHER_FX2);
662 if (mo)
663 {
664 mo->special1.i = TELEPORT_LIFE; // Lifetime countdown
665 mo->angle = actor->angle;
666 P_SetTarget(&mo->target, actor->target);
667 mo->momx = actor->momx >> 1;
668 mo->momy = actor->momy >> 1;
669 mo->momz = actor->momz >> 1;
670 }
671 }
672
673 void A_TeloSpawnB(mobj_t * actor)
674 {
675 mobj_t *mo;
676
677 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_TELOTHER_FX3);
678 if (mo)
679 {
680 mo->special1.i = TELEPORT_LIFE; // Lifetime countdown
681 mo->angle = actor->angle;
682 P_SetTarget(&mo->target, actor->target);
683 mo->momx = actor->momx >> 1;
684 mo->momy = actor->momy >> 1;
685 mo->momz = actor->momz >> 1;
686 }
687 }
688
689 void A_TeloSpawnC(mobj_t * actor)
690 {
691 mobj_t *mo;
692
693 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_TELOTHER_FX4);
694 if (mo)
695 {
696 mo->special1.i = TELEPORT_LIFE; // Lifetime countdown
697 mo->angle = actor->angle;
698 P_SetTarget(&mo->target, actor->target);
699 mo->momx = actor->momx >> 1;
700 mo->momy = actor->momy >> 1;
701 mo->momz = actor->momz >> 1;
702 }
703 }
704
705 void A_TeloSpawnD(mobj_t * actor)
706 {
707 mobj_t *mo;
708
709 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_TELOTHER_FX5);
710 if (mo)
711 {
712 mo->special1.i = TELEPORT_LIFE; // Lifetime countdown
713 mo->angle = actor->angle;
714 P_SetTarget(&mo->target, actor->target);
715 mo->momx = actor->momx >> 1;
716 mo->momy = actor->momy >> 1;
717 mo->momz = actor->momz >> 1;
718 }
719 }
720
721 void A_CheckTeleRing(mobj_t * actor)
722 {
723 if (actor->special1.i-- <= 0)
724 {
725 P_SetMobjState(actor, actor->info->deathstate);
726 }
727 }
728
729 //===========================================================================
730 //
731 // Thrust floor stuff
732 //
733 // Thrust Spike Variables
734 // special1 pointer to dirt clump mobj
735 // special2 speed of raise
736 // args[0] 0 = lowered, 1 = raised
737 // args[1] 0 = normal, 1 = bloody
738 //===========================================================================
739
740 void A_ThrustInitUp(mobj_t * actor)
741 {
742 actor->special2.i = 5; // Raise speed
743 actor->special_args[0] = 1; // Mark as up
744 actor->floorclip = 0;
745 actor->flags = MF_SOLID;
746 actor->flags2 = MF2_NOTELEPORT | MF2_FOOTCLIP;
747 P_SetTarget(&actor->special1.m, NULL);
748 }
749
750 void A_ThrustInitDn(mobj_t * actor)
751 {
752 mobj_t *mo;
753 actor->special2.i = 5; // Raise speed
754 actor->special_args[0] = 0; // Mark as down
755 actor->floorclip = actor->info->height;
756 actor->flags = 0;
757 actor->flags2 = MF2_NOTELEPORT | MF2_FOOTCLIP | MF2_DONTDRAW;
758 mo = P_SpawnMobj(actor->x, actor->y, actor->z, HEXEN_MT_DIRTCLUMP);
759 P_SetTarget(&actor->special1.m, mo);
760 }
761
762
763 void A_ThrustRaise(mobj_t * actor)
764 {
765 if (A_RaiseMobj(actor))
766 { // Reached it's target height
767 actor->special_args[0] = 1;
768 if (actor->special_args[1])
769 P_SetMobjStateNF(actor, HEXEN_S_BTHRUSTINIT2_1);
770 else
771 P_SetMobjStateNF(actor, HEXEN_S_THRUSTINIT2_1);
772 }
773
774 // Lose the dirt clump
775 if ((actor->floorclip < actor->height) && actor->special1.m)
776 {
777 P_RemoveMobj(actor->special1.m);
778 P_SetTarget(&actor->special1.m, NULL);
779 }
780
781 // Spawn some dirt
782 if (P_Random(pr_hexen) < 40)
783 P_SpawnDirt(actor, actor->radius);
784 actor->special2.i++; // Increase raise speed
785 }
786
787 void A_ThrustLower(mobj_t * actor)
788 {
789 if (A_SinkMobj(actor))
790 {
791 actor->special_args[0] = 0;
792 if (actor->special_args[1])
793 P_SetMobjStateNF(actor, HEXEN_S_BTHRUSTINIT1_1);
794 else
795 P_SetMobjStateNF(actor, HEXEN_S_THRUSTINIT1_1);
796 }
797 }
798
799 void A_ThrustBlock(mobj_t * actor)
800 {
801 actor->flags |= MF_SOLID;
802 }
803
804 void A_ThrustImpale(mobj_t * actor)
805 {
806 // Impale all shootables in radius
807 PIT_ThrustSpike(actor);
808 }
809
810 void A_SoAExplode(mobj_t * actor)
811 {
812 mobj_t *mo;
813 int i;
814 int r1,r2,r3;
815
816 for (i = 0; i < 10; i++)
817 {
818 r1 = P_Random(pr_hexen);
819 r2 = P_Random(pr_hexen);
820 r3 = P_Random(pr_hexen);
821 mo = P_SpawnMobj(actor->x + ((r3 - 128) << 12),
822 actor->y + ((r2 - 128) << 12),
823 actor->z + (r1 * actor->height / 256),
824 HEXEN_MT_ZARMORCHUNK);
825 P_SetMobjState(mo, mo->info->spawnstate + i);
826 mo->momz = ((P_Random(pr_hexen) & 7) + 5) * FRACUNIT;
827 mo->momx = P_SubRandom() << (FRACBITS - 6);
828 mo->momy = P_SubRandom() << (FRACBITS - 6);
829 }
830 if (actor->special_args[0])
831 { // Spawn an item
832 // TODO: should this be on or off?
833 #if 0 // Checks are not present in version 1.1
834 if (!nomonsters
835 || !(mobjinfo[TranslateThingType[actor->special_args[0]]].
836 flags & MF_COUNTKILL))
837 #endif
838 { // Only spawn monsters if not -nomonsters
839 P_SpawnMobj(actor->x, actor->y, actor->z,
840 TranslateThingType[actor->special_args[0]]);
841 }
842 }
843 S_StartMobjSound(mo, hexen_sfx_suitofarmor_break);
844 P_RemoveMobj(actor);
845 }
846
847 void A_BellReset1(mobj_t * actor)
848 {
849 actor->flags |= MF_NOGRAVITY;
850 actor->height <<= 2;
851 }
852
853 void A_BellReset2(mobj_t * actor)
854 {
855 actor->flags |= MF_SHOOTABLE;
856 actor->flags &= ~MF_CORPSE;
857 actor->health = 5;
858 }
859
860 void A_FlameCheck(mobj_t * actor)
861 {
862 if (!actor->special_args[0]--) // Called every 8 tics
863 {
864 P_SetMobjState(actor, HEXEN_S_NULL);
865 }
866 }
867
868 //===========================================================================
869 // Bat Spawner Variables
870 // special1 frequency counter
871 // special2
872 // args[0] frequency of spawn (1=fastest, 10=slowest)
873 // args[1] spread angle (0..255)
874 // args[2]
875 // args[3] duration of bats (in octics)
876 // args[4] turn amount per move (in degrees)
877 //
878 // Bat Variables
879 // special2 lifetime counter
880 // args[4] turn amount per move (in degrees)
881 //===========================================================================
882
883 void A_BatSpawnInit(mobj_t * actor)
884 {
885 actor->special1.i = 0; // Frequency count
886 }
887
888 void A_BatSpawn(mobj_t * actor)
889 {
890 mobj_t *mo;
891 int delta;
892 angle_t angle;
893
894 // Countdown until next spawn
895 if (actor->special1.i-- > 0)
896 return;
897 actor->special1.i = actor->special_args[0]; // Reset frequency count
898
899 delta = actor->special_args[1];
900 if (delta == 0)
901 delta = 1;
902 angle = actor->angle + (((P_Random(pr_hexen) % delta) - (delta >> 1)) << 24);
903 mo = P_SpawnMissileAngle(actor, HEXEN_MT_BAT, angle, 0);
904 if (mo)
905 {
906 mo->special_args[0] = P_Random(pr_hexen) & 63; // floatbob index
907 mo->special_args[4] = actor->special_args[4]; // turn degrees
908 mo->special2.i = actor->special_args[3] << 3; // Set lifetime
909 P_SetTarget(&mo->target, actor);
910 }
911 }
912
913 void A_BatMove(mobj_t * actor)
914 {
915 angle_t newangle;
916 fixed_t speed;
917
918 if (actor->special2.i < 0)
919 {
920 P_SetMobjState(actor, actor->info->deathstate);
921 }
922 actor->special2.i -= 2; // Called every 2 tics
923
924 if (P_Random(pr_hexen) < 128)
925 {
926 newangle = actor->angle + ANG1 * actor->special_args[4];
927 }
928 else
929 {
930 newangle = actor->angle - ANG1 * actor->special_args[4];
931 }
932
933 // Adjust momentum vector to new direction
934 newangle >>= ANGLETOFINESHIFT;
935 speed = FixedMul(actor->info->speed, P_Random(pr_hexen) << 10);
936 actor->momx = FixedMul(speed, finecosine[newangle]);
937 actor->momy = FixedMul(speed, finesine[newangle]);
938
939 if (P_Random(pr_hexen) < 15)
940 S_StartMobjSound(actor, hexen_sfx_bat_scream);
941
942 // Handle Z movement
943 actor->z = actor->target->z + 2 * FloatBobOffsets[actor->special_args[0]];
944 actor->special_args[0] = (actor->special_args[0] + 3) & 63;
945 }
946
947 void A_TreeDeath(mobj_t * actor)
948 {
949 if (!(actor->flags2 & MF2_FIREDAMAGE))
950 {
951 actor->height <<= 2;
952 actor->flags |= MF_SHOOTABLE;
953 actor->flags &= ~(MF_CORPSE + MF_DROPOFF);
954 actor->health = 35;
955 return;
956 }
957 else
958 {
959 P_SetMobjState(actor, actor->info->meleestate);
960 }
961 }
962
963 void A_NoGravity(mobj_t * actor)
964 {
965 actor->flags |= MF_NOGRAVITY;
966 }