Create getters for station height and start (#10453)

This commit is contained in:
Michael Steenbeek 2019-12-27 15:57:40 +01:00 committed by GitHub
parent 8ca0cf52a7
commit 64f7cac6d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 115 additions and 85 deletions

View File

@ -1915,7 +1915,7 @@ static void window_ride_init_viewport(rct_window* w)
focus.coordinate.x = location.x * 32; focus.coordinate.x = location.x * 32;
focus.coordinate.y = location.y * 32; focus.coordinate.y = location.y * 32;
focus.coordinate.z = ride->stations[stationIndex].Height << 3; focus.coordinate.z = ride->stations[stationIndex].GetBaseZ();
focus.sprite.type |= VIEWPORT_FOCUS_TYPE_COORDINATE; focus.sprite.type |= VIEWPORT_FOCUS_TYPE_COORDINATE;
} }
else else

View File

@ -193,7 +193,7 @@ public:
map_invalidate_tile_full(flooredX, flooredY); map_invalidate_tile_full(flooredX, flooredY);
ride->maze_tiles++; ride->maze_tiles++;
ride->stations[0].Height = tileElement->base_height; ride->stations[0].SetBaseZ(tileElement->GetBaseZ());
ride->stations[0].Start.x = 0; ride->stations[0].Start.x = 0;
ride->stations[0].Start.y = 0; ride->stations[0].Start.y = 0;

View File

@ -233,7 +233,7 @@ public:
map_invalidate_tile_full(flooredX, flooredY); map_invalidate_tile_full(flooredX, flooredY);
ride->maze_tiles++; ride->maze_tiles++;
ride->stations[0].Height = tileElement->base_height; ride->stations[0].SetBaseZ(tileElement->GetBaseZ());
ride->stations[0].Start.x = 0; ride->stations[0].Start.x = 0;
ride->stations[0].Start.y = 0; ride->stations[0].Start.y = 0;

View File

@ -99,7 +99,7 @@ public:
} }
} }
auto z = ride->stations[_stationNum].Height * 8; auto z = ride->stations[_stationNum].GetBaseZ();
if (!gCheatsSandboxMode && !map_is_location_owned({ _loc, z })) if (!gCheatsSandboxMode && !map_is_location_owned({ _loc, z }))
{ {
return MakeResult(GA_ERROR::NOT_OWNED, errorTitle); return MakeResult(GA_ERROR::NOT_OWNED, errorTitle);
@ -166,7 +166,7 @@ public:
} }
} }
auto z = ride->stations[_stationNum].Height * 8; auto z = ride->stations[_stationNum].GetBaseZ();
if (!(GetFlags() & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) if (!(GetFlags() & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && !(GetFlags() & GAME_COMMAND_FLAG_GHOST))
{ {
footpath_remove_litter(_loc.x, _loc.y, z); footpath_remove_litter(_loc.x, _loc.y, z);

View File

@ -3690,7 +3690,7 @@ void Guest::UpdateRideAdvanceThroughEntrance()
sub_state = PEEP_RIDE_FREE_VEHICLE_CHECK; sub_state = PEEP_RIDE_FREE_VEHICLE_CHECK;
} }
actionZ = ride->stations[current_ride_station].Height * 8; actionZ = ride->stations[current_ride_station].GetBaseZ();
distanceThreshold += 4; distanceThreshold += 4;
if (xy_distance < distanceThreshold) if (xy_distance < distanceThreshold)
@ -4162,7 +4162,7 @@ void Guest::UpdateRideLeaveVehicle()
assert(current_ride_station < MAX_STATIONS); assert(current_ride_station < MAX_STATIONS);
TileCoordsXYZD exitLocation = ride_get_exit_location(ride, current_ride_station); TileCoordsXYZD exitLocation = ride_get_exit_location(ride, current_ride_station);
CoordsXYZD platformLocation; CoordsXYZD platformLocation;
platformLocation.z = ride->stations[current_ride_station].Height; platformLocation.z = ride->stations[current_ride_station].GetBaseZ();
platformLocation.direction = direction_reverse(exitLocation.direction); platformLocation.direction = direction_reverse(exitLocation.direction);
@ -4219,7 +4219,6 @@ void Guest::UpdateRideLeaveVehicle()
platformLocation.x = vehicle->x + xShift * shiftMultiplier; platformLocation.x = vehicle->x + xShift * shiftMultiplier;
platformLocation.y = vehicle->y + yShift * shiftMultiplier; platformLocation.y = vehicle->y + yShift * shiftMultiplier;
platformLocation.z *= 8;
peep_go_to_ride_exit( peep_go_to_ride_exit(
this, ride, platformLocation.x, platformLocation.y, platformLocation.z, platformLocation.direction); this, ride, platformLocation.x, platformLocation.y, platformLocation.z, platformLocation.direction);
@ -4257,7 +4256,7 @@ void Guest::UpdateRideLeaveVehicle()
vehicle_entry->peep_loading_positions.size()); vehicle_entry->peep_loading_positions.size());
} }
platformLocation.z = ride->stations[current_ride_station].Height * 8; platformLocation.z = ride->stations[current_ride_station].GetBaseZ();
peep_go_to_ride_exit( peep_go_to_ride_exit(
this, ride, platformLocation.x, platformLocation.y, platformLocation.z, platformLocation.direction); this, ride, platformLocation.x, platformLocation.y, platformLocation.z, platformLocation.direction);
@ -4388,7 +4387,7 @@ void Guest::UpdateRideInExit()
{ {
if (xy_distance >= 16) if (xy_distance >= 16)
{ {
int16_t actionZ = ride->stations[current_ride_station].Height * 8; int16_t actionZ = ride->stations[current_ride_station].GetBaseZ();
actionZ += RideData5[ride->type].z; actionZ += RideData5[ride->type].z;
MoveTo((*loc).x, (*loc).y, actionZ); MoveTo((*loc).x, (*loc).y, actionZ);
@ -4429,7 +4428,7 @@ void Guest::UpdateRideApproachVehicleWaypoints()
// Motion simulators have steps this moves the peeps up the steps // Motion simulators have steps this moves the peeps up the steps
if (ride->type == RIDE_TYPE_MOTION_SIMULATOR) if (ride->type == RIDE_TYPE_MOTION_SIMULATOR)
{ {
actionZ = ride->stations[current_ride_station].Height * 8 + 2; actionZ = ride->stations[current_ride_station].GetBaseZ() + 2;
if (waypoint == 2) if (waypoint == 2)
{ {
@ -4505,7 +4504,7 @@ void Guest::UpdateRideApproachExitWaypoints()
int16_t actionZ; int16_t actionZ;
if (ride->type == RIDE_TYPE_MOTION_SIMULATOR) if (ride->type == RIDE_TYPE_MOTION_SIMULATOR)
{ {
actionZ = ride->stations[current_ride_station].Height * 8 + 2; actionZ = ride->stations[current_ride_station].GetBaseZ() + 2;
if ((var_37 & 3) == 1) if ((var_37 & 3) == 1)
{ {
@ -4876,10 +4875,10 @@ void Guest::UpdateRideMazePathfinding()
CoordsXY targetLoc = { destination_x & 0xFFE0, destination_y & 0xFFE0 }; CoordsXY targetLoc = { destination_x & 0xFFE0, destination_y & 0xFFE0 };
int16_t stationHeight = ride->stations[0].Height; int16_t stationHeight = ride->stations[0].GetBaseZ();
// Find the station track element // Find the station track element
auto trackElement = map_get_track_element_at({ targetLoc, stationHeight << 3 }); auto trackElement = map_get_track_element_at({ targetLoc, stationHeight });
if (trackElement == nullptr) if (trackElement == nullptr)
{ {
return; return;
@ -4942,7 +4941,7 @@ void Guest::UpdateRideMazePathfinding()
return; return;
do do
{ {
if (stationHeight != tileElement->base_height) if (stationHeight != tileElement->GetBaseZ())
continue; continue;
if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK) if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK)
@ -5009,7 +5008,7 @@ void Guest::UpdateRideLeaveExit()
{ {
if (ride != nullptr) if (ride != nullptr)
{ {
MoveTo((*loc).x, (*loc).y, ride->stations[current_ride_station].Height * 8); MoveTo((*loc).x, (*loc).y, ride->stations[current_ride_station].GetBaseZ());
} }
return; return;
} }

View File

@ -1504,7 +1504,7 @@ void Staff::UpdateHeadingToInspect()
int16_t delta_y = abs(y - destination_y); int16_t delta_y = abs(y - destination_y);
if (auto loc = UpdateAction()) if (auto loc = UpdateAction())
{ {
int32_t newZ = ride->stations[current_ride_station].Height * 8; int32_t newZ = ride->stations[current_ride_station].GetBaseZ();
if (delta_y < 20) if (delta_y < 20)
{ {
@ -1615,7 +1615,7 @@ void Staff::UpdateAnswering()
int16_t delta_y = abs(y - destination_y); int16_t delta_y = abs(y - destination_y);
if (auto loc = UpdateAction()) if (auto loc = UpdateAction())
{ {
int32_t newZ = ride->stations[current_ride_station].Height * 8; int32_t newZ = ride->stations[current_ride_station].GetBaseZ();
if (delta_y < 20) if (delta_y < 20)
{ {
@ -2344,15 +2344,12 @@ bool Staff::UpdateFixingMoveToStationEnd(bool firstRun, Ride* ride)
return true; return true;
} }
auto stationPosition = ride->stations[current_ride_station].Start; auto stationPos = ride->stations[current_ride_station].GetStart();
if (stationPosition.isNull()) if (stationPos.isNull())
{ {
return true; return true;
} }
auto stationTilePos = TileCoordsXYZ{ stationPosition, ride->stations[current_ride_station].Height };
auto stationPos = stationTilePos.ToCoordsXYZ();
auto tileElement = map_get_track_element_at(stationPos); auto tileElement = map_get_track_element_at(stationPos);
if (tileElement == nullptr) if (tileElement == nullptr)
{ {
@ -2435,18 +2432,16 @@ bool Staff::UpdateFixingMoveToStationStart(bool firstRun, Ride* ride)
return true; return true;
} }
auto stationPosition = ride->stations[current_ride_station].Start; auto stationPosition = ride->stations[current_ride_station].GetStart();
if (stationPosition.isNull()) if (stationPosition.isNull())
{ {
return true; return true;
} }
uint8_t stationZ = ride->stations[current_ride_station].Height;
CoordsXYE input; CoordsXYE input;
input.x = stationPosition.x * 32; input.x = stationPosition.x;
input.y = stationPosition.y * 32; input.y = stationPosition.y;
input.element = map_get_track_element_at_from_ride({ input.x, input.y, stationZ << 3 }, current_ride); input.element = map_get_track_element_at_from_ride({ input.x, input.y, stationPosition.z }, current_ride);
if (input.element == nullptr) if (input.element == nullptr)
{ {
return true; return true;
@ -2705,7 +2700,7 @@ bool Staff::UpdateFixingLeaveByEntranceExit(bool firstRun, Ride* ride)
int16_t xy_distance; int16_t xy_distance;
if (auto loc = UpdateAction(xy_distance)) if (auto loc = UpdateAction(xy_distance))
{ {
uint16_t stationHeight = ride->stations[current_ride_station].Height * 8; uint16_t stationHeight = ride->stations[current_ride_station].GetBaseZ();
if (xy_distance >= 16) if (xy_distance >= 16)
{ {

View File

@ -815,7 +815,7 @@ private:
{ {
dst->stations[i].Start = { src->station_starts[i].x, src->station_starts[i].y }; 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].SetBaseZ(src->station_height[i] * 4);
dst->stations[i].Length = src->station_length[i]; dst->stations[i].Length = src->station_length[i];
dst->stations[i].Depart = src->station_light[i]; dst->stations[i].Depart = src->station_light[i];

View File

@ -48,6 +48,7 @@
#include "../world/Banner.h" #include "../world/Banner.h"
#include "../world/Climate.h" #include "../world/Climate.h"
#include "../world/Footpath.h" #include "../world/Footpath.h"
#include "../world/Location.hpp"
#include "../world/Map.h" #include "../world/Map.h"
#include "../world/MapAnimation.h" #include "../world/MapAnimation.h"
#include "../world/Park.h" #include "../world/Park.h"
@ -2893,9 +2894,7 @@ static void ride_music_update(Ride* ride)
return; return;
} }
TileCoordsXYZ stationTileCoords{ ride->stations[0].Start.x, ride->stations[0].Start.y, ride->stations[0].Height }; CoordsXYZ rideCoords = ride->stations[0].GetStart().ToTileCentre();
CoordsXYZ rideCoords{ stationTileCoords.ToCoordsXYZ() };
rideCoords = { rideCoords.ToTileCentre(), rideCoords.z };
int32_t sampleRate = 22050; int32_t sampleRate = 22050;
@ -4927,7 +4926,7 @@ static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying)
int32_t x = location.x * 32; int32_t x = location.x * 32;
int32_t y = location.y * 32; int32_t y = location.y * 32;
int32_t z = ride->stations[stationIndex].Height; int32_t z = ride->stations[stationIndex].GetBaseZ();
bool success = false; bool success = false;
TileElement* tileElement = map_get_first_element_at({ x, y }); TileElement* tileElement = map_get_first_element_at({ x, y });
@ -4937,7 +4936,7 @@ static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying)
{ {
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
continue; continue;
if (tileElement->base_height != z) if (tileElement->GetBaseZ() != z)
continue; continue;
if (!(TrackSequenceProperties[tileElement->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) if (!(TrackSequenceProperties[tileElement->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN))
@ -5127,7 +5126,7 @@ static void loc_6B51C0(const Ride* ride)
{ {
int32_t x = ride->stations[i].Start.x * 32; int32_t x = ride->stations[i].Start.x * 32;
int32_t y = ride->stations[i].Start.y * 32; int32_t y = ride->stations[i].Start.y * 32;
int32_t z = ride->stations[i].Height * 8; int32_t z = ride->stations[i].GetBaseZ();
window_scroll_to_location(w, x, y, z); window_scroll_to_location(w, x, y, z);
CoordsXYE trackElement; CoordsXYE trackElement;
@ -5230,7 +5229,7 @@ int32_t ride_is_valid_for_test(Ride* ride, int32_t status, bool isApplying)
ride->lifecycle_flags |= RIDE_LIFECYCLE_EVER_BEEN_OPENED; ride->lifecycle_flags |= RIDE_LIFECYCLE_EVER_BEEN_OPENED;
} }
// z = ride->stations[i].Height * 8; // z = ride->stations[i].GetBaseZ();
trackElement.x = ride->stations[stationIndex].Start.x * 32; trackElement.x = ride->stations[stationIndex].Start.x * 32;
trackElement.y = ride->stations[stationIndex].Start.y * 32; trackElement.y = ride->stations[stationIndex].Start.y * 32;
trackElement.element = loc_6B4F6B(ride->id, trackElement.x, trackElement.y); trackElement.element = loc_6B4F6B(ride->id, trackElement.x, trackElement.y);
@ -5366,7 +5365,7 @@ int32_t ride_is_valid_for_open(Ride* ride, int32_t goingToBeOpen, bool isApplyin
ride->lifecycle_flags |= RIDE_LIFECYCLE_EVER_BEEN_OPENED; ride->lifecycle_flags |= RIDE_LIFECYCLE_EVER_BEEN_OPENED;
} }
// z = ride->stations[i].Height * 8; // z = ride->stations[i].GetBaseZ();
trackElement.x = ride->stations[stationIndex].Start.x * 32; trackElement.x = ride->stations[stationIndex].Start.x * 32;
trackElement.y = ride->stations[stationIndex].Start.y * 32; trackElement.y = ride->stations[stationIndex].Start.y * 32;
trackElement.element = loc_6B4F6B(ride->id, trackElement.x, trackElement.y); trackElement.element = loc_6B4F6B(ride->id, trackElement.x, trackElement.y);
@ -6200,9 +6199,9 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
return entranceExitCoords; return entranceExitCoords;
} }
stationHeight = ride->stations[gRideEntranceExitPlaceStationIndex].Height; stationHeight = ride->stations[gRideEntranceExitPlaceStationIndex].GetBaseZ();
auto coords = screen_get_map_xy_with_z(screenCoords, stationHeight * 8); auto coords = screen_get_map_xy_with_z(screenCoords, stationHeight);
if (!coords) if (!coords)
{ {
entranceExitCoords.x = LOCATION_NULL; entranceExitCoords.x = LOCATION_NULL;
@ -6212,7 +6211,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
word_F4418C = coords->x; word_F4418C = coords->x;
word_F4418E = coords->y; word_F4418E = coords->y;
entranceExitCoords = { coords->ToTileStart(), stationHeight * 8, INVALID_DIRECTION }; entranceExitCoords = { coords->ToTileStart(), stationHeight, INVALID_DIRECTION };
if (ride->type == RIDE_TYPE_NULL) if (ride->type == RIDE_TYPE_NULL)
{ {
@ -6253,7 +6252,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
{ {
if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK)
continue; continue;
if (tileElement->base_height != stationHeight) if (tileElement->GetBaseZ() != stationHeight)
continue; continue;
if (tileElement->AsTrack()->GetRideIndex() != gRideEntranceExitPlaceRideIndex) if (tileElement->AsTrack()->GetRideIndex() != gRideEntranceExitPlaceRideIndex)
continue; continue;
@ -6649,7 +6648,7 @@ static int32_t ride_get_track_length(Ride* ride)
continue; continue;
trackStart = stationTileLoc.ToCoordsXY(); trackStart = stationTileLoc.ToCoordsXY();
auto z = ride->stations[i].Height; auto z = ride->stations[i].GetBaseZ();
tileElement = map_get_first_element_at(stationTileLoc.ToCoordsXY()); tileElement = map_get_first_element_at(stationTileLoc.ToCoordsXY());
if (tileElement == nullptr) if (tileElement == nullptr)
@ -6663,7 +6662,7 @@ static int32_t ride_get_track_length(Ride* ride)
if (!(TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) if (!(TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN))
continue; continue;
if (tileElement->base_height != z) if (tileElement->GetBaseZ() != z)
continue; continue;
foundTrack = true; foundTrack = true;
@ -6901,7 +6900,7 @@ void sub_6CB945(Ride* ride)
continue; continue;
CoordsXYZ location = { ride->stations[stationId].Start.x * 32, ride->stations[stationId].Start.y * 32, CoordsXYZ location = { ride->stations[stationId].Start.x * 32, ride->stations[stationId].Start.y * 32,
ride->stations[stationId].Height * 8 }; ride->stations[stationId].GetBaseZ() };
auto tileHeight = TileCoordsXYZ(location).z; auto tileHeight = TileCoordsXYZ(location).z;
uint8_t direction = 0xFF; uint8_t direction = 0xFF;
@ -7080,23 +7079,16 @@ void sub_6CB945(Ride* ride)
if (!ride_get_exit_location(ride, stationId).isNull()) if (!ride_get_exit_location(ride, stationId).isNull())
break; break;
ride_set_exit_location( CoordsXYZD loc = { location, ride->stations[stationId].GetBaseZ(), tileElement->GetDirection() };
ride, stationId, ride_set_exit_location(ride, stationId, TileCoordsXYZD{ loc });
{ location.x / 32, location.y / 32, ride->stations[stationId].Height,
(uint8_t)tileElement->GetDirection() });
} }
else else
{ {
if (!ride_get_entrance_location(ride, stationId).isNull()) if (!ride_get_entrance_location(ride, stationId).isNull())
break; break;
TileCoordsXYZD entranceLocation = { CoordsXYZD loc = { location, ride->stations[stationId].GetBaseZ(), tileElement->GetDirection() };
location.x / 32, ride_set_entrance_location(ride, stationId, TileCoordsXYZD{ loc });
location.y / 32,
ride->stations[stationId].Height,
(uint8_t)tileElement->GetDirection(),
};
ride_set_entrance_location(ride, stationId, entranceLocation);
} }
tileElement->AsEntrance()->SetStationIndex(stationId); tileElement->AsEntrance()->SetStationIndex(stationId);
@ -7362,26 +7354,25 @@ bool ride_has_adjacent_station(Ride* ride)
* adjacent station on either side. */ * adjacent station on either side. */
for (int32_t stationNum = 0; stationNum < MAX_STATIONS; stationNum++) for (int32_t stationNum = 0; stationNum < MAX_STATIONS; stationNum++)
{ {
if (!ride->stations[stationNum].Start.isNull()) auto stationStart = ride->stations[stationNum].GetStart();
if (!stationStart.isNull())
{ {
/* Get the map element for the station start. */ /* Get the map element for the station start. */
uint16_t stationX = ride->stations[stationNum].Start.x * 32;
uint16_t stationY = ride->stations[stationNum].Start.y * 32;
uint8_t stationZ = ride->stations[stationNum].Height; uint8_t stationZ = ride->stations[stationNum].Height;
TileElement* stationElement = get_station_platform(stationX, stationY, stationZ, 0); TileElement* stationElement = get_station_platform(stationStart.x, stationStart.y, stationZ, 0);
if (stationElement == nullptr) if (stationElement == nullptr)
{ {
continue; continue;
} }
/* Check the first side of the station */ /* Check the first side of the station */
int32_t direction = stationElement->GetDirectionWithOffset(1); int32_t direction = stationElement->GetDirectionWithOffset(1);
found = check_for_adjacent_station(stationX, stationY, stationZ, direction); found = check_for_adjacent_station(stationStart.x, stationStart.y, stationZ, direction);
if (found) if (found)
break; break;
/* Check the other side of the station */ /* Check the other side of the station */
direction = direction_reverse(direction); direction = direction_reverse(direction);
found = check_for_adjacent_station(stationX, stationY, stationZ, direction); found = check_for_adjacent_station(stationStart.x, stationStart.y, stationZ, direction);
if (found) if (found)
break; break;
} }

View File

@ -176,6 +176,10 @@ struct RideStation
uint16_t LastPeepInQueue; uint16_t LastPeepInQueue;
static constexpr uint8_t NO_TRAIN = std::numeric_limits<uint8_t>::max(); static constexpr uint8_t NO_TRAIN = std::numeric_limits<uint8_t>::max();
int32_t GetBaseZ() const;
void SetBaseZ(int32_t newZ);
CoordsXYZ GetStart() const;
}; };
struct RideMeasurement struct RideMeasurement

View File

@ -396,7 +396,7 @@ static void ride_ratings_begin_proximity_loop()
int32_t x = ride->stations[i].Start.x * 32; int32_t x = ride->stations[i].Start.x * 32;
int32_t y = ride->stations[i].Start.y * 32; int32_t y = ride->stations[i].Start.y * 32;
int32_t z = ride->stations[i].Height * 8; int32_t z = ride->stations[i].GetBaseZ();
gRideRatingsCalcData.proximity_x = x; gRideRatingsCalcData.proximity_x = x;
gRideRatingsCalcData.proximity_y = y; gRideRatingsCalcData.proximity_y = y;
@ -1441,7 +1441,7 @@ static int32_t ride_ratings_get_scenery_score(Ride* ride)
int32_t z = tile_element_height({ x * 32, y * 32 }); int32_t z = tile_element_height({ x * 32, y * 32 });
// Check if station is underground, returns a fixed mediocre score since you can't have scenery underground // Check if station is underground, returns a fixed mediocre score since you can't have scenery underground
if (z > ride->stations[i].Height * 8) if (z > ride->stations[i].GetBaseZ())
{ {
return 40; return 40;
} }

View File

@ -334,17 +334,15 @@ static void ride_invalidate_station_start(Ride* ride, int32_t stationIndex, bool
TileElement* ride_get_station_start_track_element(Ride* ride, int32_t stationIndex) TileElement* ride_get_station_start_track_element(Ride* ride, int32_t stationIndex)
{ {
int32_t x = ride->stations[stationIndex].Start.x; auto stationStart = ride->stations[stationIndex].GetStart();
int32_t y = ride->stations[stationIndex].Start.y;
int32_t z = ride->stations[stationIndex].Height;
// Find the station track element // Find the station track element
TileElement* tileElement = map_get_first_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); TileElement* tileElement = map_get_first_element_at(stationStart);
if (tileElement == nullptr) if (tileElement == nullptr)
return nullptr; return nullptr;
do do
{ {
if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK && z == tileElement->base_height) if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK && stationStart.z == tileElement->GetBaseZ())
return tileElement; return tileElement;
} while (!(tileElement++)->IsLastForTile()); } while (!(tileElement++)->IsLastForTile());
@ -434,3 +432,19 @@ void ride_set_exit_location(Ride* ride, const int32_t stationIndex, const TileCo
{ {
ride->stations[stationIndex].Exit = location; ride->stations[stationIndex].Exit = location;
} }
int32_t RideStation::GetBaseZ() const
{
return Height * 8;
}
void RideStation::SetBaseZ(int32_t newZ)
{
Height = newZ / 8;
}
CoordsXYZ RideStation::GetStart() const
{
TileCoordsXYZ stationTileCoords{ Start.x, Start.y, Height };
return stationTileCoords.ToCoordsXYZ();
}

View File

@ -623,7 +623,8 @@ static void ride_remove_station(Ride* ride, int32_t x, int32_t y, int32_t z)
{ {
for (int32_t i = 0; i < MAX_STATIONS; i++) for (int32_t i = 0; i < MAX_STATIONS; i++)
{ {
if (ride->stations[i].Start.x == (x >> 5) && ride->stations[i].Start.y == (y >> 5) && ride->stations[i].Height == z) auto stationStart = ride->stations[i].GetStart();
if (stationStart.x == x && stationStart.y == y && ride->stations[i].Height == z)
{ {
ride->stations[i].Start.setNull(); ride->stations[i].Start.setNull();
ride->num_stations--; ride->num_stations--;

View File

@ -260,7 +260,7 @@ rct_string_id TrackDesign::CreateTrackDesignTrack(const Ride& ride)
{ {
for (int32_t station_index = 0; station_index < RCT12_MAX_STATIONS_PER_RIDE; station_index++) for (int32_t station_index = 0; station_index < RCT12_MAX_STATIONS_PER_RIDE; station_index++)
{ {
z = ride.stations[station_index].Height; z = ride.stations[station_index].GetBaseZ();
TileCoordsXYZD location; TileCoordsXYZD location;
if (i == 0) if (i == 0)
@ -277,9 +277,9 @@ rct_string_id TrackDesign::CreateTrackDesignTrack(const Ride& ride)
continue; continue;
} }
CoordsXY mapLocation{ location.x * 32, location.y * 32 }; CoordsXY mapLocation = location.ToCoordsXY();
TileElement* tileElement = map_get_first_element_at(location.ToCoordsXY()); TileElement* tileElement = map_get_first_element_at(mapLocation);
if (tileElement == nullptr) if (tileElement == nullptr)
continue; continue;
@ -287,7 +287,7 @@ rct_string_id TrackDesign::CreateTrackDesignTrack(const Ride& ride)
{ {
if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE) if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
continue; continue;
if (tileElement->base_height == z) if (tileElement->GetBaseZ() == z)
break; break;
} while (!(tileElement++)->IsLastForTile()); } while (!(tileElement++)->IsLastForTile());
@ -307,7 +307,6 @@ rct_string_id TrackDesign::CreateTrackDesignTrack(const Ride& ride)
entrance.x = rotatedMapLocation.x; entrance.x = rotatedMapLocation.x;
entrance.y = rotatedMapLocation.y; entrance.y = rotatedMapLocation.y;
z *= 8;
z -= gTrackPreviewOrigin.z; z -= gTrackPreviewOrigin.z;
z /= 8; z /= 8;

View File

@ -2796,12 +2796,12 @@ static bool vehicle_can_depart_synchronised(rct_vehicle* vehicle)
return false; return false;
int32_t station = vehicle->current_station; int32_t station = vehicle->current_station;
auto location = ride->stations[station].Start; auto location = ride->stations[station].GetStart();
int32_t x = location.x * 32; int32_t x = location.x;
int32_t y = location.y * 32; int32_t y = location.y;
int32_t z = ride->stations[station].Height; int32_t z = ride->stations[station].Height;
auto tileElement = map_get_track_element_at({ x, y, z << 3 }); auto tileElement = map_get_track_element_at(location);
if (tileElement == nullptr) if (tileElement == nullptr)
{ {
return false; return false;
@ -2836,8 +2836,8 @@ static bool vehicle_can_depart_synchronised(rct_vehicle* vehicle)
} }
// Reset back to starting tile. // Reset back to starting tile.
x = location.x * 32; x = location.x;
y = location.y * 32; y = location.y;
// Other search direction. // Other search direction.
direction = direction_reverse(direction) & 3; direction = direction_reverse(direction) & 3;
@ -2876,10 +2876,10 @@ static bool vehicle_can_depart_synchronised(rct_vehicle* vehicle)
if (!(sv_ride->stations[sv->station_id].Depart & STATION_DEPART_FLAG)) if (!(sv_ride->stations[sv->station_id].Depart & STATION_DEPART_FLAG))
{ {
sv = _synchronisedVehicles; sv = _synchronisedVehicles;
uint8_t rideId = 0xFF; uint8_t rideId = RIDE_ID_NULL;
for (; sv < _lastSynchronisedVehicle; sv++) for (; sv < _lastSynchronisedVehicle; sv++)
{ {
if (rideId == 0xFF) if (rideId == RIDE_ID_NULL)
{ {
rideId = sv->ride_id; rideId = sv->ride_id;
} }
@ -9277,7 +9277,7 @@ loc_6DCE68:
{ {
continue; continue;
} }
if ((vehicle->track_z >> 3) != ride->stations[i].Height) if ((vehicle->track_z) != ride->stations[i].GetBaseZ())
{ {
continue; continue;
} }

View File

@ -288,6 +288,11 @@ struct CoordsXYZ : public CoordsXY
{ {
return { floor2(x, 32), floor2(y, 32), z }; return { floor2(x, 32), floor2(y, 32), z };
} }
CoordsXYZ ToTileCentre() const
{
return ToTileStart() + CoordsXYZ{ 16, 16, z };
}
}; };
struct TileCoordsXYZ : public TileCoordsXY struct TileCoordsXYZ : public TileCoordsXY
@ -457,6 +462,12 @@ struct TileCoordsXYZD : public TileCoordsXYZ
{ {
} }
TileCoordsXYZD(CoordsXYZD c_)
: TileCoordsXYZ(c_)
, direction(c_.direction)
{
}
CoordsXYZD ToCoordsXYZD() const CoordsXYZD ToCoordsXYZD() const
{ {
return { x * 32, y * 32, z * 8, direction }; return { x * 32, y * 32, z * 8, direction };

View File

@ -483,3 +483,19 @@ void TileElementBase::SetClearanceZ(int32_t newZ)
{ {
clearance_height = (newZ / 8); clearance_height = (newZ / 8);
} }
int32_t RideStation::GetBaseZ() const
{
return Height * 8;
}
void RideStation::SetBaseZ(int32_t newZ)
{
Height = newZ / 8;
}
CoordsXYZ RideStation::GetStart() const
{
TileCoordsXYZ stationTileCoords{ Start.x, Start.y, Height };
return stationTileCoords.ToCoordsXYZ();
}