-
Notifications
You must be signed in to change notification settings - Fork 5
/
p_mobj.pas
1624 lines (1413 loc) · 43.2 KB
/
p_mobj.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
unit p_mobj;
interface
uses
p_mobj_h,
tables,
// We need the WAD data structure for Map things,
// from the THINGS lump.
doomdata,
// States are tied to finite states are
// tied to animation frames.
// Needs precompiled tables/data structures.
info_h,
m_fixed;
//==============================================================================
//
// P_SetMobjState
//
//==============================================================================
function P_SetMobjState(mobj: Pmobj_t; state: statenum_t): boolean;
//==============================================================================
//
// P_ExplodeMissile
//
//==============================================================================
procedure P_ExplodeMissile(mo: Pmobj_t);
//==============================================================================
//
// P_MobjThinker
//
//==============================================================================
procedure P_MobjThinker(mobj: Pmobj_t);
//==============================================================================
//
// P_SpawnMobj
//
//==============================================================================
function P_SpawnMobj(x, y, z: fixed_t; _type: integer): Pmobj_t;
//==============================================================================
//
// P_RemoveMobj
//
//==============================================================================
procedure P_RemoveMobj(mobj: Pmobj_t);
//==============================================================================
//
// P_SpawnPlayer
//
//==============================================================================
procedure P_SpawnPlayer(mthing: Pmapthing_t);
//==============================================================================
//
// P_SpawnMapThing
//
//==============================================================================
procedure P_SpawnMapThing(mthing: Pmapthing_t);
//==============================================================================
//
// P_SpawnPuff
//
//==============================================================================
procedure P_SpawnPuff(x, y, z: fixed_t);
//==============================================================================
//
// P_SpawnMissile
//
//==============================================================================
function P_SpawnMissile(source: Pmobj_t; dest: Pmobj_t; _type: integer): Pmobj_t;
//==============================================================================
//
// P_SpawnMissileXYZ
//
//==============================================================================
function P_SpawnMissileXYZ(x, y, z: fixed_t; source: Pmobj_t; dest: Pmobj_t; _type: integer): Pmobj_t;
//==============================================================================
//
// P_SpawnMissileAngleZ
//
//==============================================================================
function P_SpawnMissileAngleZ(source: Pmobj_t; z: fixed_t; _type: integer; angle: angle_t;
momz: fixed_t; speed: fixed_t): Pmobj_t;
//==============================================================================
//
// P_SpawnMissileAngleZSpeed
//
//==============================================================================
function P_SpawnMissileAngleZSpeed(source: Pmobj_t; z: fixed_t; _type: integer; angle: angle_t;
momz: fixed_t; speed: fixed_t; owner: Pmobj_t): Pmobj_t;
//==============================================================================
//
// P_SpawnPlayerMissile
//
//==============================================================================
procedure P_SpawnPlayerMissile(source: Pmobj_t; _type: integer);
//==============================================================================
//
// P_RespawnSpecials
//
//==============================================================================
procedure P_RespawnSpecials;
//==============================================================================
//
// P_SpawnBlood
//
//==============================================================================
procedure P_SpawnBlood(x, y, z: fixed_t; damage: integer);
//==============================================================================
//
// P_SeekerMissile
//
//==============================================================================
function P_SeekerMissile(actor: Pmobj_t; thresh, turnMax: angle_t): boolean;
//==============================================================================
//
// P_HitFloor
//
//==============================================================================
function P_HitFloor(thing: Pmobj_t): integer;
var
iquehead: integer; // Initialized at p_setup
iquetail: integer; // Initialized at p_setup
implementation
uses
d_fpc,
d_player,
d_think,
d_main,
m_vectors,
g_game,
i_system,
z_memory,
m_rnd,
doomdef,
p_local,
p_map,
p_maputl,
p_tick,
p_pspr,
p_setup,
p_extra,
p_terrain,
p_sounds,
r_defs,
r_sky,
r_main,
r_data,
sounds,
st_stuff,
hu_stuff,
s_sound,
info,
info_rnd;
//==============================================================================
//
// P_SetMobjState
// Returns true if the mobj is still present.
//
//==============================================================================
function P_SetMobjState(mobj: Pmobj_t; state: statenum_t): boolean;
var
st: Pstate_t;
begin
repeat
if state = S_NULL then
begin
if mobj.flags_ex and MF_EX_DONOTREMOVE = 0 then // JVAL Do not remove missile
begin
mobj.state := nil;
P_RemoveMobj(mobj);
end;
result := false;
exit;
end;
st := @states[Ord(state)];
mobj.state := st;
mobj.tics := st.tics;
mobj.sprite := st.sprite;
mobj.frame := st.frame;
// Modified handling.
// Call action functions when the state is set
if Assigned(st.action.acp1) then
st.action.acp2(mobj, nil);
state := st.nextstate;
until mobj.tics <> 0;
result := true;
end;
//==============================================================================
//
// P_ExplodeMissile
//
//==============================================================================
procedure P_ExplodeMissile(mo: Pmobj_t);
begin
mo.momx := 0;
mo.momy := 0;
mo.momz := 0;
P_SetMobjState(mo, statenum_t(mobjinfo[Ord(mo._type)].deathstate));
mo.tics := mo.tics - (P_Random and 3);
if mo.tics < 1 then
mo.tics := 1;
mo.flags := mo.flags and not MF_MISSILE;
A_DeathSound(mo, mo);
end;
//
// P_XYMovement
//
const
STOPSPEED = $1000;
FRICTION = $e800;
//==============================================================================
//
// P_XYMovement
//
//==============================================================================
procedure P_XYMovement(mo: Pmobj_t);
var
ptryx: fixed_t;
ptryy: fixed_t;
player: Pplayer_t;
xmove: fixed_t;
ymove: fixed_t;
begin
if mo.momx or mo.momy = 0 then
begin
if mo.flags and MF_SKULLFLY <> 0 then
begin
// the skull slammed into something
mo.flags := mo.flags and not MF_SKULLFLY;
mo.momx := 0;
mo.momy := 0;
mo.momz := 0;
P_SetMobjState(mo, statenum_t(mo.info.spawnstate));
end;
exit;
end;
player := mo.player;
if mo.momx > MAXMOVE then
mo.momx := MAXMOVE
else if mo.momx < -MAXMOVE then
mo.momx := -MAXMOVE;
if mo.momy > MAXMOVE then
mo.momy := MAXMOVE
else if mo.momy < -MAXMOVE then
mo.momy := -MAXMOVE;
xmove := mo.momx;
ymove := mo.momy;
repeat
if (xmove > MAXMOVE div 2) or (ymove > MAXMOVE div 2) then
begin
ptryx := mo.x + xmove div 2;
ptryy := mo.y + ymove div 2;
xmove := _SHR1(xmove);
ymove := _SHR1(ymove);
end
else
begin
ptryx := mo.x + xmove;
ptryy := mo.y + ymove;
xmove := 0;
ymove := 0;
end;
if not P_TryMove(mo, ptryx, ptryy) then
begin
// blocked move
if mo.player <> nil then
begin // try to slide along it
P_SlideMove(mo);
end
else if mo.flags and MF_MISSILE <> 0 then
begin
// explode a missile
if (ceilingline <> nil) and
(ceilingline.backsector <> nil) and
(ceilingline.backsector.ceilingpic = skyflatnum) then
begin
// Hack to prevent missiles exploding
// against the sky.
// Does not handle sky floors.
P_RemoveMobj(mo);
exit;
end;
P_ExplodeMissile(mo);
end
else
begin
mo.momx := 0;
mo.momy := 0;
end;
end;
until not ((xmove <> 0) or (ymove <> 0));
// slow down
if (player <> nil) and (player.cheats and CF_NOMOMENTUM <> 0) then
begin
// debug option for no sliding at all
mo.momx := 0;
mo.momy := 0;
exit;
end;
if (mo.flags and (MF_MISSILE or MF_SKULLFLY)) <> 0 then
exit; // no friction for missiles ever
if mo.z > mo.floorz then
exit; // no friction when airborne
if mo.flags and MF_CORPSE <> 0 then
begin
// do not stop sliding
// if halfway off a step with some momentum
if (mo.momx > FRACUNIT div 4) or
(mo.momx < -FRACUNIT div 4) or
(mo.momy > FRACUNIT div 4) or
(mo.momy < -FRACUNIT div 4) then
begin
if mo.floorz <> Psubsector_t(mo.subsector).sector.floorheight then
exit;
end;
end;
if (mo.momx > -STOPSPEED) and
(mo.momx < STOPSPEED) and
(mo.momy > -STOPSPEED) and
(mo.momy < STOPSPEED) and
((player = nil) or
((player.cmd.forwardmove = 0) and
(player.cmd.sidemove = 0))) then
begin
// if in a walking frame, stop moving
if (player <> nil) and
(LongWord((pDiff(player.mo.state, @states[0], SizeOf(states[0]))) - Ord(S_PLAY_RUN1)) < 4) then
P_SetMobjState(player.mo, S_PLAY);
mo.momx := 0;
mo.momy := 0;
end
else
begin
mo.momx := FixedMul(mo.momx, FRICTION);
mo.momy := FixedMul(mo.momy, FRICTION);
end;
end;
//==============================================================================
//
// P_ZMovement
//
//==============================================================================
procedure P_ZMovement(mo: Pmobj_t);
var
dist: fixed_t;
delta: fixed_t;
ceilz: fixed_t;
grav: integer;
momomz: fixed_t;
begin
// check for smooth step up
if (mo.player <> nil) and (mo.z < mo.floorz) then
begin
Pplayer_t(mo.player).viewheight := Pplayer_t(mo.player).viewheight - (mo.floorz - mo.z);
Pplayer_t(mo.player).deltaviewheight :=
_SHR((PVIEWHEIGHT - Pplayer_t(mo.player).viewheight), 3);
end;
// adjust height
mo.z := mo.z + mo.momz;
if (mo.flags and MF_FLOAT <> 0) and (mo.target <> nil) then
begin
// float down towards target if too close
if ((mo.flags and MF_SKULLFLY) = 0) and
((mo.flags and MF_INFLOAT) = 0) then
begin
dist := P_AproxDistance(mo.x - mo.target.x, mo.y - mo.target.y);
delta := (mo.target.z + _SHR1(mo.height)) - mo.z; // JVAL is it right ???
if (delta < 0) and (dist < -(delta * 3)) then
mo.z := mo.z - FLOATSPEED
else if (delta > 0) and (dist < (delta * 3)) then
mo.z := mo.z + FLOATSPEED;
end;
end;
// clip movement
if mo.z <= mo.floorz then
begin
// hit the floor
// Note (id):
// somebody left this after the setting momz to 0,
// kinda useless there.
if mo.flags and MF_SKULLFLY <> 0 then
begin
// the skull slammed into something
mo.momz := -mo.momz;
end;
momomz := mo.momz;
if mo.momz < 0 then
begin
if (mo.player <> nil) and (mo.momz < -GRAVITY * 8) then
begin
// Squat down.
// Decrease viewheight for a moment
// after hitting the ground (hard),
// and utter appropriate sound.
Pplayer_t(mo.player).deltaviewheight := _SHR(mo.momz, 3);
S_StartSound(mo, Ord(sfx_oof));
end;
mo.momz := 0;
end;
if mo.z - momomz > mo.floorz then
begin // Spawn splashes, etc.
P_HitFloor(mo);
end;
mo.z := mo.floorz;
if (mo.flags and MF_MISSILE <> 0) and (mo.flags and MF_NOCLIP = 0) then
begin
P_ExplodeMissile(mo);
exit;
end;
end
else if mo.flags and MF_NOGRAVITY = 0 then
begin
grav := GRAVITY;
// JVAL
// Low gravity cheat
if mo.player <> nil then
if Pplayer_t(mo.player).cheats and CF_LOWGRAVITY <> 0 then
grav := GRAVITY div 2;
if mo.momz = 0 then
mo.momz := - grav * 2
else
mo.momz := mo.momz - grav;
// JVAL
// Low gravity flag
if mo.flags_ex and MF_EX_LOWGRAVITY <> 0 then
mo.momz := mo.momz div 2
else if mo.flags2_ex and MF2_EX_MEDIUMGRAVITY <> 0 then
mo.momz := mo.momz * 3 div 4;
end;
ceilz := mo.ceilingz + P_SectorJumpOverhead(Psubsector_t(mo.subsector).sector);
if mo.z + mo.height > ceilz then
begin
// hit the ceiling
if mo.momz > 0 then
mo.momz := 0;
mo.z := ceilz - mo.height;
if mo.flags and MF_SKULLFLY <> 0 then
mo.momz := -mo.momz; // the skull slammed into something
if (mo.flags and MF_MISSILE <> 0) and (mo.flags and MF_NOCLIP = 0) then
begin
P_ExplodeMissile(mo);
exit;
end;
end;
end;
//==============================================================================
//
// P_NightmareRespawn
//
//==============================================================================
procedure P_NightmareRespawn(mobj: Pmobj_t);
var
x: fixed_t;
y: fixed_t;
z: fixed_t;
ss: Psubsector_t;
mo: Pmobj_t;
mthing: Pmapthing_t;
begin
x := mobj.spawnpoint.x * FRACUNIT;
y := mobj.spawnpoint.y * FRACUNIT;
// somthing is occupying it's position?
if not P_CheckPosition(mobj, x, y) then
exit; // no respwan
// spawn a teleport fog at old spot
// because of removal of the body?
mo := P_SpawnMobj(mobj.x, mobj.y, Psubsector_t(mobj.subsector).sector.floorheight, Ord(MT_TFOG));
// initiate teleport sound
S_StartSound(mo, Ord(sfx_telept));
// spawn a teleport fog at the new spot
ss := R_PointInSubsector(x, y);
mo := P_SpawnMobj(x, y, ss.sector.floorheight, Ord(MT_TFOG));
S_StartSound(mo, Ord(sfx_telept));
// spawn the new monster
mthing := @(mobj.spawnpoint);
// spawn it
if mobj.info.flags and MF_SPAWNCEILING <> 0 then
z := ONCEILINGZ
else if mobj.info.flags_ex and MF_EX_SPAWNFLOAT <> 0 then
z := ONFLOATZ
else
z := ONFLOORZ;
// inherit attributes from deceased one
mo := P_SpawnMobj(x, y, z, Ord(mobj._type));
mo.spawnpoint := mobj.spawnpoint;
mo.angle := ANG45 * (mthing.angle div 45);
if mthing.options and MTF_AMBUSH <> 0 then
mo.flags := mo.flags or MF_AMBUSH;
mo.reactiontime := 18;
// remove the old monster,
P_RemoveMobj(mobj);
end;
//==============================================================================
//
// P_MobjThinker
//
//==============================================================================
procedure P_MobjThinker(mobj: Pmobj_t);
begin
// momentum movement
if (mobj.momx <> 0) or
(mobj.momy <> 0) or
(mobj.flags and MF_SKULLFLY <> 0) then
begin
P_XYMovement(mobj);
if not Assigned(mobj.thinker._function.acv) then
begin
exit; // mobj was removed
end;
end;
if mobj.flags_ex and MF_EX_FLOATBOB <> 0 then
begin
mobj.z := mobj.floorz + FloatBobOffsets[mobj.floatbob];
mobj.floatbob := (mobj.floatbob + 1) and FLOATBOBMASK;
end
else if (mobj.z <> mobj.floorz) or (mobj.momz <> 0) then
begin
P_ZMovement(mobj);
if not Assigned(mobj.thinker._function.acv) then
begin
exit; // mobj was removed
end;
end;
// cycle through states,
// calling action functions at transitions
if mobj.tics <> -1 then
begin
mobj.tics := mobj.tics - 1;
// you can cycle through multiple states in a tic
if mobj.tics = 0 then
if not P_SetMobjState(mobj, mobj.state.nextstate) then
begin
exit; // freed itself
end;
end
else
begin
// check for nightmare respawn
if mobj.flags and MF_COUNTKILL = 0 then
begin
exit;
end;
if not respawnmonsters then
begin
exit;
end;
mobj.movecount := mobj.movecount + 1;
if mobj.movecount < 12 * TICRATE then
begin
exit;
end;
if leveltime and 31 <> 0 then
begin
exit;
end;
if P_Random > 4 then
begin
exit;
end;
P_NightmareRespawn(mobj);
end;
end;
//==============================================================================
//
// P_SpawnMobj
//
//==============================================================================
function P_SpawnMobj(x, y, z: fixed_t; _type: integer): Pmobj_t;
var
mobj: Pmobj_t;
st: Pstate_t;
info: Pmobjinfo_t;
space: fixed_t;
begin
mobj := Z_Malloc(SizeOf(mobj_t), PU_LEVEL, nil);
ZeroMemory(mobj, SizeOf(mobj_t));
info := @mobjinfo[_type];
mobj._type := _type;
mobj.info := info;
mobj.x := x;
mobj.y := y;
mobj.radius := info.radius;
mobj.height := info.height;
mobj.flags := info.flags;
mobj.flags_ex := info.flags_ex;
mobj.flags2_ex := info.flags2_ex;
mobj.renderstyle := info.renderstyle;
mobj.alpha := info.alpha;
if mobj.flags_ex and MF_EX_FLOATBOB <> 0 then
mobj.floatbob := N_Random and FLOATBOBMASK;
mobj.health := info.spawnhealth;
if gameskill <> sk_nightmare then
mobj.reactiontime := info.reactiontime;
mobj.lastlook := P_Random mod MAXPLAYERS;
// do not set the state with P_SetMobjState,
// because action routines can not be called yet
st := @states[info.spawnstate];
mobj.state := st;
mobj.tics := st.tics;
mobj.sprite := st.sprite;
mobj.frame := st.frame;
// set subsector and/or block links
P_SetThingPosition(mobj);
mobj.floorz := Psubsector_t(mobj.subsector).sector.floorheight;
mobj.ceilingz := Psubsector_t(mobj.subsector).sector.ceilingheight;
if z = ONFLOORZ then
mobj.z := mobj.floorz
else if z = ONCEILINGZ then
mobj.z := mobj.ceilingz - mobj.info.height
else if z = ONFLOATZ then
begin
space := mobj.ceilingz - mobj.info.height - mobj.floorz;
if space > 48 * FRACUNIT then
begin
space := space - 40 * FRACUNIT;
mobj.z := FixedMul(space, N_Random * 256) + mobj.floorz + 40 * FRACUNIT
end
else
mobj.z := mobj.floorz
end
else
mobj.z := z;
@mobj.thinker._function.acp1 := @P_MobjThinker;
P_AddThinker(@mobj.thinker);
mobj.prevx := mobj.x;
mobj.prevy := mobj.y;
mobj.prevz := mobj.z;
mobj.nextx := mobj.x;
mobj.nexty := mobj.y;
mobj.nextz := mobj.z;
mobj.prevangle := mobj.angle;
mobj.nextangle := mobj.angle;
mobj.intrplcnt := 0;
result := mobj;
end;
//
// P_RemoveMobj
//
const
// Time interval for item respawning.
ITEMQUESIZE = 128;
var
itemrespawnque: array[0..ITEMQUESIZE - 1] of mapthing_t;
itemrespawntime: array[0..ITEMQUESIZE - 1] of integer;
//==============================================================================
//
// P_RemoveMobj
//
//==============================================================================
procedure P_RemoveMobj(mobj: Pmobj_t);
begin
if ((mobj.flags and MF_SPECIAL) <> 0) and
((mobj.flags and MF_DROPPED) = 0) and
(mobj._type <> Ord(MT_INV)) and
(mobj._type <> Ord(MT_INS)) then
begin
itemrespawnque[iquehead] := mobj.spawnpoint;
itemrespawntime[iquehead] := leveltime;
iquehead := (iquehead + 1) and (ITEMQUESIZE - 1);
// lose one off the end?
if iquehead = iquetail then
iquetail := (iquetail + 1) and (ITEMQUESIZE - 1);
end;
// unlink from sector and block lists
P_UnsetThingPosition(mobj);
// From Woof: [FG] removed map objects may finish their sounds
if full_sounds then
S_UnlinkSound(mobj)
else
// stop any playing sound
S_StopSound(mobj);
// free block
P_RemoveThinker(Pthinker_t(mobj));
end;
//==============================================================================
//
// P_RespawnSpecials
//
//==============================================================================
procedure P_RespawnSpecials;
var
x: fixed_t;
y: fixed_t;
z: fixed_t;
ss: Psubsector_t;
mo: Pmobj_t;
mthing: Pmapthing_t;
i: integer;
begin
// only respawn items in deathmatch
if deathmatch <> 2 then
exit; //
// nothing left to respawn?
if iquehead = iquetail then
exit;
// wait at least 30 seconds
if leveltime - itemrespawntime[iquetail] < 30 * TICRATE then
exit;
mthing := @itemrespawnque[iquetail];
x := mthing.x * FRACUNIT;
y := mthing.y * FRACUNIT;
// spawn a teleport fog at the new spot
ss := R_PointInSubsector(x, y);
mo := P_SpawnMobj(x, y, ss.sector.floorheight, Ord(MT_IFOG));
S_StartSound(mo, Ord(sfx_itmbk));
// find which type to spawn
i := 0;
while i < nummobjtypes do
begin
if mthing._type = mobjinfo[i].doomednum then
break;
inc(i);
end;
// spawn it
if mobjinfo[i].flags and MF_SPAWNCEILING <> 0 then
z := ONCEILINGZ
else if mobjinfo[i].flags_ex and MF_EX_SPAWNFLOAT <> 0 then
z := ONFLOATZ
else
z := ONFLOORZ;
mo := P_SpawnMobj(x, y, z, i);
mo.spawnpoint := mthing^;
mo.angle := ANG45 * (mthing.angle div 45);
// pull it from the que
iquetail := (iquetail + 1) and (ITEMQUESIZE - 1);
end;
//==============================================================================
//
// P_SpawnPlayer
// Called when a player is spawned on the level.
// Most of the player structure stays unchanged
// between levels.
//
//==============================================================================
procedure P_SpawnPlayer(mthing: Pmapthing_t);
var
p: Pplayer_t;
x: fixed_t;
y: fixed_t;
z: fixed_t;
mobj: Pmobj_t;
i: integer;
plnum: integer;
begin
// not playing?
if not playeringame[mthing._type - 1] then
exit;
plnum := mthing._type - 1;
p := @players[plnum];
if p.playerstate = PST_REBORN then
G_PlayerReborn(plnum);
x := mthing.x * FRACUNIT;
y := mthing.y * FRACUNIT;
z := ONFLOORZ;
mobj := P_SpawnMobj(x, y, z, Ord(MT_PLAYER));
// set color translations for player sprites
if mthing._type > 1 then
mobj.flags := mobj.flags or _SHL(plnum, MF_TRANSSHIFT);
mobj.angle := ANG45 * (mthing.angle div 45);
mobj.player := p;
mobj.health := p.health;
p.mo := mobj;
p.playerstate := PST_LIVE;
p.refire := 0;
p._message := '';
p.damagecount := 0;
p.bonuscount := 0;
p.extralight := 0;
p.fixedcolormap := 0;
p.viewheight := PVIEWHEIGHT;
// setup gun psprite
P_SetupPsprites(p);
// give all cards in death match mode
if deathmatch <> 0 then
for i := 0 to Ord(NUMCARDS) - 1 do
p.cards[i] := true;
if plnum = consoleplayer then
begin
// wake up the status bar
ST_Start;
// wake up the heads up text
HU_Start;
p_justspawned := true;
end;
end;
//==============================================================================
//
// P_SpawnMapThing
// The fields of the mapthing should
// already be in host byte order.
//
//==============================================================================
procedure P_SpawnMapThing(mthing: Pmapthing_t);
var
i: integer;
bit: integer;
mobj: Pmobj_t;
x: fixed_t;
y: fixed_t;
z: fixed_t;
begin
// count deathmatch start positions
if mthing._type = 11 then
begin
if deathmatch_p < MAX_DEATHMATCH_STARTS then
begin
memcpy(@deathmatchstarts[deathmatch_p], mthing, SizeOf(mthing^));
inc(deathmatch_p);
end;
exit;
end;
// check for players specially
if mthing._type <= 4 then
begin
// save spots for respawning in network games
playerstarts[mthing._type - 1] := mthing^;
if deathmatch = 0 then
P_SpawnPlayer(mthing);
exit;
end;
// check for apropriate skill level
if not netgame and ((mthing.options and 16) <> 0) then
exit;
if gameskill = sk_baby then
bit := 1
else if gameskill = sk_nightmare then
bit := 4
else
bit := _SHL(1, Ord(gameskill) - 1);
if mthing.options and bit = 0 then
exit;
// find which type to spawn
i := nummobjtypes - 1;
while i >= 0 do
begin