Fix number of teams defaulting to 2 for some game modes (CA, FT and KH)
[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)
37                         ca_teams = cvar("g_ca_teams"); // read the cvar directly as it gets written earlier in the same frame
38                 ca_teams = bound(2, ca_teams, 4);
39
40                 int teams = 0;
41                 if(ca_teams >= 1) teams |= BIT(0);
42                 if(ca_teams >= 2) teams |= BIT(1);
43                 if(ca_teams >= 3) teams |= BIT(2);
44                 if(ca_teams >= 4) teams |= BIT(3);
45
46                 ca_teams = teams; // now set it?
47
48         ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
49         ScoreInfo_SetLabel_TeamScore(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY);
50         ScoreRules_basics_end();
51
52                 round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart);
53                 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
54
55                 EliminatedPlayers_Init(ca_isEliminated);
56
57                 ActivateTeamplay();
58                 SetLimits(autocvar_g_ca_point_limit, autocvar_g_ca_point_leadlimit, autocvar_timelimit_override, -1);
59
60                 if (autocvar_g_ca_team_spawns)
61                         have_team_spawns = -1; // request team spawns
62         }
63
64         MUTATOR_ONREMOVE
65         {
66                 LOG_INFO("This is a game type and it cannot be removed at runtime.");
67                 return -1;
68         }
69
70         return 0;
71 }
72
73 // should be removed in the future, as other code should not have to care
74 .float caplayer; // 0.5 if scheduled to join the next round