/
p_pspr.c
1557 lines (1297 loc) · 39.2 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 p_pspr.c Weapon sprite animation, weapon objects.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 1999 Activision
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifdef MSVC
// Sumtin' 'ere messes with poor ol' MSVC's head...
# pragma optimize("g", off)
#endif
#include "common.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "d_net.h"
#include "d_netcl.h"
#include "p_inventory.h"
#include "p_map.h"
#include "p_terraintype.h"
#include "p_tick.h"
#include "player.h"
#define LOWERSPEED (6)
#define RAISESPEED (6)
#define WEAPONBOTTOM (128)
#define WEAPONTOP (32)
float bulletSlope;
void R_GetWeaponBob(int player, float* x, float* y)
{
if(x)
{
*x = 1 + (cfg.common.bobWeapon * players[player].bob) *
FIX2FLT(finecosine[(128 * mapTime) & FINEMASK]);
}
if(y)
{
*y = 32 + (cfg.common.bobWeapon * players[player].bob) *
FIX2FLT(finesine[(128 * mapTime) & FINEMASK & (FINEANGLES / 2 - 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.
if(state->misc[0])
{ // Set coordinates.
psp->pos[VX] = (float) state->misc[0];
psp->pos[VY] = (float) state->misc[1];
}
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.
}
void P_ActivateMorphWeapon(player_t *player)
{
player->pendingWeapon = WT_NOCHANGE;
player->readyWeapon = WT_FIRST;
player->update |= PSF_PENDING_WEAPON | PSF_READY_WEAPON;
player->pSprites[ps_weapon].pos[VY] = WEAPONTOP;
P_SetPsprite(player, ps_weapon, S_BEAKREADY);
}
void P_PostMorphWeapon(player_t *player, weapontype_t weapon)
{
player->pendingWeapon = WT_NOCHANGE;
player->readyWeapon = weapon;
player->update |= PSF_PENDING_WEAPON | PSF_READY_WEAPON;
player->pSprites[ps_weapon].pos[VY] = WEAPONBOTTOM;
P_SetPsprite(player, ps_weapon, weaponInfo[weapon][player->class_].mode[0].states[WSN_UP]);
}
/**
* Starts bringing the pending weapon up from the bottom of the screen.
*/
void P_BringUpWeapon(struct player_s* player)
{
weapontype_t const oldPendingWeapon = player->pendingWeapon;
weaponmodeinfo_t* wminfo = NULL;
weapontype_t raiseWeapon;
if(!player) return;
if(player->plr->flags & DDPF_UNDEFINED_WEAPON)
{
// We'll do this when the server informs us about the client's current weapon.
return;
}
raiseWeapon = player->pendingWeapon;
if(raiseWeapon == WT_NOCHANGE)
raiseWeapon = player->readyWeapon;
player->pendingWeapon = WT_NOCHANGE;
player->pSprites[ps_weapon].pos[VY] = WEAPONBOTTOM;
if(!VALID_WEAPONTYPE(raiseWeapon))
{
return;
}
wminfo = WEAPON_INFO(raiseWeapon, player->class_, (player->powers[PT_WEAPONLEVEL2]? 1:0));
App_Log(DE2_MAP_XVERBOSE, "P_BringUpWeapon: Player %i, pending weapon was %i, weapon pspr to %i",
(int)(player - players), oldPendingWeapon, wminfo->states[WSN_UP]);
if(wminfo->raiseSound)
S_StartSoundEx(wminfo->raiseSound, player->plr->mo);
P_SetPsprite(player, ps_weapon, wminfo->states[WSN_UP]);
}
void P_FireWeapon(player_t *player)
{
statenum_t attackState;
int lvl = (player->powers[PT_WEAPONLEVEL2]? 1 : 0);
App_Log(DE2_DEV_MAP_XVERBOSE, "P_FireWeapon: player %i", (int)(player - players));
if(!P_CheckAmmo(player))
return;
NetCl_PlayerActionRequest(player, GPA_FIRE, player->refire);
P_MobjChangeState(player->plr->mo, PCLASS_INFO(player->class_)->attackState);
App_Log(DE2_DEV_MAP_XVERBOSE, "P_FireWeapon: Setting player %i to attack state",
(int)(player - players));
if(player->refire)
attackState = weaponInfo[player->readyWeapon][player->class_].mode[lvl].states[WSN_ATTACK_HOLD];
else
attackState = weaponInfo[player->readyWeapon][player->class_].mode[lvl].states[WSN_ATTACK];
P_SetPsprite(player, ps_weapon, attackState);
P_NoiseAlert(player->plr->mo, player->plr->mo);
if(player->readyWeapon == WT_EIGHTH && !player->refire)
{
// Play the sound for the initial gauntlet attack
S_StartSoundEx(SFX_GNTUSE, 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)
{
int level;
if(player->powers[PT_WEAPONLEVEL2])
level = 1;
else
level = 0;
P_SetPsprite(player, ps_weapon,
weaponInfo[player->readyWeapon][player->class_].mode[level].states[WSN_DOWN]);
}
/**
* 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[S_PLAY_ATK1] ||
player->plr->mo->state == &STATES[S_PLAY_ATK2])
{
P_MobjChangeState(player->plr->mo, S_PLAY);
}
if(player->readyWeapon != WT_NOCHANGE)
{
wminfo = WEAPON_INFO(player->readyWeapon, player->class_, (player->powers[PT_WEAPONLEVEL2]?1:0));
// A weaponready sound?
if(psp->state == &STATES[wminfo->states[WSN_READY]] && wminfo->readySound)
#if __JHERETIC__
if(P_Random() < 128)
#endif
S_StartSoundEx(wminfo->readySound, player->plr->mo);
// Check for change if player is dead, put the weapon away.
if(player->pendingWeapon != WT_NOCHANGE || !player->health)
{ // (pending weapon should allready be validated)
P_SetPsprite(player, ps_weapon, wminfo->states[WSN_DOWN]);
return;
}
}
// Check for autofire.
if(player->brain.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.
R_GetWeaponBob(player - players, &psp->pos[0], &psp->pos[1]);
ddpsp->offset[0] = ddpsp->offset[1] = 0;
}
// Psprite state.
ddpsp->state = DDPSP_BOBBING;
}
void P_UpdateBeak(player_t *player, pspdef_t *psp)
{
psp->pos[VY] = WEAPONTOP + FIX2FLT(player->chickenPeck << (FRACBITS - 1));
}
void C_DECL A_BeakReady(player_t *player, pspdef_t *psp)
{
if(player->brain.attack)
{
// Chicken beak attack.
player->attackDown = true;
NetCl_PlayerActionRequest(player, GPA_FIRE, 0);
P_MobjChangeState(player->plr->mo, S_CHICPLAY_ATK1);
if(player->powers[PT_WEAPONLEVEL2])
{
P_SetPsprite(player, ps_weapon, S_BEAKATK2_1);
}
else
{
P_SetPsprite(player, ps_weapon, S_BEAKATK1_1);
}
P_NoiseAlert(player->plr->mo, player->plr->mo);
}
else
{
if(player->plr->mo->state == &STATES[S_CHICPLAY_ATK1])
{ // Take out of attack state.
P_MobjChangeState(player->plr->mo, S_CHICPLAY);
}
player->attackDown = false;
}
}
/**
* The player can re fire the weapon without lowering it entirely.
*/
void C_DECL A_ReFire(player_t *player, pspdef_t *psp)
{
if((player->brain.attack) &&
player->pendingWeapon == WT_NOCHANGE && player->health)
{
player->refire++;
P_FireWeapon(player);
}
else
{
player->refire = 0;
P_CheckAmmo(player);
}
}
/**
* Lowers current weapon, and changes weapon at bottom.
*/
void C_DECL A_Lower(player_t *player, pspdef_t *psp)
{
if(player->morphTics)
psp->pos[VY] = WEAPONBOTTOM;
else
psp->pos[VY] += LOWERSPEED;
// Psprite state.
player->plr->pSprites[0].state = DDPSP_DOWN;
// Should we disable the lowering?
if(!cfg.bobWeaponLower ||
((player->powers[PT_WEAPONLEVEL2] &&
weaponInfo[player->readyWeapon][player->class_].mode[1].staticSwitch) ||
weaponInfo[player->readyWeapon][player->class_].mode[0].staticSwitch))
{
DD_SetInteger(DD_WEAPON_OFFSET_SCALE_Y, 0);
}
// Is already down.
if(psp->pos[VY] < WEAPONBOTTOM)
return;
// Player is dead.
if(player->playerState == PST_DEAD)
{
psp->pos[VY] = WEAPONBOTTOM;
// Don't bring weapon back up.
return;
}
// The old weapon has been lowered off the screen, so change the weapon
// and start raising it.
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_READY_WEAPON;
// Should we suddenly lower the weapon?
if(cfg.bobWeaponLower &&
((player->powers[PT_WEAPONLEVEL2] &&
!weaponInfo[player->readyWeapon][player->class_].mode[1].staticSwitch) ||
!weaponInfo[player->readyWeapon][player->class_].mode[0].staticSwitch))
{
DD_SetInteger(DD_WEAPON_OFFSET_SCALE_Y, 1000);
}
P_BringUpWeapon(player);
}
void C_DECL A_BeakRaise(player_t *player, pspdef_t *psp)
{
psp->pos[VY] = WEAPONTOP;
P_SetPsprite(player, ps_weapon,
weaponInfo[player->readyWeapon][player->class_].mode[0].states[WSN_READY]);
}
void C_DECL A_Raise(player_t *player, pspdef_t *psp)
{
statenum_t newstate;
// Psprite state.
player->plr->pSprites[0].state = DDPSP_UP;
// Should we disable the lowering?
if(!cfg.bobWeaponLower ||
((player->powers[PT_WEAPONLEVEL2] &&
weaponInfo[player->readyWeapon][player->class_].mode[1].staticSwitch) ||
weaponInfo[player->readyWeapon][player->class_].mode[0].staticSwitch))
{
DD_SetInteger(DD_WEAPON_OFFSET_SCALE_Y, 0);
}
psp->pos[VY] -= RAISESPEED;
if(psp->pos[VY] > WEAPONTOP)
return;
// Enable the pspr Y offset once again.
DD_SetInteger(DD_WEAPON_OFFSET_SCALE_Y, 1000);
psp->pos[VY] = WEAPONTOP;
// The weapon has been raised all the way,
// so change to the ready state.
if(player->powers[PT_WEAPONLEVEL2])
newstate = weaponInfo[player->readyWeapon][player->class_].mode[1].states[WSN_READY];
else
newstate = weaponInfo[player->readyWeapon][player->class_].mode[0].states[WSN_READY];
P_SetPsprite(player, ps_weapon, newstate);
}
/**
* Sets a slope so a near miss is at aproximately the height of the
* intended target.
*/
void P_BulletSlope(mobj_t *mo)
{
angle_t an = mo->angle;
if(!cfg.common.noAutoAim) // Autoaiming enabled.
{
// See which target is to be aimed at.
bulletSlope = P_AimLineAttack(mo, an, 16 * 64);
if(!lineTarget)
{
// No target yet, look closer.
an += 1 << 26;
bulletSlope = P_AimLineAttack(mo, an, 16 * 64);
if(!lineTarget)
{
an -= 2 << 26;
bulletSlope = P_AimLineAttack(mo, an, 16 * 64);
}
}
if(lineTarget)
{ // Found a target, we're done.
return;
}
}
// Fall back to manual aiming by lookdir.
bulletSlope = tan(LOOKDIR2RAD(mo->dPlayer->lookDir)) / 1.2;
}
void C_DECL A_BeakAttackPL1(player_t *player, pspdef_t *psp)
{
angle_t angle;
int damage;
float slope;
P_ShotAmmo(player);
damage = 1 + (P_Random() & 3);
angle = player->plr->mo->angle;
slope = P_AimLineAttack(player->plr->mo, angle, MELEERANGE);
P_LineAttack(player->plr->mo, angle, MELEERANGE, slope, damage, MT_BEAKPUFF);
if(lineTarget)
{
player->plr->mo->angle = M_PointToAngle2(player->plr->mo->origin, lineTarget->origin);
}
S_StartSoundEx(SFX_CHICPK1 + (P_Random() % 3), player->plr->mo);
player->chickenPeck = 12;
psp->tics -= P_Random() & 7;
}
void C_DECL A_BeakAttackPL2(player_t *player, pspdef_t *psp)
{
angle_t angle;
int damage;
float slope;
P_ShotAmmo(player);
damage = HITDICE(4);
angle = player->plr->mo->angle;
slope = P_AimLineAttack(player->plr->mo, angle, MELEERANGE);
P_LineAttack(player->plr->mo, angle, MELEERANGE, slope, damage, MT_BEAKPUFF);
if(lineTarget)
{
player->plr->mo->angle = M_PointToAngle2(player->plr->mo->origin, lineTarget->origin);
}
S_StartSoundEx(SFX_CHICPK1 + (P_Random() % 3), player->plr->mo);
player->chickenPeck = 12;
psp->tics -= P_Random() & 3;
}
void C_DECL A_StaffAttackPL1(player_t *player, pspdef_t *psp)
{
angle_t angle;
int damage;
float slope;
P_ShotAmmo(player);
damage = 5 + (P_Random() & 15);
angle = player->plr->mo->angle;
angle += (P_Random() - P_Random()) << 18;
slope = P_AimLineAttack(player->plr->mo, angle, MELEERANGE);
P_LineAttack(player->plr->mo, angle, MELEERANGE, slope, damage, MT_STAFFPUFF);
if(lineTarget)
{
// Turn to face target.
player->plr->mo->angle = M_PointToAngle2(player->plr->mo->origin, lineTarget->origin);
}
}
void C_DECL A_StaffAttackPL2(player_t *player, pspdef_t *psp)
{
angle_t angle;
int damage;
float slope;
P_ShotAmmo(player);
damage = 18 + (P_Random() & 63);
angle = player->plr->mo->angle;
angle += (P_Random() - P_Random()) << 18;
slope = P_AimLineAttack(player->plr->mo, angle, MELEERANGE);
P_LineAttack(player->plr->mo, angle, MELEERANGE, slope, damage, MT_STAFFPUFF2);
if(lineTarget)
{
// Turn to face target.
player->plr->mo->angle = M_PointToAngle2(player->plr->mo->origin, lineTarget->origin);
}
}
void C_DECL A_FireBlasterPL1(player_t *player, pspdef_t *psp)
{
mobj_t *mo;
angle_t angle;
int damage;
mo = player->plr->mo;
S_StartSoundEx(SFX_GLDHIT, mo);
P_ShotAmmo(player);
P_BulletSlope(mo);
damage = HITDICE(4);
angle = mo->angle;
if(player->refire)
{
angle += (P_Random() - P_Random()) << 18;
}
P_LineAttack(mo, angle, MISSILERANGE, bulletSlope, damage, MT_BLASTERPUFF1);
S_StartSoundEx(SFX_BLSSHT, mo);
}
void C_DECL A_FireBlasterPL2(player_t *player, pspdef_t *psp)
{
P_ShotAmmo(player);
S_StartSoundEx(SFX_BLSSHT, player->plr->mo);
if(IS_CLIENT) return;
P_SpawnMissile(MT_BLASTERFX1, player->plr->mo, NULL, true);
}
void C_DECL A_FireGoldWandPL1(player_t *player, pspdef_t *psp)
{
mobj_t *mo;
angle_t angle;
int damage;
mo = player->plr->mo;
P_ShotAmmo(player);
S_StartSoundEx(SFX_GLDHIT, player->plr->mo);
if(IS_CLIENT) return;
P_BulletSlope(mo);
damage = 7 + (P_Random() & 7);
angle = mo->angle;
if(player->refire)
{
angle += (P_Random() - P_Random()) << 18;
}
P_LineAttack(mo, angle, MISSILERANGE, bulletSlope, damage, MT_GOLDWANDPUFF1);
}
void C_DECL A_FireGoldWandPL2(player_t *player, pspdef_t *psp)
{
int i;
mobj_t *mo;
angle_t angle;
int damage;
coord_t momZ;
mo = player->plr->mo;
P_ShotAmmo(player);
S_StartSoundEx(SFX_GLDHIT, player->plr->mo);
if(IS_CLIENT) return;
P_BulletSlope(mo);
momZ = MOBJINFO[MT_GOLDWANDFX2].speed * bulletSlope;
Vanilla_P_SpawnMissileAngle(mo, MT_GOLDWANDFX2, mo->angle - (ANG45 / 8), momZ);
Vanilla_P_SpawnMissileAngle(mo, MT_GOLDWANDFX2, mo->angle + (ANG45 / 8), momZ);
angle = mo->angle - (ANG45 / 8);
for(i = 0; i < 5; ++i)
{
damage = 1 + (P_Random() & 7);
P_LineAttack(mo, angle, MISSILERANGE, bulletSlope, damage, MT_GOLDWANDPUFF2);
angle += ((ANG45 / 8) * 2) / 4;
}
}
void C_DECL A_FireMacePL1B(player_t *player, pspdef_t *psp)
{
mobj_t *pmo, *ball;
uint an;
if(!P_CheckAmmo(player)) return;
P_ShotAmmo(player);
if(IS_CLIENT) return;
pmo = player->plr->mo;
if((ball = P_SpawnMobjXYZ(MT_MACEFX2, pmo->origin[VX], pmo->origin[VY],
pmo->origin[VZ] - pmo->floorClip + 28,
pmo->angle, 0)))
{
ball->mom[MZ] = 2 + FIX2FLT(((int) player->plr->lookDir) << (FRACBITS - 5));
ball->target = pmo;
ball->origin[VZ] += FIX2FLT(((int) player->plr->lookDir) << (FRACBITS - 4));
an = ball->angle >> ANGLETOFINESHIFT;
ball->mom[MX] = (pmo->mom[MX] / 2) +
ball->info->speed * FIX2FLT(finecosine[an]);
ball->mom[MY] = (pmo->mom[MY] / 2) +
ball->info->speed * FIX2FLT(finesine[an]);
P_CheckMissileSpawn(ball);
S_StartSound(SFX_LOBSHT, ball);
}
}
void C_DECL A_FireMacePL1(player_t* player, pspdef_t* psp)
{
mobj_t* ball;
if(P_Random() < 28)
{
A_FireMacePL1B(player, psp);
return;
}
if(!P_CheckAmmo(player)) return;
P_ShotAmmo(player);
psp->pos[VX] = ((P_Random() & 3) - 2);
psp->pos[VY] = WEAPONTOP + (P_Random() & 3);
if(IS_CLIENT) return;
ball = P_SpawnMissileAngle(MT_MACEFX1, player->plr->mo,
player->plr->mo->angle + (((P_Random() & 7) - 4) << 24),
-12345);
if(ball)
{
ball->special1 = 16; // Tics till dropoff.
}
}
void C_DECL A_MacePL1Check(mobj_t *ball)
{
uint an;
if(ball->special1 == 0)
{
return;
}
ball->special1 -= 4;
if(ball->special1 > 0)
{
return;
}
ball->special1 = 0;
ball->flags2 |= MF2_LOGRAV;
an = ball->angle >> ANGLETOFINESHIFT;
ball->mom[MX] = 7 * FIX2FLT(finecosine[an]);
ball->mom[MY] = 7 * FIX2FLT(finesine[an]);
ball->mom[MZ] /= 2;
}
void C_DECL A_MaceBallImpact(mobj_t* ball)
{
if(ball->origin[VZ] <= ball->floorZ && P_HitFloor(ball))
{
// Landed in some sort of liquid.
P_MobjRemove(ball, true);
return;
}
if(ball->special3 != MAGIC_JUNK && ball->origin[VZ] <= ball->floorZ &&
!FEQUAL(ball->mom[MZ], 0))
{
// Bounce.
ball->special3 = MAGIC_JUNK;
ball->mom[MZ] = FIX2FLT(FLT2FIX(ball->mom[MZ] * 192) >> 8);
ball->flags2 &= ~MF2_FLOORBOUNCE;
P_MobjChangeState(ball, P_GetState(ball->type, SN_SPAWN));
S_StartSound(SFX_BOUNCE, ball);
}
else
{
// Explode.
ball->flags |= MF_NOGRAVITY;
ball->flags2 &= ~MF2_LOGRAV;
S_StartSound(SFX_LOBHIT, ball);
}
}
void C_DECL A_MaceBallImpact2(mobj_t* ball)
{
if(ball->origin[VZ] <= ball->floorZ && P_HitFloor(ball))
{
// Landed in some sort of liquid.
P_MobjRemove(ball, true);
return;
}
if(!FEQUAL(ball->origin[VZ], ball->floorZ) || ball->mom[MZ] < 2)
{
// Explode
ball->mom[MX] = ball->mom[MY] = ball->mom[MZ] = 0;
ball->flags |= MF_NOGRAVITY;
ball->flags2 &= ~(MF2_LOGRAV | MF2_FLOORBOUNCE);
}
else
{
// Bounce
mobj_t* tiny;
unsigned int an;
ball->mom[MZ] = FIX2FLT(FLT2FIX(ball->mom[MZ] * 192) >> 8);
P_MobjChangeState(ball, P_GetState(ball->type, SN_SPAWN));
if((tiny = P_SpawnMobj(MT_MACEFX3, ball->origin, ball->angle + ANG90, 0)))
{
tiny->target = ball->target;
an = tiny->angle >> ANGLETOFINESHIFT;
tiny->mom[MX] = (ball->mom[MX] / 2) +
((ball->mom[MZ] - 1) * FIX2FLT(finecosine[an]));
tiny->mom[MY] = (ball->mom[MY] / 2) +
((ball->mom[MZ] - 1) * FIX2FLT(finesine[an]));
tiny->mom[MZ] = ball->mom[MZ];
P_CheckMissileSpawn(tiny);
}
if((tiny = P_SpawnMobj(MT_MACEFX3, ball->origin, ball->angle - ANG90, 0)))
{
tiny->target = ball->target;
an = tiny->angle >> ANGLETOFINESHIFT;
tiny->mom[MX] = (ball->mom[MX] / 2) +
((ball->mom[MZ] - 1) * FIX2FLT(finecosine[an]));
tiny->mom[MY] = (ball->mom[MY] / 2) +
((ball->mom[MZ] - 1) * FIX2FLT(finesine[an]));
tiny->mom[MZ] = ball->mom[MZ];
P_CheckMissileSpawn(tiny);
}
}
}
void C_DECL A_FireMacePL2(player_t *player, pspdef_t *psp)
{
mobj_t *mo;
P_ShotAmmo(player);
S_StartSoundEx(SFX_LOBSHT, player->plr->mo);
if(IS_CLIENT)
return;
mo = P_SpawnMissile(MT_MACEFX4, player->plr->mo, NULL, true);
if(mo)
{
mo->mom[MX] += player->plr->mo->mom[MX];
mo->mom[MY] += player->plr->mo->mom[MY];
mo->mom[MZ] =
2 + FIX2FLT(((int) player->plr->lookDir) << (FRACBITS - 5));
if(lineTarget)
mo->tracer = lineTarget;
}
}
void C_DECL A_DeathBallImpact(mobj_t* ball)
{
int i;
mobj_t* target;
angle_t angle;
dd_bool newAngle;
if(ball->origin[VZ] <= ball->floorZ && P_HitFloor(ball))
{
// Landed in some sort of liquid.
P_MobjRemove(ball, true);
return;
}
if(ball->origin[VZ] <= ball->floorZ && !FEQUAL(ball->mom[MZ], 0))
{
// Bounce.
newAngle = false;
target = ball->tracer;
angle = 0;
if(target)
{
if(!(target->flags & MF_SHOOTABLE))
{
// Target died.
ball->tracer = NULL;
}
else
{
// Seek.
angle = M_PointToAngle2(ball->origin, target->origin);
newAngle = true;
}
}
else
{
// Find new target.
for(i = 0; i < 16; ++i)
{
P_AimLineAttack(ball, angle, 10 * 64);
if(lineTarget && ball->target != lineTarget)
{
ball->tracer = lineTarget;
angle = M_PointToAngle2(ball->origin, lineTarget->origin);
newAngle = true;
break;
}
angle += ANGLE_45 / 2;
}
}
if(newAngle)
{
uint an = angle >> ANGLETOFINESHIFT;
ball->angle = angle;
ball->mom[MX] = ball->info->speed * FIX2FLT(finecosine[an]);
ball->mom[MY] = ball->info->speed * FIX2FLT(finesine[an]);
}
P_MobjChangeState(ball, P_GetState(ball->type, SN_SPAWN));
S_StartSound(SFX_PSTOP, ball);
}
else
{
// Explode.
ball->flags |= MF_NOGRAVITY;
ball->flags2 &= ~MF2_LOGRAV;
S_StartSound(SFX_PHOHIT, ball);
}
}
void C_DECL A_SpawnRippers(mobj_t* actor)
{
int i;
for(i = 0; i < 8; ++i)
{
angle_t angle = i * ANG45;
uint an;
mobj_t* ripper;
if((ripper = P_SpawnMobj(MT_RIPPER, actor->origin, angle, 0)))
{
ripper->target = actor->target;
an = angle >> ANGLETOFINESHIFT;
ripper->mom[MX] = ripper->info->speed * FIX2FLT(finecosine[an]);
ripper->mom[MY] = ripper->info->speed * FIX2FLT(finesine[an]);
P_CheckMissileSpawn(ripper);
}
}
}
void C_DECL A_FireCrossbowPL1(player_t* player, pspdef_t* psp)
{
mobj_t* pmo;
pmo = player->plr->mo;
P_ShotAmmo(player);
if(IS_CLIENT)
return;
P_SpawnMissile(MT_CRBOWFX1, pmo, NULL, true);
P_SpawnMissileAngle(MT_CRBOWFX3, pmo, pmo->angle - (ANG45 / 10), -12345);
P_SpawnMissileAngle(MT_CRBOWFX3, pmo, pmo->angle + (ANG45 / 10), -12345);
}
void C_DECL A_FireCrossbowPL2(player_t* player, pspdef_t* psp)
{
mobj_t* pmo;
pmo = player->plr->mo;
P_ShotAmmo(player);
if(IS_CLIENT)
return;
P_SpawnMissile(MT_CRBOWFX2, pmo, NULL, true);
P_SpawnMissileAngle(MT_CRBOWFX2, pmo, pmo->angle - (ANG45 / 10), -12345);
P_SpawnMissileAngle(MT_CRBOWFX2, pmo, pmo->angle + (ANG45 / 10), -12345);
P_SpawnMissileAngle(MT_CRBOWFX3, pmo, pmo->angle - (ANG45 / 5), -12345);
P_SpawnMissileAngle(MT_CRBOWFX3, pmo, pmo->angle + (ANG45 / 5), -12345);
}
void C_DECL A_BoltSpark(mobj_t* bolt)
{
mobj_t* spark;
if(IS_NETWORK_SERVER) return; // Would not be visible to anyone.
if(P_Random() > 50)
{
if((spark = P_SpawnMobj(MT_CRBOWFX4, bolt->origin, P_Random() << 24, 0)))
{
P_MobjUnlink(spark);
spark->origin[VX] += FIX2FLT((P_Random() - P_Random()) << 10);
spark->origin[VY] += FIX2FLT((P_Random() - P_Random()) << 10);
P_MobjLink(spark);
}
}
}
void C_DECL A_FireSkullRodPL1(player_t* player, pspdef_t* psp)
{
mobj_t* mo;
if(!P_CheckAmmo(player)) return;
P_ShotAmmo(player);
if(IS_CLIENT) return;
if((mo = P_SpawnMissile(MT_HORNRODFX1, player->plr->mo, NULL, true)))
{
// Randomize the first frame
if(mo && P_Random() > 128)
{
P_MobjChangeState(mo, S_HRODFX1_2);
}
}
}
/**
* The special2 field holds the player number that shot the rain missile.
* The special1 field is used as a counter for the sound looping.
*/
void C_DECL A_FireSkullRodPL2(player_t *player, pspdef_t *psp)
{
mobj_t *mo;
P_ShotAmmo(player);
if(IS_CLIENT) return;
if((mo = P_SpawnMissile(MT_HORNRODFX2, player->plr->mo, NULL, true)))
{
mo->special3 = 140;
}
// Use MissileMobj instead of the return value from
// P_SpawnMissile because we need to give info to the mobj
// even if it exploded immediately.
if(IS_NETGAME)
{
// Multi-player game.
missileMobj->special2 = P_GetPlayerNum(player);
}
else