Fix Water Ride spinning on slope bug. Name flags. Refactor

There was a bug in the spinning water ride code that would mean that it would never trigger the stopping of spinning when going up a lift. This mistake was made during implementation of the function.
This commit is contained in:
duncanspumpkin 2018-01-09 18:40:52 +00:00 committed by Duncan
parent f9d6203200
commit 96f664abb9
4 changed files with 52 additions and 56 deletions

View File

@ -3825,7 +3825,7 @@ static void window_ride_maintenance_dropdown(rct_window *w, rct_widgetindex widg
vehicle = GET_VEHICLE(spriteId); vehicle = GET_VEHICLE(spriteId);
vehicle->update_flags &= ~( vehicle->update_flags &= ~(
VEHICLE_UPDATE_FLAG_BROKEN_CAR | VEHICLE_UPDATE_FLAG_BROKEN_CAR |
VEHICLE_UPDATE_FLAG_7 | VEHICLE_UPDATE_FLAG_ZERO_VELOCITY |
VEHICLE_UPDATE_FLAG_BROKEN_TRAIN VEHICLE_UPDATE_FLAG_BROKEN_TRAIN
); );
spriteId = vehicle->next_vehicle_on_train; spriteId = vehicle->next_vehicle_on_train;

View File

@ -6854,7 +6854,7 @@ void ride_fix_breakdown(sint32 rideIndex, sint32 reliabilityIncreaseFactor)
uint16 spriteIndex = ride->vehicles[i]; uint16 spriteIndex = ride->vehicles[i];
while (spriteIndex != SPRITE_INDEX_NULL) { while (spriteIndex != SPRITE_INDEX_NULL) {
rct_vehicle *vehicle = GET_VEHICLE(spriteIndex); rct_vehicle *vehicle = GET_VEHICLE(spriteIndex);
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_7; vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_ZERO_VELOCITY;
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_BROKEN_CAR; vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_BROKEN_CAR;
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_BROKEN_TRAIN; vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_BROKEN_TRAIN;
spriteIndex = vehicle->next_vehicle_on_train; spriteIndex = vehicle->next_vehicle_on_train;

View File

@ -91,6 +91,7 @@ static bool vehicle_can_depart_synchronised(rct_vehicle * vehicle);
#define VEHICLE_MAX_SPIN_SPEED 1536 #define VEHICLE_MAX_SPIN_SPEED 1536
#define VEHICLE_MAX_SPIN_SPEED_FOR_STOPPING 700 #define VEHICLE_MAX_SPIN_SPEED_FOR_STOPPING 700
#define VEHICLE_MAX_SPIN_SPEED_WATER_RIDE 512
#define VEHICLE_STOPPING_SPIN_SPEED 600 #define VEHICLE_STOPPING_SPIN_SPEED 600
rct_vehicle * gCurrentVehicle; rct_vehicle * gCurrentVehicle;
@ -1944,10 +1945,10 @@ static void vehicle_update(rct_vehicle * vehicle)
_vehicleBreakdown = ride->breakdown_reason_pending; _vehicleBreakdown = ride->breakdown_reason_pending;
if ((vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED) && ride->breakdown_reason_pending == BREAKDOWN_SAFETY_CUT_OUT) if ((vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED) && ride->breakdown_reason_pending == BREAKDOWN_SAFETY_CUT_OUT)
{ {
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_29) || if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_WATER_RIDE) ||
(vehicle->vehicle_sprite_type == 2 && vehicle->velocity <= 0x20000)) (vehicle->vehicle_sprite_type == 2 && vehicle->velocity <= 0x20000))
{ {
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; vehicle->update_flags |= VEHICLE_UPDATE_FLAG_ZERO_VELOCITY;
} }
} }
} }
@ -3356,7 +3357,7 @@ static void vehicle_update_departing(rct_vehicle * vehicle)
{ {
if (_vehicleBreakdown == BREAKDOWN_SAFETY_CUT_OUT) if (_vehicleBreakdown == BREAKDOWN_SAFETY_CUT_OUT)
{ {
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; vehicle->update_flags |= VEHICLE_UPDATE_FLAG_ZERO_VELOCITY;
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1; vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1;
} }
} }
@ -3374,7 +3375,7 @@ static void vehicle_update_departing(rct_vehicle * vehicle)
{ {
if (_vehicleBreakdown == BREAKDOWN_SAFETY_CUT_OUT) if (_vehicleBreakdown == BREAKDOWN_SAFETY_CUT_OUT)
{ {
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; vehicle->update_flags |= VEHICLE_UPDATE_FLAG_ZERO_VELOCITY;
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1; vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1;
} }
} }
@ -3794,7 +3795,7 @@ static void vehicle_update_travelling(rct_vehicle * vehicle)
if (_vehicleBreakdown == 0) if (_vehicleBreakdown == 0)
{ {
vehicle->var_B8 &= ~(1 << 1); vehicle->var_B8 &= ~(1 << 1);
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; vehicle->update_flags |= VEHICLE_UPDATE_FLAG_ZERO_VELOCITY;
} }
} }
} }
@ -3810,7 +3811,7 @@ static void vehicle_update_travelling(rct_vehicle * vehicle)
{ {
if (_vehicleBreakdown == 0) if (_vehicleBreakdown == 0)
{ {
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_7; vehicle->update_flags |= VEHICLE_UPDATE_FLAG_ZERO_VELOCITY;
vehicle->var_B8 &= ~(1 << 1); vehicle->var_B8 &= ~(1 << 1);
} }
} }
@ -6719,7 +6720,7 @@ static void check_and_apply_block_section_stop_site(rct_vehicle * vehicle)
static void update_velocity(rct_vehicle * vehicle) static void update_velocity(rct_vehicle * vehicle)
{ {
sint32 nextVelocity = vehicle->acceleration + vehicle->velocity; sint32 nextVelocity = vehicle->acceleration + vehicle->velocity;
if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_7) if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_ZERO_VELOCITY)
{ {
nextVelocity = 0; nextVelocity = 0;
} }
@ -9425,7 +9426,7 @@ loc_6DCEFF:
regs.eax *= regs.edx; regs.eax *= regs.edx;
regs.eax = regs.eax / regs.ebx; regs.eax = regs.eax / regs.ebx;
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_29)) if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_WATER_RIDE))
{ {
goto loc_6DD054; goto loc_6DD054;
} }
@ -9437,7 +9438,7 @@ loc_6DCEFF:
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING) if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING)
{ {
vehicle->spin_speed = Math::Clamp(static_cast<sint16>(-0x200), (sint16)vehicle->spin_speed, static_cast<sint16>(0x200)); vehicle->spin_speed = Math::Clamp(static_cast<sint16>(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE), (sint16)vehicle->spin_speed, static_cast<sint16>(VEHICLE_MAX_SPIN_SPEED_WATER_RIDE));
} }
if (vehicle->vehicle_sprite_type != 0) if (vehicle->vehicle_sprite_type != 0)
@ -9622,7 +9623,7 @@ sint32 vehicle_update_track_motion(rct_vehicle * vehicle, sint32 * outStation)
// eax // eax
sint32 totalAcceleration = 0; sint32 totalAcceleration = 0;
// ebp // ebp
sint32 totalFriction = 0; sint32 totalMass = 0;
// Not used // Not used
regs.dx = 0; regs.dx = 0;
// ebx // ebx
@ -9633,7 +9634,7 @@ sint32 vehicle_update_track_motion(rct_vehicle * vehicle, sint32 * outStation)
numVehicles++; numVehicles++;
// Not used? // Not used?
regs.dx |= vehicle->update_flags; regs.dx |= vehicle->update_flags;
totalFriction += vehicle->mass; totalMass += vehicle->mass;
totalAcceleration += vehicle->acceleration; totalAcceleration += vehicle->acceleration;
uint16 spriteIndex = vehicle->next_vehicle_on_train; uint16 spriteIndex = vehicle->next_vehicle_on_train;
@ -9676,9 +9677,9 @@ sint32 vehicle_update_track_motion(rct_vehicle * vehicle, sint32 * outStation)
regs.edx >>= 4; regs.edx >>= 4;
regs.eax = regs.edx; regs.eax = regs.edx;
// OpenRCT2: vehicles from different track types can have 0 mass. // OpenRCT2: vehicles from different track types can have 0 mass.
if (totalFriction != 0) if (totalMass != 0)
{ {
regs.eax = regs.eax / totalFriction; regs.eax = regs.eax / totalMass;
} }
regs.ecx -= regs.eax; regs.ecx -= regs.eax;
@ -9728,7 +9729,7 @@ loc_6DC238:
loc_6DC23A: loc_6DC23A:
regs.ebx = regs.eax; regs.ebx = regs.eax;
regs.eax <<= 14; regs.eax <<= 14;
regs.ebx *= totalFriction; regs.ebx *= totalMass;
regs.ebx >>= 2; regs.ebx >>= 2;
if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_3) if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_3)
{ {
@ -9748,11 +9749,8 @@ loc_6DC23A:
regs.eax *= 4; regs.eax *= 4;
} }
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_29)) if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_WATER_RIDE)
{ {
goto loc_6DC2E3;
}
if (regs.eax < 0) if (regs.eax < 0)
{ {
regs.eax >>= 4; regs.eax >>= 4;
@ -9760,7 +9758,7 @@ loc_6DC23A:
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING) if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING)
{ {
vehicle->spin_speed = Math::Clamp(static_cast<sint16>(-0x200), (sint16)vehicle->spin_speed, static_cast<sint16>(0x200)); vehicle->spin_speed = Math::Clamp(static_cast<sint16>(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE), (sint16)vehicle->spin_speed, static_cast<sint16>(VEHICLE_MAX_SPIN_SPEED_WATER_RIDE));
} }
if (vehicle->vehicle_sprite_type != 0) if (vehicle->vehicle_sprite_type != 0)
@ -9770,8 +9768,9 @@ loc_6DC23A:
regs.eax = 0; regs.eax = 0;
} }
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING)) if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING)
{ {
// If the vehicle is on the up slope kill the spin speed
if (vehicle->vehicle_sprite_type == 2) if (vehicle->vehicle_sprite_type == 2)
{ {
vehicle->spin_speed = 0; vehicle->spin_speed = 0;
@ -9779,13 +9778,10 @@ loc_6DC23A:
} }
goto loc_6DC2F6; goto loc_6DC2F6;
} }
loc_6DC2E3:
regs.ebx = vehicle->velocity;
if (regs.ebx < 0)
{
regs.ebx = -regs.ebx;
} }
regs.ebx = std::abs(vehicle->velocity);
if (regs.ebx <= 0x10000) if (regs.ebx <= 0x10000)
{ {
regs.ecx = 0; regs.ecx = 0;

View File

@ -248,7 +248,7 @@ enum {
VEHICLE_ENTRY_FLAG_26 = 1 << 26, VEHICLE_ENTRY_FLAG_26 = 1 << 26,
VEHICLE_ENTRY_FLAG_27 = 1 << 27, VEHICLE_ENTRY_FLAG_27 = 1 << 27,
VEHICLE_ENTRY_FLAG_28 = 1 << 28, VEHICLE_ENTRY_FLAG_28 = 1 << 28,
VEHICLE_ENTRY_FLAG_29 = 1 << 29, VEHICLE_ENTRY_FLAG_WATER_RIDE = 1 << 29, // Set on rides where water would provide continuous propulsion
VEHICLE_ENTRY_FLAG_30 = 1 << 30, VEHICLE_ENTRY_FLAG_30 = 1 << 30,
VEHICLE_ENTRY_FLAG_31 = 1u << 31, VEHICLE_ENTRY_FLAG_31 = 1u << 31,
}; };
@ -295,7 +295,7 @@ enum{
VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART = (1 << 4), VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART = (1 << 4),
VEHICLE_UPDATE_FLAG_TESTING = (1 << 5), VEHICLE_UPDATE_FLAG_TESTING = (1 << 5),
VEHICLE_UPDATE_FLAG_6 = (1 << 6), VEHICLE_UPDATE_FLAG_6 = (1 << 6),
VEHICLE_UPDATE_FLAG_7 = (1 << 7), VEHICLE_UPDATE_FLAG_ZERO_VELOCITY = (1 << 7), // Used on rides when safety cutout stops them on a lift
VEHICLE_UPDATE_FLAG_BROKEN_CAR = (1 << 8), VEHICLE_UPDATE_FLAG_BROKEN_CAR = (1 << 8),
VEHICLE_UPDATE_FLAG_BROKEN_TRAIN = (1 << 9), VEHICLE_UPDATE_FLAG_BROKEN_TRAIN = (1 << 9),
VEHICLE_UPDATE_FLAG_ON_BREAK_FOR_DROP = (1 << 10), VEHICLE_UPDATE_FLAG_ON_BREAK_FOR_DROP = (1 << 10),