]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Slightly optimize 3 functions
authorterencehill <piuntn@gmail.com>
Sat, 13 Jul 2024 21:06:56 +0000 (23:06 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 13 Jul 2024 21:06:56 +0000 (23:06 +0200)
qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc
qcsrc/common/playerstats.qc
qcsrc/server/player.qc

index 48dcb68b11dd0d6e00eef5a6ed279f76d3f31fb6..1f5b9be6117ec0bd83482ee2cee3f43f3bd06aad 100644 (file)
@@ -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?!
        }
 }
index c2adabb1b601c415710a4768bbead49959c32934..83b7a87da4e8749e1fe06ed4d105b984e0919e1b 100644 (file)
@@ -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));
index a9ae47eb1e6ddaddeca3dfcf83aaa7022ce4197f..f251d55b0be16be0d40d1043db9dbb7c5b9ac52b 100644 (file)
@@ -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);