mirror of https://github.com/OpenRCT2/OpenRCT2.git
Refactor DodgemsCarWouldCollideAt to return optional (#16695)
This commit is contained in:
parent
501328bc9a
commit
f44d944b26
|
@ -3194,7 +3194,7 @@ static Vehicle* vehicle_create_car(
|
||||||
vehicle->sprite_direction = scenario_rand() & 0x1E;
|
vehicle->sprite_direction = scenario_rand() & 0x1E;
|
||||||
chosenLoc.y = dodgemPos.y + (scenario_rand() & 0xFF);
|
chosenLoc.y = dodgemPos.y + (scenario_rand() & 0xFF);
|
||||||
chosenLoc.x = dodgemPos.x + (scenario_rand() & 0xFF);
|
chosenLoc.x = dodgemPos.x + (scenario_rand() & 0xFF);
|
||||||
} while (vehicle->DodgemsCarWouldCollideAt(chosenLoc, nullptr));
|
} while (vehicle->DodgemsCarWouldCollideAt(chosenLoc).has_value());
|
||||||
|
|
||||||
vehicle->MoveTo({ chosenLoc, dodgemPos.z });
|
vehicle->MoveTo({ chosenLoc, dodgemPos.z });
|
||||||
}
|
}
|
||||||
|
|
|
@ -6262,7 +6262,7 @@ int32_t Vehicle::UpdateMotionDodgems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto collideSprite = EntityId::GetNull();
|
std::optional<EntityId> collideSprite;
|
||||||
if (DodgemsCollisionDirection != 0)
|
if (DodgemsCollisionDirection != 0)
|
||||||
{
|
{
|
||||||
uint8_t oldCollisionDirection = DodgemsCollisionDirection & 0x1E;
|
uint8_t oldCollisionDirection = DodgemsCollisionDirection & 0x1E;
|
||||||
|
@ -6275,7 +6275,7 @@ int32_t Vehicle::UpdateMotionDodgems()
|
||||||
location.x += Unk9A36C4[oldCollisionDirection + 1].x;
|
location.x += Unk9A36C4[oldCollisionDirection + 1].x;
|
||||||
location.y += Unk9A36C4[oldCollisionDirection + 1].y;
|
location.y += Unk9A36C4[oldCollisionDirection + 1].y;
|
||||||
|
|
||||||
if (!DodgemsCarWouldCollideAt(location, &collideSprite))
|
if (collideSprite = DodgemsCarWouldCollideAt(location); !collideSprite.has_value())
|
||||||
{
|
{
|
||||||
MoveTo(location);
|
MoveTo(location);
|
||||||
}
|
}
|
||||||
|
@ -6300,8 +6300,10 @@ int32_t Vehicle::UpdateMotionDodgems()
|
||||||
location.x += Unk9A36C4[direction].x;
|
location.x += Unk9A36C4[direction].x;
|
||||||
location.y += Unk9A36C4[direction].y;
|
location.y += Unk9A36C4[direction].y;
|
||||||
|
|
||||||
if (DodgemsCarWouldCollideAt(location, &collideSprite))
|
if (collideSprite = DodgemsCarWouldCollideAt(location); collideSprite.has_value())
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
remaining_distance -= Unk9A36C4[direction].distance;
|
remaining_distance -= Unk9A36C4[direction].distance;
|
||||||
unk_F64E20.x = location.x;
|
unk_F64E20.x = location.x;
|
||||||
|
@ -6320,7 +6322,7 @@ int32_t Vehicle::UpdateMotionDodgems()
|
||||||
velocity = 0;
|
velocity = 0;
|
||||||
uint8_t direction = sprite_direction | 1;
|
uint8_t direction = sprite_direction | 1;
|
||||||
|
|
||||||
Vehicle* collideVehicle = GetEntity<Vehicle>(collideSprite);
|
Vehicle* collideVehicle = GetEntity<Vehicle>(collideSprite.value());
|
||||||
if (collideVehicle != nullptr)
|
if (collideVehicle != nullptr)
|
||||||
{
|
{
|
||||||
var_34 = (scenario_rand() & 1) ? 1 : -1;
|
var_34 = (scenario_rand() & 1) ? 1 : -1;
|
||||||
|
@ -6396,16 +6398,13 @@ static bool wouldCollideWithDodgemsTrackEdge(
|
||||||
|| coords.x + dodgemsCarRadius > rideRight || coords.y + dodgemsCarRadius > rideBottom;
|
|| coords.x + dodgemsCarRadius > rideRight || coords.y + dodgemsCarRadius > rideBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Return optional<EntityId>
|
std::optional<EntityId> Vehicle::DodgemsCarWouldCollideAt(const CoordsXY& coords) const
|
||||||
bool Vehicle::DodgemsCarWouldCollideAt(const CoordsXY& coords, EntityId* collidedWith) const
|
|
||||||
{
|
{
|
||||||
auto trackType = GetTrackType();
|
auto trackType = GetTrackType();
|
||||||
|
|
||||||
if (wouldCollideWithDodgemsTrackEdge(coords, TrackLocation, trackType, (var_44 * 30) >> 9))
|
if (wouldCollideWithDodgemsTrackEdge(coords, TrackLocation, trackType, (var_44 * 30) >> 9))
|
||||||
{
|
{
|
||||||
if (collidedWith != nullptr)
|
return EntityId::GetNull();
|
||||||
*collidedWith = EntityId::GetNull();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto location = coords;
|
auto location = coords;
|
||||||
|
@ -6435,14 +6434,12 @@ bool Vehicle::DodgemsCarWouldCollideAt(const CoordsXY& coords, EntityId* collide
|
||||||
ecx >>= 8;
|
ecx >>= 8;
|
||||||
if (std::max(distX, distY) < ecx)
|
if (std::max(distX, distY) < ecx)
|
||||||
{
|
{
|
||||||
if (collidedWith != nullptr)
|
return vehicle2->sprite_index;
|
||||||
*collidedWith = vehicle2->sprite_index;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -220,7 +220,7 @@ struct Vehicle : EntityBase
|
||||||
void SetState(Vehicle::Status vehicleStatus, uint8_t subState = 0);
|
void SetState(Vehicle::Status vehicleStatus, uint8_t subState = 0);
|
||||||
bool IsGhost() const;
|
bool IsGhost() const;
|
||||||
void UpdateSoundParams(std::vector<OpenRCT2::Audio::VehicleSoundParams>& vehicleSoundParamsList) const;
|
void UpdateSoundParams(std::vector<OpenRCT2::Audio::VehicleSoundParams>& vehicleSoundParamsList) const;
|
||||||
bool DodgemsCarWouldCollideAt(const CoordsXY& coords, EntityId* spriteId) const;
|
std::optional<EntityId> DodgemsCarWouldCollideAt(const CoordsXY& coords) const;
|
||||||
int32_t UpdateTrackMotion(int32_t* outStation);
|
int32_t UpdateTrackMotion(int32_t* outStation);
|
||||||
int32_t CableLiftUpdateTrackMotion();
|
int32_t CableLiftUpdateTrackMotion();
|
||||||
GForces GetGForces() const;
|
GForces GetGForces() const;
|
||||||
|
|
Loading…
Reference in New Issue