-
Notifications
You must be signed in to change notification settings - Fork 5
/
p_pspr.pas
1108 lines (962 loc) · 32.5 KB
/
p_pspr.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_pspr;
interface
uses
doomdef,
// Basic data types.
// Needs fixed point, and BAM angles.
m_fixed,
tables,
info_h,
p_pspr_h,
p_mobj_h,
d_player;
const
//
// Frame flags:
// handles maximum brightness (torches, muzzle flare, light sources)
//
FF_FULLBRIGHT = $8000; // flag in thing->frame
FF_FRAMEMASK = $7fff;
//==============================================================================
//
// P_DropWeapon
//
//==============================================================================
procedure P_DropWeapon(player: Pplayer_t);
//==============================================================================
//
// A_WeaponReady
//
//==============================================================================
procedure A_WeaponReady(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_ReFire
//
//==============================================================================
procedure A_ReFire(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_CheckReload
//
//==============================================================================
procedure A_CheckReload(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_Lower
//
//==============================================================================
procedure A_Lower(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_Raise
//
//==============================================================================
procedure A_Raise(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_GunFlash
//
//==============================================================================
procedure A_GunFlash(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_Punch
//
//==============================================================================
procedure A_Punch(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_Saw
//
//==============================================================================
procedure A_Saw(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_FireMissile
//
//==============================================================================
procedure A_FireMissile(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_FireBFG
//
//==============================================================================
procedure A_FireBFG(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_FirePlasma
//
//==============================================================================
procedure A_FirePlasma(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_FirePistol
//
//==============================================================================
procedure A_FirePistol(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_FireShotgun
//
//==============================================================================
procedure A_FireShotgun(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_FireShotgun2
//
//==============================================================================
procedure A_FireShotgun2(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_FireCGun
//
//==============================================================================
procedure A_FireCGun(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_Light0
//
//==============================================================================
procedure A_Light0(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_Light1
//
//==============================================================================
procedure A_Light1(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_Light2
//
//==============================================================================
procedure A_Light2(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// A_BFGSpray
//
//==============================================================================
procedure A_BFGSpray(mo: Pmobj_t);
//==============================================================================
//
// A_BFGsound
//
//==============================================================================
procedure A_BFGsound(player: Pplayer_t; psp: Ppspdef_t);
//==============================================================================
//
// P_SetupPsprites
//
//==============================================================================
procedure P_SetupPsprites(player: Pplayer_t);
//==============================================================================
//
// P_MovePsprites
//
//==============================================================================
procedure P_MovePsprites(player: Pplayer_t);
//==============================================================================
//
// P_BulletSlope
//
//==============================================================================
procedure P_BulletSlope(mo: Pmobj_t);
const
MAXWEAPONBOBSTRENGTH = 150;
var
weaponbobstrengthpct: integer = 100;
psprdefs: array[-1..MAXPLAYERS - 1] of array[-1..Ord(NUMPSPRITES) - 1] of psprdef_t;
//==============================================================================
//
// PspdefToPsprdef
//
//==============================================================================
function PspdefToPsprdef(const p: Pplayer_t; const psp: Ppspdef_t): Ppsprdef_t;
//==============================================================================
//
// P_SetPsprite
//
//==============================================================================
procedure P_SetPsprite(player: Pplayer_t; position: integer; stnum: statenum_t);
implementation
uses
d_fpc,
info,
//
// Needs to include the precompiled
// sprite animation tables.
// Header generated by multigen utility.
// This includes all the data for thing animation,
// i.e. the Thing Atrributes table
// and the Frame Sequence table.
d_event,
d_items,
m_rnd,
p_local,
p_tick,
p_mobj,
p_enemy,
p_map,
p_inter,
r_main,
s_sound,
// State.
doomstat,
// Data.
sounds;
//
// Adjust weapon bottom and top
//
const
WEAPONTOP = 32 * FRACUNIT;
WEAPONBOTTOM = WEAPONTOP + 96 * FRACUNIT;
const
LOWERSPEED = 6 * FRACUNIT;
RAISESPEED = 6 * FRACUNIT;
const
// plasma cells for a bfg attack
BFGCELLS = 40;
//==============================================================================
//
// P_SetPsprite
//
//==============================================================================
procedure P_SetPsprite(player: Pplayer_t; position: integer; stnum: statenum_t);
var
psp: Ppspdef_t;
state: Pstate_t;
pid: integer;
begin
psp := @player.psprites[position];
pid := PlayerToId(player);
repeat
if Ord(stnum) = 0 then
begin
// object removed itself
psp.state := nil;
break;
end;
state := @states[Ord(stnum)];
psp.state := state;
psp.tics := state.tics; // could be 0
// coordinate set
if state.misc1 <> 0 then
begin
psp.sx := state.misc1 * FRACUNIT;
// Customizable player bob
psprdefs[pid, position].r_sx := psp.sx;
end;
if state.misc2 <> 0 then
begin
psp.sy := state.misc2 * FRACUNIT;
// Customizable player bob
psprdefs[pid, position].r_sy := psp.sy;
end;
// Call action routine.
// Modified handling.
if Assigned(state.action.acp2) then
begin
state.action.acp2(player, psp);
if psp.state = nil then
break;
end;
stnum := psp.state.nextstate;
until psp.tics <> 0;
// an initial state of 0 could cycle through
end;
//==============================================================================
//
// P_BringUpWeapon
// Starts bringing the pending weapon up
// from the bottom of the screen.
// Uses player
//
//==============================================================================
procedure P_BringUpWeapon(player: Pplayer_t);
var
newstate: statenum_t;
begin
if player.pendingweapon = wp_nochange then
player.pendingweapon := player.readyweapon;
if player.pendingweapon = wp_chainsaw then
S_StartSound(player.mo, Ord(sfx_sawup));
newstate := statenum_t(weaponinfo[Ord(player.pendingweapon)].upstate);
player.pendingweapon := wp_nochange;
player.psprites[Ord(ps_weapon)].sy := WEAPONBOTTOM;
psprdefs[PlayerToId(player)][Ord(ps_weapon)].r_sy := WEAPONBOTTOM;
P_SetPsprite(player, Ord(ps_weapon), newstate);
end;
//==============================================================================
//
// P_CheckAmmo
// Returns true if there is enough ammo to shoot.
// If not, selects the next weapon to use.
//
//==============================================================================
function P_CheckAmmo(player: Pplayer_t): boolean;
var
ammo: ammotype_t;
count: integer;
begin
ammo := weaponinfo[Ord(player.readyweapon)].ammo;
// Minimal amount for one shot varies.
if player.readyweapon = wp_bfg then
count := BFGCELLS
else if player.readyweapon = wp_supershotgun then
count := 2 // Double barrel.
else
count := 1; // Regular.
// Some do not need ammunition anyway.
// Return if current ammunition sufficient.
if (ammo = am_noammo) or (player.ammo[Ord(ammo)] >= count) then
begin
result := true;
exit;
end;
// Out of ammo, pick a weapon to change to.
// Preferences are set here.
repeat
if (player.weaponowned[Ord(wp_plasma)] <> 0) and
(player.ammo[Ord(am_cell)] <> 0) and
(gamemode <> shareware) then
player.pendingweapon := wp_plasma
else if (player.weaponowned[Ord(wp_supershotgun)] <> 0) and
(player.ammo[Ord(am_shell)] > 2) and
(gamemode = commercial) then
player.pendingweapon := wp_supershotgun
else if (player.weaponowned[Ord(wp_chaingun)] <> 0) and
(player.ammo[Ord(am_clip)] <> 0) then
player.pendingweapon := wp_chaingun
else if (player.weaponowned[Ord(wp_shotgun)] <> 0) and
(player.ammo[Ord(am_shell)] <> 0) then
player.pendingweapon := wp_shotgun
else if player.ammo[Ord(am_clip)] <> 0 then
player.pendingweapon := wp_pistol
else if player.weaponowned[Ord(wp_chainsaw)] <> 0 then
player.pendingweapon := wp_chainsaw
else if (player.weaponowned[Ord(wp_missile)] <> 0) and
(player.ammo[Ord(am_misl)] <> 0) then
player.pendingweapon := wp_missile
else if (player.weaponowned[Ord(wp_bfg)] <> 0) and
(player.ammo[Ord(am_cell)] > 40) and
(gamemode <> shareware) then
player.pendingweapon := wp_bfg
else
// If everything fails.
player.pendingweapon := wp_fist;
until not (player.pendingweapon = wp_nochange);
// Now set appropriate weapon overlay.
P_SetPsprite(player, Ord(ps_weapon), statenum_t(weaponinfo[Ord(player.readyweapon)].downstate));
result := false;
end;
//==============================================================================
//
// P_FireWeapon.
//
//==============================================================================
procedure P_FireWeapon(player: Pplayer_t);
var
newstate: statenum_t;
begin
if P_CheckAmmo(player) then
begin
P_SetMobjState(player.mo, S_PLAY_ATK1);
newstate := statenum_t(weaponinfo[Ord(player.readyweapon)].atkstate);
P_SetPsprite(player, Ord(ps_weapon), newstate);
P_NoiseAlert(player.mo, player.mo);
end;
end;
//==============================================================================
//
// P_DropWeapon
// Player died, so put the weapon away.
//
//==============================================================================
procedure P_DropWeapon(player: Pplayer_t);
begin
P_SetPsprite(player, Ord(ps_weapon), statenum_t(weaponinfo[Ord(player.readyweapon)].downstate));
end;
//==============================================================================
//
// PspdefToId
//
//==============================================================================
function PspdefToId(const p: Pplayer_t; const psp: Ppspdef_t): integer;
var
i: integer;
begin
for i := 0 to Ord(NUMPSPRITES) - 1 do
if psp = @p.psprites[i] then
begin
result := i;
exit;
end;
result := -1;
end;
//==============================================================================
//
// A_WeaponReady
// The player can fire the weapon
// or change to another weapon at this time.
// Follows after getting weapon up,
// or after previous attack/fire sequence.
//
//==============================================================================
procedure A_WeaponReady(player: Pplayer_t; psp: Ppspdef_t);
var
newstate: statenum_t;
angle: integer;
pid, ppid: integer;
begin
// get out of attack state
if (player.mo.state = @states[Ord(S_PLAY_ATK1)]) or
(player.mo.state = @states[Ord(S_PLAY_ATK2)]) then
P_SetMobjState(player.mo, S_PLAY);
if (player.readyweapon = wp_chainsaw) and
(psp.state = @states[Ord(S_SAW)]) then
S_StartSound(player.mo, Ord(sfx_sawidl));
// check for change
// if player is dead, put the weapon away
if (player.pendingweapon <> wp_nochange) or (player.health = 0) then
begin
// change weapon
// (pending weapon should allready be validated)
newstate := statenum_t(weaponinfo[Ord(player.readyweapon)].downstate);
P_SetPsprite(player, Ord(ps_weapon), newstate);
exit;
end;
// check for fire
// the missile launcher and bfg do not auto fire
if player.cmd.buttons and BT_ATTACK <> 0 then
begin
if not player.attackdown or
((player.readyweapon <> wp_missile) and (player.readyweapon <> wp_bfg)) then
begin
player.attackdown := true;
P_FireWeapon(player);
exit;
end;
end
else
player.attackdown := false;
pid := PlayerToId(player);
ppid := PspdefToId(player, psp);
// bob the weapon based on movement speed
angle := (128 * leveltime) and FINEMASK;
psp.sx := FRACUNIT + FixedMul(player.bob, finecosine[angle]);
// Customizable player bob
weaponbobstrengthpct := ibetween(weaponbobstrengthpct, 0, MAXWEAPONBOBSTRENGTH);
psprdefs[pid, ppid].r_sx := FRACUNIT + (FixedMul(player.bob, finecosine[angle]) * weaponbobstrengthpct div 100);
angle := angle and (FINEANGLES div 2 - 1);
psp.sy := WEAPONTOP + FixedMul(player.bob, finesine[angle]);
// Customizable player bob
psprdefs[pid, ppid].r_sy := WEAPONTOP + (FixedMul(player.bob, finesine[angle]) * weaponbobstrengthpct div 100);
end;
//==============================================================================
//
// A_ReFire
// The player can re-fire the weapon
// without lowering it entirely.
//
//==============================================================================
procedure A_ReFire(player: Pplayer_t; psp: Ppspdef_t);
begin
// check for fire
// (if a weaponchange is pending, let it go through instead)
if (player.cmd.buttons and BT_ATTACK <> 0) and
(player.pendingweapon = wp_nochange) and
(player.health > 0) then
begin
player.refire := player.refire + 1;
P_FireWeapon(player);
end
else
begin
player.refire := 0;
P_CheckAmmo(player);
end;
end;
//==============================================================================
//
// A_CheckReload
//
//==============================================================================
procedure A_CheckReload(player: Pplayer_t; psp: Ppspdef_t);
begin
P_CheckAmmo(player);
end;
//==============================================================================
//
// A_Lower
// Lowers current weapon,
// and changes weapon at bottom.
//
//==============================================================================
procedure A_Lower(player: Pplayer_t; psp: Ppspdef_t);
var
pspr: Ppsprdef_t;
begin
psp.sy := psp.sy + LOWERSPEED;
// Customizable player bob
pspr := PspdefToPsprdef(player, psp);
pspr.r_sy := pspr.r_sy + LOWERSPEED;
// Is already down.
if psp.sy < WEAPONBOTTOM then
exit;
// Player is dead.
if player.playerstate = PST_DEAD then
begin
psp.sy := WEAPONBOTTOM;
// Customizable player bob
pspr.r_sy := WEAPONBOTTOM;
// don't bring weapon back up
exit;
end;
// The old weapon has been lowered off the screen,
// so change the weapon and start raising it
if player.health = 0 then
begin
// Player is dead, so keep the weapon off screen.
P_SetPsprite(player, Ord(ps_weapon), S_NULL);
exit;
end;
player.readyweapon := player.pendingweapon;
P_BringUpWeapon(player);
end;
//==============================================================================
//
// A_Raise
//
//==============================================================================
procedure A_Raise(player: Pplayer_t; psp: Ppspdef_t);
var
newstate: statenum_t;
pspr: Ppsprdef_t;
begin
psp.sy := psp.sy - RAISESPEED;
// Customizable player bob
pspr := PspdefToPsprdef(player, psp);
pspr.r_sy := pspr.r_sy - RAISESPEED;
if psp.sy > WEAPONTOP then
exit;
psp.sy := WEAPONTOP;
// Customizable player bob
pspr.r_sy := WEAPONTOP;
// The weapon has been raised all the way,
// so change to the ready state.
newstate := statenum_t(weaponinfo[Ord(player.readyweapon)].readystate);
P_SetPsprite(player, Ord(ps_weapon), newstate);
end;
//==============================================================================
//
// A_GunFlash
//
//==============================================================================
procedure A_GunFlash(player: Pplayer_t; psp: Ppspdef_t);
begin
P_SetMobjState(player.mo, S_PLAY_ATK2);
P_SetPsprite(player, Ord(ps_flash), statenum_t(weaponinfo[Ord(player.readyweapon)].flashstate));
end;
//==============================================================================
//
// WEAPON ATTACKS
//
// A_Punch
//
//==============================================================================
procedure A_Punch(player: Pplayer_t; psp: Ppspdef_t);
var
angle: angle_t;
damage: integer;
slope: integer;
begin
damage := (P_Random mod 10 + 1) * 2;
if player.powers[Ord(pw_strength)] <> 0 then
damage := damage * 10;
angle := player.mo.angle;
angle := angle + _SHLW(P_Random - P_Random, 18);
slope := P_AimLineAttack(player.mo, angle, MELEERANGE);
P_LineAttack(player.mo, angle, MELEERANGE, slope, damage);
// turn to face target
if linetarget <> nil then
begin
S_StartSound(player.mo, Ord(sfx_punch));
player.mo.angle :=
P_PointToAngle(player.mo.x, player.mo.y, linetarget.x, linetarget.y);
end;
end;
//==============================================================================
//
// A_Saw
//
//==============================================================================
procedure A_Saw(player: Pplayer_t; psp: Ppspdef_t);
var
angle: angle_t;
damage: integer;
slope: integer;
begin
damage := 2 * (P_Random mod 10 + 1);
angle := player.mo.angle;
angle := angle + _SHLW(P_Random - P_Random, 18);
// use meleerange + 1 se the puff doesn't skip the flash
slope := P_AimLineAttack(player.mo, angle, MELEERANGE + 1);
P_LineAttack(player.mo, angle, MELEERANGE + 1, slope, damage);
if linetarget = nil then
begin
S_StartSound(player.mo, Ord(sfx_sawful));
exit;
end;
S_StartSound(player.mo, Ord(sfx_sawhit));
// turn to face target
angle :=
P_PointToAngle(player.mo.x, player.mo.y, linetarget.x, linetarget.y);
if angle - player.mo.angle > ANG180 then
begin
if integer(angle - player.mo.angle) < - integer(ANG90 div 20) then
player.mo.angle := angle + ANG90 div 21
else
player.mo.angle := player.mo.angle - ANG90 div 20;
end
else
begin
if angle - player.mo.angle > ANG90 div 20 then
player.mo.angle := angle - ANG90 div 21
else
player.mo.angle := player.mo.angle + ANG90 div 20;
end;
player.mo.flags := player.mo.flags or MF_JUSTATTACKED;
end;
//==============================================================================
//
// A_FireMissile
//
//==============================================================================
procedure A_FireMissile(player: Pplayer_t; psp: Ppspdef_t);
begin
player.ammo[Ord(weaponinfo[Ord(player.readyweapon)].ammo)] :=
player.ammo[Ord(weaponinfo[Ord(player.readyweapon)].ammo)] - 1;
P_SpawnPlayerMissile(player.mo, Ord(MT_ROCKET));
end;
//==============================================================================
//
// A_FireBFG
//
//==============================================================================
procedure A_FireBFG(player: Pplayer_t; psp: Ppspdef_t);
begin
player.ammo[Ord(weaponinfo[Ord(player.readyweapon)].ammo)] :=
player.ammo[Ord(weaponinfo[Ord(player.readyweapon)].ammo)] - BFGCELLS;
P_SpawnPlayerMissile(player.mo, Ord(MT_BFG));
end;
//==============================================================================
//
// A_FirePlasma
//
//==============================================================================
procedure A_FirePlasma(player: Pplayer_t; psp: Ppspdef_t);
begin
player.ammo[Ord(weaponinfo[Ord(player.readyweapon)].ammo)] :=
player.ammo[Ord(weaponinfo[Ord(player.readyweapon)].ammo)] - 1;
P_SetPsprite(player,
Ord(ps_flash), statenum_t(weaponinfo[Ord(player.readyweapon)].flashstate + (P_Random and 1)));
P_SpawnPlayerMissile(player.mo, Ord(MT_PLASMA));
end;
//
// P_BulletSlope
// Sets a slope so a near miss is at aproximately
// the height of the intended target
//
var
bulletslope: fixed_t;
//==============================================================================
//
// P_BulletSlope
//
//==============================================================================
procedure P_BulletSlope(mo: Pmobj_t);
var
an: angle_t;
begin
// see which target is to be aimed at
an := mo.angle;
bulletslope := P_AimLineAttack(mo, an, 16 * 64 * FRACUNIT);
if linetarget = nil then
begin
an := an + $4000000;
bulletslope := P_AimLineAttack(mo, an, 16 * 64 * FRACUNIT);
if linetarget = nil then
begin
an := an - $8000000;
bulletslope := P_AimLineAttack(mo, an, 16 * 64 * FRACUNIT);
if zaxisshift and (linetarget = nil) then
bulletslope := (Pplayer_t(mo.player).lookupdown * (FRACUNIT div 16)) div 173;
end;
end;
end;
//==============================================================================
//
// P_GunShot
//
//==============================================================================
procedure P_GunShot(mo: Pmobj_t; accurate: boolean);
var
angle: angle_t;
damage: integer;
begin
damage := 5 * ((P_Random mod 3) + 1);
angle := mo.angle;
if not accurate then
angle := angle + _SHLW(P_Random - P_Random, 18);
P_LineAttack(mo, angle, MISSILERANGE, bulletslope, damage);
end;
//==============================================================================
//
// A_FirePistol
//
//==============================================================================
procedure A_FirePistol(player: Pplayer_t; psp: Ppspdef_t);
var
am: integer;
begin
S_StartSound(player.mo, Ord(sfx_pistol));
P_SetMobjState(player.mo, S_PLAY_ATK2);
am := Ord(weaponinfo[Ord(player.readyweapon)].ammo);
player.ammo[am] := player.ammo[am] - 1;
P_SetPsprite(player, Ord(ps_flash), statenum_t(weaponinfo[Ord(player.readyweapon)].flashstate));
P_BulletSlope(player.mo);
P_GunShot(player.mo, player.refire = 0);
end;
//==============================================================================
//
// A_FireShotgun
//
//==============================================================================
procedure A_FireShotgun(player: Pplayer_t; psp: Ppspdef_t);
var
i: integer;
am: integer;
begin
S_StartSound(player.mo, Ord(sfx_shotgn));
P_SetMobjState(player.mo, S_PLAY_ATK2);
am := Ord(weaponinfo[Ord(player.readyweapon)].ammo);
player.ammo[am] := player.ammo[am] - 1;
P_SetPsprite(player, Ord(ps_flash), statenum_t(weaponinfo[Ord(player.readyweapon)].flashstate));
P_BulletSlope(player.mo);
for i := 0 to 6 do
P_GunShot(player.mo, false);
end;
//==============================================================================
//
// A_FireShotgun2
//
//==============================================================================
procedure A_FireShotgun2(player: Pplayer_t; psp: Ppspdef_t);
var
i: integer;
angle: angle_t;
damage: integer;
am: integer;
begin
S_StartSound(player.mo, Ord(sfx_dshtgn));
P_SetMobjState(player.mo, S_PLAY_ATK2);
am := Ord(weaponinfo[Ord(player.readyweapon)].ammo);
player.ammo[am] := player.ammo[am] - 2;
P_SetPsprite(player, Ord(ps_flash), statenum_t(weaponinfo[Ord(player.readyweapon)].flashstate));
P_BulletSlope(player.mo);
for i := 0 to 19 do
begin
damage := 5 * ((P_Random mod 3) + 1);
angle := player.mo.angle;
angle := angle + _SHLW(P_Random - P_Random, 19);
P_LineAttack(player.mo, angle, MISSILERANGE,
bulletslope + _SHL(P_Random - P_Random, 5), damage);
end;
end;
//==============================================================================
//
// A_FireCGun
//
//==============================================================================
procedure A_FireCGun(player: Pplayer_t; psp: Ppspdef_t);
var
am: integer;
begin
S_StartSound(player.mo, Ord(sfx_pistol));
if player.ammo[Ord(weaponinfo[Ord(player.readyweapon)].ammo)] = 0 then
exit;
P_SetMobjState(player.mo, S_PLAY_ATK2);
am := Ord(weaponinfo[Ord(player.readyweapon)].ammo);
player.ammo[am] := player.ammo[am] - 1;
P_SetPsprite(player, Ord(ps_flash),
statenum_t(
weaponinfo[Ord(player.readyweapon)].flashstate +
pDiff(psp.state, @states[Ord(S_CHAIN1)], SizeOf(states[0]))
));
P_BulletSlope(player.mo);
P_GunShot(player.mo, player.refire = 0);
end;
//==============================================================================
//
// A_Light0
//
//==============================================================================
procedure A_Light0(player: Pplayer_t; psp: Ppspdef_t);
begin
player.extralight := 0;
end;
//==============================================================================
//
// A_Light1
//
//==============================================================================
procedure A_Light1(player: Pplayer_t; psp: Ppspdef_t);
begin
player.extralight := 1;
end;
//==============================================================================
//
// A_Light2
//
//==============================================================================
procedure A_Light2(player: Pplayer_t; psp: Ppspdef_t);
begin
player.extralight := 2;
end;
//==============================================================================
//
// A_BFGSpray
// Spawn a BFG explosion on every monster in view
//
//==============================================================================
procedure A_BFGSpray(mo: Pmobj_t);
var
i: integer;
j: integer;
damage: integer;
an: angle_t;
dan: angle_t;
begin
// offset angles from its attack angle