/
p_pspr.c
2069 lines (1884 loc) · 60.9 KB
/
p_pspr.c
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
/**\file
*\section Copyright and License Summary
* License: Raven
* Online License Link: http://www.dengine.net/raven_license/End_User_License_Hexen_Source_Code.html
*
*\author Copyright © 2003-2006 Jaakko Keränen <skyjake@dengine.net>
*\author Copyright © 2006 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1999 Activision
*
* This program is covered by the HERETIC / HEXEN (LIMITED USE) source
* code license; you can redistribute it and/or modify it under the terms
* of the HERETIC / HEXEN source code license as published by Activision.
*
* THIS MATERIAL IS NOT MADE OR SUPPORTED BY ACTIVISION.
*
* WARRANTY INFORMATION.
* This program is provided as is. Activision and it's affiliates make no
* warranties of any kind, whether oral or written , express or implied,
* including any warranty of merchantability, fitness for a particular
* purpose or non-infringement, and no other representations or claims of
* any kind shall be binding on or obligate Activision or it's affiliates.
*
* LICENSE CONDITIONS.
* You shall not:
*
* 1) Exploit this Program or any of its parts commercially.
* 2) Use this Program, or permit use of this Program, on more than one
* computer, computer terminal, or workstation at the same time.
* 3) Make copies of this Program or any part thereof, or make copies of
* the materials accompanying this Program.
* 4) Use the program, or permit use of this Program, in a network,
* multi-user arrangement or remote access arrangement, including any
* online use, except as otherwise explicitly provided by this Program.
* 5) Sell, rent, lease or license any copies of this Program, without
* the express prior written consent of Activision.
* 6) Remove, disable or circumvent any proprietary notices or labels
* contained on or within the Program.
*
* You should have received a copy of the HERETIC / HEXEN source code
* license along with this program (Ravenlic.txt); if not:
* http://www.ravensoft.com/
*/
/*
* P_pspr.c: Weapon sprite animation.
*
* Weapon sprite animation, weapon objects.
* Action functions for weapons.
*/
// HEADER FILES ------------------------------------------------------------
#include "jhexen.h"
#include "p_player.h"
#include "p_map.h"
// MACROS ------------------------------------------------------------------
#define LOWERSPEED (FRACUNIT*6)
#define RAISESPEED (FRACUNIT*6)
#define WEAPONBOTTOM (128*FRACUNIT)
#define WEAPONTOP (32*FRACUNIT)
#define ZAGSPEED (FRACUNIT)
#define MAX_ANGLE_ADJUST (5*ANGLE_1)
#define HAMMER_RANGE (MELEERANGE+MELEERANGE/2)
#define AXERANGE (2.25*MELEERANGE)
#define FLAMESPEED (0.45*FRACUNIT)
#define CFLAMERANGE (12*64*FRACUNIT)
#define FLAMEROTSPEED (2*FRACUNIT)
#define SHARDSPAWN_LEFT 1
#define SHARDSPAWN_RIGHT 2
#define SHARDSPAWN_UP 4
#define SHARDSPAWN_DOWN 8
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
extern void P_ExplodeMissile(mobj_t *mo);
extern void C_DECL A_UnHideThing(mobj_t *actor);
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern fixed_t FloatBobOffsets[64];
// PUBLIC DATA DEFINITIONS -------------------------------------------------
fixed_t bulletslope;
weaponinfo_t weaponinfo[NUMWEAPONS][NUMCLASSES] = {
{ // First Weapons
{ // Fighter First Weapon - Punch
{
GM_ANY, // Gamemode bits
{0, 0}, // type: mana1 | mana2
{0, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_PUNCHUP, // upstate
0, // raise sound id
S_PUNCHDOWN, // downstate
S_PUNCHREADY, // readystate
0, // readysound
S_PUNCHATK1_1, // atkstate
S_PUNCHATK1_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Cleric First Weapon - Mace
GM_ANY, // Gamemode bits
{0, 0}, // type: mana1 | mana2
{0, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_CMACEUP, // upstate
0, // raise sound id
S_CMACEDOWN, // downstate
S_CMACEREADY, // readystate
0, // readysound
S_CMACEATK_1, // atkstate
S_CMACEATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Mage First Weapon - Wand
GM_ANY, // Gamemode bits
{0, 0}, // type: mana1 | mana2
{0, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_MWANDUP,
0, // raise sound id
S_MWANDDOWN,
S_MWANDREADY,
0, // readysound
S_MWANDATK_1,
S_MWANDATK_1,
S_NULL
}
},
{
{ // Pig - Snout
GM_ANY, // Gamemode bits
{0, 0}, // type: mana1 | mana2
{0, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_SNOUTUP, // upstate
0, // raise sound id
S_SNOUTDOWN, // downstate
S_SNOUTREADY, // readystate
0, // readysound
S_SNOUTATK1, // atkstate
S_SNOUTATK1, // holdatkstate
S_NULL // flashstate
}
}
},
{ // Second Weapons
{
{ // Fighter - Axe
GM_ANY, // Gamemode bits
{1, 0}, // type: mana1 | mana2
{2, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_FAXEUP, // upstate
0, // raise sound id
S_FAXEDOWN, // downstate
S_FAXEREADY, // readystate
0, // readysound
S_FAXEATK_1, // atkstate
S_FAXEATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Cleric - Serpent Staff
GM_ANY, // Gamemode bits
{1, 0}, // type: mana1 | mana2
{1, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_CSTAFFUP, // upstate
0, // raise sound id
S_CSTAFFDOWN, // downstate
S_CSTAFFREADY, // readystate
0, // readysound
S_CSTAFFATK_1, // atkstate
S_CSTAFFATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Mage - Cone of shards
GM_ANY, // Gamemode bits
{1, 0}, // type: mana1 | mana2
{3, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_CONEUP, // upstate
0, // raise sound id
S_CONEDOWN, // downstate
S_CONEREADY, // readystate
0, // readysound
S_CONEATK1_1, // atkstate
S_CONEATK1_3, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Pig - Snout
GM_ANY, // Gamemode bits
{0, 0}, // type: mana1 | mana2
{0, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_SNOUTUP, // upstate
0, // raise sound id
S_SNOUTDOWN, // downstate
S_SNOUTREADY, // readystate
0, // readysound
S_SNOUTATK1, // atkstate
S_SNOUTATK1, // holdatkstate
S_NULL // flashstate
}
}
},
{ // Third Weapons
{
{ // Fighter - Hammer
GM_ANY, // Gamemode bits
{0, 1}, // type: mana1 | mana2
{0, 3}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_FHAMMERUP, // upstate
0, // raise sound id
S_FHAMMERDOWN, // downstate
S_FHAMMERREADY, // readystate
0, // readysound
S_FHAMMERATK_1, // atkstate
S_FHAMMERATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Cleric - Flame Strike
GM_ANY, // Gamemode bits
{0, 1}, // type: mana1 | mana2
{0, 4}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_CFLAMEUP, // upstate
0, // raise sound id
S_CFLAMEDOWN, // downstate
S_CFLAMEREADY1, // readystate
0, // readysound
S_CFLAMEATK_1, // atkstate
S_CFLAMEATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Mage - Lightning
GM_ANY, // Gamemode bits
{0, 1}, // type: mana1 | mana2
{0, 5}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_MLIGHTNINGUP, // upstate
0, // raise sound id
S_MLIGHTNINGDOWN, // downstate
S_MLIGHTNINGREADY, // readystate
0, // readysound
S_MLIGHTNINGATK_1, // atkstate
S_MLIGHTNINGATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Pig - Snout
GM_ANY, // Gamemode bits
{0, 0}, // type: mana1 | mana2
{0, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_SNOUTUP, // upstate
0, // raise sound id
S_SNOUTDOWN, // downstate
S_SNOUTREADY, // readystate
0, // readysound
S_SNOUTATK1, // atkstate
S_SNOUTATK1, // holdatkstate
S_NULL // flashstate
}
}
},
{ // Fourth Weapons
{
{ // Fighter - Rune Sword
GM_ANY, // Gamemode bits
{1, 1}, // type: mana1 | mana2
{14, 14}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_FSWORDUP, // upstate
0, // raise sound id
S_FSWORDDOWN, // downstate
S_FSWORDREADY, // readystate
0, // readysound
S_FSWORDATK_1, // atkstate
S_FSWORDATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Cleric - Holy Symbol
GM_ANY, // Gamemode bits
{1, 1}, // type: mana1 | mana2
{18, 18}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_CHOLYUP, // upstate
0, // raise sound id
S_CHOLYDOWN, // downstate
S_CHOLYREADY, // readystate
0, // readysound
S_CHOLYATK_1, // atkstate
S_CHOLYATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Mage - Staff
GM_ANY, // Gamemode bits
{1, 1}, // type: mana1 | mana2
{15, 15}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_MSTAFFUP, // upstate
0, // raise sound id
S_MSTAFFDOWN, // downstate
S_MSTAFFREADY, // readystate
0, // readysound
S_MSTAFFATK_1, // atkstate
S_MSTAFFATK_1, // holdatkstate
S_NULL // flashstate
}
},
{
{ // Pig - Snout
GM_ANY, // Gamemode bits
{0, 0}, // type: mana1 | mana2
{0, 0}, // pershot: mana1 | mana2
true, // autofire when raised if fire held
S_SNOUTUP, // upstate
0, // raise sound id
S_SNOUTDOWN, // downstate
S_SNOUTREADY, // readystate
0, // readysound
S_SNOUTATK1, // atkstate
S_SNOUTATK1, // holdatkstate
S_NULL // flashstate
}
}
}
};
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
/*
* Offset in state->misc1/2.
*/
void P_SetPSpriteOffset(pspdef_t * psp, player_t *player, state_t * state)
{
ddpsprite_t *ddpsp = player->plr->psprites;
// Clear the Offset flag by default.
//ddpsp->flags &= ~DDPSPF_OFFSET;
if(state->misc[0])
{
// Set coordinates.
psp->sx = state->misc[0] << FRACBITS;
//ddpsp->flags |= DDPSPF_OFFSET;
ddpsp->offx = state->misc[0];
}
if(state->misc[1])
{
psp->sy = state->misc[1] << FRACBITS;
//ddpsp->flags |= DDPSPF_OFFSET;
ddpsp->offy = state->misc[1];
}
}
void P_SetPsprite(player_t *player, int position, statenum_t stnum)
{
pspdef_t *psp;
state_t *state;
psp = &player->psprites[position];
do
{
if(!stnum)
{ // Object removed itself.
psp->state = NULL;
break;
}
state = &states[stnum];
psp->state = state;
psp->tics = state->tics; // could be 0
P_SetPSpriteOffset(psp, player, state);
if(state->action)
{ // Call action routine.
state->action(player, psp);
if(!psp->state)
{
break;
}
}
stnum = psp->state->nextstate;
} while(!psp->tics); // An initial state of 0 could cycle through.
}
/*
* Identical to P_SetPsprite, without calling the action function
*/
void P_SetPspriteNF(player_t *player, int position, statenum_t stnum)
{
pspdef_t *psp;
state_t *state;
psp = &player->psprites[position];
do
{
if(!stnum)
{ // Object removed itself.
psp->state = NULL;
break;
}
state = &states[stnum];
psp->state = state;
psp->tics = state->tics; // could be 0
P_SetPSpriteOffset(psp, player, state);
stnum = psp->state->nextstate;
} while(!psp->tics); // An initial state of 0 could cycle through.
}
void P_ActivateMorphWeapon(player_t *player)
{
player->pendingweapon = WP_NOCHANGE;
player->psprites[ps_weapon].sy = WEAPONTOP;
player->readyweapon = WP_FIRST; // Snout is the first weapon
player->update |= PSF_WEAPONS;
P_SetPsprite(player, ps_weapon, S_SNOUTREADY);
}
void P_PostMorphWeapon(player_t *player, weapontype_t weapon)
{
player->pendingweapon = WP_NOCHANGE;
player->readyweapon = weapon;
player->psprites[ps_weapon].sy = WEAPONBOTTOM;
player->update |= PSF_WEAPONS;
P_SetPsprite(player, ps_weapon, weaponinfo[weapon][player->class].mode[0].upstate);
}
/*
* Starts bringing the pending weapon up from the bottom of the screen.
*/
void P_BringUpWeapon(player_t *player)
{
statenum_t newState;
weaponmodeinfo_t *wminfo;
wminfo = WEAPON_INFO(player->pendingweapon, player->class, 0);
newState = wminfo->upstate;
if(player->class == PCLASS_FIGHTER && player->pendingweapon == WP_SECOND &&
player->ammo[MANA_1])
{
newState = S_FAXEUP_G;
}
if(player->pendingweapon == WP_NOCHANGE)
player->pendingweapon = player->readyweapon;
if(wminfo->raisesound)
S_StartSound(wminfo->raisesound, player->plr->mo);
player->pendingweapon = WP_NOCHANGE;
player->psprites[ps_weapon].sy = WEAPONBOTTOM;
P_SetPsprite(player, ps_weapon, newState);
}
/**
* Checks if there is enough ammo to shoot with the current weapon. If not,
* a weapon change event is dispatched (which may or may not do anything
* depending on the player's config).
*
* @returns <code>true</code> if there is enough mana to shoot.
*/
boolean P_CheckAmmo(player_t *player)
{
ammotype_t i;
int count;
boolean good;
// KLUDGE: Work around the multiple firing modes problems.
// We need to split the weapon firing routines and implement them as
// new fire modes.
if(player->class == PCLASS_FIGHTER || player->readyweapon == WP_FOURTH)
return true;
// < KLUDGE
// Check we have enough of ALL ammo types used by this weapon.
good = true;
for(i=0; i < NUMAMMO && good; ++i)
{
if(!weaponinfo[player->readyweapon][player->class].mode[0].ammotype[i])
continue; // Weapon does not take this type of ammo.
// Minimal amount for one shot varies.
count = weaponinfo[player->readyweapon][player->class].mode[0].pershot[i];
// Return if current ammunition sufficient.
if(player->ammo[i] < count)
{
good = false;
}
}
if(good)
return true;
// Out of ammo, pick a weapon to change to.
P_MaybeChangeWeapon(player, WP_NOCHANGE, AM_NOAMMO, false);
// Now set appropriate weapon overlay.
P_SetPsprite(player, ps_weapon,
weaponinfo[player->readyweapon][player->class].mode[0].downstate);
return false;
}
void P_FireWeapon(player_t *player)
{
statenum_t attackState;
if(!P_CheckAmmo(player))
return;
// Psprite state.
P_SetMobjState(player->plr->mo, PCLASS_INFO(player->class)->attackstate);
if(player->class == PCLASS_FIGHTER && player->readyweapon == WP_SECOND &&
player->ammo[MANA_1] > 0)
{ // Glowing axe
attackState = S_FAXEATK_G1;
}
else
{
if(player->refire)
attackState =
weaponinfo[player->readyweapon][player->class].mode[0].holdatkstate;
else
attackState =
weaponinfo[player->readyweapon][player->class].mode[0].atkstate;
}
P_SetPsprite(player, ps_weapon, attackState);
P_NoiseAlert(player->plr->mo, player->plr->mo);
player->update |= PSF_AMMO;
// Psprite state.
player->plr->psprites[0].state = DDPSP_FIRE;
}
/*
* The player died, so put the weapon away.
*/
void P_DropWeapon(player_t *player)
{
P_SetPsprite(player, ps_weapon,
weaponinfo[player->readyweapon][player->class].mode[0].downstate);
}
/*
* The player can fire the weapon or change to another weapon at this time.
*/
void C_DECL A_WeaponReady(player_t *player, pspdef_t * psp)
{
weaponmodeinfo_t *wminfo;
ddpsprite_t *ddpsp;
// Change player from attack state
if(player->plr->mo->state >= &states[PCLASS_INFO(player->class)->attackstate] &&
player->plr->mo->state <= &states[PCLASS_INFO(player->class)->attackendstate])
{
P_SetMobjState(player->plr->mo, PCLASS_INFO(player->class)->normalstate);
}
if(player->readyweapon != WP_NOCHANGE)
{
wminfo = WEAPON_INFO(player->readyweapon, player->class, 0);
// A weaponready sound?
if(psp->state == &states[wminfo->readystate] && wminfo->readysound)
S_StartSound(wminfo->readysound, player->plr->mo);
// check for change
// if player is dead, put the weapon away
if(player->pendingweapon != WP_NOCHANGE || !player->health)
{ // (pending weapon should allready be validated)
P_SetPsprite(player, ps_weapon, wminfo->downstate);
return;
}
}
// check for autofire
if(player->cmd.attack)
{
wminfo = WEAPON_INFO(player->readyweapon, player->class, 0);
if(!player->attackdown || wminfo->autofire)
{
player->attackdown = true;
P_FireWeapon(player);
return;
}
}
else
player->attackdown = false;
ddpsp = player->plr->psprites;
if(!player->morphTics)
{
// Bob the weapon based on movement speed.
psp->sx = G_GetInteger(DD_PSPRITE_BOB_X);
psp->sy = G_GetInteger(DD_PSPRITE_BOB_Y);
ddpsp->offx = ddpsp->offy = 0;
}
// Psprite state.
ddpsp->state = DDPSP_BOBBING;
}
/*
* The player can re fire the weapon without lowering it entirely.
*/
void C_DECL A_ReFire(player_t *player, pspdef_t * psp)
{
if(player->cmd.attack &&
player->pendingweapon == WP_NOCHANGE &&
player->health)
{
player->refire++;
P_FireWeapon(player);
}
else
{
player->refire = 0;
P_CheckAmmo(player);
}
}
void C_DECL A_Lower(player_t *player, pspdef_t * psp)
{
// Psprite state.
player->plr->psprites[0].state = DDPSP_DOWN;
if(player->morphTics)
{
psp->sy = WEAPONBOTTOM;
}
else
{
psp->sy += LOWERSPEED;
}
if(psp->sy < WEAPONBOTTOM)
{ // Not lowered all the way yet
return;
}
if(player->playerstate == PST_DEAD)
{ // Player is dead, so don't bring up a pending weapon
psp->sy = WEAPONBOTTOM;
return;
}
if(!player->health)
{ // Player is dead, so keep the weapon off screen
P_SetPsprite(player, ps_weapon, S_NULL);
return;
}
player->readyweapon = player->pendingweapon;
player->update |= PSF_WEAPONS;
P_BringUpWeapon(player);
}
void C_DECL A_Raise(player_t *player, pspdef_t * psp)
{
// Psprite state.
player->plr->psprites[0].state = DDPSP_UP;
psp->sy -= RAISESPEED;
if(psp->sy > WEAPONTOP)
{ // Not raised all the way yet
return;
}
psp->sy = WEAPONTOP;
if(player->class == PCLASS_FIGHTER && player->readyweapon == WP_SECOND &&
player->ammo[MANA_1])
{
P_SetPsprite(player, ps_weapon, S_FAXEREADY_G);
}
else
{
P_SetPsprite(player, ps_weapon,
weaponinfo[player->readyweapon][player->class].mode[0].
readystate);
}
}
void AdjustPlayerAngle(mobj_t *pmo)
{
angle_t angle;
int difference;
angle = R_PointToAngle2(pmo->pos[VX], pmo->pos[VY],
linetarget->pos[VX], linetarget->pos[VY]);
difference = (int) angle - (int) pmo->angle;
if(abs(difference) > MAX_ANGLE_ADJUST)
{
pmo->angle += difference > 0 ? MAX_ANGLE_ADJUST : -MAX_ANGLE_ADJUST;
}
else
{
pmo->angle = angle;
}
pmo->player->plr->flags |= DDPF_FIXANGLES;
}
void C_DECL A_SnoutAttack(player_t *player, pspdef_t * psp)
{
angle_t angle;
int damage;
int slope;
damage = 3 + (P_Random() & 3);
angle = player->plr->mo->angle;
slope = P_AimLineAttack(player->plr->mo, angle, MELEERANGE);
PuffType = MT_SNOUTPUFF;
PuffSpawned = NULL;
P_LineAttack(player->plr->mo, angle, MELEERANGE, slope, damage);
S_StartSound(SFX_PIG_ACTIVE1 + (P_Random() & 1), player->plr->mo);
if(linetarget)
{
AdjustPlayerAngle(player->plr->mo);
if(PuffSpawned)
{ // Bit something
S_StartSound(SFX_PIG_ATTACK, player->plr->mo);
}
}
}
void C_DECL A_FHammerAttack(player_t *player, pspdef_t * psp)
{
angle_t angle;
mobj_t *pmo = player->plr->mo;
int damage;
fixed_t power;
int slope;
int i;
damage = 60 + (P_Random() & 63);
power = 10 * FRACUNIT;
PuffType = MT_HAMMERPUFF;
for(i = 0; i < 16; i++)
{
angle = pmo->angle + i * (ANG45 / 32);
slope = P_AimLineAttack(pmo, angle, HAMMER_RANGE);
if(linetarget)
{
P_LineAttack(pmo, angle, HAMMER_RANGE, slope, damage);
AdjustPlayerAngle(pmo);
if(linetarget->flags & MF_COUNTKILL || linetarget->player)
{
P_ThrustMobj(linetarget, angle, power);
}
pmo->special1 = false; // Don't throw a hammer
goto hammerdone;
}
angle = pmo->angle - i * (ANG45 / 32);
slope = P_AimLineAttack(pmo, angle, HAMMER_RANGE);
if(linetarget)
{
P_LineAttack(pmo, angle, HAMMER_RANGE, slope, damage);
AdjustPlayerAngle(pmo);
if(linetarget->flags & MF_COUNTKILL || linetarget->player)
{
P_ThrustMobj(linetarget, angle, power);
}
pmo->special1 = false; // Don't throw a hammer
goto hammerdone;
}
}
// didn't find any targets in meleerange, so set to throw out a hammer
PuffSpawned = NULL;
angle = pmo->angle;
slope = P_AimLineAttack(pmo, angle, HAMMER_RANGE);
P_LineAttack(pmo, angle, HAMMER_RANGE, slope, damage);
if(PuffSpawned)
{
pmo->special1 = false;
}
else
{
pmo->special1 = true;
}
hammerdone:
if(player->ammo[MANA_2] <
weaponinfo[player->readyweapon][player->class].mode[0].pershot[MANA_2])
{ // Don't spawn a hammer if the player doesn't have enough mana
pmo->special1 = false;
}
return;
}
void C_DECL A_FHammerThrow(player_t *player, pspdef_t * psp)
{
mobj_t *mo;
if(!player->plr->mo->special1)
return;
P_ShotAmmo(player);
mo = P_SpawnPlayerMissile(player->plr->mo, MT_HAMMER_MISSILE);
if(mo)
mo->special1 = 0;
}
void C_DECL A_FSwordAttack(player_t *player, pspdef_t * psp)
{
mobj_t *pmo;
P_ShotAmmo(player);
pmo = player->plr->mo;
P_SPMAngleXYZ(pmo, pmo->pos[VX], pmo->pos[VY], pmo->pos[VZ] - 10 * FRACUNIT,
MT_FSWORD_MISSILE, pmo->angle + ANG45 / 4);
P_SPMAngleXYZ(pmo, pmo->pos[VX], pmo->pos[VY], pmo->pos[VZ] - 5 * FRACUNIT,
MT_FSWORD_MISSILE, pmo->angle + ANG45 / 8);
P_SPMAngleXYZ(pmo, pmo->pos[VX], pmo->pos[VY], pmo->pos[VZ],
MT_FSWORD_MISSILE, pmo->angle);
P_SPMAngleXYZ(pmo, pmo->pos[VX], pmo->pos[VY], pmo->pos[VZ] + 5 * FRACUNIT,
MT_FSWORD_MISSILE, pmo->angle - ANG45 / 8);
P_SPMAngleXYZ(pmo, pmo->pos[VX], pmo->pos[VY], pmo->pos[VZ] + 10 * FRACUNIT,
MT_FSWORD_MISSILE, pmo->angle - ANG45 / 4);
S_StartSound(SFX_FIGHTER_SWORD_FIRE, pmo);
}
void C_DECL A_FSwordAttack2(mobj_t *actor)
{
angle_t angle = actor->angle;
P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE, angle + ANG45 / 4, 0);
P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE, angle + ANG45 / 8, 0);
P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE, angle, 0);
P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE, angle - ANG45 / 8, 0);
P_SpawnMissileAngle(actor, MT_FSWORD_MISSILE, angle - ANG45 / 4, 0);
S_StartSound(SFX_FIGHTER_SWORD_FIRE, actor);
}
void C_DECL A_FSwordFlames(mobj_t *actor)
{
int i;
for(i = 1 + (P_Random() & 3); i; i--)
{
P_SpawnMobj(actor->pos[VX] + ((P_Random() - 128) << 12),
actor->pos[VY] + ((P_Random() - 128) << 12),
actor->pos[VZ] + ((P_Random() - 128) << 11), MT_FSWORD_FLAME);
}
}
void C_DECL A_MWandAttack(player_t *player, pspdef_t * psp)
{
mobj_t *mo;
mo = P_SpawnPlayerMissile(player->plr->mo, MT_MWAND_MISSILE);
if(mo)
{
mo->thinker.function = P_BlasterMobjThinker;
}
S_StartSound(SFX_MAGE_WAND_FIRE, player->plr->mo);
}
void C_DECL A_LightningReady(player_t *player, pspdef_t * psp)
{
A_WeaponReady(player, psp);
if(P_Random() < 160)
{
S_StartSound(SFX_MAGE_LIGHTNING_READY, player->plr->mo);
}
}
void C_DECL A_LightningClip(mobj_t *actor)
{
mobj_t *cMo;
mobj_t *target = 0;
int zigZag;
if(actor->type == MT_LIGHTNING_FLOOR)
{
actor->pos[VZ] = actor->floorz;
target = actor->lastenemy->tracer;
}
else if(actor->type == MT_LIGHTNING_CEILING)
{
actor->pos[VZ] = actor->ceilingz - actor->height;
target = actor->tracer;
}
if(actor->type == MT_LIGHTNING_FLOOR)
{ // floor lightning zig-zags, and forces the ceiling lightning to mimic
cMo = actor->lastenemy;
zigZag = P_Random();
if((zigZag > 128 && actor->special1 < 2) || actor->special1 < -2)
{
P_ThrustMobj(actor, actor->angle + ANG90, ZAGSPEED);
if(cMo)
{
P_ThrustMobj(cMo, actor->angle + ANG90, ZAGSPEED);
}
actor->special1++;
}
else
{
P_ThrustMobj(actor, actor->angle - ANG90, ZAGSPEED);
if(cMo)
{
P_ThrustMobj(cMo, cMo->angle - ANG90, ZAGSPEED);
}
actor->special1--;
}
}
if(target)
{
if(target->health <= 0)
{
P_ExplodeMissile(actor);
}
else
{
actor->angle = R_PointToAngle2(actor->pos[VX], actor->pos[VY],
target->pos[VX], target->pos[VY]);
actor->momx = 0;
actor->momy = 0;
P_ThrustMobj(actor, actor->angle, actor->info->speed >> 1);
}
}
}
void C_DECL A_LightningZap(mobj_t *actor)
{
mobj_t *mo;
fixed_t deltaZ;
A_LightningClip(actor);
actor->health -= 8;
if(actor->health <= 0)
{
P_SetMobjState(actor, actor->info->deathstate);
return;
}
if(actor->type == MT_LIGHTNING_FLOOR)
{
deltaZ = 10 * FRACUNIT;
}
else
{
deltaZ = -10 * FRACUNIT;
}
mo = P_SpawnMobj(actor->pos[VX] + ((P_Random() - 128) * actor->radius / 256),
actor->pos[VY] + ((P_Random() - 128) * actor->radius / 256),
actor->pos[VZ] + deltaZ, MT_LIGHTNING_ZAP);
if(mo)
{
mo->lastenemy = actor;
mo->momx = actor->momx;
mo->momy = actor->momy;
mo->target = actor->target;
if(actor->type == MT_LIGHTNING_FLOOR)
{
mo->momz = 20 * FRACUNIT;
}
else
{
mo->momz = -20 * FRACUNIT;
}