From 7293d34ca1ae87bb0b420b23cf4a19a3690f4fdc Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 13 Jul 2024 23:06:56 +0200 Subject: [PATCH] Slightly optimize 3 functions --- .../mutator/vampirehook/sv_vampirehook.qc | 29 ++++++++++--------- qcsrc/common/playerstats.qc | 3 +- qcsrc/server/player.qc | 3 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc b/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc index 48dcb68b1..1f5b9be61 100644 --- a/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc +++ b/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc @@ -14,25 +14,26 @@ MUTATOR_HOOKFUNCTION(vh, GrappleHookThink) { entity thehook = M_ARGV(0, entity); - entity dmgent = ((SAME_TEAM(thehook.owner, thehook.aiment) && autocvar_g_vampirehook_teamheal) ? thehook.owner : thehook.aiment); - - if(IS_PLAYER(thehook.aiment)) - if(thehook.last_dmg < time) - if(!STAT(FROZEN, thehook.aiment)) - if(time >= game_starttime) - if(DIFF_TEAM(thehook.owner, thehook.aiment) || autocvar_g_vampirehook_teamheal) - if(GetResource(thehook.aiment, RES_HEALTH) > 0) - if(autocvar_g_vampirehook_damage) + if (!autocvar_g_vampirehook_damage || thehook.last_dmg > time || time < game_starttime) + return; + + entity hook_owner = thehook.owner; + entity hook_aiment = thehook.aiment; + + if (IS_PLAYER(hook_aiment) && !STAT(FROZEN, hook_aiment) + && (DIFF_TEAM(hook_owner, hook_aiment) || autocvar_g_vampirehook_teamheal) + && GetResource(hook_aiment, RES_HEALTH) > 0) { thehook.last_dmg = time + autocvar_g_vampirehook_damagerate; - thehook.owner.hitsound_damage_dealt += autocvar_g_vampirehook_damage; - Damage(dmgent, thehook, thehook.owner, autocvar_g_vampirehook_damage, WEP_HOOK.m_id, DMG_NOWEP, thehook.origin, '0 0 0'); - entity targ = ((SAME_TEAM(thehook.owner, thehook.aiment)) ? thehook.aiment : thehook.owner); + hook_owner.hitsound_damage_dealt += autocvar_g_vampirehook_damage; + entity dmgent = ((SAME_TEAM(hook_owner, hook_aiment) && autocvar_g_vampirehook_teamheal) ? hook_owner : hook_aiment); + Damage(dmgent, thehook, hook_owner, autocvar_g_vampirehook_damage, WEP_HOOK.m_id, DMG_NOWEP, thehook.origin, '0 0 0'); + entity targ = ((SAME_TEAM(hook_owner, hook_aiment)) ? hook_aiment : hook_owner); // TODO: we can't do this due to an issue with globals and the mutator arguments - //Heal(targ, thehook.owner, autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); + //Heal(targ, hook_owner, autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); SetResourceExplicit(targ, RES_HEALTH, min(GetResource(targ, RES_HEALTH) + autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max)); - if(dmgent == thehook.owner) + if(dmgent == hook_owner) TakeResource(dmgent, RES_HEALTH, autocvar_g_vampirehook_damage); // FIXME: friendly fire?! } } diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index c2adabb1b..83b7a87da 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -154,7 +154,8 @@ float PlayerStats_GameReport_Event(string prefix, string event_id, float value) { if((prefix == "") || PS_GR_OUT_DB < 0) { return 0; } - string key = sprintf("%s:%s", prefix, event_id); + // use a cheaper strcat here since this function is called often in game + string key = strcat(prefix, ":", event_id); float val = stof(db_get(PS_GR_OUT_DB, key)); val += value; db_put(PS_GR_OUT_DB, key, ftos(val)); diff --git a/qcsrc/server/player.qc b/qcsrc/server/player.qc index a9ae47eb1..f251d55b0 100644 --- a/qcsrc/server/player.qc +++ b/qcsrc/server/player.qc @@ -608,7 +608,8 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, bool PlayerHeal(entity targ, entity inflictor, float amount, float limit) { - if(GetResource(targ, RES_HEALTH) <= 0 || GetResource(targ, RES_HEALTH) >= limit) + float hlth = GetResource(targ, RES_HEALTH); + if (hlth <= 0 || hlth >= limit) return false; GiveResourceWithLimit(targ, RES_HEALTH, amount, limit); -- 2.39.2