Files
OpenRCT2-Web/src/openrct2/Game.cpp
T

1715 lines
51 KiB
C++
Raw Normal View History

2017-06-01 21:55:10 +02:00
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
2014-04-02 00:31:55 +01:00
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
2015-10-09 18:22:37 +02:00
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
2015-10-09 18:22:37 +02:00
*
2014-04-02 00:31:55 +01:00
* OpenRCT2 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.
*
* A full copy of the GNU General Public License can be found in licence.txt
2014-04-02 00:31:55 +01:00
*****************************************************************************/
#pragma endregion
2015-10-09 18:22:37 +02:00
2014-10-06 17:36:58 +01:00
#include "audio/audio.h"
2017-12-13 13:02:24 +01:00
#include "Cheats.h"
2017-02-18 15:45:10 +00:00
#include "config/Config.h"
2017-03-26 21:42:07 +01:00
#include "Context.h"
2017-11-30 18:17:06 +01:00
#include "core/Math.hpp"
#include "core/Util.hpp"
#include "Editor.h"
#include "FileClassifier.h"
2017-11-30 18:17:06 +01:00
#include "Game.h"
2017-12-12 14:52:57 +01:00
#include "Input.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-05 23:56:37 +00:00
#include "interface/Widget.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"
2016-12-11 00:12:29 +00:00
#include "OpenRCT2.h"
2017-07-01 01:26:23 +01:00
#include "ParkImporter.h"
2017-10-13 10:06:36 +02:00
#include "peep/Peep.h"
#include "peep/Staff.h"
2015-02-12 20:51:40 +00:00
#include "platform/platform.h"
#include "rct1.h"
2017-12-31 13:21:34 +01:00
#include "ride/Ride.h"
2014-10-09 20:31:58 +01:00
#include "ride/ride_ratings.h"
2017-10-17 13:51:47 +02:00
#include "ride/Track.h"
#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"
2016-11-21 00:16:47 +00:00
#include "title/TitleScreen.h"
2017-10-30 07:07:01 -04:00
#include "title/TitleSequencePlayer.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"
2016-11-21 00:16:47 +00:00
#include "world/footpath.h"
2018-01-03 14:56:08 +01:00
#include "world/Map.h"
#include "world/map_animation.h"
2017-12-31 21:40:00 +01:00
#include "world/Park.h"
#include "world/scenery.h"
2014-10-06 17:36:58 +01:00
#include "world/sprite.h"
#include "world/water.h"
2018-01-02 20:36:42 +01:00
#include "object/ObjectList.h"
2016-01-04 16:22:15 +01:00
#define NUMBER_OF_AUTOSAVES_TO_KEEP 9
2016-05-20 22:56:45 +01:00
uint16 gTicksSinceLastUpdate;
2017-11-30 18:19:26 +01:00
uint8 gGamePaused = 0;
sint32 gGameSpeed = 1;
float gDayNightCycle = 0;
bool gInUpdateCode = false;
bool gInMapInitCode = false;
2017-01-04 22:17:08 +01:00
sint32 gGameCommandNestLevel;
2017-11-30 18:19:26 +01:00
bool gGameCommandIsNetworked;
char gCurrentLoadedPath[MAX_PATH];
2014-07-26 10:30:55 +01:00
2017-10-30 07:07:01 -04:00
bool gLoadKeepWindowsOpen = false;
2016-09-10 14:46:53 +01:00
uint8 gUnk13CA740;
uint8 gUnk141F568;
2016-09-03 20:25:19 +00:00
uint32 gCurrentTicks;
2017-12-20 14:35:43 +01:00
GAME_COMMAND_CALLBACK_POINTER * game_command_callback = nullptr;
2017-11-30 18:19:26 +01:00
static GAME_COMMAND_CALLBACK_POINTER * const game_command_callback_table[] = {
2017-12-20 14:35:43 +01:00
nullptr,
nullptr,
2017-06-06 23:24:18 +02:00
game_command_callback_ride_construct_placed_front,
game_command_callback_ride_construct_placed_back,
game_command_callback_ride_remove_track_piece,
game_command_callback_place_banner,
game_command_callback_place_ride_entrance_or_exit,
game_command_callback_hire_new_staff_member,
game_command_callback_pickup_guest,
game_command_callback_pickup_staff,
game_command_callback_marketing_start_campaign,
2015-07-23 17:22:03 -06:00
};
2017-01-04 22:17:08 +01:00
sint32 game_command_playerid = -1;
2015-07-23 17:22:03 -06:00
rct_string_id gGameCommandErrorTitle;
rct_string_id gGameCommandErrorText;
2017-11-30 18:19:26 +01:00
uint8 gErrorType;
2016-07-14 14:07:49 +02:00
rct_string_id gErrorStringId;
2017-11-30 18:19:26 +01:00
sint32 game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER * callback)
2015-07-23 17:22:03 -06:00
{
2017-11-30 18:47:31 +01:00
for (uint32 i = 0; i < Util::CountOf(game_command_callback_table); i++)
2017-11-30 18:19:26 +01:00
{
if (game_command_callback_table[i] == callback)
{
2017-06-06 23:24:18 +02:00
return i;
}
}
return 0;
2015-07-23 17:22:03 -06:00
}
2017-11-30 18:47:31 +01:00
GAME_COMMAND_CALLBACK_POINTER * game_command_callback_get_callback(uint32 index)
2015-07-23 17:22:03 -06:00
{
2017-11-30 18:19:26 +01:00
if (index < Util::CountOf(game_command_callback_table))
{
2017-06-06 23:24:18 +02:00
return game_command_callback_table[index];
}
2017-12-20 14:35:43 +01:00
return nullptr;
2015-07-23 17:22:03 -06:00
}
void game_increase_game_speed()
{
2017-12-01 09:35:01 +01:00
gGameSpeed = Math::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);
}
void game_reduce_game_speed()
{
2017-12-01 09:35:01 +01:00
gGameSpeed = Math::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-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
{
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,
2017-11-30 18:19:26 +01: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-09-23 13:33:55 -06:00
* rct2: 0x006838BD
*/
2014-09-23 13:33:55 -06:00
void update_palette_effects()
{
2017-11-30 18:19:26 +01:00
rct_water_type * water_type = (rct_water_type *) object_entry_groups[OBJECT_TYPE_WATER].chunks[0];
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
sint32 palette = SPR_GAME_PALETTE_DEFAULT;
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;
}
2017-10-28 13:02:54 +01: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
{
sint32 xoffset = g1->x_offset;
xoffset = xoffset * 4;
uint8 * paletteOffset = gGamePalette + xoffset;
for (sint32 i = 0; i < g1->width; i++)
{
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;
}
platform_update_palette(gGamePalette, 10, 236);
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
sint32 palette = SPR_GAME_PALETTE_DEFAULT;
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;
}
2017-10-28 13:02:54 +01: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
{
sint32 xoffset = g1->x_offset;
xoffset = xoffset * 4;
uint8 * paletteOffset = gGamePalette + xoffset;
for (sint32 i = 0; i < g1->width; i++)
{
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
}
}
2017-06-06 23:24:18 +02:00
// Animate the water/lava/chain movement palette
uint32 shade = 0;
2017-11-30 18:19:26 +01:00
if (gConfigGeneral.render_weather_gloom)
{
2017-06-06 23:24:18 +02:00
uint8 gloom = gClimateCurrentWeatherGloom;
2017-11-30 18:19:26 +01:00
if (gloom != 0)
{
2017-06-06 23:24:18 +02:00
FILTER_PALETTE_ID weatherColour = ClimateWeatherGloomColours[gloom];
shade = 1;
2017-11-30 18:19:26 +01:00
if (weatherColour != PALETTE_DARKEN_1)
{
2017-06-06 23:24:18 +02:00
shade = 2;
}
}
}
2017-12-01 09:35:01 +01:00
uint32 j = gPaletteEffectFrame;
2017-11-30 18:19:26 +01:00
j = (((uint16) ((~j / 2) * 128) * 15) >> 16);
2017-06-06 23:24:18 +02:00
uint32 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;
}
2017-10-28 13:02:54 +01: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
{
uint8 * vs = &g1->offset[j * 3];
uint8 * vd = &gGamePalette[230 * 4];
2017-11-30 18:19:26 +01:00
sint32 n = 5;
2017-10-26 13:14:37 +01:00
for (sint32 i = 0; i < n; i++)
{
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
}
}
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
{
uint8 * vs = &g1->offset[j * 3];
uint8 * vd = &gGamePalette[235 * 4];
2017-11-30 18:19:26 +01:00
sint32 n = 5;
2017-10-26 13:14:37 +01:00
for (sint32 i = 0; i < n; i++)
{
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
}
}
2017-11-30 18:19:26 +01:00
j = ((uint16) (gPaletteEffectFrame * -960) * 3) >> 16;
2017-06-06 23:24:18 +02:00
waterId = SPR_GAME_PALETTE_4;
2017-11-30 18:19:26 +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
{
uint8 * vs = &g1->offset[j * 3];
uint8 * vd = &gGamePalette[243 * 4];
2017-12-03 10:38:27 +01:00
sint32 n = 3;
2017-10-26 13:14:37 +01:00
for (sint32 i = 0; i < n; i++)
{
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
}
}
2017-06-06 23:24:18 +02:00
platform_update_palette(gGamePalette, 230, 16);
2017-11-30 18:19:26 +01:00
if (gClimateLightningFlash == 2)
{
2017-06-06 23:24:18 +02:00
platform_update_palette(gGamePalette, 10, 236);
gClimateLightningFlash = 0;
}
}
}
2014-04-02 00:31:55 +01:00
void game_update()
{
gInUpdateCode = true;
2017-11-30 18:17:06 +01:00
uint32 numUpdates;
2014-04-02 00:31:55 +01:00
2017-06-06 23:24:18 +02:00
// 0x006E3AEC // screen_game_process_mouse_input();
screenshot_check();
game_handle_keyboard_input();
2014-04-02 00:31:55 +01:00
2017-11-02 13:36:37 -04:00
if (game_is_not_paused() && gPreviewingTitleSequenceInGame)
2017-10-30 07:07:01 -04:00
{
2017-11-30 18:19:26 +01:00
title_sequence_player_update((ITitleSequencePlayer *) title_get_sequence_player());
2017-10-30 07:07:01 -04:00
}
2017-06-06 23:24:18 +02:00
// Determine how many times we need to update the game
2017-11-30 18:19:26 +01:00
if (gGameSpeed > 1)
{
2017-06-06 23:24:18 +02:00
numUpdates = 1 << (gGameSpeed - 1);
2017-11-30 18:19:26 +01:00
}
else
{
numUpdates = gTicksSinceLastUpdate / GAME_UPDATE_TIME_MS;
2017-11-30 18:19:26 +01:00
numUpdates = Math::Clamp(1u, numUpdates, (uint32) GAME_MAX_UPDATES);
2017-06-06 23:24:18 +02:00
}
2014-04-02 00:31:55 +01:00
2017-11-30 18:19:26 +01:00
if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED && network_get_authstatus() == NETWORK_AUTH_OK)
{
if (network_get_server_tick() - gCurrentTicks >= 10)
{
2017-06-06 23:24:18 +02:00
// Make sure client doesn't fall behind the server too much
numUpdates += 10;
}
}
2017-11-30 18:19:26 +01:00
if (game_is_paused())
{
2017-06-06 23:24:18 +02:00
numUpdates = 0;
// Update the animation list. Note this does not
// increment the map animation.
map_animation_invalidate_all();
// Special case because we set numUpdates to 0, otherwise in game_logic_update.
network_update();
network_process_game_commands();
2017-06-06 23:24:18 +02:00
}
2015-07-05 09:19:01 -06:00
// Update the game one or more times
2017-11-30 18:47:31 +01:00
for (uint32 i = 0; i < numUpdates; i++)
2017-11-30 18:19:26 +01:00
{
game_logic_update();
if (gGameSpeed > 1)
continue;
if (input_get_state() == INPUT_STATE_RESET ||
input_get_state() == INPUT_STATE_NORMAL
2017-11-30 18:19:26 +01:00
)
{
if (input_test_flag(INPUT_FLAG_VIEWPORT_SCROLLING))
{
input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false);
break;
}
2017-11-30 18:19:26 +01:00
}
else
{
break;
}
}
if (!gOpenRCT2Headless)
{
input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false);
// the flickering frequency is reduced by 4, compared to the original
// it was done due to inability to reproduce original frequency
// and decision that the original one looks too fast
if (gCurrentTicks % 4 == 0)
gWindowMapFlashingFlags ^= (1 << 15);
// Handle guest map flashing
gWindowMapFlashingFlags &= ~(1 << 1);
if (gWindowMapFlashingFlags & (1 << 0))
gWindowMapFlashingFlags |= (1 << 1);
gWindowMapFlashingFlags &= ~(1 << 0);
// Handle staff map flashing
gWindowMapFlashingFlags &= ~(1 << 3);
if (gWindowMapFlashingFlags & (1 << 2))
gWindowMapFlashingFlags |= (1 << 3);
gWindowMapFlashingFlags &= ~(1 << 2);
2017-10-21 17:57:37 +02:00
context_update_map_tooltip();
// Input
gUnk141F568 = gUnk13CA740;
2017-12-07 22:16:20 +01:00
context_handle_input();
}
2017-06-06 23:24:18 +02:00
// Always perform autosave check, even when paused
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) &&
!(gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) &&
!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
2017-11-30 18:19:26 +01:00
)
{
2017-06-06 23:24:18 +02:00
scenario_autosave_check();
}
2017-06-06 23:24:18 +02:00
window_dispatch_update_all();
2015-05-18 18:15:43 -04:00
2017-06-06 23:24:18 +02:00
gGameCommandNestLevel = 0;
2017-11-30 18:19:26 +01:00
gInUpdateCode = false;
}
void game_logic_update()
{
gScreenAge++;
if (gScreenAge == 0)
gScreenAge--;
network_update();
2017-11-30 18:19:26 +01:00
if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED && network_get_authstatus() == NETWORK_AUTH_OK)
{
// Can't be in sync with server, round trips won't work if we are at same level.
2017-11-30 18:19:26 +01:00
if (gCurrentTicks >= network_get_server_tick())
{
// Don't run past the server
return;
}
}
if (network_get_mode() == NETWORK_MODE_SERVER)
{
// Send current tick out.
network_send_tick();
}
else if (network_get_mode() == NETWORK_MODE_CLIENT)
{
// Check desync.
network_check_desynchronization();
}
2017-11-30 18:19:26 +01:00
2017-06-06 23:24:18 +02:00
sub_68B089();
scenario_update();
climate_update();
map_update_tiles();
// Temporarily remove provisional paths to prevent peep from interacting with them
map_remove_provisional_elements();
map_update_path_wide_flags();
peep_update_all();
map_restore_provisional_elements();
vehicle_update_all();
sprite_misc_update_all();
ride_update_all();
park_update();
research_update();
ride_ratings_update_all();
ride_measurements_update();
news_item_update_current();
2017-06-06 23:24:18 +02:00
map_animation_invalidate_all();
vehicle_sounds_update();
peep_update_crowd_noise();
climate_update_sound();
editor_open_windows_for_current_step();
2014-04-02 00:31:55 +01:00
2017-06-06 23:24:18 +02:00
// Update windows
//window_dispatch_update_all();
2014-04-02 00:31:55 +01:00
2017-11-30 18:19:26 +01:00
if (gErrorType != ERROR_TYPE_NONE)
{
2017-06-06 23:24:18 +02:00
rct_string_id title_text = STR_UNABLE_TO_LOAD_FILE;
2017-11-30 18:19:26 +01:00
rct_string_id body_text = gErrorStringId;
if (gErrorType == ERROR_TYPE_GENERIC)
{
2017-06-06 23:24:18 +02:00
title_text = gErrorStringId;
2017-11-30 18:19:26 +01:00
body_text = 0xFFFF;
2017-06-06 23:24:18 +02:00
}
2017-12-01 09:35:01 +01:00
gErrorType = ERROR_TYPE_NONE;
2014-04-02 00:31:55 +01:00
context_show_error(title_text, body_text);
2017-06-06 23:24:18 +02:00
}
2017-06-06 23:24:18 +02:00
// Start autosave timer after update
2017-11-30 18:19:26 +01:00
if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE)
{
2017-06-06 23:24:18 +02:00
gLastAutoSaveUpdate = platform_get_ticks();
}
// Separated out processing commands in network_update which could call scenario_rand where gInUpdateCode is false.
// All commands that are received are first queued and then executed where gInUpdateCode is set to true.
network_process_game_commands();
network_flush();
gCurrentTicks++;
gScenarioTicks++;
gSavedAge++;
2014-04-14 03:09:51 +01:00
}
2014-05-02 02:12:14 +01:00
/**
2015-10-09 18:22:37 +02:00
*
* rct2: 0x0069C62C
2014-05-02 02:12:14 +01:00
*
* @param cost (ebp)
*/
2017-01-04 22:17:08 +01:00
static sint32 game_check_affordability(sint32 cost)
2014-05-02 02:12:14 +01:00
{
2017-11-30 18:19:26 +01:00
if (cost <= 0)
return cost;
if (gUnk141F568 & 0xF0)
return cost;
2017-12-07 18:31:23 +01:00
if (cost <= (sint32) gCash)
2017-11-30 18:19:26 +01:00
return cost;
2015-08-16 13:05:49 -04:00
2017-06-06 23:24:18 +02:00
set_format_arg(0, uint32, cost);
2015-08-16 13:05:49 -04:00
2017-06-06 23:24:18 +02:00
gGameCommandErrorText = STR_NOT_ENOUGH_CASH_REQUIRES;
return MONEY32_UNDEFINED;
2014-05-02 02:12:14 +01:00
}
/**
2015-10-09 18:22:37 +02:00
*
2014-05-02 02:12:14 +01:00
* rct2: 0x006677F2
*
* @param flags (ebx)
* @param command (esi)
*/
2017-01-04 22:17:08 +01:00
sint32 game_do_command(sint32 eax, sint32 ebx, sint32 ecx, sint32 edx, sint32 esi, sint32 edi, sint32 ebp)
2014-05-02 02:12:14 +01:00
{
2017-06-06 23:24:18 +02:00
return game_do_command_p(esi, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp);
2014-05-02 22:21:08 +01:00
}
2014-08-05 19:15:28 +02:00
/**
*
* rct2: 0x006677F2 with pointers as arguments
*
* @param flags (ebx)
* @param command (esi)
*/
2017-11-30 18:47:31 +01:00
sint32 game_do_command_p(uint32 command, sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp)
2014-08-05 19:15:28 +02:00
{
2017-06-06 23:24:18 +02:00
sint32 cost, flags;
sint32 original_ebx, original_edx, original_esi, original_edi, original_ebp;
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
*esi = command;
original_ebx = *ebx;
original_edx = *edx;
original_esi = *esi;
original_edi = *edi;
original_ebp = *ebp;
2014-08-05 19:15:28 +02:00
2017-11-30 18:19:26 +01:00
if (command >= Util::CountOf(new_game_command_table))
{
2017-06-06 23:24:18 +02:00
return MONEY32_UNDEFINED;
}
2016-01-20 15:45:09 -07:00
2017-06-06 23:24:18 +02:00
flags = *ebx;
2014-08-05 19:15:28 +02:00
2017-11-30 18:19:26 +01:00
if (gGameCommandNestLevel == 0)
{
gGameCommandErrorText = STR_NONE;
2017-06-06 23:24:18 +02:00
gGameCommandIsNetworked = (flags & GAME_COMMAND_FLAG_NETWORKED) != 0;
}
2016-11-13 20:17:49 +01:00
2017-06-06 23:24:18 +02:00
// Increment nest count
gGameCommandNestLevel++;
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
// Remove ghost scenery so it doesn't interfere with incoming network command
if ((flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST) &&
(command == GAME_COMMAND_PLACE_WALL ||
2017-11-30 18:19:26 +01:00
command == GAME_COMMAND_PLACE_SCENERY ||
command == GAME_COMMAND_PLACE_LARGE_SCENERY ||
command == GAME_COMMAND_PLACE_BANNER ||
command == GAME_COMMAND_PLACE_PATH))
{
2017-06-06 23:24:18 +02:00
scenery_remove_ghost_tool_placement();
}
2015-07-18 10:49:08 -06:00
2017-11-30 18:19:26 +01:00
if (game_command_playerid == -1)
{
2017-06-06 23:24:18 +02:00
game_command_playerid = network_get_current_player_id();
}
2016-01-21 23:32:40 -07:00
2017-06-06 23:24:18 +02:00
// Log certain commands if we are in multiplayer and logging is enabled
bool serverLog = (network_get_mode() == NETWORK_MODE_SERVER) && gGameCommandNestLevel == 1 && gConfigNetwork.log_server_actions;
bool clientLog = (network_get_mode() == NETWORK_MODE_CLIENT) && (flags & GAME_COMMAND_FLAG_NETWORKED) && gGameCommandNestLevel == 1 && gConfigNetwork.log_server_actions;
2017-11-30 18:19:26 +01:00
if (serverLog || clientLog)
{
2017-06-06 23:24:18 +02:00
game_log_multiplayer_command(command, eax, ebx, ecx, edx, edi, ebp);
}
2017-06-06 23:24:18 +02:00
*ebx &= ~GAME_COMMAND_FLAG_APPLY;
2015-10-09 18:22:37 +02:00
2017-06-06 23:24:18 +02:00
// First call for validity and price check
new_game_command_table[command](eax, ebx, ecx, edx, esi, edi, ebp);
cost = *ebx;
2014-08-05 19:15:28 +02:00
2017-11-30 18:19:26 +01:00
if (cost != MONEY32_UNDEFINED)
{
2017-06-06 23:24:18 +02:00
// Check funds
sint32 insufficientFunds = 0;
if (gGameCommandNestLevel == 1 && !(flags & GAME_COMMAND_FLAG_2) && !(flags & GAME_COMMAND_FLAG_5) && cost != 0)
insufficientFunds = game_check_affordability(cost);
2014-08-05 19:15:28 +02:00
2017-11-30 18:19:26 +01:00
if (insufficientFunds != MONEY32_UNDEFINED)
{
2017-06-06 23:24:18 +02:00
*ebx = original_ebx;
*edx = original_edx;
*esi = original_esi;
*edi = original_edi;
*ebp = original_ebp;
2014-08-05 19:15:28 +02:00
2017-11-30 18:19:26 +01:00
if (!(flags & GAME_COMMAND_FLAG_APPLY))
{
2017-06-06 23:24:18 +02:00
// Decrement nest count
gGameCommandNestLevel--;
return cost;
}
2014-08-05 19:15:28 +02:00
2017-12-03 10:38:27 +01:00
if (network_get_mode() != NETWORK_MODE_NONE &&
!(flags & GAME_COMMAND_FLAG_NETWORKED) &&
!(flags & GAME_COMMAND_FLAG_GHOST) &&
!(flags & GAME_COMMAND_FLAG_5) &&
gGameCommandNestLevel == 1) /* Send only top-level commands */
2017-11-30 18:19:26 +01:00
{
2017-12-03 10:38:27 +01:00
// Disable these commands over the network
2017-11-30 18:19:26 +01:00
if (command != GAME_COMMAND_LOAD_OR_QUIT)
2017-12-03 10:38:27 +01:00
{
2017-06-06 23:24:18 +02:00
network_send_gamecmd(*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp, game_command_callback_get_index(game_command_callback));
2017-11-30 18:19:26 +01:00
if (network_get_mode() == NETWORK_MODE_CLIENT)
2017-12-03 10:38:27 +01:00
{
// Client sent the command to the server, do not run it locally, just return. It will run when server sends it.
2017-12-20 14:35:43 +01:00
game_command_callback = nullptr;
2017-06-06 23:24:18 +02:00
// Decrement nest count
gGameCommandNestLevel--;
return cost;
}
}
}
2015-07-08 20:19:12 -06:00
2017-06-06 23:24:18 +02:00
// Second call to actually perform the operation
new_game_command_table[command](eax, ebx, ecx, edx, esi, edi, ebp);
2015-07-23 17:22:03 -06:00
2017-06-06 23:24:18 +02:00
// Do the callback (required for multiplayer to work correctly), but only for top level commands
2017-11-30 18:19:26 +01:00
if (gGameCommandNestLevel == 1)
{
2017-06-17 13:41:40 +02:00
if (game_command_callback && !(flags & GAME_COMMAND_FLAG_GHOST))
{
2017-06-06 23:24:18 +02:00
game_command_callback(*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp);
2017-12-20 14:35:43 +01:00
game_command_callback = nullptr;
2017-06-06 23:24:18 +02:00
}
}
2015-07-23 17:22:03 -06:00
2017-06-06 23:24:18 +02:00
game_command_playerid = -1;
2016-01-23 17:33:08 -07:00
2017-06-06 23:24:18 +02:00
*edx = *ebx;
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
if (*edx != MONEY32_UNDEFINED && *edx < cost)
cost = *edx;
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
// Decrement nest count
gGameCommandNestLevel--;
if (gGameCommandNestLevel != 0)
return cost;
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
//
2017-11-30 18:19:26 +01:00
if (!(flags & 0x20))
{
2017-06-06 23:24:18 +02:00
// Update money balance
finance_payment(cost, gCommandExpenditureType);
2017-11-30 18:19:26 +01:00
if (gUnk141F568 == gUnk13CA740)
{
2017-06-06 23:24:18 +02:00
// Create a +/- money text effect
2017-06-29 17:42:36 +01:00
if (cost != 0 && game_is_not_paused())
2017-06-06 23:24:18 +02:00
money_effect_create(cost);
}
}
2014-08-05 19:15:28 +02:00
2017-11-30 18:19:26 +01:00
if (network_get_mode() == NETWORK_MODE_SERVER && !(flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST))
{
2017-06-06 23:24:18 +02:00
network_set_player_last_action(network_get_player_index(network_get_current_player_id()), command);
network_add_player_money_spent(network_get_current_player_id(), cost);
}
2016-01-20 15:45:09 -07:00
2017-06-06 23:24:18 +02:00
// Start autosave timer after game command
if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE)
gLastAutoSaveUpdate = platform_get_ticks();
2017-06-06 23:24:18 +02:00
return cost;
}
}
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
// Error occurred
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
// Decrement nest count
gGameCommandNestLevel--;
2016-11-13 20:17:49 +01:00
2017-06-06 23:24:18 +02:00
// Clear the game command callback to prevent the next command triggering it
2017-12-20 14:35:43 +01:00
game_command_callback = nullptr;
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
// Show error window
if (gGameCommandNestLevel == 0 && (flags & GAME_COMMAND_FLAG_APPLY) && gUnk141F568 == gUnk13CA740 && !(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
context_show_error(gGameCommandErrorTitle, gGameCommandErrorText);
2014-08-05 19:15:28 +02:00
2017-06-06 23:24:18 +02:00
return MONEY32_UNDEFINED;
2014-08-05 19:15:28 +02:00
}
2017-11-30 18:19:26 +01:00
void game_log_multiplayer_command(int command, int * eax, int * ebx, int * ecx, int * edx, int * edi, int * ebp)
{
2017-06-06 23:24:18 +02:00
// Get player name
int player_index = network_get_player_index(game_command_playerid);
2017-11-30 18:19:26 +01:00
const char * player_name = network_get_player_name(player_index);
2017-06-06 23:24:18 +02:00
char log_msg[256];
2017-11-30 18:19:26 +01:00
if (command == GAME_COMMAND_CHEAT)
{
2017-06-06 23:24:18 +02:00
// Get cheat name
2017-11-30 18:19:26 +01:00
const char * cheat = cheats_get_cheat_string(*ecx, *edx, *edi);
char * args[2] = {
(char *) player_name,
(char *) cheat
2017-06-06 23:24:18 +02:00
};
format_string(log_msg, 256, STR_LOG_CHEAT_USED, args);
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_CREATE_RIDE && *ebp == 1)
{ // ebp is 1 if the command comes from ride_create method in ride.c, other calls send ride_entry instead of ride and wont work
2017-06-06 23:24:18 +02:00
// Get ride name
2017-11-30 18:19:26 +01:00
Ride * ride = get_ride(*edx);
2017-06-06 23:24:18 +02:00
char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments);
2017-11-30 18:19:26 +01:00
char * args[2] = {
(char *) player_name,
2017-06-06 23:24:18 +02:00
ride_name
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_CREATE_RIDE, args);
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_DEMOLISH_RIDE && (*ebp == 1 || *ebp == 0))
{ // ebp is 1 if command comes from ride window prompt, so we don't log "demolishing" ride previews
2017-06-06 23:24:18 +02:00
// Get ride name
2017-11-30 18:19:26 +01:00
Ride * ride = get_ride(*edx);
2017-06-06 23:24:18 +02:00
char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments);
2017-11-30 18:19:26 +01:00
char * args[2] = {
2017-06-06 23:24:18 +02:00
(char *) player_name,
ride_name
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_DEMOLISH_RIDE, args);
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_SET_RIDE_APPEARANCE || command == GAME_COMMAND_SET_RIDE_VEHICLES || command == GAME_COMMAND_SET_RIDE_SETTING)
{
2017-06-06 23:24:18 +02:00
// Get ride name
int ride_index = *edx & 0xFF;
2017-11-30 18:19:26 +01:00
Ride * ride = get_ride(ride_index);
2017-06-06 23:24:18 +02:00
char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments);
2017-11-30 18:19:26 +01:00
char * args[2] = {
2017-06-06 23:24:18 +02:00
(char *) player_name,
ride_name
};
2017-11-30 18:19:26 +01:00
switch (command)
{
case GAME_COMMAND_SET_RIDE_APPEARANCE:
format_string(log_msg, 256, STR_LOG_RIDE_APPEARANCE, args);
break;
case GAME_COMMAND_SET_RIDE_VEHICLES:
format_string(log_msg, 256, STR_LOG_RIDE_VEHICLES, args);
break;
case GAME_COMMAND_SET_RIDE_SETTING:
format_string(log_msg, 256, STR_LOG_RIDE_SETTINGS, args);
break;
2017-06-06 23:24:18 +02:00
}
2017-06-06 23:24:18 +02:00
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_SET_RIDE_STATUS)
{
2017-06-06 23:24:18 +02:00
// Get ride name
int ride_index = *edx & 0xFF;
2017-11-30 18:19:26 +01:00
Ride * ride = get_ride(ride_index);
2017-06-06 23:24:18 +02:00
char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments);
2017-11-30 18:19:26 +01:00
char * args[2] = {
2017-06-06 23:24:18 +02:00
(char *) player_name,
ride_name
};
2017-06-06 23:24:18 +02:00
int status = *edx >> 8;
2017-11-30 18:19:26 +01:00
switch (status)
{
case 0:
format_string(log_msg, 256, STR_LOG_RIDE_STATUS_CLOSED, args);
break;
case 1:
format_string(log_msg, 256, STR_LOG_RIDE_STATUS_OPEN, args);
break;
case 2:
format_string(log_msg, 256, STR_LOG_RIDE_STATUS_TESTING, args);
break;
2017-06-06 23:24:18 +02:00
}
2017-06-06 23:24:18 +02:00
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_SET_RIDE_PRICE)
{
2017-06-06 23:24:18 +02:00
// Get ride name
int ride_index = *edx & 0xFF;
2017-11-30 18:19:26 +01:00
Ride * ride = get_ride(ride_index);
2017-06-06 23:24:18 +02:00
char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments);
2017-06-06 23:24:18 +02:00
// Format price
2017-11-30 18:19:26 +01:00
int price_args[1] = {*edi};
2017-06-06 23:24:18 +02:00
char price_str[16];
format_string(price_str, 16, STR_BOTTOM_TOOLBAR_CASH, price_args);
2017-06-06 23:24:18 +02:00
// Log change in primary or secondary price
2017-11-30 18:19:26 +01:00
char * args[3] = {
2017-06-06 23:24:18 +02:00
(char *) player_name,
ride_name,
price_str
};
2017-11-30 18:19:26 +01:00
if (*edx >> 8 == 0)
{
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_RIDE_PRICE, args);
2017-11-30 18:19:26 +01:00
}
else if (*edx >> 8 == 1)
{
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_RIDE_SECONDARY_PRICE, args);
}
2017-06-06 23:24:18 +02:00
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_SET_PARK_OPEN)
{
2017-06-06 23:24:18 +02:00
// Log change in park open/close
2017-11-30 18:19:26 +01:00
char * args[1] = {
2017-06-06 23:24:18 +02:00
(char *) player_name
};
2017-11-30 18:19:26 +01:00
if (*edx >> 8 == 0)
{
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_PARK_OPEN, args);
2017-11-30 18:19:26 +01:00
}
else if (*edx >> 8 == 1)
{
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_PARK_CLOSED, args);
}
2017-06-06 23:24:18 +02:00
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_SET_PARK_ENTRANCE_FEE)
{
2017-06-06 23:24:18 +02:00
// Format price
2017-11-30 18:19:26 +01:00
int price_args[1] = {*edi};
2017-06-06 23:24:18 +02:00
char price_str[16];
format_string(price_str, 16, STR_BOTTOM_TOOLBAR_CASH, price_args);
2017-06-06 23:24:18 +02:00
// Log change in park entrance fee
2017-11-30 18:19:26 +01:00
char * args[2] = {
2017-06-06 23:24:18 +02:00
(char *) player_name,
price_str
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_PARK_ENTRANCE_FEE, args);
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_PLACE_SCENERY || command == GAME_COMMAND_PLACE_WALL ||
command == GAME_COMMAND_PLACE_LARGE_SCENERY || command == GAME_COMMAND_PLACE_BANNER)
{
2017-06-06 23:24:18 +02:00
uint8 flags = *ebx & 0xFF;
2017-11-30 18:19:26 +01:00
if (flags & GAME_COMMAND_FLAG_GHOST)
{
2017-06-06 23:24:18 +02:00
// Don't log ghost previews being removed
return;
}
2017-06-06 23:24:18 +02:00
// Log placing scenery
2017-11-30 18:19:26 +01:00
char * args[1] = {
(char *) player_name
2017-06-06 23:24:18 +02:00
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_PLACE_SCENERY, args);
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_REMOVE_SCENERY || command == GAME_COMMAND_REMOVE_WALL ||
command == GAME_COMMAND_REMOVE_LARGE_SCENERY || command == GAME_COMMAND_REMOVE_BANNER)
{
2017-06-06 23:24:18 +02:00
uint8 flags = *ebx & 0xFF;
2017-11-30 18:19:26 +01:00
if (flags & GAME_COMMAND_FLAG_GHOST)
{
2017-06-06 23:24:18 +02:00
// Don't log ghost previews being removed
return;
}
2017-06-06 23:24:18 +02:00
// Log removing scenery
2017-11-30 18:19:26 +01:00
char * args[1] = {
(char *) player_name
2017-06-06 23:24:18 +02:00
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_REMOVE_SCENERY, args);
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_SET_SCENERY_COLOUR || command == GAME_COMMAND_SET_WALL_COLOUR ||
command == GAME_COMMAND_SET_LARGE_SCENERY_COLOUR || command == GAME_COMMAND_SET_BANNER_COLOUR ||
command == GAME_COMMAND_SET_BANNER_NAME || command == GAME_COMMAND_SET_SIGN_NAME ||
command == GAME_COMMAND_SET_BANNER_STYLE || command == GAME_COMMAND_SET_SIGN_STYLE)
{
2017-06-06 23:24:18 +02:00
// Log editing scenery
2017-11-30 18:19:26 +01:00
char * args[1] = {
(char *) player_name
2017-06-06 23:24:18 +02:00
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_EDIT_SCENERY, args);
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
if (command == GAME_COMMAND_SET_BANNER_NAME || command == GAME_COMMAND_SET_SIGN_NAME)
{
2017-06-06 23:24:18 +02:00
static char banner_name[128];
2017-06-06 23:24:18 +02:00
memset(banner_name, ' ', sizeof(banner_name));
int nameChunkIndex = *eax & 0xFFFF;
2017-06-06 23:24:18 +02:00
int nameChunkOffset = nameChunkIndex - 1;
if (nameChunkOffset < 0)
nameChunkOffset = 2;
nameChunkOffset *= 12;
2017-12-01 09:35:01 +01:00
nameChunkOffset = Math::Min(nameChunkOffset, (sint32) (Util::CountOf(banner_name) - 12));
2017-06-06 23:24:18 +02:00
memcpy(banner_name + nameChunkOffset + 0, edx, 4);
memcpy(banner_name + nameChunkOffset + 4, ebp, 4);
memcpy(banner_name + nameChunkOffset + 8, edi, 4);
banner_name[sizeof(banner_name) - 1] = '\0';
2017-11-30 18:19:26 +01:00
char * args_sign[2] = {
(char *) player_name,
(char *) banner_name
2017-06-06 23:24:18 +02:00
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_SET_SIGN_NAME, args_sign);
network_append_server_log(log_msg);
}
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_PLACE_TRACK)
{
2017-06-06 23:24:18 +02:00
// Get ride name
int ride_index = *edx & 0xFF;
2017-11-30 18:19:26 +01:00
Ride * ride = get_ride(ride_index);
2017-06-06 23:24:18 +02:00
char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments);
2017-11-30 18:19:26 +01:00
char * args[2] = {
2017-06-06 23:24:18 +02:00
(char *) player_name,
ride_name
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_PLACE_TRACK, args);
network_append_server_log(log_msg);
2017-11-30 18:19:26 +01:00
}
else if (command == GAME_COMMAND_REMOVE_TRACK)
{
char * args[1] = {
2017-06-06 23:24:18 +02:00
(char *) player_name
};
2017-06-06 23:24:18 +02:00
format_string(log_msg, 256, STR_LOG_REMOVE_TRACK, args);
network_append_server_log(log_msg);
}
}
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)
{
audio_stop_all_music_and_sounds();
2017-06-06 23:24:18 +02: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-03 09:00:49 +01:00
/**
2015-10-09 18:22:37 +02:00
*
2014-05-03 09:00:49 +01:00
* rct2: 0x00667C15
*/
2017-11-30 18:19:26 +01:00
void game_pause_toggle(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp)
2014-05-03 09:00:49 +01:00
{
2017-06-06 23:24:18 +02:00
if (*ebx & GAME_COMMAND_FLAG_APPLY)
pause_toggle();
2017-06-06 23:24:18 +02:00
*ebx = 0;
2014-05-03 09:00:49 +01: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: 0x0066DB5F
*/
2017-11-30 18:19:26 +01:00
static void game_load_or_quit(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp)
2014-05-02 22:21:08 +01:00
{
2017-11-30 18:19:26 +01:00
if (*ebx & GAME_COMMAND_FLAG_APPLY)
{
switch (*edx & 0xFF)
{
2017-06-06 23:24:18 +02:00
case 0:
gSavePromptMode = *edi & 0xFF;
2017-08-06 05:22:00 +02:00
context_open_window(WC_SAVE_PROMPT);
2017-06-06 23:24:18 +02:00
break;
case 1:
window_close_by_class(WC_SAVE_PROMPT);
break;
default:
game_load_or_quit_no_save_prompt();
break;
}
}
*ebx = 0;
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()
{
2017-09-12 00:04:03 +02:00
Intent * intent = intent_create(WC_LOADSAVE);
2017-09-12 21:21:39 +02:00
intent_set_uint(intent, INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE);
2017-09-12 00:04:03 +02:00
context_open_intent(intent);
intent_release(intent);
2014-05-02 22:21:08 +01:00
}
2017-11-30 18:19:26 +01:00
static void utf8_to_rct2_self(char * buffer, size_t length)
{
2017-06-06 23:24:18 +02:00
char tempBuffer[512];
utf8_to_rct2(tempBuffer, buffer);
2016-11-13 20:17:49 +01:00
2017-12-01 09:35:01 +01:00
size_t i = 0;
2017-11-30 18:19:26 +01:00
const char * src = tempBuffer;
char * dst = buffer;
while (*src != 0 && i < length - 1)
{
if (*src == (char) (uint8) 0xFF)
{
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++;
2017-11-30 18:19:26 +01:00
}
while (i < length);
}
2017-11-30 18:19:26 +01:00
static void rct2_to_utf8_self(char * buffer, size_t length)
{
2017-11-30 18:19:26 +01:00
if (length > 0)
{
2017-06-06 23:24:18 +02:00
char tempBuffer[512];
rct2_to_utf8(tempBuffer, buffer);
safe_strcpy(buffer, tempBuffer, length);
}
}
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
rct2_to_utf8_self(gScenarioCompletedBy, 32);
rct2_to_utf8_self(gScenarioName, 64);
rct2_to_utf8_self(gScenarioDetails, 256);
2015-07-29 23:57:43 +01:00
2017-06-06 23:24:18 +02:00
// User strings
2017-12-20 02:50:18 +01:00
for (auto * string : gUserStrings)
2017-11-23 15:52:06 +01:00
{
2017-12-20 02:50:18 +01:00
if (!str_is_null_or_empty(string))
2017-11-23 15:52:06 +01:00
{
2017-12-20 02:50:18 +01:00
rct2_to_utf8_self(string, RCT12_USER_STRING_MAX_LENGTH);
utf8_remove_formatting(string, true);
2017-06-06 23:24:18 +02:00
}
}
2015-07-29 23:57:43 +01:00
// News items
game_convert_news_items_to_utf8();
2015-07-29 23:57:43 +01:00
}
void game_convert_news_items_to_utf8()
{
2017-11-30 18:19:26 +01:00
for (sint32 i = 0; i < MAX_NEWS_ITEMS; i++)
{
NewsItem * newsItem = news_item_get(i);
2017-11-30 18:19:26 +01:00
if (!str_is_null_or_empty(newsItem->Text))
{
rct2_to_utf8_self(newsItem->Text, sizeof(newsItem->Text));
}
}
2015-07-29 23:57:43 +01:00
}
/**
* Converts all the user strings and news item strings to RCT2 encoding.
*/
2017-11-30 18:19:26 +01: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
2017-12-20 02:50:18 +01: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
2017-06-06 23:24:18 +02:00
// News items
2017-12-20 02:50:18 +01:00
for (auto &newsItem : s6->news_items)
2017-11-30 18:19:26 +01:00
{
2017-12-20 02:50:18 +01:00
if (!str_is_null_or_empty(newsItem.Text))
2017-11-30 18:19:26 +01:00
{
2017-12-20 02:50:18 +01:00
utf8_to_rct2_self(newsItem.Text, sizeof(newsItem.Text));
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.
void game_fix_save_vars()
{
2017-06-06 23:24:18 +02:00
// Recalculates peep count after loading a save to fix corrupted files
2017-11-30 18:19:26 +01:00
rct_peep * peep;
2017-06-06 23:24:18 +02:00
uint16 spriteIndex;
uint16 peepCount = 0;
2017-11-30 18:19:26 +01:00
FOR_ALL_GUESTS(spriteIndex, peep)
2017-11-30 18:24:44 +01:00
{
if (!peep->outside_of_park)
peepCount++;
}
2015-10-07 20:53:55 +02:00
2017-06-06 23:24:18 +02:00
gNumGuestsInPark = peepCount;
2017-06-06 23:24:18 +02:00
peep_sort();
2016-05-08 01:39:59 +02:00
2017-06-06 23:24:18 +02:00
// Fixes broken saves where a surface element could be null
// and broken saves with incorrect invisible map border tiles
2017-11-30 18:19:26 +01:00
for (sint32 y = 0; y < 256; y++)
{
for (sint32 x = 0; x < 256; x++)
{
rct_tile_element * tileElement = map_get_surface_element_at(x, y);
2017-11-30 18:21:12 +01:00
if (tileElement == nullptr)
2017-06-06 23:24:18 +02:00
{
log_error("Null map element at x = %d and y = %d. Fixing...", x, y);
2017-10-31 14:03:45 +01:00
tileElement = tile_element_insert(x, y, 14, 0);
2017-11-30 18:21:12 +01:00
if (tileElement == 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;
}
}
// Fix the invisible border tiles.
2017-10-31 14:03:45 +01:00
// At this point, we can be sure that tileElement is not NULL.
2017-11-30 18:19:26 +01:00
if (x == 0 || x == gMapSize - 1 || y == 0 || y == gMapSize - 1)
{
2017-11-30 18:19:26 +01:00
tileElement->base_height = 2;
tileElement->clearance_height = 2;
2017-11-18 12:58:27 +01:00
tileElement->properties.surface.slope = TILE_ELEMENT_SLOPE_FLAT;
}
2017-06-06 23:24:18 +02:00
}
}
research_fix();
// Fix banner list pointing to NULL map elements
banner_reset_broken_index();
// Fix invalid vehicle sprite sizes, thus preventing visual corruption of sprites
fix_invalid_vehicle_sprite_sizes();
2017-10-31 12:57:40 +01:00
// Fix gParkEntrance locations for which the tile_element no longer exists
fix_park_entrance_locations();
2017-10-25 15:05:10 +02:00
// Fix ride entrances and exits that were moved without updating ride->entrances[] / ride->exits[]
fix_ride_entrance_and_exit_locations();
2015-10-07 20:53:55 +02:00
}
void handle_park_load_failure_with_title_opt(const ParkLoadResult * result, const utf8 * path, bool loadTitleFirst)
2017-06-30 19:03:40 +01:00
{
2017-07-01 01:26:23 +01:00
if (ParkLoadResult_GetError(result) == PARK_LOAD_ERROR_MISSING_OBJECTS)
2017-06-30 19:03:40 +01:00
{
// This option is used when loading parks from the command line
// to ensure that the title sequence loads before the window
2017-11-30 18:19:26 +01:00
if (loadTitleFirst)
{
title_load();
}
2017-06-30 19:03:40 +01:00
// The path needs to be duplicated as it's a const here
// which the window function doesn't like
2017-10-23 00:44:55 +02:00
Intent * intent = intent_create(WC_OBJECT_LOAD_ERROR);
intent_set_string(intent, INTENT_EXTRA_PATH, strndup(path, strnlen(path, MAX_PATH)));
intent_set_pointer(intent, INTENT_EXTRA_LIST, (void *) ParkLoadResult_GetMissingObjects(result));
intent_set_uint(intent, INTENT_EXTRA_LIST_COUNT, (uint32) ParkLoadResult_GetMissingObjectsCount(result));
context_open_intent(intent);
intent_release(intent);
2017-10-30 16:11:45 +01:00
}
else if (ParkLoadResult_GetError(result) == PARK_LOAD_ERROR_UNSUPPORTED_RCTC_FLAG)
{
// This option is used when loading parks from the command line
// to ensure that the title sequence loads before the window
if (loadTitleFirst)
{
title_load();
}
set_format_arg(0, uint16, ParkLoadResult_GetFlag(result));
context_show_error(STR_FAILED_TO_LOAD_IMCOMPATIBLE_RCTC_FLAG, STR_NONE);
}
2017-11-30 18:19:26 +01:00
else if (ParkLoadResult_GetError(result) != PARK_LOAD_ERROR_OK)
{
2017-06-30 19:03:40 +01:00
// If loading the SV6 or SV4 failed for a reason other than invalid objects
// the current park state will be corrupted so just go back to the title screen.
title_load();
}
}
void handle_park_load_failure(const ParkLoadResult * result, const utf8 * path)
{
handle_park_load_failure_with_title_opt(result, path, false);
}
2015-07-05 09:19:01 -06:00
void game_load_init()
{
2017-11-30 18:19:26 +01:00
rct_window * mainWindow;
2015-07-05 09:19:01 -06:00
2017-06-06 23:24:18 +02:00
gScreenFlags = SCREEN_FLAGS_PLAYING;
audio_stop_all_music_and_sounds();
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
2017-11-30 18:21:12 +01:00
if (mainWindow != nullptr)
2017-08-27 22:46:35 +02:00
{
mainWindow->viewport_target_sprite = SPRITE_INDEX_NULL;
2017-11-30 18:19:26 +01:00
mainWindow->saved_view_x = gSavedViewX;
mainWindow->saved_view_y = gSavedViewY;
2017-08-27 22:46:35 +02:00
uint8 zoomDifference = gSavedViewZoom - mainWindow->viewport->zoom;
mainWindow->viewport->zoom = gSavedViewZoom;
gCurrentRotation = gSavedViewRotation;
2017-11-30 18:19:26 +01:00
if (zoomDifference != 0)
{
2017-11-14 20:36:12 +01:00
mainWindow->viewport->view_width <<= zoomDifference;
mainWindow->viewport->view_height <<= zoomDifference;
2017-06-06 23:24:18 +02:00
}
2017-08-27 22:46:35 +02:00
mainWindow->saved_view_x -= mainWindow->viewport->view_width >> 1;
mainWindow->saved_view_y -= mainWindow->viewport->view_height >> 1;
// Make sure the viewport has correct coordinates set.
viewport_update_position(mainWindow);
2017-08-27 22:46:35 +02:00
window_invalidate(mainWindow);
2017-06-06 23:24:18 +02:00
}
2014-05-04 16:21:15 +01:00
2017-06-06 23:24:18 +02:00
if (network_get_mode() != NETWORK_MODE_CLIENT)
{
reset_sprite_spatial_index();
}
reset_all_sprite_quadrant_placements();
scenery_set_default_placement_configuration();
2017-10-07 01:28:00 +02:00
Intent * intent = intent_create(INTENT_ACTION_REFRESH_NEW_RIDES);
context_broadcast_intent(intent);
intent_release(intent);
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-11-30 18:19:26 +01:00
if (!gOpenRCT2Headless)
{
2017-11-23 00:42:12 +01:00
intent = intent_create(INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD);
context_broadcast_intent(intent);
intent_release(intent);
2017-06-06 23:24:18 +02:00
window_update_all();
}
audio_stop_title_music();
2017-06-06 23:24:18 +02:00
gGameSpeed = 1;
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
{
2017-11-30 18:19:26 +01:00
for (size_t i = 0; i < MAX_SPRITES; i++)
{
rct_sprite * spr = get_sprite(i);
if (spr->unknown.sprite_identifier != SPRITE_IDENTIFIER_NULL)
{
2017-06-06 23:24:18 +02:00
sprite_move(spr->unknown.x, spr->unknown.y, spr->unknown.z, spr);
}
}
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)
{
2017-06-06 23:24:18 +02:00
log_verbose("Saving to %s", gScenarioSavePath);
2017-11-30 18:19:26 +01:00
if (scenario_save(gScenarioSavePath, 0x80000000 | (gConfigGeneral.save_plugin_data ? 1 : 0)))
{
2017-06-06 23:24:18 +02:00
log_verbose("Saved to %s", gScenarioSavePath);
safe_strcpy(gCurrentLoadedPath, gScenarioSavePath, MAX_PATH);
2017-06-06 23:24:18 +02:00
// Setting screen age to zero, so no prompt will pop up when closing the
// game shortly after saving.
gScreenAge = 0;
}
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
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];
safe_strcpy(name, path_get_filename(gScenarioSavePath), MAX_PATH);
path_remove_extension(name);
2017-09-12 00:04:03 +02:00
Intent * intent = intent_create(WC_LOADSAVE);
2017-09-12 21:21:39 +02:00
intent_set_uint(intent, INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME);
intent_set_string(intent, INTENT_EXTRA_PATH, name);
2017-09-12 00:04:03 +02:00
return intent;
}
void save_game_as()
{
Intent * intent = (Intent *) create_save_game_as_intent();
context_open_intent(intent);
intent_release(intent);
2014-05-27 23:33:16 +02:00
}
2017-11-30 18:19:26 +01:00
static sint32 compare_autosave_file_paths(const void * a, const void * b)
{
return strcmp(*(char **) a, *(char **) b);
2016-01-04 16:22:15 +01:00
}
static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processLandscapeFolder)
2016-01-04 16:22:15 +01:00
{
2017-06-06 23:24:18 +02:00
sint32 fileEnumHandle = 0;
2016-01-04 16:22:15 +01:00
2017-11-30 18:19:26 +01: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
2017-06-06 23:24:18 +02:00
file_info fileInfo;
2016-11-13 20:17:49 +01:00
2017-06-06 23:24:18 +02:00
utf8 filter[MAX_PATH];
2016-11-13 20:17:49 +01:00
2017-11-30 18:21:12 +01:00
utf8 ** autosaveFiles = nullptr;
2016-11-13 20:17:49 +01:00
2017-11-30 18:19:26 +01:00
if (processLandscapeFolder)
{
2017-06-06 23:24:18 +02:00
platform_get_user_directory(filter, "landscape", sizeof(filter));
safe_strcat_path(filter, "autosave", sizeof(filter));
2017-06-06 23:24:18 +02:00
safe_strcat_path(filter, "autosave_*.sc6", sizeof(filter));
2017-11-30 18:19:26 +01:00
}
else
{
2017-06-06 23:24:18 +02:00
platform_get_user_directory(filter, "save", sizeof(filter));
safe_strcat_path(filter, "autosave", sizeof(filter));
2017-06-06 23:24:18 +02:00
safe_strcat_path(filter, "autosave_*.sv6", sizeof(filter));
}
2016-11-13 20:17:49 +01:00
2017-06-06 23:24:18 +02:00
// At first, count how many autosaves there are
fileEnumHandle = platform_enumerate_files_begin(filter);
2017-11-30 18:19:26 +01:00
while (platform_enumerate_files_next(fileEnumHandle, &fileInfo))
{
2017-06-06 23:24:18 +02:00
autosavesCount++;
}
platform_enumerate_files_end(fileEnumHandle);
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
2017-11-30 18:19:26 +01:00
autosaveFiles = (utf8 **) malloc(sizeof(utf8 *) * autosavesCount);
2016-11-13 20:17:49 +01:00
2017-06-06 23:24:18 +02:00
fileEnumHandle = platform_enumerate_files_begin(filter);
2017-12-01 09:35:01 +01:00
for (size_t i = 0; i < autosavesCount; i++)
2017-11-30 18:19:26 +01:00
{
autosaveFiles[i] = (utf8 *) malloc(sizeof(utf8) * MAX_PATH);
2017-06-06 23:24:18 +02:00
memset(autosaveFiles[i], 0, sizeof(utf8) * MAX_PATH);
2016-11-13 20:17:49 +01:00
2017-11-30 18:19:26 +01:00
if (platform_enumerate_files_next(fileEnumHandle, &fileInfo))
{
if (processLandscapeFolder)
{
2017-06-06 23:24:18 +02:00
platform_get_user_directory(autosaveFiles[i], "landscape", sizeof(utf8) * MAX_PATH);
2017-11-30 18:19:26 +01:00
}
else
{
2017-06-06 23:24:18 +02:00
platform_get_user_directory(autosaveFiles[i], "save", sizeof(utf8) * MAX_PATH);
}
safe_strcat_path(autosaveFiles[i], "autosave", sizeof(utf8) * MAX_PATH);
2017-06-06 23:24:18 +02:00
safe_strcat_path(autosaveFiles[i], fileInfo.path, sizeof(utf8) * MAX_PATH);
}
}
platform_enumerate_files_end(fileEnumHandle);
2016-01-04 16:22:15 +01:00
2017-11-30 18:19:26 +01:00
qsort(autosaveFiles, autosavesCount, sizeof(char *), compare_autosave_file_paths);
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
{
2017-06-06 23:24:18 +02:00
platform_file_delete(autosaveFiles[i]);
}
2016-11-13 20:17:49 +01:00
2017-12-01 09:35:01 +01:00
for (size_t i = 0; i < autosavesCount; i++)
2017-11-30 18:19:26 +01:00
{
2017-06-06 23:24:18 +02:00
free(autosaveFiles[i]);
}
2016-11-13 20:17:49 +01:00
2017-06-06 23:24:18 +02:00
free(autosaveFiles);
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()
{
2017-11-30 18:19:26 +01:00
const char * subDirectory = "save";
2017-06-06 23:24:18 +02:00
const char * fileExtension = ".sv6";
uint32 saveFlags = 0x80000000;
2017-11-30 18:19:26 +01:00
if (gScreenFlags & SCREEN_FLAGS_EDITOR)
{
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
rct2_date currentDate;
platform_get_date_local(&currentDate);
rct2_time currentTime;
platform_get_time_local(&currentTime);
2016-07-23 23:25:13 +02:00
2017-06-06 23:24:18 +02:00
utf8 timeName[44];
snprintf(timeName, sizeof(timeName), "autosave_%04u-%02u-%02u_%02u-%02u-%02u%s",
2017-11-30 18:19:26 +01:00
currentDate.year, currentDate.month, currentDate.day, currentTime.hour,
currentTime.minute, currentTime.second, fileExtension);
2015-02-21 11:05:15 +00:00
2017-06-06 23:24:18 +02:00
limit_autosave_count(NUMBER_OF_AUTOSAVES_TO_KEEP, (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));
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));
2017-11-30 18:19:26 +01:00
if (platform_file_exists(path))
{
2017-06-06 23:24:18 +02:00
platform_file_copy(path, backupPath, true);
}
2015-02-21 11:05:15 +00:00
2017-06-06 23:24:18 +02:00
scenario_save(path, saveFlags);
2015-02-21 11:05:15 +00:00
}
2017-01-04 22:17:08 +01:00
static void game_load_or_quit_no_save_prompt_callback(sint32 result, const utf8 * path)
{
2017-11-30 18:19:26 +01:00
if (result == MODAL_RESULT_OK)
{
context_load_park_from_file(path);
2017-06-06 23:24:18 +02: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)
{
2017-06-06 23:24:18 +02:00
case PM_SAVE_BEFORE_LOAD:
game_do_command(0, 1, 0, 1, GAME_COMMAND_LOAD_OR_QUIT, 0, 0);
tool_cancel();
2017-11-30 18:19:26 +01:00
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
{
2017-06-06 23:24:18 +02:00
load_landscape();
2017-11-30 18:19:26 +01:00
}
else
{
2017-09-12 00:04:03 +02:00
Intent * intent = intent_create(WC_LOADSAVE);
2017-09-12 21:21:39 +02:00
intent_set_uint(intent, INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME);
2017-09-13 21:33:39 +02:00
intent_set_pointer(intent, INTENT_EXTRA_CALLBACK, (void *) game_load_or_quit_no_save_prompt_callback);
2017-09-12 00:04:03 +02:00
context_open_intent(intent);
intent_release(intent);
2017-06-06 23:24:18 +02:00
}
break;
case PM_SAVE_BEFORE_QUIT:
game_do_command(0, 1, 0, 1, GAME_COMMAND_LOAD_OR_QUIT, 0, 0);
tool_cancel();
2017-11-30 18:19:26 +01:00
if (input_test_flag(INPUT_FLAG_5))
{
2017-06-06 23:24:18 +02:00
input_set_flag(INPUT_FLAG_5, false);
}
2017-11-30 18:19:26 +01:00
gGameSpeed = 1;
gFirstTimeSaving = true;
2017-06-06 23:24:18 +02:00
title_load();
break;
default:
openrct2_finish();
2017-06-06 23:24:18 +02:00
break;
}
2014-05-02 22:21:08 +01:00
}
/**
* Initialises the map, park etc. basically all S6 data.
*/
void game_init_all(sint32 mapSize)
{
gInMapInitCode = true;
2017-06-06 23:24:18 +02:00
map_init(mapSize);
park_init();
finance_init();
reset_park_entry();
banner_init();
ride_init_all();
reset_sprite_list();
staff_reset_modes();
date_reset();
climate_reset(CLIMATE_COOL_AND_WET);
news_item_init_queue();
user_string_clear_all();
gInMapInitCode = false;
2017-09-10 11:02:16 +02:00
gNextGuestNumber = 1;
context_init();
2017-06-06 23:24:18 +02:00
scenery_set_default_placement_configuration();
2017-11-23 00:42:12 +01:00
Intent * intent = intent_create(INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD);
context_broadcast_intent(intent);
intent_release(intent);
load_palette();
}
2017-11-30 18:19:26 +01:00
GAME_COMMAND_POINTER * new_game_command_table[GAME_COMMAND_COUNT] = {
2017-06-06 23:24:18 +02:00
game_command_set_ride_appearance,
game_command_set_land_height,
game_pause_toggle,
game_command_place_track,
game_command_remove_track,
game_load_or_quit,
game_command_create_ride,
game_command_demolish_ride,
game_command_set_ride_status,
game_command_set_ride_vehicles,
game_command_set_ride_name,
game_command_set_ride_setting,
game_command_place_ride_entrance_or_exit,
game_command_remove_ride_entrance_or_exit,
game_command_remove_scenery,
game_command_place_scenery,
game_command_set_water_height,
game_command_place_footpath,
game_command_place_footpath_from_track,
game_command_remove_footpath,
game_command_change_surface_style,
game_command_set_ride_price,
game_command_set_guest_name,
game_command_set_staff_name,
game_command_raise_land,
game_command_lower_land,
game_command_smooth_land,
game_command_raise_water,
game_command_lower_water,
game_command_set_brakes_speed,
game_command_hire_new_staff_member,
game_command_set_staff_patrol,
game_command_fire_staff_member,
game_command_set_staff_order,
game_command_set_park_name,
game_command_set_park_open,
game_command_buy_land_rights,
game_command_place_park_entrance,
game_command_remove_park_entrance,
game_command_set_maze_track,
game_command_set_park_entrance_fee,
game_command_update_staff_colour,
game_command_place_wall,
game_command_remove_wall,
game_command_place_large_scenery,
game_command_remove_large_scenery,
game_command_set_current_loan,
game_command_set_research_funding,
game_command_place_track_design,
game_command_start_campaign,
game_command_place_maze_design,
game_command_place_banner,
game_command_remove_banner,
game_command_set_scenery_colour,
game_command_set_wall_colour,
game_command_set_large_scenery_colour,
game_command_set_banner_colour,
game_command_set_land_ownership,
game_command_clear_scenery,
game_command_set_banner_name,
game_command_set_sign_name,
game_command_set_banner_style,
game_command_set_sign_style,
game_command_set_player_group,
game_command_modify_groups,
game_command_kick_player,
game_command_cheat,
game_command_pickup_guest,
game_command_pickup_staff,
game_command_balloon_press,
game_command_modify_tile,
game_command_edit_scenario_options,
};