From 07678311d1d84ee942bb69ab57eb430ec2523848 Mon Sep 17 00:00:00 2001 From: SSNTails Date: Thu, 15 Feb 2024 08:39:23 -0500 Subject: [PATCH 1/6] Missiles fired by player will not hit bots --- src/p_map.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 7887c117d..dba8cc5cf 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1278,8 +1278,8 @@ static unsigned PIT_DoCheckThing(mobj_t *thing) if (tmthing->type != MT_SHELL && tmthing->target && tmthing->target->type == thing->type) { - // Don't hit same species as originator. - if (thing == tmthing->target) + // Don't hit yourself, and if a player, don't hit bots + if (thing == tmthing->target || (thing->player && thing->player->bot)) return CHECKTHING_IGNORE; if (thing->type != MT_PLAYER) From 2db0dc3ad983c2c4c2fd75ddc09ed1fa94701cfc Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 15 Feb 2024 10:32:21 -0500 Subject: [PATCH 2/6] Zwip-Zwap's suggestion of checking for coop and types of bots --- src/p_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_map.c b/src/p_map.c index dba8cc5cf..0c976d5b0 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1279,7 +1279,7 @@ static unsigned PIT_DoCheckThing(mobj_t *thing) if (tmthing->type != MT_SHELL && tmthing->target && tmthing->target->type == thing->type) { // Don't hit yourself, and if a player, don't hit bots - if (thing == tmthing->target || (thing->player && thing->player->bot)) + if (thing == tmthing->target || (thing->player && gametype == GT_COOP && (thing->player->bot == BOT_2PAI || thing->player->bot == BOT_2PHUMAN))) return CHECKTHING_IGNORE; if (thing->type != MT_PLAYER) From 398b5a1840d93b67d9d6c862098896466e2e2289 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 15 Feb 2024 23:00:35 -0500 Subject: [PATCH 3/6] P_PlayerCanHurtPlayer() --- src/p_inter.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/p_local.h | 1 + src/p_map.c | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/p_inter.c b/src/p_inter.c index 82169bc54..afcdd5217 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -3279,6 +3279,67 @@ static boolean P_TagDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, IN return true; } +// +// P_PlayerCanHurtPlayer +// +// Is it permissible for a player to hurt another player? +// This should be the definitive global function to determine if pain is allowed. :) +// +boolean P_PlayerCanHurtPlayer(player_t *target, mobj_t *inflictor, player_t *source, UINT8 damagetype) +{ + if (!(damagetype & DMG_CANHURTSELF)) + { + // You can't kill yourself, idiot... + if (source == target) + return false; + + // In COOP/RACE, you can't hurt other players unless cv_friendlyfire is on + if (!(cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE)) && (gametyperules & GTR_FRIENDLY)) + return false; + } + + // Tag handling + if (G_TagGametype()) + { + // If flashing or invulnerable, ignore the tag, + if (target->powers[pw_flashing] || target->powers[pw_invulnerability]) + return false; + + // Don't allow any damage before the round starts. + if (leveltime <= hidetime * TICRATE) + return false; + + // Ignore IT players shooting each other, unless friendlyfire is on. + if ((target->pflags & PF_TAGIT && !((cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE) || (damagetype & DMG_CANHURTSELF)) + && source->pflags & PF_TAGIT))) + return false; + + // Don't allow players on the same team to hurt one another, + // unless cv_friendlyfire is on. + if (!(cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE) || (damagetype & DMG_CANHURTSELF)) && (target->pflags & PF_TAGIT) == (source->pflags & PF_TAGIT)) + return false; + + if (inflictor->type == MT_LHRT) + return false; + + return true; + } + else if (damagetype & DMG_CANHURTSELF) + return true; + else if (G_GametypeHasTeams()) // CTF + Team Match + { + // Don't allow players on the same team to hurt one another, + // unless cv_friendlyfire is on. + if (!(cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE)) && target->ctfteam == source->ctfteam) + return false; + } + + if (inflictor->type == MT_LHRT) + return false; + + return true; +} + static boolean P_PlayerHitsPlayer(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype) { player_t *player = target->player; diff --git a/src/p_local.h b/src/p_local.h index 9644e7a24..d4b32b005 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -506,6 +506,7 @@ void P_RemoveShield(player_t *player); void P_SpecialStageDamage(player_t *player, mobj_t *inflictor, mobj_t *source); boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype); void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype); +boolean P_PlayerCanHurtPlayer(player_t *target, mobj_t *inflictor, player_t *source, UINT8 damagetype); void P_PlayerRingBurst(player_t *player, INT32 num_rings); /// \todo better fit in p_user.c void P_PlayerWeaponPanelBurst(player_t *player); void P_PlayerWeaponAmmoBurst(player_t *player); diff --git a/src/p_map.c b/src/p_map.c index 0c976d5b0..cdd66a12d 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1279,7 +1279,7 @@ static unsigned PIT_DoCheckThing(mobj_t *thing) if (tmthing->type != MT_SHELL && tmthing->target && tmthing->target->type == thing->type) { // Don't hit yourself, and if a player, don't hit bots - if (thing == tmthing->target || (thing->player && gametype == GT_COOP && (thing->player->bot == BOT_2PAI || thing->player->bot == BOT_2PHUMAN))) + if (thing->player && tmthing->target->player && !P_PlayerCanHurtPlayer(thing->player, tmthing, tmthing->target->player, 0)) return CHECKTHING_IGNORE; if (thing->type != MT_PLAYER) From 5e29cd84a2cd3b69dd793b3f006b3980052c138b Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 16 Feb 2024 11:46:37 -0500 Subject: [PATCH 4/6] Stash changes --- src/p_inter.c | 18 ++++++++++-------- src/p_local.h | 2 +- src/p_map.c | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/p_inter.c b/src/p_inter.c index afcdd5217..77604208f 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -3280,13 +3280,21 @@ static boolean P_TagDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, IN } // -// P_PlayerCanHurtPlayer +// P_CanPlayerHurtPlayer // // Is it permissible for a player to hurt another player? // This should be the definitive global function to determine if pain is allowed. :) // -boolean P_PlayerCanHurtPlayer(player_t *target, mobj_t *inflictor, player_t *source, UINT8 damagetype) +boolean P_CanPlayerHurtPlayer(player_t *target, mobj_t *inflictor, player_t *source, UINT8 damagetype) { + I_Assert(target != NULL); + I_Assert(source != NULL); + I_Assert(inflictor != NULL); + + // MT_LHRT should return true here, because we want it to go through the 'damage' process + if (inflictor->type == MT_LHRT) + return true; + if (!(damagetype & DMG_CANHURTSELF)) { // You can't kill yourself, idiot... @@ -3319,9 +3327,6 @@ boolean P_PlayerCanHurtPlayer(player_t *target, mobj_t *inflictor, player_t *sou if (!(cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE) || (damagetype & DMG_CANHURTSELF)) && (target->pflags & PF_TAGIT) == (source->pflags & PF_TAGIT)) return false; - if (inflictor->type == MT_LHRT) - return false; - return true; } else if (damagetype & DMG_CANHURTSELF) @@ -3334,9 +3339,6 @@ boolean P_PlayerCanHurtPlayer(player_t *target, mobj_t *inflictor, player_t *sou return false; } - if (inflictor->type == MT_LHRT) - return false; - return true; } diff --git a/src/p_local.h b/src/p_local.h index d4b32b005..136b7df28 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -506,7 +506,7 @@ void P_RemoveShield(player_t *player); void P_SpecialStageDamage(player_t *player, mobj_t *inflictor, mobj_t *source); boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype); void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype); -boolean P_PlayerCanHurtPlayer(player_t *target, mobj_t *inflictor, player_t *source, UINT8 damagetype); +boolean P_CanPlayerHurtPlayer(player_t *target, mobj_t *inflictor, player_t *source, UINT8 damagetype); void P_PlayerRingBurst(player_t *player, INT32 num_rings); /// \todo better fit in p_user.c void P_PlayerWeaponPanelBurst(player_t *player); void P_PlayerWeaponAmmoBurst(player_t *player); diff --git a/src/p_map.c b/src/p_map.c index cdd66a12d..b18f0d1c1 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1279,7 +1279,7 @@ static unsigned PIT_DoCheckThing(mobj_t *thing) if (tmthing->type != MT_SHELL && tmthing->target && tmthing->target->type == thing->type) { // Don't hit yourself, and if a player, don't hit bots - if (thing->player && tmthing->target->player && !P_PlayerCanHurtPlayer(thing->player, tmthing, tmthing->target->player, 0)) + if (thing->player && tmthing->target->player && !P_CanPlayerHurtPlayer(thing->player, tmthing, tmthing->target->player, 0)) return CHECKTHING_IGNORE; if (thing->type != MT_PLAYER) From dc625496d89ba310fe36a8335704d4fdab2fc7bb Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 16 Feb 2024 12:27:25 -0500 Subject: [PATCH 5/6] re-introduce the thing == tmthing->target check, so it applies to non-players --- src/p_map.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p_map.c b/src/p_map.c index b18f0d1c1..d4083cfd7 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1279,7 +1279,8 @@ static unsigned PIT_DoCheckThing(mobj_t *thing) if (tmthing->type != MT_SHELL && tmthing->target && tmthing->target->type == thing->type) { // Don't hit yourself, and if a player, don't hit bots - if (thing->player && tmthing->target->player && !P_CanPlayerHurtPlayer(thing->player, tmthing, tmthing->target->player, 0)) + if (thing == tmthing->target + || (thing->player && tmthing->target->player && !P_CanPlayerHurtPlayer(thing->player, tmthing, tmthing->target->player, 0))) return CHECKTHING_IGNORE; if (thing->type != MT_PLAYER) From 9a75ef18c388b7e5d1aab13c201695944153945a Mon Sep 17 00:00:00 2001 From: Arthur Date: Sat, 17 Feb 2024 10:04:34 -0500 Subject: [PATCH 6/6] Sometimes simple is better..? --- src/p_inter.c | 63 --------------------------------------------------- src/p_local.h | 1 - src/p_map.c | 2 +- 3 files changed, 1 insertion(+), 65 deletions(-) diff --git a/src/p_inter.c b/src/p_inter.c index 77604208f..82169bc54 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -3279,69 +3279,6 @@ static boolean P_TagDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, IN return true; } -// -// P_CanPlayerHurtPlayer -// -// Is it permissible for a player to hurt another player? -// This should be the definitive global function to determine if pain is allowed. :) -// -boolean P_CanPlayerHurtPlayer(player_t *target, mobj_t *inflictor, player_t *source, UINT8 damagetype) -{ - I_Assert(target != NULL); - I_Assert(source != NULL); - I_Assert(inflictor != NULL); - - // MT_LHRT should return true here, because we want it to go through the 'damage' process - if (inflictor->type == MT_LHRT) - return true; - - if (!(damagetype & DMG_CANHURTSELF)) - { - // You can't kill yourself, idiot... - if (source == target) - return false; - - // In COOP/RACE, you can't hurt other players unless cv_friendlyfire is on - if (!(cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE)) && (gametyperules & GTR_FRIENDLY)) - return false; - } - - // Tag handling - if (G_TagGametype()) - { - // If flashing or invulnerable, ignore the tag, - if (target->powers[pw_flashing] || target->powers[pw_invulnerability]) - return false; - - // Don't allow any damage before the round starts. - if (leveltime <= hidetime * TICRATE) - return false; - - // Ignore IT players shooting each other, unless friendlyfire is on. - if ((target->pflags & PF_TAGIT && !((cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE) || (damagetype & DMG_CANHURTSELF)) - && source->pflags & PF_TAGIT))) - return false; - - // Don't allow players on the same team to hurt one another, - // unless cv_friendlyfire is on. - if (!(cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE) || (damagetype & DMG_CANHURTSELF)) && (target->pflags & PF_TAGIT) == (source->pflags & PF_TAGIT)) - return false; - - return true; - } - else if (damagetype & DMG_CANHURTSELF) - return true; - else if (G_GametypeHasTeams()) // CTF + Team Match - { - // Don't allow players on the same team to hurt one another, - // unless cv_friendlyfire is on. - if (!(cv_friendlyfire.value || (gametyperules & GTR_FRIENDLYFIRE)) && target->ctfteam == source->ctfteam) - return false; - } - - return true; -} - static boolean P_PlayerHitsPlayer(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype) { player_t *player = target->player; diff --git a/src/p_local.h b/src/p_local.h index 136b7df28..9644e7a24 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -506,7 +506,6 @@ void P_RemoveShield(player_t *player); void P_SpecialStageDamage(player_t *player, mobj_t *inflictor, mobj_t *source); boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype); void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype); -boolean P_CanPlayerHurtPlayer(player_t *target, mobj_t *inflictor, player_t *source, UINT8 damagetype); void P_PlayerRingBurst(player_t *player, INT32 num_rings); /// \todo better fit in p_user.c void P_PlayerWeaponPanelBurst(player_t *player); void P_PlayerWeaponAmmoBurst(player_t *player); diff --git a/src/p_map.c b/src/p_map.c index d4083cfd7..32428208b 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1280,7 +1280,7 @@ static unsigned PIT_DoCheckThing(mobj_t *thing) { // Don't hit yourself, and if a player, don't hit bots if (thing == tmthing->target - || (thing->player && tmthing->target->player && !P_CanPlayerHurtPlayer(thing->player, tmthing, tmthing->target->player, 0))) + || (thing->player && tmthing->target->player && (thing->player->bot == BOT_2PAI || thing->player->bot == BOT_2PHUMAN))) return CHECKTHING_IGNORE; if (thing->type != MT_PLAYER)