]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/gamemode_tdm.qc
Fix another function full of gamemode specific blocks
[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, CBC_ORDER_EXCLUSIVE)
47 {
48         ret_string = "tdm_team";
49         return true;
50 }
51
52 MUTATOR_HOOKFUNCTION(tdm, Scores_CountFragsRemaining)
53 {
54         // announce remaining frags
55         return true;
56 }
57
58 REGISTER_MUTATOR(tdm, g_tdm)
59 {
60         ActivateTeamplay();
61         SetLimits(autocvar_g_tdm_point_limit, autocvar_g_tdm_point_leadlimit, -1, -1);
62         if(autocvar_g_tdm_team_spawns)
63                 have_team_spawns = -1; // request team spawns
64
65         MUTATOR_ONADD
66         {
67                 if(time > 1) // game loads at time 1
68                         error("This is a game type and it cannot be added at runtime.");
69                 InitializeEntity(world, tdm_DelayedInit, INITPRIO_GAMETYPE);
70         }
71
72         MUTATOR_ONROLLBACK_OR_REMOVE
73         {
74                 // we actually cannot roll back tdm_Initialize here
75                 // BUT: we don't need to! If this gets called, adding always
76                 // succeeds.
77         }
78
79         MUTATOR_ONREMOVE
80         {
81                 LOG_INFO("This is a game type and it cannot be removed at runtime.");
82                 return -1;
83         }
84
85         return 0;
86 }