Merge branch 'master' into martin-t/globals
[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         GameRules_spawning_teams(true);
12     } else {
13         serverflags &= ~SERVERFLAG_TEAMPLAY;
14         teamplay = 0;
15         cvar_set("teamplay", "0");  // DP needs this for sending proper getstatus replies.
16         GameRules_spawning_teams(false);
17     }
18 }
19
20 void GameRules_spawning_teams(bool value)
21 {
22     have_team_spawns = value ? -1 : 0;
23 }
24
25 bool _GameRules_score_enabled = true;
26 void GameRules_score_enabled(bool value)
27 {
28     _GameRules_score_enabled = value;
29 }
30
31 bool GameRules_limit_score_initialized;
32 void GameRules_limit_score(int limit)
33 {
34     if (GameRules_limit_score_initialized) return;
35     if (autocvar_g_campaign) return;
36     if (limit < 0) return;
37     cvar_set("fraglimit", ftos(limit));
38     GameRules_limit_score_initialized = true;
39 }
40
41 bool GameRules_limit_lead_initialized;
42 void GameRules_limit_lead(int limit)
43 {
44     if (GameRules_limit_lead_initialized) return;
45     if (autocvar_g_campaign) return;
46     if (limit < 0) return;
47     cvar_set("leadlimit", ftos(limit));
48     GameRules_limit_lead_initialized = true;
49 }
50
51 bool GameRules_limit_time_initialized;
52 void GameRules_limit_time(int limit)
53 {
54     if (GameRules_limit_time_initialized) return;
55     if (autocvar_g_campaign) return;
56     if (limit < 0) return;
57     cvar_set("timelimit", ftos(limit));
58     GameRules_limit_time_initialized = true;
59 }
60
61 bool GameRules_limit_time_qualifying_initialized;
62 void GameRules_limit_time_qualifying(int limit)
63 {
64     if (GameRules_limit_time_qualifying_initialized) return;
65     if (autocvar_g_campaign) return;
66     if (limit < 0) return;
67     cvar_set("g_race_qualifying_timelimit", ftos(limit));
68     GameRules_limit_time_qualifying_initialized = true;
69 }
70
71 void GameRules_limit_fallbacks()
72 {
73     GameRules_limit_score(autocvar_fraglimit_override);
74     GameRules_limit_lead(autocvar_leadlimit_override);
75     GameRules_limit_time(autocvar_timelimit_override);
76 }
77
78 void _GameRules_scoring_begin(int teams, float spprio, float stprio)
79 {
80     ScoreRules_basics(teams, spprio, stprio, _GameRules_score_enabled);
81 }
82 void _GameRules_scoring_field(entity i, string label, int scoreflags)
83 {
84     ScoreInfo_SetLabel_PlayerScore(i, label, scoreflags);
85 }
86 void _GameRules_scoring_field_team(float i, string label, int scoreflags)
87 {
88     ScoreInfo_SetLabel_TeamScore(i, label, scoreflags);
89 }
90 void _GameRules_scoring_end()
91 {
92     ScoreRules_basics_end();
93 }
94
95 .bool m_GameRules_scoring_vip;
96 void GameRules_scoring_vip(entity player, bool value)
97 {
98     player.m_GameRules_scoring_vip = value;
99 }
100 bool GameRules_scoring_is_vip(entity player)
101 {
102     return player.m_GameRules_scoring_vip;
103 }
104
105 float _GameRules_scoring_add(entity client, entity sp, float value)
106 {
107     return PlayerScore_Add(client, sp, value);
108 }
109 float _GameRules_scoring_add_team(entity client, entity sp, int st, float value)
110 {
111     return PlayerTeamScore_Add(client, sp, st, value);
112 }