From cc801a7efac8fc5d38d9efd87af7c228c55c5794 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 29 Jun 2021 17:33:16 +0200 Subject: [PATCH] - MBF21: added projectile group. --- src/gamedata/d_dehacked.cpp | 7 +++++++ src/playsim/p_map.cpp | 26 +++++++++++++++++++++++++- src/scripting/thingdef_properties.cpp | 13 +++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/gamedata/d_dehacked.cpp b/src/gamedata/d_dehacked.cpp index 3e9011b2a..ad62d1b61 100644 --- a/src/gamedata/d_dehacked.cpp +++ b/src/gamedata/d_dehacked.cpp @@ -971,6 +971,13 @@ static int PatchThing (int thingy) } type->ActorInfo()->infighting_group = grp; } + else if (linelen == 16 && stricmp(Line1, "projectile group") == 0) + { + stripwhite(Line2); + int grp = atoi(Line2); + if (grp < 0) grp = -1; + type->ActorInfo()->projectile_group = grp; + } else if (linelen > 6) { diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index 64172fa20..0e6e42ffe 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -1157,6 +1157,29 @@ static bool CheckRipLevel(AActor *victim, AActor *projectile) // //========================================================================== +static bool P_ProjectileImmune(AActor* target, AActor* source) +{ + // This one's directly taken from DSDA. + auto targetgroup = target->GetClass()->ActorInfo()->projectile_group; + auto sourcegroup = source->GetClass()->ActorInfo()->projectile_group; + + return + ( // PG_GROUPLESS means no immunity, even to own species + targetgroup != -1/*PG_GROUPLESS*/ || + target == source + ) && + ( + ( // target type has default behaviour, and things are the same type + targetgroup == 0/*PG_DEFAULT*/ && + (source->GetSpecies() == target->GetSpecies() && !(target->flags6 & MF6_DOHARMSPECIES)) + ) || + ( // target type has special behaviour, and things have the same group + targetgroup != 0/*PG_DEFAULT*/ && + targetgroup == sourcegroup + ) + ); +} + static bool CanAttackHurt(AActor *victim, AActor *shooter) { // players are never subject to infighting settings and are always allowed @@ -1204,7 +1227,8 @@ static bool CanAttackHurt(AActor *victim, AActor *shooter) // [RH] Don't hurt monsters that hate the same victim as you do return false; } - if (victim->GetSpecies() == shooter->GetSpecies() && !(victim->flags6 & MF6_DOHARMSPECIES)) + + if (P_ProjectileImmune(victim, shooter)) { // Don't hurt same species or any relative - // but only if the target isn't one's hostile. diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 2120ae97b..0367b8caf 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -1038,6 +1038,19 @@ DEFINE_PROPERTY(infightinggroup, I, Actor) info->ActorInfo()->infighting_group = i; } +//========================================================================== +// MBF21 +//========================================================================== +DEFINE_PROPERTY(projectilegroup, I, Actor) +{ + PROP_INT_PARM(i, 0); + if (i < -1) + { + I_Error("Projectile groups must be >= -1."); + } + info->ActorInfo()->projectile_group = i; +} + //========================================================================== // [BB] //==========================================================================