Xonotic
sv_rules.qc
Go to the documentation of this file.
1 #include "sv_rules.qh"
2 
3 #include <server/spawnpoints.qh>
4 #include <server/teamplay.qh>
5 
6 void GameRules_teams(bool value)
7 {
8  if (value) {
10  teamplay = 1;
11  cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies.
14  } else {
16  teamplay = 0;
17  cvar_set("teamplay", "0"); // DP needs this for sending proper getstatus replies.
19  }
20 }
21 
22 void GameRules_spawning_teams(bool value)
23 {
24  have_team_spawns = value ? -1 : 0;
25 }
26 
28 void GameRules_score_enabled(bool value)
29 {
31 }
32 
34 void GameRules_limit_score(int limit)
35 {
37  if (autocvar_g_campaign) return;
38  if (limit < 0) return;
39  cvar_set("fraglimit", ftos(limit));
41 }
42 
44 void GameRules_limit_lead(int limit)
45 {
47  if (autocvar_g_campaign) return;
48  if (limit < 0) return;
49  cvar_set("leadlimit", ftos(limit));
51 }
52 
54 void GameRules_limit_time(int limit)
55 {
57  if (autocvar_g_campaign) return;
58  if (limit < 0) return;
59  cvar_set("timelimit", ftos(limit));
61 }
62 
65 {
67  if (autocvar_g_campaign) return;
68  if (limit < 0) return;
69  cvar_set("g_race_qualifying_timelimit", ftos(limit));
71 }
72 
74 {
75  GameRules_limit_score(autocvar_fraglimit_override);
77  GameRules_limit_time(autocvar_timelimit_override);
78 }
79 
80 void _GameRules_scoring_begin(int teams, float spprio, float stprio)
81 {
82  ScoreRules_basics(teams, spprio, stprio, _GameRules_score_enabled);
83 }
84 void _GameRules_scoring_field(entity i, string label, int scoreflags)
85 {
86  ScoreInfo_SetLabel_PlayerScore(i, label, scoreflags);
87 }
88 void _GameRules_scoring_field_team(float i, string label, int scoreflags)
89 {
90  ScoreInfo_SetLabel_TeamScore(i, label, scoreflags);
91 }
93 {
95 }
96 
98 void GameRules_scoring_vip(entity player, bool value)
99 {
100  player.m_GameRules_scoring_vip = value;
101 }
103 {
104  return player.m_GameRules_scoring_vip;
105 }
106 
107 // Uses client.float_field to accumulate and consume float score and adds score to the player as int (rounded)
108 // only when at least one unit of score has been accumulated. It works with negative score too
109 // Float scores can't be used as score because they aren't supported by the QC score networking system
110 // and online server browsers (e.g. qstat)
111 float _GameRules_scoring_add_float2int(entity client, entity sp, float value, .float float_field, float score_factor)
112 {
113  client.(float_field) += value;
114  float score_counter = client.(float_field) / score_factor;
115  if (score_counter >= -0.5 && score_counter < 0.5)
116  return 0;
117 
118  // NOTE: this code works for subtracting score too
119  int points = floor(score_counter + 0.5);
120  client.(float_field) -= points * score_factor;
121  if (!points)
122  return 0;
123  return PlayerScore_Add(client, sp, points);
124 }
125 
126 float _GameRules_scoring_add(entity client, entity sp, float value)
127 {
128  return PlayerScore_Add(client, sp, value);
129 }
130 float _GameRules_scoring_add_team(entity client, entity sp, int st, float value)
131 {
132  return PlayerTeamScore_Add(client, sp, st, value);
133 }
bool m_GameRules_scoring_vip
Definition: sv_rules.qc:97
int serverflags
Definition: main.qh:184
float _GameRules_scoring_add_float2int(entity client, entity sp, float value,.float float_field, float score_factor)
Definition: sv_rules.qc:111
void GameRules_spawning_teams(bool value)
Used to disable team spawns in team modes.
Definition: sv_rules.qc:22
bool GameRules_limit_lead_initialized
Definition: sv_rules.qc:43
void _GameRules_scoring_field_team(float i, string label, int scoreflags)
Definition: sv_rules.qc:88
void GameRules_limit_fallbacks()
Set any unspecified rules to their defaults.
Definition: sv_rules.qc:73
int have_team_spawns
Definition: spawnpoints.qh:16
void GameRules_scoring_vip(entity player, bool value)
Mark a player as being &#39;important&#39; (flag carrier, ball carrier, etc)
Definition: sv_rules.qc:98
entity() spawn
void ScoreRules_basics(int teams, float sprio, float stprio, float score_enabled)
Definition: scores_rules.qc:29
void GameRules_limit_score(int limit)
Definition: sv_rules.qc:34
void ScoreRules_basics_end()
Definition: scores_rules.qc:64
bool GameRules_limit_time_qualifying_initialized
Definition: sv_rules.qc:63
void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scoreflags)
Set the label of a player score item, as well as the scoring flags.
Definition: scores.qc:165
bool GameRules_scoring_is_vip(entity player)
Definition: sv_rules.qc:102
void _GameRules_scoring_end()
Definition: sv_rules.qc:92
void GameRules_score_enabled(bool value)
Disabling score disables the "score" column on the scoreboard.
Definition: sv_rules.qc:28
void GameRules_limit_time_qualifying(int limit)
Definition: sv_rules.qc:64
void _GameRules_scoring_begin(int teams, float spprio, float stprio)
Definition: sv_rules.qc:80
const int SERVERFLAG_TEAMPLAY
Definition: constants.qh:16
entity teams
Definition: main.qh:44
int autocvar_leadlimit_override
Definition: sv_rules.qh:5
void _GameRules_scoring_field(entity i, string label, int scoreflags)
Definition: sv_rules.qc:84
void GameRules_limit_time(int limit)
Definition: sv_rules.qc:54
void GameRules_teams(bool value)
Definition: sv_rules.qc:6
bool _GameRules_score_enabled
Definition: sv_rules.qc:27
float _GameRules_scoring_add_team(entity client, entity sp, int st, float value)
Definition: sv_rules.qc:130
float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score)
Adds a score to both the player and the team.
Definition: scores.qc:390
float teamplay
Definition: progsdefs.qc:31
void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags)
Set the label of a team score item, as well as the scoring flags.
Definition: scores.qc:181
float _GameRules_scoring_add(entity client, entity sp, float value)
Definition: sv_rules.qc:126
void GameRules_limit_lead(int limit)
Definition: sv_rules.qc:44
bool autocvar_g_campaign
Definition: campaign.qh:6
float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score)
Adds a score to the player&#39;s scores.
Definition: scores.qc:336
void Team_InitTeams()
Definition: teamplay.qc:47
bool GameRules_limit_score_initialized
Definition: sv_rules.qc:33
bool GameRules_limit_time_initialized
Definition: sv_rules.qc:53