forked from TheSil/base_enhanced
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bg_saga.c
2098 lines (1823 loc) · 49.7 KB
/
bg_saga.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) 2000-2002 Raven Software, Inc.
//
/*****************************************************************************
* name: bg_saga.c
*
* desc: Siege module, shared for game, cgame, and ui.
*
* $Author: osman $
* $Revision: 1.9 $
*
*****************************************************************************/
#include "q_shared.h"
#include "bg_saga.h"
#include "bg_weapons.h"
#include "bg_public.h"
#define SIEGECHAR_TAB 9 //perhaps a bit hacky, but I don't think there's any define existing for "tab"
//Could use strap stuff but I don't particularly care at the moment anyway.
#include "namespace_begin.h"
extern int trap_FS_FOpenFile( const char *qpath, fileHandle_t *f, fsMode_t mode );
extern void trap_FS_Read( void *buffer, int len, fileHandle_t f );
extern void trap_FS_Write( const void *buffer, int len, fileHandle_t f );
extern void trap_FS_FCloseFile( fileHandle_t f );
extern int trap_FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
#ifndef QAGAME //cgame, ui
qhandle_t trap_R_RegisterShaderNoMip( const char *name );
#endif
char siege_info[MAX_SIEGE_INFO_SIZE];
int siege_valid = 0;
siegeTeam_t *team1Theme = NULL;
siegeTeam_t *team2Theme = NULL;
siegeClass_t bgSiegeClasses[MAX_SIEGE_CLASSES];
int bgNumSiegeClasses = 0;
siegeTeam_t bgSiegeTeams[MAX_SIEGE_TEAMS];
int bgNumSiegeTeams = 0;
//class flags
stringID_table_t bgSiegeClassFlagNames[] =
{
ENUM2STRING(CFL_MORESABERDMG),
ENUM2STRING(CFL_STRONGAGAINSTPHYSICAL),
ENUM2STRING(CFL_FASTFORCEREGEN),
ENUM2STRING(CFL_STATVIEWER),
ENUM2STRING(CFL_HEAVYMELEE),
ENUM2STRING(CFL_SINGLE_ROCKET),
ENUM2STRING(CFL_CUSTOMSKEL),
ENUM2STRING(CFL_EXTRA_AMMO),
ENUM2STRING(CFL_SPIDERMAN),
ENUM2STRING(CFL_GRAPPLE),
ENUM2STRING(CFL_KICK),
ENUM2STRING(CFL_WONDERWOMAN),
ENUM2STRING(CFL_SMALLSHIELD),
{"", -1}
};
//saber stances
stringID_table_t StanceTable[] =
{
ENUM2STRING(SS_NONE),
ENUM2STRING(SS_FAST),
ENUM2STRING(SS_MEDIUM),
ENUM2STRING(SS_STRONG),
ENUM2STRING(SS_DESANN),
ENUM2STRING(SS_TAVION),
ENUM2STRING(SS_DUAL),
ENUM2STRING(SS_STAFF),
{"", 0}
};
stringID_table_t OtherEntTypeTable[] = {
ENUM2STRING(OTHERENTTYPE_SELF),
ENUM2STRING(OTHERENTTYPE_ALLY),
ENUM2STRING(OTHERENTTYPE_ENEMY),
ENUM2STRING(OTHERENTTYPE_VEHICLE),
ENUM2STRING(OTHERENTTYPE_OTHER),
{"", -1}
};
stringID_table_t ModTable[] = {
ENUM2STRING(MOD_UNKNOWN),
ENUM2STRING(MOD_STUN_BATON),
ENUM2STRING(MOD_MELEE),
ENUM2STRING(MOD_SABER),
ENUM2STRING(MOD_BRYAR_PISTOL),
ENUM2STRING(MOD_BRYAR_PISTOL_ALT),
ENUM2STRING(MOD_BLASTER),
ENUM2STRING(MOD_TURBLAST),
ENUM2STRING(MOD_DISRUPTOR),
ENUM2STRING(MOD_DISRUPTOR_SPLASH),
ENUM2STRING(MOD_DISRUPTOR_SNIPER),
ENUM2STRING(MOD_BOWCASTER),
ENUM2STRING(MOD_REPEATER),
ENUM2STRING(MOD_REPEATER_ALT),
ENUM2STRING(MOD_REPEATER_ALT_SPLASH),
ENUM2STRING(MOD_DEMP2),
ENUM2STRING(MOD_DEMP2_ALT),
ENUM2STRING(MOD_FLECHETTE),
ENUM2STRING(MOD_FLECHETTE_ALT_SPLASH),
ENUM2STRING(MOD_ROCKET),
ENUM2STRING(MOD_ROCKET_SPLASH),
ENUM2STRING(MOD_ROCKET_HOMING),
ENUM2STRING(MOD_ROCKET_HOMING_SPLASH),
ENUM2STRING(MOD_THERMAL),
ENUM2STRING(MOD_THERMAL_SPLASH),
ENUM2STRING(MOD_TRIP_MINE_SPLASH),
ENUM2STRING(MOD_TIMED_MINE_SPLASH),
ENUM2STRING(MOD_DET_PACK_SPLASH),
ENUM2STRING(MOD_VEHICLE),
ENUM2STRING(MOD_CONC),
ENUM2STRING(MOD_CONC_ALT),
ENUM2STRING(MOD_FORCE_DARK),
ENUM2STRING(MOD_SENTRY),
ENUM2STRING(MOD_WATER),
ENUM2STRING(MOD_SLIME),
ENUM2STRING(MOD_LAVA),
ENUM2STRING(MOD_CRUSH),
ENUM2STRING(MOD_TELEFRAG),
ENUM2STRING(MOD_FALLING),
ENUM2STRING(MOD_SUICIDE),
ENUM2STRING(MOD_TARGET_LASER),
ENUM2STRING(MOD_TRIGGER_HURT),
ENUM2STRING(MOD_TEAM_CHANGE),
ENUM2STRING(MOD_MAX),
ENUM2STRING(MOD_SPECIAL_SENTRYBOMB),
{"", 0xFFFFFFFFFFFFFFFFll}
};
//Weapon and force power tables are also used in NPC parsing code and some other places.
stringID_table_t WPTable[] =
{
{"NULL",WP_NONE},
ENUM2STRING(WP_NONE),
// Player weapons
ENUM2STRING(WP_STUN_BATON),
ENUM2STRING(WP_MELEE),
ENUM2STRING(WP_SABER),
ENUM2STRING(WP_BRYAR_PISTOL),
{"WP_BLASTER_PISTOL", WP_BRYAR_PISTOL},
ENUM2STRING(WP_BLASTER),
ENUM2STRING(WP_DISRUPTOR),
ENUM2STRING(WP_BOWCASTER),
ENUM2STRING(WP_REPEATER),
ENUM2STRING(WP_DEMP2),
ENUM2STRING(WP_FLECHETTE),
ENUM2STRING(WP_ROCKET_LAUNCHER),
ENUM2STRING(WP_THERMAL),
ENUM2STRING(WP_TRIP_MINE),
ENUM2STRING(WP_DET_PACK),
ENUM2STRING(WP_CONCUSSION),
ENUM2STRING(WP_BRYAR_OLD),
ENUM2STRING(WP_EMPLACED_GUN),
ENUM2STRING(WP_TURRET),
{"", 0}
};
stringID_table_t FPTable[] =
{
ENUM2STRING(FP_HEAL),
ENUM2STRING(FP_LEVITATION),
ENUM2STRING(FP_SPEED),
ENUM2STRING(FP_PUSH),
ENUM2STRING(FP_PULL),
ENUM2STRING(FP_TELEPATHY),
ENUM2STRING(FP_GRIP),
ENUM2STRING(FP_LIGHTNING),
ENUM2STRING(FP_RAGE),
ENUM2STRING(FP_PROTECT),
ENUM2STRING(FP_ABSORB),
ENUM2STRING(FP_TEAM_HEAL),
ENUM2STRING(FP_TEAM_FORCE),
ENUM2STRING(FP_DRAIN),
ENUM2STRING(FP_SEE),
ENUM2STRING(FP_SABER_OFFENSE),
ENUM2STRING(FP_SABER_DEFENSE),
ENUM2STRING(FP_SABERTHROW),
{"", -1}
};
stringID_table_t HoldableTable[] =
{
ENUM2STRING(HI_NONE),
ENUM2STRING(HI_SEEKER),
ENUM2STRING(HI_SHIELD),
ENUM2STRING(HI_MEDPAC),
ENUM2STRING(HI_MEDPAC_BIG),
ENUM2STRING(HI_BINOCULARS),
ENUM2STRING(HI_SENTRY_GUN),
ENUM2STRING(HI_JETPACK),
ENUM2STRING(HI_HEALTHDISP),
ENUM2STRING(HI_AMMODISP),
ENUM2STRING(HI_EWEB),
ENUM2STRING(HI_CLOAK),
{"", -1}
};
stringID_table_t PowerupTable[] =
{
ENUM2STRING(PW_NONE),
ENUM2STRING(PW_QUAD),
ENUM2STRING(PW_BATTLESUIT),
ENUM2STRING(PW_PULL),
ENUM2STRING(PW_REDFLAG),
ENUM2STRING(PW_BLUEFLAG),
ENUM2STRING(PW_NEUTRALFLAG),
ENUM2STRING(PW_SHIELDHIT),
ENUM2STRING(PW_SPEEDBURST),
ENUM2STRING(PW_DISINT_4),
ENUM2STRING(PW_SPEED),
ENUM2STRING(PW_CLOAKED),
ENUM2STRING(PW_FORCE_ENLIGHTENED_LIGHT),
ENUM2STRING(PW_FORCE_ENLIGHTENED_DARK),
ENUM2STRING(PW_FORCE_BOON),
ENUM2STRING(PW_YSALAMIRI),
{"", -1}
};
stringID_table_t AmmoTable[] =
{
ENUM2STRING(AMMO_NONE),
ENUM2STRING(AMMO_FORCE),
ENUM2STRING(AMMO_BLASTER),
ENUM2STRING(AMMO_POWERCELL),
ENUM2STRING(AMMO_METAL_BOLTS),
ENUM2STRING(AMMO_ROCKETS),
ENUM2STRING(AMMO_EMPLACED),
ENUM2STRING(AMMO_THERMAL),
ENUM2STRING(AMMO_TRIPMINE),
ENUM2STRING(AMMO_DETPACK),
{"", -1}
};
// this crap was done inconsistently so i have to resort to this
stupidSiegeClassNum_t SiegeClassEnumToStupidClassNumber(siegePlayerClassFlags_t scl) {
switch (scl) {
case SPC_INFANTRY: return SSCN_ASSAULT;
case SPC_HEAVY_WEAPONS: return SSCN_HW;
case SPC_DEMOLITIONIST: return SSCN_DEMO;
case SPC_VANGUARD: return SSCN_SCOUT;
case SPC_SUPPORT: return SSCN_TECH;
case SPC_JEDI: return SSCN_JEDI;
default: return -1;
}
}
//======================================
//Parsing functions
//======================================
void BG_SiegeStripTabs(char *buf)
{
int i = 0;
int i_r = 0;
while (buf[i])
{
if (buf[i] != SIEGECHAR_TAB)
{ //not a tab, just stick it in
buf[i_r] = buf[i];
}
else
{ //If it's a tab, convert it to a space.
buf[i_r] = ' ';
}
i_r++;
i++;
}
buf[i_r] = '\0';
}
int BG_SiegeGetValueGroup(char *buf, char *group, char *outbuf)
{
int i = 0;
int j;
char checkGroup[4096];
qboolean isGroup;
int parseGroups = 0;
while (buf[i])
{
if (buf[i] != ' ' && buf[i] != '{' && buf[i] != '}' && buf[i] != '\n' && buf[i] != '\r' && buf[i] != SIEGECHAR_TAB)
{ //we're on a valid character
if (buf[i] == '/' &&
buf[i+1] == '/')
{ //this is a comment, so skip over it
while (buf[i] && buf[i] != '\n' && buf[i] != '\r' && buf[i] != SIEGECHAR_TAB)
{
i++;
}
}
else
{ //parse to the next space/endline/eos and check this value against our group value.
j = 0;
while (buf[i] != ' ' && buf[i] != '\n' && buf[i] != '\r' && buf[i] != SIEGECHAR_TAB && buf[i] != '{' && buf[i])
{
if (buf[i] == '/' && buf[i+1] == '/')
{ //hit a comment, break out.
break;
}
checkGroup[j] = buf[i];
j++;
i++;
}
checkGroup[j] = 0;
//Make sure this is a group as opposed to a globally defined value.
if (buf[i] == '/' && buf[i+1] == '/')
{ //stopped on a comment, so first parse to the end of it.
while (buf[i] && buf[i] != '\n' && buf[i] != '\r')
{
i++;
}
while (buf[i] == '\n' || buf[i] == '\r')
{
i++;
}
}
if (!buf[i])
{
Com_Error(ERR_DROP, "Unexpected EOF while looking for group '%s'", group);
}
isGroup = qfalse;
while ((buf[i] && buf[i] == ' ') || buf[i] == SIEGECHAR_TAB || buf[i] == '\n' || buf[i] == '\r')
{ //parse to the next valid character
i++;
}
if (buf[i] == '{')
{ //if the next valid character is an opening bracket, then this is indeed a group
isGroup = qtrue;
}
//Is this the one we want?
if (isGroup && !Q_stricmp(checkGroup, group))
{ //guess so. Parse until we hit the { indicating the beginning of the group.
while (buf[i] != '{' && buf[i])
{
i++;
}
if (buf[i])
{ //We're at the start of the group now, so parse to the closing bracket.
j = 0;
parseGroups = 0;
while ((buf[i] != '}' || parseGroups) && buf[i])
{
if (buf[i] == '{')
{ //increment for the opening bracket.
parseGroups++;
}
else if (buf[i] == '}')
{ //decrement for the closing bracket
parseGroups--;
}
if (parseGroups < 0)
{ //Syntax error, I guess.
Com_Error(ERR_DROP, "Found a closing bracket without an opening bracket while looking for group '%s'", group);
}
if ((buf[i] != '{' || parseGroups > 1) &&
(buf[i] != '}' || parseGroups > 0))
{ //don't put the start and end brackets for this group into the output buffer
outbuf[j] = buf[i];
j++;
}
if (buf[i] == '}' && !parseGroups)
{ //Alright, we can break out now.
break;
}
i++;
}
outbuf[j] = 0;
//Verify that we ended up on the closing bracket.
if (buf[i] != '}')
{
Com_Error(ERR_DROP, "Group '%s' is missing a closing bracket", group);
}
//Strip the tabs so we're friendly for value parsing.
BG_SiegeStripTabs(outbuf);
return 1; //we got it, so return 1.
}
else
{
Com_Error(ERR_DROP, "Error parsing group in file, unexpected EOF before opening bracket while looking for group '%s'", group);
}
}
else if (!isGroup)
{ //if it wasn't a group, parse to the end of the line
while (buf[i] && buf[i] != '\n' && buf[i] != '\r')
{
i++;
}
}
else
{ //this was a group but we not the one we wanted to find, so parse by it.
parseGroups = 0;
while (buf[i] && (buf[i] != '}' || parseGroups))
{
if (buf[i] == '{')
{
parseGroups++;
}
else if (buf[i] == '}')
{
parseGroups--;
}
if (parseGroups < 0)
{ //Syntax error, I guess.
Com_Error(ERR_DROP, "Found a closing bracket without an opening bracket while looking for group '%s'", group);
}
if (buf[i] == '}' && !parseGroups)
{ //Alright, we can break out now.
break;
}
i++;
}
if (buf[i] != '}')
{
Com_Error(ERR_DROP, "Found an opening bracket without a matching closing bracket while looking for group '%s'", group);
}
i++;
}
}
}
else if (buf[i] == '{')
{ //we're in a group that isn't the one we want, so parse to the end.
parseGroups = 0;
while (buf[i] && (buf[i] != '}' || parseGroups))
{
if (buf[i] == '{')
{
parseGroups++;
}
else if (buf[i] == '}')
{
parseGroups--;
}
if (parseGroups < 0)
{ //Syntax error, I guess.
Com_Error(ERR_DROP, "Found a closing bracket without an opening bracket while looking for group '%s'", group);
}
if (buf[i] == '}' && !parseGroups)
{ //Alright, we can break out now.
break;
}
i++;
}
if (buf[i] != '}')
{
Com_Error(ERR_DROP, "Found an opening bracket without a matching closing bracket while looking for group '%s'", group);
}
}
if (!buf[i])
{
break;
}
i++;
}
return 0; //guess we never found it.
}
int BG_SiegeGetPairedValue(char *buf, char *key, char *outbuf)
{
int i = 0;
int j;
int k;
char checkKey[4096];
while (buf[i])
{
if (buf[i] != ' ' && buf[i] != '{' && buf[i] != '}' && buf[i] != '\n' && buf[i] != '\r')
{ //we're on a valid character
if (buf[i] == '/' &&
buf[i+1] == '/')
{ //this is a comment, so skip over it
while (buf[i] && buf[i] != '\n' && buf[i] != '\r')
{
i++;
}
}
else
{ //parse to the next space/endline/eos and check this value against our key value.
j = 0;
while (buf[i] != ' ' && buf[i] != '\n' && buf[i] != '\r' && buf[i] != SIEGECHAR_TAB && buf[i])
{
if (buf[i] == '/' && buf[i+1] == '/')
{ //hit a comment, break out.
break;
}
checkKey[j] = buf[i];
j++;
i++;
}
checkKey[j] = 0;
k = i;
while (buf[k] && (buf[k] == ' ' || buf[k] == '\n' || buf[k] == '\r'))
{
k++;
}
if (buf[k] == '{')
{ //this is not the start of a value but rather of a group. We don't want to look in subgroups so skip over the whole thing.
int openB = 0;
while (buf[i] && (buf[i] != '}' || openB))
{
if (buf[i] == '{')
{
openB++;
}
else if (buf[i] == '}')
{
openB--;
}
if (openB < 0)
{
Com_Error(ERR_DROP, "Unexpected closing bracket (too many) while parsing to end of group '%s'", checkKey);
}
if (buf[i] == '}' && !openB)
{ //this is the end of the group
break;
}
i++;
}
if (buf[i] == '}')
{
i++;
}
}
else
{
//Is this the one we want?
if (buf[i] != '/' || buf[i+1] != '/')
{ //make sure we didn't stop on a comment, if we did then this is considered an error in the file.
if (!Q_stricmp(checkKey, key))
{ //guess so. Parse along to the next valid character, then put that into the output buffer and return 1.
while ((buf[i] == ' ' || buf[i] == '\n' || buf[i] == '\r' || buf[i] == SIEGECHAR_TAB) && buf[i])
{
i++;
}
if (buf[i])
{ //We're at the start of the value now.
qboolean parseToQuote = qfalse;
if (buf[i] == '\"')
{ //if the value is in quotes, then stop at the next quote instead of ' '
i++;
parseToQuote = qtrue;
}
j = 0;
while ( ((!parseToQuote && buf[i] != ' ' && buf[i] != '\n' && buf[i] != '\r') || (parseToQuote && buf[i] != '\"')) )
{
if (buf[i] == '/' &&
buf[i+1] == '/')
{ //hit a comment after the value? This isn't an ideal way to be writing things, but we'll support it anyway.
break;
}
outbuf[j] = buf[i];
j++;
i++;
if (!buf[i])
{
if (parseToQuote)
{
Com_Error(ERR_DROP, "Unexpected EOF while looking for endquote, error finding paired value for '%s'", key);
}
else
{
Com_Error(ERR_DROP, "Unexpected EOF while looking for space or endline, error finding paired value for '%s'", key);
}
}
}
outbuf[j] = 0;
return 1; //we got it, so return 1.
}
else
{
Com_Error(ERR_DROP, "Error parsing file, unexpected EOF while looking for valud '%s'", key);
}
}
else
{ //if that wasn't the desired key, then make sure we parse to the end of the line, so we don't mistake a value for a key
while (buf[i] && buf[i] != '\n')
{
i++;
}
}
}
else
{
Com_Error(ERR_DROP, "Error parsing file, found comment, expected value for '%s'", key);
}
}
}
}
if (!buf[i])
{
break;
}
i++;
}
return 0; //guess we never found it.
}
//======================================
//End parsing functions
//======================================
//======================================
//Class loading functions
//======================================
void BG_SiegeTranslateForcePowers(char *buf, siegeClass_t *siegeClass)
{
char checkPower[1024];
char checkLevel[256];
int l = 0;
int k = 0;
int j = 0;
int i = 0;
int parsedLevel = 0;
qboolean allPowers = qfalse;
qboolean noPowers = qfalse;
if (!Q_stricmp(buf, "FP_ALL"))
{ //this is a special case, just give us all the powers on level 3
allPowers = qtrue;
}
if (buf[0] == '0' && !buf[1])
{ //no powers then
noPowers = qtrue;
}
//First clear out the powers, or in the allPowers case, give us all level 3.
while (i < NUM_FORCE_POWERS)
{
if (allPowers)
{
siegeClass->forcePowerLevels[i] = FORCE_LEVEL_3;
}
else
{
siegeClass->forcePowerLevels[i] = 0;
}
i++;
}
if (allPowers || noPowers)
{ //we're done now then.
return;
}
i = 0;
while (buf[i])
{ //parse through the list which is seperated by |, and add all the weapons into a bitflag
if (buf[i] != ' ' && buf[i] != '|')
{
j = 0;
while (buf[i] && buf[i] != ' ' && buf[i] != '|' && buf[i] != ',')
{
checkPower[j] = buf[i];
j++;
i++;
}
checkPower[j] = 0;
if (buf[i] == ',')
{ //parse the power level
i++;
l = 0;
while (buf[i] && buf[i] != ' ' && buf[i] != '|')
{
checkLevel[l] = buf[i];
l++;
i++;
}
checkLevel[l] = 0;
parsedLevel = atoi(checkLevel);
//keep sane limits on the powers
if (parsedLevel < 0)
{
parsedLevel = 0;
}
if (parsedLevel > FORCE_LEVEL_5)
{
parsedLevel = FORCE_LEVEL_5;
}
}
else
{ //if it's not there, assume level 3 I guess.
parsedLevel = 3;
}
if (checkPower[0])
{ //Got the name, compare it against the weapon table strings.
k = 0;
if (!Q_stricmp(checkPower, "FP_JUMP"))
{ //haqery
strcpy(checkPower, "FP_LEVITATION");
}
while (FPTable[k].id != -1 && FPTable[k].name[0])
{
if (!Q_stricmp(checkPower, FPTable[k].name))
{ //found it, add the weapon into the weapons value
siegeClass->forcePowerLevels[k] = parsedLevel;
break;
}
k++;
}
}
}
if (!buf[i])
{
break;
}
i++;
}
}
//Used for the majority of generic val parsing stuff. buf should be the value string,
//table should be the appropriate string/id table. If bitflag is qtrue then the
//values are accumulated into a bitflag. If bitflag is qfalse then the first value
//is returned as a directly corresponding id and no further parsing is done.
int BG_SiegeTranslateGenericTable(char *buf, stringID_table_t *table, qboolean bitflag)
{
int items = 0;
char checkItem[1024];
int i = 0;
int j = 0;
int k = 0;
if (buf[0] == '0' && !buf[1])
{ //special case, no items.
return 0;
}
while (buf[i])
{ //Using basically the same parsing method as we do for weapons and forcepowers.
if (buf[i] != ' ' && buf[i] != '|')
{
j = 0;
while (buf[i] && buf[i] != ' ' && buf[i] != '|')
{
checkItem[j] = buf[i];
j++;
i++;
}
checkItem[j] = 0;
if (checkItem[0])
{
k = 0;
while (table[k].name && table[k].name[0])
{ //go through the list and check the parsed flag name against the hardcoded names
if (!Q_stricmp(checkItem, table[k].name))
{ //Got it, so add the value into our items value.
if (bitflag)
{
items |= (1 << table[k].id);
}
else
{ //return the value directly then.
return table[k].id;
}
break;
}
k++;
}
}
}
if (!buf[i])
{
break;
}
i++;
}
return items;
}
// duo: same as above but with 64-bit support
long long BG_SiegeTranslateGenericTable64(char *buf, stringID_table_t *table, qboolean bitflag)
{
long long items = 0ll;
char checkItem[1024];
long long i = 0ll;
long long j = 0ll;
long long k = 0ll;
if (buf[0] == '0' && !buf[1])
{ //special case, no items.
return 0;
}
while (buf[i])
{ //Using basically the same parsing method as we do for weapons and forcepowers.
if (buf[i] != ' ' && buf[i] != '|')
{
j = 0ll;
while (buf[i] && buf[i] != ' ' && buf[i] != '|')
{
checkItem[j] = buf[i];
j++;
i++;
}
checkItem[j] = 0ll;
if (checkItem[0])
{
k = 0ll;
while (table[k].name && table[k].name[0])
{ //go through the list and check the parsed flag name against the hardcoded names
if (!Q_stricmp(checkItem, table[k].name))
{ //Got it, so add the value into our items value.
if (bitflag)
{
items |= (1ll << (long long)table[k].id);
}
else
{ //return the value directly then.
return (long long)table[k].id;
}
break;
}
k++;
}
}
}
if (!buf[i])
{
break;
}
i++;
}
return items;
}
char *classTitles[SPC_MAX] =
{
"infantry", // SPC_INFANTRY
"vanguard", // SPC_VANGUARD
"support", // SPC_SUPPORT
"jedi_general", // SPC_JEDI
"demolitionist", // SPC_DEMOLITIONIST
"heavy_weapons", // SPC_HEAVY_WEAPONS
};
typedef enum {
SIEGEMAP_UNKNOWN = 0,
SIEGEMAP_HOTH,
SIEGEMAP_DESERT,
SIEGEMAP_KORRIBAN,
SIEGEMAP_NAR,
SIEGEMAP_CARGO,
SIEGEMAP_URBAN,
SIEGEMAP_BESPIN,
SIEGEMAP_ANSION
} siegeMap_t;
extern siegeMap_t GetSiegeMap(void);
extern vmCvar_t g_hothRebalance;
void BG_SiegeParseClassFile(const char *filename, siegeClassDesc_t *descBuffer)
{
fileHandle_t f;
int len;
int i;
char classInfo[4096];
char parseBuf[4096];
len = trap_FS_FOpenFile(filename, &f, FS_READ);
if (!f || len >= 4096)
{
return;
}
trap_FS_Read(classInfo, len, f);
trap_FS_FCloseFile(f);
classInfo[len] = 0;
#if 0
//first get the description if we have a buffer for it
if (descBuffer)
{
if (!BG_SiegeGetPairedValue(classInfo, "description", descBuffer->desc))
{
strcpy(descBuffer->desc, "DESCRIPTION UNAVAILABLE");
}
//Hit this assert? Memory has already been trashed. Increase
//SIEGE_CLASS_DESC_LEN.
assert(strlen(descBuffer->desc) < SIEGE_CLASS_DESC_LEN);
}
#endif
siegeClass_t *scl = &bgSiegeClasses[bgNumSiegeClasses];
// duo: added to send to clients
if (BG_SiegeGetPairedValue(classInfo, "description", parseBuf));
Q_strncpyz(scl->description, parseBuf, sizeof(scl->description));
BG_SiegeGetValueGroup(classInfo, "ClassInfo", classInfo);
//Parse name
if (BG_SiegeGetPairedValue(classInfo, "name", parseBuf))
{
strcpy(scl->name, parseBuf);
}
else
{
Com_Error(ERR_DROP, "Siege class without name entry");
}
//Parse forced model
if (BG_SiegeGetPairedValue(classInfo, "model", parseBuf))
{
strcpy(scl->forcedModel, parseBuf);
}
else
{ //It's ok if there isn't one, it's optional.
scl->forcedModel[0] = 0;
}
//Parse forced skin
if (BG_SiegeGetPairedValue(classInfo, "skin", parseBuf))
{
strcpy(scl->forcedSkin, parseBuf);
}
else
{ //It's ok if there isn't one, it's optional.
// duo: set to "default" if none found
Q_strncpyz(scl->forcedSkin, "default", sizeof(scl->forcedSkin));
//bgSiegeClasses[bgNumSiegeClasses].forcedSkin[0] = 0;
}
//Parse first saber
if (BG_SiegeGetPairedValue(classInfo, "saber1", parseBuf))
{