]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc
Freezetag: use an alternative lower revive speed if g_freezetag_revive_time_to_score...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / freezetag / sv_freezetag.qc
index 9bba0b3e5414e891c48b9b05c8d9dd867da742a6..2b87c34533c320ac26e984a54007fbb62d84c630 100644 (file)
@@ -514,13 +514,12 @@ MUTATOR_HOOKFUNCTION(ft, Damage_Calculate)
        }
 }
 
-#ifdef IS_REVIVING
-       #undef IS_REVIVING
+#ifdef IN_REVIVING_RANGE
+       #undef IN_REVIVING_RANGE
 #endif
 
-// returns true if player is reviving it
-#define IS_REVIVING(player, it, revive_extra_size) \
-       (it != player && !STAT(FROZEN, it) && !IS_DEAD(it) && SAME_TEAM(it, player) \
+#define IN_REVIVING_RANGE(player, it, revive_extra_size) \
+       (it != player && !IS_DEAD(it) && SAME_TEAM(it, player) \
        && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
 
 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
@@ -542,12 +541,30 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
        if (!(frametime && IS_PLAYER(player)))
                return true;
 
-       entity reviving_players_last = NULL;
-       entity reviving_players_first = NULL;
+       entity revivers_last = NULL;
+       entity revivers_first = NULL;
 
+       bool player_is_reviving = false;
        int 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), {
+       FOREACH_CLIENT(IS_PLAYER(it), {
+               // check if player is reviving anyone
+               if (STAT(FROZEN, it) == FROZEN_NORMAL)
+               {
+                       if ((STAT(FROZEN, player) == FROZEN_NORMAL))
+                               continue;
+                       if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
+                               continue;
+                       player_is_reviving = true;
+                       break;
+               }
+
+               if (!(STAT(FROZEN, player) == FROZEN_NORMAL))
+                       continue; // both player and it are NOT frozen
+               if (!IN_REVIVING_RANGE(player, it, revive_extra_size))
+                       continue;
+
+               // found a teammate that is reviving player
                if (autocvar_g_freezetag_revive_time_to_score > 0 && STAT(FROZEN, player) == FROZEN_NORMAL)
                {
                        it.freezetag_revive_time += frametime / autocvar_g_freezetag_revive_time_to_score;
@@ -557,18 +574,19 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
                                it.freezetag_revive_time -= 1;
                        }
                }
-               if (reviving_players_last)
-                       reviving_players_last.chain = it;
-               reviving_players_last = it;
-               if (!reviving_players_first)
-                       reviving_players_first = it;
+               if (revivers_last)
+                       revivers_last.chain = it;
+               revivers_last = it;
+               if (!revivers_first)
+                       revivers_first = it;
                ++n;
        });
-       if (reviving_players_last)
-               reviving_players_last.chain = NULL;
+       if (revivers_last)
+               revivers_last.chain = NULL;
 
        // allow normal revival during automatic revival
-       // (not allowing it IS_REVIVING should check freezetag_frozen_timeout too)
+       // (if we wouldn't allow it then freezetag_frozen_timeout should be checked too in the previous loop)
+       //if (STAT(FROZEN, player) == FROZEN_NORMAL) // redundant check
        if (!n && player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
                n = -1;
 
@@ -600,12 +618,15 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
                        else
                                STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) - frametime * clearspeed * (1 - base_progress), 1);
                }
-               else if (!STAT(FROZEN, player))
+               else if (!STAT(FROZEN, player) && !player_is_reviving)
                        STAT(REVIVE_PROGRESS, player) = base_progress; // thawing nobody
        }
        else if (STAT(FROZEN, player) == FROZEN_NORMAL) // OK, there is at least one teammate reviving us
        {
-               STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed * (1 - base_progress)), 1);
+               float spd = autocvar_g_freezetag_revive_speed_t2s;
+               if (autocvar_g_freezetag_revive_time_to_score <= 0)
+                       spd = autocvar_g_freezetag_revive_speed * (1 - base_progress);
+               STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, spd), 1);
 
                if(STAT(REVIVE_PROGRESS, player) >= 1)
                {
@@ -617,13 +638,15 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
 
                        if(n == -1)
                        {
+                               if(autocvar_sv_eventlog)
+                                       GameLogEcho(strcat(":ft:autorevival:", ftos(player.playerid)));
                                Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, frozen_time);
                                Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, player.netname, frozen_time);
                                return true;
                        }
 
                        // EVERY team mate nearby gets a point (even if multiple!)
-                       for(entity it = reviving_players_first; it; it = it.chain)
+                       for(entity it = revivers_first; it; it = it.chain)
                        {
                                GameRules_scoring_add(it, FREEZETAG_REVIVALS, +1);
                                if (autocvar_g_freezetag_revive_time_to_score <= 0)
@@ -631,13 +654,20 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
                                nades_GiveBonus(it, autocvar_g_nades_bonus_score_low);
                        }
 
-                       entity first = reviving_players_first;
-                       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);
+                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, revivers_first.netname);
+                       Send_Notification(NOTIF_ONE, revivers_first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
+                       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED, player.netname, revivers_first.netname);
+                       if(autocvar_sv_eventlog)
+                       {
+                               string revivers = "";
+                               for(entity it = revivers_first; it; it = it.chain)
+                                       revivers = strcat(revivers, ftos(it.playerid), ",");
+                               revivers = substring(revivers, 0, strlen(revivers) - 1);
+                               GameLogEcho(strcat(":ft:revival:", ftos(player.playerid), ":", revivers));
+                       }
                }
 
-               for(entity it = reviving_players_first; it; it = it.chain)
+               for(entity it = revivers_first; it; it = it.chain)
                        STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
        }
 
@@ -745,7 +775,7 @@ void freezetag_Initialize()
                freezetag_teams = cvar("g_freezetag_teams"); // read the cvar directly as it gets written earlier in the same frame
 
        freezetag_teams = BITS(bound(2, freezetag_teams, 4));
-       GameRules_scoring(freezetag_teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, {
+       GameRules_scoring(freezetag_teams, SFL_SORT_PRIO_PRIMARY, 0, {
                field_team(ST_FT_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY);
                field(SP_FREEZETAG_REVIVALS, "revivals", 0);
        });