From 2fbef2e548c1c93d91bbf5361077ee46fa5c0ea8 Mon Sep 17 00:00:00 2001 From: terencehill Date: Wed, 12 Jul 2023 16:30:41 +0200 Subject: [PATCH] Remove unneeded *_TEAMCHECK macros, simplify checks and reduce code --- mutators.cfg | 6 +-- qcsrc/common/mutators/mutator/nades/nades.qc | 56 ++++++++------------ 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/mutators.cfg b/mutators.cfg index d0337c22d..0851dc4f7 100644 --- a/mutators.cfg +++ b/mutators.cfg @@ -207,7 +207,7 @@ set g_nades_nade_newton_style 0 "nade velocity: 0 is absolute, 1 is relative (ta set g_nades_nade_type 1 "Type of the off-hand grenade. 1:normal 2:napalm 3:ice 4:translocate 5:spawn 6:heal 7:pokenade 8:entrap 9:veil, 10:ammo, 11:darkness" seta cl_nade_timer 1 "show a visual timer for nades, 1 = only circle, 2 = circle with text" -seta cl_nade_type 3 "selected type of the off-hand grenade. 1:normal 2:napalm 3:ice 4:translocate 5:spawn 6:heal 7:pokenade 8:entrap 9:veil 10:ammo 11:dark" +seta cl_nade_type 3 "selected type of the off-hand grenade. 1:normal 2:napalm 3:ice 4:translocate 5:spawn 6:heal 7:pokenade 8:entrap 9:veil 10:ammo 11:darkness" seta cl_pokenade_type "zombie" "monster to spawn" // ------------ @@ -261,7 +261,7 @@ set g_nades_ice 1 "Ice nade: freezes and reduces health" set g_nades_ice_freeze_time 3 "How long the ice field will last" set g_nades_ice_health 0 "How much health the player will have after being unfrozen" set g_nades_ice_explode 0 "Whether the ice nade should explode again once the ice field dissipated" -set g_nades_ice_teamcheck 2 "0: friendly fire, 1: nade owner isn't affected, 2: don't freeze teammates" +set g_nades_ice_teamcheck 2 "0: freezes everyone including the player who threw the nade, 1: freezes enemies and teammates, 2: freezes only enemies" // Translocate (4) set g_nades_translocate 1 "Translocate nade: teleports into explosion nade location" @@ -308,7 +308,7 @@ set g_nades_ammo_foe -2 "Multiplier of ammo given to enemies" set g_nades_darkness 0 "Darkness nade: blinds enemies" set g_nades_darkness_time 4 "How long the dark field will last" set g_nades_darkness_explode 0 "Whether the darkness nade should explode again once the dark field dissipated" -set g_nades_darkness_teamcheck 2 "0: friendly fire, 1: nade owner isn't affected, 2: don't blind teammates" +set g_nades_darkness_teamcheck 2 "0: blinds everyone including the player who threw the nade, 1: blinds enemies and teammates, 2: blinds only enemies" // ============ // camp check diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index 12997c0b5..a967124f1 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -471,24 +471,20 @@ void nade_ice_think(entity this) float current_freeze_time = this.ltime - time - 0.1; -#define ICE_NADE_RADIUS_TEAMCHECK(checked) \ - if (checked) \ - if (!it.revival_time || ((time - it.revival_time) >= 1.5)) \ - if (!STAT(FROZEN, it)) \ - nade_ice_freeze(this, it, current_freeze_time); \ - break; - - FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_freeze_time > 0, + FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage + && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_freeze_time > 0 + && (!it.revival_time || ((time - it.revival_time) >= 1.5)) && !STAT(FROZEN, it), { switch (autocvar_g_nades_ice_teamcheck) { - // 1: nade owner isn't affected; 2: no teammate is affected; any other number than 1 and 2: friendly fire - case 1: ICE_NADE_RADIUS_TEAMCHECK(it != this.realowner); - case 2: ICE_NADE_RADIUS_TEAMCHECK(DIFF_TEAM(it, this.realowner) && it != this.realowner); - default: ICE_NADE_RADIUS_TEAMCHECK(!autocvar_g_nades_ice_teamcheck || (DIFF_TEAM(it, this.realowner) || it == this.realowner)); + case 0: break; // affect everyone + default: + case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates + // fall through (check case 1 condition too) + case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade } + nade_ice_freeze(this, it, current_freeze_time); }); -#undef ICE_NADE_RADIUS_TEAMCHECK } void nade_ice_boom(entity this) @@ -861,28 +857,23 @@ void nade_darkness_think(entity this) Send_Effect(EFFECT_DARKFIELD, this.origin, '0 0 0', 1); } - float current_dark_time = this.ltime - time - 0.1; -#define DARK_NADE_RADIUS_TEAMCHECK(checked) \ - if (checked) \ - if ( IS_REAL_CLIENT(it) ) \ - { \ - STAT(NADE_DARKNESS_TIME, it) = time + 0.1; \ - DarkBlinking(it); \ - } \ - break; + float current_dark_time = this.ltime - time - 0.1; - FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0, + FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_nades_nade_radius, it != this && it.takedamage + && !IS_DEAD(it) && GetResource(it, RES_HEALTH) > 0 && current_dark_time > 0 && IS_REAL_CLIENT(it), { switch (autocvar_g_nades_darkness_teamcheck) { - // 1: nade owner isn't affected; 2: no teammate is affected; any other number than 1 and 2: friendly fire - case 1: DARK_NADE_RADIUS_TEAMCHECK(it != this.realowner); - case 2: DARK_NADE_RADIUS_TEAMCHECK(DIFF_TEAM(it, this.realowner) && it != this.realowner); - default: DARK_NADE_RADIUS_TEAMCHECK(!autocvar_g_nades_darkness_teamcheck || (DIFF_TEAM(it, this.realowner) && it != this.realowner)); + case 0: break; // affect everyone + default: + case 2: if(SAME_TEAM(it, this.realowner)) continue; // don't affect teammates + // fall through (check case 1 condition too) + case 1: if(it == this.realowner) continue; // don't affect the player who threw the nade } + STAT(NADE_DARKNESS_TIME, it) = time + 0.1; + DarkBlinking(it); }); -#undef DARK_NADE_RADIUS_TEAMCHECK } void nade_darkness_boom(entity this) @@ -1424,10 +1415,9 @@ void nades_Clear(entity player) int nades_CheckTypes(entity player, int cl_ntype) { -#define CL_NADE_TYPE_CHECK(cl_ntype, cvar) \ - case cl_ntype.m_id: \ - if (!cvar) return NADE_TYPE_NORMAL.m_id; \ - break + // TODO check what happens without this patch +#define CL_NADE_TYPE_CHECK(nade_ent, nade_cvar) \ + case nade_ent.m_id: if (nade_cvar) return cl_ntype switch (cl_ntype) { @@ -1442,7 +1432,7 @@ int nades_CheckTypes(entity player, int cl_ntype) CL_NADE_TYPE_CHECK(NADE_TYPE_AMMO, autocvar_g_nades_ammo); CL_NADE_TYPE_CHECK(NADE_TYPE_DARKNESS, autocvar_g_nades_darkness); } - return cl_ntype; + return NADE_TYPE_NORMAL.m_id; // default to NADE_TYPE_NORMAL for unknown nade types #undef CL_NADE_TYPE_CHECK } -- 2.39.2