/
bg_animation.c
2096 lines (1842 loc) · 55.4 KB
/
bg_animation.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 bg_animation.c
* @brief Incorporates several elements related to the new flexible animation
* system.
*
* This includes scripting elements, support routines for new animation set
* reference system and other bits and pieces.
*/
#include "../qcommon/q_shared.h"
#include "bg_public.h"
// JPW NERVE -- added because I need to check single/multiplayer instances and branch accordingly
#ifdef CGAMEDLL
extern vmCvar_t cg_gameType;
#endif
#ifdef GAMEDLL
extern vmCvar_t g_gametype;
#endif
// debug defines, to prevent doing costly string cvar lookups
//#define DBGANIMS
//#define DBGANIMEVENTS
// this is used globally within this file to reduce redundant params
static animScriptData_t *globalScriptData = NULL;
#define MAX_ANIM_DEFINES 16
static char *globalFilename; // to prevent redundant params
// these are used globally during script parsing
static int numDefines[NUM_ANIM_CONDITIONS];
static char defineStrings[10000]; // stores the actual strings
static int defineStringsOffset;
static animStringItem_t defineStr[NUM_ANIM_CONDITIONS][MAX_ANIM_DEFINES];
static int defineBits[NUM_ANIM_CONDITIONS][MAX_ANIM_DEFINES][2];
static scriptAnimMoveTypes_t parseMovetype;
static int parseEvent;
animStringItem_t weaponStrings[WP_NUM_WEAPONS];
animStringItem_t animStateStr[] =
{
{ "RELAXED", -1 },
{ "QUERY", -1 },
{ "ALERT", -1 },
{ "COMBAT", -1 },
{ NULL, -1 },
};
static animStringItem_t animMoveTypesStr[] =
{
{ "** UNUSED **", -1 },
{ "IDLE", -1 },
{ "IDLECR", -1 },
{ "WALK", -1 },
{ "WALKBK", -1 },
{ "WALKCR", -1 },
{ "WALKCRBK", -1 },
{ "RUN", -1 },
{ "RUNBK", -1 },
{ "SWIM", -1 },
{ "SWIMBK", -1 },
{ "STRAFERIGHT", -1 },
{ "STRAFELEFT", -1 },
{ "TURNRIGHT", -1 },
{ "TURNLEFT", -1 },
{ "CLIMBUP", -1 },
{ "CLIMBDOWN", -1 },
{ "FALLEN", -1 }, // DHM - Nerve :: dead, before limbo
{ "PRONE", -1 },
{ "PRONEBK", -1 },
{ "IDLEPRONE", -1 },
{ "FLAILING", -1 },
{ NULL, -1 },
};
static animStringItem_t animEventTypesStr[] =
{
{ "PAIN", -1 },
{ "DEATH", -1 },
{ "FIREWEAPON", -1 },
{ "FIREWEAPON2", -1 },
{ "JUMP", -1 },
{ "JUMPBK", -1 },
{ "LAND", -1 },
{ "DROPWEAPON", -1 },
{ "RAISEWEAPON", -1 },
{ "CLIMBMOUNT", -1 },
{ "CLIMBDISMOUNT", -1 },
{ "RELOAD", -1 },
{ "PICKUPGRENADE", -1 },
{ "KICKGRENADE", -1 },
{ "QUERY", -1 },
{ "INFORM_FRIENDLY_OF_ENEMY", -1 },
{ "KICK", -1 },
{ "REVIVE", -1 },
{ "FIRSTSIGHT", -1 },
{ "ROLL", -1 },
{ "FLIP", -1 },
{ "DIVE", -1 },
{ "PRONE_TO_CROUCH", -1 },
{ "BULLETIMPACT", -1 },
{ "INSPECTSOUND", -1 },
{ "SECONDLIFE", -1 },
{ "DO_ALT_WEAPON_MODE", -1 },
{ "UNDO_ALT_WEAPON_MODE", -1 },
{ "DO_ALT_WEAPON_MODE_PRONE", -1 },
{ "UNDO_ALT_WEAPON_MODE_PRONE", -1 },
{ "FIREWEAPONPRONE", -1 },
{ "FIREWEAPON2PRONE", -1 },
{ "RAISEWEAPONPRONE", -1 },
{ "RELOADPRONE", -1 },
{ "TALK", -1 },
{ "NOPOWER", -1 },
{ NULL, -1 },
};
animStringItem_t animBodyPartsStr[] =
{
{ "** UNUSED **", -1 },
{ "LEGS", -1 },
{ "TORSO", -1 },
{ "BOTH", -1 },
{ NULL, -1 },
};
//------------------------------------------------------------
// conditions
static animStringItem_t animConditionPositionsStr[] =
{
{ "** UNUSED **", -1 },
{ "BEHIND", -1 },
{ "INFRONT", -1 },
{ "RIGHT", -1 },
{ "LEFT", -1 },
{ NULL, -1 },
};
static animStringItem_t animConditionMountedStr[] =
{
{ "** UNUSED **", -1 },
{ "MG42", -1 },
{ NULL, -1 },
};
static animStringItem_t animConditionLeaningStr[] =
{
{ "** UNUSED **", -1 },
{ "RIGHT", -1 },
{ "LEFT", -1 },
{ NULL, -1 },
};
// !!! NOTE: this must be kept in sync with the tag names in ai_cast_characters.c
static animStringItem_t animConditionImpactPointsStr[] =
{
{ "** UNUSED **", -1 },
{ "HEAD", -1 },
{ "CHEST", -1 },
{ "GUT", -1 },
{ "GROIN", -1 },
{ "SHOULDER_RIGHT", -1 },
{ "SHOULDER_LEFT", -1 },
{ "KNEE_RIGHT", -1 },
{ "KNEE_LEFT", -1 },
{ NULL, -1 },
};
// !!! NOTE: this must be kept in sync with the teams in ai_cast.h
static animStringItem_t animEnemyTeamsStr[] =
{
{ "NAZI", -1 },
{ "ALLIES", -1 },
{ "MONSTER", -1 },
{ "SPARE1", -1 },
{ "SPARE2", -1 },
{ "SPARE3", -1 },
{ "SPARE4", -1 },
{ "NEUTRAL", -1 }
};
static animStringItem_t animHealthLevelStr[] =
{
{ "1", -1 },
{ "2", -1 },
{ "3", -1 },
};
static animStringItem_t animFlailTypeStr[] =
{
{ "** UNUSED **", -1 },
{ "INAIR", -1 },
{ "VCRASH", -1 },
{ "HCRASH", -1 },
{ NULL, -1 },
};
static animStringItem_t animGenBitFlagStr[] =
{
/* {"SNEAKING", -1}, // in a cover spot
{"AFTERBATTLE", -1}, // just finished battle
{"AGENT2", -1}, // agent2 only
{"RELAXED", -1}, // relaxed aiState*/
{ "ZOOMING", -1 }, // zooming with binoculars
};
// xkan, 1/17/2003 - sorts of duplicate aistateEnum_t.
static animStringItem_t animAIStateStr[] =
{
{ "RELAXED", -1 },
{ "QUERY", -1 },
{ "ALERT", -1 },
{ "COMBAT", -1 }
};
typedef enum
{
ANIM_CONDTYPE_BITFLAGS,
ANIM_CONDTYPE_VALUE,
NUM_ANIM_CONDTYPES
} animScriptConditionTypes_t;
typedef struct
{
animScriptConditionTypes_t type;
animStringItem_t *values;
} animConditionTable_t;
static animStringItem_t animConditionsStr[] =
{
{ "WEAPONS", -1 },
{ "ENEMY_POSITION", -1 },
{ "ENEMY_WEAPON", -1 },
{ "UNDERWATER", -1 },
{ "MOUNTED", -1 },
{ "MOVETYPE", -1 },
{ "UNDERHAND", -1 },
{ "LEANING", -1 },
{ "IMPACT_POINT", -1 },
{ "CROUCHING", -1 },
{ "STUNNED", -1 },
{ "FIRING", -1 },
{ "SHORT_REACTION", -1 },
{ "ENEMY_TEAM", -1 },
{ "PARACHUTE", -1 },
{ "CHARGING", -1 },
{ "SECONDLIFE", -1 },
{ "HEALTH_LEVEL", -1 },
{ "FLAILING_TYPE", -1 },
{ "GEN_BITFLAG", -1 },
{ "AISTATE", -1 },
{ NULL, -1 },
};
static animConditionTable_t animConditionsTable[NUM_ANIM_CONDITIONS] =
{
{ ANIM_CONDTYPE_BITFLAGS, weaponStrings },
{ ANIM_CONDTYPE_BITFLAGS, animConditionPositionsStr },
{ ANIM_CONDTYPE_BITFLAGS, weaponStrings },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, animConditionMountedStr },
{ ANIM_CONDTYPE_BITFLAGS, animMoveTypesStr },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, animConditionLeaningStr },
{ ANIM_CONDTYPE_VALUE, animConditionImpactPointsStr },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, animEnemyTeamsStr },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, NULL },
{ ANIM_CONDTYPE_VALUE, animHealthLevelStr },
{ ANIM_CONDTYPE_VALUE, animFlailTypeStr },
{ ANIM_CONDTYPE_BITFLAGS, animGenBitFlagStr },
{ ANIM_CONDTYPE_VALUE, animAIStateStr },
};
//------------------------------------------------------------
/*
================
return a hash value for the given string
================
*/
long BG_StringHashValue(const char *fname)
{
int i;
long hash;
if (!fname)
{
return -1;
}
hash = 0;
i = 0;
while (fname[i] != '\0')
{
if (Q_isupper(fname[i]))
{
hash += (long)(fname[i] + ('a' - 'A')) * (i + 119);
}
else
{
hash += (long)(fname[i]) * (i + 119);
}
i++;
}
if (hash == -1)
{
hash = 0; // never return -1
}
return hash;
}
/*
================
return a hash value for the given string (make sure the strings and lowered first)
================
*/
long BG_StringHashValue_Lwr(const char *fname)
{
int i;
long hash;
hash = 0;
i = 0;
while (fname[i] != '\0')
{
hash += (long)(fname[i]) * (i + 119);
i++;
}
if (hash == -1)
{
hash = 0; // never return -1
}
return hash;
}
/*
=================
BG_AnimParseError
=================
*/
void QDECL BG_AnimParseError(const char *msg, ...)
{
va_list argptr;
char text[1024];
va_start(argptr, msg);
Q_vsnprintf(text, sizeof(text), msg, argptr);
va_end(argptr);
if (globalFilename)
{
Com_Error(ERR_DROP, "%s: (%s, line %i)", text, globalFilename, COM_GetCurrentParseLine() + 1);
}
else
{
Com_Error(ERR_DROP, "%s", text);
}
}
/*
=================
BG_ModelInfoForClient
=================
*/
/*animModelInfo_t *BG_ModelInfoForClient( int client ) {
if (!globalScriptData)
BG_AnimParseError( "BG_ModelInfoForClient: NULL globalScriptData" );
//
if (!globalScriptData->clientModels[client])
BG_AnimParseError( "BG_ModelInfoForClient: client %i has no modelinfo", client );
//
return &globalScriptData->modelInfo[globalScriptData->clientModels[client] - 1];
}*/
/*
=================
BG_ModelInfoForModelname
=================
*/
/*animModelInfo_t *BG_ModelInfoForModelname( char *modelname ) {
int i;
animModelInfo_t *modelInfo;
//
if (!globalScriptData)
BG_AnimParseError( "BG_ModelInfoForModelname: NULL globalScriptData" );
//
for (i=0, modelInfo=globalScriptData->modelInfo; i<MAX_ANIMSCRIPT_MODELS; i++, modelInfo++) {
if (!modelInfo->modelname[0])
continue;
if (!Q_stricmp( modelname, modelInfo->modelname )) {
return modelInfo;
}
}
//
return NULL;
}*/
/*
=================
BG_AnimationIndexForString
=================
*/
static int BG_AnimationIndexForString(char *string, animModelInfo_t *animModelInfo)
{
int i, hash;
animation_t *anim;
hash = BG_StringHashValue(string);
for (i = 0; i < animModelInfo->numAnimations; i++)
{
anim = animModelInfo->animations[i];
if ((hash == anim->nameHash) && !Q_stricmp(string, anim->name))
{
// found a match
return i;
}
}
// no match found
BG_AnimParseError("BG_AnimationIndexForString: unknown index '%s' for animation group '%s'", string, animModelInfo->animationGroup);
return -1; // shutup compiler
}
/*
=================
BG_AnimationForString
=================
*/
animation_t *BG_AnimationForString(char *string, animModelInfo_t *animModelInfo)
{
int i, hash;
animation_t *anim;
hash = BG_StringHashValue(string);
for (i = 0; i < animModelInfo->numAnimations; i++)
{
anim = animModelInfo->animations[i];
if ((hash == anim->nameHash) && !Q_stricmp(string, anim->name))
{
// found a match
return anim;
}
}
// no match found
Com_Error(ERR_DROP, "BG_AnimationForString: unknown animation '%s' for animation group '%s'", string, animModelInfo->animationGroup);
return NULL; // shutup compiler
}
/*
=================
BG_IndexForString
errors out if no match found
=================
*/
int BG_IndexForString(char *token, animStringItem_t *strings, qboolean allowFail)
{
int i, hash;
animStringItem_t *strav;
hash = BG_StringHashValue(token);
for (i = 0, strav = strings; strav->string; strav++, i++)
{
if (strav->hash == -1)
{
strav->hash = BG_StringHashValue(strav->string);
}
if ((hash == strav->hash) && !Q_stricmp(token, strav->string))
{
// found a match
return i;
}
}
// no match found
if (!allowFail)
{
BG_AnimParseError("BG_IndexForString: unknown token '%s'", token);
}
//
return -1;
}
/*
===============
BG_CopyStringIntoBuffer
===============
*/
char *BG_CopyStringIntoBuffer(char *string, char *buffer,
unsigned int bufSize, unsigned int *offset)
{
char *pch;
// check for overloaded buffer
if (*offset + strlen(string) + 1 >= bufSize)
{
BG_AnimParseError("BG_CopyStringIntoBuffer: out of buffer space");
}
pch = &buffer[*offset];
// safe to do a strcpy since we've already checked for overrun
strcpy(pch, string);
// move the offset along
*offset += strlen(string) + 1;
return pch;
}
/*
============
BG_InitWeaponStrings
Builds the list of weapon names from the item list. This is done here rather
than hardcoded to ease the process of modifying the weapons.
============
*/
void BG_InitWeaponStrings(void)
{
int i;
gitem_t *item;
memset(weaponStrings, 0, sizeof(weaponStrings));
for (i = 0; i < WP_NUM_WEAPONS; i++)
{
// find this weapon in the itemslist, and extract the name
for (item = bg_itemlist + 1; item->classname; item++)
{
if (item->giType == IT_WEAPON && item->giTag == i)
{
// found a match
weaponStrings[i].string = item->pickup_name;
weaponStrings[i].hash = BG_StringHashValue(weaponStrings[i].string);
break;
}
}
if (!item->classname)
{
weaponStrings[i].string = "(unknown)";
weaponStrings[i].hash = BG_StringHashValue(weaponStrings[i].string);
}
}
}
/*
=================
BG_ParseConditionBits
convert the string into a single int containing bit flags, stopping at a ',' or end of line
=================
*/
void BG_ParseConditionBits(char **text_pp, animStringItem_t *stringTable, int condIndex, int result[2])
{
qboolean endFlag = qfalse;
int indexFound;
int /*indexBits,*/ tempBits[2];
char currentString[MAX_QPATH];
qboolean minus = qfalse;
char *token;
//indexBits = 0;
currentString[0] = '\0';
memset(result, 0, sizeof(result));
memset(tempBits, 0, sizeof(tempBits));
while (!endFlag)
{
token = COM_ParseExt(text_pp, qfalse);
if (!token || !token[0])
{
COM_RestoreParseSession(text_pp); // go back to the previous token
endFlag = qtrue; // done parsing indexes
if (!strlen(currentString))
{
break;
}
}
if (!Q_stricmp(token, ","))
{
endFlag = qtrue; // end of indexes
}
if (!Q_stricmp(token, "none")) // first bit is always the "unused" bit
{
COM_BitSet(result, 0);
continue;
}
if (!Q_stricmp(token, "none,")) // first bit is always the "unused" bit
{
COM_BitSet(result, 0);
endFlag = qtrue; // end of indexes
continue;
}
if (!Q_stricmp(token, "NOT"))
{
token = "MINUS"; // NOT is equivalent to MINUS
}
if (!endFlag && Q_stricmp(token, "AND") && Q_stricmp(token, "MINUS")) // must be a index
{ // check for a comma (end of indexes)
if (token[strlen(token) - 1] == ',')
{
endFlag = qtrue;
token[strlen(token) - 1] = '\0';
}
// append this to the currentString
if (strlen(currentString))
{
Q_strcat(currentString, sizeof(currentString), " ");
}
Q_strcat(currentString, sizeof(currentString), token);
}
if (!Q_stricmp(token, "AND") || !Q_stricmp(token, "MINUS") || endFlag)
{
// process the currentString
if (!strlen(currentString))
{
if (endFlag)
{
BG_AnimParseError("BG_AnimParseAnimScript: unexpected end of condition");
}
else
{
// check for minus indexes to follow
if (!Q_stricmp(token, "MINUS"))
{
minus = qtrue;
continue;
}
BG_AnimParseError("BG_AnimParseAnimScript: unexpected '%s'", token);
}
}
if (!Q_stricmp(currentString, "all"))
{
tempBits[0] = ~0x0;
tempBits[1] = ~0x0;
}
else
{
// first check this string with our defines
indexFound = BG_IndexForString(currentString, defineStr[condIndex], qtrue);
if (indexFound >= 0)
{
// we have precalculated the bitflags for the defines
tempBits[0] = defineBits[condIndex][indexFound][0];
tempBits[1] = defineBits[condIndex][indexFound][1];
}
else
{
// convert the string into an index
indexFound = BG_IndexForString(currentString, stringTable, qfalse);
// convert the index into a bitflag
COM_BitSet(tempBits, indexFound);
}
}
// perform operation
if (minus) // subtract
{
result[0] &= ~tempBits[0];
result[1] &= ~tempBits[1];
}
else // add
{
result[0] |= tempBits[0];
result[1] |= tempBits[1];
}
// clear the currentString
currentString[0] = '\0';
// check for minus indexes to follow
if (!Q_stricmp(token, "MINUS"))
{
minus = qtrue;
}
}
}
}
/*
=================
BG_ParseConditions
returns qtrue if everything went ok, error drops otherwise
=================
*/
qboolean BG_ParseConditions(char **text_pp, animScriptItem_t *scriptItem)
{
int conditionIndex, conditionValue[2];
char *token;
conditionValue[0] = 0;
conditionValue[1] = 0;
while (1)
{
token = COM_ParseExt(text_pp, qfalse);
if (!token || !token[0])
{
break;
}
// special case, "default" has no conditions
if (!Q_stricmp(token, "default"))
{
return qtrue;
}
conditionIndex = BG_IndexForString(token, animConditionsStr, qfalse);
switch (animConditionsTable[conditionIndex].type)
{
case ANIM_CONDTYPE_BITFLAGS:
BG_ParseConditionBits(text_pp, animConditionsTable[conditionIndex].values, conditionIndex, conditionValue);
break;
case ANIM_CONDTYPE_VALUE:
if (animConditionsTable[conditionIndex].values)
{
token = COM_ParseExt(text_pp, qfalse);
if (!token || !token[0])
{
BG_AnimParseError("BG_AnimParseAnimScript: expected condition value, found end of line"); // RF modification
}
// check for a comma (condition divider)
if (token[strlen(token) - 1] == ',')
{
token[strlen(token) - 1] = '\0';
}
conditionValue[0] = BG_IndexForString(token, animConditionsTable[conditionIndex].values, qfalse);
}
else
{
conditionValue[0] = 1; // not used, just check for a positive condition
}
break;
default: // TTimo gcc: NUM_ANIM_CONDTYPES not handled in switch
break;
}
// now append this condition to the item
scriptItem->conditions[scriptItem->numConditions].index = conditionIndex;
scriptItem->conditions[scriptItem->numConditions].value[0] = conditionValue[0];
scriptItem->conditions[scriptItem->numConditions].value[1] = conditionValue[1];
scriptItem->numConditions++;
}
if (scriptItem->numConditions == 0)
{
BG_AnimParseError("BG_ParseConditions: no conditions found"); // RF mod
}
return qtrue;
}
/*
=================
BG_ParseCommands
=================
*/
static void BG_ParseCommands(char **input, animScriptItem_t *scriptItem, animModelInfo_t *animModelInfo, animScriptData_t *scriptData)
{
char *token;
// TTimo gcc: might be used uninitialized
animScriptCommand_t *command = NULL;
int partIndex = 0;
while (1)
{
// parse the body part
token = COM_ParseExt(input, (partIndex < 1));
if (!token || !*token)
{
break;
}
if (!Q_stricmp(token, "}"))
{
// unget the bracket and get out of here
*input -= strlen(token);
break;
}
// new command?
if (partIndex == 0)
{
// have we exceeded the maximum number of commands?
if (scriptItem->numCommands >= MAX_ANIMSCRIPT_ANIMCOMMANDS)
{
BG_AnimParseError("BG_ParseCommands: exceeded maximum number of animations (%i)", MAX_ANIMSCRIPT_ANIMCOMMANDS);
}
command = &scriptItem->commands[scriptItem->numCommands++];
memset(command, 0, sizeof(command));
}
command->bodyPart[partIndex] = BG_IndexForString(token, animBodyPartsStr, qtrue);
if (command->bodyPart[partIndex] > 0)
{
// parse the animation
token = COM_ParseExt(input, qfalse);
if (!token || !token[0])
{
BG_AnimParseError("BG_ParseCommands: expected animation");
}
command->animIndex[partIndex] = BG_AnimationIndexForString(token, animModelInfo);
command->animDuration[partIndex] = animModelInfo->animations[command->animIndex[partIndex]]->duration;
// if this is a locomotion, set the movetype of the animation so we can reverse engineer the movetype from the animation, on the client
if (parseMovetype != ANIM_MT_UNUSED && command->bodyPart[partIndex] != ANIM_BP_TORSO)
{
animModelInfo->animations[command->animIndex[partIndex]]->movetype |= (1 << parseMovetype);
}
// if this is a fireweapon event, then this is a firing animation
if (parseEvent == ANIM_ET_FIREWEAPON || parseEvent == ANIM_ET_FIREWEAPONPRONE)
{
animModelInfo->animations[command->animIndex[partIndex]]->flags |= ANIMFL_FIRINGANIM;
animModelInfo->animations[command->animIndex[partIndex]]->initialLerp = 40;
}
// check for a duration for this animation instance
token = COM_ParseExt(input, qfalse);
if (token && token[0])
{
if (!Q_stricmp(token, "duration"))
{
// read the duration
token = COM_ParseExt(input, qfalse);
if (!token || !token[0])
{
BG_AnimParseError("BG_ParseCommands: expected duration value");
}
command->animDuration[partIndex] = atoi(token);
}
else // unget the token
{
COM_RestoreParseSession(input);
}
}
else
{
COM_RestoreParseSession(input);
}
if (command->bodyPart[partIndex] != ANIM_BP_BOTH && partIndex++ < 1)
{
continue; // allow parsing of another bodypart
}
}
else
{
// unget the token
*input -= strlen(token);
}
// parse optional parameters (sounds, etc)
while (1)
{
token = COM_ParseExt(input, qfalse);
if (!token || !token[0])
{
break;
}
if (!Q_stricmp(token, "sound"))
{
token = COM_ParseExt(input, qfalse);
if (!token || !token[0])
{
BG_AnimParseError("BG_ParseCommands: expected sound");
}
// NOTE: only sound script are supported at this stage
if (strstr(token, ".wav"))
{
BG_AnimParseError("BG_ParseCommands: wav files not supported, only sound scripts"); // RF mod
}
// ydnar: this was crashing because soundIndex wasn't initialized
// FIXME: find the reason
// Gordon: hmmm, soundindex is setup on both client and server :/
// cgs.animScriptData.soundIndex = CG_SoundScriptPrecache;
// level.animScriptData.soundIndex = G_SoundIndex;
command->soundIndex = globalScriptData->soundIndex != NULL ? globalScriptData->soundIndex(token) : 0;
}
else
{
// unknown??
BG_AnimParseError("BG_ParseCommands: unknown parameter '%s'", token);
}
}
partIndex = 0;
}
}
/*
=================
BG_AnimParseAnimScript
Parse the animation script for this model, converting it into run-time structures
=================
*/
typedef enum
{
PARSEMODE_DEFINES,
PARSEMODE_ANIMATION,
PARSEMODE_CANNED_ANIMATIONS,
PARSEMODE_STATECHANGES,
PARSEMODE_EVENTS
} animScriptParseMode_t;
static animStringItem_t animParseModesStr[] =
{
{ "defines", -1 },
{ "animations", -1 },
{ "canned_animations", -1 },
{ "statechanges", -1 },
{ "events", -1 },
{ NULL, -1 },
};
void BG_AnimParseAnimScript(animModelInfo_t *animModelInfo, animScriptData_t *scriptData, const char *filename, char *input)
{
#define MAX_INDENT_LEVELS 3
// FIXME: change this to use the botlib parser
char *text_p, *token;
animScriptParseMode_t parseMode;
animScript_t *currentScript;
animScriptItem_t tempScriptItem;
// TTimo gcc: might be used unitialized
animScriptItem_t *currentScriptItem = NULL;
int indexes[MAX_INDENT_LEVELS], indentLevel, /*oldState,*/ newParseMode;
int i, defineType;
// the scriptData passed into here must be the one this binary is using
globalScriptData = scriptData;
// start at the defines
parseMode = PARSEMODE_DEFINES;