From ddb557a0fe130b4a2d2c3eef5a226df5709cdab7 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Fri, 1 Sep 2017 13:38:21 +0200 Subject: [PATCH] Fix TD4 vehicle colour import, move track_design to C++ --- OpenRCT2.xcodeproj/project.pbxproj | 12 +- src/openrct2/game.c | 2 +- src/openrct2/interface/window.h | 2 +- .../ride/{track_design.c => TrackDesign.cpp} | 1574 +++++++++++------ .../ride/{track_design.h => TrackDesign.h} | 2 +- src/openrct2/ride/TrackDesignRepository.cpp | 2 +- src/openrct2/ride/track_design_save.c | 2 +- src/openrct2/world/SmallScenery.cpp | 2 +- 8 files changed, 1003 insertions(+), 595 deletions(-) rename src/openrct2/ride/{track_design.c => TrackDesign.cpp} (55%) rename src/openrct2/ride/{track_design.h => TrackDesign.h} (99%) diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index 927a021ff1..523ba6ca5c 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 4C4C1E981F58226500560300 /* TrackDesign.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C4C1E971F58226500560300 /* TrackDesign.cpp */; }; 4C8667821EEFDCDF0024AAB8 /* RideGroupManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C8667801EEFDCDF0024AAB8 /* RideGroupManager.cpp */; }; 4C8B42701EEB1ABD00F015CA /* X8DrawingEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C8B426E1EEB1ABD00F015CA /* X8DrawingEngine.cpp */; }; 4C8B42721EEB1AE400F015CA /* HardwareDisplayDrawingEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C8B42711EEB1AE400F015CA /* HardwareDisplayDrawingEngine.cpp */; }; @@ -369,7 +370,6 @@ F76C87121EC4E88400FA49E2 /* track.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84D21EC4E7CC00FA49E2 /* track.c */; }; F76C87141EC4E88400FA49E2 /* track_data.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84D41EC4E7CC00FA49E2 /* track_data.c */; }; F76C87161EC4E88400FA49E2 /* track_data_old.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84D61EC4E7CC00FA49E2 /* track_data_old.c */; }; - F76C87171EC4E88400FA49E2 /* track_design.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84D71EC4E7CC00FA49E2 /* track_design.c */; }; F76C87191EC4E88400FA49E2 /* track_design_save.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84D91EC4E7CD00FA49E2 /* track_design_save.c */; }; F76C871A1EC4E88400FA49E2 /* track_paint.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84DA1EC4E7CD00FA49E2 /* track_paint.c */; }; F76C871C1EC4E88400FA49E2 /* TrackDesignRepository.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F76C84DC1EC4E7CD00FA49E2 /* TrackDesignRepository.cpp */; }; @@ -590,6 +590,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 4C4C1E971F58226500560300 /* TrackDesign.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrackDesign.cpp; sourceTree = ""; }; + 4C4C1E991F5832AA00560300 /* TrackDesign.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrackDesign.h; sourceTree = ""; }; 4C8667801EEFDCDF0024AAB8 /* RideGroupManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RideGroupManager.cpp; sourceTree = ""; }; 4C8667811EEFDCDF0024AAB8 /* RideGroupManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RideGroupManager.h; sourceTree = ""; }; 4C8B426E1EEB1ABD00F015CA /* X8DrawingEngine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = X8DrawingEngine.cpp; sourceTree = ""; }; @@ -1246,8 +1248,6 @@ F76C84D41EC4E7CC00FA49E2 /* track_data.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = track_data.c; sourceTree = ""; }; F76C84D51EC4E7CC00FA49E2 /* track_data.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = track_data.h; sourceTree = ""; }; F76C84D61EC4E7CC00FA49E2 /* track_data_old.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = track_data_old.c; sourceTree = ""; }; - F76C84D71EC4E7CC00FA49E2 /* track_design.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = track_design.c; sourceTree = ""; }; - F76C84D81EC4E7CC00FA49E2 /* track_design.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = track_design.h; sourceTree = ""; }; F76C84D91EC4E7CD00FA49E2 /* track_design_save.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = track_design_save.c; sourceTree = ""; }; F76C84DA1EC4E7CD00FA49E2 /* track_paint.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = track_paint.c; sourceTree = ""; }; F76C84DB1EC4E7CD00FA49E2 /* track_paint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = track_paint.h; sourceTree = ""; }; @@ -2230,11 +2230,11 @@ F76C84D41EC4E7CC00FA49E2 /* track_data.c */, F76C84D51EC4E7CC00FA49E2 /* track_data.h */, F76C84D61EC4E7CC00FA49E2 /* track_data_old.c */, - F76C84D71EC4E7CC00FA49E2 /* track_design.c */, - F76C84D81EC4E7CC00FA49E2 /* track_design.h */, F76C84D91EC4E7CD00FA49E2 /* track_design_save.c */, F76C84DA1EC4E7CD00FA49E2 /* track_paint.c */, F76C84DB1EC4E7CD00FA49E2 /* track_paint.h */, + 4C4C1E971F58226500560300 /* TrackDesign.cpp */, + 4C4C1E991F5832AA00560300 /* TrackDesign.h */, F76C84DC1EC4E7CD00FA49E2 /* TrackDesignRepository.cpp */, F76C84DD1EC4E7CD00FA49E2 /* TrackDesignRepository.h */, F76C84E41EC4E7CD00FA49E2 /* vehicle.c */, @@ -3029,6 +3029,7 @@ F76C887A1EC5324E00FA49E2 /* AudioMixer.cpp in Sources */, F76C887B1EC5324E00FA49E2 /* FileAudioSource.cpp in Sources */, C64644FD1F3FA4120026AC2D /* Land.cpp in Sources */, + 4C4C1E981F58226500560300 /* TrackDesign.cpp in Sources */, C666EE6B1F37ACB10061AA04 /* About.cpp in Sources */, C666ED771F33DBB20061AA04 /* ShortcutKeys.cpp in Sources */, C666EE6C1F37ACB10061AA04 /* Changelog.cpp in Sources */, @@ -3345,7 +3346,6 @@ F76C87141EC4E88400FA49E2 /* track_data.c in Sources */, C666EE511F33E3800061AA04 /* TrackPlace.cpp in Sources */, F76C87161EC4E88400FA49E2 /* track_data_old.c in Sources */, - F76C87171EC4E88400FA49E2 /* track_design.c in Sources */, F76C87191EC4E88400FA49E2 /* track_design_save.c in Sources */, F76C871A1EC4E88400FA49E2 /* track_paint.c in Sources */, F76C871C1EC4E88400FA49E2 /* TrackDesignRepository.cpp in Sources */, diff --git a/src/openrct2/game.c b/src/openrct2/game.c index 4627fc7ab5..0b4e9f0315 100644 --- a/src/openrct2/game.c +++ b/src/openrct2/game.c @@ -42,7 +42,7 @@ #include "ride/ride.h" #include "ride/ride_ratings.h" #include "ride/track.h" -#include "ride/track_design.h" +#include "ride/TrackDesign.h" #include "ride/vehicle.h" #include "scenario/scenario.h" #include "title/TitleScreen.h" diff --git a/src/openrct2/interface/window.h b/src/openrct2/interface/window.h index 774a978762..3861184959 100644 --- a/src/openrct2/interface/window.h +++ b/src/openrct2/interface/window.h @@ -22,7 +22,7 @@ #include "../management/research.h" #include "../peep/peep.h" #include "../ride/ride.h" -#include "../ride/track_design.h" +#include "../ride/TrackDesign.h" #include "../ride/vehicle.h" #include "../scenario/scenario.h" #include "../world/park.h" diff --git a/src/openrct2/ride/track_design.c b/src/openrct2/ride/TrackDesign.cpp similarity index 55% rename from src/openrct2/ride/track_design.c rename to src/openrct2/ride/TrackDesign.cpp index 979eb71688..78e82466a3 100644 --- a/src/openrct2/ride/track_design.c +++ b/src/openrct2/ride/TrackDesign.cpp @@ -14,92 +14,109 @@ *****************************************************************************/ #pragma endregion -#include "../audio/audio.h" -#include "../cheats.h" -#include "../game.h" -#include "../localisation/localisation.h" -#include "../localisation/string_ids.h" -#include "../management/finance.h" +#include "../core/Math.hpp" +#include "../core/String.hpp" #include "../network/network.h" #include "../object/ObjectManager.h" #include "../object/ObjectRepository.h" #include "../OpenRCT2.h" -#include "../rct1.h" #include "../rct1/Tables.h" -#include "../util/sawyercoding.h" -#include "../util/util.h" -#include "../windows/error.h" -#include "../world/footpath.h" -#include "../world/scenery.h" -#include "ride.h" -#include "ride_data.h" -#include "track.h" -#include "track_data.h" -#include "track_design.h" #include "TrackDesignRepository.h" -typedef struct map_backup { +extern "C" +{ + #include "../audio/audio.h" + #include "../cheats.h" + #include "../game.h" + #include "../localisation/localisation.h" + #include "../localisation/string_ids.h" + #include "../management/finance.h" + #include "../rct1.h" + #include "../util/sawyercoding.h" + #include "../util/util.h" + #include "../windows/error.h" + #include "../world/footpath.h" + #include "../world/scenery.h" + #include "ride.h" + #include "ride_data.h" + #include "track.h" + #include "track_data.h" + #include "TrackDesign.h" +} + +typedef struct map_backup +{ rct_map_element map_elements[MAX_MAP_ELEMENTS]; - rct_map_element *tile_pointers[MAX_TILE_MAP_ELEMENT_POINTERS]; - rct_map_element *next_free_map_element; - uint16 map_size_units; - uint16 map_size_units_minus_2; - uint16 map_size; - uint8 current_rotation; + rct_map_element * tile_pointers[MAX_TILE_MAP_ELEMENT_POINTERS]; + rct_map_element * next_free_map_element; + uint16 map_size_units; + uint16 map_size_units_minus_2; + uint16 map_size; + uint8 current_rotation; } map_backup; -rct_track_td6 *gActiveTrackDesign; -bool gTrackDesignSceneryToggle; -rct_xyz16 gTrackPreviewMin; -rct_xyz16 gTrackPreviewMax; -rct_xyz16 gTrackPreviewOrigin; +rct_track_td6 * gActiveTrackDesign; +bool gTrackDesignSceneryToggle; +rct_xyz16 gTrackPreviewMin; +rct_xyz16 gTrackPreviewMax; +rct_xyz16 gTrackPreviewOrigin; -bool byte_9D8150; -static uint8 _trackDesignPlaceOperation; -static bool _trackDesignDontPlaceScenery; +bool byte_9D8150; +static uint8 _trackDesignPlaceOperation; +static bool _trackDesignDontPlaceScenery; static money32 _trackDesignPlaceCost; -static sint16 _trackDesignPlaceZ; -static sint16 _trackDesignPlaceSceneryZ; +static sint16 _trackDesignPlaceZ; +static sint16 _trackDesignPlaceSceneryZ; // Previously all flags in byte_F4414E static bool _trackDesignPlaceStateEntranceExitPlaced = false; static bool _trackDesignPlaceStateSceneryUnavailable = false; -static bool _trackDesignPlaceStateHasScenery = false; -static bool _trackDesignPlaceStatePlaceScenery = true; +static bool _trackDesignPlaceStateHasScenery = false; +static bool _trackDesignPlaceStatePlaceScenery = true; + +static rct_track_td6 * track_design_open_from_buffer(uint8 * src, size_t srcLength); + +static map_backup * track_design_preview_backup_map(); + +static void track_design_preview_restore_map(map_backup * backup); -static rct_track_td6 *track_design_open_from_buffer(uint8 *src, size_t srcLength); -static map_backup *track_design_preview_backup_map(); -static void track_design_preview_restore_map(map_backup *backup); static void track_design_preview_clear_map(); static void td6_reset_trailing_elements(rct_track_td6 * td6); + static void td6_set_element_helper_pointers(rct_track_td6 * td6); -rct_track_td6 *track_design_open(const utf8 *path) +rct_track_td6 * track_design_open(const utf8 * path) { log_verbose("track_design_open(\"%s\")", path); - uint8 *buffer; + uint8 * buffer; size_t bufferLength; - if (readentirefile(path, (void * *)&buffer, &bufferLength)) { - if (!sawyercoding_validate_track_checksum(buffer, bufferLength)) { + if (readentirefile(path, (void **) &buffer, &bufferLength)) + { + if (!sawyercoding_validate_track_checksum(buffer, bufferLength)) + { log_error("Track checksum failed. %s", path); free(buffer); return NULL; } // Decode the track data - uint8 *decoded = (uint8*)malloc(0x10000); + uint8 * decoded = (uint8 *) malloc(0x10000); size_t decodedLength = sawyercoding_decode_td6(buffer, decoded, bufferLength); free(buffer); - decoded = realloc(decoded, decodedLength); - if (decoded == NULL) { + decoded = (uint8 *) realloc(decoded, decodedLength); + if (decoded == NULL) + { log_error("failed to realloc"); - } else { - rct_track_td6 *td6 = track_design_open_from_buffer(decoded, decodedLength); + } + else + { + rct_track_td6 * td6 = track_design_open_from_buffer(decoded, decodedLength); free(decoded); - if (td6 != NULL) { + if (td6 != NULL) + { td6->name = track_repository_get_name_from_path(path); return td6; } @@ -108,151 +125,202 @@ rct_track_td6 *track_design_open(const utf8 *path) return NULL; } -static rct_track_td6 * track_design_open_from_td4(uint8 *src, size_t srcLength) +static rct_track_td6 * track_design_open_from_td4(uint8 * src, size_t srcLength) { - rct_track_td4 * td4 = calloc(1, sizeof(rct_track_td4)); - if (td4 == NULL) { + rct_track_td4 * td4 = (rct_track_td4 *) calloc(1, sizeof(rct_track_td4)); + if (td4 == NULL) + { log_error("Unable to allocate memory for TD4 data."); SafeFree(td4); return NULL; } uint8 version = (src[7] >> 2) & 3; - if (version == 0) { + if (version == 0) + { memcpy(td4, src, 0x38); td4->elementsSize = srcLength - 0x38; - td4->elements = malloc(td4->elementsSize); - if (td4->elements == NULL) { + td4->elements = malloc(td4->elementsSize); + if (td4->elements == NULL) + { log_error("Unable to allocate memory for TD4 element data."); SafeFree(td4); return NULL; } memcpy(td4->elements, src + 0x38, td4->elementsSize); - } else if (version == 1) { + } + else if (version == 1) + { memcpy(td4, src, 0xC4); td4->elementsSize = srcLength - 0xC4; - td4->elements = malloc(td4->elementsSize); - if (td4->elements == NULL) { + td4->elements = malloc(td4->elementsSize); + if (td4->elements == NULL) + { log_error("Unable to allocate memory for TD4 element data."); SafeFree(td4); return NULL; } memcpy(td4->elements, src + 0xC4, td4->elementsSize); - } else { + } + else + { log_error("Unsupported track design."); SafeFree(td4); return NULL; } - rct_track_td6 * td6 = calloc(1, sizeof(rct_track_td6)); - if (td6 == NULL) { + rct_track_td6 * td6 = (rct_track_td6 *) calloc(1, sizeof(rct_track_td6)); + if (td6 == NULL) + { log_error("Unable to allocate memory for TD6 data."); SafeFree(td4); return NULL; } - td6->type = rct1_get_ride_type(td4->type); + td6->type = RCT1::GetRideType(td4->type); // All TD4s that use powered launch use the type that doesn't pass the station. td6->ride_mode = td4->mode; - if (td4->mode == RCT1_RIDE_MODE_POWERED_LAUNCH) { + if (td4->mode == RCT1_RIDE_MODE_POWERED_LAUNCH) + { td6->ride_mode = RIDE_MODE_POWERED_LAUNCH; } - // Convert RCT1 vehicle type to RCT2 vehicle type -#pragma warning(push) -#pragma warning(disable : 4295) // 'identifier': array is too small to include a terminating null character - rct_object_entry vehicleObject = { 0x80, { " " }, 0 }; -#pragma warning(pop) - if (td4->type == RIDE_TYPE_MAZE) { - const char * name = rct1_get_ride_type_object(td4->type); + // Convert RCT1 vehicle type to RCT2 vehicle type. Intialise with an string consisting of 8 spaces (and no nul terminator). + rct_object_entry vehicleObject = {0x80, "", 0}; + memset(vehicleObject.name, ' ', sizeof(vehicleObject.name)); + if (td4->type == RIDE_TYPE_MAZE) + { + const char * name = RCT1::GetRideTypeObject(td4->type); assert(name != NULL); - memcpy(vehicleObject.name, name, min(strlen(name), 8)); - } else { - const char * name = rct1_get_vehicle_object(td4->vehicle_type); + memcpy(vehicleObject.name, name, Math::Min(String::SizeOf(name), (size_t)8)); + } + else + { + const char * name = RCT1::GetVehicleObject(td4->vehicle_type); assert(name != NULL); - memcpy(vehicleObject.name, name, min(strlen(name), 8)); + memcpy(vehicleObject.name, name, Math::Min(String::SizeOf(name), (size_t)8)); } memcpy(&td6->vehicle_object, &vehicleObject, sizeof(rct_object_entry)); td6->vehicle_type = td4->vehicle_type; - td6->flags = td4->flags; + td6->flags = td4->flags; td6->version_and_colour_scheme = td4->version_and_colour_scheme; // Vehicle colours - for (sint32 i = 0; i < RCT1_MAX_TRAINS_PER_RIDE; i++) { - td6->vehicle_colours[i].body_colour = rct1_get_colour(td4->vehicle_colours[i].body_colour); - td6->vehicle_colours[i].trim_colour = rct1_get_colour(td4->vehicle_colours[i].trim_colour); + for (sint32 i = 0; i < RCT1_MAX_TRAINS_PER_RIDE; i++) + { + // RCT1 had no third colour + RCT1::RCT1VehicleColourSchemeCopyDescriptor colourSchemeCopyDescriptor = RCT1::GetColourSchemeCopyDescriptor( + td4->vehicle_type); + if (colourSchemeCopyDescriptor.colour1 == COPY_COLOUR_1) + { + td6->vehicle_colours[i].body_colour = RCT1::GetColour(td4->vehicle_colours[i].body_colour); + } + else if (colourSchemeCopyDescriptor.colour1 == COPY_COLOUR_2) + { + td6->vehicle_colours[i].body_colour = RCT1::GetColour(td4->vehicle_colours[i].trim_colour); + } + else + { + td6->vehicle_colours[i].body_colour = colourSchemeCopyDescriptor.colour1; + } - // RCT1 river rapids always had black seats - if (td4->type == RCT1_RIDE_TYPE_RIVER_RAPIDS) { - td6->vehicle_colours[i].trim_colour = COLOUR_BLACK; + if (colourSchemeCopyDescriptor.colour2 == COPY_COLOUR_1) + { + td6->vehicle_colours[i].trim_colour = RCT1::GetColour(td4->vehicle_colours[i].body_colour); + } + else if (colourSchemeCopyDescriptor.colour2 == COPY_COLOUR_2) + { + td6->vehicle_colours[i].trim_colour = RCT1::GetColour(td4->vehicle_colours[i].trim_colour); + } + else + { + td6->vehicle_colours[i].trim_colour = colourSchemeCopyDescriptor.colour2; + } + + if (colourSchemeCopyDescriptor.colour3 == COPY_COLOUR_1) + { + td6->vehicle_additional_colour[i] = RCT1::GetColour(td4->vehicle_colours[i].body_colour); + } + else if (colourSchemeCopyDescriptor.colour3 == COPY_COLOUR_2) + { + td6->vehicle_additional_colour[i] = RCT1::GetColour(td4->vehicle_colours[i].trim_colour); + } + else + { + td6->vehicle_additional_colour[i] = colourSchemeCopyDescriptor.colour3; } } // Set remaining vehicles to same colour as first vehicle - for (sint32 i = RCT1_MAX_TRAINS_PER_RIDE; i < 32; i++) { - td6->vehicle_colours[i] = td6->vehicle_colours[0]; - } - // Set additional colour to trim colour for all vehicles - for (sint32 i = 0; i < 32; i++) { - td6->vehicle_additional_colour[i] = td6->vehicle_colours[i].trim_colour; + for (sint32 i = RCT1_MAX_TRAINS_PER_RIDE; i < MAX_VEHICLES_PER_RIDE; i++) + { + td6->vehicle_colours[i] = td6->vehicle_colours[0]; + td6->vehicle_additional_colour[i] = td6->vehicle_additional_colour[0]; } // Track colours - if (version == 0) { - for (sint32 i = 0; i < NUM_COLOUR_SCHEMES; i++) { - td6->track_spine_colour[i] = rct1_get_colour(td4->track_spine_colour_v0); - td6->track_rail_colour[i] = rct1_get_colour(td4->track_rail_colour_v0); - td6->track_support_colour[i] = rct1_get_colour(td4->track_support_colour_v0); + if (version == 0) + { + for (sint32 i = 0; i < NUM_COLOUR_SCHEMES; i++) + { + td6->track_spine_colour[i] = RCT1::GetColour(td4->track_spine_colour_v0); + td6->track_rail_colour[i] = RCT1::GetColour(td4->track_rail_colour_v0); + td6->track_support_colour[i] = RCT1::GetColour(td4->track_support_colour_v0); // Mazes were only hedges - switch (td4->type) { + switch (td4->type) + { case RCT1_RIDE_TYPE_HEDGE_MAZE: td6->track_support_colour[i] = MAZE_WALL_TYPE_HEDGE; break; case RCT1_RIDE_TYPE_RIVER_RAPIDS: td6->track_spine_colour[i] = COLOUR_WHITE; - td6->track_rail_colour[i] = COLOUR_WHITE; + td6->track_rail_colour[i] = COLOUR_WHITE; break; } } - } else { - for (sint32 i = 0; i < RCT12_NUM_COLOUR_SCHEMES; i++) { - td6->track_spine_colour[i] = rct1_get_colour(td4->track_spine_colour[i]); - td6->track_rail_colour[i] = rct1_get_colour(td4->track_rail_colour[i]); - td6->track_support_colour[i] = rct1_get_colour(td4->track_support_colour[i]); + } + else + { + for (sint32 i = 0; i < RCT12_NUM_COLOUR_SCHEMES; i++) + { + td6->track_spine_colour[i] = RCT1::GetColour(td4->track_spine_colour[i]); + td6->track_rail_colour[i] = RCT1::GetColour(td4->track_rail_colour[i]); + td6->track_support_colour[i] = RCT1::GetColour(td4->track_support_colour[i]); } } - td6->depart_flags = td4->depart_flags; - td6->number_of_trains = td4->number_of_trains; + td6->depart_flags = td4->depart_flags; + td6->number_of_trains = td4->number_of_trains; td6->number_of_cars_per_train = td4->number_of_cars_per_train; - td6->min_waiting_time = td4->min_waiting_time; - td6->max_waiting_time = td4->max_waiting_time; - td6->operation_setting = min(td4->operation_setting, RideProperties[td6->type].max_value); - td6->max_speed = td4->max_speed; - td6->average_speed = td4->average_speed; - td6->ride_length = td4->ride_length; - td6->max_positive_vertical_g = td4->max_positive_vertical_g; - td6->max_negative_vertical_g = td4->max_negative_vertical_g; - td6->max_lateral_g = td4->max_lateral_g; - td6->inversions = td4->num_inversions; - td6->drops = td4->num_drops; - td6->highest_drop_height = td4->highest_drop_height / 2; - td6->excitement = td4->excitement; - td6->intensity = td4->intensity; - td6->nausea = td4->nausea; - td6->upkeep_cost = td4->upkeep_cost; - if (version == 1) { + td6->min_waiting_time = td4->min_waiting_time; + td6->max_waiting_time = td4->max_waiting_time; + td6->operation_setting = Math::Min(td4->operation_setting, RideProperties[td6->type].max_value); + td6->max_speed = td4->max_speed; + td6->average_speed = td4->average_speed; + td6->ride_length = td4->ride_length; + td6->max_positive_vertical_g = td4->max_positive_vertical_g; + td6->max_negative_vertical_g = td4->max_negative_vertical_g; + td6->max_lateral_g = td4->max_lateral_g; + td6->inversions = td4->num_inversions; + td6->drops = td4->num_drops; + td6->highest_drop_height = td4->highest_drop_height / 2; + td6->excitement = td4->excitement; + td6->intensity = td4->intensity; + td6->nausea = td4->nausea; + td6->upkeep_cost = td4->upkeep_cost; + if (version == 1) + { td6->flags2 = td4->flags2; } - td6->space_required_x = 255; - td6->space_required_y = 255; + td6->space_required_x = 255; + td6->space_required_y = 255; td6->lift_hill_speed_num_circuits = 5; // Move elements across - td6->elements = td4->elements; + td6->elements = td4->elements; td6->elementsSize = td4->elementsSize; td6_reset_trailing_elements(td6); @@ -262,25 +330,30 @@ static rct_track_td6 * track_design_open_from_td4(uint8 *src, size_t srcLength) return td6; } -static rct_track_td6 *track_design_open_from_buffer(uint8 * src, size_t srcLength) +static rct_track_td6 * track_design_open_from_buffer(uint8 * src, size_t srcLength) { uint8 version = (src[7] >> 2) & 3; - if (version == 0 || version == 1) { + if (version == 0 || version == 1) + { return track_design_open_from_td4(src, srcLength); - } else if (version != 2) { + } + else if (version != 2) + { log_error("Unsupported track design."); return NULL; } - rct_track_td6 * td6 = calloc(1, sizeof(rct_track_td6)); - if (td6 == NULL) { + rct_track_td6 * td6 = (rct_track_td6 *) calloc(1, sizeof(rct_track_td6)); + if (td6 == NULL) + { log_error("Unable to allocate memory for TD6 data."); return NULL; } memcpy(td6, src, 0xA3); td6->elementsSize = srcLength - 0xA3; - td6->elements = malloc(td6->elementsSize); - if (td6->elements == NULL) { + td6->elements = malloc(td6->elementsSize); + if (td6->elements == NULL) + { free(td6); log_error("Unable to allocate memory for TD6 element data."); return NULL; @@ -288,7 +361,7 @@ static rct_track_td6 *track_design_open_from_buffer(uint8 * src, size_t srcLengt memcpy(td6->elements, src + 0xA3, td6->elementsSize); // Cap operation setting - td6->operation_setting = min(td6->operation_setting, RideProperties[td6->type].max_value); + td6->operation_setting = Math::Min(td6->operation_setting, RideProperties[td6->type].max_value); td6_set_element_helper_pointers(td6); return td6; @@ -296,55 +369,70 @@ static rct_track_td6 *track_design_open_from_buffer(uint8 * src, size_t srcLengt static void td6_reset_trailing_elements(rct_track_td6 * td6) { - void * lastElement; - if (td6->type == RIDE_TYPE_MAZE) { - rct_td6_maze_element * mazeElement = (rct_td6_maze_element *)td6->elements; - while (mazeElement->all != 0) { + void * lastElement; + if (td6->type == RIDE_TYPE_MAZE) + { + rct_td6_maze_element * mazeElement = (rct_td6_maze_element *) td6->elements; + while (mazeElement->all != 0) + { mazeElement++; } - lastElement = (void *)((uintptr_t)mazeElement + 1); - } else { - rct_td6_track_element * trackElement = (rct_td6_track_element *)td6->elements; - while (trackElement->type != 0xFF) { + lastElement = (void *) ((uintptr_t) mazeElement + 1); + } + else + { + rct_td6_track_element * trackElement = (rct_td6_track_element *) td6->elements; + while (trackElement->type != 0xFF) + { trackElement++; } - lastElement = (void *)((uintptr_t)trackElement + 1); + lastElement = (void *) ((uintptr_t) trackElement + 1); } - size_t trailingSize = td6->elementsSize - (size_t)((uintptr_t)lastElement - (uintptr_t)td6->elements); + size_t trailingSize = td6->elementsSize - (size_t)((uintptr_t) lastElement - (uintptr_t) td6->elements); memset(lastElement, 0xFF, trailingSize); } static void td6_set_element_helper_pointers(rct_track_td6 * td6) { uintptr_t sceneryElementsStart; - if (td6->type == RIDE_TYPE_MAZE) { + if (td6->type == RIDE_TYPE_MAZE) + { td6->track_elements = NULL; - td6->maze_elements = (rct_td6_maze_element*)td6->elements; + td6->maze_elements = (rct_td6_maze_element *) td6->elements; - rct_td6_maze_element *maze = td6->maze_elements; - for (; maze->all != 0; maze++) {} + rct_td6_maze_element * maze = td6->maze_elements; + for (; maze->all != 0; maze++) + { + } sceneryElementsStart = (uintptr_t)(++maze); - } else { - td6->maze_elements = NULL; - td6->track_elements = (rct_td6_track_element*)td6->elements; + } + else + { + td6->maze_elements = NULL; + td6->track_elements = (rct_td6_track_element *) td6->elements; - rct_td6_track_element *track = td6->track_elements; - for (; track->type != 0xFF; track++) {} - uintptr_t entranceElementsStart = (uintptr_t)track + 1; + rct_td6_track_element * track = td6->track_elements; + for (; track->type != 0xFF; track++) + { + } + uintptr_t entranceElementsStart = (uintptr_t) track + 1; - rct_td6_entrance_element *entranceElement = (rct_td6_entrance_element*)entranceElementsStart; + rct_td6_entrance_element * entranceElement = (rct_td6_entrance_element *) entranceElementsStart; td6->entrance_elements = entranceElement; - for (; entranceElement->z != -1; entranceElement++) {} - sceneryElementsStart = (uintptr_t)entranceElement + 1; + for (; entranceElement->z != -1; entranceElement++) + { + } + sceneryElementsStart = (uintptr_t) entranceElement + 1; } - rct_td6_scenery_element *sceneryElement = (rct_td6_scenery_element*)sceneryElementsStart; + rct_td6_scenery_element * sceneryElement = (rct_td6_scenery_element *) sceneryElementsStart; td6->scenery_elements = sceneryElement; } -void track_design_dispose(rct_track_td6 *td6) +void track_design_dispose(rct_track_td6 * td6) { - if (td6 != NULL) { + if (td6 != NULL) + { free(td6->elements); free(td6->name); free(td6); @@ -355,7 +443,7 @@ void track_design_dispose(rct_track_td6 *td6) * * rct2: 0x006ABDB0 */ -static void track_design_load_scenery_objects(rct_track_td6 *td6) +static void track_design_load_scenery_objects(rct_track_td6 * td6) { object_manager_unload_all_objects(); @@ -364,8 +452,9 @@ static void track_design_load_scenery_objects(rct_track_td6 *td6) object_manager_load_object(rideEntry); // Load scenery objects - rct_td6_scenery_element *scenery = td6->scenery_elements; - for (; scenery->scenery_object.end_flag != 0xFF; scenery++) { + rct_td6_scenery_element * scenery = td6->scenery_elements; + for (; scenery->scenery_object.end_flag != 0xFF; scenery++) + { rct_object_entry * sceneryEntry = &scenery->scenery_object; object_manager_load_object(sceneryEntry); } @@ -375,61 +464,82 @@ static void track_design_load_scenery_objects(rct_track_td6 *td6) * * rct2: 0x006D247A */ -static void track_design_mirror_scenery(rct_track_td6 *td6) +static void track_design_mirror_scenery(rct_track_td6 * td6) { - rct_td6_scenery_element *scenery = td6->scenery_elements; - for (; scenery->scenery_object.end_flag != 0xFF; scenery++) { + rct_td6_scenery_element * scenery = td6->scenery_elements; + for (; scenery->scenery_object.end_flag != 0xFF; scenery++) + { uint8 entry_type, entry_index; - if (!find_object_in_entry_group(&scenery->scenery_object, &entry_type, &entry_index)) { + if (!find_object_in_entry_group(&scenery->scenery_object, &entry_type, &entry_index)) + { entry_type = scenery->scenery_object.flags & 0xF; - if (entry_type != OBJECT_TYPE_PATHS) { + if (entry_type != OBJECT_TYPE_PATHS) + { continue; } } - rct_scenery_entry *scenery_entry = (rct_scenery_entry*)object_entry_groups[entry_type].chunks[entry_index]; - switch (entry_type) { - case OBJECT_TYPE_LARGE_SCENERY: + rct_scenery_entry * scenery_entry = (rct_scenery_entry *) object_entry_groups[entry_type].chunks[entry_index]; + switch (entry_type) { - sint16 x1 = 0, x2 = 0, y1 = 0, y2 = 0; - for (rct_large_scenery_tile* tile = scenery_entry->large_scenery.tiles; tile->x_offset != -1; tile++) { - if (x1 > tile->x_offset) x1 = tile->x_offset; - if (x2 < tile->x_offset) x2 = tile->x_offset; - if (y1 > tile->y_offset) y1 = tile->y_offset; - if (y2 > tile->y_offset) y2 = tile->y_offset; - } + case OBJECT_TYPE_LARGE_SCENERY: + { + sint16 x1 = 0, x2 = 0, y1 = 0, y2 = 0; + for (rct_large_scenery_tile * tile = scenery_entry->large_scenery.tiles; tile->x_offset != -1; tile++) + { + if (x1 > tile->x_offset) + { + x1 = tile->x_offset; + } + if (x2 < tile->x_offset) + { + x2 = tile->x_offset; + } + if (y1 > tile->y_offset) + { + y1 = tile->y_offset; + } + if (y2 > tile->y_offset) + { + y2 = tile->y_offset; + } + } - switch (scenery->flags & 3) { - case 0: - scenery->y = (-(scenery->y * 32 + y1) - y2) / 32; - break; - case 1: - scenery->x = (scenery->x * 32 + y2 + y1) / 32; - scenery->y = (-(scenery->y * 32)) / 32; - scenery->flags ^= (1 << 1); - break; - case 2: - scenery->y = (-(scenery->y * 32 - y2) + y1) / 32; - break; - case 3: - scenery->x = (scenery->x * 32 - y2 - y1) / 32; - scenery->y = (-(scenery->y * 32)) / 32; - scenery->flags ^= (1 << 1); + switch (scenery->flags & 3) + { + case 0: + scenery->y = (-(scenery->y * 32 + y1) - y2) / 32; + break; + case 1: + scenery->x = (scenery->x * 32 + y2 + y1) / 32; + scenery->y = (-(scenery->y * 32)) / 32; + scenery->flags ^= (1 << 1); + break; + case 2: + scenery->y = (-(scenery->y * 32 - y2) + y1) / 32; + break; + case 3: + scenery->x = (scenery->x * 32 - y2 - y1) / 32; + scenery->y = (-(scenery->y * 32)) / 32; + scenery->flags ^= (1 << 1); + break; + } break; } - break; - } case OBJECT_TYPE_SMALL_SCENERY: scenery->y = -scenery->y; - if (scenery_entry->small_scenery.flags & SMALL_SCENERY_FLAG_DIAGONAL) { + if (scenery_entry->small_scenery.flags & SMALL_SCENERY_FLAG_DIAGONAL) + { scenery->flags ^= (1 << 0); - if (!(scenery_entry->small_scenery.flags & SMALL_SCENERY_FLAG_FULL_TILE)) { + if (!(scenery_entry->small_scenery.flags & SMALL_SCENERY_FLAG_FULL_TILE)) + { scenery->flags ^= (1 << 2); } break; } - if (scenery->flags & (1 << 0)) { + if (scenery->flags & (1 << 0)) + { scenery->flags ^= (1 << 1); } @@ -438,7 +548,8 @@ static void track_design_mirror_scenery(rct_track_td6 *td6) case OBJECT_TYPE_WALLS: scenery->y = -scenery->y; - if (scenery->flags & (1 << 0)) { + if (scenery->flags & (1 << 0)) + { scenery->flags ^= (1 << 1); } break; @@ -446,7 +557,8 @@ static void track_design_mirror_scenery(rct_track_td6 *td6) case OBJECT_TYPE_PATHS: scenery->y = -scenery->y; - if (scenery->flags & (1 << 5)) { + if (scenery->flags & (1 << 5)) + { scenery->flags ^= (1 << 6); } @@ -462,17 +574,20 @@ static void track_design_mirror_scenery(rct_track_td6 *td6) * * rct2: 0x006D2443 */ -static void track_design_mirror_ride(rct_track_td6 *td6) +static void track_design_mirror_ride(rct_track_td6 * td6) { - rct_td6_track_element *track = td6->track_elements; - for (; track->type != 0xFF; track++) { + rct_td6_track_element * track = td6->track_elements; + for (; track->type != 0xFF; track++) + { track->type = TrackElementMirrorMap[track->type]; } - rct_td6_entrance_element *entrance = td6->entrance_elements; - for (; entrance->z != -1; entrance++) { + rct_td6_entrance_element * entrance = td6->entrance_elements; + for (; entrance->z != -1; entrance++) + { entrance->y = -entrance->y; - if (entrance->direction & 1) { + if (entrance->direction & 1) + { entrance->direction ^= (1 << 1); } } @@ -487,22 +602,26 @@ static const uint8 maze_segment_mirror_map[] = { * * rct2: 0x006D25FA */ -static void track_design_mirror_maze(rct_track_td6 *td6) +static void track_design_mirror_maze(rct_track_td6 * td6) { - rct_td6_maze_element *maze = td6->maze_elements; - for (; maze->all != 0; maze++) { + rct_td6_maze_element * maze = td6->maze_elements; + for (; maze->all != 0; maze++) + { maze->y = -maze->y; - if (maze->type == 0x8 || maze->type == 0x80) { - if (maze->direction & 1) { + if (maze->type == 0x8 || maze->type == 0x80) + { + if (maze->direction & 1) + { maze->direction ^= (1 << 1); } continue; } - uint16 maze_entry = maze->maze_entry; - uint16 new_entry = 0; - for (uint8 position = bitscanforward(maze_entry); position != 0xFF; position = bitscanforward(maze_entry)) { + uint16 maze_entry = maze->maze_entry; + uint16 new_entry = 0; + for (uint8 position = bitscanforward(maze_entry); position != 0xFF; position = bitscanforward(maze_entry)) + { maze_entry &= ~(1 << position); new_entry |= (1 << maze_segment_mirror_map[position]); } @@ -514,11 +633,14 @@ static void track_design_mirror_maze(rct_track_td6 *td6) * * rct2: 0x006D2436 */ -void track_design_mirror(rct_track_td6 *td6) +void track_design_mirror(rct_track_td6 * td6) { - if (td6->type == RIDE_TYPE_MAZE) { + if (td6->type == RIDE_TYPE_MAZE) + { track_design_mirror_maze(td6); - } else { + } + else + { track_design_mirror_ride(td6); } track_design_mirror_scenery(td6); @@ -526,12 +648,15 @@ void track_design_mirror(rct_track_td6 *td6) static void track_design_add_selection_tile(sint16 x, sint16 y) { - rct_xy16 *selectionTile = gMapSelectionTiles; - for (; selectionTile->x != -1; selectionTile++) { - if (selectionTile->x == x && selectionTile->y == y) { + rct_xy16 * selectionTile = gMapSelectionTiles; + for (; selectionTile->x != -1; selectionTile++) + { + if (selectionTile->x == x && selectionTile->y == y) + { return; } - if (selectionTile + 1 >= &gMapSelectionTiles[300]) { + if (selectionTile + 1 >= &gMapSelectionTiles[300]) + { return; } } @@ -543,33 +668,40 @@ static void track_design_add_selection_tile(sint16 x, sint16 y) static void track_design_update_max_min_coordinates(sint16 x, sint16 y, sint16 z) { - gTrackPreviewMin.x = min(gTrackPreviewMin.x, x); - gTrackPreviewMax.x = max(gTrackPreviewMax.x, x); - gTrackPreviewMin.y = min(gTrackPreviewMin.y, y); - gTrackPreviewMax.y = max(gTrackPreviewMax.y, y); - gTrackPreviewMin.z = min(gTrackPreviewMin.z, z); - gTrackPreviewMax.z = max(gTrackPreviewMax.z, z); + gTrackPreviewMin.x = Math::Min(gTrackPreviewMin.x, x); + gTrackPreviewMax.x = Math::Max(gTrackPreviewMax.x, x); + gTrackPreviewMin.y = Math::Min(gTrackPreviewMin.y, y); + gTrackPreviewMax.y = Math::Max(gTrackPreviewMax.y, y); + gTrackPreviewMin.z = Math::Min(gTrackPreviewMin.z, z); + gTrackPreviewMax.z = Math::Max(gTrackPreviewMax.z, z); } /** * * rct2: 0x006D0964 */ -static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, uint8 rideIndex, sint32 originX, sint32 originY, sint32 originZ) +static sint32 +track_design_place_scenery(rct_td6_scenery_element * scenery_start, uint8 rideIndex, sint32 originX, sint32 originY, + sint32 originZ) { - for (uint8 mode = 0; mode <= 1; mode++) { - if (scenery_start->scenery_object.end_flag != 0xFF) { + for (uint8 mode = 0; mode <= 1; mode++) + { + if (scenery_start->scenery_object.end_flag != 0xFF) + { _trackDesignPlaceStateHasScenery = true; } - if (!_trackDesignPlaceStatePlaceScenery) { + if (!_trackDesignPlaceStatePlaceScenery) + { continue; } - for (rct_td6_scenery_element *scenery = scenery_start; scenery->scenery_object.end_flag != 0xFF; scenery++) { - uint8 rotation = _currentTrackPieceDirection; - rct_xy8 tile = { .x = originX / 32, .y = originY / 32 }; - switch (rotation & 3){ + for (rct_td6_scenery_element * scenery = scenery_start; scenery->scenery_object.end_flag != 0xFF; scenery++) + { + uint8 rotation = _currentTrackPieceDirection; + rct_xy8 tile = {(uint8) (originX / 32), (uint8) (originY / 32)}; + switch (rotation & 3) + { case MAP_ELEMENT_DIRECTION_WEST: tile.x += scenery->x; tile.y += scenery->y; @@ -588,23 +720,28 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, break; } - rct_xy16 mapCoord = { .x = tile.x * 32, .y = tile.y * 32 }; + rct_xy16 mapCoord = {(sint16) (tile.x * 32), (sint16) (tile.y * 32)}; track_design_update_max_min_coordinates(mapCoord.x, mapCoord.y, originZ); - if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES && mode == 0) { - uint8 new_tile = 1; - rct_xy16* selectionTile = gMapSelectionTiles; - for (; selectionTile->x != -1; selectionTile++){ - if (selectionTile->x == tile.x && selectionTile->y == tile.y){ + if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES && mode == 0) + { + uint8 new_tile = 1; + rct_xy16 * selectionTile = gMapSelectionTiles; + for (; selectionTile->x != -1; selectionTile++) + { + if (selectionTile->x == tile.x && selectionTile->y == tile.y) + { new_tile = 0; break; } - if (selectionTile + 1 >= &gMapSelectionTiles[300]){ + if (selectionTile + 1 >= &gMapSelectionTiles[300]) + { new_tile = 0; break; } } - if (new_tile){ + if (new_tile) + { selectionTile->x = tile.x; selectionTile->y = tile.y; selectionTile++; @@ -612,42 +749,52 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, } } - if (_trackDesignPlaceOperation == PTD_OPERATION_CLEAR_OUTLINES && mode == 0) { + if (_trackDesignPlaceOperation == PTD_OPERATION_CLEAR_OUTLINES && mode == 0) + { uint8 entry_type, entry_index; - if (!find_object_in_entry_group(&scenery->scenery_object, &entry_type, &entry_index)) { + if (!find_object_in_entry_group(&scenery->scenery_object, &entry_type, &entry_index)) + { entry_type = scenery->scenery_object.flags & 0xF; - if (entry_type != OBJECT_TYPE_PATHS) { + if (entry_type != OBJECT_TYPE_PATHS) + { entry_type = 0xFF; } - if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) { + if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) + { entry_type = 0xFF; } entry_index = 0; - for (rct_footpath_entry *path = get_footpath_entry(0); - entry_index < object_entry_group_counts[OBJECT_TYPE_PATHS]; - path = get_footpath_entry(entry_index), entry_index++ - ) { - if (path == (rct_footpath_entry*)-1) { + for (rct_footpath_entry * path = get_footpath_entry(0); + entry_index < object_entry_group_counts[OBJECT_TYPE_PATHS]; + path = get_footpath_entry(entry_index), entry_index++ + ) + { + if (path == (rct_footpath_entry *) -1) + { continue; } - if (path->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR) { + if (path->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR) + { continue; } } - if (entry_index == object_entry_group_counts[OBJECT_TYPE_PATHS]) { + if (entry_index == object_entry_group_counts[OBJECT_TYPE_PATHS]) + { entry_type = 0xFF; } } - sint32 z; + sint32 z; const uint32 flags = GAME_COMMAND_FLAG_APPLY | - GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | - GAME_COMMAND_FLAG_5 | - GAME_COMMAND_FLAG_GHOST; + GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | + GAME_COMMAND_FLAG_5 | + GAME_COMMAND_FLAG_GHOST; - switch (entry_type) { + switch (entry_type) + { case OBJECT_TYPE_SMALL_SCENERY: + { //bl rotation += scenery->flags; rotation &= 3; @@ -658,13 +805,16 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, uint8 bh = rotation | (quadrant << 6) | MAP_ELEMENT_TYPE_SCENERY; - rct_scenery_entry* small_scenery = get_small_scenery_entry(entry_index); + rct_scenery_entry * small_scenery = get_small_scenery_entry(entry_index); if (!(!(small_scenery->small_scenery.flags & SMALL_SCENERY_FLAG_FULL_TILE) && - (small_scenery->small_scenery.flags & SMALL_SCENERY_FLAG_DIAGONAL)) && - (small_scenery->small_scenery.flags & (SMALL_SCENERY_FLAG_DIAGONAL | SMALL_SCENERY_FLAG_HALF_SPACE | SMALL_SCENERY_FLAG_THREE_QUARTERS))) + (small_scenery->small_scenery.flags & SMALL_SCENERY_FLAG_DIAGONAL)) && + (small_scenery->small_scenery.flags & + (SMALL_SCENERY_FLAG_DIAGONAL | SMALL_SCENERY_FLAG_HALF_SPACE | + SMALL_SCENERY_FLAG_THREE_QUARTERS))) { bh &= 0x3F; } + z = (scenery->z * 8 + originZ) / 8; game_do_command( mapCoord.x, @@ -675,6 +825,7 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, 0, 0); break; + } case OBJECT_TYPE_LARGE_SCENERY: z = (scenery->z * 8 + originZ) / 8; game_do_command( @@ -708,9 +859,11 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, } } - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) { + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) + { sint32 z = scenery->z * 8 + _trackDesignPlaceZ; - if (z < _trackDesignPlaceSceneryZ) { + if (z < _trackDesignPlaceSceneryZ) + { _trackDesignPlaceSceneryZ = z; } } @@ -720,10 +873,12 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, _trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z || _trackDesignPlaceOperation == PTD_OPERATION_4 || _trackDesignPlaceOperation == PTD_OPERATION_GET_COST - ) { + ) + { uint8 entry_type, entry_index; - if (!find_object_in_entry_group(&scenery->scenery_object, &entry_type, &entry_index)){ + if (!find_object_in_entry_group(&scenery->scenery_object, &entry_type, &entry_index)) + { entry_type = scenery->scenery_object.flags & 0xF; if (entry_type != OBJECT_TYPE_PATHS) { @@ -731,46 +886,70 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, continue; } - if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) { + if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) + { _trackDesignPlaceStateSceneryUnavailable = true; continue; } entry_index = 0; - for (rct_footpath_entry* path = get_footpath_entry(0); - entry_index < object_entry_group_counts[OBJECT_TYPE_PATHS]; - path = get_footpath_entry(entry_index), entry_index++){ + for (rct_footpath_entry * path = get_footpath_entry(0); + entry_index < object_entry_group_counts[OBJECT_TYPE_PATHS]; + path = get_footpath_entry(entry_index), entry_index++) + { - if (path == (rct_footpath_entry*)-1) + if (path == (rct_footpath_entry *) -1) + { continue; + } if (path->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR) + { continue; + } } - if (entry_index == object_entry_group_counts[OBJECT_TYPE_PATHS]){ + if (entry_index == object_entry_group_counts[OBJECT_TYPE_PATHS]) + { _trackDesignPlaceStateSceneryUnavailable = true; continue; } } money32 cost; - sint16 z; - uint8 bl; + sint16 z; + uint8 bl; + uint8 quadrant; - switch (entry_type){ + switch (entry_type) + { case OBJECT_TYPE_SMALL_SCENERY: - if (mode != 0) continue; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) continue; + if (mode != 0) + { + continue; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) + { + continue; + } rotation += scenery->flags; rotation &= 3; - z = scenery->z * 8 + originZ; - uint8 quadrant = ((scenery->flags >> 2) + _currentTrackPieceDirection) & 3; + z = scenery->z * 8 + originZ; + quadrant = ((scenery->flags >> 2) + _currentTrackPieceDirection) & 3; bl = 0x81; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) bl = 0xA9; - if (_trackDesignPlaceOperation == PTD_OPERATION_4) bl = 0xE9; - if (_trackDesignPlaceOperation == PTD_OPERATION_1) bl = 0x80; + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) + { + bl = 0xA9; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_4) + { + bl = 0xE9; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_1) + { + bl = 0x80; + } gGameCommandErrorTitle = STR_CANT_POSITION_THIS_HERE; @@ -784,13 +963,20 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, z ); - if (cost == MONEY32_UNDEFINED) { + if (cost == MONEY32_UNDEFINED) + { cost = 0; } break; case OBJECT_TYPE_LARGE_SCENERY: - if (mode != 0) continue; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) continue; + if (mode != 0) + { + continue; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) + { + continue; + } rotation += scenery->flags; rotation &= 3; @@ -798,9 +984,18 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, z = scenery->z * 8 + originZ; bl = 0x81; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) bl = 0xA9; - if (_trackDesignPlaceOperation == PTD_OPERATION_4) bl = 0xE9; - if (_trackDesignPlaceOperation == PTD_OPERATION_1) bl = 0x80; + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) + { + bl = 0xA9; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_4) + { + bl = 0xE9; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_1) + { + bl = 0x80; + } cost = game_do_command( mapCoord.x, @@ -810,23 +1005,40 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, GAME_COMMAND_PLACE_LARGE_SCENERY, entry_index, z - ); + ); if (cost == MONEY32_UNDEFINED) + { cost = 0; + } break; case OBJECT_TYPE_WALLS: - if (mode != 0) continue; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) continue; + if (mode != 0) + { + continue; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) + { + continue; + } z = scenery->z * 8 + originZ; rotation += scenery->flags; rotation &= 3; bl = 1; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) bl = 0xA9; - if (_trackDesignPlaceOperation == PTD_OPERATION_4) bl = 105; - if (_trackDesignPlaceOperation == PTD_OPERATION_1) bl = 0; + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) + { + bl = 0xA9; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_4) + { + bl = 105; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_1) + { + bl = 0; + } gGameCommandErrorTitle = STR_CANT_BUILD_PARK_ENTRANCE_HERE; @@ -838,17 +1050,24 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, GAME_COMMAND_PLACE_WALL, z, scenery->secondary_colour | ((scenery->flags & 0xFC) << 6) - ); + ); if (cost == MONEY32_UNDEFINED) + { cost = 0; + } break; case OBJECT_TYPE_PATHS: - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) continue; + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) + { + continue; + } z = (scenery->z * 8 + originZ) / 8; - if (mode == 0) { - if (scenery->flags & (1 << 7)){ + if (mode == 0) + { + if (scenery->flags & (1 << 7)) + { //dh entry_index |= (1 << 7); } @@ -862,28 +1081,50 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, bh |= scenery->flags & 0x90; bl = 1; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) bl = 41; - if (_trackDesignPlaceOperation == PTD_OPERATION_4) bl = 105; - if (_trackDesignPlaceOperation == PTD_OPERATION_1) bl = 0; + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) + { + bl = 41; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_4) + { + bl = 105; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_1) + { + bl = 0; + } gGameCommandErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - cost = game_do_command(mapCoord.x, bl | (bh << 8), mapCoord.y, z | (entry_index << 8), GAME_COMMAND_PLACE_PATH_FROM_TRACK, 0, 0); + cost = game_do_command(mapCoord.x, bl | (bh << 8), mapCoord.y, + z | (entry_index << 8), + GAME_COMMAND_PLACE_PATH_FROM_TRACK, 0, 0); } - else{ + else + { if (_trackDesignPlaceOperation == PTD_OPERATION_1) + { continue; + } - rct_map_element* map_element = map_get_path_element_at(mapCoord.x / 32, mapCoord.y / 32, z); + rct_map_element * map_element = map_get_path_element_at(mapCoord.x / 32, mapCoord.y / 32, z); if (map_element == NULL) + { continue; + } footpath_queue_chain_reset(); footpath_remove_edges_at(mapCoord.x, mapCoord.y, map_element); bl = 1; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) bl = 41; - if (_trackDesignPlaceOperation == PTD_OPERATION_4) bl = 105; + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) + { + bl = 41; + } + if (_trackDesignPlaceOperation == PTD_OPERATION_4) + { + bl = 105; + } footpath_connect_edges(mapCoord.x, mapCoord.y, map_element, bl); footpath_update_queue_chains(); @@ -896,15 +1137,19 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, break; } add_clamp_money32(_trackDesignPlaceCost, cost); - if (_trackDesignPlaceOperation != PTD_OPERATION_2) { - if (cost == MONEY32_UNDEFINED){ + if (_trackDesignPlaceOperation != PTD_OPERATION_2) + { + if (cost == MONEY32_UNDEFINED) + { _trackDesignPlaceCost = MONEY32_UNDEFINED; } } - if (_trackDesignPlaceCost != MONEY32_UNDEFINED) { + if (_trackDesignPlaceCost != MONEY32_UNDEFINED) + { continue; } - if (_trackDesignPlaceOperation == PTD_OPERATION_2) { + if (_trackDesignPlaceOperation == PTD_OPERATION_2) + { continue; } return 0; @@ -914,30 +1159,33 @@ static sint32 track_design_place_scenery(rct_td6_scenery_element *scenery_start, return 1; } -static sint32 track_design_place_maze(rct_track_td6 *td6, sint16 x, sint16 y, sint16 z, uint8 rideIndex) +static sint32 track_design_place_maze(rct_track_td6 * td6, sint16 x, sint16 y, sint16 z, uint8 rideIndex) { - if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES) { - gMapSelectionTiles->x = -1; + if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES) + { + gMapSelectionTiles->x = -1; gMapSelectArrowPosition.x = x; gMapSelectArrowPosition.y = y; gMapSelectArrowPosition.z = map_element_height(x, y) & 0xFFFF; gMapSelectArrowDirection = _currentTrackPieceDirection; } - _trackDesignPlaceZ = 0; + _trackDesignPlaceZ = 0; _trackDesignPlaceCost = 0; - rct_td6_maze_element *maze_element = td6->maze_elements; - for (; maze_element->all != 0; maze_element++){ - uint8 rotation = _currentTrackPieceDirection & 3; - rct_xy16 mapCoord = { .x = maze_element->x * 32, .y = maze_element->y * 32 }; + rct_td6_maze_element * maze_element = td6->maze_elements; + for (; maze_element->all != 0; maze_element++) + { + uint8 rotation = _currentTrackPieceDirection & 3; + rct_xy16 mapCoord = {(sint16) (maze_element->x * 32), (sint16) (maze_element->y * 32)}; rotate_map_coordinates(&mapCoord.x, &mapCoord.y, rotation); mapCoord.x += x; mapCoord.y += y; track_design_update_max_min_coordinates(mapCoord.x, mapCoord.y, z); - if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES) { + if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES) + { track_design_add_selection_tile(mapCoord.x, mapCoord.y); } @@ -945,33 +1193,42 @@ static sint32 track_design_place_maze(rct_track_td6 *td6, sint16 x, sint16 y, si _trackDesignPlaceOperation == PTD_OPERATION_2 || _trackDesignPlaceOperation == PTD_OPERATION_4 || _trackDesignPlaceOperation == PTD_OPERATION_GET_COST - ) { - uint8 flags; + ) + { + uint8 flags; money32 cost = 0; - uint16 maze_entry; - switch (maze_element->type) { + uint16 maze_entry; + switch (maze_element->type) + { case MAZE_ELEMENT_TYPE_ENTRANCE: // entrance rotation += maze_element->direction; rotation &= 3; - flags = GAME_COMMAND_FLAG_APPLY; + flags = GAME_COMMAND_FLAG_APPLY; gGameCommandErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - - if (_trackDesignPlaceOperation == PTD_OPERATION_1) { - cost = game_do_command(mapCoord.x, 0 | rotation << 8, mapCoord.y, (z / 16) & 0xFF, GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, -1, 0); - } else { + + if (_trackDesignPlaceOperation == PTD_OPERATION_1) + { + cost = game_do_command(mapCoord.x, 0 | rotation << 8, mapCoord.y, (z / 16) & 0xFF, + GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, -1, 0); + } + else + { if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) { flags = GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5; } else if (_trackDesignPlaceOperation == PTD_OPERATION_4) { - flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_GHOST; + flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | + GAME_COMMAND_FLAG_GHOST; } - cost = game_do_command(mapCoord.x, flags | rotation << 8, mapCoord.y, rideIndex, GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, 0, 0); + cost = game_do_command(mapCoord.x, flags | rotation << 8, mapCoord.y, rideIndex, + GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, 0, 0); } - if (cost != MONEY32_UNDEFINED){ + if (cost != MONEY32_UNDEFINED) + { _trackDesignPlaceStateEntranceExitPlaced = true; } break; @@ -980,24 +1237,30 @@ static sint32 track_design_place_maze(rct_track_td6 *td6, sint16 x, sint16 y, si rotation += maze_element->direction; rotation &= 3; - flags = GAME_COMMAND_FLAG_APPLY; + flags = GAME_COMMAND_FLAG_APPLY; gGameCommandErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - if (_trackDesignPlaceOperation == PTD_OPERATION_1) { - cost = game_do_command(mapCoord.x, 0 | rotation << 8, mapCoord.y, ((z / 16) & 0xFF) | (1 << 8), GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, -1, 0); + if (_trackDesignPlaceOperation == PTD_OPERATION_1) + { + cost = game_do_command(mapCoord.x, 0 | rotation << 8, mapCoord.y, ((z / 16) & 0xFF) | (1 << 8), + GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, -1, 0); } - else { + else + { if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) { flags = GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5; } else if (_trackDesignPlaceOperation == PTD_OPERATION_4) { - flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_GHOST; + flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | + GAME_COMMAND_FLAG_GHOST; } - cost = game_do_command(mapCoord.x, flags | rotation << 8, mapCoord.y, rideIndex | (1 << 8), GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, 0, 0); + cost = game_do_command(mapCoord.x, flags | rotation << 8, mapCoord.y, rideIndex | (1 << 8), + GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, 0, 0); } - if (cost != MONEY32_UNDEFINED){ + if (cost != MONEY32_UNDEFINED) + { _trackDesignPlaceStateEntranceExitPlaced = true; } break; @@ -1010,98 +1273,129 @@ static sint32 track_design_place_maze(rct_track_td6 *td6, sint16 x, sint16 y, si } else if (_trackDesignPlaceOperation == PTD_OPERATION_4) { - flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_GHOST; + flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | + GAME_COMMAND_FLAG_GHOST; } else if (_trackDesignPlaceOperation == PTD_OPERATION_1) { flags = 0; } - else + else { flags = GAME_COMMAND_FLAG_APPLY; } gGameCommandErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - cost = game_do_command(mapCoord.x, flags | (maze_entry & 0xFF) << 8, mapCoord.y, rideIndex | (maze_entry & 0xFF00), GAME_COMMAND_PLACE_MAZE_DESIGN, z, 0); + cost = game_do_command(mapCoord.x, flags | (maze_entry & 0xFF) << 8, mapCoord.y, + rideIndex | (maze_entry & 0xFF00), GAME_COMMAND_PLACE_MAZE_DESIGN, z, 0); break; } _trackDesignPlaceCost += cost; - if (cost == MONEY32_UNDEFINED){ + if (cost == MONEY32_UNDEFINED) + { _trackDesignPlaceCost = cost; return 0; } } - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) { - if (mapCoord.x < 0) continue; - if (mapCoord.y < 0) continue; - if (mapCoord.x >= 256 * 32) continue; - if (mapCoord.y >= 256 * 32) continue; + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z) + { + if (mapCoord.x < 0) + { + continue; + } + if (mapCoord.y < 0) + { + continue; + } + if (mapCoord.x >= 256 * 32) + { + continue; + } + if (mapCoord.y >= 256 * 32) + { + continue; + } - rct_map_element *map_element = map_get_surface_element_at(mapCoord.x / 32, mapCoord.y / 32); - sint16 map_height = map_element->base_height * 8; - if (map_element->properties.surface.slope & 0xF) { + rct_map_element * map_element = map_get_surface_element_at(mapCoord.x / 32, mapCoord.y / 32); + sint16 map_height = map_element->base_height * 8; + if (map_element->properties.surface.slope & 0xF) + { map_height += 16; - if (map_element->properties.surface.slope & 0x10) { + if (map_element->properties.surface.slope & 0x10) + { map_height += 16; } } - if (map_get_water_height(map_element) > 0) { + if (map_get_water_height(map_element) > 0) + { sint16 water_height = map_get_water_height(map_element); water_height *= 16; - if (water_height > map_height) { + if (water_height > map_height) + { map_height = water_height; } } sint16 temp_z = z + _trackDesignPlaceZ - map_height; - if (temp_z < 0) { + if (temp_z < 0) + { _trackDesignPlaceZ -= temp_z; } } } - if (_trackDesignPlaceOperation == PTD_OPERATION_CLEAR_OUTLINES) { + if (_trackDesignPlaceOperation == PTD_OPERATION_CLEAR_OUTLINES) + { game_do_command(0, 0x69, 0, rideIndex, GAME_COMMAND_DEMOLISH_RIDE, 0, 0); } - gTrackPreviewOrigin = (rct_xyz16) { x, y, z }; + gTrackPreviewOrigin.x = x; + gTrackPreviewOrigin.y = y; + gTrackPreviewOrigin.z = z; return 1; } -static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint16 z, uint8 rideIndex) +static bool track_design_place_ride(rct_track_td6 * td6, sint16 x, sint16 y, sint16 z, uint8 rideIndex) { - gTrackPreviewOrigin = (rct_xyz16) { x, y, z }; - if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES) { - gMapSelectionTiles->x = -1; + gTrackPreviewOrigin.x = x; + gTrackPreviewOrigin.y = y; + gTrackPreviewOrigin.z = z; + if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES) + { + gMapSelectionTiles->x = -1; gMapSelectArrowPosition.x = x; gMapSelectArrowPosition.y = y; gMapSelectArrowPosition.z = map_element_height(x, y) & 0xFFFF; gMapSelectArrowDirection = _currentTrackPieceDirection; } - _trackDesignPlaceZ = 0; + _trackDesignPlaceZ = 0; _trackDesignPlaceCost = 0; uint8 rotation = _currentTrackPieceDirection; // Track elements - rct_td6_track_element *track = td6->track_elements; - for (; track->type != 0xFF; track++) { + rct_td6_track_element * track = td6->track_elements; + for (; track->type != 0xFF; track++) + { uint8 trackType = track->type; - if (trackType == TRACK_ELEM_INVERTED_90_DEG_UP_TO_FLAT_QUARTER_LOOP) { + if (trackType == TRACK_ELEM_INVERTED_90_DEG_UP_TO_FLAT_QUARTER_LOOP) + { trackType = 0xFF; } track_design_update_max_min_coordinates(x, y, z); - switch (_trackDesignPlaceOperation) { + switch (_trackDesignPlaceOperation) + { case PTD_OPERATION_DRAW_OUTLINES: - for (const rct_preview_track* trackBlock = TrackBlocks[trackType]; trackBlock->index != 0xFF; trackBlock++) { - rct_xy16 tile = { x, y }; + for (const rct_preview_track * trackBlock = TrackBlocks[trackType]; trackBlock->index != 0xFF; trackBlock++) + { + rct_xy16 tile = {x, y}; map_offset_with_rotation(&tile.x, &tile.y, trackBlock->x, trackBlock->y, rotation); track_design_update_max_min_coordinates(tile.x, tile.y, z); track_design_add_selection_tile(tile.x, tile.y); @@ -1109,14 +1403,14 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint break; case PTD_OPERATION_CLEAR_OUTLINES: { - const rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; - const rct_preview_track *trackBlock = TrackBlocks[trackType]; - sint32 tempZ = z - trackCoordinates->z_begin + trackBlock->z; - uint8 flags = - GAME_COMMAND_FLAG_APPLY | - GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | - GAME_COMMAND_FLAG_5 | - GAME_COMMAND_FLAG_GHOST; + const rct_track_coordinates * trackCoordinates = &TrackCoordinates[trackType]; + const rct_preview_track * trackBlock = TrackBlocks[trackType]; + sint32 tempZ = z - trackCoordinates->z_begin + trackBlock->z; + uint8 flags = + GAME_COMMAND_FLAG_APPLY | + GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | + GAME_COMMAND_FLAG_5 | + GAME_COMMAND_FLAG_GHOST; ride_remove_track_piece(x, y, tempZ, rotation & 3, trackType, flags); break; } @@ -1125,15 +1419,15 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint case PTD_OPERATION_4: case PTD_OPERATION_GET_COST: { - const rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; + const rct_track_coordinates * trackCoordinates = &TrackCoordinates[trackType]; //di sint16 tempZ = z - trackCoordinates->z_begin; - uint32 edi = - ((track->flags & 0x0F) << 17) | - ((uint32)(track->flags & 0x0F) << 28) | - (((track->flags >> 4) & 0x03) << 24) | - (tempZ & 0xFFFF); + uint32 edi = + ((track->flags & 0x0F) << 17) | + ((uint32) (track->flags & 0x0F) << 28) | + (((track->flags >> 4) & 0x03) << 24) | + (tempZ & 0xFFFF); sint32 edx = _currentRideIndex | (trackType << 8); if (track->flags & TRACK_ELEMENT_FLAG_CHAIN_LIFT) @@ -1146,23 +1440,27 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint } uint8 flags = GAME_COMMAND_FLAG_APPLY; - if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) { + if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) + { flags |= GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED; flags |= GAME_COMMAND_FLAG_5; } - else if (_trackDesignPlaceOperation == PTD_OPERATION_4) { + else if (_trackDesignPlaceOperation == PTD_OPERATION_4) + { flags |= GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED; flags |= GAME_COMMAND_FLAG_5; flags |= GAME_COMMAND_FLAG_GHOST; } - else if (_trackDesignPlaceOperation == PTD_OPERATION_1) { + else if (_trackDesignPlaceOperation == PTD_OPERATION_1) + { flags = 0; } gGameCommandErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; money32 cost = game_do_command(x, flags | (rotation << 8), y, edx, GAME_COMMAND_PLACE_TRACK, edi, 0); _trackDesignPlaceCost += cost; - if (cost == MONEY32_UNDEFINED) { + if (cost == MONEY32_UNDEFINED) + { _trackDesignPlaceCost = cost; return false; } @@ -1170,33 +1468,40 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint } case PTD_OPERATION_GET_PLACE_Z: { - sint32 tempZ = z - TrackCoordinates[trackType].z_begin; - for (const rct_preview_track *trackBlock = TrackBlocks[trackType]; trackBlock->index != 0xFF; trackBlock++) { - rct_xy16 tile = { x, y }; + sint32 tempZ = z - TrackCoordinates[trackType].z_begin; + for (const rct_preview_track * trackBlock = TrackBlocks[trackType]; trackBlock->index != 0xFF; trackBlock++) + { + rct_xy16 tile = {x, y}; map_offset_with_rotation(&tile.x, &tile.y, trackBlock->x, trackBlock->y, rotation); - if (tile.x < 0 || tile.y < 0 || tile.x >= (256 * 32) || tile.y >= (256 * 32)) { + if (tile.x < 0 || tile.y < 0 || tile.x >= (256 * 32) || tile.y >= (256 * 32)) + { continue; } - rct_map_element *mapElement = map_get_surface_element_at(tile.x >> 5, tile.y >> 5); - if (mapElement == NULL) { + rct_map_element * mapElement = map_get_surface_element_at(tile.x >> 5, tile.y >> 5); + if (mapElement == NULL) + { return false; } sint32 height = mapElement->base_height * 8; - if (mapElement->properties.surface.slope & 0x0F) { + if (mapElement->properties.surface.slope & 0x0F) + { height += 16; - if (mapElement->properties.surface.slope & 0x10) { + if (mapElement->properties.surface.slope & 0x10) + { height += 16; } } uint8 water_height = map_get_water_height(mapElement) * 16; - if (water_height > 0 && water_height > height) { + if (water_height > 0 && water_height > height) + { height = water_height; } sint32 heightDifference = tempZ + _trackDesignPlaceZ + trackBlock->z - height; - if (heightDifference < 0) { + if (heightDifference < 0) + { _trackDesignPlaceZ -= heightDifference; } } @@ -1204,33 +1509,38 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint } } - const rct_track_coordinates *track_coordinates = &TrackCoordinates[trackType]; + const rct_track_coordinates * track_coordinates = &TrackCoordinates[trackType]; map_offset_with_rotation(&x, &y, track_coordinates->x, track_coordinates->y, rotation); z -= track_coordinates->z_begin; z += track_coordinates->z_end; rotation = (rotation + track_coordinates->rotation_end - track_coordinates->rotation_begin) & 3; - if (track_coordinates->rotation_end & (1 << 2)) { + if (track_coordinates->rotation_end & (1 << 2)) + { rotation |= (1 << 2); - } else { + } + else + { x += TileDirectionDelta[rotation].x; y += TileDirectionDelta[rotation].y; } } // Entrance elements - rct_td6_entrance_element *entrance = td6->entrance_elements; - for (; entrance->z != -1; entrance++) { + rct_td6_entrance_element * entrance = td6->entrance_elements; + for (; entrance->z != -1; entrance++) + { rotation = _currentTrackPieceDirection & 3; - x = entrance->x; - y = entrance->y; + x = entrance->x; + y = entrance->y; rotate_map_coordinates(&x, &y, rotation); x += gTrackPreviewOrigin.x; y += gTrackPreviewOrigin.y; track_design_update_max_min_coordinates(x, y, z); - switch (_trackDesignPlaceOperation) { + switch (_trackDesignPlaceOperation) + { case PTD_OPERATION_DRAW_OUTLINES: track_design_add_selection_tile(x, y); break; @@ -1241,25 +1551,34 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint { rotation = (rotation + entrance->direction) & 3; uint8 isExit = 0; - if (entrance->direction & (1 << 7)) { + if (entrance->direction & (1 << 7)) + { isExit = 1; } - if (_trackDesignPlaceOperation != PTD_OPERATION_1) { - rct_xy16 tile = { - x + TileDirectionDelta[rotation].x, - y + TileDirectionDelta[rotation].y + if (_trackDesignPlaceOperation != PTD_OPERATION_1) + { + rct_xy16 tile = { + (sint16) (x + TileDirectionDelta[rotation].x), + (sint16) (y + TileDirectionDelta[rotation].y) }; - rct_map_element* map_element = map_get_first_element_at(tile.x >> 5, tile.y >> 5); + rct_map_element * map_element = map_get_first_element_at(tile.x >> 5, tile.y >> 5); z = gTrackPreviewOrigin.z / 8; - z += (entrance->z == (sint8)(uint8)0x80) ? -1 : entrance->z; + z += (entrance->z == (sint8) (uint8) 0x80) ? -1 : entrance->z; - do { - if (map_element_get_type(map_element) != MAP_ELEMENT_TYPE_TRACK) continue; - if (map_element->base_height != z) continue; + do + { + if (map_element_get_type(map_element) != MAP_ELEMENT_TYPE_TRACK) + { + continue; + } + if (map_element->base_height != z) + { + continue; + } sint32 stationIndex = map_element_get_station(map_element); - uint8 bl = 1; + uint8 bl = 1; if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST) { bl = 41; @@ -1274,7 +1593,10 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint } gGameCommandErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - money32 cost = game_do_command(x, bl | (rotation << 8), y, rideIndex | (isExit << 8), GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, stationIndex, 0); + money32 cost = game_do_command(x, bl | (rotation << 8), y, + rideIndex | (isExit << 8), + GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, + stationIndex, 0); _trackDesignPlaceCost += cost; if (cost == MONEY32_UNDEFINED) @@ -1284,15 +1606,19 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint } _trackDesignPlaceStateEntranceExitPlaced = true; break; - } while (!map_element_is_last_for_tile(map_element++)); - } else { - z = (entrance->z == (sint8)(uint8)0x80) ? -1 : entrance->z; + } + while (!map_element_is_last_for_tile(map_element++)); + } + else + { + z = (entrance->z == (sint8) (uint8) 0x80) ? -1 : entrance->z; z *= 8; z += gTrackPreviewOrigin.z; z >>= 4; gGameCommandErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; - money32 cost = game_do_command(x, 0 | (rotation << 8), y, z | (isExit << 8), GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, -1, 0); + money32 cost = game_do_command(x, 0 | (rotation << 8), y, z | (isExit << 8), + GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, -1, 0); if (cost == MONEY32_UNDEFINED) { _trackDesignPlaceCost = cost; @@ -1330,47 +1656,58 @@ static bool track_design_place_ride(rct_track_td6 *td6, sint16 x, sint16 y, sint * bl == 6, Clear white outlined track. * rct2: 0x006D01B3 */ -sint32 place_virtual_track(rct_track_td6 *td6, uint8 ptdOperation, bool placeScenery, uint8 rideIndex, sint32 x, sint32 y, sint32 z) +sint32 place_virtual_track(rct_track_td6 * td6, uint8 ptdOperation, bool placeScenery, uint8 rideIndex, sint16 x, sint16 y, sint16 z) { // Previously byte_F4414E was cleared here - _trackDesignPlaceStatePlaceScenery = placeScenery; + _trackDesignPlaceStatePlaceScenery = placeScenery; _trackDesignPlaceStateEntranceExitPlaced = false; _trackDesignPlaceStateSceneryUnavailable = false; - _trackDesignPlaceStateHasScenery = false; + _trackDesignPlaceStateHasScenery = false; _trackDesignPlaceOperation = ptdOperation; - if (gTrackDesignSceneryToggle) { + if (gTrackDesignSceneryToggle) + { _trackDesignPlaceStatePlaceScenery = false; } - _currentRideIndex = rideIndex; + _currentRideIndex = rideIndex; - gTrackPreviewMin = (rct_xyz16){ x, y, z }; - gTrackPreviewMax = (rct_xyz16){ x, y, z }; + gTrackPreviewMin.x = x; + gTrackPreviewMin.y = y; + gTrackPreviewMin.z = z; + gTrackPreviewMax.x = x; + gTrackPreviewMax.y = y; + gTrackPreviewMax.z = z; _trackDesignPlaceSceneryZ = 0; uint8 track_place_success = 0; - if (td6->type == RIDE_TYPE_MAZE) { + if (td6->type == RIDE_TYPE_MAZE) + { track_place_success = track_design_place_maze(td6, x, y, z, rideIndex); - } else { + } + else + { track_place_success = track_design_place_ride(td6, x, y, z, rideIndex); } // Scenery elements - rct_td6_scenery_element *scenery = td6->scenery_elements; - if (track_place_success && scenery != NULL) { + rct_td6_scenery_element * scenery = td6->scenery_elements; + if (track_place_success && scenery != NULL) + { if (!track_design_place_scenery( scenery, rideIndex, gTrackPreviewOrigin.x, gTrackPreviewOrigin.y, gTrackPreviewOrigin.z - )) { + )) + { return _trackDesignPlaceCost; } } // 0x6D0FE6 - if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES) { + if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES) + { gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_CONSTRUCT; gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW; gMapSelectFlags &= ~MAP_SELECT_FLAG_GREEN; @@ -1392,25 +1729,29 @@ sint32 place_virtual_track(rct_track_td6 *td6, uint8 ptdOperation, bool placeSce * ebx = ride_id * cost = edi */ -static bool track_design_place_preview(rct_track_td6 *td6, money32 *cost, uint8 *rideId, uint8 *flags) +static bool track_design_place_preview(rct_track_td6 * td6, money32 * cost, uint8 * rideId, uint8 * flags) { - *flags = 0; + *flags = 0; uint8 entry_type, entry_index; - if (!find_object_in_entry_group(&td6->vehicle_object, &entry_type, &entry_index)) { + if (!find_object_in_entry_group(&td6->vehicle_object, &entry_type, &entry_index)) + { entry_index = RIDE_ENTRY_INDEX_NULL; } uint8 rideIndex; uint8 colour; uint8 rideCreateFlags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5; - if (ride_create_command(td6->type, entry_index, rideCreateFlags, &rideIndex, &colour) == MONEY32_UNDEFINED) { + if (ride_create_command(td6->type, entry_index, rideCreateFlags, &rideIndex, &colour) == MONEY32_UNDEFINED) + { return false; } - rct_ride *ride = get_ride(rideIndex); - rct_string_id new_ride_name = user_string_allocate(USER_STRING_HIGH_ID_NUMBER | USER_STRING_DUPLICATION_PERMITTED, ""); - if (new_ride_name != 0) { + rct_ride * ride = get_ride(rideIndex); + rct_string_id new_ride_name = user_string_allocate(USER_STRING_HIGH_ID_NUMBER | USER_STRING_DUPLICATION_PERMITTED, + ""); + if (new_ride_name != 0) + { rct_string_id old_name = ride->name; ride->name = new_ride_name; user_string_free(old_name); @@ -1418,14 +1759,15 @@ static bool track_design_place_preview(rct_track_td6 *td6, money32 *cost, uint8 ride->entrance_style = td6->entrance_style; - for (sint32 i = 0; i < RCT12_NUM_COLOUR_SCHEMES; i++) { - ride->track_colour_main[i] = td6->track_spine_colour[i]; + for (sint32 i = 0; i < RCT12_NUM_COLOUR_SCHEMES; i++) + { + ride->track_colour_main[i] = td6->track_spine_colour[i]; ride->track_colour_additional[i] = td6->track_rail_colour[i]; - ride->track_colour_supports[i] = td6->track_support_colour[i]; + ride->track_colour_supports[i] = td6->track_support_colour[i]; } byte_9D8150 = true; - uint8 backup_rotation = _currentTrackPieceDirection; + uint8 backup_rotation = _currentTrackPieceDirection; uint32 backup_park_flags = gParkFlags; gParkFlags &= ~PARK_FLAGS_FORBID_HIGH_CONSTRUCTION; sint32 mapSize = gMapSize << 4; @@ -1433,14 +1775,16 @@ static bool track_design_place_preview(rct_track_td6 *td6, money32 *cost, uint8 _currentTrackPieceDirection = 0; sint32 z = place_virtual_track(td6, PTD_OPERATION_GET_PLACE_Z, true, 0, mapSize, mapSize, 16); - if (_trackDesignPlaceStateHasScenery) { + if (_trackDesignPlaceStateHasScenery) + { *flags |= TRACK_DESIGN_FLAG_HAS_SCENERY; } z += 16 - _trackDesignPlaceSceneryZ; bool placeScenery = true; - if (_trackDesignPlaceStateSceneryUnavailable) { + if (_trackDesignPlaceStateSceneryUnavailable) + { placeScenery = false; *flags |= TRACK_DESIGN_FLAG_SCENERY_UNAVAILABLE; } @@ -1448,8 +1792,10 @@ static bool track_design_place_preview(rct_track_td6 *td6, money32 *cost, uint8 money32 resultCost = place_virtual_track(td6, PTD_OPERATION_GET_COST, placeScenery, rideIndex, mapSize, mapSize, z); gParkFlags = backup_park_flags; - if (resultCost != MONEY32_UNDEFINED) { - if (!find_object_in_entry_group(&td6->vehicle_object, &entry_type, &entry_index)) { + if (resultCost != MONEY32_UNDEFINED) + { + if (!find_object_in_entry_group(&td6->vehicle_object, &entry_type, &entry_index)) + { *flags |= TRACK_DESIGN_FLAG_VEHICLE_UNAVAILABLE; } else if (!ride_entry_is_invented(entry_index) && !gCheatsIgnoreResearchStatus) @@ -1458,11 +1804,13 @@ static bool track_design_place_preview(rct_track_td6 *td6, money32 *cost, uint8 } _currentTrackPieceDirection = backup_rotation; - byte_9D8150 = false; - *cost = resultCost; + byte_9D8150 = false; + *cost = resultCost; *rideId = rideIndex; return true; - } else { + } + else + { _currentTrackPieceDirection = backup_rotation; user_string_free(ride->name); ride->type = RIDE_TYPE_NULL; @@ -1471,7 +1819,7 @@ static bool track_design_place_preview(rct_track_td6 *td6, money32 *cost, uint8 } } -static money32 place_track_design(sint16 x, sint16 y, sint16 z, uint8 flags, uint8 *outRideIndex) +static money32 place_track_design(sint16 x, sint16 y, sint16 z, uint8 flags, uint8 * outRideIndex) { *outRideIndex = 255; @@ -1479,24 +1827,28 @@ static money32 place_track_design(sint16 x, sint16 y, sint16 z, uint8 flags, uin gCommandPosition.y = y + 16; gCommandPosition.z = z; - if (!(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED)) { - if (game_is_paused() && !gCheatsBuildInPauseMode) { + if (!(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED)) + { + if (game_is_paused() && !gCheatsBuildInPauseMode) + { gGameCommandErrorText = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED; return MONEY32_UNDEFINED; } } - rct_track_td6 *td6 = gActiveTrackDesign; - if (td6 == NULL) { + rct_track_td6 * td6 = gActiveTrackDesign; + if (td6 == NULL) + { return MONEY32_UNDEFINED; } - rct_object_entry *rideEntryObject = &td6->vehicle_object; + rct_object_entry * rideEntryObject = &td6->vehicle_object; uint8 entryType, entryIndex; - if (!find_object_in_entry_group(rideEntryObject, &entryType, &entryIndex)) { + if (!find_object_in_entry_group(rideEntryObject, &entryType, &entryIndex)) + { entryIndex = 0xFF; } - // Force a fallback if the entry is not invented yet a td6 of it is selected, which can happen in select-by-track-type mode. + // Force a fallback if the entry is not invented yet a td6 of it is selected, which can happen in select-by-track-type mode. else if (!ride_entry_is_invented(entryIndex) && !gCheatsIgnoreResearchStatus) { entryIndex = 0xFF; @@ -1508,12 +1860,12 @@ static money32 place_track_design(sint16 x, sint16 y, sint16 z, uint8 flags, uin const ObjectRepositoryItem * ori = object_repository_find_object_by_name(rideEntryObject->name); if (ori != NULL) { - uint8 rideGroupIndex = ori->RideGroupIndex; - ride_group * td6RideGroup = ride_group_find(td6->type, rideGroupIndex); + uint8 rideGroupIndex = ori->RideGroupIndex; + ride_group * td6RideGroup = ride_group_find(td6->type, rideGroupIndex); rct_ride_entry * ire; - uint8 *availableRideEntries = get_ride_entry_indices_for_ride_type(td6->type); - for (uint8 *rei = availableRideEntries; *rei != RIDE_ENTRY_INDEX_NULL; rei++) + uint8 * availableRideEntries = get_ride_entry_indices_for_ride_type(td6->type); + for (uint8 * rei = availableRideEntries; *rei != RIDE_ENTRY_INDEX_NULL; rei++) { ire = get_ride_entry(*rei); @@ -1532,67 +1884,90 @@ static money32 place_track_design(sint16 x, sint16 y, sint16 z, uint8 flags, uin } } - uint8 rideIndex; - uint8 rideColour; - money32 createRideResult = ride_create_command(td6->type, entryIndex, GAME_COMMAND_FLAG_APPLY, &rideIndex, &rideColour); - if (createRideResult == MONEY32_UNDEFINED) { - gGameCommandErrorTitle = STR_CANT_CREATE_NEW_RIDE_ATTRACTION; + uint8 rideIndex; + uint8 rideColour; + money32 createRideResult = ride_create_command(td6->type, entryIndex, GAME_COMMAND_FLAG_APPLY, &rideIndex, + &rideColour); + if (createRideResult == MONEY32_UNDEFINED) + { + gGameCommandErrorTitle = STR_CANT_CREATE_NEW_RIDE_ATTRACTION; gCommandExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION; return MONEY32_UNDEFINED; } - rct_ride* ride = get_ride(rideIndex); - if (ride->type == RIDE_TYPE_NULL) { + rct_ride * ride = get_ride(rideIndex); + if (ride->type == RIDE_TYPE_NULL) + { log_warning("Invalid game command for track placement, ride id = %d", rideIndex); return MONEY32_UNDEFINED; } money32 cost = 0; - if (!(flags & GAME_COMMAND_FLAG_APPLY)) { + if (!(flags & GAME_COMMAND_FLAG_APPLY)) + { _trackDesignDontPlaceScenery = false; - cost = place_virtual_track(td6, PTD_OPERATION_1, true, rideIndex, x, y, z); - if (_trackDesignPlaceStateSceneryUnavailable) { + cost = place_virtual_track(td6, PTD_OPERATION_1, true, rideIndex, x, y, z); + if (_trackDesignPlaceStateSceneryUnavailable) + { _trackDesignDontPlaceScenery = true; - cost = place_virtual_track(td6, PTD_OPERATION_1, false, rideIndex, x, y, z); + cost = place_virtual_track(td6, PTD_OPERATION_1, false, rideIndex, x, y, z); } - } else { + } + else + { uint8 operation; - if (flags & GAME_COMMAND_FLAG_GHOST) { + if (flags & GAME_COMMAND_FLAG_GHOST) + { operation = PTD_OPERATION_4; - } else { + } + else + { operation = PTD_OPERATION_2; } cost = place_virtual_track(td6, operation, !_trackDesignDontPlaceScenery, rideIndex, x, y, z); } - if (cost == MONEY32_UNDEFINED || !(flags & GAME_COMMAND_FLAG_APPLY)) { + if (cost == MONEY32_UNDEFINED || !(flags & GAME_COMMAND_FLAG_APPLY)) + { rct_string_id error_reason = gGameCommandErrorText; game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, rideIndex, GAME_COMMAND_DEMOLISH_RIDE, 0, 0); - gGameCommandErrorText = error_reason; + gGameCommandErrorText = error_reason; gCommandExpenditureType = RCT_EXPENDITURE_TYPE_RIDE_CONSTRUCTION; *outRideIndex = rideIndex; return cost; } - if (entryIndex != 0xFF) { - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (2 << 8), 0, rideIndex | (entryIndex << 8), GAME_COMMAND_SET_RIDE_VEHICLES, 0, 0); + if (entryIndex != 0xFF) + { + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (2 << 8), 0, rideIndex | (entryIndex << 8), + GAME_COMMAND_SET_RIDE_VEHICLES, 0, 0); } - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->ride_mode << 8), 0, rideIndex | (0 << 8), GAME_COMMAND_SET_RIDE_SETTING, 0, 0); - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (0 << 8), 0, rideIndex | (td6->number_of_trains << 8), GAME_COMMAND_SET_RIDE_VEHICLES, 0, 0); - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (1 << 8), 0, rideIndex | (td6->number_of_cars_per_train << 8), GAME_COMMAND_SET_RIDE_VEHICLES, 0, 0); - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->depart_flags << 8), 0, rideIndex | (1 << 8), GAME_COMMAND_SET_RIDE_SETTING, 0, 0); - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->min_waiting_time << 8), 0, rideIndex | (2 << 8), GAME_COMMAND_SET_RIDE_SETTING, 0, 0); - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->max_waiting_time << 8), 0, rideIndex | (3 << 8), GAME_COMMAND_SET_RIDE_SETTING, 0, 0); - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->operation_setting << 8), 0, rideIndex | (4 << 8), GAME_COMMAND_SET_RIDE_SETTING, 0, 0); - game_do_command(0, GAME_COMMAND_FLAG_APPLY | ((td6->lift_hill_speed_num_circuits & 0x1F) << 8), 0, rideIndex | (8 << 8), GAME_COMMAND_SET_RIDE_SETTING, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->ride_mode << 8), 0, rideIndex | (0 << 8), + GAME_COMMAND_SET_RIDE_SETTING, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (0 << 8), 0, rideIndex | (td6->number_of_trains << 8), + GAME_COMMAND_SET_RIDE_VEHICLES, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (1 << 8), 0, rideIndex | (td6->number_of_cars_per_train << 8), + GAME_COMMAND_SET_RIDE_VEHICLES, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->depart_flags << 8), 0, rideIndex | (1 << 8), + GAME_COMMAND_SET_RIDE_SETTING, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->min_waiting_time << 8), 0, rideIndex | (2 << 8), + GAME_COMMAND_SET_RIDE_SETTING, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->max_waiting_time << 8), 0, rideIndex | (3 << 8), + GAME_COMMAND_SET_RIDE_SETTING, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (td6->operation_setting << 8), 0, rideIndex | (4 << 8), + GAME_COMMAND_SET_RIDE_SETTING, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | ((td6->lift_hill_speed_num_circuits & 0x1F) << 8), 0, + rideIndex | (8 << 8), GAME_COMMAND_SET_RIDE_SETTING, 0, 0); - uint8 num_circuits = td6->lift_hill_speed_num_circuits >> 5; - if (num_circuits == 0) { + uint8 num_circuits = td6->lift_hill_speed_num_circuits >> 5; + if (num_circuits == 0) + { num_circuits = 1; } - game_do_command(0, GAME_COMMAND_FLAG_APPLY | (num_circuits << 8), 0, rideIndex | (9 << 8), GAME_COMMAND_SET_RIDE_SETTING, 0, 0); + game_do_command(0, GAME_COMMAND_FLAG_APPLY | (num_circuits << 8), 0, rideIndex | (9 << 8), + GAME_COMMAND_SET_RIDE_SETTING, 0, 0); ride_set_to_default_inspection_interval(rideIndex); ride->lifecycle_flags |= RIDE_LIFECYCLE_NOT_CUSTOM_DESIGN; @@ -1600,13 +1975,15 @@ static money32 place_track_design(sint16 x, sint16 y, sint16 z, uint8 flags, uin ride->entrance_style = td6->entrance_style; - for (sint32 i = 0; i < RCT12_NUM_COLOUR_SCHEMES; i++) { - ride->track_colour_main[i] = td6->track_spine_colour[i]; + for (sint32 i = 0; i < RCT12_NUM_COLOUR_SCHEMES; i++) + { + ride->track_colour_main[i] = td6->track_spine_colour[i]; ride->track_colour_additional[i] = td6->track_rail_colour[i]; - ride->track_colour_supports[i] = td6->track_support_colour[i]; + ride->track_colour_supports[i] = td6->track_support_colour[i]; } - for (sint32 i = 0; i < 32; i++) { + for (sint32 i = 0; i < 32; i++) + { ride->vehicle_colours[i].body_colour = td6->vehicle_colours[i].body_colour; ride->vehicle_colours[i].trim_colour = td6->vehicle_colours[i].trim_colour; ride->vehicle_colours_extended[i] = td6->vehicle_additional_colour[i]; @@ -1625,42 +2002,53 @@ static money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, gCommandPosition.x = x + 8; gCommandPosition.y = y + 8; gCommandPosition.z = z; - if (!map_check_free_elements_and_reorganise(1)) { + if (!map_check_free_elements_and_reorganise(1)) + { return MONEY32_UNDEFINED; } - if ((z & 15) != 0) { + if ((z & 15) != 0) + { return MONEY32_UNDEFINED; } - if (!(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED)) { - if (game_is_paused() && !gCheatsBuildInPauseMode) { + if (!(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED)) + { + if (game_is_paused() && !gCheatsBuildInPauseMode) + { gGameCommandErrorText = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED; return MONEY32_UNDEFINED; } } - if (flags & GAME_COMMAND_FLAG_APPLY) { - if (!(flags & GAME_COMMAND_FLAG_GHOST)) { + if (flags & GAME_COMMAND_FLAG_APPLY) + { + if (!(flags & GAME_COMMAND_FLAG_GHOST)) + { footpath_remove_litter(x, y, z); wall_remove_at(floor2(x, 32), floor2(y, 32), z, z + 32); } } - if (!gCheatsSandboxMode) { - if (!map_is_location_owned(floor2(x, 32), floor2(y, 32), z)) { + if (!gCheatsSandboxMode) + { + if (!map_is_location_owned(floor2(x, 32), floor2(y, 32), z)) + { return MONEY32_UNDEFINED; } } // Check support height - if (!gCheatsDisableSupportLimits) { - rct_map_element *mapElement = map_get_surface_element_at(x >> 5, y >> 5); - uint8 supportZ = (z + 32) >> 3; - if (supportZ > mapElement->base_height) { - uint8 supportHeight = (supportZ - mapElement->base_height) / 2; + if (!gCheatsDisableSupportLimits) + { + rct_map_element * mapElement = map_get_surface_element_at(x >> 5, y >> 5); + uint8 supportZ = (z + 32) >> 3; + if (supportZ > mapElement->base_height) + { + uint8 supportHeight = (supportZ - mapElement->base_height) / 2; uint8 maxSupportHeight = RideData5[RIDE_TYPE_MAZE].max_height; - if (supportHeight > maxSupportHeight) { + if (supportHeight > maxSupportHeight) + { gGameCommandErrorText = STR_TOO_HIGH_FOR_SUPPORTS; return MONEY32_UNDEFINED; } @@ -1669,40 +2057,47 @@ static money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, money32 cost = 0; // Clearance checks - if (!gCheatsDisableClearanceChecks) { - sint32 fx = floor2(x, 32); - sint32 fy = floor2(y, 32); + if (!gCheatsDisableClearanceChecks) + { + sint32 fx = floor2(x, 32); + sint32 fy = floor2(y, 32); sint32 fz0 = z >> 3; sint32 fz1 = fz0 + 4; - if (!map_can_construct_with_clear_at(fx, fy, fz0, fz1, &map_place_non_scenery_clear_func, 15, flags, &cost)) { + if (!map_can_construct_with_clear_at(fx, fy, fz0, fz1, &map_place_non_scenery_clear_func, 15, flags, &cost)) + { return MONEY32_UNDEFINED; } uint8 elctgaw = gMapGroundFlags; - if (elctgaw & ELEMENT_IS_UNDERWATER) { + if (elctgaw & ELEMENT_IS_UNDERWATER) + { gGameCommandErrorText = STR_RIDE_CANT_BUILD_THIS_UNDERWATER; return MONEY32_UNDEFINED; } - if (elctgaw & ELEMENT_IS_UNDERGROUND) { + if (elctgaw & ELEMENT_IS_UNDERGROUND) + { gGameCommandErrorText = STR_CAN_ONLY_BUILD_THIS_ABOVE_GROUND; return MONEY32_UNDEFINED; } } - rct_ride *ride = get_ride(rideIndex); + rct_ride * ride = get_ride(rideIndex); // Calculate price money32 price = 0; - if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) { + if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) + { price = RideTrackCosts[ride->type].track_price * TrackPricing[TRACK_ELEM_MAZE]; price = (price >> 17) * 10; } cost += price; - if (flags & GAME_COMMAND_FLAG_APPLY) { - if (gGameCommandNestLevel == 1 && !(flags & GAME_COMMAND_FLAG_GHOST)) { + if (flags & GAME_COMMAND_FLAG_APPLY) + { + if (gGameCommandNestLevel == 1 && !(flags & GAME_COMMAND_FLAG_GHOST)) + { rct_xyz16 coord; coord.x = x + 8; coord.y = y + 8; @@ -1711,16 +2106,17 @@ static money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, } // Place track element - sint32 fx = floor2(x, 32); - sint32 fy = floor2(y, 32); - sint32 fz = z >> 3; - rct_map_element *mapElement = map_element_insert(fx >> 5, fy >> 5, fz, 15); - mapElement->clearance_height = fz + 4; - mapElement->type = MAP_ELEMENT_TYPE_TRACK; - mapElement->properties.track.type = TRACK_ELEM_MAZE; + sint32 fx = floor2(x, 32); + sint32 fy = floor2(y, 32); + sint32 fz = z >> 3; + rct_map_element * mapElement = map_element_insert(fx >> 5, fy >> 5, fz, 15); + mapElement->clearance_height = fz + 4; + mapElement->type = MAP_ELEMENT_TYPE_TRACK; + mapElement->properties.track.type = TRACK_ELEM_MAZE; mapElement->properties.track.ride_index = rideIndex; mapElement->properties.track.maze_entry = mazeEntry; - if (flags & GAME_COMMAND_FLAG_GHOST) { + if (flags & GAME_COMMAND_FLAG_GHOST) + { mapElement->flags |= MAP_ELEMENT_FLAG_GHOST; } @@ -1729,7 +2125,8 @@ static money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, ride->maze_tiles++; ride->station_heights[0] = mapElement->base_height; ride->station_starts[0].xy = 0; - if (ride->maze_tiles == 1) { + if (ride->maze_tiles == 1) + { ride->overall_view.x = fx / 32; ride->overall_view.y = fy / 32; } @@ -1742,13 +2139,14 @@ static money32 place_maze_design(uint8 flags, uint8 rideIndex, uint16 mazeEntry, * * rct2: 0x006D13FE */ -void game_command_place_track_design(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +void game_command_place_track_design(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, + sint32 * ebp) { - sint16 x = *eax & 0xFFFF; - sint16 y = *ecx & 0xFFFF; - sint16 z = *edi & 0xFFFF; - uint8 flags = *ebx; - uint8 rideIndex; + sint16 x = *eax & 0xFFFF; + sint16 y = *ecx & 0xFFFF; + sint16 z = *edi & 0xFFFF; + uint8 flags = *ebx; + uint8 rideIndex; *ebx = place_track_design(x, y, z, flags, &rideIndex); *edi = rideIndex; } @@ -1757,7 +2155,8 @@ void game_command_place_track_design(sint32* eax, sint32* ebx, sint32* ecx, sint * * rct2: 0x006CDEE4 */ -void game_command_place_maze_design(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +void game_command_place_maze_design(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, + sint32 * ebp) { *ebx = place_maze_design( *ebx & 0xFF, @@ -1775,28 +2174,31 @@ void game_command_place_maze_design(sint32* eax, sint32* ebx, sint32* ecx, sint3 * * rct2: 0x006D1EF0 */ -void track_design_draw_preview(rct_track_td6 *td6, uint8 *pixels) +void track_design_draw_preview(rct_track_td6 * td6, uint8 * pixels) { // Make a copy of the map - map_backup *mapBackup = track_design_preview_backup_map(); - if (mapBackup == NULL) { + map_backup * mapBackup = track_design_preview_backup_map(); + if (mapBackup == NULL) + { return; } track_design_preview_clear_map(); - if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) { + if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) + { track_design_load_scenery_objects(td6); } money32 cost; - uint8 rideIndex; - uint8 flags; - if (!track_design_place_preview(td6, &cost, &rideIndex, &flags)) { + uint8 rideIndex; + uint8 flags; + if (!track_design_place_preview(td6, &cost, &rideIndex, &flags)) + { memset(pixels, 0, TRACK_PREVIEW_IMAGE_SIZE * 4); track_design_preview_restore_map(mapBackup); return; } - td6->cost = cost; + td6->cost = cost; td6->track_flags = flags & 7; rct_xyz32 centre; @@ -1810,15 +2212,18 @@ void track_design_draw_preview(rct_track_td6 *td6, uint8 *pixels) sint32 zoom_level = 1; - if (size_x < size_y) { + if (size_x < size_y) + { size_x = size_y; } - if (size_x > 1000 || size_z > 280) { + if (size_x > 1000 || size_z > 280) + { zoom_level = 2; } - if (size_x > 1600 || size_z > 1000) { + if (size_x > 1600 || size_z > 1000) + { zoom_level = 3; } @@ -1826,35 +2231,36 @@ void track_design_draw_preview(rct_track_td6 *td6, uint8 *pixels) size_y = 217 << zoom_level; rct_viewport view; - view.width = 370; - view.height = 217; - view.view_width = size_x; + view.width = 370; + view.height = 217; + view.view_width = size_x; view.view_height = size_y; - view.x = 0; - view.y = 0; - view.zoom = zoom_level; - view.flags = VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_INVISIBLE_SPRITES; + view.x = 0; + view.y = 0; + view.zoom = zoom_level; + view.flags = VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_INVISIBLE_SPRITES; rct_drawpixelinfo dpi; dpi.zoom_level = zoom_level; - dpi.x = 0; - dpi.y = 0; - dpi.width = 370; - dpi.height = 217; - dpi.pitch = 0; - dpi.bits = pixels; + dpi.x = 0; + dpi.y = 0; + dpi.width = 370; + dpi.height = 217; + dpi.pitch = 0; + dpi.bits = pixels; - rct_xy32 offset = { size_x / 2, size_y / 2 }; - for (sint32 i = 0; i < 4; i++) { + rct_xy32 offset = {size_x / 2, size_y / 2}; + for (sint32 i = 0; i < 4; i++) + { gCurrentRotation = i; rct_xy32 pos2d = translate_3d_to_2d_with_z(i, centre); pos2d.x -= offset.x; pos2d.y -= offset.y; - sint32 left = pos2d.x; - sint32 top = pos2d.y; - sint32 right = left + size_x; + sint32 left = pos2d.x; + sint32 top = pos2d.y; + sint32 right = left + size_x; sint32 bottom = top + size_y; view.view_x = left; @@ -1873,10 +2279,11 @@ void track_design_draw_preview(rct_track_td6 *td6, uint8 *pixels) * design preview. * rct2: 0x006D1C68 */ -static map_backup *track_design_preview_backup_map() +static map_backup * track_design_preview_backup_map() { - map_backup *backup = malloc(sizeof(map_backup)); - if (backup != NULL) { + map_backup * backup = (map_backup *) malloc(sizeof(map_backup)); + if (backup != NULL) + { memcpy( backup->map_elements, gMapElements, @@ -1887,11 +2294,11 @@ static map_backup *track_design_preview_backup_map() gMapElementTilePointers, sizeof(backup->tile_pointers) ); - backup->next_free_map_element = gNextFreeMapElement; - backup->map_size_units = gMapSizeUnits; + backup->next_free_map_element = gNextFreeMapElement; + backup->map_size_units = gMapSizeUnits; backup->map_size_units_minus_2 = gMapSizeMinus2; - backup->map_size = gMapSize; - backup->current_rotation = get_current_rotation(); + backup->map_size = gMapSize; + backup->current_rotation = get_current_rotation(); } return backup; } @@ -1900,7 +2307,7 @@ static map_backup *track_design_preview_backup_map() * Restores the map from a backup. * rct2: 0x006D2378 */ -static void track_design_preview_restore_map(map_backup *backup) +static void track_design_preview_restore_map(map_backup * backup) { memcpy( gMapElements, @@ -1913,10 +2320,10 @@ static void track_design_preview_restore_map(map_backup *backup) sizeof(backup->tile_pointers) ); gNextFreeMapElement = backup->next_free_map_element; - gMapSizeUnits = backup->map_size_units; - gMapSizeMinus2 = backup->map_size_units_minus_2; - gMapSize = backup->map_size; - gCurrentRotation = backup->current_rotation; + gMapSizeUnits = backup->map_size_units; + gMapSizeMinus2 = backup->map_size_units_minus_2; + gMapSize = backup->map_size; + gCurrentRotation = backup->current_rotation; free(backup); } @@ -1929,20 +2336,21 @@ static void track_design_preview_clear_map() { // These values were previously allocated in backup map but // it seems more fitting to place in this function - gMapSizeUnits = 255 * 32; + gMapSizeUnits = 255 * 32; gMapSizeMinus2 = (264 * 32) - 2; - gMapSize = 256; + gMapSize = 256; - for (sint32 i = 0; i < MAX_TILE_MAP_ELEMENT_POINTERS; i++) { - rct_map_element* map_element = &gMapElements[i]; - map_element->type = MAP_ELEMENT_TYPE_SURFACE; - map_element->flags = MAP_ELEMENT_FLAG_LAST_TILE; - map_element->base_height = 2; - map_element->clearance_height = 0; - map_element->properties.surface.slope = 0; - map_element->properties.surface.terrain = 0; + for (sint32 i = 0; i < MAX_TILE_MAP_ELEMENT_POINTERS; i++) + { + rct_map_element * map_element = &gMapElements[i]; + map_element->type = MAP_ELEMENT_TYPE_SURFACE; + map_element->flags = MAP_ELEMENT_FLAG_LAST_TILE; + map_element->base_height = 2; + map_element->clearance_height = 0; + map_element->properties.surface.slope = 0; + map_element->properties.surface.terrain = 0; map_element->properties.surface.grass_length = GRASS_LENGTH_CLEAR_0; - map_element->properties.surface.ownership = OWNERSHIP_OWNED; + map_element->properties.surface.ownership = OWNERSHIP_OWNED; } map_update_tile_pointers(); } diff --git a/src/openrct2/ride/track_design.h b/src/openrct2/ride/TrackDesign.h similarity index 99% rename from src/openrct2/ride/track_design.h rename to src/openrct2/ride/TrackDesign.h index 8bcabf411f..b803d5e80d 100644 --- a/src/openrct2/ride/track_design.h +++ b/src/openrct2/ride/TrackDesign.h @@ -213,7 +213,7 @@ void track_design_dispose(rct_track_td6 *td6); void track_design_mirror(rct_track_td6 *td6); -sint32 place_virtual_track(rct_track_td6 *td6, uint8 ptdOperation, bool placeScenery, uint8 rideIndex, sint32 x, sint32 y, sint32 z); +sint32 place_virtual_track(rct_track_td6 *td6, uint8 ptdOperation, bool placeScenery, uint8 rideIndex, sint16 x, sint16 y, sint16 z); void game_command_place_track_design(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); void game_command_place_maze_design(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); diff --git a/src/openrct2/ride/TrackDesignRepository.cpp b/src/openrct2/ride/TrackDesignRepository.cpp index 0ea0433bb0..f701a1421e 100644 --- a/src/openrct2/ride/TrackDesignRepository.cpp +++ b/src/openrct2/ride/TrackDesignRepository.cpp @@ -33,7 +33,7 @@ extern "C" { - #include "track_design.h" + #include "TrackDesign.h" } using namespace OpenRCT2; diff --git a/src/openrct2/ride/track_design_save.c b/src/openrct2/ride/track_design_save.c index ef38fcb778..898d583bb8 100644 --- a/src/openrct2/ride/track_design_save.c +++ b/src/openrct2/ride/track_design_save.c @@ -27,7 +27,7 @@ #include "ride_data.h" #include "track.h" #include "track_data.h" -#include "track_design.h" +#include "TrackDesign.h" #include "TrackDesignRepository.h" #define TRACK_MAX_SAVED_MAP_ELEMENTS 1500 diff --git a/src/openrct2/world/SmallScenery.cpp b/src/openrct2/world/SmallScenery.cpp index c6cf8ae213..81f490cceb 100644 --- a/src/openrct2/world/SmallScenery.cpp +++ b/src/openrct2/world/SmallScenery.cpp @@ -24,7 +24,7 @@ extern "C" #include "map.h" #include "park.h" #include "../cheats.h" - #include "../ride/track_design.h" + #include "../ride/TrackDesign.h" } static money32 SmallSceneryRemove(sint16 x, sint16 y, uint8 baseHeight, uint8 quadrant, uint8 sceneryType, uint8 flags)