diff --git a/src/openrct2/cmdline/ScreenshotCommands.cpp b/src/openrct2/cmdline/ScreenshotCommands.cpp index 97b7e0bfa4..2bd0b72428 100644 --- a/src/openrct2/cmdline/ScreenshotCommands.cpp +++ b/src/openrct2/cmdline/ScreenshotCommands.cpp @@ -17,18 +17,33 @@ #include "../interface/Screenshot.h" #include "CommandLine.hpp" +extern "C" +{ + sint32 gScreenshotWeather = 0; +} + +static uint32 _weather = 0; + +static const CommandLineOptionDefinition ScreenshotOptions[] +{ + { CMDLINE_TYPE_INTEGER, &_weather, NAC, "weather", "weather to be used (0 = default, 1 = sunny, ..., 6 = thunder)." }, + OptionTableEnd +}; + static exitcode_t HandleScreenshot(CommandLineArgEnumerator *argEnumerator); const CommandLineCommand CommandLine::ScreenshotCommands[] { // Main commands - DefineCommand("", " [ ]", nullptr, HandleScreenshot), - DefineCommand("", " giant ", nullptr, HandleScreenshot), + DefineCommand("", " [ ]", ScreenshotOptions, HandleScreenshot), + DefineCommand("", " giant ", ScreenshotOptions, HandleScreenshot), CommandTableEnd }; static exitcode_t HandleScreenshot(CommandLineArgEnumerator *argEnumerator) { + gScreenshotWeather = _weather; + const char * * argv = (const char * *)argEnumerator->GetArguments() + argEnumerator->GetIndex(); sint32 argc = argEnumerator->GetCount() - argEnumerator->GetIndex(); sint32 result = cmdline_for_screenshot(argv, argc); diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 6983860660..39d16949df 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -348,17 +348,28 @@ sint32 cmdline_for_gfxbench(const char **argv, sint32 argc) sint32 cmdline_for_screenshot(const char **argv, sint32 argc) { - bool giantScreenshot = (argc == 5 || argc == 6) && _stricmp(argv[2], "giant") == 0; - if (argc != 4 && argc != 5 && argc != 8 && argc != 9 && !giantScreenshot) { - printf("Usage: openrct2 screenshot [ ] []\n"); - printf("Usage: openrct2 screenshot giant []\n"); + // Don't include options in the count (they have been handled by CommandLine::ParseOptions already) + for (sint32 i = 0; i < argc; i++) + { + if (argv[i][0] == '-') + { + // Setting argc to i works, because options can only be at the end of the command + argc = i; + break; + } + } + + bool giantScreenshot = (argc == 5) && _stricmp(argv[2], "giant") == 0; + if (argc != 4 && argc != 8 && !giantScreenshot) { + std::printf("Usage: openrct2 screenshot [ ]\n"); + std::printf("Usage: openrct2 screenshot giant \n"); return -1; } bool customLocation = false; bool centreMapX = false; bool centreMapY = false; - sint32 resolutionWidth, resolutionHeight, customX = 0, customY = 0, customZoom, customRotation = 0, customWeather = -1; + sint32 resolutionWidth, resolutionHeight, customX = 0, customY = 0, customZoom, customRotation = 0; const char *inputPath = argv[0]; const char *outputPath = argv[1]; @@ -371,20 +382,19 @@ sint32 cmdline_for_screenshot(const char **argv, sint32 argc) centreMapY = true; customZoom = atoi(argv[3]); customRotation = atoi(argv[4]) & 3; - if (argc == 6) - customWeather = atoi(argv[5]); } else { resolutionWidth = atoi(argv[2]); resolutionHeight = atoi(argv[3]); - if (argc >= 8) + if (argc == 8) { customLocation = true; if (argv[4][0] == 'c') centreMapX = true; else customX = atoi(argv[4]); + if (argv[5][0] == 'c') centreMapY = true; else @@ -392,14 +402,10 @@ sint32 cmdline_for_screenshot(const char **argv, sint32 argc) customZoom = atoi(argv[6]); customRotation = atoi(argv[7]) & 3; - if (argc == 9) - customWeather = atoi(argv[8]); } else { customZoom = 0; - if (argc == 5) - customWeather = atoi(argv[4]); } } @@ -408,7 +414,18 @@ sint32 cmdline_for_screenshot(const char **argv, sint32 argc) if (context->Initialise()) { drawing_engine_init(); - context->LoadParkFromFile(inputPath); + + try + { + context->LoadParkFromFile(inputPath); + } + catch (const std::exception &e) + { + std::printf("%s", e.what()); + drawing_engine_dispose(); + delete context; + return -1; + } gIntroState = INTRO_STATE_NONE; gScreenFlags = SCREEN_FLAGS_PLAYING; @@ -470,14 +487,15 @@ sint32 cmdline_for_screenshot(const char **argv, sint32 argc) gCurrentRotation = gSavedViewRotation; } - if (customWeather != -1) + if (gScreenshotWeather != 0) { - if (customWeather < -1 || customWeather >= 6) + if (gScreenshotWeather < 1 || gScreenshotWeather > 6) { - printf("Weather can only be set to an integer value from 0 till 5."); + printf("Weather can only be set to an integer value from 1 till 6."); return -1; } + uint8 customWeather = gScreenshotWeather - 1; climate_force_weather(customWeather); } diff --git a/src/openrct2/interface/Screenshot.h b/src/openrct2/interface/Screenshot.h index e7cd27d944..9382afc901 100644 --- a/src/openrct2/interface/Screenshot.h +++ b/src/openrct2/interface/Screenshot.h @@ -25,6 +25,7 @@ extern "C" { #endif extern uint8 gScreenshotCountdown; + extern sint32 gScreenshotWeather; void screenshot_check(); sint32 screenshot_dump();