]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/gamemode_tdm.qc
Merge branch 'master' into sev/luma
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_tdm.qc
1 /*QUAKED spawnfunc_tdm_team (0 .5 .8) (-16 -16 -24) (16 16 32)
2 Team declaration for TDM gameplay, this allows you to decide what team names and control point models are used in your map.
3 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.
4 Keys:
5 "netname" Name of the team (for example Red, Blue, Green, Yellow, Life, Death, Offense, Defense, etc)...
6 "cnt" Scoreboard color of the team (for example 4 is red and 13 is blue)... */
7 void spawnfunc_tdm_team()
8 {
9         if(!g_tdm) { remove(self); return; }
10
11         self.classname = "tdm_team";
12         self.team = self.cnt + 1;
13 }
14
15 // code from here on is just to support maps that don't have team entities
16 void tdm_SpawnTeam (string teamname, float teamcolor)
17 {
18         entity oldself;
19         oldself = self;
20         self = spawn();
21         self.classname = "tdm_team";
22         self.netname = teamname;
23         self.cnt = teamcolor;
24
25         spawnfunc_tdm_team();
26
27         self = oldself;
28 }
29
30 void tdm_DelayedInit()
31 {
32         // if no teams are found, spawn defaults
33         if(find(world, classname, "tdm_team") == world)
34         {
35                 print("No ""tdm_team"" entities found on this map, creating them anyway.\n");
36
37                 float numteams = min(4, autocvar_g_tdm_teams_override);
38
39                 if(numteams < 2) { numteams = autocvar_g_tdm_teams; }
40                 numteams = bound(2, numteams, 4);
41
42                 float i;
43                 for(i = 1; i <= numteams; ++i)
44                         tdm_SpawnTeam(Team_ColorName(Team_NumberToTeam(i)), Team_NumberToTeam(i) - 1);
45         }
46 }
47
48 MUTATOR_HOOKFUNCTION(tdm_GetTeamCount)
49 {
50         ret_string = "tdm_team";
51         return TRUE;
52 }
53
54 MUTATOR_DEFINITION(gamemode_tdm)
55 {
56         MUTATOR_HOOK(GetTeamCount, tdm_GetTeamCount, CBC_ORDER_ANY);
57
58         MUTATOR_ONADD
59         {
60                 if(time > 1) // game loads at time 1
61                         error("This is a game type and it cannot be added at runtime.");
62                 InitializeEntity(world, tdm_DelayedInit, INITPRIO_GAMETYPE);
63         }
64
65         MUTATOR_ONROLLBACK_OR_REMOVE
66         {
67                 // we actually cannot roll back tdm_Initialize here
68                 // BUT: we don't need to! If this gets called, adding always
69                 // succeeds.
70         }
71
72         MUTATOR_ONREMOVE
73         {
74                 print("This is a game type and it cannot be removed at runtime.");
75                 return -1;
76         }
77
78         return 0;
79 }