]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/gamemodes/sv_rules.qc
Refactor game rules
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / sv_rules.qc
1 #include "sv_rules.qh"
2
3 #include <server/teamplay.qh>
4
5 void GameRules_teams(bool value)
6 {
7     if (value) {
8         serverflags |= SERVERFLAG_TEAMPLAY;
9         teamplay = 1;
10         cvar_set("teamplay", "2");  // DP needs this for sending proper getstatus replies.
11     } else {
12         serverflags &= ~SERVERFLAG_TEAMPLAY;
13         teamplay = 0;
14         cvar_set("teamplay", "0");  // DP needs this for sending proper getstatus replies.
15     }
16 }
17
18 bool _GameRules_score_enabled = true;
19 void GameRules_score_enabled(bool value)
20 {
21     _GameRules_score_enabled = value;
22 }
23
24 bool GameRules_limit_score_initialized;
25 void GameRules_limit_score(int limit)
26 {
27     if (GameRules_limit_score_initialized) return;
28     if (autocvar_g_campaign) return;
29     if (limit < 0) return;
30     cvar_set("fraglimit", ftos(limit));
31     GameRules_limit_score_initialized = true;
32 }
33
34 bool GameRules_limit_lead_initialized;
35 void GameRules_limit_lead(int limit)
36 {
37     if (GameRules_limit_lead_initialized) return;
38     if (autocvar_g_campaign) return;
39     if (limit < 0) return;
40     cvar_set("leadlimit", ftos(limit));
41     GameRules_limit_lead_initialized = true;
42 }
43
44 bool GameRules_limit_time_initialized;
45 void GameRules_limit_time(int limit)
46 {
47     if (GameRules_limit_time_initialized) return;
48     if (autocvar_g_campaign) return;
49     if (limit < 0) return;
50     cvar_set("timelimit", ftos(limit));
51     GameRules_limit_time_initialized = true;
52 }
53
54 bool GameRules_limit_time_qualifying_initialized;
55 void GameRules_limit_time_qualifying(int limit)
56 {
57     if (GameRules_limit_time_qualifying_initialized) return;
58     if (autocvar_g_campaign) return;
59     if (limit < 0) return;
60     cvar_set("g_race_qualifying_timelimit", ftos(limit));
61     GameRules_limit_time_qualifying_initialized = true;
62 }
63
64 void GameRules_limit_fallbacks()
65 {
66     GameRules_limit_score(autocvar_fraglimit_override);
67     GameRules_limit_lead(autocvar_leadlimit_override);
68     GameRules_limit_time(autocvar_timelimit_override);
69 }
70
71 void _GameRules_scoring_begin(int teams, float spprio, float stprio)
72 {
73     ScoreRules_basics(teams, spprio, stprio, _GameRules_score_enabled);
74 }
75 void _GameRules_scoring_field(entity i, string label, int scoreflags)
76 {
77     ScoreInfo_SetLabel_PlayerScore(i, label, scoreflags);
78 }
79 void _GameRules_scoring_field_team(float i, string label, int scoreflags)
80 {
81     ScoreInfo_SetLabel_TeamScore(i, label, scoreflags);
82 }
83 void _GameRules_scoring_end()
84 {
85     ScoreRules_basics_end();
86 }