diff --git a/src/ride/ride.c b/src/ride/ride.c index 7549743045..b679b11ea1 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -3662,6 +3662,36 @@ static bool ride_is_mode_valid(rct_ride *ride, uint8 mode) return false; } +static bool ride_is_valid_lift_hill_speed(rct_ride *ride, int speed) +{ + int minSpeed = gCheatsFastLiftHill ? 0 : RideLiftData[ride->type].minimum_speed; + int maxSpeed = gCheatsFastLiftHill ? 255 : RideLiftData[ride->type].maximum_speed; + return speed >= minSpeed && speed <= maxSpeed; +} + +static bool ride_is_valid_num_circuits(rct_ride *ride, int numCircuits) +{ + int minNumCircuits = 1; + int maxNumCircuits = gCheatsFastLiftHill ? 255 : 20; + return numCircuits >= minNumCircuits && numCircuits <= maxNumCircuits; +} + +static bool ride_is_valid_operation_option(rct_ride *ride, uint8 value) +{ + uint8 minValue = RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8) + 4, uint8); + uint8 maxValue = RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8) + 5, uint8); + if (ride->mode == RIDE_MODE_MAZE) { + // Allow 64 people in mazes under non-cheat settings. The old maximum of 16 was too little for even moderately big mazes. + maxValue = 64; + } + if (gCheatsFastLiftHill) { + minValue = 0; + maxValue = 255; + } + + return value >= minValue && value <= maxValue; +} + static money32 ride_set_setting(uint8 rideIndex, uint8 setting, uint8 value, uint8 flags) { RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_RUNNING_COSTS * 4; @@ -3704,24 +3734,44 @@ static money32 ride_set_setting(uint8 rideIndex, uint8 setting, uint8 value, uin } break; case RIDE_SETTING_MIN_WAITING_TIME: + if (value > 250) { + log_warning("Invalid minimum waiting time."); + return MONEY32_UNDEFINED; + } + if (flags & GAME_COMMAND_FLAG_APPLY) { ride->min_waiting_time = value; ride->max_waiting_time = max(value, ride->max_waiting_time); } break; case RIDE_SETTING_MAX_WAITING_TIME: + if (value > 250) { + log_warning("Invalid maximum waiting time."); + return MONEY32_UNDEFINED; + } + if (flags & GAME_COMMAND_FLAG_APPLY) { ride->max_waiting_time = value; ride->min_waiting_time = min(value, ride->min_waiting_time); } break; - case RIDE_SETTING_TIME_LIMIT: + case RIDE_SETTING_OPERATION_OPTION: + if (!ride_is_valid_operation_option(ride, value)) { + log_warning("Invalid operation option value."); + return MONEY32_UNDEFINED; + } + if (flags & GAME_COMMAND_FLAG_APPLY) { invalidate_test_results(rideIndex); - ride->time_limit = value; + ride->operation_option = value; } break; case RIDE_SETTING_INSPECTION_INTERVAL: + if (value > RIDE_INSPECTION_NEVER) { + log_warning("Invalid inspection interval."); + return MONEY32_UNDEFINED; + } + if (flags & GAME_COMMAND_FLAG_APPLY) { ride->inspection_interval = value; } @@ -3735,6 +3785,11 @@ static money32 ride_set_setting(uint8 rideIndex, uint8 setting, uint8 value, uin } break; case RIDE_SETTING_MUSIC_TYPE: + if (value >= MUSIC_STYLE_COUNT) { + log_warning("Invalid music style."); + return MONEY32_UNDEFINED; + } + if (flags & GAME_COMMAND_FLAG_APPLY) { if (value != ride->music) { ride->music = value; @@ -3743,6 +3798,11 @@ static money32 ride_set_setting(uint8 rideIndex, uint8 setting, uint8 value, uin } break; case RIDE_SETTING_LIFT_HILL_SPEED: + if (!ride_is_valid_lift_hill_speed(ride, value)) { + log_warning("Invalid lift hill speed."); + return MONEY32_UNDEFINED; + } + if (flags & GAME_COMMAND_FLAG_APPLY) { if (value != ride->lift_hill_speed) { ride->lift_hill_speed = value; @@ -3756,6 +3816,11 @@ static money32 ride_set_setting(uint8 rideIndex, uint8 setting, uint8 value, uin return MONEY32_UNDEFINED; } + if (!ride_is_valid_num_circuits(ride, value)) { + log_warning("Invalid number of circuits."); + return MONEY32_UNDEFINED; + } + if (flags & GAME_COMMAND_FLAG_APPLY) { if (value != ride->num_circuits) { ride->num_circuits = value; diff --git a/src/ride/ride.h b/src/ride/ride.h index 661ecde39b..4a3fa896cf 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -626,7 +626,8 @@ enum { MUSIC_STYLE_MODERN, MUSIC_STYLE_PIRATES, MUSIC_STYLE_ROCK_STYLE_3, - MUSIC_STYLE_CANDY_STYLE + MUSIC_STYLE_CANDY_STYLE, + MUSIC_STYLE_COUNT }; enum { @@ -848,7 +849,7 @@ enum { RIDE_SETTING_DEPARTURE, RIDE_SETTING_MIN_WAITING_TIME, RIDE_SETTING_MAX_WAITING_TIME, - RIDE_SETTING_TIME_LIMIT, + RIDE_SETTING_OPERATION_OPTION, RIDE_SETTING_INSPECTION_INTERVAL, RIDE_SETTING_MUSIC, RIDE_SETTING_MUSIC_TYPE, diff --git a/src/windows/ride.c b/src/windows/ride.c index 4947fa194b..53ab10bbc6 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -2792,7 +2792,7 @@ static void window_ride_mode_tweak_set(rct_window *w, uint8 value) ) RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, uint16) = 1868; - game_do_command(0, (value << 8) | 1, 0, (4 << 8) | w->number, GAME_COMMAND_SET_RIDE_SETTING, 0, 0); + set_operating_setting(w->number, RIDE_SETTING_OPERATION_OPTION, value); } /** @@ -2802,18 +2802,21 @@ static void window_ride_mode_tweak_set(rct_window *w, uint8 value) static void window_ride_mode_tweak_increase(rct_window *w) { rct_ride *ride = get_ride(w->number); - uint8 value = ride->operation_option; - //fast_lift_hill is the cheat that allows maxing out many limits on the Operating tab. - uint8 max_value = gCheatsFastLiftHill ? 255 : RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8) + 5, uint8); - //Allow 64 people in mazes under non-cheat settings. The old maximum of 16 was too little for even moderately big mazes. - if(ride->mode == RIDE_MODE_MAZE && !gCheatsFastLiftHill) - max_value = 64; + uint8 maxValue = RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8) + 5, uint8); + if (ride->mode == RIDE_MODE_MAZE) { + // Allow 64 people in mazes under non-cheat settings. The old maximum of 16 was too little for even moderately big mazes. + maxValue = 64; + } + if (gCheatsFastLiftHill) { + maxValue = 255; + } - if (value < max_value) - value += ride->mode == RIDE_MODE_BUMPERCAR ? 10 : 1; - - window_ride_mode_tweak_set(w, value); + uint8 increment = ride->mode == RIDE_MODE_BUMPERCAR ? 10 : 1; + uint8 newValue = ride->operation_option + increment; + if (newValue < maxValue) { + window_ride_mode_tweak_set(w, newValue); + } } /** @@ -2823,14 +2826,17 @@ static void window_ride_mode_tweak_increase(rct_window *w) static void window_ride_mode_tweak_decrease(rct_window *w) { rct_ride *ride = get_ride(w->number); - uint8 value = ride->operation_option; - //fast_lift_hill is the cheat that allows maxing many limits on the Operating tab. - uint8 min_value = gCheatsFastLiftHill ? 0 : RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8) + 4, uint8); - if (value > min_value) - value -= ride->mode == RIDE_MODE_BUMPERCAR ? 10 : 1; + uint8 minValue = RCT2_GLOBAL(RCT2_ADDRESS_RIDE_FLAGS + (ride->type * 8) + 4, uint8); + if (gCheatsFastLiftHill) { + minValue = 0; + } - window_ride_mode_tweak_set(w, value); + uint8 decrement = ride->mode == RIDE_MODE_BUMPERCAR ? 10 : 1; + uint8 newValue = ride->operation_option - decrement; + if (newValue > minValue) { + window_ride_mode_tweak_set(w, newValue); + } } /**