]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make use of a temporary intrusive list to avoid checking revivng players twice for...
authorterencehill <piuntn@gmail.com>
Thu, 27 Sep 2018 13:28:19 +0000 (15:28 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 27 Sep 2018 13:28:19 +0000 (15:28 +0200)
qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc
qcsrc/common/mutators/mutator/nades/nades.qc

index 7980399f64f49eeb8d396cd658f620fa425d8eb5..0b87c03bd1489cba14f3bca30d31604534c7b65a 100644 (file)
@@ -473,21 +473,23 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
                return true;
 
        int n;
-       entity o = NULL;
-       vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
        entity player = M_ARGV(0, entity);
        //if (STAT(FROZEN, player) == FROZEN_NORMAL)
        //if(player.freezetag_frozen_timeout > 0 && time < player.freezetag_frozen_timeout)
                //player.iceblock.alpha = ICE_MIN_ALPHA + (ICE_MAX_ALPHA - ICE_MIN_ALPHA) * (player.freezetag_frozen_timeout - time) / (player.freezetag_frozen_timeout - player.freezetag_frozen_time);
 
+       IntrusiveList reviving_players = NULL;
+
        if(player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
                n = -1;
        else
        {
                n = 0;
+               vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
                FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
-                       if(!o)
-                               o = it;
+                       if (!reviving_players)
+                               reviving_players = IL_NEW();
+                       IL_PUSH(reviving_players, it);
                        ++n;
                });
        }
@@ -520,22 +522,25 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
                        }
 
                        // EVERY team mate nearby gets a point (even if multiple!)
-                       FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
+                       IL_EACH(reviving_players, true, {
                                GameRules_scoring_add(it, FREEZETAG_REVIVALS, +1);
                                GameRules_scoring_add(it, SCORE, +1);
                                nades_GiveBonus(it, autocvar_g_nades_bonus_score_low);
                        });
 
-                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
-                       Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
-                       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED, player.netname, o.netname);
+                       entity first = IL_FIRST(reviving_players);
+                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, first.netname);
+                       Send_Notification(NOTIF_ONE, first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
+                       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED, player.netname, first.netname);
                }
 
-               FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
+               IL_EACH(reviving_players, true, {
                        STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
                });
        }
 
+       if (reviving_players)
+               IL_DELETE(reviving_players);
        return true;
 }
 
index 93a45fb3d59e1239a4fc339fadbbe1fd56616a23..b4a3066fb04a17621faa46e165db9160320e9308 100644 (file)
@@ -1338,16 +1338,19 @@ MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
        }
 
        int n = 0;
-       entity o = NULL;
-       vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
+
+       IntrusiveList reviving_players = NULL;
+
        if(player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
                n = -1;
        else if (STAT(FROZEN, player) == FROZEN_TEMP_DYING)
        {
+               vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
                n = 0;
                FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
-                       if(!o)
-                               o = it;
+                       if (!reviving_players)
+                               reviving_players = IL_NEW();
+                       IL_PUSH(reviving_players, it);
                        ++n;
                });
        }
@@ -1361,14 +1364,17 @@ MUTATOR_HOOKFUNCTION(nades, PlayerPreThink)
                {
                        Unfreeze(player, false);
 
-                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
-                       Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
+                       entity first = IL_FIRST(reviving_players);
+                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, first.netname);
+                       Send_Notification(NOTIF_ONE, first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
                }
 
-               FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
+               IL_EACH(reviving_players, true, {
                        STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
                });
        }
+       if (reviving_players)
+               IL_DELETE(reviving_players);
 }
 
 MUTATOR_HOOKFUNCTION(nades, PlayerPhysics_UpdateStats)