]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator/gamemode_ca.qh
Refactor game rules
[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 REGISTER_MUTATOR(ca, false)
25 {
26         MUTATOR_ONADD
27         {
28                 // game loads at time 1
29                 if (time > 1) error("This is a game type and it cannot be added at runtime.");
30
31                 allowed_to_spawn = true;
32
33                 ca_teams = autocvar_g_ca_teams_override;
34                 if (ca_teams < 2)
35                         ca_teams = cvar("g_ca_teams"); // read the cvar directly as it gets written earlier in the same frame
36                 ca_teams = bound(2, ca_teams, 4);
37
38                 int teams = 0;
39                 if(ca_teams >= 1) teams |= BIT(0);
40                 if(ca_teams >= 2) teams |= BIT(1);
41                 if(ca_teams >= 3) teams |= BIT(2);
42                 if(ca_teams >= 4) teams |= BIT(3);
43
44                 ca_teams = teams; // now set it?
45
46         GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, {
47             field_team(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY);
48         });
49
50                 round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart);
51                 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
52
53                 EliminatedPlayers_Init(ca_isEliminated);
54
55                 GameRules_teams(true);
56         GameRules_limit_score(autocvar_g_ca_point_limit);
57         GameRules_limit_lead(autocvar_g_ca_point_leadlimit);
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