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