/
p_mobj.cpp
7432 lines (6646 loc) · 189 KB
/
p_mobj.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-2017 Christoph Oelckers
//
// 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/
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION:
// Moving object handling. Spawn functions.
//
//-----------------------------------------------------------------------------
/* For code that originates from ZDoom the following applies:
**
**---------------------------------------------------------------------------
**
** 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.
**
** 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.
**---------------------------------------------------------------------------
**
*/
// HEADER FILES ------------------------------------------------------------
#include <float.h>
#include "templates.h"
#include "m_random.h"
#include "doomdef.h"
#include "p_local.h"
#include "p_maputl.h"
#include "p_lnspec.h"
#include "p_effect.h"
#include "p_terrain.h"
#include "hu_stuff.h"
#include "v_video.h"
#include "c_dispatch.h"
#include "b_bot.h" //Added by MC:
#include "a_sharedglobal.h"
#include "gi.h"
#include "sbar.h"
#include "p_acs.h"
#include "cmdlib.h"
#include "decallib.h"
#include "a_keys.h"
#include "p_conversation.h"
#include "g_game.h"
#include "teaminfo.h"
#include "r_sky.h"
#include "d_event.h"
#include "p_enemy.h"
#include "gstrings.h"
#include "po_man.h"
#include "p_spec.h"
#include "p_checkposition.h"
#include "serializer.h"
#include "r_utility.h"
#include "thingdef.h"
#include "d_player.h"
#include "g_levellocals.h"
#include "a_morph.h"
#include "events.h"
#include "actorinlines.h"
#include "a_dynlight.h"
#include "fragglescript/t_fs.h"
// MACROS ------------------------------------------------------------------
#define WATER_SINK_FACTOR 0.125
#define WATER_SINK_SMALL_FACTOR 0.25
#define WATER_SINK_SPEED 0.5
#define WATER_JUMP_SPEED 3.5
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void PlayerLandedOnThing (AActor *mo, AActor *onmobj);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
EXTERN_CVAR (Int, cl_rockettrails)
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static FRandom pr_explodemissile ("ExplodeMissile");
FRandom pr_bounce ("Bounce");
static FRandom pr_reflect ("Reflect");
static FRandom pr_nightmarerespawn ("NightmareRespawn");
static FRandom pr_botspawnmobj ("BotSpawnActor");
static FRandom pr_spawnmapthing ("SpawnMapThing");
static FRandom pr_spawnpuff ("SpawnPuff");
static FRandom pr_spawnblood ("SpawnBlood");
static FRandom pr_splatter ("BloodSplatter");
static FRandom pr_takedamage ("TakeDamage");
static FRandom pr_splat ("FAxeSplatter");
static FRandom pr_ripperblood ("RipperBlood");
static FRandom pr_chunk ("Chunk");
static FRandom pr_checkmissilespawn ("CheckMissileSpawn");
static FRandom pr_spawnmissile ("SpawnMissile");
static FRandom pr_missiledamage ("MissileDamage");
static FRandom pr_multiclasschoice ("MultiClassChoice");
static FRandom pr_rockettrail("RocketTrail");
static FRandom pr_uniquetid("UniqueTID");
// PUBLIC DATA DEFINITIONS -------------------------------------------------
FRandom pr_spawnmobj ("SpawnActor");
CUSTOM_CVAR (Float, sv_gravity, 800.f, CVAR_SERVERINFO|CVAR_NOSAVE|CVAR_NOINITCALL)
{
for (auto Level : AllLevels())
{
Level->gravity = self;
}
}
CVAR (Bool, cl_missiledecals, true, CVAR_ARCHIVE)
CVAR (Bool, addrocketexplosion, false, CVAR_ARCHIVE)
CVAR (Int, cl_pufftype, 0, CVAR_ARCHIVE);
CVAR (Int, cl_bloodtype, 0, CVAR_ARCHIVE);
// CODE --------------------------------------------------------------------
IMPLEMENT_CLASS(AActor, false, true)
IMPLEMENT_POINTERS_START(AActor)
IMPLEMENT_POINTER(target)
IMPLEMENT_POINTER(lastenemy)
IMPLEMENT_POINTER(tracer)
IMPLEMENT_POINTER(goal)
IMPLEMENT_POINTER(LastLookActor)
IMPLEMENT_POINTER(Inventory)
IMPLEMENT_POINTER(LastHeard)
IMPLEMENT_POINTER(master)
IMPLEMENT_POINTER(Poisoner)
IMPLEMENT_POINTER(alternative)
IMPLEMENT_POINTERS_END
AActor::~AActor ()
{
// Please avoid calling the destructor directly (or through delete)!
// Use Destroy() instead.
}
//==========================================================================
//
// AActor :: Serialize
//
//==========================================================================
#define A(a,b) ((a), (b), def->b)
void AActor::Serialize(FSerializer &arc)
{
AActor *def = GetDefault();
Super::Serialize(arc);
arc
.Sprite("sprite", sprite, &def->sprite)
A("pos", __Pos)
A("angles", Angles)
A("frame", frame)
A("scale", Scale)
A("renderstyle", RenderStyle)
A("renderflags", renderflags)
A("picnum", picnum)
A("floorpic", floorpic)
A("ceilingpic", ceilingpic)
A("tidtohate", TIDtoHate)
A("lastlookpn", LastLookPlayerNumber)
("lastlookactor", LastLookActor)
A("effects", effects)
A("fountaincolor", fountaincolor)
A("alpha", Alpha)
A("fillcolor", fillcolor)
A("sector", Sector)
A("floorz", floorz)
A("ceilingz", ceilingz)
A("dropoffz", dropoffz)
A("floorsector", floorsector)
A("ceilingsector", ceilingsector)
A("radius", radius)
A("renderradius", renderradius)
A("height", Height)
A("ppassheight", projectilepassheight)
A("vel", Vel)
A("tics", tics)
A("state", state)
A("damage", DamageVal)
.Terrain("floorterrain", floorterrain, &def->floorterrain)
A("projectilekickback", projectileKickback)
A("flags", flags)
A("flags2", flags2)
A("flags3", flags3)
A("flags4", flags4)
A("flags5", flags5)
A("flags6", flags6)
A("flags7", flags7)
A("flags8", flags8)
A("weaponspecial", weaponspecial)
A("special1", special1)
A("special2", special2)
A("specialf1", specialf1)
A("specialf2", specialf2)
A("health", health)
A("movedir", movedir)
A("visdir", visdir)
A("movecount", movecount)
A("strafecount", strafecount)
("target", target)
("lastenemy", lastenemy)
("lastheard", LastHeard)
A("reactiontime", reactiontime)
A("threshold", threshold)
A("player", player)
A("spawnpoint", SpawnPoint)
A("spawnangle", SpawnAngle)
A("starthealth", StartHealth)
A("skillrespawncount", skillrespawncount)
("tracer", tracer)
A("floorclip", Floorclip)
A("tid", tid)
A("special", special)
.Args("args", args, def->args, special)
A("accuracy", accuracy)
A("stamina", stamina)
("goal", goal)
A("waterlevel", waterlevel)
A("boomwaterlevel", boomwaterlevel)
A("minmissilechance", MinMissileChance)
A("spawnflags", SpawnFlags)
("inventory", Inventory)
A("inventoryid", InventoryID)
A("floatbobphase", FloatBobPhase)
A("floatbobstrength", FloatBobStrength)
A("translation", Translation)
A("bloodcolor", BloodColor)
A("bloodtranslation", BloodTranslation)
A("seesound", SeeSound)
A("attacksound", AttackSound)
A("paimsound", PainSound)
A("deathsound", DeathSound)
A("activesound", ActiveSound)
A("usesound", UseSound)
A("bouncesound", BounceSound)
A("wallbouncesound", WallBounceSound)
A("crushpainsound", CrushPainSound)
A("speed", Speed)
A("floatspeed", FloatSpeed)
A("mass", Mass)
A("painchance", PainChance)
A("spawnstate", SpawnState)
A("seestate", SeeState)
A("meleestate", MeleeState)
A("missilestate", MissileState)
A("maxdropoffheight", MaxDropOffHeight)
A("maxstepheight", MaxStepHeight)
A("bounceflags", BounceFlags)
A("bouncefactor", bouncefactor)
A("wallbouncefactor", wallbouncefactor)
A("bouncecount", bouncecount)
A("maxtargetrange", maxtargetrange)
A("meleethreshold", meleethreshold)
A("meleerange", meleerange)
A("damagetype", DamageType)
A("damagetypereceived", DamageTypeReceived)
A("paintype", PainType)
A("deathtype", DeathType)
A("gravity", Gravity)
A("fastchasestrafecount", FastChaseStrafeCount)
("master", master)
A("smokecounter", smokecounter)
("blockingmobj", BlockingMobj)
A("blockingline", BlockingLine)
A("blocking3dfloor", Blocking3DFloor)
A("blockingceiling", BlockingCeiling)
A("blockingfloor", BlockingFloor)
A("visibletoteam", VisibleToTeam)
A("pushfactor", pushfactor)
A("species", Species)
A("score", Score)
A("designatedteam", DesignatedTeam)
A("lastpush", lastpush)
A("activationtype", activationtype)
A("lastbump", lastbump)
A("painthreshold", PainThreshold)
A("damagefactor", DamageFactor)
A("damagemultiply", DamageMultiply)
A("waveindexxy", WeaveIndexXY)
A("weaveindexz", WeaveIndexZ)
A("pdmgreceived", PoisonDamageReceived)
A("pdurreceived", PoisonDurationReceived)
A("ppreceived", PoisonPeriodReceived)
("poisoner", Poisoner)
A("posiondamage", PoisonDamage)
A("poisonduration", PoisonDuration)
A("poisonperiod", PoisonPeriod)
A("poisondamagetype", PoisonDamageType)
A("poisondmgtypereceived", PoisonDamageTypeReceived)
A("conversationroot", ConversationRoot)
A("conversation", Conversation)
A("friendplayer", FriendPlayer)
A("telefogsourcetype", TeleFogSourceType)
A("telefogdesttype", TeleFogDestType)
A("ripperlevel", RipperLevel)
A("riplevelmin", RipLevelMin)
A("riplevelmax", RipLevelMax)
A("devthreshold", DefThreshold)
A("spriteangle", SpriteAngle)
A("spriterotation", SpriteRotation)
("alternative", alternative)
A("cameraheight", CameraHeight)
A("camerafov", CameraFOV)
A("tag", Tag)
A("visiblestartangle",VisibleStartAngle)
A("visibleendangle",VisibleEndAngle)
A("visiblestartpitch",VisibleStartPitch)
A("visibleendpitch",VisibleEndPitch)
A("woundhealth", WoundHealth)
A("rdfactor", RadiusDamageFactor)
A("selfdamagefactor", SelfDamageFactor)
A("stealthalpha", StealthAlpha)
A("renderhidden", RenderHidden)
A("renderrequired", RenderRequired)
A("friendlyseeblocks", friendlyseeblocks)
A("spawntime", SpawnTime)
A("spawnorder", SpawnOrder)
A("friction", Friction)
A("userlights", UserLights);
}
#undef A
//==========================================================================
//
// This must be done after the world is set up.
//
//==========================================================================
void AActor::PostSerialize()
{
touching_sectorlist = nullptr;
touching_rendersectors = nullptr;
LinkToWorld(nullptr, false, Sector);
AddToHash();
if (player)
{
if (Level->PlayerInGame(player) &&
player->cls != NULL &&
!(flags4 & MF4_NOSKIN) &&
state->sprite == GetDefaultByType(player->cls)->SpawnState->sprite)
{ // Give player back the skin
sprite = Skins[player->userinfo.GetSkin()].sprite;
}
if (Speed == 0)
{
Speed = GetDefault()->Speed;
}
}
ClearInterpolation();
UpdateWaterLevel(false);
}
AActor &AActor::operator= (const AActor &other)
{
memcpy (&snext, &other.snext, (uint8_t *)&this[1] - (uint8_t *)&snext);
return *this;
}
//==========================================================================
//
// AActor::InStateSequence
//
// Checks whether the current state is in a contiguous sequence that
// starts with basestate
//
//==========================================================================
static int InStateSequence(FState * newstate, FState * basestate)
{
if (basestate == NULL) return false;
FState * thisstate = basestate;
do
{
if (newstate == thisstate) return true;
basestate = thisstate;
thisstate = thisstate->GetNextState();
}
while (thisstate == basestate+1);
return false;
}
DEFINE_ACTION_FUNCTION_NATIVE(AActor, InStateSequence, InStateSequence)
{
PARAM_PROLOGUE;
PARAM_POINTER(newstate, FState);
PARAM_POINTER(basestate, FState);
ACTION_RETURN_BOOL(InStateSequence(newstate, basestate));
}
DEFINE_ACTION_FUNCTION_NATIVE(FState, InStateSequence, InStateSequence)
{
PARAM_SELF_STRUCT_PROLOGUE(FState);
PARAM_POINTER(basestate, FState);
ACTION_RETURN_BOOL(InStateSequence(self, basestate));
}
bool AActor::IsMapActor()
{
// [SP] Don't remove owned inventory objects.
return (!IsKindOf(NAME_Inventory) || GC::ReadBarrier(PointerVar<AActor>(NAME_Owner)) == nullptr);
}
//==========================================================================
//
// AActor::GetTics
//
// Get the actual duration of the next state
// We are using a state flag now to indicate a state that should be
// accelerated in Fast mode or slowed in Slow mode.
//
//==========================================================================
int AActor::GetTics(FState * newstate)
{
int tics = newstate->GetTics();
if (isFast() && newstate->GetFast())
{
return tics - (tics>>1);
}
else if (isSlow() && newstate->GetSlow())
{
return tics<<1;
}
return tics;
}
//==========================================================================
//
// AActor::SetState
//
// Returns true if the mobj is still present.
//
//==========================================================================
bool AActor::SetState (FState *newstate, bool nofunction)
{
if (debugfile && player && (player->cheats & CF_PREDICTING))
fprintf (debugfile, "for pl %d: SetState while predicting!\n", Level->PlayerNum(player));
do
{
if (newstate == NULL)
{
state = NULL;
Destroy ();
return false;
}
int prevsprite, newsprite;
if (state != NULL)
{
prevsprite = state->sprite;
}
else
{
prevsprite = -1;
}
if (!(newstate->UseFlags & SUF_ACTOR))
{
Printf(TEXTCOLOR_RED "State %s in %s not flagged for use as an actor sprite\n", FState::StaticGetStateName(newstate).GetChars(), GetClass()->TypeName.GetChars());
state = nullptr;
Destroy();
return false;
}
state = newstate;
tics = GetTics(newstate);
renderflags = (renderflags & ~RF_FULLBRIGHT) | ActorRenderFlags::FromInt (newstate->GetFullbright());
newsprite = newstate->sprite;
if (newsprite != SPR_FIXED)
{ // okay to change sprite and/or frame
if (!newstate->GetSameFrame())
{ // okay to change frame
frame = newstate->GetFrame();
}
if (newsprite != SPR_NOCHANGE)
{ // okay to change sprite
if (!(flags4 & MF4_NOSKIN) && newsprite == SpawnState->sprite)
{ // [RH] If the new sprite is the same as the original sprite, and
// this actor is attached to a player, use the player's skin's
// sprite. If a player is not attached, do not change the sprite
// unless it is different from the previous state's sprite; a
// player may have been attached, died, and respawned elsewhere,
// and we do not want to lose the skin on the body. If it wasn't
// for Dehacked, I would move sprite changing out of the states
// altogether, since actors rarely change their sprites after
// spawning.
if (player != NULL && Skins.Size() > 0)
{
sprite = Skins[player->userinfo.GetSkin()].sprite;
}
else if (newsprite != prevsprite)
{
sprite = newsprite;
}
}
else
{
sprite = newsprite;
}
}
}
if (!nofunction)
{
FState *returned_state;
FStateParamInfo stp = { newstate, STATE_Actor, PSP_WEAPON };
if (newstate->CallAction(this, this, &stp, &returned_state))
{
// Check whether the called action function resulted in destroying the actor
if (ObjectFlags & OF_EuthanizeMe)
{
return false;
}
if (returned_state != NULL)
{ // The action was an A_Jump-style function that wants to change the next state.
newstate = returned_state;
tics = 0; // make sure we loop and set the new state properly
continue;
}
}
}
newstate = newstate->GetNextState();
} while (tics == 0);
SetDynamicLights();
return true;
}
DEFINE_ACTION_FUNCTION(AActor, SetState)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_POINTER(state, FState);
PARAM_BOOL(nofunction);
ACTION_RETURN_BOOL(self->SetState(state, nofunction));
};
//============================================================================
//
// AActor :: DestroyAllInventory
//
//============================================================================
void AActor::DestroyAllInventory ()
{
AActor *inv = Inventory;
if (inv != nullptr)
{
TArray<AActor *> toDelete;
// Delete the list in a two stage approach.
// This is necessary because an item may destroy another item (e.g. sister weapons)
// which would break the list and leave parts of it undestroyed, maybe doing bad things later.
while (inv != nullptr)
{
toDelete.Push(inv);
auto item = inv->Inventory;
inv->Inventory = nullptr;
inv->PointerVar<AActor>(NAME_Owner) = nullptr;
inv = item;
}
for (auto p : toDelete)
{
// the item may already have been deleted by another one, so check this here to avoid problems.
if (!(p->ObjectFlags & OF_EuthanizeMe))
{
p->Destroy();
}
}
}
}
DEFINE_ACTION_FUNCTION(AActor, DestroyAllInventory)
{
PARAM_SELF_PROLOGUE(AActor);
self->DestroyAllInventory();
return 0;
}
//============================================================================
//
// AActor :: UseInventory
//
// Attempts to use an item. If the use succeeds, one copy of the item is
// removed from the inventory. If all copies are removed, then the item is
// destroyed.
//
//============================================================================
bool AActor::UseInventory (AActor *item)
{
IFVIRTUAL(AActor, UseInventory)
{
VMValue params[] = { this, item };
int retval = 0;
VMReturn ret(&retval);
VMCall(func, params, 2, &ret, 1);
return !!retval;
}
return false;
}
//===========================================================================
//
// AActor :: DropInventory
//
// Removes a single copy of an item and throws it out in front of the actor.
//
//===========================================================================
AActor *AActor::DropInventory (AActor *item, int amt)
{
IFVM(Actor, DropInventory)
{
VMValue params[] = { this, item, amt };
AActor *retval = 0;
VMReturn ret((void**)&retval);
VMCall(func, params, 3, &ret, 1);
return retval;
}
return nullptr;
}
//============================================================================
//
// AActor :: FindInventory
//
//============================================================================
AActor *AActor::FindInventory (PClassActor *type, bool subclass)
{
AActor *item;
if (type == NULL)
{
return NULL;
}
for (item = Inventory; item != NULL; item = item->Inventory)
{
if (!subclass)
{
if (item->GetClass() == type)
{
break;
}
}
else
{
if (item->IsKindOf(type))
{
break;
}
}
}
return item;
}
AActor *AActor::FindInventory (FName type, bool subclass)
{
return FindInventory(PClass::FindActor(type), subclass);
}
DEFINE_ACTION_FUNCTION(AActor, FindInventory)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_CLASS(type, AActor);
PARAM_BOOL(subclass);
ACTION_RETURN_OBJECT(self->FindInventory(type, subclass));
}
//============================================================================
//
// AActor :: GiveInventoryType
//
//============================================================================
AActor *AActor::GiveInventoryType (PClassActor *type)
{
if (type != nullptr)
{
auto item = Spawn (Level, type);
if (!CallTryPickup (item, this))
{
item->Destroy ();
return nullptr;
}
return item;
}
return nullptr;
}
DEFINE_ACTION_FUNCTION(AActor, GiveInventoryType)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_CLASS(type, AActor);
ACTION_RETURN_OBJECT(self->GiveInventoryType(type));
}
//============================================================================
//
// AActor :: ClearInventory
//
// Clears the inventory of a single actor.
//
//============================================================================
void AActor::ClearInventory()
{
IFVIRTUAL(AActor, ClearInventory)
{
VMValue params[] = { this };
VMCall(func, params, 1, nullptr, 0);
}
}
//============================================================================
//
// AActor :: CopyFriendliness
//
// Makes this actor hate (or like) the same things another actor does.
//
//============================================================================
void AActor::CopyFriendliness (AActor *other, bool changeTarget, bool resetHealth)
{
Level->total_monsters -= CountsAsKill();
TIDtoHate = other->TIDtoHate;
LastLookActor = other->LastLookActor;
LastLookPlayerNumber = other->LastLookPlayerNumber;
flags = (flags & ~MF_FRIENDLY) | (other->flags & MF_FRIENDLY);
flags3 = (flags3 & ~(MF3_NOSIGHTCHECK | MF3_HUNTPLAYERS)) | (other->flags3 & (MF3_NOSIGHTCHECK | MF3_HUNTPLAYERS));
flags4 = (flags4 & ~(MF4_NOHATEPLAYERS | MF4_BOSSSPAWNED)) | (other->flags4 & (MF4_NOHATEPLAYERS | MF4_BOSSSPAWNED));
FriendPlayer = other->FriendPlayer;
DesignatedTeam = other->DesignatedTeam;
if (changeTarget && other->target != NULL && !(other->target->flags3 & MF3_NOTARGET) && !(other->target->flags7 & MF7_NEVERTARGET))
{
// LastHeard must be set as well so that A_Look can react to the new target if called
LastHeard = target = other->target;
}
if (resetHealth) health = SpawnHealth();
Level->total_monsters += CountsAsKill();
}
DEFINE_ACTION_FUNCTION(AActor, CopyFriendliness)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_OBJECT_NOT_NULL(other, AActor);
PARAM_BOOL(changetarget);
PARAM_BOOL(resethealth);
self->CopyFriendliness(other, changetarget, resethealth);
return 0;
}
//---------------------------------------------------------------------------
//
// FUNC P_GetRealMaxHealth
//
// Taken out of P_GiveBody so that the bot code can also use it to decide
// whether to pick up an item or not.
//
//---------------------------------------------------------------------------
int P_GetRealMaxHealth(AActor *actor, int max)
{
// Max is 0 by default, preserving default behavior for P_GiveBody()
// calls while supporting health pickups.
auto player = actor->player;
if (max <= 0)
{
max = actor->GetMaxHealth(true);
// [MH] First step in predictable generic morph effects
if (player->morphTics)
{
if (player->MorphStyle & MORPH_FULLHEALTH)
{
if (!(player->MorphStyle & MORPH_ADDSTAMINA))
{
max -= actor->stamina + actor->IntVar(NAME_BonusHealth);
}
}
else // old health behaviour
{
max = MAXMORPHHEALTH;
if (player->MorphStyle & MORPH_ADDSTAMINA)
{
max += actor->stamina + actor->IntVar(NAME_BonusHealth);
}
}
}
}
else
{
// Bonus health should be added on top of the item's limit.
if (player->morphTics == 0 || (player->MorphStyle & MORPH_ADDSTAMINA))
{
max += actor->IntVar(NAME_BonusHealth);
}
}
return max;
}
//---------------------------------------------------------------------------
//
// FUNC P_GiveBody
//
// Returns false if the body isn't needed at all.
//
//---------------------------------------------------------------------------
bool P_GiveBody(AActor *actor, int num, int max)
{
if (actor->health <= 0 || (actor->player != NULL && actor->player->playerstate == PST_DEAD))
{ // Do not heal dead things.
return false;
}
player_t *player = actor->player;
num = clamp(num, -65536, 65536); // prevent overflows for bad values
if (player != NULL)
{
max = P_GetRealMaxHealth(player->mo, max); // do not pass voodoo dolls in here.
// [RH] For Strife: A negative value sets you up with a percentage of your full health.
if (num < 0)
{
num = max * -num / 100;
if (player->health < num)
{
player->health = num;
actor->health = num;
return true;
}
}
else if (num > 0)
{
if (player->health < max)
{
num = int(num * G_SkillProperty(SKILLP_HealthFactor));
if (num < 1) num = 1;
player->health += num;
if (player->health > max)
{
player->health = max;
}
actor->health = player->health;
return true;
}
}
}
else
{
// Parameter value for max is ignored on monsters, preserving original
// behaviour of health as well as on existing calls to P_GiveBody().
max = actor->SpawnHealth();
if (num < 0)
{
num = max * -num / 100;
if (actor->health < num)
{
actor->health = num;
return true;
}
}
else if (actor->health < max)
{
actor->health += num;
if (actor->health > max)
{
actor->health = max;
}
return true;
}
}
return false;
}
DEFINE_ACTION_FUNCTION(AActor, GiveBody)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(num);
PARAM_INT(max);
ACTION_RETURN_BOOL(P_GiveBody(self, num, max));
}
//============================================================================
//
// AActor :: CheckLocalView
//
// Returns true if this actor is local for the player. Here, local means the
// player is either looking out this actor's eyes, or this actor is the player
// and the player is looking out the eyes of something non-"sentient."
//
//============================================================================
bool AActor::CheckLocalView() const
{
auto p = Level->GetConsolePlayer();
if (p == nullptr)
{
return false;
}
if (p->camera == this)
{
return true;
}
if (p->mo != this || p->camera == nullptr)
{
return false;
}
if (p->camera->player == NULL &&
!(p->camera->flags3 & MF3_ISMONSTER))
{
return true;
}
return false;
}
DEFINE_ACTION_FUNCTION(AActor, CheckLocalView)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(cp);
ACTION_RETURN_BOOL(self->CheckLocalView());
}
//============================================================================
//
// AActor :: IsInsideVisibleAngles
//
// Returns true if this actor is within viewing angle/pitch visibility.
//
//============================================================================
bool AActor::IsInsideVisibleAngles() const
{
// Don't bother masking if not wanted.
if (!(renderflags & RF_MASKROTATION))
return true;
auto p = Level->GetConsolePlayer();
if (p == nullptr || p->camera == nullptr)
return true;
DAngle anglestart = VisibleStartAngle;
DAngle angleend = VisibleEndAngle;
DAngle pitchstart = VisibleStartPitch;
DAngle pitchend = VisibleEndPitch;