Debian Codegraph @

code/game/g_team.c

raw
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Open Arena source code.
6 Portions copied from Tremulous under GPL version 2 including any later version.
7
8 Open Arena source code is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
12
13 Open Arena source code is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Open Arena source code; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 ===========================================================================
22 */
23 //
24
25 #include "g_local.h"
26
27
28 typedef struct teamgame_s {
29 float last_flag_capture;
30 int last_capture_team;
31 flagStatus_t redStatus; // CTF
32 flagStatus_t blueStatus; // CTF
33 flagStatus_t flagStatus; // One Flag CTF
34 int redTakenTime;
35 int blueTakenTime;
36 int redObeliskAttackedTime;
37 int blueObeliskAttackedTime;
38 } teamgame_t;
39
40 teamgame_t teamgame;
41
42 gentity_t *neutralObelisk;
43
44 //Some pointers for Double Domination so we don't need GFind (I think it might crash at random times...)
45 gentity_t *ddA;
46 gentity_t *ddB;
47 //Pointers for Standard Domination
48 gentity_t *dom_points[MAX_DOMINATION_POINTS];
49
50 void Team_SetFlagStatus( int team, flagStatus_t status );
51
52 qboolean dominationPointsSpawned;
53
54 void Team_InitGame( void ) {
55 memset(&teamgame, 0, sizeof teamgame);
56
57 switch( g_gametype.integer ) {
58 case GT_CTF:
59 case GT_CTF_ELIMINATION:
60 case GT_DOUBLE_D:
61 teamgame.redStatus = -1; // Invalid to force update
62 Team_SetFlagStatus( TEAM_RED, FLAG_ATBASE );
63 teamgame.blueStatus = -1; // Invalid to force update
64 Team_SetFlagStatus( TEAM_BLUE, FLAG_ATBASE );
65 ddA = NULL;
66 ddB = NULL;
67 break;
68 case GT_DOMINATION:
69 dominationPointsSpawned = qfalse;
70 break;
71 case GT_1FCTF:
72 teamgame.flagStatus = -1; // Invalid to force update
73 Team_SetFlagStatus( TEAM_FREE, FLAG_ATBASE );
74 break;
75 default:
76 break;
77 }
78 }
79
80 int OtherTeam(int team) {
81 if (team==TEAM_RED)
82 return TEAM_BLUE;
83 else if (team==TEAM_BLUE)
84 return TEAM_RED;
85 return team;
86 }
87
88 const char *TeamName(int team) {
89 if (team==TEAM_RED)
90 return "RED";
91 else if (team==TEAM_BLUE)
92 return "BLUE";
93 else if (team==TEAM_SPECTATOR)
94 return "SPECTATOR";
95 return "FREE";
96 }
97
98 const char *OtherTeamName(int team) {
99 if (team==TEAM_RED)
100 return "BLUE";
101 else if (team==TEAM_BLUE)
102 return "RED";
103 else if (team==TEAM_SPECTATOR)
104 return "SPECTATOR";
105 return "FREE";
106 }
107
108 const char *TeamColorString(int team) {
109 if (team==TEAM_RED)
110 return S_COLOR_RED;
111 else if (team==TEAM_BLUE)
112 return S_COLOR_BLUE;
113 else if (team==TEAM_SPECTATOR)
114 return S_COLOR_YELLOW;
115 return S_COLOR_WHITE;
116 }
117
118 // NULL for everyone
119 void QDECL PrintMsg( gentity_t *ent, const char *fmt, ... ) {
120 char msg[1024];
121 va_list argptr;
122 char *p;
123
124 va_start (argptr,fmt);
125 if (Q_vsnprintf (msg, sizeof(msg), fmt, argptr) >= sizeof(msg)) {
126 G_Error ( "PrintMsg overrun" );
127 }
128 va_end (argptr);
129
130 // double quotes are bad
131 while ((p = strchr(msg, '"')) != NULL)
132 *p = '\'';
133
134 trap_SendServerCommand ( ( (ent == NULL) ? -1 : ent-g_entities ), va("print \"%s\"", msg ));
135 }
136
137 /*
138 ================
139 KK-OAX From Tremulous
140 G_TeamFromString
141 Return the team referenced by a string
142 ================
143 */
144 team_t G_TeamFromString( char *str )
145 {
146 switch( tolower( *str ) )
147 {
148 case '0': case 's': return TEAM_NONE;
149 case '1': case 'f': return TEAM_FREE;
150 case '2': case 'r': return TEAM_RED;
151 case '3': case 'b': return TEAM_BLUE;
152 default: return TEAM_NUM_TEAMS;
153 }
154 }
155
156 /*
157 ==============
158 AddTeamScore
159
160 used for gametype > GT_TEAM
161 for gametype GT_TEAM the level.teamScores is updated in AddScore in g_combat.c
162 ==============
163 */
164 void AddTeamScore(vec3_t origin, int team, int score) {
165 gentity_t *te;
166
167
168 if ( g_gametype.integer != GT_DOMINATION ) {
169 te = G_TempEntity(origin, EV_GLOBAL_TEAM_SOUND );
170 te->r.svFlags |= SVF_BROADCAST;
171
172
173
174 if ( team == TEAM_RED ) {
175 if ( level.teamScores[ TEAM_RED ] + score == level.teamScores[ TEAM_BLUE ] ) {
176 //teams are tied sound
177 te->s.eventParm = GTS_TEAMS_ARE_TIED;
178 }
179 else if ( level.teamScores[ TEAM_RED ] <= level.teamScores[ TEAM_BLUE ] &&
180 level.teamScores[ TEAM_RED ] + score > level.teamScores[ TEAM_BLUE ]) {
181 // red took the lead sound
182 te->s.eventParm = GTS_REDTEAM_TOOK_LEAD;
183 }
184 else {
185 // red scored sound
186 te->s.eventParm = GTS_REDTEAM_SCORED;
187 }
188 }
189 else {
190 if ( level.teamScores[ TEAM_BLUE ] + score == level.teamScores[ TEAM_RED ] ) {
191 //teams are tied sound
192 te->s.eventParm = GTS_TEAMS_ARE_TIED;
193 }
194 else if ( level.teamScores[ TEAM_BLUE ] <= level.teamScores[ TEAM_RED ] &&
195 level.teamScores[ TEAM_BLUE ] + score > level.teamScores[ TEAM_RED ]) {
196 // blue took the lead sound
197 te->s.eventParm = GTS_BLUETEAM_TOOK_LEAD;
198 }
199 else {
200 // blue scored sound
201 te->s.eventParm = GTS_BLUETEAM_SCORED;
202 }
203 }
204 }
205 level.teamScores[ team ] += score;
206 }
207
208 /*
209 ==============
210 OnSameTeam
211 ==============
212 */
213 qboolean OnSameTeam( gentity_t *ent1, gentity_t *ent2 ) {
214 if ( !ent1->client || !ent2->client ) {
215 return qfalse;
216 }
217
218 if ( g_gametype.integer < GT_TEAM || g_ffa_gt==1) {
219 return qfalse;
220 }
221
222 if ( ent1->client->sess.sessionTeam == ent2->client->sess.sessionTeam ) {
223 return qtrue;
224 }
225
226 return qfalse;
227 }
228
229
230 static char ctfFlagStatusRemap[] = { '0', '1', '*', '*', '2' };
231 static char oneFlagStatusRemap[] = { '0', '1', '2', '3', '4' };
232
233 void Team_SetFlagStatus( int team, flagStatus_t status ) {
234 qboolean modified = qfalse;
235
236 switch( team ) {
237 case TEAM_RED: // CTF
238 if( teamgame.redStatus != status ) {
239 teamgame.redStatus = status;
240 modified = qtrue;
241 }
242 break;
243
244 case TEAM_BLUE: // CTF
245 if( teamgame.blueStatus != status ) {
246 teamgame.blueStatus = status;
247 modified = qtrue;
248 }
249 break;
250
251 case TEAM_FREE: // One Flag CTF
252 if( teamgame.flagStatus != status ) {
253 teamgame.flagStatus = status;
254 modified = qtrue;
255 }
256 break;
257 }
258
259
260 if( modified ) {
261 char st[4];
262
263 if( g_gametype.integer == GT_CTF || g_gametype.integer == GT_CTF_ELIMINATION) {
264 st[0] = ctfFlagStatusRemap[teamgame.redStatus];
265 st[1] = ctfFlagStatusRemap[teamgame.blueStatus];
266 st[2] = 0;
267 }
268 else if (g_gametype.integer == GT_DOUBLE_D) {
269 st[0] = oneFlagStatusRemap[teamgame.redStatus];
270 st[1] = oneFlagStatusRemap[teamgame.blueStatus];
271 st[2] = 0;
272 }
273 else { // GT_1FCTF
274 st[0] = oneFlagStatusRemap[teamgame.flagStatus];
275 st[1] = 0;
276 }
277
278 trap_SetConfigstring( CS_FLAGSTATUS, st );
279 }
280 }
281
282 void Team_CheckDroppedItem( gentity_t *dropped ) {
283 if( dropped->item->giTag == PW_REDFLAG ) {
284 Team_SetFlagStatus( TEAM_RED, FLAG_DROPPED );
285 }
286 else if( dropped->item->giTag == PW_BLUEFLAG ) {
287 Team_SetFlagStatus( TEAM_BLUE, FLAG_DROPPED );
288 }
289 else if( dropped->item->giTag == PW_NEUTRALFLAG ) {
290 Team_SetFlagStatus( TEAM_FREE, FLAG_DROPPED );
291 }
292 }
293
294 /*
295 ================
296 Team_ForceGesture
297 ================
298 */
299 void Team_ForceGesture(int team) {
300 int i;
301 gentity_t *ent;
302
303 for (i = 0; i < MAX_CLIENTS; i++) {
304 ent = &g_entities[i];
305 if (!ent->inuse)
306 continue;
307 if (!ent->client)
308 continue;
309 if (ent->client->sess.sessionTeam != team)
310 continue;
311 ent->flags |= FL_FORCE_GESTURE;
312 }
313 }
314
315 /*
316 ================
317 Team_DD_bonusAtPoints
318 Adds bonus point to a player if he is close to the point and on the team that scores
319 ================
320 */
321
322 void Team_DD_bonusAtPoints(int team) {
323 vec3_t v1, v2;
324 int i;
325 gentity_t *player;
326
327 for (i = 0; i < MAX_CLIENTS; i++) {
328 player = &g_entities[i];
329 if (!player->inuse)
330 continue;
331 if (!player->client)
332 continue;
333
334 if( player->client->sess.sessionTeam != team )
335 return; //player was not on scoring team
336
337 //See if the player is close to any of the points:
338 VectorSubtract(player->r.currentOrigin, ddA->r.currentOrigin, v1);
339 VectorSubtract(player->r.currentOrigin, ddB->r.currentOrigin, v2);
340 if (!( ( ( VectorLength(v1) < CTF_TARGET_PROTECT_RADIUS &&
341 trap_InPVS(ddA->r.currentOrigin, player->r.currentOrigin ) ) ||
342 ( VectorLength(v2) < CTF_TARGET_PROTECT_RADIUS &&
343 trap_InPVS(ddB->r.currentOrigin, player->r.currentOrigin ) ) )))
344 return; //Wasn't close to any of the points
345
346 AddScore(player, player->r.currentOrigin, DD_AT_POINT_AT_CAPTURE);
347 }
348 }
349
350 /*
351 ================
352 Team_FragBonuses
353
354 Calculate the bonuses for flag defense, flag carrier defense, etc.
355 Note that bonuses are not cumulative. You get one, they are in importance
356 order.
357 ================
358 */
359 void Team_FragBonuses(gentity_t *targ, gentity_t *inflictor, gentity_t *attacker)
360 {
361 int i;
362 gentity_t *ent;
363 int flag_pw, enemy_flag_pw;
364 int otherteam;
365 int tokens;
366 gentity_t *flag, *carrier = NULL;
367 char *c;
368 vec3_t v1, v2;
369 int team;
370
371 // no bonus for fragging yourself or team mates
372 if (!targ->client || !attacker->client || targ == attacker || OnSameTeam(targ, attacker))
373 return;
374
375 team = targ->client->sess.sessionTeam;
376 otherteam = OtherTeam(targ->client->sess.sessionTeam);
377 if (otherteam < 0)
378 return; // whoever died isn't on a team
379
380 // same team, if the flag at base, check to he has the enemy flag
381 if (team == TEAM_RED) {
382 flag_pw = PW_REDFLAG;
383 enemy_flag_pw = PW_BLUEFLAG;
384 } else {
385 flag_pw = PW_BLUEFLAG;
386 enemy_flag_pw = PW_REDFLAG;
387 }
388
389 if (g_gametype.integer == GT_1FCTF) {
390 enemy_flag_pw = PW_NEUTRALFLAG;
391 }
392
393 // did the attacker frag the flag carrier?
394 tokens = 0;
395 if( g_gametype.integer == GT_HARVESTER ) {
396 tokens = targ->client->ps.generic1;
397 }
398 if (targ->client->ps.powerups[enemy_flag_pw]) {
399 attacker->client->pers.teamState.lastfraggedcarrier = level.time;
400 AddScore(attacker, targ->r.currentOrigin, CTF_FRAG_CARRIER_BONUS);
401 attacker->client->pers.teamState.fragcarrier++;
402 PrintMsg(NULL, "%s" S_COLOR_WHITE " fragged %s's flag carrier!\n",
403 attacker->client->pers.netname, TeamName(team));
404 if(g_gametype.integer == GT_CTF) {
405 G_LogPrintf( "CTF: %i %i %i: %s fragged %s's flag carrier!\n", attacker->client->ps.clientNum, team, 3, attacker->client->pers.netname, TeamName(team) );
406 } else if(g_gametype.integer == GT_CTF_ELIMINATION) {
407 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s fragged %s's flag carrier!\n", level.roundNumber, attacker->client->ps.clientNum, team, 3, attacker->client->pers.netname, TeamName(team) );
408 } else if(g_gametype.integer == GT_1FCTF) {
409 G_LogPrintf( "1fCTF: %i %i %i: %s fragged %s's flag carrier!\n", attacker->client->ps.clientNum, team, 3, attacker->client->pers.netname, TeamName(team) );
410 }
411
412
413 // the target had the flag, clear the hurt carrier
414 // field on the other team
415 for (i = 0; i < g_maxclients.integer; i++) {
416 ent = g_entities + i;
417 if (ent->inuse && ent->client->sess.sessionTeam == otherteam)
418 ent->client->pers.teamState.lasthurtcarrier = 0;
419 }
420 return;
421 }
422
423 // did the attacker frag a head carrier? other->client->ps.generic1
424 if (tokens) {
425 attacker->client->pers.teamState.lastfraggedcarrier = level.time;
426 AddScore(attacker, targ->r.currentOrigin, CTF_FRAG_CARRIER_BONUS * tokens * tokens);
427 attacker->client->pers.teamState.fragcarrier++;
428 PrintMsg(NULL, "%s" S_COLOR_WHITE " fragged %s's skull carrier!\n",
429 attacker->client->pers.netname, TeamName(team));
430
431 G_LogPrintf("HARVESTER: %i %i %i %i %i: %s fragged %s (%s) who had %i skulls.\n",
432 attacker->client->ps.clientNum, team, 1, targ->client->ps.clientNum, tokens,
433 attacker->client->pers.netname, targ->client->pers.netname,TeamName(team),tokens);
434
435 // the target had the flag, clear the hurt carrier
436 // field on the other team
437 for (i = 0; i < g_maxclients.integer; i++) {
438 ent = g_entities + i;
439 if (ent->inuse && ent->client->sess.sessionTeam == otherteam)
440 ent->client->pers.teamState.lasthurtcarrier = 0;
441 }
442 return;
443 }
444
445 if (targ->client->pers.teamState.lasthurtcarrier &&
446 level.time - targ->client->pers.teamState.lasthurtcarrier < CTF_CARRIER_DANGER_PROTECT_TIMEOUT &&
447 !attacker->client->ps.powerups[flag_pw]) {
448 // attacker is on the same team as the flag carrier and
449 // fragged a guy who hurt our flag carrier
450 AddScore(attacker, targ->r.currentOrigin, CTF_CARRIER_DANGER_PROTECT_BONUS);
451
452 attacker->client->pers.teamState.carrierdefense++;
453 targ->client->pers.teamState.lasthurtcarrier = 0;
454
455 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
456 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 3, attacker->client->pers.netname, "DEFENCE" );
457 if(!level.hadBots)
458 ChallengeMessage(attacker,AWARD_DEFENCE);
459 team = attacker->client->sess.sessionTeam;
460 // add the sprite over the player's head
461 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
462 attacker->client->ps.eFlags |= EF_AWARD_DEFEND;
463 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
464
465 return;
466 }
467
468 if (targ->client->pers.teamState.lasthurtcarrier &&
469 level.time - targ->client->pers.teamState.lasthurtcarrier < CTF_CARRIER_DANGER_PROTECT_TIMEOUT) {
470 // attacker is on the same team as the skull carrier and
471 AddScore(attacker, targ->r.currentOrigin, CTF_CARRIER_DANGER_PROTECT_BONUS);
472
473 attacker->client->pers.teamState.carrierdefense++;
474 targ->client->pers.teamState.lasthurtcarrier = 0;
475
476 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
477 if(!level.hadBots)
478 ChallengeMessage(attacker,AWARD_DEFENCE);
479 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 3, attacker->client->pers.netname, "DEFENCE" );
480 team = attacker->client->sess.sessionTeam;
481 // add the sprite over the player's head
482 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
483 attacker->client->ps.eFlags |= EF_AWARD_DEFEND;
484 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
485
486 return;
487 }
488
489 //We place the Double Domination bonus test here! This appears to be the best place to place them.
490 if ( g_gametype.integer == GT_DOUBLE_D ) {
491 if(attacker->client->sess.sessionTeam == level.pointStatusA ) { //Attack must defend point A
492 //See how close attacker and target was to Point A:
493 VectorSubtract(targ->r.currentOrigin, ddA->r.currentOrigin, v1);
494 VectorSubtract(attacker->r.currentOrigin, ddA->r.currentOrigin, v2);
495
496 if ( ( ( VectorLength(v1) < CTF_TARGET_PROTECT_RADIUS &&
497 trap_InPVS(ddA->r.currentOrigin, targ->r.currentOrigin ) ) ||
498 ( VectorLength(v2) < CTF_TARGET_PROTECT_RADIUS &&
499 trap_InPVS(ddA->r.currentOrigin, attacker->r.currentOrigin ) ) ) &&
500 attacker->client->sess.sessionTeam != targ->client->sess.sessionTeam) {
501
502 //We defended point A
503 //Was we dominating and maybe close to score?
504 if(attacker->client->sess.sessionTeam == level.pointStatusB && level.time - level.timeTaken > (10-DD_CLOSE)*1000)
505 AddScore(attacker, targ->r.currentOrigin, DD_POINT_DEFENCE_CLOSE_BONUS);
506 else
507 AddScore(attacker, targ->r.currentOrigin, DD_POINT_DEFENCE_BONUS);
508 attacker->client->pers.teamState.basedefense++;
509
510 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
511 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 3, attacker->client->pers.netname, "DEFENCE" );
512 if(!level.hadBots)
513 ChallengeMessage(attacker,AWARD_DEFENCE);
514 // add the sprite over the player's head
515 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
516 attacker->client->ps.eFlags |= EF_AWARD_DEFEND;
517 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
518
519 return; //Return so we don't recieve credits for point B also
520
521 } //We denfended point A
522
523
524
525 } //Defend point A
526
527 if(attacker->client->sess.sessionTeam == level.pointStatusB ) { //Attack must defend point B
528 //See how close attacker and target was to Point B:
529 VectorSubtract(targ->r.currentOrigin, ddB->r.currentOrigin, v1);
530 VectorSubtract(attacker->r.currentOrigin, ddB->r.currentOrigin, v2);
531
532 if ( ( ( VectorLength(v1) < CTF_TARGET_PROTECT_RADIUS &&
533 trap_InPVS(ddB->r.currentOrigin, targ->r.currentOrigin ) ) ||
534 ( VectorLength(v2) < CTF_TARGET_PROTECT_RADIUS &&
535 trap_InPVS(ddB->r.currentOrigin, attacker->r.currentOrigin ) ) ) &&
536 attacker->client->sess.sessionTeam != targ->client->sess.sessionTeam) {
537
538 //We defended point B
539 //Was we dominating and maybe close to score?
540 if(attacker->client->sess.sessionTeam == level.pointStatusA && level.time - level.timeTaken > (10-DD_CLOSE)*1000)
541 AddScore(attacker, targ->r.currentOrigin, DD_POINT_DEFENCE_CLOSE_BONUS);
542 else
543 AddScore(attacker, targ->r.currentOrigin, DD_POINT_DEFENCE_BONUS);
544 attacker->client->pers.teamState.basedefense++;
545
546 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
547 if(!level.hadBots)
548 ChallengeMessage(attacker,AWARD_DEFENCE);
549 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 3, attacker->client->pers.netname, "DEFENCE" );
550 // add the sprite over the player's head
551 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
552 attacker->client->ps.eFlags |= EF_AWARD_DEFEND;
553 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
554
555 return;
556
557 } //We denfended point B
558
559
560
561 } //Defend point B
562 return; //In double Domination we shall not go on, or we would test for team bases that we don't use
563 }
564
565 // flag and flag carrier area defense bonuses
566
567 // we have to find the flag and carrier entities
568
569 if( g_gametype.integer == GT_OBELISK ) {
570 // find the team obelisk
571 switch (attacker->client->sess.sessionTeam) {
572 case TEAM_RED:
573 c = "team_redobelisk";
574 break;
575 case TEAM_BLUE:
576 c = "team_blueobelisk";
577 break;
578 default:
579 return;
580 }
581
582 } else if (g_gametype.integer == GT_HARVESTER ) {
583 // find the center obelisk
584 c = "team_neutralobelisk";
585 } else {
586 // find the flag
587 switch (attacker->client->sess.sessionTeam) {
588 case TEAM_RED:
589 c = "team_CTF_redflag";
590 break;
591 case TEAM_BLUE:
592 c = "team_CTF_blueflag";
593 break;
594 default:
595 return;
596 }
597 // find attacker's team's flag carrier
598 for (i = 0; i < g_maxclients.integer; i++) {
599 carrier = g_entities + i;
600 if (carrier->inuse && carrier->client->ps.powerups[flag_pw])
601 break;
602 carrier = NULL;
603 }
604 }
605 flag = NULL;
606 while ((flag = G_Find (flag, FOFS(classname), c)) != NULL) {
607 if (!(flag->flags & FL_DROPPED_ITEM))
608 break;
609 }
610
611 if (!flag)
612 return; // can't find attacker's flag
613
614 // ok we have the attackers flag and a pointer to the carrier
615
616 // check to see if we are defending the base's flag
617 VectorSubtract(targ->r.currentOrigin, flag->r.currentOrigin, v1);
618 VectorSubtract(attacker->r.currentOrigin, flag->r.currentOrigin, v2);
619
620 if ( ( ( VectorLength(v1) < CTF_TARGET_PROTECT_RADIUS &&
621 trap_InPVS(flag->r.currentOrigin, targ->r.currentOrigin ) ) ||
622 ( VectorLength(v2) < CTF_TARGET_PROTECT_RADIUS &&
623 trap_InPVS(flag->r.currentOrigin, attacker->r.currentOrigin ) ) ) &&
624 attacker->client->sess.sessionTeam != targ->client->sess.sessionTeam && g_gametype.integer != GT_ELIMINATION &&
625 (g_gametype.integer != GT_CTF_ELIMINATION || !g_elimination_ctf_oneway.integer ||
626 ((level.eliminationSides+level.roundNumber)%2 == 0 && attacker->client->sess.sessionTeam == TEAM_BLUE ) ||
627 ((level.eliminationSides+level.roundNumber)%2 == 1 && attacker->client->sess.sessionTeam == TEAM_RED ) ) ) {
628
629 // we defended the base flag
630 AddScore(attacker, targ->r.currentOrigin, CTF_FLAG_DEFENSE_BONUS);
631 attacker->client->pers.teamState.basedefense++;
632
633 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
634 if(!level.hadBots)
635 ChallengeMessage(attacker,AWARD_DEFENCE);
636 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 3, attacker->client->pers.netname, "DEFENCE" );
637 // add the sprite over the player's head
638 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
639 attacker->client->ps.eFlags |= EF_AWARD_DEFEND;
640 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
641
642 return;
643 }
644
645 if (carrier && carrier != attacker) {
646 VectorSubtract(targ->r.currentOrigin, carrier->r.currentOrigin, v1);
647 VectorSubtract(attacker->r.currentOrigin, carrier->r.currentOrigin, v1);
648
649 if ( ( ( VectorLength(v1) < CTF_ATTACKER_PROTECT_RADIUS &&
650 trap_InPVS(carrier->r.currentOrigin, targ->r.currentOrigin ) ) ||
651 ( VectorLength(v2) < CTF_ATTACKER_PROTECT_RADIUS &&
652 trap_InPVS(carrier->r.currentOrigin, attacker->r.currentOrigin ) ) ) &&
653 attacker->client->sess.sessionTeam != targ->client->sess.sessionTeam) {
654 AddScore(attacker, targ->r.currentOrigin, CTF_CARRIER_PROTECT_BONUS);
655 attacker->client->pers.teamState.carrierdefense++;
656
657 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
658 if(!level.hadBots)
659 ChallengeMessage(attacker,AWARD_DEFENCE);
660 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 3, attacker->client->pers.netname, "DEFENCE" );
661 // add the sprite over the player's head
662 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
663 attacker->client->ps.eFlags |= EF_AWARD_DEFEND;
664 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
665
666 return;
667 }
668 }
669 }
670
671 /*
672 ================
673 Team_CheckHurtCarrier
674
675 Check to see if attacker hurt the flag carrier. Needed when handing out bonuses for assistance to flag
676 carrier defense.
677 ================
678 */
679 void Team_CheckHurtCarrier(gentity_t *targ, gentity_t *attacker)
680 {
681 int flag_pw;
682
683 if (!targ->client || !attacker->client)
684 return;
685
686 if (targ->client->sess.sessionTeam == TEAM_RED)
687 flag_pw = PW_BLUEFLAG;
688 else
689 flag_pw = PW_REDFLAG;
690
691 // flags
692 if (targ->client->ps.powerups[flag_pw] &&
693 targ->client->sess.sessionTeam != attacker->client->sess.sessionTeam)
694 attacker->client->pers.teamState.lasthurtcarrier = level.time;
695
696 // skulls
697 if (targ->client->ps.generic1 &&
698 targ->client->sess.sessionTeam != attacker->client->sess.sessionTeam)
699 attacker->client->pers.teamState.lasthurtcarrier = level.time;
700 }
701
702
703 gentity_t *Team_ResetFlag( int team ) {
704 char *c;
705 gentity_t *ent, *rent = NULL;
706
707 switch (team) {
708 case TEAM_RED:
709 c = "team_CTF_redflag";
710 break;
711 case TEAM_BLUE:
712 c = "team_CTF_blueflag";
713 break;
714 case TEAM_FREE:
715 c = "team_CTF_neutralflag";
716 break;
717 default:
718 return NULL;
719 }
720
721 ent = NULL;
722 while ((ent = G_Find (ent, FOFS(classname), c)) != NULL) {
723 if (ent->flags & FL_DROPPED_ITEM)
724 G_FreeEntity(ent);
725 else {
726 rent = ent;
727 RespawnItem(ent);
728 }
729 }
730
731 Team_SetFlagStatus( team, FLAG_ATBASE );
732
733 return rent;
734 }
735
736 //Functions for Domination
737
738 void Team_Dom_SpawnPoints( void ) {
739 char *c;
740 gentity_t *flag;
741 int i;
742 gitem_t *it;
743
744 flag = NULL;
745
746 if(dominationPointsSpawned)
747 return;
748 dominationPointsSpawned = qtrue;
749
750 it = NULL;
751 it = BG_FindItem ("Neutral domination point");
752 if(it == NULL) {
753 PrintMsg( NULL, "No domination item\n");
754 return;
755 } else {
756 PrintMsg( NULL, "Domination item found\n");
757 }
758 i = 0;
759 c = "domination_point";
760
761 //return; Just to test, the lines below crashes game
762
763 while ((flag = G_Find (flag, FOFS(classname), c)) != NULL) {
764 if(i>=MAX_DOMINATION_POINTS)
765 break;
766 //domination_points_names[i] = flag->message;
767 if(flag->message) {
768 Q_strncpyz(level.domination_points_names[i],flag->message,MAX_DOMINATION_POINTS_NAMES-1);
769 PrintMsg( NULL, "Domination point \'%s\' found\n",level.domination_points_names[i]);
770 } else {
771 Q_strncpyz(level.domination_points_names[i],va("Point %i",i),MAX_DOMINATION_POINTS_NAMES-1);
772 PrintMsg( NULL, "Domination point \'%s\' found (autonamed)\n",level.domination_points_names[i]);
773 }
774 dom_points[i] = G_Spawn();
775 VectorCopy( flag->r.currentOrigin, dom_points[i]->s.origin );
776 dom_points[i]->classname = it->classname;
777 G_SpawnItem(dom_points[i], it);
778 FinishSpawningItem(dom_points[i] );
779
780 i++;
781 }
782 level.domination_points_count = i;
783 }
784
785 int getDomPointNumber( gentity_t *point ) {
786 int i;
787 for(i=1;i<MAX_DOMINATION_POINTS && i<level.domination_points_count;i++) {
788 if(dom_points[i] == NULL)
789 return 0; //Not found, just return first, so we don't crash
790 if(dom_points[i] == point)
791 return i;
792 }
793 return 0;
794 }
795
796 void Team_Dom_TakePoint( gentity_t *point, int team, int clientnumber ) {
797 gitem_t *it;
798 vec3_t origin;
799 int i;
800 i = getDomPointNumber(point);
801 if(i<0)
802 i = 0;
803 if(i>=MAX_DOMINATION_POINTS)
804 i = MAX_DOMINATION_POINTS - 1;
805
806 it = NULL;
807 VectorCopy( point->r.currentOrigin, origin );
808
809 if(team == TEAM_RED) {
810 it = BG_FindItem ("Red domination point");
811 PrintMsg( NULL, "Red took \'%s\'\n",level.domination_points_names[i]);
812 } else
813 if(team == TEAM_BLUE) {
814 it = BG_FindItem ("Blue domination point");
815 PrintMsg( NULL, "Blue took \'%s\'\n",level.domination_points_names[i]);
816 }
817 if (!it || it == NULL) {
818 PrintMsg( NULL, "No item\n");
819 return;
820 }
821
822 G_FreeEntity(point);
823
824 point = G_Spawn();
825
826 VectorCopy( origin, point->s.origin );
827 point->classname = it->classname;
828 dom_points[i] = point;
829 G_SpawnItem(point, it);
830 FinishSpawningItem( point );
831 level.pointStatusDom[i] = team;
832 G_LogPrintf( "DOM: %i %i %i %i: %s takes point %s!\n",
833 clientnumber,i,0,team,
834 TeamName(team),level.domination_points_names[i]);
835 SendDominationPointsStatusMessageToAllClients();
836 }
837
838 //Functions for Double Domination
839
840 void Team_DD_RemovePointAgfx( void ) {
841 if(ddA!=NULL) {
842 G_FreeEntity(ddA);
843 ddA = NULL;
844 }
845 }
846
847 void Team_DD_RemovePointBgfx( void ) {
848 if(ddB!=NULL) {
849 G_FreeEntity(ddB);
850 ddB = NULL;
851 }
852 }
853
854 void Team_DD_makeA2team( gentity_t *target, int team ) {
855 gitem_t *it;
856 //gentity_t *it_ent;
857 Team_DD_RemovePointAgfx();
858 it = NULL;
859 if(team == TEAM_NONE)
860 return;
861 if(team == TEAM_RED)
862 it = BG_FindItem ("Point A (Red)");
863 if(team == TEAM_BLUE)
864 it = BG_FindItem ("Point A (Blue)");
865 if(team == TEAM_FREE)
866 it = BG_FindItem ("Point A (White)");
867 if (!it || it == NULL) {
868 PrintMsg( NULL, "No item\n");
869 return;
870 }
871 ddA = G_Spawn();
872
873 VectorCopy( target->r.currentOrigin, ddA->s.origin );
874 ddA->classname = it->classname;
875 G_SpawnItem(ddA, it);
876 FinishSpawningItem(ddA );
877 }
878
879 void Team_DD_makeB2team( gentity_t *target, int team ) {
880 gitem_t *it;
881 //gentity_t *it_ent;
882
883 Team_DD_RemovePointBgfx();
884 it = NULL;
885 if(team == TEAM_NONE)
886 return;
887 if(team == TEAM_RED)
888 it = BG_FindItem ("Point B (Red)");
889 if(team == TEAM_BLUE)
890 it = BG_FindItem ("Point B (Blue)");
891 if(team == TEAM_FREE)
892 it = BG_FindItem ("Point B (White)");
893 if (!it || it == NULL) {
894 PrintMsg( NULL, "No item\n");
895 return;
896 }
897 ddB = G_Spawn();
898
899 VectorCopy( target->r.currentOrigin, ddB->s.origin );
900 ddB->classname = it->classname;
901 G_SpawnItem(ddB, it);
902 FinishSpawningItem(ddB );
903 }
904
905 void Team_ResetFlags( void ) {
906 if( g_gametype.integer == GT_CTF || g_gametype.integer == GT_CTF_ELIMINATION) {
907 Team_ResetFlag( TEAM_RED );
908 Team_ResetFlag( TEAM_BLUE );
909 }
910 else if( g_gametype.integer == GT_1FCTF ) {
911 Team_ResetFlag( TEAM_FREE );
912 }
913 }
914
915 void Team_ReturnFlagSound( gentity_t *ent, int team ) {
916 gentity_t *te;
917
918 if (ent == NULL) {
919 G_Printf ("Warning: NULL passed to Team_ReturnFlagSound\n");
920 return;
921 }
922
923 //See if we are during CTF_ELIMINATION warmup
924 if((level.time<=level.roundStartTime && level.time>level.roundStartTime-1000*g_elimination_activewarmup.integer)&&g_gametype.integer == GT_CTF_ELIMINATION)
925 return;
926
927 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_TEAM_SOUND );
928 if( team == TEAM_BLUE ) {
929 te->s.eventParm = GTS_RED_RETURN;
930 }
931 else {
932 te->s.eventParm = GTS_BLUE_RETURN;
933 }
934 te->r.svFlags |= SVF_BROADCAST;
935 }
936
937 void Team_TakeFlagSound( gentity_t *ent, int team ) {
938 gentity_t *te;
939
940 if (ent == NULL) {
941 G_Printf ("Warning: NULL passed to Team_TakeFlagSound\n");
942 return;
943 }
944
945 // only play sound when the flag was at the base
946 // or not picked up the last 10 seconds
947 switch(team) {
948 case TEAM_RED:
949 if( teamgame.blueStatus != FLAG_ATBASE ) {
950 if (teamgame.blueTakenTime > level.time - 10000 && g_gametype.integer != GT_CTF_ELIMINATION)
951 return;
952 }
953 teamgame.blueTakenTime = level.time;
954 break;
955
956 case TEAM_BLUE: // CTF
957 if( teamgame.redStatus != FLAG_ATBASE ) {
958 if (teamgame.redTakenTime > level.time - 10000 && g_gametype.integer != GT_CTF_ELIMINATION)
959 return;
960 }
961 teamgame.redTakenTime = level.time;
962 break;
963 }
964
965 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_TEAM_SOUND );
966 if( team == TEAM_BLUE ) {
967 te->s.eventParm = GTS_RED_TAKEN;
968 }
969 else {
970 te->s.eventParm = GTS_BLUE_TAKEN;
971 }
972 te->r.svFlags |= SVF_BROADCAST;
973 }
974
975 void Team_CaptureFlagSound( gentity_t *ent, int team ) {
976 gentity_t *te;
977
978 if (ent == NULL) {
979 G_Printf ("Warning: NULL passed to Team_CaptureFlagSound\n");
980 return;
981 }
982
983 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_TEAM_SOUND );
984 if( team == TEAM_BLUE ) {
985 te->s.eventParm = GTS_BLUE_CAPTURE;
986 }
987 else {
988 te->s.eventParm = GTS_RED_CAPTURE;
989 }
990 te->r.svFlags |= SVF_BROADCAST;
991 }
992
993 void Team_ReturnFlag( int team ) {
994 Team_ReturnFlagSound(Team_ResetFlag(team), team);
995 if( team == TEAM_FREE ) {
996 PrintMsg(NULL, "The flag has returned!\n" );
997 if(g_gametype.integer == GT_1FCTF) {
998 G_LogPrintf( "1FCTF: %i %i %i: The flag was returned!\n", -1, -1, 2 );
999 }
1000 }
1001 else {
1002 PrintMsg(NULL, "The %s flag has returned!\n", TeamName(team));
1003 if(g_gametype.integer == GT_CTF_ELIMINATION) {
1004 G_LogPrintf( "CTF: %i %i %i: The %s flag was returned!\n", -1, team, 2, TeamName(team) );
1005 } else
1006 if(g_gametype.integer == GT_CTF_ELIMINATION) {
1007 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: The %s flag was returned!\n", level.roundNumber, -1, team, 2, TeamName(team) );
1008 }
1009 }
1010 }
1011
1012 void Team_FreeEntity( gentity_t *ent ) {
1013 if( ent->item->giTag == PW_REDFLAG ) {
1014 Team_ReturnFlag( TEAM_RED );
1015 }
1016 else if( ent->item->giTag == PW_BLUEFLAG ) {
1017 Team_ReturnFlag( TEAM_BLUE );
1018 }
1019 else if( ent->item->giTag == PW_NEUTRALFLAG ) {
1020 Team_ReturnFlag( TEAM_FREE );
1021 }
1022 }
1023
1024 /*
1025 ==============
1026 Team_DroppedFlagThink
1027
1028 Automatically set in Launch_Item if the item is one of the flags
1029
1030 Flags are unique in that if they are dropped, the base flag must be respawned when they time out
1031 ==============
1032 */
1033 void Team_DroppedFlagThink(gentity_t *ent) {
1034 int team = TEAM_FREE;
1035
1036 if( ent->item->giTag == PW_REDFLAG ) {
1037 team = TEAM_RED;
1038 }
1039 else if( ent->item->giTag == PW_BLUEFLAG ) {
1040 team = TEAM_BLUE;
1041 }
1042 else if( ent->item->giTag == PW_NEUTRALFLAG ) {
1043 team = TEAM_FREE;
1044 }
1045
1046 Team_ReturnFlagSound( Team_ResetFlag( team ), team );
1047 // Reset Flag will delete this entity
1048 }
1049
1050 /*
1051 Update DD points
1052 */
1053
1054 void updateDDpoints(void) {
1055 //teamgame.redStatus = -1; // Invalid to force update
1056 Team_SetFlagStatus( TEAM_RED, level.pointStatusA );
1057 //teamgame.blueStatus = -1; // Invalid to force update
1058 Team_SetFlagStatus( TEAM_BLUE, level.pointStatusB );
1059 }
1060
1061 /*
1062 ==============
1063 Team_SpawnDoubleDominationPoints
1064 ==============
1065 */
1066
1067 int Team_SpawnDoubleDominationPoints ( void ) {
1068 gentity_t *ent;
1069 level.pointStatusA = TEAM_FREE;
1070 level.pointStatusB = TEAM_FREE;
1071 updateDDpoints();
1072 ent = NULL;
1073 if ((ent = G_Find (ent, FOFS(classname), "team_CTF_redflag")) != NULL) {
1074 Team_DD_makeA2team( ent, TEAM_FREE );
1075 }
1076 ent = NULL;
1077 if ((ent = G_Find (ent, FOFS(classname), "team_CTF_blueflag")) != NULL) {
1078 Team_DD_makeB2team( ent, TEAM_FREE );
1079 }
1080 return 1;
1081 }
1082
1083 /*
1084 ==============
1085 Team_RemoveDoubleDominationPoints
1086 ==============
1087 */
1088
1089 int Team_RemoveDoubleDominationPoints ( void ) {
1090 level.pointStatusA = TEAM_NONE;
1091 level.pointStatusB = TEAM_NONE;
1092 updateDDpoints();
1093 Team_DD_makeA2team( NULL, TEAM_NONE );
1094 Team_DD_makeB2team( NULL, TEAM_NONE );
1095 return 1;
1096 }
1097
1098 /*
1099 ==============
1100 Team_TouchDoubleDominationPoint
1101 ==============
1102 */
1103
1104 //team is the either TEAM_RED(A) or TEAM_BLUE(B)
1105 int Team_TouchDoubleDominationPoint( gentity_t *ent, gentity_t *other, int team ) {
1106 gclient_t *cl = other->client;
1107 qboolean otherDominating, isClose;
1108 int clientTeam = cl->sess.sessionTeam;
1109 int otherTeam;
1110 int score; //Used to add the scores together
1111
1112 if(clientTeam == TEAM_RED)
1113 otherTeam = TEAM_BLUE;
1114 else
1115 otherTeam = TEAM_RED;
1116
1117 otherDominating = qfalse;
1118 isClose = qfalse;
1119
1120 if(level.pointStatusA == otherTeam && level.pointStatusB == otherTeam) {
1121 otherDominating = qtrue;
1122 if(level.time - level.timeTaken > (10-DD_CLOSE)*1000)
1123 isClose = qtrue;
1124 }
1125
1126
1127 if(team == TEAM_RED) //We have touched point A
1128 {
1129 if(TEAM_NONE == level.pointStatusA)
1130 return 0; //Haven't spawned yet
1131 if(clientTeam == level.pointStatusA)
1132 return 0; //If we already have the flag
1133 //if we didn't have the point, then we have now!
1134 level.pointStatusA = clientTeam;
1135 PrintMsg( NULL, "%s" S_COLOR_WHITE " (%s) took control of A!\n", cl->pers.netname, TeamName(clientTeam) );
1136 Team_DD_makeA2team( ent, clientTeam );
1137 G_LogPrintf( "DD: %i %i %i: %s took point A for %s!\n", cl->ps.clientNum, clientTeam, 0, cl->pers.netname, TeamName(clientTeam) );
1138 //Give personal score
1139 score = DD_POINT_CAPTURE; //Base score for capture
1140 if(otherDominating){
1141 score += DD_POINT_CAPTURE_BREAK;
1142 if(isClose)
1143 score += DD_POINT_CAPTURE_CLOSE;
1144 }
1145 AddScore(other, ent->r.currentOrigin, score);
1146 //Do we also have point B?
1147 if(clientTeam == level.pointStatusB)
1148 {
1149 //We are dominating!
1150 level.timeTaken = level.time; //At this time
1151 PrintMsg( NULL, "%s" S_COLOR_WHITE " is dominating!\n", TeamName(clientTeam) );
1152 SendDDtimetakenMessageToAllClients();
1153 }
1154 }
1155
1156 if(team == TEAM_BLUE) //We have touched point B
1157 {
1158 if(TEAM_NONE == level.pointStatusB)
1159 return 0; //Haven't spawned yet
1160 if(clientTeam == level.pointStatusB)
1161 return 0; //If we already have the flag
1162 //if we didn't have the point, then we have now!
1163 level.pointStatusB = clientTeam;
1164 PrintMsg( NULL, "%s" S_COLOR_WHITE " (%s) took control of B!\n", cl->pers.netname, TeamName(clientTeam) );
1165 Team_DD_makeB2team( ent, clientTeam );
1166 G_LogPrintf( "DD: %i %i %i: %s took point B for %s!\n", cl->ps.clientNum, clientTeam, 1, cl->pers.netname, TeamName(clientTeam) );
1167 //Give personal score
1168 score = DD_POINT_CAPTURE; //Base score for capture
1169 if(otherDominating){
1170 score += DD_POINT_CAPTURE_BREAK;
1171 if(isClose)
1172 score += DD_POINT_CAPTURE_CLOSE;
1173 }
1174 AddScore(other, ent->r.currentOrigin, score);
1175 //Do we also have point A?
1176 if(clientTeam == level.pointStatusA)
1177 {
1178 //We are dominating!
1179 level.timeTaken = level.time; //At this time
1180 PrintMsg( NULL, "%s" S_COLOR_WHITE " is dominating!\n", TeamName(clientTeam) );
1181 SendDDtimetakenMessageToAllClients();
1182 }
1183 }
1184
1185 updateDDpoints();
1186
1187 return 0;
1188 }
1189
1190 /*
1191 ==============
1192 Team_TouchOurFlag
1193 ==============
1194 */
1195 int Team_TouchOurFlag( gentity_t *ent, gentity_t *other, int team ) {
1196 int i;
1197 gentity_t *player;
1198 gclient_t *cl = other->client;
1199 int enemy_flag;
1200
1201 if( g_gametype.integer == GT_1FCTF ) {
1202 enemy_flag = PW_NEUTRALFLAG;
1203 }
1204 else {
1205 if (cl->sess.sessionTeam == TEAM_RED) {
1206 enemy_flag = PW_BLUEFLAG;
1207 } else {
1208 enemy_flag = PW_REDFLAG;
1209 }
1210
1211 if ( ent->flags & FL_DROPPED_ITEM ) {
1212 // hey, its not home. return it by teleporting it back
1213 PrintMsg( NULL, "%s" S_COLOR_WHITE " returned the %s flag!\n",
1214 cl->pers.netname, TeamName(team));
1215 AddScore(other, ent->r.currentOrigin, CTF_RECOVERY_BONUS);
1216 if(g_gametype.integer == GT_CTF) {
1217 G_LogPrintf( "CTF: %i %i %i: %s returned the %s flag!\n", cl->ps.clientNum, team, 2, cl->pers.netname, TeamName(team) );
1218 } else if(g_gametype.integer == GT_CTF_ELIMINATION) {
1219 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s returned the %s flag!\n", level.roundNumber, cl->ps.clientNum, team, 2, cl->pers.netname, TeamName(team) );
1220 }
1221 other->client->pers.teamState.flagrecovery++;
1222 other->client->pers.teamState.lastreturnedflag = level.time;
1223 //ResetFlag will remove this entity! We must return zero
1224 Team_ReturnFlagSound(Team_ResetFlag(team), team);
1225 return 0;
1226 }
1227 }
1228
1229 // the flag is at home base. if the player has the enemy
1230 // flag, he's just won!
1231 if (!cl->ps.powerups[enemy_flag])
1232 return 0; // We don't have the flag
1233 if( g_gametype.integer == GT_1FCTF ) {
1234 PrintMsg( NULL, "%s" S_COLOR_WHITE " captured the flag!\n", cl->pers.netname );
1235 G_LogPrintf( "1FCTF: %i %i %i: %s captured the flag!\n", cl->ps.clientNum, -1, 1, cl->pers.netname );
1236 }
1237 else {
1238 PrintMsg( NULL, "%s" S_COLOR_WHITE " captured the %s flag!\n", cl->pers.netname, TeamName(OtherTeam(team)));
1239 if(g_gametype.integer == GT_CTF)
1240 G_LogPrintf( "CTF: %i %i %i: %s captured the %s flag!\n", cl->ps.clientNum, OtherTeam(team), 1, cl->pers.netname, TeamName(OtherTeam(team)) );
1241 if(g_gametype.integer == GT_CTF_ELIMINATION)
1242 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s captured the %s flag!\n", level.roundNumber, cl->ps.clientNum, OtherTeam(team), 1, cl->pers.netname, TeamName(OtherTeam(team)) );
1243 }
1244
1245 cl->ps.powerups[enemy_flag] = 0;
1246
1247 teamgame.last_flag_capture = level.time;
1248 teamgame.last_capture_team = team;
1249
1250 // Increase the team's score
1251 AddTeamScore(ent->s.pos.trBase, other->client->sess.sessionTeam, 1);
1252 Team_ForceGesture(other->client->sess.sessionTeam);
1253 //If CTF Elimination, stop the round:
1254 if(g_gametype.integer==GT_CTF_ELIMINATION) {
1255 EndEliminationRound();
1256 }
1257
1258 other->client->pers.teamState.captures++;
1259 // add the sprite over the player's head
1260 other->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
1261 other->client->ps.eFlags |= EF_AWARD_CAP;
1262 other->client->rewardTime = level.time + REWARD_SPRITE_TIME;
1263 other->client->ps.persistant[PERS_CAPTURES]++;
1264 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", other->client->ps.clientNum, 4, other->client->pers.netname, "CAPTURE" );
1265 if(TeamCount(-1,TEAM_RED) && TeamCount(-1,TEAM_BLUE) && !level.hadBots)
1266 ChallengeMessage(other,AWARD_CAPTURE);
1267 // other gets another 10 frag bonus
1268 AddScore(other, ent->r.currentOrigin, CTF_CAPTURE_BONUS);
1269
1270 Team_CaptureFlagSound( ent, team );
1271
1272 // Ok, let's do the player loop, hand out the bonuses
1273 for (i = 0; i < g_maxclients.integer; i++) {
1274 player = &g_entities[i];
1275 if (!player->inuse || player == other)
1276 continue;
1277
1278 if (player->client->sess.sessionTeam !=
1279 cl->sess.sessionTeam) {
1280 player->client->pers.teamState.lasthurtcarrier = -5;
1281 } else if (player->client->sess.sessionTeam ==
1282 cl->sess.sessionTeam) {
1283 if (player != other)
1284 AddScore(player, ent->r.currentOrigin, CTF_TEAM_BONUS);
1285 // award extra points for capture assists
1286 if (player->client->pers.teamState.lastreturnedflag +
1287 CTF_RETURN_FLAG_ASSIST_TIMEOUT > level.time) {
1288 AddScore (player, ent->r.currentOrigin, CTF_RETURN_FLAG_ASSIST_BONUS);
1289 other->client->pers.teamState.assists++;
1290
1291 player->client->ps.persistant[PERS_ASSIST_COUNT]++;
1292 if(!level.hadBots)
1293 ChallengeMessage(player,AWARD_ASSIST);
1294 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", player->client->ps.clientNum, 5, player->client->pers.netname, "ASSIST" );
1295 // add the sprite over the player's head
1296 player->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
1297 player->client->ps.eFlags |= EF_AWARD_ASSIST;
1298 player->client->rewardTime = level.time + REWARD_SPRITE_TIME;
1299
1300 }
1301 if (player->client->pers.teamState.lastfraggedcarrier +
1302 CTF_FRAG_CARRIER_ASSIST_TIMEOUT > level.time) {
1303 AddScore(player, ent->r.currentOrigin, CTF_FRAG_CARRIER_ASSIST_BONUS);
1304 other->client->pers.teamState.assists++;
1305 player->client->ps.persistant[PERS_ASSIST_COUNT]++;
1306 if(!level.hadBots)
1307 ChallengeMessage(player,AWARD_ASSIST);
1308 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", player->client->ps.clientNum, 5, player->client->pers.netname, "ASSIST" );
1309 // add the sprite over the player's head
1310 player->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
1311 player->client->ps.eFlags |= EF_AWARD_ASSIST;
1312 player->client->rewardTime = level.time + REWARD_SPRITE_TIME;
1313 }
1314 }
1315 }
1316 Team_ResetFlags();
1317
1318 CalculateRanks();
1319
1320 return 0; // Do not respawn this automatically
1321 }
1322
1323 int Team_TouchEnemyFlag( gentity_t *ent, gentity_t *other, int team ) {
1324 gclient_t *cl = other->client;
1325
1326 if( g_gametype.integer == GT_1FCTF ) {
1327 PrintMsg (NULL, "%s" S_COLOR_WHITE " got the flag!\n", other->client->pers.netname );
1328
1329 G_LogPrintf( "1FCTF: %i %i %i: %s got the flag!\n", cl->ps.clientNum, team, 0, cl->pers.netname);
1330
1331 cl->ps.powerups[PW_NEUTRALFLAG] = INT_MAX; // flags never expire
1332
1333 if( team == TEAM_RED ) {
1334 Team_SetFlagStatus( TEAM_FREE, FLAG_TAKEN_RED );
1335 }
1336 else {
1337 Team_SetFlagStatus( TEAM_FREE, FLAG_TAKEN_BLUE );
1338 }
1339 }
1340 else{
1341 PrintMsg (NULL, "%s" S_COLOR_WHITE " got the %s flag!\n",
1342 other->client->pers.netname, TeamName(team));
1343
1344 if(g_gametype.integer == GT_CTF) {
1345 G_LogPrintf( "CTF: %i %i %i: %s got the %s flag!\n", cl->ps.clientNum, team, 0, cl->pers.netname, TeamName(team));
1346 } else if(g_gametype.integer == GT_CTF_ELIMINATION) {
1347 G_LogPrintf( "CTF_ELIMINATION: %i %i %i %i: %s got the %s flag!\n", level.roundNumber, cl->ps.clientNum, team, 0, cl->pers.netname, TeamName(team));
1348 }
1349
1350 if (team == TEAM_RED)
1351 cl->ps.powerups[PW_REDFLAG] = INT_MAX; // flags never expire
1352 else
1353 cl->ps.powerups[PW_BLUEFLAG] = INT_MAX; // flags never expire
1354
1355 Team_SetFlagStatus( team, FLAG_TAKEN );
1356 }
1357
1358 AddScore(other, ent->r.currentOrigin, CTF_FLAG_BONUS);
1359 cl->pers.teamState.flagsince = level.time;
1360 Team_TakeFlagSound( ent, team );
1361
1362 return -1; // Do not respawn this automatically, but do delete it if it was FL_DROPPED
1363 }
1364
1365 int Pickup_Team( gentity_t *ent, gentity_t *other ) {
1366 int team;
1367 gclient_t *cl = other->client;
1368
1369 if( g_gametype.integer == GT_OBELISK ) {
1370 // there are no team items that can be picked up in obelisk
1371 G_FreeEntity( ent );
1372 return 0;
1373 }
1374
1375 if( g_gametype.integer == GT_HARVESTER ) {
1376 // the only team items that can be picked up in harvester are the cubes
1377 if( ent->spawnflags != cl->sess.sessionTeam ) {
1378 cl->ps.generic1 += 1; //Skull pickedup
1379 G_LogPrintf("HARVESTER: %i %i %i %i %i: %s picked up a skull.\n",
1380 cl->ps.clientNum,cl->sess.sessionTeam,3,-1,1,
1381 cl->pers.netname);
1382 } else {
1383 G_LogPrintf("HARVESTER: %i %i %i %i %i: %s destroyed a skull.\n,",
1384 cl->ps.clientNum,cl->sess.sessionTeam,2,-1,1,
1385 cl->pers.netname);
1386 }
1387 G_FreeEntity( ent ); //Destory skull
1388 return 0;
1389 }
1390 if ( g_gametype.integer == GT_DOMINATION ) {
1391 Team_Dom_TakePoint(ent, cl->sess.sessionTeam,cl->ps.clientNum);
1392 return 0;
1393 }
1394 // figure out what team this flag is
1395 if( strcmp(ent->classname, "team_CTF_redflag") == 0 ) {
1396 team = TEAM_RED;
1397 }
1398 else if( strcmp(ent->classname, "team_CTF_blueflag") == 0 ) {
1399 team = TEAM_BLUE;
1400 }
1401 else if( strcmp(ent->classname, "team_CTF_neutralflag") == 0 ) {
1402 team = TEAM_FREE;
1403 }
1404 else {
1405 PrintMsg ( other, "Don't know what team the flag is on.\n");
1406 return 0;
1407 }
1408 if( g_gametype.integer == GT_1FCTF ) {
1409 if( team == TEAM_FREE ) {
1410 return Team_TouchEnemyFlag( ent, other, cl->sess.sessionTeam );
1411 }
1412 if( team != cl->sess.sessionTeam) {
1413 return Team_TouchOurFlag( ent, other, cl->sess.sessionTeam );
1414 }
1415 return 0;
1416 }
1417 if( g_gametype.integer == GT_DOUBLE_D) {
1418 return Team_TouchDoubleDominationPoint( ent, other, team );
1419 }
1420 // GT_CTF
1421 if( team == cl->sess.sessionTeam) {
1422 return Team_TouchOurFlag( ent, other, team );
1423 }
1424 return Team_TouchEnemyFlag( ent, other, team );
1425 }
1426
1427 /*
1428 ===========
1429 Team_GetLocation
1430
1431 Report a location for the player. Uses placed nearby target_location entities
1432 ============
1433 */
1434 gentity_t *Team_GetLocation(gentity_t *ent)
1435 {
1436 gentity_t *eloc, *best;
1437 float bestlen, len;
1438 vec3_t origin;
1439
1440 best = NULL;
1441 bestlen = 3*8192.0*8192.0;
1442
1443 VectorCopy( ent->r.currentOrigin, origin );
1444
1445 for (eloc = level.locationHead; eloc; eloc = eloc->nextTrain) {
1446 len = ( origin[0] - eloc->r.currentOrigin[0] ) * ( origin[0] - eloc->r.currentOrigin[0] )
1447 + ( origin[1] - eloc->r.currentOrigin[1] ) * ( origin[1] - eloc->r.currentOrigin[1] )
1448 + ( origin[2] - eloc->r.currentOrigin[2] ) * ( origin[2] - eloc->r.currentOrigin[2] );
1449
1450 if ( len > bestlen ) {
1451 continue;
1452 }
1453
1454 if ( !trap_InPVS( origin, eloc->r.currentOrigin ) ) {
1455 continue;
1456 }
1457
1458 bestlen = len;
1459 best = eloc;
1460 }
1461
1462 return best;
1463 }
1464
1465
1466 /*
1467 ===========
1468 Team_GetLocation
1469
1470 Report a location for the player. Uses placed nearby target_location entities
1471 ============
1472 */
1473 qboolean Team_GetLocationMsg(gentity_t *ent, char *loc, int loclen)
1474 {
1475 gentity_t *best;
1476
1477 best = Team_GetLocation( ent );
1478
1479 if (!best)
1480 return qfalse;
1481
1482 if (best->count) {
1483 if (best->count < 0)
1484 best->count = 0;
1485 if (best->count > 7)
1486 best->count = 7;
1487 Com_sprintf(loc, loclen, "%c%c%s" S_COLOR_WHITE, Q_COLOR_ESCAPE, best->count + '0', best->message );
1488 } else
1489 Com_sprintf(loc, loclen, "%s", best->message);
1490
1491 return qtrue;
1492 }
1493
1494
1495 /*---------------------------------------------------------------------------*/
1496
1497 /*
1498 ================
1499 SelectRandomDeathmatchSpawnPoint
1500
1501 go to a random point that doesn't telefrag
1502 ================
1503 */
1504 #define MAX_TEAM_SPAWN_POINTS 32
1505 gentity_t *SelectRandomTeamSpawnPoint( int teamstate, team_t team ) {
1506 gentity_t *spot;
1507 int count;
1508 int selection;
1509 gentity_t *spots[MAX_TEAM_SPAWN_POINTS];
1510 char *classname;
1511
1512 if(g_gametype.integer == GT_ELIMINATION) { //change sides every round
1513 if((level.roundNumber+level.eliminationSides)%2==1){
1514 if(team == TEAM_RED)
1515 team = TEAM_BLUE;
1516 else if(team == TEAM_BLUE)
1517 team = TEAM_RED;
1518 }
1519 }
1520
1521 if (teamstate == TEAM_BEGIN) {
1522 if (team == TEAM_RED)
1523 classname = "team_CTF_redplayer";
1524 else if (team == TEAM_BLUE)
1525 classname = "team_CTF_blueplayer";
1526 else
1527 return NULL;
1528 } else {
1529 if (team == TEAM_RED)
1530 classname = "team_CTF_redspawn";
1531 else if (team == TEAM_BLUE)
1532 classname = "team_CTF_bluespawn";
1533 else
1534 return NULL;
1535 }
1536 count = 0;
1537
1538 spot = NULL;
1539
1540 while ((spot = G_Find (spot, FOFS(classname), classname)) != NULL) {
1541 if ( SpotWouldTelefrag( spot ) ) {
1542 continue;
1543 }
1544 spots[ count ] = spot;
1545 if (++count == MAX_TEAM_SPAWN_POINTS)
1546 break;
1547 }
1548
1549 if ( !count ) { // no spots that won't telefrag
1550 return G_Find( NULL, FOFS(classname), classname);
1551 }
1552
1553 selection = rand() % count;
1554 return spots[ selection ];
1555 }
1556
1557 /*
1558 ================
1559 SelectRandomDDSpawnPoint
1560
1561 go to a random Double Domination Spawn Point
1562 ================
1563 */
1564 #define MAX_TEAM_SPAWN_POINTS 32
1565 gentity_t *SelectRandomDDSpawnPoint( void ) {
1566 gentity_t *spot;
1567 int count;
1568 int selection;
1569 gentity_t *spots[MAX_TEAM_SPAWN_POINTS];
1570 char *classname;
1571
1572
1573 classname = "info_player_dd";
1574
1575 count = 0;
1576
1577 spot = NULL;
1578
1579 while ((spot = G_Find (spot, FOFS(classname), classname)) != NULL) {
1580 if ( SpotWouldTelefrag( spot ) ) {
1581 continue;
1582 }
1583 spots[ count ] = spot;
1584 if (++count == MAX_TEAM_SPAWN_POINTS)
1585 break;
1586 }
1587
1588 if ( !count ) { // no spots that won't telefrag
1589 return G_Find( NULL, FOFS(classname), classname);
1590 }
1591
1592 selection = rand() % count;
1593 return spots[ selection ];
1594 }
1595
1596 gentity_t *SelectRandomTeamDDSpawnPoint( team_t team ) {
1597 gentity_t *spot;
1598 int count;
1599 int selection;
1600 gentity_t *spots[MAX_TEAM_SPAWN_POINTS];
1601 char *classname;
1602
1603 if(team == TEAM_RED)
1604 classname = "info_player_dd_red";
1605 else
1606 classname = "info_player_dd_blue";
1607
1608 count = 0;
1609
1610 spot = NULL;
1611
1612 while ((spot = G_Find (spot, FOFS(classname), classname)) != NULL) {
1613 if ( SpotWouldTelefrag( spot ) ) {
1614 continue;
1615 }
1616 spots[ count ] = spot;
1617 if (++count == MAX_TEAM_SPAWN_POINTS)
1618 break;
1619 }
1620
1621 if ( !count ) { // no spots that won't telefrag
1622 return G_Find( NULL, FOFS(classname), classname);
1623 }
1624
1625 selection = rand() % count;
1626 return spots[ selection ];
1627 }
1628
1629
1630 /*
1631 ===========
1632 SelectCTFSpawnPoint
1633
1634 ============
1635 */
1636 gentity_t *SelectCTFSpawnPoint ( team_t team, int teamstate, vec3_t origin, vec3_t angles ) {
1637 gentity_t *spot;
1638
1639 spot = SelectRandomTeamSpawnPoint ( teamstate, team );
1640
1641 if (!spot) {
1642 return SelectSpawnPoint( vec3_origin, origin, angles );
1643 }
1644
1645 VectorCopy (spot->s.origin, origin);
1646 origin[2] += 9;
1647 VectorCopy (spot->s.angles, angles);
1648
1649 return spot;
1650 }
1651
1652 /*
1653 ===========
1654 SelectDoubleDominationSpawnPoint
1655
1656 ============
1657 */
1658 gentity_t *SelectDoubleDominationSpawnPoint ( team_t team, vec3_t origin, vec3_t angles ) {
1659 gentity_t *spot;
1660
1661 spot = SelectRandomTeamDDSpawnPoint( team );
1662
1663 if(!spot) {
1664 spot = SelectRandomDDSpawnPoint ( );
1665 }
1666
1667 if (!spot) {
1668 return SelectSpawnPoint( vec3_origin, origin, angles );
1669 }
1670
1671 VectorCopy (spot->s.origin, origin);
1672 origin[2] += 9;
1673 VectorCopy (spot->s.angles, angles);
1674
1675 return spot;
1676 }
1677
1678 /*---------------------------------------------------------------------------*/
1679
1680 static int QDECL SortClients( const void *a, const void *b ) {
1681 return *(int *)a - *(int *)b;
1682 }
1683
1684
1685 /*
1686 ==================
1687 TeamplayLocationsMessage
1688
1689 Format:
1690 clientNum location health armor weapon powerups
1691
1692 ==================
1693 */
1694 void TeamplayInfoMessage( gentity_t *ent ) {
1695 char entry[1024];
1696 char string[8192];
1697 int stringlength;
1698 int i, j;
1699 gentity_t *player;
1700 int cnt;
1701 int h, a, w;
1702 int clients[TEAM_MAXOVERLAY];
1703
1704 if ( ! ent->client->pers.teamInfo )
1705 return;
1706
1707 // figure out what client should be on the display
1708 // we are limited to 8, but we want to use the top eight players
1709 // but in client order (so they don't keep changing position on the overlay)
1710 for (i = 0, cnt = 0; i < g_maxclients.integer && cnt < TEAM_MAXOVERLAY; i++) {
1711 player = g_entities + level.sortedClients[i];
1712 if (player->inuse && player->client->sess.sessionTeam ==
1713 ent->client->sess.sessionTeam ) {
1714 clients[cnt++] = level.sortedClients[i];
1715 }
1716 }
1717
1718 // We have the top eight players, sort them by clientNum
1719 qsort( clients, cnt, sizeof( clients[0] ), SortClients );
1720
1721 // send the latest information on all clients
1722 string[0] = 0;
1723 stringlength = 0;
1724
1725 for (i = 0, cnt = 0; i < g_maxclients.integer && cnt < TEAM_MAXOVERLAY; i++) {
1726 player = g_entities + i;
1727 if (player->inuse && player->client->sess.sessionTeam ==
1728 ent->client->sess.sessionTeam ) {
1729
1730 h = player->client->ps.stats[STAT_HEALTH];
1731 a = player->client->ps.stats[STAT_ARMOR];
1732 w = player->client->ps.weapon;
1733 if(player->client->isEliminated)
1734 {
1735 h = 0;
1736 a = 0;
1737 w = 0;
1738 }
1739 if (h < 0) h = 0;
1740 if (a < 0) a = 0;
1741
1742 Com_sprintf (entry, sizeof(entry),
1743 " %i %i %i %i %i %i",
1744 // level.sortedClients[i], player->client->pers.teamState.location, h, a,
1745 i, player->client->pers.teamState.location, h, a,
1746 w, player->s.powerups);
1747 j = strlen(entry);
1748 if (stringlength + j > sizeof(string))
1749 break;
1750 strcpy (string + stringlength, entry);
1751 stringlength += j;
1752 cnt++;
1753 }
1754 }
1755
1756 trap_SendServerCommand( ent-g_entities, va("tinfo %i %s", cnt, string) );
1757 }
1758
1759 void CheckTeamStatus(void) {
1760 int i;
1761 gentity_t *loc, *ent;
1762
1763 if (level.time - level.lastTeamLocationTime > TEAM_LOCATION_UPDATE_TIME) {
1764
1765 level.lastTeamLocationTime = level.time;
1766
1767 for (i = 0; i < g_maxclients.integer; i++) {
1768 ent = g_entities + i;
1769
1770 if ( ent->client->pers.connected != CON_CONNECTED ) {
1771 continue;
1772 }
1773
1774 if (ent->inuse && (ent->client->sess.sessionTeam == TEAM_RED || ent->client->sess.sessionTeam == TEAM_BLUE)) {
1775 loc = Team_GetLocation( ent );
1776 if (loc)
1777 ent->client->pers.teamState.location = loc->health;
1778 else
1779 ent->client->pers.teamState.location = 0;
1780 }
1781 }
1782
1783 for (i = 0; i < g_maxclients.integer; i++) {
1784 ent = g_entities + i;
1785
1786 if ( ent->client->pers.connected != CON_CONNECTED ) {
1787 continue;
1788 }
1789
1790 if (ent->inuse && (ent->client->sess.sessionTeam == TEAM_RED || ent->client->sess.sessionTeam == TEAM_BLUE)) {
1791 TeamplayInfoMessage( ent );
1792 }
1793 }
1794 }
1795 }
1796
1797 /*-----------------------------------------------------------------*/
1798
1799 /*QUAKED team_CTF_redplayer (1 0 0) (-16 -16 -16) (16 16 32)
1800 Only in CTF games. Red players spawn here at game start.
1801 */
1802 void SP_team_CTF_redplayer( gentity_t *ent ) {
1803 }
1804
1805
1806 /*QUAKED team_CTF_blueplayer (0 0 1) (-16 -16 -16) (16 16 32)
1807 Only in CTF games. Blue players spawn here at game start.
1808 */
1809 void SP_team_CTF_blueplayer( gentity_t *ent ) {
1810 }
1811
1812
1813 /*QUAKED team_CTF_redspawn (1 0 0) (-16 -16 -24) (16 16 32)
1814 potential spawning position for red team in CTF games.
1815 Targets will be fired when someone spawns in on them.
1816 */
1817 void SP_team_CTF_redspawn(gentity_t *ent) {
1818 }
1819
1820 /*QUAKED team_CTF_bluespawn (0 0 1) (-16 -16 -24) (16 16 32)
1821 potential spawning position for blue team in CTF games.
1822 Targets will be fired when someone spawns in on them.
1823 */
1824 void SP_team_CTF_bluespawn(gentity_t *ent) {
1825 }
1826
1827 /*
1828 ================
1829 Obelisks
1830 ================
1831 */
1832
1833 static void ObeliskHealthChange( int team, int health ) {
1834 int currentPercentage;
1835 int percentage = (health*100)/g_obeliskHealth.integer;
1836 if(percentage < 0)
1837 percentage = 0;
1838 currentPercentage = level.healthRedObelisk;
1839 if(team != TEAM_RED)
1840 currentPercentage = level.healthBlueObelisk;
1841 if(percentage != currentPercentage) {
1842 if(team == TEAM_RED) {
1843 level.healthRedObelisk = percentage;
1844 } else {
1845 level.healthBlueObelisk = percentage;
1846 }
1847 level.MustSendObeliskHealth = qtrue;
1848 //G_Printf("Obelisk health %i %i\n",team,percentage);
1849 ObeliskHealthMessage();
1850 }
1851 }
1852
1853 static void ObeliskRegen( gentity_t *self ) {
1854 self->nextthink = level.time + g_obeliskRegenPeriod.integer * 1000;
1855 ObeliskHealthChange(self->spawnflags,self->health);
1856 if( self->health >= g_obeliskHealth.integer ) {
1857 return;
1858 }
1859
1860 G_AddEvent( self, EV_POWERUP_REGEN, 0 );
1861 self->health += g_obeliskRegenAmount.integer;
1862 if ( self->health > g_obeliskHealth.integer ) {
1863 self->health = g_obeliskHealth.integer;
1864 }
1865
1866 self->activator->s.modelindex2 = self->health * 0xff / g_obeliskHealth.integer;
1867 self->activator->s.frame = 0;
1868 }
1869
1870
1871 static void ObeliskRespawn( gentity_t *self ) {
1872 self->takedamage = qtrue;
1873 self->health = g_obeliskHealth.integer;
1874
1875 self->think = ObeliskRegen;
1876 self->nextthink = level.time + g_obeliskRegenPeriod.integer * 1000;
1877
1878 self->activator->s.frame = 0;
1879 }
1880
1881
1882 static void ObeliskDie( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int mod ) {
1883 int otherTeam;
1884
1885 otherTeam = OtherTeam( self->spawnflags );
1886 AddTeamScore(self->s.pos.trBase, otherTeam, 1);
1887 Team_ForceGesture(otherTeam);
1888
1889 CalculateRanks();
1890
1891 self->takedamage = qfalse;
1892 self->think = ObeliskRespawn;
1893 self->nextthink = level.time + g_obeliskRespawnDelay.integer * 1000;
1894
1895 self->activator->s.modelindex2 = 0xff;
1896 self->activator->s.frame = 2;
1897
1898 G_AddEvent( self->activator, EV_OBELISKEXPLODE, 0 );
1899
1900 AddScore(attacker, self->r.currentOrigin, CTF_CAPTURE_BONUS);
1901
1902 // add the sprite over the player's head
1903 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
1904 attacker->client->ps.eFlags |= EF_AWARD_CAP;
1905 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
1906 attacker->client->ps.persistant[PERS_CAPTURES]++;
1907 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", attacker->client->ps.clientNum, 4, attacker->client->pers.netname, "CAPTURE" );
1908 G_LogPrintf("OBELISK: %i %i %i %i: %s destroyed the enemy obelisk.\n",
1909 attacker->client->ps.clientNum,attacker->client->sess.sessionTeam,3,0,
1910 attacker->client->pers.netname);
1911 if(TeamCount(-1,TEAM_RED) && TeamCount(-1,TEAM_BLUE) && !level.hadBots)
1912 ChallengeMessage(attacker,AWARD_CAPTURE);
1913
1914 ObeliskHealthChange(self->spawnflags,self->health);
1915 teamgame.redObeliskAttackedTime = 0;
1916 teamgame.blueObeliskAttackedTime = 0;
1917 }
1918
1919
1920 static void ObeliskTouch( gentity_t *self, gentity_t *other, trace_t *trace ) {
1921 int tokens,i;
1922
1923 if ( !other->client ) {
1924 return;
1925 }
1926
1927 if ( OtherTeam(other->client->sess.sessionTeam) != self->spawnflags ) {
1928 return;
1929 }
1930
1931 tokens = other->client->ps.generic1;
1932 if( tokens <= 0 ) {
1933 return;
1934 }
1935
1936 PrintMsg(NULL, "%s" S_COLOR_WHITE " brought in %i skull%s.\n",
1937 other->client->pers.netname, tokens, tokens>1 ? "s" : "" );
1938
1939 G_LogPrintf("HARVESTER: %i %i %i %i %i: %s brought in %i skull%s for %s\n",
1940 other->client->ps.clientNum,other->client->sess.sessionTeam,0,-1,tokens,
1941 other->client->pers.netname,tokens, tokens>1 ? "s" : "", TeamName(other->client->sess.sessionTeam));
1942
1943 AddTeamScore(self->s.pos.trBase, other->client->sess.sessionTeam, tokens);
1944 Team_ForceGesture(other->client->sess.sessionTeam);
1945
1946 AddScore(other, self->r.currentOrigin, CTF_CAPTURE_BONUS*tokens);
1947
1948 // add the sprite over the player's head
1949 other->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
1950 other->client->ps.eFlags |= EF_AWARD_CAP;
1951 other->client->rewardTime = level.time + REWARD_SPRITE_TIME;
1952 other->client->ps.persistant[PERS_CAPTURES] += tokens;
1953 for(i = 0;i<tokens;i++)
1954 {
1955 G_LogPrintf( "Award: %i %i: %s gained the %s award!\n", other->client->ps.clientNum, 4, other->client->pers.netname, "CAPTURE" );
1956 if(TeamCount(-1,TEAM_RED) && TeamCount(-1,TEAM_BLUE) && !level.hadBots)
1957 ChallengeMessage(other,AWARD_CAPTURE);
1958 }
1959
1960 other->client->ps.generic1 = 0;
1961 CalculateRanks();
1962
1963 Team_CaptureFlagSound( self, self->spawnflags );
1964 }
1965
1966 static void ObeliskPain( gentity_t *self, gentity_t *attacker, int damage ) {
1967 int actualDamage = damage / 10;
1968 if (actualDamage <= 0) {
1969 actualDamage = 1;
1970 }
1971 self->activator->s.modelindex2 = self->health * 0xff / g_obeliskHealth.integer;
1972 if (!self->activator->s.frame) {
1973 G_AddEvent(self, EV_OBELISKPAIN, 0);
1974 }
1975 self->activator->s.frame = 1;
1976 AddScore(attacker, self->r.currentOrigin, actualDamage);
1977 G_LogPrintf("OBELISK: %i %i %i %i: %s dealt %i damage to the enemy obelisk.\n",
1978 attacker->client->ps.clientNum,attacker->client->sess.sessionTeam,1,actualDamage,
1979 attacker->client->pers.netname,actualDamage);
1980 }
1981
1982 gentity_t *SpawnObelisk( vec3_t origin, int team, int spawnflags) {
1983 trace_t tr;
1984 vec3_t dest;
1985 gentity_t *ent;
1986
1987 ent = G_Spawn();
1988
1989 VectorCopy( origin, ent->s.origin );
1990 VectorCopy( origin, ent->s.pos.trBase );
1991 VectorCopy( origin, ent->r.currentOrigin );
1992
1993 VectorSet( ent->r.mins, -15, -15, 0 );
1994 VectorSet( ent->r.maxs, 15, 15, 87 );
1995
1996 ent->s.eType = ET_GENERAL;
1997 ent->flags = FL_NO_KNOCKBACK;
1998
1999 if( g_gametype.integer == GT_OBELISK ) {
2000 ent->r.contents = CONTENTS_SOLID;
2001 ent->takedamage = qtrue;
2002 ent->health = g_obeliskHealth.integer;
2003 ent->die = ObeliskDie;
2004 ent->pain = ObeliskPain;
2005 ent->think = ObeliskRegen;
2006 ent->nextthink = level.time + g_obeliskRegenPeriod.integer * 1000;
2007 }
2008 if( g_gametype.integer == GT_HARVESTER ) {
2009 ent->r.contents = CONTENTS_TRIGGER;
2010 ent->touch = ObeliskTouch;
2011 }
2012
2013 if ( spawnflags & 1 ) {
2014 // suspended
2015 G_SetOrigin( ent, ent->s.origin );
2016 } else {
2017 // mappers like to put them exactly on the floor, but being coplanar
2018 // will sometimes show up as starting in solid, so lif it up one pixel
2019 ent->s.origin[2] += 1;
2020
2021 // drop to floor
2022 VectorSet( dest, ent->s.origin[0], ent->s.origin[1], ent->s.origin[2] - 4096 );
2023 trap_Trace( &tr, ent->s.origin, ent->r.mins, ent->r.maxs, dest, ent->s.number, MASK_SOLID );
2024 if ( tr.startsolid ) {
2025 ent->s.origin[2] -= 1;
2026 G_Printf( "SpawnObelisk: %s startsolid at %s\n", ent->classname, vtos(ent->s.origin) );
2027
2028 ent->s.groundEntityNum = ENTITYNUM_NONE;
2029 G_SetOrigin( ent, ent->s.origin );
2030 }
2031 else {
2032 // allow to ride movers
2033 ent->s.groundEntityNum = tr.entityNum;
2034 G_SetOrigin( ent, tr.endpos );
2035 }
2036 }
2037
2038 ent->spawnflags = team;
2039
2040 trap_LinkEntity( ent );
2041
2042 return ent;
2043 }
2044
2045 /*QUAKED team_redobelisk (1 0 0) (-16 -16 0) (16 16 8)
2046 */
2047 void SP_team_redobelisk( gentity_t *ent ) {
2048 gentity_t *obelisk;
2049
2050 if ( g_gametype.integer <= GT_TEAM || g_ffa_gt>0) {
2051 G_FreeEntity(ent);
2052 return;
2053 }
2054 ent->s.eType = ET_TEAM;
2055 if ( g_gametype.integer == GT_OBELISK ) {
2056 obelisk = SpawnObelisk( ent->s.origin, TEAM_RED, ent->spawnflags );
2057 obelisk->activator = ent;
2058 // initial obelisk health value
2059 ent->s.modelindex2 = 0xff;
2060 ent->s.frame = 0;
2061 }
2062 if ( g_gametype.integer == GT_HARVESTER ) {
2063 obelisk = SpawnObelisk( ent->s.origin, TEAM_RED, ent->spawnflags );
2064 obelisk->activator = ent;
2065 }
2066 ent->s.modelindex = TEAM_RED;
2067 trap_LinkEntity(ent);
2068 }
2069
2070 /*QUAKED team_blueobelisk (0 0 1) (-16 -16 0) (16 16 88)
2071 */
2072 void SP_team_blueobelisk( gentity_t *ent ) {
2073 gentity_t *obelisk;
2074
2075 if ( g_gametype.integer <= GT_TEAM || g_ffa_gt>0) {
2076 G_FreeEntity(ent);
2077 return;
2078 }
2079 ent->s.eType = ET_TEAM;
2080 if ( g_gametype.integer == GT_OBELISK ) {
2081 obelisk = SpawnObelisk( ent->s.origin, TEAM_BLUE, ent->spawnflags );
2082 obelisk->activator = ent;
2083 // initial obelisk health value
2084 ent->s.modelindex2 = 0xff;
2085 ent->s.frame = 0;
2086 }
2087 if ( g_gametype.integer == GT_HARVESTER ) {
2088 obelisk = SpawnObelisk( ent->s.origin, TEAM_BLUE, ent->spawnflags );
2089 obelisk->activator = ent;
2090 }
2091 ent->s.modelindex = TEAM_BLUE;
2092 trap_LinkEntity(ent);
2093 }
2094
2095 /*QUAKED team_neutralobelisk (0 0 1) (-16 -16 0) (16 16 88)
2096 */
2097 void SP_team_neutralobelisk( gentity_t *ent ) {
2098 if ( g_gametype.integer != GT_1FCTF && g_gametype.integer != GT_HARVESTER ) {
2099 G_FreeEntity(ent);
2100 return;
2101 }
2102 ent->s.eType = ET_TEAM;
2103 if ( g_gametype.integer == GT_HARVESTER) {
2104 neutralObelisk = SpawnObelisk( ent->s.origin, TEAM_FREE, ent->spawnflags);
2105 neutralObelisk->spawnflags = TEAM_FREE;
2106 }
2107 ent->s.modelindex = TEAM_FREE;
2108 trap_LinkEntity(ent);
2109 }
2110
2111
2112 /*
2113 ================
2114 CheckObeliskAttack
2115 ================
2116 */
2117 qboolean CheckObeliskAttack( gentity_t *obelisk, gentity_t *attacker ) {
2118 gentity_t *te;
2119
2120 // if this really is an obelisk
2121 if( obelisk->die != ObeliskDie ) {
2122 return qfalse;
2123 }
2124
2125 // if the attacker is a client
2126 if( !attacker->client ) {
2127 return qfalse;
2128 }
2129
2130 // if the obelisk is on the same team as the attacker then don't hurt it
2131 if( obelisk->spawnflags == attacker->client->sess.sessionTeam ) {
2132 return qtrue;
2133 }
2134
2135 // obelisk may be hurt
2136
2137 // if not played any sounds recently
2138 if ((obelisk->spawnflags == TEAM_RED &&
2139 teamgame.redObeliskAttackedTime < level.time - OVERLOAD_ATTACK_BASE_SOUND_TIME) ||
2140 (obelisk->spawnflags == TEAM_BLUE &&
2141 teamgame.blueObeliskAttackedTime < level.time - OVERLOAD_ATTACK_BASE_SOUND_TIME) ) {
2142
2143 // tell which obelisk is under attack
2144 te = G_TempEntity( obelisk->s.pos.trBase, EV_GLOBAL_TEAM_SOUND );
2145 if( obelisk->spawnflags == TEAM_RED ) {
2146 te->s.eventParm = GTS_REDOBELISK_ATTACKED;
2147 teamgame.redObeliskAttackedTime = level.time;
2148 }
2149 else {
2150 te->s.eventParm = GTS_BLUEOBELISK_ATTACKED;
2151 teamgame.blueObeliskAttackedTime = level.time;
2152 }
2153 te->r.svFlags |= SVF_BROADCAST;
2154 }
2155
2156 return qfalse;
2157 }
2158
2159 /*
2160 ================
2161 ShuffleTeams
2162 *Randomizes the teams based on a type of function and then restarts the map
2163 *Currently there is only one type so type is ignored. You can add total randomizaion or waighted randomization later.
2164 *
2165 *The function will split the teams like this:
2166 *1. Red team
2167 *2. Blue team
2168 *3. Blue team
2169 *4. Red team
2170 *5. Go to 1
2171 ================
2172 */
2173 void ShuffleTeams(void) {
2174 int i;
2175 int assignedClients=1, nextTeam=TEAM_RED;
2176
2177 if ( g_gametype.integer < GT_TEAM || g_ffa_gt==1)
2178 return; //Can only shuffle team games!
2179
2180 for( i=0;i < level.numConnectedClients; i++ ) {
2181 if( g_entities[ &level.clients[level.sortedClients[i]] - level.clients].r.svFlags & SVF_BOT)
2182 continue; //Don't sort bots... they are always equal
2183
2184 if(level.clients[level.sortedClients[i]].sess.sessionTeam==TEAM_RED || level.clients[level.sortedClients[i]].sess.sessionTeam==TEAM_BLUE ) {
2185 //For every second client we chenge team. But we do it a little of to make it slightly more fair
2186 if(assignedClients>1) {
2187 assignedClients=0;
2188 if(nextTeam == TEAM_RED)
2189 nextTeam = TEAM_BLUE;
2190 else
2191 nextTeam = TEAM_RED;
2192 }
2193
2194 //Set the team
2195 //We do not run all the logic because we shall run map_restart in a moment.
2196 level.clients[level.sortedClients[i]].sess.sessionTeam = nextTeam;
2197
2198 ClientUserinfoChanged( level.sortedClients[i] );
2199 ClientBegin( level.sortedClients[i] );
2200
2201 assignedClients++;
2202 }
2203 }
2204
2205 //Restart!
2206 trap_SendConsoleCommand( EXEC_APPEND, "map_restart 0\n" );
2207
2208 }
2209