/
cg_players.cpp
8606 lines (7066 loc) · 343 KB
/
cg_players.cpp
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
// cg_players.c -- handle the media and animation for player entities
#include "cgame/cg_local.h"
#include "Ghoul2/G2.h"
#include "game/bg_saga.h"
#include "cgame/fx_local.h"
#include "game/bg_luaevent.h"
#include "cgame/cg_media.h"
#include "game/bg_vehicles.h"
#include "JAPP/jp_csflags.h"
#include "JAPP/jp_ssflags.h"
#define IMPROVED_RAGDOLL
extern int cgSiegeTeam1PlShader;
extern int cgSiegeTeam2PlShader;
void CG_AddRadarEnt(centity_t *cent); // cg_ents.c
void CG_AddBracketedEnt(centity_t *cent); // cg_ents.c
qboolean CG_InFighter(void);
qboolean WP_SaberBladeUseSecondBladeStyle(saberInfo_t *saber, int bladeNum);
const char *cg_customSoundNames[MAX_CUSTOM_SOUNDS] = {"*death1", "*death2", "*death3", "*jump1", "*pain25", "*pain50", "*pain75", "*pain100",
"*falling1", "*choke1", "*choke2", "*choke3", "*gasp", "*land1", "*taunt", NULL};
// NPC sounds:
// Used as a supplement to the basic set for enemies and hazard team
// (keep numbers in ascending order in order for variant-capping to work)
const char *cg_customCombatSoundNames[MAX_CUSTOM_COMBAT_SOUNDS] = {"*anger1", // Say when acquire an enemy when didn't have one before
"*anger2", "*anger3",
"*victory1", // Say when killed an enemy
"*victory2", "*victory3",
"*confuse1", // Say when confused
"*confuse2", "*confuse3",
"*pushed1", // Say when force-pushed
"*pushed2", "*pushed3", "*choke1", "*choke2", "*choke3", "*ffwarn", "*ffturn", NULL};
// Used as a supplement to the basic set for stormtroopers
// (keep numbers in ascending order in order for variant-capping to work)
const char *cg_customExtraSoundNames[MAX_CUSTOM_EXTRA_SOUNDS] = {
"*chase1", "*chase2", "*chase3", "*cover1", "*cover2", "*cover3", "*cover4", "*cover5", "*detected1", "*detected2",
"*detected3", "*detected4", "*detected5", "*lost1", "*outflank1", "*outflank2", "*escaping1", "*escaping2", "*escaping3", "*giveup1",
"*giveup2", "*giveup3", "*giveup4", "*look1", "*look2", "*sight1", "*sight2", "*sight3", "*sound1", "*sound2",
"*sound3", "*suspicious1", "*suspicious2", "*suspicious3", "*suspicious4", "*suspicious5", NULL};
// Used as a supplement to the basic set for jedi
// (keep numbers in ascending order in order for variant-capping to work)
const char *cg_customJediSoundNames[MAX_CUSTOM_JEDI_SOUNDS] = {
"*combat1", "*combat2", "*combat3", "*jdetected1", "*jdetected2", "*jdetected3", "*taunt1", "*taunt2", "*taunt3", "*jchase1", "*jchase2", "*jchase3",
"*jlost1", "*jlost2", "*jlost3", "*deflect1", "*deflect2", "*deflect3", "*gloat1", "*gloat2", "*gloat3", "*pushfail", NULL};
// Used for DUEL taunts
const char *cg_customDuelSoundNames[MAX_CUSTOM_DUEL_SOUNDS] = {"*anger1", // Say when acquire an enemy when didn't have one before
"*anger2", "*anger3",
"*victory1", // Say when killed an enemy
"*victory2", "*victory3", "*taunt1", "*taunt2", "*taunt3", "*deflect1",
"*deflect2", "*deflect3", "*gloat1", "*gloat2", "*gloat3", NULL};
void CG_Disintegration(centity_t *cent, refEntity_t *ent);
sfxHandle_t CG_CustomSound(int clientNum, const char *soundName) {
clientInfo_t *ci;
int i, numCSounds = 0, numCComSounds = 0, numCExSounds = 0, numCJediSounds = 0, numCSiegeSounds = 0, numCDuelSounds = 0;
char lSoundName[MAX_QPATH];
if (soundName[0] != '*')
return trap->S_RegisterSound(soundName);
COM_StripExtension(soundName, lSoundName, sizeof(lSoundName));
if (clientNum < 0)
clientNum = 0;
if (clientNum >= MAX_CLIENTS)
ci = cg_entities[clientNum].npcClient;
else
ci = &cgs.clientinfo[clientNum];
if (!ci)
return 0;
for (i = 0; i < MAX_CUSTOM_SOUNDS; i++) {
if (!cg_customSoundNames[i]) {
numCSounds = i;
break;
}
}
if (clientNum >= MAX_CLIENTS) {
for (i = 0; i < MAX_CUSTOM_SOUNDS; i++) {
if (!cg_customCombatSoundNames[i]) {
numCComSounds = i;
break;
}
}
for (i = 0; i < MAX_CUSTOM_SOUNDS; i++) {
if (!cg_customExtraSoundNames[i]) {
numCExSounds = i;
break;
}
}
for (i = 0; i < MAX_CUSTOM_SOUNDS; i++) {
if (!cg_customJediSoundNames[i]) {
numCJediSounds = i;
break;
}
}
}
{ // if ( cgs.gametype == GT_SIEGE ) {
for (i = 0; i < MAX_CUSTOM_SIEGE_SOUNDS; i++) {
if (!bg_customSiegeSoundNames[i]) {
numCSiegeSounds = i;
break;
}
}
}
for (i = 0; i < MAX_CUSTOM_SOUNDS; i++) {
if (!cg_customDuelSoundNames[i]) {
numCDuelSounds = i;
break;
}
}
for (i = 0; i < MAX_CUSTOM_SOUNDS; i++) {
if (i < numCSounds && !strcmp(lSoundName, cg_customSoundNames[i]))
return ci->sounds[i];
else if (i < numCSiegeSounds && !strcmp(lSoundName, bg_customSiegeSoundNames[i])) // siege only
return ci->siegeSounds[i];
else if (i < numCDuelSounds && !strcmp(lSoundName, cg_customDuelSoundNames[i])) // taunts etc
return ci->duelSounds[i];
else if (clientNum >= MAX_CLIENTS && i < numCComSounds && !strcmp(lSoundName, cg_customCombatSoundNames[i])) // npc only
return ci->combatSounds[i];
else if (clientNum >= MAX_CLIENTS && i < numCExSounds && !strcmp(lSoundName, cg_customExtraSoundNames[i])) // npc only
return ci->extraSounds[i];
else if (clientNum >= MAX_CLIENTS && i < numCJediSounds && !strcmp(lSoundName, cg_customJediSoundNames[i])) // npc only
return ci->jediSounds[i];
}
#ifdef _DEBUG
Com_Printf("Unknown custom sound: %s\n", lSoundName);
#endif
return 0;
}
#define MAX_SURF_LIST_SIZE 1024
qboolean CG_ParseSurfsFile(const char *modelName, const char *skinName, char *surfOff, char *surfOn) {
int len, i;
const char *text_p, *token, *value;
static char text[20000] = {0};
char sfilename[MAX_QPATH];
fileHandle_t f;
// Raz: moved to heap
text[0] = '\0';
// check for multi-part skins
for (i = 0; skinName && skinName[i]; i++) {
if (skinName[i] == '|')
return qfalse;
}
// Load and parse .surf file
Com_sprintf(sfilename, sizeof(sfilename), "models/players/%s/model_%s.surf", modelName, skinName);
// load the file
len = trap->FS_Open(sfilename, &f, FS_READ);
if (len <= 0)
return qfalse;
if (len >= sizeof(text) - 1) {
Com_Printf("File %s too long\n", sfilename);
trap->FS_Close(f);
return qfalse;
}
trap->FS_Read(text, len, f);
text[len] = '\0';
trap->FS_Close(f);
// parse the text
text_p = text;
surfOff[0] = surfOn[0] = '\0';
// read information for surfOff and surfOn
while (1) {
token = COM_ParseExt(&text_p, qtrue);
if (!token || !token[0])
break;
// surfOff
if (!Q_stricmp(token, "surfOff")) {
if (COM_ParseString(&text_p, &value))
continue;
if (surfOff && surfOff[0]) {
Q_strcat(surfOff, MAX_SURF_LIST_SIZE, ",");
Q_strcat(surfOff, MAX_SURF_LIST_SIZE, value);
} else
Q_strncpyz(surfOff, value, MAX_SURF_LIST_SIZE);
continue;
}
// surfOn
if (!Q_stricmp(token, "surfOn")) {
if (COM_ParseString(&text_p, &value))
continue;
if (surfOn && surfOn[0]) {
Q_strcat(surfOn, MAX_SURF_LIST_SIZE, ",");
Q_strcat(surfOn, MAX_SURF_LIST_SIZE, value);
} else
Q_strncpyz(surfOn, value, MAX_SURF_LIST_SIZE);
continue;
}
}
return qtrue;
}
qboolean BG_IsValidCharacterModel(const char *modelName, const char *skinName);
qboolean BG_ValidateSkinForTeam(const char *modelName, char *skinName, int team, vector3 *colors);
static qboolean CG_RegisterClientModelname(clientInfo_t *ci, const char *modelName, const char *skinName, const char *teamName, int clientNum) {
int handle, checkSkin;
char afilename[MAX_QPATH], GLAName[MAX_QPATH], surfOff[MAX_SURF_LIST_SIZE], surfOn[MAX_SURF_LIST_SIZE], *slash;
const char *useSkinName;
vector3 tempVec = {0.0f, 0.0f, 0.0f};
qboolean badModel = qfalse;
cg.japp.trueviewWarning = qfalse;
retryModel:
if (badModel) {
if (modelName && modelName[0])
Com_Printf("WARNING: Attempted to load an unsupported multiplayer model %s! (bad or missing bone, or missing animation sequence)\n", modelName);
modelName = DEFAULT_MODEL;
skinName = "default";
badModel = qfalse;
}
// First things first. If this is a ghoul2 model, then let's make sure we demolish this first.
if (ci->ghoul2Model && trap->G2_HaveWeGhoul2Models(ci->ghoul2Model))
trap->G2API_CleanGhoul2Models(&(ci->ghoul2Model));
if (!BG_IsValidCharacterModel(modelName, skinName)) {
modelName = DEFAULT_MODEL;
skinName = "default";
}
if (cgs.gametype >= GT_TEAM && !cgs.jediVmerc && cgs.gametype != GT_SIEGE && !cg_forceModel.integer) {
BG_ValidateSkinForTeam(ci->modelName, ci->skinName, ci->team, reinterpret_cast<vector3 *>(&ci->colorOverride));
skinName = ci->skinName;
} else
ci->colorOverride.r = ci->colorOverride.g = ci->colorOverride.b = 0.0f;
// Raz: fix for transparent custom skin parts
// three part skin
if (strchr(skinName, '|') && strstr(skinName, "head") && strstr(skinName, "torso") && strstr(skinName, "lower"))
useSkinName = va("models/players/%s/|%s", modelName, skinName);
else
useSkinName = va("models/players/%s/model_%s.skin", modelName, skinName);
checkSkin = trap->R_RegisterSkin(useSkinName);
if (checkSkin)
ci->torsoSkin = checkSkin;
else
ci->torsoSkin = trap->R_RegisterSkin(va("models/players/%s/model_default.skin", modelName));
Com_sprintf(afilename, sizeof(afilename), "models/players/%s/model.glm", modelName);
handle = trap->G2API_InitGhoul2Model(&ci->ghoul2Model, afilename, 0, ci->torsoSkin, 0, 0, 0);
if (handle < 0)
return qfalse;
// The model is now loaded.
trap->G2API_SetSkin(ci->ghoul2Model, 0, ci->torsoSkin, ci->torsoSkin);
GLAName[0] = '\0';
trap->G2API_GetGLAName(ci->ghoul2Model, 0, GLAName);
if (GLAName[0]) {
if (!strstr(GLAName, "players/_humanoid/")) {
badModel = qtrue;
goto retryModel;
}
}
if (!BGPAFtextLoaded) {
if (!GLAName[0]) {
badModel = qtrue;
goto retryModel;
}
Q_strncpyz(afilename, GLAName, sizeof(afilename));
slash = Q_strrchr(afilename, '/');
if (slash)
strcpy(slash, "/animation.cfg");
else
return qfalse;
// rww - All player models must use humanoid, no matter what.
if (Q_stricmp(afilename, "models/players/_humanoid/animation.cfg")) {
Com_Printf("Model does not use supported animation config.\n");
return qfalse;
} else if (BG_ParseAnimationFile("models/players/_humanoid/animation.cfg", bgHumanoidAnimations, qtrue) == -1) {
Com_Printf("Failed to load animation file models/players/_humanoid/animation.cfg\n");
return qfalse;
}
BG_ParseAnimationEvtFile("models/players/_humanoid/", 0, -1); // get the sounds for the humanoid anims
} else if (!bgAllEvents[0].eventsParsed) {
// make sure the player anim sounds are loaded even if the anims already are
BG_ParseAnimationEvtFile("models/players/_humanoid/", 0, -1);
}
if (CG_ParseSurfsFile(modelName, skinName, surfOff, surfOn)) {
// turn on/off any surfs
const char *token, *p;
// Now turn on/off any surfaces
if (surfOff[0]) {
p = surfOff;
while (1) {
token = COM_ParseExt(&p, qtrue);
if (!token[0])
break;
// turn off this surf
trap->G2API_SetSurfaceOnOff(ci->ghoul2Model, token, 0x00000002 /*G2SURFACEFLAG_OFF*/);
}
}
if (surfOn[0]) {
p = surfOn;
while (1) {
token = COM_ParseExt(&p, qtrue);
if (!token[0])
break;
// turn on this surf
trap->G2API_SetSurfaceOnOff(ci->ghoul2Model, token, 0);
}
}
}
ci->bolt_rhand = trap->G2API_AddBolt(ci->ghoul2Model, 0, "*r_hand");
if (!trap->G2API_SetBoneAnim(ci->ghoul2Model, 0, "model_root", 0, 12, BONE_ANIM_OVERRIDE_LOOP, 1.0f, cg.time, -1, -1))
badModel = qtrue;
if (!trap->G2API_SetBoneAngles(ci->ghoul2Model, 0, "upper_lumbar", &tempVec, BONE_ANGLES_POSTMULT, POSITIVE_X, NEGATIVE_Y, NEGATIVE_Z, NULL, 0, cg.time))
badModel = qtrue;
if (!trap->G2API_SetBoneAngles(ci->ghoul2Model, 0, "cranium", &tempVec, BONE_ANGLES_POSTMULT, POSITIVE_Z, NEGATIVE_Y, POSITIVE_X, NULL, 0, cg.time))
badModel = qtrue;
ci->bolt_lhand = trap->G2API_AddBolt(ci->ghoul2Model, 0, "*l_hand");
// rhand must always be first bolt. lhand always second. Whichever you want the jetpack bolted to must always be third.
trap->G2API_AddBolt(ci->ghoul2Model, 0, "*chestg");
// claw bolts
trap->G2API_AddBolt(ci->ghoul2Model, 0, "*r_hand_cap_r_arm");
trap->G2API_AddBolt(ci->ghoul2Model, 0, "*l_hand_cap_l_arm");
ci->bolt_head = trap->G2API_AddBolt(ci->ghoul2Model, 0, "*head_top");
if (ci->bolt_head == -1)
ci->bolt_head = trap->G2API_AddBolt(ci->ghoul2Model, 0, "ceyebrow");
ci->bolt_motion = trap->G2API_AddBolt(ci->ghoul2Model, 0, "Motion");
// We need a lower lumbar bolt for footsteps
ci->bolt_llumbar = trap->G2API_AddBolt(ci->ghoul2Model, 0, "lower_lumbar");
if (ci->bolt_rhand == -1 || ci->bolt_lhand == -1 || ci->bolt_head == -1 || ci->bolt_motion == -1 || ci->bolt_llumbar == -1)
badModel = qtrue;
if (badModel)
goto retryModel;
if (!Q_stricmp(modelName, "boba_fett")) {
// special case, turn off the jetpack surfs
trap->G2API_SetSurfaceOnOff(ci->ghoul2Model, "torso_rjet", TURN_OFF);
trap->G2API_SetSurfaceOnOff(ci->ghoul2Model, "torso_cjet", TURN_OFF);
trap->G2API_SetSurfaceOnOff(ci->ghoul2Model, "torso_ljet", TURN_OFF);
}
if (clientNum != -1)
cg_entities[clientNum].ghoul2weapon = NULL;
Q_strncpyz(ci->teamName, teamName, sizeof(ci->teamName));
// Model icon for drawing the portrait on screen
ci->modelIcon = trap->R_RegisterShaderNoMip(va("models/players/%s/icon_%s", modelName, skinName));
if (!ci->modelIcon) {
int i = 0, j;
char iconName[1024];
strcpy(iconName, "icon_");
j = strlen(iconName);
for (i = 0, j = strlen(iconName); skinName[i] && skinName[i] != '|' && j < 1024; i++, j++)
iconName[j] = skinName[i];
iconName[j] = '\0';
if (skinName[i] == '|')
ci->modelIcon = trap->R_RegisterShaderNoMip(va("models/players/%s/%s", modelName, iconName));
}
return qtrue;
}
static void CG_ColorFromInt(int val, vector3 *color) {
VectorClear(color);
if (val < 1 || val > 7) {
VectorSet(color, 1, 1, 1);
return;
}
if (val & 1)
color->b = 1.0f;
if (val & 2)
color->g = 1.0f;
if (val & 4)
color->r = 1.0f;
}
static void CG_ColorFromString(const char *v, vector3 *color) { CG_ColorFromInt(atoi(v), color); }
// load anim info
int CG_G2SkelForModel(void *g2) {
int animIndex = -1;
char GLAName[MAX_QPATH], *slash;
GLAName[0] = '\0';
trap->G2API_GetGLAName(g2, 0, GLAName);
slash = Q_strrchr(GLAName, '/');
if (slash) {
strcpy(slash, "/animation.cfg");
animIndex = BG_ParseAnimationFile(GLAName, NULL, qfalse);
}
return animIndex;
}
// get the appropriate anim events file index
int CG_G2EvIndexForModel(void *g2, int animIndex) {
int evtIndex = -1;
char GLAName[MAX_QPATH], *slash;
if (animIndex == -1) {
assert(!"shouldn't happen, bad animIndex");
return -1;
}
GLAName[0] = '\0';
trap->G2API_GetGLAName(g2, 0, GLAName);
slash = Q_strrchr(GLAName, '/');
if (slash) {
*(++slash) = '\0';
evtIndex = BG_ParseAnimationEvtFile(GLAName, animIndex, bgNumAnimEvents);
}
return evtIndex;
}
#define DEFAULT_FEMALE_SOUNDPATH "chars/mp_generic_female/misc"
#define DEFAULT_MALE_SOUNDPATH "chars/mp_generic_male/misc"
#define DEFAULT_NEUTER_SOUNDPATH "chars/mp_generic_male/misc"
void CG_LoadCISounds(clientInfo_t *ci, qboolean modelloaded) {
fileHandle_t f;
gender_e gender = GENDER_MALE;
int i = 0, fLen = 0;
const char *dir, *s;
char soundpath[MAX_QPATH], soundName[1024];
dir = ci->modelName;
if (!ci->skinName[0] || !Q_stricmp("default", ci->skinName)) {
fLen = trap->FS_Open(va("models/players/%s/sounds.cfg", dir), &f, FS_READ);
if (!f)
fLen = trap->FS_Open(va("models/players/%s/sounds_default.cfg", dir), &f, FS_READ);
} else {
fLen = trap->FS_Open(va("models/players/%s/sounds_%s.cfg", dir, ci->skinName), &f, FS_READ);
if (!f)
fLen = trap->FS_Open(va("models/players/%s/sounds.cfg", dir), &f, FS_READ);
}
soundpath[0] = '\0';
if (f) {
trap->FS_Read(soundpath, fLen, f);
soundpath[fLen] = '\0';
for (i = fLen; i >= 0 && soundpath[i] != '\n'; i--) {
if (soundpath[i] == 'f') {
gender = GENDER_FEMALE;
soundpath[i] = '\0';
}
#if 0
else if ( soundpath[i] == 'n' ) {
gender = GENDER_NEUTER;
soundpath[i] = '\0';
}
#endif
}
for (i = 0; soundpath[i] && soundpath[i] != '\r' && soundpath[i] != '\n'; i++) {
//
}
soundpath[i] = '\0';
trap->FS_Close(f);
ci->gender = gender;
}
trap->S_Shutup(qtrue);
for (i = 0; i < MAX_CUSTOM_SOUNDS; i++) {
s = cg_customSoundNames[i];
if (!s)
break;
Com_sprintf(soundName, sizeof(soundName), "%s", s + 1);
COM_StripExtension(soundName, soundName, sizeof(soundName));
// strip the extension because we might want .mp3's
ci->sounds[i] = '\0';
// if the model didn't load use the sounds of the default model
if (soundpath[0])
ci->sounds[i] = trap->S_RegisterSound(va("sound/chars/%s/misc/%s", soundpath, soundName));
else if (modelloaded)
ci->sounds[i] = trap->S_RegisterSound(va("sound/chars/%s/misc/%s", dir, soundName));
if (!ci->sounds[i]) {
if (gender == GENDER_MALE)
ci->sounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_MALE_SOUNDPATH, soundName));
else if (gender == GENDER_FEMALE)
ci->sounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_FEMALE_SOUNDPATH, soundName));
else
ci->sounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_NEUTER_SOUNDPATH, soundName));
}
}
{ // if ( cgs.gametype == GT_SIEGE ) {
for (i = 0; i < MAX_CUSTOM_SIEGE_SOUNDS; i++) {
s = bg_customSiegeSoundNames[i];
if (!s)
break;
Com_sprintf(soundName, sizeof(soundName), "%s", s + 1);
COM_StripExtension(soundName, soundName, sizeof(soundName));
// strip the extension because we might want .mp3's
ci->siegeSounds[i] = '\0';
// if the model didn't load use the sounds of the default model
if (soundpath[0]) {
ci->siegeSounds[i] = trap->S_RegisterSound(va("sound/chars/%s/misc/%s", soundpath, soundName));
if (!ci->siegeSounds[i])
ci->siegeSounds[i] = trap->S_RegisterSound(va("sound/%s/%s", soundpath, soundName));
} else if (modelloaded)
ci->siegeSounds[i] = trap->S_RegisterSound(va("sound/chars/%s/misc/%s", dir, soundName));
if (!ci->siegeSounds[i]) {
if (gender == GENDER_MALE)
ci->siegeSounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_MALE_SOUNDPATH, soundName));
else if (gender == GENDER_FEMALE)
ci->siegeSounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_FEMALE_SOUNDPATH, soundName));
else
ci->siegeSounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_NEUTER_SOUNDPATH, soundName));
}
}
}
{ // if ( cgs.gametype == GT_DUEL || cgs.gametype == GT_POWERDUEL ) {
// load the Duel sounds then
for (i = 0; i < MAX_CUSTOM_DUEL_SOUNDS; i++) {
s = cg_customDuelSoundNames[i];
if (!s)
break;
Com_sprintf(soundName, sizeof(soundName), "%s", s + 1);
COM_StripExtension(soundName, soundName, sizeof(soundName));
// strip the extension because we might want .mp3's
ci->duelSounds[i] = '\0';
// if the model didn't load use the sounds of the default model
if (soundpath[0])
ci->duelSounds[i] = trap->S_RegisterSound(va("sound/chars/%s/misc/%s", soundpath, soundName));
else if (modelloaded)
ci->duelSounds[i] = trap->S_RegisterSound(va("sound/chars/%s/misc/%s", dir, soundName));
if (!ci->duelSounds[i]) {
if (gender == GENDER_MALE)
ci->duelSounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_MALE_SOUNDPATH, soundName));
else if (gender == GENDER_FEMALE)
ci->duelSounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_FEMALE_SOUNDPATH, soundName));
else
ci->duelSounds[i] = trap->S_RegisterSound(va("sound/%s/%s", DEFAULT_NEUTER_SOUNDPATH, soundName));
}
}
}
trap->S_Shutup(qfalse);
}
// Load it now, taking the disk hits. This will usually be deferred to a safe time
void CG_LoadClientInfo(clientInfo_t *ci) {
qboolean modelloaded;
int clientNum, i;
char teamname[MAX_QPATH];
const char *fallbackModel = DEFAULT_MODEL;
if (ci->gender == GENDER_FEMALE)
fallbackModel = DEFAULT_MODEL_FEMALE;
clientNum = ci - cgs.clientinfo;
if (clientNum < 0 || clientNum >= MAX_CLIENTS)
clientNum = -1;
ci->deferred = qfalse;
teamname[0] = '\0';
if (cgs.gametype >= GT_TEAM) {
if (ci->team == TEAM_BLUE)
Q_strncpyz(teamname, DEFAULT_BLUETEAM_NAME /*cg_blueTeamName.string*/, sizeof(teamname));
else
Q_strncpyz(teamname, DEFAULT_REDTEAM_NAME /*cg_redTeamName.string*/, sizeof(teamname));
}
if (teamname[0])
strcat(teamname, "/");
modelloaded = qtrue;
if (cgs.gametype == GT_SIEGE && (ci->team == TEAM_SPECTATOR || ci->siegeIndex == -1)) {
// yeah.. kind of a hack I guess. Don't care until they are actually ingame with a valid class.
if (!CG_RegisterClientModelname(ci, fallbackModel, "default", teamname, -1))
trap->Error(ERR_DROP, "DEFAULT_MODEL (%s) failed to register", fallbackModel);
} else if (!CG_RegisterClientModelname(ci, ci->modelName, ci->skinName, teamname, clientNum)) {
// fall back to default team name
if (cgs.gametype >= GT_TEAM) {
// keep skin name
if (ci->team == TEAM_BLUE)
Q_strncpyz(teamname, DEFAULT_BLUETEAM_NAME, sizeof(teamname));
else
Q_strncpyz(teamname, DEFAULT_REDTEAM_NAME, sizeof(teamname));
if (!CG_RegisterClientModelname(ci, fallbackModel, ci->skinName, teamname, -1))
trap->Error(ERR_DROP, "DEFAULT_MODEL / skin (%s/%s) failed to register", fallbackModel, ci->skinName);
} else if (!CG_RegisterClientModelname(ci, fallbackModel, "default", teamname, -1))
trap->Error(ERR_DROP, "DEFAULT_MODEL (%s) failed to register", fallbackModel);
modelloaded = qfalse;
}
if (clientNum != -1)
trap->G2API_ClearAttachedInstance(clientNum);
if (clientNum != -1 && ci->ghoul2Model && trap->G2_HaveWeGhoul2Models(ci->ghoul2Model)) {
if (cg_entities[clientNum].ghoul2 && trap->G2_HaveWeGhoul2Models(cg_entities[clientNum].ghoul2))
trap->G2API_CleanGhoul2Models(&cg_entities[clientNum].ghoul2);
trap->G2API_DuplicateGhoul2Instance(ci->ghoul2Model, &cg_entities[clientNum].ghoul2);
// Attach the instance to this entity num so we can make use of client-server
// shared operations if possible.
trap->G2API_AttachInstanceToEntNum(cg_entities[clientNum].ghoul2, clientNum, qfalse);
// check now to see if we have this bone for setting anims and such
if (trap->G2API_AddBolt(cg_entities[clientNum].ghoul2, 0, "face") == -1)
cg_entities[clientNum].noFace = qtrue;
cg_entities[clientNum].localAnimIndex = CG_G2SkelForModel(cg_entities[clientNum].ghoul2);
cg_entities[clientNum].eventAnimIndex = CG_G2EvIndexForModel(cg_entities[clientNum].ghoul2, cg_entities[clientNum].localAnimIndex);
}
ci->newAnims = qfalse;
if (ci->torsoModel) {
orientation_t tag;
// if the torso model has the "tag_flag"
if (trap->R_LerpTag(&tag, ci->torsoModel, 0, 0, 1, "tag_flag"))
ci->newAnims = qtrue;
}
// sounds
if (cgs.gametype == GT_SIEGE && (ci->team == TEAM_SPECTATOR || ci->siegeIndex == -1)) {
// don't need to load sounds
} else
CG_LoadCISounds(ci, modelloaded);
ci->deferred = qfalse;
// reset any existing players and bodies, because they might be in bad
// frames for this new model
clientNum = ci - cgs.clientinfo;
for (i = 0; i < MAX_GENTITIES; i++) {
if (cg_entities[i].currentState.clientNum == clientNum && cg_entities[i].currentState.eType == ET_PLAYER)
CG_ResetPlayerEntity(&cg_entities[i]);
}
}
// Take care of initializing all the ghoul2 saber stuff based on clientinfo data. -rww
static void CG_InitG2SaberData(int saberNum, clientInfo_t *ci) {
trap->G2API_InitGhoul2Model(&ci->ghoul2Weapons[saberNum], ci->saber[saberNum].model, 0, ci->saber[saberNum].skin, 0, 0, 0);
if (ci->ghoul2Weapons[saberNum]) {
int k = 0, tagBolt;
const char *tagName;
if (ci->saber[saberNum].skin)
trap->G2API_SetSkin(ci->ghoul2Weapons[saberNum], 0, ci->saber[saberNum].skin, ci->saber[saberNum].skin);
if (ci->saber[saberNum].saberFlags & SFL_BOLT_TO_WRIST)
trap->G2API_SetBoltInfo(ci->ghoul2Weapons[saberNum], 0, 3 + saberNum);
else
trap->G2API_SetBoltInfo(ci->ghoul2Weapons[saberNum], 0, saberNum);
for (k = 0; k < ci->saber[saberNum].numBlades; k++) {
tagName = va("*blade%i", k + 1);
tagBolt = trap->G2API_AddBolt(ci->ghoul2Weapons[saberNum], 0, tagName);
if (tagBolt == -1) {
if (k == 0) {
// guess this is an 0ldsk3wl saber
tagBolt = trap->G2API_AddBolt(ci->ghoul2Weapons[saberNum], 0, "*flash");
if (tagBolt == -1) {
break;
}
}
if (tagBolt == -1) {
break;
}
}
}
}
}
static void CG_CopyClientInfoModel(clientInfo_t *from, clientInfo_t *to) {
VectorCopy(&from->headOffset, &to->headOffset);
to->gender = from->gender;
to->legsModel = from->legsModel;
to->legsSkin = from->legsSkin;
to->torsoModel = from->torsoModel;
to->torsoSkin = from->torsoSkin;
to->modelIcon = from->modelIcon;
to->newAnims = from->newAnims;
// rww - Trying to use the same ghoul2 pointer for two seperate clients == DISASTER
assert(to->ghoul2Model != from->ghoul2Model);
if (to->ghoul2Model && trap->G2_HaveWeGhoul2Models(to->ghoul2Model))
trap->G2API_CleanGhoul2Models(&to->ghoul2Model);
if (from->ghoul2Model && trap->G2_HaveWeGhoul2Models(from->ghoul2Model))
trap->G2API_DuplicateGhoul2Instance(from->ghoul2Model, &to->ghoul2Model);
to->bolt_head = from->bolt_head;
to->bolt_lhand = from->bolt_lhand;
to->bolt_rhand = from->bolt_rhand;
to->bolt_motion = from->bolt_motion;
to->bolt_llumbar = from->bolt_llumbar;
to->siegeIndex = from->siegeIndex;
memcpy(to->sounds, from->sounds, sizeof(to->sounds));
memcpy(to->siegeSounds, from->siegeSounds, sizeof(to->siegeSounds));
memcpy(to->duelSounds, from->duelSounds, sizeof(to->duelSounds));
}
static qboolean CG_ScanForExistingClientInfo(clientInfo_t *ci, int clientNum) {
int i;
clientInfo_t *match;
for (i = 0; i < cgs.maxclients; i++) {
match = &cgs.clientinfo[i];
if (!match->infoValid)
continue;
if (match->deferred)
continue;
if (!Q_stricmp(ci->modelName, match->modelName) && !Q_stricmp(ci->skinName, match->skinName) && !Q_stricmp(ci->saberName, match->saberName) &&
!Q_stricmp(ci->saber2Name, match->saber2Name) && (cgs.gametype < GT_TEAM || ci->team == match->team) && ci->siegeIndex == match->siegeIndex &&
match->ghoul2Model && match->bolt_head) // if the bolts haven't been initialized, this "match" is useless to us
{
// this clientinfo is identical, so use it's handles
ci->deferred = qfalse;
// rww - Filthy hack. If this is actually the info already belonging to us, just reassign the pointer.
// Switching instances when not necessary produces small animation glitches.
// Actually, before, were we even freeing the instance attached to the old clientinfo before copying
// this new clientinfo over it? Could be a nasty leak possibility. (though this should remedy it in theory)
if (clientNum == i) {
if (match->ghoul2Model && trap->G2_HaveWeGhoul2Models(match->ghoul2Model)) {
// The match has a valid instance (if it didn't, we'd probably already be fudged (^_^) at this state)
// First kill the copy we have if we have one. (but it should be null)
if (ci->ghoul2Model && trap->G2_HaveWeGhoul2Models(ci->ghoul2Model))
trap->G2API_CleanGhoul2Models(&ci->ghoul2Model);
VectorCopy(&match->headOffset, &ci->headOffset);
ci->gender = match->gender;
ci->legsModel = match->legsModel;
ci->legsSkin = match->legsSkin;
ci->torsoModel = match->torsoModel;
ci->torsoSkin = match->torsoSkin;
ci->modelIcon = match->modelIcon;
ci->newAnims = match->newAnims;
ci->bolt_head = match->bolt_head;
ci->bolt_lhand = match->bolt_lhand;
ci->bolt_rhand = match->bolt_rhand;
ci->bolt_motion = match->bolt_motion;
ci->bolt_llumbar = match->bolt_llumbar;
ci->siegeIndex = match->siegeIndex;
memcpy(ci->sounds, match->sounds, sizeof(ci->sounds));
memcpy(ci->siegeSounds, match->siegeSounds, sizeof(ci->siegeSounds));
memcpy(ci->duelSounds, match->duelSounds, sizeof(ci->duelSounds));
// We can share this pointer, because it already belongs to this client.
// The pointer itself and the ghoul2 instance is never actually changed, just passed between
// clientinfo structures.
ci->ghoul2Model = match->ghoul2Model;
}
} else
CG_CopyClientInfoModel(match, ci);
return qtrue;
}
}
// nothing matches, so defer the load
return qfalse;
}
// We aren't going to load it now, so grab some other client's info to use until we have some spare time.
static void CG_SetDeferredClientInfo(clientInfo_t *ci) {
int i;
clientInfo_t *match;
// if someone else is already the same models and skins we can just load the client info
for (i = 0; i < cgs.maxclients; i++) {
match = &cgs.clientinfo[i];
if (!match->infoValid || match->deferred)
continue;
if (Q_stricmp(ci->skinName, match->skinName) || Q_stricmp(ci->modelName, match->modelName) ||
(cgs.gametype >= GT_TEAM && ci->team != match->team && ci->team != TEAM_SPECTATOR)) {
continue;
}
// just load the real info cause it uses the same models and skins
CG_LoadClientInfo(ci);
return;
}
// if we are in teamplay, only grab a model if the skin is correct
if (cgs.gametype >= GT_TEAM) {
for (i = 0; i < cgs.maxclients; i++) {
match = &cgs.clientinfo[i];
if (!match->infoValid || match->deferred)
continue;
if (ci->team != TEAM_SPECTATOR && (Q_stricmp(ci->skinName, match->skinName) || (cgs.gametype >= GT_TEAM && ci->team != match->team))) {
continue;
}
ci->deferred = qtrue;
CG_CopyClientInfoModel(match, ci);
return;
}
// load the full model, because we don't ever want to show an improper team skin. This will cause a hitch for the
// first player, when the second enters.
// Combat shouldn't be going on yet, so it shouldn't matter
CG_LoadClientInfo(ci);
return;
}
// find the first valid clientinfo and grab its stuff
for (i = 0; i < cgs.maxclients; i++) {
match = &cgs.clientinfo[i];
if (!match->infoValid)
continue;
if (match->deferred)
continue;
ci->deferred = qtrue;
CG_CopyClientInfoModel(match, ci);
return;
}
// we should never get here...
// trap->Print( "CG_SetDeferredClientInfo: no valid clients!\n" );
// Actually it is possible now because of the unique sabers.
CG_LoadClientInfo(ci);
}
void WP_SetSaber(int entNum, saberInfo_t *sabers, int saberNum, const char *saberName);
void ParseRGBSaber(const char *str, vector3 *c);
void CG_NewClientInfo(int clientNum, qboolean entitiesInitialized) {
clientInfo_t *ci, newInfo;
const char *configstring, *v, *yo;
char *slash;
void *oldGhoul2, *oldG2Weapons[MAX_SABERS];
int i, k, r, g, b, full;
qboolean saberUpdate[MAX_SABERS];
ci = &cgs.clientinfo[clientNum];
oldGhoul2 = ci->ghoul2Model;
for (k = 0; k < MAX_SABERS; k++)
oldG2Weapons[k] = ci->ghoul2Weapons[k];
configstring = CG_ConfigString(clientNum + CS_PLAYERS);
if (!configstring[0]) {
// clean this stuff up first
if (ci->ghoul2Model && trap->G2_HaveWeGhoul2Models(ci->ghoul2Model))
trap->G2API_CleanGhoul2Models(&ci->ghoul2Model);
for (k = 0; k < MAX_SABERS; k++) {
if (ci->ghoul2Weapons[k] && trap->G2_HaveWeGhoul2Models(ci->ghoul2Weapons[k]))
trap->G2API_CleanGhoul2Models(&ci->ghoul2Weapons[k]);
}
// player just left
memset(ci, 0, sizeof(*ci));
return;
}
// build into a temp buffer so the defer checks can use the old value
memset(&newInfo, 0, sizeof(newInfo));
// isolate the player's name
Q_strncpyz(newInfo.name, Info_ValueForKey(configstring, "n"), sizeof(newInfo.name));
// colors
v = Info_ValueForKey(configstring, "c1");
CG_ColorFromString(v, &newInfo.color1);
newInfo.icolor1 = atoi(v);
v = Info_ValueForKey(configstring, "c2");
CG_ColorFromString(v, &newInfo.color2);
newInfo.icolor2 = atoi(v);
// bot skill
v = Info_ValueForKey(configstring, "skill");
if (v && v[0])
newInfo.botSkill = atoi(v);
else
newInfo.botSkill = -1;
// handicap
v = Info_ValueForKey(configstring, "hc");
newInfo.handicap = atoi(v);
// wins
v = Info_ValueForKey(configstring, "w");
newInfo.wins = atoi(v);
// losses
v = Info_ValueForKey(configstring, "l");
newInfo.losses = atoi(v);
// team
v = Info_ValueForKey(configstring, "t");
newInfo.team = (team_e)atoi(v);
// copy team info out to menu
if (clientNum == cg.clientNum)
trap->Cvar_Set("ui_team", v);
yo = Info_ValueForKey(configstring, "c3");
full = atoi(yo);
r = full & 255;
g = (full >> 8) & 255;
b = full >> 16;
if (cg.clientNum == clientNum && newInfo.icolor1 == SABER_RGB) {
trap->Cvar_Set("color1", va("%i", SABER_RGB));
trap->Cvar_Set("cp_sbRGB1", yo);
}
ParseRGBSaber(va("%i,%i,%i", r, g, b), &newInfo.rgb1);
yo = Info_ValueForKey(configstring, "c4");
full = atoi(yo);
r = full & 255;
g = (full >> 8) & 255;
b = full >> 16;
if (cg.clientNum == clientNum && newInfo.icolor2 == SABER_RGB) {
trap->Cvar_Set("color2", va("%i", SABER_RGB));
trap->Cvar_Set("cp_sbRGB2", yo);
}
ParseRGBSaber(va("%i,%i,%i", r, g, b), &newInfo.rgb2);
// Raz: Gender hints