Debian Codegraph @

code/game/g_team.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 #include "g_local.h"
25
26
27 typedef struct teamgame_s {
28 float last_flag_capture;
29 int last_capture_team;
30 flagStatus_t redStatus; // CTF
31 flagStatus_t blueStatus; // CTF
32 flagStatus_t flagStatus; // One Flag CTF
33 int redTakenTime;
34 int blueTakenTime;
35 int redObeliskAttackedTime;
36 int blueObeliskAttackedTime;
37 } teamgame_t;
38
39 teamgame_t teamgame;
40
41 gentity_t *neutralObelisk;
42
43 void Team_SetFlagStatus( int team, flagStatus_t status );
44
45 void Team_InitGame( void ) {
46 memset(&teamgame, 0, sizeof teamgame);
47
48 switch( g_gametype.integer ) {
49 case GT_CTF:
50 teamgame.redStatus = -1; // Invalid to force update
51 Team_SetFlagStatus( TEAM_RED, FLAG_ATBASE );
52 teamgame.blueStatus = -1; // Invalid to force update
53 Team_SetFlagStatus( TEAM_BLUE, FLAG_ATBASE );
54 break;
55 #ifdef MISSIONPACK
56 case GT_1FCTF:
57 teamgame.flagStatus = -1; // Invalid to force update
58 Team_SetFlagStatus( TEAM_FREE, FLAG_ATBASE );
59 break;
60 #endif
61 default:
62 break;
63 }
64 }
65
66 int OtherTeam(int team) {
67 if (team==TEAM_RED)
68 return TEAM_BLUE;
69 else if (team==TEAM_BLUE)
70 return TEAM_RED;
71 return team;
72 }
73
74 const char *TeamName(int team) {
75 if (team==TEAM_RED)
76 return "RED";
77 else if (team==TEAM_BLUE)
78 return "BLUE";
79 else if (team==TEAM_SPECTATOR)
80 return "SPECTATOR";
81 return "FREE";
82 }
83
84 const char *TeamColorString(int team) {
85 if (team==TEAM_RED)
86 return S_COLOR_RED;
87 else if (team==TEAM_BLUE)
88 return S_COLOR_BLUE;
89 else if (team==TEAM_SPECTATOR)
90 return S_COLOR_YELLOW;
91 return S_COLOR_WHITE;
92 }
93
94 // NULL for everyone
95 static Q_PRINTF_FUNC(2, 3) void QDECL PrintMsg( gentity_t *ent, const char *fmt, ... ) {
96 char msg[1024];
97 va_list argptr;
98 char *p;
99
100 va_start (argptr,fmt);
101 if (Q_vsnprintf (msg, sizeof(msg), fmt, argptr) >= sizeof(msg)) {
102 G_Error ( "PrintMsg overrun" );
103 }
104 va_end (argptr);
105
106 // double quotes are bad
107 while ((p = strchr(msg, '"')) != NULL)
108 *p = '\'';
109
110 trap_SendServerCommand ( ( (ent == NULL) ? -1 : ent-g_entities ), va("print \"%s\"", msg ));
111 }
112
113 /*
114 ==============
115 AddTeamScore
116
117 used for gametype > GT_TEAM
118 for gametype GT_TEAM the level.teamScores is updated in AddScore in g_combat.c
119 ==============
120 */
121 void AddTeamScore(vec3_t origin, int team, int score) {
122 gentity_t *te;
123
124 te = G_TempEntity(origin, EV_GLOBAL_TEAM_SOUND );
125 te->r.svFlags |= SVF_BROADCAST;
126
127 if ( team == TEAM_RED ) {
128 if ( level.teamScores[ TEAM_RED ] + score == level.teamScores[ TEAM_BLUE ] ) {
129 //teams are tied sound
130 te->s.eventParm = GTS_TEAMS_ARE_TIED;
131 }
132 else if ( level.teamScores[ TEAM_RED ] <= level.teamScores[ TEAM_BLUE ] &&
133 level.teamScores[ TEAM_RED ] + score > level.teamScores[ TEAM_BLUE ]) {
134 // red took the lead sound
135 te->s.eventParm = GTS_REDTEAM_TOOK_LEAD;
136 }
137 else {
138 // red scored sound
139 te->s.eventParm = GTS_REDTEAM_SCORED;
140 }
141 }
142 else {
143 if ( level.teamScores[ TEAM_BLUE ] + score == level.teamScores[ TEAM_RED ] ) {
144 //teams are tied sound
145 te->s.eventParm = GTS_TEAMS_ARE_TIED;
146 }
147 else if ( level.teamScores[ TEAM_BLUE ] <= level.teamScores[ TEAM_RED ] &&
148 level.teamScores[ TEAM_BLUE ] + score > level.teamScores[ TEAM_RED ]) {
149 // blue took the lead sound
150 te->s.eventParm = GTS_BLUETEAM_TOOK_LEAD;
151 }
152 else {
153 // blue scored sound
154 te->s.eventParm = GTS_BLUETEAM_SCORED;
155 }
156 }
157 level.teamScores[ team ] += score;
158 }
159
160 /*
161 ==============
162 OnSameTeam
163 ==============
164 */
165 qboolean OnSameTeam( gentity_t *ent1, gentity_t *ent2 ) {
166 if ( !ent1->client || !ent2->client ) {
167 return qfalse;
168 }
169
170 if ( g_gametype.integer < GT_TEAM ) {
171 return qfalse;
172 }
173
174 if ( ent1->client->sess.sessionTeam == ent2->client->sess.sessionTeam ) {
175 return qtrue;
176 }
177
178 return qfalse;
179 }
180
181
182 static char ctfFlagStatusRemap[] = { '0', '1', '*', '*', '2' };
183 static char oneFlagStatusRemap[] = { '0', '1', '2', '3', '4' };
184
185 void Team_SetFlagStatus( int team, flagStatus_t status ) {
186 qboolean modified = qfalse;
187
188 switch( team ) {
189 case TEAM_RED: // CTF
190 if( teamgame.redStatus != status ) {
191 teamgame.redStatus = status;
192 modified = qtrue;
193 }
194 break;
195
196 case TEAM_BLUE: // CTF
197 if( teamgame.blueStatus != status ) {
198 teamgame.blueStatus = status;
199 modified = qtrue;
200 }
201 break;
202
203 case TEAM_FREE: // One Flag CTF
204 if( teamgame.flagStatus != status ) {
205 teamgame.flagStatus = status;
206 modified = qtrue;
207 }
208 break;
209 }
210
211 if( modified ) {
212 char st[4];
213
214 if( g_gametype.integer == GT_CTF ) {
215 st[0] = ctfFlagStatusRemap[teamgame.redStatus];
216 st[1] = ctfFlagStatusRemap[teamgame.blueStatus];
217 st[2] = 0;
218 }
219 else { // GT_1FCTF
220 st[0] = oneFlagStatusRemap[teamgame.flagStatus];
221 st[1] = 0;
222 }
223
224 trap_SetConfigstring( CS_FLAGSTATUS, st );
225 }
226 }
227
228 void Team_CheckDroppedItem( gentity_t *dropped ) {
229 if( dropped->item->giTag == PW_REDFLAG ) {
230 Team_SetFlagStatus( TEAM_RED, FLAG_DROPPED );
231 }
232 else if( dropped->item->giTag == PW_BLUEFLAG ) {
233 Team_SetFlagStatus( TEAM_BLUE, FLAG_DROPPED );
234 }
235 else if( dropped->item->giTag == PW_NEUTRALFLAG ) {
236 Team_SetFlagStatus( TEAM_FREE, FLAG_DROPPED );
237 }
238 }
239
240 /*
241 ================
242 Team_ForceGesture
243 ================
244 */
245 void Team_ForceGesture(int team) {
246 int i;
247 gentity_t *ent;
248
249 for (i = 0; i < MAX_CLIENTS; i++) {
250 ent = &g_entities[i];
251 if (!ent->inuse)
252 continue;
253 if (!ent->client)
254 continue;
255 if (ent->client->sess.sessionTeam != team)
256 continue;
257 //
258 ent->flags |= FL_FORCE_GESTURE;
259 }
260 }
261
262 /*
263 ================
264 Team_FragBonuses
265
266 Calculate the bonuses for flag defense, flag carrier defense, etc.
267 Note that bonuses are not cumulative. You get one, they are in importance
268 order.
269 ================
270 */
271 void Team_FragBonuses(gentity_t *targ, gentity_t *inflictor, gentity_t *attacker)
272 {
273 int i;
274 gentity_t *ent;
275 int flag_pw, enemy_flag_pw;
276 int otherteam;
277 int tokens;
278 gentity_t *flag, *carrier = NULL;
279 char *c;
280 vec3_t v1, v2;
281 int team;
282
283 // no bonus for fragging yourself or team mates
284 if (!targ->client || !attacker->client || targ == attacker || OnSameTeam(targ, attacker))
285 return;
286
287 team = targ->client->sess.sessionTeam;
288 otherteam = OtherTeam(targ->client->sess.sessionTeam);
289 if (otherteam < 0)
290 return; // whoever died isn't on a team
291
292 // same team, if the flag at base, check to he has the enemy flag
293 if (team == TEAM_RED) {
294 flag_pw = PW_REDFLAG;
295 enemy_flag_pw = PW_BLUEFLAG;
296 } else {
297 flag_pw = PW_BLUEFLAG;
298 enemy_flag_pw = PW_REDFLAG;
299 }
300
301 #ifdef MISSIONPACK
302 if (g_gametype.integer == GT_1FCTF) {
303 flag_pw = PW_NEUTRALFLAG;
304 enemy_flag_pw = PW_NEUTRALFLAG;
305 }
306 #endif
307
308 // did the attacker frag the flag carrier?
309 tokens = 0;
310 #ifdef MISSIONPACK
311 if( g_gametype.integer == GT_HARVESTER ) {
312 tokens = targ->client->ps.generic1;
313 }
314 #endif
315 if (targ->client->ps.powerups[enemy_flag_pw]) {
316 attacker->client->pers.teamState.lastfraggedcarrier = level.time;
317 AddScore(attacker, targ->r.currentOrigin, CTF_FRAG_CARRIER_BONUS);
318 attacker->client->pers.teamState.fragcarrier++;
319 PrintMsg(NULL, "%s" S_COLOR_WHITE " fragged %s's flag carrier!\n",
320 attacker->client->pers.netname, TeamName(team));
321
322 // the target had the flag, clear the hurt carrier
323 // field on the other team
324 for (i = 0; i < g_maxclients.integer; i++) {
325 ent = g_entities + i;
326 if (ent->inuse && ent->client->sess.sessionTeam == otherteam)
327 ent->client->pers.teamState.lasthurtcarrier = 0;
328 }
329 return;
330 }
331
332 // did the attacker frag a head carrier? other->client->ps.generic1
333 if (tokens) {
334 attacker->client->pers.teamState.lastfraggedcarrier = level.time;
335 AddScore(attacker, targ->r.currentOrigin, CTF_FRAG_CARRIER_BONUS * tokens * tokens);
336 attacker->client->pers.teamState.fragcarrier++;
337 PrintMsg(NULL, "%s" S_COLOR_WHITE " fragged %s's skull carrier!\n",
338 attacker->client->pers.netname, TeamName(team));
339
340 // the target had the flag, clear the hurt carrier
341 // field on the other team
342 for (i = 0; i < g_maxclients.integer; i++) {
343 ent = g_entities + i;
344 if (ent->inuse && ent->client->sess.sessionTeam == otherteam)
345 ent->client->pers.teamState.lasthurtcarrier = 0;
346 }
347 return;
348 }
349
350 if (targ->client->pers.teamState.lasthurtcarrier &&
351 level.time - targ->client->pers.teamState.lasthurtcarrier < CTF_CARRIER_DANGER_PROTECT_TIMEOUT &&
352 !attacker->client->ps.powerups[flag_pw]) {
353 // attacker is on the same team as the flag carrier and
354 // fragged a guy who hurt our flag carrier
355 AddScore(attacker, targ->r.currentOrigin, CTF_CARRIER_DANGER_PROTECT_BONUS);
356
357 attacker->client->pers.teamState.carrierdefense++;
358 targ->client->pers.teamState.lasthurtcarrier = 0;
359
360 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
361 // add the sprite over the player's head
362 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
363 attacker->client->ps.eFlags |= EF_AWARD_DEFEND;
364 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
365
366 return;
367 }
368
369 // flag and flag carrier area defense bonuses
370
371 // we have to find the flag and carrier entities
372
373 #ifdef MISSIONPACK
374 if( g_gametype.integer == GT_OBELISK ) {
375 // find the team obelisk
376 switch (attacker->client->sess.sessionTeam) {
377 case TEAM_RED:
378 c = "team_redobelisk";
379 break;
380 case TEAM_BLUE:
381 c = "team_blueobelisk";
382 break;
383 default:
384 return;
385 }
386
387 } else if (g_gametype.integer == GT_HARVESTER ) {
388 // find the center obelisk
389 c = "team_neutralobelisk";
390 } else {
391 #endif
392 // find the flag
393 switch (attacker->client->sess.sessionTeam) {
394 case TEAM_RED:
395 c = "team_CTF_redflag";
396 break;
397 case TEAM_BLUE:
398 c = "team_CTF_blueflag";
399 break;
400 default:
401 return;
402 }
403 // find attacker's team's flag carrier
404 for (i = 0; i < g_maxclients.integer; i++) {
405 carrier = g_entities + i;
406 if (carrier->inuse && carrier->client->ps.powerups[flag_pw])
407 break;
408 carrier = NULL;
409 }
410 #ifdef MISSIONPACK
411 }
412 #endif
413 flag = NULL;
414 while ((flag = G_Find (flag, FOFS(classname), c)) != NULL) {
415 if (!(flag->flags & FL_DROPPED_ITEM))
416 break;
417 }
418
419 if (!flag)
420 return; // can't find attacker's flag
421
422 // ok we have the attackers flag and a pointer to the carrier
423
424 // check to see if we are defending the base's flag
425 VectorSubtract(targ->r.currentOrigin, flag->r.currentOrigin, v1);
426 VectorSubtract(attacker->r.currentOrigin, flag->r.currentOrigin, v2);
427
428 if ( ( ( VectorLength(v1) < CTF_TARGET_PROTECT_RADIUS &&
429 trap_InPVS(flag->r.currentOrigin, targ->r.currentOrigin ) ) ||
430 ( VectorLength(v2) < CTF_TARGET_PROTECT_RADIUS &&
431 trap_InPVS(flag->r.currentOrigin, attacker->r.currentOrigin ) ) ) &&
432 attacker->client->sess.sessionTeam != targ->client->sess.sessionTeam) {
433
434 // we defended the base flag
435 AddScore(attacker, targ->r.currentOrigin, CTF_FLAG_DEFENSE_BONUS);
436 attacker->client->pers.teamState.basedefense++;
437
438 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
439 // add the sprite over the player's head
440 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
441 attacker->client->ps.eFlags |= EF_AWARD_DEFEND;
442 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
443
444 return;
445 }
446
447 if (carrier && carrier != attacker) {
448 VectorSubtract(targ->r.currentOrigin, carrier->r.currentOrigin, v1);
449 VectorSubtract(attacker->r.currentOrigin, carrier->r.currentOrigin, v2);
450
451 if ( ( ( VectorLength(v1) < CTF_ATTACKER_PROTECT_RADIUS &&
452 trap_InPVS(carrier->r.currentOrigin, targ->r.currentOrigin ) ) ||
453 ( VectorLength(v2) < CTF_ATTACKER_PROTECT_RADIUS &&
454 trap_InPVS(carrier->r.currentOrigin, attacker->r.currentOrigin ) ) ) &&
455 attacker->client->sess.sessionTeam != targ->client->sess.sessionTeam) {
456 AddScore(attacker, targ->r.currentOrigin, CTF_CARRIER_PROTECT_BONUS);
457 attacker->client->pers.teamState.carrierdefense++;
458
459 attacker->client->ps.persistant[PERS_DEFEND_COUNT]++;
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 }
469
470 /*
471 ================
472 Team_CheckHurtCarrier
473
474 Check to see if attacker hurt the flag carrier. Needed when handing out bonuses for assistance to flag
475 carrier defense.
476 ================
477 */
478 void Team_CheckHurtCarrier(gentity_t *targ, gentity_t *attacker)
479 {
480 int flag_pw;
481
482 if (!targ->client || !attacker->client)
483 return;
484
485 if (targ->client->sess.sessionTeam == TEAM_RED)
486 flag_pw = PW_BLUEFLAG;
487 else
488 flag_pw = PW_REDFLAG;
489
490 #ifdef MISSIONPACK
491 if (g_gametype.integer == GT_1FCTF) {
492 flag_pw = PW_NEUTRALFLAG;
493 }
494 #endif
495
496 // flags
497 if (targ->client->ps.powerups[flag_pw] &&
498 targ->client->sess.sessionTeam != attacker->client->sess.sessionTeam)
499 attacker->client->pers.teamState.lasthurtcarrier = level.time;
500
501 // skulls
502 if (targ->client->ps.generic1 &&
503 targ->client->sess.sessionTeam != attacker->client->sess.sessionTeam)
504 attacker->client->pers.teamState.lasthurtcarrier = level.time;
505 }
506
507
508 gentity_t *Team_ResetFlag( int team ) {
509 char *c;
510 gentity_t *ent, *rent = NULL;
511
512 switch (team) {
513 case TEAM_RED:
514 c = "team_CTF_redflag";
515 break;
516 case TEAM_BLUE:
517 c = "team_CTF_blueflag";
518 break;
519 case TEAM_FREE:
520 c = "team_CTF_neutralflag";
521 break;
522 default:
523 return NULL;
524 }
525
526 ent = NULL;
527 while ((ent = G_Find (ent, FOFS(classname), c)) != NULL) {
528 if (ent->flags & FL_DROPPED_ITEM)
529 G_FreeEntity(ent);
530 else {
531 rent = ent;
532 RespawnItem(ent);
533 }
534 }
535
536 Team_SetFlagStatus( team, FLAG_ATBASE );
537
538 return rent;
539 }
540
541 void Team_ResetFlags( void ) {
542 if( g_gametype.integer == GT_CTF ) {
543 Team_ResetFlag( TEAM_RED );
544 Team_ResetFlag( TEAM_BLUE );
545 }
546 #ifdef MISSIONPACK
547 else if( g_gametype.integer == GT_1FCTF ) {
548 Team_ResetFlag( TEAM_FREE );
549 }
550 #endif
551 }
552
553 void Team_ReturnFlagSound( gentity_t *ent, int team ) {
554 gentity_t *te;
555
556 if (ent == NULL) {
557 G_Printf ("Warning: NULL passed to Team_ReturnFlagSound\n");
558 return;
559 }
560
561 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_TEAM_SOUND );
562 if( team == TEAM_BLUE ) {
563 te->s.eventParm = GTS_RED_RETURN;
564 }
565 else {
566 te->s.eventParm = GTS_BLUE_RETURN;
567 }
568 te->r.svFlags |= SVF_BROADCAST;
569 }
570
571 void Team_TakeFlagSound( gentity_t *ent, int team ) {
572 gentity_t *te;
573
574 if (ent == NULL) {
575 G_Printf ("Warning: NULL passed to Team_TakeFlagSound\n");
576 return;
577 }
578
579 // only play sound when the flag was at the base
580 // or not picked up the last 10 seconds
581 switch(team) {
582 case TEAM_RED:
583 if( teamgame.blueStatus != FLAG_ATBASE ) {
584 if (teamgame.blueTakenTime > level.time - 10000)
585 return;
586 }
587 teamgame.blueTakenTime = level.time;
588 break;
589
590 case TEAM_BLUE: // CTF
591 if( teamgame.redStatus != FLAG_ATBASE ) {
592 if (teamgame.redTakenTime > level.time - 10000)
593 return;
594 }
595 teamgame.redTakenTime = level.time;
596 break;
597 }
598
599 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_TEAM_SOUND );
600 if( team == TEAM_BLUE ) {
601 te->s.eventParm = GTS_RED_TAKEN;
602 }
603 else {
604 te->s.eventParm = GTS_BLUE_TAKEN;
605 }
606 te->r.svFlags |= SVF_BROADCAST;
607 }
608
609 void Team_CaptureFlagSound( gentity_t *ent, int team ) {
610 gentity_t *te;
611
612 if (ent == NULL) {
613 G_Printf ("Warning: NULL passed to Team_CaptureFlagSound\n");
614 return;
615 }
616
617 te = G_TempEntity( ent->s.pos.trBase, EV_GLOBAL_TEAM_SOUND );
618 if( team == TEAM_BLUE ) {
619 te->s.eventParm = GTS_BLUE_CAPTURE;
620 }
621 else {
622 te->s.eventParm = GTS_RED_CAPTURE;
623 }
624 te->r.svFlags |= SVF_BROADCAST;
625 }
626
627 void Team_ReturnFlag( int team ) {
628 Team_ReturnFlagSound(Team_ResetFlag(team), team);
629 if( team == TEAM_FREE ) {
630 PrintMsg(NULL, "The flag has returned!\n" );
631 }
632 else {
633 PrintMsg(NULL, "The %s flag has returned!\n", TeamName(team));
634 }
635 }
636
637 void Team_FreeEntity( gentity_t *ent ) {
638 if( ent->item->giTag == PW_REDFLAG ) {
639 Team_ReturnFlag( TEAM_RED );
640 }
641 else if( ent->item->giTag == PW_BLUEFLAG ) {
642 Team_ReturnFlag( TEAM_BLUE );
643 }
644 else if( ent->item->giTag == PW_NEUTRALFLAG ) {
645 Team_ReturnFlag( TEAM_FREE );
646 }
647 }
648
649 /*
650 ==============
651 Team_DroppedFlagThink
652
653 Automatically set in Launch_Item if the item is one of the flags
654
655 Flags are unique in that if they are dropped, the base flag must be respawned when they time out
656 ==============
657 */
658 void Team_DroppedFlagThink(gentity_t *ent) {
659 int team = TEAM_FREE;
660
661 if( ent->item->giTag == PW_REDFLAG ) {
662 team = TEAM_RED;
663 }
664 else if( ent->item->giTag == PW_BLUEFLAG ) {
665 team = TEAM_BLUE;
666 }
667 else if( ent->item->giTag == PW_NEUTRALFLAG ) {
668 team = TEAM_FREE;
669 }
670
671 Team_ReturnFlagSound( Team_ResetFlag( team ), team );
672 // Reset Flag will delete this entity
673 }
674
675
676 /*
677 ==============
678 Team_DroppedFlagThink
679 ==============
680 */
681 int Team_TouchOurFlag( gentity_t *ent, gentity_t *other, int team ) {
682 int i;
683 gentity_t *player;
684 gclient_t *cl = other->client;
685 int enemy_flag;
686
687 #ifdef MISSIONPACK
688 if( g_gametype.integer == GT_1FCTF ) {
689 enemy_flag = PW_NEUTRALFLAG;
690 }
691 else {
692 #endif
693 if (cl->sess.sessionTeam == TEAM_RED) {
694 enemy_flag = PW_BLUEFLAG;
695 } else {
696 enemy_flag = PW_REDFLAG;
697 }
698
699 if ( ent->flags & FL_DROPPED_ITEM ) {
700 // hey, it's not home. return it by teleporting it back
701 PrintMsg( NULL, "%s" S_COLOR_WHITE " returned the %s flag!\n",
702 cl->pers.netname, TeamName(team));
703 AddScore(other, ent->r.currentOrigin, CTF_RECOVERY_BONUS);
704 other->client->pers.teamState.flagrecovery++;
705 other->client->pers.teamState.lastreturnedflag = level.time;
706 //ResetFlag will remove this entity! We must return zero
707 Team_ReturnFlagSound(Team_ResetFlag(team), team);
708 return 0;
709 }
710 #ifdef MISSIONPACK
711 }
712 #endif
713
714 // the flag is at home base. if the player has the enemy
715 // flag, he's just won!
716 if (!cl->ps.powerups[enemy_flag])
717 return 0; // We don't have the flag
718 #ifdef MISSIONPACK
719 if( g_gametype.integer == GT_1FCTF ) {
720 PrintMsg( NULL, "%s" S_COLOR_WHITE " captured the flag!\n", cl->pers.netname );
721 }
722 else {
723 #endif
724 PrintMsg( NULL, "%s" S_COLOR_WHITE " captured the %s flag!\n", cl->pers.netname, TeamName(OtherTeam(team)));
725 #ifdef MISSIONPACK
726 }
727 #endif
728
729 cl->ps.powerups[enemy_flag] = 0;
730
731 teamgame.last_flag_capture = level.time;
732 teamgame.last_capture_team = team;
733
734 // Increase the team's score
735 AddTeamScore(ent->s.pos.trBase, other->client->sess.sessionTeam, 1);
736 Team_ForceGesture(other->client->sess.sessionTeam);
737
738 other->client->pers.teamState.captures++;
739 // add the sprite over the player's head
740 other->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
741 other->client->ps.eFlags |= EF_AWARD_CAP;
742 other->client->rewardTime = level.time + REWARD_SPRITE_TIME;
743 other->client->ps.persistant[PERS_CAPTURES]++;
744
745 // other gets another 10 frag bonus
746 AddScore(other, ent->r.currentOrigin, CTF_CAPTURE_BONUS);
747
748 Team_CaptureFlagSound( ent, team );
749
750 // Ok, let's do the player loop, hand out the bonuses
751 for (i = 0; i < g_maxclients.integer; i++) {
752 player = &g_entities[i];
753
754 // also make sure we don't award assist bonuses to the flag carrier himself.
755 if (!player->inuse || player == other)
756 continue;
757
758 if (player->client->sess.sessionTeam !=
759 cl->sess.sessionTeam) {
760 player->client->pers.teamState.lasthurtcarrier = -5;
761 } else if (player->client->sess.sessionTeam ==
762 cl->sess.sessionTeam) {
763 #ifdef MISSIONPACK
764 AddScore(player, ent->r.currentOrigin, CTF_TEAM_BONUS);
765 #endif
766 // award extra points for capture assists
767 if (player->client->pers.teamState.lastreturnedflag +
768 CTF_RETURN_FLAG_ASSIST_TIMEOUT > level.time) {
769 AddScore (player, ent->r.currentOrigin, CTF_RETURN_FLAG_ASSIST_BONUS);
770 other->client->pers.teamState.assists++;
771
772 player->client->ps.persistant[PERS_ASSIST_COUNT]++;
773 // add the sprite over the player's head
774 player->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
775 player->client->ps.eFlags |= EF_AWARD_ASSIST;
776 player->client->rewardTime = level.time + REWARD_SPRITE_TIME;
777
778 }
779 if (player->client->pers.teamState.lastfraggedcarrier +
780 CTF_FRAG_CARRIER_ASSIST_TIMEOUT > level.time) {
781 AddScore(player, ent->r.currentOrigin, CTF_FRAG_CARRIER_ASSIST_BONUS);
782 other->client->pers.teamState.assists++;
783 player->client->ps.persistant[PERS_ASSIST_COUNT]++;
784 // add the sprite over the player's head
785 player->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
786 player->client->ps.eFlags |= EF_AWARD_ASSIST;
787 player->client->rewardTime = level.time + REWARD_SPRITE_TIME;
788 }
789 }
790 }
791 Team_ResetFlags();
792
793 CalculateRanks();
794
795 return 0; // Do not respawn this automatically
796 }
797
798 int Team_TouchEnemyFlag( gentity_t *ent, gentity_t *other, int team ) {
799 gclient_t *cl = other->client;
800
801 #ifdef MISSIONPACK
802 if( g_gametype.integer == GT_1FCTF ) {
803 PrintMsg (NULL, "%s" S_COLOR_WHITE " got the flag!\n", other->client->pers.netname );
804
805 cl->ps.powerups[PW_NEUTRALFLAG] = INT_MAX; // flags never expire
806
807 if( team == TEAM_RED ) {
808 Team_SetFlagStatus( TEAM_FREE, FLAG_TAKEN_RED );
809 }
810 else {
811 Team_SetFlagStatus( TEAM_FREE, FLAG_TAKEN_BLUE );
812 }
813 }
814 else{
815 #endif
816 PrintMsg (NULL, "%s" S_COLOR_WHITE " got the %s flag!\n",
817 other->client->pers.netname, TeamName(team));
818
819 if (team == TEAM_RED)
820 cl->ps.powerups[PW_REDFLAG] = INT_MAX; // flags never expire
821 else
822 cl->ps.powerups[PW_BLUEFLAG] = INT_MAX; // flags never expire
823
824 Team_SetFlagStatus( team, FLAG_TAKEN );
825 #ifdef MISSIONPACK
826 }
827
828 AddScore(other, ent->r.currentOrigin, CTF_FLAG_BONUS);
829 #endif
830 cl->pers.teamState.flagsince = level.time;
831 Team_TakeFlagSound( ent, team );
832
833 return -1; // Do not respawn this automatically, but do delete it if it was FL_DROPPED
834 }
835
836 int Pickup_Team( gentity_t *ent, gentity_t *other ) {
837 int team;
838 gclient_t *cl = other->client;
839
840 #ifdef MISSIONPACK
841 if( g_gametype.integer == GT_OBELISK ) {
842 // there are no team items that can be picked up in obelisk
843 G_FreeEntity( ent );
844 return 0;
845 }
846
847 if( g_gametype.integer == GT_HARVESTER ) {
848 // the only team items that can be picked up in harvester are the cubes
849 if( ent->spawnflags != cl->sess.sessionTeam ) {
850 cl->ps.generic1 += 1;
851 }
852 G_FreeEntity( ent );
853 return 0;
854 }
855 #endif
856 // figure out what team this flag is
857 if( strcmp(ent->classname, "team_CTF_redflag") == 0 ) {
858 team = TEAM_RED;
859 }
860 else if( strcmp(ent->classname, "team_CTF_blueflag") == 0 ) {
861 team = TEAM_BLUE;
862 }
863 #ifdef MISSIONPACK
864 else if( strcmp(ent->classname, "team_CTF_neutralflag") == 0 ) {
865 team = TEAM_FREE;
866 }
867 #endif
868 else {
869 PrintMsg ( other, "Don't know what team the flag is on.\n");
870 return 0;
871 }
872 #ifdef MISSIONPACK
873 if( g_gametype.integer == GT_1FCTF ) {
874 if( team == TEAM_FREE ) {
875 return Team_TouchEnemyFlag( ent, other, cl->sess.sessionTeam );
876 }
877 if( team != cl->sess.sessionTeam) {
878 return Team_TouchOurFlag( ent, other, cl->sess.sessionTeam );
879 }
880 return 0;
881 }
882 #endif
883 // GT_CTF
884 if( team == cl->sess.sessionTeam) {
885 return Team_TouchOurFlag( ent, other, team );
886 }
887 return Team_TouchEnemyFlag( ent, other, team );
888 }
889
890 /*
891 ===========
892 Team_GetLocation
893
894 Report a location for the player. Uses placed nearby target_location entities
895 ============
896 */
897 gentity_t *Team_GetLocation(gentity_t *ent)
898 {
899 gentity_t *eloc, *best;
900 float bestlen, len;
901 vec3_t origin;
902
903 best = NULL;
904 bestlen = 3*8192.0*8192.0;
905
906 VectorCopy( ent->r.currentOrigin, origin );
907
908 for (eloc = level.locationHead; eloc; eloc = eloc->nextTrain) {
909 len = ( origin[0] - eloc->r.currentOrigin[0] ) * ( origin[0] - eloc->r.currentOrigin[0] )
910 + ( origin[1] - eloc->r.currentOrigin[1] ) * ( origin[1] - eloc->r.currentOrigin[1] )
911 + ( origin[2] - eloc->r.currentOrigin[2] ) * ( origin[2] - eloc->r.currentOrigin[2] );
912
913 if ( len > bestlen ) {
914 continue;
915 }
916
917 if ( !trap_InPVS( origin, eloc->r.currentOrigin ) ) {
918 continue;
919 }
920
921 bestlen = len;
922 best = eloc;
923 }
924
925 return best;
926 }
927
928
929 /*
930 ===========
931 Team_GetLocation
932
933 Report a location for the player. Uses placed nearby target_location entities
934 ============
935 */
936 qboolean Team_GetLocationMsg(gentity_t *ent, char *loc, int loclen)
937 {
938 gentity_t *best;
939
940 best = Team_GetLocation( ent );
941
942 if (!best)
943 return qfalse;
944
945 if (best->count) {
946 if (best->count < 0)
947 best->count = 0;
948 if (best->count > 7)
949 best->count = 7;
950 Com_sprintf(loc, loclen, "%c%c%s" S_COLOR_WHITE, Q_COLOR_ESCAPE, best->count + '0', best->message );
951 } else
952 Com_sprintf(loc, loclen, "%s", best->message);
953
954 return qtrue;
955 }
956
957
958 /*---------------------------------------------------------------------------*/
959
960 /*
961 ================
962 SelectRandomTeamSpawnPoint
963
964 go to a random point that doesn't telefrag
965 ================
966 */
967 #define MAX_TEAM_SPAWN_POINTS 32
968 gentity_t *SelectRandomTeamSpawnPoint( int teamstate, team_t team ) {
969 gentity_t *spot;
970 int count;
971 int selection;
972 gentity_t *spots[MAX_TEAM_SPAWN_POINTS];
973 char *classname;
974
975 if (teamstate == TEAM_BEGIN) {
976 if (team == TEAM_RED)
977 classname = "team_CTF_redplayer";
978 else if (team == TEAM_BLUE)
979 classname = "team_CTF_blueplayer";
980 else
981 return NULL;
982 } else {
983 if (team == TEAM_RED)
984 classname = "team_CTF_redspawn";
985 else if (team == TEAM_BLUE)
986 classname = "team_CTF_bluespawn";
987 else
988 return NULL;
989 }
990 count = 0;
991
992 spot = NULL;
993
994 while ((spot = G_Find (spot, FOFS(classname), classname)) != NULL) {
995 if ( SpotWouldTelefrag( spot ) ) {
996 continue;
997 }
998 spots[ count ] = spot;
999 if (++count == MAX_TEAM_SPAWN_POINTS)
1000 break;
1001 }
1002
1003 if ( !count ) { // no spots that won't telefrag
1004 return G_Find( NULL, FOFS(classname), classname);
1005 }
1006
1007 selection = rand() % count;
1008 return spots[ selection ];
1009 }
1010
1011
1012 /*
1013 ===========
1014 SelectCTFSpawnPoint
1015
1016 ============
1017 */
1018 gentity_t *SelectCTFSpawnPoint ( team_t team, int teamstate, vec3_t origin, vec3_t angles, qboolean isbot ) {
1019 gentity_t *spot;
1020
1021 spot = SelectRandomTeamSpawnPoint ( teamstate, team );
1022
1023 if (!spot) {
1024 return SelectSpawnPoint( vec3_origin, origin, angles, isbot );
1025 }
1026
1027 VectorCopy (spot->s.origin, origin);
1028 origin[2] += 9;
1029 VectorCopy (spot->s.angles, angles);
1030
1031 return spot;
1032 }
1033
1034 /*---------------------------------------------------------------------------*/
1035
1036 static int QDECL SortClients( const void *a, const void *b ) {
1037 return *(int *)a - *(int *)b;
1038 }
1039
1040
1041 /*
1042 ==================
1043 TeamplayLocationsMessage
1044
1045 Format:
1046 clientNum location health armor weapon powerups
1047
1048 ==================
1049 */
1050 void TeamplayInfoMessage( gentity_t *ent ) {
1051 char entry[1024];
1052 char string[8192];
1053 int stringlength;
1054 int i, j;
1055 gentity_t *player;
1056 int cnt;
1057 int h, a;
1058 int clients[TEAM_MAXOVERLAY];
1059 int team;
1060
1061 if ( ! ent->client->pers.teamInfo )
1062 return;
1063
1064 // send team info to spectator for team of followed client
1065 if (ent->client->sess.sessionTeam == TEAM_SPECTATOR) {
1066 if ( ent->client->sess.spectatorState != SPECTATOR_FOLLOW
1067 || ent->client->sess.spectatorClient < 0 ) {
1068 return;
1069 }
1070 team = g_entities[ ent->client->sess.spectatorClient ].client->sess.sessionTeam;
1071 } else {
1072 team = ent->client->sess.sessionTeam;
1073 }
1074
1075 if (team != TEAM_RED && team != TEAM_BLUE) {
1076 return;
1077 }
1078
1079 // figure out what client should be on the display
1080 // we are limited to 8, but we want to use the top eight players
1081 // but in client order (so they don't keep changing position on the overlay)
1082 for (i = 0, cnt = 0; i < g_maxclients.integer && cnt < TEAM_MAXOVERLAY; i++) {
1083 player = g_entities + level.sortedClients[i];
1084 if (player->inuse && player->client->sess.sessionTeam == team ) {
1085 clients[cnt++] = level.sortedClients[i];
1086 }
1087 }
1088
1089 // We have the top eight players, sort them by clientNum
1090 qsort( clients, cnt, sizeof( clients[0] ), SortClients );
1091
1092 // send the latest information on all clients
1093 string[0] = 0;
1094 stringlength = 0;
1095
1096 for (i = 0, cnt = 0; i < g_maxclients.integer && cnt < TEAM_MAXOVERLAY; i++) {
1097 player = g_entities + i;
1098 if (player->inuse && player->client->sess.sessionTeam == team ) {
1099
1100 h = player->client->ps.stats[STAT_HEALTH];
1101 a = player->client->ps.stats[STAT_ARMOR];
1102 if (h < 0) h = 0;
1103 if (a < 0) a = 0;
1104
1105 Com_sprintf (entry, sizeof(entry),
1106 " %i %i %i %i %i %i",
1107 // level.sortedClients[i], player->client->pers.teamState.location, h, a,
1108 i, player->client->pers.teamState.location, h, a,
1109 player->client->ps.weapon, player->s.powerups);
1110 j = strlen(entry);
1111 if (stringlength + j >= sizeof(string))
1112 break;
1113 strcpy (string + stringlength, entry);
1114 stringlength += j;
1115 cnt++;
1116 }
1117 }
1118
1119 trap_SendServerCommand( ent-g_entities, va("tinfo %i %s", cnt, string) );
1120 }
1121
1122 void CheckTeamStatus(void) {
1123 int i;
1124 gentity_t *loc, *ent;
1125
1126 if (level.time - level.lastTeamLocationTime > TEAM_LOCATION_UPDATE_TIME) {
1127
1128 level.lastTeamLocationTime = level.time;
1129
1130 for (i = 0; i < g_maxclients.integer; i++) {
1131 ent = g_entities + i;
1132
1133 if ( ent->client->pers.connected != CON_CONNECTED ) {
1134 continue;
1135 }
1136
1137 if (ent->inuse && (ent->client->sess.sessionTeam == TEAM_RED || ent->client->sess.sessionTeam == TEAM_BLUE)) {
1138 loc = Team_GetLocation( ent );
1139 if (loc)
1140 ent->client->pers.teamState.location = loc->health;
1141 else
1142 ent->client->pers.teamState.location = 0;
1143 }
1144 }
1145
1146 for (i = 0; i < g_maxclients.integer; i++) {
1147 ent = g_entities + i;
1148
1149 if ( ent->client->pers.connected != CON_CONNECTED ) {
1150 continue;
1151 }
1152
1153 if (ent->inuse) {
1154 TeamplayInfoMessage( ent );
1155 }
1156 }
1157 }
1158 }
1159
1160 /*-----------------------------------------------------------------*/
1161
1162 /*QUAKED team_CTF_redplayer (1 0 0) (-16 -16 -16) (16 16 32)
1163 Only in CTF games. Red players spawn here at game start.
1164 */
1165 void SP_team_CTF_redplayer( gentity_t *ent ) {
1166 }
1167
1168
1169 /*QUAKED team_CTF_blueplayer (0 0 1) (-16 -16 -16) (16 16 32)
1170 Only in CTF games. Blue players spawn here at game start.
1171 */
1172 void SP_team_CTF_blueplayer( gentity_t *ent ) {
1173 }
1174
1175
1176 /*QUAKED team_CTF_redspawn (1 0 0) (-16 -16 -24) (16 16 32)
1177 potential spawning position for red team in CTF games.
1178 Targets will be fired when someone spawns in on them.
1179 */
1180 void SP_team_CTF_redspawn(gentity_t *ent) {
1181 }
1182
1183 /*QUAKED team_CTF_bluespawn (0 0 1) (-16 -16 -24) (16 16 32)
1184 potential spawning position for blue team in CTF games.
1185 Targets will be fired when someone spawns in on them.
1186 */
1187 void SP_team_CTF_bluespawn(gentity_t *ent) {
1188 }
1189
1190
1191 #ifdef MISSIONPACK
1192 /*
1193 ================
1194 Obelisks
1195 ================
1196 */
1197
1198 static void ObeliskRegen( gentity_t *self ) {
1199 self->nextthink = level.time + g_obeliskRegenPeriod.integer * 1000;
1200 if( self->health >= g_obeliskHealth.integer ) {
1201 return;
1202 }
1203
1204 G_AddEvent( self, EV_POWERUP_REGEN, 0 );
1205 self->health += g_obeliskRegenAmount.integer;
1206 if ( self->health > g_obeliskHealth.integer ) {
1207 self->health = g_obeliskHealth.integer;
1208 }
1209
1210 self->activator->s.modelindex2 = self->health * 0xff / g_obeliskHealth.integer;
1211 self->activator->s.frame = 0;
1212 }
1213
1214
1215 static void ObeliskRespawn( gentity_t *self ) {
1216 self->takedamage = qtrue;
1217 self->health = g_obeliskHealth.integer;
1218
1219 self->think = ObeliskRegen;
1220 self->nextthink = level.time + g_obeliskRegenPeriod.integer * 1000;
1221
1222 self->activator->s.frame = 0;
1223 }
1224
1225
1226 static void ObeliskDie( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int mod ) {
1227 int otherTeam;
1228
1229 otherTeam = OtherTeam( self->spawnflags );
1230 AddTeamScore(self->s.pos.trBase, otherTeam, 1);
1231 Team_ForceGesture(otherTeam);
1232
1233 CalculateRanks();
1234
1235 self->takedamage = qfalse;
1236 self->think = ObeliskRespawn;
1237 self->nextthink = level.time + g_obeliskRespawnDelay.integer * 1000;
1238
1239 self->activator->s.modelindex2 = 0xff;
1240 self->activator->s.frame = 2;
1241
1242 G_AddEvent( self->activator, EV_OBELISKEXPLODE, 0 );
1243
1244 AddScore(attacker, self->r.currentOrigin, CTF_CAPTURE_BONUS);
1245
1246 // add the sprite over the player's head
1247 attacker->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
1248 attacker->client->ps.eFlags |= EF_AWARD_CAP;
1249 attacker->client->rewardTime = level.time + REWARD_SPRITE_TIME;
1250 attacker->client->ps.persistant[PERS_CAPTURES]++;
1251
1252 teamgame.redObeliskAttackedTime = 0;
1253 teamgame.blueObeliskAttackedTime = 0;
1254 }
1255
1256
1257 static void ObeliskTouch( gentity_t *self, gentity_t *other, trace_t *trace ) {
1258 int tokens;
1259
1260 if ( !other->client ) {
1261 return;
1262 }
1263
1264 if ( OtherTeam(other->client->sess.sessionTeam) != self->spawnflags ) {
1265 return;
1266 }
1267
1268 tokens = other->client->ps.generic1;
1269 if( tokens <= 0 ) {
1270 return;
1271 }
1272
1273 PrintMsg(NULL, "%s" S_COLOR_WHITE " brought in %i %s.\n",
1274 other->client->pers.netname, tokens, ( tokens == 1 ) ? "skull" : "skulls" );
1275
1276 AddTeamScore(self->s.pos.trBase, other->client->sess.sessionTeam, tokens);
1277 Team_ForceGesture(other->client->sess.sessionTeam);
1278
1279 AddScore(other, self->r.currentOrigin, CTF_CAPTURE_BONUS*tokens);
1280
1281 // add the sprite over the player's head
1282 other->client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP );
1283 other->client->ps.eFlags |= EF_AWARD_CAP;
1284 other->client->rewardTime = level.time + REWARD_SPRITE_TIME;
1285 other->client->ps.persistant[PERS_CAPTURES] += tokens;
1286
1287 other->client->ps.generic1 = 0;
1288 CalculateRanks();
1289
1290 Team_CaptureFlagSound( self, self->spawnflags );
1291 }
1292
1293 static void ObeliskPain( gentity_t *self, gentity_t *attacker, int damage ) {
1294 int actualDamage = damage / 10;
1295 if (actualDamage <= 0) {
1296 actualDamage = 1;
1297 }
1298 self->activator->s.modelindex2 = self->health * 0xff / g_obeliskHealth.integer;
1299 if (!self->activator->s.frame) {
1300 G_AddEvent(self, EV_OBELISKPAIN, 0);
1301 }
1302 self->activator->s.frame = 1;
1303 AddScore(attacker, self->r.currentOrigin, actualDamage);
1304 }
1305
1306 // spawn invisible damagable obelisk entity / harvester base trigger.
1307 gentity_t *SpawnObelisk( vec3_t origin, vec3_t mins, vec3_t maxs, int team ) {
1308 gentity_t *ent;
1309
1310 ent = G_Spawn();
1311
1312 VectorCopy( origin, ent->s.origin );
1313 VectorCopy( origin, ent->s.pos.trBase );
1314 VectorCopy( origin, ent->r.currentOrigin );
1315
1316 VectorCopy( mins, ent->r.mins );
1317 VectorCopy( maxs, ent->r.maxs );
1318
1319 ent->s.eType = ET_GENERAL;
1320 ent->flags = FL_NO_KNOCKBACK;
1321
1322 if( g_gametype.integer == GT_OBELISK ) {
1323 ent->r.contents = CONTENTS_SOLID;
1324 ent->takedamage = qtrue;
1325 ent->health = g_obeliskHealth.integer;
1326 ent->die = ObeliskDie;
1327 ent->pain = ObeliskPain;
1328 ent->think = ObeliskRegen;
1329 ent->nextthink = level.time + g_obeliskRegenPeriod.integer * 1000;
1330 }
1331 if( g_gametype.integer == GT_HARVESTER ) {
1332 ent->r.contents = CONTENTS_TRIGGER;
1333 ent->touch = ObeliskTouch;
1334 }
1335
1336 G_SetOrigin( ent, ent->s.origin );
1337
1338 ent->spawnflags = team;
1339
1340 trap_LinkEntity( ent );
1341
1342 return ent;
1343 }
1344
1345 // setup entity for team base model / obelisk model.
1346 void ObeliskInit( gentity_t *ent ) {
1347 trace_t tr;
1348 vec3_t dest;
1349
1350 ent->s.eType = ET_TEAM;
1351
1352 VectorSet( ent->r.mins, -15, -15, 0 );
1353 VectorSet( ent->r.maxs, 15, 15, 87 );
1354
1355 if ( ent->spawnflags & 1 ) {
1356 // suspended
1357 G_SetOrigin( ent, ent->s.origin );
1358 } else {
1359 // mappers like to put them exactly on the floor, but being coplanar
1360 // will sometimes show up as starting in solid, so lif it up one pixel
1361 ent->s.origin[2] += 1;
1362
1363 // drop to floor
1364 VectorSet( dest, ent->s.origin[0], ent->s.origin[1], ent->s.origin[2] - 4096 );
1365 trap_Trace( &tr, ent->s.origin, ent->r.mins, ent->r.maxs, dest, ent->s.number, MASK_SOLID );
1366 if ( tr.startsolid ) {
1367 ent->s.origin[2] -= 1;
1368 G_Printf( "SpawnObelisk: %s startsolid at %s\n", ent->classname, vtos(ent->s.origin) );
1369
1370 ent->s.groundEntityNum = ENTITYNUM_NONE;
1371 G_SetOrigin( ent, ent->s.origin );
1372 }
1373 else {
1374 // allow to ride movers
1375 ent->s.groundEntityNum = tr.entityNum;
1376 G_SetOrigin( ent, tr.endpos );
1377 }
1378 }
1379 }
1380
1381 /*QUAKED team_redobelisk (1 0 0) (-16 -16 0) (16 16 8)
1382 */
1383 void SP_team_redobelisk( gentity_t *ent ) {
1384 gentity_t *obelisk;
1385
1386 if ( g_gametype.integer <= GT_TEAM ) {
1387 G_FreeEntity(ent);
1388 return;
1389 }
1390 ObeliskInit( ent );
1391 if ( g_gametype.integer == GT_OBELISK ) {
1392 obelisk = SpawnObelisk( ent->s.origin, ent->r.mins, ent->r.maxs, TEAM_RED );
1393 obelisk->activator = ent;
1394 // initial obelisk health value
1395 ent->s.modelindex2 = 0xff;
1396 ent->s.frame = 0;
1397 }
1398 if ( g_gametype.integer == GT_HARVESTER ) {
1399 obelisk = SpawnObelisk( ent->s.origin, ent->r.mins, ent->r.maxs, TEAM_RED );
1400 obelisk->activator = ent;
1401 }
1402 ent->s.modelindex = TEAM_RED;
1403 trap_LinkEntity(ent);
1404 }
1405
1406 /*QUAKED team_blueobelisk (0 0 1) (-16 -16 0) (16 16 88)
1407 */
1408 void SP_team_blueobelisk( gentity_t *ent ) {
1409 gentity_t *obelisk;
1410
1411 if ( g_gametype.integer <= GT_TEAM ) {
1412 G_FreeEntity(ent);
1413 return;
1414 }
1415 ObeliskInit( ent );
1416 if ( g_gametype.integer == GT_OBELISK ) {
1417 obelisk = SpawnObelisk( ent->s.origin, ent->r.mins, ent->r.maxs, TEAM_BLUE );
1418 obelisk->activator = ent;
1419 // initial obelisk health value
1420 ent->s.modelindex2 = 0xff;
1421 ent->s.frame = 0;
1422 }
1423 if ( g_gametype.integer == GT_HARVESTER ) {
1424 obelisk = SpawnObelisk( ent->s.origin, ent->r.mins, ent->r.maxs, TEAM_BLUE );
1425 obelisk->activator = ent;
1426 }
1427 ent->s.modelindex = TEAM_BLUE;
1428 trap_LinkEntity(ent);
1429 }
1430
1431 /*QUAKED team_neutralobelisk (0 0 1) (-16 -16 0) (16 16 88)
1432 */
1433 void SP_team_neutralobelisk( gentity_t *ent ) {
1434 if ( g_gametype.integer != GT_1FCTF && g_gametype.integer != GT_HARVESTER ) {
1435 G_FreeEntity(ent);
1436 return;
1437 }
1438 ObeliskInit( ent );
1439 if ( g_gametype.integer == GT_HARVESTER) {
1440 neutralObelisk = SpawnObelisk( ent->s.origin, ent->r.mins, ent->r.maxs, TEAM_FREE );
1441 neutralObelisk->activator = ent;
1442 }
1443 ent->s.modelindex = TEAM_FREE;
1444 trap_LinkEntity(ent);
1445 }
1446
1447
1448 /*
1449 ================
1450 CheckObeliskAttack
1451 ================
1452 */
1453 qboolean CheckObeliskAttack( gentity_t *obelisk, gentity_t *attacker ) {
1454 gentity_t *te;
1455
1456 // if this really is an obelisk
1457 if( obelisk->die != ObeliskDie ) {
1458 return qfalse;
1459 }
1460
1461 // if the attacker is a client
1462 if( !attacker->client ) {
1463 return qfalse;
1464 }
1465
1466 // if the obelisk is on the same team as the attacker then don't hurt it
1467 if( obelisk->spawnflags == attacker->client->sess.sessionTeam ) {
1468 return qtrue;
1469 }
1470
1471 // obelisk may be hurt
1472
1473 // if not played any sounds recently
1474 if ((obelisk->spawnflags == TEAM_RED &&
1475 teamgame.redObeliskAttackedTime < level.time - OVERLOAD_ATTACK_BASE_SOUND_TIME) ||
1476 (obelisk->spawnflags == TEAM_BLUE &&
1477 teamgame.blueObeliskAttackedTime < level.time - OVERLOAD_ATTACK_BASE_SOUND_TIME) ) {
1478
1479 // tell which obelisk is under attack
1480 te = G_TempEntity( obelisk->s.pos.trBase, EV_GLOBAL_TEAM_SOUND );
1481 if( obelisk->spawnflags == TEAM_RED ) {
1482 te->s.eventParm = GTS_REDOBELISK_ATTACKED;
1483 teamgame.redObeliskAttackedTime = level.time;
1484 }
1485 else {
1486 te->s.eventParm = GTS_BLUEOBELISK_ATTACKED;
1487 teamgame.blueObeliskAttackedTime = level.time;
1488 }
1489 te->r.svFlags |= SVF_BROADCAST;
1490 }
1491
1492 return qfalse;
1493 }
1494 #endif