From 547d69ba59332c77e4b10855ad406421500e6bd0 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Sun, 18 Mar 2018 12:01:00 +0300 Subject: [PATCH] Removed 'owned' global variables. --- .../gamemode/onslaught/sv_onslaught.qc | 50 ++++++++++-------- .../mutators/mutator/gamemode_domination.qc | 52 ++++++++++--------- qcsrc/server/teamplay.qc | 24 +++++++++ qcsrc/server/teamplay.qh | 14 ++++- 4 files changed, 94 insertions(+), 46 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc index 2536af659..06fb06d18 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc @@ -1075,46 +1075,52 @@ int total_generators; void Onslaught_count_generators() { entity e; - total_generators = redowned = blueowned = yellowowned = pinkowned = 0; + total_generators = 0; + for (int i = 1; i <= NUM_TEAMS; ++i) + { + Team_SetNumberOfControlPoints(Team_GetTeamFromIndex(i), 0); + } for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext) { ++total_generators; - redowned += (e.team == NUM_TEAM_1 && e.health > 0); - blueowned += (e.team == NUM_TEAM_2 && e.health > 0); - yellowowned += (e.team == NUM_TEAM_3 && e.health > 0); - pinkowned += (e.team == NUM_TEAM_4 && e.health > 0); + if (GetResourceAmount(e, RESOURCE_HEALTH) < 1) + { + continue; + } + entity team_ = Entity_GetTeam(e); + int num_control_points = Team_GetNumberOfControlPoints(team_); + ++num_control_points; + Team_SetNumberOfControlPoints(team_, num_control_points); } } int Onslaught_GetWinnerTeam() { int winner_team = 0; - if(redowned > 0) - winner_team = NUM_TEAM_1; - if(blueowned > 0) + if (Team_GetNumberOfControlPoints(Team_GetTeamFromIndex(1)) >= 1) { - if(winner_team) return 0; - winner_team = NUM_TEAM_2; + winner_team = NUM_TEAM_1; } - if(yellowowned > 0) + for (int i = 2; i <= NUM_TEAMS; ++i) { - if(winner_team) return 0; - winner_team = NUM_TEAM_3; + if (Team_GetNumberOfControlPoints(Team_GetTeamFromIndex(i)) >= 1) + { + if (winner_team != 0) + { + return 0; + } + winner_team = Team_IndexToTeam(i); + } } - if(pinkowned > 0) + if (winner_team) { - if(winner_team) return 0; - winner_team = NUM_TEAM_4; - } - if(winner_team) return winner_team; + } return -1; // no generators left? } void nades_Clear(entity e); -#define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0)) -#define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1) bool Onslaught_CheckWinner() { if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)) @@ -1160,8 +1166,10 @@ bool Onslaught_CheckWinner() Onslaught_count_generators(); - if(ONS_OWNED_GENERATORS_OK()) + if (Team_GetNumberOfTeamsWithControlPoints() > 1) + { return 0; + } int winner_team = Onslaught_GetWinnerTeam(); diff --git a/qcsrc/server/mutators/mutator/gamemode_domination.qc b/qcsrc/server/mutators/mutator/gamemode_domination.qc index 7febaed8a..8c71fc2db 100644 --- a/qcsrc/server/mutators/mutator/gamemode_domination.qc +++ b/qcsrc/server/mutators/mutator/gamemode_domination.qc @@ -295,47 +295,51 @@ void dom_controlpoint_setup(entity this) WaypointSprite_SpawnFixed(WP_DomNeut, this.origin + '0 0 32', this, sprite, RADARICON_DOMPOINT); } -float total_controlpoints; +int total_control_points; void Domination_count_controlpoints() { - total_controlpoints = redowned = blueowned = yellowowned = pinkowned = 0; + total_control_points = 0; + for (int i = 1; i <= NUM_TEAMS; ++i) + { + Team_SetNumberOfControlPoints(Team_GetTeamFromIndex(i), 0); + } IL_EACH(g_dompoints, true, { - ++total_controlpoints; - redowned += (it.goalentity.team == NUM_TEAM_1); - blueowned += (it.goalentity.team == NUM_TEAM_2); - yellowowned += (it.goalentity.team == NUM_TEAM_3); - pinkowned += (it.goalentity.team == NUM_TEAM_4); + ++total_control_points; + entity team_ = Entity_GetTeam(it.goalentity); + int num_control_points = Team_GetNumberOfControlPoints(team_); + ++num_control_points; + Team_SetNumberOfControlPoints(team_, num_control_points); }); } -float Domination_GetWinnerTeam() +int Domination_GetWinnerTeam() { - float winner_team = 0; - if(redowned == total_controlpoints) - winner_team = NUM_TEAM_1; - if(blueowned == total_controlpoints) + int winner_team = 0; + if (Team_GetNumberOfControlPoints(Team_GetTeamFromIndex(1)) == + total_control_points) { - if(winner_team) return 0; - winner_team = NUM_TEAM_2; + winner_team = NUM_TEAM_1; } - if(yellowowned == total_controlpoints) + for (int i = 2; i <= NUM_TEAMS; ++i) { - if(winner_team) return 0; - winner_team = NUM_TEAM_3; + if (Team_GetNumberOfControlPoints(Team_GetTeamFromIndex(i)) == + total_control_points) + { + if (winner_team != 0) + { + return 0; + } + winner_team = Team_IndexToTeam(i); + } } - if(pinkowned == total_controlpoints) + if (winner_team) { - if(winner_team) return 0; - winner_team = NUM_TEAM_4; - } - if(winner_team) return winner_team; + } return -1; // no control points left? } -#define DOM_OWNED_CONTROLPOINTS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0)) -#define DOM_OWNED_CONTROLPOINTS_OK() (DOM_OWNED_CONTROLPOINTS() < total_controlpoints) float Domination_CheckWinner() { if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0) diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 325252bcd..d3fba6107 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -35,6 +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. .entity m_lowest_human; ///< Human with the lowest score in a team. .entity m_lowest_bot; ///< Bot with the lowest score in a team. @@ -99,6 +100,29 @@ int Team_GetNumberOfAliveTeams() return result; } +int Team_GetNumberOfControlPoints(entity team_) +{ + return team_.m_num_control_points; +} + +void Team_SetNumberOfControlPoints(entity team_, int number) +{ + team_.m_num_control_points = number; +} + +int Team_GetNumberOfTeamsWithControlPoints() +{ + int result = 0; + for (int i = 0; i < NUM_TEAMS; ++i) + { + if (g_team_entities[i].m_num_control_points > 0) + { + ++result; + } + } + return result; +} + void TeamchangeFrags(entity e) { PlayerScore_Clear(e); diff --git a/qcsrc/server/teamplay.qh b/qcsrc/server/teamplay.qh index a12e26b6f..a4310b3e5 100644 --- a/qcsrc/server/teamplay.qh +++ b/qcsrc/server/teamplay.qh @@ -38,7 +38,19 @@ void Team_SetNumberOfAlivePlayers(entity team_, int number); /// \return Number of alive teams. int Team_GetNumberOfAliveTeams(); -int redowned, blueowned, yellowowned, pinkowned; +/// \brief Returns the number of control points owned by a team. +/// \param[in] team_ Team entity. +/// \return Number of control points owned by a team. +int Team_GetNumberOfControlPoints(entity team_); + +/// \brief Sets the number of control points owned by a team. +/// \param[in,out] team_ Team entity. +/// \param[in] number Number of control points to set. +void Team_SetNumberOfControlPoints(entity team_, int number); + +/// \brief Returns the number of teams that own control points. +/// \return Number of teams that own control points. +int Team_GetNumberOfTeamsWithControlPoints(); void TeamchangeFrags(entity e); -- 2.39.2