Merge pull request #10407 from duncanspumpkin/refactor_stations

Fixing COORDS_NULL: Refactor stations
This commit is contained in:
Michael Steenbeek 2019-12-21 16:13:48 +01:00 committed by GitHub
commit c2565bfe1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 69 additions and 35 deletions

View File

@ -1911,7 +1911,7 @@ static void window_ride_init_viewport(rct_window* w)
}
} while (count >= 0);
LocationXY8 location = ride->stations[stationIndex].Start;
auto location = ride->stations[stationIndex].Start;
focus.coordinate.x = location.x * 32;
focus.coordinate.y = location.y * 32;

View File

@ -2121,7 +2121,7 @@ int32_t guest_path_finding(Guest* peep)
if (numEntranceStations == 0)
{
// closestStationNum is always 0 here.
LocationXY8 entranceXY = ride->stations[closestStationNum].Start;
auto entranceXY = ride->stations[closestStationNum].Start;
loc.x = entranceXY.x;
loc.y = entranceXY.y;
loc.z = ride->stations[closestStationNum].Height;

View File

@ -2333,7 +2333,7 @@ bool Staff::UpdateFixingMoveToStationEnd(bool firstRun, Ride* ride)
return true;
}
LocationXY8 stationPosition = ride->stations[current_ride_station].Start;
auto stationPosition = ride->stations[current_ride_station].Start;
if (stationPosition.isNull())
{
return true;
@ -2425,7 +2425,7 @@ bool Staff::UpdateFixingMoveToStationStart(bool firstRun, Ride* ride)
return true;
}
LocationXY8 stationPosition = ride->stations[current_ride_station].Start;
auto stationPosition = ride->stations[current_ride_station].Start;
if (stationPosition.isNull())
{
return true;

View File

@ -799,7 +799,14 @@ private:
dst->overall_view = src->overall_view;
for (int32_t i = 0; i < RCT12_MAX_STATIONS_PER_RIDE; i++)
{
dst->stations[i].Start = src->station_starts[i];
if (src->station_starts[i].isNull())
{
dst->stations[i].Start.setNull();
}
else
{
dst->stations[i].Start = { src->station_starts[i].x, src->station_starts[i].y };
}
dst->stations[i].Height = src->station_height[i] / 2;
dst->stations[i].Length = src->station_length[i];
dst->stations[i].Depart = src->station_light[i];

View File

@ -526,7 +526,15 @@ void S6Exporter::ExportRide(rct2_ride* dst, const Ride* src)
for (int32_t i = 0; i < RCT12_MAX_STATIONS_PER_RIDE; i++)
{
dst->station_starts[i] = src->stations[i].Start;
if (src->stations[i].Start.isNull())
{
dst->station_starts[i].setNull();
}
else
{
dst->station_starts[i] = { static_cast<uint8_t>(src->stations[i].Start.x),
static_cast<uint8_t>(src->stations[i].Start.y) };
}
dst->station_heights[i] = src->stations[i].Height;
dst->station_length[i] = src->stations[i].Length;
dst->station_depart[i] = src->stations[i].Depart;

View File

@ -521,7 +521,14 @@ public:
for (int32_t i = 0; i < RCT12_MAX_STATIONS_PER_RIDE; i++)
{
dst->stations[i].Start = src->station_starts[i];
if (src->station_starts[i].isNull())
{
dst->stations[i].Start.setNull();
}
else
{
dst->stations[i].Start = { src->station_starts[i].x, src->station_starts[i].y };
}
dst->stations[i].Height = src->station_heights[i];
dst->stations[i].Length = src->station_length[i];
dst->stations[i].Depart = src->station_depart[i];

View File

@ -3257,7 +3257,7 @@ static void ride_entrance_exit_connected(Ride* ride)
{
for (int32_t i = 0; i < MAX_STATIONS; ++i)
{
LocationXY8 station_start = ride->stations[i].Start;
auto station_start = ride->stations[i].Start;
auto entrance = ride_get_entrance_location(ride, i);
auto exit = ride_get_exit_location(ride, i);
@ -3289,14 +3289,12 @@ static void ride_entrance_exit_connected(Ride* ride)
static void ride_shop_connected(Ride* ride)
{
LocationXY8 coordinates = ride->stations[0].Start;
if (coordinates.isNull())
TileCoordsXY shopLoc = ride->stations[0].Start;
if (shopLoc.isNull())
return;
TileCoordsXY loc = { coordinates.x, coordinates.y };
TrackElement* trackElement = nullptr;
TileElement* tileElement = map_get_first_element_at(loc.x, loc.y);
TileElement* tileElement = map_get_first_element_at(shopLoc.x, shopLoc.y);
do
{
if (tileElement == nullptr)
@ -3346,8 +3344,8 @@ static void ride_shop_connected(Ride* ride)
// Flip direction north<->south, east<->west
uint8_t face_direction = direction_reverse(count);
int32_t y2 = loc.y - TileDirectionDelta[face_direction].y;
int32_t x2 = loc.x - TileDirectionDelta[face_direction].x;
int32_t y2 = shopLoc.y - TileDirectionDelta[face_direction].y;
int32_t x2 = shopLoc.x - TileDirectionDelta[face_direction].x;
if (map_coord_is_connected({ x2, y2, tileElement->base_height }, face_direction))
return;
@ -4924,7 +4922,7 @@ void loc_6DDF9C(Ride* ride, TileElement* tileElement)
*/
static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying)
{
LocationXY8 location;
TileCoordsXY location;
int32_t stationIndex;
for (stationIndex = 0; stationIndex < MAX_STATIONS; stationIndex++)
{
@ -6234,7 +6232,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
return entranceExitCoords;
}
LocationXY8 stationStart = ride->stations[gRideEntranceExitPlaceStationIndex].Start;
auto stationStart = ride->stations[gRideEntranceExitPlaceStationIndex].Start;
if (stationStart.isNull())
{
entranceExitCoords.x = LOCATION_NULL;
@ -6652,20 +6650,20 @@ static int32_t ride_get_track_length(Ride* ride)
TileElement* tileElement = nullptr;
track_circuit_iterator it, slowIt;
ride_id_t rideIndex;
int32_t x = 0, y = 0, z, trackType, result;
int32_t trackType, result;
CoordsXY trackStart;
bool foundTrack = false;
for (int32_t i = 0; i < MAX_STATIONS && !foundTrack; i++)
{
LocationXY8 location = ride->stations[i].Start;
if (location.isNull())
const auto& stationTileLoc = ride->stations[i].Start;
if (stationTileLoc.isNull())
continue;
x = location.x * 32;
y = location.y * 32;
z = ride->stations[i].Height;
trackStart = stationTileLoc.ToCoordsXY();
auto z = ride->stations[i].Height;
tileElement = map_get_first_element_at(x >> 5, y >> 5);
tileElement = map_get_first_element_at(stationTileLoc.x, stationTileLoc.y);
if (tileElement == nullptr)
continue;
do
@ -6696,7 +6694,7 @@ static int32_t ride_get_track_length(Ride* ride)
bool moveSlowIt = true;
result = 0;
track_circuit_iterator_begin(&it, { x, y, tileElement });
track_circuit_iterator_begin(&it, { trackStart.x, trackStart.y, tileElement });
slowIt = it;
while (track_circuit_iterator_next(&it))
{

View File

@ -162,7 +162,7 @@ struct rct_ride_entry
struct RideStation
{
LocationXY8 Start;
TileCoordsXY Start;
uint8_t Height;
uint8_t Length;
uint8_t Depart;

View File

@ -1433,7 +1433,7 @@ static int32_t ride_ratings_get_scenery_score(Ride* ride)
}
else
{
LocationXY8 location = ride->stations[i].Start;
auto location = ride->stations[i].Start;
x = location.x;
y = location.y;
}

View File

@ -417,12 +417,12 @@ TileCoordsXYZD ride_get_exit_location(const Ride* ride, const int32_t stationInd
void ride_clear_entrance_location(Ride* ride, const int32_t stationIndex)
{
ride->stations[stationIndex].Entrance.x = COORDS_NULL;
ride->stations[stationIndex].Entrance.setNull();
}
void ride_clear_exit_location(Ride* ride, const int32_t stationIndex)
{
ride->stations[stationIndex].Exit.x = COORDS_NULL;
ride->stations[stationIndex].Exit.setNull();
}
void ride_set_entrance_location(Ride* ride, const int32_t stationIndex, const TileCoordsXYZD location)

View File

@ -2797,7 +2797,7 @@ static bool vehicle_can_depart_synchronised(rct_vehicle* vehicle)
return false;
int32_t station = vehicle->current_station;
LocationXY8 location = ride->stations[station].Start;
auto location = ride->stations[station].Start;
int32_t x = location.x * 32;
int32_t y = location.y * 32;
int32_t z = ride->stations[station].Height;
@ -9283,16 +9283,15 @@ loc_6DCE62:
loc_6DCE68:
_vehicleMotionTrackFlags |= 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;
for (int32_t i = 0; i < MAX_STATIONS; i++)
{
if ((uint16_t)regs.ax != ride->stations[i].Start.xy)
auto trackLoc = TileCoordsXY(CoordsXY{ vehicle->track_x, vehicle->track_y });
if (trackLoc != ride->stations[i].Start)
{
continue;
}
if ((uint16_t)regs.dl != ride->stations[i].Height)
if ((vehicle->track_z >> 3) != ride->stations[i].Height)
{
continue;
}

View File

@ -226,10 +226,25 @@ struct TileCoordsXY
return rotatedCoords;
}
bool operator==(const TileCoordsXY& other) const
{
return x == other.x && y == other.y;
}
bool operator!=(const TileCoordsXY& other) const
{
return !(*this == other);
}
bool isNull() const
{
return x == COORDS_NULL;
};
void setNull()
{
x = COORDS_NULL;
}
};
struct CoordsXYZ : public CoordsXY