/
g_cmds.c
2945 lines (2533 loc) · 72.4 KB
/
g_cmds.c
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
// Copyright (C) 1999-2000 Id Software, Inc.
//
#include "g_local.h"
#include "../../ui/menudef.h" // for the voice chats
//rww - for getting bot commands...
int AcceptBotCommand(char *cmd, gentity_t *pl);
//end rww
void BG_CycleInven(playerState_t *ps, int direction);
void BG_CycleForce(playerState_t *ps, int direction);
/*
==================
DeathmatchScoreboardMessage
==================
*/
void DeathmatchScoreboardMessage( gentity_t *ent ) {
char entry[1024];
char string[1400];
int stringlength;
int i, j;
gclient_t *cl;
int numSorted, scoreFlags, accuracy, perfect;
// send the latest information on all clients
string[0] = 0;
stringlength = 0;
scoreFlags = 0;
numSorted = level.numConnectedClients;
if (numSorted > MAX_CLIENT_SCORE_SEND)
{
numSorted = MAX_CLIENT_SCORE_SEND;
}
for (i=0 ; i < numSorted ; i++) {
int ping;
cl = &level.clients[level.sortedClients[i]];
if ( cl->pers.connected == CON_CONNECTING ) {
ping = -1;
} else {
ping = cl->ps.ping < 999 ? cl->ps.ping : 999;
}
if( cl->accuracy_shots ) {
accuracy = cl->accuracy_hits * 100 / cl->accuracy_shots;
}
else {
accuracy = 0;
}
perfect = ( cl->ps.persistant[PERS_RANK] == 0 && cl->ps.persistant[PERS_KILLED] == 0 ) ? 1 : 0;
Com_sprintf (entry, sizeof(entry),
" %i %i %i %i %i %i %i %i %i %i %i %i %i %i", level.sortedClients[i],
cl->ps.persistant[PERS_SCORE], ping, (level.time - cl->pers.enterTime)/60000,
scoreFlags, g_entities[level.sortedClients[i]].s.powerups, accuracy,
cl->ps.persistant[PERS_IMPRESSIVE_COUNT],
cl->ps.persistant[PERS_EXCELLENT_COUNT],
cl->ps.persistant[PERS_GAUNTLET_FRAG_COUNT],
cl->ps.persistant[PERS_DEFEND_COUNT],
cl->ps.persistant[PERS_ASSIST_COUNT],
perfect,
cl->ps.persistant[PERS_CAPTURES]);
j = strlen(entry);
if (stringlength + j > 1022)
break;
strcpy (string + stringlength, entry);
stringlength += j;
}
//still want to know the total # of clients
i = level.numConnectedClients;
trap_SendServerCommand( ent-g_entities, va("scores %i %i %i%s", i,
level.teamScores[TEAM_RED], level.teamScores[TEAM_BLUE],
string ) );
}
/*
==================
Cmd_Score_f
Request current scoreboard information
==================
*/
void Cmd_Score_f( gentity_t *ent ) {
DeathmatchScoreboardMessage( ent );
}
/*
==================
CheatsOk
==================
*/
qboolean CheatsOk( gentity_t *ent ) {
if ( !g_cheats.integer ) {
trap_SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStripEdString("SVINGAME", "NOCHEATS")));
return qfalse;
}
if ( ent->health <= 0 ) {
trap_SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStripEdString("SVINGAME", "MUSTBEALIVE")));
return qfalse;
}
return qtrue;
}
/*
==================
ConcatArgs
==================
*/
char *ConcatArgs( int start ) {
int i, c, tlen;
static char line[MAX_STRING_CHARS];
int len;
char arg[MAX_STRING_CHARS];
len = 0;
c = trap_Argc();
for ( i = start ; i < c ; i++ ) {
trap_Argv( i, arg, sizeof( arg ) );
tlen = strlen( arg );
if ( len + tlen >= MAX_STRING_CHARS - 1 ) {
break;
}
memcpy( line + len, arg, tlen );
len += tlen;
if ( i != c - 1 ) {
line[len] = ' ';
len++;
}
}
line[len] = 0;
return line;
}
/*
G_ClientNumberFromPattern
Returns a client number of a matching player as described below
-1 when there are no matching players
-2 when there are multiple matching players
Description: There are 6 test cases: compare (5), compare
color-insensitive (4), compare color-case-insensitive (3), find
substring (2), find color-insensitive substring (1) and find
color-case-insensitive substring (0).
If for one of these test cases there is only a single player name that
passes it, it's a hit. There can be many hits so more precise (higher
in the numeration above) match takes precendence.
5 4 3
*<---*<---*
^ ^ ^
| | |
*<---*<---*
2 1 0
Graph above shows relations between negated test cases (ie not
satisfying 1 implies that tested string doesn't satisfy 2 4 and 5). It
has been used for optimization.
*/
#define MatchedTwice(n) (matchedTwice & 1 << (n))
#define StoreMatch(n) matchedTwice |= matched & 1 << (n); matched |= 1 << (n); matches[n] = idnum
int G_ClientNumberFromPattern ( const char *pattern ) {
gclient_t *cl;
char ciName[MAX_NETNAME];
char cciName[MAX_NETNAME];
char ciPattern[MAX_NETNAME];
char cciPatter[MAX_NETNAME];
char *name;
int idnum = 0;
int matches[5]; // Element n stores last client number matched in test case n
int matched = 0; // bit n stores 1 if at least one netname passed test case n
int matchedTwice = 0; // bit n stores 1 if at least two netnames passed test case n
Q_strncpyz(ciPattern, pattern, sizeof(ciPattern));
Q_CleanStr(ciPattern);
Q_strncpyz(cciPatter, ciPattern, sizeof(cciPatter));
Q_strlwr(cciPatter);
for ( cl = level.clients; idnum < level.maxclients; idnum++, cl++ ) {
if ( cl->pers.connected != CON_CONNECTED ) {
continue;
}
name = cl->pers.netname;
Q_strncpyz(ciName, name, sizeof(ciName));
Q_CleanStr(ciName);
Q_strncpyz(cciName, ciName, sizeof(cciName));
Q_strlwr(cciName);
if ( !MatchedTwice(0) ) {
if ( strstr(cciName, cciPatter) ) {
StoreMatch(0);
} else {
continue;
}
}
if ( !MatchedTwice(1) ) {
if ( strstr(ciName, ciPattern) ) {
StoreMatch(1);
} else {
if ( !MatchedTwice(3) ) {
if ( !strcmp(cciName, cciPatter) ) {
StoreMatch(3);
}
}
continue;
}
}
if ( !MatchedTwice(2) ) {
if ( strstr(name, pattern) ) {
StoreMatch(2);
} else {
if ( !MatchedTwice(3) ) {
if ( !strcmp(cciName, cciPatter) ) {
StoreMatch(3);
} else {
continue;
}
}
if ( !MatchedTwice(4) ) {
if ( !strcmp(ciName, ciPattern) ) {
StoreMatch(4);
}
}
continue;
}
}
if ( !MatchedTwice(3) ) {
if ( !strcmp(cciName, cciPatter) ) {
StoreMatch(3);
} else {
continue;
}
}
if ( !MatchedTwice(4) ) {
if ( !strcmp(ciName, ciPattern) ) {
StoreMatch(4);
} else {
continue;
}
}
// netnames are distinct so just return when we get an exact match.
if ( !strcmp(name, pattern) ) {
return idnum;
}
}
matched &= ~matchedTwice; // Matched once
if ( matched & 16 ) {
return matches[4];
} else if ( matched & 8 ) {
return matches[3];
} else if ( matched & 4 ) {
return matches[2];
} else if ( matched & 2 ) {
return matches[1];
} else if ( matched & 1 ) {
return matches[0];
} else if ( matchedTwice ) {
return -2;
} else {
return -1;
}
}
/*
==================
ClientNumberFromString
Returns a player number for either a number or name string
Returns -1 if invalid
==================
*/
int ClientNumberFromString( gentity_t *to, const char *s ) {
gclient_t *cl;
int idnum;
if ( !s || !s[0] ) {
return -1;
}
// numeric values could be slot numbers
if ( Q_IsInteger( s ) ) {
idnum = atoi( s );
if ( idnum < 0 && idnum >= level.maxclients ) {
trap_SendServerCommand( to-g_entities, va("print \"Bad client slot: %i\n\"", idnum));
return -1;
}
cl = &level.clients[idnum];
if ( cl->pers.connected != CON_CONNECTED ) {
trap_SendServerCommand( to-g_entities, va("print \"Client %i is not on the server\n\"", idnum));
return -1;
}
return idnum;
}
// check for a name match
idnum = G_ClientNumberFromPattern(s);
if ( idnum >= 0 ) {
return idnum;
} else if ( idnum == -1 ) {
trap_SendServerCommand( to-g_entities,
va("print \"There is no user matching '%s" S_COLOR_WHITE "' on the server\n\"", s));
} else if ( idnum == -2 ) {
trap_SendServerCommand( to-g_entities,
va("print \"There are multiple users with '%s" S_COLOR_WHITE "' in their names. Please be more specific.\n\"", s));
}
return -1;
}
/*
==================
G_CrosshairPlayer
Inferior, serverside variant of CG_CrosshairPlayer. ent must be a
client.
==================
*/
static gentity_t *G_CrosshairPlayer( gentity_t *ent ) {
trace_t tr;
vec3_t org, forward, fwdOrg;
AngleVectors( ent->client->ps.viewangles, forward, NULL, NULL );
VectorCopy(ent->client->ps.origin, org);
org[2] += ent->client->ps.viewheight;
VectorMA(org, 256, forward, fwdOrg);
trap_Trace(&tr, org, NULL, NULL, fwdOrg, ent->s.number, MASK_PLAYERSOLID);
if (tr.fraction != 1 && tr.entityNum < MAX_CLIENTS) {
return &g_entities[tr.entityNum];
}
return NULL;
}
/*
==================
Cmd_Give_f
Give items to a client
==================
*/
void Cmd_Give_f (gentity_t *ent)
{
char name[MAX_TOKEN_CHARS];
gitem_t *it;
int i;
qboolean give_all;
gentity_t *it_ent;
trace_t trace;
char arg[MAX_TOKEN_CHARS];
if ( !CheatsOk( ent ) ) {
return;
}
trap_Argv( 1, name, sizeof( name ) );
if (Q_stricmp(name, "all") == 0)
give_all = qtrue;
else
give_all = qfalse;
if (give_all)
{
i = 0;
while (i < HI_NUM_HOLDABLE)
{
ent->client->ps.stats[STAT_HOLDABLE_ITEMS] |= (1 << i);
i++;
}
i = 0;
}
if (give_all || Q_stricmp( name, "health") == 0)
{
if (trap_Argc() == 3) {
trap_Argv( 2, arg, sizeof( arg ) );
ent->health = atoi(arg);
if (ent->health > ent->client->ps.stats[STAT_MAX_HEALTH]) {
ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
}
}
else {
ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
}
if (!give_all)
return;
}
if (give_all || Q_stricmp(name, "weapons") == 0)
{
ent->client->ps.stats[STAT_WEAPONS] = (1 << (WP_DET_PACK+1)) - ( 1 << WP_NONE );
if (!give_all)
return;
}
if ( !give_all && Q_stricmp(name, "weaponnum") == 0 )
{
trap_Argv( 2, arg, sizeof( arg ) );
ent->client->ps.stats[STAT_WEAPONS] |= (1 << atoi(arg));
return;
}
if (give_all || Q_stricmp(name, "ammo") == 0)
{
int num = 999;
if (trap_Argc() == 3) {
trap_Argv( 2, arg, sizeof( arg ) );
num = atoi(arg);
}
for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
ent->client->ps.ammo[i] = num;
}
if (!give_all)
return;
}
if (give_all || Q_stricmp(name, "armor") == 0)
{
if (trap_Argc() == 3) {
trap_Argv( 2, arg, sizeof( arg ) );
ent->client->ps.stats[STAT_ARMOR] = atoi(arg);
} else {
ent->client->ps.stats[STAT_ARMOR] = ent->client->ps.stats[STAT_MAX_HEALTH];
}
if (!give_all)
return;
}
if (Q_stricmp(name, "excellent") == 0) {
ent->client->ps.persistant[PERS_EXCELLENT_COUNT]++;
return;
}
if (Q_stricmp(name, "impressive") == 0) {
ent->client->ps.persistant[PERS_IMPRESSIVE_COUNT]++;
return;
}
if (Q_stricmp(name, "gauntletaward") == 0) {
ent->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT]++;
return;
}
if (Q_stricmp(name, "defend") == 0) {
ent->client->ps.persistant[PERS_DEFEND_COUNT]++;
return;
}
if (Q_stricmp(name, "assist") == 0) {
ent->client->ps.persistant[PERS_ASSIST_COUNT]++;
return;
}
// spawn a specific item right on the player
if ( !give_all ) {
it = BG_FindItem (name);
if (!it) {
return;
}
it_ent = G_Spawn();
VectorCopy( ent->r.currentOrigin, it_ent->s.origin );
it_ent->classname = it->classname;
G_SpawnItem (it_ent, it);
FinishSpawningItem(it_ent );
memset( &trace, 0, sizeof( trace ) );
Touch_Item (it_ent, ent, &trace);
if (it_ent->inuse) {
G_FreeEntity( it_ent );
}
}
}
/*
==================
Cmd_God_f
Sets client to godmode
argv(0) god
==================
*/
void Cmd_God_f (gentity_t *ent)
{
char *msg;
if ( !CheatsOk( ent ) ) {
return;
}
ent->flags ^= FL_GODMODE;
if (!(ent->flags & FL_GODMODE) )
msg = "godmode OFF\n";
else
msg = "godmode ON\n";
trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg));
}
/*
==================
Cmd_Notarget_f
Sets client to notarget
argv(0) notarget
==================
*/
void Cmd_Notarget_f( gentity_t *ent ) {
char *msg;
if ( !CheatsOk( ent ) ) {
return;
}
ent->flags ^= FL_NOTARGET;
if (!(ent->flags & FL_NOTARGET) )
msg = "notarget OFF\n";
else
msg = "notarget ON\n";
trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg));
}
/*
==================
Cmd_Noclip_f
argv(0) noclip
==================
*/
void Cmd_Noclip_f( gentity_t *ent ) {
char *msg;
if ( !CheatsOk( ent ) ) {
return;
}
if ( ent->client->noclip ) {
msg = "noclip OFF\n";
} else {
msg = "noclip ON\n";
}
ent->client->noclip = !ent->client->noclip;
trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg));
}
/*
==================
Cmd_LevelShot_f
This is just to help generate the level pictures
for the menus. It goes to the intermission immediately
and sends over a command to the client to resize the view,
hide the scoreboard, and take a special screenshot
==================
*/
void Cmd_LevelShot_f( gentity_t *ent ) {
if ( !CheatsOk( ent ) ) {
return;
}
// doesn't work in single player
if ( g_gametype.integer != 0 ) {
trap_SendServerCommand( ent-g_entities,
"print \"Must be in g_gametype 0 for levelshot\n\"" );
return;
}
BeginIntermission();
trap_SendServerCommand( ent-g_entities, "clientLevelShot" );
}
/*
==================
Cmd_LevelShot_f
This is just to help generate the level pictures
for the menus. It goes to the intermission immediately
and sends over a command to the client to resize the view,
hide the scoreboard, and take a special screenshot
==================
*/
void Cmd_TeamTask_f( gentity_t *ent ) {
char userinfo[MAX_INFO_STRING];
char arg[MAX_TOKEN_CHARS];
int task;
int client = ent->client - level.clients;
if ( trap_Argc() != 2 ) {
return;
}
trap_Argv( 1, arg, sizeof( arg ) );
task = atoi( arg );
trap_GetUserinfo(client, userinfo, sizeof(userinfo));
Info_SetValueForKey(userinfo, "teamtask", va("%d", task));
trap_SetUserinfo(client, userinfo);
ClientUserinfoChanged(client);
}
/*
=================
Cmd_Kill_f
=================
*/
void Cmd_Kill_f( gentity_t *ent ) {
if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) {
return;
}
if (ent->health <= 0) {
return;
}
if (g_gametype.integer == GT_TOURNAMENT && level.numPlayingClients > 1 && !level.warmupTime)
{
if (!g_allowDuelSuicide.integer)
{
trap_SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStripEdString("SVINGAME", "ATTEMPTDUELKILL")) );
return;
}
}
ent->flags &= ~FL_GODMODE;
ent->client->ps.stats[STAT_HEALTH] = ent->health = -999;
player_die (ent, ent, ent, 100000, MOD_SUICIDE);
}
gentity_t *G_GetDuelWinner(gclient_t *client)
{
gclient_t *wCl;
int i;
for ( i = 0 ; i < level.maxclients ; i++ ) {
wCl = &level.clients[i];
if (wCl && wCl != client && /*wCl->ps.clientNum != client->ps.clientNum &&*/
wCl->pers.connected == CON_CONNECTED && wCl->sess.sessionTeam != TEAM_SPECTATOR)
{
return &g_entities[wCl->ps.clientNum];
}
}
return NULL;
}
/*
=================
BroadCastTeamChange
Let everyone know about a team change
=================
*/
void BroadcastTeamChange( gclient_t *client, int oldTeam )
{
int clientnum;
client->ps.fd.forceDoInit = 1; //every time we change teams make sure our force powers are set right
if ( client->sess.sessionTeam == TEAM_RED ) {
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStripEdString("SVINGAME", "JOINEDTHEREDTEAM")) );
} else if ( client->sess.sessionTeam == TEAM_BLUE ) {
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStripEdString("SVINGAME", "JOINEDTHEBLUETEAM")));
} else if ( client->sess.sessionTeam == TEAM_SPECTATOR && oldTeam != TEAM_SPECTATOR ) {
for ( clientnum = 0; clientnum < level.maxclients; clientnum++ ) {
if ( level.clients[ clientnum ].pers.connected == CON_CONNECTED
&& !level.clients[ clientnum ].ps.duelInProgress ) {
trap_SendServerCommand( clientnum, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStripEdString("SVINGAME", "JOINEDTHESPECTATORS")));
}
}
} else if ( client->sess.sessionTeam == TEAM_FREE ) {
if (g_gametype.integer == GT_TOURNAMENT)
{
/*
gentity_t *currentWinner = G_GetDuelWinner(client);
if (currentWinner && currentWinner->client)
{
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s %s\n\"",
currentWinner->client->pers.netname, G_GetStripEdString("SVINGAME", "VERSUS"), client->pers.netname));
}
else
{
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStripEdString("SVINGAME", "JOINEDTHEBATTLE")));
}
*/
//NOTE: Just doing a vs. once it counts two players up
}
else
{
for ( clientnum = 0; clientnum < level.maxclients; clientnum++ ) {
if ( level.clients[ clientnum ].pers.connected == CON_CONNECTED
&& !level.clients[ clientnum ].ps.duelInProgress ) {
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStripEdString("SVINGAME", "JOINEDTHEBATTLE")));
}
}
}
}
G_LogPrintf ( "setteam: %i %s %s\n",
client - &level.clients[0],
TeamName ( oldTeam ),
TeamName ( client->sess.sessionTeam ) );
}
static int SetTeamSpec( gentity_t *ent, team_t team, spectatorState_t specState, int specClient )
{
gclient_t *client;
int clientNum;
int oldTeam;
int teamLeader;
client = ent->client;
clientNum = client - level.clients;
if ( (g_gametype.integer == GT_TOURNAMENT)
&& level.numNonSpectatorClients >= 2 ) {
team = TEAM_SPECTATOR;
specState = SPECTATOR_NOT;
}
//
// decide if we will allow the change
//
oldTeam = client->sess.sessionTeam;
if ( team == oldTeam && team != TEAM_SPECTATOR ) {
return -1;
}
//
// execute the team change
//
// if the player was dead leave the body
if ( client->ps.stats[STAT_HEALTH] <= 0 ) {
CopyToBodyQue(ent);
}
// he starts at 'base'
client->pers.teamState.state = TEAM_BEGIN;
if ( oldTeam != TEAM_SPECTATOR ) {
// Kill him (makes sure he loses flags, etc)
ent->flags &= ~FL_GODMODE;
ent->client->ps.stats[STAT_HEALTH] = ent->health = 0;
player_die (ent, ent, ent, 100000, MOD_SUICIDE);
}
// they go to the end of the line for tournements
if ( team == TEAM_SPECTATOR ) {
if ( (g_gametype.integer != GT_TOURNAMENT) || (oldTeam != TEAM_SPECTATOR) ) {//so you don't get dropped to the bottom of the queue for changing skins, etc.
client->sess.spectatorTime = level.time;
}
}
client->sess.sessionTeam = team;
client->sess.spectatorState = specState;
client->sess.spectatorClient = specClient;
client->sess.teamLeader = qfalse;
if ( team == TEAM_RED || team == TEAM_BLUE ) {
teamLeader = TeamLeader( team );
// if there is no team leader or the team leader is a bot and this client is not a bot
if ( teamLeader == -1 || ( !(g_entities[clientNum].r.svFlags & SVF_BOT) && (g_entities[teamLeader].r.svFlags & SVF_BOT) ) ) {
SetLeader( team, clientNum );
}
}
// make sure there is a team leader on the team the player came from
if ( oldTeam == TEAM_RED || oldTeam == TEAM_BLUE ) {
CheckTeamLeader( oldTeam );
}
BroadcastTeamChange( client, oldTeam );
// get and distribute relevent paramters
ClientUserinfoChanged( clientNum );
ClientBegin( clientNum, qfalse );
return 0;
}
/*
=================
SetTeam
=================
*/
void SetTeam( gentity_t *ent, team_t team )
{
SetTeamSpec( ent, team, SPECTATOR_FREE, 0 );
}
/*
=================
SetTeamFromString
=================
*/
void SetTeamFromString( gentity_t *ent, char *s ) {
int team;
gclient_t *client;
int clientNum;
spectatorState_t specState;
int specClient;
//
// see what change is requested
//
client = ent->client;
clientNum = client - level.clients;
specClient = 0;
specState = SPECTATOR_NOT;
if ( !Q_stricmp( s, "scoreboard" ) || !Q_stricmp( s, "score" ) ) {
team = TEAM_SPECTATOR;
specState = SPECTATOR_SCOREBOARD;
} else if ( !Q_stricmp( s, "spectator" ) || !Q_stricmp( s, "s" ) ) {
team = TEAM_SPECTATOR;
specState = SPECTATOR_FREE;
} else if ( GT_Team(g_gametype.integer) ) {
// if running a team game, assign player to one of the teams
specState = SPECTATOR_NOT;
if ( !Q_stricmp( s, "red" ) || !Q_stricmp( s, "r" ) ) {
if ( !ValidateTeam(clientNum, TEAM_RED) ) {
trap_SendServerCommand( clientNum,
va("print \"%s\n\"", G_GetStripEdString("SVINGAME", "TOOMANYRED")) );
return;
}
team = TEAM_RED;
} else if ( !Q_stricmp( s, "blue" ) || !Q_stricmp( s, "b" ) ) {
if ( !ValidateTeam(clientNum, TEAM_BLUE) ) {
trap_SendServerCommand( clientNum,
va("print \"%s\n\"", G_GetStripEdString("SVINGAME", "TOOMANYBLUE")) );
return;
}
team = TEAM_BLUE;
} else {
// pick the team with the least number of players
team = PickTeam( clientNum );
if ( team == TEAM_SPECTATOR ) {
trap_SendServerCommand( clientNum, "print \"Teams are full.\n\""); // TRANSLATE
return;
}
}
} else {
team = TEAM_FREE;
if ( !ValidateTeam(clientNum, TEAM_FREE) ) {
trap_SendServerCommand( clientNum, "print \"Game is full.\n\""); // TRANSLATE
return;
}
}
if ( SetTeamSpec( ent, team, specState, specClient ) == 0 ) {
ent->client->switchTeamTime = level.time + 5000;
};
}
/*
=================
StopFollowing
If the client being followed leaves the game, or you just want to drop
to free floating spectator mode
=================
*/
void StopFollowing( gentity_t *ent ) {
ent->client->ps.persistant[ PERS_TEAM ] = TEAM_SPECTATOR;
ent->client->sess.sessionTeam = TEAM_SPECTATOR;
ent->client->sess.spectatorState = SPECTATOR_FREE;
ent->client->ps.pm_flags &= ~PMF_FOLLOW;
ent->r.svFlags &= ~SVF_BOT;
ent->client->ps.clientNum = ent - g_entities;
ent->client->ps.weapon = WP_NONE;
}
/*
=================
Cmd_Team_f
=================
*/
void Cmd_Team_f( gentity_t *ent ) {
int oldTeam;
char s[MAX_TOKEN_CHARS];
const char *printTeam;
if ( trap_Argc() != 2 ) {
oldTeam = ent->client->sess.sessionTeam;
switch ( oldTeam ) {
case TEAM_BLUE:
printTeam = G_GetStripEdString("SVINGAME", "PRINTBLUETEAM");
break;
case TEAM_RED:
printTeam = G_GetStripEdString("SVINGAME", "PRINTREDTEAM");
break;
case TEAM_FREE:
printTeam = G_GetStripEdString("SVINGAME", "PRINTFREETEAM");
break;
case TEAM_SPECTATOR:
printTeam = G_GetStripEdString("SVINGAME", "PRINTSPECTEAM");
break;
default:
return;
}
trap_SendServerCommand( ent-g_entities, va("print \"%s\n\"", printTeam) );
return;
}
if ( ent->client->switchTeamTime > level.time ) {
trap_SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStripEdString("SVINGAME", "NOSWITCH")) );
return;
}
if (gEscaping)
{
return;
}
if ( (g_gametype.integer == GT_TOURNAMENT )
&& ent->client->sess.sessionTeam == TEAM_FREE ) {
trap_SendServerCommand( ent-g_entities, "print \"Cannot switch teams in Duel\n\"" );
return;
}
trap_Argv( 1, s, sizeof( s ) );
SetTeamFromString( ent, s );
}
/*
=================
Cmd_Team_f
=================
*/
void Cmd_ForceChanged_f( gentity_t *ent )
{
char fpChStr[1024];
const char *buf;
// Cmd_Kill_f(ent);
if (ent->client->sess.sessionTeam == TEAM_SPECTATOR)
{ //if it's a spec, just make the changes now
//trap_SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStripEdString("SVINGAME", "FORCEAPPLIED")) );
//No longer print it, as the UI calls this a lot.
WP_InitForcePowers( ent );
goto argCheck;
}
buf = G_GetStripEdString("SVINGAME", "FORCEPOWERCHANGED");
strcpy(fpChStr, buf);
trap_SendServerCommand( ent-g_entities, va("print \"%s%s\n\n\"", S_COLOR_GREEN, fpChStr) );
ent->client->ps.fd.forceDoInit = 1;
argCheck:
if (g_gametype.integer == GT_TOURNAMENT)
{ //If this is duel, don't even bother changing team in relation to this.
return;
}
if (trap_Argc() > 1)
{
char arg[MAX_TOKEN_CHARS];
trap_Argv( 1, arg, sizeof( arg ) );
if (arg[0])
{ //if there's an arg, assume it's a combo team command from the UI.
Cmd_Team_f(ent);