/
p_interaction.cpp
1893 lines (1682 loc) · 50.5 KB
/
p_interaction.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 1999-2016 Randy Heit
// Copyright 2002-2016 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:
// Handling interactions (i.e., collisions).
//
//-----------------------------------------------------------------------------
// Data.
#include "doomdef.h"
#include "gstrings.h"
#include "doomstat.h"
#include "m_random.h"
#include "i_system.h"
#include "announcer.h"
#include "am_map.h"
#include "c_console.h"
#include "c_dispatch.h"
#include "p_local.h"
#include "p_lnspec.h"
#include "p_effect.h"
#include "p_acs.h"
#include "b_bot.h" //Added by MC:
#include "d_player.h"
#include "gi.h"
#include "sbar.h"
#include "d_net.h"
#include "d_netinf.h"
#include "a_morph.h"
#include "vm.h"
#include "g_levellocals.h"
#include "events.h"
#include "actorinlines.h"
static FRandom pr_botrespawn ("BotRespawn");
static FRandom pr_killmobj ("ActorDie");
FRandom pr_damagemobj ("ActorTakeDamage");
static FRandom pr_lightning ("LightningDamage");
static FRandom pr_poison ("PoisonDamage");
static FRandom pr_switcher ("SwitchTarget");
CVAR (Bool, cl_showsprees, true, CVAR_ARCHIVE)
CVAR (Bool, cl_showmultikills, true, CVAR_ARCHIVE)
EXTERN_CVAR (Bool, show_obituaries)
CVAR (Float, sv_damagefactormobj, 1.0, CVAR_SERVERINFO|CVAR_CHEAT)
CVAR (Float, sv_damagefactorfriendly, 1.0, CVAR_SERVERINFO|CVAR_CHEAT)
CVAR (Float, sv_damagefactorplayer, 1.0, CVAR_SERVERINFO|CVAR_CHEAT)
//
// GET STUFF
//
//
// P_TouchSpecialThing
//
void P_TouchSpecialThing (AActor *special, AActor *toucher)
{
double delta = special->Z() - toucher->Z();
// The pickup is at or above the toucher's feet OR
// The pickup is below the toucher.
if (delta > toucher->Height || delta < MIN(-32., -special->Height))
{ // out of reach
return;
}
// Dead thing touching.
// Can happen with a sliding player corpse.
if (toucher->health <= 0)
return;
//Added by MC: Finished with this destination.
if (toucher->player != NULL && toucher->player->Bot != NULL && special == toucher->player->Bot->dest)
{
toucher->player->Bot->prev = toucher->player->Bot->dest;
toucher->player->Bot->dest = nullptr;
}
special->CallTouch (toucher);
}
// [RH]
// PronounMessage: Replace parts of strings with player-specific pronouns
//
// The following expansions are performed:
// %g -> he/she/they/it
// %h -> him/her/them/it
// %p -> his/her/their/its
// %s -> his/hers/theirs/its
// %r -> he's/she's/they're/it's
// %o -> other (victim)
// %k -> killer
//
void PronounMessage (const char *from, char *to, int pronoun, const char *victim, const char *killer)
{
static const char *pronouns[GENDER_MAX][5] =
{
{ "he", "him", "his", "his", "he's" },
{ "she", "her", "her", "hers", "she's" },
{ "they", "them", "their", "theirs", "they're" },
{ "it", "it", "its", "its'", "it's" }
};
static const int pronounshift[GENDER_MAX][5] =
{
{ 2, 3, 3, 3, 4 },
{ 3, 3, 3, 4, 5 },
{ 4, 4, 5, 6, 7 },
{ 2, 2, 3, 4, 4 }
};
const char *substitute = NULL;
do
{
if (*from != '%')
{
*to++ = *from;
}
else
{
int grammarcase = -1;
switch (from[1])
{
case 'g': grammarcase = 0; break; // Subject
case 'h': grammarcase = 1; break; // Object
case 'p': grammarcase = 2; break; // Possessive Determiner
case 's': grammarcase = 3; break; // Possessive Pronoun
case 'r': grammarcase = 4; break; // Perfective
case 'o': substitute = victim; break;
case 'k': substitute = killer; break;
}
if (substitute != nullptr)
{
size_t len = strlen (substitute);
memcpy (to, substitute, len);
to += len;
from++;
substitute = nullptr;
}
else if (grammarcase < 0)
{
*to++ = '%';
}
else
{
strcpy (to, pronouns[pronoun][grammarcase]);
to += pronounshift[pronoun][grammarcase];
from++;
}
}
} while (*from++);
}
// [RH]
// ClientObituary: Show a message when a player dies
//
void ClientObituary (AActor *self, AActor *inflictor, AActor *attacker, int dmgflags, FName MeansOfDeath)
{
FString ret;
char gendermessage[1024];
// No obituaries for non-players, voodoo dolls or when not wanted
if (self->player == nullptr || self->player->mo != self || !show_obituaries)
return;
// Treat voodoo dolls as unknown deaths
if (inflictor && inflictor->player && inflictor->player->mo != inflictor)
MeansOfDeath = NAME_None;
FName mod = MeansOfDeath;
const char *message = nullptr;
const char *messagename = nullptr;
if (attacker == nullptr || attacker->player != nullptr)
{
if (mod == NAME_Telefrag)
{
if (AnnounceTelefrag (attacker, self))
return;
}
else
{
if (AnnounceKill (attacker, self))
return;
}
}
FString obit = DamageTypeDefinition::GetObituary(mod);
if (attacker == nullptr && obit.IsNotEmpty()) messagename = obit;
else
{
switch (mod)
{
case NAME_Suicide: messagename = "$OB_SUICIDE"; break;
case NAME_Falling: messagename = "$OB_FALLING"; break;
case NAME_Crush: messagename = "$OB_CRUSH"; break;
case NAME_Exit: messagename = "$OB_EXIT"; break;
case NAME_Drowning: messagename = "$OB_WATER"; break;
case NAME_Slime: messagename = "$OB_SLIME"; break;
case NAME_Fire: messagename = "$OB_LAVA"; break;
}
}
// Check for being killed by a voodoo doll.
if (inflictor && inflictor->player && inflictor->player->mo != inflictor)
{
messagename = "$OB_VOODOO";
}
if (attacker != NULL && message == NULL)
{
if (attacker == self)
{
message = "$OB_KILLEDSELF";
}
else
{
IFVIRTUALPTR(attacker, AActor, GetObituary)
{
VMValue params[] = { attacker, self, inflictor, mod.GetIndex(), !!(dmgflags & DMG_PLAYERATTACK) };
VMReturn rett(&ret);
VMCall(func, params, countof(params), &rett, 1);
if (ret.IsNotEmpty()) message = ret;
}
}
}
if (message == nullptr) message = messagename; // fallback to defaults if possible.
if (attacker == nullptr) attacker = self; // world
if (attacker->player == nullptr) attacker = self; // for the message creation
if (message != NULL && message[0] == '$')
{
message = GStrings[message+1];
}
if (message == NULL)
{
message = GStrings("OB_DEFAULT");
}
// [CK] Don't display empty strings
if (message == NULL || strlen(message) <= 0)
return;
PronounMessage (message, gendermessage, self->player->userinfo.GetGender(),
self->player->userinfo.GetName(), attacker->player->userinfo.GetName());
Printf (PRINT_MEDIUM, "%s\n", gendermessage);
}
//
// KillMobj
//
EXTERN_CVAR (Int, fraglimit)
void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOfDeath)
{
// Handle possible unmorph on death
bool wasgibbed = (health < GetGibHealth());
{
IFVIRTUAL(AActor, MorphedDeath)
{
AActor *realthis = NULL;
int realstyle = 0;
int realhealth = 0;
VMValue params[] = { this };
VMReturn returns[3];
returns[0].PointerAt((void**)&realthis);
returns[1].IntAt(&realstyle);
returns[2].IntAt(&realhealth);
VMCall(func, params, 1, returns, 3);
if (realthis && !(realstyle & MORPH_UNDOBYDEATHSAVES))
{
if (wasgibbed)
{
int realgibhealth = realthis->GetGibHealth();
if (realthis->health >= realgibhealth)
{
realthis->health = realgibhealth - 1; // if morphed was gibbed, so must original be (where allowed)l
}
}
realthis->CallDie(source, inflictor, dmgflags, MeansOfDeath);
}
}
}
// [SO] 9/2/02 -- It's rather funny to see an exploded player body with the invuln sparkle active :)
effects &= ~FX_RESPAWNINVUL;
//flags &= ~MF_INVINCIBLE;
// [RH] Notify this actor's items.
for (AActor *item = Inventory; item != NULL; )
{
AActor *next = item->Inventory;
IFVIRTUALPTRNAME(item, NAME_Inventory, OwnerDied)
{
VMValue params[1] = { item };
VMCall(func, params, 1, nullptr, 0);
}
item = next;
}
if (flags & MF_MISSILE)
{ // [RH] When missiles die, they just explode
P_ExplodeMissile (this, NULL, NULL);
return;
}
// [RH] Set the target to the thing that killed it. Strife apparently does this.
if (source != NULL)
{
target = source;
}
// [ZZ] Fire WorldThingDied script hook.
Level->localEventManager->WorldThingDied(this, inflictor);
// [JM] Fire KILL type scripts for actor. Not needed for players, since they have the "DEATH" script type.
if (!player && !(flags7 & MF7_NOKILLSCRIPTS) && ((flags7 & MF7_USEKILLSCRIPTS) || gameinfo.forcekillscripts))
{
Level->Behaviors.StartTypedScripts(SCRIPT_Kill, this, true, 0, true);
}
flags &= ~(MF_SHOOTABLE|MF_FLOAT|MF_SKULLFLY);
if (!(flags4 & MF4_DONTFALL)) flags&=~MF_NOGRAVITY;
flags |= MF_DROPOFF;
if ((flags3 & MF3_ISMONSTER) || FindState(NAME_Raise) != NULL || IsKindOf(NAME_PlayerPawn))
{ // [RH] Only monsters get to be corpses.
// Objects with a raise state should get the flag as well so they can
// be revived by an Arch-Vile. Batman Doom needs this.
// [RC] And disable this if DONTCORPSE is set, of course.
if(!(flags6 & MF6_DONTCORPSE)) flags |= MF_CORPSE;
}
flags6 |= MF6_KILLED;
IFVIRTUAL(AActor, GetDeathHeight)
{
VMValue params[] = { (DObject*)this };
VMReturn ret(&Height);
VMCall(func, params, 1, &ret, 1);
}
// [RH] If the thing has a special, execute and remove it
// Note that the thing that killed it is considered
// the activator of the script.
// New: In Hexen, the thing that died is the activator,
// so now a level flag selects who the activator gets to be.
// Everything is now moved to P_ActivateThingSpecial().
if (special && (!(flags & MF_SPECIAL) || (flags3 & MF3_ISMONSTER))
&& !(activationtype & THINGSPEC_NoDeathSpecial))
{
P_ActivateThingSpecial(this, source, true);
}
if (CountsAsKill())
Level->killed_monsters++;
if (source && source->player)
{
if (CountsAsKill())
{ // count for intermission
source->player->killcount++;
}
// Don't count any frags at level start, because they're just telefrags
// resulting from insufficient deathmatch starts, and it wouldn't be
// fair to count them toward a player's score.
if (player && Level->maptime)
{
source->player->frags[Level->PlayerNum(player)]++;
if (player == source->player) // [RH] Cumulative frag count
{
char buff[256];
player->fragcount--;
if (deathmatch && player->spreecount >= 5 && cl_showsprees)
{
PronounMessage (GStrings("SPREEKILLSELF"), buff,
player->userinfo.GetGender(), player->userinfo.GetName(),
player->userinfo.GetName());
StatusBar->AttachMessage (Create<DHUDMessageFadeOut>(SmallFont, buff,
1.5f, 0.2f, 0, 0, CR_WHITE, 3.f, 0.5f), MAKE_ID('K','S','P','R'));
}
}
else
{
if ((dmflags2 & DF2_YES_LOSEFRAG) && deathmatch)
player->fragcount--;
if (this->IsTeammate(source))
{
source->player->fragcount--;
}
else
{
++source->player->fragcount;
++source->player->spreecount;
}
if (source->player->morphTics)
{ // Make a super chicken
source->GiveInventoryType (PClass::FindActor(NAME_PowerWeaponLevel2));
}
if (deathmatch && cl_showsprees)
{
const char *spreemsg;
char buff[256];
switch (source->player->spreecount)
{
case 5:
spreemsg = GStrings("SPREE5");
break;
case 10:
spreemsg = GStrings("SPREE10");
break;
case 15:
spreemsg = GStrings("SPREE15");
break;
case 20:
spreemsg = GStrings("SPREE20");
break;
case 25:
spreemsg = GStrings("SPREE25");
break;
default:
spreemsg = NULL;
break;
}
if (spreemsg == NULL && player->spreecount >= 5)
{
if (!AnnounceSpreeLoss (this))
{
PronounMessage (GStrings("SPREEOVER"), buff, player->userinfo.GetGender(),
player->userinfo.GetName(), source->player->userinfo.GetName());
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (SmallFont, buff,
1.5f, 0.2f, 0, 0, CR_WHITE, 3.f, 0.5f), MAKE_ID('K','S','P','R'));
}
}
else if (spreemsg != NULL)
{
if (!AnnounceSpree (source))
{
PronounMessage (spreemsg, buff, player->userinfo.GetGender(),
player->userinfo.GetName(), source->player->userinfo.GetName());
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (SmallFont, buff,
1.5f, 0.2f, 0, 0, CR_WHITE, 3.f, 0.5f), MAKE_ID('K','S','P','R'));
}
}
}
}
// [RH] Multikills
if (player != source->player)
{
source->player->multicount++;
if (source->player->lastkilltime > 0)
{
if (source->player->lastkilltime < Level->time - 3*TICRATE)
{
source->player->multicount = 1;
}
if (deathmatch &&
source->CheckLocalView() &&
cl_showmultikills)
{
const char *multimsg;
switch (source->player->multicount)
{
case 1:
multimsg = NULL;
break;
case 2:
multimsg = GStrings("MULTI2");
break;
case 3:
multimsg = GStrings("MULTI3");
break;
case 4:
multimsg = GStrings("MULTI4");
break;
default:
multimsg = GStrings("MULTI5");
break;
}
if (multimsg != NULL)
{
char buff[256];
if (!AnnounceMultikill (source))
{
PronounMessage (multimsg, buff, player->userinfo.GetGender(),
player->userinfo.GetName(), source->player->userinfo.GetName());
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (SmallFont, buff,
1.5f, 0.8f, 0, 0, CR_RED, 3.f, 0.5f), MAKE_ID('M','K','I','L'));
}
}
}
}
source->player->lastkilltime = Level->time;
}
// [RH] Implement fraglimit
if (deathmatch && fraglimit &&
fraglimit <= D_GetFragCount (source->player))
{
Printf ("%s\n", GStrings("TXT_FRAGLIMIT"));
Level->ExitLevel (0, false);
}
}
}
else if (!multiplayer && CountsAsKill() && Level->isPrimaryLevel())
{
// count all monster deaths,
// even those caused by other monsters
Level->Players[0]->killcount++;
}
if (player)
{
// [RH] Death messages
ClientObituary (this, inflictor, source, dmgflags, MeansOfDeath);
// [ZZ] fire player death hook
Level->localEventManager->PlayerDied(Level->PlayerNum(player));
// Death script execution, care of Skull Tag
Level->Behaviors.StartTypedScripts (SCRIPT_Death, this, true);
// [RH] Force a delay between death and respawn
player->respawn_time = Level->time + TICRATE;
//Added by MC: Respawn bots
if (Level->BotInfo.botnum && !demoplayback)
{
if (player->Bot != NULL)
player->Bot->t_respawn = (pr_botrespawn()%15)+((Level->BotInfo.botnum-1)*2)+TICRATE+1;
//Added by MC: Discard enemies.
for (int i = 0; i < MAXPLAYERS; i++)
{
DBot *Bot = Level->Players[i]->Bot;
if (Bot != nullptr && this == Bot->enemy)
{
if (Bot->dest == Bot->enemy)
Bot->dest = nullptr;
Bot->enemy = nullptr;
}
}
player->spreecount = 0;
player->multicount = 0;
}
// count environment kills against you
if (!source)
{
player->frags[Level->PlayerNum(player)]++;
player->fragcount--; // [RH] Cumulative frag count
}
flags &= ~MF_SOLID;
player->playerstate = PST_DEAD;
IFVM(PlayerPawn, DropWeapon)
{
VMValue param = player->mo;
VMCall(func, ¶m, 1, nullptr, 0);
}
if (Level->isCamera(this) && automapactive)
{
// don't die in auto map, switch view prior to dying
AM_Stop ();
}
// [GRB] Clear extralight. When you killed yourself with weapon that
// called A_Light1/2 before it called A_Light0, extraligh remained.
player->extralight = 0;
}
// [RH] If this is the unmorphed version of another monster, destroy this
// actor, because the morphed version is the one that will stick around.
if (flags & MF_UNMORPHED)
{
Destroy ();
return;
}
FState *diestate = NULL;
int gibhealth = GetGibHealth();
ActorFlags4 iflags4 = inflictor == NULL ? ActorFlags4::FromInt(0) : inflictor->flags4;
bool extremelydead = ((health < gibhealth || iflags4 & MF4_EXTREMEDEATH) && !(iflags4 & MF4_NOEXTREMEDEATH));
// Special check for 'extreme' damage type to ensure that it gets recorded properly as an extreme death for subsequent checks.
if (DamageType == NAME_Extreme)
{
extremelydead = true;
DamageType = NAME_None;
}
// find the appropriate death state. The order is:
//
// 1. If damagetype is not 'none' and death is extreme, try a damage type specific extreme death state
// 2. If no such state is found or death is not extreme try a damage type specific normal death state
// 3. If damagetype is 'ice' and actor is a monster or player, try the generic freeze death (unless prohibited)
// 4. If no state has been found and death is extreme, try the extreme death state
// 5. If no such state is found or death is not extreme try the regular death state.
// 6. If still no state has been found, destroy the actor immediately.
if (DamageType != NAME_None)
{
if (extremelydead)
{
FName labels[] = { NAME_Death, NAME_Extreme, DamageType };
diestate = FindState(3, labels, true);
}
if (diestate == NULL)
{
diestate = FindState (NAME_Death, DamageType, true);
if (diestate != NULL) extremelydead = false;
}
if (diestate == NULL)
{
if (DamageType == NAME_Ice)
{ // If an actor doesn't have an ice death, we can still give them a generic one.
if (!deh.NoAutofreeze && !(flags4 & MF4_NOICEDEATH) && (player || (flags3 & MF3_ISMONSTER)))
{
diestate = FindState(NAME_GenericFreezeDeath);
extremelydead = false;
}
}
}
}
if (diestate == NULL)
{
// Don't pass on a damage type this actor cannot handle.
// (most importantly, prevent barrels from passing on ice damage.)
// Massacre must be preserved though.
if (DamageType != NAME_Massacre)
{
DamageType = NAME_None;
}
if (extremelydead)
{ // Extreme death
diestate = FindState (NAME_Death, NAME_Extreme, true);
}
if (diestate == NULL)
{ // Normal death
extremelydead = false;
diestate = FindState (NAME_Death);
}
}
if (extremelydead)
{
// We'll only get here if an actual extreme death state was used.
// For players, mark the appropriate flag.
if (player != NULL)
{
player->cheats |= CF_EXTREMELYDEAD;
}
// If a non-player, mark as extremely dead for the crash state.
else if (health >= gibhealth)
{
health = gibhealth - 1;
}
}
if (diestate != NULL)
{
SetState (diestate);
if (tics > 1)
{
tics -= pr_killmobj() & 3;
if (tics < 1)
tics = 1;
}
}
// The following condition is needed to avoid crash when player class has no death states
// Instance of player pawn will be garbage collected on reloading of level
else if (player == nullptr)
{
Destroy();
}
}
DEFINE_ACTION_FUNCTION(AActor, Die)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_OBJECT(source, AActor);
PARAM_OBJECT(inflictor, AActor);
PARAM_INT(dmgflags);
PARAM_NAME(MeansOfDeath);
self->Die(source, inflictor, dmgflags, MeansOfDeath);
return 0;
}
void AActor::CallDie(AActor *source, AActor *inflictor, int dmgflags, FName MeansOfDeath)
{
IFVIRTUAL(AActor, Die)
{
VMValue params[] = { (DObject*)this, source, inflictor, dmgflags, MeansOfDeath.GetIndex() };
VMCall(func, params, 5, nullptr, 0);
}
else return Die(source, inflictor, dmgflags, MeansOfDeath);
}
//---------------------------------------------------------------------------
//
// PROC P_AutoUseHealth
//
//---------------------------------------------------------------------------
void P_AutoUseHealth(player_t *player, int saveHealth)
{
IFVM(PlayerPawn, AutoUseHealth)
{
VMValue params[] = { player->mo, saveHealth };
VMCall(func, params, 2, nullptr, 0);
}
}
//============================================================================
//
// P_AutoUseStrifeHealth
//
//============================================================================
CVAR(Bool, sv_disableautohealth, false, CVAR_ARCHIVE|CVAR_SERVERINFO)
void P_AutoUseStrifeHealth (player_t *player)
{
IFVM(PlayerPawn, AutoUseStrifeHealth)
{
VMValue params[] = { player->mo };
VMCall(func, params, 1, nullptr, 0);
}
}
//==========================================================================
//
// ReactToDamage
//
//==========================================================================
static bool TriggerPainChance(AActor *target, FName mod, bool forcedPain, bool zscript);
static inline bool MustForcePain(AActor *target, AActor *inflictor)
{
return (inflictor && (inflictor->flags6 & MF6_FORCEPAIN));
}
static inline bool isFakePain(AActor *target, AActor *inflictor, int damage)
{
return (((target->flags7 & MF7_ALLOWPAIN || target->flags5 & MF5_NODAMAGE) && damage > 0) ||
(inflictor && (inflictor->flags7 & MF7_CAUSEPAIN)));
}
// [MC] Completely ripped out of DamageMobj to make it less messy.
static void ReactToDamage(AActor *target, AActor *inflictor, AActor *source, int damage, FName mod, int flags, int originaldamage)
{
bool justhit = false;
int painchance = 0;
FState *woundstate = nullptr;
bool fakedPain = false;
bool forcedPain = false;
bool noPain = false;
// Dead or non-existent entity, do not react. Especially if the damage is cancelled.
if (target == nullptr || target->health < 1 || damage < 0)
return;
player_t *player = target->player;
if (player)
{
if ((player->cheats & CF_GODMODE2) || (player->mo->flags5 & MF5_NOPAIN) ||
((player->cheats & CF_GODMODE) && damage < TELEFRAG_DAMAGE))
return;
}
noPain = (flags & DMG_NO_PAIN) || (target->flags5 & MF5_NOPAIN) || (inflictor && (inflictor->flags5 & MF5_PAINLESS));
// Are we attempting to cause pain?
if (!noPain)
{
fakedPain = (isFakePain(target, inflictor, originaldamage));
forcedPain = (MustForcePain(target, inflictor));
}
// [MC] No forced or faked pain so skip it.
// However the rest of the function must carry on.
if (!noPain && damage < 1 && !fakedPain && !forcedPain)
noPain = true;
woundstate = target->FindState(NAME_Wound, mod);
if (woundstate != NULL)
{
int woundhealth = target->WoundHealth;
if (target->health <= woundhealth)
{
target->SetState(woundstate);
return;
}
}
if (!noPain &&
((target->player != nullptr || !G_SkillProperty(SKILLP_NoPain)) && !(target->flags & MF_SKULLFLY))
&& damage >= target->PainThreshold)
{
if (inflictor && inflictor->PainType != NAME_None)
mod = inflictor->PainType;
// Not called from ZScript.
justhit = TriggerPainChance(target, mod, forcedPain, false);
}
if (target->player == nullptr) target->reactiontime = 0; // we're awake now...
if (source)
{
if (source == target->target)
{
target->threshold = target->DefThreshold;
if (target->state == target->SpawnState && target->SeeState != NULL)
{
target->SetState(target->SeeState);
}
}
else if (source != target->target && target->CallOkayToSwitchTarget(source))
{
// Target actor is not intent on another actor,
// so make him chase after source
// killough 2/15/98: remember last enemy, to prevent
// sleeping early; 2/21/98: Place priority on players
if (target->lastenemy == NULL ||
(target->lastenemy->player == NULL && target->TIDtoHate == 0) ||
target->lastenemy->health <= 0)
{
target->lastenemy = target->target; // remember last enemy - killough
}
target->target = source;
target->threshold = target->DefThreshold;
if (target->state == target->SpawnState && target->SeeState != NULL)
{
target->SetState(target->SeeState);
}
}
}
// killough 11/98: Don't attack a friend, unless hit by that friend.
if (justhit && (target->target == source || !target->target || !target->IsFriend(target->target)))
target->flags |= MF_JUSTHIT; // fight back!
}
static bool TriggerPainChance(AActor *target, FName mod = NAME_None, bool forcedPain = false, bool zscript = false)
{
if (target == nullptr || target->flags5 & MF5_NOPAIN || target->health < 1)
return false;
bool justhit = false, flinched = false;
int painchance = target->PainChance;
for (auto & pc : target->GetInfo()->PainChances)
{
if (pc.first == mod)
{
painchance = pc.second;
break;
}
}
if (forcedPain || (pr_damagemobj() < painchance))
{
if (mod == NAME_Electric)
{
if (pr_lightning() < 96)
{
justhit = true;
FState *painstate = target->FindState(NAME_Pain, mod);
if (painstate != NULL)
{
flinched = true;
target->SetState(painstate);
}
}
else
{ // "electrocute" the target
target->renderflags |= RF_FULLBRIGHT;
if ((target->flags3 & MF3_ISMONSTER) && pr_lightning() < 128)
{
target->Howl();
}
}
}
else
{
justhit = true;
FState *painstate = target->FindState(NAME_Pain, mod);
if (painstate != NULL)
{
flinched = true;
target->SetState(painstate);
}
if (mod == NAME_PoisonCloud)
{
if ((target->flags3 & MF3_ISMONSTER) && pr_poison() < 128)
{
target->Howl();
}
}
}
}
return (zscript) ? flinched : justhit;
}
// TriggerPainChance directly from DECORATE/ZScript will return if the
// entity flinched or not.
DEFINE_ACTION_FUNCTION(AActor, TriggerPainChance)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_NAME(mod);
PARAM_BOOL(forcedPain);
ACTION_RETURN_BOOL(TriggerPainChance(self, mod, forcedPain, true));
}
/*
=================
=
= P_DamageMobj
=
= Damages both enemies and players
= inflictor is the thing that caused the damage
= creature or missile, can be NULL (slime, etc)
= source is the thing to target after taking damage
= creature or NULL
= Source and inflictor are the same for melee attacks
= source can be null for barrel explosions and other environmental stuff
==================
*/
//===========================================================================
//
//
//
//===========================================================================
static int hasBuddha(player_t *player)
{
if (player->playerstate == PST_DEAD) return 0;
if (player->cheats & CF_BUDDHA2) return 2;
if ((player->cheats & CF_BUDDHA) ||
(player->mo->flags7 & MF7_BUDDHA) ||
player->mo->FindInventory(PClass::FindActor(NAME_PowerBuddha), true) != nullptr) return 1;