From eec2edad218428083168846ea3e69ede6db47fb6 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Tue, 11 Nov 2014 23:05:04 +0000 Subject: [PATCH 001/162] start implementing vehicle update --- src/ride/ride.h | 49 ++++++++ src/ride/vehicle.c | 293 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 341 insertions(+), 1 deletion(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index a54a49b105..65da673ff9 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -70,6 +70,55 @@ typedef struct { vehicle_colour list[256]; } vehicle_colour_preset_list; +/** + * Ride type vehicle structure. + * size: 0x65 + */ +typedef struct{ + uint16 var_00; // 0x00 , 0x1A + uint8 var_02; // 0x02 , 0x1C + uint8 var_03; // 0x03 , 0x1D + uint32 var_04; // 0x04 , 0x1E + uint16 var_08; // 0x08 , 0x22 + sint8 var_0A; // 0x0A , 0x24 + uint8 pad_0B; + uint16 var_0C; // 0x0C , 0x26 + uint8 var_0E; // 0x0E , 0x28 + uint8 var_0F; // 0x0F , 0x29 + uint8 var_10; // 0x10 , 0x2A + uint8 var_11; // 0x11 , 0x2B + uint16 var_12; // 0x12 , 0x2C + uint16 var_14; // 0x14 , 0x2E + uint16 var_16; // 0x16 , 0x30 + uint32 base_image_id; // 0x18 , 0x32 + uint32 var_1C; // 0x1C , 0x36 + uint32 var_20; // 0x20 , 0x3A + uint32 var_24; // 0x24 , 0x3E + uint32 var_28; // 0x28 , 0x42 + uint32 var_2C; // 0x2C , 0x46 + uint32 var_30; // 0x30 , 0x4A + uint32 var_34; // 0x34 , 0x4E + uint32 var_38; // 0x38 , 0x52 + uint32 var_3C; // 0x3C , 0x56 + uint32 var_40; // 0x40 , 0x5A + uint32 var_44; // 0x44 , 0x5E + uint32 var_48; // 0x48 , 0x62 + uint32 var_4C; // 0x4C , 0x66 + uint32 no_vehicle_images; // 0x50 , 0x6A + uint8 no_seating_rows; // 0x54 , 0x6E + uint8 pad_55[0x2]; + uint8 var_57; // 0x57 , 0x71 + uint8 pad_58; + uint8 var_59; // 0x59 , 0x73 + uint8 var_5A; // 0x5A , 0x74 + uint8 pad_5B; // 0x5B , 0x75 + uint8 var_5C; // 0x5C , 0x76 + uint8 var_5D; // 0x5D , 0x77 + uint8 pad_5E[0x2]; + uint8 var_60; // 0x60 , 0x7A + sint8* peep_loading_positions; // 0x61 , 0x7B +} rct_ride_type_vehicle; + /** * Ride type structure. * size: unknown diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 4f66083e0b..01ce805611 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -25,6 +25,7 @@ #include "../hook.h" #include "../interface/viewport.h" #include "../openrct2.h" +#include "../scenario.h" #include "../world/sprite.h" #include "ride.h" #include "ride_data.h" @@ -32,6 +33,12 @@ #include "vehicle.h" static void vehicle_update(rct_vehicle *vehicle); +static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); +static void vehicle_update_waiting_to_depart(rct_vehicle *vehicle); +static void vehicle_update_departing(rct_vehicle *vehicle); +static void vehicle_update_travelling(rct_vehicle *vehicle); +static void vehicle_update_arriving(rct_vehicle *vehicle); +static void vehicle_update_sound(rct_vehicle *vehicle); /** * @@ -449,13 +456,297 @@ void vehicle_update_all() } } +static void sub_6D6D1F(rct_vehicle *vehicle) +{ + rct_ride *ride; + + ride = GET_RIDE(vehicle->ride); + RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)ride, 0); +} + +static uint16 sub_6D7AC0(uint8 soundId, uint8 volume, uint8 bl, uint8 dl) +{ + if (soundId != 255) { + if (soundId == dl) { + volume += 15; + if ((sint8)volume < 0) + volume = bl; + + if (volume > bl) + volume = bl; + return (volume << 8) | soundId; + } else { + volume -= 9; + if (volume >= 80) + return (volume << 8) | soundId; + } + } + + soundId = dl; + volume = bl == 255 ? 255 : bl / 4; + + return (volume << 8) | soundId; +} + /** * * rct2: 0x006D77F2 */ static void vehicle_update(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006D77F2, 0, 0, 0, 0, (int)vehicle, 0, 0); + // RCT2_CALLPROC_X(0x006D77F2, 0, 0, 0, 0, (int)vehicle, 0, 0); + + rct_ride *ride; + rct_ride_type *rideEntry; + + if (vehicle->ride_subtype == 255) { + switch (vehicle->status) { + case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: + vehicle_update_moving_to_end_of_station(vehicle); + break; + case VEHICLE_STATUS_WAITING_TO_DEPART: + vehicle_update_waiting_to_depart(vehicle); + break; + case VEHICLE_STATUS_DEPARTING: + vehicle_update_departing(vehicle); + break; + case VEHICLE_STATUS_TRAVELLING: + vehicle_update_travelling(vehicle); + break; + case VEHICLE_STATUS_ARRIVING: + vehicle_update_arriving(vehicle); + break; + } + return; + } + + rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + ride = GET_RIDE(vehicle->ride); + if (vehicle->var_48 & 0x20) + sub_6D6D1F(vehicle); + + RCT2_GLOBAL(0x00F64E34, uint8) = 255; + if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) { + RCT2_GLOBAL(0x00F64E34, uint8) = ride->breakdown_reason_pending; + if ((vehicleEntry->var_14 & 8) && ride->breakdown_reason_pending == BREAKDOWN_SAFETY_CUT_OUT) { + if (!(vehicleEntry->var_14 & 0x2000) || + ( + vehicle->var_1F == 2 && + vehicle->velocity <= 0x20000 + ) + ) { + vehicle->var_48 |= 0x80; + } + } + } + + int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); + RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->var_51 << 8) | ride->mode, (int)vehicle, 0, 0); + + vehicle_update_sound(vehicle); +} + +static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006DF8A4, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + +static void vehicle_update_waiting_to_depart(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006DF8F1, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + +static void vehicle_update_departing(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006DF97A, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + +static void vehicle_update_travelling(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006DF99C, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + +static void vehicle_update_arriving(rct_vehicle *vehicle) +{ + vehicle->var_51++; + if (vehicle->var_51 >= 64) + vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; +} + +/** + * + * rct2: 0x006D7888 + */ +static void vehicle_update_sound(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006D7888, 0, 0, 0, 0, (int)vehicle, 0, 0); return; + + // PROBLEMS + uint16 spriteIndex; + rct_ride *ride; + rct_ride_type *rideEntry; + rct_vehicle *vehicle2; + + ride = GET_RIDE(vehicle->ride); + rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + uint16 ax = vehicle->var_B8; + uint8 al, ah, bl, bh, cl, dh, dl = 255; + int ecx = abs(vehicle->velocity) - 0x10000; + if (ecx >= 0) { + dl = vehicleEntry->var_57; + ecx >>= 15; + bl = 208 + (ecx & 0xFF); + if (bl < 0) + bl = 255; + } + + if (vehicleEntry->var_59 == 3) { + dh = vehicle->var_CC; + if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x7F)) { + if (vehicle->velocity < 0x40000 || vehicle->var_CC != 255) + goto loc_6D7A97; + + if ((scenario_rand() & 0xFFFF) <= 0x5555) { + dh = 18; + goto loc_6D7A43; + } + } + + goto loc_6D7A4A; + } + if (vehicleEntry->var_59 == 4) { + dh = vehicle->var_CC; + if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x7F)) { + if (vehicle->velocity < 0x40000 || vehicle->var_CC != 255) + goto loc_6D7A97; + + if ((scenario_rand() & 0xFFFF) <= 0x5555) { + dh = 59; + goto loc_6D7A43; + } + } + goto loc_6D7A4A; + } + + if (!(vehicleEntry->var_14 & 0x10)) + goto loc_6D7A97; + + uint8 ch = 0; + vehicle2 = vehicle; + for (;;) { + ch += vehicle2->num_peeps; + spriteIndex = vehicle2->next_vehicle_on_train; + if (spriteIndex == SPRITE_INDEX_NULL) + break; + + vehicle2 = &(g_sprite_list[spriteIndex].vehicle); + } + if (ch != 0) { + if (vehicle->velocity < 0) { + if (vehicle->velocity > 0xFFFD4000) + goto loc_6D7A97; + + spriteIndex = vehicle->sprite_index; + do { + vehicle2 = &(g_sprite_list[spriteIndex].vehicle); + cl = vehicle2->var_1F; + if (cl < 1) + continue; + if (cl <= 4) + goto loc_6D79E2; + if (cl < 9) + continue; + if (cl <= 15) + goto loc_6D79E2; + } while ((spriteIndex = vehicle2->next_vehicle_on_train) != SPRITE_INDEX_NULL); + goto loc_6D7A97; + } + + if (vehicle->velocity < 0x2C000) + goto loc_6D7A97; + + spriteIndex = vehicle->sprite_index; + do { + vehicle2 = &(g_sprite_list[spriteIndex].vehicle); + cl = vehicle2->var_1F; + if (cl < 5) + continue; + if (cl <= 8) + goto loc_6D79E2; + if (cl < 17) + continue; + if (cl <= 23) + goto loc_6D79E2; + } while ((spriteIndex = vehicle2->next_vehicle_on_train) != SPRITE_INDEX_NULL); + goto loc_6D7A97; + + loc_6D79E2: + dh = vehicle->var_CC; + if (dh == 255) { + int eax = scenario_rand(); + al = eax & 0xFF; + ah = (eax >> 8) & 0xFF; + if (ah <= ch) { + switch (vehicleEntry->var_59) { + case 0: + eax = ((al * 2) >> 8) & 0xFF; + dh = RCT2_ADDRESS(0x009A3A14, uint8)[eax]; + goto loc_6D7A43; + case 1: + eax = ((al * 7) >> 8) & 0xFF; + dh = RCT2_ADDRESS(0x009A3A18, uint8)[eax]; + goto loc_6D7A43; + case 2: + eax = ((al * 2) >> 8) & 0xFF; + dh = RCT2_ADDRESS(0x009A3A16, uint8)[eax]; + goto loc_6D7A43; + } + } + dh = 254; + + loc_6D7A43: + dh = vehicle->var_CC; + } + + loc_6D7A4A: + if (dh != 254) + dh = 255; + + bh = 255; + goto loc_6D7AC0; + } + +loc_6D7A97: + vehicle->var_CC = 255; + dh = RCT2_GLOBAL(0x0097D7C8 + (ride->type * 4), uint8); + bh = 243; + if (!(ax & 2)) + dh = 255; + +loc_6D7AC0: + ; + uint16 soundIdVolume; + + soundIdVolume = sub_6D7AC0(vehicle->sound1_id, vehicle->sound1_volume, bl, dl); + vehicle->sound1_id = soundIdVolume & 0xFF; + vehicle->sound1_volume = (soundIdVolume >> 8) & 0xFF; + soundIdVolume = sub_6D7AC0(vehicle->sound2_id, vehicle->sound2_volume, bl, dl); + vehicle->sound2_id = soundIdVolume & 0xFF; + vehicle->sound2_volume = (soundIdVolume >> 8) & 0xFF; + + { + int ebx = RCT2_ADDRESS(0x009A3684, sint16)[vehicle->sprite_direction]; + int eax = ((vehicle->velocity >> 14) * ebx) >> 14; + eax = max(eax, 0xFF81); + eax = min(eax, 0x7F); + vehicle->var_BF = eax & 0xFF; + } } /** From 6f5a54e536f9621f94818d883e187cef2aa08c68 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 12 Nov 2014 01:04:50 +0000 Subject: [PATCH 002/162] try to make sense of vehicle_update_sound --- src/ride/ride.h | 2 +- src/ride/vehicle.c | 287 +++++++++++++++++++++++++-------------------- src/ride/vehicle.h | 1 + 3 files changed, 162 insertions(+), 128 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index 65da673ff9..2bb2758fb7 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -109,7 +109,7 @@ typedef struct{ uint8 pad_55[0x2]; uint8 var_57; // 0x57 , 0x71 uint8 pad_58; - uint8 var_59; // 0x59 , 0x73 + uint8 sound_range; // 0x59 , 0x73 uint8 var_5A; // 0x5A , 0x74 uint8 pad_5B; // 0x5B , 0x75 uint8 var_5C; // 0x5C , 0x76 diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 01ce805611..1443d972e0 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -39,6 +39,16 @@ static void vehicle_update_departing(rct_vehicle *vehicle); static void vehicle_update_travelling(rct_vehicle *vehicle); static void vehicle_update_arriving(rct_vehicle *vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); +static int vehicle_update_scream_sound(rct_vehicle *vehicle); + +#define NO_SCREAM 254 + +const uint8 byte_9A3A14[] = { SOUND_SCREAM_8, SOUND_SCREAM_1 }; +const uint8 byte_9A3A16[] = { SOUND_SCREAM_1, SOUND_SCREAM_6 }; +const uint8 byte_9A3A18[] = { + SOUND_SCREAM_3, SOUND_SCREAM_1, SOUND_SCREAM_5, SOUND_SCREAM_6, + SOUND_SCREAM_7, SOUND_SCREAM_2, SOUND_SCREAM_4, SOUND_LIFT_1 +}; /** * @@ -464,28 +474,24 @@ static void sub_6D6D1F(rct_vehicle *vehicle) RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)ride, 0); } -static uint16 sub_6D7AC0(uint8 soundId, uint8 volume, uint8 bl, uint8 dl) +static uint16 sub_6D7AC0(int currentSoundId, int currentVolume, int targetSoundId, int targetVolume) { - if (soundId != 255) { - if (soundId == dl) { - volume += 15; - if ((sint8)volume < 0) - volume = bl; - - if (volume > bl) - volume = bl; - return (volume << 8) | soundId; + if (currentSoundId != 255) { + if (currentSoundId == targetSoundId) { + currentVolume = min(currentVolume + 15, targetVolume); + return (currentVolume << 8) | currentSoundId; } else { - volume -= 9; - if (volume >= 80) - return (volume << 8) | soundId; + currentVolume -= 9; + if (currentVolume >= 80) + return (currentVolume << 8) | currentSoundId; } } - soundId = dl; - volume = bl == 255 ? 255 : bl / 4; + // Begin sound at quarter volume + currentSoundId = targetSoundId; + currentVolume = targetVolume == 255 ? 255 : targetVolume / 4; - return (volume << 8) | soundId; + return (currentVolume << 8) | currentSoundId; } /** @@ -585,18 +591,17 @@ static void vehicle_update_sound(rct_vehicle *vehicle) RCT2_CALLPROC_X(0x006D7888, 0, 0, 0, 0, (int)vehicle, 0, 0); return; // PROBLEMS - uint16 spriteIndex; rct_ride *ride; rct_ride_type *rideEntry; - rct_vehicle *vehicle2; + uint8 bl, dl = 255; + uint8 screamId, screamVolume; + uint16 soundIdVolume; ride = GET_RIDE(vehicle->ride); rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - uint16 ax = vehicle->var_B8; - uint8 al, ah, bl, bh, cl, dh, dl = 255; int ecx = abs(vehicle->velocity) - 0x10000; if (ecx >= 0) { dl = vehicleEntry->var_57; @@ -606,137 +611,65 @@ static void vehicle_update_sound(rct_vehicle *vehicle) bl = 255; } - if (vehicleEntry->var_59 == 3) { - dh = vehicle->var_CC; + switch (vehicleEntry->sound_range) { + case 3: + screamVolume = vehicle->scream_sound_id; if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x7F)) { - if (vehicle->velocity < 0x40000 || vehicle->var_CC != 255) + if (vehicle->velocity < 0x40000 || vehicle->scream_sound_id != 255) goto loc_6D7A97; if ((scenario_rand() & 0xFFFF) <= 0x5555) { - dh = 18; - goto loc_6D7A43; + vehicle->scream_sound_id = SOUND_TRAIN_WHISTLE; + screamId = 255; + break; } } + if (screamVolume != 254) screamVolume = 255; + screamId = 255; + break; - goto loc_6D7A4A; - } - if (vehicleEntry->var_59 == 4) { - dh = vehicle->var_CC; + case 4: + screamVolume = vehicle->scream_sound_id; if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x7F)) { - if (vehicle->velocity < 0x40000 || vehicle->var_CC != 255) + if (vehicle->velocity < 0x40000 || vehicle->scream_sound_id != 255) goto loc_6D7A97; if ((scenario_rand() & 0xFFFF) <= 0x5555) { - dh = 59; - goto loc_6D7A43; + vehicle->scream_sound_id = SOUND_TRAM; + screamId = 255; + break; } } - goto loc_6D7A4A; - } + if (screamVolume != 254) screamVolume = 255; + screamId = 255; + break; - if (!(vehicleEntry->var_14 & 0x10)) - goto loc_6D7A97; + default: + if ((vehicleEntry->var_14 & 0x10)) { + screamId = vehicle_update_scream_sound(vehicle); + if (screamId == 255) + goto loc_6D7A97; - uint8 ch = 0; - vehicle2 = vehicle; - for (;;) { - ch += vehicle2->num_peeps; - spriteIndex = vehicle2->next_vehicle_on_train; - if (spriteIndex == SPRITE_INDEX_NULL) + screamVolume = 255; break; - - vehicle2 = &(g_sprite_list[spriteIndex].vehicle); - } - if (ch != 0) { - if (vehicle->velocity < 0) { - if (vehicle->velocity > 0xFFFD4000) - goto loc_6D7A97; - - spriteIndex = vehicle->sprite_index; - do { - vehicle2 = &(g_sprite_list[spriteIndex].vehicle); - cl = vehicle2->var_1F; - if (cl < 1) - continue; - if (cl <= 4) - goto loc_6D79E2; - if (cl < 9) - continue; - if (cl <= 15) - goto loc_6D79E2; - } while ((spriteIndex = vehicle2->next_vehicle_on_train) != SPRITE_INDEX_NULL); - goto loc_6D7A97; } - if (vehicle->velocity < 0x2C000) - goto loc_6D7A97; - - spriteIndex = vehicle->sprite_index; - do { - vehicle2 = &(g_sprite_list[spriteIndex].vehicle); - cl = vehicle2->var_1F; - if (cl < 5) - continue; - if (cl <= 8) - goto loc_6D79E2; - if (cl < 17) - continue; - if (cl <= 23) - goto loc_6D79E2; - } while ((spriteIndex = vehicle2->next_vehicle_on_train) != SPRITE_INDEX_NULL); - goto loc_6D7A97; - - loc_6D79E2: - dh = vehicle->var_CC; - if (dh == 255) { - int eax = scenario_rand(); - al = eax & 0xFF; - ah = (eax >> 8) & 0xFF; - if (ah <= ch) { - switch (vehicleEntry->var_59) { - case 0: - eax = ((al * 2) >> 8) & 0xFF; - dh = RCT2_ADDRESS(0x009A3A14, uint8)[eax]; - goto loc_6D7A43; - case 1: - eax = ((al * 7) >> 8) & 0xFF; - dh = RCT2_ADDRESS(0x009A3A18, uint8)[eax]; - goto loc_6D7A43; - case 2: - eax = ((al * 2) >> 8) & 0xFF; - dh = RCT2_ADDRESS(0x009A3A16, uint8)[eax]; - goto loc_6D7A43; - } - } - dh = 254; - - loc_6D7A43: - dh = vehicle->var_CC; - } - - loc_6D7A4A: - if (dh != 254) - dh = 255; - - bh = 255; - goto loc_6D7AC0; + loc_6D7A97: + vehicle->scream_sound_id = 255; + screamVolume = RCT2_GLOBAL(0x0097D7C8 + (ride->type * 4), uint8); + screamId = 243; + if (!(vehicle->var_B8 & 2)) + screamVolume = 255; } -loc_6D7A97: - vehicle->var_CC = 255; - dh = RCT2_GLOBAL(0x0097D7C8 + (ride->type * 4), uint8); - bh = 243; - if (!(ax & 2)) - dh = 255; - -loc_6D7AC0: - ; - uint16 soundIdVolume; + // Friction sound soundIdVolume = sub_6D7AC0(vehicle->sound1_id, vehicle->sound1_volume, bl, dl); vehicle->sound1_id = soundIdVolume & 0xFF; vehicle->sound1_volume = (soundIdVolume >> 8) & 0xFF; - soundIdVolume = sub_6D7AC0(vehicle->sound2_id, vehicle->sound2_volume, bl, dl); + + // Scream sound + soundIdVolume = sub_6D7AC0(vehicle->sound2_id, vehicle->sound2_volume, screamId, screamVolume); vehicle->sound2_id = soundIdVolume & 0xFF; vehicle->sound2_volume = (soundIdVolume >> 8) & 0xFF; @@ -750,7 +683,91 @@ loc_6D7AC0: } /** +<<<<<<< 0bfcf9391dbd97ecf76b3e6440e443ad52442517 * +======= + * + * rct2: 0x006D796B + */ +static int vehicle_update_scream_sound(rct_vehicle *vehicle) +{ + int r; + uint16 spriteIndex; + rct_ride_type *rideEntry; + rct_vehicle *vehicle2; + + rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + int totalNumPeeps = vehicle_get_total_num_peeps(vehicle); + if (totalNumPeeps == 0) + return 255; + + if (vehicle->velocity < 0) { + if (vehicle->velocity > -0x2C000) + return 255; + + spriteIndex = vehicle->sprite_index; + do { + vehicle2 = &(g_sprite_list[spriteIndex].vehicle); + if (vehicle2->var_1F < 1) + continue; + if (vehicle2->var_1F <= 4) + goto produceScream; + if (vehicle2->var_1F < 9) + continue; + if (vehicle2->var_1F <= 15) + goto produceScream; + } while ((spriteIndex = vehicle2->next_vehicle_on_train) != SPRITE_INDEX_NULL); + return 255; + } + + if (vehicle->velocity < 0x2C000) + return 255; + + spriteIndex = vehicle->sprite_index; + do { + vehicle2 = &(g_sprite_list[spriteIndex].vehicle); + if (vehicle2->var_1F < 5) + continue; + if (vehicle2->var_1F <= 8) + goto produceScream; + if (vehicle2->var_1F < 17) + continue; + if (vehicle2->var_1F <= 23) + goto produceScream; + } while ((spriteIndex = vehicle2->next_vehicle_on_train) != SPRITE_INDEX_NULL); + return 255; + +produceScream: + if (vehicle->scream_sound_id == 255) { + r = scenario_rand(); + if (totalNumPeeps >= r % 16) { + switch (vehicleEntry->sound_range) { + case 0: + vehicle->scream_sound_id = byte_9A3A14[r % 2]; + break; + case 1: + vehicle->scream_sound_id = byte_9A3A18[r % 8]; + break; + case 2: + vehicle->scream_sound_id = byte_9A3A16[r % 2]; + break; + default: + vehicle->scream_sound_id = NO_SCREAM; + break; + } + } else { + vehicle->scream_sound_id = NO_SCREAM; + } + } + return vehicle->scream_sound_id; +} + +/** + * +>>>>>>> try to make sense of vehicle_update_sound * rct2: 0x006D73D0 * ax: verticalG * dx: lateralG @@ -927,3 +944,19 @@ rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle) rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); return &rideEntry->vehicles[vehicle->vehicle_type]; } + +int vehicle_get_total_num_peeps(rct_vehicle *vehicle) +{ + uint16 spriteIndex; + int numPeeps = 0; + for (;;) { + numPeeps += vehicle->num_peeps; + spriteIndex = vehicle->next_vehicle_on_train; + if (spriteIndex == SPRITE_INDEX_NULL) + break; + + vehicle = &(g_sprite_list[spriteIndex].vehicle); + } + + return numPeeps; +} diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 1f8f175f8b..7fa5ac8535 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -281,6 +281,7 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d bool sub_6DD365(rct_vehicle *vehicle); int sub_6DAB4C(rct_vehicle *vehicle, int *outStation); rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle); +int vehicle_get_total_num_peeps(rct_vehicle *vehicle); /** Helper macro until rides are stored in this module. */ #define GET_VEHICLE(sprite_index) &(g_sprite_list[sprite_index].vehicle) From 3f5bd269132e2cedb4b3e1c14719408316cb180b Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 12 Nov 2014 01:32:20 +0000 Subject: [PATCH 003/162] implement vehicle_update_doing_circus_show --- src/ride/vehicle.c | 116 ++++++++++++++++++++++++++++++++++++++------- src/ride/vehicle.h | 3 +- 2 files changed, 101 insertions(+), 18 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 1443d972e0..df8a68a9b3 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -33,11 +33,15 @@ #include "vehicle.h" static void vehicle_update(rct_vehicle *vehicle); -static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); -static void vehicle_update_waiting_to_depart(rct_vehicle *vehicle); -static void vehicle_update_departing(rct_vehicle *vehicle); -static void vehicle_update_travelling(rct_vehicle *vehicle); -static void vehicle_update_arriving(rct_vehicle *vehicle); + +static void vehicle_D6_255_update_moving_to_end_of_station(rct_vehicle *vehicle); +static void vehicle_D6_255_update_waiting_to_depart(rct_vehicle *vehicle); +static void vehicle_D6_255_update_departing(rct_vehicle *vehicle); +static void vehicle_D6_255_update_travelling(rct_vehicle *vehicle); +static void vehicle_D6_255_update_arriving(rct_vehicle *vehicle); + +static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); + static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -508,19 +512,19 @@ static void vehicle_update(rct_vehicle *vehicle) if (vehicle->ride_subtype == 255) { switch (vehicle->status) { case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: - vehicle_update_moving_to_end_of_station(vehicle); + vehicle_D6_255_update_moving_to_end_of_station(vehicle); break; case VEHICLE_STATUS_WAITING_TO_DEPART: - vehicle_update_waiting_to_depart(vehicle); + vehicle_D6_255_update_waiting_to_depart(vehicle); break; case VEHICLE_STATUS_DEPARTING: - vehicle_update_departing(vehicle); + vehicle_D6_255_update_departing(vehicle); break; case VEHICLE_STATUS_TRAVELLING: - vehicle_update_travelling(vehicle); + vehicle_D6_255_update_travelling(vehicle); break; case VEHICLE_STATUS_ARRIVING: - vehicle_update_arriving(vehicle); + vehicle_D6_255_update_arriving(vehicle); break; } return; @@ -549,39 +553,92 @@ static void vehicle_update(rct_vehicle *vehicle) } } - int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); - RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->var_51 << 8) | ride->mode, (int)vehicle, 0, 0); + switch (vehicle->status) { + case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: + case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: + case VEHICLE_STATUS_WAITING_TO_DEPART: + case VEHICLE_STATUS_DEPARTING: + case VEHICLE_STATUS_TRAVELLING: + case VEHICLE_STATUS_ARRIVING: + case VEHICLE_STATUS_UNLOADING_PASSENGERS: + case VEHICLE_STATUS_TRAVELLING_07: + case VEHICLE_STATUS_CRASHING: + case VEHICLE_STATUS_CRASHED: + case VEHICLE_STATUS_TRAVELLING_0A: + case VEHICLE_STATUS_SWINGING: + case VEHICLE_STATUS_ROTATING: + case VEHICLE_STATUS_ROTATING_0D: + case VEHICLE_STATUS_OPERATING: + case VEHICLE_STATUS_SHOWING_FILM: + case VEHICLE_STATUS_ROTATING_10: + case VEHICLE_STATUS_OPERATING_11: + case VEHICLE_STATUS_OPERATING_12: + case VEHICLE_STATUS_OPERATING_13: + case VEHICLE_STATUS_WAITING_FOR_CABLE_LIFT: + case VEHICLE_STATUS_TRAVELLING_15: + { + int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); + RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->var_51 << 8) | ride->mode, (int)vehicle, 0, 0); + } + break; + + case VEHICLE_STATUS_DOING_CIRCUS_SHOW: + vehicle_update_doing_circus_show(vehicle); + } vehicle_update_sound(vehicle); } -static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle) +static void vehicle_D6_255_update_moving_to_end_of_station(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF8A4, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_update_waiting_to_depart(rct_vehicle *vehicle) +static void vehicle_D6_255_update_waiting_to_depart(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF8F1, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_update_departing(rct_vehicle *vehicle) +static void vehicle_D6_255_update_departing(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF97A, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_update_travelling(rct_vehicle *vehicle) +static void vehicle_D6_255_update_travelling(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF99C, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_update_arriving(rct_vehicle *vehicle) +static void vehicle_D6_255_update_arriving(rct_vehicle *vehicle) { vehicle->var_51++; if (vehicle->var_51 >= 64) vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; } +/** + * + * rct2: 0x006D95F7 + */ +static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) +{ + int currentTime, totalTime; + + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + totalTime = *(RCT2_ADDRESS(0x009A0AB4, uint16*)[vehicle->var_51]); + currentTime = vehicle->var_4C + 1; + if (currentTime <= totalTime) { + vehicle->var_4C = currentTime; + } else { + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->var_51 = 0; + vehicle->var_C0 = 0; + } +} + /** * * rct2: 0x006D7888 @@ -960,3 +1017,28 @@ int vehicle_get_total_num_peeps(rct_vehicle *vehicle) return numPeeps; } + +/** + * + * rct2: 0x006DA1EC + */ +void vehicle_invalidate_window(rct_vehicle *vehicle) +{ + int viewVehicleIndex; + rct_ride *ride; + rct_window *w; + + w = window_find_by_number(WC_RIDE, vehicle->ride); + if (w == NULL) + return; + + ride = GET_RIDE(vehicle->ride); + viewVehicleIndex = w->ride.view - 1; + if (viewVehicleIndex < 0 || viewVehicleIndex >= ride->num_vehicles) + return; + + if (vehicle->sprite_index != ride->vehicles[viewVehicleIndex]) + return; + + window_invalidate(w); +} diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 7fa5ac8535..4ae4c5f8f9 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -149,7 +149,7 @@ typedef struct { uint8 sound2_id; // 0xBD uint8 sound2_volume; // 0xBE sint8 var_BF; - uint8 pad_C0[2]; + uint16 var_C0; uint8 speed; // 0xC2 uint8 acceleration; // 0xC3 uint8 var_C4; @@ -282,6 +282,7 @@ bool sub_6DD365(rct_vehicle *vehicle); int sub_6DAB4C(rct_vehicle *vehicle, int *outStation); rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle); int vehicle_get_total_num_peeps(rct_vehicle *vehicle); +void vehicle_invalidate_window(rct_vehicle *vehicle); /** Helper macro until rides are stored in this module. */ #define GET_VEHICLE(sprite_index) &(g_sprite_list[sprite_index].vehicle) From 5e198dfa1f59460597c3ba3a5a908ebfaa187ff0 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 3 Apr 2015 18:21:50 +0100 Subject: [PATCH 004/162] Add known ride offsets --- src/object.c | 5 ++++ src/ride/ride.c | 8 +++---- src/ride/ride.h | 58 +++++++++++++++++++++++++--------------------- src/windows/ride.c | 8 +++---- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/object.c b/src/object.c index 96badbb090..7307cea6a5 100644 --- a/src/object.c +++ b/src/object.c @@ -544,12 +544,14 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp b = rideVehicleEntry->var_16 * 80; image_index += b; } + // Verticle if (rideVehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_VERTICAL_SLOPES) { rideVehicleEntry->var_28 = image_index; b = rideVehicleEntry->var_16 * 116; image_index += b; } + // Unknown if (rideVehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_DIAGONAL_SLOPES) { rideVehicleEntry->var_2C = image_index; @@ -576,12 +578,14 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp b = rideVehicleEntry->var_16 * 128; image_index += b; } + // Unknown if (rideVehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_DIAGONAL_GENTLE_SLOPE_BANKED_TRANSITIONS) { rideVehicleEntry->var_3C = image_index; b = rideVehicleEntry->var_16 * 16; image_index += b; } + // Unknown if (rideVehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_GENTLE_SLOPE_BANKED_TRANSITIONS) { rideVehicleEntry->var_40 = image_index; @@ -606,6 +610,7 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp b = rideVehicleEntry->var_16 * 80; image_index += b; } + // Unknown if (rideVehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_RESTRAINT_ANIMATION) { rideVehicleEntry->var_1C = image_index; diff --git a/src/ride/ride.c b/src/ride/ride.c index 7340a3e298..354ccfc13c 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -6597,8 +6597,8 @@ void ride_update_max_vehicles(int rideIndex) int totalFriction = 0; for (int i = 0; i < numCars; i++) { vehicleEntry = &rideEntry->vehicles[trainLayout[i]]; - trainLength += vehicleEntry->var_04; - totalFriction += vehicleEntry->car_friction; + trainLength += vehicleEntry->spacing; + totalFriction += vehicleEntry->friction; } if (trainLength <= stationLength && totalFriction <= maxFriction) { @@ -6629,7 +6629,7 @@ void ride_update_max_vehicles(int rideIndex) trainLength = 0; for (int i = 0; i < newCarsPerTrain; i++) { vehicleEntry = &rideEntry->vehicles[trainLayout[i]]; - trainLength += vehicleEntry->var_04; + trainLength += vehicleEntry->spacing; } int totalLength = trainLength / 2; @@ -6655,7 +6655,7 @@ void ride_update_max_vehicles(int rideIndex) int totalSpacing = 0; for (int i = 0; i < newCarsPerTrain; i++) { vehicleEntry = &rideEntry->vehicles[trainLayout[i]]; - totalSpacing += vehicleEntry->var_04; + totalSpacing += vehicleEntry->spacing; } totalSpacing >>= 13; diff --git a/src/ride/ride.h b/src/ride/ride.h index 2bb2758fb7..ae8a5a8cd8 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -78,11 +78,11 @@ typedef struct{ uint16 var_00; // 0x00 , 0x1A uint8 var_02; // 0x02 , 0x1C uint8 var_03; // 0x03 , 0x1D - uint32 var_04; // 0x04 , 0x1E - uint16 var_08; // 0x08 , 0x22 + uint32 spacing; // 0x04 , 0x1E + uint16 friction; // 0x08 , 0x22 sint8 var_0A; // 0x0A , 0x24 uint8 pad_0B; - uint16 var_0C; // 0x0C , 0x26 + uint16 available_sprites; // 0x0C , 0x26 uint8 var_0E; // 0x0E , 0x28 uint8 var_0F; // 0x0F , 0x29 uint8 var_10; // 0x10 , 0x2A @@ -106,10 +106,11 @@ typedef struct{ uint32 var_4C; // 0x4C , 0x66 uint32 no_vehicle_images; // 0x50 , 0x6A uint8 no_seating_rows; // 0x54 , 0x6E - uint8 pad_55[0x2]; + uint8 spinning_inertia; // 0x55 , 0x6F + uint8 spinning_friction; // 0x56 , 0x70 uint8 var_57; // 0x57 , 0x71 uint8 pad_58; - uint8 sound_range; // 0x59 , 0x73 + uint8 sound_range; // 0x59 , 0x73 uint8 var_5A; // 0x5A , 0x74 uint8 pad_5B; // 0x5B , 0x75 uint8 var_5C; // 0x5C , 0x76 @@ -124,28 +125,33 @@ typedef struct{ * size: unknown */ typedef struct { - rct_string_id name; // 0x000 - rct_string_id description; // 0x002 - uint32 images_offset; // 0x004 - uint32 flags; // 0x008 - uint8 ride_type[3]; // 0x00C - uint8 min_cars_in_train; // 0x00F - uint8 max_cars_in_train; // 0x010 - uint8 cars_per_flat_ride; // 0x011 - uint8 zero_cars; // 0x012 - uint8 tab_vehicle; // 0x013 - uint8 default_vehicle; // 0x014 - uint8 front_vehicle; // 0x015 - uint8 second_vehicle; // 0x016 - uint8 rear_vehicle; // 0x017 - uint8 third_vehicle; // 0x018 + rct_string_id name; // 0x000 + rct_string_id description; // 0x002 + uint32 images_offset; // 0x004 + uint32 flags; // 0x008 + uint8 ride_type[3]; // 0x00C + uint8 min_cars_in_train; // 0x00F + uint8 max_cars_in_train; // 0x010 + uint8 cars_per_flat_ride; // 0x011 + // Number of cars that can't hold passengers + uint8 zero_cars; // 0x012 + // The index to the vehicle type displayed in + // the vehicle tab. + uint8 tab_vehicle; // 0x013 + uint8 default_vehicle; // 0x014 + // Convert from first - fourth vehicle to + // vehicle structure + uint8 front_vehicle; // 0x015 + uint8 second_vehicle; // 0x016 + uint8 rear_vehicle; // 0x017 + uint8 third_vehicle; // 0x018 uint8 pad_019; - rct_ride_type_vehicle vehicles[4]; // 0x01A - vehicle_colour_preset_list *vehicle_preset_list; // 0x1AE - sint8 excitement_multipler; // 0x1B2 - sint8 intensity_multipler; // 0x1B3 - sint8 nausea_multipler; // 0x1B4 - uint8 max_height; // 0x1B5 + rct_ride_type_vehicle vehicles[4]; // 0x1A + uint32 var_1AE; + sint8 excitement_multipler; // 0x1B2 + sint8 intensity_multipler; // 0x1B3 + sint8 nausea_multipler; // 0x1B4 + uint8 additional_max_height; // 0x1B5 union { uint64 enabledTrackPieces; // 0x1B6 struct { diff --git a/src/windows/ride.c b/src/windows/ride.c index b68086446c..5710b8b047 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -2647,8 +2647,8 @@ static void window_ride_vehicle_scrollpaint(rct_window *w, rct_drawpixelinfo *dp // For each car in train for (j = 0; j < ride->num_cars_per_train; j++) { rct_ride_type_vehicle* rideVehicleEntry = &rideEntry->vehicles[trainLayout[j]]; - x += rideVehicleEntry->var_04 / 17432; - y -= (rideVehicleEntry->var_04 / 2) / 17432; + x += rideVehicleEntry->spacing / 17432; + y -= (rideVehicleEntry->spacing / 2) / 17432; // Get colour of vehicle switch (ride->colour_scheme_type & 3) { @@ -2680,8 +2680,8 @@ static void window_ride_vehicle_scrollpaint(rct_window *w, rct_drawpixelinfo *dp nextSpriteToDraw->tertiary_colour = vehicleColour.additional_2; nextSpriteToDraw++; - x += rideVehicleEntry->var_04 / 17432; - y -= (rideVehicleEntry->var_04 / 2) / 17432; + x += rideVehicleEntry->spacing / 17432; + y -= (rideVehicleEntry->spacing / 2) / 17432; } if (ride->type == RIDE_TYPE_REVERSER_ROLLER_COASTER) { From 2ab0c7684bd2d5ddd7cf751ddf7b3f5f0028d9c3 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Apr 2015 09:38:37 +0100 Subject: [PATCH 005/162] Started work on 6d6d1f --- src/ride/ride.h | 15 ++++++-- src/ride/vehicle.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++ src/ride/vehicle.h | 2 +- 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index ae8a5a8cd8..6afd1124a3 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -232,13 +232,20 @@ typedef struct { // (in RCT2, display_speed = (max_speed * 9) >> 18) sint32 max_speed; // 0x0D8 sint32 average_speed; // 0x0DC - uint8 pad_0E0[4]; + uint8 var_0E0; + uint8 var_0E1; + uint8 pad_0E2[0x2]; sint32 length[4]; // 0x0E4 uint16 time[4]; // 0x0F4 fixed16_2dp max_positive_vertical_g; // 0x0FC fixed16_2dp max_negative_vertical_g; // 0x0FE fixed16_2dp max_lateral_g; // 0x100 - uint8 pad_102[0xC]; + fixed16_2dp previous_vertical_g;// 0x102 + fixed16_2dp previous_lateral_g; // 0x104 + uint8 pad_106[0x2]; + uint32 var_108; + // x y map location + uint16 var_10C; uint16 var_10E; uint16 var_110; uint16 var_112; @@ -253,7 +260,7 @@ typedef struct { uint8 var_116; uint8 highest_drop_height; // 0x117 sint32 sheltered_length; // 0x118 - uint8 pad_11C[0x2]; + uint16 var_11C; uint8 num_sheltered_sections; // 0x11E uint8 var_11F; sint16 var_120; @@ -358,7 +365,7 @@ typedef struct { uint32 lifecycle_flags; // 0x1D0 uint8 vehicle_colours_extended[32]; // 0x1D4 uint16 total_air_time; // 0x1F4 - uint8 pad_1F6; + uint8 var_1F6; uint8 num_circuits; // 0x1F7 sint16 cable_lift_x; // 0x1F8 sint16 cable_lift_y; // 0x1FA diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index df8a68a9b3..0871114590 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -475,6 +475,99 @@ static void sub_6D6D1F(rct_vehicle *vehicle) rct_ride *ride; ride = GET_RIDE(vehicle->ride); + + if (vehicle->status == VEHICLE_STATUS_TRAVELLING_07){ + ride->lifecycle_flags |= RIDE_LIFECYCLE_TESTED; + ride->lifecycle_flags |= RIDE_LIFECYCLE_NO_RAW_STATS; + ride->lifecycle_flags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; + vehicle->var_48 &= ~(1 << 1); + window_invalidate_by_number(WC_RIDE, vehicle->ride); + return; + } + + uint8 entrance = ride->var_1F6; + if (ride->entrances[entrance] != 0xFFFF){ + + //ecx + uint8 var_E0 = ride->var_0E0; + + ride->var_0E1++; + if (ride->var_0E1 >= 32)ride->var_0E1 = 0; + + sint32 velocity = abs(vehicle->velocity); + if (velocity > ride->max_speed){ + ride->max_speed = velocity; + } + + if (ride->var_0E1 == 0 && velocity > 0x8000){ + ride->average_speed += velocity; + ride->time[var_E0]++; + } + + sint32 distance = abs(((vehicle->velocity + vehicle->var_2C) / 1024) * 42); + if (vehicle->var_CE != 0){ + ride->length[var_E0] += distance; + } + + if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_HAS_G_FORCES){ + int vertical_g, lateral_g; + vehicle_get_g_forces(vehicle, &vertical_g, &lateral_g); + + vertical_g += ride->previous_vertical_g; + lateral_g += ride->previous_lateral_g; + vertical_g /= 2; + lateral_g /= 2; + + ride->previous_vertical_g = vertical_g; + ride->previous_lateral_g = lateral_g; + + if (vertical_g <= 0){ + ride->total_air_time++; + } + + if (vertical_g > ride->max_positive_vertical_g) + ride->max_positive_vertical_g = vertical_g; + + if (vertical_g < ride->max_negative_vertical_g) + ride->max_negative_vertical_g = vertical_g; + + lateral_g = abs(lateral_g); + + if (lateral_g > ride->max_lateral_g) + ride->max_lateral_g = lateral_g; + } + } + + uint16 map_location = (vehicle->var_38 / 32) | ((vehicle->var_3A / 32) << 8); + if (vehicle->var_3C / 8 != ride->var_11F && map_location != ride->var_10C){ + ride->var_11F = vehicle->var_3C / 8; + ride->var_10C = map_location; + + if (ride->entrances[ride->var_1F6] != 0xFFFF){ + + sint16 var_36 = vehicle->var_36 / 4; + if (var_36 == 182 || !(vehicle->var_48 & (1<<0))){ + if (!(ride->var_108 & (1 << 6))){ + ride->var_108 |= (1 << 6); + if (ride->drops + 64 < 0xFF){ + ride->drops += 64; + } + } + } + else{ + ride->var_108 &= ~(1 << 6); + } + + if (ride->type == RIDE_TYPE_WATER_COASTER){ + if (var_36 >= 68 && var_36 < 87){ + ride->special_track_elements |= (1 << 5); + } + } + + //0x6d6edf + } + } + //6d7211 RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)ride, 0); } diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 4ae4c5f8f9..9ab2cd7759 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -106,7 +106,7 @@ typedef struct { uint8 pad_21[3]; uint32 var_24; sint32 velocity; // 0x28 - uint32 var_2C; + sint32 var_2C; uint8 ride; // 0x30 uint8 vehicle_type; // 0x31 rct_vehicle_colour colours; // 0x32 From 79fb099c2129f3d4ed58e0c258bde93d4f894744 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Apr 2015 12:36:02 +0100 Subject: [PATCH 006/162] Added more of update measurements --- src/peep/peep.c | 3 +- src/ride/ride.c | 7 ++- src/ride/ride.h | 1 + src/ride/track.h | 36 +++++++------- src/ride/vehicle.c | 117 ++++++++++++++++++++++++++++++++++++++++++--- src/windows/ride.c | 7 ++- 6 files changed, 144 insertions(+), 27 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index 7961c49e17..13e2e32f2e 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -37,6 +37,7 @@ #include "../world/footpath.h" #include "../management/marketing.h" #include "../game.h" +#include "../ride/track.h" #include "peep.h" #include "staff.h" @@ -2326,7 +2327,7 @@ void peep_update_ride_sub_state_7(rct_peep* peep){ for (; vehicle->is_child; vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride)){ uint16 trackType = vehicle->track_type >> 2; - if (trackType == 0 || trackType > 3) + if (trackType == TRACK_ELEM_FLAT || trackType > TRACK_ELEM_MIDDLE_STATION) continue; rct_map_element* inner_map = map_get_first_element_at(vehicle->track_x / 32, vehicle->track_y / 32); diff --git a/src/ride/ride.c b/src/ride/ride.c index 354ccfc13c..bcfc7a43d1 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -2703,7 +2703,12 @@ void ride_measurement_update(rct_ride_measurement *measurement) } uint8 trackType = (vehicle->track_type >> 2) & 0xFF; - if (trackType == 216 || trackType == 123 || trackType == 9 || trackType == 63 || trackType == 147 || trackType == 155) + if (trackType == 216 || + trackType == TRACK_ELEM_CABLE_LIFT_HILL || + trackType == TRACK_ELEM_25_DEG_UP_TO_FLAT || + trackType == TRACK_ELEM_60_DEG_UP_TO_FLAT || + trackType == TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT || + trackType == TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT) if (vehicle->velocity == 0) return; diff --git a/src/ride/ride.h b/src/ride/ride.h index 6afd1124a3..c488eca176 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -246,6 +246,7 @@ typedef struct { uint32 var_108; // x y map location uint16 var_10C; + // Next 3 variables are related (XXXX XYYY ZZZa aaaa) uint16 var_10E; uint16 var_110; uint16 var_112; diff --git a/src/ride/track.h b/src/ride/track.h index 5690767666..c14c3366fb 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -311,7 +311,7 @@ enum { TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP, TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP, TRACK_ELEM_25_DEG_UP_TO_FLAT, - TRACK_ELEM_25_DEG_DOWN, + TRACK_ELEM_25_DEG_DOWN = 10, TRACK_ELEM_60_DEG_DOWN, TRACK_ELEM_FLAT_TO_25_DEG_DOWN, TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN, @@ -321,7 +321,7 @@ enum { TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES, TRACK_ELEM_FLAT_TO_LEFT_BANK, TRACK_ELEM_FLAT_TO_RIGHT_BANK, - TRACK_ELEM_LEFT_BANK_TO_FLAT, + TRACK_ELEM_LEFT_BANK_TO_FLAT = 20, TRACK_ELEM_RIGHT_BANK_TO_FLAT, TRACK_ELEM_BANKED_LEFT_QUARTER_TURN_5_TILES, TRACK_ELEM_BANKED_RIGHT_QUARTER_TURN_5_TILES, @@ -331,7 +331,7 @@ enum { TRACK_ELEM_25_DEG_UP_TO_RIGHT_BANK, TRACK_ELEM_LEFT_BANK_TO_25_DEG_DOWN, TRACK_ELEM_RIGHT_BANK_TO_25_DEG_DOWN, - TRACK_ELEM_25_DEG_DOWN_TO_LEFT_BANK, + TRACK_ELEM_25_DEG_DOWN_TO_LEFT_BANK = 30, TRACK_ELEM_25_DEG_DOWN_TO_RIGHT_BANK, TRACK_ELEM_LEFT_BANK, TRACK_ELEM_RIGHT_BANK, @@ -341,7 +341,7 @@ enum { TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_DOWN, TRACK_ELEM_S_BEND_LEFT, TRACK_ELEM_S_BEND_RIGHT, - TRACK_ELEM_LEFT_VERTICAL_LOOP, + TRACK_ELEM_LEFT_VERTICAL_LOOP = 40, TRACK_ELEM_RIGHT_VERTICAL_LOOP, TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES, TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES, @@ -351,7 +351,7 @@ enum { TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP, TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN, TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN, - TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE, + TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE = 50, TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE, TRACK_ELEM_LEFT_TWIST_DOWN_TO_UP, TRACK_ELEM_RIGHT_TWIST_DOWN_TO_UP, @@ -361,7 +361,7 @@ enum { TRACK_ELEM_HALF_LOOP_DOWN, TRACK_ELEM_LEFT_CORKSCREW_UP, TRACK_ELEM_RIGHT_CORKSCREW_UP, - TRACK_ELEM_LEFT_CORKSCREW_DOWN, + TRACK_ELEM_LEFT_CORKSCREW_DOWN = 60, TRACK_ELEM_RIGHT_CORKSCREW_DOWN, TRACK_ELEM_FLAT_TO_60_DEG_UP, TRACK_ELEM_60_DEG_UP_TO_FLAT, @@ -371,7 +371,7 @@ enum { TRACK_ELEM_TOWER_SECTION, TRACK_ELEM_FLAT_COVERED, TRACK_ELEM_25_DEG_UP_COVERED, - TRACK_ELEM_60_DEG_UP_COVERED, + TRACK_ELEM_60_DEG_UP_COVERED = 70, TRACK_ELEM_FLAT_TO_25_DEG_UP_COVERED, TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP_COVERED, TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP_COVERED, @@ -381,7 +381,7 @@ enum { TRACK_ELEM_FLAT_TO_25_DEG_DOWN_COVERED, TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN_COVERED, TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN_COVERED, - TRACK_ELEM_25_DEG_DOWN_TO_FLAT_COVERED, + TRACK_ELEM_25_DEG_DOWN_TO_FLAT_COVERED = 80, TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_COVERED, TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_COVERED, TRACK_ELEM_S_BEND_LEFT_COVERED, @@ -391,7 +391,7 @@ enum { TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_SMALL, TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_SMALL, TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_SMALL, - TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_SMALL, + TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_SMALL = 90, TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_LARGE, TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_LARGE, TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_LARGE, @@ -401,7 +401,7 @@ enum { TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_DOWN, TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_DOWN, TRACK_ELEM_BRAKES, - TRACK_ELEM_ROTATION_CONTROL_TOGGLE, + TRACK_ELEM_ROTATION_CONTROL_TOGGLE = 100, TRACK_ELEM_INVERTED_90_DEG_UP_TO_FLAT_QUARTER_LOOP, TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_UP, TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_UP, @@ -411,7 +411,7 @@ enum { TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_UP, TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_DOWN, TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_DOWN, - TRACK_ELEM_25_DEG_UP_LEFT_BANKED, + TRACK_ELEM_25_DEG_UP_LEFT_BANKED = 110, TRACK_ELEM_25_DEG_UP_RIGHT_BANKED, TRACK_ELEM_WATERFALL, TRACK_ELEM_RAPIDS, @@ -421,7 +421,7 @@ enum { TRACK_ELEM_WATER_SPLASH, TRACK_ELEM_FLAT_TO_60_DEG_UP_LONG_BASE, TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE, - TRACK_ELEM_WHIRLPOOL, + TRACK_ELEM_WHIRLPOOL = 120, TRACK_ELEM_FLAT_TO_60_DEG_DOWN_LONG_BASE, TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE_122, TRACK_ELEM_CABLE_LIFT_HILL, @@ -431,7 +431,7 @@ enum { TRACK_ELEM_90_DEG_DOWN, TRACK_ELEM_60_DEG_UP_TO_90_DEG_UP, TRACK_ELEM_90_DEG_DOWN_TO_60_DEG_DOWN, - TRACK_ELEM_90_DEG_UP_TO_60_DEG_UP, + TRACK_ELEM_90_DEG_UP_TO_60_DEG_UP = 130, TRACK_ELEM_60_DEG_DOWN_TO_90_DEG_DOWN, TRACK_ELEM_BRAKE_FOR_DROP, TRACK_ELEM_LEFT_EIGHTH_TO_DIAG, @@ -441,7 +441,7 @@ enum { TRACK_ELEM_LEFT_EIGHTH_BANK_TO_DIAG, TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_DIAG, TRACK_ELEM_LEFT_EIGHTH_BANK_TO_ORTHOGONAL, - TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_ORTHOGONAL, + TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_ORTHOGONAL = 140, TRACK_ELEM_DIAG_FLAT, TRACK_ELEM_DIAG_25_DEG_UP, TRACK_ELEM_DIAG_60_DEG_UP, @@ -451,7 +451,7 @@ enum { TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT, TRACK_ELEM_DIAG_25_DEG_DOWN, TRACK_ELEM_DIAG_60_DEG_DOWN, - TRACK_ELEM_DIAG_FLAT_TO_25_DEG_DOWN, + TRACK_ELEM_DIAG_FLAT_TO_25_DEG_DOWN = 150, TRACK_ELEM_DIAG_25_DEG_DOWN_TO_60_DEG_DOWN, TRACK_ELEM_DIAG_60_DEG_DOWN_TO_25_DEG_DOWN, TRACK_ELEM_DIAG_25_DEG_DOWN_TO_FLAT, @@ -461,7 +461,7 @@ enum { TRACK_ELEM_DIAG_60_DEG_DOWN_TO_FLAT, TRACK_ELEM_DIAG_FLAT_TO_LEFT_BANK, TRACK_ELEM_DIAG_FLAT_TO_RIGHT_BANK, - TRACK_ELEM_DIAG_LEFT_BANK_TO_FLAT, + TRACK_ELEM_DIAG_LEFT_BANK_TO_FLAT = 160, TRACK_ELEM_DIAG_RIGHT_BANK_TO_FLAT, TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_UP, TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_UP, @@ -471,7 +471,7 @@ enum { TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_DOWN, TRACK_ELEM_DIAG_25_DEG_DOWN_TO_LEFT_BANK, TRACK_ELEM_DIAG_25_DEG_DOWN_TO_RIGHT_BANK, - TRACK_ELEM_DIAG_LEFT_BANK, + TRACK_ELEM_DIAG_LEFT_BANK = 170, TRACK_ELEM_DIAG_RIGHT_BANK, TRACK_ELEM_LOG_FLUME_REVERSER, TRACK_ELEM_SPINNING_TUNNEL, @@ -481,7 +481,7 @@ enum { TRACK_ELEM_RIGHT_BARREL_ROLL_DOWN_TO_UP, TRACK_ELEM_LEFT_BANK_TO_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP, TRACK_ELEM_RIGHT_BANK_TO_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP, - TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_LEFT_BANK, + TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_LEFT_BANK = 180, TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_RIGHT_BANK, TRACK_ELEM_POWERED_LIFT, TRACK_ELEM_LEFT_LARGE_HALF_LOOP_UP, diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 0871114590..a33dd853bc 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -27,6 +27,7 @@ #include "../openrct2.h" #include "../scenario.h" #include "../world/sprite.h" +#include "track.h" #include "ride.h" #include "ride_data.h" #include "track.h" @@ -545,8 +546,8 @@ static void sub_6D6D1F(rct_vehicle *vehicle) if (ride->entrances[ride->var_1F6] != 0xFFFF){ - sint16 var_36 = vehicle->var_36 / 4; - if (var_36 == 182 || !(vehicle->var_48 & (1<<0))){ + uint16 track_elem_type = vehicle->track_type / 4; + if (track_elem_type == TRACK_ELEM_POWERED_LIFT || !(vehicle->var_48 & (1 << 0))){ if (!(ride->var_108 & (1 << 6))){ ride->var_108 |= (1 << 6); if (ride->drops + 64 < 0xFF){ @@ -559,16 +560,121 @@ static void sub_6D6D1F(rct_vehicle *vehicle) } if (ride->type == RIDE_TYPE_WATER_COASTER){ - if (var_36 >= 68 && var_36 < 87){ + if (track_elem_type >= TRACK_ELEM_FLAT_COVERED && track_elem_type <= TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED){ ride->special_track_elements |= (1 << 5); } } - //0x6d6edf + switch (track_elem_type) + { + case TRACK_ELEM_RAPIDS: + case TRACK_ELEM_SPINNING_TUNNEL: + ride->special_track_elements |= (1 << 5); + break; + case TRACK_ELEM_WATERFALL: + case TRACK_ELEM_LOG_FLUME_REVERSER: + ride->special_track_elements |= (1 << 6); + break; + case TRACK_ELEM_WHIRLPOOL: + ride->special_track_elements |= (1 << 7); + break; + case TRACK_ELEM_WATER_SPLASH: + if (vehicle->velocity >= 0xB0000){ + ride->special_track_elements |= (1 << 5); + } + } + + // ax + uint16 flags = RCT2_ADDRESS(0x0099423C, uint16)[track_elem_type]; + + uint32 var_108 = ride->var_108; + if (var_108 & (1 << 1) && flags & (1 << 1)){ + ride->var_10E += 0x800; + } + else if (!(flags & (1 << 2))){ + if (flags & (1 << 1)){ + ride->var_108 |= (1 << 1); + ride->var_10E &= 0x7FF; + + if (flags & (1 << 3)){ + ride->var_108 |= (1 << 3); + } + if (flags & (1 << 4)){ + ride->var_108 |= (1 << 4); + } + } + + if (flags & (1 << 2)){ + ride->var_108 |= (1 << 2); + ride->var_10E &= 0x7FF; + + if (flags & (1 << 3)){ + ride->var_108 |= (1 << 3); + } + if (flags & (1 << 4)){ + ride->var_108 |= (1 << 4); + } + } + } + else if (var_108 & (1 << 2)){ + ride->var_10E += 0x800; + } + else{ + ride->var_108 &= ~(0x6); + ride->var_108 &= ~(0x18); + + uint16* ebp = &ride->var_110; + if (!(var_108 & (1 << 3))){ + ebp = &ride->var_112; + if (!(var_108 & (1 << 4))){ + ebp = &ride->var_10E; + } + } + uint16 bx; + switch (ride->var_10E >> 11){ + case 0: + bx = *ebp & 0x1F; + if (bx != 0x1F){ + bx++; + } + *ebp &= 0xFFE0; + *ebp |= bx; + break; + case 1: + bx = *ebp & 0xE0; + if (bx != 0xE0){ + bx += 0x20; + } + *ebp &= 0xFF1F; + *ebp |= bx; + break; + default: + if (var_108&(1 << 4)){ + bx = *ebp & 0xF800; + if (bx != 0xF800){ + bx += 0x800; + } + *ebp &= 0x7FF; + *ebp |= bx; + break; + } + // fall through to case 2 + case 2: + bx = *ebp & 0x700; + if (bx != 0x700){ + bx += 0x100; + } + *ebp &= 0xF8FF; + *ebp |= bx; + break; + } + } + + //6d70b8 } } //6d7211 - RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)ride, 0); + RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)vehicle->ride, 0); } static uint16 sub_6D7AC0(int currentSoundId, int currentVolume, int targetSoundId, int targetVolume) @@ -917,7 +1023,6 @@ produceScream: /** * ->>>>>>> try to make sense of vehicle_update_sound * rct2: 0x006D73D0 * ax: verticalG * dx: lateralG diff --git a/src/windows/ride.c b/src/windows/ride.c index 5710b8b047..faac53d803 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -2114,7 +2114,12 @@ static rct_string_id window_ride_get_status_vehicle(rct_window *w, void *argumen vehicle = &(g_sprite_list[vehicleSpriteIndex].vehicle); if (vehicle->status != VEHICLE_STATUS_CRASHING && vehicle->status != VEHICLE_STATUS_CRASHED) { int trackType = vehicle->track_type >> 2; - if (trackType == 216 || trackType == 123 || trackType == 9 || trackType == 63 || trackType == 147 || trackType == 155) { + if (trackType == 216 || + trackType == TRACK_ELEM_CABLE_LIFT_HILL || + trackType == TRACK_ELEM_25_DEG_UP_TO_FLAT || + trackType == TRACK_ELEM_60_DEG_UP_TO_FLAT || + trackType == TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT || + trackType == TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT) { if ((RCT2_ADDRESS(0x01357644, uint32)[ride->type] & 0x40) && vehicle->velocity == 0) { RCT2_GLOBAL((int)arguments + 0, uint16) = STR_STOPPED_BY_BLOCK_BRAKES; return 1191; From d9511910deab40ae2d1579f05fc70026a89d5d70 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Apr 2015 15:57:08 +0100 Subject: [PATCH 007/162] Finish vehicle_update_measurements --- src/ride/ride.h | 2 +- src/ride/vehicle.c | 155 +++++++++++++++++++++++++++++++++++++++++---- src/ride/vehicle.h | 1 + 3 files changed, 145 insertions(+), 13 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index c488eca176..9b9d6d594b 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -258,7 +258,7 @@ typedef struct { uint8 undercover_portion; // 0x114 (XXX?-????) }; uint8 drops; // 0x115 (??XX XXXX) - uint8 var_116; + uint8 start_drop_height; // 0x116 uint8 highest_drop_height; // 0x117 sint32 sheltered_length; // 0x118 uint16 var_11C; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index a33dd853bc..3561ae09b3 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -27,6 +27,7 @@ #include "../openrct2.h" #include "../scenario.h" #include "../world/sprite.h" +#include "../world/scenery.h" #include "track.h" #include "ride.h" #include "ride_data.h" @@ -471,11 +472,14 @@ void vehicle_update_all() } } -static void sub_6D6D1F(rct_vehicle *vehicle) +/* rct2: 0x006D6D1F */ +static void vehicle_update_measurements(rct_vehicle *vehicle) { rct_ride *ride; ride = GET_RIDE(vehicle->ride); + //RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)vehicle->ride, 0); + //return; if (vehicle->status == VEHICLE_STATUS_TRAVELLING_07){ ride->lifecycle_flags |= RIDE_LIFECYCLE_TESTED; @@ -506,7 +510,7 @@ static void sub_6D6D1F(rct_vehicle *vehicle) } sint32 distance = abs(((vehicle->velocity + vehicle->var_2C) / 1024) * 42); - if (vehicle->var_CE != 0){ + if (vehicle->var_CE == 0){ ride->length[var_E0] += distance; } @@ -540,7 +544,7 @@ static void sub_6D6D1F(rct_vehicle *vehicle) } uint16 map_location = (vehicle->var_38 / 32) | ((vehicle->var_3A / 32) << 8); - if (vehicle->var_3C / 8 != ride->var_11F && map_location != ride->var_10C){ + if (vehicle->var_3C / 8 != ride->var_11F || map_location != ride->var_10C){ ride->var_11F = vehicle->var_3C / 8; ride->var_10C = map_location; @@ -561,7 +565,7 @@ static void sub_6D6D1F(rct_vehicle *vehicle) if (ride->type == RIDE_TYPE_WATER_COASTER){ if (track_elem_type >= TRACK_ELEM_FLAT_COVERED && track_elem_type <= TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED){ - ride->special_track_elements |= (1 << 5); + ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; } } @@ -569,18 +573,18 @@ static void sub_6D6D1F(rct_vehicle *vehicle) { case TRACK_ELEM_RAPIDS: case TRACK_ELEM_SPINNING_TUNNEL: - ride->special_track_elements |= (1 << 5); + ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; break; case TRACK_ELEM_WATERFALL: case TRACK_ELEM_LOG_FLUME_REVERSER: - ride->special_track_elements |= (1 << 6); + ride->special_track_elements |= RIDE_ELEMENT_REVERSER_OR_WATERFALL; break; case TRACK_ELEM_WHIRLPOOL: - ride->special_track_elements |= (1 << 7); + ride->special_track_elements |= RIDE_ELEMENT_WHIRLPOOL; break; case TRACK_ELEM_WATER_SPLASH: if (vehicle->velocity >= 0xB0000){ - ride->special_track_elements |= (1 << 5); + ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; } } @@ -670,11 +674,138 @@ static void sub_6D6D1F(rct_vehicle *vehicle) } } - //6d70b8 + if (var_108 & (1 << 5)){ + if (vehicle->velocity < 0 || !(flags & (1 << 5))){ + ride->var_108 &= ~(1 << 5); + + sint16 z = vehicle->z / 8 - ride->start_drop_height; + if (z < 0){ + z = abs(z); + if (z > ride->highest_drop_height){ + ride->highest_drop_height = (uint8)z; + } + } + } + } + else if (flags & (1 << 5) && vehicle->velocity >= 0){ + ride->var_108 &= ~(1 << 7); + ride->var_108 |= (1 << 5); + + uint8 drops = ride->drops & 0x3F; + if (drops != 0x3F) + drops++; + ride->drops &= ~0x3F; + ride->drops |= drops; + + ride->start_drop_height = vehicle->z / 8; + var_108 &= ~(1 << 7); + } + + if (var_108 & (1 << 7)){ + if (vehicle->velocity > 0 || !(flags & (1 << 6))){ + ride->var_108 &= ~(1 << 7); + + sint16 z = vehicle->z / 8 - ride->start_drop_height; + if (z < 0){ + z = abs(z); + if (z > ride->highest_drop_height){ + ride->highest_drop_height = (uint8)z; + } + } + } + } + else if (flags & (1 << 6) && vehicle->velocity <= 0){ + ride->var_108 &= ~(1 << 5); + ride->var_108 |= (1 << 7); + + uint8 drops = ride->drops & 0x3F; + if (drops != 0x3F) + drops++; + ride->drops &= ~0x3F; + ride->drops |= drops; + + ride->start_drop_height = vehicle->z / 8; + var_108 &= ~(1 << 7); + } + + if (flags & (1 << 7)){ + uint8 inversions = ride->inversions & 0x1F; + if (inversions != 0x1F) + inversions++; + + ride->inversions &= ~0x1F; + ride->inversions |= inversions; + } + + if (flags & (1 << 11)){ + uint8 helixes = ride_get_helix_sections(ride); + if (helixes != 0x1F) + helixes++; + + ride->special_track_elements &= ~0x1F; + ride->special_track_elements |= helixes; + } } } - //6d7211 - RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)vehicle->ride, 0); + + if (ride->entrances[ride->var_1F6] == 0xFFFF) + return; + + sint16 x, y; + x = vehicle->x; + y = vehicle->y; + + if (x == SPRITE_LOCATION_NULL){ + ride->var_108 &= (1 << 0); + return; + } + + rct_map_element* map_element = map_get_surface_element_at(x / 32, y / 32); + if (map_element->base_height * 8 > vehicle->z){ + + for (;; map_element++){ + if (map_element_is_last_for_tile(map_element)){ + ride->var_108 &= (1 << 0); + return; + } + + if (map_element_get_type(map_element) == MAP_ELEMENT_TYPE_SCENERY_MULTIPLE) + break; + + if (map_element_get_type(map_element) == MAP_ELEMENT_TYPE_PATH) + break; + + if (map_element_get_type(map_element) != MAP_ELEMENT_TYPE_SCENERY) + continue; + + rct_scenery_entry* scenery = (rct_scenery_entry*)object_entry_groups[OBJECT_TYPE_SMALL_SCENERY].chunks[map_element->properties.scenery.type]; + if (scenery->small_scenery.flags & SMALL_SCENERY_FLAG_FULL_TILE) + break; + } + } + + if (!(ride->var_108 & (1 << 0))){ + ride->var_108 |= (1 << 0); + + uint8 num_sheltered_sections = ride->num_sheltered_sections & 0x1F; + if (num_sheltered_sections != 0x1F) + num_sheltered_sections++; + ride->num_sheltered_sections &= ~0x1F; + ride->num_sheltered_sections |= num_sheltered_sections; + + if (vehicle->var_1F != 0){ + ride->num_sheltered_sections |= (1 << 5); + } + + if (vehicle->var_20 != 0){ + ride->num_sheltered_sections |= (1 << 6); + } + } + + sint32 distance = ((vehicle->velocity + vehicle->var_2C) / 1024) * 42; + if (distance < 0)return; + + ride->sheltered_length += distance; } static uint16 sub_6D7AC0(int currentSoundId, int currentVolume, int targetSoundId, int targetVolume) @@ -735,7 +866,7 @@ static void vehicle_update(rct_vehicle *vehicle) ride = GET_RIDE(vehicle->ride); if (vehicle->var_48 & 0x20) - sub_6D6D1F(vehicle); + vehicle_update_measurements(vehicle); RCT2_GLOBAL(0x00F64E34, uint8) = 255; if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) { diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 9ab2cd7759..ed70a7b72f 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -105,6 +105,7 @@ typedef struct { uint8 var_20; uint8 pad_21[3]; uint32 var_24; + uint8 pad_21[0x07]; sint32 velocity; // 0x28 sint32 var_2C; uint8 ride; // 0x30 From 59736c7b4aedc1ff31f9521ecfc0fd9e793bbf3b Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Apr 2015 18:28:42 +0100 Subject: [PATCH 008/162] Refactor and name flags --- src/ride/track.h | 11 ++ src/ride/vehicle.c | 389 +++++++++++++++++++++++---------------------- 2 files changed, 206 insertions(+), 194 deletions(-) diff --git a/src/ride/track.h b/src/ride/track.h index c14c3366fb..102bc4ccea 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -300,6 +300,17 @@ enum { TRACK_CORKSCREW_DOWN = 224 }; +enum { + TRACK_ELEM_FLAG_TURN_LEFT = (1 << 1), + TRACK_ELEM_FLAG_TURN_RIGHT = (1 << 2), + TRACK_ELEM_FLAG_TURN_BANKED = (1 << 3), + TRACK_ELEM_FLAG_TURN_SLOPED = (1 << 4), + TRACK_ELEM_FLAG_DOWN = (1 << 5), + TRACK_ELEM_FLAG_UP = (1 << 6), + TRACK_ELEM_FLAG_INVERSION = (1 << 7), + TRACK_ELEM_FLAG_HELIX = (1 << 11), +}; + enum { TRACK_ELEM_FLAT, TRACK_ELEM_END_STATION, diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 3561ae09b3..dede3779aa 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -548,204 +548,205 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) ride->var_11F = vehicle->var_3C / 8; ride->var_10C = map_location; - if (ride->entrances[ride->var_1F6] != 0xFFFF){ + if (ride->entrances[ride->var_1F6] == 0xFFFF) + return; - uint16 track_elem_type = vehicle->track_type / 4; - if (track_elem_type == TRACK_ELEM_POWERED_LIFT || !(vehicle->var_48 & (1 << 0))){ - if (!(ride->var_108 & (1 << 6))){ - ride->var_108 |= (1 << 6); - if (ride->drops + 64 < 0xFF){ - ride->drops += 64; - } + uint16 track_elem_type = vehicle->track_type / 4; + if (track_elem_type == TRACK_ELEM_POWERED_LIFT || !(vehicle->var_48 & (1 << 0))){ + if (!(ride->var_108 & (1 << 6))){ + ride->var_108 |= (1 << 6); + if (ride->drops + 64 < 0xFF){ + ride->drops += 64; } } - else{ - ride->var_108 &= ~(1 << 6); - } - - if (ride->type == RIDE_TYPE_WATER_COASTER){ - if (track_elem_type >= TRACK_ELEM_FLAT_COVERED && track_elem_type <= TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED){ - ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; - } - } - - switch (track_elem_type) - { - case TRACK_ELEM_RAPIDS: - case TRACK_ELEM_SPINNING_TUNNEL: - ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; - break; - case TRACK_ELEM_WATERFALL: - case TRACK_ELEM_LOG_FLUME_REVERSER: - ride->special_track_elements |= RIDE_ELEMENT_REVERSER_OR_WATERFALL; - break; - case TRACK_ELEM_WHIRLPOOL: - ride->special_track_elements |= RIDE_ELEMENT_WHIRLPOOL; - break; - case TRACK_ELEM_WATER_SPLASH: - if (vehicle->velocity >= 0xB0000){ - ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; - } - } - - // ax - uint16 flags = RCT2_ADDRESS(0x0099423C, uint16)[track_elem_type]; - - uint32 var_108 = ride->var_108; - if (var_108 & (1 << 1) && flags & (1 << 1)){ - ride->var_10E += 0x800; - } - else if (!(flags & (1 << 2))){ - if (flags & (1 << 1)){ - ride->var_108 |= (1 << 1); - ride->var_10E &= 0x7FF; - - if (flags & (1 << 3)){ - ride->var_108 |= (1 << 3); - } - if (flags & (1 << 4)){ - ride->var_108 |= (1 << 4); - } - } - - if (flags & (1 << 2)){ - ride->var_108 |= (1 << 2); - ride->var_10E &= 0x7FF; - - if (flags & (1 << 3)){ - ride->var_108 |= (1 << 3); - } - if (flags & (1 << 4)){ - ride->var_108 |= (1 << 4); - } - } - } - else if (var_108 & (1 << 2)){ - ride->var_10E += 0x800; - } - else{ - ride->var_108 &= ~(0x6); - ride->var_108 &= ~(0x18); - - uint16* ebp = &ride->var_110; - if (!(var_108 & (1 << 3))){ - ebp = &ride->var_112; - if (!(var_108 & (1 << 4))){ - ebp = &ride->var_10E; - } - } - uint16 bx; - switch (ride->var_10E >> 11){ - case 0: - bx = *ebp & 0x1F; - if (bx != 0x1F){ - bx++; - } - *ebp &= 0xFFE0; - *ebp |= bx; - break; - case 1: - bx = *ebp & 0xE0; - if (bx != 0xE0){ - bx += 0x20; - } - *ebp &= 0xFF1F; - *ebp |= bx; - break; - default: - if (var_108&(1 << 4)){ - bx = *ebp & 0xF800; - if (bx != 0xF800){ - bx += 0x800; - } - *ebp &= 0x7FF; - *ebp |= bx; - break; - } - // fall through to case 2 - case 2: - bx = *ebp & 0x700; - if (bx != 0x700){ - bx += 0x100; - } - *ebp &= 0xF8FF; - *ebp |= bx; - break; - } - } - - if (var_108 & (1 << 5)){ - if (vehicle->velocity < 0 || !(flags & (1 << 5))){ - ride->var_108 &= ~(1 << 5); - - sint16 z = vehicle->z / 8 - ride->start_drop_height; - if (z < 0){ - z = abs(z); - if (z > ride->highest_drop_height){ - ride->highest_drop_height = (uint8)z; - } - } - } - } - else if (flags & (1 << 5) && vehicle->velocity >= 0){ - ride->var_108 &= ~(1 << 7); - ride->var_108 |= (1 << 5); - - uint8 drops = ride->drops & 0x3F; - if (drops != 0x3F) - drops++; - ride->drops &= ~0x3F; - ride->drops |= drops; - - ride->start_drop_height = vehicle->z / 8; - var_108 &= ~(1 << 7); - } - - if (var_108 & (1 << 7)){ - if (vehicle->velocity > 0 || !(flags & (1 << 6))){ - ride->var_108 &= ~(1 << 7); - - sint16 z = vehicle->z / 8 - ride->start_drop_height; - if (z < 0){ - z = abs(z); - if (z > ride->highest_drop_height){ - ride->highest_drop_height = (uint8)z; - } - } - } - } - else if (flags & (1 << 6) && vehicle->velocity <= 0){ - ride->var_108 &= ~(1 << 5); - ride->var_108 |= (1 << 7); - - uint8 drops = ride->drops & 0x3F; - if (drops != 0x3F) - drops++; - ride->drops &= ~0x3F; - ride->drops |= drops; - - ride->start_drop_height = vehicle->z / 8; - var_108 &= ~(1 << 7); - } - - if (flags & (1 << 7)){ - uint8 inversions = ride->inversions & 0x1F; - if (inversions != 0x1F) - inversions++; - - ride->inversions &= ~0x1F; - ride->inversions |= inversions; - } - - if (flags & (1 << 11)){ - uint8 helixes = ride_get_helix_sections(ride); - if (helixes != 0x1F) - helixes++; - - ride->special_track_elements &= ~0x1F; - ride->special_track_elements |= helixes; - } } + else{ + ride->var_108 &= ~(1 << 6); + } + + if (ride->type == RIDE_TYPE_WATER_COASTER){ + if (track_elem_type >= TRACK_ELEM_FLAT_COVERED && track_elem_type <= TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED){ + ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; + } + } + + switch (track_elem_type) + { + case TRACK_ELEM_RAPIDS: + case TRACK_ELEM_SPINNING_TUNNEL: + ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; + break; + case TRACK_ELEM_WATERFALL: + case TRACK_ELEM_LOG_FLUME_REVERSER: + ride->special_track_elements |= RIDE_ELEMENT_REVERSER_OR_WATERFALL; + break; + case TRACK_ELEM_WHIRLPOOL: + ride->special_track_elements |= RIDE_ELEMENT_WHIRLPOOL; + break; + case TRACK_ELEM_WATER_SPLASH: + if (vehicle->velocity >= 0xB0000){ + ride->special_track_elements |= RIDE_ELEMENT_TUNNEL_SPLASH_OR_RAPIDS; + } + } + + // ax + uint16 track_flags = RCT2_ADDRESS(0x0099423C, uint16)[track_elem_type]; + + uint32 var_108 = ride->var_108; + if (var_108 & (1 << 1) && track_flags & TRACK_ELEM_FLAG_TURN_LEFT){ + ride->var_10E += 0x800; + } + else if (var_108 & (1 << 2) && track_flags & TRACK_ELEM_FLAG_TURN_RIGHT){ + ride->var_10E += 0x800; + } + else if (var_108 & (1 << 2) || var_108 & (1 << 1)){ + ride->var_108 &= ~(0x6); + ride->var_108 &= ~(0x18); + + uint16* ebp = &ride->var_110; + if (!(var_108 & (1 << 3))){ + ebp = &ride->var_112; + if (!(var_108 & (1 << 4))){ + ebp = &ride->var_10E; + } + } + uint16 bx; + switch (ride->var_10E >> 11){ + case 0: + bx = *ebp & 0x1F; + if (bx != 0x1F){ + bx++; + } + *ebp &= 0xFFE0; + *ebp |= bx; + break; + case 1: + bx = *ebp & 0xE0; + if (bx != 0xE0){ + bx += 0x20; + } + *ebp &= 0xFF1F; + *ebp |= bx; + break; + default: + if (var_108&(1 << 4)){ + bx = *ebp & 0xF800; + if (bx != 0xF800){ + bx += 0x800; + } + *ebp &= 0x7FF; + *ebp |= bx; + break; + } + // fall through to case 2 + case 2: + bx = *ebp & 0x700; + if (bx != 0x700){ + bx += 0x100; + } + *ebp &= 0xF8FF; + *ebp |= bx; + break; + } + } + else { + if (track_flags & TRACK_ELEM_FLAG_TURN_LEFT){ + ride->var_108 |= (1 << 1); + ride->var_10E &= 0x7FF; + + if (track_flags & TRACK_ELEM_FLAG_TURN_BANKED){ + ride->var_108 |= (1 << 3); + } + if (track_flags & TRACK_ELEM_FLAG_TURN_SLOPED){ + ride->var_108 |= (1 << 4); + } + } + + if (track_flags & TRACK_ELEM_FLAG_TURN_RIGHT){ + ride->var_108 |= (1 << 2); + ride->var_10E &= 0x7FF; + + if (track_flags & TRACK_ELEM_FLAG_TURN_BANKED){ + ride->var_108 |= (1 << 3); + } + if (track_flags & TRACK_ELEM_FLAG_TURN_SLOPED){ + ride->var_108 |= (1 << 4); + } + } + } + + if (var_108 & (1 << 5)){ + if (vehicle->velocity < 0 || !(track_flags & TRACK_ELEM_FLAG_DOWN)){ + ride->var_108 &= ~(1 << 5); + + sint16 z = vehicle->z / 8 - ride->start_drop_height; + if (z < 0){ + z = abs(z); + if (z > ride->highest_drop_height){ + ride->highest_drop_height = (uint8)z; + } + } + } + } + else if (track_flags & TRACK_ELEM_FLAG_DOWN && vehicle->velocity >= 0){ + ride->var_108 &= ~(1 << 7); + ride->var_108 |= (1 << 5); + + uint8 drops = ride->drops & 0x3F; + if (drops != 0x3F) + drops++; + ride->drops &= ~0x3F; + ride->drops |= drops; + + ride->start_drop_height = vehicle->z / 8; + var_108 &= ~(1 << 7); + } + + if (var_108 & (1 << 7)){ + if (vehicle->velocity > 0 || !(track_flags & TRACK_ELEM_FLAG_UP)){ + ride->var_108 &= ~(1 << 7); + + sint16 z = vehicle->z / 8 - ride->start_drop_height; + if (z < 0){ + z = abs(z); + if (z > ride->highest_drop_height){ + ride->highest_drop_height = (uint8)z; + } + } + } + } + else if (track_flags & TRACK_ELEM_FLAG_UP && vehicle->velocity <= 0){ + ride->var_108 &= ~(1 << 5); + ride->var_108 |= (1 << 7); + + uint8 drops = ride->drops & 0x3F; + if (drops != 0x3F) + drops++; + ride->drops &= ~0x3F; + ride->drops |= drops; + + ride->start_drop_height = vehicle->z / 8; + var_108 &= ~(1 << 7); + } + + if (track_flags & TRACK_ELEM_FLAG_INVERSION){ + uint8 inversions = ride->inversions & 0x1F; + if (inversions != 0x1F) + inversions++; + + ride->inversions &= ~0x1F; + ride->inversions |= inversions; + } + + if (track_flags & TRACK_ELEM_FLAG_HELIX){ + uint8 helixes = ride_get_helix_sections(ride); + if (helixes != 0x1F) + helixes++; + + ride->special_track_elements &= ~0x1F; + ride->special_track_elements |= helixes; + } + } if (ride->entrances[ride->var_1F6] == 0xFFFF) From 2b7f7c923243d64d139ba9012bfc71aed9cd6d8a Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Apr 2015 20:22:27 +0100 Subject: [PATCH 009/162] Refactor turn count variables --- src/ride/ride.c | 168 +++++++++++++++++++++++++++++++++------- src/ride/ride.h | 47 +++++++---- src/ride/ride_ratings.c | 81 ++++++++++--------- src/ride/vehicle.c | 123 +++++++++++++---------------- 4 files changed, 266 insertions(+), 153 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index bcfc7a43d1..40afe2965d 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -5880,52 +5880,164 @@ bool ride_type_has_flag(int rideType, int flag) } /* - * The next six functions are helpers to access ride data at the offset 10E & - * 110. We believe it stores three distinct values in the following format: + * The next eight functions are helpers to access ride data at the offset 10E & + * 110. Known as the turn counts. There are 3 different types (default, banked, sloped) + * and there are 4 counts as follows: * - * unknown1: bits 9-11 - * unknown2: bits 6-8 - * unknown3: low 5 bits + * 1 element turns: low 5 bits + * 2 element turns: bits 6-8 + * 3 element turns: bits 9-11 + * 4 element or more turns: bits 12-15 + * + * 4 plus elements only possible on sloped type. Falls back to 3 element + * if by some miracle you manage 4 element none sloped. */ -int get_var_10E_unk_1(rct_ride* ride) { - return (ride->var_10E >> 8) & 0x7; +void increment_turn_count_1_element(rct_ride* ride, uint8 type){ + uint16* turn_count; + switch (type){ + case 0: + turn_count = &ride->turn_count_default; + break; + case 1: + turn_count = &ride->turn_count_banked; + break; + case 2: + turn_count = &ride->turn_count_sloped; + break; + } + uint16 value = (*turn_count & TURN_MASK_1_ELEMENT) + 1; + *turn_count &= ~TURN_MASK_1_ELEMENT; + if (value > TURN_MASK_1_ELEMENT) + value = TURN_MASK_1_ELEMENT; + *turn_count |= value; } -int get_var_10E_unk_2(rct_ride* ride) { - return (ride->var_10E >> 5) & 0x7; +void increment_turn_count_2_elements(rct_ride* ride, uint8 type){ + uint16* turn_count; + switch (type){ + case 0: + turn_count = &ride->turn_count_default; + break; + case 1: + turn_count = &ride->turn_count_banked; + break; + case 2: + turn_count = &ride->turn_count_sloped; + break; + } + uint16 value = (*turn_count & TURN_MASK_2_ELEMENTS) + 0x20; + *turn_count &= ~TURN_MASK_2_ELEMENTS; + value <<= 5; + if (value > TURN_MASK_2_ELEMENTS) + value = TURN_MASK_2_ELEMENTS; + *turn_count |= value; } -int get_var_10E_unk_3(rct_ride* ride) { - return ride->var_10E & 0x1F; +void increment_turn_count_3_elements(rct_ride* ride, uint8 type){ + uint16* turn_count; + switch (type){ + case 0: + turn_count = &ride->turn_count_default; + break; + case 1: + turn_count = &ride->turn_count_banked; + break; + case 2: + turn_count = &ride->turn_count_sloped; + break; + } + uint16 value = (*turn_count & TURN_MASK_3_ELEMENTS) + 0x100; + *turn_count &= ~TURN_MASK_3_ELEMENTS; + value <<= 8; + if (value > TURN_MASK_3_ELEMENTS) + value = TURN_MASK_3_ELEMENTS; + *turn_count |= value; } -int get_var_110_unk_1(rct_ride* ride) { - return (ride->var_110 >> 8) & 0x7; +void increment_turn_count_4_plus_elements(rct_ride* ride, uint8 type){ + uint16* turn_count; + switch (type){ + case 0: + case 1: + // Just incase fallback to 3 element turn + increment_turn_count_3_elements(ride, type); + return; + case 2: + turn_count = &ride->turn_count_sloped; + break; + } + uint16 value = (*turn_count & TURN_MASK_4_PLUS_ELEMENTS) + 0x800; + *turn_count &= ~TURN_MASK_4_PLUS_ELEMENTS; + value <<= 11; + if (value > TURN_MASK_4_PLUS_ELEMENTS) + value = TURN_MASK_4_PLUS_ELEMENTS; + *turn_count |= value; } -int get_var_110_unk_2(rct_ride* ride) { - return (ride->var_110 >> 5) & 0x7; +int get_turn_count_1_element(rct_ride* ride, uint8 type) { + uint16* turn_count; + switch (type){ + case 0: + turn_count = &ride->turn_count_default; + break; + case 1: + turn_count = &ride->turn_count_banked; + break; + case 2: + turn_count = &ride->turn_count_sloped; + break; + } + + return (*turn_count) & TURN_MASK_1_ELEMENT; } -int get_var_110_unk_3(rct_ride* ride) { - return ride->var_110 & 0x1F; +int get_turn_count_2_elements(rct_ride* ride, uint8 type) { + uint16* turn_count; + switch (type){ + case 0: + turn_count = &ride->turn_count_default; + break; + case 1: + turn_count = &ride->turn_count_banked; + break; + case 2: + turn_count = &ride->turn_count_sloped; + break; + } + + return (*turn_count >> 5) & TURN_MASK_2_ELEMENTS; } -int get_var_112_unk_1(rct_ride* ride) { - return (ride->var_112 >> 11) & 0x3F; +int get_turn_count_3_elements(rct_ride* ride, uint8 type) { + uint16* turn_count; + switch (type){ + case 0: + turn_count = &ride->turn_count_default; + break; + case 1: + turn_count = &ride->turn_count_banked; + break; + case 2: + turn_count = &ride->turn_count_sloped; + break; + } + + return (*turn_count >> 8) & TURN_MASK_3_ELEMENTS; } -int get_var_112_unk_2(rct_ride* ride) { - return (ride->var_112 >> 8) & 7; -} +int get_turn_count_4_plus_elements(rct_ride* ride, uint8 type) { + uint16* turn_count; + switch (type){ + case 0: + case 1: + return 0; + case 2: + turn_count = &ride->turn_count_sloped; + break; + } -int get_var_112_unk_3(rct_ride* ride) { - return (ride->var_112 >> 5) & 7; -} - -int get_var_112_unk_4(rct_ride* ride) { - return ride->var_112 & 0x1F; + return (*turn_count >> 11) & TURN_MASK_4_PLUS_ELEMENTS; } bool ride_has_spinning_tunnel(rct_ride *ride) { diff --git a/src/ride/ride.h b/src/ride/ride.h index 9b9d6d594b..4307372de7 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -243,13 +243,13 @@ typedef struct { fixed16_2dp previous_vertical_g;// 0x102 fixed16_2dp previous_lateral_g; // 0x104 uint8 pad_106[0x2]; - uint32 var_108; + uint32 testing_flags; // 0x108 // x y map location uint16 var_10C; // Next 3 variables are related (XXXX XYYY ZZZa aaaa) - uint16 var_10E; - uint16 var_110; - uint16 var_112; + uint16 turn_count_default; // 0x10E X = current turn count + uint16 turn_count_banked; // 0x110 + uint16 turn_count_sloped; // 0x112 X = number turns > 3 elements union { uint8 inversions; // 0x114 (???X XXXX) uint8 holes; // 0x114 (???X XXXX) @@ -257,7 +257,8 @@ typedef struct { // It reaches the maximum value of 7 at about 50% undercover and doesn't increase beyond that. uint8 undercover_portion; // 0x114 (XXX?-????) }; - uint8 drops; // 0x115 (??XX XXXX) + // Y is number of powered lifts, X is drops + uint8 drops; // 0x115 (YYXX XXXX) uint8 start_drop_height; // 0x116 uint8 highest_drop_height; // 0x117 sint32 sheltered_length; // 0x118 @@ -475,6 +476,17 @@ enum { RIDE_ENTRY_FLAG_31 = 1 << 31, // 0x80000000 }; +enum{ + RIDE_TESTING_FLAG_0 = (1 << 0), + RIDE_TESTING_TURN_LEFT = (1 << 1), + RIDE_TESTING_TURN_RIGHT = (1 << 2), + RIDE_TESTING_TURN_BANKED = (1 << 3), + RIDE_TESTING_TURN_SLOPED = (1 << 4), + RIDE_TESTING_DROP_DOWN = (1 << 5), + RIDE_TESTING_POWERED_LIFT = (1 << 6), + RIDE_TESTING_DROP_UP = (1 << 7), +}; + enum { RIDE_TYPE_NULL = 255, RIDE_TYPE_SPIRAL_ROLLER_COASTER = 0, @@ -882,6 +894,12 @@ enum { #define STATION_DEPART_FLAG (1 << 7) #define STATION_DEPART_MASK (~STATION_DEPART_FLAG) +#define CURRENT_TURN_COUNT_MASK 0xF800 +#define TURN_MASK_1_ELEMENT 0x001F +#define TURN_MASK_2_ELEMENTS 0x00E0 +#define TURN_MASK_3_ELEMENTS 0x0700 +#define TURN_MASK_4_PLUS_ELEMENTS 0xF800 + // rct2: 0x009ACFA4 extern rct_ride_type **gRideTypeList; @@ -1003,6 +1021,7 @@ void game_command_callback_ride_remove_track_piece(int eax, int ebx, int ecx, in void game_command_demolish_ride(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); void game_command_set_ride_appearance(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); void game_command_set_ride_price(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); + void ride_clear_for_construction(int rideIndex); void set_vehicle_type_image_max_sizes(rct_ride_type_vehicle* vehicle_type, int num_images); void invalidate_test_results(int rideIndex); @@ -1010,16 +1029,14 @@ void invalidate_test_results(int rideIndex); void ride_select_next_section(); void ride_select_previous_section(); -int get_var_10E_unk_1(rct_ride* ride); -int get_var_10E_unk_2(rct_ride* ride); -int get_var_10E_unk_3(rct_ride* ride); -int get_var_110_unk_1(rct_ride* ride); -int get_var_110_unk_2(rct_ride* ride); -int get_var_110_unk_3(rct_ride* ride); -int get_var_112_unk_1(rct_ride* ride); -int get_var_112_unk_2(rct_ride* ride); -int get_var_112_unk_3(rct_ride* ride); -int get_var_112_unk_4(rct_ride* ride); +void increment_turn_count_1_element(rct_ride* ride, uint8 type); +void increment_turn_count_2_elements(rct_ride* ride, uint8 type); +void increment_turn_count_3_elements(rct_ride* ride, uint8 type); +void increment_turn_count_4_plus_elements(rct_ride* ride, uint8 type); +int get_turn_count_1_element(rct_ride* ride, uint8 type); +int get_turn_count_2_elements(rct_ride* ride, uint8 type); +int get_turn_count_3_elements(rct_ride* ride, uint8 type); +int get_turn_count_4_plus_elements(rct_ride* ride, uint8 type); uint8 ride_get_helix_sections(rct_ride *ride); bool ride_has_spinning_tunnel(rct_ride *ride); diff --git a/src/ride/ride_ratings.c b/src/ride/ride_ratings.c index 5b04920885..0f99ce8052 100644 --- a/src/ride/ride_ratings.c +++ b/src/ride/ride_ratings.c @@ -930,22 +930,22 @@ static int sub_65E72D(rct_ride *ride) return (dh << 8) | numShelteredEighths; } -static rating_tuple get_var_10E_rating(rct_ride* ride) { - int var_10E_unk_1 = get_var_10E_unk_1(ride); - int var_10E_unk_2 = get_var_10E_unk_2(ride); - int var_10E_unk_3 = get_var_10E_unk_3(ride); +static rating_tuple get_flat_turns_rating(rct_ride* ride) { + int no_3_plus_turns = get_turn_count_3_elements(ride, 0); + int no_2_turns = get_turn_count_2_elements(ride, 0); + int no_1_turns = get_turn_count_1_element(ride, 0); - int excitement = (var_10E_unk_1 * 0x28000) >> 16; - excitement += (var_10E_unk_2 * 0x30000) >> 16; - excitement += (var_10E_unk_3 * 63421) >> 16; + int excitement = (no_3_plus_turns * 0x28000) >> 16; + excitement += no_2_turns * 3; + excitement += (no_1_turns * 63421) >> 16; - int intensity = (var_10E_unk_1 * 81920) >> 16; - intensity += (var_10E_unk_2 * 49152) >> 16; - intensity += (var_10E_unk_3 * 21140) >> 16; + int intensity = (no_3_plus_turns * 81920) >> 16; + intensity += (no_2_turns * 49152) >> 16; + intensity += (no_1_turns * 21140) >> 16; - int nausea = (var_10E_unk_1 * 0x50000) >> 16; - nausea += (var_10E_unk_2 * 0x32000) >> 16; - nausea += (var_10E_unk_3 * 42281) >> 16; + int nausea = no_3_plus_turns * 5; + nausea += (no_2_turns * 0x3200) >> 16; + nausea += (no_1_turns * 42281) >> 16; rating_tuple rating = { excitement, intensity, nausea }; return rating; @@ -954,22 +954,22 @@ static rating_tuple get_var_10E_rating(rct_ride* ride) { /** * rct2: 0x0065DF72 */ -static rating_tuple get_var_110_rating(rct_ride* ride) { - int var_110_unk_1 = get_var_110_unk_1(ride); - int var_110_unk_2 = get_var_110_unk_2(ride); - int var_110_unk_3 = get_var_110_unk_3(ride); +static rating_tuple get_banked_turns_rating(rct_ride* ride) { + int no_3_plus_turns = get_turn_count_3_elements(ride, 1); + int no_2_turns = get_turn_count_2_elements(ride, 1); + int no_1_turns = get_turn_count_1_element(ride, 1); - int excitement = (var_110_unk_1 * 0x3C000) >> 16; - excitement += (var_110_unk_2 * 0x3C000) >> 16; - excitement += (var_110_unk_3 * 73992) >> 16; + int excitement = (no_3_plus_turns * 0x3c000) >> 16; + excitement += (no_2_turns * 0x3c000) >> 16; + excitement += (no_1_turns * 73992) >> 16; - int intensity = (var_110_unk_1 * 0x14000) >> 16; - intensity += (var_110_unk_2 * 49152) >> 16; - intensity += (var_110_unk_3 * 21140) >> 16; + int intensity = (no_3_plus_turns * 0x14000) >> 16; + intensity += (no_2_turns * 49152) >> 16; + intensity += (no_1_turns * 21140) >> 16; - int nausea = (var_110_unk_1 * 0x50000) >> 16; - nausea += (var_110_unk_2 * 0x32000) >> 16; - nausea += (var_110_unk_3 * 48623) >> 16; + int nausea = no_3_plus_turns * 5; + nausea += (no_2_turns * 0x32000) >> 16; + nausea += (no_1_turns * 48623) >> 16; rating_tuple rating = { excitement, intensity, nausea }; return rating; @@ -978,27 +978,26 @@ static rating_tuple get_var_110_rating(rct_ride* ride) { /** * rct2: 0x0065E047 */ -static rating_tuple get_var_112_rating(rct_ride *ride) { +static rating_tuple get_sloped_turns_rating(rct_ride* ride) { + int no_4_plus_turns = get_turn_count_4_plus_elements(ride, 2); + int no_3_turns = get_turn_count_3_elements(ride, 2); + int no_2_turns = get_turn_count_2_elements(ride, 2); + int no_1_turns = get_turn_count_1_element(ride, 2); int al; - al = get_var_112_unk_1(ride); - al = min(al, 4); + al = min(no_4_plus_turns, 4); int excitement = (al * 0x78000) >> 16; - al = get_var_112_unk_1(ride); - al = min(al, 8); + al = min(no_4_plus_turns, 8); int nausea = (al * 0x78000) >> 16; - al = get_var_112_unk_2(ride); - al = min(al, 6); + al = min(no_3_turns, 6); excitement += (al * 273066) >> 16; - al = get_var_112_unk_3(ride); - al = min(al, 6); - excitement += (al * 0x3AAAA) >> 16; + al = min(no_2_turns, 6); + excitement += (al * 0x3aaaa) >> 16; - al = get_var_112_unk_4(ride); - al = min(al, 7); + al = min(no_1_turns, 7); excitement += (al * 187245) >> 16; rating_tuple rating = { excitement, 0, nausea }; @@ -1078,17 +1077,17 @@ static rating_tuple sub_65DDD1(rct_ride *ride) intensity += special_track_element_rating.intensity; nausea += special_track_element_rating.nausea; - rating_tuple var_10E_rating = get_var_10E_rating(ride); + rating_tuple var_10E_rating = get_flat_turns_rating(ride); excitement += var_10E_rating.excitement; intensity += var_10E_rating.intensity; nausea += var_10E_rating.nausea; - rating_tuple var_110_rating = get_var_110_rating(ride); + rating_tuple var_110_rating = get_banked_turns_rating(ride); excitement += var_110_rating.excitement; intensity += var_110_rating.intensity; nausea += var_110_rating.nausea; - rating_tuple var_112_rating = get_var_112_rating(ride); + rating_tuple var_112_rating = get_sloped_turns_rating(ride); excitement += var_112_rating.excitement; intensity += var_112_rating.intensity; nausea += var_112_rating.nausea; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index dede3779aa..f8376f9251 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -553,15 +553,15 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) uint16 track_elem_type = vehicle->track_type / 4; if (track_elem_type == TRACK_ELEM_POWERED_LIFT || !(vehicle->var_48 & (1 << 0))){ - if (!(ride->var_108 & (1 << 6))){ - ride->var_108 |= (1 << 6); + if (!(ride->testing_flags & RIDE_TESTING_POWERED_LIFT)){ + ride->testing_flags |= RIDE_TESTING_POWERED_LIFT; if (ride->drops + 64 < 0xFF){ ride->drops += 64; } } } else{ - ride->var_108 &= ~(1 << 6); + ride->testing_flags &= ~RIDE_TESTING_POWERED_LIFT; } if (ride->type == RIDE_TYPE_WATER_COASTER){ @@ -592,92 +592,77 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) // ax uint16 track_flags = RCT2_ADDRESS(0x0099423C, uint16)[track_elem_type]; - uint32 var_108 = ride->var_108; - if (var_108 & (1 << 1) && track_flags & TRACK_ELEM_FLAG_TURN_LEFT){ - ride->var_10E += 0x800; + uint32 testing_flags = ride->testing_flags; + if (testing_flags & RIDE_TESTING_TURN_LEFT && + track_flags & TRACK_ELEM_FLAG_TURN_LEFT){ + // 0x800 as this is masked to CURRENT_TURN_COUNT_MASK + ride->turn_count_default += 0x800; } - else if (var_108 & (1 << 2) && track_flags & TRACK_ELEM_FLAG_TURN_RIGHT){ - ride->var_10E += 0x800; + else if (testing_flags & RIDE_TESTING_TURN_RIGHT && + track_flags & TRACK_ELEM_FLAG_TURN_RIGHT){ + // 0x800 as this is masked to CURRENT_TURN_COUNT_MASK + ride->turn_count_default += 0x800; } - else if (var_108 & (1 << 2) || var_108 & (1 << 1)){ - ride->var_108 &= ~(0x6); - ride->var_108 &= ~(0x18); + else if (testing_flags & RIDE_TESTING_TURN_RIGHT || + testing_flags & RIDE_TESTING_TURN_LEFT){ - uint16* ebp = &ride->var_110; - if (!(var_108 & (1 << 3))){ - ebp = &ride->var_112; - if (!(var_108 & (1 << 4))){ - ebp = &ride->var_10E; + ride->testing_flags &= ~( + RIDE_TESTING_TURN_LEFT | + RIDE_TESTING_TURN_RIGHT | + RIDE_TESTING_TURN_BANKED | + RIDE_TESTING_TURN_SLOPED); + + uint8 turn_type = 1; + if (!(testing_flags & RIDE_TESTING_TURN_BANKED)){ + turn_type = 2; + if (!(testing_flags & RIDE_TESTING_TURN_SLOPED)){ + turn_type = 0; } } - uint16 bx; - switch (ride->var_10E >> 11){ + switch (ride->turn_count_default >> 11){ case 0: - bx = *ebp & 0x1F; - if (bx != 0x1F){ - bx++; - } - *ebp &= 0xFFE0; - *ebp |= bx; + increment_turn_count_1_element(ride, turn_type); break; case 1: - bx = *ebp & 0xE0; - if (bx != 0xE0){ - bx += 0x20; - } - *ebp &= 0xFF1F; - *ebp |= bx; + increment_turn_count_2_elements(ride, turn_type); break; - default: - if (var_108&(1 << 4)){ - bx = *ebp & 0xF800; - if (bx != 0xF800){ - bx += 0x800; - } - *ebp &= 0x7FF; - *ebp |= bx; - break; - } - // fall through to case 2 case 2: - bx = *ebp & 0x700; - if (bx != 0x700){ - bx += 0x100; - } - *ebp &= 0xF8FF; - *ebp |= bx; + increment_turn_count_3_elements(ride, turn_type); + break; + default: + increment_turn_count_4_plus_elements(ride, turn_type); break; } } else { if (track_flags & TRACK_ELEM_FLAG_TURN_LEFT){ - ride->var_108 |= (1 << 1); - ride->var_10E &= 0x7FF; + ride->testing_flags |= RIDE_TESTING_TURN_LEFT; + ride->turn_count_default &= ~CURRENT_TURN_COUNT_MASK; if (track_flags & TRACK_ELEM_FLAG_TURN_BANKED){ - ride->var_108 |= (1 << 3); + ride->testing_flags |= RIDE_TESTING_TURN_BANKED; } if (track_flags & TRACK_ELEM_FLAG_TURN_SLOPED){ - ride->var_108 |= (1 << 4); + ride->testing_flags |= RIDE_TESTING_TURN_SLOPED; } } if (track_flags & TRACK_ELEM_FLAG_TURN_RIGHT){ - ride->var_108 |= (1 << 2); - ride->var_10E &= 0x7FF; + ride->testing_flags |= RIDE_TESTING_TURN_RIGHT; + ride->turn_count_default &= ~CURRENT_TURN_COUNT_MASK; if (track_flags & TRACK_ELEM_FLAG_TURN_BANKED){ - ride->var_108 |= (1 << 3); + ride->testing_flags |= RIDE_TESTING_TURN_BANKED; } if (track_flags & TRACK_ELEM_FLAG_TURN_SLOPED){ - ride->var_108 |= (1 << 4); + ride->testing_flags |= RIDE_TESTING_TURN_SLOPED; } } } - if (var_108 & (1 << 5)){ + if (testing_flags & RIDE_TESTING_DROP_DOWN){ if (vehicle->velocity < 0 || !(track_flags & TRACK_ELEM_FLAG_DOWN)){ - ride->var_108 &= ~(1 << 5); + ride->testing_flags &= ~RIDE_TESTING_DROP_DOWN; sint16 z = vehicle->z / 8 - ride->start_drop_height; if (z < 0){ @@ -689,8 +674,8 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } } else if (track_flags & TRACK_ELEM_FLAG_DOWN && vehicle->velocity >= 0){ - ride->var_108 &= ~(1 << 7); - ride->var_108 |= (1 << 5); + ride->testing_flags &= ~RIDE_TESTING_DROP_UP; + ride->testing_flags |= RIDE_TESTING_DROP_DOWN; uint8 drops = ride->drops & 0x3F; if (drops != 0x3F) @@ -699,12 +684,12 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) ride->drops |= drops; ride->start_drop_height = vehicle->z / 8; - var_108 &= ~(1 << 7); + testing_flags &= ~RIDE_TESTING_DROP_UP; } - if (var_108 & (1 << 7)){ + if (testing_flags & RIDE_TESTING_DROP_UP){ if (vehicle->velocity > 0 || !(track_flags & TRACK_ELEM_FLAG_UP)){ - ride->var_108 &= ~(1 << 7); + ride->testing_flags &= ~RIDE_TESTING_DROP_UP; sint16 z = vehicle->z / 8 - ride->start_drop_height; if (z < 0){ @@ -716,8 +701,8 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } } else if (track_flags & TRACK_ELEM_FLAG_UP && vehicle->velocity <= 0){ - ride->var_108 &= ~(1 << 5); - ride->var_108 |= (1 << 7); + ride->testing_flags &= ~RIDE_TESTING_DROP_DOWN; + ride->testing_flags |= RIDE_TESTING_DROP_UP; uint8 drops = ride->drops & 0x3F; if (drops != 0x3F) @@ -726,7 +711,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) ride->drops |= drops; ride->start_drop_height = vehicle->z / 8; - var_108 &= ~(1 << 7); + testing_flags &= ~RIDE_TESTING_DROP_UP; } if (track_flags & TRACK_ELEM_FLAG_INVERSION){ @@ -757,7 +742,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) y = vehicle->y; if (x == SPRITE_LOCATION_NULL){ - ride->var_108 &= (1 << 0); + ride->testing_flags &= RIDE_TESTING_FLAG_0; return; } @@ -766,7 +751,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) for (;; map_element++){ if (map_element_is_last_for_tile(map_element)){ - ride->var_108 &= (1 << 0); + ride->testing_flags &= RIDE_TESTING_FLAG_0; return; } @@ -785,8 +770,8 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } } - if (!(ride->var_108 & (1 << 0))){ - ride->var_108 |= (1 << 0); + if (!(ride->testing_flags & RIDE_TESTING_FLAG_0)){ + ride->testing_flags |= RIDE_TESTING_FLAG_0; uint8 num_sheltered_sections = ride->num_sheltered_sections & 0x1F; if (num_sheltered_sections != 0x1F) From d602fc75be39344761fe41b5ef63062a0e9a50e1 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 5 Apr 2015 21:51:49 +0100 Subject: [PATCH 010/162] Fix bugs. --- src/ride/ride.c | 7 ++++--- src/ride/vehicle.c | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index 40afe2965d..d97a21fc0d 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -5908,6 +5908,7 @@ void increment_turn_count_1_element(rct_ride* ride, uint8 type){ } uint16 value = (*turn_count & TURN_MASK_1_ELEMENT) + 1; *turn_count &= ~TURN_MASK_1_ELEMENT; + if (value > TURN_MASK_1_ELEMENT) value = TURN_MASK_1_ELEMENT; *turn_count |= value; @@ -5928,7 +5929,7 @@ void increment_turn_count_2_elements(rct_ride* ride, uint8 type){ } uint16 value = (*turn_count & TURN_MASK_2_ELEMENTS) + 0x20; *turn_count &= ~TURN_MASK_2_ELEMENTS; - value <<= 5; + if (value > TURN_MASK_2_ELEMENTS) value = TURN_MASK_2_ELEMENTS; *turn_count |= value; @@ -5949,7 +5950,7 @@ void increment_turn_count_3_elements(rct_ride* ride, uint8 type){ } uint16 value = (*turn_count & TURN_MASK_3_ELEMENTS) + 0x100; *turn_count &= ~TURN_MASK_3_ELEMENTS; - value <<= 8; + if (value > TURN_MASK_3_ELEMENTS) value = TURN_MASK_3_ELEMENTS; *turn_count |= value; @@ -5969,7 +5970,7 @@ void increment_turn_count_4_plus_elements(rct_ride* ride, uint8 type){ } uint16 value = (*turn_count & TURN_MASK_4_PLUS_ELEMENTS) + 0x800; *turn_count &= ~TURN_MASK_4_PLUS_ELEMENTS; - value <<= 11; + if (value > TURN_MASK_4_PLUS_ELEMENTS) value = TURN_MASK_4_PLUS_ELEMENTS; *turn_count |= value; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index f8376f9251..e22f57415d 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -478,14 +478,14 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) rct_ride *ride; ride = GET_RIDE(vehicle->ride); - //RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)vehicle->ride, 0); + //RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)vehicle->ride * sizeof(rct_ride), 0); //return; if (vehicle->status == VEHICLE_STATUS_TRAVELLING_07){ ride->lifecycle_flags |= RIDE_LIFECYCLE_TESTED; ride->lifecycle_flags |= RIDE_LIFECYCLE_NO_RAW_STATS; ride->lifecycle_flags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; - vehicle->var_48 &= ~(1 << 1); + vehicle->var_48 &= ~(1 << 5); window_invalidate_by_number(WC_RIDE, vehicle->ride); return; } @@ -742,16 +742,16 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) y = vehicle->y; if (x == SPRITE_LOCATION_NULL){ - ride->testing_flags &= RIDE_TESTING_FLAG_0; + ride->testing_flags &= ~RIDE_TESTING_FLAG_0; return; } rct_map_element* map_element = map_get_surface_element_at(x / 32, y / 32); - if (map_element->base_height * 8 > vehicle->z){ + if (map_element->base_height * 8 <= vehicle->z){ for (;; map_element++){ if (map_element_is_last_for_tile(map_element)){ - ride->testing_flags &= RIDE_TESTING_FLAG_0; + ride->testing_flags &= ~RIDE_TESTING_FLAG_0; return; } From c8c55002c8a41618204b9805d478566f69a61ecb Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 7 Apr 2015 18:44:55 +0100 Subject: [PATCH 011/162] Refactor with sheltered knowledge --- src/ride/ride.h | 5 +++-- src/ride/vehicle.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index 4307372de7..ce08dfe5b1 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -263,7 +263,8 @@ typedef struct { uint8 highest_drop_height; // 0x117 sint32 sheltered_length; // 0x118 uint16 var_11C; - uint8 num_sheltered_sections; // 0x11E + uint8 num_sheltered_sections; // 0x11E (?abY YYYY) + // z related to var_10C uint8 var_11F; sint16 var_120; sint16 var_122; @@ -477,7 +478,7 @@ enum { }; enum{ - RIDE_TESTING_FLAG_0 = (1 << 0), + RIDE_TESTING_SHELTERED = (1 << 0), RIDE_TESTING_TURN_LEFT = (1 << 1), RIDE_TESTING_TURN_RIGHT = (1 << 2), RIDE_TESTING_TURN_BANKED = (1 << 3), diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index e22f57415d..1fcfe9db53 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -742,7 +742,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) y = vehicle->y; if (x == SPRITE_LOCATION_NULL){ - ride->testing_flags &= ~RIDE_TESTING_FLAG_0; + ride->testing_flags &= ~RIDE_TESTING_SHELTERED; return; } @@ -751,7 +751,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) for (;; map_element++){ if (map_element_is_last_for_tile(map_element)){ - ride->testing_flags &= ~RIDE_TESTING_FLAG_0; + ride->testing_flags &= ~RIDE_TESTING_SHELTERED; return; } @@ -770,8 +770,8 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } } - if (!(ride->testing_flags & RIDE_TESTING_FLAG_0)){ - ride->testing_flags |= RIDE_TESTING_FLAG_0; + if (!(ride->testing_flags & RIDE_TESTING_SHELTERED)){ + ride->testing_flags |= RIDE_TESTING_SHELTERED; uint8 num_sheltered_sections = ride->num_sheltered_sections & 0x1F; if (num_sheltered_sections != 0x1F) From 691914e4e443be38e210e538dab38a4ffc1aa863 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 7 Apr 2015 19:05:41 +0100 Subject: [PATCH 012/162] Small rename --- src/ride/vehicle.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 1fcfe9db53..858bd6c624 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -36,11 +36,11 @@ static void vehicle_update(rct_vehicle *vehicle); -static void vehicle_D6_255_update_moving_to_end_of_station(rct_vehicle *vehicle); -static void vehicle_D6_255_update_waiting_to_depart(rct_vehicle *vehicle); -static void vehicle_D6_255_update_departing(rct_vehicle *vehicle); -static void vehicle_D6_255_update_travelling(rct_vehicle *vehicle); -static void vehicle_D6_255_update_arriving(rct_vehicle *vehicle); +static void vehicle_ride_null_update_moving_to_end_of_station(rct_vehicle *vehicle); +static void vehicle_ride_null_update_waiting_to_depart(rct_vehicle *vehicle); +static void vehicle_ride_null_update_departing(rct_vehicle *vehicle); +static void vehicle_ride_null_update_travelling(rct_vehicle *vehicle); +static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle); static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); @@ -825,22 +825,22 @@ static void vehicle_update(rct_vehicle *vehicle) rct_ride *ride; rct_ride_type *rideEntry; - if (vehicle->ride_subtype == 255) { + if (vehicle->ride_subtype == RIDE_TYPE_NULL) { switch (vehicle->status) { case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: - vehicle_D6_255_update_moving_to_end_of_station(vehicle); + vehicle_ride_null_update_moving_to_end_of_station(vehicle); break; case VEHICLE_STATUS_WAITING_TO_DEPART: - vehicle_D6_255_update_waiting_to_depart(vehicle); + vehicle_ride_null_update_waiting_to_depart(vehicle); break; case VEHICLE_STATUS_DEPARTING: - vehicle_D6_255_update_departing(vehicle); + vehicle_ride_null_update_departing(vehicle); break; case VEHICLE_STATUS_TRAVELLING: - vehicle_D6_255_update_travelling(vehicle); + vehicle_ride_null_update_travelling(vehicle); break; case VEHICLE_STATUS_ARRIVING: - vehicle_D6_255_update_arriving(vehicle); + vehicle_ride_null_update_arriving(vehicle); break; } return; @@ -905,27 +905,27 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_sound(vehicle); } -static void vehicle_D6_255_update_moving_to_end_of_station(rct_vehicle *vehicle) +static void vehicle_ride_null_update_moving_to_end_of_station(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF8A4, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_D6_255_update_waiting_to_depart(rct_vehicle *vehicle) +static void vehicle_ride_null_update_waiting_to_depart(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF8F1, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_D6_255_update_departing(rct_vehicle *vehicle) +static void vehicle_ride_null_update_departing(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF97A, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_D6_255_update_travelling(rct_vehicle *vehicle) +static void vehicle_ride_null_update_travelling(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF99C, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_D6_255_update_arriving(rct_vehicle *vehicle) +static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle) { vehicle->var_51++; if (vehicle->var_51 >= 64) From d52a5a185021f8824a55379cd72bafa04884bd39 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 7 Apr 2015 21:28:11 +0100 Subject: [PATCH 013/162] Added vehicle update move to end of station --- src/ride/ride.h | 6 +-- src/ride/vehicle.c | 112 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 3 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index ce08dfe5b1..285f5a75e3 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -600,7 +600,7 @@ enum { RIDE_MODE_ROTATING_LIFT, RIDE_MODE_STATION_TO_STATION, RIDE_MODE_SINGLE_RIDE_PER_ADMISSION, - RIDE_MODE_UNLIMITED_RIDES_PER_ADMISSION, + RIDE_MODE_UNLIMITED_RIDES_PER_ADMISSION = 10, RIDE_MODE_MAZE, RIDE_MODE_RACE, RIDE_MODE_BUMPERCAR, @@ -610,7 +610,7 @@ enum { RIDE_MODE_FORWARD_ROTATION, RIDE_MODE_BACKWARD_ROTATION, RIDE_MODE_FILM_AVENGING_AVIATORS, - RIDE_MODE_3D_FILM_MOUSE_TAILS, + RIDE_MODE_3D_FILM_MOUSE_TAILS = 20, RIDE_MODE_SPACE_RINGS, RIDE_MODE_BEGINNERS, RIDE_MODE_LIM_POWERED_LAUNCH, @@ -620,7 +620,7 @@ enum { RIDE_MODE_INTENSE, RIDE_MODE_BERSERK, RIDE_MODE_HAUNTED_HOUSE, - RIDE_MODE_CIRCUS_SHOW, + RIDE_MODE_CIRCUS_SHOW = 30, RIDE_MODE_DOWNWARD_LAUNCH, RIDE_MODE_CROOKED_HOUSE, RIDE_MODE_FREEFALL_DROP, diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 858bd6c624..171e91398d 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -43,6 +43,7 @@ static void vehicle_ride_null_update_travelling(rct_vehicle *vehicle); static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle); static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); +static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -871,6 +872,8 @@ static void vehicle_update(rct_vehicle *vehicle) switch (vehicle->status) { case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: + vehicle_update_moving_to_end_of_station(vehicle); + break; case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: case VEHICLE_STATUS_WAITING_TO_DEPART: case VEHICLE_STATUS_DEPARTING: @@ -932,6 +935,115 @@ static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle) vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; } +static void sub_6DAB4C(rct_vehicle* vehicle, int* eax, int* ebx){ + int eax_, ebx_, ecx, edx, esi, ebp, edi; + esi = (int)vehicle; + RCT2_CALLFUNC_X(0x006DAB4C, &eax_, &ebx_, &ecx, &edx, &esi, &edi, &ebp); + + *eax = eax_; + *ebx = ebx_; +} + +/** +* +* rct2: 0x006D7BCC +*/ +static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ + rct_ride* ride = GET_RIDE(vehicle->ride); + int eax, ebx; + + switch (ride->mode){ + case RIDE_MODE_UPWARD_LAUNCH: + case RIDE_MODE_ROTATING_LIFT: + case RIDE_MODE_DOWNWARD_LAUNCH: + case RIDE_MODE_FREEFALL_DROP: + if (vehicle->velocity >= -131940){ + vehicle->var_2C = -3298; + } + if (vehicle->velocity < -131940){ + vehicle->velocity = vehicle->velocity / 16; + vehicle->var_2C = 0; + } + + sub_6DAB4C(vehicle, &eax, &ebx); + if (!(eax&(1 << 5))) + break; + //Fall through to next case + case RIDE_MODE_BUMPERCAR: + case RIDE_MODE_SWING: + case RIDE_MODE_ROTATION: + case RIDE_MODE_FORWARD_ROTATION: + case RIDE_MODE_BACKWARD_ROTATION: + case RIDE_MODE_FILM_AVENGING_AVIATORS: + case RIDE_MODE_FILM_THRILL_RIDERS: + case RIDE_MODE_BEGINNERS: + case RIDE_MODE_INTENSE: + case RIDE_MODE_BERSERK: + case RIDE_MODE_3D_FILM_MOUSE_TAILS: + case RIDE_MODE_3D_FILM_STORM_CHASERS: + case RIDE_MODE_3D_FILM_SPACE_RAIDERS: + case RIDE_MODE_SPACE_RINGS: + case RIDE_MODE_HAUNTED_HOUSE: + case RIDE_MODE_CROOKED_HOUSE: + case RIDE_MODE_CIRCUS_SHOW: + vehicle->current_station = 0; + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; + vehicle->var_51 = 0; + vehicle_invalidate_window(vehicle); + break; + default: + { + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + if (!(vehicleEntry->var_14 & (1 << 3))){ + if (vehicle->velocity <= 131940){ + vehicle->var_2C = 3298; + } + } + if (vehicle->velocity > 131940){ + vehicle->velocity = vehicle->velocity / 16; + vehicle->var_2C = 0; + } + + int station; + sub_6DAB4C(vehicle, &eax, &station); + + if (eax & (1 << 1)){ + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->var_51++; + + if (ride->mode == RIDE_MODE_RACE && + vehicle->var_51 >= 40){ + vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; + vehicle->var_51 = 0; + vehicle_invalidate_window(vehicle); + break; + } + } + else{ + if (vehicle->velocity > 98955){ + vehicle->var_51 = 0; + } + } + + if (!(eax & (1 << 0))) + break; + + vehicle->current_station = station; + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; + vehicle->var_51 = 0; + vehicle_invalidate_window(vehicle); + break; + } + } +} + /** * * rct2: 0x006D95F7 From 339f872bec0836ebf46e07301407dfd390ce0edb Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 8 Apr 2015 18:48:17 +0100 Subject: [PATCH 014/162] Added sub_6d6a2c --- src/ride/vehicle.c | 115 +++++++++++++++++++++++++++++++++++++++++++++ src/ride/vehicle.h | 7 +-- 2 files changed, 119 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 171e91398d..214b712c1b 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -44,6 +44,7 @@ static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle); static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); +static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -473,6 +474,103 @@ void vehicle_update_all() } } +/* rct2: 0x006D6A2C */ +static int sub_6D6A2C(rct_vehicle* vehicle){ + + int ebp = 0; + uint16 vehicle_id = vehicle->sprite_index; + + do { + vehicle = GET_VEHICLE(vehicle_id); + + vehicle->var_4C = 0; + vehicle->var_4E = 0; + vehicle->var_4A = 0; + + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + if (vehicleEntry->var_14 & (1 << 2) && + abs(vehicle->var_B6) <= 700 && + !(vehicle->var_BA & 0x30) && + ( + !(vehicleEntry->var_12 & (1 << 14)) || + !(vehicle->var_BA & 0xF8)) + ){ + vehicle->var_B6 = 0; + } + else{ + ebp++; + + if (abs(vehicle->var_B6) < 600){ + vehicle->var_B6 = 600; + } + sint16 value = vehicle->var_B6 / 256; + vehicle->var_BA += value; + vehicle->var_B6 -= value; + + invalidate_sprite((rct_sprite*)vehicle); + continue; + } + + if (vehicleEntry->var_12 == 6 && + vehicle->var_C5 != 0){ + + if (vehicle->var_C8 + 0x3333 < 0xFFFF){ + vehicle->var_C8 = vehicle->var_C8 + 0x3333 - 0xFFFF; + vehicle->var_C5++; + vehicle->var_C5 &= 7; + invalidate_sprite((rct_sprite*)vehicle); + } + else{ + vehicle->var_C8 += 0x3333; + } + ebp++; + continue; + } + + if (vehicle->var_48 & (1 << 8) && + vehicle->var_B5 != 0xFF && + ( + ride->breakdown_reason_pending == BREAKDOWN_RESTRAINTS_STUCK_CLOSED || + ride->breakdown_reason_pending == BREAKDOWN_DOORS_STUCK_CLOSED) + ){ + + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)){ + + ride->lifecycle_flags |= RIDE_LIFECYCLE_BROKEN_DOWN; + + ride_breakdown_add_news_item(vehicle->ride); + + ride->window_invalidate_flags |= + RIDE_INVALIDATE_RIDE_MAIN | + RIDE_INVALIDATE_RIDE_LIST | + RIDE_INVALIDATE_RIDE_MAINTENANCE; + + ride->mechanic_status = RIDE_MECHANIC_STATUS_CALLING; + + rct_vehicle* broken_vehicle = GET_VEHICLE(ride->vehicles[ride->broken_vehicle]); + ride->inspection_station = broken_vehicle->current_station; + + ride->breakdown_reason = ride->breakdown_reason_pending; + } + + } + else{ + if (vehicle->var_B5 + 20 > 0xFF){ + vehicle->var_B5 = 255; + continue; + } + invalidate_sprite((rct_sprite*)vehicle); + ebp++; + } + + } while ((vehicle_id = vehicle->next_vehicle_on_train) != 0xFFFF); + + return ebp; +} + /* rct2: 0x006D6D1F */ static void vehicle_update_measurements(rct_vehicle *vehicle) { @@ -875,6 +973,8 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_moving_to_end_of_station(vehicle); break; case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: + vehicle_update_waiting_for_passengers(vehicle); + break; case VEHICLE_STATUS_WAITING_TO_DEPART: case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: @@ -1044,6 +1144,19 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ } } +/* 0x006D7DA1 */ +static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ + vehicle->velocity = 0; + + rct_ride* ride = GET_RIDE(vehicle->ride); + + if (vehicle->var_51 == 0){ + if (sub_6D6A2C(vehicle)) + return; + //0x6d7dc1 + } +} + /** * * rct2: 0x006D95F7 @@ -1370,6 +1483,8 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d current->var_C4 = 0; current->var_C5 = 0; current->var_C8 = 0; + current->pad_CA[0] = 0; + current->pad_CA[1] = 0; current->scream_sound_id = 0xFF; current->var_1F = 0; current->var_20 = 0; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index ed70a7b72f..e58cfd5dd5 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -142,7 +142,7 @@ typedef struct { uint8 num_peeps; // 0xB3 uint8 next_free_seat; // 0xB4 uint8 var_B5; - uint16 var_B6; + sint16 var_B6; uint16 var_B8; uint8 var_BA; uint8 sound1_id; // 0xBB @@ -155,8 +155,9 @@ typedef struct { uint8 acceleration; // 0xC3 uint8 var_C4; uint8 var_C5; - uint8 pad_C6[2]; - uint32 var_C8; + uint8 pad_C6[0x2]; + uint16 var_C8; + uint8 pad_CA[0x2]; uint8 scream_sound_id; // 0xCC uint8 var_CD; union { From 392815cd0c1affff545100fabec5376bcc62f0b7 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 10 Apr 2015 08:24:36 +0100 Subject: [PATCH 015/162] Added more of waiting_for_passengers --- src/peep/peep.c | 4 +-- src/ride/ride.h | 4 ++- src/ride/vehicle.c | 89 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 93 insertions(+), 4 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index 13e2e32f2e..f6b043963f 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -1690,8 +1690,8 @@ static void peep_update_ride_sub_state_0(rct_peep* peep){ } } else{ - chosen_train = ride->var_066[peep->current_ride_station]; - } + chosen_train = ride->train_at_station[peep->current_ride_station]; + } if (chosen_train == 0xFF){ return; } diff --git a/src/ride/ride.h b/src/ride/ride.h index 285f5a75e3..15c2073702 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -193,7 +193,9 @@ typedef struct { uint8 station_heights[4]; // 0x05A uint8 station_length[4]; // 0x05E uint8 station_depart[4]; // 0x062 - uint8 var_066[4]; + // ride->vehicle index for current train waiting for passengers + // at station + uint8 train_at_station[4]; // 0x066 uint16 entrances[4]; // 0x06A uint16 exits[4]; // 0x072 uint16 last_peep_in_queue[4]; // 0x07A diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 214b712c1b..11f5157d2b 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -562,6 +562,7 @@ static int sub_6D6A2C(rct_vehicle* vehicle){ vehicle->var_B5 = 255; continue; } + vehicle->var_B5 += 20; invalidate_sprite((rct_sprite*)vehicle); ebp++; } @@ -1153,8 +1154,94 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (vehicle->var_51 == 0){ if (sub_6D6A2C(vehicle)) return; - //0x6d7dc1 + + if (ride->entrances[vehicle->current_station] == 0xFFFF){ + ride->train_at_station[vehicle->current_station] = 0xFF; + vehicle->var_51 = 2; + return; + } + + uint8 train_index = 0; + while (ride->vehicles[train_index] != vehicle->sprite_index)train_index++; + + if (ride->train_at_station[vehicle->current_station] != 0xFF) + return; + + ride->train_at_station[vehicle->current_station] = train_index; + vehicle->var_51 = 1; + vehicle->var_C0 = 0; + + invalidate_sprite((rct_sprite*)vehicle); + return; } + else if (vehicle->var_51 == 1){ + if (vehicle->var_C0 != 0xFFFF) + vehicle->var_C0++; + + vehicle->var_48 &= ~(1 << 4); + + // 0xF64E31, 0xF64E32, 0xF64E33 + uint8 num_peeps_on_train = 0, num_used_seats_on_train = 0, num_seats_on_train = 0; + + for (uint16 sprite_id = vehicle->sprite_index; sprite_id != 0xFFFF;){ + rct_vehicle* train_vehicle = GET_VEHICLE(sprite_id); + + num_peeps_on_train += train_vehicle->num_peeps; + num_used_seats_on_train += train_vehicle->next_free_seat; + num_seats_on_train += train_vehicle->num_seats; + + sprite_id = train_vehicle->next_vehicle_on_train; + } + + num_seats_on_train &= 0x7F; + + if (!(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_NO_TEST_MODE)){ + if (vehicle->var_C0 < 20){ + //0x6D7FB9 + } + } + else{ + if (num_peeps_on_train == 0){ + //0x6D7FB9 + } + } + + if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_HAS_LOAD_OPTIONS){ + if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH){ + if (ride->min_waiting_time * 32 > vehicle->var_C0){ + //0x6D7FB9 + } + } + if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MAXIMUM_LENGTH){ + if (ride->max_waiting_time * 32 < vehicle->var_C0){ + //***0x6D7FB4 + } + } + } + + if (ride->depart_flags & RIDE_DEPART_LEAVE_WHEN_ANOTHER_ARRIVES){ + + for (int i = 0; i < 32; ++i){ + uint16 train_id = ride->vehicles[i]; + if (train_id == 0xFFFF) + continue; + + if (train_id == vehicle->sprite_index) + continue; + + rct_vehicle* train = GET_VEHICLE(train_id); + + if (train->status == VEHICLE_STATUS_UNLOADING_PASSENGERS || + train->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION){ + if (train->current_station == vehicle->current_station){ + //0x6d7FB4 + } + } + } + } + //0x6d7f49 + } + //0x6d8085 } /** From fe6e0a11fa25c623605a82121a839ac370259a78 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 10 Apr 2015 12:41:23 +0100 Subject: [PATCH 016/162] Finished waiting for passengers. Bugs encountered --- src/ride/ride.c | 2 +- src/ride/vehicle.c | 144 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 138 insertions(+), 8 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index d97a21fc0d..39dd1e8dea 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -943,7 +943,7 @@ static void ride_remove_vehicles(rct_ride *ride) } for (i = 0; i < 4; i++) - ride->var_066[i] = 255; + ride->train_at_station[i] = 255; } } diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 11f5157d2b..aa4137d543 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1145,6 +1145,58 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ } } +/* 0x006D7FB4 */ +static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train, uint8 num_used_seats){ + + if (num_peeps_on_train != num_used_seats) + return; + + rct_ride* ride = GET_RIDE(vehicle->ride); + + if (ride->status == RIDE_STATUS_OPEN && + !(ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) && + !(vehicle->var_48 & (1<<4))){ + return; + } + + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)){ + if (ride->status != RIDE_STATUS_CLOSED || + ride->num_riders != 0){ + ride->train_at_station[vehicle->current_station] = 0xFF; + vehicle->var_51 = 2; + return; + } + } + + if (ride->mode == RIDE_MODE_FORWARD_ROTATION || + ride->mode == RIDE_MODE_BACKWARD_ROTATION){ + + uint8 peep = ((-vehicle->var_1F) / 8) & 0xF; + if (vehicle->peep[peep] != 0xFFFF){ + ride->train_at_station[vehicle->current_station] = 0xFF; + vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; + vehicle->var_51 = 2; + vehicle_invalidate_window(vehicle); + return; + } + + if (vehicle->num_peeps == 0) + return; + + ride->train_at_station[vehicle->current_station] = 0xFF; + vehicle->var_51 = 2; + return; + } + + if (num_peeps_on_train == 0) + return; + + ride->train_at_station[vehicle->current_station] = 0xFF; + vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; + vehicle->var_51 = 2; + vehicle_invalidate_window(vehicle); +} + /* 0x006D7DA1 */ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle->velocity = 0; @@ -1197,24 +1249,31 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (!(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_NO_TEST_MODE)){ if (vehicle->var_C0 < 20){ - //0x6D7FB9 + vehicle->var_48 |= (1 << 4); + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; } } else{ if (num_peeps_on_train == 0){ - //0x6D7FB9 + vehicle->var_48 |= (1 << 4); + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; } } if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_HAS_LOAD_OPTIONS){ if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH){ if (ride->min_waiting_time * 32 > vehicle->var_C0){ - //0x6D7FB9 + vehicle->var_48 |= (1 << 4); + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; } } if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MAXIMUM_LENGTH){ if (ride->max_waiting_time * 32 < vehicle->var_C0){ - //***0x6D7FB4 + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; } } } @@ -1234,14 +1293,85 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (train->status == VEHICLE_STATUS_UNLOADING_PASSENGERS || train->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION){ if (train->current_station == vehicle->current_station){ - //0x6d7FB4 + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; } } } } - //0x6d7f49 + + if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_HAS_LOAD_OPTIONS && + ride->depart_flags & RIDE_DEPART_WAIT_FOR_LOAD){ + + if (num_peeps_on_train == num_seats_on_train){ + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + + uint8 load = ride->depart_flags & RIDE_DEPART_WAIT_FOR_LOAD_MASK; + if (load == 3){ + vehicle->var_48 |= (1 << 4); + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + + uint8 three_quater_seats = (3 * num_seats_on_train) / 4; + if (three_quater_seats != 0 && num_peeps_on_train >= three_quater_seats){ + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + + if (load == 2){ + vehicle->var_48 |= (1 << 4); + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + + if (num_seats_on_train / 2 != 0 && num_peeps_on_train >= num_seats_on_train / 2){ + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + + if (load == 1){ + vehicle->var_48 |= (1 << 4); + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + + if (num_seats_on_train / 4 != 0 && num_peeps_on_train >= num_seats_on_train / 4){ + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + + if (load == 0){ + vehicle->var_48 |= (1 << 4); + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + + if (num_peeps_on_train != 0){ + vehicle->var_48 |= (1 << 4); + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + } + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; } - //0x6d8085 + + if (RCT2_CALLPROC_X(0x006D6956, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100) + return; + + vehicle->velocity = 0; + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->var_51 = 0; + vehicle->var_48 &= ~(1 << 2); + + if (ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS){ + vehicle->var_48 |= (1 << 2); + } + + vehicle_invalidate_window(vehicle); } /** From b60ca54e47f813b62f993fc4b207e5b2174a426f Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 12 Apr 2015 15:33:28 +0100 Subject: [PATCH 017/162] Fix some of the vehicle bugs --- src/ride/vehicle.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index aa4137d543..836ec16a91 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -476,6 +476,7 @@ void vehicle_update_all() /* rct2: 0x006D6A2C */ static int sub_6D6A2C(rct_vehicle* vehicle){ + //return RCT2_CALLPROC_X(0x006d6a2c, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100; int ebp = 0; uint16 vehicle_id = vehicle->sprite_index; @@ -569,7 +570,7 @@ static int sub_6D6A2C(rct_vehicle* vehicle){ } while ((vehicle_id = vehicle->next_vehicle_on_train) != 0xFFFF); - return ebp; + return !ebp; } /* rct2: 0x006D6D1F */ @@ -1249,7 +1250,6 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (!(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_NO_TEST_MODE)){ if (vehicle->var_C0 < 20){ - vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1355,6 +1355,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ return; } } + vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1363,7 +1364,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ return; vehicle->velocity = 0; - vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->status = VEHICLE_STATUS_WAITING_TO_DEPART; vehicle->var_51 = 0; vehicle->var_48 &= ~(1 << 2); From 7afc7453fdab2747e6348948a2e7d1579ce20c96 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 12 Apr 2015 16:25:22 +0100 Subject: [PATCH 018/162] Fix loading bugs --- src/ride/vehicle.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 836ec16a91..9233383020 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1256,7 +1256,6 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ } else{ if (num_peeps_on_train == 0){ - vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1265,13 +1264,13 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_HAS_LOAD_OPTIONS){ if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH){ if (ride->min_waiting_time * 32 > vehicle->var_C0){ - vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } } if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MAXIMUM_LENGTH){ if (ride->max_waiting_time * 32 < vehicle->var_C0){ + vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1293,6 +1292,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (train->status == VEHICLE_STATUS_UNLOADING_PASSENGERS || train->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION){ if (train->current_station == vehicle->current_station){ + vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1304,41 +1304,42 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ ride->depart_flags & RIDE_DEPART_WAIT_FOR_LOAD){ if (num_peeps_on_train == num_seats_on_train){ + vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } uint8 load = ride->depart_flags & RIDE_DEPART_WAIT_FOR_LOAD_MASK; if (load == 3){ - vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } uint8 three_quater_seats = (3 * num_seats_on_train) / 4; if (three_quater_seats != 0 && num_peeps_on_train >= three_quater_seats){ + vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } if (load == 2){ - vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } if (num_seats_on_train / 2 != 0 && num_peeps_on_train >= num_seats_on_train / 2){ - train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); - return; - } - - if (load == 1){ vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } + if (load == 1){ + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; + } + if (num_seats_on_train / 4 != 0 && num_peeps_on_train >= num_seats_on_train / 4){ + vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1351,9 +1352,9 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (num_peeps_on_train != 0){ vehicle->var_48 |= (1 << 4); - train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); - return; - } + } + train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); + return; } vehicle->var_48 |= (1 << 4); train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); From 8ac940de477acd9d528032b38ae577ba676d2906 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 12 Apr 2015 16:47:02 +0100 Subject: [PATCH 019/162] Refactor --- src/peep/peep.c | 3 +-- src/ride/ride.c | 4 ++++ src/ride/vehicle.c | 36 ++++++++++++++++++------------------ src/ride/vehicle.h | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index f6b043963f..eca608e7f7 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -2210,8 +2210,7 @@ static void peep_update_ride_sub_state_2(rct_peep* peep){ rct_vehicle *currentTrain = GET_VEHICLE(ride->vehicles[peep->current_train]); if (ride->status == RIDE_STATUS_OPEN && ++peep->var_AC != 0 && - !(vehicle->update_flags & VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART) - ) { + !(currentTrain->update_flags & VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART)){ return; } diff --git a/src/ride/ride.c b/src/ride/ride.c index 39dd1e8dea..a663f54d5e 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -2261,6 +2261,10 @@ void ride_prepare_breakdown(int rideIndex, int breakdownReason) } if (vehicle != NULL) vehicle->update_flags |= VEHICLE_UPDATE_FLAG_BROKEN_CAR; + vehicle = &(g_sprite_list[ride->vehicles[ride->broken_vehicle]].vehicle); + for (i = ride->broken_car; i > 0; i--) + vehicle = &(g_sprite_list[vehicle->next_vehicle_on_train].vehicle); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_BROKEN_CAR; break; case BREAKDOWN_VEHICLE_MALFUNCTION: // Choose a random train diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 9233383020..22a9a6edcb 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -531,7 +531,7 @@ static int sub_6D6A2C(rct_vehicle* vehicle){ continue; } - if (vehicle->var_48 & (1 << 8) && + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_CAR && vehicle->var_B5 != 0xFF && ( ride->breakdown_reason_pending == BREAKDOWN_RESTRAINTS_STUCK_CLOSED || @@ -586,7 +586,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) ride->lifecycle_flags |= RIDE_LIFECYCLE_TESTED; ride->lifecycle_flags |= RIDE_LIFECYCLE_NO_RAW_STATS; ride->lifecycle_flags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; - vehicle->var_48 &= ~(1 << 5); + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_TESTING; window_invalidate_by_number(WC_RIDE, vehicle->ride); return; } @@ -653,7 +653,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) return; uint16 track_elem_type = vehicle->track_type / 4; - if (track_elem_type == TRACK_ELEM_POWERED_LIFT || !(vehicle->var_48 & (1 << 0))){ + if (track_elem_type == TRACK_ELEM_POWERED_LIFT || !(vehicle->update_flags & VEHICLE_UPDATE_FLAG_0)){ if (!(ride->testing_flags & RIDE_TESTING_POWERED_LIFT)){ ride->testing_flags |= RIDE_TESTING_POWERED_LIFT; if (ride->drops + 64 < 0xFF){ @@ -952,7 +952,7 @@ static void vehicle_update(rct_vehicle *vehicle) rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; ride = GET_RIDE(vehicle->ride); - if (vehicle->var_48 & 0x20) + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_TESTING) vehicle_update_measurements(vehicle); RCT2_GLOBAL(0x00F64E34, uint8) = 255; @@ -965,7 +965,7 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle->velocity <= 0x20000 ) ) { - vehicle->var_48 |= 0x80; + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_15; } } } @@ -1156,7 +1156,7 @@ static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train if (ride->status == RIDE_STATUS_OPEN && !(ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) && - !(vehicle->var_48 & (1<<4))){ + !(vehicle->update_flags & VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART)){ return; } @@ -1231,7 +1231,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (vehicle->var_C0 != 0xFFFF) vehicle->var_C0++; - vehicle->var_48 &= ~(1 << 4); + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; // 0xF64E31, 0xF64E32, 0xF64E33 uint8 num_peeps_on_train = 0, num_used_seats_on_train = 0, num_seats_on_train = 0; @@ -1270,7 +1270,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ } if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MAXIMUM_LENGTH){ if (ride->max_waiting_time * 32 < vehicle->var_C0){ - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1292,7 +1292,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (train->status == VEHICLE_STATUS_UNLOADING_PASSENGERS || train->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION){ if (train->current_station == vehicle->current_station){ - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1304,7 +1304,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ ride->depart_flags & RIDE_DEPART_WAIT_FOR_LOAD){ if (num_peeps_on_train == num_seats_on_train){ - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1317,7 +1317,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ uint8 three_quater_seats = (3 * num_seats_on_train) / 4; if (three_quater_seats != 0 && num_peeps_on_train >= three_quater_seats){ - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1328,7 +1328,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ } if (num_seats_on_train / 2 != 0 && num_peeps_on_train >= num_seats_on_train / 2){ - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1339,24 +1339,24 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ } if (num_seats_on_train / 4 != 0 && num_peeps_on_train >= num_seats_on_train / 4){ - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } if (load == 0){ - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } if (num_peeps_on_train != 0){ - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; } train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } - vehicle->var_48 |= (1 << 4); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1367,10 +1367,10 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle->velocity = 0; vehicle->status = VEHICLE_STATUS_WAITING_TO_DEPART; vehicle->var_51 = 0; - vehicle->var_48 &= ~(1 << 2); + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT; if (ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS){ - vehicle->var_48 |= (1 << 2); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT; } vehicle_invalidate_window(vehicle); diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index e58cfd5dd5..0577334ad0 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -267,6 +267,25 @@ enum { VEHICLE_VISUAL_SUBMARINE }; +enum{ + VEHICLE_UPDATE_FLAG_0 = (1 << 0), + VEHICLE_UPDATE_FLAG_1 = (1 << 1), + VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT = (1 << 2), + VEHICLE_UPDATE_FLAG_3 = (1 << 3), + VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART = (1 << 4), + VEHICLE_UPDATE_FLAG_TESTING = (1 << 5), + VEHICLE_UPDATE_FLAG_6 = (1 << 6), + VEHICLE_UPDATE_FLAG_7 = (1 << 7), + VEHICLE_UPDATE_FLAG_BROKEN_CAR = (1 << 8), + VEHICLE_UPDATE_FLAG_BROKEN_TRAIN = (1 << 9), + VEHICLE_UPDATE_FLAG_10 = (1 << 10), + VEHICLE_UPDATE_FLAG_11 = (1 << 11), + VEHICLE_UPDATE_FLAG_12 = (1 << 12), + VEHICLE_UPDATE_FLAG_13 = (1 << 13), + VEHICLE_UPDATE_FLAG_14 = (1 << 14), + VEHICLE_UPDATE_FLAG_15 = (1 << 15) +}; + #define VEHICLE_SEAT_PAIR_FLAG 0x80 #define VEHICLE_SEAT_NUM_MASK 0x7F From 50dbff6dd5e4f0c187e48eea8ee9a61554208fc6 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 12 Apr 2015 17:28:55 +0100 Subject: [PATCH 020/162] Added vehicle_close_restraints --- src/ride/vehicle.c | 62 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 22a9a6edcb..1cbcd28e21 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -474,8 +474,60 @@ void vehicle_update_all() } } -/* rct2: 0x006D6A2C */ -static int sub_6D6A2C(rct_vehicle* vehicle){ +/* rct2: 0x006D6956 + * returns 0 when all closed + */ +static int vehicle_close_restraints(rct_vehicle* vehicle){ + rct_ride* ride = GET_RIDE(vehicle->ride); + int ebp = 0; + uint16 vehicle_id = vehicle->sprite_index; + + do { + vehicle = GET_VEHICLE(vehicle_id); + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_CAR && + vehicle->var_B5 != 0 && + ( + ride->breakdown_reason_pending == BREAKDOWN_RESTRAINTS_STUCK_OPEN || + ride->breakdown_reason_pending == BREAKDOWN_DOORS_STUCK_OPEN) + ){ + + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)){ + + ride->lifecycle_flags |= RIDE_LIFECYCLE_BROKEN_DOWN; + + ride_breakdown_add_news_item(vehicle->ride); + + ride->window_invalidate_flags |= + RIDE_INVALIDATE_RIDE_MAIN | + RIDE_INVALIDATE_RIDE_LIST | + RIDE_INVALIDATE_RIDE_MAINTENANCE; + + ride->mechanic_status = RIDE_MECHANIC_STATUS_CALLING; + + rct_vehicle* broken_vehicle = GET_VEHICLE(ride->vehicles[ride->broken_vehicle]); + ride->inspection_station = broken_vehicle->current_station; + + ride->breakdown_reason = ride->breakdown_reason_pending; + } + } + else{ + if (vehicle->var_B5 - 20 < 0){ + vehicle->var_B5 = 0; + continue; + } + vehicle->var_B5 -= 20; + } + invalidate_sprite((rct_sprite*)vehicle); + ebp++; + } while ((vehicle_id = vehicle->next_vehicle_on_train) != 0xFFFF); + + return ebp; +} + +/* rct2: 0x006D6A2C + * returns 0 when all open + */ +static int vehicle_open_restraints(rct_vehicle* vehicle){ //return RCT2_CALLPROC_X(0x006d6a2c, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100; int ebp = 0; @@ -570,7 +622,7 @@ static int sub_6D6A2C(rct_vehicle* vehicle){ } while ((vehicle_id = vehicle->next_vehicle_on_train) != 0xFFFF); - return !ebp; + return ebp; } /* rct2: 0x006D6D1F */ @@ -1205,7 +1257,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ rct_ride* ride = GET_RIDE(vehicle->ride); if (vehicle->var_51 == 0){ - if (sub_6D6A2C(vehicle)) + if (!vehicle_open_restraints(vehicle)) return; if (ride->entrances[vehicle->current_station] == 0xFFFF){ @@ -1361,7 +1413,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ return; } - if (RCT2_CALLPROC_X(0x006D6956, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100) + if (vehicle_close_restraints(vehicle)) return; vehicle->velocity = 0; From 2bd851e26aa22a1598264b4cd59deaa0d49a58da Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 12 Apr 2015 17:47:52 +0100 Subject: [PATCH 021/162] Fix small flag mistake --- src/ride/vehicle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 1cbcd28e21..e322639ee4 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1017,7 +1017,7 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle->velocity <= 0x20000 ) ) { - vehicle->update_flags |= VEHICLE_UPDATE_FLAG_15; + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; } } } From a66966a4d9608a6344ab49342b39abbea5853a35 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 8 Jun 2015 19:07:30 +0100 Subject: [PATCH 022/162] fix rating bugs and merge mistakes --- src/rct1.c | 2 +- src/ride/ride.c | 30 ++++++++++++----- src/ride/ride.h | 52 +--------------------------- src/ride/ride_data.c | 6 ++-- src/ride/ride_ratings.c | 75 +++++++++++++++++++---------------------- src/ride/track.c | 2 +- src/ride/vehicle.c | 31 ++++++----------- src/ride/vehicle.h | 26 +++----------- 8 files changed, 77 insertions(+), 147 deletions(-) diff --git a/src/rct1.c b/src/rct1.c index 90fe58171d..2134b67d5c 100644 --- a/src/rct1.c +++ b/src/rct1.c @@ -712,7 +712,7 @@ static void rct1_fix_z() for (int i = 0; i < 4; i++) { ride->station_heights[i] /= 2; } - ride->var_116 /= 2; + ride->start_drop_height /= 2; ride->highest_drop_height = 1; if (ride->var_11F != 255) { ride->var_11F /= 2; diff --git a/src/ride/ride.c b/src/ride/ride.c index a663f54d5e..46839e1958 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -2261,10 +2261,6 @@ void ride_prepare_breakdown(int rideIndex, int breakdownReason) } if (vehicle != NULL) vehicle->update_flags |= VEHICLE_UPDATE_FLAG_BROKEN_CAR; - vehicle = &(g_sprite_list[ride->vehicles[ride->broken_vehicle]].vehicle); - for (i = ride->broken_car; i > 0; i--) - vehicle = &(g_sprite_list[vehicle->next_vehicle_on_train].vehicle); - vehicle->update_flags |= VEHICLE_UPDATE_FLAG_BROKEN_CAR; break; case BREAKDOWN_VEHICLE_MALFUNCTION: // Choose a random train @@ -5339,7 +5335,7 @@ foundRideEntry: ride->station_starts[i] = 0xFFFF; ride->entrances[i] = 0xFFFF; ride->exits[i] = 0xFFFF; - ride->var_066[i] = 255; + ride->train_at_station[i] = 255; ride->queue_time[i] = 0; } @@ -5909,6 +5905,8 @@ void increment_turn_count_1_element(rct_ride* ride, uint8 type){ case 2: turn_count = &ride->turn_count_sloped; break; + default: + return; } uint16 value = (*turn_count & TURN_MASK_1_ELEMENT) + 1; *turn_count &= ~TURN_MASK_1_ELEMENT; @@ -5930,6 +5928,8 @@ void increment_turn_count_2_elements(rct_ride* ride, uint8 type){ case 2: turn_count = &ride->turn_count_sloped; break; + default: + return; } uint16 value = (*turn_count & TURN_MASK_2_ELEMENTS) + 0x20; *turn_count &= ~TURN_MASK_2_ELEMENTS; @@ -5951,6 +5951,8 @@ void increment_turn_count_3_elements(rct_ride* ride, uint8 type){ case 2: turn_count = &ride->turn_count_sloped; break; + default: + return; } uint16 value = (*turn_count & TURN_MASK_3_ELEMENTS) + 0x100; *turn_count &= ~TURN_MASK_3_ELEMENTS; @@ -5971,6 +5973,8 @@ void increment_turn_count_4_plus_elements(rct_ride* ride, uint8 type){ case 2: turn_count = &ride->turn_count_sloped; break; + default: + return; } uint16 value = (*turn_count & TURN_MASK_4_PLUS_ELEMENTS) + 0x800; *turn_count &= ~TURN_MASK_4_PLUS_ELEMENTS; @@ -5992,6 +5996,8 @@ int get_turn_count_1_element(rct_ride* ride, uint8 type) { case 2: turn_count = &ride->turn_count_sloped; break; + default: + return 0; } return (*turn_count) & TURN_MASK_1_ELEMENT; @@ -6009,9 +6015,11 @@ int get_turn_count_2_elements(rct_ride* ride, uint8 type) { case 2: turn_count = &ride->turn_count_sloped; break; + default: + return 0; } - return (*turn_count >> 5) & TURN_MASK_2_ELEMENTS; + return ((*turn_count) & TURN_MASK_2_ELEMENTS) >> 5; } int get_turn_count_3_elements(rct_ride* ride, uint8 type) { @@ -6026,9 +6034,11 @@ int get_turn_count_3_elements(rct_ride* ride, uint8 type) { case 2: turn_count = &ride->turn_count_sloped; break; + default: + return 0; } - return (*turn_count >> 8) & TURN_MASK_3_ELEMENTS; + return ((*turn_count) & TURN_MASK_3_ELEMENTS) >> 8; } int get_turn_count_4_plus_elements(rct_ride* ride, uint8 type) { @@ -6040,9 +6050,11 @@ int get_turn_count_4_plus_elements(rct_ride* ride, uint8 type) { case 2: turn_count = &ride->turn_count_sloped; break; + default: + return 0; } - return (*turn_count >> 11) & TURN_MASK_4_PLUS_ELEMENTS; + return ((*turn_count) & TURN_MASK_4_PLUS_ELEMENTS) >> 11; } bool ride_has_spinning_tunnel(rct_ride *ride) { @@ -6720,7 +6732,7 @@ void ride_update_max_vehicles(int rideIndex) for (int i = 0; i < numCars; i++) { vehicleEntry = &rideEntry->vehicles[trainLayout[i]]; trainLength += vehicleEntry->spacing; - totalFriction += vehicleEntry->friction; + totalFriction += vehicleEntry->car_friction; } if (trainLength <= stationLength && totalFriction <= maxFriction) { diff --git a/src/ride/ride.h b/src/ride/ride.h index 15c2073702..0cbc944584 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -70,56 +70,6 @@ typedef struct { vehicle_colour list[256]; } vehicle_colour_preset_list; -/** - * Ride type vehicle structure. - * size: 0x65 - */ -typedef struct{ - uint16 var_00; // 0x00 , 0x1A - uint8 var_02; // 0x02 , 0x1C - uint8 var_03; // 0x03 , 0x1D - uint32 spacing; // 0x04 , 0x1E - uint16 friction; // 0x08 , 0x22 - sint8 var_0A; // 0x0A , 0x24 - uint8 pad_0B; - uint16 available_sprites; // 0x0C , 0x26 - uint8 var_0E; // 0x0E , 0x28 - uint8 var_0F; // 0x0F , 0x29 - uint8 var_10; // 0x10 , 0x2A - uint8 var_11; // 0x11 , 0x2B - uint16 var_12; // 0x12 , 0x2C - uint16 var_14; // 0x14 , 0x2E - uint16 var_16; // 0x16 , 0x30 - uint32 base_image_id; // 0x18 , 0x32 - uint32 var_1C; // 0x1C , 0x36 - uint32 var_20; // 0x20 , 0x3A - uint32 var_24; // 0x24 , 0x3E - uint32 var_28; // 0x28 , 0x42 - uint32 var_2C; // 0x2C , 0x46 - uint32 var_30; // 0x30 , 0x4A - uint32 var_34; // 0x34 , 0x4E - uint32 var_38; // 0x38 , 0x52 - uint32 var_3C; // 0x3C , 0x56 - uint32 var_40; // 0x40 , 0x5A - uint32 var_44; // 0x44 , 0x5E - uint32 var_48; // 0x48 , 0x62 - uint32 var_4C; // 0x4C , 0x66 - uint32 no_vehicle_images; // 0x50 , 0x6A - uint8 no_seating_rows; // 0x54 , 0x6E - uint8 spinning_inertia; // 0x55 , 0x6F - uint8 spinning_friction; // 0x56 , 0x70 - uint8 var_57; // 0x57 , 0x71 - uint8 pad_58; - uint8 sound_range; // 0x59 , 0x73 - uint8 var_5A; // 0x5A , 0x74 - uint8 pad_5B; // 0x5B , 0x75 - uint8 var_5C; // 0x5C , 0x76 - uint8 var_5D; // 0x5D , 0x77 - uint8 pad_5E[0x2]; - uint8 var_60; // 0x60 , 0x7A - sint8* peep_loading_positions; // 0x61 , 0x7B -} rct_ride_type_vehicle; - /** * Ride type structure. * size: unknown @@ -147,7 +97,7 @@ typedef struct { uint8 third_vehicle; // 0x018 uint8 pad_019; rct_ride_type_vehicle vehicles[4]; // 0x1A - uint32 var_1AE; + vehicle_colour_preset_list *vehicle_preset_list; // 0x1AE sint8 excitement_multipler; // 0x1B2 sint8 intensity_multipler; // 0x1B3 sint8 nausea_multipler; // 0x1B4 diff --git a/src/ride/ride_data.c b/src/ride/ride_data.c index c7cc940212..3f48607a17 100644 --- a/src/ride/ride_data.c +++ b/src/ride/ride_data.c @@ -1256,7 +1256,7 @@ const rct_ride_type_vehicle CableLiftVehicle = { .rotation_frame_mask = 31, .var_02 = 0, .var_03 = 0, - .var_04 = 0, + .spacing = 0, .car_friction = 0, .tab_height = 0, .num_seats = 0, @@ -1286,7 +1286,9 @@ const rct_ride_type_vehicle CableLiftVehicle = { .no_seating_rows = 0, .spinning_inertia = 0, .spinning_friction = 255, - .pad_57 = { 0,0,0 }, + .var_57 = 0, + .pad_58 = 0, + .sound_range = 0, .var_5A = 0, .powered_acceleration = 0, .powered_max_speed = 0, diff --git a/src/ride/ride_ratings.c b/src/ride/ride_ratings.c index 0f99ce8052..ebebef733b 100644 --- a/src/ride/ride_ratings.c +++ b/src/ride/ride_ratings.c @@ -931,23 +931,24 @@ static int sub_65E72D(rct_ride *ride) } static rating_tuple get_flat_turns_rating(rct_ride* ride) { + rating_tuple rating; + int no_3_plus_turns = get_turn_count_3_elements(ride, 0); int no_2_turns = get_turn_count_2_elements(ride, 0); int no_1_turns = get_turn_count_1_element(ride, 0); - int excitement = (no_3_plus_turns * 0x28000) >> 16; - excitement += no_2_turns * 3; - excitement += (no_1_turns * 63421) >> 16; + rating.excitement = (no_3_plus_turns * 0x28000) >> 16; + rating.excitement += (no_2_turns * 0x30000) >> 16; + rating.excitement += (no_1_turns * 63421) >> 16; - int intensity = (no_3_plus_turns * 81920) >> 16; - intensity += (no_2_turns * 49152) >> 16; - intensity += (no_1_turns * 21140) >> 16; + rating.intensity = (no_3_plus_turns * 81920) >> 16; + rating.intensity += (no_2_turns * 49152) >> 16; + rating.intensity += (no_1_turns * 21140) >> 16; - int nausea = no_3_plus_turns * 5; - nausea += (no_2_turns * 0x3200) >> 16; - nausea += (no_1_turns * 42281) >> 16; + rating.nausea = (no_3_plus_turns * 0x50000) >> 16; + rating.nausea += (no_2_turns * 0x32000) >> 16; + rating.nausea += (no_1_turns * 42281) >> 16; - rating_tuple rating = { excitement, intensity, nausea }; return rating; } @@ -955,23 +956,24 @@ static rating_tuple get_flat_turns_rating(rct_ride* ride) { * rct2: 0x0065DF72 */ static rating_tuple get_banked_turns_rating(rct_ride* ride) { + rating_tuple rating; + int no_3_plus_turns = get_turn_count_3_elements(ride, 1); int no_2_turns = get_turn_count_2_elements(ride, 1); int no_1_turns = get_turn_count_1_element(ride, 1); - int excitement = (no_3_plus_turns * 0x3c000) >> 16; - excitement += (no_2_turns * 0x3c000) >> 16; - excitement += (no_1_turns * 73992) >> 16; + rating.excitement = (no_3_plus_turns * 0x3C000) >> 16; + rating.excitement += (no_2_turns * 0x3C000) >> 16; + rating.excitement += (no_1_turns * 73992) >> 16; - int intensity = (no_3_plus_turns * 0x14000) >> 16; - intensity += (no_2_turns * 49152) >> 16; - intensity += (no_1_turns * 21140) >> 16; + rating.intensity = (no_3_plus_turns * 0x14000) >> 16; + rating.intensity += (no_2_turns * 49152) >> 16; + rating.intensity += (no_1_turns * 21140) >> 16; - int nausea = no_3_plus_turns * 5; - nausea += (no_2_turns * 0x32000) >> 16; - nausea += (no_1_turns * 48623) >> 16; + rating.nausea = (no_3_plus_turns * 0x50000) >> 16; + rating.nausea += (no_2_turns * 0x32000) >> 16; + rating.nausea += (no_1_turns * 48623) >> 16; - rating_tuple rating = { excitement, intensity, nausea }; return rating; } @@ -979,28 +981,20 @@ static rating_tuple get_banked_turns_rating(rct_ride* ride) { * rct2: 0x0065E047 */ static rating_tuple get_sloped_turns_rating(rct_ride* ride) { + rating_tuple rating; + int no_4_plus_turns = get_turn_count_4_plus_elements(ride, 2); int no_3_turns = get_turn_count_3_elements(ride, 2); int no_2_turns = get_turn_count_2_elements(ride, 2); int no_1_turns = get_turn_count_1_element(ride, 2); - int al; - al = min(no_4_plus_turns, 4); - int excitement = (al * 0x78000) >> 16; + rating.excitement = (min(no_4_plus_turns, 4) * 0x78000) >> 16; + rating.excitement += (min(no_3_turns, 6) * 273066) >> 16; + rating.excitement += (min(no_2_turns, 6) * 0x3AAAA) >> 16; + rating.excitement += (min(no_1_turns, 7) * 187245) >> 16; + rating.intensity = 0; + rating.nausea = (min(no_4_plus_turns, 8) * 0x78000) >> 16; - al = min(no_4_plus_turns, 8); - int nausea = (al * 0x78000) >> 16; - - al = min(no_3_turns, 6); - excitement += (al * 273066) >> 16; - - al = min(no_2_turns, 6); - excitement += (al * 0x3aaaa) >> 16; - - al = min(no_1_turns, 7); - excitement += (al * 187245) >> 16; - - rating_tuple rating = { excitement, 0, nausea }; return rating; } @@ -1008,11 +1002,12 @@ static rating_tuple get_sloped_turns_rating(rct_ride* ride) { * rct2: 0x0065E0F2 */ static rating_tuple get_inversions_ratings(uint8 inversions) { - int excitement = (min(inversions, 6) * 0x1AAAAA) >> 16; - int intensity = (inversions * 0x320000) >> 16; - int nausea = (inversions * 0x15AAAA) >> 16; + rating_tuple rating; + + rating.excitement = (min(inversions, 6) * 0x1AAAAA) >> 16; + rating.intensity = (inversions * 0x320000) >> 16; + rating.nausea = (inversions * 0x15AAAA) >> 16; - rating_tuple rating = { excitement, intensity, nausea }; return rating; } diff --git a/src/ride/track.c b/src/ride/track.c index ff7bf11948..a66b0fc42c 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -4241,7 +4241,7 @@ static money32 track_place(int rideIndex, int type, int originX, int originY, in if (!gCheatsDisableSupportLimits){ int ride_height = clearanceZ - mapElement->base_height; if (ride_height >= 0) { - int maxHeight = rideEntry->max_height; + int maxHeight = rideEntry->additional_max_height; if (maxHeight == 0) { maxHeight = RCT2_GLOBAL(0x0097D218 + (ride->type * 8), uint8); } diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index e322639ee4..930dde1fe0 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -517,7 +517,7 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ } vehicle->var_B5 -= 20; } - invalidate_sprite((rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); ebp++; } while ((vehicle_id = vehicle->next_vehicle_on_train) != 0xFFFF); @@ -563,7 +563,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ vehicle->var_BA += value; vehicle->var_B6 -= value; - invalidate_sprite((rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); continue; } @@ -574,7 +574,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ vehicle->var_C8 = vehicle->var_C8 + 0x3333 - 0xFFFF; vehicle->var_C5++; vehicle->var_C5 &= 7; - invalidate_sprite((rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); } else{ vehicle->var_C8 += 0x3333; @@ -616,7 +616,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ continue; } vehicle->var_B5 += 20; - invalidate_sprite((rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); ebp++; } @@ -696,9 +696,9 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } } - uint16 map_location = (vehicle->var_38 / 32) | ((vehicle->var_3A / 32) << 8); - if (vehicle->var_3C / 8 != ride->var_11F || map_location != ride->var_10C){ - ride->var_11F = vehicle->var_3C / 8; + uint16 map_location = (vehicle->track_x / 32) | ((vehicle->track_y / 32) << 8); + if (vehicle->track_z / 8 != ride->var_11F || map_location != ride->var_10C){ + ride->var_11F = vehicle->track_z / 8; ride->var_10C = map_location; if (ride->entrances[ride->var_1F6] == 0xFFFF) @@ -1089,15 +1089,6 @@ static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle) vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; } -static void sub_6DAB4C(rct_vehicle* vehicle, int* eax, int* ebx){ - int eax_, ebx_, ecx, edx, esi, ebp, edi; - esi = (int)vehicle; - RCT2_CALLFUNC_X(0x006DAB4C, &eax_, &ebx_, &ecx, &edx, &esi, &edi, &ebp); - - *eax = eax_; - *ebx = ebx_; -} - /** * * rct2: 0x006D7BCC @@ -1119,7 +1110,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ vehicle->var_2C = 0; } - sub_6DAB4C(vehicle, &eax, &ebx); + eax = sub_6DAB4C(vehicle, &ebx); if (!(eax&(1 << 5))) break; //Fall through to next case @@ -1163,7 +1154,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ } int station; - sub_6DAB4C(vehicle, &eax, &station); + eax = sub_6DAB4C(vehicle, &station); if (eax & (1 << 1)){ vehicle->velocity = 0; @@ -1276,7 +1267,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle->var_51 = 1; vehicle->var_C0 = 0; - invalidate_sprite((rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); return; } else if (vehicle->var_51 == 1){ @@ -1552,9 +1543,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle) } /** -<<<<<<< 0bfcf9391dbd97ecf76b3e6440e443ad52442517 * -======= * * rct2: 0x006D796B */ diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 0577334ad0..025a8ee7b6 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -37,7 +37,7 @@ typedef struct { uint16 rotation_frame_mask; // 0x00 , 0x1A uint8 var_02; // 0x02 , 0x1C uint8 var_03; // 0x03 , 0x1D - uint32 var_04; // 0x04 , 0x1E + uint32 spacing; // 0x04 , 0x1E uint16 car_friction; // 0x08 , 0x22 sint8 tab_height; // 0x0A , 0x24 uint8 num_seats; // 0x0B , 0x25 @@ -67,7 +67,9 @@ typedef struct { uint8 no_seating_rows; // 0x54 , 0x6E uint8 spinning_inertia; // 0x55 , 0x6F uint8 spinning_friction; // 0x56 , 0x70 - uint8 pad_57[0x3]; + uint8 var_57; // 0x57 , 0x71 + uint8 pad_58; + uint8 sound_range; // 0x59 , 0x73 uint8 var_5A; // 0x5A , 0x74 uint8 powered_acceleration; // 0x5B , 0x75 uint8 powered_max_speed; // 0x5C , 0x76 @@ -105,7 +107,6 @@ typedef struct { uint8 var_20; uint8 pad_21[3]; uint32 var_24; - uint8 pad_21[0x07]; sint32 velocity; // 0x28 sint32 var_2C; uint8 ride; // 0x30 @@ -267,25 +268,6 @@ enum { VEHICLE_VISUAL_SUBMARINE }; -enum{ - VEHICLE_UPDATE_FLAG_0 = (1 << 0), - VEHICLE_UPDATE_FLAG_1 = (1 << 1), - VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT = (1 << 2), - VEHICLE_UPDATE_FLAG_3 = (1 << 3), - VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART = (1 << 4), - VEHICLE_UPDATE_FLAG_TESTING = (1 << 5), - VEHICLE_UPDATE_FLAG_6 = (1 << 6), - VEHICLE_UPDATE_FLAG_7 = (1 << 7), - VEHICLE_UPDATE_FLAG_BROKEN_CAR = (1 << 8), - VEHICLE_UPDATE_FLAG_BROKEN_TRAIN = (1 << 9), - VEHICLE_UPDATE_FLAG_10 = (1 << 10), - VEHICLE_UPDATE_FLAG_11 = (1 << 11), - VEHICLE_UPDATE_FLAG_12 = (1 << 12), - VEHICLE_UPDATE_FLAG_13 = (1 << 13), - VEHICLE_UPDATE_FLAG_14 = (1 << 14), - VEHICLE_UPDATE_FLAG_15 = (1 << 15) -}; - #define VEHICLE_SEAT_PAIR_FLAG 0x80 #define VEHICLE_SEAT_NUM_MASK 0x7F From 31e351b13fbfec271f7f50e1bd1cb928b58fc62e Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 17 Nov 2015 20:23:26 +0000 Subject: [PATCH 023/162] Revert name change of additional max height --- src/ride/ride.h | 2 +- src/ride/track.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index 0cbc944584..1187ad0389 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -101,7 +101,7 @@ typedef struct { sint8 excitement_multipler; // 0x1B2 sint8 intensity_multipler; // 0x1B3 sint8 nausea_multipler; // 0x1B4 - uint8 additional_max_height; // 0x1B5 + uint8 max_height; // 0x1B5 union { uint64 enabledTrackPieces; // 0x1B6 struct { diff --git a/src/ride/track.c b/src/ride/track.c index a66b0fc42c..ff7bf11948 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -4241,7 +4241,7 @@ static money32 track_place(int rideIndex, int type, int originX, int originY, in if (!gCheatsDisableSupportLimits){ int ride_height = clearanceZ - mapElement->base_height; if (ride_height >= 0) { - int maxHeight = rideEntry->additional_max_height; + int maxHeight = rideEntry->max_height; if (maxHeight == 0) { maxHeight = RCT2_GLOBAL(0x0097D218 + (ride->type * 8), uint8); } From 4541e43cf02ea81364713fcd6e512fada0dacc7a Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 17 Nov 2015 21:49:45 +0000 Subject: [PATCH 024/162] Marginal improvements in accuracy by using right shifts and one logic mistake --- src/ride/vehicle.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 930dde1fe0..0d4a896967 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -662,7 +662,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) ride->time[var_E0]++; } - sint32 distance = abs(((vehicle->velocity + vehicle->var_2C) / 1024) * 42); + sint32 distance = abs(((vehicle->velocity + vehicle->var_2C) >> 10) * 42); if (vehicle->var_CE == 0){ ride->length[var_E0] += distance; } @@ -673,8 +673,8 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) vertical_g += ride->previous_vertical_g; lateral_g += ride->previous_lateral_g; - vertical_g /= 2; - lateral_g /= 2; + vertical_g >>= 1; + lateral_g >>= 1; ride->previous_vertical_g = vertical_g; ride->previous_lateral_g = lateral_g; @@ -705,7 +705,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) return; uint16 track_elem_type = vehicle->track_type / 4; - if (track_elem_type == TRACK_ELEM_POWERED_LIFT || !(vehicle->update_flags & VEHICLE_UPDATE_FLAG_0)){ + if (track_elem_type == TRACK_ELEM_POWERED_LIFT || (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0)){ if (!(ride->testing_flags & RIDE_TESTING_POWERED_LIFT)){ ride->testing_flags |= RIDE_TESTING_POWERED_LIFT; if (ride->drops + 64 < 0xFF){ @@ -864,7 +864,6 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) ride->drops |= drops; ride->start_drop_height = vehicle->z / 8; - testing_flags &= ~RIDE_TESTING_DROP_UP; } if (track_flags & TRACK_ELEM_FLAG_INVERSION){ @@ -941,7 +940,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } } - sint32 distance = ((vehicle->velocity + vehicle->var_2C) / 1024) * 42; + sint32 distance = ((vehicle->velocity + vehicle->var_2C) >> 10) * 42; if (distance < 0)return; ride->sheltered_length += distance; From 24efa0f1fda236ab94418104780cd3a676f34cc6 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 18 Nov 2015 19:26:01 +0000 Subject: [PATCH 025/162] Fix small bug in cover code --- src/ride/vehicle.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 0d4a896967..b064f46d76 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -901,24 +901,31 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) rct_map_element* map_element = map_get_surface_element_at(x / 32, y / 32); if (map_element->base_height * 8 <= vehicle->z){ - for (;; map_element++){ - if (map_element_is_last_for_tile(map_element)){ - ride->testing_flags &= ~RIDE_TESTING_SHELTERED; - return; + bool cover_found = false; + do{ + if (map_element_get_type(map_element) == MAP_ELEMENT_TYPE_SCENERY_MULTIPLE) { + cover_found = true; + break; } - if (map_element_get_type(map_element) == MAP_ELEMENT_TYPE_SCENERY_MULTIPLE) - break; - - if (map_element_get_type(map_element) == MAP_ELEMENT_TYPE_PATH) + if (map_element_get_type(map_element) == MAP_ELEMENT_TYPE_PATH) { + cover_found = true; break; + } if (map_element_get_type(map_element) != MAP_ELEMENT_TYPE_SCENERY) continue; - rct_scenery_entry* scenery = (rct_scenery_entry*)object_entry_groups[OBJECT_TYPE_SMALL_SCENERY].chunks[map_element->properties.scenery.type]; - if (scenery->small_scenery.flags & SMALL_SCENERY_FLAG_FULL_TILE) + rct_scenery_entry* scenery = g_smallSceneryEntries[map_element->properties.scenery.type]; + if (scenery->small_scenery.flags & SMALL_SCENERY_FLAG_FULL_TILE) { + cover_found = true; break; + } + } while (!map_element_is_last_for_tile(map_element++)); + + if (cover_found == false) { + ride->testing_flags &= ~RIDE_TESTING_SHELTERED; + return; } } From a71316c7a35d0192e9cb01fe8569c47946070808 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 18 Nov 2015 20:12:24 +0000 Subject: [PATCH 026/162] Small fix. --- src/ride/vehicle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index b064f46d76..c88cda1957 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -567,7 +567,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ continue; } - if (vehicleEntry->var_12 == 6 && + if (vehicleEntry->var_11 == 6 && vehicle->var_C5 != 0){ if (vehicle->var_C8 + 0x3333 < 0xFFFF){ @@ -924,8 +924,8 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } while (!map_element_is_last_for_tile(map_element++)); if (cover_found == false) { - ride->testing_flags &= ~RIDE_TESTING_SHELTERED; - return; + ride->testing_flags &= ~RIDE_TESTING_SHELTERED; + return; } } From b7491061770bbc1a302f571bdd767170961c96a1 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 19 Nov 2015 18:44:24 +0000 Subject: [PATCH 027/162] Fix restraint issue. --- src/ride/station.c | 2 +- src/ride/track_paint.c | 4 +- src/ride/vehicle.c | 104 ++++++++++++++++++++--------------------- src/ride/vehicle.h | 4 +- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/ride/station.c b/src/ride/station.c index 91f25949fb..0db623df5e 100644 --- a/src/ride/station.c +++ b/src/ride/station.c @@ -105,7 +105,7 @@ static void ride_update_station_bumpercar(rct_ride *ride, int stationIndex) dh = (dx >> 8) & 0xFF; for (i = 0; i < ride->num_vehicles; i++) { vehicle = &(g_sprite_list[ride->vehicles[i]].vehicle); - if (vehicle->var_CE < dh || (vehicle->var_CE < dh && vehicle->var_51 > dl)) + if (vehicle->var_CE < dh || (vehicle->var_CE < dh && vehicle->sub_state > dl)) continue; // End match diff --git a/src/ride/track_paint.c b/src/ride/track_paint.c index 44d14d0a8d..5db853655d 100644 --- a/src/ride/track_paint.c +++ b/src/ride/track_paint.c @@ -310,9 +310,9 @@ void top_spin_paint_vehicle(sint8 al, sint8 cl, uint8 rideIndex, uint8 direction uint32 seatImageId; - if (vehicle != NULL && vehicle->var_B5 >= 64) { + if (vehicle != NULL && vehicle->restraints_position >= 64) { // Open Restraints - image_id = (vehicle->var_B5 - 64) >> 6; + image_id = (vehicle->restraints_position - 64) >> 6; image_id += direction * 3; image_id += rideEntry->vehicles[0].base_image_id; image_id += 64; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index c88cda1957..29671a3dae 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -485,7 +485,7 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ do { vehicle = GET_VEHICLE(vehicle_id); if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_CAR && - vehicle->var_B5 != 0 && + vehicle->restraints_position != 0 && ( ride->breakdown_reason_pending == BREAKDOWN_RESTRAINTS_STUCK_OPEN || ride->breakdown_reason_pending == BREAKDOWN_DOORS_STUCK_OPEN) @@ -511,11 +511,11 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ } } else{ - if (vehicle->var_B5 - 20 < 0){ - vehicle->var_B5 = 0; + if (vehicle->restraints_position - 20 < 0){ + vehicle->restraints_position = 0; continue; } - vehicle->var_B5 -= 20; + vehicle->restraints_position -= 20; } invalidate_sprite_2((rct_sprite*)vehicle); ebp++; @@ -528,7 +528,7 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ * returns 0 when all open */ static int vehicle_open_restraints(rct_vehicle* vehicle){ - //return RCT2_CALLPROC_X(0x006d6a2c, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100; + //return (RCT2_CALLPROC_X(0x006d6a2c, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100); int ebp = 0; uint16 vehicle_id = vehicle->sprite_index; @@ -544,29 +544,29 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - if (vehicleEntry->var_14 & (1 << 2) && - abs(vehicle->var_B6) <= 700 && - !(vehicle->var_BA & 0x30) && - ( - !(vehicleEntry->var_12 & (1 << 14)) || - !(vehicle->var_BA & 0xF8)) - ){ - vehicle->var_B6 = 0; - } - else{ - ebp++; - - if (abs(vehicle->var_B6) < 600){ - vehicle->var_B6 = 600; + if (vehicleEntry->var_14 & (1 << 2)) { + if (abs(vehicle->var_B6) <= 700 && + !(vehicle->var_BA & 0x30) && + ( + !(vehicleEntry->var_12 & (1 << 14)) || + !(vehicle->var_BA & 0xF8)) + ){ + vehicle->var_B6 = 0; } - sint16 value = vehicle->var_B6 / 256; - vehicle->var_BA += value; - vehicle->var_B6 -= value; + else { + ebp++; - invalidate_sprite_2((rct_sprite*)vehicle); - continue; + if (abs(vehicle->var_B6) < 600) { + vehicle->var_B6 = 600; + } + sint16 value = vehicle->var_B6 / 256; + vehicle->var_BA += value; + vehicle->var_B6 -= value; + + invalidate_sprite_2((rct_sprite*)vehicle); + continue; + } } - if (vehicleEntry->var_11 == 6 && vehicle->var_C5 != 0){ @@ -584,7 +584,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ } if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_CAR && - vehicle->var_B5 != 0xFF && + vehicle->restraints_position != 0xFF && ( ride->breakdown_reason_pending == BREAKDOWN_RESTRAINTS_STUCK_CLOSED || ride->breakdown_reason_pending == BREAKDOWN_DOORS_STUCK_CLOSED) @@ -611,11 +611,11 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ } else{ - if (vehicle->var_B5 + 20 > 0xFF){ - vehicle->var_B5 = 255; + if (vehicle->restraints_position + 20 > 0xFF){ + vehicle->restraints_position = 255; continue; } - vehicle->var_B5 += 20; + vehicle->restraints_position += 20; invalidate_sprite_2((rct_sprite*)vehicle); ebp++; } @@ -1057,7 +1057,7 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_TRAVELLING_15: { int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); - RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->var_51 << 8) | ride->mode, (int)vehicle, 0, 0); + RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->sub_state << 8) | ride->mode, (int)vehicle, 0, 0); } break; @@ -1090,8 +1090,8 @@ static void vehicle_ride_null_update_travelling(rct_vehicle *vehicle) static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle) { - vehicle->var_51++; - if (vehicle->var_51 >= 64) + vehicle->sub_state++; + if (vehicle->sub_state >= 64) vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; } @@ -1141,7 +1141,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ vehicle->velocity = 0; vehicle->var_2C = 0; vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; - vehicle->var_51 = 0; + vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); break; default: @@ -1165,19 +1165,19 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ if (eax & (1 << 1)){ vehicle->velocity = 0; vehicle->var_2C = 0; - vehicle->var_51++; + vehicle->sub_state++; if (ride->mode == RIDE_MODE_RACE && - vehicle->var_51 >= 40){ + vehicle->sub_state >= 40){ vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; - vehicle->var_51 = 0; + vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); break; } } else{ if (vehicle->velocity > 98955){ - vehicle->var_51 = 0; + vehicle->sub_state = 0; } } @@ -1188,7 +1188,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ vehicle->velocity = 0; vehicle->var_2C = 0; vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; - vehicle->var_51 = 0; + vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); break; } @@ -1213,7 +1213,7 @@ static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train if (ride->status != RIDE_STATUS_CLOSED || ride->num_riders != 0){ ride->train_at_station[vehicle->current_station] = 0xFF; - vehicle->var_51 = 2; + vehicle->sub_state = 2; return; } } @@ -1225,7 +1225,7 @@ static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train if (vehicle->peep[peep] != 0xFFFF){ ride->train_at_station[vehicle->current_station] = 0xFF; vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; - vehicle->var_51 = 2; + vehicle->sub_state = 2; vehicle_invalidate_window(vehicle); return; } @@ -1234,7 +1234,7 @@ static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train return; ride->train_at_station[vehicle->current_station] = 0xFF; - vehicle->var_51 = 2; + vehicle->sub_state = 2; return; } @@ -1243,7 +1243,7 @@ static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train ride->train_at_station[vehicle->current_station] = 0xFF; vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; - vehicle->var_51 = 2; + vehicle->sub_state = 2; vehicle_invalidate_window(vehicle); } @@ -1253,13 +1253,13 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ rct_ride* ride = GET_RIDE(vehicle->ride); - if (vehicle->var_51 == 0){ - if (!vehicle_open_restraints(vehicle)) + if (vehicle->sub_state == 0){ + if (vehicle_open_restraints(vehicle)) return; if (ride->entrances[vehicle->current_station] == 0xFFFF){ ride->train_at_station[vehicle->current_station] = 0xFF; - vehicle->var_51 = 2; + vehicle->sub_state = 2; return; } @@ -1270,13 +1270,13 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ return; ride->train_at_station[vehicle->current_station] = train_index; - vehicle->var_51 = 1; + vehicle->sub_state = 1; vehicle->var_C0 = 0; invalidate_sprite_2((rct_sprite*)vehicle); return; } - else if (vehicle->var_51 == 1){ + else if (vehicle->sub_state == 1){ if (vehicle->var_C0 != 0xFFFF) vehicle->var_C0++; @@ -1415,7 +1415,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle->velocity = 0; vehicle->status = VEHICLE_STATUS_WAITING_TO_DEPART; - vehicle->var_51 = 0; + vehicle->sub_state = 0; vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT; if (ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS){ @@ -1436,14 +1436,14 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; - totalTime = *(RCT2_ADDRESS(0x009A0AB4, uint16*)[vehicle->var_51]); + totalTime = *(RCT2_ADDRESS(0x009A0AB4, uint16*)[vehicle->sub_state]); currentTime = vehicle->var_4C + 1; if (currentTime <= totalTime) { vehicle->var_4C = currentTime; } else { vehicle->status = VEHICLE_STATUS_ARRIVING; vehicle_invalidate_window(vehicle); - vehicle->var_51 = 0; + vehicle->sub_state = 0; vehicle->var_C0 = 0; } } @@ -1740,7 +1740,7 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d current->var_4A = 0; current->var_4C = 0; current->var_4E = 0; - current->var_B5 = 0; + current->restraints_position = 0; current->var_BA = 0; current->var_B6 = 0; current->var_B8 = 0; @@ -1771,7 +1771,7 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d current->var_34 = 164; current->update_flags = VEHICLE_UPDATE_FLAG_1; current->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; - current->var_51 = 0; + current->sub_state = 0; current->num_peeps = 0; current->next_free_seat = 0; return current; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 025a8ee7b6..206f40743b 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -136,13 +136,13 @@ typedef struct { uint16 var_4C; uint16 var_4E; uint8 status; // 0x50 - uint8 var_51; + uint8 sub_state; // 0x51 uint16 peep[32]; // 0x52 uint8 peep_tshirt_colours[32]; // 0x92 uint8 num_seats; // 0xB2 uint8 num_peeps; // 0xB3 uint8 next_free_seat; // 0xB4 - uint8 var_B5; + uint8 restraints_position; // 0xB5 0 == Close, 255 == Open sint16 var_B6; uint16 var_B8; uint8 var_BA; From a2312616ab628319da442b184e36bf2391f50b4b Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 19 Nov 2015 20:28:07 +0000 Subject: [PATCH 028/162] Added update showing film --- src/ride/ride_data.c | 7 +++++++ src/ride/ride_data.h | 2 ++ src/ride/vehicle.c | 38 +++++++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/ride/ride_data.c b/src/ride/ride_data.c index 3f48607a17..c02f0202e6 100644 --- a/src/ride/ride_data.c +++ b/src/ride/ride_data.c @@ -1298,3 +1298,10 @@ const rct_ride_type_vehicle CableLiftVehicle = { .special_frames = 0, .peep_loading_positions = NULL }; + +/* rct2: 0x009A0AA0 */ +const uint16 RideFilmLength[3] = { + 5000, // MOUSE_TAILS + 6000, // STORM_CHASERS + 7000 // SPACE_RAIDERS +}; diff --git a/src/ride/ride_data.h b/src/ride/ride_data.h index bd124525b5..89c55c3b96 100644 --- a/src/ride/ride_data.h +++ b/src/ride/ride_data.h @@ -97,4 +97,6 @@ extern const uint32 ShopItemImage[SHOP_ITEM_COUNT]; extern const rct_ride_type_vehicle CableLiftVehicle; +extern const uint16 RideFilmLength[3]; + #endif diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 29671a3dae..75b0ad9aa9 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -42,6 +42,7 @@ static void vehicle_ride_null_update_departing(rct_vehicle *vehicle); static void vehicle_ride_null_update_travelling(rct_vehicle *vehicle); static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle); +static void vehicle_update_showing_film(rct_vehicle *vehicle); static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); @@ -1048,7 +1049,6 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_ROTATING: case VEHICLE_STATUS_ROTATING_0D: case VEHICLE_STATUS_OPERATING: - case VEHICLE_STATUS_SHOWING_FILM: case VEHICLE_STATUS_ROTATING_10: case VEHICLE_STATUS_OPERATING_11: case VEHICLE_STATUS_OPERATING_12: @@ -1060,7 +1060,9 @@ static void vehicle_update(rct_vehicle *vehicle) RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->sub_state << 8) | ride->mode, (int)vehicle, 0, 0); } break; - + case VEHICLE_STATUS_SHOWING_FILM: + vehicle_update_showing_film(vehicle); + break; case VEHICLE_STATUS_DOING_CIRCUS_SHOW: vehicle_update_doing_circus_show(vehicle); } @@ -1425,6 +1427,30 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle_invalidate_window(vehicle); } +/** +* +* rct2: 0x006D95AD +*/ +static void vehicle_update_showing_film(rct_vehicle *vehicle) +{ + int currentTime, totalTime; + + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + totalTime = RideFilmLength[vehicle->sub_state]; + currentTime = vehicle->var_4C + 1; + if (currentTime <= totalTime) { + vehicle->var_4C = currentTime; + } + else { + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; + } +} + /** * * rct2: 0x006D95F7 @@ -1459,7 +1485,8 @@ static void vehicle_update_sound(rct_vehicle *vehicle) // PROBLEMS rct_ride *ride; rct_ride_type *rideEntry; - uint8 bl, dl = 255; + // bl should be set before hand + uint8 bl = 255, dl = 255; uint8 screamId, screamVolume; uint16 soundIdVolume; @@ -1472,9 +1499,10 @@ static void vehicle_update_sound(rct_vehicle *vehicle) if (ecx >= 0) { dl = vehicleEntry->var_57; ecx >>= 15; - bl = 208 + (ecx & 0xFF); - if (bl < 0) + if (208 + (ecx & 0xFF) > 255) bl = 255; + else + bl = 208 + (ecx & 0xFF); } switch (vehicleEntry->sound_range) { From 2dcc4748ac8fbb430b72c9309d88005db8d8da44 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 19 Nov 2015 20:53:13 +0000 Subject: [PATCH 029/162] Implemented update_waiting_for_cable_lift --- src/ride/vehicle.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 75b0ad9aa9..975611bfcd 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -46,6 +46,7 @@ static void vehicle_update_showing_film(rct_vehicle *vehicle); static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); +static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -1053,13 +1054,15 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_OPERATING_11: case VEHICLE_STATUS_OPERATING_12: case VEHICLE_STATUS_OPERATING_13: - case VEHICLE_STATUS_WAITING_FOR_CABLE_LIFT: case VEHICLE_STATUS_TRAVELLING_15: { int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->sub_state << 8) | ride->mode, (int)vehicle, 0, 0); } break; + case VEHICLE_STATUS_WAITING_FOR_CABLE_LIFT: + vehicle_update_waiting_for_cable_lift(vehicle); + break; case VEHICLE_STATUS_SHOWING_FILM: vehicle_update_showing_film(vehicle); break; @@ -1427,6 +1430,23 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle_invalidate_window(vehicle); } +/** +* +* rct2: 0x006D9CE9 +*/ +static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle) +{ + rct_ride* ride = GET_RIDE(vehicle->ride); + + rct_vehicle* cableLift = GET_VEHICLE(ride->cable_lift); + + if (cableLift->status != VEHICLE_STATUS_WAITING_FOR_PASSENGERS) + return; + + cableLift->status = VEHICLE_STATUS_WAITING_TO_DEPART; + cableLift->var_C0 = vehicle->sprite_index; +} + /** * * rct2: 0x006D95AD From 98ef642463c6d2b0675bd7674932ffb9f33eb5aa Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 20 Nov 2015 00:04:07 +0000 Subject: [PATCH 030/162] Implemented vehicle_update_crash. Note crash on water not implemented yet --- src/ride/vehicle.c | 177 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 975611bfcd..dd27dc637e 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -19,6 +19,7 @@ *****************************************************************************/ #include "../addresses.h" +#include "../game.h" #include "../audio/audio.h" #include "../audio/mixer.h" #include "../config.h" @@ -47,6 +48,7 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); +static void vehicle_update_crash(rct_vehicle *vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -1036,6 +1038,10 @@ static void vehicle_update(rct_vehicle *vehicle) break; case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: vehicle_update_waiting_for_passengers(vehicle); + break; + case VEHICLE_STATUS_CRASHING: + case VEHICLE_STATUS_CRASHED: + vehicle_update_crash(vehicle); break; case VEHICLE_STATUS_WAITING_TO_DEPART: case VEHICLE_STATUS_DEPARTING: @@ -1043,8 +1049,7 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: - case VEHICLE_STATUS_CRASHING: - case VEHICLE_STATUS_CRASHED: + case VEHICLE_STATUS_TRAVELLING_0A: case VEHICLE_STATUS_SWINGING: case VEHICLE_STATUS_ROTATING: @@ -1494,6 +1499,174 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) } } +/* rct2: 0x0068B8BD + * returns the map element that the vehicle will collide with + * returns NULL if no collisions. + */ +static rct_map_element* vehicle_check_collision(sint16 x, sint16 y, sint16 z) { + rct_map_element* mapElement = map_get_first_element_at(x / 32, y / 32); + + uint8 bl; + if ((x & 0x1F) >= 16) { + bl = 1; + if ((y & 0x1F) < 16) + bl = 2; + } + else { + bl = 4; + if ((y & 0x1F) >= 16) + bl = 8; + } + + do { + if (z / 8 < mapElement->base_height) + continue; + + if (z / 8 >= mapElement->clearance_height) + continue; + + if (mapElement->flags & bl) + return mapElement; + } while (!map_element_is_last_for_tile(mapElement++)); + + return NULL; +} + +static void vehicle_crash_on_land(rct_vehicle* vehicle) { + vehicle->status = VEHICLE_STATUS_CRASHED; + vehicle_invalidate_window(vehicle); + + rct_ride* ride = GET_RIDE(vehicle->ride); + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED)) { + + rct_vehicle* frontVehicle = vehicle; + while (frontVehicle->is_child != 0)frontVehicle = GET_VEHICLE(frontVehicle->prev_vehicle_on_ride); + + uint8 trainIndex = 0; + while (ride->vehicles[trainIndex] != frontVehicle->sprite_index) + trainIndex++; + + ride_crash(vehicle->ride, trainIndex); + + if (ride->status != RIDE_STATUS_CLOSED) { + ride_set_status(vehicle->ride, RIDE_STATUS_CLOSED); + } + } + ride->lifecycle_flags |= RIDE_LIFECYCLE_CRASHED; + ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; + + if (vehicle->is_child == 0) { + RCT2_CALLPROC_X(0x006DE6C6, 0, 0, 0, 0, (int)vehicle, 0, 0); + } + + vehicle->sub_state = 2; + audio_play_sound_at_location(SOUND_CRASH, vehicle->x, vehicle->y, vehicle->z); + + sprite_misc_3_create(vehicle->x, vehicle->y, vehicle->z); + sprite_misc_5_create(vehicle->x, vehicle->y, vehicle->z); + + uint8 numParticles = min(vehicle->sprite_width, 7); + + while (numParticles-- != 0) + crashed_vehicle_particle_create(vehicle->colours, vehicle->x, vehicle->y, vehicle->z); + + vehicle->var_0C |= (1 << 7); + vehicle->var_C5 = 0; + vehicle->var_C8 = 0; + vehicle->sprite_width = 13; + vehicle->sprite_height_negative = 45; + vehicle->sprite_height_positive = 5; + + sprite_move(vehicle->x, vehicle->y, vehicle->z, (rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); + + vehicle->var_4E = 0; +} + +/** +* +* rct2: 0x006D98CA +*/ +static void vehicle_update_crash(rct_vehicle *vehicle){ + uint16 spriteId = vehicle->sprite_index; + rct_vehicle* curVehicle; + do { + curVehicle = GET_VEHICLE(spriteId); + if (curVehicle->sub_state > 1) { + if (curVehicle->var_4E <= 96) { + curVehicle->var_4E++; + if ((scenario_rand() & 0xFFFF) <= 0x1555) { + sprite_misc_3_create( + curVehicle->x + (scenario_rand() & 2 - 1), + curVehicle->y + (scenario_rand() & 2 - 1), + curVehicle->z + ); + } + } + if (curVehicle->var_C8 + 7281 > 0xFFFF) { + curVehicle->var_C5++; + if (curVehicle->var_C5 >= 8) + curVehicle->var_C5 = 0; + invalidate_sprite_2((rct_sprite*)curVehicle); + } + curVehicle->var_C8 += 7281; + continue; + } + + rct_map_element* collideElement = vehicle_check_collision(curVehicle->x, curVehicle->y, curVehicle->z); + if (collideElement == NULL) { + curVehicle->sub_state = 1; + } + else if (curVehicle->sub_state == 1){ + vehicle_crash_on_land(curVehicle); + continue; + } + + int z = map_element_height(curVehicle->x, curVehicle->y); + sint16 waterHeight = (z >> 16) & 0xFFFF; + z = (sint16)(z & 0xFFFF); + + if (waterHeight != 0) { + waterHeight -= curVehicle->z; + if (waterHeight <= 20) { + // 0x6D99C4 crash on water + } + } + + if (z + 20 > curVehicle->z || curVehicle->z < 16){ + vehicle_crash_on_land(curVehicle); + continue; + } + + invalidate_sprite_2((rct_sprite*)curVehicle); + + rct_xyz16 curPosition = { + .x = curVehicle->x, + .y = curVehicle->y, + .z = curVehicle->z + }; + + curPosition.x += (sint8)(curVehicle->var_B6 >> 8); + curPosition.y += (sint8)(curVehicle->var_C0 >> 8); + curPosition.z += (sint8)(curVehicle->var_4E >> 8); + curVehicle->track_x += (sint16)(curVehicle->var_B6 << 8); + curVehicle->track_y += (sint16)(curVehicle->var_B6 << 8); + curVehicle->track_z += (sint16)(curVehicle->var_B6 << 8); + + if (curPosition.x > 0x1FFF || + curPosition.y > 0x1FFF) { + vehicle_crash_on_land(curVehicle); + continue; + } + + sprite_move(curPosition.x, curPosition.y, curPosition.z, (rct_sprite*)curVehicle); + invalidate_sprite_2((rct_sprite*)curVehicle); + + if (curVehicle->sub_state == 1) { + curVehicle->var_4E += 0xFFEC; + } + } while ((spriteId = curVehicle->next_vehicle_on_train) != 0xFFFF); +} /** * * rct2: 0x006D7888 From 1df0359859a9d6621700152e9f8b56b3a2e156bc Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 20 Nov 2015 18:15:15 +0000 Subject: [PATCH 031/162] Implement vehicle_kill_all_passengers. Fix some small bugs in the crash code --- src/peep/peep.h | 2 +- src/ride/vehicle.c | 68 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/peep/peep.h b/src/peep/peep.h index c758f335b7..3ccd25f3f8 100644 --- a/src/peep/peep.h +++ b/src/peep/peep.h @@ -408,7 +408,7 @@ typedef struct { uint16 next_y; // 0x26 uint8 next_z; // 0x28 uint8 next_var_29; // 0x29 - uint8 outside_of_park; + uint8 outside_of_park; // 0x2A uint8 state; // 0x2B uint8 sub_state; // 0x2C uint8 sprite_type; // 0x2D diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index dd27dc637e..cfc732f6ed 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1532,6 +1532,64 @@ static rct_map_element* vehicle_check_collision(sint16 x, sint16 y, sint16 z) { return NULL; } +/* rct2: 0x006DE6C6 */ +static void vehicle_kill_all_passengers(rct_vehicle* vehicle) { + uint16 numFatalities = 0; + for (rct_vehicle* curVehicle = vehicle; + curVehicle->next_vehicle_on_train != 0xFFFF; + curVehicle = GET_VEHICLE(curVehicle->next_vehicle_on_train)) { + numFatalities += curVehicle->num_peeps; + } + + rct_ride* ride = GET_RIDE(vehicle->ride); + RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = numFatalities; + + uint8 crashType = numFatalities == 0 ? + RIDE_CRASH_TYPE_NO_FATALITIES : + RIDE_CRASH_TYPE_FATALITIES; + + if (crashType >= ride->last_crash_type) + ride->last_crash_type = crashType; + + if (numFatalities != 0) { + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_SIX_FLAGS_DEPRECATED)) { + RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 2, uint16) = ride->name; + RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS + 4, uint32) = ride->name_arguments; + + news_item_add_to_queue(NEWS_ITEM_RIDE, 2219, vehicle->ride); + } + + if (RCT2_GLOBAL(0x135882E, uint16) < 500) { + RCT2_GLOBAL(0x135882E, uint16) += 200; + } + } + + for (rct_vehicle* curVehicle = vehicle; + curVehicle->next_vehicle_on_train != 0xFFFF; + curVehicle = GET_VEHICLE(curVehicle->next_vehicle_on_train)) { + + if (curVehicle->num_peeps != curVehicle->next_free_seat) + continue; + + if (curVehicle->num_peeps == 0) + continue; + + for (uint8 i = 0; i < curVehicle->num_peeps; i++) { + rct_peep* peep = GET_PEEP(curVehicle->peep[i]); + if (peep->outside_of_park == 0) { + RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16)--; + RCT2_GLOBAL(RCT2_ADDRESS_BTM_TOOLBAR_DIRTY_FLAGS, uint16) |= + BTM_TB_DIRTY_FLAG_PEEP_COUNT; + } + ride->num_riders--; + peep_sprite_remove(peep); + } + + curVehicle->num_peeps = 0; + curVehicle->next_free_seat = 0; + } +} + static void vehicle_crash_on_land(rct_vehicle* vehicle) { vehicle->status = VEHICLE_STATUS_CRASHED; vehicle_invalidate_window(vehicle); @@ -1556,7 +1614,7 @@ static void vehicle_crash_on_land(rct_vehicle* vehicle) { ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; if (vehicle->is_child == 0) { - RCT2_CALLPROC_X(0x006DE6C6, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_kill_all_passengers(vehicle); } vehicle->sub_state = 2; @@ -1632,8 +1690,8 @@ static void vehicle_update_crash(rct_vehicle *vehicle){ // 0x6D99C4 crash on water } } - - if (z + 20 > curVehicle->z || curVehicle->z < 16){ + sint16 zDiff = curVehicle->z - z; + if ((zDiff <= 0 && zDiff >= -20) || curVehicle->z < 16){ vehicle_crash_on_land(curVehicle); continue; } @@ -1650,8 +1708,8 @@ static void vehicle_update_crash(rct_vehicle *vehicle){ curPosition.y += (sint8)(curVehicle->var_C0 >> 8); curPosition.z += (sint8)(curVehicle->var_4E >> 8); curVehicle->track_x += (sint16)(curVehicle->var_B6 << 8); - curVehicle->track_y += (sint16)(curVehicle->var_B6 << 8); - curVehicle->track_z += (sint16)(curVehicle->var_B6 << 8); + curVehicle->track_y += (sint16)(curVehicle->var_C0 << 8); + curVehicle->track_z += (sint16)(curVehicle->var_4E << 8); if (curPosition.x > 0x1FFF || curPosition.y > 0x1FFF) { From ec5121b3f60cdd93140475ad495d566f643b16b3 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 20 Nov 2015 19:23:25 +0000 Subject: [PATCH 032/162] Implement vehicle crash on water. Fix small particle issues Requires a change in rand() implementation. --- src/ride/vehicle.c | 64 ++++++++++++++++++++++++++++++++++++++++---- src/world/particle.c | 6 ++--- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index cfc732f6ed..e7bfad5ac9 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1641,6 +1641,58 @@ static void vehicle_crash_on_land(rct_vehicle* vehicle) { vehicle->var_4E = 0; } +static void vehicle_crash_on_water(rct_vehicle* vehicle) { + vehicle->status = VEHICLE_STATUS_CRASHED; + vehicle_invalidate_window(vehicle); + + rct_ride* ride = GET_RIDE(vehicle->ride); + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED)) { + + rct_vehicle* frontVehicle = vehicle; + while (frontVehicle->is_child != 0)frontVehicle = GET_VEHICLE(frontVehicle->prev_vehicle_on_ride); + + uint8 trainIndex = 0; + while (ride->vehicles[trainIndex] != frontVehicle->sprite_index) + trainIndex++; + + ride_crash(vehicle->ride, trainIndex); + + if (ride->status != RIDE_STATUS_CLOSED) { + ride_set_status(vehicle->ride, RIDE_STATUS_CLOSED); + } + } + ride->lifecycle_flags |= RIDE_LIFECYCLE_CRASHED; + ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; + + if (vehicle->is_child == 0) { + vehicle_kill_all_passengers(vehicle); + } + + vehicle->sub_state = 2; + audio_play_sound_at_location(SOUND_WATER_1, vehicle->x, vehicle->y, vehicle->z); + + crash_splash_create(vehicle->x, vehicle->y, vehicle->z); + crash_splash_create(vehicle->x - 8, vehicle->y - 9, vehicle->z); + crash_splash_create(vehicle->x + 11, vehicle->y - 9, vehicle->z); + crash_splash_create(vehicle->x + 11, vehicle->y + 8, vehicle->z); + crash_splash_create(vehicle->x - 4, vehicle->y + 8, vehicle->z); + + for (int i = 0; i < 10; ++i) + crashed_vehicle_particle_create(vehicle->colours, vehicle->x - 4, vehicle->y + 8, vehicle->z); + + vehicle->var_0C |= (1 << 7); + vehicle->var_C5 = 0; + vehicle->var_C8 = 0; + vehicle->sprite_width = 13; + vehicle->sprite_height_negative = 45; + vehicle->sprite_height_positive = 5; + + sprite_move(vehicle->x, vehicle->y, vehicle->z, (rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); + + vehicle->var_4E = 0xFFFF; +} + /** * * rct2: 0x006D98CA @@ -1683,14 +1735,16 @@ static void vehicle_update_crash(rct_vehicle *vehicle){ int z = map_element_height(curVehicle->x, curVehicle->y); sint16 waterHeight = (z >> 16) & 0xFFFF; z = (sint16)(z & 0xFFFF); - + sint16 zDiff; if (waterHeight != 0) { - waterHeight -= curVehicle->z; - if (waterHeight <= 20) { - // 0x6D99C4 crash on water + zDiff = curVehicle->z - waterHeight; + if (zDiff <= 0 && zDiff >= -20) { + vehicle_crash_on_water(curVehicle); + continue; } } - sint16 zDiff = curVehicle->z - z; + + zDiff = curVehicle->z - z; if ((zDiff <= 0 && zDiff >= -20) || curVehicle->z < 16){ vehicle_crash_on_land(curVehicle); continue; diff --git a/src/world/particle.c b/src/world/particle.c index ecec4ff98d..faa2f9125c 100644 --- a/src/world/particle.c +++ b/src/world/particle.c @@ -16,14 +16,14 @@ void crashed_vehicle_particle_create(rct_vehicle_colour colours, int x, int y, i sprite->sprite_height_negative = 8; sprite->sprite_height_positive = 8; sprite->sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite_move(x, y, z + 4, (rct_sprite*)sprite); + sprite_move(x, y, z, (rct_sprite*)sprite); sprite->misc_identifier = SPRITE_MISC_CRASHED_VEHICLE_PARTICLE; sprite->var_26 = (util_rand() & 0xFF) * 12; sprite->var_24 = (util_rand() & 0x7F) + 140; sprite->var_2E = ((util_rand() & 0xFF) * 5) >> 8; - sprite->acceleration_x = (util_rand() & 0xFFFF) * 4; - sprite->acceleration_y = (util_rand() & 0xFFFF) * 4; + sprite->acceleration_x = ((sint16)(util_rand() & 0xFFFF)) * 4; + sprite->acceleration_y = ((sint16)(util_rand() & 0xFFFF)) * 4; sprite->acceleration_z = (util_rand() & 0xFFFF) * 4 + 0x10000; sprite->velocity_x = 0; sprite->velocity_y = 0; From e59305d1d12b9c4a7d4472b39b1f63d33bb2aec1 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 20 Nov 2015 23:41:50 +0000 Subject: [PATCH 033/162] Implement waiting to depart. Not finished will not work at present --- src/ride/vehicle.c | 239 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 230 insertions(+), 9 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index e7bfad5ac9..79c9517a06 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -47,6 +47,7 @@ static void vehicle_update_showing_film(rct_vehicle *vehicle); static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); +static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); @@ -1039,17 +1040,19 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: vehicle_update_waiting_for_passengers(vehicle); break; + case VEHICLE_STATUS_WAITING_TO_DEPART: + vehicle_update_waiting_to_depart(vehicle); + break; case VEHICLE_STATUS_CRASHING: case VEHICLE_STATUS_CRASHED: vehicle_update_crash(vehicle); break; - case VEHICLE_STATUS_WAITING_TO_DEPART: + case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: - case VEHICLE_STATUS_TRAVELLING_0A: case VEHICLE_STATUS_SWINGING: case VEHICLE_STATUS_ROTATING: @@ -1435,6 +1438,223 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle_invalidate_window(vehicle); } +/* rct2: 0x006D808BE */ +static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + bool shouldBreak = false; + if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) { + switch (ride->breakdown_reason_pending) { + case BREAKDOWN_RESTRAINTS_STUCK_CLOSED: + case BREAKDOWN_RESTRAINTS_STUCK_OPEN: + case BREAKDOWN_DOORS_STUCK_CLOSED: + case BREAKDOWN_DOORS_STUCK_OPEN: + break; + default: + shouldBreak = true; + break; + } + } + + bool skipCheck = false; + if (shouldBreak != false || ride->status != RIDE_STATUS_OPEN) { + if (ride->mode == RIDE_MODE_FORWARD_ROTATION || + ride->mode == RIDE_MODE_BACKWARD_ROTATION) { + uint8 bl = ((-vehicle->var_1F) >> 3) & 0xF; + if (vehicle->peep[bl] == 0xFFFF) { + if (vehicle->num_peeps == 0) { + skipCheck = true; + } + } + else { + if (ride->exits[vehicle->current_station] != 0xFFFF) { + vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + return; + } + } + } + else { + uint16 spriteId = vehicle->sprite_index; + for (rct_vehicle* curVehicle; spriteId != 0xFFFF; spriteId = curVehicle->next_vehicle_on_train) { + curVehicle = GET_VEHICLE(spriteId); + + if (curVehicle->num_peeps != 0) { + if (ride->exits[vehicle->current_station] != 0xFFFF) { + vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + return; + } + break; + } + } + } + } + + if (skipCheck == false) { + if (!(ride->station_depart[vehicle->current_station] & STATION_DEPART_FLAG)) + return; + } + + if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] + & RIDE_TYPE_FLAG_CAN_SYNCHRONISE_ADJACENT_STATIONS) { + if (ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS) { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT) { + if (RCT2_CALLPROC_X(0x006DE287, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100) + return; + } + } + } + + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 0; + + if (ride->lifecycle_flags & RIDE_LIFECYCLE_CABLE_LIFT) { + RCT2_GLOBAL(0x00F441D2, uint8) = vehicle->ride; + rct_xy_element track; + int z; + int direction; + + if (track_block_get_next_from_zero( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z, + vehicle->ride, + vehicle->track_direction, + &track, + &z, + &direction)) { + + if (track_element_is_cable_lift(track.element)) { + vehicle->status = VEHICLE_STATUS_WAITING_FOR_CABLE_LIFT; + } + } + } + + switch (ride->mode) { + case RIDE_MODE_BUMPERCAR: + vehicle->status = VEHICLE_STATUS_TRAVELLING_0A; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + vehicle->var_CE = 0; + //6d91bf + break; + case RIDE_MODE_SWING: + vehicle->status = VEHICLE_STATUS_SWINGING; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + vehicle->var_CE = 0; + vehicle->var_4C = 0xFFFF; + //6d9249 + break; + case RIDE_MODE_ROTATION: + vehicle->status = VEHICLE_STATUS_ROTATING; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + vehicle->var_CE = 0; + vehicle->var_4C = 0xFFFF; + //6d92ff + break; + case RIDE_MODE_FILM_AVENGING_AVIATORS: + case RIDE_MODE_FILM_THRILL_RIDERS: + vehicle->status = VEHICLE_STATUS_OPERATING; + vehicle->sub_state = 0; + if (ride->mode == RIDE_MODE_FILM_THRILL_RIDERS) + vehicle->sub_state = 1; + vehicle_invalidate_window(vehicle); + vehicle->var_4C = 0xFFFF; + //6d94f2 + break; + case RIDE_MODE_BEGINNERS: + case RIDE_MODE_INTENSE: + case RIDE_MODE_BERSERK: + vehicle->status = VEHICLE_STATUS_OPERATING_11; + vehicle_invalidate_window(vehicle); + + switch (ride->mode) { + case RIDE_MODE_BEGINNERS: + vehicle->sub_state = 0; + break; + case RIDE_MODE_INTENSE: + vehicle->sub_state = 1; + break; + case RIDE_MODE_BERSERK: + vehicle->sub_state = 2; + break; + } + vehicle->var_4C = 0xFFFF; + vehicle->var_1F = 0; + vehicle->var_20 = 0; + //6d9547 + break; + case RIDE_MODE_FORWARD_ROTATION: + case RIDE_MODE_BACKWARD_ROTATION: + vehicle->status = VEHICLE_STATUS_ROTATING_0D; + vehicle->sub_state = vehicle->var_1F; + vehicle_invalidate_window(vehicle); + vehicle->var_CE = 0; + vehicle->var_4C = 0x808; + //6d9413 + break; + case RIDE_MODE_3D_FILM_MOUSE_TAILS: + case RIDE_MODE_3D_FILM_STORM_CHASERS: + case RIDE_MODE_3D_FILM_SPACE_RAIDERS: + vehicle->status = VEHICLE_STATUS_SHOWING_FILM; + vehicle_invalidate_window(vehicle); + switch (ride->mode) { + case RIDE_MODE_3D_FILM_MOUSE_TAILS: + vehicle->sub_state = 0; + break; + case RIDE_MODE_3D_FILM_STORM_CHASERS: + vehicle->sub_state = 1; + break; + case RIDE_MODE_3D_FILM_SPACE_RAIDERS: + vehicle->sub_state = 2; + break; + } + vehicle->var_4C = 0xFFFF; + //6d95ad + break; + case RIDE_MODE_CIRCUS_SHOW: + vehicle->status = VEHICLE_STATUS_DOING_CIRCUS_SHOW; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + vehicle->var_4C = 0xFFFF; + //6d95f7 + break; + case RIDE_MODE_SPACE_RINGS: + vehicle->status = VEHICLE_STATUS_ROTATING_10; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + vehicle->var_1F = 0; + vehicle->var_4C = 0xFFFF; + //6d97cb + break; + case RIDE_MODE_HAUNTED_HOUSE: + vehicle->status = VEHICLE_STATUS_OPERATING_12; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + vehicle->var_1F = 0; + vehicle->var_4C = 0xFFFF; + //6d9641 + break; + case RIDE_MODE_CROOKED_HOUSE: + vehicle->status = VEHICLE_STATUS_OPERATING_13; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + vehicle->var_1F = 0; + vehicle->var_4C = 0xFFFF; + //6d9781 + break; + default: + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + vehicle->var_CE = 0; + break; + } +} + /** * * rct2: 0x006D9CE9 @@ -1535,9 +1755,10 @@ static rct_map_element* vehicle_check_collision(sint16 x, sint16 y, sint16 z) { /* rct2: 0x006DE6C6 */ static void vehicle_kill_all_passengers(rct_vehicle* vehicle) { uint16 numFatalities = 0; - for (rct_vehicle* curVehicle = vehicle; - curVehicle->next_vehicle_on_train != 0xFFFF; - curVehicle = GET_VEHICLE(curVehicle->next_vehicle_on_train)) { + + uint16 spriteId = vehicle->sprite_index; + for (rct_vehicle* curVehicle; spriteId != 0xFFFF; spriteId = curVehicle->next_vehicle_on_train) { + curVehicle = GET_VEHICLE(spriteId); numFatalities += curVehicle->num_peeps; } @@ -1564,10 +1785,10 @@ static void vehicle_kill_all_passengers(rct_vehicle* vehicle) { } } - for (rct_vehicle* curVehicle = vehicle; - curVehicle->next_vehicle_on_train != 0xFFFF; - curVehicle = GET_VEHICLE(curVehicle->next_vehicle_on_train)) { - + spriteId = vehicle->sprite_index; + for (rct_vehicle* curVehicle; spriteId != 0xFFFF; spriteId = curVehicle->next_vehicle_on_train) { + curVehicle = GET_VEHICLE(spriteId); + if (curVehicle->num_peeps != curVehicle->next_free_seat) continue; From e254d9f14a3aa31de4e9cf6309d6ed1aebf6e2fe Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 21 Nov 2015 10:46:24 +0000 Subject: [PATCH 034/162] Implement bumpercars update. Named known vehicle states --- src/ride/vehicle.c | 76 +++++++++++++++++++++++++++++++++------------- src/ride/vehicle.h | 14 ++++----- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 79c9517a06..f20ec8fda9 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -48,6 +48,7 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); +static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle); static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); @@ -1047,21 +1048,22 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_CRASHED: vehicle_update_crash(vehicle); break; - + case VEHICLE_STATUS_TRAVELING_BUMPER_CARS: + vehicle_update_bumpcar_mode(vehicle); + break; case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: - case VEHICLE_STATUS_TRAVELLING_0A: case VEHICLE_STATUS_SWINGING: case VEHICLE_STATUS_ROTATING: - case VEHICLE_STATUS_ROTATING_0D: - case VEHICLE_STATUS_OPERATING: - case VEHICLE_STATUS_ROTATING_10: - case VEHICLE_STATUS_OPERATING_11: - case VEHICLE_STATUS_OPERATING_12: - case VEHICLE_STATUS_OPERATING_13: + case VEHICLE_STATUS_FERRIS_WHEEL_ROTATING: + case VEHICLE_STATUS_SIMULATOR_OPERATING: + case VEHICLE_STATUS_SPACE_RINGS_OPERATING: + case VEHICLE_STATUS_TOP_SPIN_OPERATING: + case VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING: + case VEHICLE_STATUS_CROOKED_HOUSE_OPERATING: case VEHICLE_STATUS_TRAVELLING_15: { int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); @@ -1438,6 +1440,36 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle_invalidate_window(vehicle); } +/* rct2: 0x006D91BF */ +static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry[vehicle->vehicle_type]; + + if (vehicleEntry->var_12 & (1 << 7) && vehicle->var_C5 != 1) { + vehicle->var_C5 = 1; + invalidate_sprite_2((rct_sprite*)vehicle); + } + + RCT2_CALLPROC_X(0x006DA44E, 0, 0, 0, 0, (int)vehicle, 0, 0); + + // Update the length of time vehicle has been in bumper mode + if (vehicle->sub_state++ == 0xFF) { + vehicle->var_CE++; + } + + if (ride->lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) + return; + + vehicle->var_C5 = 0; + invalidate_sprite_2((rct_sprite*)vehicle); + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); +} + /* rct2: 0x006D808BE */ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); @@ -1456,7 +1488,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { } bool skipCheck = false; - if (shouldBreak != false || ride->status != RIDE_STATUS_OPEN) { + if (shouldBreak == true || ride->status != RIDE_STATUS_OPEN) { if (ride->mode == RIDE_MODE_FORWARD_ROTATION || ride->mode == RIDE_MODE_BACKWARD_ROTATION) { uint8 bl = ((-vehicle->var_1F) >> 3) & 0xF; @@ -1521,7 +1553,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->track_y, vehicle->track_z, vehicle->ride, - vehicle->track_direction, + (uint8)(vehicle->track_direction & 0x3), &track, &z, &direction)) { @@ -1534,11 +1566,13 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { switch (ride->mode) { case RIDE_MODE_BUMPERCAR: - vehicle->status = VEHICLE_STATUS_TRAVELLING_0A; - vehicle->sub_state = 0; + vehicle->status = VEHICLE_STATUS_TRAVELING_BUMPER_CARS; vehicle_invalidate_window(vehicle); + // Bumper mode uses sub_state / var_CE to tell how long + // the vehicle has been ridden. + vehicle->sub_state = 0; vehicle->var_CE = 0; - //6d91bf + vehicle_update_bumpcar_mode(vehicle); break; case RIDE_MODE_SWING: vehicle->status = VEHICLE_STATUS_SWINGING; @@ -1558,7 +1592,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { break; case RIDE_MODE_FILM_AVENGING_AVIATORS: case RIDE_MODE_FILM_THRILL_RIDERS: - vehicle->status = VEHICLE_STATUS_OPERATING; + vehicle->status = VEHICLE_STATUS_SIMULATOR_OPERATING; vehicle->sub_state = 0; if (ride->mode == RIDE_MODE_FILM_THRILL_RIDERS) vehicle->sub_state = 1; @@ -1569,7 +1603,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { case RIDE_MODE_BEGINNERS: case RIDE_MODE_INTENSE: case RIDE_MODE_BERSERK: - vehicle->status = VEHICLE_STATUS_OPERATING_11; + vehicle->status = VEHICLE_STATUS_TOP_SPIN_OPERATING; vehicle_invalidate_window(vehicle); switch (ride->mode) { @@ -1590,7 +1624,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { break; case RIDE_MODE_FORWARD_ROTATION: case RIDE_MODE_BACKWARD_ROTATION: - vehicle->status = VEHICLE_STATUS_ROTATING_0D; + vehicle->status = VEHICLE_STATUS_FERRIS_WHEEL_ROTATING; vehicle->sub_state = vehicle->var_1F; vehicle_invalidate_window(vehicle); vehicle->var_CE = 0; @@ -1614,17 +1648,17 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { break; } vehicle->var_4C = 0xFFFF; - //6d95ad + vehicle_update_showing_film(vehicle); break; case RIDE_MODE_CIRCUS_SHOW: vehicle->status = VEHICLE_STATUS_DOING_CIRCUS_SHOW; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_4C = 0xFFFF; - //6d95f7 + vehicle_update_doing_circus_show(vehicle); break; case RIDE_MODE_SPACE_RINGS: - vehicle->status = VEHICLE_STATUS_ROTATING_10; + vehicle->status = VEHICLE_STATUS_SPACE_RINGS_OPERATING; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; @@ -1632,7 +1666,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { //6d97cb break; case RIDE_MODE_HAUNTED_HOUSE: - vehicle->status = VEHICLE_STATUS_OPERATING_12; + vehicle->status = VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; @@ -1640,7 +1674,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { //6d9641 break; case RIDE_MODE_CROOKED_HOUSE: - vehicle->status = VEHICLE_STATUS_OPERATING_13; + vehicle->status = VEHICLE_STATUS_CROOKED_HOUSE_OPERATING; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 206f40743b..bb517e9591 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -192,17 +192,17 @@ enum { VEHICLE_STATUS_TRAVELLING_07, VEHICLE_STATUS_CRASHING, VEHICLE_STATUS_CRASHED, - VEHICLE_STATUS_TRAVELLING_0A, + VEHICLE_STATUS_TRAVELING_BUMPER_CARS, VEHICLE_STATUS_SWINGING, VEHICLE_STATUS_ROTATING, - VEHICLE_STATUS_ROTATING_0D, - VEHICLE_STATUS_OPERATING, + VEHICLE_STATUS_FERRIS_WHEEL_ROTATING, + VEHICLE_STATUS_SIMULATOR_OPERATING, VEHICLE_STATUS_SHOWING_FILM, - VEHICLE_STATUS_ROTATING_10, - VEHICLE_STATUS_OPERATING_11, - VEHICLE_STATUS_OPERATING_12, + VEHICLE_STATUS_SPACE_RINGS_OPERATING, + VEHICLE_STATUS_TOP_SPIN_OPERATING, + VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING, VEHICLE_STATUS_DOING_CIRCUS_SHOW, - VEHICLE_STATUS_OPERATING_13, + VEHICLE_STATUS_CROOKED_HOUSE_OPERATING, VEHICLE_STATUS_WAITING_FOR_CABLE_LIFT, VEHICLE_STATUS_TRAVELLING_15, VEHICLE_STATUS_STOPPING, From 70ef91c61eaf249195af589f182ccfe14568afd7 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 21 Nov 2015 11:35:02 +0000 Subject: [PATCH 035/162] Implement vehicle_update_swinging. --- src/ride/ride.h | 7 ++--- src/ride/vehicle.c | 67 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index 1187ad0389..9b753e7f72 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -399,7 +399,7 @@ enum { RIDE_ENTRY_FLAG_NO_INVERSIONS = 1 << 1, // 0x2 RIDE_ENTRY_FLAG_NO_BANKED_TRACK = 1 << 2, // 0x4 RIDE_ENTRY_FLAG_3 = 1 << 3, // 0x8 - RIDE_ENTRY_FLAG_4 = 1 << 4, // 0x10 + RIDE_ENTRY_FLAG_ALTERNATIVE_SWING_MODE_1 = 1 << 4, // 0x10 RIDE_ENTRY_FLAG_5 = 1 << 5, // 0x20 RIDE_ENTRY_FLAG_6 = 1 << 6, // 0x40 RIDE_ENTRY_FLAG_7 = 1 << 7, // 0x80 @@ -414,8 +414,9 @@ enum { RIDE_ENTRY_FLAG_16 = 1 << 16, // 0x10000 RIDE_ENTRY_DISABLE_FIRST_TWO_OPERATING_MODES = 1 << 17, // 0x20000 RIDE_ENTRY_FLAG_18 = 1 << 18, // 0x40000 - RIDE_ENTRY_FLAG_19 = 1 << 19, // 0x80000 - RIDE_ENTRY_FLAG_20 = 1 << 20, // 0x100000 + RIDE_ENTRY_FLAG_19 = 1 << 19, // 0x80000 + // Must be set with swing mode 1 as well. + RIDE_ENTRY_FLAG_ALTERNATIVE_SWING_MODE_2 = 1 << 20, // 0x100000 RIDE_ENTRY_FLAG_21 = 1 << 21, // 0x200000 RIDE_ENTRY_FLAG_22 = 1 << 22, // 0x400000 RIDE_ENTRY_FLAG_23 = 1 << 23, // 0x800000 diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index f20ec8fda9..a903c7a185 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -49,6 +49,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle); +static void vehicle_update_swinging(rct_vehicle* vehicle); static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); @@ -1050,13 +1051,16 @@ static void vehicle_update(rct_vehicle *vehicle) break; case VEHICLE_STATUS_TRAVELING_BUMPER_CARS: vehicle_update_bumpcar_mode(vehicle); + break; + case VEHICLE_STATUS_SWINGING: + vehicle_update_swinging(vehicle); break; case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: - case VEHICLE_STATUS_SWINGING: + case VEHICLE_STATUS_ROTATING: case VEHICLE_STATUS_FERRIS_WHEEL_ROTATING: case VEHICLE_STATUS_SIMULATOR_OPERATING: @@ -1580,7 +1584,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); vehicle->var_CE = 0; vehicle->var_4C = 0xFFFF; - //6d9249 + vehicle_update_swinging(vehicle); break; case RIDE_MODE_ROTATION: vehicle->status = VEHICLE_STATUS_ROTATING; @@ -1689,6 +1693,65 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { } } +/* rct2: 0x006D9249 */ +static void vehicle_update_swinging(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + + // SubState for this ride means swinging state + // 0 == first swing + // 3 == full swing + uint8 swingState = vehicle->sub_state; + if (rideEntry->flags & RIDE_ENTRY_FLAG_ALTERNATIVE_SWING_MODE_1) { + swingState += 4; + if (rideEntry->flags & RIDE_ENTRY_FLAG_ALTERNATIVE_SWING_MODE_2) + swingState += 4; + } + uint8* edi = RCT2_ADDRESS(0x0099F9D0, uint8*)[swingState]; + uint8 al = edi[(uint16)(vehicle->var_4C + 1)]; + + // 0x80 indicates that a complete swing has been + // completed and the next swing can start + if (al != 0x80) { + vehicle->var_4C++; + if (al == vehicle->var_1F) + return; + // Used to know which sprite to draw + vehicle->var_1F = al; + invalidate_sprite_2((rct_sprite*)vehicle); + return; + } + + vehicle->var_4C = 0xFFFF; + vehicle->var_CE++; + if (ride->status != RIDE_STATUS_CLOSED) { + // It takes 3 swings to get into full swing + // ride->rotations already takes this into account + if (vehicle->var_CE + 3 < ride->rotations) { + // Go to the next swing state until we + // are at full swing. + if (vehicle->sub_state != 3) { + vehicle->sub_state++; + } + vehicle_update_swinging(vehicle); + return; + } + } + + // To get to this part of the code the + // swing has to be in slowing down phase + if (vehicle->sub_state == 0) { + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; + return; + } + // Go towards first swing state + vehicle->sub_state--; + vehicle_update_swinging(vehicle); +} + /** * * rct2: 0x006D9CE9 From d4827d389f32462f7a77efe233ed0c3684585414 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 21 Nov 2015 12:13:10 +0000 Subject: [PATCH 036/162] Implemented update simulator operating --- src/ride/vehicle.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index a903c7a185..db3b249407 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -50,6 +50,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle); static void vehicle_update_swinging(rct_vehicle* vehicle); +static void vehicle_update_simulator_operating(rct_vehicle* vehicle); static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); @@ -1055,15 +1056,16 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_SWINGING: vehicle_update_swinging(vehicle); break; + case VEHICLE_STATUS_SIMULATOR_OPERATING: + vehicle_update_simulator_operating(vehicle); + break; case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: - case VEHICLE_STATUS_ROTATING: case VEHICLE_STATUS_FERRIS_WHEEL_ROTATING: - case VEHICLE_STATUS_SIMULATOR_OPERATING: case VEHICLE_STATUS_SPACE_RINGS_OPERATING: case VEHICLE_STATUS_TOP_SPIN_OPERATING: case VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING: @@ -1602,7 +1604,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = 1; vehicle_invalidate_window(vehicle); vehicle->var_4C = 0xFFFF; - //6d94f2 + vehicle_update_simulator_operating(vehicle); break; case RIDE_MODE_BEGINNERS: case RIDE_MODE_INTENSE: @@ -1752,6 +1754,29 @@ static void vehicle_update_swinging(rct_vehicle* vehicle) { vehicle_update_swinging(vehicle); } +/* rct2: 0x006D94F2 */ +static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + uint8* edi = RCT2_ADDRESS(0x009A042C, uint8*)[vehicle->sub_state]; + + uint8 al = edi[(uint16)(vehicle->var_4C + 1)]; + if (al != 0xFF) { + vehicle->var_4C++; + if (al == vehicle->var_1F) + return; + vehicle->var_1F = al; + invalidate_sprite_2((rct_vehicle*)vehicle); + return; + } + + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; +} + /** * * rct2: 0x006D9CE9 From 2661622dcebbeba5e7e2f890fd8b4de13a6a7c8a Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 21 Nov 2015 14:47:12 +0000 Subject: [PATCH 037/162] Fix some of the sound bugs. Note this has diverged needs attention --- src/audio/mixer.cpp | 1 + src/ride/vehicle.c | 35 +++++++++++++++++------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/audio/mixer.cpp b/src/audio/mixer.cpp index 1edda91bc7..293639dcd1 100644 --- a/src/audio/mixer.cpp +++ b/src/audio/mixer.cpp @@ -805,6 +805,7 @@ void* Mixer_Play_Effect(int id, int loop, int volume, float pan, double rate, in return 0; } if (id >= countof(gMixer.css1sources)) { + log_error("Tried to play an invalid sound id. %i", id); return 0; } gMixer.Lock(); diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index db3b249407..14b4511594 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1450,7 +1450,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); - rct_ride_type_vehicle* vehicleEntry = &rideEntry[vehicle->vehicle_type]; + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; if (vehicleEntry->var_12 & (1 << 7) && vehicle->var_C5 != 1) { vehicle->var_C5 = 1; @@ -1767,7 +1767,7 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { if (al == vehicle->var_1F) return; vehicle->var_1F = al; - invalidate_sprite_2((rct_vehicle*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); return; } @@ -2128,14 +2128,15 @@ static void vehicle_update_crash(rct_vehicle *vehicle){ */ static void vehicle_update_sound(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006D7888, 0, 0, 0, 0, (int)vehicle, 0, 0); return; + //RCT2_CALLPROC_X(0x006D7888, 0, 0, 0, 0, (int)vehicle, 0, 0); return; // PROBLEMS rct_ride *ride; rct_ride_type *rideEntry; // bl should be set before hand uint8 bl = 255, dl = 255; - uint8 screamId, screamVolume; + // bh screamVolume should be set before hand + uint8 screamId, screamVolume = 255; uint16 soundIdVolume; ride = GET_RIDE(vehicle->ride); @@ -2155,35 +2156,35 @@ static void vehicle_update_sound(rct_vehicle *vehicle) switch (vehicleEntry->sound_range) { case 3: - screamVolume = vehicle->scream_sound_id; + screamId = vehicle->scream_sound_id; if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x7F)) { if (vehicle->velocity < 0x40000 || vehicle->scream_sound_id != 255) goto loc_6D7A97; if ((scenario_rand() & 0xFFFF) <= 0x5555) { vehicle->scream_sound_id = SOUND_TRAIN_WHISTLE; - screamId = 255; + screamVolume = 255; break; } } - if (screamVolume != 254) screamVolume = 255; - screamId = 255; + if (screamId != 254) screamId = 255; + screamVolume = 255; break; case 4: - screamVolume = vehicle->scream_sound_id; + screamId = vehicle->scream_sound_id; if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x7F)) { if (vehicle->velocity < 0x40000 || vehicle->scream_sound_id != 255) goto loc_6D7A97; if ((scenario_rand() & 0xFFFF) <= 0x5555) { vehicle->scream_sound_id = SOUND_TRAM; - screamId = 255; + screamVolume = 255; break; } } - if (screamVolume != 254) screamVolume = 255; - screamId = 255; + if (screamId != 254) screamId = 255; + screamVolume = 255; break; default: @@ -2191,22 +2192,20 @@ static void vehicle_update_sound(rct_vehicle *vehicle) screamId = vehicle_update_scream_sound(vehicle); if (screamId == 255) goto loc_6D7A97; - - screamVolume = 255; break; } loc_6D7A97: vehicle->scream_sound_id = 255; - screamVolume = RCT2_GLOBAL(0x0097D7C8 + (ride->type * 4), uint8); - screamId = 243; + screamId = RCT2_GLOBAL(0x0097D7C8 + (ride->type * 4), uint8); + screamVolume = 243; if (!(vehicle->var_B8 & 2)) - screamVolume = 255; + screamId = 255; } // Friction sound - soundIdVolume = sub_6D7AC0(vehicle->sound1_id, vehicle->sound1_volume, bl, dl); + soundIdVolume = sub_6D7AC0(vehicle->sound1_id, vehicle->sound1_volume, dl, bl); vehicle->sound1_id = soundIdVolume & 0xFF; vehicle->sound1_volume = (soundIdVolume >> 8) & 0xFF; From 53fa41f2b1fdcf7098eae194ffe64419b224ac7f Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 21 Nov 2015 15:53:56 +0000 Subject: [PATCH 038/162] Implement ride lift data --- src/ride/ride.c | 2 +- src/ride/ride_data.c | 189 ++++++++++++++++++++-------------------- src/ride/ride_data.h | 8 +- src/ride/ride_ratings.c | 7 +- src/ride/vehicle.c | 4 +- src/windows/ride.c | 4 +- 6 files changed, 109 insertions(+), 105 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index 46839e1958..26cab45f68 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -5367,7 +5367,7 @@ foundRideEntry: RCT2_GLOBAL(0x0097CF40 + 5 + (ride->type * 8), uint8) ) / 4; - ride->lift_hill_speed = RCT2_ADDRESS(0x0097D7C9, uint8)[ride->type * 4]; + ride->lift_hill_speed = RideLiftData[ride->type].minimum_speed; ride->measurement_index = 255; ride->excitement = (ride_rating)-1; diff --git a/src/ride/ride_data.c b/src/ride/ride_data.c index c02f0202e6..8817466865 100644 --- a/src/ride/ride_data.c +++ b/src/ride/ride_data.c @@ -11,6 +11,7 @@ #include "../localisation/localisation.h" #include "ride.h" #include "ride_data.h" +#include "../audio/audio.h" const bool hasRunningTrack[0x60] = { true, // 0 Spiral Roller coaster @@ -889,100 +890,6 @@ const rct_ride_entrance_definition RideEntranceDefinitions[RIDE_ENTRANCE_STYLE_C { 0, 0, 2, STR_ENTRANCE_NONE, 0x00000000, 0, } // RIDE_ENTRANCE_STYLE_NONE }; -// Data read from 0x0097D7C9 4 bytes at a time -const uint8 RideLiftHillAdjustments[0x60] = { - 7, // Spiral Roller coaster - 4, // Stand Up Coaster - 4, // Suspended Swinging - 5, // Inverted - 4, // Steel Mini Coaster - 5, // Mini Railroad - 5, // Monorail - 4, // Mini Suspended Coaster - 5, // Boat Ride - 4, // Wooden Wild Mine/Mouse - 4, // Steeplechase/Motorbike/Soap Box Derby - 5, // Car Ride - 5, // Launched Freefall - 4, // Bobsleigh Coaster - 5, // Observation Tower - 4, // Looping Roller Coaster - 4, // Dinghy Slide - 4, // Mine Train Coaster - 5, // Chairlift - 4, // Corkscrew Roller Coaster - 5, // Maze - 5, // Spiral Slide - 5, // Go Karts - 5, // Log Flume - 5, // River Rapids - 5, // Bumper Cars - 5, // Pirate Ship - 5, // Swinging Inverter Ship - 5, // Food Stall - 5, // (none) - 5, // Drink Stall - 5, // (none) - 5, // Shop (all types) - 5, // Merry Go Round - 5, // Balloon Stall (maybe) - 5, // Information Kiosk - 5, // Bathroom - 5, // Ferris Wheel - 5, // Motion Simulator - 5, // 3D Cinema - 5, // Topspin - 5, // Space Rings - 5, // Reverse Freefall Coaster - 5, // Elevator - 4, // Vertical Drop Roller Coaster - 5, // ATM - 5, // Twist - 5, // Haunted House - 5, // First Aid - 5, // Circus Show - 5, // Ghost Train - 5, // Twister Roller Coaster - 5, // Wooden Roller Coaster - 3, // Side-Friction Roller Coaster - 4, // Wild Mouse - 4, // Multi Dimension Coaster - 4, // (none) - 4, // Flying Roller Coaster - 4, // (none) - 3, // Virginia Reel - 5, // Splash Boats - 5, // Mini Helicopters - 4, // Lay-down Roller Coaster - 5, // Suspended Monorail - 4, // (none) - 3, // Reverser Roller Coaster - 4, // Heartline Twister Roller Coaster - 5, // Mini Golf - 5, // Giga Coaster - 5, // Roto-Drop - 5, // Flying Saucers - 5, // Crooked House - 5, // Monorail Cycles - 4, // Compact Inverted Coaster - 4, // Water Coaster - 5, // Air Powered Vertical Coaster - 4, // Inverted Hairpin Coaster - 5, // Magic Carpet - 5, // Submarine Ride - 5, // River Rafts - 5, // (none) - 5, // Enterprise - 5, // (none) - 5, // (none) - 5, // (none) - 4, // (none) - 4, // Inverted Impulse Coaster - 4, // Mini Roller Coaster - 5, // Mine Ride - 4 // LIM Launched Roller Coaster -}; - // rct2: 0x0097D4F2 const rct_ride_data_4 RideData4[91] = { { RIDE_TYPE_FLAG4_ALLOW_MUSIC | RIDE_TYPE_FLAG4_PEEP_CHECK_GFORCES | RIDE_TYPE_FLAG4_HAS_ENTRANCE_EXIT | RIDE_TYPE_FLAG4_HAS_AIR_TIME | RIDE_TYPE_FLAG4_ALLOW_MULTIPLE_CIRCUITS | RIDE_TYPE_FLAG4_11 | RIDE_TYPE_FLAG4_13, MUSIC_STYLE_ROCK_STYLE_3, 0, 0, 0, 20, 20 }, // RIDE_TYPE_SPIRAL_ROLLER_COASTER @@ -1305,3 +1212,97 @@ const uint16 RideFilmLength[3] = { 6000, // STORM_CHASERS 7000 // SPACE_RAIDERS }; + +/* rct2: 0x0097D7C8, 0x0097D7C9, 0x0097D7CA */ +const rct_ride_lift_data RideLiftData[] = { + { SOUND_LIFT_3, 7, 7 }, // Spiral Roller coaster + { SOUND_LIFT_1, 4, 6 }, // Stand Up Coaster + { SOUND_LIFT_1, 4, 6 }, // Suspended Swinging + { SOUND_LIFT_7, 5, 7 }, // Inverted + { SOUND_LIFT_3, 4, 6 }, // Steel Mini Coaster + { 255, 5, 5 }, // Mini Railroad + { 255, 5, 5 }, // Monorail + { SOUND_LIFT_3, 4, 5 }, // Mini Suspended Coaster + { 255, 5, 5 }, // Boat Ride + { SOUND_LIFT_1, 4, 5 }, // Wooden Wild Mine/Mouse + { SOUND_LIFT_1, 4, 5 }, // Steeplechase/Motorbike/Soap Box D + { 255, 5, 5 }, // Car Ride + { 255, 5, 5 }, // Launched Freefall + { SOUND_LIFT_3, 4, 5 }, // Bobsleigh Coaster + { 255, 5, 5 }, // Observation Tower + { SOUND_LIFT_1, 4, 6 }, // Looping Roller Coaster + { SOUND_LIFT_3, 4, 5 }, // Dinghy Slide + { SOUND_LIFT_4, 4, 6 }, // Mine Train Coaster + { 255, 5, 5 }, // Chairlift + { SOUND_LIFT_4, 4, 6 }, // Corkscrew Roller Coaster + { 255, 5, 5 }, // Maze + { 255, 5, 5 }, // Spiral Slide + { 255, 5, 5 }, // Go Karts + { 255, 5, 5 }, // Log Flume + { 255, 5, 5 }, // River Rapids + { 255, 5, 5 }, // Bumper Cars + { 255, 5, 5 }, // Pirate Ship + { 255, 5, 5 }, // Swinging Inverter Ship + { 255, 5, 5 }, // Food Stall + { 255, 5, 5 }, // (none) + { 255, 5, 5 }, // Drink Stall + { 255, 5, 5 }, // (none) + { 255, 5, 5 }, // Shop (all types) + { 255, 5, 5 }, // Merry Go Round + { 255, 5, 5 }, // Balloon Stall (maybe) + { 255, 5, 5 }, // Information Kiosk + { 255, 5, 5 }, // Bathroom + { 255, 5, 5 }, // Ferris Wheel + { 255, 5, 5 }, // Motion Simulator + { 255, 5, 5 }, // 3D Cinema + { 255, 5, 5 }, // Topspin + { 255, 5, 5 }, // Space Rings + { 255, 5, 5 }, // Reverse Freefall Coaster + { 255, 5, 5 }, // Elevator + { SOUND_LIFT_7, 4, 5 }, // Vertical Drop Roller Coaster + { 255, 5, 5 }, // ATM + { 255, 5, 5 }, // Twist + { 255, 5, 5 }, // Haunted House + { 255, 5, 5 }, // First Aid + { 255, 5, 5 }, // Circus Show + { 255, 5, 5 }, // Ghost Train + { SOUND_LIFT_7, 5, 8 }, // Twister Roller Coaster + { SOUND_LIFT_5, 5, 7 }, // Wooden Roller Coaster + { SOUND_LIFT_5, 3, 4 }, // Side-Friction Roller Coaster + { SOUND_LIFT_6, 4, 6 }, // Wild Mouse + { SOUND_LIFT_3, 4, 6 }, // Multi Dimension Coaster + { SOUND_LIFT_3, 4, 6 }, // (none) + { SOUND_LIFT_7, 4, 6 }, // Flying Roller Coaster + { SOUND_LIFT_7, 4, 6 }, // (none) + { SOUND_LIFT_1, 3, 4 }, // Virginia Reel + { 255, 5, 5 }, // Splash Boats + { 255, 5, 5 }, // Mini Helicopters + { SOUND_LIFT_1, 4, 6 }, // Lay-down Roller Coaster + { 255, 5, 5 }, // Suspended Monorail + { SOUND_LIFT_1, 4, 6 }, // (none) + { SOUND_LIFT_1, 3, 4 }, // Reverser Roller Coaster + { SOUND_LIFT_1, 4, 6 }, // Heartline Twister Roller Coaster + { 255, 5, 5 }, // Mini Golf + { SOUND_LIFT_1, 5, 8 }, // Giga Coaster + { 255, 5, 5 }, // Roto-Drop + { 255, 5, 5 }, // Flying Saucers + { 255, 5, 5 }, // Crooked House + { 255, 5, 5 }, // Monorail Cycles + { SOUND_LIFT_3, 4, 6 }, // Compact Inverted Coaster + { SOUND_LIFT_1, 4, 6 }, // Water Coaster + { 255, 5, 5 }, // Air Powered Vertical Coaster + { SOUND_LIFT_6, 4, 6 }, // Inverted Hairpin Coaster + { 255, 5, 5 }, // Magic Carpet + { 255, 5, 5 }, // Submarine Ride + { 255, 5, 5 }, // River Rafts + { 255, 5, 5 }, // (none) + { 255, 5, 5 }, // Enterprise + { 255, 5, 5 }, // (none) + { 255, 5, 5 }, // (none) + { 255, 5, 5 }, // (none) + { SOUND_LIFT_4, 4, 7 }, // (none) + { SOUND_LIFT_1, 4, 7 }, // Inverted Impulse Coaster + { SOUND_LIFT_1, 4, 6 }, // Mini Roller Coaster + { 255, 5, 5 }, // Mine Ride + { SOUND_LIFT_6, 4, 6 } // LIM Launched Roller Coaster +}; \ No newline at end of file diff --git a/src/ride/ride_data.h b/src/ride/ride_data.h index 89c55c3b96..398b8ac127 100644 --- a/src/ride/ride_data.h +++ b/src/ride/ride_data.h @@ -54,6 +54,12 @@ typedef struct { uint8 pad[4]; } rct_ride_data_4; +typedef struct { + uint8 sound_id; + uint8 minimum_speed; + uint8 maximum_speed; +} rct_ride_lift_data; + enum { RIDE_TYPE_FLAG4_0 = (1 << 0), RIDE_TYPE_FLAG4_MUSIC_ON_DEFAULT = (1 << 1), @@ -87,7 +93,7 @@ extern const uint8 AllRideModesAvailable[]; extern const uint8 RideAvailableBreakdowns[]; extern const rct_ride_entrance_definition RideEntranceDefinitions[RIDE_ENTRANCE_STYLE_COUNT]; -extern const uint8 RideLiftHillAdjustments[0x60]; +extern const rct_ride_lift_data RideLiftData[90]; extern const rct_ride_data_4 RideData4[91]; diff --git a/src/ride/ride_ratings.c b/src/ride/ride_ratings.c index ebebef733b..07ea3d5c3a 100644 --- a/src/ride/ride_ratings.c +++ b/src/ride/ride_ratings.c @@ -843,11 +843,8 @@ static void ride_ratings_apply_intensity_penalty(rating_tuple *ratings) */ static void set_unreliability_factor(rct_ride *ride) { - // The higher the number, the lower the breakdown - // possibility. Range is [3, 7]. values are here: - // https://gist.github.com/kevinburke/123977c4884ccadbec70. Consider - // inlining this per ride - uint8 lift_speed_adjustment = RideLiftHillAdjustments[ride->type]; + // The bigger the difference in lift speed and minimum the higher the unreliability + uint8 lift_speed_adjustment = RideLiftData[ride->type].minimum_speed; ride->unreliability_factor += (ride->lift_hill_speed - lift_speed_adjustment) * 2; } diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 14b4511594..538250e078 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2197,13 +2197,13 @@ static void vehicle_update_sound(rct_vehicle *vehicle) loc_6D7A97: vehicle->scream_sound_id = 255; - screamId = RCT2_GLOBAL(0x0097D7C8 + (ride->type * 4), uint8); + // Get lift hill sound + screamId = RideLiftData[ride->type].sound_id; screamVolume = 243; if (!(vehicle->var_B8 & 2)) screamId = 255; } - // Friction sound soundIdVolume = sub_6D7AC0(vehicle->sound1_id, vehicle->sound1_volume, dl, bl); vehicle->sound1_id = soundIdVolume & 0xFF; diff --git a/src/windows/ride.c b/src/windows/ride.c index faac53d803..c234e75150 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -2937,12 +2937,12 @@ static void window_ride_operating_mousedown(int widgetIndex, rct_window *w, rct_ if(gConfigCheat.fast_lift_hill) max_lift_hill_speed = 255; else - max_lift_hill_speed = RCT2_GLOBAL(0x0097D7CA + (ride->type * 4), uint8); + max_lift_hill_speed = RideLiftData[ride->type].maximum_speed; set_operating_setting(w->number, 8, min(ride->lift_hill_speed + 1, max_lift_hill_speed)); break; case WIDX_LIFT_HILL_SPEED_DECREASE: - set_operating_setting(w->number, 8, max(RCT2_GLOBAL(0x0097D7C9 + (ride->type * 4), uint8), ride->lift_hill_speed - 1)); + set_operating_setting(w->number, 8, max(RideLiftData[ride->type].minimum_speed, ride->lift_hill_speed - 1)); break; case WIDX_MINIMUM_LENGTH_INCREASE: set_operating_setting(w->number, 2, min(ride->min_waiting_time + 1, 250)); From ae50ce54c67d8fd692a134813b6f3b172405b10d Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 21 Nov 2015 16:16:05 +0000 Subject: [PATCH 039/162] Implement vehicle update top spin --- src/ride/vehicle.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 538250e078..78c9c1596f 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -51,6 +51,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle); static void vehicle_update_swinging(rct_vehicle* vehicle); static void vehicle_update_simulator_operating(rct_vehicle* vehicle); +static void vehicle_update_top_spin_operating(rct_vehicle* vehicle); static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); @@ -1059,6 +1060,9 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_SIMULATOR_OPERATING: vehicle_update_simulator_operating(vehicle); break; + case VEHICLE_STATUS_TOP_SPIN_OPERATING: + vehicle_update_top_spin_operating(vehicle); + break; case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: @@ -1067,7 +1071,7 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_ROTATING: case VEHICLE_STATUS_FERRIS_WHEEL_ROTATING: case VEHICLE_STATUS_SPACE_RINGS_OPERATING: - case VEHICLE_STATUS_TOP_SPIN_OPERATING: + case VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING: case VEHICLE_STATUS_CROOKED_HOUSE_OPERATING: case VEHICLE_STATUS_TRAVELLING_15: @@ -1626,7 +1630,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->var_4C = 0xFFFF; vehicle->var_1F = 0; vehicle->var_20 = 0; - //6d9547 + vehicle_update_top_spin_operating(vehicle); break; case RIDE_MODE_FORWARD_ROTATION: case RIDE_MODE_BACKWARD_ROTATION: @@ -1777,6 +1781,34 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { vehicle->var_C0 = 0; } +/* rct2: 0x006D9547 */ +static void vehicle_update_top_spin_operating(rct_vehicle* vehicle) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + uint8* edi = RCT2_ADDRESS(0x009A12E0, uint8*)[vehicle->sub_state]; + + uint8 al = edi[((sint16)vehicle->var_4C + 1) * 2]; + if (al != 0xFF) { + vehicle->var_4C = (sint16)vehicle->var_4C + 1; + if (al != vehicle->var_1F) { + vehicle->var_1F = al; + invalidate_sprite_2((rct_sprite*)vehicle); + } + al = edi[vehicle->var_4C * 2 + 1]; + if (al != vehicle->var_20) { + vehicle->var_20 = al; + invalidate_sprite_2((rct_sprite*)vehicle); + } + return; + } + + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; +} + /** * * rct2: 0x006D9CE9 From e06ad99a932db371d52367f76379b4f739f4f579 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 25 Nov 2015 19:55:04 +0000 Subject: [PATCH 040/162] Implement vehicle ferris wheel rotating update --- src/ride/vehicle.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 78c9c1596f..3fefa0fdad 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -48,6 +48,7 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); +static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle); static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle); static void vehicle_update_swinging(rct_vehicle* vehicle); static void vehicle_update_simulator_operating(rct_vehicle* vehicle); @@ -1063,15 +1064,16 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_TOP_SPIN_OPERATING: vehicle_update_top_spin_operating(vehicle); break; + case VEHICLE_STATUS_FERRIS_WHEEL_ROTATING: + vehicle_update_ferris_wheel_rotating(vehicle); + break; case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: case VEHICLE_STATUS_ROTATING: - case VEHICLE_STATUS_FERRIS_WHEEL_ROTATING: case VEHICLE_STATUS_SPACE_RINGS_OPERATING: - case VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING: case VEHICLE_STATUS_CROOKED_HOUSE_OPERATING: case VEHICLE_STATUS_TRAVELLING_15: @@ -1639,7 +1641,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); vehicle->var_CE = 0; vehicle->var_4C = 0x808; - //6d9413 + vehicle_update_ferris_wheel_rotating(vehicle); break; case RIDE_MODE_3D_FILM_MOUSE_TAILS: case RIDE_MODE_3D_FILM_STORM_CHASERS: @@ -1758,6 +1760,84 @@ static void vehicle_update_swinging(rct_vehicle* vehicle) { vehicle_update_swinging(vehicle); } +/* rct2: 0x006D9413 */ +static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + rct_ride* ride = GET_RIDE(vehicle->ride); + if (((vehicle->var_4C -= 0x100) & 0xFF00) != 0) + return; + + sint8 var_4C = vehicle->var_4C & 0xFF; + + if (var_4C == 3) { + vehicle->var_4C = (0xFF & var_4C) | (0xFF00 & (var_4C << 8)); + } + else if (var_4C < 3) { + if (var_4C != -8) + var_4C--; + vehicle->var_4C = (0xFF & var_4C) | (0xFF00 & (-var_4C << 8)); + } + else { + var_4C--; + vehicle->var_4C = (0xFF & var_4C) | (0xFF00 & (var_4C << 8)); + } + + uint8 rotation = vehicle->var_1F; + if (ride->mode & RIDE_MODE_FORWARD_ROTATION) + rotation++; + else + rotation--; + + rotation &= 0x7F; + vehicle->var_1F = rotation; + + if (rotation == vehicle->sub_state) + vehicle->var_CE++; + + invalidate_sprite_2((rct_sprite*)vehicle); + + uint8 subState = vehicle->sub_state; + if (ride->mode & RIDE_MODE_FORWARD_ROTATION) + subState++; + else + subState--; + subState &= 0x7F; + + if (subState == vehicle->var_1F) { + bool shouldStop = true; + if (ride->status != RIDE_STATUS_CLOSED) { + if (vehicle->var_CE <= ride->rotations) + shouldStop = false; + } + + if (shouldStop) { + var_4C = vehicle->var_4C; + vehicle->var_4C &= 0xFF00; + vehicle->var_4C |= 0xFF & (-abs(var_4C)); + } + } + + if ((sint8)(vehicle->var_4C & 0xFF) != -8) + return; + + subState = vehicle->sub_state; + if (ride->mode & RIDE_MODE_FORWARD_ROTATION) + subState += 8; + else + subState -= 8; + subState &= 0x7F; + + if (subState != vehicle->var_1F) + return; + + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; +} + /* rct2: 0x006D94F2 */ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) From 093d49253f3470d4e80a60e12519a381013b4c4e Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 25 Nov 2015 20:26:15 +0000 Subject: [PATCH 041/162] Implemented vehicle update space rings and haunted house --- src/ride/vehicle.c | 106 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 5 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 3fefa0fdad..2122b78be5 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -49,6 +49,8 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle); +static void vehicle_update_space_rings_operating(rct_vehicle* vehicle); +static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle); static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle); static void vehicle_update_swinging(rct_vehicle* vehicle); static void vehicle_update_simulator_operating(rct_vehicle* vehicle); @@ -1067,14 +1069,18 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_FERRIS_WHEEL_ROTATING: vehicle_update_ferris_wheel_rotating(vehicle); break; + case VEHICLE_STATUS_SPACE_RINGS_OPERATING: + vehicle_update_space_rings_operating(vehicle); + break; + case VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING: + vehicle_update_haunted_house_operating(vehicle); + break; case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: case VEHICLE_STATUS_ROTATING: - case VEHICLE_STATUS_SPACE_RINGS_OPERATING: - case VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING: case VEHICLE_STATUS_CROOKED_HOUSE_OPERATING: case VEHICLE_STATUS_TRAVELLING_15: { @@ -1675,7 +1681,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; vehicle->var_4C = 0xFFFF; - //6d97cb + vehicle_update_space_rings_operating(vehicle); break; case RIDE_MODE_HAUNTED_HOUSE: vehicle->status = VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING; @@ -1683,7 +1689,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; vehicle->var_4C = 0xFFFF; - //6d9641 + vehicle_update_haunted_house_operating(vehicle); break; case RIDE_MODE_CROOKED_HOUSE: vehicle->status = VEHICLE_STATUS_CROOKED_HOUSE_OPERATING; @@ -1813,7 +1819,7 @@ static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle) { } if (shouldStop) { - var_4C = vehicle->var_4C; + var_4C = (sint8)(vehicle->var_4C & 0xFF); vehicle->var_4C &= 0xFF00; vehicle->var_4C |= 0xFF & (-abs(var_4C)); } @@ -1861,6 +1867,96 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { vehicle->var_C0 = 0; } +/* rct2: 0x006D97CB */ +static void vehicle_update_space_rings_operating(rct_vehicle* vehicle) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + uint8* edi = RCT2_ADDRESS(0x009A0ACC, uint8*)[vehicle->sub_state]; + + uint8 al = edi[(uint16)(vehicle->var_4C + 1)]; + if (al != 0xFF) { + vehicle->var_4C++; + if (al == vehicle->var_1F) + return; + vehicle->var_1F = al; + invalidate_sprite_2((rct_sprite*)vehicle); + return; + } + + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; +} + +/* rct2: 0x006D9641*/ +static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + if (vehicle->var_1F != 0) { + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 1) { + vehicle->var_1F++; + invalidate_sprite_2((rct_sprite*)vehicle); + + if (vehicle->var_1F == 19) + vehicle->var_1F = 0; + } + } + + uint16* edi = RCT2_ADDRESS(0x009A0ABC, uint16*)[vehicle->sub_state]; + + uint16 ax = *edi; + if ((uint16)(vehicle->var_4C + 1) > ax) { + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; + return; + } + + vehicle->var_4C++; + switch (vehicle->var_4C) { + case 45: + audio_play_sound_at_location( + SOUND_HAUNTED_HOUSE_SCARE, + vehicle->x, + vehicle->y, + vehicle->z); + break; + case 75: + vehicle->var_1F = 1; + invalidate_sprite_2((rct_sprite*)vehicle); + break; + case 400: + audio_play_sound_at_location( + SOUND_HAUNTED_HOUSE_SCREAM_1, + vehicle->x, + vehicle->y, + vehicle->z); + break; + case 745: + audio_play_sound_at_location( + SOUND_HAUNTED_HOUSE_SCARE, + vehicle->x, + vehicle->y, + vehicle->z); + break; + case 775: + vehicle->var_1F = 1; + invalidate_sprite_2((rct_sprite*)vehicle); + break; + case 1100: + audio_play_sound_at_location( + SOUND_HAUNTED_HOUSE_SCREAM_2, + vehicle->x, + vehicle->y, + vehicle->z); + break; + } +} + /* rct2: 0x006D9547 */ static void vehicle_update_top_spin_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) From 688bd521b90c89c0bff989ef54c2a666382e8c37 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 25 Nov 2015 20:39:59 +0000 Subject: [PATCH 042/162] Implement vehicle update crooked house --- src/ride/ride_data.c | 5 +++++ src/ride/ride_data.h | 1 + src/ride/vehicle.c | 23 +++++++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/ride/ride_data.c b/src/ride/ride_data.c index 8817466865..f70d6a66c2 100644 --- a/src/ride/ride_data.c +++ b/src/ride/ride_data.c @@ -1213,6 +1213,11 @@ const uint16 RideFilmLength[3] = { 7000 // SPACE_RAIDERS }; +/* rct2: 0x009A0AC4 */ +const uint16 RideCrookedHouseLength[1] = { + 600 +}; + /* rct2: 0x0097D7C8, 0x0097D7C9, 0x0097D7CA */ const rct_ride_lift_data RideLiftData[] = { { SOUND_LIFT_3, 7, 7 }, // Spiral Roller coaster diff --git a/src/ride/ride_data.h b/src/ride/ride_data.h index 398b8ac127..554060b718 100644 --- a/src/ride/ride_data.h +++ b/src/ride/ride_data.h @@ -104,5 +104,6 @@ extern const uint32 ShopItemImage[SHOP_ITEM_COUNT]; extern const rct_ride_type_vehicle CableLiftVehicle; extern const uint16 RideFilmLength[3]; +extern const uint16 RideCrookedHouseLength[1]; #endif diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 2122b78be5..94cd69c762 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -51,6 +51,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle); static void vehicle_update_space_rings_operating(rct_vehicle* vehicle); static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle); +static void vehicle_update_crooked_house_operating(rct_vehicle* vehicle); static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle); static void vehicle_update_swinging(rct_vehicle* vehicle); static void vehicle_update_simulator_operating(rct_vehicle* vehicle); @@ -1075,13 +1076,15 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING: vehicle_update_haunted_house_operating(vehicle); break; + case VEHICLE_STATUS_CROOKED_HOUSE_OPERATING: + vehicle_update_crooked_house_operating(vehicle); + break; case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: case VEHICLE_STATUS_ROTATING: - case VEHICLE_STATUS_CROOKED_HOUSE_OPERATING: case VEHICLE_STATUS_TRAVELLING_15: { int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); @@ -1697,7 +1700,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; vehicle->var_4C = 0xFFFF; - //6d9781 + vehicle_update_crooked_house_operating(vehicle); break; default: vehicle->sub_state = 0; @@ -1957,6 +1960,22 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { } } +/* rct2: 0x006d9781 */ +static void vehicle_update_crooked_house_operating(rct_vehicle* vehicle) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + if ((uint16)(vehicle->var_4C + 1) > RideCrookedHouseLength[vehicle->sub_state]) { + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; + return; + } + + vehicle->var_4C++; +} + /* rct2: 0x006D9547 */ static void vehicle_update_top_spin_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) From 713b63d9f5ba9430728c4ea7d4ff44c089322bb6 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 25 Nov 2015 22:25:13 +0000 Subject: [PATCH 043/162] Implement vehicle update rotation --- src/ride/ride.h | 6 ++-- src/ride/vehicle.c | 82 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index 9b753e7f72..22afb46925 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -400,8 +400,10 @@ enum { RIDE_ENTRY_FLAG_NO_BANKED_TRACK = 1 << 2, // 0x4 RIDE_ENTRY_FLAG_3 = 1 << 3, // 0x8 RIDE_ENTRY_FLAG_ALTERNATIVE_SWING_MODE_1 = 1 << 4, // 0x10 - RIDE_ENTRY_FLAG_5 = 1 << 5, // 0x20 - RIDE_ENTRY_FLAG_6 = 1 << 6, // 0x40 + // Twist type rotation ride + RIDE_ENTRY_FLAG_ALTERNATIVE_ROTATION_MODE_1 = 1 << 5, // 0x20 + // Lifting arm rotation ride (enterprise) + RIDE_ENTRY_FLAG_ALTERNATIVE_ROTATION_MODE_2 = 1 << 6, // 0x40 RIDE_ENTRY_FLAG_7 = 1 << 7, // 0x80 RIDE_ENTRY_FLAG_8 = 1 << 8, // 0x100 RIDE_ENTRY_FLAG_9 = 1 << 9, // 0x200 diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 94cd69c762..0321c38b61 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -49,6 +49,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle); +static void vehicle_update_rotating(rct_vehicle* vehicle); static void vehicle_update_space_rings_operating(rct_vehicle* vehicle); static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle); static void vehicle_update_crooked_house_operating(rct_vehicle* vehicle); @@ -1079,12 +1080,14 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_CROOKED_HOUSE_OPERATING: vehicle_update_crooked_house_operating(vehicle); break; + case VEHICLE_STATUS_ROTATING: + vehicle_update_rotating(vehicle); + break; case VEHICLE_STATUS_DEPARTING: case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: - case VEHICLE_STATUS_ROTATING: case VEHICLE_STATUS_TRAVELLING_15: { int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); @@ -1609,7 +1612,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); vehicle->var_CE = 0; vehicle->var_4C = 0xFFFF; - //6d92ff + vehicle_update_rotating(vehicle); break; case RIDE_MODE_FILM_AVENGING_AVIATORS: case RIDE_MODE_FILM_THRILL_RIDERS: @@ -1870,6 +1873,81 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { vehicle->var_C0 = 0; } +/* rct2: 0x006D92FF */ +static void vehicle_update_rotating(rct_vehicle* vehicle) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + return; + + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + + uint8* edi; + if (rideEntry->flags & RIDE_ENTRY_FLAG_ALTERNATIVE_ROTATION_MODE_1) { + edi = RCT2_ADDRESS(0x0099F0F4, uint8*)[vehicle->sub_state]; + } + else if (rideEntry->flags & RIDE_ENTRY_FLAG_ALTERNATIVE_ROTATION_MODE_2) { + edi = RCT2_ADDRESS(0x009A2428, uint8*)[vehicle->sub_state]; + } + else { + edi = RCT2_ADDRESS(0x0099EB1C, uint8*)[vehicle->sub_state]; + } + + sint32 var_4C = (sint16)vehicle->var_4C; + if (RCT2_GLOBAL(0x00F64E34, uint8) == BREAKDOWN_CONTROL_FAILURE) { + var_4C += (ride->var_1AC >> 6) + 1; + } + var_4C++; + + uint8 al = edi[(uint32)var_4C]; + if (al != 0xFF) { + vehicle->var_4C = (uint16)var_4C; + if (al == vehicle->var_1F) + return; + vehicle->var_1F = al; + invalidate_sprite_2((rct_sprite*)vehicle); + return; + } + + vehicle->var_4C = 0xFFFF; + vehicle->var_CE++; + if (RCT2_GLOBAL(0x00F64E34, uint8) != BREAKDOWN_CONTROL_FAILURE) { + bool shouldStop = true; + if (ride->status != RIDE_STATUS_CLOSED) { + al = vehicle->var_CE + 1; + if (ride->type == RIDE_TYPE_ENTERPRISE) + al += 9; + + if (al < ride->rotations) + shouldStop = false; + } + + if (shouldStop == true) { + if (vehicle->sub_state == 2) { + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; + return; + } + vehicle->sub_state++; + vehicle_update_rotating(vehicle); + return; + } + } + + if (ride->type == RIDE_TYPE_ENTERPRISE && + vehicle->sub_state == 2) { + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_C0 = 0; + return; + } + + vehicle->sub_state = 1; + vehicle_update_rotating(vehicle); +} + /* rct2: 0x006D97CB */ static void vehicle_update_space_rings_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) From 3dd5847fcaf431cadcee910729aaa3b9412e8f9f Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 25 Nov 2015 22:36:11 +0000 Subject: [PATCH 044/162] Fix small audio crash --- src/ride/vehicle.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 0321c38b61..90d24cdc3f 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2495,6 +2495,8 @@ static void vehicle_update_sound(rct_vehicle *vehicle) default: if ((vehicleEntry->var_14 & 0x10)) { screamId = vehicle_update_scream_sound(vehicle); + if (screamId == NO_SCREAM) + screamId = 255; if (screamId == 255) goto loc_6D7A97; break; From d42a784d6be9ebe6b02c7eb01e08a5d26881c53b Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 28 Nov 2015 18:13:22 +0000 Subject: [PATCH 045/162] Started vehicle_update_departing --- src/ride/ride.h | 2 +- src/ride/vehicle.c | 192 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 188 insertions(+), 6 deletions(-) diff --git a/src/ride/ride.h b/src/ride/ride.h index 22afb46925..2efaa238cd 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -184,7 +184,7 @@ typedef struct { // (in RCT2, display_speed = (max_speed * 9) >> 18) sint32 max_speed; // 0x0D8 sint32 average_speed; // 0x0DC - uint8 var_0E0; + uint8 current_test_segment; // 0x0E0 uint8 var_0E1; uint8 pad_0E2[0x2]; sint32 length[4]; // 0x0E4 diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 90d24cdc3f..3bdc5b562f 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -48,6 +48,7 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); +static void vehicle_update_departing(rct_vehicle* vehicle); static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle); static void vehicle_update_rotating(rct_vehicle* vehicle); static void vehicle_update_space_rings_operating(rct_vehicle* vehicle); @@ -659,9 +660,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) uint8 entrance = ride->var_1F6; if (ride->entrances[entrance] != 0xFFFF){ - - //ecx - uint8 var_E0 = ride->var_0E0; + uint8 test_segment = ride->current_test_segment; ride->var_0E1++; if (ride->var_0E1 >= 32)ride->var_0E1 = 0; @@ -673,12 +672,12 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) if (ride->var_0E1 == 0 && velocity > 0x8000){ ride->average_speed += velocity; - ride->time[var_E0]++; + ride->time[test_segment]++; } sint32 distance = abs(((vehicle->velocity + vehicle->var_2C) >> 10) * 42); if (vehicle->var_CE == 0){ - ride->length[var_E0] += distance; + ride->length[test_segment] += distance; } if (RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_HAS_G_FORCES){ @@ -1084,6 +1083,8 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_rotating(vehicle); break; case VEHICLE_STATUS_DEPARTING: + vehicle_update_departing(vehicle); + break; case VEHICLE_STATUS_TRAVELLING: case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: @@ -1713,6 +1714,187 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { } } +/* rct2: 0x006D9EB0 */ +static void vehicle_peep_easteregg_here_we_are(rct_vehicle* vehicle) { + uint16 spriteId = vehicle->sprite_index; + do { + vehicle = GET_VEHICLE(spriteId); + for (int i = 0; i < vehicle->num_peeps; ++i) { + rct_peep* peep = GET_PEEP(vehicle->peep[i]); + if (peep->flags & PEEP_FLAGS_HERE_WE_ARE) { + peep_insert_new_thought(peep, PEEP_THOUGHT_HERE_WE_ARE, peep->current_ride); + } + } + } while ((spriteId = vehicle->next_vehicle_on_train) != 0xFFFF); +} + +/* rct2: 0x006D845B */ +static void vehicle_update_departing(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + + if (vehicle->sub_state == 0) { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) { + if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) + return; + + ride->lifecycle_flags |= RIDE_LIFECYCLE_BROKEN_DOWN; + ride_breakdown_add_news_item(vehicle->ride); + + ride->window_invalidate_flags |= + RIDE_INVALIDATE_RIDE_MAIN | + RIDE_INVALIDATE_RIDE_LIST | + RIDE_INVALIDATE_RIDE_MAINTENANCE; + ride->inspection_station = vehicle->current_station; + ride->breakdown_reason = ride->breakdown_reason_pending; + vehicle->velocity = 0; + return; + } + + vehicle->sub_state = 1; + vehicle_peep_easteregg_here_we_are(vehicle); + + if (rideEntry->flags & RIDE_ENTRY_FLAG_3) { + uint8 soundId = (rideEntry->vehicles[0].sound_range == 4) ? + SOUND_TRAM : + SOUND_TRAIN_CHUGGING; + + audio_play_sound_at_location( + soundId, + vehicle->x, + vehicle->y, + vehicle->z); + } + + if (ride->mode == RIDE_MODE_UPWARD_LAUNCH || + (ride->mode == RIDE_MODE_DOWNWARD_LAUNCH && vehicle->var_CE > 1)) { + + audio_play_sound_at_location( + SOUND_RIDE_LAUNCH_2, + vehicle->x, + vehicle->y, + vehicle->z + ); + } + + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TESTED)) { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_TESTING) { + if (ride->current_test_segment + 1 < ride->num_stations) { + ride->current_test_segment++; + ride->var_1F6 = vehicle->current_station; + } + else { + // Update test data for this segment + RCT2_CALLPROC_X(0x006D7338, 0, 0, 0, 0, (int)vehicle, vehicle->ride * 0x260, 0); + } + } + else if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TEST_IN_PROGRESS)) { + // Reset all test data + RCT2_CALLPROC_X(0x006D6BE7, 0, 0, 0, 0, (int)vehicle, vehicle->ride * 0x260, 0); + } + } + } + + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + switch (ride->mode) { + case RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE: + if (vehicle->velocity >= -131940) + vehicle->var_2C = -3298; + break; + case RIDE_MODE_POWERED_LAUNCH_PASSTROUGH: + case RIDE_MODE_POWERED_LAUNCH: + case RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED: + case RIDE_MODE_LIM_POWERED_LAUNCH: + case RIDE_MODE_UPWARD_LAUNCH: + if (ride->type == RIDE_TYPE_AIR_POWERED_VERTICAL_COASTER) { + if ((ride->launch_speed << 16) > vehicle->velocity) { + vehicle->var_2C = ride->launch_speed << 13; + } + break; + } + + if ((ride->launch_speed << 16) > vehicle->velocity) + vehicle->var_2C = ride->launch_speed << 12; + break; + case RIDE_MODE_DOWNWARD_LAUNCH: + if (vehicle->sub_state >= 1) { + if ((14 << 16) > vehicle->velocity) + vehicle->var_2C = 14 << 12; + break; + } + // Fall through + case RIDE_MODE_CONTINUOUS_CIRCUIT: + case RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED: + case RIDE_MODE_ROTATING_LIFT: + case RIDE_MODE_FREEFALL_DROP: + case RIDE_MODE_BOAT_HIRE: + if (vehicleEntry->var_14 & (1 << 3)) + break; + + if (vehicle->velocity <= 131940) + vehicle->var_2C = 3298; + break; + } + int edx; + uint32 flags = sub_6DAB4C(vehicle, &edx); + + if (flags & (1 << 8)) { + if ((edx & 0xFF) == 2) { + vehicle->velocity = -vehicle->velocity; + // jmp 0x6D8858 + } + } + + if (flags & ((1 << 5) | (1 << 12))) { + if ((edx & 0xFF) == 5) { + // jmp 0x6d982f + } + else if ((edx & 0xFF) == 2) { + vehicle->velocity = -vehicle->velocity; + // jmp 0x6D8858 + } + else if ((edx & 0xFF) == 4) { + vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_3; + vehicle->velocity = 0; + } + } + + if (flags & (1 << 4)) { + vehicle->var_B8 |= (1 << 1); + if ((edx & 0xFF) != 2) { + sint32 speed = ride->lift_hill_speed * 31079; + if (vehicle->velocity <= speed) { + vehicle->var_2C = 15539; + if (vehicle->velocity != 0) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == BREAKDOWN_SAFETY_CUT_OUT) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1; + } + } + else + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1; + } + } + else { + sint32 speed = ride->lift_hill_speed * -31079; + if (vehicle->velocity >= speed) { + vehicle->var_2C = -15539; + if (vehicle->velocity != 0) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == BREAKDOWN_SAFETY_CUT_OUT) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1; + } + } + else + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1; + } + } + } + + //6d8772 +} + /* rct2: 0x006D9249 */ static void vehicle_update_swinging(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); From eb1e97d73cad6a6311e4ce1c06b490936ea99b0f Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 28 Nov 2015 23:18:02 +0000 Subject: [PATCH 046/162] Implemented more. Fixed mistake with edx --- src/ride/vehicle.c | 78 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 3bdc5b562f..089dc1b620 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1836,25 +1836,26 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { vehicle->var_2C = 3298; break; } - int edx; - uint32 flags = sub_6DAB4C(vehicle, &edx); + + uint32 flags = sub_6DAB4C(vehicle, NULL); if (flags & (1 << 8)) { - if ((edx & 0xFF) == 2) { + if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { vehicle->velocity = -vehicle->velocity; // jmp 0x6D8858 } } if (flags & ((1 << 5) | (1 << 12))) { - if ((edx & 0xFF) == 5) { - // jmp 0x6d982f + if (ride->mode == RIDE_MODE_BOAT_HIRE) { + RCT2_CALLPROC_X(0x006D982F, 0, 0, 0, 0, (int)vehicle, 0, 0); + return; } - else if ((edx & 0xFF) == 2) { + else if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { vehicle->velocity = -vehicle->velocity; // jmp 0x6D8858 } - else if ((edx & 0xFF) == 4) { + else if (ride->mode == RIDE_MODE_SHUTTLE) { vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_3; vehicle->velocity = 0; } @@ -1862,7 +1863,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (flags & (1 << 4)) { vehicle->var_B8 |= (1 << 1); - if ((edx & 0xFF) != 2) { + if (ride->mode != RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { sint32 speed = ride->lift_hill_speed * 31079; if (vehicle->velocity <= speed) { vehicle->var_2C = 15539; @@ -1892,7 +1893,66 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { } } - //6d8772 + if (ride->mode == RIDE_MODE_FREEFALL_DROP) { + vehicle->var_C5++; + }else{ + bool shouldLaunch = true; + if (ride->mode == RIDE_MODE_DOWNWARD_LAUNCH) { + if (vehicle->var_CE < 1) + shouldLaunch = false; + } + + if (shouldLaunch) { + if (!(flags & (1 << 3)) || (RCT2_GLOBAL(0x00F64E1C, uint8) != vehicle->current_station)) { + //jmp 6d8858 + } + + if (!flags & (1 << 5)) + return; + if (ride->mode == RIDE_MODE_BOAT_HIRE || + ride->mode == RIDE_MODE_ROTATING_LIFT || + ride->mode == RIDE_MODE_SHUTTLE) + return; + + if (ride->lifecycle_flags & RIDE_LIFECYCLE_SIX_FLAGS_DEPRECATED) + return; + + RCT2_CALLPROC_X(0x006D9EFE, 0, 0, 0, 0, (int)vehicle, 0, 0); + return; + } + } + + rct_map_element* mapElement = map_get_track_element_at_of_type( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z / 8, + vehicle->track_type >> 2); + + if (mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE) { + //jmp 6d8858 + } + + if (mapElement->clearance_height == (mapElement + 1)->clearance_height) { + if ((mapElement + 1)->properties.track.type == TRACK_ELEM_TOWER_SECTION) { + if (ride->mode == RIDE_MODE_FREEFALL_DROP) + invalidate_sprite_2((rct_sprite*)vehicle); + return; + } + } + + if ((mapElement + 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE) + ;// jmp 6d8858 + + if (mapElement->clearance_height != vehicle->z) + ;// jmp 6d8858 + + if ((mapElement + 2)->properties.track.type == TRACK_ELEM_TOWER_SECTION) { + if (ride->mode == RIDE_MODE_FREEFALL_DROP) + invalidate_sprite_2((rct_sprite*)vehicle); + return; + } + + //6d8858 } /* rct2: 0x006D9249 */ From 371dec1c17c42fe51bd75e37f6602a066cbac334 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 29 Nov 2015 10:39:17 +0000 Subject: [PATCH 047/162] Fix bugs and finish departing station implementation --- src/ride/vehicle.c | 82 +++++++++++++++++++++++++++++++++++++++------- src/ride/vehicle.h | 4 ++- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 089dc1b620..e728f29919 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -49,6 +49,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_departing(rct_vehicle* vehicle); +static void sub_6D8858(rct_vehicle* vehicle); static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle); static void vehicle_update_rotating(rct_vehicle* vehicle); static void vehicle_update_space_rings_operating(rct_vehicle* vehicle); @@ -1818,7 +1819,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { vehicle->var_2C = ride->launch_speed << 12; break; case RIDE_MODE_DOWNWARD_LAUNCH: - if (vehicle->sub_state >= 1) { + if (vehicle->var_CE >= 1) { if ((14 << 16) > vehicle->velocity) vehicle->var_2C = 14 << 12; break; @@ -1842,7 +1843,8 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (flags & (1 << 8)) { if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { vehicle->velocity = -vehicle->velocity; - // jmp 0x6D8858 + sub_6D8858(vehicle); + return; } } @@ -1853,7 +1855,8 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { } else if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { vehicle->velocity = -vehicle->velocity; - // jmp 0x6D8858 + sub_6D8858(vehicle); + return; } else if (ride->mode == RIDE_MODE_SHUTTLE) { vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_3; @@ -1904,10 +1907,11 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (shouldLaunch) { if (!(flags & (1 << 3)) || (RCT2_GLOBAL(0x00F64E1C, uint8) != vehicle->current_station)) { - //jmp 6d8858 + sub_6D8858(vehicle); + return; } - if (!flags & (1 << 5)) + if (!(flags & (1 << 5))) return; if (ride->mode == RIDE_MODE_BOAT_HIRE || ride->mode == RIDE_MODE_ROTATING_LIFT || @@ -1929,10 +1933,11 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { vehicle->track_type >> 2); if (mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE) { - //jmp 6d8858 + sub_6D8858(vehicle); + return; } - if (mapElement->clearance_height == (mapElement + 1)->clearance_height) { + if (mapElement->clearance_height == (mapElement + 1)->base_height) { if ((mapElement + 1)->properties.track.type == TRACK_ELEM_TOWER_SECTION) { if (ride->mode == RIDE_MODE_FREEFALL_DROP) invalidate_sprite_2((rct_sprite*)vehicle); @@ -1940,11 +1945,15 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { } } - if ((mapElement + 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE) - ;// jmp 6d8858 + if ((mapElement + 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE) { + sub_6D8858(vehicle); + return; + } - if (mapElement->clearance_height != vehicle->z) - ;// jmp 6d8858 + if (mapElement->clearance_height != (mapElement + 2)->base_height) { + sub_6D8858(vehicle); + return; + } if ((mapElement + 2)->properties.track.type == TRACK_ELEM_TOWER_SECTION) { if (ride->mode == RIDE_MODE_FREEFALL_DROP) @@ -1952,7 +1961,56 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { return; } - //6d8858 + sub_6D8858(vehicle); +} + +/* Part of vehicle_update_departing */ +static void sub_6D8858(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + + if (ride->mode == RIDE_MODE_DOWNWARD_LAUNCH ) { + if (vehicle->var_CE >= 1 && (14 << 16) > vehicle->velocity) + return; + + audio_play_sound_at_location( + SOUND_RIDE_LAUNCH_1, + vehicle->x, + vehicle->y, + vehicle->z); + } + + if (ride->mode == RIDE_MODE_UPWARD_LAUNCH) { + if ((ride->launch_speed << 16) > vehicle->velocity) + return; + + audio_play_sound_at_location( + SOUND_RIDE_LAUNCH_1, + vehicle->x, + vehicle->y, + vehicle->z); + } + + if (ride->mode != RIDE_MODE_RACE && + ride->mode != RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED && + ride->mode != RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED) { + + ride->station_depart[vehicle->current_station] &= STATION_DEPART_FLAG; + uint8 waitingTime = 3; + if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH) { + waitingTime = max(ride->min_waiting_time, 3); + waitingTime = min(waitingTime, 127); + } + + ride->station_depart[vehicle->current_station] |= waitingTime; + } + + vehicle->status = VEHICLE_STATUS_TRAVELLING; + vehicle_invalidate_window(vehicle); + vehicle->var_D0 = 0; + + vehicle->sub_state = 1; + if (vehicle->velocity < 0) + vehicle->sub_state = 0; } /* rct2: 0x006D9249 */ diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index bb517e9591..67ebe30367 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -165,7 +165,9 @@ typedef struct { uint8 var_CE; uint8 num_laps; // 0xCE }; - uint8 pad_CF[0x03]; + uint8 pad_CF; + uint8 var_D0; + uint8 pad_D1; sint8 var_D2; uint8 var_D3; uint8 var_D4; From a0e1c16f48f668080831985d9a35ea95de1f8bb8 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 29 Nov 2015 10:58:37 +0000 Subject: [PATCH 048/162] Minor refactor --- src/ride/vehicle.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index e728f29919..90c194ac97 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -49,7 +49,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_departing(rct_vehicle* vehicle); -static void sub_6D8858(rct_vehicle* vehicle); +static void vehicle_finish_departing(rct_vehicle* vehicle); static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle); static void vehicle_update_rotating(rct_vehicle* vehicle); static void vehicle_update_space_rings_operating(rct_vehicle* vehicle); @@ -1843,7 +1843,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (flags & (1 << 8)) { if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { vehicle->velocity = -vehicle->velocity; - sub_6D8858(vehicle); + vehicle_finish_departing(vehicle); return; } } @@ -1855,7 +1855,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { } else if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { vehicle->velocity = -vehicle->velocity; - sub_6D8858(vehicle); + vehicle_finish_departing(vehicle); return; } else if (ride->mode == RIDE_MODE_SHUTTLE) { @@ -1907,7 +1907,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (shouldLaunch) { if (!(flags & (1 << 3)) || (RCT2_GLOBAL(0x00F64E1C, uint8) != vehicle->current_station)) { - sub_6D8858(vehicle); + vehicle_finish_departing(vehicle); return; } @@ -1933,7 +1933,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { vehicle->track_type >> 2); if (mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE) { - sub_6D8858(vehicle); + vehicle_finish_departing(vehicle); return; } @@ -1946,12 +1946,12 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { } if ((mapElement + 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE) { - sub_6D8858(vehicle); + vehicle_finish_departing(vehicle); return; } if (mapElement->clearance_height != (mapElement + 2)->base_height) { - sub_6D8858(vehicle); + vehicle_finish_departing(vehicle); return; } @@ -1961,11 +1961,18 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { return; } - sub_6D8858(vehicle); + vehicle_finish_departing(vehicle); } -/* Part of vehicle_update_departing */ -static void sub_6D8858(rct_vehicle* vehicle) { +/* rct2: 0x006D8858 + * Part of vehicle_update_departing + * Called after finishing departing sequence to enter + * traveling state. + * Vertical rides class the lift to the top of the tower + * as the departing sequence. After this point station + * boosters do not affect the ride. + */ +static void vehicle_finish_departing(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); if (ride->mode == RIDE_MODE_DOWNWARD_LAUNCH ) { From 3204b52d1e17d9bddc398bbfb4a284003a83bcce Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 29 Nov 2015 13:30:48 +0000 Subject: [PATCH 049/162] Implemented vehicle_update_test_finish and vehicle_test_reset --- src/ride/vehicle.c | 76 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 90c194ac97..fd3ebd2635 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1729,6 +1729,76 @@ static void vehicle_peep_easteregg_here_we_are(rct_vehicle* vehicle) { } while ((spriteId = vehicle->next_vehicle_on_train) != 0xFFFF); } +/* rct2: 0x006D7338 + * Performed when vehicle has completed a full circuit + */ +static void vehicle_update_test_finish(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + ride->lifecycle_flags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_TESTING; + ride->lifecycle_flags |= RIDE_LIFECYCLE_TESTED; + + for (int i = ride->num_stations - 1; i >= 1; i--) { + if (ride->time[i - 1] != 0) + continue; + + uint16 oldTime = ride->time[i - 1]; + ride->time[i - 1] = ride->time[i]; + ride->time[i] = oldTime; + + sint32 oldLength = ride->length[i - 1]; + ride->length[i - 1] = ride->length[i]; + ride->length[i] = oldLength; + } + + uint32 totalTime = 0; + for (uint8 i = 0; i < ride->num_stations; ++i) { + totalTime += ride->time[i]; + } + + totalTime = min(totalTime, 1); + ride->average_speed = ride->average_speed / totalTime; + + window_invalidate_by_number(WC_RIDE, vehicle->ride); +} + +/* rct2: 0x006D6BE7 + * + */ +static void vehicle_test_reset(rct_vehicle* vehicle) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TESTING; + + rct_ride* ride = GET_RIDE(vehicle->ride); + ride->lifecycle_flags |= RIDE_LIFECYCLE_TEST_IN_PROGRESS; + ride->lifecycle_flags &= ~RIDE_LIFECYCLE_NO_RAW_STATS; + ride->max_speed = 0; + ride->average_speed = 0; + ride->current_test_segment = 0; + ride->var_0E1 = 0; + ride->max_positive_vertical_g = FIXED_2DP(1, 0); + ride->max_negative_vertical_g = FIXED_2DP(1, 0); + ride->max_lateral_g = 0; + ride->previous_vertical_g = 0; + ride->previous_lateral_g = 0; + ride->testing_flags = 0; + ride->var_10C = 0xFFFF; + ride->var_11F = 0xFF; + ride->turn_count_default = 0; + ride->turn_count_banked = 0; + ride->turn_count_sloped = 0; + ride->inversions = 0; + ride->drops = 0; + ride->sheltered_length = 0; + ride->var_11C = 0; + ride->num_sheltered_sections = 0; + ride->highest_drop_height = 0; + ride->special_track_elements = 0; + memset(&ride->length, 0, 4 * 4); + memset(&ride->time, 0, 4 * 2); + ride->var_1F6 = vehicle->current_station; + window_invalidate_by_number(WC_RIDE, vehicle->ride); +} + /* rct2: 0x006D845B */ static void vehicle_update_departing(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); @@ -1785,13 +1855,11 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { ride->var_1F6 = vehicle->current_station; } else { - // Update test data for this segment - RCT2_CALLPROC_X(0x006D7338, 0, 0, 0, 0, (int)vehicle, vehicle->ride * 0x260, 0); + vehicle_update_test_finish(vehicle); } } else if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TEST_IN_PROGRESS)) { - // Reset all test data - RCT2_CALLPROC_X(0x006D6BE7, 0, 0, 0, 0, (int)vehicle, vehicle->ride * 0x260, 0); + vehicle_test_reset(vehicle); } } } From 6e675b08c3aa5d33bbdde5386c6c4123548615e7 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 29 Nov 2015 14:42:04 +0000 Subject: [PATCH 050/162] Implement vehicle_update_traveling --- src/ride/vehicle.c | 226 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 196 insertions(+), 30 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index fd3ebd2635..b2666f34fb 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -50,6 +50,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle); static void vehicle_update_departing(rct_vehicle* vehicle); static void vehicle_finish_departing(rct_vehicle* vehicle); +static void vehicle_update_travelling(rct_vehicle* vehicle); static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle); static void vehicle_update_rotating(rct_vehicle* vehicle); static void vehicle_update_space_rings_operating(rct_vehicle* vehicle); @@ -1087,6 +1088,8 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_departing(vehicle); break; case VEHICLE_STATUS_TRAVELLING: + vehicle_update_travelling(vehicle); + break; case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: @@ -1799,6 +1802,37 @@ static void vehicle_test_reset(rct_vehicle* vehicle) { window_invalidate_by_number(WC_RIDE, vehicle->ride); } +static bool vehicle_next_tower_element_is_top(rct_vehicle* vehicle) { + rct_map_element* mapElement = map_get_track_element_at_of_type( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z / 8, + vehicle->track_type >> 2); + + if (mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE) { + return true; + } + + if (mapElement->clearance_height == (mapElement + 1)->base_height) { + if ((mapElement + 1)->properties.track.type == TRACK_ELEM_TOWER_SECTION) { + return false; + } + } + + if ((mapElement + 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE) { + return true; + } + + if (mapElement->clearance_height != (mapElement + 2)->base_height) { + return true; + } + + if ((mapElement + 2)->properties.track.type == TRACK_ELEM_TOWER_SECTION) { + return false; + } + return true; +} + /* rct2: 0x006D845B */ static void vehicle_update_departing(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); @@ -1994,36 +2028,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { } } - rct_map_element* mapElement = map_get_track_element_at_of_type( - vehicle->track_x, - vehicle->track_y, - vehicle->track_z / 8, - vehicle->track_type >> 2); - - if (mapElement->flags & MAP_ELEMENT_FLAG_LAST_TILE) { - vehicle_finish_departing(vehicle); - return; - } - - if (mapElement->clearance_height == (mapElement + 1)->base_height) { - if ((mapElement + 1)->properties.track.type == TRACK_ELEM_TOWER_SECTION) { - if (ride->mode == RIDE_MODE_FREEFALL_DROP) - invalidate_sprite_2((rct_sprite*)vehicle); - return; - } - } - - if ((mapElement + 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE) { - vehicle_finish_departing(vehicle); - return; - } - - if (mapElement->clearance_height != (mapElement + 2)->base_height) { - vehicle_finish_departing(vehicle); - return; - } - - if ((mapElement + 2)->properties.track.type == TRACK_ELEM_TOWER_SECTION) { + if (vehicle_next_tower_element_is_top(vehicle) == false) { if (ride->mode == RIDE_MODE_FREEFALL_DROP) invalidate_sprite_2((rct_sprite*)vehicle); return; @@ -2088,6 +2093,167 @@ static void vehicle_finish_departing(rct_vehicle* vehicle) { vehicle->sub_state = 0; } +/* rct2: 0x006D8937 */ +static void vehicle_update_travelling(rct_vehicle* vehicle) { + // Check to see if vehicle is lost + RCT2_CALLPROC_X(0x006DE5CB, 0, 0, 0, 0, (int)vehicle, 0, 0); + + rct_ride* ride = GET_RIDE(vehicle->ride); + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0 && ride->mode == RIDE_MODE_ROTATING_LIFT) + return; + + if (vehicle->sub_state == 2) { + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->var_C0--; + if (vehicle->var_C0 == 0) + vehicle->sub_state = 0; + } + + if (ride->mode == RIDE_MODE_FREEFALL_DROP && + vehicle->var_C5 != 0) { + + vehicle->var_C5++; + vehicle->velocity = 0; + vehicle->var_2C = 0; + invalidate_sprite_2((rct_sprite*)vehicle); + return; + } + + uint32 flags = sub_6DAB4C(vehicle, NULL); + + bool skipCheck = false; + if (flags & ((1 << 8) | (1 << 9)) && + ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE && + vehicle->sub_state == 0) { + vehicle->sub_state = 1; + vehicle->velocity = 0; + skipCheck = true; + } + + if (!skipCheck) { + if (flags & (1 << 6)) { + RCT2_CALLPROC_X(0x006D9EFE, 0, 0, 0, 0, (int)vehicle, 0, 0); + return; + } + + if (flags & (1 << 7)) { + RCT2_CALLPROC_X(0x006DA059, 0, 0, 0, 0, (int)vehicle, 0, 0); + return; + } + + if (flags & ((1 << 9) | (1 << 12))) { + if (ride->mode == RIDE_MODE_ROTATING_LIFT) { + if (vehicle->sub_state <= 1) { + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 1; + vehicle->var_C0 = 0; + return; + } + } + else if (ride->mode == RIDE_MODE_SHUTTLE) { + vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_3; + vehicle->velocity = 0; + } + else { + if (ride->lifecycle_flags & RIDE_LIFECYCLE_SIX_FLAGS_DEPRECATED) { + if (vehicle->sub_state != 0) { + vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_3; + vehicle->velocity = 0; + } + else { + vehicle->sub_state = 1; + vehicle->velocity = 0; + } + } + else { + if (vehicle->sub_state != 0) { + RCT2_CALLPROC_X(0x006D9EFE, 0, 0, 0, 0, (int)vehicle, 0, 0); + return; + } + vehicle->sub_state = 1; + vehicle->velocity = 0; + } + } + } + } + + if (ride->mode == RIDE_MODE_ROTATING_LIFT && + vehicle->sub_state <= 1) { + + if (vehicle->sub_state == 0) { + if (vehicle->velocity >= -131940) + vehicle->var_2C = -3298; + vehicle->velocity = max(vehicle->velocity, -131940); + } + else { + if (vehicle_next_tower_element_is_top(vehicle) == true) { + vehicle->velocity = 0; + vehicle->sub_state = 2; + vehicle->var_C0 = 150; + } + else { + if (vehicle->velocity <= 131940) + vehicle->var_2C = 3298; + } + } + } + + if (flags & (1 << 4)) { + if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { + if (vehicle->sub_state == 0) { + if (vehicle->velocity != 0) + vehicle->var_B8 |= (1 << 1); + + if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_12)) { + if (vehicle->velocity > ride->lift_hill_speed * -31079) { + vehicle->var_2C = -15539; + + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + vehicle->var_B8 |= (1 << 7); + + vehicle->var_B8 &= ~(1 << 1); + } + } + } + } + else { + vehicle->var_B8 |= (1 << 1); + if (vehicle->velocity <= ride->lift_hill_speed * 31079) { + vehicle->var_2C = 15539; + if (vehicle->velocity != 0) { + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) + vehicle->var_B8 |= (1 << 7); + } + vehicle->var_B8 &= ~(1 << 1); + } + } + } + + if (!(flags & (1 << 3))) + return; + + if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE && + vehicle->velocity >= 0 && + !(vehicle->update_flags & VEHICLE_UPDATE_FLAG_12)) { + return; + } + + if (ride->mode == RIDE_MODE_POWERED_LAUNCH_PASSTROUGH && + vehicle->velocity < 0) + return; + + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle->current_station = RCT2_GLOBAL(0x00F64E1C, uint8); + vehicle_invalidate_window(vehicle); + vehicle->var_C0 = 0; + + vehicle->sub_state = 0; + if (vehicle->velocity < 0) + vehicle->sub_state = 1; +} + /* rct2: 0x006D9249 */ static void vehicle_update_swinging(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); From 95ac8d67ee40ec9c58f64399917158f85286a7c6 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 29 Nov 2015 19:45:01 +0000 Subject: [PATCH 051/162] Implement vehicle missing. Fixed bugs with reverese incline --- src/ride/vehicle.c | 67 ++++++++++++++++++++++++++++++++++++++-------- src/ride/vehicle.h | 3 +-- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index b2666f34fb..3c4efef8e4 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2093,10 +2093,51 @@ static void vehicle_finish_departing(rct_vehicle* vehicle) { vehicle->sub_state = 0; } +/* rct2: 0x006DE5CB */ +static void vehicle_check_if_missing(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + + if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED)) + return; + + if (ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED || + ride->mode == RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED) + return; + + if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_27)) + return; + + vehicle->var_D0++; + if (ride->lifecycle_flags & RIDE_LIFECYCLE_11) + return; + + uint16 limit = ride->type == RIDE_TYPE_BOAT_RIDE ? 15360 : 9600; + + if (vehicle->var_D0 <= limit) + return; + + ride->lifecycle_flags |= RIDE_LIFECYCLE_11; + + RCT2_GLOBAL(0x0013CE952, rct_string_id) + = RCT2_ADDRESS(0x0097C98E, rct_string_id)[ride->type * 4] + 6; + + uint8 vehicleIndex = 0; + for (; vehicleIndex < ride->num_vehicles; ++vehicleIndex) + if (ride->vehicles[vehicleIndex] == vehicle->sprite_index) break; + + vehicleIndex++; + RCT2_GLOBAL(0x0013CE954, uint16) = vehicleIndex; + RCT2_GLOBAL(0x0013CE956, rct_string_id) = ride->name; + RCT2_GLOBAL(0x0013CE958, uint32) = ride->name_arguments; + RCT2_GLOBAL(0x0013CE95C, rct_string_id) = + RCT2_ADDRESS(0x0097C98E, rct_string_id)[ride->type * 4 + 2]; + + news_item_add_to_queue(NEWS_ITEM_RIDE, 2218, vehicle->ride); +} + /* rct2: 0x006D8937 */ static void vehicle_update_travelling(rct_vehicle* vehicle) { - // Check to see if vehicle is lost - RCT2_CALLPROC_X(0x006DE5CB, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_check_if_missing(vehicle); rct_ride* ride = GET_RIDE(vehicle->ride); if (RCT2_GLOBAL(0x00F64E34, uint8) == 0 && ride->mode == RIDE_MODE_ROTATING_LIFT) @@ -2142,7 +2183,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { return; } - if (flags & ((1 << 9) | (1 << 12))) { + if (flags & ((1 << 5) | (1 << 12))) { if (ride->mode == RIDE_MODE_ROTATING_LIFT) { if (vehicle->sub_state <= 1) { vehicle->status = VEHICLE_STATUS_ARRIVING; @@ -2207,13 +2248,13 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { vehicle->var_B8 |= (1 << 1); if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_12)) { - if (vehicle->velocity > ride->lift_hill_speed * -31079) { + if (vehicle->velocity >= ride->lift_hill_speed * -31079) { vehicle->var_2C = -15539; - if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) - vehicle->var_B8 |= (1 << 7); - - vehicle->var_B8 &= ~(1 << 1); + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) { + vehicle->var_B8 &= ~(1 << 1); + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; + } } } } @@ -2223,10 +2264,14 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { if (vehicle->velocity <= ride->lift_hill_speed * 31079) { vehicle->var_2C = 15539; if (vehicle->velocity != 0) { - if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) - vehicle->var_B8 |= (1 << 7); + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; + vehicle->var_B8 &= ~(1 << 1); + } + } + else { + vehicle->var_B8 &= ~(1 << 1); } - vehicle->var_B8 &= ~(1 << 1); } } } diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 67ebe30367..432dd63c02 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -166,8 +166,7 @@ typedef struct { uint8 num_laps; // 0xCE }; uint8 pad_CF; - uint8 var_D0; - uint8 pad_D1; + uint16 var_D0; sint8 var_D2; uint8 var_D3; uint8 var_D4; From 9e182df02568d34f2e25c212203e1b91e07a843b Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 30 Nov 2015 17:46:23 +0000 Subject: [PATCH 052/162] Labeled lost_time_out --- src/ride/vehicle.c | 6 +++--- src/ride/vehicle.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 3c4efef8e4..3b15d7c82e 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2086,7 +2086,7 @@ static void vehicle_finish_departing(rct_vehicle* vehicle) { vehicle->status = VEHICLE_STATUS_TRAVELLING; vehicle_invalidate_window(vehicle); - vehicle->var_D0 = 0; + vehicle->lost_time_out = 0; vehicle->sub_state = 1; if (vehicle->velocity < 0) @@ -2107,13 +2107,13 @@ static void vehicle_check_if_missing(rct_vehicle* vehicle) { if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_27)) return; - vehicle->var_D0++; + vehicle->lost_time_out++; if (ride->lifecycle_flags & RIDE_LIFECYCLE_11) return; uint16 limit = ride->type == RIDE_TYPE_BOAT_RIDE ? 15360 : 9600; - if (vehicle->var_D0 <= limit) + if (vehicle->lost_time_out <= limit) return; ride->lifecycle_flags |= RIDE_LIFECYCLE_11; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 432dd63c02..f6c93266eb 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -166,7 +166,7 @@ typedef struct { uint8 num_laps; // 0xCE }; uint8 pad_CF; - uint16 var_D0; + uint16 lost_time_out; // 0xD0 sint8 var_D2; uint8 var_D3; uint8 var_D4; From 5a69dd50ef2ff5326ec55e9186dec0be1e010181 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 30 Nov 2015 21:11:22 +0000 Subject: [PATCH 053/162] Implemented some of the cable lift code --- src/ride/ride.c | 2 +- src/ride/vehicle.c | 69 +++++++++++++++++++++++++++++++--------------- src/ride/vehicle.h | 6 ++-- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index 26cab45f68..7e91e111e8 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -4486,7 +4486,7 @@ bool ride_create_cable_lift(int rideIndex, bool isApplying) tail->next_vehicle_on_ride = head->sprite_index; ride->lifecycle_flags |= RIDE_LIFECYCLE_CABLE_LIFT; - sub_6DEF56(head); + sub_6DEF56(head, NULL, NULL); return true; } diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 3b15d7c82e..af2bd3b47e 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -37,11 +37,11 @@ static void vehicle_update(rct_vehicle *vehicle); -static void vehicle_ride_null_update_moving_to_end_of_station(rct_vehicle *vehicle); -static void vehicle_ride_null_update_waiting_to_depart(rct_vehicle *vehicle); -static void vehicle_ride_null_update_departing(rct_vehicle *vehicle); -static void vehicle_ride_null_update_travelling(rct_vehicle *vehicle); -static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle); +static void vehicle_update_cable_lift_moving_to_end_of_station(rct_vehicle *vehicle); +static void vehicle_update_cable_lift_waiting_to_depart(rct_vehicle *vehicle); +static void vehicle_update_cable_lift_departing(rct_vehicle *vehicle); +static void vehicle_update_cable_lift_travelling(rct_vehicle *vehicle); +static void vehicle_update_cable_lift_arriving(rct_vehicle *vehicle); static void vehicle_update_showing_film(rct_vehicle *vehicle); static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); @@ -999,22 +999,23 @@ static void vehicle_update(rct_vehicle *vehicle) rct_ride *ride; rct_ride_type *rideEntry; + // The cable lift uses the ride type of NULL if (vehicle->ride_subtype == RIDE_TYPE_NULL) { switch (vehicle->status) { case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: - vehicle_ride_null_update_moving_to_end_of_station(vehicle); + vehicle_update_cable_lift_moving_to_end_of_station(vehicle); break; case VEHICLE_STATUS_WAITING_TO_DEPART: - vehicle_ride_null_update_waiting_to_depart(vehicle); + vehicle_update_cable_lift_waiting_to_depart(vehicle); break; case VEHICLE_STATUS_DEPARTING: - vehicle_ride_null_update_departing(vehicle); + vehicle_update_cable_lift_departing(vehicle); break; case VEHICLE_STATUS_TRAVELLING: - vehicle_ride_null_update_travelling(vehicle); + vehicle_update_cable_lift_travelling(vehicle); break; case VEHICLE_STATUS_ARRIVING: - vehicle_ride_null_update_arriving(vehicle); + vehicle_update_cable_lift_arriving(vehicle); break; } return; @@ -1057,7 +1058,7 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_CRASHED: vehicle_update_crash(vehicle); break; - case VEHICLE_STATUS_TRAVELING_BUMPER_CARS: + case VEHICLE_STATUS_TRAVELLING_BUMPER_CARS: vehicle_update_bumpcar_mode(vehicle); break; case VEHICLE_STATUS_SWINGING: @@ -1093,7 +1094,7 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: case VEHICLE_STATUS_TRAVELLING_07: - case VEHICLE_STATUS_TRAVELLING_15: + case VEHICLE_STATUS_TRAVELLING_CABLE_LIFT: { int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->sub_state << 8) | ride->mode, (int)vehicle, 0, 0); @@ -1112,27 +1113,48 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_sound(vehicle); } -static void vehicle_ride_null_update_moving_to_end_of_station(rct_vehicle *vehicle) +static void vehicle_update_cable_lift_moving_to_end_of_station(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF8A4, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_ride_null_update_waiting_to_depart(rct_vehicle *vehicle) +static void vehicle_update_cable_lift_waiting_to_depart(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF8F1, 0, 0, 0, 0, (int)vehicle, 0, 0); } -static void vehicle_ride_null_update_departing(rct_vehicle *vehicle) +static void vehicle_update_cable_lift_departing(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006DF97A, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle->sub_state++; + if (vehicle->sub_state < 16) + return; + + rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); + vehicle->status = VEHICLE_STATUS_TRAVELLING; + passengerVehicle->status = VEHICLE_STATUS_TRAVELLING_CABLE_LIFT; } -static void vehicle_ride_null_update_travelling(rct_vehicle *vehicle) +static void vehicle_update_cable_lift_travelling(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006DF99C, 0, 0, 0, 0, (int)vehicle, 0, 0); + rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); + + vehicle->velocity = min(passengerVehicle->velocity, 439800); + vehicle->var_2C = 0; + if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) + return; + + int eax = 0; + sub_6DEF56(vehicle, &eax, NULL); + if (!(eax & (1 << 1))) + return; + + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle->sub_state = 0; } -static void vehicle_ride_null_update_arriving(rct_vehicle *vehicle) +static void vehicle_update_cable_lift_arriving(rct_vehicle *vehicle) { vehicle->sub_state++; if (vehicle->sub_state >= 64) @@ -1595,7 +1617,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { switch (ride->mode) { case RIDE_MODE_BUMPERCAR: - vehicle->status = VEHICLE_STATUS_TRAVELING_BUMPER_CARS; + vehicle->status = VEHICLE_STATUS_TRAVELLING_BUMPER_CARS; vehicle_invalidate_window(vehicle); // Bumper mode uses sub_state / var_CE to tell how long // the vehicle has been ridden. @@ -3277,9 +3299,12 @@ int vehicle_is_used_in_pairs(rct_vehicle *vehicle) * * rct2: 0x006DEF56 */ -void sub_6DEF56(rct_vehicle *cableLift) +void sub_6DEF56(rct_vehicle *cableLift, int* eax, int* ebx) { - RCT2_CALLPROC_X(0x006DEF56, 0, 0, 0, 0, (int)cableLift, 0, 0); + int _eax, _ebx, ecx, edx, ebp, edi; + RCT2_CALLFUNC_X(0x006DEF56, &_eax, &_ebx, &ecx, &edx, (int*)&cableLift, &edi, &ebp); + if (eax != NULL)*eax = _eax; + if (ebx != NULL)*ebx = _ebx; } rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head) diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index f6c93266eb..fc666dc8c1 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -193,7 +193,7 @@ enum { VEHICLE_STATUS_TRAVELLING_07, VEHICLE_STATUS_CRASHING, VEHICLE_STATUS_CRASHED, - VEHICLE_STATUS_TRAVELING_BUMPER_CARS, + VEHICLE_STATUS_TRAVELLING_BUMPER_CARS, VEHICLE_STATUS_SWINGING, VEHICLE_STATUS_ROTATING, VEHICLE_STATUS_FERRIS_WHEEL_ROTATING, @@ -205,7 +205,7 @@ enum { VEHICLE_STATUS_DOING_CIRCUS_SHOW, VEHICLE_STATUS_CROOKED_HOUSE_OPERATING, VEHICLE_STATUS_WAITING_FOR_CABLE_LIFT, - VEHICLE_STATUS_TRAVELLING_15, + VEHICLE_STATUS_TRAVELLING_CABLE_LIFT, VEHICLE_STATUS_STOPPING, VEHICLE_STATUS_WAITING_FOR_PASSENGERS_17, VEHICLE_STATUS_WAITING_TO_START, @@ -280,7 +280,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG); void vehicle_set_map_toolbar(rct_vehicle *vehicle); int vehicle_is_used_in_pairs(rct_vehicle *vehicle); rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); -void sub_6DEF56(rct_vehicle *cableLift); +void sub_6DEF56(rct_vehicle *cableLift, int* eax, int* ebx); rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head); bool sub_6DD365(rct_vehicle *vehicle); int sub_6DAB4C(rct_vehicle *vehicle, int *outStation); From 9561f879036c10658e98d6cecead2dcb040076fe Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 2 Dec 2015 19:45:51 +0000 Subject: [PATCH 054/162] Implement cable lift waiting to depart --- src/ride/vehicle.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index af2bd3b47e..1dfd364105 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1113,16 +1113,44 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_sound(vehicle); } +/* rct2: 0x006DF8A4 */ static void vehicle_update_cable_lift_moving_to_end_of_station(rct_vehicle *vehicle) { RCT2_CALLPROC_X(0x006DF8A4, 0, 0, 0, 0, (int)vehicle, 0, 0); } +/* rct2: 0x006DF8F1 */ static void vehicle_update_cable_lift_waiting_to_depart(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006DF8F1, 0, 0, 0, 0, (int)vehicle, 0, 0); + if (vehicle->velocity >= -58640) + vehicle->var_2C = -14660; + + if (vehicle->velocity < -58640) { + vehicle->velocity -= vehicle->velocity / 16; + vehicle->var_2C = 0; + } + + sub_6DEF56(vehicle, NULL, NULL); + + // Next check to see if the second part of the cable lift + // is at the front of the passenger vehicle to simulate the + // cable being attached underneath the train. + rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); + rct_vehicle* cableLiftSecondPart = GET_VEHICLE(vehicle->prev_vehicle_on_ride); + + sint16 dist_x = abs(passengerVehicle->x - cableLiftSecondPart->x); + sint16 dist_y = abs(passengerVehicle->y - cableLiftSecondPart->y); + + if (dist_x + dist_y > 2) + return; + + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 0; } +/* rct2: 0x006DF97A */ static void vehicle_update_cable_lift_departing(rct_vehicle *vehicle) { vehicle->sub_state++; @@ -1134,6 +1162,7 @@ static void vehicle_update_cable_lift_departing(rct_vehicle *vehicle) passengerVehicle->status = VEHICLE_STATUS_TRAVELLING_CABLE_LIFT; } +/* rct2: 0x006DF99C */ static void vehicle_update_cable_lift_travelling(rct_vehicle *vehicle) { rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); @@ -1154,6 +1183,7 @@ static void vehicle_update_cable_lift_travelling(rct_vehicle *vehicle) vehicle->sub_state = 0; } +/* rct2: 0x006DF9F0 */ static void vehicle_update_cable_lift_arriving(rct_vehicle *vehicle) { vehicle->sub_state++; From 2d2c419d605841f048d58276a185a2df58a42d6f Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 2 Dec 2015 22:48:14 +0000 Subject: [PATCH 055/162] Implemented cable lift move to end of station --- src/ride/vehicle.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 1dfd364105..60a9c3468b 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1005,6 +1005,9 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: vehicle_update_cable_lift_moving_to_end_of_station(vehicle); break; + case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: + // Stays in this state until a train puts it into next state + break; case VEHICLE_STATUS_WAITING_TO_DEPART: vehicle_update_cable_lift_waiting_to_depart(vehicle); break; @@ -1116,7 +1119,23 @@ static void vehicle_update(rct_vehicle *vehicle) /* rct2: 0x006DF8A4 */ static void vehicle_update_cable_lift_moving_to_end_of_station(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006DF8A4, 0, 0, 0, 0, (int)vehicle, 0, 0); + if (vehicle->velocity >= -439800) + vehicle->var_2C = -2932; + + if (vehicle->velocity < -439800) { + vehicle->velocity -= vehicle->velocity / 16; + vehicle->var_2C = 0; + } + + int flags; + sub_6DEF56(vehicle, &flags, NULL); + + if (!(flags & (1 << 0))) + return; + + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; } /* rct2: 0x006DF8F1 */ @@ -3331,7 +3350,7 @@ int vehicle_is_used_in_pairs(rct_vehicle *vehicle) */ void sub_6DEF56(rct_vehicle *cableLift, int* eax, int* ebx) { - int _eax, _ebx, ecx, edx, ebp, edi; + int _eax = 0, _ebx = 0, ecx = 0, edx = 0, ebp = 0, edi = 0; RCT2_CALLFUNC_X(0x006DEF56, &_eax, &_ebx, &ecx, &edx, (int*)&cableLift, &edi, &ebp); if (eax != NULL)*eax = _eax; if (ebx != NULL)*ebx = _ebx; From 2cbbf52a1b129148f431901fca6a2cf8ffb7438f Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 3 Dec 2015 18:43:11 +0000 Subject: [PATCH 056/162] Implemented start of cableLift update --- src/ride/ride.c | 2 +- src/ride/vehicle.c | 56 +++++++++++++++++++++++++++++++++++----------- src/ride/vehicle.h | 2 +- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index 7e91e111e8..26cab45f68 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -4486,7 +4486,7 @@ bool ride_create_cable_lift(int rideIndex, bool isApplying) tail->next_vehicle_on_ride = head->sprite_index; ride->lifecycle_flags |= RIDE_LIFECYCLE_CABLE_LIFT; - sub_6DEF56(head, NULL, NULL); + sub_6DEF56(head); return true; } diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 60a9c3468b..6aabdc3220 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1127,10 +1127,7 @@ static void vehicle_update_cable_lift_moving_to_end_of_station(rct_vehicle *vehi vehicle->var_2C = 0; } - int flags; - sub_6DEF56(vehicle, &flags, NULL); - - if (!(flags & (1 << 0))) + if (!(sub_6DEF56(vehicle) & (1 << 0))) return; vehicle->velocity = 0; @@ -1149,7 +1146,7 @@ static void vehicle_update_cable_lift_waiting_to_depart(rct_vehicle *vehicle) vehicle->var_2C = 0; } - sub_6DEF56(vehicle, NULL, NULL); + sub_6DEF56(vehicle); // Next check to see if the second part of the cable lift // is at the front of the passenger vehicle to simulate the @@ -1191,9 +1188,7 @@ static void vehicle_update_cable_lift_travelling(rct_vehicle *vehicle) if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) return; - int eax = 0; - sub_6DEF56(vehicle, &eax, NULL); - if (!(eax & (1 << 1))) + if (!(sub_6DEF56(vehicle) & (1 << 1))) return; vehicle->velocity = 0; @@ -3348,12 +3343,47 @@ int vehicle_is_used_in_pairs(rct_vehicle *vehicle) * * rct2: 0x006DEF56 */ -void sub_6DEF56(rct_vehicle *cableLift, int* eax, int* ebx) +int sub_6DEF56(rct_vehicle *cableLift) { - int _eax = 0, _ebx = 0, ecx = 0, edx = 0, ebp = 0, edi = 0; - RCT2_CALLFUNC_X(0x006DEF56, &_eax, &_ebx, &ecx, &edx, (int*)&cableLift, &edi, &ebp); - if (eax != NULL)*eax = _eax; - if (ebx != NULL)*ebx = _ebx; + rct_ride_type* rideEntry = GET_RIDE_ENTRY(cableLift->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[cableLift->vehicle_type]; + rct_ride* ride = GET_RIDE(cableLift->ride); + + RCT2_GLOBAL(0x00F64E2C, uint8) = 0; + RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = cableLift; + RCT2_GLOBAL(0x00F64E18, uint32) = 0; + RCT2_GLOBAL(0x00F64E1C, uint32) = (uint32)-1; + + // After -1 assignment + cableLift->velocity += cableLift->var_2C; + RCT2_GLOBAL(0x00F64E08, sint32) = cableLift->velocity; + RCT2_GLOBAL(0x00F64E0C, sint32) = (cableLift->velocity / 1024) * 42; + + rct_vehicle* frontVehicle = cableLift; + if (cableLift->velocity < 0) { + frontVehicle = vehicle_get_tail(cableLift); + } + + RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = frontVehicle; + + rct_vehicle* vehicle = frontVehicle; + // start of loop + vehicle->var_2C = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32) = 1; + vehicle->var_24 += RCT2_GLOBAL(0x00F64E0C, sint32); + + if (vehicle->var_24 < 0) { + //6df203 + } + + if (vehicle->var_24 < 13962) { + // 6df413 (basically loops) + } + //6df002 + + int eax = 0, ebx = 0, ecx = 0, edx = 0, ebp = 0, edi = 0; + RCT2_CALLFUNC_X(0x006DEF56, &eax, &ebx, &ecx, &edx, (int*)&cableLift, &edi, &ebp); + return eax; } rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head) diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index fc666dc8c1..644e8aae4e 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -280,7 +280,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG); void vehicle_set_map_toolbar(rct_vehicle *vehicle); int vehicle_is_used_in_pairs(rct_vehicle *vehicle); rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); -void sub_6DEF56(rct_vehicle *cableLift, int* eax, int* ebx); +int sub_6DEF56(rct_vehicle *cableLift); rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head); bool sub_6DD365(rct_vehicle *vehicle); int sub_6DAB4C(rct_vehicle *vehicle, int *outStation); From a059f87805bde6af03f47d674547d6f37fb683af Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 5 Dec 2015 12:05:15 +0000 Subject: [PATCH 057/162] Implement more of cableLift update --- src/ride/vehicle.c | 110 ++++++++++++++++++++++++++++++++++++++++++++- src/world/map.c | 22 +++++++++ src/world/map.h | 1 + 3 files changed, 132 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 6aabdc3220..57ad8daa45 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -68,6 +68,15 @@ static int vehicle_update_scream_sound(rct_vehicle *vehicle); #define NO_SCREAM 254 +typedef struct { + uint16 x; // 0x00 + uint16 y; // 0x02 + uint16 z; // 0x04 + uint8 direction; // 0x06 + uint8 var_07; + uint8 var_08; +} rct_vehicle_info; + const uint8 byte_9A3A14[] = { SOUND_SCREAM_8, SOUND_SCREAM_1 }; const uint8 byte_9A3A16[] = { SOUND_SCREAM_1, SOUND_SCREAM_6 }; const uint8 byte_9A3A18[] = { @@ -75,6 +84,13 @@ const uint8 byte_9A3A18[] = { SOUND_SCREAM_7, SOUND_SCREAM_2, SOUND_SCREAM_4, SOUND_LIFT_1 }; +static const rct_vehicle_info *vehicle_get_move_info(int cd, int typeAndDirection, int offset) +{ + const rct_vehicle_info **infoListList = RCT2_ADDRESS(0x008B8F30, rct_vehicle_info**)[cd]; + const rct_vehicle_info *infoList = infoListList[typeAndDirection]; + return &infoList[offset]; +} + /** * * rct2: 0x006BB9FF @@ -3379,7 +3395,99 @@ int sub_6DEF56(rct_vehicle *cableLift) if (vehicle->var_24 < 13962) { // 6df413 (basically loops) } - //6df002 + + rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; + invalidate_sprite_2((rct_sprite*)vehicle); + + // 6df01a loop + uint8 trackType = vehicle->track_type >> 2; + if (trackType == TRACK_ELEM_CABLE_LIFT_HILL || + vehicle->var_34 == 160) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); + } + + uint16 var_34 = vehicle->var_34 + 1; + + const rct_vehicle_info *moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); + uint16 unk16 = *((uint16*)((int)moveInfo - 2)); + if (var_34 >= unk16) { + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + rct_map_element* trackElement = + map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z, + trackType, + 0); + + rct_xy_element input; + rct_xy_element output; + int outputZ; + int outputDirection; + + input.x = vehicle->x; + input.y = vehicle->y; + input.element = trackElement; + + if (track_block_get_next(&input, &output, &outputZ, &outputDirection)) { + if (gTrackDefinitions[output.element->properties.track.type].vangle_start == RCT2_GLOBAL(0x00F64E36, uint8) && + gTrackDefinitions[output.element->properties.track.type].bank_start == RCT2_GLOBAL(0x00F64E37, uint8)) { + + vehicle->track_x = output.x; + vehicle->track_y = output.y; + vehicle->track_z = outputZ; + vehicle->track_direction = outputDirection; + vehicle->track_type |= output.element->properties.track.type << 2; + var_34 = 0; + } + else { + //6df1e6 + } + } + else { + //6df1e6 + } + } + + vehicle->var_34 = var_34; + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, var_34); + rct_xyz16 unk = { + .x = moveInfo->x, + .y = moveInfo->y, + .z = moveInfo->z + }; + + unk.x += vehicle->track_x; + unk.y += vehicle->track_y; + unk.z += vehicle->track_z; + + uint8 bx = 0; + unk.z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); + if (unk.x != unk_F64E20->x) + bx |= (1 << 0); + if (unk.y != unk_F64E20->y) + bx |= (1 << 1); + if (unk.z != unk_F64E20->z) + bx |= (1 << 2); + + vehicle->var_24 -= RCT2_ADDRESS(0x009A2930, uint32)[bx]; + unk_F64E20->x = unk.x; + unk_F64E20->y = unk.y; + unk_F64E20->z = unk.z; + + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + vehicle->var_1F = moveInfo->var_07; + + if (vehicle->var_24 >= 13962) { + vehicle->var_2C = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + // jmp 6df01a + } int eax = 0, ebx = 0, ecx = 0, edx = 0, ebp = 0, edi = 0; RCT2_CALLFUNC_X(0x006DEF56, &eax, &ebx, &ecx, &edx, (int*)&cableLift, &edi, &ebp); diff --git a/src/world/map.c b/src/world/map.c index 6e285f9a11..00a3b6b009 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -5011,3 +5011,25 @@ rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int track return NULL; } +/** + * Gets the track element at x, y, z that is the given track type and sequence. + * @param x x units, not tiles. + * @param y y units, not tiles. + * @param z Base height. + * @param trackType + * @param sequence + */ +rct_map_element *map_get_track_element_at_of_type_seq(int x, int y, int z, int trackType, int sequence) +{ + rct_map_element *mapElement = map_get_first_element_at(x >> 5, y >> 5); + do { + if (map_element_get_type(mapElement) != MAP_ELEMENT_TYPE_TRACK) continue; + if (mapElement->base_height != z) continue; + if (mapElement->properties.track.type != trackType) continue; + if ((mapElement->properties.track.sequence & 0x0F) != sequence) continue; + + return mapElement; + } while (!map_element_is_last_for_tile(mapElement++)); + + return NULL; +} \ No newline at end of file diff --git a/src/world/map.h b/src/world/map.h index d2db49fefa..3bd38ee1ff 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -392,5 +392,6 @@ bool map_large_scenery_get_origin( rct_map_element *map_get_track_element_at(int x, int y, int z); rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int trackType); +rct_map_element *map_get_track_element_at_of_type_seq(int x, int y, int z, int trackType, int sequence); #endif From 33a156041943ba91a6519d497a9f79a0413c898e Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 6 Dec 2015 10:45:32 +0000 Subject: [PATCH 058/162] Implement more of cable lift update. Still requires proper linking up --- src/ride/vehicle.c | 345 ++++++++++++++++++++++++++++++++------------- 1 file changed, 247 insertions(+), 98 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 57ad8daa45..bf18618744 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3355,6 +3355,183 @@ int vehicle_is_used_in_pairs(rct_vehicle *vehicle) return vehicle->num_seats & VEHICLE_SEAT_PAIR_FLAG; } +bool sub_6DF01A_loop(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); + + for (; vehicle->var_24 >= 13962; RCT2_GLOBAL(0x00F64E10, uint32)++) { + uint8 trackType = vehicle->track_type >> 2; + if (trackType == TRACK_ELEM_CABLE_LIFT_HILL || + vehicle->var_34 == 160) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); + } + + uint16 var_34 = vehicle->var_34 + 1; + + const rct_vehicle_info *moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); + uint16 unk16 = *((uint16*)((int)moveInfo - 2)); + if (var_34 >= unk16) { + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + rct_map_element* trackElement = + map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z, + trackType, + 0); + + rct_xy_element input; + rct_xy_element output; + int outputZ; + int outputDirection; + + input.x = vehicle->x; + input.y = vehicle->y; + input.element = trackElement; + + if (!track_block_get_next(&input, &output, &outputZ, &outputDirection)) + return false; + + if (gTrackDefinitions[output.element->properties.track.type].vangle_start != RCT2_GLOBAL(0x00F64E36, uint8) || + gTrackDefinitions[output.element->properties.track.type].bank_start != RCT2_GLOBAL(0x00F64E37, uint8)) + return false; + + vehicle->track_x = output.x; + vehicle->track_y = output.y; + vehicle->track_z = outputZ; + vehicle->track_direction = outputDirection; + vehicle->track_type |= output.element->properties.track.type << 2; + var_34 = 0; + } + + vehicle->var_34 = var_34; + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, var_34); + rct_xyz16 unk = { + .x = moveInfo->x, + .y = moveInfo->y, + .z = moveInfo->z + }; + + unk.x += vehicle->track_x; + unk.y += vehicle->track_y; + unk.z += vehicle->track_z; + + uint8 bx = 0; + unk.z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); + if (unk.x != unk_F64E20->x) + bx |= (1 << 0); + if (unk.y != unk_F64E20->y) + bx |= (1 << 1); + if (unk.z != unk_F64E20->z) + bx |= (1 << 2); + + vehicle->var_24 -= RCT2_ADDRESS(0x009A2930, uint32)[bx]; + unk_F64E20->x = unk.x; + unk_F64E20->y = unk.y; + unk_F64E20->z = unk.z; + + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + vehicle->var_1F = moveInfo->var_07; + + if (vehicle->var_24 >= 13962) { + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + } + } + return true; +} + +bool sub_6DF21B_loop(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); + + for (; (sint16)vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { + uint16 var_34 = vehicle->var_34 - 1; + const rct_vehicle_info *moveInfo; + + if ((sint16)var_34 == -1) { + uint8 trackType = vehicle->track_type >> 2; + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_start; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_start; + rct_map_element* trackElement = + map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z, + trackType, + 0); + + rct_xy_element input; + rct_xy_element output; + int outputZ; + int outputDirection; + + input.x = vehicle->track_x; + input.y = vehicle->track_y; + input.element = trackElement; + + if (!track_block_get_previous(&input, &output, &outputZ, &outputDirection)) + return false; + + if (gTrackDefinitions[output.element->properties.track.type].vangle_end != RCT2_GLOBAL(0x00F64E36, uint8) || + gTrackDefinitions[output.element->properties.track.type].bank_end != RCT2_GLOBAL(0x00F64E37, uint8)) + return false; + + vehicle->track_x = output.x; + vehicle->track_y = output.y; + vehicle->track_z = outputZ; + vehicle->track_direction = outputDirection; + vehicle->track_type |= output.element->properties.track.type << 2; + + if (output.element->properties.track.type == TRACK_ELEM_END_STATION) { + RCT2_GLOBAL(0x00F64E18, uint32) = (1 << 0); + } + + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); + uint16 unk16 = *((uint16*)((int)moveInfo - 2)); + var_34 = unk16 - 1; + } + vehicle->var_34 = var_34; + + + vehicle->var_34 = var_34; + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, var_34); + rct_xyz16 unk = { + .x = moveInfo->x, + .y = moveInfo->y, + .z = moveInfo->z + }; + + unk.x += vehicle->track_x; + unk.y += vehicle->track_y; + unk.z += vehicle->track_z; + + uint8 bx = 0; + unk.z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); + if (unk.x != unk_F64E20->x) + bx |= (1 << 0); + if (unk.y != unk_F64E20->y) + bx |= (1 << 1); + if (unk.z != unk_F64E20->z) + bx |= (1 << 2); + + vehicle->var_24 += RCT2_ADDRESS(0x009A2930, uint32)[bx]; + unk_F64E20->x = unk.x; + unk_F64E20->y = unk.y; + unk_F64E20->z = unk.z; + + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + vehicle->var_1F = moveInfo->var_07; + + if ((sint32)vehicle->var_24 < 0) { + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + } + } + return true; +} + /** * * rct2: 0x006DEF56 @@ -3382,116 +3559,88 @@ int sub_6DEF56(rct_vehicle *cableLift) RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = frontVehicle; - rct_vehicle* vehicle = frontVehicle; - // start of loop - vehicle->var_2C = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; - RCT2_GLOBAL(0x00F64E10, uint32) = 1; - vehicle->var_24 += RCT2_GLOBAL(0x00F64E0C, sint32); + for (rct_vehicle* vehicle = frontVehicle;;) { + vehicle->var_2C = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32) = 1; + vehicle->var_24 += RCT2_GLOBAL(0x00F64E0C, sint32); - if (vehicle->var_24 < 0) { - //6df203 - } + if (vehicle->var_24 < 0 || vehicle->var_24 >= 13962) { + rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; + invalidate_sprite_2((rct_sprite*)vehicle); - if (vehicle->var_24 < 13962) { - // 6df413 (basically loops) - } - - rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); - unk_F64E20->x = vehicle->x; - unk_F64E20->y = vehicle->y; - unk_F64E20->z = vehicle->z; - invalidate_sprite_2((rct_sprite*)vehicle); - - // 6df01a loop - uint8 trackType = vehicle->track_type >> 2; - if (trackType == TRACK_ELEM_CABLE_LIFT_HILL || - vehicle->var_34 == 160) { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); - } - - uint16 var_34 = vehicle->var_34 + 1; - - const rct_vehicle_info *moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); - uint16 unk16 = *((uint16*)((int)moveInfo - 2)); - if (var_34 >= unk16) { - RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; - RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; - rct_map_element* trackElement = - map_get_track_element_at_of_type_seq( - vehicle->track_x, - vehicle->track_y, - vehicle->track_z, - trackType, - 0); - - rct_xy_element input; - rct_xy_element output; - int outputZ; - int outputDirection; - - input.x = vehicle->x; - input.y = vehicle->y; - input.element = trackElement; - - if (track_block_get_next(&input, &output, &outputZ, &outputDirection)) { - if (gTrackDefinitions[output.element->properties.track.type].vangle_start == RCT2_GLOBAL(0x00F64E36, uint8) && - gTrackDefinitions[output.element->properties.track.type].bank_start == RCT2_GLOBAL(0x00F64E37, uint8)) { - - vehicle->track_x = output.x; - vehicle->track_y = output.y; - vehicle->track_z = outputZ; - vehicle->track_direction = outputDirection; - vehicle->track_type |= output.element->properties.track.type << 2; - var_34 = 0; + if ((sint32)vehicle->var_24 < 0) { + if (sub_6DF21B_loop(vehicle) == false) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 - 13962; + vehicle->var_24 = 13962; + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + //goto 6df01a loop (forwards loop) + } + //rejoins after forward loop } - else { - //6df1e6 + + if (sub_6DF01A_loop(vehicle) == false) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 + 1; + vehicle->var_24 = (uint32)-1; + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + //goto 6df21b loop (backwards loop) } + // backwards and forwards loops end here + sprite_move( + unk_F64E20->x, + unk_F64E20->y, + unk_F64E20->z, + (rct_sprite*)vehicle); + + invalidate_sprite_2((rct_vehicle*)vehicle); + } + vehicle->var_2C /= RCT2_GLOBAL(0x00F64E10, uint32); + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { + if (vehicle->next_vehicle_on_train == 0xFFFF) + break; + vehicle = GET_VEHICLE(vehicle->next_vehicle_on_train); } else { - //6df1e6 + if (vehicle == cableLift) + break; + vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); } } - vehicle->var_34 = var_34; - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, var_34); - rct_xyz16 unk = { - .x = moveInfo->x, - .y = moveInfo->y, - .z = moveInfo->z - }; + uint32 vehicleCount = 0; + uint16 frictionTotal = 0; + uint16 var2CTotal = 0; - unk.x += vehicle->track_x; - unk.y += vehicle->track_y; - unk.z += vehicle->track_z; - - uint8 bx = 0; - unk.z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); - if (unk.x != unk_F64E20->x) - bx |= (1 << 0); - if (unk.y != unk_F64E20->y) - bx |= (1 << 1); - if (unk.z != unk_F64E20->z) - bx |= (1 << 2); - - vehicle->var_24 -= RCT2_ADDRESS(0x009A2930, uint32)[bx]; - unk_F64E20->x = unk.x; - unk_F64E20->y = unk.y; - unk_F64E20->z = unk.z; - - vehicle->sprite_direction = moveInfo->direction; - vehicle->var_20 = moveInfo->var_08; - vehicle->var_1F = moveInfo->var_07; - - if (vehicle->var_24 >= 13962) { - vehicle->var_2C = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; - RCT2_GLOBAL(0x00F64E10, uint32)++; - // jmp 6df01a + for (uint16 spriteId = cableLift->sprite_index; spriteId != 0xFFFF;) { + rct_vehicle* vehicle = GET_VEHICLE(spriteId); + vehicleCount++; + frictionTotal += vehicle->friction; + var2CTotal += vehicle->var_2C; + spriteId = vehicle->next_vehicle_on_train; } - int eax = 0, ebx = 0, ecx = 0, edx = 0, ebp = 0, edi = 0; - RCT2_CALLFUNC_X(0x006DEF56, &eax, &ebx, &ecx, &edx, (int*)&cableLift, &edi, &ebp); - return eax; + sint32 ecx = (var2CTotal / vehicleCount) >> 9; + ecx -= cableLift->velocity >> 12; + + sint32 edx = cableLift->velocity >> 8; + edx *= edx; + if (cableLift->velocity < 0) + edx = -edx; + edx >>= 4; + ecx -= edx / frictionTotal; + + cableLift->var_2C = ecx; + return RCT2_GLOBAL(0x00F64E18, uint32); + + //int eax = 0, ebx = 0, ecx = 0, edx = 0, ebp = 0, edi = 0; + //RCT2_CALLFUNC_X(0x006DEF56, &eax, &ebx, &ecx, &edx, (int*)&cableLift, &edi, &ebp); + //return eax; } rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head) From 2e40ad2a35a3fcf8c8b877eafba49ee73f3e83c8 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 6 Dec 2015 17:04:57 +0000 Subject: [PATCH 059/162] Link up cable lift update code. Fix some bugs --- src/ride/vehicle.c | 81 ++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index bf18618744..be88ec1977 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3361,7 +3361,7 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { for (; vehicle->var_24 >= 13962; RCT2_GLOBAL(0x00F64E10, uint32)++) { uint8 trackType = vehicle->track_type >> 2; - if (trackType == TRACK_ELEM_CABLE_LIFT_HILL || + if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle->var_34 == 160) { RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); } @@ -3377,7 +3377,7 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { map_get_track_element_at_of_type_seq( vehicle->track_x, vehicle->track_y, - vehicle->track_z, + vehicle->track_z / 8, trackType, 0); @@ -3386,8 +3386,8 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { int outputZ; int outputDirection; - input.x = vehicle->x; - input.y = vehicle->y; + input.x = vehicle->track_x; + input.y = vehicle->track_y; input.element = trackElement; if (!track_block_get_next(&input, &output, &outputZ, &outputDirection)) @@ -3426,7 +3426,7 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { if (unk.z != unk_F64E20->z) bx |= (1 << 2); - vehicle->var_24 -= RCT2_ADDRESS(0x009A2930, uint32)[bx]; + vehicle->var_24 -= RCT2_ADDRESS(0x009A2930, sint32)[bx]; unk_F64E20->x = unk.x; unk_F64E20->y = unk.y; unk_F64E20->z = unk.z; @@ -3458,33 +3458,31 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { map_get_track_element_at_of_type_seq( vehicle->track_x, vehicle->track_y, - vehicle->track_z, + vehicle->track_z / 8, trackType, 0); rct_xy_element input; - rct_xy_element output; - int outputZ; - int outputDirection; input.x = vehicle->track_x; input.y = vehicle->track_y; input.element = trackElement; + track_begin_end output; - if (!track_block_get_previous(&input, &output, &outputZ, &outputDirection)) + if (!track_block_get_previous(input.x, input.y, input.element, &output)) return false; - if (gTrackDefinitions[output.element->properties.track.type].vangle_end != RCT2_GLOBAL(0x00F64E36, uint8) || - gTrackDefinitions[output.element->properties.track.type].bank_end != RCT2_GLOBAL(0x00F64E37, uint8)) + if (gTrackDefinitions[output.begin_element->properties.track.type].vangle_end != RCT2_GLOBAL(0x00F64E36, uint8) || + gTrackDefinitions[output.begin_element->properties.track.type].bank_end != RCT2_GLOBAL(0x00F64E37, uint8)) return false; - vehicle->track_x = output.x; - vehicle->track_y = output.y; - vehicle->track_z = outputZ; - vehicle->track_direction = outputDirection; - vehicle->track_type |= output.element->properties.track.type << 2; + vehicle->track_x = output.begin_x; + vehicle->track_y = output.begin_y; + vehicle->track_z = output.begin_z; + vehicle->track_direction = output.begin_direction; + vehicle->track_type |= output.begin_element->properties.track.type << 2; - if (output.element->properties.track.type == TRACK_ELEM_END_STATION) { + if (output.begin_element->properties.track.type == TRACK_ELEM_END_STATION) { RCT2_GLOBAL(0x00F64E18, uint32) = (1 << 0); } @@ -3516,7 +3514,7 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { if (unk.z != unk_F64E20->z) bx |= (1 << 2); - vehicle->var_24 += RCT2_ADDRESS(0x009A2930, uint32)[bx]; + vehicle->var_24 += RCT2_ADDRESS(0x009A2930, sint32)[bx]; unk_F64E20->x = unk.x; unk_F64E20->y = unk.y; unk_F64E20->z = unk.z; @@ -3547,7 +3545,6 @@ int sub_6DEF56(rct_vehicle *cableLift) RCT2_GLOBAL(0x00F64E18, uint32) = 0; RCT2_GLOBAL(0x00F64E1C, uint32) = (uint32)-1; - // After -1 assignment cableLift->velocity += cableLift->var_2C; RCT2_GLOBAL(0x00F64E08, sint32) = cableLift->velocity; RCT2_GLOBAL(0x00F64E0C, sint32) = (cableLift->velocity / 1024) * 42; @@ -3571,27 +3568,33 @@ int sub_6DEF56(rct_vehicle *cableLift) unk_F64E20->z = vehicle->z; invalidate_sprite_2((rct_sprite*)vehicle); - if ((sint32)vehicle->var_24 < 0) { - if (sub_6DF21B_loop(vehicle) == false) { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); - RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 - 13962; - vehicle->var_24 = 13962; - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; - RCT2_GLOBAL(0x00F64E10, uint32)++; - //goto 6df01a loop (forwards loop) + while (true) { + if ((sint32)vehicle->var_24 < 0) { + if (sub_6DF21B_loop(vehicle) == true) { + break; + } + else { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 - 13962; + vehicle->var_24 = 13962; + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + continue; + } + } + else { + if (sub_6DF01A_loop(vehicle) == true) { + break; + } + else { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 + 1; + vehicle->var_24 = (uint32)-1; + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + } } - //rejoins after forward loop } - - if (sub_6DF01A_loop(vehicle) == false) { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); - RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 + 1; - vehicle->var_24 = (uint32)-1; - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; - RCT2_GLOBAL(0x00F64E10, uint32)++; - //goto 6df21b loop (backwards loop) - } - // backwards and forwards loops end here sprite_move( unk_F64E20->x, unk_F64E20->y, From 80f034251e8969f3518adfd9b55e34e794da118c Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 6 Dec 2015 17:14:46 +0000 Subject: [PATCH 060/162] Fix remaining bugs in cable lift and warnings --- src/ride/vehicle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index be88ec1977..c2afee3ee7 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3446,7 +3446,7 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); - for (; (sint16)vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { + for (; (sint32)vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { uint16 var_34 = vehicle->var_34 - 1; const rct_vehicle_info *moveInfo; @@ -3601,7 +3601,7 @@ int sub_6DEF56(rct_vehicle *cableLift) unk_F64E20->z, (rct_sprite*)vehicle); - invalidate_sprite_2((rct_vehicle*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); } vehicle->var_2C /= RCT2_GLOBAL(0x00F64E10, uint32); if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { @@ -3618,7 +3618,7 @@ int sub_6DEF56(rct_vehicle *cableLift) uint32 vehicleCount = 0; uint16 frictionTotal = 0; - uint16 var2CTotal = 0; + sint32 var2CTotal = 0; for (uint16 spriteId = cableLift->sprite_index; spriteId != 0xFFFF;) { rct_vehicle* vehicle = GET_VEHICLE(spriteId); From e09e00c931d749804bc5c07e66b37e8220d5ba1d Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 8 Dec 2015 23:19:40 +0000 Subject: [PATCH 061/162] Label track_progress offset. Name cable lift motion update --- src/ride/ride.c | 2 +- src/ride/vehicle.c | 38 ++++++++++++++++++-------------------- src/ride/vehicle.h | 4 ++-- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index 26cab45f68..52bfbd5300 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -4486,7 +4486,7 @@ bool ride_create_cable_lift(int rideIndex, bool isApplying) tail->next_vehicle_on_ride = head->sprite_index; ride->lifecycle_flags |= RIDE_LIFECYCLE_CABLE_LIFT; - sub_6DEF56(head); + vehicle_update_track_motion_cable_lift(head); return true; } diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index c2afee3ee7..5847fadc9f 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1143,7 +1143,7 @@ static void vehicle_update_cable_lift_moving_to_end_of_station(rct_vehicle *vehi vehicle->var_2C = 0; } - if (!(sub_6DEF56(vehicle) & (1 << 0))) + if (!(vehicle_update_track_motion_cable_lift(vehicle) & (1 << 0))) return; vehicle->velocity = 0; @@ -1162,7 +1162,7 @@ static void vehicle_update_cable_lift_waiting_to_depart(rct_vehicle *vehicle) vehicle->var_2C = 0; } - sub_6DEF56(vehicle); + vehicle_update_track_motion_cable_lift(vehicle); // Next check to see if the second part of the cable lift // is at the front of the passenger vehicle to simulate the @@ -1204,7 +1204,7 @@ static void vehicle_update_cable_lift_travelling(rct_vehicle *vehicle) if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) return; - if (!(sub_6DEF56(vehicle) & (1 << 1))) + if (!(vehicle_update_track_motion_cable_lift(vehicle) & (1 << 1))) return; vehicle->velocity = 0; @@ -3362,15 +3362,15 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { for (; vehicle->var_24 >= 13962; RCT2_GLOBAL(0x00F64E10, uint32)++) { uint8 trackType = vehicle->track_type >> 2; if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && - vehicle->var_34 == 160) { + vehicle->track_progress == 160) { RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); } - uint16 var_34 = vehicle->var_34 + 1; + uint16 trackProgress = vehicle->track_progress + 1; const rct_vehicle_info *moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); - uint16 unk16 = *((uint16*)((int)moveInfo - 2)); - if (var_34 >= unk16) { + uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); + if (trackProgress >= trackTotalProgress) { RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; rct_map_element* trackElement = @@ -3402,11 +3402,11 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { vehicle->track_z = outputZ; vehicle->track_direction = outputDirection; vehicle->track_type |= output.element->properties.track.type << 2; - var_34 = 0; + trackProgress = 0; } - vehicle->var_34 = var_34; - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, var_34); + vehicle->track_progress = trackProgress; + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, trackProgress); rct_xyz16 unk = { .x = moveInfo->x, .y = moveInfo->y, @@ -3447,10 +3447,10 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); for (; (sint32)vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { - uint16 var_34 = vehicle->var_34 - 1; + uint16 trackProgress = vehicle->track_progress - 1; const rct_vehicle_info *moveInfo; - if ((sint16)var_34 == -1) { + if ((sint16)trackProgress == -1) { uint8 trackType = vehicle->track_type >> 2; RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_start; RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_start; @@ -3487,14 +3487,12 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { } moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); - uint16 unk16 = *((uint16*)((int)moveInfo - 2)); - var_34 = unk16 - 1; + uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); + trackProgress = trackTotalProgress - 1; } - vehicle->var_34 = var_34; + vehicle->track_progress = trackProgress; - - vehicle->var_34 = var_34; - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, var_34); + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, trackProgress); rct_xyz16 unk = { .x = moveInfo->x, .y = moveInfo->y, @@ -3534,7 +3532,7 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { * * rct2: 0x006DEF56 */ -int sub_6DEF56(rct_vehicle *cableLift) +int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift) { rct_ride_type* rideEntry = GET_RIDE_ENTRY(cableLift->ride_subtype); rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[cableLift->vehicle_type]; @@ -3700,7 +3698,7 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d sprite_move(16, 16, z, (rct_sprite*)current); current->track_type = (TRACK_ELEM_CABLE_LIFT_HILL << 2) | (current->sprite_direction >> 3); - current->var_34 = 164; + current->track_progress = 164; current->update_flags = VEHICLE_UPDATE_FLAG_1; current->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; current->sub_state = 0; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 644e8aae4e..610bcf87d1 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -112,7 +112,7 @@ typedef struct { uint8 ride; // 0x30 uint8 vehicle_type; // 0x31 rct_vehicle_colour colours; // 0x32 - uint16 var_34; + uint16 track_progress; // 0x34 union { sint16 track_direction; // 0x36 (0000 0000 0000 0011) sint16 track_type; // 0x36 (0000 0011 1111 1100) @@ -280,7 +280,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG); void vehicle_set_map_toolbar(rct_vehicle *vehicle); int vehicle_is_used_in_pairs(rct_vehicle *vehicle); rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); -int sub_6DEF56(rct_vehicle *cableLift); +int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift); rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head); bool sub_6DD365(rct_vehicle *vehicle); int sub_6DAB4C(rct_vehicle *vehicle, int *outStation); From cbf859bffbec2bff1d87b6838549fb666d2f4e9c Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 11 Dec 2015 13:07:22 +0000 Subject: [PATCH 062/162] Added vehicle_update_travelling_boat and vehicle_update_travelling_cable_lif --- src/ride/vehicle.c | 141 ++++++++++++++++++++++++++++++++++++++++++++- src/ride/vehicle.h | 11 +++- 2 files changed, 147 insertions(+), 5 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 5847fadc9f..825a0ba5fe 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -62,6 +62,8 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle); static void vehicle_update_top_spin_operating(rct_vehicle* vehicle); static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); +static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle); +static void vehicle_update_travelling_boat(rct_vehicle* vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -667,7 +669,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) //RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)vehicle->ride * sizeof(rct_ride), 0); //return; - if (vehicle->status == VEHICLE_STATUS_TRAVELLING_07){ + if (vehicle->status == VEHICLE_STATUS_TRAVELLING_BOAT){ ride->lifecycle_flags |= RIDE_LIFECYCLE_TESTED; ride->lifecycle_flags |= RIDE_LIFECYCLE_NO_RAW_STATS; ride->lifecycle_flags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; @@ -1110,10 +1112,14 @@ static void vehicle_update(rct_vehicle *vehicle) case VEHICLE_STATUS_TRAVELLING: vehicle_update_travelling(vehicle); break; + case VEHICLE_STATUS_TRAVELLING_CABLE_LIFT: + vehicle_update_travelling_cable_lift(vehicle); + break; + case VEHICLE_STATUS_TRAVELLING_BOAT: + vehicle_update_travelling_boat(vehicle); + break; case VEHICLE_STATUS_ARRIVING: case VEHICLE_STATUS_UNLOADING_PASSENGERS: - case VEHICLE_STATUS_TRAVELLING_07: - case VEHICLE_STATUS_TRAVELLING_CABLE_LIFT: { int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->sub_state << 8) | ride->mode, (int)vehicle, 0, 0); @@ -1915,6 +1921,39 @@ static bool vehicle_next_tower_element_is_top(rct_vehicle* vehicle) { return true; } +/* rct2: 0x006D986C */ +static void vehicle_update_travelling_boat_hire_setup(rct_vehicle* vehicle) { + vehicle->var_34 = vehicle->sprite_direction; + vehicle->track_x = vehicle->x & 0xFFE0; + vehicle->track_y = vehicle->y & 0xFFE0; + + rct_xy8 location = { + .x = (vehicle->track_x + RCT2_ADDRESS(0x00993CCC, sint16)[2 * (vehicle->sprite_direction >> 3)]) / 32, + .y = (vehicle->track_y + RCT2_ADDRESS(0x00993CCE, sint16)[2 * (vehicle->sprite_direction >> 3)]) / 32 + }; + + vehicle->boat_location = location; + vehicle->var_35 = 0; + vehicle->status = VEHICLE_STATUS_TRAVELLING_BOAT; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 0; + vehicle->var_24 += 27924; + + vehicle_update_travelling_boat(vehicle); +} + +/* rct2: 0x006D982F */ +static void vehicle_update_departing_boat_hire(rct_vehicle* vehicle) { + vehicle->lost_time_out = 0; + rct_ride* ride = GET_RIDE(vehicle->ride); + + ride->station_depart[vehicle->current_station] &= STATION_DEPART_FLAG; + uint8 waitingTime = max(ride->min_waiting_time, 3); + waitingTime = min(waitingTime, 127); + ride->station_depart[vehicle->current_station] |= waitingTime; + vehicle_update_travelling_boat_hire_setup(vehicle); +} + /* rct2: 0x006D845B */ static void vehicle_update_departing(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); @@ -2275,6 +2314,10 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { return; } } + else if (ride->mode == RIDE_MODE_BOAT_HIRE) { + vehicle_update_travelling_boat_hire_setup(vehicle); + return; + } else if (ride->mode == RIDE_MODE_SHUTTLE) { vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_3; vehicle->velocity = 0; @@ -2381,6 +2424,12 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { vehicle->sub_state = 1; } +/* rct2: 0x006D9820 */ +static void vehicle_update_travelling_boat(rct_vehicle* vehicle) { + vehicle_check_if_missing(vehicle); + RCT2_CALLPROC_X(0x006DA717, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + /* rct2: 0x006D9249 */ static void vehicle_update_swinging(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); @@ -3009,6 +3058,92 @@ static void vehicle_crash_on_water(rct_vehicle* vehicle) { vehicle->var_4E = 0xFFFF; } +/** +* +* rct2: 0x006D9D21 +*/ +static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + + if (vehicle->sub_state == 0) { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) { + if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) + return; + + ride->lifecycle_flags |= RIDE_LIFECYCLE_BROKEN_DOWN; + ride_breakdown_add_news_item(vehicle->ride); + ride->window_invalidate_flags |= + RIDE_INVALIDATE_RIDE_MAIN | + RIDE_INVALIDATE_RIDE_LIST | + RIDE_INVALIDATE_RIDE_MAINTENANCE; + + ride->mechanic_status = RIDE_MECHANIC_STATUS_CALLING; + ride->inspection_station = vehicle->current_station; + ride->breakdown_reason = ride->breakdown_reason_pending; + vehicle->velocity = 0; + return; + } + + vehicle->sub_state = 1; + vehicle_peep_easteregg_here_we_are(vehicle); + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TESTED)) { + if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_TESTING)) { + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TEST_IN_PROGRESS)) { + vehicle_test_reset(vehicle); + } + else { + uint8 currentSegment = ride->current_test_segment + 1; + if (currentSegment >= ride->num_stations) { + vehicle_update_test_finish(vehicle); + } + else { + ride->current_test_segment = currentSegment; + ride->var_1F6 = vehicle->current_station; + } + } + } + } + } + + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + if (vehicle->velocity <= 439800) { + vehicle->var_2C = 4398; + } + int flags = sub_6DAB4C(vehicle, NULL); + + if (flags & (1 << 11)) { + vehicle->status = VEHICLE_STATUS_TRAVELLING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 1; + vehicle->lost_time_out = 0; + return; + } + + if (vehicle->sub_state == 2) + return; + + if (flags & (1 << 3) && vehicle->current_station == RCT2_GLOBAL(0x00F64E1C, uint8)) + return; + + vehicle->sub_state = 2; + + if (ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED || + ride->mode == RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED) + return; + + // This is slightly different to the vanilla function + ride->station_depart[vehicle->current_station] &= STATION_DEPART_FLAG; + uint8 waitingTime = 3; + if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH) { + waitingTime = max(ride->min_waiting_time, 3); + waitingTime = min(waitingTime, 127); + } + + ride->station_depart[vehicle->current_station] |= waitingTime; +} + /** * * rct2: 0x006D98CA diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 610bcf87d1..047898b854 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -112,10 +112,17 @@ typedef struct { uint8 ride; // 0x30 uint8 vehicle_type; // 0x31 rct_vehicle_colour colours; // 0x32 - uint16 track_progress; // 0x34 + union { + uint16 track_progress; // 0x34 + struct { + uint8 var_34; + uint8 var_35; + }; + }; union { sint16 track_direction; // 0x36 (0000 0000 0000 0011) sint16 track_type; // 0x36 (0000 0011 1111 1100) + rct_xy8 boat_location; // 0x36 }; uint16 track_x; // 0x38 uint16 track_y; // 0x3A @@ -190,7 +197,7 @@ enum { VEHICLE_STATUS_TRAVELLING, VEHICLE_STATUS_ARRIVING, VEHICLE_STATUS_UNLOADING_PASSENGERS, - VEHICLE_STATUS_TRAVELLING_07, + VEHICLE_STATUS_TRAVELLING_BOAT, VEHICLE_STATUS_CRASHING, VEHICLE_STATUS_CRASHED, VEHICLE_STATUS_TRAVELLING_BUMPER_CARS, From cd5a18b2c5db00149da9133f86796366909795ed Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 11 Dec 2015 15:28:07 +0000 Subject: [PATCH 063/162] Implement vehicle_update_arriving --- src/ride/vehicle.c | 208 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 825a0ba5fe..3a75a3ccfa 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2073,7 +2073,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (flags & ((1 << 5) | (1 << 12))) { if (ride->mode == RIDE_MODE_BOAT_HIRE) { - RCT2_CALLPROC_X(0x006D982F, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_update_departing_boat_hire(vehicle); return; } else if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { @@ -2424,6 +2424,212 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { vehicle->sub_state = 1; } +/* rct2: 0x006D8C36 */ +static void vehicle_update_arriving(rct_vehicle* vehicle) { + RCT2_GLOBAL(0x00F64E35, uint8) = 1; + rct_ride* ride = GET_RIDE(vehicle->ride); + + switch (ride->mode) { + case RIDE_MODE_SWING: + case RIDE_MODE_ROTATION: + case RIDE_MODE_FORWARD_ROTATION: + case RIDE_MODE_BACKWARD_ROTATION: + case RIDE_MODE_FILM_AVENGING_AVIATORS: + case RIDE_MODE_FILM_THRILL_RIDERS: + case RIDE_MODE_BEGINNERS: + case RIDE_MODE_INTENSE: + case RIDE_MODE_BERSERK: + case RIDE_MODE_3D_FILM_MOUSE_TAILS: + case RIDE_MODE_3D_FILM_STORM_CHASERS: + case RIDE_MODE_3D_FILM_SPACE_RAIDERS: + case RIDE_MODE_CIRCUS_SHOW: + case RIDE_MODE_SPACE_RINGS: + case RIDE_MODE_HAUNTED_HOUSE: + case RIDE_MODE_CROOKED_HOUSE: + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_12; + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + return; + } + + if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN && + ride->breakdown_reason_pending == BREAKDOWN_BRAKES_FAILURE && + ride->inspection_station == vehicle->current_station && + ride->mechanic_status != RIDE_MECHANIC_STATUS_4) + RCT2_GLOBAL(0x00F64E35, uint8) = 0; + + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + if (vehicle->sub_state == 0) { + if (ride->mode == RIDE_MODE_RACE && + ride->lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) { + goto loc_6D8E36; + } + + if (vehicle->velocity <= 131940) { + vehicle->var_2C = 3298; + goto loc_6D8E36; + } + + sint32 velocity_diff = vehicle->velocity; + if (velocity_diff >= 1572864) + velocity_diff /= 8; + else + velocity_diff /= 16; + + if (RCT2_GLOBAL(0x00F64E35, uint8) == 0) { + goto loc_6D8E36; + } + + if (ride->num_circuits != 1) { + if (vehicle->num_laps + 1 < ride->num_circuits) { + goto loc_6D8E36; + } + } + vehicle->velocity -= velocity_diff; + vehicle->var_2C = 0; + } + else { + if (!(vehicleEntry->var_14 & (1 << 3)) && + vehicle->velocity >= -131940) { + vehicle->var_2C = -3298; + } + + if (vehicle->velocity >= -131940) { + goto loc_6D8E36; + } + + sint32 velocity_diff = vehicle->velocity; + if (velocity_diff < -1572864) + velocity_diff /= 8; + else + velocity_diff /= 16; + + if (RCT2_GLOBAL(0x00F64E35, uint8) == 0) { + goto loc_6D8E36; + } + + if (vehicle->num_laps + 1 < ride->num_circuits) { + goto loc_6D8E36; + } + + if (vehicle->num_laps + 1 != ride->num_circuits) { + vehicle->velocity -= velocity_diff; + vehicle->var_2C = 0; + goto loc_6D8E36; + } + + if (RideData4[ride->type].flags & RIDE_TYPE_FLAG4_ALLOW_MULTIPLE_CIRCUITS && + ride->mode != RIDE_MODE_SHUTTLE && + ride->mode != RIDE_MODE_POWERED_LAUNCH) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; + } + else{ + vehicle->velocity -= velocity_diff; + vehicle->var_2C = 0; + } + } + + uint32 flags; + loc_6D8E36: + flags = sub_6DAB4C(vehicle, NULL); + if (flags & (1 << 7) && + RCT2_GLOBAL(0x00F64E35, uint8) == 0) { + RCT2_CALLPROC_X(0x006DA059, 0, 0, 0, 0, (int)vehicle, 0, 0); + return; + } + + if (flags & (1 << 0) && + RCT2_GLOBAL(0x00F64E35, uint8) == 0) { + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 1; + vehicle_invalidate_window(vehicle); + return; + } + + if (!(flags & ((1 << 0) | (1 << 1) | (1 << 5)))) { + if (vehicle->velocity > 98955) + vehicle->var_C0 = 0; + return; + } + + vehicle->var_C0++; + if (flags & (1 << 1) && + vehicleEntry->var_14 & (1 << 13) && + vehicle->var_C0 < 40){ + return; + } + + rct_map_element* mapElement = map_get_track_element_at( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z / 8 + ); + + vehicle->current_station = map_get_station(mapElement); + vehicle->num_laps++; + + if (vehicle->sub_state != 0) { + if (vehicle->num_laps < ride->num_circuits) { + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 1; + vehicle_invalidate_window(vehicle); + return; + } + + if (vehicle->num_laps == ride->num_circuits && + vehicle->update_flags & VEHICLE_UPDATE_FLAG_12) { + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 1; + vehicle_invalidate_window(vehicle); + return; + } + } + + if (ride->num_circuits != 1 && + vehicle->num_laps < ride->num_circuits) { + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 1; + vehicle_invalidate_window(vehicle); + return; + } + + if ((ride->mode == RIDE_MODE_UPWARD_LAUNCH || + ride->mode == RIDE_MODE_DOWNWARD_LAUNCH) && + vehicle->var_CE < 2) { + audio_play_sound_at_location( + SOUND_RIDE_LAUNCH_2, + vehicle->x, + vehicle->y, + vehicle->z); + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 1; + vehicle_invalidate_window(vehicle); + return; + } + + if (ride->mode == RIDE_MODE_RACE && + ride->lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) { + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 1; + vehicle_invalidate_window(vehicle); + return; + } + + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_12; + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); +} + /* rct2: 0x006D9820 */ static void vehicle_update_travelling_boat(rct_vehicle* vehicle) { vehicle_check_if_missing(vehicle); From 0a8ef64a83ed5f1c7b01cd22005f7ddad5c8ee49 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 11 Dec 2015 15:49:21 +0000 Subject: [PATCH 064/162] Fix some small bugs. Actually use arrive code --- src/ride/vehicle.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 3a75a3ccfa..36d459d61e 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -64,6 +64,7 @@ static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle); static void vehicle_update_travelling_boat(rct_vehicle* vehicle); +static void vehicle_update_arriving(rct_vehicle* vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -1119,6 +1120,8 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_travelling_boat(vehicle); break; case VEHICLE_STATUS_ARRIVING: + vehicle_update_arriving(vehicle); + break; case VEHICLE_STATUS_UNLOADING_PASSENGERS: { int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); @@ -2526,7 +2529,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { if (RideData4[ride->type].flags & RIDE_TYPE_FLAG4_ALLOW_MULTIPLE_CIRCUITS && ride->mode != RIDE_MODE_SHUTTLE && ride->mode != RIDE_MODE_POWERED_LAUNCH) { - vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_12; } else{ vehicle->velocity -= velocity_diff; @@ -2559,7 +2562,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { vehicle->var_C0++; if (flags & (1 << 1) && - vehicleEntry->var_14 & (1 << 13) && + vehicleEntry->var_14 & (1 << 14) && vehicle->var_C0 < 40){ return; } From a372637bd88c31df216488f91655666e9d0958e5 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 11 Dec 2015 17:35:24 +0000 Subject: [PATCH 065/162] Implemented vehicle_update_unloading_passengers --- src/ride/vehicle.c | 95 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 36d459d61e..ca9fd9e546 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -65,6 +65,7 @@ static void vehicle_update_crash(rct_vehicle *vehicle); static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle); static void vehicle_update_travelling_boat(rct_vehicle* vehicle); static void vehicle_update_arriving(rct_vehicle* vehicle); +static void vehicle_update_unloading_passengers(rct_vehicle* vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -1123,10 +1124,7 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_arriving(vehicle); break; case VEHICLE_STATUS_UNLOADING_PASSENGERS: - { - int *addressSwitchPtr = (int*)(0x006D7B70 + (vehicle->status * 4)); - RCT2_CALLPROC_X(*addressSwitchPtr, 0, 0, 0, (vehicle->sub_state << 8) | ride->mode, (int)vehicle, 0, 0); - } + vehicle_update_unloading_passengers(vehicle); break; case VEHICLE_STATUS_WAITING_FOR_CABLE_LIFT: vehicle_update_waiting_for_cable_lift(vehicle); @@ -2633,6 +2631,95 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); } +/* rct2: 0x006D9002 */ +static void vehicle_update_unloading_passengers(rct_vehicle* vehicle) { + if (vehicle->sub_state == 0) { + if (!vehicle_open_restraints(vehicle)) { + vehicle->sub_state = 1; + } + } + + rct_ride* ride = GET_RIDE(vehicle->ride); + if (ride->mode == RIDE_MODE_FORWARD_ROTATION || + ride->mode == RIDE_MODE_BACKWARD_ROTATION) { + uint8 seat = ((-vehicle->var_1F) >> 3) & 0xF; + if (vehicle->restraints_position == 255 && + (vehicle->peep[seat * 2] != 0xFFFF)) { + vehicle->next_free_seat -= 2; + + rct_peep* peep = GET_PEEP(vehicle->peep[seat * 2]); + vehicle->peep[seat * 2] = 0xFFFF; + + peep_decrement_num_riders(peep); + peep->sub_state = 7; + peep->state = PEEP_STATE_LEAVING_RIDE; + peep_window_state_update(peep); + + peep = GET_PEEP(vehicle->peep[seat * 2 + 1]); + vehicle->peep[seat * 2 + 1] = 0xFFFF; + + peep_decrement_num_riders(peep); + peep->sub_state = 7; + peep->state = PEEP_STATE_LEAVING_RIDE; + peep_window_state_update(peep); + } + } + else { + if (ride->exits[vehicle->current_station] == 0xFFFF) { + if (vehicle->sub_state != 1) + return; + + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TESTED) && + vehicle->update_flags & VEHICLE_UPDATE_FLAG_TESTING && + ride->current_test_segment + 1 >= ride->num_stations) { + vehicle_update_test_finish(vehicle); + } + vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); + return; + } + + uint16 spriteId = vehicle->sprite_index; + for (rct_vehicle* train; spriteId != 0xFFFF; spriteId = train->next_vehicle_on_train) { + train = GET_VEHICLE(spriteId); + if (train->restraints_position != 255) + continue; + + if (train->next_free_seat == 0) + continue; + + train->next_free_seat = 0; + for (uint8 peepIndex = 0; peepIndex < train->num_peeps; peepIndex++) { + rct_peep* peep = GET_PEEP(train->peep[peepIndex]); + peep_decrement_num_riders(peep); + peep->sub_state = 7; + peep->state = PEEP_STATE_LEAVING_RIDE; + peep_window_state_update(peep); + } + } + } + + if (vehicle->sub_state != 1) + return; + + uint16 spriteId = vehicle->sprite_index; + for (rct_vehicle* train; spriteId != 0xFFFF; spriteId = train->next_vehicle_on_train) { + train = GET_VEHICLE(spriteId); + if (train->num_peeps != train->next_free_seat) + return; + } + + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TESTED) && + vehicle->update_flags & VEHICLE_UPDATE_FLAG_TESTING && + ride->current_test_segment + 1 >= ride->num_stations) { + vehicle_update_test_finish(vehicle); + } + vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; + vehicle->sub_state = 0; + vehicle_invalidate_window(vehicle); +} + /* rct2: 0x006D9820 */ static void vehicle_update_travelling_boat(rct_vehicle* vehicle) { vehicle_check_if_missing(vehicle); From c94d36207702315c666c2e170c2ee37108e1a37d Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 11 Dec 2015 20:26:26 +0000 Subject: [PATCH 066/162] Fix sound bugs --- src/ride/vehicle.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index ca9fd9e546..ece0a688d2 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -85,7 +85,7 @@ const uint8 byte_9A3A14[] = { SOUND_SCREAM_8, SOUND_SCREAM_1 }; const uint8 byte_9A3A16[] = { SOUND_SCREAM_1, SOUND_SCREAM_6 }; const uint8 byte_9A3A18[] = { SOUND_SCREAM_3, SOUND_SCREAM_1, SOUND_SCREAM_5, SOUND_SCREAM_6, - SOUND_SCREAM_7, SOUND_SCREAM_2, SOUND_SCREAM_4, SOUND_LIFT_1 + SOUND_SCREAM_7, SOUND_SCREAM_2, SOUND_SCREAM_4 }; static const rct_vehicle_info *vehicle_get_move_info(int cd, int typeAndDirection, int offset) @@ -3532,9 +3532,6 @@ static void vehicle_update_crash(rct_vehicle *vehicle){ */ static void vehicle_update_sound(rct_vehicle *vehicle) { - //RCT2_CALLPROC_X(0x006D7888, 0, 0, 0, 0, (int)vehicle, 0, 0); return; - - // PROBLEMS rct_ride *ride; rct_ride_type *rideEntry; // bl should be set before hand @@ -3552,10 +3549,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle) if (ecx >= 0) { dl = vehicleEntry->var_57; ecx >>= 15; - if (208 + (ecx & 0xFF) > 255) - bl = 255; - else - bl = 208 + (ecx & 0xFF); + bl = min(208 + ecx & 0xFF, 255); } switch (vehicleEntry->sound_range) { @@ -3571,7 +3565,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle) break; } } - if (screamId != 254) screamId = 255; + if (screamId == NO_SCREAM) screamId = 255; screamVolume = 255; break; @@ -3587,7 +3581,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle) break; } } - if (screamId != 254) screamId = 255; + if (screamId == NO_SCREAM) screamId = 255; screamVolume = 255; break; @@ -3623,8 +3617,8 @@ static void vehicle_update_sound(rct_vehicle *vehicle) { int ebx = RCT2_ADDRESS(0x009A3684, sint16)[vehicle->sprite_direction]; int eax = ((vehicle->velocity >> 14) * ebx) >> 14; - eax = max(eax, 0xFF81); - eax = min(eax, 0x7F); + eax = clamp(-127, eax, 127); + vehicle->var_BF = eax & 0xFF; } } @@ -3636,7 +3630,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle) */ static int vehicle_update_scream_sound(rct_vehicle *vehicle) { - int r; + uint32 r; uint16 spriteIndex; rct_ride_type *rideEntry; rct_vehicle *vehicle2; @@ -3694,7 +3688,7 @@ produceScream: vehicle->scream_sound_id = byte_9A3A14[r % 2]; break; case 1: - vehicle->scream_sound_id = byte_9A3A18[r % 8]; + vehicle->scream_sound_id = byte_9A3A18[r % 7]; break; case 2: vehicle->scream_sound_id = byte_9A3A16[r % 2]; From 4b326f45693b67728e24c7f779b77b5de2e374a5 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 11 Dec 2015 20:55:34 +0000 Subject: [PATCH 067/162] Implement vehicle_update_crash_setup --- src/ride/vehicle.c | 64 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index ece0a688d2..50c9a0c9bb 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -66,6 +66,7 @@ static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle); static void vehicle_update_travelling_boat(rct_vehicle* vehicle); static void vehicle_update_arriving(rct_vehicle* vehicle); static void vehicle_update_unloading_passengers(rct_vehicle* vehicle); +static void vehicle_update_crash_setup(rct_vehicle* vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -2145,7 +2146,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (ride->lifecycle_flags & RIDE_LIFECYCLE_SIX_FLAGS_DEPRECATED) return; - RCT2_CALLPROC_X(0x006D9EFE, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_update_crash_setup(vehicle); return; } } @@ -2257,6 +2258,63 @@ static void vehicle_check_if_missing(rct_vehicle* vehicle) { news_item_add_to_queue(NEWS_ITEM_RIDE, 2218, vehicle->ride); } +/* rct2: 0x006D9EFE */ +static void vehicle_update_crash_setup(rct_vehicle* vehicle) { + vehicle->status = VEHICLE_STATUS_CRASHING; + vehicle_invalidate_window(vehicle); + + int num_peeps = vehicle_get_total_num_peeps(vehicle); + if (num_peeps != 0) { + audio_play_sound_at_location( + SOUND_HAUNTED_HOUSE_SCREAM_2, + vehicle->x, + vehicle->y, + vehicle->z + ); + } + + int edx = vehicle->velocity >> 10; + + rct_vehicle* lastVehicle = vehicle; + uint16 spriteId = vehicle->sprite_index; + for (rct_vehicle* trainVehicle; spriteId != 0xFFFF; spriteId = trainVehicle->next_vehicle_on_train) { + trainVehicle = GET_VEHICLE(spriteId); + lastVehicle = trainVehicle; + + trainVehicle->sub_state = 0; + int x = RCT2_ADDRESS(0x009A3AC4, sint16)[trainVehicle->sprite_direction * 2]; + int y = RCT2_ADDRESS(0x009A3AC6, sint16)[trainVehicle->sprite_direction * 2]; + + int ecx = RCT2_ADDRESS(0x009A37E4, uint32)[trainVehicle->var_1F] >> 15; + x *= ecx; + y *= ecx; + x >>= 16; + y >>= 16; + ecx = RCT2_ADDRESS(0x009A38D4, uint32)[trainVehicle->var_1F] >> 23; + x *= edx; + y *= edx; + ecx *= edx; + x >>= 8; + y >>= 8; + ecx >>= 8; + + trainVehicle->var_B6 = x; + trainVehicle->var_C0 = y; + trainVehicle->var_4E = ecx; + trainVehicle->var_B6 += (scenario_rand() & 0xF) - 8; + trainVehicle->var_C0 += (scenario_rand() & 0xF) - 8; + trainVehicle->var_4E += (scenario_rand() & 0xF) - 8; + + trainVehicle->track_x = 0; + trainVehicle->track_y = 0; + trainVehicle->track_z = 0; + } + + (GET_VEHICLE(vehicle->prev_vehicle_on_ride))->next_vehicle_on_ride = lastVehicle->next_vehicle_on_ride; + (GET_VEHICLE(lastVehicle->next_vehicle_on_ride))->prev_vehicle_on_ride = vehicle->prev_vehicle_on_ride; + vehicle->velocity = 0; +} + /* rct2: 0x006D8937 */ static void vehicle_update_travelling(rct_vehicle* vehicle) { vehicle_check_if_missing(vehicle); @@ -2296,7 +2354,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { if (!skipCheck) { if (flags & (1 << 6)) { - RCT2_CALLPROC_X(0x006D9EFE, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_update_crash_setup(vehicle); return; } @@ -2336,7 +2394,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { } else { if (vehicle->sub_state != 0) { - RCT2_CALLPROC_X(0x006D9EFE, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_update_crash_setup(vehicle); return; } vehicle->sub_state = 1; From 93e2fa14e8e17465b4ca4cb204b6c86d2ae7dc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sat, 12 Dec 2015 11:21:49 +0100 Subject: [PATCH 068/162] vehicle-fixes --- src/ride/vehicle.c | 135 +++++++++++++++++++++++---------------------- src/ride/vehicle.h | 2 +- 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 50c9a0c9bb..4cb581f245 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -512,7 +512,7 @@ void vehicle_update_all() } } -/* rct2: 0x006D6956 +/* rct2: 0x006D6956 * returns 0 when all closed */ static int vehicle_close_restraints(rct_vehicle* vehicle){ @@ -554,7 +554,7 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ continue; } vehicle->restraints_position -= 20; - } + } invalidate_sprite_2((rct_sprite*)vehicle); ebp++; } while ((vehicle_id = vehicle->next_vehicle_on_train) != 0xFFFF); @@ -562,7 +562,7 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ return ebp; } -/* rct2: 0x006D6A2C +/* rct2: 0x006D6A2C * returns 0 when all open */ static int vehicle_open_restraints(rct_vehicle* vehicle){ @@ -782,23 +782,23 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) uint16 track_flags = RCT2_ADDRESS(0x0099423C, uint16)[track_elem_type]; uint32 testing_flags = ride->testing_flags; - if (testing_flags & RIDE_TESTING_TURN_LEFT && + if (testing_flags & RIDE_TESTING_TURN_LEFT && track_flags & TRACK_ELEM_FLAG_TURN_LEFT){ // 0x800 as this is masked to CURRENT_TURN_COUNT_MASK ride->turn_count_default += 0x800; } - else if (testing_flags & RIDE_TESTING_TURN_RIGHT && + else if (testing_flags & RIDE_TESTING_TURN_RIGHT && track_flags & TRACK_ELEM_FLAG_TURN_RIGHT){ // 0x800 as this is masked to CURRENT_TURN_COUNT_MASK ride->turn_count_default += 0x800; } - else if (testing_flags & RIDE_TESTING_TURN_RIGHT || + else if (testing_flags & RIDE_TESTING_TURN_RIGHT || testing_flags & RIDE_TESTING_TURN_LEFT){ ride->testing_flags &= ~( - RIDE_TESTING_TURN_LEFT | - RIDE_TESTING_TURN_RIGHT | - RIDE_TESTING_TURN_BANKED | + RIDE_TESTING_TURN_LEFT | + RIDE_TESTING_TURN_RIGHT | + RIDE_TESTING_TURN_BANKED | RIDE_TESTING_TURN_SLOPED); uint8 turn_type = 1; @@ -817,7 +817,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) break; case 2: increment_turn_count_3_elements(ride, turn_type); - break; + break; default: increment_turn_count_4_plus_elements(ride, turn_type); break; @@ -848,7 +848,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } } } - + if (testing_flags & RIDE_TESTING_DROP_DOWN){ if (vehicle->velocity < 0 || !(track_flags & TRACK_ELEM_FLAG_DOWN)){ ride->testing_flags &= ~RIDE_TESTING_DROP_DOWN; @@ -919,7 +919,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) ride->special_track_elements &= ~0x1F; ride->special_track_elements |= helixes; } - + } if (ride->entrances[ride->var_1F6] == 0xFFFF) @@ -1074,8 +1074,8 @@ static void vehicle_update(rct_vehicle *vehicle) break; case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: vehicle_update_waiting_for_passengers(vehicle); - break; - case VEHICLE_STATUS_WAITING_TO_DEPART: + break; + case VEHICLE_STATUS_WAITING_TO_DEPART: vehicle_update_waiting_to_depart(vehicle); break; case VEHICLE_STATUS_CRASHING: @@ -1084,7 +1084,7 @@ static void vehicle_update(rct_vehicle *vehicle) break; case VEHICLE_STATUS_TRAVELLING_BUMPER_CARS: vehicle_update_bumpcar_mode(vehicle); - break; + break; case VEHICLE_STATUS_SWINGING: vehicle_update_swinging(vehicle); break; @@ -1096,19 +1096,19 @@ static void vehicle_update(rct_vehicle *vehicle) break; case VEHICLE_STATUS_FERRIS_WHEEL_ROTATING: vehicle_update_ferris_wheel_rotating(vehicle); - break; + break; case VEHICLE_STATUS_SPACE_RINGS_OPERATING: vehicle_update_space_rings_operating(vehicle); - break; + break; case VEHICLE_STATUS_HAUNTED_HOUSE_OPERATING: vehicle_update_haunted_house_operating(vehicle); - break; + break; case VEHICLE_STATUS_CROOKED_HOUSE_OPERATING: vehicle_update_crooked_house_operating(vehicle); - break; + break; case VEHICLE_STATUS_ROTATING: vehicle_update_rotating(vehicle); - break; + break; case VEHICLE_STATUS_DEPARTING: vehicle_update_departing(vehicle); break; @@ -1117,10 +1117,10 @@ static void vehicle_update(rct_vehicle *vehicle) break; case VEHICLE_STATUS_TRAVELLING_CABLE_LIFT: vehicle_update_travelling_cable_lift(vehicle); - break; + break; case VEHICLE_STATUS_TRAVELLING_BOAT: vehicle_update_travelling_boat(vehicle); - break; + break; case VEHICLE_STATUS_ARRIVING: vehicle_update_arriving(vehicle); break; @@ -1324,7 +1324,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); - break; + break; } } } @@ -1354,7 +1354,7 @@ static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train if (ride->mode == RIDE_MODE_FORWARD_ROTATION || ride->mode == RIDE_MODE_BACKWARD_ROTATION){ - + uint8 peep = ((-vehicle->var_1F) / 8) & 0xF; if (vehicle->peep[peep] != 0xFFFF){ ride->train_at_station[vehicle->current_station] = 0xFF; @@ -1535,7 +1535,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ if (num_peeps_on_train != 0){ vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART; - } + } train_ready_to_depart(vehicle, num_peeps_on_train, num_used_seats_on_train); return; } @@ -1822,7 +1822,7 @@ static void vehicle_peep_easteregg_here_we_are(rct_vehicle* vehicle) { } while ((spriteId = vehicle->next_vehicle_on_train) != 0xFFFF); } -/* rct2: 0x006D7338 +/* rct2: 0x006D7338 * Performed when vehicle has completed a full circuit */ static void vehicle_update_test_finish(rct_vehicle* vehicle) { @@ -1856,11 +1856,11 @@ static void vehicle_update_test_finish(rct_vehicle* vehicle) { } /* rct2: 0x006D6BE7 - * + * */ static void vehicle_test_reset(rct_vehicle* vehicle) { - vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TESTING; - + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TESTING; + rct_ride* ride = GET_RIDE(vehicle->ride); ride->lifecycle_flags |= RIDE_LIFECYCLE_TEST_IN_PROGRESS; ride->lifecycle_flags &= ~RIDE_LIFECYCLE_NO_RAW_STATS; @@ -1988,7 +1988,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { SOUND_TRAIN_CHUGGING; audio_play_sound_at_location( - soundId, + soundId, vehicle->x, vehicle->y, vehicle->z); @@ -2049,15 +2049,15 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { vehicle->var_2C = 14 << 12; break; } - // Fall through + // Fall through case RIDE_MODE_CONTINUOUS_CIRCUIT: case RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED: case RIDE_MODE_ROTATING_LIFT: case RIDE_MODE_FREEFALL_DROP: case RIDE_MODE_BOAT_HIRE: - if (vehicleEntry->var_14 & (1 << 3)) + if (vehicleEntry->var_14 & (1 << 3)) break; - + if (vehicle->velocity <= 131940) vehicle->var_2C = 3298; break; @@ -2072,7 +2072,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { return; } } - + if (flags & ((1 << 5) | (1 << 12))) { if (ride->mode == RIDE_MODE_BOAT_HIRE) { vehicle_update_departing_boat_hire(vehicle); @@ -2088,7 +2088,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { vehicle->velocity = 0; } } - + if (flags & (1 << 4)) { vehicle->var_B8 |= (1 << 1); if (ride->mode != RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { @@ -2145,7 +2145,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (ride->lifecycle_flags & RIDE_LIFECYCLE_SIX_FLAGS_DEPRECATED) return; - + vehicle_update_crash_setup(vehicle); return; } @@ -2156,13 +2156,13 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { invalidate_sprite_2((rct_sprite*)vehicle); return; } - + vehicle_finish_departing(vehicle); } -/* rct2: 0x006D8858 - * Part of vehicle_update_departing - * Called after finishing departing sequence to enter +/* rct2: 0x006D8858 + * Part of vehicle_update_departing + * Called after finishing departing sequence to enter * traveling state. * Vertical rides class the lift to the top of the tower * as the departing sequence. After this point station @@ -2208,7 +2208,7 @@ static void vehicle_finish_departing(rct_vehicle* vehicle) { } vehicle->status = VEHICLE_STATUS_TRAVELLING; - vehicle_invalidate_window(vehicle); + vehicle_invalidate_window(vehicle); vehicle->lost_time_out = 0; vehicle->sub_state = 1; @@ -2241,7 +2241,7 @@ static void vehicle_check_if_missing(rct_vehicle* vehicle) { ride->lifecycle_flags |= RIDE_LIFECYCLE_11; - RCT2_GLOBAL(0x0013CE952, rct_string_id) + RCT2_GLOBAL(0x0013CE952, rct_string_id) = RCT2_ADDRESS(0x0097C98E, rct_string_id)[ride->type * 4] + 6; uint8 vehicleIndex = 0; @@ -2344,7 +2344,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { uint32 flags = sub_6DAB4C(vehicle, NULL); bool skipCheck = false; - if (flags & ((1 << 8) | (1 << 9)) && + if (flags & ((1 << 8) | (1 << 9)) && ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE && vehicle->sub_state == 0) { vehicle->sub_state = 1; @@ -2434,7 +2434,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_12)) { if (vehicle->velocity >= ride->lift_hill_speed * -31079) { vehicle->var_2C = -15539; - + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) { vehicle->var_B8 &= ~(1 << 1); vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; @@ -2537,7 +2537,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { sint32 velocity_diff = vehicle->velocity; if (velocity_diff >= 1572864) velocity_diff /= 8; - else + else velocity_diff /= 16; if (RCT2_GLOBAL(0x00F64E35, uint8) == 0) { @@ -2575,7 +2575,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { if (vehicle->num_laps + 1 < ride->num_circuits) { goto loc_6D8E36; } - + if (vehicle->num_laps + 1 != ride->num_circuits) { vehicle->velocity -= velocity_diff; vehicle->var_2C = 0; @@ -2662,8 +2662,8 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { vehicle->var_CE < 2) { audio_play_sound_at_location( SOUND_RIDE_LAUNCH_2, - vehicle->x, - vehicle->y, + vehicle->x, + vehicle->y, vehicle->z); vehicle->velocity = 0; vehicle->var_2C = 0; @@ -2757,7 +2757,7 @@ static void vehicle_update_unloading_passengers(rct_vehicle* vehicle) { } } } - + if (vehicle->sub_state != 1) return; @@ -2875,7 +2875,7 @@ static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle) { rotation &= 0x7F; vehicle->var_1F = rotation; - + if (rotation == vehicle->sub_state) vehicle->var_CE++; @@ -2937,7 +2937,7 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { invalidate_sprite_2((rct_sprite*)vehicle); return; } - + vehicle->status = VEHICLE_STATUS_ARRIVING; vehicle_invalidate_window(vehicle); vehicle->sub_state = 0; @@ -3072,9 +3072,9 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { switch (vehicle->var_4C) { case 45: audio_play_sound_at_location( - SOUND_HAUNTED_HOUSE_SCARE, - vehicle->x, - vehicle->y, + SOUND_HAUNTED_HOUSE_SCARE, + vehicle->x, + vehicle->y, vehicle->z); break; case 75: @@ -3195,7 +3195,7 @@ static void vehicle_update_showing_film(rct_vehicle *vehicle) } /** - * + * * rct2: 0x006D95F7 */ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) @@ -3217,7 +3217,7 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) } } -/* rct2: 0x0068B8BD +/* rct2: 0x0068B8BD * returns the map element that the vehicle will collide with * returns NULL if no collisions. */ @@ -3266,7 +3266,7 @@ static void vehicle_kill_all_passengers(rct_vehicle* vehicle) { uint8 crashType = numFatalities == 0 ? RIDE_CRASH_TYPE_NO_FATALITIES : RIDE_CRASH_TYPE_FATALITIES; - + if (crashType >= ride->last_crash_type) ride->last_crash_type = crashType; @@ -3398,7 +3398,7 @@ static void vehicle_crash_on_water(rct_vehicle* vehicle) { for (int i = 0; i < 10; ++i) crashed_vehicle_particle_create(vehicle->colours, vehicle->x - 4, vehicle->y + 8, vehicle->z); - + vehicle->var_0C |= (1 << 7); vehicle->var_C5 = 0; vehicle->var_C8 = 0; @@ -3426,9 +3426,9 @@ static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle) { ride->lifecycle_flags |= RIDE_LIFECYCLE_BROKEN_DOWN; ride_breakdown_add_news_item(vehicle->ride); - ride->window_invalidate_flags |= - RIDE_INVALIDATE_RIDE_MAIN | - RIDE_INVALIDATE_RIDE_LIST | + ride->window_invalidate_flags |= + RIDE_INVALIDATE_RIDE_MAIN | + RIDE_INVALIDATE_RIDE_LIST | RIDE_INVALIDATE_RIDE_MAINTENANCE; ride->mechanic_status = RIDE_MECHANIC_STATUS_CALLING; @@ -3548,7 +3548,7 @@ static void vehicle_update_crash(rct_vehicle *vehicle){ continue; } } - + zDiff = curVehicle->z - z; if ((zDiff <= 0 && zDiff >= -20) || curVehicle->z < 16){ vehicle_crash_on_land(curVehicle); @@ -3585,7 +3585,7 @@ static void vehicle_update_crash(rct_vehicle *vehicle){ } while ((spriteId = curVehicle->next_vehicle_on_train) != 0xFFFF); } /** - * + * * rct2: 0x006D7888 */ static void vehicle_update_sound(rct_vehicle *vehicle) @@ -3655,6 +3655,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle) loc_6D7A97: vehicle->scream_sound_id = 255; + assert(ride->type < countof(RideLiftData)); // Get lift hill sound screamId = RideLiftData[ride->type].sound_id; screamVolume = 243; @@ -3676,14 +3677,14 @@ static void vehicle_update_sound(rct_vehicle *vehicle) int ebx = RCT2_ADDRESS(0x009A3684, sint16)[vehicle->sprite_direction]; int eax = ((vehicle->velocity >> 14) * ebx) >> 14; eax = clamp(-127, eax, 127); - + vehicle->var_BF = eax & 0xFF; } } /** * - * + * * rct2: 0x006D796B */ static int vehicle_update_scream_sound(rct_vehicle *vehicle) @@ -3763,7 +3764,7 @@ produceScream: } /** - * + * * rct2: 0x006D73D0 * ax: verticalG * dx: lateralG @@ -4240,7 +4241,7 @@ int vehicle_get_total_num_peeps(rct_vehicle *vehicle) } /** - * + * * rct2: 0x006DA1EC */ void vehicle_invalidate_window(rct_vehicle *vehicle) diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 047898b854..216343e58d 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -298,4 +298,4 @@ void vehicle_invalidate_window(rct_vehicle *vehicle); /** Helper macro until rides are stored in this module. */ #define GET_VEHICLE(sprite_index) &(g_sprite_list[sprite_index].vehicle) -#endif \ No newline at end of file +#endif From 90d006232b24614d4dfa2750ab3c174fad977f11 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 12 Dec 2015 11:48:28 +0000 Subject: [PATCH 069/162] Change sign of var_24. Add missing cable lift data --- src/ride/ride.c | 2 +- src/ride/ride_data.c | 3 ++- src/ride/ride_data.h | 2 +- src/ride/vehicle.c | 12 ++++++------ src/ride/vehicle.h | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index 52bfbd5300..f723d902a7 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -4468,7 +4468,7 @@ bool ride_create_cable_lift(int rideIndex, bool isApplying) uint16 var_44 = edx & 0xFFFF; edx = rol32(edx, 10) >> 1; ebx -= edx; - uint32 var_24 = ebx; + sint32 var_24 = ebx; ebx -= edx; rct_vehicle *current = cable_lift_segment_create(rideIndex, x, y, z, direction, var_44, var_24, i == 0); diff --git a/src/ride/ride_data.c b/src/ride/ride_data.c index f70d6a66c2..905b8c68e0 100644 --- a/src/ride/ride_data.c +++ b/src/ride/ride_data.c @@ -1309,5 +1309,6 @@ const rct_ride_lift_data RideLiftData[] = { { SOUND_LIFT_1, 4, 7 }, // Inverted Impulse Coaster { SOUND_LIFT_1, 4, 6 }, // Mini Roller Coaster { 255, 5, 5 }, // Mine Ride - { SOUND_LIFT_6, 4, 6 } // LIM Launched Roller Coaster + { SOUND_LIFT_6, 4, 6 }, // (none) + { 255, 4, 6 } // LIM Launched Roller Coaster }; \ No newline at end of file diff --git a/src/ride/ride_data.h b/src/ride/ride_data.h index 554060b718..f82dce841f 100644 --- a/src/ride/ride_data.h +++ b/src/ride/ride_data.h @@ -93,7 +93,7 @@ extern const uint8 AllRideModesAvailable[]; extern const uint8 RideAvailableBreakdowns[]; extern const rct_ride_entrance_definition RideEntranceDefinitions[RIDE_ENTRANCE_STYLE_COUNT]; -extern const rct_ride_lift_data RideLiftData[90]; +extern const rct_ride_lift_data RideLiftData[91]; extern const rct_ride_data_4 RideData4[91]; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 4cb581f245..bc7021d602 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3741,7 +3741,7 @@ static int vehicle_update_scream_sound(rct_vehicle *vehicle) produceScream: if (vehicle->scream_sound_id == 255) { r = scenario_rand(); - if (totalNumPeeps >= r % 16) { + if (totalNumPeeps >= (int)(r % 16)) { switch (vehicleEntry->sound_range) { case 0: vehicle->scream_sound_id = byte_9A3A14[r % 2]; @@ -3930,7 +3930,7 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); - for (; (sint32)vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { + for (; vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { uint16 trackProgress = vehicle->track_progress - 1; const rct_vehicle_info *moveInfo; @@ -4005,7 +4005,7 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { vehicle->var_20 = moveInfo->var_08; vehicle->var_1F = moveInfo->var_07; - if ((sint32)vehicle->var_24 < 0) { + if (vehicle->var_24 < 0) { vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; } } @@ -4051,7 +4051,7 @@ int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift) invalidate_sprite_2((rct_sprite*)vehicle); while (true) { - if ((sint32)vehicle->var_24 < 0) { + if (vehicle->var_24 < 0) { if (sub_6DF21B_loop(vehicle) == true) { break; } @@ -4071,7 +4071,7 @@ int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift) else { RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 + 1; - vehicle->var_24 = (uint32)-1; + vehicle->var_24 = -1; vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; RCT2_GLOBAL(0x00F64E10, uint32)++; } @@ -4128,7 +4128,7 @@ int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift) //return eax; } -rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head) +rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head) { rct_ride *ride = GET_RIDE(rideIndex); rct_vehicle *current = &(create_sprite(1)->vehicle); diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 216343e58d..524bd8f659 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -106,7 +106,7 @@ typedef struct { uint8 var_1F; uint8 var_20; uint8 pad_21[3]; - uint32 var_24; + sint32 var_24; sint32 velocity; // 0x28 sint32 var_2C; uint8 ride; // 0x30 @@ -288,7 +288,7 @@ void vehicle_set_map_toolbar(rct_vehicle *vehicle); int vehicle_is_used_in_pairs(rct_vehicle *vehicle); rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift); -rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head); +rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head); bool sub_6DD365(rct_vehicle *vehicle); int sub_6DAB4C(rct_vehicle *vehicle, int *outStation); rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle); From 45d1375b8334e65d07994b2267e8df62a2bd3c83 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 12 Dec 2015 12:21:13 +0000 Subject: [PATCH 070/162] Implement vehicle_update_collision setup. Removed ride crash hook. --- src/openrct2.c | 1 - src/ride/ride.c | 6 +-- src/ride/ride.h | 2 +- src/ride/vehicle.c | 96 +++++++++++++++++++++++++++++++++++++++++----- src/ride/vehicle.h | 2 +- 5 files changed, 89 insertions(+), 18 deletions(-) diff --git a/src/openrct2.c b/src/openrct2.c index 6a6692d8d9..1ecd84b318 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -640,7 +640,6 @@ static void openrct2_setup_rct2_hooks() { addhook(0x006E732D, (int)gfx_set_dirty_blocks, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0); // remove when all callers are decompiled addhook(0x006E7499, (int)gfx_redraw_screen_rect, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0); // remove when 0x6E7FF3 is decompiled - addhook(0x006B752C, (int)ride_crash, 0, (int[]){ EDX, EBX, END }, 0, 0); // remove when all callers are decompiled addhook(0x0069A42F, (int)peep_window_state_update, 0, (int[]){ ESI, END }, 0, 0); // remove when all callers are decompiled addhook(0x006BB76E, (int)audio_play_sound_panned, 0, (int[]){EAX, EBX, ECX, EDX, EBP, END}, EAX, 0); // remove when all callers are decompiled addhook(0x006C42D9, (int)scrolling_text_setup, 0, (int[]){EAX, ECX, EBP, END}, 0, EBX); // remove when all callers are decompiled diff --git a/src/ride/ride.c b/src/ride/ride.c index f723d902a7..35bc459a93 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -7298,16 +7298,12 @@ void game_command_remove_ride_entrance_or_exit(int *eax, int *ebx, int *ecx, int * * rct2: 0x006B752C */ -void ride_crash(int rideIndex, int vehicleIndex) +void ride_crash(uint8 rideIndex, uint8 vehicleIndex) { rct_ride *ride; rct_vehicle *vehicle; rct_window *w; - // TODO Remove these when hook is no longer used - rideIndex &= 0xFF; - vehicleIndex &= 0xFF; - ride = GET_RIDE(rideIndex); vehicle = GET_VEHICLE(ride->vehicles[vehicleIndex]); diff --git a/src/ride/ride.h b/src/ride/ride.h index 2efaa238cd..02cf2726e3 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -1041,7 +1041,7 @@ void game_command_place_ride_entrance_or_exit(int *eax, int *ebx, int *ecx, int void game_command_remove_ride_entrance_or_exit(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); void sub_6CB945(int rideIndex); -void ride_crash(int rideIndex, int vehicleIndex); +void ride_crash(uint8 rideIndex, uint8 vehicleIndex); bool ride_type_is_intamin(int rideType); void sub_6C94D8(); diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index bc7021d602..5010cd7694 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -67,10 +67,13 @@ static void vehicle_update_travelling_boat(rct_vehicle* vehicle); static void vehicle_update_arriving(rct_vehicle* vehicle); static void vehicle_update_unloading_passengers(rct_vehicle* vehicle); static void vehicle_update_crash_setup(rct_vehicle* vehicle); +static void vehicle_update_collision_setup(rct_vehicle* vehicle); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); +static void vehicle_kill_all_passengers(rct_vehicle* vehicle); + #define NO_SCREAM 254 typedef struct { @@ -566,8 +569,6 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ * returns 0 when all open */ static int vehicle_open_restraints(rct_vehicle* vehicle){ - //return (RCT2_CALLPROC_X(0x006d6a2c, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100); - int ebp = 0; uint16 vehicle_id = vehicle->sprite_index; @@ -669,8 +670,6 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) rct_ride *ride; ride = GET_RIDE(vehicle->ride); - //RCT2_CALLPROC_X(0x006D6D1F, 0, 0, 0, 0, (int)vehicle, (int)vehicle->ride * sizeof(rct_ride), 0); - //return; if (vehicle->status == VEHICLE_STATUS_TRAVELLING_BOAT){ ride->lifecycle_flags |= RIDE_LIFECYCLE_TESTED; @@ -1015,8 +1014,6 @@ static uint16 sub_6D7AC0(int currentSoundId, int currentVolume, int targetSoundI */ static void vehicle_update(rct_vehicle *vehicle) { - // RCT2_CALLPROC_X(0x006D77F2, 0, 0, 0, 0, (int)vehicle, 0, 0); - rct_ride *ride; rct_ride_type *rideEntry; @@ -2258,6 +2255,86 @@ static void vehicle_check_if_missing(rct_vehicle* vehicle) { news_item_add_to_queue(NEWS_ITEM_RIDE, 2218, vehicle->ride); } +/** + * Setup function for a vehicle colliding with + * another vehicle. + * + * rct2: 0x006DA059 + */ +static void vehicle_update_collision_setup(rct_vehicle* vehicle) { + vehicle->status = VEHICLE_STATUS_CRASHED; + vehicle_invalidate_window(vehicle); + + rct_ride* ride = GET_RIDE(vehicle->ride); + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED)) { + rct_vehicle* frontVehicle = vehicle; + while (frontVehicle->is_child != 0)frontVehicle = GET_VEHICLE(frontVehicle->prev_vehicle_on_ride); + + uint8 trainIndex = 0; + while (ride->vehicles[trainIndex] != frontVehicle->sprite_index) + trainIndex++; + + ride_crash(vehicle->ride, trainIndex); + + if (ride->status != RIDE_STATUS_CLOSED) { + ride_set_status(vehicle->ride, RIDE_STATUS_CLOSED); + } + } + + ride->lifecycle_flags |= RIDE_LIFECYCLE_CRASHED; + ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; + vehicle_kill_all_passengers(vehicle); + + rct_vehicle* lastVehicle = vehicle; + uint16 spriteId = vehicle->sprite_index; + for (rct_vehicle* train; spriteId != 0xFFFF; spriteId = train->next_vehicle_on_train) { + train = GET_VEHICLE(spriteId); + lastVehicle = train; + + train->sub_state = 2; + + audio_play_sound_at_location( + SOUND_CRASH, + train->x, + train->y, + train->z + ); + + sprite_misc_3_create( + train->x, + train->y, + train->z + ); + + for (int i = 0; i < 10; i++) { + crashed_vehicle_particle_create( + train->colours, + train->x, + train->y, + train->z + ); + } + + train->var_0C |= (1 << 7); + train->var_C8 = scenario_rand(); + train->var_CA = scenario_rand(); + + train->var_C5 = train->var_CA & 0x7; + train->sprite_width = 13; + train->sprite_height_negative = 45; + train->sprite_height_positive = 5; + + sprite_move(train->x, train->y, train->z, (rct_sprite*)train); + invalidate_sprite_2((rct_sprite*)train); + + train->var_4E = 0; + } + + (GET_VEHICLE(vehicle->prev_vehicle_on_ride))->next_vehicle_on_ride = lastVehicle->next_vehicle_on_ride; + (GET_VEHICLE(lastVehicle->next_vehicle_on_ride))->prev_vehicle_on_ride = vehicle->prev_vehicle_on_ride; + vehicle->velocity = 0; +} + /* rct2: 0x006D9EFE */ static void vehicle_update_crash_setup(rct_vehicle* vehicle) { vehicle->status = VEHICLE_STATUS_CRASHING; @@ -2359,7 +2436,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { } if (flags & (1 << 7)) { - RCT2_CALLPROC_X(0x006DA059, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_update_collision_setup(vehicle); return; } @@ -2598,7 +2675,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { flags = sub_6DAB4C(vehicle, NULL); if (flags & (1 << 7) && RCT2_GLOBAL(0x00F64E35, uint8) == 0) { - RCT2_CALLPROC_X(0x006DA059, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_update_collision_setup(vehicle); return; } @@ -4163,8 +4240,7 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d current->var_C4 = 0; current->var_C5 = 0; current->var_C8 = 0; - current->pad_CA[0] = 0; - current->pad_CA[1] = 0; + current->var_CA = 0; current->scream_sound_id = 0xFF; current->var_1F = 0; current->var_20 = 0; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 524bd8f659..aa578e0297 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -165,7 +165,7 @@ typedef struct { uint8 var_C5; uint8 pad_C6[0x2]; uint16 var_C8; - uint8 pad_CA[0x2]; + uint16 var_CA; uint8 scream_sound_id; // 0xCC uint8 var_CD; union { From 5964b3768a2515f7b388b32542dc59c33daddb5e Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 12 Dec 2015 14:55:05 +0000 Subject: [PATCH 071/162] Implement bumper car motion update --- src/ride/vehicle.c | 180 ++++++++++++++++++++++++++++++++++++++++++++- src/ride/vehicle.h | 3 +- 2 files changed, 177 insertions(+), 6 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 5010cd7694..8532dc6c82 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -68,7 +68,8 @@ static void vehicle_update_arriving(rct_vehicle* vehicle); static void vehicle_update_unloading_passengers(rct_vehicle* vehicle); static void vehicle_update_crash_setup(rct_vehicle* vehicle); static void vehicle_update_collision_setup(rct_vehicle* vehicle); - +static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle); +static bool vehicle_update_bumper_car_collision(rct_vehicle *vehicle, sint16 x, sint16 y, uint16 *spriteId); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -1567,7 +1568,7 @@ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { invalidate_sprite_2((rct_sprite*)vehicle); } - RCT2_CALLPROC_X(0x006DA44E, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_update_motion_bumper_car(vehicle); // Update the length of time vehicle has been in bumper mode if (vehicle->sub_state++ == 0xFF) { @@ -4205,6 +4206,172 @@ int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift) //return eax; } +/* rct2: 0x006DA44E */ +static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { + RCT2_GLOBAL(0x00F64E18, uint32) = 0; + rct_ride* ride = GET_RIDE(vehicle->ride); + + sint32 nextVelocity = vehicle->velocity + vehicle->var_2C; + if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN) && + ride->breakdown_reason_pending == BREAKDOWN_SAFETY_CUT_OUT) { + nextVelocity = 0; + } + vehicle->velocity = nextVelocity; + + RCT2_GLOBAL(0x00F64E08, sint32) = nextVelocity; + RCT2_GLOBAL(0x00F64E0C, sint32) = (nextVelocity / 1024) * 42; + RCT2_GLOBAL(0x00F64E10, uint32) = 1; + + vehicle->var_2C = 0; + if (!(ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) || + ride->breakdown_reason_pending != BREAKDOWN_SAFETY_CUT_OUT) { + if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 1 && + vehicle->var_34 != 0) { + + if (vehicle->var_34 > 0) { + vehicle->var_34--; + vehicle->sprite_direction += 2; + } + else { + vehicle->var_34++; + vehicle->sprite_direction -= 2; + } + vehicle->sprite_direction &= 0x1E; + invalidate_sprite_2((rct_sprite*)vehicle); + } + else if ((scenario_rand() & 0xFFFF) <= 2849) { + if (vehicle->var_35 & (1 << 6)) + vehicle->sprite_direction -= 2; + else + vehicle->sprite_direction += 2; + vehicle->sprite_direction &= 0x1E; + invalidate_sprite_2((rct_sprite*)vehicle); + } + } + + uint16 collideSprite = 0xFFFF; + + if (vehicle->var_C4 != 0) { + uint8 oldC4 = vehicle->var_C4 & 0x1E; + vehicle->var_C4 = 0; + + rct_xyz16 location = { + .x = vehicle->x, + .y = vehicle->y, + .z = vehicle->z + }; + + location.x += RCT2_ADDRESS(0x009A36C4, sint16)[oldC4 * 4]; + location.y += RCT2_ADDRESS(0x009A36C6, sint16)[oldC4 * 4]; + location.x += RCT2_ADDRESS(0x009A36CC, sint16)[oldC4 * 4]; + location.y += RCT2_ADDRESS(0x009A36CE, sint16)[oldC4 * 4]; + + if (!vehicle_update_bumper_car_collision(vehicle, location.x, location.y, &collideSprite)) { + invalidate_sprite_2((rct_sprite*)vehicle); + sprite_move( + location.x, + location.y, + location.z, + (rct_sprite*)vehicle + ); + invalidate_sprite_2((rct_sprite*)vehicle); + } + } + + vehicle->var_24 += RCT2_GLOBAL(0x00F64E0C, sint32); + + if (vehicle->var_24 >= 13962) { + vehicle->var_B8 &= ~(1 << 1); + rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; + + invalidate_sprite_2((rct_sprite*)vehicle); + + while (1) { + vehicle->var_35++; + uint8 direction = vehicle->sprite_direction; + direction |= vehicle->var_35 & 1; + + rct_xyz16 location = *unk_F64E20; + location.x += RCT2_ADDRESS(0x009A36C4, sint16)[direction * 4]; + location.y += RCT2_ADDRESS(0x009A36C6, sint16)[direction * 4]; + + if (vehicle_update_bumper_car_collision(vehicle, location.x, location.y, &collideSprite)) + break; + + vehicle->var_24 -= RCT2_ADDRESS(0x009A36C8, sint16)[direction * 4]; + unk_F64E20->x = location.x; + unk_F64E20->y = location.y; + if (vehicle->var_24 < 13962) { + break; + } + RCT2_GLOBAL(0x00F64E10, uint32)++; + } + + if (vehicle->var_24 >= 13962) { + sint32 oldVelocity = vehicle->velocity; + vehicle->var_24 = 0; + vehicle->velocity = 0; + uint8 direction = vehicle->sprite_direction | 1; + + if (collideSprite != 0xFFFF) { + vehicle->var_34 = scenario_rand() & 1 ? 1 : -1; + + if (oldVelocity >= 131072) { + rct_vehicle* collideVehicle = GET_VEHICLE(collideSprite); + collideVehicle->var_C4 = direction; + vehicle->var_C4 = direction ^ (1 << 4); + } + } + else { + vehicle->var_34 = scenario_rand() & 1 ? 6 : -6; + + if (oldVelocity >= 131072) { + vehicle->var_C4 = direction ^ (1 << 4); + } + } + } + + sprite_move( + unk_F64E20->x, + unk_F64E20->y, + unk_F64E20->z, + (rct_sprite*)vehicle + ); + invalidate_sprite_2((rct_sprite*)vehicle); + } + + sint32 eax = vehicle->velocity / 2; + sint32 edx = vehicle->velocity >> 8; + edx *= edx; + if (vehicle->velocity < 0) + edx = -edx; + edx >>= 5; + eax += edx; + eax /= vehicle->friction; + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + if (!(vehicleEntry->var_14 & (1 << 3))) { + vehicle->var_2C = -eax; + return RCT2_GLOBAL(0x00F64E18, uint32); + } + + sint32 ebx = (vehicle->speed * vehicle->friction) >> 2; + sint32 _eax = vehicle->speed << 14; + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_3) { + _eax = -_eax; + } + _eax -= vehicle->velocity; + _eax *= vehicle->acceleration * 2; + _eax /= ebx; + + vehicle->var_2C = _eax - eax; + return RCT2_GLOBAL(0x00F64E18, uint32); +} + rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head) { rct_ride *ride = GET_RIDE(rideIndex); @@ -4271,12 +4438,17 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d * * rct2: 0x006DD365 */ -bool sub_6DD365(rct_vehicle *vehicle) +static bool vehicle_update_bumper_car_collision(rct_vehicle *vehicle, sint16 x, sint16 y, uint16 *spriteId) { registers regs; regs.esi = (int)vehicle; + regs.eax = x; + regs.ecx = y; - return RCT2_CALLFUNC_Y(0x006DD365, ®s) & 0x100; + bool result = RCT2_CALLFUNC_Y(0x006DD365, ®s) & 0x100; + if (spriteId != NULL) + *spriteId = regs.bp; + return result; } /** diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index aa578e0297..03a0ab433b 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -115,7 +115,7 @@ typedef struct { union { uint16 track_progress; // 0x34 struct { - uint8 var_34; + sint8 var_34; uint8 var_35; }; }; @@ -289,7 +289,6 @@ int vehicle_is_used_in_pairs(rct_vehicle *vehicle); rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift); rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head); -bool sub_6DD365(rct_vehicle *vehicle); int sub_6DAB4C(rct_vehicle *vehicle, int *outStation); rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle); int vehicle_get_total_num_peeps(rct_vehicle *vehicle); From 846d69a772ed0973b0657e71bd0a144e1a0915f8 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 12 Dec 2015 17:59:03 +0000 Subject: [PATCH 072/162] Implement vehicle_update_bumper_car_collision --- src/ride/vehicle.c | 63 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 8532dc6c82..92a649c3da 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -4440,15 +4440,62 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d */ static bool vehicle_update_bumper_car_collision(rct_vehicle *vehicle, sint16 x, sint16 y, uint16 *spriteId) { - registers regs; - regs.esi = (int)vehicle; - regs.eax = x; - regs.ecx = y; + uint16 bp = (vehicle->var_44 * 30) >> 9; + uint32 trackType = vehicle->track_type >> 2; + + sint16 rideLeft = vehicle->track_x + RCT2_ADDRESS(0x0099E228, uint8)[trackType * 4]; + sint16 rideRight = vehicle->track_x + RCT2_ADDRESS(0x0099E22A, uint8)[trackType * 4]; + sint16 rideTop = vehicle->track_y + RCT2_ADDRESS(0x0099E229, uint8)[trackType * 4]; + sint16 rideBottom = vehicle->track_y + RCT2_ADDRESS(0x0099E22B, uint8)[trackType * 4]; - bool result = RCT2_CALLFUNC_Y(0x006DD365, ®s) & 0x100; - if (spriteId != NULL) - *spriteId = regs.bp; - return result; + if (x - bp < rideLeft || + y - bp < rideTop || + x + bp > rideRight || + y + bp > rideBottom) { + if (spriteId != NULL) + *spriteId = 0xFFFF; + return true; + } + + uint16 location = (y / 32) | ((x / 32) << 8); + + + uint8 rideIndex = vehicle->ride; + for (sint32* ebp = RCT2_ADDRESS(0x009A37C4, sint32); ebp <= RCT2_ADDRESS(0x009A37E4, sint32); ebp++) { + uint16 spriteIdx = RCT2_ADDRESS(0xF1EF60, uint16)[location]; + for (rct_vehicle* vehicle2 = GET_VEHICLE(spriteIdx); spriteIdx != 0xFFFF; spriteIdx = vehicle2->next_in_quadrant) { + vehicle2 = GET_VEHICLE(spriteIdx); + + if (vehicle2 == vehicle) + continue; + + if (vehicle2->sprite_identifier != SPRITE_IDENTIFIER_VEHICLE) + continue; + + if (vehicle2->ride != rideIndex) + continue; + + int distX = abs(x - vehicle2->x); + if (distX > 32768) + continue; + + int distY = abs(y - vehicle2->y); + if (distY > 32768) + continue; + + int ecx = (vehicle->var_44 + vehicle2->var_44) / 2; + ecx *= 30; + ecx >>= 8; + if (max(distX, distY) < ecx) { + if (spriteId != NULL) + *spriteId = vehicle2->sprite_index; + return true; + } + } + location += *ebp; + } + + return false; } /** From 1e72e9fb14ebadea795da5f70e173b52baa2808b Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 12 Dec 2015 20:25:20 +0000 Subject: [PATCH 073/162] Started implementing get g forces --- src/ride/vehicle.c | 298 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 294 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 92a649c3da..40685b68c1 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3850,6 +3850,300 @@ produceScream: */ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) { + int _eax = (((sint64)0x280000) * RCT2_ADDRESS(0x009A37E4, sint32)[vehicle->var_1F]) >> 32; + _eax = (((sint64)_eax) * RCT2_ADDRESS(0x009A39C4, sint32)[vehicle->var_20]) >> 32; + + switch (vehicle->track_type >> 2) { + TRACK_ELEM_FLAT: + TRACK_ELEM_END_STATION: + TRACK_ELEM_BEGIN_STATION: + TRACK_ELEM_MIDDLE_STATION: + TRACK_ELEM_25_DEG_UP: + TRACK_ELEM_60_DEG_UP: // + TRACK_ELEM_25_DEG_DOWN: + TRACK_ELEM_60_DEG_DOWN: // + TRACK_ELEM_FLAT_TO_LEFT_BANK: + TRACK_ELEM_FLAT_TO_RIGHT_BANK: + TRACK_ELEM_LEFT_BANK_TO_FLAT: + TRACK_ELEM_RIGHT_BANK_TO_FLAT:// + TRACK_ELEM_LEFT_BANK: + TRACK_ELEM_RIGHT_BANK: + TRACK_ELEM_TOWER_BASE: + TRACK_ELEM_TOWER_SECTION: + TRACK_ELEM_FLAT_COVERED: + TRACK_ELEM_25_DEG_UP_COVERED: + TRACK_ELEM_60_DEG_UP_COVERED: + TRACK_ELEM_25_DEG_DOWN_COVERED: + TRACK_ELEM_60_DEG_DOWN_COVERED: + TRACK_ELEM_BRAKES: + TRACK_ELEM_ROTATION_CONTROL_TOGGLE: + TRACK_ELEM_INVERTED_90_DEG_UP_TO_FLAT_QUARTER_LOOP: + TRACK_ELEM_25_DEG_UP_LEFT_BANKED: + TRACK_ELEM_25_DEG_UP_RIGHT_BANKED: + TRACK_ELEM_WATERFALL: + TRACK_ELEM_RAPIDS: + TRACK_ELEM_ON_RIDE_PHOTO: + TRACK_ELEM_25_DEG_DOWN_LEFT_BANKED: + TRACK_ELEM_25_DEG_DOWN_RIGHT_BANKED: + TRACK_ELEM_WHIRLPOOL: + TRACK_ELEM_REVERSE_WHOA_BELLY_VERTICAL: + TRACK_ELEM_90_DEG_UP: + TRACK_ELEM_90_DEG_DOWN: + TRACK_ELEM_DIAG_FLAT: + TRACK_ELEM_DIAG_25_DEG_UP: + TRACK_ELEM_DIAG_60_DEG_UP: + TRACK_ELEM_DIAG_25_DEG_DOWN: + TRACK_ELEM_DIAG_60_DEG_DOWN: + TRACK_ELEM_DIAG_FLAT_TO_LEFT_BANK: + TRACK_ELEM_DIAG_FLAT_TO_RIGHT_BANK: + TRACK_ELEM_DIAG_LEFT_BANK_TO_FLAT: + TRACK_ELEM_DIAG_RIGHT_BANK_TO_FLAT: + TRACK_ELEM_DIAG_LEFT_BANK: + TRACK_ELEM_DIAG_RIGHT_BANK: + TRACK_ELEM_LOG_FLUME_REVERSER: + TRACK_ELEM_SPINNING_TUNNEL: + TRACK_ELEM_POWERED_LIFT: + //6d73FF + break; + TRACK_ELEM_FLAT_TO_25_DEG_UP:// + TRACK_ELEM_25_DEG_DOWN_TO_FLAT:// + TRACK_ELEM_LEFT_BANK_TO_25_DEG_UP: + TRACK_ELEM_RIGHT_BANK_TO_25_DEG_UP: + TRACK_ELEM_25_DEG_DOWN_TO_LEFT_BANK: + TRACK_ELEM_25_DEG_DOWN_TO_RIGHT_BANK: + TRACK_ELEM_FLAT_TO_25_DEG_UP_COVERED: + TRACK_ELEM_25_DEG_DOWN_TO_FLAT_COVERED: + //6d7509 + break; + TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP:// + TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN:// + TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP_COVERED: + TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN_COVERED: + //6d7545 + break; + TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP:// + TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN:// + TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP_COVERED: + TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN_COVERED: + //6d7551 + break; + TRACK_ELEM_25_DEG_UP_TO_FLAT:// + TRACK_ELEM_FLAT_TO_25_DEG_DOWN:// + TRACK_ELEM_25_DEG_UP_TO_LEFT_BANK: + TRACK_ELEM_25_DEG_UP_TO_RIGHT_BANK: + TRACK_ELEM_LEFT_BANK_TO_25_DEG_DOWN: + TRACK_ELEM_RIGHT_BANK_TO_25_DEG_DOWN: + TRACK_ELEM_25_DEG_UP_TO_FLAT_COVERED: + TRACK_ELEM_FLAT_TO_25_DEG_DOWN_COVERED: + TRACK_ELEM_CABLE_LIFT_HILL: + //6d7569 + break; + TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES:// + TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_UP: + TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_DOWN: + TRACK_ELEM_LEFT_TWIST_DOWN_TO_UP: + TRACK_ELEM_LEFT_TWIST_UP_TO_DOWN: + TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_COVERED: + TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_UP: + TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_DOWN: + //6d7590 + break; + TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES:// + TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_UP: + TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_DOWN: + TRACK_ELEM_RIGHT_TWIST_DOWN_TO_UP: + TRACK_ELEM_RIGHT_TWIST_UP_TO_DOWN: + TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_COVERED: + TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_UP: + TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_DOWN: + //6d75B7 + break; + TRACK_ELEM_BANKED_LEFT_QUARTER_TURN_5_TILES: + TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_LARGE: + TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_LARGE: + TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_UP: + TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_DOWN: + //6d75E1 + break; + TRACK_ELEM_BANKED_RIGHT_QUARTER_TURN_5_TILES: + TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_LARGE: + TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_LARGE: + TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_UP: + TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_DOWN: + //6d75F0 + break; + TRACK_ELEM_S_BEND_LEFT: + TRACK_ELEM_S_BEND_LEFT_COVERED: + //6d75FF + break; + TRACK_ELEM_S_BEND_RIGHT: + TRACK_ELEM_S_BEND_RIGHT_COVERED: + //6d7608 + break; + TRACK_ELEM_LEFT_VERTICAL_LOOP: + TRACK_ELEM_RIGHT_VERTICAL_LOOP: + //6d7690 + break; + TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES: + TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: + TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN: + TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_COVERED: + //6d7704 + break; + TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES: + TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: + TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN: + TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED: + //6d7710 + break; + TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_BANK: + TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_SMALL: + TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_SMALL: + //6d7782 + break; + TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_BANK: + TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_SMALL: + TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_SMALL: + //6d778E + break; + TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE: + //6d779A + break; + TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE: + //6d77A3 + break; + TRACK_ELEM_HALF_LOOP_UP: + //6d763E + break; + TRACK_ELEM_HALF_LOOP_DOWN: + //6d7656 + break; + TRACK_ELEM_LEFT_CORKSCREW_UP: + TRACK_ELEM_RIGHT_CORKSCREW_DOWN: + //6d76AA + break; + TRACK_ELEM_RIGHT_CORKSCREW_UP: + TRACK_ELEM_LEFT_CORKSCREW_DOWN: + //6d76B9 + break; + TRACK_ELEM_FLAT_TO_60_DEG_UP: + TRACK_ELEM_60_DEG_DOWN_TO_FLAT: + //6d747C + break; + TRACK_ELEM_60_DEG_UP_TO_FLAT: + TRACK_ELEM_FLAT_TO_60_DEG_DOWN: + TRACK_ELEM_BRAKE_FOR_DROP: + //6d7488 + break; + TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_UP: + TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_DOWN: + //6d7770 + break; + TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_UP: + TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_DOWN: + //6d7779 + break; + TRACK_ELEM_WATER_SPLASH: + //6d7408 + break; + TRACK_ELEM_FLAT_TO_60_DEG_UP_LONG_BASE: + TRACK_ELEM_FLAT_TO_60_DEG_DOWN_LONG_BASE: + //6d74F1 + break; + TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE: + TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE_122: + //6d74FD + break; + TRACK_ELEM_REVERSE_WHOA_BELLY_SLOPE: + //6d7458 + break; + TRACK_ELEM_60_DEG_UP_TO_90_DEG_UP: + TRACK_ELEM_90_DEG_DOWN_TO_60_DEG_DOWN: + //6d7515 + break; + TRACK_ELEM_90_DEG_UP_TO_60_DEG_UP: + TRACK_ELEM_60_DEG_DOWN_TO_90_DEG_DOWN: + //6d7521 + break; + TRACK_ELEM_LEFT_EIGHTH_TO_DIAG: + TRACK_ELEM_LEFT_EIGHTH_TO_ORTHOGONAL: + //6d7575 + break; + TRACK_ELEM_RIGHT_EIGHTH_TO_DIAG: + TRACK_ELEM_RIGHT_EIGHTH_TO_ORTHOGONAL: + //6d759C + break; + TRACK_ELEM_LEFT_EIGHTH_BANK_TO_DIAG: + TRACK_ELEM_LEFT_EIGHTH_BANK_TO_ORTHOGONAL: + //6d75C3 + break; + TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_DIAG: + TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_ORTHOGONAL: + //6d75D2 + break; + TRACK_ELEM_DIAG_FLAT_TO_25_DEG_UP: + TRACK_ELEM_DIAG_25_DEG_DOWN_TO_FLAT: + TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_UP: + TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_UP: + TRACK_ELEM_DIAG_25_DEG_DOWN_TO_LEFT_BANK: + TRACK_ELEM_DIAG_25_DEG_DOWN_TO_RIGHT_BANK: + //6d7494 + break; + TRACK_ELEM_DIAG_25_DEG_UP_TO_60_DEG_UP: + TRACK_ELEM_DIAG_60_DEG_DOWN_TO_25_DEG_DOWN: + //6D752D + break; + TRACK_ELEM_DIAG_60_DEG_UP_TO_25_DEG_UP: + TRACK_ELEM_DIAG_25_DEG_DOWN_TO_60_DEG_DOWN: + //6D7539 + break; + TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT: + TRACK_ELEM_DIAG_FLAT_TO_25_DEG_DOWN: + TRACK_ELEM_DIAG_25_DEG_UP_TO_LEFT_BANK: + TRACK_ELEM_DIAG_25_DEG_UP_TO_RIGHT_BANK: + TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_DOWN: + TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_DOWN: + //6d755D + break; + TRACK_ELEM_DIAG_FLAT_TO_60_DEG_UP: + TRACK_ELEM_DIAG_60_DEG_DOWN_TO_FLAT: + //6D7464 + break; + TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT: + TRACK_ELEM_DIAG_FLAT_TO_60_DEG_DOWN: + //6d7470 + break; + TRACK_ELEM_LEFT_BARREL_ROLL_UP_TO_DOWN: + TRACK_ELEM_LEFT_BARREL_ROLL_DOWN_TO_UP: + //6d7581 + break; + TRACK_ELEM_RIGHT_BARREL_ROLL_UP_TO_DOWN: + TRACK_ELEM_RIGHT_BARREL_ROLL_DOWN_TO_UP: + //6d75A8 + break; + TRACK_ELEM_LEFT_BANK_TO_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: + //6d771C + break; + TRACK_ELEM_RIGHT_BANK_TO_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: + //6D7746 + break; + TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_LEFT_BANK: + //6D7731 + break; + TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_RIGHT_BANK: + //6D775B + break; + TRACK_ELEM_LEFT_LARGE_HALF_LOOP_UP: + TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_UP: + //6d7666 + break; + TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_DOWN: + TRACK_ELEM_LEFT_LARGE_HALF_LOOP_DOWN: + //6d767F + break; + //187 - 255 + } + int eax, ebx, ecx, edx, esi, edi, ebp; esi = (int)vehicle; @@ -4200,10 +4494,6 @@ int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift) cableLift->var_2C = ecx; return RCT2_GLOBAL(0x00F64E18, uint32); - - //int eax = 0, ebx = 0, ecx = 0, edx = 0, ebp = 0, edi = 0; - //RCT2_CALLFUNC_X(0x006DEF56, &eax, &ebx, &ecx, &edx, (int*)&cableLift, &edi, &ebp); - //return eax; } /* rct2: 0x006DA44E */ From be757f6379128c313f009d2652b83d4424fdf6d2 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 12 Dec 2015 21:07:46 +0000 Subject: [PATCH 074/162] Add missing track elem enum elements. --- src/ride/track.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/ride/track.h b/src/ride/track.h index 102bc4ccea..57238af68f 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -498,7 +498,75 @@ enum { TRACK_ELEM_LEFT_LARGE_HALF_LOOP_UP, TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_UP, TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_DOWN, - TRACK_ELEM_LEFT_LARGE_HALF_LOOP_DOWN + TRACK_ELEM_LEFT_LARGE_HALF_LOOP_DOWN, + TRACK_ELEM_LEFT_FLYER_TWIST_UP, + TRACK_ELEM_RIGHT_FLYER_TWIST_UP, + TRACK_ELEM_LEFT_FLYER_TWIST_DOWN, + TRACK_ELEM_RIGHT_FLYER_TWIST_DOWN, + TRACK_ELEM_FLYER_HALF_LOOP_UP, + TRACK_ELEM_FLYER_HALF_LOOP_DOWN, + TRACK_ELEM_LEFT_FLYER_CORKSCREW_UP, + TRACK_ELEM_RIGHT_FLYER_CORKSCREW_UP, + TRACK_ELEM_LEFT_FLYER_CORKSCREW_DOWN, + TRACK_ELEM_RIGHT_FLYER_CORKSCREW_DOWN, + TRACK_ELEM_HEARTLINE_TRANSFER_UP, + TRACK_ELEM_HEARTLINE_TRANSFER_DOWN, + TRACK_ELEM_LEFT_HEARTLINE_ROLL, + TRACK_ELEM_RIGHT_HEARTLINE_ROLL, + TRACK_ELEM_MINI_GOLF_HOLE_A, + TRACK_ELEM_MINI_GOLF_HOLE_B, + TRACK_ELEM_MINI_GOLF_HOLE_C, + TRACK_ELEM_MINI_GOLF_HOLE_D, + TRACK_ELEM_MINI_GOLF_HOLE_E, + TRACK_ELEM_MULTIDIM_INVERTED_FLAT_TO_90_DEG_QUATER_LOOP_DOWN, + TRACK_ELEM_90_DEG_TO_INVERTED_FLAT_QUATER_LOOP_UP, + TRACK_ELEM_INVERTED_FLAT_TO_90_DEG_QUATER_LOOP_DOWN, + TRACK_ELEM_LEFT_CURVED_LIFT_HILL, + TRACK_ELEM_RIGHT_CURVED_LIFT_HILL, + TRACK_ELEM_LEFT_REVERSER, + TRACK_ELEM_RIGHT_REVERSER, + TRACK_ELEM_AIR_THRUST_TOP_CAP, + TRACK_ELEM_AIR_THRUST_VERTICAL_DOWN, + TRACK_ELEM_AIR_THRUST_VERTICAL_DOWN_TO_LEVEL, + TRACK_ELEM_BLOCK_BRAKES, + TRACK_ELEM_LEFT_BANKED_QUATER_TURN_3_TILE_25_DEG_UP, + TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_3_TILE_25_DEG_UP, + TRACK_ELEM_LEFT_BANKED_QUATER_TURN_3_TILE_25_DEG_DOWN, + TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_3_TILE_25_DEG_DOWN, + TRACK_ELEM_LEFT_BANKED_QUATER_TURN_5_TILE_25_DEG_UP, + TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_5_TILE_25_DEG_UP, + TRACK_ELEM_LEFT_BANKED_QUATER_TURN_5_TILE_25_DEG_DOWN, + TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_5_TILE_25_DEG_DOWN, + TRACK_ELEM_25_DEG_UP_TO_LEFT_BANKED_25_DEG_UP, + TRACK_ELEM_25_DEG_UP_TO_RIGHT_BANKED_25_DEG_UP, + TRACK_ELEM_LEFT_BANKED_25_DEG_UP_TO_25_DEG_UP, + TRACK_ELEM_RIGHT_BANKED_25_DEG_UP_TO_25_DEG_UP, + TRACK_ELEM_25_DEG_DOWN_TO_LEFT_BANKED_25_DEG_DOWN, + TRACK_ELEM_25_DEG_DOWN_TO_RIGHT_BANKED_25_DEG_DOWN, + TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_25_DEG_DOWN, + TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_25_DEG_DOWN, + TRACK_ELEM_LEFT_BANKED_FLAT_TO_LEFT_BANKED_25_DEG_UP, + TRACK_ELEM_RIGHT_BANKED_FLAT_TO_RIGHT_BANKED_25_DEG_UP, + TRACK_ELEM_LEFT_BANKED_25_DEG_UP_TO_LEFT_BANKED_FLAT, + TRACK_ELEM_RIGHT_BANKED_25_DEG_UP_TO_RIGHT_BANKED_FLAT, + TRACK_ELEM_LEFT_BANKED_FLAT_TO_LEFT_BANKED_25_DEG_DOWN, + TRACK_ELEM_RIGHT_BANKED_FLAT_TO_RIGHT_BANKED_25_DEG_DOWN, + TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_LEFT_BANKED_FLAT, + TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_RIGHT_BANKED_FLAT, + TRACK_ELEM_FLAT_TO_LEFT_BANKED_25_DEG_UP, + TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_UP, + TRACK_ELEM_LEFT_BANKED_25_DEG_UP_TO_FLAT, + TRACK_ELEM_RIGHT_BANKED_25_DEG_UP_TO_FLAT, + TRACK_ELEM_FLAT_TO_LEFT_BANKED_25_DEG_DOWN, + TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_DOWN, + TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_FLAT, + TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_FLAT, + TRACK_ELEM_LEFT_QUATER_TURN_1_TILE_90_DEG_UP, + TRACK_ELEM_RIGHT_QUATER_TURN_1_TILE_90_DEG_UP, + TRACK_ELEM_LEFT_QUATER_TURN_1_TILE_90_DEG_DOWN, + TRACK_ELEM_RIGHT_QUATER_TURN_1_TILE_90_DEG_DOWN, + TRACK_ELEM_MULTIDIM_90_DEG_UP_TO_INVERTED_FLAT_QUATER_LOOP, + TRACK_ELEM_MULTIDIM_FLAT_TO_90_DEG_DOWN_QUATER_LOOP, }; enum { From bed328503be27c285ca46f756adb64c144b7c842 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 13 Dec 2015 15:33:01 +0000 Subject: [PATCH 075/162] Add remaining track types to acceleration function --- projects/openrct2.vcxproj.user | 8 +- src/ride/vehicle.c | 464 +++++++++++++++++++-------------- 2 files changed, 281 insertions(+), 191 deletions(-) diff --git a/projects/openrct2.vcxproj.user b/projects/openrct2.vcxproj.user index e977faccec..4beb5eab50 100644 --- a/projects/openrct2.vcxproj.user +++ b/projects/openrct2.vcxproj.user @@ -7,18 +7,22 @@ $(TargetDir)\openrct2.exe WindowsLocalDebugger $(TargetDir) + + $(TargetDir) WindowsLocalDebugger $(TargetDir)\openrct2.exe - + + $(TargetDir) WindowsLocalDebugger $(TargetDir)\openrct2.exe - + + $(TargetDir) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 40685b68c1..c3e3ace4b6 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3854,294 +3854,380 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) _eax = (((sint64)_eax) * RCT2_ADDRESS(0x009A39C4, sint32)[vehicle->var_20]) >> 32; switch (vehicle->track_type >> 2) { - TRACK_ELEM_FLAT: - TRACK_ELEM_END_STATION: - TRACK_ELEM_BEGIN_STATION: - TRACK_ELEM_MIDDLE_STATION: - TRACK_ELEM_25_DEG_UP: - TRACK_ELEM_60_DEG_UP: // - TRACK_ELEM_25_DEG_DOWN: - TRACK_ELEM_60_DEG_DOWN: // - TRACK_ELEM_FLAT_TO_LEFT_BANK: - TRACK_ELEM_FLAT_TO_RIGHT_BANK: - TRACK_ELEM_LEFT_BANK_TO_FLAT: - TRACK_ELEM_RIGHT_BANK_TO_FLAT:// - TRACK_ELEM_LEFT_BANK: - TRACK_ELEM_RIGHT_BANK: - TRACK_ELEM_TOWER_BASE: - TRACK_ELEM_TOWER_SECTION: - TRACK_ELEM_FLAT_COVERED: - TRACK_ELEM_25_DEG_UP_COVERED: - TRACK_ELEM_60_DEG_UP_COVERED: - TRACK_ELEM_25_DEG_DOWN_COVERED: - TRACK_ELEM_60_DEG_DOWN_COVERED: - TRACK_ELEM_BRAKES: - TRACK_ELEM_ROTATION_CONTROL_TOGGLE: - TRACK_ELEM_INVERTED_90_DEG_UP_TO_FLAT_QUARTER_LOOP: - TRACK_ELEM_25_DEG_UP_LEFT_BANKED: - TRACK_ELEM_25_DEG_UP_RIGHT_BANKED: - TRACK_ELEM_WATERFALL: - TRACK_ELEM_RAPIDS: - TRACK_ELEM_ON_RIDE_PHOTO: - TRACK_ELEM_25_DEG_DOWN_LEFT_BANKED: - TRACK_ELEM_25_DEG_DOWN_RIGHT_BANKED: - TRACK_ELEM_WHIRLPOOL: - TRACK_ELEM_REVERSE_WHOA_BELLY_VERTICAL: - TRACK_ELEM_90_DEG_UP: - TRACK_ELEM_90_DEG_DOWN: - TRACK_ELEM_DIAG_FLAT: - TRACK_ELEM_DIAG_25_DEG_UP: - TRACK_ELEM_DIAG_60_DEG_UP: - TRACK_ELEM_DIAG_25_DEG_DOWN: - TRACK_ELEM_DIAG_60_DEG_DOWN: - TRACK_ELEM_DIAG_FLAT_TO_LEFT_BANK: - TRACK_ELEM_DIAG_FLAT_TO_RIGHT_BANK: - TRACK_ELEM_DIAG_LEFT_BANK_TO_FLAT: - TRACK_ELEM_DIAG_RIGHT_BANK_TO_FLAT: - TRACK_ELEM_DIAG_LEFT_BANK: - TRACK_ELEM_DIAG_RIGHT_BANK: - TRACK_ELEM_LOG_FLUME_REVERSER: - TRACK_ELEM_SPINNING_TUNNEL: - TRACK_ELEM_POWERED_LIFT: + case TRACK_ELEM_FLAT: + case TRACK_ELEM_END_STATION: + case TRACK_ELEM_BEGIN_STATION: + case TRACK_ELEM_MIDDLE_STATION: + case TRACK_ELEM_25_DEG_UP: + case TRACK_ELEM_60_DEG_UP: // + case TRACK_ELEM_25_DEG_DOWN: + case TRACK_ELEM_60_DEG_DOWN: // + case TRACK_ELEM_FLAT_TO_LEFT_BANK: + case TRACK_ELEM_FLAT_TO_RIGHT_BANK: + case TRACK_ELEM_LEFT_BANK_TO_FLAT: + case TRACK_ELEM_RIGHT_BANK_TO_FLAT:// + case TRACK_ELEM_LEFT_BANK: + case TRACK_ELEM_RIGHT_BANK: + case TRACK_ELEM_TOWER_BASE: + case TRACK_ELEM_TOWER_SECTION: + case TRACK_ELEM_FLAT_COVERED: + case TRACK_ELEM_25_DEG_UP_COVERED: + case TRACK_ELEM_60_DEG_UP_COVERED: + case TRACK_ELEM_25_DEG_DOWN_COVERED: + case TRACK_ELEM_60_DEG_DOWN_COVERED: + case TRACK_ELEM_BRAKES: + case TRACK_ELEM_ROTATION_CONTROL_TOGGLE: + case TRACK_ELEM_INVERTED_90_DEG_UP_TO_FLAT_QUARTER_LOOP: + case TRACK_ELEM_25_DEG_UP_LEFT_BANKED: + case TRACK_ELEM_25_DEG_UP_RIGHT_BANKED: + case TRACK_ELEM_WATERFALL: + case TRACK_ELEM_RAPIDS: + case TRACK_ELEM_ON_RIDE_PHOTO: + case TRACK_ELEM_25_DEG_DOWN_LEFT_BANKED: + case TRACK_ELEM_25_DEG_DOWN_RIGHT_BANKED: + case TRACK_ELEM_WHIRLPOOL: + case TRACK_ELEM_REVERSE_WHOA_BELLY_VERTICAL: + case TRACK_ELEM_90_DEG_UP: + case TRACK_ELEM_90_DEG_DOWN: + case TRACK_ELEM_DIAG_FLAT: + case TRACK_ELEM_DIAG_25_DEG_UP: + case TRACK_ELEM_DIAG_60_DEG_UP: + case TRACK_ELEM_DIAG_25_DEG_DOWN: + case TRACK_ELEM_DIAG_60_DEG_DOWN: + case TRACK_ELEM_DIAG_FLAT_TO_LEFT_BANK: + case TRACK_ELEM_DIAG_FLAT_TO_RIGHT_BANK: + case TRACK_ELEM_DIAG_LEFT_BANK_TO_FLAT: + case TRACK_ELEM_DIAG_RIGHT_BANK_TO_FLAT: + case TRACK_ELEM_DIAG_LEFT_BANK: + case TRACK_ELEM_DIAG_RIGHT_BANK: + case TRACK_ELEM_LOG_FLUME_REVERSER: + case TRACK_ELEM_SPINNING_TUNNEL: + case TRACK_ELEM_POWERED_LIFT: + case TRACK_ELEM_MINI_GOLF_HOLE_A: + case TRACK_ELEM_MINI_GOLF_HOLE_B: + case TRACK_ELEM_MINI_GOLF_HOLE_C: + case TRACK_ELEM_MINI_GOLF_HOLE_D: + case TRACK_ELEM_MINI_GOLF_HOLE_E: + case TRACK_ELEM_LEFT_REVERSER: + case TRACK_ELEM_RIGHT_REVERSER: + case TRACK_ELEM_AIR_THRUST_VERTICAL_DOWN: + case TRACK_ELEM_BLOCK_BRAKES: + case TRACK_ELEM_25_DEG_UP_TO_LEFT_BANKED_25_DEG_UP: + case TRACK_ELEM_25_DEG_UP_TO_RIGHT_BANKED_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_25_DEG_UP_TO_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANKED_25_DEG_UP_TO_25_DEG_UP: + case TRACK_ELEM_25_DEG_DOWN_TO_LEFT_BANKED_25_DEG_DOWN: + case TRACK_ELEM_25_DEG_DOWN_TO_RIGHT_BANKED_25_DEG_DOWN: + case TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_25_DEG_DOWN: + case TRACK_ELEM_LEFT_QUATER_TURN_1_TILE_90_DEG_UP: + case TRACK_ELEM_RIGHT_QUATER_TURN_1_TILE_90_DEG_UP: + case TRACK_ELEM_LEFT_QUATER_TURN_1_TILE_90_DEG_DOWN: + case TRACK_ELEM_RIGHT_QUATER_TURN_1_TILE_90_DEG_DOWN: //6d73FF break; - TRACK_ELEM_FLAT_TO_25_DEG_UP:// - TRACK_ELEM_25_DEG_DOWN_TO_FLAT:// - TRACK_ELEM_LEFT_BANK_TO_25_DEG_UP: - TRACK_ELEM_RIGHT_BANK_TO_25_DEG_UP: - TRACK_ELEM_25_DEG_DOWN_TO_LEFT_BANK: - TRACK_ELEM_25_DEG_DOWN_TO_RIGHT_BANK: - TRACK_ELEM_FLAT_TO_25_DEG_UP_COVERED: - TRACK_ELEM_25_DEG_DOWN_TO_FLAT_COVERED: + case TRACK_ELEM_FLAT_TO_25_DEG_UP:// + case TRACK_ELEM_25_DEG_DOWN_TO_FLAT:// + case TRACK_ELEM_LEFT_BANK_TO_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANK_TO_25_DEG_UP: + case TRACK_ELEM_25_DEG_DOWN_TO_LEFT_BANK: + case TRACK_ELEM_25_DEG_DOWN_TO_RIGHT_BANK: + case TRACK_ELEM_FLAT_TO_25_DEG_UP_COVERED: + case TRACK_ELEM_25_DEG_DOWN_TO_FLAT_COVERED: + case TRACK_ELEM_LEFT_BANKED_FLAT_TO_LEFT_BANKED_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANKED_FLAT_TO_RIGHT_BANKED_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_LEFT_BANKED_FLAT: + case TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_RIGHT_BANKED_FLAT: + case TRACK_ELEM_FLAT_TO_LEFT_BANKED_25_DEG_UP: + case TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_FLAT: + case TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_FLAT: //6d7509 break; - TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP:// - TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN:// - TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP_COVERED: - TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN_COVERED: + case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP:// + case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN:// + case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP_COVERED: + case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN_COVERED: //6d7545 - break; - TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP:// - TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN:// - TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP_COVERED: - TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN_COVERED: + break; + case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP:// + case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN:// + case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP_COVERED: + case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN_COVERED: //6d7551 break; - TRACK_ELEM_25_DEG_UP_TO_FLAT:// - TRACK_ELEM_FLAT_TO_25_DEG_DOWN:// - TRACK_ELEM_25_DEG_UP_TO_LEFT_BANK: - TRACK_ELEM_25_DEG_UP_TO_RIGHT_BANK: - TRACK_ELEM_LEFT_BANK_TO_25_DEG_DOWN: - TRACK_ELEM_RIGHT_BANK_TO_25_DEG_DOWN: - TRACK_ELEM_25_DEG_UP_TO_FLAT_COVERED: - TRACK_ELEM_FLAT_TO_25_DEG_DOWN_COVERED: - TRACK_ELEM_CABLE_LIFT_HILL: + case TRACK_ELEM_25_DEG_UP_TO_FLAT:// + case TRACK_ELEM_FLAT_TO_25_DEG_DOWN:// + case TRACK_ELEM_25_DEG_UP_TO_LEFT_BANK: + case TRACK_ELEM_25_DEG_UP_TO_RIGHT_BANK: + case TRACK_ELEM_LEFT_BANK_TO_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_BANK_TO_25_DEG_DOWN: + case TRACK_ELEM_25_DEG_UP_TO_FLAT_COVERED: + case TRACK_ELEM_FLAT_TO_25_DEG_DOWN_COVERED: + case TRACK_ELEM_CABLE_LIFT_HILL: + case TRACK_ELEM_LEFT_BANKED_25_DEG_UP_TO_LEFT_BANKED_FLAT: + case TRACK_ELEM_RIGHT_BANKED_25_DEG_UP_TO_RIGHT_BANKED_FLAT: + case TRACK_ELEM_LEFT_BANKED_FLAT_TO_LEFT_BANKED_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_BANKED_FLAT_TO_RIGHT_BANKED_25_DEG_DOWN: + case TRACK_ELEM_LEFT_BANKED_25_DEG_UP_TO_FLAT: + case TRACK_ELEM_RIGHT_BANKED_25_DEG_UP_TO_FLAT: + case TRACK_ELEM_FLAT_TO_LEFT_BANKED_25_DEG_DOWN: + case TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_DOWN: //6d7569 break; - TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES:// - TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_UP: - TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_DOWN: - TRACK_ELEM_LEFT_TWIST_DOWN_TO_UP: - TRACK_ELEM_LEFT_TWIST_UP_TO_DOWN: - TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_COVERED: - TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_UP: - TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_DOWN: + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES:// + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_UP: + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_DOWN: + case TRACK_ELEM_LEFT_TWIST_DOWN_TO_UP: + case TRACK_ELEM_LEFT_TWIST_UP_TO_DOWN: + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_COVERED: + case TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_UP: + case TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_DOWN: + case TRACK_ELEM_LEFT_FLYER_TWIST_UP: + case TRACK_ELEM_LEFT_FLYER_TWIST_DOWN: + case TRACK_ELEM_LEFT_HEARTLINE_ROLL: //6d7590 break; - TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES:// - TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_UP: - TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_DOWN: - TRACK_ELEM_RIGHT_TWIST_DOWN_TO_UP: - TRACK_ELEM_RIGHT_TWIST_UP_TO_DOWN: - TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_COVERED: - TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_UP: - TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_DOWN: + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES:// + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_UP: + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_TWIST_DOWN_TO_UP: + case TRACK_ELEM_RIGHT_TWIST_UP_TO_DOWN: + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_COVERED: + case TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_UP: + case TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_DOWN: + case TRACK_ELEM_RIGHT_FLYER_TWIST_UP: + case TRACK_ELEM_RIGHT_FLYER_TWIST_DOWN: + case TRACK_ELEM_RIGHT_HEARTLINE_ROLL: //6d75B7 break; - TRACK_ELEM_BANKED_LEFT_QUARTER_TURN_5_TILES: - TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_LARGE: - TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_LARGE: - TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_UP: - TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_DOWN: + case TRACK_ELEM_BANKED_LEFT_QUARTER_TURN_5_TILES: + case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_LARGE: + case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_LARGE: + case TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_UP: + case TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_DOWN: //6d75E1 break; - TRACK_ELEM_BANKED_RIGHT_QUARTER_TURN_5_TILES: - TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_LARGE: - TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_LARGE: - TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_UP: - TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_DOWN: + case TRACK_ELEM_BANKED_RIGHT_QUARTER_TURN_5_TILES: + case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_LARGE: + case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_LARGE: + case TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_UP: + case TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_DOWN: //6d75F0 break; - TRACK_ELEM_S_BEND_LEFT: - TRACK_ELEM_S_BEND_LEFT_COVERED: + case TRACK_ELEM_S_BEND_LEFT: + case TRACK_ELEM_S_BEND_LEFT_COVERED: //6d75FF break; - TRACK_ELEM_S_BEND_RIGHT: - TRACK_ELEM_S_BEND_RIGHT_COVERED: + case TRACK_ELEM_S_BEND_RIGHT: + case TRACK_ELEM_S_BEND_RIGHT_COVERED: //6d7608 break; - TRACK_ELEM_LEFT_VERTICAL_LOOP: - TRACK_ELEM_RIGHT_VERTICAL_LOOP: + case TRACK_ELEM_LEFT_VERTICAL_LOOP: + case TRACK_ELEM_RIGHT_VERTICAL_LOOP: //6d7690 break; - TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES: - TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: - TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN: - TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_COVERED: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_COVERED: + case TRACK_ELEM_LEFT_CURVED_LIFT_HILL: //6d7704 break; - TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES: - TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: - TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN: - TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED: + case TRACK_ELEM_RIGHT_CURVED_LIFT_HILL: //6d7710 break; - TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_BANK: - TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_SMALL: - TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_SMALL: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_BANK: + case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_SMALL: + case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_SMALL: //6d7782 break; - TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_BANK: - TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_SMALL: - TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_SMALL: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_BANK: + case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_SMALL: + case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_SMALL: //6d778E break; - TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE: + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE: //6d779A break; - TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE: + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE: //6d77A3 break; - TRACK_ELEM_HALF_LOOP_UP: + case TRACK_ELEM_HALF_LOOP_UP: + case TRACK_ELEM_FLYER_HALF_LOOP_UP: //6d763E break; - TRACK_ELEM_HALF_LOOP_DOWN: + case TRACK_ELEM_HALF_LOOP_DOWN: + case TRACK_ELEM_FLYER_HALF_LOOP_DOWN: //6d7656 break; - TRACK_ELEM_LEFT_CORKSCREW_UP: - TRACK_ELEM_RIGHT_CORKSCREW_DOWN: + case TRACK_ELEM_LEFT_CORKSCREW_UP: + case TRACK_ELEM_RIGHT_CORKSCREW_DOWN: + case TRACK_ELEM_LEFT_FLYER_CORKSCREW_UP: + case TRACK_ELEM_RIGHT_FLYER_CORKSCREW_DOWN: //6d76AA break; - TRACK_ELEM_RIGHT_CORKSCREW_UP: - TRACK_ELEM_LEFT_CORKSCREW_DOWN: + case TRACK_ELEM_RIGHT_CORKSCREW_UP: + case TRACK_ELEM_LEFT_CORKSCREW_DOWN: + case TRACK_ELEM_RIGHT_FLYER_CORKSCREW_UP: + case TRACK_ELEM_LEFT_FLYER_CORKSCREW_DOWN: //6d76B9 break; - TRACK_ELEM_FLAT_TO_60_DEG_UP: - TRACK_ELEM_60_DEG_DOWN_TO_FLAT: + case TRACK_ELEM_FLAT_TO_60_DEG_UP: + case TRACK_ELEM_60_DEG_DOWN_TO_FLAT: //6d747C break; - TRACK_ELEM_60_DEG_UP_TO_FLAT: - TRACK_ELEM_FLAT_TO_60_DEG_DOWN: - TRACK_ELEM_BRAKE_FOR_DROP: + case TRACK_ELEM_60_DEG_UP_TO_FLAT: + case TRACK_ELEM_FLAT_TO_60_DEG_DOWN: + case TRACK_ELEM_BRAKE_FOR_DROP: //6d7488 break; - TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_UP: - TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_DOWN: + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_UP: + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_DOWN: //6d7770 break; - TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_UP: - TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_DOWN: + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_UP: + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_DOWN: //6d7779 break; - TRACK_ELEM_WATER_SPLASH: + case TRACK_ELEM_WATER_SPLASH: //6d7408 break; - TRACK_ELEM_FLAT_TO_60_DEG_UP_LONG_BASE: - TRACK_ELEM_FLAT_TO_60_DEG_DOWN_LONG_BASE: + case TRACK_ELEM_FLAT_TO_60_DEG_UP_LONG_BASE: + case TRACK_ELEM_FLAT_TO_60_DEG_DOWN_LONG_BASE: //6d74F1 break; - TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE: - TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE_122: + case TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE: + case TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE_122: //6d74FD break; - TRACK_ELEM_REVERSE_WHOA_BELLY_SLOPE: + case TRACK_ELEM_REVERSE_WHOA_BELLY_SLOPE: + case TRACK_ELEM_AIR_THRUST_VERTICAL_DOWN_TO_LEVEL: //6d7458 break; - TRACK_ELEM_60_DEG_UP_TO_90_DEG_UP: - TRACK_ELEM_90_DEG_DOWN_TO_60_DEG_DOWN: + case TRACK_ELEM_60_DEG_UP_TO_90_DEG_UP: + case TRACK_ELEM_90_DEG_DOWN_TO_60_DEG_DOWN: //6d7515 break; - TRACK_ELEM_90_DEG_UP_TO_60_DEG_UP: - TRACK_ELEM_60_DEG_DOWN_TO_90_DEG_DOWN: + case TRACK_ELEM_90_DEG_UP_TO_60_DEG_UP: + case TRACK_ELEM_60_DEG_DOWN_TO_90_DEG_DOWN: //6d7521 break; - TRACK_ELEM_LEFT_EIGHTH_TO_DIAG: - TRACK_ELEM_LEFT_EIGHTH_TO_ORTHOGONAL: + case TRACK_ELEM_LEFT_EIGHTH_TO_DIAG: + case TRACK_ELEM_LEFT_EIGHTH_TO_ORTHOGONAL: //6d7575 break; - TRACK_ELEM_RIGHT_EIGHTH_TO_DIAG: - TRACK_ELEM_RIGHT_EIGHTH_TO_ORTHOGONAL: + case TRACK_ELEM_RIGHT_EIGHTH_TO_DIAG: + case TRACK_ELEM_RIGHT_EIGHTH_TO_ORTHOGONAL: //6d759C break; - TRACK_ELEM_LEFT_EIGHTH_BANK_TO_DIAG: - TRACK_ELEM_LEFT_EIGHTH_BANK_TO_ORTHOGONAL: + case TRACK_ELEM_LEFT_EIGHTH_BANK_TO_DIAG: + case TRACK_ELEM_LEFT_EIGHTH_BANK_TO_ORTHOGONAL: //6d75C3 break; - TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_DIAG: - TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_ORTHOGONAL: + case TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_DIAG: + case TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_ORTHOGONAL: //6d75D2 break; - TRACK_ELEM_DIAG_FLAT_TO_25_DEG_UP: - TRACK_ELEM_DIAG_25_DEG_DOWN_TO_FLAT: - TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_UP: - TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_UP: - TRACK_ELEM_DIAG_25_DEG_DOWN_TO_LEFT_BANK: - TRACK_ELEM_DIAG_25_DEG_DOWN_TO_RIGHT_BANK: + case TRACK_ELEM_DIAG_FLAT_TO_25_DEG_UP: + case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_FLAT: + case TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_UP: + case TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_UP: + case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_LEFT_BANK: + case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_RIGHT_BANK: //6d7494 break; - TRACK_ELEM_DIAG_25_DEG_UP_TO_60_DEG_UP: - TRACK_ELEM_DIAG_60_DEG_DOWN_TO_25_DEG_DOWN: + case TRACK_ELEM_DIAG_25_DEG_UP_TO_60_DEG_UP: + case TRACK_ELEM_DIAG_60_DEG_DOWN_TO_25_DEG_DOWN: //6D752D break; - TRACK_ELEM_DIAG_60_DEG_UP_TO_25_DEG_UP: - TRACK_ELEM_DIAG_25_DEG_DOWN_TO_60_DEG_DOWN: + case TRACK_ELEM_DIAG_60_DEG_UP_TO_25_DEG_UP: + case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_60_DEG_DOWN: //6D7539 break; - TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT: - TRACK_ELEM_DIAG_FLAT_TO_25_DEG_DOWN: - TRACK_ELEM_DIAG_25_DEG_UP_TO_LEFT_BANK: - TRACK_ELEM_DIAG_25_DEG_UP_TO_RIGHT_BANK: - TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_DOWN: - TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_DOWN: + case TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT: + case TRACK_ELEM_DIAG_FLAT_TO_25_DEG_DOWN: + case TRACK_ELEM_DIAG_25_DEG_UP_TO_LEFT_BANK: + case TRACK_ELEM_DIAG_25_DEG_UP_TO_RIGHT_BANK: + case TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_DOWN: + case TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_DOWN: //6d755D break; - TRACK_ELEM_DIAG_FLAT_TO_60_DEG_UP: - TRACK_ELEM_DIAG_60_DEG_DOWN_TO_FLAT: + case TRACK_ELEM_DIAG_FLAT_TO_60_DEG_UP: + case TRACK_ELEM_DIAG_60_DEG_DOWN_TO_FLAT: //6D7464 break; - TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT: - TRACK_ELEM_DIAG_FLAT_TO_60_DEG_DOWN: + case TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT: + case TRACK_ELEM_DIAG_FLAT_TO_60_DEG_DOWN: //6d7470 break; - TRACK_ELEM_LEFT_BARREL_ROLL_UP_TO_DOWN: - TRACK_ELEM_LEFT_BARREL_ROLL_DOWN_TO_UP: + case TRACK_ELEM_LEFT_BARREL_ROLL_UP_TO_DOWN: + case TRACK_ELEM_LEFT_BARREL_ROLL_DOWN_TO_UP: //6d7581 break; - TRACK_ELEM_RIGHT_BARREL_ROLL_UP_TO_DOWN: - TRACK_ELEM_RIGHT_BARREL_ROLL_DOWN_TO_UP: + case TRACK_ELEM_RIGHT_BARREL_ROLL_UP_TO_DOWN: + case TRACK_ELEM_RIGHT_BARREL_ROLL_DOWN_TO_UP: //6d75A8 break; - TRACK_ELEM_LEFT_BANK_TO_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: + case TRACK_ELEM_LEFT_BANK_TO_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: //6d771C break; - TRACK_ELEM_RIGHT_BANK_TO_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANK_TO_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: //6D7746 break; - TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_LEFT_BANK: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_LEFT_BANK: //6D7731 break; - TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_RIGHT_BANK: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_RIGHT_BANK: //6D775B break; - TRACK_ELEM_LEFT_LARGE_HALF_LOOP_UP: - TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_UP: + case TRACK_ELEM_LEFT_LARGE_HALF_LOOP_UP: + case TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_UP: //6d7666 break; - TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_DOWN: - TRACK_ELEM_LEFT_LARGE_HALF_LOOP_DOWN: + case TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_DOWN: + case TRACK_ELEM_LEFT_LARGE_HALF_LOOP_DOWN: //6d767F break; - //187 - 255 + case TRACK_ELEM_HEARTLINE_TRANSFER_UP: + //6d74A0 + break; + case TRACK_ELEM_HEARTLINE_TRANSFER_DOWN: + //6D74CA + break; + case TRACK_ELEM_MULTIDIM_INVERTED_FLAT_TO_90_DEG_QUATER_LOOP_DOWN: + case TRACK_ELEM_INVERTED_FLAT_TO_90_DEG_QUATER_LOOP_DOWN: + case TRACK_ELEM_MULTIDIM_FLAT_TO_90_DEG_DOWN_QUATER_LOOP: + //6d762D + break; + case TRACK_ELEM_90_DEG_TO_INVERTED_FLAT_QUATER_LOOP_UP: + case TRACK_ELEM_MULTIDIM_90_DEG_UP_TO_INVERTED_FLAT_QUATER_LOOP: + case 255: + //6D7614 + break; + case TRACK_ELEM_AIR_THRUST_TOP_CAP: + //6D744C + break; + case TRACK_ELEM_LEFT_BANKED_QUATER_TURN_3_TILE_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_QUATER_TURN_3_TILE_25_DEG_DOWN: + //6d76C8 + break; + case TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_3_TILE_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_3_TILE_25_DEG_DOWN: + //6d76d7 + break; + case TRACK_ELEM_LEFT_BANKED_QUATER_TURN_5_TILE_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_QUATER_TURN_5_TILE_25_DEG_DOWN: + //6D76E6 + break; + case TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_5_TILE_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_5_TILE_25_DEG_DOWN: + //6d76F5 + break; } int eax, ebx, ecx, edx, esi, edi, ebp; From 9ad290463a17e9f151cba9b002790d9243a432bb Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 25 Oct 2015 15:01:42 +0000 Subject: [PATCH 076/162] prepare hook for sub_6DAB4C --- src/hook.c | 22 ++++++++++++-- src/hook.h | 6 +++- src/openrct2.c | 74 ++++++++++++---------------------------------- src/ride/vehicle.c | 14 +++++++-- 4 files changed, 54 insertions(+), 62 deletions(-) diff --git a/src/hook.c b/src/hook.c index 757d873ce7..70d30af2e5 100644 --- a/src/hook.c +++ b/src/hook.c @@ -30,7 +30,9 @@ void* g_hooktableaddress = 0; int g_hooktableoffset = 0; int g_maxhooks = 1000; -void hookfunc(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister) +registers _returnRegisters; + +void hookfunc(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister, bool useReturnRegisters) { int i = 0; char data[100]; @@ -155,6 +157,15 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in break; } + if (useReturnRegisters) { + // mov ebx, [_returnRegisters.ebx] + data[i++] = 0x8B; + data[i++] = 0x1C; + data[i++] = 0x25; + *((uint32*)&data[i]) = (uint32)(&_returnRegisters.ebx); + i += 4; + } + data[i++] = 0x83; // sub esp, x data[i++] = 0xEC; data[i++] = (signed char)(stacksize * -4) - rargssize; @@ -198,7 +209,7 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in #endif // _WIN32 } -void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister) +void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister, bool useReturnRegisters) { if (!g_hooktableaddress) { size_t size = g_maxhooks * 100; @@ -228,6 +239,11 @@ void addhook(int address, int newaddress, int stacksize, int registerargs[], int // We own the pages with PROT_WRITE | PROT_EXEC, we can simply just memcpy the data memcpy((void *)address, data, i); #endif // _WIN32 - hookfunc(hookaddress, newaddress, stacksize, registerargs, registersreturned, eaxDestinationRegister); + hookfunc(hookaddress, newaddress, stacksize, registerargs, registersreturned, eaxDestinationRegister, useReturnRegisters); g_hooktableoffset++; } + +void hook_setreturnregisters(registers *regs) +{ + _returnRegisters = *regs; +} diff --git a/src/hook.h b/src/hook.h index 7f2289f059..38cf1d1198 100644 --- a/src/hook.h +++ b/src/hook.h @@ -21,6 +21,9 @@ #ifndef _HOOK_H_ #define _HOOK_H_ +#include "addresses.h" +#include "common.h" + enum REGISTER_ARGS { EAX = 1 << 0, EBX = 1 << 1, @@ -32,6 +35,7 @@ enum REGISTER_ARGS { END = 0 }; -void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister); +void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister, bool useReturnRegisters); +void hook_setreturnregisters(registers *regs); #endif \ No newline at end of file diff --git a/src/openrct2.c b/src/openrct2.c index c35dfb2d17..70055979bd 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -40,14 +40,14 @@ #include "util/util.h" #include "world/mapgen.h" -#if defined(__unix__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) #include #include #include #include #include #include -#endif // defined(__unix__) +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) int gOpenRCT2StartupAction = STARTUP_ACTION_TITLE; utf8 gOpenRCT2StartupActionPath[512] = { 0 }; @@ -59,11 +59,11 @@ bool gOpenRCT2Headless = false; bool gOpenRCT2ShowChangelog; -#if defined(__unix__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) void *gDataSegment; void *gTextSegment; int gExeFd; -#endif // defined(__unix__) +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) /** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to 0. */ int _finished; @@ -471,7 +471,7 @@ static bool openrct2_setup_rct2_segment() { // POSIX OSes will run OpenRCT2 as a native application and then load in the Windows PE, mapping the appropriate addresses as // necessary. Windows does not need to do this as OpenRCT2 runs as a DLL loaded from the Windows PE. -#if defined(__unix__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) #define RDATA_OFFSET 0x004A4000 #define DATASEG_OFFSET 0x005E2000 @@ -513,45 +513,8 @@ static bool openrct2_setup_rct2_segment() off_t file_size = 6750208; int len = 0x01429000 - 0x8a4000; // 0xB85000, 12079104 bytes or around 11.5MB - int pageSize = getpagesize(); - int numPages = (len + pageSize - 1) / pageSize; - unsigned char *dummy = malloc(numPages); - int err = mincore((void *)0x8a4000, len, dummy); - bool pagesDirty = false; - if (err != 0) - { - err = errno; -#ifdef __linux__ - // On Linux ENOMEM means all requested range is unmapped - if (err != ENOMEM) - { - pagesDirty = true; - perror("mincore"); - } -#else - pagesDirty = true; - perror("mincore"); -#endif // __linux__ - } else { - log_warning("mincore ok"); - for (int i = 0; i < numPages; i++) - { - if (dummy[i] != 0) - { - pagesDirty = true; - void *start = (void *)0x8a4000 + i * pageSize; - void *end = (void *)0x8a4000 + (i + 1) * pageSize - 1; - log_warning("page %p - %p has flags: %x, you're in for bad time!", start, end, dummy[i]); - } - } - } - free(dummy); - if (pagesDirty) - { - log_error("Found already mapped pages in region we want to claim. This means something accessed memory before we got to and following mmap (or next malloc) call will likely fail."); - } // section: rw data - gDataSegment = mmap((void *)0x8a4000, len, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_SHARED, -1, 0); + gDataSegment = mmap((void *)0x8a4000, len, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_SHARED, 0, 0); if (gDataSegment != (void *)0x8a4000) { log_fatal("mmap failed to get required offset for data segment! got %p, expected %p, errno = %d", gDataSegment, (void *)(0x8a4000), errno); exit(1); @@ -567,7 +530,7 @@ static bool openrct2_setup_rct2_segment() } void *fbase = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, gExeFd, 0); - err = errno; + int err = errno; log_warning("mmapped file to %p", fbase); if (fbase == MAP_FAILED) { @@ -585,7 +548,7 @@ static bool openrct2_setup_rct2_segment() err = errno; log_error("Failed to unmap file! errno = %d", err); } -#endif // defined(__unix__) +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) // Check that the expected data is at various addresses. // Start at 0x9a6000, which is start of .data, to skip the region containing addresses to DLL @@ -609,7 +572,7 @@ static bool openrct2_setup_rct2_segment() static bool openrct2_release_rct2_segment() { bool result = true; -#if defined(__unix__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) int len = 0x01429000 - 0x8a4000; // 0xB85000, 12079104 bytes or around 11.5MB int err; err = munmap(gDataSegment, len); @@ -634,7 +597,7 @@ static bool openrct2_release_rct2_segment() log_error("Failed to close file! errno = %d", err); result = false; } -#endif // defined(__unix__) +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) return result; } @@ -643,14 +606,15 @@ static bool openrct2_release_rct2_segment() */ static void openrct2_setup_rct2_hooks() { - addhook(0x006E732D, (int)gfx_set_dirty_blocks, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0); // remove when all callers are decompiled - addhook(0x006E7499, (int)gfx_redraw_screen_rect, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0); // remove when 0x6E7FF3 is decompiled - addhook(0x006B752C, (int)ride_crash, 0, (int[]){ EDX, EBX, END }, 0, 0); // remove when all callers are decompiled - addhook(0x0069A42F, (int)peep_window_state_update, 0, (int[]){ ESI, END }, 0, 0); // remove when all callers are decompiled - addhook(0x006BB76E, (int)audio_play_sound_panned, 0, (int[]){EAX, EBX, ECX, EDX, EBP, END}, 0, EAX); // remove when all callers are decompiled - addhook(0x006C42D9, (int)scrolling_text_setup, 0, (int[]){EAX, ECX, EBP, END}, 0, EBX); // remove when all callers are decompiled - addhook(0x006C2321, (int)gfx_get_string_width, 0, (int[]){ESI, END}, 0, ECX); // remove when all callers are decompiled - addhook(0x006C2555, (int)format_string, 0, (int[]){EDI, EAX, ECX, END}, 0, 0); // remove when all callers are decompiled + addhook(0x006E732D, (int)gfx_set_dirty_blocks, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0, false); // remove when all callers are decompiled + addhook(0x006E7499, (int)gfx_redraw_screen_rect, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0, false); // remove when 0x6E7FF3 is decompiled + addhook(0x006B752C, (int)ride_crash, 0, (int[]){ EDX, EBX, END }, 0, 0, false); // remove when all callers are decompiled + addhook(0x0069A42F, (int)peep_window_state_update, 0, (int[]){ ESI, END }, 0, 0, false); // remove when all callers are decompiled + addhook(0x006BB76E, (int)audio_play_sound_panned, 0, (int[]){EAX, EBX, ECX, EDX, EBP, END}, EAX, 0, false); // remove when all callers are decompiled + addhook(0x006C42D9, (int)scrolling_text_setup, 0, (int[]){EAX, ECX, EBP, END}, 0, EBX, false); // remove when all callers are decompiled + addhook(0x006C2321, (int)gfx_get_string_width, 0, (int[]){ESI, END}, 0, ECX, false); // remove when all callers are decompiled + addhook(0x006C2555, (int)format_string, 0, (int[]){EDI, EAX, ECX, END}, 0, 0, false); // remove when all callers are decompiled + addhook(0x006DAB4C, (int)sub_6DAB4C, 0, (int[]){ESI, END}, 0, EAX, true); // remove when all callers are decompiled } #if _MSC_VER >= 1900 diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 4f66083e0b..7bf795624c 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -623,11 +623,19 @@ bool sub_6DD365(rct_vehicle *vehicle) int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) { registers regs; - regs.esi = (int)vehicle; - RCT2_CALLFUNC_Y(0x006DAB4C, ®s); + regs.esi = vehicle; + regs.edi = vehicle->vehicle_type; + regs.eax = vehicle->ride_subtype; + regs.edi *= 0x65; + regs.eax = GET_RIDE_ENTRY(regs.eax); + regs.edi += regs.eax; - if (outStation != NULL) *outStation = regs.ebx; + RCT2_CALLFUNC_Y(0x006DAB63, ®s); + + // regs.eax = 0; + // regs.ebx = 0; + hook_setreturnregisters(®s); return regs.eax; } From 96575ba4d85b381bbe6444475ade54fcb4515b42 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 25 Oct 2015 16:34:04 +0000 Subject: [PATCH 077/162] implement sub_6DAB4C_chunk_1 --- src/ride/vehicle.c | 90 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 7bf795624c..d8e3ef2e89 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -616,6 +616,67 @@ bool sub_6DD365(rct_vehicle *vehicle) return RCT2_CALLFUNC_Y(0x006DD365, ®s) & 0x100; } +// 0x0x009A2970 +const sint32 *dword_9A297 = (sint32*)0x009A2970; + +/** + * + * rct2: 0x006DAB6F + */ +static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) +{ + rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle *vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + int verticalG, lateralG; + registers regs; + + RCT2_GLOBAL(0x00F64E2C, uint8) = 0; + RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = vehicle; + RCT2_GLOBAL(0x00F64E18, uint32) = 0; + RCT2_GLOBAL(0x00F64E1C, uint32) = 0xFFFFFFFF; + + if (vehicleEntry->var_12 & (1 << 1)) { + regs.bx = vehicle->var_36 >> 2; + if (regs.bx < 68 || regs.bx >= 87) { + vehicle_get_g_forces(vehicle, &verticalG, &lateralG); + lateralG = abs(lateralG); + if (lateralG <= 150) { + if (dword_9A297[vehicle->var_1F] < 0) { + if (verticalG > -40) { + return; + } + } else if (verticalG > -80) { + return; + } + } + + if (vehicle->var_1F != 8) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 6); + } + } + } else if (vehicleEntry->var_12 & (1 << 2)) { + regs.bx = vehicle->var_36 >> 2; + if (regs.bx < 68 || regs.bx >= 87) { + vehicle_get_g_forces(vehicle, &verticalG, &lateralG); + + if (dword_9A297[vehicle->var_1F] < 0) { + if (verticalG > -45) { + return; + } + } else { + if (verticalG > -80) { + return; + } + } + + if (vehicle->var_1F != 8 && vehicle->var_1F != 55) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 6); + } + } + } +} + /** * * rct2: 0x006DAB4C @@ -624,17 +685,30 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) { registers regs; + rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle *vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + // esi = vehicle + // eax = rideEntry + // edi = vehicleEntry + + if (vehicleEntry->var_12 & (1 << 3)) { + goto loc_6DC3A7; + } + + sub_6DAB4C_chunk_1(vehicle); + +loc_6DAC43: regs.esi = vehicle; - regs.edi = vehicle->vehicle_type; - regs.eax = vehicle->ride_subtype; - regs.edi *= 0x65; - regs.eax = GET_RIDE_ENTRY(regs.eax); - regs.edi += regs.eax; + regs.edi = (int)vehicleEntry - 0x1A; + RCT2_CALLFUNC_Y(0x006DAC43, ®s); + goto end; - RCT2_CALLFUNC_Y(0x006DAB63, ®s); +loc_6DC3A7: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DC3A7, ®s); - // regs.eax = 0; - // regs.ebx = 0; +end: hook_setreturnregisters(®s); return regs.eax; } From 05eac05fa98bff2f11f388bea04c3f9d9990e9ab Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 25 Oct 2015 17:49:54 +0000 Subject: [PATCH 078/162] implement sub_6DAB4C_chunk_2 --- src/ride/vehicle.c | 82 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index d8e3ef2e89..9214e0f83e 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -625,9 +625,7 @@ const sint32 *dword_9A297 = (sint32*)0x009A2970; */ static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) { - rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); - rct_ride_type_vehicle *vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); int verticalG, lateralG; registers regs; @@ -677,6 +675,77 @@ static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) } } +/** + * + * rct2: 0x006DAC43 + */ +static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) +{ + rct_ride *ride = GET_RIDE(vehicle->ride); + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + if (vehicleEntry->var_14 & (1 << 12)) { + sint32 velocity = ride->speed << 16; + if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) { + velocity = 0; + } + vehicle->velocity = velocity; + vehicle->var_2C = 0; + } + + int trackType = vehicle->var_36 >> 2; + switch (trackType) { + case 1: + case 216: + if (ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT || ride_is_block_sectioned(ride)) { + break; + } + return; + case 9: + case 63: + case 123: + case 147: + case 155: + if (ride_is_block_sectioned(ride)) { + break; + } + return; + default: + return; + } + + rct_map_element *trackElement = map_get_track_element_at_of_type( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z >> 3, + trackType + ); + if (trackType == 1) { + if (trackElement->flags & (1 << 5)) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 0x400; + } + } else if (trackType == 123 || trackType == 216 || track_element_is_lift_hill(trackElement)) { + if (!(trackElement->flags & (1 << 5))) { + if (trackType == 216 && vehicle->velocity >= 0) { + if (vehicle->velocity <= 0x20364) { + vehicle->velocity = 0x20364; + vehicle->var_2C = 0; + } else { + vehicle->velocity -= vehicle->velocity >> 4; + vehicle->var_2C = 0; + } + } + return; + } + RCT2_GLOBAL(0x00F64E18, uint32) |= 0x400; + vehicle->var_2C = 0; + if (vehicle->velocity <= 0x20000) { + vehicle->velocity = 0; + } + vehicle->velocity -= vehicle->velocity >> 3; + } +} + /** * * rct2: 0x006DAB4C @@ -685,6 +754,7 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) { registers regs; + rct_ride *ride = GET_RIDE(vehicle->ride); rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle *vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; @@ -697,11 +767,11 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) } sub_6DAB4C_chunk_1(vehicle); + sub_6DAB4C_chunk_2(vehicle); -loc_6DAC43: +loc_6DADAE: regs.esi = vehicle; - regs.edi = (int)vehicleEntry - 0x1A; - RCT2_CALLFUNC_Y(0x006DAC43, ®s); + RCT2_CALLFUNC_Y(0x006DADAE, ®s); goto end; loc_6DC3A7: From adda80f4bad66a5e6230406171b698cfce81e985 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 25 Oct 2015 18:31:51 +0000 Subject: [PATCH 079/162] implement sub_6DAB4C_chunk_3 --- src/ride/vehicle.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 9214e0f83e..e708f0c9bd 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -746,6 +746,32 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) } } +/** + * + * rct2: 0x006DADAE + */ +static void sub_6DAB4C_chunk_3(rct_vehicle *vehicle) +{ + sint32 nextVelocity = vehicle->var_2C + vehicle->velocity; + if (vehicle->var_48 & (1 << 7)) { + nextVelocity = 0; + } + if (vehicle->var_48 & (1 << 10)) { + vehicle->var_D2--; + if (vehicle->var_D2 == -70) { + vehicle->var_48 &= ~(1 << 10); + } + if (vehicle->var_D2 >= 0) { + nextVelocity = 0; + vehicle->var_2C = 0; + } + } + vehicle->velocity = nextVelocity; + + RCT2_GLOBAL(0x00F64E08, sint32) = nextVelocity; + RCT2_GLOBAL(0x00F64E0C, sint32) = (nextVelocity >> 10) * 42; +} + /** * * rct2: 0x006DAB4C @@ -768,10 +794,16 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) sub_6DAB4C_chunk_1(vehicle); sub_6DAB4C_chunk_2(vehicle); + sub_6DAB4C_chunk_3(vehicle); -loc_6DADAE: + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { + vehicle = vehicle_get_tail(vehicle); + } + RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = vehicle; + +loc_6DAE27: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DADAE, ®s); + RCT2_CALLFUNC_Y(0x006DAE27, ®s); goto end; loc_6DC3A7: From 9ffb9ec353aec8959983e70c8671836de518e782 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 25 Oct 2015 19:23:42 +0000 Subject: [PATCH 080/162] implement loc_6DAE27 --- src/ride/vehicle.c | 82 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 10 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index e708f0c9bd..fc65195875 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -617,7 +617,7 @@ bool sub_6DD365(rct_vehicle *vehicle) } // 0x0x009A2970 -const sint32 *dword_9A297 = (sint32*)0x009A2970; +const sint32 *dword_9A2970 = (sint32*)0x009A2970; /** * @@ -627,7 +627,6 @@ static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) { rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); int verticalG, lateralG; - registers regs; RCT2_GLOBAL(0x00F64E2C, uint8) = 0; RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = vehicle; @@ -635,12 +634,12 @@ static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) RCT2_GLOBAL(0x00F64E1C, uint32) = 0xFFFFFFFF; if (vehicleEntry->var_12 & (1 << 1)) { - regs.bx = vehicle->var_36 >> 2; - if (regs.bx < 68 || regs.bx >= 87) { + int trackType = vehicle->track_type >> 2; + if (trackType < 68 || trackType >= 87) { vehicle_get_g_forces(vehicle, &verticalG, &lateralG); lateralG = abs(lateralG); if (lateralG <= 150) { - if (dword_9A297[vehicle->var_1F] < 0) { + if (dword_9A2970[vehicle->var_1F] < 0) { if (verticalG > -40) { return; } @@ -654,11 +653,11 @@ static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) } } } else if (vehicleEntry->var_12 & (1 << 2)) { - regs.bx = vehicle->var_36 >> 2; - if (regs.bx < 68 || regs.bx >= 87) { + int trackType = vehicle->track_type >> 2; + if (trackType < 68 || trackType >= 87) { vehicle_get_g_forces(vehicle, &verticalG, &lateralG); - if (dword_9A297[vehicle->var_1F] < 0) { + if (dword_9A2970[vehicle->var_1F] < 0) { if (verticalG > -45) { return; } @@ -693,7 +692,7 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) vehicle->var_2C = 0; } - int trackType = vehicle->var_36 >> 2; + int trackType = vehicle->track_type >> 2; switch (trackType) { case 1: case 216: @@ -772,6 +771,33 @@ static void sub_6DAB4C_chunk_3(rct_vehicle *vehicle) RCT2_GLOBAL(0x00F64E0C, sint32) = (nextVelocity >> 10) * 42; } +/** + * + * rct2: 0x006D6776 + */ +static void sub_6D6776(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006D6776, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + +/** + * + * rct2: 0x006D661F + */ +static void sub_6D661F(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006D661F, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + +/** + * + * rct2: 0x006D63D4 + */ +static void sub_6D63D4(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006D63D4, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + /** * * rct2: 0x006DAB4C @@ -802,8 +828,44 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = vehicle; loc_6DAE27: + if (vehicleEntry->var_14 & (1 << 1)) { + sub_6D6776(vehicle); + } + if (vehicleEntry->var_14 & (1 << 2)) { + sub_6D661F(vehicle); + } + if ((vehicleEntry->var_14 & (1 << 7)) || (vehicleEntry->var_14 & (1 << 8))) { + sub_6D63D4(vehicle); + } + vehicle->var_2C = dword_9A2970[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32) = 1; + + regs.eax = RCT2_GLOBAL(0x00F64E0C, sint32) + vehicle->var_24; + vehicle->var_24 = regs.eax; + if (regs.eax < 0) { + goto loc_6DBA13; + } + if (regs.eax < 0x368A) { + goto loc_6DBF3E; + } + vehicle->var_B8 &= ~(1 << 1); + RCT2_GLOBAL(0x00F64E20, uint32) = vehicle->x | (vehicle->y << 16); + RCT2_GLOBAL(0x00F64E24, uint16) = vehicle->z; + invalidate_sprite_2((rct_sprite*)vehicle); + +loc_6DAEB9: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DAE27, ®s); + RCT2_CALLFUNC_Y(0x006DAEB9, ®s); + goto end; + +loc_6DBA13: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DBA13, ®s); + goto end; + +loc_6DBF3E: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DBF3E, ®s); goto end; loc_6DC3A7: From 3280c2410034fd931ae7bf7f3ea3adf2cc07378d Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 25 Oct 2015 20:09:53 +0000 Subject: [PATCH 081/162] label update flags for vehicle --- src/ride/vehicle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index fc65195875..41747f1dfd 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -752,13 +752,13 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) static void sub_6DAB4C_chunk_3(rct_vehicle *vehicle) { sint32 nextVelocity = vehicle->var_2C + vehicle->velocity; - if (vehicle->var_48 & (1 << 7)) { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_7) { nextVelocity = 0; } - if (vehicle->var_48 & (1 << 10)) { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_10) { vehicle->var_D2--; if (vehicle->var_D2 == -70) { - vehicle->var_48 &= ~(1 << 10); + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_10; } if (vehicle->var_D2 >= 0) { nextVelocity = 0; From 2df54c60d0fd16b18018ce0ad47e33fc9950515b Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 1 Nov 2015 13:12:43 +0000 Subject: [PATCH 082/162] implement more sub_6DAB4C --- src/ride/ride_data.c | 4 ++- src/ride/vehicle.c | 72 +++++++++++++++++++++++++++++++++++++++++--- src/ride/vehicle.h | 7 +++-- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/ride/ride_data.c b/src/ride/ride_data.c index a41ceda1c4..bd289aed0c 100644 --- a/src/ride/ride_data.c +++ b/src/ride/ride_data.c @@ -1289,7 +1289,9 @@ const rct_ride_type_vehicle CableLiftVehicle = { .no_seating_rows = 0, .spinning_inertia = 0, .spinning_friction = 255, - .pad_57 = { 0,0,0 }, + .pad_57 = 0, + .var_58 = 0, + .pad_59 = 0, .var_5A = 0, .powered_acceleration = 0, .powered_max_speed = 0, diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 41747f1dfd..ae7f47c742 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -777,7 +777,8 @@ static void sub_6DAB4C_chunk_3(rct_vehicle *vehicle) */ static void sub_6D6776(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006D6776, 0, 0, 0, 0, (int)vehicle, 0, 0); + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + RCT2_CALLPROC_X(0x006D6776, 0, 0, 0, 0, (int)vehicle, (int)vehicleEntry, 0); } /** @@ -808,8 +809,8 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) rct_ride *ride = GET_RIDE(vehicle->ride); rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); - rct_ride_type_vehicle *vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + // esi = vehicle // eax = rideEntry // edi = vehicleEntry @@ -854,8 +855,71 @@ loc_6DAE27: invalidate_sprite_2((rct_sprite*)vehicle); loc_6DAEB9: + regs.edi = vehicle->track_type; + regs.cx = vehicle->track_type >> 2; + + int trackType = vehicle->track_type >> 2; + if (trackType == 197 || trackType == 198) { + if (vehicle->var_34 == 80) { + vehicle->vehicle_type ^= 1; + vehicleEntry = vehicle_get_vehicle_entry(vehicle); + } + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0x40000) { + vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 8; + } else if (RCT2_GLOBAL(0x00F64E08, sint32) < 0x20000) { + vehicle->var_2C = 0x50000; + } + } else if (trackType == TRACK_ELEM_BRAKES) { + if (!( + ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN && + ride->breakdown_reason_pending != BREAKDOWN_BRAKES_FAILURE && + ride->mechanic_status == RIDE_MECHANIC_STATUS_4 + )) { + regs.eax = vehicle->var_CF << 16; + if (regs.eax < RCT2_GLOBAL(0x00F64E08, sint32)) { + vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; + } else if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x0F)) { + if (RCT2_GLOBAL(0x00F64E2C, uint8) == 0) { + RCT2_GLOBAL(0x00F64E2C, uint8)++; + sound_play_panned(SOUND_51, 0x8001, vehicle->x, vehicle->y, vehicle->z); + } + } + } + } + + if ((trackType == TRACK_ELEM_FLAT && ride->type == RIDE_TYPE_REVERSE_FREEFALL_COASTER) || + (trackType == TRACK_ELEM_POWERED_LIFT) + ) { + vehicle->var_2C = RCT2_GLOBAL(0x0097CF40 + (ride->type * 8) + 7, uint8) << 10; + } + if (trackType == TRACK_ELEM_BRAKE_FOR_DROP) { + if (!vehicle->is_child) { + if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_10)) { + if (vehicle->var_34 >= 8) { + vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; + if (vehicle->var_34 >= 24) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_10; + vehicle->var_D2 = 90; + } + } + } + } + } + if (trackType == TRACK_ELEM_LOG_FLUME_REVERSER) { + if (vehicle->var_34 != 16 || vehicle->velocity < 0x40000) { + if (vehicle->var_34 == 32) { + vehicle->vehicle_type = vehicleEntry->var_58; + vehicleEntry = vehicle_get_vehicle_entry(vehicle); + } + } else { + vehicle->var_34 += 17; + } + } + +loc_6DB06B: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DAEB9, ®s); + regs.edi = vehicle->track_type; + RCT2_CALLFUNC_Y(0x006DB06B, ®s); goto end; loc_6DBA13: diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 1f8f175f8b..07f4b00691 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -67,7 +67,9 @@ typedef struct { uint8 no_seating_rows; // 0x54 , 0x6E uint8 spinning_inertia; // 0x55 , 0x6F uint8 spinning_friction; // 0x56 , 0x70 - uint8 pad_57[0x3]; + uint8 pad_57; // 0x57 , 0x71 + uint8 var_58; // 0x58 , 0x72 + uint8 pad_59; // 0x59 , 0x73 uint8 var_5A; // 0x5A , 0x74 uint8 powered_acceleration; // 0x5B , 0x75 uint8 powered_max_speed; // 0x5C , 0x76 @@ -162,7 +164,8 @@ typedef struct { uint8 var_CE; uint8 num_laps; // 0xCE }; - uint8 pad_CF[0x03]; + uint8 var_CF; + uint8 pad_D0[0x02]; sint8 var_D2; uint8 var_D3; uint8 var_D4; From 4f567094551c7ebe7ba0d422015075b53f6ae405 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 1 Nov 2015 14:58:46 +0000 Subject: [PATCH 083/162] implement more sub_6DAB4C --- src/ride/track.c | 24 +++++++++++++ src/ride/track.h | 1 + src/ride/vehicle.c | 53 +++++++++++++++++++++++++++-- src/world/map.c | 84 +++++++++++++++++++++++++++++----------------- src/world/map.h | 1 + 5 files changed, 131 insertions(+), 32 deletions(-) diff --git a/src/ride/track.c b/src/ride/track.c index e367b6b9c3..3a77514fb5 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -4922,6 +4922,30 @@ bool track_element_is_lift_hill(rct_map_element *trackElement) return trackElement->type & 0x80; } +/** + * Checks if a track element is recognised as the beginning of a block. + * A beginning of a block can be the end of a station, the end of a lift hill, + * or a block brake. + */ +bool track_element_is_block_start(rct_map_element *trackElement) +{ + switch (trackElement->properties.track.type) { + case TRACK_ELEM_END_STATION: + case TRACK_ELEM_CABLE_LIFT_HILL: + case 216: + return true; + case TRACK_ELEM_25_DEG_UP_TO_FLAT: + case TRACK_ELEM_60_DEG_UP_TO_FLAT: + case TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT: + case TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT: + if (track_element_is_lift_hill(trackElement)) { + return true; + } + break; + } + return false; +} + bool track_element_is_cable_lift(rct_map_element *trackElement) { return trackElement->properties.track.colour & TRACK_ELEMENT_COLOUR_FLAG_CABLE_LIFT; } diff --git a/src/ride/track.h b/src/ride/track.h index 5690767666..a973cba0c4 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -547,6 +547,7 @@ void track_get_back(rct_xy_element *input, rct_xy_element *output); void track_get_front(rct_xy_element *input, rct_xy_element *output); bool track_element_is_lift_hill(rct_map_element *trackElement); +bool track_element_is_block_start(rct_map_element *trackElement); bool track_element_is_cable_lift(rct_map_element *trackElement); void track_element_set_cable_lift(rct_map_element *trackElement); diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index ae7f47c742..f27dbbed00 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -917,9 +917,58 @@ loc_6DAEB9: } loc_6DB06B: + regs.ax = vehicle->var_34 + 1; + regs.ecx = vehicle->var_CD; + regs.ecx = RCT2_ADDRESS(0x008B8F30, uint32)[regs.ecx]; + regs.edi = RCT2_GLOBAL(regs.ecx + (vehicle->track_type * 4), uint32); + if (regs.ax < RCT2_GLOBAL(regs.edi - 2, uint16)) { + goto loc_6DB59A; + } + + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + rct_map_element *mapElement = map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z >> 3, + trackType, + 0 + ); + if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 0x800; + } + + if (!track_element_is_block_start(mapElement)) { + goto loc_6DB2BD; + } + + if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { + goto loc_6DB2BD; + } + RCT2_GLOBAL(regs.edi + 1, uint8) |= 0x20; + if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { + if (!(rideEntry->vehicles[0].var_14 & (1 << 3))) { + sound_play_panned(SOUND_49, 0x8001, vehicle->track_x, vehicle->track_y, vehicle->track_z); + } + } + map_invalidate_tile(vehicle->track_x, vehicle->track_z, mapElement->base_height * 8, mapElement->clearance_height * 8); + +loc_6DB1B0: regs.esi = vehicle; - regs.edi = vehicle->track_type; - RCT2_CALLFUNC_Y(0x006DB06B, ®s); + regs.edi = mapElement; + RCT2_CALLFUNC_Y(0x006DB1B0, ®s); + goto end; + +loc_6DB2BD: + regs.eax = trackType; + regs.esi = vehicle; + regs.edi = mapElement; + RCT2_CALLFUNC_Y(0x006DB2BD, ®s); + goto end; + +loc_6DB59A: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DB59A, ®s); goto end; loc_6DBA13: diff --git a/src/world/map.c b/src/world/map.c index 640851372f..42a80537f3 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -897,7 +897,7 @@ void game_command_remove_large_scenery(int* eax, int* ebx, int* ecx, int* edx, i } *ebx = scenery_entry->large_scenery.removal_price * 10; - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY || + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY || calculate_cost == false){ *ebx = 0; } @@ -985,7 +985,7 @@ void game_command_set_scenery_colour(int* eax, int* ebx, int* ecx, int* edx, int // Previously it would do a search for type of bh (set from calling function) instead of just small scenery // Unsure if this was a mistake. rct_map_element* map_element = map_get_small_scenery_element_at(x, y, base_height, scenery_type); - + if (map_element == NULL) { *ebx = 0; return; @@ -1053,7 +1053,7 @@ void game_command_set_fence_colour(int* eax, int* ebx, int* ecx, int* edx, int* rct_scenery_entry* scenery_entry = g_wallSceneryEntries[map_element->properties.fence.type]; map_element->properties.fence.item[1] &= 0xE0; map_element->properties.fence.item[1] |= color1; - map_element->properties.fence.item[1] &= 0x1F; + map_element->properties.fence.item[1] &= 0x1F; map_element->flags &= 0x9F; map_element->properties.fence.item[1] |= (color2 & 0x7) * 32; map_element->flags |= (color2 & 0x18) * 4; @@ -1093,7 +1093,7 @@ void game_command_set_large_scenery_colour(int* eax, int* ebx, int* ecx, int* ed *ebx = 0; return; } - + if((flags & GAME_COMMAND_FLAG_GHOST) && !(map_element->flags & MAP_ELEMENT_FLAG_GHOST)){ *ebx = 0; return; @@ -1134,10 +1134,10 @@ void game_command_set_large_scenery_colour(int* eax, int* ebx, int* ecx, int* ed if(flags & GAME_COMMAND_FLAG_APPLY){ rct_map_element* mapElement = map_get_large_scenery_segment( - currentTile.x, - currentTile.y, - base_height, - map_element_direction, + currentTile.x, + currentTile.y, + base_height, + map_element_direction, i); mapElement->properties.scenerymultiple.colour[0] &= 0xE0; @@ -1567,7 +1567,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl return MONEY32_UNDEFINED; } } - + //Uncomment to use vanilla code /* registers regs = {0}; @@ -1581,7 +1581,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl regs.ebp = 0; RCT2_CALLFUNC_Y(0x006639FE, ®s); return regs.ebx; */ - + RCT2_GLOBAL(0x9E2E18, money32) = MONEY(0, 0); if(flags & GAME_COMMAND_FLAG_APPLY) { @@ -1589,10 +1589,10 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl map_remove_walls_at(x, y, height * 8 - 16, height * 8 + 32); } RCT2_GLOBAL(0x9E2E18, money32) += MONEY(20, 0); - + //Check for obstructing scenery - rct_map_element *mapElement = map_get_first_element_at(x / 32, y / 32); - do{ + rct_map_element *mapElement = map_get_first_element_at(x / 32, y / 32); + do{ if(map_element_get_type(mapElement) != MAP_ELEMENT_TYPE_SCENERY) continue; if(height > mapElement->clearance_height) @@ -1609,7 +1609,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl if(flags & GAME_COMMAND_FLAG_APPLY) map_element_remove(mapElement--); }while(!map_element_is_last_for_tile(mapElement++)); - + //Check for ride support limits if(gCheatsDisableSupportLimits==false) { @@ -1653,7 +1653,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl } } } - + zCorner = height; if(style & 0xF) { @@ -1663,14 +1663,14 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl zCorner += 2; } } - + if(map_can_construct_with_clear_at(x, y, height, zCorner, RCT2_ADDRESS(0x663CB9, void), 0xF) == false) return MONEY32_UNDEFINED; - + mapElement = map_get_first_element_at(x / 32, y / 32); - do{ + do{ int elementType = map_element_get_type(mapElement); - + if(elementType == MAP_ELEMENT_TYPE_FENCE) continue; if(elementType == MAP_ELEMENT_TYPE_SCENERY) @@ -1694,7 +1694,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl return MONEY32_UNDEFINED; } }while(!map_element_is_last_for_tile(mapElement++)); - + if(flags & GAME_COMMAND_FLAG_APPLY) { surfaceElement = map_get_surface_element_at(x / 32, y / 32); @@ -3323,7 +3323,7 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in } } - + sint16 maxHeight = 0xFFFF; for (rct_large_scenery_tile* tile = scenery_entry->large_scenery.tiles; tile->x_offset != -1; @@ -3335,7 +3335,7 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in }; rotate_map_coordinates(&curTile.x, &curTile.y, rotation); - + curTile.x += x; curTile.y += y; @@ -3440,8 +3440,8 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in new_map_element->clearance_height = zHigh; new_map_element->type = MAP_ELEMENT_TYPE_SCENERY_MULTIPLE | rotation; - new_map_element->properties.scenerymultiple.type = - (tile_num << 10) | + new_map_element->properties.scenerymultiple.type = + (tile_num << 10) | entry_index; new_map_element->properties.scenerymultiple.colour[0] = color1; @@ -4895,7 +4895,7 @@ void game_command_set_banner_style(int* eax, int* ebx, int* ecx, int* edx, int* *ebx = MONEY32_UNDEFINED; return; } - + map_element->properties.banner.flags = 0xFF; if (banner->flags & BANNER_FLAG_NO_ENTRY){ map_element->properties.banner.flags &= ~(1 << map_element->properties.banner.position); @@ -4930,7 +4930,7 @@ void game_command_set_banner_style(int* eax, int* ebx, int* ecx, int* edx, int* *ebx = 0; } -void game_command_set_sign_style(int* eax, int* ebx, int* ecx, int* edx, int* esi, int* edi, int* ebp) { +void game_command_set_sign_style(int* eax, int* ebx, int* ecx, int* edx, int* esi, int* edi, int* ebp) { uint8 bannerId = *ecx & 0xFF; rct_banner *banner = &gBanners[bannerId]; int x = banner->x << 5; @@ -4938,9 +4938,9 @@ void game_command_set_sign_style(int* eax, int* ebx, int* ecx, int* edx, int* es uint8 mainColour = (uint8)*edx; uint8 textColour = (uint8)*edi; - + if (*ebp == 0) { // small sign - + rct_map_element* map_element = map_get_first_element_at(x / 32, y / 32); bool fence_found = false; do{ @@ -4998,7 +4998,7 @@ void game_command_set_sign_style(int* eax, int* ebx, int* ecx, int* edx, int* es } /** - * Gets the map element at x, y, z. + * Gets the track element at x, y, z. * @param x x units, not tiles. * @param y y units, not tiles. * @param z Base height. @@ -5017,10 +5017,11 @@ rct_map_element *map_get_track_element_at(int x, int y, int z) } /** - * Gets the map element at x, y, z. + * Gets the track element at x, y, z that is the given track type. * @param x x units, not tiles. * @param y y units, not tiles. * @param z Base height. + * @param trackType */ rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int trackType) { @@ -5035,3 +5036,26 @@ rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int track return NULL; } + +/** + * Gets the track element at x, y, z that is the given track type and sequence. + * @param x x units, not tiles. + * @param y y units, not tiles. + * @param z Base height. + * @param trackType + * @param sequence + */ +rct_map_element *map_get_track_element_at_of_type_seq(int x, int y, int z, int trackType, int sequence) +{ + rct_map_element *mapElement = map_get_first_element_at(x >> 5, y >> 5); + do { + if (map_element_get_type(mapElement) != MAP_ELEMENT_TYPE_TRACK) continue; + if (mapElement->base_height != z) continue; + if (mapElement->properties.track.type != trackType) continue; + if ((mapElement->properties.track.sequence & 0x0F) != sequence) continue; + + return mapElement; + } while (!map_element_is_last_for_tile(mapElement++)); + + return NULL; +} diff --git a/src/world/map.h b/src/world/map.h index 705df960c5..892dea6b13 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -392,5 +392,6 @@ bool map_large_scenery_get_origin( rct_map_element *map_get_track_element_at(int x, int y, int z); rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int trackType); +rct_map_element *map_get_track_element_at_of_type_seq(int x, int y, int z, int trackType, int sequence); #endif From 5d2bd6b6828aa31256f832872d4ce6974b10ec35 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 1 Nov 2015 15:50:38 +0000 Subject: [PATCH 084/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 61 +++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index f27dbbed00..9e1f16be30 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -771,6 +771,38 @@ static void sub_6DAB4C_chunk_3(rct_vehicle *vehicle) RCT2_GLOBAL(0x00F64E0C, sint32) = (nextVelocity >> 10) * 42; } +static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) +{ + int x = vehicle->track_x; + int y = vehicle->track_y; + int z = vehicle->track_z; + track_begin_end trackBeginEnd; + do { + if (!track_block_get_previous(x, y, mapElement, &trackBeginEnd)) { + return; + } + if (trackBeginEnd.begin_x == vehicle->track_x && trackBeginEnd.begin_y == vehicle->track_y) { + return; + } + + x = trackBeginEnd.begin_x; + y = trackBeginEnd.begin_y; + z = trackBeginEnd.begin_z; + } while (track_element_is_block_start(trackBeginEnd.begin_element)); + + mapElement = map_get_track_element_at(x, y, z >> 3); + mapElement->flags &= ~(1 << 5); + map_invalidate_element(x, y, mapElement); + + int trackType = mapElement->properties.track.type; + if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { + rct_ride *ride = GET_RIDE(vehicle->ride); + if (ride_is_block_sectioned(ride)) { + sound_play_panned(SOUND_48, 0x8001, x, y, z); + } + } +} + /** * * rct2: 0x006D6776 @@ -916,7 +948,6 @@ loc_6DAEB9: } } -loc_6DB06B: regs.ax = vehicle->var_34 + 1; regs.ecx = vehicle->var_CD; regs.ecx = RCT2_ADDRESS(0x008B8F30, uint32)[regs.ecx]; @@ -938,26 +969,18 @@ loc_6DB06B: RCT2_GLOBAL(0x00F64E18, uint32) |= 0x800; } - if (!track_element_is_block_start(mapElement)) { - goto loc_6DB2BD; - } - - if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { - goto loc_6DB2BD; - } - RCT2_GLOBAL(regs.edi + 1, uint8) |= 0x20; - if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { - if (!(rideEntry->vehicles[0].var_14 & (1 << 3))) { - sound_play_panned(SOUND_49, 0x8001, vehicle->track_x, vehicle->track_y, vehicle->track_z); + if (track_element_is_block_start(mapElement)) { + if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { + RCT2_GLOBAL(regs.edi + 1, uint8) |= 0x20; + if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { + if (!(rideEntry->vehicles[0].var_14 & (1 << 3))) { + sound_play_panned(SOUND_49, 0x8001, vehicle->track_x, vehicle->track_y, vehicle->track_z); + } + } + map_invalidate_element(vehicle->track_x, vehicle->track_z, mapElement); + loc_6DB1B0(vehicle, mapElement); } } - map_invalidate_tile(vehicle->track_x, vehicle->track_z, mapElement->base_height * 8, mapElement->clearance_height * 8); - -loc_6DB1B0: - regs.esi = vehicle; - regs.edi = mapElement; - RCT2_CALLFUNC_Y(0x006DB1B0, ®s); - goto end; loc_6DB2BD: regs.eax = trackType; From 65c129568d1b59015ec139530093f37905a7b781 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 21 Nov 2015 11:59:38 +0000 Subject: [PATCH 085/162] fix play sound calls for sub_6DAB4C --- src/ride/vehicle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 9e1f16be30..52afae38b0 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -798,7 +798,7 @@ static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { rct_ride *ride = GET_RIDE(vehicle->ride); if (ride_is_block_sectioned(ride)) { - sound_play_panned(SOUND_48, 0x8001, x, y, z); + audio_play_sound_at_location(SOUND_48, x, y, z); } } } @@ -913,7 +913,7 @@ loc_6DAEB9: } else if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x0F)) { if (RCT2_GLOBAL(0x00F64E2C, uint8) == 0) { RCT2_GLOBAL(0x00F64E2C, uint8)++; - sound_play_panned(SOUND_51, 0x8001, vehicle->x, vehicle->y, vehicle->z); + audio_play_sound_at_location(SOUND_51, vehicle->x, vehicle->y, vehicle->z); } } } @@ -974,7 +974,7 @@ loc_6DAEB9: RCT2_GLOBAL(regs.edi + 1, uint8) |= 0x20; if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { if (!(rideEntry->vehicles[0].var_14 & (1 << 3))) { - sound_play_panned(SOUND_49, 0x8001, vehicle->track_x, vehicle->track_y, vehicle->track_z); + audio_play_sound_at_location(SOUND_49, vehicle->track_x, vehicle->track_y, vehicle->track_z); } } map_invalidate_element(vehicle->track_x, vehicle->track_z, mapElement); From 1527a443b8770d9e17ad2bf8e77297327e4f82be Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 21 Nov 2015 14:20:52 +0000 Subject: [PATCH 086/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 85 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 52afae38b0..a0a1b69dae 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -831,6 +831,15 @@ static void sub_6D63D4(rct_vehicle *vehicle) RCT2_CALLPROC_X(0x006D63D4, 0, 0, 0, 0, (int)vehicle, 0, 0); } +/** + * + * rct2: 0x006DEE93 + */ +static void vehicle_update_scenery_door(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006DEE93, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + /** * * rct2: 0x006DAB4C @@ -983,10 +992,77 @@ loc_6DAEB9: } loc_6DB2BD: - regs.eax = trackType; + // TODO check if getting the vehicle entry again is necessary + vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + if (vehicleEntry->var_12 & (1 << 8)) { + vehicle_update_scenery_door(vehicle); + } + + switch (vehicle->var_CD) { + default: + goto loc_6DB358; + case 2: + case 3: + vehicle->var_CD = 2; + goto loc_6DB32A; + case 4: + vehicle->var_CD = 1; + goto loc_6DB358; + case 7: + vehicle->var_CD = 6; + goto loc_6DB358; + case 8: + vehicle->var_CD = 5; + goto loc_6DB358; + } + +loc_6DB32A: + { + track_begin_end trackBeginEnd; + if (!track_block_get_previous(vehicle->track_x, vehicle->track_y, mapElement, &trackBeginEnd)) { + goto loc_6DB94A; + } + regs.eax = trackBeginEnd.begin_x; + regs.ecx = trackBeginEnd.begin_y; + regs.edx = trackBeginEnd.begin_z; + regs.bl = trackBeginEnd.begin_direction; + } + goto loc_6DB41D; + +loc_6DB358: + { + rct_xy_element xyElement; + int z, direction; + xyElement.x = vehicle->track_x; + xyElement.y = vehicle->track_y; + xyElement.element = mapElement; + if (!track_block_get_next(&xyElement, &xyElement, &z, &direction)) { + goto loc_6DB94A; + } + mapElement = xyElement.element; + regs.eax = xyElement.x; + regs.ecx = xyElement.y; + regs.edx = z; + regs.bl = direction; + } + if (mapElement->properties.track.type == 211 || + mapElement->properties.track.type == 212 + ) { + if (!vehicle->is_child && vehicle->velocity <= 0x30000) { + vehicle->velocity = 0; + } + } + +// loc_6DB38B: regs.esi = vehicle; regs.edi = mapElement; - RCT2_CALLFUNC_Y(0x006DB2BD, ®s); + RCT2_CALLFUNC_Y(0x006DB38B, ®s); + goto end; + +loc_6DB41D: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DB41D, ®s); goto end; loc_6DB59A: @@ -994,6 +1070,11 @@ loc_6DB59A: RCT2_CALLFUNC_Y(0x006DB59A, ®s); goto end; +loc_6DB94A: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DB94A, ®s); + goto end; + loc_6DBA13: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DBA13, ®s); From eaef1bf08ee3b1bc3068a1d9d46a4fe9da7d3d58 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 22 Nov 2015 12:14:53 +0000 Subject: [PATCH 087/162] implement more sub_6DAB4C --- src/ride/track.c | 42 +++++++++++++++++++++++------------------- src/ride/track.h | 3 +++ src/ride/vehicle.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/src/ride/track.c b/src/ride/track.c index 3a77514fb5..01fdd09311 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -2385,33 +2385,16 @@ int track_delete() int track_is_connected_by_shape(rct_map_element *a, rct_map_element *b) { int trackType, aBank, aAngle, bBank, bAngle; - rct_ride *ride; - ride = GET_RIDE(a->properties.track.ride_index); trackType = a->properties.track.type; aBank = gTrackDefinitions[trackType].bank_end; aAngle = gTrackDefinitions[trackType].vangle_end; - if (RideData4[ride->type].flags & RIDE_TYPE_FLAG4_3) { - if (a->properties.track.colour & 4) { - if (aBank == TRACK_BANK_NONE) - aBank = TRACK_BANK_UPSIDE_DOWN; - else if (aBank == TRACK_BANK_UPSIDE_DOWN) - aBank = TRACK_BANK_NONE; - } - } + aBank = track_get_actual_bank(a, aBank); - ride = GET_RIDE(b->properties.track.ride_index); trackType = b->properties.track.type; bBank = gTrackDefinitions[trackType].bank_start; bAngle = gTrackDefinitions[trackType].vangle_start; - if (RideData4[ride->type].flags & RIDE_TYPE_FLAG4_3) { - if (b->properties.track.colour & 4) { - if (bBank == TRACK_BANK_NONE) - bBank = TRACK_BANK_UPSIDE_DOWN; - else if (bBank == TRACK_BANK_UPSIDE_DOWN) - bBank = TRACK_BANK_NONE; - } - } + bBank = track_get_actual_bank(b, bBank); return aBank == bBank && aAngle == bAngle; } @@ -4957,3 +4940,24 @@ void track_element_set_cable_lift(rct_map_element *trackElement) { void track_element_clear_cable_lift(rct_map_element *trackElement) { trackElement->properties.track.colour &= ~TRACK_ELEMENT_COLOUR_FLAG_CABLE_LIFT; } + +int track_get_actual_bank(rct_map_element *mapElement, int bank) +{ + rct_ride *ride = GET_RIDE(mapElement->properties.track.ride_index); + int trackColour = mapElement->properties.track.colour; + return track_get_actual_bank_2(ride->type, trackColour, bank); +} + +int track_get_actual_bank_2(int rideType, int trackColour, int bank) +{ + if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_3) { + if (trackColour & 4) { + if (bank == TRACK_BANK_NONE) { + bank = TRACK_BANK_UPSIDE_DOWN; + } else if (bank == TRACK_BANK_UPSIDE_DOWN) { + bank = TRACK_BANK_NONE; + } + } + } + return bank; +} diff --git a/src/ride/track.h b/src/ride/track.h index a973cba0c4..c526f7d5f2 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -553,4 +553,7 @@ bool track_element_is_cable_lift(rct_map_element *trackElement); void track_element_set_cable_lift(rct_map_element *trackElement); void track_element_clear_cable_lift(rct_map_element *trackElement); +int track_get_actual_bank(rct_map_element *mapElement, int bank); +int track_get_actual_bank_2(int rideType, int trackColour, int bank); + #endif diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index a0a1b69dae..212080056a 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -840,6 +840,33 @@ static void vehicle_update_scenery_door(rct_vehicle *vehicle) RCT2_CALLPROC_X(0x006DEE93, 0, 0, 0, 0, (int)vehicle, 0, 0); } +/** + * + * rct2: 0x006DB38B + */ +static bool loc_6DB38B(rct_vehicle *vehicle, rct_map_element *mapElement) +{ + uint8 colourThingToXor = (vehicle->update_flags >> 9) & 8; + int trackType = mapElement->properties.track.type; + + // Get bank + int rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; + int trackColour = mapElement->properties.track.colour ^ colourThingToXor; + int bankStart = gTrackDefinitions[trackType].bank_start; + bankStart = track_get_actual_bank_2(rideType, trackColour, bankStart); + + // Get vangle + int vangleStart = gTrackDefinitions[trackType].vangle_start; + + // ? + uint16 angleAndBank = vangleStart | (bankStart << 8); + if (angleAndBank != RCT2_GLOBAL(0x00F64E36, uint16)) { + return false; + } + + return true; +} + /** * * rct2: 0x006DAB4C @@ -1054,14 +1081,22 @@ loc_6DB358: } } -// loc_6DB38B: - regs.esi = vehicle; - regs.edi = mapElement; - RCT2_CALLFUNC_Y(0x006DB38B, ®s); - goto end; + if (!loc_6DB38B(vehicle, mapElement)) { + goto loc_6DB94A; + } + + // Update VEHICLE_UPDATE_FLAG_11 flag + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_11; + int rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; + if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_3) { + if (mapElement->properties.track.colour & 4) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_11; + } + } loc_6DB41D: regs.esi = vehicle; + regs.edi = mapElement; RCT2_CALLFUNC_Y(0x006DB41D, ®s); goto end; From 1252ac6f7f7c9c1f626c3eb18c77aa3b2da9901b Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 22 Nov 2015 14:55:46 +0000 Subject: [PATCH 088/162] implement more sub_6DAB4C --- src/ride/track.c | 12 ++++++ src/ride/track.h | 2 + src/ride/vehicle.c | 100 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 110 insertions(+), 4 deletions(-) diff --git a/src/ride/track.c b/src/ride/track.c index 01fdd09311..7692307a03 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -4961,3 +4961,15 @@ int track_get_actual_bank_2(int rideType, int trackColour, int bank) } return bank; } + +bool track_element_is_station(rct_map_element *trackElement) +{ + switch (trackElement->properties.track.type) { + case TRACK_ELEM_END_STATION: + case TRACK_ELEM_BEGIN_STATION: + case TRACK_ELEM_MIDDLE_STATION: + return true; + default: + return false; + } +} diff --git a/src/ride/track.h b/src/ride/track.h index c526f7d5f2..2b65d69024 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -556,4 +556,6 @@ void track_element_clear_cable_lift(rct_map_element *trackElement); int track_get_actual_bank(rct_map_element *mapElement, int bank); int track_get_actual_bank_2(int rideType, int trackColour, int bank); +bool track_element_is_station(rct_map_element *trackElement); + #endif diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 212080056a..2d7bf21647 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -25,6 +25,8 @@ #include "../hook.h" #include "../interface/viewport.h" #include "../openrct2.h" +#include "../scenario.h" +#include "../world/map_animation.h" #include "../world/sprite.h" #include "ride.h" #include "ride_data.h" @@ -867,6 +869,44 @@ static bool loc_6DB38B(rct_vehicle *vehicle, rct_map_element *mapElement) return true; } +void loc_6DB481(rct_vehicle *vehicle) +{ + uint16 probability = 0x8000; + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_6) { + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_6; + } else { + probability = 0x0A3D; + } + if ((scenario_rand() & 0xFFFF) <= probability) { + vehicle->var_CD += 2; + } +} + +/** + * + * rct2: 0x006DB545 + */ +static void vehicle_trigger_on_ride_photo(rct_vehicle *vehicle, rct_map_element *mapElement) +{ + mapElement->properties.track.sequence &= 0x0F; + mapElement->properties.track.sequence |= 0x30; + map_animation_create( + MAP_ANIMATION_TYPE_TRACK_ONRIDEPHOTO, + vehicle->track_x, + vehicle->track_y, + mapElement->base_height + ); +} + +/** + * + * rct2: 0x006DEDE8 + */ +static void sub_6DEDE8(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006DEDE8, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + /** * * rct2: 0x006DAB4C @@ -1095,10 +1135,62 @@ loc_6DB358: } loc_6DB41D: - regs.esi = vehicle; - regs.edi = mapElement; - RCT2_CALLFUNC_Y(0x006DB41D, ®s); - goto end; + vehicle->track_x = regs.ax; + vehicle->track_y = regs.cx; + vehicle->track_z = regs.dx; + + // TODO check if getting the vehicle entry again is necessary + vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + if ((vehicleEntry->var_14 & (1 << 14)) && vehicle->var_CD < 7) { + trackType = mapElement->properties.track.type; + if (trackType == TRACK_ELEM_FLAT) { + loc_6DB481(vehicle); + } else if (ride->lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) { + if (track_element_is_station(mapElement)) { + loc_6DB481(vehicle); + } + } + } + + if (vehicle->var_CD != 0 && vehicle->var_CD < 5) { + regs.ax >>= 5; + regs.cx >>= 5; + regs.ah = regs.cl; + regs.dx >>= 3; + if (regs.ax != ride->var_13C || regs.dl != ride->var_13F) { + if (regs.ax == ride->var_13A && regs.dl == ride->var_13E) { + vehicle->var_CD = 4; + } + } else { + vehicle->var_CD = 3; + } + } + +loc_6DB500: + // Update VEHICLE_UPDATE_FLAG_0 + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; + if (track_element_is_lift_hill(mapElement)) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; + } + + trackType = mapElement->properties.track.type; + if (trackType != TRACK_ELEM_BRAKES) { + vehicle->var_D9 = mapElement->properties.track.colour >> 4; + } + vehicle->track_direction = regs.bl & 3; + vehicle->track_type |= trackType << 2; + vehicle->var_CF = (mapElement->properties.track.sequence >> 3) & 0x1E; + if (trackType == TRACK_ELEM_ON_RIDE_PHOTO) { + vehicle_trigger_on_ride_photo(vehicle, mapElement); + } + if (trackType == TRACK_ELEM_ROTATION_CONTROL_TOGGLE) { + vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_13; + } + if (vehicleEntry->var_12 & (1 << 8)) { + sub_6DEDE8(vehicle); + } + regs.ax = 0; loc_6DB59A: regs.esi = vehicle; From e8a78f0e2a4f378475b8bb050838c5751f5ca5b0 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 22 Nov 2015 17:50:33 +0000 Subject: [PATCH 089/162] implement more sub_6DAB4C --- src/ride/track.c | 28 ++++++++++++++++++++++ src/ride/track.h | 1 + src/ride/vehicle.c | 59 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/ride/track.c b/src/ride/track.c index 7692307a03..ff0063bb2f 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -4973,3 +4973,31 @@ bool track_element_is_station(rct_map_element *trackElement) return false; } } + +bool track_element_is_covered(int trackElementType) +{ + switch (trackElementType) { + case TRACK_ELEM_FLAT_COVERED: + case TRACK_ELEM_25_DEG_UP_COVERED: + case TRACK_ELEM_60_DEG_UP_COVERED: + case TRACK_ELEM_FLAT_TO_25_DEG_UP_COVERED: + case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP_COVERED: + case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP_COVERED: + case TRACK_ELEM_25_DEG_UP_TO_FLAT_COVERED: + case TRACK_ELEM_25_DEG_DOWN_COVERED: + case TRACK_ELEM_60_DEG_DOWN_COVERED: + case TRACK_ELEM_FLAT_TO_25_DEG_DOWN_COVERED: + case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN_COVERED: + case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN_COVERED: + case TRACK_ELEM_25_DEG_DOWN_TO_FLAT_COVERED: + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_COVERED: + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_COVERED: + case TRACK_ELEM_S_BEND_LEFT_COVERED: + case TRACK_ELEM_S_BEND_RIGHT_COVERED: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_COVERED: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED: + return true; + default: + return false; + } +} diff --git a/src/ride/track.h b/src/ride/track.h index 2b65d69024..fdb999d5b1 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -557,5 +557,6 @@ int track_get_actual_bank(rct_map_element *mapElement, int bank); int track_get_actual_bank_2(int rideType, int trackColour, int bank); bool track_element_is_station(rct_map_element *trackElement); +bool track_element_is_covered(int trackElementType); #endif diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 2d7bf21647..6630cd1e98 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -907,6 +907,59 @@ static void sub_6DEDE8(rct_vehicle *vehicle) RCT2_CALLPROC_X(0x006DEDE8, 0, 0, 0, 0, (int)vehicle, 0, 0); } +static void vehicle_update_play_water_splash_sound() +{ + if (RCT2_GLOBAL(0x00F64E08, sint32) <= 0x20364) { + return; + } + + audio_play_sound_at_location( + SOUND_WATER_SPLASH, + RCT2_GLOBAL(0x00F64E20, uint16), + RCT2_GLOBAL(0x00F64E22, uint16), + RCT2_GLOBAL(0x00F64E24, uint16) + ); +} + +/** + * + * rct2: 0x006DB59E + */ +static void vehicle_update_handle_water_splash(rct_vehicle *vehicle) +{ + rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + int trackType = vehicle->track_type >> 2; + + if (!(rideEntry->flags & RIDE_ENTRY_FLAG_8)) { + if (rideEntry->flags & RIDE_ENTRY_FLAG_9) { + if (!vehicle->is_child) { + if (track_element_is_covered(trackType)) { + rct_vehicle *nextVehicle = GET_VEHICLE(vehicle->next_vehicle_on_ride); + rct_vehicle *nextNextVehicle = GET_VEHICLE(nextVehicle->next_vehicle_on_ride); + if (!track_element_is_covered(nextNextVehicle->track_type >> 2)) { + if (vehicle->var_34 == 4) { + vehicle_update_play_water_splash_sound(); + } + } + } + } + } + } else { + if (trackType == TRACK_ELEM_25_DEG_DOWN_TO_FLAT) { + if (vehicle->var_34 == 12) { + vehicle_update_play_water_splash_sound(); + } + } + } + if (!vehicle->is_child) { + if (trackType == TRACK_ELEM_WATER_SPLASH) { + if (vehicle->var_34 == 48) { + vehicle_update_play_water_splash_sound(); + } + } + } +} + /** * * rct2: 0x006DAB4C @@ -1193,8 +1246,12 @@ loc_6DB500: regs.ax = 0; loc_6DB59A: + vehicle->var_34 = regs.ax; + vehicle_update_handle_water_splash(vehicle); + +loc_6DB706: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DB59A, ®s); + RCT2_CALLFUNC_Y(0x006DB706, ®s); goto end; loc_6DB94A: From d5d7956d429b3a92641aa1e351518be3df662f60 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 28 Nov 2015 17:09:56 +0000 Subject: [PATCH 090/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 134 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 121 insertions(+), 13 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 6630cd1e98..ec650a0b9b 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -33,6 +33,16 @@ #include "track.h" #include "vehicle.h" +rct_xyz16 *unk_F64E20 = (rct_xyz16*)0x00F64E20; + +// Size: 0x09 +typedef struct { + uint16 x; // 0x00 + uint16 y; // 0x02 + uint16 z; // 0x04 + uint8 pad_06[3]; // 0x06 +} rct_vehicle_info; + static void vehicle_update(rct_vehicle *vehicle); /** @@ -915,9 +925,9 @@ static void vehicle_update_play_water_splash_sound() audio_play_sound_at_location( SOUND_WATER_SPLASH, - RCT2_GLOBAL(0x00F64E20, uint16), - RCT2_GLOBAL(0x00F64E22, uint16), - RCT2_GLOBAL(0x00F64E24, uint16) + unk_F64E20->x, + unk_F64E20->y, + unk_F64E20->z ); } @@ -960,6 +970,49 @@ static void vehicle_update_handle_water_splash(rct_vehicle *vehicle) } } +static const rct_vehicle_info *vehicle_get_move_info(int cd, int typeAndDirection, int offset) +{ + const rct_vehicle_info **infoListList = RCT2_ADDRESS(0x008B8F30, rct_vehicle_info**)[cd]; + const rct_vehicle_info *infoList = infoListList[typeAndDirection]; + return &infoList[offset]; +} + +/** + * + * rct2: 0x006DB807 + */ +static void sub_6DB807(rct_vehicle *vehicle) +{ + const rct_vehicle_info *moveInfo = vehicle_get_move_info( + vehicle->var_CD, + vehicle->track_type, + vehicle->var_34 + ); + int x = vehicle->track_x + moveInfo->x; + int y = vehicle->track_y + moveInfo->y; + int z = vehicle->z; + sprite_move(x, y, z, (rct_sprite*)vehicle); +} + +/** + * + * rct2: 0x006DB7D6 + */ +static void sub_6DB7D6(rct_vehicle *vehicle) +{ + rct_vehicle *previousVehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); + rct_vehicle *nextVehicle = GET_VEHICLE(vehicle->next_vehicle_on_ride); + + vehicle->var_34 = 168; + vehicle->vehicle_type ^= 1; + + previousVehicle->var_34 = 86; + nextVehicle->var_34 = 158; + + sub_6DB807(nextVehicle); + sub_6DB807(previousVehicle); +} + /** * * rct2: 0x006DAB4C @@ -1011,8 +1064,9 @@ loc_6DAE27: goto loc_6DBF3E; } vehicle->var_B8 &= ~(1 << 1); - RCT2_GLOBAL(0x00F64E20, uint32) = vehicle->x | (vehicle->y << 16); - RCT2_GLOBAL(0x00F64E24, uint16) = vehicle->z; + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; invalidate_sprite_2((rct_sprite*)vehicle); loc_6DAEB9: @@ -1078,11 +1132,18 @@ loc_6DAEB9: } regs.ax = vehicle->var_34 + 1; - regs.ecx = vehicle->var_CD; - regs.ecx = RCT2_ADDRESS(0x008B8F30, uint32)[regs.ecx]; - regs.edi = RCT2_GLOBAL(regs.ecx + (vehicle->track_type * 4), uint32); - if (regs.ax < RCT2_GLOBAL(regs.edi - 2, uint16)) { - goto loc_6DB59A; + { + const rct_vehicle_info *moveInfo = vehicle_get_move_info( + vehicle->var_CD, + vehicle->track_type, + 0 + ); + + // There are two bytes before the move info list + uint16 unk16 = *((uint16*)((int)moveInfo - 2)); + if (regs.ax < unk16) { + goto loc_6DB59A; + } } RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; @@ -1100,7 +1161,7 @@ loc_6DAEB9: if (track_element_is_block_start(mapElement)) { if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { - RCT2_GLOBAL(regs.edi + 1, uint8) |= 0x20; + mapElement->flags |= (1 << 5); if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { if (!(rideEntry->vehicles[0].var_14 & (1 << 3))) { audio_play_sound_at_location(SOUND_49, vehicle->track_x, vehicle->track_y, vehicle->track_z); @@ -1249,9 +1310,56 @@ loc_6DB59A: vehicle->var_34 = regs.ax; vehicle_update_handle_water_splash(vehicle); -loc_6DB706: +loc_6DB706:; + // regs.esi = vehicle; + // RCT2_CALLFUNC_Y(0x006DB706, ®s); + // goto end; + + const rct_vehicle_info *moveInfo = vehicle_get_move_info( + vehicle->var_CD, + vehicle->track_type, + vehicle->var_34 + ); + sint16 x = vehicle->track_x + moveInfo->x; + sint16 y = vehicle->track_y + moveInfo->y; + sint16 z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + + regs.ebx = 0; + if (x != unk_F64E20->x) { regs.ebx |= 1; } + if (y != unk_F64E20->y) { regs.ebx |= 2; } + if (z != unk_F64E20->z) { regs.ebx |= 4; } + if (vehicle->var_CD == 15 && + vehicle->track_type >= 844 && + vehicle->track_type < 852 && + vehicle->var_34 >= 30 && + vehicle->var_34 <= 66 + ) { + regs.ebx |= 8; + } + + if (vehicle->var_CD == 16 && + vehicle->track_type >= 844 && + vehicle->track_type < 852 && + vehicle->var_34 == 96 + ) { + sub_6DB7D6(vehicle); + + const rct_vehicle_info *moveInfo2 = vehicle_get_move_info( + vehicle->var_CD, + vehicle->track_type, + vehicle->var_34 + ); + x = vehicle->x + moveInfo2->x; + y = vehicle->y + moveInfo2->y; + } + +loc_6DB8A5: + regs.ax = x; + regs.cx = y; + regs.dx = z; regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DB706, ®s); + regs.edi = moveInfo; + RCT2_CALLFUNC_Y(0x006DB8A5, ®s); goto end; loc_6DB94A: From e5c83561e54ddd8d12a71a1affcb4c9ec4d64d4f Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 28 Nov 2015 17:49:51 +0000 Subject: [PATCH 091/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 66 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index ec650a0b9b..d9e9398ed1 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -40,7 +40,9 @@ typedef struct { uint16 x; // 0x00 uint16 y; // 0x02 uint16 z; // 0x04 - uint8 pad_06[3]; // 0x06 + uint8 direction; // 0x06 + uint8 var_07; + uint8 var_08; } rct_vehicle_info; static void vehicle_update(rct_vehicle *vehicle); @@ -994,6 +996,17 @@ static void sub_6DB807(rct_vehicle *vehicle) sprite_move(x, y, z, (rct_sprite*)vehicle); } +/** + * + * rct2: 0x006DD078 + * @param vehicle (esi) + * @param otherVehicleIndex (bp) + */ +static bool sub_6DD078(rct_vehicle *vehicle, uint16 otherVehicleIndex) +{ + return RCT2_CALLPROC_X(0x006DD078, 0, 0, 0, 0, (int)vehicle, 0, otherVehicleIndex) & 0x100; +} + /** * * rct2: 0x006DB7D6 @@ -1354,24 +1367,61 @@ loc_6DB706:; } loc_6DB8A5: - regs.ax = x; - regs.cx = y; - regs.dx = z; - regs.esi = vehicle; - regs.edi = moveInfo; - RCT2_CALLFUNC_Y(0x006DB8A5, ®s); - goto end; + regs.ebx = RCT2_ADDRESS(0x009A2930, uint32)[regs.ebx]; + vehicle->var_24 -= regs.ebx; + unk_F64E20->x = x; + unk_F64E20->y = y; + unk_F64E20->z = z; + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + vehicle->var_1F = moveInfo->var_07; + + regs.ebx = moveInfo->var_07; + + if ((vehicleEntry->var_14 & 0x200) && moveInfo->var_07 != 0) { + vehicle->var_4A = 0; + vehicle->var_4C = 0; + vehicle->var_4E = 0; + } + + if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { + if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + regs.bp = vehicle->prev_vehicle_on_ride; + if (sub_6DD078(vehicle, vehicle->prev_vehicle_on_ride)) { + goto loc_6DB967; + } + } + } + + if (vehicle->var_24 < 0x368A) { + goto loc_6DBF20; + } + + regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[regs.ebx]; + vehicle->var_2C += regs.ebx; + RCT2_GLOBAL(0x00F64E10, uint32)++; + goto loc_6DAEB9; loc_6DB94A: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DB94A, ®s); goto end; +loc_6DB967: + regs.esi = vehicle; + // regs.bp = regs.bp + RCT2_CALLFUNC_Y(0x006DB94A, ®s); + goto end; + loc_6DBA13: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DBA13, ®s); goto end; +loc_6DBF20: + sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); + loc_6DBF3E: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DBF3E, ®s); From 9c25fd0105a94fe17cec7acea98ae54b3a3276e7 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 28 Nov 2015 18:11:48 +0000 Subject: [PATCH 092/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index d9e9398ed1..6f8c613e41 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1324,10 +1324,6 @@ loc_6DB59A: vehicle_update_handle_water_splash(vehicle); loc_6DB706:; - // regs.esi = vehicle; - // RCT2_CALLFUNC_Y(0x006DB706, ®s); - // goto end; - const rct_vehicle_info *moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, @@ -1403,9 +1399,12 @@ loc_6DB8A5: goto loc_6DAEB9; loc_6DB94A: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DB94A, ®s); - goto end; + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + regs.eax = vehicle->var_24 + 1; + RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + vehicle->var_24 = 0xFFFFFFFF; + regs.ebx = vehicle->var_1F; + goto loc_6DBE3F; loc_6DB967: regs.esi = vehicle; @@ -1418,6 +1417,20 @@ loc_6DBA13: RCT2_CALLFUNC_Y(0x006DBA13, ®s); goto end; +loc_6DBA33: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DBA33, ®s); + goto end; + +loc_6DBE3F: + if ((sint32)vehicle->var_24 >= 0) { + goto loc_6DBF20; + } + regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[regs.ebx]; + vehicle->var_2C = regs.ebx; + RCT2_GLOBAL(0x00F64E10, uint32)++; + goto loc_6DBA33; + loc_6DBF20: sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)vehicle); invalidate_sprite_2((rct_sprite*)vehicle); From c0a79b7604cddc9e74d49a245932577896592d54 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 28 Nov 2015 18:40:44 +0000 Subject: [PATCH 093/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 6f8c613e41..b48f77cbda 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1407,10 +1407,30 @@ loc_6DB94A: goto loc_6DBE3F; loc_6DB967: - regs.esi = vehicle; - // regs.bp = regs.bp - RCT2_CALLFUNC_Y(0x006DB94A, ®s); - goto end; + regs.eax = vehicle->var_24 + 1; + RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + vehicle->var_24 -= regs.eax; + + // Might need to be bp rather than vehicle, but hopefully not + rct_vehicle *head = vehicle_get_head(vehicle); + + regs.eax = abs(vehicle->velocity - head->velocity); + if (!(rideEntry->flags & RIDE_ENTRY_FLAG_18)) { + if (regs.eax > 0xE0000) { + if (!(vehicleEntry->var_14 & (1 << 6))) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 7); + } + } + } + + if (vehicleEntry->var_14 & (1 << 14)) { + vehicle->velocity -= vehicle->velocity >> 2; + } else { + vehicle->velocity = head->velocity >> 1; + head->velocity = vehicle->velocity >> 1; + } + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); + goto loc_6DBE3F; loc_6DBA13: regs.esi = vehicle; From 125a9a2b312a5ae78420c69f3acf701ec953b0a1 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 28 Nov 2015 21:14:34 +0000 Subject: [PATCH 094/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 105 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index b48f77cbda..29471ff2fc 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1433,13 +1433,105 @@ loc_6DB967: goto loc_6DBE3F; loc_6DBA13: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DBA13, ®s); - goto end; + vehicle->var_B8 &= ~(1 << 1); + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; + invalidate_sprite_2((rct_sprite*)vehicle); loc_6DBA33: + trackType = vehicle->track_type >> 2; + if (trackType == TRACK_ELEM_FLAT && ride->type == RIDE_TYPE_REVERSE_FREEFALL_COASTER) { + sint32 unkVelocity = RCT2_GLOBAL(0x00F64E08, sint32); + if (unkVelocity > 0xFFF80000) { + unkVelocity = abs(unkVelocity); + vehicle->var_2C = unkVelocity * 2; + } + } + + if (trackType == TRACK_ELEM_BRAKES) { + regs.eax = -(vehicle->var_CF << 16); + if (regs.eax <= RCT2_GLOBAL(0x00F64E08, sint32)) { + regs.eax = RCT2_GLOBAL(0x00F64E08, sint32) * -4; + vehicle->var_2C = regs.eax; + } + } + + regs.ax = vehicle->var_34 - 1; + if (regs.ax != -1) { + goto loc_6DBD42; + } + + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + mapElement = map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z >> 3, + trackType, + 0 + ); + +loc_6DBB08: + x = vehicle->track_x; + y = vehicle->track_y; + switch (vehicle->var_CD) { + case 3: + vehicle->var_CD = 1; + break; + case 7: + vehicle->var_CD = 5; + break; + case 8: + vehicle->var_CD = 6; + break; + case 2: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + vehicle->var_CD = 2; + loc_6DBB4F: + { + rct_xy_element input; + rct_xy_element output; + int outputZ; + int outputDirection; + + input.x = x; + input.y = y; + input.element = mapElement; + if (track_block_get_next(&input, &output, &outputZ, &outputDirection)) { + regs.edi = output.element; + goto loc_6DBE5E; + } + regs.bh = outputDirection; + goto loc_6DBC3B; + } + } + +loc_6DBB7E: + regs.ax = x; + regs.cx = y; regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DBA33, ®s); + regs.edi = mapElement; + RCT2_CALLFUNC_Y(0x006DBB7E, ®s); + goto end; + +loc_6DBC3B: + regs.ax = x; + regs.cx = x; + regs.dx = z; + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DBC3B, ®s); + goto end; + +loc_6DBD42: + // regs.ax = regs.ax + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DBD42, ®s); goto end; loc_6DBE3F: @@ -1451,6 +1543,11 @@ loc_6DBE3F: RCT2_GLOBAL(0x00F64E10, uint32)++; goto loc_6DBA33; +loc_6DBE5E: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DBE5E, ®s); + goto end; + loc_6DBF20: sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)vehicle); invalidate_sprite_2((rct_sprite*)vehicle); From 12f0abd35e3e929afdc9640fd4d4014f1234660b Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 28 Nov 2015 21:42:34 +0000 Subject: [PATCH 095/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 29471ff2fc..c98b2b3082 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1507,24 +1507,53 @@ loc_6DBB08: regs.edi = output.element; goto loc_6DBE5E; } - regs.bh = outputDirection; + mapElement = output.element; goto loc_6DBC3B; } } loc_6DBB7E: - regs.ax = x; - regs.cx = y; - regs.esi = vehicle; - regs.edi = mapElement; - RCT2_CALLFUNC_Y(0x006DBB7E, ®s); - goto end; + { + track_begin_end trackBeginEnd; + if (track_block_get_previous(x, y, mapElement, &trackBeginEnd)) { + goto loc_6DBE5E; + } + mapElement = trackBeginEnd.begin_element; + + trackType = mapElement->properties.track.type; + if (trackType == 211 || trackType == 212) { + goto loc_6DBE5E; + } + + int trackColour = vehicle->update_flags >> 9; + int bank = gTrackDefinitions[trackType].bank_end;; + bank = track_get_actual_bank_2(ride->type, regs.al, bank); + int vAngle = gTrackDefinitions[trackType].vangle_end; + if (RCT2_GLOBAL(0x00F64E36, uint16) != vAngle || + RCT2_GLOBAL(0x00F64E37, uint16) != bank + ) { + goto loc_6DBE5E; + } + + // Update VEHICLE_UPDATE_FLAG_11 + vehicle->update_flags &= VEHICLE_UPDATE_FLAG_11; + if (RideData4[ride->type].flags & RIDE_TYPE_FLAG4_3) { + if (mapElement->properties.track.colour & 4) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_11; + } + } + + x = trackBeginEnd.begin_x; + y = trackBeginEnd.begin_y; + z = trackBeginEnd.begin_z; + } loc_6DBC3B: regs.ax = x; - regs.cx = x; + regs.cx = y; regs.dx = z; regs.esi = vehicle; + regs.edi = mapElement; RCT2_CALLFUNC_Y(0x006DBC3B, ®s); goto end; From 3ecbfe6c688f3d6943ad09e5eae808578303d9df Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 28 Nov 2015 23:48:41 +0000 Subject: [PATCH 096/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 71 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index c98b2b3082..0aec0944ad 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1512,7 +1512,8 @@ loc_6DBB08: } } -loc_6DBB7E: +loc_6DBB7E:; + int direction; { track_begin_end trackBeginEnd; if (track_block_get_previous(x, y, mapElement, &trackBeginEnd)) { @@ -1546,16 +1547,70 @@ loc_6DBB7E: x = trackBeginEnd.begin_x; y = trackBeginEnd.begin_y; z = trackBeginEnd.begin_z; + direction = trackBeginEnd.begin_direction; } loc_6DBC3B: - regs.ax = x; - regs.cx = y; - regs.dx = z; - regs.esi = vehicle; - regs.edi = mapElement; - RCT2_CALLFUNC_Y(0x006DBC3B, ®s); - goto end; + vehicle->track_x = x; + vehicle->track_y = y; + vehicle->track_z = z; + + if (vehicle->var_CD != 0 && + vehicle->var_CD < 5 + ) { + sint16 xy = (x >> 5) | ((y >> 5) << 8); + if (ride->var_13C == xy && + ride->var_13F == (z >> 3) + ) { + vehicle->var_CD = 3; + } else if ( + ride->var_13A == xy && + ride->var_13E == (z >> 3) + ) { + vehicle->var_CD = 4; + } + } + + if (track_element_is_lift_hill(mapElement)) { + if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { + trackType = mapElement->properties.track.type; + if (RCT2_ADDRESS(0x0099423C, uint16)[trackType] & 0x20) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 0x200; + } + } + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; + } + } else { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; + if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { + if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 0x100; + } + } + } + } + + trackType = mapElement->properties.track.type; + if (trackType != TRACK_ELEM_BRAKES) { + vehicle->var_D9 = mapElement->properties.track.colour >> 4; + } + direction &= 3; + vehicle->track_type = trackType << 2; + vehicle->track_direction |= direction; + vehicle->var_CF = (mapElement->properties.track.sequence >> 4) << 1; + + moveInfo = vehicle_get_move_info( + vehicle->var_CD, + vehicle->track_type, + 0 + ); + + // There are two bytes before the move info list + uint16 unk16 = *((uint16*)((int)moveInfo - 2)); + unk16--; + regs.ax = unk16; loc_6DBD42: // regs.ax = regs.ax From 86ef1b0d49f0612f5be1fe6bf253b581c436ec5f Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 29 Nov 2015 00:10:48 +0000 Subject: [PATCH 097/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 55 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 0aec0944ad..80187f9df8 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1389,6 +1389,7 @@ loc_6DB8A5: } } +loc_6DB928: if (vehicle->var_24 < 0x368A) { goto loc_6DBF20; } @@ -1613,10 +1614,45 @@ loc_6DBC3B: regs.ax = unk16; loc_6DBD42: - // regs.ax = regs.ax - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DBD42, ®s); - goto end; + vehicle->var_34 = regs.ax; + moveInfo = vehicle_get_move_info( + vehicle->var_CD, + vehicle->track_type, + 0 + ); + + x = vehicle->track_x + moveInfo->x; + y = vehicle->track_y + moveInfo->y; + z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + + regs.ebx = 0; + if (x == unk_F64E20->x) { regs.ebx |= 1; } + if (y == unk_F64E20->y) { regs.ebx |= 2; } + if (z == unk_F64E20->z) { regs.ebx |= 4; } + vehicle->var_24 += RCT2_ADDRESS(0x009A2930, uint32)[regs.ebx]; + + unk_F64E20->x = x; + unk_F64E20->y = y; + unk_F64E20->z = z; + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + regs.ebx = moveInfo->var_07; + vehicle->var_1F = regs.bl; + + if ((vehicleEntry->var_14 & 0x200) && regs.bl != 0) { + vehicle->var_4A = 0; + vehicle->var_4C = 0; + vehicle->var_4E = 0; + } + + if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { + if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + regs.bp = vehicle->next_vehicle_on_ride; + if (sub_6DD078(vehicle, regs.bp)) { + goto loc_6DBE7F; + } + } + } loc_6DBE3F: if ((sint32)vehicle->var_24 >= 0) { @@ -1628,8 +1664,17 @@ loc_6DBE3F: goto loc_6DBA33; loc_6DBE5E: + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + regs.eax = (sint32)vehicle->var_24 - 0x368A; + RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + vehicle->var_24 -= regs.eax; + regs.ebx = vehicle->var_1F; + goto loc_6DB928; + +loc_6DBE7F: + // regs.bp = regs.bp; regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DBE5E, ®s); + RCT2_CALLFUNC_Y(0x006DBE7F, ®s); goto end; loc_6DBF20: From d718a51aed6f529689b3f887d30d8e3cacf35b61 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 29 Nov 2015 00:24:29 +0000 Subject: [PATCH 098/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 80187f9df8..5cf3b40333 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1672,10 +1672,32 @@ loc_6DBE5E: goto loc_6DB928; loc_6DBE7F: - // regs.bp = regs.bp; - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DBE7F, ®s); - goto end; + regs.eax = vehicle->var_24 - 0x368A; + RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + vehicle->var_24 -= regs.eax; + + rct_vehicle *v3 = GET_VEHICLE(regs.bp); + rct_vehicle *v4 = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); + regs.eax = abs(v4->velocity - v3->velocity); + + if (!(rideEntry->flags & RIDE_ENTRY_FLAG_18)) { + if (regs.eax > 0xE0000) { + if (!(vehicleEntry->var_14 & (1 << 6))) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 7); + } + } + } + + if (vehicleEntry->var_14 & (1 << 14)) { + vehicle->velocity -= vehicle->velocity >> 2; + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 2); + } else { + vehicle->velocity = v3->velocity >> 1; + v3->velocity = v4->velocity >> 1; + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 2); + } + + goto loc_6DB928; loc_6DBF20: sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)vehicle); From 3a538892ada1dad6df2ef718a90c7c2bec7f61e2 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 29 Nov 2015 11:54:13 +0000 Subject: [PATCH 099/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 99 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 5cf3b40333..477f2e06b3 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1026,6 +1026,83 @@ static void sub_6DB7D6(rct_vehicle *vehicle) sub_6DB807(previousVehicle); } +/** + * + * rct2: 0x006DBF3E + */ +void sub_6DBF3E(rct_vehicle *vehicle) +{ + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + vehicle->var_2C = (uint32)((sint32)vehicle->var_2C / RCT2_GLOBAL(0x00F64E10, sint32)); + if (vehicle->var_CD == 2) { + return; + } + + int trackType = vehicle->track_type >> 2; + if (!(RCT2_GLOBAL(0x0099BA64 + (trackType * 16), uint32) & 0x10)) { + return; + } + + RCT2_GLOBAL(0x00F64E18, uint32) |= 8; + + rct_map_element *mapElement = map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z >> 3, + trackType, + 0 + ); + if (RCT2_GLOBAL(0x00F64E1C, uint32) == 0xFFFFFFFF) { + RCT2_GLOBAL(0x00F64E1C, uint32) = (mapElement->properties.track.sequence >> 4) & 7; + } + + if (trackType == TRACK_ELEM_TOWER_BASE && + vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*) + ) { + if (vehicle->var_34 > 3 && !(vehicle->update_flags & VEHICLE_UPDATE_FLAG_3)) { + rct_xy_element input, output; + int outputZ, outputDirection; + + input.x = vehicle->track_x; + input.y = vehicle->track_y; + input.element = mapElement; + if (track_block_get_next(&input, &output, &outputZ, &outputDirection)) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 0x1000; + } + } + + if (vehicle->var_34 <= 3) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 1; + } + } + + if (trackType != TRACK_ELEM_END_STATION || + vehicle != RCT2_GLOBAL(0x00F64E04, rct_vehicle*) + ) { + return; + } + + uint16 ax = vehicle->var_34; + if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + if (ax <= 22) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 1; + } + } else { + uint16 cx = 17; + if (vehicleEntry->var_14 & (1 << 12)) { + cx = 6; + } + if (vehicleEntry->var_14 & (1 << 14)) { + cx = vehicle->var_CD == 6 ? 18 : 20; + } + + if (ax > cx) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 1; + } + } +} + /** * * rct2: 0x006DAB4C @@ -1704,8 +1781,28 @@ loc_6DBF20: invalidate_sprite_2((rct_sprite*)vehicle); loc_6DBF3E: + sub_6DBF3E(vehicle); + +loc_6DC0F7: + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { + RCT2_GLOBAL(0x00F64E18, uint32) |= 4; + } + if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { + goto loc_6DC144; + } + + vehicle = GET_VEHICLE(vehicle->next_vehicle_on_train); + } else { + if (vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { + goto loc_6DC144; + } + } + goto loc_6DAE27; + +loc_6DC144: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DBF3E, ®s); + RCT2_CALLFUNC_Y(0x006DC144, ®s); goto end; loc_6DC3A7: From 22857ae3709813cacae39460ddf92a32e66adf1e Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 29 Nov 2015 14:07:52 +0000 Subject: [PATCH 100/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 186 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 184 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 477f2e06b3..ec719fa3b7 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1801,8 +1801,190 @@ loc_6DC0F7: goto loc_6DAE27; loc_6DC144: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DC144, ®s); + vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); + regs.eax = 0; + regs.ebp = 0; + regs.dx = 0; + regs.ebx = 0; + + for (;;) { + regs.ebx++; + regs.dx |= vehicle->update_flags; + regs.bp += vehicle->friction; + regs.eax += vehicle->var_2C; + + uint16 spriteIndex = vehicle->next_vehicle_on_train; + if (spriteIndex == SPRITE_INDEX_NULL) { + break; + } + vehicle = GET_VEHICLE(spriteIndex); + } + + vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); + regs.eax = (regs.eax / regs.ebx) * 21; + if (regs.eax < 0) { + regs.eax += 511; + } + regs.eax >>= 9; + regs.ecx = regs.eax; + regs.eax = vehicle->velocity; + if (regs.eax < 0) { + regs.eax = -regs.eax; + regs.eax >>= 12; + regs.eax = -regs.eax; + } else { + regs.eax >>= 12; + } + + regs.ecx -= regs.eax; + regs.edx = vehicle->velocity; + regs.ebx = regs.edx; + regs.edx >>= 8; + regs.edx *= regs.edx; + if (regs.ebx < 0) { + regs.edx = -regs.edx; + } + regs.edx >>= 4; + regs.eax = regs.edx; + regs.eax = regs.eax / regs.ebp; + regs.ecx -= regs.eax; + + if (!(vehicleEntry->var_14 & (1 << 3))) { + goto loc_6DC2FA; + } + if (vehicleEntry->var_12 & (1 << 0)) { + regs.eax = vehicle->speed * 0x4000; + if (regs.eax < vehicle->velocity) { + goto loc_6DC2FA; + } + } + regs.eax = vehicle->speed; + trackType = vehicle->track_direction >> 2; + if (trackType == TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE) { + goto loc_6DC22F; + } + if (trackType != TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE) { + goto loc_6DC23A; + } + if (vehicle->var_CD == 6) { + goto loc_6DC238; + } + +loc_6DC226: + regs.ebx = regs.eax >> 2; + regs.eax -= regs.ebx; + goto loc_6DC23A; + +loc_6DC22F: + if (vehicle->var_CD != 5) { + goto loc_6DC226; + } + +loc_6DC238: + regs.eax >>= 1; + +loc_6DC23A: + regs.ebx = regs.eax; + regs.eax <<= 14; + regs.ebx *= regs.ebp; + regs.ebx >>= 2; + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_3) { + regs.eax = -regs.eax; + } + regs.eax -= vehicle->velocity; + regs.edx = vehicle->acceleration; + regs.edx <<= 1; + regs.eax *= regs.edx; + regs.eax /= regs.ebx; + + if (vehicleEntry->var_12 & (1 << 15)) { + regs.eax <<= 2; + } + + if (!(vehicleEntry->var_14 & (1 << 13))) { + goto loc_6DC2E3; + } + + if (regs.eax < 0) { + regs.eax >>= 4; + } + + if (vehicleEntry->var_14 & (1 << 2)) { + regs.bx = vehicle->var_B6; + if (regs.bx > 512) { + regs.bx = 512; + } + if (regs.bx < -512) { + regs.bx = -512; + } + vehicle->var_B6 = regs.bx; + } + + if (vehicle->var_1F != 0) { + if (regs.eax < 0) { + regs.eax = 0; + } + + if (!(vehicleEntry->var_14 & (1 << 2))) { + if (vehicle->var_1F == 2) { + vehicle->var_B6 = 0; + } + } + goto loc_6DC2F6; + } + +loc_6DC2E3: + regs.ebx = vehicle->velocity; + if (regs.ebx < 0) { + regs.ebx = -regs.ebx; + } + if (regs.ebx <= 0x10000) { + regs.ecx = 0; + } + +loc_6DC2F6: + regs.ecx += regs.eax; + goto loc_6DC316; + +loc_6DC2FA: + if (regs.ecx <= 0) { + if (regs.ecx >= -500) { + if (vehicle->velocity <= 0x8000) { + regs.ecx += 400; + } + } + } + +loc_6DC316: + regs.bx = vehicle->track_type >> 2; + if (regs.bx == TRACK_ELEM_WATER_SPLASH) { + if (vehicle->var_34 >= 48 && + vehicle->var_34 <= 128 + ) { + regs.eax = vehicle->velocity >> 6; + regs.ecx -= regs.eax; + } + } + + if (rideEntry->flags & RIDE_ENTRY_FLAG_9) { + if (!vehicle->is_child) { + regs.bx = vehicle->track_type >> 2; + if (track_element_is_covered(regs.bx)) { + if (vehicle->velocity > 0x20000) { + regs.eax = vehicle->velocity >> 6; + regs.ecx -= regs.eax; + } + } + } + } + + vehicle->var_2C = regs.ecx; + + regs.eax = RCT2_GLOBAL(0x00F64E18, uint32); + regs.ebx = RCT2_GLOBAL(0x00F64E1C, uint32); + if (ride->lifecycle_flags & RIDE_LIFECYCLE_SIX_FLAGS_DEPRECATED) { + regs.eax &= 0xC0; + } goto end; loc_6DC3A7: From 4eee290947eb34d826820a3e230572094a3a8487 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 01:54:33 +0000 Subject: [PATCH 101/162] use original hook code which works better for this branch --- src/hook.c | 124 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 50 deletions(-) diff --git a/src/hook.c b/src/hook.c index 70d30af2e5..28a65bf538 100644 --- a/src/hook.c +++ b/src/hook.c @@ -55,6 +55,73 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in int rargssize = numrargs * 4; + data[i++] = 0x50; // push eax + + // move stack down for possible existing arguments + for (int j = 0; j < stacksize; j++) { + data[i++] = 0x8B; // mov eax, [esp+x] + data[i++] = 0x44; + data[i++] = 0xE4; + data[i++] = (signed char)((4 * (stacksize - j)) + 4); + + data[i++] = 0x89; // mov [esp+x], eax + data[i++] = 0x44; + data[i++] = 0xE4; + data[i++] = (signed char)((4 * (stacksize - j)) - ((registerssaved + stacksize) * 4)); + } + + if (numrargs > 0) { + // push the registers to be on the stack to access as arguments + data[i++] = 0x83; // add esp, x + data[i++] = 0xC4; + data[i++] = -((registerssaved + stacksize) * 4) + 4; + + for (signed int j = numrargs - 1; j >= 0; j--) { + switch (registerargs[j]) { + case EAX: data[i++] = 0x50; break; + case EBX: data[i++] = 0x53; break; + case ECX: data[i++] = 0x51; break; + case EDX: data[i++] = 0x52; break; + case ESI: data[i++] = 0x56; break; + case EDI: data[i++] = 0x57; break; + case EBP: data[i++] = 0x55; break; + } + } + + data[i++] = 0x83; // add esp, x + data[i++] = 0xC4; + data[i++] = rargssize + ((registerssaved + stacksize) * 4) - 4; + } + + + data[i++] = 0xE8; // call + data[i++] = 0x00; + data[i++] = 0x00; + data[i++] = 0x00; + data[i++] = 0x00; + + int sizec = i; + + data[i++] = 0x8B; // push eax, [esp] - puts eip in eax + data[i++] = 0x04; + data[i++] = 0xE4; + + data[i++] = 0x83; // add eax, x + data[i++] = 0xC0; + int sizeoffset = i; + data[i++] = 0; // set to returnlocation offset later + + data[i++] = 0x89; // mov [esp-20h], eax - put return address on stack + data[i++] = 0x44; + data[i++] = 0xE4; + data[i++] = (signed char)(-(registerssaved * 4) - rargssize - (stacksize * 4)) + 4; + + data[i++] = 0x83; // add esp, x + data[i++] = 0xC4; + data[i++] = 4; + + data[i++] = 0x58; // pop eax + if (!(registersreturned & EAX)) { data[i++] = 0x50; // push eax } @@ -77,51 +144,15 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in data[i++] = 0x57; // push edi } - data[i++] = 0x50; //push eax - data[i++] = 0x89; //mov eax, esp - data[i++] = 0xE0; - data[i++] = 0x83; //sub eax, (0xC + numargs*4) & 0xF - data[i++] = 0xE8; - data[i++] = (0xC + numrargs * 4) & 0xF; - data[i++] = 0x83; //and eax, 0xC - data[i++] = 0xE0; - data[i++] = 0x0C; - data[i++] = 0xA3; //mov [0x9ABDA8], eax - data[i++] = 0xA8; - data[i++] = 0xBD; - data[i++] = 0x9A; - data[i++] = 0x00; - data[i++] = 0x58; //pop eax - data[i++] = 0x2B; //sub esp, [0x9ABDA8] - data[i++] = 0x25; - data[i++] = 0xA8; - data[i++] = 0xBD; - data[i++] = 0x9A; - data[i++] = 0x00; + data[i++] = 0x83; // sub esp, x + data[i++] = 0xEC; + data[i++] = 4 + (stacksize * 4) + rargssize; - // work out distance to nearest 0xC - // (esp - numargs * 4) & 0xC - // move to align - 4 - // save that amount - - if (numrargs > 0) { - // push the registers to be on the stack to access as arguments - for (signed int j = numrargs - 1; j >= 0; j--) { - switch (registerargs[j]) { - case EAX: data[i++] = 0x50; break; - case EBX: data[i++] = 0x53; break; - case ECX: data[i++] = 0x51; break; - case EDX: data[i++] = 0x52; break; - case ESI: data[i++] = 0x56; break; - case EDI: data[i++] = 0x57; break; - case EBP: data[i++] = 0x55; break; - } - } - } - - data[i++] = 0xE8; // call + data[i++] = 0xE9; // jmp *((int *)&data[i]) = (newaddress - address - i - 4); i += 4; + data[sizeoffset] = i - sizec; + // returnlocation: switch (eaxDestinationRegister) { @@ -170,13 +201,6 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in data[i++] = 0xEC; data[i++] = (signed char)(stacksize * -4) - rargssize; - data[i++] = 0x03; //add esp, [0x9ABDA8] - data[i++] = 0x25; - data[i++] = 0xA8; - data[i++] = 0xBD; - data[i++] = 0x9A; - data[i++] = 0x00; - if (!(registersreturned & EDI)) { data[i++] = 0x5F; // pop edi } @@ -246,4 +270,4 @@ void addhook(int address, int newaddress, int stacksize, int registerargs[], int void hook_setreturnregisters(registers *regs) { _returnRegisters = *regs; -} +} \ No newline at end of file From adcbfec41394916ccf332b512dd058f4a8a84e8e Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 02:06:39 +0000 Subject: [PATCH 102/162] name return flags for sub_6DAB4C --- src/ride/vehicle.c | 43 ++++++++++++++++++++++--------------------- src/ride/vehicle.h | 15 +++++++++++++++ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index ec719fa3b7..353c83249f 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -663,7 +663,7 @@ static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) } if (vehicle->var_1F != 8) { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 6); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED; } } } else if (vehicleEntry->var_12 & (1 << 2)) { @@ -682,7 +682,7 @@ static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) } if (vehicle->var_1F != 8 && vehicle->var_1F != 55) { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 6); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED; } } } @@ -735,7 +735,7 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) ); if (trackType == 1) { if (trackElement->flags & (1 << 5)) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 0x400; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_10; } } else if (trackType == 123 || trackType == 216 || track_element_is_lift_hill(trackElement)) { if (!(trackElement->flags & (1 << 5))) { @@ -750,7 +750,7 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) } return; } - RCT2_GLOBAL(0x00F64E18, uint32) |= 0x400; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_10; vehicle->var_2C = 0; if (vehicle->velocity <= 0x20000) { vehicle->velocity = 0; @@ -1044,7 +1044,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) return; } - RCT2_GLOBAL(0x00F64E18, uint32) |= 8; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_3; rct_map_element *mapElement = map_get_track_element_at_of_type_seq( vehicle->track_x, @@ -1068,12 +1068,12 @@ void sub_6DBF3E(rct_vehicle *vehicle) input.y = vehicle->track_y; input.element = mapElement; if (track_block_get_next(&input, &output, &outputZ, &outputDirection)) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 0x1000; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_12; } } if (vehicle->var_34 <= 3) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 1; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_0; } } @@ -1086,7 +1086,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) uint16 ax = vehicle->var_34; if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { if (ax <= 22) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 1; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_0; } } else { uint16 cx = 17; @@ -1098,7 +1098,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) } if (ax > cx) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 1; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_0; } } } @@ -1246,7 +1246,7 @@ loc_6DAEB9: 0 ); if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 0x800; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_11; } if (track_element_is_block_start(mapElement)) { @@ -1477,7 +1477,7 @@ loc_6DB928: goto loc_6DAEB9; loc_6DB94A: - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; regs.eax = vehicle->var_24 + 1; RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; vehicle->var_24 = 0xFFFFFFFF; @@ -1496,7 +1496,7 @@ loc_6DB967: if (!(rideEntry->flags & RIDE_ENTRY_FLAG_18)) { if (regs.eax > 0xE0000) { if (!(vehicleEntry->var_14 & (1 << 6))) { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 7); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } } } @@ -1507,7 +1507,7 @@ loc_6DB967: vehicle->velocity = head->velocity >> 1; head->velocity = vehicle->velocity >> 1; } - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_1; goto loc_6DBE3F; loc_6DBA13: @@ -1654,7 +1654,7 @@ loc_6DBC3B: if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { trackType = mapElement->properties.track.type; if (RCT2_ADDRESS(0x0099423C, uint16)[trackType] & 0x20) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 0x200; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_9; } } vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; @@ -1664,7 +1664,7 @@ loc_6DBC3B: vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 0x100; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_8; } } } @@ -1741,7 +1741,7 @@ loc_6DBE3F: goto loc_6DBA33; loc_6DBE5E: - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; regs.eax = (sint32)vehicle->var_24 - 0x368A; RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; vehicle->var_24 -= regs.eax; @@ -1760,18 +1760,18 @@ loc_6DBE7F: if (!(rideEntry->flags & RIDE_ENTRY_FLAG_18)) { if (regs.eax > 0xE0000) { if (!(vehicleEntry->var_14 & (1 << 6))) { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 7); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } } } if (vehicleEntry->var_14 & (1 << 14)) { vehicle->velocity -= vehicle->velocity >> 2; - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 2); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } else { vehicle->velocity = v3->velocity >> 1; v3->velocity = v4->velocity >> 1; - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 2); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } goto loc_6DB928; @@ -1785,7 +1785,7 @@ loc_6DBF3E: loc_6DC0F7: if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { - RCT2_GLOBAL(0x00F64E18, uint32) |= 4; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { @@ -1983,7 +1983,8 @@ loc_6DC316: regs.eax = RCT2_GLOBAL(0x00F64E18, uint32); regs.ebx = RCT2_GLOBAL(0x00F64E1C, uint32); if (ride->lifecycle_flags & RIDE_LIFECYCLE_SIX_FLAGS_DEPRECATED) { - regs.eax &= 0xC0; + regs.eax &= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED; + regs.eax &= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } goto end; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 07f4b00691..38c52d9ee9 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -268,6 +268,21 @@ enum { VEHICLE_VISUAL_SUBMARINE }; +enum { + VEHICLE_UPDATE_MOTION_TRACK_FLAG_0 = 1 << 0, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_1 = 1 << 1, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_2 = 1 << 2, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_3 = 1 << 3, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_5 = 1 << 5, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED = 1 << 6, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION = 1 << 7, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_8 = 1 << 8, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_9 = 1 << 9, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_10 = 1 << 10, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_11 = 1 << 11, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_12 = 1 << 12, +}; + #define VEHICLE_SEAT_PAIR_FLAG 0x80 #define VEHICLE_SEAT_NUM_MASK 0x7F From 6a629adc246e774b8c7b8f0c690a33410c1de46a Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 02:59:42 +0000 Subject: [PATCH 103/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 107 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 353c83249f..4a1e310f92 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1989,8 +1989,113 @@ loc_6DC316: goto end; loc_6DC3A7: + RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = vehicle; + RCT2_GLOBAL(0x00F64E18, uint32) = 0; + vehicle->velocity += vehicle->var_2C; + RCT2_GLOBAL(0x00F64E08, sint32) = vehicle->velocity; + RCT2_GLOBAL(0x00F64E0C, sint32) = (vehicle->velocity >> 10) * 42; + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { + vehicle = vehicle_get_tail(vehicle); + } + RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = vehicle; + +loc_6DC40E: + regs.ebx = vehicle->var_1F; + RCT2_GLOBAL(0x00F64E10, uint32) = 1; + vehicle->var_2C = dword_9A2970[vehicle->var_1F]; + vehicle->var_24 = RCT2_GLOBAL(0x00F64E0C, uint32) + vehicle->var_24; + if ((sint32)vehicle->var_24 < 0) { + goto loc_6DCA7A; + } + if ((sint32)vehicle->var_24 < 0x368A) { + goto loc_6DCE02; + } + vehicle->var_B8 &= ~(1 << 1); + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; + invalidate_sprite_2((rct_sprite*)vehicle); + +loc_6DC462: + vehicle->var_D3 = 0; + if (vehicle->var_D3 == 0) { + goto loc_6DC476; + } + vehicle->var_D3--; + goto loc_6DC985; + +loc_6DC476: + if (!(vehicle->var_D5 & (1 << 2))) { + regs.edi = RCT2_ADDRESS(0x008B8F74, uint32)[vehicle->var_D4]; + regs.al = vehicle->var_C5 + 1; + if ((uint8)regs.al < ((uint8*)regs.edi)[-1]) { + vehicle->var_C5 = regs.al; + goto loc_6DC985; + } + vehicle->var_D5 &= ~(1 << 2); + } + + if (vehicle->var_D5 & (1 << 0)) { + regs.di = vehicle->is_child ? vehicle->prev_vehicle_on_ride : vehicle->next_vehicle_on_ride; + rct_vehicle *vEDI = GET_VEHICLE(regs.di); + if (!(vEDI->var_D5 & (1 << 0)) || (vEDI->var_D5 & (1 << 2))) { + goto loc_6DC985; + } + if (vEDI->var_D3 != 0) { + goto loc_6DC985; + } + vEDI->var_D5 &= ~(1 << 0); + vehicle->var_D5 &= ~(1 << 0); + } + + if (vehicle->var_D5 & (1 << 1)) { + regs.di = vehicle->is_child ? vehicle->prev_vehicle_on_ride : vehicle->next_vehicle_on_ride; + rct_vehicle *vEDI = GET_VEHICLE(regs.di); + if (!(vEDI->var_D5 & (1 << 1)) || (vEDI->var_D5 & (1 << 2))) { + goto loc_6DC985; + } + if (vEDI->var_D3 != 0) { + goto loc_6DC985; + } + vEDI->var_D5 &= ~(1 << 1); + vehicle->var_D5 &= ~(1 << 1); + } + + if (vehicle->var_D5 & (1 << 3)) { + rct_vehicle *vEDI = vehicle; + + for (;;) { + vEDI = vEDI->prev_vehicle_on_ride; + if (vEDI == vehicle) { + break; + } + if (!vEDI->is_child) continue; + if (!(vEDI->var_D5 & (1 << 4))) continue; + if (vEDI->track_x != vehicle->track_x) continue; + if (vEDI->track_y != vehicle->track_y) continue; + if (vEDI->track_z != vehicle->track_z) continue; + goto loc_6DC985; + } + + vehicle->var_D5 |= (1 << 4); + vehicle->var_D5 &= ~(1 << 3); + } + +loc_6DC5B8: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DC3A7, ®s); + RCT2_CALLFUNC_Y(0x006DC5B8, ®s); + +loc_6DC985: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DC985, ®s); + +loc_6DCA7A: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DCA7A, ®s); + +loc_6DCE02: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DCE02, ®s); end: hook_setreturnregisters(®s); From 2aeeb08af3eb5e57176a428aafad141d6c3cadb5 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 16:10:30 +0000 Subject: [PATCH 104/162] implement more sub_6DAB4C --- src/ride/track.c | 10 +++ src/ride/track.h | 1 + src/ride/vehicle.c | 164 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 144 insertions(+), 31 deletions(-) diff --git a/src/ride/track.c b/src/ride/track.c index ff0063bb2f..c9c358bfec 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -4962,6 +4962,16 @@ int track_get_actual_bank_2(int rideType, int trackColour, int bank) return bank; } +int track_get_actual_bank_3(rct_vehicle *vehicle, rct_map_element *mapElement) +{ + uint8 colourThingToXor = (vehicle->update_flags >> 9) & 8; + int trackType = mapElement->properties.track.type; + int rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; + int trackColour = mapElement->properties.track.colour ^ colourThingToXor; + int bankStart = gTrackDefinitions[trackType].bank_start; + return track_get_actual_bank_2(rideType, trackColour, bankStart); +} + bool track_element_is_station(rct_map_element *trackElement) { switch (trackElement->properties.track.type) { diff --git a/src/ride/track.h b/src/ride/track.h index fdb999d5b1..d40a42651a 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -555,6 +555,7 @@ void track_element_clear_cable_lift(rct_map_element *trackElement); int track_get_actual_bank(rct_map_element *mapElement, int bank); int track_get_actual_bank_2(int rideType, int trackColour, int bank); +int track_get_actual_bank_3(rct_vehicle *vehicle, rct_map_element *mapElement); bool track_element_is_station(rct_map_element *trackElement); bool track_element_is_covered(int trackElementType); diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 4a1e310f92..d9bc360034 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -860,16 +860,11 @@ static void vehicle_update_scenery_door(rct_vehicle *vehicle) */ static bool loc_6DB38B(rct_vehicle *vehicle, rct_map_element *mapElement) { - uint8 colourThingToXor = (vehicle->update_flags >> 9) & 8; - int trackType = mapElement->properties.track.type; - // Get bank - int rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; - int trackColour = mapElement->properties.track.colour ^ colourThingToXor; - int bankStart = gTrackDefinitions[trackType].bank_start; - bankStart = track_get_actual_bank_2(rideType, trackColour, bankStart); + int bankStart = track_get_actual_bank_3(vehicle, mapElement); // Get vangle + int trackType = mapElement->properties.track.type; int vangleStart = gTrackDefinitions[trackType].vangle_start; // ? @@ -1103,6 +1098,37 @@ void sub_6DBF3E(rct_vehicle *vehicle) } } +/** + * + * rct2: 0x006DB429 + */ +void sub_6DB429(rct_vehicle *vehicle, rct_map_element *mapElement) +{ + rct_ride *ride = GET_RIDE(vehicle->ride); + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + if (vehicleEntry->var_14 & (1 << 14)) { + if (vehicle->var_CD >= 7) { + if (mapElement->properties.track.type != 0) { + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) || + !track_element_is_station(mapElement->properties.track.type) + ) { + return; + } + } + uint16 chance = 0x8000; + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_6) { + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_6; + } else { + chance = 0xA3D; + } + if ((scenario_rand() & 0xFFFF) <= chance) { + vehicle->var_CD = 2; + } + } + } +} + /** * * rct2: 0x006DAB4C @@ -1114,7 +1140,7 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) rct_ride *ride = GET_RIDE(vehicle->ride); rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); - + // esi = vehicle // eax = rideEntry // edi = vehicleEntry @@ -1162,7 +1188,7 @@ loc_6DAE27: loc_6DAEB9: regs.edi = vehicle->track_type; regs.cx = vehicle->track_type >> 2; - + int trackType = vehicle->track_type >> 2; if (trackType == 197 || trackType == 198) { if (vehicle->var_34 == 80) { @@ -1179,7 +1205,7 @@ loc_6DAEB9: ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN && ride->breakdown_reason_pending != BREAKDOWN_BRAKES_FAILURE && ride->mechanic_status == RIDE_MECHANIC_STATUS_4 - )) { + )) { regs.eax = vehicle->var_CF << 16; if (regs.eax < RCT2_GLOBAL(0x00F64E08, sint32)) { vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; @@ -1194,7 +1220,7 @@ loc_6DAEB9: if ((trackType == TRACK_ELEM_FLAT && ride->type == RIDE_TYPE_REVERSE_FREEFALL_COASTER) || (trackType == TRACK_ELEM_POWERED_LIFT) - ) { + ) { vehicle->var_2C = RCT2_GLOBAL(0x0097CF40 + (ride->type * 8) + 7, uint8) << 10; } if (trackType == TRACK_ELEM_BRAKE_FOR_DROP) { @@ -1227,7 +1253,7 @@ loc_6DAEB9: vehicle->var_CD, vehicle->track_type, 0 - ); + ); // There are two bytes before the move info list uint16 unk16 = *((uint16*)((int)moveInfo - 2)); @@ -1244,7 +1270,7 @@ loc_6DAEB9: vehicle->track_z >> 3, trackType, 0 - ); + ); if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_11; } @@ -1319,7 +1345,7 @@ loc_6DB358: } if (mapElement->properties.track.type == 211 || mapElement->properties.track.type == 212 - ) { + ) { if (!vehicle->is_child && vehicle->velocity <= 0x30000) { vehicle->velocity = 0; } @@ -1405,7 +1431,7 @@ loc_6DB706:; vehicle->var_CD, vehicle->track_type, vehicle->var_34 - ); + ); sint16 x = vehicle->track_x + moveInfo->x; sint16 y = vehicle->track_y + moveInfo->y; sint16 z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); @@ -1419,7 +1445,7 @@ loc_6DB706:; vehicle->track_type < 852 && vehicle->var_34 >= 30 && vehicle->var_34 <= 66 - ) { + ) { regs.ebx |= 8; } @@ -1427,14 +1453,14 @@ loc_6DB706:; vehicle->track_type >= 844 && vehicle->track_type < 852 && vehicle->var_34 == 96 - ) { + ) { sub_6DB7D6(vehicle); const rct_vehicle_info *moveInfo2 = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, vehicle->var_34 - ); + ); x = vehicle->x + moveInfo2->x; y = vehicle->y + moveInfo2->y; } @@ -1548,7 +1574,7 @@ loc_6DBA33: vehicle->track_z >> 3, trackType, 0 - ); + ); loc_6DBB08: x = vehicle->track_x; @@ -1605,7 +1631,7 @@ loc_6DBB7E:; } int trackColour = vehicle->update_flags >> 9; - int bank = gTrackDefinitions[trackType].bank_end;; + int bank = gTrackDefinitions[trackType].bank_end; bank = track_get_actual_bank_2(ride->type, regs.al, bank); int vAngle = gTrackDefinitions[trackType].vangle_end; if (RCT2_GLOBAL(0x00F64E36, uint16) != vAngle || @@ -1635,16 +1661,16 @@ loc_6DBC3B: if (vehicle->var_CD != 0 && vehicle->var_CD < 5 - ) { + ) { sint16 xy = (x >> 5) | ((y >> 5) << 8); if (ride->var_13C == xy && ride->var_13F == (z >> 3) - ) { + ) { vehicle->var_CD = 3; } else if ( ride->var_13A == xy && ride->var_13E == (z >> 3) - ) { + ) { vehicle->var_CD = 4; } } @@ -1683,7 +1709,7 @@ loc_6DBC3B: vehicle->var_CD, vehicle->track_type, 0 - ); + ); // There are two bytes before the move info list uint16 unk16 = *((uint16*)((int)moveInfo - 2)); @@ -1696,12 +1722,12 @@ loc_6DBD42: vehicle->var_CD, vehicle->track_type, 0 - ); + ); x = vehicle->track_x + moveInfo->x; y = vehicle->track_y + moveInfo->y; z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); - + regs.ebx = 0; if (x == unk_F64E20->x) { regs.ebx |= 1; } if (y == unk_F64E20->y) { regs.ebx |= 2; } @@ -1773,7 +1799,7 @@ loc_6DBE7F: v3->velocity = v4->velocity >> 1; RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } - + goto loc_6DB928; loc_6DBF20: @@ -1791,7 +1817,7 @@ loc_6DC0F7: if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { goto loc_6DC144; } - + vehicle = GET_VEHICLE(vehicle->next_vehicle_on_train); } else { if (vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { @@ -1848,7 +1874,7 @@ loc_6DC144: regs.eax = regs.edx; regs.eax = regs.eax / regs.ebp; regs.ecx -= regs.eax; - + if (!(vehicleEntry->var_14 & (1 << 3))) { goto loc_6DC2FA; } @@ -1960,7 +1986,7 @@ loc_6DC316: if (regs.bx == TRACK_ELEM_WATER_SPLASH) { if (vehicle->var_34 >= 48 && vehicle->var_34 <= 128 - ) { + ) { regs.eax = vehicle->velocity >> 6; regs.ecx -= regs.eax; } @@ -2082,13 +2108,89 @@ loc_6DC476: } loc_6DC5B8: + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); + + // There are two bytes before the move info list + { + uint16 unk16_v34 = vehicle->var_34 + 1; + uint16 unk16 = *((uint16*)((int)moveInfo - 2)); + if (unk16_v34 < unk16) { + regs.ax = unk16_v34; + goto loc_6DC743; + } + } + + trackType = vehicle->track_type >> 2; + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + mapElement = map_get_track_element_at_of_type_seq( + vehicle->track_x, vehicle->track_y, vehicle->track_z, + trackType, 0 + ); + { + rct_xy_element input, output; + int outZ, outDirection; + if (!track_block_get_next(&input, &output, &outZ, &outDirection)) { + goto loc_6DC9BC; + } + mapElement = output.element; + x = output.x; + y = output.y; + z = outZ; + } + + if (!loc_6DB38B(vehicle, mapElement)) { + goto loc_6DB94A; + } + + rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; + vehicle->update_flags &= VEHICLE_UPDATE_FLAG_11; + if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_3) { + if (mapElement->properties.track.colour & (1 << 2)) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_11; + } + } + + vehicle->track_x = x; + vehicle->track_y = y; + vehicle->track_z = z; + sub_6DB429(vehicle, mapElement); + + if (vehicle->var_CD != 0 && vehicle->var_CD != 5) { + regs.al = x >> 5; + regs.ah = y >> 5; + regs.dl = z >> 3; + if (regs.ax != ride->var_13C || regs.dl != ride->var_13E) { + if (regs.ax == ride->var_13A && regs.dl == ride->var_13E) { + vehicle->var_CD = 4; + } + } else { + vehicle->var_CD = 3; + } + } + + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; + if (track_element_is_lift_hill(mapElement)) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; + } + +loc_6DB50F: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DC5B8, ®s); + RCT2_CALLFUNC_Y(0x006DB50F, ®s); + +loc_6DC743: + // regs.ax = regs.ax; + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DC743, ®s); loc_6DC985: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DC985, ®s); +loc_6DC9BC: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DC9BC, ®s); + loc_6DCA7A: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DCA7A, ®s); From 8408351e07f899c860dfbc5a04f4e3e784252e98 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 16:23:24 +0000 Subject: [PATCH 105/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 63 +++++++++------------------------------------- 1 file changed, 12 insertions(+), 51 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index d9bc360034..9310723e26 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1098,37 +1098,6 @@ void sub_6DBF3E(rct_vehicle *vehicle) } } -/** - * - * rct2: 0x006DB429 - */ -void sub_6DB429(rct_vehicle *vehicle, rct_map_element *mapElement) -{ - rct_ride *ride = GET_RIDE(vehicle->ride); - rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); - - if (vehicleEntry->var_14 & (1 << 14)) { - if (vehicle->var_CD >= 7) { - if (mapElement->properties.track.type != 0) { - if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) || - !track_element_is_station(mapElement->properties.track.type) - ) { - return; - } - } - uint16 chance = 0x8000; - if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_6) { - vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_6; - } else { - chance = 0xA3D; - } - if ((scenario_rand() & 0xFFFF) <= chance) { - vehicle->var_CD = 2; - } - } - } -} - /** * * rct2: 0x006DAB4C @@ -2137,14 +2106,15 @@ loc_6DC5B8: x = output.x; y = output.y; z = outZ; + direction = outDirection; } if (!loc_6DB38B(vehicle, mapElement)) { - goto loc_6DB94A; + goto loc_6DC9BC; } rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; - vehicle->update_flags &= VEHICLE_UPDATE_FLAG_11; + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_11; if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_3) { if (mapElement->properties.track.colour & (1 << 2)) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_11; @@ -2154,29 +2124,20 @@ loc_6DC5B8: vehicle->track_x = x; vehicle->track_y = y; vehicle->track_z = z; - sub_6DB429(vehicle, mapElement); - if (vehicle->var_CD != 0 && vehicle->var_CD != 5) { - regs.al = x >> 5; - regs.ah = y >> 5; - regs.dl = z >> 3; - if (regs.ax != ride->var_13C || regs.dl != ride->var_13E) { - if (regs.ax == ride->var_13A && regs.dl == ride->var_13E) { - vehicle->var_CD = 4; - } - } else { - vehicle->var_CD = 3; + if (vehicle->is_child) { + rct_vehicle *prevVehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); + regs.al = prevVehicle->var_CD; + if (regs.al != 0) { + regs.al--; } + vehicle->var_CD = regs.al; } vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; - if (track_element_is_lift_hill(mapElement)) { - vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; - } - -loc_6DB50F: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DB50F, ®s); + vehicle->track_type = (mapElement->properties.track.type << 2) | (direction & 3); + vehicle->var_CF = (mapElement->properties.track.sequence >> 4) << 1; + regs.ax = 0; loc_6DC743: // regs.ax = regs.ax; From 1e4f7c88759a125b238a0d017ffcaf7984304bca Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 17:37:23 +0000 Subject: [PATCH 106/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 85 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 9310723e26..e3d76d3f30 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1109,6 +1109,8 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) rct_ride *ride = GET_RIDE(vehicle->ride); rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + rct_map_element *mapElement = NULL; // esi = vehicle // eax = rideEntry @@ -1233,7 +1235,7 @@ loc_6DAEB9: RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; - rct_map_element *mapElement = map_get_track_element_at_of_type_seq( + mapElement = map_get_track_element_at_of_type_seq( vehicle->track_x, vehicle->track_y, vehicle->track_z >> 3, @@ -2140,9 +2142,86 @@ loc_6DC5B8: regs.ax = 0; loc_6DC743: - // regs.ax = regs.ax; + vehicle->var_34 = regs.ax; + if (vehicle->is_child) { + vehicle->var_C5++; + if (vehicle->var_C5 >= 6) { + vehicle->var_C5 = 0; + } + } + + for (;;) { + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, vehicle->var_34); + if (moveInfo->x != (uint16)0x8000) { + break; + } + switch (moveInfo->y) { + case 0: // loc_6DC7B4 + if (vehicle->is_child) { + vehicle->var_D5 |= (1 << 3); + } else { + uint16 rand16 = scenario_rand() & 0xFFFF; + regs.bl = 14; + if (rand16 <= 0xA000) { + regs.bl = 12; + if (rand16 <= 0x900) { + regs.bl = 10; + } + } + vehicle->var_CD = regs.bl; + } + vehicle->var_34++; + break; + case 1: // loc_6DC7ED + vehicle->var_D3 = mapElement->properties.track.type; + vehicle->var_34++; + break; + case 2: // loc_6DC800 + vehicle->var_D5 |= (1 << 0); + vehicle->var_34++; + break; + case 3: // loc_6DC810 + vehicle->var_D5 |= (1 << 1); + vehicle->var_34++; + break; + case 4: // loc_6DC820 + trackType = mapElement->properties.track.type; + if (trackType == TRACK_ELEM_BEGIN_STATION) { + rct_peep *peep = GET_PEEP(vehicle->peep[0]); + if (peep->id & 7) { + trackType = TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP; + } + } + if (trackType == TRACK_ELEM_FLAT_TO_25_DEG_UP) { + rct_peep *peep = GET_PEEP(vehicle->peep[0]); + if (peep->id & 7) { + trackType = TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP; + } + } + vehicle->var_D4 = trackType; + vehicle->var_C5 = 0; + vehicle->var_34++; + break; + case 5: // loc_6DC87A + vehicle->var_D5 |= (1 << 2); + vehicle->var_34++; + break; + case 6: // loc_6DC88A + vehicle->var_D5 &= ~(1 << 4); + vehicle->var_D5 |= (1 << 5); + vehicle->var_34++; + break; + default: + log_error("Invalid move info..."); + assert(false); + break; + } + } + +loc_6DC8A1: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DC743, ®s); + regs.edi = mapElement; + RCT2_CALLFUNC_Y(0x006DC8A1, ®s); loc_6DC985: regs.esi = vehicle; From 255e756e28660672c1e029a3b7655ed22623e650 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 20:32:29 +0000 Subject: [PATCH 107/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 80 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 13 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index e3d76d3f30..d35c5021e1 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1104,7 +1104,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) */ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) { - registers regs; + registers regs = { 0 }; rct_ride *ride = GET_RIDE(vehicle->ride); rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); @@ -2173,7 +2173,7 @@ loc_6DC743: vehicle->var_34++; break; case 1: // loc_6DC7ED - vehicle->var_D3 = mapElement->properties.track.type; + vehicle->var_D3 = moveInfo->z; vehicle->var_34++; break; case 2: // loc_6DC800 @@ -2185,20 +2185,20 @@ loc_6DC743: vehicle->var_34++; break; case 4: // loc_6DC820 - trackType = mapElement->properties.track.type; - if (trackType == TRACK_ELEM_BEGIN_STATION) { + z = moveInfo->z; + if (z == 2) { rct_peep *peep = GET_PEEP(vehicle->peep[0]); if (peep->id & 7) { - trackType = TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP; + z = 7; } } - if (trackType == TRACK_ELEM_FLAT_TO_25_DEG_UP) { + if (trackType == 6) { rct_peep *peep = GET_PEEP(vehicle->peep[0]); if (peep->id & 7) { - trackType = TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP; + z = 8; } } - vehicle->var_D4 = trackType; + vehicle->var_D4 = z; vehicle->var_C5 = 0; vehicle->var_34++; break; @@ -2219,13 +2219,63 @@ loc_6DC743: } loc_6DC8A1: - regs.esi = vehicle; - regs.edi = mapElement; - RCT2_CALLFUNC_Y(0x006DC8A1, ®s); + x = vehicle->track_x + moveInfo->x; + y = vehicle->track_y + moveInfo->y; + z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + + // Investigate redundant code + regs.ebx = 0; + if (regs.ax != unk_F64E20->x) { + regs.ebx |= 1; + } + if (regs.cx == unk_F64E20->y) { + regs.ebx |= 2; + } + if (regs.dx == unk_F64E20->z) { + regs.ebx |= 4; + } + regs.ebx = 0x368A; + vehicle->var_24 -= regs.ebx; + if ((sint32)vehicle->var_24 < 0) { + vehicle->var_24 = 0; + } + + unk_F64E20->x = x; + unk_F64E20->y = y; + unk_F64E20->z = z; + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + vehicle->var_1F = moveInfo->var_07; + + if (rideEntry->vehicles[0].var_14 & (1 << 9)) { + if (vehicle->var_1F != 0) { + vehicle->var_4A = 0; + vehicle->var_4C = 0; + vehicle->var_4E = 0; + } + } + + if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { + if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + sub_6DD078(vehicle, vehicle->var_44); + } + } + goto loc_6DC99A; loc_6DC985: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DC985, ®s); + regs.ebx = 0; + vehicle->var_24 -= 0x368A; + if ((sint32)vehicle->var_24 < 0) { + vehicle->var_24 = 0; + } + +loc_6DC99A: + if ((sint32)vehicle->var_24 < 0x368A) { + goto loc_6DCDE4; + } + vehicle->var_2C = dword_9A2970[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + goto loc_6DC462; loc_6DC9BC: regs.esi = vehicle; @@ -2235,6 +2285,10 @@ loc_6DCA7A: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DCA7A, ®s); +loc_6DCDE4: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DCDE4, ®s); + loc_6DCE02: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DCE02, ®s); From e3c1872d673830591f7a07a374ab230edb3dce08 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 20:41:57 +0000 Subject: [PATCH 108/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index d35c5021e1..ff95d129bf 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2278,13 +2278,25 @@ loc_6DC99A: goto loc_6DC462; loc_6DC9BC: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DC9BC, ®s); + RCT2_GLOBAL(0x00F64E18, uint32) |= 0x20; + regs.eax = vehicle->var_24 + 1; + RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + vehicle->var_24 -= regs.eax; + regs.ebx = vehicle->var_1F; + goto loc_6DCD2B; + + ///////////////////////////////////////// + // Dead code: 0x006DC9D9 to 0x006DCA79 // + ///////////////////////////////////////// loc_6DCA7A: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DCA7A, ®s); +loc_6DCD2B: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DCD2B, ®s); + loc_6DCDE4: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DCDE4, ®s); From 66a8a3f0cb7bc3e989eb847f6d9c72d3291d46c1 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 21:29:03 +0000 Subject: [PATCH 109/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 124 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index ff95d129bf..66de7a6e7e 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2101,6 +2101,9 @@ loc_6DC5B8: { rct_xy_element input, output; int outZ, outDirection; + input.x = vehicle->track_x; + input.y = vehicle->track_y; + input.element = mapElement; if (!track_block_get_next(&input, &output, &outZ, &outDirection)) { goto loc_6DC9BC; } @@ -2290,13 +2293,130 @@ loc_6DC9BC: ///////////////////////////////////////// loc_6DCA7A: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DCA7A, ®s); + vehicle->var_B8 &= ~(1 << 1); + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; + invalidate_sprite_2((rct_sprite*)vehicle); + +loc_6DCA9A: + regs.ax = vehicle->var_34 - 1; + if (regs.ax != (short)0xFFFF) { + goto loc_6DCC2C; + } + + trackType = vehicle->track_type >> 2; + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + mapElement = map_get_track_element_at_of_type_seq( + vehicle->track_x, vehicle->track_y, vehicle->track_z, + trackType, 0 + ); + { + track_begin_end trackBeginEnd; + if (!track_block_get_previous(vehicle->track_x, vehicle->track_y, mapElement, &trackBeginEnd)) { + goto loc_6DC9BC; + } + x = trackBeginEnd.begin_x; + y = trackBeginEnd.begin_y; + z = trackBeginEnd.begin_z; + direction = trackBeginEnd.begin_direction; + mapElement = trackBeginEnd.begin_element; + } + + if (!loc_6DB38B(vehicle, mapElement)) { + goto loc_6DCD4A; + } + + rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_11; + if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_3) { + if (mapElement->properties.track.colour & (1 << 2)) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_11; + } + } + + vehicle->track_x = x; + vehicle->track_y = y; + vehicle->track_z = z; + + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; + if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { + if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_8; + } + } + } + + vehicle->track_type = (mapElement->properties.track.type << 2) | (direction & 3); + vehicle->var_CF = (mapElement->properties.track.colour >> 4) << 1; + + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); + + // There are two bytes before the move info list + regs.ax = *((uint16*)((int)moveInfo - 2)) - 1; + +loc_6DCC2C: + vehicle->var_34 = regs.ax; + + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, vehicle->var_34); + x = vehicle->track_x + moveInfo->x; + y = vehicle->track_y + moveInfo->y; + z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + + // Investigate redundant code + regs.ebx = 0; + if (regs.ax != unk_F64E20->x) { + regs.ebx |= 1; + } + if (regs.cx == unk_F64E20->y) { + regs.ebx |= 2; + } + if (regs.dx == unk_F64E20->z) { + regs.ebx |= 4; + } + regs.ebx = 0x368A; + vehicle->var_24 -= regs.ebx; + if ((sint32)vehicle->var_24 < 0) { + vehicle->var_24 = 0; + } + + unk_F64E20->x = x; + unk_F64E20->y = y; + unk_F64E20->z = z; + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + vehicle->var_1F = moveInfo->var_07; + + if (rideEntry->vehicles[0].var_14 & (1 << 9)) { + if (vehicle->var_1F != 0) { + vehicle->var_4A = 0; + vehicle->var_4C = 0; + vehicle->var_4E = 0; + } + } + + if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { + if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + if (sub_6DD078(vehicle, vehicle->var_44)) { + goto loc_6DCD6B; + } + } + } loc_6DCD2B: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DCD2B, ®s); +loc_6DCD4A: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DCD4A, ®s); + +loc_6DCD6B: + regs.esi = vehicle; + RCT2_CALLFUNC_Y(0x006DCD6B, ®s); + loc_6DCDE4: regs.esi = vehicle; RCT2_CALLFUNC_Y(0x006DCDE4, ®s); From 83b15044c40423c87d18d58a4e0753cae4551756 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 22:03:13 +0000 Subject: [PATCH 110/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 66de7a6e7e..138d0add76 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2400,26 +2400,48 @@ loc_6DCC2C: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { if (sub_6DD078(vehicle, vehicle->var_44)) { + regs.bp = vehicle->var_44; goto loc_6DCD6B; } } } loc_6DCD2B: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DCD2B, ®s); + if (vehicle->var_24 >= 0) { + goto loc_6DCDE4; + } + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + goto loc_6DCA9A; loc_6DCD4A: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DCD4A, ®s); + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; + regs.eax = vehicle->var_24 - 0x368A; + RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + vehicle->var_24 -= regs.eax; + regs.ebx = vehicle->var_1F; + goto loc_6DC99A; loc_6DCD6B: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DCD6B, ®s); + regs.eax = vehicle->var_24 - 0x368A; + RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + vehicle->var_24 -= regs.eax; + rct_vehicle *vEBP = GET_VEHICLE(regs.bp); + rct_vehicle *vEDI = RCT2_GLOBAL(0x00F64E04, uint32); + regs.eax = abs(vEDI->velocity - vEBP->velocity); + if (regs.eax > 0xE0000) { + if (!(vehicleEntry->var_14 & (1 << 6))) { + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; + } + } + vEDI->velocity = vEBP->velocity >> 1; + vEBP->velocity = vEDI->velocity >> 1; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; + goto loc_6DC99A; loc_6DCDE4: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DCDE4, ®s); + sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)vehicle); + invalidate_sprite_2((rct_sprite*)vehicle); loc_6DCE02: regs.esi = vehicle; From 89bcf50c762b0c96d3384165f9069d443869bae7 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 22:26:57 +0000 Subject: [PATCH 111/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 67 +++++++++++++++++++++++++++++++++++++++++++++- src/ride/vehicle.h | 1 + 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 138d0add76..895c7b8e6b 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2444,8 +2444,73 @@ loc_6DCDE4: invalidate_sprite_2((rct_sprite*)vehicle); loc_6DCE02: + vehicle->var_2C /= RCT2_GLOBAL(0x00F64E10, uint32); + if (vehicle->var_CD == 2) { + goto loc_6DCEB2; + } + trackType = vehicle->track_type >> 2; + if (!(RCT2_GLOBAL(0x0099BA64 + (trackType * 16), uint32) & 0x10)) { + goto loc_6DCEB2; + } + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_3; + if (trackType != TRACK_ELEM_END_STATION) { + goto loc_6DCEB2; + } + if (vehicle != RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { + goto loc_6DCEB2; + } + regs.ax = vehicle->var_34; + if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + goto loc_6DCE62; + } + regs.cx = 8; + if (regs.ax > regs.cx) { + goto loc_6DCE68; + } + goto loc_6DCEB2; + +loc_6DCE62: + if (regs.ax > 11) { + goto loc_6DCEB2; + } + +loc_6DCE68: + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_0; + regs.al = vehicle->track_x >> 5; + regs.ah = vehicle->track_y >> 5; + regs.dl = vehicle->track_z >> 3; + for (int i = 0; i < 4; i++) { + if ((uint16)regs.ax != ride->station_starts[i]) { + continue; + } + if ((uint16)regs.dl != ride->station_heights[i]) { + continue; + } + RCT2_GLOBAL(0x00F64E1C, uint32) = i; + } + +loc_6DCEB2: + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_4; + } + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { + regs.si = vehicle->next_vehicle_on_train; + if (regs.si == SPRITE_INDEX_NULL) { + goto loc_6DCEFF; + } + vehicle = GET_VEHICLE(regs.si); + goto loc_6DC40E; + } + + if (vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { + goto loc_6DCEFF; + } + vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); + goto loc_6DC40E; + +loc_6DCEFF: regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DCE02, ®s); + RCT2_CALLFUNC_Y(0x006DCEFF, ®s); end: hook_setreturnregisters(®s); diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 38c52d9ee9..833b7de61f 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -273,6 +273,7 @@ enum { VEHICLE_UPDATE_MOTION_TRACK_FLAG_1 = 1 << 1, VEHICLE_UPDATE_MOTION_TRACK_FLAG_2 = 1 << 2, VEHICLE_UPDATE_MOTION_TRACK_FLAG_3 = 1 << 3, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_4 = 1 << 4, VEHICLE_UPDATE_MOTION_TRACK_FLAG_5 = 1 << 5, VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED = 1 << 6, VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION = 1 << 7, From 656bc61a6a9453ddc16677c4367cb7418d4ada27 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 13 Dec 2015 22:53:06 +0000 Subject: [PATCH 112/162] implement more sub_6DAB4C --- src/ride/vehicle.c | 95 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 895c7b8e6b..5977ef15a8 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2495,10 +2495,10 @@ loc_6DCEB2: } if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.si = vehicle->next_vehicle_on_train; - if (regs.si == SPRITE_INDEX_NULL) { + if ((uint16)regs.si == SPRITE_INDEX_NULL) { goto loc_6DCEFF; } - vehicle = GET_VEHICLE(regs.si); + vehicle = GET_VEHICLE((uint16)regs.si); goto loc_6DC40E; } @@ -2509,8 +2509,95 @@ loc_6DCEB2: goto loc_6DC40E; loc_6DCEFF: - regs.esi = vehicle; - RCT2_CALLFUNC_Y(0x006DCEFF, ®s); + vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); + regs.eax = 0; + regs.ebp = 0; + regs.dx = 0; + regs.ebx = 0; + + for (;;) { + regs.ebx++; + regs.dx |= vehicle->update_flags; + regs.bp += vehicle->friction; + regs.eax += vehicle->var_2C; + regs.si = vehicle->next_vehicle_on_train; + if ((uint16)regs.si == SPRITE_INDEX_NULL) { + break; + } + vehicle = GET_VEHICLE((uint16)regs.si); + } + + vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); + regs.ebx /= regs.eax; + regs.ecx = (regs.eax * 21) >> 9; + regs.eax = vehicle->velocity >> 12; + regs.ecx -= regs.eax; + regs.ebx = vehicle->velocity; + regs.edx = vehicle->velocity >> 8; + regs.edx *= regs.edx; + if (regs.ebx < 0) { + regs.edx = -regs.edx; + } + regs.edx >>= 4; + regs.eax = regs.edx / regs.ebp; + regs.ecx -= regs.eax; + + if (!(vehicleEntry->var_14 & (1 << 3))) { + goto loc_6DD069; + } + if (vehicleEntry->var_12 & (1 << 0)) { + regs.eax = vehicle->speed * 0x4000; + if (regs.eax < vehicle->velocity) { + goto loc_6DD069; + } + } + regs.eax = vehicle->speed; + regs.bx = vehicle->track_type >> 2; + regs.ebx = regs.eax; + regs.eax <<= 14; + regs.ebx *= regs.ebp; + regs.ebx >>= 2; + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_3) { + regs.eax = -regs.eax; + } + regs.eax -= vehicle->velocity; + regs.edx = vehicle->acceleration; + regs.edx <<= 1; + regs.eax *= regs.edx; + regs.eax = regs.eax / regs.ebx; + + if (!(vehicleEntry->var_14 & (1 << 13))) { + goto loc_6DD054; + } + + if (regs.eax < 0) { + regs.eax >>= 4; + } + + if (vehicleEntry->var_14 & (1 << 2)) { + vehicle->var_B6 = clamp(-0x200, (sint16)vehicle->var_B6, 0x200); + } + + if (vehicle->var_1F != 0) { + regs.eax = max(0, regs.eax); + if (vehicleEntry->var_14 & (1 << 2)) { + if (vehicle->var_1F == 2) { + vehicle->var_B6 = 0; + } + } + } else { + loc_6DD054: + regs.ebx = abs(vehicle->velocity); + if (regs.ebx > 0x10000) { + regs.ecx = 0; + } + } + regs.ecx += regs.eax; + +loc_6DD069: + vehicle->var_2C = regs.ecx; + regs.eax = RCT2_GLOBAL(0x00F64E18, uint32); + regs.ebx = RCT2_GLOBAL(0x00F64E1C, uint32); end: hook_setreturnregisters(®s); From 490bdc85a6a6c3bfe6ea05f382bb809ed8b04adf Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 14 Dec 2015 12:30:28 +0000 Subject: [PATCH 113/162] implement sub_6DEDE8 --- src/ride/vehicle.c | 70 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 5977ef15a8..09ecdac0fc 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -27,10 +27,12 @@ #include "../openrct2.h" #include "../scenario.h" #include "../world/map_animation.h" +#include "../world/scenery.h" #include "../world/sprite.h" #include "ride.h" #include "ride_data.h" #include "track.h" +#include "track_data.h" #include "vehicle.h" rct_xyz16 *unk_F64E20 = (rct_xyz16*)0x00F64E20; @@ -47,6 +49,17 @@ typedef struct { static void vehicle_update(rct_vehicle *vehicle); +const uint8 DoorOpenSoundIds[] = { + SOUND_WATER_2, + SOUND_DOOR_OPEN +}; + +const uint8 DoorCloseSoundIds[] = { + SOUND_62, + SOUND_DOOR_CLOSE, + SOUND_62 +}; + /** * * rct2: 0x006BB9FF @@ -845,6 +858,38 @@ static void sub_6D63D4(rct_vehicle *vehicle) RCT2_CALLPROC_X(0x006D63D4, 0, 0, 0, 0, (int)vehicle, 0, 0); } +/** + * + * rct2: 0x006DEDB1 + */ +static vehicle_play_scenery_door_open_sound(rct_vehicle *vehicle, rct_map_element *mapElement) +{ + rct_scenery_entry *wallEntry = g_wallSceneryEntries[mapElement->properties.fence.type]; + int doorSoundType = (wallEntry->wall.flags2 >> 1) & 3; + if (doorSoundType != 0) { + int soundId = DoorOpenSoundIds[doorSoundType]; + if (soundId != 255) { + audio_play_sound_at_location(doorSoundType, vehicle->x, vehicle->track_y, vehicle->track_z); + } + } +} + +/** + * + * rct2: 0x006DED7A + */ +static vehicle_play_scenery_door_close_sound(rct_vehicle *vehicle, rct_map_element *mapElement) +{ + rct_scenery_entry *wallEntry = g_wallSceneryEntries[mapElement->properties.fence.type]; + int doorSoundType = (wallEntry->wall.flags2 >> 1) & 3; + if (doorSoundType != 0) { + int soundId = DoorCloseSoundIds[doorSoundType]; + if (soundId != 255) { + audio_play_sound_at_location(doorSoundType, vehicle->x, vehicle->track_y, vehicle->track_z); + } + } +} + /** * * rct2: 0x006DEE93 @@ -911,7 +956,30 @@ static void vehicle_trigger_on_ride_photo(rct_vehicle *vehicle, rct_map_element */ static void sub_6DEDE8(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006DEDE8, 0, 0, 0, 0, (int)vehicle, 0, 0); + int trackType = vehicle->track_type >> 2; + rct_preview_track *trackBlock = TrackBlocks[trackType]; + rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; + int x = vehicle->x; + int y = vehicle->y; + int z = (vehicle->z - trackBlock->z + trackCoordinates->z_begin) >> 3; + int direction = (vehicle->track_direction + trackCoordinates->rotation_begin) & 3; + direction ^= 2; + + rct_map_element *mapElement = map_get_fence_element_at(x, y, z, direction); + if (mapElement == NULL) { + return; + } + + if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { + mapElement->properties.fence.item[3] &= 7; + mapElement->properties.fence.item[3] |= 0x88; + map_animation_create(MAP_ANIMATION_TYPE_WALL_UNKNOWN, x, y, z); + vehicle_play_scenery_door_open_sound(vehicle, mapElement); + } else { + mapElement->properties.fence.item[3] &= 7; + mapElement->properties.fence.item[3] |= 0xB0; + vehicle_play_scenery_door_close_sound(vehicle, mapElement); + } } static void vehicle_update_play_water_splash_sound() From e0af62ee8aeed7ec8ee68ae604583d1ad17d633b Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 14 Dec 2015 15:28:36 +0000 Subject: [PATCH 114/162] implement vehicle_update_scenery_door --- src/ride/vehicle.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 09ecdac0fc..7060ff008b 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -896,7 +896,32 @@ static vehicle_play_scenery_door_close_sound(rct_vehicle *vehicle, rct_map_eleme */ static void vehicle_update_scenery_door(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006DEE93, 0, 0, 0, 0, (int)vehicle, 0, 0); + int trackType = vehicle->track_type >> 2; + rct_preview_track *trackBlock = TrackBlocks[trackType]; + while ((trackBlock + 1)->index != 255) { + trackBlock++; + } + rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; + int x = floor2(vehicle->x, 32); + int y = floor2(vehicle->y, 32); + int z = (vehicle->track_z - trackBlock->z + trackCoordinates->z_end) >> 3; + int direction = (vehicle->track_direction + trackCoordinates->rotation_end) & 3; + + rct_map_element *mapElement = map_get_fence_element_at(x, y, z, direction); + if (mapElement == NULL) { + return; + } + + if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { + mapElement->properties.fence.item[3] &= 7; + mapElement->properties.fence.item[3] |= 8; + map_animation_create(MAP_ANIMATION_TYPE_WALL_UNKNOWN, x, y, z); + vehicle_play_scenery_door_open_sound(vehicle, mapElement); + } else { + mapElement->properties.fence.item[3] &= 7; + mapElement->properties.fence.item[3] |= 0x30; + vehicle_play_scenery_door_close_sound(vehicle, mapElement); + } } /** @@ -959,9 +984,9 @@ static void sub_6DEDE8(rct_vehicle *vehicle) int trackType = vehicle->track_type >> 2; rct_preview_track *trackBlock = TrackBlocks[trackType]; rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; - int x = vehicle->x; - int y = vehicle->y; - int z = (vehicle->z - trackBlock->z + trackCoordinates->z_begin) >> 3; + int x = vehicle->track_x; + int y = vehicle->track_y; + int z = (vehicle->track_z - trackBlock->z + trackCoordinates->z_begin) >> 3; int direction = (vehicle->track_direction + trackCoordinates->rotation_begin) & 3; direction ^= 2; From 19679de125be0b3a6186dadf3d49c931868f222f Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 14 Dec 2015 20:08:15 +0000 Subject: [PATCH 115/162] implement sub_6D661F --- src/ride/vehicle.c | 359 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 358 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 7060ff008b..65e988145f 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -840,13 +840,370 @@ static void sub_6D6776(rct_vehicle *vehicle) RCT2_CALLPROC_X(0x006D6776, 0, 0, 0, 0, (int)vehicle, (int)vehicleEntry, 0); } +#pragma region off_9A2E84 + +enum { + loc_6D673C, + loc_6D66F0, + loc_6D672B, + loc_6D6711, + loc_6D66D6, + loc_6D66C3, + loc_6D66B0, + loc_6D669A, + loc_6D6684, + loc_6D665A, + loc_6D6708, + loc_6D6703, + loc_6D66DD, + loc_6D6718 +}; + +static const uint8 off_9A2E84[256] = { + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D66F0, + loc_6D672B, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D66F0, + loc_6D672B, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D66F0, + loc_6D672B, + loc_6D66F0, + loc_6D672B, + loc_6D6711, + loc_6D66D6, + loc_6D673C, + loc_6D673C, + loc_6D66C3, + loc_6D66B0, + loc_6D66C3, + loc_6D66B0, + loc_6D66C3, + loc_6D66B0, + loc_6D66C3, + loc_6D66B0, + loc_6D669A, + loc_6D6684, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D66F0, + loc_6D672B, + loc_6D6711, + loc_6D66D6, + loc_6D66C3, + loc_6D66B0, + loc_6D66C3, + loc_6D66B0, + loc_6D66C3, + loc_6D66B0, + loc_6D66F0, + loc_6D672B, + loc_6D66F0, + loc_6D672B, + loc_6D669A, + loc_6D6684, + loc_6D669A, + loc_6D6684, + loc_6D673C, + loc_6D665A, + loc_6D673C, + loc_6D66F0, + loc_6D672B, + loc_6D66F0, + loc_6D672B, + loc_6D66F0, + loc_6D672B, + loc_6D66F0, + loc_6D672B, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D6708, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D6703, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D66DD, + loc_6D6718, + loc_6D66DD, + loc_6D6718, + loc_6D66DD, + loc_6D6718, + loc_6D66DD, + loc_6D6718, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D66C3, + loc_6D66B0, + loc_6D66C3, + loc_6D66B0, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D66C3, + loc_6D66B0, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D66C3, + loc_6D66B0, + loc_6D66C3, + loc_6D66B0, + loc_6D66F0, + loc_6D672B, + loc_6D66F0, + loc_6D672B, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C, + loc_6D673C +}; + +#pragma endregion + /** * * rct2: 0x006D661F */ static void sub_6D661F(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006D661F, 0, 0, 0, 0, (int)vehicle, 0, 0); + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_13) { + vehicle->var_B6 = 0; + return; + } + + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + int spinningInertia = vehicleEntry->spinning_inertia; + int trackType = vehicle->track_type >> 2; + sint32 dword_F64E08 = RCT2_GLOBAL(0x00F64E08, sint32); + int unk; + switch (off_9A2E84[trackType]) { + case loc_6D665A: + spinningInertia += 6; + unk = dword_F64E08 >> spinningInertia; + if (vehicle->sprite_index & 1) { + vehicle->var_B6 -= unk; + } else { + vehicle->var_B6 += unk; + } + break; + case loc_6D6684: + case loc_6D6703: + spinningInertia += 5; + vehicle->var_B6 -= dword_F64E08 >> spinningInertia; + break; + case loc_6D669A: + spinningInertia += 5; + vehicle->var_B6 += dword_F64E08 >> spinningInertia; + break; + case loc_6D66B0: + spinningInertia += 7; + vehicle->var_B6 -= dword_F64E08 >> spinningInertia; + break; + case loc_6D66C3: + spinningInertia += 7; + vehicle->var_B6 += dword_F64E08 >> spinningInertia; + break; + case loc_6D66D6: + if (vehicle->var_34 < 48) { + spinningInertia += 8; + vehicle->var_B6 += dword_F64E08 >> spinningInertia; + break; + } + case loc_6D66DD: + spinningInertia += 9; + vehicle->var_B6 += dword_F64E08 >> spinningInertia; + break; + case loc_6D66F0: + spinningInertia += 8; + vehicle->var_B6 += dword_F64E08 >> spinningInertia; + break; + case loc_6D6708: + if (vehicle->var_34 > 22) { + spinningInertia += 5; + vehicle->var_B6 += dword_F64E08 >> spinningInertia; + } + break; + case loc_6D6711: + if (vehicle->var_34 < 48) { + spinningInertia += 8; + vehicle->var_B6 += dword_F64E08 >> spinningInertia; + break; + } + case loc_6D6718: + spinningInertia += 9; + vehicle->var_B6 -= dword_F64E08 >> spinningInertia; + break; + case loc_6D672B: + spinningInertia += 8; + vehicle->var_B6 += dword_F64E08 >> spinningInertia; + break; + } + + unk = clamp(-0x600, vehicle->var_B6, 0x600); + vehicle->var_B6 = unk; + vehicle->var_BA += unk >> 8; + vehicle->var_B6 -= unk >> vehicleEntry->spinning_friction; + invalidate_sprite_2((rct_sprite*)vehicle); } /** From 3fccb000408ed4e00db134256df4cf0efa181e73 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 14 Dec 2015 21:42:06 +0000 Subject: [PATCH 116/162] Fix spelling mistake. Finished gForce calculations. There are bugs in any loops due to unsigned/signed behaviour --- src/ride/track.h | 34 ++++---- src/ride/vehicle.c | 213 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 189 insertions(+), 58 deletions(-) diff --git a/src/ride/track.h b/src/ride/track.h index 57238af68f..95cf79fdc3 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -518,9 +518,9 @@ enum { TRACK_ELEM_MINI_GOLF_HOLE_C, TRACK_ELEM_MINI_GOLF_HOLE_D, TRACK_ELEM_MINI_GOLF_HOLE_E, - TRACK_ELEM_MULTIDIM_INVERTED_FLAT_TO_90_DEG_QUATER_LOOP_DOWN, - TRACK_ELEM_90_DEG_TO_INVERTED_FLAT_QUATER_LOOP_UP, - TRACK_ELEM_INVERTED_FLAT_TO_90_DEG_QUATER_LOOP_DOWN, + TRACK_ELEM_MULTIDIM_INVERTED_FLAT_TO_90_DEG_QUARTER_LOOP_DOWN, + TRACK_ELEM_90_DEG_TO_INVERTED_FLAT_QUARTER_LOOP_UP, + TRACK_ELEM_INVERTED_FLAT_TO_90_DEG_QUARTER_LOOP_DOWN, TRACK_ELEM_LEFT_CURVED_LIFT_HILL, TRACK_ELEM_RIGHT_CURVED_LIFT_HILL, TRACK_ELEM_LEFT_REVERSER, @@ -529,14 +529,14 @@ enum { TRACK_ELEM_AIR_THRUST_VERTICAL_DOWN, TRACK_ELEM_AIR_THRUST_VERTICAL_DOWN_TO_LEVEL, TRACK_ELEM_BLOCK_BRAKES, - TRACK_ELEM_LEFT_BANKED_QUATER_TURN_3_TILE_25_DEG_UP, - TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_3_TILE_25_DEG_UP, - TRACK_ELEM_LEFT_BANKED_QUATER_TURN_3_TILE_25_DEG_DOWN, - TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_3_TILE_25_DEG_DOWN, - TRACK_ELEM_LEFT_BANKED_QUATER_TURN_5_TILE_25_DEG_UP, - TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_5_TILE_25_DEG_UP, - TRACK_ELEM_LEFT_BANKED_QUATER_TURN_5_TILE_25_DEG_DOWN, - TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_5_TILE_25_DEG_DOWN, + TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_3_TILE_25_DEG_UP, + TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_3_TILE_25_DEG_UP, + TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_3_TILE_25_DEG_DOWN, + TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_3_TILE_25_DEG_DOWN, + TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_5_TILE_25_DEG_UP, + TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_5_TILE_25_DEG_UP, + TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_5_TILE_25_DEG_DOWN, + TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_5_TILE_25_DEG_DOWN, TRACK_ELEM_25_DEG_UP_TO_LEFT_BANKED_25_DEG_UP, TRACK_ELEM_25_DEG_UP_TO_RIGHT_BANKED_25_DEG_UP, TRACK_ELEM_LEFT_BANKED_25_DEG_UP_TO_25_DEG_UP, @@ -561,12 +561,12 @@ enum { TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_DOWN, TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_FLAT, TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_FLAT, - TRACK_ELEM_LEFT_QUATER_TURN_1_TILE_90_DEG_UP, - TRACK_ELEM_RIGHT_QUATER_TURN_1_TILE_90_DEG_UP, - TRACK_ELEM_LEFT_QUATER_TURN_1_TILE_90_DEG_DOWN, - TRACK_ELEM_RIGHT_QUATER_TURN_1_TILE_90_DEG_DOWN, - TRACK_ELEM_MULTIDIM_90_DEG_UP_TO_INVERTED_FLAT_QUATER_LOOP, - TRACK_ELEM_MULTIDIM_FLAT_TO_90_DEG_DOWN_QUATER_LOOP, + TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_90_DEG_UP, + TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_90_DEG_UP, + TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_90_DEG_DOWN, + TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_90_DEG_DOWN, + TRACK_ELEM_MULTIDIM_90_DEG_UP_TO_INVERTED_FLAT_QUARTER_LOOP, + TRACK_ELEM_MULTIDIM_FLAT_TO_90_DEG_DOWN_QUARTER_LOOP, }; enum { diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index c3e3ace4b6..c23989a602 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3852,6 +3852,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) { int _eax = (((sint64)0x280000) * RCT2_ADDRESS(0x009A37E4, sint32)[vehicle->var_1F]) >> 32; _eax = (((sint64)_eax) * RCT2_ADDRESS(0x009A39C4, sint32)[vehicle->var_20]) >> 32; + int _ebp = 0, _ecx = 0, _edx = 0; switch (vehicle->track_type >> 2) { case TRACK_ELEM_FLAT: @@ -3920,11 +3921,12 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_25_DEG_DOWN_TO_RIGHT_BANKED_25_DEG_DOWN: case TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_25_DEG_DOWN: case TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_25_DEG_DOWN: - case TRACK_ELEM_LEFT_QUATER_TURN_1_TILE_90_DEG_UP: - case TRACK_ELEM_RIGHT_QUATER_TURN_1_TILE_90_DEG_UP: - case TRACK_ELEM_LEFT_QUATER_TURN_1_TILE_90_DEG_DOWN: - case TRACK_ELEM_RIGHT_QUATER_TURN_1_TILE_90_DEG_DOWN: + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_90_DEG_UP: + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_90_DEG_UP: + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_90_DEG_DOWN: + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_90_DEG_DOWN: //6d73FF + // Do nothing break; case TRACK_ELEM_FLAT_TO_25_DEG_UP:// case TRACK_ELEM_25_DEG_DOWN_TO_FLAT:// @@ -3942,20 +3944,9 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_UP: case TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_FLAT: case TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_FLAT: + _ecx = 103; //6d7509 break; - case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP:// - case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN:// - case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP_COVERED: - case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN_COVERED: - //6d7545 - break; - case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP:// - case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN:// - case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP_COVERED: - case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN_COVERED: - //6d7551 - break; case TRACK_ELEM_25_DEG_UP_TO_FLAT:// case TRACK_ELEM_FLAT_TO_25_DEG_DOWN:// case TRACK_ELEM_25_DEG_UP_TO_LEFT_BANK: @@ -3973,8 +3964,23 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_RIGHT_BANKED_25_DEG_UP_TO_FLAT: case TRACK_ELEM_FLAT_TO_LEFT_BANKED_25_DEG_DOWN: case TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_DOWN: + _ecx = -103; //6d7569 break; + case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP:// + case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN:// + case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP_COVERED: + case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN_COVERED: + _ecx = 82; + //6d7545 + break; + case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP:// + case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN:// + case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP_COVERED: + case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN_COVERED: + _ecx = -82; + //6d7551 + break; case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES:// case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_UP: case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_DOWN: @@ -3986,6 +3992,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_LEFT_FLYER_TWIST_UP: case TRACK_ELEM_LEFT_FLYER_TWIST_DOWN: case TRACK_ELEM_LEFT_HEARTLINE_ROLL: + _ebp = 98; //6d7590 break; case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES:// @@ -3999,6 +4006,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_RIGHT_FLYER_TWIST_UP: case TRACK_ELEM_RIGHT_FLYER_TWIST_DOWN: case TRACK_ELEM_RIGHT_HEARTLINE_ROLL: + _ebp = -98; //6d75B7 break; case TRACK_ELEM_BANKED_LEFT_QUARTER_TURN_5_TILES: @@ -4006,6 +4014,8 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_LARGE: case TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_UP: case TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_DOWN: + _ecx = 200; + _ebp = 160; //6d75E1 break; case TRACK_ELEM_BANKED_RIGHT_QUARTER_TURN_5_TILES: @@ -4013,18 +4023,23 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_LARGE: case TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_UP: case TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_DOWN: + _ecx = 200; + _ebp = -160; //6d75F0 break; case TRACK_ELEM_S_BEND_LEFT: case TRACK_ELEM_S_BEND_LEFT_COVERED: + _ebp = (vehicle->track_progress < 48) ? 98 : -98; //6d75FF break; case TRACK_ELEM_S_BEND_RIGHT: case TRACK_ELEM_S_BEND_RIGHT_COVERED: + _ebp = (vehicle->track_progress < 48) ? -98 : 98; //6d7608 break; case TRACK_ELEM_LEFT_VERTICAL_LOOP: case TRACK_ELEM_RIGHT_VERTICAL_LOOP: + _ecx = (abs(vehicle->track_progress - 155) / 2) + 28; //6d7690 break; case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES: @@ -4032,6 +4047,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN: case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_COVERED: case TRACK_ELEM_LEFT_CURVED_LIFT_HILL: + _ebp = 59; //6d7704 break; case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES: @@ -4039,98 +4055,139 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN: case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED: case TRACK_ELEM_RIGHT_CURVED_LIFT_HILL: + _ebp = -59; //6d7710 break; case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_BANK: case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_SMALL: case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_SMALL: + _ecx = 100; + _ebp = 100; //6d7782 break; case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_BANK: case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_SMALL: case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_SMALL: + _ecx = 100; + _ebp = -100; //6d778E break; case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE: + _ebp = 45; //6d779A break; case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE: + _ebp = -45; //6d77A3 break; case TRACK_ELEM_HALF_LOOP_UP: case TRACK_ELEM_FLYER_HALF_LOOP_UP: + _ecx = (-(vehicle->track_progress - 155) / 2) + 28; //6d763E break; case TRACK_ELEM_HALF_LOOP_DOWN: case TRACK_ELEM_FLYER_HALF_LOOP_DOWN: + _ecx = (vehicle->track_progress / 2) + 28; //6d7656 break; case TRACK_ELEM_LEFT_CORKSCREW_UP: case TRACK_ELEM_RIGHT_CORKSCREW_DOWN: case TRACK_ELEM_LEFT_FLYER_CORKSCREW_UP: case TRACK_ELEM_RIGHT_FLYER_CORKSCREW_DOWN: + _ecx = 52; + _ebp = 70; //6d76AA break; case TRACK_ELEM_RIGHT_CORKSCREW_UP: case TRACK_ELEM_LEFT_CORKSCREW_DOWN: case TRACK_ELEM_RIGHT_FLYER_CORKSCREW_UP: case TRACK_ELEM_LEFT_FLYER_CORKSCREW_DOWN: + _ecx = 52; + _ebp = -70; //6d76B9 break; case TRACK_ELEM_FLAT_TO_60_DEG_UP: case TRACK_ELEM_60_DEG_DOWN_TO_FLAT: + _ecx = 56; //6d747C break; case TRACK_ELEM_60_DEG_UP_TO_FLAT: case TRACK_ELEM_FLAT_TO_60_DEG_DOWN: case TRACK_ELEM_BRAKE_FOR_DROP: + _ecx = -56; //6d7488 break; case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_UP: case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_DOWN: + _ebp = 88; //6d7770 break; case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_UP: case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_DOWN: + _ebp = -88; //6d7779 break; case TRACK_ELEM_WATER_SPLASH: + _ecx = -150; + if (vehicle->track_progress < 32) + break; + _ecx = 150; + if (vehicle->track_progress < 64) + break; + _ecx = 0; + if (vehicle->track_progress < 96) + break; + _ecx = 150; + if (vehicle->track_progress < 128) + break; + _ecx = -150; //6d7408 break; case TRACK_ELEM_FLAT_TO_60_DEG_UP_LONG_BASE: case TRACK_ELEM_FLAT_TO_60_DEG_DOWN_LONG_BASE: + _ecx = 160; //6d74F1 break; case TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE: case TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE_122: + _ecx = -160; //6d74FD break; case TRACK_ELEM_REVERSE_WHOA_BELLY_SLOPE: case TRACK_ELEM_AIR_THRUST_VERTICAL_DOWN_TO_LEVEL: + _ecx = 120; //6d7458 break; case TRACK_ELEM_60_DEG_UP_TO_90_DEG_UP: case TRACK_ELEM_90_DEG_DOWN_TO_60_DEG_DOWN: + _ecx = 110; //6d7515 break; case TRACK_ELEM_90_DEG_UP_TO_60_DEG_UP: case TRACK_ELEM_60_DEG_DOWN_TO_90_DEG_DOWN: + _ecx = -110; //6d7521 break; case TRACK_ELEM_LEFT_EIGHTH_TO_DIAG: case TRACK_ELEM_LEFT_EIGHTH_TO_ORTHOGONAL: + _ebp = 137; //6d7575 break; case TRACK_ELEM_RIGHT_EIGHTH_TO_DIAG: case TRACK_ELEM_RIGHT_EIGHTH_TO_ORTHOGONAL: + _ebp = -137; //6d759C break; case TRACK_ELEM_LEFT_EIGHTH_BANK_TO_DIAG: case TRACK_ELEM_LEFT_EIGHTH_BANK_TO_ORTHOGONAL: + _ecx = 270; + _ebp = 200; //6d75C3 break; case TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_DIAG: case TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_ORTHOGONAL: + _ecx = 270; + _ebp = -200; //6d75D2 break; case TRACK_ELEM_DIAG_FLAT_TO_25_DEG_UP: @@ -4139,104 +4196,178 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_UP: case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_LEFT_BANK: case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_RIGHT_BANK: + _ecx = 113; //6d7494 break; - case TRACK_ELEM_DIAG_25_DEG_UP_TO_60_DEG_UP: - case TRACK_ELEM_DIAG_60_DEG_DOWN_TO_25_DEG_DOWN: - //6D752D - break; - case TRACK_ELEM_DIAG_60_DEG_UP_TO_25_DEG_UP: - case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_60_DEG_DOWN: - //6D7539 - break; case TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT: case TRACK_ELEM_DIAG_FLAT_TO_25_DEG_DOWN: case TRACK_ELEM_DIAG_25_DEG_UP_TO_LEFT_BANK: case TRACK_ELEM_DIAG_25_DEG_UP_TO_RIGHT_BANK: case TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_DOWN: case TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_DOWN: + _ecx = -113; //6d755D + break; + case TRACK_ELEM_DIAG_25_DEG_UP_TO_60_DEG_UP: + case TRACK_ELEM_DIAG_60_DEG_DOWN_TO_25_DEG_DOWN: + _ecx = 95; + //6D752D + break; + case TRACK_ELEM_DIAG_60_DEG_UP_TO_25_DEG_UP: + case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_60_DEG_DOWN: + _ecx = -95; + //6D7539 break; case TRACK_ELEM_DIAG_FLAT_TO_60_DEG_UP: case TRACK_ELEM_DIAG_60_DEG_DOWN_TO_FLAT: + _ecx = 60; //6D7464 break; case TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT: case TRACK_ELEM_DIAG_FLAT_TO_60_DEG_DOWN: + _ecx = -60; //6d7470 break; case TRACK_ELEM_LEFT_BARREL_ROLL_UP_TO_DOWN: case TRACK_ELEM_LEFT_BARREL_ROLL_DOWN_TO_UP: + _ecx = 170; + _ebp = 115; //6d7581 break; case TRACK_ELEM_RIGHT_BARREL_ROLL_UP_TO_DOWN: case TRACK_ELEM_RIGHT_BARREL_ROLL_DOWN_TO_UP: + _ecx = 170; + _ebp = -115; //6d75A8 break; case TRACK_ELEM_LEFT_BANK_TO_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: + _ecx = -(vehicle->track_progress / 2) + 134; + _ebp = 90; //6d771C break; case TRACK_ELEM_RIGHT_BANK_TO_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: + _ecx = -(vehicle->track_progress / 2) + 134; + _ebp = -90; //6D7746 break; case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_LEFT_BANK: - //6D7731 + _ecx = -(vehicle->track_progress / 2) + 134; + _ebp = 90; + //6D7731 identical to 6d771c break; case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_RIGHT_BANK: - //6D775B + _ecx = -(vehicle->track_progress / 2) + 134; + _ebp = -90; + //6D775B identical to 6d7746 break; case TRACK_ELEM_LEFT_LARGE_HALF_LOOP_UP: case TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_UP: + _ecx = (-(vehicle->track_progress - 311) / 4) + 46; //6d7666 break; case TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_DOWN: case TRACK_ELEM_LEFT_LARGE_HALF_LOOP_DOWN: + _ecx = (vehicle->track_progress / 4) + 46; //6d767F break; case TRACK_ELEM_HEARTLINE_TRANSFER_UP: + _ecx = 103; + if (vehicle->track_progress < 32) + break; + _ecx = -103; + if (vehicle->track_progress < 64) + break; + _ecx = 0; + if (vehicle->track_progress < 96) + break; + _ecx = 103; + if (vehicle->track_progress < 128) + break; + _ecx = -103; //6d74A0 break; case TRACK_ELEM_HEARTLINE_TRANSFER_DOWN: + _ecx = -103; + if (vehicle->track_progress < 32) + break; + _ecx = 103; + if (vehicle->track_progress < 64) + break; + _ecx = 0; + if (vehicle->track_progress < 96) + break; + _ecx = -103; + if (vehicle->track_progress < 128) + break; + _ecx = 103; //6D74CA break; - case TRACK_ELEM_MULTIDIM_INVERTED_FLAT_TO_90_DEG_QUATER_LOOP_DOWN: - case TRACK_ELEM_INVERTED_FLAT_TO_90_DEG_QUATER_LOOP_DOWN: - case TRACK_ELEM_MULTIDIM_FLAT_TO_90_DEG_DOWN_QUATER_LOOP: + case TRACK_ELEM_MULTIDIM_INVERTED_FLAT_TO_90_DEG_QUARTER_LOOP_DOWN: + case TRACK_ELEM_INVERTED_FLAT_TO_90_DEG_QUARTER_LOOP_DOWN: + case TRACK_ELEM_MULTIDIM_FLAT_TO_90_DEG_DOWN_QUARTER_LOOP: + _ecx = (vehicle->track_progress / 4) + 55; //6d762D break; - case TRACK_ELEM_90_DEG_TO_INVERTED_FLAT_QUATER_LOOP_UP: - case TRACK_ELEM_MULTIDIM_90_DEG_UP_TO_INVERTED_FLAT_QUATER_LOOP: + case TRACK_ELEM_90_DEG_TO_INVERTED_FLAT_QUARTER_LOOP_UP: + case TRACK_ELEM_MULTIDIM_90_DEG_UP_TO_INVERTED_FLAT_QUARTER_LOOP: case 255: + _ecx = (-(vehicle->track_progress - 137) / 4) + 55; //6D7614 break; case TRACK_ELEM_AIR_THRUST_TOP_CAP: + _ecx = -60; //6D744C break; - case TRACK_ELEM_LEFT_BANKED_QUATER_TURN_3_TILE_25_DEG_UP: - case TRACK_ELEM_LEFT_BANKED_QUATER_TURN_3_TILE_25_DEG_DOWN: + case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_3_TILE_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_3_TILE_25_DEG_DOWN: + _ecx = 200; + _ebp = 100; //6d76C8 break; - case TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_3_TILE_25_DEG_UP: - case TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_3_TILE_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_3_TILE_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_3_TILE_25_DEG_DOWN: + _ecx = 200; + _ebp = -100; //6d76d7 break; - case TRACK_ELEM_LEFT_BANKED_QUATER_TURN_5_TILE_25_DEG_UP: - case TRACK_ELEM_LEFT_BANKED_QUATER_TURN_5_TILE_25_DEG_DOWN: + case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_5_TILE_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_5_TILE_25_DEG_DOWN: + _ecx = 200; + _ebp = 160; //6D76E6 break; - case TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_5_TILE_25_DEG_UP: - case TRACK_ELEM_RIGHT_BANKED_QUATER_TURN_5_TILE_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_5_TILE_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_5_TILE_25_DEG_DOWN: + _ecx = 200; + _ebp = -160; //6d76F5 break; } + if (_ecx != 0) { + _eax += abs(vehicle->velocity) * 98 / _ecx; + } + + if (_ebp != 0) { + _edx += abs(vehicle->velocity) * 98 / _ebp; + } + + _eax *= 10; + _edx *= 10; + _eax >>= 16; + _edx >>= 16; int eax, ebx, ecx, edx, esi, edi, ebp; esi = (int)vehicle; RCT2_CALLFUNC_X(0x006D73D0, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - if (verticalG != NULL) *verticalG = (sint16)(eax & 0xFFFF); - if (lateralG != NULL) *lateralG = (sint16)(edx & 0xFFFF); + // Note shr causing this to assert on all loops + if (_eax != (sint16)(eax & 0xFFFF)) + assert(_eax == (sint16)(eax & 0xFFFF)); + if (_edx != (sint16)(edx & 0xFFFF)) + assert(_edx == (sint16)(edx & 0xFFFF)); + if (verticalG != NULL) *verticalG = (sint16)(_eax & 0xFFFF); + if (lateralG != NULL) *lateralG = (sint16)(_edx & 0xFFFF); } void vehicle_set_map_toolbar(rct_vehicle *vehicle) From a941e67df6dee0f9d94ff74620d02092b987f1a0 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 14 Dec 2015 23:31:00 +0000 Subject: [PATCH 117/162] fix vehicle-update after merge with sub_6DAB4C --- src/hook.c | 144 ++++++++++++++++----------------------------- src/hook.h | 6 +- src/openrct2.c | 75 +++++++++++++++++------ src/ride/vehicle.c | 9 ++- 4 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/hook.c b/src/hook.c index 28a65bf538..1f8da14bf6 100644 --- a/src/hook.c +++ b/src/hook.c @@ -30,9 +30,7 @@ void* g_hooktableaddress = 0; int g_hooktableoffset = 0; int g_maxhooks = 1000; -registers _returnRegisters; - -void hookfunc(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister, bool useReturnRegisters) +void hookfunc(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister) { int i = 0; char data[100]; @@ -55,73 +53,6 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in int rargssize = numrargs * 4; - data[i++] = 0x50; // push eax - - // move stack down for possible existing arguments - for (int j = 0; j < stacksize; j++) { - data[i++] = 0x8B; // mov eax, [esp+x] - data[i++] = 0x44; - data[i++] = 0xE4; - data[i++] = (signed char)((4 * (stacksize - j)) + 4); - - data[i++] = 0x89; // mov [esp+x], eax - data[i++] = 0x44; - data[i++] = 0xE4; - data[i++] = (signed char)((4 * (stacksize - j)) - ((registerssaved + stacksize) * 4)); - } - - if (numrargs > 0) { - // push the registers to be on the stack to access as arguments - data[i++] = 0x83; // add esp, x - data[i++] = 0xC4; - data[i++] = -((registerssaved + stacksize) * 4) + 4; - - for (signed int j = numrargs - 1; j >= 0; j--) { - switch (registerargs[j]) { - case EAX: data[i++] = 0x50; break; - case EBX: data[i++] = 0x53; break; - case ECX: data[i++] = 0x51; break; - case EDX: data[i++] = 0x52; break; - case ESI: data[i++] = 0x56; break; - case EDI: data[i++] = 0x57; break; - case EBP: data[i++] = 0x55; break; - } - } - - data[i++] = 0x83; // add esp, x - data[i++] = 0xC4; - data[i++] = rargssize + ((registerssaved + stacksize) * 4) - 4; - } - - - data[i++] = 0xE8; // call - data[i++] = 0x00; - data[i++] = 0x00; - data[i++] = 0x00; - data[i++] = 0x00; - - int sizec = i; - - data[i++] = 0x8B; // push eax, [esp] - puts eip in eax - data[i++] = 0x04; - data[i++] = 0xE4; - - data[i++] = 0x83; // add eax, x - data[i++] = 0xC0; - int sizeoffset = i; - data[i++] = 0; // set to returnlocation offset later - - data[i++] = 0x89; // mov [esp-20h], eax - put return address on stack - data[i++] = 0x44; - data[i++] = 0xE4; - data[i++] = (signed char)(-(registerssaved * 4) - rargssize - (stacksize * 4)) + 4; - - data[i++] = 0x83; // add esp, x - data[i++] = 0xC4; - data[i++] = 4; - - data[i++] = 0x58; // pop eax - if (!(registersreturned & EAX)) { data[i++] = 0x50; // push eax } @@ -144,15 +75,51 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in data[i++] = 0x57; // push edi } - data[i++] = 0x83; // sub esp, x - data[i++] = 0xEC; - data[i++] = 4 + (stacksize * 4) + rargssize; + data[i++] = 0x50; //push eax + data[i++] = 0x89; //mov eax, esp + data[i++] = 0xE0; + data[i++] = 0x83; //sub eax, (0xC + numargs*4) & 0xF + data[i++] = 0xE8; + data[i++] = (0xC + numrargs * 4) & 0xF; + data[i++] = 0x83; //and eax, 0xC + data[i++] = 0xE0; + data[i++] = 0x0C; + data[i++] = 0xA3; //mov [0x9ABDA8], eax + data[i++] = 0xA8; + data[i++] = 0xBD; + data[i++] = 0x9A; + data[i++] = 0x00; + data[i++] = 0x58; //pop eax + data[i++] = 0x2B; //sub esp, [0x9ABDA8] + data[i++] = 0x25; + data[i++] = 0xA8; + data[i++] = 0xBD; + data[i++] = 0x9A; + data[i++] = 0x00; - data[i++] = 0xE9; // jmp + // work out distance to nearest 0xC + // (esp - numargs * 4) & 0xC + // move to align - 4 + // save that amount + + if (numrargs > 0) { + // push the registers to be on the stack to access as arguments + for (signed int j = numrargs - 1; j >= 0; j--) { + switch (registerargs[j]) { + case EAX: data[i++] = 0x50; break; + case EBX: data[i++] = 0x53; break; + case ECX: data[i++] = 0x51; break; + case EDX: data[i++] = 0x52; break; + case ESI: data[i++] = 0x56; break; + case EDI: data[i++] = 0x57; break; + case EBP: data[i++] = 0x55; break; + } + } + } + + data[i++] = 0xE8; // call *((int *)&data[i]) = (newaddress - address - i - 4); i += 4; - data[sizeoffset] = i - sizec; - // returnlocation: switch (eaxDestinationRegister) { @@ -188,19 +155,17 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in break; } - if (useReturnRegisters) { - // mov ebx, [_returnRegisters.ebx] - data[i++] = 0x8B; - data[i++] = 0x1C; - data[i++] = 0x25; - *((uint32*)&data[i]) = (uint32)(&_returnRegisters.ebx); - i += 4; - } - data[i++] = 0x83; // sub esp, x data[i++] = 0xEC; data[i++] = (signed char)(stacksize * -4) - rargssize; + data[i++] = 0x03; //add esp, [0x9ABDA8] + data[i++] = 0x25; + data[i++] = 0xA8; + data[i++] = 0xBD; + data[i++] = 0x9A; + data[i++] = 0x00; + if (!(registersreturned & EDI)) { data[i++] = 0x5F; // pop edi } @@ -233,7 +198,7 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in #endif // _WIN32 } -void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister, bool useReturnRegisters) +void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister) { if (!g_hooktableaddress) { size_t size = g_maxhooks * 100; @@ -263,11 +228,6 @@ void addhook(int address, int newaddress, int stacksize, int registerargs[], int // We own the pages with PROT_WRITE | PROT_EXEC, we can simply just memcpy the data memcpy((void *)address, data, i); #endif // _WIN32 - hookfunc(hookaddress, newaddress, stacksize, registerargs, registersreturned, eaxDestinationRegister, useReturnRegisters); + hookfunc(hookaddress, newaddress, stacksize, registerargs, registersreturned, eaxDestinationRegister); g_hooktableoffset++; -} - -void hook_setreturnregisters(registers *regs) -{ - _returnRegisters = *regs; } \ No newline at end of file diff --git a/src/hook.h b/src/hook.h index 38cf1d1198..7f2289f059 100644 --- a/src/hook.h +++ b/src/hook.h @@ -21,9 +21,6 @@ #ifndef _HOOK_H_ #define _HOOK_H_ -#include "addresses.h" -#include "common.h" - enum REGISTER_ARGS { EAX = 1 << 0, EBX = 1 << 1, @@ -35,7 +32,6 @@ enum REGISTER_ARGS { END = 0 }; -void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister, bool useReturnRegisters); -void hook_setreturnregisters(registers *regs); +void addhook(int address, int newaddress, int stacksize, int registerargs[], int registersreturned, int eaxDestinationRegister); #endif \ No newline at end of file diff --git a/src/openrct2.c b/src/openrct2.c index 0018f36252..26a8bdf27e 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -40,14 +40,14 @@ #include "util/util.h" #include "world/mapgen.h" -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#if defined(__unix__) #include #include #include #include #include #include -#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#endif // defined(__unix__) int gOpenRCT2StartupAction = STARTUP_ACTION_TITLE; utf8 gOpenRCT2StartupActionPath[512] = { 0 }; @@ -59,11 +59,11 @@ bool gOpenRCT2Headless = false; bool gOpenRCT2ShowChangelog; -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#if defined(__unix__) void *gDataSegment; void *gTextSegment; int gExeFd; -#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#endif // defined(__unix__) /** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to 0. */ int _finished; @@ -471,7 +471,7 @@ static bool openrct2_setup_rct2_segment() { // POSIX OSes will run OpenRCT2 as a native application and then load in the Windows PE, mapping the appropriate addresses as // necessary. Windows does not need to do this as OpenRCT2 runs as a DLL loaded from the Windows PE. -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#if defined(__unix__) #define RDATA_OFFSET 0x004A4000 #define DATASEG_OFFSET 0x005E2000 @@ -513,8 +513,45 @@ static bool openrct2_setup_rct2_segment() off_t file_size = 6750208; int len = 0x01429000 - 0x8a4000; // 0xB85000, 12079104 bytes or around 11.5MB + int pageSize = getpagesize(); + int numPages = (len + pageSize - 1) / pageSize; + unsigned char *dummy = malloc(numPages); + int err = mincore((void *)0x8a4000, len, dummy); + bool pagesDirty = false; + if (err != 0) + { + err = errno; +#ifdef __linux__ + // On Linux ENOMEM means all requested range is unmapped + if (err != ENOMEM) + { + pagesDirty = true; + perror("mincore"); + } +#else + pagesDirty = true; + perror("mincore"); +#endif // __linux__ + } else { + log_warning("mincore ok"); + for (int i = 0; i < numPages; i++) + { + if (dummy[i] != 0) + { + pagesDirty = true; + void *start = (void *)0x8a4000 + i * pageSize; + void *end = (void *)0x8a4000 + (i + 1) * pageSize - 1; + log_warning("page %p - %p has flags: %x, you're in for bad time!", start, end, dummy[i]); + } + } + } + free(dummy); + if (pagesDirty) + { + log_error("Found already mapped pages in region we want to claim. This means something accessed memory before we got to and following mmap (or next malloc) call will likely fail."); + } // section: rw data - gDataSegment = mmap((void *)0x8a4000, len, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_SHARED, 0, 0); + gDataSegment = mmap((void *)0x8a4000, len, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_SHARED, -1, 0); if (gDataSegment != (void *)0x8a4000) { log_fatal("mmap failed to get required offset for data segment! got %p, expected %p, errno = %d", gDataSegment, (void *)(0x8a4000), errno); exit(1); @@ -530,7 +567,7 @@ static bool openrct2_setup_rct2_segment() } void *fbase = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, gExeFd, 0); - int err = errno; + err = errno; log_warning("mmapped file to %p", fbase); if (fbase == MAP_FAILED) { @@ -548,7 +585,7 @@ static bool openrct2_setup_rct2_segment() err = errno; log_error("Failed to unmap file! errno = %d", err); } -#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#endif // defined(__unix__) // Check that the expected data is at various addresses. // Start at 0x9a6000, which is start of .data, to skip the region containing addresses to DLL @@ -572,7 +609,7 @@ static bool openrct2_setup_rct2_segment() static bool openrct2_release_rct2_segment() { bool result = true; -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#if defined(__unix__) int len = 0x01429000 - 0x8a4000; // 0xB85000, 12079104 bytes or around 11.5MB int err; err = munmap(gDataSegment, len); @@ -597,7 +634,7 @@ static bool openrct2_release_rct2_segment() log_error("Failed to close file! errno = %d", err); result = false; } -#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#endif // defined(__unix__) return result; } @@ -606,14 +643,14 @@ static bool openrct2_release_rct2_segment() */ static void openrct2_setup_rct2_hooks() { - addhook(0x006E732D, (int)gfx_set_dirty_blocks, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0, false); // remove when all callers are decompiled - addhook(0x006E7499, (int)gfx_redraw_screen_rect, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0, false); // remove when 0x6E7FF3 is decompiled - addhook(0x0069A42F, (int)peep_window_state_update, 0, (int[]){ ESI, END }, 0, 0, false); // remove when all callers are decompiled - addhook(0x006BB76E, (int)audio_play_sound_panned, 0, (int[]){EAX, EBX, ECX, EDX, EBP, END}, EAX, 0, false); // remove when all callers are decompiled - addhook(0x006C42D9, (int)scrolling_text_setup, 0, (int[]){EAX, ECX, EBP, END}, 0, EBX, false); // remove when all callers are decompiled - addhook(0x006C2321, (int)gfx_get_string_width, 0, (int[]){ESI, END}, 0, ECX, false); // remove when all callers are decompiled - addhook(0x006C2555, (int)format_string, 0, (int[]){EDI, EAX, ECX, END}, 0, 0, false); // remove when all callers are decompiled - addhook(0x006DAB4C, (int)sub_6DAB4C, 0, (int[]){ESI, END}, 0, EAX, true); // remove when all callers are decompiled + addhook(0x006E732D, (int)gfx_set_dirty_blocks, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0); // remove when all callers are decompiled + addhook(0x006E7499, (int)gfx_redraw_screen_rect, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0); // remove when 0x6E7FF3 is decompiled + addhook(0x006B752C, (int)ride_crash, 0, (int[]){ EDX, EBX, END }, 0, 0); // remove when all callers are decompiled + addhook(0x0069A42F, (int)peep_window_state_update, 0, (int[]){ ESI, END }, 0, 0); // remove when all callers are decompiled + addhook(0x006BB76E, (int)audio_play_sound_panned, 0, (int[]){EAX, EBX, ECX, EDX, EBP, END}, 0, EAX); // remove when all callers are decompiled + addhook(0x006C42D9, (int)scrolling_text_setup, 0, (int[]){EAX, ECX, EBP, END}, 0, EBX); // remove when all callers are decompiled + addhook(0x006C2321, (int)gfx_get_string_width, 0, (int[]){ESI, END}, 0, ECX); // remove when all callers are decompiled + addhook(0x006C2555, (int)format_string, 0, (int[]){EDI, EAX, ECX, END}, 0, 0); // remove when all callers are decompiled } #if _MSC_VER >= 1900 @@ -628,4 +665,4 @@ FILE **__iob_func() streams[2] = stderr; return streams; } -#endif +#endif \ No newline at end of file diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 40e102fefc..aefaa12199 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -5927,6 +5927,13 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) { registers regs = { 0 }; + ////////////////////////////////////////////////////////////////////////////////////////// + regs.esi = (int)vehicle; + RCT2_CALLFUNC_Y(0x006DAB4C, ®s); + if (outStation != NULL) *outStation = regs.ebx; + return regs.eax; + ////////////////////////////////////////////////////////////////////////////////////////// + rct_ride *ride = GET_RIDE(vehicle->ride); rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); @@ -7421,7 +7428,7 @@ loc_6DD069: regs.ebx = RCT2_GLOBAL(0x00F64E1C, uint32); end: - hook_setreturnregisters(®s); + // hook_setreturnregisters(®s); return regs.eax; } From 75b59462997e455aafd169157582dbc99ab08b23 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 15 Dec 2015 17:47:30 +0000 Subject: [PATCH 118/162] Refactor get_g_force and fix known signed/unsigned issues --- src/ride/vehicle.c | 215 +++++++++++++++++++++++---------------------- 1 file changed, 109 insertions(+), 106 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index aefaa12199..e4b78bb845 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3866,10 +3866,12 @@ produceScream: */ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) { - int _eax = (((sint64)0x280000) * RCT2_ADDRESS(0x009A37E4, sint32)[vehicle->var_1F]) >> 32; - _eax = (((sint64)_eax) * RCT2_ADDRESS(0x009A39C4, sint32)[vehicle->var_20]) >> 32; - int _ebp = 0, _ecx = 0, _edx = 0; + int gForceVert = (((sint64)0x280000) * RCT2_ADDRESS(0x009A37E4, sint32)[vehicle->var_1F]) >> 32; + gForceVert = (((sint64)gForceVert) * RCT2_ADDRESS(0x009A39C4, sint32)[vehicle->var_20]) >> 32; + int lateralFactor = 0, vertFactor = 0; + // Note shr has meant some of the below functions cast a known negative number to + // unsigned. Possibly an original bug but will be left implemented. switch (vehicle->track_type >> 2) { case TRACK_ELEM_FLAT: case TRACK_ELEM_END_STATION: @@ -3960,7 +3962,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_UP: case TRACK_ELEM_LEFT_BANKED_25_DEG_DOWN_TO_FLAT: case TRACK_ELEM_RIGHT_BANKED_25_DEG_DOWN_TO_FLAT: - _ecx = 103; + vertFactor = 103; //6d7509 break; case TRACK_ELEM_25_DEG_UP_TO_FLAT:// @@ -3980,21 +3982,21 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_RIGHT_BANKED_25_DEG_UP_TO_FLAT: case TRACK_ELEM_FLAT_TO_LEFT_BANKED_25_DEG_DOWN: case TRACK_ELEM_FLAT_TO_RIGHT_BANKED_25_DEG_DOWN: - _ecx = -103; + vertFactor = -103; //6d7569 break; case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP:// case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN:// case TRACK_ELEM_25_DEG_UP_TO_60_DEG_UP_COVERED: case TRACK_ELEM_60_DEG_DOWN_TO_25_DEG_DOWN_COVERED: - _ecx = 82; + vertFactor = 82; //6d7545 break; case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP:// case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN:// case TRACK_ELEM_60_DEG_UP_TO_25_DEG_UP_COVERED: case TRACK_ELEM_25_DEG_DOWN_TO_60_DEG_DOWN_COVERED: - _ecx = -82; + vertFactor = -82; //6d7551 break; case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES:// @@ -4008,7 +4010,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_LEFT_FLYER_TWIST_UP: case TRACK_ELEM_LEFT_FLYER_TWIST_DOWN: case TRACK_ELEM_LEFT_HEARTLINE_ROLL: - _ebp = 98; + lateralFactor = 98; //6d7590 break; case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES:// @@ -4022,7 +4024,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_RIGHT_FLYER_TWIST_UP: case TRACK_ELEM_RIGHT_FLYER_TWIST_DOWN: case TRACK_ELEM_RIGHT_HEARTLINE_ROLL: - _ebp = -98; + lateralFactor = -98; //6d75B7 break; case TRACK_ELEM_BANKED_LEFT_QUARTER_TURN_5_TILES: @@ -4030,8 +4032,8 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_LARGE: case TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_UP: case TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_DOWN: - _ecx = 200; - _ebp = 160; + vertFactor = 200; + lateralFactor = 160; //6d75E1 break; case TRACK_ELEM_BANKED_RIGHT_QUARTER_TURN_5_TILES: @@ -4039,23 +4041,23 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_LARGE: case TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_UP: case TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_DOWN: - _ecx = 200; - _ebp = -160; + vertFactor = 200; + lateralFactor = -160; //6d75F0 break; case TRACK_ELEM_S_BEND_LEFT: case TRACK_ELEM_S_BEND_LEFT_COVERED: - _ebp = (vehicle->track_progress < 48) ? 98 : -98; + lateralFactor = (vehicle->track_progress < 48) ? 98 : -98; //6d75FF break; case TRACK_ELEM_S_BEND_RIGHT: case TRACK_ELEM_S_BEND_RIGHT_COVERED: - _ebp = (vehicle->track_progress < 48) ? -98 : 98; + lateralFactor = (vehicle->track_progress < 48) ? -98 : 98; //6d7608 break; case TRACK_ELEM_LEFT_VERTICAL_LOOP: case TRACK_ELEM_RIGHT_VERTICAL_LOOP: - _ecx = (abs(vehicle->track_progress - 155) / 2) + 28; + vertFactor = (abs(vehicle->track_progress - 155) / 2) + 28; //6d7690 break; case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES: @@ -4063,7 +4065,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN: case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_COVERED: case TRACK_ELEM_LEFT_CURVED_LIFT_HILL: - _ebp = 59; + lateralFactor = 59; //6d7704 break; case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES: @@ -4071,139 +4073,139 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN: case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED: case TRACK_ELEM_RIGHT_CURVED_LIFT_HILL: - _ebp = -59; + lateralFactor = -59; //6d7710 break; case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_BANK: case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_SMALL: case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_SMALL: - _ecx = 100; - _ebp = 100; + vertFactor = 100; + lateralFactor = 100; //6d7782 break; case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_BANK: case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_SMALL: case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_SMALL: - _ecx = 100; - _ebp = -100; + vertFactor = 100; + lateralFactor = -100; //6d778E break; case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE: - _ebp = 45; + lateralFactor = 45; //6d779A break; case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE: - _ebp = -45; + lateralFactor = -45; //6d77A3 break; case TRACK_ELEM_HALF_LOOP_UP: case TRACK_ELEM_FLYER_HALF_LOOP_UP: - _ecx = (-(vehicle->track_progress - 155) / 2) + 28; + vertFactor = (((uint16)(-(vehicle->track_progress - 155))) / 2) + 28; //6d763E break; case TRACK_ELEM_HALF_LOOP_DOWN: case TRACK_ELEM_FLYER_HALF_LOOP_DOWN: - _ecx = (vehicle->track_progress / 2) + 28; + vertFactor = (vehicle->track_progress / 2) + 28; //6d7656 break; case TRACK_ELEM_LEFT_CORKSCREW_UP: case TRACK_ELEM_RIGHT_CORKSCREW_DOWN: case TRACK_ELEM_LEFT_FLYER_CORKSCREW_UP: case TRACK_ELEM_RIGHT_FLYER_CORKSCREW_DOWN: - _ecx = 52; - _ebp = 70; + vertFactor = 52; + lateralFactor = 70; //6d76AA break; case TRACK_ELEM_RIGHT_CORKSCREW_UP: case TRACK_ELEM_LEFT_CORKSCREW_DOWN: case TRACK_ELEM_RIGHT_FLYER_CORKSCREW_UP: case TRACK_ELEM_LEFT_FLYER_CORKSCREW_DOWN: - _ecx = 52; - _ebp = -70; + vertFactor = 52; + lateralFactor = -70; //6d76B9 break; case TRACK_ELEM_FLAT_TO_60_DEG_UP: case TRACK_ELEM_60_DEG_DOWN_TO_FLAT: - _ecx = 56; + vertFactor = 56; //6d747C break; case TRACK_ELEM_60_DEG_UP_TO_FLAT: case TRACK_ELEM_FLAT_TO_60_DEG_DOWN: case TRACK_ELEM_BRAKE_FOR_DROP: - _ecx = -56; + vertFactor = -56; //6d7488 break; case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_UP: case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_DOWN: - _ebp = 88; + lateralFactor = 88; //6d7770 break; case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_UP: case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_DOWN: - _ebp = -88; + lateralFactor = -88; //6d7779 break; case TRACK_ELEM_WATER_SPLASH: - _ecx = -150; + vertFactor = -150; if (vehicle->track_progress < 32) break; - _ecx = 150; + vertFactor = 150; if (vehicle->track_progress < 64) break; - _ecx = 0; + vertFactor = 0; if (vehicle->track_progress < 96) break; - _ecx = 150; + vertFactor = 150; if (vehicle->track_progress < 128) break; - _ecx = -150; + vertFactor = -150; //6d7408 break; case TRACK_ELEM_FLAT_TO_60_DEG_UP_LONG_BASE: case TRACK_ELEM_FLAT_TO_60_DEG_DOWN_LONG_BASE: - _ecx = 160; + vertFactor = 160; //6d74F1 break; case TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE: case TRACK_ELEM_60_DEG_UP_TO_FLAT_LONG_BASE_122: - _ecx = -160; + vertFactor = -160; //6d74FD break; case TRACK_ELEM_REVERSE_WHOA_BELLY_SLOPE: case TRACK_ELEM_AIR_THRUST_VERTICAL_DOWN_TO_LEVEL: - _ecx = 120; + vertFactor = 120; //6d7458 break; case TRACK_ELEM_60_DEG_UP_TO_90_DEG_UP: case TRACK_ELEM_90_DEG_DOWN_TO_60_DEG_DOWN: - _ecx = 110; + vertFactor = 110; //6d7515 break; case TRACK_ELEM_90_DEG_UP_TO_60_DEG_UP: case TRACK_ELEM_60_DEG_DOWN_TO_90_DEG_DOWN: - _ecx = -110; + vertFactor = -110; //6d7521 break; case TRACK_ELEM_LEFT_EIGHTH_TO_DIAG: case TRACK_ELEM_LEFT_EIGHTH_TO_ORTHOGONAL: - _ebp = 137; + lateralFactor = 137; //6d7575 break; case TRACK_ELEM_RIGHT_EIGHTH_TO_DIAG: case TRACK_ELEM_RIGHT_EIGHTH_TO_ORTHOGONAL: - _ebp = -137; + lateralFactor = -137; //6d759C break; case TRACK_ELEM_LEFT_EIGHTH_BANK_TO_DIAG: case TRACK_ELEM_LEFT_EIGHTH_BANK_TO_ORTHOGONAL: - _ecx = 270; - _ebp = 200; + vertFactor = 270; + lateralFactor = 200; //6d75C3 break; case TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_DIAG: case TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_ORTHOGONAL: - _ecx = 270; - _ebp = -200; + vertFactor = 270; + lateralFactor = -200; //6d75D2 break; case TRACK_ELEM_DIAG_FLAT_TO_25_DEG_UP: @@ -4212,7 +4214,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_UP: case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_LEFT_BANK: case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_RIGHT_BANK: - _ecx = 113; + vertFactor = 113; //6d7494 break; case TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT: @@ -4221,169 +4223,170 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_DIAG_25_DEG_UP_TO_RIGHT_BANK: case TRACK_ELEM_DIAG_LEFT_BANK_TO_25_DEG_DOWN: case TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_DOWN: - _ecx = -113; + vertFactor = -113; //6d755D break; case TRACK_ELEM_DIAG_25_DEG_UP_TO_60_DEG_UP: case TRACK_ELEM_DIAG_60_DEG_DOWN_TO_25_DEG_DOWN: - _ecx = 95; + vertFactor = 95; //6D752D break; case TRACK_ELEM_DIAG_60_DEG_UP_TO_25_DEG_UP: case TRACK_ELEM_DIAG_25_DEG_DOWN_TO_60_DEG_DOWN: - _ecx = -95; + vertFactor = -95; //6D7539 break; case TRACK_ELEM_DIAG_FLAT_TO_60_DEG_UP: case TRACK_ELEM_DIAG_60_DEG_DOWN_TO_FLAT: - _ecx = 60; + vertFactor = 60; //6D7464 break; case TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT: case TRACK_ELEM_DIAG_FLAT_TO_60_DEG_DOWN: - _ecx = -60; + vertFactor = -60; //6d7470 break; case TRACK_ELEM_LEFT_BARREL_ROLL_UP_TO_DOWN: case TRACK_ELEM_LEFT_BARREL_ROLL_DOWN_TO_UP: - _ecx = 170; - _ebp = 115; + vertFactor = 170; + lateralFactor = 115; //6d7581 break; case TRACK_ELEM_RIGHT_BARREL_ROLL_UP_TO_DOWN: case TRACK_ELEM_RIGHT_BARREL_ROLL_DOWN_TO_UP: - _ecx = 170; - _ebp = -115; + vertFactor = 170; + lateralFactor = -115; //6d75A8 break; case TRACK_ELEM_LEFT_BANK_TO_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: - _ecx = -(vehicle->track_progress / 2) + 134; - _ebp = 90; + vertFactor = -(vehicle->track_progress / 2) + 134; + lateralFactor = 90; //6d771C break; case TRACK_ELEM_RIGHT_BANK_TO_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: - _ecx = -(vehicle->track_progress / 2) + 134; - _ebp = -90; + vertFactor = -(vehicle->track_progress / 2) + 134; + lateralFactor = -90; //6D7746 break; case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_LEFT_BANK: - _ecx = -(vehicle->track_progress / 2) + 134; - _ebp = 90; + vertFactor = -(vehicle->track_progress / 2) + 134; + lateralFactor = 90; //6D7731 identical to 6d771c break; case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_RIGHT_BANK: - _ecx = -(vehicle->track_progress / 2) + 134; - _ebp = -90; + vertFactor = -(vehicle->track_progress / 2) + 134; + lateralFactor = -90; //6D775B identical to 6d7746 break; case TRACK_ELEM_LEFT_LARGE_HALF_LOOP_UP: case TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_UP: - _ecx = (-(vehicle->track_progress - 311) / 4) + 46; + vertFactor = (((uint16)(-(vehicle->track_progress - 311))) / 4) + 46; //6d7666 break; case TRACK_ELEM_RIGHT_LARGE_HALF_LOOP_DOWN: case TRACK_ELEM_LEFT_LARGE_HALF_LOOP_DOWN: - _ecx = (vehicle->track_progress / 4) + 46; + vertFactor = (vehicle->track_progress / 4) + 46; //6d767F break; case TRACK_ELEM_HEARTLINE_TRANSFER_UP: - _ecx = 103; + vertFactor = 103; if (vehicle->track_progress < 32) break; - _ecx = -103; + vertFactor = -103; if (vehicle->track_progress < 64) break; - _ecx = 0; + vertFactor = 0; if (vehicle->track_progress < 96) break; - _ecx = 103; + vertFactor = 103; if (vehicle->track_progress < 128) break; - _ecx = -103; + vertFactor = -103; //6d74A0 break; case TRACK_ELEM_HEARTLINE_TRANSFER_DOWN: - _ecx = -103; + vertFactor = -103; if (vehicle->track_progress < 32) break; - _ecx = 103; + vertFactor = 103; if (vehicle->track_progress < 64) break; - _ecx = 0; + vertFactor = 0; if (vehicle->track_progress < 96) break; - _ecx = -103; + vertFactor = -103; if (vehicle->track_progress < 128) break; - _ecx = 103; + vertFactor = 103; //6D74CA break; case TRACK_ELEM_MULTIDIM_INVERTED_FLAT_TO_90_DEG_QUARTER_LOOP_DOWN: case TRACK_ELEM_INVERTED_FLAT_TO_90_DEG_QUARTER_LOOP_DOWN: case TRACK_ELEM_MULTIDIM_FLAT_TO_90_DEG_DOWN_QUARTER_LOOP: - _ecx = (vehicle->track_progress / 4) + 55; + vertFactor = (vehicle->track_progress / 4) + 55; //6d762D break; case TRACK_ELEM_90_DEG_TO_INVERTED_FLAT_QUARTER_LOOP_UP: case TRACK_ELEM_MULTIDIM_90_DEG_UP_TO_INVERTED_FLAT_QUARTER_LOOP: case 255: - _ecx = (-(vehicle->track_progress - 137) / 4) + 55; + vertFactor = (((uint16)(-(vehicle->track_progress - 137))) / 4) + 55; //6D7614 break; case TRACK_ELEM_AIR_THRUST_TOP_CAP: - _ecx = -60; + vertFactor = -60; //6D744C break; case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_3_TILE_25_DEG_UP: case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_3_TILE_25_DEG_DOWN: - _ecx = 200; - _ebp = 100; + vertFactor = 200; + lateralFactor = 100; //6d76C8 break; case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_3_TILE_25_DEG_UP: case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_3_TILE_25_DEG_DOWN: - _ecx = 200; - _ebp = -100; + vertFactor = 200; + lateralFactor = -100; //6d76d7 break; case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_5_TILE_25_DEG_UP: case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_5_TILE_25_DEG_DOWN: - _ecx = 200; - _ebp = 160; + vertFactor = 200; + lateralFactor = 160; //6D76E6 break; case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_5_TILE_25_DEG_UP: case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_5_TILE_25_DEG_DOWN: - _ecx = 200; - _ebp = -160; + vertFactor = 200; + lateralFactor = -160; //6d76F5 break; } - if (_ecx != 0) { - _eax += abs(vehicle->velocity) * 98 / _ecx; + int gForceLateral = 0; + + if (vertFactor != 0) { + gForceVert += abs(vehicle->velocity) * 98 / vertFactor; } - if (_ebp != 0) { - _edx += abs(vehicle->velocity) * 98 / _ebp; + if (lateralFactor != 0) { + gForceLateral += abs(vehicle->velocity) * 98 / lateralFactor; } - _eax *= 10; - _edx *= 10; - _eax >>= 16; - _edx >>= 16; + gForceVert *= 10; + gForceLateral *= 10; + gForceVert >>= 16; + gForceLateral >>= 16; int eax, ebx, ecx, edx, esi, edi, ebp; esi = (int)vehicle; RCT2_CALLFUNC_X(0x006D73D0, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - // Note shr causing this to assert on all loops - if (_eax != (sint16)(eax & 0xFFFF)) - assert(_eax == (sint16)(eax & 0xFFFF)); - if (_edx != (sint16)(edx & 0xFFFF)) - assert(_edx == (sint16)(edx & 0xFFFF)); - if (verticalG != NULL) *verticalG = (sint16)(_eax & 0xFFFF); - if (lateralG != NULL) *lateralG = (sint16)(_edx & 0xFFFF); + if (gForceVert != (sint16)(eax & 0xFFFF)) + assert(gForceVert == (sint16)(eax & 0xFFFF)); + if (gForceLateral != (sint16)(edx & 0xFFFF)) + assert(gForceLateral == (sint16)(edx & 0xFFFF)); + if (verticalG != NULL) *verticalG = (sint16)(gForceVert & 0xFFFF); + if (lateralG != NULL) *lateralG = (sint16)(gForceLateral & 0xFFFF); } void vehicle_set_map_toolbar(rct_vehicle *vehicle) From a406a4b344390764182cd14baf7a3262ce99929d Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 15 Dec 2015 18:26:44 +0000 Subject: [PATCH 119/162] Fix merge related bugs --- src/ride/vehicle.c | 97 +++++++++++++++++++++++----------------------- src/ride/vehicle.h | 2 +- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index e4b78bb845..1b23ccf452 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -5545,7 +5545,7 @@ static void sub_6D661F(rct_vehicle *vehicle) vehicle->var_B6 += dword_F64E08 >> spinningInertia; break; case loc_6D66D6: - if (vehicle->var_34 < 48) { + if (vehicle->track_progress < 48) { spinningInertia += 8; vehicle->var_B6 += dword_F64E08 >> spinningInertia; break; @@ -5559,13 +5559,13 @@ static void sub_6D661F(rct_vehicle *vehicle) vehicle->var_B6 += dword_F64E08 >> spinningInertia; break; case loc_6D6708: - if (vehicle->var_34 > 22) { + if (vehicle->track_progress > 22) { spinningInertia += 5; vehicle->var_B6 += dword_F64E08 >> spinningInertia; } break; case loc_6D6711: - if (vehicle->var_34 < 48) { + if (vehicle->track_progress < 48) { spinningInertia += 8; vehicle->var_B6 += dword_F64E08 >> spinningInertia; break; @@ -5775,7 +5775,7 @@ static void vehicle_update_handle_water_splash(rct_vehicle *vehicle) rct_vehicle *nextVehicle = GET_VEHICLE(vehicle->next_vehicle_on_ride); rct_vehicle *nextNextVehicle = GET_VEHICLE(nextVehicle->next_vehicle_on_ride); if (!track_element_is_covered(nextNextVehicle->track_type >> 2)) { - if (vehicle->var_34 == 4) { + if (vehicle->track_progress == 4) { vehicle_update_play_water_splash_sound(); } } @@ -5784,14 +5784,14 @@ static void vehicle_update_handle_water_splash(rct_vehicle *vehicle) } } else { if (trackType == TRACK_ELEM_25_DEG_DOWN_TO_FLAT) { - if (vehicle->var_34 == 12) { + if (vehicle->track_progress == 12) { vehicle_update_play_water_splash_sound(); } } } if (!vehicle->is_child) { if (trackType == TRACK_ELEM_WATER_SPLASH) { - if (vehicle->var_34 == 48) { + if (vehicle->track_progress == 48) { vehicle_update_play_water_splash_sound(); } } @@ -5807,7 +5807,7 @@ static void sub_6DB807(rct_vehicle *vehicle) const rct_vehicle_info *moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, - vehicle->var_34 + vehicle->track_progress ); int x = vehicle->track_x + moveInfo->x; int y = vehicle->track_y + moveInfo->y; @@ -5835,11 +5835,11 @@ static void sub_6DB7D6(rct_vehicle *vehicle) rct_vehicle *previousVehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); rct_vehicle *nextVehicle = GET_VEHICLE(vehicle->next_vehicle_on_ride); - vehicle->var_34 = 168; + vehicle->track_progress = 168; vehicle->vehicle_type ^= 1; - previousVehicle->var_34 = 86; - nextVehicle->var_34 = 158; + previousVehicle->track_progress = 86; + nextVehicle->track_progress = 158; sub_6DB807(nextVehicle); sub_6DB807(previousVehicle); @@ -5879,7 +5879,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) if (trackType == TRACK_ELEM_TOWER_BASE && vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*) ) { - if (vehicle->var_34 > 3 && !(vehicle->update_flags & VEHICLE_UPDATE_FLAG_3)) { + if (vehicle->track_progress > 3 && !(vehicle->update_flags & VEHICLE_UPDATE_FLAG_3)) { rct_xy_element input, output; int outputZ, outputDirection; @@ -5891,8 +5891,8 @@ void sub_6DBF3E(rct_vehicle *vehicle) } } - if (vehicle->var_34 <= 3) { - RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_0; + if (vehicle->track_progress <= 3) { + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION; } } @@ -5902,10 +5902,10 @@ void sub_6DBF3E(rct_vehicle *vehicle) return; } - uint16 ax = vehicle->var_34; + uint16 ax = vehicle->track_progress; if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { if (ax <= 22) { - RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_0; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION; } } else { uint16 cx = 17; @@ -5917,7 +5917,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) } if (ax > cx) { - RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_0; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION; } } } @@ -5993,7 +5993,7 @@ loc_6DAEB9: int trackType = vehicle->track_type >> 2; if (trackType == 197 || trackType == 198) { - if (vehicle->var_34 == 80) { + if (vehicle->track_progress == 80) { vehicle->vehicle_type ^= 1; vehicleEntry = vehicle_get_vehicle_entry(vehicle); } @@ -6028,9 +6028,9 @@ loc_6DAEB9: if (trackType == TRACK_ELEM_BRAKE_FOR_DROP) { if (!vehicle->is_child) { if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_10)) { - if (vehicle->var_34 >= 8) { + if (vehicle->track_progress >= 8) { vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; - if (vehicle->var_34 >= 24) { + if (vehicle->track_progress >= 24) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_10; vehicle->var_D2 = 90; } @@ -6039,17 +6039,17 @@ loc_6DAEB9: } } if (trackType == TRACK_ELEM_LOG_FLUME_REVERSER) { - if (vehicle->var_34 != 16 || vehicle->velocity < 0x40000) { - if (vehicle->var_34 == 32) { + if (vehicle->track_progress != 16 || vehicle->velocity < 0x40000) { + if (vehicle->track_progress == 32) { vehicle->vehicle_type = vehicleEntry->var_58; vehicleEntry = vehicle_get_vehicle_entry(vehicle); } } else { - vehicle->var_34 += 17; + vehicle->track_progress += 17; } } - regs.ax = vehicle->var_34 + 1; + regs.ax = vehicle->track_progress + 1; { const rct_vehicle_info *moveInfo = vehicle_get_move_info( vehicle->var_CD, @@ -6225,14 +6225,14 @@ loc_6DB500: regs.ax = 0; loc_6DB59A: - vehicle->var_34 = regs.ax; + vehicle->track_progress = regs.ax; vehicle_update_handle_water_splash(vehicle); loc_6DB706:; const rct_vehicle_info *moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, - vehicle->var_34 + vehicle->track_progress ); sint16 x = vehicle->track_x + moveInfo->x; sint16 y = vehicle->track_y + moveInfo->y; @@ -6245,8 +6245,8 @@ loc_6DB706:; if (vehicle->var_CD == 15 && vehicle->track_type >= 844 && vehicle->track_type < 852 && - vehicle->var_34 >= 30 && - vehicle->var_34 <= 66 + vehicle->track_progress >= 30 && + vehicle->track_progress <= 66 ) { regs.ebx |= 8; } @@ -6254,14 +6254,14 @@ loc_6DB706:; if (vehicle->var_CD == 16 && vehicle->track_type >= 844 && vehicle->track_type < 852 && - vehicle->var_34 == 96 + vehicle->track_progress == 96 ) { sub_6DB7D6(vehicle); const rct_vehicle_info *moveInfo2 = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, - vehicle->var_34 + vehicle->track_progress ); x = vehicle->x + moveInfo2->x; y = vehicle->y + moveInfo2->y; @@ -6363,7 +6363,7 @@ loc_6DBA33: } } - regs.ax = vehicle->var_34 - 1; + regs.ax = vehicle->track_progress - 1; if (regs.ax != -1) { goto loc_6DBD42; } @@ -6519,7 +6519,7 @@ loc_6DBC3B: regs.ax = unk16; loc_6DBD42: - vehicle->var_34 = regs.ax; + vehicle->track_progress = regs.ax; moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, @@ -6786,8 +6786,8 @@ loc_6DC2FA: loc_6DC316: regs.bx = vehicle->track_type >> 2; if (regs.bx == TRACK_ELEM_WATER_SPLASH) { - if (vehicle->var_34 >= 48 && - vehicle->var_34 <= 128 + if (vehicle->track_progress >= 48 && + vehicle->track_progress <= 128 ) { regs.eax = vehicle->velocity >> 6; regs.ecx -= regs.eax; @@ -6914,7 +6914,7 @@ loc_6DC5B8: // There are two bytes before the move info list { - uint16 unk16_v34 = vehicle->var_34 + 1; + uint16 unk16_v34 = vehicle->track_progress + 1; uint16 unk16 = *((uint16*)((int)moveInfo - 2)); if (unk16_v34 < unk16) { regs.ax = unk16_v34; @@ -6976,7 +6976,7 @@ loc_6DC5B8: regs.ax = 0; loc_6DC743: - vehicle->var_34 = regs.ax; + vehicle->track_progress = regs.ax; if (vehicle->is_child) { vehicle->var_C5++; if (vehicle->var_C5 >= 6) { @@ -6985,7 +6985,7 @@ loc_6DC743: } for (;;) { - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, vehicle->var_34); + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, vehicle->track_progress); if (moveInfo->x != (uint16)0x8000) { break; } @@ -7004,19 +7004,19 @@ loc_6DC743: } vehicle->var_CD = regs.bl; } - vehicle->var_34++; + vehicle->track_progress++; break; case 1: // loc_6DC7ED vehicle->var_D3 = moveInfo->z; - vehicle->var_34++; + vehicle->track_progress++; break; case 2: // loc_6DC800 vehicle->var_D5 |= (1 << 0); - vehicle->var_34++; + vehicle->track_progress++; break; case 3: // loc_6DC810 vehicle->var_D5 |= (1 << 1); - vehicle->var_34++; + vehicle->track_progress++; break; case 4: // loc_6DC820 z = moveInfo->z; @@ -7034,16 +7034,16 @@ loc_6DC743: } vehicle->var_D4 = z; vehicle->var_C5 = 0; - vehicle->var_34++; + vehicle->track_progress++; break; case 5: // loc_6DC87A vehicle->var_D5 |= (1 << 2); - vehicle->var_34++; + vehicle->track_progress++; break; case 6: // loc_6DC88A vehicle->var_D5 &= ~(1 << 4); vehicle->var_D5 |= (1 << 5); - vehicle->var_34++; + vehicle->track_progress++; break; default: log_error("Invalid move info..."); @@ -7131,7 +7131,7 @@ loc_6DCA7A: invalidate_sprite_2((rct_sprite*)vehicle); loc_6DCA9A: - regs.ax = vehicle->var_34 - 1; + regs.ax = vehicle->track_progress - 1; if (regs.ax != (short)0xFFFF) { goto loc_6DCC2C; } @@ -7189,9 +7189,9 @@ loc_6DCA9A: regs.ax = *((uint16*)((int)moveInfo - 2)) - 1; loc_6DCC2C: - vehicle->var_34 = regs.ax; + vehicle->track_progress = regs.ax; - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, vehicle->var_34); + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, vehicle->track_progress); x = vehicle->track_x + moveInfo->x; y = vehicle->track_y + moveInfo->y; z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); @@ -7290,7 +7290,7 @@ loc_6DCE02: if (vehicle != RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { goto loc_6DCEB2; } - regs.ax = vehicle->var_34; + regs.ax = vehicle->track_progress; if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { goto loc_6DCE62; } @@ -7306,7 +7306,7 @@ loc_6DCE62: } loc_6DCE68: - RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_0; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION; regs.al = vehicle->track_x >> 5; regs.ah = vehicle->track_y >> 5; regs.dl = vehicle->track_z >> 3; @@ -7432,6 +7432,7 @@ loc_6DD069: end: // hook_setreturnregisters(®s); + if (outStation != NULL) *outStation = regs.ebx; return regs.eax; } diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index f9bab73f33..dccea8daa5 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -277,7 +277,7 @@ enum { }; enum { - VEHICLE_UPDATE_MOTION_TRACK_FLAG_0 = 1 << 0, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION = 1 << 0, VEHICLE_UPDATE_MOTION_TRACK_FLAG_1 = 1 << 1, VEHICLE_UPDATE_MOTION_TRACK_FLAG_2 = 1 << 2, VEHICLE_UPDATE_MOTION_TRACK_FLAG_3 = 1 << 3, From 37efbfd0a575896557aeba487eea414c1332c732 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 15 Dec 2015 18:56:19 +0000 Subject: [PATCH 120/162] Refactor chunk_1 label functions --- src/ride/ride.c | 4 ++-- src/ride/vehicle.c | 40 +++++++++++++++++++++------------------- src/ride/vehicle.h | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index b0af9f3907..e71844f30f 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -4280,7 +4280,7 @@ void loc_6DDF9C(rct_ride *ride, rct_map_element *mapElement) for (int i = 0; i < ride->num_vehicles; i++) { train = GET_VEHICLE(ride->vehicles[i]); if (i == 0) { - sub_6DAB4C(train, NULL); + vehicle_update_track_motion(train, NULL); vehicle_unset_var_48_b1(train); continue; } @@ -4300,7 +4300,7 @@ void loc_6DDF9C(rct_ride *ride, rct_map_element *mapElement) } car = GET_VEHICLE(spriteIndex); } - } while (sub_6DAB4C(train, NULL) & 0x400); + } while (vehicle_update_track_motion(train, NULL) & 0x400); mapElement->flags |= (1 << 5); car = train; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 1b23ccf452..32a499337c 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1264,7 +1264,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ vehicle->var_2C = 0; } - eax = sub_6DAB4C(vehicle, &ebx); + eax = vehicle_update_track_motion(vehicle, &ebx); if (!(eax&(1 << 5))) break; //Fall through to next case @@ -1308,7 +1308,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ } int station; - eax = sub_6DAB4C(vehicle, &station); + eax = vehicle_update_track_motion(vehicle, &station); if (eax & (1 << 1)){ vehicle->velocity = 0; @@ -2077,7 +2077,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { break; } - uint32 flags = sub_6DAB4C(vehicle, NULL); + uint32 flags = vehicle_update_track_motion(vehicle, NULL); if (flags & (1 << 8)) { if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { @@ -2435,7 +2435,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { return; } - uint32 flags = sub_6DAB4C(vehicle, NULL); + uint32 flags = vehicle_update_track_motion(vehicle, NULL); bool skipCheck = false; if (flags & ((1 << 8) | (1 << 9)) && @@ -2689,7 +2689,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { uint32 flags; loc_6D8E36: - flags = sub_6DAB4C(vehicle, NULL); + flags = vehicle_update_track_motion(vehicle, NULL); if (flags & (1 << 7) && RCT2_GLOBAL(0x00F64E35, uint8) == 0) { vehicle_update_collision_setup(vehicle); @@ -3559,7 +3559,7 @@ static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle) { if (vehicle->velocity <= 439800) { vehicle->var_2C = 4398; } - int flags = sub_6DAB4C(vehicle, NULL); + int flags = vehicle_update_track_motion(vehicle, NULL); if (flags & (1 << 11)) { vehicle->status = VEHICLE_STATUS_TRAVELLING; @@ -5029,21 +5029,17 @@ const sint32 *dword_9A2970 = (sint32*)0x009A2970; /** * - * rct2: 0x006DAB6F + * rct2: 0x006DAB90 */ -static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) +static void vehicle_update_track_motion_up_stop_check(rct_vehicle *vehicle) { rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); int verticalG, lateralG; - RCT2_GLOBAL(0x00F64E2C, uint8) = 0; - RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = vehicle; - RCT2_GLOBAL(0x00F64E18, uint32) = 0; - RCT2_GLOBAL(0x00F64E1C, uint32) = 0xFFFFFFFF; - + // No up stops (coaster types) if (vehicleEntry->var_12 & (1 << 1)) { int trackType = vehicle->track_type >> 2; - if (trackType < 68 || trackType >= 87) { + if (!track_element_is_covered(trackType)) { vehicle_get_g_forces(vehicle, &verticalG, &lateralG); lateralG = abs(lateralG); if (lateralG <= 150) { @@ -5061,8 +5057,9 @@ static void sub_6DAB4C_chunk_1(rct_vehicle *vehicle) } } } else if (vehicleEntry->var_12 & (1 << 2)) { + // No up stops bobsleigh type int trackType = vehicle->track_type >> 2; - if (trackType < 68 || trackType >= 87) { + if (!track_element_is_covered(trackType)) { vehicle_get_g_forces(vehicle, &verticalG, &lateralG); if (dword_9A2970[vehicle->var_1F] < 0) { @@ -5926,7 +5923,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) * * rct2: 0x006DAB4C */ -int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) +int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) { registers regs = { 0 }; @@ -5951,7 +5948,12 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation) goto loc_6DC3A7; } - sub_6DAB4C_chunk_1(vehicle); + RCT2_GLOBAL(0x00F64E2C, uint8) = 0; + RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = vehicle; + RCT2_GLOBAL(0x00F64E18, uint32) = 0; + RCT2_GLOBAL(0x00F64E1C, uint32) = 0xFFFFFFFF; + + vehicle_update_track_motion_up_stop_check(vehicle); sub_6DAB4C_chunk_2(vehicle); sub_6DAB4C_chunk_3(vehicle); @@ -6811,8 +6813,8 @@ loc_6DC316: regs.eax = RCT2_GLOBAL(0x00F64E18, uint32); regs.ebx = RCT2_GLOBAL(0x00F64E1C, uint32); if (ride->lifecycle_flags & RIDE_LIFECYCLE_SIX_FLAGS_DEPRECATED) { - regs.eax &= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED; - regs.eax &= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; + regs.eax &= ~VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED; + regs.eax &= ~VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } goto end; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index dccea8daa5..9fdde1ace0 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -305,7 +305,7 @@ int vehicle_is_used_in_pairs(rct_vehicle *vehicle); rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift); rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head); -int sub_6DAB4C(rct_vehicle *vehicle, int *outStation); +int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation); rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle); int vehicle_get_total_num_peeps(rct_vehicle *vehicle); void vehicle_invalidate_window(rct_vehicle *vehicle); From 94f94d038c1b4e08fbcfaaf4c84b6c6cd6f936ac Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 15 Dec 2015 22:32:11 +0000 Subject: [PATCH 121/162] Refactoring of forward loop and fixing of small bugs --- src/ride/vehicle.c | 430 ++++++++++++++++++++++++--------------------- 1 file changed, 226 insertions(+), 204 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 32a499337c..f142bb5921 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -5088,6 +5088,7 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) rct_ride *ride = GET_RIDE(vehicle->ride); rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + // Is chair lift type if (vehicleEntry->var_14 & (1 << 12)) { sint32 velocity = ride->speed << 16; if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) { @@ -5099,17 +5100,17 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) int trackType = vehicle->track_type >> 2; switch (trackType) { - case 1: - case 216: + case TRACK_ELEM_END_STATION: + case TRACK_ELEM_BLOCK_BRAKES: if (ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT || ride_is_block_sectioned(ride)) { break; } return; - case 9: - case 63: - case 123: - case 147: - case 155: + case TRACK_ELEM_25_DEG_UP_TO_FLAT: + case TRACK_ELEM_60_DEG_UP_TO_FLAT: + case TRACK_ELEM_CABLE_LIFT_HILL: + case TRACK_ELEM_DIAG_25_DEG_UP_TO_FLAT: + case TRACK_ELEM_DIAG_60_DEG_UP_TO_FLAT: if (ride_is_block_sectioned(ride)) { break; } @@ -5124,13 +5125,13 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) vehicle->track_z >> 3, trackType ); - if (trackType == 1) { + if (trackType == TRACK_ELEM_END_STATION) { if (trackElement->flags & (1 << 5)) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_10; } - } else if (trackType == 123 || trackType == 216 || track_element_is_lift_hill(trackElement)) { + } else if (trackType == TRACK_ELEM_CABLE_LIFT_HILL || trackType == TRACK_ELEM_BLOCK_BRAKES || track_element_is_lift_hill(trackElement)) { if (!(trackElement->flags & (1 << 5))) { - if (trackType == 216 && vehicle->velocity >= 0) { + if (trackType == TRACK_ELEM_BLOCK_BRAKES && vehicle->velocity >= 0) { if (vehicle->velocity <= 0x20364) { vehicle->velocity = 0x20364; vehicle->var_2C = 0; @@ -5812,7 +5813,7 @@ static void sub_6DB807(rct_vehicle *vehicle) sprite_move(x, y, z, (rct_sprite*)vehicle); } -/** +/** Collision? * * rct2: 0x006DD078 * @param vehicle (esi) @@ -5900,7 +5901,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) } uint16 ax = vehicle->track_progress; - if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { if (ax <= 22) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_AT_STATION; } @@ -5919,6 +5920,175 @@ void sub_6DBF3E(rct_vehicle *vehicle) } } +/** + * + * rct2: 0x006DB08C + */ +bool vehicle_update_track_motion_forwards_get_new_track(rct_vehicle *vehicle, uint16 trackType, rct_ride* ride, rct_ride_type* rideEntry) { + registers regs = { 0 }; + + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + rct_map_element *mapElement = map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z >> 3, + trackType, + 0 + ); + if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_11; + } + + if (track_element_is_block_start(mapElement)) { + if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { + mapElement->flags |= (1 << 5); + if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { + if (!(rideEntry->vehicles[0].var_14 & (1 << 3))) { + audio_play_sound_at_location(SOUND_49, vehicle->track_x, vehicle->track_y, vehicle->track_z); + } + } + map_invalidate_element(vehicle->track_x, vehicle->track_z, mapElement); + loc_6DB1B0(vehicle, mapElement); + } + } + + // TODO check if getting the vehicle entry again is necessary + rct_ride_type_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + if (vehicleEntry->var_12 & (1 << 8)) { + vehicle_update_scenery_door(vehicle); + } + + switch (vehicle->var_CD) { + default: + goto loc_6DB358; + case 2: + case 3: + vehicle->var_CD = 2; + goto loc_6DB32A; + case 4: + vehicle->var_CD = 1; + goto loc_6DB358; + case 7: + vehicle->var_CD = 6; + goto loc_6DB358; + case 8: + vehicle->var_CD = 5; + goto loc_6DB358; + } + +loc_6DB32A: + { + track_begin_end trackBeginEnd; + if (!track_block_get_previous(vehicle->track_x, vehicle->track_y, mapElement, &trackBeginEnd)) { + return false; + } + regs.eax = trackBeginEnd.begin_x; + regs.ecx = trackBeginEnd.begin_y; + regs.edx = trackBeginEnd.begin_z; + regs.bl = trackBeginEnd.begin_direction; + } + goto loc_6DB41D; + +loc_6DB358: + { + rct_xy_element xyElement; + int z, direction; + xyElement.x = vehicle->track_x; + xyElement.y = vehicle->track_y; + xyElement.element = mapElement; + if (!track_block_get_next(&xyElement, &xyElement, &z, &direction)) { + return false; + } + mapElement = xyElement.element; + regs.eax = xyElement.x; + regs.ecx = xyElement.y; + regs.edx = z; + regs.bl = direction; + } + if (mapElement->properties.track.type == 211 || + mapElement->properties.track.type == 212 + ) { + if (!vehicle->is_child && vehicle->velocity <= 0x30000) { + vehicle->velocity = 0; + } + } + + if (!loc_6DB38B(vehicle, mapElement)) { + return false; + } + + // Update VEHICLE_UPDATE_FLAG_11 flag + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_11; + int rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; + if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_3) { + if (mapElement->properties.track.colour & 4) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_11; + } + } + +loc_6DB41D: + vehicle->track_x = regs.ax; + vehicle->track_y = regs.cx; + vehicle->track_z = regs.dx; + + // TODO check if getting the vehicle entry again is necessary + vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + if ((vehicleEntry->var_14 & (1 << 14)) && vehicle->var_CD < 7) { + trackType = mapElement->properties.track.type; + if (trackType == TRACK_ELEM_FLAT) { + loc_6DB481(vehicle); + } + else if (ride->lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) { + if (track_element_is_station(mapElement)) { + loc_6DB481(vehicle); + } + } + } + + if (vehicle->var_CD != 0 && vehicle->var_CD < 5) { + regs.ax >>= 5; + regs.cx >>= 5; + regs.ah = regs.cl; + regs.dx >>= 3; + if (regs.ax != ride->var_13C || regs.dl != ride->var_13F) { + if (regs.ax == ride->var_13A && regs.dl == ride->var_13E) { + vehicle->var_CD = 4; + } + } + else { + vehicle->var_CD = 3; + } + } + +loc_6DB500: + // Update VEHICLE_UPDATE_FLAG_0 + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; + if (track_element_is_lift_hill(mapElement)) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; + } + + trackType = mapElement->properties.track.type; + if (trackType != TRACK_ELEM_BRAKES) { + vehicle->var_D9 = mapElement->properties.track.colour >> 4; + } + vehicle->track_direction = regs.bl & 3; + vehicle->track_type |= trackType << 2; + vehicle->var_CF = (mapElement->properties.track.sequence >> 3) & 0x1E; + if (trackType == TRACK_ELEM_ON_RIDE_PHOTO) { + vehicle_trigger_on_ride_photo(vehicle, mapElement); + } + if (trackType == TRACK_ELEM_ROTATION_CONTROL_TOGGLE) { + vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_13; + } + if (vehicleEntry->var_12 & (1 << 8)) { + sub_6DEDE8(vehicle); + } + return true; +} + /** * * rct2: 0x006DAB4C @@ -5960,15 +6130,20 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { vehicle = vehicle_get_tail(vehicle); } + // This will be the front vehicle even when traveling + // backwards. RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = vehicle; loc_6DAE27: + // Swinging cars if (vehicleEntry->var_14 & (1 << 1)) { sub_6D6776(vehicle); } + // Spinning cars if (vehicleEntry->var_14 & (1 << 2)) { sub_6D661F(vehicle); } + // Rider sprites?? animation?? if ((vehicleEntry->var_14 & (1 << 7)) || (vehicleEntry->var_14 & (1 << 8))) { sub_6D63D4(vehicle); } @@ -5978,11 +6153,14 @@ loc_6DAE27: regs.eax = RCT2_GLOBAL(0x00F64E0C, sint32) + vehicle->var_24; vehicle->var_24 = regs.eax; if (regs.eax < 0) { + // Backward loop goto loc_6DBA13; } if (regs.eax < 0x368A) { + // Location found goto loc_6DBF3E; } + // Forward loop vehicle->var_B8 &= ~(1 << 1); unk_F64E20->x = vehicle->x; unk_F64E20->y = vehicle->y; @@ -5994,7 +6172,7 @@ loc_6DAEB9: regs.cx = vehicle->track_type >> 2; int trackType = vehicle->track_type >> 2; - if (trackType == 197 || trackType == 198) { + if (trackType == TRACK_ELEM_HEARTLINE_TRANSFER_UP || trackType == TRACK_ELEM_HEARTLINE_TRANSFER_DOWN) { if (vehicle->track_progress == 80) { vehicle->vehicle_type ^= 1; vehicleEntry = vehicle_get_vehicle_entry(vehicle); @@ -6007,7 +6185,7 @@ loc_6DAEB9: } else if (trackType == TRACK_ELEM_BRAKES) { if (!( ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN && - ride->breakdown_reason_pending != BREAKDOWN_BRAKES_FAILURE && + ride->breakdown_reason_pending == BREAKDOWN_BRAKES_FAILURE && ride->mechanic_status == RIDE_MECHANIC_STATUS_4 )) { regs.eax = vehicle->var_CF << 16; @@ -6025,7 +6203,7 @@ loc_6DAEB9: if ((trackType == TRACK_ELEM_FLAT && ride->type == RIDE_TYPE_REVERSE_FREEFALL_COASTER) || (trackType == TRACK_ELEM_POWERED_LIFT) ) { - vehicle->var_2C = RCT2_GLOBAL(0x0097CF40 + (ride->type * 8) + 7, uint8) << 10; + vehicle->var_2C = RCT2_GLOBAL(0x0097CF40 + (ride->type * 8) + 7, uint8) << 16; } if (trackType == TRACK_ELEM_BRAKE_FOR_DROP) { if (!vehicle->is_child) { @@ -6052,186 +6230,27 @@ loc_6DAEB9: } regs.ax = vehicle->track_progress + 1; - { - const rct_vehicle_info *moveInfo = vehicle_get_move_info( - vehicle->var_CD, - vehicle->track_type, - 0 - ); - - // There are two bytes before the move info list - uint16 unk16 = *((uint16*)((int)moveInfo - 2)); - if (regs.ax < unk16) { - goto loc_6DB59A; - } - } - - RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; - RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; - mapElement = map_get_track_element_at_of_type_seq( - vehicle->track_x, - vehicle->track_y, - vehicle->track_z >> 3, - trackType, + + const rct_vehicle_info *moveInfo = vehicle_get_move_info( + vehicle->var_CD, + vehicle->track_type, 0 ); - if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { - RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_11; - } - if (track_element_is_block_start(mapElement)) { - if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { - mapElement->flags |= (1 << 5); - if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { - if (!(rideEntry->vehicles[0].var_14 & (1 << 3))) { - audio_play_sound_at_location(SOUND_49, vehicle->track_x, vehicle->track_y, vehicle->track_z); - } - } - map_invalidate_element(vehicle->track_x, vehicle->track_z, mapElement); - loc_6DB1B0(vehicle, mapElement); - } - } - -loc_6DB2BD: - // TODO check if getting the vehicle entry again is necessary - vehicleEntry = vehicle_get_vehicle_entry(vehicle); - - if (vehicleEntry->var_12 & (1 << 8)) { - vehicle_update_scenery_door(vehicle); - } - - switch (vehicle->var_CD) { - default: - goto loc_6DB358; - case 2: - case 3: - vehicle->var_CD = 2; - goto loc_6DB32A; - case 4: - vehicle->var_CD = 1; - goto loc_6DB358; - case 7: - vehicle->var_CD = 6; - goto loc_6DB358; - case 8: - vehicle->var_CD = 5; - goto loc_6DB358; - } - -loc_6DB32A: - { - track_begin_end trackBeginEnd; - if (!track_block_get_previous(vehicle->track_x, vehicle->track_y, mapElement, &trackBeginEnd)) { + // Track Total Progress is in the two bytes before the move info list + uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); + if (regs.ax >= trackTotalProgress) { + if (!vehicle_update_track_motion_forwards_get_new_track(vehicle, trackType, ride, rideEntry)) { goto loc_6DB94A; } - regs.eax = trackBeginEnd.begin_x; - regs.ecx = trackBeginEnd.begin_y; - regs.edx = trackBeginEnd.begin_z; - regs.bl = trackBeginEnd.begin_direction; - } - goto loc_6DB41D; - -loc_6DB358: - { - rct_xy_element xyElement; - int z, direction; - xyElement.x = vehicle->track_x; - xyElement.y = vehicle->track_y; - xyElement.element = mapElement; - if (!track_block_get_next(&xyElement, &xyElement, &z, &direction)) { - goto loc_6DB94A; - } - mapElement = xyElement.element; - regs.eax = xyElement.x; - regs.ecx = xyElement.y; - regs.edx = z; - regs.bl = direction; - } - if (mapElement->properties.track.type == 211 || - mapElement->properties.track.type == 212 - ) { - if (!vehicle->is_child && vehicle->velocity <= 0x30000) { - vehicle->velocity = 0; - } + regs.ax = 0; } - if (!loc_6DB38B(vehicle, mapElement)) { - goto loc_6DB94A; - } - - // Update VEHICLE_UPDATE_FLAG_11 flag - vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_11; - int rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; - if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_3) { - if (mapElement->properties.track.colour & 4) { - vehicle->update_flags |= VEHICLE_UPDATE_FLAG_11; - } - } - -loc_6DB41D: - vehicle->track_x = regs.ax; - vehicle->track_y = regs.cx; - vehicle->track_z = regs.dx; - - // TODO check if getting the vehicle entry again is necessary - vehicleEntry = vehicle_get_vehicle_entry(vehicle); - - if ((vehicleEntry->var_14 & (1 << 14)) && vehicle->var_CD < 7) { - trackType = mapElement->properties.track.type; - if (trackType == TRACK_ELEM_FLAT) { - loc_6DB481(vehicle); - } else if (ride->lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING) { - if (track_element_is_station(mapElement)) { - loc_6DB481(vehicle); - } - } - } - - if (vehicle->var_CD != 0 && vehicle->var_CD < 5) { - regs.ax >>= 5; - regs.cx >>= 5; - regs.ah = regs.cl; - regs.dx >>= 3; - if (regs.ax != ride->var_13C || regs.dl != ride->var_13F) { - if (regs.ax == ride->var_13A && regs.dl == ride->var_13E) { - vehicle->var_CD = 4; - } - } else { - vehicle->var_CD = 3; - } - } - -loc_6DB500: - // Update VEHICLE_UPDATE_FLAG_0 - vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; - if (track_element_is_lift_hill(mapElement)) { - vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; - } - - trackType = mapElement->properties.track.type; - if (trackType != TRACK_ELEM_BRAKES) { - vehicle->var_D9 = mapElement->properties.track.colour >> 4; - } - vehicle->track_direction = regs.bl & 3; - vehicle->track_type |= trackType << 2; - vehicle->var_CF = (mapElement->properties.track.sequence >> 3) & 0x1E; - if (trackType == TRACK_ELEM_ON_RIDE_PHOTO) { - vehicle_trigger_on_ride_photo(vehicle, mapElement); - } - if (trackType == TRACK_ELEM_ROTATION_CONTROL_TOGGLE) { - vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_13; - } - if (vehicleEntry->var_12 & (1 << 8)) { - sub_6DEDE8(vehicle); - } - regs.ax = 0; - -loc_6DB59A: vehicle->track_progress = regs.ax; vehicle_update_handle_water_splash(vehicle); loc_6DB706:; - const rct_vehicle_info *moveInfo = vehicle_get_move_info( + moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, vehicle->track_progress @@ -6239,14 +6258,15 @@ loc_6DB706:; sint16 x = vehicle->track_x + moveInfo->x; sint16 y = vehicle->track_y + moveInfo->y; sint16 z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); - + + trackType = vehicle->track_type >> 2; regs.ebx = 0; if (x != unk_F64E20->x) { regs.ebx |= 1; } if (y != unk_F64E20->y) { regs.ebx |= 2; } if (z != unk_F64E20->z) { regs.ebx |= 4; } if (vehicle->var_CD == 15 && - vehicle->track_type >= 844 && - vehicle->track_type < 852 && + (trackType >= TRACK_ELEM_LEFT_REVERSER || + trackType == TRACK_ELEM_RIGHT_REVERSER) && vehicle->track_progress >= 30 && vehicle->track_progress <= 66 ) { @@ -6254,8 +6274,8 @@ loc_6DB706:; } if (vehicle->var_CD == 16 && - vehicle->track_type >= 844 && - vehicle->track_type < 852 && + (trackType >= TRACK_ELEM_LEFT_REVERSER || + trackType == TRACK_ELEM_RIGHT_REVERSER) && vehicle->track_progress == 96 ) { sub_6DB7D6(vehicle); @@ -6287,8 +6307,9 @@ loc_6DB8A5: vehicle->var_4E = 0; } + // vehicle == frontVehicle if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { - if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->prev_vehicle_on_ride; if (sub_6DD078(vehicle, vehicle->prev_vehicle_on_ride)) { goto loc_6DB967; @@ -6334,8 +6355,9 @@ loc_6DB967: if (vehicleEntry->var_14 & (1 << 14)) { vehicle->velocity -= vehicle->velocity >> 2; } else { + sint32 newHeadVelocity = vehicle->velocity >> 1; vehicle->velocity = head->velocity >> 1; - head->velocity = vehicle->velocity >> 1; + head->velocity = newHeadVelocity; } RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_1; goto loc_6DBE3F; @@ -6424,7 +6446,7 @@ loc_6DBB7E:; int direction; { track_begin_end trackBeginEnd; - if (track_block_get_previous(x, y, mapElement, &trackBeginEnd)) { + if (!track_block_get_previous(x, y, mapElement, &trackBeginEnd)) { goto loc_6DBE5E; } mapElement = trackBeginEnd.begin_element; @@ -6438,14 +6460,14 @@ loc_6DBB7E:; int bank = gTrackDefinitions[trackType].bank_end; bank = track_get_actual_bank_2(ride->type, regs.al, bank); int vAngle = gTrackDefinitions[trackType].vangle_end; - if (RCT2_GLOBAL(0x00F64E36, uint16) != vAngle || - RCT2_GLOBAL(0x00F64E37, uint16) != bank + if (RCT2_GLOBAL(0x00F64E36, uint8) != vAngle || + RCT2_GLOBAL(0x00F64E37, uint8) != bank ) { goto loc_6DBE5E; } // Update VEHICLE_UPDATE_FLAG_11 - vehicle->update_flags &= VEHICLE_UPDATE_FLAG_11; + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_11; if (RideData4[ride->type].flags & RIDE_TYPE_FLAG4_3) { if (mapElement->properties.track.colour & 4) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_11; @@ -6480,7 +6502,7 @@ loc_6DBC3B: } if (track_element_is_lift_hill(mapElement)) { - if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { trackType = mapElement->properties.track.type; if (RCT2_ADDRESS(0x0099423C, uint16)[trackType] & 0x20) { @@ -6493,7 +6515,7 @@ loc_6DBC3B: if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { - if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_8; } } @@ -6553,7 +6575,7 @@ loc_6DBD42: } if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { - if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->next_vehicle_on_ride; if (sub_6DD078(vehicle, regs.bp)) { goto loc_6DBE7F; @@ -6617,7 +6639,7 @@ loc_6DC0F7: if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } - if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { goto loc_6DC144; } @@ -6951,7 +6973,7 @@ loc_6DC5B8: goto loc_6DC9BC; } - rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; + int rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_11; if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_3) { if (mapElement->properties.track.colour & (1 << 2)) { @@ -7092,7 +7114,7 @@ loc_6DC8A1: } if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { - if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { sub_6DD078(vehicle, vehicle->var_44); } } @@ -7176,7 +7198,7 @@ loc_6DCA9A: if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { - if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_8; } } @@ -7231,7 +7253,7 @@ loc_6DCC2C: } if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { - if (RCT2_GLOBAL(0x00F64E08, uint32) >= 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { if (sub_6DD078(vehicle, vehicle->var_44)) { regs.bp = vehicle->var_44; goto loc_6DCD6B; @@ -7293,7 +7315,7 @@ loc_6DCE02: goto loc_6DCEB2; } regs.ax = vehicle->track_progress; - if (RCT2_GLOBAL(0x00F64E08, uint32) < 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { goto loc_6DCE62; } regs.cx = 8; From 606014dfe6835f57b4ab853dfa546194ac1963a3 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 15 Dec 2015 22:36:07 +0000 Subject: [PATCH 122/162] Fix small bug introduced --- src/ride/vehicle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index f142bb5921..99e02c6cb2 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -6265,7 +6265,7 @@ loc_6DB706:; if (y != unk_F64E20->y) { regs.ebx |= 2; } if (z != unk_F64E20->z) { regs.ebx |= 4; } if (vehicle->var_CD == 15 && - (trackType >= TRACK_ELEM_LEFT_REVERSER || + (trackType == TRACK_ELEM_LEFT_REVERSER || trackType == TRACK_ELEM_RIGHT_REVERSER) && vehicle->track_progress >= 30 && vehicle->track_progress <= 66 @@ -6274,7 +6274,7 @@ loc_6DB706:; } if (vehicle->var_CD == 16 && - (trackType >= TRACK_ELEM_LEFT_REVERSER || + (trackType == TRACK_ELEM_LEFT_REVERSER || trackType == TRACK_ELEM_RIGHT_REVERSER) && vehicle->track_progress == 96 ) { From 53a1d93ec38f6aa4266020b48ef1068319188ed9 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 15 Dec 2015 22:59:15 +0000 Subject: [PATCH 123/162] Fix infinite loop. Backwards still not working --- src/ride/vehicle.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 99e02c6cb2..591e4096b4 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -6538,9 +6538,8 @@ loc_6DBC3B: ); // There are two bytes before the move info list - uint16 unk16 = *((uint16*)((int)moveInfo - 2)); - unk16--; - regs.ax = unk16; + trackTotalProgress = *((uint16*)((int)moveInfo - 2)); + regs.ax = trackTotalProgress - 1; loc_6DBD42: vehicle->track_progress = regs.ax; @@ -6649,9 +6648,12 @@ loc_6DC0F7: if (vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { goto loc_6DC144; } + if (vehicle->prev_vehicle_on_ride == SPRITE_INDEX_NULL) { + goto loc_6DC144; + } + vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); } goto loc_6DAE27; - loc_6DC144: vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); regs.eax = 0; From 462d13fed2f5fe604334810742b500b3893fac9a Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 16 Dec 2015 18:37:45 +0000 Subject: [PATCH 124/162] move cable lift code into separate source file --- projects/openrct2.vcxproj | 4 +- projects/openrct2.vcxproj.filters | 9 +- src/ride/cable_lift.c | 312 ++++++++++++++ src/ride/cable_lift.h | 11 + src/ride/ride.c | 3 +- src/ride/vehicle.c | 694 +++++++++++------------------- src/ride/vehicle.h | 9 +- 7 files changed, 590 insertions(+), 452 deletions(-) create mode 100644 src/ride/cable_lift.c create mode 100644 src/ride/cable_lift.h diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 13d1c0ff54..1dd11edc21 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -91,6 +91,7 @@ + @@ -250,6 +251,7 @@ + @@ -509,4 +511,4 @@ xcopy /YS "$(SolutionDir)..\Data" "$(TargetDir)Data" - + \ No newline at end of file diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index d32f0f5439..4f09fbfd79 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -552,6 +552,10 @@ Source\Interface + + + Source\Ride + @@ -824,5 +828,8 @@ Source\Interface + + Source\Ride + - + \ No newline at end of file diff --git a/src/ride/cable_lift.c b/src/ride/cable_lift.c new file mode 100644 index 0000000000..679259b16b --- /dev/null +++ b/src/ride/cable_lift.c @@ -0,0 +1,312 @@ +#include "../world/sprite.h" +#include "cable_lift.h" +#include "ride.h" +#include "track.h" + +static void cable_lift_update_moving_to_end_of_station(rct_vehicle *vehicle); +static void cable_lift_update_waiting_to_depart(rct_vehicle *vehicle); +static void cable_lift_update_departing(rct_vehicle *vehicle); +static void cable_lift_update_travelling(rct_vehicle *vehicle); +static void cable_lift_update_arriving(rct_vehicle *vehicle); + +rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head) +{ + rct_ride *ride = GET_RIDE(rideIndex); + rct_vehicle *current = &(create_sprite(1)->vehicle); + current->sprite_identifier = SPRITE_IDENTIFIER_VEHICLE; + current->ride = rideIndex; + current->ride_subtype = 0xFF; + if (head) { + move_sprite_to_list((rct_sprite*)current, SPRITE_LINKEDLIST_OFFSET_VEHICLE); + ride->cable_lift = current->sprite_index; + } + current->is_child = head ? 0 : 1; + current->var_44 = var_44; + current->var_24 = var_24; + current->sprite_width = 10; + current->sprite_height_negative = 10; + current->sprite_height_positive = 10; + current->friction = 100; + current->num_seats = 0; + current->speed = 20; + current->acceleration = 80; + current->velocity = 0; + current->var_2C = 0; + current->var_4A = 0; + current->var_4C = 0; + current->var_4E = 0; + current->restraints_position = 0; + current->var_BA = 0; + current->var_B6 = 0; + current->var_B8 = 0; + current->sound1_id = 0xFF; + current->sound2_id = 0xFF; + current->var_C4 = 0; + current->var_C5 = 0; + current->var_C8 = 0; + current->var_CA = 0; + current->scream_sound_id = 0xFF; + current->var_1F = 0; + current->var_20 = 0; + for (int j = 0; j < 32; j++) { + current->peep[j] = SPRITE_INDEX_NULL; + } + current->var_CD = 0; + current->sprite_direction = direction << 3; + current->track_x = x; + current->track_y = y; + + z = z * 8; + current->track_z = z; + z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + + sprite_move(16, 16, z, (rct_sprite*)current); + current->track_type = (TRACK_ELEM_CABLE_LIFT_HILL << 2) | (current->sprite_direction >> 3); + current->track_progress = 164; + current->update_flags = VEHICLE_UPDATE_FLAG_1; + current->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; + current->sub_state = 0; + current->num_peeps = 0; + current->next_free_seat = 0; + return current; +} + +void cable_lift_update(rct_vehicle *vehicle) +{ + switch (vehicle->status) { + case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: + cable_lift_update_moving_to_end_of_station(vehicle); + break; + case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: + // Stays in this state until a train puts it into next state + break; + case VEHICLE_STATUS_WAITING_TO_DEPART: + cable_lift_update_waiting_to_depart(vehicle); + break; + case VEHICLE_STATUS_DEPARTING: + cable_lift_update_departing(vehicle); + break; + case VEHICLE_STATUS_TRAVELLING: + cable_lift_update_travelling(vehicle); + break; + case VEHICLE_STATUS_ARRIVING: + cable_lift_update_arriving(vehicle); + break; + } +} + +/** + * + * rct2: 0x006DF8A4 + */ +static void cable_lift_update_moving_to_end_of_station(rct_vehicle *vehicle) +{ + if (vehicle->velocity >= -439800) + vehicle->var_2C = -2932; + + if (vehicle->velocity < -439800) { + vehicle->velocity -= vehicle->velocity / 16; + vehicle->var_2C = 0; + } + + if (!(cable_lift_update_track_motion(vehicle) & (1 << 0))) + return; + + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; +} + +/** + * + * rct2: 0x006DF8F1 + */ +static void cable_lift_update_waiting_to_depart(rct_vehicle *vehicle) +{ + if (vehicle->velocity >= -58640) + vehicle->var_2C = -14660; + + if (vehicle->velocity < -58640) { + vehicle->velocity -= vehicle->velocity / 16; + vehicle->var_2C = 0; + } + + cable_lift_update_track_motion(vehicle); + + // Next check to see if the second part of the cable lift + // is at the front of the passenger vehicle to simulate the + // cable being attached underneath the train. + rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); + rct_vehicle* cableLiftSecondPart = GET_VEHICLE(vehicle->prev_vehicle_on_ride); + + sint16 dist_x = abs(passengerVehicle->x - cableLiftSecondPart->x); + sint16 dist_y = abs(passengerVehicle->y - cableLiftSecondPart->y); + + if (dist_x + dist_y > 2) + return; + + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_DEPARTING; + vehicle->sub_state = 0; +} + +/** + * + * rct2: 0x006DF97A + */ +static void cable_lift_update_departing(rct_vehicle *vehicle) +{ + vehicle->sub_state++; + if (vehicle->sub_state < 16) + return; + + rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); + vehicle->status = VEHICLE_STATUS_TRAVELLING; + passengerVehicle->status = VEHICLE_STATUS_TRAVELLING_CABLE_LIFT; +} + +/** + * + * rct2: 0x006DF99C + */ +static void cable_lift_update_travelling(rct_vehicle *vehicle) +{ + rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); + + vehicle->velocity = min(passengerVehicle->velocity, 439800); + vehicle->var_2C = 0; + if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) + return; + + if (!(cable_lift_update_track_motion(vehicle) & (1 << 1))) + return; + + vehicle->velocity = 0; + vehicle->var_2C = 0; + vehicle->status = VEHICLE_STATUS_ARRIVING; + vehicle->sub_state = 0; +} + +/** + * + * rct2: 0x006DF9F0 + */ +static void cable_lift_update_arriving(rct_vehicle *vehicle) +{ + vehicle->sub_state++; + if (vehicle->sub_state >= 64) + vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; +} + +/** + * + * rct2: 0x006DEF56 + */ +int cable_lift_update_track_motion(rct_vehicle *cableLift) +{ + rct_ride_type* rideEntry = GET_RIDE_ENTRY(cableLift->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[cableLift->vehicle_type]; + rct_ride* ride = GET_RIDE(cableLift->ride); + + RCT2_GLOBAL(0x00F64E2C, uint8) = 0; + RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = cableLift; + RCT2_GLOBAL(0x00F64E18, uint32) = 0; + RCT2_GLOBAL(0x00F64E1C, uint32) = (uint32)-1; + + cableLift->velocity += cableLift->var_2C; + RCT2_GLOBAL(0x00F64E08, sint32) = cableLift->velocity; + RCT2_GLOBAL(0x00F64E0C, sint32) = (cableLift->velocity / 1024) * 42; + + rct_vehicle* frontVehicle = cableLift; + if (cableLift->velocity < 0) { + frontVehicle = vehicle_get_tail(cableLift); + } + + RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = frontVehicle; + + for (rct_vehicle* vehicle = frontVehicle;;) { + vehicle->var_2C = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32) = 1; + vehicle->var_24 += RCT2_GLOBAL(0x00F64E0C, sint32); + + if (vehicle->var_24 < 0 || vehicle->var_24 >= 13962) { + rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; + invalidate_sprite_2((rct_sprite*)vehicle); + + while (true) { + if (vehicle->var_24 < 0) { + if (sub_6DF21B_loop(vehicle) == true) { + break; + } + else { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 - 13962; + vehicle->var_24 = 13962; + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + continue; + } + } + else { + if (sub_6DF01A_loop(vehicle) == true) { + break; + } + else { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); + RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 + 1; + vehicle->var_24 = -1; + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32)++; + } + } + } + sprite_move( + unk_F64E20->x, + unk_F64E20->y, + unk_F64E20->z, + (rct_sprite*)vehicle); + + invalidate_sprite_2((rct_sprite*)vehicle); + } + vehicle->var_2C /= RCT2_GLOBAL(0x00F64E10, uint32); + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { + if (vehicle->next_vehicle_on_train == 0xFFFF) + break; + vehicle = GET_VEHICLE(vehicle->next_vehicle_on_train); + } + else { + if (vehicle == cableLift) + break; + vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); + } + } + + uint32 vehicleCount = 0; + uint16 frictionTotal = 0; + sint32 var2CTotal = 0; + + for (uint16 spriteId = cableLift->sprite_index; spriteId != 0xFFFF;) { + rct_vehicle* vehicle = GET_VEHICLE(spriteId); + vehicleCount++; + frictionTotal += vehicle->friction; + var2CTotal += vehicle->var_2C; + spriteId = vehicle->next_vehicle_on_train; + } + + sint32 ecx = (var2CTotal / vehicleCount) >> 9; + ecx -= cableLift->velocity >> 12; + + sint32 edx = cableLift->velocity >> 8; + edx *= edx; + if (cableLift->velocity < 0) + edx = -edx; + edx >>= 4; + ecx -= edx / frictionTotal; + + cableLift->var_2C = ecx; + return RCT2_GLOBAL(0x00F64E18, uint32); +} diff --git a/src/ride/cable_lift.h b/src/ride/cable_lift.h new file mode 100644 index 0000000000..5da0d87b9b --- /dev/null +++ b/src/ride/cable_lift.h @@ -0,0 +1,11 @@ +#ifndef _CABLE_LIFT_H_ +#define _CABLE_LIFT_H_ + +#include "../common.h" +#include "vehicle.h" + +rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head); +void cable_lift_update(rct_vehicle *vehicle); +int cable_lift_update_track_motion(rct_vehicle *cableLift); + +#endif \ No newline at end of file diff --git a/src/ride/ride.c b/src/ride/ride.c index e71844f30f..d81ee14f9c 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -45,6 +45,7 @@ #include "../world/map.h" #include "../world/map_animation.h" #include "../world/sprite.h" +#include "cable_lift.h" #include "ride.h" #include "ride_data.h" #include "track.h" @@ -4499,7 +4500,7 @@ bool ride_create_cable_lift(int rideIndex, bool isApplying) tail->next_vehicle_on_ride = head->sprite_index; ride->lifecycle_flags |= RIDE_LIFECYCLE_CABLE_LIFT; - vehicle_update_track_motion_cable_lift(head); + cable_lift_update_track_motion(head); return true; } diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 591e4096b4..b4e3655035 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -30,6 +30,7 @@ #include "../world/map_animation.h" #include "../world/sprite.h" #include "../world/scenery.h" +#include "cable_lift.h" #include "track.h" #include "ride.h" #include "ride_data.h" @@ -39,12 +40,6 @@ static void vehicle_update(rct_vehicle *vehicle); -static void vehicle_update_cable_lift_moving_to_end_of_station(rct_vehicle *vehicle); -static void vehicle_update_cable_lift_waiting_to_depart(rct_vehicle *vehicle); -static void vehicle_update_cable_lift_departing(rct_vehicle *vehicle); -static void vehicle_update_cable_lift_travelling(rct_vehicle *vehicle); -static void vehicle_update_cable_lift_arriving(rct_vehicle *vehicle); - static void vehicle_update_showing_film(rct_vehicle *vehicle); static void vehicle_update_doing_circus_show(rct_vehicle *vehicle); static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle); @@ -62,12 +57,12 @@ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle); static void vehicle_update_swinging(rct_vehicle* vehicle); static void vehicle_update_simulator_operating(rct_vehicle* vehicle); static void vehicle_update_top_spin_operating(rct_vehicle* vehicle); -static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); -static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle); static void vehicle_update_travelling_boat(rct_vehicle* vehicle); static void vehicle_update_arriving(rct_vehicle* vehicle); static void vehicle_update_unloading_passengers(rct_vehicle* vehicle); +static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); +static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle); static void vehicle_update_crash_setup(rct_vehicle* vehicle); static void vehicle_update_collision_setup(rct_vehicle* vehicle); static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle); @@ -117,9 +112,9 @@ const uint8 DoorCloseSoundIds[] = { }; /** -* -* rct2: 0x006BB9FF -*/ + * + * rct2: 0x006BB9FF + */ void vehicle_update_sound_params(rct_vehicle* vehicle) { if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) && (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TRACK_DESIGNER) || RCT2_GLOBAL(0x0141F570, uint8) == 6)) { @@ -214,9 +209,9 @@ void vehicle_update_sound_params(rct_vehicle* vehicle) } /** -* -* rct2: 0x006BC2F3 -*/ + * + * rct2: 0x006BC2F3 + */ int sub_6BC2F3(rct_vehicle* vehicle) { int result = 0; @@ -242,9 +237,9 @@ int sub_6BC2F3(rct_vehicle* vehicle) } /** -* -* rct2: 0x006BBC6B -*/ + * + * rct2: 0x006BBC6B + */ void vehicle_sounds_update() { if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1 && !gGameSoundsOff && gConfigSound.sound && !gOpenRCT2Headless) { @@ -532,8 +527,10 @@ void vehicle_update_all() } } -/* rct2: 0x006D6956 - * returns 0 when all closed +/** + * + * rct2: 0x006D6956 + * @returns 0 when all closed */ static int vehicle_close_restraints(rct_vehicle* vehicle){ rct_ride* ride = GET_RIDE(vehicle->ride); @@ -582,8 +579,10 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ return ebp; } -/* rct2: 0x006D6A2C - * returns 0 when all open +/** + * + * rct2: 0x006D6A2C + * @returns 0 when all open */ static int vehicle_open_restraints(rct_vehicle* vehicle){ int ebp = 0; @@ -681,7 +680,10 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ return ebp; } -/* rct2: 0x006D6D1F */ +/** + * + * rct2: 0x006D6D1F + */ static void vehicle_update_measurements(rct_vehicle *vehicle) { rct_ride *ride; @@ -1036,26 +1038,7 @@ static void vehicle_update(rct_vehicle *vehicle) // The cable lift uses the ride type of NULL if (vehicle->ride_subtype == RIDE_TYPE_NULL) { - switch (vehicle->status) { - case VEHICLE_STATUS_MOVING_TO_END_OF_STATION: - vehicle_update_cable_lift_moving_to_end_of_station(vehicle); - break; - case VEHICLE_STATUS_WAITING_FOR_PASSENGERS: - // Stays in this state until a train puts it into next state - break; - case VEHICLE_STATUS_WAITING_TO_DEPART: - vehicle_update_cable_lift_waiting_to_depart(vehicle); - break; - case VEHICLE_STATUS_DEPARTING: - vehicle_update_cable_lift_departing(vehicle); - break; - case VEHICLE_STATUS_TRAVELLING: - vehicle_update_cable_lift_travelling(vehicle); - break; - case VEHICLE_STATUS_ARRIVING: - vehicle_update_cable_lift_arriving(vehicle); - break; - } + cable_lift_update(vehicle); return; } @@ -1154,99 +1137,12 @@ static void vehicle_update(rct_vehicle *vehicle) vehicle_update_sound(vehicle); } -/* rct2: 0x006DF8A4 */ -static void vehicle_update_cable_lift_moving_to_end_of_station(rct_vehicle *vehicle) -{ - if (vehicle->velocity >= -439800) - vehicle->var_2C = -2932; - if (vehicle->velocity < -439800) { - vehicle->velocity -= vehicle->velocity / 16; - vehicle->var_2C = 0; - } - - if (!(vehicle_update_track_motion_cable_lift(vehicle) & (1 << 0))) - return; - - vehicle->velocity = 0; - vehicle->var_2C = 0; - vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; -} - -/* rct2: 0x006DF8F1 */ -static void vehicle_update_cable_lift_waiting_to_depart(rct_vehicle *vehicle) -{ - if (vehicle->velocity >= -58640) - vehicle->var_2C = -14660; - - if (vehicle->velocity < -58640) { - vehicle->velocity -= vehicle->velocity / 16; - vehicle->var_2C = 0; - } - - vehicle_update_track_motion_cable_lift(vehicle); - - // Next check to see if the second part of the cable lift - // is at the front of the passenger vehicle to simulate the - // cable being attached underneath the train. - rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); - rct_vehicle* cableLiftSecondPart = GET_VEHICLE(vehicle->prev_vehicle_on_ride); - - sint16 dist_x = abs(passengerVehicle->x - cableLiftSecondPart->x); - sint16 dist_y = abs(passengerVehicle->y - cableLiftSecondPart->y); - - if (dist_x + dist_y > 2) - return; - - vehicle->velocity = 0; - vehicle->var_2C = 0; - vehicle->status = VEHICLE_STATUS_DEPARTING; - vehicle->sub_state = 0; -} - -/* rct2: 0x006DF97A */ -static void vehicle_update_cable_lift_departing(rct_vehicle *vehicle) -{ - vehicle->sub_state++; - if (vehicle->sub_state < 16) - return; - - rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); - vehicle->status = VEHICLE_STATUS_TRAVELLING; - passengerVehicle->status = VEHICLE_STATUS_TRAVELLING_CABLE_LIFT; -} - -/* rct2: 0x006DF99C */ -static void vehicle_update_cable_lift_travelling(rct_vehicle *vehicle) -{ - rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); - - vehicle->velocity = min(passengerVehicle->velocity, 439800); - vehicle->var_2C = 0; - if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) - return; - - if (!(vehicle_update_track_motion_cable_lift(vehicle) & (1 << 1))) - return; - - vehicle->velocity = 0; - vehicle->var_2C = 0; - vehicle->status = VEHICLE_STATUS_ARRIVING; - vehicle->sub_state = 0; -} - -/* rct2: 0x006DF9F0 */ -static void vehicle_update_cable_lift_arriving(rct_vehicle *vehicle) -{ - vehicle->sub_state++; - if (vehicle->sub_state >= 64) - vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; -} /** -* -* rct2: 0x006D7BCC -*/ + * + * rct2: 0x006D7BCC + */ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ rct_ride* ride = GET_RIDE(vehicle->ride); int eax, ebx; @@ -1343,7 +1239,10 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ } } -/* 0x006D7FB4 */ +/** + * + * rct2: 0x006D7FB4 + */ static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train, uint8 num_used_seats){ if (num_peeps_on_train != num_used_seats) @@ -1395,7 +1294,10 @@ static void train_ready_to_depart(rct_vehicle* vehicle, uint8 num_peeps_on_train vehicle_invalidate_window(vehicle); } -/* 0x006D7DA1 */ +/** + * + * rct2: 0x006D7DA1 + */ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle->velocity = 0; @@ -1573,7 +1475,10 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle_invalidate_window(vehicle); } -/* rct2: 0x006D91BF */ +/** + * + * rct2: 0x006D91BF + */ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); @@ -1603,7 +1508,10 @@ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); } -/* rct2: 0x006D808BE */ +/** + * + * rct2: 0x006D808BE + */ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); bool shouldBreak = false; @@ -1822,8 +1730,11 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { } } -/* rct2: 0x006D9EB0 */ -static void vehicle_peep_easteregg_here_we_are(rct_vehicle* vehicle) { +/** + * + * rct2: 0x006D9EB0 + */ +void vehicle_peep_easteregg_here_we_are(rct_vehicle* vehicle) { uint16 spriteId = vehicle->sprite_index; do { vehicle = GET_VEHICLE(spriteId); @@ -1836,10 +1747,11 @@ static void vehicle_peep_easteregg_here_we_are(rct_vehicle* vehicle) { } while ((spriteId = vehicle->next_vehicle_on_train) != 0xFFFF); } -/* rct2: 0x006D7338 +/** * Performed when vehicle has completed a full circuit + * rct2: 0x006D7338 */ -static void vehicle_update_test_finish(rct_vehicle* vehicle) { +void vehicle_update_test_finish(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); ride->lifecycle_flags &= ~RIDE_LIFECYCLE_TEST_IN_PROGRESS; vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_TESTING; @@ -1869,10 +1781,11 @@ static void vehicle_update_test_finish(rct_vehicle* vehicle) { window_invalidate_by_number(WC_RIDE, vehicle->ride); } -/* rct2: 0x006D6BE7 +/** * + * rct2: 0x006D6BE7 */ -static void vehicle_test_reset(rct_vehicle* vehicle) { +void vehicle_test_reset(rct_vehicle* vehicle) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_TESTING; rct_ride* ride = GET_RIDE(vehicle->ride); @@ -1937,7 +1850,10 @@ static bool vehicle_next_tower_element_is_top(rct_vehicle* vehicle) { return true; } -/* rct2: 0x006D986C */ +/** + * + * rct2: 0x006D986C + */ static void vehicle_update_travelling_boat_hire_setup(rct_vehicle* vehicle) { vehicle->var_34 = vehicle->sprite_direction; vehicle->track_x = vehicle->x & 0xFFE0; @@ -1958,7 +1874,10 @@ static void vehicle_update_travelling_boat_hire_setup(rct_vehicle* vehicle) { vehicle_update_travelling_boat(vehicle); } -/* rct2: 0x006D982F */ +/** + * + * rct2: 0x006D982F + */ static void vehicle_update_departing_boat_hire(rct_vehicle* vehicle) { vehicle->lost_time_out = 0; rct_ride* ride = GET_RIDE(vehicle->ride); @@ -1970,7 +1889,10 @@ static void vehicle_update_departing_boat_hire(rct_vehicle* vehicle) { vehicle_update_travelling_boat_hire_setup(vehicle); } -/* rct2: 0x006D845B */ +/** + * + * rct2: 0x006D845B + */ static void vehicle_update_departing(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); @@ -2174,13 +2096,14 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { vehicle_finish_departing(vehicle); } -/* rct2: 0x006D8858 +/** * Part of vehicle_update_departing * Called after finishing departing sequence to enter * traveling state. * Vertical rides class the lift to the top of the tower * as the departing sequence. After this point station * boosters do not affect the ride. + * rct2: 0x006D8858 */ static void vehicle_finish_departing(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); @@ -2230,7 +2153,10 @@ static void vehicle_finish_departing(rct_vehicle* vehicle) { vehicle->sub_state = 0; } -/* rct2: 0x006DE5CB */ +/** + * + * rct2: 0x006DE5CB + */ static void vehicle_check_if_missing(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); @@ -2352,7 +2278,10 @@ static void vehicle_update_collision_setup(rct_vehicle* vehicle) { vehicle->velocity = 0; } -/* rct2: 0x006D9EFE */ +/** + * + * rct2: 0x006D9EFE + */ static void vehicle_update_crash_setup(rct_vehicle* vehicle) { vehicle->status = VEHICLE_STATUS_CRASHING; vehicle_invalidate_window(vehicle); @@ -2409,7 +2338,10 @@ static void vehicle_update_crash_setup(rct_vehicle* vehicle) { vehicle->velocity = 0; } -/* rct2: 0x006D8937 */ +/** + * + * rct2: 0x006D8937 + */ static void vehicle_update_travelling(rct_vehicle* vehicle) { vehicle_check_if_missing(vehicle); @@ -2577,7 +2509,10 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { vehicle->sub_state = 1; } -/* rct2: 0x006D8C36 */ +/** + * + * rct2: 0x006D8C36 + */ static void vehicle_update_arriving(rct_vehicle* vehicle) { RCT2_GLOBAL(0x00F64E35, uint8) = 1; rct_ride* ride = GET_RIDE(vehicle->ride); @@ -2783,7 +2718,10 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); } -/* rct2: 0x006D9002 */ +/** + * + * rct2: 0x006D9002 + */ static void vehicle_update_unloading_passengers(rct_vehicle* vehicle) { if (vehicle->sub_state == 0) { if (!vehicle_open_restraints(vehicle)) { @@ -2872,13 +2810,122 @@ static void vehicle_update_unloading_passengers(rct_vehicle* vehicle) { vehicle_invalidate_window(vehicle); } -/* rct2: 0x006D9820 */ +/** + * + * rct2: 0x006D9CE9 + */ +static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle) +{ + rct_ride* ride = GET_RIDE(vehicle->ride); + + rct_vehicle* cableLift = GET_VEHICLE(ride->cable_lift); + + if (cableLift->status != VEHICLE_STATUS_WAITING_FOR_PASSENGERS) + return; + + cableLift->status = VEHICLE_STATUS_WAITING_TO_DEPART; + cableLift->var_C0 = vehicle->sprite_index; +} + +/** + * + * rct2: 0x006D9D21 + */ +static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + + if (vehicle->sub_state == 0) { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) { + if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) + return; + + ride->lifecycle_flags |= RIDE_LIFECYCLE_BROKEN_DOWN; + ride_breakdown_add_news_item(vehicle->ride); + ride->window_invalidate_flags |= + RIDE_INVALIDATE_RIDE_MAIN | + RIDE_INVALIDATE_RIDE_LIST | + RIDE_INVALIDATE_RIDE_MAINTENANCE; + + ride->mechanic_status = RIDE_MECHANIC_STATUS_CALLING; + ride->inspection_station = vehicle->current_station; + ride->breakdown_reason = ride->breakdown_reason_pending; + vehicle->velocity = 0; + return; + } + + vehicle->sub_state = 1; + vehicle_peep_easteregg_here_we_are(vehicle); + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TESTED)) { + if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_TESTING)) { + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TEST_IN_PROGRESS)) { + vehicle_test_reset(vehicle); + } + else { + uint8 currentSegment = ride->current_test_segment + 1; + if (currentSegment >= ride->num_stations) { + vehicle_update_test_finish(vehicle); + } + else { + ride->current_test_segment = currentSegment; + ride->var_1F6 = vehicle->current_station; + } + } + } + } + } + + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; + + if (vehicle->velocity <= 439800) { + vehicle->var_2C = 4398; + } + int flags = vehicle_update_track_motion(vehicle, NULL); + + if (flags & (1 << 11)) { + vehicle->status = VEHICLE_STATUS_TRAVELLING; + vehicle_invalidate_window(vehicle); + vehicle->sub_state = 1; + vehicle->lost_time_out = 0; + return; + } + + if (vehicle->sub_state == 2) + return; + + if (flags & (1 << 3) && vehicle->current_station == RCT2_GLOBAL(0x00F64E1C, uint8)) + return; + + vehicle->sub_state = 2; + + if (ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED || + ride->mode == RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED) + return; + + // This is slightly different to the vanilla function + ride->station_depart[vehicle->current_station] &= STATION_DEPART_FLAG; + uint8 waitingTime = 3; + if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH) { + waitingTime = max(ride->min_waiting_time, 3); + waitingTime = min(waitingTime, 127); + } + + ride->station_depart[vehicle->current_station] |= waitingTime; +} + +/** + * + * rct2: 0x006D9820 + */ static void vehicle_update_travelling_boat(rct_vehicle* vehicle) { vehicle_check_if_missing(vehicle); RCT2_CALLPROC_X(0x006DA717, 0, 0, 0, 0, (int)vehicle, 0, 0); } -/* rct2: 0x006D9249 */ + /** + * + * rct2: 0x006D9249 + */ static void vehicle_update_swinging(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); @@ -2937,7 +2984,10 @@ static void vehicle_update_swinging(rct_vehicle* vehicle) { vehicle_update_swinging(vehicle); } -/* rct2: 0x006D9413 */ +/** + * + * rct2: 0x006D9413 + */ static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; @@ -3015,7 +3065,10 @@ static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle) { vehicle->var_C0 = 0; } -/* rct2: 0x006D94F2 */ +/** + * + * rct2: 0x006D94F2 + */ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; @@ -3038,7 +3091,10 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { vehicle->var_C0 = 0; } -/* rct2: 0x006D92FF */ +/** + * + * rct2: 0x006D92FF + */ static void vehicle_update_rotating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; @@ -3113,7 +3169,10 @@ static void vehicle_update_rotating(rct_vehicle* vehicle) { vehicle_update_rotating(vehicle); } -/* rct2: 0x006D97CB */ +/** + * + * rct2: 0x006D97CB + */ static void vehicle_update_space_rings_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; @@ -3136,7 +3195,10 @@ static void vehicle_update_space_rings_operating(rct_vehicle* vehicle) { vehicle->var_C0 = 0; } -/* rct2: 0x006D9641*/ +/** + * + * rct2: 0x006D9641 + */ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; @@ -3203,7 +3265,10 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { } } -/* rct2: 0x006d9781 */ +/** + * + * rct2: 0x006d9781 + */ static void vehicle_update_crooked_house_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; @@ -3219,7 +3284,10 @@ static void vehicle_update_crooked_house_operating(rct_vehicle* vehicle) { vehicle->var_4C++; } -/* rct2: 0x006D9547 */ +/** + * + * rct2: 0x006D9547 + */ static void vehicle_update_top_spin_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; @@ -3248,26 +3316,9 @@ static void vehicle_update_top_spin_operating(rct_vehicle* vehicle) { } /** -* -* rct2: 0x006D9CE9 -*/ -static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle) -{ - rct_ride* ride = GET_RIDE(vehicle->ride); - - rct_vehicle* cableLift = GET_VEHICLE(ride->cable_lift); - - if (cableLift->status != VEHICLE_STATUS_WAITING_FOR_PASSENGERS) - return; - - cableLift->status = VEHICLE_STATUS_WAITING_TO_DEPART; - cableLift->var_C0 = vehicle->sprite_index; -} - -/** -* -* rct2: 0x006D95AD -*/ + * + * rct2: 0x006D95AD + */ static void vehicle_update_showing_film(rct_vehicle *vehicle) { int currentTime, totalTime; @@ -3311,9 +3362,10 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) } } -/* rct2: 0x0068B8BD - * returns the map element that the vehicle will collide with - * returns NULL if no collisions. +/** + * + * rct2: 0x0068B8BD + * @returns the map element that the vehicle will collide with or NULL if no collisions. */ static rct_map_element* vehicle_check_collision(sint16 x, sint16 y, sint16 z) { rct_map_element* mapElement = map_get_first_element_at(x / 32, y / 32); @@ -3344,7 +3396,10 @@ static rct_map_element* vehicle_check_collision(sint16 x, sint16 y, sint16 z) { return NULL; } -/* rct2: 0x006DE6C6 */ +/** + * + * rct2: 0x006DE6C6 + */ static void vehicle_kill_all_passengers(rct_vehicle* vehicle) { uint16 numFatalities = 0; @@ -3507,95 +3562,9 @@ static void vehicle_crash_on_water(rct_vehicle* vehicle) { } /** -* -* rct2: 0x006D9D21 -*/ -static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle) { - rct_ride* ride = GET_RIDE(vehicle->ride); - - if (vehicle->sub_state == 0) { - if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) { - if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN) - return; - - ride->lifecycle_flags |= RIDE_LIFECYCLE_BROKEN_DOWN; - ride_breakdown_add_news_item(vehicle->ride); - ride->window_invalidate_flags |= - RIDE_INVALIDATE_RIDE_MAIN | - RIDE_INVALIDATE_RIDE_LIST | - RIDE_INVALIDATE_RIDE_MAINTENANCE; - - ride->mechanic_status = RIDE_MECHANIC_STATUS_CALLING; - ride->inspection_station = vehicle->current_station; - ride->breakdown_reason = ride->breakdown_reason_pending; - vehicle->velocity = 0; - return; - } - - vehicle->sub_state = 1; - vehicle_peep_easteregg_here_we_are(vehicle); - if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TESTED)) { - if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_TESTING)) { - if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TEST_IN_PROGRESS)) { - vehicle_test_reset(vehicle); - } - else { - uint8 currentSegment = ride->current_test_segment + 1; - if (currentSegment >= ride->num_stations) { - vehicle_update_test_finish(vehicle); - } - else { - ride->current_test_segment = currentSegment; - ride->var_1F6 = vehicle->current_station; - } - } - } - } - } - - rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); - rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - - if (vehicle->velocity <= 439800) { - vehicle->var_2C = 4398; - } - int flags = vehicle_update_track_motion(vehicle, NULL); - - if (flags & (1 << 11)) { - vehicle->status = VEHICLE_STATUS_TRAVELLING; - vehicle_invalidate_window(vehicle); - vehicle->sub_state = 1; - vehicle->lost_time_out = 0; - return; - } - - if (vehicle->sub_state == 2) - return; - - if (flags & (1 << 3) && vehicle->current_station == RCT2_GLOBAL(0x00F64E1C, uint8)) - return; - - vehicle->sub_state = 2; - - if (ride->mode == RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED || - ride->mode == RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED) - return; - - // This is slightly different to the vanilla function - ride->station_depart[vehicle->current_station] &= STATION_DEPART_FLAG; - uint8 waitingTime = 3; - if (ride->depart_flags & RIDE_DEPART_WAIT_FOR_MINIMUM_LENGTH) { - waitingTime = max(ride->min_waiting_time, 3); - waitingTime = min(waitingTime, 127); - } - - ride->station_depart[vehicle->current_station] |= waitingTime; -} - -/** -* -* rct2: 0x006D98CA -*/ + * + * rct2: 0x006D98CA + */ static void vehicle_update_crash(rct_vehicle *vehicle){ uint16 spriteId = vehicle->sprite_index; rct_vehicle* curVehicle; @@ -3777,7 +3746,6 @@ static void vehicle_update_sound(rct_vehicle *vehicle) } /** - * * * rct2: 0x006D796B */ @@ -4376,15 +4344,16 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) gForceLateral *= 10; gForceVert >>= 16; gForceLateral >>= 16; + + // Call original version so we can test if our result is the same as the original int eax, ebx, ecx, edx, esi, edi, ebp; - esi = (int)vehicle; RCT2_CALLFUNC_X(0x006D73D0, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - if (gForceVert != (sint16)(eax & 0xFFFF)) assert(gForceVert == (sint16)(eax & 0xFFFF)); if (gForceLateral != (sint16)(edx & 0xFFFF)) assert(gForceLateral == (sint16)(edx & 0xFFFF)); + if (verticalG != NULL) *verticalG = (sint16)(gForceVert & 0xFFFF); if (lateralG != NULL) *lateralG = (sint16)(gForceLateral & 0xFFFF); } @@ -4622,117 +4591,8 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { /** * - * rct2: 0x006DEF56 + * rct2: 0x006DA44E */ -int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift) -{ - rct_ride_type* rideEntry = GET_RIDE_ENTRY(cableLift->ride_subtype); - rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[cableLift->vehicle_type]; - rct_ride* ride = GET_RIDE(cableLift->ride); - - RCT2_GLOBAL(0x00F64E2C, uint8) = 0; - RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = cableLift; - RCT2_GLOBAL(0x00F64E18, uint32) = 0; - RCT2_GLOBAL(0x00F64E1C, uint32) = (uint32)-1; - - cableLift->velocity += cableLift->var_2C; - RCT2_GLOBAL(0x00F64E08, sint32) = cableLift->velocity; - RCT2_GLOBAL(0x00F64E0C, sint32) = (cableLift->velocity / 1024) * 42; - - rct_vehicle* frontVehicle = cableLift; - if (cableLift->velocity < 0) { - frontVehicle = vehicle_get_tail(cableLift); - } - - RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = frontVehicle; - - for (rct_vehicle* vehicle = frontVehicle;;) { - vehicle->var_2C = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; - RCT2_GLOBAL(0x00F64E10, uint32) = 1; - vehicle->var_24 += RCT2_GLOBAL(0x00F64E0C, sint32); - - if (vehicle->var_24 < 0 || vehicle->var_24 >= 13962) { - rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); - unk_F64E20->x = vehicle->x; - unk_F64E20->y = vehicle->y; - unk_F64E20->z = vehicle->z; - invalidate_sprite_2((rct_sprite*)vehicle); - - while (true) { - if (vehicle->var_24 < 0) { - if (sub_6DF21B_loop(vehicle) == true) { - break; - } - else { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); - RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 - 13962; - vehicle->var_24 = 13962; - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; - RCT2_GLOBAL(0x00F64E10, uint32)++; - continue; - } - } - else { - if (sub_6DF01A_loop(vehicle) == true) { - break; - } - else { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); - RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 + 1; - vehicle->var_24 = -1; - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; - RCT2_GLOBAL(0x00F64E10, uint32)++; - } - } - } - sprite_move( - unk_F64E20->x, - unk_F64E20->y, - unk_F64E20->z, - (rct_sprite*)vehicle); - - invalidate_sprite_2((rct_sprite*)vehicle); - } - vehicle->var_2C /= RCT2_GLOBAL(0x00F64E10, uint32); - if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { - if (vehicle->next_vehicle_on_train == 0xFFFF) - break; - vehicle = GET_VEHICLE(vehicle->next_vehicle_on_train); - } - else { - if (vehicle == cableLift) - break; - vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); - } - } - - uint32 vehicleCount = 0; - uint16 frictionTotal = 0; - sint32 var2CTotal = 0; - - for (uint16 spriteId = cableLift->sprite_index; spriteId != 0xFFFF;) { - rct_vehicle* vehicle = GET_VEHICLE(spriteId); - vehicleCount++; - frictionTotal += vehicle->friction; - var2CTotal += vehicle->var_2C; - spriteId = vehicle->next_vehicle_on_train; - } - - sint32 ecx = (var2CTotal / vehicleCount) >> 9; - ecx -= cableLift->velocity >> 12; - - sint32 edx = cableLift->velocity >> 8; - edx *= edx; - if (cableLift->velocity < 0) - edx = -edx; - edx >>= 4; - ecx -= edx / frictionTotal; - - cableLift->var_2C = ecx; - return RCT2_GLOBAL(0x00F64E18, uint32); -} - -/* rct2: 0x006DA44E */ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { RCT2_GLOBAL(0x00F64E18, uint32) = 0; rct_ride* ride = GET_RIDE(vehicle->ride); @@ -4898,67 +4758,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { return RCT2_GLOBAL(0x00F64E18, uint32); } -rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head) -{ - rct_ride *ride = GET_RIDE(rideIndex); - rct_vehicle *current = &(create_sprite(1)->vehicle); - current->sprite_identifier = SPRITE_IDENTIFIER_VEHICLE; - current->ride = rideIndex; - current->ride_subtype = 0xFF; - if (head) { - move_sprite_to_list((rct_sprite*)current, SPRITE_LINKEDLIST_OFFSET_VEHICLE); - ride->cable_lift = current->sprite_index; - } - current->is_child = head ? 0 : 1; - current->var_44 = var_44; - current->var_24 = var_24; - current->sprite_width = 10; - current->sprite_height_negative = 10; - current->sprite_height_positive = 10; - current->friction = 100; - current->num_seats = 0; - current->speed = 20; - current->acceleration = 80; - current->velocity = 0; - current->var_2C = 0; - current->var_4A = 0; - current->var_4C = 0; - current->var_4E = 0; - current->restraints_position = 0; - current->var_BA = 0; - current->var_B6 = 0; - current->var_B8 = 0; - current->sound1_id = 0xFF; - current->sound2_id = 0xFF; - current->var_C4 = 0; - current->var_C5 = 0; - current->var_C8 = 0; - current->var_CA = 0; - current->scream_sound_id = 0xFF; - current->var_1F = 0; - current->var_20 = 0; - for (int j = 0; j < 32; j++) { - current->peep[j] = SPRITE_INDEX_NULL; - } - current->var_CD = 0; - current->sprite_direction = direction << 3; - current->track_x = x; - current->track_y = y; - z = z * 8; - current->track_z = z; - z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); - - sprite_move(16, 16, z, (rct_sprite*)current); - current->track_type = (TRACK_ELEM_CABLE_LIFT_HILL << 2) | (current->sprite_direction >> 3); - current->track_progress = 164; - current->update_flags = VEHICLE_UPDATE_FLAG_1; - current->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; - current->sub_state = 0; - current->num_peeps = 0; - current->next_free_seat = 0; - return current; -} /** * @@ -5024,7 +4824,7 @@ static bool vehicle_update_bumper_car_collision(rct_vehicle *vehicle, sint16 x, return false; } -// 0x0x009A2970 +// rct2: 0x009A2970 const sint32 *dword_9A2970 = (sint32*)0x009A2970; /** diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 9fdde1ace0..2e2b08a410 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -303,12 +303,17 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG); void vehicle_set_map_toolbar(rct_vehicle *vehicle); int vehicle_is_used_in_pairs(rct_vehicle *vehicle); rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); -int vehicle_update_track_motion_cable_lift(rct_vehicle *cableLift); -rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head); int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation); rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle); int vehicle_get_total_num_peeps(rct_vehicle *vehicle); void vehicle_invalidate_window(rct_vehicle *vehicle); +void vehicle_update_test_finish(rct_vehicle* vehicle); +void vehicle_test_reset(rct_vehicle* vehicle); +void vehicle_peep_easteregg_here_we_are(rct_vehicle* vehicle); +rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); +rct_vehicle *vehicle_get_tail(rct_vehicle *vehicle); +bool sub_6DF21B_loop(rct_vehicle* vehicle); +bool sub_6DF01A_loop(rct_vehicle* vehicle); /** Helper macro until rides are stored in this module. */ #define GET_VEHICLE(sprite_index) &(g_sprite_list[sprite_index].vehicle) From 12fdf1f5e7f0f15c49df91fa77c165d49058bff8 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Wed, 16 Dec 2015 19:12:58 +0000 Subject: [PATCH 125/162] name vehicle entry flags --- src/object.c | 28 +++++++------- src/peep/peep.c | 28 +++++++------- src/ride/ride.c | 2 +- src/ride/ride_data.c | 4 +- src/ride/vehicle.c | 88 ++++++++++++++++++++++---------------------- src/ride/vehicle.h | 43 ++++++++++++++++++++-- src/windows/ride.c | 10 ++--- 7 files changed, 120 insertions(+), 83 deletions(-) diff --git a/src/object.c b/src/object.c index 81020c04cc..51ed617651 100644 --- a/src/object.c +++ b/src/object.c @@ -490,14 +490,14 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp if (rideVehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_FLAT) { int al = 1; - if (rideVehicleEntry->var_14 & 2) { + if (rideVehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SWINGING) { al = 13; - if ((rideVehicleEntry->var_14 & 0x820) != 0x820) { + if ((rideVehicleEntry->flags_b & (VEHICLE_ENTRY_FLAG_B_5 | VEHICLE_ENTRY_FLAG_B_11)) != (VEHICLE_ENTRY_FLAG_B_5 | VEHICLE_ENTRY_FLAG_B_11)) { al = 7; - if (!(rideVehicleEntry->var_14 & 0x20)) { - if (!(rideVehicleEntry->var_14 & 0x800)) { + if (!(rideVehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_5)) { + if (!(rideVehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_11)) { al = 5; - if (rideVehicleEntry->var_14 & 0x200) { + if (rideVehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_9) { al = 3; } } @@ -508,19 +508,19 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp // 0x6DE90B al = 0x20; - if (!(rideVehicleEntry->var_12 & 0x4000)) + if (!(rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_14)) { al = 1; - if (rideVehicleEntry->var_14 & 0x80) + if (rideVehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_7) { if (rideVehicleEntry->var_11 != 6) { al = 2; - if (!(rideVehicleEntry->var_12 & 0x80)) al = 4; + if (!(rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_7)) al = 4; } } } - if (rideVehicleEntry->var_12 & 0x1000) al = rideVehicleEntry->special_frames; + if (rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_12) al = rideVehicleEntry->special_frames; rideVehicleEntry->var_02 = al; // 0x6DE946 @@ -531,7 +531,7 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp if (rideVehicleEntry->car_visual != VEHICLE_VISUAL_RIVER_RAPIDS) { int b = rideVehicleEntry->var_16 * 32; - if (rideVehicleEntry->var_12 & 0x800) b /= 2; + if (rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_11) b /= 2; if (rideVehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_15) b /= 8; image_index += b; @@ -540,7 +540,7 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp if (rideVehicleEntry->sprite_flags & VEHICLE_SPRITE_FLAG_GENTLE_SLOPES) { rideVehicleEntry->var_20 = image_index; b = rideVehicleEntry->var_16 * 72; - if (rideVehicleEntry->var_12 & 0x4000) + if (rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_14) b = rideVehicleEntry->var_16 * 16; image_index += b; @@ -644,9 +644,9 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp cur_vehicle_images_offset = image_index + rideVehicleEntry->no_seating_rows * rideVehicleEntry->no_vehicle_images; // 0x6DEB0D - if (!(rideVehicleEntry->var_12 & 0x400)){ + if (!(rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_10)){ int num_images = cur_vehicle_images_offset - rideVehicleEntry->base_image_id; - if (rideVehicleEntry->var_12 & 0x2000){ + if (rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_13){ num_images *= 2; } @@ -725,7 +725,7 @@ int paint_ride_entry(int flags, int ebx, int ecx, int edx, rct_drawpixelinfo* dp rideVehicleEntry->no_vehicle_images = 0; rideVehicleEntry->var_16 = 0; - if (!(rideVehicleEntry->var_12 & 0x400)){ + if (!(rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_10)){ rideVehicleEntry->sprite_width = 0; rideVehicleEntry->sprite_height_negative = 0; rideVehicleEntry->sprite_height_positive = 0; diff --git a/src/peep/peep.c b/src/peep/peep.c index f3138c3ed8..1a4f28ed0d 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -1644,8 +1644,8 @@ static void peep_go_to_ride_entrance(rct_peep* peep, rct_ride* ride){ uint8 shift_multiplier = 21; rct_ride_type* ride_type = GET_RIDE_ENTRY(ride->subtype); - if (ride_type->vehicles[ride_type->default_vehicle].var_12 & (1 << 3) || - ride_type->vehicles[ride_type->default_vehicle].var_14 & 0x5000){ + if (ride_type->vehicles[ride_type->default_vehicle].flags_a & VEHICLE_ENTRY_FLAG_A_3 || + ride_type->vehicles[ride_type->default_vehicle].flags_b & (VEHICLE_ENTRY_FLAG_B_12 | VEHICLE_ENTRY_FLAG_B_14)){ shift_multiplier = 32; } @@ -1849,8 +1849,8 @@ void peep_update_ride_sub_state_1(rct_peep* peep){ { uint8 vehicle = ride_entry->default_vehicle; - if (ride_entry->vehicles[vehicle].var_12 & (1 << 3) || - ride_entry->vehicles[vehicle].var_14 & ((1 << 14) | (1<<12))) + if (ride_entry->vehicles[vehicle].flags_a & VEHICLE_ENTRY_FLAG_A_3 || + ride_entry->vehicles[vehicle].flags_b & (VEHICLE_ENTRY_FLAG_B_12 | VEHICLE_ENTRY_FLAG_B_14)) RCT2_GLOBAL(0xF1AECA, uint16) = 0x1C; else RCT2_GLOBAL(0xF1AECA, uint16) = 0x10; @@ -1951,7 +1951,7 @@ void peep_update_ride_sub_state_1(rct_peep* peep){ ride_entry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle* vehicle_type = &ride_entry->vehicles[vehicle->vehicle_type]; - if (vehicle_type->var_14 & (1 << 10)){ + if (vehicle_type->flags_b & VEHICLE_ENTRY_FLAG_B_10){ sint16 x, y, z; x = ride->entrances[peep->current_ride_station] & 0xFF; y = ride->entrances[peep->current_ride_station] >> 8; @@ -2008,7 +2008,7 @@ void peep_update_ride_sub_state_1(rct_peep* peep){ return; } - if (vehicle_type->var_14 & (1 << 15)){ + if (vehicle_type->flags_b & VEHICLE_ENTRY_FLAG_B_15){ peep->destination_x = vehicle->x; peep->destination_y = vehicle->y; peep->destination_tolerence = 15; @@ -2061,8 +2061,8 @@ static void peep_go_to_ride_exit(rct_peep* peep, rct_ride* ride, sint16 x, sint1 rct_ride_type* ride_type = GET_RIDE_ENTRY(ride->subtype); rct_ride_type_vehicle* vehicle_entry = &ride_type->vehicles[ride_type->default_vehicle]; - if (vehicle_entry->var_12 & (1 << 3) || - vehicle_entry->var_14 & 0x5000){ + if (vehicle_entry->flags_a & VEHICLE_ENTRY_FLAG_A_3 || + vehicle_entry->flags_b & (VEHICLE_ENTRY_FLAG_B_12 | VEHICLE_ENTRY_FLAG_B_14)){ shift_multiplier = 32; } @@ -2211,7 +2211,7 @@ static void peep_update_ride_sub_state_2(rct_peep* peep){ rct_ride_type* ride_entry = GET_RIDE_ENTRY(vehicle->ride_subtype); - if (ride_entry->vehicles[0].var_12 & (1 << 3)){ + if (ride_entry->vehicles[0].flags_a & VEHICLE_ENTRY_FLAG_A_3){ vehicle->var_D5 &= ~(1 << 5); @@ -2362,7 +2362,7 @@ void peep_update_ride_sub_state_7(rct_peep* peep){ rct_ride_type* ride_entry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle* vehicle_entry = &ride_entry->vehicles[vehicle->vehicle_type]; - if (!(vehicle_entry->var_14 & (1 << 10))){ + if (!(vehicle_entry->flags_b & VEHICLE_ENTRY_FLAG_B_10)){ sint16 x, y, z; x = ride->exits[peep->current_ride_station] & 0xFF; y = ride->exits[peep->current_ride_station] >> 8; @@ -2397,12 +2397,12 @@ void peep_update_ride_sub_state_7(rct_peep* peep){ vehicle_entry = &ride_entry->vehicles[ride_entry->default_vehicle]; uint8 shift_multiplier = 12; - if (vehicle_entry->var_14 & (1 << 14)){ + if (vehicle_entry->flags_b & VEHICLE_ENTRY_FLAG_B_14){ shift_multiplier = 9; } uint8 direction = exit_direction; - if (vehicle_entry->var_14 & ((1 << 14) | (1 << 12))){ + if (vehicle_entry->flags_b & (VEHICLE_ENTRY_FLAG_B_12 | VEHICLE_ENTRY_FLAG_B_14)){ direction = ((vehicle->sprite_direction + 3) / 8) + 1; direction &= 3; @@ -2543,7 +2543,7 @@ static void peep_update_ride_prepare_for_state_9(rct_peep* peep){ rct_ride_type* ride_type = GET_RIDE_ENTRY(ride->subtype); rct_ride_type_vehicle* vehicle_entry = &ride_type->vehicles[ride_type->default_vehicle]; - if (vehicle_entry->var_14 & 0x5000){ + if (vehicle_entry->flags_b & (VEHICLE_ENTRY_FLAG_B_12 | VEHICLE_ENTRY_FLAG_B_14)){ shift_multiplier = 32; } @@ -2759,7 +2759,7 @@ static void peep_update_ride_sub_state_13(rct_peep* peep){ rct_ride_type* ride_type = GET_RIDE_ENTRY(ride->subtype); rct_ride_type_vehicle* vehicle_entry = &ride_type->vehicles[ride_type->default_vehicle]; - if (vehicle_entry->var_14 & 0x5000){ + if (vehicle_entry->flags_b & (VEHICLE_ENTRY_FLAG_B_12 | VEHICLE_ENTRY_FLAG_B_14)){ shift_multiplier = 32; } diff --git a/src/ride/ride.c b/src/ride/ride.c index d81ee14f9c..abe78e93b6 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -6227,7 +6227,7 @@ void set_vehicle_type_image_max_sizes(rct_ride_type_vehicle* vehicle_type, int n // Moved from object paint - if (vehicle_type->var_12 & 0x2000){ + if (vehicle_type->flags_a & VEHICLE_ENTRY_FLAG_A_13){ bl += 16; } diff --git a/src/ride/ride_data.c b/src/ride/ride_data.c index 8d129ffbaa..477f658e3c 100644 --- a/src/ride/ride_data.c +++ b/src/ride/ride_data.c @@ -1175,8 +1175,8 @@ const rct_ride_type_vehicle CableLiftVehicle = { .sprite_height_negative = 0, .sprite_height_positive = 0, .var_11 = 0, - .var_12 = 0, - .var_14 = 0, + .flags_a = 0, + .flags_b = 0, .var_16 = 1, .base_image_id = 29110, .var_1C = 0, diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index b4e3655035..06071498d5 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -599,11 +599,11 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - if (vehicleEntry->var_14 & (1 << 2)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING) { if (abs(vehicle->var_B6) <= 700 && !(vehicle->var_BA & 0x30) && ( - !(vehicleEntry->var_12 & (1 << 14)) || + !(vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_14) || !(vehicle->var_BA & 0xF8)) ){ vehicle->var_B6 = 0; @@ -1053,8 +1053,8 @@ static void vehicle_update(rct_vehicle *vehicle) RCT2_GLOBAL(0x00F64E34, uint8) = 255; if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) { RCT2_GLOBAL(0x00F64E34, uint8) = ride->breakdown_reason_pending; - if ((vehicleEntry->var_14 & 8) && ride->breakdown_reason_pending == BREAKDOWN_SAFETY_CUT_OUT) { - if (!(vehicleEntry->var_14 & 0x2000) || + if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3) && ride->breakdown_reason_pending == BREAKDOWN_SAFETY_CUT_OUT) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_13) || ( vehicle->var_1F == 2 && vehicle->velocity <= 0x20000 @@ -1193,7 +1193,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - if (!(vehicleEntry->var_14 & (1 << 3))){ + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3)){ if (vehicle->velocity <= 131940){ vehicle->var_2C = 3298; } @@ -1484,7 +1484,7 @@ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - if (vehicleEntry->var_12 & (1 << 7) && vehicle->var_C5 != 1) { + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_7 && vehicle->var_C5 != 1) { vehicle->var_C5 = 1; invalidate_sprite_2((rct_sprite*)vehicle); } @@ -1991,7 +1991,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { case RIDE_MODE_ROTATING_LIFT: case RIDE_MODE_FREEFALL_DROP: case RIDE_MODE_BOAT_HIRE: - if (vehicleEntry->var_14 & (1 << 3)) + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3) break; if (vehicle->velocity <= 131940) @@ -2582,7 +2582,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { vehicle->var_2C = 0; } else { - if (!(vehicleEntry->var_14 & (1 << 3)) && + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3) && vehicle->velocity >= -131940) { vehicle->var_2C = -3298; } @@ -2647,7 +2647,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { vehicle->var_C0++; if (flags & (1 << 1) && - vehicleEntry->var_14 & (1 << 14) && + vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_14 && vehicle->var_C0 < 40){ return; } @@ -3707,7 +3707,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle) break; default: - if ((vehicleEntry->var_14 & 0x10)) { + if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_4)) { screamId = vehicle_update_scream_sound(vehicle); if (screamId == NO_SCREAM) screamId = 255; @@ -4740,7 +4740,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; - if (!(vehicleEntry->var_14 & (1 << 3))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3)) { vehicle->var_2C = -eax; return RCT2_GLOBAL(0x00F64E18, uint32); } @@ -4837,7 +4837,7 @@ static void vehicle_update_track_motion_up_stop_check(rct_vehicle *vehicle) int verticalG, lateralG; // No up stops (coaster types) - if (vehicleEntry->var_12 & (1 << 1)) { + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_1) { int trackType = vehicle->track_type >> 2; if (!track_element_is_covered(trackType)) { vehicle_get_g_forces(vehicle, &verticalG, &lateralG); @@ -4856,7 +4856,7 @@ static void vehicle_update_track_motion_up_stop_check(rct_vehicle *vehicle) RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED; } } - } else if (vehicleEntry->var_12 & (1 << 2)) { + } else if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_2) { // No up stops bobsleigh type int trackType = vehicle->track_type >> 2; if (!track_element_is_covered(trackType)) { @@ -4889,7 +4889,7 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); // Is chair lift type - if (vehicleEntry->var_14 & (1 << 12)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_12) { sint32 velocity = ride->speed << 16; if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) { velocity = 0; @@ -5707,10 +5707,10 @@ void sub_6DBF3E(rct_vehicle *vehicle) } } else { uint16 cx = 17; - if (vehicleEntry->var_14 & (1 << 12)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_12) { cx = 6; } - if (vehicleEntry->var_14 & (1 << 14)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_14) { cx = vehicle->var_CD == 6 ? 18 : 20; } @@ -5744,7 +5744,7 @@ bool vehicle_update_track_motion_forwards_get_new_track(rct_vehicle *vehicle, ui if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { mapElement->flags |= (1 << 5); if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { - if (!(rideEntry->vehicles[0].var_14 & (1 << 3))) { + if (!(rideEntry->vehicles[0].flags_b & VEHICLE_ENTRY_FLAG_B_3)) { audio_play_sound_at_location(SOUND_49, vehicle->track_x, vehicle->track_y, vehicle->track_z); } } @@ -5756,7 +5756,7 @@ bool vehicle_update_track_motion_forwards_get_new_track(rct_vehicle *vehicle, ui // TODO check if getting the vehicle entry again is necessary rct_ride_type_vehicle* vehicleEntry = vehicle_get_vehicle_entry(vehicle); - if (vehicleEntry->var_12 & (1 << 8)) { + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_8) { vehicle_update_scenery_door(vehicle); } @@ -5836,7 +5836,7 @@ loc_6DB41D: // TODO check if getting the vehicle entry again is necessary vehicleEntry = vehicle_get_vehicle_entry(vehicle); - if ((vehicleEntry->var_14 & (1 << 14)) && vehicle->var_CD < 7) { + if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_14) && vehicle->var_CD < 7) { trackType = mapElement->properties.track.type; if (trackType == TRACK_ELEM_FLAT) { loc_6DB481(vehicle); @@ -5883,7 +5883,7 @@ loc_6DB500: if (trackType == TRACK_ELEM_ROTATION_CONTROL_TOGGLE) { vehicle->update_flags ^= VEHICLE_UPDATE_FLAG_13; } - if (vehicleEntry->var_12 & (1 << 8)) { + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_8) { sub_6DEDE8(vehicle); } return true; @@ -5914,7 +5914,7 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) // eax = rideEntry // edi = vehicleEntry - if (vehicleEntry->var_12 & (1 << 3)) { + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_3) { goto loc_6DC3A7; } @@ -5936,15 +5936,15 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) loc_6DAE27: // Swinging cars - if (vehicleEntry->var_14 & (1 << 1)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SWINGING) { sub_6D6776(vehicle); } // Spinning cars - if (vehicleEntry->var_14 & (1 << 2)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING) { sub_6D661F(vehicle); } // Rider sprites?? animation?? - if ((vehicleEntry->var_14 & (1 << 7)) || (vehicleEntry->var_14 & (1 << 8))) { + if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_7) || (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_8)) { sub_6D63D4(vehicle); } vehicle->var_2C = dword_9A2970[vehicle->var_1F]; @@ -6101,7 +6101,7 @@ loc_6DB8A5: regs.ebx = moveInfo->var_07; - if ((vehicleEntry->var_14 & 0x200) && moveInfo->var_07 != 0) { + if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_9) && moveInfo->var_07 != 0) { vehicle->var_4A = 0; vehicle->var_4C = 0; vehicle->var_4E = 0; @@ -6146,13 +6146,13 @@ loc_6DB967: regs.eax = abs(vehicle->velocity - head->velocity); if (!(rideEntry->flags & RIDE_ENTRY_FLAG_18)) { if (regs.eax > 0xE0000) { - if (!(vehicleEntry->var_14 & (1 << 6))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_6)) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } } } - if (vehicleEntry->var_14 & (1 << 14)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_14) { vehicle->velocity -= vehicle->velocity >> 2; } else { sint32 newHeadVelocity = vehicle->velocity >> 1; @@ -6367,7 +6367,7 @@ loc_6DBD42: regs.ebx = moveInfo->var_07; vehicle->var_1F = regs.bl; - if ((vehicleEntry->var_14 & 0x200) && regs.bl != 0) { + if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_9) && regs.bl != 0) { vehicle->var_4A = 0; vehicle->var_4C = 0; vehicle->var_4E = 0; @@ -6410,13 +6410,13 @@ loc_6DBE7F: if (!(rideEntry->flags & RIDE_ENTRY_FLAG_18)) { if (regs.eax > 0xE0000) { - if (!(vehicleEntry->var_14 & (1 << 6))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_6)) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } } } - if (vehicleEntry->var_14 & (1 << 14)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_14) { vehicle->velocity -= vehicle->velocity >> 2; RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } else { @@ -6503,10 +6503,10 @@ loc_6DC144: regs.eax = regs.eax / regs.ebp; regs.ecx -= regs.eax; - if (!(vehicleEntry->var_14 & (1 << 3))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3)) { goto loc_6DC2FA; } - if (vehicleEntry->var_12 & (1 << 0)) { + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_0) { regs.eax = vehicle->speed * 0x4000; if (regs.eax < vehicle->velocity) { goto loc_6DC2FA; @@ -6551,11 +6551,11 @@ loc_6DC23A: regs.eax *= regs.edx; regs.eax /= regs.ebx; - if (vehicleEntry->var_12 & (1 << 15)) { + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_15) { regs.eax <<= 2; } - if (!(vehicleEntry->var_14 & (1 << 13))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_13)) { goto loc_6DC2E3; } @@ -6563,7 +6563,7 @@ loc_6DC23A: regs.eax >>= 4; } - if (vehicleEntry->var_14 & (1 << 2)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING) { regs.bx = vehicle->var_B6; if (regs.bx > 512) { regs.bx = 512; @@ -6579,7 +6579,7 @@ loc_6DC23A: regs.eax = 0; } - if (!(vehicleEntry->var_14 & (1 << 2))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING)) { if (vehicle->var_1F == 2) { vehicle->var_B6 = 0; } @@ -6907,7 +6907,7 @@ loc_6DC8A1: vehicle->var_20 = moveInfo->var_08; vehicle->var_1F = moveInfo->var_07; - if (rideEntry->vehicles[0].var_14 & (1 << 9)) { + if (rideEntry->vehicles[0].flags_b & VEHICLE_ENTRY_FLAG_B_9) { if (vehicle->var_1F != 0) { vehicle->var_4A = 0; vehicle->var_4C = 0; @@ -7046,7 +7046,7 @@ loc_6DCC2C: vehicle->var_20 = moveInfo->var_08; vehicle->var_1F = moveInfo->var_07; - if (rideEntry->vehicles[0].var_14 & (1 << 9)) { + if (rideEntry->vehicles[0].flags_b & VEHICLE_ENTRY_FLAG_B_9) { if (vehicle->var_1F != 0) { vehicle->var_4A = 0; vehicle->var_4C = 0; @@ -7087,7 +7087,7 @@ loc_6DCD6B: rct_vehicle *vEDI = RCT2_GLOBAL(0x00F64E04, uint32); regs.eax = abs(vEDI->velocity - vEBP->velocity); if (regs.eax > 0xE0000) { - if (!(vehicleEntry->var_14 & (1 << 6))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_6)) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } } @@ -7199,10 +7199,10 @@ loc_6DCEFF: regs.eax = regs.edx / regs.ebp; regs.ecx -= regs.eax; - if (!(vehicleEntry->var_14 & (1 << 3))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3)) { goto loc_6DD069; } - if (vehicleEntry->var_12 & (1 << 0)) { + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_0) { regs.eax = vehicle->speed * 0x4000; if (regs.eax < vehicle->velocity) { goto loc_6DD069; @@ -7223,7 +7223,7 @@ loc_6DCEFF: regs.eax *= regs.edx; regs.eax = regs.eax / regs.ebx; - if (!(vehicleEntry->var_14 & (1 << 13))) { + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_13)) { goto loc_6DD054; } @@ -7231,13 +7231,13 @@ loc_6DCEFF: regs.eax >>= 4; } - if (vehicleEntry->var_14 & (1 << 2)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING) { vehicle->var_B6 = clamp(-0x200, (sint16)vehicle->var_B6, 0x200); } if (vehicle->var_1F != 0) { regs.eax = max(0, regs.eax); - if (vehicleEntry->var_14 & (1 << 2)) { + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING) { if (vehicle->var_1F == 2) { vehicle->var_B6 = 0; } diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 2e2b08a410..45aac1b316 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -46,8 +46,8 @@ typedef struct { uint8 sprite_height_negative; // 0x0F , 0x29 uint8 sprite_height_positive; // 0x10 , 0x2A uint8 var_11; // 0x11 , 0x2B - uint16 var_12; // 0x12 , 0x2C - uint16 var_14; // 0x14 , 0x2E + uint16 flags_a; // 0x12 , 0x2C + uint16 flags_b; // 0x14 , 0x2E uint16 var_16; // 0x16 , 0x30 uint32 base_image_id; // 0x18 , 0x32 uint32 var_1C; // 0x1C , 0x36 @@ -189,6 +189,44 @@ typedef struct { rct_vehicle *tail; } train_ref; +enum { + VEHICLE_ENTRY_FLAG_A_0 = 1 << 0, + VEHICLE_ENTRY_FLAG_A_1 = 1 << 1, + VEHICLE_ENTRY_FLAG_A_2 = 1 << 2, + VEHICLE_ENTRY_FLAG_A_3 = 1 << 3, + VEHICLE_ENTRY_FLAG_A_4 = 1 << 4, + VEHICLE_ENTRY_FLAG_A_5 = 1 << 5, + VEHICLE_ENTRY_FLAG_A_6 = 1 << 6, + VEHICLE_ENTRY_FLAG_A_7 = 1 << 7, + VEHICLE_ENTRY_FLAG_A_8 = 1 << 8, + VEHICLE_ENTRY_FLAG_A_9 = 1 << 9, + VEHICLE_ENTRY_FLAG_A_10 = 1 << 10, + VEHICLE_ENTRY_FLAG_A_11 = 1 << 11, + VEHICLE_ENTRY_FLAG_A_12 = 1 << 12, + VEHICLE_ENTRY_FLAG_A_13 = 1 << 13, + VEHICLE_ENTRY_FLAG_A_14 = 1 << 14, + VEHICLE_ENTRY_FLAG_A_15 = 1 << 15, +}; + +enum { + VEHICLE_ENTRY_FLAG_B_0 = 1 << 0, + VEHICLE_ENTRY_FLAG_B_SWINGING = 1 << 1, + VEHICLE_ENTRY_FLAG_B_SPINNING = 1 << 2, + VEHICLE_ENTRY_FLAG_B_3 = 1 << 3, + VEHICLE_ENTRY_FLAG_B_4 = 1 << 4, + VEHICLE_ENTRY_FLAG_B_5 = 1 << 5, + VEHICLE_ENTRY_FLAG_B_6 = 1 << 6, + VEHICLE_ENTRY_FLAG_B_7 = 1 << 7, + VEHICLE_ENTRY_FLAG_B_8 = 1 << 8, + VEHICLE_ENTRY_FLAG_B_9 = 1 << 9, + VEHICLE_ENTRY_FLAG_B_10 = 1 << 10, + VEHICLE_ENTRY_FLAG_B_11 = 1 << 11, + VEHICLE_ENTRY_FLAG_B_12 = 1 << 12, + VEHICLE_ENTRY_FLAG_B_13 = 1 << 13, + VEHICLE_ENTRY_FLAG_B_14 = 1 << 14, + VEHICLE_ENTRY_FLAG_B_15 = 1 << 15, +}; + enum { VEHICLE_STATUS_MOVING_TO_END_OF_STATION, VEHICLE_STATUS_WAITING_FOR_PASSENGERS, @@ -297,7 +335,6 @@ enum { void vehicle_update_all(); int sub_6BC2F3(rct_vehicle* vehicle); -void sub_6BB9FF(rct_vehicle* vehicle); void vehicle_sounds_update(); void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG); void vehicle_set_map_toolbar(rct_vehicle *vehicle); diff --git a/src/windows/ride.c b/src/windows/ride.c index f9dba8ac6c..e403b9277f 100644 --- a/src/windows/ride.c +++ b/src/windows/ride.c @@ -1059,7 +1059,7 @@ static void window_ride_draw_tab_vehicle(rct_drawpixelinfo *dpi, rct_window *w) spriteIndex = 32; if (w->page == WINDOW_RIDE_PAGE_VEHICLE) spriteIndex += w->frame_no; - spriteIndex /= (rideVehicleEntry->var_12 & 0x800) ? 4 : 2; + spriteIndex /= (rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_11) ? 4 : 2; spriteIndex &= rideVehicleEntry->rotation_frame_mask; spriteIndex *= rideVehicleEntry->var_16; spriteIndex += rideVehicleEntry->base_image_id; @@ -2670,7 +2670,7 @@ static void window_ride_vehicle_scrollpaint(rct_window *w, rct_drawpixelinfo *dp vehicleColour = ride_get_vehicle_colour(ride, vehicleColourIndex); spriteIndex = 16; - if (rideVehicleEntry->var_12 & 0x800) + if (rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_11) spriteIndex /= 2; spriteIndex &= rideVehicleEntry->rotation_frame_mask; @@ -4143,9 +4143,9 @@ static void window_ride_colour_invalidate(rct_window *w) for (int i = 0; i < ride->num_cars_per_train; i++) { uint8 vehicleTypeIndex = trainLayout[i]; - colourFlags |= rideEntry->vehicles[vehicleTypeIndex].var_14; + colourFlags |= rideEntry->vehicles[vehicleTypeIndex].flags_b; colourFlags = ror32(colourFlags, 16); - colourFlags |= rideEntry->vehicles[vehicleTypeIndex].var_12; + colourFlags |= rideEntry->vehicles[vehicleTypeIndex].flags_a; colourFlags = ror32(colourFlags, 16); } @@ -4335,7 +4335,7 @@ static void window_ride_colour_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi y += rideVehicleEntry->tab_height; // Draw the coloured spinning vehicle - spriteIndex = rideVehicleEntry->var_12 & 0x800 ? w->frame_no / 4 : w->frame_no / 2; + spriteIndex = rideVehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_11 ? w->frame_no / 4 : w->frame_no / 2; spriteIndex &= rideVehicleEntry->rotation_frame_mask; spriteIndex *= rideVehicleEntry->var_16; spriteIndex += rideVehicleEntry->base_image_id; From 46dbc17d728b5fa754a272fa580d8da07b288509 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 16 Dec 2015 21:37:58 +0000 Subject: [PATCH 126/162] Move remaining cable lift functions out of vehicle.c --- src/ride/cable_lift.c | 173 +++++++++++++++++++++++++++++++++++++++ src/ride/vehicle.c | 185 +----------------------------------------- src/ride/vehicle.h | 13 ++- 3 files changed, 185 insertions(+), 186 deletions(-) diff --git a/src/ride/cable_lift.c b/src/ride/cable_lift.c index 679259b16b..c00d1663ca 100644 --- a/src/ride/cable_lift.c +++ b/src/ride/cable_lift.c @@ -199,6 +199,179 @@ static void cable_lift_update_arriving(rct_vehicle *vehicle) vehicle->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION; } +bool sub_6DF01A_loop(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); + + for (; vehicle->var_24 >= 13962; RCT2_GLOBAL(0x00F64E10, uint32)++) { + uint8 trackType = vehicle->track_type >> 2; + if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && + vehicle->track_progress == 160) { + RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); + } + + uint16 trackProgress = vehicle->track_progress + 1; + + const rct_vehicle_info *moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); + uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); + if (trackProgress >= trackTotalProgress) { + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + rct_map_element* trackElement = + map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z / 8, + trackType, + 0); + + rct_xy_element input; + rct_xy_element output; + int outputZ; + int outputDirection; + + input.x = vehicle->track_x; + input.y = vehicle->track_y; + input.element = trackElement; + + if (!track_block_get_next(&input, &output, &outputZ, &outputDirection)) + return false; + + if (gTrackDefinitions[output.element->properties.track.type].vangle_start != RCT2_GLOBAL(0x00F64E36, uint8) || + gTrackDefinitions[output.element->properties.track.type].bank_start != RCT2_GLOBAL(0x00F64E37, uint8)) + return false; + + vehicle->track_x = output.x; + vehicle->track_y = output.y; + vehicle->track_z = outputZ; + vehicle->track_direction = outputDirection; + vehicle->track_type |= output.element->properties.track.type << 2; + trackProgress = 0; + } + + vehicle->track_progress = trackProgress; + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, trackProgress); + rct_xyz16 unk = { + .x = moveInfo->x, + .y = moveInfo->y, + .z = moveInfo->z + }; + + unk.x += vehicle->track_x; + unk.y += vehicle->track_y; + unk.z += vehicle->track_z; + + uint8 bx = 0; + unk.z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); + if (unk.x != unk_F64E20->x) + bx |= (1 << 0); + if (unk.y != unk_F64E20->y) + bx |= (1 << 1); + if (unk.z != unk_F64E20->z) + bx |= (1 << 2); + + vehicle->var_24 -= RCT2_ADDRESS(0x009A2930, sint32)[bx]; + unk_F64E20->x = unk.x; + unk_F64E20->y = unk.y; + unk_F64E20->z = unk.z; + + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + vehicle->var_1F = moveInfo->var_07; + + if (vehicle->var_24 >= 13962) { + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + } + } + return true; +} + +bool sub_6DF21B_loop(rct_vehicle* vehicle) { + rct_ride* ride = GET_RIDE(vehicle->ride); + rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); + + for (; vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { + uint16 trackProgress = vehicle->track_progress - 1; + const rct_vehicle_info *moveInfo; + + if ((sint16)trackProgress == -1) { + uint8 trackType = vehicle->track_type >> 2; + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_start; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_start; + rct_map_element* trackElement = + map_get_track_element_at_of_type_seq( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z / 8, + trackType, + 0); + + rct_xy_element input; + + input.x = vehicle->track_x; + input.y = vehicle->track_y; + input.element = trackElement; + track_begin_end output; + + if (!track_block_get_previous(input.x, input.y, input.element, &output)) + return false; + + if (gTrackDefinitions[output.begin_element->properties.track.type].vangle_end != RCT2_GLOBAL(0x00F64E36, uint8) || + gTrackDefinitions[output.begin_element->properties.track.type].bank_end != RCT2_GLOBAL(0x00F64E37, uint8)) + return false; + + vehicle->track_x = output.begin_x; + vehicle->track_y = output.begin_y; + vehicle->track_z = output.begin_z; + vehicle->track_direction = output.begin_direction; + vehicle->track_type |= output.begin_element->properties.track.type << 2; + + if (output.begin_element->properties.track.type == TRACK_ELEM_END_STATION) { + RCT2_GLOBAL(0x00F64E18, uint32) = (1 << 0); + } + + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); + uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); + trackProgress = trackTotalProgress - 1; + } + vehicle->track_progress = trackProgress; + + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, trackProgress); + rct_xyz16 unk = { + .x = moveInfo->x, + .y = moveInfo->y, + .z = moveInfo->z + }; + + unk.x += vehicle->track_x; + unk.y += vehicle->track_y; + unk.z += vehicle->track_z; + + uint8 bx = 0; + unk.z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); + if (unk.x != unk_F64E20->x) + bx |= (1 << 0); + if (unk.y != unk_F64E20->y) + bx |= (1 << 1); + if (unk.z != unk_F64E20->z) + bx |= (1 << 2); + + vehicle->var_24 += RCT2_ADDRESS(0x009A2930, sint32)[bx]; + unk_F64E20->x = unk.x; + unk_F64E20->y = unk.y; + unk_F64E20->z = unk.z; + + vehicle->sprite_direction = moveInfo->direction; + vehicle->var_20 = moveInfo->var_08; + vehicle->var_1F = moveInfo->var_07; + + if (vehicle->var_24 < 0) { + vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + } + } + return true; +} + /** * * rct2: 0x006DEF56 diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 06071498d5..89c25f9009 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -74,16 +74,6 @@ static void vehicle_kill_all_passengers(rct_vehicle* vehicle); #define NO_SCREAM 254 -// Size: 0x09 -typedef struct { - uint16 x; // 0x00 - uint16 y; // 0x02 - uint16 z; // 0x04 - uint8 direction; // 0x06 - uint8 var_07; - uint8 var_08; -} rct_vehicle_info; - rct_xyz16 *unk_F64E20 = (rct_xyz16*)0x00F64E20; const uint8 byte_9A3A14[] = { SOUND_SCREAM_8, SOUND_SCREAM_1 }; @@ -93,7 +83,7 @@ const uint8 byte_9A3A18[] = { SOUND_SCREAM_7, SOUND_SCREAM_2, SOUND_SCREAM_4 }; -static const rct_vehicle_info *vehicle_get_move_info(int cd, int typeAndDirection, int offset) +const rct_vehicle_info *vehicle_get_move_info(int cd, int typeAndDirection, int offset) { const rct_vehicle_info **infoListList = RCT2_ADDRESS(0x008B8F30, rct_vehicle_info**)[cd]; const rct_vehicle_info *infoList = infoListList[typeAndDirection]; @@ -4416,179 +4406,6 @@ int vehicle_is_used_in_pairs(rct_vehicle *vehicle) return vehicle->num_seats & VEHICLE_SEAT_PAIR_FLAG; } -bool sub_6DF01A_loop(rct_vehicle* vehicle) { - rct_ride* ride = GET_RIDE(vehicle->ride); - rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); - - for (; vehicle->var_24 >= 13962; RCT2_GLOBAL(0x00F64E10, uint32)++) { - uint8 trackType = vehicle->track_type >> 2; - if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && - vehicle->track_progress == 160) { - RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 1); - } - - uint16 trackProgress = vehicle->track_progress + 1; - - const rct_vehicle_info *moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); - uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); - if (trackProgress >= trackTotalProgress) { - RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; - RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; - rct_map_element* trackElement = - map_get_track_element_at_of_type_seq( - vehicle->track_x, - vehicle->track_y, - vehicle->track_z / 8, - trackType, - 0); - - rct_xy_element input; - rct_xy_element output; - int outputZ; - int outputDirection; - - input.x = vehicle->track_x; - input.y = vehicle->track_y; - input.element = trackElement; - - if (!track_block_get_next(&input, &output, &outputZ, &outputDirection)) - return false; - - if (gTrackDefinitions[output.element->properties.track.type].vangle_start != RCT2_GLOBAL(0x00F64E36, uint8) || - gTrackDefinitions[output.element->properties.track.type].bank_start != RCT2_GLOBAL(0x00F64E37, uint8)) - return false; - - vehicle->track_x = output.x; - vehicle->track_y = output.y; - vehicle->track_z = outputZ; - vehicle->track_direction = outputDirection; - vehicle->track_type |= output.element->properties.track.type << 2; - trackProgress = 0; - } - - vehicle->track_progress = trackProgress; - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, trackProgress); - rct_xyz16 unk = { - .x = moveInfo->x, - .y = moveInfo->y, - .z = moveInfo->z - }; - - unk.x += vehicle->track_x; - unk.y += vehicle->track_y; - unk.z += vehicle->track_z; - - uint8 bx = 0; - unk.z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); - if (unk.x != unk_F64E20->x) - bx |= (1 << 0); - if (unk.y != unk_F64E20->y) - bx |= (1 << 1); - if (unk.z != unk_F64E20->z) - bx |= (1 << 2); - - vehicle->var_24 -= RCT2_ADDRESS(0x009A2930, sint32)[bx]; - unk_F64E20->x = unk.x; - unk_F64E20->y = unk.y; - unk_F64E20->z = unk.z; - - vehicle->sprite_direction = moveInfo->direction; - vehicle->var_20 = moveInfo->var_08; - vehicle->var_1F = moveInfo->var_07; - - if (vehicle->var_24 >= 13962) { - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; - } - } - return true; -} - -bool sub_6DF21B_loop(rct_vehicle* vehicle) { - rct_ride* ride = GET_RIDE(vehicle->ride); - rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); - - for (; vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { - uint16 trackProgress = vehicle->track_progress - 1; - const rct_vehicle_info *moveInfo; - - if ((sint16)trackProgress == -1) { - uint8 trackType = vehicle->track_type >> 2; - RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_start; - RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_start; - rct_map_element* trackElement = - map_get_track_element_at_of_type_seq( - vehicle->track_x, - vehicle->track_y, - vehicle->track_z / 8, - trackType, - 0); - - rct_xy_element input; - - input.x = vehicle->track_x; - input.y = vehicle->track_y; - input.element = trackElement; - track_begin_end output; - - if (!track_block_get_previous(input.x, input.y, input.element, &output)) - return false; - - if (gTrackDefinitions[output.begin_element->properties.track.type].vangle_end != RCT2_GLOBAL(0x00F64E36, uint8) || - gTrackDefinitions[output.begin_element->properties.track.type].bank_end != RCT2_GLOBAL(0x00F64E37, uint8)) - return false; - - vehicle->track_x = output.begin_x; - vehicle->track_y = output.begin_y; - vehicle->track_z = output.begin_z; - vehicle->track_direction = output.begin_direction; - vehicle->track_type |= output.begin_element->properties.track.type << 2; - - if (output.begin_element->properties.track.type == TRACK_ELEM_END_STATION) { - RCT2_GLOBAL(0x00F64E18, uint32) = (1 << 0); - } - - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); - uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); - trackProgress = trackTotalProgress - 1; - } - vehicle->track_progress = trackProgress; - - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, trackProgress); - rct_xyz16 unk = { - .x = moveInfo->x, - .y = moveInfo->y, - .z = moveInfo->z - }; - - unk.x += vehicle->track_x; - unk.y += vehicle->track_y; - unk.z += vehicle->track_z; - - uint8 bx = 0; - unk.z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); - if (unk.x != unk_F64E20->x) - bx |= (1 << 0); - if (unk.y != unk_F64E20->y) - bx |= (1 << 1); - if (unk.z != unk_F64E20->z) - bx |= (1 << 2); - - vehicle->var_24 += RCT2_ADDRESS(0x009A2930, sint32)[bx]; - unk_F64E20->x = unk.x; - unk_F64E20->y = unk.y; - unk_F64E20->z = unk.z; - - vehicle->sprite_direction = moveInfo->direction; - vehicle->var_20 = moveInfo->var_08; - vehicle->var_1F = moveInfo->var_07; - - if (vehicle->var_24 < 0) { - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; - } - } - return true; -} - /** * * rct2: 0x006DA44E diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 45aac1b316..7199b454d7 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -189,6 +189,16 @@ typedef struct { rct_vehicle *tail; } train_ref; +// Size: 0x09 +typedef struct { + uint16 x; // 0x00 + uint16 y; // 0x02 + uint16 z; // 0x04 + uint8 direction; // 0x06 + uint8 var_07; + uint8 var_08; +} rct_vehicle_info; + enum { VEHICLE_ENTRY_FLAG_A_0 = 1 << 0, VEHICLE_ENTRY_FLAG_A_1 = 1 << 1, @@ -349,8 +359,7 @@ void vehicle_test_reset(rct_vehicle* vehicle); void vehicle_peep_easteregg_here_we_are(rct_vehicle* vehicle); rct_vehicle *vehicle_get_head(rct_vehicle *vehicle); rct_vehicle *vehicle_get_tail(rct_vehicle *vehicle); -bool sub_6DF21B_loop(rct_vehicle* vehicle); -bool sub_6DF01A_loop(rct_vehicle* vehicle); +const rct_vehicle_info *vehicle_get_move_info(int cd, int typeAndDirection, int offset); /** Helper macro until rides are stored in this module. */ #define GET_VEHICLE(sprite_index) &(g_sprite_list[sprite_index].vehicle) From 3c3dd963faec5129449300e8706bc3fe2422a2c6 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 16 Dec 2015 23:01:22 +0000 Subject: [PATCH 127/162] Rearrange of code to match cable lift layout --- src/ride/vehicle.c | 299 +++++++++++++++++++++++++-------------------- 1 file changed, 169 insertions(+), 130 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 89c25f9009..376c986b86 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -5708,82 +5708,10 @@ loc_6DB500: /** * - * rct2: 0x006DAB4C + * rct2: 0x006DAEB9 */ -int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) -{ +bool vehicle_update_track_motion_forwards(rct_vehicle *vehicle, rct_ride_type_vehicle* vehicleEntry, rct_ride* ride, rct_ride_type* rideEntry) { registers regs = { 0 }; - - ////////////////////////////////////////////////////////////////////////////////////////// - regs.esi = (int)vehicle; - RCT2_CALLFUNC_Y(0x006DAB4C, ®s); - if (outStation != NULL) *outStation = regs.ebx; - return regs.eax; - ////////////////////////////////////////////////////////////////////////////////////////// - - rct_ride *ride = GET_RIDE(vehicle->ride); - rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); - rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); - - rct_map_element *mapElement = NULL; - - // esi = vehicle - // eax = rideEntry - // edi = vehicleEntry - - if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_3) { - goto loc_6DC3A7; - } - - RCT2_GLOBAL(0x00F64E2C, uint8) = 0; - RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = vehicle; - RCT2_GLOBAL(0x00F64E18, uint32) = 0; - RCT2_GLOBAL(0x00F64E1C, uint32) = 0xFFFFFFFF; - - vehicle_update_track_motion_up_stop_check(vehicle); - sub_6DAB4C_chunk_2(vehicle); - sub_6DAB4C_chunk_3(vehicle); - - if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { - vehicle = vehicle_get_tail(vehicle); - } - // This will be the front vehicle even when traveling - // backwards. - RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = vehicle; - -loc_6DAE27: - // Swinging cars - if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SWINGING) { - sub_6D6776(vehicle); - } - // Spinning cars - if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING) { - sub_6D661F(vehicle); - } - // Rider sprites?? animation?? - if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_7) || (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_8)) { - sub_6D63D4(vehicle); - } - vehicle->var_2C = dword_9A2970[vehicle->var_1F]; - RCT2_GLOBAL(0x00F64E10, uint32) = 1; - - regs.eax = RCT2_GLOBAL(0x00F64E0C, sint32) + vehicle->var_24; - vehicle->var_24 = regs.eax; - if (regs.eax < 0) { - // Backward loop - goto loc_6DBA13; - } - if (regs.eax < 0x368A) { - // Location found - goto loc_6DBF3E; - } - // Forward loop - vehicle->var_B8 &= ~(1 << 1); - unk_F64E20->x = vehicle->x; - unk_F64E20->y = vehicle->y; - unk_F64E20->z = vehicle->z; - invalidate_sprite_2((rct_sprite*)vehicle); - loc_6DAEB9: regs.edi = vehicle->track_type; regs.cx = vehicle->track_type >> 2; @@ -5796,10 +5724,12 @@ loc_6DAEB9: } if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0x40000) { vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 8; - } else if (RCT2_GLOBAL(0x00F64E08, sint32) < 0x20000) { + } + else if (RCT2_GLOBAL(0x00F64E08, sint32) < 0x20000) { vehicle->var_2C = 0x50000; } - } else if (trackType == TRACK_ELEM_BRAKES) { + } + else if (trackType == TRACK_ELEM_BRAKES) { if (!( ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN && ride->breakdown_reason_pending == BREAKDOWN_BRAKES_FAILURE && @@ -5808,7 +5738,8 @@ loc_6DAEB9: regs.eax = vehicle->var_CF << 16; if (regs.eax < RCT2_GLOBAL(0x00F64E08, sint32)) { vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; - } else if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x0F)) { + } + else if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x0F)) { if (RCT2_GLOBAL(0x00F64E2C, uint8) == 0) { RCT2_GLOBAL(0x00F64E2C, uint8)++; audio_play_sound_at_location(SOUND_51, vehicle->x, vehicle->y, vehicle->z); @@ -5841,13 +5772,14 @@ loc_6DAEB9: vehicle->vehicle_type = vehicleEntry->var_58; vehicleEntry = vehicle_get_vehicle_entry(vehicle); } - } else { + } + else { vehicle->track_progress += 17; } } regs.ax = vehicle->track_progress + 1; - + const rct_vehicle_info *moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, @@ -5875,7 +5807,7 @@ loc_6DB706:; sint16 x = vehicle->track_x + moveInfo->x; sint16 y = vehicle->track_y + moveInfo->y; sint16 z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); - + trackType = vehicle->track_type >> 2; regs.ebx = 0; if (x != unk_F64E20->x) { regs.ebx |= 1; } @@ -5883,7 +5815,7 @@ loc_6DB706:; if (z != unk_F64E20->z) { regs.ebx |= 4; } if (vehicle->var_CD == 15 && (trackType == TRACK_ELEM_LEFT_REVERSER || - trackType == TRACK_ELEM_RIGHT_REVERSER) && + trackType == TRACK_ELEM_RIGHT_REVERSER) && vehicle->track_progress >= 30 && vehicle->track_progress <= 66 ) { @@ -5892,7 +5824,7 @@ loc_6DB706:; if (vehicle->var_CD == 16 && (trackType == TRACK_ELEM_LEFT_REVERSER || - trackType == TRACK_ELEM_RIGHT_REVERSER) && + trackType == TRACK_ELEM_RIGHT_REVERSER) && vehicle->track_progress == 96 ) { sub_6DB7D6(vehicle); @@ -5936,7 +5868,7 @@ loc_6DB8A5: loc_6DB928: if (vehicle->var_24 < 0x368A) { - goto loc_6DBF20; + return true; } regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[regs.ebx]; @@ -5950,7 +5882,7 @@ loc_6DB94A: RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; vehicle->var_24 = 0xFFFFFFFF; regs.ebx = vehicle->var_1F; - goto loc_6DBE3F; + return false; loc_6DB967: regs.eax = vehicle->var_24 + 1; @@ -5971,23 +5903,25 @@ loc_6DB967: if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_14) { vehicle->velocity -= vehicle->velocity >> 2; - } else { + } + else { sint32 newHeadVelocity = vehicle->velocity >> 1; vehicle->velocity = head->velocity >> 1; head->velocity = newHeadVelocity; } RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_1; - goto loc_6DBE3F; + return false; +} -loc_6DBA13: - vehicle->var_B8 &= ~(1 << 1); - unk_F64E20->x = vehicle->x; - unk_F64E20->y = vehicle->y; - unk_F64E20->z = vehicle->z; - invalidate_sprite_2((rct_sprite*)vehicle); +/** +* +* rct2: 0x006DBA33 +*/ +bool vehicle_update_track_motion_backwards(rct_vehicle *vehicle, rct_ride_type_vehicle* vehicleEntry, rct_ride* ride, rct_ride_type* rideEntry) { + registers regs = { 0 }; -loc_6DBA33: - trackType = vehicle->track_type >> 2; +loc_6DBA33:; + uint16 trackType = vehicle->track_type >> 2; if (trackType == TRACK_ELEM_FLAT && ride->type == RIDE_TYPE_REVERSE_FREEFALL_COASTER) { sint32 unkVelocity = RCT2_GLOBAL(0x00F64E08, sint32); if (unkVelocity > 0xFFF80000) { @@ -6011,7 +5945,7 @@ loc_6DBA33: RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; - mapElement = map_get_track_element_at_of_type_seq( + rct_map_element* mapElement = map_get_track_element_at_of_type_seq( vehicle->track_x, vehicle->track_y, vehicle->track_z >> 3, @@ -6019,9 +5953,10 @@ loc_6DBA33: 0 ); -loc_6DBB08: - x = vehicle->track_x; - y = vehicle->track_y; +loc_6DBB08:; + sint16 x = vehicle->track_x; + sint16 y = vehicle->track_y; + sint16 z = 0; switch (vehicle->var_CD) { case 3: vehicle->var_CD = 1; @@ -6079,7 +6014,7 @@ loc_6DBB7E:; int vAngle = gTrackDefinitions[trackType].vangle_end; if (RCT2_GLOBAL(0x00F64E36, uint8) != vAngle || RCT2_GLOBAL(0x00F64E37, uint8) != bank - ) { + ) { goto loc_6DBE5E; } @@ -6110,7 +6045,8 @@ loc_6DBC3B: ride->var_13F == (z >> 3) ) { vehicle->var_CD = 3; - } else if ( + } + else if ( ride->var_13A == xy && ride->var_13E == (z >> 3) ) { @@ -6128,7 +6064,8 @@ loc_6DBC3B: } vehicle->update_flags |= VEHICLE_UPDATE_FLAG_0; } - } else { + } + else { if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { @@ -6148,14 +6085,14 @@ loc_6DBC3B: vehicle->track_direction |= direction; vehicle->var_CF = (mapElement->properties.track.sequence >> 4) << 1; - moveInfo = vehicle_get_move_info( + const rct_vehicle_info* moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, 0 ); // There are two bytes before the move info list - trackTotalProgress = *((uint16*)((int)moveInfo - 2)); + uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); regs.ax = trackTotalProgress - 1; loc_6DBD42: @@ -6201,7 +6138,7 @@ loc_6DBD42: loc_6DBE3F: if ((sint32)vehicle->var_24 >= 0) { - goto loc_6DBF20; + return true; } regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[regs.ebx]; vehicle->var_2C = regs.ebx; @@ -6214,7 +6151,7 @@ loc_6DBE5E: RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; vehicle->var_24 -= regs.eax; regs.ebx = vehicle->var_1F; - goto loc_6DB928; + return false; loc_6DBE7F: regs.eax = vehicle->var_24 - 0x368A; @@ -6236,41 +6173,141 @@ loc_6DBE7F: if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_14) { vehicle->velocity -= vehicle->velocity >> 2; RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; - } else { + } + else { vehicle->velocity = v3->velocity >> 1; v3->velocity = v4->velocity >> 1; RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } - goto loc_6DB928; + return false; +} -loc_6DBF20: - sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)vehicle); - invalidate_sprite_2((rct_sprite*)vehicle); +/** + * + * rct2: 0x006DAB4C + */ +int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) +{ + registers regs = { 0 }; -loc_6DBF3E: - sub_6DBF3E(vehicle); + ////////////////////////////////////////////////////////////////////////////////////////// + regs.esi = (int)vehicle; + RCT2_CALLFUNC_Y(0x006DAB4C, ®s); + if (outStation != NULL) *outStation = regs.ebx; + return regs.eax; + ////////////////////////////////////////////////////////////////////////////////////////// -loc_6DC0F7: - if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { - RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; + rct_ride *ride = GET_RIDE(vehicle->ride); + rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + rct_map_element *mapElement = NULL; + + // esi = vehicle + // eax = rideEntry + // edi = vehicleEntry + + if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_3) { + goto loc_6DC3A7; } - if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { - if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { - goto loc_6DC144; - } - vehicle = GET_VEHICLE(vehicle->next_vehicle_on_train); - } else { - if (vehicle == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { - goto loc_6DC144; + RCT2_GLOBAL(0x00F64E2C, uint8) = 0; + RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = vehicle; + RCT2_GLOBAL(0x00F64E18, uint32) = 0; + RCT2_GLOBAL(0x00F64E1C, uint32) = 0xFFFFFFFF; + + vehicle_update_track_motion_up_stop_check(vehicle); + sub_6DAB4C_chunk_2(vehicle); + sub_6DAB4C_chunk_3(vehicle); + + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { + vehicle = vehicle_get_tail(vehicle); + } + // This will be the front vehicle even when traveling + // backwards. + RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = vehicle; + + uint16 spriteId = vehicle->sprite_index; + for (rct_vehicle* car = vehicle; spriteId != 0xFFFF; car = GET_VEHICLE(spriteId)) { + // Swinging cars + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SWINGING) { + sub_6D6776(car); } - if (vehicle->prev_vehicle_on_ride == SPRITE_INDEX_NULL) { - goto loc_6DC144; + // Spinning cars + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING) { + sub_6D661F(car); } - vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride); + // Rider sprites?? animation?? + if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_7) || (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_8)) { + sub_6D63D4(car); + } + car->var_2C = dword_9A2970[car->var_1F]; + RCT2_GLOBAL(0x00F64E10, uint32) = 1; + + regs.eax = RCT2_GLOBAL(0x00F64E0C, sint32) + car->var_24; + car->var_24 = regs.eax; + + car->var_B8 &= ~(1 << 1); + unk_F64E20->x = car->x; + unk_F64E20->y = car->y; + unk_F64E20->z = car->z; + invalidate_sprite_2((rct_sprite*)car); + + while (true) { + if (car->var_24 < 0) { + // Backward loop + if (vehicle_update_track_motion_backwards(car, vehicleEntry, ride, rideEntry)) { + break; + } + else { + if (car->var_24 < 0x368A) { + break; + } + regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[car->var_1F]; + car->var_2C += regs.ebx; + RCT2_GLOBAL(0x00F64E10, uint32)++; + continue; + } + } + if (car->var_24 < 0x368A) { + // Location found + goto loc_6DBF3E; + } + if (vehicle_update_track_motion_forwards(car, vehicleEntry, ride, rideEntry)) { + break; + } + else { + if (car->var_24 >= 0) { + break; + } + regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[regs.ebx]; + car->var_2C = regs.ebx; + RCT2_GLOBAL(0x00F64E10, uint32)++; + continue; + } + } + loc_6DBF20: + sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)car); + invalidate_sprite_2((rct_sprite*)car); + + loc_6DBF3E: + sub_6DBF3E(car); + + loc_6DC0F7: + if (car->update_flags & VEHICLE_UPDATE_FLAG_0) { + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; + } + if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { + spriteId = car->next_vehicle_on_train; + } + else { + if (car == RCT2_GLOBAL(0x00F64E04, rct_vehicle*)) { + break; + } + spriteId = car->prev_vehicle_on_ride; + } } - goto loc_6DAE27; loc_6DC144: vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); regs.eax = 0; @@ -6330,7 +6367,7 @@ loc_6DC144: } } regs.eax = vehicle->speed; - trackType = vehicle->track_direction >> 2; + uint16 trackType = vehicle->track_direction >> 2; if (trackType == TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE) { goto loc_6DC22F; } @@ -6552,8 +6589,8 @@ loc_6DC476: vehicle->var_D5 &= ~(1 << 3); } -loc_6DC5B8: - moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); +loc_6DC5B8:; + const rct_vehicle_info* moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); // There are two bytes before the move info list { @@ -6572,6 +6609,8 @@ loc_6DC5B8: vehicle->track_x, vehicle->track_y, vehicle->track_z, trackType, 0 ); + sint16 x, y, z; + int direction; { rct_xy_element input, output; int outZ, outDirection; From 2007c6c4dc0ef3093b82c5c4ea231b802764bbfa Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 16 Dec 2015 23:39:38 +0000 Subject: [PATCH 128/162] Fix backwards bugs. Fix lift hill bug --- src/ride/vehicle.c | 24 ++++++++++++------------ src/ride/vehicle.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 376c986b86..9118d8c114 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2015,7 +2015,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { } } - if (flags & (1 << 4)) { + if (flags & VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_ON_LIFT_HILL) { vehicle->var_B8 |= (1 << 1); if (ride->mode != RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { sint32 speed = ride->lift_hill_speed * 31079; @@ -2441,7 +2441,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { } } - if (flags & (1 << 4)) { + if (flags & VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_ON_LIFT_HILL) { if (ride->mode == RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { if (vehicle->sub_state == 0) { if (vehicle->velocity != 0) @@ -4830,7 +4830,7 @@ static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) * * rct2: 0x006D6776 */ -static void sub_6D6776(rct_vehicle *vehicle) +static void vehicle_update_swinging_car(rct_vehicle *vehicle) { rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); RCT2_CALLPROC_X(0x006D6776, 0, 0, 0, 0, (int)vehicle, (int)vehicleEntry, 0); @@ -5120,7 +5120,7 @@ static const uint8 off_9A2E84[256] = { * * rct2: 0x006D661F */ -static void sub_6D661F(rct_vehicle *vehicle) +static void vehicle_update_spinning_car(rct_vehicle *vehicle) { if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_13) { vehicle->var_B6 = 0; @@ -5943,8 +5943,8 @@ loc_6DBA33:; goto loc_6DBD42; } - RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; - RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; + RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_start; + RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_start; rct_map_element* mapElement = map_get_track_element_at_of_type_seq( vehicle->track_x, vehicle->track_y, @@ -6058,7 +6058,7 @@ loc_6DBC3B: if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { trackType = mapElement->properties.track.type; - if (RCT2_ADDRESS(0x0099423C, uint16)[trackType] & 0x20) { + if (!(RCT2_ADDRESS(0x0099423C, uint16)[trackType] & 0x20)) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_9; } } @@ -6100,7 +6100,7 @@ loc_6DBD42: moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, - 0 + vehicle->track_progress ); x = vehicle->track_x + moveInfo->x; @@ -6232,11 +6232,11 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) for (rct_vehicle* car = vehicle; spriteId != 0xFFFF; car = GET_VEHICLE(spriteId)) { // Swinging cars if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SWINGING) { - sub_6D6776(car); + vehicle_update_swinging_car(car); } // Spinning cars if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_SPINNING) { - sub_6D661F(car); + vehicle_update_spinning_car(car); } // Rider sprites?? animation?? if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_7) || (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_8)) { @@ -6296,7 +6296,7 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) loc_6DC0F7: if (car->update_flags & VEHICLE_UPDATE_FLAG_0) { - RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_ON_LIFT_HILL; } if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { spriteId = car->next_vehicle_on_train; @@ -7004,7 +7004,7 @@ loc_6DCE68: loc_6DCEB2: if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { - RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_4; + RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_ON_LIFT_HILL; } if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.si = vehicle->next_vehicle_on_train; diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 7199b454d7..87ef7c7974 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -329,7 +329,7 @@ enum { VEHICLE_UPDATE_MOTION_TRACK_FLAG_1 = 1 << 1, VEHICLE_UPDATE_MOTION_TRACK_FLAG_2 = 1 << 2, VEHICLE_UPDATE_MOTION_TRACK_FLAG_3 = 1 << 3, - VEHICLE_UPDATE_MOTION_TRACK_FLAG_4 = 1 << 4, + VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_ON_LIFT_HILL = 1 << 4, VEHICLE_UPDATE_MOTION_TRACK_FLAG_5 = 1 << 5, VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_DERAILED = 1 << 6, VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION = 1 << 7, From 7f0f983f25118dfd3aff12c95296f7ccb4e59b89 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 17 Dec 2015 23:12:08 +0000 Subject: [PATCH 129/162] Fix block breaks --- src/ride/vehicle.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 9118d8c114..b5cb4b7afd 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -4808,17 +4808,18 @@ static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) return; } - x = trackBeginEnd.begin_x; - y = trackBeginEnd.begin_y; + x = trackBeginEnd.end_x; + y = trackBeginEnd.end_y; z = trackBeginEnd.begin_z; - } while (track_element_is_block_start(trackBeginEnd.begin_element)); + mapElement = trackBeginEnd.begin_element; + } while (!track_element_is_block_start(trackBeginEnd.begin_element)); mapElement = map_get_track_element_at(x, y, z >> 3); mapElement->flags &= ~(1 << 5); map_invalidate_element(x, y, mapElement); int trackType = mapElement->properties.track.type; - if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { + if (trackType == TRACK_ELEM_BLOCK_BRAKES || trackType == TRACK_ELEM_END_STATION) { rct_ride *ride = GET_RIDE(vehicle->ride); if (ride_is_block_sectioned(ride)) { audio_play_sound_at_location(SOUND_48, x, y, z); @@ -5560,7 +5561,7 @@ bool vehicle_update_track_motion_forwards_get_new_track(rct_vehicle *vehicle, ui if (track_element_is_block_start(mapElement)) { if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { mapElement->flags |= (1 << 5); - if (trackType == 216 || trackType == TRACK_ELEM_END_STATION) { + if (trackType == TRACK_ELEM_BLOCK_BRAKES || trackType == TRACK_ELEM_END_STATION) { if (!(rideEntry->vehicles[0].flags_b & VEHICLE_ENTRY_FLAG_B_3)) { audio_play_sound_at_location(SOUND_49, vehicle->track_x, vehicle->track_y, vehicle->track_z); } @@ -6281,7 +6282,7 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) if (car->var_24 >= 0) { break; } - regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[regs.ebx]; + regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[car->var_1F]; car->var_2C = regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; continue; From 0364d0deb72127a2c595a3f0c9cbb3d6da737bbf Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 17 Dec 2015 23:45:58 +0000 Subject: [PATCH 130/162] Fix vertical launch --- src/ride/vehicle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index b5cb4b7afd..987fee86e7 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -5502,7 +5502,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) input.x = vehicle->track_x; input.y = vehicle->track_y; input.element = mapElement; - if (track_block_get_next(&input, &output, &outputZ, &outputDirection)) { + if (!track_block_get_next(&input, &output, &outputZ, &outputDirection)) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_12; } } From 0f3fe73e6315515a7002f8feebfad168bea08283 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 18 Dec 2015 20:33:45 +0000 Subject: [PATCH 131/162] Fix more vehicle bugs. Changed sub_6DD078 to change the collide vehicle --- src/ride/track.c | 2 +- src/ride/vehicle.c | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/ride/track.c b/src/ride/track.c index c9c358bfec..19b4f5c994 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -4964,7 +4964,7 @@ int track_get_actual_bank_2(int rideType, int trackColour, int bank) int track_get_actual_bank_3(rct_vehicle *vehicle, rct_map_element *mapElement) { - uint8 colourThingToXor = (vehicle->update_flags >> 9) & 8; + uint8 colourThingToXor = (vehicle->update_flags >> 9) & 0xFF; int trackType = mapElement->properties.track.type; int rideType = GET_RIDE(mapElement->properties.track.ride_index)->type; int trackColour = mapElement->properties.track.colour ^ colourThingToXor; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 987fee86e7..72db1b74a3 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3359,6 +3359,8 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) */ static rct_map_element* vehicle_check_collision(sint16 x, sint16 y, sint16 z) { rct_map_element* mapElement = map_get_first_element_at(x / 32, y / 32); + if (mapElement == NULL) + return 1; //Can't return null as that implies no collision. uint8 bl; if ((x & 0x1F) >= 16) { @@ -5437,9 +5439,15 @@ static void sub_6DB807(rct_vehicle *vehicle) * @param vehicle (esi) * @param otherVehicleIndex (bp) */ -static bool sub_6DD078(rct_vehicle *vehicle, uint16 otherVehicleIndex) +static bool sub_6DD078(rct_vehicle *vehicle, uint16* otherVehicleIndex) { - return RCT2_CALLPROC_X(0x006DD078, 0, 0, 0, 0, (int)vehicle, 0, otherVehicleIndex) & 0x100; + registers regs = { 0 }; + regs.esi = vehicle; + regs.bp = *otherVehicleIndex; + bool result = RCT2_CALLFUNC_Y(0x006DD078, ®s) & 0x100; + + *otherVehicleIndex = regs.bp; + return result; } /** @@ -5606,6 +5614,7 @@ loc_6DB32A: regs.ecx = trackBeginEnd.begin_y; regs.edx = trackBeginEnd.begin_z; regs.bl = trackBeginEnd.begin_direction; + mapElement = trackBeginEnd.begin_element; } goto loc_6DB41D; @@ -5861,7 +5870,7 @@ loc_6DB8A5: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->prev_vehicle_on_ride; - if (sub_6DD078(vehicle, vehicle->prev_vehicle_on_ride)) { + if (sub_6DD078(vehicle, ®s.bp)) { goto loc_6DB967; } } @@ -5891,7 +5900,7 @@ loc_6DB967: vehicle->var_24 -= regs.eax; // Might need to be bp rather than vehicle, but hopefully not - rct_vehicle *head = vehicle_get_head(vehicle); + rct_vehicle *head = vehicle_get_head(GET_VEHICLE(regs.bp)); regs.eax = abs(vehicle->velocity - head->velocity); if (!(rideEntry->flags & RIDE_ENTRY_FLAG_18)) { @@ -6131,7 +6140,7 @@ loc_6DBD42: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->next_vehicle_on_ride; - if (sub_6DD078(vehicle, regs.bp)) { + if (sub_6DD078(vehicle, ®s.bp)) { goto loc_6DBE7F; } } @@ -6607,7 +6616,7 @@ loc_6DC5B8:; RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; mapElement = map_get_track_element_at_of_type_seq( - vehicle->track_x, vehicle->track_y, vehicle->track_z, + vehicle->track_x, vehicle->track_y, vehicle->track_z >> 3, trackType, 0 ); sint16 x, y, z; @@ -6709,7 +6718,7 @@ loc_6DC743: z = 7; } } - if (trackType == 6) { + if (z == 6) { rct_peep *peep = GET_PEEP(vehicle->peep[0]); if (peep->id & 7) { z = 8; @@ -6774,7 +6783,8 @@ loc_6DC8A1: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { - sub_6DD078(vehicle, vehicle->var_44); + regs.bp = vehicle->var_44; + sub_6DD078(vehicle, ®s.bp); } } goto loc_6DC99A; @@ -6823,7 +6833,7 @@ loc_6DCA9A: RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; mapElement = map_get_track_element_at_of_type_seq( - vehicle->track_x, vehicle->track_y, vehicle->track_z, + vehicle->track_x, vehicle->track_y, vehicle->track_z >> 3, trackType, 0 ); { @@ -6913,8 +6923,8 @@ loc_6DCC2C: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { - if (sub_6DD078(vehicle, vehicle->var_44)) { - regs.bp = vehicle->var_44; + regs.bp = vehicle->var_44; + if (sub_6DD078(vehicle, ®s.bp)) { goto loc_6DCD6B; } } @@ -7042,7 +7052,7 @@ loc_6DCEFF: } vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); - regs.ebx /= regs.eax; + regs.eax /= regs.ebx; regs.ecx = (regs.eax * 21) >> 9; regs.eax = vehicle->velocity >> 12; regs.ecx -= regs.eax; From 306855fd3e503bb9a9379337c891598502a8ce56 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Fri, 18 Dec 2015 21:05:49 +0000 Subject: [PATCH 132/162] Fix doors corrupting elements --- src/ride/vehicle.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 72db1b74a3..d3a84cc417 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -5269,13 +5269,13 @@ static void vehicle_update_scenery_door(rct_vehicle *vehicle) } if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { - mapElement->properties.fence.item[3] &= 7; - mapElement->properties.fence.item[3] |= 8; + mapElement->properties.fence.item[2] &= 7; + mapElement->properties.fence.item[2] |= 8; map_animation_create(MAP_ANIMATION_TYPE_WALL_UNKNOWN, x, y, z); vehicle_play_scenery_door_open_sound(vehicle, mapElement); } else { - mapElement->properties.fence.item[3] &= 7; - mapElement->properties.fence.item[3] |= 0x30; + mapElement->properties.fence.item[2] &= 7; + mapElement->properties.fence.item[2] |= 0x30; vehicle_play_scenery_door_close_sound(vehicle, mapElement); } } @@ -5352,13 +5352,13 @@ static void sub_6DEDE8(rct_vehicle *vehicle) } if (vehicle->next_vehicle_on_train != SPRITE_INDEX_NULL) { - mapElement->properties.fence.item[3] &= 7; - mapElement->properties.fence.item[3] |= 0x88; + mapElement->properties.fence.item[2] &= 7; + mapElement->properties.fence.item[2] |= 0x88; map_animation_create(MAP_ANIMATION_TYPE_WALL_UNKNOWN, x, y, z); vehicle_play_scenery_door_open_sound(vehicle, mapElement); } else { - mapElement->properties.fence.item[3] &= 7; - mapElement->properties.fence.item[3] |= 0xB0; + mapElement->properties.fence.item[2] &= 7; + mapElement->properties.fence.item[2] |= 0xB0; vehicle_play_scenery_door_close_sound(vehicle, mapElement); } } From 09ac928fd63d433c5d2b0cbf1ebd06987d9d15b8 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 20 Dec 2015 12:30:10 +0000 Subject: [PATCH 133/162] implement sub_6D63D4 --- src/ride/vehicle.c | 248 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 216 insertions(+), 32 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index d3a84cc417..38f53aab09 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -101,6 +101,11 @@ const uint8 DoorCloseSoundIds[] = { SOUND_62 }; +void vehicle_invalidate(rct_vehicle *vehicle) +{ + invalidate_sprite_2((rct_sprite*)vehicle); +} + /** * * rct2: 0x006BB9FF @@ -562,7 +567,7 @@ static int vehicle_close_restraints(rct_vehicle* vehicle){ } vehicle->restraints_position -= 20; } - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); ebp++; } while ((vehicle_id = vehicle->next_vehicle_on_train) != 0xFFFF); @@ -608,7 +613,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ vehicle->var_BA += value; vehicle->var_B6 -= value; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); continue; } } @@ -619,7 +624,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ vehicle->var_C8 = vehicle->var_C8 + 0x3333 - 0xFFFF; vehicle->var_C5++; vehicle->var_C5 &= 7; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } else{ vehicle->var_C8 += 0x3333; @@ -661,7 +666,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ continue; } vehicle->restraints_position += 20; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); ebp++; } @@ -1313,7 +1318,7 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle* vehicle){ vehicle->sub_state = 1; vehicle->var_C0 = 0; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); return; } else if (vehicle->sub_state == 1){ @@ -1476,7 +1481,7 @@ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { if (vehicleEntry->flags_a & VEHICLE_ENTRY_FLAG_A_7 && vehicle->var_C5 != 1) { vehicle->var_C5 = 1; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } vehicle_update_motion_bumper_car(vehicle); @@ -1490,7 +1495,7 @@ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { return; vehicle->var_C5 = 0; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); vehicle->velocity = 0; vehicle->var_2C = 0; vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; @@ -2079,7 +2084,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (vehicle_next_tower_element_is_top(vehicle) == false) { if (ride->mode == RIDE_MODE_FREEFALL_DROP) - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); return; } @@ -2353,7 +2358,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { vehicle->var_C5++; vehicle->velocity = 0; vehicle->var_2C = 0; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); return; } @@ -2940,7 +2945,7 @@ static void vehicle_update_swinging(rct_vehicle* vehicle) { return; // Used to know which sprite to draw vehicle->var_1F = al; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); return; } @@ -3013,7 +3018,7 @@ static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle) { if (rotation == vehicle->sub_state) vehicle->var_CE++; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); uint8 subState = vehicle->sub_state; if (ride->mode & RIDE_MODE_FORWARD_ROTATION) @@ -3071,7 +3076,7 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { if (al == vehicle->var_1F) return; vehicle->var_1F = al; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); return; } @@ -3115,7 +3120,7 @@ static void vehicle_update_rotating(rct_vehicle* vehicle) { if (al == vehicle->var_1F) return; vehicle->var_1F = al; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); return; } @@ -3175,7 +3180,7 @@ static void vehicle_update_space_rings_operating(rct_vehicle* vehicle) { if (al == vehicle->var_1F) return; vehicle->var_1F = al; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); return; } @@ -3196,7 +3201,7 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { if (vehicle->var_1F != 0) { if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 1) { vehicle->var_1F++; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); if (vehicle->var_1F == 19) vehicle->var_1F = 0; @@ -3225,7 +3230,7 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { break; case 75: vehicle->var_1F = 1; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); break; case 400: audio_play_sound_at_location( @@ -3243,7 +3248,7 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { break; case 775: vehicle->var_1F = 1; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); break; case 1100: audio_play_sound_at_location( @@ -3289,12 +3294,12 @@ static void vehicle_update_top_spin_operating(rct_vehicle* vehicle) { vehicle->var_4C = (sint16)vehicle->var_4C + 1; if (al != vehicle->var_1F) { vehicle->var_1F = al; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } al = edi[vehicle->var_4C * 2 + 1]; if (al != vehicle->var_20) { vehicle->var_20 = al; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } return; } @@ -3496,7 +3501,7 @@ static void vehicle_crash_on_land(rct_vehicle* vehicle) { vehicle->sprite_height_positive = 5; sprite_move(vehicle->x, vehicle->y, vehicle->z, (rct_sprite*)vehicle); - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); vehicle->var_4E = 0; } @@ -3548,7 +3553,7 @@ static void vehicle_crash_on_water(rct_vehicle* vehicle) { vehicle->sprite_height_positive = 5; sprite_move(vehicle->x, vehicle->y, vehicle->z, (rct_sprite*)vehicle); - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); vehicle->var_4E = 0xFFFF; } @@ -4442,7 +4447,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { vehicle->sprite_direction -= 2; } vehicle->sprite_direction &= 0x1E; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } else if ((scenario_rand() & 0xFFFF) <= 2849) { if (vehicle->var_35 & (1 << 6)) @@ -4450,7 +4455,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { else vehicle->sprite_direction += 2; vehicle->sprite_direction &= 0x1E; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } } @@ -4472,14 +4477,14 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { location.y += RCT2_ADDRESS(0x009A36CE, sint16)[oldC4 * 4]; if (!vehicle_update_bumper_car_collision(vehicle, location.x, location.y, &collideSprite)) { - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); sprite_move( location.x, location.y, location.z, (rct_sprite*)vehicle ); - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } } @@ -4492,7 +4497,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { unk_F64E20->y = vehicle->y; unk_F64E20->z = vehicle->z; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); while (1) { vehicle->var_35++; @@ -4545,7 +4550,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { unk_F64E20->z, (rct_sprite*)vehicle ); - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } sint32 eax = vehicle->velocity / 2; @@ -5202,16 +5207,195 @@ static void vehicle_update_spinning_car(rct_vehicle *vehicle) vehicle->var_B6 = unk; vehicle->var_BA += unk >> 8; vehicle->var_B6 -= unk >> vehicleEntry->spinning_friction; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); } +/** + * + * rct2: 0x006734B2 + */ +static void sub_6734B2(sint16 x, sint16 y, sint16 z) +{ + RCT2_CALLPROC_X(0x006734B2, x, 0, y, z, 0, 0, 0); +} + +static const struct { sint8 x, y, z; } byte_9A3A20[] = { + { -11, 0, 22 }, + { -10, 4, 22 }, + { -8, 8, 22 }, + { -4, 10, 22 }, + { 0, 11, 22 }, + { 4, 10, 22 }, + { 8, 8, 22 }, + { 10, 4, 22 }, + { 11, 0, 22 }, + { 10, -4, 22 }, + { 8, -8, 22 }, + { 4, -10, 22 }, + { 0, -11, 22 }, + { -4, -10, 22 }, + { -8, -8, 22 }, + { -10, -4, 22 }, + { -9, 0, 27 }, + { -8, 4, 27 }, + { -6, 6, 27 }, + { -4, 8, 27 }, + { 0, 9, 27 }, + { 4, 8, 27 }, + { 6, 6, 27 }, + { 8, 4, 27 }, + { 9, 0, 27 }, + { 8, -4, 27 }, + { 6, -6, 27 }, + { 4, -8, 27 }, + { 0, -9, 27 }, + { -4, -8, 27 }, + { -6, -6, 27 }, + { -8, -4, 27 }, + { -13, 0, 18 }, + { -12, 4, 17 }, + { -9, 9, 17 }, + { -4, 8, 17 }, + { 0, 13, 18 }, + { 4, 8, 17 }, + { 6, 6, 17 }, + { 8, 4, 17 }, + { 13, 0, 18 }, + { 8, -4, 17 }, + { 6, -6, 17 }, + { 4, -8, 17 }, + { 0, -13, 18 }, + { -4, -8, 17 }, + { -6, -6, 17 }, + { -8, -4, 17 } +}; + /** * * rct2: 0x006D63D4 */ static void sub_6D63D4(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006D63D4, 0, 0, 0, 0, (int)vehicle, 0, 0); + uint8 al, ah; + uint32 eax; + + uint32 *var_C8 = (uint32*)&vehicle->var_C8; + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + switch (vehicleEntry->var_11) { + case 1: // loc_6D652B + *var_C8 += RCT2_GLOBAL(0x00F64E08, uint32); + al = (*var_C8 >> 20) & 3; + if (vehicle->var_C5 != al) { + ah = al; + al = vehicle->var_C5; + vehicle->var_C5 = ah; + al &= 0x02; + ah &= 0x02; + if (al != ah) { + rct_ride *ride = GET_RIDE(vehicle->ride); + if (ride->entrance_style == RIDE_ENTRANCE_STYLE_PLAIN || + (vehicle->status != VEHICLE_STATUS_MOVING_TO_END_OF_STATION && + vehicle->status != VEHICLE_STATUS_ARRIVING) + ) { + int index = vehicle->sprite_direction >> 1; + if (vehicle->var_1F == 2) { + index += 16; + } + if (vehicle->var_1F == 6) { + index += 32; + } + sub_6734B2( + vehicle->x + byte_9A3A20[index].x, + vehicle->y + byte_9A3A20[index].y, + vehicle->z + byte_9A3A20[index].z + ); + } + } + vehicle_invalidate(vehicle); + } + break; + case 2: // loc_6D6424 + *var_C8 += RCT2_GLOBAL(0x00F64E08, uint32); + al = (*var_C8 >> 18) & 2; + if (vehicle->var_C5 != al) { + vehicle->var_C5 = al; + vehicle_invalidate(vehicle); + } + break; + case 3: // loc_6D6482 + *var_C8 += RCT2_GLOBAL(0x00F64E08, uint32); + eax = ((*var_C8 >> 13) & 0xFF) * 6; + ah = (eax >> 8) & 0xFF; + if (vehicle->var_C5 != ah) { + vehicle->var_C5 = ah; + vehicle_invalidate(vehicle); + } + break; + case 4: // loc_6D64F7 + *var_C8 += RCT2_GLOBAL(0x00F64E08, uint32); + eax = ((*var_C8 >> 13) & 0xFF) * 7; + ah = (eax >> 8) & 0xFF; + if (vehicle->var_C5 != ah) { + vehicle->var_C5 = ah; + vehicle_invalidate(vehicle); + } + break; + case 5: // loc_6D6453 + *var_C8 += RCT2_GLOBAL(0x00F64E08, uint32); + al = (*var_C8 >> 19) & 1; + if (vehicle->var_C5 != al) { + vehicle->var_C5 = al; + vehicle_invalidate(vehicle); + } + break; + case 6: // loc_6D65C3 + if (vehicle->var_C8 <= 0xCCCC) { + vehicle->var_C8 += 0x3333; + } else { + vehicle->var_C8 += 0x3333; + vehicle->var_C8 += 1; + vehicle->var_C8 &= 7; + vehicle_invalidate(vehicle); + } + break; + case 7: // loc_6D63F5 + *var_C8 += RCT2_GLOBAL(0x00F64E08, uint32); + al = (*var_C8 >> 18) & 3; + if (vehicle->var_C5 != al) { + vehicle->var_C5 = al; + vehicle_invalidate(vehicle); + } + break; + case 8: // loc_6D64B6 + if (vehicle->num_peeps != 0) { + *var_C8 += RCT2_GLOBAL(0x00F64E08, uint32); + eax = ((*var_C8 >> 13) & 0xFF) << 2; + ah = (eax >> 8) & 0xFF; + if (vehicle->var_C5 != ah) { + vehicle->var_C5 = ah; + vehicle_invalidate(vehicle); + } + } + break; + case 9: // loc_6D65E1 + ah = vehicle->var_D9; + al = vehicle->var_D8; + if (al != ah) { + if (vehicle->var_C8 <= 0xCCCC) { + vehicle->var_C8 += 0x3333; + } else { + vehicle->var_C8 += 0x3333; + uint8 bl = al + 1; + if (al >= ah) { + bl -= 2; + } + vehicle->var_D8 = bl; + vehicle->var_C5 = (bl - 4) & 7; + vehicle_invalidate(vehicle); + } + } + break; + } } /** @@ -6532,7 +6716,7 @@ loc_6DC40E: unk_F64E20->x = vehicle->x; unk_F64E20->y = vehicle->y; unk_F64E20->z = vehicle->z; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); loc_6DC462: vehicle->var_D3 = 0; @@ -6821,7 +7005,7 @@ loc_6DCA7A: unk_F64E20->x = vehicle->x; unk_F64E20->y = vehicle->y; unk_F64E20->z = vehicle->z; - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); loc_6DCA9A: regs.ax = vehicle->track_progress - 1; @@ -6965,7 +7149,7 @@ loc_6DCD6B: loc_6DCDE4: sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)vehicle); - invalidate_sprite_2((rct_sprite*)vehicle); + vehicle_invalidate(vehicle); loc_6DCE02: vehicle->var_2C /= RCT2_GLOBAL(0x00F64E10, uint32); From c2c41ec11829f19202c1c93fd9006c944bea3746 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 20 Dec 2015 12:50:33 +0000 Subject: [PATCH 134/162] implement steam_particle_create --- src/ride/vehicle.c | 125 ++++++++++++++++++++++++--------------------- src/world/sprite.c | 27 ++++++---- src/world/sprite.h | 32 +++++++++++- 3 files changed, 115 insertions(+), 69 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 38f53aab09..a42f3a445d 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -101,6 +101,57 @@ const uint8 DoorCloseSoundIds[] = { SOUND_62 }; +static const struct { sint8 x, y, z; } SteamParticleOffsets[] = { + { -11, 0, 22 }, + { -10, 4, 22 }, + { -8, 8, 22 }, + { -4, 10, 22 }, + { 0, 11, 22 }, + { 4, 10, 22 }, + { 8, 8, 22 }, + { 10, 4, 22 }, + { 11, 0, 22 }, + { 10, -4, 22 }, + { 8, -8, 22 }, + { 4, -10, 22 }, + { 0, -11, 22 }, + { -4, -10, 22 }, + { -8, -8, 22 }, + { -10, -4, 22 }, + { -9, 0, 27 }, + { -8, 4, 27 }, + { -6, 6, 27 }, + { -4, 8, 27 }, + { 0, 9, 27 }, + { 4, 8, 27 }, + { 6, 6, 27 }, + { 8, 4, 27 }, + { 9, 0, 27 }, + { 8, -4, 27 }, + { 6, -6, 27 }, + { 4, -8, 27 }, + { 0, -9, 27 }, + { -4, -8, 27 }, + { -6, -6, 27 }, + { -8, -4, 27 }, + { -13, 0, 18 }, + { -12, 4, 17 }, + { -9, 9, 17 }, + { -4, 8, 17 }, + { 0, 13, 18 }, + { 4, 8, 17 }, + { 6, 6, 17 }, + { 8, 4, 17 }, + { 13, 0, 18 }, + { 8, -4, 17 }, + { 6, -6, 17 }, + { 4, -8, 17 }, + { 0, -13, 18 }, + { -4, -8, 17 }, + { -6, -6, 17 }, + { -8, -4, 17 } +}; + void vehicle_invalidate(rct_vehicle *vehicle) { invalidate_sprite_2((rct_sprite*)vehicle); @@ -5214,62 +5265,22 @@ static void vehicle_update_spinning_car(rct_vehicle *vehicle) * * rct2: 0x006734B2 */ -static void sub_6734B2(sint16 x, sint16 y, sint16 z) +static void steam_particle_create(sint16 x, sint16 y, sint16 z) { - RCT2_CALLPROC_X(0x006734B2, x, 0, y, z, 0, 0, 0); + rct_map_element *mapElement = map_get_surface_element_at(x >> 5, y >> 5); + if (mapElement != NULL && z > mapElement->base_height * 8) { + rct_steam_particle *steam = (rct_steam_particle*)create_sprite(2); + steam->sprite_width = 20; + steam->sprite_height_negative = 18; + steam->sprite_height_positive = 16; + steam->sprite_identifier = SPRITE_IDENTIFIER_MISC; + steam->misc_identifier = SPRITE_MISC_STEAM_PARTICLE; + steam->var_26 = 256; + steam->var_24 = 0; + sprite_move(x, y, z, (rct_sprite*)steam); + } } -static const struct { sint8 x, y, z; } byte_9A3A20[] = { - { -11, 0, 22 }, - { -10, 4, 22 }, - { -8, 8, 22 }, - { -4, 10, 22 }, - { 0, 11, 22 }, - { 4, 10, 22 }, - { 8, 8, 22 }, - { 10, 4, 22 }, - { 11, 0, 22 }, - { 10, -4, 22 }, - { 8, -8, 22 }, - { 4, -10, 22 }, - { 0, -11, 22 }, - { -4, -10, 22 }, - { -8, -8, 22 }, - { -10, -4, 22 }, - { -9, 0, 27 }, - { -8, 4, 27 }, - { -6, 6, 27 }, - { -4, 8, 27 }, - { 0, 9, 27 }, - { 4, 8, 27 }, - { 6, 6, 27 }, - { 8, 4, 27 }, - { 9, 0, 27 }, - { 8, -4, 27 }, - { 6, -6, 27 }, - { 4, -8, 27 }, - { 0, -9, 27 }, - { -4, -8, 27 }, - { -6, -6, 27 }, - { -8, -4, 27 }, - { -13, 0, 18 }, - { -12, 4, 17 }, - { -9, 9, 17 }, - { -4, 8, 17 }, - { 0, 13, 18 }, - { 4, 8, 17 }, - { 6, 6, 17 }, - { 8, 4, 17 }, - { 13, 0, 18 }, - { 8, -4, 17 }, - { 6, -6, 17 }, - { 4, -8, 17 }, - { 0, -13, 18 }, - { -4, -8, 17 }, - { -6, -6, 17 }, - { -8, -4, 17 } -}; - /** * * rct2: 0x006D63D4 @@ -5304,10 +5315,10 @@ static void sub_6D63D4(rct_vehicle *vehicle) if (vehicle->var_1F == 6) { index += 32; } - sub_6734B2( - vehicle->x + byte_9A3A20[index].x, - vehicle->y + byte_9A3A20[index].y, - vehicle->z + byte_9A3A20[index].z + steam_particle_create( + vehicle->x + SteamParticleOffsets[index].x, + vehicle->y + SteamParticleOffsets[index].y, + vehicle->z + SteamParticleOffsets[index].z ); } } diff --git a/src/world/sprite.c b/src/world/sprite.c index 40ec76621a..cb9f5bdac9 100644 --- a/src/world/sprite.c +++ b/src/world/sprite.c @@ -273,18 +273,23 @@ void move_sprite_to_list(rct_sprite *sprite, uint8 cl) * * rct2: 0x00673200 */ -static void sprite_misc_0_update(rct_sprite *sprite) +static void sprite_steam_particle_update(rct_steam_particle *steam) { - invalidate_sprite_2(sprite); + invalidate_sprite_2((rct_sprite*)steam); - int original_var24 = sprite->unknown.var_24; - sprite->unknown.var_24 += 0x5555; - if (sprite->unknown.var_24 < 0x5555) { - sprite_move(sprite->unknown.x, sprite->unknown.y, sprite->unknown.z + 1, sprite); + int original_var24 = steam->var_24; + steam->var_24 += 0x5555; + if (steam->var_24 < 0x5555) { + sprite_move( + steam->x, + steam->y, + steam->z + 1, + (rct_sprite*)steam + ); } - sprite->unknown.var_26 += 64; - if (sprite->unknown.var_26 >= (56 * 64)) { - sprite_remove(sprite); + steam->var_26 += 64; + if (steam->var_26 >= (56 * 64)) { + sprite_remove((rct_sprite*)steam); } } @@ -357,8 +362,8 @@ static void sprite_misc_5_update(rct_sprite *sprite) void sprite_misc_update(rct_sprite *sprite) { switch (sprite->unknown.misc_identifier) { - case SPRITE_MISC_0: - sprite_misc_0_update(sprite); + case SPRITE_MISC_STEAM_PARTICLE: + sprite_steam_particle_update((rct_steam_particle*)sprite); break; case SPRITE_MISC_MONEY_EFFECT: money_effect_update(&sprite->money_effect); diff --git a/src/world/sprite.h b/src/world/sprite.h index 89fdb512d2..db1a20dce5 100644 --- a/src/world/sprite.h +++ b/src/world/sprite.h @@ -282,6 +282,35 @@ typedef struct { uint16 var_26; } rct_crash_splash; +typedef struct { + uint8 sprite_identifier; // 0x00 + uint8 misc_identifier; // 0x01 + uint16 next_in_quadrant; // 0x02 + uint16 next; // 0x04 + uint16 previous; // 0x06 + uint8 linked_list_type_offset; // 0x08 Valid values are SPRITE_LINKEDLIST_OFFSET_... + // Height from center of sprite to bottom + uint8 sprite_height_negative; // 0x09 + uint16 sprite_index; // 0x0A + uint16 var_0C; + sint16 x; // 0x0E + sint16 y; // 0x10 + sint16 z; // 0x12 + // Width from center of sprite to edge + uint8 sprite_width; // 0x14 + // Height from center of sprite to top + uint8 sprite_height_positive; // 0x15 + sint16 sprite_left; // 0x16 + sint16 sprite_top; // 0x18 + sint16 sprite_right; // 0x1A + sint16 sprite_bottom; // 0x1C + uint8 sprite_direction; // 0x1E + uint8 pad_1F[3]; // 0x1F + uint16 name_string_idx; // 0x22 + uint16 var_24; + uint16 var_26; +} rct_steam_particle; + /** * Sprite structure. * size: 0x0100 @@ -298,10 +327,11 @@ typedef union { rct_money_effect money_effect; rct_crashed_vehicle_particle crashed_vehicle_particle; rct_crash_splash crash_splash; + rct_steam_particle steam_particle; } rct_sprite; enum { - SPRITE_MISC_0, + SPRITE_MISC_STEAM_PARTICLE, SPRITE_MISC_MONEY_EFFECT, SPRITE_MISC_CRASHED_VEHICLE_PARTICLE, SPRITE_MISC_3, // (related to vehicle crash, probably crash particles) From 98178c25601847e90d52f8e835083f739c614f61 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 20 Dec 2015 14:21:06 +0000 Subject: [PATCH 135/162] refactor callprocs in vehicle.c --- src/ride/vehicle.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index a42f3a445d..7829fadb3b 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1620,8 +1620,9 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { & RIDE_TYPE_FLAG_CAN_SYNCHRONISE_ADJACENT_STATIONS) { if (ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS) { if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT) { - if (RCT2_CALLPROC_X(0x006DE287, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100) + if (sub_6DE287(vehicle)) { return; + } } } } @@ -1776,6 +1777,15 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { } } +/** + * + * rct2: 0x006DE287 + */ +static bool sub_6DE287(rct_vehicle *vehicle) +{ + return RCT2_CALLPROC_X(0x006DE287, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100; +} + /** * * rct2: 0x006D9EB0 @@ -2963,7 +2973,8 @@ static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle) { * * rct2: 0x006D9820 */ -static void vehicle_update_travelling_boat(rct_vehicle* vehicle) { +static void vehicle_update_travelling_boat(rct_vehicle* vehicle) +{ vehicle_check_if_missing(vehicle); RCT2_CALLPROC_X(0x006DA717, 0, 0, 0, 0, (int)vehicle, 0, 0); } From 6825c8645f6bc8f7062c31469b07ca5bf078ee0a Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 20 Dec 2015 15:22:51 +0000 Subject: [PATCH 136/162] implement vehicle_update_swinging_car --- src/ride/vehicle.c | 223 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 222 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 7829fadb3b..8a6dbee93d 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -71,6 +71,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); static void vehicle_kill_all_passengers(rct_vehicle* vehicle); +static bool sub_6DE287(rct_vehicle *vehicle); #define NO_SCREAM 254 @@ -4896,14 +4897,234 @@ static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) } } +static int vehicle_get_swing_amount(rct_vehicle *vehicle) +{ + int trackType = vehicle->track_type >> 2; + switch (trackType) { + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES: + case TRACK_ELEM_BANKED_LEFT_QUARTER_TURN_5_TILES: + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_UP: + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_25_DEG_DOWN: + case TRACK_ELEM_LEFT_QUARTER_TURN_5_TILES_COVERED: + case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_LARGE: + case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_LARGE: + case TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_UP: + case TRACK_ELEM_LEFT_QUARTER_BANKED_HELIX_LARGE_DOWN: + case TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_UP: + case TRACK_ELEM_LEFT_QUARTER_HELIX_LARGE_DOWN: + case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_5_TILE_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_5_TILE_25_DEG_DOWN: + // loc_6D67E1 + return 14; + + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES: + case TRACK_ELEM_BANKED_RIGHT_QUARTER_TURN_5_TILES: + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_UP: + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_QUARTER_TURN_5_TILES_COVERED: + case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_LARGE: + case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_LARGE: + case TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_UP: + case TRACK_ELEM_RIGHT_QUARTER_BANKED_HELIX_LARGE_DOWN: + case TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_UP: + case TRACK_ELEM_RIGHT_QUARTER_HELIX_LARGE_DOWN: + case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_5_TILE_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_5_TILE_25_DEG_DOWN: + // loc_6D6804 + return -14; + + case TRACK_ELEM_S_BEND_LEFT: + case TRACK_ELEM_S_BEND_LEFT_COVERED: + // loc_6D67EF + if (vehicle->var_34 < 48) { + return 14; + } else { + return -15; + } + + case TRACK_ELEM_S_BEND_RIGHT: + case TRACK_ELEM_S_BEND_RIGHT_COVERED: + // loc_6D67CC + if (vehicle->var_34 < 48) { + return -14; + } else { + return 15; + } + + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_BANK: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_COVERED: + case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_UP_SMALL: + case TRACK_ELEM_LEFT_HALF_BANKED_HELIX_DOWN_SMALL: + case TRACK_ELEM_LEFT_BANK_TO_LEFT_QUARTER_TURN_3_TILES_25_DEG_UP: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_LEFT_BANK: + case TRACK_ELEM_LEFT_CURVED_LIFT_HILL: + case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_3_TILE_25_DEG_UP: + case TRACK_ELEM_LEFT_BANKED_QUARTER_TURN_3_TILE_25_DEG_DOWN: + // loc_6D67BE + return 13; + + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_BANK: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_COVERED: + case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_UP_SMALL: + case TRACK_ELEM_RIGHT_HALF_BANKED_HELIX_DOWN_SMALL: + case TRACK_ELEM_RIGHT_BANK_TO_RIGHT_QUARTER_TURN_3_TILES_25_DEG_UP: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_25_DEG_DOWN_TO_RIGHT_BANK: + case TRACK_ELEM_RIGHT_CURVED_LIFT_HILL: + case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_3_TILE_25_DEG_UP: + case TRACK_ELEM_RIGHT_BANKED_QUARTER_TURN_3_TILE_25_DEG_DOWN: + // loc_6D67B0 + return -13; + + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE: + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_UP: + case TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE_60_DEG_DOWN: + // loc_6D67A2 + return 12; + + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE: + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_UP: + case TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE_60_DEG_DOWN: + // loc_6D6794 + return -12; + + case TRACK_ELEM_LEFT_EIGHTH_TO_DIAG: + case TRACK_ELEM_LEFT_EIGHTH_TO_ORTHOGONAL: + case TRACK_ELEM_LEFT_EIGHTH_BANK_TO_DIAG: + case TRACK_ELEM_LEFT_EIGHTH_BANK_TO_ORTHOGONAL: + // loc_6D67D3 + return 15; + + case TRACK_ELEM_RIGHT_EIGHTH_TO_DIAG: + case TRACK_ELEM_RIGHT_EIGHTH_TO_ORTHOGONAL: + case TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_DIAG: + case TRACK_ELEM_RIGHT_EIGHTH_BANK_TO_ORTHOGONAL: + // loc_6D67F6 + return -15; + } +} + /** * * rct2: 0x006D6776 */ static void vehicle_update_swinging_car(rct_vehicle *vehicle) { + sint32 dword_F64E08 = RCT2_GLOBAL(0x00F64E08, sint32); + vehicle->var_4E = (-(sint16)vehicle->var_4C) >> 6; + int swingAmount = vehicle_get_swing_amount(vehicle); + if (swingAmount < 0) { + vehicle->var_4E -= dword_F64E08 >> (-swingAmount); + } else { + vehicle->var_4E += dword_F64E08 >> swingAmount; + } + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); - RCT2_CALLPROC_X(0x006D6776, 0, 0, 0, 0, (int)vehicle, (int)vehicleEntry, 0); + sint16 dx = 3185; + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_5) { + dx = 5006; + } + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_9) { + dx = 1820; + } + sint16 cx = -dx; + + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_11) { + dx = 5370; + cx = -5370; + + int trackType = vehicle->track_type >> 2; + switch (trackType) { + case TRACK_ELEM_BANKED_LEFT_QUARTER_TURN_5_TILES: + case TRACK_ELEM_LEFT_BANK: + case TRACK_ELEM_LEFT_QUARTER_TURN_3_TILES_BANK: + dx = 10831; + cx = -819; + break; + case TRACK_ELEM_BANKED_RIGHT_QUARTER_TURN_5_TILES: + case TRACK_ELEM_RIGHT_BANK: + case TRACK_ELEM_RIGHT_QUARTER_TURN_3_TILES_BANK: + dx = 819; + cx = -10831; + break; + } + + switch (trackType) { + case TRACK_ELEM_END_STATION: + case TRACK_ELEM_BEGIN_STATION: + case TRACK_ELEM_MIDDLE_STATION: + case TRACK_ELEM_BRAKES: + case TRACK_ELEM_BLOCK_BRAKES: + dx = 0; + cx = 0; + break; + } + + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_0) { + dx = 0; + cx = 0; + } + } + + vehicle->var_4C += vehicle->var_4E; + vehicle->var_4E -= vehicle->var_4E >> 5; + sint16 ax = vehicle->var_4C; + if (ax > dx) { + ax = dx; + vehicle->var_4E = 0; + } + if (ax < cx) { + ax = cx; + vehicle->var_4E = 0; + } + + vehicle->var_4C = ax; + uint8 bl = 11; + if (ax >= -10012) { + bl = 12; + if (ax <= 10012) { + bl = 9; + if (ax >= -8191) { + bl = 10; + if (ax <= 8191) { + bl = 7; + if (ax >= -6371) { + bl = 8; + if (ax <= 6371) { + bl = 5; + if (ax >= -4550) { + bl = 6; + if (ax <= 4550) { + bl = 3; + if (ax >= -2730) { + bl = 4; + if (ax <= 2730) { + ax = 1; + if (ax >= -910) { + bl = 2; + if (ax <= 910) { + bl = 0; + } + } + } + } + } + } + } + } + } + } + } + } + if (bl != vehicle->var_4A) { + vehicle->var_4A = bl; + vehicle_invalidate(vehicle); + } } #pragma region off_9A2E84 From 742fe96cdac317b3b819ad5d8569de7a3d7bc64c Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 20 Dec 2015 18:33:43 +0000 Subject: [PATCH 137/162] implement vehicle_can_depart_synchronised --- src/ride/vehicle.c | 145 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 140 insertions(+), 5 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 8a6dbee93d..4ca1f315fc 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -71,7 +71,7 @@ static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); static void vehicle_kill_all_passengers(rct_vehicle* vehicle); -static bool sub_6DE287(rct_vehicle *vehicle); +static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle); #define NO_SCREAM 254 @@ -1621,7 +1621,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { & RIDE_TYPE_FLAG_CAN_SYNCHRONISE_ADJACENT_STATIONS) { if (ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS) { if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT) { - if (sub_6DE287(vehicle)) { + if (vehicle_can_depart_synchronised(vehicle)) { return; } } @@ -1780,11 +1780,146 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { /** * - * rct2: 0x006DE287 + * rct2: 0x006DE1A4 */ -static bool sub_6DE287(rct_vehicle *vehicle) +static bool sub_6DE1A4(int x, int y, int z) { - return RCT2_CALLPROC_X(0x006DE287, 0, 0, 0, 0, (int)vehicle, 0, 0) & 0x100; + return RCT2_CALLPROC_X(0x006DE1A4, x, 0, y, z, 0, 0, 0) & 0x100; +} + +typedef struct { + uint8 ride_id; + uint8 station_id; + uint16 vehicle_id; +} rct_synchrnoised_vehicle; + +// 8 synchrnoised vehicle info +rct_synchrnoised_vehicle *_synchrnoisedVehicles = (rct_synchrnoised_vehicle*)0x00F64E4C; + +#define _lastSynchrnoisedVehicle RCT2_GLOBAL(0x00F64E48, rct_synchrnoised_vehicle*) +#define MaxSynchrnoisedVehicle ((rct_synchrnoised_vehicle*)0x00F64E6C) + +/** + * Checks whether a vehicle can depart a station when set to synchrnoise with adjacent stations. + * rct2: 0x006DE287 + * @param vehicle The vehicle waiting to depart. + * @returns true if the vehicle can depart (all adjacent trains are ready or broken down), otherwise false. + */ +static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle) +{ + rct_ride *ride = GET_RIDE(vehicle->ride); + int station = vehicle->current_station; + uint16 xy = ride->station_starts[station]; + int x = (xy & 0xFF) * 32; + int y = (xy >> 8) * 32; + int z = ride->station_heights[station]; + + rct_map_element *mapElement = map_get_track_element_at(x, y, z); + int direction = (mapElement->type + 1) & 3; + _lastSynchrnoisedVehicle = _synchrnoisedVehicles; + + while (_lastSynchrnoisedVehicle < MaxSynchrnoisedVehicle) { + x += TileDirectionDelta[direction].x; + y += TileDirectionDelta[direction].y; + if (!sub_6DE1A4(x, y, z)) { + break; + } + } + + while (_lastSynchrnoisedVehicle < MaxSynchrnoisedVehicle) { + x += TileDirectionDelta[direction].x; + y += TileDirectionDelta[direction].y; + if (!sub_6DE1A4(x, y, z)) { + break; + } + } + + if (_lastSynchrnoisedVehicle == _synchrnoisedVehicles) { + // No adjacent stations, allow depart + return true; + } + + for (rct_synchrnoised_vehicle *sv = _synchrnoisedVehicles; sv < _lastSynchrnoisedVehicle; sv++) { + if (ride_is_block_sectioned(ride)) { + if (!(ride->station_depart[sv->station_id] & 0x80)) { + sv = _synchrnoisedVehicles; + uint8 rideId = 0xFF; + for (; sv < _lastSynchrnoisedVehicle; sv++) { + if (rideId == 0xFF) { + rideId = sv->ride_id; + } + if (rideId != sv->ride_id) { + return true; + } + } + + ride = GET_RIDE(rideId); + for (int i = 0; i < ride->num_vehicles; i++) { + rct_vehicle *v = GET_VEHICLE(ride->vehicles[i]); + if (v->status != VEHICLE_STATUS_WAITING_TO_DEPART && v->velocity != 0) { + return true; + } + } + + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT; + return false; + } + } + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)) { + if (ride->status != RIDE_STATUS_CLOSED) { + if (sv->vehicle_id == SPRITE_INDEX_NULL) { + if (_lastSynchrnoisedVehicle > &_synchrnoisedVehicles[1]) { + return true; + } + uint8 someRideIndex = _synchrnoisedVehicles[0].ride_id; + // uint8 currentStation = _synchrnoisedVehicles[0].station_id + if (someRideIndex != vehicle->ride) { + return true; + } + + ride = GET_RIDE(someRideIndex); + int numAdjacentTrainsAtStation = 0; + int numTravelingTrains = 0; + int currentStation = vehicle->current_station; + for (int i = 0; i < ride->num_vehicles; i++) { + uint16 spriteIndex = ride->vehicles[i]; + if (spriteIndex != SPRITE_INDEX_NULL) { + rct_vehicle *otherVehicle = GET_VEHICLE(spriteIndex); + if (otherVehicle->status != VEHICLE_STATUS_TRAVELLING) { + if (currentStation == otherVehicle->current_station) { + if (otherVehicle->status == VEHICLE_STATUS_WAITING_TO_DEPART || + otherVehicle->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION + ) { + numAdjacentTrainsAtStation++; + } + } + } else { + numTravelingTrains++; + } + } + } + + int totalTrains = numAdjacentTrainsAtStation + numTravelingTrains; + if (totalTrains != ride->num_vehicles || numTravelingTrains >= ride->num_vehicles / 2) { + return true; + } else { + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT; + return false; + } + } + } + } + } + + for (rct_synchrnoised_vehicle *sv = _synchrnoisedVehicles; sv < _lastSynchrnoisedVehicle; sv++) { + if (sv->vehicle_id != SPRITE_INDEX_NULL) { + rct_vehicle *v = GET_VEHICLE(sv->vehicle_id); + v->update_flags &= ~VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT; + } + } + + vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT; + return false; } /** From c4d8b8c66537b1c2899d8293e9cd69035b241f78 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 20 Dec 2015 20:58:30 +0000 Subject: [PATCH 138/162] Fix sign issues with global constants. Fix fast backwards rides breaking speed calculations --- src/ride/cable_lift.c | 2 +- src/ride/vehicle.c | 46 ++++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/ride/cable_lift.c b/src/ride/cable_lift.c index c00d1663ca..69dcafc249 100644 --- a/src/ride/cable_lift.c +++ b/src/ride/cable_lift.c @@ -58,7 +58,7 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d z = z * 8; current->track_z = z; - z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); sprite_move(16, 16, z, (rct_sprite*)current); current->track_type = (TRACK_ELEM_CABLE_LIFT_HILL << 2) | (current->sprite_direction >> 3); diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 4ca1f315fc..98cf63f51a 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -5142,6 +5142,7 @@ static int vehicle_get_swing_amount(rct_vehicle *vehicle) // loc_6D67F6 return -15; } + return 0; } /** @@ -5155,7 +5156,8 @@ static void vehicle_update_swinging_car(rct_vehicle *vehicle) int swingAmount = vehicle_get_swing_amount(vehicle); if (swingAmount < 0) { vehicle->var_4E -= dword_F64E08 >> (-swingAmount); - } else { + } + else if (swingAmount > 0){ vehicle->var_4E += dword_F64E08 >> swingAmount; } @@ -6378,7 +6380,7 @@ loc_6DB706:; ); sint16 x = vehicle->track_x + moveInfo->x; sint16 y = vehicle->track_y + moveInfo->y; - sint16 z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + sint16 z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); trackType = vehicle->track_type >> 2; regs.ebx = 0; @@ -6411,7 +6413,7 @@ loc_6DB706:; } loc_6DB8A5: - regs.ebx = RCT2_ADDRESS(0x009A2930, uint32)[regs.ebx]; + regs.ebx = RCT2_ADDRESS(0x009A2930, sint32)[regs.ebx]; vehicle->var_24 -= regs.ebx; unk_F64E20->x = x; unk_F64E20->y = y; @@ -6443,7 +6445,7 @@ loc_6DB928: return true; } - regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[regs.ebx]; + regs.ebx = dword_9A2970[regs.ebx]; vehicle->var_2C += regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; goto loc_6DAEB9; @@ -6451,14 +6453,14 @@ loc_6DB928: loc_6DB94A: RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; regs.eax = vehicle->var_24 + 1; - RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; vehicle->var_24 = 0xFFFFFFFF; regs.ebx = vehicle->var_1F; return false; loc_6DB967: regs.eax = vehicle->var_24 + 1; - RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; vehicle->var_24 -= regs.eax; // Might need to be bp rather than vehicle, but hopefully not @@ -6677,13 +6679,13 @@ loc_6DBD42: x = vehicle->track_x + moveInfo->x; y = vehicle->track_y + moveInfo->y; - z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); regs.ebx = 0; if (x == unk_F64E20->x) { regs.ebx |= 1; } if (y == unk_F64E20->y) { regs.ebx |= 2; } if (z == unk_F64E20->z) { regs.ebx |= 4; } - vehicle->var_24 += RCT2_ADDRESS(0x009A2930, uint32)[regs.ebx]; + vehicle->var_24 += RCT2_ADDRESS(0x009A2930, sint32)[regs.ebx]; unk_F64E20->x = x; unk_F64E20->y = y; @@ -6712,22 +6714,22 @@ loc_6DBE3F: if ((sint32)vehicle->var_24 >= 0) { return true; } - regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[regs.ebx]; - vehicle->var_2C = regs.ebx; + regs.ebx = dword_9A2970[regs.ebx]; + vehicle->var_2C += regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; goto loc_6DBA33; loc_6DBE5E: RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; - regs.eax = (sint32)vehicle->var_24 - 0x368A; - RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + regs.eax = vehicle->var_24 - 0x368A; + RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; vehicle->var_24 -= regs.eax; regs.ebx = vehicle->var_1F; return false; loc_6DBE7F: regs.eax = vehicle->var_24 - 0x368A; - RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; vehicle->var_24 -= regs.eax; rct_vehicle *v3 = GET_VEHICLE(regs.bp); @@ -6836,7 +6838,7 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) if (car->var_24 < 0x368A) { break; } - regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[car->var_1F]; + regs.ebx = dword_9A2970[car->var_1F]; car->var_2C += regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; continue; @@ -6853,7 +6855,7 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) if (car->var_24 >= 0) { break; } - regs.ebx = RCT2_ADDRESS(0x009A2970, uint32)[car->var_1F]; + regs.ebx = dword_9A2970[car->var_1F]; car->var_2C = regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; continue; @@ -7083,7 +7085,7 @@ loc_6DC40E: regs.ebx = vehicle->var_1F; RCT2_GLOBAL(0x00F64E10, uint32) = 1; vehicle->var_2C = dword_9A2970[vehicle->var_1F]; - vehicle->var_24 = RCT2_GLOBAL(0x00F64E0C, uint32) + vehicle->var_24; + vehicle->var_24 = RCT2_GLOBAL(0x00F64E0C, sint32) + vehicle->var_24; if ((sint32)vehicle->var_24 < 0) { goto loc_6DCA7A; } @@ -7309,7 +7311,7 @@ loc_6DC743: loc_6DC8A1: x = vehicle->track_x + moveInfo->x; y = vehicle->track_y + moveInfo->y; - z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); // Investigate redundant code regs.ebx = 0; @@ -7369,7 +7371,7 @@ loc_6DC99A: loc_6DC9BC: RCT2_GLOBAL(0x00F64E18, uint32) |= 0x20; regs.eax = vehicle->var_24 + 1; - RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; vehicle->var_24 -= regs.eax; regs.ebx = vehicle->var_1F; goto loc_6DCD2B; @@ -7449,7 +7451,7 @@ loc_6DCC2C: moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, vehicle->track_progress); x = vehicle->track_x + moveInfo->x; y = vehicle->track_y + moveInfo->y; - z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8); + z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); // Investigate redundant code regs.ebx = 0; @@ -7496,21 +7498,21 @@ loc_6DCD2B: if (vehicle->var_24 >= 0) { goto loc_6DCDE4; } - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + vehicle->var_2C += dword_9A2970[vehicle->var_1F]; RCT2_GLOBAL(0x00F64E10, uint32)++; goto loc_6DCA9A; loc_6DCD4A: RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; regs.eax = vehicle->var_24 - 0x368A; - RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; vehicle->var_24 -= regs.eax; regs.ebx = vehicle->var_1F; goto loc_6DC99A; loc_6DCD6B: regs.eax = vehicle->var_24 - 0x368A; - RCT2_GLOBAL(0x00F64E0C, uint32) -= regs.eax; + RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; vehicle->var_24 -= regs.eax; rct_vehicle *vEBP = GET_VEHICLE(regs.bp); rct_vehicle *vEDI = RCT2_GLOBAL(0x00F64E04, uint32); From e14fa03be1ace1bb94fe43cb10f66d962fcace96 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 20 Dec 2015 21:36:11 +0000 Subject: [PATCH 139/162] Labelled remaining_distance. Relabelled acceleration/powered acceleration --- src/ride/cable_lift.c | 68 ++++++------- src/ride/cable_lift.h | 2 +- src/ride/ride.c | 8 +- src/ride/vehicle.c | 230 +++++++++++++++++++++--------------------- src/ride/vehicle.h | 6 +- 5 files changed, 157 insertions(+), 157 deletions(-) diff --git a/src/ride/cable_lift.c b/src/ride/cable_lift.c index 69dcafc249..973e82812d 100644 --- a/src/ride/cable_lift.c +++ b/src/ride/cable_lift.c @@ -9,7 +9,7 @@ static void cable_lift_update_departing(rct_vehicle *vehicle); static void cable_lift_update_travelling(rct_vehicle *vehicle); static void cable_lift_update_arriving(rct_vehicle *vehicle); -rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head) +rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 remaining_distance, bool head) { rct_ride *ride = GET_RIDE(rideIndex); rct_vehicle *current = &(create_sprite(1)->vehicle); @@ -22,16 +22,16 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d } current->is_child = head ? 0 : 1; current->var_44 = var_44; - current->var_24 = var_24; + current->remaining_distance = remaining_distance; current->sprite_width = 10; current->sprite_height_negative = 10; current->sprite_height_positive = 10; current->friction = 100; current->num_seats = 0; current->speed = 20; - current->acceleration = 80; + current->powered_acceleration = 80; current->velocity = 0; - current->var_2C = 0; + current->acceleration = 0; current->var_4A = 0; current->var_4C = 0; current->var_4E = 0; @@ -102,18 +102,18 @@ void cable_lift_update(rct_vehicle *vehicle) static void cable_lift_update_moving_to_end_of_station(rct_vehicle *vehicle) { if (vehicle->velocity >= -439800) - vehicle->var_2C = -2932; + vehicle->acceleration = -2932; if (vehicle->velocity < -439800) { vehicle->velocity -= vehicle->velocity / 16; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } if (!(cable_lift_update_track_motion(vehicle) & (1 << 0))) return; vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; } @@ -124,11 +124,11 @@ static void cable_lift_update_moving_to_end_of_station(rct_vehicle *vehicle) static void cable_lift_update_waiting_to_depart(rct_vehicle *vehicle) { if (vehicle->velocity >= -58640) - vehicle->var_2C = -14660; + vehicle->acceleration = -14660; if (vehicle->velocity < -58640) { vehicle->velocity -= vehicle->velocity / 16; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } cable_lift_update_track_motion(vehicle); @@ -146,7 +146,7 @@ static void cable_lift_update_waiting_to_depart(rct_vehicle *vehicle) return; vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_DEPARTING; vehicle->sub_state = 0; } @@ -175,7 +175,7 @@ static void cable_lift_update_travelling(rct_vehicle *vehicle) rct_vehicle* passengerVehicle = GET_VEHICLE(vehicle->var_C0); vehicle->velocity = min(passengerVehicle->velocity, 439800); - vehicle->var_2C = 0; + vehicle->acceleration = 0; if (passengerVehicle->update_flags & VEHICLE_UPDATE_FLAG_BROKEN_TRAIN) return; @@ -183,7 +183,7 @@ static void cable_lift_update_travelling(rct_vehicle *vehicle) return; vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_ARRIVING; vehicle->sub_state = 0; } @@ -203,7 +203,7 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); - for (; vehicle->var_24 >= 13962; RCT2_GLOBAL(0x00F64E10, uint32)++) { + for (; vehicle->remaining_distance >= 13962; RCT2_GLOBAL(0x00F64E10, uint32)++) { uint8 trackType = vehicle->track_type >> 2; if (trackType == TRACK_ELEM_CABLE_LIFT_HILL && vehicle->track_progress == 160) { @@ -270,7 +270,7 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { if (unk.z != unk_F64E20->z) bx |= (1 << 2); - vehicle->var_24 -= RCT2_ADDRESS(0x009A2930, sint32)[bx]; + vehicle->remaining_distance -= RCT2_ADDRESS(0x009A2930, sint32)[bx]; unk_F64E20->x = unk.x; unk_F64E20->y = unk.y; unk_F64E20->z = unk.z; @@ -279,8 +279,8 @@ bool sub_6DF01A_loop(rct_vehicle* vehicle) { vehicle->var_20 = moveInfo->var_08; vehicle->var_1F = moveInfo->var_07; - if (vehicle->var_24 >= 13962) { - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + if (vehicle->remaining_distance >= 13962) { + vehicle->acceleration += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; } } return true; @@ -290,7 +290,7 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { rct_ride* ride = GET_RIDE(vehicle->ride); rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); - for (; vehicle->var_24 < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { + for (; vehicle->remaining_distance < 0; RCT2_GLOBAL(0x00F64E10, uint32)++) { uint16 trackProgress = vehicle->track_progress - 1; const rct_vehicle_info *moveInfo; @@ -356,7 +356,7 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { if (unk.z != unk_F64E20->z) bx |= (1 << 2); - vehicle->var_24 += RCT2_ADDRESS(0x009A2930, sint32)[bx]; + vehicle->remaining_distance += RCT2_ADDRESS(0x009A2930, sint32)[bx]; unk_F64E20->x = unk.x; unk_F64E20->y = unk.y; unk_F64E20->z = unk.z; @@ -365,8 +365,8 @@ bool sub_6DF21B_loop(rct_vehicle* vehicle) { vehicle->var_20 = moveInfo->var_08; vehicle->var_1F = moveInfo->var_07; - if (vehicle->var_24 < 0) { - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + if (vehicle->remaining_distance < 0) { + vehicle->acceleration += RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; } } return true; @@ -387,7 +387,7 @@ int cable_lift_update_track_motion(rct_vehicle *cableLift) RCT2_GLOBAL(0x00F64E18, uint32) = 0; RCT2_GLOBAL(0x00F64E1C, uint32) = (uint32)-1; - cableLift->velocity += cableLift->var_2C; + cableLift->velocity += cableLift->acceleration; RCT2_GLOBAL(0x00F64E08, sint32) = cableLift->velocity; RCT2_GLOBAL(0x00F64E0C, sint32) = (cableLift->velocity / 1024) * 42; @@ -399,11 +399,11 @@ int cable_lift_update_track_motion(rct_vehicle *cableLift) RCT2_GLOBAL(0x00F64E00, rct_vehicle*) = frontVehicle; for (rct_vehicle* vehicle = frontVehicle;;) { - vehicle->var_2C = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; + vehicle->acceleration = RCT2_ADDRESS(0x009A2970, sint32)[vehicle->var_1F]; RCT2_GLOBAL(0x00F64E10, uint32) = 1; - vehicle->var_24 += RCT2_GLOBAL(0x00F64E0C, sint32); + vehicle->remaining_distance += RCT2_GLOBAL(0x00F64E0C, sint32); - if (vehicle->var_24 < 0 || vehicle->var_24 >= 13962) { + if (vehicle->remaining_distance < 0 || vehicle->remaining_distance >= 13962) { rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); unk_F64E20->x = vehicle->x; unk_F64E20->y = vehicle->y; @@ -411,15 +411,15 @@ int cable_lift_update_track_motion(rct_vehicle *cableLift) invalidate_sprite_2((rct_sprite*)vehicle); while (true) { - if (vehicle->var_24 < 0) { + if (vehicle->remaining_distance < 0) { if (sub_6DF21B_loop(vehicle) == true) { break; } else { RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); - RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 - 13962; - vehicle->var_24 = 13962; - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->remaining_distance - 13962; + vehicle->remaining_distance = 13962; + vehicle->acceleration += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; RCT2_GLOBAL(0x00F64E10, uint32)++; continue; } @@ -430,9 +430,9 @@ int cable_lift_update_track_motion(rct_vehicle *cableLift) } else { RCT2_GLOBAL(0x00F64E18, uint32) |= (1 << 5); - RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->var_24 + 1; - vehicle->var_24 = -1; - vehicle->var_2C += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; + RCT2_GLOBAL(0x00F64E0C, uint32) -= vehicle->remaining_distance + 1; + vehicle->remaining_distance = -1; + vehicle->acceleration += RCT2_ADDRESS(0x009A2970, uint32)[vehicle->var_1F]; RCT2_GLOBAL(0x00F64E10, uint32)++; } } @@ -445,7 +445,7 @@ int cable_lift_update_track_motion(rct_vehicle *cableLift) invalidate_sprite_2((rct_sprite*)vehicle); } - vehicle->var_2C /= RCT2_GLOBAL(0x00F64E10, uint32); + vehicle->acceleration /= RCT2_GLOBAL(0x00F64E10, uint32); if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { if (vehicle->next_vehicle_on_train == 0xFFFF) break; @@ -466,7 +466,7 @@ int cable_lift_update_track_motion(rct_vehicle *cableLift) rct_vehicle* vehicle = GET_VEHICLE(spriteId); vehicleCount++; frictionTotal += vehicle->friction; - var2CTotal += vehicle->var_2C; + var2CTotal += vehicle->acceleration; spriteId = vehicle->next_vehicle_on_train; } @@ -480,6 +480,6 @@ int cable_lift_update_track_motion(rct_vehicle *cableLift) edx >>= 4; ecx -= edx / frictionTotal; - cableLift->var_2C = ecx; + cableLift->acceleration = ecx; return RCT2_GLOBAL(0x00F64E18, uint32); } diff --git a/src/ride/cable_lift.h b/src/ride/cable_lift.h index 5da0d87b9b..46f65d035c 100644 --- a/src/ride/cable_lift.h +++ b/src/ride/cable_lift.h @@ -4,7 +4,7 @@ #include "../common.h" #include "vehicle.h" -rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 var_24, bool head); +rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, sint32 remaining_distance, bool head); void cable_lift_update(rct_vehicle *vehicle); int cable_lift_update_track_motion(rct_vehicle *cableLift); diff --git a/src/ride/ride.c b/src/ride/ride.c index abe78e93b6..33226294ff 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -4291,9 +4291,9 @@ void loc_6DDF9C(rct_ride *ride, rct_map_element *mapElement) car = train; while (true) { car->velocity = 0; - car->var_2C = 0; + car->acceleration = 0; car->var_4A = 0; - car->var_24 += 13962; + car->remaining_distance += 13962; uint16 spriteIndex = car->next_vehicle_on_train; if (spriteIndex == SPRITE_INDEX_NULL) { @@ -4482,10 +4482,10 @@ bool ride_create_cable_lift(int rideIndex, bool isApplying) uint16 var_44 = edx & 0xFFFF; edx = rol32(edx, 10) >> 1; ebx -= edx; - sint32 var_24 = ebx; + sint32 remaining_distance = ebx; ebx -= edx; - rct_vehicle *current = cable_lift_segment_create(rideIndex, x, y, z, direction, var_44, var_24, i == 0); + rct_vehicle *current = cable_lift_segment_create(rideIndex, x, y, z, direction, var_44, remaining_distance, i == 0); current->next_vehicle_on_train = SPRITE_INDEX_NULL; if (i == 0) { head = current; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 98cf63f51a..abd4e18308 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -763,7 +763,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) ride->time[test_segment]++; } - sint32 distance = abs(((vehicle->velocity + vehicle->var_2C) >> 10) * 42); + sint32 distance = abs(((vehicle->velocity + vehicle->acceleration) >> 10) * 42); if (vehicle->var_CE == 0){ ride->length[test_segment] += distance; } @@ -1048,7 +1048,7 @@ static void vehicle_update_measurements(rct_vehicle *vehicle) } } - sint32 distance = ((vehicle->velocity + vehicle->var_2C) >> 10) * 42; + sint32 distance = ((vehicle->velocity + vehicle->acceleration) >> 10) * 42; if (distance < 0)return; ride->sheltered_length += distance; @@ -1200,11 +1200,11 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ case RIDE_MODE_DOWNWARD_LAUNCH: case RIDE_MODE_FREEFALL_DROP: if (vehicle->velocity >= -131940){ - vehicle->var_2C = -3298; + vehicle->acceleration = -3298; } if (vehicle->velocity < -131940){ vehicle->velocity = vehicle->velocity / 16; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } eax = vehicle_update_track_motion(vehicle, &ebx); @@ -1230,7 +1230,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ case RIDE_MODE_CIRCUS_SHOW: vehicle->current_station = 0; vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); @@ -1242,12 +1242,12 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3)){ if (vehicle->velocity <= 131940){ - vehicle->var_2C = 3298; + vehicle->acceleration = 3298; } } if (vehicle->velocity > 131940){ vehicle->velocity = vehicle->velocity / 16; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } int station; @@ -1255,7 +1255,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ if (eax & (1 << 1)){ vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->sub_state++; if (ride->mode == RIDE_MODE_RACE && @@ -1277,7 +1277,7 @@ static void vehicle_update_moving_to_end_of_station(rct_vehicle *vehicle){ vehicle->current_station = station; vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_WAITING_FOR_PASSENGERS; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); @@ -1549,7 +1549,7 @@ static void vehicle_update_bumpcar_mode(rct_vehicle* vehicle) { vehicle->var_C5 = 0; vehicle_invalidate(vehicle); vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); @@ -2061,7 +2061,7 @@ static void vehicle_update_travelling_boat_hire_setup(rct_vehicle* vehicle) { vehicle->status = VEHICLE_STATUS_TRAVELLING_BOAT; vehicle_invalidate_window(vehicle); vehicle->sub_state = 0; - vehicle->var_24 += 27924; + vehicle->remaining_distance += 27924; vehicle_update_travelling_boat(vehicle); } @@ -2154,7 +2154,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { switch (ride->mode) { case RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE: if (vehicle->velocity >= -131940) - vehicle->var_2C = -3298; + vehicle->acceleration = -3298; break; case RIDE_MODE_POWERED_LAUNCH_PASSTROUGH: case RIDE_MODE_POWERED_LAUNCH: @@ -2163,18 +2163,18 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { case RIDE_MODE_UPWARD_LAUNCH: if (ride->type == RIDE_TYPE_AIR_POWERED_VERTICAL_COASTER) { if ((ride->launch_speed << 16) > vehicle->velocity) { - vehicle->var_2C = ride->launch_speed << 13; + vehicle->acceleration = ride->launch_speed << 13; } break; } if ((ride->launch_speed << 16) > vehicle->velocity) - vehicle->var_2C = ride->launch_speed << 12; + vehicle->acceleration = ride->launch_speed << 12; break; case RIDE_MODE_DOWNWARD_LAUNCH: if (vehicle->var_CE >= 1) { if ((14 << 16) > vehicle->velocity) - vehicle->var_2C = 14 << 12; + vehicle->acceleration = 14 << 12; break; } // Fall through @@ -2187,7 +2187,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { break; if (vehicle->velocity <= 131940) - vehicle->var_2C = 3298; + vehicle->acceleration = 3298; break; } @@ -2222,7 +2222,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { if (ride->mode != RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE) { sint32 speed = ride->lift_hill_speed * 31079; if (vehicle->velocity <= speed) { - vehicle->var_2C = 15539; + vehicle->acceleration = 15539; if (vehicle->velocity != 0) { if (RCT2_GLOBAL(0x00F64E34, uint8) == BREAKDOWN_SAFETY_CUT_OUT) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; @@ -2236,7 +2236,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { else { sint32 speed = ride->lift_hill_speed * -31079; if (vehicle->velocity >= speed) { - vehicle->var_2C = -15539; + vehicle->acceleration = -15539; if (vehicle->velocity != 0) { if (RCT2_GLOBAL(0x00F64E34, uint8) == BREAKDOWN_SAFETY_CUT_OUT) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; @@ -2543,7 +2543,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { if (vehicle->sub_state == 2) { vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->var_C0--; if (vehicle->var_C0 == 0) vehicle->sub_state = 0; @@ -2554,7 +2554,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { vehicle->var_C5++; vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle_invalidate(vehicle); return; } @@ -2627,7 +2627,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { if (vehicle->sub_state == 0) { if (vehicle->velocity >= -131940) - vehicle->var_2C = -3298; + vehicle->acceleration = -3298; vehicle->velocity = max(vehicle->velocity, -131940); } else { @@ -2638,7 +2638,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { } else { if (vehicle->velocity <= 131940) - vehicle->var_2C = 3298; + vehicle->acceleration = 3298; } } } @@ -2651,7 +2651,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_12)) { if (vehicle->velocity >= ride->lift_hill_speed * -31079) { - vehicle->var_2C = -15539; + vehicle->acceleration = -15539; if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) { vehicle->var_B8 &= ~(1 << 1); @@ -2664,7 +2664,7 @@ static void vehicle_update_travelling(rct_vehicle* vehicle) { else { vehicle->var_B8 |= (1 << 1); if (vehicle->velocity <= ride->lift_hill_speed * 31079) { - vehicle->var_2C = 15539; + vehicle->acceleration = 15539; if (vehicle->velocity != 0) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; @@ -2728,7 +2728,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { case RIDE_MODE_CROOKED_HOUSE: vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_12; vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); @@ -2751,7 +2751,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { } if (vehicle->velocity <= 131940) { - vehicle->var_2C = 3298; + vehicle->acceleration = 3298; goto loc_6D8E36; } @@ -2771,12 +2771,12 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { } } vehicle->velocity -= velocity_diff; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } else { if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3) && vehicle->velocity >= -131940) { - vehicle->var_2C = -3298; + vehicle->acceleration = -3298; } if (vehicle->velocity >= -131940) { @@ -2799,7 +2799,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { if (vehicle->num_laps + 1 != ride->num_circuits) { vehicle->velocity -= velocity_diff; - vehicle->var_2C = 0; + vehicle->acceleration = 0; goto loc_6D8E36; } @@ -2810,7 +2810,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { } else{ vehicle->velocity -= velocity_diff; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } } @@ -2887,7 +2887,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { vehicle->y, vehicle->z); vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_DEPARTING; vehicle->sub_state = 1; vehicle_invalidate_window(vehicle); @@ -2904,7 +2904,7 @@ static void vehicle_update_arriving(rct_vehicle* vehicle) { vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_12; vehicle->velocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; vehicle->status = VEHICLE_STATUS_UNLOADING_PASSENGERS; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); @@ -3070,7 +3070,7 @@ static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle) { rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; if (vehicle->velocity <= 439800) { - vehicle->var_2C = 4398; + vehicle->acceleration = 4398; } int flags = vehicle_update_track_motion(vehicle, NULL); @@ -4619,7 +4619,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { RCT2_GLOBAL(0x00F64E18, uint32) = 0; rct_ride* ride = GET_RIDE(vehicle->ride); - sint32 nextVelocity = vehicle->velocity + vehicle->var_2C; + sint32 nextVelocity = vehicle->velocity + vehicle->acceleration; if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN) && ride->breakdown_reason_pending == BREAKDOWN_SAFETY_CUT_OUT) { nextVelocity = 0; @@ -4630,7 +4630,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { RCT2_GLOBAL(0x00F64E0C, sint32) = (nextVelocity / 1024) * 42; RCT2_GLOBAL(0x00F64E10, uint32) = 1; - vehicle->var_2C = 0; + vehicle->acceleration = 0; if (!(ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) || ride->breakdown_reason_pending != BREAKDOWN_SAFETY_CUT_OUT) { if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 1 && @@ -4686,9 +4686,9 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { } } - vehicle->var_24 += RCT2_GLOBAL(0x00F64E0C, sint32); + vehicle->remaining_distance += RCT2_GLOBAL(0x00F64E0C, sint32); - if (vehicle->var_24 >= 13962) { + if (vehicle->remaining_distance >= 13962) { vehicle->var_B8 &= ~(1 << 1); rct_xyz16 *unk_F64E20 = RCT2_ADDRESS(0x00F64E20, rct_xyz16); unk_F64E20->x = vehicle->x; @@ -4709,18 +4709,18 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { if (vehicle_update_bumper_car_collision(vehicle, location.x, location.y, &collideSprite)) break; - vehicle->var_24 -= RCT2_ADDRESS(0x009A36C8, sint16)[direction * 4]; + vehicle->remaining_distance -= RCT2_ADDRESS(0x009A36C8, sint16)[direction * 4]; unk_F64E20->x = location.x; unk_F64E20->y = location.y; - if (vehicle->var_24 < 13962) { + if (vehicle->remaining_distance < 13962) { break; } RCT2_GLOBAL(0x00F64E10, uint32)++; } - if (vehicle->var_24 >= 13962) { + if (vehicle->remaining_distance >= 13962) { sint32 oldVelocity = vehicle->velocity; - vehicle->var_24 = 0; + vehicle->remaining_distance = 0; vehicle->velocity = 0; uint8 direction = vehicle->sprite_direction | 1; @@ -4763,7 +4763,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { rct_ride_type_vehicle* vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type]; if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3)) { - vehicle->var_2C = -eax; + vehicle->acceleration = -eax; return RCT2_GLOBAL(0x00F64E18, uint32); } @@ -4773,10 +4773,10 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { _eax = -_eax; } _eax -= vehicle->velocity; - _eax *= vehicle->acceleration * 2; + _eax *= vehicle->powered_acceleration * 2; _eax /= ebx; - vehicle->var_2C = _eax - eax; + vehicle->acceleration = _eax - eax; return RCT2_GLOBAL(0x00F64E18, uint32); } @@ -4917,7 +4917,7 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) velocity = 0; } vehicle->velocity = velocity; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } int trackType = vehicle->track_type >> 2; @@ -4956,16 +4956,16 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) if (trackType == TRACK_ELEM_BLOCK_BRAKES && vehicle->velocity >= 0) { if (vehicle->velocity <= 0x20364) { vehicle->velocity = 0x20364; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } else { vehicle->velocity -= vehicle->velocity >> 4; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } } return; } RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_10; - vehicle->var_2C = 0; + vehicle->acceleration = 0; if (vehicle->velocity <= 0x20000) { vehicle->velocity = 0; } @@ -4979,7 +4979,7 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) */ static void sub_6DAB4C_chunk_3(rct_vehicle *vehicle) { - sint32 nextVelocity = vehicle->var_2C + vehicle->velocity; + sint32 nextVelocity = vehicle->acceleration + vehicle->velocity; if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_7) { nextVelocity = 0; } @@ -4990,7 +4990,7 @@ static void sub_6DAB4C_chunk_3(rct_vehicle *vehicle) } if (vehicle->var_D2 >= 0) { nextVelocity = 0; - vehicle->var_2C = 0; + vehicle->acceleration = 0; } } vehicle->velocity = nextVelocity; @@ -6041,7 +6041,7 @@ void sub_6DBF3E(rct_vehicle *vehicle) { rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); - vehicle->var_2C = (uint32)((sint32)vehicle->var_2C / RCT2_GLOBAL(0x00F64E10, sint32)); + vehicle->acceleration = (uint32)((sint32)vehicle->acceleration / RCT2_GLOBAL(0x00F64E10, sint32)); if (vehicle->var_CD == 2) { return; } @@ -6297,10 +6297,10 @@ loc_6DAEB9: vehicleEntry = vehicle_get_vehicle_entry(vehicle); } if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0x40000) { - vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 8; + vehicle->acceleration = -RCT2_GLOBAL(0x00F64E08, sint32) * 8; } else if (RCT2_GLOBAL(0x00F64E08, sint32) < 0x20000) { - vehicle->var_2C = 0x50000; + vehicle->acceleration = 0x50000; } } else if (trackType == TRACK_ELEM_BRAKES) { @@ -6311,7 +6311,7 @@ loc_6DAEB9: )) { regs.eax = vehicle->var_CF << 16; if (regs.eax < RCT2_GLOBAL(0x00F64E08, sint32)) { - vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; + vehicle->acceleration = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; } else if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x0F)) { if (RCT2_GLOBAL(0x00F64E2C, uint8) == 0) { @@ -6325,13 +6325,13 @@ loc_6DAEB9: if ((trackType == TRACK_ELEM_FLAT && ride->type == RIDE_TYPE_REVERSE_FREEFALL_COASTER) || (trackType == TRACK_ELEM_POWERED_LIFT) ) { - vehicle->var_2C = RCT2_GLOBAL(0x0097CF40 + (ride->type * 8) + 7, uint8) << 16; + vehicle->acceleration = RCT2_GLOBAL(0x0097CF40 + (ride->type * 8) + 7, uint8) << 16; } if (trackType == TRACK_ELEM_BRAKE_FOR_DROP) { if (!vehicle->is_child) { if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_10)) { if (vehicle->track_progress >= 8) { - vehicle->var_2C = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; + vehicle->acceleration = -RCT2_GLOBAL(0x00F64E08, sint32) * 16; if (vehicle->track_progress >= 24) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_10; vehicle->var_D2 = 90; @@ -6414,7 +6414,7 @@ loc_6DB706:; loc_6DB8A5: regs.ebx = RCT2_ADDRESS(0x009A2930, sint32)[regs.ebx]; - vehicle->var_24 -= regs.ebx; + vehicle->remaining_distance -= regs.ebx; unk_F64E20->x = x; unk_F64E20->y = y; unk_F64E20->z = z; @@ -6441,27 +6441,27 @@ loc_6DB8A5: } loc_6DB928: - if (vehicle->var_24 < 0x368A) { + if (vehicle->remaining_distance < 0x368A) { return true; } regs.ebx = dword_9A2970[regs.ebx]; - vehicle->var_2C += regs.ebx; + vehicle->acceleration += regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; goto loc_6DAEB9; loc_6DB94A: RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; - regs.eax = vehicle->var_24 + 1; + regs.eax = vehicle->remaining_distance + 1; RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; - vehicle->var_24 = 0xFFFFFFFF; + vehicle->remaining_distance = 0xFFFFFFFF; regs.ebx = vehicle->var_1F; return false; loc_6DB967: - regs.eax = vehicle->var_24 + 1; + regs.eax = vehicle->remaining_distance + 1; RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; - vehicle->var_24 -= regs.eax; + vehicle->remaining_distance -= regs.eax; // Might need to be bp rather than vehicle, but hopefully not rct_vehicle *head = vehicle_get_head(GET_VEHICLE(regs.bp)); @@ -6500,7 +6500,7 @@ loc_6DBA33:; sint32 unkVelocity = RCT2_GLOBAL(0x00F64E08, sint32); if (unkVelocity > 0xFFF80000) { unkVelocity = abs(unkVelocity); - vehicle->var_2C = unkVelocity * 2; + vehicle->acceleration = unkVelocity * 2; } } @@ -6508,7 +6508,7 @@ loc_6DBA33:; regs.eax = -(vehicle->var_CF << 16); if (regs.eax <= RCT2_GLOBAL(0x00F64E08, sint32)) { regs.eax = RCT2_GLOBAL(0x00F64E08, sint32) * -4; - vehicle->var_2C = regs.eax; + vehicle->acceleration = regs.eax; } } @@ -6685,7 +6685,7 @@ loc_6DBD42: if (x == unk_F64E20->x) { regs.ebx |= 1; } if (y == unk_F64E20->y) { regs.ebx |= 2; } if (z == unk_F64E20->z) { regs.ebx |= 4; } - vehicle->var_24 += RCT2_ADDRESS(0x009A2930, sint32)[regs.ebx]; + vehicle->remaining_distance += RCT2_ADDRESS(0x009A2930, sint32)[regs.ebx]; unk_F64E20->x = x; unk_F64E20->y = y; @@ -6711,26 +6711,26 @@ loc_6DBD42: } loc_6DBE3F: - if ((sint32)vehicle->var_24 >= 0) { + if ((sint32)vehicle->remaining_distance >= 0) { return true; } regs.ebx = dword_9A2970[regs.ebx]; - vehicle->var_2C += regs.ebx; + vehicle->acceleration += regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; goto loc_6DBA33; loc_6DBE5E: RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; - regs.eax = vehicle->var_24 - 0x368A; + regs.eax = vehicle->remaining_distance - 0x368A; RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; - vehicle->var_24 -= regs.eax; + vehicle->remaining_distance -= regs.eax; regs.ebx = vehicle->var_1F; return false; loc_6DBE7F: - regs.eax = vehicle->var_24 - 0x368A; + regs.eax = vehicle->remaining_distance - 0x368A; RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; - vehicle->var_24 -= regs.eax; + vehicle->remaining_distance -= regs.eax; rct_vehicle *v3 = GET_VEHICLE(regs.bp); rct_vehicle *v4 = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); @@ -6767,9 +6767,9 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) ////////////////////////////////////////////////////////////////////////////////////////// regs.esi = (int)vehicle; - RCT2_CALLFUNC_Y(0x006DAB4C, ®s); - if (outStation != NULL) *outStation = regs.ebx; - return regs.eax; + //RCT2_CALLFUNC_Y(0x006DAB4C, ®s); + //if (outStation != NULL) *outStation = regs.ebx; + //return regs.eax; ////////////////////////////////////////////////////////////////////////////////////////// rct_ride *ride = GET_RIDE(vehicle->ride); @@ -6816,11 +6816,11 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_7) || (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_8)) { sub_6D63D4(car); } - car->var_2C = dword_9A2970[car->var_1F]; + car->acceleration = dword_9A2970[car->var_1F]; RCT2_GLOBAL(0x00F64E10, uint32) = 1; - regs.eax = RCT2_GLOBAL(0x00F64E0C, sint32) + car->var_24; - car->var_24 = regs.eax; + regs.eax = RCT2_GLOBAL(0x00F64E0C, sint32) + car->remaining_distance; + car->remaining_distance = regs.eax; car->var_B8 &= ~(1 << 1); unk_F64E20->x = car->x; @@ -6829,22 +6829,22 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) invalidate_sprite_2((rct_sprite*)car); while (true) { - if (car->var_24 < 0) { + if (car->remaining_distance < 0) { // Backward loop if (vehicle_update_track_motion_backwards(car, vehicleEntry, ride, rideEntry)) { break; } else { - if (car->var_24 < 0x368A) { + if (car->remaining_distance < 0x368A) { break; } regs.ebx = dword_9A2970[car->var_1F]; - car->var_2C += regs.ebx; + car->acceleration += regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; continue; } } - if (car->var_24 < 0x368A) { + if (car->remaining_distance < 0x368A) { // Location found goto loc_6DBF3E; } @@ -6852,11 +6852,11 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) break; } else { - if (car->var_24 >= 0) { + if (car->remaining_distance >= 0) { break; } regs.ebx = dword_9A2970[car->var_1F]; - car->var_2C = regs.ebx; + car->acceleration = regs.ebx; RCT2_GLOBAL(0x00F64E10, uint32)++; continue; } @@ -6893,7 +6893,7 @@ loc_6DC144: regs.ebx++; regs.dx |= vehicle->update_flags; regs.bp += vehicle->friction; - regs.eax += vehicle->var_2C; + regs.eax += vehicle->acceleration; uint16 spriteIndex = vehicle->next_vehicle_on_train; if (spriteIndex == SPRITE_INDEX_NULL) { @@ -6974,7 +6974,7 @@ loc_6DC23A: regs.eax = -regs.eax; } regs.eax -= vehicle->velocity; - regs.edx = vehicle->acceleration; + regs.edx = vehicle->powered_acceleration; regs.edx <<= 1; regs.eax *= regs.edx; regs.eax /= regs.ebx; @@ -7060,7 +7060,7 @@ loc_6DC316: } } - vehicle->var_2C = regs.ecx; + vehicle->acceleration = regs.ecx; regs.eax = RCT2_GLOBAL(0x00F64E18, uint32); regs.ebx = RCT2_GLOBAL(0x00F64E1C, uint32); @@ -7073,7 +7073,7 @@ loc_6DC316: loc_6DC3A7: RCT2_GLOBAL(0x00F64E04, rct_vehicle*) = vehicle; RCT2_GLOBAL(0x00F64E18, uint32) = 0; - vehicle->velocity += vehicle->var_2C; + vehicle->velocity += vehicle->acceleration; RCT2_GLOBAL(0x00F64E08, sint32) = vehicle->velocity; RCT2_GLOBAL(0x00F64E0C, sint32) = (vehicle->velocity >> 10) * 42; if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { @@ -7084,12 +7084,12 @@ loc_6DC3A7: loc_6DC40E: regs.ebx = vehicle->var_1F; RCT2_GLOBAL(0x00F64E10, uint32) = 1; - vehicle->var_2C = dword_9A2970[vehicle->var_1F]; - vehicle->var_24 = RCT2_GLOBAL(0x00F64E0C, sint32) + vehicle->var_24; - if ((sint32)vehicle->var_24 < 0) { + vehicle->acceleration = dword_9A2970[vehicle->var_1F]; + vehicle->remaining_distance = RCT2_GLOBAL(0x00F64E0C, sint32) + vehicle->remaining_distance; + if ((sint32)vehicle->remaining_distance < 0) { goto loc_6DCA7A; } - if ((sint32)vehicle->var_24 < 0x368A) { + if ((sint32)vehicle->remaining_distance < 0x368A) { goto loc_6DCE02; } vehicle->var_B8 &= ~(1 << 1); @@ -7325,9 +7325,9 @@ loc_6DC8A1: regs.ebx |= 4; } regs.ebx = 0x368A; - vehicle->var_24 -= regs.ebx; - if ((sint32)vehicle->var_24 < 0) { - vehicle->var_24 = 0; + vehicle->remaining_distance -= regs.ebx; + if ((sint32)vehicle->remaining_distance < 0) { + vehicle->remaining_distance = 0; } unk_F64E20->x = x; @@ -7355,24 +7355,24 @@ loc_6DC8A1: loc_6DC985: regs.ebx = 0; - vehicle->var_24 -= 0x368A; - if ((sint32)vehicle->var_24 < 0) { - vehicle->var_24 = 0; + vehicle->remaining_distance -= 0x368A; + if ((sint32)vehicle->remaining_distance < 0) { + vehicle->remaining_distance = 0; } loc_6DC99A: - if ((sint32)vehicle->var_24 < 0x368A) { + if ((sint32)vehicle->remaining_distance < 0x368A) { goto loc_6DCDE4; } - vehicle->var_2C = dword_9A2970[vehicle->var_1F]; + vehicle->acceleration = dword_9A2970[vehicle->var_1F]; RCT2_GLOBAL(0x00F64E10, uint32)++; goto loc_6DC462; loc_6DC9BC: RCT2_GLOBAL(0x00F64E18, uint32) |= 0x20; - regs.eax = vehicle->var_24 + 1; + regs.eax = vehicle->remaining_distance + 1; RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; - vehicle->var_24 -= regs.eax; + vehicle->remaining_distance -= regs.eax; regs.ebx = vehicle->var_1F; goto loc_6DCD2B; @@ -7465,9 +7465,9 @@ loc_6DCC2C: regs.ebx |= 4; } regs.ebx = 0x368A; - vehicle->var_24 -= regs.ebx; - if ((sint32)vehicle->var_24 < 0) { - vehicle->var_24 = 0; + vehicle->remaining_distance -= regs.ebx; + if ((sint32)vehicle->remaining_distance < 0) { + vehicle->remaining_distance = 0; } unk_F64E20->x = x; @@ -7495,25 +7495,25 @@ loc_6DCC2C: } loc_6DCD2B: - if (vehicle->var_24 >= 0) { + if (vehicle->remaining_distance >= 0) { goto loc_6DCDE4; } - vehicle->var_2C += dword_9A2970[vehicle->var_1F]; + vehicle->acceleration += dword_9A2970[vehicle->var_1F]; RCT2_GLOBAL(0x00F64E10, uint32)++; goto loc_6DCA9A; loc_6DCD4A: RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; - regs.eax = vehicle->var_24 - 0x368A; + regs.eax = vehicle->remaining_distance - 0x368A; RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; - vehicle->var_24 -= regs.eax; + vehicle->remaining_distance -= regs.eax; regs.ebx = vehicle->var_1F; goto loc_6DC99A; loc_6DCD6B: - regs.eax = vehicle->var_24 - 0x368A; + regs.eax = vehicle->remaining_distance - 0x368A; RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; - vehicle->var_24 -= regs.eax; + vehicle->remaining_distance -= regs.eax; rct_vehicle *vEBP = GET_VEHICLE(regs.bp); rct_vehicle *vEDI = RCT2_GLOBAL(0x00F64E04, uint32); regs.eax = abs(vEDI->velocity - vEBP->velocity); @@ -7532,7 +7532,7 @@ loc_6DCDE4: vehicle_invalidate(vehicle); loc_6DCE02: - vehicle->var_2C /= RCT2_GLOBAL(0x00F64E10, uint32); + vehicle->acceleration /= RCT2_GLOBAL(0x00F64E10, uint32); if (vehicle->var_CD == 2) { goto loc_6DCEB2; } @@ -7607,7 +7607,7 @@ loc_6DCEFF: regs.ebx++; regs.dx |= vehicle->update_flags; regs.bp += vehicle->friction; - regs.eax += vehicle->var_2C; + regs.eax += vehicle->acceleration; regs.si = vehicle->next_vehicle_on_train; if ((uint16)regs.si == SPRITE_INDEX_NULL) { break; @@ -7649,7 +7649,7 @@ loc_6DCEFF: regs.eax = -regs.eax; } regs.eax -= vehicle->velocity; - regs.edx = vehicle->acceleration; + regs.edx = vehicle->powered_acceleration; regs.edx <<= 1; regs.eax *= regs.edx; regs.eax = regs.eax / regs.ebx; @@ -7683,7 +7683,7 @@ loc_6DCEFF: regs.ecx += regs.eax; loc_6DD069: - vehicle->var_2C = regs.ecx; + vehicle->acceleration = regs.ecx; regs.eax = RCT2_GLOBAL(0x00F64E18, uint32); regs.ebx = RCT2_GLOBAL(0x00F64E1C, uint32); diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 87ef7c7974..484b49f768 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -106,9 +106,9 @@ typedef struct { uint8 var_1F; uint8 var_20; uint8 pad_21[3]; - sint32 var_24; + sint32 remaining_distance; // 0x24 sint32 velocity; // 0x28 - sint32 var_2C; + sint32 acceleration; // 0x2C uint8 ride; // 0x30 uint8 vehicle_type; // 0x31 rct_vehicle_colour colours; // 0x32 @@ -160,7 +160,7 @@ typedef struct { sint8 var_BF; uint16 var_C0; uint8 speed; // 0xC2 - uint8 acceleration; // 0xC3 + uint8 powered_acceleration; // 0xC3 uint8 var_C4; uint8 var_C5; uint8 pad_C6[0x2]; From 9d937b3475dec94bddd87ae938d43839f6042ba7 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 21 Dec 2015 09:19:35 +0000 Subject: [PATCH 140/162] Refactor of backwards get next track --- src/ride/vehicle.c | 90 +++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index abd4e18308..ae7514d4d0 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -6488,35 +6488,10 @@ loc_6DB967: } /** -* -* rct2: 0x006DBA33 -*/ -bool vehicle_update_track_motion_backwards(rct_vehicle *vehicle, rct_ride_type_vehicle* vehicleEntry, rct_ride* ride, rct_ride_type* rideEntry) { - registers regs = { 0 }; - -loc_6DBA33:; - uint16 trackType = vehicle->track_type >> 2; - if (trackType == TRACK_ELEM_FLAT && ride->type == RIDE_TYPE_REVERSE_FREEFALL_COASTER) { - sint32 unkVelocity = RCT2_GLOBAL(0x00F64E08, sint32); - if (unkVelocity > 0xFFF80000) { - unkVelocity = abs(unkVelocity); - vehicle->acceleration = unkVelocity * 2; - } - } - - if (trackType == TRACK_ELEM_BRAKES) { - regs.eax = -(vehicle->var_CF << 16); - if (regs.eax <= RCT2_GLOBAL(0x00F64E08, sint32)) { - regs.eax = RCT2_GLOBAL(0x00F64E08, sint32) * -4; - vehicle->acceleration = regs.eax; - } - } - - regs.ax = vehicle->track_progress - 1; - if (regs.ax != -1) { - goto loc_6DBD42; - } - + * + * rct2: 0x006DBAA6 + */ +bool vehicle_update_track_motion_backwards_get_new_track(rct_vehicle *vehicle, uint16 trackType, rct_ride* ride, rct_ride_type* rideEntry, uint16* progress) { RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_start; RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_start; rct_map_element* mapElement = map_get_track_element_at_of_type_seq( @@ -6560,8 +6535,7 @@ loc_6DBB08:; input.y = y; input.element = mapElement; if (track_block_get_next(&input, &output, &outputZ, &outputDirection)) { - regs.edi = output.element; - goto loc_6DBE5E; + return false; } mapElement = output.element; goto loc_6DBC3B; @@ -6573,23 +6547,24 @@ loc_6DBB7E:; { track_begin_end trackBeginEnd; if (!track_block_get_previous(x, y, mapElement, &trackBeginEnd)) { - goto loc_6DBE5E; + return false; } mapElement = trackBeginEnd.begin_element; trackType = mapElement->properties.track.type; - if (trackType == 211 || trackType == 212) { - goto loc_6DBE5E; + if (trackType == TRACK_ELEM_LEFT_REVERSER || + trackType == TRACK_ELEM_RIGHT_REVERSER) { + return false; } int trackColour = vehicle->update_flags >> 9; int bank = gTrackDefinitions[trackType].bank_end; - bank = track_get_actual_bank_2(ride->type, regs.al, bank); + bank = track_get_actual_bank_2(ride->type, trackColour, bank); int vAngle = gTrackDefinitions[trackType].vangle_end; if (RCT2_GLOBAL(0x00F64E36, uint8) != vAngle || RCT2_GLOBAL(0x00F64E37, uint8) != bank ) { - goto loc_6DBE5E; + return false; } // Update VEHICLE_UPDATE_FLAG_11 @@ -6667,19 +6642,52 @@ loc_6DBC3B: // There are two bytes before the move info list uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); - regs.ax = trackTotalProgress - 1; + *progress = trackTotalProgress - 1; +} + +/** + * + * rct2: 0x006DBA33 + */ +bool vehicle_update_track_motion_backwards(rct_vehicle *vehicle, rct_ride_type_vehicle* vehicleEntry, rct_ride* ride, rct_ride_type* rideEntry) { + registers regs = { 0 }; + +loc_6DBA33:; + uint16 trackType = vehicle->track_type >> 2; + if (trackType == TRACK_ELEM_FLAT && ride->type == RIDE_TYPE_REVERSE_FREEFALL_COASTER) { + sint32 unkVelocity = RCT2_GLOBAL(0x00F64E08, sint32); + if (unkVelocity > 0xFFF80000) { + unkVelocity = abs(unkVelocity); + vehicle->acceleration = unkVelocity * 2; + } + } + + if (trackType == TRACK_ELEM_BRAKES) { + regs.eax = -(vehicle->var_CF << 16); + if (regs.eax <= RCT2_GLOBAL(0x00F64E08, sint32)) { + regs.eax = RCT2_GLOBAL(0x00F64E08, sint32) * -4; + vehicle->acceleration = regs.eax; + } + } + + regs.ax = vehicle->track_progress - 1; + if (regs.ax == -1) { + if (!vehicle_update_track_motion_backwards_get_new_track(vehicle, trackType, ride, rideEntry, ®s.ax)) { + goto loc_6DBE5E; + } + } loc_6DBD42: vehicle->track_progress = regs.ax; - moveInfo = vehicle_get_move_info( + const rct_vehicle_info* moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, vehicle->track_progress ); - x = vehicle->track_x + moveInfo->x; - y = vehicle->track_y + moveInfo->y; - z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); + sint16 x = vehicle->track_x + moveInfo->x; + sint16 y = vehicle->track_y + moveInfo->y; + sint16 z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); regs.ebx = 0; if (x == unk_F64E20->x) { regs.ebx |= 1; } From 3b7839c0265054ee4ee2b137b42952ca143081d7 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 21 Dec 2015 18:26:41 +0000 Subject: [PATCH 141/162] implement try_add_synchronised_station --- src/ride/vehicle.c | 73 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index ae7514d4d0..373b36b43c 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -1778,15 +1778,6 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { } } -/** - * - * rct2: 0x006DE1A4 - */ -static bool sub_6DE1A4(int x, int y, int z) -{ - return RCT2_CALLPROC_X(0x006DE1A4, x, 0, y, z, 0, 0, 0) & 0x100; -} - typedef struct { uint8 ride_id; uint8 station_id; @@ -1799,6 +1790,66 @@ rct_synchrnoised_vehicle *_synchrnoisedVehicles = (rct_synchrnoised_vehicle*)0x0 #define _lastSynchrnoisedVehicle RCT2_GLOBAL(0x00F64E48, rct_synchrnoised_vehicle*) #define MaxSynchrnoisedVehicle ((rct_synchrnoised_vehicle*)0x00F64E6C) +/** + * Checks if a map position contains a synchrnoised ride station and adds the vehicle + * to synchrnoise to the vehicle synchronisation list. + * rct2: 0x006DE1A4 + */ +static bool try_add_synchronised_station(int x, int y, int z) +{ + bool foundMapElement = false; + rct_map_element *mapElement = map_get_first_element_at(x >> 5, y >> 5); + if (mapElement != NULL) { + do { + if (map_element_get_type(mapElement) != MAP_ELEMENT_TYPE_TRACK) continue; + if (z != mapElement->base_height && + z != mapElement->base_height - 2 && + z != mapElement->base_height + 2 + ) { + continue; + } + + foundMapElement = true; + break; + } while (!map_element_is_last_for_tile(mapElement++)); + } + if (!foundMapElement) { + return false; + } + + int rideIndex = mapElement->properties.track.ride_index; + rct_ride *ride = GET_RIDE(rideIndex); + if (!(ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS)) { + return false; + } + + int stationIndex = map_get_station(mapElement); + + rct_synchrnoised_vehicle *sv = _lastSynchrnoisedVehicle; + sv->ride_id = rideIndex; + sv->station_id = stationIndex; + sv->vehicle_id = SPRITE_INDEX_NULL; + _lastSynchrnoisedVehicle++; + + if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) { + return false; + } + + for (int i = 0; i < ride->num_vehicles; i++) { + uint16 spriteIndex = ride->vehicles[i]; + if (spriteIndex == SPRITE_INDEX_NULL) continue; + + rct_vehicle *vehicle = GET_VEHICLE(spriteIndex); + if (vehicle->status != VEHICLE_STATUS_WAITING_TO_DEPART) continue; + if (vehicle->sub_state != 0) continue; + if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT)) continue; + if (vehicle->current_station != stationIndex) continue; + + sv->vehicle_id = spriteIndex; + return true; + } +} + /** * Checks whether a vehicle can depart a station when set to synchrnoise with adjacent stations. * rct2: 0x006DE287 @@ -1821,7 +1872,7 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle) while (_lastSynchrnoisedVehicle < MaxSynchrnoisedVehicle) { x += TileDirectionDelta[direction].x; y += TileDirectionDelta[direction].y; - if (!sub_6DE1A4(x, y, z)) { + if (!try_add_synchronised_station(x, y, z)) { break; } } @@ -1829,7 +1880,7 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle) while (_lastSynchrnoisedVehicle < MaxSynchrnoisedVehicle) { x += TileDirectionDelta[direction].x; y += TileDirectionDelta[direction].y; - if (!sub_6DE1A4(x, y, z)) { + if (!try_add_synchronised_station(x, y, z)) { break; } } From bc24393239dcd875e0672620b8f9567fae5d1706 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Mon, 21 Dec 2015 21:33:17 +0000 Subject: [PATCH 142/162] implement vehicle_update_motion_boat_hire --- src/ride/vehicle.c | 316 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 312 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 373b36b43c..dfad0301e8 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -59,6 +59,9 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle); static void vehicle_update_top_spin_operating(rct_vehicle* vehicle); static void vehicle_update_crash(rct_vehicle *vehicle); static void vehicle_update_travelling_boat(rct_vehicle* vehicle); +static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle); +static void sub_6DA280(rct_vehicle *vehicle); +static bool vehicle_is_boat_on_water(rct_vehicle *vehicle, int x, int y); static void vehicle_update_arriving(rct_vehicle* vehicle); static void vehicle_update_unloading_passengers(rct_vehicle* vehicle); static void vehicle_update_waiting_for_cable_lift(rct_vehicle *vehicle); @@ -67,6 +70,8 @@ static void vehicle_update_crash_setup(rct_vehicle* vehicle); static void vehicle_update_collision_setup(rct_vehicle* vehicle); static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle); static bool vehicle_update_bumper_car_collision(rct_vehicle *vehicle, sint16 x, sint16 y, uint16 *spriteId); +static void sub_6D63D4(rct_vehicle *vehicle); +static bool sub_6DD078(rct_vehicle *vehicle, uint16* otherVehicleIndex); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -3163,7 +3168,307 @@ static void vehicle_update_travelling_cable_lift(rct_vehicle* vehicle) { static void vehicle_update_travelling_boat(rct_vehicle* vehicle) { vehicle_check_if_missing(vehicle); - RCT2_CALLPROC_X(0x006DA717, 0, 0, 0, 0, (int)vehicle, 0, 0); + vehicle_update_motion_boat_hire(vehicle); +} + +static void loc_6DA9F9(rct_vehicle *vehicle, int x, int y, int bx, int dx) +{ + vehicle->remaining_distance = 0; + // z = vehicle->z; + if (!sub_6DD078(vehicle, NULL)) { + vehicle->track_x = bx; + vehicle->track_y = dx; + + rct_map_element *mapElement = map_get_track_element_at( + vehicle->track_x, + vehicle->track_y, + vehicle->track_z >> 3 + ); + + rct_ride *ride = GET_RIDE(vehicle->ride); + vehicle->track_type = + (mapElement->properties.track.type << 2) | + (ride->boat_hire_return_direction & 3); + + vehicle->var_34 = 0; + vehicle->status = VEHICLE_STATUS_TRAVELLING; + unk_F64E20->x = x; + unk_F64E20->y = y; + } +} + +/** + * + * rct2: 0x006DA717 + */ +static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) +{ + // RCT2_CALLPROC_X(0x006DA717, 0, 0, 0, 0, (int)vehicle, 0, 0); + + //////////////////////////////////////////////// + // TODO fix bugs with this function + //////////////////////////////////////////////// + RCT2_GLOBAL(0x00F64E18, uint32) = 0; + vehicle->velocity += vehicle->acceleration; + RCT2_GLOBAL(0x00F64E08, sint32) = vehicle->velocity; + RCT2_GLOBAL(0x00F64E0C, sint32) = (vehicle->velocity >> 10) * 42; + + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + if (vehicleEntry->flags_b & (VEHICLE_ENTRY_FLAG_B_7 | VEHICLE_ENTRY_FLAG_B_8)) { + sub_6D63D4(vehicle); + } + + RCT2_GLOBAL(0x00F64E10, uint32) = 1; + vehicle->acceleration = 0; + vehicle->remaining_distance += RCT2_GLOBAL(0x00F64E0C, sint32); + if (vehicle->remaining_distance >= 0x368A) { + vehicle->var_B8 &= ~(1 << 1); + unk_F64E20->x = vehicle->x; + unk_F64E20->y = vehicle->y; + unk_F64E20->z = vehicle->z; + vehicle_invalidate(vehicle); + + for (;;) { + loc_6DA7A5: + vehicle->var_35++; + int x = (vehicle->boat_location.x * 32) + 16; + int y = (vehicle->boat_location.y * 32) + 16; + int z; + uint8 bl; + + x -= vehicle->x; + if (x >= 0) { + y -= vehicle->y; + if (y < 0) { + // loc_6DA81A: + y = -y; + bl = 24; + if (y <= x * 4) { + bl = 16; + if (x <= y * 4) { + bl = 20; + } + } + } else { + bl = 8; + if (y <= x * 4) { + bl = 16; + if (x <= y * 4) { + bl = 12; + } + } + } + } else { + y -= vehicle->y; + if (y < 0) { + // loc_6DA83D: + x = -x; + y = -y; + bl = 24; + if (y <= x * 4) { + bl = 0; + if (x <= y * 4) { + bl = 28; + } + } + } else { + x = -x; + bl = 8; + if (y <= x * 4) { + bl = 0; + if (x <= y * 4) { + bl = 4; + } + } + } + } + + // loc_6DA861: + vehicle->var_34 = bl; + x += y; + if (x <= 12) { + sub_6DA280(vehicle); + } + + if (!(vehicle->var_35 & (1 << 0))) { + uint8 spriteDirection = vehicle->sprite_direction; + if (spriteDirection != vehicle->var_34) { + uint8 dl = (vehicle->var_34 + 16 - spriteDirection) & 0x1E; + if (dl >= 16) { + spriteDirection += 2; + if (dl > 24) { + vehicle->var_35--; + } + } else { + spriteDirection -= 2; + if (dl < 8) { + vehicle->var_35--; + } + } + + vehicle->sprite_direction = spriteDirection & 0x1E; + } + } + + int edi = (vehicle->sprite_direction | (vehicle->var_35 & 1)) & 0x1F; + x = vehicle->x + RCT2_ADDRESS(0x009A36C4, sint16)[edi * 4]; + y = vehicle->y + RCT2_ADDRESS(0x009A36C6, sint16)[edi * 4]; + z = vehicle->z; + if (sub_6DD078(vehicle, NULL)) { + goto loc_6DAA79; + } + + int bx = floor2(x, 32); + int dx = floor2(y, 32); + if (bx != vehicle->track_x || dx != vehicle->track_y) { + if (vehicle_is_boat_on_water(vehicle, x, y)) { + // loc_6DA939: + rct_ride *ride = GET_RIDE(vehicle->ride); + + bool do_loc_6DAA97 = false; + if (vehicle->sub_state != 1) { + do_loc_6DAA97 = true; + } else { + uint16 xy = (((dx >> 5) << 8) | (bx >> 5)); + if (xy != ride->boat_hire_return_position) { + do_loc_6DAA97 = true; + } + } + + // loc_6DAA97: + if (do_loc_6DAA97) { + vehicle->remaining_distance = 0; + if (vehicle->sprite_direction == vehicle->var_34) { + sub_6DA280(vehicle); + } + goto loc_6DAAAB; + } + + if (!(ride->boat_hire_return_direction & 1)) { + uint16 bp = y & 0x1F; + if (bp == 16) { + loc_6DA9F9(vehicle, x, y, bx, dx); + goto loc_6DAAAB; + } + if (bp <= 16) { + x = unk_F64E20->x; + y = unk_F64E20->y + 1; + } else { + x = unk_F64E20->x; + y = unk_F64E20->y - 1; + } + } else { + // loc_6DA9A2: + uint16 bp = x & 0x1F; + if (bp == 16) { + loc_6DA9F9(vehicle, x, y, bx, dx); + goto loc_6DAAAB; + } + if (bp <= 16) { + x = unk_F64E20->x + 1; + y = unk_F64E20->y; + } else { + x = unk_F64E20->x - 1; + y = unk_F64E20->y; + } + } + + // loc_6DA9D1: + vehicle->remaining_distance = 0; + // z = vehicle->z; + if (!sub_6DD078(vehicle, NULL)) { + unk_F64E20->x = x; + unk_F64E20->y = y; + } + goto loc_6DAAAB; + } + vehicle->track_x = bx; + vehicle->track_y = dx; + } + + vehicle->remaining_distance = RCT2_ADDRESS(0x009A36C8, uint32)[edi * 2]; + unk_F64E20->x = x; + unk_F64E20->y = y; + if (vehicle->remaining_distance < 0x368A) { + goto loc_6DAAAB; + } + RCT2_GLOBAL(0x00F64E10, uint32)++; + } + + loc_6DAA79: + vehicle->remaining_distance = 0; + if (vehicle->sprite_direction == vehicle->var_34) { + vehicle->sprite_direction ^= (1 << 4); + sub_6DA280(vehicle); + vehicle->sprite_direction ^= (1 << 4); + } + + loc_6DAAAB: + sprite_move( + unk_F64E20->x, + unk_F64E20->y, + unk_F64E20->z, + (rct_sprite*)vehicle + ); + vehicle_invalidate(vehicle); + } + +// loc_6DAAC9: + { + int edx = vehicle->velocity >> 8; + edx = (edx * edx); + if (vehicle->velocity < 0) { + edx = -edx; + } + edx >>= 5; + int eax = ((vehicle->velocity >> 1) + edx) / vehicle->friction; + int ecx = -eax; + if (vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3) { + eax = vehicle->speed << 14; + int ebx = (vehicle->speed * vehicle->friction) >> 2; + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_3) { + eax = -eax; + } + eax -= vehicle->velocity; + edx = vehicle->powered_acceleration * 2; + ecx += (eax * edx) / ebx; + } + vehicle->acceleration = ecx; + } + // eax = RCT2_GLOBAL(0x00F64E18, uint32); + // ebx = RCT2_GLOBAL(0x00F64E1C, uint32); +} + + /** + * + * rct2: 0x006DA280 + */ +static void sub_6DA280(rct_vehicle *vehicle) +{ + RCT2_CALLPROC_X(0x006DA280, 0, 0, 0, 0, (int)vehicle, 0, 0); +} + + /** + * + * rct2: 0x006DA22A + */ +static bool vehicle_is_boat_on_water(rct_vehicle *vehicle, int x, int y) +{ + int z = vehicle->track_z >> 3; + rct_map_element *mapElement = map_get_first_element_at(x >> 5, y >> 5); + do { + if (map_element_get_type(mapElement) == MAP_ELEMENT_TYPE_SURFACE) { + int waterZ = (mapElement->properties.surface.terrain & 0x1F) * 2; + if (z != waterZ) { + return true; + } + } else { + if (z > mapElement->base_height - 2 && z < mapElement->clearance_height + 2) { + return true; + } + } + } while (!map_element_is_last_for_tile(mapElement++)); + return false; } /** @@ -6058,10 +6363,13 @@ static bool sub_6DD078(rct_vehicle *vehicle, uint16* otherVehicleIndex) { registers regs = { 0 }; regs.esi = vehicle; - regs.bp = *otherVehicleIndex; + if (otherVehicleIndex != NULL) { + regs.bp = *otherVehicleIndex; + } bool result = RCT2_CALLFUNC_Y(0x006DD078, ®s) & 0x100; - - *otherVehicleIndex = regs.bp; + if (otherVehicleIndex != NULL) { + *otherVehicleIndex = regs.bp; + } return result; } From 27d38c6f392667b1fccef9b8e129a06ce214a43a Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 21 Dec 2015 22:18:56 +0000 Subject: [PATCH 143/162] Fix incorrect comparison for backwards loop. --- src/ride/vehicle.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index dfad0301e8..5a57054bdc 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -7069,7 +7069,7 @@ loc_6DBD42: } if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { - if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { + if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { regs.bp = vehicle->next_vehicle_on_ride; if (sub_6DD078(vehicle, ®s.bp)) { goto loc_6DBE7F; @@ -7116,8 +7116,9 @@ loc_6DBE7F: RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } else { - vehicle->velocity = v3->velocity >> 1; + sint32 v3Velocity = v3->velocity; v3->velocity = v4->velocity >> 1; + v4->velocity = v3Velocity >> 1; RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; } From 7f6814951697137fafbd14e3dbb158d32ba6b946 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 22 Dec 2015 10:27:38 +0000 Subject: [PATCH 144/162] Minor Refactor --- src/ride/vehicle.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 5a57054bdc..d3d73bf937 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -7252,16 +7252,21 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) } loc_6DC144: vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); - regs.eax = 0; - regs.ebp = 0; + //eax + sint32 totalAcceleration = 0; + //ebp + sint32 totalFriction = 0; + //Not used regs.dx = 0; - regs.ebx = 0; + //ebx + int numVehicles = 0; for (;;) { - regs.ebx++; + numVehicles++; + // Not used? regs.dx |= vehicle->update_flags; - regs.bp += vehicle->friction; - regs.eax += vehicle->acceleration; + totalFriction += vehicle->friction; + totalAcceleration += vehicle->acceleration; uint16 spriteIndex = vehicle->next_vehicle_on_train; if (spriteIndex == SPRITE_INDEX_NULL) { @@ -7271,7 +7276,7 @@ loc_6DC144: } vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); - regs.eax = (regs.eax / regs.ebx) * 21; + regs.eax = (totalAcceleration / numVehicles) * 21; if (regs.eax < 0) { regs.eax += 511; } @@ -7296,7 +7301,7 @@ loc_6DC144: } regs.edx >>= 4; regs.eax = regs.edx; - regs.eax = regs.eax / regs.ebp; + regs.eax = regs.eax / totalFriction; regs.ecx -= regs.eax; if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3)) { @@ -7336,7 +7341,7 @@ loc_6DC238: loc_6DC23A: regs.ebx = regs.eax; regs.eax <<= 14; - regs.ebx *= regs.ebp; + regs.ebx *= totalFriction; regs.ebx >>= 2; if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_3) { regs.eax = -regs.eax; From 0903dda369f99ebca4f24b4f56e75a0447a512b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 22 Dec 2015 15:21:56 +0100 Subject: [PATCH 145/162] fixes for issues in vehcile-update --- src/ride/vehicle.c | 83 +++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index d3d73bf937..0970d36fd4 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -91,7 +91,7 @@ const uint8 byte_9A3A18[] = { const rct_vehicle_info *vehicle_get_move_info(int cd, int typeAndDirection, int offset) { - const rct_vehicle_info **infoListList = RCT2_ADDRESS(0x008B8F30, rct_vehicle_info**)[cd]; + const rct_vehicle_info **infoListList = RCT2_ADDRESS(0x008B8F30, const rct_vehicle_info**)[cd]; const rct_vehicle_info *infoList = infoListList[typeAndDirection]; return &infoList[offset]; } @@ -1821,7 +1821,7 @@ static bool try_add_synchronised_station(int x, int y, int z) if (!foundMapElement) { return false; } - + int rideIndex = mapElement->properties.track.ride_index; rct_ride *ride = GET_RIDE(rideIndex); if (!(ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS)) { @@ -1853,6 +1853,7 @@ static bool try_add_synchronised_station(int x, int y, int z) sv->vehicle_id = spriteIndex; return true; } + return false; } /** @@ -2447,7 +2448,7 @@ static void vehicle_check_if_missing(rct_vehicle* vehicle) { } /** - * Setup function for a vehicle colliding with + * Setup function for a vehicle colliding with * another vehicle. * * rct2: 0x006DA059 @@ -3184,7 +3185,7 @@ static void loc_6DA9F9(rct_vehicle *vehicle, int x, int y, int bx, int dx) vehicle->track_y, vehicle->track_z >> 3 ); - + rct_ride *ride = GET_RIDE(vehicle->ride); vehicle->track_type = (mapElement->properties.track.type << 2) | @@ -3324,7 +3325,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) if (vehicle_is_boat_on_water(vehicle, x, y)) { // loc_6DA939: rct_ride *ride = GET_RIDE(vehicle->ride); - + bool do_loc_6DAA97 = false; if (vehicle->sub_state != 1) { do_loc_6DAA97 = true; @@ -3919,7 +3920,9 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) static rct_map_element* vehicle_check_collision(sint16 x, sint16 y, sint16 z) { rct_map_element* mapElement = map_get_first_element_at(x / 32, y / 32); if (mapElement == NULL) - return 1; //Can't return null as that implies no collision. + // Can't return null as that implies no collision, + // but should still cause a crash when dereferenced. + return (rct_map_element *) -1; uint8 bl; if ((x & 0x1F) >= 16) { @@ -4389,7 +4392,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) gForceVert = (((sint64)gForceVert) * RCT2_ADDRESS(0x009A39C4, sint32)[vehicle->var_20]) >> 32; int lateralFactor = 0, vertFactor = 0; - // Note shr has meant some of the below functions cast a known negative number to + // Note shr has meant some of the below functions cast a known negative number to // unsigned. Possibly an original bug but will be left implemented. switch (vehicle->track_type >> 2) { case TRACK_ELEM_FLAT: @@ -4744,7 +4747,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) case TRACK_ELEM_DIAG_RIGHT_BANK_TO_25_DEG_DOWN: vertFactor = -113; //6d755D - break; + break; case TRACK_ELEM_DIAG_25_DEG_UP_TO_60_DEG_UP: case TRACK_ELEM_DIAG_60_DEG_DOWN_TO_25_DEG_DOWN: vertFactor = 95; @@ -4895,7 +4898,7 @@ void vehicle_get_g_forces(rct_vehicle *vehicle, int *verticalG, int *lateralG) gForceLateral *= 10; gForceVert >>= 16; gForceLateral >>= 16; - + // Call original version so we can test if our result is the same as the original int eax, ebx, ecx, edx, esi, edi, ebp; esi = (int)vehicle; @@ -5024,7 +5027,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { .y = vehicle->y, .z = vehicle->z }; - + location.x += RCT2_ADDRESS(0x009A36C4, sint16)[oldC4 * 4]; location.y += RCT2_ADDRESS(0x009A36C6, sint16)[oldC4 * 4]; location.x += RCT2_ADDRESS(0x009A36CC, sint16)[oldC4 * 4]; @@ -5097,7 +5100,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { } } } - + sprite_move( unk_F64E20->x, unk_F64E20->y, @@ -5106,7 +5109,7 @@ static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle) { ); vehicle_invalidate(vehicle); } - + sint32 eax = vehicle->velocity / 2; sint32 edx = vehicle->velocity >> 8; edx *= edx; @@ -5146,7 +5149,7 @@ static bool vehicle_update_bumper_car_collision(rct_vehicle *vehicle, sint16 x, { uint16 bp = (vehicle->var_44 * 30) >> 9; uint32 trackType = vehicle->track_type >> 2; - + sint16 rideLeft = vehicle->track_x + RCT2_ADDRESS(0x0099E228, uint8)[trackType * 4]; sint16 rideRight = vehicle->track_x + RCT2_ADDRESS(0x0099E22A, uint8)[trackType * 4]; sint16 rideTop = vehicle->track_y + RCT2_ADDRESS(0x0099E229, uint8)[trackType * 4]; @@ -5275,7 +5278,7 @@ static void sub_6DAB4C_chunk_2(rct_vehicle *vehicle) vehicle->velocity = velocity; vehicle->acceleration = 0; } - + int trackType = vehicle->track_type >> 2; switch (trackType) { case TRACK_ELEM_END_STATION: @@ -5376,6 +5379,9 @@ static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) } while (!track_element_is_block_start(trackBeginEnd.begin_element)); mapElement = map_get_track_element_at(x, y, z >> 3); + if (mapElement == NULL) { + return; + } mapElement->flags &= ~(1 << 5); map_invalidate_element(x, y, mapElement); @@ -5546,7 +5552,7 @@ static void vehicle_update_swinging_car(rct_vehicle *vehicle) cx = -10831; break; } - + switch (trackType) { case TRACK_ELEM_END_STATION: case TRACK_ELEM_BEGIN_STATION: @@ -6014,7 +6020,7 @@ static void sub_6D63D4(rct_vehicle *vehicle) { uint8 al, ah; uint32 eax; - + uint32 *var_C8 = (uint32*)&vehicle->var_C8; rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); switch (vehicleEntry->var_11) { @@ -6138,7 +6144,7 @@ static void sub_6D63D4(rct_vehicle *vehicle) * * rct2: 0x006DEDB1 */ -static vehicle_play_scenery_door_open_sound(rct_vehicle *vehicle, rct_map_element *mapElement) +static void vehicle_play_scenery_door_open_sound(rct_vehicle *vehicle, rct_map_element *mapElement) { rct_scenery_entry *wallEntry = g_wallSceneryEntries[mapElement->properties.fence.type]; int doorSoundType = (wallEntry->wall.flags2 >> 1) & 3; @@ -6154,7 +6160,7 @@ static vehicle_play_scenery_door_open_sound(rct_vehicle *vehicle, rct_map_elemen * * rct2: 0x006DED7A */ -static vehicle_play_scenery_door_close_sound(rct_vehicle *vehicle, rct_map_element *mapElement) +static void vehicle_play_scenery_door_close_sound(rct_vehicle *vehicle, rct_map_element *mapElement) { rct_scenery_entry *wallEntry = g_wallSceneryEntries[mapElement->properties.fence.type]; int doorSoundType = (wallEntry->wall.flags2 >> 1) & 3; @@ -6173,11 +6179,11 @@ static vehicle_play_scenery_door_close_sound(rct_vehicle *vehicle, rct_map_eleme static void vehicle_update_scenery_door(rct_vehicle *vehicle) { int trackType = vehicle->track_type >> 2; - rct_preview_track *trackBlock = TrackBlocks[trackType]; + const rct_preview_track *trackBlock = TrackBlocks[trackType]; while ((trackBlock + 1)->index != 255) { trackBlock++; } - rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; + const rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; int x = floor2(vehicle->x, 32); int y = floor2(vehicle->y, 32); int z = (vehicle->track_z - trackBlock->z + trackCoordinates->z_end) >> 3; @@ -6208,7 +6214,7 @@ static bool loc_6DB38B(rct_vehicle *vehicle, rct_map_element *mapElement) { // Get bank int bankStart = track_get_actual_bank_3(vehicle, mapElement); - + // Get vangle int trackType = mapElement->properties.track.type; int vangleStart = gTrackDefinitions[trackType].vangle_start; @@ -6258,8 +6264,8 @@ static void vehicle_trigger_on_ride_photo(rct_vehicle *vehicle, rct_map_element static void sub_6DEDE8(rct_vehicle *vehicle) { int trackType = vehicle->track_type >> 2; - rct_preview_track *trackBlock = TrackBlocks[trackType]; - rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; + const rct_preview_track *trackBlock = TrackBlocks[trackType]; + const rct_track_coordinates *trackCoordinates = &TrackCoordinates[trackType]; int x = vehicle->track_x; int y = vehicle->track_y; int z = (vehicle->track_z - trackBlock->z + trackCoordinates->z_begin) >> 3; @@ -6362,7 +6368,7 @@ static void sub_6DB807(rct_vehicle *vehicle) static bool sub_6DD078(rct_vehicle *vehicle, uint16* otherVehicleIndex) { registers regs = { 0 }; - regs.esi = vehicle; + regs.esi = (int)vehicle; if (otherVehicleIndex != NULL) { regs.bp = *otherVehicleIndex; } @@ -6793,7 +6799,7 @@ loc_6DB8A5: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->prev_vehicle_on_ride; - if (sub_6DD078(vehicle, ®s.bp)) { + if (sub_6DD078(vehicle, (uint16 *)®s.bp)) { goto loc_6DB967; } } @@ -6911,7 +6917,7 @@ loc_6DBB7E:; mapElement = trackBeginEnd.begin_element; trackType = mapElement->properties.track.type; - if (trackType == TRACK_ELEM_LEFT_REVERSER || + if (trackType == TRACK_ELEM_LEFT_REVERSER || trackType == TRACK_ELEM_RIGHT_REVERSER) { return false; } @@ -7002,6 +7008,7 @@ loc_6DBC3B: // There are two bytes before the move info list uint16 trackTotalProgress = *((uint16*)((int)moveInfo - 2)); *progress = trackTotalProgress - 1; + return true; } /** @@ -7031,7 +7038,7 @@ loc_6DBA33:; regs.ax = vehicle->track_progress - 1; if (regs.ax == -1) { - if (!vehicle_update_track_motion_backwards_get_new_track(vehicle, trackType, ride, rideEntry, ®s.ax)) { + if (!vehicle_update_track_motion_backwards_get_new_track(vehicle, trackType, ride, rideEntry, (uint16 *)®s.ax)) { goto loc_6DBE5E; } } @@ -7071,7 +7078,7 @@ loc_6DBD42: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { regs.bp = vehicle->next_vehicle_on_ride; - if (sub_6DD078(vehicle, ®s.bp)) { + if (sub_6DD078(vehicle, (uint16 *)®s.bp)) { goto loc_6DBE7F; } } @@ -7143,7 +7150,7 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) rct_ride *ride = GET_RIDE(vehicle->ride); rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); - + rct_map_element *mapElement = NULL; // esi = vehicle @@ -7189,7 +7196,7 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) regs.eax = RCT2_GLOBAL(0x00F64E0C, sint32) + car->remaining_distance; car->remaining_distance = regs.eax; - + car->var_B8 &= ~(1 << 1); unk_F64E20->x = car->x; unk_F64E20->y = car->y; @@ -7721,7 +7728,7 @@ loc_6DC8A1: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->var_44; - sub_6DD078(vehicle, ®s.bp); + sub_6DD078(vehicle, (uint16 *)®s.bp); } } goto loc_6DC99A; @@ -7765,7 +7772,7 @@ loc_6DCA9A: if (regs.ax != (short)0xFFFF) { goto loc_6DCC2C; } - + trackType = vehicle->track_type >> 2; RCT2_GLOBAL(0x00F64E36, uint8) = gTrackDefinitions[trackType].vangle_end; RCT2_GLOBAL(0x00F64E37, uint8) = gTrackDefinitions[trackType].bank_end; @@ -7812,9 +7819,9 @@ loc_6DCA9A: vehicle->track_type = (mapElement->properties.track.type << 2) | (direction & 3); vehicle->var_CF = (mapElement->properties.track.colour >> 4) << 1; - + moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); - + // There are two bytes before the move info list regs.ax = *((uint16*)((int)moveInfo - 2)) - 1; @@ -7861,7 +7868,7 @@ loc_6DCC2C: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->var_44; - if (sub_6DD078(vehicle, ®s.bp)) { + if (sub_6DD078(vehicle, (uint16 *)®s.bp)) { goto loc_6DCD6B; } } @@ -7888,7 +7895,7 @@ loc_6DCD6B: RCT2_GLOBAL(0x00F64E0C, sint32) -= regs.eax; vehicle->remaining_distance -= regs.eax; rct_vehicle *vEBP = GET_VEHICLE(regs.bp); - rct_vehicle *vEDI = RCT2_GLOBAL(0x00F64E04, uint32); + rct_vehicle *vEDI = RCT2_GLOBAL(0x00F64E04, rct_vehicle *); regs.eax = abs(vEDI->velocity - vEBP->velocity); if (regs.eax > 0xE0000) { if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_6)) { @@ -8002,7 +8009,7 @@ loc_6DCEFF: regs.edx >>= 4; regs.eax = regs.edx / regs.ebp; regs.ecx -= regs.eax; - + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_3)) { goto loc_6DD069; } @@ -8026,7 +8033,7 @@ loc_6DCEFF: regs.edx <<= 1; regs.eax *= regs.edx; regs.eax = regs.eax / regs.ebx; - + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_13)) { goto loc_6DD054; } From 4c88609e7e89daacbf7f4eff1f5424f249972073 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 23 Dec 2015 11:57:50 +0000 Subject: [PATCH 146/162] Fix stretch backwards coasters --- src/ride/vehicle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 0970d36fd4..c4db2e5857 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -7056,9 +7056,9 @@ loc_6DBD42: sint16 z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8); regs.ebx = 0; - if (x == unk_F64E20->x) { regs.ebx |= 1; } - if (y == unk_F64E20->y) { regs.ebx |= 2; } - if (z == unk_F64E20->z) { regs.ebx |= 4; } + if (x != unk_F64E20->x) { regs.ebx |= 1; } + if (y != unk_F64E20->y) { regs.ebx |= 2; } + if (z != unk_F64E20->z) { regs.ebx |= 4; } vehicle->remaining_distance += RCT2_ADDRESS(0x009A2930, sint32)[regs.ebx]; unk_F64E20->x = x; From f7520fd2ba3f007c0900b1b9fd90e639d746ffb8 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 27 Dec 2015 11:46:15 +0000 Subject: [PATCH 147/162] implement vehicle_update_motion_collision_detection --- src/ride/vehicle.c | 182 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 160 insertions(+), 22 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index c4db2e5857..69216f6ead 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -71,7 +71,7 @@ static void vehicle_update_collision_setup(rct_vehicle* vehicle); static int vehicle_update_motion_bumper_car(rct_vehicle* vehicle); static bool vehicle_update_bumper_car_collision(rct_vehicle *vehicle, sint16 x, sint16 y, uint16 *spriteId); static void sub_6D63D4(rct_vehicle *vehicle); -static bool sub_6DD078(rct_vehicle *vehicle, uint16* otherVehicleIndex); +static bool vehicle_update_motion_collision_detection(rct_vehicle *vehicle, sint16 x, sint16 y, sint16 z, uint16 *otherVehicleIndex); static void vehicle_update_sound(rct_vehicle *vehicle); static int vehicle_update_scream_sound(rct_vehicle *vehicle); @@ -3175,8 +3175,7 @@ static void vehicle_update_travelling_boat(rct_vehicle* vehicle) static void loc_6DA9F9(rct_vehicle *vehicle, int x, int y, int bx, int dx) { vehicle->remaining_distance = 0; - // z = vehicle->z; - if (!sub_6DD078(vehicle, NULL)) { + if (!vehicle_update_motion_collision_detection(vehicle, x, y, vehicle->z, NULL)) { vehicle->track_x = bx; vehicle->track_y = dx; @@ -3315,7 +3314,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) x = vehicle->x + RCT2_ADDRESS(0x009A36C4, sint16)[edi * 4]; y = vehicle->y + RCT2_ADDRESS(0x009A36C6, sint16)[edi * 4]; z = vehicle->z; - if (sub_6DD078(vehicle, NULL)) { + if (vehicle_update_motion_collision_detection(vehicle, x, y, z, NULL)) { goto loc_6DAA79; } @@ -3376,8 +3375,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) // loc_6DA9D1: vehicle->remaining_distance = 0; - // z = vehicle->z; - if (!sub_6DD078(vehicle, NULL)) { + if (!vehicle_update_motion_collision_detection(vehicle, x, y, vehicle->z, NULL)) { unk_F64E20->x = x; unk_F64E20->y = y; } @@ -6359,24 +6357,164 @@ static void sub_6DB807(rct_vehicle *vehicle) sprite_move(x, y, z, (rct_sprite*)vehicle); } -/** Collision? - * +/** + * Collision Detection * rct2: 0x006DD078 * @param vehicle (esi) + * @param x (ax) + * @param y (cx) + * @param z (dx) * @param otherVehicleIndex (bp) */ -static bool sub_6DD078(rct_vehicle *vehicle, uint16* otherVehicleIndex) -{ - registers regs = { 0 }; - regs.esi = (int)vehicle; - if (otherVehicleIndex != NULL) { - regs.bp = *otherVehicleIndex; +static bool vehicle_update_motion_collision_detection( + rct_vehicle *vehicle, sint16 x, sint16 y, sint16 z, uint16* otherVehicleIndex +) { + if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_1) return false; + + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); + + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_6)){ + vehicle->var_C4 = 0; + rct_vehicle* collideVehicle = GET_VEHICLE(*otherVehicleIndex); + + if (vehicle == collideVehicle) return false; + + sint32 x_diff = abs(x - collideVehicle->x); + if (x_diff > 0x7FFF) return false; + + sint32 y_diff = abs(y - collideVehicle->y); + if (y_diff > 0x7FFF) return false; + + if (x_diff + y_diff > 0xFFFF) return false; + + sint32 z_diff = abs(z - collideVehicle->z); + if (x_diff + y_diff + z_diff > 0xFFFF) return false; + + uint16 ecx = min(vehicle->var_44 + collideVehicle->var_44, 560); + ecx = ((ecx >> 1) * 30) >> 8; + + if (x_diff + y_diff + z_diff >= ecx) return false; + + uint8 direction = (vehicle->sprite_direction - collideVehicle->sprite_direction + 7) & 0x1F; + if (direction >= 0xF) return false; + + return true; } - bool result = RCT2_CALLFUNC_Y(0x006DD078, ®s) & 0x100; - if (otherVehicleIndex != NULL) { - *otherVehicleIndex = regs.bp; + + uint16 eax = ((x / 32) << 8) + (y / 32); + // TODO change to using a better technique + uint32* ebp = RCT2_ADDRESS(0x009A37C4, uint32); + bool mayCollide = false; + uint16 collideId = 0xFFFF; + rct_vehicle* collideVehicle = NULL; + for(; ebp <= RCT2_ADDRESS(0x009A37E4, uint32); ebp++){ + collideId = RCT2_ADDRESS(0x00F1EF60, uint16)[eax]; + for(; collideId != 0xFFFF; collideId = collideVehicle->next_in_quadrant){ + collideVehicle = GET_VEHICLE(collideId); + if (collideVehicle == vehicle) continue; + + if (collideVehicle->sprite_identifier != SPRITE_IDENTIFIER_VEHICLE) continue; + + sint32 z_diff = abs(collideVehicle->z - z); + + if (z_diff > 16) continue; + + rct_ride_type_vehicle* collideType = vehicle_get_vehicle_entry(collideVehicle); + + if (!(collideType->flags_b & VEHICLE_ENTRY_FLAG_B_6)) continue; + + sint32 x_diff = abs(collideVehicle->x - x); + if (x_diff > 0x7FFF) continue; + + sint32 y_diff = abs(collideVehicle->y - y); + if (y_diff > 0x7FFF) continue; + + if (x_diff + y_diff > 0xFFFF) continue; + + uint8 cl = min(vehicle->var_CD, collideVehicle->var_CD); + uint8 ch = max(vehicle->var_CD, collideVehicle->var_CD); + if (cl != ch){ + if (cl == 5 && ch == 6) continue; + } + + uint32 ecx = vehicle->var_44 + collideVehicle->var_44; + ecx = ((ecx >> 1) * 30) >> 8; + + if (x + y >= ecx) continue; + + if (!(collideType->flags_b & VEHICLE_ENTRY_FLAG_B_14)){ + mayCollide = true; + break; + } + + uint8 direction = (vehicle->sprite_direction - collideVehicle->sprite_direction - 6) & 0x1F; + + if (direction < 0x14) continue; + + sint16 next_x_diff = abs(x + RCT2_ADDRESS(0x009A3B04, sint16)[vehicle->sprite_direction*2]-collideVehicle->x); + sint16 next_y_diff = abs(y + RCT2_ADDRESS(0x009A3B06, sint16)[vehicle->sprite_direction*2]-collideVehicle->y); + + if (next_x_diff + next_y_diff < x_diff + y_diff){ + mayCollide = true; + break; + } + + } + if (mayCollide == true) { + break; + } + + // TODO change this + eax += *ebp; } - return result; + + if (mayCollide == false) { + vehicle->var_C4 = 0; + return false; + } + + vehicle->var_C4++; + if (vehicle->var_C4 < 200) { + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_6; + *otherVehicleIndex = collideId; + return true; + } + + // TODO Is it possible for collideVehicle to be NULL? + + if (vehicle->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION){ + if (vehicle->sprite_direction == 0) { + if (vehicle->x <= collideVehicle->x) { + return false; + } + } + else if (vehicle->sprite_direction == 8) { + if (vehicle->x >= collideVehicle->x) { + return false; + } + } + else if (vehicle->sprite_direction == 16) { + if (vehicle->y >= collideVehicle->y) { + return false; + } + } + else if (vehicle->sprite_direction == 24) { + if (vehicle->y <= collideVehicle->y) { + return false; + } + } + } + + if (collideVehicle->status == VEHICLE_STATUS_TRAVELLING_BOAT && + vehicle->status != VEHICLE_STATUS_ARRIVING && + vehicle->status != VEHICLE_STATUS_TRAVELLING + ) { + return false; + } + + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_6; + *otherVehicleIndex = collideId; + return true; } /** @@ -6799,7 +6937,7 @@ loc_6DB8A5: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->prev_vehicle_on_ride; - if (sub_6DD078(vehicle, (uint16 *)®s.bp)) { + if (vehicle_update_motion_collision_detection(vehicle, x, y, z, (uint16 *)®s.bp)) { goto loc_6DB967; } } @@ -7078,7 +7216,7 @@ loc_6DBD42: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) < 0) { regs.bp = vehicle->next_vehicle_on_ride; - if (sub_6DD078(vehicle, (uint16 *)®s.bp)) { + if (vehicle_update_motion_collision_detection(vehicle, x, y, z, (uint16*)®s.bp)) { goto loc_6DBE7F; } } @@ -7728,7 +7866,7 @@ loc_6DC8A1: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->var_44; - sub_6DD078(vehicle, (uint16 *)®s.bp); + vehicle_update_motion_collision_detection(vehicle, x, y, z, (uint16*)®s.bp); } } goto loc_6DC99A; @@ -7868,7 +8006,7 @@ loc_6DCC2C: if (vehicle == RCT2_GLOBAL(0x00F64E00, rct_vehicle*)) { if (RCT2_GLOBAL(0x00F64E08, sint32) >= 0) { regs.bp = vehicle->var_44; - if (sub_6DD078(vehicle, (uint16 *)®s.bp)) { + if (vehicle_update_motion_collision_detection(vehicle, x, y, z, (uint16*)®s.bp)) { goto loc_6DCD6B; } } From ac0d729baf19a9fdae0ed9f40e17a58441367526 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Tue, 29 Dec 2015 12:06:11 +0000 Subject: [PATCH 148/162] implement sub_6DA280 --- src/ride/vehicle.c | 57 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 69216f6ead..e65baa4563 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3444,7 +3444,62 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) */ static void sub_6DA280(rct_vehicle *vehicle) { - RCT2_CALLPROC_X(0x006DA280, 0, 0, 0, 0, (int)vehicle, 0, 0); + rct_ride* ride = GET_RIDE(vehicle->ride); + + rct_xy8 location = { + .x = (vehicle->x + RCT2_ADDRESS(0x00993CCC, sint16)[2 * (ride->boat_hire_return_direction & 3)]) / 32, + .y = (vehicle->y + RCT2_ADDRESS(0x00993CCE, sint16)[2 * (ride->boat_hire_return_direction & 3)]) / 32 + }; + + if (*((uint16*)&location) == ride->boat_hire_return_position) { + vehicle->sub_state = 1; + vehicle->boat_location = location; + return; + } + + vehicle->sub_state = 0; + uint8 curDirection = ((vehicle->sprite_direction + 19) >> 3) & 3; + uint8 randDirection = scenario_rand() & 3; + + rct_ride_type* rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype); + if (scenario_rand() & 1 && (!(rideEntry->flags & RIDE_ENTRY_FLAG_7) || vehicle->lost_time_out > 1920)) { + location = *((rct_xy8*)&ride->boat_hire_return_position); + rct_xy16 destLocation = { + .x = location.x * 32 - RCT2_ADDRESS(0x00993CCC, sint16)[2 * (ride->boat_hire_return_direction & 3)] + 16, + .y = location.y * 32 - RCT2_ADDRESS(0x00993CCE, sint16)[2 * (ride->boat_hire_return_direction & 3)] + 16 + }; + + destLocation.x -= vehicle->x; + destLocation.y -= vehicle->y; + + if (abs(destLocation.x) <= abs(destLocation.y)) { + randDirection = destLocation.x < 0 ? 3 : 1; + } else { + randDirection = destLocation.y < 0 ? 0 : 2; + } + } + + static const sint8 rotations[] = { 0, 1, -1, 2 }; + for (int i = 0; i < 4; i++) { + if (randDirection + rotations[i] == curDirection) { + continue; + } + + sint16 x = vehicle->track_x + RCT2_ADDRESS(0x00993CCC, sint16)[2 * (randDirection + rotations[i] & 3)]; + sint16 y = vehicle->track_y + RCT2_ADDRESS(0x00993CCE, sint16)[2 * (randDirection + rotations[i] & 3)]; + + if (!vehicle_is_boat_on_water(vehicle, x, y)) { + continue; + } + vehicle->boat_location.x = x / 32; + vehicle->boat_location.y = y / 32; + return; + } + + sint16 x = vehicle->track_x + RCT2_ADDRESS(0x00993CCC, sint16)[2 * (curDirection & 3)]; + sint16 y = vehicle->track_y + RCT2_ADDRESS(0x00993CCE, sint16)[2 * (curDirection & 3)]; + vehicle->boat_location.x = x / 32; + vehicle->boat_location.y = y / 32; } /** From 3e03ab71fa42e83358c89e937fde9666645d1ca4 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 31 Dec 2015 09:53:23 +0000 Subject: [PATCH 149/162] Fix small bugs in boat hire code. --- src/ride/vehicle.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index e65baa4563..6a95a2a079 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3385,7 +3385,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) vehicle->track_y = dx; } - vehicle->remaining_distance = RCT2_ADDRESS(0x009A36C8, uint32)[edi * 2]; + vehicle->remaining_distance -= RCT2_ADDRESS(0x009A36C8, uint32)[edi * 2]; unk_F64E20->x = x; unk_F64E20->y = y; if (vehicle->remaining_distance < 0x368A) { @@ -3473,9 +3473,9 @@ static void sub_6DA280(rct_vehicle *vehicle) destLocation.y -= vehicle->y; if (abs(destLocation.x) <= abs(destLocation.y)) { - randDirection = destLocation.x < 0 ? 3 : 1; + randDirection = destLocation.y < 0 ? 3 : 1; } else { - randDirection = destLocation.y < 0 ? 0 : 2; + randDirection = destLocation.x < 0 ? 0 : 2; } } @@ -3488,7 +3488,7 @@ static void sub_6DA280(rct_vehicle *vehicle) sint16 x = vehicle->track_x + RCT2_ADDRESS(0x00993CCC, sint16)[2 * (randDirection + rotations[i] & 3)]; sint16 y = vehicle->track_y + RCT2_ADDRESS(0x00993CCE, sint16)[2 * (randDirection + rotations[i] & 3)]; - if (!vehicle_is_boat_on_water(vehicle, x, y)) { + if (vehicle_is_boat_on_water(vehicle, x, y)) { continue; } vehicle->boat_location.x = x / 32; @@ -6495,7 +6495,7 @@ static bool vehicle_update_motion_collision_detection( uint32 ecx = vehicle->var_44 + collideVehicle->var_44; ecx = ((ecx >> 1) * 30) >> 8; - if (x + y >= ecx) continue; + if (x_diff + y_diff >= ecx) continue; if (!(collideType->flags_b & VEHICLE_ENTRY_FLAG_B_14)){ mayCollide = true; @@ -6531,7 +6531,8 @@ static bool vehicle_update_motion_collision_detection( vehicle->var_C4++; if (vehicle->var_C4 < 200) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_6; - *otherVehicleIndex = collideId; + if (otherVehicleIndex != NULL) + *otherVehicleIndex = collideId; return true; } @@ -6568,7 +6569,8 @@ static bool vehicle_update_motion_collision_detection( } vehicle->update_flags |= VEHICLE_UPDATE_FLAG_6; - *otherVehicleIndex = collideId; + if (otherVehicleIndex != NULL) + *otherVehicleIndex = collideId; return true; } From 1f4b4b2c3f8d60f5ed5b52d749b3788dc6a9d4f2 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 31 Dec 2015 10:27:33 +0000 Subject: [PATCH 150/162] Fix flying boats when entering the station. Issue was caused by not clearing the word var_34 but instead only the byte var_34. This caused track_progress (word var_34) to become a very large negative number that would be interpreted as a valid track_progress. This would eventually end up reading invalid memory. --- src/ride/vehicle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 6a95a2a079..79a6e2a0c8 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3190,7 +3190,7 @@ static void loc_6DA9F9(rct_vehicle *vehicle, int x, int y, int bx, int dx) (mapElement->properties.track.type << 2) | (ride->boat_hire_return_direction & 3); - vehicle->var_34 = 0; + vehicle->track_progress = 0; vehicle->status = VEHICLE_STATUS_TRAVELLING; unk_F64E20->x = x; unk_F64E20->y = y; From bcd02e833c9052c4dc07fd2e3ea70d4d79371083 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 2 Jan 2016 10:45:59 +0000 Subject: [PATCH 151/162] Fix vehicles bunching up when waiting for passengers in certain directions. Most notable in bumper boats on blackpool pleasure --- src/ride/vehicle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 79a6e2a0c8..2fa658f119 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -6545,12 +6545,12 @@ static bool vehicle_update_motion_collision_detection( } } else if (vehicle->sprite_direction == 8) { - if (vehicle->x >= collideVehicle->x) { + if (vehicle->y >= collideVehicle->y) { return false; } } else if (vehicle->sprite_direction == 16) { - if (vehicle->y >= collideVehicle->y) { + if (vehicle->x >= collideVehicle->x) { return false; } } From afca9d27d6c2ec3612bad8baa04d963de33f9c57 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 2 Jan 2016 16:19:06 +0000 Subject: [PATCH 152/162] Fix sound bugs with opening/closing track doors. Fix average speed bug. --- src/ride/vehicle.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 2fa658f119..1a949a2377 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -97,12 +97,11 @@ const rct_vehicle_info *vehicle_get_move_info(int cd, int typeAndDirection, int } const uint8 DoorOpenSoundIds[] = { - SOUND_WATER_2, - SOUND_DOOR_OPEN + SOUND_DOOR_OPEN, + SOUND_62 }; const uint8 DoorCloseSoundIds[] = { - SOUND_62, SOUND_DOOR_CLOSE, SOUND_62 }; @@ -2024,7 +2023,7 @@ void vehicle_update_test_finish(rct_vehicle* vehicle) { totalTime += ride->time[i]; } - totalTime = min(totalTime, 1); + totalTime = max(totalTime, 1); ride->average_speed = ride->average_speed / totalTime; window_invalidate_by_number(WC_RIDE, vehicle->ride); @@ -6202,9 +6201,9 @@ static void vehicle_play_scenery_door_open_sound(rct_vehicle *vehicle, rct_map_e rct_scenery_entry *wallEntry = g_wallSceneryEntries[mapElement->properties.fence.type]; int doorSoundType = (wallEntry->wall.flags2 >> 1) & 3; if (doorSoundType != 0) { - int soundId = DoorOpenSoundIds[doorSoundType]; + int soundId = DoorOpenSoundIds[doorSoundType - 1]; if (soundId != 255) { - audio_play_sound_at_location(doorSoundType, vehicle->x, vehicle->track_y, vehicle->track_z); + audio_play_sound_at_location(soundId, vehicle->x, vehicle->track_y, vehicle->track_z); } } } @@ -6218,9 +6217,9 @@ static void vehicle_play_scenery_door_close_sound(rct_vehicle *vehicle, rct_map_ rct_scenery_entry *wallEntry = g_wallSceneryEntries[mapElement->properties.fence.type]; int doorSoundType = (wallEntry->wall.flags2 >> 1) & 3; if (doorSoundType != 0) { - int soundId = DoorCloseSoundIds[doorSoundType]; + int soundId = DoorCloseSoundIds[doorSoundType - 1]; if (soundId != 255) { - audio_play_sound_at_location(doorSoundType, vehicle->x, vehicle->track_y, vehicle->track_z); + audio_play_sound_at_location(soundId, vehicle->x, vehicle->track_y, vehicle->track_z); } } } From 797a2cc75d83a65a5ec312749f654068f6c5ff27 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 2 Jan 2016 17:04:39 +0000 Subject: [PATCH 153/162] Fix bug with block breaks when there are track overlaps. Labeled map_flag (1<<5) as block break closed as well. --- src/ride/vehicle.c | 12 +++++++----- src/world/map.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 1a949a2377..b378724515 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -5410,7 +5410,7 @@ static void sub_6DAB4C_chunk_3(rct_vehicle *vehicle) RCT2_GLOBAL(0x00F64E0C, sint32) = (nextVelocity >> 10) * 42; } -static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) +static void vehicle_update_block_breaks_open_previous_section(rct_vehicle *vehicle, rct_map_element *mapElement) { int x = vehicle->track_x; int y = vehicle->track_y; @@ -5420,7 +5420,9 @@ static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) if (!track_block_get_previous(x, y, mapElement, &trackBeginEnd)) { return; } - if (trackBeginEnd.begin_x == vehicle->track_x && trackBeginEnd.begin_y == vehicle->track_y) { + if (trackBeginEnd.begin_x == vehicle->track_x && + trackBeginEnd.begin_y == vehicle->track_y && + mapElement == trackBeginEnd.begin_element) { return; } @@ -5434,7 +5436,7 @@ static void loc_6DB1B0(rct_vehicle *vehicle, rct_map_element *mapElement) if (mapElement == NULL) { return; } - mapElement->flags &= ~(1 << 5); + mapElement->flags &= ~MAP_ELEMENT_FLAG_BLOCK_BREAK_CLOSED; map_invalidate_element(x, y, mapElement); int trackType = mapElement->properties.track.type; @@ -6691,14 +6693,14 @@ bool vehicle_update_track_motion_forwards_get_new_track(rct_vehicle *vehicle, ui if (track_element_is_block_start(mapElement)) { if (vehicle->next_vehicle_on_train == SPRITE_INDEX_NULL) { - mapElement->flags |= (1 << 5); + mapElement->flags |= MAP_ELEMENT_FLAG_BLOCK_BREAK_CLOSED; if (trackType == TRACK_ELEM_BLOCK_BRAKES || trackType == TRACK_ELEM_END_STATION) { if (!(rideEntry->vehicles[0].flags_b & VEHICLE_ENTRY_FLAG_B_3)) { audio_play_sound_at_location(SOUND_49, vehicle->track_x, vehicle->track_y, vehicle->track_z); } } map_invalidate_element(vehicle->track_x, vehicle->track_z, mapElement); - loc_6DB1B0(vehicle, mapElement); + vehicle_update_block_breaks_open_previous_section(vehicle, mapElement); } } diff --git a/src/world/map.h b/src/world/map.h index e04ed5dc32..d96fc9fdd8 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -141,6 +141,7 @@ enum { enum { MAP_ELEMENT_FLAG_GHOST = (1 << 4), MAP_ELEMENT_FLAG_BROKEN = (1 << 5), + MAP_ELEMENT_FLAG_BLOCK_BREAK_CLOSED = (1 << 5), MAP_ELEMENT_FLAG_LAST_TILE = (1 << 7) }; From 2b1b0f76f301df2fd34bf183ba818a34ffe3fecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sat, 2 Jan 2016 15:52:37 +0100 Subject: [PATCH 154/162] Whitespace fixes. This is just whitespace fixup for all files affected in vehcile-update branch. --- src/hook.c | 6 ++-- src/openrct2.c | 2 +- src/peep/peep.c | 2 +- src/ride/cable_lift.h | 2 +- src/ride/ride.c | 4 +-- src/ride/ride.h | 12 ++++---- src/ride/ride_data.c | 4 +-- src/ride/ride_ratings.c | 2 +- src/ride/track_paint.c | 6 ++-- src/ride/vehicle.c | 68 ++++++++++++++++++++--------------------- src/world/map.c | 56 ++++++++++++++++----------------- 11 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/hook.c b/src/hook.c index 1f8da14bf6..c0b9e16b72 100644 --- a/src/hook.c +++ b/src/hook.c @@ -79,7 +79,7 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in data[i++] = 0x89; //mov eax, esp data[i++] = 0xE0; data[i++] = 0x83; //sub eax, (0xC + numargs*4) & 0xF - data[i++] = 0xE8; + data[i++] = 0xE8; data[i++] = (0xC + numrargs * 4) & 0xF; data[i++] = 0x83; //and eax, 0xC data[i++] = 0xE0; @@ -87,7 +87,7 @@ void hookfunc(int address, int newaddress, int stacksize, int registerargs[], in data[i++] = 0xA3; //mov [0x9ABDA8], eax data[i++] = 0xA8; data[i++] = 0xBD; - data[i++] = 0x9A; + data[i++] = 0x9A; data[i++] = 0x00; data[i++] = 0x58; //pop eax data[i++] = 0x2B; //sub esp, [0x9ABDA8] @@ -230,4 +230,4 @@ void addhook(int address, int newaddress, int stacksize, int registerargs[], int #endif // _WIN32 hookfunc(hookaddress, newaddress, stacksize, registerargs, registersreturned, eaxDestinationRegister); g_hooktableoffset++; -} \ No newline at end of file +} diff --git a/src/openrct2.c b/src/openrct2.c index 6f5ca0f1fc..eb41a4457f 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -595,4 +595,4 @@ FILE **__iob_func() streams[2] = stderr; return streams; } -#endif \ No newline at end of file +#endif diff --git a/src/peep/peep.c b/src/peep/peep.c index 9fdc1a01b6..3828a234d0 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -1726,7 +1726,7 @@ static void peep_update_ride_sub_state_0(rct_peep* peep){ } else{ chosen_train = ride->train_at_station[peep->current_ride_station]; - } + } if (chosen_train == 0xFF){ return; } diff --git a/src/ride/cable_lift.h b/src/ride/cable_lift.h index 46f65d035c..95b32757c4 100644 --- a/src/ride/cable_lift.h +++ b/src/ride/cable_lift.h @@ -8,4 +8,4 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d void cable_lift_update(rct_vehicle *vehicle); int cable_lift_update_track_motion(rct_vehicle *cableLift); -#endif \ No newline at end of file +#endif diff --git a/src/ride/ride.c b/src/ride/ride.c index d8bc04a53a..0fe59765e6 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -6027,7 +6027,7 @@ int get_turn_count_3_elements(rct_ride* ride, uint8 type) { break; case 1: turn_count = &ride->turn_count_banked; - break; + break; case 2: turn_count = &ride->turn_count_sloped; break; @@ -6044,7 +6044,7 @@ int get_turn_count_4_plus_elements(rct_ride* ride, uint8 type) { case 0: case 1: return 0; - case 2: + case 2: turn_count = &ride->turn_count_sloped; break; default: diff --git a/src/ride/ride.h b/src/ride/ride.h index 2626e38108..7239791272 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -82,13 +82,13 @@ typedef struct { uint8 ride_type[3]; // 0x00C uint8 min_cars_in_train; // 0x00F uint8 max_cars_in_train; // 0x010 - uint8 cars_per_flat_ride; // 0x011 + uint8 cars_per_flat_ride; // 0x011 // Number of cars that can't hold passengers - uint8 zero_cars; // 0x012 + uint8 zero_cars; // 0x012 // The index to the vehicle type displayed in // the vehicle tab. uint8 tab_vehicle; // 0x013 - uint8 default_vehicle; // 0x014 + uint8 default_vehicle; // 0x014 // Convert from first - fourth vehicle to // vehicle structure uint8 front_vehicle; // 0x015 @@ -200,7 +200,7 @@ typedef struct { uint16 var_10C; // Next 3 variables are related (XXXX XYYY ZZZa aaaa) uint16 turn_count_default; // 0x10E X = current turn count - uint16 turn_count_banked; // 0x110 + uint16 turn_count_banked; // 0x110 uint16 turn_count_sloped; // 0x112 X = number turns > 3 elements union { uint8 inversions; // 0x114 (???X XXXX) @@ -410,8 +410,8 @@ enum { RIDE_ENTRY_FLAG_16 = 1 << 16, // 0x10000 RIDE_ENTRY_DISABLE_FIRST_TWO_OPERATING_MODES = 1 << 17, // 0x20000 RIDE_ENTRY_FLAG_18 = 1 << 18, // 0x40000 - RIDE_ENTRY_FLAG_19 = 1 << 19, // 0x80000 - // Must be set with swing mode 1 as well. + RIDE_ENTRY_FLAG_19 = 1 << 19, // 0x80000 + // Must be set with swing mode 1 as well. RIDE_ENTRY_FLAG_ALTERNATIVE_SWING_MODE_2 = 1 << 20, // 0x100000 RIDE_ENTRY_FLAG_21 = 1 << 21, // 0x200000 RIDE_ENTRY_FLAG_22 = 1 << 22, // 0x400000 diff --git a/src/ride/ride_data.c b/src/ride/ride_data.c index 0937db17e1..2a20c03721 100644 --- a/src/ride/ride_data.c +++ b/src/ride/ride_data.c @@ -1316,7 +1316,7 @@ const uint16 RideCrookedHouseLength[1] = { }; /* rct2: 0x0097D7C8, 0x0097D7C9, 0x0097D7CA */ -const rct_ride_lift_data RideLiftData[] = { +const rct_ride_lift_data RideLiftData[] = { { SOUND_LIFT_3, 7, 7 }, // Spiral Roller coaster { SOUND_LIFT_1, 4, 6 }, // Stand Up Coaster { SOUND_LIFT_1, 4, 6 }, // Suspended Swinging @@ -1408,4 +1408,4 @@ const rct_ride_lift_data RideLiftData[] = { { 255, 5, 5 }, // Mine Ride { SOUND_LIFT_6, 4, 6 }, // (none) { 255, 4, 6 } // LIM Launched Roller Coaster -}; \ No newline at end of file +}; diff --git a/src/ride/ride_ratings.c b/src/ride/ride_ratings.c index 5389fc0b1d..a2262d6549 100644 --- a/src/ride/ride_ratings.c +++ b/src/ride/ride_ratings.c @@ -981,7 +981,7 @@ static rating_tuple get_banked_turns_rating(rct_ride* ride) { */ static rating_tuple get_sloped_turns_rating(rct_ride* ride) { rating_tuple rating; - + int no_4_plus_turns = get_turn_count_4_plus_elements(ride, 2); int no_3_turns = get_turn_count_3_elements(ride, 2); int no_2_turns = get_turn_count_2_elements(ride, 2); diff --git a/src/ride/track_paint.c b/src/ride/track_paint.c index f294444c95..9585a0c7f9 100644 --- a/src/ride/track_paint.c +++ b/src/ride/track_paint.c @@ -82,7 +82,7 @@ static rct_xy16 loc_7667AC[] = { /** * - * rct2: 0x0142811C + * rct2: 0x0142811C * Can be calculated as Rounddown(34*sin(x)+0.5) * where x is in 7.5 deg segments. */ @@ -1028,7 +1028,7 @@ static void shop_paint_setup(uint8 rideIndex, uint8 trackSequence, uint8 directi RCT2_GLOBAL(0x009DEA52, uint16) = 2; RCT2_GLOBAL(0x009DEA54, uint16) = 2; RCT2_GLOBAL(0x009DEA56, sint16) = height16; - sub_98199C(0, 45, imageId, 0, height, 28, 28, rotation); + sub_98199C(0, 45, imageId, 0, height, 28, 28, rotation); } else { RCT2_GLOBAL(0x009DEA52, uint16) = 2; RCT2_GLOBAL(0x009DEA54, uint16) = 2; @@ -1099,7 +1099,7 @@ static void facility_paint_setup(uint8 rideIndex, uint8 trackSequence, uint8 dir RCT2_GLOBAL(0x009DEA52, uint16) = direction == 3 ? 28 : 2; RCT2_GLOBAL(0x009DEA54, uint16) = direction == 0 ? 28 : 2; RCT2_GLOBAL(0x009DEA56, sint16) = height16; - sub_98199C(0, 29, imageId, 0, height, lengthY, lengthX, rotation); + sub_98199C(0, 29, imageId, 0, height, lengthY, lengthX, rotation); } else { // Door image or base RCT2_GLOBAL(0x009DEA52, uint16) = direction == 3 ? 28 : 2; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index b378724515..5e18be5c29 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -6426,37 +6426,37 @@ static bool vehicle_update_motion_collision_detection( rct_vehicle *vehicle, sint16 x, sint16 y, sint16 z, uint16* otherVehicleIndex ) { if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_1) return false; - + rct_ride_type_vehicle *vehicleEntry = vehicle_get_vehicle_entry(vehicle); - + if (!(vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_6)){ vehicle->var_C4 = 0; rct_vehicle* collideVehicle = GET_VEHICLE(*otherVehicleIndex); - + if (vehicle == collideVehicle) return false; - + sint32 x_diff = abs(x - collideVehicle->x); if (x_diff > 0x7FFF) return false; - + sint32 y_diff = abs(y - collideVehicle->y); if (y_diff > 0x7FFF) return false; - + if (x_diff + y_diff > 0xFFFF) return false; - + sint32 z_diff = abs(z - collideVehicle->z); if (x_diff + y_diff + z_diff > 0xFFFF) return false; - + uint16 ecx = min(vehicle->var_44 + collideVehicle->var_44, 560); ecx = ((ecx >> 1) * 30) >> 8; - + if (x_diff + y_diff + z_diff >= ecx) return false; - + uint8 direction = (vehicle->sprite_direction - collideVehicle->sprite_direction + 7) & 0x1F; if (direction >= 0xF) return false; - + return true; } - + uint16 eax = ((x / 32) << 8) + (y / 32); // TODO change to using a better technique uint32* ebp = RCT2_ADDRESS(0x009A37C4, uint32); @@ -6468,53 +6468,53 @@ static bool vehicle_update_motion_collision_detection( for(; collideId != 0xFFFF; collideId = collideVehicle->next_in_quadrant){ collideVehicle = GET_VEHICLE(collideId); if (collideVehicle == vehicle) continue; - + if (collideVehicle->sprite_identifier != SPRITE_IDENTIFIER_VEHICLE) continue; - + sint32 z_diff = abs(collideVehicle->z - z); - + if (z_diff > 16) continue; - + rct_ride_type_vehicle* collideType = vehicle_get_vehicle_entry(collideVehicle); - + if (!(collideType->flags_b & VEHICLE_ENTRY_FLAG_B_6)) continue; - + sint32 x_diff = abs(collideVehicle->x - x); if (x_diff > 0x7FFF) continue; - + sint32 y_diff = abs(collideVehicle->y - y); if (y_diff > 0x7FFF) continue; - + if (x_diff + y_diff > 0xFFFF) continue; - + uint8 cl = min(vehicle->var_CD, collideVehicle->var_CD); uint8 ch = max(vehicle->var_CD, collideVehicle->var_CD); if (cl != ch){ if (cl == 5 && ch == 6) continue; } - + uint32 ecx = vehicle->var_44 + collideVehicle->var_44; ecx = ((ecx >> 1) * 30) >> 8; - + if (x_diff + y_diff >= ecx) continue; - + if (!(collideType->flags_b & VEHICLE_ENTRY_FLAG_B_14)){ mayCollide = true; break; } - + uint8 direction = (vehicle->sprite_direction - collideVehicle->sprite_direction - 6) & 0x1F; - + if (direction < 0x14) continue; - + sint16 next_x_diff = abs(x + RCT2_ADDRESS(0x009A3B04, sint16)[vehicle->sprite_direction*2]-collideVehicle->x); sint16 next_y_diff = abs(y + RCT2_ADDRESS(0x009A3B06, sint16)[vehicle->sprite_direction*2]-collideVehicle->y); - + if (next_x_diff + next_y_diff < x_diff + y_diff){ mayCollide = true; break; } - + } if (mayCollide == true) { break; @@ -6523,12 +6523,12 @@ static bool vehicle_update_motion_collision_detection( // TODO change this eax += *ebp; } - + if (mayCollide == false) { vehicle->var_C4 = 0; return false; } - + vehicle->var_C4++; if (vehicle->var_C4 < 200) { vehicle->update_flags |= VEHICLE_UPDATE_FLAG_6; @@ -6538,7 +6538,7 @@ static bool vehicle_update_motion_collision_detection( } // TODO Is it possible for collideVehicle to be NULL? - + if (vehicle->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION){ if (vehicle->sprite_direction == 0) { if (vehicle->x <= collideVehicle->x) { @@ -6561,14 +6561,14 @@ static bool vehicle_update_motion_collision_detection( } } } - + if (collideVehicle->status == VEHICLE_STATUS_TRAVELLING_BOAT && vehicle->status != VEHICLE_STATUS_ARRIVING && vehicle->status != VEHICLE_STATUS_TRAVELLING ) { return false; } - + vehicle->update_flags |= VEHICLE_UPDATE_FLAG_6; if (otherVehicleIndex != NULL) *otherVehicleIndex = collideId; diff --git a/src/world/map.c b/src/world/map.c index d32136bdce..4228bc709d 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -897,7 +897,7 @@ void game_command_remove_large_scenery(int* eax, int* ebx, int* ecx, int* edx, i } *ebx = scenery_entry->large_scenery.removal_price * 10; - if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY || + if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY || calculate_cost == false){ *ebx = 0; } @@ -985,7 +985,7 @@ void game_command_set_scenery_colour(int* eax, int* ebx, int* ecx, int* edx, int // Previously it would do a search for type of bh (set from calling function) instead of just small scenery // Unsure if this was a mistake. rct_map_element* map_element = map_get_small_scenery_element_at(x, y, base_height, scenery_type); - + if (map_element == NULL) { *ebx = 0; return; @@ -1053,7 +1053,7 @@ void game_command_set_fence_colour(int* eax, int* ebx, int* ecx, int* edx, int* rct_scenery_entry* scenery_entry = g_wallSceneryEntries[map_element->properties.fence.type]; map_element->properties.fence.item[1] &= 0xE0; map_element->properties.fence.item[1] |= color1; - map_element->properties.fence.item[1] &= 0x1F; + map_element->properties.fence.item[1] &= 0x1F; map_element->flags &= 0x9F; map_element->properties.fence.item[1] |= (color2 & 0x7) * 32; map_element->flags |= (color2 & 0x18) * 4; @@ -1093,7 +1093,7 @@ void game_command_set_large_scenery_colour(int* eax, int* ebx, int* ecx, int* ed *ebx = 0; return; } - + if((flags & GAME_COMMAND_FLAG_GHOST) && !(map_element->flags & MAP_ELEMENT_FLAG_GHOST)){ *ebx = 0; return; @@ -1134,10 +1134,10 @@ void game_command_set_large_scenery_colour(int* eax, int* ebx, int* ecx, int* ed if(flags & GAME_COMMAND_FLAG_APPLY){ rct_map_element* mapElement = map_get_large_scenery_segment( - currentTile.x, - currentTile.y, - base_height, - map_element_direction, + currentTile.x, + currentTile.y, + base_height, + map_element_direction, i); mapElement->properties.scenerymultiple.colour[0] &= 0xE0; @@ -1567,7 +1567,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl return MONEY32_UNDEFINED; } } - + //Uncomment to use vanilla code /* registers regs = {0}; @@ -1581,7 +1581,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl regs.ebp = 0; RCT2_CALLFUNC_Y(0x006639FE, ®s); return regs.ebx; */ - + RCT2_GLOBAL(0x9E2E18, money32) = MONEY(0, 0); if(flags & GAME_COMMAND_FLAG_APPLY) { @@ -1589,10 +1589,10 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl map_remove_walls_at(x, y, height * 8 - 16, height * 8 + 32); } RCT2_GLOBAL(0x9E2E18, money32) += MONEY(20, 0); - + //Check for obstructing scenery - rct_map_element *mapElement = map_get_first_element_at(x / 32, y / 32); - do{ + rct_map_element *mapElement = map_get_first_element_at(x / 32, y / 32); + do{ if(map_element_get_type(mapElement) != MAP_ELEMENT_TYPE_SCENERY) continue; if(height > mapElement->clearance_height) @@ -1609,7 +1609,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl if(flags & GAME_COMMAND_FLAG_APPLY) map_element_remove(mapElement--); }while(!map_element_is_last_for_tile(mapElement++)); - + //Check for ride support limits if(gCheatsDisableSupportLimits==false) { @@ -1653,7 +1653,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl } } } - + zCorner = height; if(style & 0xF) { @@ -1663,14 +1663,14 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl zCorner += 2; } } - + if(map_can_construct_with_clear_at(x, y, height, zCorner, RCT2_ADDRESS(0x663CB9, void), 0xF) == false) return MONEY32_UNDEFINED; - + mapElement = map_get_first_element_at(x / 32, y / 32); - do{ + do{ int elementType = map_element_get_type(mapElement); - + if(elementType == MAP_ELEMENT_TYPE_FENCE) continue; if(elementType == MAP_ELEMENT_TYPE_SCENERY) @@ -1694,7 +1694,7 @@ static money32 map_set_land_height(int flags, int x, int y, int height, int styl return MONEY32_UNDEFINED; } }while(!map_element_is_last_for_tile(mapElement++)); - + if(flags & GAME_COMMAND_FLAG_APPLY) { surfaceElement = map_get_surface_element_at(x / 32, y / 32); @@ -3323,7 +3323,7 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in } } - + sint16 maxHeight = 0xFFFF; for (rct_large_scenery_tile* tile = scenery_entry->large_scenery.tiles; tile->x_offset != -1; @@ -3335,7 +3335,7 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in }; rotate_map_coordinates(&curTile.x, &curTile.y, rotation); - + curTile.x += x; curTile.y += y; @@ -3440,8 +3440,8 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in new_map_element->clearance_height = zHigh; new_map_element->type = MAP_ELEMENT_TYPE_SCENERY_MULTIPLE | rotation; - new_map_element->properties.scenerymultiple.type = - (tile_num << 10) | + new_map_element->properties.scenerymultiple.type = + (tile_num << 10) | entry_index; new_map_element->properties.scenerymultiple.colour[0] = color1; @@ -4894,7 +4894,7 @@ void game_command_set_banner_style(int* eax, int* ebx, int* ecx, int* edx, int* *ebx = MONEY32_UNDEFINED; return; } - + map_element->properties.banner.flags = 0xFF; if (banner->flags & BANNER_FLAG_NO_ENTRY){ map_element->properties.banner.flags &= ~(1 << map_element->properties.banner.position); @@ -4929,7 +4929,7 @@ void game_command_set_banner_style(int* eax, int* ebx, int* ecx, int* edx, int* *ebx = 0; } -void game_command_set_sign_style(int* eax, int* ebx, int* ecx, int* edx, int* esi, int* edi, int* ebp) { +void game_command_set_sign_style(int* eax, int* ebx, int* ecx, int* edx, int* esi, int* edi, int* ebp) { uint8 bannerId = *ecx & 0xFF; rct_banner *banner = &gBanners[bannerId]; int x = banner->x << 5; @@ -4937,9 +4937,9 @@ void game_command_set_sign_style(int* eax, int* ebx, int* ecx, int* edx, int* es uint8 mainColour = (uint8)*edx; uint8 textColour = (uint8)*edi; - + if (*ebp == 0) { // small sign - + rct_map_element* map_element = map_get_first_element_at(x / 32, y / 32); bool fence_found = false; do{ From 3d2a45648166ec4bd412fc595d81f4b900414c91 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 3 Jan 2016 11:10:02 +0000 Subject: [PATCH 155/162] Rework logic to make flow clearer. Fix issue with invalid direction. Fix small logic mistake. --- src/ride/vehicle.c | 52 ++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 5e18be5c29..22f6a8ba0d 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -7063,10 +7063,13 @@ bool vehicle_update_track_motion_backwards_get_new_track(rct_vehicle *vehicle, u 0 ); -loc_6DBB08:; + bool nextTileBackwards = true; + int direction; +//loc_6DBB08:; sint16 x = vehicle->track_x; sint16 y = vehicle->track_y; sint16 z = 0; + switch (vehicle->var_CD) { case 3: vehicle->var_CD = 1; @@ -7078,34 +7081,15 @@ loc_6DBB08:; vehicle->var_CD = 6; break; case 2: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: + case 4: vehicle->var_CD = 2; - loc_6DBB4F: - { - rct_xy_element input; - rct_xy_element output; - int outputZ; - int outputDirection; - - input.x = x; - input.y = y; - input.element = mapElement; - if (track_block_get_next(&input, &output, &outputZ, &outputDirection)) { - return false; - } - mapElement = output.element; - goto loc_6DBC3B; - } + nextTileBackwards = false; + break; } -loc_6DBB7E:; - int direction; - { + + if (nextTileBackwards == true) { + //loc_6DBB7E:; track_begin_end trackBeginEnd; if (!track_block_get_previous(x, y, mapElement, &trackBeginEnd)) { return false; @@ -7141,8 +7125,22 @@ loc_6DBB7E:; z = trackBeginEnd.begin_z; direction = trackBeginEnd.begin_direction; } + else { + //loc_6DBB4F:; + rct_xy_element input; + rct_xy_element output; + int outputZ; -loc_6DBC3B: + input.x = x; + input.y = y; + input.element = mapElement; + if (track_block_get_next(&input, &output, &outputZ, &direction)) { + return false; + } + mapElement = output.element; + } + +//loc_6DBC3B: vehicle->track_x = x; vehicle->track_y = y; vehicle->track_z = z; From 5e6befe20b4cf39f8924b1c4c45522913be02aee Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 4 Jan 2016 09:11:36 +0000 Subject: [PATCH 156/162] Fix 3D films only lasting 1 ticks time --- src/ride/vehicle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 22f6a8ba0d..fc9dad71af 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3929,7 +3929,7 @@ static void vehicle_update_showing_film(rct_vehicle *vehicle) return; totalTime = RideFilmLength[vehicle->sub_state]; - currentTime = vehicle->var_4C + 1; + currentTime = ((sint16)vehicle->var_4C) + 1; if (currentTime <= totalTime) { vehicle->var_4C = currentTime; } From ccc7b1f228078d6f94a1af0491da634c715e87b5 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 4 Jan 2016 09:36:29 +0000 Subject: [PATCH 157/162] Refactor var_4C into seperate variables --- src/ride/cable_lift.c | 2 +- src/ride/vehicle.c | 113 ++++++++++++++++++++++-------------------- src/ride/vehicle.h | 9 +++- 3 files changed, 67 insertions(+), 57 deletions(-) diff --git a/src/ride/cable_lift.c b/src/ride/cable_lift.c index 973e82812d..c1b0444256 100644 --- a/src/ride/cable_lift.c +++ b/src/ride/cable_lift.c @@ -33,7 +33,7 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d current->velocity = 0; current->acceleration = 0; current->var_4A = 0; - current->var_4C = 0; + current->swinging_car_var_0 = 0; current->var_4E = 0; current->restraints_position = 0; current->var_BA = 0; diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index fc9dad71af..0a2d96dd5b 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -642,7 +642,7 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ do { vehicle = GET_VEHICLE(vehicle_id); - vehicle->var_4C = 0; + vehicle->swinging_car_var_0 = 0; vehicle->var_4E = 0; vehicle->var_4A = 0; @@ -1672,7 +1672,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_CE = 0; - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle_update_swinging(vehicle); break; case RIDE_MODE_ROTATION: @@ -1680,7 +1680,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_CE = 0; - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle_update_rotating(vehicle); break; case RIDE_MODE_FILM_AVENGING_AVIATORS: @@ -1690,7 +1690,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { if (ride->mode == RIDE_MODE_FILM_THRILL_RIDERS) vehicle->sub_state = 1; vehicle_invalidate_window(vehicle); - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle_update_simulator_operating(vehicle); break; case RIDE_MODE_BEGINNERS: @@ -1710,7 +1710,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = 2; break; } - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle->var_1F = 0; vehicle->var_20 = 0; vehicle_update_top_spin_operating(vehicle); @@ -1721,7 +1721,8 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = vehicle->var_1F; vehicle_invalidate_window(vehicle); vehicle->var_CE = 0; - vehicle->var_4C = 0x808; + vehicle->ferris_wheel_var_0 = 8; + vehicle->ferris_wheel_var_1 = 8; vehicle_update_ferris_wheel_rotating(vehicle); break; case RIDE_MODE_3D_FILM_MOUSE_TAILS: @@ -1740,14 +1741,14 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = 2; break; } - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle_update_showing_film(vehicle); break; case RIDE_MODE_CIRCUS_SHOW: vehicle->status = VEHICLE_STATUS_DOING_CIRCUS_SHOW; vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle_update_doing_circus_show(vehicle); break; case RIDE_MODE_SPACE_RINGS: @@ -1755,7 +1756,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle_update_space_rings_operating(vehicle); break; case RIDE_MODE_HAUNTED_HOUSE: @@ -1763,7 +1764,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle_update_haunted_house_operating(vehicle); break; case RIDE_MODE_CROOKED_HOUSE: @@ -1771,7 +1772,7 @@ static void vehicle_update_waiting_to_depart(rct_vehicle* vehicle) { vehicle->sub_state = 0; vehicle_invalidate_window(vehicle); vehicle->var_1F = 0; - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle_update_crooked_house_operating(vehicle); break; default: @@ -3542,12 +3543,12 @@ static void vehicle_update_swinging(rct_vehicle* vehicle) { swingState += 4; } uint8* edi = RCT2_ADDRESS(0x0099F9D0, uint8*)[swingState]; - uint8 al = edi[(uint16)(vehicle->var_4C + 1)]; + uint8 al = edi[(uint16)(vehicle->current_time + 1)]; // 0x80 indicates that a complete swing has been // completed and the next swing can start if (al != 0x80) { - vehicle->var_4C++; + vehicle->current_time++; if (al == vehicle->var_1F) return; // Used to know which sprite to draw @@ -3556,7 +3557,7 @@ static void vehicle_update_swinging(rct_vehicle* vehicle) { return; } - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle->var_CE++; if (ride->status != RIDE_STATUS_CLOSED) { // It takes 3 swings to get into full swing @@ -3595,22 +3596,25 @@ static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle) { return; rct_ride* ride = GET_RIDE(vehicle->ride); - if (((vehicle->var_4C -= 0x100) & 0xFF00) != 0) + if ((vehicle->ferris_wheel_var_1 -= 1) != 0) return; - sint8 var_4C = vehicle->var_4C & 0xFF; + sint8 ferris_wheel_var_0 = vehicle->ferris_wheel_var_0; - if (var_4C == 3) { - vehicle->var_4C = (0xFF & var_4C) | (0xFF00 & (var_4C << 8)); + if (ferris_wheel_var_0 == 3) { + vehicle->ferris_wheel_var_0 = ferris_wheel_var_0; + vehicle->ferris_wheel_var_1 = ferris_wheel_var_0; } - else if (var_4C < 3) { - if (var_4C != -8) - var_4C--; - vehicle->var_4C = (0xFF & var_4C) | (0xFF00 & (-var_4C << 8)); + else if (ferris_wheel_var_0 < 3) { + if (ferris_wheel_var_0 != -8) + ferris_wheel_var_0--; + vehicle->ferris_wheel_var_0 = ferris_wheel_var_0; + vehicle->ferris_wheel_var_1 = -ferris_wheel_var_0; } else { - var_4C--; - vehicle->var_4C = (0xFF & var_4C) | (0xFF00 & (var_4C << 8)); + ferris_wheel_var_0--; + vehicle->ferris_wheel_var_0 = ferris_wheel_var_0; + vehicle->ferris_wheel_var_1 = ferris_wheel_var_0; } uint8 rotation = vehicle->var_1F; @@ -3642,13 +3646,12 @@ static void vehicle_update_ferris_wheel_rotating(rct_vehicle* vehicle) { } if (shouldStop) { - var_4C = (sint8)(vehicle->var_4C & 0xFF); - vehicle->var_4C &= 0xFF00; - vehicle->var_4C |= 0xFF & (-abs(var_4C)); + ferris_wheel_var_0 = vehicle->ferris_wheel_var_0; + vehicle->ferris_wheel_var_0 = -abs(ferris_wheel_var_0); } } - if ((sint8)(vehicle->var_4C & 0xFF) != -8) + if (vehicle->ferris_wheel_var_0 != -8) return; subState = vehicle->sub_state; @@ -3677,9 +3680,9 @@ static void vehicle_update_simulator_operating(rct_vehicle* vehicle) { uint8* edi = RCT2_ADDRESS(0x009A042C, uint8*)[vehicle->sub_state]; - uint8 al = edi[(uint16)(vehicle->var_4C + 1)]; + uint8 al = edi[(uint16)(vehicle->current_time + 1)]; if (al != 0xFF) { - vehicle->var_4C++; + vehicle->current_time++; if (al == vehicle->var_1F) return; vehicle->var_1F = al; @@ -3715,7 +3718,7 @@ static void vehicle_update_rotating(rct_vehicle* vehicle) { edi = RCT2_ADDRESS(0x0099EB1C, uint8*)[vehicle->sub_state]; } - sint32 var_4C = (sint16)vehicle->var_4C; + sint32 var_4C = (sint16)vehicle->current_time; if (RCT2_GLOBAL(0x00F64E34, uint8) == BREAKDOWN_CONTROL_FAILURE) { var_4C += (ride->var_1AC >> 6) + 1; } @@ -3723,7 +3726,7 @@ static void vehicle_update_rotating(rct_vehicle* vehicle) { uint8 al = edi[(uint32)var_4C]; if (al != 0xFF) { - vehicle->var_4C = (uint16)var_4C; + vehicle->current_time = (uint16)var_4C; if (al == vehicle->var_1F) return; vehicle->var_1F = al; @@ -3731,7 +3734,7 @@ static void vehicle_update_rotating(rct_vehicle* vehicle) { return; } - vehicle->var_4C = 0xFFFF; + vehicle->current_time = -1; vehicle->var_CE++; if (RCT2_GLOBAL(0x00F64E34, uint8) != BREAKDOWN_CONTROL_FAILURE) { bool shouldStop = true; @@ -3781,9 +3784,9 @@ static void vehicle_update_space_rings_operating(rct_vehicle* vehicle) { uint8* edi = RCT2_ADDRESS(0x009A0ACC, uint8*)[vehicle->sub_state]; - uint8 al = edi[(uint16)(vehicle->var_4C + 1)]; + uint8 al = edi[(uint16)(vehicle->current_time + 1)]; if (al != 0xFF) { - vehicle->var_4C++; + vehicle->current_time++; if (al == vehicle->var_1F) return; vehicle->var_1F = al; @@ -3818,7 +3821,7 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { uint16* edi = RCT2_ADDRESS(0x009A0ABC, uint16*)[vehicle->sub_state]; uint16 ax = *edi; - if ((uint16)(vehicle->var_4C + 1) > ax) { + if ((uint16)(vehicle->current_time + 1) > ax) { vehicle->status = VEHICLE_STATUS_ARRIVING; vehicle_invalidate_window(vehicle); vehicle->sub_state = 0; @@ -3826,8 +3829,8 @@ static void vehicle_update_haunted_house_operating(rct_vehicle* vehicle) { return; } - vehicle->var_4C++; - switch (vehicle->var_4C) { + vehicle->current_time++; + switch (vehicle->current_time) { case 45: audio_play_sound_at_location( SOUND_HAUNTED_HOUSE_SCARE, @@ -3875,7 +3878,7 @@ static void vehicle_update_crooked_house_operating(rct_vehicle* vehicle) { if (RCT2_GLOBAL(0x00F64E34, uint8) == 0) return; - if ((uint16)(vehicle->var_4C + 1) > RideCrookedHouseLength[vehicle->sub_state]) { + if ((uint16)(vehicle->current_time + 1) > RideCrookedHouseLength[vehicle->sub_state]) { vehicle->status = VEHICLE_STATUS_ARRIVING; vehicle_invalidate_window(vehicle); vehicle->sub_state = 0; @@ -3883,7 +3886,7 @@ static void vehicle_update_crooked_house_operating(rct_vehicle* vehicle) { return; } - vehicle->var_4C++; + vehicle->current_time++; } /** @@ -3896,14 +3899,14 @@ static void vehicle_update_top_spin_operating(rct_vehicle* vehicle) { uint8* edi = RCT2_ADDRESS(0x009A12E0, uint8*)[vehicle->sub_state]; - uint8 al = edi[((sint16)vehicle->var_4C + 1) * 2]; + uint8 al = edi[(vehicle->current_time + 1) * 2]; if (al != 0xFF) { - vehicle->var_4C = (sint16)vehicle->var_4C + 1; + vehicle->current_time = vehicle->current_time + 1; if (al != vehicle->var_1F) { vehicle->var_1F = al; vehicle_invalidate(vehicle); } - al = edi[vehicle->var_4C * 2 + 1]; + al = edi[vehicle->current_time * 2 + 1]; if (al != vehicle->var_20) { vehicle->var_20 = al; vehicle_invalidate(vehicle); @@ -3929,9 +3932,9 @@ static void vehicle_update_showing_film(rct_vehicle *vehicle) return; totalTime = RideFilmLength[vehicle->sub_state]; - currentTime = ((sint16)vehicle->var_4C) + 1; + currentTime = vehicle->current_time + 1; if (currentTime <= totalTime) { - vehicle->var_4C = currentTime; + vehicle->current_time = currentTime; } else { vehicle->status = VEHICLE_STATUS_ARRIVING; @@ -3953,9 +3956,9 @@ static void vehicle_update_doing_circus_show(rct_vehicle *vehicle) return; totalTime = *(RCT2_ADDRESS(0x009A0AB4, uint16*)[vehicle->sub_state]); - currentTime = vehicle->var_4C + 1; + currentTime = vehicle->current_time + 1; if (currentTime <= totalTime) { - vehicle->var_4C = currentTime; + vehicle->current_time = currentTime; } else { vehicle->status = VEHICLE_STATUS_ARRIVING; vehicle_invalidate_window(vehicle); @@ -5568,7 +5571,7 @@ static int vehicle_get_swing_amount(rct_vehicle *vehicle) static void vehicle_update_swinging_car(rct_vehicle *vehicle) { sint32 dword_F64E08 = RCT2_GLOBAL(0x00F64E08, sint32); - vehicle->var_4E = (-(sint16)vehicle->var_4C) >> 6; + vehicle->var_4E = (-vehicle->swinging_car_var_0) >> 6; int swingAmount = vehicle_get_swing_amount(vehicle); if (swingAmount < 0) { vehicle->var_4E -= dword_F64E08 >> (-swingAmount); @@ -5624,9 +5627,9 @@ static void vehicle_update_swinging_car(rct_vehicle *vehicle) } } - vehicle->var_4C += vehicle->var_4E; + vehicle->swinging_car_var_0 += vehicle->var_4E; vehicle->var_4E -= vehicle->var_4E >> 5; - sint16 ax = vehicle->var_4C; + sint16 ax = vehicle->swinging_car_var_0; if (ax > dx) { ax = dx; vehicle->var_4E = 0; @@ -5636,7 +5639,7 @@ static void vehicle_update_swinging_car(rct_vehicle *vehicle) vehicle->var_4E = 0; } - vehicle->var_4C = ax; + vehicle->swinging_car_var_0 = ax; uint8 bl = 11; if (ax >= -10012) { bl = 12; @@ -6987,7 +6990,7 @@ loc_6DB8A5: if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_9) && moveInfo->var_07 != 0) { vehicle->var_4A = 0; - vehicle->var_4C = 0; + vehicle->swinging_car_var_0 = 0; vehicle->var_4E = 0; } @@ -7265,7 +7268,7 @@ loc_6DBD42: if ((vehicleEntry->flags_b & VEHICLE_ENTRY_FLAG_B_9) && regs.bl != 0) { vehicle->var_4A = 0; - vehicle->var_4C = 0; + vehicle->swinging_car_var_0 = 0; vehicle->var_4E = 0; } @@ -7914,7 +7917,7 @@ loc_6DC8A1: if (rideEntry->vehicles[0].flags_b & VEHICLE_ENTRY_FLAG_B_9) { if (vehicle->var_1F != 0) { vehicle->var_4A = 0; - vehicle->var_4C = 0; + vehicle->swinging_car_var_0 = 0; vehicle->var_4E = 0; } } @@ -8054,7 +8057,7 @@ loc_6DCC2C: if (rideEntry->vehicles[0].flags_b & VEHICLE_ENTRY_FLAG_B_9) { if (vehicle->var_1F != 0) { vehicle->var_4A = 0; - vehicle->var_4C = 0; + vehicle->swinging_car_var_0 = 0; vehicle->var_4E = 0; } } diff --git a/src/ride/vehicle.h b/src/ride/vehicle.h index 484b49f768..367cfc1644 100644 --- a/src/ride/vehicle.h +++ b/src/ride/vehicle.h @@ -140,7 +140,14 @@ typedef struct { uint16 update_flags; // 0x48 uint8 var_4A; uint8 current_station; // 0x4B - uint16 var_4C; + union { + sint16 swinging_car_var_0; // 0x4C + sint16 current_time; // 0x4C + struct { + sint8 ferris_wheel_var_0; // 0x4C + sint8 ferris_wheel_var_1; // 0x4D + }; + }; uint16 var_4E; uint8 status; // 0x50 uint8 sub_state; // 0x51 From d5bce19af1349021e2e03861d864af05842fcaf4 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Mon, 4 Jan 2016 10:06:26 +0000 Subject: [PATCH 158/162] Fix race car mode collisions --- src/ride/vehicle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 0a2d96dd5b..2df1f6f893 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -6510,8 +6510,8 @@ static bool vehicle_update_motion_collision_detection( if (direction < 0x14) continue; - sint16 next_x_diff = abs(x + RCT2_ADDRESS(0x009A3B04, sint16)[vehicle->sprite_direction*2]-collideVehicle->x); - sint16 next_y_diff = abs(y + RCT2_ADDRESS(0x009A3B06, sint16)[vehicle->sprite_direction*2]-collideVehicle->y); + sint16 next_x_diff = abs(x + RCT2_ADDRESS(0x009A3B04, sint16)[((4 + vehicle->sprite_direction) >> 3) * 2] - collideVehicle->x); + sint16 next_y_diff = abs(y + RCT2_ADDRESS(0x009A3B06, sint16)[((4 + vehicle->sprite_direction) >> 3) *2]-collideVehicle->y); if (next_x_diff + next_y_diff < x_diff + y_diff){ mayCollide = true; From 8e0413bd2f6ba6feba264a32b883b8a7dfc41c4f Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 9 Jan 2016 15:57:55 +0000 Subject: [PATCH 159/162] Fix mechanics not being called to broken down rides --- src/ride/vehicle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 2df1f6f893..7b625c4ac8 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -2158,6 +2158,7 @@ static void vehicle_update_departing(rct_vehicle* vehicle) { RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST | RIDE_INVALIDATE_RIDE_MAINTENANCE; + ride->mechanic_status = RIDE_MECHANIC_STATUS_CALLING; ride->inspection_station = vehicle->current_station; ride->breakdown_reason = ride->breakdown_reason_pending; vehicle->velocity = 0; From 326c1f276a8d302bd3761386dc680a9e6b502db4 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sat, 9 Jan 2016 16:17:04 +0000 Subject: [PATCH 160/162] Fix fixed broken restraints causing the train to get stuck in a loop --- src/ride/vehicle.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 7b625c4ac8..59e1974623 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -714,7 +714,6 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ ride->breakdown_reason = ride->breakdown_reason_pending; } - } else{ if (vehicle->restraints_position + 20 > 0xFF){ @@ -722,10 +721,9 @@ static int vehicle_open_restraints(rct_vehicle* vehicle){ continue; } vehicle->restraints_position += 20; - vehicle_invalidate(vehicle); - ebp++; } - + vehicle_invalidate(vehicle); + ebp++; } while ((vehicle_id = vehicle->next_vehicle_on_train) != 0xFFFF); return ebp; From 8e74815200ff7a4a78097c0fbcb0da05f938377e Mon Sep 17 00:00:00 2001 From: LRFLEW Date: Sat, 9 Jan 2016 15:58:25 -0700 Subject: [PATCH 161/162] Added ride/cable_lift.c to Xcode project --- OpenRCT2.xcodeproj/project.pbxproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index ab52dad826..4fe426a7dc 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ D43532601C34730200BA219B /* libpng.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D435325E1C3472E500BA219B /* libpng.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; D46105CE1C38828D00DB1EE3 /* scenario_sources.c in Sources */ = {isa = PBXBuildFile; fileRef = D46105CD1C38828D00DB1EE3 /* scenario_sources.c */; }; D4ABAB061C2F812B0080CAD9 /* news_options.c in Sources */ = {isa = PBXBuildFile; fileRef = D4ABAB051C2F812B0080CAD9 /* news_options.c */; }; + D4B85B5B1C41C7F3005C568A /* cable_lift.c in Sources */ = {isa = PBXBuildFile; fileRef = D4B85B591C41C7F3005C568A /* cable_lift.c */; }; D4D4DF141C34697B0048BE43 /* image_io.c in Sources */ = {isa = PBXBuildFile; fileRef = D4D4DF121C34697B0048BE43 /* image_io.c */; }; D4EC47DF1C26342F0024B507 /* addresses.c in Sources */ = {isa = PBXBuildFile; fileRef = D4EC46D61C26342F0024B507 /* addresses.c */; }; D4EC47E01C26342F0024B507 /* audio.c in Sources */ = {isa = PBXBuildFile; fileRef = D4EC46D91C26342F0024B507 /* audio.c */; }; @@ -222,6 +223,8 @@ D4895D321C23EFDD000CD788 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = distribution/osx/Info.plist; sourceTree = SOURCE_ROOT; }; D497D0781C20FD52002BF46A /* OpenRCT2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenRCT2.app; sourceTree = BUILT_PRODUCTS_DIR; }; D4ABAB051C2F812B0080CAD9 /* news_options.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = news_options.c; sourceTree = ""; }; + D4B85B591C41C7F3005C568A /* cable_lift.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cable_lift.c; sourceTree = ""; }; + D4B85B5A1C41C7F3005C568A /* cable_lift.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cable_lift.h; sourceTree = ""; }; D4D4DF121C34697B0048BE43 /* image_io.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = image_io.c; path = src/image_io.c; sourceTree = ""; }; D4D4DF131C34697B0048BE43 /* image_io.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = image_io.h; path = src/image_io.h; sourceTree = ""; }; D4EC46D61C26342F0024B507 /* addresses.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = addresses.c; path = src/addresses.c; sourceTree = ""; }; @@ -859,6 +862,8 @@ D4EC475C1C26342F0024B507 /* ride */ = { isa = PBXGroup; children = ( + D4B85B591C41C7F3005C568A /* cable_lift.c */, + D4B85B5A1C41C7F3005C568A /* cable_lift.h */, D4EC475D1C26342F0024B507 /* ride.c */, D4EC475E1C26342F0024B507 /* ride.h */, D4EC475F1C26342F0024B507 /* ride_data.c */, @@ -1451,6 +1456,7 @@ D4EC48111C26342F0024B507 /* network.cpp in Sources */, D4EC47FF1C26342F0024B507 /* widget.c in Sources */, D4EC48691C26342F0024B507 /* title_options.c in Sources */, + D4B85B5B1C41C7F3005C568A /* cable_lift.c in Sources */, D4EC48471C26342F0024B507 /* map_tooltip.c in Sources */, D4EC483F1C26342F0024B507 /* guest.c in Sources */, D4EC487A1C26342F0024B507 /* map_helpers.c in Sources */, From b16337a035c2e8c6465fce8b14d123df6b3bea21 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 10 Jan 2016 09:24:56 +0000 Subject: [PATCH 162/162] Refactor to remove all remaining warnings and remove redundant comments --- src/ride/vehicle.c | 67 +++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/src/ride/vehicle.c b/src/ride/vehicle.c index 59e1974623..afe238067c 100644 --- a/src/ride/vehicle.c +++ b/src/ride/vehicle.c @@ -3203,10 +3203,6 @@ static void loc_6DA9F9(rct_vehicle *vehicle, int x, int y, int bx, int dx) static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) { // RCT2_CALLPROC_X(0x006DA717, 0, 0, 0, 0, (int)vehicle, 0, 0); - - //////////////////////////////////////////////// - // TODO fix bugs with this function - //////////////////////////////////////////////// RCT2_GLOBAL(0x00F64E18, uint32) = 0; vehicle->velocity += vehicle->acceleration; RCT2_GLOBAL(0x00F64E08, sint32) = vehicle->velocity; @@ -3228,7 +3224,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) vehicle_invalidate(vehicle); for (;;) { - loc_6DA7A5: + // loc_6DA7A5 vehicle->var_35++; int x = (vehicle->boat_location.x * 32) + 16; int y = (vehicle->boat_location.y * 32) + 16; @@ -3314,7 +3310,13 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) y = vehicle->y + RCT2_ADDRESS(0x009A36C6, sint16)[edi * 4]; z = vehicle->z; if (vehicle_update_motion_collision_detection(vehicle, x, y, z, NULL)) { - goto loc_6DAA79; + vehicle->remaining_distance = 0; + if (vehicle->sprite_direction == vehicle->var_34) { + vehicle->sprite_direction ^= (1 << 4); + sub_6DA280(vehicle); + vehicle->sprite_direction ^= (1 << 4); + } + break; } int bx = floor2(x, 32); @@ -3340,14 +3342,14 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) if (vehicle->sprite_direction == vehicle->var_34) { sub_6DA280(vehicle); } - goto loc_6DAAAB; + break; } if (!(ride->boat_hire_return_direction & 1)) { uint16 bp = y & 0x1F; if (bp == 16) { loc_6DA9F9(vehicle, x, y, bx, dx); - goto loc_6DAAAB; + break; } if (bp <= 16) { x = unk_F64E20->x; @@ -3361,7 +3363,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) uint16 bp = x & 0x1F; if (bp == 16) { loc_6DA9F9(vehicle, x, y, bx, dx); - goto loc_6DAAAB; + break; } if (bp <= 16) { x = unk_F64E20->x + 1; @@ -3378,7 +3380,7 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) unk_F64E20->x = x; unk_F64E20->y = y; } - goto loc_6DAAAB; + break; } vehicle->track_x = bx; vehicle->track_y = dx; @@ -3388,20 +3390,11 @@ static void vehicle_update_motion_boat_hire(rct_vehicle *vehicle) unk_F64E20->x = x; unk_F64E20->y = y; if (vehicle->remaining_distance < 0x368A) { - goto loc_6DAAAB; + break; } RCT2_GLOBAL(0x00F64E10, uint32)++; } - loc_6DAA79: - vehicle->remaining_distance = 0; - if (vehicle->sprite_direction == vehicle->var_34) { - vehicle->sprite_direction ^= (1 << 4); - sub_6DA280(vehicle); - vehicle->sprite_direction ^= (1 << 4); - } - - loc_6DAAAB: sprite_move( unk_F64E20->x, unk_F64E20->y, @@ -6481,10 +6474,10 @@ static bool vehicle_update_motion_collision_detection( if (!(collideType->flags_b & VEHICLE_ENTRY_FLAG_B_6)) continue; - sint32 x_diff = abs(collideVehicle->x - x); + uint32 x_diff = abs(collideVehicle->x - x); if (x_diff > 0x7FFF) continue; - sint32 y_diff = abs(collideVehicle->y - y); + uint32 y_diff = abs(collideVehicle->y - y); if (y_diff > 0x7FFF) continue; if (x_diff + y_diff > 0xFFFF) continue; @@ -6509,8 +6502,8 @@ static bool vehicle_update_motion_collision_detection( if (direction < 0x14) continue; - sint16 next_x_diff = abs(x + RCT2_ADDRESS(0x009A3B04, sint16)[((4 + vehicle->sprite_direction) >> 3) * 2] - collideVehicle->x); - sint16 next_y_diff = abs(y + RCT2_ADDRESS(0x009A3B06, sint16)[((4 + vehicle->sprite_direction) >> 3) *2]-collideVehicle->y); + uint32 next_x_diff = abs(x + RCT2_ADDRESS(0x009A3B04, sint16)[((4 + vehicle->sprite_direction) >> 3) * 2] - collideVehicle->x); + uint32 next_y_diff = abs(y + RCT2_ADDRESS(0x009A3B06, sint16)[((4 + vehicle->sprite_direction) >> 3) * 2] - collideVehicle->y); if (next_x_diff + next_y_diff < x_diff + y_diff){ mayCollide = true; @@ -6817,7 +6810,7 @@ loc_6DB41D: } } -loc_6DB500: + // loc_6DB500 // Update VEHICLE_UPDATE_FLAG_0 vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_0; if (track_element_is_lift_hill(mapElement)) { @@ -6935,7 +6928,7 @@ loc_6DAEB9: vehicle->track_progress = regs.ax; vehicle_update_handle_water_splash(vehicle); -loc_6DB706:; + // loc_6DB706 moveInfo = vehicle_get_move_info( vehicle->var_CD, vehicle->track_type, @@ -6975,7 +6968,7 @@ loc_6DB706:; y = vehicle->y + moveInfo2->y; } -loc_6DB8A5: + // loc_6DB8A5 regs.ebx = RCT2_ADDRESS(0x009A2930, sint32)[regs.ebx]; vehicle->remaining_distance -= regs.ebx; unk_F64E20->x = x; @@ -7003,7 +6996,7 @@ loc_6DB8A5: } } -loc_6DB928: + // loc_6DB928 if (vehicle->remaining_distance < 0x368A) { return true; } @@ -7239,7 +7232,7 @@ loc_6DBA33:; } } -loc_6DBD42: + // loc_6DBD42 vehicle->track_progress = regs.ax; const rct_vehicle_info* moveInfo = vehicle_get_move_info( vehicle->var_CD, @@ -7280,7 +7273,7 @@ loc_6DBD42: } } -loc_6DBE3F: + // loc_6DBE3F if ((sint32)vehicle->remaining_distance >= 0) { return true; } @@ -7432,14 +7425,14 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) continue; } } - loc_6DBF20: + // loc_6DBF20 sprite_move(unk_F64E20->x, unk_F64E20->y, unk_F64E20->z, (rct_sprite*)car); invalidate_sprite_2((rct_sprite*)car); loc_6DBF3E: sub_6DBF3E(car); - loc_6DC0F7: + // loc_6DC0F7 if (car->update_flags & VEHICLE_UPDATE_FLAG_0) { RCT2_GLOBAL(0x00F64E18, uint32) |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_ON_LIFT_HILL; } @@ -7453,7 +7446,7 @@ int vehicle_update_track_motion(rct_vehicle *vehicle, int *outStation) spriteId = car->prev_vehicle_on_ride; } } -loc_6DC144: + // loc_6DC144 vehicle = RCT2_GLOBAL(0x00F64E04, rct_vehicle*); //eax sint32 totalAcceleration = 0; @@ -7739,7 +7732,7 @@ loc_6DC476: vehicle->var_D5 &= ~(1 << 3); } -loc_6DC5B8:; + // loc_6DC5B8 const rct_vehicle_info* moveInfo = vehicle_get_move_info(vehicle->var_CD, vehicle->track_type, 0); // There are two bytes before the move info list @@ -7839,7 +7832,7 @@ loc_6DC743: vehicle->track_progress++; break; case 1: // loc_6DC7ED - vehicle->var_D3 = moveInfo->z; + vehicle->var_D3 = (uint8)moveInfo->z; vehicle->track_progress++; break; case 2: // loc_6DC800 @@ -7864,7 +7857,7 @@ loc_6DC743: z = 8; } } - vehicle->var_D4 = z; + vehicle->var_D4 = (uint8)z; vehicle->var_C5 = 0; vehicle->track_progress++; break; @@ -7884,7 +7877,7 @@ loc_6DC743: } } -loc_6DC8A1: + // loc_6DC8A1 x = vehicle->track_x + moveInfo->x; y = vehicle->track_y + moveInfo->y; z = vehicle->track_z + moveInfo->z + RCT2_GLOBAL(0x0097D21A + (ride->type * 8), sint8);