]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator/gamemode_tdm.qc
Mutators: combine headers
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_tdm.qc
1 #ifdef IMPLEMENTATION
2 bool autocvar_g_tdm_team_spawns;
3 int autocvar_g_tdm_point_limit;
4 int autocvar_g_tdm_point_leadlimit;
5 int autocvar_g_tdm_teams;
6 int autocvar_g_tdm_teams_override;
7
8 /*QUAKED spawnfunc_tdm_team (0 .5 .8) (-16 -16 -24) (16 16 32)
9 Team declaration for TDM gameplay, this allows you to decide what team names and control point models are used in your map.
10 Note: If you use spawnfunc_tdm_team entities you must define at least 2!  However, unlike domination, you don't need to make a blank one too.
11 Keys:
12 "netname" Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)...
13 "cnt" Scoreboard color of the team (for example 4 is red and 13 is blue)... */
14 spawnfunc(tdm_team)
15 {
16         if(!g_tdm || !self.cnt) { remove(self); return; }
17
18         self.classname = "tdm_team";
19         self.team = self.cnt + 1;
20 }
21
22 // code from here on is just to support maps that don't have team entities
23 void tdm_SpawnTeam (string teamname, float teamcolor)
24 {
25         entity this = new(tdm_team);
26         this.netname = teamname;
27         this.cnt = teamcolor;
28         this.spawnfunc_checked = true;
29         WITH(entity, self, this, spawnfunc_tdm_team(this));
30 }
31
32 void tdm_DelayedInit()
33 {
34         // if no teams are found, spawn defaults
35         if(find(world, classname, "tdm_team") == world)
36         {
37                 LOG_INFO("No ""tdm_team"" entities found on this map, creating them anyway.\n");
38
39                 int numteams = min(4, autocvar_g_tdm_teams_override);
40
41                 if(numteams < 2) { numteams = autocvar_g_tdm_teams; }
42                 numteams = bound(2, numteams, 4);
43
44                 float i;
45                 for(i = 1; i <= numteams; ++i)
46                         tdm_SpawnTeam(Team_ColorName(Team_NumberToTeam(i)), Team_NumberToTeam(i) - 1);
47         }
48 }
49
50 MUTATOR_HOOKFUNCTION(tdm, GetTeamCount, CBC_ORDER_EXCLUSIVE)
51 {
52         ret_string = "tdm_team";
53         return true;
54 }
55
56 MUTATOR_HOOKFUNCTION(tdm, Scores_CountFragsRemaining)
57 {
58         // announce remaining frags
59         return true;
60 }
61
62 REGISTER_MUTATOR(tdm, g_tdm)
63 {
64         ActivateTeamplay();
65         SetLimits(autocvar_g_tdm_point_limit, autocvar_g_tdm_point_leadlimit, -1, -1);
66         if(autocvar_g_tdm_team_spawns)
67                 have_team_spawns = -1; // request team spawns
68
69         MUTATOR_ONADD
70         {
71                 if(time > 1) // game loads at time 1
72                         error("This is a game type and it cannot be added at runtime.");
73                 InitializeEntity(world, tdm_DelayedInit, INITPRIO_GAMETYPE);
74         }
75
76         MUTATOR_ONROLLBACK_OR_REMOVE
77         {
78                 // we actually cannot roll back tdm_Initialize here
79                 // BUT: we don't need to! If this gets called, adding always
80                 // succeeds.
81         }
82
83         MUTATOR_ONREMOVE
84         {
85                 LOG_INFO("This is a game type and it cannot be removed at runtime.");
86                 return -1;
87         }
88
89         return 0;
90 }
91 #endif