1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

clang-format root

This commit is contained in:
clang-format
2018-06-22 23:25:16 +02:00
committed by Hielke Morsink
parent 9c022606f1
commit c57bbca827
36 changed files with 2278 additions and 1895 deletions

View File

@@ -9,15 +9,14 @@
#include <openrct2/Context.h> #include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h> #include <openrct2/OpenRCT2.h>
#include <openrct2/platform/platform.h> #include <openrct2/platform/platform.h>
using namespace OpenRCT2; using namespace OpenRCT2;
/** /**
* Main entry point for non-Windows sytems. Windows instead uses its own DLL proxy. * Main entry point for non-Windows sytems. Windows instead uses its own DLL proxy.
*/ */
int main(int argc, const char * * argv) int main(int argc, const char** argv)
{ {
int runGame = cmdline_run(argv, argc); int runGame = cmdline_run(argv, argc);
core_init(); core_init();

View File

@@ -13,47 +13,46 @@
#undef CreateWindow #undef CreateWindow
// Then the rest // Then the rest
#include <openrct2-ui/Ui.h>
#include <openrct2-ui/UiContext.h>
#include <openrct2-ui/audio/AudioContext.h>
#include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/AudioContext.h>
#include <openrct2/ui/UiContext.h>
#include <shellapi.h> #include <shellapi.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <openrct2/audio/AudioContext.h>
#include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/ui/UiContext.h>
#include <openrct2-ui/audio/AudioContext.h>
#include <openrct2-ui/Ui.h>
#include <openrct2-ui/UiContext.h>
using namespace OpenRCT2; using namespace OpenRCT2;
using namespace OpenRCT2::Audio; using namespace OpenRCT2::Audio;
using namespace OpenRCT2::Ui; using namespace OpenRCT2::Ui;
#define DLLEXPORT extern "C" __declspec(dllexport) #define DLLEXPORT extern "C" __declspec(dllexport)
static char * * GetCommandLineArgs(int argc, wchar_t * * argvW); static char** GetCommandLineArgs(int argc, wchar_t** argvW);
static void FreeCommandLineArgs(int argc, char * * argv); static void FreeCommandLineArgs(int argc, char** argv);
static char * ConvertUTF16toUTF8(const wchar_t * src); static char* ConvertUTF16toUTF8(const wchar_t* src);
DLLEXPORT int LaunchOpenRCT2(int argc, wchar_t * * argvW) DLLEXPORT int LaunchOpenRCT2(int argc, wchar_t** argvW)
{ {
char * * argv = GetCommandLineArgs(argc, argvW); char** argv = GetCommandLineArgs(argc, argvW);
if (argv == nullptr) if (argv == nullptr)
{ {
puts("Unable to fetch command line arguments."); puts("Unable to fetch command line arguments.");
return -1; return -1;
} }
int exitCode = NormalisedMain(argc, const_cast<const char * *>(argv)); int exitCode = NormalisedMain(argc, const_cast<const char**>(argv));
FreeCommandLineArgs(argc, argv); FreeCommandLineArgs(argc, argv);
return exitCode; return exitCode;
} }
static char * * GetCommandLineArgs(int argc, wchar_t * * argvW) static char** GetCommandLineArgs(int argc, wchar_t** argvW)
{ {
// Allocate UTF-8 strings // Allocate UTF-8 strings
char * * argv = (char * *)malloc(argc * sizeof(char *)); char** argv = (char**)malloc(argc * sizeof(char*));
if (argv == nullptr) if (argv == nullptr)
{ {
return nullptr; return nullptr;
@@ -68,7 +67,7 @@ static char * * GetCommandLineArgs(int argc, wchar_t * * argvW)
return argv; return argv;
} }
static void FreeCommandLineArgs(int argc, char * * argv) static void FreeCommandLineArgs(int argc, char** argv)
{ {
// Free argv // Free argv
for (int i = 0; i < argc; i++) for (int i = 0; i < argc; i++)
@@ -78,11 +77,11 @@ static void FreeCommandLineArgs(int argc, char * * argv)
free(argv); free(argv);
} }
static char * ConvertUTF16toUTF8(const wchar_t * src) static char* ConvertUTF16toUTF8(const wchar_t* src)
{ {
int srcLen = lstrlenW(src); int srcLen = lstrlenW(src);
int sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr); int sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr);
char * result = (char *)calloc(1, sizeReq + 1); char* result = (char*)calloc(1, sizeReq + 1);
WideCharToMultiByte(CP_UTF8, 0, src, srcLen, result, sizeReq, nullptr, nullptr); WideCharToMultiByte(CP_UTF8, 0, src, srcLen, result, sizeReq, nullptr, nullptr);
return result; return result;
} }

View File

@@ -12,15 +12,17 @@
#include <windows.h> #include <windows.h>
// Enable visual styles // Enable visual styles
#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #pragma comment( \
linker, \
"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define DLLIMPORT extern "C" #define DLLIMPORT extern "C"
DLLIMPORT int LaunchOpenRCT2(int argc, wchar_t * * argv); DLLIMPORT int LaunchOpenRCT2(int argc, wchar_t** argv);
/** /**
* Windows entry point to OpenRCT2 with a console window using a traditional C main function. * Windows entry point to OpenRCT2 with a console window using a traditional C main function.
*/ */
int wmain(int argc, wchar_t * * argvW, [[maybe_unused]] wchar_t * envp) int wmain(int argc, wchar_t** argvW, [[maybe_unused]] wchar_t* envp)
{ {
return LaunchOpenRCT2(argc, argvW); return LaunchOpenRCT2(argc, argvW);
} }

View File

@@ -7,10 +7,11 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "actions/ParkSetLoanAction.hpp"
#include "Cheats.h" #include "Cheats.h"
#include "config/Config.h"
#include "GameState.h" #include "GameState.h"
#include "actions/ParkSetLoanAction.hpp"
#include "config/Config.h"
#include "localisation/Localisation.h" #include "localisation/Localisation.h"
#include "network/network.h" #include "network/network.h"
#include "ride/Ride.h" #include "ride/Ride.h"
@@ -58,10 +59,12 @@ int32_t day_spinner_value = 1;
static void cheat_set_grass_length(int32_t length) static void cheat_set_grass_length(int32_t length)
{ {
int32_t x, y; int32_t x, y;
rct_tile_element *tileElement; rct_tile_element* tileElement;
for (y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) { for (y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) { {
for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
{
tileElement = map_get_surface_element_at(x, y); tileElement = map_get_surface_element_at(x, y);
if (!(tileElement->properties.surface.ownership & OWNERSHIP_OWNED)) if (!(tileElement->properties.surface.ownership & OWNERSHIP_OWNED))
continue; continue;
@@ -84,8 +87,10 @@ static void cheat_water_plants()
tile_element_iterator it; tile_element_iterator it;
tile_element_iterator_begin(&it); tile_element_iterator_begin(&it);
do { do
if (it.element->GetType() == TILE_ELEMENT_TYPE_SMALL_SCENERY) { {
if (it.element->GetType() == TILE_ELEMENT_TYPE_SMALL_SCENERY)
{
it.element->properties.scenery.age = 0; it.element->properties.scenery.age = 0;
} }
} while (tile_element_iterator_next(&it)); } while (tile_element_iterator_next(&it));
@@ -98,7 +103,8 @@ static void cheat_fix_vandalism()
tile_element_iterator it; tile_element_iterator it;
tile_element_iterator_begin(&it); tile_element_iterator_begin(&it);
do { do
{
if (it.element->GetType() != TILE_ELEMENT_TYPE_PATH) if (it.element->GetType() != TILE_ELEMENT_TYPE_PATH)
continue; continue;
@@ -116,17 +122,19 @@ static void cheat_remove_litter()
rct_litter* litter; rct_litter* litter;
uint16_t spriteIndex, nextSpriteIndex; uint16_t spriteIndex, nextSpriteIndex;
for (spriteIndex = gSpriteListHead[SPRITE_LIST_LITTER]; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = nextSpriteIndex) { for (spriteIndex = gSpriteListHead[SPRITE_LIST_LITTER]; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = nextSpriteIndex)
{
litter = &(get_sprite(spriteIndex)->litter); litter = &(get_sprite(spriteIndex)->litter);
nextSpriteIndex = litter->next; nextSpriteIndex = litter->next;
sprite_remove((rct_sprite*)litter); sprite_remove((rct_sprite*)litter);
} }
tile_element_iterator it; tile_element_iterator it;
rct_scenery_entry *sceneryEntry; rct_scenery_entry* sceneryEntry;
tile_element_iterator_begin(&it); tile_element_iterator_begin(&it);
do { do
{
if (it.element->GetType() != TILE_ELEMENT_TYPE_PATH) if (it.element->GetType() != TILE_ELEMENT_TYPE_PATH)
continue; continue;
@@ -145,16 +153,18 @@ static void cheat_remove_litter()
static void cheat_fix_rides() static void cheat_fix_rides()
{ {
int32_t rideIndex; int32_t rideIndex;
Ride *ride; Ride* ride;
rct_peep *mechanic; rct_peep* mechanic;
FOR_ALL_RIDES(rideIndex, ride) FOR_ALL_RIDES (rideIndex, ride)
{ {
if ((ride->mechanic_status != RIDE_MECHANIC_STATUS_FIXING) && (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN))) if ((ride->mechanic_status != RIDE_MECHANIC_STATUS_FIXING)
&& (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)))
{ {
mechanic = ride_get_assigned_mechanic(ride); mechanic = ride_get_assigned_mechanic(ride);
if (mechanic != nullptr){ if (mechanic != nullptr)
{
mechanic->RemoveFromRide(); mechanic->RemoveFromRide();
} }
@@ -167,9 +177,9 @@ static void cheat_fix_rides()
static void cheat_renew_rides() static void cheat_renew_rides()
{ {
int32_t i; int32_t i;
Ride *ride; Ride* ride;
FOR_ALL_RIDES(i, ride) FOR_ALL_RIDES (i, ride)
{ {
ride_renew(ride); ride_renew(ride);
} }
@@ -179,13 +189,13 @@ static void cheat_renew_rides()
static void cheat_make_destructible() static void cheat_make_destructible()
{ {
int32_t i; int32_t i;
Ride *ride; Ride* ride;
FOR_ALL_RIDES(i, ride) FOR_ALL_RIDES (i, ride)
{ {
if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE) if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE)
ride->lifecycle_flags&=~RIDE_LIFECYCLE_INDESTRUCTIBLE; ride->lifecycle_flags &= ~RIDE_LIFECYCLE_INDESTRUCTIBLE;
if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK) if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK)
ride->lifecycle_flags&=~RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK; ride->lifecycle_flags &= ~RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK;
} }
window_invalidate_by_class(WC_RIDE); window_invalidate_by_class(WC_RIDE);
} }
@@ -193,9 +203,10 @@ static void cheat_make_destructible()
static void cheat_reset_crash_status() static void cheat_reset_crash_status()
{ {
int32_t i; int32_t i;
Ride *ride; Ride* ride;
FOR_ALL_RIDES(i, ride){ FOR_ALL_RIDES (i, ride)
{
// Reset crash status // Reset crash status
if (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED) if (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED)
ride->lifecycle_flags &= ~RIDE_LIFECYCLE_CRASHED; ride->lifecycle_flags &= ~RIDE_LIFECYCLE_CRASHED;
@@ -208,9 +219,10 @@ static void cheat_reset_crash_status()
static void cheat_10_minute_inspections() static void cheat_10_minute_inspections()
{ {
int32_t i; int32_t i;
Ride *ride; Ride* ride;
FOR_ALL_RIDES(i, ride) { FOR_ALL_RIDES (i, ride)
{
// Set inspection interval to 10 minutes // Set inspection interval to 10 minutes
ride->inspection_interval = RIDE_INSPECTION_EVERY_10_MINUTES; ride->inspection_interval = RIDE_INSPECTION_EVERY_10_MINUTES;
} }
@@ -219,10 +231,12 @@ static void cheat_10_minute_inspections()
static void cheat_no_money(bool enabled) static void cheat_no_money(bool enabled)
{ {
if (enabled) { if (enabled)
{
gParkFlags |= PARK_FLAGS_NO_MONEY; gParkFlags |= PARK_FLAGS_NO_MONEY;
} }
else { else
{
gParkFlags &= ~PARK_FLAGS_NO_MONEY; gParkFlags &= ~PARK_FLAGS_NO_MONEY;
} }
// Invalidate all windows that have anything to do with finance // Invalidate all windows that have anything to do with finance
@@ -274,10 +288,12 @@ static void cheat_generate_guests(int32_t count)
static void cheat_set_guest_parameter(int32_t parameter, int32_t value) static void cheat_set_guest_parameter(int32_t parameter, int32_t value)
{ {
int32_t spriteIndex; int32_t spriteIndex;
rct_peep *peep; rct_peep* peep;
FOR_ALL_GUESTS(spriteIndex, peep) { FOR_ALL_GUESTS (spriteIndex, peep)
switch(parameter) { {
switch (parameter)
{
case GUEST_PARAMETER_HAPPINESS: case GUEST_PARAMETER_HAPPINESS:
peep->happiness = value; peep->happiness = value;
peep->happiness_target = value; peep->happiness_target = value;
@@ -314,19 +330,19 @@ static void cheat_set_guest_parameter(int32_t parameter, int32_t value)
} }
peep->UpdateSpriteType(); peep->UpdateSpriteType();
} }
} }
static void cheat_give_all_guests(int32_t object) static void cheat_give_all_guests(int32_t object)
{ {
int32_t spriteIndex; int32_t spriteIndex;
rct_peep *peep; rct_peep* peep;
FOR_ALL_GUESTS(spriteIndex, peep) { FOR_ALL_GUESTS (spriteIndex, peep)
switch(object) {
switch (object)
{ {
case OBJECT_MONEY: case OBJECT_MONEY:
peep->cash_in_pocket = MONEY(1000,00); peep->cash_in_pocket = MONEY(1000, 00);
break; break;
case OBJECT_PARK_MAP: case OBJECT_PARK_MAP:
peep->item_standard_flags |= PEEP_ITEM_MAP; peep->item_standard_flags |= PEEP_ITEM_MAP;
@@ -348,13 +364,13 @@ static void cheat_give_all_guests(int32_t object)
static void cheat_remove_all_guests() static void cheat_remove_all_guests()
{ {
rct_peep *peep; rct_peep* peep;
rct_vehicle *vehicle; rct_vehicle* vehicle;
uint16_t spriteIndex, nextSpriteIndex; uint16_t spriteIndex, nextSpriteIndex;
int32_t rideIndex; int32_t rideIndex;
Ride *ride; Ride* ride;
FOR_ALL_RIDES(rideIndex, ride) FOR_ALL_RIDES (rideIndex, ride)
{ {
ride->num_riders = 0; ride->num_riders = 0;
@@ -380,7 +396,7 @@ static void cheat_remove_all_guests()
vehicle->mass -= peep->mass; vehicle->mass -= peep->mass;
} }
for (auto &peepInTrainIndex : vehicle->peep) for (auto& peepInTrainIndex : vehicle->peep)
{ {
peepInTrainIndex = SPRITE_INDEX_NULL; peepInTrainIndex = SPRITE_INDEX_NULL;
} }
@@ -393,10 +409,12 @@ static void cheat_remove_all_guests()
} }
} }
for (spriteIndex = gSpriteListHead[SPRITE_LIST_PEEP]; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = nextSpriteIndex) { for (spriteIndex = gSpriteListHead[SPRITE_LIST_PEEP]; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = nextSpriteIndex)
{
peep = &(get_sprite(spriteIndex)->peep); peep = &(get_sprite(spriteIndex)->peep);
nextSpriteIndex = peep->next; nextSpriteIndex = peep->next;
if (peep->type == PEEP_TYPE_GUEST) { if (peep->type == PEEP_TYPE_GUEST)
{
peep->Remove(); peep->Remove();
} }
} }
@@ -408,10 +426,12 @@ static void cheat_remove_all_guests()
static void cheat_explode_guests() static void cheat_explode_guests()
{ {
int32_t sprite_index; int32_t sprite_index;
rct_peep *peep; rct_peep* peep;
FOR_ALL_GUESTS(sprite_index, peep) { FOR_ALL_GUESTS (sprite_index, peep)
if (scenario_rand_max(6) == 0) { {
if (scenario_rand_max(6) == 0)
{
peep->peep_flags |= PEEP_FLAGS_EXPLODE; peep->peep_flags |= PEEP_FLAGS_EXPLODE;
} }
} }
@@ -420,9 +440,10 @@ static void cheat_explode_guests()
static void cheat_set_staff_speed(uint8_t value) static void cheat_set_staff_speed(uint8_t value)
{ {
uint16_t spriteIndex; uint16_t spriteIndex;
rct_peep *peep; rct_peep* peep;
FOR_ALL_STAFF(spriteIndex, peep) { FOR_ALL_STAFF (spriteIndex, peep)
{
peep->energy = value; peep->energy = value;
peep->energy_target = value; peep->energy_target = value;
} }
@@ -433,9 +454,11 @@ static void cheat_own_all_land()
const int32_t min = 32; const int32_t min = 32;
const int32_t max = gMapSizeUnits - 32; const int32_t max = gMapSizeUnits - 32;
for (CoordsXY coords = {min, min}; coords.y <= max; coords.y += 32) { for (CoordsXY coords = { min, min }; coords.y <= max; coords.y += 32)
for (coords.x = min; coords.x <= max; coords.x += 32) { {
rct_tile_element * surfaceElement = map_get_surface_element_at(coords); for (coords.x = min; coords.x <= max; coords.x += 32)
{
rct_tile_element* surfaceElement = map_get_surface_element_at(coords);
// Ignore already owned tiles. // Ignore already owned tiles.
if (surfaceElement->properties.surface.ownership & OWNERSHIP_OWNED) if (surfaceElement->properties.surface.ownership & OWNERSHIP_OWNED)
@@ -445,7 +468,8 @@ static void cheat_own_all_land()
int32_t destOwnership = check_max_allowable_land_rights_for_tile(coords.x >> 5, coords.y >> 5, base_z); int32_t destOwnership = check_max_allowable_land_rights_for_tile(coords.x >> 5, coords.y >> 5, base_z);
// only own tiles that were not set to 0 // only own tiles that were not set to 0
if (destOwnership != OWNERSHIP_UNOWNED) { if (destOwnership != OWNERSHIP_UNOWNED)
{
surfaceElement->properties.surface.ownership |= destOwnership; surfaceElement->properties.surface.ownership |= destOwnership;
update_park_fences_around_tile(coords); update_park_fences_around_tile(coords);
uint16_t baseHeight = surfaceElement->base_height * 8; uint16_t baseHeight = surfaceElement->base_height * 8;
@@ -455,13 +479,15 @@ static void cheat_own_all_land()
} }
// Completely unown peep spawn points // Completely unown peep spawn points
for (const auto &spawn : gPeepSpawns) { for (const auto& spawn : gPeepSpawns)
{
int32_t x = spawn.x; int32_t x = spawn.x;
int32_t y = spawn.y; int32_t y = spawn.y;
if (x != PEEP_SPAWN_UNDEFINED) { if (x != PEEP_SPAWN_UNDEFINED)
rct_tile_element * surfaceElement = map_get_surface_element_at({x, y}); {
rct_tile_element* surfaceElement = map_get_surface_element_at({ x, y });
surfaceElement->properties.surface.ownership = OWNERSHIP_UNOWNED; surfaceElement->properties.surface.ownership = OWNERSHIP_UNOWNED;
update_park_fences_around_tile({x, y}); update_park_fences_around_tile({ x, y });
uint16_t baseHeight = surfaceElement->base_height * 8; uint16_t baseHeight = surfaceElement->base_height * 8;
map_invalidate_tile(x, y, baseHeight, baseHeight + 16); map_invalidate_tile(x, y, baseHeight, baseHeight + 16);
} }
@@ -473,68 +499,171 @@ static void cheat_own_all_land()
#pragma endregion #pragma endregion
void game_command_cheat( void game_command_cheat(
[[maybe_unused]] int32_t * eax, [[maybe_unused]] int32_t* eax,
int32_t * ebx, int32_t* ebx,
int32_t * ecx, int32_t* ecx,
int32_t * edx, int32_t* edx,
[[maybe_unused]] int32_t * esi, [[maybe_unused]] int32_t* esi,
int32_t * edi, int32_t* edi,
[[maybe_unused]] int32_t * ebp) [[maybe_unused]] int32_t* ebp)
{ {
int32_t cheat = *ecx; int32_t cheat = *ecx;
if (*ebx & GAME_COMMAND_FLAG_APPLY) if (*ebx & GAME_COMMAND_FLAG_APPLY)
{ {
switch (cheat) switch (cheat)
{ {
case CHEAT_SANDBOXMODE: gCheatsSandboxMode = *edx != 0; window_invalidate_by_class(WC_MAP); window_invalidate_by_class(WC_FOOTPATH); break; case CHEAT_SANDBOXMODE:
case CHEAT_DISABLECLEARANCECHECKS: gCheatsDisableClearanceChecks = *edx != 0; break; gCheatsSandboxMode = *edx != 0;
case CHEAT_DISABLESUPPORTLIMITS: gCheatsDisableSupportLimits = *edx != 0; break; window_invalidate_by_class(WC_MAP);
case CHEAT_SHOWALLOPERATINGMODES: gCheatsShowAllOperatingModes = *edx != 0; break; window_invalidate_by_class(WC_FOOTPATH);
case CHEAT_SHOWVEHICLESFROMOTHERTRACKTYPES: gCheatsShowVehiclesFromOtherTrackTypes = *edx != 0; break; break;
case CHEAT_FASTLIFTHILL: gCheatsFastLiftHill = *edx != 0; break; case CHEAT_DISABLECLEARANCECHECKS:
case CHEAT_DISABLEBRAKESFAILURE: gCheatsDisableBrakesFailure = *edx != 0; break; gCheatsDisableClearanceChecks = *edx != 0;
case CHEAT_DISABLEALLBREAKDOWNS: gCheatsDisableAllBreakdowns = *edx != 0; break; break;
case CHEAT_DISABLETRAINLENGTHLIMIT: gCheatsDisableTrainLengthLimit = *edx != 0; break; case CHEAT_DISABLESUPPORTLIMITS:
case CHEAT_ENABLECHAINLIFTONALLTRACK: gCheatsEnableChainLiftOnAllTrack = *edx != 0; break; gCheatsDisableSupportLimits = *edx != 0;
case CHEAT_BUILDINPAUSEMODE: gCheatsBuildInPauseMode = *edx != 0; break; break;
case CHEAT_IGNORERIDEINTENSITY: gCheatsIgnoreRideIntensity = *edx != 0; break; case CHEAT_SHOWALLOPERATINGMODES:
case CHEAT_DISABLEVANDALISM: gCheatsDisableVandalism = *edx != 0; break; gCheatsShowAllOperatingModes = *edx != 0;
case CHEAT_DISABLELITTERING: gCheatsDisableLittering = *edx != 0; break; break;
case CHEAT_NOMONEY: cheat_no_money(*edx != 0); break; case CHEAT_SHOWVEHICLESFROMOTHERTRACKTYPES:
case CHEAT_ADDMONEY: cheat_add_money(*edx); break; gCheatsShowVehiclesFromOtherTrackTypes = *edx != 0;
case CHEAT_SETMONEY: cheat_set_money(*edx); break; break;
case CHEAT_CLEARLOAN: cheat_clear_loan(); break; case CHEAT_FASTLIFTHILL:
case CHEAT_SETGUESTPARAMETER: cheat_set_guest_parameter(*edx, *edi); break; gCheatsFastLiftHill = *edx != 0;
case CHEAT_GENERATEGUESTS: cheat_generate_guests(*edx); break; break;
case CHEAT_REMOVEALLGUESTS: cheat_remove_all_guests(); break; case CHEAT_DISABLEBRAKESFAILURE:
case CHEAT_EXPLODEGUESTS: cheat_explode_guests(); break; gCheatsDisableBrakesFailure = *edx != 0;
case CHEAT_GIVEALLGUESTS: cheat_give_all_guests(*edx); break; break;
case CHEAT_SETGRASSLENGTH: cheat_set_grass_length(*edx); break; case CHEAT_DISABLEALLBREAKDOWNS:
case CHEAT_WATERPLANTS: cheat_water_plants(); break; gCheatsDisableAllBreakdowns = *edx != 0;
case CHEAT_FIXVANDALISM: cheat_fix_vandalism(); break; break;
case CHEAT_REMOVELITTER: cheat_remove_litter(); break; case CHEAT_DISABLETRAINLENGTHLIMIT:
case CHEAT_DISABLEPLANTAGING: gCheatsDisablePlantAging = *edx != 0; break; gCheatsDisableTrainLengthLimit = *edx != 0;
case CHEAT_SETSTAFFSPEED: cheat_set_staff_speed(*edx); break; break;
case CHEAT_RENEWRIDES: cheat_renew_rides(); break; case CHEAT_ENABLECHAINLIFTONALLTRACK:
case CHEAT_MAKEDESTRUCTIBLE: cheat_make_destructible(); break; gCheatsEnableChainLiftOnAllTrack = *edx != 0;
case CHEAT_FIXRIDES: cheat_fix_rides(); break; break;
case CHEAT_RESETCRASHSTATUS: cheat_reset_crash_status(); break; case CHEAT_BUILDINPAUSEMODE:
case CHEAT_10MINUTEINSPECTIONS: cheat_10_minute_inspections(); break; gCheatsBuildInPauseMode = *edx != 0;
case CHEAT_WINSCENARIO: scenario_success(); break; break;
case CHEAT_FORCEWEATHER: climate_force_weather(*edx); break; case CHEAT_IGNORERIDEINTENSITY:
case CHEAT_FREEZECLIMATE: gCheatsFreezeClimate = *edx != 0; break; gCheatsIgnoreRideIntensity = *edx != 0;
case CHEAT_NEVERENDINGMARKETING: gCheatsNeverendingMarketing = *edx != 0; break; break;
case CHEAT_OPENCLOSEPARK: park_set_open(park_is_open() ? 0 : 1); break; case CHEAT_DISABLEVANDALISM:
case CHEAT_HAVEFUN: gScenarioObjectiveType = OBJECTIVE_HAVE_FUN; break; gCheatsDisableVandalism = *edx != 0;
case CHEAT_SETFORCEDPARKRATING: if(*edx > -1) { park_rating_spinner_value = *edx; } set_forced_park_rating(*edx); break; break;
case CHEAT_RESETDATE: date_reset(); window_invalidate_by_class(WC_BOTTOM_TOOLBAR); break; case CHEAT_DISABLELITTERING:
case CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES: gCheatsAllowArbitraryRideTypeChanges = *edx != 0; window_invalidate_by_class(WC_RIDE); break; gCheatsDisableLittering = *edx != 0;
case CHEAT_OWNALLLAND: cheat_own_all_land(); break; break;
case CHEAT_DISABLERIDEVALUEAGING: gCheatsDisableRideValueAging = *edx != 0; break; case CHEAT_NOMONEY:
case CHEAT_IGNORERESEARCHSTATUS: gCheatsIgnoreResearchStatus = *edx != 0; break; cheat_no_money(*edx != 0);
case CHEAT_ENABLEALLDRAWABLETRACKPIECES: gCheatsEnableAllDrawableTrackPieces = *edx != 0; break; break;
case CHEAT_ADDMONEY:
cheat_add_money(*edx);
break;
case CHEAT_SETMONEY:
cheat_set_money(*edx);
break;
case CHEAT_CLEARLOAN:
cheat_clear_loan();
break;
case CHEAT_SETGUESTPARAMETER:
cheat_set_guest_parameter(*edx, *edi);
break;
case CHEAT_GENERATEGUESTS:
cheat_generate_guests(*edx);
break;
case CHEAT_REMOVEALLGUESTS:
cheat_remove_all_guests();
break;
case CHEAT_EXPLODEGUESTS:
cheat_explode_guests();
break;
case CHEAT_GIVEALLGUESTS:
cheat_give_all_guests(*edx);
break;
case CHEAT_SETGRASSLENGTH:
cheat_set_grass_length(*edx);
break;
case CHEAT_WATERPLANTS:
cheat_water_plants();
break;
case CHEAT_FIXVANDALISM:
cheat_fix_vandalism();
break;
case CHEAT_REMOVELITTER:
cheat_remove_litter();
break;
case CHEAT_DISABLEPLANTAGING:
gCheatsDisablePlantAging = *edx != 0;
break;
case CHEAT_SETSTAFFSPEED:
cheat_set_staff_speed(*edx);
break;
case CHEAT_RENEWRIDES:
cheat_renew_rides();
break;
case CHEAT_MAKEDESTRUCTIBLE:
cheat_make_destructible();
break;
case CHEAT_FIXRIDES:
cheat_fix_rides();
break;
case CHEAT_RESETCRASHSTATUS:
cheat_reset_crash_status();
break;
case CHEAT_10MINUTEINSPECTIONS:
cheat_10_minute_inspections();
break;
case CHEAT_WINSCENARIO:
scenario_success();
break;
case CHEAT_FORCEWEATHER:
climate_force_weather(*edx);
break;
case CHEAT_FREEZECLIMATE:
gCheatsFreezeClimate = *edx != 0;
break;
case CHEAT_NEVERENDINGMARKETING:
gCheatsNeverendingMarketing = *edx != 0;
break;
case CHEAT_OPENCLOSEPARK:
park_set_open(park_is_open() ? 0 : 1);
break;
case CHEAT_HAVEFUN:
gScenarioObjectiveType = OBJECTIVE_HAVE_FUN;
break;
case CHEAT_SETFORCEDPARKRATING:
if (*edx > -1)
{
park_rating_spinner_value = *edx;
} }
if (network_get_mode() == NETWORK_MODE_NONE) { set_forced_park_rating(*edx);
break;
case CHEAT_RESETDATE:
date_reset();
window_invalidate_by_class(WC_BOTTOM_TOOLBAR);
break;
case CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES:
gCheatsAllowArbitraryRideTypeChanges = *edx != 0;
window_invalidate_by_class(WC_RIDE);
break;
case CHEAT_OWNALLLAND:
cheat_own_all_land();
break;
case CHEAT_DISABLERIDEVALUEAGING:
gCheatsDisableRideValueAging = *edx != 0;
break;
case CHEAT_IGNORERESEARCHSTATUS:
gCheatsIgnoreResearchStatus = *edx != 0;
break;
case CHEAT_ENABLEALLDRAWABLETRACKPIECES:
gCheatsEnableAllDrawableTrackPieces = *edx != 0;
break;
}
if (network_get_mode() == NETWORK_MODE_NONE)
{
config_save_default(); config_save_default();
} }
window_invalidate_by_class(WC_CHEATS); window_invalidate_by_class(WC_CHEATS);
@@ -566,121 +695,171 @@ void cheats_reset()
gCheatsIgnoreResearchStatus = false; gCheatsIgnoreResearchStatus = false;
} }
//Generates the string to print for the server log when a cheat is used. // Generates the string to print for the server log when a cheat is used.
const char* cheats_get_cheat_string(int cheat, int edx, int edi) { const char* cheats_get_cheat_string(int cheat, int edx, int edi)
switch (cheat) { {
switch (cheat)
{
case CHEAT_SANDBOXMODE: case CHEAT_SANDBOXMODE:
if (gCheatsSandboxMode) { if (gCheatsSandboxMode)
{
return language_get_string(STR_CHEAT_SANDBOX_MODE_DISABLE); return language_get_string(STR_CHEAT_SANDBOX_MODE_DISABLE);
} else { }
else
{
return language_get_string(STR_CHEAT_SANDBOX_MODE); return language_get_string(STR_CHEAT_SANDBOX_MODE);
} }
case CHEAT_DISABLECLEARANCECHECKS: return language_get_string(STR_DISABLE_CLEARANCE_CHECKS); case CHEAT_DISABLECLEARANCECHECKS:
case CHEAT_DISABLESUPPORTLIMITS: return language_get_string(STR_DISABLE_SUPPORT_LIMITS); return language_get_string(STR_DISABLE_CLEARANCE_CHECKS);
case CHEAT_SHOWALLOPERATINGMODES: return language_get_string(STR_CHEAT_SHOW_ALL_OPERATING_MODES); case CHEAT_DISABLESUPPORTLIMITS:
case CHEAT_SHOWVEHICLESFROMOTHERTRACKTYPES: return language_get_string(STR_CHEAT_SHOW_VEHICLES_FROM_OTHER_TRACK_TYPES); return language_get_string(STR_DISABLE_SUPPORT_LIMITS);
case CHEAT_FASTLIFTHILL: return language_get_string(STR_CHEAT_UNLOCK_OPERATING_LIMITS); case CHEAT_SHOWALLOPERATINGMODES:
case CHEAT_DISABLEBRAKESFAILURE: return language_get_string(STR_CHEAT_DISABLE_BRAKES_FAILURE); return language_get_string(STR_CHEAT_SHOW_ALL_OPERATING_MODES);
case CHEAT_DISABLEALLBREAKDOWNS: return language_get_string(STR_CHEAT_DISABLE_BREAKDOWNS); case CHEAT_SHOWVEHICLESFROMOTHERTRACKTYPES:
case CHEAT_DISABLETRAINLENGTHLIMIT: return language_get_string(STR_CHEAT_DISABLE_TRAIN_LENGTH_LIMIT); return language_get_string(STR_CHEAT_SHOW_VEHICLES_FROM_OTHER_TRACK_TYPES);
case CHEAT_ENABLECHAINLIFTONALLTRACK: return language_get_string(STR_CHEAT_ENABLE_CHAIN_LIFT_ON_ALL_TRACK); case CHEAT_FASTLIFTHILL:
case CHEAT_BUILDINPAUSEMODE: return language_get_string(STR_CHEAT_BUILD_IN_PAUSE_MODE); return language_get_string(STR_CHEAT_UNLOCK_OPERATING_LIMITS);
case CHEAT_IGNORERIDEINTENSITY: return language_get_string(STR_CHEAT_IGNORE_INTENSITY); case CHEAT_DISABLEBRAKESFAILURE:
case CHEAT_DISABLEVANDALISM: return language_get_string(STR_CHEAT_DISABLE_VANDALISM); return language_get_string(STR_CHEAT_DISABLE_BRAKES_FAILURE);
case CHEAT_DISABLELITTERING: return language_get_string(STR_CHEAT_DISABLE_LITTERING); case CHEAT_DISABLEALLBREAKDOWNS:
case CHEAT_NOMONEY: return language_get_string(STR_MAKE_PARK_NO_MONEY); return language_get_string(STR_CHEAT_DISABLE_BREAKDOWNS);
case CHEAT_ADDMONEY: return language_get_string(STR_LOG_CHEAT_ADD_MONEY); case CHEAT_DISABLETRAINLENGTHLIMIT:
case CHEAT_CLEARLOAN: return language_get_string(STR_CHEAT_CLEAR_LOAN); return language_get_string(STR_CHEAT_DISABLE_TRAIN_LENGTH_LIMIT);
case CHEAT_ENABLECHAINLIFTONALLTRACK:
return language_get_string(STR_CHEAT_ENABLE_CHAIN_LIFT_ON_ALL_TRACK);
case CHEAT_BUILDINPAUSEMODE:
return language_get_string(STR_CHEAT_BUILD_IN_PAUSE_MODE);
case CHEAT_IGNORERIDEINTENSITY:
return language_get_string(STR_CHEAT_IGNORE_INTENSITY);
case CHEAT_DISABLEVANDALISM:
return language_get_string(STR_CHEAT_DISABLE_VANDALISM);
case CHEAT_DISABLELITTERING:
return language_get_string(STR_CHEAT_DISABLE_LITTERING);
case CHEAT_NOMONEY:
return language_get_string(STR_MAKE_PARK_NO_MONEY);
case CHEAT_ADDMONEY:
return language_get_string(STR_LOG_CHEAT_ADD_MONEY);
case CHEAT_CLEARLOAN:
return language_get_string(STR_CHEAT_CLEAR_LOAN);
case CHEAT_SETGUESTPARAMETER: case CHEAT_SETGUESTPARAMETER:
{ {
static char cheat_string[128]; static char cheat_string[128];
safe_strcpy(cheat_string, language_get_string(STR_CHEAT_SET_GUESTS_PARAMETERS), 128); safe_strcpy(cheat_string, language_get_string(STR_CHEAT_SET_GUESTS_PARAMETERS), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
switch (edx) { switch (edx)
{
case GUEST_PARAMETER_HAPPINESS: case GUEST_PARAMETER_HAPPINESS:
safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_HAPPINESS), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_HAPPINESS), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
if (edi == 255) { if (edi == 255)
{
safe_strcat(cheat_string, language_get_string(STR_MAX), 128); safe_strcat(cheat_string, language_get_string(STR_MAX), 128);
} else if (edi == 0) { }
else if (edi == 0)
{
safe_strcat(cheat_string, language_get_string(STR_MIN), 128); safe_strcat(cheat_string, language_get_string(STR_MIN), 128);
} }
break; break;
case GUEST_PARAMETER_ENERGY: case GUEST_PARAMETER_ENERGY:
safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_ENERGY), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_ENERGY), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
if (edi == 127) { if (edi == 127)
{
safe_strcat(cheat_string, language_get_string(STR_MAX), 128); safe_strcat(cheat_string, language_get_string(STR_MAX), 128);
} else if (edi == 0) { }
else if (edi == 0)
{
safe_strcat(cheat_string, language_get_string(STR_MIN), 128); safe_strcat(cheat_string, language_get_string(STR_MIN), 128);
} }
break; break;
case GUEST_PARAMETER_HUNGER: case GUEST_PARAMETER_HUNGER:
safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_HUNGER), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_HUNGER), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
if (edi == 255) { if (edi == 255)
{
safe_strcat(cheat_string, language_get_string(STR_MIN), 128); safe_strcat(cheat_string, language_get_string(STR_MIN), 128);
} else if (edi == 0) { }
else if (edi == 0)
{
safe_strcat(cheat_string, language_get_string(STR_MAX), 128); safe_strcat(cheat_string, language_get_string(STR_MAX), 128);
} }
break; break;
case GUEST_PARAMETER_THIRST: case GUEST_PARAMETER_THIRST:
safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_THIRST), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_THIRST), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
if (edi == 255) { if (edi == 255)
{
safe_strcat(cheat_string, language_get_string(STR_MIN), 128); safe_strcat(cheat_string, language_get_string(STR_MIN), 128);
} else if (edi == 0) { }
else if (edi == 0)
{
safe_strcat(cheat_string, language_get_string(STR_MAX), 128); safe_strcat(cheat_string, language_get_string(STR_MAX), 128);
} }
break; break;
case GUEST_PARAMETER_NAUSEA: case GUEST_PARAMETER_NAUSEA:
safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_NAUSEA), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_NAUSEA), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
if (edi == 255) { if (edi == 255)
{
safe_strcat(cheat_string, language_get_string(STR_MAX), 128); safe_strcat(cheat_string, language_get_string(STR_MAX), 128);
} else if (edi == 0) { }
else if (edi == 0)
{
safe_strcat(cheat_string, language_get_string(STR_MIN), 128); safe_strcat(cheat_string, language_get_string(STR_MIN), 128);
} }
break; break;
case GUEST_PARAMETER_NAUSEA_TOLERANCE: case GUEST_PARAMETER_NAUSEA_TOLERANCE:
safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_NAUSEA_TOLERANCE), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_NAUSEA_TOLERANCE), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
if (edi == PEEP_NAUSEA_TOLERANCE_HIGH) { if (edi == PEEP_NAUSEA_TOLERANCE_HIGH)
{
safe_strcat(cheat_string, language_get_string(STR_MAX), 128); safe_strcat(cheat_string, language_get_string(STR_MAX), 128);
} else if (edi == PEEP_NAUSEA_TOLERANCE_NONE) { }
else if (edi == PEEP_NAUSEA_TOLERANCE_NONE)
{
safe_strcat(cheat_string, language_get_string(STR_MIN), 128); safe_strcat(cheat_string, language_get_string(STR_MIN), 128);
} }
break; break;
case GUEST_PARAMETER_BATHROOM: case GUEST_PARAMETER_BATHROOM:
safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_BATHROOM), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_BATHROOM), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
if (edi == 255) { if (edi == 255)
{
safe_strcat(cheat_string, language_get_string(STR_MAX), 128); safe_strcat(cheat_string, language_get_string(STR_MAX), 128);
} else if (edi == 0) { }
else if (edi == 0)
{
safe_strcat(cheat_string, language_get_string(STR_MIN), 128); safe_strcat(cheat_string, language_get_string(STR_MIN), 128);
} }
break; break;
case GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY: case GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY:
safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_PREFERRED_INTENSITY), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_GUEST_PREFERRED_INTENSITY), 128);
safe_strcat(cheat_string, " ", 128); safe_strcat(cheat_string, " ", 128);
if (edi == 1) { if (edi == 1)
{
safe_strcat(cheat_string, language_get_string(STR_CHEAT_MORE_THAN_1), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_MORE_THAN_1), 128);
} else if (edi == 0) { }
else if (edi == 0)
{
safe_strcat(cheat_string, language_get_string(STR_CHEAT_LESS_THAN_15), 128); safe_strcat(cheat_string, language_get_string(STR_CHEAT_LESS_THAN_15), 128);
} }
break; break;
} }
return cheat_string; return cheat_string;
} }
case CHEAT_GENERATEGUESTS: return language_get_string(STR_CHEAT_LARGE_TRAM_GUESTS); case CHEAT_GENERATEGUESTS:
case CHEAT_REMOVEALLGUESTS: return language_get_string(STR_CHEAT_REMOVE_ALL_GUESTS); return language_get_string(STR_CHEAT_LARGE_TRAM_GUESTS);
case CHEAT_EXPLODEGUESTS: return language_get_string(STR_CHEAT_EXPLODE); case CHEAT_REMOVEALLGUESTS:
return language_get_string(STR_CHEAT_REMOVE_ALL_GUESTS);
case CHEAT_EXPLODEGUESTS:
return language_get_string(STR_CHEAT_EXPLODE);
case CHEAT_GIVEALLGUESTS: case CHEAT_GIVEALLGUESTS:
{ {
static char cheat_string[64]; static char cheat_string[64];
safe_strcpy(cheat_string, language_get_string(STR_CHEAT_GIVE_ALL_GUESTS), 64); safe_strcpy(cheat_string, language_get_string(STR_CHEAT_GIVE_ALL_GUESTS), 64);
safe_strcat(cheat_string, " ", 64); safe_strcat(cheat_string, " ", 64);
switch (edx) { switch (edx)
{
case OBJECT_MONEY: case OBJECT_MONEY:
{ {
char money[16]; char money[16];
@@ -689,69 +868,112 @@ const char* cheats_get_cheat_string(int cheat, int edx, int edi) {
safe_strcat(cheat_string, money, 64); safe_strcat(cheat_string, money, 64);
break; break;
} }
case OBJECT_PARK_MAP: safe_strcat(cheat_string, language_get_string(STR_SHOP_ITEM_PLURAL_PARK_MAP), 64); break; case OBJECT_PARK_MAP:
case OBJECT_BALLOON: safe_strcat(cheat_string, language_get_string(STR_SHOP_ITEM_PLURAL_BALLOON), 64); break; safe_strcat(cheat_string, language_get_string(STR_SHOP_ITEM_PLURAL_PARK_MAP), 64);
case OBJECT_UMBRELLA: safe_strcat(cheat_string, language_get_string(STR_SHOP_ITEM_PLURAL_UMBRELLA), 64); break; break;
case OBJECT_BALLOON:
safe_strcat(cheat_string, language_get_string(STR_SHOP_ITEM_PLURAL_BALLOON), 64);
break;
case OBJECT_UMBRELLA:
safe_strcat(cheat_string, language_get_string(STR_SHOP_ITEM_PLURAL_UMBRELLA), 64);
break;
} }
return cheat_string; return cheat_string;
} }
case CHEAT_SETGRASSLENGTH: case CHEAT_SETGRASSLENGTH:
if (edx == 0) { if (edx == 0)
{
return language_get_string(STR_CHEAT_MOWED_GRASS); return language_get_string(STR_CHEAT_MOWED_GRASS);
} else if (edx == 1) { }
else if (edx == 1)
{
return language_get_string(STR_CHEAT_CLEAR_GRASS); return language_get_string(STR_CHEAT_CLEAR_GRASS);
} }
case CHEAT_WATERPLANTS: return language_get_string(STR_CHEAT_WATER_PLANTS); case CHEAT_WATERPLANTS:
case CHEAT_FIXVANDALISM: return language_get_string(STR_CHEAT_FIX_VANDALISM); return language_get_string(STR_CHEAT_WATER_PLANTS);
case CHEAT_REMOVELITTER: return language_get_string(STR_CHEAT_REMOVE_LITTER); case CHEAT_FIXVANDALISM:
case CHEAT_DISABLEPLANTAGING: return language_get_string(STR_CHEAT_DISABLE_PLANT_AGING); return language_get_string(STR_CHEAT_FIX_VANDALISM);
case CHEAT_REMOVELITTER:
return language_get_string(STR_CHEAT_REMOVE_LITTER);
case CHEAT_DISABLEPLANTAGING:
return language_get_string(STR_CHEAT_DISABLE_PLANT_AGING);
case CHEAT_SETSTAFFSPEED: case CHEAT_SETSTAFFSPEED:
{ {
static char cheat_string[64]; static char cheat_string[64];
safe_strcpy(cheat_string, language_get_string(STR_CHEAT_STAFF_SPEED), 64); safe_strcpy(cheat_string, language_get_string(STR_CHEAT_STAFF_SPEED), 64);
safe_strcat(cheat_string, " ", 64); safe_strcat(cheat_string, " ", 64);
if (edx == CHEATS_STAFF_FAST_SPEED) { if (edx == CHEATS_STAFF_FAST_SPEED)
{
safe_strcat(cheat_string, language_get_string(STR_FAST), 64); safe_strcat(cheat_string, language_get_string(STR_FAST), 64);
} else if (edx == CHEATS_STAFF_NORMAL_SPEED) { }
else if (edx == CHEATS_STAFF_NORMAL_SPEED)
{
safe_strcat(cheat_string, language_get_string(STR_NORMAL), 64); safe_strcat(cheat_string, language_get_string(STR_NORMAL), 64);
} }
return cheat_string; return cheat_string;
} }
case CHEAT_RENEWRIDES: return language_get_string(STR_CHEAT_RENEW_RIDES); case CHEAT_RENEWRIDES:
case CHEAT_MAKEDESTRUCTIBLE: return language_get_string(STR_CHEAT_MAKE_DESTRUCTABLE); return language_get_string(STR_CHEAT_RENEW_RIDES);
case CHEAT_FIXRIDES: return language_get_string(STR_CHEAT_FIX_ALL_RIDES); case CHEAT_MAKEDESTRUCTIBLE:
case CHEAT_RESETCRASHSTATUS: return language_get_string(STR_CHEAT_RESET_CRASH_STATUS); return language_get_string(STR_CHEAT_MAKE_DESTRUCTABLE);
case CHEAT_10MINUTEINSPECTIONS: return language_get_string(STR_CHEAT_10_MINUTE_INSPECTIONS); case CHEAT_FIXRIDES:
case CHEAT_WINSCENARIO: return language_get_string(STR_CHEAT_WIN_SCENARIO); return language_get_string(STR_CHEAT_FIX_ALL_RIDES);
case CHEAT_RESETCRASHSTATUS:
return language_get_string(STR_CHEAT_RESET_CRASH_STATUS);
case CHEAT_10MINUTEINSPECTIONS:
return language_get_string(STR_CHEAT_10_MINUTE_INSPECTIONS);
case CHEAT_WINSCENARIO:
return language_get_string(STR_CHEAT_WIN_SCENARIO);
case CHEAT_FORCEWEATHER: case CHEAT_FORCEWEATHER:
{ {
static char cheat_string[64]; static char cheat_string[64];
safe_strcpy(cheat_string, language_get_string(STR_FORCE_WEATHER), 64); safe_strcpy(cheat_string, language_get_string(STR_FORCE_WEATHER), 64);
safe_strcat(cheat_string, " ", 64); safe_strcat(cheat_string, " ", 64);
switch (edx) { switch (edx)
case 0: safe_strcat(cheat_string, language_get_string(STR_SUNNY), 64); break; {
case 1: safe_strcat(cheat_string, language_get_string(STR_PARTIALLY_CLOUDY), 64); break; case 0:
case 2: safe_strcat(cheat_string, language_get_string(STR_CLOUDY), 64); break; safe_strcat(cheat_string, language_get_string(STR_SUNNY), 64);
case 3: safe_strcat(cheat_string, language_get_string(STR_RAIN), 64); break; break;
case 4: safe_strcat(cheat_string, language_get_string(STR_HEAVY_RAIN), 64); break; case 1:
case 5: safe_strcat(cheat_string, language_get_string(STR_THUNDERSTORM), 64); break; safe_strcat(cheat_string, language_get_string(STR_PARTIALLY_CLOUDY), 64);
break;
case 2:
safe_strcat(cheat_string, language_get_string(STR_CLOUDY), 64);
break;
case 3:
safe_strcat(cheat_string, language_get_string(STR_RAIN), 64);
break;
case 4:
safe_strcat(cheat_string, language_get_string(STR_HEAVY_RAIN), 64);
break;
case 5:
safe_strcat(cheat_string, language_get_string(STR_THUNDERSTORM), 64);
break;
} }
return cheat_string; return cheat_string;
} }
case CHEAT_FREEZECLIMATE: case CHEAT_FREEZECLIMATE:
if (gCheatsFreezeClimate) { if (gCheatsFreezeClimate)
{
return language_get_string(STR_CHEAT_UNFREEZE_CLIMATE); return language_get_string(STR_CHEAT_UNFREEZE_CLIMATE);
} else { }
else
{
return language_get_string(STR_CHEAT_FREEZE_CLIMATE); return language_get_string(STR_CHEAT_FREEZE_CLIMATE);
} }
case CHEAT_NEVERENDINGMARKETING: return language_get_string(STR_CHEAT_NEVERENDING_MARKETING); case CHEAT_NEVERENDINGMARKETING:
return language_get_string(STR_CHEAT_NEVERENDING_MARKETING);
case CHEAT_OPENCLOSEPARK: case CHEAT_OPENCLOSEPARK:
if (park_is_open()) { if (park_is_open())
{
return language_get_string(STR_CHEAT_CLOSE_PARK); return language_get_string(STR_CHEAT_CLOSE_PARK);
} else { }
else
{
return language_get_string(STR_CHEAT_OPEN_PARK); return language_get_string(STR_CHEAT_OPEN_PARK);
} }
case CHEAT_HAVEFUN: return language_get_string(STR_CHEAT_HAVE_FUN); case CHEAT_HAVEFUN:
return language_get_string(STR_CHEAT_HAVE_FUN);
case CHEAT_SETFORCEDPARKRATING: case CHEAT_SETFORCEDPARKRATING:
{ {
static char cheat_string[64]; static char cheat_string[64];
@@ -765,13 +987,20 @@ const char* cheats_get_cheat_string(int cheat, int edx, int edi) {
return cheat_string; return cheat_string;
} }
case CHEAT_RESETDATE: return language_get_string(STR_CHEAT_RESET_DATE); case CHEAT_RESETDATE:
case CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES: return language_get_string(STR_CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES); return language_get_string(STR_CHEAT_RESET_DATE);
case CHEAT_SETMONEY: return language_get_string(STR_SET_MONEY); case CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES:
case CHEAT_OWNALLLAND: return language_get_string(STR_CHEAT_OWN_ALL_LAND); return language_get_string(STR_CHEAT_ALLOW_ARBITRARY_RIDE_TYPE_CHANGES);
case CHEAT_DISABLERIDEVALUEAGING: return language_get_string(STR_CHEAT_DISABLE_RIDE_VALUE_AGING); case CHEAT_SETMONEY:
case CHEAT_IGNORERESEARCHSTATUS: return language_get_string(STR_CHEAT_IGNORE_RESEARCH_STATUS); return language_get_string(STR_SET_MONEY);
case CHEAT_ENABLEALLDRAWABLETRACKPIECES: return language_get_string(STR_CHEAT_ENABLE_ALL_DRAWABLE_TRACK_PIECES); case CHEAT_OWNALLLAND:
return language_get_string(STR_CHEAT_OWN_ALL_LAND);
case CHEAT_DISABLERIDEVALUEAGING:
return language_get_string(STR_CHEAT_DISABLE_RIDE_VALUE_AGING);
case CHEAT_IGNORERESEARCHSTATUS:
return language_get_string(STR_CHEAT_IGNORE_RESEARCH_STATUS);
case CHEAT_ENABLEALLDRAWABLETRACKPIECES:
return language_get_string(STR_CHEAT_ENABLE_ALL_DRAWABLE_TRACK_PIECES);
} }
return ""; return "";

View File

@@ -34,8 +34,8 @@ extern bool gCheatsAllowArbitraryRideTypeChanges;
extern bool gCheatsIgnoreResearchStatus; extern bool gCheatsIgnoreResearchStatus;
extern bool gCheatsEnableAllDrawableTrackPieces; extern bool gCheatsEnableAllDrawableTrackPieces;
enum
enum { {
CHEAT_SANDBOXMODE, CHEAT_SANDBOXMODE,
CHEAT_DISABLECLEARANCECHECKS, CHEAT_DISABLECLEARANCECHECKS,
CHEAT_DISABLESUPPORTLIMITS, CHEAT_DISABLESUPPORTLIMITS,
@@ -87,7 +87,8 @@ enum {
CHEAT_DATE_SET, CHEAT_DATE_SET,
}; };
enum { enum
{
GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_HAPPINESS,
GUEST_PARAMETER_ENERGY, GUEST_PARAMETER_ENERGY,
GUEST_PARAMETER_HUNGER, GUEST_PARAMETER_HUNGER,
@@ -98,14 +99,15 @@ enum {
GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY
}; };
enum { enum
{
OBJECT_MONEY, OBJECT_MONEY,
OBJECT_PARK_MAP, OBJECT_PARK_MAP,
OBJECT_BALLOON, OBJECT_BALLOON,
OBJECT_UMBRELLA OBJECT_UMBRELLA
}; };
#define CHEATS_GIVE_GUESTS_MONEY MONEY(1000,00) #define CHEATS_GIVE_GUESTS_MONEY MONEY(1000, 00)
#define CHEATS_TRAM_INCREMENT 250 #define CHEATS_TRAM_INCREMENT 250
#define CHEATS_STAFF_FAST_SPEED 0xFF #define CHEATS_STAFF_FAST_SPEED 0xFF
#define CHEATS_STAFF_NORMAL_SPEED 0x60 #define CHEATS_STAFF_NORMAL_SPEED 0x60

View File

@@ -9,34 +9,39 @@
#pragma warning(disable : 4706) // assignment within conditional expression #pragma warning(disable : 4706) // assignment within conditional expression
#include <cmath>
#include <cstring>
#include <jansson.h>
#include "CmdlineSprite.h" #include "CmdlineSprite.h"
#include "OpenRCT2.h"
#include "core/Imaging.h" #include "core/Imaging.h"
#include "drawing/Drawing.h" #include "drawing/Drawing.h"
#include "drawing/ImageImporter.h" #include "drawing/ImageImporter.h"
#include "localisation/Language.h" #include "localisation/Language.h"
#include "OpenRCT2.h"
#include "platform/platform.h" #include "platform/platform.h"
#include "util/Util.h" #include "util/Util.h"
#include <cmath>
#include <cstring>
#include <jansson.h>
using namespace OpenRCT2::Drawing; using namespace OpenRCT2::Drawing;
#pragma pack(push, 1) #pragma pack(push, 1)
struct rct_sprite_file_header { struct rct_sprite_file_header
{
uint32_t num_entries; uint32_t num_entries;
uint32_t total_size; uint32_t total_size;
}; };
assert_struct_size(rct_sprite_file_header, 8); assert_struct_size(rct_sprite_file_header, 8);
struct rct_sprite_file_palette_entry { struct rct_sprite_file_palette_entry
{
uint8_t b, g, r, a; uint8_t b, g, r, a;
}; };
struct rle_code { struct rle_code
{
uint8_t num_pixels; uint8_t num_pixels;
uint8_t offset_x; uint8_t offset_x;
}; };
@@ -56,16 +61,16 @@ public:
static rct_sprite_file_palette_entry spriteFilePalette[256]; static rct_sprite_file_palette_entry spriteFilePalette[256];
static rct_sprite_file_header spriteFileHeader; static rct_sprite_file_header spriteFileHeader;
static rct_g1_element *spriteFileEntries; static rct_g1_element* spriteFileEntries;
static uint8_t *spriteFileData; static uint8_t* spriteFileData;
#ifdef _WIN32 #ifdef _WIN32
static FILE * fopen_utf8(const char * path, const char * mode) static FILE* fopen_utf8(const char* path, const char* mode)
{ {
wchar_t * pathW = utf8_to_widechar(path); wchar_t* pathW = utf8_to_widechar(path);
wchar_t * modeW = utf8_to_widechar(mode); wchar_t* modeW = utf8_to_widechar(mode);
FILE * file = _wfopen(pathW, modeW); FILE* file = _wfopen(pathW, modeW);
free(pathW); free(pathW);
free(modeW); free(modeW);
return file; return file;
@@ -87,33 +92,38 @@ static void sprite_entries_make_relative()
spriteFileEntries[i].offset -= (uintptr_t)spriteFileData; spriteFileEntries[i].offset -= (uintptr_t)spriteFileData;
} }
static bool sprite_file_open(const utf8 *path) static bool sprite_file_open(const utf8* path)
{ {
FILE * file = fopen(path, "rb"); FILE* file = fopen(path, "rb");
if (file == nullptr) if (file == nullptr)
return false; return false;
if (fread(&spriteFileHeader, sizeof(rct_sprite_file_header), 1, file) != 1) { if (fread(&spriteFileHeader, sizeof(rct_sprite_file_header), 1, file) != 1)
{
fclose(file); fclose(file);
return false; return false;
} }
if (spriteFileHeader.num_entries > 0) { if (spriteFileHeader.num_entries > 0)
{
int32_t openEntryTableSize = spriteFileHeader.num_entries * sizeof(rct_g1_element_32bit); int32_t openEntryTableSize = spriteFileHeader.num_entries * sizeof(rct_g1_element_32bit);
rct_g1_element_32bit * openElements = (rct_g1_element_32bit *)malloc(openEntryTableSize); rct_g1_element_32bit* openElements = (rct_g1_element_32bit*)malloc(openEntryTableSize);
if (openElements == nullptr) { if (openElements == nullptr)
{
fclose(file); fclose(file);
return false; return false;
} }
if (fread(openElements, openEntryTableSize, 1, file) != 1) { if (fread(openElements, openEntryTableSize, 1, file) != 1)
{
free(openElements); free(openElements);
fclose(file); fclose(file);
return false; return false;
} }
spriteFileData = (uint8_t *)malloc(spriteFileHeader.total_size); spriteFileData = (uint8_t*)malloc(spriteFileHeader.total_size);
if (fread(spriteFileData, spriteFileHeader.total_size, 1, file) != 1) { if (fread(spriteFileData, spriteFileHeader.total_size, 1, file) != 1)
{
free(spriteFileData); free(spriteFileData);
free(openElements); free(openElements);
fclose(file); fclose(file);
@@ -121,10 +131,11 @@ static bool sprite_file_open(const utf8 *path)
} }
int32_t entryTableSize = spriteFileHeader.num_entries * sizeof(rct_g1_element); int32_t entryTableSize = spriteFileHeader.num_entries * sizeof(rct_g1_element);
spriteFileEntries = (rct_g1_element *)malloc(entryTableSize); spriteFileEntries = (rct_g1_element*)malloc(entryTableSize);
for (uint32_t i = 0; i < spriteFileHeader.num_entries; i++) { for (uint32_t i = 0; i < spriteFileHeader.num_entries; i++)
rct_g1_element_32bit * inElement = &openElements[i]; {
rct_g1_element * outElement = &spriteFileEntries[i]; rct_g1_element_32bit* inElement = &openElements[i];
rct_g1_element* outElement = &spriteFileEntries[i];
outElement->offset = (uint8_t*)((uintptr_t)inElement->offset + (uintptr_t)spriteFileData); outElement->offset = (uint8_t*)((uintptr_t)inElement->offset + (uintptr_t)spriteFileData);
outElement->width = inElement->width; outElement->width = inElement->width;
@@ -142,28 +153,32 @@ static bool sprite_file_open(const utf8 *path)
return true; return true;
} }
static bool sprite_file_save(const char *path) static bool sprite_file_save(const char* path)
{ {
FILE * file = fopen(path, "wb"); FILE* file = fopen(path, "wb");
if (file == nullptr) if (file == nullptr)
return false; return false;
if (fwrite(&spriteFileHeader, sizeof(rct_sprite_file_header), 1, file) != 1) { if (fwrite(&spriteFileHeader, sizeof(rct_sprite_file_header), 1, file) != 1)
{
fclose(file); fclose(file);
return false; return false;
} }
if (spriteFileHeader.num_entries > 0) { if (spriteFileHeader.num_entries > 0)
{
int32_t saveEntryTableSize = spriteFileHeader.num_entries * sizeof(rct_g1_element_32bit); int32_t saveEntryTableSize = spriteFileHeader.num_entries * sizeof(rct_g1_element_32bit);
rct_g1_element_32bit * saveElements = (rct_g1_element_32bit *)malloc(saveEntryTableSize); rct_g1_element_32bit* saveElements = (rct_g1_element_32bit*)malloc(saveEntryTableSize);
if (saveElements == nullptr) { if (saveElements == nullptr)
{
fclose(file); fclose(file);
return false; return false;
} }
for (uint32_t i = 0; i < spriteFileHeader.num_entries; i++) { for (uint32_t i = 0; i < spriteFileHeader.num_entries; i++)
rct_g1_element * inElement = &spriteFileEntries[i]; {
rct_g1_element_32bit * outElement = &saveElements[i]; rct_g1_element* inElement = &spriteFileEntries[i];
rct_g1_element_32bit* outElement = &saveElements[i];
outElement->offset = (uint32_t)((uintptr_t)inElement->offset - (uintptr_t)spriteFileData); outElement->offset = (uint32_t)((uintptr_t)inElement->offset - (uintptr_t)spriteFileData);
outElement->width = inElement->width; outElement->width = inElement->width;
@@ -174,14 +189,16 @@ static bool sprite_file_save(const char *path)
outElement->zoomed_offset = inElement->zoomed_offset; outElement->zoomed_offset = inElement->zoomed_offset;
} }
if (fwrite(saveElements, saveEntryTableSize, 1, file) != 1) { if (fwrite(saveElements, saveEntryTableSize, 1, file) != 1)
{
free(saveElements); free(saveElements);
fclose(file); fclose(file);
return false; return false;
} }
free(saveElements); free(saveElements);
if (fwrite(spriteFileData, spriteFileHeader.total_size, 1, file) != 1) { if (fwrite(spriteFileData, spriteFileHeader.total_size, 1, file) != 1)
{
fclose(file); fclose(file);
return false; return false;
} }
@@ -197,16 +214,16 @@ static void sprite_file_close()
SafeFree(spriteFileData); SafeFree(spriteFileData);
} }
static bool sprite_file_export(int32_t spriteIndex, const char *outPath) static bool sprite_file_export(int32_t spriteIndex, const char* outPath)
{ {
rct_g1_element *spriteHeader; rct_g1_element* spriteHeader;
rct_drawpixelinfo dpi; rct_drawpixelinfo dpi;
uint8_t *pixels; uint8_t* pixels;
int32_t pixelBufferSize; int32_t pixelBufferSize;
spriteHeader = &spriteFileEntries[spriteIndex]; spriteHeader = &spriteFileEntries[spriteIndex];
pixelBufferSize = spriteHeader->width * spriteHeader->height; pixelBufferSize = spriteHeader->width * spriteHeader->height;
pixels = (uint8_t *)malloc(pixelBufferSize); pixels = (uint8_t*)malloc(pixelBufferSize);
memset(pixels, 0, pixelBufferSize); memset(pixels, 0, pixelBufferSize);
dpi.bits = pixels; dpi.bits = pixels;
@@ -219,10 +236,30 @@ static bool sprite_file_export(int32_t spriteIndex, const char *outPath)
memcpy(spriteFilePalette, CmdlineSprite::_standardPalette, 256 * 4); memcpy(spriteFilePalette, CmdlineSprite::_standardPalette, 256 * 4);
if (spriteHeader->flags & G1_FLAG_RLE_COMPRESSION) { if (spriteHeader->flags & G1_FLAG_RLE_COMPRESSION)
gfx_rle_sprite_to_buffer(spriteHeader->offset, pixels, (uint8_t*)spriteFilePalette, &dpi, IMAGE_TYPE_DEFAULT, 0, spriteHeader->height, 0, spriteHeader->width); {
} else { gfx_rle_sprite_to_buffer(
gfx_bmp_sprite_to_buffer((uint8_t*)spriteFilePalette, spriteHeader->offset, pixels, spriteHeader, &dpi, spriteHeader->height, spriteHeader->width, IMAGE_TYPE_DEFAULT); spriteHeader->offset,
pixels,
(uint8_t*)spriteFilePalette,
&dpi,
IMAGE_TYPE_DEFAULT,
0,
spriteHeader->height,
0,
spriteHeader->width);
}
else
{
gfx_bmp_sprite_to_buffer(
(uint8_t*)spriteFilePalette,
spriteHeader->offset,
pixels,
spriteHeader,
&dpi,
spriteHeader->height,
spriteHeader->width,
IMAGE_TYPE_DEFAULT);
} }
auto const pixels8 = dpi.bits; auto const pixels8 = dpi.bits;
@@ -234,7 +271,7 @@ static bool sprite_file_export(int32_t spriteIndex, const char *outPath)
image.Height = dpi.height; image.Height = dpi.height;
image.Depth = 8; image.Depth = 8;
image.Stride = dpi.width + dpi.pitch; image.Stride = dpi.width + dpi.pitch;
image.Palette = std::make_unique<rct_palette>(*((rct_palette *)&spriteFilePalette)); image.Palette = std::make_unique<rct_palette>(*((rct_palette*)&spriteFilePalette));
image.Pixels = std::vector<uint8_t>(pixels8, pixels8 + pixelsLen); image.Pixels = std::vector<uint8_t>(pixels8, pixels8 + pixelsLen);
Imaging::WriteToFile(outPath, image, IMAGE_FORMAT::PNG); Imaging::WriteToFile(outPath, image, IMAGE_FORMAT::PNG);
return true; return true;
@@ -246,7 +283,16 @@ static bool sprite_file_export(int32_t spriteIndex, const char *outPath)
} }
} }
static bool sprite_file_import(const char *path, int16_t x_offset, int16_t y_offset, bool keep_palette, bool forceBmp, rct_g1_element *outElement, uint8_t **outBuffer, int *outBufferLength, int32_t mode) static bool sprite_file_import(
const char* path,
int16_t x_offset,
int16_t y_offset,
bool keep_palette,
bool forceBmp,
rct_g1_element* outElement,
uint8_t** outBuffer,
int* outBufferLength,
int32_t mode)
{ {
try try
{ {
@@ -269,7 +315,7 @@ static bool sprite_file_import(const char *path, int16_t x_offset, int16_t y_off
auto result = importer.Import(image, x_offset, y_offset, flags, (ImageImporter::IMPORT_MODE)mode); auto result = importer.Import(image, x_offset, y_offset, flags, (ImageImporter::IMPORT_MODE)mode);
*outElement = result.Element; *outElement = result.Element;
*outBuffer = (uint8_t *)result.Buffer; *outBuffer = (uint8_t*)result.Buffer;
*outBufferLength = (int)result.BufferLength; *outBufferLength = (int)result.BufferLength;
return true; return true;
} }
@@ -280,20 +326,25 @@ static bool sprite_file_import(const char *path, int16_t x_offset, int16_t y_off
} }
} }
int32_t cmdline_for_sprite(const char **argv, int32_t argc) int32_t cmdline_for_sprite(const char** argv, int32_t argc)
{ {
gOpenRCT2Headless = true; gOpenRCT2Headless = true;
if (argc == 0) if (argc == 0)
return -1; return -1;
if (_strcmpi(argv[0], "details") == 0) { if (_strcmpi(argv[0], "details") == 0)
if (argc < 2) { {
if (argc < 2)
{
fprintf(stdout, "usage: sprite details <spritefile> [idx]\n"); fprintf(stdout, "usage: sprite details <spritefile> [idx]\n");
return -1; return -1;
} else if (argc == 2) { }
const char *spriteFilePath = argv[1]; else if (argc == 2)
{
const char* spriteFilePath = argv[1];
if (!sprite_file_open(spriteFilePath)) { if (!sprite_file_open(spriteFilePath))
{
fprintf(stderr, "Unable to open input sprite file.\n"); fprintf(stderr, "Unable to open input sprite file.\n");
return -1; return -1;
} }
@@ -303,22 +354,26 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
sprite_file_close(); sprite_file_close();
return 1; return 1;
} else { }
const char *spriteFilePath = argv[1]; else
{
const char* spriteFilePath = argv[1];
int32_t spriteIndex = atoi(argv[2]); int32_t spriteIndex = atoi(argv[2]);
if (!sprite_file_open(spriteFilePath)) { if (!sprite_file_open(spriteFilePath))
{
fprintf(stderr, "Unable to open input sprite file.\n"); fprintf(stderr, "Unable to open input sprite file.\n");
return -1; return -1;
} }
if (spriteIndex < 0 || spriteIndex >= (int32_t)spriteFileHeader.num_entries) { if (spriteIndex < 0 || spriteIndex >= (int32_t)spriteFileHeader.num_entries)
{
sprite_file_close(); sprite_file_close();
fprintf(stderr, "Sprite #%d does not exist in sprite file.\n", spriteIndex); fprintf(stderr, "Sprite #%d does not exist in sprite file.\n", spriteIndex);
return -1; return -1;
} }
rct_g1_element *g1 = &spriteFileEntries[spriteIndex]; rct_g1_element* g1 = &spriteFileEntries[spriteIndex];
printf("width: %d\n", g1->width); printf("width: %d\n", g1->width);
printf("height: %d\n", g1->height); printf("height: %d\n", g1->height);
printf("x offset: %d\n", g1->x_offset); printf("x offset: %d\n", g1->x_offset);
@@ -328,27 +383,33 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
sprite_file_close(); sprite_file_close();
return 1; return 1;
} }
} else if (_strcmpi(argv[0], "export") == 0) { }
if (argc < 4) { else if (_strcmpi(argv[0], "export") == 0)
{
if (argc < 4)
{
fprintf(stdout, "usage: sprite export <spritefile> <idx> <output>\n"); fprintf(stdout, "usage: sprite export <spritefile> <idx> <output>\n");
return -1; return -1;
} }
const char *spriteFilePath = argv[1]; const char* spriteFilePath = argv[1];
int32_t spriteIndex = atoi(argv[2]); int32_t spriteIndex = atoi(argv[2]);
const char *outputPath = argv[3]; const char* outputPath = argv[3];
if (!sprite_file_open(spriteFilePath)) { if (!sprite_file_open(spriteFilePath))
{
fprintf(stderr, "Unable to open input sprite file.\n"); fprintf(stderr, "Unable to open input sprite file.\n");
return -1; return -1;
} }
if (spriteIndex < 0 || spriteIndex >= (int32_t)spriteFileHeader.num_entries) { if (spriteIndex < 0 || spriteIndex >= (int32_t)spriteFileHeader.num_entries)
{
fprintf(stderr, "Sprite #%d does not exist in sprite file.\n", spriteIndex); fprintf(stderr, "Sprite #%d does not exist in sprite file.\n", spriteIndex);
return -1; return -1;
} }
if (!sprite_file_export(spriteIndex, outputPath)) { if (!sprite_file_export(spriteIndex, outputPath))
{
fprintf(stderr, "Could not export\n"); fprintf(stderr, "Could not export\n");
sprite_file_close(); sprite_file_close();
return -1; return -1;
@@ -356,16 +417,20 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
sprite_file_close(); sprite_file_close();
return 1; return 1;
} else if (_strcmpi(argv[0], "exportall") == 0) { }
if (argc < 3) { else if (_strcmpi(argv[0], "exportall") == 0)
{
if (argc < 3)
{
fprintf(stdout, "usage: sprite exportall <spritefile> <output directory>\n"); fprintf(stdout, "usage: sprite exportall <spritefile> <output directory>\n");
return -1; return -1;
} }
const char *spriteFilePath = argv[1]; const char* spriteFilePath = argv[1];
char outputPath[MAX_PATH]; char outputPath[MAX_PATH];
if (!sprite_file_open(spriteFilePath)) { if (!sprite_file_open(spriteFilePath))
{
fprintf(stderr, "Unable to open input sprite file.\n"); fprintf(stderr, "Unable to open input sprite file.\n");
return -1; return -1;
} }
@@ -373,7 +438,8 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
safe_strcpy(outputPath, argv[2], MAX_PATH); safe_strcpy(outputPath, argv[2], MAX_PATH);
path_end_with_separator(outputPath, MAX_PATH); path_end_with_separator(outputPath, MAX_PATH);
if (!platform_ensure_directory_exists(outputPath)){ if (!platform_ensure_directory_exists(outputPath))
{
fprintf(stderr, "Unable to create directory.\n"); fprintf(stderr, "Unable to create directory.\n");
return -1; return -1;
} }
@@ -382,18 +448,20 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
int32_t numbers = (int32_t)std::floor(std::log(maxIndex)); int32_t numbers = (int32_t)std::floor(std::log(maxIndex));
size_t pathLen = strlen(outputPath); size_t pathLen = strlen(outputPath);
if (pathLen >= (size_t)(MAX_PATH - numbers - 5)) { if (pathLen >= (size_t)(MAX_PATH - numbers - 5))
{
fprintf(stderr, "Path too long.\n"); fprintf(stderr, "Path too long.\n");
return -1; return -1;
} }
for (int32_t x = 0; x < numbers; x++){ for (int32_t x = 0; x < numbers; x++)
{
outputPath[pathLen + x] = '0'; outputPath[pathLen + x] = '0';
} }
safe_strcpy(outputPath + pathLen + numbers, ".png", MAX_PATH - pathLen - numbers); safe_strcpy(outputPath + pathLen + numbers, ".png", MAX_PATH - pathLen - numbers);
for (int32_t spriteIndex = 0; spriteIndex < maxIndex; spriteIndex++){ for (int32_t spriteIndex = 0; spriteIndex < maxIndex; spriteIndex++)
{
if (spriteIndex % 100 == 99) if (spriteIndex % 100 == 99)
{ {
// Status indicator // Status indicator
@@ -408,7 +476,7 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
} }
// Add to the index at the end of the file name // Add to the index at the end of the file name
char *counter = outputPath + pathLen + numbers - 1; char* counter = outputPath + pathLen + numbers - 1;
(*counter)++; (*counter)++;
while (*counter > '9') while (*counter > '9')
{ {
@@ -420,14 +488,16 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
sprite_file_close(); sprite_file_close();
return 1; return 1;
}
} else if (_strcmpi(argv[0], "create") == 0) { else if (_strcmpi(argv[0], "create") == 0)
if (argc < 2) { {
if (argc < 2)
{
fprintf(stderr, "usage: sprite create <spritefile>\n"); fprintf(stderr, "usage: sprite create <spritefile>\n");
return -1; return -1;
} }
const char *spriteFilePath = argv[1]; const char* spriteFilePath = argv[1];
spriteFileHeader.num_entries = 0; spriteFileHeader.num_entries = 0;
spriteFileHeader.total_size = 0; spriteFileHeader.total_size = 0;
@@ -435,21 +505,23 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
sprite_file_close(); sprite_file_close();
return 1; return 1;
} else if (_strcmpi(argv[0], "append") == 0) { }
if (argc != 3 && argc != 5) { else if (_strcmpi(argv[0], "append") == 0)
{
if (argc != 3 && argc != 5)
{
fprintf(stderr, "usage: sprite append <spritefile> <input> [<x offset> <y offset>]\n"); fprintf(stderr, "usage: sprite append <spritefile> <input> [<x offset> <y offset>]\n");
return -1; return -1;
} }
const char* spriteFilePath = argv[1];
const char *spriteFilePath = argv[1]; const char* imagePath = argv[2];
const char *imagePath = argv[2];
int16_t x_offset = 0; int16_t x_offset = 0;
int16_t y_offset = 0; int16_t y_offset = 0;
if (argc == 5) if (argc == 5)
{ {
char *endptr; char* endptr;
x_offset = strtol(argv[3], &endptr, 0); x_offset = strtol(argv[3], &endptr, 0);
if (*endptr != 0) if (*endptr != 0)
@@ -467,50 +539,61 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
} }
rct_g1_element spriteElement; rct_g1_element spriteElement;
uint8_t *buffer; uint8_t* buffer;
int32_t bufferLength; int32_t bufferLength;
if (!sprite_file_import(imagePath, x_offset, y_offset, false, false, &spriteElement, &buffer, &bufferLength, gSpriteMode)) if (!sprite_file_import(
imagePath, x_offset, y_offset, false, false, &spriteElement, &buffer, &bufferLength, gSpriteMode))
return -1; return -1;
if (!sprite_file_open(spriteFilePath)) { if (!sprite_file_open(spriteFilePath))
{
fprintf(stderr, "Unable to open input sprite file.\n"); fprintf(stderr, "Unable to open input sprite file.\n");
return -1; return -1;
} }
spriteFileHeader.num_entries++; spriteFileHeader.num_entries++;
spriteFileHeader.total_size += bufferLength; spriteFileHeader.total_size += bufferLength;
spriteFileEntries = (rct_g1_element *)realloc(spriteFileEntries, spriteFileHeader.num_entries * sizeof(rct_g1_element)); spriteFileEntries = (rct_g1_element*)realloc(spriteFileEntries, spriteFileHeader.num_entries * sizeof(rct_g1_element));
sprite_entries_make_relative(); sprite_entries_make_relative();
spriteFileData = (uint8_t *)realloc(spriteFileData, spriteFileHeader.total_size); spriteFileData = (uint8_t*)realloc(spriteFileData, spriteFileHeader.total_size);
sprite_entries_make_absolute(); sprite_entries_make_absolute();
spriteFileEntries[spriteFileHeader.num_entries - 1] = spriteElement; spriteFileEntries[spriteFileHeader.num_entries - 1] = spriteElement;
memcpy(spriteFileData + (spriteFileHeader.total_size - bufferLength), buffer, bufferLength); memcpy(spriteFileData + (spriteFileHeader.total_size - bufferLength), buffer, bufferLength);
spriteFileEntries[spriteFileHeader.num_entries - 1].offset = spriteFileData + (spriteFileHeader.total_size - bufferLength); spriteFileEntries[spriteFileHeader.num_entries - 1].offset
= spriteFileData + (spriteFileHeader.total_size - bufferLength);
free(buffer); free(buffer);
if (!sprite_file_save(spriteFilePath)) if (!sprite_file_save(spriteFilePath))
return -1; return -1;
return 1; return 1;
} else if (_strcmpi(argv[0], "build") == 0) { }
if (argc < 3) { else if (_strcmpi(argv[0], "build") == 0)
{
if (argc < 3)
{
fprintf(stdout, "usage: sprite build <spritefile> <sprite description file> [silent]\n"); fprintf(stdout, "usage: sprite build <spritefile> <sprite description file> [silent]\n");
return -1; return -1;
} }
const char *spriteFilePath = argv[1]; const char* spriteFilePath = argv[1];
const char *spriteDescriptionPath = argv[2]; const char* spriteDescriptionPath = argv[2];
char* directoryPath = path_get_directory(spriteDescriptionPath); char* directoryPath = path_get_directory(spriteDescriptionPath);
json_error_t error; json_error_t error;
json_t* sprite_list=json_load_file(spriteDescriptionPath, JSON_REJECT_DUPLICATES, &error); json_t* sprite_list = json_load_file(spriteDescriptionPath, JSON_REJECT_DUPLICATES, &error);
if (sprite_list == nullptr) if (sprite_list == nullptr)
{ {
fprintf(stderr, "Error parsing sprite description file: %s at line %d column %d\n", error.text, error.line, error.column); fprintf(
stderr,
"Error parsing sprite description file: %s at line %d column %d\n",
error.text,
error.line,
error.column);
return -1; return -1;
} }
@@ -534,15 +617,15 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
json_array_foreach(sprite_list, i, sprite_description) json_array_foreach(sprite_list, i, sprite_description)
{ {
if(!json_is_object(sprite_description)) if (!json_is_object(sprite_description))
{ {
fprintf(stderr, "Error: expected object for sprite %lu\n", (unsigned long)i); fprintf(stderr, "Error: expected object for sprite %lu\n", (unsigned long)i);
json_decref(sprite_list); json_decref(sprite_list);
return -1; return -1;
} }
json_t* path = json_object_get(sprite_description,"path"); json_t* path = json_object_get(sprite_description, "path");
if(!path || !json_is_string(path)) if (!path || !json_is_string(path))
{ {
fprintf(stderr, "Error: no path provided for sprite %lu\n", (unsigned long)i); fprintf(stderr, "Error: no path provided for sprite %lu\n", (unsigned long)i);
json_decref(sprite_list); json_decref(sprite_list);
@@ -557,7 +640,7 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
json_t* palette = json_object_get(sprite_description, "palette"); json_t* palette = json_object_get(sprite_description, "palette");
if (palette && json_is_string(palette)) if (palette && json_is_string(palette))
{ {
const char *option = json_string_value(palette); const char* option = json_string_value(palette);
if (strncmp(option, "keep", 4) == 0) if (strncmp(option, "keep", 4) == 0)
{ {
keep_palette = true; keep_palette = true;
@@ -573,16 +656,22 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
} }
// Resolve absolute sprite path // Resolve absolute sprite path
char *imagePath = platform_get_absolute_path(json_string_value(path), directoryPath); char* imagePath = platform_get_absolute_path(json_string_value(path), directoryPath);
rct_g1_element spriteElement; rct_g1_element spriteElement;
uint8_t *buffer; uint8_t* buffer;
int bufferLength; int bufferLength;
if (!sprite_file_import(imagePath, if (!sprite_file_import(
imagePath,
x_offset == nullptr ? 0 : json_integer_value(x_offset), x_offset == nullptr ? 0 : json_integer_value(x_offset),
y_offset == nullptr ? 0 : json_integer_value(y_offset), y_offset == nullptr ? 0 : json_integer_value(y_offset),
keep_palette, forceBmp, &spriteElement, &buffer, &bufferLength, gSpriteMode)) keep_palette,
forceBmp,
&spriteElement,
&buffer,
&bufferLength,
gSpriteMode))
{ {
fprintf(stderr, "Could not import image file: %s\nCanceling\n", imagePath); fprintf(stderr, "Could not import image file: %s\nCanceling\n", imagePath);
json_decref(sprite_list); json_decref(sprite_list);
@@ -600,15 +689,17 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
spriteFileHeader.num_entries++; spriteFileHeader.num_entries++;
spriteFileHeader.total_size += bufferLength; spriteFileHeader.total_size += bufferLength;
spriteFileEntries = (rct_g1_element *)realloc(spriteFileEntries, spriteFileHeader.num_entries * sizeof(rct_g1_element)); spriteFileEntries
= (rct_g1_element*)realloc(spriteFileEntries, spriteFileHeader.num_entries * sizeof(rct_g1_element));
sprite_entries_make_relative(); sprite_entries_make_relative();
spriteFileData = (uint8_t *)realloc(spriteFileData, spriteFileHeader.total_size); spriteFileData = (uint8_t*)realloc(spriteFileData, spriteFileHeader.total_size);
sprite_entries_make_absolute(); sprite_entries_make_absolute();
spriteFileEntries[spriteFileHeader.num_entries - 1] = spriteElement; spriteFileEntries[spriteFileHeader.num_entries - 1] = spriteElement;
memcpy(spriteFileData + (spriteFileHeader.total_size - bufferLength), buffer, bufferLength); memcpy(spriteFileData + (spriteFileHeader.total_size - bufferLength), buffer, bufferLength);
spriteFileEntries[spriteFileHeader.num_entries - 1].offset = spriteFileData + (spriteFileHeader.total_size - bufferLength); spriteFileEntries[spriteFileHeader.num_entries - 1].offset
= spriteFileData + (spriteFileHeader.total_size - bufferLength);
free(buffer); free(buffer);
@@ -625,7 +716,6 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
free(imagePath); free(imagePath);
sprite_file_close(); sprite_file_close();
} }
json_decref(sprite_list); json_decref(sprite_list);
@@ -633,7 +723,9 @@ int32_t cmdline_for_sprite(const char **argv, int32_t argc)
fprintf(stdout, "Finished\n"); fprintf(stdout, "Finished\n");
return 1; return 1;
} else { }
else
{
fprintf(stderr, "Unknown sprite command.\n"); fprintf(stderr, "Unknown sprite command.\n");
return 1; return 1;
} }

View File

@@ -12,7 +12,7 @@
#include "common.h" #include "common.h"
int32_t cmdline_for_sprite(const char **argv, int32_t argc); int32_t cmdline_for_sprite(const char** argv, int32_t argc);
extern int32_t gSpriteMode; extern int32_t gSpriteMode;
#endif #endif

View File

@@ -13,11 +13,22 @@
#include <memory> #include <memory>
#include <string> #include <string>
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#include <emscripten.h> #include <emscripten.h>
#endif // __EMSCRIPTEN__ #endif // __EMSCRIPTEN__
#include "audio/AudioContext.h"
#include "Context.h" #include "Context.h"
#include "ui/UiContext.h" #include "Editor.h"
#include "FileClassifier.h"
#include "Game.h"
#include "GameState.h"
#include "Input.h"
#include "Intro.h"
#include "OpenRCT2.h"
#include "ParkImporter.h"
#include "PlatformEnvironment.h"
#include "Version.h"
#include "audio/AudioContext.h"
#include "audio/audio.h"
#include "config/Config.h"
#include "core/Console.hpp" #include "core/Console.hpp"
#include "core/File.h" #include "core/File.h"
#include "core/FileScanner.h" #include "core/FileScanner.h"
@@ -29,45 +40,31 @@
#include "core/String.hpp" #include "core/String.hpp"
#include "core/Util.hpp" #include "core/Util.hpp"
#include "drawing/IDrawingEngine.h" #include "drawing/IDrawingEngine.h"
#include "localisation/Localisation.h"
#include "FileClassifier.h"
#include "GameState.h"
#include "network/network.h"
#include "object/ObjectManager.h"
#include "object/ObjectRepository.h"
#include "OpenRCT2.h"
#include "paint/Painter.h"
#include "ParkImporter.h"
#include "platform/Crash.h"
#include "PlatformEnvironment.h"
#include "ride/TrackDesignRepository.h"
#include "scenario/Scenario.h"
#include "scenario/ScenarioRepository.h"
#include "title/TitleScreen.h"
#include "title/TitleSequenceManager.h"
#include "ui/WindowManager.h"
#include "world/Park.h"
#include "Version.h"
#include "Editor.h"
#include "Game.h"
#include "Input.h"
#include "Intro.h"
#include "audio/audio.h"
#include "config/Config.h"
#include "drawing/LightFX.h" #include "drawing/LightFX.h"
#include "interface/Chat.h" #include "interface/Chat.h"
#include "interface/InteractiveConsole.h" #include "interface/InteractiveConsole.h"
#include "interface/Viewport.h" #include "interface/Viewport.h"
#include "Intro.h"
#include "localisation/Date.h" #include "localisation/Date.h"
#include "localisation/Localisation.h"
#include "localisation/LocalisationService.h" #include "localisation/LocalisationService.h"
#include "network/DiscordService.h" #include "network/DiscordService.h"
#include "network/Http.h" #include "network/Http.h"
#include "network/network.h" #include "network/network.h"
#include "network/twitch.h" #include "network/twitch.h"
#include "object/ObjectManager.h"
#include "object/ObjectRepository.h"
#include "paint/Painter.h"
#include "platform/Crash.h"
#include "platform/platform.h" #include "platform/platform.h"
#include "ride/TrackDesignRepository.h"
#include "scenario/Scenario.h"
#include "scenario/ScenarioRepository.h"
#include "title/TitleScreen.h"
#include "title/TitleSequenceManager.h"
#include "ui/UiContext.h"
#include "ui/WindowManager.h"
#include "util/Util.h" #include "util/Util.h"
#include "world/Park.h"
using namespace OpenRCT2; using namespace OpenRCT2;
using namespace OpenRCT2::Audio; using namespace OpenRCT2::Audio;
@@ -115,24 +112,25 @@ namespace OpenRCT2
uint32_t _lastUpdateTick = 0; uint32_t _lastUpdateTick = 0;
bool _variableFrame = false; bool _variableFrame = false;
/** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to false. */ /** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to
* false. */
bool _finished = false; bool _finished = false;
public: public:
// Singleton of Context. // Singleton of Context.
// Remove this when GetContext() is no longer called so that // Remove this when GetContext() is no longer called so that
// multiple instances can be created in parallel // multiple instances can be created in parallel
static Context * Instance; static Context* Instance;
public: public:
Context( Context(
const std::shared_ptr<IPlatformEnvironment>& env, const std::shared_ptr<IPlatformEnvironment>& env,
const std::shared_ptr<IAudioContext>& audioContext, const std::shared_ptr<IAudioContext>& audioContext,
const std::shared_ptr<IUiContext>& uiContext) const std::shared_ptr<IUiContext>& uiContext)
: _env(env), : _env(env)
_audioContext(audioContext), , _audioContext(audioContext)
_uiContext(uiContext), , _uiContext(uiContext)
_localisationService(std::make_shared<LocalisationService>(env)) , _localisationService(std::make_shared<LocalisationService>(env))
{ {
Instance = this; Instance = this;
} }
@@ -159,7 +157,7 @@ namespace OpenRCT2
return _uiContext; return _uiContext;
} }
GameState * GetGameState() override GameState* GetGameState() override
{ {
return _gameState.get(); return _gameState.get();
} }
@@ -184,12 +182,12 @@ namespace OpenRCT2
return _objectRepository; return _objectRepository;
} }
ITrackDesignRepository * GetTrackDesignRepository() override ITrackDesignRepository* GetTrackDesignRepository() override
{ {
return _trackDesignRepository.get(); return _trackDesignRepository.get();
} }
IScenarioRepository * GetScenarioRepository() override IScenarioRepository* GetScenarioRepository() override
{ {
return _scenarioRepository.get(); return _scenarioRepository.get();
} }
@@ -199,12 +197,12 @@ namespace OpenRCT2
return _drawingEngineType; return _drawingEngineType;
} }
IDrawingEngine * GetDrawingEngine() override IDrawingEngine* GetDrawingEngine() override
{ {
return _drawingEngine.get(); return _drawingEngine.get();
} }
int32_t RunOpenRCT2(int argc, const char * * argv) override int32_t RunOpenRCT2(int argc, const char** argv) override
{ {
if (Initialise()) if (Initialise())
{ {
@@ -213,7 +211,7 @@ namespace OpenRCT2
return gExitCode; return gExitCode;
} }
void WriteLine(const std::string &s) override void WriteLine(const std::string& s) override
{ {
_stdInOutConsole.WriteLine(s); _stdInOutConsole.WriteLine(s);
} }
@@ -234,60 +232,14 @@ namespace OpenRCT2
std::string GetPathLegacy(int32_t pathId) override std::string GetPathLegacy(int32_t pathId) override
{ {
static constexpr const char * const LegacyFileNames[PATH_ID_END] = static constexpr const char* const LegacyFileNames[PATH_ID_END]
{ = { nullptr, nullptr, "css1.dat", "css2.dat", "css4.dat", "css5.dat", "css6.dat", "css7.dat",
nullptr, "css8.dat", "css9.dat", "css11.dat", "css12.dat", "css13.dat", "css14.dat", "css15.dat", "css3.dat",
nullptr, "css17.dat", "css18.dat", "css19.dat", "css20.dat", "css21.dat", "css22.dat", nullptr, "css23.dat",
"css1.dat", "css24.dat", "css25.dat", "css26.dat", "css27.dat", "css28.dat", "css29.dat", "css30.dat", "css31.dat",
"css2.dat", "css32.dat", "css33.dat", "css34.dat", "css35.dat", "css36.dat", "css37.dat", "css38.dat", "CUSTOM1.WAV",
"css4.dat", "CUSTOM2.WAV", "css39.dat", "css40.dat", "css41.dat", nullptr, "css42.dat", "css43.dat", "css44.dat",
"css5.dat", "css45.dat", "css46.dat", "css50.dat" };
"css6.dat",
"css7.dat",
"css8.dat",
"css9.dat",
"css11.dat",
"css12.dat",
"css13.dat",
"css14.dat",
"css15.dat",
"css3.dat",
"css17.dat",
"css18.dat",
"css19.dat",
"css20.dat",
"css21.dat",
"css22.dat",
nullptr,
"css23.dat",
"css24.dat",
"css25.dat",
"css26.dat",
"css27.dat",
"css28.dat",
"css29.dat",
"css30.dat",
"css31.dat",
"css32.dat",
"css33.dat",
"css34.dat",
"css35.dat",
"css36.dat",
"css37.dat",
"css38.dat",
"CUSTOM1.WAV",
"CUSTOM2.WAV",
"css39.dat",
"css40.dat",
"css41.dat",
nullptr,
"css42.dat",
"css43.dat",
"css44.dat",
"css45.dat",
"css46.dat",
"css50.dat"
};
std::string result; std::string result;
if (pathId == PATH_ID_CSS50) if (pathId == PATH_ID_CSS50)
@@ -479,7 +431,7 @@ namespace OpenRCT2
drawingEngine->SetVSync(gConfigGeneral.use_vsync); drawingEngine->SetVSync(gConfigGeneral.use_vsync);
_drawingEngine = std::unique_ptr<IDrawingEngine>(std::move(drawingEngine)); _drawingEngine = std::unique_ptr<IDrawingEngine>(std::move(drawingEngine));
} }
catch (const std::exception &ex) catch (const std::exception& ex)
{ {
_painter = nullptr; _painter = nullptr;
if (_drawingEngineType == DRAWING_ENGINE_SOFTWARE) if (_drawingEngineType == DRAWING_ENGINE_SOFTWARE)
@@ -509,27 +461,26 @@ namespace OpenRCT2
_painter = nullptr; _painter = nullptr;
} }
bool LoadParkFromFile(const std::string &path, bool loadTitleScreenOnFail) final override bool LoadParkFromFile(const std::string& path, bool loadTitleScreenOnFail) final override
{ {
try try
{ {
auto fs = FileStream(path, FILE_MODE_OPEN); auto fs = FileStream(path, FILE_MODE_OPEN);
return LoadParkFromStream(&fs, path, loadTitleScreenOnFail); return LoadParkFromStream(&fs, path, loadTitleScreenOnFail);
} }
catch (const std::exception &e) catch (const std::exception& e)
{ {
Console::Error::WriteLine(e.what()); Console::Error::WriteLine(e.what());
} }
return false; return false;
} }
bool LoadParkFromStream(IStream * stream, const std::string &path, bool loadTitleScreenFirstOnFail) final override bool LoadParkFromStream(IStream* stream, const std::string& path, bool loadTitleScreenFirstOnFail) final override
{ {
ClassifiedFileInfo info; ClassifiedFileInfo info;
if (TryClassifyFile(stream, &info)) if (TryClassifyFile(stream, &info))
{ {
if (info.Type == FILE_TYPE::SAVED_GAME || if (info.Type == FILE_TYPE::SAVED_GAME || info.Type == FILE_TYPE::SCENARIO)
info.Type == FILE_TYPE::SCENARIO)
{ {
std::unique_ptr<IParkImporter> parkImporter; std::unique_ptr<IParkImporter> parkImporter;
if (info.Version <= FILE_TYPE_S4_CUTOFF) if (info.Version <= FILE_TYPE_S4_CUTOFF)
@@ -545,7 +496,8 @@ namespace OpenRCT2
try try
{ {
auto result = parkImporter->LoadFromStream(stream, info.Type == FILE_TYPE::SCENARIO, false, path.c_str()); auto result
= parkImporter->LoadFromStream(stream, info.Type == FILE_TYPE::SCENARIO, false, path.c_str());
_objectManager->LoadObjects(result.RequiredObjects.data(), result.RequiredObjects.size()); _objectManager->LoadObjects(result.RequiredObjects.data(), result.RequiredObjects.size());
parkImporter->Import(); parkImporter->Import();
String::Set(gScenarioSavePath, Util::CountOf(gScenarioSavePath), path.c_str()); String::Set(gScenarioSavePath, Util::CountOf(gScenarioSavePath), path.c_str());
@@ -596,7 +548,7 @@ namespace OpenRCT2
// which the window function doesn't like // which the window function doesn't like
auto intent = Intent(WC_OBJECT_LOAD_ERROR); auto intent = Intent(WC_OBJECT_LOAD_ERROR);
intent.putExtra(INTENT_EXTRA_PATH, path); intent.putExtra(INTENT_EXTRA_PATH, path);
intent.putExtra(INTENT_EXTRA_LIST, (void *)e.MissingObjects.data()); intent.putExtra(INTENT_EXTRA_LIST, (void*)e.MissingObjects.data());
intent.putExtra(INTENT_EXTRA_LIST_COUNT, (uint32_t)e.MissingObjects.size()); intent.putExtra(INTENT_EXTRA_LIST_COUNT, (uint32_t)e.MissingObjects.size());
auto windowManager = _uiContext->GetWindowManager(); auto windowManager = _uiContext->GetWindowManager();
@@ -649,7 +601,8 @@ namespace OpenRCT2
{ {
utf8 path[MAX_PATH]; utf8 path[MAX_PATH];
config_get_default_path(path, sizeof(path)); config_get_default_path(path, sizeof(path));
Console::Error::WriteLine("An RCT2 install directory must be specified! Please edit \"game_path\" in %s.\n", path); Console::Error::WriteLine(
"An RCT2 install directory must be specified! Please edit \"game_path\" in %s.\n", path);
return std::string(); return std::string();
} }
} }
@@ -696,7 +649,8 @@ namespace OpenRCT2
} }
} }
switch (gOpenRCT2StartupAction) { switch (gOpenRCT2StartupAction)
{
case STARTUP_ACTION_INTRO: case STARTUP_ACTION_INTRO:
gIntroState = INTRO_STATE_PUBLISHER_BEGIN; gIntroState = INTRO_STATE_PUBLISHER_BEGIN;
title_load(); title_load();
@@ -712,7 +666,7 @@ namespace OpenRCT2
{ {
#ifndef DISABLE_HTTP #ifndef DISABLE_HTTP
// Download park and open it using its temporary filename // Download park and open it using its temporary filename
void * data; void* data;
size_t dataSize = Network::Http::DownloadPark(gOpenRCT2StartupActionPath, &data); size_t dataSize = Network::Http::DownloadPark(gOpenRCT2StartupActionPath, &data);
if (dataSize == 0) if (dataSize == 0)
{ {
@@ -738,7 +692,7 @@ namespace OpenRCT2
break; break;
} }
} }
catch (const std::exception &ex) catch (const std::exception& ex)
{ {
Console::Error::WriteLine("Failed to load '%s'", gOpenRCT2StartupActionPath); Console::Error::WriteLine("Failed to load '%s'", gOpenRCT2StartupActionPath);
Console::Error::WriteLine("%s", ex.what()); Console::Error::WriteLine("%s", ex.what());
@@ -808,10 +762,14 @@ namespace OpenRCT2
bool ShouldRunVariableFrame() bool ShouldRunVariableFrame()
{ {
if (!gConfigGeneral.uncap_fps) return false; if (!gConfigGeneral.uncap_fps)
if (gGameSpeed > 4) return false; return false;
if (gOpenRCT2Headless) return false; if (gGameSpeed > 4)
if (_uiContext->IsMinimised()) return false; return false;
if (gOpenRCT2Headless)
return false;
if (_uiContext->IsMinimised())
return false;
return true; return true;
} }
@@ -828,14 +786,16 @@ namespace OpenRCT2
do do
{ {
RunFrame(); RunFrame();
} } while (!_finished);
while (!_finished);
#else #else
emscripten_set_main_loop_arg([](void * vctx) -> emscripten_set_main_loop_arg(
{ [](void* vctx) -> {
auto ctx = reinterpret_cast<Context *>(vctx); auto ctx = reinterpret_cast<Context*>(vctx);
ctx->RunFrame(); ctx->RunFrame();
}, this, 0, 1); },
this,
0,
1);
#endif // __EMSCRIPTEN__ #endif // __EMSCRIPTEN__
log_verbose("finish openrct2 loop"); log_verbose("finish openrct2 loop");
} }
@@ -914,7 +874,7 @@ namespace OpenRCT2
while (_accumulator >= GAME_UPDATE_TIME_MS) while (_accumulator >= GAME_UPDATE_TIME_MS)
{ {
// Get the original position of each sprite // Get the original position of each sprite
if(draw) if (draw)
sprite_position_tween_store_a(); sprite_position_tween_store_a();
Update(); Update();
@@ -922,7 +882,7 @@ namespace OpenRCT2
_accumulator -= GAME_UPDATE_TIME_MS; _accumulator -= GAME_UPDATE_TIME_MS;
// Get the next position of each sprite // Get the next position of each sprite
if(draw) if (draw)
sprite_position_tween_store_b(); sprite_position_tween_store_b();
} }
@@ -987,14 +947,14 @@ namespace OpenRCT2
CopyOriginalUserFilesOver(DIRID::LANDSCAPE, "*.sc6"); CopyOriginalUserFilesOver(DIRID::LANDSCAPE, "*.sc6");
} }
void CopyOriginalUserFilesOver(DIRID dirid, const std::string &pattern) void CopyOriginalUserFilesOver(DIRID dirid, const std::string& pattern)
{ {
auto src = _env->GetDirectoryPath(DIRBASE::RCT2, dirid); auto src = _env->GetDirectoryPath(DIRBASE::RCT2, dirid);
auto dst = _env->GetDirectoryPath(DIRBASE::USER, dirid); auto dst = _env->GetDirectoryPath(DIRBASE::USER, dirid);
CopyOriginalUserFilesOver(src, dst, pattern); CopyOriginalUserFilesOver(src, dst, pattern);
} }
void CopyOriginalUserFilesOver(const std::string &srcRoot, const std::string &dstRoot, const std::string &pattern) void CopyOriginalUserFilesOver(const std::string& srcRoot, const std::string& dstRoot, const std::string& pattern)
{ {
log_verbose("CopyOriginalUserFilesOver('%s', '%s', '%s')", srcRoot.c_str(), dstRoot.c_str(), pattern.c_str()); log_verbose("CopyOriginalUserFilesOver('%s', '%s', '%s')", srcRoot.c_str(), dstRoot.c_str(), pattern.c_str());
@@ -1031,7 +991,7 @@ namespace OpenRCT2
} }
}; };
Context * Context::Instance = nullptr; Context* Context::Instance = nullptr;
std::unique_ptr<IContext> CreateContext() std::unique_ptr<IContext> CreateContext()
{ {
@@ -1046,28 +1006,28 @@ namespace OpenRCT2
return std::make_unique<Context>(env, audioContext, uiContext); return std::make_unique<Context>(env, audioContext, uiContext);
} }
IContext * GetContext() IContext* GetContext()
{ {
return Context::Instance; return Context::Instance;
} }
} } // namespace OpenRCT2
void context_init() void context_init()
{ {
GetContext()->GetUiContext()->GetWindowManager()->Init(); GetContext()->GetUiContext()->GetWindowManager()->Init();
} }
bool context_load_park_from_file(const utf8 * path) bool context_load_park_from_file(const utf8* path)
{ {
return GetContext()->LoadParkFromFile(path); return GetContext()->LoadParkFromFile(path);
} }
bool context_load_park_from_stream(void * stream) bool context_load_park_from_stream(void* stream)
{ {
return GetContext()->LoadParkFromStream((IStream*)stream, ""); return GetContext()->LoadParkFromStream((IStream*)stream, "");
} }
void openrct2_write_full_version_info(utf8 * buffer, size_t bufferSize) void openrct2_write_full_version_info(utf8* buffer, size_t bufferSize)
{ {
String::Set(buffer, bufferSize, gVersionInfoFull); String::Set(buffer, bufferSize, gVersionInfoFull);
} }
@@ -1097,12 +1057,12 @@ void context_show_cursor()
GetContext()->GetUiContext()->SetCursorVisible(true); GetContext()->GetUiContext()->SetCursorVisible(true);
} }
void context_get_cursor_position(int32_t * x, int32_t * y) void context_get_cursor_position(int32_t* x, int32_t* y)
{ {
GetContext()->GetUiContext()->GetCursorPosition(x, y); GetContext()->GetUiContext()->GetCursorPosition(x, y);
} }
void context_get_cursor_position_scaled(int32_t * x, int32_t * y) void context_get_cursor_position_scaled(int32_t* x, int32_t* y)
{ {
context_get_cursor_position(x, y); context_get_cursor_position(x, y);
@@ -1116,22 +1076,22 @@ void context_set_cursor_position(int32_t x, int32_t y)
GetContext()->GetUiContext()->SetCursorPosition(x, y); GetContext()->GetUiContext()->SetCursorPosition(x, y);
} }
const CursorState * context_get_cursor_state() const CursorState* context_get_cursor_state()
{ {
return GetContext()->GetUiContext()->GetCursorState(); return GetContext()->GetUiContext()->GetCursorState();
} }
const uint8_t * context_get_keys_state() const uint8_t* context_get_keys_state()
{ {
return GetContext()->GetUiContext()->GetKeysState(); return GetContext()->GetUiContext()->GetKeysState();
} }
const uint8_t * context_get_keys_pressed() const uint8_t* context_get_keys_pressed()
{ {
return GetContext()->GetUiContext()->GetKeysPressed(); return GetContext()->GetUiContext()->GetKeysPressed();
} }
TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength) TextInputSession* context_start_text_input(utf8* buffer, size_t maxLength)
{ {
return GetContext()->GetUiContext()->StartTextInput(buffer, maxLength); return GetContext()->GetUiContext()->StartTextInput(buffer, maxLength);
} }
@@ -1161,13 +1121,13 @@ void context_recreate_window()
GetContext()->GetUiContext()->RecreateWindow(); GetContext()->GetUiContext()->RecreateWindow();
} }
int32_t context_get_resolutions(Resolution * * outResolutions) int32_t context_get_resolutions(Resolution** outResolutions)
{ {
auto resolutions = GetContext()->GetUiContext()->GetFullscreenResolutions(); auto resolutions = GetContext()->GetUiContext()->GetFullscreenResolutions();
int32_t count = (int32_t)resolutions.size(); int32_t count = (int32_t)resolutions.size();
*outResolutions = Memory::AllocateArray<Resolution>(count); *outResolutions = Memory::AllocateArray<Resolution>(count);
std::copy_n(resolutions.begin(), count, *outResolutions); std::copy_n(resolutions.begin(), count, *outResolutions);
return count; return count;
} }
int32_t context_get_width() int32_t context_get_width()
@@ -1190,31 +1150,31 @@ void context_set_cursor_trap(bool value)
GetContext()->GetUiContext()->SetCursorTrap(value); GetContext()->GetUiContext()->SetCursorTrap(value);
} }
rct_window * context_open_window(rct_windowclass wc) rct_window* context_open_window(rct_windowclass wc)
{ {
auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
return windowManager->OpenWindow(wc); return windowManager->OpenWindow(wc);
} }
rct_window * context_open_window_view(rct_windowclass wc) rct_window* context_open_window_view(rct_windowclass wc)
{ {
auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
return windowManager->OpenView(wc); return windowManager->OpenView(wc);
} }
rct_window * context_open_detail_window(uint8_t type, int32_t id) rct_window* context_open_detail_window(uint8_t type, int32_t id)
{ {
auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
return windowManager->OpenDetails(type, id); return windowManager->OpenDetails(type, id);
} }
rct_window * context_open_intent(Intent * intent) rct_window* context_open_intent(Intent* intent)
{ {
auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
return windowManager->OpenIntent(intent); return windowManager->OpenIntent(intent);
} }
void context_broadcast_intent(Intent * intent) void context_broadcast_intent(Intent* intent)
{ {
auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
windowManager->BroadcastIntent(*intent); windowManager->BroadcastIntent(*intent);
@@ -1226,7 +1186,7 @@ void context_force_close_window_by_class(rct_windowclass windowClass)
windowManager->ForceClose(windowClass); windowManager->ForceClose(windowClass);
} }
rct_window * context_show_error(rct_string_id title, rct_string_id message) rct_window* context_show_error(rct_string_id title, rct_string_id message)
{ {
auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
return windowManager->ShowError(title, message); return windowManager->ShowError(title, message);
@@ -1255,7 +1215,7 @@ void context_quit()
GetContext()->Quit(); GetContext()->Quit();
} }
const utf8 * context_get_path_legacy(int32_t pathId) const utf8* context_get_path_legacy(int32_t pathId)
{ {
static utf8 result[MAX_PATH]; static utf8 result[MAX_PATH];
auto path = GetContext()->GetPathLegacy(pathId); auto path = GetContext()->GetPathLegacy(pathId);
@@ -1263,7 +1223,7 @@ const utf8 * context_get_path_legacy(int32_t pathId)
return result; return result;
} }
bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize) bool platform_open_common_file_dialog(utf8* outFilename, file_dialog_desc* desc, size_t outSize)
{ {
try try
{ {
@@ -1272,7 +1232,7 @@ bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * des
desc2.Title = String::ToStd(desc->title); desc2.Title = String::ToStd(desc->title);
desc2.InitialDirectory = String::ToStd(desc->initial_directory); desc2.InitialDirectory = String::ToStd(desc->initial_directory);
desc2.DefaultFilename = String::ToStd(desc->default_filename); desc2.DefaultFilename = String::ToStd(desc->default_filename);
for (const auto &filter : desc->filters) for (const auto& filter : desc->filters)
{ {
if (filter.name != nullptr) if (filter.name != nullptr)
{ {
@@ -1283,7 +1243,7 @@ bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * des
String::Set(outFilename, outSize, result.c_str()); String::Set(outFilename, outSize, result.c_str());
return !result.empty(); return !result.empty();
} }
catch (const std::exception &ex) catch (const std::exception& ex)
{ {
log_error(ex.what()); log_error(ex.what());
outFilename[0] = '\0'; outFilename[0] = '\0';
@@ -1291,14 +1251,14 @@ bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * des
} }
} }
utf8 * platform_open_directory_browser(const utf8 * title) utf8* platform_open_directory_browser(const utf8* title)
{ {
try try
{ {
std::string result = GetContext()->GetUiContext()->ShowDirectoryDialog(title); std::string result = GetContext()->GetUiContext()->ShowDirectoryDialog(title);
return String::Duplicate(result.c_str()); return String::Duplicate(result.c_str());
} }
catch (const std::exception &ex) catch (const std::exception& ex)
{ {
log_error(ex.what()); log_error(ex.what());
return nullptr; return nullptr;
@@ -1314,7 +1274,7 @@ bool platform_place_string_on_clipboard(utf8* target)
* This function is deprecated. * This function is deprecated.
* Use IPlatformEnvironment instead. * Use IPlatformEnvironment instead.
*/ */
void platform_get_user_directory(utf8 * outPath, const utf8 * subDirectory, size_t outSize) void platform_get_user_directory(utf8* outPath, const utf8* subDirectory, size_t outSize)
{ {
auto env = GetContext()->GetPlatformEnvironment(); auto env = GetContext()->GetPlatformEnvironment();
auto path = env->GetDirectoryPath(DIRBASE::USER); auto path = env->GetDirectoryPath(DIRBASE::USER);
@@ -1329,7 +1289,7 @@ void platform_get_user_directory(utf8 * outPath, const utf8 * subDirectory, size
* This function is deprecated. * This function is deprecated.
* Use IPlatformEnvironment instead. * Use IPlatformEnvironment instead.
*/ */
void platform_get_openrct_data_path(utf8 * outPath, size_t outSize) void platform_get_openrct_data_path(utf8* outPath, size_t outSize)
{ {
auto env = GetContext()->GetPlatformEnvironment(); auto env = GetContext()->GetPlatformEnvironment();
auto path = env->GetDirectoryPath(DIRBASE::OPENRCT2); auto path = env->GetDirectoryPath(DIRBASE::OPENRCT2);

View File

@@ -36,14 +36,14 @@ struct CursorState
struct TextInputSession struct TextInputSession
{ {
utf8 * Buffer; // UTF-8 stream utf8* Buffer; // UTF-8 stream
size_t BufferSize; // Maximum number of bytes (excluding null terminator) size_t BufferSize; // Maximum number of bytes (excluding null terminator)
size_t Size; // Number of bytes (excluding null terminator) size_t Size; // Number of bytes (excluding null terminator)
size_t Length; // Number of codepoints size_t Length; // Number of codepoints
size_t SelectionStart; // Selection start, in bytes size_t SelectionStart; // Selection start, in bytes
size_t SelectionSize; // Selection length in bytes size_t SelectionSize; // Selection length in bytes
const utf8 * ImeBuffer; // IME UTF-8 stream const utf8* ImeBuffer; // IME UTF-8 stream
}; };
struct Resolution struct Resolution
@@ -95,24 +95,25 @@ namespace OpenRCT2
virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract; virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract;
virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract; virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract;
virtual GameState * GetGameState() abstract; virtual GameState* GetGameState() abstract;
virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract; virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract;
virtual Localisation::LocalisationService& GetLocalisationService() abstract; virtual Localisation::LocalisationService& GetLocalisationService() abstract;
virtual std::shared_ptr<IObjectManager> GetObjectManager() abstract; virtual std::shared_ptr<IObjectManager> GetObjectManager() abstract;
virtual std::shared_ptr<IObjectRepository> GetObjectRepository() abstract; virtual std::shared_ptr<IObjectRepository> GetObjectRepository() abstract;
virtual ITrackDesignRepository * GetTrackDesignRepository() abstract; virtual ITrackDesignRepository* GetTrackDesignRepository() abstract;
virtual IScenarioRepository * GetScenarioRepository() abstract; virtual IScenarioRepository* GetScenarioRepository() abstract;
virtual int32_t GetDrawingEngineType() abstract; virtual int32_t GetDrawingEngineType() abstract;
virtual Drawing::IDrawingEngine * GetDrawingEngine() abstract; virtual Drawing::IDrawingEngine* GetDrawingEngine() abstract;
virtual int32_t RunOpenRCT2(int argc, const char * * argv) abstract; virtual int32_t RunOpenRCT2(int argc, const char** argv) abstract;
virtual bool Initialise() abstract; virtual bool Initialise() abstract;
virtual void InitialiseDrawingEngine() abstract; virtual void InitialiseDrawingEngine() abstract;
virtual void DisposeDrawingEngine() abstract; virtual void DisposeDrawingEngine() abstract;
virtual bool LoadParkFromFile(const std::string &path, bool loadTitleScreenOnFail = false) abstract; virtual bool LoadParkFromFile(const std::string& path, bool loadTitleScreenOnFail = false) abstract;
virtual bool LoadParkFromStream(IStream * stream, const std::string &path, bool loadTitleScreenFirstOnFail = false) abstract; virtual bool LoadParkFromStream(IStream * stream, const std::string& path, bool loadTitleScreenFirstOnFail = false)
virtual void WriteLine(const std::string &s) abstract; abstract;
virtual void WriteLine(const std::string& s) abstract;
virtual void Finish() abstract; virtual void Finish() abstract;
virtual void Quit() abstract; virtual void Quit() abstract;
@@ -127,7 +128,7 @@ namespace OpenRCT2
const std::shared_ptr<IPlatformEnvironment>& env, const std::shared_ptr<IPlatformEnvironment>& env,
const std::shared_ptr<Audio::IAudioContext>& audioContext, const std::shared_ptr<Audio::IAudioContext>& audioContext,
const std::shared_ptr<Ui::IUiContext>& uiContext); const std::shared_ptr<Ui::IUiContext>& uiContext);
IContext * GetContext(); IContext* GetContext();
} // namespace OpenRCT2 } // namespace OpenRCT2
enum enum
@@ -207,35 +208,35 @@ void context_setcurrentcursor(int32_t cursor);
void context_update_cursor_scale(); void context_update_cursor_scale();
void context_hide_cursor(); void context_hide_cursor();
void context_show_cursor(); void context_show_cursor();
void context_get_cursor_position(int32_t * x, int32_t * y); void context_get_cursor_position(int32_t* x, int32_t* y);
void context_get_cursor_position_scaled(int32_t * x, int32_t * y); void context_get_cursor_position_scaled(int32_t* x, int32_t* y);
void context_set_cursor_position(int32_t x, int32_t y); void context_set_cursor_position(int32_t x, int32_t y);
const CursorState * context_get_cursor_state(); const CursorState* context_get_cursor_state();
const uint8_t * context_get_keys_state(); const uint8_t* context_get_keys_state();
const uint8_t * context_get_keys_pressed(); const uint8_t* context_get_keys_pressed();
TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength); TextInputSession* context_start_text_input(utf8* buffer, size_t maxLength);
void context_stop_text_input(); void context_stop_text_input();
bool context_is_input_active(); bool context_is_input_active();
void context_trigger_resize(); void context_trigger_resize();
void context_set_fullscreen_mode(int32_t mode); void context_set_fullscreen_mode(int32_t mode);
void context_recreate_window(); void context_recreate_window();
int32_t context_get_resolutions(struct Resolution * * outResolutions); int32_t context_get_resolutions(struct Resolution** outResolutions);
int32_t context_get_width(); int32_t context_get_width();
int32_t context_get_height(); int32_t context_get_height();
bool context_has_focus(); bool context_has_focus();
void context_set_cursor_trap(bool value); void context_set_cursor_trap(bool value);
rct_window * context_open_window(rct_windowclass wc); rct_window* context_open_window(rct_windowclass wc);
rct_window * context_open_detail_window(uint8_t type, int32_t id); rct_window* context_open_detail_window(uint8_t type, int32_t id);
rct_window * context_open_window_view(uint8_t view); rct_window* context_open_window_view(uint8_t view);
rct_window * context_show_error(rct_string_id title, rct_string_id message); rct_window* context_show_error(rct_string_id title, rct_string_id message);
rct_window * context_open_intent(Intent * intent); rct_window* context_open_intent(Intent* intent);
void context_broadcast_intent(Intent * intent); void context_broadcast_intent(Intent* intent);
void context_force_close_window_by_class(rct_windowclass wc); void context_force_close_window_by_class(rct_windowclass wc);
void context_update_map_tooltip(); void context_update_map_tooltip();
void context_handle_input(); void context_handle_input();
void context_input_handle_keyboard(bool isTitle); void context_input_handle_keyboard(bool isTitle);
bool context_read_bmp(void * * outPixels, uint32_t * outWidth, uint32_t * outHeight, const utf8 * path); bool context_read_bmp(void** outPixels, uint32_t* outWidth, uint32_t* outHeight, const utf8* path);
void context_quit(); void context_quit();
const utf8 * context_get_path_legacy(int32_t pathId); const utf8* context_get_path_legacy(int32_t pathId);
bool context_load_park_from_file(const utf8 * path); bool context_load_park_from_file(const utf8* path);
bool context_load_park_from_stream(void * stream); bool context_load_park_from_stream(void* stream);

View File

@@ -7,10 +7,11 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "localisation/Date.h"
#include "Date.h"
#include "core/Guard.hpp" #include "core/Guard.hpp"
#include "core/Math.hpp" #include "core/Math.hpp"
#include "localisation/Date.h"
#include "Date.h"
using namespace OpenRCT2; using namespace OpenRCT2;
@@ -20,8 +21,8 @@ constexpr int32_t MASK_FORTNIGHT_TICKS = 0x7FFF;
constexpr int32_t MASK_MONTH_TICKS = 0xFFFF; constexpr int32_t MASK_MONTH_TICKS = 0xFFFF;
Date::Date(uint32_t monthsElapsed, uint16_t monthTicks) Date::Date(uint32_t monthsElapsed, uint16_t monthTicks)
: _monthTicks(monthTicks), : _monthTicks(monthTicks)
_monthsElapsed(monthsElapsed) , _monthsElapsed(monthsElapsed)
{ {
} }

View File

@@ -43,4 +43,4 @@ namespace OpenRCT2
static int32_t GetDaysInMonth(int32_t month); static int32_t GetDaysInMonth(int32_t month);
}; };
} } // namespace OpenRCT2

View File

@@ -7,10 +7,12 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "Diagnostic.h"
#include "core/String.hpp"
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
#include "core/String.hpp"
#include "Diagnostic.h"
#ifdef __ANDROID__ #ifdef __ANDROID__
#include <android/log.h> #include <android/log.h>
@@ -19,9 +21,10 @@
[[maybe_unused]] static bool _log_location_enabled = true; [[maybe_unused]] static bool _log_location_enabled = true;
bool _log_levels[DIAGNOSTIC_LEVEL_COUNT] = { true, true, true, false, true }; bool _log_levels[DIAGNOSTIC_LEVEL_COUNT] = { true, true, true, false, true };
static FILE * diagnostic_get_stream(DIAGNOSTIC_LEVEL level) static FILE* diagnostic_get_stream(DIAGNOSTIC_LEVEL level)
{ {
switch (level) { switch (level)
{
case DIAGNOSTIC_LEVEL_VERBOSE: case DIAGNOSTIC_LEVEL_VERBOSE:
case DIAGNOSTIC_LEVEL_INFORMATION: case DIAGNOSTIC_LEVEL_INFORMATION:
return stdout; return stdout;
@@ -32,9 +35,10 @@ static FILE * diagnostic_get_stream(DIAGNOSTIC_LEVEL level)
#ifdef __ANDROID__ #ifdef __ANDROID__
int _android_log_priority[DIAGNOSTIC_LEVEL_COUNT] = {ANDROID_LOG_FATAL, ANDROID_LOG_ERROR, ANDROID_LOG_WARN, ANDROID_LOG_VERBOSE, ANDROID_LOG_INFO}; int _android_log_priority[DIAGNOSTIC_LEVEL_COUNT]
= { ANDROID_LOG_FATAL, ANDROID_LOG_ERROR, ANDROID_LOG_WARN, ANDROID_LOG_VERBOSE, ANDROID_LOG_INFO };
void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char *format, ...) void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char* format, ...)
{ {
va_list args; va_list args;
@@ -46,7 +50,8 @@ void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char *format, ...)
va_end(args); va_end(args);
} }
void diagnostic_log_with_location(DIAGNOSTIC_LEVEL diagnosticLevel, const char *file, const char *function, int32_t line, const char *format, ...) void diagnostic_log_with_location(
DIAGNOSTIC_LEVEL diagnosticLevel, const char* file, const char* function, int32_t line, const char* format, ...)
{ {
va_list args; va_list args;
char buf[1024]; char buf[1024];
@@ -63,15 +68,9 @@ void diagnostic_log_with_location(DIAGNOSTIC_LEVEL diagnosticLevel, const char *
#else #else
static constexpr const char * _level_strings[] = { static constexpr const char* _level_strings[] = { "FATAL", "ERROR", "WARNING", "VERBOSE", "INFO" };
"FATAL",
"ERROR",
"WARNING",
"VERBOSE",
"INFO"
};
void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char *format, ...) void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char* format, ...)
{ {
va_list args; va_list args;
if (_log_levels[diagnosticLevel]) if (_log_levels[diagnosticLevel])
@@ -89,7 +88,8 @@ void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char *format, ...)
} }
} }
void diagnostic_log_with_location(DIAGNOSTIC_LEVEL diagnosticLevel, const char *file, const char *function, int32_t line, const char *format, ...) void diagnostic_log_with_location(
DIAGNOSTIC_LEVEL diagnosticLevel, const char* file, const char* function, int32_t line, const char* format, ...)
{ {
va_list args; va_list args;
if (_log_levels[diagnosticLevel]) if (_log_levels[diagnosticLevel])

View File

@@ -12,7 +12,8 @@
#include <cstdint> #include <cstdint>
enum DIAGNOSTIC_LEVEL { enum DIAGNOSTIC_LEVEL
{
DIAGNOSTIC_LEVEL_FATAL, DIAGNOSTIC_LEVEL_FATAL,
DIAGNOSTIC_LEVEL_ERROR, DIAGNOSTIC_LEVEL_ERROR,
DIAGNOSTIC_LEVEL_WARNING, DIAGNOSTIC_LEVEL_WARNING,
@@ -44,45 +45,48 @@ enum DIAGNOSTIC_LEVEL {
*/ */
#if defined(DEBUG) #if defined(DEBUG)
#if DEBUG > 0 #if DEBUG > 0
#define DEBUG_LEVEL_1 1 #define DEBUG_LEVEL_1 1
#if DEBUG > 1 #if DEBUG > 1
#define DEBUG_LEVEL_2 1 #define DEBUG_LEVEL_2 1
#if DEBUG > 2 #if DEBUG > 2
#define DEBUG_LEVEL_3 1 #define DEBUG_LEVEL_3 1
#else
#define DEBUG_LEVEL_3 0
#endif // DEBUG > 2
#else
#define DEBUG_LEVEL_3 0
#define DEBUG_LEVEL_2 0
#endif // DEBUG > 1
#else
#define DEBUG_LEVEL_1 0
#define DEBUG_LEVEL_2 0
#define DEBUG_LEVEL_3 0
#endif // DEBUG > 0
#else #else
#define DEBUG_LEVEL_3 0 #define DEBUG_LEVEL_3 0
#define DEBUG_LEVEL_2 0 #endif // DEBUG > 2
#define DEBUG_LEVEL_1 0 #else
#define DEBUG_LEVEL_3 0
#define DEBUG_LEVEL_2 0
#endif // DEBUG > 1
#else
#define DEBUG_LEVEL_1 0
#define DEBUG_LEVEL_2 0
#define DEBUG_LEVEL_3 0
#endif // DEBUG > 0
#else
#define DEBUG_LEVEL_3 0
#define DEBUG_LEVEL_2 0
#define DEBUG_LEVEL_1 0
#endif // defined(DEBUG) #endif // defined(DEBUG)
extern bool _log_levels[DIAGNOSTIC_LEVEL_COUNT]; extern bool _log_levels[DIAGNOSTIC_LEVEL_COUNT];
void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char *format, ...); void diagnostic_log(DIAGNOSTIC_LEVEL diagnosticLevel, const char* format, ...);
void diagnostic_log_with_location(DIAGNOSTIC_LEVEL diagnosticLevel, const char *file, const char *function, int32_t line, const char *format, ...); void diagnostic_log_with_location(
DIAGNOSTIC_LEVEL diagnosticLevel, const char* file, const char* function, int32_t line, const char* format, ...);
#ifdef _MSC_VER #ifdef _MSC_VER
#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __FUNCTION__, __LINE__, format, ## __VA_ARGS__) #define diagnostic_log_macro(level, format, ...) \
diagnostic_log_with_location(level, __FILE__, __FUNCTION__, __LINE__, format, ##__VA_ARGS__)
#else #else
#define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __func__, __LINE__, format, ## __VA_ARGS__) #define diagnostic_log_macro(level, format, ...) \
diagnostic_log_with_location(level, __FILE__, __func__, __LINE__, format, ##__VA_ARGS__)
#endif // _MSC_VER #endif // _MSC_VER
#define log_fatal(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_FATAL, format, ## __VA_ARGS__) #define log_fatal(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_FATAL, format, ##__VA_ARGS__)
#define log_error(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_ERROR, format, ## __VA_ARGS__) #define log_error(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_ERROR, format, ##__VA_ARGS__)
#define log_warning(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_WARNING, format, ## __VA_ARGS__) #define log_warning(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_WARNING, format, ##__VA_ARGS__)
#define log_verbose(format, ...) diagnostic_log(DIAGNOSTIC_LEVEL_VERBOSE, format, ## __VA_ARGS__) #define log_verbose(format, ...) diagnostic_log(DIAGNOSTIC_LEVEL_VERBOSE, format, ##__VA_ARGS__)
#define log_info(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_INFORMATION, format, ## __VA_ARGS__) #define log_info(format, ...) diagnostic_log_macro(DIAGNOSTIC_LEVEL_INFORMATION, format, ##__VA_ARGS__)
#endif #endif

View File

@@ -7,10 +7,9 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include <array>
#include <vector>
#include "Context.h"
#include "Editor.h" #include "Editor.h"
#include "Context.h"
#include "EditorObjectSelectionSession.h" #include "EditorObjectSelectionSession.h"
#include "FileClassifier.h" #include "FileClassifier.h"
#include "Game.h" #include "Game.h"
@@ -26,15 +25,18 @@
#include "peep/Staff.h" #include "peep/Staff.h"
#include "rct1/RCT1.h" #include "rct1/RCT1.h"
#include "scenario/Scenario.h" #include "scenario/Scenario.h"
#include "ui/UiContext.h"
#include "ui/WindowManager.h"
#include "util/Util.h" #include "util/Util.h"
#include "windows/Intent.h" #include "windows/Intent.h"
#include "world/Climate.h" #include "world/Climate.h"
#include "world/Entrance.h" #include "world/Entrance.h"
#include "world/Footpath.h" #include "world/Footpath.h"
#include "world/Scenery.h"
#include "world/Park.h" #include "world/Park.h"
#include "ui/UiContext.h" #include "world/Scenery.h"
#include "ui/WindowManager.h"
#include <array>
#include <vector>
using namespace OpenRCT2; using namespace OpenRCT2;
@@ -42,12 +44,12 @@ namespace Editor
{ {
static std::array<std::vector<uint8_t>, OBJECT_TYPE_COUNT> _editorSelectedObjectFlags; static std::array<std::vector<uint8_t>, OBJECT_TYPE_COUNT> _editorSelectedObjectFlags;
static void ConvertSaveToScenarioCallback(int32_t result, const utf8 * path); static void ConvertSaveToScenarioCallback(int32_t result, const utf8* path);
static void SetAllLandOwned(); static void SetAllLandOwned();
static bool LoadLandscapeFromSV4(const char * path); static bool LoadLandscapeFromSV4(const char* path);
static bool LoadLandscapeFromSC4(const char * path); static bool LoadLandscapeFromSC4(const char* path);
static void FinaliseMainView(); static void FinaliseMainView();
static bool ReadS6(const char * path); static bool ReadS6(const char* path);
static void ClearMapForEditing(bool fromSave); static void ClearMapForEditing(bool fromSave);
/** /**
@@ -65,7 +67,7 @@ namespace Editor
gParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES; gParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES;
gS6Info.category = SCENARIO_CATEGORY_OTHER; gS6Info.category = SCENARIO_CATEGORY_OTHER;
viewport_init_all(); viewport_init_all();
rct_window * mainWindow = context_open_window_view(WV_EDITOR_MAIN); rct_window* mainWindow = context_open_window_view(WV_EDITOR_MAIN);
window_set_location(mainWindow, 2400, 2400, 112); window_set_location(mainWindow, 2400, 2400, 112);
load_palette(); load_palette();
gScreenAge = 0; gScreenAge = 0;
@@ -82,11 +84,11 @@ namespace Editor
tool_cancel(); tool_cancel();
auto intent = Intent(WC_LOADSAVE); auto intent = Intent(WC_LOADSAVE);
intent.putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME); intent.putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME);
intent.putExtra(INTENT_EXTRA_CALLBACK, (void *) ConvertSaveToScenarioCallback); intent.putExtra(INTENT_EXTRA_CALLBACK, (void*)ConvertSaveToScenarioCallback);
context_open_intent(&intent); context_open_intent(&intent);
} }
static void ConvertSaveToScenarioCallback(int32_t result, const utf8 * path) static void ConvertSaveToScenarioCallback(int32_t result, const utf8* path)
{ {
if (result != MODAL_RESULT_OK) if (result != MODAL_RESULT_OK)
{ {
@@ -142,7 +144,7 @@ namespace Editor
SetAllLandOwned(); SetAllLandOwned();
gS6Info.editor_step = EDITOR_STEP_OBJECT_SELECTION; gS6Info.editor_step = EDITOR_STEP_OBJECT_SELECTION;
viewport_init_all(); viewport_init_all();
rct_window * mainWindow = context_open_window_view(WV_EDITOR_MAIN); rct_window* mainWindow = context_open_window_view(WV_EDITOR_MAIN);
window_set_location(mainWindow, 2400, 2400, 112); window_set_location(mainWindow, 2400, 2400, 112);
load_palette(); load_palette();
} }
@@ -163,7 +165,7 @@ namespace Editor
SetAllLandOwned(); SetAllLandOwned();
gS6Info.editor_step = EDITOR_STEP_OBJECT_SELECTION; gS6Info.editor_step = EDITOR_STEP_OBJECT_SELECTION;
viewport_init_all(); viewport_init_all();
rct_window * mainWindow = context_open_window_view(WV_EDITOR_MAIN); rct_window* mainWindow = context_open_window_view(WV_EDITOR_MAIN);
window_set_location(mainWindow, 2400, 2400, 112); window_set_location(mainWindow, 2400, 2400, 112);
load_palette(); load_palette();
} }
@@ -183,7 +185,7 @@ namespace Editor
* *
* rct2: 0x006758C0 * rct2: 0x006758C0
*/ */
bool LoadLandscape(const utf8 * path) bool LoadLandscape(const utf8* path)
{ {
// #4996: Make sure the object selection window closes here to prevent unload objects // #4996: Make sure the object selection window closes here to prevent unload objects
// after we have loaded a new park. // after we have loaded a new park.
@@ -208,7 +210,7 @@ namespace Editor
* *
* rct2: 0x006A2B02 * rct2: 0x006A2B02
*/ */
static bool LoadLandscapeFromSV4(const char * path) static bool LoadLandscapeFromSV4(const char* path)
{ {
load_from_sv4(path); load_from_sv4(path);
ClearMapForEditing(true); ClearMapForEditing(true);
@@ -222,7 +224,7 @@ namespace Editor
return true; return true;
} }
static bool LoadLandscapeFromSC4(const char * path) static bool LoadLandscapeFromSC4(const char* path)
{ {
load_from_sc4(path); load_from_sc4(path);
ClearMapForEditing(false); ClearMapForEditing(false);
@@ -240,7 +242,7 @@ namespace Editor
* *
* rct2: 0x006758FE * rct2: 0x006758FE
*/ */
static bool ReadS6(const char * path) static bool ReadS6(const char* path)
{ {
auto extension = path_get_extension(path); auto extension = path_get_extension(path);
if (_stricmp(extension, ".sc6") == 0) if (_stricmp(extension, ".sc6") == 0)
@@ -268,7 +270,7 @@ namespace Editor
map_remove_all_rides(); map_remove_all_rides();
// //
for (auto &banner : gBanners) for (auto& banner : gBanners)
{ {
if (banner.type == 255) if (banner.type == 255)
{ {
@@ -279,8 +281,8 @@ namespace Editor
// //
{ {
int32_t i; int32_t i;
Ride * ride; Ride* ride;
FOR_ALL_RIDES(i, ride) FOR_ALL_RIDES (i, ride)
{ {
user_string_free(ride->name); user_string_free(ride->name);
} }
@@ -291,7 +293,7 @@ namespace Editor
// //
for (int32_t i = 0; i < MAX_SPRITES; i++) for (int32_t i = 0; i < MAX_SPRITES; i++)
{ {
rct_sprite * sprite = get_sprite(i); rct_sprite* sprite = get_sprite(i);
user_string_free(sprite->unknown.name_string_idx); user_string_free(sprite->unknown.name_string_idx);
} }
@@ -331,17 +333,9 @@ namespace Editor
gInitialCash = std::min(gInitialCash, 100000); gInitialCash = std::min(gInitialCash, 100000);
finance_reset_cash_to_initial(); finance_reset_cash_to_initial();
gBankLoan = Math::Clamp( gBankLoan = Math::Clamp(MONEY(0, 00), gBankLoan, MONEY(5000000, 00));
MONEY(0, 00),
gBankLoan,
MONEY(5000000, 00)
);
gMaxBankLoan = Math::Clamp( gMaxBankLoan = Math::Clamp(MONEY(0, 00), gMaxBankLoan, MONEY(5000000, 00));
MONEY(0, 00),
gMaxBankLoan,
MONEY(5000000, 00)
);
gBankLoanInterestRate = Math::Clamp((uint8_t)5, gBankLoanInterestRate, (uint8_t)80); gBankLoanInterestRate = Math::Clamp((uint8_t)5, gBankLoanInterestRate, (uint8_t)80);
} }
@@ -431,8 +425,7 @@ namespace Editor
*/ */
int32_t CheckObjectSelection() int32_t CheckObjectSelection()
{ {
bool isTrackDesignerManager = bool isTrackDesignerManager = gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER);
gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER);
if (!isTrackDesignerManager) if (!isTrackDesignerManager)
{ {
@@ -494,7 +487,7 @@ namespace Editor
} }
} }
for (const auto &parkEntrance : gParkEntrances) for (const auto& parkEntrance : gParkEntrances)
{ {
if (parkEntrance.x == LOCATION_NULL) if (parkEntrance.x == LOCATION_NULL)
{ {
@@ -540,13 +533,13 @@ namespace Editor
} }
void GameCommandEditScenarioOptions( void GameCommandEditScenarioOptions(
[[maybe_unused]] int32_t * eax, [[maybe_unused]] int32_t* eax,
int32_t * ebx, int32_t* ebx,
int32_t * ecx, int32_t* ecx,
int32_t * edx, int32_t* edx,
[[maybe_unused]] int32_t * esi, [[maybe_unused]] int32_t* esi,
[[maybe_unused]] int32_t * edi, [[maybe_unused]] int32_t* edi,
[[maybe_unused]] int32_t * ebp) [[maybe_unused]] int32_t* ebp)
{ {
if (!(*ebx & GAME_COMMAND_FLAG_APPLY)) if (!(*ebx & GAME_COMMAND_FLAG_APPLY))
{ {
@@ -760,7 +753,7 @@ namespace Editor
uint8_t GetSelectedObjectFlags(int32_t objectType, size_t index) uint8_t GetSelectedObjectFlags(int32_t objectType, size_t index)
{ {
uint8_t result = 0; uint8_t result = 0;
auto &list = _editorSelectedObjectFlags[objectType]; auto& list = _editorSelectedObjectFlags[objectType];
if (list.size() > index) if (list.size() > index)
{ {
result = list[index]; result = list[index];
@@ -770,7 +763,7 @@ namespace Editor
void ClearSelectedObject(int32_t objectType, size_t index, uint32_t flags) void ClearSelectedObject(int32_t objectType, size_t index, uint32_t flags)
{ {
auto &list = _editorSelectedObjectFlags[objectType]; auto& list = _editorSelectedObjectFlags[objectType];
if (list.size() <= index) if (list.size() <= index)
{ {
list.resize(index + 1); list.resize(index + 1);
@@ -780,22 +773,22 @@ namespace Editor
void SetSelectedObject(int32_t objectType, size_t index, uint32_t flags) void SetSelectedObject(int32_t objectType, size_t index, uint32_t flags)
{ {
auto &list = _editorSelectedObjectFlags[objectType]; auto& list = _editorSelectedObjectFlags[objectType];
if (list.size() <= index) if (list.size() <= index)
{ {
list.resize(index + 1); list.resize(index + 1);
} }
list[index] |= flags; list[index] |= flags;
} }
} } // namespace Editor
void editor_open_windows_for_current_step() void editor_open_windows_for_current_step()
{ {
Editor::OpenWindowsForCurrentStep(); Editor::OpenWindowsForCurrentStep();
} }
void game_command_edit_scenario_options(int32_t * eax, int32_t * ebx, int32_t * ecx, int32_t * edx, int32_t * esi, int32_t * edi, int32_t * ebp) void game_command_edit_scenario_options(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp)
{ {
Editor::GameCommandEditScenarioOptions(eax, ebx, ecx, edx, esi, edi, ebp); Editor::GameCommandEditScenarioOptions(eax, ebx, ecx, edx, esi, edi, ebp);
} }

View File

@@ -18,7 +18,7 @@ namespace Editor
void ConvertSaveToScenario(); void ConvertSaveToScenario();
void LoadTrackDesigner(); void LoadTrackDesigner();
void LoadTrackManager(); void LoadTrackManager();
bool LoadLandscape(const utf8 *path); bool LoadLandscape(const utf8* path);
bool CheckPark(); bool CheckPark();
int32_t CheckObjectSelection(); int32_t CheckObjectSelection();
@@ -70,6 +70,7 @@ enum
void editor_open_windows_for_current_step(); void editor_open_windows_for_current_step();
void game_command_edit_scenario_options(int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void game_command_edit_scenario_options(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
#endif #endif

View File

@@ -7,24 +7,25 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include <vector>
#include "Context.h"
#include "core/Util.hpp"
#include "Editor.h"
#include "EditorObjectSelectionSession.h" #include "EditorObjectSelectionSession.h"
#include "Context.h"
#include "Editor.h"
#include "Game.h" #include "Game.h"
#include "OpenRCT2.h"
#include "core/Util.hpp"
#include "localisation/Localisation.h" #include "localisation/Localisation.h"
#include "management/Research.h" #include "management/Research.h"
#include "object/DefaultObjects.h" #include "object/DefaultObjects.h"
#include "object/ObjectList.h" #include "object/ObjectList.h"
#include "object/ObjectManager.h" #include "object/ObjectManager.h"
#include "object/ObjectRepository.h" #include "object/ObjectRepository.h"
#include "OpenRCT2.h"
#include "ride/RideData.h" #include "ride/RideData.h"
#include "windows/Intent.h" #include "windows/Intent.h"
#include "world/Footpath.h" #include "world/Footpath.h"
#include "world/LargeScenery.h" #include "world/LargeScenery.h"
#include <vector>
bool _maxObjectsWasHit; bool _maxObjectsWasHit;
std::vector<uint8_t> _objectSelectionFlags; std::vector<uint8_t> _objectSelectionFlags;
@@ -44,11 +45,11 @@ static void window_editor_object_selection_select_default_objects();
static void setup_track_manager_objects() static void setup_track_manager_objects()
{ {
int32_t numObjects = (int32_t)object_repository_get_items_count(); int32_t numObjects = (int32_t)object_repository_get_items_count();
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++) for (int32_t i = 0; i < numObjects; i++)
{ {
uint8_t * selectionFlags = &_objectSelectionFlags[i]; uint8_t* selectionFlags = &_objectSelectionFlags[i];
const ObjectRepositoryItem * item = &items[i]; const ObjectRepositoryItem* item = &items[i];
uint8_t object_type = object_entry_get_type(&item->ObjectEntry); uint8_t object_type = object_entry_get_type(&item->ObjectEntry);
if (object_type == OBJECT_TYPE_RIDE) if (object_type == OBJECT_TYPE_RIDE)
{ {
@@ -73,11 +74,11 @@ static void setup_track_manager_objects()
static void setup_track_designer_objects() static void setup_track_designer_objects()
{ {
int32_t numObjects = (int32_t)object_repository_get_items_count(); int32_t numObjects = (int32_t)object_repository_get_items_count();
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++) for (int32_t i = 0; i < numObjects; i++)
{ {
uint8_t * selectionFlags = &_objectSelectionFlags[i]; uint8_t* selectionFlags = &_objectSelectionFlags[i];
const ObjectRepositoryItem * item = &items[i]; const ObjectRepositoryItem* item = &items[i];
uint8_t objectType = object_entry_get_type(&item->ObjectEntry); uint8_t objectType = object_entry_get_type(&item->ObjectEntry);
if (objectType == OBJECT_TYPE_RIDE) if (objectType == OBJECT_TYPE_RIDE)
{ {
@@ -118,11 +119,13 @@ void setup_in_use_selection_flags()
tile_element_iterator iter; tile_element_iterator iter;
tile_element_iterator_begin(&iter); tile_element_iterator_begin(&iter);
do { do
{
uint16_t type; uint16_t type;
rct_banner* banner; rct_banner* banner;
switch (iter.element->GetType()) { switch (iter.element->GetType())
{
default: default:
case TILE_ELEMENT_TYPE_SURFACE: case TILE_ELEMENT_TYPE_SURFACE:
case TILE_ELEMENT_TYPE_TRACK: case TILE_ELEMENT_TYPE_TRACK:
@@ -133,7 +136,8 @@ void setup_in_use_selection_flags()
assert(type < object_entry_group_counts[OBJECT_TYPE_PATHS]); assert(type < object_entry_group_counts[OBJECT_TYPE_PATHS]);
Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED); Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED);
if (footpath_element_has_path_scenery(iter.element)) { if (footpath_element_has_path_scenery(iter.element))
{
uint8_t path_additions = footpath_element_get_path_scenery_index(iter.element); uint8_t path_additions = footpath_element_get_path_scenery_index(iter.element);
Editor::SetSelectedObject(OBJECT_TYPE_PATH_BITS, path_additions, OBJECT_SELECTION_FLAG_SELECTED); Editor::SetSelectedObject(OBJECT_TYPE_PATH_BITS, path_additions, OBJECT_SELECTION_FLAG_SELECTED);
} }
@@ -175,29 +179,31 @@ void setup_in_use_selection_flags()
} }
} while (tile_element_iterator_next(&iter)); } while (tile_element_iterator_next(&iter));
for (uint8_t ride_index = 0; ride_index < 0xFF; ride_index++) { for (uint8_t ride_index = 0; ride_index < 0xFF; ride_index++)
{
Ride* ride = get_ride(ride_index); Ride* ride = get_ride(ride_index);
if (ride->type != RIDE_TYPE_NULL) { if (ride->type != RIDE_TYPE_NULL)
{
uint8_t type = ride->subtype; uint8_t type = ride->subtype;
Editor::SetSelectedObject(OBJECT_TYPE_RIDE, type, OBJECT_SELECTION_FLAG_SELECTED); Editor::SetSelectedObject(OBJECT_TYPE_RIDE, type, OBJECT_SELECTION_FLAG_SELECTED);
} }
} }
int32_t numObjects = (int32_t)object_repository_get_items_count(); int32_t numObjects = (int32_t)object_repository_get_items_count();
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++) { for (int32_t i = 0; i < numObjects; i++)
uint8_t *selectionFlags = &_objectSelectionFlags[i]; {
const ObjectRepositoryItem * item = &items[i]; uint8_t* selectionFlags = &_objectSelectionFlags[i];
const ObjectRepositoryItem* item = &items[i];
*selectionFlags &= ~OBJECT_SELECTION_FLAG_IN_USE; *selectionFlags &= ~OBJECT_SELECTION_FLAG_IN_USE;
uint8_t entryType, entryIndex; uint8_t entryType, entryIndex;
if (find_object_in_entry_group(&item->ObjectEntry, &entryType, &entryIndex)) { if (find_object_in_entry_group(&item->ObjectEntry, &entryType, &entryIndex))
{
auto flags = Editor::GetSelectedObjectFlags(entryType, entryIndex); auto flags = Editor::GetSelectedObjectFlags(entryType, entryIndex);
if (flags & OBJECT_SELECTION_FLAG_SELECTED) if (flags & OBJECT_SELECTION_FLAG_SELECTED)
{ {
*selectionFlags |= *selectionFlags |= OBJECT_SELECTION_FLAG_IN_USE | OBJECT_SELECTION_FLAG_SELECTED;
OBJECT_SELECTION_FLAG_IN_USE |
OBJECT_SELECTION_FLAG_SELECTED;
} }
if (flags & OBJECT_SELECTION_FLAG_2) if (flags & OBJECT_SELECTION_FLAG_2)
{ {
@@ -216,33 +222,39 @@ void sub_6AB211()
int32_t numObjects = (int32_t)object_repository_get_items_count(); int32_t numObjects = (int32_t)object_repository_get_items_count();
_objectSelectionFlags = std::vector<uint8_t>(numObjects); _objectSelectionFlags = std::vector<uint8_t>(numObjects);
for (uint8_t objectType = 0; objectType < OBJECT_TYPE_COUNT; objectType++) { for (uint8_t objectType = 0; objectType < OBJECT_TYPE_COUNT; objectType++)
{
_numSelectedObjectsForType[objectType] = 0; _numSelectedObjectsForType[objectType] = 0;
_numAvailableObjectsForType[objectType] = 0; _numAvailableObjectsForType[objectType] = 0;
} }
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++) { for (int32_t i = 0; i < numObjects; i++)
{
uint8_t objectType = object_entry_get_type(&items[i].ObjectEntry); uint8_t objectType = object_entry_get_type(&items[i].ObjectEntry);
_numAvailableObjectsForType[objectType]++; _numAvailableObjectsForType[objectType]++;
} }
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) { if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
{
setup_track_designer_objects(); setup_track_designer_objects();
} }
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) { if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
{
setup_track_manager_objects(); setup_track_manager_objects();
} }
setup_in_use_selection_flags(); setup_in_use_selection_flags();
reset_selected_object_count_and_size(); reset_selected_object_count_and_size();
if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER))) { if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)))
{
window_editor_object_selection_select_required_objects(); window_editor_object_selection_select_required_objects();
// To prevent it breaking in scenario mode. // To prevent it breaking in scenario mode.
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) { if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
{
window_editor_object_selection_select_default_objects(); window_editor_object_selection_select_default_objects();
} }
} }
@@ -299,14 +311,16 @@ static void remove_selected_objects_from_research(const rct_object_entry* instal
void unload_unselected_objects() void unload_unselected_objects()
{ {
int32_t numItems = (int32_t)object_repository_get_items_count(); int32_t numItems = (int32_t)object_repository_get_items_count();
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
size_t numObjectsToUnload = 0; size_t numObjectsToUnload = 0;
rct_object_entry * objectsToUnload = (rct_object_entry *)malloc(numItems * sizeof(rct_object_entry)); rct_object_entry* objectsToUnload = (rct_object_entry*)malloc(numItems * sizeof(rct_object_entry));
for (int32_t i = 0; i < numItems; i++) { for (int32_t i = 0; i < numItems; i++)
if (!(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED)) { {
const rct_object_entry * entry = &items[i].ObjectEntry; if (!(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED))
{
const rct_object_entry* entry = &items[i].ObjectEntry;
remove_selected_objects_from_research(entry); remove_selected_objects_from_research(entry);
objectsToUnload[numObjectsToUnload++] = *entry; objectsToUnload[numObjectsToUnload++] = *entry;
@@ -318,14 +332,14 @@ void unload_unselected_objects()
} }
/** /**
* *
* rct2: 0x006AA805 * rct2: 0x006AA805
*/ */
static void window_editor_object_selection_select_default_objects() static void window_editor_object_selection_select_default_objects()
{ {
if (_numSelectedObjectsForType[0] == 0) if (_numSelectedObjectsForType[0] == 0)
{ {
for (const auto &defaultSelectedObject : DefaultSelectedObjects) for (const auto& defaultSelectedObject : DefaultSelectedObjects)
{ {
window_editor_object_selection_select_object(0, 7, &defaultSelectedObject); window_editor_object_selection_select_object(0, 7, &defaultSelectedObject);
} }
@@ -350,16 +364,18 @@ static void window_editor_object_selection_select_required_objects()
*/ */
void reset_selected_object_count_and_size() void reset_selected_object_count_and_size()
{ {
for (auto &objectType : _numSelectedObjectsForType) for (auto& objectType : _numSelectedObjectsForType)
{ {
objectType = 0; objectType = 0;
} }
int32_t numObjects = (int32_t)object_repository_get_items_count(); int32_t numObjects = (int32_t)object_repository_get_items_count();
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++) { for (int32_t i = 0; i < numObjects; i++)
{
uint8_t objectType = object_entry_get_type(&items[i].ObjectEntry); uint8_t objectType = object_entry_get_type(&items[i].ObjectEntry);
if (_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED) { if (_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED)
{
_numSelectedObjectsForType[objectType]++; _numSelectedObjectsForType[objectType]++;
} }
} }
@@ -370,9 +386,11 @@ void reset_selected_object_count_and_size()
* optional / required dependants of an * optional / required dependants of an
* object. * object.
*/ */
static void set_object_selection_error(uint8_t is_master_object, rct_string_id error_msg){ static void set_object_selection_error(uint8_t is_master_object, rct_string_id error_msg)
{
gGameCommandErrorText = error_msg; gGameCommandErrorText = error_msg;
if (!is_master_object){ if (!is_master_object)
{
reset_selected_object_count_and_size(); reset_selected_object_count_and_size();
} }
} }
@@ -381,40 +399,48 @@ static void set_object_selection_error(uint8_t is_master_object, rct_string_id e
* *
* rct2: 0x006AB54F * rct2: 0x006AB54F
*/ */
int32_t window_editor_object_selection_select_object(uint8_t bh, int32_t flags, const rct_object_entry *entry) int32_t window_editor_object_selection_select_object(uint8_t bh, int32_t flags, const rct_object_entry* entry)
{ {
int32_t numObjects = (int32_t)object_repository_get_items_count(); int32_t numObjects = (int32_t)object_repository_get_items_count();
const ObjectRepositoryItem * item = object_repository_find_object_by_entry(entry); const ObjectRepositoryItem* item = object_repository_find_object_by_entry(entry);
if (item == nullptr) { if (item == nullptr)
{
set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_OBJECT_DATA_NOT_FOUND); set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_OBJECT_DATA_NOT_FOUND);
return 0; return 0;
} }
// Get repository item index // Get repository item index
int32_t index = -1; int32_t index = -1;
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++) { for (int32_t i = 0; i < numObjects; i++)
if (&items[i] == item) { {
if (&items[i] == item)
{
index = i; index = i;
} }
} }
uint8_t * selectionFlags = &_objectSelectionFlags[index]; uint8_t* selectionFlags = &_objectSelectionFlags[index];
if (!(flags & 1)) { if (!(flags & 1))
if (!(*selectionFlags & OBJECT_SELECTION_FLAG_SELECTED)) { {
if (!(*selectionFlags & OBJECT_SELECTION_FLAG_SELECTED))
{
return 1; return 1;
} }
else if (*selectionFlags & OBJECT_SELECTION_FLAG_IN_USE) { else if (*selectionFlags & OBJECT_SELECTION_FLAG_IN_USE)
{
set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_CURRENTLY_IN_USE); set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_CURRENTLY_IN_USE);
return 0; return 0;
} }
else if (*selectionFlags & OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED) { else if (*selectionFlags & OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED)
{
set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_ALWAYS_REQUIRED); set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_ALWAYS_REQUIRED);
return 0; return 0;
} }
uint8_t objectType = object_entry_get_type(&item->ObjectEntry); uint8_t objectType = object_entry_get_type(&item->ObjectEntry);
if (objectType == OBJECT_TYPE_SCENERY_GROUP && (flags & (1 << 2))) { if (objectType == OBJECT_TYPE_SCENERY_GROUP && (flags & (1 << 2)))
{
for (const auto& sgEntry : item->SceneryGroupInfo.Entries) for (const auto& sgEntry : item->SceneryGroupInfo.Entries)
{ {
window_editor_object_selection_select_object(++bh, flags, &sgEntry); window_editor_object_selection_select_object(++bh, flags, &sgEntry);
@@ -424,28 +450,36 @@ int32_t window_editor_object_selection_select_object(uint8_t bh, int32_t flags,
_numSelectedObjectsForType[objectType]--; _numSelectedObjectsForType[objectType]--;
*selectionFlags &= ~OBJECT_SELECTION_FLAG_SELECTED; *selectionFlags &= ~OBJECT_SELECTION_FLAG_SELECTED;
return 1; return 1;
} else { }
if (bh == 0) { else
if (flags & (1 << 3)) { {
if (bh == 0)
{
if (flags & (1 << 3))
{
*selectionFlags |= OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED; *selectionFlags |= OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED;
} }
} }
if (*selectionFlags & OBJECT_SELECTION_FLAG_SELECTED) { if (*selectionFlags & OBJECT_SELECTION_FLAG_SELECTED)
{
return 1; return 1;
} }
uint8_t objectType = object_entry_get_type(&item->ObjectEntry); uint8_t objectType = object_entry_get_type(&item->ObjectEntry);
uint16_t maxObjects = object_entry_group_counts[objectType]; uint16_t maxObjects = object_entry_group_counts[objectType];
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) { if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
{
maxObjects = 4; maxObjects = 4;
} }
if (maxObjects <= _numSelectedObjectsForType[objectType]) { if (maxObjects <= _numSelectedObjectsForType[objectType])
{
set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_TOO_MANY_OF_TYPE_SELECTED); set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_TOO_MANY_OF_TYPE_SELECTED);
return 0; return 0;
} }
if (objectType == OBJECT_TYPE_SCENERY_GROUP && (flags & (1 << 2))) { if (objectType == OBJECT_TYPE_SCENERY_GROUP && (flags & (1 << 2)))
{
for (const auto& sgEntry : item->SceneryGroupInfo.Entries) for (const auto& sgEntry : item->SceneryGroupInfo.Entries)
{ {
if (!window_editor_object_selection_select_object(++bh, flags, &sgEntry)) if (!window_editor_object_selection_select_object(++bh, flags, &sgEntry))
@@ -455,15 +489,17 @@ int32_t window_editor_object_selection_select_object(uint8_t bh, int32_t flags,
} }
} }
if (bh != 0 && !(flags & (1 << 1))) { if (bh != 0 && !(flags & (1 << 1)))
{
char objectName[64]; char objectName[64];
object_create_identifier_name(objectName, 64, &item->ObjectEntry); object_create_identifier_name(objectName, 64, &item->ObjectEntry);
set_format_arg(0, const char *, objectName); set_format_arg(0, const char*, objectName);
set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_SHOULD_SELECT_X_FIRST); set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_SHOULD_SELECT_X_FIRST);
return 0; return 0;
} }
if (maxObjects <= _numSelectedObjectsForType[objectType]) { if (maxObjects <= _numSelectedObjectsForType[objectType])
{
set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_TOO_MANY_OF_TYPE_SELECTED); set_object_selection_error(bh, STR_OBJECT_SELECTION_ERR_TOO_MANY_OF_TYPE_SELECTED);
return 0; return 0;
} }
@@ -478,11 +514,13 @@ int32_t window_editor_object_selection_select_object(uint8_t bh, int32_t flags,
bool editor_check_object_group_at_least_one_selected(int32_t checkObjectType) bool editor_check_object_group_at_least_one_selected(int32_t checkObjectType)
{ {
int32_t numObjects = (int32_t)object_repository_get_items_count(); int32_t numObjects = (int32_t)object_repository_get_items_count();
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
for (int32_t i = 0; i < numObjects; i++) { for (int32_t i = 0; i < numObjects; i++)
{
uint8_t objectType = object_entry_get_type(&items[i].ObjectEntry); uint8_t objectType = object_entry_get_type(&items[i].ObjectEntry);
if (checkObjectType == objectType && (_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED)) { if (checkObjectType == objectType && (_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_SELECTED))
{
return true; return true;
} }
} }
@@ -495,17 +533,19 @@ int32_t editor_remove_unused_objects()
setup_in_use_selection_flags(); setup_in_use_selection_flags();
int32_t numObjects = (int32_t)object_repository_get_items_count(); int32_t numObjects = (int32_t)object_repository_get_items_count();
const ObjectRepositoryItem * items = object_repository_get_items(); const ObjectRepositoryItem* items = object_repository_get_items();
int32_t numUnselectedObjects = 0; int32_t numUnselectedObjects = 0;
for (int32_t i = 0; i < numObjects; i++) for (int32_t i = 0; i < numObjects; i++)
{ {
if (!(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_IN_USE) && !(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED)) if (!(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_IN_USE)
&& !(_objectSelectionFlags[i] & OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED))
{ {
const ObjectRepositoryItem * item = &items[i]; const ObjectRepositoryItem* item = &items[i];
uint8_t objectType = object_entry_get_type(&item->ObjectEntry); uint8_t objectType = object_entry_get_type(&item->ObjectEntry);
if (objectType == OBJECT_TYPE_PARK_ENTRANCE || objectType == OBJECT_TYPE_SCENARIO_TEXT || objectType == OBJECT_TYPE_WATER || objectType == OBJECT_TYPE_SCENERY_GROUP) if (objectType == OBJECT_TYPE_PARK_ENTRANCE || objectType == OBJECT_TYPE_SCENARIO_TEXT
|| objectType == OBJECT_TYPE_WATER || objectType == OBJECT_TYPE_SCENERY_GROUP)
{ {
continue; continue;
} }

View File

@@ -9,10 +9,11 @@
#pragma once #pragma once
#include <vector>
#include "common.h" #include "common.h"
#include "object/Object.h" #include "object/Object.h"
#include <vector>
extern bool _maxObjectsWasHit; extern bool _maxObjectsWasHit;
extern std::vector<uint8_t> _objectSelectionFlags; extern std::vector<uint8_t> _objectSelectionFlags;
extern int32_t _numSelectedObjectsForType[OBJECT_TYPE_COUNT]; extern int32_t _numSelectedObjectsForType[OBJECT_TYPE_COUNT];
@@ -22,11 +23,10 @@ void editor_object_flags_free();
void unload_unselected_objects(); void unload_unselected_objects();
void sub_6AB211(); void sub_6AB211();
void reset_selected_object_count_and_size(); void reset_selected_object_count_and_size();
int32_t window_editor_object_selection_select_object(uint8_t bh, int32_t flags, const rct_object_entry *entry); int32_t window_editor_object_selection_select_object(uint8_t bh, int32_t flags, const rct_object_entry* entry);
/** /**
* Removes all unused objects from the object selection. * Removes all unused objects from the object selection.
* @return The number of removed objects. * @return The number of removed objects.
*/ */
int32_t editor_remove_unused_objects(); int32_t editor_remove_unused_objects();

View File

@@ -7,33 +7,33 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "FileClassifier.h"
#include "core/Console.hpp" #include "core/Console.hpp"
#include "core/FileStream.hpp" #include "core/FileStream.hpp"
#include "core/Path.hpp" #include "core/Path.hpp"
#include "FileClassifier.h"
#include "rct12/SawyerChunkReader.h" #include "rct12/SawyerChunkReader.h"
#include "scenario/Scenario.h" #include "scenario/Scenario.h"
#include "util/SawyerCoding.h" #include "util/SawyerCoding.h"
static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result); static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result);
static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result); static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result);
static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result); static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result);
bool TryClassifyFile(const std::string &path, ClassifiedFileInfo * result) bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result)
{ {
try try
{ {
auto fs = FileStream(path, FILE_MODE_OPEN); auto fs = FileStream(path, FILE_MODE_OPEN);
return TryClassifyFile(&fs, result); return TryClassifyFile(&fs, result);
} }
catch (const std::exception &) catch (const std::exception&)
{ {
return false; return false;
} }
} }
bool TryClassifyFile(IStream * stream, ClassifiedFileInfo * result) bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result)
{ {
// TODO Currently track designs get classified as SC4s because they use the // TODO Currently track designs get classified as SC4s because they use the
// same checksum algorithm. The only way after to tell the difference // same checksum algorithm. The only way after to tell the difference
@@ -61,7 +61,7 @@ bool TryClassifyFile(IStream * stream, ClassifiedFileInfo * result)
return false; return false;
} }
static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result) static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result)
{ {
bool success = false; bool success = false;
uint64_t originalPosition = stream->GetPosition(); uint64_t originalPosition = stream->GetPosition();
@@ -80,7 +80,7 @@ static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result)
result->Version = s6Header.version; result->Version = s6Header.version;
success = true; success = true;
} }
catch (const std::exception &e) catch (const std::exception& e)
{ {
// Exceptions are likely to occur if file is not S6 format // Exceptions are likely to occur if file is not S6 format
log_verbose(e.what()); log_verbose(e.what());
@@ -89,14 +89,14 @@ static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result)
return success; return success;
} }
static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result) static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result)
{ {
bool success = false; bool success = false;
uint64_t originalPosition = stream->GetPosition(); uint64_t originalPosition = stream->GetPosition();
try try
{ {
size_t dataLength = (size_t)stream->GetLength(); size_t dataLength = (size_t)stream->GetLength();
auto deleter_lambda = [dataLength](uint8_t * ptr) { Memory::FreeArray(ptr, dataLength); }; auto deleter_lambda = [dataLength](uint8_t* ptr) { Memory::FreeArray(ptr, dataLength); };
std::unique_ptr<uint8_t, decltype(deleter_lambda)> data(stream->ReadArray<uint8_t>(dataLength), deleter_lambda); std::unique_ptr<uint8_t, decltype(deleter_lambda)> data(stream->ReadArray<uint8_t>(dataLength), deleter_lambda);
stream->SetPosition(originalPosition); stream->SetPosition(originalPosition);
int32_t fileTypeVersion = sawyercoding_detect_file_type(data.get(), dataLength); int32_t fileTypeVersion = sawyercoding_detect_file_type(data.get(), dataLength);
@@ -117,7 +117,7 @@ static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result)
success = true; success = true;
} }
} }
catch (const std::exception &e) catch (const std::exception& e)
{ {
Console::Error::WriteLine(e.what()); Console::Error::WriteLine(e.what());
} }
@@ -126,20 +126,21 @@ static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result)
return success; return success;
} }
static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result) static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result)
{ {
bool success = false; bool success = false;
uint64_t originalPosition = stream->GetPosition(); uint64_t originalPosition = stream->GetPosition();
try try
{ {
size_t dataLength = (size_t)stream->GetLength(); size_t dataLength = (size_t)stream->GetLength();
auto deleter_lambda = [dataLength](uint8_t * ptr) { Memory::FreeArray(ptr, dataLength); }; auto deleter_lambda = [dataLength](uint8_t* ptr) { Memory::FreeArray(ptr, dataLength); };
std::unique_ptr<uint8_t, decltype(deleter_lambda)> data(stream->ReadArray<uint8_t>(dataLength), deleter_lambda); std::unique_ptr<uint8_t, decltype(deleter_lambda)> data(stream->ReadArray<uint8_t>(dataLength), deleter_lambda);
stream->SetPosition(originalPosition); stream->SetPosition(originalPosition);
if (sawyercoding_validate_track_checksum(data.get(), dataLength)) if (sawyercoding_validate_track_checksum(data.get(), dataLength))
{ {
std::unique_ptr<uint8_t, decltype(&Memory::Free<uint8_t>)> td6data(Memory::Allocate<uint8_t>(0x10000), &Memory::Free<uint8_t>); std::unique_ptr<uint8_t, decltype(&Memory::Free<uint8_t>)> td6data(
Memory::Allocate<uint8_t>(0x10000), &Memory::Free<uint8_t>);
size_t td6len = sawyercoding_decode_td6(data.get(), td6data.get(), dataLength); size_t td6len = sawyercoding_decode_td6(data.get(), td6data.get(), dataLength);
if (td6data != nullptr && td6len >= 8) if (td6data != nullptr && td6len >= 8)
{ {
@@ -161,16 +162,22 @@ static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result)
return success; return success;
} }
uint32_t get_file_extension_type(const utf8 * path) uint32_t get_file_extension_type(const utf8* path)
{ {
auto extension = Path::GetExtension(path); auto extension = Path::GetExtension(path);
if (String::Equals(extension, ".dat", true)) return FILE_EXTENSION_DAT; if (String::Equals(extension, ".dat", true))
if (String::Equals(extension, ".sc4", true)) return FILE_EXTENSION_SC4; return FILE_EXTENSION_DAT;
if (String::Equals(extension, ".sv4", true)) return FILE_EXTENSION_SV4; if (String::Equals(extension, ".sc4", true))
if (String::Equals(extension, ".td4", true)) return FILE_EXTENSION_TD4; return FILE_EXTENSION_SC4;
if (String::Equals(extension, ".sc6", true)) return FILE_EXTENSION_SC6; if (String::Equals(extension, ".sv4", true))
if (String::Equals(extension, ".sv6", true)) return FILE_EXTENSION_SV6; return FILE_EXTENSION_SV4;
if (String::Equals(extension, ".td6", true)) return FILE_EXTENSION_TD6; if (String::Equals(extension, ".td4", true))
return FILE_EXTENSION_TD4;
if (String::Equals(extension, ".sc6", true))
return FILE_EXTENSION_SC6;
if (String::Equals(extension, ".sv6", true))
return FILE_EXTENSION_SV6;
if (String::Equals(extension, ".td6", true))
return FILE_EXTENSION_TD6;
return FILE_EXTENSION_UNKNOWN; return FILE_EXTENSION_UNKNOWN;
} }

View File

@@ -43,7 +43,7 @@ struct ClassifiedFileInfo
}; };
#define FILE_TYPE_S4_CUTOFF 2 #define FILE_TYPE_S4_CUTOFF 2
bool TryClassifyFile(const std::string &path, ClassifiedFileInfo * result); bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result);
bool TryClassifyFile(IStream * stream, ClassifiedFileInfo * result); bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result);
uint32_t get_file_extension_type(const utf8 * path); uint32_t get_file_extension_type(const utf8* path);

View File

@@ -7,18 +7,20 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include <memory> #include "Game.h"
#include "audio/audio.h"
#include "Cheats.h" #include "Cheats.h"
#include "config/Config.h"
#include "Context.h" #include "Context.h"
#include "Editor.h"
#include "FileClassifier.h"
#include "Input.h"
#include "OpenRCT2.h"
#include "ParkImporter.h"
#include "audio/audio.h"
#include "config/Config.h"
#include "core/FileScanner.h" #include "core/FileScanner.h"
#include "core/Math.hpp" #include "core/Math.hpp"
#include "core/Util.hpp" #include "core/Util.hpp"
#include "Editor.h"
#include "FileClassifier.h"
#include "Game.h"
#include "Input.h"
#include "interface/Screenshot.h" #include "interface/Screenshot.h"
#include "interface/Viewport.h" #include "interface/Viewport.h"
#include "interface/Window.h" #include "interface/Window.h"
@@ -29,8 +31,7 @@
#include "management/Research.h" #include "management/Research.h"
#include "network/network.h" #include "network/network.h"
#include "object/Object.h" #include "object/Object.h"
#include "OpenRCT2.h" #include "object/ObjectList.h"
#include "ParkImporter.h"
#include "peep/Peep.h" #include "peep/Peep.h"
#include "peep/Staff.h" #include "peep/Staff.h"
#include "platform/platform.h" #include "platform/platform.h"
@@ -59,7 +60,8 @@
#include "world/Sprite.h" #include "world/Sprite.h"
#include "world/Surface.h" #include "world/Surface.h"
#include "world/Water.h" #include "world/Water.h"
#include "object/ObjectList.h"
#include <memory>
#define NUMBER_OF_AUTOSAVES_TO_KEEP 9 #define NUMBER_OF_AUTOSAVES_TO_KEEP 9
@@ -104,7 +106,7 @@ rct_string_id gErrorStringId;
using namespace OpenRCT2; using namespace OpenRCT2;
int32_t game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER * callback) int32_t game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER* callback)
{ {
for (uint32_t i = 0; i < Util::CountOf(game_command_callback_table); i++) for (uint32_t i = 0; i < Util::CountOf(game_command_callback_table); i++)
{ {
@@ -116,7 +118,7 @@ int32_t game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER * callback
return 0; return 0;
} }
GAME_COMMAND_CALLBACK_POINTER * game_command_callback_get_callback(uint32_t index) GAME_COMMAND_CALLBACK_POINTER* game_command_callback_get_callback(uint32_t index)
{ {
if (index < Util::CountOf(game_command_callback_table)) if (index < Util::CountOf(game_command_callback_table))
{ {
@@ -168,12 +170,12 @@ enum
}; };
/** /**
* *
* rct2: 0x006838BD * rct2: 0x006838BD
*/ */
void update_palette_effects() void update_palette_effects()
{ {
auto water_type = (rct_water_type *)object_entry_get_chunk(OBJECT_TYPE_WATER, 0); auto water_type = (rct_water_type*)object_entry_get_chunk(OBJECT_TYPE_WATER, 0);
if (gClimateLightningFlash == 1) if (gClimateLightningFlash == 1)
{ {
@@ -184,12 +186,12 @@ void update_palette_effects()
{ {
palette = water_type->image_id; palette = water_type->image_id;
} }
const rct_g1_element * g1 = gfx_get_g1_element(palette); const rct_g1_element* g1 = gfx_get_g1_element(palette);
if (g1 != nullptr) if (g1 != nullptr)
{ {
int32_t xoffset = g1->x_offset; int32_t xoffset = g1->x_offset;
xoffset = xoffset * 4; xoffset = xoffset * 4;
uint8_t * paletteOffset = gGamePalette + xoffset; uint8_t* paletteOffset = gGamePalette + xoffset;
for (int32_t i = 0; i < g1->width; i++) for (int32_t i = 0; i < g1->width; i++)
{ {
paletteOffset[(i * 4) + 0] = -((0xFF - g1->offset[(i * 3) + 0]) / 2) - 1; paletteOffset[(i * 4) + 0] = -((0xFF - g1->offset[(i * 3) + 0]) / 2) - 1;
@@ -212,12 +214,12 @@ void update_palette_effects()
palette = water_type->image_id; palette = water_type->image_id;
} }
const rct_g1_element * g1 = gfx_get_g1_element(palette); const rct_g1_element* g1 = gfx_get_g1_element(palette);
if (g1 != nullptr) if (g1 != nullptr)
{ {
int32_t xoffset = g1->x_offset; int32_t xoffset = g1->x_offset;
xoffset = xoffset * 4; xoffset = xoffset * 4;
uint8_t * paletteOffset = gGamePalette + xoffset; uint8_t* paletteOffset = gGamePalette + xoffset;
for (int32_t i = 0; i < g1->width; i++) for (int32_t i = 0; i < g1->width; i++)
{ {
paletteOffset[(i * 4) + 0] = g1->offset[(i * 3) + 0]; paletteOffset[(i * 4) + 0] = g1->offset[(i * 3) + 0];
@@ -242,17 +244,17 @@ void update_palette_effects()
} }
} }
uint32_t j = gPaletteEffectFrame; uint32_t j = gPaletteEffectFrame;
j = (((uint16_t) ((~j / 2) * 128) * 15) >> 16); j = (((uint16_t)((~j / 2) * 128) * 15) >> 16);
uint32_t waterId = SPR_GAME_PALETTE_WATER; uint32_t waterId = SPR_GAME_PALETTE_WATER;
if (water_type != nullptr) if (water_type != nullptr)
{ {
waterId = water_type->palette_index_1; waterId = water_type->palette_index_1;
} }
const rct_g1_element * g1 = gfx_get_g1_element(shade + waterId); const rct_g1_element* g1 = gfx_get_g1_element(shade + waterId);
if (g1 != nullptr) if (g1 != nullptr)
{ {
uint8_t * vs = &g1->offset[j * 3]; uint8_t* vs = &g1->offset[j * 3];
uint8_t * vd = &gGamePalette[230 * 4]; uint8_t* vd = &gGamePalette[230 * 4];
int32_t n = 5; int32_t n = 5;
for (int32_t i = 0; i < n; i++) for (int32_t i = 0; i < n; i++)
{ {
@@ -276,8 +278,8 @@ void update_palette_effects()
g1 = gfx_get_g1_element(shade + waterId); g1 = gfx_get_g1_element(shade + waterId);
if (g1 != nullptr) if (g1 != nullptr)
{ {
uint8_t * vs = &g1->offset[j * 3]; uint8_t* vs = &g1->offset[j * 3];
uint8_t * vd = &gGamePalette[235 * 4]; uint8_t* vd = &gGamePalette[235 * 4];
int32_t n = 5; int32_t n = 5;
for (int32_t i = 0; i < n; i++) for (int32_t i = 0; i < n; i++)
{ {
@@ -293,13 +295,13 @@ void update_palette_effects()
} }
} }
j = ((uint16_t) (gPaletteEffectFrame * -960) * 3) >> 16; j = ((uint16_t)(gPaletteEffectFrame * -960) * 3) >> 16;
waterId = SPR_GAME_PALETTE_4; waterId = SPR_GAME_PALETTE_4;
g1 = gfx_get_g1_element(shade + waterId); g1 = gfx_get_g1_element(shade + waterId);
if (g1 != nullptr) if (g1 != nullptr)
{ {
uint8_t * vs = &g1->offset[j * 3]; uint8_t* vs = &g1->offset[j * 3];
uint8_t * vd = &gGamePalette[243 * 4]; uint8_t* vd = &gGamePalette[243 * 4];
int32_t n = 3; int32_t n = 3;
for (int32_t i = 0; i < n; i++) for (int32_t i = 0; i < n; i++)
{ {
@@ -357,13 +359,14 @@ int32_t game_do_command(int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int3
} }
/** /**
* *
* rct2: 0x006677F2 with pointers as arguments * rct2: 0x006677F2 with pointers as arguments
* *
* @param ebx flags * @param ebx flags
* @param esi command * @param esi command
*/ */
int32_t game_do_command_p(uint32_t command, int32_t * eax, int32_t * ebx, int32_t * ecx, int32_t * edx, int32_t * esi, int32_t * edi, int32_t * ebp) int32_t game_do_command_p(
uint32_t command, int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp)
{ {
int32_t cost, flags; int32_t cost, flags;
int32_t original_ebx, original_edx, original_esi, original_edi, original_ebp; int32_t original_ebx, original_edx, original_esi, original_edi, original_ebp;
@@ -392,12 +395,10 @@ int32_t game_do_command_p(uint32_t command, int32_t * eax, int32_t * ebx, int32_
gGameCommandNestLevel++; gGameCommandNestLevel++;
// Remove ghost scenery so it doesn't interfere with incoming network command // Remove ghost scenery so it doesn't interfere with incoming network command
if ((flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST) && if ((flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST)
(command == GAME_COMMAND_PLACE_WALL || && (command == GAME_COMMAND_PLACE_WALL || command == GAME_COMMAND_PLACE_SCENERY
command == GAME_COMMAND_PLACE_SCENERY || || command == GAME_COMMAND_PLACE_LARGE_SCENERY || command == GAME_COMMAND_PLACE_BANNER
command == GAME_COMMAND_PLACE_LARGE_SCENERY || || command == GAME_COMMAND_PLACE_PATH))
command == GAME_COMMAND_PLACE_BANNER ||
command == GAME_COMMAND_PLACE_PATH))
{ {
scenery_remove_ghost_tool_placement(); scenery_remove_ghost_tool_placement();
} }
@@ -408,8 +409,10 @@ int32_t game_do_command_p(uint32_t command, int32_t * eax, int32_t * ebx, int32_
} }
// Log certain commands if we are in multiplayer and logging is enabled // 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 serverLog
bool clientLog = (network_get_mode() == NETWORK_MODE_CLIENT) && (flags & GAME_COMMAND_FLAG_NETWORKED) && gGameCommandNestLevel == 1 && gConfigNetwork.log_server_actions; = (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;
if (serverLog || clientLog) if (serverLog || clientLog)
{ {
game_log_multiplayer_command(command, eax, ebx, ecx, edx, edi, ebp); game_log_multiplayer_command(command, eax, ebx, ecx, edx, edi, ebp);
@@ -443,19 +446,19 @@ int32_t game_do_command_p(uint32_t command, int32_t * eax, int32_t * ebx, int32_
return cost; return cost;
} }
if (network_get_mode() != NETWORK_MODE_NONE && if (network_get_mode() != NETWORK_MODE_NONE && !(flags & GAME_COMMAND_FLAG_NETWORKED)
!(flags & GAME_COMMAND_FLAG_NETWORKED) && && !(flags & GAME_COMMAND_FLAG_GHOST) && !(flags & GAME_COMMAND_FLAG_5)
!(flags & GAME_COMMAND_FLAG_GHOST) && && gGameCommandNestLevel == 1) /* Send only top-level commands */
!(flags & GAME_COMMAND_FLAG_5) &&
gGameCommandNestLevel == 1) /* Send only top-level commands */
{ {
// Disable these commands over the network // Disable these commands over the network
if (command != GAME_COMMAND_LOAD_OR_QUIT) if (command != GAME_COMMAND_LOAD_OR_QUIT)
{ {
network_send_gamecmd(*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp, game_command_callback_get_index(game_command_callback)); network_send_gamecmd(
*eax, *ebx, *ecx, *edx, *esi, *edi, *ebp, game_command_callback_get_index(game_command_callback));
if (network_get_mode() == NETWORK_MODE_CLIENT) if (network_get_mode() == NETWORK_MODE_CLIENT)
{ {
// Client sent the command to the server, do not run it locally, just return. It will run when server sends it. // Client sent the command to the server, do not run it locally, just return. It will run when server
// sends it.
game_command_callback = nullptr; game_command_callback = nullptr;
// Decrement nest count // Decrement nest count
gGameCommandNestLevel--; gGameCommandNestLevel--;
@@ -502,7 +505,8 @@ int32_t game_do_command_p(uint32_t command, int32_t * eax, int32_t * ebx, int32_
} }
} }
if (network_get_mode() == NETWORK_MODE_SERVER && !(flags & GAME_COMMAND_FLAG_NETWORKED) && !(flags & GAME_COMMAND_FLAG_GHOST)) if (network_get_mode() == NETWORK_MODE_SERVER && !(flags & GAME_COMMAND_FLAG_NETWORKED)
&& !(flags & GAME_COMMAND_FLAG_GHOST))
{ {
network_set_player_last_action(network_get_player_index(network_get_current_player_id()), command); 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); network_add_player_money_spent(network_get_current_player_id(), cost);
@@ -525,41 +529,37 @@ int32_t game_do_command_p(uint32_t command, int32_t * eax, int32_t * ebx, int32_
game_command_callback = nullptr; game_command_callback = nullptr;
// Show error window // 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)) 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); context_show_error(gGameCommandErrorTitle, gGameCommandErrorText);
return MONEY32_UNDEFINED; return MONEY32_UNDEFINED;
} }
void game_log_multiplayer_command(int command, const int * eax, const int * ebx, const int * ecx, int * edx, int * edi, int * ebp) void game_log_multiplayer_command(int command, const int* eax, const int* ebx, const int* ecx, int* edx, int* edi, int* ebp)
{ {
// Get player name // Get player name
int player_index = network_get_player_index(game_command_playerid); int player_index = network_get_player_index(game_command_playerid);
const char * player_name = network_get_player_name(player_index); const char* player_name = network_get_player_name(player_index);
char log_msg[256]; char log_msg[256];
if (command == GAME_COMMAND_CHEAT) if (command == GAME_COMMAND_CHEAT)
{ {
// Get cheat name // Get cheat name
const char * cheat = cheats_get_cheat_string(*ecx, *edx, *edi); const char* cheat = cheats_get_cheat_string(*ecx, *edx, *edi);
char * args[2] = { char* args[2] = { (char*)player_name, (char*)cheat };
(char *) player_name,
(char *) cheat
};
format_string(log_msg, 256, STR_LOG_CHEAT_USED, args); format_string(log_msg, 256, STR_LOG_CHEAT_USED, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
} }
else if (command == GAME_COMMAND_CREATE_RIDE && *ebp == 1) 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 { // 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
// Get ride name // Get ride name
Ride * ride = get_ride(*edx); Ride* ride = get_ride(*edx);
char ride_name[128]; char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments); format_string(ride_name, 128, ride->name, &ride->name_arguments);
char * args[2] = { char* args[2] = { (char*)player_name, ride_name };
(char *) player_name,
ride_name
};
format_string(log_msg, 256, STR_LOG_CREATE_RIDE, args); format_string(log_msg, 256, STR_LOG_CREATE_RIDE, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
@@ -567,30 +567,26 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
else if (command == GAME_COMMAND_DEMOLISH_RIDE && (*ebp == 1 || *ebp == 0)) 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 { // ebp is 1 if command comes from ride window prompt, so we don't log "demolishing" ride previews
// Get ride name // Get ride name
Ride * ride = get_ride(*edx); Ride* ride = get_ride(*edx);
char ride_name[128]; char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments); format_string(ride_name, 128, ride->name, &ride->name_arguments);
char * args[2] = { char* args[2] = { (char*)player_name, ride_name };
(char *) player_name,
ride_name
};
format_string(log_msg, 256, STR_LOG_DEMOLISH_RIDE, args); format_string(log_msg, 256, STR_LOG_DEMOLISH_RIDE, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
} }
else if (command == GAME_COMMAND_SET_RIDE_APPEARANCE || command == GAME_COMMAND_SET_RIDE_VEHICLES || command == GAME_COMMAND_SET_RIDE_SETTING) else if (
command == GAME_COMMAND_SET_RIDE_APPEARANCE || command == GAME_COMMAND_SET_RIDE_VEHICLES
|| command == GAME_COMMAND_SET_RIDE_SETTING)
{ {
// Get ride name // Get ride name
int ride_index = *edx & 0xFF; int ride_index = *edx & 0xFF;
Ride * ride = get_ride(ride_index); Ride* ride = get_ride(ride_index);
char ride_name[128]; char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments); format_string(ride_name, 128, ride->name, &ride->name_arguments);
char * args[2] = { char* args[2] = { (char*)player_name, ride_name };
(char *) player_name,
ride_name
};
switch (command) switch (command)
{ {
@@ -611,14 +607,11 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
{ {
// Get ride name // Get ride name
int ride_index = *edx & 0xFF; int ride_index = *edx & 0xFF;
Ride * ride = get_ride(ride_index); Ride* ride = get_ride(ride_index);
char ride_name[128]; char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments); format_string(ride_name, 128, ride->name, &ride->name_arguments);
char * args[2] = { char* args[2] = { (char*)player_name, ride_name };
(char *) player_name,
ride_name
};
int status = *edx >> 8; int status = *edx >> 8;
switch (status) switch (status)
@@ -640,21 +633,17 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
{ {
// Get ride name // Get ride name
int ride_index = *edx & 0xFF; int ride_index = *edx & 0xFF;
Ride * ride = get_ride(ride_index); Ride* ride = get_ride(ride_index);
char ride_name[128]; char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments); format_string(ride_name, 128, ride->name, &ride->name_arguments);
// Format price // Format price
int price_args[1] = {*edi}; int price_args[1] = { *edi };
char price_str[16]; char price_str[16];
format_string(price_str, 16, STR_BOTTOM_TOOLBAR_CASH, price_args); format_string(price_str, 16, STR_BOTTOM_TOOLBAR_CASH, price_args);
// Log change in primary or secondary price // Log change in primary or secondary price
char * args[3] = { char* args[3] = { (char*)player_name, ride_name, price_str };
(char *) player_name,
ride_name,
price_str
};
if (*edx >> 8 == 0) if (*edx >> 8 == 0)
{ {
@@ -670,9 +659,7 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
else if (command == GAME_COMMAND_SET_PARK_OPEN) else if (command == GAME_COMMAND_SET_PARK_OPEN)
{ {
// Log change in park open/close // Log change in park open/close
char * args[1] = { char* args[1] = { (char*)player_name };
(char *) player_name
};
if (*edx >> 8 == 0) if (*edx >> 8 == 0)
{ {
@@ -688,21 +675,19 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
else if (command == GAME_COMMAND_SET_PARK_ENTRANCE_FEE) else if (command == GAME_COMMAND_SET_PARK_ENTRANCE_FEE)
{ {
// Format price // Format price
int price_args[1] = {*edi}; int price_args[1] = { *edi };
char price_str[16]; char price_str[16];
format_string(price_str, 16, STR_BOTTOM_TOOLBAR_CASH, price_args); format_string(price_str, 16, STR_BOTTOM_TOOLBAR_CASH, price_args);
// Log change in park entrance fee // Log change in park entrance fee
char * args[2] = { char* args[2] = { (char*)player_name, price_str };
(char *) player_name,
price_str
};
format_string(log_msg, 256, STR_LOG_PARK_ENTRANCE_FEE, args); format_string(log_msg, 256, STR_LOG_PARK_ENTRANCE_FEE, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
} }
else if (command == GAME_COMMAND_PLACE_SCENERY || command == GAME_COMMAND_PLACE_WALL || else if (
command == GAME_COMMAND_PLACE_LARGE_SCENERY || command == GAME_COMMAND_PLACE_BANNER) command == GAME_COMMAND_PLACE_SCENERY || command == GAME_COMMAND_PLACE_WALL
|| command == GAME_COMMAND_PLACE_LARGE_SCENERY || command == GAME_COMMAND_PLACE_BANNER)
{ {
uint8_t flags = *ebx & 0xFF; uint8_t flags = *ebx & 0xFF;
if (flags & GAME_COMMAND_FLAG_GHOST) if (flags & GAME_COMMAND_FLAG_GHOST)
@@ -712,15 +697,14 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
} }
// Log placing scenery // Log placing scenery
char * args[1] = { char* args[1] = { (char*)player_name };
(char *) player_name
};
format_string(log_msg, 256, STR_LOG_PLACE_SCENERY, args); format_string(log_msg, 256, STR_LOG_PLACE_SCENERY, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
} }
else if (command == GAME_COMMAND_REMOVE_SCENERY || command == GAME_COMMAND_REMOVE_WALL || else if (
command == GAME_COMMAND_REMOVE_LARGE_SCENERY || command == GAME_COMMAND_REMOVE_BANNER) command == GAME_COMMAND_REMOVE_SCENERY || command == GAME_COMMAND_REMOVE_WALL
|| command == GAME_COMMAND_REMOVE_LARGE_SCENERY || command == GAME_COMMAND_REMOVE_BANNER)
{ {
uint8_t flags = *ebx & 0xFF; uint8_t flags = *ebx & 0xFF;
if (flags & GAME_COMMAND_FLAG_GHOST) if (flags & GAME_COMMAND_FLAG_GHOST)
@@ -730,22 +714,19 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
} }
// Log removing scenery // Log removing scenery
char * args[1] = { char* args[1] = { (char*)player_name };
(char *) player_name
};
format_string(log_msg, 256, STR_LOG_REMOVE_SCENERY, args); format_string(log_msg, 256, STR_LOG_REMOVE_SCENERY, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
} }
else if (command == GAME_COMMAND_SET_SCENERY_COLOUR || command == GAME_COMMAND_SET_WALL_COLOUR || else if (
command == GAME_COMMAND_SET_LARGE_SCENERY_COLOUR || command == GAME_COMMAND_SET_BANNER_COLOUR || command == GAME_COMMAND_SET_SCENERY_COLOUR || command == GAME_COMMAND_SET_WALL_COLOUR
command == GAME_COMMAND_SET_BANNER_NAME || command == GAME_COMMAND_SET_SIGN_NAME || || command == GAME_COMMAND_SET_LARGE_SCENERY_COLOUR || command == GAME_COMMAND_SET_BANNER_COLOUR
command == GAME_COMMAND_SET_BANNER_STYLE || command == GAME_COMMAND_SET_SIGN_STYLE) || command == GAME_COMMAND_SET_BANNER_NAME || command == GAME_COMMAND_SET_SIGN_NAME
|| command == GAME_COMMAND_SET_BANNER_STYLE || command == GAME_COMMAND_SET_SIGN_STYLE)
{ {
// Log editing scenery // Log editing scenery
char * args[1] = { char* args[1] = { (char*)player_name };
(char *) player_name
};
format_string(log_msg, 256, STR_LOG_EDIT_SCENERY, args); format_string(log_msg, 256, STR_LOG_EDIT_SCENERY, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
@@ -760,15 +741,12 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
if (nameChunkOffset < 0) if (nameChunkOffset < 0)
nameChunkOffset = 2; nameChunkOffset = 2;
nameChunkOffset *= 12; nameChunkOffset *= 12;
nameChunkOffset = std::min(nameChunkOffset, (int32_t) (Util::CountOf(banner_name) - 12)); nameChunkOffset = std::min(nameChunkOffset, (int32_t)(Util::CountOf(banner_name) - 12));
memcpy(banner_name + nameChunkOffset + 0, edx, 4); memcpy(banner_name + nameChunkOffset + 0, edx, 4);
memcpy(banner_name + nameChunkOffset + 4, ebp, 4); memcpy(banner_name + nameChunkOffset + 4, ebp, 4);
memcpy(banner_name + nameChunkOffset + 8, edi, 4); memcpy(banner_name + nameChunkOffset + 8, edi, 4);
banner_name[sizeof(banner_name) - 1] = '\0'; banner_name[sizeof(banner_name) - 1] = '\0';
char * args_sign[2] = { char* args_sign[2] = { (char*)player_name, (char*)banner_name };
(char *) player_name,
(char *) banner_name
};
format_string(log_msg, 256, STR_LOG_SET_SIGN_NAME, args_sign); format_string(log_msg, 256, STR_LOG_SET_SIGN_NAME, args_sign);
network_append_server_log(log_msg); network_append_server_log(log_msg);
@@ -778,32 +756,25 @@ void game_log_multiplayer_command(int command, const int * eax, const int * ebx,
{ {
// Get ride name // Get ride name
int ride_index = *edx & 0xFF; int ride_index = *edx & 0xFF;
Ride * ride = get_ride(ride_index); Ride* ride = get_ride(ride_index);
char ride_name[128]; char ride_name[128];
format_string(ride_name, 128, ride->name, &ride->name_arguments); format_string(ride_name, 128, ride->name, &ride->name_arguments);
char * args[2] = { char* args[2] = { (char*)player_name, ride_name };
(char *) player_name,
ride_name
};
format_string(log_msg, 256, STR_LOG_PLACE_TRACK, args); format_string(log_msg, 256, STR_LOG_PLACE_TRACK, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
} }
else if (command == GAME_COMMAND_REMOVE_TRACK) else if (command == GAME_COMMAND_REMOVE_TRACK)
{ {
char * args[1] = { char* args[1] = { (char*)player_name };
(char *) player_name
};
format_string(log_msg, 256, STR_LOG_REMOVE_TRACK, args); format_string(log_msg, 256, STR_LOG_REMOVE_TRACK, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
} }
else if (command == GAME_COMMAND_PLACE_PEEP_SPAWN) else if (command == GAME_COMMAND_PLACE_PEEP_SPAWN)
{ {
char * args[1] = { char* args[1] = { (char*)player_name };
(char *) player_name
};
format_string(log_msg, 256, STR_LOG_PLACE_PEEP_SPAWN, args); format_string(log_msg, 256, STR_LOG_PLACE_PEEP_SPAWN, args);
network_append_server_log(log_msg); network_append_server_log(log_msg);
@@ -835,13 +806,13 @@ bool game_is_not_paused()
* rct2: 0x00667C15 * rct2: 0x00667C15
*/ */
void game_pause_toggle( void game_pause_toggle(
[[maybe_unused]] int32_t * eax, [[maybe_unused]] int32_t* eax,
int32_t * ebx, int32_t* ebx,
[[maybe_unused]] int32_t * ecx, [[maybe_unused]] int32_t* ecx,
[[maybe_unused]] int32_t * edx, [[maybe_unused]] int32_t* edx,
[[maybe_unused]] int32_t * esi, [[maybe_unused]] int32_t* esi,
[[maybe_unused]] int32_t * edi, [[maybe_unused]] int32_t* edi,
[[maybe_unused]] int32_t * ebp) [[maybe_unused]] int32_t* ebp)
{ {
if (*ebx & GAME_COMMAND_FLAG_APPLY) if (*ebx & GAME_COMMAND_FLAG_APPLY)
pause_toggle(); pause_toggle();
@@ -854,13 +825,13 @@ void game_pause_toggle(
* rct2: 0x0066DB5F * rct2: 0x0066DB5F
*/ */
static void game_load_or_quit( static void game_load_or_quit(
[[maybe_unused]] int32_t * eax, [[maybe_unused]] int32_t* eax,
int32_t * ebx, int32_t* ebx,
[[maybe_unused]] int32_t * ecx, [[maybe_unused]] int32_t* ecx,
int32_t * edx, int32_t* edx,
[[maybe_unused]] int32_t * esi, [[maybe_unused]] int32_t* esi,
int32_t * edi, int32_t* edi,
[[maybe_unused]] int32_t * ebp) [[maybe_unused]] int32_t* ebp)
{ {
if (*ebx & GAME_COMMAND_FLAG_APPLY) if (*ebx & GAME_COMMAND_FLAG_APPLY)
{ {
@@ -892,16 +863,16 @@ static void load_landscape()
context_open_intent(&intent); context_open_intent(&intent);
} }
void utf8_to_rct2_self(char * buffer, size_t length) void utf8_to_rct2_self(char* buffer, size_t length)
{ {
auto temp = utf8_to_rct2(buffer); auto temp = utf8_to_rct2(buffer);
size_t i = 0; size_t i = 0;
const char * src = temp.data(); const char* src = temp.data();
char * dst = buffer; char* dst = buffer;
while (*src != 0 && i < length - 1) while (*src != 0 && i < length - 1)
{ {
if (*src == (char) (uint8_t) 0xFF) if (*src == (char)(uint8_t)0xFF)
{ {
if (i < length - 3) if (i < length - 3)
{ {
@@ -925,11 +896,10 @@ void utf8_to_rct2_self(char * buffer, size_t length)
{ {
*dst++ = '\0'; *dst++ = '\0';
i++; i++;
} } while (i < length);
while (i < length);
} }
void rct2_to_utf8_self(char * buffer, size_t length) void rct2_to_utf8_self(char* buffer, size_t length)
{ {
if (length > 0) if (length > 0)
{ {
@@ -949,7 +919,7 @@ void game_convert_strings_to_utf8()
rct2_to_utf8_self(gScenarioDetails, 256); rct2_to_utf8_self(gScenarioDetails, 256);
// User strings // User strings
for (auto * string : gUserStrings) for (auto* string : gUserStrings)
{ {
if (!str_is_null_or_empty(string)) if (!str_is_null_or_empty(string))
{ {
@@ -960,14 +930,13 @@ void game_convert_strings_to_utf8()
// News items // News items
game_convert_news_items_to_utf8(); game_convert_news_items_to_utf8();
} }
void game_convert_news_items_to_utf8() void game_convert_news_items_to_utf8()
{ {
for (int32_t i = 0; i < MAX_NEWS_ITEMS; i++) for (int32_t i = 0; i < MAX_NEWS_ITEMS; i++)
{ {
NewsItem * newsItem = news_item_get(i); NewsItem* newsItem = news_item_get(i);
if (!str_is_null_or_empty(newsItem->Text)) if (!str_is_null_or_empty(newsItem->Text))
{ {
@@ -979,7 +948,7 @@ void game_convert_news_items_to_utf8()
/** /**
* Converts all the user strings and news item strings to RCT2 encoding. * Converts all the user strings and news item strings to RCT2 encoding.
*/ */
void game_convert_strings_to_rct2(rct_s6_data * s6) void game_convert_strings_to_rct2(rct_s6_data* s6)
{ {
// Scenario details // Scenario details
utf8_to_rct2_self(s6->scenario_completed_name, sizeof(s6->scenario_completed_name)); utf8_to_rct2_self(s6->scenario_completed_name, sizeof(s6->scenario_completed_name));
@@ -987,7 +956,7 @@ void game_convert_strings_to_rct2(rct_s6_data * s6)
utf8_to_rct2_self(s6->scenario_description, sizeof(s6->scenario_description)); utf8_to_rct2_self(s6->scenario_description, sizeof(s6->scenario_description));
// User strings // User strings
for (auto * userString : s6->custom_strings) for (auto* userString : s6->custom_strings)
{ {
if (!str_is_null_or_empty(userString)) if (!str_is_null_or_empty(userString))
{ {
@@ -996,7 +965,7 @@ void game_convert_strings_to_rct2(rct_s6_data * s6)
} }
// News items // News items
for (auto &newsItem : s6->news_items) for (auto& newsItem : s6->news_items)
{ {
if (!str_is_null_or_empty(newsItem.Text)) if (!str_is_null_or_empty(newsItem.Text))
{ {
@@ -1010,10 +979,10 @@ void game_convert_strings_to_rct2(rct_s6_data * s6)
void game_fix_save_vars() void game_fix_save_vars()
{ {
// Recalculates peep count after loading a save to fix corrupted files // Recalculates peep count after loading a save to fix corrupted files
rct_peep * peep; rct_peep* peep;
uint16_t spriteIndex; uint16_t spriteIndex;
uint16_t peepCount = 0; uint16_t peepCount = 0;
FOR_ALL_GUESTS(spriteIndex, peep) FOR_ALL_GUESTS (spriteIndex, peep)
{ {
if (!peep->outside_of_park) if (!peep->outside_of_park)
peepCount++; peepCount++;
@@ -1024,10 +993,10 @@ void game_fix_save_vars()
peep_sort(); peep_sort();
// Peeps to remove have to be cached here, as removing them from within the loop breaks iteration // Peeps to remove have to be cached here, as removing them from within the loop breaks iteration
std::vector<rct_peep *> peepsToRemove; std::vector<rct_peep*> peepsToRemove;
// Fix possibly invalid field values // Fix possibly invalid field values
FOR_ALL_GUESTS(spriteIndex, peep) FOR_ALL_GUESTS (spriteIndex, peep)
{ {
if (peep->current_ride_station >= MAX_STATIONS) if (peep->current_ride_station >= MAX_STATIONS)
{ {
@@ -1038,7 +1007,7 @@ void game_fix_save_vars()
continue; continue;
} }
set_format_arg(0, uint32_t, peep->id); set_format_arg(0, uint32_t, peep->id);
utf8 * curName = gCommonStringFormatBuffer; utf8* curName = gCommonStringFormatBuffer;
rct_string_id curId = peep->name_string_idx; rct_string_id curId = peep->name_string_idx;
format_string(curName, 256, curId, gCommonFormatArgs); format_string(curName, 256, curId, gCommonFormatArgs);
log_warning("Peep %u (%s) has invalid ride station = %u for ride %u.", spriteIndex, curName, srcStation, rideIdx); log_warning("Peep %u (%s) has invalid ride station = %u for ride %u.", spriteIndex, curName, srcStation, rideIdx);
@@ -1047,7 +1016,9 @@ void game_fix_save_vars()
{ {
log_warning("Couldn't find station, removing peep %u", spriteIndex); log_warning("Couldn't find station, removing peep %u", spriteIndex);
peepsToRemove.push_back(peep); peepsToRemove.push_back(peep);
} else { }
else
{
log_warning("Amending ride station to %u.", station); log_warning("Amending ride station to %u.", station);
peep->current_ride_station = station; peep->current_ride_station = station;
} }
@@ -1071,7 +1042,7 @@ void game_fix_save_vars()
{ {
for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
{ {
rct_tile_element * tileElement = map_get_surface_element_at(x, y); rct_tile_element* tileElement = map_get_surface_element_at(x, y);
if (tileElement == nullptr) if (tileElement == nullptr)
{ {
@@ -1112,7 +1083,7 @@ void game_fix_save_vars()
void game_load_init() void game_load_init()
{ {
rct_window * mainWindow; rct_window* mainWindow;
gScreenFlags = SCREEN_FLAGS_PLAYING; gScreenFlags = SCREEN_FLAGS_PLAYING;
audio_stop_all_music_and_sounds(); audio_stop_all_music_and_sounds();
@@ -1165,7 +1136,7 @@ void reset_all_sprite_quadrant_placements()
{ {
for (size_t i = 0; i < MAX_SPRITES; i++) for (size_t i = 0; i < MAX_SPRITES; i++)
{ {
rct_sprite * spr = get_sprite(i); rct_sprite* spr = get_sprite(i);
if (spr->unknown.sprite_identifier != SPRITE_IDENTIFIER_NULL) if (spr->unknown.sprite_identifier != SPRITE_IDENTIFIER_NULL)
{ {
sprite_move(spr->unknown.x, spr->unknown.y, spr->unknown.z, spr); sprite_move(spr->unknown.x, spr->unknown.y, spr->unknown.z, spr);
@@ -1194,29 +1165,29 @@ void save_game()
} }
} }
void * create_save_game_as_intent() void* create_save_game_as_intent()
{ {
char name[MAX_PATH]; char name[MAX_PATH];
safe_strcpy(name, path_get_filename(gScenarioSavePath), MAX_PATH); safe_strcpy(name, path_get_filename(gScenarioSavePath), MAX_PATH);
path_remove_extension(name); path_remove_extension(name);
Intent * intent = new Intent(WC_LOADSAVE); Intent* intent = new Intent(WC_LOADSAVE);
intent->putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME); intent->putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME);
intent->putExtra(INTENT_EXTRA_PATH, std::string{name}); intent->putExtra(INTENT_EXTRA_PATH, std::string{ name });
return intent; return intent;
} }
void save_game_as() void save_game_as()
{ {
auto * intent = (Intent *) create_save_game_as_intent(); auto* intent = (Intent*)create_save_game_as_intent();
context_open_intent(intent); context_open_intent(intent);
delete intent; delete intent;
} }
static int32_t compare_autosave_file_paths(const void * a, const void * b) static int32_t compare_autosave_file_paths(const void* a, const void* b)
{ {
return strcmp(*(char **) a, *(char **) b); return strcmp(*(char**)a, *(char**)b);
} }
static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processLandscapeFolder) static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processLandscapeFolder)
@@ -1226,7 +1197,7 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL
utf8 filter[MAX_PATH]; utf8 filter[MAX_PATH];
utf8 ** autosaveFiles = nullptr; utf8** autosaveFiles = nullptr;
if (processLandscapeFolder) if (processLandscapeFolder)
{ {
@@ -1256,13 +1227,13 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL
return; return;
} }
autosaveFiles = (utf8 **) malloc(sizeof(utf8 *) * autosavesCount); autosaveFiles = (utf8**)malloc(sizeof(utf8*) * autosavesCount);
{ {
auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(filter, false)); auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(filter, false));
for (size_t i = 0; i < autosavesCount; i++) for (size_t i = 0; i < autosavesCount; i++)
{ {
autosaveFiles[i] = (utf8 *)malloc(sizeof(utf8) * MAX_PATH); autosaveFiles[i] = (utf8*)malloc(sizeof(utf8) * MAX_PATH);
memset(autosaveFiles[i], 0, sizeof(utf8) * MAX_PATH); memset(autosaveFiles[i], 0, sizeof(utf8) * MAX_PATH);
if (scanner->Next()) if (scanner->Next())
@@ -1281,7 +1252,7 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL
} }
} }
qsort(autosaveFiles, autosavesCount, sizeof(char *), compare_autosave_file_paths); qsort(autosaveFiles, autosavesCount, sizeof(char*), compare_autosave_file_paths);
// Calculate how many saves we need to delete. // Calculate how many saves we need to delete.
numAutosavesToDelete = autosavesCount - numberOfFilesToKeep; numAutosavesToDelete = autosavesCount - numberOfFilesToKeep;
@@ -1291,7 +1262,6 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL
platform_file_delete(autosaveFiles[i]); platform_file_delete(autosaveFiles[i]);
} }
for (size_t i = 0; i < autosavesCount; i++) for (size_t i = 0; i < autosavesCount; i++)
{ {
free(autosaveFiles[i]); free(autosaveFiles[i]);
@@ -1302,8 +1272,8 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL
void game_autosave() void game_autosave()
{ {
const char * subDirectory = "save"; const char* subDirectory = "save";
const char * fileExtension = ".sv6"; const char* fileExtension = ".sv6";
uint32_t saveFlags = 0x80000000; uint32_t saveFlags = 0x80000000;
if (gScreenFlags & SCREEN_FLAGS_EDITOR) if (gScreenFlags & SCREEN_FLAGS_EDITOR)
{ {
@@ -1319,9 +1289,17 @@ void game_autosave()
platform_get_time_local(&currentTime); platform_get_time_local(&currentTime);
utf8 timeName[44]; utf8 timeName[44];
snprintf(timeName, sizeof(timeName), "autosave_%04u-%02u-%02u_%02u-%02u-%02u%s", snprintf(
currentDate.year, currentDate.month, currentDate.day, currentTime.hour, timeName,
currentTime.minute, currentTime.second, fileExtension); sizeof(timeName),
"autosave_%04u-%02u-%02u_%02u-%02u-%02u%s",
currentDate.year,
currentDate.month,
currentDate.day,
currentTime.hour,
currentTime.minute,
currentTime.second,
fileExtension);
limit_autosave_count(NUMBER_OF_AUTOSAVES_TO_KEEP, (gScreenFlags & SCREEN_FLAGS_EDITOR)); limit_autosave_count(NUMBER_OF_AUTOSAVES_TO_KEEP, (gScreenFlags & SCREEN_FLAGS_EDITOR));
@@ -1344,7 +1322,7 @@ void game_autosave()
scenario_save(path, saveFlags); scenario_save(path, saveFlags);
} }
static void game_load_or_quit_no_save_prompt_callback(int32_t result, const utf8 * path) static void game_load_or_quit_no_save_prompt_callback(int32_t result, const utf8* path)
{ {
if (result == MODAL_RESULT_OK) if (result == MODAL_RESULT_OK)
{ {
@@ -1372,7 +1350,7 @@ void game_load_or_quit_no_save_prompt()
{ {
auto intent = Intent(WC_LOADSAVE); auto intent = Intent(WC_LOADSAVE);
intent.putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME); intent.putExtra(INTENT_EXTRA_LOADSAVE_TYPE, LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME);
intent.putExtra(INTENT_EXTRA_CALLBACK, (void *) game_load_or_quit_no_save_prompt_callback); intent.putExtra(INTENT_EXTRA_CALLBACK, (void*)game_load_or_quit_no_save_prompt_callback);
context_open_intent(&intent); context_open_intent(&intent);
} }
break; break;
@@ -1393,7 +1371,7 @@ void game_load_or_quit_no_save_prompt()
} }
} }
GAME_COMMAND_POINTER * new_game_command_table[GAME_COMMAND_COUNT] = { GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = {
game_command_set_ride_appearance, game_command_set_ride_appearance,
game_command_set_land_height, game_command_set_land_height,
game_pause_toggle, game_pause_toggle,

View File

@@ -118,12 +118,14 @@ enum
ERROR_TYPE_FILE_LOAD = 255 ERROR_TYPE_FILE_LOAD = 255
}; };
using GAME_COMMAND_POINTER = void(int32_t * eax, int32_t * ebx, int32_t * ecx, int32_t * edx, int32_t * esi, int32_t * edi, int32_t * ebp); using GAME_COMMAND_POINTER
using GAME_COMMAND_CALLBACK_POINTER = void(int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int32_t esi, int32_t edi, int32_t ebp); = void(int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
using GAME_COMMAND_CALLBACK_POINTER
= void(int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int32_t esi, int32_t edi, int32_t ebp);
extern GAME_COMMAND_CALLBACK_POINTER * game_command_callback; extern GAME_COMMAND_CALLBACK_POINTER* game_command_callback;
int32_t game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER * callback); int32_t game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER* callback);
GAME_COMMAND_CALLBACK_POINTER * game_command_callback_get_callback(uint32_t index); GAME_COMMAND_CALLBACK_POINTER* game_command_callback_get_callback(uint32_t index);
extern int32_t game_command_playerid; extern int32_t game_command_playerid;
extern rct_string_id gGameCommandErrorTitle; extern rct_string_id gGameCommandErrorTitle;
@@ -131,7 +133,7 @@ extern rct_string_id gGameCommandErrorText;
extern uint8_t gErrorType; extern uint8_t gErrorType;
extern rct_string_id gErrorStringId; extern rct_string_id gErrorStringId;
extern GAME_COMMAND_POINTER * new_game_command_table[GAME_COMMAND_COUNT]; extern GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT];
extern uint32_t gCurrentTicks; extern uint32_t gCurrentTicks;
@@ -158,24 +160,25 @@ void reset_all_sprite_quadrant_placements();
void update_palette_effects(); void update_palette_effects();
int32_t game_do_command(int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int32_t esi, int32_t edi, int32_t ebp); int32_t game_do_command(int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int32_t esi, int32_t edi, int32_t ebp);
int32_t game_do_command_p(uint32_t command, int32_t * eax, int32_t * ebx, int32_t * ecx, int32_t * edx, int32_t * esi, int32_t * edi, int32_t * ebp); int32_t game_do_command_p(
uint32_t command, int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
void game_log_multiplayer_command(int command, const int * eax, const int * ebx, const int * ecx, int * edx, int * edi, int * ebp); void game_log_multiplayer_command(int command, const int* eax, const int* ebx, const int* ecx, int* edx, int* edi, int* ebp);
void game_load_or_quit_no_save_prompt(); void game_load_or_quit_no_save_prompt();
void load_from_sv6(const char * path); void load_from_sv6(const char* path);
void game_load_init(); void game_load_init();
void game_pause_toggle(int32_t * eax, int32_t * ebx, int32_t * ecx, int32_t * edx, int32_t * esi, int32_t * edi, int32_t * ebp); void game_pause_toggle(int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
void pause_toggle(); void pause_toggle();
bool game_is_paused(); bool game_is_paused();
bool game_is_not_paused(); bool game_is_not_paused();
void save_game(); void save_game();
void * create_save_game_as_intent(); void* create_save_game_as_intent();
void save_game_as(); void save_game_as();
void game_autosave(); void game_autosave();
void game_convert_strings_to_utf8(); void game_convert_strings_to_utf8();
void game_convert_news_items_to_utf8(); void game_convert_news_items_to_utf8();
void game_convert_strings_to_rct2(rct_s6_data * s6); void game_convert_strings_to_rct2(rct_s6_data* s6);
void utf8_to_rct2_self(char * buffer, size_t length); void utf8_to_rct2_self(char* buffer, size_t length);
void rct2_to_utf8_self(char * buffer, size_t length); void rct2_to_utf8_self(char* buffer, size_t length);
void game_fix_save_vars(); void game_fix_save_vars();

View File

@@ -8,26 +8,27 @@
*****************************************************************************/ *****************************************************************************/
#include "GameState.h" #include "GameState.h"
#include "Context.h" #include "Context.h"
#include "core/Math.hpp"
#include "Editor.h" #include "Editor.h"
#include "Input.h" #include "Input.h"
#include "OpenRCT2.h"
#include "core/Math.hpp"
#include "interface/Screenshot.h" #include "interface/Screenshot.h"
#include "localisation/Date.h" #include "localisation/Date.h"
#include "localisation/Localisation.h" #include "localisation/Localisation.h"
#include "management/NewsItem.h" #include "management/NewsItem.h"
#include "network/network.h" #include "network/network.h"
#include "OpenRCT2.h"
#include "platform/Platform2.h" #include "platform/Platform2.h"
#include "scenario/Scenario.h" #include "scenario/Scenario.h"
#include "title/TitleScreen.h" #include "title/TitleScreen.h"
#include "title/TitleSequencePlayer.h" #include "title/TitleSequencePlayer.h"
#include "ui/UiContext.h"
#include "windows/Intent.h" #include "windows/Intent.h"
#include "world/Climate.h" #include "world/Climate.h"
#include "world/MapAnimation.h" #include "world/MapAnimation.h"
#include "world/Park.h" #include "world/Park.h"
#include "world/Scenery.h" #include "world/Scenery.h"
#include "ui/UiContext.h"
using namespace OpenRCT2; using namespace OpenRCT2;
@@ -99,7 +100,8 @@ void GameState::Update()
numUpdates = Math::Clamp<uint32_t>(1, numUpdates, GAME_MAX_UPDATES); numUpdates = Math::Clamp<uint32_t>(1, numUpdates, GAME_MAX_UPDATES);
} }
if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED && network_get_authstatus() == NETWORK_AUTH_OK) 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) if (network_get_server_tick() - gCurrentTicks >= 10)
{ {
@@ -127,8 +129,7 @@ void GameState::Update()
UpdateLogic(); UpdateLogic();
if (gGameSpeed == 1) if (gGameSpeed == 1)
{ {
if (input_get_state() == INPUT_STATE_RESET || if (input_get_state() == INPUT_STATE_RESET || input_get_state() == INPUT_STATE_NORMAL)
input_get_state() == INPUT_STATE_NORMAL)
{ {
if (input_test_flag(INPUT_FLAG_VIEWPORT_SCROLLING)) if (input_test_flag(INPUT_FLAG_VIEWPORT_SCROLLING))
{ {
@@ -174,9 +175,8 @@ void GameState::Update()
} }
// Always perform autosave check, even when paused // Always perform autosave check, even when paused
if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !(gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
!(gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && && !(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER))
!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER))
{ {
scenario_autosave_check(); scenario_autosave_check();
} }
@@ -195,9 +195,8 @@ void GameState::UpdateLogic()
network_update(); network_update();
if (network_get_mode() == NETWORK_MODE_CLIENT && if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED
network_get_status() == NETWORK_STATUS_CONNECTED && && network_get_authstatus() == NETWORK_AUTH_OK)
network_get_authstatus() == NETWORK_AUTH_OK)
{ {
// Can't be in sync with server, round trips won't work if we are at same level. // Can't be in sync with server, round trips won't work if we are at same level.
if (gCurrentTicks >= network_get_server_tick()) if (gCurrentTicks >= network_get_server_tick())
@@ -250,7 +249,7 @@ void GameState::UpdateLogic()
editor_open_windows_for_current_step(); editor_open_windows_for_current_step();
// Update windows // Update windows
//window_dispatch_update_all(); // window_dispatch_update_all();
if (gErrorType != ERROR_TYPE_NONE) if (gErrorType != ERROR_TYPE_NONE)
{ {

View File

@@ -9,9 +9,10 @@
#pragma once #pragma once
#include <memory>
#include "Date.h" #include "Date.h"
#include <memory>
namespace OpenRCT2 namespace OpenRCT2
{ {
class Park; class Park;
@@ -29,11 +30,17 @@ namespace OpenRCT2
GameState(); GameState();
GameState(const GameState&) = delete; GameState(const GameState&) = delete;
Date& GetDate() { return _date; } Date& GetDate()
Park& GetPark() { return *_park; } {
return _date;
}
Park& GetPark()
{
return *_park;
}
void InitAll(int32_t mapSize); void InitAll(int32_t mapSize);
void Update(); void Update();
void UpdateLogic(); void UpdateLogic();
}; };
} } // namespace OpenRCT2

View File

@@ -7,9 +7,10 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "Context.h"
#include "Input.h" #include "Input.h"
#include "Context.h"
INPUT_STATE _inputState; INPUT_STATE _inputState;
uint8_t _inputFlags; uint8_t _inputFlags;
uint8_t gInputPlaceObjectModifier; uint8_t gInputPlaceObjectModifier;
@@ -42,9 +43,12 @@ void game_handle_keyboard_input()
void input_set_flag(INPUT_FLAGS flag, bool on) void input_set_flag(INPUT_FLAGS flag, bool on)
{ {
if (on) { if (on)
{
_inputFlags |= flag; _inputFlags |= flag;
} else { }
else
{
_inputFlags &= ~flag; _inputFlags &= ~flag;
} }
} }

View File

@@ -12,7 +12,8 @@
#include "interface/Window.h" #include "interface/Window.h"
enum INPUT_FLAGS { enum INPUT_FLAGS
{
INPUT_FLAG_WIDGET_PRESSED = (1 << 0), INPUT_FLAG_WIDGET_PRESSED = (1 << 0),
// The dropdown can stay open if the mouse is released, set on flag DROPDOWN_FLAG_STAY_OPEN // The dropdown can stay open if the mouse is released, set on flag DROPDOWN_FLAG_STAY_OPEN
@@ -36,7 +37,8 @@ enum INPUT_FLAGS {
INPUT_FLAG_VIEWPORT_SCROLLING = (1 << 7) INPUT_FLAG_VIEWPORT_SCROLLING = (1 << 7)
}; };
enum MOUSE_STATE { enum MOUSE_STATE
{
MOUSE_STATE_RELEASED, MOUSE_STATE_RELEASED,
MOUSE_STATE_LEFT_PRESS, MOUSE_STATE_LEFT_PRESS,
MOUSE_STATE_LEFT_RELEASE, MOUSE_STATE_LEFT_RELEASE,
@@ -44,7 +46,8 @@ enum MOUSE_STATE {
MOUSE_STATE_RIGHT_RELEASE MOUSE_STATE_RIGHT_RELEASE
}; };
enum INPUT_STATE { enum INPUT_STATE
{
INPUT_STATE_RESET, INPUT_STATE_RESET,
INPUT_STATE_NORMAL, INPUT_STATE_NORMAL,
INPUT_STATE_WIDGET_PRESSED, INPUT_STATE_WIDGET_PRESSED,
@@ -57,13 +60,15 @@ enum INPUT_STATE {
INPUT_STATE_SCROLL_RIGHT INPUT_STATE_SCROLL_RIGHT
}; };
enum PLACE_OBJECT_MODIFIER { enum PLACE_OBJECT_MODIFIER
{
PLACE_OBJECT_MODIFIER_NONE = 0, PLACE_OBJECT_MODIFIER_NONE = 0,
PLACE_OBJECT_MODIFIER_SHIFT_Z = (1 << 0), PLACE_OBJECT_MODIFIER_SHIFT_Z = (1 << 0),
PLACE_OBJECT_MODIFIER_COPY_Z = (1 << 1), PLACE_OBJECT_MODIFIER_COPY_Z = (1 << 1),
}; };
struct widget_ref { struct widget_ref
{
rct_windowclass window_classification; rct_windowclass window_classification;
rct_windownumber window_number; rct_windownumber window_number;
rct_widgetindex widget_index; rct_widgetindex widget_index;
@@ -90,7 +95,7 @@ extern INPUT_STATE _inputState;
extern uint8_t _inputFlags; extern uint8_t _inputFlags;
extern uint16_t _tooltipNotShownTicks; extern uint16_t _tooltipNotShownTicks;
void input_window_position_begin(rct_window *w, rct_widgetindex widgetIndex, int32_t x, int32_t y); void input_window_position_begin(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y);
void title_handle_keyboard_input(); void title_handle_keyboard_input();
void game_handle_input(); void game_handle_input();

View File

@@ -7,11 +7,12 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "audio/audio.h"
#include "audio/AudioMixer.h"
#include "Context.h"
#include "drawing/Drawing.h"
#include "Intro.h" #include "Intro.h"
#include "Context.h"
#include "audio/AudioMixer.h"
#include "audio/audio.h"
#include "drawing/Drawing.h"
#include "sprites.h" #include "sprites.h"
#define BACKROUND_COLOUR_DARK PALETTE_INDEX_10 #define BACKROUND_COLOUR_DARK PALETTE_INDEX_10
@@ -26,13 +27,13 @@ uint8_t gIntroState;
// Used mainly for timing but also for Y coordinate and fading. // Used mainly for timing but also for Y coordinate and fading.
static int32_t _introStateCounter; static int32_t _introStateCounter;
static void *_soundChannel = nullptr; static void* _soundChannel = nullptr;
static bool _chainLiftFinished; static bool _chainLiftFinished;
static void screen_intro_process_mouse_input(); static void screen_intro_process_mouse_input();
static void screen_intro_process_keyboard_input(); static void screen_intro_process_keyboard_input();
static void screen_intro_skip_part(); static void screen_intro_skip_part();
static void screen_intro_draw_logo(rct_drawpixelinfo *dpi); static void screen_intro_draw_logo(rct_drawpixelinfo* dpi);
// rct2: 0x0068E966 // rct2: 0x0068E966
void intro_update() void intro_update()
@@ -40,7 +41,8 @@ void intro_update()
screen_intro_process_mouse_input(); screen_intro_process_mouse_input();
screen_intro_process_keyboard_input(); screen_intro_process_keyboard_input();
switch (gIntroState) { switch (gIntroState)
{
case INTRO_STATE_DISCLAIMER_1: case INTRO_STATE_DISCLAIMER_1:
case INTRO_STATE_DISCLAIMER_2: case INTRO_STATE_DISCLAIMER_2:
// Originally used for the disclaimer text // Originally used for the disclaimer text
@@ -61,7 +63,8 @@ void intro_update()
_introStateCounter += 5; _introStateCounter += 5;
// Check if logo is off the screen...ish // Check if logo is off the screen...ish
if (_introStateCounter > context_get_height() - 120) { if (_introStateCounter > context_get_height() - 120)
{
_introStateCounter = -116; _introStateCounter = -116;
gIntroState++; gIntroState++;
} }
@@ -77,23 +80,28 @@ void intro_update()
_introStateCounter += 5; _introStateCounter += 5;
// Check if logo is almost scrolled to the bottom // Check if logo is almost scrolled to the bottom
if (!_chainLiftFinished && _introStateCounter >= context_get_height() + 40 - 421) { if (!_chainLiftFinished && _introStateCounter >= context_get_height() + 40 - 421)
{
_chainLiftFinished = true; _chainLiftFinished = true;
// Stop the chain lift sound // Stop the chain lift sound
if (_soundChannel != nullptr) { if (_soundChannel != nullptr)
{
Mixer_Stop_Channel(_soundChannel); Mixer_Stop_Channel(_soundChannel);
_soundChannel = nullptr; _soundChannel = nullptr;
} }
// Play the track friction sound // Play the track friction sound
_soundChannel = Mixer_Play_Effect(SOUND_TRACK_FRICTION_3, MIXER_LOOP_INFINITE, MIXER_VOLUME_MAX, 0.25f, 0.75, true); _soundChannel
= Mixer_Play_Effect(SOUND_TRACK_FRICTION_3, MIXER_LOOP_INFINITE, MIXER_VOLUME_MAX, 0.25f, 0.75, true);
} }
// Check if logo is off the screen...ish // Check if logo is off the screen...ish
if (_introStateCounter >= context_get_height() + 40) { if (_introStateCounter >= context_get_height() + 40)
{
// Stop the track friction sound // Stop the track friction sound
if (_soundChannel != nullptr) { if (_soundChannel != nullptr)
{
Mixer_Stop_Channel(_soundChannel); Mixer_Stop_Channel(_soundChannel);
_soundChannel = nullptr; _soundChannel = nullptr;
} }
@@ -108,7 +116,8 @@ void intro_update()
case INTRO_STATE_LOGO_FADE_IN: case INTRO_STATE_LOGO_FADE_IN:
// Fade in, add 4 / 256 to fading // Fade in, add 4 / 256 to fading
_introStateCounter += 0x400; _introStateCounter += 0x400;
if (_introStateCounter > 0xFF00) { if (_introStateCounter > 0xFF00)
{
gIntroState++; gIntroState++;
_introStateCounter = 0; _introStateCounter = 0;
} }
@@ -116,7 +125,8 @@ void intro_update()
case INTRO_STATE_LOGO_WAIT: case INTRO_STATE_LOGO_WAIT:
// Wait 80 game ticks // Wait 80 game ticks
_introStateCounter++; _introStateCounter++;
if (_introStateCounter >= 80) { if (_introStateCounter >= 80)
{
// Set fading to 256 // Set fading to 256
_introStateCounter = 0xFF00; _introStateCounter = 0xFF00;
@@ -126,13 +136,15 @@ void intro_update()
case INTRO_STATE_LOGO_FADE_OUT: case INTRO_STATE_LOGO_FADE_OUT:
// Fade out, subtract 4 / 256 from fading // Fade out, subtract 4 / 256 from fading
_introStateCounter -= 0x400; _introStateCounter -= 0x400;
if (_introStateCounter < 0) { if (_introStateCounter < 0)
{
gIntroState = INTRO_STATE_CLEAR; gIntroState = INTRO_STATE_CLEAR;
} }
break; break;
case INTRO_STATE_CLEAR: case INTRO_STATE_CLEAR:
// Stop any playing sound // Stop any playing sound
if (_soundChannel != nullptr) { if (_soundChannel != nullptr)
{
Mixer_Stop_Channel(_soundChannel); Mixer_Stop_Channel(_soundChannel);
_soundChannel = nullptr; _soundChannel = nullptr;
} }
@@ -149,11 +161,12 @@ void intro_update()
} }
} }
void intro_draw(rct_drawpixelinfo *dpi) void intro_draw(rct_drawpixelinfo* dpi)
{ {
int32_t screenWidth = context_get_width(); int32_t screenWidth = context_get_width();
switch (gIntroState) { switch (gIntroState)
{
case INTRO_STATE_DISCLAIMER_1: case INTRO_STATE_DISCLAIMER_1:
case INTRO_STATE_DISCLAIMER_2: case INTRO_STATE_DISCLAIMER_2:
break; break;
@@ -164,9 +177,12 @@ void intro_draw(rct_drawpixelinfo *dpi)
gfx_clear(dpi, BACKROUND_COLOUR_DARK); gfx_clear(dpi, BACKROUND_COLOUR_DARK);
// Draw a white rectangle for the logo background (gives a bit of white margin) // Draw a white rectangle for the logo background (gives a bit of white margin)
gfx_fill_rect(dpi, gfx_fill_rect(
(screenWidth / 2) - 320 + 50, _introStateCounter + 50, dpi,
(screenWidth / 2) - 320 + 50 + 540, _introStateCounter + 50 + 425, (screenWidth / 2) - 320 + 50,
_introStateCounter + 50,
(screenWidth / 2) - 320 + 50 + 540,
_introStateCounter + 50 + 425,
BORDER_COLOUR_PUBLISHER); BORDER_COLOUR_PUBLISHER);
// Draw Infogrames logo // Draw Infogrames logo
@@ -187,9 +203,12 @@ void intro_draw(rct_drawpixelinfo *dpi)
gfx_draw_sprite(dpi, SPR_INTRO_CHRIS_SAWYER_10, (screenWidth / 2) - 320 + 320, _introStateCounter, 0); gfx_draw_sprite(dpi, SPR_INTRO_CHRIS_SAWYER_10, (screenWidth / 2) - 320 + 320, _introStateCounter, 0);
break; break;
case INTRO_STATE_LOGO_FADE_IN: case INTRO_STATE_LOGO_FADE_IN:
if (_introStateCounter <= 0xFF00) { if (_introStateCounter <= 0xFF00)
{
gfx_transpose_palette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF); gfx_transpose_palette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF);
} else { }
else
{
gfx_transpose_palette(PALETTE_G1_IDX_LOGO, 255); gfx_transpose_palette(PALETTE_G1_IDX_LOGO, 255);
} }
screen_intro_draw_logo(dpi); screen_intro_draw_logo(dpi);
@@ -198,9 +217,12 @@ void intro_draw(rct_drawpixelinfo *dpi)
screen_intro_draw_logo(dpi); screen_intro_draw_logo(dpi);
break; break;
case INTRO_STATE_LOGO_FADE_OUT: case INTRO_STATE_LOGO_FADE_OUT:
if (_introStateCounter >= 0) { if (_introStateCounter >= 0)
{
gfx_transpose_palette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF); gfx_transpose_palette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF);
} else { }
else
{
gfx_transpose_palette(PALETTE_G1_IDX_LOGO, 0); gfx_transpose_palette(PALETTE_G1_IDX_LOGO, 0);
} }
screen_intro_draw_logo(dpi); screen_intro_draw_logo(dpi);
@@ -213,7 +235,8 @@ void intro_draw(rct_drawpixelinfo *dpi)
static void screen_intro_process_mouse_input() static void screen_intro_process_mouse_input()
{ {
if (context_get_cursor_state()->any == CURSOR_PRESSED) { if (context_get_cursor_state()->any == CURSOR_PRESSED)
{
screen_intro_skip_part(); screen_intro_skip_part();
} }
} }
@@ -224,9 +247,11 @@ static void screen_intro_process_mouse_input()
*/ */
static void screen_intro_process_keyboard_input() static void screen_intro_process_keyboard_input()
{ {
const uint8_t * keys = context_get_keys_state(); const uint8_t* keys = context_get_keys_state();
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++)
if (keys[i] != 0) { {
if (keys[i] != 0)
{
screen_intro_skip_part(); screen_intro_skip_part();
break; break;
} }
@@ -235,7 +260,8 @@ static void screen_intro_process_keyboard_input()
static void screen_intro_skip_part() static void screen_intro_skip_part()
{ {
switch (gIntroState) { switch (gIntroState)
{
case INTRO_STATE_NONE: case INTRO_STATE_NONE:
break; break;
case INTRO_STATE_DISCLAIMER_2: case INTRO_STATE_DISCLAIMER_2:
@@ -247,7 +273,7 @@ static void screen_intro_skip_part()
} }
} }
static void screen_intro_draw_logo(rct_drawpixelinfo *dpi) static void screen_intro_draw_logo(rct_drawpixelinfo* dpi)
{ {
int32_t screenWidth = context_get_width(); int32_t screenWidth = context_get_width();
int32_t imageWidth = 640; int32_t imageWidth = 640;

View File

@@ -14,7 +14,8 @@
struct rct_drawpixelinfo; struct rct_drawpixelinfo;
enum INTRO_STATE { enum INTRO_STATE
{
INTRO_STATE_NONE, INTRO_STATE_NONE,
INTRO_STATE_PUBLISHER_BEGIN, INTRO_STATE_PUBLISHER_BEGIN,
INTRO_STATE_PUBLISHER_SCROLL, INTRO_STATE_PUBLISHER_SCROLL,
@@ -32,6 +33,6 @@ enum INTRO_STATE {
extern uint8_t gIntroState; extern uint8_t gIntroState;
void intro_update(); void intro_update();
void intro_draw(rct_drawpixelinfo *dpi); void intro_draw(rct_drawpixelinfo* dpi);
#endif #endif

View File

@@ -59,8 +59,7 @@ extern uint8_t gScreenFlags;
extern uint32_t gScreenAge; extern uint32_t gScreenAge;
extern uint8_t gSavePromptMode; extern uint8_t gSavePromptMode;
void openrct2_write_full_version_info(utf8 * buffer, size_t bufferSize); void openrct2_write_full_version_info(utf8* buffer, size_t bufferSize);
void openrct2_finish(); void openrct2_finish();
int32_t cmdline_run(const char * * argv, int32_t argc); int32_t cmdline_run(const char** argv, int32_t argc);

View File

@@ -7,17 +7,19 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include <memory> #include "ParkImporter.h"
#include "Context.h" #include "Context.h"
#include "core/Path.hpp" #include "core/Path.hpp"
#include "core/String.hpp" #include "core/String.hpp"
#include "object/ObjectManager.h" #include "object/ObjectManager.h"
#include "object/ObjectRepository.h" #include "object/ObjectRepository.h"
#include "ParkImporter.h"
#include <memory>
namespace ParkImporter namespace ParkImporter
{ {
std::unique_ptr<IParkImporter> Create(const std::string &hintPath) std::unique_ptr<IParkImporter> Create(const std::string& hintPath)
{ {
std::unique_ptr<IParkImporter> parkImporter; std::unique_ptr<IParkImporter> parkImporter;
std::string extension = Path::GetExtension(hintPath); std::string extension = Path::GetExtension(hintPath);
@@ -33,15 +35,13 @@ namespace ParkImporter
return parkImporter; return parkImporter;
} }
bool ExtensionIsRCT1(const std::string &extension) bool ExtensionIsRCT1(const std::string& extension)
{ {
return String::Equals(extension, ".sc4", true) || return String::Equals(extension, ".sc4", true) || String::Equals(extension, ".sv4", true);
String::Equals(extension, ".sv4", true);
} }
bool ExtensionIsScenario(const std::string &extension) bool ExtensionIsScenario(const std::string& extension)
{ {
return String::Equals(extension, ".sc4", true) || return String::Equals(extension, ".sc4", true) || String::Equals(extension, ".sc6", true);
String::Equals(extension, ".sc6", true);
} }
} } // namespace ParkImporter

View File

@@ -10,7 +10,6 @@
#pragma once #pragma once
#include "common.h" #include "common.h"
#include "object/Object.h" #include "object/Object.h"
enum PARK_LOAD_ERROR enum PARK_LOAD_ERROR
@@ -22,10 +21,11 @@ enum PARK_LOAD_ERROR
PARK_LOAD_ERROR_UNKNOWN = 255 PARK_LOAD_ERROR_UNKNOWN = 255
}; };
#include "core/String.hpp"
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "core/String.hpp"
interface IObjectManager; interface IObjectManager;
interface IObjectRepository; interface IObjectRepository;
@@ -51,13 +51,11 @@ interface IParkImporter
public: public:
virtual ~IParkImporter() = default; virtual ~IParkImporter() = default;
virtual ParkLoadResult Load(const utf8 * path) abstract; virtual ParkLoadResult Load(const utf8* path) abstract;
virtual ParkLoadResult LoadSavedGame(const utf8 * path, bool skipObjectCheck = false) abstract; virtual ParkLoadResult LoadSavedGame(const utf8* path, bool skipObjectCheck = false) abstract;
virtual ParkLoadResult LoadScenario(const utf8 * path, bool skipObjectCheck = false) abstract; virtual ParkLoadResult LoadScenario(const utf8* path, bool skipObjectCheck = false) abstract;
virtual ParkLoadResult LoadFromStream(IStream * stream, virtual ParkLoadResult LoadFromStream(
bool isScenario, IStream * stream, bool isScenario, bool skipObjectCheck = false, const utf8* path = String::Empty) abstract;
bool skipObjectCheck = false,
const utf8 * path = String::Empty) abstract;
virtual void Import() abstract; virtual void Import() abstract;
virtual bool GetDetails(scenario_index_entry * dst) abstract; virtual bool GetDetails(scenario_index_entry * dst) abstract;
@@ -65,13 +63,14 @@ public:
namespace ParkImporter namespace ParkImporter
{ {
std::unique_ptr<IParkImporter> Create(const std::string &hintPath); std::unique_ptr<IParkImporter> Create(const std::string& hintPath);
std::unique_ptr<IParkImporter> CreateS4(); std::unique_ptr<IParkImporter> CreateS4();
std::unique_ptr<IParkImporter> CreateS6(std::shared_ptr<IObjectRepository> objectRepository, std::shared_ptr<IObjectManager> objectManager); std::unique_ptr<IParkImporter>
CreateS6(std::shared_ptr<IObjectRepository> objectRepository, std::shared_ptr<IObjectManager> objectManager);
bool ExtensionIsRCT1(const std::string &extension); bool ExtensionIsRCT1(const std::string& extension);
bool ExtensionIsScenario(const std::string &extension); bool ExtensionIsScenario(const std::string& extension);
} } // namespace ParkImporter
class ObjectLoadException : public std::exception class ObjectLoadException : public std::exception
{ {

View File

@@ -7,13 +7,14 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include "PlatformEnvironment.h"
#include "OpenRCT2.h"
#include "config/Config.h" #include "config/Config.h"
#include "core/Path.hpp" #include "core/Path.hpp"
#include "core/String.hpp" #include "core/String.hpp"
#include "OpenRCT2.h"
#include "platform/platform.h"
#include "platform/Platform2.h" #include "platform/Platform2.h"
#include "PlatformEnvironment.h" #include "platform/platform.h"
using namespace OpenRCT2; using namespace OpenRCT2;
@@ -39,8 +40,9 @@ public:
std::string GetDirectoryPath(DIRBASE base, DIRID did) const override std::string GetDirectoryPath(DIRBASE base, DIRID did) const override
{ {
auto basePath = GetDirectoryPath(base); auto basePath = GetDirectoryPath(base);
const utf8 * directoryName; const utf8* directoryName;
switch (base) { switch (base)
{
default: default:
case DIRBASE::RCT1: case DIRBASE::RCT1:
case DIRBASE::RCT2: case DIRBASE::RCT2:
@@ -64,15 +66,15 @@ public:
return Path::Combine(basePath, fileName); return Path::Combine(basePath, fileName);
} }
void SetBasePath(DIRBASE base, const std::string &path) override void SetBasePath(DIRBASE base, const std::string& path) override
{ {
_basePath[(size_t)base] = path; _basePath[(size_t)base] = path;
} }
private: private:
static const char * DirectoryNamesRCT2[]; static const char* DirectoryNamesRCT2[];
static const char * DirectoryNamesOpenRCT2[]; static const char* DirectoryNamesOpenRCT2[];
static const char * FileNames[]; static const char* FileNames[];
static DIRBASE GetDefaultBaseDirectory(PATHID pathid) static DIRBASE GetDefaultBaseDirectory(PATHID pathid)
{ {

View File

@@ -9,9 +9,10 @@
#pragma once #pragma once
#include "common.h"
#include <memory> #include <memory>
#include <string> #include <string>
#include "common.h"
namespace OpenRCT2 namespace OpenRCT2
{ {
@@ -73,7 +74,7 @@ namespace OpenRCT2
virtual std::string GetDirectoryPath(DIRBASE base) const abstract; virtual std::string GetDirectoryPath(DIRBASE base) const abstract;
virtual std::string GetDirectoryPath(DIRBASE base, DIRID did) const abstract; virtual std::string GetDirectoryPath(DIRBASE base, DIRID did) const abstract;
virtual std::string GetFilePath(PATHID pathid) const abstract; virtual std::string GetFilePath(PATHID pathid) const abstract;
virtual void SetBasePath(DIRBASE base, const std::string &path) abstract; virtual void SetBasePath(DIRBASE base, const std::string& path) abstract;
}; };
std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment(DIRBASE_VALUES basePaths); std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment(DIRBASE_VALUES basePaths);

View File

@@ -7,15 +7,15 @@
* OpenRCT2 is licensed under the GNU General Public License version 3. * OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/ *****************************************************************************/
#include <string>
#include "Version.h" #include "Version.h"
#include <string>
#ifdef OPENRCT2_BUILD_INFO_HEADER #ifdef OPENRCT2_BUILD_INFO_HEADER
#include OPENRCT2_BUILD_INFO_HEADER #include OPENRCT2_BUILD_INFO_HEADER
#endif #endif
const char gVersionInfoFull[] = const char gVersionInfoFull[] = OPENRCT2_NAME ", "
OPENRCT2_NAME ", "
#ifdef OPENRCT2_VERSION_TAG #ifdef OPENRCT2_VERSION_TAG
OPENRCT2_VERSION_TAG OPENRCT2_VERSION_TAG
#else #else

View File

@@ -15,56 +15,56 @@
#define OPENRCT2_VERSION "0.2.0" #define OPENRCT2_VERSION "0.2.0"
#if defined(__amd64__) || defined(_M_AMD64) #if defined(__amd64__) || defined(_M_AMD64)
#define OPENRCT2_ARCHITECTURE "x86-64" #define OPENRCT2_ARCHITECTURE "x86-64"
#elif defined(__i386__) || defined(_M_IX86) #elif defined(__i386__) || defined(_M_IX86)
#define OPENRCT2_ARCHITECTURE "x86" #define OPENRCT2_ARCHITECTURE "x86"
#elif defined(__aarch64__) #elif defined(__aarch64__)
#define OPENRCT2_ARCHITECTURE "AArch64" #define OPENRCT2_ARCHITECTURE "AArch64"
#elif defined(__arm__) || defined(_M_ARM) #elif defined(__arm__) || defined(_M_ARM)
#if defined(__ARM_ARCH_7A__) #if defined(__ARM_ARCH_7A__)
#define OPENRCT2_ARCHITECTURE "arm-v7a" #define OPENRCT2_ARCHITECTURE "arm-v7a"
#else #else
#define OPENRCT2_ARCHITECTURE "arm" #define OPENRCT2_ARCHITECTURE "arm"
#endif #endif
#elif defined(__powerpc__) || defined(_M_PPC) #elif defined(__powerpc__) || defined(_M_PPC)
#define OPENRCT2_ARCHITECTURE "PowerPC" #define OPENRCT2_ARCHITECTURE "PowerPC"
#elif defined(__mips64) #elif defined(__mips64)
#define OPENRCT2_ARCHITECTURE "mips64" #define OPENRCT2_ARCHITECTURE "mips64"
#elif defined(__mips__) #elif defined(__mips__)
#define OPENRCT2_ARCHITECTURE "mips" #define OPENRCT2_ARCHITECTURE "mips"
#endif #endif
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#define OPENRCT2_ARCHITECTURE "Emscripten" #define OPENRCT2_ARCHITECTURE "Emscripten"
#endif #endif
#ifndef OPENRCT2_ARCHITECTURE #ifndef OPENRCT2_ARCHITECTURE
#error "OPENRCT2_ARCHITECTURE is undefined. Please add identification." #error "OPENRCT2_ARCHITECTURE is undefined. Please add identification."
#endif #endif
// Platform // Platform
#ifdef _WIN32 #ifdef _WIN32
#define OPENRCT2_PLATFORM "Windows" #define OPENRCT2_PLATFORM "Windows"
#endif #endif
#if defined(__linux__) && !defined(__ANDROID__) #if defined(__linux__) && !defined(__ANDROID__)
#define OPENRCT2_PLATFORM "Linux" #define OPENRCT2_PLATFORM "Linux"
#endif #endif
#if (defined(__APPLE__) && defined(__MACH__)) #if (defined(__APPLE__) && defined(__MACH__))
#define OPENRCT2_PLATFORM "macOS" #define OPENRCT2_PLATFORM "macOS"
#endif #endif
#ifdef __FreeBSD__ #ifdef __FreeBSD__
#define OPENRCT2_PLATFORM "FreeBSD" #define OPENRCT2_PLATFORM "FreeBSD"
#endif #endif
#ifdef __ANDROID__ #ifdef __ANDROID__
#define OPENRCT2_PLATFORM "Android" #define OPENRCT2_PLATFORM "Android"
#endif #endif
#ifdef __OpenBSD__ #ifdef __OpenBSD__
#define OPENRCT2_PLATFORM "OpenBSD" #define OPENRCT2_PLATFORM "OpenBSD"
#endif #endif
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#define OPENRCT2_PLATFORM "Emscripten" #define OPENRCT2_PLATFORM "Emscripten"
#endif #endif
#ifndef OPENRCT2_PLATFORM #ifndef OPENRCT2_PLATFORM
#error Unknown platform! #error Unknown platform!
#endif #endif
#ifndef OPENRCT2_CUSTOM_INFO #ifndef OPENRCT2_CUSTOM_INFO

View File

@@ -19,14 +19,14 @@
#include <ctime> #include <ctime>
#endif #endif
#include "Diagnostic.h"
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
#include "Diagnostic.h"
using utf8 = char; using utf8 = char;
using utf8string = utf8 *; using utf8string = utf8*;
using const_utf8string = const utf8 *; using const_utf8string = const utf8*;
#ifdef _WIN32 #ifdef _WIN32
using utf16 = wchar_t; using utf16 = wchar_t;
using utf16string = utf16*; using utf16string = utf16*;
@@ -51,10 +51,10 @@ using colour_t = uint8_t;
#define ror64(x, shift) (((uint64_t)(x) >> (shift)) | ((uint64_t)(x) << (64 - (shift)))) #define ror64(x, shift) (((uint64_t)(x) >> (shift)) | ((uint64_t)(x) << (64 - (shift))))
// Rounds an integer down to the given power of 2. y must be a power of 2. // Rounds an integer down to the given power of 2. y must be a power of 2.
#define floor2(x, y) ((x) & (~((y) - 1))) #define floor2(x, y) ((x) & (~((y)-1)))
// Rounds an integer up to the given power of 2. y must be a power of 2. // Rounds an integer up to the given power of 2. y must be a power of 2.
#define ceil2(x, y) (((x) + (y) - 1) & (~((y) - 1))) #define ceil2(x, y) (((x) + (y)-1) & (~((y)-1)))
// Gets the name of a symbol as a C string // Gets the name of a symbol as a C string
#define nameof(symbol) #symbol #define nameof(symbol) #symbol
@@ -70,7 +70,7 @@ using colour_t = uint8_t;
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define RCT2_ENDIANESS __ORDER_LITTLE_ENDIAN__ #define RCT2_ENDIANESS __ORDER_LITTLE_ENDIAN__
#define LOBYTE(w) ((uint8_t)(w)) #define LOBYTE(w) ((uint8_t)(w))
#define HIBYTE(w) ((uint8_t)(((uint16_t)(w)>>8)&0xFF)) #define HIBYTE(w) ((uint8_t)(((uint16_t)(w) >> 8) & 0xFF))
#endif // __BYTE_ORDER__ #endif // __BYTE_ORDER__
#ifndef RCT2_ENDIANESS #ifndef RCT2_ENDIANESS
@@ -79,8 +79,10 @@ using colour_t = uint8_t;
#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#if !((defined (_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || (defined(__APPLE__) && defined(__MACH__)) || defined(__ANDROID_API__) || defined(__FreeBSD__)) #if !( \
char *strndup(const char *src, size_t size); (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) \
|| (defined(__APPLE__) && defined(__MACH__)) || defined(__ANDROID_API__) || defined(__FreeBSD__))
char* strndup(const char* src, size_t size);
#endif // !(POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) #endif // !(POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
// BSD and macOS have MAP_ANON instead of MAP_ANONYMOUS // BSD and macOS have MAP_ANON instead of MAP_ANONYMOUS
@@ -117,10 +119,10 @@ using money64 = fixed64_1dp;
#define FIXED_2DP(whole, fraction) FIXED_XDP(10, whole, fraction) #define FIXED_2DP(whole, fraction) FIXED_XDP(10, whole, fraction)
// Construct a money value in the format MONEY(10,70) to represent 10.70. Fractional part must be two digits. // Construct a money value in the format MONEY(10,70) to represent 10.70. Fractional part must be two digits.
#define MONEY(whole, fraction) ((whole) * 10 + ((fraction) / 10)) #define MONEY(whole, fraction) ((whole)*10 + ((fraction) / 10))
#define MONEY_FREE MONEY(0,00) #define MONEY_FREE MONEY(0, 00)
#define MONEY16_UNDEFINED (money16)(uint16_t)0xFFFF #define MONEY16_UNDEFINED (money16)(uint16_t) 0xFFFF
#define MONEY32_UNDEFINED ((money32)0x80000000) #define MONEY32_UNDEFINED ((money32)0x80000000)
using BannerIndex = uint8_t; using BannerIndex = uint8_t;
@@ -128,20 +130,35 @@ using BannerIndex = uint8_t;
using EMPTY_ARGS_VOID_POINTER = void(); using EMPTY_ARGS_VOID_POINTER = void();
using rct_string_id = uint16_t; using rct_string_id = uint16_t;
#define SafeFree(x) do { free(x); (x) = nullptr; } while (false) #define SafeFree(x) \
do \
{ \
free(x); \
(x) = nullptr; \
} while (false)
#define SafeDelete(x) do { delete (x); (x) = nullptr; } while (false) #define SafeDelete(x) \
#define SafeDeleteArray(x) do { delete[] (x); (x) = nullptr; } while (false) do \
{ \
delete (x); \
(x) = nullptr; \
} while (false)
#define SafeDeleteArray(x) \
do \
{ \
delete[](x); \
(x) = nullptr; \
} while (false)
#ifndef interface #ifndef interface
#define interface struct #define interface struct
#endif #endif
#define abstract = 0 #define abstract = 0
#if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) #if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
#define OPENRCT2_X86 #define OPENRCT2_X86
#elif defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_X64) || defined(_M_IX86)) // VS2008 #elif defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_X64) || defined(_M_IX86)) // VS2008
#define OPENRCT2_X86 #define OPENRCT2_X86
#endif #endif
#if defined(__i386__) || defined(_M_IX86) #if defined(__i386__) || defined(_M_IX86)
@@ -149,9 +166,9 @@ using rct_string_id = uint16_t;
#endif #endif
#if defined(__LP64__) || defined(_WIN64) #if defined(__LP64__) || defined(_WIN64)
#define PLATFORM_64BIT #define PLATFORM_64BIT
#else #else
#define PLATFORM_32BIT #define PLATFORM_32BIT
#endif #endif
// C99's restrict keywords guarantees the pointer in question, for the whole of its lifetime, // C99's restrict keywords guarantees the pointer in question, for the whole of its lifetime,
@@ -159,74 +176,86 @@ using rct_string_id = uint16_t;
// aliasing the same memory area. Using it lets compiler generate better code. If your compiler // aliasing the same memory area. Using it lets compiler generate better code. If your compiler
// does not support it, feel free to drop it, at some performance hit. // does not support it, feel free to drop it, at some performance hit.
#ifdef _MSC_VER #ifdef _MSC_VER
#define RESTRICT __restrict #define RESTRICT __restrict
#else #else
#define RESTRICT __restrict__ #define RESTRICT __restrict__
#endif #endif
#define assert_struct_size(x, y) static_assert(sizeof(x) == (y), "Improper struct size") #define assert_struct_size(x, y) static_assert(sizeof(x) == (y), "Improper struct size")
#ifdef PLATFORM_X86 #ifdef PLATFORM_X86
#ifndef FASTCALL #ifndef FASTCALL
#ifdef __GNUC__ #ifdef __GNUC__
#define FASTCALL __attribute__((fastcall)) #define FASTCALL __attribute__((fastcall))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define FASTCALL __fastcall #define FASTCALL __fastcall
#else #else
#pragma message "Not using fastcall calling convention, please check your compiler support" #pragma message "Not using fastcall calling convention, please check your compiler support"
#define FASTCALL #define FASTCALL
#endif #endif
#endif // FASTCALL #endif // FASTCALL
#else // PLATFORM_X86 #else // PLATFORM_X86
#define FASTCALL #define FASTCALL
#endif // PLATFORM_X86 #endif // PLATFORM_X86
/** /**
* x86 register structure, only used for easy interop to RCT2 code. * x86 register structure, only used for easy interop to RCT2 code.
*/ */
#pragma pack(push, 1) #pragma pack(push, 1)
struct registers { struct registers
union { {
union
{
int32_t eax; int32_t eax;
int16_t ax; int16_t ax;
struct { struct
{
char al; char al;
char ah; char ah;
}; };
}; };
union { union
{
int32_t ebx; int32_t ebx;
int16_t bx; int16_t bx;
struct { struct
{
char bl; char bl;
char bh; char bh;
}; };
}; };
union { union
{
int32_t ecx; int32_t ecx;
int16_t cx; int16_t cx;
struct { struct
{
char cl; char cl;
char ch; char ch;
}; };
}; };
union { union
{
int32_t edx; int32_t edx;
int16_t dx; int16_t dx;
struct { struct
{
char dl; char dl;
char dh; char dh;
}; };
}; };
union { union
{
int32_t esi; int32_t esi;
int16_t si; int16_t si;
}; };
union { union
{
int32_t edi; int32_t edi;
int16_t di; int16_t di;
}; };
union { union
{
int32_t ebp; int32_t ebp;
int16_t bp; int16_t bp;
}; };

View File

@@ -12,7 +12,8 @@
#include "rct1/RCT1.h" #include "rct1/RCT1.h"
enum { enum
{
SPR_NONE = -1, SPR_NONE = -1,
// Used for on-demand drawing of dynamic memory // Used for on-demand drawing of dynamic memory
@@ -313,7 +314,6 @@ enum {
SPR_TAB_GUEST_INVENTORY = 5326, SPR_TAB_GUEST_INVENTORY = 5326,
SPR_TAB_FINANCES_RESEARCH_0 = 5327, SPR_TAB_FINANCES_RESEARCH_0 = 5327,
SPR_TAB_MUSIC_0 = 5335, SPR_TAB_MUSIC_0 = 5335,
SPR_TAB_SHOPS_AND_STALLS_0 = 5351, SPR_TAB_SHOPS_AND_STALLS_0 = 5351,