]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/gamemode_tdm.qc
Remove oldself variables
[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 {SELFPARAM();
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 {SELFPARAM();
22         setself(spawn());
23         self.classname = "tdm_team";
24         self.netname = teamname;
25         self.cnt = teamcolor;
26
27         spawnfunc_tdm_team();
28
29         setself(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                 float 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)
51 {
52         ret_string = "tdm_team";
53         return true;
54 }
55
56 MUTATOR_HOOKFUNCTION(tdm_CountFrags)
57 {
58         // announce remaining frags
59         return true;
60 }
61
62 MUTATOR_DEFINITION(gamemode_tdm)
63 {
64         MUTATOR_HOOK(GetTeamCount, tdm_GetTeamCount, CBC_ORDER_ANY);
65         MUTATOR_HOOK(Scores_CountFragsRemaining, tdm_CountFrags, CBC_ORDER_ANY);
66
67         MUTATOR_ONADD
68         {
69                 if(time > 1) // game loads at time 1
70                         error("This is a game type and it cannot be added at runtime.");
71                 InitializeEntity(world, tdm_DelayedInit, INITPRIO_GAMETYPE);
72         }
73
74         MUTATOR_ONROLLBACK_OR_REMOVE
75         {
76                 // we actually cannot roll back tdm_Initialize here
77                 // BUT: we don't need to! If this gets called, adding always
78                 // succeeds.
79         }
80
81         MUTATOR_ONREMOVE
82         {
83                 LOG_INFO("This is a game type and it cannot be removed at runtime.");
84                 return -1;
85         }
86
87         return 0;
88 }