2016-01-17 18:09:05 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// Copyright 1993-1996 id Software
|
|
|
|
// Copyright 1994-1996 Raven Software
|
|
|
|
// Copyright 1999-2016 Randy Heit
|
|
|
|
// Copyright 2002-2016 Christoph Oelckers
|
2016-01-17 18:09:05 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// 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.
|
2016-01-17 18:09:05 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
2016-01-17 18:09:05 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-04-17 11:33:19 +00:00
|
|
|
// 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/
|
2016-01-17 18:09:05 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-01-17 18:09:05 +00:00
|
|
|
//
|
|
|
|
// 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:
|
|
|
|
|
2016-03-28 20:20:25 +00:00
|
|
|
#include "d_player.h"
|
2016-01-17 18:09:05 +00:00
|
|
|
#include "gi.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "d_net.h"
|
|
|
|
#include "d_netinf.h"
|
2016-02-15 01:14:34 +00:00
|
|
|
#include "a_morph.h"
|
2017-04-12 23:12:04 +00:00
|
|
|
#include "vm.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2017-01-31 00:07:00 +00:00
|
|
|
#include "events.h"
|
2017-03-11 18:18:31 +00:00
|
|
|
#include "actorinlines.h"
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2017-07-26 17:32:45 +00:00
|
|
|
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)
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// GET STUFF
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_TouchSpecialThing
|
|
|
|
//
|
|
|
|
void P_TouchSpecialThing (AActor *special, AActor *toucher)
|
|
|
|
{
|
2016-03-26 19:59:35 +00:00
|
|
|
double delta = special->Z() - toucher->Z();
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
// The pickup is at or above the toucher's feet OR
|
|
|
|
// The pickup is below the toucher.
|
2016-03-26 19:59:35 +00:00
|
|
|
if (delta > toucher->Height || delta < MIN(-32., -special->Height))
|
2016-01-17 18:09:05 +00:00
|
|
|
{ // 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;
|
2019-01-06 08:39:35 +00:00
|
|
|
toucher->player->Bot->dest = nullptr;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2016-11-28 11:55:33 +00:00
|
|
|
special->CallTouch (toucher);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// [RH]
|
2018-10-30 20:41:04 +00:00
|
|
|
// PronounMessage: Replace parts of strings with player-specific pronouns
|
2016-01-17 18:09:05 +00:00
|
|
|
//
|
|
|
|
// The following expansions are performed:
|
2018-10-30 20:41:04 +00:00
|
|
|
// %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
|
2016-01-17 18:09:05 +00:00
|
|
|
// %o -> other (victim)
|
|
|
|
// %k -> killer
|
|
|
|
//
|
2018-10-30 20:41:04 +00:00
|
|
|
void PronounMessage (const char *from, char *to, int pronoun, const char *victim, const char *killer)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
static const char *pronouns[GENDER_MAX][5] =
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
{ "he", "him", "his", "his", "he's" },
|
|
|
|
{ "she", "her", "her", "hers", "she's" },
|
|
|
|
{ "they", "them", "their", "theirs", "they're" },
|
|
|
|
{ "it", "it", "its", "its'", "it's" }
|
2016-01-17 18:09:05 +00:00
|
|
|
};
|
2018-10-30 20:41:04 +00:00
|
|
|
static const int pronounshift[GENDER_MAX][5] =
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
{ 2, 3, 3, 3, 4 },
|
|
|
|
{ 3, 3, 3, 4, 5 },
|
|
|
|
{ 4, 4, 5, 6, 7 },
|
|
|
|
{ 2, 2, 3, 4, 4 }
|
2016-01-17 18:09:05 +00:00
|
|
|
};
|
2018-10-30 20:41:04 +00:00
|
|
|
const char *substitute = NULL;
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (*from != '%')
|
|
|
|
{
|
|
|
|
*to++ = *from;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
int grammarcase = -1;
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
switch (from[1])
|
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
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;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2018-10-30 20:41:04 +00:00
|
|
|
if (substitute != nullptr)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
size_t len = strlen (substitute);
|
|
|
|
memcpy (to, substitute, len);
|
2016-01-17 18:09:05 +00:00
|
|
|
to += len;
|
|
|
|
from++;
|
2018-10-30 20:41:04 +00:00
|
|
|
substitute = nullptr;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2018-10-30 20:41:04 +00:00
|
|
|
else if (grammarcase < 0)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
*to++ = '%';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
strcpy (to, pronouns[pronoun][grammarcase]);
|
|
|
|
to += pronounshift[pronoun][grammarcase];
|
2016-01-17 18:09:05 +00:00
|
|
|
from++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (*from++);
|
|
|
|
}
|
|
|
|
|
|
|
|
// [RH]
|
|
|
|
// ClientObituary: Show a message when a player dies
|
|
|
|
//
|
2018-04-23 19:26:05 +00:00
|
|
|
void ClientObituary (AActor *self, AActor *inflictor, AActor *attacker, int dmgflags, FName MeansOfDeath)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2017-05-09 17:04:07 +00:00
|
|
|
FString ret;
|
2016-01-17 18:09:05 +00:00
|
|
|
char gendermessage[1024];
|
|
|
|
|
|
|
|
// No obituaries for non-players, voodoo dolls or when not wanted
|
2018-08-18 23:14:15 +00:00
|
|
|
if (self->player == nullptr || self->player->mo != self || !show_obituaries)
|
2016-01-17 18:09:05 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Treat voodoo dolls as unknown deaths
|
|
|
|
if (inflictor && inflictor->player && inflictor->player->mo != inflictor)
|
|
|
|
MeansOfDeath = NAME_None;
|
|
|
|
|
2018-08-18 23:14:15 +00:00
|
|
|
FName mod = MeansOfDeath;
|
|
|
|
const char *message = nullptr;
|
|
|
|
const char *messagename = nullptr;
|
2016-01-17 18:09:05 +00:00
|
|
|
|
2018-08-18 23:14:15 +00:00
|
|
|
if (attacker == nullptr || attacker->player != nullptr)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
if (mod == NAME_Telefrag)
|
|
|
|
{
|
|
|
|
if (AnnounceTelefrag (attacker, self))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (AnnounceKill (attacker, self))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-26 20:36:06 +00:00
|
|
|
FString obit = DamageTypeDefinition::GetObituary(mod);
|
2017-05-09 17:04:07 +00:00
|
|
|
if (attacker == nullptr && obit.IsNotEmpty()) messagename = obit;
|
2017-02-26 20:36:06 +00:00
|
|
|
else
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2017-02-26 20:36:06 +00:00
|
|
|
switch (mod)
|
|
|
|
{
|
2017-05-09 17:04:07 +00:00
|
|
|
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;
|
2017-02-28 13:30:14 +00:00
|
|
|
case NAME_Fire: messagename = "$OB_LAVA"; break;
|
2017-02-26 20:36:06 +00:00
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for being killed by a voodoo doll.
|
|
|
|
if (inflictor && inflictor->player && inflictor->player->mo != inflictor)
|
|
|
|
{
|
2017-02-28 13:30:14 +00:00
|
|
|
messagename = "$OB_VOODOO";
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attacker != NULL && message == NULL)
|
|
|
|
{
|
|
|
|
if (attacker == self)
|
|
|
|
{
|
2017-02-28 13:30:14 +00:00
|
|
|
message = "$OB_KILLEDSELF";
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2017-02-28 13:30:14 +00:00
|
|
|
else
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2017-02-28 13:30:14 +00:00
|
|
|
IFVIRTUALPTR(attacker, AActor, GetObituary)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2017-02-28 13:30:14 +00:00
|
|
|
VMValue params[] = { attacker, self, inflictor, mod.GetIndex(), !!(dmgflags & DMG_PLAYERATTACK) };
|
|
|
|
VMReturn rett(&ret);
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, countof(params), &rett, 1);
|
2017-02-28 13:30:14 +00:00
|
|
|
if (ret.IsNotEmpty()) message = ret;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 13:30:14 +00:00
|
|
|
if (message == nullptr) message = messagename; // fallback to defaults if possible.
|
2017-03-02 11:27:18 +00:00
|
|
|
if (attacker == nullptr) attacker = self; // world
|
2017-02-28 13:30:14 +00:00
|
|
|
if (attacker->player == nullptr) attacker = self; // for the message creation
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
if (message != NULL && message[0] == '$')
|
|
|
|
{
|
2019-03-02 11:06:24 +00:00
|
|
|
message = GStrings.GetString(message+1, nullptr, self->player->userinfo.GetGender());
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (message == NULL)
|
|
|
|
{
|
2019-08-18 16:28:09 +00:00
|
|
|
// one last thing: Synthesize a string label from the actor's class name and try to resolve that.
|
|
|
|
auto cls = attacker->GetClass()->TypeName.GetChars();
|
|
|
|
if (mod == NAME_Melee)
|
|
|
|
{
|
|
|
|
FStringf ob("DEFHITOB_%s", cls);
|
|
|
|
message = GStrings.GetString(ob, nullptr, self->player->userinfo.GetGender());
|
|
|
|
}
|
|
|
|
if (message == nullptr)
|
|
|
|
{
|
|
|
|
FStringf ob("DEFOB_%s", cls);
|
|
|
|
message = GStrings.GetString(ob, nullptr, self->player->userinfo.GetGender());
|
|
|
|
}
|
|
|
|
if (message == nullptr)
|
|
|
|
{
|
|
|
|
message = GStrings.GetString("OB_DEFAULT", nullptr, self->player->userinfo.GetGender());
|
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// [CK] Don't display empty strings
|
|
|
|
if (message == NULL || strlen(message) <= 0)
|
|
|
|
return;
|
|
|
|
|
2018-10-30 20:41:04 +00:00
|
|
|
PronounMessage (message, gendermessage, self->player->userinfo.GetGender(),
|
2016-01-17 18:09:05 +00:00
|
|
|
self->player->userinfo.GetName(), attacker->player->userinfo.GetName());
|
|
|
|
Printf (PRINT_MEDIUM, "%s\n", gendermessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// KillMobj
|
|
|
|
//
|
|
|
|
EXTERN_CVAR (Int, fraglimit)
|
|
|
|
|
2018-04-23 19:26:05 +00:00
|
|
|
void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOfDeath)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
// Handle possible unmorph on death
|
|
|
|
bool wasgibbed = (health < GetGibHealth());
|
2018-11-24 09:47:42 +00:00
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-11-24 09:47:42 +00:00
|
|
|
IFVIRTUAL(AActor, MorphedDeath)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-11-24 09:47:42 +00:00
|
|
|
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))
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-11-24 09:47:42 +00:00
|
|
|
if (wasgibbed)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-11-24 09:47:42 +00:00
|
|
|
int realgibhealth = realthis->GetGibHealth();
|
|
|
|
if (realthis->health >= realgibhealth)
|
|
|
|
{
|
|
|
|
realthis->health = realgibhealth - 1; // if morphed was gibbed, so must original be (where allowed)l
|
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2018-11-24 09:47:42 +00:00
|
|
|
realthis->CallDie(source, inflictor, dmgflags, MeansOfDeath);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2018-11-24 09:47:42 +00:00
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// [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.
|
2018-12-04 16:00:48 +00:00
|
|
|
for (AActor *item = Inventory; item != NULL; )
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-12-04 16:00:48 +00:00
|
|
|
AActor *next = item->Inventory;
|
2018-12-04 16:11:36 +00:00
|
|
|
IFVIRTUALPTRNAME(item, NAME_Inventory, OwnerDied)
|
2017-01-17 19:30:17 +00:00
|
|
|
{
|
|
|
|
VMValue params[1] = { item };
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, 1, nullptr, 0);
|
2017-01-17 19:30:17 +00:00
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
item = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & MF_MISSILE)
|
|
|
|
{ // [RH] When missiles die, they just explode
|
2019-09-09 13:41:09 +00:00
|
|
|
P_ExplodeMissile (this, NULL, NULL, false, MeansOfDeath);
|
2016-01-17 18:09:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// [RH] Set the target to the thing that killed it. Strife apparently does this.
|
|
|
|
if (source != NULL)
|
|
|
|
{
|
|
|
|
target = source;
|
|
|
|
}
|
|
|
|
|
2017-01-31 00:07:00 +00:00
|
|
|
// [ZZ] Fire WorldThingDied script hook.
|
2019-02-02 15:43:11 +00:00
|
|
|
Level->localEventManager->WorldThingDied(this, inflictor);
|
2017-01-31 00:07:00 +00:00
|
|
|
|
2016-07-23 08:21:04 +00:00
|
|
|
// [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))
|
|
|
|
{
|
2019-01-27 16:35:50 +00:00
|
|
|
Level->Behaviors.StartTypedScripts(SCRIPT_Kill, this, true, 0, true);
|
2016-07-23 08:21:04 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
flags &= ~(MF_SHOOTABLE|MF_FLOAT|MF_SKULLFLY);
|
|
|
|
if (!(flags4 & MF4_DONTFALL)) flags&=~MF_NOGRAVITY;
|
|
|
|
flags |= MF_DROPOFF;
|
2019-01-03 21:05:49 +00:00
|
|
|
if ((flags3 & MF3_ISMONSTER) || FindState(NAME_Raise) != NULL || IsKindOf(NAME_PlayerPawn))
|
2016-01-17 18:09:05 +00:00
|
|
|
{ // [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;
|
|
|
|
|
2017-02-28 12:40:46 +00:00
|
|
|
IFVIRTUAL(AActor, GetDeathHeight)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2017-02-28 12:40:46 +00:00
|
|
|
VMValue params[] = { (DObject*)this };
|
|
|
|
VMReturn ret(&Height);
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, 1, &ret, 1);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// [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())
|
2019-01-27 16:35:50 +00:00
|
|
|
Level->killed_monsters++;
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
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.
|
2019-01-27 16:35:50 +00:00
|
|
|
if (player && Level->maptime)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2019-02-01 16:31:11 +00:00
|
|
|
source->player->frags[Level->PlayerNum(player)]++;
|
2016-01-17 18:09:05 +00:00
|
|
|
if (player == source->player) // [RH] Cumulative frag count
|
|
|
|
{
|
|
|
|
char buff[256];
|
|
|
|
|
|
|
|
player->fragcount--;
|
|
|
|
if (deathmatch && player->spreecount >= 5 && cl_showsprees)
|
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
PronounMessage (GStrings("SPREEKILLSELF"), buff,
|
2016-01-17 18:09:05 +00:00
|
|
|
player->userinfo.GetGender(), player->userinfo.GetName(),
|
|
|
|
player->userinfo.GetName());
|
2019-04-09 22:28:40 +00:00
|
|
|
StatusBar->AttachMessage (Create<DHUDMessageFadeOut>(nullptr, buff,
|
2016-01-17 18:09:05 +00:00
|
|
|
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
|
2017-01-15 22:21:38 +00:00
|
|
|
source->GiveInventoryType (PClass::FindActor(NAME_PowerWeaponLevel2));
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
PronounMessage (GStrings("SPREEOVER"), buff, player->userinfo.GetGender(),
|
2016-01-17 18:09:05 +00:00
|
|
|
player->userinfo.GetName(), source->player->userinfo.GetName());
|
2019-04-09 22:28:40 +00:00
|
|
|
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (nullptr, buff,
|
2016-01-17 18:09:05 +00:00
|
|
|
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))
|
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
PronounMessage (spreemsg, buff, player->userinfo.GetGender(),
|
2016-01-17 18:09:05 +00:00
|
|
|
player->userinfo.GetName(), source->player->userinfo.GetName());
|
2019-04-09 22:28:40 +00:00
|
|
|
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (nullptr, buff,
|
2016-01-17 18:09:05 +00:00
|
|
|
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)
|
|
|
|
{
|
2019-01-27 16:35:50 +00:00
|
|
|
if (source->player->lastkilltime < Level->time - 3*TICRATE)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
source->player->multicount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deathmatch &&
|
2019-01-31 02:29:25 +00:00
|
|
|
source->CheckLocalView() &&
|
2016-01-17 18:09:05 +00:00
|
|
|
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))
|
|
|
|
{
|
2018-10-30 20:41:04 +00:00
|
|
|
PronounMessage (multimsg, buff, player->userinfo.GetGender(),
|
2016-01-17 18:09:05 +00:00
|
|
|
player->userinfo.GetName(), source->player->userinfo.GetName());
|
2019-04-09 22:28:40 +00:00
|
|
|
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (nullptr, buff,
|
2016-01-17 18:09:05 +00:00
|
|
|
1.5f, 0.8f, 0, 0, CR_RED, 3.f, 0.5f), MAKE_ID('M','K','I','L'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-27 16:35:50 +00:00
|
|
|
source->player->lastkilltime = Level->time;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Implement fraglimit
|
|
|
|
if (deathmatch && fraglimit &&
|
|
|
|
fraglimit <= D_GetFragCount (source->player))
|
|
|
|
{
|
|
|
|
Printf ("%s\n", GStrings("TXT_FRAGLIMIT"));
|
2019-01-29 22:45:14 +00:00
|
|
|
Level->ExitLevel (0, false);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-30 00:15:32 +00:00
|
|
|
else if (!multiplayer && CountsAsKill() && Level->isPrimaryLevel())
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
// count all monster deaths,
|
|
|
|
// even those caused by other monsters
|
2019-01-30 00:15:32 +00:00
|
|
|
Level->Players[0]->killcount++;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (player)
|
|
|
|
{
|
|
|
|
// [RH] Death messages
|
2018-04-23 19:26:05 +00:00
|
|
|
ClientObituary (this, inflictor, source, dmgflags, MeansOfDeath);
|
2016-01-17 18:09:05 +00:00
|
|
|
|
2017-02-02 18:46:10 +00:00
|
|
|
// [ZZ] fire player death hook
|
2019-02-02 15:43:11 +00:00
|
|
|
Level->localEventManager->PlayerDied(Level->PlayerNum(player));
|
2017-02-02 18:46:10 +00:00
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
// Death script execution, care of Skull Tag
|
2019-01-27 16:35:50 +00:00
|
|
|
Level->Behaviors.StartTypedScripts (SCRIPT_Death, this, true);
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
// [RH] Force a delay between death and respawn
|
2019-01-27 16:35:50 +00:00
|
|
|
player->respawn_time = Level->time + TICRATE;
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
//Added by MC: Respawn bots
|
2019-01-30 00:38:18 +00:00
|
|
|
if (Level->BotInfo.botnum && !demoplayback)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
if (player->Bot != NULL)
|
2019-01-30 00:38:18 +00:00
|
|
|
player->Bot->t_respawn = (pr_botrespawn()%15)+((Level->BotInfo.botnum-1)*2)+TICRATE+1;
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
//Added by MC: Discard enemies.
|
|
|
|
for (int i = 0; i < MAXPLAYERS; i++)
|
|
|
|
{
|
2019-01-30 00:15:32 +00:00
|
|
|
DBot *Bot = Level->Players[i]->Bot;
|
|
|
|
if (Bot != nullptr && this == Bot->enemy)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2019-01-30 00:15:32 +00:00
|
|
|
if (Bot->dest == Bot->enemy)
|
|
|
|
Bot->dest = nullptr;
|
|
|
|
Bot->enemy = nullptr;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player->spreecount = 0;
|
|
|
|
player->multicount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// count environment kills against you
|
|
|
|
if (!source)
|
|
|
|
{
|
2019-02-01 16:31:11 +00:00
|
|
|
player->frags[Level->PlayerNum(player)]++;
|
2016-01-17 18:09:05 +00:00
|
|
|
player->fragcount--; // [RH] Cumulative frag count
|
|
|
|
}
|
|
|
|
|
|
|
|
flags &= ~MF_SOLID;
|
|
|
|
player->playerstate = PST_DEAD;
|
2018-11-24 17:21:40 +00:00
|
|
|
|
|
|
|
IFVM(PlayerPawn, DropWeapon)
|
|
|
|
{
|
|
|
|
VMValue param = player->mo;
|
|
|
|
VMCall(func, ¶m, 1, nullptr, 0);
|
|
|
|
}
|
|
|
|
|
2019-02-01 16:02:10 +00:00
|
|
|
if (Level->isCamera(this) && automapactive)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
// 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
|
2019-01-27 16:35:50 +00:00
|
|
|
// actor, because the morphed version is the one that will stick around.
|
2016-01-17 18:09:05 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-06-05 08:06:31 +00:00
|
|
|
// 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)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-26 00:14:47 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, Die)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
|
|
|
PARAM_OBJECT(source, AActor);
|
|
|
|
PARAM_OBJECT(inflictor, AActor);
|
2018-11-17 09:03:40 +00:00
|
|
|
PARAM_INT(dmgflags);
|
|
|
|
PARAM_NAME(MeansOfDeath);
|
2018-04-23 19:26:05 +00:00
|
|
|
self->Die(source, inflictor, dmgflags, MeansOfDeath);
|
2016-11-26 00:14:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
|
2018-04-23 19:26:05 +00:00
|
|
|
void AActor::CallDie(AActor *source, AActor *inflictor, int dmgflags, FName MeansOfDeath)
|
2016-11-26 00:14:47 +00:00
|
|
|
{
|
|
|
|
IFVIRTUAL(AActor, Die)
|
|
|
|
{
|
2018-04-23 19:26:05 +00:00
|
|
|
VMValue params[] = { (DObject*)this, source, inflictor, dmgflags, MeansOfDeath.GetIndex() };
|
|
|
|
VMCall(func, params, 5, nullptr, 0);
|
2016-11-26 00:14:47 +00:00
|
|
|
}
|
2018-04-23 19:26:05 +00:00
|
|
|
else return Die(source, inflictor, dmgflags, MeansOfDeath);
|
2016-11-26 00:14:47 +00:00
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_AutoUseHealth
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_AutoUseHealth(player_t *player, int saveHealth)
|
|
|
|
{
|
2018-12-02 18:45:45 +00:00
|
|
|
IFVM(PlayerPawn, AutoUseHealth)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-12-02 18:45:45 +00:00
|
|
|
VMValue params[] = { player->mo, saveHealth };
|
|
|
|
VMCall(func, params, 2, nullptr, 0);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// P_AutoUseStrifeHealth
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
CVAR(Bool, sv_disableautohealth, false, CVAR_ARCHIVE|CVAR_SERVERINFO)
|
|
|
|
|
|
|
|
void P_AutoUseStrifeHealth (player_t *player)
|
|
|
|
{
|
2018-12-02 18:45:45 +00:00
|
|
|
IFVM(PlayerPawn, AutoUseStrifeHealth)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-12-02 18:45:45 +00:00
|
|
|
VMValue params[] = { player->mo };
|
|
|
|
VMCall(func, params, 1, nullptr, 0);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 02:38:56 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ReactToDamage
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2018-12-13 03:36:20 +00:00
|
|
|
static bool TriggerPainChance(AActor *target, FName mod, bool forcedPain, bool zscript);
|
2018-12-13 02:38:56 +00:00
|
|
|
|
|
|
|
static inline bool MustForcePain(AActor *target, AActor *inflictor)
|
|
|
|
{
|
|
|
|
return (inflictor && (inflictor->flags6 & MF6_FORCEPAIN));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isFakePain(AActor *target, AActor *inflictor, int damage)
|
|
|
|
{
|
2019-01-02 13:31:40 +00:00
|
|
|
return (((target->flags7 & MF7_ALLOWPAIN || target->flags5 & MF5_NODAMAGE) && damage > 0) ||
|
|
|
|
(inflictor && (inflictor->flags7 & MF7_CAUSEPAIN)));
|
2018-12-13 02:38:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// [MC] Completely ripped out of DamageMobj to make it less messy.
|
2018-12-28 16:20:12 +00:00
|
|
|
static void ReactToDamage(AActor *target, AActor *inflictor, AActor *source, int damage, FName mod, int flags, int originaldamage)
|
2018-12-13 02:38:56 +00:00
|
|
|
{
|
|
|
|
bool justhit = false;
|
|
|
|
int painchance = 0;
|
|
|
|
FState *woundstate = nullptr;
|
|
|
|
bool fakedPain = false;
|
|
|
|
bool forcedPain = false;
|
|
|
|
bool noPain = false;
|
2019-02-15 16:02:59 +00:00
|
|
|
bool wakeup = false;
|
2018-12-13 02:38:56 +00:00
|
|
|
|
2018-12-13 03:36:20 +00:00
|
|
|
// Dead or non-existent entity, do not react. Especially if the damage is cancelled.
|
2018-12-13 02:38:56 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-02-15 16:02:59 +00:00
|
|
|
|
2018-12-13 02:38:56 +00:00
|
|
|
woundstate = target->FindState(NAME_Wound, mod);
|
2019-02-15 16:02:59 +00:00
|
|
|
if (woundstate != nullptr)
|
2018-12-13 02:38:56 +00:00
|
|
|
{
|
|
|
|
int woundhealth = target->WoundHealth;
|
|
|
|
|
|
|
|
if (target->health <= woundhealth)
|
|
|
|
{
|
|
|
|
target->SetState(woundstate);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 16:02:59 +00:00
|
|
|
// [MC] NOPAIN will not stop the actor from waking up if damaged.
|
|
|
|
// ALLOW/CAUSEPAIN will enable infighting, even if painless.
|
|
|
|
noPain = (flags & DMG_NO_PAIN) || (target->flags5 & MF5_NOPAIN) || (inflictor && (inflictor->flags5 & MF5_PAINLESS));
|
|
|
|
fakedPain = (isFakePain(target, inflictor, originaldamage));
|
|
|
|
forcedPain = (MustForcePain(target, inflictor));
|
|
|
|
wakeup = (damage > 0 || fakedPain || forcedPain);
|
2018-12-13 02:38:56 +00:00
|
|
|
|
2019-02-15 16:02:59 +00:00
|
|
|
if (!noPain && wakeup &&
|
2018-12-13 03:36:20 +00:00
|
|
|
((target->player != nullptr || !G_SkillProperty(SKILLP_NoPain)) && !(target->flags & MF_SKULLFLY))
|
2019-02-15 16:02:59 +00:00
|
|
|
&& (forcedPain || damage >= target->PainThreshold))
|
2018-12-13 02:38:56 +00:00
|
|
|
{
|
2018-12-13 03:36:20 +00:00
|
|
|
if (inflictor && inflictor->PainType != NAME_None)
|
|
|
|
mod = inflictor->PainType;
|
2018-12-13 02:38:56 +00:00
|
|
|
|
2018-12-13 03:36:20 +00:00
|
|
|
// Not called from ZScript.
|
|
|
|
justhit = TriggerPainChance(target, mod, forcedPain, false);
|
2018-12-13 02:38:56 +00:00
|
|
|
}
|
|
|
|
|
2019-02-15 16:02:59 +00:00
|
|
|
if (wakeup && target->player == nullptr) target->reactiontime = 0; // we're awake now...
|
|
|
|
if (wakeup && source)
|
2018-12-13 02:38:56 +00:00
|
|
|
{
|
|
|
|
if (source == target->target)
|
|
|
|
{
|
|
|
|
target->threshold = target->DefThreshold;
|
2019-02-15 16:02:59 +00:00
|
|
|
if (target->state == target->SpawnState && target->SeeState != nullptr)
|
2018-12-13 02:38:56 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
2019-02-15 16:02:59 +00:00
|
|
|
if (target->lastenemy == nullptr ||
|
|
|
|
(target->lastenemy->player == nullptr && target->TIDtoHate == 0) ||
|
2018-12-13 02:38:56 +00:00
|
|
|
target->lastenemy->health <= 0)
|
|
|
|
{
|
|
|
|
target->lastenemy = target->target; // remember last enemy - killough
|
|
|
|
}
|
|
|
|
target->target = source;
|
|
|
|
target->threshold = target->DefThreshold;
|
2019-02-15 16:02:59 +00:00
|
|
|
if (target->state == target->SpawnState && target->SeeState != nullptr)
|
2018-12-13 02:38:56 +00:00
|
|
|
{
|
|
|
|
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!
|
|
|
|
}
|
|
|
|
|
2018-12-13 03:36:20 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
=
|
|
|
|
= 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
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
|
2019-01-03 12:58:53 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
2019-01-03 21:05:49 +00:00
|
|
|
//
|
2019-01-03 12:58:53 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
// Returns the amount of damage actually inflicted upon the target, or -1 if
|
|
|
|
// the damage was cancelled.
|
2018-05-15 15:24:19 +00:00
|
|
|
static int DamageMobj (AActor *target, AActor *inflictor, AActor *source, int damage, FName mod, int flags, DAngle angle, bool& needevent)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
player_t *player = NULL;
|
|
|
|
int temp;
|
|
|
|
bool justhit = false;
|
|
|
|
bool plrDontThrust = false;
|
2016-08-08 18:01:43 +00:00
|
|
|
const int rawdamage = damage;
|
|
|
|
const bool telefragDamage = (rawdamage >= TELEFRAG_DAMAGE);
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
if (damage < 0) damage = 0;
|
|
|
|
|
|
|
|
if (target == NULL || !((target->flags & MF_SHOOTABLE) || (target->flags6 & MF6_VULNERABLE)))
|
|
|
|
{ // Shouldn't happen
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2018-04-23 19:26:05 +00:00
|
|
|
FName MeansOfDeath = mod;
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
// Spectral targets only take damage from spectral projectiles.
|
2016-08-08 18:01:43 +00:00
|
|
|
if (target->flags4 & MF4_SPECTRAL && !telefragDamage)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
if (inflictor == NULL || !(inflictor->flags4 & MF4_SPECTRAL))
|
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (target->health <= 0)
|
|
|
|
{
|
2016-01-17 18:50:34 +00:00
|
|
|
if (inflictor && mod == NAME_Ice && !(inflictor->flags7 & MF7_ICESHATTER))
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
else if (target->flags & MF_ICECORPSE) // frozen
|
|
|
|
{
|
|
|
|
target->tics = 1;
|
|
|
|
target->flags6 |= MF6_SHATTERING;
|
2016-03-19 23:54:18 +00:00
|
|
|
target->Vel.Zero();
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2017-05-15 15:03:05 +00:00
|
|
|
if (target == source && (!telefragDamage || target->flags7 & MF7_LAXTELEFRAGDMG))
|
2017-02-27 10:22:51 +00:00
|
|
|
{
|
2017-02-28 11:47:44 +00:00
|
|
|
damage = int(damage * target->SelfDamageFactor);
|
2017-02-27 10:22:51 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
// [MC] Changed it to check rawdamage here for consistency, even though that doesn't actually do anything
|
|
|
|
// different here. At any rate, invulnerable is being checked before type factoring, which is then being
|
|
|
|
// checked by player cheats/invul/buddha followed by monster buddha. This is inconsistent. Don't let the
|
|
|
|
// original telefrag damage CHECK (rawdamage) be influenced by outside factors when looking at cheats/invul.
|
2016-08-08 18:01:43 +00:00
|
|
|
if ((target->flags2 & MF2_INVULNERABLE) && !telefragDamage && (!(flags & DMG_FORCED)))
|
2016-01-17 18:09:05 +00:00
|
|
|
{ // actor is invulnerable
|
|
|
|
if (target->player == NULL)
|
|
|
|
{
|
|
|
|
if (inflictor == NULL || (!(inflictor->flags3 & MF3_FOILINVUL) && !(flags & DMG_FOILINVUL)))
|
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return 0;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Players are optionally excluded from getting thrust by damage.
|
2019-01-03 17:01:58 +00:00
|
|
|
if (target->IntVar(NAME_PlayerFlags) & PPF_NOTHRUSTWHENINVUL)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return 0;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inflictor != NULL)
|
|
|
|
{
|
|
|
|
if (inflictor->flags5 & MF5_PIERCEARMOR)
|
|
|
|
flags |= DMG_NO_ARMOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Andy Baker's Stealth monsters
|
|
|
|
if (target->flags & MF_STEALTH)
|
|
|
|
{
|
2016-03-21 11:18:46 +00:00
|
|
|
target->Alpha = 1.;
|
2016-01-17 18:09:05 +00:00
|
|
|
target->visdir = -1;
|
|
|
|
}
|
|
|
|
if (target->flags & MF_SKULLFLY)
|
|
|
|
{
|
2016-03-19 23:54:18 +00:00
|
|
|
target->Vel.Zero();
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
player = target->player;
|
|
|
|
if (!(flags & DMG_FORCED)) // DMG_FORCED skips all special damage checks, TELEFRAG_DAMAGE may not be reduced at all
|
|
|
|
{
|
|
|
|
if (target->flags2 & MF2_DORMANT)
|
|
|
|
{
|
|
|
|
// Invulnerable, and won't wake up
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 18:01:43 +00:00
|
|
|
if (!telefragDamage || (target->flags7 & MF7_LAXTELEFRAGDMG)) // TELEFRAG_DAMAGE may only be reduced with LAXTELEFRAGDMG or it may not guarantee its effect.
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
if (player && damage > 1)
|
|
|
|
{
|
2016-02-10 16:06:33 +00:00
|
|
|
// Take half damage in trainer mode
|
2017-07-15 07:38:10 +00:00
|
|
|
damage = int(damage * G_SkillProperty(SKILLP_DamageFactor) * sv_damagefactorplayer);
|
|
|
|
}
|
|
|
|
else if (!player && damage > 1 && !(target->flags & MF_FRIENDLY))
|
|
|
|
{
|
|
|
|
// inflict scaled damage to non-players
|
|
|
|
damage = int(damage * sv_damagefactormobj);
|
|
|
|
}
|
|
|
|
else if (!player && damage > 1 && (target->flags & MF_FRIENDLY))
|
|
|
|
{
|
|
|
|
// inflict scaled damage to non-player friends
|
|
|
|
damage = int(damage * sv_damagefactorfriendly);
|
2016-02-10 16:06:33 +00:00
|
|
|
}
|
|
|
|
// Special damage types
|
|
|
|
if (inflictor)
|
|
|
|
{
|
|
|
|
if (inflictor->flags4 & MF4_SPECTRAL)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2016-02-10 16:06:33 +00:00
|
|
|
if (player != NULL)
|
|
|
|
{
|
|
|
|
if (!deathmatch && inflictor->FriendPlayer > 0)
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-02-10 16:06:33 +00:00
|
|
|
}
|
|
|
|
else if (target->flags4 & MF4_SPECTRAL)
|
|
|
|
{
|
|
|
|
if (inflictor->FriendPlayer == 0 && !target->IsHostile(inflictor))
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-02-10 16:06:33 +00:00
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
damage = inflictor->CallDoSpecialDamage(target, damage, mod);
|
2016-01-17 18:09:05 +00:00
|
|
|
if (damage < 0)
|
2016-02-10 16:06:33 +00:00
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-02-10 16:06:33 +00:00
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int olddam = damage;
|
|
|
|
|
|
|
|
if (damage > 0 && source != NULL)
|
|
|
|
{
|
2016-03-25 15:30:31 +00:00
|
|
|
damage = int(damage * source->DamageMultiply);
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
// Handle active damage modifiers (e.g. PowerDamage)
|
2018-11-10 15:00:49 +00:00
|
|
|
if (damage > 0 && !(flags & DMG_NO_ENHANCE))
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2019-02-12 16:00:28 +00:00
|
|
|
damage = source->GetModifiedDamage(mod, damage, false, inflictor, target, flags);
|
2016-02-10 16:06:33 +00:00
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2016-02-10 16:06:33 +00:00
|
|
|
// Handle passive damage modifiers (e.g. PowerProtection), provided they are not afflicted with protection penetrating powers.
|
2016-11-27 10:59:47 +00:00
|
|
|
if (damage > 0 && !(flags & DMG_NO_PROTECT))
|
2016-02-10 16:06:33 +00:00
|
|
|
{
|
2019-02-06 19:06:28 +00:00
|
|
|
damage = target->GetModifiedDamage(mod, damage, true, inflictor, source, flags);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
if (damage > 0 && !(flags & DMG_NO_FACTOR))
|
|
|
|
{
|
2016-03-21 23:06:58 +00:00
|
|
|
damage = target->ApplyDamageFactor(mod, damage);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (damage >= 0)
|
|
|
|
{
|
2016-11-28 23:16:30 +00:00
|
|
|
damage = target->CallTakeSpecialDamage(inflictor, source, damage, mod);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// '<0' is handled below. This only handles the case where damage gets reduced to 0.
|
|
|
|
if (damage == 0 && olddam > 0)
|
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return 0;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (target->flags5 & MF5_NODAMAGE)
|
|
|
|
{
|
|
|
|
damage = 0;
|
2016-02-10 16:06:33 +00:00
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
if (damage < 0)
|
|
|
|
{
|
|
|
|
// any negative value means that something in the above chain has cancelled out all damage and all damage effects, including pain.
|
2018-12-13 02:38:56 +00:00
|
|
|
return -1;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2017-02-26 14:47:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
//[RC] Backported from the Zandronum source.. Mostly.
|
|
|
|
if( target->player &&
|
|
|
|
damage > 0 &&
|
|
|
|
source &&
|
2017-02-26 15:23:22 +00:00
|
|
|
mod != NAME_Reflection &&
|
|
|
|
target != source)
|
|
|
|
|
2017-02-26 14:47:37 +00:00
|
|
|
{
|
2017-02-26 15:23:22 +00:00
|
|
|
int reflectdamage = 0;
|
2017-04-14 14:51:11 +00:00
|
|
|
bool reflecttype = false;
|
2017-02-26 15:23:22 +00:00
|
|
|
for (auto p = target->player->mo->Inventory; p != nullptr; p = p->Inventory)
|
|
|
|
{
|
|
|
|
// This picks the reflection item with the maximum efficiency for the given damage type.
|
|
|
|
if (p->IsKindOf(NAME_PowerReflection))
|
|
|
|
{
|
2017-04-14 14:51:11 +00:00
|
|
|
double alwaysreflect = p->FloatVar(NAME_Strength);
|
|
|
|
int alwaysdamage = clamp(int(damage * alwaysreflect), 0, damage);
|
|
|
|
int mydamage = alwaysdamage + p->ApplyDamageFactor(mod, damage - alwaysdamage);
|
|
|
|
if (mydamage > reflectdamage)
|
|
|
|
{
|
|
|
|
reflectdamage = mydamage;
|
|
|
|
reflecttype = p->BoolVar(NAME_ReflectType);
|
|
|
|
}
|
2017-02-26 15:23:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reflectdamage > 0)
|
2017-02-26 14:47:37 +00:00
|
|
|
{
|
|
|
|
// use the reflect item's damage factors to get the final value here.
|
2017-04-14 14:51:11 +00:00
|
|
|
P_DamageMobj(source, nullptr, target, reflectdamage, reflecttype? mod : NAME_Reflection );
|
2017-02-26 14:47:37 +00:00
|
|
|
|
|
|
|
// Reset means of death flag.
|
|
|
|
MeansOfDeath = mod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
// Push the target unless the source's weapon's kickback is 0.
|
|
|
|
// (i.e. Gauntlets/Chainsaw)
|
|
|
|
if (!plrDontThrust && inflictor && inflictor != target // [RH] Not if hurting own self
|
|
|
|
&& !(target->flags & MF_NOCLIP)
|
|
|
|
&& !(inflictor->flags2 & MF2_NODMGTHRUST)
|
|
|
|
&& !(flags & DMG_THRUSTLESS)
|
|
|
|
&& !(target->flags7 & MF7_DONTTHRUST)
|
|
|
|
&& (source == NULL || source->player == NULL || !(source->flags2 & MF2_NODMGTHRUST)))
|
|
|
|
{
|
2018-11-25 00:12:45 +00:00
|
|
|
IFVIRTUALPTR(target, AActor, ApplyKickback)
|
|
|
|
{
|
|
|
|
VMValue params[] = { target, inflictor, source, damage, angle.Degrees, mod.GetIndex(), flags };
|
|
|
|
VMCall(func, params, countof(params), nullptr, 0);
|
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Avoid friendly fire if enabled
|
|
|
|
if (!(flags & DMG_FORCED) && source != NULL &&
|
|
|
|
((player && player != source->player) || (!player && target != source)) &&
|
|
|
|
target->IsTeammate (source))
|
|
|
|
{
|
2016-01-17 19:57:55 +00:00
|
|
|
//Use the original damage to check for telefrag amount. Don't let the now-amplified damagetypes do it.
|
2016-08-08 18:01:43 +00:00
|
|
|
if (!telefragDamage || (target->flags7 & MF7_LAXTELEFRAGDMG))
|
2016-01-17 18:09:05 +00:00
|
|
|
{ // Still allow telefragging :-(
|
2019-01-27 16:35:50 +00:00
|
|
|
damage = (int)(damage * target->Level->teamdamage);
|
2018-12-13 02:38:56 +00:00
|
|
|
if (damage <= 0)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return (damage < 0) ? -1 : 0;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// player specific
|
|
|
|
//
|
|
|
|
if (player)
|
|
|
|
{
|
2016-11-06 13:44:30 +00:00
|
|
|
// Don't allow DMG_FORCED to work on ultimate degreeslessness/buddha and nodamage.
|
|
|
|
if ((player->cheats & (CF_GODMODE2 | CF_BUDDHA2)) || (player->mo->flags5 & MF5_NODAMAGE))
|
|
|
|
{
|
|
|
|
flags &= ~DMG_FORCED;
|
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
//Added by MC: Lets bots look allround for enemies if they survive an ambush.
|
|
|
|
if (player->Bot != NULL)
|
|
|
|
{
|
|
|
|
player->Bot->allround = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// end of game hell hack
|
2016-01-17 19:57:55 +00:00
|
|
|
if ((target->Sector->Flags & SECF_ENDLEVEL) && damage >= target->health)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
damage = target->health - 1;
|
|
|
|
}
|
|
|
|
|
2016-11-06 13:18:13 +00:00
|
|
|
if (!(flags & DMG_FORCED))
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
// check the real player, not a voodoo doll here for invulnerability effects
|
2016-08-08 18:01:43 +00:00
|
|
|
if ((!telefragDamage && ((player->mo->flags2 & MF2_INVULNERABLE) ||
|
2016-11-06 13:18:13 +00:00
|
|
|
(player->cheats & CF_GODMODE))) ||
|
2016-01-17 18:09:05 +00:00
|
|
|
(player->cheats & CF_GODMODE2) || (player->mo->flags5 & MF5_NODAMAGE))
|
|
|
|
//Absolutely no hurting if NODAMAGE is involved. Same for GODMODE2.
|
|
|
|
{ // player is invulnerable, so don't hurt him
|
2018-12-13 02:38:56 +00:00
|
|
|
return 0;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2016-03-14 21:57:26 +00:00
|
|
|
// Armor for players.
|
2016-01-17 18:09:05 +00:00
|
|
|
if (!(flags & DMG_NO_ARMOR) && player->mo->Inventory != NULL)
|
|
|
|
{
|
|
|
|
int newdam = damage;
|
|
|
|
if (damage > 0)
|
|
|
|
{
|
2017-01-16 00:16:11 +00:00
|
|
|
newdam = player->mo->AbsorbDamage(damage, mod);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
2016-08-08 18:01:43 +00:00
|
|
|
if (!telefragDamage || (player->mo->flags7 & MF7_LAXTELEFRAGDMG)) //rawdamage is never modified.
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
// if we are telefragging don't let the damage value go below that magic value. Some further checks would fail otherwise.
|
|
|
|
damage = newdam;
|
|
|
|
}
|
2016-03-14 21:57:26 +00:00
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
if (damage <= 0)
|
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return (damage < 0) ? -1 : 0;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 18:01:43 +00:00
|
|
|
if (damage >= player->health && !telefragDamage
|
2016-01-17 18:09:05 +00:00
|
|
|
&& (G_SkillProperty(SKILLP_AutoUseHealth) || deathmatch)
|
|
|
|
&& !player->morphTics)
|
|
|
|
{ // Try to use some inventory health
|
|
|
|
P_AutoUseHealth (player, damage - player->health + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player->health -= damage; // mirror mobj health here for Dave
|
|
|
|
// [RH] Make voodoo dolls and real players record the same health
|
|
|
|
target->health = player->mo->health -= damage;
|
|
|
|
if (player->health < 50 && !deathmatch && !(flags & DMG_FORCED))
|
|
|
|
{
|
|
|
|
P_AutoUseStrifeHealth (player);
|
|
|
|
player->mo->health = player->health;
|
|
|
|
}
|
|
|
|
if (player->health <= 0)
|
|
|
|
{
|
|
|
|
// [SP] Buddha cheat: if the player is about to die, rescue him to 1 health.
|
|
|
|
// This does not save the player if damage >= TELEFRAG_DAMAGE, still need to
|
|
|
|
// telefrag him right? ;) (Unfortunately the damage is "absorbed" by armor,
|
|
|
|
// but telefragging should still do enough damage to kill the player)
|
|
|
|
// Ignore players that are already dead.
|
|
|
|
// [MC]Buddha2 absorbs telefrag damage, and anything else thrown their way.
|
2019-01-03 12:58:53 +00:00
|
|
|
int buddha = hasBuddha(player);
|
2018-12-03 08:48:05 +00:00
|
|
|
if (flags & DMG_FORCED) buddha = 0;
|
|
|
|
if (telefragDamage && buddha == 1) buddha = 0;
|
|
|
|
if (buddha)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
// If this is a voodoo doll we need to handle the real player as well.
|
|
|
|
player->mo->health = target->health = player->health = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player->health = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
player->LastDamageType = mod;
|
|
|
|
player->attacker = source;
|
|
|
|
player->damagecount += damage; // add damage after armor / invuln
|
|
|
|
if (player->damagecount > 100)
|
|
|
|
{
|
|
|
|
player->damagecount = 100; // teleport stomp does 10k points...
|
|
|
|
}
|
|
|
|
temp = damage < 100 ? damage : 100;
|
2019-02-01 16:02:10 +00:00
|
|
|
if (player == target->Level->GetConsolePlayer() )
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
I_Tactile (40,10,40+temp*2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Armor for monsters.
|
|
|
|
if (!(flags & (DMG_NO_ARMOR|DMG_FORCED)) && target->Inventory != NULL && damage > 0)
|
|
|
|
{
|
|
|
|
int newdam = damage;
|
2017-01-16 09:23:26 +00:00
|
|
|
newdam = target->AbsorbDamage(damage, mod);
|
2016-01-17 18:09:05 +00:00
|
|
|
damage = newdam;
|
|
|
|
if (damage <= 0)
|
|
|
|
{
|
2018-12-13 02:38:56 +00:00
|
|
|
return (damage < 0) ? -1 : 0;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
target->health -= damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// the damage has been dealt; now deal with the consequences
|
|
|
|
//
|
|
|
|
target->DamageTypeReceived = mod;
|
|
|
|
|
|
|
|
// If the damaging player has the power of drain, give the player 50% of the damage
|
|
|
|
// done in health.
|
2017-02-26 15:23:22 +00:00
|
|
|
if ( source && source->player && !(target->flags5 & MF5_DONTDRAIN))
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
if (!target->player || target->player != source->player)
|
|
|
|
{
|
2017-02-26 15:23:22 +00:00
|
|
|
double draindamage = 0;
|
|
|
|
for (auto p = source->player->mo->Inventory; p != nullptr; p = p->Inventory)
|
|
|
|
{
|
|
|
|
// This picks the item with the maximum efficiency.
|
|
|
|
if (p->IsKindOf(NAME_PowerDrain))
|
|
|
|
{
|
|
|
|
double mydamage = p->FloatVar(NAME_Strength);
|
|
|
|
if (mydamage > draindamage) draindamage = mydamage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 20:50:13 +00:00
|
|
|
if (draindamage > 0)
|
2017-03-29 18:25:54 +00:00
|
|
|
{
|
2017-03-29 20:50:13 +00:00
|
|
|
int draindmg = int(draindamage * damage);
|
|
|
|
IFVIRTUALPTR(source, AActor, OnDrain)
|
|
|
|
{
|
|
|
|
VMValue params[] = { source, target, draindmg, mod.GetIndex() };
|
|
|
|
VMReturn ret(&draindmg);
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, countof(params), &ret, 1);
|
2017-03-29 20:50:13 +00:00
|
|
|
}
|
|
|
|
if (P_GiveBody(source, draindmg))
|
|
|
|
{
|
|
|
|
S_Sound(source, CHAN_ITEM, "*drainhealth", 1, ATTN_NORM);
|
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target->health <= 0)
|
|
|
|
{
|
|
|
|
//[MC]Buddha flag for monsters.
|
2016-08-08 18:01:43 +00:00
|
|
|
if (!(flags & DMG_FORCED) && ((target->flags7 & MF7_BUDDHA) && !telefragDamage && ((inflictor == NULL || !(inflictor->flags7 & MF7_FOILBUDDHA)) && !(flags & DMG_FOILBUDDHA))))
|
2016-01-17 18:09:05 +00:00
|
|
|
{ //FOILBUDDHA or Telefrag damage must kill it.
|
|
|
|
target->health = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
// Death
|
|
|
|
target->special1 = damage;
|
|
|
|
|
|
|
|
// use inflictor's death type if it got one.
|
|
|
|
if (inflictor && inflictor->DeathType != NAME_None) mod = inflictor->DeathType;
|
|
|
|
|
|
|
|
// check for special fire damage or ice damage deaths
|
|
|
|
if (mod == NAME_Fire)
|
|
|
|
{
|
|
|
|
if (player && !player->morphTics)
|
|
|
|
{ // Check for flame death
|
|
|
|
if (!inflictor ||
|
|
|
|
((target->health > -50) && (damage > 25)) ||
|
|
|
|
!(inflictor->flags5 & MF5_SPECIALFIREDAMAGE))
|
|
|
|
{
|
|
|
|
target->DamageType = NAME_Fire;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target->DamageType = NAME_Fire;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target->DamageType = mod;
|
|
|
|
}
|
|
|
|
if (source && source->tracer && (source->flags5 & MF5_SUMMONEDMONSTER))
|
|
|
|
{ // Minotaur's kills go to his master
|
|
|
|
// Make sure still alive and not a pointer to fighter head
|
|
|
|
if (source->tracer->player && (source->tracer->player->mo == source->tracer))
|
|
|
|
{
|
|
|
|
source = source->tracer;
|
|
|
|
}
|
|
|
|
}
|
2018-05-15 15:24:19 +00:00
|
|
|
|
|
|
|
const int realdamage = MAX(0, damage);
|
2019-02-02 15:43:11 +00:00
|
|
|
target->Level->localEventManager->WorldThingDamaged(target, inflictor, source, realdamage, mod, flags, angle);
|
2018-05-15 15:24:19 +00:00
|
|
|
needevent = false;
|
|
|
|
|
2018-04-23 19:26:05 +00:00
|
|
|
target->CallDie (source, inflictor, flags, MeansOfDeath);
|
2018-05-15 15:24:19 +00:00
|
|
|
return realdamage;
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-21 12:12:34 +00:00
|
|
|
return MAX(0, damage);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 07:31:23 +00:00
|
|
|
static int DoDamageMobj(AActor *target, AActor *inflictor, AActor *source, int damage, FName mod, int flags, DAngle angle)
|
|
|
|
{
|
|
|
|
// [ZZ] event handlers need the result.
|
|
|
|
bool needevent = true;
|
|
|
|
int realdamage = DamageMobj(target, inflictor, source, damage, mod, flags, angle, needevent);
|
|
|
|
if (realdamage >= 0) //Keep this check separated. Mods relying upon negative numbers may break otherwise.
|
2018-12-28 16:20:12 +00:00
|
|
|
ReactToDamage(target, inflictor, source, realdamage, mod, flags, damage);
|
2018-12-13 07:31:23 +00:00
|
|
|
|
|
|
|
if (realdamage > 0 && needevent)
|
|
|
|
{
|
|
|
|
// [ZZ] event handlers only need the resultant damage (they can't do anything about it anyway)
|
2019-02-02 15:43:11 +00:00
|
|
|
target->Level->localEventManager->WorldThingDamaged(target, inflictor, source, realdamage, mod, flags, angle);
|
2018-12-13 07:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return MAX(0, realdamage);
|
|
|
|
}
|
|
|
|
|
2016-10-23 15:15:24 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, DamageMobj)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
|
|
|
PARAM_OBJECT(inflictor, AActor);
|
|
|
|
PARAM_OBJECT(source, AActor);
|
|
|
|
PARAM_INT(damage);
|
|
|
|
PARAM_NAME(mod);
|
2018-11-17 09:03:40 +00:00
|
|
|
PARAM_INT(flags);
|
|
|
|
PARAM_FLOAT(angle);
|
2018-12-13 07:31:23 +00:00
|
|
|
ACTION_RETURN_INT(DoDamageMobj(self, inflictor, source, damage, mod, flags, angle));
|
2016-10-23 15:15:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 20:31:52 +00:00
|
|
|
int P_DamageMobj(AActor *target, AActor *inflictor, AActor *source, int damage, FName mod, int flags, DAngle angle)
|
|
|
|
{
|
|
|
|
IFVIRTUALPTR(target, AActor, DamageMobj)
|
|
|
|
{
|
|
|
|
VMValue params[7] = { target, inflictor, source, damage, mod.GetIndex(), flags, angle.Degrees };
|
|
|
|
VMReturn ret;
|
|
|
|
int retval;
|
|
|
|
ret.IntAt(&retval);
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, 7, &ret, 1);
|
2017-01-10 20:31:52 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2017-01-31 02:35:44 +00:00
|
|
|
else
|
|
|
|
{
|
2018-12-13 07:31:23 +00:00
|
|
|
return DoDamageMobj(target, inflictor, source, damage, mod, flags, angle);
|
2017-01-31 02:35:44 +00:00
|
|
|
}
|
2017-01-10 20:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
void P_PoisonMobj (AActor *target, AActor *inflictor, AActor *source, int damage, int duration, int period, FName type)
|
|
|
|
{
|
|
|
|
// Check for invulnerability.
|
|
|
|
if (!(inflictor->flags6 & MF6_POISONALWAYS))
|
|
|
|
{
|
|
|
|
if (target->flags2 & MF2_INVULNERABLE)
|
|
|
|
{ // actor is invulnerable
|
|
|
|
if (target->player == NULL)
|
|
|
|
{
|
|
|
|
if (!(inflictor->flags3 & MF3_FOILINVUL))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
target->Poisoner = source;
|
|
|
|
target->PoisonDamageTypeReceived = type;
|
|
|
|
target->PoisonPeriodReceived = period;
|
|
|
|
|
|
|
|
if (inflictor->flags6 & MF6_ADDITIVEPOISONDAMAGE)
|
|
|
|
{
|
|
|
|
target->PoisonDamageReceived += damage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target->PoisonDamageReceived = damage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inflictor->flags6 & MF6_ADDITIVEPOISONDURATION)
|
|
|
|
{
|
|
|
|
target->PoisonDurationReceived += duration;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target->PoisonDurationReceived = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-11-30 00:25:51 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, PoisonMobj)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
2016-12-02 11:06:49 +00:00
|
|
|
PARAM_OBJECT_NOT_NULL(inflictor, AActor);
|
2016-11-30 00:25:51 +00:00
|
|
|
PARAM_OBJECT(source, AActor);
|
|
|
|
PARAM_INT(damage);
|
|
|
|
PARAM_INT(duration);
|
|
|
|
PARAM_INT(period);
|
|
|
|
PARAM_NAME(mod);
|
|
|
|
P_PoisonMobj(self, inflictor, source, damage, duration, period, mod);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-15 00:39:59 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// OkayToSwitchTarget
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-11-30 00:25:51 +00:00
|
|
|
|
2017-03-15 00:39:59 +00:00
|
|
|
bool AActor::OkayToSwitchTarget(AActor *other)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
if (other == this)
|
|
|
|
return false; // [RH] Don't hate self (can happen when shooting barrels)
|
|
|
|
|
|
|
|
if (other->flags7 & MF7_NEVERTARGET)
|
|
|
|
return false; // never EVER target me!
|
|
|
|
|
|
|
|
if (!(other->flags & MF_SHOOTABLE))
|
|
|
|
return false; // Don't attack things that can't be hurt
|
|
|
|
|
|
|
|
if ((flags4 & MF4_NOTARGETSWITCH) && target != NULL)
|
|
|
|
return false; // Don't switch target if not allowed
|
|
|
|
|
|
|
|
if ((master != NULL && other->IsA(master->GetClass())) || // don't attack your master (or others of its type)
|
|
|
|
(other->master != NULL && IsA(other->master->GetClass()))) // don't attack your minion (or those of others of your type)
|
|
|
|
{
|
|
|
|
if (!IsHostile (other) && // allow target switch if other is considered hostile
|
|
|
|
(other->tid != TIDtoHate || TIDtoHate == 0) && // or has the tid we hate
|
|
|
|
other->TIDtoHate == TIDtoHate) // or has different hate information
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 17:44:32 +00:00
|
|
|
if ((flags7 & MF7_NOINFIGHTSPECIES) && GetSpecies() == other->GetSpecies())
|
2017-02-25 19:12:30 +00:00
|
|
|
return false; // Don't fight own species.
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
if ((other->flags3 & MF3_NOTARGET) &&
|
|
|
|
(other->tid != TIDtoHate || TIDtoHate == 0) &&
|
|
|
|
!IsHostile (other))
|
|
|
|
return false;
|
|
|
|
if (threshold != 0 && !(flags4 & MF4_QUICKTORETALIATE))
|
|
|
|
return false;
|
|
|
|
if (IsFriend (other))
|
|
|
|
{ // [RH] Friendlies don't target other friendlies
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int infight;
|
2017-02-26 18:05:20 +00:00
|
|
|
if (flags7 & MF7_FORCEINFIGHTING) infight = 1;
|
|
|
|
else if (flags5 & MF5_NOINFIGHTING) infight = -1;
|
2019-01-28 13:31:23 +00:00
|
|
|
else infight = Level->GetInfighting();
|
2016-01-17 18:50:34 +00:00
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
if (infight < 0 && other->player == NULL && !IsHostile (other))
|
|
|
|
{
|
|
|
|
return false; // infighting off: Non-friendlies don't target other non-friendlies
|
|
|
|
}
|
|
|
|
if (TIDtoHate != 0 && TIDtoHate == other->TIDtoHate)
|
|
|
|
return false; // [RH] Don't target "teammates"
|
|
|
|
if (other->player != NULL && (flags4 & MF4_NOHATEPLAYERS))
|
|
|
|
return false; // [RH] Don't target players
|
|
|
|
if (target != NULL && target->health > 0 &&
|
|
|
|
TIDtoHate != 0 && target->tid == TIDtoHate && pr_switcher() < 128 &&
|
|
|
|
P_CheckSight (this, target))
|
|
|
|
return false; // [RH] Don't be too quick to give up things we hate
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-15 00:39:59 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, OkayToSwitchTarget)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
|
|
|
PARAM_OBJECT(other, AActor);
|
|
|
|
ACTION_RETURN_BOOL(self->OkayToSwitchTarget(other));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AActor::CallOkayToSwitchTarget(AActor *other)
|
|
|
|
{
|
|
|
|
IFVIRTUAL(AActor, OkayToSwitchTarget)
|
|
|
|
{
|
|
|
|
VMValue params[] = { (DObject*)this, other };
|
|
|
|
int retv;
|
|
|
|
VMReturn ret(&retv);
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, 2, &ret, 1);
|
2017-03-15 00:39:59 +00:00
|
|
|
return !!retv;
|
|
|
|
}
|
2017-03-19 11:41:00 +00:00
|
|
|
return OkayToSwitchTarget(other);
|
2017-03-15 00:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// P_PoisonPlayer - Sets up all data concerning poisoning
|
|
|
|
//
|
|
|
|
// poisoner is the object directly responsible for poisoning the player,
|
|
|
|
// such as a missile. source is the actor responsible for creating the
|
|
|
|
// poisoner.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool P_PoisonPlayer (player_t *player, AActor *poisoner, AActor *source, int poison)
|
|
|
|
{
|
2018-12-02 19:06:13 +00:00
|
|
|
if ((player->cheats & CF_GODMODE) || (player->mo->flags2 & MF2_INVULNERABLE) || (player->cheats & CF_GODMODE2) ||
|
|
|
|
(player->mo->flags5 & MF5_NODAMAGE))
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (source != NULL && source->player != player && player->mo->IsTeammate (source))
|
|
|
|
{
|
2019-01-27 16:35:50 +00:00
|
|
|
poison = (int)(poison * player->mo->Level->teamdamage);
|
2016-01-17 18:09:05 +00:00
|
|
|
}
|
|
|
|
if (poison > 0)
|
|
|
|
{
|
|
|
|
player->poisoncount += poison;
|
|
|
|
player->poisoner = source;
|
|
|
|
if (poisoner == NULL)
|
|
|
|
{
|
|
|
|
player->poisontype = player->poisonpaintype = NAME_None;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // We need to record these in case the poisoner disappears before poisoncount reaches 0.
|
|
|
|
player->poisontype = poisoner->DamageType;
|
|
|
|
player->poisonpaintype = poisoner->PainType != NAME_None ? poisoner->PainType : poisoner->DamageType;
|
|
|
|
}
|
|
|
|
if(player->poisoncount > 100)
|
|
|
|
{
|
|
|
|
player->poisoncount = 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-26 18:23:22 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(_PlayerInfo, PoisonPlayer)
|
|
|
|
{
|
|
|
|
PARAM_SELF_STRUCT_PROLOGUE(player_t);
|
|
|
|
PARAM_OBJECT(poisoner, AActor);
|
|
|
|
PARAM_OBJECT(source, AActor);
|
|
|
|
PARAM_INT(poison);
|
|
|
|
ACTION_RETURN_BOOL(P_PoisonPlayer(self, poisoner, source, poison));
|
|
|
|
}
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// P_PoisonDamage - Similar to P_DamageMobj
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-11-27 10:59:47 +00:00
|
|
|
void P_PoisonDamage (player_t *player, AActor *source, int damage, bool playPainSound)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
AActor *target;
|
|
|
|
|
|
|
|
if (player == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
target = player->mo;
|
|
|
|
if (target->health <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-12-02 19:06:13 +00:00
|
|
|
|
|
|
|
// [MC] This must be checked before any modifications. Otherwise, power amplifiers
|
|
|
|
// may result in doing too much damage that cannot be negated by regular buddha,
|
|
|
|
// which is inconsistent. The raw damage must be the only determining factor for
|
|
|
|
// determining if telefrag is actually desired.
|
|
|
|
const bool telefragDamage = (damage >= TELEFRAG_DAMAGE && !(target->flags7 & MF7_LAXTELEFRAGDMG));
|
|
|
|
|
|
|
|
if ((player->cheats & CF_GODMODE2) || (target->flags5 & MF5_NODAMAGE) || //These two are never subjected to telefrag thresholds.
|
|
|
|
(!telefragDamage && ((target->flags2 & MF2_INVULNERABLE) || (player->cheats & CF_GODMODE))))
|
2016-01-17 18:09:05 +00:00
|
|
|
{ // target is invulnerable
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Take half damage in trainer mode
|
2017-07-15 07:38:10 +00:00
|
|
|
damage = int(damage * G_SkillProperty(SKILLP_DamageFactor) * sv_damagefactorplayer);
|
2016-01-17 18:09:05 +00:00
|
|
|
// Handle passive damage modifiers (e.g. PowerProtection)
|
2019-02-06 19:06:28 +00:00
|
|
|
damage = target->GetModifiedDamage(player->poisontype, damage, true, nullptr, source);
|
2016-01-17 18:09:05 +00:00
|
|
|
// Modify with damage factors
|
2016-03-21 23:06:58 +00:00
|
|
|
damage = target->ApplyDamageFactor(player->poisontype, damage);
|
|
|
|
|
2016-01-17 18:09:05 +00:00
|
|
|
if (damage <= 0)
|
|
|
|
{ // Damage was reduced to 0, so don't bother further.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (damage >= player->health
|
|
|
|
&& (G_SkillProperty(SKILLP_AutoUseHealth) || deathmatch)
|
|
|
|
&& !player->morphTics)
|
|
|
|
{ // Try to use some inventory health
|
|
|
|
P_AutoUseHealth(player, damage - player->health+1);
|
|
|
|
}
|
|
|
|
player->health -= damage; // mirror mobj health here for Dave
|
|
|
|
if (player->health < 50 && !deathmatch)
|
|
|
|
{
|
|
|
|
P_AutoUseStrifeHealth(player);
|
|
|
|
}
|
|
|
|
if (player->health < 0)
|
|
|
|
{
|
|
|
|
player->health = 0;
|
|
|
|
}
|
|
|
|
player->attacker = source;
|
|
|
|
|
|
|
|
//
|
|
|
|
// do the damage
|
|
|
|
//
|
|
|
|
target->health -= damage;
|
|
|
|
if (target->health <= 0)
|
|
|
|
{ // Death
|
2019-01-03 12:58:53 +00:00
|
|
|
int buddha = hasBuddha(player);
|
2018-12-03 08:48:05 +00:00
|
|
|
if (telefragDamage && buddha == 1) buddha = 0;
|
|
|
|
if (buddha)
|
2016-01-17 18:09:05 +00:00
|
|
|
{ // [SP] Save the player...
|
|
|
|
player->health = target->health = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target->special1 = damage;
|
|
|
|
if (player && !player->morphTics)
|
|
|
|
{ // Check for flame death
|
|
|
|
if ((player->poisontype == NAME_Fire) && (target->health > -50) && (damage > 25))
|
|
|
|
{
|
|
|
|
target->DamageType = NAME_Fire;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target->DamageType = player->poisontype;
|
|
|
|
}
|
|
|
|
}
|
2016-11-26 00:14:47 +00:00
|
|
|
target->CallDie(source, source);
|
2016-01-17 18:09:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-01-27 16:35:50 +00:00
|
|
|
if (!(target->Level->time&63) && playPainSound)
|
2016-01-17 18:09:05 +00:00
|
|
|
{
|
|
|
|
FState *painstate = target->FindState(NAME_Pain, player->poisonpaintype);
|
|
|
|
if (painstate != NULL)
|
|
|
|
{
|
|
|
|
target->SetState(painstate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if((P_Random() < target->info->painchance)
|
|
|
|
&& !(target->flags&MF_SKULLFLY))
|
|
|
|
{
|
|
|
|
target->flags |= MF_JUSTHIT; // fight back!
|
|
|
|
P_SetMobjState(target, target->info->painstate);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2016-11-27 10:59:47 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(_PlayerInfo, PoisonDamage)
|
|
|
|
{
|
|
|
|
PARAM_SELF_STRUCT_PROLOGUE(player_t);
|
|
|
|
PARAM_OBJECT(source, AActor);
|
|
|
|
PARAM_INT(damage);
|
|
|
|
PARAM_BOOL(playsound);
|
|
|
|
P_PoisonDamage(self, source, damage, playsound);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
|
|
|
|
CCMD (kill)
|
|
|
|
{
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
if (CheckCheatmode ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!stricmp (argv[1], "monsters"))
|
|
|
|
{
|
|
|
|
// Kill all the monsters
|
|
|
|
if (CheckCheatmode ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Net_WriteByte (DEM_GENERICCHEAT);
|
|
|
|
Net_WriteByte (CHT_MASSACRE);
|
|
|
|
}
|
2017-07-19 19:02:46 +00:00
|
|
|
else if (!stricmp (argv[1], "baddies"))
|
|
|
|
{
|
|
|
|
// Kill all the unfriendly monsters
|
|
|
|
if (CheckCheatmode ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Net_WriteByte (DEM_GENERICCHEAT);
|
|
|
|
Net_WriteByte (CHT_MASSACRE2);
|
|
|
|
}
|
2016-01-17 18:09:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Net_WriteByte (DEM_KILLCLASSCHEAT);
|
|
|
|
Net_WriteString (argv[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If suiciding is disabled, then don't do it.
|
|
|
|
if (dmflags2 & DF2_NOSUICIDE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Kill the player
|
|
|
|
Net_WriteByte (DEM_SUICIDE);
|
|
|
|
}
|
|
|
|
C_HideConsole ();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(remove)
|
|
|
|
{
|
|
|
|
if (argv.argc() == 2)
|
|
|
|
{
|
|
|
|
if (CheckCheatmode())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Net_WriteByte(DEM_REMOVE);
|
|
|
|
Net_WriteString(argv[1]);
|
|
|
|
C_HideConsole();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf("Usage: remove <actor class name>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|