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