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