From 445d603abef57076375e9f804964cd94167453af Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Tue, 14 Jul 2015 18:18:10 +0100 Subject: [PATCH] refactor various things such as scenario begin and staff mode reset, add rct1 ride struct --- src/editor.c | 23 ++------- src/editor.h | 2 - src/peep/staff.c | 15 ++++++ src/peep/staff.h | 1 + src/rct1.c | 16 +++++- src/rct1.h | 129 ++++++++++++++++++++++++++++++++++++++++++++++- src/rct2.c | 4 +- src/scenario.c | 29 +++++------ src/scenario.h | 1 + src/title.c | 3 +- 10 files changed, 182 insertions(+), 41 deletions(-) diff --git a/src/editor.c b/src/editor.c index bb9bef8c2c..b3960732ce 100644 --- a/src/editor.c +++ b/src/editor.c @@ -69,7 +69,7 @@ void editor_load() reset_sprite_list(); ride_init_all(); window_guest_list_init_vars_a(); - sub_6BD3A4(); + staff_reset_modes(); park_init(); finance_init(); date_reset(); @@ -186,7 +186,7 @@ void trackdesigner_load() reset_sprite_list(); ride_init_all(); window_guest_list_init_vars_a(); - sub_6BD3A4(); + staff_reset_modes(); park_init(); finance_init(); date_reset(); @@ -223,7 +223,7 @@ void trackmanager_load() reset_sprite_list(); ride_init_all(); window_guest_list_init_vars_a(); - sub_6BD3A4(); + staff_reset_modes(); park_init(); finance_init(); date_reset(); @@ -254,21 +254,6 @@ static void set_all_land_owned() game_do_command(64, 1, 64, 2, GAME_COMMAND_SET_LAND_OWNERSHIP, (mapSize - 2) * 32, (mapSize - 2) * 32); } -/** - * - * rct2: 0x006BD3A4 - */ -void sub_6BD3A4() -{ - for (int i = 0; i < 200; i++) - RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[i] = STAFF_MODE_NONE; - - for (int i = 200; i < 204; i++) - RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[i] = STAFF_MODE_WALK; - - staff_update_greyed_patrol_areas(); -} - /** * * rct2: 0x006758C0 @@ -447,7 +432,7 @@ static int editor_read_s6(const char *path) } reset_sprite_list(); - sub_6BD3A4(); + staff_reset_modes(); RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_HEADING_FOR_PARK, uint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_LAST_GUESTS_IN_PARK, uint16) = 0; diff --git a/src/editor.h b/src/editor.h index ac83963cd4..54044a3dfa 100644 --- a/src/editor.h +++ b/src/editor.h @@ -43,8 +43,6 @@ void trackdesigner_load(); void trackmanager_load(); void editor_load_landscape(const char *path); -void sub_6BD3A4(); - void editor_open_windows_for_current_step(); bool editor_check_park(); diff --git a/src/peep/staff.c b/src/peep/staff.c index 11cf6b1966..e7725d093d 100644 --- a/src/peep/staff.c +++ b/src/peep/staff.c @@ -32,6 +32,21 @@ uint32 *gStaffPatrolAreas = (uint32*)0x013B0E72; uint8 *gStaffModes = (uint8*)0x013CA672; +/** + * + * rct2: 0x006BD3A4 + */ +void staff_reset_modes() +{ + for (int i = 0; i < 200; i++) + RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[i] = STAFF_MODE_NONE; + + for (int i = 200; i < 204; i++) + RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[i] = STAFF_MODE_WALK; + + staff_update_greyed_patrol_areas(); +} + /** * * rct2: 0x00669E55 diff --git a/src/peep/staff.h b/src/peep/staff.h index 42303f33f7..68b2b32321 100644 --- a/src/peep/staff.h +++ b/src/peep/staff.h @@ -58,6 +58,7 @@ void game_command_set_staff_order(int *eax, int *ebx, int *ecx, int *edx, int *e void game_command_set_staff_patrol(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); void game_command_fire_staff_member(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); +void staff_reset_modes(); void update_staff_colour(uint8 staffType, uint16 color); uint16 hire_new_staff_member(uint8 staffType); void staff_update_greyed_patrol_areas(); diff --git a/src/rct1.c b/src/rct1.c index 06bbf8348a..95c5b11364 100644 --- a/src/rct1.c +++ b/src/rct1.c @@ -328,6 +328,16 @@ static void rct1_remove_rides() } while (map_element_iterator_next(&it)); } +static bool is_object_name_blank(rct_object_entry *entry) +{ + for (int i = 0; i < 8; i++) { + if (entry->name[i] != ' ') { + return false; + } + } + return true; +} + /** * * rct2: 0x0069F53D @@ -337,6 +347,10 @@ static void rct1_load_default_objects() for (int i = 0; i < 9; i++) { rct_object_entry *entries = (rct_object_entry*)RCT1DefaultObjects[i].entries; for (int j = 0; j < RCT1DefaultObjects[i].count; j++) { + if (is_object_name_blank(&entries[j])) { + continue; + } + if (!object_load(j, &entries[j], NULL)) { error_string_quit(0x99990000 + (i * 0x100) + j, -1); return; @@ -1283,7 +1297,7 @@ static const rct_object_entry RCT1DefaultObjectsWater[] = { }; static const RCT1DefaultObjectsGroup RCT1DefaultObjects[10] = { - { NULL, 0 }, + { RCT1DefaultObjectsRides, countof(RCT1DefaultObjectsRides) }, { RCT1DefaultObjectsSmallScenery, countof(RCT1DefaultObjectsSmallScenery) }, { RCT1DefaultObjectsLargeScenery, countof(RCT1DefaultObjectsLargeScenery) }, { RCT1DefaultObjectsWall, countof(RCT1DefaultObjectsWall) }, diff --git a/src/rct1.h b/src/rct1.h index c28f087653..5a3c66555b 100644 --- a/src/rct1.h +++ b/src/rct1.h @@ -37,6 +37,131 @@ typedef struct { uint8 direction; } rct1_entrance; +/** + * RCT1 ride structure + * size: 0x260 + */ +typedef struct { + uint8 type; + uint8 vehicle_type; + uint16 lifecycle_flags; + uint8 operating_mode; + uint8 colour_scheme; + uint16 vehicle_colours[12]; + uint8 track_primary_colour; + uint8 track_secondary_colour; + uint8 track_support_colour; + uint8 status; + uint16 name; + uint16 name_argument_ride; + uint16 name_argument_number; + uint16 overall_view; + uint16 station_starts[4]; + uint8 station_height[4]; + uint8 station_length[4]; + uint8 station_light[4]; + uint8 station_depart[4]; + uint16 entrance[4]; + uint16 exit[4]; + uint16 first_peep_in_queue[4]; + uint8 num_peeps_in_queue[4]; + uint16 vehicles[12]; + uint8 depart_flags; + uint8 num_stations; + uint8 num_trains; + uint8 num_cars_per_train; + uint8 unk_7A; + uint8 unk_7B; + uint8 max_trains; + uint8 unk_7D; + uint8 min_waiting_time; + uint8 max_waiting_time; + uint8 operation_option; + uint8 unk_081[0x3]; + uint8 data_logging_index; + uint8 special_track_elements; + uint16 unk_86; + sint32 max_speed; + sint32 average_speed; + uint8 pad_090[4]; + sint32 length[4]; + uint16 time[4]; + fixed16_2dp max_positive_vertical_g; + fixed16_2dp max_negative_vertical_g; + fixed16_2dp max_lateral_g; + uint8 unk_B2[18]; + union { + uint8 num_inversions; + uint8 num_holes; + }; + uint8 num_drops; + uint8 unk_C6; + uint8 highest_drop_height; + sint32 sheltered_length; + uint8 unk_CC[2]; + uint8 num_sheltered_sections; + uint8 unk_CF; + sint16 unk_D0; + sint16 unk_D2; + sint16 customers_per_hour; + sint16 unk_D6; + sint16 unk_D8; + sint16 unk_DA; + sint16 unk_DC; + sint16 unk_DE; + uint16 age; + sint16 running_cost; + sint16 unk_E4; + sint16 unk_E6; + money16 price; + sint16 var_EA; + sint16 var_EC; + uint8 var_EE; + uint8 var_EF; + union { + rating_tuple ratings; + struct { + ride_rating excitement; + ride_rating intensity; + ride_rating nausea; + }; + }; + uint16 value; + uint16 var_F8; + uint8 satisfaction; + uint8 satisfaction_time_out; + uint8 satisfaction_next; + uint8 window_invalidate_flags; + uint8 unk_FE[2]; + uint32 total_customers; + money32 total_profit; + uint8 popularity; + uint8 popularity_time_out; + uint8 popularity_next; + uint8 num_riders; + uint8 unk_10C[36]; + sint16 build_date; + money16 upkeep_cost; + uint8 unk_134[15]; + uint8 breakdown_reason; + uint8 unk_144[2]; + uint16 reliability; + uint8 unreliability_factor; + uint8 unk_148; + uint8 inspection_interval; + uint8 last_inspection; + uint8 unk_14C[20]; + money32 income_per_hour; + money32 profit; + uint8 queue_time[4]; + uint8 track_colour_main[4]; + uint8 track_colour_additional[4]; + uint8 track_colour_supports[4]; + uint8 music; + uint8 entrance_style; + uint8 unk_17A[230]; +} rct1_ride; + /** * RCT1,AA,LL scenario / saved game structure. * size: 0x1F850C @@ -166,9 +291,9 @@ typedef struct { rct_research_item research_items_LL[180]; uint8 unk_19A020[5468]; rct_banner banners[100]; - char string_table[32][1024]; + char string_table[1024][32]; uint32 game_time_counter; - rct_ride rides[255]; + rct1_ride rides[255]; uint16 unk_game_time_counter; uint16 view_x; uint16 view_y; diff --git a/src/rct2.c b/src/rct2.c index ef8940af49..a41de22853 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -38,7 +38,9 @@ #include "network/twitch.h" #include "object.h" #include "openrct2.h" +#include "peep/staff.h" #include "platform/platform.h" +#include "rct1.h" #include "ride/ride.h" #include "ride/track.h" #include "scenario.h" @@ -108,7 +110,7 @@ int rct2_init() reset_sprite_list(); ride_init_all(); window_guest_list_init_vars_a(); - sub_6BD3A4(); + staff_reset_modes(); map_init(150); park_init(); if (!gOpenRCT2Headless) diff --git a/src/scenario.c b/src/scenario.c index 582803e2c8..1310af5a61 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -207,14 +207,6 @@ int scenario_load_and_play(const rct_scenario_basic *scenario) int scenario_load_and_play_from_path(const char *path) { - rct_window *mainWindow; - rct_s6_info *s6Info = (rct_s6_info*)0x0141F570; - - // Create the scenario pseduo-random seeds using the current time - uint32 srand0, srand1; - srand0 = RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_SRAND_0, uint32) ^ platform_get_ticks(); - srand1 = RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_SRAND_1, uint32) ^ platform_get_ticks(); - window_close_construction_windows(); if (!scenario_load(path)) @@ -224,6 +216,15 @@ int scenario_load_and_play_from_path(const char *path) _scenarioFileName = path_get_filename(_scenarioPath); log_verbose("starting scenario, %s", path); + scenario_begin(); + + return 1; +} + +void scenario_begin() +{ + rct_s6_info *s6Info = (rct_s6_info*)0x0141F570; + rct_window *mainWindow; RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_PLAYING; viewport_init_all(); @@ -234,9 +235,9 @@ int scenario_load_and_play_from_path(const char *path) mainWindow->saved_view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16); mainWindow->saved_view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16); - uint8 _cl = (RCT2_GLOBAL(0x0138869E, sint16) & 0xFF) - mainWindow->viewport->zoom; - mainWindow->viewport->zoom = RCT2_GLOBAL(0x0138869E, sint16) & 0xFF; - *((char*)(&RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32))) = RCT2_GLOBAL(0x0138869E, sint16) >> 8; + uint8 _cl = (RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF) - mainWindow->viewport->zoom; + mainWindow->viewport->zoom = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF; + *((char*)(&RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32))) = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) >> 8; if (_cl != 0) { if (_cl < 0) { _cl = -_cl; @@ -255,8 +256,8 @@ int scenario_load_and_play_from_path(const char *path) window_new_ride_init_vars(); // Set the scenario pseduo-random seeds - RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_SRAND_0, sint32) = srand0; - RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_SRAND_1, sint32) = srand1; + RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_SRAND_0, sint32) ^= platform_get_ticks(); + RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_SRAND_1, sint32) ^= platform_get_ticks(); RCT2_GLOBAL(0x009DEB7C, sint16) = 0; RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, sint32) &= 0xFFFFF7FF; @@ -340,8 +341,6 @@ int scenario_load_and_play_from_path(const char *path) RCT2_GLOBAL(0x009DEA66, uint16) = 0; RCT2_GLOBAL(0x009DEA5C, uint16) = 62000; // (doesn't appear to ever be read) gGameSpeed = 1; - - return 1; } void scenario_end() diff --git a/src/scenario.h b/src/scenario.h index 5f4f842221..d2cdd74b98 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -421,6 +421,7 @@ int scenario_load_basic(const char *path, rct_s6_header *header, rct_s6_info *in int scenario_load(const char *path); int scenario_load_and_play(const rct_scenario_basic *scenario); int scenario_load_and_play_from_path(const char *path); +void scenario_begin(); void scenario_update(); unsigned int scenario_rand(); unsigned int scenario_rand_max(unsigned int max); diff --git a/src/title.c b/src/title.c index 79148ac83c..838e8924c7 100644 --- a/src/title.c +++ b/src/title.c @@ -34,6 +34,7 @@ #include "management/news_item.h" #include "management/research.h" #include "openrct2.h" +#include "peep/staff.h" #include "ride/ride.h" #include "scenario.h" #include "util/util.h" @@ -110,7 +111,7 @@ void title_load() reset_sprite_list(); ride_init_all(); window_guest_list_init_vars_a(); - sub_6BD3A4(); + staff_reset_modes(); map_init(150); park_init(); date_reset();