/
g_cmds.c
4305 lines (3670 loc) · 97 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
/*
* Wolfenstein: Enemy Territory GPL Source Code
* Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
*
* ET: Legacy
* Copyright (C) 2012 Jan Simek <mail@etlegacy.com>
*
* This file is part of ET: Legacy - http://www.etlegacy.com
*
* ET: Legacy 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 3 of the License, or
* (at your option) any later version.
*
* ET: Legacy 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 ET: Legacy. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, Wolfenstein: Enemy Territory GPL Source Code is also
* subject to certain additional terms. You should have received a copy
* of these additional terms immediately following the terms and conditions
* of the GNU General Public License which accompanied the source code.
* If not, please request a copy in writing from id Software at the address below.
*
* id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
*
* @file g_cmds.c
*/
#include "g_local.h"
void BotDebug(int clientNum);
void GetBotAutonomies(int clientNum, int *weapAutonomy, int *moveAutonomy);
qboolean G_IsOnFireteam(int entityNum, fireteamData_t **teamNum);
/*
==================
G_SendScore
Sends current scoreboard information
==================
*/
void G_SendScore(gentity_t *ent)
{
char entry[128];
int i;
gclient_t *cl;
int numSorted;
int team, size, count;
char buffer[1024];
char startbuffer[32];
// send the latest information on all clients
numSorted = level.numConnectedClients;
if (numSorted > MAX_CLIENTS)
{
numSorted = MAX_CLIENTS;
}
i = 0;
// Gordon: team doesnt actually mean team, ignore...
for (team = 0; team < 2; team++)
{
*buffer = '\0';
*startbuffer = '\0';
if (team == 0)
{
Q_strncpyz(startbuffer, va("sc0 %i %i", level.teamScores[TEAM_AXIS], level.teamScores[TEAM_ALLIES]), 32);
}
else
{
Q_strncpyz(startbuffer, "sc1", 32);
}
size = strlen(startbuffer) + 1;
count = 0;
for (; i < numSorted ; i++)
{
int ping, playerClass, respawnsLeft;
cl = &level.clients[level.sortedClients[i]];
if (g_entities[level.sortedClients[i]].r.svFlags & SVF_POW)
{
continue;
}
// NERVE - SMF - if on same team, send across player class
// Gordon: FIXME: remove/move elsewhere?
if (cl->ps.persistant[PERS_TEAM] == ent->client->ps.persistant[PERS_TEAM] || G_smvLocateEntityInMVList(ent, level.sortedClients[i], qfalse))
{
playerClass = cl->ps.stats[STAT_PLAYER_CLASS];
}
else
{
playerClass = 0;
}
// NERVE - SMF - number of respawns left
respawnsLeft = cl->ps.persistant[PERS_RESPAWNS_LEFT];
if (g_gametype.integer == GT_WOLF_LMS)
{
if (g_entities[level.sortedClients[i]].health <= 0)
{
respawnsLeft = -2;
}
}
else
{
if ((respawnsLeft == 0 && ((cl->ps.pm_flags & PMF_LIMBO) || ((level.intermissiontime) && g_entities[level.sortedClients[i]].health <= 0))))
{
respawnsLeft = -2;
}
}
if (cl->pers.connected == CON_CONNECTING)
{
ping = -1;
}
else
{
ping = cl->ps.ping < 999 ? cl->ps.ping : 999;
}
if (g_gametype.integer == GT_WOLF_LMS)
{
Com_sprintf(entry, sizeof(entry), " %i %i %i %i %i %i %i", level.sortedClients[i], cl->ps.persistant[PERS_SCORE], ping,
(level.time - cl->pers.enterTime - (level.time - level.intermissiontime)) / 60000, g_entities[level.sortedClients[i]].s.powerups, playerClass, respawnsLeft);
}
else
{
int j, totalXP;
for (totalXP = 0, j = 0; j < SK_NUM_SKILLS; j++)
{
totalXP += cl->sess.skillpoints[j];
}
Com_sprintf(entry, sizeof(entry), " %i %i %i %i %i %i %i", level.sortedClients[i], totalXP, ping,
(level.time - cl->pers.enterTime - (level.time - level.intermissiontime)) / 60000, g_entities[level.sortedClients[i]].s.powerups, playerClass, respawnsLeft);
}
// Make sure the entry can fit in the buffer.
// If not break away and send the buffer content
if (size + strlen(entry) > 1000)
{
break;
}
// Copy the entry into the send buffer
size += strlen(entry);
Q_strcat(buffer, 1024, entry);
// Send a maximum of 31 players in one packet
if (++count >= 32)
{
i++;
break;
}
}
if (count > 0 || team == 0)
{
trap_SendServerCommand(ent - g_entities, va("%s %i%s", startbuffer, count, buffer));
}
}
}
/*
==================
Cmd_Score_f
Request current scoreboard information
==================
*/
void Cmd_Score_f(gentity_t *ent)
{
ent->client->wantsscore = qtrue;
// G_SendScore( ent );
}
/*
==================
CheatsOk
==================
*/
qboolean CheatsOk(gentity_t *ent)
{
if (!g_cheats.integer)
{
trap_SendServerCommand(ent - g_entities, va("print \"Cheats are not enabled on this server.\n\""));
return qfalse;
}
if (ent->health <= 0)
{
trap_SendServerCommand(ent - g_entities, va("print \"You must be alive to use this command.\n\""));
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;
}
/*
==================
SanitizeString
Remove case and control characters
==================
*/
void SanitizeString(char *in, char *out, qboolean fToLower)
{
while (*in)
{
if (*in == 27 || *in == '^')
{
in++; // skip color code
if (*in)
{
in++;
}
continue;
}
if (*in < 32)
{
in++;
continue;
}
*out++ = (fToLower) ? tolower(*in++) : *in++;
}
*out = 0;
}
/*
==================
ClientNumberFromString
Returns a player number for either a number or name string
Returns -1 if invalid
==================
*/
int ClientNumberFromString(gentity_t *to, char *s)
{
gclient_t *cl;
int idnum;
char s2[MAX_STRING_CHARS];
char n2[MAX_STRING_CHARS];
qboolean fIsNumber = qtrue;
// See if its a number or string
for (idnum = 0; idnum < (int)strlen(s) && s[idnum] != 0; idnum++)
{
if (s[idnum] < '0' || s[idnum] > '9')
{
fIsNumber = qfalse;
break;
}
}
// check for a name match
SanitizeString(s, s2, qtrue);
for (idnum = 0, cl = level.clients; idnum < level.maxclients; idnum++, cl++)
{
if (cl->pers.connected != CON_CONNECTED)
{
continue;
}
SanitizeString(cl->pers.netname, n2, qtrue);
if (!strcmp(n2, s2))
{
return(idnum);
}
}
// numeric values are just slot numbers
if (fIsNumber)
{
idnum = atoi(s);
if (idnum < 0 || idnum >= level.maxclients)
{
CPx(to - g_entities, va("print \"Bad client slot: [lof]%i\n\"", idnum));
return -1;
}
cl = &level.clients[idnum];
if (cl->pers.connected != CON_CONNECTED)
{
CPx(to - g_entities, va("print \"Client[lof] %i [lon]is not active\n\"", idnum));
return -1;
}
return(idnum);
}
CPx(to - g_entities, va("print \"User [lof]%s [lon]is not on the server\n\"", s));
return(-1);
}
/*
=================
Cmd_ListBotGoals_f
=================
*/
void Cmd_ListBotGoals_f(gentity_t *ent)
{
int i;
team_t t;
if (!CheatsOk(ent))
{
return;
}
for (t = TEAM_AXIS; t <= TEAM_ALLIES; t++)
{
gentity_t *list = g_entities, *targ;
G_Printf("\n%s bot goals\n=====================\n", (t == TEAM_AXIS ? "Axis" : "Allies"));
for (i = 0; i < level.num_entities; i++, list++)
{
if (!list->inuse)
{
continue;
}
if (!(list->aiInactive & (1 << t)))
{
G_Printf("%s (%s)", (list->scriptName ? list->scriptName : (list->targetname ? list->targetname : "NONE")), list->classname);
if (list->target_ent)
{
targ = list->target_ent;
G_Printf(" -> ");
G_Printf("%s (%s)", (targ->scriptName ? targ->scriptName : (targ->targetname ? targ->targetname : "NONE")), targ->classname);
}
G_Printf("\n");
}
}
}
}
/*
==================
Cmd_Give_f
Give items to a client
==================
*/
void Cmd_Give_f(gentity_t *ent)
{
char *name, *amt;
// gitem_t *it;
int i;
qboolean give_all;
// gentity_t *it_ent;
// trace_t trace;
int amount;
int skill;
qboolean hasAmount = qfalse;
if (!CheatsOk(ent))
{
return;
}
//----(SA) check for an amount (like "give health 30")
amt = ConcatArgs(2);
if (*amt)
{
hasAmount = qtrue;
}
amount = atoi(amt);
//----(SA) end
name = ConcatArgs(1);
if (Q_stricmp(name, "all") == 0)
{
give_all = qtrue;
}
else
{
give_all = qfalse;
}
if (Q_stricmpn(name, "skill", 5) == 0)
{
if (hasAmount)
{
skill = amount; // Change amount to skill, so that we can use amount properly
if (skill >= 0 && skill < SK_NUM_SKILLS)
{
// Detecting the correct amount to move to the next skill level
amount = 20;
if (ent->client->sess.skill[skill] < NUM_SKILL_LEVELS - 1)
{
amount = skillLevels[ent->client->sess.skill[skill] + 1] - ent->client->sess.skillpoints[skill];
}
G_AddSkillPoints(ent, skill, amount);
G_DebugAddSkillPoints(ent, skill, amount, "give skill");
}
}
else
{
// bumps all skills with 1 level
for (i = 0; i < SK_NUM_SKILLS; i++)
{
// Detecting the correct amount to move to the next skill level
amount = 20;
if (ent->client->sess.skill[i] < NUM_SKILL_LEVELS - 1)
{
amount = skillLevels[ent->client->sess.skill[i] + 1] - ent->client->sess.skillpoints[i];
}
G_AddSkillPoints(ent, i, amount);
G_DebugAddSkillPoints(ent, i, amount, "give skill");
}
}
return;
}
if (Q_stricmpn(name, "medal", 5) == 0)
{
for (i = 0; i < SK_NUM_SKILLS; i++)
{
if (!ent->client->sess.medals[i])
{
ent->client->sess.medals[i] = 1;
}
}
ClientUserinfoChanged(ent - g_entities);
return;
}
if (give_all || Q_stricmpn(name, "health", 6) == 0)
{
//----(SA) modified
if (amount)
{
ent->health += amount;
}
else
{
ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
}
if (!give_all)
{
return;
}
}
/*if ( Q_stricmpn( name, "damage", 6) == 0)
{
if(amount) {
name = ConcatArgs( 3 );
if( *name ) {
int client = ClientNumberFromString( ent, name );
if( client >= 0 ) {
G_Damage( &g_entities[client], ent, ent, NULL, NULL, amount, DAMAGE_NO_PROTECTION, MOD_UNKNOWN );
}
} else {
G_Damage( ent, ent, ent, NULL, NULL, amount, DAMAGE_NO_PROTECTION, MOD_UNKNOWN );
}
}
return;
}*/
if (give_all || Q_stricmp(name, "weapons") == 0)
{
for (i = 0; i < WP_NUM_WEAPONS; i++)
{
if (BG_WeaponInWolfMP(i))
{
COM_BitSet(ent->client->ps.weapons, i);
}
}
if (!give_all)
{
return;
}
}
if (give_all || Q_stricmpn(name, "ammo", 4) == 0)
{
if (amount)
{
if (ent->client->ps.weapon
&& ent->client->ps.weapon != WP_SATCHEL && ent->client->ps.weapon != WP_SATCHEL_DET
)
{
Add_Ammo(ent, ent->client->ps.weapon, amount, qtrue);
}
}
else
{
for (i = 1 ; i < WP_NUM_WEAPONS ; i++)
{
if (COM_BitCheck(ent->client->ps.weapons, i) && i != WP_SATCHEL && i != WP_SATCHEL_DET)
{
Add_Ammo(ent, i, 9999, qtrue);
}
}
}
if (!give_all)
{
return;
}
}
// "give allammo <n>" allows you to give a specific amount of ammo to /all/ weapons while
// allowing "give ammo <n>" to only give to the selected weap.
if (Q_stricmpn(name, "allammo", 7) == 0 && amount)
{
for (i = 1 ; i < WP_NUM_WEAPONS; i++)
Add_Ammo(ent, i, amount, qtrue);
if (!give_all)
{
return;
}
}
//---- (SA) Wolf keys
if (give_all || Q_stricmp(name, "keys") == 0)
{
ent->client->ps.stats[STAT_KEYS] = (1 << KEY_NUM_KEYS) - 2;
if (!give_all)
{
return;
}
}
//---- (SA) end
// 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 ) );
it_ent->active = qtrue;
Touch_Item (it_ent, ent, &trace);
it_ent->active = qfalse;
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;
char *name;
qboolean godAll = qfalse;
if (!CheatsOk(ent))
{
return;
}
name = ConcatArgs(1);
// are we supposed to make all our teammates gods too?
if (Q_stricmp(name, "all") == 0)
{
godAll = qtrue;
}
// can only use this cheat in single player
if (godAll && g_gametype.integer == GT_SINGLE_PLAYER)
{
int j;
qboolean settingFlag = qtrue;
gentity_t *other;
// are we turning it on or off?
if (ent->flags & FL_GODMODE)
{
settingFlag = qfalse;
}
// loop through all players
for (j = 0; j < level.maxclients; j++)
{
other = &g_entities[j];
// if they're on the same team
if (OnSameTeam(other, ent))
{
// set or clear the flag
if (settingFlag)
{
other->flags |= FL_GODMODE;
}
else
{
other->flags &= ~FL_GODMODE;
}
}
}
if (settingFlag)
{
msg = "godmode all ON\n";
}
else
{
msg = "godmode all OFF\n";
}
}
else
{
if (!Q_stricmp(name, "on") || atoi(name))
{
ent->flags |= FL_GODMODE;
}
else if (!Q_stricmp(name, "off") || !Q_stricmp(name, "0"))
{
ent->flags &= ~FL_GODMODE;
}
else
{
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_Nofatigue_f
Sets client to nofatigue
argv(0) nofatigue
==================
*/
void Cmd_Nofatigue_f(gentity_t *ent)
{
char *msg;
char *name = ConcatArgs(1);
if (!CheatsOk(ent))
{
return;
}
if (!Q_stricmp(name, "on") || atoi(name))
{
ent->flags |= FL_NOFATIGUE;
}
else if (!Q_stricmp(name, "off") || !Q_stricmp(name, "0"))
{
ent->flags &= ~FL_NOFATIGUE;
}
else
{
ent->flags ^= FL_NOFATIGUE;
}
if (!(ent->flags & FL_NOFATIGUE))
{
msg = "nofatigue OFF\n";
}
else
{
msg = "nofatigue 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;
char *name = ConcatArgs(1);
if (!CheatsOk(ent))
{
return;
}
if (!Q_stricmp(name, "on") || atoi(name))
{
ent->client->noclip = qtrue;
}
else if (!Q_stricmp(name, "off") || !Q_stricmp(name, "0"))
{
ent->client->noclip = qfalse;
}
else
{
ent->client->noclip = !ent->client->noclip;
}
if (ent->client->noclip)
{
msg = "noclip ON\n";
}
else
{
msg = "noclip OFF\n";
}
trap_SendServerCommand(ent - g_entities, va("print \"%s\"", msg));
}
/*
=================
Cmd_Kill_f
=================
*/
void Cmd_Kill_f(gentity_t *ent)
{
if (ent->client->sess.sessionTeam == TEAM_SPECTATOR ||
(ent->client->ps.pm_flags & PMF_LIMBO) ||
ent->health <= 0 || level.match_pause != PAUSE_NONE)
{
return;
}
#ifdef SAVEGAME_SUPPORT
if (g_gametype.integer == GT_SINGLE_PLAYER && g_reloading.integer)
{
return;
}
#endif // SAVEGAME_SUPPORT
ent->flags &= ~FL_GODMODE;
ent->client->ps.stats[STAT_HEALTH] = ent->health = 0;
ent->client->ps.persistant[PERS_HWEAPON_USE] = 0; // TTimo - if using /kill while at MG42
player_die(ent, ent, ent, (g_gamestate.integer == GS_PLAYING) ? 100000 : 135, MOD_SUICIDE);
}
void BotRecordTeamChange(int client);
void G_TeamDataForString(const char *teamstr, int clientNum, team_t *team, spectatorState_t *sState, int *specClient)
{
*sState = SPECTATOR_NOT;
if (!Q_stricmp(teamstr, "follow1"))
{
*team = TEAM_SPECTATOR;
*sState = SPECTATOR_FOLLOW;
if (specClient)
{
*specClient = -1;
}
}
else if (!Q_stricmp(teamstr, "follow2"))
{
*team = TEAM_SPECTATOR;
*sState = SPECTATOR_FOLLOW;
if (specClient)
{
*specClient = -2;
}
}
else if (!Q_stricmp(teamstr, "spectator") || !Q_stricmp(teamstr, "s"))
{
*team = TEAM_SPECTATOR;
*sState = SPECTATOR_FREE;
}
else if (!Q_stricmp(teamstr, "red") || !Q_stricmp(teamstr, "r") || !Q_stricmp(teamstr, "axis"))
{
*team = TEAM_AXIS;
}
else if (!Q_stricmp(teamstr, "blue") || !Q_stricmp(teamstr, "b") || !Q_stricmp(teamstr, "allies"))
{
*team = TEAM_ALLIES;
}
else
{
*team = PickTeam(clientNum);
if (!G_teamJoinCheck(*team, &g_entities[clientNum]))
{
*team = ((TEAM_AXIS | TEAM_ALLIES) & ~*team);
}
}
}
/*
=================
SetTeam
=================
*/
qboolean SetTeam(gentity_t *ent, char *s, qboolean force, weapon_t w1, weapon_t w2, qboolean setweapons)
{
team_t team, oldTeam;
gclient_t *client;
int clientNum;
spectatorState_t specState;
int specClient;
int respawnsLeft;
//
// see what change is requested
//
client = ent->client;
clientNum = client - level.clients;
specClient = 0;
// ydnar: preserve respawn count
respawnsLeft = client->ps.persistant[PERS_RESPAWNS_LEFT];
G_TeamDataForString(s, client - level.clients, &team, &specState, &specClient);
if (team != TEAM_SPECTATOR)
{
// Ensure the player can join
if (!G_teamJoinCheck(team, ent))
{
// Leave them where they were before the command was issued
return(qfalse);
}
if (g_noTeamSwitching.integer && (team != ent->client->sess.sessionTeam && ent->client->sess.sessionTeam != TEAM_SPECTATOR) && g_gamestate.integer == GS_PLAYING && !force)
{
trap_SendServerCommand(clientNum, "cp \"You cannot switch during a match, please wait until the round ends.\n\"");
return qfalse; // ignore the request
}
if (((g_gametype.integer == GT_WOLF_LMS && g_lms_teamForceBalance.integer) || g_teamForceBalance.integer) && !force)
{
int counts[TEAM_NUM_TEAMS];
counts[TEAM_ALLIES] = TeamCount(ent - g_entities, TEAM_ALLIES);
counts[TEAM_AXIS] = TeamCount(ent - g_entities, TEAM_AXIS);
// We allow a spread of one
if (team == TEAM_AXIS && counts[TEAM_AXIS] - counts[TEAM_ALLIES] >= 1)
{
CP("cp \"The Axis has too many players.\n\"");
return qfalse; // ignore the request
}
if (team == TEAM_ALLIES && counts[TEAM_ALLIES] - counts[TEAM_AXIS] >= 1)
{
CP("cp \"The Allies have too many players.\n\"");
return qfalse; // ignore the request
}
// It's ok, the team we are switching to has less or same number of players
}
}
if (g_maxGameClients.integer > 0 && level.numNonSpectatorClients >= g_maxGameClients.integer)
{
team = TEAM_SPECTATOR;
}
//
// decide if we will allow the change
//
oldTeam = client->sess.sessionTeam;
if (team == oldTeam && team != TEAM_SPECTATOR)
{
return qfalse;
}
// NERVE - SMF - prevent players from switching to regain deployments
if (g_gametype.integer != GT_WOLF_LMS)
{
if ((g_maxlives.integer > 0 ||
(g_alliedmaxlives.integer > 0 && ent->client->sess.sessionTeam == TEAM_ALLIES) ||
(g_axismaxlives.integer > 0 && ent->client->sess.sessionTeam == TEAM_AXIS))
&& ent->client->ps.persistant[PERS_RESPAWNS_LEFT] == 0 && oldTeam != TEAM_SPECTATOR)
{
CP("cp \"You can't switch teams because you are out of lives.\n\" 3");
return qfalse; // ignore the request
}
}
// DHM - Nerve :: Force players to wait 30 seconds before they can join a new team.
// OSP - changed to 5 seconds
// Gordon: disabling if in dev mode: cuz it sucks
// Gordon: bleh, half of these variables don't mean what they used to, so this doesn't work
/* if ( !g_cheats.integer ) {
if ( team != oldTeam && level.warmupTime == 0 && !client->pers.initialSpawn && ( (level.time - client->pers.connectTime) > 10000 ) && ( (level.time - client->pers.enterTime) < 5000 ) && !force ) {
CP(va("cp \"^3You must wait %i seconds before joining ^3a new team.\n\" 3", (int)(5 - ((level.time - client->pers.enterTime)/1000))));
return qfalse;
}
}*/
// dhm