]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/teamplay.qc
Merge branch 'TimePath/gamerules' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / teamplay.qc
index 0918130159a737e83e63f5bd076af7320e3dc533..e93a03201a9ddf4233b229126b69d15bca035de6 100644 (file)
@@ -37,13 +37,6 @@ void default_delayedinit(entity this)
                ScoreRules_generic();
 }
 
-void ActivateTeamplay()
-{
-       serverflags |= SERVERFLAG_TEAMPLAY;
-       teamplay = 1;
-       cvar_set("teamplay", "2");  // DP needs this for sending proper getstatus replies.
-}
-
 void InitGameplayMode()
 {
        VoteReset();
@@ -52,15 +45,18 @@ void InitGameplayMode()
        get_mi_min_max(1);
        world.mins = mi_min;
        world.maxs = mi_max;
+       // currently, NetRadiant's limit is 131072 qu for each side
+       // distance from one corner of a 131072qu cube to the opposite corner is approx. 227023 qu
+       // set the distance according to map size but don't go over the limit to avoid issues with float precision
+       // in case somebody makes extremely large maps
+       max_shot_distance = min(230000, vlen(world.maxs - world.mins));
 
        MapInfo_LoadMapSettings(mapname);
-       serverflags &= ~SERVERFLAG_TEAMPLAY;
-       teamplay = 0;
-       cvar_set("teamplay", "0");  // DP needs this for sending proper getstatus replies.
+       GameRules_teams(false);
 
        if (!cvar_value_issafe(world.fog))
        {
-               LOG_INFO("The current map contains a potentially harmful fog setting, ignored\n");
+               LOG_INFO("The current map contains a potentially harmful fog setting, ignored");
                world.fog = string_null;
        }
        if(MapInfo_Map_fog != "")
@@ -82,25 +78,23 @@ void InitGameplayMode()
 
 string GetClientVersionMessage(entity this)
 {
-       string versionmsg;
-       if (this.version_mismatch) {
-               if(this.version < autocvar_gameversion) {
-                       versionmsg = "^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8";
+       if (CS(this).version_mismatch) {
+               if(CS(this).version < autocvar_gameversion) {
+                       return strcat("This is Xonotic ", autocvar_g_xonoticversion,
+                               "\n^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8");
                } else {
-                       versionmsg = "^3This server is using an outdated Xonotic version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8";
+                       return strcat("This is Xonotic ", autocvar_g_xonoticversion,
+                               "\n^3This server is using an outdated Xonotic version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8");
                }
        } else {
-               versionmsg = "^2client version and server version are compatible.^8";
+               return strcat("Welcome to Xonotic ", autocvar_g_xonoticversion);
        }
-       return versionmsg;
 }
 
 string getwelcomemessage(entity this)
 {
-       string s, modifications, motd;
-
        MUTATOR_CALLHOOK(BuildMutatorsPrettyString, "");
-       modifications = M_ARGV(0, string);
+       string modifications = M_ARGV(0, string);
 
        if(g_weaponarena)
        {
@@ -124,9 +118,7 @@ string getwelcomemessage(entity this)
        modifications = substring(modifications, 2, strlen(modifications) - 2);
 
        string versionmessage = GetClientVersionMessage(this);
-
-       s = strcat("This is Xonotic ", autocvar_g_xonoticversion, "\n", versionmessage);
-       s = strcat(s, "^8\n\nmatch type is ^1", gamemode_name, "^8\n");
+       string s = strcat(versionmessage, "^8\n^8\nmatch type is ^1", gamemode_name, "^8\n");
 
        if(modifications != "")
                s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
@@ -151,7 +143,7 @@ string getwelcomemessage(entity this)
 
        s = strcat(s, mutator_msg); // trust that the mutator will do proper formatting
 
-       motd = autocvar_sv_motd;
+       string motd = autocvar_sv_motd;
        if (motd != "") {
                s = strcat(s, "\n\n^8MOTD: ^7", strreplace("\\n", "\n", motd));
        }
@@ -208,7 +200,7 @@ void SetPlayerTeam(entity pl, float t, float s, float noprint)
                LogTeamchange(pl.playerid, pl.team, 3);  // log manual team join
 
                if(!noprint)
-               bprint(pl.netname, "^7 has changed from ", Team_NumberToColoredFullName(s), "^7 to ", Team_NumberToColoredFullName(t), "\n");
+                       bprint(playername(pl, false), "^7 has changed from ", Team_NumberToColoredFullName(s), "^7 to ", Team_NumberToColoredFullName(t), "\n");
        }
 
 }
@@ -223,7 +215,7 @@ void CheckAllowedTeams (entity for_whom)
 
        string teament_name = string_null;
 
-       bool mutator_returnvalue = MUTATOR_CALLHOOK(CheckAllowedTeams, teams_mask, teament_name);
+       bool mutator_returnvalue = MUTATOR_CALLHOOK(CheckAllowedTeams, teams_mask, teament_name, for_whom);
        teams_mask = M_ARGV(0, float);
        teament_name = M_ARGV(1, string);
 
@@ -327,7 +319,7 @@ void GetTeamCounts(entity ignore)
        // FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
        // also remember the lowest-scoring player
 
-       FOREACH_CLIENT(true, LAMBDA(
+       FOREACH_CLIENT(true, {
                float t;
                if(IS_PLAYER(it) || it.caplayer)
                        t = it.team;
@@ -350,7 +342,7 @@ void GetTeamCounts(entity ignore)
                                        cb1 = cb1 + bvalue;
                                }
                        }
-                       if(t == NUM_TEAM_2)
+                       else if(t == NUM_TEAM_2)
                        {
                                if(c2 >= 0)
                                {
@@ -358,7 +350,7 @@ void GetTeamCounts(entity ignore)
                                        cb2 = cb2 + bvalue;
                                }
                        }
-                       if(t == NUM_TEAM_3)
+                       else if(t == NUM_TEAM_3)
                        {
                                if(c3 >= 0)
                                {
@@ -366,7 +358,7 @@ void GetTeamCounts(entity ignore)
                                        cb3 = cb3 + bvalue;
                                }
                        }
-                       if(t == NUM_TEAM_4)
+                       else if(t == NUM_TEAM_4)
                        {
                                if(c4 >= 0)
                                {
@@ -375,7 +367,7 @@ void GetTeamCounts(entity ignore)
                                }
                        }
                }
-       ));
+       });
 
        // if the player who has a forced team has not joined yet, reserve the spot
        if(autocvar_g_campaign)
@@ -649,7 +641,7 @@ void SV_ChangeTeam(entity this, float _color)
                return;
        }
 
-       if((autocvar_g_campaign) || (autocvar_g_changeteam_banned && this.wasplayer)) {
+       if((autocvar_g_campaign) || (autocvar_g_changeteam_banned && CS(this).wasplayer)) {
                Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_NOTALLOWED);
                return; // changing teams is not allowed
        }
@@ -736,7 +728,7 @@ void ShufflePlayerOutOfTeam (float source_team)
        lowest_player_score = 999999999;
 
        // find the lowest-scoring player & bot of that team
-       FOREACH_CLIENT(IS_PLAYER(it) && it.team == steam, LAMBDA(
+       FOREACH_CLIENT(IS_PLAYER(it) && it.team == steam, {
                if(it.isbot)
                {
                        if(it.totalfrags < lowest_bot_score)
@@ -753,7 +745,7 @@ void ShufflePlayerOutOfTeam (float source_team)
                                lowest_player_score = it.totalfrags;
                        }
                }
-       ));
+       });
 
        // prefers to move a bot...
        if(lowest_bot != NULL)