2014-04-02 00:31:55 +01:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 OpenRCT2 developers
|
2015-10-09 18:22:37 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2015-10-09 18:22:37 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2014-04-02 00:31:55 +01:00
|
|
|
*****************************************************************************/
|
2015-10-09 18:22:37 +02:00
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
#include "Game.h"
|
|
|
|
|
|
2017-12-13 13:02:24 +01:00
|
|
|
#include "Cheats.h"
|
2017-03-26 21:42:07 +01:00
|
|
|
#include "Context.h"
|
2018-06-22 23:25:16 +02:00
|
|
|
#include "Editor.h"
|
|
|
|
|
#include "FileClassifier.h"
|
2019-05-11 21:31:34 +02:00
|
|
|
#include "GameStateSnapshots.h"
|
2018-06-22 23:25:16 +02:00
|
|
|
#include "Input.h"
|
|
|
|
|
#include "OpenRCT2.h"
|
|
|
|
|
#include "ParkImporter.h"
|
2020-03-31 23:12:35 +02:00
|
|
|
#include "PlatformEnvironment.h"
|
2018-12-06 06:34:27 +01:00
|
|
|
#include "ReplayManager.h"
|
2020-12-09 23:39:10 -07:00
|
|
|
#include "actions/LoadOrQuitAction.h"
|
2018-06-22 23:25:16 +02:00
|
|
|
#include "audio/audio.h"
|
|
|
|
|
#include "config/Config.h"
|
2021-02-13 02:50:29 +00:00
|
|
|
#include "core/Console.hpp"
|
2018-01-06 18:52:12 +00:00
|
|
|
#include "core/FileScanner.h"
|
2020-03-31 23:12:35 +02:00
|
|
|
#include "core/Path.hpp"
|
2020-05-28 22:37:50 +01:00
|
|
|
#include "interface/Colour.h"
|
2017-06-08 23:02:39 +01:00
|
|
|
#include "interface/Screenshot.h"
|
2018-01-05 23:45:53 +00:00
|
|
|
#include "interface/Viewport.h"
|
2018-01-06 00:05:16 +00:00
|
|
|
#include "interface/Window.h"
|
2018-01-06 18:32:25 +01:00
|
|
|
#include "localisation/Localisation.h"
|
2017-10-06 22:37:06 +02:00
|
|
|
#include "management/Finance.h"
|
2017-10-11 21:38:26 +02:00
|
|
|
#include "management/Marketing.h"
|
|
|
|
|
#include "management/NewsItem.h"
|
2017-10-05 16:22:37 +02:00
|
|
|
#include "management/Research.h"
|
2015-02-12 11:30:57 +00:00
|
|
|
#include "network/network.h"
|
2018-01-02 20:36:42 +01:00
|
|
|
#include "object/Object.h"
|
2018-06-22 23:25:16 +02:00
|
|
|
#include "object/ObjectList.h"
|
2017-10-13 10:06:36 +02:00
|
|
|
#include "peep/Peep.h"
|
|
|
|
|
#include "peep/Staff.h"
|
2020-06-28 15:46:14 -04:00
|
|
|
#include "platform/Platform2.h"
|
2018-01-09 10:40:42 +01:00
|
|
|
#include "rct1/RCT1.h"
|
2017-12-31 13:21:34 +01:00
|
|
|
#include "ride/Ride.h"
|
2018-01-18 22:33:06 +00:00
|
|
|
#include "ride/RideRatings.h"
|
2018-02-09 23:49:50 +01:00
|
|
|
#include "ride/Station.h"
|
2017-10-17 13:51:47 +02:00
|
|
|
#include "ride/Track.h"
|
2017-09-01 13:38:21 +02:00
|
|
|
#include "ride/TrackDesign.h"
|
2017-10-11 23:32:15 +02:00
|
|
|
#include "ride/Vehicle.h"
|
2018-01-02 17:58:43 +00:00
|
|
|
#include "scenario/Scenario.h"
|
2020-02-06 23:15:20 +00:00
|
|
|
#include "scripting/ScriptEngine.h"
|
2016-11-21 00:16:47 +00:00
|
|
|
#include "title/TitleScreen.h"
|
2018-06-02 00:07:14 +01:00
|
|
|
#include "ui/UiContext.h"
|
|
|
|
|
#include "ui/WindowManager.h"
|
2017-12-13 13:02:24 +01:00
|
|
|
#include "util/SawyerCoding.h"
|
|
|
|
|
#include "util/Util.h"
|
2017-10-19 10:01:05 +02:00
|
|
|
#include "windows/Intent.h"
|
2017-12-14 10:34:12 +01:00
|
|
|
#include "world/Banner.h"
|
2017-03-11 11:24:18 +00:00
|
|
|
#include "world/Climate.h"
|
2017-12-14 10:34:12 +01:00
|
|
|
#include "world/Entrance.h"
|
2018-01-11 10:59:26 +01:00
|
|
|
#include "world/Footpath.h"
|
2018-01-03 14:56:08 +01:00
|
|
|
#include "world/Map.h"
|
2018-01-11 10:59:26 +01:00
|
|
|
#include "world/MapAnimation.h"
|
2017-12-31 21:40:00 +01:00
|
|
|
#include "world/Park.h"
|
2018-01-11 10:59:26 +01:00
|
|
|
#include "world/Scenery.h"
|
|
|
|
|
#include "world/Sprite.h"
|
2018-05-01 16:33:16 +02:00
|
|
|
#include "world/Surface.h"
|
2018-01-11 10:59:26 +01:00
|
|
|
#include "world/Water.h"
|
2018-06-22 23:25:16 +02:00
|
|
|
|
2018-08-12 12:50:40 +01:00
|
|
|
#include <algorithm>
|
2020-04-12 11:32:39 +02:00
|
|
|
#include <cstdio>
|
2018-11-21 23:16:04 +01:00
|
|
|
#include <iterator>
|
2018-06-22 23:25:16 +02:00
|
|
|
#include <memory>
|
2016-01-04 16:22:15 +01:00
|
|
|
|
2018-12-01 16:36:00 +01:00
|
|
|
uint16_t gCurrentDeltaTime;
|
2018-06-22 23:25:16 +02:00
|
|
|
uint8_t gGamePaused = 0;
|
|
|
|
|
int32_t gGameSpeed = 1;
|
2018-09-23 23:40:47 +02:00
|
|
|
bool gDoSingleUpdate = false;
|
2018-06-22 23:25:16 +02:00
|
|
|
float gDayNightCycle = 0;
|
|
|
|
|
bool gInUpdateCode = false;
|
|
|
|
|
bool gInMapInitCode = false;
|
2018-12-15 18:39:00 +00:00
|
|
|
std::string gCurrentLoadedPath;
|
2014-07-26 10:30:55 +01:00
|
|
|
|
2017-10-30 07:07:01 -04:00
|
|
|
bool gLoadKeepWindowsOpen = false;
|
|
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t gCurrentTicks;
|
2018-12-01 16:36:00 +01:00
|
|
|
uint32_t gCurrentRealTimeTicks;
|
2016-09-03 20:25:19 +00:00
|
|
|
|
2016-04-15 17:54:46 +01:00
|
|
|
rct_string_id gGameCommandErrorTitle;
|
|
|
|
|
rct_string_id gGameCommandErrorText;
|
|
|
|
|
|
2017-07-22 23:19:09 +00:00
|
|
|
using namespace OpenRCT2;
|
|
|
|
|
|
2020-03-22 23:22:28 +01:00
|
|
|
void game_reset_speed()
|
|
|
|
|
{
|
|
|
|
|
gGameSpeed = 1;
|
|
|
|
|
window_invalidate_by_class(WC_TOP_TOOLBAR);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-05 18:50:51 +00:00
|
|
|
void game_increase_game_speed()
|
|
|
|
|
{
|
2018-06-20 17:11:35 +02:00
|
|
|
gGameSpeed = std::min(gConfigGeneral.debugging_tools ? 5 : 4, gGameSpeed + 1);
|
2017-06-06 23:24:18 +02:00
|
|
|
if (gGameSpeed == 5)
|
|
|
|
|
gGameSpeed = 8;
|
|
|
|
|
window_invalidate_by_class(WC_TOP_TOOLBAR);
|
2014-11-05 18:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void game_reduce_game_speed()
|
|
|
|
|
{
|
2018-06-20 17:11:35 +02:00
|
|
|
gGameSpeed = std::max(1, gGameSpeed - 1);
|
2017-06-06 23:24:18 +02:00
|
|
|
if (gGameSpeed == 7)
|
|
|
|
|
gGameSpeed = 4;
|
|
|
|
|
window_invalidate_by_class(WC_TOP_TOOLBAR);
|
2014-11-05 18:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-11 02:42:39 +01:00
|
|
|
/**
|
2015-10-09 18:22:37 +02:00
|
|
|
*
|
2014-04-11 02:42:39 +01:00
|
|
|
* rct2: 0x0066B5C0 (part of 0x0066B3E8)
|
|
|
|
|
*/
|
|
|
|
|
void game_create_windows()
|
|
|
|
|
{
|
2017-08-12 23:06:12 +02:00
|
|
|
context_open_window(WC_MAIN_WINDOW);
|
2017-11-11 02:57:45 +01:00
|
|
|
context_open_window(WC_TOP_TOOLBAR);
|
2017-11-15 02:11:25 +01:00
|
|
|
context_open_window(WC_BOTTOM_TOOLBAR);
|
2017-06-06 23:24:18 +02:00
|
|
|
window_resize_gui(context_get_width(), context_get_height());
|
2014-04-11 02:42:39 +01:00
|
|
|
}
|
|
|
|
|
|
2017-11-30 18:19:26 +01:00
|
|
|
enum
|
|
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
SPR_GAME_PALETTE_DEFAULT = 1532,
|
|
|
|
|
SPR_GAME_PALETTE_WATER = 1533,
|
2017-06-06 23:24:18 +02:00
|
|
|
SPR_GAME_PALETTE_WATER_DARKER_1 = 1534,
|
|
|
|
|
SPR_GAME_PALETTE_WATER_DARKER_2 = 1535,
|
2018-06-22 23:25:16 +02:00
|
|
|
SPR_GAME_PALETTE_3 = 1536,
|
|
|
|
|
SPR_GAME_PALETTE_3_DARKER_1 = 1537,
|
|
|
|
|
SPR_GAME_PALETTE_3_DARKER_2 = 1538,
|
|
|
|
|
SPR_GAME_PALETTE_4 = 1539,
|
|
|
|
|
SPR_GAME_PALETTE_4_DARKER_1 = 1540,
|
|
|
|
|
SPR_GAME_PALETTE_4_DARKER_2 = 1541,
|
2016-11-10 13:21:47 +01:00
|
|
|
};
|
|
|
|
|
|
2014-07-20 02:46:29 -04:00
|
|
|
/**
|
2018-06-22 23:25:16 +02:00
|
|
|
*
|
|
|
|
|
* rct2: 0x006838BD
|
|
|
|
|
*/
|
2014-09-23 13:33:55 -06:00
|
|
|
void update_palette_effects()
|
2014-07-20 02:46:29 -04:00
|
|
|
{
|
2020-11-09 10:36:37 +01:00
|
|
|
auto water_type = static_cast<rct_water_type*>(object_entry_get_chunk(ObjectType::Water, 0));
|
2015-03-01 21:06:51 +00:00
|
|
|
|
2017-11-30 18:19:26 +01:00
|
|
|
if (gClimateLightningFlash == 1)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Change palette to lighter colour during lightning
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t palette = SPR_GAME_PALETTE_DEFAULT;
|
2015-03-01 21:06:51 +00:00
|
|
|
|
2017-11-30 18:21:12 +01:00
|
|
|
if (water_type != nullptr)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
palette = water_type->image_id;
|
|
|
|
|
}
|
2018-06-22 23:25:16 +02:00
|
|
|
const rct_g1_element* g1 = gfx_get_g1_element(palette);
|
2017-11-30 18:21:12 +01:00
|
|
|
if (g1 != nullptr)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t xoffset = g1->x_offset;
|
2017-10-26 13:14:37 +01:00
|
|
|
xoffset = xoffset * 4;
|
2018-06-22 23:25:16 +02:00
|
|
|
uint8_t* paletteOffset = gGamePalette + xoffset;
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t i = 0; i < g1->width; i++)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
|
|
|
|
paletteOffset[(i * 4) + 0] = -((0xFF - g1->offset[(i * 3) + 0]) / 2) - 1;
|
|
|
|
|
paletteOffset[(i * 4) + 1] = -((0xFF - g1->offset[(i * 3) + 1]) / 2) - 1;
|
|
|
|
|
paletteOffset[(i * 4) + 2] = -((0xFF - g1->offset[(i * 3) + 2]) / 2) - 1;
|
|
|
|
|
}
|
2020-05-28 22:37:50 +01:00
|
|
|
platform_update_palette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
gClimateLightningFlash++;
|
2017-11-30 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (gClimateLightningFlash == 2)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Change palette back to normal after lightning
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t palette = SPR_GAME_PALETTE_DEFAULT;
|
2015-03-01 21:06:51 +00:00
|
|
|
|
2017-11-30 18:21:12 +01:00
|
|
|
if (water_type != nullptr)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
palette = water_type->image_id;
|
|
|
|
|
}
|
2015-03-01 21:06:51 +00:00
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
const rct_g1_element* g1 = gfx_get_g1_element(palette);
|
2017-11-30 18:21:12 +01:00
|
|
|
if (g1 != nullptr)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t xoffset = g1->x_offset;
|
2017-10-26 13:14:37 +01:00
|
|
|
xoffset = xoffset * 4;
|
2018-06-22 23:25:16 +02:00
|
|
|
uint8_t* paletteOffset = gGamePalette + xoffset;
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t i = 0; i < g1->width; i++)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
|
|
|
|
paletteOffset[(i * 4) + 0] = g1->offset[(i * 3) + 0];
|
|
|
|
|
paletteOffset[(i * 4) + 1] = g1->offset[(i * 3) + 1];
|
|
|
|
|
paletteOffset[(i * 4) + 2] = g1->offset[(i * 3) + 2];
|
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-07-20 02:46:29 -04:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Animate the water/lava/chain movement palette
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t shade = 0;
|
2017-11-30 18:19:26 +01:00
|
|
|
if (gConfigGeneral.render_weather_gloom)
|
|
|
|
|
{
|
2018-01-12 22:53:41 +00:00
|
|
|
auto paletteId = climate_get_weather_gloom_palette_id(gClimateCurrent);
|
2020-12-05 19:13:59 +01:00
|
|
|
if (paletteId != FilterPaletteID::PaletteNull)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
shade = 1;
|
2020-12-05 19:13:59 +01:00
|
|
|
if (paletteId != FilterPaletteID::PaletteDarken1)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
shade = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t j = gPaletteEffectFrame;
|
2020-04-17 16:36:25 -03:00
|
|
|
j = ((static_cast<uint16_t>((~j / 2) * 128) * 15) >> 16);
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t waterId = SPR_GAME_PALETTE_WATER;
|
2017-11-30 18:21:12 +01:00
|
|
|
if (water_type != nullptr)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
waterId = water_type->palette_index_1;
|
|
|
|
|
}
|
2018-06-22 23:25:16 +02:00
|
|
|
const rct_g1_element* g1 = gfx_get_g1_element(shade + waterId);
|
2017-11-30 18:21:12 +01:00
|
|
|
if (g1 != nullptr)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
uint8_t* vs = &g1->offset[j * 3];
|
2020-05-28 22:37:50 +01:00
|
|
|
uint8_t* vd = &gGamePalette[PALETTE_OFFSET_WATER_WAVES * 4];
|
|
|
|
|
int32_t n = PALETTE_LENGTH_WATER_WAVES;
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t i = 0; i < n; i++)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
|
|
|
|
vd[0] = vs[0];
|
|
|
|
|
vd[1] = vs[1];
|
|
|
|
|
vd[2] = vs[2];
|
|
|
|
|
vs += 9;
|
|
|
|
|
if (vs >= &g1->offset[9 * n])
|
|
|
|
|
{
|
|
|
|
|
vs -= 9 * n;
|
|
|
|
|
}
|
|
|
|
|
vd += 4;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-07-20 02:46:29 -04:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
waterId = SPR_GAME_PALETTE_3;
|
2017-11-30 18:21:12 +01:00
|
|
|
if (water_type != nullptr)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
waterId = water_type->palette_index_2;
|
|
|
|
|
}
|
2017-11-30 18:24:44 +01:00
|
|
|
g1 = gfx_get_g1_element(shade + waterId);
|
2017-11-30 18:21:12 +01:00
|
|
|
if (g1 != nullptr)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
uint8_t* vs = &g1->offset[j * 3];
|
2020-05-28 22:37:50 +01:00
|
|
|
uint8_t* vd = &gGamePalette[PALETTE_OFFSET_WATER_SPARKLES * 4];
|
|
|
|
|
int32_t n = PALETTE_LENGTH_WATER_SPARKLES;
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t i = 0; i < n; i++)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
|
|
|
|
vd[0] = vs[0];
|
|
|
|
|
vd[1] = vs[1];
|
|
|
|
|
vd[2] = vs[2];
|
|
|
|
|
vs += 9;
|
|
|
|
|
if (vs >= &g1->offset[9 * n])
|
|
|
|
|
{
|
|
|
|
|
vs -= 9 * n;
|
|
|
|
|
}
|
|
|
|
|
vd += 4;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-07-20 02:46:29 -04:00
|
|
|
|
2020-04-17 16:36:25 -03:00
|
|
|
j = (static_cast<uint16_t>(gPaletteEffectFrame * -960) * 3) >> 16;
|
2017-06-06 23:24:18 +02:00
|
|
|
waterId = SPR_GAME_PALETTE_4;
|
2018-06-22 23:25:16 +02:00
|
|
|
g1 = gfx_get_g1_element(shade + waterId);
|
2017-11-30 18:21:12 +01:00
|
|
|
if (g1 != nullptr)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
uint8_t* vs = &g1->offset[j * 3];
|
2020-05-28 22:37:50 +01:00
|
|
|
uint8_t* vd = &gGamePalette[PALETTE_INDEX_243 * 4];
|
2018-06-22 23:25:16 +02:00
|
|
|
int32_t n = 3;
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t i = 0; i < n; i++)
|
2017-10-26 13:14:37 +01:00
|
|
|
{
|
|
|
|
|
vd[0] = vs[0];
|
|
|
|
|
vd[1] = vs[1];
|
|
|
|
|
vd[2] = vs[2];
|
|
|
|
|
vs += 3;
|
2017-11-30 18:19:26 +01:00
|
|
|
if (vs >= &g1->offset[3 * n])
|
|
|
|
|
{
|
2017-10-26 13:14:37 +01:00
|
|
|
vs -= 3 * n;
|
|
|
|
|
}
|
|
|
|
|
vd += 4;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-07-20 02:46:29 -04:00
|
|
|
|
2020-05-28 22:37:50 +01:00
|
|
|
platform_update_palette(gGamePalette, PALETTE_OFFSET_ANIMATED, PALETTE_LENGTH_ANIMATED);
|
2017-11-30 18:19:26 +01:00
|
|
|
if (gClimateLightningFlash == 2)
|
|
|
|
|
{
|
2020-05-28 22:37:50 +01:00
|
|
|
platform_update_palette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC);
|
2017-06-06 23:24:18 +02:00
|
|
|
gClimateLightningFlash = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-20 02:46:29 -04:00
|
|
|
}
|
2014-08-05 19:15:28 +02:00
|
|
|
|
2015-03-31 02:21:30 +01:00
|
|
|
void pause_toggle()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
gGamePaused ^= GAME_PAUSED_NORMAL;
|
|
|
|
|
window_invalidate_by_class(WC_TOP_TOOLBAR);
|
2017-11-30 18:19:26 +01:00
|
|
|
if (gGamePaused & GAME_PAUSED_NORMAL)
|
|
|
|
|
{
|
2020-10-07 00:34:42 +03:00
|
|
|
OpenRCT2::Audio::StopAll();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2015-03-31 02:21:30 +01:00
|
|
|
}
|
2014-08-05 19:15:28 +02:00
|
|
|
|
2016-04-23 13:34:55 +01:00
|
|
|
bool game_is_paused()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return gGamePaused != 0;
|
2016-04-23 13:34:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool game_is_not_paused()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return gGamePaused == 0;
|
2016-04-23 13:34:55 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 22:21:08 +01:00
|
|
|
/**
|
2014-11-20 18:40:10 +00:00
|
|
|
*
|
2014-05-02 22:21:08 +01:00
|
|
|
* rct2: 0x0066DC0F
|
|
|
|
|
*/
|
|
|
|
|
static void load_landscape()
|
|
|
|
|
{
|
2018-02-05 22:59:44 +01:00
|
|
|
auto intent = Intent(WC_LOADSAVE);
|
|
|
|
|
intent.putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE);
|
|
|
|
|
context_open_intent(&intent);
|
2014-05-02 22:21:08 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
void utf8_to_rct2_self(char* buffer, size_t length)
|
2016-03-13 15:33:38 +00:00
|
|
|
{
|
2018-04-14 18:06:49 +01:00
|
|
|
auto temp = utf8_to_rct2(buffer);
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
size_t i = 0;
|
|
|
|
|
const char* src = temp.data();
|
|
|
|
|
char* dst = buffer;
|
2017-11-30 18:19:26 +01:00
|
|
|
while (*src != 0 && i < length - 1)
|
|
|
|
|
{
|
2020-04-17 16:36:25 -03:00
|
|
|
if (*src == static_cast<char>(static_cast<uint8_t>(0xFF)))
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
|
|
|
|
if (i < length - 3)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*dst++ = *src++;
|
|
|
|
|
*dst++ = *src++;
|
|
|
|
|
*dst++ = *src++;
|
2017-11-30 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
i += 3;
|
2017-11-30 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*dst++ = *src++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-30 18:19:26 +01:00
|
|
|
do
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
*dst++ = '\0';
|
|
|
|
|
i++;
|
2018-06-22 23:25:16 +02:00
|
|
|
} while (i < length);
|
2016-03-13 15:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
void rct2_to_utf8_self(char* buffer, size_t length)
|
2016-03-13 15:33:38 +00:00
|
|
|
{
|
2017-11-30 18:19:26 +01:00
|
|
|
if (length > 0)
|
|
|
|
|
{
|
2020-12-23 01:43:27 -03:00
|
|
|
auto temp = rct2_to_utf8(buffer, RCT2LanguageId::EnglishUK);
|
2018-04-14 18:06:49 +01:00
|
|
|
safe_strcpy(buffer, temp.data(), length);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-03-13 15:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 23:57:43 +01:00
|
|
|
/**
|
|
|
|
|
* Converts all the user strings and news item strings to UTF-8.
|
|
|
|
|
*/
|
|
|
|
|
void game_convert_strings_to_utf8()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Scenario details
|
2020-12-23 01:43:27 -03:00
|
|
|
gScenarioCompletedBy = rct2_to_utf8(gScenarioCompletedBy, RCT2LanguageId::EnglishUK);
|
|
|
|
|
gScenarioName = rct2_to_utf8(gScenarioName, RCT2LanguageId::EnglishUK);
|
|
|
|
|
gScenarioDetails = rct2_to_utf8(gScenarioDetails, RCT2LanguageId::EnglishUK);
|
2015-07-29 23:57:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts all the user strings and news item strings to RCT2 encoding.
|
|
|
|
|
*/
|
2018-06-22 23:25:16 +02:00
|
|
|
void game_convert_strings_to_rct2(rct_s6_data* s6)
|
2015-07-29 23:57:43 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Scenario details
|
|
|
|
|
utf8_to_rct2_self(s6->scenario_completed_name, sizeof(s6->scenario_completed_name));
|
|
|
|
|
utf8_to_rct2_self(s6->scenario_name, sizeof(s6->scenario_name));
|
|
|
|
|
utf8_to_rct2_self(s6->scenario_description, sizeof(s6->scenario_description));
|
2015-07-29 23:57:43 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// User strings
|
2018-06-22 23:25:16 +02:00
|
|
|
for (auto* userString : s6->custom_strings)
|
2017-11-23 15:52:06 +01:00
|
|
|
{
|
|
|
|
|
if (!str_is_null_or_empty(userString))
|
|
|
|
|
{
|
|
|
|
|
utf8_to_rct2_self(userString, RCT12_USER_STRING_MAX_LENGTH);
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-29 23:57:43 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-07 20:53:55 +02:00
|
|
|
// OpenRCT2 workaround to recalculate some values which are saved redundantly in the save to fix corrupted files.
|
|
|
|
|
// For example recalculate guest count by looking at all the guests instead of trusting the value in the file.
|
2017-07-05 18:18:40 +02:00
|
|
|
void game_fix_save_vars()
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
// Recalculates peep count after loading a save to fix corrupted files
|
2020-06-10 17:54:34 +01:00
|
|
|
uint32_t guestCount = 0;
|
2017-11-30 18:24:44 +01:00
|
|
|
{
|
2021-03-16 11:18:06 +00:00
|
|
|
for (auto guest : EntityList<Guest>())
|
2020-06-10 17:54:34 +01:00
|
|
|
{
|
|
|
|
|
if (!guest->OutsideOfPark)
|
|
|
|
|
{
|
|
|
|
|
guestCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-30 18:24:44 +01:00
|
|
|
}
|
2015-10-07 20:53:55 +02:00
|
|
|
|
2020-06-10 17:54:34 +01:00
|
|
|
gNumGuestsInPark = guestCount;
|
2015-10-30 06:44:19 -05:00
|
|
|
|
2018-02-10 20:24:50 +01:00
|
|
|
// Peeps to remove have to be cached here, as removing them from within the loop breaks iteration
|
2019-02-28 19:28:58 +00:00
|
|
|
std::vector<Peep*> peepsToRemove;
|
2018-02-10 20:24:50 +01:00
|
|
|
|
2018-02-09 22:43:31 +01:00
|
|
|
// Fix possibly invalid field values
|
2021-03-16 11:18:06 +00:00
|
|
|
for (auto peep : EntityList<Guest>())
|
2018-02-09 22:43:31 +01:00
|
|
|
{
|
2020-06-07 22:18:17 -03:00
|
|
|
if (peep->CurrentRideStation >= MAX_STATIONS)
|
2018-02-09 22:43:31 +01:00
|
|
|
{
|
2020-06-08 14:04:07 +02:00
|
|
|
const auto srcStation = peep->CurrentRideStation;
|
|
|
|
|
const auto rideIdx = peep->CurrentRide;
|
2018-02-10 20:24:50 +01:00
|
|
|
if (rideIdx == RIDE_ID_NULL)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-11-09 17:00:09 +01:00
|
|
|
Ride* ride = get_ride(rideIdx);
|
|
|
|
|
if (ride == nullptr)
|
|
|
|
|
{
|
2020-06-10 17:54:34 +01:00
|
|
|
log_warning("Couldn't find ride %u, resetting ride on peep %u", rideIdx, peep->sprite_index);
|
2020-06-07 22:21:53 -03:00
|
|
|
peep->CurrentRide = RIDE_ID_NULL;
|
2019-11-09 17:00:09 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2019-07-21 20:44:19 +01:00
|
|
|
auto curName = peep->GetName();
|
2019-07-21 22:52:53 +01:00
|
|
|
log_warning(
|
2020-06-10 17:54:34 +01:00
|
|
|
"Peep %u (%s) has invalid ride station = %u for ride %u.", peep->sprite_index, curName.c_str(), srcStation,
|
|
|
|
|
rideIdx);
|
2020-03-21 15:11:50 +01:00
|
|
|
auto station = ride_get_first_valid_station_exit(ride);
|
|
|
|
|
if (station == STATION_INDEX_NULL)
|
2018-02-09 23:49:50 +01:00
|
|
|
{
|
2020-06-10 17:54:34 +01:00
|
|
|
log_warning("Couldn't find station, removing peep %u", peep->sprite_index);
|
2018-02-10 20:24:50 +01:00
|
|
|
peepsToRemove.push_back(peep);
|
2018-06-22 23:25:16 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-02-09 23:49:50 +01:00
|
|
|
log_warning("Amending ride station to %u.", station);
|
2020-06-07 22:18:17 -03:00
|
|
|
peep->CurrentRideStation = station;
|
2018-02-09 23:49:50 +01:00
|
|
|
}
|
2018-02-09 22:43:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-20 20:39:47 +02:00
|
|
|
if (!peepsToRemove.empty())
|
2018-03-10 07:39:57 +00:00
|
|
|
{
|
|
|
|
|
// Some broken saves have broken spatial indexes
|
|
|
|
|
reset_sprite_spatial_index();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 20:24:50 +01:00
|
|
|
for (auto ptr : peepsToRemove)
|
|
|
|
|
{
|
2018-03-27 21:04:57 +01:00
|
|
|
ptr->Remove();
|
2018-02-10 20:24:50 +01:00
|
|
|
}
|
|
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Fixes broken saves where a surface element could be null
|
2017-07-05 18:18:40 +02:00
|
|
|
// and broken saves with incorrect invisible map border tiles
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2019-12-18 00:25:12 -03:00
|
|
|
auto* surfaceElement = map_get_surface_element_at(TileCoordsXY{ x, y }.ToCoordsXY());
|
2015-10-30 06:44:19 -05:00
|
|
|
|
2019-08-11 09:06:04 +01:00
|
|
|
if (surfaceElement == nullptr)
|
2017-06-06 23:24:18 +02:00
|
|
|
{
|
|
|
|
|
log_error("Null map element at x = %d and y = %d. Fixing...", x, y);
|
2021-02-04 18:21:17 +02:00
|
|
|
surfaceElement = TileElementInsert<SurfaceElement>(TileCoordsXYZ{ x, y, 14 }.ToCoordsXYZ(), 0b0000);
|
|
|
|
|
if (surfaceElement == nullptr)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
log_error("Unable to fix: Map element limit reached.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-05 18:18:40 +02:00
|
|
|
|
|
|
|
|
// Fix the invisible border tiles.
|
2019-08-11 09:06:04 +01:00
|
|
|
// At this point, we can be sure that surfaceElement is not NULL.
|
2017-11-30 18:19:26 +01:00
|
|
|
if (x == 0 || x == gMapSize - 1 || y == 0 || y == gMapSize - 1)
|
2017-07-05 18:18:40 +02:00
|
|
|
{
|
2020-03-07 21:07:18 +01:00
|
|
|
surfaceElement->SetBaseZ(MINIMUM_LAND_HEIGHT_BIG);
|
|
|
|
|
surfaceElement->SetClearanceZ(MINIMUM_LAND_HEIGHT_BIG);
|
2019-08-11 09:06:04 +01:00
|
|
|
surfaceElement->SetSlope(0);
|
|
|
|
|
surfaceElement->SetWaterHeight(0);
|
2017-07-05 18:18:40 +02:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-01 14:56:44 +01:00
|
|
|
|
2018-01-02 19:40:08 +01:00
|
|
|
research_fix();
|
2017-06-29 18:06:26 +02:00
|
|
|
|
|
|
|
|
// Fix banner list pointing to NULL map elements
|
|
|
|
|
banner_reset_broken_index();
|
2017-07-06 02:20:51 +01:00
|
|
|
|
2018-02-24 16:33:11 +01:00
|
|
|
// Fix banners which share their index
|
|
|
|
|
fix_duplicated_banners();
|
|
|
|
|
|
2017-07-06 02:20:51 +01:00
|
|
|
// Fix invalid vehicle sprite sizes, thus preventing visual corruption of sprites
|
|
|
|
|
fix_invalid_vehicle_sprite_sizes();
|
2017-10-22 23:22:46 +02:00
|
|
|
|
2017-10-31 12:57:40 +01:00
|
|
|
// Fix gParkEntrance locations for which the tile_element no longer exists
|
2017-10-22 23:22:46 +02:00
|
|
|
fix_park_entrance_locations();
|
2015-10-07 20:53:55 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-05 09:19:01 -06:00
|
|
|
void game_load_init()
|
|
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
rct_window* mainWindow;
|
2015-07-05 09:19:01 -06:00
|
|
|
|
2019-05-11 21:31:34 +02:00
|
|
|
IGameStateSnapshots* snapshots = GetContext()->GetGameStateSnapshots();
|
|
|
|
|
snapshots->Reset();
|
|
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gScreenFlags = SCREEN_FLAGS_PLAYING;
|
2020-10-07 00:34:42 +03:00
|
|
|
OpenRCT2::Audio::StopAll();
|
2017-10-30 07:07:01 -04:00
|
|
|
if (!gLoadKeepWindowsOpen)
|
|
|
|
|
{
|
|
|
|
|
viewport_init_all();
|
|
|
|
|
game_create_windows();
|
2017-11-02 20:16:30 -04:00
|
|
|
mainWindow = window_get_main();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mainWindow = window_get_main();
|
|
|
|
|
window_unfollow_sprite(mainWindow);
|
2017-10-30 07:07:01 -04:00
|
|
|
}
|
2014-05-04 16:21:15 +01:00
|
|
|
|
2018-06-02 00:07:14 +01:00
|
|
|
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
|
2020-02-21 20:32:51 -03:00
|
|
|
windowManager->SetMainView(gSavedView, gSavedViewZoom, gSavedViewRotation);
|
2014-05-04 16:21:15 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
if (network_get_mode() != NETWORK_MODE_CLIENT)
|
|
|
|
|
{
|
2019-08-20 23:51:12 +02:00
|
|
|
GameActions::ClearQueue();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2020-08-22 05:09:42 +01:00
|
|
|
reset_sprite_spatial_index();
|
2020-10-31 07:32:32 -04:00
|
|
|
reset_all_sprite_quadrant_placements();
|
2017-06-06 23:24:18 +02:00
|
|
|
scenery_set_default_placement_configuration();
|
2017-10-07 01:28:00 +02:00
|
|
|
|
2018-02-05 22:59:44 +01:00
|
|
|
auto intent = Intent(INTENT_ACTION_REFRESH_NEW_RIDES);
|
|
|
|
|
context_broadcast_intent(&intent);
|
2017-10-07 01:28:00 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
gWindowUpdateTicks = 0;
|
2014-05-04 16:21:15 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
load_palette();
|
2017-06-02 19:08:03 +01:00
|
|
|
|
2017-11-30 18:19:26 +01:00
|
|
|
if (!gOpenRCT2Headless)
|
|
|
|
|
{
|
2018-02-05 22:59:44 +01:00
|
|
|
intent = Intent(INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD);
|
|
|
|
|
context_broadcast_intent(&intent);
|
2017-06-06 23:24:18 +02:00
|
|
|
window_update_all();
|
|
|
|
|
}
|
2015-02-22 18:24:19 +00:00
|
|
|
|
2020-10-07 00:34:42 +03:00
|
|
|
OpenRCT2::Audio::StopTitleMusic();
|
2017-06-06 23:24:18 +02:00
|
|
|
gGameSpeed = 1;
|
2020-02-22 22:18:22 +00:00
|
|
|
}
|
2020-02-06 23:15:20 +00:00
|
|
|
|
2020-02-22 22:18:22 +00:00
|
|
|
void game_load_scripts()
|
|
|
|
|
{
|
2020-04-24 15:58:01 +01:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
2020-02-06 23:15:20 +00:00
|
|
|
GetContext()->GetScriptEngine().LoadPlugins();
|
2020-02-23 12:55:48 +00:00
|
|
|
#endif
|
2020-02-06 23:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-22 22:53:32 +01:00
|
|
|
void game_unload_scripts()
|
2020-02-06 23:15:20 +00:00
|
|
|
{
|
2020-04-24 15:58:01 +01:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
2020-02-06 23:15:20 +00:00
|
|
|
GetContext()->GetScriptEngine().UnloadPlugins();
|
2020-02-23 12:55:48 +00:00
|
|
|
#endif
|
2014-05-04 16:21:15 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-11 09:38:37 -06:00
|
|
|
/**
|
2014-06-21 15:50:13 +01:00
|
|
|
*
|
2015-12-11 09:38:37 -06:00
|
|
|
* rct2: 0x0069E9A7
|
2015-05-30 10:15:29 +01:00
|
|
|
* Call after a rotation or loading of a save to reset sprite quadrants
|
2014-06-21 15:50:13 +01:00
|
|
|
*/
|
2015-05-30 10:15:29 +01:00
|
|
|
void reset_all_sprite_quadrant_placements()
|
2014-11-23 23:03:45 +00:00
|
|
|
{
|
2021-02-24 23:34:34 +01:00
|
|
|
for (size_t i = 0; i < MAX_ENTITIES; i++)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2020-06-06 11:32:37 +01:00
|
|
|
auto* spr = GetEntity(i);
|
2021-03-17 08:04:41 +00:00
|
|
|
if (spr != nullptr && spr->Type != EntityType::Null)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2020-06-06 11:32:37 +01:00
|
|
|
spr->MoveTo({ spr->x, spr->y, spr->z });
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-21 15:50:13 +01:00
|
|
|
}
|
|
|
|
|
|
2015-08-22 11:56:32 +01:00
|
|
|
void save_game()
|
2014-05-27 23:33:16 +02:00
|
|
|
{
|
2017-11-30 18:19:26 +01:00
|
|
|
if (!gFirstTimeSaving)
|
|
|
|
|
{
|
2018-12-15 18:39:00 +00:00
|
|
|
save_game_with_name(gScenarioSavePath.c_str());
|
2017-11-30 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
save_game_as();
|
|
|
|
|
}
|
2015-08-19 21:54:25 +02:00
|
|
|
}
|
2017-09-12 00:04:03 +02:00
|
|
|
|
2018-10-14 22:36:41 +02:00
|
|
|
void save_game_cmd(const utf8* name /* = nullptr */)
|
|
|
|
|
{
|
|
|
|
|
if (name == nullptr)
|
|
|
|
|
{
|
2018-12-15 18:39:00 +00:00
|
|
|
save_game_with_name(gScenarioSavePath.c_str());
|
2018-10-14 22:36:41 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char savePath[MAX_PATH];
|
|
|
|
|
platform_get_user_directory(savePath, "save", sizeof(savePath));
|
|
|
|
|
safe_strcat_path(savePath, name, sizeof(savePath));
|
|
|
|
|
path_append_extension(savePath, ".sv6", sizeof(savePath));
|
|
|
|
|
save_game_with_name(savePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void save_game_with_name(const utf8* name)
|
|
|
|
|
{
|
|
|
|
|
log_verbose("Saving to %s", name);
|
|
|
|
|
if (scenario_save(name, 0x80000000 | (gConfigGeneral.save_plugin_data ? 1 : 0)))
|
|
|
|
|
{
|
|
|
|
|
log_verbose("Saved to %s", name);
|
2018-12-15 18:39:00 +00:00
|
|
|
gCurrentLoadedPath = name;
|
2018-10-14 22:36:41 +02:00
|
|
|
gScreenAge = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
void* create_save_game_as_intent()
|
2015-08-19 21:54:25 +02:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
char name[MAX_PATH];
|
2018-12-15 18:39:00 +00:00
|
|
|
safe_strcpy(name, path_get_filename(gScenarioSavePath.c_str()), MAX_PATH);
|
2017-06-06 23:24:18 +02:00
|
|
|
path_remove_extension(name);
|
2017-09-12 00:04:03 +02:00
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
Intent* intent = new Intent(WC_LOADSAVE);
|
2018-02-05 18:52:13 +01:00
|
|
|
intent->putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME);
|
2018-06-22 23:25:16 +02:00
|
|
|
intent->putExtra(INTENT_EXTRA_PATH, std::string{ name });
|
2017-09-12 00:04:03 +02:00
|
|
|
|
|
|
|
|
return intent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void save_game_as()
|
|
|
|
|
{
|
2020-04-17 16:36:25 -03:00
|
|
|
auto* intent = static_cast<Intent*>(create_save_game_as_intent());
|
2017-09-12 00:04:03 +02:00
|
|
|
context_open_intent(intent);
|
2018-02-05 18:52:13 +01:00
|
|
|
delete intent;
|
2014-05-27 23:33:16 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-06 21:32:13 +01:00
|
|
|
static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processLandscapeFolder)
|
2016-01-04 16:22:15 +01:00
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
size_t autosavesCount = 0;
|
2017-06-06 23:24:18 +02:00
|
|
|
size_t numAutosavesToDelete = 0;
|
2016-01-04 16:22:15 +01:00
|
|
|
|
2020-10-17 16:57:18 +02:00
|
|
|
auto environment = GetContext()->GetPlatformEnvironment();
|
|
|
|
|
auto folderDirectory = environment->GetDirectoryPath(DIRBASE::USER, DIRID::SAVE);
|
2020-10-17 16:18:23 +02:00
|
|
|
char const* fileFilter = "autosave_*.sv6";
|
2017-11-30 18:19:26 +01:00
|
|
|
if (processLandscapeFolder)
|
|
|
|
|
{
|
2020-10-17 16:57:18 +02:00
|
|
|
folderDirectory = environment->GetDirectoryPath(DIRBASE::USER, DIRID::LANDSCAPE);
|
2020-10-17 16:18:23 +02:00
|
|
|
fileFilter = "autosave_*.sc6";
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2020-10-17 16:18:23 +02:00
|
|
|
utf8 filter[MAX_PATH];
|
2020-10-17 16:57:18 +02:00
|
|
|
safe_strcpy(filter, folderDirectory.c_str(), sizeof(filter));
|
2020-10-17 16:18:23 +02:00
|
|
|
safe_strcat_path(filter, "autosave", sizeof(filter));
|
|
|
|
|
safe_strcat_path(filter, fileFilter, sizeof(filter));
|
|
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// At first, count how many autosaves there are
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2021-05-20 17:06:53 +02:00
|
|
|
auto scanner = Path::ScanDirectory(filter, false);
|
2018-01-06 18:52:12 +00:00
|
|
|
while (scanner->Next())
|
|
|
|
|
{
|
|
|
|
|
autosavesCount++;
|
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// If there are fewer autosaves than the number of files to keep we don't need to delete anything
|
2017-11-30 18:19:26 +01:00
|
|
|
if (autosavesCount <= numberOfFilesToKeep)
|
|
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2020-06-28 04:12:13 -04:00
|
|
|
auto autosaveFiles = std::vector<std::string>(autosavesCount);
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2021-05-20 17:06:53 +02:00
|
|
|
auto scanner = Path::ScanDirectory(filter, false);
|
2018-01-06 18:52:12 +00:00
|
|
|
for (size_t i = 0; i < autosavesCount; i++)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2020-06-28 04:12:13 -04:00
|
|
|
autosaveFiles[i].resize(MAX_PATH, 0);
|
2018-01-06 18:52:12 +00:00
|
|
|
if (scanner->Next())
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2020-10-25 01:35:42 -07:00
|
|
|
safe_strcpy(autosaveFiles[i].data(), folderDirectory.c_str(), sizeof(utf8) * MAX_PATH);
|
2020-06-28 04:12:13 -04:00
|
|
|
safe_strcat_path(autosaveFiles[i].data(), "autosave", sizeof(utf8) * MAX_PATH);
|
|
|
|
|
safe_strcat_path(autosaveFiles[i].data(), scanner->GetPathRelative(), sizeof(utf8) * MAX_PATH);
|
2017-11-30 18:19:26 +01:00
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-04 16:22:15 +01:00
|
|
|
|
2020-06-28 04:12:13 -04:00
|
|
|
std::sort(autosaveFiles.begin(), autosaveFiles.end(), [](const auto& saveFile0, const auto& saveFile1) {
|
|
|
|
|
return saveFile0.compare(saveFile1) < 0;
|
|
|
|
|
});
|
2016-01-04 16:22:15 +01:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Calculate how many saves we need to delete.
|
|
|
|
|
numAutosavesToDelete = autosavesCount - numberOfFilesToKeep;
|
2016-11-13 20:17:49 +01:00
|
|
|
|
2017-12-03 22:38:02 +01:00
|
|
|
for (size_t i = 0; numAutosavesToDelete > 0; i++, numAutosavesToDelete--)
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2020-10-25 01:35:42 -07:00
|
|
|
if (!platform_file_delete(autosaveFiles[i].data()))
|
|
|
|
|
{
|
|
|
|
|
log_warning("Failed to delete autosave file: %s", autosaveFiles[i].data());
|
|
|
|
|
}
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-01-04 16:22:15 +01:00
|
|
|
}
|
2015-08-19 21:54:25 +02:00
|
|
|
|
2015-02-21 11:05:15 +00:00
|
|
|
void game_autosave()
|
|
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
const char* subDirectory = "save";
|
|
|
|
|
const char* fileExtension = ".sv6";
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t saveFlags = 0x80000000;
|
2017-11-30 18:19:26 +01:00
|
|
|
if (gScreenFlags & SCREEN_FLAGS_EDITOR)
|
|
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
subDirectory = "landscape";
|
2017-06-06 23:24:18 +02:00
|
|
|
fileExtension = ".sc6";
|
|
|
|
|
saveFlags |= 2;
|
|
|
|
|
}
|
2016-07-23 23:25:13 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
// Retrieve current time
|
2020-06-28 15:46:14 -04:00
|
|
|
auto currentDate = Platform::GetDateLocal();
|
|
|
|
|
auto currentTime = Platform::GetTimeLocal();
|
2016-07-23 23:25:13 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
utf8 timeName[44];
|
2018-06-22 23:25:16 +02:00
|
|
|
snprintf(
|
2018-07-21 13:51:54 +02:00
|
|
|
timeName, sizeof(timeName), "autosave_%04u-%02u-%02u_%02u-%02u-%02u%s", currentDate.year, currentDate.month,
|
|
|
|
|
currentDate.day, currentTime.hour, currentTime.minute, currentTime.second, fileExtension);
|
2015-02-21 11:05:15 +00:00
|
|
|
|
2019-01-19 14:31:12 +01:00
|
|
|
int32_t autosavesToKeep = gConfigGeneral.autosave_amount;
|
|
|
|
|
limit_autosave_count(autosavesToKeep - 1, (gScreenFlags & SCREEN_FLAGS_EDITOR));
|
2016-07-23 23:25:13 +02:00
|
|
|
|
2017-06-06 23:24:18 +02:00
|
|
|
utf8 path[MAX_PATH];
|
|
|
|
|
utf8 backupPath[MAX_PATH];
|
|
|
|
|
platform_get_user_directory(path, subDirectory, sizeof(path));
|
2017-07-27 13:16:31 -04:00
|
|
|
safe_strcat_path(path, "autosave", sizeof(path));
|
|
|
|
|
platform_ensure_directory_exists(path);
|
2017-06-06 23:24:18 +02:00
|
|
|
safe_strcpy(backupPath, path, sizeof(backupPath));
|
|
|
|
|
safe_strcat_path(path, timeName, sizeof(path));
|
|
|
|
|
safe_strcat_path(backupPath, "autosave", sizeof(backupPath));
|
|
|
|
|
safe_strcat(backupPath, fileExtension, sizeof(backupPath));
|
|
|
|
|
safe_strcat(backupPath, ".bak", sizeof(backupPath));
|
2015-08-04 21:41:45 +01:00
|
|
|
|
2020-07-02 11:03:31 -04:00
|
|
|
if (Platform::FileExists(path))
|
2017-11-30 18:19:26 +01:00
|
|
|
{
|
2017-06-06 23:24:18 +02:00
|
|
|
platform_file_copy(path, backupPath, true);
|
|
|
|
|
}
|
2015-02-21 11:05:15 +00:00
|
|
|
|
2020-04-12 11:32:39 +02:00
|
|
|
if (!scenario_save(path, saveFlags))
|
2021-02-13 00:15:27 +00:00
|
|
|
Console::Error::WriteLine("Could not autosave the scenario. Is the save folder writeable?");
|
2015-02-21 11:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 23:25:16 +02:00
|
|
|
static void game_load_or_quit_no_save_prompt_callback(int32_t result, const utf8* path)
|
2016-11-29 18:41:54 +00:00
|
|
|
{
|
2017-11-30 18:19:26 +01:00
|
|
|
if (result == MODAL_RESULT_OK)
|
|
|
|
|
{
|
2020-04-22 22:53:32 +01:00
|
|
|
game_unload_scripts();
|
2018-06-13 23:29:05 +01:00
|
|
|
window_close_by_class(WC_EDITOR_OBJECT_SELECTION);
|
2017-08-23 07:04:36 +01:00
|
|
|
context_load_park_from_file(path);
|
2020-02-22 22:18:22 +00:00
|
|
|
game_load_scripts();
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2016-11-29 18:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 22:21:08 +01:00
|
|
|
/**
|
2015-10-09 18:22:37 +02:00
|
|
|
*
|
2014-05-02 22:21:08 +01:00
|
|
|
* rct2: 0x0066DB79
|
|
|
|
|
*/
|
|
|
|
|
void game_load_or_quit_no_save_prompt()
|
|
|
|
|
{
|
2017-11-30 18:19:26 +01:00
|
|
|
switch (gSavePromptMode)
|
|
|
|
|
{
|
2020-10-02 23:04:59 -03:00
|
|
|
case PromptMode::SaveBeforeLoad:
|
2019-02-21 09:34:30 +00:00
|
|
|
{
|
|
|
|
|
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt);
|
|
|
|
|
GameActions::Execute(&loadOrQuitAction);
|
2018-06-22 23:25:16 +02:00
|
|
|
tool_cancel();
|
|
|
|
|
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
|
|
|
|
|
{
|
|
|
|
|
load_landscape();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
auto intent = Intent(WC_LOADSAVE);
|
|
|
|
|
intent.putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME);
|
2020-04-17 16:36:25 -03:00
|
|
|
intent.putExtra(INTENT_EXTRA_CALLBACK, reinterpret_cast<void*>(game_load_or_quit_no_save_prompt_callback));
|
2018-06-22 23:25:16 +02:00
|
|
|
context_open_intent(&intent);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-02-21 09:34:30 +00:00
|
|
|
}
|
2020-10-02 23:04:59 -03:00
|
|
|
case PromptMode::SaveBeforeQuit:
|
2019-02-21 09:34:30 +00:00
|
|
|
{
|
|
|
|
|
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt);
|
|
|
|
|
GameActions::Execute(&loadOrQuitAction);
|
2018-06-22 23:25:16 +02:00
|
|
|
tool_cancel();
|
|
|
|
|
if (input_test_flag(INPUT_FLAG_5))
|
|
|
|
|
{
|
|
|
|
|
input_set_flag(INPUT_FLAG_5, false);
|
|
|
|
|
}
|
|
|
|
|
gGameSpeed = 1;
|
|
|
|
|
gFirstTimeSaving = true;
|
2020-04-22 22:53:32 +01:00
|
|
|
game_unload_scripts();
|
2018-06-22 23:25:16 +02:00
|
|
|
title_load();
|
|
|
|
|
break;
|
2019-02-21 09:34:30 +00:00
|
|
|
}
|
2018-06-22 23:25:16 +02:00
|
|
|
default:
|
2020-04-22 22:53:32 +01:00
|
|
|
game_unload_scripts();
|
2018-06-22 23:25:16 +02:00
|
|
|
openrct2_finish();
|
|
|
|
|
break;
|
2017-06-06 23:24:18 +02:00
|
|
|
}
|
2014-05-02 22:21:08 +01:00
|
|
|
}
|
2020-03-31 23:12:35 +02:00
|
|
|
|
|
|
|
|
void start_silent_record()
|
|
|
|
|
{
|
|
|
|
|
std::string name = Path::Combine(
|
|
|
|
|
OpenRCT2::GetContext()->GetPlatformEnvironment()->GetDirectoryPath(OpenRCT2::DIRBASE::USER), "debug_replay.sv6r");
|
|
|
|
|
auto* replayManager = OpenRCT2::GetContext()->GetReplayManager();
|
|
|
|
|
if (replayManager->StartRecording(name, OpenRCT2::k_MaxReplayTicks, OpenRCT2::IReplayManager::RecordType::SILENT))
|
|
|
|
|
{
|
|
|
|
|
OpenRCT2::ReplayRecordInfo info;
|
|
|
|
|
replayManager->GetCurrentReplayInfo(info);
|
|
|
|
|
safe_strcpy(gSilentRecordingName, info.FilePath.c_str(), MAX_PATH);
|
|
|
|
|
|
2020-05-02 16:40:21 +02:00
|
|
|
const char* logFmt = "Silent replay recording started: (%s) %s\n";
|
2021-05-09 19:11:04 +01:00
|
|
|
Console::WriteLine(logFmt, info.Name.c_str(), info.FilePath.c_str());
|
2020-03-31 23:12:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool stop_silent_record()
|
|
|
|
|
{
|
|
|
|
|
auto* replayManager = OpenRCT2::GetContext()->GetReplayManager();
|
|
|
|
|
if (!replayManager->IsRecording() && !replayManager->IsNormalising())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenRCT2::ReplayRecordInfo info;
|
|
|
|
|
replayManager->GetCurrentReplayInfo(info);
|
|
|
|
|
|
|
|
|
|
if (replayManager->StopRecording())
|
|
|
|
|
{
|
|
|
|
|
const char* logFmt = "Replay recording stopped: (%s) %s\n"
|
|
|
|
|
" Ticks: %u\n"
|
|
|
|
|
" Commands: %u\n"
|
|
|
|
|
" Checksums: %u";
|
|
|
|
|
|
2021-05-09 19:11:04 +01:00
|
|
|
Console::WriteLine(logFmt, info.Name.c_str(), info.FilePath.c_str(), info.Ticks, info.NumCommands, info.NumChecksums);
|
2020-03-31 23:12:35 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|