]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator/gamemode_tdm.qc
Remove remove()
[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) { delete(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, int teamcolor)
62 {
63         entity this = new_pure(tdm_team);
64         this.netname = teamname;
65         this.cnt = teamcolor - 1;
66         this.team = teamcolor;
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 = autocvar_g_tdm_teams_override;
79
80                 if(numteams < 2) { numteams = autocvar_g_tdm_teams; }
81                 numteams = bound(2, numteams, 4);
82
83                 int teams = 0;
84                 if(numteams >= 1) teams |= BIT(0);
85                 if(numteams >= 2) teams |= BIT(1);
86                 if(numteams >= 3) teams |= BIT(2);
87                 if(numteams >= 4) teams |= BIT(3);
88
89                 if(teams & BIT(0))
90                         tdm_SpawnTeam("Red", NUM_TEAM_1);
91                 if(teams & BIT(1))
92                         tdm_SpawnTeam("Blue", NUM_TEAM_2);
93                 if(teams & BIT(2))
94                         tdm_SpawnTeam("Yellow", NUM_TEAM_3);
95                 if(teams & BIT(3))
96                         tdm_SpawnTeam("Pink", NUM_TEAM_4);
97         }
98 }
99
100 MUTATOR_HOOKFUNCTION(tdm, GetTeamCount, CBC_ORDER_EXCLUSIVE)
101 {
102         M_ARGV(1, string) = "tdm_team";
103         return true;
104 }
105
106 MUTATOR_HOOKFUNCTION(tdm, Scores_CountFragsRemaining)
107 {
108         // announce remaining frags
109         return true;
110 }
111
112 #endif