aboutsummaryrefslogtreecommitdiffstats
path: root/code/game/g_rankings.c
blob: 862f3072dfb1c5204d062ed8a26106236d8fe850 (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
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.

This file is part of Quake III Arena source code.

Quake III Arena source code 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.

Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
// g_rankings.c -- reports for global rankings system

#include "g_local.h"
#include "g_rankings.h"

/*
================
G_RankRunFrame
================
*/
void G_RankRunFrame()
{
	gentity_t*		ent;
	gentity_t*		ent2;
	grank_status_t	old_status;
	grank_status_t	status;
	int				time;
	int				i;
	int				j;

	if( !trap_RankCheckInit() ) 
	{
		trap_RankBegin( GR_GAMEKEY );
	}

	trap_RankPoll();
	
	if( trap_RankActive() )
	{
		for( i = 0; i < level.maxclients; i++ )
		{
			ent = &(g_entities[i]);
			if ( !ent->inuse )
				continue;
			if ( ent->client == NULL )
				continue;
			if ( ent->r.svFlags & SVF_BOT)
			{
				// no bots in ranked games
				trap_SendConsoleCommand( EXEC_INSERT, va("kick %s\n", 
					ent->client->pers.netname) );
				continue;
			}

			old_status = ent->client->client_status;
			status = trap_RankUserStatus( i );
			
			if( ent->client->client_status != status )
			{
				// inform client of current status
				// not needed for client side log in
				trap_SendServerCommand( i, va("rank_status %i\n",status) );
				if ( i == 0 )
				{
					int j = 0;
				}
				ent->client->client_status = status;
			}
			
			switch( status )
			{
			case QGR_STATUS_NEW:
			case QGR_STATUS_SPECTATOR:
				if( ent->client->sess.sessionTeam != TEAM_SPECTATOR )
				{
					ent->client->sess.sessionTeam = TEAM_SPECTATOR;
					ent->client->sess.spectatorState = SPECTATOR_FREE;
					ClientSpawn( ent );
					// make sure by now CS_GRAND rankingsGameID is ready
					trap_SendServerCommand( i, va("rank_status %i\n",status) );
					trap_SendServerCommand( i, "rank_menu\n" );
				}
				break;
			case QGR_STATUS_NO_USER:
			case QGR_STATUS_BAD_PASSWORD:
			case QGR_STATUS_TIMEOUT:
			case QGR_STATUS_NO_MEMBERSHIP:
			case QGR_STATUS_INVALIDUSER:
			case QGR_STATUS_ERROR:
				if( (ent->r.svFlags & SVF_BOT) == 0 )
				{
					trap_RankUserReset( ent->s.clientNum );
				}
				break;
			case QGR_STATUS_ACTIVE:
				if( (ent->client->sess.sessionTeam == TEAM_SPECTATOR) &&
					(g_gametype.integer < GT_TEAM) )
				{
					SetTeam( ent, "free" );
				}

				if( old_status != QGR_STATUS_ACTIVE )
				{
					// player has just become active
					for( j = 0; j < level.maxclients; j++ )
					{
						ent2 = &(g_entities[j]);
						if ( !ent2->inuse )
							continue;
						if ( ent2->client == NULL )
							continue;
						if ( ent2->r.svFlags & SVF_BOT)
							continue;

						if( (i != j) && (trap_RankUserStatus( j ) == QGR_STATUS_ACTIVE) )
						{
							trap_RankReportInt( i, j, QGR_KEY_PLAYED_WITH, 1, 0 );
						}

						// send current scores so the player's rank will show 
						// up under the crosshair immediately
						DeathmatchScoreboardMessage( ent2 );
					}
				}
				break;
			default:
				break;
			}
		}

		// don't let ranked games last forever
		if( ((g_fraglimit.integer == 0) || (g_fraglimit.integer > 100)) && 
			((g_timelimit.integer == 0) || (g_timelimit.integer > 1000)) )
		{
			trap_Cvar_Set( "timelimit", "1000" );
		}
	}

	// tell time to clients so they can show current match rating
	if( level.intermissiontime == 0 )
	{
		for( i = 0; i < level.maxclients; i++ )
		{
			ent = &(g_entities[i]);
			if( ent->client == NULL )
			{
				continue;
			}

			time = (level.time - ent->client->pers.enterTime) / 1000;
			ent->client->ps.persistant[PERS_MATCH_TIME] = time;
		}
	}
}

/*
================
G_RankFireWeapon
================
*/
void G_RankFireWeapon( int self, int weapon )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	if( weapon == WP_GAUNTLET )
	{
		// the gauntlet only "fires" when it actually hits something
		return;
	}
	
	trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED, 1, 1 );
	
	switch( weapon )
	{
	case WP_MACHINEGUN:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_MACHINEGUN, 1, 1 );
		break;
	case WP_SHOTGUN:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_SHOTGUN, 1, 1 );
		break;
	case WP_GRENADE_LAUNCHER:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_GRENADE, 1, 1 );
		break;
	case WP_ROCKET_LAUNCHER:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_ROCKET, 1, 1 );
		break;
	case WP_LIGHTNING:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_LIGHTNING, 1, 1 );
		break;
	case WP_RAILGUN:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_RAILGUN, 1, 1 );
		break;
	case WP_PLASMAGUN:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_PLASMA, 1, 1 );
		break;
	case WP_BFG:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_BFG, 1, 1 );
		break;
	case WP_GRAPPLING_HOOK:
		trap_RankReportInt( self, -1, QGR_KEY_SHOT_FIRED_GRAPPLE, 1, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankDamage
================
*/
void G_RankDamage( int self, int attacker, int damage, int means_of_death )
{
	// state information to avoid counting each shotgun pellet as a hit
	static int	last_framenum = -1;
	static int	last_self = -1;
	static int	last_attacker = -1;
	static int	last_means_of_death = MOD_UNKNOWN;

	qboolean	new_hit;
	int			splash;
	int			key_hit;
	int			key_damage;
	int			key_splash;

	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	new_hit = (level.framenum != last_framenum) || 
		(self != last_self) || 
		(attacker != last_attacker) || 
		(means_of_death != last_means_of_death);

	// update state information
	last_framenum = level.framenum;
	last_self = self;
	last_attacker = attacker;
	last_means_of_death = means_of_death;

	// the gauntlet only "fires" when it actually hits something
	if( (attacker != ENTITYNUM_WORLD) && (attacker != self) && 
		(means_of_death == MOD_GAUNTLET)  && 
		(g_entities[attacker].client) )
	{
		trap_RankReportInt( attacker, -1, QGR_KEY_SHOT_FIRED_GAUNTLET, 1, 1 );
	}

	// don't track hazard damage, just deaths
	switch( means_of_death )
	{
	case MOD_WATER:
	case MOD_SLIME:
	case MOD_LAVA:
	case MOD_CRUSH:
	case MOD_TELEFRAG:
	case MOD_FALLING:
	case MOD_SUICIDE:
	case MOD_TRIGGER_HURT:
		return;
	default:
		break;
	}

	// get splash damage
	switch( means_of_death )
	{
	case MOD_GRENADE_SPLASH:
	case MOD_ROCKET_SPLASH:
	case MOD_PLASMA_SPLASH:
	case MOD_BFG_SPLASH:
		splash = damage;
		break;
	default:
		splash = 0;
		key_splash = -1;
		break;
	}
	
	// hit, damage, and splash taken
	switch( means_of_death )
	{
	case MOD_GAUNTLET:
		key_hit = QGR_KEY_HIT_TAKEN_GAUNTLET;
		key_damage = QGR_KEY_DAMAGE_TAKEN_GAUNTLET;
		break;
	case MOD_MACHINEGUN:
		key_hit = QGR_KEY_HIT_TAKEN_MACHINEGUN;
		key_damage = QGR_KEY_DAMAGE_TAKEN_MACHINEGUN;
		break;
	case MOD_SHOTGUN:
		key_hit = QGR_KEY_HIT_TAKEN_SHOTGUN;
		key_damage = QGR_KEY_DAMAGE_TAKEN_SHOTGUN;
		break;
	case MOD_GRENADE:
	case MOD_GRENADE_SPLASH:
		key_hit = QGR_KEY_HIT_TAKEN_GRENADE;
		key_damage = QGR_KEY_DAMAGE_TAKEN_GRENADE;
		key_splash = QGR_KEY_SPLASH_TAKEN_GRENADE;
		break;
	case MOD_ROCKET:
	case MOD_ROCKET_SPLASH:
		key_hit = QGR_KEY_HIT_TAKEN_ROCKET;
		key_damage = QGR_KEY_DAMAGE_TAKEN_ROCKET;
		key_splash = QGR_KEY_SPLASH_TAKEN_ROCKET;
		break;
	case MOD_PLASMA:
	case MOD_PLASMA_SPLASH:
		key_hit = QGR_KEY_HIT_TAKEN_PLASMA;
		key_damage = QGR_KEY_DAMAGE_TAKEN_PLASMA;
		key_splash = QGR_KEY_SPLASH_TAKEN_PLASMA;
		break;
	case MOD_RAILGUN:
		key_hit = QGR_KEY_HIT_TAKEN_RAILGUN;
		key_damage = QGR_KEY_DAMAGE_TAKEN_RAILGUN;
		break;
	case MOD_LIGHTNING:
		key_hit = QGR_KEY_HIT_TAKEN_LIGHTNING;
		key_damage = QGR_KEY_DAMAGE_TAKEN_LIGHTNING;
		break;
	case MOD_BFG:
	case MOD_BFG_SPLASH:
		key_hit = QGR_KEY_HIT_TAKEN_BFG;
		key_damage = QGR_KEY_DAMAGE_TAKEN_BFG;
		key_splash = QGR_KEY_SPLASH_TAKEN_BFG;
		break;
	case MOD_GRAPPLE:
		key_hit = QGR_KEY_HIT_TAKEN_GRAPPLE;
		key_damage = QGR_KEY_DAMAGE_TAKEN_GRAPPLE;
		break;
	default:
		key_hit = QGR_KEY_HIT_TAKEN_UNKNOWN;
		key_damage = QGR_KEY_DAMAGE_TAKEN_UNKNOWN;
		break;
	}

	// report general and specific hit taken
	if( new_hit )
	{
		trap_RankReportInt( self, -1, QGR_KEY_HIT_TAKEN, 1, 1 );
		trap_RankReportInt( self, -1, key_hit, 1, 1 );
	}
	
	// report general and specific damage taken
	trap_RankReportInt( self, -1, QGR_KEY_DAMAGE_TAKEN, damage, 1 );
	trap_RankReportInt( self, -1, key_damage, damage, 1 );

	// report general and specific splash taken
	if( splash != 0 )
	{
		trap_RankReportInt( self, -1, QGR_KEY_SPLASH_TAKEN, splash, 1 );
		trap_RankReportInt( self, -1, key_splash, splash, 1 );
	}

	// hit, damage, and splash given
	if( (attacker != ENTITYNUM_WORLD) && (attacker != self) )
	{
		switch( means_of_death )
		{
		case MOD_GAUNTLET:
			key_hit = QGR_KEY_HIT_GIVEN_GAUNTLET;
			key_damage = QGR_KEY_DAMAGE_GIVEN_GAUNTLET;
			break;
		case MOD_MACHINEGUN:
			key_hit = QGR_KEY_HIT_GIVEN_MACHINEGUN;
			key_damage = QGR_KEY_DAMAGE_GIVEN_MACHINEGUN;
			break;
		case MOD_SHOTGUN:
			key_hit = QGR_KEY_HIT_GIVEN_SHOTGUN;
			key_damage = QGR_KEY_DAMAGE_GIVEN_SHOTGUN;
			break;
		case MOD_GRENADE:
		case MOD_GRENADE_SPLASH:
			key_hit = QGR_KEY_HIT_GIVEN_GRENADE;
			key_damage = QGR_KEY_DAMAGE_GIVEN_GRENADE;
			key_splash = QGR_KEY_SPLASH_GIVEN_GRENADE;
			break;
		case MOD_ROCKET:
		case MOD_ROCKET_SPLASH:
			key_hit = QGR_KEY_HIT_GIVEN_ROCKET;
			key_damage = QGR_KEY_DAMAGE_GIVEN_ROCKET;
			key_splash = QGR_KEY_SPLASH_GIVEN_ROCKET;
			break;
		case MOD_PLASMA:
		case MOD_PLASMA_SPLASH:
			key_hit = QGR_KEY_HIT_GIVEN_PLASMA;
			key_damage = QGR_KEY_DAMAGE_GIVEN_PLASMA;
			key_splash = QGR_KEY_SPLASH_GIVEN_PLASMA;
			break;
		case MOD_RAILGUN:
			key_hit = QGR_KEY_HIT_GIVEN_RAILGUN;
			key_damage = QGR_KEY_DAMAGE_GIVEN_RAILGUN;
			break;
		case MOD_LIGHTNING:
			key_hit = QGR_KEY_HIT_GIVEN_LIGHTNING;
			key_damage = QGR_KEY_DAMAGE_GIVEN_LIGHTNING;
			break;
		case MOD_BFG:
		case MOD_BFG_SPLASH:
			key_hit = QGR_KEY_HIT_GIVEN_BFG;
			key_damage = QGR_KEY_DAMAGE_GIVEN_BFG;
			key_splash = QGR_KEY_SPLASH_GIVEN_BFG;
			break;
		case MOD_GRAPPLE:
			key_hit = QGR_KEY_HIT_GIVEN_GRAPPLE;
			key_damage = QGR_KEY_DAMAGE_GIVEN_GRAPPLE;
			break;
		default:
			key_hit = QGR_KEY_HIT_GIVEN_UNKNOWN;
			key_damage = QGR_KEY_DAMAGE_GIVEN_UNKNOWN;
			break;
		}
		
		// report general and specific hit given
		// jwu 8/26/00
		// had a case where attacker is 245 which is grnadeshooter attacker is 
		// g_entities index not necessarilly clientnum
		if (g_entities[attacker].client) {
			if( new_hit )
			{
				trap_RankReportInt( attacker, -1, QGR_KEY_HIT_GIVEN, 1, 1 );
				trap_RankReportInt( attacker, -1, key_hit, 1, 1 );
			}
			
			// report general and specific damage given
			trap_RankReportInt( attacker, -1, QGR_KEY_DAMAGE_GIVEN, damage, 1 );
			trap_RankReportInt( attacker, -1, key_damage, damage, 1 );

			// report general and specific splash given
			if( splash != 0 )
			{
				trap_RankReportInt( attacker, -1, QGR_KEY_SPLASH_GIVEN, splash, 1 );
				trap_RankReportInt( attacker, -1, key_splash, splash, 1 );
			}
		}
	}

	// friendly fire
	if( (attacker != self) && 
		OnSameTeam( &(g_entities[self]), &(g_entities[attacker])) &&
		(g_entities[attacker].client) )
	{
		// report teammate hit
		if( new_hit )
		{
			trap_RankReportInt( self, -1, QGR_KEY_TEAMMATE_HIT_TAKEN, 1, 1 );
			trap_RankReportInt( attacker, -1, QGR_KEY_TEAMMATE_HIT_GIVEN, 1, 
				1 );
		}

		// report teammate damage
		trap_RankReportInt( self, -1, QGR_KEY_TEAMMATE_DAMAGE_TAKEN, damage, 
			1 );
		trap_RankReportInt( attacker, -1, QGR_KEY_TEAMMATE_DAMAGE_GIVEN, 
			damage, 1 );
			
		// report teammate splash
		if( splash != 0 )
		{
			trap_RankReportInt( self, -1, QGR_KEY_TEAMMATE_SPLASH_TAKEN, 
				splash, 1 );
			trap_RankReportInt( attacker, -1, QGR_KEY_TEAMMATE_SPLASH_GIVEN, 
				splash, 1 );
		}
	}
}

/*
================
G_RankPlayerDie
================
*/
void G_RankPlayerDie( int self, int attacker, int means_of_death )
{
	int	p1;
	int	p2;

	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	if( attacker == ENTITYNUM_WORLD )
	{
		p1 = self;
		p2 = -1;
		
		trap_RankReportInt( p1, p2, QGR_KEY_HAZARD_DEATH, 1, 1 );

		switch( means_of_death )
		{
		case MOD_WATER:
			trap_RankReportInt( p1, p2, QGR_KEY_WATER, 1, 1 );
			break;
		case MOD_SLIME:
			trap_RankReportInt( p1, p2, QGR_KEY_SLIME, 1, 1 );
			break;
		case MOD_LAVA:
			trap_RankReportInt( p1, p2, QGR_KEY_LAVA, 1, 1 );
			break;
		case MOD_CRUSH:
			trap_RankReportInt( p1, p2, QGR_KEY_CRUSH, 1, 1 );
			break;
		case MOD_TELEFRAG:
			trap_RankReportInt( p1, p2, QGR_KEY_TELEFRAG, 1, 1 );
			break;
		case MOD_FALLING:
			trap_RankReportInt( p1, p2, QGR_KEY_FALLING, 1, 1 );
			break;
		case MOD_SUICIDE:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_CMD, 1, 1 );
			break;
		case MOD_TRIGGER_HURT:
			trap_RankReportInt( p1, p2, QGR_KEY_TRIGGER_HURT, 1, 1 );
			break;
		default:
			trap_RankReportInt( p1, p2, QGR_KEY_HAZARD_MISC, 1, 1 );
			break;
		}
	}
	else if( attacker == self )
	{
		p1 = self;
		p2 = -1;
		
		trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE, 1, 1 );
		
		switch( means_of_death )
		{
		case MOD_GAUNTLET:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_GAUNTLET, 1, 1 );
			break;
		case MOD_MACHINEGUN:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_MACHINEGUN, 1, 1 );
			break;
		case MOD_SHOTGUN:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_SHOTGUN, 1, 1 );
			break;
		case MOD_GRENADE:
		case MOD_GRENADE_SPLASH:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_GRENADE, 1, 1 );
			break;
		case MOD_ROCKET:
		case MOD_ROCKET_SPLASH:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_ROCKET, 1, 1 );
			break;
		case MOD_PLASMA:
		case MOD_PLASMA_SPLASH:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_PLASMA, 1, 1 );
			break;
		case MOD_RAILGUN:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_RAILGUN, 1, 1 );
			break;
		case MOD_LIGHTNING:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_LIGHTNING, 1, 1 );
			break;
		case MOD_BFG:
		case MOD_BFG_SPLASH:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_BFG, 1, 1 );
			break;
		case MOD_GRAPPLE:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_GRAPPLE, 1, 1 );
			break;
		default:
			trap_RankReportInt( p1, p2, QGR_KEY_SUICIDE_UNKNOWN, 1, 1 );
			break;
		}
	}
	else
	{
		p1 = attacker;
		p2 = self;

		trap_RankReportInt( p1, p2, QGR_KEY_FRAG, 1, 1 );
		
		switch( means_of_death )
		{
		case MOD_GAUNTLET:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_GAUNTLET, 1, 1 );
			break;
		case MOD_MACHINEGUN:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_MACHINEGUN, 1, 1 );
			break;
		case MOD_SHOTGUN:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_SHOTGUN, 1, 1 );
			break;
		case MOD_GRENADE:
		case MOD_GRENADE_SPLASH:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_GRENADE, 1, 1 );
			break;
		case MOD_ROCKET:
		case MOD_ROCKET_SPLASH:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_ROCKET, 1, 1 );
			break;
		case MOD_PLASMA:
		case MOD_PLASMA_SPLASH:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_PLASMA, 1, 1 );
			break;
		case MOD_RAILGUN:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_RAILGUN, 1, 1 );
			break;
		case MOD_LIGHTNING:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_LIGHTNING, 1, 1 );
			break;
		case MOD_BFG:
		case MOD_BFG_SPLASH:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_BFG, 1, 1 );
			break;
		case MOD_GRAPPLE:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_GRAPPLE, 1, 1 );
			break;
		default:
			trap_RankReportInt( p1, p2, QGR_KEY_FRAG_UNKNOWN, 1, 1 );
			break;
		}
	}
}

/*
================
G_RankWeaponTime
================
*/
void G_RankWeaponTime( int self, int weapon )
{
	gclient_t*	client;
	int			time;

	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	client = g_entities[self].client;
	time = (level.time - client->weapon_change_time) / 1000;
	client->weapon_change_time = level.time;

	if( time <= 0 )
	{
		return;
	}
	
	trap_RankReportInt( self, -1, QGR_KEY_TIME, time, 1 );

	switch( weapon )
	{
	case WP_GAUNTLET:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_GAUNTLET, time, 1 );
		break;
	case WP_MACHINEGUN:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_MACHINEGUN, time, 1 );
		break;
	case WP_SHOTGUN:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_SHOTGUN, time, 1 );
		break;
	case WP_GRENADE_LAUNCHER:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_GRENADE, time, 1 );
		break;
	case WP_ROCKET_LAUNCHER:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_ROCKET, time, 1 );
		break;
	case WP_LIGHTNING:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_LIGHTNING, time, 1 );
		break;
	case WP_RAILGUN:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_RAILGUN, time, 1 );
		break;
	case WP_PLASMAGUN:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_PLASMA, time, 1 );
		break;
	case WP_BFG:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_BFG, time, 1 );
		break;
	case WP_GRAPPLING_HOOK:
		trap_RankReportInt( self, -1, QGR_KEY_TIME_GRAPPLE, time, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankPickupWeapon
================
*/
void G_RankPickupWeapon( int self, int weapon )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	trap_RankReportInt( self, -1, QGR_KEY_PICKUP_WEAPON, 1, 1 );
	switch( weapon )
	{
	case WP_GAUNTLET:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_GAUNTLET, 1, 1 );
		break;
	case WP_MACHINEGUN:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_MACHINEGUN, 1, 1 );
		break;
	case WP_SHOTGUN:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_SHOTGUN, 1, 1 );
		break;
	case WP_GRENADE_LAUNCHER:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_GRENADE, 1, 1 );
		break;
	case WP_ROCKET_LAUNCHER:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_ROCKET, 1, 1 );
		break;
	case WP_LIGHTNING:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_LIGHTNING, 1, 1 );
		break;
	case WP_RAILGUN:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_RAILGUN, 1, 1 );
		break;
	case WP_PLASMAGUN:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_PLASMA, 1, 1 );
		break;
	case WP_BFG:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_BFG, 1, 1 );
		break;
	case WP_GRAPPLING_HOOK:
		trap_RankReportInt( self, -1, QGR_KEY_PICKUP_GRAPPLE, 1, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankPickupAmmo
================
*/
void G_RankPickupAmmo( int self, int weapon, int quantity )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	trap_RankReportInt( self, -1, QGR_KEY_BOXES, 1, 1 );
	trap_RankReportInt( self, -1, QGR_KEY_ROUNDS, quantity, 1 );
	
	switch( weapon )
	{
	case WP_MACHINEGUN:
		trap_RankReportInt( self, -1, QGR_KEY_BOXES_BULLETS, 1, 1 );
		trap_RankReportInt( self, -1, QGR_KEY_ROUNDS_BULLETS, quantity, 1 );
		break;
	case WP_SHOTGUN:
		trap_RankReportInt( self, -1, QGR_KEY_BOXES_SHELLS, 1, 1 );
		trap_RankReportInt( self, -1, QGR_KEY_ROUNDS_SHELLS, quantity, 1 );
		break;
	case WP_GRENADE_LAUNCHER:
		trap_RankReportInt( self, -1, QGR_KEY_BOXES_GRENADES, 1, 1 );
		trap_RankReportInt( self, -1, QGR_KEY_ROUNDS_GRENADES, quantity, 1 );
		break;
	case WP_ROCKET_LAUNCHER:
		trap_RankReportInt( self, -1, QGR_KEY_BOXES_ROCKETS, 1, 1 );
		trap_RankReportInt( self, -1, QGR_KEY_ROUNDS_ROCKETS, quantity, 1 );
		break;
	case WP_LIGHTNING:
		trap_RankReportInt( self, -1, QGR_KEY_BOXES_LG_AMMO, 1, 1 );
		trap_RankReportInt( self, -1, QGR_KEY_ROUNDS_LG_AMMO, quantity, 1 );
		break;
	case WP_RAILGUN:
		trap_RankReportInt( self, -1, QGR_KEY_BOXES_SLUGS, 1, 1 );
		trap_RankReportInt( self, -1, QGR_KEY_ROUNDS_SLUGS, quantity, 1 );
		break;
	case WP_PLASMAGUN:
		trap_RankReportInt( self, -1, QGR_KEY_BOXES_CELLS, 1, 1 );
		trap_RankReportInt( self, -1, QGR_KEY_ROUNDS_CELLS, quantity, 1 );
		break;
	case WP_BFG:
		trap_RankReportInt( self, -1, QGR_KEY_BOXES_BFG_AMMO, 1, 1 );
		trap_RankReportInt( self, -1, QGR_KEY_ROUNDS_BFG_AMMO, quantity, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankPickupHealth
================
*/
void G_RankPickupHealth( int self, int quantity )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	trap_RankReportInt( self, -1, QGR_KEY_HEALTH, 1, 1 );
	trap_RankReportInt( self, -1, QGR_KEY_HEALTH_TOTAL, quantity, 1 );

	switch( quantity )
	{
	case 5:
		trap_RankReportInt( self, -1, QGR_KEY_HEALTH_5, 1, 1 );
		break;
	case 25:
		trap_RankReportInt( self, -1, QGR_KEY_HEALTH_25, 1, 1 );
		break;
	case 50:
		trap_RankReportInt( self, -1, QGR_KEY_HEALTH_50, 1, 1 );
		break;
	case 100:
		trap_RankReportInt( self, -1, QGR_KEY_HEALTH_MEGA, 1, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankPickupArmor
================
*/
void G_RankPickupArmor( int self, int quantity )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	trap_RankReportInt( self, -1, QGR_KEY_ARMOR, 1, 1 );
	trap_RankReportInt( self, -1, QGR_KEY_ARMOR_TOTAL, quantity, 1 );

	switch( quantity )
	{
	case 5:
		trap_RankReportInt( self, -1, QGR_KEY_ARMOR_SHARD, 1, 1 );
		break;
	case 50:
		trap_RankReportInt( self, -1, QGR_KEY_ARMOR_YELLOW, 1, 1 );
		break;
	case 100:
		trap_RankReportInt( self, -1, QGR_KEY_ARMOR_RED, 1, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankPickupPowerup
================
*/
void G_RankPickupPowerup( int self, int powerup )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	// ctf flags are treated as powerups
	if( (powerup == PW_REDFLAG) || (powerup == PW_BLUEFLAG) )
	{
		trap_RankReportInt( self, -1, QGR_KEY_FLAG_PICKUP, 1, 1 );
		return;
	}

	trap_RankReportInt( self, -1, QGR_KEY_POWERUP, 1, 1 );
	
	switch( powerup )
	{
	case PW_QUAD:
		trap_RankReportInt( self, -1, QGR_KEY_QUAD, 1, 1 );
		break;
	case PW_BATTLESUIT:
		trap_RankReportInt( self, -1, QGR_KEY_SUIT, 1, 1 );
		break;
	case PW_HASTE:
		trap_RankReportInt( self, -1, QGR_KEY_HASTE, 1, 1 );
		break;
	case PW_INVIS:
		trap_RankReportInt( self, -1, QGR_KEY_INVIS, 1, 1 );
		break;
	case PW_REGEN:
		trap_RankReportInt( self, -1, QGR_KEY_REGEN, 1, 1 );
		break;
	case PW_FLIGHT:
		trap_RankReportInt( self, -1, QGR_KEY_FLIGHT, 1, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankPickupHoldable
================
*/
void G_RankPickupHoldable( int self, int holdable )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	switch( holdable )
	{
	case HI_MEDKIT:
		trap_RankReportInt( self, -1, QGR_KEY_MEDKIT, 1, 1 );
		break;
	case HI_TELEPORTER:
		trap_RankReportInt( self, -1, QGR_KEY_TELEPORTER, 1, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankUseHoldable
================
*/
void G_RankUseHoldable( int self, int holdable )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	switch( holdable )
	{
	case HI_MEDKIT:
		trap_RankReportInt( self, -1, QGR_KEY_MEDKIT_USE, 1, 1 );
		break;
	case HI_TELEPORTER:
		trap_RankReportInt( self, -1, QGR_KEY_TELEPORTER_USE, 1, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankReward
================
*/
void G_RankReward( int self, int award )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	switch( award )
	{
	case EF_AWARD_IMPRESSIVE:
		trap_RankReportInt( self, -1, QGR_KEY_IMPRESSIVE, 1, 1 );
		break;
	case EF_AWARD_EXCELLENT:
		trap_RankReportInt( self, -1, QGR_KEY_EXCELLENT, 1, 1 );
		break;
	default:
		break;
	}
}

/*
================
G_RankCapture
================
*/
void G_RankCapture( int self )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	trap_RankReportInt( self, -1, QGR_KEY_FLAG_CAPTURE, 1, 1 );
}

/*
================
G_RankUserTeamName
================
*/
void G_RankUserTeamName( int self, char* team_name )
{
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	trap_RankReportStr( self, -1, QGR_KEY_TEAM_NAME, team_name );
}

/*
================
G_RankClientDisconnect
================
*/
void G_RankClientDisconnect( int self )
{
	gclient_t*	client;
	int			time;
	int			match_rating;
	
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	// match rating
	client = g_entities[self].client;
	time = (level.time - client->pers.enterTime) / 1000;
	if( time < 60 )
	{
		match_rating = 0;
	}
	else
	{
		match_rating = client->ps.persistant[PERS_MATCH_RATING] / time;
	}
	trap_RankReportInt( self, -1, QGR_KEY_MATCH_RATING, match_rating, 0 );
}

/*
================
G_RankGameOver
================
*/
void G_RankGameOver( void )
{
	int		i;
	char	str[MAX_INFO_VALUE];
	int		num;
	
	if( level.warmupTime != 0 )
	{
		// no reports during warmup period
		return;
	}
	
	for( i = 0; i < level.maxclients; i++ )
	{
		if( trap_RankUserStatus( i ) == QGR_STATUS_ACTIVE )
		{
			G_RankClientDisconnect( i );
		}
	}
	
	// hostname
	trap_Cvar_VariableStringBuffer( "sv_hostname", str, sizeof(str) );
	trap_RankReportStr( -1, -1, QGR_KEY_HOSTNAME, str );

	// map
	trap_Cvar_VariableStringBuffer( "mapname", str, sizeof(str) );
	trap_RankReportStr( -1, -1, QGR_KEY_MAP, str );

	// mod
	trap_Cvar_VariableStringBuffer( "fs_game", str, sizeof(str) );
	trap_RankReportStr( -1, -1, QGR_KEY_MOD, str );

	// gametype
	num = trap_Cvar_VariableIntegerValue("g_gametype");
	trap_RankReportInt( -1, -1, QGR_KEY_GAMETYPE, num, 0 );
	
	// fraglimit
	num = trap_Cvar_VariableIntegerValue("fraglimit");
	trap_RankReportInt( -1, -1, QGR_KEY_FRAGLIMIT, num, 0 );
	
	// timelimit
	num = trap_Cvar_VariableIntegerValue("timelimit");
	trap_RankReportInt( -1, -1, QGR_KEY_TIMELIMIT, num, 0 );

	// maxclients
	num = trap_Cvar_VariableIntegerValue("sv_maxclients");
	trap_RankReportInt( -1, -1, QGR_KEY_MAXCLIENTS, num, 0 );

	// maxrate
	num = trap_Cvar_VariableIntegerValue("sv_maxRate");
	trap_RankReportInt( -1, -1, QGR_KEY_MAXRATE, num, 0 );

	// minping
	num = trap_Cvar_VariableIntegerValue("sv_minPing");
	trap_RankReportInt( -1, -1, QGR_KEY_MINPING, num, 0 );

	// maxping
	num = trap_Cvar_VariableIntegerValue("sv_maxPing");
	trap_RankReportInt( -1, -1, QGR_KEY_MAXPING, num, 0 );

	// dedicated
	num = trap_Cvar_VariableIntegerValue("dedicated");
	trap_RankReportInt( -1, -1, QGR_KEY_DEDICATED, num, 0 );

	// version
	trap_Cvar_VariableStringBuffer( "version", str, sizeof(str) );
	trap_RankReportStr( -1, -1, QGR_KEY_VERSION, str );
}