Merge branch 'master' into Mario/monsters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_freezetag.qc
index 0c22db0..c1cb5b8 100644 (file)
@@ -1,7 +1,6 @@
 .float freezetag_frozen_time;
 .float freezetag_frozen_timeout;
 .float freezetag_revive_progress;
-.entity freezetag_ice;
 #define ICE_MAX_ALPHA 1
 #define ICE_MIN_ALPHA 0.1
 float freezetag_teams;
@@ -14,22 +13,22 @@ void freezetag_count_alive_players()
                if(e.team == NUM_TEAM_1 && e.health >= 1)
                {
                        ++total_players;
-                       if (!e.freezetag_frozen) ++redalive;
+                       if (e.frozen != 1) ++redalive;
                }
                else if(e.team == NUM_TEAM_2 && e.health >= 1)
                {
                        ++total_players;
-                       if (!e.freezetag_frozen) ++bluealive;
+                       if (e.frozen != 1) ++bluealive;
                }
                else if(e.team == NUM_TEAM_3 && e.health >= 1)
                {
                        ++total_players;
-                       if (!e.freezetag_frozen) ++yellowalive;
+                       if (e.frozen != 1) ++yellowalive;
                }
                else if(e.team == NUM_TEAM_4 && e.health >= 1)
                {
                        ++total_players;
-                       if (!e.freezetag_frozen) ++pinkalive;
+                       if (e.frozen != 1) ++pinkalive;
                }
        }
        FOR_EACH_REALCLIENT(e) {
@@ -128,15 +127,6 @@ float freezetag_CheckWinner()
        return 1;
 }
 
-// this is needed to allow the player to turn his view around (fixangle can't
-// be used to freeze his view, as that also changes the angles), while not
-// turning that ice object with the player
-void freezetag_Ice_Think()
-{
-       setorigin(self, self.owner.origin - '0 0 16');
-       self.nextthink = time;
-}
-
 void freezetag_Add_Score(entity attacker)
 {
        if(attacker == self)
@@ -157,54 +147,24 @@ void freezetag_Add_Score(entity attacker)
 
 void freezetag_Freeze(entity attacker)
 {
-       if(self.freezetag_frozen)
+       if(self.frozen)
                return;
-       self.freezetag_frozen = 1;
-       self.freezetag_frozen_time = time;
-       self.freezetag_revive_progress = 0;
-       self.health = 1;
-       if(autocvar_g_freezetag_frozen_maxtime > 0)
-               self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
-
+       
+       Freeze(self, 0, 1, TRUE);
+       
        freezetag_count_alive_players();
 
-       entity ice;
-       ice = spawn();
-       ice.owner = self;
-       ice.classname = "freezetag_ice";
-       ice.think = freezetag_Ice_Think;
-       ice.nextthink = time;
-       ice.frame = floor(random() * 21); // ice model has 20 different looking frames
-       ice.alpha = ICE_MAX_ALPHA;
-       ice.colormod = Team_ColorRGB(self.team);
-       ice.glowmod = ice.colormod;
-       setmodel(ice, "models/ice/ice.md3");
-
-       self.freezetag_ice = ice;
-
-       RemoveGrapplingHook(self);
-
-       // add waypoint
-       WaypointSprite_Spawn("freezetag_frozen", 0, 0, self, '0 0 64', world, self.team, self, waypointsprite_attached, TRUE, RADARICON_WAYPOINT, '0.25 0.90 1');
-
        freezetag_Add_Score(attacker);
 }
 
 void freezetag_Unfreeze(entity attacker)
 {
-       self.freezetag_frozen = 0;
        self.freezetag_frozen_time = 0;
        self.freezetag_frozen_timeout = 0;
-       self.freezetag_revive_progress = 0;
-
-       remove(self.freezetag_ice);
-       self.freezetag_ice = world;
-
-       if(self.waypointsprite_attached)
-               WaypointSprite_Kill(self.waypointsprite_attached);
+       
+       Unfreeze(self);
 }
 
-
 // ================
 // Bot player logic
 // ================
@@ -221,7 +181,7 @@ void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradiu
        {
                if ((head != self) && (head.team == self.team))
                {
-                       if (head.freezetag_frozen)
+                       if (head.frozen == 1)
                        {
                                distance = vlen(head.origin - org);
                                if (distance > sradius)
@@ -253,12 +213,12 @@ void havocbot_role_ft_offense()
        unfrozen = 0;
        FOR_EACH_PLAYER(head)
        {
-               if ((head.team == self.team) && (!head.freezetag_frozen))
+               if ((head.team == self.team) && (head.frozen != 1))
                        unfrozen++;
        }
 
        // If only one left on team or if role has timed out then start trying to free players.
-       if (((unfrozen == 0) && (!self.freezetag_frozen)) || (time > self.havocbot_role_timeout))
+       if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
        {
                dprint("changing role to freeing\n");
                self.havocbot_role = havocbot_role_ft_freeing;
@@ -326,7 +286,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
        if(round_handler_IsActive())
        if(round_handler_CountdownRunning())
        {
-               if(self.freezetag_frozen)
+               if(self.frozen)
                        freezetag_Unfreeze(world);
                freezetag_count_alive_players();
                return 1; // let the player die so that he can respawn whenever he wants
@@ -338,7 +298,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
                || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
        {
                // let the player die, he will be automatically frozen when he respawns
-               if(!self.freezetag_frozen)
+               if(self.frozen != 1)
                {
                        freezetag_Add_Score(frag_attacker);
                        freezetag_count_alive_players();
@@ -349,7 +309,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
                return 1;
        }
 
-       if(self.freezetag_frozen)
+       if(self.frozen)
                return 1;
 
        freezetag_Freeze(frag_attacker);
@@ -369,8 +329,6 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
                Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
        }
 
-       frag_target.health = 1; // "respawn" the player :P
-
        return 1;
 }
 
@@ -401,7 +359,7 @@ MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
 {
        FOR_EACH_PLAYER(self)
        {
-               if (self.freezetag_frozen)
+               if (self.frozen)
                        freezetag_Unfreeze(world);
                self.freezetag_frozen_timeout = -1;
                PutClientInServer();
@@ -425,7 +383,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
        if(gameover)
                return 1;
 
-       if(self.freezetag_frozen)
+       if(self.frozen == 1)
        {
                // keep health = 1
                self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
@@ -438,7 +396,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
        entity o;
        o = world;
        if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
-               self.freezetag_ice.alpha = ICE_MIN_ALPHA + (ICE_MAX_ALPHA - ICE_MIN_ALPHA) * (self.freezetag_frozen_timeout - time) / (self.freezetag_frozen_timeout - self.freezetag_frozen_time);
+               self.iceblock.alpha = ICE_MIN_ALPHA + (ICE_MAX_ALPHA - ICE_MIN_ALPHA) * (self.freezetag_frozen_timeout - time) / (self.freezetag_frozen_timeout - self.freezetag_frozen_time);
 
        if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
                n = -1;
@@ -448,15 +406,15 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
                n = 0;
                FOR_EACH_PLAYER(other) if(self != other)
                {
-                       if(other.freezetag_frozen == 0)
+                       if(other.frozen == 0)
                        {
-                               if(other.team == self.team)
+                               if(SAME_TEAM(other, self))
                                {
                                        if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
                                        {
                                                if(!o)
                                                        o = other;
-                                               if(self.freezetag_frozen)
+                                               if(self.frozen == 1)
                                                        other.reviving = TRUE;
                                                ++n;
                                        }
@@ -465,12 +423,12 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
                }
        }
 
-       if(n && self.freezetag_frozen) // OK, there is at least one teammate reviving us
+       if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
        {
-               self.freezetag_revive_progress = bound(0, self.freezetag_revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
-               self.health = max(1, self.freezetag_revive_progress * autocvar_g_balance_health_start);
+               self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
+               self.health = max(1, self.revive_progress * autocvar_g_balance_health_start);
 
-               if(self.freezetag_revive_progress >= 1)
+               if(self.revive_progress >= 1)
                {
                        freezetag_Unfreeze(self);
                        freezetag_count_alive_players();
@@ -501,45 +459,27 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
                {
                        if(other.reviving)
                        {
-                               other.freezetag_revive_progress = self.freezetag_revive_progress;
+                               other.revive_progress = self.revive_progress;
                                other.reviving = FALSE;
                        }
                }
        }
-       else if(!n && self.freezetag_frozen) // only if no teammate is nearby will we reset
+       else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
        {
-               self.freezetag_revive_progress = bound(0, self.freezetag_revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
-               self.health = max(1, self.freezetag_revive_progress * autocvar_g_balance_health_start);
+               self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
+               self.health = max(1, self.revive_progress * autocvar_g_balance_health_start);
        }
-       else if(!n)
+       else if(!n && !self.frozen)
        {
-               self.freezetag_revive_progress = 0; // thawing nobody
+               self.revive_progress = 0; // thawing nobody
        }
 
        return 1;
 }
 
-MUTATOR_HOOKFUNCTION(freezetag_PlayerPhysics)
-{
-       if(self.freezetag_frozen)
-       {
-               if(autocvar_sv_dodging_frozen && IS_REAL_CLIENT(self))
-               {
-                       self.movement_x = bound(-5, self.movement_x, 5);
-                       self.movement_y = bound(-5, self.movement_y, 5);
-                       self.movement_z = bound(-5, self.movement_z, 5);
-               }
-               else
-                       self.movement = '0 0 0';
-                       
-               self.disableclientprediction = 1;
-       }
-       return 1;
-}
-
 MUTATOR_HOOKFUNCTION(freezetag_PlayerDamage_Calculate)
 {
-       if(frag_target.freezetag_frozen && frag_deathtype != DEATH_HURTTRIGGER)
+       if(frag_target.frozen == 1 && frag_deathtype != DEATH_HURTTRIGGER)
        {
                if(autocvar_g_freezetag_revive_falldamage > 0)
                if(frag_deathtype == DEATH_FALL)
@@ -558,28 +498,6 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDamage_Calculate)
        return 1;
 }
 
-MUTATOR_HOOKFUNCTION(freezetag_PlayerJump)
-{
-       if(self.freezetag_frozen)
-               return TRUE; // no jumping in freezetag when frozen
-       
-       return FALSE;
-}
-
-MUTATOR_HOOKFUNCTION(freezetag_ForbidThrowCurrentWeapon)
-{
-       if (self.freezetag_frozen)
-               return 1;
-       return 0;
-}
-
-MUTATOR_HOOKFUNCTION(freezetag_ItemTouch)
-{
-       if (other.freezetag_frozen)
-               return MUT_ITEMTOUCH_RETURN;
-       return MUT_ITEMTOUCH_CONTINUE;
-}
-
 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
 {
        if not(self.deadflag)
@@ -593,13 +511,6 @@ MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
        return TRUE;
 }
 
-MUTATOR_HOOKFUNCTION(freezetag_SpectateCopy)
-{
-       self.freezetag_frozen = other.freezetag_frozen;
-       self.freezetag_revive_progress = other.freezetag_revive_progress;
-       return 0;
-}
-
 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
 {
        freezetag_teams = autocvar_g_freezetag_teams_override;
@@ -610,14 +521,6 @@ MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
        return 0;
 }
 
-MUTATOR_HOOKFUNCTION(freezetag_VehicleTouch)
-{
-       if(other.freezetag_frozen)
-               return TRUE;
-               
-       return FALSE;
-}
-
 void freezetag_Initialize()
 {
        precache_model("models/ice/ice.md3");
@@ -630,9 +533,6 @@ void freezetag_Initialize()
        addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
        addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
        addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
-
-       addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
-       addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
 }
 
 MUTATOR_DEFINITION(gamemode_freezetag)
@@ -644,15 +544,9 @@ MUTATOR_DEFINITION(gamemode_freezetag)
        MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
        MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
        MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
-       MUTATOR_HOOK(PlayerPhysics, freezetag_PlayerPhysics, CBC_ORDER_FIRST);
        MUTATOR_HOOK(PlayerDamage_Calculate, freezetag_PlayerDamage_Calculate, CBC_ORDER_ANY);
-       MUTATOR_HOOK(PlayerJump, freezetag_PlayerJump, CBC_ORDER_ANY);
-       MUTATOR_HOOK(ForbidThrowCurrentWeapon, freezetag_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
-       MUTATOR_HOOK(ItemTouch, freezetag_ItemTouch, CBC_ORDER_ANY);
        MUTATOR_HOOK(HavocBot_ChooseRule, freezetag_BotRoles, CBC_ORDER_ANY);
-       MUTATOR_HOOK(SpectateCopy, freezetag_SpectateCopy, CBC_ORDER_ANY);
        MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
-       MUTATOR_HOOK(VehicleTouch, freezetag_VehicleTouch, CBC_ORDER_ANY);
 
        MUTATOR_ONADD
        {