Debian Codegraph @

prboom2/src/p_mobj.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2004 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * Moving object handling. Spawn functions.
31 *
32 *-----------------------------------------------------------------------------*/
33
34 #include "doomdef.h"
35 #include "doomstat.h"
36 #include "m_random.h"
37 #include "r_main.h"
38 #include "p_maputl.h"
39 #include "p_map.h"
40 #include "p_tick.h"
41 #include "sounds.h"
42 #include "st_stuff.h"
43 #include "hu_stuff.h"
44 #include "s_sound.h"
45 #include "s_advsound.h"
46 #include "info.h"
47 #include "g_game.h"
48 #include "p_inter.h"
49 #include "p_user.h"
50 #include "lprintf.h"
51 #include "smooth.h"
52 #include "p_enemy.h"
53 #include "p_spec.h"
54 #include "g_overflow.h"
55 #include "e6y.h"//e6y
56
57 #include "dsda.h"
58 #include "dsda/aim.h"
59 #include "dsda/ambient.h"
60 #include "dsda/excmd.h"
61 #include "dsda/map_format.h"
62 #include "dsda/mapinfo.h"
63 #include "dsda/settings.h"
64 #include "dsda/skill_info.h"
65 #include "dsda/spawn_number.h"
66 #include "dsda/thing_id.h"
67 #include "dsda/tranmap.h"
68 #include "dsda/utility.h"
69
70 #include "heretic/def.h"
71 #include "heretic/sb_bar.h"
72
73 #include "hexen/po_man.h"
74
75 // heretic_note: static NUMSTATES arrays here - probably fine?
76 // NUMSTATES > HERETIC_NUMSTATES
77
78 //
79 // P_SetMobjState
80 // Returns true if the mobj is still present.
81 //
82
83 dboolean P_SetMobjState(mobj_t* mobj,statenum_t state)
84 {
85 state_t* st;
86
87 // killough 4/9/98: remember states seen, to detect cycles:
88
89 extern statenum_t* seenstate_tab; // fast transition table
90 statenum_t *seenstate; // pointer to table
91 static int recursion; // detects recursion
92 statenum_t i; // initial state
93 dboolean ret; // return value
94 statenum_t* tempstate = NULL; // for use with recursion
95
96 if (raven) return Raven_P_SetMobjState(mobj, state);
97
98 seenstate = seenstate_tab;
99 i = state;
100 ret = true;
101
102 if (recursion++) // if recursion detected,
103 seenstate = tempstate = Z_Calloc(num_states, sizeof(statenum_t)); // allocate state table
104
105 do
106 {
107 if (state == g_s_null)
108 {
109 mobj->state = NULL;
110 P_RemoveMobj (mobj);
111 ret = false;
112 break; // killough 4/9/98
113 }
114
115 st = &states[state];
116 mobj->state = st;
117 mobj->tics = st->tics;
118 mobj->sprite = st->sprite;
119 mobj->frame = st->frame;
120
121 // Modified handling.
122 // Call action functions when the state is set
123
124 if (st->action)
125 st->action(mobj);
126
127 seenstate[state] = 1 + st->nextstate; // killough 4/9/98
128
129 state = st->nextstate;
130 } while (!mobj->tics && !seenstate[state]); // killough 4/9/98
131
132 if (ret && !mobj->tics) // killough 4/9/98: detect state cycles
133 doom_printf("Warning: State Cycle Detected");
134
135 if (!--recursion)
136 for (;(state=seenstate[i]);i=state-1)
137 seenstate[i] = 0; // killough 4/9/98: erase memory of states
138
139 if (tempstate)
140 Z_Free(tempstate);
141
142 return ret;
143 }
144
145
146 //
147 // P_ExplodeMissile
148 //
149
150 void P_ExplodeMissile (mobj_t* mo)
151 {
152 if (heretic && mo->type == HERETIC_MT_WHIRLWIND)
153 {
154 if (++mo->special2.i < 60)
155 {
156 return;
157 }
158 }
159
160 mo->momx = mo->momy = mo->momz = 0;
161
162 P_SetMobjState (mo, mobjinfo[mo->type].deathstate);
163
164 if (!raven)
165 {
166 mo->tics -= P_Random(pr_explode) & 3;
167
168 if (mo->tics < 1)
169 mo->tics = 1;
170 }
171
172 mo->flags &= ~MF_MISSILE;
173
174 if (!hexen)
175 {
176 if (mo->info->deathsound)
177 S_StartMobjSound(mo, mo->info->deathsound);
178 }
179 else
180 {
181 switch (mo->type)
182 {
183 case HEXEN_MT_SORCBALL1:
184 case HEXEN_MT_SORCBALL2:
185 case HEXEN_MT_SORCBALL3:
186 S_StartVoidSound(hexen_sfx_sorcerer_bigballexplode);
187 break;
188 case HEXEN_MT_SORCFX1:
189 S_StartVoidSound(hexen_sfx_sorcerer_headscream);
190 break;
191 default:
192 if (mo->info->deathsound)
193 S_StartMobjSound(mo, mo->info->deathsound);
194 break;
195 }
196 }
197 }
198
199
200 //
201 // P_XYMovement
202 //
203 // Attempts to move something if it has momentum.
204 //
205
206 void P_ApplyCompatibleSectorMovementSpecial(mobj_t *mo, int special)
207 {
208 // nothing in doom
209 }
210
211 // heretic, hexen, and zdoom all use the same values
212 void P_ApplyHereticSectorMovementSpecial(mobj_t *mo, int special)
213 {
214 static int windTab[3] = { 2048 * 5, 2048 * 10, 2048 * 25 };
215
216 if (mo->flags2 & MF2_WINDTHRUST)
217 {
218 switch (special)
219 {
220 case zs_wind_east_weak:
221 case zs_wind_east_medium:
222 case zs_wind_east_strong:
223 P_ThrustMobj(mo, 0, windTab[special - 40]);
224 break;
225 case zs_wind_north_weak:
226 case zs_wind_north_medium:
227 case zs_wind_north_strong:
228 P_ThrustMobj(mo, ANG90, windTab[special - 43]);
229 break;
230 case zs_wind_south_weak:
231 case zs_wind_south_medium:
232 case zs_wind_south_strong:
233 P_ThrustMobj(mo, ANG270, windTab[special - 46]);
234 break;
235 case zs_wind_west_weak:
236 case zs_wind_west_medium:
237 case zs_wind_west_strong:
238 P_ThrustMobj(mo, ANG180, windTab[special - 49]);
239 break;
240 }
241 }
242 }
243
244 static void P_XYMovement (mobj_t* mo)
245 {
246 player_t *player;
247 fixed_t xmove, ymove;
248
249 //e6y
250 fixed_t oldx,oldy; // phares 9/10/98: reducing bobbing/momentum on ice
251
252 // heretic
253 int special;
254
255 if (!(mo->momx | mo->momy)) // Any momentum?
256 {
257 if (mo->flags & MF_SKULLFLY)
258 {
259 statenum_t new_state;
260 // the skull slammed into something
261
262 mo->flags &= ~MF_SKULLFLY;
263 mo->momz = 0;
264
265 if (raven)
266 new_state = mo->info->seestate;
267 else
268 new_state = mo->info->spawnstate;
269
270 P_SetMobjState (mo, new_state);
271 }
272 return;
273 }
274
275 special = mo->subsector->sector->special;
276 map_format.apply_sector_movement_special(mo, special);
277
278 player = mo->player;
279
280 if (mo->momx > MAXMOVE)
281 mo->momx = MAXMOVE;
282 else if (mo->momx < -MAXMOVE)
283 mo->momx = -MAXMOVE;
284
285 if (mo->momy > MAXMOVE)
286 mo->momy = MAXMOVE;
287 else if (mo->momy < -MAXMOVE)
288 mo->momy = -MAXMOVE;
289
290 xmove = mo->momx;
291 ymove = mo->momy;
292
293 oldx = mo->x; // phares 9/10/98: new code to reduce bobbing/momentum
294 oldy = mo->y; // when on ice & up against wall. These will be compared
295 // to your x,y values later to see if you were able to move
296
297 do
298 {
299 fixed_t ptryx, ptryy;
300 angle_t angle;
301
302 // killough 8/9/98: fix bug in original Doom source:
303 // Large negative displacements were never considered.
304 // This explains the tendency for Mancubus fireballs
305 // to pass through walls.
306 // CPhipps - compatibility optioned
307
308 if (xmove > MAXMOVE / 2 ||
309 ymove > MAXMOVE / 2 ||
310 (!comp[comp_moveblock] && (xmove < -MAXMOVE/2 || ymove < -MAXMOVE/2)))
311 {
312 ptryx = mo->x + xmove / 2;
313 ptryy = mo->y + ymove / 2;
314 xmove >>= 1;
315 ymove >>= 1;
316 }
317 else
318 {
319 ptryx = mo->x + xmove;
320 ptryy = mo->y + ymove;
321 xmove = ymove = 0;
322 }
323
324 // killough 3/15/98: Allow objects to drop off
325
326 if (!P_TryMove (mo, ptryx, ptryy, true))
327 {
328 // blocked move
329
330 // killough 8/11/98: bouncing off walls
331 // killough 10/98:
332 // Add ability for objects other than players to bounce on ice
333
334 if (
335 !(mo->flags & MF_MISSILE) &&
336 mbf_features &&
337 (
338 mo->flags & MF_BOUNCES ||
339 (
340 !player &&
341 blockline &&
342 variable_friction &&
343 mo->z <= mo->floorz &&
344 P_GetFriction(mo, NULL) > ORIG_FRICTION
345 )
346 )
347 )
348 {
349 if (blockline)
350 {
351 fixed_t r = ((blockline->dx >> FRACBITS) * mo->momx +
352 (blockline->dy >> FRACBITS) * mo->momy) /
353 ((blockline->dx >> FRACBITS)*(blockline->dx >> FRACBITS)+
354 (blockline->dy >> FRACBITS)*(blockline->dy >> FRACBITS));
355 fixed_t x = FixedMul(r, blockline->dx);
356 fixed_t y = FixedMul(r, blockline->dy);
357
358 // reflect momentum away from wall
359
360 mo->momx = x*2 - mo->momx;
361 mo->momy = y*2 - mo->momy;
362
363 // if under gravity, slow down in
364 // direction perpendicular to wall.
365
366 if (!(mo->flags & MF_NOGRAVITY))
367 {
368 mo->momx = (mo->momx + x)/2;
369 mo->momy = (mo->momy + y)/2;
370 }
371 }
372 else
373 mo->momx = mo->momy = 0;
374 }
375 else if (player || mo->flags2 & MF2_SLIDE) // try to slide along it
376 {
377 if (BlockingMobj == NULL || map_format.zdoom)
378 {
379 P_SlideMove(mo);
380 }
381 else
382 {
383 if (P_TryMove(mo, mo->x, ptryy, 0))
384 {
385 mo->momx = 0;
386 }
387 else if (P_TryMove(mo, ptryx, mo->y, 0))
388 {
389 mo->momy = 0;
390 }
391 else
392 {
393 mo->momx = mo->momy = 0;
394 }
395 }
396 }
397 else if (mo->flags & MF_MISSILE)
398 {
399 if (hexen && mo->flags2 & MF2_FLOORBOUNCE)
400 {
401 if (BlockingMobj)
402 {
403 if ((BlockingMobj->flags2 & MF2_REFLECTIVE) ||
404 ((!BlockingMobj->player) &&
405 (!(BlockingMobj->flags & MF_COUNTKILL))))
406 {
407 fixed_t speed;
408
409 angle = R_PointToAngle2(BlockingMobj->x, BlockingMobj->y, mo->x, mo->y) +
410 ANG1 * ((P_Random(pr_hexen) % 16) - 8);
411 speed = P_AproxDistance(mo->momx, mo->momy);
412 speed = FixedMul(speed, 0.75 * FRACUNIT);
413 mo->angle = angle;
414 angle >>= ANGLETOFINESHIFT;
415 mo->momx = FixedMul(speed, finecosine[angle]);
416 mo->momy = FixedMul(speed, finesine[angle]);
417 if (mo->info->seesound)
418 {
419 S_StartMobjSound(mo, mo->info->seesound);
420 }
421 return;
422 }
423 else
424 { // Struck a player/creature
425 P_ExplodeMissile(mo);
426 }
427 }
428 else
429 { // Struck a wall
430 P_BounceWall(mo);
431 switch (mo->type)
432 {
433 case HEXEN_MT_SORCBALL1:
434 case HEXEN_MT_SORCBALL2:
435 case HEXEN_MT_SORCBALL3:
436 case HEXEN_MT_SORCFX1:
437 break;
438 default:
439 if (mo->info->seesound)
440 {
441 S_StartMobjSound(mo, mo->info->seesound);
442 }
443 break;
444 }
445 return;
446 }
447 }
448
449 if (BlockingMobj && (BlockingMobj->flags2 & MF2_REFLECTIVE))
450 {
451 angle = R_PointToAngle2(BlockingMobj->x,
452 BlockingMobj->y, mo->x, mo->y);
453
454 // Change angle for delflection/reflection
455 switch (BlockingMobj->type)
456 {
457 case HEXEN_MT_CENTAUR:
458 case HEXEN_MT_CENTAURLEADER:
459 if (abs((int) angle - (int) BlockingMobj->angle) >> 24 > 45)
460 goto explode;
461 if (mo->type == HEXEN_MT_HOLY_FX)
462 goto explode;
463 // Drop through to sorcerer full reflection
464 case HEXEN_MT_SORCBOSS:
465 // Deflection
466 if (P_Random(pr_hexen) < 128)
467 angle += ANG45;
468 else
469 angle -= ANG45;
470 break;
471 default:
472 // Reflection
473 angle += ANG1 * ((P_Random(pr_hexen) % 16) - 8);
474 break;
475 }
476
477 // Reflect the missile along angle
478 mo->angle = angle;
479 angle >>= ANGLETOFINESHIFT;
480 mo->momx = FixedMul(mo->info->speed >> 1, finecosine[angle]);
481 mo->momy = FixedMul(mo->info->speed >> 1, finesine[angle]);
482 if (mo->flags2 & MF2_SEEKERMISSILE)
483 {
484 P_SetTarget(&mo->special1.m, mo->target);
485 }
486 P_SetTarget(&mo->target, BlockingMobj);
487 return;
488 }
489
490 explode:
491 // explode a missile
492 if (ceilingline &&
493 ceilingline->backsector &&
494 ceilingline->backsector->ceilingpic == skyflatnum)
495 {
496 if (raven && mo->type == g_skullpop_mt)
497 {
498 mo->momx = mo->momy = 0;
499 mo->momz = -FRACUNIT;
500 return;
501 }
502 else if (hexen && mo->type == HEXEN_MT_HOLY_FX)
503 {
504 P_ExplodeMissile(mo);
505 return;
506 }
507 else if (demo_compatibility || // killough
508 mo->z > ceilingline->backsector->ceilingheight)
509 {
510 // Hack to prevent missiles exploding
511 // against the sky.
512 // Does not handle sky floors.
513
514 P_RemoveMobj(mo);
515 return;
516 }
517 }
518 P_ExplodeMissile(mo);
519 }
520 else // whatever else it is, it is now standing still in (x,y)
521 {
522 mo->momx = mo->momy = 0;
523 }
524 }
525 } while (xmove || ymove);
526
527 /* no friction for missiles or skulls ever, no friction when airborne */
528 if (mo->flags & (MF_MISSILE | MF_SKULLFLY))
529 return;
530
531 if (
532 mo->z > mo->floorz && !(mo->flags2 & MF2_ONMOBJ) && !(mo->flags & MF_FLY) &&
533 player && mo->player && map_info.air_control > 256
534 )
535 {
536 mo->momx = FixedMul(mo->momx, map_info.air_friction);
537 mo->momy = FixedMul(mo->momy, map_info.air_friction);
538
539 player->momx = FixedMul(player->momx, map_info.air_friction);
540 player->momy = FixedMul(player->momy, map_info.air_friction);
541 return;
542 }
543
544 if (mo->z > mo->floorz &&
545 !(mo->flags & MF_FLY) &&
546 !(mo->flags2 & MF2_FLY) &&
547 !(mo->flags2 & MF2_ONMOBJ) &&
548 (!hexen || mo->type != HEXEN_MT_BLASTEFFECT))
549 return;
550
551 /* killough 8/11/98: add bouncers
552 * killough 9/15/98: add objects falling off ledges
553 * killough 11/98: only include bouncers hanging off ledges
554 */
555 if (
556 (
557 (mo->flags & MF_BOUNCES && mo->z > mo->dropoffz) ||
558 mo->flags & MF_CORPSE ||
559 mo->intflags & MIF_FALLING
560 ) &&
561 (
562 mo->momx > FRACUNIT / 4 ||
563 mo->momx < -FRACUNIT / 4 ||
564 mo->momy > FRACUNIT / 4 ||
565 mo->momy < -FRACUNIT / 4
566 ) &&
567 mo->floorz != mo->subsector->sector->floorheight
568 )
569 return; // do not stop sliding if halfway off a step with some momentum
570
571 // killough 11/98:
572 // Stop voodoo dolls that have come to rest, despite any
573 // moving corresponding player, except in old demos:
574
575 if (
576 mo->momx > -STOPSPEED && mo->momx < STOPSPEED &&
577 mo->momy > -STOPSPEED && mo->momy < STOPSPEED &&
578 !(map_format.zdoom && mo->intflags & MIF_SCROLLING) &&
579 (
580 !player ||
581 !(player->cmd.forwardmove | player->cmd.sidemove) ||
582 (
583 player->mo != mo &&
584 compatibility_level >= lxdoom_1_compatibility &&
585 (comp[comp_voodooscroller] || !(mo->intflags & MIF_SCROLLING))
586 )
587 )
588 )
589 {
590 // if in a walking frame, stop moving
591
592 // killough 10/98:
593 // Don't affect main player when voodoo dolls stop, except in old demos:
594
595 if (player)
596 {
597 if (player->chickenTics)
598 {
599 if ((unsigned)(player->mo->state - states - HERETIC_S_CHICPLAY_RUN1) < 4)
600 {
601 P_SetMobjState(player->mo, HERETIC_S_CHICPLAY);
602 }
603 }
604 else
605 {
606 if ((unsigned)(player->mo->state - states - pclass[player->pclass].run_state) < 4)
607 {
608 if (raven || player->mo == mo || compatibility_level >= lxdoom_1_compatibility)
609 {
610 P_SetMobjState(player->mo, pclass[player->pclass].normal_state);
611 }
612 }
613 }
614 }
615
616 mo->momx = mo->momy = 0;
617
618 /* killough 10/98: kill any bobbing momentum too (except in voodoo dolls)
619 * cph - DEMOSYNC - needs compatibility check?
620 */
621 if (!raven && player && player->mo == mo)
622 player->momx = player->momy = 0;
623 }
624 else
625 {
626 /* phares 3/17/98
627 *
628 * Friction will have been adjusted by friction thinkers for
629 * icy or muddy floors. Otherwise it was never touched and
630 * remained set at ORIG_FRICTION
631 *
632 * killough 8/28/98: removed inefficient thinker algorithm,
633 * instead using touching_sectorlist in P_GetFriction() to
634 * determine friction (and thus only when it is needed).
635 *
636 * killough 10/98: changed to work with new bobbing method.
637 * Reducing player momentum is no longer needed to reduce
638 * bobbing, so ice works much better now.
639 *
640 * cph - DEMOSYNC - need old code for Boom demos?
641 */
642
643 //e6y
644 if (compatibility_level <= boom_201_compatibility && !prboom_comp[PC_PRBOOM_FRICTION].state)
645 {
646 if (mo->flags2 & MF2_FLY && !(mo->z <= mo->floorz)
647 && !(mo->flags2 & MF2_ONMOBJ))
648 {
649 mo->momx = FixedMul(mo->momx, FRICTION_FLY);
650 mo->momy = FixedMul(mo->momy, FRICTION_FLY);
651 }
652 else if (
653 hexen ? P_GetThingFloorType(mo) == FLOOR_ICE :
654 heretic ? special == 15 :
655 false
656 )
657 {
658 mo->momx = FixedMul(mo->momx, FRICTION_LOW);
659 mo->momy = FixedMul(mo->momy, FRICTION_LOW);
660 }
661 else
662 {
663 // phares 3/17/98
664 // Friction will have been adjusted by friction thinkers for icy
665 // or muddy floors. Otherwise it was never touched and
666 // remained set at ORIG_FRICTION
667 mo->momx = FixedMul(mo->momx, mo->friction);
668 mo->momy = FixedMul(mo->momy, mo->friction);
669 }
670
671 mo->friction = ORIG_FRICTION; // reset to normal for next tic
672 }
673 else if (compatibility_level <= lxdoom_1_compatibility && !prboom_comp[PC_PRBOOM_FRICTION].state)
674 {
675 // phares 9/10/98: reduce bobbing/momentum when on ice & up against wall
676
677 if ((oldx == mo->x) && (oldy == mo->y)) // Did you go anywhere?
678 { // No. Use original friction. This allows you to not bob so much
679 // if you're on ice, but keeps enough momentum around to break free
680 // when you're mildly stuck in a wall.
681 mo->momx = FixedMul(mo->momx,ORIG_FRICTION);
682 mo->momy = FixedMul(mo->momy,ORIG_FRICTION);
683 }
684 else
685 { // Yes. Use stored friction.
686 mo->momx = FixedMul(mo->momx,mo->friction);
687 mo->momy = FixedMul(mo->momy,mo->friction);
688 }
689 mo->friction = ORIG_FRICTION; // reset to normal for next tic
690 }
691 else
692 {
693 fixed_t friction = P_GetFriction(mo, NULL);
694
695 mo->momx = FixedMul(mo->momx, friction);
696 mo->momy = FixedMul(mo->momy, friction);
697
698 /* killough 10/98: Always decrease player bobbing by ORIG_FRICTION.
699 * This prevents problems with bobbing on ice, where it was not being
700 * reduced fast enough, leading to all sorts of kludges being developed.
701 */
702
703 if (player && player->mo == mo) /* Not voodoo dolls */
704 {
705 player->momx = FixedMul(player->momx, ORIG_FRICTION);
706 player->momy = FixedMul(player->momy, ORIG_FRICTION);
707 }
708 }
709 }
710 }
711
712 fixed_t P_MobjGravity(mobj_t* mo)
713 {
714 return FixedMul(mo->subsector->sector->gravity, mo->gravity);
715 }
716
717 void P_AutoCorrectLookDir(player_t* player)
718 {
719 if (allow_incompatibility && dsda_MouseLook())
720 {
721 return;
722 }
723
724 player->centering = true;
725 }
726
727 //
728 // P_ZMovement
729 //
730 // Attempt vertical movement.
731
732 static void P_ZMovement (mobj_t* mo)
733 {
734 fixed_t gravity = P_MobjGravity(mo);
735
736 /* killough 7/11/98:
737 * BFG fireballs bounced on floors and ceilings in Pre-Beta Doom
738 * killough 8/9/98: added support for non-missile objects bouncing
739 * (e.g. grenade, mine, pipebomb)
740 */
741
742 if (mo->flags & MF_BOUNCES && mo->momz)
743 {
744 mo->z += mo->momz;
745 if (mo->z <= mo->floorz) /* bounce off floors */
746 {
747 mo->z = mo->floorz;
748 if (mo->momz < 0)
749 {
750 mo->momz = -mo->momz;
751 if (!(mo->flags & MF_NOGRAVITY)) /* bounce back with decay */
752 {
753 mo->momz = mo->flags & MF_FLOAT ? // floaters fall slowly
754 mo->flags & MF_DROPOFF ? // DROPOFF indicates rate
755 FixedMul(mo->momz, (fixed_t)(FRACUNIT*.85)) :
756 FixedMul(mo->momz, (fixed_t)(FRACUNIT*.70)) :
757 FixedMul(mo->momz, (fixed_t)(FRACUNIT*.45)) ;
758
759 /* Bring it to rest below a certain speed */
760 if (D_abs(mo->momz) <= mo->info->mass * (gravity * 4 / 256))
761 mo->momz = 0;
762 }
763
764 /* killough 11/98: touchy objects explode on impact */
765 if (mo->flags & MF_TOUCHY && mo->intflags & MIF_ARMED
766 && mo->health > 0)
767 P_DamageMobj(mo, NULL, NULL, mo->health);
768 else if (mo->flags & MF_FLOAT && sentient(mo))
769 goto floater;
770 return;
771 }
772 }
773 else if (mo->z >= mo->ceilingz - mo->height)
774 {
775 /* bounce off ceilings */
776 mo->z = mo->ceilingz - mo->height;
777 if (mo->momz > 0)
778 {
779 if (mo->subsector->sector->ceilingpic != skyflatnum)
780 mo->momz = -mo->momz; /* always bounce off non-sky ceiling */
781 else if (mo->flags & MF_MISSILE)
782 P_RemoveMobj(mo); /* missiles don't bounce off skies */
783 else if (mo->flags & MF_NOGRAVITY)
784 mo->momz = -mo->momz; // bounce unless under gravity
785
786 if (mo->flags & MF_FLOAT && sentient(mo))
787 goto floater;
788
789 return;
790 }
791 }
792 else
793 {
794 if (!(mo->flags & MF_NOGRAVITY)) /* free-fall under gravity */
795 mo->momz -= mo->info->mass * (gravity / 256);
796
797 if (mo->flags & MF_FLOAT && sentient(mo)) goto floater;
798 return;
799 }
800
801 /* came to a stop */
802 mo->momz = 0;
803
804 if (mo->flags & MF_MISSILE)
805 {
806 if (ceilingline &&
807 ceilingline->backsector &&
808 ceilingline->backsector->ceilingpic == skyflatnum &&
809 mo->z > ceilingline->backsector->ceilingheight)
810 P_RemoveMobj(mo); /* don't explode on skies */
811 else
812 P_ExplodeMissile(mo);
813 }
814
815 if (mo->flags & MF_FLOAT && sentient(mo)) goto floater;
816 return;
817 }
818
819 /* killough 8/9/98: end bouncing object code */
820
821 // check for smooth step up
822
823 if (mo->player && //e6y: restoring original visual behaviour for demo_compatibility
824 (demo_compatibility || mo->player->mo == mo) && // killough 5/12/98: exclude voodoo dolls
825 mo->z < mo->floorz)
826 {
827 mo->player->viewheight -= mo->floorz - mo->z;
828 mo->player->deltaviewheight = (g_viewheight - mo->player->viewheight) >> 3;
829 }
830
831 // adjust altitude
832
833 mo->z += mo->momz;
834
835 floater:
836 if ((mo->flags & MF_FLOAT) && mo->target)
837
838 // float down towards target if too close
839
840 if (!(mo->flags & MF_SKULLFLY) && !(mo->flags & MF_INFLOAT))
841 {
842 fixed_t delta;
843 if (P_AproxDistance(mo->x - mo->target->x, mo->y - mo->target->y) <
844 D_abs(delta = mo->target->z + (mo->height >> 1) - mo->z) * 3)
845 mo->z += delta < 0 ? -FLOATSPEED : FLOATSPEED;
846 }
847
848 if (mo->player && (mo->flags & MF_FLY) && (mo->z > mo->floorz))
849 {
850 mo->z += finesine[(FINEANGLES/80*gametic)&FINEMASK]/8;
851 mo->momz = FixedMul (mo->momz, FRICTION_FLY);
852 }
853
854 if (mo->player && mo->flags2 & MF2_FLY && !(mo->z <= mo->floorz)
855 && leveltime & 2)
856 {
857 mo->z += finesine[(FINEANGLES / 20 * leveltime >> 2) & FINEMASK];
858 }
859
860 // clip movement
861
862 if (mo->z <= mo->floorz)
863 {
864 // hit the floor
865
866 if (raven)
867 {
868 if (mo->flags & MF_MISSILE)
869 {
870 mo->z = mo->floorz;
871 if (mo->flags2 & MF2_FLOORBOUNCE)
872 {
873 P_FloorBounceMissile(mo);
874 return;
875 }
876 else if (
877 raven && (
878 mo->type == HERETIC_MT_MNTRFX2 ||
879 mo->type == HEXEN_MT_MNTRFX2 ||
880 mo->type == HEXEN_MT_LIGHTNING_FLOOR
881 )
882 )
883 { // Minotaur floor fire can go up steps
884 return;
885 }
886 else if (hexen && mo->type == HEXEN_MT_HOLY_FX)
887 { // The spirit struck the ground
888 mo->momz = 0;
889 P_HitFloor(mo);
890 return;
891 }
892 else
893 {
894 if (hexen)
895 P_HitFloor(mo);
896 P_ExplodeMissile(mo);
897 return;
898 }
899 }
900
901 if (hexen && mo->flags & MF_COUNTKILL) // Blasted mobj falling
902 {
903 if (mo->momz < -(23 * FRACUNIT))
904 {
905 P_DamageMobj(mo, NULL, NULL, 10000);
906 }
907 }
908
909 if (mo->z - mo->momz > mo->floorz)
910 { // Spawn splashes, etc.
911 P_HitFloor(mo);
912 }
913 }
914
915 /* Note (id):
916 * somebody left this after the setting momz to 0,
917 * kinda useless there.
918 * cph - This was the a bug in the linuxdoom-1.10 source which
919 * caused it not to sync Doom 2 v1.9 demos. Someone
920 * added the above comment and moved up the following code. So
921 * demos would desync in close lost soul fights.
922 * cph - revised 2001/04/15 -
923 * This was a bug in the Doom/Doom 2 source; the following code
924 * is meant to make charging lost souls bounce off of floors, but it
925 * was incorrectly placed after momz was set to 0.
926 * However, this bug was fixed in Doom95, Final/Ultimate Doom, and
927 * the v1.10 source release (which is one reason why it failed to sync
928 * some Doom2 v1.9 demos)
929 * I've added a comp_soul compatibility option to make this behavior
930 * selectable for PrBoom v2.3+. For older demos, we do this here only
931 * if we're in a compatibility level above Doom 2 v1.9 (in which case we
932 * mimic the bug and do it further down instead)
933 */
934
935 if (
936 mo->flags & MF_SKULLFLY &&
937 (
938 !comp[comp_soul] ||
939 (
940 compatibility_level > doom2_19_compatibility &&
941 compatibility_level < prboom_4_compatibility
942 )
943 )
944 )
945 mo->momz = -mo->momz; // the skull slammed into something
946
947 if (hexen) mo->z = mo->floorz;
948 if (mo->momz < 0)
949 {
950 /* killough 11/98: touchy objects explode on impact */
951 if (mo->flags & MF_TOUCHY && mo->intflags & MIF_ARMED && mo->health > 0)
952 P_DamageMobj(mo, NULL, NULL, mo->health);
953 else
954 {
955 if (mo->flags2 & MF2_ICEDAMAGE && mo->momz < -gravity * 8)
956 {
957 mo->tics = 1;
958 mo->momx = 0;
959 mo->momy = 0;
960 mo->momz = 0;
961 return;
962 }
963 // heretic_note: probably not necessary?
964 if (!heretic && mo->player)
965 mo->player->jumpTics = 7;
966 if (
967 mo->player && /* killough 5/12/98: exclude voodoo dolls */
968 // e6y
969 // Restoring original visual behaviour for demo_compatibility.
970 // Viewheight of consoleplayer should be decreased for a moment
971 // after voodoo doll hits the ground.
972 // This additional condition makes sense only for plutonia complevel
973 // when voodoo doll falls down after teleporting,
974 // but can be applied globally for all demo_compatibility complevels,
975 // because original sources do not exclude voodoo dolls from condition above,
976 // but Boom does it.
977 (demo_compatibility || mo->player->mo == mo) &&
978 mo->momz < -gravity * 8 &&
979 !(mo->flags2 & MF2_FLY)
980 )
981 {
982 // Squat down.
983 // Decrease viewheight for a moment
984 // after hitting the ground (hard),
985 // and utter appropriate sound.
986
987 mo->player->deltaviewheight = mo->momz >> 3;
988
989 if (heretic)
990 {
991 S_StartMobjSound(mo, heretic_sfx_plroof);
992 P_AutoCorrectLookDir(mo->player);
993 }
994 else if (hexen)
995 {
996 if (mo->momz < -23 * FRACUNIT)
997 {
998 P_FallingDamage(mo->player);
999 P_NoiseAlert(mo, mo);
1000 }
1001 else if (mo->momz < -gravity * 12 && !mo->player->morphTics)
1002 {
1003 S_StartMobjSound(mo, hexen_sfx_player_land);
1004 switch (mo->player->pclass)
1005 {
1006 case PCLASS_FIGHTER:
1007 S_StartMobjSound(mo, hexen_sfx_player_fighter_grunt);
1008 break;
1009 case PCLASS_CLERIC:
1010 S_StartMobjSound(mo, hexen_sfx_player_cleric_grunt);
1011 break;
1012 case PCLASS_MAGE:
1013 S_StartMobjSound(mo, hexen_sfx_player_mage_grunt);
1014 break;
1015 default:
1016 break;
1017 }
1018 }
1019 else if (P_GetThingFloorType(mo) < FLOOR_LIQUID && !mo->player->morphTics)
1020 {
1021 S_StartMobjSound(mo, hexen_sfx_player_land);
1022 }
1023 P_AutoCorrectLookDir(mo->player);
1024 }
1025 //e6y: compatibility optioned
1026 else if (comp[comp_sound] || (mo->health > 0)) /* cph - prevent "oof" when dead */
1027 S_StartSound (mo, sfx_oof);
1028 }
1029 else if (hexen && mo->type >= HEXEN_MT_POTTERY1 && mo->type <= HEXEN_MT_POTTERY3)
1030 {
1031 P_DamageMobj(mo, NULL, NULL, 25);
1032 }
1033 }
1034 mo->momz = 0;
1035 }
1036 if (!hexen) mo->z = mo->floorz;
1037
1038 /* cph 2001/04/15 -
1039 * This is the buggy lost-soul bouncing code referenced above.
1040 * We've already set momz = 0 normally by this point, so it's useless.
1041 * However we might still have upward momentum, in which case this will
1042 * incorrectly reverse it, so we might still need this for demo sync
1043 */
1044 if (mo->flags & MF_SKULLFLY &&
1045 compatibility_level <= doom2_19_compatibility)
1046 mo->momz = -mo->momz; // the skull slammed into something
1047
1048 if (mo->info->crashstate && (mo->flags & MF_CORPSE) && !(mo->flags2 & MF2_ICEDAMAGE))
1049 {
1050 P_SetMobjState(mo, mo->info->crashstate);
1051 return;
1052 }
1053
1054 if (!raven && (mo->flags & MF_MISSILE) && !(mo->flags & MF_NOCLIP))
1055 {
1056 P_ExplodeMissile (mo);
1057 return;
1058 }
1059 }
1060 else if (mo->flags2 & MF2_LOGRAV)
1061 {
1062 if (mo->momz == 0)
1063 mo->momz = -(gravity >> 3) * 2;
1064 else
1065 mo->momz -= gravity >> 3;
1066 }
1067 else if (!(mo->flags & MF_NOGRAVITY))
1068 {
1069 if (mo->momz == 0)
1070 mo->momz = -gravity;
1071 mo->momz -= gravity;
1072 }
1073
1074 if (mo->z + mo->height > mo->ceilingz)
1075 {
1076 /* cph 2001/04/15 -
1077 * Lost souls were meant to bounce off of ceilings;
1078 * new comp_soul compatibility option added
1079 */
1080 if (!comp[comp_soul] && mo->flags & MF_SKULLFLY)
1081 mo->momz = -mo->momz; // the skull slammed into something
1082
1083 // hit the ceiling
1084
1085 if (mo->momz > 0)
1086 mo->momz = 0;
1087
1088 mo->z = mo->ceilingz - mo->height;
1089
1090 if (hexen && mo->flags2 & MF2_FLOORBOUNCE)
1091 {
1092 if (mo->info->seesound)
1093 {
1094 S_StartMobjSound(mo, mo->info->seesound);
1095 }
1096 return;
1097 }
1098
1099 /* cph 2001/04/15 -
1100 * We might have hit a ceiling but had downward momentum (e.g. ceiling is
1101 * lowering on us), so for old demos we must still do the buggy
1102 * momentum reversal here
1103 */
1104 if (comp[comp_soul] && mo->flags & MF_SKULLFLY)
1105 mo->momz = -mo->momz; // the skull slammed into something
1106
1107 if ((mo->flags & MF_MISSILE) && (hexen || !(mo->flags & MF_NOCLIP)))
1108 {
1109 if (hexen && mo->type == HEXEN_MT_LIGHTNING_CEILING)
1110 {
1111 return;
1112 }
1113 if (raven && mo->subsector->sector->ceilingpic == skyflatnum)
1114 {
1115 if (mo->type == g_skullpop_mt)
1116 {
1117 mo->momx = mo->momy = 0;
1118 mo->momz = -FRACUNIT;
1119 }
1120 else if (mo->type == HEXEN_MT_HOLY_FX)
1121 {
1122 P_ExplodeMissile(mo);
1123 }
1124 else
1125 {
1126 P_RemoveMobj(mo);
1127 }
1128 return;
1129 }
1130 P_ExplodeMissile (mo);
1131 return;
1132 }
1133 }
1134 }
1135
1136 //
1137 // P_NightmareRespawn
1138 //
1139
1140 static void P_NightmareRespawn(mobj_t* mobj)
1141 {
1142 fixed_t x;
1143 fixed_t y;
1144 fixed_t z;
1145 sector_t* sec;
1146 mobj_t* mo;
1147 mapthing_t* mthing;
1148
1149 x = mobj->spawnpoint.x;
1150 y = mobj->spawnpoint.y;
1151
1152 /* haleyjd: stupid nightmare respawning bug fix
1153 *
1154 * 08/09/00: compatibility added, time to ramble :)
1155 * This fixes the notorious nightmare respawning bug that causes monsters
1156 * that didn't spawn at level startup to respawn at the point (0,0)
1157 * regardless of that point's nature. SMMU and Eternity need this for
1158 * script-spawned things like Halif Swordsmythe, as well.
1159 *
1160 * cph - copied from eternity, alias comp_respawnfix
1161 */
1162 if(!comp[comp_respawn] && !x && !y)
1163 {
1164 // spawnpoint was zeroed out, so use point of death instead
1165 x = mobj->x;
1166 y = mobj->y;
1167 }
1168
1169 // something is occupying its position?
1170
1171 if (!P_CheckPosition (mobj, x, y) )
1172 return; // no respwan
1173
1174 // spawn a teleport fog at old spot
1175 // because of removal of the body?
1176
1177 mo = P_SpawnMobj (mobj->x,
1178 mobj->y,
1179 mobj->subsector->sector->floorheight + g_telefog_height,
1180 g_mt_tfog);
1181
1182 // initiate teleport sound
1183
1184 S_StartSound (mo, g_sfx_telept);
1185
1186 // spawn a teleport fog at the new spot
1187
1188 sec = R_PointInSector (x,y);
1189
1190 mo = P_SpawnMobj (x, y, sec->floorheight + g_telefog_height, g_mt_tfog);
1191
1192 S_StartSound (mo, g_sfx_telept);
1193
1194 // spawn the new monster
1195
1196 mthing = &mobj->spawnpoint;
1197 if (mobj->info->flags & MF_SPAWNCEILING)
1198 z = ONCEILINGZ;
1199 else
1200 z = ONFLOORZ;
1201
1202 // inherit attributes from deceased one
1203
1204 mo = P_SpawnMobj (x,y,z, mobj->type);
1205 mo->spawnpoint = mobj->spawnpoint;
1206 mo->angle = ANG45 * (mthing->angle/45);
1207 mo->index = mobj->index;
1208
1209 // "bug" in the respawn code for heretic
1210 // the chicken's return type is stored in special2.i
1211 // that value didn't exist in doom so is left uninitialized on respawn
1212 // we have to set this to the MT zero value for heretic
1213 if (heretic && mo->type == HERETIC_MT_CHICKEN)
1214 mo->special2.i = HERETIC_MT_ZERO;
1215
1216 if (hexen && mo->type == HEXEN_MT_PIG)
1217 mo->special2.i = HEXEN_MT_ZERO;
1218
1219 if (mthing->options & MTF_AMBUSH)
1220 mo->flags |= MF_AMBUSH;
1221
1222 /* killough 11/98: transfer friendliness from deceased */
1223 mo->flags = (mo->flags & ~MF_FRIEND) | (mobj->flags & MF_FRIEND);
1224 mo->flags = mo->flags | MF_RESSURECTED;//e6y
1225
1226 mo->reactiontime = 18;
1227
1228 // remove the old monster,
1229
1230 P_RemoveMobj (mobj);
1231 }
1232
1233 fixed_t FloatBobOffsets[64] = {
1234 0, 51389, 102283, 152192,
1235 200636, 247147, 291278, 332604,
1236 370727, 405280, 435929, 462380,
1237 484378, 501712, 514213, 521763,
1238 524287, 521763, 514213, 501712,
1239 484378, 462380, 435929, 405280,
1240 370727, 332604, 291278, 247147,
1241 200636, 152192, 102283, 51389,
1242 -1, -51390, -102284, -152193,
1243 -200637, -247148, -291279, -332605,
1244 -370728, -405281, -435930, -462381,
1245 -484380, -501713, -514215, -521764,
1246 -524288, -521764, -514214, -501713,
1247 -484379, -462381, -435930, -405280,
1248 -370728, -332605, -291279, -247148,
1249 -200637, -152193, -102284, -51389
1250 };
1251
1252 //
1253 // P_MobjThinker
1254 //
1255
1256 static void PlayerLandedOnThing(mobj_t * mo, mobj_t * onmobj, fixed_t gravity);
1257
1258 void P_MobjThinker (mobj_t* mobj)
1259 {
1260 // killough 11/98:
1261 // removed old code which looked at target references
1262 // (we use pointer reference counting now)
1263
1264 if (mobj->type == MT_MUSICSOURCE)
1265 {
1266 MusInfoThinker(mobj);
1267 return;
1268 }
1269
1270 mobj->PrevX = mobj->x;
1271 mobj->PrevY = mobj->y;
1272 mobj->PrevZ = mobj->z;
1273
1274 // momentum movement
1275 BlockingMobj = NULL;
1276 if (mobj->momx | mobj->momy || mobj->flags & MF_SKULLFLY)
1277 {
1278 P_XYMovement(mobj);
1279 mobj->intflags &= ~MIF_SCROLLING;
1280 if (mobj->thinker.function != P_MobjThinker) // cph - Must've been removed
1281 return; // killough - mobj was removed
1282 }
1283 else if (mobj->flags2 & MF2_BLASTED)
1284 { // Reset to not blasted when momentums are gone
1285 ResetBlasted(mobj);
1286 }
1287
1288 if (mobj->flags2 & MF2_FLOATBOB)
1289 { // Floating item bobbing motion
1290 mobj->z = mobj->floorz +
1291 (hexen ? mobj->special1.i : 0) + FloatBobOffsets[(mobj->health++) & 63];
1292 }
1293 else if (mobj->z != mobj->floorz || mobj->momz || BlockingMobj)
1294 {
1295 if (mobj->flags2 & MF2_PASSMOBJ)
1296 {
1297 mobj_t *onmo;
1298
1299 if (!(onmo = P_CheckOnmobj(mobj)))
1300 {
1301 P_ZMovement(mobj);
1302
1303 // This bug is part of the original source
1304 if (hexen && mobj->player && mobj->flags & MF2_ONMOBJ)
1305 {
1306 mobj->flags2 &= ~MF2_ONMOBJ;
1307 }
1308
1309 if (map_format.zdoom)
1310 {
1311 mobj->flags2 &= ~MF2_ONMOBJ;
1312 }
1313 }
1314 else
1315 {
1316 if (mobj->player)
1317 {
1318 if (map_format.hexen)
1319 {
1320 fixed_t gravity = P_MobjGravity(mobj);
1321
1322 if (hexen && mobj->momz < -gravity * 8 && !(mobj->flags2 & MF2_FLY))
1323 {
1324 PlayerLandedOnThing(mobj, onmo, gravity);
1325 }
1326 if (onmo->z + onmo->height - mobj->z <= 24 * FRACUNIT)
1327 {
1328 mobj->player->viewheight -= onmo->z + onmo->height - mobj->z;
1329 mobj->player->deltaviewheight = (g_viewheight - mobj->player->viewheight) >> 3;
1330 mobj->z = onmo->z + onmo->height;
1331 mobj->flags2 |= MF2_ONMOBJ;
1332 mobj->momz = 0;
1333 }
1334 else
1335 { // hit the bottom of the blocking mobj
1336 mobj->momz = 0;
1337 }
1338 }
1339 else
1340 {
1341 if (mobj->momz < 0)
1342 {
1343 mobj->flags2 |= MF2_ONMOBJ;
1344 mobj->momz = 0;
1345 }
1346 if (onmo->player || onmo->type == HERETIC_MT_POD)
1347 {
1348 mobj->momx = onmo->momx;
1349 mobj->momy = onmo->momy;
1350 if (onmo->z < onmo->floorz)
1351 {
1352 mobj->z += onmo->floorz - onmo->z;
1353 if (onmo->player)
1354 {
1355 onmo->player->viewheight -= onmo->floorz - onmo->z;
1356 onmo->player->deltaviewheight = (g_viewheight - onmo->player->viewheight) >> 3;
1357 }
1358 onmo->z = onmo->floorz;
1359 }
1360 }
1361 }
1362 }
1363 else if (map_format.zdoom)
1364 {
1365 mobj->momz = 0;
1366
1367 if (onmo->z + onmo->height - mobj->z <= 24 * FRACUNIT)
1368 {
1369 mobj->z = onmo->z + onmo->height;
1370 mobj->flags2 |= MF2_ONMOBJ;
1371 }
1372 }
1373 }
1374 }
1375 else
1376 P_ZMovement(mobj);
1377 if (mobj->thinker.function != P_MobjThinker) // cph - Must've been removed
1378 return; // killough - mobj was removed
1379 }
1380 // raven_note: are the intflags irrelevant when compatibility is enabled?
1381 else if (!raven && !(mobj->momx | mobj->momy) && !sentient(mobj))
1382 { // non-sentient objects at rest
1383 mobj->intflags |= MIF_ARMED; // arm a mine which has come to rest
1384
1385 // killough 9/12/98: objects fall off ledges if they are hanging off
1386 // slightly push off of ledge if hanging more than halfway off
1387
1388 if (mobj->z > mobj->dropoffz && // Only objects contacting dropoff
1389 !(mobj->flags & MF_NOGRAVITY) && // Only objects which fall
1390 !comp[comp_falloff]) // Not in old demos
1391 P_ApplyTorque(mobj); // Apply torque
1392 else
1393 mobj->intflags &= ~MIF_FALLING, mobj->gear = 0; // Reset torque
1394 }
1395
1396 if (map_format.mobj_in_special_sector(mobj))
1397 return;
1398
1399 // cycle through states,
1400 // calling action functions at transitions
1401 if (mobj->tics != -1)
1402 {
1403 mobj->tics--;
1404
1405 // you can cycle through multiple states in a tic
1406
1407 // raven's cycle code is only here (i.e., not in every call to P_SetMobjState)
1408 // not sure about ramifications of moving loop inside all state calls
1409 if (raven)
1410 {
1411 while (!mobj->tics)
1412 if (!P_SetMobjState(mobj, mobj->state->nextstate))
1413 return; // freed itself
1414 }
1415 else
1416 {
1417 if (!mobj->tics)
1418 if (!P_SetMobjState(mobj, mobj->state->nextstate))
1419 return; // freed itself
1420 }
1421 }
1422 else
1423 {
1424 // check for nightmare respawn
1425
1426 if (! (mobj->flags & MF_COUNTKILL) )
1427 return;
1428
1429 if (!skill_info.respawn_time)
1430 return;
1431
1432 mobj->movecount++;
1433
1434 if (mobj->movecount < skill_info.respawn_time * 35)
1435 return;
1436
1437 if (leveltime & 31)
1438 return;
1439
1440 if (P_Random(pr_respawn) > 4)
1441 return;
1442
1443 P_NightmareRespawn (mobj);
1444 }
1445 }
1446
1447
1448 // Certain functions assume that a mobj_t pointer is non-NULL,
1449 // causing a crash in some situations where it is NULL. Vanilla
1450 // Doom did not crash because of the lack of proper memory
1451 // protection. This function substitutes NULL pointers for
1452 // pointers to a dummy mobj, to avoid a crash.
1453 mobj_t *P_SubstNullMobj(mobj_t *mobj)
1454 {
1455 if (mobj == NULL)
1456 {
1457 static mobj_t dummy_mobj;
1458
1459 dummy_mobj.x = 0;
1460 dummy_mobj.y = 0;
1461 dummy_mobj.z = 0;
1462 dummy_mobj.flags = 0;
1463
1464 mobj = &dummy_mobj;
1465 }
1466
1467 return mobj;
1468 }
1469
1470 /*
1471 * P_FindDoomedNum
1472 *
1473 * Finds a mobj type with a matching doomednum
1474 *
1475 * killough 8/24/98: rewrote to use hashing
1476 */
1477
1478 static dboolean P_IsTypeMatch(unsigned doomednum, int type)
1479 {
1480 return (unsigned) mobjinfo[type].doomednum == doomednum &&
1481 mobjinfo[type].visibility & map_format.visibility;
1482 }
1483
1484 static PUREFUNC int P_FindDoomedNum(unsigned type)
1485 {
1486 static struct { int first, next; } *hash;
1487 register int i;
1488
1489 if (!hash)
1490 {
1491 hash = Z_Malloc(sizeof(*hash) * num_mobj_types);
1492
1493 for (i = 0; i < num_mobj_types; i++)
1494 hash[i].first = num_mobj_types;
1495
1496 for (i = mobj_types_zero; i < num_mobj_types; i++)
1497 if (mobjinfo[i].doomednum != -1)
1498 {
1499 unsigned h = (unsigned) mobjinfo[i].doomednum % num_mobj_types;
1500 hash[i].next = hash[h].first;
1501 hash[h].first = i;
1502 }
1503 }
1504
1505 i = hash[type % num_mobj_types].first;
1506 while (i < num_mobj_types && !P_IsTypeMatch(type, i))
1507 i = hash[i].next;
1508
1509 return i;
1510 }
1511
1512 dboolean P_SpawnProjectile(short thing_id, mobj_t *source, int spawn_num, angle_t angle,
1513 fixed_t speed, fixed_t vspeed, short dest_id, mobj_t *forcedest,
1514 int gravity, short new_thing_id)
1515 {
1516 int type;
1517 dboolean is_monster;
1518 dboolean success = false;
1519 thing_id_search_t search;
1520 thing_id_search_t dest_search;
1521 mobj_t *spawn_location;
1522 mobj_t *destination;
1523 mobj_t *new_mobj;
1524
1525 type = dsda_ThingTypeFromSpawnNumber(spawn_num);
1526
1527 if (type == num_mobj_types)
1528 return false;
1529
1530 is_monster = (type == MT_SKULL || (mobjinfo[type].flags & MF_COUNTKILL));
1531
1532 if (nomonsters && is_monster)
1533 return false;
1534
1535 dsda_ResetThingIDSearch(&search);
1536 while ((spawn_location = dsda_FindMobjFromThingIDOrMobj(thing_id, source, &search)))
1537 {
1538 dsda_ResetThingIDSearch(&dest_search);
1539 destination = dsda_FindMobjFromThingIDOrMobj(dest_id, forcedest, &dest_search);
1540
1541 if (!dest_id || destination)
1542 {
1543 do
1544 {
1545 new_mobj = P_SpawnMobj(spawn_location->x, spawn_location->y, spawn_location->z, type);
1546 if (new_mobj)
1547 {
1548 if (new_thing_id)
1549 dsda_AddMobjThingID(new_mobj, new_thing_id);
1550
1551 if (new_mobj->info->seesound)
1552 {
1553 S_StartMobjSound(new_mobj, new_mobj->info->seesound);
1554 }
1555
1556 if (gravity)
1557 {
1558 new_mobj->flags &= ~MF_NOGRAVITY;
1559 if (!is_monster && gravity == 1)
1560 {
1561 new_mobj->flags2 |= MF2_LOGRAV;
1562 }
1563 }
1564 else
1565 {
1566 new_mobj->flags |= MF_NOGRAVITY;
1567 }
1568
1569 P_SetTarget(&new_mobj->target, spawn_location);
1570
1571 if (destination)
1572 {
1573 fixed_t aimx, aimy, aimz;
1574 fixed_t slope;
1575
1576 aimx = destination->x - new_mobj->x;
1577 aimy = destination->y - new_mobj->y;
1578 aimz = destination->z + destination->height / 2 - new_mobj->z;
1579 slope = FixedDiv(aimz, P_AproxDistance(aimx, aimy));
1580 new_mobj->angle = R_PointToAngle2(0, 0, aimx, aimy);
1581 new_mobj->momx = FixedMul(speed, finecosine[new_mobj->angle >> ANGLETOFINESHIFT]);
1582 new_mobj->momy = FixedMul(speed, finesine[new_mobj->angle >> ANGLETOFINESHIFT]);
1583 new_mobj->momz = FixedMul(speed, slope);
1584 }
1585 else
1586 {
1587 new_mobj->angle = angle;
1588 new_mobj->momx = FixedMul(speed, finecosine[new_mobj->angle >> ANGLETOFINESHIFT]);
1589 new_mobj->momy = FixedMul(speed, finesine[new_mobj->angle >> ANGLETOFINESHIFT]);
1590 new_mobj->momz = vspeed;
1591 }
1592
1593 new_mobj->flags |= MF_DROPPED; // Don't respawn
1594
1595 if (new_mobj->flags & MF_MISSILE)
1596 {
1597 if (P_CheckMissileSpawn(new_mobj))
1598 {
1599 success = true;
1600 }
1601 }
1602 else if (P_TestMobjLocation(new_mobj))
1603 {
1604 success = true;
1605 }
1606 else
1607 {
1608 dsda_WatchFailedSpawn(new_mobj);
1609 P_RemoveMobj(new_mobj);
1610 }
1611 }
1612 } while (dest_id && (destination = dsda_FindMobjFromThingIDOrMobj(dest_id, forcedest, &dest_search)));
1613 }
1614 }
1615
1616 return success;
1617 }
1618
1619 dboolean P_SpawnThing(short thing_id, mobj_t *source, int spawn_num,
1620 angle_t angle, dboolean fog, short new_thing_id)
1621 {
1622 int type;
1623 dboolean success = false;
1624 thing_id_search_t search;
1625 mobj_t *spawn_location;
1626 mobj_t *new_mobj;
1627
1628 type = dsda_ThingTypeFromSpawnNumber(spawn_num);
1629
1630 if (type == num_mobj_types)
1631 return false;
1632
1633 if (nomonsters && (type == MT_SKULL || (mobjinfo[type].flags & MF_COUNTKILL)))
1634 return false;
1635
1636 dsda_ResetThingIDSearch(&search);
1637 while ((spawn_location = dsda_FindMobjFromThingIDOrMobj(thing_id, source, &search)))
1638 {
1639 new_mobj = P_SpawnMobj(spawn_location->x, spawn_location->y, spawn_location->z, type);
1640 if (!P_TestMobjLocation(new_mobj))
1641 {
1642 dsda_WatchFailedSpawn(new_mobj);
1643 P_RemoveMobj(new_mobj);
1644 }
1645 else
1646 {
1647 new_mobj->angle = angle == ANGLE_MAX ? spawn_location->angle : angle;
1648 if (fog)
1649 {
1650 mobj_t *fog_mobj;
1651 fog_mobj = P_SpawnMobj(spawn_location->x, spawn_location->y,
1652 spawn_location->z + TELEFOGHEIGHT, g_mt_tfog);
1653 S_StartMobjSound(fog_mobj, g_sfx_telept);
1654 }
1655 if (new_thing_id)
1656 dsda_AddMobjThingID(new_mobj, new_thing_id);
1657 new_mobj->flags |= MF_DROPPED; // Don't respawn
1658 success = true;
1659 }
1660 }
1661
1662 return success;
1663 }
1664
1665 int P_MobjSpawnHealth(const mobj_t* mobj)
1666 {
1667 int result;
1668
1669 if (mobj->type == MT_SKULL || mobj->flags & MF_COUNTKILL)
1670 {
1671 if (mobj->flags & MF_FRIEND)
1672 {
1673 if (skill_info.friend_health_factor)
1674 {
1675 result = FixedMul(mobj->info->spawnhealth, skill_info.friend_health_factor);
1676
1677 return result > 0 ? result : 1;
1678 }
1679 }
1680 else if (skill_info.monster_health_factor)
1681 {
1682 result = FixedMul(mobj->info->spawnhealth, skill_info.monster_health_factor);
1683
1684 return result > 0 ? result : 1;
1685 }
1686 }
1687
1688 return mobj->info->spawnhealth;
1689 }
1690
1691 //
1692 // P_SpawnMobj
1693 //
1694 mobj_t* P_SpawnMobj(fixed_t x,fixed_t y,fixed_t z,mobjtype_t type)
1695 {
1696 mobj_t* mobj;
1697 state_t* st;
1698 mobjinfo_t* info;
1699
1700 mobj = Z_MallocLevel (sizeof(*mobj));
1701 memset (mobj, 0, sizeof (*mobj));
1702 info = &mobjinfo[type];
1703 mobj->type = type;
1704 mobj->info = info;
1705 mobj->x = x;
1706 mobj->y = y;
1707 mobj->radius = info->radius;
1708 mobj->height = info->height; // phares
1709 mobj->flags = info->flags;
1710 mobj->flags2 = info->flags2;
1711 if (raven) mobj->damage = info->damage;
1712
1713 /* killough 8/23/98: no friends, bouncers, or touchy things in old demos */
1714 if (!mbf_features)
1715 mobj->flags &= ~(MF_BOUNCES | MF_FRIEND | MF_TOUCHY);
1716 else
1717 if (type == g_mt_player) // Except in old demos, players
1718 mobj->flags |= MF_FRIEND; // are always friends.
1719
1720 if (map_info.flags & MI_PASSOVER && mobj->flags & MF_SOLID)
1721 mobj->flags2 |= MF2_PASSMOBJ;
1722
1723 mobj->health = P_MobjSpawnHealth(mobj);
1724
1725 if (!(skill_info.flags & SI_INSTANT_REACTION))
1726 mobj->reactiontime = info->reactiontime;
1727
1728 if (type != ZMT_AMBIENTSOUND)
1729 mobj->lastlook = P_Random (pr_lastlook) % g_maxplayers;
1730
1731 // do not set the state with P_SetMobjState,
1732 // because action routines can not be called yet
1733
1734 st = &states[info->spawnstate];
1735
1736 mobj->state = st;
1737 mobj->tics = st->tics;
1738 mobj->sprite = st->sprite;
1739 mobj->frame = st->frame;
1740 mobj->touching_sectorlist = NULL; // NULL head of sector list // phares 3/13/98
1741
1742 // set subsector and/or block links
1743
1744 P_SetThingPosition (mobj);
1745
1746 mobj->dropoffz = /* killough 11/98: for tracking dropoffs */
1747 mobj->floorz = mobj->subsector->sector->floorheight;
1748 mobj->ceilingz = mobj->subsector->sector->ceilingheight;
1749
1750 if (z == ONFLOORZ)
1751 {
1752 mobj->z = mobj->floorz;
1753 }
1754 else if (z == ONCEILINGZ)
1755 {
1756 mobj->z = mobj->ceilingz - mobj->height;
1757 }
1758 else if (raven && z == FLOATRANDZ)
1759 {
1760 fixed_t space;
1761
1762 space = ((mobj->ceilingz) - (mobj->height)) - mobj->floorz;
1763 if (space > 48 * FRACUNIT)
1764 {
1765 space -= 40 * FRACUNIT;
1766 mobj->z =
1767 ((space * P_Random(pr_heretic)) >> 8) + mobj->floorz + 40 * FRACUNIT;
1768 }
1769 else
1770 {
1771 mobj->z = mobj->floorz;
1772 }
1773 }
1774 else if (hexen && mobj->flags2 & MF2_FLOATBOB)
1775 {
1776 mobj->z = mobj->floorz + z; // artifact z passed in as height
1777 }
1778 else
1779 {
1780 mobj->z = z;
1781 }
1782
1783 if (hexen)
1784 {
1785 if (mobj->flags2 & MF2_FOOTCLIP
1786 && P_GetThingFloorType(mobj) >= FLOOR_LIQUID
1787 && mobj->z == mobj->subsector->sector->floorheight)
1788 {
1789 mobj->floorclip = 10 * FRACUNIT;
1790 }
1791 else
1792 {
1793 mobj->floorclip = 0;
1794 }
1795 }
1796 else
1797 {
1798 if (mobj->flags2 & MF2_FOOTCLIP
1799 && P_GetThingFloorType(mobj) != FLOOR_SOLID
1800 && mobj->floorz == mobj->subsector->sector->floorheight)
1801 {
1802 mobj->flags2 |= MF2_FEETARECLIPPED;
1803 }
1804 else
1805 {
1806 mobj->flags2 &= ~MF2_FEETARECLIPPED;
1807 }
1808 }
1809
1810 mobj->PrevX = mobj->x;
1811 mobj->PrevY = mobj->y;
1812 mobj->PrevZ = mobj->z;
1813
1814 mobj->thinker.function = P_MobjThinker;
1815
1816 //e6y
1817 mobj->friction = ORIG_FRICTION; // phares 3/17/98
1818 mobj->gravity = map_info.gravity;
1819 mobj->alpha = 1.f;
1820 mobj->index = -1;
1821
1822 mobj->target = mobj->tracer = mobj->lastenemy = NULL;
1823 P_AddThinker(&mobj->thinker);
1824 if (!((mobj->flags ^ MF_COUNTKILL) & (MF_FRIEND | MF_COUNTKILL)))
1825 totallive++;
1826
1827 dsda_WatchSpawn(mobj);
1828
1829 return mobj;
1830 }
1831
1832
1833 static mapthing_t itemrespawnque[ITEMQUESIZE];
1834 static int itemrespawntime[ITEMQUESIZE];
1835 int iquehead;
1836 int iquetail;
1837
1838
1839 //
1840 // P_RemoveMobj
1841 //
1842
1843 void P_RemoveMobj (mobj_t* mobj)
1844 {
1845 if (raven) // so short, just putting it here
1846 {
1847 if (hexen)
1848 {
1849 // Remove from creature queue
1850 if (mobj->flags & MF_COUNTKILL && mobj->flags & MF_CORPSE)
1851 {
1852 A_DeQueueCorpse(mobj);
1853 }
1854 }
1855
1856 if (map_format.thing_id && mobj->tid)
1857 {
1858 map_format.remove_mobj_thing_id(mobj);
1859 }
1860
1861 P_UnsetThingPosition(mobj);
1862 if (sector_list)
1863 {
1864 P_DelSeclist(sector_list);
1865 sector_list = NULL;
1866 }
1867 S_StopSound(mobj);
1868 P_RemoveThinker((thinker_t *) mobj);
1869 return;
1870 }
1871
1872 if ((mobj->flags & MF_SPECIAL)
1873 && !(mobj->flags & MF_DROPPED)
1874 && (mobj->type != MT_INV)
1875 && (mobj->type != MT_INS))
1876 {
1877 itemrespawnque[iquehead] = mobj->spawnpoint;
1878 itemrespawntime[iquehead] = leveltime;
1879 iquehead = (iquehead+1)&(ITEMQUESIZE-1);
1880
1881 // lose one off the end?
1882
1883 if (iquehead == iquetail)
1884 iquetail = (iquetail+1)&(ITEMQUESIZE-1);
1885 }
1886
1887 if (map_format.thing_id && mobj->tid)
1888 {
1889 map_format.remove_mobj_thing_id(mobj);
1890 }
1891
1892 // unlink from sector and block lists
1893
1894 P_UnsetThingPosition (mobj);
1895
1896 // Delete all nodes on the current sector_list phares 3/16/98
1897
1898 if (sector_list)
1899 {
1900 P_DelSeclist(sector_list);
1901 sector_list = NULL;
1902 }
1903
1904 // stop any playing sound
1905
1906 // [FG] removed map objects may finish their sounds
1907 if (full_sounds)
1908 S_UnlinkSound(mobj);
1909 else
1910 S_StopSound(mobj);
1911
1912 // killough 11/98:
1913 //
1914 // Remove any references to other mobjs.
1915 //
1916 // Older demos might depend on the fields being left alone, however,
1917 // if multiple thinkers reference each other indirectly before the
1918 // end of the current tic.
1919 // CPhipps - only leave dead references in old demos; I hope lxdoom_1 level
1920 // demos are rare and don't rely on this. I hope.
1921
1922 if (compatibility_level >= lxdoom_1_compatibility || allow_incompatibility) {
1923 P_SetTarget(&mobj->target, NULL);
1924 P_SetTarget(&mobj->tracer, NULL);
1925 P_SetTarget(&mobj->lastenemy, NULL);
1926 }
1927 // free block
1928
1929 P_RemoveThinker (&mobj->thinker);
1930 }
1931
1932 void P_RemoveMonsters(void)
1933 {
1934 thinker_t *th;
1935 mobj_t *mobj;
1936
1937 for (th = thinkercap.next; th != &thinkercap; th = th->next)
1938 {
1939 if (th->function != P_MobjThinker)
1940 continue;
1941
1942 mobj = (mobj_t *) th;
1943 if (mobj->player)
1944 continue;
1945
1946 if (
1947 mobj->type == MT_SKULL ||
1948 mobj->flags & MF_COUNTKILL ||
1949 (mobj->target && !mobj->target->player)
1950 )
1951 P_RemoveMobj(mobj);
1952 }
1953
1954 P_CleanThinkers();
1955 }
1956
1957 //
1958 // P_RespawnSpecials
1959 //
1960
1961 void P_RespawnSpecials (void)
1962 {
1963 fixed_t x;
1964 fixed_t y;
1965 fixed_t z;
1966 sector_t* sec;
1967 mobj_t* mo;
1968 mapthing_t* mthing;
1969 int i;
1970
1971 // only respawn items in deathmatch
1972
1973 if (deathmatch != 2)
1974 return;
1975
1976 // nothing left to respawn?
1977
1978 if (iquehead == iquetail)
1979 return;
1980
1981 // wait at least 30 seconds
1982
1983 if (leveltime - itemrespawntime[iquetail] < 30*35)
1984 return;
1985
1986 mthing = &itemrespawnque[iquetail];
1987
1988 x = mthing->x;
1989 y = mthing->y;
1990
1991 // spawn a teleport fog at the new spot
1992
1993 sec = R_PointInSector (x,y);
1994 mo = P_SpawnMobj (x, y, sec->floorheight , MT_IFOG);
1995 S_StartSound (mo, sfx_itmbk);
1996
1997 // find which type to spawn
1998
1999 /* killough 8/23/98: use table for faster lookup */
2000 i = P_FindDoomedNum(mthing->type);
2001
2002 // spawn it
2003
2004 if (mobjinfo[i].flags & MF_SPAWNCEILING)
2005 z = ONCEILINGZ;
2006 else
2007 z = ONFLOORZ;
2008
2009 mo = P_SpawnMobj (x,y,z, i);
2010 mo->spawnpoint = *mthing;
2011 mo->angle = ANG45 * (mthing->angle/45);
2012
2013 // pull it from the queue
2014
2015 iquetail = (iquetail+1)&(ITEMQUESIZE-1);
2016 }
2017
2018 //
2019 // P_SpawnPlayer
2020 // Called when a player is spawned on the level.
2021 // Most of the player structure stays unchanged
2022 // between levels.
2023 //
2024
2025 extern byte playernumtotrans[MAX_MAXPLAYERS];
2026
2027 void P_SpawnPlayer (int n, const mapthing_t* mthing)
2028 {
2029 player_t* p;
2030 fixed_t x;
2031 fixed_t y;
2032 fixed_t z;
2033 mobj_t* mobj;
2034 int i;
2035
2036 // e6y
2037 // playeringame overflow detection
2038 // it detects and emulates overflows on vex6d.wad\bug_wald(toke).lmp, etc.
2039 // http://www.doom2.net/doom2/research/runningbody.zip
2040 if (PlayeringameOverrun(mthing))
2041 return;
2042
2043 // not playing?
2044
2045 if (!playeringame[n])
2046 return;
2047
2048 p = &players[n];
2049
2050 if (p->playerstate == PST_REBORN)
2051 G_PlayerReborn (n);
2052
2053 /* cph 2001/08/14 - use the options field of memorised player starts to
2054 * indicate whether the start really exists in the level.
2055 */
2056 if (!mthing->options)
2057 I_Error("P_SpawnPlayer: attempt to spawn player at unavailable start point");
2058
2059 x = mthing->x;
2060 y = mthing->y;
2061 z = ONFLOORZ;
2062
2063 if (hexen)
2064 {
2065 if (randomclass && deathmatch)
2066 {
2067 p->pclass = 1 + P_Random(pr_hexen) % 3;
2068 if (p->pclass == PlayerClass[mthing->type - 1])
2069 {
2070 p->pclass = 1 + ((p->pclass + 1) % 3);
2071 }
2072 PlayerClass[mthing->type - 1] = p->pclass;
2073 SB_SetClassData();
2074 }
2075 else
2076 {
2077 p->pclass = PlayerClass[mthing->type - 1];
2078 }
2079 switch (p->pclass)
2080 {
2081 case PCLASS_FIGHTER:
2082 mobj = P_SpawnMobj(x, y, z, HEXEN_MT_PLAYER_FIGHTER);
2083 break;
2084 case PCLASS_CLERIC:
2085 mobj = P_SpawnMobj(x, y, z, HEXEN_MT_PLAYER_CLERIC);
2086 break;
2087 case PCLASS_MAGE:
2088 mobj = P_SpawnMobj(x, y, z, HEXEN_MT_PLAYER_MAGE);
2089 break;
2090 default:
2091 I_Error("P_SpawnPlayer: Unknown class type");
2092 return;
2093 }
2094 }
2095 else
2096 mobj = P_SpawnMobj(x,y,z, g_mt_player);
2097
2098 if (map_info.flags & MI_USE_PLAYER_START_Z)
2099 mobj->z += mthing->height;
2100
2101 if (map_format.zdoom)
2102 P_AdjustZLimits(mobj);
2103
2104 // set color translations for player sprites
2105 if (hexen)
2106 {
2107 if (p->pclass == PCLASS_FIGHTER && (mthing->type == 1 || mthing->type == 3))
2108 {
2109 // The first type should be blue, and the third should be the
2110 // Fighter's original gold color
2111 if (mthing->type == 1)
2112 {
2113 mobj->flags |= MF_TRANSLATION2;
2114 }
2115 }
2116 else if (mthing->type > 1)
2117 { // Set color translation bits for player sprites
2118 mobj->flags |= (mthing->type - 1) << MF_TRANSSHIFT;
2119 }
2120 }
2121 else
2122 mobj->flags |= playernumtotrans[n]<<MF_TRANSSHIFT;
2123
2124 if (leave_data.flags & LF_SET_ANGLE)
2125 mobj->angle = leave_data.angle;
2126 else
2127 mobj->angle = ANG45 * (mthing->angle/45);
2128
2129 mobj->player = p;
2130 mobj->health = p->health;
2131 mobj->player->prev_viewangle = mobj->angle;
2132
2133 p->mo = mobj;
2134 p->playerstate = PST_LIVE;
2135 p->refire = 0;
2136 p->damagecount = 0;
2137 p->bonuscount = 0;
2138 p->poisoncount = 0;
2139 p->chickenTics = 0;
2140 p->morphTics = 0;
2141 p->rain1 = NULL;
2142 p->rain2 = NULL;
2143 p->extralight = 0;
2144 p->fixedcolormap = 0;
2145 p->viewheight = g_viewheight;
2146
2147 p->momx = p->momy = 0; // killough 10/98: initialize bobbing to 0.
2148
2149 // setup gun psprite
2150
2151 P_SetupPsprites (p);
2152
2153 // give all cards in death match mode
2154
2155 if (deathmatch)
2156 {
2157 for (i = 0 ; i < NUMCARDS ; i++)
2158 p->cards[i] = true;
2159 if (p == &players[consoleplayer])
2160 p->ravenkeys = 7;
2161 }
2162 else if (p == &players[consoleplayer] && !hexen)
2163 p->ravenkeys = 0;
2164
2165 R_SmoothPlaying_Reset(p); // e6y
2166 }
2167
2168 /*
2169 * P_IsDoomnumAllowed()
2170 * Based on code taken from P_LoadThings() in src/p_setup.c Return TRUE
2171 * if the thing in question is expected to be available in the gamemode used.
2172 */
2173
2174 dboolean P_IsDoomnumAllowed(int doomnum)
2175 {
2176 // Do not spawn cool, new monsters if !commercial
2177 if (!raven && gamemode != commercial)
2178 switch(doomnum)
2179 {
2180 case 64: // Archvile
2181 case 65: // Former Human Commando
2182 case 66: // Revenant
2183 case 67: // Mancubus
2184 case 68: // Arachnotron
2185 case 69: // Hell Knight
2186 case 71: // Pain Elemental
2187 case 84: // Wolf SS
2188 case 88: // Boss Brain
2189 case 89: // Boss Shooter
2190 return false;
2191 }
2192
2193 return true;
2194 }
2195
2196 //
2197 // P_SpawnMapThing
2198 // The fields of the mapthing should
2199 // already be in host byte order.
2200 //
2201
2202 static dboolean P_ShouldSpawnPlayer(const mapthing_t* mthing)
2203 {
2204 return !deathmatch && (map_format.zdoom ?
2205 mthing->special_args[0] == leave_data.position :
2206 !mthing->special_args[0]);
2207 }
2208
2209 static dboolean P_ShouldSpawnMapThing(int options)
2210 {
2211 unsigned int spawnMask;
2212 dboolean spawn_multi;
2213
2214 spawn_multi = skill_info.flags & SI_SPAWN_MULTI;
2215
2216 if (map_format.hexen)
2217 {
2218 // Check current game type with spawn flags
2219 if (netgame == false)
2220 {
2221 spawnMask = MTF_GSINGLE;
2222
2223 if (spawn_multi)
2224 spawnMask |= MTF_GCOOP;
2225 }
2226 else if (deathmatch)
2227 {
2228 spawnMask = MTF_GDEATHMATCH;
2229 }
2230 else
2231 {
2232 spawnMask = MTF_GCOOP;
2233 }
2234
2235 if (!(options & spawnMask))
2236 {
2237 return false;
2238 }
2239 }
2240 else
2241 {
2242 /* jff "not single" thing flag */
2243 if (!spawn_multi && !netgame && options & MTF_NOTSINGLE)
2244 return false;
2245
2246 //jff 3/30/98 implement "not deathmatch" thing flag
2247 if (netgame && deathmatch && options & MTF_NOTDM)
2248 return false;
2249
2250 //jff 3/30/98 implement "not cooperative" thing flag
2251 if ((spawn_multi || netgame) && !deathmatch && options & MTF_NOTCOOP)
2252 return false;
2253 }
2254
2255 // check for appropriate skill level
2256 if (
2257 skill_info.spawn_filter == 1 ? !(options & MTF_SKILL1) :
2258 skill_info.spawn_filter == 2 ? !(options & MTF_SKILL2) :
2259 skill_info.spawn_filter == 3 ? !(options & MTF_SKILL3) :
2260 skill_info.spawn_filter == 4 ? !(options & MTF_SKILL4) :
2261 !(options & MTF_SKILL5)
2262 )
2263 return false;
2264
2265 if (hexen)
2266 {
2267 static unsigned int classFlags[] = {
2268 0, // null class
2269 MTF_FIGHTER,
2270 MTF_CLERIC,
2271 MTF_MAGE
2272 };
2273
2274 int i;
2275
2276 // Check current character classes with spawn flags
2277 if (netgame == false)
2278 { // Single player
2279 if ((options & classFlags[PlayerClass[0]]) == 0)
2280 { // Not for current class
2281 return false;
2282 }
2283 }
2284 else if (deathmatch == false)
2285 { // Cooperative
2286 spawnMask = 0;
2287 for (i = 0; i < g_maxplayers; i++)
2288 {
2289 if (playeringame[i])
2290 {
2291 spawnMask |= classFlags[PlayerClass[i]];
2292 }
2293 }
2294 if ((options & spawnMask) == 0)
2295 {
2296 return false;
2297 }
2298 }
2299 }
2300
2301 return true;
2302 }
2303
2304 void P_TrySpawnPlayer(const mapthing_t *mthing, int player)
2305 {
2306 mapthing_t *player_start;
2307
2308 player_start = &playerstarts[mthing->special_args[0]][player];
2309 *player_start = *mthing;
2310 player_start->type = player + 1;
2311
2312 /* cph 2006/07/24 - use the otherwise-unused options field to flag that
2313 * this start is present (so we know which elements of the array are filled
2314 * in, in effect). Also note that the call below to P_SpawnPlayer must use
2315 * the playerstarts version with this field set */
2316 player_start->options = 1;
2317
2318 if (P_ShouldSpawnPlayer(mthing))
2319 P_SpawnPlayer(player, player_start);
2320 }
2321
2322 static int P_TypeToPlayer(int type)
2323 {
2324 if (type <= 4 && type > 0)
2325 return type - 1;
2326
2327 if (map_format.hexen && type >= 9100 && type <= 9103)
2328 return 4 + type - 9100;
2329
2330 return -1;
2331 }
2332
2333 mobj_t* P_SpawnMapThing (const mapthing_t* mthing, int index)
2334 {
2335 int i;
2336 int player;
2337 mobj_t* mobj;
2338 fixed_t x;
2339 fixed_t y;
2340 fixed_t z;
2341 int options = mthing->options; /* cph 2001/07/07 - make writable copy */
2342 short thingtype = mthing->type;
2343 int iden_num = 0;
2344
2345 // killough 2/26/98: Ignore type-0 things as NOPs
2346 // phares 5/14/98: Ignore Player 5-8 starts (for now)
2347
2348 if (!hexen)
2349 {
2350 switch(thingtype)
2351 {
2352 case 0:
2353 case DEN_PLAYER5:
2354 case DEN_PLAYER6:
2355 case DEN_PLAYER7:
2356 case DEN_PLAYER8:
2357 return NULL;
2358 }
2359 }
2360
2361 // killough 11/98: clear flags unused by Doom
2362 //
2363 // We clear the flags unused in Doom if we see flag mask 256 set, since
2364 // it is reserved to be 0 under the new scheme. A 1 in this reserved bit
2365 // indicates it's a Doom wad made by a Doom editor which puts 1's in
2366 // bits that weren't used in Doom (such as HellMaker wads). So we should
2367 // then simply ignore all upper bits.
2368
2369 if (
2370 !map_format.hexen &&
2371 (
2372 demo_compatibility ||
2373 (
2374 compatibility_level >= lxdoom_1_compatibility &&
2375 options & MTF_RESERVED
2376 )
2377 )
2378 )
2379 {
2380 if (!demo_compatibility) // cph - Add warning about bad thing flags
2381 lprintf(LO_WARN, "P_SpawnMapThing: correcting bad flags (%u) (thing type %d)\n", options, thingtype);
2382 options &= MTF_SKILL1|MTF_SKILL2|MTF_SKILL3|MTF_SKILL4|MTF_SKILL5|MTF_AMBUSH|MTF_NOTSINGLE;
2383 }
2384
2385 // count deathmatch start positions
2386
2387 // doom2.exe has at most 10 deathmatch starts
2388 if (thingtype == 11)
2389 {
2390 if (compatibility && deathmatch_p - deathmatchstarts >= 10)
2391 {
2392 return NULL;
2393 }
2394 else
2395 {
2396 // 1/11/98 killough -- new code removes limit on deathmatch starts:
2397
2398 size_t offset = deathmatch_p - deathmatchstarts;
2399
2400 if (offset >= num_deathmatchstarts)
2401 {
2402 num_deathmatchstarts = num_deathmatchstarts ?
2403 num_deathmatchstarts * 2 : 16;
2404 deathmatchstarts = Z_Realloc(deathmatchstarts,
2405 num_deathmatchstarts *
2406 sizeof(*deathmatchstarts));
2407 deathmatch_p = deathmatchstarts + offset;
2408 }
2409 memcpy(deathmatch_p++, mthing, sizeof(*mthing));
2410 (deathmatch_p - 1)->options = 1;
2411
2412 return NULL;
2413 }
2414 }
2415
2416 if (PO_Detect(mthing->type))
2417 {
2418 return NULL;
2419 }
2420
2421 // check for players specially
2422 if ((player = P_TypeToPlayer(thingtype)) >= 0)
2423 {
2424 if (map_info.flags & MI_FILTER_STARTS)
2425 if (!P_ShouldSpawnMapThing(options))
2426 return NULL;
2427
2428 // killough 7/19/98: Marine's best friend :)
2429 if (
2430 !netgame &&
2431 player > 0 && player <= dogs &&
2432 !players[player].secretcount
2433 )
2434 { // use secretcount to avoid multiple dogs in case of multiple starts
2435 players[player].secretcount = 1;
2436
2437 // killough 10/98: force it to be a friend
2438 options |= (map_format.zdoom ? MTF_FRIENDLY : MTF_FRIEND);
2439 if (HelperThing != -1) // haleyjd 9/22/99: deh substitution
2440 {
2441 int type = HelperThing - 1;
2442 if (type >= 0 && type < num_mobj_types)
2443 {
2444 i = type;
2445 }
2446 else
2447 {
2448 doom_printf("Invalid value %i for helper, ignored.", HelperThing);
2449 i = MT_DOGS;
2450 }
2451 }
2452 else {
2453 i = MT_DOGS;
2454 }
2455 goto spawnit;
2456 }
2457
2458 P_TrySpawnPlayer(mthing, player);
2459
2460 return NULL;
2461 }
2462
2463 // MAP_FORMAT_TODO: need to verify heretic types
2464 if (heretic)
2465 {
2466 // Ambient sound sequences
2467 if (mthing->type >= 1200 && mthing->type < 1300)
2468 {
2469 P_AddAmbientSfx(mthing->type - 1200);
2470 return NULL;
2471 }
2472
2473 // Check for boss spots
2474 if (mthing->type == 56) // Monster_BossSpot
2475 {
2476 P_AddBossSpot(mthing->x, mthing->y,
2477 ANG45 * (mthing->angle / 45));
2478 return NULL;
2479 }
2480 }
2481
2482 if (map_format.hexen)
2483 {
2484 if (mthing->type >= 1400 && mthing->type < 1410)
2485 {
2486 R_PointInSector(
2487 mthing->x, mthing->y
2488 )->seqType = mthing->type - 1400;
2489 return NULL;
2490 }
2491 }
2492
2493 if (!P_ShouldSpawnMapThing(options))
2494 return NULL;
2495
2496 if (!raven && thingtype >= 14001 && thingtype <= 14064)
2497 {
2498 iden_num = thingtype - 14000; // Ambient sound id
2499 thingtype = 14064; // ZMT_AMBIENTSOUND
2500 }
2501
2502 if (!raven && thingtype == 14065)
2503 {
2504 iden_num = mthing->special_args[0]; // Ambient sound id
2505 thingtype = 14064; // ZMT_AMBIENTSOUND
2506 }
2507
2508 if (!raven && thingtype >= 14100 && thingtype <= 14164)
2509 {
2510 iden_num = thingtype - 14100; // Mus change
2511 thingtype = 14164; // MT_MUSICSOURCE
2512 }
2513
2514 if (!raven && thingtype == 14165 && map_format.hexen)
2515 {
2516 iden_num = BETWEEN(0, 64, mthing->special_args[0]); // Mus change
2517 thingtype = 14164; // MT_MUSICSOURCE
2518 }
2519
2520 // find which type to spawn
2521
2522 // killough 8/23/98: use table for faster lookup
2523 i = P_FindDoomedNum(thingtype);
2524
2525 // phares 5/16/98:
2526 // Do not abort because of an unknown thing. Ignore it, but post a
2527 // warning message for the player.
2528
2529 if (i == num_mobj_types)
2530 {
2531 lprintf(LO_INFO, "P_SpawnMapThing: Unknown Thing type %i at (%i, %i)\n", thingtype, mthing->x, mthing->y);
2532 return NULL;
2533 }
2534
2535 // don't spawn keycards and players in deathmatch
2536
2537 if (deathmatch && mobjinfo[i].flags & MF_NOTDMATCH)
2538 return NULL;
2539
2540 // don't spawn any monsters if -nomonsters
2541
2542 if (nomonsters && (i == MT_SKULL || (mobjinfo[i].flags & MF_COUNTKILL)))
2543 return NULL;
2544
2545 // spawn it
2546 spawnit:
2547
2548 if (heretic && i == HERETIC_MT_WMACE)
2549 {
2550 P_AddMaceSpot(mthing);
2551 return NULL;
2552 }
2553
2554 x = mthing->x;
2555 y = mthing->y;
2556
2557 if (mobjinfo[i].flags & MF_SPAWNCEILING)
2558 z = ONCEILINGZ;
2559 else if (mobjinfo[i].flags2 & MF2_SPAWNFLOAT)
2560 z = FLOATRANDZ;
2561 else if (hexen && mobjinfo[i].flags2 & MF2_FLOATBOB)
2562 z = mthing->height;
2563 else
2564 z = ONFLOORZ;
2565
2566 if (hexen && i == HEXEN_MT_ZLYNCHED_NOHEART)
2567 P_SpawnMobj(x, y, ONFLOORZ, HEXEN_MT_BLOODPOOL);
2568
2569 mobj = P_SpawnMobj (x, y, z, i);
2570
2571 if (!(mobj->flags & MF_FRIEND) &&
2572 options & (map_format.zdoom ? MTF_FRIENDLY : MTF_FRIEND) &&
2573 mbf_features)
2574 {
2575 mobj->flags |= MF_FRIEND; // killough 10/98:
2576 P_UpdateThinker(&mobj->thinker); // transfer friendliness flag
2577
2578 // Friends can have a different spawn health
2579 mobj->health = P_MobjSpawnHealth(mobj);
2580 }
2581
2582 if (mthing->health != FRACUNIT)
2583 {
2584 if (mthing->health < 0)
2585 mobj->health = -mthing->health >> FRACBITS;
2586 else
2587 mobj->health = FixedMul(mobj->health, mthing->health);
2588 }
2589
2590 if (mthing->gravity != FRACUNIT)
2591 {
2592 if (mthing->gravity < 0)
2593 mobj->gravity = -mthing->gravity;
2594 else
2595 mobj->gravity = FixedMul(map_info.gravity, mthing->gravity);
2596 }
2597
2598 mobj->alpha = mthing->alpha;
2599 if (mobj->alpha < 1.f)
2600 mobj->tranmap = dsda_TranMap(dsda_FloatToPercent(mobj->alpha));
2601 else
2602 mobj->tranmap = NULL;
2603
2604 mobj->spawnpoint = *mthing; // heretic_note: this is only done with totalkills++ in heretic
2605 mobj->index = index;//e6y
2606 mobj->iden_nums = iden_num;
2607
2608 if (map_format.hexen)
2609 {
2610 if (z == ONFLOORZ)
2611 {
2612 mobj->z += mthing->height;
2613 }
2614 else if (z == ONCEILINGZ)
2615 {
2616 mobj->z -= mthing->height;
2617 }
2618
2619 if (map_format.zdoom)
2620 P_AdjustZLimits(mobj);
2621
2622 mobj->tid = mthing->tid;
2623 mobj->special = mthing->special;
2624 mobj->special_args[0] = mthing->special_args[0];
2625 mobj->special_args[1] = mthing->special_args[1];
2626 mobj->special_args[2] = mthing->special_args[2];
2627 mobj->special_args[3] = mthing->special_args[3];
2628 mobj->special_args[4] = mthing->special_args[4];
2629 }
2630
2631 if (mobj->flags2 & MF2_FLOATBOB)
2632 { // Seed random starting index for bobbing motion
2633 mobj->health = P_Random(pr_heretic);
2634 if (hexen) mobj->special1.i = mthing->height;
2635 }
2636
2637 if (mobj->tics > 0)
2638 mobj->tics = 1 + (P_Random(pr_spawnthing) % mobj->tics);
2639
2640 if (map_format.zdoom)
2641 {
2642 if (options & MTF_TRANSLUCENT)
2643 mobj->flags |= MF_TRANSLUCENT;
2644
2645 if (options & MTF_INVISIBLE)
2646 {
2647 P_UnsetThingPosition(mobj);
2648 mobj->flags |= MF_NOSECTOR;
2649 P_SetThingPosition(mobj);
2650 }
2651
2652 if (options & MTF_COUNTSECRET)
2653 P_AddMobjSecret(mobj);
2654 }
2655
2656 /* killough 7/20/98: exclude friends */
2657 if (!((mobj->flags ^ MF_COUNTKILL) & (MF_FRIEND | MF_COUNTKILL)))
2658 totalkills++;
2659
2660 if (mobj->flags & MF_COUNTITEM)
2661 totalitems++;
2662
2663 if (map_format.hexen)
2664 {
2665 if (mobj->flags & MF_COUNTKILL)
2666 {
2667 // Quantize angle to 45 degree increments
2668 mobj->angle = ANG45 * (mthing->angle / 45);
2669 }
2670 else
2671 {
2672 // Scale angle correctly (source is 0..359)
2673 mobj->angle = ((mthing->angle << 8) / 360) << 24;
2674 }
2675 }
2676 else
2677 mobj->angle = ANG45 * (mthing->angle / 45);
2678
2679 if (options & MTF_AMBUSH)
2680 mobj->flags |= MF_AMBUSH;
2681
2682 if (map_format.hexen && mthing->options & MTF_DORMANT)
2683 {
2684 mobj->flags2 |= MF2_DORMANT;
2685 if (hexen && mobj->type == HEXEN_MT_ICEGUY)
2686 {
2687 P_SetMobjState(mobj, HEXEN_S_ICEGUY_DORMANT);
2688 }
2689 mobj->tics = -1;
2690 }
2691
2692 if (!raven && thingtype == 14064)
2693 {
2694 dsda_SpawnAmbientSource(mobj);
2695 }
2696
2697 return mobj;
2698 }
2699
2700 //
2701 // GAME SPAWN FUNCTIONS
2702 //
2703
2704 //
2705 // P_SpawnPuff
2706 //
2707
2708 extern fixed_t attackrange;
2709
2710 void P_SpawnPuff(fixed_t x,fixed_t y,fixed_t z)
2711 {
2712 mobj_t* th;
2713 int t;
2714
2715 if (raven) return Raven_P_SpawnPuff(x, y, z);
2716
2717 // killough 5/5/98: remove dependence on order of evaluation:
2718 t = P_Random(pr_spawnpuff);
2719 z += (t - P_Random(pr_spawnpuff))<<10;
2720
2721 th = P_SpawnMobj (x,y,z, MT_PUFF);
2722 th->momz = FRACUNIT;
2723 th->tics -= P_Random(pr_spawnpuff)&3;
2724
2725 if (th->tics < 1)
2726 th->tics = 1;
2727
2728 // don't make punches spark on the wall
2729
2730 if (attackrange == MELEERANGE)
2731 P_SetMobjState (th, S_PUFF3);
2732 }
2733
2734
2735 //
2736 // P_SpawnBlood
2737 //
2738 void P_SpawnBlood(fixed_t x, fixed_t y, fixed_t z, int damage, mobj_t *bleeder)
2739 {
2740 mobj_t* th;
2741 // killough 5/5/98: remove dependence on order of evaluation:
2742 int t = P_Random(pr_spawnblood);
2743 z += (t - P_Random(pr_spawnblood))<<10;
2744 th = P_SpawnMobj(x,y,z, MT_BLOOD);
2745 th->momz = FRACUNIT*2;
2746 th->tics -= P_Random(pr_spawnblood)&3;
2747 th->color = bleeder->info->bloodcolor;
2748
2749 if (th->tics < 1)
2750 th->tics = 1;
2751
2752 if (damage <= 12 && damage >= 9)
2753 P_SetMobjState (th,S_BLOOD2);
2754 else if (damage < 9)
2755 P_SetMobjState (th,S_BLOOD3);
2756 }
2757
2758
2759 //
2760 // P_CheckMissileSpawn
2761 // Moves the missile forward a bit
2762 // and possibly explodes it right there.
2763 //
2764
2765 dboolean P_CheckMissileSpawn (mobj_t* th)
2766 {
2767 if (!raven) {
2768 th->tics -= P_Random(pr_missile)&3;
2769 if (th->tics < 1)
2770 th->tics = 1;
2771 }
2772
2773 // move a little forward so an angle can
2774 // be computed if it immediately explodes
2775
2776 if (heretic && th->type == HERETIC_MT_BLASTERFX1) {
2777 // Ultra-fast ripper spawning missile
2778 th->x += (th->momx >> 3);
2779 th->y += (th->momy >> 3);
2780 th->z += (th->momz >> 3);
2781 }
2782 else {
2783 th->x += (th->momx>>1);
2784 th->y += (th->momy>>1);
2785 th->z += (th->momz>>1);
2786 }
2787
2788 // killough 8/12/98: for non-missile objects (e.g. grenades)
2789 if (!(th->flags & MF_MISSILE) && mbf_features)
2790 return true;
2791
2792 // killough 3/15/98: no dropoff (really = don't care for missiles)
2793
2794 if (!P_TryMove (th, th->x, th->y, false)) {
2795 P_ExplodeMissile (th);
2796 return false;
2797 }
2798
2799 return true;
2800 }
2801
2802
2803 //
2804 // P_SpawnMissile
2805 //
2806
2807 mobj_t* P_SpawnMissile(mobj_t* source,mobj_t* dest,mobjtype_t type)
2808 {
2809 fixed_t z;
2810 mobj_t* th;
2811 angle_t an;
2812 int dist;
2813
2814 if (!raven)
2815 {
2816 z = source->z + 32 * FRACUNIT;
2817 }
2818 else
2819 {
2820 switch (type)
2821 {
2822 case HERETIC_MT_MNTRFX1: // Minotaur swing attack missile
2823 case HEXEN_MT_MNTRFX1: // Minotaur swing attack missile
2824 case HEXEN_MT_ICEGUY_FX:
2825 case HEXEN_MT_HOLY_MISSILE:
2826 z = source->z + 40 * FRACUNIT;
2827 break;
2828 case HERETIC_MT_MNTRFX2: // Minotaur floor fire missile
2829 z = ONFLOORZ;
2830 break;
2831 case HEXEN_MT_MNTRFX2: // Minotaur floor fire missile
2832 z = ONFLOORZ + source->floorclip;
2833 break;
2834 case HERETIC_MT_SRCRFX1: // Sorcerer Demon fireball
2835 z = source->z + 48 * FRACUNIT;
2836 break;
2837 case HERETIC_MT_KNIGHTAXE: // Knight normal axe
2838 case HERETIC_MT_REDAXE: // Knight red power axe
2839 z = source->z + 36 * FRACUNIT;
2840 break;
2841 case HEXEN_MT_CENTAUR_FX:
2842 z = source->z + 45 * FRACUNIT;
2843 break;
2844 default:
2845 z = source->z + 32 * FRACUNIT;
2846 break;
2847 }
2848
2849 if (hexen)
2850 z -= source->floorclip;
2851 else if (source->flags2 & MF2_FEETARECLIPPED)
2852 z -= FOOTCLIPSIZE;
2853 }
2854
2855 th = P_SpawnMobj(source->x, source->y, z, type);
2856
2857 if (th->info->seesound)
2858 S_StartMobjSound(th, th->info->seesound);
2859
2860 P_SetTarget(&th->target, source); // where it came from
2861 an = R_PointToAngle2(source->x, source->y, dest->x, dest->y);
2862
2863 // fuzzy player
2864 if (dest->flags & MF_SHADOW)
2865 { // killough 5/5/98: remove dependence on order of evaluation:
2866 int t = P_Random(pr_shadow);
2867 an += (t - P_Random(pr_shadow)) << g_fuzzy_aim_shift;
2868 }
2869
2870 th->angle = an;
2871 an >>= ANGLETOFINESHIFT;
2872 th->momx = FixedMul(th->info->speed, finecosine[an]);
2873 th->momy = FixedMul(th->info->speed, finesine[an]);
2874
2875 dist = P_AproxDistance(dest->x - source->x, dest->y - source->y);
2876 dist = dist / th->info->speed;
2877
2878 if (dist < 1)
2879 dist = 1;
2880
2881 th->momz = (dest->z - source->z) / dist;
2882
2883 if (!raven)
2884 {
2885 P_CheckMissileSpawn(th);
2886 return th;
2887 }
2888
2889 return (P_CheckMissileSpawn(th) ? th : NULL);
2890 }
2891
2892
2893 //
2894 // P_SpawnPlayerMissile
2895 // Tries to aim at a nearby monster
2896 //
2897
2898 mobj_t* P_SpawnPlayerMissile(mobj_t* source, mobjtype_t type)
2899 {
2900 mobj_t *th;
2901 fixed_t x, y, z;
2902 aim_t aim;
2903
2904 // see which target is to be aimed at
2905 dsda_PlayerAim(source, source->angle, &aim, mbf_features ? MF_FRIEND : 0);
2906
2907 x = source->x;
2908 y = source->y;
2909
2910 if (!raven)
2911 {
2912 z = source->z + 4 * 8 * FRACUNIT + aim.z_offset;
2913 }
2914 else
2915 {
2916 if (type == HEXEN_MT_LIGHTNING_FLOOR)
2917 {
2918 z = ONFLOORZ;
2919 aim.slope = 0;
2920 }
2921 else if (type == HEXEN_MT_LIGHTNING_CEILING)
2922 {
2923 z = ONCEILINGZ;
2924 aim.slope = 0;
2925 }
2926 else
2927 {
2928 z = source->z + 4 * 8 * FRACUNIT + aim.z_offset;
2929
2930 if (hexen)
2931 {
2932 z -= source->floorclip;
2933 }
2934 else if (source->flags2 & MF2_FEETARECLIPPED)
2935 {
2936 z -= FOOTCLIPSIZE;
2937 }
2938 }
2939 }
2940
2941 // heretic global MissileMobj
2942 MissileMobj = th = P_SpawnMobj(x, y, z, type);
2943
2944 if (!hexen && th->info->seesound)
2945 S_StartMobjSound(th, th->info->seesound);
2946
2947 P_SetTarget(&th->target, source);
2948 th->angle = aim.angle;
2949
2950 if (dsda_FreeAim())
2951 {
2952 fixed_t horizontal_speed;
2953
2954 horizontal_speed = FixedMul(th->info->speed, finecosine[source->pitch >> ANGLETOFINESHIFT]);
2955 th->momx = FixedMul(horizontal_speed, finecosine[aim.angle >> ANGLETOFINESHIFT]);
2956 th->momy = FixedMul(horizontal_speed, finesine[aim.angle >> ANGLETOFINESHIFT]);
2957 th->momz = FixedMul(th->info->speed, -finesine[source->pitch >> ANGLETOFINESHIFT]);
2958 }
2959 else
2960 {
2961 th->momx = FixedMul(th->info->speed, finecosine[aim.angle >> ANGLETOFINESHIFT]);
2962 th->momy = FixedMul(th->info->speed, finesine[aim.angle >> ANGLETOFINESHIFT]);
2963 th->momz = FixedMul(th->info->speed, aim.slope);
2964 }
2965
2966 if (hexen)
2967 {
2968 if (th->type == HEXEN_MT_MWAND_MISSILE || th->type == HEXEN_MT_CFLAME_MISSILE)
2969 { // Ultra-fast ripper spawning missile
2970 th->x += (th->momx >> 3);
2971 th->y += (th->momy >> 3);
2972 th->z += (th->momz >> 3);
2973 }
2974 else
2975 { // Normal missile
2976 th->x += (th->momx >> 1);
2977 th->y += (th->momy >> 1);
2978 th->z += (th->momz >> 1);
2979 }
2980 if (!P_TryMove(th, th->x, th->y, false))
2981 { // Exploded immediately
2982 P_ExplodeMissile(th);
2983 return (NULL);
2984 }
2985 return (th);
2986 }
2987
2988 // heretic - return missile if it's ok
2989 return P_CheckMissileSpawn(th) ? th : NULL;
2990 }
2991
2992 // heretic
2993
2994 #include "p_spec.h"
2995
2996 mobjtype_t PuffType;
2997 mobj_t *MissileMobj;
2998
2999 void P_BlasterMobjThinker(mobj_t * mobj)
3000 {
3001 int i;
3002 fixed_t xfrac;
3003 fixed_t yfrac;
3004 fixed_t zfrac;
3005 fixed_t z;
3006 dboolean changexy;
3007
3008 mobj->PrevX = mobj->x;
3009 mobj->PrevY = mobj->y;
3010 mobj->PrevZ = mobj->z;
3011
3012 // Handle movement
3013 if (mobj->momx || mobj->momy || (mobj->z != mobj->floorz) || mobj->momz)
3014 {
3015 xfrac = mobj->momx >> 3;
3016 yfrac = mobj->momy >> 3;
3017 zfrac = mobj->momz >> 3;
3018 changexy = xfrac || yfrac;
3019 for (i = 0; i < 8; i++)
3020 {
3021 if (changexy)
3022 {
3023 if (!P_TryMove(mobj, mobj->x + xfrac, mobj->y + yfrac, false))
3024 { // Blocked move
3025 P_ExplodeMissile(mobj);
3026 return;
3027 }
3028 }
3029 mobj->z += zfrac;
3030 if (mobj->z <= mobj->floorz)
3031 { // Hit the floor
3032 mobj->z = mobj->floorz;
3033 P_HitFloor(mobj);
3034 P_ExplodeMissile(mobj);
3035 return;
3036 }
3037 if (mobj->z + mobj->height > mobj->ceilingz)
3038 { // Hit the ceiling
3039 mobj->z = mobj->ceilingz - mobj->height;
3040 P_ExplodeMissile(mobj);
3041 return;
3042 }
3043 if (changexy)
3044 {
3045 if (hexen)
3046 {
3047 if (mobj->type == HEXEN_MT_MWAND_MISSILE && (P_Random(pr_hexen) < 128))
3048 {
3049 z = mobj->z - 8 * FRACUNIT;
3050 if (z < mobj->floorz)
3051 {
3052 z = mobj->floorz;
3053 }
3054 P_SpawnMobj(mobj->x, mobj->y, z, HEXEN_MT_MWANDSMOKE);
3055 }
3056 else if (!--mobj->special1.i)
3057 {
3058 mobj_t *mo;
3059 mobj->special1.i = 4;
3060 z = mobj->z - 12 * FRACUNIT;
3061 if (z < mobj->floorz)
3062 {
3063 z = mobj->floorz;
3064 }
3065 mo = P_SpawnMobj(mobj->x, mobj->y, z, HEXEN_MT_CFLAMEFLOOR);
3066 if (mo)
3067 {
3068 mo->angle = mobj->angle;
3069 }
3070 }
3071 }
3072 else if (P_Random(pr_heretic) < 64)
3073 {
3074 z = mobj->z - 8 * FRACUNIT;
3075 if (z < mobj->floorz)
3076 {
3077 z = mobj->floorz;
3078 }
3079 P_SpawnMobj(mobj->x, mobj->y, z, HERETIC_MT_BLASTERSMOKE);
3080 }
3081 }
3082 }
3083 }
3084 // Advance the state
3085 if (mobj->tics != -1)
3086 {
3087 mobj->tics--;
3088 while (!mobj->tics)
3089 {
3090 if (!P_SetMobjState(mobj, mobj->state->nextstate))
3091 { // mobj was removed
3092 return;
3093 }
3094 }
3095 }
3096 }
3097
3098 void A_ContMobjSound(mobj_t * actor)
3099 {
3100 switch (actor->type)
3101 {
3102 case HERETIC_MT_KNIGHTAXE:
3103 S_StartMobjSound(actor, heretic_sfx_kgtatk);
3104 break;
3105 case HERETIC_MT_MUMMYFX1:
3106 S_StartMobjSound(actor, heretic_sfx_mumhed);
3107 break;
3108 case HEXEN_MT_SERPENTFX:
3109 S_StartMobjSound(actor, hexen_sfx_serpentfx_continuous);
3110 break;
3111 case HEXEN_MT_HAMMER_MISSILE:
3112 S_StartMobjSound(actor, hexen_sfx_fighter_hammer_continuous);
3113 break;
3114 case HEXEN_MT_QUAKE_FOCUS:
3115 S_StartMobjSound(actor, hexen_sfx_earthquake);
3116 break;
3117 default:
3118 break;
3119 }
3120 }
3121
3122 mobj_t *P_SpawnMissileAngle(mobj_t * source, mobjtype_t type, angle_t angle, fixed_t momz)
3123 {
3124 fixed_t z;
3125 mobj_t *mo;
3126
3127 switch (type)
3128 {
3129 case HERETIC_MT_MNTRFX1: // Minotaur swing attack missile
3130 case HEXEN_MT_MNTRFX1: // Minotaur swing attack missile
3131 case HEXEN_MT_MSTAFF_FX2:
3132 z = source->z + 40 * FRACUNIT;
3133 break;
3134 case HEXEN_MT_MNTRFX2: // Minotaur floor fire missile
3135 z = ONFLOORZ + source->floorclip;
3136 break;
3137 case HERETIC_MT_MNTRFX2: // Minotaur floor fire missile
3138 z = ONFLOORZ;
3139 break;
3140 case HERETIC_MT_SRCRFX1: // Sorcerer Demon fireball
3141 z = source->z + 48 * FRACUNIT;
3142 break;
3143 case HEXEN_MT_ICEGUY_FX2: // Secondary Projectiles of the Ice Guy
3144 z = source->z + 3 * FRACUNIT;
3145 break;
3146 default:
3147 z = source->z + 32 * FRACUNIT;
3148 break;
3149 }
3150
3151 if (hexen)
3152 {
3153 z -= source->floorclip;
3154 }
3155 else if (source->flags2 & MF2_FEETARECLIPPED)
3156 {
3157 z -= FOOTCLIPSIZE;
3158 }
3159
3160 mo = P_SpawnMobj(source->x, source->y, z, type);
3161 if (mo->info->seesound)
3162 {
3163 S_StartMobjSound(mo, mo->info->seesound);
3164 }
3165 P_SetTarget(&mo->target, source); // Originator
3166 mo->angle = angle;
3167 angle >>= ANGLETOFINESHIFT;
3168 mo->momx = FixedMul(mo->info->speed, finecosine[angle]);
3169 mo->momy = FixedMul(mo->info->speed, finesine[angle]);
3170 mo->momz = momz;
3171 return (P_CheckMissileSpawn(mo) ? mo : NULL);
3172 }
3173
3174 dboolean P_SetMobjStateNF(mobj_t * mobj, statenum_t state)
3175 {
3176 state_t *st;
3177
3178 if (state == g_s_null)
3179 { // Remove mobj
3180 mobj->state = NULL;
3181 P_RemoveMobj(mobj);
3182 return (false);
3183 }
3184 st = &states[state];
3185 mobj->state = st;
3186 mobj->tics = st->tics;
3187 mobj->sprite = st->sprite;
3188 mobj->frame = st->frame;
3189 return (true);
3190 }
3191
3192 void P_ThrustMobj(mobj_t * mo, angle_t angle, fixed_t move)
3193 {
3194 angle >>= ANGLETOFINESHIFT;
3195 mo->momx += FixedMul(move, finecosine[angle]);
3196 mo->momy += FixedMul(move, finesine[angle]);
3197 }
3198
3199 dboolean P_SeekerMissile(mobj_t * actor, mobj_t ** seekTarget, angle_t thresh, angle_t turnMax, dboolean seekcenter)
3200 {
3201 int dir;
3202 int dist;
3203 angle_t delta;
3204 angle_t angle;
3205 mobj_t *target;
3206
3207 target = *seekTarget;
3208 if (target == NULL)
3209 {
3210 return (false);
3211 }
3212 if (!(target->flags & MF_SHOOTABLE))
3213 { // Target died
3214 *seekTarget = NULL;
3215 return (false);
3216 }
3217 dir = P_FaceMobj(actor, target, &delta);
3218 if (delta > thresh)
3219 {
3220 delta >>= 1;
3221 if (delta > turnMax)
3222 {
3223 delta = turnMax;
3224 }
3225 }
3226 if (dir)
3227 { // Turn clockwise
3228 actor->angle += delta;
3229 }
3230 else
3231 { // Turn counter clockwise
3232 actor->angle -= delta;
3233 }
3234 angle = actor->angle >> ANGLETOFINESHIFT;
3235 actor->momx = FixedMul(actor->info->speed, finecosine[angle]);
3236 actor->momy = FixedMul(actor->info->speed, finesine[angle]);
3237 if (actor->z + actor->height < target->z ||
3238 target->z + target->height < actor->z || seekcenter)
3239 { // Need to seek vertically
3240 dist = P_AproxDistance(target->x - actor->x, target->y - actor->y);
3241 dist = dist / actor->info->speed;
3242 if (dist < 1)
3243 {
3244 dist = 1;
3245 }
3246 if (hexen)
3247 actor->momz = (target->z + (target->height >> 1) - (actor->z + (actor->height >> 1))) / dist;
3248 else
3249 actor->momz = (target->z + (seekcenter ? target->height/2 : 0) - actor->z) / dist;
3250 }
3251 return (true);
3252 }
3253
3254 mobj_t *P_SPMAngle(mobj_t * source, mobjtype_t type, angle_t angle)
3255 {
3256 mobj_t *th;
3257 fixed_t x, y, z;
3258 aim_t aim;
3259
3260 //
3261 // see which target is to be aimed at
3262 //
3263 dsda_PlayerAim(source, angle, &aim, 0);
3264
3265 x = source->x;
3266 y = source->y;
3267 z = source->z + 4 * 8 * FRACUNIT + aim.z_offset;
3268 if (hexen)
3269 {
3270 z -= source->floorclip;
3271 }
3272 else if (source->flags2 & MF2_FEETARECLIPPED)
3273 {
3274 z -= FOOTCLIPSIZE;
3275 }
3276 th = P_SpawnMobj(x, y, z, type);
3277 if (!hexen && th->info->seesound)
3278 {
3279 S_StartMobjSound(th, th->info->seesound);
3280 }
3281 P_SetTarget(&th->target, source);
3282 th->angle = aim.angle;
3283 th->momx = FixedMul(th->info->speed, finecosine[aim.angle >> ANGLETOFINESHIFT]);
3284 th->momy = FixedMul(th->info->speed, finesine[aim.angle >> ANGLETOFINESHIFT]);
3285 th->momz = FixedMul(th->info->speed, aim.slope);
3286 return (P_CheckMissileSpawn(th) ? th : NULL);
3287 }
3288
3289 static int Hexen_P_HitFloor(mobj_t * thing);
3290
3291 int P_HitFloor(mobj_t * thing)
3292 {
3293 mobj_t *mo;
3294
3295 if (thing->floorz != thing->subsector->sector->floorheight)
3296 { // don't splash if landing on the edge above water/lava/etc....
3297 return (FLOOR_SOLID);
3298 }
3299
3300 if (hexen) return Hexen_P_HitFloor(thing);
3301
3302 switch (P_GetThingFloorType(thing))
3303 {
3304 case FLOOR_WATER:
3305 P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HERETIC_MT_SPLASHBASE);
3306 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HERETIC_MT_SPLASH);
3307 P_SetTarget(&mo->target, thing);
3308 mo->momx = P_SubRandom() << 8;
3309 mo->momy = P_SubRandom() << 8;
3310 mo->momz = 2 * FRACUNIT + (P_Random(pr_heretic) << 8);
3311 S_StartMobjSound(mo, heretic_sfx_gloop);
3312 return (FLOOR_WATER);
3313 case FLOOR_LAVA:
3314 P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HERETIC_MT_LAVASPLASH);
3315 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HERETIC_MT_LAVASMOKE);
3316 mo->momz = FRACUNIT + (P_Random(pr_heretic) << 7);
3317 S_StartMobjSound(mo, heretic_sfx_burn);
3318 return (FLOOR_LAVA);
3319 case FLOOR_SLUDGE:
3320 P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HERETIC_MT_SLUDGESPLASH);
3321 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HERETIC_MT_SLUDGECHUNK);
3322 P_SetTarget(&mo->target, thing);
3323 mo->momx = P_SubRandom() << 8;
3324 mo->momy = P_SubRandom() << 8;
3325 mo->momz = FRACUNIT + (P_Random(pr_heretic) << 8);
3326 return (FLOOR_SLUDGE);
3327 }
3328 return (FLOOR_SOLID);
3329 }
3330
3331 int P_GetThingFloorType(mobj_t * thing)
3332 {
3333 if (hexen && thing->floorpic)
3334 {
3335 return (TerrainTypes[thing->floorpic]);
3336 }
3337 else
3338 {
3339 return (TerrainTypes[thing->subsector->sector->floorpic]);
3340 }
3341 }
3342
3343 // Returns 1 if 'source' needs to turn clockwise, or 0 if 'source' needs
3344 // to turn counter clockwise. 'delta' is set to the amount 'source'
3345 // needs to turn.
3346 int P_FaceMobj(mobj_t * source, mobj_t * target, angle_t * delta)
3347 {
3348 angle_t diff;
3349 angle_t angle1;
3350 angle_t angle2;
3351
3352 angle1 = source->angle;
3353 angle2 = R_PointToAngle2(source->x, source->y, target->x, target->y);
3354 if (angle2 > angle1)
3355 {
3356 diff = angle2 - angle1;
3357 if (diff > ANG180)
3358 {
3359 *delta = ANGLE_MAX - diff;
3360 return (0);
3361 }
3362 else
3363 {
3364 *delta = diff;
3365 return (1);
3366 }
3367 }
3368 else
3369 {
3370 diff = angle1 - angle2;
3371 if (diff > ANG180)
3372 {
3373 *delta = ANGLE_MAX - diff;
3374 return (1);
3375 }
3376 else
3377 {
3378 *delta = diff;
3379 return (0);
3380 }
3381 }
3382 }
3383
3384 dboolean Raven_P_SetMobjState(mobj_t * mobj, statenum_t state)
3385 {
3386 state_t *st;
3387
3388 if (state == g_s_null)
3389 { // Remove mobj
3390 mobj->state = NULL;
3391 P_RemoveMobj(mobj);
3392 return (false);
3393 }
3394 st = &states[state];
3395 mobj->state = st;
3396 mobj->tics = st->tics;
3397 mobj->sprite = st->sprite;
3398 mobj->frame = st->frame;
3399 if (st->action)
3400 { // Call action function
3401 st->action(mobj);
3402 }
3403 return (true);
3404 }
3405
3406 void P_FloorBounceMissile(mobj_t * mo)
3407 {
3408 if (hexen)
3409 {
3410 if (P_HitFloor(mo) >= FLOOR_LIQUID)
3411 {
3412 switch (mo->type)
3413 {
3414 case HEXEN_MT_SORCFX1:
3415 case HEXEN_MT_SORCBALL1:
3416 case HEXEN_MT_SORCBALL2:
3417 case HEXEN_MT_SORCBALL3:
3418 break;
3419 default:
3420 P_RemoveMobj(mo);
3421 return;
3422 }
3423 }
3424 switch (mo->type)
3425 {
3426 case HEXEN_MT_SORCFX1:
3427 mo->momz = -mo->momz; // no energy absorbed
3428 break;
3429 case HEXEN_MT_SGSHARD1:
3430 case HEXEN_MT_SGSHARD2:
3431 case HEXEN_MT_SGSHARD3:
3432 case HEXEN_MT_SGSHARD4:
3433 case HEXEN_MT_SGSHARD5:
3434 case HEXEN_MT_SGSHARD6:
3435 case HEXEN_MT_SGSHARD7:
3436 case HEXEN_MT_SGSHARD8:
3437 case HEXEN_MT_SGSHARD9:
3438 case HEXEN_MT_SGSHARD0:
3439 mo->momz = FixedMul(mo->momz, -0.3 * FRACUNIT);
3440 if (abs(mo->momz) < (FRACUNIT / 2))
3441 {
3442 P_SetMobjState(mo, HEXEN_S_NULL);
3443 return;
3444 }
3445 break;
3446 default:
3447 mo->momz = FixedMul(mo->momz, -0.7 * FRACUNIT);
3448 break;
3449 }
3450 mo->momx = 2 * mo->momx / 3;
3451 mo->momy = 2 * mo->momy / 3;
3452 if (mo->info->seesound)
3453 {
3454 switch (mo->type)
3455 {
3456 case HEXEN_MT_SORCBALL1:
3457 case HEXEN_MT_SORCBALL2:
3458 case HEXEN_MT_SORCBALL3:
3459 if (!mo->special_args[0])
3460 S_StartMobjSound(mo, mo->info->seesound);
3461 break;
3462 default:
3463 S_StartMobjSound(mo, mo->info->seesound);
3464 break;
3465 }
3466 S_StartMobjSound(mo, mo->info->seesound);
3467 }
3468 }
3469 else
3470 {
3471 mo->momz = -mo->momz;
3472 P_SetMobjState(mo, mobjinfo[mo->type].deathstate);
3473 }
3474 }
3475
3476 extern mobj_t *PuffSpawned;
3477
3478 void Raven_P_SpawnPuff(fixed_t x, fixed_t y, fixed_t z)
3479 {
3480 mobj_t *puff;
3481
3482 z += (P_SubRandom() << 10);
3483 puff = P_SpawnMobj(x, y, z, PuffType);
3484 if (hexen && linetarget && puff->info->seesound)
3485 { // Hit thing sound
3486 S_StartMobjSound(puff, puff->info->seesound);
3487 }
3488 else if (puff->info->attacksound)
3489 {
3490 S_StartMobjSound(puff, puff->info->attacksound);
3491 }
3492 switch (PuffType)
3493 {
3494 case HERETIC_MT_BEAKPUFF:
3495 case HERETIC_MT_STAFFPUFF:
3496 case HEXEN_MT_PUNCHPUFF:
3497 puff->momz = FRACUNIT;
3498 break;
3499 case HERETIC_MT_GAUNTLETPUFF1:
3500 case HERETIC_MT_GAUNTLETPUFF2:
3501 case HEXEN_MT_HAMMERPUFF:
3502 puff->momz = (fixed_t)(.8 * FRACUNIT);
3503 default:
3504 break;
3505 }
3506 PuffSpawned = puff;
3507 }
3508
3509 void P_BloodSplatter(fixed_t x, fixed_t y, fixed_t z, mobj_t * originator)
3510 {
3511 mobj_t *mo;
3512
3513 mo = P_SpawnMobj(x, y, z, g_mt_bloodsplatter);
3514 P_SetTarget(&mo->target, originator);
3515 mo->momx = P_SubRandom() << g_bloodsplatter_shift;
3516 mo->momy = P_SubRandom() << g_bloodsplatter_shift;
3517 mo->momz = FRACUNIT * g_bloodsplatter_weight;
3518 }
3519
3520 void P_RipperBlood(mobj_t * mo, mobj_t * bleeder)
3521 {
3522 mobj_t *th;
3523 fixed_t x, y, z;
3524
3525 x = mo->x + (P_SubRandom() << 12);
3526 y = mo->y + (P_SubRandom() << 12);
3527 z = mo->z + (P_SubRandom() << 12);
3528 th = P_SpawnMobj(x, y, z, g_mt_blood);
3529 if (!hexen) th->flags |= MF_NOGRAVITY;
3530 th->momx = mo->momx >> 1;
3531 th->momy = mo->momy >> 1;
3532 th->tics += P_Random(pr_heretic) & 3;
3533 th->color = bleeder->info->bloodcolor;
3534 }
3535
3536 // hexen
3537
3538 #define MAX_TID_COUNT 200
3539
3540 extern mobj_t LavaInflictor;
3541
3542 static int TIDList[MAX_TID_COUNT + 1]; // +1 for termination marker
3543 static mobj_t *TIDMobj[MAX_TID_COUNT];
3544
3545 mobj_t *P_SpawnMissileAngleSpeed(mobj_t * source, mobjtype_t type,
3546 angle_t angle, fixed_t momz, fixed_t speed)
3547 {
3548 fixed_t z;
3549 mobj_t *mo;
3550
3551 z = source->z;
3552 z -= source->floorclip;
3553 mo = P_SpawnMobj(source->x, source->y, z, type);
3554 P_SetTarget(&mo->target, source); // Originator
3555 mo->angle = angle;
3556 angle >>= ANGLETOFINESHIFT;
3557 mo->momx = FixedMul(speed, finecosine[angle]);
3558 mo->momy = FixedMul(speed, finesine[angle]);
3559 mo->momz = momz;
3560 return (P_CheckMissileSpawn(mo) ? mo : NULL);
3561 }
3562
3563 mobj_t *P_SPMAngleXYZ(mobj_t * source, fixed_t x, fixed_t y,
3564 fixed_t z, mobjtype_t type, angle_t angle)
3565 {
3566 mobj_t *th;
3567 aim_t aim;
3568
3569 //
3570 // see which target is to be aimed at
3571 //
3572 dsda_PlayerAim(source, angle, &aim, 0);
3573
3574 z += 4 * 8 * FRACUNIT + aim.z_offset;
3575 z -= source->floorclip;
3576 th = P_SpawnMobj(x, y, z, type);
3577 P_SetTarget(&th->target, source);
3578 th->angle = aim.angle;
3579 th->momx = FixedMul(th->info->speed, finecosine[aim.angle >> ANGLETOFINESHIFT]);
3580 th->momy = FixedMul(th->info->speed, finesine[aim.angle >> ANGLETOFINESHIFT]);
3581 th->momz = FixedMul(th->info->speed, aim.slope);
3582 return (P_CheckMissileSpawn(th) ? th : NULL);
3583 }
3584
3585 static void PlayerLandedOnThing(mobj_t * mo, mobj_t * onmobj, fixed_t gravity)
3586 {
3587 mo->player->deltaviewheight = mo->momz >> 3;
3588 if (mo->momz < -23 * FRACUNIT)
3589 {
3590 P_FallingDamage(mo->player);
3591 P_NoiseAlert(mo, mo);
3592 }
3593 else if (mo->momz < -gravity * 12 && !mo->player->morphTics)
3594 {
3595 S_StartMobjSound(mo, hexen_sfx_player_land);
3596 switch (mo->player->pclass)
3597 {
3598 case PCLASS_FIGHTER:
3599 S_StartMobjSound(mo, hexen_sfx_player_fighter_grunt);
3600 break;
3601 case PCLASS_CLERIC:
3602 S_StartMobjSound(mo, hexen_sfx_player_cleric_grunt);
3603 break;
3604 case PCLASS_MAGE:
3605 S_StartMobjSound(mo, hexen_sfx_player_mage_grunt);
3606 break;
3607 default:
3608 break;
3609 }
3610 }
3611 else if (!mo->player->morphTics)
3612 {
3613 S_StartMobjSound(mo, hexen_sfx_player_land);
3614 }
3615 P_AutoCorrectLookDir(mo->player);
3616 }
3617
3618 void P_CreateTIDList(void)
3619 {
3620 int i;
3621 mobj_t *mobj;
3622 thinker_t *t;
3623
3624 i = 0;
3625 for (t = thinkercap.next; t != &thinkercap; t = t->next)
3626 { // Search all current thinkers
3627 if (t->function != P_MobjThinker)
3628 { // Not a mobj thinker
3629 continue;
3630 }
3631 mobj = (mobj_t *) t;
3632 if (mobj->tid != 0)
3633 { // Add to list
3634 if (i == MAX_TID_COUNT)
3635 {
3636 I_Error("P_CreateTIDList: MAX_TID_COUNT (%d) exceeded.",
3637 MAX_TID_COUNT);
3638 }
3639 TIDList[i] = mobj->tid;
3640 TIDMobj[i++] = mobj;
3641 }
3642 }
3643 // Add termination marker
3644 TIDList[i] = 0;
3645 }
3646
3647 void P_InsertMobjIntoTIDList(mobj_t * mobj, short tid)
3648 {
3649 int i;
3650 int index;
3651
3652 index = -1;
3653 for (i = 0; TIDList[i] != 0; i++)
3654 {
3655 if (TIDList[i] == -1)
3656 { // Found empty slot
3657 index = i;
3658 break;
3659 }
3660 }
3661 if (index == -1)
3662 { // Append required
3663 if (i == MAX_TID_COUNT)
3664 {
3665 I_Error("P_InsertMobjIntoTIDList: MAX_TID_COUNT (%d)"
3666 "exceeded.", MAX_TID_COUNT);
3667 }
3668 index = i;
3669 TIDList[index + 1] = 0;
3670 }
3671 mobj->tid = tid;
3672 TIDList[index] = tid;
3673 TIDMobj[index] = mobj;
3674 }
3675
3676 void P_RemoveMobjFromTIDList(mobj_t * mobj)
3677 {
3678 int i;
3679
3680 for (i = 0; TIDList[i] != 0; i++)
3681 {
3682 if (TIDMobj[i] == mobj)
3683 {
3684 TIDList[i] = -1;
3685 TIDMobj[i] = NULL;
3686 mobj->tid = 0;
3687 return;
3688 }
3689 }
3690 mobj->tid = 0;
3691 }
3692
3693 mobj_t *P_FindMobjFromTID(short tid, int *searchPosition)
3694 {
3695 int i;
3696
3697 for (i = *searchPosition + 1; TIDList[i] != 0; i++)
3698 {
3699 if (TIDList[i] == tid)
3700 {
3701 *searchPosition = i;
3702 return TIDMobj[i];
3703 }
3704 }
3705 *searchPosition = -1;
3706 return NULL;
3707 }
3708
3709 void P_BloodSplatter2(fixed_t x, fixed_t y, fixed_t z, mobj_t * originator)
3710 {
3711 mobj_t *mo;
3712 int r1, r2;
3713
3714 r1 = P_Random(pr_hexen);
3715 r2 = P_Random(pr_hexen);
3716 mo = P_SpawnMobj(x + ((r2 - 128) << 11),
3717 y + ((r1 - 128) << 11), z, HEXEN_MT_AXEBLOOD);
3718 P_SetTarget(&mo->target, originator);
3719 }
3720
3721 #define SMALLSPLASHCLIP 12<<FRACBITS;
3722
3723 static int Hexen_P_HitFloor(mobj_t * thing)
3724 {
3725 mobj_t *mo;
3726 int smallsplash = false;
3727
3728 if (thing->floorz != thing->subsector->sector->floorheight)
3729 { // don't splash if landing on the edge above water/lava/etc....
3730 return (FLOOR_SOLID);
3731 }
3732
3733 // Things that don't splash go here
3734 switch (thing->type)
3735 {
3736 case HEXEN_MT_LEAF1:
3737 case HEXEN_MT_LEAF2:
3738 case HEXEN_MT_SPLASH:
3739 case HEXEN_MT_SLUDGECHUNK:
3740 return (FLOOR_SOLID);
3741 default:
3742 break;
3743 }
3744
3745 // Small splash for small masses
3746 if (thing->info->mass < 10)
3747 smallsplash = true;
3748
3749 switch (P_GetThingFloorType(thing))
3750 {
3751 case FLOOR_WATER:
3752 if (smallsplash)
3753 {
3754 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HEXEN_MT_SPLASHBASE);
3755 if (mo)
3756 mo->floorclip += SMALLSPLASHCLIP;
3757 S_StartMobjSound(mo, hexen_sfx_ambient10); // small drip
3758 }
3759 else
3760 {
3761 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HEXEN_MT_SPLASH);
3762 P_SetTarget(&mo->target, thing);
3763 mo->momx = P_SubRandom() << 8;
3764 mo->momy = P_SubRandom() << 8;
3765 mo->momz = 2 * FRACUNIT + (P_Random(pr_hexen) << 8);
3766 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HEXEN_MT_SPLASHBASE);
3767 if (thing->player)
3768 P_NoiseAlert(thing, thing);
3769 S_StartMobjSound(mo, hexen_sfx_water_splash);
3770 }
3771 return (FLOOR_WATER);
3772 case FLOOR_LAVA:
3773 if (smallsplash)
3774 {
3775 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HEXEN_MT_LAVASPLASH);
3776 if (mo)
3777 mo->floorclip += SMALLSPLASHCLIP;
3778 }
3779 else
3780 {
3781 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HEXEN_MT_LAVASMOKE);
3782 mo->momz = FRACUNIT + (P_Random(pr_hexen) << 7);
3783 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, HEXEN_MT_LAVASPLASH);
3784 if (thing->player)
3785 P_NoiseAlert(thing, thing);
3786 }
3787 S_StartMobjSound(mo, hexen_sfx_lava_sizzle);
3788 if (thing->player && leveltime & 31)
3789 {
3790 P_DamageMobj(thing, &LavaInflictor, NULL, 5);
3791 }
3792 return (FLOOR_LAVA);
3793 case FLOOR_SLUDGE:
3794 if (smallsplash)
3795 {
3796 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ,
3797 HEXEN_MT_SLUDGESPLASH);
3798 if (mo)
3799 mo->floorclip += SMALLSPLASHCLIP;
3800 }
3801 else
3802 {
3803 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ,
3804 HEXEN_MT_SLUDGECHUNK);
3805 P_SetTarget(&mo->target, thing);
3806 mo->momx = P_SubRandom() << 8;
3807 mo->momy = P_SubRandom() << 8;
3808 mo->momz = FRACUNIT + (P_Random(pr_hexen) << 8);
3809 mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ,
3810 HEXEN_MT_SLUDGESPLASH);
3811 if (thing->player)
3812 P_NoiseAlert(thing, thing);
3813 }
3814 S_StartMobjSound(mo, hexen_sfx_sludge_gloop);
3815 return (FLOOR_SLUDGE);
3816 }
3817 return (FLOOR_SOLID);
3818 }
3819
3820 mobj_t *P_SpawnMissileXYZ(fixed_t x, fixed_t y, fixed_t z,
3821 mobj_t * source, mobj_t * dest, mobjtype_t type)
3822 {
3823 mobj_t *th;
3824 angle_t an;
3825 int dist;
3826
3827 z -= source->floorclip;
3828 th = P_SpawnMobj(x, y, z, type);
3829 if (th->info->seesound)
3830 {
3831 S_StartMobjSound(th, th->info->seesound);
3832 }
3833 P_SetTarget(&th->target, source); // Originator
3834 an = R_PointToAngle2(source->x, source->y, dest->x, dest->y);
3835 if (dest->flags & MF_SHADOW)
3836 { // Invisible target
3837 an += P_SubRandom() << 21;
3838 }
3839 th->angle = an;
3840 an >>= ANGLETOFINESHIFT;
3841 th->momx = FixedMul(th->info->speed, finecosine[an]);
3842 th->momy = FixedMul(th->info->speed, finesine[an]);
3843 dist = P_AproxDistance(dest->x - source->x, dest->y - source->y);
3844 dist = dist / th->info->speed;
3845 if (dist < 1)
3846 {
3847 dist = 1;
3848 }
3849 th->momz = (dest->z - source->z) / dist;
3850 return (P_CheckMissileSpawn(th) ? th : NULL);
3851 }
3852
3853 mobj_t *P_SpawnKoraxMissile(fixed_t x, fixed_t y, fixed_t z,
3854 mobj_t * source, mobj_t * dest, mobjtype_t type)
3855 {
3856 mobj_t *th;
3857 angle_t an;
3858 int dist;
3859
3860 z -= source->floorclip;
3861 th = P_SpawnMobj(x, y, z, type);
3862 if (th->info->seesound)
3863 {
3864 S_StartMobjSound(th, th->info->seesound);
3865 }
3866 P_SetTarget(&th->target, source); // Originator
3867 an = R_PointToAngle2(x, y, dest->x, dest->y);
3868 if (dest->flags & MF_SHADOW)
3869 { // Invisible target
3870 an += P_SubRandom() << 21;
3871 }
3872 th->angle = an;
3873 an >>= ANGLETOFINESHIFT;
3874 th->momx = FixedMul(th->info->speed, finecosine[an]);
3875 th->momy = FixedMul(th->info->speed, finesine[an]);
3876 dist = P_AproxDistance(dest->x - x, dest->y - y);
3877 dist = dist / th->info->speed;
3878 if (dist < 1)
3879 {
3880 dist = 1;
3881 }
3882 th->momz = (dest->z - z + (30 * FRACUNIT)) / dist;
3883 return (P_CheckMissileSpawn(th) ? th : NULL);
3884 }