X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fteamplay.qc;h=8709a6aae6b5be4cc0c1c61f54ef71a7a45d292c;hp=deb6032ce207a32b980a06804608cbd4303ad173;hb=3220cab5a7b69ced4a641504a6a5f4eccf2d3bfc;hpb=c1385b1eb134e4c40239273511fd63b97ff51815 diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index deb6032ce..8709a6aae 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -31,7 +31,7 @@ void LogTeamchange(float player_id, float team_number, float type) GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type))); } -void default_delayedinit() +void default_delayedinit(entity this) { if(!scores_initialized) ScoreRules_generic(); @@ -44,23 +44,6 @@ void ActivateTeamplay() cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies. } -void SetLimits(int fraglimit_override, int leadlimit_override, float timelimit_override, float qualifying_override) -{ - // enforce the server's universal frag/time limits - // set to -1 to not change value - if(!autocvar_g_campaign) - { - if(fraglimit_override >= 0) - cvar_set("fraglimit", ftos(fraglimit_override)); - if(timelimit_override >= 0) - cvar_set("timelimit", ftos(timelimit_override)); - if(leadlimit_override >= 0) - cvar_set("leadlimit", ftos(leadlimit_override)); - if(qualifying_override >= 0) - cvar_set("g_race_qualifying_timelimit", ftos(qualifying_override)); - } -} - void InitGameplayMode() { VoteReset(); @@ -89,21 +72,19 @@ void InitGameplayMode() MapInfo_ClearTemps(); - // set both here, gamemode can override it later - SetLimits(autocvar_fraglimit_override, autocvar_leadlimit_override, autocvar_timelimit_override, -1); gamemode_name = MapInfo_Type_ToText(MapInfo_LoadedGametype); cache_mutatormsg = strzone(""); cache_lastmutatormsg = strzone(""); - InitializeEntity(world, default_delayedinit, INITPRIO_GAMETYPE_FALLBACK); + InitializeEntity(NULL, default_delayedinit, INITPRIO_GAMETYPE_FALLBACK); } -string GetClientVersionMessage() -{SELFPARAM(); +string GetClientVersionMessage(entity this) +{ string versionmsg; - if (self.version_mismatch) { - if(self.version < autocvar_gameversion) { + 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"; } else { versionmsg = "^3This server is using an outdated Xonotic version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8"; @@ -114,12 +95,12 @@ string GetClientVersionMessage() return versionmsg; } -string getwelcomemessage() +string getwelcomemessage(entity this) { string s, modifications, motd; MUTATOR_CALLHOOK(BuildMutatorsPrettyString, ""); - modifications = ret_string; + modifications = M_ARGV(0, string); if(g_weaponarena) { @@ -142,8 +123,7 @@ string getwelcomemessage() modifications = strcat(modifications, ", Powerups"); modifications = substring(modifications, 2, strlen(modifications) - 2); - string versionmessage; - versionmessage = GetClientVersionMessage(); + 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"); @@ -151,9 +131,6 @@ string getwelcomemessage() if(modifications != "") s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n"); - if (cvar("g_nades")) - s = strcat(s, "\n\n^3nades^8 are enabled, press 'g' to use them\n"); - if(cache_lastmutatormsg != autocvar_g_mutatormsg) { if(cache_lastmutatormsg) @@ -170,7 +147,7 @@ string getwelcomemessage() string mutator_msg = ""; MUTATOR_CALLHOOK(BuildGameplayTipsString, mutator_msg); - mutator_msg = ret_string; + mutator_msg = M_ARGV(0, string); s = strcat(s, mutator_msg); // trust that the mutator will do proper formatting @@ -228,7 +205,7 @@ void SetPlayerTeam(entity pl, float t, float s, float noprint) // set c1...c4 to show what teams are allowed void CheckAllowedTeams (entity for_whom) -{SELFPARAM(); +{ int dm = 0; c1 = c2 = c3 = c4 = -1; @@ -237,8 +214,8 @@ void CheckAllowedTeams (entity for_whom) string teament_name = string_null; bool mutator_returnvalue = MUTATOR_CALLHOOK(GetTeamCount, dm, teament_name); - teament_name = ret_string; - dm = ret_float; + dm = M_ARGV(0, float); + teament_name = M_ARGV(1, string); if(!mutator_returnvalue) { @@ -253,7 +230,7 @@ void CheckAllowedTeams (entity for_whom) // find out what teams are allowed if necessary if(teament_name) { - entity head = find(world, classname, teament_name); + entity head = find(NULL, classname, teament_name); while(head) { switch(head.team) @@ -290,14 +267,17 @@ void CheckAllowedTeams (entity for_whom) } } + if(!for_whom) + return; + // if player has a forced team, ONLY allow that one - if(self.team_forced == NUM_TEAM_1 && c1 >= 0) + if(for_whom.team_forced == NUM_TEAM_1 && c1 >= 0) c2 = c3 = c4 = -1; - else if(self.team_forced == NUM_TEAM_2 && c2 >= 0) + else if(for_whom.team_forced == NUM_TEAM_2 && c2 >= 0) c1 = c3 = c4 = -1; - else if(self.team_forced == NUM_TEAM_3 && c3 >= 0) + else if(for_whom.team_forced == NUM_TEAM_3 && c3 >= 0) c1 = c2 = c4 = -1; - else if(self.team_forced == NUM_TEAM_4 && c4 >= 0) + else if(for_whom.team_forced == NUM_TEAM_4 && c4 >= 0) c1 = c2 = c3 = -1; } @@ -311,26 +291,24 @@ float PlayerValue(entity p) // teams that are allowed will now have their player counts stored in c1...c4 void GetTeamCounts(entity ignore) { - entity head; float value, bvalue; // now count how many players are on each team already // 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 - FOR_EACH_CLIENT(head) - { + FOREACH_CLIENT(true, LAMBDA( float t; - if(IS_PLAYER(head) || head.caplayer) - t = head.team; - else if(head.team_forced > 0) - t = head.team_forced; // reserve the spot + if(IS_PLAYER(it) || it.caplayer) + t = it.team; + else if(it.team_forced > 0) + t = it.team_forced; // reserve the spot else continue; - if(head != ignore)// && head.netname != "") + if(it != ignore)// && it.netname != "") { - value = PlayerValue(head); - if(IS_BOT_CLIENT(head)) + value = PlayerValue(it); + if(IS_BOT_CLIENT(it)) bvalue = value; else bvalue = 0; @@ -367,7 +345,7 @@ void GetTeamCounts(entity ignore) } } } - } + )); // if the player who has a forced team has not joined yet, reserve the spot if(autocvar_g_campaign) @@ -479,7 +457,7 @@ float FindSmallestTeam(entity pl, float ignore_pl) if(ignore_pl) GetTeamCounts(pl); else - GetTeamCounts(world); + GetTeamCounts(NULL); RandomSelection_Init(); @@ -493,19 +471,19 @@ float FindSmallestTeam(entity pl, float ignore_pl) // now t is the minimum, or A minimum! if(t == 1 || TeamSmallerEqThanTeam(1, t, pl)) - RandomSelection_Add(world, 1, string_null, 1, 1); + RandomSelection_Add(NULL, 1, string_null, 1, 1); if(t == 2 || TeamSmallerEqThanTeam(2, t, pl)) - RandomSelection_Add(world, 2, string_null, 1, 1); + RandomSelection_Add(NULL, 2, string_null, 1, 1); if(t == 3 || TeamSmallerEqThanTeam(3, t, pl)) - RandomSelection_Add(world, 3, string_null, 1, 1); + RandomSelection_Add(NULL, 3, string_null, 1, 1); if(t == 4 || TeamSmallerEqThanTeam(4, t, pl)) - RandomSelection_Add(world, 4, string_null, 1, 1); + RandomSelection_Add(NULL, 4, string_null, 1, 1); return RandomSelection_chosen_float; } -float JoinBestTeam(entity pl, float only_return_best, float forcebestteam) -{SELFPARAM(); +int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam) +{ float smallest, selectedteam; // don't join a team if we're not playing a team game @@ -513,20 +491,20 @@ float JoinBestTeam(entity pl, float only_return_best, float forcebestteam) return 0; // find out what teams are available - CheckAllowedTeams(pl); + CheckAllowedTeams(this); // if we don't care what team he ends up on, put him on whatever team he entered as. // if he's not on a valid team, then let other code put him on the smallest team if(!forcebestteam) { - if( c1 >= 0 && pl.team == NUM_TEAM_1) - selectedteam = pl.team; - else if(c2 >= 0 && pl.team == NUM_TEAM_2) - selectedteam = pl.team; - else if(c3 >= 0 && pl.team == NUM_TEAM_3) - selectedteam = pl.team; - else if(c4 >= 0 && pl.team == NUM_TEAM_4) - selectedteam = pl.team; + if( c1 >= 0 && this.team == NUM_TEAM_1) + selectedteam = this.team; + else if(c2 >= 0 && this.team == NUM_TEAM_2) + selectedteam = this.team; + else if(c3 >= 0 && this.team == NUM_TEAM_3) + selectedteam = this.team; + else if(c4 >= 0 && this.team == NUM_TEAM_4) + selectedteam = this.team; else selectedteam = -1; @@ -534,47 +512,47 @@ float JoinBestTeam(entity pl, float only_return_best, float forcebestteam) { if(!only_return_best) { - SetPlayerColors(pl, selectedteam - 1); + SetPlayerColors(this, selectedteam - 1); // when JoinBestTeam is called by client.qc/ClientKill_Now_TeamChange the players team is -1 and thus skipped // when JoinBestTeam is called by cl_client.qc/ClientConnect the player_id is 0 the log attempt is rejected - LogTeamchange(pl.playerid, pl.team, 99); + LogTeamchange(this.playerid, this.team, 99); } return selectedteam; } // otherwise end up on the smallest team (handled below) } - smallest = FindSmallestTeam(pl, true); + smallest = FindSmallestTeam(this, true); - if(!only_return_best && !pl.bot_forced_team) + if(!only_return_best && !this.bot_forced_team) { - TeamchangeFrags(self); + TeamchangeFrags(this); if(smallest == 1) { - SetPlayerColors(pl, NUM_TEAM_1 - 1); + SetPlayerColors(this, NUM_TEAM_1 - 1); } else if(smallest == 2) { - SetPlayerColors(pl, NUM_TEAM_2 - 1); + SetPlayerColors(this, NUM_TEAM_2 - 1); } else if(smallest == 3) { - SetPlayerColors(pl, NUM_TEAM_3 - 1); + SetPlayerColors(this, NUM_TEAM_3 - 1); } else if(smallest == 4) { - SetPlayerColors(pl, NUM_TEAM_4 - 1); + SetPlayerColors(this, NUM_TEAM_4 - 1); } else { error("smallest team: invalid team\n"); } - LogTeamchange(pl.playerid, pl.team, 2); // log auto join + LogTeamchange(this.playerid, this.team, 2); // log auto join - if(pl.deadflag == DEAD_NO) - Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE.m_id, pl.origin, '0 0 0'); + if(!IS_DEAD(this)) + Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0'); } return smallest; @@ -582,16 +560,24 @@ float JoinBestTeam(entity pl, float only_return_best, float forcebestteam) //void() ctf_playerchanged; void SV_ChangeTeam(float _color) -{SELFPARAM(); +{ENGINE_EVENT(); float scolor, dcolor, steam, dteam; //, dbotcount, scount, dcount; // in normal deathmatch we can just apply the color and we're done - if(!teamplay) { - SetPlayerColors(self, _color); + if(!teamplay) + SetPlayerColors(this, _color); + + if(!IS_CLIENT(this)) + { + // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_CONNECTING, this.netname); return; } - scolor = self.clientcolors & 0x0F; + if(!teamplay) + return; + + scolor = this.clientcolors & 0x0F; dcolor = _color & 0x0F; if(scolor == NUM_TEAM_1 - 1) @@ -611,7 +597,7 @@ void SV_ChangeTeam(float _color) else // if(dcolor == NUM_TEAM_4 - 1) dteam = 4; - CheckAllowedTeams(self); + CheckAllowedTeams(this); if(dteam == 1 && c1 < 0) dteam = 4; if(dteam == 4 && c4 < 0) dteam = 3; @@ -622,45 +608,43 @@ void SV_ChangeTeam(float _color) if(scolor == dcolor) { //bprint("same team change\n"); - SetPlayerTeam(self, dteam, steam, true); + SetPlayerTeam(this, dteam, steam, true); return; } - if((autocvar_g_campaign) || (autocvar_g_changeteam_banned && self.wasplayer)) { - Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_TEAMCHANGE_NOTALLOWED); + if((autocvar_g_campaign) || (autocvar_g_changeteam_banned && this.wasplayer)) { + Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_NOTALLOWED); return; // changing teams is not allowed } // autocvar_g_balance_teams_prevent_imbalance only makes sense if autocvar_g_balance_teams is on, as it makes the team selection dialog pointless if(autocvar_g_balance_teams && autocvar_g_balance_teams_prevent_imbalance) { - GetTeamCounts(self); - if(!TeamSmallerEqThanTeam(dteam, steam, self)) + GetTeamCounts(this); + if(!TeamSmallerEqThanTeam(dteam, steam, this)) { - Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM); + Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_TEAMCHANGE_LARGERTEAM); return; } } // bprint("allow change teams from ", ftos(steam), " to ", ftos(dteam), "\n"); - if(IS_PLAYER(self) && steam != dteam) + if(IS_PLAYER(this) && steam != dteam) { // reduce frags during a team change - TeamchangeFrags(self); + TeamchangeFrags(this); } - // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here - if(!IS_CLIENT(self)) - Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_CONNECTING, self.netname); + MUTATOR_CALLHOOK(Player_ChangeTeam, this, steam, dteam); - SetPlayerTeam(self, dteam, steam, !IS_CLIENT(self)); + SetPlayerTeam(this, dteam, steam, !IS_CLIENT(this)); - if(IS_PLAYER(self) && steam != dteam) + if(IS_PLAYER(this) && steam != dteam) { // kill player when changing teams - if(self.deadflag == DEAD_NO) - Damage(self, self, self, 100000, DEATH_TEAMCHANGE.m_id, self.origin, '0 0 0'); + if(!IS_DEAD(this)) + Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0'); } } @@ -668,7 +652,7 @@ void ShufflePlayerOutOfTeam (float source_team) { float smallestteam, smallestteam_count, steam; float lowest_bot_score, lowest_player_score; - entity head, lowest_bot, lowest_player, selected; + entity lowest_bot, lowest_player, selected; smallestteam = 0; smallestteam_count = 999999999; @@ -709,37 +693,33 @@ void ShufflePlayerOutOfTeam (float source_team) else // if(source_team == 4) steam = NUM_TEAM_4; - lowest_bot = world; + lowest_bot = NULL; lowest_bot_score = 999999999; - lowest_player = world; + lowest_player = NULL; lowest_player_score = 999999999; // find the lowest-scoring player & bot of that team - FOR_EACH_PLAYER(head) - { - if(head.team == steam) + FOREACH_CLIENT(IS_PLAYER(it) && it.team == steam, LAMBDA( + if(it.isbot) { - if(head.isbot) + if(it.totalfrags < lowest_bot_score) { - if(head.totalfrags < lowest_bot_score) - { - lowest_bot = head; - lowest_bot_score = head.totalfrags; - } + lowest_bot = it; + lowest_bot_score = it.totalfrags; } - else + } + else + { + if(it.totalfrags < lowest_player_score) { - if(head.totalfrags < lowest_player_score) - { - lowest_player = head; - lowest_player_score = head.totalfrags; - } + lowest_player = it; + lowest_player_score = it.totalfrags; } } - } + )); // prefers to move a bot... - if(lowest_bot != world) + if(lowest_bot != NULL) selected = lowest_bot; // but it will move a player if it has to else @@ -800,7 +780,7 @@ void ShufflePlayerOutOfTeam (float source_team) TeamchangeFrags(selected); SetPlayerTeam(selected, smallestteam, source_team, false); - if(selected.deadflag == DEAD_NO) + if(!IS_DEAD(selected)) Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0'); Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team); }