-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.cpp
704 lines (592 loc) · 21 KB
/
main.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
// TransData
//
// TransData is used to report information out of a Transcendence
// datafile
// Copyright (c) 2019 Kronosaur Productions, LLC. All Rights Reserved.
#include "PreComp.h"
#ifdef DEBUG
//#define DEBUG_PERFORMANCE
#endif
#define NOARGS CONSTLIT("noArgs")
#define QUESTION_MARK_SWITCH CONSTLIT("?")
#define HELP_SWITCH CONSTLIT("help")
#define H_SWITCH CONSTLIT("h")
#define NO_LOGO_SWITCH CONSTLIT("nologo")
#define ACHIEVEMENTS_SWITCH CONSTLIT("achievements")
#define ADVENTURE_SWITCH CONSTLIT("adventure")
#define API_VERSION_SWITCH CONSTLIT("apiVersion")
#define ARMOR_TABLE_SWITCH CONSTLIT("armortable")
#define ATTRIBUTE_LIST_SWITCH CONSTLIT("attributelist")
#define BATTLE_SIM_SWITCH CONSTLIT("battlesim")
#define DEBUG_SWITCH CONSTLIT("debug")
#define DEBUG_CREATE_SWITCH CONSTLIT("debugCreate")
#define DEBUG_MARKERS_SWITCH CONSTLIT("debugMarkers")
#define DECOMPILE_SWITCH CONSTLIT("decompile")
#define DIAGNOSTICS_SWITCH CONSTLIT("diagnostics")
#define EFFECT_EXPLORER_SWITCH CONSTLIT("effectExplorer")
#define EFFECT_IMAGE_SWITCH CONSTLIT("effectImage")
#define EFFECT_PERF_SWITCH CONSTLIT("effectPerf")
#define ENCOUNTER_COUNT_SWITCH CONSTLIT("encountercount")
#define ENCOUNTER_FREQ_SWITCH CONSTLIT("encounterfreq")
#define ENCOUNTER_SIM_SWITCH CONSTLIT("encountersim")
#define EXPORT_SWITCH CONSTLIT("export")
#define ENCOUNTER_TABLE_SWITCH CONSTLIT("encountertable")
#define ENTITIES_SWITCH CONSTLIT("entitiesReference")
#define EXTENSION_FOLDER_ATTRIB CONSTLIT("extensionFolder")
#define EXTENSION_TABLE_SWITCH CONSTLIT("extensionTable")
#define EXTENSIONS_ATTRIB CONSTLIT("extensions")
#define HEXARC_TEST_SWITCH CONSTLIT("hexarcTest")
#define ITEM_FREQUENCY_SWITCH CONSTLIT("itemsim")
#define ITEM_TABLE_SWITCH CONSTLIT("itemtable")
#define LANGUAGE_SWITCH CONSTLIT("language")
#define LOOT_SIM_SWITCH CONSTLIT("lootsim")
#define MORE_EXTENSIONS_ATTRIB CONSTLIT("moreExtensions")
#define PERF_TEST_SWITCH CONSTLIT("perftest")
#define RANDOM_ITEMS_SWITCH CONSTLIT("randomitems")
#define RANDOM_NUMBER_TEST CONSTLIT("randomnumbertest")
#define REFERENCE_SWITCH CONSTLIT("reference")
#define RUN_SWITCH CONSTLIT("run")
#define RUN_FILE_SWITCH CONSTLIT("runFile")
#define SCRIPT_SWITCH CONSTLIT("script")
#define SHIELD_TEST_SWITCH CONSTLIT("shieldtest")
#define SHIP_IMAGE_SWITCH CONSTLIT("shipimage")
#define SHIP_IMAGES_SWITCH CONSTLIT("shipimages")
#define SHIP_TABLE_SWITCH CONSTLIT("shiptable")
#define SIM_TABLES_SWITCH CONSTLIT("simTables")
#define SMOKE_TEST_SWITCH CONSTLIT("smoketest")
#define SNAPSHOT_SWITCH CONSTLIT("snapshot")
#define STATION_FREQUENCY_SWITCH CONSTLIT("stationfrequency")
#define STATION_PLACE_SIM_SWITCH CONSTLIT("stationSeparationSim")
#define STATS_SWITCH CONSTLIT("stats")
#define STD_ARMOR_SWITCH CONSTLIT("stdarmor")
#define STD_SHIELD_SWITCH CONSTLIT("stdshield")
#define SYSTEM_COUNT_SWITCH CONSTLIT("systemcount")
#define SYSTEM_IMAGES_SWITCH CONSTLIT("systemImages")
#define SYSTEM_LABELS_SWITCH CONSTLIT("systemlabels")
#define SYSTEM_TEST_SWITCH CONSTLIT("systemtest")
#define TOPOLOGY_SWITCH CONSTLIT("topology")
#define TOPOLOGY_MAP_SWITCH CONSTLIT("topologyMap")
#define TRADE_SIM_SWITCH CONSTLIT("tradeSim")
#define TRADE_TABLE_SWITCH CONSTLIT("tradeTable")
#define TYPE_DEPENDENCIES_SWITCH CONSTLIT("typeDependencies")
#define IMAGES_SWITCH CONSTLIT("typeImages")
#define TYPE_ISLANDS_SWITCH CONSTLIT("typeIslands")
#define TYPE_TABLE_SWITCH CONSTLIT("typeTable")
#define WEAPON_IMAGES_SWITCH CONSTLIT("weaponImages")
#define WORD_GENERATOR_SWITCH CONSTLIT("wordgenerator")
#define WORD_LIST_SWITCH CONSTLIT("wordlist")
#define WORLD_IMAGES_SWITCH CONSTLIT("worldImages")
#define CLEAR_REGISTERED_SWITCH CONSTLIT("clearRegistered")
#define GAME_FILE_SWITCH CONSTLIT("gameFile")
void AlchemyMain (CXMLElement *pCmdLine);
ALERROR CreateXMLElementFromDataFile (const CString &sFilespec, CXMLElement **retpDataFile, CString *retsError);
ALERROR InitUniverse (CUniverse &Universe, CHost &Host, const CString &sFilespec, CXMLElement *pCmdLine, CString *retsError);
int main (int argc, const char *argv[ ], char *envp[ ])
// main
//
// main entry-point
{
// Output Windows Western codepage
::SetConsoleOutputCP(1252);
#ifdef DEBUG_MEMORY_LEAKS
int iFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
iFlag = _CrtSetDbgFlag(iFlag | _CRTDBG_ALLOC_MEM_DF);
iFlag = _CrtSetDbgFlag(iFlag | _CRTDBG_LEAK_CHECK_DF);
_CrtSetBreakAlloc(1137987);
#endif
if (!kernelInit(KERNEL_FLAG_INTERNETS))
{
printf("ERROR: Unable to initialize Alchemy kernel.\n");
return 1;
}
// Do it
{
ALERROR error;
CString sError;
// Look for a TransData.xml file. If we find it, load it.
CXMLElement *pOptions = NULL;
CString sDefaultOptionsFile = CONSTLIT("TransData.xml");
if (pathExists(sDefaultOptionsFile))
{
if (error = CreateXMLElementFromDataFile(sDefaultOptionsFile, &pOptions, &sError))
{
printf("ERROR: Unable to parse %s: %s.\n", sDefaultOptionsFile.GetASCIIZPointer(), sError.GetASCIIZPointer());
return 1;
}
}
// Otherwise we just create an empty element
else
pOptions = new CXMLElement(CONSTLIT("TransData"), NULL);
// Load the command line and merge it into pOptions
CXMLElement *pCmdLine;
if (error = CreateXMLElementFromCommandLine(argc, argv, &pCmdLine))
{
printf("ERROR: Unable to parse command line.\n");
return 1;
}
pOptions->MergeFrom(pCmdLine);
delete pCmdLine;
// If we have a text argument, then use it as a command-line file:
const CString &sArg = pOptions->GetContentText(0);
if (!sArg.IsBlank())
{
CXMLElement *pDataFile;
if (error = CreateXMLElementFromDataFile(sArg, &pDataFile, &sError))
{
printf("ERROR: %s\n", sError.GetASCIIZPointer());
return 1;
}
// Merge into options
pOptions->MergeFrom(pDataFile);
delete pDataFile;
}
// Now run
AlchemyMain(pOptions);
// Done
delete pOptions;
}
// Done
kernelCleanUp();
return 0;
}
void AlchemyMain (CXMLElement *pCmdLine)
// AlchemyMain
//
// Main entry-point after kernel initialization
{
ALERROR error;
// Welcome message
bool bLogo = !pCmdLine->GetAttributeBool(NO_LOGO_SWITCH);
if (bLogo)
{
SFileVersionInfo VersionInfo;
if (fileGetVersionInfo(NULL_STR, &VersionInfo) != NOERROR)
{
printf("ERROR: Unable to get version info.\n");
return;
}
if (pCmdLine->FindAttribute(RUN_SWITCH)
|| pCmdLine->FindAttribute(RUN_FILE_SWITCH))
{
printf("TLisp Shell %s\n", (LPSTR)VersionInfo.sProductVersion);
printf("%s\n\n", (LPSTR)VersionInfo.sCopyright);
}
else
{
printf("TransData %s\n", (LPSTR)VersionInfo.sProductVersion);
printf("%s\n\n", (LPSTR)VersionInfo.sCopyright);
}
}
if (pCmdLine->GetAttributeBool(NOARGS)
|| pCmdLine->GetAttributeBool(QUESTION_MARK_SWITCH)
|| pCmdLine->GetAttributeBool(HELP_SWITCH)
|| pCmdLine->GetAttributeBool(H_SWITCH))
{
ShowHelp(pCmdLine);
return;
}
else if (pCmdLine->GetAttributeBool(DEBUG_MARKERS_SWITCH))
{
DebugMarkers(pCmdLine);
return;
}
// Set debug log
#ifdef DEBUG
CTextFileLog LogFile(CONSTLIT("TransData.log"));
::kernelSetDebugLog(&LogFile, FALSE);
#endif
// Figure out the data file that we're working on
bool bDefaultDataFile = false;
CString sDataFile = pCmdLine->GetAttribute(CONSTLIT("dataFile"));
if (sDataFile.IsBlank())
{
bDefaultDataFile = true;
sDataFile = CONSTLIT("Transcendence");
}
// See if we are doing a command that does not require parsing
if (pCmdLine->GetAttributeBool(WORD_LIST_SWITCH))
{
GenerateWordList(sDataFile, pCmdLine);
::kernelSetDebugLog(NULL);
return;
}
else if (pCmdLine->GetAttributeBool(WORD_GENERATOR_SWITCH))
{
WordGenerator(pCmdLine);
::kernelSetDebugLog(NULL);
return;
}
else if (pCmdLine->GetAttributeBool(ENTITIES_SWITCH))
{
GenerateEntitiesTable(sDataFile, pCmdLine);
::kernelSetDebugLog(NULL);
return;
}
else if (pCmdLine->GetAttributeBool(DECOMPILE_SWITCH))
{
Decompile(sDataFile, pCmdLine);
::kernelSetDebugLog(NULL);
return;
}
else if (pCmdLine->GetAttributeBool(CLEAR_REGISTERED_SWITCH))
{
const CString sSaveFile = pCmdLine->GetAttribute(GAME_FILE_SWITCH);
CGameFile Game;
if (error = Game.Open(sSaveFile, CGameFile::FLAG_NO_UPGRADE))
{
printf("ERROR: Can't open %s.\n", (char *)sSaveFile);
::kernelSetDebugLog(NULL);
return;
}
printf("Save file: %s.\n", (char *)sSaveFile);
if (Game.IsRegistered())
{
if (error = Game.ClearRegistered())
{
printf("ERROR: Unable to clear registered bit.\n");
::kernelSetDebugLog(NULL);
return;
}
printf("Cleared registered bit.\n");
}
else
printf("Unregistered game.\n");
if (Game.IsGameResurrect() && Game.GetDifficulty() == CDifficultyOptions::ELevel::Permadeath)
{
if (error = Game.ClearGameResurrect())
{
printf("ERROR: Unable to clear resurrect bit.\n");
::kernelSetDebugLog(NULL);
return;
}
printf("Cleared resurrect bit.\n");
}
if (Game.IsEndGame())
{
if (error = Game.ClearEndGame())
{
printf("ERROR: Unable to clear endgame bit.\n");
::kernelSetDebugLog(NULL);
return;
}
printf("Cleared endgame bit.\n");
}
if (!Game.IsDebug())
{
if (error = Game.SetDebugMode())
{
printf("ERROR: Unable to set debug bit.\n");
::kernelSetDebugLog(NULL);
return;
}
printf("Set debug mode.\n");
}
::kernelSetDebugLog(NULL);
return;
}
// Set to data file directory
#if 0
if (!sDataFile.IsBlank())
{
CString sFolder = pathGetPath(sDataFile);
if (!sFolder.IsBlank())
::SetCurrentDirectory(sFolder.GetASCIIZPointer());
}
#endif
// Initialize the Universe
CHost Host;
CUniverse Universe;
CString sError;
if (error = InitUniverse(Universe, Host, (bDefaultDataFile ? NULL_STR : sDataFile), pCmdLine, &sError))
{
printf("%s\n", sError.GetASCIIZPointer());
::kernelSetDebugLog(NULL);
return;
}
// Figure out what to do
if (pCmdLine->GetAttributeBool(ACHIEVEMENTS_SWITCH))
GenerateAchievementsTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(ARMOR_TABLE_SWITCH))
GenerateArmorTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(DIAGNOSTICS_SWITCH))
GenerateDiagnostics(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(ENCOUNTER_COUNT_SWITCH))
GenerateEncounterCount(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(ENCOUNTER_FREQ_SWITCH))
GenerateEncounterFrequency(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(ENCOUNTER_TABLE_SWITCH))
GenerateEncounterTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(EXPORT_SWITCH))
ExportData(Universe, *pCmdLine);
else if (pCmdLine->GetAttributeBool(EXTENSION_TABLE_SWITCH))
GenerateExtensionTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(IMAGES_SWITCH))
GenerateImageChart(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(ITEM_FREQUENCY_SWITCH))
GenerateItemFrequencyTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(ITEM_TABLE_SWITCH))
GenerateItemTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(LANGUAGE_SWITCH))
GenerateLanguageTable(Universe, pCmdLine);
else if (pCmdLine->FindAttribute(SCRIPT_SWITCH))
GenerateScript(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(LOOT_SIM_SWITCH))
GenerateLootSim(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(RANDOM_ITEMS_SWITCH))
GenerateRandomItemTables(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(RANDOM_NUMBER_TEST))
DoRandomNumberTest();
else if (pCmdLine->FindAttribute(RUN_SWITCH)
|| pCmdLine->FindAttribute(RUN_FILE_SWITCH))
Run(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SHIELD_TEST_SWITCH))
GenerateShieldStats(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(EFFECT_EXPLORER_SWITCH))
GenerateEffectExplorer(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(EFFECT_IMAGE_SWITCH))
GenerateEffectImage(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(EFFECT_PERF_SWITCH))
DoEffectPerformanceTest(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SHIP_IMAGE_SWITCH))
GenerateShipImage(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SHIP_IMAGES_SWITCH))
GenerateShipImageChart(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SHIP_TABLE_SWITCH))
GenerateShipTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SIM_TABLES_SWITCH))
GenerateSimTables(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SMOKE_TEST_SWITCH))
DoSmokeTest(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SNAPSHOT_SWITCH))
GenerateSnapshot(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(STATION_FREQUENCY_SWITCH))
GenerateStationFrequencyTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(STATION_PLACE_SIM_SWITCH))
GenerateStationPlaceSim(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(STATS_SWITCH))
GenerateStats(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(STD_ARMOR_SWITCH))
GenerateStdArmorTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(STD_SHIELD_SWITCH))
GenerateStdShieldTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SYSTEM_COUNT_SWITCH))
GenerateSystemCount(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SYSTEM_IMAGES_SWITCH))
GenerateSystemImages(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SYSTEM_LABELS_SWITCH))
GenerateSystemLabelCount(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(SYSTEM_TEST_SWITCH))
GenerateSystemTest(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(TOPOLOGY_SWITCH))
GenerateTopology(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(TOPOLOGY_MAP_SWITCH))
GenerateTopologyMap(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(ATTRIBUTE_LIST_SWITCH))
GenerateAttributeList(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(PERF_TEST_SWITCH))
PerformanceTest(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(BATTLE_SIM_SWITCH))
RunBattleSim(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(ENCOUNTER_SIM_SWITCH))
RunEncounterSim(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(TYPE_DEPENDENCIES_SWITCH))
GenerateTypeDependencies(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(TYPE_TABLE_SWITCH))
GenerateTypeTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(TYPE_ISLANDS_SWITCH))
GenerateTypeIslands(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(HEXARC_TEST_SWITCH))
HexarcTest(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(TRADE_SIM_SWITCH))
DoTradeSim(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(TRADE_TABLE_SWITCH))
GenerateTradeTable(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(WEAPON_IMAGES_SWITCH))
GenerateWeaponEffectChart(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(WORLD_IMAGES_SWITCH))
GenerateWorldImageChart(Universe, pCmdLine);
else if (pCmdLine->GetAttributeBool(REFERENCE_SWITCH))
GenerateReference(Universe, pCmdLine);
else
GenerateStats(Universe, pCmdLine);
// Done
::kernelSetDebugLog(NULL);
}
ALERROR CreateXMLElementFromDataFile (const CString &sFilespec, CXMLElement **retpDataFile, CString *retsError)
{
ALERROR error;
int i;
CFileReadBlock File(sFilespec);
if (error = File.Open())
{
if (retsError) *retsError = strPatternSubst(CONSTLIT("Unable to open data file: %s."), sFilespec);
return error;
}
CXMLElement *pFile;
if (error = CXMLElement::ParseXML(&File, NULL, &pFile, retsError))
return error;
// Create a new element that looks like a command-line
CXMLElement *pDataFile = new CXMLElement(CONSTLIT("TransData"), NULL);
// Parse
CString sExtensionList;
for (i = 0; i < pFile->GetContentElementCount(); i++)
{
CXMLElement *pItem = pFile->GetContentElement(i);
if (strEquals(pItem->GetTag(), CONSTLIT("Extension")))
{
DWORD dwUNID = pItem->GetAttributeInteger(CONSTLIT("unid"));
if (dwUNID == 0)
{
printf("Warning: Invalid extension UNID: %x.\n", dwUNID);
continue;
}
if (sExtensionList.IsBlank())
sExtensionList = strPatternSubst(CONSTLIT("0x%x"), dwUNID);
else
sExtensionList = strPatternSubst(CONSTLIT("%s, 0x%x"), sExtensionList, dwUNID);
}
else if (strEquals(pItem->GetTag(), CONSTLIT("Option")))
{
CString sName = pItem->GetAttribute(CONSTLIT("name"));
CString sValue = pItem->GetAttribute(CONSTLIT("value"));
if (sValue.IsBlank())
sValue = CONSTLIT("true");
pDataFile->AddAttribute(sName, sValue);
}
else
printf("Warning: Unknown directive: %s.\n", pItem->GetTag().GetASCIIZPointer());
}
// Additional parameters
if (!sExtensionList.IsBlank())
pDataFile->AddAttribute(CONSTLIT("extensions"), sExtensionList);
// Done
*retpDataFile = pDataFile;
delete pFile;
return NOERROR;
}
ALERROR InitUniverse (CUniverse &Universe, CHost &Host, const CString &sFilespec, CXMLElement *pCmdLine, CString *retsError)
{
ALERROR error;
bool bLogo = !pCmdLine->GetAttributeBool(NO_LOGO_SWITCH);
if (bLogo)
printf("Loading...");
CUniverse::SInitDesc Ctx;
Ctx.sFilespec = sFilespec;
Ctx.pHost = &Host;
Ctx.bDebugMode = pCmdLine->GetAttributeBool(DEBUG_SWITCH);
Ctx.bVerboseCreate = pCmdLine->GetAttributeBool(DEBUG_CREATE_SWITCH);
// Figure out what adventure we need
if (!pCmdLine->FindAttributeInteger(ADVENTURE_SWITCH, (int *)&Ctx.dwAdventure))
Ctx.dwAdventure = DEFAULT_ADVENTURE_EXTENSION_UNID;
// See if we need to load images
if (pCmdLine->GetAttributeBool(EFFECT_IMAGE_SWITCH)
|| pCmdLine->GetAttributeBool(IMAGES_SWITCH)
|| pCmdLine->GetAttributeBool(SHIP_IMAGE_SWITCH)
|| pCmdLine->GetAttributeBool(SHIP_IMAGES_SWITCH)
|| pCmdLine->GetAttributeBool(SMOKE_TEST_SWITCH)
|| pCmdLine->GetAttributeBool(SNAPSHOT_SWITCH)
|| pCmdLine->GetAttributeBool(TOPOLOGY_MAP_SWITCH)
|| pCmdLine->GetAttributeBool(WEAPON_IMAGES_SWITCH)
|| pCmdLine->GetAttributeBool(BATTLE_SIM_SWITCH)
|| pCmdLine->GetAttributeBool(ENCOUNTER_SIM_SWITCH)
|| pCmdLine->GetAttributeBool(EFFECT_EXPLORER_SWITCH)
|| pCmdLine->GetAttributeBool(WORLD_IMAGES_SWITCH))
;
else
Ctx.bNoResources = true;
// If we're not in diagnostics mode, take out the diagnostics extension.
// [Otherwise we get some extraneous items in our item lists.]
Ctx.bDiagnostics = pCmdLine->GetAttributeBool(DIAGNOSTICS_SWITCH)
|| pCmdLine->GetAttributeBool(SMOKE_TEST_SWITCH);
// API version
Ctx.dwMinAPIVersion = pCmdLine->GetAttributeIntegerBounded(API_VERSION_SWITCH, 0, API_VERSION, API_VERSION);
// Extension
CString sExtensionFolder = pCmdLine->GetAttribute(EXTENSION_FOLDER_ATTRIB);
if (!sExtensionFolder.IsBlank())
{
TArray<CString> List;
ParseStringList(sExtensionFolder, PSL_FLAG_ALLOW_WHITESPACE, &List);
Ctx.ExtensionFolders.Insert(List);
}
CString sExtensionList;
if (pCmdLine->FindAttribute(EXTENSIONS_ATTRIB, &sExtensionList))
{
if (strEquals(sExtensionList, CONSTLIT("none")))
NULL;
else if (strEquals(sExtensionList, CONSTLIT("all")))
Ctx.bDefaultExtensions = true;
else
ParseUNIDList(sExtensionList, PUL_FLAG_HEX, &Ctx.ExtensionUNIDs);
}
else
Ctx.bDefaultExtensions = true;
// If we have additional extensions, add them now.
if (!Ctx.bDefaultExtensions
&& pCmdLine->FindAttribute(MORE_EXTENSIONS_ATTRIB, &sExtensionList))
{
if (strEquals(sExtensionList, CONSTLIT("all")))
{
Ctx.bDefaultExtensions = true;
Ctx.ExtensionUNIDs.DeleteAll();
}
else
{
TArray<DWORD> Extensions;
ParseUNIDList(sExtensionList, PUL_FLAG_HEX, &Extensions);
for (int i = 0; i < Extensions.GetCount(); i++)
if (Ctx.ExtensionUNIDs.Find(Extensions[i]))
{
Extensions.Delete(i);
i--;
}
Ctx.ExtensionUNIDs.Insert(Extensions);
}
}
// Open the universe
Ctx.bNoCollectionCheck = true;
// CC Libraries
SPrimitiveDefTable *pNewTable = Ctx.CCPrimitives.Insert();
GetCCTransDataLibrary(pNewTable);
#ifdef DEBUG_PERFORMANCE
DWORD dwStart = ::GetTickCount();
#endif
if (error = Universe.Init(Ctx, retsError))
{
printf("\n");
return error;
}
if (bLogo)
printf("done.\n");
if (error = Universe.InitGame(0, retsError))
return error;
#ifdef DEBUG_PERFORMANCE
printf("Universe Init: %d ms.\n", sysGetTicksElapsed(dwStart));
#endif
// Mark everything as known
if (!Ctx.bDiagnostics)
MarkItemsKnown(Universe);
return NOERROR;
}
bool IsMainCommandParam (const CString &sAttrib)
{
return (strEquals(sAttrib, CONSTLIT("adventure"))
|| strEquals(sAttrib, CONSTLIT("all"))
|| strEquals(sAttrib, CONSTLIT("allClasses"))
|| strEquals(sAttrib, CONSTLIT("apiVersion"))
|| strEquals(sAttrib, CONSTLIT("criteria"))
|| strEquals(sAttrib, CONSTLIT("debug"))
|| strEquals(sAttrib, CONSTLIT("debugCreate"))
|| strEquals(sAttrib, CONSTLIT("extensionFolder"))
|| strEquals(sAttrib, CONSTLIT("extensions"))
|| strEquals(sAttrib, CONSTLIT("noLogo")));
}
void MarkItemsKnown (CUniverse &Universe)
{
int i;
for (i = 0; i < Universe.GetItemTypeCount(); i++)
{
CItemType *pItem = Universe.GetItemType(i);
pItem->SetAllKnown();
pItem->SetShowReference();
}
}