]> 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 #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 spawnfunc(tdm_team)
12 {
13         if(!g_tdm || !self.cnt) { 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 this = new(tdm_team);
23         this.netname = teamname;
24         this.cnt = teamcolor;
25         this.spawnfunc_checked = true;
26         WITH(entity, self, this, spawnfunc_tdm_team(this));
27 }
28
29 void tdm_DelayedInit()
30 {
31         // if no teams are found, spawn defaults
32         if(find(world, classname, "tdm_team") == world)
33         {
34                 LOG_INFO("No ""tdm_team"" entities found on this map, creating them anyway.\n");
35
36                 int numteams = min(4, autocvar_g_tdm_teams_override);
37
38                 if(numteams < 2) { numteams = autocvar_g_tdm_teams; }
39                 numteams = bound(2, numteams, 4);
40
41                 float i;
42                 for(i = 1; i <= numteams; ++i)
43                         tdm_SpawnTeam(Team_ColorName(Team_NumberToTeam(i)), Team_NumberToTeam(i) - 1);
44         }
45 }
46
47 MUTATOR_HOOKFUNCTION(tdm_GetTeamCount)
48 {
49         ret_string = "tdm_team";
50         return true;
51 }
52
53 MUTATOR_HOOKFUNCTION(tdm_CountFrags)
54 {
55         // announce remaining frags
56         return true;
57 }
58
59 MUTATOR_DEFINITION(gamemode_tdm)
60 {
61         MUTATOR_HOOK(GetTeamCount, tdm_GetTeamCount, CBC_ORDER_ANY);
62         MUTATOR_HOOK(Scores_CountFragsRemaining, tdm_CountFrags, CBC_ORDER_ANY);
63
64         MUTATOR_ONADD
65         {
66                 if(time > 1) // game loads at time 1
67                         error("This is a game type and it cannot be added at runtime.");
68                 InitializeEntity(world, tdm_DelayedInit, INITPRIO_GAMETYPE);
69         }
70
71         MUTATOR_ONROLLBACK_OR_REMOVE
72         {
73                 // we actually cannot roll back tdm_Initialize here
74                 // BUT: we don't need to! If this gets called, adding always
75                 // succeeds.
76         }
77
78         MUTATOR_ONREMOVE
79         {
80                 LOG_INFO("This is a game type and it cannot be removed at runtime.");
81                 return -1;
82         }
83
84         return 0;
85 }