1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

attempt to pass TD6 more for preview

Currently breaks preview.
Construction kind of works but has bad settings and crashes for some ride types
This commit is contained in:
Ted John
2016-04-28 00:19:22 +01:00
parent b2cc98da91
commit 68520765fc
4 changed files with 88 additions and 66 deletions

View File

@@ -240,6 +240,7 @@ const rct_trackdefinition gTrackDefinitions_INCORRECT[] = {
#define TRACK_MAX_SAVED_MAP_ELEMENTS 1500
rct_map_element **gTrackSavedMapElements = (rct_map_element**)0x00F63674;
rct_track_td6 *gActiveTrackDesign;
static bool track_save_should_select_scenery_around(int rideIndex, rct_map_element *mapElement);
static void track_save_select_nearby_scenery_for_tile(int rideIndex, int cx, int cy);
@@ -1932,7 +1933,7 @@ int track_place_ride(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint8** trac
* bl == 6, Clear white outlined track.
* rct2: 0x006D01B3
*/
int sub_6D01B3(uint8 bl, uint8 rideIndex, int x, int y, int z)
int sub_6D01B3(rct_track_td6 *td6, uint8 bl, uint8 rideIndex, int x, int y, int z)
{
RCT2_GLOBAL(0x00F4414E, uint8) = bl & 0x80;
RCT2_GLOBAL(0x00F440D4, uint8) = bl & 0x7F;
@@ -1951,10 +1952,9 @@ int sub_6D01B3(uint8 bl, uint8 rideIndex, int x, int y, int z)
RCT2_GLOBAL(0x00F44129, uint16) = 0;
uint8* track_elements = RCT2_ADDRESS(0x009D821B, uint8);
rct_track_td6* track_design = RCT2_ADDRESS(0x009D8178, rct_track_td6);
uint8 track_place_success = 0;
if (track_design->type == RIDE_TYPE_MAZE){
if (td6->type == RIDE_TYPE_MAZE){
track_place_success = track_place_maze(x, y, z, rideIndex, &track_elements);
}
else{
@@ -1992,17 +1992,17 @@ int sub_6D01B3(uint8 bl, uint8 rideIndex, int x, int y, int z)
* ebx = ride_id
* cost = edi
*/
int sub_6D2189(int* cost, uint8* ride_id){
int sub_6D2189(rct_track_td6 *td6, int* cost, uint8* ride_id)
{
RCT2_GLOBAL(0xF44151, uint8) = 0;
rct_track_td6* track_design = RCT2_ADDRESS(0x009D8178, rct_track_td6);
uint8 entry_type, entry_index;
if (!find_object_in_entry_group(&track_design->vehicle_object, &entry_type, &entry_index))
if (!find_object_in_entry_group(&td6->vehicle_object, &entry_type, &entry_index))
entry_index = 0xFF;
int eax = 0, ebx, ecx = 0, edx, esi, edi = 0, ebp = 0;
ebx = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5;
edx = track_design->type | (entry_index << 8);
edx = td6->type | (entry_index << 8);
esi = GAME_COMMAND_CREATE_RIDE;
if (MONEY32_UNDEFINED == game_do_command_p(GAME_COMMAND_CREATE_RIDE, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp)) return 1;
@@ -2021,21 +2021,21 @@ int sub_6D2189(int* cost, uint8* ride_id){
user_string_free(old_name);
}
uint8 version = track_design->version_and_colour_scheme >> 2;
uint8 version = td6->version_and_colour_scheme >> 2;
if (version == 2){
ride->entrance_style = track_design->entrance_style;
ride->entrance_style = td6->entrance_style;
}
if (version != 0){
memcpy(&ride->track_colour_main, &track_design->track_spine_colour, 4);
memcpy(&ride->track_colour_additional, &track_design->track_rail_colour, 4);
memcpy(&ride->track_colour_supports, &track_design->track_support_colour, 4);
memcpy(&ride->track_colour_main, &td6->track_spine_colour, 4);
memcpy(&ride->track_colour_additional, &td6->track_rail_colour, 4);
memcpy(&ride->track_colour_supports, &td6->track_support_colour, 4);
}
else{
memset(&ride->track_colour_main, track_design->track_spine_colour_rct1, 4);
memset(&ride->track_colour_additional, track_design->track_rail_colour_rct1, 4);
memset(&ride->track_colour_supports, track_design->track_support_colour_rct1, 4);
memset(&ride->track_colour_main, td6->track_spine_colour_rct1, 4);
memset(&ride->track_colour_additional, td6->track_rail_colour_rct1, 4);
memset(&ride->track_colour_supports, td6->track_support_colour_rct1, 4);
}
RCT2_GLOBAL(0x009D8150, uint8) |= 1;
@@ -2045,7 +2045,7 @@ int sub_6D2189(int* cost, uint8* ride_id){
int map_size = gMapSize << 4;
_currentTrackPieceDirection = 0;
int z = sub_6D01B3(3, 0, map_size, map_size, 16);
int z = sub_6D01B3(td6, 3, 0, map_size, map_size, 16);
if (RCT2_GLOBAL(0xF4414E, uint8) & 4){
RCT2_GLOBAL(0xF44151, uint8) |= 2;
@@ -2058,12 +2058,12 @@ int sub_6D2189(int* cost, uint8* ride_id){
bl |= 0x80;
RCT2_GLOBAL(0xF44151, uint8) |= 1;
}
edi = sub_6D01B3(bl, *ride_id, map_size, map_size, z);
edi = sub_6D01B3(td6, bl, *ride_id, map_size, map_size, z);
gParkFlags = backup_park_flags;
if (edi != MONEY32_UNDEFINED){
if (!find_object_in_entry_group(&track_design->vehicle_object, &entry_type, &entry_index)){
if (!find_object_in_entry_group(&td6->vehicle_object, &entry_type, &entry_index)){
RCT2_GLOBAL(0xF44151, uint8) |= 4;
}
@@ -2096,7 +2096,8 @@ void sub_6D235B(uint8 ride_id){
*
* rct2: 0x006D1EF0
*/
void draw_track_preview(uint8** preview){
void draw_track_preview(rct_track_td6 *td6, uint8** preview)
{
// Make a copy of the map
if (!backup_map())return;
@@ -2109,7 +2110,7 @@ void draw_track_preview(uint8** preview){
int cost;
uint8 ride_id;
if (!sub_6D2189(&cost, &ride_id)){
if (!sub_6D2189(td6, &cost, &ride_id)) {
memset(preview, 0, TRACK_PREVIEW_IMAGE_SIZE * 4);
reload_map_backup();
return;
@@ -2271,7 +2272,7 @@ rct_track_design *track_get_info(int index, uint8** preview)
// Copy the track design apart from the preview image
memcpy(&trackDesign->track_td6, loaded_track, sizeof(rct_track_td6));
// Load in a new preview image, calculate cost variable, calculate var_06
draw_track_preview((uint8**)trackDesign->preview);
draw_track_preview(&trackDesign->track_td6, (uint8**)trackDesign->preview);
trackDesign->track_td6.cost = RCT2_GLOBAL(RCT2_ADDRESS_TRACK_DESIGN_COST, money32);
trackDesign->track_td6.track_flags = RCT2_GLOBAL(0x00F44151, uint8) & 7;
@@ -2628,7 +2629,7 @@ int maze_ride_to_td6(uint8 rideIndex, rct_track_td6* track_design, uint8* track_
// Save global vars as they are still used by scenery
sint16 start_z = RCT2_GLOBAL(0x00F44146, sint16);
sub_6D01B3(0, 0, 4096, 4096, 0);
sub_6D01B3(track_design, 0, 0, 4096, 4096, 0);
RCT2_GLOBAL(0x00F44142, sint16) = start_x;
RCT2_GLOBAL(0x00F44144, sint16) = start_y;
RCT2_GLOBAL(0x00F44146, sint16) = start_z;
@@ -2887,7 +2888,7 @@ int tracked_ride_to_td6(uint8 rideIndex, rct_track_td6* track_design, uint8* tra
RCT2_GLOBAL(0x00F44058, uint8*) = track_elements;
sub_6D01B3(0, 0, 4096, 4096, 0);
sub_6D01B3(track_design, 0, 0, 4096, 4096, 0);
// Resave global vars for scenery reasons.
RCT2_GLOBAL(0x00F44142, sint16) = start_x;
@@ -3163,7 +3164,7 @@ rct_track_design *temp_track_get_info(char* path, uint8** preview)
// Copy the track design apart from the preview image
memcpy(&trackDesign->track_td6, loaded_track, sizeof(rct_track_td6));
// Load in a new preview image, calculate cost variable, calculate var_06
draw_track_preview((uint8**)trackDesign->preview);
draw_track_preview(&trackDesign->track_td6, (uint8**)trackDesign->preview);
trackDesign->track_td6.cost = RCT2_GLOBAL(RCT2_ADDRESS_TRACK_DESIGN_COST, money32);
trackDesign->track_td6.track_flags = RCT2_GLOBAL(0x00F44151, uint8) & 7;
@@ -3262,7 +3263,7 @@ void game_command_place_track_design(int* eax, int* ebx, int* ecx, int* edx, int
}
}
rct_track_td6* track_design = RCT2_ADDRESS(0x009D8178, rct_track_td6);
rct_track_td6* track_design = gActiveTrackDesign;
rct_object_entry* ride_object = &track_design->vehicle_object;
uint8 entry_type, entry_index;
@@ -3301,10 +3302,10 @@ void game_command_place_track_design(int* eax, int* ebx, int* ecx, int* edx, int
money32 cost = 0;
if (!(flags & GAME_COMMAND_FLAG_APPLY)){
RCT2_GLOBAL(0x00F44150, uint8) = 0;
cost = sub_6D01B3(1, rideIndex, x, y, z);
cost = sub_6D01B3(track_design, 1, rideIndex, x, y, z);
if (RCT2_GLOBAL(0x00F4414E, uint8) & (1 << 1)){
RCT2_GLOBAL(0x00F44150, uint8) |= 1 << 7;
cost = sub_6D01B3(0x81, rideIndex, x, y, z);
cost = sub_6D01B3(track_design, 0x81, rideIndex, x, y, z);
}
}
else{
@@ -3316,7 +3317,7 @@ void game_command_place_track_design(int* eax, int* ebx, int* ecx, int* edx, int
bl = 2;
}
bl |= RCT2_GLOBAL(0x00F44150, uint8);
cost = sub_6D01B3(bl, rideIndex, x, y, z);
cost = sub_6D01B3(track_design, bl, rideIndex, x, y, z);
}
if (cost == MONEY32_UNDEFINED ||

View File

@@ -593,6 +593,8 @@ extern const rct_trackdefinition *gTrackDefinitions;
extern rct_map_element **gTrackSavedMapElements;
extern rct_track_td6 *gActiveTrackDesign;
void track_load_list(ride_list_item item);
int sub_67726A(const char *path);
rct_track_design *track_get_info(int index, uint8** preview);
@@ -603,7 +605,7 @@ int track_delete();
void track_mirror();
void reset_track_list_cache();
int track_is_connected_by_shape(rct_map_element *a, rct_map_element *b);
int sub_6D01B3(uint8 bl, uint8 rideIndex, int x, int y, int z);
int sub_6D01B3(rct_track_td6 *td6, uint8 bl, uint8 rideIndex, int x, int y, int z);
int save_track_design(uint8 rideIndex);
int install_track(char* source_path, char* dest_name);
void window_track_list_format_name(utf8 *dst, const utf8 *src, int colour, bool quotes);
@@ -645,6 +647,7 @@ bool track_element_is_station(rct_map_element *trackElement);
bool track_element_is_covered(int trackElementType);
bool track_design_open(rct_track_td6 *td6, const utf8 *path);
void draw_track_preview(rct_track_td6 *td6, uint8** preview);
void track_design_index_create();
size_t track_design_index_get_for_ride(track_design_file_ref **tdRefs, uint8 rideType, const char *entry);

View File

@@ -95,6 +95,9 @@ ride_list_item _window_track_list_item;
static track_design_file_ref *_trackDesigns = NULL;
static size_t _trackDesignsCount = 0;
static uint16 _loadedTrackDesignIndex;
static rct_track_td6 _loadedTrackDesign;
static uint8 _loadedTrackDesignPreview[4][TRACK_PREVIEW_IMAGE_SIZE];
/**
*
@@ -376,7 +379,6 @@ static void window_track_list_invalidate(rct_window *w)
static void window_track_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
{
rct_widget *widget;
rct_track_design *trackDesign = NULL;
uint8 *image;
uint16 holes, speed, drops, dropHeight, inversions;
fixed32_2dp rating;
@@ -401,12 +403,27 @@ static void window_track_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
colour = ColourMapA[w->colours[0]].darkest;
gfx_fill_rect(dpi, x, y, x + 369, y + 216, colour);
trackDesign = track_get_info(trackIndex, &image);
if (trackDesign == NULL) {
return;
}
rct_track_td6 *td6 = &_loadedTrackDesign;
gActiveTrackDesign = td6;
if (_loadedTrackDesignIndex != trackIndex) {
if (!track_design_open(td6, _trackDesigns[trackIndex].path)) {
return;
}
rct_track_td6* track_td6 = &trackDesign->track_td6;
// Load in a new preview image, calculate cost variable, calculate var_06
draw_track_preview(td6, (uint8**)_loadedTrackDesignPreview);
td6->cost = RCT2_GLOBAL(RCT2_ADDRESS_TRACK_DESIGN_COST, money32);
td6->track_flags = RCT2_GLOBAL(0x00F44151, uint8) & 7;
_loadedTrackDesignIndex = trackIndex;
}
image = _loadedTrackDesignPreview[_currentTrackPieceDirection];
// trackDesign = track_get_info(trackIndex, &image);
// if (trackDesign == NULL) {
// return;
// }
substituteElement = &g1Elements[0];
tmpElement = *substituteElement;
@@ -424,13 +441,13 @@ static void window_track_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
RCT2_GLOBAL(0x00F44153, uint8) = 0;
// Warnings
if ((track_td6->track_flags & 4) && !(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)) {
if ((td6->track_flags & 4) && !(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)) {
// Vehicle design not available
gfx_draw_string_centred_clipped(dpi, STR_VEHICLE_DESIGN_UNAVAILABLE, NULL, 0, x, y, 368);
y -= 10;
}
if (track_td6->track_flags & 1) {
if (td6->track_flags & 1) {
RCT2_GLOBAL(0x00F44153, uint8) = 1;
if (RCT2_GLOBAL(RCT2_ADDRESS_TRACK_DESIGN_SCENERY_TOGGLE, uint8) == 0) {
// Scenery not available
@@ -448,84 +465,84 @@ static void window_track_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
y = w->y + widget->bottom + 2;
// Stats
rating = track_td6->excitement * 10;
rating = td6->excitement * 10;
gfx_draw_string_left(dpi, STR_TRACK_LIST_EXCITEMENT_RATING, &rating, 0, x, y);
y += 10;
rating = track_td6->intensity * 10;
rating = td6->intensity * 10;
gfx_draw_string_left(dpi, STR_TRACK_LIST_INTENSITY_RATING, &rating, 0, x, y);
y += 10;
rating = track_td6->nausea * 10;
rating = td6->nausea * 10;
gfx_draw_string_left(dpi, STR_TRACK_LIST_NAUSEA_RATING, &rating, 0, x, y);
y += 14;
if (track_td6->type != RIDE_TYPE_MAZE) {
if (track_td6->type == RIDE_TYPE_MINI_GOLF) {
if (td6->type != RIDE_TYPE_MAZE) {
if (td6->type == RIDE_TYPE_MINI_GOLF) {
// Holes
holes = track_td6->holes & 0x1F;
holes = td6->holes & 0x1F;
gfx_draw_string_left(dpi, STR_HOLES, &holes, 0, x, y);
y += 10;
} else {
// Maximum speed
speed = ((track_td6->max_speed << 16) * 9) >> 18;
speed = ((td6->max_speed << 16) * 9) >> 18;
gfx_draw_string_left(dpi, STR_MAX_SPEED, &speed, 0, x, y);
y += 10;
// Average speed
speed = ((track_td6->average_speed << 16) * 9) >> 18;
speed = ((td6->average_speed << 16) * 9) >> 18;
gfx_draw_string_left(dpi, STR_AVERAGE_SPEED, &speed, 0, x, y);
y += 10;
}
// Ride length
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 0, uint16) = 1345;
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 2, uint16) = track_td6->ride_length;
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 2, uint16) = td6->ride_length;
gfx_draw_string_left_clipped(dpi, STR_TRACK_LIST_RIDE_LENGTH, (void*)RCT2_ADDRESS_COMMON_FORMAT_ARGS, 0, x, y, 214);
y += 10;
}
if (ride_type_has_flag(track_td6->type, RIDE_TYPE_FLAG_HAS_G_FORCES)) {
if (ride_type_has_flag(td6->type, RIDE_TYPE_FLAG_HAS_G_FORCES)) {
// Maximum positive vertical Gs
gForces = track_td6->max_positive_vertical_g * 32;
gForces = td6->max_positive_vertical_g * 32;
gfx_draw_string_left(dpi, STR_MAX_POSITIVE_VERTICAL_G, &gForces, 0, x, y);
y += 10;
// Maximum negative verical Gs
gForces = track_td6->max_negative_vertical_g * 32;
gForces = td6->max_negative_vertical_g * 32;
gfx_draw_string_left(dpi, STR_MAX_NEGATIVE_VERTICAL_G, &gForces, 0, x, y);
y += 10;
// Maximum lateral Gs
gForces = track_td6->max_lateral_g * 32;
gForces = td6->max_lateral_g * 32;
gfx_draw_string_left(dpi, STR_MAX_LATERAL_G, &gForces, 0, x, y);
y += 10;
// If .TD6
if (track_td6->version_and_colour_scheme / 4 >= 2) {
if (track_td6->total_air_time != 0) {
if (td6->version_and_colour_scheme / 4 >= 2) {
if (td6->total_air_time != 0) {
// Total air time
airTime = track_td6->total_air_time * 25;
airTime = td6->total_air_time * 25;
gfx_draw_string_left(dpi, STR_TOTAL_AIR_TIME, &airTime, 0, x, y);
y += 10;
}
}
}
if (ride_type_has_flag(track_td6->type, RIDE_TYPE_FLAG_HAS_DROPS)) {
if (ride_type_has_flag(td6->type, RIDE_TYPE_FLAG_HAS_DROPS)) {
// Drops
drops = track_td6->drops & 0x3F;
drops = td6->drops & 0x3F;
gfx_draw_string_left(dpi, STR_DROPS, &drops, 0, x, y);
y += 10;
// Drop height is multiplied by 0.75
dropHeight = (track_td6->highest_drop_height + (track_td6->highest_drop_height / 2)) / 2;
dropHeight = (td6->highest_drop_height + (td6->highest_drop_height / 2)) / 2;
gfx_draw_string_left(dpi, STR_HIGHEST_DROP_HEIGHT, &drops, 0, x, y);
y += 10;
}
if (track_td6->type != RIDE_TYPE_MINI_GOLF) {
inversions = track_td6->inversions & 0x1F;
if (td6->type != RIDE_TYPE_MINI_GOLF) {
inversions = td6->inversions & 0x1F;
if (inversions != 0) {
// Inversions
gfx_draw_string_left(dpi, STR_INVERSIONS, &inversions, 0, x, y);
@@ -534,16 +551,16 @@ static void window_track_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
}
y += 4;
if (track_td6->space_required_x != 0xFF) {
if (td6->space_required_x != 0xFF) {
// Space required
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 0, uint16) = track_td6->space_required_x;
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 2, uint16) = track_td6->space_required_y;
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 0, uint16) = td6->space_required_x;
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 2, uint16) = td6->space_required_y;
gfx_draw_string_left(dpi, STR_TRACK_LIST_SPACE_REQUIRED, (void*)RCT2_ADDRESS_COMMON_FORMAT_ARGS, 0, x, y);
y += 10;
}
if (track_td6->cost != 0) {
gfx_draw_string_left(dpi, STR_TRACK_LIST_COST_AROUND, &track_td6->cost, 0, x, y);
if (td6->cost != 0) {
gfx_draw_string_left(dpi, STR_TRACK_LIST_COST_AROUND, &td6->cost, 0, x, y);
y += 14;
}
}

View File

@@ -306,6 +306,7 @@ static void window_track_place_clear_provisional()
{
if (_window_track_place_last_was_valid) {
sub_6D01B3(
gActiveTrackDesign,
6,
RCT2_GLOBAL(0x00F440EB, uint8),
_window_track_place_last_valid_x,
@@ -341,7 +342,7 @@ static int window_track_place_get_base_z(int x, int y)
if (mapElement->properties.surface.terrain & 0x1F)
z = max(z, (mapElement->properties.surface.terrain & 0x1F) << 4);
return z + sub_6D01B3(3, 0, x, y, z);
return z + sub_6D01B3(gActiveTrackDesign, 3, 0, x, y, z);
}
static void window_track_place_attempt_placement(int x, int y, int z, int bl, money32 *cost, uint8 *rideIndex)
@@ -474,7 +475,7 @@ static void window_track_place_toolupdate(rct_window* w, int widgetIndex, int x,
// Check if tool map position has changed since last update
if (mapX == _window_track_place_last_x && mapY == _window_track_place_last_y) {
sub_6D01B3(0, 0, mapX, mapY, 0);
sub_6D01B3(gActiveTrackDesign, 0, 0, mapX, mapY, 0);
return;
}
@@ -507,7 +508,7 @@ static void window_track_place_toolupdate(rct_window* w, int widgetIndex, int x,
widget_invalidate(w, WIDX_PRICE);
}
sub_6D01B3(0, 0, mapX, mapY, mapZ);
sub_6D01B3(gActiveTrackDesign, 0, 0, mapX, mapY, mapZ);
}
/**