Debian Codegraph @

code/game/g_arenas.c

raw symbols SCIP
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 // g_arenas.c
25 //
26
27 #include "g_local.h"
28
29
30 gentity_t *podium1;
31 gentity_t *podium2;
32 gentity_t *podium3;
33
34
35 /*
36 ==================
37 UpdateTournamentInfo
38 ==================
39 */
40 void UpdateTournamentInfo( void ) {
41 int i;
42 gentity_t *player;
43 int playerClientNum;
44 int n, accuracy, perfect, msglen;
45 #ifdef MISSIONPACK
46 int score1, score2;
47 qboolean won;
48 #endif
49 char buf[32];
50 char msg[MAX_STRING_CHARS];
51
52 // find the real player
53 player = NULL;
54 for (i = 0; i < level.maxclients; i++ ) {
55 player = &g_entities[i];
56 if ( !player->inuse ) {
57 continue;
58 }
59 if ( !( player->r.svFlags & SVF_BOT ) ) {
60 break;
61 }
62 }
63 // this should never happen!
64 if ( !player || i == level.maxclients ) {
65 return;
66 }
67 playerClientNum = i;
68
69 CalculateRanks();
70
71 if ( level.clients[playerClientNum].sess.sessionTeam == TEAM_SPECTATOR ) {
72 #ifdef MISSIONPACK
73 Com_sprintf( msg, sizeof(msg), "postgame %i %i 0 0 0 0 0 0 0 0 0 0 0", level.numNonSpectatorClients, playerClientNum );
74 #else
75 Com_sprintf( msg, sizeof(msg), "postgame %i %i 0 0 0 0 0 0", level.numNonSpectatorClients, playerClientNum );
76 #endif
77 }
78 else {
79 if( player->client->accuracy_shots ) {
80 accuracy = player->client->accuracy_hits * 100 / player->client->accuracy_shots;
81 }
82 else {
83 accuracy = 0;
84 }
85 #ifdef MISSIONPACK
86 won = qfalse;
87 if (g_gametype.integer >= GT_CTF) {
88 score1 = level.teamScores[TEAM_RED];
89 score2 = level.teamScores[TEAM_BLUE];
90 if (level.clients[playerClientNum].sess.sessionTeam == TEAM_RED) {
91 won = (level.teamScores[TEAM_RED] > level.teamScores[TEAM_BLUE]);
92 } else {
93 won = (level.teamScores[TEAM_BLUE] > level.teamScores[TEAM_RED]);
94 }
95 } else {
96 if (&level.clients[playerClientNum] == &level.clients[ level.sortedClients[0] ]) {
97 won = qtrue;
98 score1 = level.clients[ level.sortedClients[0] ].ps.persistant[PERS_SCORE];
99 score2 = level.clients[ level.sortedClients[1] ].ps.persistant[PERS_SCORE];
100 } else {
101 score2 = level.clients[ level.sortedClients[0] ].ps.persistant[PERS_SCORE];
102 score1 = level.clients[ level.sortedClients[1] ].ps.persistant[PERS_SCORE];
103 }
104 }
105 if (won && player->client->ps.persistant[PERS_KILLED] == 0) {
106 perfect = 1;
107 } else {
108 perfect = 0;
109 }
110 Com_sprintf( msg, sizeof(msg), "postgame %i %i %i %i %i %i %i %i %i %i %i %i %i %i", level.numNonSpectatorClients, playerClientNum, accuracy,
111 player->client->ps.persistant[PERS_IMPRESSIVE_COUNT], player->client->ps.persistant[PERS_EXCELLENT_COUNT],player->client->ps.persistant[PERS_DEFEND_COUNT],
112 player->client->ps.persistant[PERS_ASSIST_COUNT], player->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT], player->client->ps.persistant[PERS_SCORE],
113 perfect, score1, score2, level.time, player->client->ps.persistant[PERS_CAPTURES] );
114
115 #else
116 perfect = ( level.clients[playerClientNum].ps.persistant[PERS_RANK] == 0 && player->client->ps.persistant[PERS_KILLED] == 0 ) ? 1 : 0;
117 Com_sprintf( msg, sizeof(msg), "postgame %i %i %i %i %i %i %i %i", level.numNonSpectatorClients, playerClientNum, accuracy,
118 player->client->ps.persistant[PERS_IMPRESSIVE_COUNT], player->client->ps.persistant[PERS_EXCELLENT_COUNT],
119 player->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT], player->client->ps.persistant[PERS_SCORE],
120 perfect );
121 #endif
122 }
123
124 msglen = strlen( msg );
125 for( i = 0; i < level.numNonSpectatorClients; i++ ) {
126 n = level.sortedClients[i];
127 Com_sprintf( buf, sizeof(buf), " %i %i %i", n, level.clients[n].ps.persistant[PERS_RANK], level.clients[n].ps.persistant[PERS_SCORE] );
128 msglen += strlen( buf );
129 if( msglen >= sizeof(msg) ) {
130 break;
131 }
132 strcat( msg, buf );
133 }
134 trap_SendConsoleCommand( EXEC_APPEND, msg );
135 }
136
137
138 static gentity_t *SpawnModelOnVictoryPad( gentity_t *pad, vec3_t offset, gentity_t *ent, int place ) {
139 gentity_t *body;
140 vec3_t vec;
141 vec3_t f, r, u;
142
143 body = G_Spawn();
144 if ( !body ) {
145 G_Printf( S_COLOR_RED "ERROR: out of gentities\n" );
146 return NULL;
147 }
148
149 body->classname = ent->client->pers.netname;
150 body->client = ent->client;
151 body->s = ent->s;
152 body->s.eType = ET_PLAYER; // could be ET_INVISIBLE
153 body->s.eFlags = 0; // clear EF_TALK, etc
154 body->s.powerups = 0; // clear powerups
155 body->s.loopSound = 0; // clear lava burning
156 body->s.number = body - g_entities;
157 body->timestamp = level.time;
158 body->physicsObject = qtrue;
159 body->physicsBounce = 0; // don't bounce
160 body->s.event = 0;
161 body->s.pos.trType = TR_STATIONARY;
162 body->s.groundEntityNum = ENTITYNUM_WORLD;
163 body->s.legsAnim = LEGS_IDLE;
164 body->s.torsoAnim = TORSO_STAND;
165 if( body->s.weapon == WP_NONE ) {
166 body->s.weapon = WP_MACHINEGUN;
167 }
168 if( body->s.weapon == WP_GAUNTLET) {
169 body->s.torsoAnim = TORSO_STAND2;
170 }
171 body->s.event = 0;
172 body->r.svFlags = ent->r.svFlags;
173 VectorCopy (ent->r.mins, body->r.mins);
174 VectorCopy (ent->r.maxs, body->r.maxs);
175 VectorCopy (ent->r.absmin, body->r.absmin);
176 VectorCopy (ent->r.absmax, body->r.absmax);
177 body->clipmask = CONTENTS_SOLID | CONTENTS_PLAYERCLIP;
178 body->r.contents = CONTENTS_BODY;
179 body->r.ownerNum = ent->r.ownerNum;
180 body->takedamage = qfalse;
181
182 VectorSubtract( level.intermission_origin, pad->r.currentOrigin, vec );
183 vectoangles( vec, body->s.apos.trBase );
184 body->s.apos.trBase[PITCH] = 0;
185 body->s.apos.trBase[ROLL] = 0;
186
187 AngleVectors( body->s.apos.trBase, f, r, u );
188 VectorMA( pad->r.currentOrigin, offset[0], f, vec );
189 VectorMA( vec, offset[1], r, vec );
190 VectorMA( vec, offset[2], u, vec );
191
192 G_SetOrigin( body, vec );
193
194 trap_LinkEntity (body);
195
196 body->count = place;
197
198 return body;
199 }
200
201
202 static void CelebrateStop( gentity_t *player ) {
203 int anim;
204
205 if( player->s.weapon == WP_GAUNTLET) {
206 anim = TORSO_STAND2;
207 }
208 else {
209 anim = TORSO_STAND;
210 }
211 player->s.torsoAnim = ( ( player->s.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim;
212 }
213
214
215 #define TIMER_GESTURE (34*66+50)
216 static void CelebrateStart( gentity_t *player ) {
217 player->s.torsoAnim = ( ( player->s.torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | TORSO_GESTURE;
218 player->nextthink = level.time + TIMER_GESTURE;
219 player->think = CelebrateStop;
220
221 /*
222 player->client->ps.events[player->client->ps.eventSequence & (MAX_PS_EVENTS-1)] = EV_TAUNT;
223 player->client->ps.eventParms[player->client->ps.eventSequence & (MAX_PS_EVENTS-1)] = 0;
224 player->client->ps.eventSequence++;
225 */
226 G_AddEvent(player, EV_TAUNT, 0);
227 }
228
229
230 static vec3_t offsetFirst = {0, 0, 74};
231 static vec3_t offsetSecond = {-10, 60, 54};
232 static vec3_t offsetThird = {-19, -60, 45};
233
234 static void PodiumPlacementThink( gentity_t *podium ) {
235 vec3_t vec;
236 vec3_t origin;
237 vec3_t f, r, u;
238
239 podium->nextthink = level.time + 100;
240
241 AngleVectors( level.intermission_angle, vec, NULL, NULL );
242 VectorMA( level.intermission_origin, trap_Cvar_VariableIntegerValue( "g_podiumDist" ), vec, origin );
243 origin[2] -= trap_Cvar_VariableIntegerValue( "g_podiumDrop" );
244 G_SetOrigin( podium, origin );
245
246 if( podium1 ) {
247 VectorSubtract( level.intermission_origin, podium->r.currentOrigin, vec );
248 vectoangles( vec, podium1->s.apos.trBase );
249 podium1->s.apos.trBase[PITCH] = 0;
250 podium1->s.apos.trBase[ROLL] = 0;
251
252 AngleVectors( podium1->s.apos.trBase, f, r, u );
253 VectorMA( podium->r.currentOrigin, offsetFirst[0], f, vec );
254 VectorMA( vec, offsetFirst[1], r, vec );
255 VectorMA( vec, offsetFirst[2], u, vec );
256
257 G_SetOrigin( podium1, vec );
258 }
259
260 if( podium2 ) {
261 VectorSubtract( level.intermission_origin, podium->r.currentOrigin, vec );
262 vectoangles( vec, podium2->s.apos.trBase );
263 podium2->s.apos.trBase[PITCH] = 0;
264 podium2->s.apos.trBase[ROLL] = 0;
265
266 AngleVectors( podium2->s.apos.trBase, f, r, u );
267 VectorMA( podium->r.currentOrigin, offsetSecond[0], f, vec );
268 VectorMA( vec, offsetSecond[1], r, vec );
269 VectorMA( vec, offsetSecond[2], u, vec );
270
271 G_SetOrigin( podium2, vec );
272 }
273
274 if( podium3 ) {
275 VectorSubtract( level.intermission_origin, podium->r.currentOrigin, vec );
276 vectoangles( vec, podium3->s.apos.trBase );
277 podium3->s.apos.trBase[PITCH] = 0;
278 podium3->s.apos.trBase[ROLL] = 0;
279
280 AngleVectors( podium3->s.apos.trBase, f, r, u );
281 VectorMA( podium->r.currentOrigin, offsetThird[0], f, vec );
282 VectorMA( vec, offsetThird[1], r, vec );
283 VectorMA( vec, offsetThird[2], u, vec );
284
285 G_SetOrigin( podium3, vec );
286 }
287 }
288
289
290 static gentity_t *SpawnPodium( void ) {
291 gentity_t *podium;
292 vec3_t vec;
293 vec3_t origin;
294
295 podium = G_Spawn();
296 if ( !podium ) {
297 return NULL;
298 }
299
300 podium->classname = "podium";
301 podium->s.eType = ET_GENERAL;
302 podium->s.number = podium - g_entities;
303 podium->clipmask = CONTENTS_SOLID;
304 podium->r.contents = CONTENTS_SOLID;
305 podium->s.modelindex = G_ModelIndex( SP_PODIUM_MODEL );
306
307 AngleVectors( level.intermission_angle, vec, NULL, NULL );
308 VectorMA( level.intermission_origin, trap_Cvar_VariableIntegerValue( "g_podiumDist" ), vec, origin );
309 origin[2] -= trap_Cvar_VariableIntegerValue( "g_podiumDrop" );
310 G_SetOrigin( podium, origin );
311
312 VectorSubtract( level.intermission_origin, podium->r.currentOrigin, vec );
313 podium->s.apos.trBase[YAW] = vectoyaw( vec );
314 trap_LinkEntity (podium);
315
316 podium->think = PodiumPlacementThink;
317 podium->nextthink = level.time + 100;
318 return podium;
319 }
320
321
322 /*
323 ==================
324 SpawnModelsOnVictoryPads
325 ==================
326 */
327 void SpawnModelsOnVictoryPads( void ) {
328 gentity_t *player;
329 gentity_t *podium;
330
331 podium1 = NULL;
332 podium2 = NULL;
333 podium3 = NULL;
334
335 podium = SpawnPodium();
336
337 player = SpawnModelOnVictoryPad( podium, offsetFirst, &g_entities[level.sortedClients[0]],
338 level.clients[ level.sortedClients[0] ].ps.persistant[PERS_RANK] &~ RANK_TIED_FLAG );
339 if ( player ) {
340 player->nextthink = level.time + 2000;
341 player->think = CelebrateStart;
342 podium1 = player;
343 }
344
345 player = SpawnModelOnVictoryPad( podium, offsetSecond, &g_entities[level.sortedClients[1]],
346 level.clients[ level.sortedClients[1] ].ps.persistant[PERS_RANK] &~ RANK_TIED_FLAG );
347 if ( player ) {
348 podium2 = player;
349 }
350
351 if ( level.numNonSpectatorClients > 2 ) {
352 player = SpawnModelOnVictoryPad( podium, offsetThird, &g_entities[level.sortedClients[2]],
353 level.clients[ level.sortedClients[2] ].ps.persistant[PERS_RANK] &~ RANK_TIED_FLAG );
354 if ( player ) {
355 podium3 = player;
356 }
357 }
358 }
359
360
361 /*
362 ===============
363 Svcmd_AbortPodium_f
364 ===============
365 */
366 void Svcmd_AbortPodium_f( void ) {
367 if( g_gametype.integer != GT_SINGLE_PLAYER ) {
368 return;
369 }
370
371 if( podium1 ) {
372 podium1->nextthink = level.time;
373 podium1->think = CelebrateStop;
374 }
375 }