forked from JACoders/OpenJK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathg_cmds.c
3477 lines (2953 loc) · 95.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 - 2005, Id Software, Inc.
Copyright (C) 2000 - 2013, Raven Software, Inc.
Copyright (C) 2001 - 2013, Activision, Inc.
Copyright (C) 2005 - 2015, ioquake3 contributors
Copyright (C) 2013 - 2015, OpenJK contributors
This file is part of the OpenJK source code.
OpenJK is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
#include "g_local.h"
#include "bg_saga.h"
#include "ui/menudef.h" // for the voice chats
//rww - for getting bot commands...
int AcceptBotCommand(char *cmd, gentity_t *pl);
//end rww
void WP_SetSaber( int entNum, saberInfo_t *sabers, int saberNum, const char *saberName );
void Cmd_NPC_f( gentity_t *ent );
void SetTeamQuick(gentity_t *ent, int team, qboolean doBegin);
/*
==================
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 );
}
/*
==================
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;
}
/*
==================
StringIsInteger
==================
*/
qboolean StringIsInteger( const char *s ) {
int i=0, len=0;
qboolean foundDigit=qfalse;
for ( i=0, len=strlen( s ); i<len; i++ )
{
if ( !isdigit( s[i] ) )
return qfalse;
foundDigit = qtrue;
}
return foundDigit;
}
/*
==================
ClientNumberFromString
Returns a player number for either a number or name string
Returns -1 if invalid
==================
*/
int ClientNumberFromString( gentity_t *to, const char *s, qboolean allowconnecting ) {
gclient_t *cl;
int idnum;
char cleanInput[MAX_NETNAME];
if ( StringIsInteger( s ) )
{// numeric values could be slot numbers
idnum = atoi( s );
if ( idnum >= 0 && idnum < level.maxclients )
{
cl = &level.clients[idnum];
if ( cl->pers.connected == CON_CONNECTED )
return idnum;
else if ( allowconnecting && cl->pers.connected == CON_CONNECTING )
return idnum;
}
}
Q_strncpyz( cleanInput, s, sizeof(cleanInput) );
Q_StripColor( cleanInput );
for ( idnum=0,cl=level.clients; idnum < level.maxclients; idnum++,cl++ )
{// check for a name match
if ( cl->pers.connected != CON_CONNECTED )
if ( !allowconnecting || cl->pers.connected < CON_CONNECTING )
continue;
if ( !Q_stricmp( cl->pers.netname_nocolor, cleanInput ) )
return idnum;
}
trap->SendServerCommand( to-g_entities, va( "print \"User %s is not on the server\n\"", s ) );
return -1;
}
/*
==================
Cmd_Give_f
Give items to a client
==================
*/
void G_Give( gentity_t *ent, const char *name, const char *args, int argc )
{
gitem_t *it;
int i;
qboolean give_all = qfalse;
gentity_t *it_ent;
trace_t trace;
if ( !Q_stricmp( name, "all" ) )
give_all = qtrue;
if ( give_all )
{
for ( i=0; i<HI_NUM_HOLDABLE; i++ )
ent->client->ps.stats[STAT_HOLDABLE_ITEMS] |= (1 << i);
}
if ( give_all || !Q_stricmp( name, "health") )
{
if ( argc == 3 )
ent->health = Com_Clampi( 1, ent->client->ps.stats[STAT_MAX_HEALTH], atoi( args ) );
else
{
if ( level.gametype == GT_SIEGE && ent->client->siegeClass != -1 )
ent->health = bgSiegeClasses[ent->client->siegeClass].maxhealth;
else
ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
}
if ( !give_all )
return;
}
if ( give_all || !Q_stricmp( name, "armor" ) || !Q_stricmp( name, "shield" ) )
{
if ( argc == 3 )
ent->client->ps.stats[STAT_ARMOR] = Com_Clampi( 0, ent->client->ps.stats[STAT_MAX_HEALTH], atoi( args ) );
else
{
if ( level.gametype == GT_SIEGE && ent->client->siegeClass != -1 )
ent->client->ps.stats[STAT_ARMOR] = bgSiegeClasses[ent->client->siegeClass].maxarmor;
else
ent->client->ps.stats[STAT_ARMOR] = ent->client->ps.stats[STAT_MAX_HEALTH];
}
if ( !give_all )
return;
}
if ( give_all || !Q_stricmp( name, "force" ) )
{
if ( argc == 3 )
ent->client->ps.fd.forcePower = Com_Clampi( 0, ent->client->ps.fd.forcePowerMax, atoi( args ) );
else
ent->client->ps.fd.forcePower = ent->client->ps.fd.forcePowerMax;
if ( !give_all )
return;
}
if ( give_all || !Q_stricmp( name, "weapons" ) )
{
ent->client->ps.stats[STAT_WEAPONS] = (1 << (LAST_USEABLE_WEAPON+1)) - ( 1 << WP_NONE );
if ( !give_all )
return;
}
if ( !give_all && !Q_stricmp( name, "weaponnum" ) )
{
ent->client->ps.stats[STAT_WEAPONS] |= (1 << atoi( args ));
return;
}
if ( give_all || !Q_stricmp( name, "ammo" ) )
{
int num = 999;
if ( argc == 3 )
num = Com_Clampi( 0, 999, atoi( args ) );
for ( i=AMMO_BLASTER; i<AMMO_MAX; i++ )
ent->client->ps.ammo[i] = num;
if ( !give_all )
return;
}
if ( !Q_stricmp( name, "excellent" ) ) {
ent->client->ps.persistant[PERS_EXCELLENT_COUNT]++;
return;
}
if ( !Q_stricmp( name, "impressive" ) ) {
ent->client->ps.persistant[PERS_IMPRESSIVE_COUNT]++;
return;
}
if ( !Q_stricmp( name, "gauntletaward" ) ) {
ent->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT]++;
return;
}
if ( !Q_stricmp( name, "defend" ) ) {
ent->client->ps.persistant[PERS_DEFEND_COUNT]++;
return;
}
if ( !Q_stricmp( name, "assist" ) ) {
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 );
if ( !it_ent || !it_ent->inuse )
return;
FinishSpawningItem( it_ent );
if ( !it_ent || !it_ent->inuse )
return;
memset( &trace, 0, sizeof( trace ) );
Touch_Item( it_ent, ent, &trace );
if ( it_ent->inuse )
G_FreeEntity( it_ent );
}
}
void Cmd_Give_f( gentity_t *ent )
{
char name[MAX_TOKEN_CHARS] = {0};
trap->Argv( 1, name, sizeof( name ) );
G_Give( ent, name, ConcatArgs( 2 ), trap->Argc() );
}
void Cmd_GiveOther_f( gentity_t *ent )
{
char name[MAX_TOKEN_CHARS] = {0};
int i;
char otherindex[MAX_TOKEN_CHARS];
gentity_t *otherEnt = NULL;
if ( trap->Argc () < 3 ) {
trap->SendServerCommand( ent-g_entities, "print \"Usage: giveother <player id> <givestring>\n\"" );
return;
}
trap->Argv( 1, otherindex, sizeof( otherindex ) );
i = ClientNumberFromString( ent, otherindex, qfalse );
if ( i == -1 ) {
return;
}
otherEnt = &g_entities[i];
if ( !otherEnt->inuse || !otherEnt->client ) {
return;
}
if ( (otherEnt->health <= 0 || otherEnt->client->tempSpectate >= level.time || otherEnt->client->sess.sessionTeam == TEAM_SPECTATOR) )
{
// Intentionally displaying for the command user
trap->SendServerCommand( ent-g_entities, va( "print \"%s\n\"", G_GetStringEdString( "MP_SVGAME", "MUSTBEALIVE" ) ) );
return;
}
trap->Argv( 2, name, sizeof( name ) );
G_Give( otherEnt, name, ConcatArgs( 3 ), trap->Argc()-1 );
}
/*
==================
Cmd_God_f
Sets client to godmode
argv(0) god
==================
*/
void Cmd_God_f( gentity_t *ent ) {
char *msg = NULL;
ent->flags ^= FL_GODMODE;
if ( !(ent->flags & FL_GODMODE) )
msg = "godmode OFF";
else
msg = "godmode ON";
trap->SendServerCommand( ent-g_entities, va( "print \"%s\n\"", msg ) );
}
/*
==================
Cmd_Notarget_f
Sets client to notarget
argv(0) notarget
==================
*/
void Cmd_Notarget_f( gentity_t *ent ) {
char *msg = NULL;
ent->flags ^= FL_NOTARGET;
if ( !(ent->flags & FL_NOTARGET) )
msg = "notarget OFF";
else
msg = "notarget ON";
trap->SendServerCommand( ent-g_entities, va( "print \"%s\n\"", msg ) );
}
/*
==================
Cmd_Noclip_f
argv(0) noclip
==================
*/
void Cmd_Noclip_f( gentity_t *ent ) {
char *msg = NULL;
ent->client->noclip = !ent->client->noclip;
if ( !ent->client->noclip )
msg = "noclip OFF";
else
msg = "noclip ON";
trap->SendServerCommand( ent-g_entities, va( "print \"%s\n\"", 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 ( !ent->client->pers.localClient )
{
trap->SendServerCommand(ent-g_entities, "print \"The levelshot command must be executed by a local client\n\"");
return;
}
// doesn't work in single player
if ( level.gametype == GT_SINGLE_PLAYER )
{
trap->SendServerCommand(ent-g_entities, "print \"Must not be in singleplayer mode for levelshot\n\"" );
return;
}
BeginIntermission();
trap->SendServerCommand( ent-g_entities, "clientLevelShot" );
}
#if 0
/*
==================
Cmd_TeamTask_f
From TA.
==================
*/
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);
}
#endif
void G_Kill( gentity_t *ent ) {
if ((level.gametype == GT_DUEL || level.gametype == GT_POWERDUEL) &&
level.numPlayingClients > 1 && !level.warmupTime)
{
if (!g_allowDuelSuicide.integer)
{
trap->SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "ATTEMPTDUELKILL")) );
return;
}
}
ent->flags &= ~FL_GODMODE;
ent->client->ps.stats[STAT_HEALTH] = ent->health = -999;
player_die (ent, ent, ent, 100000, MOD_SUICIDE);
}
/*
=================
Cmd_Kill_f
=================
*/
void Cmd_Kill_f( gentity_t *ent ) {
G_Kill( ent );
}
void Cmd_KillOther_f( gentity_t *ent )
{
int i;
char otherindex[MAX_TOKEN_CHARS];
gentity_t *otherEnt = NULL;
if ( trap->Argc () < 2 ) {
trap->SendServerCommand( ent-g_entities, "print \"Usage: killother <player id>\n\"" );
return;
}
trap->Argv( 1, otherindex, sizeof( otherindex ) );
i = ClientNumberFromString( ent, otherindex, qfalse );
if ( i == -1 ) {
return;
}
otherEnt = &g_entities[i];
if ( !otherEnt->inuse || !otherEnt->client ) {
return;
}
if ( (otherEnt->health <= 0 || otherEnt->client->tempSpectate >= level.time || otherEnt->client->sess.sessionTeam == TEAM_SPECTATOR) )
{
// Intentionally displaying for the command user
trap->SendServerCommand( ent-g_entities, va( "print \"%s\n\"", G_GetStringEdString( "MP_SVGAME", "MUSTBEALIVE" ) ) );
return;
}
G_Kill( otherEnt );
}
/*
=================
BroadCastTeamChange
Let everyone know about a team change
=================
*/
void BroadcastTeamChange( gclient_t *client, int oldTeam )
{
client->ps.fd.forceDoInit = 1; //every time we change teams make sure our force powers are set right
if (level.gametype == GT_SIEGE)
{ //don't announce these things in siege
return;
}
if ( client->sess.sessionTeam == TEAM_RED ) {
trap->SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStringEdString("MP_SVGAME", "JOINEDTHEREDTEAM")) );
} else if ( client->sess.sessionTeam == TEAM_BLUE ) {
trap->SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStringEdString("MP_SVGAME", "JOINEDTHEBLUETEAM")));
} else if ( client->sess.sessionTeam == TEAM_SPECTATOR && oldTeam != TEAM_SPECTATOR ) {
trap->SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStringEdString("MP_SVGAME", "JOINEDTHESPECTATORS")));
} else if ( client->sess.sessionTeam == TEAM_FREE ) {
trap->SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " %s\n\"",
client->pers.netname, G_GetStringEdString("MP_SVGAME", "JOINEDTHEBATTLE")));
}
G_LogPrintf( "ChangeTeam: %i [%s] (%s) \"%s^7\" %s -> %s\n", (int)(client - level.clients), client->sess.IP, client->pers.guid, client->pers.netname, TeamName( oldTeam ), TeamName( client->sess.sessionTeam ) );
}
qboolean G_PowerDuelCheckFail(gentity_t *ent)
{
int loners = 0;
int doubles = 0;
if (!ent->client || ent->client->sess.duelTeam == DUELTEAM_FREE)
{
return qtrue;
}
G_PowerDuelCount(&loners, &doubles, qfalse);
if (ent->client->sess.duelTeam == DUELTEAM_LONE && loners >= 1)
{
return qtrue;
}
if (ent->client->sess.duelTeam == DUELTEAM_DOUBLE && doubles >= 2)
{
return qtrue;
}
return qfalse;
}
/*
=================
SetTeam
=================
*/
qboolean g_dontPenalizeTeam = qfalse;
qboolean g_preventTeamBegin = qfalse;
void SetTeam( gentity_t *ent, char *s ) {
int team, oldTeam;
gclient_t *client;
int clientNum;
spectatorState_t specState;
int specClient;
int teamLeader;
// fix: this prevents rare creation of invalid players
if (!ent->inuse)
{
return;
}
//
// 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_FREE; // SPECTATOR_SCOREBOARD disabling this for now since it is totally broken on client side
} else if ( !Q_stricmp( s, "follow1" ) ) {
team = TEAM_SPECTATOR;
specState = SPECTATOR_FOLLOW;
specClient = -1;
} else if ( !Q_stricmp( s, "follow2" ) ) {
team = TEAM_SPECTATOR;
specState = SPECTATOR_FOLLOW;
specClient = -2;
} else if ( !Q_stricmp( s, "spectator" ) || !Q_stricmp( s, "s" ) ) {
team = TEAM_SPECTATOR;
specState = SPECTATOR_FREE;
} else if ( level.gametype >= GT_TEAM ) {
// if running a team game, assign player to one of the teams
specState = SPECTATOR_NOT;
if ( !Q_stricmp( s, "red" ) || !Q_stricmp( s, "r" ) ) {
team = TEAM_RED;
} else if ( !Q_stricmp( s, "blue" ) || !Q_stricmp( s, "b" ) ) {
team = TEAM_BLUE;
} else {
// pick the team with the least number of players
//For now, don't do this. The legalize function will set powers properly now.
/*
if (g_forceBasedTeams.integer)
{
if (ent->client->ps.fd.forceSide == FORCE_LIGHTSIDE)
{
team = TEAM_BLUE;
}
else
{
team = TEAM_RED;
}
}
else
{
*/
team = PickTeam( clientNum );
//}
}
if ( g_teamForceBalance.integer && !g_jediVmerc.integer ) {
int counts[TEAM_NUM_TEAMS];
//JAC: Invalid clientNum was being used
counts[TEAM_BLUE] = TeamCount( ent-g_entities, TEAM_BLUE );
counts[TEAM_RED] = TeamCount( ent-g_entities, TEAM_RED );
// We allow a spread of two
if ( team == TEAM_RED && counts[TEAM_RED] - counts[TEAM_BLUE] > 1 ) {
//For now, don't do this. The legalize function will set powers properly now.
/*
if (g_forceBasedTeams.integer && ent->client->ps.fd.forceSide == FORCE_DARKSIDE)
{
trap->SendServerCommand( ent->client->ps.clientNum,
va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "TOOMANYRED_SWITCH")) );
}
else
*/
{
//JAC: Invalid clientNum was being used
trap->SendServerCommand( ent-g_entities,
va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "TOOMANYRED")) );
}
return; // ignore the request
}
if ( team == TEAM_BLUE && counts[TEAM_BLUE] - counts[TEAM_RED] > 1 ) {
//For now, don't do this. The legalize function will set powers properly now.
/*
if (g_forceBasedTeams.integer && ent->client->ps.fd.forceSide == FORCE_LIGHTSIDE)
{
trap->SendServerCommand( ent->client->ps.clientNum,
va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "TOOMANYBLUE_SWITCH")) );
}
else
*/
{
//JAC: Invalid clientNum was being used
trap->SendServerCommand( ent-g_entities,
va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "TOOMANYBLUE")) );
}
return; // ignore the request
}
// It's ok, the team we are switching to has less or same number of players
}
//For now, don't do this. The legalize function will set powers properly now.
/*
if (g_forceBasedTeams.integer)
{
if (team == TEAM_BLUE && ent->client->ps.fd.forceSide != FORCE_LIGHTSIDE)
{
trap->SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "MUSTBELIGHT")) );
return;
}
if (team == TEAM_RED && ent->client->ps.fd.forceSide != FORCE_DARKSIDE)
{
trap->SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "MUSTBEDARK")) );
return;
}
}
*/
} else {
// force them to spectators if there aren't any spots free
team = TEAM_FREE;
}
oldTeam = client->sess.sessionTeam;
if (level.gametype == GT_SIEGE)
{
if (client->tempSpectate >= level.time &&
team == TEAM_SPECTATOR)
{ //sorry, can't do that.
return;
}
if ( team == oldTeam && team != TEAM_SPECTATOR )
return;
client->sess.siegeDesiredTeam = team;
//oh well, just let them go.
/*
if (team != TEAM_SPECTATOR)
{ //can't switch to anything in siege unless you want to switch to being a fulltime spectator
//fill them in on their objectives for this team now
trap->SendServerCommand(ent-g_entities, va("sb %i", client->sess.siegeDesiredTeam));
trap->SendServerCommand( ent-g_entities, va("print \"You will be on the selected team the next time the round begins.\n\"") );
return;
}
*/
if (client->sess.sessionTeam != TEAM_SPECTATOR &&
team != TEAM_SPECTATOR)
{ //not a spectator now, and not switching to spec, so you have to wait til you die.
//trap->SendServerCommand( ent-g_entities, va("print \"You will be on the selected team the next time you respawn.\n\"") );
qboolean doBegin;
if (ent->client->tempSpectate >= level.time)
{
doBegin = qfalse;
}
else
{
doBegin = qtrue;
}
if (doBegin)
{
// Kill them so they automatically respawn in the team they wanted.
if (ent->health > 0)
{
ent->flags &= ~FL_GODMODE;
ent->client->ps.stats[STAT_HEALTH] = ent->health = 0;
player_die( ent, ent, ent, 100000, MOD_TEAM_CHANGE );
}
}
if (ent->client->sess.sessionTeam != ent->client->sess.siegeDesiredTeam)
{
SetTeamQuick(ent, ent->client->sess.siegeDesiredTeam, qfalse);
}
return;
}
}
// override decision if limiting the players
if ( (level.gametype == GT_DUEL)
&& level.numNonSpectatorClients >= 2 )
{
team = TEAM_SPECTATOR;
}
else if ( (level.gametype == GT_POWERDUEL)
&& (level.numPlayingClients >= 3 || G_PowerDuelCheckFail(ent)) )
{
team = TEAM_SPECTATOR;
}
else if ( g_maxGameClients.integer > 0 &&
level.numNonSpectatorClients >= g_maxGameClients.integer )
{
team = TEAM_SPECTATOR;
}
//
// decide if we will allow the change
//
if ( team == oldTeam && team != TEAM_SPECTATOR ) {
return;
}
//
// execute the team change
//
//If it's siege then show the mission briefing for the team you just joined.
// if (level.gametype == GT_SIEGE && team != TEAM_SPECTATOR)
// {
// trap->SendServerCommand(clientNum, va("sb %i", team));
// }
// if the player was dead leave the body
if ( client->ps.stats[STAT_HEALTH] <= 0 && client->sess.sessionTeam != TEAM_SPECTATOR ) {
MaintainBodyQueue(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;
g_dontPenalizeTeam = qtrue;
player_die (ent, ent, ent, 100000, MOD_SUICIDE);
g_dontPenalizeTeam = qfalse;
}
// they go to the end of the line for tournaments
if ( team == TEAM_SPECTATOR && oldTeam != team )
AddTournamentQueue( client );
// clear votes if going to spectator (specs can't vote)
if ( team == TEAM_SPECTATOR )
G_ClearVote( ent );
// also clear team votes if switching red/blue or going to spec
G_ClearTeamVote( ent, oldTeam );
client->sess.sessionTeam = (team_t)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 );
//make a disappearing effect where they were before teleporting them to the appropriate spawn point,
//if we were not on the spec team
if (oldTeam != TEAM_SPECTATOR)
{
gentity_t *tent = G_TempEntity( client->ps.origin, EV_PLAYER_TELEPORT_OUT );
tent->s.clientNum = clientNum;
}
// get and distribute relevent paramters
if ( !ClientUserinfoChanged( clientNum ) )
return;
if (!g_preventTeamBegin)
{
ClientBegin( clientNum, qfalse );
}
}
/*
=================
StopFollowing
If the client being followed leaves the game, or you just want to drop
to free floating spectator mode
=================
*/
extern void G_LeaveVehicle( gentity_t *ent, qboolean ConCheck );
void StopFollowing( gentity_t *ent ) {
int i=0;
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;
G_LeaveVehicle( ent, qfalse ); // clears m_iVehicleNum as well
ent->client->ps.emplacedIndex = 0;
//ent->client->ps.m_iVehicleNum = 0;
ent->client->ps.viewangles[ROLL] = 0.0f;
ent->client->ps.forceHandExtend = HANDEXTEND_NONE;
ent->client->ps.forceHandExtendTime = 0;
ent->client->ps.zoomMode = 0;
ent->client->ps.zoomLocked = qfalse;
ent->client->ps.zoomLockTime = 0;
ent->client->ps.saberMove = LS_NONE;
ent->client->ps.legsAnim = 0;
ent->client->ps.legsTimer = 0;
ent->client->ps.torsoAnim = 0;
ent->client->ps.torsoTimer = 0;
ent->client->ps.isJediMaster = qfalse; // major exploit if you are spectating somebody and they are JM and you reconnect
ent->client->ps.cloakFuel = 100; // so that fuel goes away after stop following them
ent->client->ps.jetpackFuel = 100; // so that fuel goes away after stop following them
ent->health = ent->client->ps.stats[STAT_HEALTH] = 100; // so that you don't keep dead angles if you were spectating a dead person
ent->client->ps.bobCycle = 0;
ent->client->ps.pm_type = PM_SPECTATOR;
ent->client->ps.eFlags &= ~EF_DISINTEGRATION;
for ( i=0; i<PW_NUM_POWERUPS; i++ )
ent->client->ps.powerups[i] = 0;
}
/*
=================
Cmd_Team_f
=================
*/
void Cmd_Team_f( gentity_t *ent ) {
int oldTeam;
char s[MAX_TOKEN_CHARS];
oldTeam = ent->client->sess.sessionTeam;
if ( trap->Argc() != 2 ) {
switch ( oldTeam ) {
case TEAM_BLUE:
trap->SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "PRINTBLUETEAM")) );
break;
case TEAM_RED:
trap->SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "PRINTREDTEAM")) );
break;
case TEAM_FREE:
trap->SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "PRINTFREETEAM")) );
break;
case TEAM_SPECTATOR:
trap->SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "PRINTSPECTEAM")) );
break;
}
return;
}
if ( ent->client->switchTeamTime > level.time ) {
trap->SendServerCommand( ent-g_entities, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "NOSWITCH")) );
return;
}