]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator/gamemode_tdm.qc
Propagate this
[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();
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(world, tdm_DelayedInit, INITPRIO_GAMETYPE);
17
18                 ActivateTeamplay();
19                 SetLimits(autocvar_g_tdm_point_limit, autocvar_g_tdm_point_leadlimit, -1, -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 || !self.cnt) { remove(self); return; }
55
56         self.classname = "tdm_team";
57         self.team = self.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(tdm_team);
64         this.netname = teamname;
65         this.cnt = teamcolor;
66         this.spawnfunc_checked = true;
67         WITHSELF(this, spawnfunc_tdm_team(this));
68 }
69
70 void tdm_DelayedInit()
71 {
72         // if no teams are found, spawn defaults
73         if(find(world, classname, "tdm_team") == world)
74         {
75                 LOG_TRACE("No \"tdm_team\" entities found on this map, creating them anyway.\n");
76
77                 int numteams = min(4, autocvar_g_tdm_teams_override);
78
79                 if(numteams < 2) { numteams = autocvar_g_tdm_teams; }
80                 numteams = bound(2, numteams, 4);
81
82                 float i;
83                 for(i = 1; i <= numteams; ++i)
84                         tdm_SpawnTeam(Team_ColorName(Team_NumberToTeam(i)), Team_NumberToTeam(i) - 1);
85         }
86 }
87
88 MUTATOR_HOOKFUNCTION(tdm, GetTeamCount, CBC_ORDER_EXCLUSIVE)
89 {
90         ret_string = "tdm_team";
91         return true;
92 }
93
94 MUTATOR_HOOKFUNCTION(tdm, Scores_CountFragsRemaining)
95 {
96         // announce remaining frags
97         return true;
98 }
99
100 #endif