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