X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fteamplay.qc;h=9b4455fcfd0c5cbb42605d1e1edf5a7c981f1949;hb=f963d587753ce1f8e48c8bf87b0bf860732986be;hp=43d4d2461fbb141585102ca9735f9e071b9b6339;hpb=74ab018d9c0857ea241cae2c8ac8b2d64bcbc332;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 43d4d2461..9b4455fcf 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -28,8 +28,6 @@ enum /// \brief Indicates that the player is not allowed to join a team. const int TEAM_NOT_ALLOWED = -1; -.float team_forced; // can be a team number to force a team, or 0 for default action, or -1 for forced spectator - .int m_team_balance_state; ///< Holds the state of the team balance entity. .entity m_team_balance_team[NUM_TEAMS]; ///< ??? @@ -37,7 +35,7 @@ const int TEAM_NOT_ALLOWED = -1; .int m_num_players; ///< Number of players (both humans and bots) in a team. .int m_num_bots; ///< Number of bots in a team. .int m_num_players_alive; ///< Number of alive players in a team. -.int m_num_control_points; ///< Number of control points owned by a team. +.int m_num_owned_items; ///< Number of items owned by a team. string autocvar_g_forced_team_red; string autocvar_g_forced_team_blue; @@ -46,11 +44,13 @@ string autocvar_g_forced_team_pink; entity g_team_entities[NUM_TEAMS]; ///< Holds global team entities. -STATIC_INIT(g_team_entities) +void Team_InitTeams() { + if (g_team_entities[0]) + return; for (int i = 0; i < NUM_TEAMS; ++i) { - g_team_entities[i] = spawn(); + g_team_entities[i] = new_pure(team_entity); } } @@ -92,6 +92,21 @@ void Team_SetNumberOfAlivePlayers(entity team_ent, int number) team_ent.m_num_players_alive = number; } +int Team_GetWinnerAliveTeam() +{ + int winner = 0; + for (int i = 0; i < NUM_TEAMS; ++i) + { + if (g_team_entities[i].m_num_players_alive > 0) + { + if (winner) + return 0; + winner = Team_IndexToTeam(i + 1); + } + } + return (winner ? winner : -1); +} + int Team_GetNumberOfAliveTeams() { int result = 0; @@ -105,22 +120,37 @@ int Team_GetNumberOfAliveTeams() return result; } -int Team_GetNumberOfControlPoints(entity team_ent) +int Team_GetWinnerTeam_WithOwnedItems(int min_control_points) { - return team_ent.m_num_control_points; + int winner = 0; + for (int i = 0; i < NUM_TEAMS; ++i) + { + if (g_team_entities[i].m_num_owned_items >= min_control_points) + { + if (winner) + return 0; + winner = Team_IndexToTeam(i + 1); + } + } + return (winner ? winner : -1); } -void Team_SetNumberOfControlPoints(entity team_ent, int number) +int Team_GetNumberOfOwnedItems(entity team_ent) { - team_ent.m_num_control_points = number; + return team_ent.m_num_owned_items; } -int Team_GetNumberOfTeamsWithControlPoints() +void Team_SetNumberOfOwnedItems(entity team_ent, int number) +{ + team_ent.m_num_owned_items = number; +} + +int Team_GetNumberOfTeamsWithOwnedItems() { int result = 0; for (int i = 0; i < NUM_TEAMS; ++i) { - if (g_team_entities[i].m_num_control_points > 0) + if (g_team_entities[i].m_num_owned_items > 0) { ++result; } @@ -130,7 +160,7 @@ int Team_GetNumberOfTeamsWithControlPoints() void setcolor(entity this, int clr) { -#if 0 +#if 1 this.clientcolors = clr; this.team = (clr & 15) + 1; #else @@ -207,38 +237,38 @@ bool Player_SetTeamIndex(entity player, int index) bool SetPlayerTeam(entity player, int team_index, int type) { int old_team_index = Entity_GetTeamIndex(player); + if (!Player_SetTeamIndex(player, team_index)) - { return false; - } + LogTeamChange(player.playerid, player.team, type); + if (team_index != old_team_index) { - PlayerScore_Clear(player); - if (team_index != -1) - { - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM( - player.team, INFO_JOIN_PLAY_TEAM), player.netname); - } - else - { - if (!CS(player).just_joined) - { - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_SPECTATE, - player.netname); - } - } KillPlayerForTeamChange(player); + PlayerScore_Clear(player); // works only in game modes without teams + if (!IS_BOT_CLIENT(player)) - { TeamBalance_AutoBalanceBots(); - } + + if (team_index != -1) + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(player.team, INFO_JOIN_PLAY_TEAM), player.netname); } - else if (team_index == -1) + + if (team_index == -1) { - if (!CS(player).just_joined && player.frags != FRAGS_SPECTATOR) + if (autocvar_sv_maxidle_playertospectator > 0 && CS(player).idlekick_lasttimeleft) + { + // this done here so it happens even when manually speccing during the countdown + Kill_Notification(NOTIF_ONE_ONLY, player, MSG_CENTER, CPID_IDLING); + CS(player).idlekick_lasttimeleft = 0; + } + else if (!CS(player).just_joined && player.frags != FRAGS_SPECTATOR) + { Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_SPECTATE, player.netname); + } } + return true; } @@ -497,7 +527,7 @@ entity TeamBalance_CheckAllowedTeams(entity for_whom) } // TODO: Balance quantity of bots across > 2 teams when bot_vs_human is set (and remove next line) - if (autocvar_bot_vs_human && AvailableTeams() == 2 && for_whom) + if (autocvar_bot_vs_human && AVAILABLE_TEAMS == 2 && for_whom) { if (autocvar_bot_vs_human > 0) { @@ -683,7 +713,7 @@ void TeamBalance_GetTeamCounts(entity balance, entity ignore) } int team_num; // TODO: Reconsider when the player is truly on the team. - if (IS_CLIENT(it) || (it.caplayer)) + if (IS_CLIENT(it) || INGAME(it)) { team_num = it.team; } @@ -1123,18 +1153,13 @@ void SV_ChangeTeam(entity player, int new_color) { SetPlayerColors(player, new_color); } - // TODO: Should we really bother with this? if(!IS_CLIENT(player)) { - // 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, - player.netname); return; } if (!teamplay) { return; } - Player_SetTeamIndexChecked(player, Team_TeamToIndex((new_color & 0x0F) + - 1)); + Player_SetTeamIndexChecked(player, Team_TeamToIndex((new_color & 0x0F) + 1)); }