-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathParameters.cpp
More file actions
551 lines (432 loc) · 15.8 KB
/
Copy pathParameters.cpp
File metadata and controls
551 lines (432 loc) · 15.8 KB
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
/*
* Open Fodder
* ---------------
*
* Copyright (C) 2008-2026 Open Fodder
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <stdafx.hpp>
#include <sstream>
#include "Utils/ini.hpp"
#include "Utils/cxxopts.hpp"
#include "Utils/json.hpp"
using Json = nlohmann::json;
cxxopts::Options* sFodderParameters::mCliOptions = 0;
/* These values override the original engine values, when in custom mode */
const size_t CUSTOM_DEFAULT_MAX_SPRITES = sFodderParameters::MAX_SPRITES_MAX;
const size_t CUSTOM_DEFAULT_MAX_SPAWN = 25;
std::string sFodderParameters::ToJson() {
Json Save;
Save["mSkipIntro"] = mSkipIntro;
Save["mSkipToMission"] = mSkipRecruit;
Save["mSkipBriefing"] = mSkipBriefing;
Save["mSkipService"] = mSkipService;
Save["mWindowMode"] = mWindowMode;
Save["mIntegerScaling"] = mIntegerScaling;
Save["mRandom"] = mRandom;
Save["mDefaultPlatform"] = mDefaultPlatform;
Save["mCampaignName"] = mCampaignName;
Save["mMissionNumber"] = mMissionNumber;
Save["mPhaseNumber"] = mPhaseNumber;
Save["mUnitTesting"] = mUnitTesting;
Save["mSinglePhase"] = mSinglePhase;
Save["mSpritesMax"] = mSpritesMax;
Save["mSpawnEnemyMax"] = mSpawnEnemyMax;
Save["mCheatsEnabled"] = mCheatsEnabled;
return Save.dump(1);
}
bool sFodderParameters::FromJson(const std::string& pJson) {
Json LoadedData;
try {
LoadedData = Json::parse(pJson);
}
catch (std::exception Exception) {
std::cout << "SaveGame JSON Parsing Error: " << Exception.what() << "\n";
return false;
}
mSkipService = LoadedData["mSkipService"];
mSkipBriefing = LoadedData["mSkipBriefing"];
mSkipIntro = LoadedData["mSkipIntro"];
mSkipRecruit = LoadedData["mSkipToMission"];
mMissionNumber = LoadedData["mMissionNumber"];
mPhaseNumber = LoadedData["mPhaseNumber"];
mWindowMode = LoadedData["mWindowMode"];
mRandom = LoadedData["mRandom"];
mDefaultPlatform = LoadedData["mDefaultPlatform"];
mCampaignName = LoadedData["mCampaignName"];
mUnitTesting = LoadedData["mUnitTesting"];
mSinglePhase = LoadedData["mSinglePhase"];
// Max Sprites
{
if (LoadedData.count("mSpritesMax") > 0)
mSpritesMax = LoadedData["mSpritesMax"];
else
mSpritesMax = 45; // The original engine limit
if (mSpritesMax < MIN_SPRITES_MAX)
mSpritesMax = MIN_SPRITES_MAX;
if (mSpritesMax > MAX_SPRITES_MAX)
mSpritesMax = MAX_SPRITES_MAX;
}
// Max Spawned
{
if (LoadedData.count("mSpawnEnemyMax") > 0)
mSpawnEnemyMax = LoadedData["mSpawnEnemyMax"];
else
mSpawnEnemyMax = 0x0A; // The original engine limit
}
if (LoadedData.count("mCheatsEnabled") > 0)
mCheatsEnabled = LoadedData["mCheatsEnabled"];
else
mCheatsEnabled = false;
if (LoadedData.count("mIntegerScaling") > 0) {
mIntegerScaling = LoadedData["mIntegerScaling"];
}
return true;
}
void sFodderParameters::PrepareOptions() {
if (!mCliOptions)
mCliOptions = new cxxopts::Options("OpenFodder", "War has never been so much fun");
mCliOptions->allow_unrecognised_options();
mCliOptions->add_options()
("about", "About", cxxopts::value<bool>()->default_value("false"))
("h,help", "Help", cxxopts::value<bool>()->default_value("false"))
("pc", "Default to PC platform data", cxxopts::value<bool>()->default_value("false"))
("amiga", "Default to Amiga platform data", cxxopts::value<bool>()->default_value("false"))
("engine", "Default to engine (single map/random)", cxxopts::value<std::string>()->default_value("cf1"), "cf1")
("columns", "Number of camera columns", cxxopts::value<std::uint32_t>()->default_value("22"), "22")
("rows", "Number of camera rows", cxxopts::value<std::uint32_t>()->default_value("16"), "16")
("alternate-mouse", "Play with non-original mouse behaviour", cxxopts::value<bool>()->default_value("false"))
("w,window", "Start in window mode", cxxopts::value<bool>()->default_value("false"))
("window-scale", "Set the window scale", cxxopts::value<std::uint32_t>()->default_value("0"))
("integer-scaling", "Use integer scaling", cxxopts::value<bool>()->default_value("true"))
("cheats", "Enable cheat keys", cxxopts::value<bool>()->default_value("false"))
("max-sprite", "Set the maximum sprites", cxxopts::value<std::uint32_t>()->default_value("45"), "45")
("max-spawn", "Set the maximum spawn", cxxopts::value<std::uint32_t>()->default_value("10"), "10")
("sleep-delta", "Set the engine speed (20 = 50Hz)", cxxopts::value<std::uint32_t>()->default_value("20"), "20")
("demo-record", "Record Demo", cxxopts::value<std::string>()->default_value(""), "\"Demo File\"")
("demo-record-all", "Record Demo")
("demo-play", "Play Demo", cxxopts::value<std::string>()->default_value(""), "\"Demo File\"")
("unit-test", "Run Tests", cxxopts::value<bool>()->default_value("false"))
("unit-test-headless", "Run Tests, with no output", cxxopts::value<bool>()->default_value("false"))
("appveyor", "Output for appveyor", cxxopts::value<bool>()->default_value("false"))
("nosound", "Disable sound output", cxxopts::value<bool>()->default_value("false"))
("playground", "Sprite playground", cxxopts::value<bool>()->default_value("false"))
("skipintro", "Skip all game intros", cxxopts::value<bool>()->default_value("false"))
("disable-intro-video", "Disable intro video playback", cxxopts::value<bool>()->default_value("false"))
("skipbriefing", "Skip mission briefing", cxxopts::value<bool>()->default_value("false"))
("skipservice", "Skip mission debriefing", cxxopts::value<bool>()->default_value("false"))
("skiphill", "Skip the hill", cxxopts::value<bool>()->default_value("false"))
("list-campaigns", "List available campaigns", cxxopts::value<bool>()->default_value("false"))
("c,campaign", "Starting campaign", cxxopts::value<std::string>()->default_value(""), "\"name\"")
("m,mission", "Starting mission", cxxopts::value<std::uint32_t>()->default_value("0"), "1")
("p,phase", "Starting phase", cxxopts::value<std::uint32_t>()->default_value("0"), "2")
("single-map", "Play a single map", cxxopts::value<std::string>()->default_value(""), "\"MyMap\"")
("r,random", "Generate and play a random map", cxxopts::value<bool>()->default_value("false"))
("random-save", "Generate and save a random map", cxxopts::value<std::string>()->default_value(""), "\"MyMap\"")
("script", "Name of script to execute", cxxopts::value<std::string>()->default_value(""), "\"script.js\"")
#ifdef OF_JS_DEBUG
("debugger", "Wait for debugger in scripts", cxxopts::value<bool>()->default_value("false"))
#endif
;
}
bool sFodderParameters::ProcessCLI(int argc, char *argv[]) {
if (!mCliOptions)
PrepareOptions();
try {
auto result = mCliOptions->parse(argc, argv);
if (result["appveyor"].as<bool>()) {
mAppVeyor = true;
}
if (result["help"].as<bool>() == true) {
g_Debugger->Notice(mCliOptions->help());
mShowHelp = true;
return false;
}
if (result.count("pc"))
mDefaultPlatform = ePlatform::PC;
if (result.count("amiga"))
mDefaultPlatform = ePlatform::Amiga;
if (result.count("engine")) {
if (result["engine"].as<std::string>() == "cf1")
mDefaultGame = eGame::CF1;
if (result["engine"].as<std::string>() == "cf2")
mDefaultGame = eGame::CF2;
}
if (result["list-campaigns"].as<bool>() == true) {
g_Debugger->Notice("\nAvailable Campaigns\n\n");
g_ResourceMan->refresh();
for (auto& Name : g_Fodder->mVersions->GetCampaignNames())
g_Debugger->Notice(Name);
return false;
}
if (result.count("demo-record-all")) {
mDemoRecord = true;
mDemoFile = "-";
}
else {
mDemoFile = result["demo-record"].as<std::string>();
if (mDemoFile.size())
mDemoRecord = true;
else {
mDemoFile = result["demo-play"].as<std::string>();
if (mDemoFile.size())
mDemoPlayback = true;
}
}
mShowAbout = result["about"].as<bool>();
if (result.count("skipintro"))
mSkipIntro = result["skipintro"].as<bool>();
if (result.count("disable-intro-video"))
mDisableIntroVideo = result["disable-intro-video"].as<bool>();
if (result.count("skipservice"))
mSkipService = result["skipservice"].as<bool>();
if (result.count("skipbriefing"))
mSkipBriefing = result["skipbriefing"].as<bool>();
if (result.count("skiphill"))
mSkipRecruit = result["skiphill"].as<bool>();
mUnitTesting = result["unit-test"].as<bool>();
mSingleMap = result["single-map"].as<std::string>();
if (mSingleMap.size()) {
mSingleMap.append(".map");
mSinglePhase = true;
}
mCampaignName = result["campaign"].as<std::string>();
mMissionNumber = result["mission"].as<std::uint32_t>();
mPhaseNumber = result["phase"].as<std::uint32_t>();
if(result.count("alternate-mouse"))
mMouseAlternative = result["alternate-mouse"].as<bool>();
if (result.count("window"))
mWindowMode = result["window"].as<bool>();
if(result.count("window-scale"))
mWindowScale = result["window-scale"].as<uint32>();
if (result.count("integer-scaling"))
mIntegerScaling = result["integer-scaling"].as<bool>();
mRandom = result["random"].as<bool>();
if (result["random-save"].count()) {
mRandomFilename = result["random-save"].as<std::string>();
mRandomSave = true;
mRandom = true;
}
mDisableSound = result["nosound"].as<bool>();
mPlayground = result["playground"].as<bool>();
mSleepDelta = result["sleep-delta"].as<uint32_t>();
if (result.count("cheats"))
mCheatsEnabled = result["cheats"].as<bool>();
if(result.count("rows"))
mWindowRows = result["rows"].as<std::uint32_t>();
if (result.count("columns"))
mWindowColumns = result["columns"].as<std::uint32_t>();
if (result.count("script"))
mScriptRun = result["script"].as<std::string>();
// Random / Script mode increase default max sprites/spawn
if (mScriptRun.size() || mRandom) {
mSpritesMax = CUSTOM_DEFAULT_MAX_SPRITES;
mSpawnEnemyMax = CUSTOM_DEFAULT_MAX_SPAWN;
}
#ifdef OF_JS_DEBUG
mDebugger = result["debugger"].as<bool>();
#endif
if (result.count("max-sprite"))
mSpritesMax = result["max-sprite"].as<uint32_t>();
if (result.count("max-spawn"))
mSpawnEnemyMax = result["max-spawn"].as<uint32_t>();
if (mSpritesMax < MIN_SPRITES_MAX)
mSpritesMax = MIN_SPRITES_MAX;
if (mSpritesMax > MAX_SPRITES_MAX)
mSpritesMax = MAX_SPRITES_MAX;
// Cheats perm enabled in debug build
#ifdef _DEBUG
mCheatsEnabled = true;
#endif
// Skip intro and recruit screen if a campaign and mission/phase is provided
if (mCampaignName.length() && (mMissionNumber || mPhaseNumber)) {
mSkipRecruit = true;
mSkipIntro = true;
}
if (result["unit-test-headless"].as<bool>()) {
mUnitTesting = true;
mDisableVideo = true;
mDisableSound = true;
g_Window = std::make_shared<cWindowNull>();
g_Fodder->mWindow = g_Window;
}
if (mUnitTesting) {
mWindowMode = true;
}
#ifdef _DEBUG
mWindowMode = true;
#endif
}
catch (...) {
g_Debugger->Notice(mCliOptions->help());
return false;
}
return true;
}
std::string str_to_lower(std::string pStr) {
std::transform(pStr.begin(), pStr.end(), pStr.begin(), ::tolower);
return pStr;
}
bool sFodderParameters::SaveIni() {
INI<> ini("openfodder.ini", false);
ini.parse();
if (ini.select("openfodder")) {
ini.set("window", mWindowMode ? "true" : "false");
ini.set("cheats", mCheatsEnabled ? "true" : "false");
ini.set("scale", (mWindowScale == 0) ? "auto" : std::to_string(mWindowScale));
ini.set("integer", mIntegerScaling ? "true" : "false");
ini.set("columns", (mWindowColumns == 0) ? "0" : std::to_string(mWindowColumns));
ini.set("rows", (mWindowRows == 0) ? "0" : std::to_string(mWindowRows));
ini.set("alternate-mouse", mMouseAlternative ? "true" : "false");
ini.set("mouse-locked", mMouseLocked ? "true" : "false");
{
std::ostringstream speed;
speed.setf(std::ios::fixed);
speed.precision(1);
speed << mMouseSpeed;
ini.set("mouse-speed", speed.str());
}
ini.set("copyprotection", mCopyProtection ? "true" : "false");
}
else {
return false;
}
if (ini.select("engine")) {
ini.set("platform",
(mDefaultPlatform == ePlatform::Amiga) ? "amiga" :
(mDefaultPlatform == ePlatform::PC) ? "pc" :
"");
ini.set("engine",
(mDefaultGame == eGame::CF2) ? "cf2" : "cf1");
ini.set("maxsprite", std::to_string(mSpritesMax));
ini.set("maxspawn", std::to_string(mSpawnEnemyMax));
ini.set("sleep-delta", std::to_string(mSleepDelta));
}
if (ini.select("skip")) {
ini.set("intro", mSkipIntro ? "true" : "false");
ini.set("intro-video", mDisableIntroVideo ? "true" : "false");
ini.set("briefing", mSkipBriefing ? "true" : "false");
ini.set("service", mSkipService ? "true" : "false");
ini.set("hill", mSkipRecruit ? "true" : "false");
}
// [paths]
// TODO Later
//
// if (ini.select("paths")) {
// ini["paths"].clear();
// for (size_t i = 0; i < mResourcePaths.size(); ++i) {
// ini["paths"][std::to_string(i)] = mResourcePaths[i];
// }
// }
//
return ini.save();
}
bool sFodderParameters::ProcessINI() {
INI<> ini("openfodder.ini", false);
if (!ini.parse())
return false;
// Section: Openfodder
{
if (ini.select("openfodder")) {
if (ini.get("window", "false") == "true")
mWindowMode = true;
else
mWindowMode = false;
if (ini.get("cheats", "false") == "true")
mCheatsEnabled = true;
else
mCheatsEnabled = false;
if (ini.get("scale", "false") == "auto")
mWindowScale = 0;
else {
mWindowScale = ini.get("scale", 0);
}
if (ini.get("integer", "true") == "true")
mIntegerScaling = true;
else {
mIntegerScaling = false;
}
if (ini.get("columns", "0") == "0")
mWindowColumns = 0;
else {
mWindowColumns = ini.get("columns", 22);
}
if (ini.get("rows", "0") == "0")
mWindowRows = 0;
else {
mWindowRows = ini.get("rows", 16);
}
if (ini.get("alternate-mouse", "false") == "true")
mMouseAlternative = true;
if (ini.get("mouse-locked", "false") == "true")
mMouseLocked = true;
mMouseSpeed = (float)ini.get("mouse-speed", 1.5);
if (mMouseSpeed < 0.5f)
mMouseSpeed = 0.5f;
if (mMouseSpeed > 10.0f)
mMouseSpeed = 10.0f;
if (ini.get("copyprotection", "false") == "true")
mCopyProtection = true;
}
}
// Section: Engine
{
if (ini.select("engine")) {
auto platform = str_to_lower(ini.get("platform", ""));
if (platform == "amiga")
mDefaultPlatform = ePlatform::Amiga;
if (platform == "pc")
mDefaultPlatform = ePlatform::PC;
auto game = str_to_lower(ini.get("engine", ""));
if (game == "cf1")
mDefaultGame = eGame::CF1;
if (game == "cf2")
mDefaultGame = eGame::CF2;
auto maxsprite = ini.get("maxsprite", 0);
if (maxsprite)
mSpritesMax = maxsprite;
auto maxspawn = ini.get("maxspawn", 0);
if (maxspawn)
mSpawnEnemyMax = maxspawn;
if (mSpritesMax < MIN_SPRITES_MAX)
mSpritesMax = MIN_SPRITES_MAX;
if (mSpritesMax > MAX_SPRITES_MAX)
mSpritesMax = MAX_SPRITES_MAX;
}
}
// Section: Skip
{
if (ini.select("skip")) {
if (ini.get("intro", "false") == "true")
mSkipIntro = true;
if (ini.get("intro-video", "false") == "true")
mDisableIntroVideo = true;
if (ini.get("briefing", "false") == "true")
mSkipBriefing = true;
if (ini.get("service", "false") == "true")
mSkipService = true;
if (ini.get("hill", "false") == "true")
mSkipRecruit = true;
}
}
if (ini.select("paths")) {
for (auto& path : ini["paths"]) {
g_ResourceMan->addDir(path.second);
}
}
return true;
}