Debian Codegraph @

code/game/g_main.c

raw ◀ ▶
2 Debian patches touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23
24 #include "g_local.h"
25
26 level_locals_t level;
27
28 typedef struct {
29 vmCvar_t *vmCvar;
30 char *cvarName;
31 char *defaultString;
32 int cvarFlags;
33 int modificationCount; // for tracking changes
34 qboolean trackChange; // track this variable, and announce if changed
35 qboolean teamShader; // track and if changed, update shader state
36 } cvarTable_t;
37
38 gentity_t g_entities[MAX_GENTITIES];
39 gclient_t g_clients[MAX_CLIENTS];
40
41 vmCvar_t g_gametype;
42 vmCvar_t g_dmflags;
43 vmCvar_t g_videoflags;
44 vmCvar_t g_elimflags;
45 vmCvar_t g_voteflags;
46 vmCvar_t g_fraglimit;
47 vmCvar_t g_timelimit;
48 vmCvar_t g_capturelimit;
49 vmCvar_t g_friendlyFire;
50 vmCvar_t g_password;
51 vmCvar_t g_needpass;
52 vmCvar_t g_maxclients;
53 vmCvar_t g_maxGameClients;
54 vmCvar_t g_dedicated;
55 vmCvar_t g_speed;
56 vmCvar_t g_gravity;
57 vmCvar_t g_gravityModifier;
58 vmCvar_t g_damageModifier;
59 vmCvar_t g_cheats;
60 vmCvar_t g_knockback;
61 vmCvar_t g_quadfactor;
62 vmCvar_t g_forcerespawn;
63 vmCvar_t g_respawntime;
64 vmCvar_t g_inactivity;
65 vmCvar_t g_debugMove;
66 vmCvar_t g_debugDamage;
67 vmCvar_t g_debugAlloc;
68 vmCvar_t g_weaponRespawn;
69 vmCvar_t g_weaponTeamRespawn;
70 vmCvar_t g_motd;
71 vmCvar_t g_motdfile;
72 vmCvar_t g_votemaps;
73 vmCvar_t g_votecustom;
74 vmCvar_t g_synchronousClients;
75 vmCvar_t g_warmup;
76 vmCvar_t g_doWarmup;
77 vmCvar_t g_restarted;
78 vmCvar_t g_logfile;
79 vmCvar_t g_logfileSync;
80 vmCvar_t g_blood;
81 vmCvar_t g_podiumDist;
82 vmCvar_t g_podiumDrop;
83 vmCvar_t g_allowVote;
84 vmCvar_t g_teamAutoJoin;
85 vmCvar_t g_teamForceBalance;
86 vmCvar_t g_banIPs;
87 vmCvar_t g_filterBan;
88 vmCvar_t g_smoothClients;
89 vmCvar_t pmove_fixed;
90 vmCvar_t pmove_msec;
91 vmCvar_t pmove_float;
92 vmCvar_t g_rankings;
93 vmCvar_t g_listEntity;
94 vmCvar_t g_obeliskHealth;
95 vmCvar_t g_obeliskRegenPeriod;
96 vmCvar_t g_obeliskRegenAmount;
97 vmCvar_t g_obeliskRespawnDelay;
98 vmCvar_t g_cubeTimeout;
99 #ifdef MISSIONPACK
100 vmCvar_t g_redteam;
101 vmCvar_t g_blueteam;
102 vmCvar_t g_singlePlayer;
103 #endif
104 vmCvar_t g_enableDust;
105 vmCvar_t g_enableBreath;
106 vmCvar_t g_proxMineTimeout;
107 vmCvar_t g_music;
108 vmCvar_t g_spawnprotect;
109 //Following for elimination:
110 vmCvar_t g_elimination_selfdamage;
111 vmCvar_t g_elimination_startHealth;
112 vmCvar_t g_elimination_startArmor;
113 vmCvar_t g_elimination_bfg;
114 vmCvar_t g_elimination_grapple;
115 vmCvar_t g_elimination_roundtime;
116 vmCvar_t g_elimination_warmup;
117 vmCvar_t g_elimination_activewarmup;
118 vmCvar_t g_elimination_allgametypes;
119 vmCvar_t g_elimination_machinegun;
120 vmCvar_t g_elimination_shotgun;
121 vmCvar_t g_elimination_grenade;
122 vmCvar_t g_elimination_rocket;
123 vmCvar_t g_elimination_railgun;
124 vmCvar_t g_elimination_lightning;
125 vmCvar_t g_elimination_plasmagun;
126 vmCvar_t g_elimination_chain;
127 vmCvar_t g_elimination_mine;
128 vmCvar_t g_elimination_nail;
129
130 vmCvar_t g_elimination_lockspectator;
131
132 vmCvar_t g_rockets;
133
134 //dmn_clowns suggestions (with my idea of implementing):
135 vmCvar_t g_instantgib;
136 vmCvar_t g_vampire;
137 vmCvar_t g_vampireMaxHealth;
138 //Regen
139 vmCvar_t g_regen;
140 int g_ffa_gt; //Are this a FFA gametype even if gametype is high?
141 vmCvar_t g_lms_lives;
142 vmCvar_t g_lms_mode;
143 vmCvar_t g_elimination_ctf_oneway;
144 vmCvar_t g_awardpushing; //The server can decide if players are awarded for pushing people in lave etc.
145 vmCvar_t g_persistantpowerups; //Allow missionpack style persistant powerups?
146
147 vmCvar_t g_catchup; //Favors the week players
148
149 vmCvar_t g_autonextmap; //Autochange map
150 vmCvar_t g_mappools; //mappools to be used for autochange
151
152 vmCvar_t g_voteNames;
153 vmCvar_t g_voteBan;
154 vmCvar_t g_voteGametypes;
155 vmCvar_t g_voteMinTimelimit;
156 vmCvar_t g_voteMaxTimelimit;
157 vmCvar_t g_voteMinFraglimit;
158 vmCvar_t g_voteMaxFraglimit;
159 vmCvar_t g_maxvotes;
160
161 vmCvar_t g_humanplayers;
162
163 //used for voIP
164 vmCvar_t g_redTeamClientNumbers;
165 vmCvar_t g_blueTeamClientNumbers;
166
167 //unlagged - server options
168 vmCvar_t g_delagHitscan;
169 vmCvar_t g_truePing;
170 vmCvar_t sv_fps;
171 vmCvar_t g_lagLightning; //Adds a little lag to the lightninggun to make it less powerfull
172 //unlagged - server options
173 //KK-OAX
174 vmCvar_t g_sprees;
175 vmCvar_t g_altExcellent;
176 vmCvar_t g_spreeDiv;
177
178 //Command/Chat spamming/flooding
179 vmCvar_t g_floodMaxDemerits;
180 vmCvar_t g_floodMinTime;
181
182 //Admin
183 vmCvar_t g_admin;
184 vmCvar_t g_adminLog;
185 vmCvar_t g_adminParseSay;
186 vmCvar_t g_adminNameProtect;
187 vmCvar_t g_adminTempBan;
188 vmCvar_t g_adminMaxBan;
189 vmCvar_t g_specChat;
190 vmCvar_t g_publicAdminMessages;
191
192 vmCvar_t g_maxWarnings;
193 vmCvar_t g_warningExpire;
194
195 vmCvar_t g_minNameChangePeriod;
196 vmCvar_t g_maxNameChanges;
197
198 vmCvar_t g_timestamp_startgame;
199
200 // bk001129 - made static to avoid aliasing
201 static cvarTable_t gameCvarTable[] = {
202 // don't override the cheat state set by the system
203 { &g_cheats, "sv_cheats", "", 0, 0, qfalse },
204
205 // noset vars
206 { NULL, "gamename", GAMEVERSION , CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
•207 { NULL, "gamedate", PRODUCT_DATE , CVAR_ROM, 0, qfalse },
208 { &g_restarted, "g_restarted", "0", CVAR_ROM, 0, qfalse },
209 { NULL, "sv_mapname", "", CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
210
211 // latched vars
212 { &g_gametype, "g_gametype", "0", CVAR_SERVERINFO | CVAR_USERINFO | CVAR_LATCH, 0, qfalse },
213
214 { &g_maxclients, "sv_maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH | CVAR_ARCHIVE, 0, qfalse },
215 { &g_maxGameClients, "g_maxGameClients", "0", CVAR_SERVERINFO | CVAR_LATCH | CVAR_ARCHIVE, 0, qfalse },
216
217 // change anytime vars
218 { &g_dmflags, "dmflags", "0", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qtrue },
219 { &g_videoflags, "videoflags", "7", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qtrue },
220 { &g_elimflags, "elimflags", "0", CVAR_SERVERINFO, 0, qfalse },
221 { &g_voteflags, "voteflags", "0", CVAR_SERVERINFO, 0, qfalse },
222 { &g_fraglimit, "fraglimit", "20", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
223 { &g_timelimit, "timelimit", "0", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
224 { &g_capturelimit, "capturelimit", "8", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
225
226 { &g_synchronousClients, "g_synchronousClients", "0", CVAR_SYSTEMINFO, 0, qfalse },
227
228 { &g_friendlyFire, "g_friendlyFire", "0", CVAR_ARCHIVE, 0, qtrue },
229
230 { &g_teamAutoJoin, "g_teamAutoJoin", "0", CVAR_ARCHIVE },
231 { &g_teamForceBalance, "g_teamForceBalance", "0", CVAR_ARCHIVE },
232
233 { &g_warmup, "g_warmup", "20", CVAR_ARCHIVE, 0, qtrue },
234 { &g_doWarmup, "g_doWarmup", "0", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qtrue },
235 { &g_logfile, "g_log", "games.log", CVAR_ARCHIVE, 0, qfalse },
236 { &g_logfileSync, "g_logsync", "0", CVAR_ARCHIVE, 0, qfalse },
237
238 { &g_password, "g_password", "", CVAR_USERINFO, 0, qfalse },
239
240 { &g_banIPs, "g_banIPs", "", CVAR_ARCHIVE, 0, qfalse },
241 { &g_filterBan, "g_filterBan", "1", CVAR_ARCHIVE, 0, qfalse },
242
243 { &g_needpass, "g_needpass", "0", CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
244
245 { &g_dedicated, "dedicated", "0", 0, 0, qfalse },
246
247 { &g_speed, "g_speed", "320", 0, 0, qtrue },
248 { &g_gravity, "g_gravity", "800", 0, 0, qtrue },
249 { &g_gravityModifier, "g_gravityModifier", "1", 0, 0, qtrue },
250 { &g_damageModifier, "g_damageModifier", "0", 0, 0, qtrue },
251 { &g_knockback, "g_knockback", "1000", 0, 0, qtrue },
252 { &g_quadfactor, "g_quadfactor", "3", 0, 0, qtrue },
253 { &g_weaponRespawn, "g_weaponrespawn", "5", 0, 0, qtrue },
254 { &g_weaponTeamRespawn, "g_weaponTeamRespawn", "30", 0, 0, qtrue },
255 { &g_forcerespawn, "g_forcerespawn", "20", 0, 0, qtrue },
256 { &g_respawntime, "g_respawntime", "0", CVAR_ARCHIVE, 0, qtrue },
257 { &g_inactivity, "g_inactivity", "0", 0, 0, qtrue },
258 { &g_debugMove, "g_debugMove", "0", 0, 0, qfalse },
259 { &g_debugDamage, "g_debugDamage", "0", 0, 0, qfalse },
260 { &g_debugAlloc, "g_debugAlloc", "0", 0, 0, qfalse },
261 { &g_motd, "g_motd", "", 0, 0, qfalse },
262 { &g_motdfile, "g_motdfile", "motd.cfg", 0, 0, qfalse },
263 { &g_blood, "com_blood", "1", 0, 0, qfalse },
264
265 { &g_podiumDist, "g_podiumDist", "80", 0, 0, qfalse },
266 { &g_podiumDrop, "g_podiumDrop", "70", 0, 0, qfalse },
267
268 //Votes start:
269 { &g_allowVote, "g_allowVote", "1", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse },
270 { &g_maxvotes, "g_maxVotes", MAX_VOTE_COUNT, CVAR_ARCHIVE, 0, qfalse },
271 { &g_voteNames, "g_voteNames", "/map_restart/nextmap/map/g_gametype/kick/clientkick/g_doWarmup/timelimit/fraglimit/shuffle/", CVAR_ARCHIVE, 0, qfalse }, //clientkick g_doWarmup timelimit fraglimit
272 { &g_voteBan, "g_voteBan", "0", CVAR_ARCHIVE, 0, qfalse },
273 { &g_voteGametypes, "g_voteGametypes", "/0/1/3/4/5/6/7/8/9/10/11/12/", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse },
274 { &g_voteMaxTimelimit, "g_voteMaxTimelimit", "1000", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse },
275 { &g_voteMinTimelimit, "g_voteMinTimelimit", "0", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse },
276 { &g_voteMaxFraglimit, "g_voteMaxFraglimit", "0", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse },
277 { &g_voteMinFraglimit, "g_voteMinFraglimit", "0", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse },
278 { &g_votemaps, "g_votemapsfile", "votemaps.cfg", 0, 0, qfalse },
279 { &g_votecustom, "g_votecustomfile", "votecustom.cfg", 0, 0, qfalse },
280
281 { &g_listEntity, "g_listEntity", "0", 0, 0, qfalse },
282
283 { &g_obeliskHealth, "g_obeliskHealth", "2500", 0, 0, qfalse },
284 { &g_obeliskRegenPeriod, "g_obeliskRegenPeriod", "1", 0, 0, qfalse },
285 { &g_obeliskRegenAmount, "g_obeliskRegenAmount", "15", 0, 0, qfalse },
286 { &g_obeliskRespawnDelay, "g_obeliskRespawnDelay", "10", CVAR_SERVERINFO, 0, qfalse },
287
288 { &g_cubeTimeout, "g_cubeTimeout", "30", 0, 0, qfalse },
289 #ifdef MISSIONPACK
290 { &g_redteam, "g_redteam", "Stroggs", CVAR_ARCHIVE | CVAR_SERVERINFO | CVAR_USERINFO , 0, qtrue, qtrue },
291 { &g_blueteam, "g_blueteam", "Pagans", CVAR_ARCHIVE | CVAR_SERVERINFO | CVAR_USERINFO , 0, qtrue, qtrue },
292 { &g_singlePlayer, "ui_singlePlayerActive", "", 0, 0, qfalse, qfalse },
293 #endif
294
295 { &g_enableDust, "g_enableDust", "0", CVAR_SERVERINFO, 0, qtrue, qfalse },
296 { &g_enableBreath, "g_enableBreath", "0", CVAR_SERVERINFO, 0, qtrue, qfalse },
297 { &g_proxMineTimeout, "g_proxMineTimeout", "20000", 0, 0, qfalse },
298
299 { &g_smoothClients, "g_smoothClients", "1", 0, 0, qfalse},
300 { &pmove_fixed, "pmove_fixed", "0", CVAR_SYSTEMINFO | CVAR_ARCHIVE, 0, qfalse},
301 { &pmove_msec, "pmove_msec", "11", CVAR_SYSTEMINFO | CVAR_ARCHIVE, 0, qfalse},
302
303 { &pmove_float, "pmove_float", "1", CVAR_SYSTEMINFO | CVAR_ARCHIVE, 0, qtrue},
304
305 //unlagged - server options
306 { &g_delagHitscan, "g_delagHitscan", "0", CVAR_ARCHIVE | CVAR_SERVERINFO, 0, qtrue },
307 { &g_truePing, "g_truePing", "0", CVAR_ARCHIVE, 0, qtrue },
308 // it's CVAR_SYSTEMINFO so the client's sv_fps will be automagically set to its value
309 { &sv_fps, "sv_fps", "20", CVAR_SYSTEMINFO | CVAR_ARCHIVE, 0, qfalse },
310 { &g_lagLightning, "g_lagLightning", "1", CVAR_ARCHIVE, 0, qtrue },
311 //unlagged - server options
312
313 { &g_rankings, "g_rankings", "0", 0, 0, qfalse},
314 { &g_music, "g_music", "", 0, 0, qfalse},
315 { &g_spawnprotect, "g_spawnprotect", "500", CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue},
316 //Now for elimination stuff:
317 { &g_elimination_selfdamage, "elimination_selfdamage", "0", 0, 0, qtrue },
318 { &g_elimination_startHealth, "elimination_startHealth", "200", CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
319 { &g_elimination_startArmor, "elimination_startArmor", "150", CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
320 { &g_elimination_bfg, "elimination_bfg", "0", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
321 { &g_elimination_grapple, "elimination_grapple", "0", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
322 { &g_elimination_roundtime, "elimination_roundtime", "120", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
323 { &g_elimination_warmup, "elimination_warmup", "7", CVAR_ARCHIVE | CVAR_NORESTART , 0, qtrue },
324 { &g_elimination_activewarmup, "elimination_activewarmup", "5", CVAR_ARCHIVE | CVAR_NORESTART , 0, qtrue },
325 { &g_elimination_allgametypes, "g_elimination", "0", CVAR_LATCH | CVAR_NORESTART, 0, qfalse },
326
327 { &g_elimination_machinegun, "elimination_machinegun", "500", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
328 { &g_elimination_shotgun, "elimination_shotgun", "500", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
329 { &g_elimination_grenade, "elimination_grenade", "100", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
330 { &g_elimination_rocket, "elimination_rocket", "50", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
331 { &g_elimination_railgun, "elimination_railgun", "20", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
332 { &g_elimination_lightning, "elimination_lightning", "300", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
333 { &g_elimination_plasmagun, "elimination_plasmagun", "200", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
334 { &g_elimination_chain, "elimination_chain", "0", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
335 { &g_elimination_mine, "elimination_mine", "0", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
336 { &g_elimination_nail, "elimination_nail", "0", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
337
338 { &g_elimination_ctf_oneway, "elimination_ctf_oneway", "0", CVAR_ARCHIVE| CVAR_NORESTART, 0, qtrue },
339
340 { &g_elimination_lockspectator, "elimination_lockspectator", "0", CVAR_NORESTART, 0, qtrue },
341
342 { &g_awardpushing, "g_awardpushing", "1", CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
343
344 //g_persistantpowerups
345 #ifdef MISSIONPACK
346 { &g_persistantpowerups, "g_runes", "1", CVAR_LATCH, 0, qfalse },
347 #else
348 { &g_persistantpowerups, "g_runes", "0", CVAR_LATCH|CVAR_ARCHIVE, 0, qfalse },
349 #endif
350
351
352 //nexuiz style rocket arena
353 { &g_rockets, "g_rockets", "0", CVAR_SERVERINFO | CVAR_LATCH | CVAR_NORESTART, 0, qfalse },
354
355 //Instantgib and Vampire thingies
356 { &g_instantgib, "g_instantgib", "0", CVAR_SERVERINFO | CVAR_LATCH, 0, qfalse },
357 { &g_vampire, "g_vampire", "0.0", CVAR_NORESTART, 0, qtrue },
358 { &g_regen, "g_regen", "0", CVAR_NORESTART, 0, qtrue },
359 { &g_vampireMaxHealth, "g_vampire_max_health", "500", CVAR_NORESTART, 0, qtrue },
360 { &g_lms_lives, "g_lms_lives", "1", CVAR_NORESTART, 0, qtrue },
361 { &g_lms_mode, "g_lms_mode", "0", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
362
363 { &g_catchup, "g_catchup", "0", CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue},
364
365 { &g_autonextmap, "g_autonextmap", "0", CVAR_ARCHIVE | CVAR_NORESTART, 0, qfalse},
366 { &g_mappools, "g_mappools", "0\\maps_dm.cfg\\1\\maps_tourney.cfg\\3\\maps_tdm.cfg\\4\\maps_ctf.cfg\\5\\maps_oneflag.cfg\\6\\maps_obelisk.cfg\
367 \\7\\maps_harvester.cfg\\8\\maps_elimination.cfg\\9\\maps_ctf.cfg\\10\\maps_lms.cfg\\11\\maps_dd.cfg\\12\\maps_dom.cfg\\", CVAR_ARCHIVE | CVAR_NORESTART, 0, qfalse},
368 { &g_humanplayers, "g_humanplayers", "0", CVAR_ROM | CVAR_NORESTART, 0, qfalse },
369 //used for voIP
370 { &g_redTeamClientNumbers, "g_redTeamClientNumbers", "0",CVAR_ROM, 0, qfalse },
371 { &g_blueTeamClientNumbers, "g_blueTeamClientNumbers", "0",CVAR_ROM, 0, qfalse },
372
373 //KK-OAX
374 { &g_sprees, "g_sprees", "sprees.dat", 0, 0, qfalse },
375 { &g_altExcellent, "g_altExcellent", "0", CVAR_SERVERINFO, 0, qtrue},
376 { &g_spreeDiv, "g_spreeDiv", "5", 0, 0, qfalse},
377
378 //Used for command/chat flooding
379 { &g_floodMaxDemerits, "g_floodMaxDemerits", "5000", CVAR_ARCHIVE, 0, qfalse },
380 { &g_floodMinTime, "g_floodMinTime", "2000", CVAR_ARCHIVE, 0, qfalse },
381
382 //Admin
383 { &g_admin, "g_admin", "admin.dat", CVAR_ARCHIVE, 0, qfalse },
384 { &g_adminLog, "g_adminLog", "admin.log", CVAR_ARCHIVE, 0, qfalse },
385 { &g_adminParseSay, "g_adminParseSay", "1", CVAR_ARCHIVE, 0, qfalse },
386 { &g_adminNameProtect, "g_adminNameProtect", "1", CVAR_ARCHIVE, 0, qfalse },
387 { &g_adminTempBan, "g_adminTempBan", "2m", CVAR_ARCHIVE, 0, qfalse },
388 { &g_adminMaxBan, "g_adminMaxBan", "2w", CVAR_ARCHIVE, 0, qfalse },
389
390 { &g_specChat, "g_specChat", "1", CVAR_ARCHIVE, 0, qfalse },
391 { &g_publicAdminMessages, "g_publicAdminMessages", "1", CVAR_ARCHIVE, 0, qfalse },
392
393 { &g_maxWarnings, "g_maxWarnings", "3", CVAR_ARCHIVE, 0, qfalse },
394 { &g_warningExpire, "g_warningExpire", "3600", CVAR_ARCHIVE, 0, qfalse },
395
396 { &g_minNameChangePeriod, "g_minNameChangePeriod", "10", 0, 0, qfalse},
397 { &g_maxNameChanges, "g_maxNameChanges", "50", 0, 0, qfalse},
398
399 { &g_timestamp_startgame, "g_timestamp", "0001-01-01 00:00:00", CVAR_SERVERINFO, 0, qfalse}
400
401 };
402
403 // bk001129 - made static to avoid aliasing
404 static int gameCvarTableSize = sizeof( gameCvarTable ) / sizeof( gameCvarTable[0] );
405
406
407 void G_InitGame( int levelTime, int randomSeed, int restart );
408 void G_RunFrame( int levelTime );
409 void G_ShutdownGame( int restart );
410 void CheckExitRules( void );
411
412
413 /*
414 ================
415 vmMain
416
417 This is the only way control passes into the module.
418 This must be the very first function compiled into the .q3vm file
419 ================
420 */
•421 Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) {
422 switch ( command ) {
423 case GAME_INIT:
424 G_InitGame( arg0, arg1, arg2 );
425 return 0;
426 case GAME_SHUTDOWN:
427 G_ShutdownGame( arg0 );
428 return 0;
429 case GAME_CLIENT_CONNECT:
430 return (intptr_t)ClientConnect( arg0, arg1, arg2 );
431 case GAME_CLIENT_THINK:
432 ClientThink( arg0 );
433 return 0;
434 case GAME_CLIENT_USERINFO_CHANGED:
435 ClientUserinfoChanged( arg0 );
436 return 0;
437 case GAME_CLIENT_DISCONNECT:
438 ClientDisconnect( arg0 );
439 return 0;
440 case GAME_CLIENT_BEGIN:
441 ClientBegin( arg0 );
442 return 0;
443 case GAME_CLIENT_COMMAND:
444 ClientCommand( arg0 );
445 return 0;
446 case GAME_RUN_FRAME:
447 G_RunFrame( arg0 );
448 return 0;
449 case GAME_CONSOLE_COMMAND:
450 return ConsoleCommand();
451 case BOTAI_START_FRAME:
452 return BotAIStartFrame( arg0 );
453 }
454
455 return -1;
456 }
457
458
459 void QDECL G_Printf( const char *fmt, ... ) {
460 va_list argptr;
461 char text[1024];
462
463 va_start (argptr, fmt);
464 Q_vsnprintf (text, sizeof(text), fmt, argptr);
465 va_end (argptr);
466
467 trap_Printf( text );
468 }
469
470 void QDECL G_Error( const char *fmt, ... ) {
471 va_list argptr;
472 char text[1024];
473
474 va_start (argptr, fmt);
475 Q_vsnprintf (text, sizeof(text), fmt, argptr);
476 va_end (argptr);
477
478 trap_Error( text );
479 }
480
481 /*
482 ================
483 G_FindTeams
484
485 Chain together all entities with a matching team field.
486 Entity teams are used for item groups and multi-entity mover groups.
487
488 All but the first will have the FL_TEAMSLAVE flag set and teammaster field set
489 All but the last will have the teamchain field set to the next one
490 ================
491 */
492 void G_FindTeams( void ) {
493 gentity_t *e, *e2;
494 int i, j;
495 int c, c2;
496
497 c = 0;
498 c2 = 0;
499 for ( i=1, e=g_entities+i ; i < level.num_entities ; i++,e++ ){
500 if (!e->inuse)
501 continue;
502 if (!e->team)
503 continue;
504 if (e->flags & FL_TEAMSLAVE)
505 continue;
506 e->teammaster = e;
507 c++;
508 c2++;
509 for (j=i+1, e2=e+1 ; j < level.num_entities ; j++,e2++)
510 {
511 if (!e2->inuse)
512 continue;
513 if (!e2->team)
514 continue;
515 if (e2->flags & FL_TEAMSLAVE)
516 continue;
517 if (!strcmp(e->team, e2->team))
518 {
519 c2++;
520 e2->teamchain = e->teamchain;
521 e->teamchain = e2;
522 e2->teammaster = e;
523 e2->flags |= FL_TEAMSLAVE;
524
525 // make sure that targets only point at the master
526 if ( e2->targetname ) {
527 e->targetname = e2->targetname;
528 e2->targetname = NULL;
529 }
530 }
531 }
532 }
533 G_Printf ("%i teams with %i entities\n", c, c2);
534 }
535
536 void G_RemapTeamShaders( void ) {
537 #ifdef MISSIONPACK
538 char string[1024];
539 float f = level.time * 0.001;
540 Com_sprintf( string, sizeof(string), "team_icon/%s_red", g_redteam.string );
541 AddRemap("textures/ctf2/redteam01", string, f);
542 AddRemap("textures/ctf2/redteam02", string, f);
543 Com_sprintf( string, sizeof(string), "team_icon/%s_blue", g_blueteam.string );
544 AddRemap("textures/ctf2/blueteam01", string, f);
545 AddRemap("textures/ctf2/blueteam02", string, f);
546 trap_SetConfigstring(CS_SHADERSTATE, BuildShaderStateConfig());
547 #endif
548 }
549
550
551 /*
552 =================
553 G_RegisterCvars
554 =================
555 */
556 void G_RegisterCvars( void ) {
557 int i;
558 cvarTable_t *cv;
559 qboolean remapped = qfalse;
560
561 for ( i = 0, cv = gameCvarTable ; i < gameCvarTableSize ; i++, cv++ ) {
562 trap_Cvar_Register( cv->vmCvar, cv->cvarName,
563 cv->defaultString, cv->cvarFlags );
564 if ( cv->vmCvar )
565 cv->modificationCount = cv->vmCvar->modificationCount;
566
567 if (cv->teamShader) {
568 remapped = qtrue;
569 }
570 }
571
572 if (remapped) {
573 G_RemapTeamShaders();
574 }
575
576 // check some things
577 if ( g_gametype.integer < 0 || g_gametype.integer >= GT_MAX_GAME_TYPE ) {
578 G_Printf( "g_gametype %i is out of range, defaulting to 0\n", g_gametype.integer );
579 trap_Cvar_Set( "g_gametype", "0" );
580 }
581
582 //set FFA status for high gametypes:
583 if ( g_gametype.integer == GT_LMS ) {
584 g_ffa_gt = 1; //Last Man standig is a FFA gametype
585 } else {
586 g_ffa_gt = 0; //If >GT_CTF use bases
587 }
588
589 level.warmupModificationCount = g_warmup.modificationCount;
590 }
591
592 /*
593 =================
594 G_UpdateCvars
595 =================
596 */
597 void G_UpdateCvars( void ) {
598 int i;
599 cvarTable_t *cv;
600 qboolean remapped = qfalse;
601
602 for ( i = 0, cv = gameCvarTable ; i < gameCvarTableSize ; i++, cv++ ) {
603 if ( cv->vmCvar ) {
604 trap_Cvar_Update( cv->vmCvar );
605
606 if ( cv->modificationCount != cv->vmCvar->modificationCount ) {
607 cv->modificationCount = cv->vmCvar->modificationCount;
608
609 if ( cv->trackChange ) {
610 trap_SendServerCommand( -1, va("print \"Server: %s changed to %s\n\"",
611 cv->cvarName, cv->vmCvar->string ) );
612 }
613
614 if ( cv->vmCvar == &g_votecustom )
615 VoteParseCustomVotes();
616
617 //Here comes the cvars that must trigger a map_restart
618 if (cv->vmCvar == &g_instantgib || cv->vmCvar == &g_rockets || cv->vmCvar == &g_elimination_allgametypes) {
619 trap_Cvar_Set("sv_dorestart","1");
620 }
621
622 if ( cv->vmCvar == &g_voteNames ) {
623 //Set vote flags
624 int voteflags=0;
625 if( allowedVote("map_restart") )
626 voteflags|=VF_map_restart;
627
628 if( allowedVote("map") )
629 voteflags|=VF_map;
630
631 if( allowedVote("clientkick") )
632 voteflags|=VF_clientkick;
633
634 if( allowedVote("shuffle") )
635 voteflags|=VF_shuffle;
636
637 if( allowedVote("nextmap") )
638 voteflags|=VF_nextmap;
639
640 if( allowedVote("g_gametype") )
641 voteflags|=VF_g_gametype;
642
643 if( allowedVote("g_doWarmup") )
644 voteflags|=VF_g_doWarmup;
645
646 if( allowedVote("timelimit") )
647 voteflags|=VF_timelimit;
648
649 if( allowedVote("fraglimit") )
650 voteflags|=VF_fraglimit;
651
652 if( allowedVote("custom") )
653 voteflags|=VF_custom;
654
655 trap_Cvar_Set("voteflags",va("%i",voteflags));
656 }
657
658 if (cv->teamShader) {
659 remapped = qtrue;
660 }
661 }
662 }
663 }
664
665 if (remapped) {
666 G_RemapTeamShaders();
667 }
668 }
669
670 /*
671 Sets the cvar g_timestamp. Return 0 if success or !0 for errors.
672 */
673 int G_UpdateTimestamp( void ) {
674 int ret = 0;
675 qtime_t timestamp;
676 ret = trap_RealTime(&timestamp);
677 trap_Cvar_Set("g_timestamp",va("%04i-%02i-%02i %02i:%02i:%02i",
678 1900+timestamp.tm_year,1+timestamp.tm_mon, timestamp.tm_mday,
679 timestamp.tm_hour,timestamp.tm_min,timestamp.tm_sec));
680
681 return ret;
682 }
683
684 /*
685 ============
686 G_InitGame
687
688 ============
689 */
690 void G_InitGame( int levelTime, int randomSeed, int restart ) {
691 int i;
692
693
694 G_Printf ("------- Game Initialization -------\n");
695 G_Printf ("gamename: %s\n", GAMEVERSION);
•696 G_Printf ("gamedate: %s\n", PRODUCT_DATE);
697
698 srand( randomSeed );
699
700 G_RegisterCvars();
701
702 G_UpdateTimestamp();
703
704 //disable unwanted cvars
705 if( g_gametype.integer == GT_SINGLE_PLAYER )
706 {
707 g_instantgib.integer = 0;
708 g_rockets.integer = 0;
709 g_vampire.value = 0.0f;
710 }
711
712 G_ProcessIPBans();
713
714 //KK-OAX Changed to Tremulous's BG_InitMemory
715 BG_InitMemory();
716
717 // set some level globals
718 memset( &level, 0, sizeof( level ) );
719
720 level.time = levelTime;
721 level.startTime = levelTime;
722
723 level.snd_fry = G_SoundIndex("sound/player/fry.wav"); // FIXME standing in lava / slime
724
725 if ( g_gametype.integer != GT_SINGLE_PLAYER && g_logfile.string[0] ) {
726 if ( g_logfileSync.integer ) {
727 trap_FS_FOpenFile( g_logfile.string, &level.logFile, FS_APPEND_SYNC );
728 } else {
729 trap_FS_FOpenFile( g_logfile.string, &level.logFile, FS_APPEND );
730 }
731 if ( !level.logFile ) {
732 G_Printf( "WARNING: Couldn't open logfile: %s\n", g_logfile.string );
733 } else {
734 char serverinfo[MAX_INFO_STRING];
735
736 trap_GetServerinfo( serverinfo, sizeof( serverinfo ) );
737
738 G_LogPrintf("------------------------------------------------------------\n" );
739 G_LogPrintf("InitGame: %s\n", serverinfo );
740 G_LogPrintf("Info: ServerInfo length: %d of %d\n", strlen(serverinfo), MAX_INFO_STRING );
741 }
742 } else {
743 G_Printf( "Not logging to disk.\n" );
744 }
745
746 //Parse the custom vote names:
747 VoteParseCustomVotes();
748
749 G_InitWorldSession();
750
751 //KK-OAX Get Admin Configuration
752 G_admin_readconfig( NULL, 0 );
753 //Let's Load up any killing sprees/multikills
754 G_ReadAltKillSettings( NULL, 0 );
755
756 // initialize all entities for this game
757 memset( g_entities, 0, MAX_GENTITIES * sizeof(g_entities[0]) );
758 level.gentities = g_entities;
759
760 // initialize all clients for this game
761 level.maxclients = g_maxclients.integer;
762 memset( g_clients, 0, MAX_CLIENTS * sizeof(g_clients[0]) );
763 level.clients = g_clients;
764
765 // set client fields on player ents
766 for ( i=0 ; i<level.maxclients ; i++ ) {
767 g_entities[i].client = level.clients + i;
768 }
769
770 // always leave room for the max number of clients,
771 // even if they aren't all used, so numbers inside that
772 // range are NEVER anything but clients
773 level.num_entities = MAX_CLIENTS;
774
775 for ( i=0 ; i<MAX_CLIENTS ; i++ ) {
776 g_entities[i].classname = "clientslot";
777 }
778
779 // let the server system know where the entites are
780 trap_LocateGameData( level.gentities, level.num_entities, sizeof( gentity_t ),
781 &level.clients[0].ps, sizeof( level.clients[0] ) );
782
783 // reserve some spots for dead player bodies
784 InitBodyQue();
785
786 ClearRegisteredItems();
787
788 // parse the key/value pairs and spawn gentities
789 G_SpawnEntitiesFromString();
790
791 // general initialization
792 G_FindTeams();
793
794 // make sure we have flags for CTF, etc
795 if( g_gametype.integer >= GT_TEAM && (g_ffa_gt!=1)) {
796 G_CheckTeamItems();
797 }
798
799 SaveRegisteredItems();
800
801 G_Printf ("-----------------------------------\n");
802
803 if( g_gametype.integer == GT_SINGLE_PLAYER || trap_Cvar_VariableIntegerValue( "com_buildScript" ) ) {
804 G_ModelIndex( SP_PODIUM_MODEL );
805 }
806
807 if ( trap_Cvar_VariableIntegerValue( "bot_enable" ) ) {
808 BotAISetup( restart );
809 BotAILoadMap( restart );
810 G_InitBots( restart );
811 }
812
813 G_RemapTeamShaders();
814
815 //elimination:
816 level.roundNumber = 1;
817 level.roundNumberStarted = 0;
818 level.roundStartTime = level.time+g_elimination_warmup.integer*1000;
819 level.roundRespawned = qfalse;
820 level.eliminationSides = rand()%2; //0 or 1
821
822 //Challenges:
823 level.teamSize = 0;
824 level.hadBots = qfalse;
825
826 if(g_gametype.integer == GT_DOUBLE_D)
827 Team_SpawnDoubleDominationPoints();
828
829 if(g_gametype.integer == GT_DOMINATION ){
830 level.dom_scoreGiven = 0;
831 for(i=0;i<MAX_DOMINATION_POINTS;i++)
832 level.pointStatusDom[i] = TEAM_NONE;
833 level.domination_points_count = 0; //make sure its not too big
834 }
835
836 PlayerStoreInit();
837
838 //Set vote flags
839 {
840 int voteflags=0;
841 if( allowedVote("map_restart") )
842 voteflags|=VF_map_restart;
843
844 if( allowedVote("map") )
845 voteflags|=VF_map;
846
847 if( allowedVote("clientkick") )
848 voteflags|=VF_clientkick;
849
850 if( allowedVote("shuffle") )
851 voteflags|=VF_shuffle;
852
853 if( allowedVote("nextmap") )
854 voteflags|=VF_nextmap;
855
856 if( allowedVote("g_gametype") )
857 voteflags|=VF_g_gametype;
858
859 if( allowedVote("g_doWarmup") )
860 voteflags|=VF_g_doWarmup;
861
862 if( allowedVote("timelimit") )
863 voteflags|=VF_timelimit;
864
865 if( allowedVote("fraglimit") )
866 voteflags|=VF_fraglimit;
867
868 if( allowedVote("custom") )
869 voteflags|=VF_custom;
870
871 trap_Cvar_Set("voteflags",va("%i",voteflags));
872 }
873 }
874
875
876
877 /*
878 =================
879 G_ShutdownGame
880 =================
881 */
882 void G_ShutdownGame( int restart ) {
883 G_Printf ("==== ShutdownGame ====\n");
884
885 if ( level.logFile ) {
886 G_LogPrintf("ShutdownGame:\n" );
887 G_LogPrintf("------------------------------------------------------------\n" );
888 trap_FS_FCloseFile( level.logFile );
889 level.logFile = 0;
890 }
891
892 // write all the client session data so we can get it back
893 G_WriteSessionData();
894
895 //KK-OAX Admin Cleanup
896 G_admin_cleanup( );
897 G_admin_namelog_cleanup( );
898
899 if ( trap_Cvar_VariableIntegerValue( "bot_enable" ) ) {
900 BotAIShutdown( restart );
901 }
902 }
903
904
905
906 //===================================================================
907
908 void QDECL Com_Error ( int level, const char *error, ... ) {
909 va_list argptr;
910 char text[1024];
911
912 va_start (argptr, error);
913 Q_vsnprintf (text, sizeof(text), error, argptr);
914 va_end (argptr);
915
916 G_Error( "%s", text);
917 }
918
919 void QDECL Com_Printf( const char *msg, ... ) {
920 va_list argptr;
921 char text[1024];
922
923 va_start (argptr, msg);
924 Q_vsnprintf (text, sizeof(text), msg, argptr);
925 va_end (argptr);
926
927 G_Printf ("%s", text);
928 }
929
930 /*
931 ========================================================================
932
933 PLAYER COUNTING / SCORE SORTING
934
935 ========================================================================
936 */
937
938 /*
939 =============
940 AddTournamentPlayer
941
942 If there are less than two tournament players, put a
943 spectator in the game and restart
944 =============
945 */
946 void AddTournamentPlayer( void ) {
947 int i;
948 gclient_t *client;
949 gclient_t *nextInLine;
950
951 if ( level.numPlayingClients >= 2 ) {
952 return;
953 }
954
955 // never change during intermission
956 if ( level.intermissiontime ) {
957 return;
958 }
959
960 nextInLine = NULL;
961
962 for ( i = 0 ; i < level.maxclients ; i++ ) {
963 client = &level.clients[i];
964 if ( client->pers.connected != CON_CONNECTED ) {
965 continue;
966 }
967 if ( client->sess.sessionTeam != TEAM_SPECTATOR ) {
968 continue;
969 }
970 // never select the dedicated follow or scoreboard clients
971 if ( client->sess.spectatorState == SPECTATOR_SCOREBOARD ||
972 client->sess.spectatorClient < 0 ) {
973 continue;
974 }
975
976 if(!nextInLine || client->sess.spectatorNum > nextInLine->sess.spectatorNum) {
977 nextInLine = client;
978 }
979 }
980
981 if ( !nextInLine ) {
982 return;
983 }
984
985 level.warmupTime = -1;
986
987 // set them to free-for-all team
988 SetTeam( &g_entities[ nextInLine - level.clients ], "f" );
989 }
990
991 /*
992 =======================
993 AddTournamentQueue
994
995 Add client to end of tournament queue
996 =======================
997 */
998 void AddTournamentQueue(gclient_t *client)
999 {
1000 int index;
1001 gclient_t *curclient;
1002 for(index = 0; index < level.maxclients; index++)
1003 {
1004 curclient = &level.clients[index];
1005 if(curclient->pers.connected != CON_DISCONNECTED)
1006 {
1007 if(curclient == client)
1008 curclient->sess.spectatorNum = 0;
1009 else if(curclient->sess.sessionTeam == TEAM_SPECTATOR)
1010 curclient->sess.spectatorNum++;
1011 }
1012 }
1013 }
1014
1015 /*
1016 =======================
1017 RemoveTournamentLoser
1018
1019 Make the loser a spectator at the back of the line
1020 =======================
1021 */
1022 void RemoveTournamentLoser( void ) {
1023 int clientNum;
1024
1025 if ( level.numPlayingClients != 2 ) {
1026 return;
1027 }
1028
1029 clientNum = level.sortedClients[1];
1030
1031 if ( level.clients[ clientNum ].pers.connected != CON_CONNECTED ) {
1032 return;
1033 }
1034
1035 // make them a spectator
1036 SetTeam( &g_entities[ clientNum ], "s" );
1037 }
1038
1039 /*
1040 =======================
1041 RemoveTournamentWinner
1042 =======================
1043 */
1044 void RemoveTournamentWinner( void ) {
1045 int clientNum;
1046
1047 if ( level.numPlayingClients != 2 ) {
1048 return;
1049 }
1050
1051 clientNum = level.sortedClients[0];
1052
1053 if ( level.clients[ clientNum ].pers.connected != CON_CONNECTED ) {
1054 return;
1055 }
1056
1057 // make them a spectator
1058 SetTeam( &g_entities[ clientNum ], "s" );
1059 }
1060
1061 /*
1062 =======================
1063 AdjustTournamentScores
1064 =======================
1065 */
1066 void AdjustTournamentScores( void ) {
1067 int clientNum;
1068
1069 clientNum = level.sortedClients[0];
1070 if ( level.clients[ clientNum ].pers.connected == CON_CONNECTED ) {
1071 level.clients[ clientNum ].sess.wins++;
1072 ClientUserinfoChanged( clientNum );
1073 }
1074
1075 clientNum = level.sortedClients[1];
1076 if ( level.clients[ clientNum ].pers.connected == CON_CONNECTED ) {
1077 level.clients[ clientNum ].sess.losses++;
1078 ClientUserinfoChanged( clientNum );
1079 }
1080
1081 }
1082
1083 /*
1084 =============
1085 SortRanks
1086
1087 =============
1088 */
1089 int QDECL SortRanks( const void *a, const void *b ) {
1090 gclient_t *ca, *cb;
1091
1092 ca = &level.clients[*(int *)a];
1093 cb = &level.clients[*(int *)b];
1094
1095 // sort special clients last
1096 if ( ca->sess.spectatorState == SPECTATOR_SCOREBOARD || ca->sess.spectatorClient < 0 ) {
1097 return 1;
1098 }
1099 if ( cb->sess.spectatorState == SPECTATOR_SCOREBOARD || cb->sess.spectatorClient < 0 ) {
1100 return -1;
1101 }
1102
1103 // then connecting clients
1104 if ( ca->pers.connected == CON_CONNECTING ) {
1105 return 1;
1106 }
1107 if ( cb->pers.connected == CON_CONNECTING ) {
1108 return -1;
1109 }
1110
1111
1112 // then spectators
1113 if ( ca->sess.sessionTeam == TEAM_SPECTATOR && cb->sess.sessionTeam == TEAM_SPECTATOR ) {
1114 if ( ca->sess.spectatorNum > cb->sess.spectatorNum ) {
1115 return -1;
1116 }
1117 if ( ca->sess.spectatorNum < cb->sess.spectatorNum ) {
1118 return 1;
1119 }
1120 return 0;
1121 }
1122 if ( ca->sess.sessionTeam == TEAM_SPECTATOR ) {
1123 return 1;
1124 }
1125 if ( cb->sess.sessionTeam == TEAM_SPECTATOR ) {
1126 return -1;
1127 }
1128
1129 //In elimination and CTF elimination, sort dead players last
1130 if((g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION)
1131 && level.roundNumber==level.roundNumberStarted && (ca->isEliminated != cb->isEliminated)) {
1132 if( ca->isEliminated )
1133 return 1;
1134 if( cb->isEliminated )
1135 return -1;
1136 }
1137
1138 // then sort by score
1139 if ( ca->ps.persistant[PERS_SCORE]
1140 > cb->ps.persistant[PERS_SCORE] ) {
1141 return -1;
1142 }
1143 if ( ca->ps.persistant[PERS_SCORE]
1144 < cb->ps.persistant[PERS_SCORE] ) {
1145 return 1;
1146 }
1147 return 0;
1148 }
1149
1150 /*
1151 ============
1152 CalculateRanks
1153
1154 Recalculates the score ranks of all players
1155 This will be called on every client connect, begin, disconnect, death,
1156 and team change.
1157 ============
1158 */
1159 void CalculateRanks( void ) {
1160 int i;
1161 int rank;
1162 int score;
1163 int newScore;
1164 int humanplayers;
1165 gclient_t *cl;
1166
1167 level.follow1 = -1;
1168 level.follow2 = -1;
1169 level.numConnectedClients = 0;
1170 level.numNonSpectatorClients = 0;
1171 level.numPlayingClients = 0;
1172 humanplayers = 0; // don't count bots
1173 for ( i = 0; i < TEAM_NUM_TEAMS; i++ ) {
1174 level.numteamVotingClients[i] = 0;
1175 }
1176 for ( i = 0 ; i < level.maxclients ; i++ ) {
1177 if ( level.clients[i].pers.connected != CON_DISCONNECTED ) {
1178 level.sortedClients[level.numConnectedClients] = i;
1179 level.numConnectedClients++;
1180
1181 //We just set humanplayers to 0 during intermission
1182 if ( !level.intermissiontime && level.clients[i].pers.connected == CON_CONNECTED && !(g_entities[i].r.svFlags & SVF_BOT) ) {
1183 humanplayers++;
1184 }
1185
1186 if ( level.clients[i].sess.sessionTeam != TEAM_SPECTATOR ) {
1187 level.numNonSpectatorClients++;
1188 // decide if this should be auto-followed
1189 if ( level.clients[i].pers.connected == CON_CONNECTED ) {
1190 level.numPlayingClients++;
1191 if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
1192 if ( level.clients[i].sess.sessionTeam == TEAM_RED )
1193 level.numteamVotingClients[0]++;
1194 else if ( level.clients[i].sess.sessionTeam == TEAM_BLUE )
1195 level.numteamVotingClients[1]++;
1196 }
1197 if ( level.follow1 == -1 ) {
1198 level.follow1 = i;
1199 } else if ( level.follow2 == -1 ) {
1200 level.follow2 = i;
1201 }
1202 }
1203 }
1204 }
1205 }
1206
1207 qsort( level.sortedClients, level.numConnectedClients,
1208 sizeof(level.sortedClients[0]), SortRanks );
1209
1210 // set the rank value for all clients that are connected and not spectators
1211 if ( g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) {
1212 // in team games, rank is just the order of the teams, 0=red, 1=blue, 2=tied
1213 for ( i = 0; i < level.numConnectedClients; i++ ) {
1214 cl = &level.clients[ level.sortedClients[i] ];
1215 if ( level.teamScores[TEAM_RED] == level.teamScores[TEAM_BLUE] ) {
1216 cl->ps.persistant[PERS_RANK] = 2;
1217 } else if ( level.teamScores[TEAM_RED] > level.teamScores[TEAM_BLUE] ) {
1218 cl->ps.persistant[PERS_RANK] = 0;
1219 } else {
1220 cl->ps.persistant[PERS_RANK] = 1;
1221 }
1222 }
1223 } else {
1224 rank = -1;
1225 score = 0;
1226 for ( i = 0; i < level.numPlayingClients; i++ ) {
1227 cl = &level.clients[ level.sortedClients[i] ];
1228 newScore = cl->ps.persistant[PERS_SCORE];
1229 if ( i == 0 || newScore != score ) {
1230 rank = i;
1231 // assume we aren't tied until the next client is checked
1232 level.clients[ level.sortedClients[i] ].ps.persistant[PERS_RANK] = rank;
1233 } else {
1234 // we are tied with the previous client
1235 level.clients[ level.sortedClients[i-1] ].ps.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
1236 level.clients[ level.sortedClients[i] ].ps.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
1237 }
1238 score = newScore;
1239 if ( g_gametype.integer == GT_SINGLE_PLAYER && level.numPlayingClients == 1 ) {
1240 level.clients[ level.sortedClients[i] ].ps.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
1241 }
1242 }
1243 }
1244
1245 // set the CS_SCORES1/2 configstrings, which will be visible to everyone
1246 if ( g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) {
1247 trap_SetConfigstring( CS_SCORES1, va("%i", level.teamScores[TEAM_RED] ) );
1248 trap_SetConfigstring( CS_SCORES2, va("%i", level.teamScores[TEAM_BLUE] ) );
1249 } else {
1250 if ( level.numConnectedClients == 0 ) {
1251 trap_SetConfigstring( CS_SCORES1, va("%i", SCORE_NOT_PRESENT) );
1252 trap_SetConfigstring( CS_SCORES2, va("%i", SCORE_NOT_PRESENT) );
1253 } else if ( level.numConnectedClients == 1 ) {
1254 trap_SetConfigstring( CS_SCORES1, va("%i", level.clients[ level.sortedClients[0] ].ps.persistant[PERS_SCORE] ) );
1255 trap_SetConfigstring( CS_SCORES2, va("%i", SCORE_NOT_PRESENT) );
1256 } else {
1257 trap_SetConfigstring( CS_SCORES1, va("%i", level.clients[ level.sortedClients[0] ].ps.persistant[PERS_SCORE] ) );
1258 trap_SetConfigstring( CS_SCORES2, va("%i", level.clients[ level.sortedClients[1] ].ps.persistant[PERS_SCORE] ) );
1259 }
1260 }
1261
1262 // see if it is time to end the level
1263 CheckExitRules();
1264
1265 // if we are at the intermission, send the new info to everyone
1266 if ( level.intermissiontime ) {
1267 SendScoreboardMessageToAllClients();
1268 }
1269
1270 if(g_humanplayers.integer != humanplayers) //Presume all spectators are humans!
1271 trap_Cvar_Set( "g_humanplayers", va("%i", humanplayers) );
1272 }
1273
1274
1275 /*
1276 ========================================================================
1277
1278 MAP CHANGING
1279
1280 ========================================================================
1281 */
1282
1283 /*
1284 ========================
1285 SendScoreboardMessageToAllClients
1286
1287 Do this at BeginIntermission time and whenever ranks are recalculated
1288 due to enters/exits/forced team changes
1289 ========================
1290 */
1291 void SendScoreboardMessageToAllClients( void ) {
1292 int i;
1293
1294 for ( i = 0 ; i < level.maxclients ; i++ ) {
1295 if ( level.clients[ i ].pers.connected == CON_CONNECTED ) {
1296 DeathmatchScoreboardMessage( g_entities + i );
1297 EliminationMessage( g_entities + i );
1298 }
1299 }
1300 }
1301
1302 /*
1303 ========================
1304 SendElimiantionMessageToAllClients
1305
1306 Used to send information important to Elimination
1307 ========================
1308 */
1309 void SendEliminationMessageToAllClients( void ) {
1310 int i;
1311
1312 for ( i = 0 ; i < level.maxclients ; i++ ) {
1313 if ( level.clients[ i ].pers.connected == CON_CONNECTED ) {
1314 EliminationMessage( g_entities + i );
1315 }
1316 }
1317 }
1318
1319 /*
1320 ========================
1321 SendDDtimetakenMessageToAllClients
1322
1323 Do this if a team just started dominating.
1324 ========================
1325 */
1326 void SendDDtimetakenMessageToAllClients( void ) {
1327 int i;
1328
1329 for ( i = 0 ; i < level.maxclients ; i++ ) {
1330 if ( level.clients[ i ].pers.connected == CON_CONNECTED ) {
1331 DoubleDominationScoreTimeMessage( g_entities + i );
1332 }
1333 }
1334 }
1335
1336 /*
1337 ========================
1338 SendAttackingTeamMessageToAllClients
1339
1340 Used for CTF Elimination oneway
1341 ========================
1342 */
1343 void SendAttackingTeamMessageToAllClients( void ) {
1344 int i;
1345
1346 for ( i = 0 ; i < level.maxclients ; i++ ) {
1347 if ( level.clients[ i ].pers.connected == CON_CONNECTED ) {
1348 AttackingTeamMessage( g_entities + i );
1349 }
1350 }
1351 }
1352
1353 /*
1354 ========================
1355 SendDominationPointsStatusMessageToAllClients
1356
1357 Used for Standard domination
1358 ========================
1359 */
1360 void SendDominationPointsStatusMessageToAllClients( void ) {
1361 int i;
1362
1363 for ( i = 0 ; i < level.maxclients ; i++ ) {
1364 if ( level.clients[ i ].pers.connected == CON_CONNECTED ) {
1365 DominationPointStatusMessage( g_entities + i );
1366 }
1367 }
1368 }
1369 /*
1370 ========================
1371 SendYourTeamMessageToTeam
1372
1373 Tell all players on a given team who there allies are. Used for VoIP
1374 ========================
1375 */
1376 void SendYourTeamMessageToTeam( team_t team ) {
1377 int i;
1378
1379 for ( i = 0 ; i < level.maxclients ; i++ ) {
1380 if ( level.clients[ i ].pers.connected == CON_CONNECTED && level.clients[ i ].sess.sessionTeam == team ) {
1381 YourTeamMessage( g_entities + i );
1382 }
1383 }
1384 }
1385
1386
1387 /*
1388 ========================
1389 MoveClientToIntermission
1390
1391 When the intermission starts, this will be called for all players.
1392 If a new client connects, this will be called after the spawn function.
1393 ========================
1394 */
1395 void MoveClientToIntermission( gentity_t *ent ) {
1396 // take out of follow mode if needed
1397 if ( ent->client->sess.spectatorState == SPECTATOR_FOLLOW ) {
1398 StopFollowing( ent );
1399 }
1400
1401 FindIntermissionPoint();
1402 // move to the spot
1403 VectorCopy( level.intermission_origin, ent->s.origin );
1404 VectorCopy( level.intermission_origin, ent->client->ps.origin );
1405 VectorCopy (level.intermission_angle, ent->client->ps.viewangles);
1406 ent->client->ps.pm_type = PM_INTERMISSION;
1407
1408 // clean up powerup info
1409 memset( ent->client->ps.powerups, 0, sizeof(ent->client->ps.powerups) );
1410
1411 ent->client->ps.eFlags = 0;
1412 ent->s.eFlags = 0;
1413 ent->s.eType = ET_GENERAL;
1414 ent->s.modelindex = 0;
1415 ent->s.loopSound = 0;
1416 ent->s.event = 0;
1417 ent->r.contents = 0;
1418 }
1419
1420 /*
1421 ==================
1422 FindIntermissionPoint
1423
1424 This is also used for spectator spawns
1425 ==================
1426 */
1427 void FindIntermissionPoint( void ) {
1428 gentity_t *ent, *target;
1429 vec3_t dir;
1430
1431 // find the intermission spot
1432 ent = G_Find (NULL, FOFS(classname), "info_player_intermission");
1433 if ( !ent ) { // the map creator forgot to put in an intermission point...
1434 SelectSpawnPoint ( vec3_origin, level.intermission_origin, level.intermission_angle );
1435 } else {
1436 VectorCopy (ent->s.origin, level.intermission_origin);
1437 VectorCopy (ent->s.angles, level.intermission_angle);
1438 // if it has a target, look towards it
1439 if ( ent->target ) {
1440 target = G_PickTarget( ent->target );
1441 if ( target ) {
1442 VectorSubtract( target->s.origin, level.intermission_origin, dir );
1443 vectoangles( dir, level.intermission_angle );
1444 }
1445 }
1446 }
1447
1448 }
1449
1450 /*
1451 ==================
1452 BeginIntermission
1453 ==================
1454 */
1455 void BeginIntermission( void ) {
1456 int i;
1457 gentity_t *client;
1458
1459 if ( level.intermissiontime ) {
1460 return; // already active
1461 }
1462
1463 // if in tournement mode, change the wins / losses
1464 if ( g_gametype.integer == GT_TOURNAMENT ) {
1465 AdjustTournamentScores();
1466 }
1467
1468 level.intermissiontime = level.time;
1469 // move all clients to the intermission point
1470 for (i=0 ; i< level.maxclients ; i++) {
1471 client = g_entities + i;
1472 if (!client->inuse)
1473 continue;
1474 // respawn if dead
1475 if (client->health <= 0) {
1476 ClientRespawn(client);
1477 }
1478 MoveClientToIntermission( client );
1479 }
1480 #ifdef MISSIONPACK
1481 if (g_singlePlayer.integer) {
1482 trap_Cvar_Set("ui_singlePlayerActive", "0");
1483 UpdateTournamentInfo();
1484 }
1485 #else
1486 // if single player game
1487 if ( g_gametype.integer == GT_SINGLE_PLAYER ) {
1488 UpdateTournamentInfo();
1489 SpawnModelsOnVictoryPads();
1490 }
1491 #endif
1492 // send the current scoring to all clients
1493 SendScoreboardMessageToAllClients();
1494
1495 }
1496
1497
1498 /*
1499 =============
1500 ExitLevel
1501
1502 When the intermission has been exited, the server is either killed
1503 or moved to a new level based on the "nextmap" cvar
1504
1505 =============
1506 */
1507 void ExitLevel (void) {
1508 int i;
1509 gclient_t *cl;
1510 char nextmap[MAX_STRING_CHARS];
1511 char d1[MAX_STRING_CHARS];
1512 char serverinfo[MAX_INFO_STRING];
1513
1514 //bot interbreeding
1515 BotInterbreedEndMatch();
1516
1517 // if we are running a tournement map, kick the loser to spectator status,
1518 // which will automatically grab the next spectator and restart
1519 if ( g_gametype.integer == GT_TOURNAMENT ) {
1520 if ( !level.restarted ) {
1521 RemoveTournamentLoser();
1522 trap_SendConsoleCommand( EXEC_APPEND, "map_restart 0\n" );
1523 level.restarted = qtrue;
1524 level.changemap = NULL;
1525 level.intermissiontime = 0;
1526 }
1527 return;
1528 }
1529
1530 trap_Cvar_VariableStringBuffer( "nextmap", nextmap, sizeof(nextmap) );
1531 trap_Cvar_VariableStringBuffer( "d1", d1, sizeof(d1) );
1532
1533 trap_GetServerinfo( serverinfo, sizeof( serverinfo ) );
1534
1535 //Here the game finds the nextmap if g_autonextmap is set
1536 if(g_autonextmap.integer ) {
1537 char filename[MAX_FILEPATH];
1538 fileHandle_t file,mapfile;
1539 //Look in g_mappools.string for the file to look for maps in
1540 Q_strncpyz(filename,Info_ValueForKey(g_mappools.string, va("%i",g_gametype.integer)),MAX_FILEPATH);
1541 //If we found a filename:
1542 if(filename[0]) {
1543 //Read the file:
1544 /*int len =*/ trap_FS_FOpenFile(filename, &file, FS_READ);
1545 if(!file)
1546 trap_FS_FOpenFile(va("%s.org",filename), &file, FS_READ);
1547 if(file) {
1548 char buffer[4*1024]; // buffer to read file into
1549 char mapnames[1024][20]; // Array of mapnames in the map pool
1550 char *pointer;
1551 int choice, count=0; //The random choice from mapnames and count of mapnames
1552 int i;
1553 memset(&buffer,0,sizeof(buffer));
1554 trap_FS_Read(&buffer,sizeof(buffer),file);
1555 pointer = buffer;
1556 while ( qtrue ) {
1557 Q_strncpyz(mapnames[count],COM_Parse( &pointer ),20);
1558 if ( !mapnames[count][0] ) {
1559 break;
1560 }
1561 G_Printf("Mapname in mappool: %s\n",mapnames[count]);
1562 count++;
1563 }
1564 trap_FS_FCloseFile(file);
1565 //It is possible that the maps in the file read are flawed, so we try up to ten times:
1566 for(i=0;i<10;i++) {
1567 choice = (count > 0)? rand()%count : 0;
1568 if(Q_strequal(mapnames[choice],Info_ValueForKey(serverinfo,"mapname")))
1569 continue;
1570 //Now check that the map exists:
1571 trap_FS_FOpenFile(va("maps/%s.bsp",mapnames[choice]),&mapfile,FS_READ);
1572 if(mapfile) {
1573 G_Printf("Picked map number %i - %s\n",choice,mapnames[choice]);
1574 Q_strncpyz(nextmap,va("map %s",mapnames[choice]),sizeof(nextmap));
1575 trap_Cvar_Set("nextmap",nextmap);
1576 trap_FS_FCloseFile(mapfile);
1577 break;
1578 }
1579 }
1580 }
1581 }
1582 }
1583
1584 if( !Q_stricmp( nextmap, "map_restart 0" ) && Q_stricmp( d1, "" ) ) {
1585 trap_Cvar_Set( "nextmap", "vstr d2" );
1586 trap_SendConsoleCommand( EXEC_APPEND, "vstr d1\n" );
1587 } else {
1588 trap_SendConsoleCommand( EXEC_APPEND, "vstr nextmap\n" );
1589 }
1590
1591 level.changemap = NULL;
1592 level.intermissiontime = 0;
1593
1594 // reset all the scores so we don't enter the intermission again
1595 level.teamScores[TEAM_RED] = 0;
1596 level.teamScores[TEAM_BLUE] = 0;
1597 for ( i=0 ; i< g_maxclients.integer ; i++ ) {
1598 cl = level.clients + i;
1599 if ( cl->pers.connected != CON_CONNECTED ) {
1600 continue;
1601 }
1602 cl->ps.persistant[PERS_SCORE] = 0;
1603 }
1604
1605 // we need to do this here before chaning to CON_CONNECTING
1606 G_WriteSessionData();
1607
1608 // change all client states to connecting, so the early players into the
1609 // next level will know the others aren't done reconnecting
1610 for (i=0 ; i< g_maxclients.integer ; i++) {
1611 if ( level.clients[i].pers.connected == CON_CONNECTED ) {
1612 level.clients[i].pers.connected = CON_CONNECTING;
1613 }
1614 }
1615
1616 }
1617
1618 /*
1619 =================
1620 G_LogPrintf
1621
1622 Print to the logfile with a time stamp if it is open
1623 =================
1624 */
1625 void QDECL G_LogPrintf( const char *fmt, ... ) {
1626 va_list argptr;
1627 char string[1024];
1628 int min, tens, sec;
1629
1630 sec = level.time / 1000;
1631
1632 min = sec / 60;
1633 sec -= min * 60;
1634 tens = sec / 10;
1635 sec -= tens * 10;
1636
1637 Com_sprintf( string, sizeof(string), "%3i:%i%i ", min, tens, sec );
1638
1639 va_start( argptr, fmt );
1640 Q_vsnprintf(string + 7, sizeof(string) - 7, fmt, argptr);
1641 va_end( argptr );
1642
1643 if ( g_dedicated.integer ) {
1644 G_Printf( "%s", string + 7 );
1645 }
1646
1647 if ( !level.logFile ) {
1648 return;
1649 }
1650
1651 trap_FS_Write( string, strlen( string ), level.logFile );
1652 }
1653
1654 /*
1655 ================
1656 LogExit
1657
1658 Append information about this game to the log file
1659 ================
1660 */
1661 void LogExit( const char *string ) {
1662 int i, numSorted;
1663 gclient_t *cl;
1664 #ifdef MISSIONPACK
1665 qboolean won = qtrue;
1666 #endif
1667 G_LogPrintf( "Exit: %s\n", string );
1668
1669 level.intermissionQueued = level.time;
1670
1671 // this will keep the clients from playing any voice sounds
1672 // that will get cut off when the queued intermission starts
1673 trap_SetConfigstring( CS_INTERMISSION, "1" );
1674
1675 // don't send more than 32 scores (FIXME?)
1676 numSorted = level.numConnectedClients;
1677 if ( numSorted > 32 ) {
1678 numSorted = 32;
1679 }
1680
1681 if ( g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) {
1682 G_LogPrintf( "red:%i blue:%i\n",
1683 level.teamScores[TEAM_RED], level.teamScores[TEAM_BLUE] );
1684 }
1685
1686 for (i=0 ; i < numSorted ; i++) {
1687 int ping;
1688
1689 cl = &level.clients[level.sortedClients[i]];
1690
1691 if ( cl->sess.sessionTeam == TEAM_SPECTATOR ) {
1692 continue;
1693 }
1694 if ( cl->pers.connected == CON_CONNECTING ) {
1695 continue;
1696 }
1697
1698 ping = cl->ps.ping < 999 ? cl->ps.ping : 999;
1699
1700 G_LogPrintf( "score: %i ping: %i client: %i %s\n", cl->ps.persistant[PERS_SCORE], ping, level.sortedClients[i], cl->pers.netname );
1701 #ifdef MISSIONPACK
1702 if (g_singlePlayer.integer && g_gametype.integer == GT_TOURNAMENT) {
1703 if (g_entities[cl - level.clients].r.svFlags & SVF_BOT && cl->ps.persistant[PERS_RANK] == 0) {
1704 won = qfalse;
1705 }
1706 }
1707 #endif
1708
1709 }
1710
1711 #ifdef MISSIONPACK
1712 if (g_singlePlayer.integer) {
1713 if (g_gametype.integer >= GT_CTF && g_ffa_gt==0) {
1714 won = level.teamScores[TEAM_RED] > level.teamScores[TEAM_BLUE];
1715 }
1716 trap_SendConsoleCommand( EXEC_APPEND, (won) ? "spWin\n" : "spLose\n" );
1717 }
1718 #endif
1719
1720
1721 }
1722
1723
1724 /*
1725 =================
1726 CheckIntermissionExit
1727
1728 The level will stay at the intermission for a minimum of 5 seconds
1729 If all players wish to continue, the level will then exit.
1730 If one or more players have not acknowledged the continue, the game will
1731 wait 10 seconds before going on.
1732 =================
1733 */
1734 void CheckIntermissionExit( void ) {
1735 int ready, notReady, playerCount;
1736 int i;
1737 gclient_t *cl;
1738 int readyMask;
1739
1740 if ( g_gametype.integer == GT_SINGLE_PLAYER ) {
1741 return;
1742 }
1743
1744 // see which players are ready
1745 ready = 0;
1746 notReady = 0;
1747 readyMask = 0;
1748 playerCount = 0;
1749 for (i=0 ; i< g_maxclients.integer ; i++) {
1750 cl = level.clients + i;
1751 if ( cl->pers.connected != CON_CONNECTED ) {
1752 continue;
1753 }
1754 if ( g_entities[cl->ps.clientNum].r.svFlags & SVF_BOT ) {
1755 continue;
1756 }
1757
1758 playerCount++;
1759 if ( cl->readyToExit ) {
1760 ready++;
1761 if ( i < 16 ) {
1762 readyMask |= 1 << i;
1763 }
1764 } else {
1765 notReady++;
1766 }
1767 }
1768
1769 // copy the readyMask to each player's stats so
1770 // it can be displayed on the scoreboard
1771 for (i=0 ; i< g_maxclients.integer ; i++) {
1772 cl = level.clients + i;
1773 if ( cl->pers.connected != CON_CONNECTED ) {
1774 continue;
1775 }
1776 cl->ps.stats[STAT_CLIENTS_READY] = readyMask;
1777 }
1778
1779 // never exit in less than five seconds
1780 if ( level.time < level.intermissiontime + 5000 ) {
1781 return;
1782 }
1783
1784 // only test ready status when there are real players present
1785 if ( playerCount > 0 ) {
1786 // if nobody wants to go, clear timer
1787 if ( !ready ) {
1788 level.readyToExit = qfalse;
1789 return;
1790 }
1791
1792 // if everyone wants to go, go now
1793 if ( !notReady ) {
1794 ExitLevel();
1795 return;
1796 }
1797 }
1798
1799 // the first person to ready starts the ten second timeout
1800 if ( !level.readyToExit ) {
1801 level.readyToExit = qtrue;
1802 level.exitTime = level.time;
1803 }
1804
1805 // if we have waited ten seconds since at least one player
1806 // wanted to exit, go ahead
1807 if ( level.time < level.exitTime + 10000 ) {
1808 return;
1809 }
1810
1811 ExitLevel();
1812 }
1813
1814 /*
1815 =============
1816 ScoreIsTied
1817 =============
1818 */
1819 qboolean ScoreIsTied( void ) {
1820 int a, b;
1821
1822 if ( level.numPlayingClients < 2 ) {
1823 return qfalse;
1824 }
1825
1826 //Sago: In Elimination and Oneway Flag Capture teams must win by two points.
1827 if ( g_gametype.integer == GT_ELIMINATION ||
1828 (g_gametype.integer == GT_CTF_ELIMINATION && g_elimination_ctf_oneway.integer)) {
1829 return (level.teamScores[TEAM_RED] == level.teamScores[TEAM_BLUE] ||
1830 level.teamScores[TEAM_RED] == level.teamScores[TEAM_BLUE]+1 ||
1831 level.teamScores[TEAM_RED] == level.teamScores[TEAM_BLUE]-1);
1832 }
1833
1834 if ( g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) {
1835 return level.teamScores[TEAM_RED] == level.teamScores[TEAM_BLUE];
1836 }
1837
1838 a = level.clients[level.sortedClients[0]].ps.persistant[PERS_SCORE];
1839 b = level.clients[level.sortedClients[1]].ps.persistant[PERS_SCORE];
1840
1841 return a == b;
1842 }
1843
1844 /*
1845 =================
1846 CheckExitRules
1847
1848 There will be a delay between the time the exit is qualified for
1849 and the time everyone is moved to the intermission spot, so you
1850 can see the last frag.
1851 =================
1852 */
1853 void CheckExitRules( void ) {
1854 int i;
1855 gclient_t *cl;
1856 // if at the intermission, wait for all non-bots to
1857 // signal ready, then go to next level
1858 if ( level.intermissiontime ) {
1859 CheckIntermissionExit ();
1860 return;
1861 } else {
1862 //sago: Find the reason for this to be neccesary.
1863 for (i=0 ; i< g_maxclients.integer ; i++) {
1864 cl = level.clients + i;
1865 if ( cl->pers.connected != CON_CONNECTED ) {
1866 continue;
1867 }
1868 cl->ps.stats[STAT_CLIENTS_READY] = 0;
1869 }
1870 }
1871
1872 if ( level.intermissionQueued ) {
1873 #ifdef MISSIONPACK
1874 int time = (g_singlePlayer.integer) ? SP_INTERMISSION_DELAY_TIME : INTERMISSION_DELAY_TIME;
1875 if ( level.time - level.intermissionQueued >= time ) {
1876 level.intermissionQueued = 0;
1877 BeginIntermission();
1878 }
1879 #else
1880 if ( level.time - level.intermissionQueued >= INTERMISSION_DELAY_TIME ) {
1881 level.intermissionQueued = 0;
1882 BeginIntermission();
1883 }
1884 #endif
1885 return;
1886 }
1887
1888 // check for sudden death
1889 if ( ScoreIsTied() ) {
1890 // always wait for sudden death
1891 return;
1892 }
1893
1894 if ( g_timelimit.integer > 0 && !level.warmupTime ) {
1895 if ( (level.time - level.startTime)/60000 >= g_timelimit.integer ) {
1896 trap_SendServerCommand( -1, "print \"Timelimit hit.\n\"");
1897 LogExit( "Timelimit hit." );
1898 return;
1899 }
1900 }
1901
1902 if ( level.numPlayingClients < 2 ) {
1903 return;
1904 }
1905
1906 if ( (g_gametype.integer < GT_CTF || g_ffa_gt>0 ) && g_fraglimit.integer ) {
1907 if ( level.teamScores[TEAM_RED] >= g_fraglimit.integer ) {
1908 trap_SendServerCommand( -1, "print \"Red hit the fraglimit.\n\"" );
1909 LogExit( "Fraglimit hit." );
1910 return;
1911 }
1912
1913 if ( level.teamScores[TEAM_BLUE] >= g_fraglimit.integer ) {
1914 trap_SendServerCommand( -1, "print \"Blue hit the fraglimit.\n\"" );
1915 LogExit( "Fraglimit hit." );
1916 return;
1917 }
1918
1919 for ( i=0 ; i< g_maxclients.integer ; i++ ) {
1920 cl = level.clients + i;
1921 if ( cl->pers.connected != CON_CONNECTED ) {
1922 continue;
1923 }
1924 if ( cl->sess.sessionTeam != TEAM_FREE ) {
1925 continue;
1926 }
1927
1928 if ( cl->ps.persistant[PERS_SCORE] >= g_fraglimit.integer ) {
1929 LogExit( "Fraglimit hit." );
1930 trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " hit the fraglimit.\n\"",
1931 cl->pers.netname ) );
1932 return;
1933 }
1934 }
1935 }
1936
1937 if ( (g_gametype.integer >= GT_CTF && g_ffa_gt<1) && g_capturelimit.integer ) {
1938
1939 if ( level.teamScores[TEAM_RED] >= g_capturelimit.integer ) {
1940 trap_SendServerCommand( -1, "print \"Red hit the capturelimit.\n\"" );
1941 LogExit( "Capturelimit hit." );
1942 return;
1943 }
1944
1945 if ( level.teamScores[TEAM_BLUE] >= g_capturelimit.integer ) {
1946 trap_SendServerCommand( -1, "print \"Blue hit the capturelimit.\n\"" );
1947 LogExit( "Capturelimit hit." );
1948 return;
1949 }
1950 }
1951 }
1952
1953 //LMS - Last man Stading functions:
1954 void StartLMSRound(void) {
1955 int countsLiving;
1956 countsLiving = TeamLivingCount( -1, TEAM_FREE );
1957 if(countsLiving<2) {
1958 trap_SendServerCommand( -1, "print \"Not enough players to start the round\n\"");
1959 level.roundNumberStarted = level.roundNumber-1;
1960 level.roundStartTime = level.time+1000*g_elimination_warmup.integer;
1961 return;
1962 }
1963
1964 //If we are enough to start a round:
1965 level.roundNumberStarted = level.roundNumber; //Set numbers
1966
1967 G_LogPrintf( "LMS: %i %i %i: Round %i has started!\n", level.roundNumber, -1, 0, level.roundNumber );
1968
1969 SendEliminationMessageToAllClients();
1970 EnableWeapons();
1971 }
1972
1973 //the elimination start function
1974 void StartEliminationRound(void) {
1975
1976 int countsLiving[TEAM_NUM_TEAMS];
1977 countsLiving[TEAM_BLUE] = TeamLivingCount( -1, TEAM_BLUE );
1978 countsLiving[TEAM_RED] = TeamLivingCount( -1, TEAM_RED );
1979 if((countsLiving[TEAM_BLUE]==0) || (countsLiving[TEAM_RED]==0))
1980 {
1981 trap_SendServerCommand( -1, "print \"Not enough players to start the round\n\"");
1982 level.roundNumberStarted = level.roundNumber-1;
1983 level.roundRespawned = qfalse;
1984 //Remember that one of the teams is empty!
1985 level.roundRedPlayers = countsLiving[TEAM_RED];
1986 level.roundBluePlayers = countsLiving[TEAM_BLUE];
1987 level.roundStartTime = level.time+1000*g_elimination_warmup.integer;
1988 return;
1989 }
1990
1991 //If we are enough to start a round:
1992 level.roundNumberStarted = level.roundNumber; //Set numbers
1993 level.roundRedPlayers = countsLiving[TEAM_RED];
1994 level.roundBluePlayers = countsLiving[TEAM_BLUE];
1995 if(g_gametype.integer == GT_CTF_ELIMINATION) {
1996 Team_ReturnFlag( TEAM_RED );
1997 Team_ReturnFlag( TEAM_BLUE );
1998 }
1999 if(g_gametype.integer == GT_ELIMINATION) {
2000 G_LogPrintf( "ELIMINATION: %i %i %i: Round %i has started!\n", level.roundNumber, -1, 0, level.roundNumber );
2001 } else if(g_gametype.integer == GT_CTF_ELIMINATION) {
2002 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: Round %i has started!\n", level.roundNumber, -1, -1, 4, level.roundNumber );
2003 }
2004 SendEliminationMessageToAllClients();
2005 if(g_elimination_ctf_oneway.integer)
2006 SendAttackingTeamMessageToAllClients(); //Ensure that evaryone know who should attack.
2007 EnableWeapons();
2008 }
2009
2010 //things to do at end of round:
2011 void EndEliminationRound(void)
2012 {
2013 DisableWeapons();
2014 level.roundNumber++;
2015 level.roundStartTime = level.time+1000*g_elimination_warmup.integer;
2016 SendEliminationMessageToAllClients();
2017 CalculateRanks();
2018 level.roundRespawned = qfalse;
2019 if(g_elimination_ctf_oneway.integer)
2020 SendAttackingTeamMessageToAllClients();
2021 }
2022
2023 //Things to do if we don't want to move the roundNumber
2024 void RestartEliminationRound(void) {
2025 DisableWeapons();
2026 level.roundNumberStarted = level.roundNumber-1;
2027 level.roundStartTime = level.time+1000*g_elimination_warmup.integer;
2028 if(!level.intermissiontime)
2029 SendEliminationMessageToAllClients();
2030 level.roundRespawned = qfalse;
2031 if(g_elimination_ctf_oneway.integer)
2032 SendAttackingTeamMessageToAllClients();
2033 }
2034
2035 //Things to do during match warmup
2036 void WarmupEliminationRound(void) {
2037 EnableWeapons();
2038 level.roundNumberStarted = level.roundNumber-1;
2039 level.roundStartTime = level.time+1000*g_elimination_warmup.integer;
2040 SendEliminationMessageToAllClients();
2041 level.roundRespawned = qfalse;
2042 if(g_elimination_ctf_oneway.integer)
2043 SendAttackingTeamMessageToAllClients();
2044 }
2045
2046 /*
2047 ========================================================================
2048
2049 FUNCTIONS CALLED EVERY FRAME
2050
2051 ========================================================================
2052 */
2053
2054 /*
2055 CheckDoubleDomination
2056 */
2057
2058 void CheckDoubleDomination( void ) {
2059 if ( level.numPlayingClients < 1 ) {
2060 return;
2061 }
2062
2063 if ( level.warmupTime != 0) {
2064 if( ((level.pointStatusA == TEAM_BLUE && level.pointStatusB == TEAM_BLUE) ||
2065 (level.pointStatusA == TEAM_RED && level.pointStatusB == TEAM_RED)) &&
2066 level.timeTaken + 10*1000 <= level.time ) {
2067 Team_RemoveDoubleDominationPoints();
2068 level.roundStartTime = level.time + 10*1000;
2069 SendScoreboardMessageToAllClients();
2070 }
2071 return;
2072 }
2073
2074 if(g_gametype.integer != GT_DOUBLE_D)
2075 return;
2076
2077 //Don't score if we are in intermission. Both points might have been taken when we went into intermission
2078 if(level.intermissiontime)
2079 return;
2080
2081 if(level.pointStatusA == TEAM_RED && level.pointStatusB == TEAM_RED && level.timeTaken + 10*1000 <= level.time) {
2082 //Red scores
2083 trap_SendServerCommand( -1, "print \"Red team scores!\n\"");
2084 AddTeamScore(level.intermission_origin,TEAM_RED,1);
2085 G_LogPrintf( "DD: %i %i %i: %s scores!\n", -1, TEAM_RED, 2, TeamName(TEAM_RED) );
2086 Team_ForceGesture(TEAM_RED);
2087 Team_DD_bonusAtPoints(TEAM_RED);
2088 Team_RemoveDoubleDominationPoints();
2089 //We start again in 10 seconds:
2090 level.roundStartTime = level.time + 10*1000;
2091 SendScoreboardMessageToAllClients();
2092 CalculateRanks();
2093 }
2094
2095 if(level.pointStatusA == TEAM_BLUE && level.pointStatusB == TEAM_BLUE && level.timeTaken + 10*1000 <= level.time) {
2096 //Blue scores
2097 trap_SendServerCommand( -1, "print \"Blue team scores!\n\"");
2098 AddTeamScore(level.intermission_origin,TEAM_BLUE,1);
2099 G_LogPrintf( "DD: %i %i %i: %s scores!\n", -1, TEAM_BLUE, 2, TeamName(TEAM_BLUE) );
2100 Team_ForceGesture(TEAM_BLUE);
2101 Team_DD_bonusAtPoints(TEAM_BLUE);
2102 Team_RemoveDoubleDominationPoints();
2103 //We start again in 10 seconds:
2104 level.roundStartTime = level.time + 10*1000;
2105 SendScoreboardMessageToAllClients();
2106 CalculateRanks();
2107 }
2108
2109 if((level.pointStatusA == TEAM_NONE || level.pointStatusB == TEAM_NONE) && level.time>level.roundStartTime) {
2110 trap_SendServerCommand( -1, "print \"A new round has started\n\"");
2111 Team_SpawnDoubleDominationPoints();
2112 SendScoreboardMessageToAllClients();
2113 }
2114 }
2115
2116 /*
2117 CheckLMS
2118 */
2119
2120 void CheckLMS(void) {
2121 int mode;
2122 mode = g_lms_mode.integer;
2123 if ( level.numPlayingClients < 1 ) {
2124 return;
2125 }
2126
2127
2128
2129 //We don't want to do anything in intermission
2130 if(level.intermissiontime) {
2131 if(level.roundRespawned) {
2132 RestartEliminationRound();
2133 }
2134 level.roundStartTime = level.time; //so that a player might join at any time to fix the bots+no humans+autojoin bug
2135 return;
2136 }
2137
2138 if(g_gametype.integer == GT_LMS)
2139 {
2140 int countsLiving[TEAM_NUM_TEAMS];
2141 //trap_SendServerCommand( -1, "print \"This is LMS!\n\"");
2142 countsLiving[TEAM_FREE] = TeamLivingCount( -1, TEAM_FREE );
2143 if(countsLiving[TEAM_FREE]==1 && level.roundNumber==level.roundNumberStarted)
2144 {
2145 if(mode <=1 )
2146 LMSpoint();
2147 trap_SendServerCommand( -1, "print \"We have a winner!\n\"");
2148 EndEliminationRound();
2149 Team_ForceGesture(TEAM_FREE);
2150 }
2151
2152 if(countsLiving[TEAM_FREE]==0 && level.roundNumber==level.roundNumberStarted)
2153 {
2154 trap_SendServerCommand( -1, "print \"All death... how sad\n\"");
2155 EndEliminationRound();
2156 }
2157
2158 if((g_elimination_roundtime.integer) && (level.roundNumber==level.roundNumberStarted)&&(g_lms_mode.integer == 1 || g_lms_mode.integer==3)&&(level.time>=level.roundStartTime+1000*g_elimination_roundtime.integer))
2159 {
2160 trap_SendServerCommand( -1, "print \"Time up - Overtime disabled\n\"");
2161 if(mode <=1 )
2162 LMSpoint();
2163 EndEliminationRound();
2164 }
2165
2166 //This might be better placed another place:
2167 if(g_elimination_activewarmup.integer<2)
2168 g_elimination_activewarmup.integer=2; //We need at least 2 seconds to spawn all players
2169 if(g_elimination_activewarmup.integer >= g_elimination_warmup.integer) //This must not be true
2170 g_elimination_warmup.integer = g_elimination_activewarmup.integer+1; //Increase warmup
2171
2172 //Force respawn
2173 if(level.roundNumber != level.roundNumberStarted && level.time>level.roundStartTime-1000*g_elimination_activewarmup.integer && !level.roundRespawned)
2174 {
2175 level.roundRespawned = qtrue;
2176 RespawnAll();
2177 DisableWeapons();
2178 SendEliminationMessageToAllClients();
2179 }
2180
2181 if(level.time<=level.roundStartTime && level.time>level.roundStartTime-1000*g_elimination_activewarmup.integer)
2182 {
2183 RespawnDead();
2184 //DisableWeapons();
2185 }
2186
2187 if(level.roundNumber == level.roundNumberStarted)
2188 {
2189 EnableWeapons();
2190 }
2191
2192 if((level.roundNumber>level.roundNumberStarted)&&(level.time>=level.roundStartTime))
2193 StartLMSRound();
2194
2195 if(level.time+1000*g_elimination_warmup.integer-500>level.roundStartTime && level.numPlayingClients < 2)
2196 {
2197 RespawnDead(); //Allow player to run around anyway
2198 WarmupEliminationRound(); //Start over
2199 return;
2200 }
2201
2202 if(level.warmupTime != 0) {
2203 if(level.time+1000*g_elimination_warmup.integer-500>level.roundStartTime)
2204 {
2205 RespawnDead();
2206 WarmupEliminationRound();
2207 }
2208 }
2209
2210 }
2211 }
2212
2213 /*
2214 =============
2215 CheckElimination
2216 =============
2217 */
2218 void CheckElimination(void) {
2219 if ( level.numPlayingClients < 1 ) {
2220 if( (g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION) &&
2221 ( level.time+1000*g_elimination_warmup.integer-500>level.roundStartTime ))
2222 RestartEliminationRound(); //For spectators
2223 return;
2224 }
2225
2226 //We don't want to do anything in itnermission
2227 if(level.intermissiontime) {
2228 if(level.roundRespawned)
2229 RestartEliminationRound();
2230 level.roundStartTime = level.time+1000*g_elimination_warmup.integer;
2231 return;
2232 }
2233
2234 if(g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION)
2235 {
2236 int counts[TEAM_NUM_TEAMS];
2237 int countsLiving[TEAM_NUM_TEAMS];
2238 int countsHealth[TEAM_NUM_TEAMS];
2239 counts[TEAM_BLUE] = TeamCount( -1, TEAM_BLUE );
2240 counts[TEAM_RED] = TeamCount( -1, TEAM_RED );
2241
2242 countsLiving[TEAM_BLUE] = TeamLivingCount( -1, TEAM_BLUE );
2243 countsLiving[TEAM_RED] = TeamLivingCount( -1, TEAM_RED );
2244
2245 countsHealth[TEAM_BLUE] = TeamHealthCount( -1, TEAM_BLUE );
2246 countsHealth[TEAM_RED] = TeamHealthCount( -1, TEAM_RED );
2247
2248 if(level.roundBluePlayers != 0 && level.roundRedPlayers != 0) { //Cannot score if one of the team never got any living players
2249 if((countsLiving[TEAM_BLUE]==0)&&(level.roundNumber==level.roundNumberStarted))
2250 {
2251 //Blue team has been eliminated!
2252 trap_SendServerCommand( -1, "print \"Blue Team eliminated!\n\"");
2253 AddTeamScore(level.intermission_origin,TEAM_RED,1);
2254 if(g_gametype.integer == GT_ELIMINATION) {
2255 G_LogPrintf( "ELIMINATION: %i %i %i: %s wins round %i by eleminating the enemy team!\n", level.roundNumber, TEAM_RED, 1, TeamName(TEAM_RED), level.roundNumber );
2256 } else {
2257 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s wins round %i by eleminating the enemy team!\n", level.roundNumber, -1, TEAM_RED, 6, TeamName(TEAM_RED), level.roundNumber );
2258 }
2259 EndEliminationRound();
2260 Team_ForceGesture(TEAM_RED);
2261 }
2262 else if((countsLiving[TEAM_RED]==0)&&(level.roundNumber==level.roundNumberStarted))
2263 {
2264 //Red team eliminated!
2265 trap_SendServerCommand( -1, "print \"Red Team eliminated!\n\"");
2266 AddTeamScore(level.intermission_origin,TEAM_BLUE,1);
2267 if(g_gametype.integer == GT_ELIMINATION) {
2268 G_LogPrintf( "ELIMINATION: %i %i %i: %s wins round %i by eleminating the enemy team!\n", level.roundNumber, TEAM_BLUE, 1, TeamName(TEAM_BLUE), level.roundNumber );
2269 } else {
2270 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s wins round %i by eleminating the enemy team!\n", level.roundNumber, -1, TEAM_BLUE, 6, TeamName(TEAM_BLUE), level.roundNumber );
2271 }
2272 EndEliminationRound();
2273 Team_ForceGesture(TEAM_BLUE);
2274 }
2275 }
2276
2277 //Time up
2278 if((level.roundNumber==level.roundNumberStarted)&&(g_elimination_roundtime.integer)&&(level.time>=level.roundStartTime+1000*g_elimination_roundtime.integer))
2279 {
2280 trap_SendServerCommand( -1, "print \"No teams eliminated.\n\"");
2281
2282 if(level.roundBluePlayers != 0 && level.roundRedPlayers != 0) {//We don't want to divide by zero. (should not be possible)
2283 if(g_gametype.integer == GT_CTF_ELIMINATION && g_elimination_ctf_oneway.integer) {
2284 //One way CTF, make defensice team the winner.
2285 if ( (level.eliminationSides+level.roundNumber)%2 == 0 ) { //Red was attacking
2286 trap_SendServerCommand( -1, "print \"Blue team defended the base\n\"");
2287 AddTeamScore(level.intermission_origin,TEAM_BLUE,1);
2288 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s wins round %i by defending the flag!\n", level.roundNumber, -1, TEAM_BLUE, 5, TeamName(TEAM_BLUE), level.roundNumber );
2289 }
2290 else {
2291 trap_SendServerCommand( -1, "print \"Red team defended the base\n\"");
2292 AddTeamScore(level.intermission_origin,TEAM_RED,1);
2293 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s wins round %i by defending the flag!\n", level.roundNumber, -1, TEAM_RED, 5, TeamName(TEAM_RED), level.roundNumber );
2294 }
2295 }
2296 else if(((double)countsLiving[TEAM_RED])/((double)level.roundRedPlayers)>((double)countsLiving[TEAM_BLUE])/((double)level.roundBluePlayers))
2297 {
2298 //Red team has higher procentage survivors
2299 trap_SendServerCommand( -1, "print \"Red team has most survivers!\n\"");
2300 AddTeamScore(level.intermission_origin,TEAM_RED,1);
2301 if(g_gametype.integer == GT_ELIMINATION) {
2302 G_LogPrintf( "ELIMINATION: %i %i %i: %s wins round %i due to more survivors!\n", level.roundNumber, TEAM_RED, 2, TeamName(TEAM_RED), level.roundNumber );
2303 } else {
2304 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s wins round %i due to more survivors!\n", level.roundNumber, -1, TEAM_RED, 7, TeamName(TEAM_RED), level.roundNumber );
2305 }
2306 }
2307 else if(((double)countsLiving[TEAM_RED])/((double)level.roundRedPlayers)<((double)countsLiving[TEAM_BLUE])/((double)level.roundBluePlayers))
2308 {
2309 //Blue team has higher procentage survivors
2310 trap_SendServerCommand( -1, "print \"Blue team has most survivers!\n\"");
2311 AddTeamScore(level.intermission_origin,TEAM_BLUE,1);
2312 if(g_gametype.integer == GT_ELIMINATION) {
2313 G_LogPrintf( "ELIMINATION: %i %i %i: %s wins round %i due to more survivors!\n", level.roundNumber, TEAM_BLUE, 2, TeamName(TEAM_BLUE), level.roundNumber );
2314 } else {
2315 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s wins round %i due to more survivors!\n", level.roundNumber, -1, TEAM_BLUE, 7, TeamName(TEAM_BLUE), level.roundNumber );
2316 }
2317 }
2318 else if(countsHealth[TEAM_RED]>countsHealth[TEAM_BLUE])
2319 {
2320 //Red team has more health
2321 trap_SendServerCommand( -1, "print \"Red team has more health left!\n\"");
2322 AddTeamScore(level.intermission_origin,TEAM_RED,1);
2323 if(g_gametype.integer == GT_ELIMINATION) {
2324 G_LogPrintf( "ELIMINATION: %i %i %i: %s wins round %i due to more health left!\n", level.roundNumber, TEAM_RED, 3, TeamName(TEAM_RED), level.roundNumber );
2325 } else {
2326 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s wins round %i due to more health left!\n", level.roundNumber, -1, TEAM_RED, 8, TeamName(TEAM_RED), level.roundNumber );
2327 }
2328 }
2329 else if(countsHealth[TEAM_RED]<countsHealth[TEAM_BLUE])
2330 {
2331 //Blue team has more health
2332 trap_SendServerCommand( -1, "print \"Blue team has more health left!\n\"");
2333 AddTeamScore(level.intermission_origin,TEAM_BLUE,1);
2334 if(g_gametype.integer == GT_ELIMINATION) {
2335 G_LogPrintf( "ELIMINATION: %i %i %i: %s wins round %i due to more health left!\n", level.roundNumber, TEAM_BLUE, 3, TeamName(TEAM_BLUE), level.roundNumber );
2336 } else {
2337 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s wins round %i due to more health left!\n", level.roundNumber, -1, TEAM_BLUE, 8, TeamName(TEAM_BLUE), level.roundNumber );
2338 }
2339 }
2340 }
2341 //Draw
2342 if(g_gametype.integer == GT_ELIMINATION) {
2343 G_LogPrintf( "ELIMINATION: %i %i %i: Round %i ended in a draw!\n", level.roundNumber, -1, 4, level.roundNumber );
2344 } else {
2345 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: Round %i ended in a draw!\n", level.roundNumber, -1, -1, 9, level.roundNumber );
2346 }
2347 EndEliminationRound();
2348 }
2349
2350 //This might be better placed another place:
2351 if(g_elimination_activewarmup.integer<1)
2352 g_elimination_activewarmup.integer=1; //We need at least 1 second to spawn all players
2353 if(g_elimination_activewarmup.integer >= g_elimination_warmup.integer) //This must not be true
2354 g_elimination_warmup.integer = g_elimination_activewarmup.integer+1; //Increase warmup
2355
2356 //Force respawn
2357 if(level.roundNumber!=level.roundNumberStarted && level.time>level.roundStartTime-1000*g_elimination_activewarmup.integer && !level.roundRespawned)
2358 {
2359 level.roundRespawned = qtrue;
2360 RespawnAll();
2361 SendEliminationMessageToAllClients();
2362 }
2363
2364 if(level.time<=level.roundStartTime && level.time>level.roundStartTime-1000*g_elimination_activewarmup.integer)
2365 {
2366 RespawnDead();
2367 }
2368
2369
2370 if((level.roundNumber>level.roundNumberStarted)&&(level.time>=level.roundStartTime))
2371 StartEliminationRound();
2372
2373 if(level.time+1000*g_elimination_warmup.integer-500>level.roundStartTime)
2374 if(counts[TEAM_BLUE]<1 || counts[TEAM_RED]<1)
2375 {
2376 RespawnDead(); //Allow players to run around anyway
2377 WarmupEliminationRound(); //Start over
2378 return;
2379 }
2380
2381 if(level.warmupTime != 0) {
2382 if(level.time+1000*g_elimination_warmup.integer-500>level.roundStartTime)
2383 {
2384 RespawnDead();
2385 WarmupEliminationRound();
2386 }
2387 }
2388 }
2389 }
2390
2391 /*
2392 =============
2393 CheckDomination
2394 =============
2395 */
2396 void CheckDomination(void) {
2397 int i;
2398 int scoreFactor = 1;
2399
2400 if ( (level.numPlayingClients < 1) || (g_gametype.integer != GT_DOMINATION) ) {
2401 return;
2402 }
2403
2404 //Do nothing if warmup
2405 if(level.warmupTime != 0)
2406 return;
2407
2408 //Don't score if we are in intermission. Just plain stupid
2409 if(level.intermissiontime)
2410 return;
2411
2412 //Sago: I use if instead of while, since if the server stops for more than 2 seconds people should not be allowed to score anyway
2413 if(level.domination_points_count>3)
2414 scoreFactor = 2; //score more slowly if there are many points
2415 if(level.time>=level.dom_scoreGiven*DOM_SECSPERPOINT*scoreFactor) {
2416 for(i=0;i<level.domination_points_count;i++) {
2417 if ( level.pointStatusDom[i] == TEAM_RED )
2418 AddTeamScore(level.intermission_origin,TEAM_RED,1);
2419 if ( level.pointStatusDom[i] == TEAM_BLUE )
2420 AddTeamScore(level.intermission_origin,TEAM_BLUE,1);
2421 G_LogPrintf( "DOM: %i %i %i %i: %s holds point %s for 1 point!\n",
2422 -1,i,1,level.pointStatusDom[i],
2423 TeamName(level.pointStatusDom[i]),level.domination_points_names[i]);
2424 }
2425 level.dom_scoreGiven++;
2426 while(level.time>level.dom_scoreGiven*DOM_SECSPERPOINT*scoreFactor)
2427 level.dom_scoreGiven++;
2428 CalculateRanks();
2429 }
2430 }
2431
2432 /*
2433 =============
2434 CheckTournament
2435
2436 Once a frame, check for changes in tournement player state
2437 =============
2438 */
2439 void CheckTournament( void ) {
2440 // check because we run 3 game frames before calling Connect and/or ClientBegin
2441 // for clients on a map_restart
2442 if ( level.numPlayingClients == 0 ) {
2443 return;
2444 }
2445
2446 if ( g_gametype.integer == GT_TOURNAMENT ) {
2447
2448 // pull in a spectator if needed
2449 if ( level.numPlayingClients < 2 ) {
2450 AddTournamentPlayer();
2451 }
2452
2453 // if we don't have two players, go back to "waiting for players"
2454 if ( level.numPlayingClients != 2 ) {
2455 if ( level.warmupTime != -1 ) {
2456 level.warmupTime = -1;
2457 trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) );
2458 G_LogPrintf( "Warmup:\n" );
2459 }
2460 return;
2461 }
2462
2463 if ( level.warmupTime == 0 ) {
2464 return;
2465 }
2466
2467 // if the warmup is changed at the console, restart it
2468 if ( g_warmup.modificationCount != level.warmupModificationCount ) {
2469 level.warmupModificationCount = g_warmup.modificationCount;
2470 level.warmupTime = -1;
2471 }
2472
2473 // if all players have arrived, start the countdown
2474 if ( level.warmupTime < 0 ) {
2475 if ( level.numPlayingClients == 2 ) {
2476 // fudge by -1 to account for extra delays
2477 if ( g_warmup.integer > 1 ) {
2478 level.warmupTime = level.time + ( g_warmup.integer - 1 ) * 1000;
2479 } else {
2480 level.warmupTime = 0;
2481 }
2482
2483 trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) );
2484 }
2485 return;
2486 }
2487
2488 // if the warmup time has counted down, restart
2489 if ( level.time > level.warmupTime ) {
2490 level.warmupTime += 10000;
2491 trap_Cvar_Set( "g_restarted", "1" );
2492 trap_SendConsoleCommand( EXEC_APPEND, "map_restart 0\n" );
2493 level.restarted = qtrue;
2494 return;
2495 }
2496 } else if ( g_gametype.integer != GT_SINGLE_PLAYER && level.warmupTime != 0 ) {
2497 int counts[TEAM_NUM_TEAMS];
2498 qboolean notEnough = qfalse;
2499
2500 if ( g_gametype.integer > GT_TEAM && !g_ffa_gt ) {
2501 counts[TEAM_BLUE] = TeamCount( -1, TEAM_BLUE );
2502 counts[TEAM_RED] = TeamCount( -1, TEAM_RED );
2503
2504 if (counts[TEAM_RED] < 1 || counts[TEAM_BLUE] < 1) {
2505 notEnough = qtrue;
2506 }
2507 } else if ( level.numPlayingClients < 2 ) {
2508 notEnough = qtrue;
2509 }
2510
2511 if ( notEnough ) {
2512 if ( level.warmupTime != -1 ) {
2513 level.warmupTime = -1;
2514 trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) );
2515 G_LogPrintf( "Warmup:\n" );
2516 }
2517 return; // still waiting for team members
2518 }
2519
2520 if ( level.warmupTime == 0 ) {
2521 return;
2522 }
2523
2524 // if the warmup is changed at the console, restart it
2525 if ( g_warmup.modificationCount != level.warmupModificationCount ) {
2526 level.warmupModificationCount = g_warmup.modificationCount;
2527 level.warmupTime = -1;
2528 }
2529
2530 // if all players have arrived, start the countdown
2531 if ( level.warmupTime < 0 ) {
2532 // fudge by -1 to account for extra delays
2533 level.warmupTime = level.time + ( g_warmup.integer - 1 ) * 1000;
2534 trap_SetConfigstring( CS_WARMUP, va("%i", level.warmupTime) );
2535 return;
2536 }
2537
2538 // if the warmup time has counted down, restart
2539 if ( level.time > level.warmupTime ) {
2540 level.warmupTime += 10000;
2541 trap_Cvar_Set( "g_restarted", "1" );
2542 trap_SendConsoleCommand( EXEC_APPEND, "map_restart 0\n" );
2543 level.restarted = qtrue;
2544 return;
2545 }
2546 }
2547 }
2548
2549
2550
2551
2552 /*
2553 ==================
2554 PrintTeam
2555 ==================
2556 */
2557 void PrintTeam(int team, char *message) {
2558 int i;
2559
2560 for ( i = 0 ; i < level.maxclients ; i++ ) {
2561 if (level.clients[i].sess.sessionTeam != team)
2562 continue;
2563 trap_SendServerCommand( i, message );
2564 }
2565 }
2566
2567 /*
2568 ==================
2569 SetLeader
2570 ==================
2571 */
2572 void SetLeader(int team, int client) {
2573 int i;
2574
2575 if ( level.clients[client].pers.connected == CON_DISCONNECTED ) {
2576 PrintTeam(team, va("print \"%s is not connected\n\"", level.clients[client].pers.netname) );
2577 return;
2578 }
2579 if (level.clients[client].sess.sessionTeam != team) {
2580 PrintTeam(team, va("print \"%s is not on the team anymore\n\"", level.clients[client].pers.netname) );
2581 return;
2582 }
2583 for ( i = 0 ; i < level.maxclients ; i++ ) {
2584 if (level.clients[i].sess.sessionTeam != team)
2585 continue;
2586 if (level.clients[i].sess.teamLeader) {
2587 level.clients[i].sess.teamLeader = qfalse;
2588 ClientUserinfoChanged(i);
2589 }
2590 }
2591 level.clients[client].sess.teamLeader = qtrue;
2592 ClientUserinfoChanged( client );
2593 PrintTeam(team, va("print \"%s is the new team leader\n\"", level.clients[client].pers.netname) );
2594 }
2595
2596 /*
2597 ==================
2598 CheckTeamLeader
2599 ==================
2600 */
2601 void CheckTeamLeader( int team ) {
2602 int i;
2603
2604 for ( i = 0 ; i < level.maxclients ; i++ ) {
2605 if (level.clients[i].sess.sessionTeam != team)
2606 continue;
2607 if (level.clients[i].sess.teamLeader)
2608 break;
2609 }
2610 if (i >= level.maxclients) {
2611 for ( i = 0 ; i < level.maxclients ; i++ ) {
2612 if (level.clients[i].sess.sessionTeam != team)
2613 continue;
2614 if (!(g_entities[i].r.svFlags & SVF_BOT)) {
2615 level.clients[i].sess.teamLeader = qtrue;
2616 break;
2617 }
2618 }
2619 for ( i = 0 ; i < level.maxclients ; i++ ) {
2620 if (level.clients[i].sess.sessionTeam != team)
2621 continue;
2622 level.clients[i].sess.teamLeader = qtrue;
2623 break;
2624 }
2625 }
2626 }
2627
2628 /*
2629 ==================
2630 CheckTeamVote
2631 ==================
2632 */
2633 void CheckTeamVote( int team ) {
2634 int cs_offset;
2635
2636 if ( team == TEAM_RED )
2637 cs_offset = 0;
2638 else if ( team == TEAM_BLUE )
2639 cs_offset = 1;
2640 else
2641 return;
2642
2643 if ( !level.teamVoteTime[cs_offset] ) {
2644 return;
2645 }
2646 if ( level.time - level.teamVoteTime[cs_offset] >= VOTE_TIME ) {
2647 trap_SendServerCommand( -1, "print \"Team vote failed.\n\"" );
2648 } else {
2649 if ( level.teamVoteYes[cs_offset] > level.numteamVotingClients[cs_offset]/2 ) {
2650 // execute the command, then remove the vote
2651 trap_SendServerCommand( -1, "print \"Team vote passed.\n\"" );
2652 //
2653 if ( !Q_strncmp( "leader", level.teamVoteString[cs_offset], 6) ) {
2654 //set the team leader
2655 SetLeader(team, atoi(level.teamVoteString[cs_offset] + 7));
2656 }
2657 else {
2658 trap_SendConsoleCommand( EXEC_APPEND, va("%s\n", level.teamVoteString[cs_offset] ) );
2659 }
2660 } else if ( level.teamVoteNo[cs_offset] >= level.numteamVotingClients[cs_offset]/2 ) {
2661 // same behavior as a timeout
2662 trap_SendServerCommand( -1, "print \"Team vote failed.\n\"" );
2663 } else {
2664 // still waiting for a majority
2665 return;
2666 }
2667 }
2668 level.teamVoteTime[cs_offset] = 0;
2669 trap_SetConfigstring( CS_TEAMVOTE_TIME + cs_offset, "" );
2670
2671 }
2672
2673
2674 /*
2675 ==================
2676 CheckCvars
2677 ==================
2678 */
2679 void CheckCvars( void ) {
2680 static int lastMod = -1;
2681
2682 if ( g_password.modificationCount != lastMod ) {
2683 lastMod = g_password.modificationCount;
2684 if ( *g_password.string && Q_stricmp( g_password.string, "none" ) ) {
2685 trap_Cvar_Set( "g_needpass", "1" );
2686 } else {
2687 trap_Cvar_Set( "g_needpass", "0" );
2688 }
2689 }
2690 }
2691
2692 /*
2693 =============
2694 G_RunThink
2695
2696 Runs thinking code for this frame if necessary
2697 =============
2698 */
2699 void G_RunThink (gentity_t *ent) {
2700 float thinktime;
2701
2702 thinktime = ent->nextthink;
2703 if (thinktime <= 0) {
2704 return;
2705 }
2706 if (thinktime > level.time) {
2707 return;
2708 }
2709
2710 ent->nextthink = 0;
2711 if (!ent->think) {
2712 G_Error ( "NULL ent->think");
2713 }
2714 ent->think (ent);
2715 }
2716
2717 /*
2718 ================
2719 G_RunFrame
2720
2721 Advances the non-player objects in the world
2722 ================
2723 */
2724 void G_RunFrame( int levelTime ) {
2725 int i;
2726 gentity_t *ent;
2727 int msec;
2728 int start, end;
2729
2730 // if we are waiting for the level to restart, do nothing
2731 if ( level.restarted ) {
2732 return;
2733 }
2734
2735 level.framenum++;
2736 level.previousTime = level.time;
2737 level.time = levelTime;
2738 msec = level.time - level.previousTime;
2739
2740 // get any cvar changes
2741 G_UpdateCvars();
2742
2743 if( (g_gametype.integer==GT_ELIMINATION || g_gametype.integer==GT_CTF_ELIMINATION) && !(g_elimflags.integer & EF_NO_FREESPEC) && g_elimination_lockspectator.integer>1)
2744 trap_Cvar_Set("elimflags",va("%i",g_elimflags.integer|EF_NO_FREESPEC));
2745 else
2746 if( (g_elimflags.integer & EF_NO_FREESPEC) && g_elimination_lockspectator.integer<2)
2747 trap_Cvar_Set("elimflags",va("%i",g_elimflags.integer&(~EF_NO_FREESPEC) ) );
2748
2749 if( g_elimination_ctf_oneway.integer && !(g_elimflags.integer & EF_ONEWAY) ) {
2750 trap_Cvar_Set("elimflags",va("%i",g_elimflags.integer|EF_ONEWAY ) );
2751 //If the server admin has enabled it midgame imidiantly braodcast attacking team
2752 SendAttackingTeamMessageToAllClients();
2753 }
2754 else
2755 if( !g_elimination_ctf_oneway.integer && (g_elimflags.integer & EF_ONEWAY) ) {
2756 trap_Cvar_Set("elimflags",va("%i",g_elimflags.integer&(~EF_ONEWAY) ) );
2757 }
2758
2759 //
2760 // go through all allocated objects
2761 //
2762 start = trap_Milliseconds();
2763 ent = &g_entities[0];
2764 for (i=0 ; i<level.num_entities ; i++, ent++) {
2765 if ( !ent->inuse ) {
2766 continue;
2767 }
2768
2769 // clear events that are too old
2770 if ( level.time - ent->eventTime > EVENT_VALID_MSEC ) {
2771 if ( ent->s.event ) {
2772 ent->s.event = 0; // &= EV_EVENT_BITS;
2773 if ( ent->client ) {
2774 ent->client->ps.externalEvent = 0;
2775 // predicted events should never be set to zero
2776 //ent->client->ps.events[0] = 0;
2777 //ent->client->ps.events[1] = 0;
2778 }
2779 }
2780 if ( ent->freeAfterEvent ) {
2781 // tempEntities or dropped items completely go away after their event
2782 G_FreeEntity( ent );
2783 continue;
2784 } else if ( ent->unlinkAfterEvent ) {
2785 // items that will respawn will hide themselves after their pickup event
2786 ent->unlinkAfterEvent = qfalse;
2787 trap_UnlinkEntity( ent );
2788 }
2789 }
2790
2791 // temporary entities don't think
2792 if ( ent->freeAfterEvent ) {
2793 continue;
2794 }
2795
2796 if ( !ent->r.linked && ent->neverFree ) {
2797 continue;
2798 }
2799
2800 //unlagged - backward reconciliation #2
2801 // we'll run missiles separately to save CPU in backward reconciliation
2802 /*
2803 if ( ent->s.eType == ET_MISSILE ) {
2804 G_RunMissile( ent );
2805 continue;
2806 }
2807 */
2808 //unlagged - backward reconciliation #2
2809
2810 if ( ent->s.eType == ET_ITEM || ent->physicsObject ) {
2811 G_RunItem( ent );
2812 continue;
2813 }
2814
2815 if ( ent->s.eType == ET_MOVER ) {
2816 G_RunMover( ent );
2817 continue;
2818 }
2819
2820 if ( i < MAX_CLIENTS ) {
2821 G_RunClient( ent );
2822 continue;
2823 }
2824
2825 G_RunThink( ent );
2826 }
2827
2828 //unlagged - backward reconciliation #2
2829 // NOW run the missiles, with all players backward-reconciled
2830 // to the positions they were in exactly 50ms ago, at the end
2831 // of the last server frame
2832 G_TimeShiftAllClients( level.previousTime, NULL );
2833
2834 ent = &g_entities[0];
2835 for (i=0 ; i<level.num_entities ; i++, ent++) {
2836 if ( !ent->inuse ) {
2837 continue;
2838 }
2839
2840 // temporary entities don't think
2841 if ( ent->freeAfterEvent ) {
2842 continue;
2843 }
2844
2845 if ( ent->s.eType == ET_MISSILE ) {
2846 G_RunMissile( ent );
2847 }
2848 }
2849
2850 G_UnTimeShiftAllClients( NULL );
2851 //unlagged - backward reconciliation #2
2852
2853 end = trap_Milliseconds();
2854
2855 start = trap_Milliseconds();
2856 // perform final fixups on the players
2857 ent = &g_entities[0];
2858 for (i=0 ; i < level.maxclients ; i++, ent++ ) {
2859 if ( ent->inuse ) {
2860 ClientEndFrame( ent );
2861 }
2862 }
2863 end = trap_Milliseconds();
2864
2865 // see if it is time to do a tournement restart
2866 CheckTournament();
2867
2868 //Check Elimination state
2869 CheckElimination();
2870 CheckLMS();
2871
2872 //Check Double Domination
2873 CheckDoubleDomination();
2874
2875 CheckDomination();
2876
2877 //Sago: I just need to think why I placed this here... they should only spawn once
2878 if(g_gametype.integer == GT_DOMINATION)
2879 Team_Dom_SpawnPoints();
2880
2881 // see if it is time to end the level
2882 CheckExitRules();
2883
2884 // update to team status?
2885 CheckTeamStatus();
2886
2887 // cancel vote if timed out
2888 CheckVote();
2889
2890 // check team votes
2891 CheckTeamVote( TEAM_RED );
2892 CheckTeamVote( TEAM_BLUE );
2893
2894 // for tracking changes
2895 CheckCvars();
2896
2897 if (g_listEntity.integer) {
2898 for (i = 0; i < MAX_GENTITIES; i++) {
2899 G_Printf("%4i: %s\n", i, g_entities[i].classname);
2900 }
2901 trap_Cvar_Set("g_listEntity", "0");
2902 }
2903
2904 //unlagged - backward reconciliation #4
2905 // record the time at the end of this frame - it should be about
2906 // the time the next frame begins - when the server starts
2907 // accepting commands from connected clients
2908 level.frameStartTime = trap_Milliseconds();
2909 //unlagged - backward reconciliation #4
2910 }
2911