]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_freezetag.qc
Cleanup: replace a few checks with the macro IS_PLAYER
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_freezetag.qc
index 5ca9a2fd62354d2b3f1b91f171006316207dc2c4..6ba51a0b90776400c3951f46477c6876d0e9846f 100644 (file)
@@ -2,47 +2,31 @@
 .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;
 
-float freezetag_CheckTeams();
-float freezetag_CheckWinner();
-void freezetag_Initialize()
-{
-       precache_model("models/ice/ice.md3");
-       ScoreRules_freezetag();
-
-       round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null, 5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
-
-       addstat(STAT_REDALIVE, AS_INT, redalive_stat);
-       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);
-}
-
 void freezetag_count_alive_players()
 {
        entity e;
        total_players = redalive = bluealive = yellowalive = pinkalive = 0;
        FOR_EACH_PLAYER(e) {
-               if(e.team == COLOR_TEAM1 && e.health >= 1)
+               if(e.team == NUM_TEAM_1 && e.health >= 1)
                {
                        ++total_players;
                        if (!e.freezetag_frozen) ++redalive;
                }
-               else if(e.team == COLOR_TEAM2 && e.health >= 1)
+               else if(e.team == NUM_TEAM_2 && e.health >= 1)
                {
                        ++total_players;
                        if (!e.freezetag_frozen) ++bluealive;
                }
-               else if(e.team == COLOR_TEAM3 && e.health >= 1)
+               else if(e.team == NUM_TEAM_3 && e.health >= 1)
                {
                        ++total_players;
                        if (!e.freezetag_frozen) ++yellowalive;
                }
-               else if(e.team == COLOR_TEAM4 && e.health >= 1)
+               else if(e.team == NUM_TEAM_4 && e.health >= 1)
                {
                        ++total_players;
                        if (!e.freezetag_frozen) ++pinkalive;
@@ -61,30 +45,23 @@ void freezetag_count_alive_players()
 float prev_total_players;
 float freezetag_CheckTeams()
 {
-       entity e;
        if(FREEZETAG_ALIVE_TEAMS_OK())
        {
-               if(prev_total_players != -1)
-               {
-                       FOR_EACH_REALCLIENT(e)
-                               Send_CSQC_Centerprint_Generic_Expire(e, CPID_WAITING_PLAYERS);
-               }
+               if(prev_total_players > 0)
+                       Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
                prev_total_players = -1;
                return 1;
        }
        if(prev_total_players != total_players)
        {
-               string teams_missing = "";
-               if(!redalive)   teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM1), ", ");
-               if(!bluealive)  teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM2), ", ");
+               float p1 = 0, p2 = 0, p3 = 0, p4 = 0;
+               if(!redalive) p1 = NUM_TEAM_1;
+               if(!bluealive) p2 = NUM_TEAM_2;
                if(freezetag_teams >= 3)
-               if(!yellowalive)        teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM3), ", ");
-               if(freezetag_teams == 4)
-               if(!pinkalive)  teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM4), ", ");
-               teams_missing = substring(teams_missing, 0, strlen(teams_missing)-2);
-
-               FOR_EACH_REALCLIENT(e)
-                       Send_CSQC_Centerprint_Generic(e, CPID_WAITING_PLAYERS, strcat("Waiting for players to join...\n\nNeed active players for: ", teams_missing), -1, 0);
+               if(!yellowalive) p3 = NUM_TEAM_3;
+               if(freezetag_teams >= 4)
+               if(!pinkalive) p4 = NUM_TEAM_4;
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, p1, p2, p3, p4);
                prev_total_players = total_players;
        }
        return 0;
@@ -94,21 +71,21 @@ float freezetag_getWinnerTeam()
 {
        float winner_team = 0;
        if(redalive >= 1)
-               winner_team = COLOR_TEAM1;
+               winner_team = NUM_TEAM_1;
        if(bluealive >= 1)
        {
                if(winner_team) return 0;
-               winner_team = COLOR_TEAM2;
+               winner_team = NUM_TEAM_2;
        }
        if(yellowalive >= 1)
        {
                if(winner_team) return 0;
-               winner_team = COLOR_TEAM3;
+               winner_team = NUM_TEAM_3;
        }
        if(pinkalive >= 1)
        {
                if(winner_team) return 0;
-               winner_team = COLOR_TEAM4;
+               winner_team = NUM_TEAM_4;
        }
        if(winner_team)
                return winner_team;
@@ -120,11 +97,11 @@ float freezetag_CheckWinner()
        entity e;
        if(round_handler_GetTimeLeft() <= 0)
        {
-               FOR_EACH_REALCLIENT(e)
-                       centerprint(e, "Round over, there's no winner");
-               bprint("Round over, there's no winner.\n");
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
                FOR_EACH_PLAYER(e)
                        e.freezetag_frozen_timeout = 0;
+               round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
                return 1;
        }
 
@@ -132,25 +109,22 @@ float freezetag_CheckWinner()
                return 0;
 
        float winner_team;
-       string teamname;
        winner_team = freezetag_getWinnerTeam();
        if(winner_team > 0)
        {
-               teamname = ColoredTeamName(winner_team);
-               FOR_EACH_REALCLIENT(e)
-                       centerprint(e, strcat(teamname, "^5 wins the round, all other teams were frozen."));
-               bprint(teamname, "^5 wins the round since all the other teams were frozen.\n");
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
                TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
        }
        else if(winner_team == -1)
        {
-               FOR_EACH_REALCLIENT(e)
-                       centerprint(e, "^5Round tied! All teams were frozen.");
-               bprint("^5Round tied! All teams were frozen.\n");
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
        }
 
        FOR_EACH_PLAYER(e)
                e.freezetag_frozen_timeout = 0;
+       round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
        return 1;
 }
 
@@ -171,7 +145,7 @@ void freezetag_Add_Score(entity attacker)
                // counted as "suicide" already
                PlayerScore_Add(self, SP_SCORE, -1);
        }
-       else if(attacker.classname == "player")
+       else if(IS_PLAYER(attacker))
        {
                // got frozen by an enemy
                // counted as "kill" and "death" already
@@ -189,8 +163,8 @@ void freezetag_Freeze(entity attacker)
        self.freezetag_frozen_time = time;
        self.freezetag_revive_progress = 0;
        self.health = 1;
-       if(autocvar_g_freezetag_frozen_timeout > 0)
-               self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_timeout;
+       if(autocvar_g_freezetag_frozen_maxtime > 0)
+               self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
 
        freezetag_count_alive_players();
 
@@ -201,6 +175,9 @@ void freezetag_Freeze(entity attacker)
        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;
@@ -380,16 +357,16 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
        if(frag_attacker == frag_target || frag_attacker == world)
        {
                if(frag_target.classname == STR_PLAYER)
-                       centerprint(frag_target, "^1You froze yourself.\n");
-               bprint("^7", frag_target.netname, "^1 froze himself.\n");
+                       Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
        }
        else
        {
                if(frag_target.classname == STR_PLAYER)
-                       centerprint(frag_target, strcat("^1You were frozen by ^7", frag_attacker.netname, ".\n"));
+                       Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
                if(frag_attacker.classname == STR_PLAYER)
-                       centerprint(frag_attacker, strcat("^2You froze ^7", frag_target.netname, ".\n"));
-               bprint("^7", frag_target.netname, "^1 was frozen by ^7", frag_attacker.netname, ".\n");
+                       Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
        }
 
        frag_target.health = 1; // "respawn" the player :P
@@ -413,7 +390,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
        if(round_handler_IsActive())
        if(round_handler_IsRoundStarted())
        {
-               centerprint(self, "^1Round already started, you spawn as frozen.");
+               Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
                freezetag_Freeze(world);
        }
 
@@ -440,10 +417,10 @@ MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
        return 1;
 }
 
+.float reviving; // temp var
 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
 {
        float n;
-       vector revive_extra_size;
 
        if(gameover)
                return 1;
@@ -458,17 +435,16 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
        if(!round_handler_IsRoundStarted())
                return 1;
 
-       revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
-
        entity o;
        o = world;
        if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
-               self.freezetag_ice.alpha = 0.1 + (self.freezetag_frozen_timeout - time) / (self.freezetag_frozen_timeout - self.freezetag_frozen_time);
+               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);
 
        if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
                n = -1;
        else
        {
+               vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
                n = 0;
                FOR_EACH_PLAYER(other) if(self != other)
                {
@@ -480,6 +456,8 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
                                        {
                                                if(!o)
                                                        o = other;
+                                               if(self.freezetag_frozen)
+                                                       other.reviving = TRUE;
                                                ++n;
                                        }
                                }
@@ -499,49 +477,32 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
 
                        if(n == -1)
                        {
-                               string s = ftos(autocvar_g_freezetag_frozen_timeout);
-                               centerprint(self, strcat("^5You were automatically revived after ", s, " seconds^5.\n"));
-                               bprint("^7", self.netname, "^5 were automatically revived after ", s, " seconds^5.\n");
+                               Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
+                               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
                                return 1;
                        }
 
                        // EVERY team mate nearby gets a point (even if multiple!)
-                       FOR_EACH_PLAYER(other) if(self != other)
+                       FOR_EACH_PLAYER(other)
                        {
-                               if(other.freezetag_frozen == 0)
+                               if(other.reviving)
                                {
-                                       if(other.team == self.team)
-                                       {
-                                               if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
-                                               {
-                                                       PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
-                                                       PlayerScore_Add(other, SP_SCORE, +1);
-                                               }
-                                       }
+                                       PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
+                                       PlayerScore_Add(other, SP_SCORE, +1);
                                }
                        }
 
-                       if(n > 1)
-                               centerprint(self, strcat("^5You were revived by ^7", o.netname, "^5 et al.\n"));
-                       else
-                               centerprint(self, strcat("^5You were revived by ^7", o.netname, "^5.\n"));
-                       centerprint(o, strcat("^5You revived ^7", self.netname, "^5.\n"));
-                       if(n > 1)
-                               bprint("^7", o.netname, "^5 et al revived ^7", self.netname, "^5.\n");
-                       else
-                               bprint("^7", o.netname, "^5 revived ^7", self.netname, "^5.\n");
+                       Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
+                       Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
+                       Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
                }
 
-               // now find EVERY teammate within reviving radius, set their revive_progress values correct
-               FOR_EACH_PLAYER(other) if(self != other)
+               FOR_EACH_PLAYER(other)
                {
-                       if(other.freezetag_frozen == 0)
+                       if(other.reviving)
                        {
-                               if(other.team == self.team)
-                               {
-                                       if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
-                                               other.freezetag_revive_progress = self.freezetag_revive_progress;
-                               }
+                               other.freezetag_revive_progress = self.freezetag_revive_progress;
+                               other.reviving = FALSE;
                        }
                }
        }
@@ -615,6 +576,23 @@ MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
        return 0;
 }
 
+void freezetag_Initialize()
+{
+       precache_model("models/ice/ice.md3");
+       ScoreRules_freezetag();
+
+       round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
+       round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
+
+       addstat(STAT_REDALIVE, AS_INT, redalive_stat);
+       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)
 {
        MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);