Merge branch 'master' into terencehill/ft_autorevive_progress
authorterencehill <piuntn@gmail.com>
Mon, 30 Sep 2019 18:07:27 +0000 (20:07 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 30 Sep 2019 18:07:27 +0000 (20:07 +0200)
# Conflicts:
# gamemodes-server.cfg

gamemodes-server.cfg
qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc
qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qh
qcsrc/server/g_damage.qc
qcsrc/server/player.qc

index 6d8ee6f07364532ee1ecb47cc6e051b8a4181823..d5eb85d649c63a5aceb34186c9338f5b1e03333b 100644 (file)
@@ -368,6 +368,10 @@ set g_freezetag_revive_extra_size 100 "Distance in qu that you can stand from a
 set g_freezetag_revive_nade 1 "Enable reviving from own nade explosion"
 set g_freezetag_revive_nade_health 40 "Amount of health player has if they revived from their own nade explosion"
 set g_freezetag_round_timelimit 360 "round time limit in seconds"
+set g_freezetag_revive_auto 1 "automatically revive frozen players after some time (g_freezetag_frozen_maxtime)"
+set g_freezetag_revive_auto_progress 1 "start the automatic reviving progress as soon as the player gets frozen"
+set g_freezetag_revive_auto_reducible 1 "reduce auto-revival time when frozen players are hit by enemies; if cvar value is negative reduce time even when they are hit by teammates"
+set g_freezetag_revive_auto_reducible_forcefactor 0.025 "hit force to time reduction conversion factor"
 set g_freezetag_frozen_maxtime 60 "frozen players will be automatically unfrozen after this time in seconds"
 set g_freezetag_teams_override 0
 set g_freezetag_team_spawns 0 "when 1, players spawn from the team spawnpoints of the map, if any"
index 54f6268e36da53d537e2effef2c5c72c62afadbf..bf336caf98fddfc9c371728cedd1096eebcce0d0 100644 (file)
@@ -198,7 +198,8 @@ void freezetag_Freeze(entity targ, entity attacker)
        if(STAT(FROZEN, targ))
                return;
 
-       if(autocvar_g_freezetag_frozen_maxtime > 0)
+       targ.freezetag_frozen_time = time;
+       if (autocvar_g_freezetag_revive_auto && autocvar_g_freezetag_frozen_maxtime > 0)
                targ.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
 
        Freeze(targ, 0, FROZEN_NORMAL, true);
@@ -454,6 +455,30 @@ MUTATOR_HOOKFUNCTION(ft, Unfreeze)
        targ.freezetag_frozen_timeout = 0;
 }
 
+MUTATOR_HOOKFUNCTION(ft, Damage_Calculate)
+{
+       entity frag_attacker = M_ARGV(1, entity);
+       entity frag_target = M_ARGV(2, entity);
+       //float frag_deathtype = M_ARGV(3, float);
+       //float frag_damage = M_ARGV(4, float);
+       vector frag_force = M_ARGV(6, vector);
+
+       if (STAT(FROZEN, frag_target) == FROZEN_NORMAL && autocvar_g_freezetag_revive_auto_reducible
+               && autocvar_g_freezetag_frozen_maxtime > 0 && autocvar_g_freezetag_revive_auto)
+       {
+               float t = 0;
+               if ((autocvar_g_freezetag_revive_auto_reducible > 0 || DIFF_TEAM(frag_attacker, frag_target))
+                       && frag_target.freezetag_frozen_timeout > time)
+               {
+                       if (fabs(autocvar_g_freezetag_revive_auto_reducible) == 1)
+                               t = vlen(frag_force) * autocvar_g_freezetag_revive_auto_reducible_forcefactor;
+                       frag_target.freezetag_frozen_timeout -= t;
+                       if (frag_target.freezetag_frozen_timeout < time)
+                               frag_target.freezetag_frozen_timeout = time;
+               }
+       }
+}
+
 #ifdef IS_REVIVING
        #undef IS_REVIVING
 #endif
@@ -499,30 +524,38 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
                        reviving_players_last.chain = NULL;
        }
 
+       float base_progress = 0;
+       if  (STAT(FROZEN, player) == FROZEN_NORMAL && autocvar_g_freezetag_revive_auto
+               && autocvar_g_freezetag_frozen_maxtime > 0 && autocvar_g_freezetag_revive_auto_progress)
+       {
+               base_progress = bound(0, (1 - (player.freezetag_frozen_timeout - time) / autocvar_g_freezetag_frozen_maxtime), 1);
+       }
+
        if (!n) // no teammate nearby
        {
                if (STAT(FROZEN, player) == FROZEN_NORMAL)
                {
-                       STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
+                       STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
                        SetResourceExplicit(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health)));
                }
                else if (!STAT(FROZEN, player))
-                       STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
+                       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(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
+               STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
                SetResourceExplicit(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health)));
 
                if(STAT(REVIVE_PROGRESS, player) >= 1)
                {
+                       float frozen_time = time - player.freezetag_frozen_time;
                        Unfreeze(player, false);
                        freezetag_count_alive_players();
 
                        if(n == -1)
                        {
-                               Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
-                               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, player.netname, autocvar_g_freezetag_frozen_maxtime);
+                               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;
                        }
 
index 3eb753020b35a857da4cde61e2b9b95879727c47..e749d1ab6eb85893464fbd9f7323d6b8ee2fbb80 100644 (file)
@@ -31,6 +31,10 @@ const float ICE_MAX_ALPHA = 1;
 const float ICE_MIN_ALPHA = 0.1;
 float freezetag_teams;
 
+bool autocvar_g_freezetag_revive_auto;
+int autocvar_g_freezetag_revive_auto_progress;
+int autocvar_g_freezetag_revive_auto_reducible;
+float autocvar_g_freezetag_revive_auto_reducible_forcefactor;
 float autocvar_g_freezetag_revive_extra_size;
 float autocvar_g_freezetag_revive_speed;
 bool autocvar_g_freezetag_revive_nade;
index e14ecd6ce7808ebeeca7dd436dc1aa4d41db2127..d375baa440d41328f318fa8ccfa307757daea696 100644 (file)
@@ -610,7 +610,7 @@ void Damage(entity targ, entity inflictor, entity attacker, float damage, int de
                                damage = 0;
                                force = '0 0 0';
                        }
-                       else if(SAME_TEAM(attacker, targ))
+                       else if(!STAT(FROZEN, targ) && SAME_TEAM(attacker, targ))
                        {
                                if(autocvar_teamplay_mode == 1)
                                        damage = 0;
@@ -777,7 +777,7 @@ void Damage(entity targ, entity inflictor, entity attacker, float damage, int de
 
                        if(IS_PLAYER(victim) || (IS_TURRET(victim) && victim.active == ACTIVE_ACTIVE) || IS_MONSTER(victim) || MUTATOR_CALLHOOK(PlayHitsound, victim, attacker))
                        {
-                               if(DIFF_TEAM(victim, attacker) && !STAT(FROZEN, victim))
+                               if (DIFF_TEAM(victim, attacker))
                                {
                                        if(damage > 0)
                                        {
@@ -800,11 +800,9 @@ void Damage(entity targ, entity inflictor, entity attacker, float damage, int de
                                                }
                                        }
                                }
-                               else if(IS_PLAYER(attacker))
+                               else if (IS_PLAYER(attacker) && !STAT(FROZEN, victim)) // same team
                                {
-                                       // if enemy gets frozen in this frame and receives other damage don't
-                                       // play the typehitsound e.g. when hit by multiple bullets of the shotgun
-                                       if (deathtype != DEATH_FIRE.m_id && (!STAT(FROZEN, victim) || time > victim.freeze_time))
+                                       if (deathtype != DEATH_FIRE.m_id)
                                        {
                                                attacker.typehitsound += 1;
                                        }
index 9e67050cb654b23c9847c8b2e94bda0f1898b106..8dffbc8ba61fb96bbbe7572a21be2e08b26b3e85 100644 (file)
@@ -411,7 +411,8 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage,
        if (take > 100)
                Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
 
-       if (time >= this.spawnshieldtime || autocvar_g_spawnshield_blockdamage < 1)
+       if ((time >= this.spawnshieldtime || autocvar_g_spawnshield_blockdamage < 1)
+               && !STAT(FROZEN, this))
        {
                if (!(this.flags & FL_GODMODE))
                {
@@ -493,7 +494,7 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage,
        if(vbot || IS_REAL_CLIENT(this))
        if(abot || IS_REAL_CLIENT(attacker))
        if(attacker && this != attacker)
-       if(DIFF_TEAM(this, attacker))
+       if (DIFF_TEAM(this, attacker) && (!STAT(FROZEN, this) || this.freeze_time > time))
        {
                if(DEATH_ISSPECIAL(deathtype))
                        awep = attacker.(weaponentity).m_weapon;
@@ -502,8 +503,8 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage,
                valid_damage_for_weaponstats = true;
        }
 
-       dh = dh - max(GetResource(this, RES_HEALTH), 0);
-       da = da - max(GetResource(this, RES_ARMOR), 0);
+       dh -= max(GetResource(this, RES_HEALTH), 0); // health difference
+       da -= max(GetResource(this, RES_ARMOR), 0); // armor difference
        if(valid_damage_for_weaponstats)
        {
                WeaponStats_LogDamage(awep.m_id, abot, this.(weaponentity).m_weapon.m_id, vbot, dh + da);