/
p_actionfunctions.cpp
5033 lines (4432 loc) · 127 KB
/
p_actionfunctions.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
/*
** thingdef_codeptr.cpp
**
** Code pointers for Actor definitions
**
**---------------------------------------------------------------------------
** Copyright 2002-2006 Christoph Oelckers
** Copyright 2004-2006 Randy Heit
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
** 4. When not used as part of ZDoom or a ZDoom derivative, this code will be
** covered by 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 SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
#include "gi.h"
#include "g_level.h"
#include "actor.h"
#include "r_defs.h"
#include "a_pickups.h"
#include "cmdlib.h"
#include "p_lnspec.h"
#include "p_effect.h"
#include "p_enemy.h"
#include "decallib.h"
#include "p_local.h"
#include "c_console.h"
#include "engineerrors.h"
#include "a_sharedglobal.h"
#include "v_font.h"
#include "doomstat.h"
#include "a_specialspot.h"
#include "actorptrselect.h"
#include "p_trace.h"
#include "p_setup.h"
#include "gstrings.h"
#include "d_player.h"
#include "p_maputl.h"
#include "p_spec.h"
#include "v_text.h"
#include "thingdef.h"
#include "g_levellocals.h"
#include "r_utility.h"
#include "sbar.h"
#include "actorinlines.h"
#include "types.h"
static FRandom pr_camissile ("CustomActorfire");
static FRandom pr_cabullet ("CustomBullet");
static FRandom pr_cwjump ("CustomWpJump");
static FRandom pr_cwpunch ("CustomWpPunch");
static FRandom pr_grenade ("ThrowGrenade");
static FRandom pr_crailgun ("CustomRailgun");
static FRandom pr_spawndebris ("SpawnDebris");
static FRandom pr_spawnitemex ("SpawnItemEx");
static FRandom pr_burst ("Burst");
static FRandom pr_monsterrefire ("MonsterRefire");
static FRandom pr_teleport("A_Teleport");
static FRandom pr_bfgselfdamage("BFGSelfDamage");
FRandom pr_cajump("CustomJump");
//==========================================================================
//
// ACustomInventory :: CallStateChain
//
// Executes the code pointers in a chain of states
// until there is no next state
//
//==========================================================================
extern TArray<VMValue> actionParams; // this can use the same storage as CallAction
static int CallStateChain (AActor *self, AActor *actor, FState *state)
{
INTBOOL result = false;
int counter = 0;
// We accept return types of `state`, `(int|bool)` or `state, (int|bool)`.
// The last one is for the benefit of A_Warp and A_Teleport.
int retval, numret;
FState *nextstate;
VMReturn ret[2];
ret[0].PointerAt((void **)&nextstate);
ret[1].IntAt(&retval);
FState *savedstate = self->state;
while (state != NULL)
{
if (!(state->UseFlags & SUF_ITEM))
{
Printf(TEXTCOLOR_RED "State %s not flagged for use in CustomInventory state chains.\n", FState::StaticGetStateName(state).GetChars());
return false;
}
self->state = state;
nextstate = NULL; // assume no jump
if (state->ActionFunc != NULL)
{
if (state->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.
auto owner = FState::StaticFindStateOwner(state);
Printf(TEXTCOLOR_RED "Unsafe state call in state %s to %s which accesses user variables. The action function has been removed from this state\n",
FState::StaticGetStateName(state).GetChars(), state->ActionFunc->PrintableName.GetChars());
state->ActionFunc = nullptr;
}
PPrototype *proto = state->ActionFunc->Proto;
VMReturn *wantret;
FStateParamInfo stp = { state, STATE_StateChain, PSP_WEAPON };
retval = true; // assume success
wantret = NULL; // assume no return value wanted
numret = 0;
// For functions that return nothing (or return some type
// we don't care about), we pretend they return true,
// thanks to the values set just above.
if (proto->ReturnTypes.Size() >= 2 &&
proto->ReturnTypes[0] == TypeState &&
(proto->ReturnTypes[1] == TypeSInt32 || proto->ReturnTypes[0] == TypeUInt32 || proto->ReturnTypes[1] == TypeBool))
{ // Function returns a state and an int or bool
wantret = &ret[0];
numret = 2;
}
else if (proto->ReturnTypes.Size() == 1 && proto->ReturnTypes[0] == TypeState)
{ // Function returns a state
wantret = &ret[0];
retval = false; // this is a jump function which never affects the success state.
numret = 1;
}
else if (proto->ReturnTypes.Size() >= 1 &&
(proto->ReturnTypes[0] == TypeSInt32 || proto->ReturnTypes[0] == TypeUInt32 || proto->ReturnTypes[0] == TypeBool))
{ // Function returns an int or bool
wantret = &ret[1];
numret = 1;
}
try
{
state->CheckCallerType(actor, self);
if (state->ActionFunc->DefaultArgs.Size() > 0)
{
auto defs = state->ActionFunc->DefaultArgs;
auto index = actionParams.Reserve(defs.Size());
for (unsigned i = 0; i < defs.Size(); i++)
{
actionParams[i + index] = defs[i];
}
if (state->ActionFunc->ImplicitArgs >= 1)
{
actionParams[index] = actor;
}
if (state->ActionFunc->ImplicitArgs == 3)
{
actionParams[index + 1] = self;
actionParams[index + 2] = VMValue(&stp);
}
VMCallAction(state->ActionFunc, &actionParams[index], state->ActionFunc->DefaultArgs.Size(), wantret, numret);
actionParams.Clamp(index);
}
else
{
VMValue params[3] = { actor, self, VMValue(&stp) };
VMCallAction(state->ActionFunc, params, state->ActionFunc->ImplicitArgs, wantret, numret);
}
}
catch (CVMAbortException &err)
{
err.MaybePrintMessage();
err.stacktrace.AppendFormat("Called from state %s in inventory state chain in %s\n", FState::StaticGetStateName(state).GetChars(), self->GetClass()->TypeName.GetChars());
throw;
}
// As long as even one state succeeds, the whole chain succeeds unless aborted below.
// A state that wants to jump does not count as "succeeded".
if (nextstate == NULL)
{
result |= retval;
}
}
// Since there are no delays it is a good idea to check for infinite loops here!
counter++;
if (counter >= 10000) break;
if (nextstate == NULL)
{
nextstate = state->GetNextState();
if (state == nextstate)
{ // Abort immediately if the state jumps to itself!
result = false;
break;
}
}
state = nextstate;
}
self->state = savedstate;
return !!result;
}
DEFINE_ACTION_FUNCTION_NATIVE(ACustomInventory, CallStateChain, CallStateChain)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_OBJECT(affectee, AActor);
PARAM_POINTER(state, FState);
ACTION_RETURN_BOOL(CallStateChain(self, affectee, state));
}
//==========================================================================
//
// GetZAt
//
// NON-ACTION function to get the floor or ceiling z at (x, y) with
// relativity being an option.
//==========================================================================
enum GZFlags
{
GZF_ABSOLUTEPOS = 1, // Use the absolute position instead of an offsetted one.
GZF_ABSOLUTEANG = 1 << 1, // Don't add the actor's angle to the parameter.
GZF_CEILING = 1 << 2, // Check the ceiling instead of the floor.
GZF_3DRESTRICT = 1 << 3, // Ignore midtextures and 3D floors above the pointer's z.
GZF_NOPORTALS = 1 << 4, // Don't pass through any portals.
GZF_NO3DFLOOR = 1 << 5, // Pass all 3D floors.
};
DEFINE_ACTION_FUNCTION(AActor, GetZAt)
{
if (numret > 0)
{
assert(ret != NULL);
PARAM_SELF_PROLOGUE(AActor);
PARAM_FLOAT(px);
PARAM_FLOAT(py);
PARAM_ANGLE(angle);
PARAM_INT(flags);
PARAM_INT(pick_pointer);
AActor *mobj = COPY_AAPTR(self, pick_pointer);
if (mobj == nullptr)
{
ret->SetFloat(0);
}
else
{
// [MC] At any time, the NextLowest/Highest functions could be changed to include
// more FFC flags to check. Don't risk it by just passing flags straight to it.
DVector2 pos = { px, py };
double z = 0.;
int pflags = (flags & GZF_3DRESTRICT) ? FFCF_3DRESTRICT : 0;
if (flags & GZF_NOPORTALS) pflags |= FFCF_NOPORTALS;
if (!(flags & GZF_ABSOLUTEPOS))
{
if (!(flags & GZF_ABSOLUTEANG))
{
angle += mobj->Angles.Yaw;
}
double s = angle.Sin();
double c = angle.Cos();
pos = mobj->Vec2Offset(pos.X * c + pos.Y * s, pos.X * s - pos.Y * c);
}
sector_t *sec = self->Level->PointInSector(pos);
if (sec)
{
if (flags & GZF_CEILING)
{
if ((flags & GZF_NO3DFLOOR) && (flags & GZF_NOPORTALS))
{
z = sec->ceilingplane.ZatPoint(pos);
}
else if (flags & GZF_NO3DFLOOR)
{
z = HighestCeilingAt(sec, pos.X, pos.Y);
}
else
{ // [MC] Handle strict 3D floors and portal toggling via the flags passed to it.
z = NextHighestCeilingAt(sec, pos.X, pos.Y, mobj->Z(), mobj->Top(), pflags);
}
}
else
{
if ((flags & GZF_NO3DFLOOR) && (flags & GZF_NOPORTALS))
{
z = sec->floorplane.ZatPoint(pos);
}
else if (flags & GZF_NO3DFLOOR)
{
z = LowestFloorAt(sec, pos.X, pos.Y);
}
else
{
z = NextLowestFloorAt(sec, pos.X, pos.Y, mobj->Z(), pflags, mobj->MaxStepHeight);
}
}
}
ret->SetFloat(z);
return 1;
}
}
return 0;
}
//==========================================================================
//
// GetCrouchFactor
//
// NON-ACTION function to retrieve a player's crouching factor.
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, GetCrouchFactor)
{
if (numret > 0)
{
assert(ret != NULL);
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(ptr);
AActor *mobj = COPY_AAPTR(self, ptr);
if (!mobj || !mobj->player)
{
ret->SetFloat(1);
}
else
{
ret->SetFloat(mobj->player->crouchfactor);
}
return 1;
}
return 0;
}
//==========================================================================
//
// GetCVar
//
// NON-ACTION function that works like ACS's GetCVar.
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, GetCVar)
{
if (numret > 0)
{
assert(ret != nullptr);
PARAM_SELF_PROLOGUE(AActor);
PARAM_STRING(cvarname);
FBaseCVar *cvar = GetCVar(self->player ? int(self->player - players) : -1, cvarname);
if (cvar == nullptr)
{
ret->SetFloat(0);
}
else
{
ret->SetFloat(cvar->GetGenericRep(CVAR_Float).Float);
}
return 1;
}
return 0;
}
//==========================================================================
//
// GetCVar
//
// NON-ACTION function that works like ACS's GetCVar.
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, GetCVarString)
{
if (numret > 0)
{
assert(ret != nullptr);
PARAM_SELF_PROLOGUE(AActor);
PARAM_STRING(cvarname);
FBaseCVar *cvar = GetCVar(self->player? int(self->player - players) : -1, cvarname);
if (cvar == nullptr)
{
ret->SetString("");
}
else
{
ret->SetString(cvar->GetGenericRep(CVAR_String).String);
}
return 1;
}
return 0;
}
//==========================================================================
//
// GetPlayerInput
//
// NON-ACTION function that works like ACS's GetPlayerInput.
// Takes a pointer as anyone may or may not be a player.
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, GetPlayerInput)
{
if (numret > 0)
{
assert(ret != nullptr);
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT (inputnum);
PARAM_INT(ptr);
AActor *mobj = COPY_AAPTR(self, ptr);
//Need a player.
if (!mobj || !mobj->player)
{
ret->SetInt(0);
}
else
{
ret->SetInt(P_Thing_CheckInputNum(mobj->player, inputnum));
}
return 1;
}
return 0;
}
//==========================================================================
//
// CountProximity
//
// NON-ACTION function of A_CheckProximity that returns how much it counts.
// Takes a pointer as anyone may or may not be a player.
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, CountProximity)
{
if (numret > 0)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_CLASS(classname, AActor);
PARAM_FLOAT(distance);
PARAM_INT(flags);
PARAM_INT(ptr);
AActor *mobj = COPY_AAPTR(self, ptr);
if (mobj == nullptr)
{
ret->SetInt(0);
}
else
{
ret->SetInt(P_Thing_CheckProximity(self->Level, self, classname, distance, 0, flags, ptr, true));
}
return 1;
}
return 0;
}
//===========================================================================
//
// __decorate_internal_int__
// __decorate_internal_bool__
// __decorate_internal_float__
//
// Placeholders for forcing DECORATE to cast numbers. If actually called,
// returns whatever was passed.
//
//===========================================================================
DEFINE_ACTION_FUNCTION(AActor, __decorate_internal_int__)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(returnme);
ACTION_RETURN_INT(returnme);
}
DEFINE_ACTION_FUNCTION(AActor, __decorate_internal_bool__)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_BOOL(returnme);
ACTION_RETURN_BOOL(returnme);
}
DEFINE_ACTION_FUNCTION(AActor, __decorate_internal_float__)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_FLOAT(returnme);
if (numret > 0)
{
ret->SetFloat(returnme);
return 1;
}
return 0;
}
//==========================================================================
//
// A_RearrangePointers
//
// Allow an actor to change its relationship to other actors by
// copying pointers freely between TARGET MASTER and TRACER.
// Can also assign null value, but does not duplicate A_ClearTarget.
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_RearrangePointers)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT (ptr_target);
PARAM_INT (ptr_master);
PARAM_INT (ptr_tracer);
PARAM_INT (flags);
// Rearrange pointers internally
// Fetch all values before modification, so that all fields can get original values
AActor
*gettarget = self->target,
*getmaster = self->master,
*gettracer = self->tracer;
switch (ptr_target) // pick the new target
{
case AAPTR_MASTER:
self->target = getmaster;
if (!(PTROP_UNSAFETARGET & flags)) VerifyTargetChain(self);
break;
case AAPTR_TRACER:
self->target = gettracer;
if (!(PTROP_UNSAFETARGET & flags)) VerifyTargetChain(self);
break;
case AAPTR_NULL:
self->target = nullptr;
// THIS IS NOT "A_ClearTarget", so no other targeting info is removed
break;
}
// presently permitting non-monsters to set master
switch (ptr_master) // pick the new master
{
case AAPTR_TARGET:
self->master = gettarget;
if (!(PTROP_UNSAFEMASTER & flags)) VerifyMasterChain(self);
break;
case AAPTR_TRACER:
self->master = gettracer;
if (!(PTROP_UNSAFEMASTER & flags)) VerifyMasterChain(self);
break;
case AAPTR_NULL:
self->master = nullptr;
break;
}
switch (ptr_tracer) // pick the new tracer
{
case AAPTR_TARGET:
self->tracer = gettarget;
break; // no verification deemed necessary; the engine never follows a tracer chain(?)
case AAPTR_MASTER:
self->tracer = getmaster;
break; // no verification deemed necessary; the engine never follows a tracer chain(?)
case AAPTR_NULL:
self->tracer = nullptr;
break;
}
return 0;
}
//==========================================================================
//
// A_TransferPointer
//
// Copy one pointer (MASTER, TARGET or TRACER) from this actor (SELF),
// or from this actor's MASTER, TARGET or TRACER.
//
// You can copy any one of that actor's pointers
//
// Assign the copied pointer to any one pointer in SELF,
// MASTER, TARGET or TRACER.
//
// Any attempt to make an actor point to itself will replace the pointer
// with a null value.
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_TransferPointer)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT (ptr_source);
PARAM_INT (ptr_recipient);
PARAM_INT (ptr_sourcefield);
PARAM_INT (ptr_recipientfield);
PARAM_INT (flags);
AActor *source, *recipient;
// Exchange pointers with actors to whom you have pointers (or with yourself, if you must)
source = COPY_AAPTR(self, ptr_source);
recipient = COPY_AAPTR(self, ptr_recipient); // pick an actor to store the provided pointer value
if (recipient == NULL)
{
return 0;
}
// convert source from dataprovider to data
source = COPY_AAPTR(source, ptr_sourcefield);
if (source == recipient)
{ // The recepient should not acquire a pointer to itself; will write NULL}
source = NULL;
}
if (ptr_recipientfield == AAPTR_DEFAULT)
{ // If default: Write to same field as data was read from
ptr_recipientfield = ptr_sourcefield;
}
ASSIGN_AAPTR(recipient, ptr_recipientfield, source, flags);
return 0;
}
//==========================================================================
//
// A_CopyFriendliness
//
// Join forces with one of the actors you are pointing to (MASTER by default)
//
// Normal CopyFriendliness reassigns health. This function will not.
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_CopyFriendliness)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT (ptr_source);
if (self->player != NULL)
{
return 0;
}
AActor *source = COPY_AAPTR(self, ptr_source);
if (source != NULL)
{ // No change in current target or health
self->CopyFriendliness(source, false, false);
}
return 0;
}
//==========================================================================
//
// These come from a time when DECORATE constants did not exist yet and
// the sound interface was less flexible. As a result the parameters are
// not optimal and these functions have been deprecated in favor of extending
// A_PlaySound and A_StopSound.
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_PlaySoundEx)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_SOUND (soundid);
PARAM_NAME (channel);
PARAM_BOOL (looping);
PARAM_INT (attenuation_raw);
float attenuation;
switch (attenuation_raw)
{
case -1: attenuation = ATTN_STATIC; break; // drop off rapidly
default:
case 0: attenuation = ATTN_NORM; break; // normal
case 1:
case 2: attenuation = ATTN_NONE; break; // full volume
}
if (channel < NAME_Auto || channel > NAME_SoundSlot7)
{
channel = NAME_Auto;
}
if (!looping)
{
S_Sound (self, channel.GetIndex() - NAME_Auto, 0, soundid, 1, attenuation);
}
else
{
if (!S_IsActorPlayingSomething (self, channel.GetIndex() - NAME_Auto, soundid))
{
S_Sound (self, (channel.GetIndex() - NAME_Auto), CHANF_LOOP, soundid, 1, attenuation);
}
}
return 0;
}
DEFINE_ACTION_FUNCTION(AActor, A_StopSoundEx)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_NAME(channel);
if (channel > NAME_Auto && channel <= NAME_SoundSlot7)
{
S_StopSound (self, channel.GetIndex() - NAME_Auto);
}
return 0;
}
//==========================================================================
//
// Generic seeker missile function
//
//==========================================================================
static FRandom pr_seekermissile ("SeekerMissile");
enum
{
SMF_LOOK = 1,
SMF_PRECISE = 2,
SMF_CURSPEED = 4,
};
DEFINE_ACTION_FUNCTION(AActor, A_SeekerMissile)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(ang1);
PARAM_INT(ang2);
PARAM_INT(flags);
PARAM_INT(chance);
PARAM_INT(distance);
if ((flags & SMF_LOOK) && (self->tracer == nullptr) && (pr_seekermissile()<chance))
{
self->tracer = P_RoughMonsterSearch (self, distance, true);
}
if (!P_SeekerMissile(self, clamp<int>(ang1, 0, 90), clamp<int>(ang2, 0, 90), !!(flags & SMF_PRECISE), !!(flags & SMF_CURSPEED)))
{
if (flags & SMF_LOOK)
{ // This monster is no longer seekable, so let us look for another one next time.
self->tracer = nullptr;
}
}
return 0;
}
//==========================================================================
//
// Hitscan attack with a customizable amount of bullets (specified in damage)
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_BulletAttack)
{
PARAM_SELF_PROLOGUE(AActor);
int i;
if (!self->target) return 0;
A_FaceTarget (self);
DAngle slope = P_AimLineAttack (self, self->Angles.Yaw, MISSILERANGE);
S_Sound (self, CHAN_WEAPON, 0, self->AttackSound, 1, ATTN_NORM);
for (i = self->GetMissileDamage (0, 1); i > 0; --i)
{
DAngle angle = self->Angles.Yaw + pr_cabullet.Random2() * (5.625 / 256.);
int damage = ((pr_cabullet()%5)+1)*3;
P_LineAttack(self, angle, MISSILERANGE, slope, damage,
NAME_Hitscan, NAME_BulletPuff);
}
return 0;
}
//==========================================================================
//
// State jump function
//
//==========================================================================
DEFINE_ACTION_FUNCTION(AActor, A_Jump)
{
PARAM_ACTION_PROLOGUE(AActor);
PARAM_INT(maxchance);
PARAM_STATE_ACTION(jumpto);
if (maxchance >= 256 || pr_cajump() < maxchance)
{
ACTION_RETURN_STATE(jumpto);
}
ACTION_RETURN_STATE(NULL);
}
//==========================================================================
//
// A_RadiusDamageSelf
//
//==========================================================================
enum
{
RDSF_BFGDAMAGE = 1,
};
DEFINE_ACTION_FUNCTION(AActor, A_RadiusDamageSelf)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(damage);
PARAM_FLOAT(distance);
PARAM_INT(flags);
PARAM_CLASS(flashtype, AActor);
int i;
int damageSteps;
int actualDamage;
double actualDistance;
if (self->target == nullptr) return 0;
actualDistance = self->Distance3D(self->target);
if (actualDistance < distance)
{
// [XA] Decrease damage with distance. Use the BFG damage
// calculation formula if the flag is set (essentially
// a generalization of SMMU's BFG11K behavior, used
// with fraggle's blessing.)
damageSteps = damage - int(damage * actualDistance / distance);
if (flags & RDSF_BFGDAMAGE)
{
actualDamage = 0;
for (i = 0; i < damageSteps; ++i)
actualDamage += (pr_bfgselfdamage() & 7) + 1;
}
else
{
actualDamage = damageSteps;
}
// optional "flash" effect -- spawn an actor on
// the player to indicate bad things happened.
AActor *flash = NULL;
if(flashtype != NULL)
flash = Spawn(self->Level, flashtype, self->target->PosPlusZ(self->target->Height / 4), ALLOW_REPLACE);
int dmgFlags = 0;
FName dmgType = NAME_BFGSplash;
if (flash != NULL)
{
if (flash->flags5 & MF5_PUFFGETSOWNER) flash->target = self->target;
if (flash->flags3 & MF3_FOILINVUL) dmgFlags |= DMG_FOILINVUL;
if (flash->flags7 & MF7_FOILBUDDHA) dmgFlags |= DMG_FOILBUDDHA;
dmgType = flash->DamageType;
}
int newdam = P_DamageMobj(self->target, self, self->target, actualDamage, dmgType, dmgFlags);
P_TraceBleed(newdam > 0 ? newdam : actualDamage, self->target, self);
}
return 0;
}
//==========================================================================
//
// The ultimate code pointer: Fully customizable missiles!
//
//==========================================================================
enum CM_Flags
{
CMF_AIMMODE = 3,
CMF_TRACKOWNER = 4,
CMF_CHECKTARGETDEAD = 8,
CMF_ABSOLUTEPITCH = 16,
CMF_OFFSETPITCH = 32,
CMF_SAVEPITCH = 64,
CMF_ABSOLUTEANGLE = 128,
CMF_BADPITCH = 256
};
DEFINE_ACTION_FUNCTION(AActor, A_SpawnProjectile)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_CLASS (ti, AActor);
PARAM_FLOAT (Spawnheight);
PARAM_FLOAT (Spawnofs_xy);
PARAM_ANGLE (Angle);
PARAM_INT (flags);
PARAM_ANGLE (Pitch);
PARAM_INT (ptr);
AActor *ref = COPY_AAPTR(self, ptr);
int aimmode = flags & CMF_AIMMODE;
AActor * targ;
AActor * missile = nullptr;
if (ref != NULL || aimmode == 2)
{
if (ti)
{
DAngle angle = self->Angles.Yaw - 90;
double x = Spawnofs_xy * angle.Cos();
double y = Spawnofs_xy * angle.Sin();
double z = Spawnheight + self->GetBobOffset() - 32 + (self->player? self->player->crouchoffset : 0.);
DVector3 pos = self->Pos();
switch (aimmode)
{
case 0:
default:
// same adjustment as above (in all 3 directions this time) - for better aiming!
self->SetXYZ(self->Vec3Offset(x, y, z));
missile = P_SpawnMissileXYZ(self->PosPlusZ(32.), self, ref, ti, false);
self->SetXYZ(pos);
break;
case 1:
missile = P_SpawnMissileXYZ(self->Vec3Offset(x, y, self->GetBobOffset() + Spawnheight), self, ref, ti, false);
break;
case 2:
self->SetXYZ(self->Vec3Offset(x, y, 0.));
missile = P_SpawnMissileAngleZSpeed(self, self->Z() + self->GetBobOffset() + Spawnheight, ti, self->Angles.Yaw, 0, GetDefaultByType(ti)->Speed, self, false);
self->SetXYZ(pos);
flags |= CMF_ABSOLUTEPITCH;
break;
}
if (missile != NULL)
{
// Use the actual velocity instead of the missile's Speed property
// so that this can handle missiles with a high vertical velocity
// component properly.
double missilespeed;
if ( (CMF_ABSOLUTEPITCH|CMF_OFFSETPITCH) & flags)
{
if (!(flags & CMF_BADPITCH))
{
if (CMF_OFFSETPITCH & flags)
{
Pitch += missile->Vel.Pitch();
}
missilespeed = fabs(Pitch.Cos() * missile->Speed);
missile->Vel.Z = -Pitch.Sin() * missile->Speed;
}
else
{
// Replicate the bogus calculation from A_CustomMissile in its entirety.
// This tried to do the right thing but in the process effectively inverted the base pitch.
if (CMF_OFFSETPITCH & flags)
{
Pitch -= missile->Vel.Pitch();
}
missilespeed = fabs(Pitch.Cos() * missile->Speed);
missile->Vel.Z = Pitch.Sin() * missile->Speed;
}
}
else
{
missilespeed = missile->VelXYToSpeed();
}
if (CMF_SAVEPITCH & flags)
{