-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.cpp
860 lines (698 loc) · 21.6 KB
/
script.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
// Filename:- script.cpp
//
// file to control model-loading scripts (scripts are purely a viewer convenience for multiple-bolt stuff)
//
#include "stdafx.h"
#include "includes.h"
#include "ModViewTreeView.h"
#include "glm_code.h"
#include "R_Model.h"
#include "R_Surface.h"
#include "textures.h"
#include "TEXT.H"
#include "sequence.h"
#include "model.h"
#include "GenericParser2.h"
//
#include "script.h"
CGenericParser2 theParser;
LPCSTR Script_GetExtension(void)
{
return sSCRIPT_EXTENSION;
}
LPCSTR Script_GetFilter(bool bStandAlone /* = true */)
{
static char sFilterString[1024];
strcpy(sFilterString, "ModView script files (*" sSCRIPT_EXTENSION ")|*" sSCRIPT_EXTENSION "|");
strcat(sFilterString,bStandAlone?"|":"");
return sFilterString;
}
/*
bool CString_ExtractLine(CString &strSrc, CString &strDst)
{
int iLoc = strSrc.Find("\n");
if (iLoc!= -1)
{
strDst = strSrc.Left(iLoc);
strSrc = strSrc.Mid(iLoc+1);
}
return (iLoc!=-1);
}
bool CString_ExtractUntil(CString &strSrc, CString &strDst, char cSeperator)
{
int iLoc = strSrc.Find(cSeperator);
if (iLoc!= -1)
{
strDst = strSrc.Left(iLoc);
strSrc = strSrc.Mid(iLoc+1);
}
return (iLoc!=-1);
}
*/
typedef map<ModelContainer_t*, string> HandleXref_t;
HandleXref_t HandleXRefs;
static CString strHandlesSoFar; // semicolon-delineated string of all handle names, for quick ifdef check
static void Script_Clear()
{
HandleXRefs.clear();
strHandlesSoFar = ';'; // initial state = ';' so all finds can check ";<name;"
}
// generates a unique handlename based on the input suggestion...
//
static LPCSTR GenerateHandleName(LPCSTR psIdealBaseName)
{
static CString strReturn;
int iAlternative = 0;
do
{
strReturn = psIdealBaseName;
strReturn.MakeLower();
if (iAlternative++)
strReturn += va("_%d",iAlternative);
}
while (strHandlesSoFar.Find(va(";%s;",(LPCSTR) strReturn)) != -1); // note ';' at both ends of find() arg
strHandlesSoFar += strReturn;
strHandlesSoFar += ";"; // doesn't really matter what this is, as long as each name gets seperated
return (LPCSTR) strReturn;
}
static void R_ModelContainer_WriteOptional(ModelContainer_t* pContainer, void *pvData, bool bIsBolt )
{
FILE *fhText = (FILE *) pvData;
if (Model_GetG2SurfaceRootOverride(pContainer) != -1)
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\"%s\"\n",sSCRIPTKEYWORD_SURFACENAME_ROOTOVERRIDE, Model_GetSurfaceName(pContainer->hModel, Model_GetG2SurfaceRootOverride(pContainer->hModel)));
}
// name of secondary anim start bone MUST be written out before iSequenceLockNumber_Secondary, or reading won't work...
//
if (Model_SecondaryAnimLockingActive(pContainer))
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\"%s\"\n",sSCRIPTKEYWORD_BONENAME_SECONDARYSTART, Model_GetBoneName(pContainer->hModel, Model_GetSecondaryAnimStart(pContainer->hModel)));
}
if (pContainer->iSequenceLockNumber_Primary != -1)
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\"%s\"\n",sSCRIPTKEYWORD_LOCKSEQUENCE, Model_Sequence_GetName(pContainer->hModel, pContainer->iSequenceLockNumber_Primary));
}
if (pContainer->iSequenceLockNumber_Secondary != -1)
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\"%s\"\n",sSCRIPTKEYWORD_LOCKSEQUENCE_SECONDARY, Model_Sequence_GetName(pContainer->hModel, pContainer->iSequenceLockNumber_Secondary));
}
if (pContainer->bSeqMultiLock_Primary_Active)
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\"%s\"\n",sSCRIPTKEYWORD_MULTISEQ_PRIMARYLOCK, sANY_NONBLANK_STRING);
}
if (pContainer->bSeqMultiLock_Secondary_Active)
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\"%s\"\n",sSCRIPTKEYWORD_MULTISEQ_SECONDARYLOCK, sANY_NONBLANK_STRING);
}
// group...
if (pContainer->SeqMultiLock_Primary.size())
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\n",sSCRIPTKEYWORD_MULTISEQ_PRIMARYLIST);
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "{\n");
for (int i=0; i<pContainer->SeqMultiLock_Primary.size(); i++)
{
LPCSTR psSeqName = Model_Sequence_GetName(pContainer, pContainer->SeqMultiLock_Primary[i]);
if (psSeqName)
{
fprintf(fhText, bIsBolt?"\t\t\t":"\t\t");
fprintf(fhText, "name%d\t\"%s\"\n",i,psSeqName);
}
}
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "}\n");
}
// group...
if (pContainer->SeqMultiLock_Secondary.size())
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\n",sSCRIPTKEYWORD_MULTISEQ_SECONDARYLIST);
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "{\n");
for (int i=0; i<pContainer->SeqMultiLock_Secondary.size(); i++)
{
LPCSTR psSeqName = Model_Sequence_GetName(pContainer, pContainer->SeqMultiLock_Secondary[i]);
if (psSeqName)
{
fprintf(fhText, bIsBolt?"\t\t\t":"\t\t");
fprintf(fhText, "name%d\t\"%s\"\n",i,psSeqName);
}
}
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "}\n");
}
if (pContainer->SkinSets.size())
{
if (!pContainer->strCurrentSkinFile.empty() && !pContainer->strCurrentSkinEthnic.empty())
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\"%s\"\n",sSCRIPTKEYWORD_SKINFILE, pContainer->strCurrentSkinFile.c_str());
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\t\"%s\"\n",sSCRIPTKEYWORD_ETHNIC, pContainer->strCurrentSkinEthnic.c_str());
}
}
if (pContainer->OldSkinSets.size())
{
if (!pContainer->strCurrentSkinFile.empty())
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\t\"%s\"\n",sSCRIPTKEYWORD_OLDSKINFILE, pContainer->strCurrentSkinFile.c_str());
}
}
// write out all surfaces that are ON that weren't defaulted to ON (ie user-changed)...
//
int
iNumSurfaces = Model_GetNumSurfacesDifferentFromDefault(pContainer,SURF_ON);
if (iNumSurfaces)
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\n",sSCRIPTKEYWORD_SURFACES_ON);
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "{\n");
for (int i=0; i<iNumSurfaces; i++)
{
LPCSTR psSurfaceName = Model_GetSurfaceDifferentFromDefault(pContainer,SURF_ON,i);
if (psSurfaceName)
{
fprintf(fhText, bIsBolt?"\t\t\t":"\t\t");
fprintf(fhText, "name%d\t\"%s\"\n",i,psSurfaceName );
}
}
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "}\n");
}
// write out all surfaces that are OFF that weren't defaulted to OFF (ie user-changed)...
//
iNumSurfaces = Model_GetNumSurfacesDifferentFromDefault(pContainer,SURF_OFF);
if (iNumSurfaces)
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\n",sSCRIPTKEYWORD_SURFACES_OFF);
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "{\n");
for (int i=0; i<iNumSurfaces; i++)
{
LPCSTR psSurfaceName = Model_GetSurfaceDifferentFromDefault(pContainer,SURF_OFF,i);
if (psSurfaceName)
{
fprintf(fhText, bIsBolt?"\t\t\t":"\t\t");
fprintf(fhText, "name%d\t\"%s\"\n",i, psSurfaceName);
}
}
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "}\n");
}
// write out all surfaces that are OFF+NOCHILDREN (ie user-changed)...
//
iNumSurfaces = Model_GetNumSurfacesDifferentFromDefault(pContainer,SURF_NO_DESCENDANTS);
if (iNumSurfaces)
{
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "%s\n",sSCRIPTKEYWORD_SURFACES_OFFNOCHILDREN);
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "{\n");
for (int i=0; i<iNumSurfaces; i++)
{
LPCSTR psSurfaceName = Model_GetSurfaceDifferentFromDefault(pContainer,SURF_NO_DESCENDANTS,i);
if (psSurfaceName)
{
fprintf(fhText, bIsBolt?"\t\t\t":"\t\t");
fprintf(fhText, "name%d\t\"%s\"\n",i, psSurfaceName);
}
}
fprintf(fhText, bIsBolt?"\t\t":"\t");
fprintf(fhText, "}\n");
}
}
static void R_ModelContainer_CallBack_WriteBolts(ModelContainer_t* pContainer, void *pvData )
{
FILE *fhText = (FILE *) pvData;
CString strHandleName = GenerateHandleName(Filename_WithoutPath(Filename_WithoutExt(pContainer->sLocalPathName)));
HandleXRefs[ pContainer ] = strHandleName;
// main model or bolton?
if (pContainer->pBoneBolt_ParentContainer == NULL && pContainer->pSurfaceBolt_ParentContainer == NULL)
{
// parent...
//
/* eg:
name "mainwpn"
modelfile "models/weapons/m4/m4.glm"
*/
fprintf(fhText, "\t%s\t\t\"%s\"\n",sSCRIPTKEYWORD_NAME, (LPCSTR) strHandleName);
fprintf(fhText, "\t%s\t\"%s\"\n",sSCRIPTKEYWORD_MODELFILE, (LPCSTR) pContainer->sLocalPathName);
R_ModelContainer_WriteOptional(pContainer, pvData, false );
}
else
{
// bolton...(surface or bone)
//
/* eg:
boltmodel
{
name "ar buffer"
modelfile "models/test/m4/buffer/buffer.glm"
parent "mainwpn"
bolttobone "gun"
locksequence "right_hand_idle"
}
*/
fprintf(fhText, "\t%s\n",sSCRIPTKEYWORD_BOLTMODEL);
fprintf(fhText, "\t{\n");
fprintf(fhText, "\t\t%s\t\"%s\"\n",sSCRIPTKEYWORD_NAME, (LPCSTR) strHandleName);
fprintf(fhText, "\t\t%s\t\"%s\"\n",sSCRIPTKEYWORD_MODELFILE, (LPCSTR) pContainer->sLocalPathName);
//
// we're bolted to either a bone or a surface (never both), so...
//
if (pContainer->pBoneBolt_ParentContainer)
{
fprintf(fhText, "\t\t%s\t\"%s\"\n",sSCRIPTKEYWORD_PARENT, HandleXRefs[pContainer->pBoneBolt_ParentContainer].c_str());
fprintf(fhText, "\t\t%s\t\"%s\"\n",sSCRIPTKEYWORD_BOLTTOBONE, Model_GetBoltName(pContainer->pBoneBolt_ParentContainer,pContainer->iBoneBolt_ParentBoltIndex, true)); // bBoltIsBone
}
else
{
fprintf(fhText, "\t\t%s\t\"%s\"\n",sSCRIPTKEYWORD_PARENT, HandleXRefs[pContainer->pSurfaceBolt_ParentContainer].c_str());
fprintf(fhText, "\t\t%s\t\"%s\"\n",sSCRIPTKEYWORD_BOLTTOSURFACE, Model_GetBoltName(pContainer->pSurfaceBolt_ParentContainer,pContainer->iSurfaceBolt_ParentBoltIndex, false)); // bBoltIsBone
}
R_ModelContainer_WriteOptional(pContainer, pvData, true );
fprintf(fhText, "\t}\n");
}
fprintf(fhText,"\n");
}
bool Script_Write(LPCSTR psFullPathedFilename)
{
FILE *fhText = NULL;
if (Model_Loaded())
{
Script_Clear();
fhText = fopen(psFullPathedFilename,"wt");
if (fhText)
{
fprintf(fhText,va("%s\n{\n",sSCRIPTKEYWORD_LOADMODEL));
R_ModelContainer_Apply(&AppVars.Container, R_ModelContainer_CallBack_WriteBolts, fhText);
fprintf(fhText,"}\n");
fprintf(fhText,"\n"); // cosmetic
fclose(fhText);
}
// DT EDIT
/*
else
{
ErrorBox( va("Couldn't open file: %s\n", psFullPathedFilename));
return false;
}
*/
}
return !!fhText;
}
// search for certain optional arguments for the model that's just been loaded (whether bolt or primary)..
//
// return = errmess, else NULL for ok
//
static LPCSTR Script_Parse_ReadOptionalArgs(ModelContainer_t *pContainer, CGPGroup *pParseGroup)
{
LPCSTR psError = NULL;
// I know this code has loads of spurious string constructors, but I don't care. It's nice and readable,
// and adds no user-noticeable overhead to file reading...
//
do
{
string strSurfaceName = pParseGroup->FindPairValue(sSCRIPTKEYWORD_SURFACENAME_ROOTOVERRIDE, "");
if (strSurfaceName.length())
{
if (!Model_SetG2SurfaceRootOverride (pContainer, strSurfaceName.c_str()))
{
psError = va("Failed to set model root-surface override \"%s\"",strSurfaceName.c_str());
}
}
// name of secondary anim start bone MUST be written out before iSequenceLockNumber_Secondary, or reading won't work...
//
string strBoneName = pParseGroup->FindPairValue(sSCRIPTKEYWORD_BONENAME_SECONDARYSTART, "");
if (strBoneName.length())
{
if (!Model_SetSecondaryAnimStart(pContainer->hModel, strBoneName.c_str()))
{
psError = va("Failed to set secondary anim start bone \"%s\"",strBoneName.c_str());
break;
}
}
// "locksequence"...?
//
string strSequence = pParseGroup->FindPairValue(sSCRIPTKEYWORD_LOCKSEQUENCE, "");
if (strSequence.length())
{
if (!Model_Sequence_Lock(pContainer->hModel,strSequence.c_str(),true)) // errors displayed internally
{
psError = "Failed to lock primary sequence";
break;
}
}
// "locksequence_secondary"...?
//
strSequence = pParseGroup->FindPairValue(sSCRIPTKEYWORD_LOCKSEQUENCE_SECONDARY, "");
if (strSequence.length())
{
if (!Model_Sequence_Lock(pContainer->hModel,strSequence.c_str(),false)) // errors displayed internally
{
psError = "Failed to lock secondary sequence";
break;
}
}
// "skinfile"...?
//
string strSkinFile = pParseGroup->FindPairValue(sSCRIPTKEYWORD_SKINFILE, "");
if (strSkinFile.length())
{
string strEthnic = pParseGroup->FindPairValue(sSCRIPTKEYWORD_ETHNIC, "");
if (strEthnic.length())
{
if (!Skins_ApplyEthnic( pContainer, strSkinFile.c_str(), strEthnic.c_str(),false/*findmeste true*/,true))
{
psError = va("Failed to apply ethnic \"%s\" of skin \"%s\"",strSkinFile.c_str(), strEthnic.c_str());
break;
}
}
}
// "oldskinfile"...?
//
string strOldSkinFile = pParseGroup->FindPairValue(sSCRIPTKEYWORD_OLDSKINFILE, "");
if (strOldSkinFile.length())
{
if (!OldSkins_Apply( pContainer, strOldSkinFile.c_str() ))
{
psError = va("Failed to apply skin \"%s\"",strOldSkinFile.c_str());
break;
}
}
// multisequence primary and secondary locking...
//
string
strLock = pParseGroup->FindPairValue(sSCRIPTKEYWORD_MULTISEQ_PRIMARYLOCK, "");
if (strLock.length())
{
Model_MultiSeq_SetActive(pContainer->hModel, true, true);
}
strLock = pParseGroup->FindPairValue(sSCRIPTKEYWORD_MULTISEQ_SECONDARYLOCK, "");
if (strLock.length())
{
Model_MultiSeq_SetActive(pContainer->hModel, false, true);
}
// multisequence primary and secondary lists...
//
CGPGroup*
pSubGroup = pParseGroup->FindSubGroup(sSCRIPTKEYWORD_MULTISEQ_PRIMARYLIST);
if (pSubGroup)
{
CGPValue *pValue = pSubGroup->GetPairs();
while (pValue)
{
// string strJunk = (*it).first; // eg 'name0'
string strSequence = pValue->GetTopValue();
int iSeqNum = Model_Sequence_IndexForName(pContainer, strSequence.c_str());
if (iSeqNum != -1)
{
Model_MultiSeq_Add( pContainer->hModel, iSeqNum, true, false);
}
pValue = pValue->GetNext();
}
}
pSubGroup = pParseGroup->FindSubGroup(sSCRIPTKEYWORD_MULTISEQ_SECONDARYLIST);
if (pSubGroup)
{
CGPValue *pValue = pSubGroup->GetPairs();
while (pValue)
{
// string strJunk = (*it).first; // eg 'name0'
string strSequence = pValue->GetTopValue();
int iSeqNum = Model_Sequence_IndexForName(pContainer, strSequence.c_str());
if (iSeqNum != -1)
{
Model_MultiSeq_Add( pContainer->hModel, iSeqNum, false, false);
}
pValue = pValue->GetNext();
}
}
// now read in any surfaces that were set ON, OFF, or OFF+NO CHILDREN by the user...
//
pSubGroup = pParseGroup->FindSubGroup(sSCRIPTKEYWORD_SURFACES_ON);
if (pSubGroup)
{
CGPValue *pValue = pSubGroup->GetPairs();
while (pValue)
{
// string strJunk = (*it).first; // eg 'name0'
string strSurface = pValue->GetTopValue();
Model_GLMSurface_SetStatus( pContainer->hModel, strSurface.c_str(), SURF_ON);
pValue = pValue->GetNext();
}
}
pSubGroup = pParseGroup->FindSubGroup(sSCRIPTKEYWORD_SURFACES_OFF);
if (pSubGroup)
{
CGPValue *pValue = pSubGroup->GetPairs();
while (pValue)
{
// string strJunk = (*it).first; // eg 'name0'
string strSurface = pValue->GetTopValue();
Model_GLMSurface_SetStatus( pContainer->hModel, strSurface.c_str(), SURF_OFF);
pValue = pValue->GetNext();
}
}
pSubGroup = pParseGroup->FindSubGroup(sSCRIPTKEYWORD_SURFACES_OFFNOCHILDREN);
if (pSubGroup)
{
CGPValue *pValue = pSubGroup->GetPairs();
while (pValue)
{
// string strJunk = (*it).first; // eg 'name0'
string strSurface = pValue->GetTopValue();
Model_GLMSurface_SetStatus( pContainer->hModel, strSurface.c_str(), SURF_NO_DESCENDANTS);
pValue = pValue->GetNext();
}
}
// ...
}
while(0);
if (psError)
{
static string strErrors;
strErrors = psError;
strErrors.insert(0,"Script_Parse_ReadOptionalArgs(): ");
return strErrors.c_str();
}
return NULL;
}
static LPCSTR Script_Parse_BoltModel(CGPGroup *pParseGroup)
{
LPCSTR psError = NULL;
do
{
// "name"...
//
string strHandle = pParseGroup->FindPairValue(sSCRIPTKEYWORD_NAME, "");
if (! (strHandle.length()))
{
psError = "No '" sSCRIPTKEYWORD_NAME "' keyword found!";
break;
}
// "modelfile"...
//
string strModelFile = pParseGroup->FindPairValue(sSCRIPTKEYWORD_MODELFILE, "");
if (! (strModelFile.length()))
{
psError = "No '" sSCRIPTKEYWORD_MODELFILE "' keyword found!";
break;
}
// "parent"...
//
string strParentHandle = pParseGroup->FindPairValue(sSCRIPTKEYWORD_PARENT, "");
if (! (strParentHandle.length()))
{
psError = "No '" sSCRIPTKEYWORD_PARENT "' keyword found!";
break;
}
// "bolttobone" or "bolttosurface"
//
string strBoltToBone = pParseGroup->FindPairValue(sSCRIPTKEYWORD_BOLTTOBONE, "");
string strBoltToSurface = pParseGroup->FindPairValue(sSCRIPTKEYWORD_BOLTTOSURFACE, "");
if ( !(strBoltToBone.length()) && !(strBoltToSurface.length()) )
{
psError = "No '" sSCRIPTKEYWORD_BOLTTOBONE "' or '" sSCRIPTKEYWORD_BOLTTOSURFACE "' keyword found!";
break;
}
// check parent handle is valid...
//
ModelContainer_t *pParentContainer = NULL;
for (HandleXref_t::iterator it = HandleXRefs.begin(); it!=HandleXRefs.end(); it++)
{
pParentContainer = (*it).first;
string sThisName = (*it).second;
if (sThisName == strParentHandle)
break;
}
if (pParentContainer == NULL)
{
psError = va("Unknown parent handle \"%s\"",strParentHandle.c_str());
break;
}
// read model in...
//
char *psFullPathedFileName = va("%s%s",gamedir,strModelFile.c_str());
//
// bolt to bone?
//
if (strBoltToBone.length())
{
if (!Model_LoadBoltOn(psFullPathedFileName, pParentContainer->hModel, strBoltToBone.c_str(), true, false)) // bBoltIsBone, bBoltReplacesAllExisting
{
psError = va("Failed to load bonebolt-model \"%s\"",psFullPathedFileName);
break;
}
}
else
{
// bolt to surface...
//
if (!Model_LoadBoltOn(psFullPathedFileName, pParentContainer->hModel, strBoltToSurface.c_str(), false, false)) // bBoltIsBone, bBoltReplacesAllExisting
{
psError = va("Failed to load surfacebolt-model \"%s\"",psFullPathedFileName);
break;
}
}
// loaded ok...
//
ModelContainer_t *pThisContainer = ModelContainer_FindFromModelHandle( AppVars.hModelLastLoaded );
HandleXRefs[pThisContainer] = strHandle;
Script_Parse_ReadOptionalArgs(pThisContainer, pParseGroup);
}
while(0);
if (psError)
{
static string strErrors;
strErrors = psError;
strErrors.insert(0,"Script_Parse_BoltModel(): ");
return strErrors.c_str();
}
return NULL;
}
static LPCSTR Script_Parse_LoadModel(CGPGroup *pParseGroup)
{
LPCSTR psError = NULL;
do
{
// "name"...
//
string strHandle = pParseGroup->FindPairValue(sSCRIPTKEYWORD_NAME, "");
if (! (strHandle.length()))
{
psError = "No '" sSCRIPTKEYWORD_NAME "' keyword found!";
break;
}
// "modelfile"...
//
string strModelFile = pParseGroup->FindPairValue(sSCRIPTKEYWORD_MODELFILE, "");
if (! (strModelFile.length()))
{
psError = "No '" sSCRIPTKEYWORD_MODELFILE "' keyword found!";
break;
}
// read model in... (need to make local version of this to pass, va() gets used too much during load
//
extern bool Document_ModelLoadPrimary(LPCSTR psFilename);
//char *psFullPathModelName = va("%s%s",gamedir,strModelFile.c_str());
char sFullPathModelName[MAX_PATH];
strncpy(sFullPathModelName,va("%s%s",gamedir,strModelFile.c_str()),sizeof(sFullPathModelName)-1);
sFullPathModelName[sizeof(sFullPathModelName)-1]='\0';
if (!Document_ModelLoadPrimary( sFullPathModelName ))
{
psError = va("Failed to load primary model %s",sFullPathModelName);
break;
}
// loaded ok...
//
ModelContainer_t *pThisContainer = &AppVars.Container;
HandleXRefs[pThisContainer] = strHandle;
psError = Script_Parse_ReadOptionalArgs(pThisContainer, pParseGroup);
if (psError)
break;
// now check for boltons...
//
CGPGroup *pSubGroup = pParseGroup->GetSubGroups();
while (pSubGroup)
{
string strSubGroupType = pSubGroup->GetName();
if (strSubGroupType == sSCRIPTKEYWORD_BOLTMODEL)
{
if ((psError = Script_Parse_BoltModel(pSubGroup))!=NULL)
break;
}
pSubGroup = pSubGroup->GetNext();
}
if (psError)
break;
}
while(0);
if (psError)
{
static string strErrors;
strErrors = psError;
strErrors.insert(0,"Script_Parse_LoadModel(): ");
return strErrors.c_str();
}
return NULL;
}
bool Script_Read(LPCSTR psFullPathedFilename)
{
LPCSTR psError = NULL;
char *psData = NULL;
int iSize = LoadFile(psFullPathedFilename, (void**)&psData);
if (iSize != -1)
{
SetQdirFromPath( psFullPathedFilename );
Script_Clear();
char *psDataPtr = psData;
// parse it...
//
if (theParser.Parse(&psDataPtr, true))
{
CGPGroup *pFileGroup = theParser.GetBaseParseGroup();
CGPGroup *pParseGroup_LoadModel = pFileGroup->FindSubGroup(sSCRIPTKEYWORD_LOADMODEL);//, true);
if (pParseGroup_LoadModel)
{
// special optional arg for NPC->MVS hackiness...
//
string strBaseDir = pParseGroup_LoadModel->FindPairValue(sSCRIPTKEYWORD_BASEDIR, "");
if (!strBaseDir.empty())
{
SetQdirFromPath( strBaseDir.c_str() );
}
psError = Script_Parse_LoadModel(pParseGroup_LoadModel);
}
else
{
psError = "Unable to find keyword '" sSCRIPTKEYWORD_LOADMODEL "'";
}
}
else
{
psError = va("{} - Brace mismatch error in file \"%s\"!",psFullPathedFilename);
}
}
else
{
psError = "File not found";
}
SAFEFREE(psData);
if (psError)
{
ErrorBox(va("Error while reading script file: \"%s\":\n\n%s",psFullPathedFilename,psError));
}
return !psError;
}
/////////////////// eof /////////////////