summaryrefslogtreecommitdiff
path: root/src/cgame/cg_event.c
blob: 4ce2b251f37fac8ad4c7f28d5ad571b0a9210eb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2000-2009 Darklegion Development

This file is part of Tremulous.

Tremulous is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

Tremulous is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Tremulous; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/

// cg_event.c -- handle entity events at snapshot or playerstate transitions


#include "cg_local.h"

/*
=============
CG_Obituary
=============
*/
static void CG_Obituary( entityState_t *ent )
{
  int           mod;
  int           target, attacker;
  char          *message;
  char          *message2;
  const char    *targetInfo;
  const char    *attackerInfo;
  char          targetName[ MAX_NAME_LENGTH ];
  char          attackerName[ MAX_NAME_LENGTH ];
  char          className[ 64 ];
  gender_t      gender;
  clientInfo_t  *ci;
  qboolean      teamKill = qfalse;

  target = ent->otherEntityNum;
  attacker = ent->otherEntityNum2;
  mod = ent->eventParm;

  if( target < 0 || target >= MAX_CLIENTS )
    CG_Error( "CG_Obituary: target out of range" );

  ci = &cgs.clientinfo[ target ];
  gender = ci->gender;

  if( attacker < 0 || attacker >= MAX_CLIENTS )
  {
    attacker = ENTITYNUM_WORLD;
    attackerInfo = NULL;
  }
  else
  {
    attackerInfo = CG_ConfigString( CS_PLAYERS + attacker );
    if( ci && cgs.clientinfo[ attacker ].team == ci->team )
      teamKill = qtrue;
  }

  targetInfo = CG_ConfigString( CS_PLAYERS + target );

  if( !targetInfo )
    return;

  Q_strncpyz( targetName, Info_ValueForKey( targetInfo, "n" ), sizeof( targetName ));

  message2 = "";

  // check for single client messages

  switch( mod )
  {
    case MOD_FALLING:
      message = "^5fell fowl to gravity";
      break;
    case MOD_CRUSH:
      message = "^5was squished";
      break;
    case MOD_WATER:
      message = "^5forgot to pack a snorkel";
      break;
    case MOD_SLIME:
      message = "^5was sucked by an infestation slime";
      break;
    case MOD_LAVA:
      message = "^5did a back flip into the lava";
      break;
    case MOD_TARGET_LASER:
      message = "^5saw the light";
      break;
    case MOD_TRIGGER_HURT:
      message = "^5was in the wrong place";
      break;
    case MOD_HSPAWN:
      message = "^5should have run further";
      break;
    case MOD_ASPAWN:
      message = "^5shouldn't have trod in the acid";
      break;
    case MOD_MGTURRET:
      message = "^5was gunned down by a turret";
      break;
    case MOD_MGTURRET2:
      message = "^5was roasted by a flame turret";
      break;
    case MOD_TESLAGEN:
      message = "^5was zapped by a tesla generator";
      break;
    case MOD_ATUBE:
      message = "^5was melted by an acid tube";
      break;
    case MOD_OVERMIND:
      message = "^5got too close to the overmind";
      break;
    case MOD_REACTOR:
      message = "^5got too close to the reactor";
      break;
    case MOD_SLOWBLOB:
      message = "^5should have visited a medical station";
      break;
    case MOD_SWARM:
      message = "^5was hunted down by the swarm";
      break;
    case MOD_SPITEFUL_ABCESS:
      message = "^5was raped by a Spiteful Abcess";
      break;
    case MOD_WARP_BLOCKED:
      message = "^5warped into a wall";
      break;
    default:
      message = NULL;
      break;
  }

  if( !message && attacker == target )
  {
    switch( mod )
    {
      case MOD_FLAMER_SPLASH:
      case MOD_LEVEL4_FLAMES:
        if( gender == GENDER_FEMALE )
          message = "^5toasted herself";
        else if( gender == GENDER_NEUTER )
          message = "^5toasted itself";
        else
          message = "^5toasted himself";
        break;

      case MOD_LCANNON_SPLASH:
        if( gender == GENDER_FEMALE )
          message = "^5irradiated herself";
        else if( gender == GENDER_NEUTER )
          message = "^5irradiated itself";
        else
          message = "^5irradiated himself";
        break;


      case MOD_ROCKETL_SPLASH:
        if( gender == GENDER_FEMALE )
          message = "^5blew herself up";
        else if( gender == GENDER_NEUTER )
          message = "^5blew itself up";
        else
          message = "^5blew himself up";
        break;

      case MOD_PSAWBLADE:
        if( gender == GENDER_FEMALE )
          message = "^5sliced herself up";
        else if( gender == GENDER_NEUTER )
          message = "^5sliced itself up";
        else
          message = "^5sliced himself up";
        break;
		
      case MOD_MD2:
        if( gender == GENDER_FEMALE )
          message = "^5 vaporized herself up";
        else if( gender == GENDER_NEUTER )
          message = "^vaporized itself up";
        else
          message = "^vaporized himself up";
        break;	
		
      case MOD_GRENADE:
        if( gender == GENDER_FEMALE )
          message = "^5blew herself up";
        else if( gender == GENDER_NEUTER )
          message = "^5blew itself up";
        else
          message = "^5blew himself up";
        break;

      case MOD_LEVEL3_BOUNCEBALL:
        if( gender == GENDER_FEMALE )
          message = "^5sniped herself";
        else if( gender == GENDER_NEUTER )
          message = "^5sniped itself";
        else
          message = "^5sniped himself";
        break;

      case MOD_LEVEL5_PRICKLES:
        if( gender == GENDER_FEMALE )
          message = "^5spiked herself";
        else if( gender == GENDER_NEUTER )
          message = "^5spiked itself";
        else
          message = "^5spiked himself";
        break;
		
      case MOD_PRIFLE:
        if( gender == GENDER_FEMALE )
          message = "^5pulse rifled herself";
        else if( gender == GENDER_NEUTER )
          message = "^5pulse rifled itself";
        else
          message = "^5pulse rifled himself";
        break;
        

      case MOD_MINE:
        if( gender == GENDER_FEMALE )
          message = "^5was betrayed by own mine";
        else if( gender == GENDER_NEUTER )
          message = "^5it betrayed by own mine";
        else
          message = "^5was betrayed by own mine";
        break;
		
		case MOD_FLAMES:
        if( gender == GENDER_FEMALE )
          message = "^5was terminated by own flames";
        else if( gender == GENDER_NEUTER )
          message = "^5it terminated by own flames";
        else
          message = "^5was terminated by own flames";
        break;

      default:
        if( gender == GENDER_FEMALE )
          message = "^5killed herself";
        else if( gender == GENDER_NEUTER )
          message = "^5killed itself";
        else
          message = "^5killed himself";
        break;
    }
  }

  if( message )
  {
    CG_Printf( "%s" S_COLOR_WHITE " %s\n", targetName, message );
    return;
  }

  // check for double client messages
  if( !attackerInfo )
  {
    attacker = ENTITYNUM_WORLD;
    strcpy( attackerName, "noname" );
  }
  else
  {
    Q_strncpyz( attackerName, Info_ValueForKey( attackerInfo, "n" ), sizeof( attackerName ));
    // check for kill messages about the current clientNum
    if( target == cg.snap->ps.clientNum )
      Q_strncpyz( cg.killerName, attackerName, sizeof( cg.killerName ) );
  }

  if( attacker != ENTITYNUM_WORLD )
  {
    switch( mod )
    {
      case MOD_PAINSAW:
        message = "^5was sawn by^7";
        break;
      case MOD_BLASTER:
        message = "^5was blasted by^7";
        break;
      case MOD_MACHINEGUN:
        message = "^5was machinegunned by^7";
        break;
      case MOD_CHAINGUN:
        message = "^5was chaingunned by^7";
        break;
      case MOD_SHOTGUN:
        message = "^5was gunned down by^7";
        break;
      case MOD_PRIFLE:
        message = "^5was pulse rifled by^7";
        break;
      case MOD_MDRIVER:
        message = "^5was mass driven by^7";
        break;
      case MOD_MD2:
        message = "^5was vaporized by^7";
        break;
      case MOD_LASGUN:
        message = "^5was lasgunned by^7";
        break;
      case MOD_FLAMER:
        message = "^5was grilled by^7";
        message2 = "^5's ^5flamer";
        break;
      case MOD_FLAMER_SPLASH:
        message = "^5was toasted by^7";
        message2 = "^5's ^5flamer";
        break;
      case MOD_LCANNON:
        message = "^5felt the full force of^7";
        message2 = "^5's ^5lucifer cannon";
        break;
      case MOD_LCANNON_SPLASH:
        message = "^5was caught in the fallout of^7";
        message2 = "^5's ^5lucifer cannon";
        break;
      case MOD_ROCKETL:
        message = "^5ate^7";
        message2 = "^5's ^5rocket";
        break;
      case MOD_ROCKETL_SPLASH:
        message = "^5almost dodged^7";
        message2 = "^5's ^5rocket";
        break;
      case MOD_LIGHTNING:
        message = "^5was electrocuted by^7";
        break;
      case MOD_GRENADE:
        message = "^5couldn't escape^7";
        message2 = "^5's ^5grenade";
        break;
      case MOD_PSAWBLADE:
        message = "^5was sliced by^7";
        message2 = "^5's ^5blades";
        break;
      case MOD_MINE:
        message = "^5found^7";
        message2 = "^5's ^5mine";
        break;  

     case MOD_FLAMES:
     case MOD_LEVEL4_FLAMES:
        message = "^5tasted^7";
        message2 = "^5's ^5flames";
        break;

      case MOD_ABUILDER_CLAW:
        message = "^5should leave^7";
        message2 = "^5's ^5buildings alone";
        break;
      case MOD_LEVEL0_BITE:
        message = "^5was bitten by^7";
        break;
      case MOD_LEVEL1_CLAW:
        message = "^5was swiped by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL1 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL2_CLAW:
      case MOD_LEVEL2_CLAW_UPG:
        message = "^5was clawed by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL2 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL2_ZAP:
        message = "^5was zapped by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL2 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL2_BOUNCEBALL:
        message = "^5was sniped by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL2 )->humanName );
        message2 = className;
        break;
	  case MOD_LEVEL5_CLAW:
        message = "^5was sliced by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL5 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL5_ZAP:
        message = "^5was zapped by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL5 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL5_BOUNCEBALL:
        message = "^5was sniped by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL5 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL3_CLAW:
        message = "^5was chomped by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL3 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL3_POUNCE:
        message = "^5was pounced upon by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL3 )->humanName );
        message2 = className;
        break;
		
      case MOD_LEVEL5_POUNCE:
        message = "^5was air pounced upon by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL5 )->humanName );
        message2 = className;
        break;
		
      case MOD_LEVEL5_PRICKLES:
        message = "^5was spiked by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL5 )->humanName );
        message2 = className;
        break;
		
      case MOD_LEVEL3_BOUNCEBALL:
        message = "^5was sniped by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL3 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL4_CLAW:
        message = "^5was mauled by^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL4 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL4_TRAMPLE:
        message = "^5should have gotten out of the way of^7";
        Com_sprintf( className, 64, "^5's %s",
            BG_ClassConfig( PCL_ALIEN_LEVEL4 )->humanName );
        message2 = className;
        break;
      case MOD_LEVEL4_CRUSH:
        message = "^5was crushed under^7";
        message2 = "^5's weight";
        break;

      case MOD_POISON:
        message = "^5should have used a medkit against^7";
        message2 = "^5's poison";
        break;

      case MOD_TELEFRAG:
        message = "^5tried to invade^7";
        message2 = "^5's personal space";
        break;
        
      default:
        message = "^5was killed by^7";
        break;
    }

    if( message )
    {
      CG_Printf( "%s" S_COLOR_WHITE " %s %s%s" S_COLOR_WHITE "%s\n",
        targetName, message,
        ( teamKill ) ? S_COLOR_RED "TEAMMATE " S_COLOR_WHITE : "",
        attackerName, message2 );
      if( teamKill && attacker == cg.clientNum )
      {
        CG_CenterPrint( va ( "You killed " S_COLOR_RED "TEAMMATE "
          S_COLOR_WHITE "%s", targetName ),
          SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH );
      }
      return;
    }
  }

  // we don't know what it was
  CG_Printf( "%s" S_COLOR_CYAN " ^5died\n", targetName );
}



//==========================================================================

/*
================
CG_PainEvent

Also called by playerstate transition
================
*/
void CG_PainEvent( centity_t *cent, int health )
{
  char  *snd;

  // don't do more than two pain sounds a second
  if( cg.time - cent->pe.painTime < 500 )
    return;

  if( health < 25 )
    snd = "*pain25_1.wav";
  else if( health < 50 )
    snd = "*pain50_1.wav";
  else if( health < 75 )
    snd = "*pain75_1.wav";
  else
    snd = "*pain100_1.wav";

  trap_S_StartSound( NULL, cent->currentState.number, CHAN_VOICE,
    CG_CustomSound( cent->currentState.number, snd ) );

  // save pain time for programitic twitch animation
  cent->pe.painTime = cg.time;
  cent->pe.painDirection ^= 1;
}

/*
================
CG_HeadShotEvent

Also called by playerstate transition
================
*/
void CG_HeadShotEvent( centity_t *cent, int health )
{
  particleSystem_t *ps;

  if( !cg_bleedSelfHeadShots.integer &&
      cent->currentState.number == cg.snap->ps.clientNum )
    return;

  ps = CG_SpawnNewParticleSystem( cgs.media.headShotPS );
  if( CG_IsParticleSystemValid( &ps ) )
  {
    CG_SetAttachmentCent( &ps->attachment, cent );
    CG_AttachToCent( &ps->attachment );
  }
  //trap_S_StartSound( NULL, es->number, CHAN_VOICE, cgs.media.humanGibSound );
}

/*
=========================
CG_Level2Zap
=========================
*/
static void CG_Level2Zap( entityState_t *es )
{
  int           i;
  centity_t     *source = NULL, *target = NULL;

  if( es->misc < 0 || es->misc >= MAX_CLIENTS )
    return;

  source = &cg_entities[ es->misc ];
  for( i = 0; i <= 2; i++ )
  {
    switch( i )
    {
      case 0:
        if( es->time <= 0 )
          continue;

        target = &cg_entities[ es->time ];
        break;

      case 1:
        if( es->time2 <= 0 )
          continue;

        target = &cg_entities[ es->time2 ];
        break;

      case 2:
        if( es->constantLight <= 0 )
          continue;

        target = &cg_entities[ es->constantLight ];
        break;
    }

    if( !CG_IsTrailSystemValid( &source->level2ZapTS[ i ] ) )
      source->level2ZapTS[ i ] = CG_SpawnNewTrailSystem( cgs.media.level2ZapTS );

    if( CG_IsTrailSystemValid( &source->level2ZapTS[ i ] ) )
    {
      CG_SetAttachmentCent( &source->level2ZapTS[ i ]->frontAttachment, source );
      CG_SetAttachmentCent( &source->level2ZapTS[ i ]->backAttachment, target );
      CG_AttachToCent( &source->level2ZapTS[ i ]->frontAttachment );
      CG_AttachToCent( &source->level2ZapTS[ i ]->backAttachment );
    }
  }
  source->level2ZapTime = cg.time;
}

/*
==============
CG_EntityEvent

An entity has an event value
also called by CG_CheckPlayerstateEvents
==============
*/
void CG_EntityEvent( centity_t *cent, vec3_t position )
{
  entityState_t *es;
  int           event;
  vec3_t        dir;
  const char    *s;
  int           clientNum;
  clientInfo_t  *ci;
  int           steptime;
  qboolean      warpingEnemyWraith = qfalse;

  if( cg.snap->ps.persistant[ PERS_SPECSTATE ] != SPECTATOR_NOT )
    steptime = 200;
  else
    steptime = BG_Class( cg.snap->ps.stats[ STAT_CLASS ] )->steptime;

  es = &cent->currentState;
  event = es->event & ~EV_EVENT_BITS;

  if( cg_debugEvents.integer )
    CG_Printf( "ent:%3i  event:%3i %s\n", es->number, event,
               BG_EventName( event ) );

  if( !event )
    return;

  clientNum = es->clientNum;
  if( clientNum < 0 || clientNum >= MAX_CLIENTS )
    clientNum = 0;

  ci = &cgs.clientinfo[ clientNum ];

  if( ci->team != cg.snap->ps.stats[ STAT_TEAM ] &&
      cg.snap->ps.stats[ STAT_TEAM ] != TEAM_NONE &&
      ( es->eFlags & EF_WARPING ) )
  {
    warpingEnemyWraith = qtrue;
  }

  switch( event )
  {
    //
    // movement generated events
    //
    case EV_FOOTSTEP:
      if( cg_footsteps.integer && ci->footsteps != FOOTSTEP_NONE && 
          !warpingEnemyWraith )
      {
        if( ci->footsteps == FOOTSTEP_CUSTOM )
          trap_S_StartSound( NULL, es->number, CHAN_BODY,
            ci->customFootsteps[ rand( ) & 3 ] );
        else
          trap_S_StartSound( NULL, es->number, CHAN_BODY,
            cgs.media.footsteps[ ci->footsteps ][ rand( ) & 3 ] );
      }
      break;

    case EV_FOOTSTEP_METAL:
      if( cg_footsteps.integer && ci->footsteps != FOOTSTEP_NONE &&
          !warpingEnemyWraith )
      {
        if( ci->footsteps == FOOTSTEP_CUSTOM )
          trap_S_StartSound( NULL, es->number, CHAN_BODY,
            ci->customMetalFootsteps[ rand( ) & 3 ] );
        else
          trap_S_StartSound( NULL, es->number, CHAN_BODY,
            cgs.media.footsteps[ FOOTSTEP_METAL ][ rand( ) & 3 ] );
      }
      break;

    case EV_FOOTSTEP_SQUELCH:
      if( cg_footsteps.integer && ci->footsteps != FOOTSTEP_NONE &&
          !warpingEnemyWraith )
      {
        trap_S_StartSound( NULL, es->number, CHAN_BODY,
          cgs.media.footsteps[ FOOTSTEP_FLESH ][ rand( ) & 3 ] );
      }
      break;

    case EV_FOOTSPLASH:
      if( cg_footsteps.integer && ci->footsteps != FOOTSTEP_NONE &&
          !warpingEnemyWraith )
      {
        trap_S_StartSound( NULL, es->number, CHAN_BODY,
          cgs.media.footsteps[ FOOTSTEP_SPLASH ][ rand( ) & 3 ] );
      }
      break;

    case EV_FOOTWADE:
      if( cg_footsteps.integer && ci->footsteps != FOOTSTEP_NONE &&
          !warpingEnemyWraith )
      {
        trap_S_StartSound( NULL, es->number, CHAN_BODY,
          cgs.media.footsteps[ FOOTSTEP_SPLASH ][ rand( ) & 3 ] );
      }
      break;

    case EV_SWIM:
      if( cg_footsteps.integer && ci->footsteps != FOOTSTEP_NONE &&
          !warpingEnemyWraith )
      {
        trap_S_StartSound( NULL, es->number, CHAN_BODY,
          cgs.media.footsteps[ FOOTSTEP_SPLASH ][ rand( ) & 3 ] );
      }
      break;


    case EV_FALL_SHORT:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.landSound );

      if( clientNum == cg.predictedPlayerState.clientNum )
      {
        // smooth landing z changes
        cg.landChange = -8;
        cg.landTime = cg.time;
      }
      break;

    case EV_FALL_MEDIUM:
      // use normal pain sound
      trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*pain100_1.wav" ) );

      if( clientNum == cg.predictedPlayerState.clientNum )
      {
        // smooth landing z changes
        cg.landChange = -16;
        cg.landTime = cg.time;
      }
      break;

    case EV_FALL_FAR:
      trap_S_StartSound (NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*fall1.wav" ) );
      cent->pe.painTime = cg.time;  // don't play a pain sound right after this

      if( clientNum == cg.predictedPlayerState.clientNum )
      {
        // smooth landing z changes
        cg.landChange = -24;
        cg.landTime = cg.time;
      }
      break;

    case EV_FALLING:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*falling1.wav" ) );
      break;

    case EV_STEP_4:
    case EV_STEP_8:
    case EV_STEP_12:
    case EV_STEP_16:    // smooth out step up transitions
    case EV_STEPDN_4:
    case EV_STEPDN_8:
    case EV_STEPDN_12:
    case EV_STEPDN_16:    // smooth out step down transitions
      {
        float  oldStep;
        int    delta;
        int    step;

        if( clientNum != cg.predictedPlayerState.clientNum )
          break;

        // if we are interpolating, we don't need to smooth steps
        if( cg.demoPlayback || ( cg.snap->ps.pm_flags & PMF_FOLLOW ) ||
            cg_nopredict.integer || cg_synchronousClients.integer )
          break;

        // check for stepping up before a previous step is completed
        delta = cg.time - cg.stepTime;

        if( delta < steptime )
          oldStep = cg.stepChange * ( steptime - delta ) / steptime;
        else
          oldStep = 0;

        // add this amount
        if( event >= EV_STEPDN_4 )
        {
          step = 4 * ( event - EV_STEPDN_4 + 1 );
          cg.stepChange = oldStep - step;
        }
        else
        {
          step = 4 * ( event - EV_STEP_4 + 1 );
          cg.stepChange = oldStep + step;
        }

        if( cg.stepChange > MAX_STEP_CHANGE )
          cg.stepChange = MAX_STEP_CHANGE;
        else if( cg.stepChange < -MAX_STEP_CHANGE )
          cg.stepChange = -MAX_STEP_CHANGE;

        cg.stepTime = cg.time;
        break;
      }

    case EV_JUMP:
      if( !warpingEnemyWraith )
      {
        trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*jump1.wav" ) );

        if( BG_ClassHasAbility( cg.predictedPlayerState.stats[ STAT_CLASS ], SCA_WALLJUMPER ) )
        {
          vec3_t  surfNormal, refNormal = { 0.0f, 0.0f, 1.0f };
          vec3_t  is;

          if( clientNum != cg.predictedPlayerState.clientNum )
            break;

          //set surfNormal
          VectorCopy( cg.predictedPlayerState.grapplePoint, surfNormal );

          //if we are moving from one surface to another smooth the transition
          if( !VectorCompare( surfNormal, cg.lastNormal ) && surfNormal[ 2 ] != 1.0f )
          {
            CrossProduct( refNormal, surfNormal, is );
            VectorNormalize( is );

            //add the op
            CG_addSmoothOp( is, 15.0f, 1.0f );
          }

          //copy the current normal to the lastNormal
          VectorCopy( surfNormal, cg.lastNormal );
        }
      }
      break;

    case EV_AIRPOUNCE:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.airpounce);
	  //airpounce gfx effect
	  {
        particleSystem_t *ps = CG_SpawnNewParticleSystem( cgs.media.airpounceblast );

        if( CG_IsParticleSystemValid( &ps ) )
        {
          CG_SetAttachmentCent( &ps->attachment, cent );
          CG_AttachToCent( &ps->attachment );
        }
      }
	  
      if( BG_ClassHasAbility( cg.predictedPlayerState.stats[ STAT_CLASS ], SCA_WALLJUMPER ) )
      {
        vec3_t  surfNormal, refNormal = { 0.0f, 0.0f, 1.0f };
        vec3_t  is;

        if( clientNum != cg.predictedPlayerState.clientNum )
          break;

        //set surfNormal
        VectorCopy( cg.predictedPlayerState.grapplePoint, surfNormal );

        //if we are moving from one surface to another smooth the transition
        if( !VectorCompare( surfNormal, cg.lastNormal ) && surfNormal[ 2 ] != 1.0f )
        {
          CrossProduct( refNormal, surfNormal, is );
          VectorNormalize( is );

          //add the op
          CG_addSmoothOp( is, 15.0f, 1.0f );
        }

        //copy the current normal to the lastNormal
        VectorCopy( surfNormal, cg.lastNormal );
      }

      break;
	  
    case EV_LEV1_GRAB:
      trap_S_StartSound( NULL, es->number, CHAN_VOICE, cgs.media.alienL1Grab );
      break;

    case EV_LEV4_TRAMPLE_PREPARE:
      trap_S_StartSound( NULL, es->number, CHAN_VOICE, cgs.media.alienL4ChargePrepare );
      break;

    case EV_LEV4_TRAMPLE_START:
      //FIXME: stop cgs.media.alienL4ChargePrepare playing here
      trap_S_StartSound( NULL, es->number, CHAN_VOICE, cgs.media.alienL4ChargeStart );
      break;

    case EV_TAUNT:
      if( !cg_noTaunt.integer )
        trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, "*taunt.wav" ) );
      break;

	case EV_HUMMEL:
        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.hummelSound );
      break;
	  
    case EV_WATER_TOUCH:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.watrInSound );
      break;

    case EV_WATER_LEAVE:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.watrOutSound );
      break;

    case EV_WATER_UNDER:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.watrUnSound );
      break;

    case EV_WATER_CLEAR:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, CG_CustomSound( es->number, "*gasp.wav" ) );
      break;

    //
    // weapon events
    //
    case EV_NOAMMO:
      trap_S_StartSound( NULL, es->number, CHAN_WEAPON,
                         cgs.media.weaponEmptyClick );
      break;

    case EV_CHANGE_WEAPON:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.selectSound );
      break;

    case EV_FIRE_WEAPON:
      CG_FireWeapon( cent, WPM_PRIMARY );
      break;

    case EV_FIRE_WEAPON2:
      CG_FireWeapon( cent, WPM_SECONDARY );
      break;

    case EV_FIRE_WEAPON3:
      CG_FireWeapon( cent, WPM_TERTIARY );
      break;

    //=================================================================

    //
    // other events
    //
    case EV_PLAYER_TELEPORT_IN:
      //deprecated
      break;

    case EV_PLAYER_TELEPORT_OUT:
      CG_PlayerDisconnect( position );
      break;

    case EV_BUILD_CONSTRUCT:
      //do something useful here
      break;

    case EV_BUILD_DESTROY:
      //do something useful here
      break;

    case EV_RPTUSE_SOUND:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.repeaterUseSound );
      break;

    case EV_GRENADE_BOUNCE:
      if( rand( ) & 1 )
        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.hardBounceSound1 );
      else
        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.hardBounceSound2 );
      break;

	case EV_MINE_BOUNCE:
      if( rand( ) & 1 )
        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.mineBounceSound1 );
		else
        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.mineBounceSound1 );
      break;
      break;

    case EV_ACIDBOMB_BOUNCE:
      if( rand( ) & 1 )
        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.acidBombBounceSound1 );
      else
        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.acidBombBounceSound2 );
      break;

    case EV_ROCKETL_PRIME:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.rocketlPrimeSound );
      break;

    case EV_WARP_ENTER:
      {
        particleSystem_t *ps;

        ps = CG_SpawnNewParticleSystem( cgs.media.warpEnterPS );

        if( CG_IsParticleSystemValid( &ps ) )
        {
          CG_SetAttachmentPoint( &ps->attachment, position );
          CG_AttachToPoint( &ps->attachment );
        }

        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.warpEnterSound );
      }
      break;

    case EV_WARP_EXIT:
      {
        particleSystem_t *ps;

        ps = CG_SpawnNewParticleSystem( cgs.media.warpExitPS );

        if( CG_IsParticleSystemValid( &ps ) )
        {
          CG_SetAttachmentPoint( &ps->attachment, position );
          CG_AttachToPoint( &ps->attachment );
        }

        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.warpExitSound );
      }
      break;

    //
    // missile impacts
    //
    case EV_MISSILE_HIT:
      ByteToDir( es->eventParm, dir );
      CG_MissileHitEntity( es->weapon, es->generic1, position, dir, es->otherEntityNum, es->torsoAnim );
      break;

    case EV_MISSILE_MISS:
      ByteToDir( es->eventParm, dir );
      CG_MissileHitWall( es->weapon, es->generic1, 0, position, dir, IMPACTSOUND_DEFAULT, es->torsoAnim );
      break;

    case EV_MISSILE_MISS_METAL:
      ByteToDir( es->eventParm, dir );
      CG_MissileHitWall( es->weapon, es->generic1, 0, position, dir, IMPACTSOUND_METAL, es->torsoAnim );
      break;

#define BUILDABLE_EXPLOSION_QUAKE 50

    case EV_HUMAN_BUILDABLE_EXPLOSION:
      ByteToDir( es->eventParm, dir );
      CG_HumanBuildableExplosion( position, dir, es->modelindex );
      CG_InduceViewQuake( position, BUILDABLE_EXPLOSION_QUAKE );
      break;

    case EV_ALIEN_BUILDABLE_EXPLOSION:
      ByteToDir( es->eventParm, dir );
      CG_AlienBuildableExplosion( position, dir, es->modelindex );
      
      if ( es->modelindex == BA_A_SPITEFUL_ABCESS )
        CG_AlienSpitefulAbcessExplosion( position, dir );

      CG_InduceViewQuake( position, BUILDABLE_EXPLOSION_QUAKE );
      break;
	  
//Scleim greifer schwanz f\FCr slime
    case EV_SLIMETRAIL:
      cent->currentState.weapon = WP_NONE;
      {
        centity_t *source = &cg_entities[ es->generic1 ];
        centity_t *target = &cg_entities[ es->clientNum ];
        vec3_t    sourceOffset = { 0.0f, 0.0f, 0.0f };

        if( !CG_IsTrailSystemValid( &source->muzzleTS ) )
        {
		//trailsystem
          source->muzzleTS = CG_SpawnNewTrailSystem( cgs.media.slimeTS );

          if( CG_IsTrailSystemValid( &source->muzzleTS ) )
          {
            CG_SetAttachmentCent( &source->muzzleTS->frontAttachment, source );
            CG_SetAttachmentCent( &source->muzzleTS->backAttachment, target );
            CG_AttachToCent( &source->muzzleTS->frontAttachment );
            CG_AttachToCent( &source->muzzleTS->backAttachment );
            CG_SetAttachmentOffset( &source->muzzleTS->frontAttachment, sourceOffset );

            source->muzzleTSDeathTime = cg.time + cg_teslaTrailTime.integer;
          }
        }
      }
      break;
	  



    case EV_TESLATRAIL:
      cent->currentState.weapon = WP_TESLAGEN;
      {
        centity_t *source = &cg_entities[ es->generic1 ];
        centity_t *target = &cg_entities[ es->clientNum ];
        vec3_t    sourceOffset = { 0.0f, 0.0f, 28.0f };

        if( !CG_IsTrailSystemValid( &source->muzzleTS ) )
        {
          source->muzzleTS = CG_SpawnNewTrailSystem( cgs.media.teslaZapTS );

          if( CG_IsTrailSystemValid( &source->muzzleTS ) )
          {
            CG_SetAttachmentCent( &source->muzzleTS->frontAttachment, source );
            CG_SetAttachmentCent( &source->muzzleTS->backAttachment, target );
            CG_AttachToCent( &source->muzzleTS->frontAttachment );
            CG_AttachToCent( &source->muzzleTS->backAttachment );
            CG_SetAttachmentOffset( &source->muzzleTS->frontAttachment, sourceOffset );

            source->muzzleTSDeathTime = cg.time + cg_teslaTrailTime.integer;
          }
        }
      }
      break;

    case EV_BULLET_HIT_WALL:
      ByteToDir( es->eventParm, dir );
      CG_Bullet( es->pos.trBase, es->otherEntityNum, dir, qfalse, ENTITYNUM_WORLD );
      break;

    case EV_BULLET_HIT_FLESH:
      CG_Bullet( es->pos.trBase, es->otherEntityNum, dir, qtrue, es->eventParm );
      break;

    case EV_SHOTGUN:
      CG_ShotgunFire( es );
      break;

    case EV_GENERAL_SOUND:
      if( cgs.gameSounds[ es->eventParm ] )
        trap_S_StartSound( NULL, es->number, CHAN_VOICE, cgs.gameSounds[ es->eventParm ] );
      else
      {
        s = CG_ConfigString( CS_SOUNDS + es->eventParm );
        trap_S_StartSound( NULL, es->number, CHAN_VOICE, CG_CustomSound( es->number, s ) );
      }
      break;

    case EV_GLOBAL_SOUND: // play from the player's head so it never diminishes
      if( cgs.gameSounds[ es->eventParm ] )
        trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_AUTO, cgs.gameSounds[ es->eventParm ] );
      else
      {
        s = CG_ConfigString( CS_SOUNDS + es->eventParm );
        trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_AUTO, CG_CustomSound( es->number, s ) );
      }
      break;

    case EV_PAIN:
      {
        const int health = es->eventParm & ~EVENT_HEADSHOT_BIT;
        // local player sounds are triggered in CG_CheckLocalSounds,
        // so ignore events on the player
        if( cent->currentState.number != cg.snap->ps.clientNum )
          CG_PainEvent( cent, health );
        if( es->eventParm & EVENT_HEADSHOT_BIT )
          CG_HeadShotEvent( cent, health );
      }
      break;

    case EV_DEATH1:
    case EV_DEATH2:
    case EV_DEATH3:
      trap_S_StartSound( NULL, es->number, CHAN_VOICE,
          CG_CustomSound( es->number, va( "*death%i.wav", event - EV_DEATH1 + 1 ) ) );
      if( es->eventParm & EVENT_HEADSHOT_BIT )
        CG_HeadShotEvent( cent, 0 );
      break;

    case EV_OBITUARY:
      CG_Obituary( es );
      break;

    case EV_GIB_PLAYER:
      // no gibbing
      break;

    case EV_BLEED:
      if( !warpingEnemyWraith &&
          ( cg_bleedSelfWounds.integer ||
            cent->currentState.number != cg.snap->ps.clientNum ) )
      {
        particleSystem_t *ps = NULL;
        if( ci->team == TEAM_ALIENS )
          ps = CG_SpawnNewParticleSystem( cgs.media.alienWoundsBleedPS );
        else if( ci->team == TEAM_HUMANS )
          ps = CG_SpawnNewParticleSystem( cgs.media.humanWoundsBleedPS );

        if( ( ps != NULL ) && CG_IsParticleSystemValid( &ps ) )
        {
          CG_SetAttachmentCent( &ps->attachment, cent );
          CG_AttachToCent( &ps->attachment );
        }
      }
      break;

    case EV_STOPLOOPINGSOUND:
      trap_S_StopLoopingSound( es->number );
      es->loopSound = 0;
      break;

    case EV_DEBUG_LINE:
      CG_Beam( cent );
      break;

    case EV_BUILD_DELAY:
      if( clientNum == cg.predictedPlayerState.clientNum )
      {
        trap_S_StartLocalSound( cgs.media.buildableRepairedSound, CHAN_LOCAL_SOUND );
        cg.lastBuildAttempt = cg.time;
      }
      break;

    case EV_BUILD_REPAIR:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.buildableRepairSound );
      break;

    case EV_BUILD_REPAIRED:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.buildableRepairedSound );
      break;

    case EV_OVERMIND_ATTACK:
      if( cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_ALIENS )
      {
        trap_S_StartLocalSound( cgs.media.alienOvermindAttack, CHAN_ANNOUNCER );
        CG_CenterPrint( "The Overmind is under attack!", 200, GIANTCHAR_WIDTH * 4 );
      }
      break;

    case EV_OVERMIND_DYING:
      if( cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_ALIENS )
      {
        trap_S_StartLocalSound( cgs.media.alienOvermindDying, CHAN_ANNOUNCER );
        CG_CenterPrint( "The Overmind is dying!", 200, GIANTCHAR_WIDTH * 4 );
      }
      break;

    case EV_DCC_ATTACK:
      if( cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_HUMANS )
      {
        CG_CenterPrint( "Our base is under attack!", 200, GIANTCHAR_WIDTH * 4 );
		trap_S_StartLocalSound( cgs.media.humanbaseunderatt, CHAN_ANNOUNCER );
      }
      break;

    case EV_MGTURRET_SPINUP:
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.turretSpinupSound );
      break;

    case EV_OVERMIND_SPAWNS:
      if( cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_ALIENS )
      {
        trap_S_StartLocalSound( cgs.media.alienOvermindSpawns, CHAN_ANNOUNCER );
        CG_CenterPrint( "^5The Overmind needs spawns!", 200, GIANTCHAR_WIDTH * 4 );
      }
      break;

    case EV_ALIEN_EVOLVE:
      trap_S_StartSound( NULL, es->number, CHAN_BODY, cgs.media.alienEvolveSound );
      {
        particleSystem_t *ps = CG_SpawnNewParticleSystem( cgs.media.alienEvolvePS );

        if( CG_IsParticleSystemValid( &ps ) )
        {
          CG_SetAttachmentCent( &ps->attachment, cent );
          CG_AttachToCent( &ps->attachment );
        }
      }

      if( es->number == cg.clientNum )
      {
        CG_ResetPainBlend( );
        cg.spawnTime = cg.time;
      }
      break;

    case EV_ALIEN_EVOLVE_FAILED:
      if( clientNum == cg.predictedPlayerState.clientNum )
      {
        //FIXME: change to "negative" sound
        trap_S_StartLocalSound( cgs.media.buildableRepairedSound, CHAN_LOCAL_SOUND );
        cg.lastEvolveAttempt = cg.time;
      }
      break;

    case EV_ALIEN_ACIDTUBE:
      {
        particleSystem_t *ps = CG_SpawnNewParticleSystem( cgs.media.alienAcidTubePS );

        if( CG_IsParticleSystemValid( &ps ) )
        {
          CG_SetAttachmentCent( &ps->attachment, cent );
          ByteToDir( es->eventParm, dir );
          CG_SetParticleSystemNormal( ps, dir );
          CG_AttachToCent( &ps->attachment );
        }
      }
      break;
	  
	      case EV_FORCE_FIELD:
      {
        particleSystem_t *ps = CG_SpawnNewParticleSystem( cgs.media.forcefieldPS );
        trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.forcefieldSound );

        if( CG_IsParticleSystemValid( &ps ) )
        {
          CG_SetAttachmentCent( &ps->attachment, cent );
          ByteToDir( es->eventParm, dir );
          CG_SetParticleSystemNormal( ps, dir );
          CG_AttachToCent( &ps->attachment );
        }
      }
	        break;
	      case EV_ALIEN_SLIME:
      {
        particleSystem_t *ps = CG_SpawnNewParticleSystem( cgs.media.alienSlimePS );


        if( CG_IsParticleSystemValid( &ps ) )
        {
          CG_SetAttachmentCent( &ps->attachment, cent );
          ByteToDir( es->eventParm, dir );
          CG_SetParticleSystemNormal( ps, dir );
          CG_AttachToCent( &ps->attachment );
        }
      }
      break;

    case EV_MEDKIT_USED:
      // the parameter is the healer's entity number
      {
        const int   healerNum = es->eventParm;
        const char  *configstring;
        const char  *name;

        if( healerNum != clientNum )
        {
          if( healerNum == cg.clientNum )
          {
            configstring = CG_ConfigString( clientNum + CS_PLAYERS );
            // isolate the player's name
            name = Info_ValueForKey( configstring, "n" );

            CG_Printf( S_COLOR_CYAN "You bandaged " S_COLOR_WHITE "%s" S_COLOR_CYAN "'s wounds.\n", name );
          } else if( clientNum == cg.clientNum )
          {
            configstring = CG_ConfigString( healerNum + CS_PLAYERS );
            // isolate the player's name
            name = Info_ValueForKey( configstring, "n" );

            CG_Printf( S_COLOR_WHITE "%s" S_COLOR_CYAN " bandaged your wounds.\n", name );
          }
        }
      }
      trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.medkitUseSound );
      break;

    case EV_PLAYER_RESPAWN:
      if( es->number == cg.clientNum )
        cg.spawnTime = cg.time;
      break;

    case EV_LEV2_ZAP:
      CG_Level2Zap( es );
      break;

    default:
      CG_Error( "Unknown event: %i", event );
      break;
  }
}


/*
==============
CG_CheckEvents

==============
*/
void CG_CheckEvents( centity_t *cent )
{
  entity_event_t event;
  entity_event_t oldEvent = EV_NONE;


  // check for event-only entities
  if( cent->currentState.eType > ET_EVENTS )
  {
    event = cent->currentState.eType - ET_EVENTS;

    if( cent->previousEvent )
      return; // already fired

    cent->previousEvent = 1;

    cent->currentState.event = cent->currentState.eType - ET_EVENTS;
    
    // Move the pointer to the entity that the
    // event was originally attached to
    if( cent->currentState.eFlags & EF_PLAYER_EVENT )
    {
      cent = &cg_entities[ cent->currentState.otherEntityNum ];
      oldEvent = cent->currentState.event;
      cent->currentState.event = event;
    }

  }
  else
  {
    // check for events riding with another entity
    if( cent->currentState.event == cent->previousEvent )
      return;

    cent->previousEvent = cent->currentState.event;
    if( ( cent->currentState.event & ~EV_EVENT_BITS ) == 0 )
      return;
  }

  // calculate the position at exactly the frame time
  BG_EvaluateTrajectory( &cent->currentState.pos, cg.snap->serverTime, cent->lerpOrigin );
  CG_SetEntitySoundPosition( cent );

  CG_EntityEvent( cent, cent->lerpOrigin );
  
  // If this was a reattached spilled event, restore the original event
  if( oldEvent != EV_NONE )
    cent->currentState.event = oldEvent;
}