/
p_pspr.cpp
1434 lines (1223 loc) · 36 KB
/
p_pspr.cpp
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
//-----------------------------------------------------------------------------
//
// Copyright 1993-1996 id Software
// Copyright 1994-1996 Raven Software
// Copyright 1998-1998 Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
// Copyright 1999-2016 Randy Heit
// Copyright 2002-2016 Christoph Oelckers
// Copyright 2016 Leonard2
//
// 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 3 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, see http://www.gnu.org/licenses/
//
//-----------------------------------------------------------------------------
//
// HEADER FILES ------------------------------------------------------------
#include <stdlib.h>
#include "doomdef.h"
#include "d_event.h"
#include "c_cvars.h"
#include "m_random.h"
#include "p_enemy.h"
#include "p_local.h"
#include "s_sound.h"
#include "doomstat.h"
#include "p_pspr.h"
#include "templates.h"
#include "g_level.h"
#include "d_player.h"
#include "serializer_doom.h"
#include "serialize_obj.h"
#include "v_text.h"
#include "cmdlib.h"
#include "g_levellocals.h"
#include "vm.h"
#include "sbar.h"
// MACROS ------------------------------------------------------------------
#define LOWERSPEED 6.
// TYPES -------------------------------------------------------------------
struct FGenericButtons
{
int ReadyFlag; // Flag passed to A_WeaponReady
int StateFlag; // Flag set in WeaponState
int ButtonFlag; // Button to press
ENamedName StateName; // Name of the button/state
};
enum EWRF_Options
{
WRF_NoBob = 1,
WRF_NoSwitch = 1 << 1,
WRF_NoPrimary = 1 << 2,
WRF_NoSecondary = 1 << 3,
WRF_NoFire = WRF_NoPrimary | WRF_NoSecondary,
WRF_AllowReload = 1 << 4,
WRF_AllowZoom = 1 << 5,
WRF_DisableSwitch = 1 << 6,
WRF_AllowUser1 = 1 << 7,
WRF_AllowUser2 = 1 << 8,
WRF_AllowUser3 = 1 << 9,
WRF_AllowUser4 = 1 << 10,
};
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// [SO] 1=Weapons states are all 1 tick
// 2=states with a function 1 tick, others 0 ticks.
CVAR(Int, sv_fastweapons, false, CVAR_SERVERINFO);
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static const FGenericButtons ButtonChecks[] =
{
{ WRF_AllowZoom, WF_WEAPONZOOMOK, BT_ZOOM, NAME_Zoom },
{ WRF_AllowReload, WF_WEAPONRELOADOK, BT_RELOAD, NAME_Reload },
{ WRF_AllowUser1, WF_USER1OK, BT_USER1, NAME_User1 },
{ WRF_AllowUser2, WF_USER2OK, BT_USER2, NAME_User2 },
{ WRF_AllowUser3, WF_USER3OK, BT_USER3, NAME_User3 },
{ WRF_AllowUser4, WF_USER4OK, BT_USER4, NAME_User4 },
};
// CODE --------------------------------------------------------------------
//------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------
IMPLEMENT_CLASS(DPSprite, false, true)
IMPLEMENT_POINTERS_START(DPSprite)
IMPLEMENT_POINTER(Caller)
IMPLEMENT_POINTER(Next)
IMPLEMENT_POINTERS_END
DEFINE_FIELD_NAMED(DPSprite, State, CurState) // deconflict with same named type
DEFINE_FIELD(DPSprite, Caller)
DEFINE_FIELD(DPSprite, Next)
DEFINE_FIELD(DPSprite, Owner)
DEFINE_FIELD(DPSprite, Sprite)
DEFINE_FIELD(DPSprite, Frame)
DEFINE_FIELD(DPSprite, Flags)
DEFINE_FIELD(DPSprite, ID)
DEFINE_FIELD(DPSprite, processPending)
DEFINE_FIELD(DPSprite, x)
DEFINE_FIELD(DPSprite, y)
DEFINE_FIELD(DPSprite, oldx)
DEFINE_FIELD(DPSprite, oldy)
DEFINE_FIELD(DPSprite, pivot)
DEFINE_FIELD(DPSprite, scale)
DEFINE_FIELD(DPSprite, rotation)
DEFINE_FIELD_NAMED(DPSprite, Coord[0], Coord0)
DEFINE_FIELD_NAMED(DPSprite, Coord[1], Coord1)
DEFINE_FIELD_NAMED(DPSprite, Coord[2], Coord2)
DEFINE_FIELD_NAMED(DPSprite, Coord[3], Coord3)
DEFINE_FIELD(DPSprite, firstTic)
DEFINE_FIELD(DPSprite, Tics)
DEFINE_FIELD(DPSprite, Translation)
DEFINE_FIELD(DPSprite, HAlign)
DEFINE_FIELD(DPSprite, VAlign)
DEFINE_FIELD(DPSprite, alpha)
DEFINE_FIELD(DPSprite, InterpolateTic)
DEFINE_FIELD_BIT(DPSprite, Flags, bAddWeapon, PSPF_ADDWEAPON)
DEFINE_FIELD_BIT(DPSprite, Flags, bAddBob, PSPF_ADDBOB)
DEFINE_FIELD_BIT(DPSprite, Flags, bPowDouble, PSPF_POWDOUBLE)
DEFINE_FIELD_BIT(DPSprite, Flags, bCVarFast, PSPF_CVARFAST)
DEFINE_FIELD_BIT(DPSprite, Flags, bFlip, PSPF_FLIP)
DEFINE_FIELD_BIT(DPSprite, Flags, bMirror, PSPF_MIRROR)
DEFINE_FIELD_BIT(DPSprite, Flags, bPlayerTranslated, PSPF_PLAYERTRANSLATED)
DEFINE_FIELD_BIT(DPSprite, Flags, bPivotPercent, PSPF_PIVOTPERCENT)
DEFINE_FIELD_BIT(DPSprite, Flags, bInterpolate, PSPF_INTERPOLATE)
//------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------
DPSprite::DPSprite(player_t *owner, AActor *caller, int id)
: HAlign(0),
VAlign(0),
x(.0), y(.0),
oldx(.0), oldy(.0),
InterpolateTic(false),
firstTic(true),
Tics(0),
Translation(0),
Flags(0),
Caller(caller),
Owner(owner),
State(nullptr),
Sprite(0),
Frame(0),
ID(id),
processPending(true)
{
rotation = 0.;
scale = {1.0, 1.0};
pivot = {0.0, 0.0};
for (int i = 0; i < 4; i++)
{
Coord[i] = DVector2(0, 0);
Prev.v[i] = Vert.v[i] = FVector2(0,0);
}
alpha = 1;
Renderstyle = STYLE_Normal;
DPSprite *prev = nullptr;
DPSprite *next = Owner->psprites;
while (next != nullptr && next->ID < ID)
{
prev = next;
next = next->Next;
}
Next = next;
GC::WriteBarrier(this, next);
if (prev == nullptr)
{
Owner->psprites = this;
GC::WriteBarrier(this);
}
else
{
prev->Next = this;
GC::WriteBarrier(prev, this);
}
if (Next && Next->ID == ID && ID != 0)
Next->Destroy(); // Replace it.
if (Caller->IsKindOf(NAME_Weapon) || Caller->IsKindOf(NAME_PlayerPawn))
Flags = (PSPF_ADDWEAPON|PSPF_ADDBOB|PSPF_POWDOUBLE|PSPF_CVARFAST|PSPF_PIVOTPERCENT);
}
//------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------
DPSprite *player_t::FindPSprite(int layer)
{
if (layer == 0)
return nullptr;
DPSprite *pspr = psprites;
while (pspr)
{
if (pspr->ID == layer)
break;
pspr = pspr->Next;
}
return pspr;
}
DEFINE_ACTION_FUNCTION(_PlayerInfo, FindPSprite) // the underscore is needed to get past the name mangler which removes the first clas name character to match the class representation (needs to be fixed in a later commit)
{
PARAM_SELF_STRUCT_PROLOGUE(player_t);
PARAM_INT(id);
ACTION_RETURN_OBJECT(self->FindPSprite((PSPLayers)id));
}
//------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------
void P_SetPsprite(player_t *player, PSPLayers id, FState *state, bool pending)
{
if (player == nullptr) return;
auto psp = player->GetPSprite(id);
if (psp) psp->SetState(state, pending);
}
DEFINE_ACTION_FUNCTION(_PlayerInfo, SetPSprite) // the underscore is needed to get past the name mangler which removes the first clas name character to match the class representation (needs to be fixed in a later commit)
{
PARAM_SELF_STRUCT_PROLOGUE(player_t);
PARAM_INT(id);
PARAM_POINTER(state, FState);
PARAM_BOOL(pending);
P_SetPsprite(self, (PSPLayers)id, state, pending);
return 0;
}
DPSprite *player_t::GetPSprite(PSPLayers layer)
{
AActor *oldcaller = nullptr;
AActor *newcaller = nullptr;
if (layer >= PSP_TARGETCENTER)
{
if (mo != nullptr)
{
newcaller = mo->FindInventory(NAME_PowerTargeter, true);
}
}
else if (layer == PSP_STRIFEHANDS)
{
newcaller = mo;
}
else
{
newcaller = ReadyWeapon;
}
if (newcaller == nullptr) return nullptr; // Error case was not handled properly. This function cannot give a guarantee to always succeed!
DPSprite *pspr = FindPSprite(layer);
if (pspr == nullptr)
{
pspr = Create<DPSprite>(this, newcaller, layer);
}
else
{
oldcaller = pspr->Caller;
}
// Always update the caller here in case we switched weapon
// or if the layer was being used by something else before.
pspr->Caller = newcaller;
if (newcaller != oldcaller)
{ // Only reset stuff if this layer was created now or if it was being used before.
if (layer >= PSP_TARGETCENTER)
{ // The targeter layers were affected by those.
pspr->Flags = (PSPF_CVARFAST|PSPF_POWDOUBLE);
}
else
{
pspr->Flags = (PSPF_ADDWEAPON|PSPF_ADDBOB|PSPF_CVARFAST|PSPF_POWDOUBLE|PSPF_PIVOTPERCENT);
}
if (layer == PSP_STRIFEHANDS)
{
// Some of the old hacks rely on this layer coming from the FireHands state.
// This is the ONLY time a psprite's state is actually null.
pspr->State = nullptr;
pspr->y = WEAPONTOP;
}
pspr->firstTic = true;
}
return pspr;
}
DEFINE_ACTION_FUNCTION(_PlayerInfo, GetPSprite) // the underscore is needed to get past the name mangler which removes the first clas name character to match the class representation (needs to be fixed in a later commit)
{
PARAM_SELF_STRUCT_PROLOGUE(player_t);
PARAM_INT(id);
ACTION_RETURN_OBJECT(self->GetPSprite((PSPLayers)id));
}
std::pair<FRenderStyle, float> DPSprite::GetRenderStyle(FRenderStyle ownerstyle, double owneralpha)
{
FRenderStyle returnstyle, mystyle;
double returnalpha;
ownerstyle.CheckFuzz();
mystyle = Renderstyle;
mystyle.CheckFuzz();
if (Flags & PSPF_RENDERSTYLE)
{
if (Flags & PSPF_FORCESTYLE)
{
returnstyle = mystyle;
}
else if (ownerstyle.BlendOp != STYLEOP_Add)
{
// all styles that do more than simple blending need to be fully preserved.
returnstyle = ownerstyle;
}
else
{
returnstyle = mystyle;
if (ownerstyle.DestAlpha == STYLEALPHA_One)
{
// If the owner is additive and the overlay translucent, force additive result.
returnstyle.DestAlpha = STYLEALPHA_One;
}
if (ownerstyle.Flags & (STYLEF_ColorIsFixed|STYLEF_RedIsAlpha))
{
// If the owner's style is a stencil type, this must be preserved.
returnstyle.Flags = ownerstyle.Flags;
}
}
}
else
{
returnstyle = ownerstyle;
}
if ((Flags & PSPF_FORCEALPHA) && returnstyle.BlendOp != STYLEOP_Fuzz && returnstyle.BlendOp != STYLEOP_Shadow)
{
// ALWAYS take priority if asked for, except fuzz. Fuzz does absolutely nothing
// no matter what way it's changed.
returnalpha = alpha;
returnstyle.Flags &= ~(STYLEF_Alpha1 | STYLEF_TransSoulsAlpha);
}
else if (Flags & PSPF_ALPHA)
{
// Set the alpha based on if using the overlay's own or not. Also adjust
// and override the alpha if not forced.
if (returnstyle.BlendOp != STYLEOP_Add)
{
returnalpha = owneralpha;
}
else
{
returnalpha = owneralpha * alpha;
}
}
else
{
returnalpha = owneralpha;
}
// Should normal renderstyle come out on top at the end and we desire alpha,
// switch it to translucent. Normal never applies any sort of alpha.
if (returnstyle.BlendOp == STYLEOP_Add && returnstyle.SrcAlpha == STYLEALPHA_One && returnstyle.DestAlpha == STYLEALPHA_Zero && returnalpha < 1.)
{
returnstyle = LegacyRenderStyles[STYLE_Translucent];
returnalpha = owneralpha * alpha;
}
return{ returnstyle, clamp<float>(float(returnalpha), 0.f, 1.f) };
}
//---------------------------------------------------------------------------
//
// PROC P_NewPspriteTick
//
//---------------------------------------------------------------------------
void DPSprite::NewTick()
{
// This function should be called after the beginning of a tick, before any possible
// prprite-event, or near the end, after any possible psprite event.
// Because data is reset for every tick (which it must be) this has no impact on savegames.
for (int i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i])
{
DPSprite *pspr = players[i].psprites;
while (pspr)
{
pspr->processPending = true;
pspr->ResetInterpolation();
pspr = pspr->Next;
}
}
}
}
//---------------------------------------------------------------------------
//
// PROC P_SetPsprite
//
//---------------------------------------------------------------------------
void DPSprite::SetState(FState *newstate, bool pending)
{
if (ID == PSP_WEAPON)
{ // A_WeaponReady will re-set these as needed
Owner->WeaponState &= ~(WF_WEAPONREADY | WF_WEAPONREADYALT | WF_WEAPONBOBBING | WF_WEAPONSWITCHOK | WF_WEAPONRELOADOK | WF_WEAPONZOOMOK |
WF_USER1OK | WF_USER2OK | WF_USER3OK | WF_USER4OK);
}
processPending = pending;
do
{
if (newstate == nullptr)
{ // Object removed itself.
Destroy();
return;
}
if (!(newstate->UseFlags & (SUF_OVERLAY|SUF_WEAPON))) // Weapon and overlay are mostly the same, the main difference is that weapon states restrict the self pointer to class Actor.
{
Printf(TEXTCOLOR_RED "State %s not flagged for use in overlays or weapons\n", FState::StaticGetStateName(newstate).GetChars());
State = nullptr;
Destroy();
return;
}
else if (!(newstate->UseFlags & SUF_WEAPON))
{
if (Caller->IsKindOf(NAME_Weapon))
{
Printf(TEXTCOLOR_RED "State %s not flagged for use in weapons\n", FState::StaticGetStateName(newstate).GetChars());
State = nullptr;
Destroy();
return;
}
}
State = newstate;
if (newstate->sprite != SPR_FIXED)
{ // okay to change sprite and/or frame
if (!newstate->GetSameFrame())
{ // okay to change frame
Frame = newstate->GetFrame();
}
if (newstate->sprite != SPR_NOCHANGE)
{ // okay to change sprite
Sprite = newstate->sprite;
}
}
Tics = newstate->GetTics(); // could be 0
if (Flags & PSPF_CVARFAST)
{
if (sv_fastweapons == 2 && ID == PSP_WEAPON)
Tics = newstate->ActionFunc == nullptr ? 0 : 1;
else if (sv_fastweapons == 3)
Tics = (newstate->GetTics() != 0);
else if (sv_fastweapons)
Tics = 1; // great for producing decals :)
}
if (ID != PSP_FLASH)
{ // It's still possible to set the flash layer's offsets with the action function.
// Anything going through here cannot be reliably interpolated so this has to reset the interpolation coordinates if it changes the values.
if (newstate->GetMisc1())
{ // Set coordinates.
oldx = x = newstate->GetMisc1();
}
if (newstate->GetMisc2())
{
oldy = y = newstate->GetMisc2();
}
}
if (Owner->mo != nullptr)
{
FState *nextstate;
FStateParamInfo stp = { newstate, STATE_Psprite, ID };
if (newstate->ActionFunc != nullptr && newstate->ActionFunc->Unsafe)
{
// If an unsafe function (i.e. one that accesses user variables) is being detected, print a warning once and remove the bogus function. We may not call it because that would inevitably crash.
Printf(TEXTCOLOR_RED "Unsafe state call in state %sd to %s which accesses user variables. The action function has been removed from this state\n",
FState::StaticGetStateName(newstate).GetChars(), newstate->ActionFunc->PrintableName.GetChars());
newstate->ActionFunc = nullptr;
}
if (newstate->CallAction(Owner->mo, Caller, &stp, &nextstate))
{
// It's possible this call resulted in this very layer being replaced.
if (ObjectFlags & OF_EuthanizeMe)
{
return;
}
if (nextstate != nullptr)
{
newstate = nextstate;
Tics = 0;
continue;
}
if (State == nullptr)
{
Destroy();
return;
}
}
}
newstate = State->GetNextState();
} while (!Tics); // An initial state of 0 could cycle through.
return;
}
DEFINE_ACTION_FUNCTION(DPSprite, SetState)
{
PARAM_SELF_PROLOGUE(DPSprite);
PARAM_POINTER(state, FState);
PARAM_BOOL(pending);
self->SetState(state, pending);
return 0;
}
//---------------------------------------------------------------------------
//
// PROC P_BringUpWeapon
//
// Starts bringing the pending weapon up from the bottom of the screen.
// This is only called to start the rising, not throughout it.
//
//---------------------------------------------------------------------------
void P_BringUpWeapon (player_t *player)
{
IFVM(PlayerPawn, BringUpWeapon)
{
VMValue param = player->mo;
VMCall(func, ¶m, 1, nullptr, 0);
}
}
//============================================================================
//
// P_BobWeapon
//
// [RH] Moved this out of A_WeaponReady so that the weapon can bob every
// tic and not just when A_WeaponReady is called. Not all weapons execute
// A_WeaponReady every tic, and it looks bad if they don't bob smoothly.
//
// [XA] Added new bob styles and exposed bob properties. Thanks, Ryan Cordell!
// [SP] Added new user option for bob speed
//
//============================================================================
void P_BobWeapon (player_t *player, float *x, float *y, double ticfrac)
{
IFVIRTUALPTRNAME(player->mo, NAME_PlayerPawn, BobWeapon)
{
VMValue param[] = { player->mo, ticfrac };
DVector2 result;
VMReturn ret(&result);
VMCall(func, param, 2, &ret, 1);
*x = (float)result.X;
*y = (float)result.Y;
return;
}
*x = *y = 0;
}
//---------------------------------------------------------------------------
//
// PROC P_CheckWeaponButtons
//
// Check extra button presses for weapons.
//
//---------------------------------------------------------------------------
static void P_CheckWeaponButtons (player_t *player)
{
auto weapon = player->ReadyWeapon;
if (weapon == nullptr)
{
return;
}
// The button checks are ordered by precedence. The first one to match a
// button press and affect a state change wins.
for (size_t i = 0; i < countof(ButtonChecks); ++i)
{
if ((player->WeaponState & ButtonChecks[i].StateFlag) &&
(player->cmd.ucmd.buttons & ButtonChecks[i].ButtonFlag))
{
FState *state = weapon->FindState(ButtonChecks[i].StateName);
// [XA] don't change state if still null, so if the modder
// sets WRF_xxx to true but forgets to define the corresponding
// state, the weapon won't disappear. ;)
if (state != nullptr)
{
P_SetPsprite(player, PSP_WEAPON, state);
return;
}
}
}
}
DEFINE_ACTION_FUNCTION(APlayerPawn, CheckWeaponButtons)
{
PARAM_SELF_PROLOGUE(AActor);
P_CheckWeaponButtons(self->player);
return 0;
}
enum WOFFlags
{
WOF_KEEPX = 1,
WOF_KEEPY = 1 << 1,
WOF_ADD = 1 << 2,
WOF_INTERPOLATE = 1 << 3,
WOF_RELATIVE = 1 << 4,
WOF_ZEROY = 1 << 5,
};
void HandleOverlayRelative(DPSprite *psp, double *x, double *y)
{
double wx = *x;
double wy = *y;
double c = psp->rotation.Cos(), s = psp->rotation.Sin();
double nx = wx * c + wy * s;
double ny = wx * s - wy * c;
*x = nx; *y = ny;
}
//---------------------------------------------------------------------------
//
// PROC A_OverlayVertexOffset
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_OverlayVertexOffset)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer)
PARAM_INT(index)
PARAM_FLOAT(x)
PARAM_FLOAT(y)
PARAM_INT(flags)
if (index < 0 || index > 3 || ((flags & WOF_KEEPX) && (flags & WOF_KEEPY)) || !ACTION_CALL_FROM_PSPRITE())
return 0;
DPSprite *pspr = self->player->FindPSprite(((layer != 0) ? layer : stateinfo->mPSPIndex));
if (pspr == nullptr)
return 0;
if (!(flags & WOF_KEEPX)) pspr->Coord[index].X = (flags & WOF_ADD) ? pspr->Coord[index].X + x : x;
if (!(flags & WOF_KEEPY)) pspr->Coord[index].Y = (flags & WOF_ADD) ? pspr->Coord[index].Y + y : y;
if (flags & (WOF_ADD | WOF_INTERPOLATE)) pspr->InterpolateTic = true;
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_OverlayScale
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_OverlayScale)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer)
PARAM_FLOAT(wx)
PARAM_FLOAT(wy)
PARAM_INT(flags)
if (!ACTION_CALL_FROM_PSPRITE() || ((flags & WOF_KEEPX) && (flags & WOF_KEEPY)))
return 0;
DPSprite *pspr = self->player->FindPSprite(((layer != 0) ? layer : stateinfo->mPSPIndex));
if (pspr == nullptr)
return 0;
if (!(flags & WOF_ZEROY) && wy == 0.0)
wy = wx;
if (!(flags & WOF_KEEPX)) pspr->scale.X = (flags & WOF_ADD) ? pspr->scale.X + wx : wx;
if (!(flags & WOF_KEEPY)) pspr->scale.Y = (flags & WOF_ADD) ? pspr->scale.Y + wy : wy;
if (flags & (WOF_ADD | WOF_INTERPOLATE)) pspr->InterpolateTic = true;
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_OverlayRotate
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_OverlayRotate)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer)
PARAM_ANGLE(degrees)
PARAM_INT(flags)
if (!ACTION_CALL_FROM_PSPRITE())
return 0;
DPSprite *pspr = self->player->FindPSprite(((layer != 0) ? layer : stateinfo->mPSPIndex));
if (pspr != nullptr)
{
pspr->rotation = (flags & WOF_ADD) ? pspr->rotation + degrees : degrees;
if (flags & (WOF_ADD | WOF_INTERPOLATE)) pspr->InterpolateTic = true;
}
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_OverlayPivot
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_OverlayPivot)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer)
PARAM_FLOAT(wx)
PARAM_FLOAT(wy)
PARAM_INT(flags)
if (!ACTION_CALL_FROM_PSPRITE() || ((flags & WOF_KEEPX) && (flags & WOF_KEEPY)))
return 0;
DPSprite *pspr = self->player->FindPSprite(((layer != 0) ? layer : stateinfo->mPSPIndex));
if (pspr == nullptr)
return 0;
if (flags & WOF_RELATIVE)
{
HandleOverlayRelative(pspr, &wx, &wy);
}
if (!(flags & WOF_KEEPX)) pspr->pivot.X = (flags & WOF_ADD) ? pspr->pivot.X + wx : wx;
if (!(flags & WOF_KEEPY)) pspr->pivot.Y = (flags & WOF_ADD) ? pspr->pivot.Y + wy : wy;
if (flags & (WOF_ADD | WOF_INTERPOLATE)) pspr->InterpolateTic = true;
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_OverlayOffset
//
//---------------------------------------------------------------------------
void A_OverlayOffset(AActor *self, int layer, double wx, double wy, int flags)
{
if ((flags & WOF_KEEPX) && (flags & WOF_KEEPY))
{
return;
}
player_t *player = self->player;
DPSprite *psp;
if (player)
{
psp = player->FindPSprite(layer);
if (psp == nullptr)
return;
if (flags & WOF_RELATIVE)
{
HandleOverlayRelative(psp, &wx, &wy);
}
if (!(flags & WOF_KEEPX)) psp->x = (flags & WOF_ADD) ? psp->x + wx : wx;
if (!(flags & WOF_KEEPY)) psp->y = (flags & WOF_ADD) ? psp->y + wy : wy;
if (!(flags & (WOF_ADD | WOF_INTERPOLATE)))
psp->ResetInterpolation();
}
}
DEFINE_ACTION_FUNCTION(AActor, A_OverlayOffset)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer)
PARAM_FLOAT(wx)
PARAM_FLOAT(wy)
PARAM_INT(flags)
A_OverlayOffset(self, ((layer != 0) ? layer : stateinfo->mPSPIndex), wx, wy, flags);
return 0;
}
DEFINE_ACTION_FUNCTION(AActor, A_WeaponOffset)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_FLOAT(wx)
PARAM_FLOAT(wy)
PARAM_INT(flags)
A_OverlayOffset(self, PSP_WEAPON, wx, wy, flags);
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_OverlayFlags
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_OverlayFlags)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer);
PARAM_INT(flags);
PARAM_BOOL(set);
if (!ACTION_CALL_FROM_PSPRITE())
return 0;
DPSprite *pspr = self->player->FindPSprite(((layer != 0) ? layer : stateinfo->mPSPIndex));
if (pspr == nullptr)
return 0;
if (set)
pspr->Flags |= flags;
else
{
pspr->Flags &= ~flags;
// This is the only way to shut off the temporary interpolation tic
// in the event another mod is causing potential interference
if (flags & PSPF_INTERPOLATE)
pspr->ResetInterpolation();
}
return 0;
}
DEFINE_ACTION_FUNCTION(AActor, A_OverlayPivotAlign)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer);
PARAM_INT(halign);
PARAM_INT(valign);
if (!ACTION_CALL_FROM_PSPRITE())
return 0;
DPSprite *pspr = self->player->FindPSprite(((layer != 0) ? layer : stateinfo->mPSPIndex));
if (pspr != nullptr)
{
if (halign >= PSPA_LEFT && halign <= PSPA_RIGHT)
pspr->HAlign |= halign;
if (valign >= PSPA_TOP && valign <= PSPA_BOTTOM)
pspr->VAlign |= valign;
}
return 0;
}
//---------------------------------------------------------------------------
//
// PROC A_OverlayTranslation
//
//---------------------------------------------------------------------------
DEFINE_ACTION_FUNCTION(AActor, A_OverlayTranslation)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer);
PARAM_NAME(trname);
if (!ACTION_CALL_FROM_PSPRITE())
return 0;
DPSprite* pspr = self->player->FindPSprite(((layer != 0) ? layer : stateinfo->mPSPIndex));
if (pspr != nullptr)
{
// There is no constant for the empty name...
if (trname.GetChars()[0] == 0)
{
// an empty string resets to the default
// (unlike AActor::SetTranslation, there is no Default block for PSprites, so just set the translation to 0)
pspr->Translation = 0;
return 0;
}
int tnum = R_FindCustomTranslation(trname);
if (tnum >= 0)
{
pspr->Translation = tnum;
}
// silently ignore if the name does not exist, this would create some insane message spam otherwise.
}
return 0;
}
//---------------------------------------------------------------------------
//
// PROC OverlayX/Y
// Action function to return the X/Y of an overlay.
//---------------------------------------------------------------------------
static double GetOverlayPosition(AActor *self, int layer, bool gety)
{
if (layer)
{
DPSprite *pspr = self->player->FindPSprite(layer);
if (pspr != nullptr)
{
return gety ? (pspr->y) : (pspr->x);
}
}
return 0.;
}
DEFINE_ACTION_FUNCTION(AActor, OverlayX)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(layer);
if (ACTION_CALL_FROM_PSPRITE())
{
double res = GetOverlayPosition(self, ((layer != 0) ? layer : stateinfo->mPSPIndex), false);
ACTION_RETURN_FLOAT(res);
}
ACTION_RETURN_FLOAT(0.);
}
DEFINE_ACTION_FUNCTION(AActor, OverlayY)
{
PARAM_ACTION_PROLOGUE(AActor);