8009feb8a569c252694450672b86367b5ced92be
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_ca.qh
1 #pragma once
2
3 #include "../gamemode.qh"
4
5 int autocvar_g_ca_point_limit;
6 int autocvar_g_ca_point_leadlimit;
7 float autocvar_g_ca_round_timelimit;
8 bool autocvar_g_ca_team_spawns;
9 int autocvar_g_ca_teams;
10 int autocvar_g_ca_teams_override;
11 float autocvar_g_ca_warmup;
12
13
14 int ca_teams;
15 bool allowed_to_spawn;
16
17 const int ST_CA_ROUNDS = 1;
18
19 bool CA_CheckTeams();
20 bool CA_CheckWinner();
21 void CA_RoundStart();
22 bool ca_isEliminated(entity e);
23
24 void SetLimits(int fraglimit_override, int leadlimit_override, float timelimit_override, float qualifying_override);
25
26 REGISTER_MUTATOR(ca, false)
27 {
28         MUTATOR_ONADD
29         {
30                 // game loads at time 1
31                 if (time > 1) error("This is a game type and it cannot be added at runtime.");
32
33                 allowed_to_spawn = true;
34
35                 ca_teams = autocvar_g_ca_teams_override;
36                 if (ca_teams < 2) ca_teams = autocvar_g_ca_teams;
37                 ca_teams = bound(2, ca_teams, 4);
38
39                 int teams = 0;
40                 if(ca_teams >= 1) teams |= BIT(0);
41                 if(ca_teams >= 2) teams |= BIT(1);
42                 if(ca_teams >= 3) teams |= BIT(2);
43                 if(ca_teams >= 4) teams |= BIT(3);
44
45                 ca_teams = teams; // now set it?
46
47         ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
48         ScoreInfo_SetLabel_TeamScore(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY);
49         ScoreRules_basics_end();
50
51                 round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart);
52                 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
53
54                 EliminatedPlayers_Init(ca_isEliminated);
55
56                 ActivateTeamplay();
57                 SetLimits(autocvar_g_ca_point_limit, autocvar_g_ca_point_leadlimit, autocvar_timelimit_override, -1);
58
59                 if (autocvar_g_ca_team_spawns)
60                         have_team_spawns = -1; // request team spawns
61         }
62
63         MUTATOR_ONREMOVE
64         {
65                 LOG_INFO("This is a game type and it cannot be removed at runtime.");
66                 return -1;
67         }
68
69         return 0;
70 }
71
72 // should be removed in the future, as other code should not have to care
73 .float caplayer; // 0.5 if scheduled to join the next round