Debian Codegraph @

code/cgame/cg_event.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 // cg_event.c -- handle entity events at snapshot or playerstate transitions
24
25 #include "cg_local.h"
26
27 // for the voice chats
28 #ifdef MISSIONPACK
29 #include "../../ui/menudef.h"
30 #endif
31 //==========================================================================
32
33 /*
34 ===================
35 CG_PlaceString
36
37 Also called by scoreboard drawing
38 ===================
39 */
40 const char *CG_PlaceString( int rank ) {
41 static char str[64];
42 char *s, *t;
43
44 if ( rank & RANK_TIED_FLAG ) {
45 rank &= ~RANK_TIED_FLAG;
46 t = "Tied for ";
47 } else {
48 t = "";
49 }
50
51 if ( rank == 1 ) {
52 s = S_COLOR_BLUE "1st" S_COLOR_WHITE; // draw in blue
53 } else if ( rank == 2 ) {
54 s = S_COLOR_RED "2nd" S_COLOR_WHITE; // draw in red
55 } else if ( rank == 3 ) {
56 s = S_COLOR_YELLOW "3rd" S_COLOR_WHITE; // draw in yellow
57 } else if ( rank == 11 ) {
58 s = "11th";
59 } else if ( rank == 12 ) {
60 s = "12th";
61 } else if ( rank == 13 ) {
62 s = "13th";
63 } else if ( rank % 10 == 1 ) {
64 s = va("%ist", rank);
65 } else if ( rank % 10 == 2 ) {
66 s = va("%ind", rank);
67 } else if ( rank % 10 == 3 ) {
68 s = va("%ird", rank);
69 } else {
70 s = va("%ith", rank);
71 }
72
73 Com_sprintf( str, sizeof( str ), "%s%s", t, s );
74 return str;
75 }
76
77 /*
78 =============
79 CG_Obituary
80 =============
81 */
82 static void CG_Obituary( entityState_t *ent ) {
83 int mod;
84 int target, attacker;
85 char *message;
86 char *message2;
87 const char *targetInfo;
88 const char *attackerInfo;
89 char targetName[32];
90 char attackerName[32];
91 gender_t gender;
92 clientInfo_t *ci;
93
94 target = ent->otherEntityNum;
95 attacker = ent->otherEntityNum2;
96 mod = ent->eventParm;
97
98 if ( target < 0 || target >= MAX_CLIENTS ) {
99 CG_Error( "CG_Obituary: target out of range" );
100 }
101 ci = &cgs.clientinfo[target];
102
103 if ( attacker < 0 || attacker >= MAX_CLIENTS ) {
104 attacker = ENTITYNUM_WORLD;
105 attackerInfo = NULL;
106 } else {
107 attackerInfo = CG_ConfigString( CS_PLAYERS + attacker );
108 }
109
110 targetInfo = CG_ConfigString( CS_PLAYERS + target );
111 if ( !targetInfo ) {
112 return;
113 }
114 Q_strncpyz( targetName, Info_ValueForKey( targetInfo, "n" ), sizeof(targetName) - 2);
115 strcat( targetName, S_COLOR_WHITE );
116
117 message2 = "";
118
119 // check for single client messages
120
121 switch( mod ) {
122 case MOD_SUICIDE:
123 message = "suicides";
124 break;
125 case MOD_FALLING:
126 message = "cratered";
127 break;
128 case MOD_CRUSH:
129 message = "was squished";
130 break;
131 case MOD_WATER:
132 message = "sank like a rock";
133 break;
134 case MOD_SLIME:
135 message = "melted";
136 break;
137 case MOD_LAVA:
138 message = "does a back flip into the lava";
139 break;
140 case MOD_TARGET_LASER:
141 message = "saw the light";
142 break;
143 case MOD_TRIGGER_HURT:
144 message = "was in the wrong place";
145 break;
146 default:
147 message = NULL;
148 break;
149 }
150
151 if (attacker == target) {
152 gender = ci->gender;
153 switch (mod) {
154 #ifdef MISSIONPACK
155 case MOD_KAMIKAZE:
156 message = "goes out with a bang";
157 break;
158 #endif
159 case MOD_GRENADE_SPLASH:
160 if ( gender == GENDER_FEMALE )
161 message = "tripped on her own grenade";
162 else if ( gender == GENDER_NEUTER )
163 message = "tripped on its own grenade";
164 else
165 message = "tripped on his own grenade";
166 break;
167 case MOD_ROCKET_SPLASH:
168 if ( gender == GENDER_FEMALE )
169 message = "blew herself up";
170 else if ( gender == GENDER_NEUTER )
171 message = "blew itself up";
172 else
173 message = "blew himself up";
174 break;
175 case MOD_PLASMA_SPLASH:
176 if ( gender == GENDER_FEMALE )
177 message = "melted herself";
178 else if ( gender == GENDER_NEUTER )
179 message = "melted itself";
180 else
181 message = "melted himself";
182 break;
183 case MOD_BFG_SPLASH:
184 message = "should have used a smaller gun";
185 break;
186 #ifdef MISSIONPACK
187 case MOD_PROXIMITY_MINE:
188 if( gender == GENDER_FEMALE ) {
189 message = "found her prox mine";
190 } else if ( gender == GENDER_NEUTER ) {
191 message = "found its prox mine";
192 } else {
193 message = "found his prox mine";
194 }
195 break;
196 #endif
197 default:
198 if ( gender == GENDER_FEMALE )
199 message = "killed herself";
200 else if ( gender == GENDER_NEUTER )
201 message = "killed itself";
202 else
203 message = "killed himself";
204 break;
205 }
206 }
207
208 if (message) {
209 CG_Printf( "%s %s.\n", targetName, message);
210 return;
211 }
212
213 // check for kill messages from the current clientNum
214 if ( attacker == cg.snap->ps.clientNum ) {
215 char *s;
216
217 if ( cgs.gametype < GT_TEAM ) {
218 s = va("You fragged %s\n%s place with %i", targetName,
219 CG_PlaceString( cg.snap->ps.persistant[PERS_RANK] + 1 ),
220 cg.snap->ps.persistant[PERS_SCORE] );
221 } else {
222 s = va("You fragged %s", targetName );
223 }
224 #ifdef MISSIONPACK
225 if (!(cg_singlePlayerActive.integer && cg_cameraOrbit.integer)) {
226 CG_CenterPrint( s, SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH );
227 }
228 #else
229 CG_CenterPrint( s, SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH );
230 #endif
231
232 // print the text message as well
233 }
234
235 // check for double client messages
236 if ( !attackerInfo ) {
237 attacker = ENTITYNUM_WORLD;
238 strcpy( attackerName, "noname" );
239 } else {
240 Q_strncpyz( attackerName, Info_ValueForKey( attackerInfo, "n" ), sizeof(attackerName) - 2);
241 strcat( attackerName, S_COLOR_WHITE );
242 // check for kill messages about the current clientNum
243 if ( target == cg.snap->ps.clientNum ) {
244 Q_strncpyz( cg.killerName, attackerName, sizeof( cg.killerName ) );
245 }
246 }
247
248 if ( attacker != ENTITYNUM_WORLD ) {
249 switch (mod) {
250 case MOD_GRAPPLE:
251 message = "was caught by";
252 break;
253 case MOD_GAUNTLET:
254 message = "was pummeled by";
255 break;
256 case MOD_MACHINEGUN:
257 message = "was machinegunned by";
258 break;
259 case MOD_SHOTGUN:
260 message = "was gunned down by";
261 break;
262 case MOD_GRENADE:
263 message = "ate";
264 message2 = "'s grenade";
265 break;
266 case MOD_GRENADE_SPLASH:
267 message = "was shredded by";
268 message2 = "'s shrapnel";
269 break;
270 case MOD_ROCKET:
271 message = "ate";
272 message2 = "'s rocket";
273 break;
274 case MOD_ROCKET_SPLASH:
275 message = "almost dodged";
276 message2 = "'s rocket";
277 break;
278 case MOD_PLASMA:
279 message = "was melted by";
280 message2 = "'s plasmagun";
281 break;
282 case MOD_PLASMA_SPLASH:
283 message = "was melted by";
284 message2 = "'s plasmagun";
285 break;
286 case MOD_RAILGUN:
287 message = "was railed by";
288 break;
289 case MOD_LIGHTNING:
290 message = "was electrocuted by";
291 break;
292 case MOD_BFG:
293 case MOD_BFG_SPLASH:
294 message = "was blasted by";
295 message2 = "'s BFG";
296 break;
297 #ifdef MISSIONPACK
298 case MOD_NAIL:
299 message = "was nailed by";
300 break;
301 case MOD_CHAINGUN:
302 message = "got lead poisoning from";
303 message2 = "'s Chaingun";
304 break;
305 case MOD_PROXIMITY_MINE:
306 message = "was too close to";
307 message2 = "'s Prox Mine";
308 break;
309 case MOD_KAMIKAZE:
310 message = "falls to";
311 message2 = "'s Kamikaze blast";
312 break;
313 case MOD_JUICED:
314 message = "was juiced by";
315 break;
316 #endif
317 case MOD_TELEFRAG:
318 message = "tried to invade";
319 message2 = "'s personal space";
320 break;
321 default:
322 message = "was killed by";
323 break;
324 }
325
326 if (message) {
327 CG_Printf( "%s %s %s%s\n",
328 targetName, message, attackerName, message2);
329 return;
330 }
331 }
332
333 // we don't know what it was
334 CG_Printf( "%s died.\n", targetName );
335 }
336
337 //==========================================================================
338
339 /*
340 ===============
341 CG_UseItem
342 ===============
343 */
344 static void CG_UseItem( centity_t *cent ) {
345 clientInfo_t *ci;
346 int itemNum, clientNum;
347 gitem_t *item;
348 entityState_t *es;
349
350 es = &cent->currentState;
351
352 itemNum = (es->event & ~EV_EVENT_BITS) - EV_USE_ITEM0;
353 if ( itemNum < 0 || itemNum > HI_NUM_HOLDABLE ) {
354 itemNum = 0;
355 }
356
357 // print a message if the local player
358 if ( es->number == cg.snap->ps.clientNum ) {
359 if ( !itemNum ) {
360 CG_CenterPrint( "No item to use", SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH );
361 } else {
362 item = BG_FindItemForHoldable( itemNum );
363 CG_CenterPrint( va("Use %s", item->pickup_name), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH );
364 }
365 }
366
367 switch ( itemNum ) {
368 default:
369 case HI_NONE:
370 trap_S_StartSound (NULL, es->number, CHAN_BODY, cgs.media.useNothingSound );
371 break;
372
373 case HI_TELEPORTER:
374 break;
375
376 case HI_MEDKIT:
377 clientNum = cent->currentState.clientNum;
378 if ( clientNum >= 0 && clientNum < MAX_CLIENTS ) {
379 ci = &cgs.clientinfo[ clientNum ];
380 ci->medkitUsageTime = cg.time;
381 }
382 trap_S_StartSound (NULL, es->number, CHAN_BODY, cgs.media.medkitSound );
383 break;
384
385 #ifdef MISSIONPACK
386 case HI_KAMIKAZE:
387 break;
388
389 case HI_PORTAL:
390 break;
391 case HI_INVULNERABILITY:
392 trap_S_StartSound (NULL, es->number, CHAN_BODY, cgs.media.useInvulnerabilitySound );
393 break;
394 #endif
395 }
396
397 }
398
399 /*
400 ================
401 CG_ItemPickup
402
403 A new item was picked up this frame
404 ================
405 */
406 static void CG_ItemPickup( int itemNum ) {
407 cg.itemPickup = itemNum;
408 cg.itemPickupTime = cg.time;
409 cg.itemPickupBlendTime = cg.time;
410 // see if it should be the grabbed weapon
411 if ( bg_itemlist[itemNum].giType == IT_WEAPON ) {
412 // select it immediately
413 if ( cg_autoswitch.integer && bg_itemlist[itemNum].giTag != WP_MACHINEGUN ) {
414 cg.weaponSelectTime = cg.time;
415 cg.weaponSelect = bg_itemlist[itemNum].giTag;
416 }
417 }
418
419 }
420
421 /*
422 ================
423 CG_WaterLevel
424
425 Returns waterlevel for entity origin
426 ================
427 */
428 int CG_WaterLevel(centity_t *cent) {
429 vec3_t point;
430 int contents, sample1, sample2, anim, waterlevel;
431 int viewheight;
432
433 anim = cent->currentState.legsAnim & ~ANIM_TOGGLEBIT;
434
435 if (anim == LEGS_WALKCR || anim == LEGS_IDLECR) {
436 viewheight = CROUCH_VIEWHEIGHT;
437 } else {
438 viewheight = DEFAULT_VIEWHEIGHT;
439 }
440
441 //
442 // get waterlevel, accounting for ducking
443 //
444 waterlevel = 0;
445
446 point[0] = cent->lerpOrigin[0];
447 point[1] = cent->lerpOrigin[1];
448 point[2] = cent->lerpOrigin[2] + MINS_Z + 1;
449 contents = CG_PointContents(point, -1);
450
451 if (contents & MASK_WATER) {
452 sample2 = viewheight - MINS_Z;
453 sample1 = sample2 / 2;
454 waterlevel = 1;
455 point[2] = cent->lerpOrigin[2] + MINS_Z + sample1;
456 contents = CG_PointContents(point, -1);
457
458 if (contents & MASK_WATER) {
459 waterlevel = 2;
460 point[2] = cent->lerpOrigin[2] + MINS_Z + sample2;
461 contents = CG_PointContents(point, -1);
462
463 if (contents & MASK_WATER) {
464 waterlevel = 3;
465 }
466 }
467 }
468
469 return waterlevel;
470 }
471
472 /*
473 ================
474 CG_PainEvent
475
476 Also called by playerstate transition
477 ================
478 */
479 void CG_PainEvent( centity_t *cent, int health ) {
480 char *snd;
481
482 // don't do more than two pain sounds a second
483 if ( cg.time - cent->pe.painTime < 500 ) {
484 return;
485 }
486
487 if ( health < 25 ) {
488 snd = "*pain25_1.wav";
489 } else if ( health < 50 ) {
490 snd = "*pain50_1.wav";
491 } else if ( health < 75 ) {
492 snd = "*pain75_1.wav";
493 } else {
494 snd = "*pain100_1.wav";
495 }
496 // play a gurp sound instead of a normal pain sound
497 if (CG_WaterLevel(cent) == 3) {
498 if (rand()&1) {
499 trap_S_StartSound(NULL, cent->currentState.number, CHAN_VOICE, CG_CustomSound(cent->currentState.number, "sound/player/gurp1.wav"));
500 } else {
501 trap_S_StartSound(NULL, cent->currentState.number, CHAN_VOICE, CG_CustomSound(cent->currentState.number, "sound/player/gurp2.wav"));
502 }
503 } else {
504 trap_S_StartSound(NULL, cent->currentState.number, CHAN_VOICE, CG_CustomSound(cent->currentState.number, snd));
505 }
506 // save pain time for programitic twitch animation
507 cent->pe.painTime = cg.time;
508 cent->pe.painDirection ^= 1;
509 }
510
511
512
513 /*
514 ==============
515 CG_EntityEvent
516
517 An entity has an event value
518 also called by CG_CheckPlayerstateEvents
519 ==============
520 */
521 #define DEBUGNAME(x) if(cg_debugEvents.integer){CG_Printf(x"\n");}
522 void CG_EntityEvent( centity_t *cent, vec3_t position ) {
523 entityState_t *es;
524 int event;
525 vec3_t dir;
526 const char *s;
527 int clientNum;
528 clientInfo_t *ci;
529
530 es = &cent->currentState;
531 event = es->event & ~EV_EVENT_BITS;
532
533 if ( cg_debugEvents.integer ) {
534 CG_Printf( "ent:%3i event:%3i ", es->number, event );
535 }
536
537 if ( !event ) {
538 DEBUGNAME("ZEROEVENT");
539 return;
540 }
541
542 clientNum = es->clientNum;
543 if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
544 clientNum = 0;
545 }
546 ci = &cgs.clientinfo[ clientNum ];
547
548 switch ( event ) {
549 //
550 // movement generated events
551 //
552 case EV_FOOTSTEP:
553 DEBUGNAME("EV_FOOTSTEP");
554 if (cg_footsteps.integer) {
555 trap_S_StartSound (NULL, es->number, CHAN_BODY,
556 cgs.media.footsteps[ ci->footsteps ][rand()&3] );
557 }
558 break;
559 case EV_FOOTSTEP_METAL:
560 DEBUGNAME("EV_FOOTSTEP_METAL");
561 if (cg_footsteps.integer) {
562 trap_S_StartSound (NULL, es->number, CHAN_BODY,
563 cgs.media.footsteps[ FOOTSTEP_METAL ][rand()&3] );
564 }
565 break;
566 case EV_FOOTSPLASH:
567 DEBUGNAME("EV_FOOTSPLASH");
568 if (cg_footsteps.integer) {
569 trap_S_StartSound (NULL, es->number, CHAN_BODY,
570 cgs.media.footsteps[ FOOTSTEP_SPLASH ][rand()&3] );
571 }
572 break;
573 case EV_FOOTWADE:
574 DEBUGNAME("EV_FOOTWADE");
575 if (cg_footsteps.integer) {
576 trap_S_StartSound (NULL, es->number, CHAN_BODY,
577 cgs.media.footsteps[ FOOTSTEP_SPLASH ][rand()&3] );
578 }
579 break;
580 case EV_SWIM:
581 DEBUGNAME("EV_SWIM");
582 if (cg_footsteps.integer) {
583 trap_S_StartSound (NULL, es->number, CHAN_BODY,
584 cgs.media.footsteps[ FOOTSTEP_SPLASH ][rand()&3] );
585 }
586 break;
587
588
589 case EV_FALL_SHORT:
590 DEBUGNAME("EV_FALL_SHORT");
591 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.landSound );
592 if ( clientNum == cg.predictedPlayerState.clientNum ) {
593 // smooth landing z changes
594 cg.landChange = -8;
595 cg.landTime = cg.time;
596 }
597 break;
598 case EV_FALL_MEDIUM:
599 DEBUGNAME("EV_FALL_MEDIUM");
600 // use normal pain sound
601 trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*pain100_1.wav" ) );
602 if ( clientNum == cg.predictedPlayerState.clientNum ) {
603 // smooth landing z changes
604 cg.landChange = -16;
605 cg.landTime = cg.time;
606 }
607 break;
608 case EV_FALL_FAR:
609 DEBUGNAME("EV_FALL_FAR");
610 trap_S_StartSound (NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*fall1.wav" ) );
611 cent->pe.painTime = cg.time; // don't play a pain sound right after this
612 if ( clientNum == cg.predictedPlayerState.clientNum ) {
613 // smooth landing z changes
614 cg.landChange = -24;
615 cg.landTime = cg.time;
616 }
617 break;
618
619 case EV_STEP_4:
620 case EV_STEP_8:
621 case EV_STEP_12:
622 case EV_STEP_16: // smooth out step up transitions
623 DEBUGNAME("EV_STEP");
624 {
625 float oldStep;
626 int delta;
627 int step;
628
629 if ( clientNum != cg.predictedPlayerState.clientNum ) {
630 break;
631 }
632 // if we are interpolating, we don't need to smooth steps
633 if ( cg.demoPlayback || (cg.snap->ps.pm_flags & PMF_FOLLOW) ||
634 cg_nopredict.integer || cg_synchronousClients.integer ) {
635 break;
636 }
637 // check for stepping up before a previous step is completed
638 delta = cg.time - cg.stepTime;
639 if (delta < STEP_TIME) {
640 oldStep = cg.stepChange * (STEP_TIME - delta) / STEP_TIME;
641 } else {
642 oldStep = 0;
643 }
644
645 // add this amount
646 step = 4 * (event - EV_STEP_4 + 1 );
647 cg.stepChange = oldStep + step;
648 if ( cg.stepChange > MAX_STEP_CHANGE ) {
649 cg.stepChange = MAX_STEP_CHANGE;
650 }
651 cg.stepTime = cg.time;
652 break;
653 }
654
655 case EV_JUMP_PAD:
656 DEBUGNAME("EV_JUMP_PAD");
657 // CG_Printf( "EV_JUMP_PAD w/effect #%i\n", es->eventParm );
658 {
659 vec3_t up = {0, 0, 1};
660
661
662 CG_SmokePuff( cent->lerpOrigin, up,
663 32,
664 1, 1, 1, 0.33f,
665 1000,
666 cg.time, 0,
667 LEF_PUFF_DONT_SCALE,
668 cgs.media.smokePuffShader );
669 }
670
671 // boing sound at origin, jump sound on player
672 trap_S_StartSound ( cent->lerpOrigin, -1, CHAN_VOICE, cgs.media.jumpPadSound );
673 trap_S_StartSound (NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*jump1.wav" ) );
674 break;
675
676 case EV_JUMP:
677 DEBUGNAME("EV_JUMP");
678 trap_S_StartSound (NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*jump1.wav" ) );
679 break;
680 case EV_TAUNT:
681 DEBUGNAME("EV_TAUNT");
682 trap_S_StartSound (NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*taunt.wav" ) );
683 break;
684 #ifdef MISSIONPACK
685 case EV_TAUNT_YES:
686 DEBUGNAME("EV_TAUNT_YES");
687 CG_VoiceChatLocal(SAY_TEAM, qfalse, es->number, COLOR_CYAN, VOICECHAT_YES);
688 break;
689 case EV_TAUNT_NO:
690 DEBUGNAME("EV_TAUNT_NO");
691 CG_VoiceChatLocal(SAY_TEAM, qfalse, es->number, COLOR_CYAN, VOICECHAT_NO);
692 break;
693 case EV_TAUNT_FOLLOWME:
694 DEBUGNAME("EV_TAUNT_FOLLOWME");
695 CG_VoiceChatLocal(SAY_TEAM, qfalse, es->number, COLOR_CYAN, VOICECHAT_FOLLOWME);
696 break;
697 case EV_TAUNT_GETFLAG:
698 DEBUGNAME("EV_TAUNT_GETFLAG");
699 CG_VoiceChatLocal(SAY_TEAM, qfalse, es->number, COLOR_CYAN, VOICECHAT_ONGETFLAG);
700 break;
701 case EV_TAUNT_GUARDBASE:
702 DEBUGNAME("EV_TAUNT_GUARDBASE");
703 CG_VoiceChatLocal(SAY_TEAM, qfalse, es->number, COLOR_CYAN, VOICECHAT_ONDEFENSE);
704 break;
705 case EV_TAUNT_PATROL:
706 DEBUGNAME("EV_TAUNT_PATROL");
707 CG_VoiceChatLocal(SAY_TEAM, qfalse, es->number, COLOR_CYAN, VOICECHAT_ONPATROL);
708 break;
709 #endif
710 case EV_WATER_TOUCH:
711 DEBUGNAME("EV_WATER_TOUCH");
712 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.watrInSound );
713 break;
714 case EV_WATER_LEAVE:
715 DEBUGNAME("EV_WATER_LEAVE");
716 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.watrOutSound );
717 break;
718 case EV_WATER_UNDER:
719 DEBUGNAME("EV_WATER_UNDER");
720 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.watrUnSound );
721 break;
722 case EV_WATER_CLEAR:
723 DEBUGNAME("EV_WATER_CLEAR");
724 trap_S_StartSound (NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*gasp.wav" ) );
725 break;
726
727 case EV_ITEM_PICKUP:
728 DEBUGNAME("EV_ITEM_PICKUP");
729 {
730 gitem_t *item;
731 int index;
732
733 index = es->eventParm; // player predicted
734
735 if ( index < 1 || index >= bg_numItems ) {
736 break;
737 }
738 item = &bg_itemlist[ index ];
739
740 // powerups and team items will have a separate global sound, this one
741 // will be played at prediction time
742 if ( item->giType == IT_POWERUP || item->giType == IT_TEAM) {
743 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.n_healthSound );
744 } else if (item->giType == IT_PERSISTANT_POWERUP) {
745 #ifdef MISSIONPACK
746 switch (item->giTag ) {
747 case PW_SCOUT:
748 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.scoutSound );
749 break;
750 case PW_GUARD:
751 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.guardSound );
752 break;
753 case PW_DOUBLER:
754 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.doublerSound );
755 break;
756 case PW_AMMOREGEN:
757 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.ammoregenSound );
758 break;
759 }
760 #endif
761 } else {
762 trap_S_StartSound (NULL, es->number, CHAN_AUTO, trap_S_RegisterSound( item->pickup_sound, qfalse ) );
763 }
764
765 // show icon and name on status bar
766 if ( es->number == cg.snap->ps.clientNum ) {
767 CG_ItemPickup( index );
768 }
769 }
770 break;
771
772 case EV_GLOBAL_ITEM_PICKUP:
773 DEBUGNAME("EV_GLOBAL_ITEM_PICKUP");
774 {
775 gitem_t *item;
776 int index;
777
778 index = es->eventParm; // player predicted
779
780 if ( index < 1 || index >= bg_numItems ) {
781 break;
782 }
783 item = &bg_itemlist[ index ];
784 // powerup pickups are global
785 if( item->pickup_sound ) {
786 trap_S_StartSound (NULL, cg.snap->ps.clientNum, CHAN_AUTO, trap_S_RegisterSound( item->pickup_sound, qfalse ) );
787 }
788
789 // show icon and name on status bar
790 if ( es->number == cg.snap->ps.clientNum ) {
791 CG_ItemPickup( index );
792 }
793 }
794 break;
795
796 //
797 // weapon events
798 //
799 case EV_NOAMMO:
800 DEBUGNAME("EV_NOAMMO");
801 // trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.noAmmoSound );
802 if ( es->number == cg.snap->ps.clientNum ) {
803 CG_OutOfAmmoChange();
804 }
805 break;
806 case EV_CHANGE_WEAPON:
807 DEBUGNAME("EV_CHANGE_WEAPON");
808 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.selectSound );
809 break;
810 case EV_FIRE_WEAPON:
811 DEBUGNAME("EV_FIRE_WEAPON");
812 CG_FireWeapon( cent );
813 break;
814
815 case EV_USE_ITEM0:
816 DEBUGNAME("EV_USE_ITEM0");
817 CG_UseItem( cent );
818 break;
819 case EV_USE_ITEM1:
820 DEBUGNAME("EV_USE_ITEM1");
821 CG_UseItem( cent );
822 break;
823 case EV_USE_ITEM2:
824 DEBUGNAME("EV_USE_ITEM2");
825 CG_UseItem( cent );
826 break;
827 case EV_USE_ITEM3:
828 DEBUGNAME("EV_USE_ITEM3");
829 CG_UseItem( cent );
830 break;
831 case EV_USE_ITEM4:
832 DEBUGNAME("EV_USE_ITEM4");
833 CG_UseItem( cent );
834 break;
835 case EV_USE_ITEM5:
836 DEBUGNAME("EV_USE_ITEM5");
837 CG_UseItem( cent );
838 break;
839 case EV_USE_ITEM6:
840 DEBUGNAME("EV_USE_ITEM6");
841 CG_UseItem( cent );
842 break;
843 case EV_USE_ITEM7:
844 DEBUGNAME("EV_USE_ITEM7");
845 CG_UseItem( cent );
846 break;
847 case EV_USE_ITEM8:
848 DEBUGNAME("EV_USE_ITEM8");
849 CG_UseItem( cent );
850 break;
851 case EV_USE_ITEM9:
852 DEBUGNAME("EV_USE_ITEM9");
853 CG_UseItem( cent );
854 break;
855 case EV_USE_ITEM10:
856 DEBUGNAME("EV_USE_ITEM10");
857 CG_UseItem( cent );
858 break;
859 case EV_USE_ITEM11:
860 DEBUGNAME("EV_USE_ITEM11");
861 CG_UseItem( cent );
862 break;
863 case EV_USE_ITEM12:
864 DEBUGNAME("EV_USE_ITEM12");
865 CG_UseItem( cent );
866 break;
867 case EV_USE_ITEM13:
868 DEBUGNAME("EV_USE_ITEM13");
869 CG_UseItem( cent );
870 break;
871 case EV_USE_ITEM14:
872 DEBUGNAME("EV_USE_ITEM14");
873 CG_UseItem( cent );
874 break;
875 case EV_USE_ITEM15:
876 DEBUGNAME("EV_USE_ITEM15");
877 CG_UseItem( cent );
878 break;
879
880 //=================================================================
881
882 //
883 // other events
884 //
885 case EV_PLAYER_TELEPORT_IN:
886 DEBUGNAME("EV_PLAYER_TELEPORT_IN");
887 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.teleInSound );
888 CG_SpawnEffect( position);
889 break;
890
891 case EV_PLAYER_TELEPORT_OUT:
892 DEBUGNAME("EV_PLAYER_TELEPORT_OUT");
893 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.teleOutSound );
894 CG_SpawnEffect( position);
895 break;
896
897 case EV_ITEM_POP:
898 DEBUGNAME("EV_ITEM_POP");
899 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.respawnSound );
900 break;
901 case EV_ITEM_RESPAWN:
902 DEBUGNAME("EV_ITEM_RESPAWN");
903 cent->miscTime = cg.time; // scale up from this
904 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.respawnSound );
905 break;
906
907 case EV_GRENADE_BOUNCE:
908 DEBUGNAME("EV_GRENADE_BOUNCE");
909 if ( rand() & 1 ) {
910 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.hgrenb1aSound );
911 } else {
912 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.hgrenb2aSound );
913 }
914 break;
915
916 #ifdef MISSIONPACK
917 case EV_PROXIMITY_MINE_STICK:
918 DEBUGNAME("EV_PROXIMITY_MINE_STICK");
919 if( es->eventParm & SURF_FLESH ) {
920 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.wstbimplSound );
921 } else if( es->eventParm & SURF_METALSTEPS ) {
922 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.wstbimpmSound );
923 } else {
924 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.wstbimpdSound );
925 }
926 break;
927
928 case EV_PROXIMITY_MINE_TRIGGER:
929 DEBUGNAME("EV_PROXIMITY_MINE_TRIGGER");
930 trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.wstbactvSound );
931 break;
932 case EV_KAMIKAZE:
933 DEBUGNAME("EV_KAMIKAZE");
934 CG_KamikazeEffect( cent->lerpOrigin );
935 break;
936 case EV_OBELISKEXPLODE:
937 DEBUGNAME("EV_OBELISKEXPLODE");
938 CG_ObeliskExplode( cent->lerpOrigin, es->eventParm );
939 break;
940 case EV_OBELISKPAIN:
941 DEBUGNAME("EV_OBELISKPAIN");
942 CG_ObeliskPain( cent->lerpOrigin );
943 break;
944 case EV_INVUL_IMPACT:
945 DEBUGNAME("EV_INVUL_IMPACT");
946 CG_InvulnerabilityImpact( cent->lerpOrigin, cent->currentState.angles );
947 break;
948 case EV_JUICED:
949 DEBUGNAME("EV_JUICED");
950 CG_InvulnerabilityJuiced( cent->lerpOrigin );
951 break;
952 case EV_LIGHTNINGBOLT:
953 DEBUGNAME("EV_LIGHTNINGBOLT");
954 CG_LightningBoltBeam(es->origin2, es->pos.trBase);
955 break;
956 #endif
957 case EV_SCOREPLUM:
958 DEBUGNAME("EV_SCOREPLUM");
959 CG_ScorePlum( cent->currentState.otherEntityNum, cent->lerpOrigin, cent->currentState.time );
960 break;
961
962 //
963 // missile impacts
964 //
965 case EV_MISSILE_HIT:
966 DEBUGNAME("EV_MISSILE_HIT");
967 ByteToDir( es->eventParm, dir );
968 CG_MissileHitPlayer( es->weapon, position, dir, es->otherEntityNum );
969 break;
970
971 case EV_MISSILE_MISS:
972 DEBUGNAME("EV_MISSILE_MISS");
973 ByteToDir( es->eventParm, dir );
974 CG_MissileHitWall( es->weapon, 0, position, dir, IMPACTSOUND_DEFAULT );
975 break;
976
977 case EV_MISSILE_MISS_METAL:
978 DEBUGNAME("EV_MISSILE_MISS_METAL");
979 ByteToDir( es->eventParm, dir );
980 CG_MissileHitWall( es->weapon, 0, position, dir, IMPACTSOUND_METAL );
981 break;
982
983 case EV_RAILTRAIL:
984 DEBUGNAME("EV_RAILTRAIL");
985 cent->currentState.weapon = WP_RAILGUN;
986
987 if(es->clientNum == cg.snap->ps.clientNum && !cg.renderingThirdPerson)
988 {
989 if(cg_drawGun.integer == 2)
990 VectorMA(es->origin2, 8, cg.refdef.viewaxis[1], es->origin2);
991 else if(cg_drawGun.integer == 3)
992 VectorMA(es->origin2, 4, cg.refdef.viewaxis[1], es->origin2);
993 }
994
995 CG_RailTrail(ci, es->origin2, es->pos.trBase);
996
997 // if the end was on a nomark surface, don't make an explosion
998 if ( es->eventParm != 255 ) {
999 ByteToDir( es->eventParm, dir );
1000 CG_MissileHitWall( es->weapon, es->clientNum, position, dir, IMPACTSOUND_DEFAULT );
1001 }
1002 break;
1003
1004 case EV_BULLET_HIT_WALL:
1005 DEBUGNAME("EV_BULLET_HIT_WALL");
1006 ByteToDir( es->eventParm, dir );
1007 CG_Bullet( es->pos.trBase, es->otherEntityNum, dir, qfalse, ENTITYNUM_WORLD );
1008 break;
1009
1010 case EV_BULLET_HIT_FLESH:
1011 DEBUGNAME("EV_BULLET_HIT_FLESH");
1012 CG_Bullet( es->pos.trBase, es->otherEntityNum, dir, qtrue, es->eventParm );
1013 break;
1014
1015 case EV_SHOTGUN:
1016 DEBUGNAME("EV_SHOTGUN");
1017 CG_ShotgunFire( es );
1018 break;
1019
1020 case EV_GENERAL_SOUND:
1021 DEBUGNAME("EV_GENERAL_SOUND");
1022 if ( cgs.gameSounds[ es->eventParm ] ) {
1023 trap_S_StartSound (NULL, es->number, CHAN_VOICE, cgs.gameSounds[ es->eventParm ] );
1024 } else {
1025 s = CG_ConfigString( CS_SOUNDS + es->eventParm );
1026 trap_S_StartSound (NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, s ) );
1027 }
1028 break;
1029
1030 case EV_GLOBAL_SOUND: // play from the player's head so it never diminishes
1031 DEBUGNAME("EV_GLOBAL_SOUND");
1032 if ( cgs.gameSounds[ es->eventParm ] ) {
1033 trap_S_StartSound (NULL, cg.snap->ps.clientNum, CHAN_AUTO, cgs.gameSounds[ es->eventParm ] );
1034 } else {
1035 s = CG_ConfigString( CS_SOUNDS + es->eventParm );
1036 trap_S_StartSound (NULL, cg.snap->ps.clientNum, CHAN_AUTO, CG_CustomSound( es->number, s ) );
1037 }
1038 break;
1039
1040 case EV_GLOBAL_TEAM_SOUND: // play from the player's head so it never diminishes
1041 {
1042 DEBUGNAME("EV_GLOBAL_TEAM_SOUND");
1043 switch( es->eventParm ) {
1044 case GTS_RED_CAPTURE: // CTF: red team captured the blue flag, 1FCTF: red team captured the neutral flag
1045 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED )
1046 CG_AddBufferedSound( cgs.media.captureYourTeamSound );
1047 else
1048 CG_AddBufferedSound( cgs.media.captureOpponentSound );
1049 break;
1050 case GTS_BLUE_CAPTURE: // CTF: blue team captured the red flag, 1FCTF: blue team captured the neutral flag
1051 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE )
1052 CG_AddBufferedSound( cgs.media.captureYourTeamSound );
1053 else
1054 CG_AddBufferedSound( cgs.media.captureOpponentSound );
1055 break;
1056 case GTS_RED_RETURN: // CTF: blue flag returned, 1FCTF: never used
1057 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED )
1058 CG_AddBufferedSound( cgs.media.returnYourTeamSound );
1059 else
1060 CG_AddBufferedSound( cgs.media.returnOpponentSound );
1061 //
1062 CG_AddBufferedSound( cgs.media.blueFlagReturnedSound );
1063 break;
1064 case GTS_BLUE_RETURN: // CTF red flag returned, 1FCTF: neutral flag returned
1065 if ( cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE )
1066 CG_AddBufferedSound( cgs.media.returnYourTeamSound );
1067 else
1068 CG_AddBufferedSound( cgs.media.returnOpponentSound );
1069 //
1070 CG_AddBufferedSound( cgs.media.redFlagReturnedSound );
1071 break;
1072
1073 case GTS_RED_TAKEN: // CTF: red team took blue flag, 1FCTF: blue team took the neutral flag
1074 // if this player picked up the flag then a sound is played in CG_CheckLocalSounds
1075 if (cg.snap->ps.powerups[PW_BLUEFLAG] || cg.snap->ps.powerups[PW_NEUTRALFLAG]) {
1076 }
1077 else {
1078 if (cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE) {
1079 #ifdef MISSIONPACK
1080 if (cgs.gametype == GT_1FCTF)
1081 CG_AddBufferedSound( cgs.media.yourTeamTookTheFlagSound );
1082 else
1083 #endif
1084 CG_AddBufferedSound( cgs.media.enemyTookYourFlagSound );
1085 }
1086 else if (cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED) {
1087 #ifdef MISSIONPACK
1088 if (cgs.gametype == GT_1FCTF)
1089 CG_AddBufferedSound( cgs.media.enemyTookTheFlagSound );
1090 else
1091 #endif
1092 CG_AddBufferedSound( cgs.media.yourTeamTookEnemyFlagSound );
1093 }
1094 }
1095 break;
1096 case GTS_BLUE_TAKEN: // CTF: blue team took the red flag, 1FCTF red team took the neutral flag
1097 // if this player picked up the flag then a sound is played in CG_CheckLocalSounds
1098 if (cg.snap->ps.powerups[PW_REDFLAG] || cg.snap->ps.powerups[PW_NEUTRALFLAG]) {
1099 }
1100 else {
1101 if (cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED) {
1102 #ifdef MISSIONPACK
1103 if (cgs.gametype == GT_1FCTF)
1104 CG_AddBufferedSound( cgs.media.yourTeamTookTheFlagSound );
1105 else
1106 #endif
1107 CG_AddBufferedSound( cgs.media.enemyTookYourFlagSound );
1108 }
1109 else if (cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE) {
1110 #ifdef MISSIONPACK
1111 if (cgs.gametype == GT_1FCTF)
1112 CG_AddBufferedSound( cgs.media.enemyTookTheFlagSound );
1113 else
1114 #endif
1115 CG_AddBufferedSound( cgs.media.yourTeamTookEnemyFlagSound );
1116 }
1117 }
1118 break;
1119 #ifdef MISSIONPACK
1120 case GTS_REDOBELISK_ATTACKED: // Overload: red obelisk is being attacked
1121 if (cg.snap->ps.persistant[PERS_TEAM] == TEAM_RED) {
1122 CG_AddBufferedSound( cgs.media.yourBaseIsUnderAttackSound );
1123 }
1124 break;
1125 case GTS_BLUEOBELISK_ATTACKED: // Overload: blue obelisk is being attacked
1126 if (cg.snap->ps.persistant[PERS_TEAM] == TEAM_BLUE) {
1127 CG_AddBufferedSound( cgs.media.yourBaseIsUnderAttackSound );
1128 }
1129 break;
1130 #endif
1131
1132 case GTS_REDTEAM_SCORED:
1133 CG_AddBufferedSound(cgs.media.redScoredSound);
1134 break;
1135 case GTS_BLUETEAM_SCORED:
1136 CG_AddBufferedSound(cgs.media.blueScoredSound);
1137 break;
1138 case GTS_REDTEAM_TOOK_LEAD:
1139 CG_AddBufferedSound(cgs.media.redLeadsSound);
1140 break;
1141 case GTS_BLUETEAM_TOOK_LEAD:
1142 CG_AddBufferedSound(cgs.media.blueLeadsSound);
1143 break;
1144 case GTS_TEAMS_ARE_TIED:
1145 CG_AddBufferedSound( cgs.media.teamsTiedSound );
1146 break;
1147 #ifdef MISSIONPACK
1148 case GTS_KAMIKAZE:
1149 trap_S_StartLocalSound(cgs.media.kamikazeFarSound, CHAN_ANNOUNCER);
1150 break;
1151 #endif
1152 default:
1153 break;
1154 }
1155 break;
1156 }
1157
1158 case EV_PAIN:
1159 // local player sounds are triggered in CG_CheckLocalSounds,
1160 // so ignore events on the player
1161 DEBUGNAME("EV_PAIN");
1162 if ( cent->currentState.number != cg.snap->ps.clientNum ) {
1163 CG_PainEvent( cent, es->eventParm );
1164 }
1165 break;
1166
1167 case EV_DEATH1:
1168 case EV_DEATH2:
1169 case EV_DEATH3:
1170 DEBUGNAME("EV_DEATHx");
1171
1172 if (CG_WaterLevel(cent) == 3) {
1173 trap_S_StartSound(NULL, es->number, CHAN_VOICE, CG_CustomSound(es->number, "*drown.wav"));
1174 } else {
1175 trap_S_StartSound(NULL, es->number, CHAN_VOICE, CG_CustomSound(es->number, va("*death%i.wav", event - EV_DEATH1 + 1)));
1176 }
1177
1178 break;
1179
1180
1181 case EV_OBITUARY:
1182 DEBUGNAME("EV_OBITUARY");
1183 CG_Obituary( es );
1184 break;
1185
1186 //
1187 // powerup events
1188 //
1189 case EV_POWERUP_QUAD:
1190 DEBUGNAME("EV_POWERUP_QUAD");
1191 if ( es->number == cg.snap->ps.clientNum ) {
1192 cg.powerupActive = PW_QUAD;
1193 cg.powerupTime = cg.time;
1194 }
1195 trap_S_StartSound (NULL, es->number, CHAN_ITEM, cgs.media.quadSound );
1196 break;
1197 case EV_POWERUP_BATTLESUIT:
1198 DEBUGNAME("EV_POWERUP_BATTLESUIT");
1199 if ( es->number == cg.snap->ps.clientNum ) {
1200 cg.powerupActive = PW_BATTLESUIT;
1201 cg.powerupTime = cg.time;
1202 }
1203 trap_S_StartSound (NULL, es->number, CHAN_ITEM, cgs.media.protectSound );
1204 break;
1205 case EV_POWERUP_REGEN:
1206 DEBUGNAME("EV_POWERUP_REGEN");
1207 if ( es->number == cg.snap->ps.clientNum ) {
1208 cg.powerupActive = PW_REGEN;
1209 cg.powerupTime = cg.time;
1210 }
1211 trap_S_StartSound (NULL, es->number, CHAN_ITEM, cgs.media.regenSound );
1212 break;
1213
1214 case EV_GIB_PLAYER:
1215 DEBUGNAME("EV_GIB_PLAYER");
1216 // don't play gib sound when using the kamikaze because it interferes
1217 // with the kamikaze sound, downside is that the gib sound will also
1218 // not be played when someone is gibbed while just carrying the kamikaze
1219 if ( !(es->eFlags & EF_KAMIKAZE) ) {
1220 trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.gibSound );
1221 }
1222 CG_GibPlayer( cent->lerpOrigin );
1223 break;
1224
1225 case EV_STOPLOOPINGSOUND:
1226 DEBUGNAME("EV_STOPLOOPINGSOUND");
1227 trap_S_StopLoopingSound( es->number );
1228 es->loopSound = 0;
1229 break;
1230
1231 case EV_DEBUG_LINE:
1232 DEBUGNAME("EV_DEBUG_LINE");
1233 CG_Beam( cent );
1234 break;
1235
1236 default:
1237 DEBUGNAME("UNKNOWN");
1238 CG_Error( "Unknown event: %i", event );
1239 break;
1240 }
1241
1242 }
1243
1244
1245 /*
1246 ==============
1247 CG_CheckEvents
1248
1249 ==============
1250 */
1251 void CG_CheckEvents( centity_t *cent ) {
1252 // check for event-only entities
1253 if ( cent->currentState.eType > ET_EVENTS ) {
1254 if ( cent->previousEvent ) {
1255 return; // already fired
1256 }
1257 // if this is a player event set the entity number of the client entity number
1258 if ( cent->currentState.eFlags & EF_PLAYER_EVENT ) {
1259 cent->currentState.number = cent->currentState.otherEntityNum;
1260 }
1261
1262 cent->previousEvent = 1;
1263
1264 cent->currentState.event = cent->currentState.eType - ET_EVENTS;
1265 } else {
1266 // check for events riding with another entity
1267 if ( cent->currentState.event == cent->previousEvent ) {
1268 return;
1269 }
1270 cent->previousEvent = cent->currentState.event;
1271 if ( ( cent->currentState.event & ~EV_EVENT_BITS ) == 0 ) {
1272 return;
1273 }
1274 }
1275
1276 // calculate the position at exactly the frame time
1277 BG_EvaluateTrajectory( &cent->currentState.pos, cg.snap->serverTime, cent->lerpOrigin );
1278 CG_SetEntitySoundPosition( cent );
1279
1280 CG_EntityEvent( cent, cent->lerpOrigin );
1281 }
1282