| 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 |
// cg_servercmds.c -- reliably sequenced text commands sent by the server |
| 24 |
// these are processed at snapshot transition time, so there will definately |
| 25 |
// be a valid snapshot this frame |
| 26 |
|
| 27 |
#include "cg_local.h" |
| 28 |
#include "../../ui/menudef.h" // bk001205 - for Q3_ui as well |
| 29 |
|
| 30 |
typedef struct { |
| 31 |
const char *order; |
| 32 |
int taskNum; |
| 33 |
} orderTask_t; |
| 34 |
|
| 35 |
static const orderTask_t validOrders[] = { |
| 36 |
{ VOICECHAT_GETFLAG, TEAMTASK_OFFENSE }, |
| 37 |
{ VOICECHAT_OFFENSE, TEAMTASK_OFFENSE }, |
| 38 |
{ VOICECHAT_DEFEND, TEAMTASK_DEFENSE }, |
| 39 |
{ VOICECHAT_DEFENDFLAG, TEAMTASK_DEFENSE }, |
| 40 |
{ VOICECHAT_PATROL, TEAMTASK_PATROL }, |
| 41 |
{ VOICECHAT_CAMP, TEAMTASK_CAMP }, |
| 42 |
{ VOICECHAT_FOLLOWME, TEAMTASK_FOLLOW }, |
| 43 |
{ VOICECHAT_RETURNFLAG, TEAMTASK_RETRIEVE }, |
| 44 |
{ VOICECHAT_FOLLOWFLAGCARRIER, TEAMTASK_ESCORT } |
| 45 |
}; |
| 46 |
|
| 47 |
static const int numValidOrders = sizeof(validOrders) / sizeof(orderTask_t); |
| 48 |
|
| 49 |
#ifdef MISSIONPACK // bk001204 |
| 50 |
static int CG_ValidOrder(const char *p) { |
| 51 |
int i; |
| 52 |
for (i = 0; i < numValidOrders; i++) { |
| 53 |
if (Q_stricmp(p, validOrders[i].order) == 0) { |
| 54 |
return validOrders[i].taskNum; |
| 55 |
} |
| 56 |
} |
| 57 |
return -1; |
| 58 |
} |
| 59 |
#endif |
| 60 |
|
| 61 |
/* |
| 62 |
================= |
| 63 |
CG_ParseScores |
| 64 |
|
| 65 |
================= |
| 66 |
*/ |
| 67 |
static void CG_ParseScores( void ) { |
| 68 |
int i, powerups; |
| 69 |
|
| 70 |
cg.numScores = atoi( CG_Argv( 1 ) ); |
| 71 |
if ( cg.numScores > MAX_CLIENTS ) { |
| 72 |
cg.numScores = MAX_CLIENTS; |
| 73 |
} |
| 74 |
|
| 75 |
cg.teamScores[0] = atoi( CG_Argv( 2 ) ); |
| 76 |
cg.teamScores[1] = atoi( CG_Argv( 3 ) ); |
| 77 |
|
| 78 |
cgs.roundStartTime = atoi( CG_Argv( 4 ) ); |
| 79 |
|
| 80 |
//Update thing in lower-right corner |
| 81 |
if(cgs.gametype == GT_ELIMINATION || cgs.gametype == GT_CTF_ELIMINATION) |
| 82 |
{ |
| 83 |
cgs.scores1 = cg.teamScores[0]; |
| 84 |
cgs.scores2 = cg.teamScores[1]; |
| 85 |
} |
| 86 |
|
| 87 |
memset( cg.scores, 0, sizeof( cg.scores ) ); |
| 88 |
|
| 89 |
#define NUM_DATA 15 |
| 90 |
#define FIRST_DATA 4 |
| 91 |
|
| 92 |
for ( i = 0 ; i < cg.numScores ; i++ ) { |
| 93 |
// |
| 94 |
cg.scores[i].client = atoi( CG_Argv( i * NUM_DATA + FIRST_DATA + 1 ) ); |
| 95 |
cg.scores[i].score = atoi( CG_Argv( i * NUM_DATA + FIRST_DATA + 2 ) ); |
| 96 |
cg.scores[i].ping = atoi( CG_Argv( i * NUM_DATA + FIRST_DATA + 3 ) ); |
| 97 |
cg.scores[i].time = atoi( CG_Argv( i * NUM_DATA + FIRST_DATA + 4 ) ); |
| 98 |
cg.scores[i].scoreFlags = atoi( CG_Argv( i * NUM_DATA + FIRST_DATA + 5 ) ); |
| 99 |
powerups = atoi( CG_Argv( i * NUM_DATA + FIRST_DATA + 6 ) ); |
| 100 |
cg.scores[i].accuracy = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 7)); |
| 101 |
cg.scores[i].impressiveCount = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 8)); |
| 102 |
cg.scores[i].excellentCount = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 9)); |
| 103 |
cg.scores[i].guantletCount = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 10)); |
| 104 |
cg.scores[i].defendCount = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 11)); |
| 105 |
cg.scores[i].assistCount = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 12)); |
| 106 |
cg.scores[i].perfect = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 13)); |
| 107 |
cg.scores[i].captures = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 14)); |
| 108 |
cg.scores[i].isDead = atoi(CG_Argv(i * NUM_DATA + FIRST_DATA + 15)); |
| 109 |
//cgs.roundStartTime = |
| 110 |
|
| 111 |
if ( cg.scores[i].client < 0 || cg.scores[i].client >= MAX_CLIENTS ) { |
| 112 |
cg.scores[i].client = 0; |
| 113 |
} |
| 114 |
cgs.clientinfo[ cg.scores[i].client ].score = cg.scores[i].score; |
| 115 |
cgs.clientinfo[ cg.scores[i].client ].powerups = powerups; |
| 116 |
cgs.clientinfo[ cg.scores[i].client ].isDead = cg.scores[i].isDead; |
| 117 |
|
| 118 |
cg.scores[i].team = cgs.clientinfo[cg.scores[i].client].team; |
| 119 |
} |
| 120 |
#ifdef MISSIONPACK |
| 121 |
CG_SetScoreSelection(NULL); |
| 122 |
#endif |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
static void CG_ParseAccuracy( void ) { |
| 127 |
int i; |
| 128 |
|
| 129 |
for ( i = WP_MACHINEGUN ; i < WP_NUM_WEAPONS ; i++ ) { |
| 130 |
cg.accuracys[i-WP_MACHINEGUN][0] = atoi( CG_Argv( (i-WP_MACHINEGUN)*2 + 1 ) ); |
| 131 |
cg.accuracys[i-WP_MACHINEGUN][1] = atoi( CG_Argv( (i-WP_MACHINEGUN)*2 + 2 ) ); |
| 132 |
#if DEBUG |
| 133 |
CG_Printf("W: %i shots: %i Hits: %i\n", i,cg.accuracys[i][0], cg.accuracys[i][1]); |
| 134 |
#endif |
| 135 |
} |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
/* |
| 141 |
================= |
| 142 |
CG_ParseElimination |
| 143 |
|
| 144 |
================= |
| 145 |
*/ |
| 146 |
static void CG_ParseElimination( void ) { |
| 147 |
if(cgs.gametype == GT_ELIMINATION || cgs.gametype == GT_CTF_ELIMINATION) |
| 148 |
{ |
| 149 |
cgs.scores1 = atoi( CG_Argv( 1 ) ); |
| 150 |
cgs.scores2 = atoi( CG_Argv( 2 ) ); |
| 151 |
} |
| 152 |
cgs.roundStartTime = atoi( CG_Argv( 3 ) ); |
| 153 |
} |
| 154 |
|
| 155 |
/* |
| 156 |
================= |
| 157 |
CG_ParseMappage |
| 158 |
Sago: This parses values from the server rather directly. Some checks are performed, but beware if you change it or new |
| 159 |
security holes are found |
| 160 |
================= |
| 161 |
*/ |
| 162 |
static void CG_ParseMappage( void ) { |
| 163 |
char command[1024]; |
| 164 |
const char *temp; |
| 165 |
const char* c; |
| 166 |
int i; |
| 167 |
|
| 168 |
temp = CG_Argv( 1 ); |
| 169 |
for( c = temp; *c; ++c) { |
| 170 |
switch(*c) { |
| 171 |
case '\n': |
| 172 |
case '\r': |
| 173 |
case ';': |
| 174 |
//The server tried something bad! |
| 175 |
return; |
| 176 |
break; |
| 177 |
} |
| 178 |
} |
| 179 |
Q_strncpyz(command,va("ui_mappage %s",temp),1024); |
| 180 |
for(i=2;i<12;i++) { |
| 181 |
temp = CG_Argv( i ); |
| 182 |
for( c = temp; *c; ++c) { |
| 183 |
switch(*c) { |
| 184 |
case '\n': |
| 185 |
case '\r': |
| 186 |
case ';': |
| 187 |
//The server tried something bad! |
| 188 |
return; |
| 189 |
break; |
| 190 |
} |
| 191 |
} |
| 192 |
if(strlen(temp)<1) |
| 193 |
temp = "---"; |
| 194 |
Q_strcat(command,1024,va(" %s ",temp)); |
| 195 |
} |
| 196 |
trap_SendConsoleCommand(command); |
| 197 |
|
| 198 |
} |
| 199 |
|
| 200 |
/* |
| 201 |
================= |
| 202 |
CG_ParseDDtimetaken |
| 203 |
|
| 204 |
================= |
| 205 |
*/ |
| 206 |
static void CG_ParseDDtimetaken( void ) { |
| 207 |
cgs.timetaken = atoi( CG_Argv( 1 ) ); |
| 208 |
} |
| 209 |
|
| 210 |
/* |
| 211 |
================= |
| 212 |
CG_ParseDomPointNames |
| 213 |
================= |
| 214 |
*/ |
| 215 |
|
| 216 |
static void CG_ParseDomPointNames( void ) { |
| 217 |
int i,j; |
| 218 |
cgs.domination_points_count = atoi( CG_Argv( 1 ) ); |
| 219 |
if(cgs.domination_points_count>=MAX_DOMINATION_POINTS) |
| 220 |
cgs.domination_points_count = MAX_DOMINATION_POINTS; |
| 221 |
for(i = 0;i<cgs.domination_points_count;i++) { |
| 222 |
Q_strncpyz(cgs.domination_points_names[i],CG_Argv(2)+i*MAX_DOMINATION_POINTS_NAMES,MAX_DOMINATION_POINTS_NAMES-1); |
| 223 |
for(j=MAX_DOMINATION_POINTS_NAMES-1; cgs.domination_points_names[i][j] < '0' && j>0; j--) { |
| 224 |
cgs.domination_points_names[i][j] = 0; |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
/* |
| 230 |
================= |
| 231 |
CG_ParseDomScores |
| 232 |
================= |
| 233 |
*/ |
| 234 |
|
| 235 |
static void CG_ParseDomStatus( void ) { |
| 236 |
int i; |
| 237 |
if( cgs.domination_points_count!=atoi( CG_Argv(1) ) ) { |
| 238 |
cgs.domination_points_count = 0; |
| 239 |
return; |
| 240 |
} |
| 241 |
for(i = 0;i<cgs.domination_points_count;i++) { |
| 242 |
cgs.domination_points_status[i] = atoi( CG_Argv(2+i) ); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
/* |
| 247 |
================= |
| 248 |
CG_ParseChallenge |
| 249 |
================= |
| 250 |
*/ |
| 251 |
|
| 252 |
static void CG_ParseChallenge( void ) { |
| 253 |
addChallenge(atoi( CG_Argv(1) ) ); |
| 254 |
} |
| 255 |
|
| 256 |
static void CG_ParseObeliskHealth( void ) { |
| 257 |
cg.redObeliskHealth = atoi( CG_Argv(1) ); |
| 258 |
cg.blueObeliskHealth = atoi( CG_Argv(2) ); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Sets the respawn counter for the client. |
| 263 |
*/ |
| 264 |
static void CG_ParseRespawnTime( void ) { |
| 265 |
cg.respawnTime = atoi( CG_Argv(1) ); |
| 266 |
} |
| 267 |
|
| 268 |
/* |
| 269 |
================= |
| 270 |
CG_ParseTeam |
| 271 |
================= |
| 272 |
*/ |
| 273 |
|
| 274 |
static void CG_ParseTeam( void ) { |
| 275 |
//TODO: Add code here |
| 276 |
if(cg_voip_teamonly.integer) |
| 277 |
trap_Cvar_Set("cl_voipSendTarget",CG_Argv(1)); |
| 278 |
} |
| 279 |
|
| 280 |
/* |
| 281 |
================= |
| 282 |
CG_ParseAttackingTeam |
| 283 |
|
| 284 |
================= |
| 285 |
*/ |
| 286 |
static void CG_ParseAttackingTeam( void ) { |
| 287 |
int temp; |
| 288 |
temp = atoi( CG_Argv( 1 ) ); |
| 289 |
if(temp==TEAM_RED) |
| 290 |
cgs.attackingTeam = TEAM_RED; |
| 291 |
else if (temp==TEAM_BLUE) |
| 292 |
cgs.attackingTeam = TEAM_BLUE; |
| 293 |
else |
| 294 |
cgs.attackingTeam = TEAM_NONE; //Should never happen. |
| 295 |
} |
| 296 |
|
| 297 |
/* |
| 298 |
================= |
| 299 |
CG_ParseTeamInfo |
| 300 |
|
| 301 |
================= |
| 302 |
*/ |
| 303 |
static void CG_ParseTeamInfo( void ) { |
| 304 |
int i; |
| 305 |
int client; |
| 306 |
|
| 307 |
numSortedTeamPlayers = atoi( CG_Argv( 1 ) ); |
| 308 |
if( numSortedTeamPlayers < 0 || numSortedTeamPlayers > TEAM_MAXOVERLAY ) |
| 309 |
{ |
| 310 |
CG_Error( "CG_ParseTeamInfo: numSortedTeamPlayers out of range (%d)", |
| 311 |
numSortedTeamPlayers ); |
| 312 |
return; |
| 313 |
} |
| 314 |
|
| 315 |
for ( i = 0 ; i < numSortedTeamPlayers ; i++ ) { |
| 316 |
client = atoi( CG_Argv( i * 6 + 2 ) ); |
| 317 |
if( client < 0 || client >= MAX_CLIENTS ) |
| 318 |
{ |
| 319 |
CG_Error( "CG_ParseTeamInfo: bad client number: %d", client ); |
| 320 |
return; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
sortedTeamPlayers[i] = client; |
| 325 |
|
| 326 |
cgs.clientinfo[ client ].location = atoi( CG_Argv( i * 6 + 3 ) ); |
| 327 |
cgs.clientinfo[ client ].health = atoi( CG_Argv( i * 6 + 4 ) ); |
| 328 |
cgs.clientinfo[ client ].armor = atoi( CG_Argv( i * 6 + 5 ) ); |
| 329 |
cgs.clientinfo[ client ].curWeapon = atoi( CG_Argv( i * 6 + 6 ) ); |
| 330 |
cgs.clientinfo[ client ].powerups = atoi( CG_Argv( i * 6 + 7 ) ); |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
/* |
| 336 |
================ |
| 337 |
CG_ParseServerinfo |
| 338 |
|
| 339 |
This is called explicitly when the gamestate is first received, |
| 340 |
and whenever the server updates any serverinfo flagged cvars |
| 341 |
================ |
| 342 |
*/ |
| 343 |
void CG_ParseServerinfo( void ) { |
| 344 |
const char *info; |
| 345 |
char *mapname; |
| 346 |
|
| 347 |
info = CG_ConfigString( CS_SERVERINFO ); |
| 348 |
cgs.gametype = atoi( Info_ValueForKey( info, "g_gametype" ) ); |
| 349 |
//By default do as normal: |
| 350 |
cgs.ffa_gt = 0; |
| 351 |
//See if ffa gametype |
| 352 |
if(cgs.gametype == GT_LMS) |
| 353 |
cgs.ffa_gt = 1; |
| 354 |
trap_Cvar_Set("g_gametype", va("%i", cgs.gametype)); |
| 355 |
cgs.dmflags = atoi( Info_ValueForKey( info, "dmflags" ) ); |
| 356 |
cgs.videoflags = atoi( Info_ValueForKey( info, "videoflags" ) ); |
| 357 |
cgs.elimflags = atoi( Info_ValueForKey( info, "elimflags" ) ); |
| 358 |
cgs.teamflags = atoi( Info_ValueForKey( info, "teamflags" ) ); |
| 359 |
cgs.fraglimit = atoi( Info_ValueForKey( info, "fraglimit" ) ); |
| 360 |
cgs.capturelimit = atoi( Info_ValueForKey( info, "capturelimit" ) ); |
| 361 |
cgs.timelimit = atoi( Info_ValueForKey( info, "timelimit" ) ); |
| 362 |
cgs.maxclients = atoi( Info_ValueForKey( info, "sv_maxclients" ) ); |
| 363 |
cgs.roundtime = atoi( Info_ValueForKey( info, "elimination_roundtime" ) ); |
| 364 |
cgs.nopickup = atoi( Info_ValueForKey( info, "g_rockets" ) ) + atoi( Info_ValueForKey( info, "g_instantgib" ) ) + atoi( Info_ValueForKey( info, "g_elimination" ) ); |
| 365 |
cgs.lms_mode = atoi( Info_ValueForKey( info, "g_lms_mode" ) ); |
| 366 |
cgs.altExcellent = atoi( Info_ValueForKey( info, "g_altExcellent" ) ); |
| 367 |
mapname = Info_ValueForKey( info, "mapname" ); |
| 368 |
Com_sprintf( cgs.mapname, sizeof( cgs.mapname ), "maps/%s.bsp", mapname ); |
| 369 |
Q_strncpyz( cgs.redTeam, Info_ValueForKey( info, "g_redTeam" ), sizeof(cgs.redTeam) ); |
| 370 |
trap_Cvar_Set("g_redTeam", cgs.redTeam); |
| 371 |
Q_strncpyz( cgs.blueTeam, Info_ValueForKey( info, "g_blueTeam" ), sizeof(cgs.blueTeam) ); |
| 372 |
trap_Cvar_Set("g_blueTeam", cgs.blueTeam); |
| 373 |
|
| 374 |
//unlagged - server options |
| 375 |
// we'll need this for deciding whether or not to predict weapon effects |
| 376 |
cgs.delagHitscan = atoi( Info_ValueForKey( info, "g_delagHitscan" ) ); |
| 377 |
trap_Cvar_Set("g_delagHitscan", va("%i", cgs.delagHitscan)); |
| 378 |
//unlagged - server options |
| 379 |
|
| 380 |
//Copy allowed votes directly to the client: |
| 381 |
trap_Cvar_Set("cg_voteflags",Info_ValueForKey( info, "voteflags" ) ); |
| 382 |
} |
| 383 |
|
| 384 |
/* |
| 385 |
================== |
| 386 |
CG_ParseWarmup |
| 387 |
================== |
| 388 |
*/ |
| 389 |
static void CG_ParseWarmup( void ) { |
| 390 |
const char *info; |
| 391 |
int warmup; |
| 392 |
|
| 393 |
info = CG_ConfigString( CS_WARMUP ); |
| 394 |
|
| 395 |
warmup = atoi( info ); |
| 396 |
cg.warmupCount = -1; |
| 397 |
|
| 398 |
if ( warmup == 0 && cg.warmup ) { |
| 399 |
|
| 400 |
} else if ( warmup > 0 && cg.warmup <= 0 ) { |
| 401 |
#ifdef MISSIONPACK |
| 402 |
if (cgs.gametype >= GT_CTF && cgs.gametype < GT_MAX_GAME_TYPE && !cgs.ffa_gt) { |
| 403 |
trap_S_StartLocalSound( cgs.media.countPrepareTeamSound, CHAN_ANNOUNCER ); |
| 404 |
} else |
| 405 |
#endif |
| 406 |
{ |
| 407 |
trap_S_StartLocalSound( cgs.media.countPrepareSound, CHAN_ANNOUNCER ); |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
cg.warmup = warmup; |
| 412 |
} |
| 413 |
|
| 414 |
/* |
| 415 |
================ |
| 416 |
CG_SetConfigValues |
| 417 |
|
| 418 |
Called on load to set the initial values from configure strings |
| 419 |
================ |
| 420 |
*/ |
| 421 |
void CG_SetConfigValues( void ) { |
| 422 |
const char *s; |
| 423 |
|
| 424 |
cgs.scores1 = atoi( CG_ConfigString( CS_SCORES1 ) ); |
| 425 |
cgs.scores2 = atoi( CG_ConfigString( CS_SCORES2 ) ); |
| 426 |
cgs.levelStartTime = atoi( CG_ConfigString( CS_LEVEL_START_TIME ) ); |
| 427 |
if( cgs.gametype == GT_CTF || cgs.gametype == GT_CTF_ELIMINATION || cgs.gametype == GT_DOUBLE_D) { |
| 428 |
s = CG_ConfigString( CS_FLAGSTATUS ); |
| 429 |
cgs.redflag = s[0] - '0'; |
| 430 |
cgs.blueflag = s[1] - '0'; |
| 431 |
} |
| 432 |
//#ifdef MISSIONPACK |
| 433 |
else if( cgs.gametype == GT_1FCTF ) { |
| 434 |
s = CG_ConfigString( CS_FLAGSTATUS ); |
| 435 |
cgs.flagStatus = s[0] - '0'; |
| 436 |
} |
| 437 |
//#endif |
| 438 |
cg.warmup = atoi( CG_ConfigString( CS_WARMUP ) ); |
| 439 |
} |
| 440 |
|
| 441 |
/* |
| 442 |
===================== |
| 443 |
CG_ShaderStateChanged |
| 444 |
===================== |
| 445 |
*/ |
| 446 |
void CG_ShaderStateChanged(void) { |
| 447 |
char originalShader[MAX_QPATH]; |
| 448 |
char newShader[MAX_QPATH]; |
| 449 |
char timeOffset[16]; |
| 450 |
const char *o; |
| 451 |
char *n,*t; |
| 452 |
|
| 453 |
o = CG_ConfigString( CS_SHADERSTATE ); |
| 454 |
while (o && *o) { |
| 455 |
n = strstr(o, "="); |
| 456 |
if (n && *n) { |
| 457 |
strncpy(originalShader, o, n-o); |
| 458 |
originalShader[n-o] = 0; |
| 459 |
n++; |
| 460 |
t = strstr(n, ":"); |
| 461 |
if (t && *t) { |
| 462 |
strncpy(newShader, n, t-n); |
| 463 |
newShader[t-n] = 0; |
| 464 |
} else { |
| 465 |
break; |
| 466 |
} |
| 467 |
t++; |
| 468 |
o = strstr(t, "@"); |
| 469 |
if (o) { |
| 470 |
strncpy(timeOffset, t, o-t); |
| 471 |
timeOffset[o-t] = 0; |
| 472 |
o++; |
| 473 |
trap_R_RemapShader( originalShader, newShader, timeOffset ); |
| 474 |
} |
| 475 |
} else { |
| 476 |
break; |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
/* |
| 482 |
================ |
| 483 |
CG_ConfigStringModified |
| 484 |
|
| 485 |
================ |
| 486 |
*/ |
| 487 |
static void CG_ConfigStringModified( void ) { |
| 488 |
const char *str; |
| 489 |
int num; |
| 490 |
|
| 491 |
num = atoi( CG_Argv( 1 ) ); |
| 492 |
|
| 493 |
// get the gamestate from the client system, which will have the |
| 494 |
// new configstring already integrated |
| 495 |
trap_GetGameState( &cgs.gameState ); |
| 496 |
|
| 497 |
// look up the individual string that was modified |
| 498 |
str = CG_ConfigString( num ); |
| 499 |
|
| 500 |
// do something with it if necessary |
| 501 |
if ( num == CS_MUSIC ) { |
| 502 |
CG_StartMusic(); |
| 503 |
} else if ( num == CS_SERVERINFO ) { |
| 504 |
CG_ParseServerinfo(); |
| 505 |
} else if ( num == CS_WARMUP ) { |
| 506 |
CG_ParseWarmup(); |
| 507 |
} else if ( num == CS_SCORES1 ) { |
| 508 |
cgs.scores1 = atoi( str ); |
| 509 |
} else if ( num == CS_SCORES2 ) { |
| 510 |
cgs.scores2 = atoi( str ); |
| 511 |
} else if ( num == CS_LEVEL_START_TIME ) { |
| 512 |
cgs.levelStartTime = atoi( str ); |
| 513 |
} else if ( num == CS_VOTE_TIME ) { |
| 514 |
cgs.voteTime = atoi( str ); |
| 515 |
cgs.voteModified = qtrue; |
| 516 |
} else if ( num == CS_VOTE_YES ) { |
| 517 |
cgs.voteYes = atoi( str ); |
| 518 |
cgs.voteModified = qtrue; |
| 519 |
} else if ( num == CS_VOTE_NO ) { |
| 520 |
cgs.voteNo = atoi( str ); |
| 521 |
cgs.voteModified = qtrue; |
| 522 |
} else if ( num == CS_VOTE_STRING ) { |
| 523 |
Q_strncpyz( cgs.voteString, str, sizeof( cgs.voteString ) ); |
| 524 |
#ifdef MISSIONPACK |
| 525 |
trap_S_StartLocalSound( cgs.media.voteNow, CHAN_ANNOUNCER ); |
| 526 |
#endif //MISSIONPACK |
| 527 |
} else if ( num >= CS_TEAMVOTE_TIME && num <= CS_TEAMVOTE_TIME + 1) { |
| 528 |
cgs.teamVoteTime[num-CS_TEAMVOTE_TIME] = atoi( str ); |
| 529 |
cgs.teamVoteModified[num-CS_TEAMVOTE_TIME] = qtrue; |
| 530 |
} else if ( num >= CS_TEAMVOTE_YES && num <= CS_TEAMVOTE_YES + 1) { |
| 531 |
cgs.teamVoteYes[num-CS_TEAMVOTE_YES] = atoi( str ); |
| 532 |
cgs.teamVoteModified[num-CS_TEAMVOTE_YES] = qtrue; |
| 533 |
} else if ( num >= CS_TEAMVOTE_NO && num <= CS_TEAMVOTE_NO + 1) { |
| 534 |
cgs.teamVoteNo[num-CS_TEAMVOTE_NO] = atoi( str ); |
| 535 |
cgs.teamVoteModified[num-CS_TEAMVOTE_NO] = qtrue; |
| 536 |
} else if ( num >= CS_TEAMVOTE_STRING && num <= CS_TEAMVOTE_STRING + 1) { |
| 537 |
Q_strncpyz( cgs.teamVoteString[num-CS_TEAMVOTE_STRING], str, sizeof( cgs.teamVoteString ) ); |
| 538 |
#ifdef MISSIONPACK |
| 539 |
trap_S_StartLocalSound( cgs.media.voteNow, CHAN_ANNOUNCER ); |
| 540 |
#endif |
| 541 |
} else if ( num == CS_INTERMISSION ) { |
| 542 |
cg.intermissionStarted = atoi( str ); |
| 543 |
} else if ( num >= CS_MODELS && num < CS_MODELS+MAX_MODELS ) { |
| 544 |
cgs.gameModels[ num-CS_MODELS ] = trap_R_RegisterModel( str ); |
| 545 |
} else if ( num >= CS_SOUNDS && num < CS_SOUNDS+MAX_SOUNDS ) { |
| 546 |
if ( str[0] != '*' ) { // player specific sounds don't register here |
| 547 |
cgs.gameSounds[ num-CS_SOUNDS] = trap_S_RegisterSound( str, qfalse ); |
| 548 |
} |
| 549 |
} else if ( num >= CS_PLAYERS && num < CS_PLAYERS+MAX_CLIENTS ) { |
| 550 |
CG_NewClientInfo( num - CS_PLAYERS ); |
| 551 |
CG_BuildSpectatorString(); |
| 552 |
} else if ( num == CS_FLAGSTATUS ) { |
| 553 |
if( cgs.gametype == GT_CTF || cgs.gametype == GT_CTF_ELIMINATION || cgs.gametype == GT_DOUBLE_D) { |
| 554 |
// format is rb where its red/blue, 0 is at base, 1 is taken, 2 is dropped |
| 555 |
cgs.redflag = str[0] - '0'; |
| 556 |
cgs.blueflag = str[1] - '0'; |
| 557 |
} |
| 558 |
//#ifdef MISSIONPACK |
| 559 |
else if( cgs.gametype == GT_1FCTF ) { |
| 560 |
cgs.flagStatus = str[0] - '0'; |
| 561 |
} |
| 562 |
//#endif |
| 563 |
} |
| 564 |
else if ( num == CS_SHADERSTATE ) { |
| 565 |
CG_ShaderStateChanged(); |
| 566 |
} |
| 567 |
|
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
/* |
| 572 |
======================= |
| 573 |
CG_AddToTeamChat |
| 574 |
|
| 575 |
======================= |
| 576 |
*/ |
| 577 |
static void CG_AddToTeamChat( const char *str ) { |
| 578 |
int len; |
| 579 |
char *p, *ls; |
| 580 |
int lastcolor; |
| 581 |
int chatHeight; |
| 582 |
|
| 583 |
if (cg_teamChatHeight.integer < TEAMCHAT_HEIGHT) { |
| 584 |
chatHeight = cg_teamChatHeight.integer; |
| 585 |
} else { |
| 586 |
chatHeight = TEAMCHAT_HEIGHT; |
| 587 |
} |
| 588 |
|
| 589 |
if (chatHeight <= 0 || cg_teamChatTime.integer <= 0) { |
| 590 |
// team chat disabled, dump into normal chat |
| 591 |
cgs.teamChatPos = cgs.teamLastChatPos = 0; |
| 592 |
return; |
| 593 |
} |
| 594 |
|
| 595 |
len = 0; |
| 596 |
|
| 597 |
p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight]; |
| 598 |
*p = 0; |
| 599 |
|
| 600 |
lastcolor = '7'; |
| 601 |
|
| 602 |
ls = NULL; |
| 603 |
while (*str) { |
| 604 |
if (len > TEAMCHAT_WIDTH - 1) { |
| 605 |
if (ls) { |
| 606 |
str -= (p - ls); |
| 607 |
str++; |
| 608 |
p -= (p - ls); |
| 609 |
} |
| 610 |
*p = 0; |
| 611 |
|
| 612 |
cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time; |
| 613 |
|
| 614 |
cgs.teamChatPos++; |
| 615 |
p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight]; |
| 616 |
*p = 0; |
| 617 |
*p++ = Q_COLOR_ESCAPE; |
| 618 |
*p++ = lastcolor; |
| 619 |
len = 0; |
| 620 |
ls = NULL; |
| 621 |
} |
| 622 |
|
| 623 |
if ( Q_IsColorString( str ) ) { |
| 624 |
*p++ = *str++; |
| 625 |
lastcolor = *str; |
| 626 |
*p++ = *str++; |
| 627 |
continue; |
| 628 |
} |
| 629 |
if (*str == ' ') { |
| 630 |
ls = p; |
| 631 |
} |
| 632 |
*p++ = *str++; |
| 633 |
len++; |
| 634 |
} |
| 635 |
*p = 0; |
| 636 |
|
| 637 |
cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time; |
| 638 |
cgs.teamChatPos++; |
| 639 |
|
| 640 |
if (cgs.teamChatPos - cgs.teamLastChatPos > chatHeight) |
| 641 |
cgs.teamLastChatPos = cgs.teamChatPos - chatHeight; |
| 642 |
} |
| 643 |
|
| 644 |
/* |
| 645 |
=============== |
| 646 |
CG_MapRestart |
| 647 |
|
| 648 |
The server has issued a map_restart, so the next snapshot |
| 649 |
is completely new and should not be interpolated to. |
| 650 |
|
| 651 |
A tournement restart will clear everything, but doesn't |
| 652 |
require a reload of all the media |
| 653 |
=============== |
| 654 |
*/ |
| 655 |
static void CG_MapRestart( void ) { |
| 656 |
if ( cg_showmiss.integer ) { |
| 657 |
CG_Printf( "CG_MapRestart\n" ); |
| 658 |
} |
| 659 |
|
| 660 |
CG_InitLocalEntities(); |
| 661 |
CG_InitMarkPolys(); |
| 662 |
CG_ClearParticles (); |
| 663 |
|
| 664 |
// make sure the "3 frags left" warnings play again |
| 665 |
cg.fraglimitWarnings = 0; |
| 666 |
|
| 667 |
cg.timelimitWarnings = 0; |
| 668 |
|
| 669 |
cg.intermissionStarted = qfalse; |
| 670 |
|
| 671 |
cgs.voteTime = 0; |
| 672 |
|
| 673 |
cg.mapRestart = qtrue; |
| 674 |
|
| 675 |
CG_StartMusic(); |
| 676 |
|
| 677 |
trap_S_ClearLoopingSounds(qtrue); |
| 678 |
|
| 679 |
// we really should clear more parts of cg here and stop sounds |
| 680 |
|
| 681 |
// play the "fight" sound if this is a restart without warmup |
| 682 |
if ( cg.warmup == 0 /* && cgs.gametype == GT_TOURNAMENT */) { |
| 683 |
trap_S_StartLocalSound( cgs.media.countFightSound, CHAN_ANNOUNCER ); |
| 684 |
CG_CenterPrint( "FIGHT!", 120, GIANTCHAR_WIDTH*2 ); |
| 685 |
} |
| 686 |
#ifdef MISSIONPACK |
| 687 |
if (cg_singlePlayerActive.integer) { |
| 688 |
trap_Cvar_Set("ui_matchStartTime", va("%i", cg.time)); |
| 689 |
if (cg_recordSPDemo.integer && cg_recordSPDemoName.string && *cg_recordSPDemoName.string) { |
| 690 |
trap_SendConsoleCommand(va("set g_synchronousclients 1 ; record %s \n", cg_recordSPDemoName.string)); |
| 691 |
} |
| 692 |
} |
| 693 |
#endif |
| 694 |
trap_Cvar_Set("cg_thirdPerson", "0"); |
| 695 |
} |
| 696 |
|
| 697 |
#define MAX_VOICEFILESIZE 16384 |
| 698 |
#define MAX_VOICEFILES 8 |
| 699 |
#define MAX_VOICECHATS 64 |
| 700 |
#define MAX_VOICESOUNDS 64 |
| 701 |
#define MAX_CHATSIZE 64 |
| 702 |
#define MAX_HEADMODELS 64 |
| 703 |
|
| 704 |
typedef struct voiceChat_s |
| 705 |
{ |
| 706 |
char id[64]; |
| 707 |
int numSounds; |
| 708 |
sfxHandle_t sounds[MAX_VOICESOUNDS]; |
| 709 |
char chats[MAX_VOICESOUNDS][MAX_CHATSIZE]; |
| 710 |
} voiceChat_t; |
| 711 |
|
| 712 |
typedef struct voiceChatList_s |
| 713 |
{ |
| 714 |
char name[64]; |
| 715 |
int gender; |
| 716 |
int numVoiceChats; |
| 717 |
voiceChat_t voiceChats[MAX_VOICECHATS]; |
| 718 |
} voiceChatList_t; |
| 719 |
|
| 720 |
typedef struct headModelVoiceChat_s |
| 721 |
{ |
| 722 |
char headmodel[64]; |
| 723 |
int voiceChatNum; |
| 724 |
} headModelVoiceChat_t; |
| 725 |
|
| 726 |
voiceChatList_t voiceChatLists[MAX_VOICEFILES]; |
| 727 |
headModelVoiceChat_t headModelVoiceChat[MAX_HEADMODELS]; |
| 728 |
|
| 729 |
/* |
| 730 |
================= |
| 731 |
CG_ParseVoiceChats |
| 732 |
================= |
| 733 |
*/ |
| 734 |
int CG_ParseVoiceChats( const char *filename, voiceChatList_t *voiceChatList, int maxVoiceChats ) { |
| 735 |
int len, i; |
| 736 |
fileHandle_t f; |
| 737 |
char buf[MAX_VOICEFILESIZE]; |
| 738 |
char **p, *ptr; |
| 739 |
char *token; |
| 740 |
voiceChat_t *voiceChats; |
| 741 |
qboolean compress; |
| 742 |
sfxHandle_t sound; |
| 743 |
|
| 744 |
compress = qtrue; |
| 745 |
if (cg_buildScript.integer) { |
| 746 |
compress = qfalse; |
| 747 |
} |
| 748 |
|
| 749 |
len = trap_FS_FOpenFile( filename, &f, FS_READ ); |
| 750 |
if ( !f ) { |
| 751 |
trap_Print( va( S_COLOR_RED "voice chat file not found: %s\n", filename ) ); |
| 752 |
return qfalse; |
| 753 |
} |
| 754 |
if ( len >= MAX_VOICEFILESIZE ) { |
| 755 |
trap_Print( va( S_COLOR_RED "voice chat file too large: %s is %i, max allowed is %i\n", filename, len, MAX_VOICEFILESIZE ) ); |
| 756 |
trap_FS_FCloseFile( f ); |
| 757 |
return qfalse; |
| 758 |
} |
| 759 |
|
| 760 |
trap_FS_Read( buf, len, f ); |
| 761 |
buf[len] = 0; |
| 762 |
trap_FS_FCloseFile( f ); |
| 763 |
|
| 764 |
ptr = buf; |
| 765 |
p = &ptr; |
| 766 |
|
| 767 |
Com_sprintf(voiceChatList->name, sizeof(voiceChatList->name), "%s", filename); |
| 768 |
voiceChats = voiceChatList->voiceChats; |
| 769 |
for ( i = 0; i < maxVoiceChats; i++ ) { |
| 770 |
voiceChats[i].id[0] = 0; |
| 771 |
} |
| 772 |
token = COM_ParseExt(p, qtrue); |
| 773 |
if (!token || token[0] == 0) { |
| 774 |
return qtrue; |
| 775 |
} |
| 776 |
if (!Q_stricmp(token, "female")) { |
| 777 |
voiceChatList->gender = GENDER_FEMALE; |
| 778 |
} |
| 779 |
else if (!Q_stricmp(token, "male")) { |
| 780 |
voiceChatList->gender = GENDER_MALE; |
| 781 |
} |
| 782 |
else if (!Q_stricmp(token, "neuter")) { |
| 783 |
voiceChatList->gender = GENDER_NEUTER; |
| 784 |
} |
| 785 |
else { |
| 786 |
trap_Print( va( S_COLOR_RED "expected gender not found in voice chat file: %s\n", filename ) ); |
| 787 |
return qfalse; |
| 788 |
} |
| 789 |
|
| 790 |
voiceChatList->numVoiceChats = 0; |
| 791 |
while ( 1 ) { |
| 792 |
token = COM_ParseExt(p, qtrue); |
| 793 |
if (!token || token[0] == 0) { |
| 794 |
return qtrue; |
| 795 |
} |
| 796 |
Com_sprintf(voiceChats[voiceChatList->numVoiceChats].id, sizeof( voiceChats[voiceChatList->numVoiceChats].id ), "%s", token); |
| 797 |
token = COM_ParseExt(p, qtrue); |
| 798 |
if (Q_stricmp(token, "{")) { |
| 799 |
trap_Print( va( S_COLOR_RED "expected { found %s in voice chat file: %s\n", token, filename ) ); |
| 800 |
return qfalse; |
| 801 |
} |
| 802 |
voiceChats[voiceChatList->numVoiceChats].numSounds = 0; |
| 803 |
while(1) { |
| 804 |
token = COM_ParseExt(p, qtrue); |
| 805 |
if (!token || token[0] == 0) { |
| 806 |
return qtrue; |
| 807 |
} |
| 808 |
if (!Q_stricmp(token, "}")) |
| 809 |
break; |
| 810 |
sound = trap_S_RegisterSound( token, compress ); |
| 811 |
voiceChats[voiceChatList->numVoiceChats].sounds[voiceChats[voiceChatList->numVoiceChats].numSounds] = sound; |
| 812 |
token = COM_ParseExt(p, qtrue); |
| 813 |
if (!token || token[0] == 0) { |
| 814 |
return qtrue; |
| 815 |
} |
| 816 |
Com_sprintf(voiceChats[voiceChatList->numVoiceChats].chats[ |
| 817 |
voiceChats[voiceChatList->numVoiceChats].numSounds], MAX_CHATSIZE, "%s", token); |
| 818 |
if (sound) |
| 819 |
voiceChats[voiceChatList->numVoiceChats].numSounds++; |
| 820 |
if (voiceChats[voiceChatList->numVoiceChats].numSounds >= MAX_VOICESOUNDS) |
| 821 |
break; |
| 822 |
} |
| 823 |
voiceChatList->numVoiceChats++; |
| 824 |
if (voiceChatList->numVoiceChats >= maxVoiceChats) |
| 825 |
return qtrue; |
| 826 |
} |
| 827 |
return qtrue; |
| 828 |
} |
| 829 |
|
| 830 |
/* |
| 831 |
================= |
| 832 |
CG_LoadVoiceChats |
| 833 |
================= |
| 834 |
*/ |
| 835 |
void CG_LoadVoiceChats( void ) { |
| 836 |
int size; |
| 837 |
|
| 838 |
size = trap_MemoryRemaining(); |
| 839 |
CG_ParseVoiceChats( "scripts/female1.voice", &voiceChatLists[0], MAX_VOICECHATS ); |
| 840 |
CG_ParseVoiceChats( "scripts/female2.voice", &voiceChatLists[1], MAX_VOICECHATS ); |
| 841 |
CG_ParseVoiceChats( "scripts/female3.voice", &voiceChatLists[2], MAX_VOICECHATS ); |
| 842 |
CG_ParseVoiceChats( "scripts/male1.voice", &voiceChatLists[3], MAX_VOICECHATS ); |
| 843 |
CG_ParseVoiceChats( "scripts/male2.voice", &voiceChatLists[4], MAX_VOICECHATS ); |
| 844 |
CG_ParseVoiceChats( "scripts/male3.voice", &voiceChatLists[5], MAX_VOICECHATS ); |
| 845 |
CG_ParseVoiceChats( "scripts/male4.voice", &voiceChatLists[6], MAX_VOICECHATS ); |
| 846 |
CG_ParseVoiceChats( "scripts/male5.voice", &voiceChatLists[7], MAX_VOICECHATS ); |
| 847 |
CG_Printf("voice chat memory size = %d\n", size - trap_MemoryRemaining()); |
| 848 |
} |
| 849 |
|
| 850 |
/* |
| 851 |
================= |
| 852 |
CG_HeadModelVoiceChats |
| 853 |
================= |
| 854 |
*/ |
| 855 |
int CG_HeadModelVoiceChats( char *filename ) { |
| 856 |
int len, i; |
| 857 |
fileHandle_t f; |
| 858 |
char buf[MAX_VOICEFILESIZE]; |
| 859 |
char **p, *ptr; |
| 860 |
char *token; |
| 861 |
|
| 862 |
len = trap_FS_FOpenFile( filename, &f, FS_READ ); |
| 863 |
if ( !f ) { |
| 864 |
//trap_Print( va( "voice chat file not found: %s\n", filename ) ); |
| 865 |
return -1; |
| 866 |
} |
| 867 |
if ( len >= MAX_VOICEFILESIZE ) { |
| 868 |
trap_Print( va( S_COLOR_RED "voice chat file too large: %s is %i, max allowed is %i\n", filename, len, MAX_VOICEFILESIZE ) ); |
| 869 |
trap_FS_FCloseFile( f ); |
| 870 |
return -1; |
| 871 |
} |
| 872 |
|
| 873 |
trap_FS_Read( buf, len, f ); |
| 874 |
buf[len] = 0; |
| 875 |
trap_FS_FCloseFile( f ); |
| 876 |
|
| 877 |
ptr = buf; |
| 878 |
p = &ptr; |
| 879 |
|
| 880 |
token = COM_ParseExt(p, qtrue); |
| 881 |
if (!token || token[0] == 0) { |
| 882 |
return -1; |
| 883 |
} |
| 884 |
|
| 885 |
for ( i = 0; i < MAX_VOICEFILES; i++ ) { |
| 886 |
if ( !Q_stricmp(token, voiceChatLists[i].name) ) { |
| 887 |
return i; |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
//FIXME: maybe try to load the .voice file which name is stored in token? |
| 892 |
|
| 893 |
return -1; |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
/* |
| 898 |
================= |
| 899 |
CG_GetVoiceChat |
| 900 |
================= |
| 901 |
*/ |
| 902 |
int CG_GetVoiceChat( voiceChatList_t *voiceChatList, const char *id, sfxHandle_t *snd, char **chat) { |
| 903 |
int i, rnd; |
| 904 |
|
| 905 |
for ( i = 0; i < voiceChatList->numVoiceChats; i++ ) { |
| 906 |
if ( !Q_stricmp( id, voiceChatList->voiceChats[i].id ) ) { |
| 907 |
rnd = random() * voiceChatList->voiceChats[i].numSounds; |
| 908 |
*snd = voiceChatList->voiceChats[i].sounds[rnd]; |
| 909 |
*chat = voiceChatList->voiceChats[i].chats[rnd]; |
| 910 |
return qtrue; |
| 911 |
} |
| 912 |
} |
| 913 |
return qfalse; |
| 914 |
} |
| 915 |
|
| 916 |
/* |
| 917 |
================= |
| 918 |
CG_VoiceChatListForClient |
| 919 |
================= |
| 920 |
*/ |
| 921 |
voiceChatList_t *CG_VoiceChatListForClient( int clientNum ) { |
| 922 |
clientInfo_t *ci; |
| 923 |
int voiceChatNum, i, j, k, gender; |
| 924 |
char filename[MAX_QPATH], headModelName[MAX_QPATH]; |
| 925 |
|
| 926 |
if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { |
| 927 |
clientNum = 0; |
| 928 |
} |
| 929 |
ci = &cgs.clientinfo[ clientNum ]; |
| 930 |
|
| 931 |
for ( k = 0; k < 2; k++ ) { |
| 932 |
if ( k == 0 ) { |
| 933 |
if (ci->headModelName[0] == '*') { |
| 934 |
Com_sprintf( headModelName, sizeof(headModelName), "%s/%s", ci->headModelName+1, ci->headSkinName ); |
| 935 |
} |
| 936 |
else { |
| 937 |
Com_sprintf( headModelName, sizeof(headModelName), "%s/%s", ci->headModelName, ci->headSkinName ); |
| 938 |
} |
| 939 |
} |
| 940 |
else { |
| 941 |
if (ci->headModelName[0] == '*') { |
| 942 |
Com_sprintf( headModelName, sizeof(headModelName), "%s", ci->headModelName+1 ); |
| 943 |
} |
| 944 |
else { |
| 945 |
Com_sprintf( headModelName, sizeof(headModelName), "%s", ci->headModelName ); |
| 946 |
} |
| 947 |
} |
| 948 |
// find the voice file for the head model the client uses |
| 949 |
for ( i = 0; i < MAX_HEADMODELS; i++ ) { |
| 950 |
if (!Q_stricmp(headModelVoiceChat[i].headmodel, headModelName)) { |
| 951 |
break; |
| 952 |
} |
| 953 |
} |
| 954 |
if (i < MAX_HEADMODELS) { |
| 955 |
return &voiceChatLists[headModelVoiceChat[i].voiceChatNum]; |
| 956 |
} |
| 957 |
// find a <headmodelname>.vc file |
| 958 |
for ( i = 0; i < MAX_HEADMODELS; i++ ) { |
| 959 |
if (!strlen(headModelVoiceChat[i].headmodel)) { |
| 960 |
Com_sprintf(filename, sizeof(filename), "scripts/%s.vc", headModelName); |
| 961 |
voiceChatNum = CG_HeadModelVoiceChats(filename); |
| 962 |
if (voiceChatNum == -1) |
| 963 |
break; |
| 964 |
Com_sprintf(headModelVoiceChat[i].headmodel, sizeof ( headModelVoiceChat[i].headmodel ), |
| 965 |
"%s", headModelName); |
| 966 |
headModelVoiceChat[i].voiceChatNum = voiceChatNum; |
| 967 |
return &voiceChatLists[headModelVoiceChat[i].voiceChatNum]; |
| 968 |
} |
| 969 |
} |
| 970 |
} |
| 971 |
gender = ci->gender; |
| 972 |
for (k = 0; k < 2; k++) { |
| 973 |
// just pick the first with the right gender |
| 974 |
for ( i = 0; i < MAX_VOICEFILES; i++ ) { |
| 975 |
if (strlen(voiceChatLists[i].name)) { |
| 976 |
if (voiceChatLists[i].gender == gender) { |
| 977 |
// store this head model with voice chat for future reference |
| 978 |
for ( j = 0; j < MAX_HEADMODELS; j++ ) { |
| 979 |
if (!strlen(headModelVoiceChat[j].headmodel)) { |
| 980 |
Com_sprintf(headModelVoiceChat[j].headmodel, sizeof ( headModelVoiceChat[j].headmodel ), |
| 981 |
"%s", headModelName); |
| 982 |
headModelVoiceChat[j].voiceChatNum = i; |
| 983 |
break; |
| 984 |
} |
| 985 |
} |
| 986 |
return &voiceChatLists[i]; |
| 987 |
} |
| 988 |
} |
| 989 |
} |
| 990 |
// fall back to male gender because we don't have neuter in the mission pack |
| 991 |
if (gender == GENDER_MALE) |
| 992 |
break; |
| 993 |
gender = GENDER_MALE; |
| 994 |
} |
| 995 |
// store this head model with voice chat for future reference |
| 996 |
for ( j = 0; j < MAX_HEADMODELS; j++ ) { |
| 997 |
if (!strlen(headModelVoiceChat[j].headmodel)) { |
| 998 |
Com_sprintf(headModelVoiceChat[j].headmodel, sizeof ( headModelVoiceChat[j].headmodel ), |
| 999 |
"%s", headModelName); |
| 1000 |
headModelVoiceChat[j].voiceChatNum = 0; |
| 1001 |
break; |
| 1002 |
} |
| 1003 |
} |
| 1004 |
// just return the first voice chat list |
| 1005 |
return &voiceChatLists[0]; |
| 1006 |
} |
| 1007 |
|
| 1008 |
#define MAX_VOICECHATBUFFER 32 |
| 1009 |
|
| 1010 |
typedef struct bufferedVoiceChat_s |
| 1011 |
{ |
| 1012 |
int clientNum; |
| 1013 |
sfxHandle_t snd; |
| 1014 |
int voiceOnly; |
| 1015 |
char cmd[MAX_SAY_TEXT]; |
| 1016 |
char message[MAX_SAY_TEXT]; |
| 1017 |
} bufferedVoiceChat_t; |
| 1018 |
|
| 1019 |
bufferedVoiceChat_t voiceChatBuffer[MAX_VOICECHATBUFFER]; |
| 1020 |
|
| 1021 |
/* |
| 1022 |
================= |
| 1023 |
CG_PlayVoiceChat |
| 1024 |
================= |
| 1025 |
*/ |
| 1026 |
void CG_PlayVoiceChat( bufferedVoiceChat_t *vchat ) { |
| 1027 |
#ifdef MISSIONPACK |
| 1028 |
// if we are going into the intermission, don't start any voices |
| 1029 |
if ( cg.intermissionStarted ) { |
| 1030 |
return; |
| 1031 |
} |
| 1032 |
|
| 1033 |
if ( !cg_noVoiceChats.integer ) { |
| 1034 |
trap_S_StartLocalSound( vchat->snd, CHAN_VOICE); |
| 1035 |
if (vchat->clientNum != cg.snap->ps.clientNum) { |
| 1036 |
int orderTask = CG_ValidOrder(vchat->cmd); |
| 1037 |
if (orderTask > 0) { |
| 1038 |
cgs.acceptOrderTime = cg.time + 5000; |
| 1039 |
Q_strncpyz(cgs.acceptVoice, vchat->cmd, sizeof(cgs.acceptVoice)); |
| 1040 |
cgs.acceptTask = orderTask; |
| 1041 |
cgs.acceptLeader = vchat->clientNum; |
| 1042 |
} |
| 1043 |
// see if this was an order |
| 1044 |
CG_ShowResponseHead(); |
| 1045 |
} |
| 1046 |
} |
| 1047 |
if (!vchat->voiceOnly && !cg_noVoiceText.integer) { |
| 1048 |
CG_AddToTeamChat( vchat->message ); |
| 1049 |
CG_Printf( "%s\n", vchat->message ); |
| 1050 |
} |
| 1051 |
voiceChatBuffer[cg.voiceChatBufferOut].snd = 0; |
| 1052 |
#endif |
| 1053 |
} |
| 1054 |
|
| 1055 |
/* |
| 1056 |
===================== |
| 1057 |
CG_PlayBufferedVoieChats |
| 1058 |
===================== |
| 1059 |
*/ |
| 1060 |
void CG_PlayBufferedVoiceChats( void ) { |
| 1061 |
#ifdef MISSIONPACK |
| 1062 |
if ( cg.voiceChatTime < cg.time ) { |
| 1063 |
if (cg.voiceChatBufferOut != cg.voiceChatBufferIn && voiceChatBuffer[cg.voiceChatBufferOut].snd) { |
| 1064 |
// |
| 1065 |
CG_PlayVoiceChat(&voiceChatBuffer[cg.voiceChatBufferOut]); |
| 1066 |
// |
| 1067 |
cg.voiceChatBufferOut = (cg.voiceChatBufferOut + 1) % MAX_VOICECHATBUFFER; |
| 1068 |
cg.voiceChatTime = cg.time + 1000; |
| 1069 |
} |
| 1070 |
} |
| 1071 |
#endif |
| 1072 |
} |
| 1073 |
|
| 1074 |
/* |
| 1075 |
===================== |
| 1076 |
CG_AddBufferedVoiceChat |
| 1077 |
===================== |
| 1078 |
*/ |
| 1079 |
void CG_AddBufferedVoiceChat( bufferedVoiceChat_t *vchat ) { |
| 1080 |
#ifdef MISSIONPACK |
| 1081 |
// if we are going into the intermission, don't start any voices |
| 1082 |
if ( cg.intermissionStarted ) { |
| 1083 |
return; |
| 1084 |
} |
| 1085 |
|
| 1086 |
memcpy(&voiceChatBuffer[cg.voiceChatBufferIn], vchat, sizeof(bufferedVoiceChat_t)); |
| 1087 |
cg.voiceChatBufferIn = (cg.voiceChatBufferIn + 1) % MAX_VOICECHATBUFFER; |
| 1088 |
if (cg.voiceChatBufferIn == cg.voiceChatBufferOut) { |
| 1089 |
CG_PlayVoiceChat( &voiceChatBuffer[cg.voiceChatBufferOut] ); |
| 1090 |
cg.voiceChatBufferOut++; |
| 1091 |
} |
| 1092 |
#endif |
| 1093 |
} |
| 1094 |
|
| 1095 |
/* |
| 1096 |
================= |
| 1097 |
CG_VoiceChatLocal |
| 1098 |
================= |
| 1099 |
*/ |
| 1100 |
void CG_VoiceChatLocal( int mode, qboolean voiceOnly, int clientNum, int color, const char *cmd ) { |
| 1101 |
#ifdef MISSIONPACK |
| 1102 |
char *chat; |
| 1103 |
voiceChatList_t *voiceChatList; |
| 1104 |
clientInfo_t *ci; |
| 1105 |
sfxHandle_t snd; |
| 1106 |
bufferedVoiceChat_t vchat; |
| 1107 |
|
| 1108 |
// if we are going into the intermission, don't start any voices |
| 1109 |
if ( cg.intermissionStarted ) { |
| 1110 |
return; |
| 1111 |
} |
| 1112 |
|
| 1113 |
if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) { |
| 1114 |
clientNum = 0; |
| 1115 |
} |
| 1116 |
ci = &cgs.clientinfo[ clientNum ]; |
| 1117 |
|
| 1118 |
cgs.currentVoiceClient = clientNum; |
| 1119 |
|
| 1120 |
voiceChatList = CG_VoiceChatListForClient( clientNum ); |
| 1121 |
|
| 1122 |
if ( CG_GetVoiceChat( voiceChatList, cmd, &snd, &chat ) ) { |
| 1123 |
// |
| 1124 |
if ( mode == SAY_TEAM || !cg_teamChatsOnly.integer ) { |
| 1125 |
vchat.clientNum = clientNum; |
| 1126 |
vchat.snd = snd; |
| 1127 |
vchat.voiceOnly = voiceOnly; |
| 1128 |
Q_strncpyz(vchat.cmd, cmd, sizeof(vchat.cmd)); |
| 1129 |
if ( mode == SAY_TELL ) { |
| 1130 |
Com_sprintf(vchat.message, sizeof(vchat.message), "[%s]: %c%c%s", ci->name, Q_COLOR_ESCAPE, color, chat); |
| 1131 |
} |
| 1132 |
else if ( mode == SAY_TEAM ) { |
| 1133 |
Com_sprintf(vchat.message, sizeof(vchat.message), "(%s): %c%c%s", ci->name, Q_COLOR_ESCAPE, color, chat); |
| 1134 |
} |
| 1135 |
else { |
| 1136 |
Com_sprintf(vchat.message, sizeof(vchat.message), "%s: %c%c%s", ci->name, Q_COLOR_ESCAPE, color, chat); |
| 1137 |
} |
| 1138 |
CG_AddBufferedVoiceChat(&vchat); |
| 1139 |
} |
| 1140 |
} |
| 1141 |
#endif |
| 1142 |
} |
| 1143 |
|
| 1144 |
/* |
| 1145 |
================= |
| 1146 |
CG_VoiceChat |
| 1147 |
================= |
| 1148 |
*/ |
| 1149 |
void CG_VoiceChat( int mode ) { |
| 1150 |
#ifdef MISSIONPACK |
| 1151 |
const char *cmd; |
| 1152 |
int clientNum, color; |
| 1153 |
qboolean voiceOnly; |
| 1154 |
|
| 1155 |
voiceOnly = atoi(CG_Argv(1)); |
| 1156 |
clientNum = atoi(CG_Argv(2)); |
| 1157 |
color = atoi(CG_Argv(3)); |
| 1158 |
cmd = CG_Argv(4); |
| 1159 |
|
| 1160 |
if (cg_noTaunt.integer != 0) { |
| 1161 |
if (!strcmp(cmd, VOICECHAT_KILLINSULT) || !strcmp(cmd, VOICECHAT_TAUNT) || \ |
| 1162 |
!strcmp(cmd, VOICECHAT_DEATHINSULT) || !strcmp(cmd, VOICECHAT_KILLGAUNTLET) || \ |
| 1163 |
!strcmp(cmd, VOICECHAT_PRAISE)) { |
| 1164 |
return; |
| 1165 |
} |
| 1166 |
} |
| 1167 |
|
| 1168 |
CG_VoiceChatLocal( mode, voiceOnly, clientNum, color, cmd ); |
| 1169 |
#endif |
| 1170 |
} |
| 1171 |
|
| 1172 |
/* |
| 1173 |
================= |
| 1174 |
CG_RemoveChatEscapeChar |
| 1175 |
================= |
| 1176 |
*/ |
| 1177 |
static void CG_RemoveChatEscapeChar( char *text ) { |
| 1178 |
int i, l; |
| 1179 |
|
| 1180 |
l = 0; |
| 1181 |
for ( i = 0; text[i]; i++ ) { |
| 1182 |
if (text[i] == '\x19') |
| 1183 |
continue; |
| 1184 |
text[l++] = text[i]; |
| 1185 |
} |
| 1186 |
text[l] = '\0'; |
| 1187 |
} |
| 1188 |
|
| 1189 |
/* |
| 1190 |
================= |
| 1191 |
CG_ServerCommand |
| 1192 |
|
| 1193 |
The string has been tokenized and can be retrieved with |
| 1194 |
Cmd_Argc() / Cmd_Argv() |
| 1195 |
================= |
| 1196 |
*/ |
| 1197 |
static void CG_ServerCommand( void ) { |
| 1198 |
const char *cmd; |
| 1199 |
char text[MAX_SAY_TEXT]; |
| 1200 |
|
| 1201 |
cmd = CG_Argv(0); |
| 1202 |
|
| 1203 |
if ( !cmd[0] ) { |
| 1204 |
// server claimed the command |
| 1205 |
return; |
| 1206 |
} |
| 1207 |
|
| 1208 |
if ( !strcmp( cmd, "cp" ) ) { |
| 1209 |
CG_CenterPrint( CG_Argv(1), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH ); |
| 1210 |
return; |
| 1211 |
} |
| 1212 |
|
| 1213 |
if ( !strcmp( cmd, "cs" ) ) { |
| 1214 |
CG_ConfigStringModified(); |
| 1215 |
return; |
| 1216 |
} |
| 1217 |
|
| 1218 |
if ( !strcmp( cmd, "print" ) ) { |
| 1219 |
CG_Printf( "%s", CG_Argv(1) ); |
| 1220 |
#ifdef MISSIONPACK |
| 1221 |
cmd = CG_Argv(1); // yes, this is obviously a hack, but so is the way we hear about |
| 1222 |
// votes passing or failing |
| 1223 |
if ( !Q_stricmpn( cmd, "vote failed", 11 ) || !Q_stricmpn( cmd, "team vote failed", 16 )) { |
| 1224 |
trap_S_StartLocalSound( cgs.media.voteFailed, CHAN_ANNOUNCER ); |
| 1225 |
} else if ( !Q_stricmpn( cmd, "vote passed", 11 ) || !Q_stricmpn( cmd, "team vote passed", 16 ) ) { |
| 1226 |
trap_S_StartLocalSound( cgs.media.votePassed, CHAN_ANNOUNCER ); |
| 1227 |
} |
| 1228 |
#endif |
| 1229 |
return; |
| 1230 |
} |
| 1231 |
|
| 1232 |
if ( !strcmp( cmd, "chat" ) ) { |
| 1233 |
if ( !cg_teamChatsOnly.integer ) { |
| 1234 |
if( cg_chatBeep.integer ) |
| 1235 |
trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); |
| 1236 |
Q_strncpyz( text, CG_Argv(1), MAX_SAY_TEXT ); |
| 1237 |
CG_RemoveChatEscapeChar( text ); |
| 1238 |
CG_Printf( "%s\n", text ); |
| 1239 |
} |
| 1240 |
return; |
| 1241 |
} |
| 1242 |
|
| 1243 |
if ( !strcmp( cmd, "tchat" ) ) { |
| 1244 |
if( cg_teamChatBeep.integer ) |
| 1245 |
trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); |
| 1246 |
Q_strncpyz( text, CG_Argv(1), MAX_SAY_TEXT ); |
| 1247 |
CG_RemoveChatEscapeChar( text ); |
| 1248 |
CG_AddToTeamChat( text ); |
| 1249 |
CG_Printf( "%s\n", text ); |
| 1250 |
return; |
| 1251 |
} |
| 1252 |
if ( !strcmp( cmd, "vchat" ) ) { |
| 1253 |
CG_VoiceChat( SAY_ALL ); |
| 1254 |
return; |
| 1255 |
} |
| 1256 |
|
| 1257 |
if ( !strcmp( cmd, "vtchat" ) ) { |
| 1258 |
CG_VoiceChat( SAY_TEAM ); |
| 1259 |
return; |
| 1260 |
} |
| 1261 |
|
| 1262 |
if ( !strcmp( cmd, "vtell" ) ) { |
| 1263 |
CG_VoiceChat( SAY_TELL ); |
| 1264 |
return; |
| 1265 |
} |
| 1266 |
|
| 1267 |
if ( !strcmp( cmd, "scores" ) ) { |
| 1268 |
CG_ParseScores(); |
| 1269 |
return; |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
if ( !strcmp( cmd, "accs" ) ) { |
| 1274 |
CG_ParseAccuracy(); |
| 1275 |
return; |
| 1276 |
} |
| 1277 |
|
| 1278 |
|
| 1279 |
if ( !strcmp( cmd, "ddtaken" ) ) { |
| 1280 |
CG_ParseDDtimetaken(); |
| 1281 |
return; |
| 1282 |
} |
| 1283 |
|
| 1284 |
if ( !strcmp( cmd, "dompointnames" ) ) { |
| 1285 |
CG_ParseDomPointNames(); |
| 1286 |
return; |
| 1287 |
} |
| 1288 |
|
| 1289 |
if ( !strcmp( cmd, "domStatus" ) ) { |
| 1290 |
CG_ParseDomStatus(); |
| 1291 |
return; |
| 1292 |
} |
| 1293 |
|
| 1294 |
if ( !strcmp( cmd, "elimination" ) ) { |
| 1295 |
CG_ParseElimination(); |
| 1296 |
return; |
| 1297 |
} |
| 1298 |
|
| 1299 |
if ( !strcmp( cmd, "mappage" ) ) { |
| 1300 |
CG_ParseMappage(); |
| 1301 |
return; |
| 1302 |
} |
| 1303 |
|
| 1304 |
if ( !strcmp( cmd, "attackingteam" ) ) { |
| 1305 |
CG_ParseAttackingTeam(); |
| 1306 |
return; |
| 1307 |
} |
| 1308 |
|
| 1309 |
if ( !strcmp( cmd, "tinfo" ) ) { |
| 1310 |
CG_ParseTeamInfo(); |
| 1311 |
return; |
| 1312 |
} |
| 1313 |
|
| 1314 |
if ( !strcmp( cmd, "map_restart" ) ) { |
| 1315 |
CG_MapRestart(); |
| 1316 |
return; |
| 1317 |
} |
| 1318 |
|
| 1319 |
if ( Q_stricmp (cmd, "remapShader") == 0 ) |
| 1320 |
{ |
| 1321 |
if (trap_Argc() == 4) |
| 1322 |
{ |
| 1323 |
char shader1[MAX_QPATH]; |
| 1324 |
char shader2[MAX_QPATH]; |
| 1325 |
char shader3[MAX_QPATH]; |
| 1326 |
|
| 1327 |
Q_strncpyz(shader1, CG_Argv(1), sizeof(shader1)); |
| 1328 |
Q_strncpyz(shader2, CG_Argv(2), sizeof(shader2)); |
| 1329 |
Q_strncpyz(shader3, CG_Argv(3), sizeof(shader3)); |
| 1330 |
|
| 1331 |
trap_R_RemapShader(shader1, shader2, shader3); |
| 1332 |
} |
| 1333 |
|
| 1334 |
return; |
| 1335 |
} |
| 1336 |
|
| 1337 |
// loaddeferred can be both a servercmd and a consolecmd |
| 1338 |
if ( !strcmp( cmd, "loaddefered" ) ) { // FIXME: spelled wrong, but not changing for demo |
| 1339 |
CG_LoadDeferredPlayers(); |
| 1340 |
return; |
| 1341 |
} |
| 1342 |
|
| 1343 |
// clientLevelShot is sent before taking a special screenshot for |
| 1344 |
// the menu system during development |
| 1345 |
if ( !strcmp( cmd, "clientLevelShot" ) ) { |
| 1346 |
cg.levelShot = qtrue; |
| 1347 |
return; |
| 1348 |
} |
| 1349 |
|
| 1350 |
// challenge completed is determened by the server. A client should consider this message valid: |
| 1351 |
if ( !strcmp( cmd, "ch" ) ) { |
| 1352 |
CG_ParseChallenge(); |
| 1353 |
return; |
| 1354 |
} |
| 1355 |
|
| 1356 |
if ( !strcmp (cmd, "oh") ) { |
| 1357 |
CG_ParseObeliskHealth(); |
| 1358 |
return; |
| 1359 |
} |
| 1360 |
|
| 1361 |
if ( !strcmp( cmd, "respawn" ) ) { |
| 1362 |
CG_ParseRespawnTime(); |
| 1363 |
return; |
| 1364 |
} |
| 1365 |
|
| 1366 |
if ( !strcmp( cmd, "team" ) ) { |
| 1367 |
CG_ParseTeam(); |
| 1368 |
return; |
| 1369 |
} |
| 1370 |
|
| 1371 |
if ( !strcmp( cmd, "customvotes" ) ) { |
| 1372 |
char infoString[1024]; |
| 1373 |
int i; |
| 1374 |
//TODO: Create a ParseCustomvotes function |
| 1375 |
memset(&infoString,0,sizeof(infoString)); |
| 1376 |
for(i=1;i<=12;i++) { |
| 1377 |
Q_strcat(infoString,sizeof(infoString),CG_Argv( i )); |
| 1378 |
Q_strcat(infoString,sizeof(infoString)," "); |
| 1379 |
} |
| 1380 |
trap_Cvar_Set("cg_vote_custom_commands",infoString); |
| 1381 |
return; |
| 1382 |
} |
| 1383 |
|
| 1384 |
CG_Printf( "Unknown client game command: %s\n", cmd ); |
| 1385 |
} |
| 1386 |
|
| 1387 |
|
| 1388 |
/* |
| 1389 |
==================== |
| 1390 |
CG_ExecuteNewServerCommands |
| 1391 |
|
| 1392 |
Execute all of the server commands that were received along |
| 1393 |
with this this snapshot. |
| 1394 |
==================== |
| 1395 |
*/ |
| 1396 |
void CG_ExecuteNewServerCommands( int latestSequence ) { |
| 1397 |
while ( cgs.serverCommandSequence < latestSequence ) { |
| 1398 |
if ( trap_GetServerCommand( ++cgs.serverCommandSequence ) ) { |
| 1399 |
CG_ServerCommand(); |
| 1400 |
} |
| 1401 |
} |
| 1402 |
} |