/
g_cmds.c
5075 lines (4444 loc) · 116 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-2018 ET:Legacy team <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"
#ifdef FEATURE_OMNIBOT
#include "g_etbot_interface.h"
#endif
#ifdef FEATURE_LUA
#include "g_lua.h"
#endif
qboolean G_IsOnFireteam(int entityNum, fireteamData_t **teamNum);
/**
* @brief G_MatchOnePlayer
* @param[in] plist
* @param[out] err
* @param[in] len
* @return
*/
qboolean G_MatchOnePlayer(int *plist, char *err, size_t len)
{
err[0] = '\0';
if (plist[0] == -1)
{
Q_strcat(err, len, "no connected player by that name or slot #");
return qfalse;
}
if (plist[1] != -1)
{
char line[MAX_NAME_LENGTH + 10];
gclient_t *cl;
int *p;
line[0] = '\0';
Q_strcat(err, len, "more than one player name matches be more specific or use the slot #:\n");
for (p = plist; *p != -1; p++)
{
cl = &level.clients[*p];
if (cl->pers.connected == CON_CONNECTED)
{
Com_sprintf(line, MAX_NAME_LENGTH + 10, "%2i - %s^7\n", *p, cl->pers.netname);
if (strlen(err) + strlen(line) > len)
{
break;
}
Q_strcat(err, len, line);
}
}
return qfalse;
}
return qtrue;
}
/**
* @brief Sets plist to an array of integers that represent client numbers that have
* names that are a partial match for s. List is terminated by a -1.
*
* @param[in] s
* @param[out] plist
* @return Number of matching clientids.
*/
int ClientNumbersFromString(char *s, int *plist)
{
gclient_t *p;
int i, found = 0;
char s2[MAX_STRING_CHARS];
char n2[MAX_STRING_CHARS];
char *m;
char *end = NULL;
*plist = -1;
// if a number is provided, it might be a slot #
// check the whole string is a number and only if so assume it is a slot number
// still fails for players with a name like "23" and there are 24 slots used
i = (int) strtol(s, &end, 10); // end will be "" when s contains only digits
if ((!end || !*end) && i >= 0)
{
if (i >= 0 && i < level.maxclients)
{
p = &level.clients[i];
if (p->pers.connected == CON_CONNECTED || p->pers.connected == CON_CONNECTING)
{
*plist++ = i;
*plist = -1;
return 1;
}
}
}
// now look for name matches
SanitizeString(s, s2, qtrue);
if (strlen(s2) < 1)
{
return 0;
}
for (i = 0; i < level.maxclients; ++i)
{
p = &level.clients[i];
if (p->pers.connected != CON_CONNECTED && p->pers.connected != CON_CONNECTING)
{
continue;
}
SanitizeString(p->pers.netname, n2, qtrue);
m = strstr(n2, s2);
if (m != NULL)
{
*plist++ = i;
found++;
}
}
*plist = -1;
return found;
}
/*
* @brief G_TeamDamageStats
* @param[in] ent
*
* @note Unused
void G_TeamDamageStats(gentity_t *ent)
{
if (!ent->client) return;
{
float teamHitPct =
ent->client->sess.hits ?
(ent->client->sess.team_hits / ent->client->sess.hits)*(100):
0;
CPx(ent-g_entities,
va("print \"Team Hits: %.2f Total Hits: %.2f "
"Pct: %.2f Limit: %d\n\"",
ent->client->sess.team_hits,
ent->client->sess.hits,
teamHitPct,
g_teamDamageRestriction.integer
));
}
return;
}
*/
/**
* @brief G_PlaySound_Cmd
*/
void G_PlaySound_Cmd(void)
{
char sound[MAX_QPATH], name[MAX_NAME_LENGTH], cmd[32] = { "playsound" };
if (trap_Argc() < 2)
{
G_Printf("usage: playsound [name|slot#] sound\n");
return;
}
if (trap_Argc() > 2)
{
trap_Argv(0, cmd, sizeof(cmd));
trap_Argv(1, name, sizeof(name));
trap_Argv(2, sound, sizeof(sound));
}
else
{
trap_Argv(1, sound, sizeof(sound));
name[0] = '\0';
}
if (name[0])
{
int pids[MAX_CLIENTS];
char err[MAX_STRING_CHARS];
gentity_t *victim;
if (ClientNumbersFromString(name, pids) != 1)
{
G_MatchOnePlayer(pids, err, sizeof(err));
G_Printf("playsound: %s\n", err);
return;
}
victim = &level.gentities[pids[0]];
if (!Q_stricmp(cmd, "playsound_env"))
{
G_AddEvent(victim, EV_GENERAL_SOUND, G_SoundIndex(sound));
}
else
{
G_ClientSound(victim, G_SoundIndex(sound));
}
}
else
{
G_globalSound(sound);
}
}
#ifdef FEATURE_RATING
/**
* @brief G_SendSkillRating
* @param[in] ent
*/
static void G_SendSkillRating(gentity_t *ent)
{
char buffer[1024];
int i, clientNum;
gclient_t *cl;
if (!ent || !ent->client)
{
return;
}
trap_Argv(1, buffer, sizeof(buffer));
clientNum = atoi(buffer);
if (clientNum < 0 || clientNum > g_maxclients.integer)
{
return;
}
Q_strncpyz(buffer, "sra ", sizeof(buffer));
// win probability
Q_strcat(buffer, sizeof(buffer), va("%.1f ", level.axisProb * 100.f));
Q_strcat(buffer, sizeof(buffer), va("%.1f ", level.alliesProb * 100.f));
for (i = 0; i < level.numConnectedClients; i++)
{
cl = &level.clients[level.sortedClients[i]];
Q_strcat(buffer, sizeof(buffer), va("%.3f ", MIN(MAX(cl->sess.mu - 3 * cl->sess.sigma, 0.f), 2 * MU)));
}
trap_SendServerCommand(ent - g_entities, buffer);
}
#endif
/**
* @brief Add score with clientNum at index i of level.sortedClients[] to the string buf.
*
* @param ent - unused
* @param[in] i
* @param[out] buf
* @param[in] bufsize
*
* @return qtrue if the score was appended to buf, qfalse otherwise.
*
* @todo FIXME: FEATURE_MULTIVIEW might be buggy -> powerups var is used to store player class/type (differs from GPL Code)
* playerClass is no longer sent!
*/
qboolean G_SendScore_Add(gentity_t *ent, int i, char *buf, int bufsize)
{
gclient_t *cl = &level.clients[level.sortedClients[i]];
int ping, respawnsLeft = cl->ps.persistant[PERS_RESPAWNS_LEFT]; // number of respawns left
char entry[128];
int totalXP = 0;
int miscFlags = 0; // 1 - ready 2 - is bot
entry[0] = '\0';
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)
{
totalXP = cl->ps.persistant[PERS_SCORE];
}
else
{
int j;
if ((g_gametype.integer == GT_WOLF_CAMPAIGN && (g_campaigns[level.currentCampaign].current != 0 && !level.newCampaign)) ||
(g_gametype.integer == GT_WOLF_LMS && g_currentRound.integer != 0))
{
for (j = SK_BATTLE_SENSE; j < SK_NUM_SKILLS; j++)
{
totalXP += cl->sess.skillpoints[j];
}
}
else
{
for (j = SK_BATTLE_SENSE; j < SK_NUM_SKILLS; j++)
{
// current map XPs only
totalXP += cl->sess.skillpoints[j] - cl->sess.startskillpoints[j];
}
}
}
if (cl->ps.eFlags & EF_READY)
{
miscFlags |= 1;
}
if (g_entities[level.sortedClients[i]].r.svFlags & SVF_BOT)
{
miscFlags |= 2;
}
Com_sprintf(entry,
sizeof(entry),
" %i %i %i %i %i %i %i",
level.sortedClients[i],
totalXP,
ping,
(level.intermissiontime - cl->pers.enterTime) / 60000,
g_entities[level.sortedClients[i]].s.powerups,
miscFlags,
respawnsLeft
);
if ((strlen(buf) + strlen(entry) + 1) > bufsize)
{
return qfalse;
}
Q_strcat(buf, bufsize, entry);
return qtrue;
}
/**
* @brief Sends current scoreboard information
* @param[in] ent
*/
void G_SendScore(gentity_t *ent)
{
int i = 0;
int numSorted = level.numConnectedClients; // send the latest information on all clients
int count = 0;
// commands over 1022 will crash the client so they're
// pruned in trap_SendServerCommand()
// 1022 -32 for the startbuffer -3 for the clientNum
char buffer[987];
char startbuffer[32];
*buffer = '\0';
*startbuffer = '\0';
#ifdef FEATURE_RATING
if (g_skillRating.integer)
{
G_SendSkillRating(ent);
}
#endif
Q_strncpyz(startbuffer, va(
"sc0 %i %i",
level.teamScores[TEAM_AXIS],
level.teamScores[TEAM_ALLIES]),
sizeof(startbuffer));
// keep adding scores to the sc0 command until we fill
// up the buffer. Any scores that are left will be
// added on to the sc1 command.
for (; i < numSorted; ++i)
{
// the old version of SendScore() did this. I removed it
// originally because it seemed like an unneccessary hack.
// perhaps it is necessary for compat with CG_Argv()?
if (count == 33)
{
break;
}
if (!G_SendScore_Add(ent, i, buffer, sizeof(buffer)))
{
break;
}
count++;
}
trap_SendServerCommand(ent - g_entities, va("%s %i%s", startbuffer, count, buffer));
if (i == numSorted)
{
return;
}
count = 0;
*buffer = '\0';
*startbuffer = '\0';
Q_strncpyz(startbuffer, "sc1", sizeof(startbuffer));
for (; i < numSorted; ++i)
{
if (!G_SendScore_Add(ent, i, buffer, sizeof(buffer)))
{
G_Printf("ERROR: G_SendScore() buffer overflow\n");
break;
}
count++;
}
if (!count)
{
return;
}
trap_SendServerCommand(ent - g_entities, va("%s %i%s", startbuffer, count, buffer));
}
/**
* @brief Request current scoreboard information
* @param[out] ent
*/
void Cmd_Score_f(gentity_t *ent)
{
ent->client->wantsscore = qtrue;
//G_SendScore( ent );
}
/**
* @brief CheatsOk
* @param[in] ent
* @return
*/
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;
}
/**
* @brief Concatenates console arguments
* @param[in] start concatenate from this argument
*/
char *ConcatArgs(int start)
{
int i, c;
unsigned int tlen, len = 0;
static char line[MAX_STRING_CHARS];
char arg[MAX_STRING_CHARS];
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;
}
Com_Memcpy(line + len, arg, tlen);
len += tlen;
if (i != c - 1)
{
line[len] = ' ';
len++;
}
}
line[len] = 0;
return line;
}
/**
* @brief Remove case and control characters
* @param[in] in
* @param[out] out
* @param[in] fToLower
*/
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;
}
/**
* @brief ClientNumberFromString
* @param[in] to
* @param[in] s
* @return A player number for either a number or name string, -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;
}
/**
* @brief GetSkillPointUntilLevelUp
* @param[in] ent
* @param[in] skill
* @return
*/
float GetSkillPointUntilLevelUp(gentity_t *ent, skillType_t skill)
{
if (ent->client->sess.skill[skill] < NUM_SKILL_LEVELS - 1)
{
int i = ent->client->sess.skill[skill] + 1;
int x = 1;
for (; i < NUM_SKILL_LEVELS; i++, x++)
{
if (GetSkillTableData(skill)->skillLevels[ent->client->sess.skill[skill] + x] >= 0)
{
return GetSkillTableData(skill)->skillLevels[ent->client->sess.skill[skill] + x] - ent->client->sess.skillpoints[skill];
}
}
}
return -1;
}
/**
* @brief Give items to a client
* @param[in,out] ent
*/
void Cmd_Give_f(gentity_t *ent)
{
char *name, *amt;
//gitem_t *it;
weapon_t weapon;
qboolean give_all;
//gentity_t *it_ent;
//trace_t trace;
int amount;
qboolean hasAmount = qfalse;
if (!ent || !ent->client)
{
return;
}
if (!CheatsOk(ent))
{
return;
}
// check for an amount (like "give health 30")
amt = ConcatArgs(2);
if (*amt)
{
hasAmount = qtrue;
}
amount = atoi(amt);
name = ConcatArgs(1);
if (Q_stricmp(name, "all") == 0)
{
give_all = qtrue;
}
else
{
give_all = qfalse;
}
if (Q_stricmpn(name, "skill", 5) == 0)
{
skillType_t skill;
float points;
if ((ent->client->sess.sessionTeam != TEAM_ALLIES && ent->client->sess.sessionTeam != TEAM_AXIS) || g_gamestate.integer != GS_PLAYING)
{
trap_SendServerCommand(ent - g_entities, va("print \"give skill: Command not available - player is spectator or game isn't started.\n\""));
return;
}
if (hasAmount) // skill number given
{
skill = (skillType_t)amount; // Change amount to skill, so that we can use amount properly
if (skill >= SK_BATTLE_SENSE && skill < SK_NUM_SKILLS)
{
// Detecting the correct amount to move to the next skill level
points = GetSkillPointUntilLevelUp(ent, skill);
if (points < 0)
{
points = 20;
}
G_AddSkillPoints(ent, skill, points);
G_DebugAddSkillPoints(ent, skill, points, "give skill");
// ceil the given points to keep consistency with the displayed XP value in HUD
trap_SendServerCommand(ent - g_entities, va("print \"give skill: Skill %i '%s' increased (+%.0fXP).\n\"", skill, GetSkillTableData(skill)->skillNames, ceil(points)));
}
else
{
trap_SendServerCommand(ent - g_entities, va("print \"give skill <skill_no>: No valid skill '%i' (0-6).\n\"", skill));
}
}
else
{
// bumps all skills with 1 level
for (skill = SK_BATTLE_SENSE; skill < SK_NUM_SKILLS; skill++)
{
// Detecting the correct amount to move to the next skill level
points = GetSkillPointUntilLevelUp(ent, skill);
if (points < 0)
{
points = 20;
}
G_AddSkillPoints(ent, skill, points);
G_DebugAddSkillPoints(ent, skill, points, "give skill");
}
trap_SendServerCommand(ent - g_entities, va("print \"give skill: All skills increased by 1 level.\n\""));
}
return;
}
if (Q_stricmpn(name, "medal", 5) == 0)
{
int i;
for (i = SK_BATTLE_SENSE; i < SK_NUM_SKILLS; i++)
{
if (!ent->client->sess.medals[i])
{
ent->client->sess.medals[i] = 1;
break; // add 1 medal, not all at once..
}
}
ClientUserinfoChanged(ent - g_entities);
return;
}
if (give_all || Q_stricmpn(name, "health", 6) == 0)
{
// 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 (weapon = 0; weapon < WP_NUM_WEAPONS; weapon++)
{
COM_BitSet(ent->client->ps.weapons, weapon);
}
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, (weapon_t)ent->client->ps.weapon, amount, qtrue);
}
}
else
{
for (weapon = WP_KNIFE ; weapon < WP_NUM_WEAPONS ; weapon++)
{
if (COM_BitCheck(ent->client->ps.weapons, weapon) && weapon != WP_SATCHEL && weapon != WP_SATCHEL_DET)
{
Add_Ammo(ent, weapon, 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 (weapon = WP_KNIFE ; weapon < WP_NUM_WEAPONS; weapon++)
Add_Ammo(ent, weapon, amount, qtrue);
if (!give_all)
{
return;
}
}
// 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;
}
}
// 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 );
Com_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 );
}
}*/
}
/**
* @brief Sets client to godmode
* @param[in,out] ent
*
* @note 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));
}
/**
* @brief Sets client to nofatigue
* @param[in,out] ent
*
* @note 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
{