From 2eb967b30d52f1c0720c4f995cf80f4c54aa848a Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 1 Mar 2020 23:18:59 +0100 Subject: [PATCH 1/2] Change station start to CoordsXY --- src/openrct2/interface/InteractiveConsole.cpp | 7 +- src/openrct2/peep/Guest.cpp | 68 +++++++------------ src/openrct2/peep/GuestPathfinding.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 5 +- src/openrct2/rct2/S6Exporter.cpp | 4 +- src/openrct2/rct2/S6Importer.cpp | 3 +- src/openrct2/ride/Ride.cpp | 64 ++++++++--------- src/openrct2/ride/Ride.h | 2 +- src/openrct2/ride/RideRatings.cpp | 34 ++++------ src/openrct2/ride/Station.cpp | 9 ++- src/openrct2/ride/Track.cpp | 12 ++-- src/openrct2/ride/Vehicle.cpp | 3 +- 12 files changed, 89 insertions(+), 124 deletions(-) diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 85eba8f2ed..6999c895fc 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -905,10 +905,9 @@ static int32_t cc_set(InteractiveConsole& console, const arguments_t& argv) rct_window* w = window_get_main(); if (w != nullptr) { - int32_t x = (int16_t)(int_val[0] * 32 + 16); - int32_t y = (int16_t)(int_val[1] * 32 + 16); - int32_t z = tile_element_height({ x, y }); - w->SetLocation(x, y, z); + auto location = TileCoordsXYZ(int_val[0], int_val[1], 0).ToCoordsXYZ().ToTileCentre(); + location.z = tile_element_height(location); + w->SetLocation(location.x, location.y, location.z); viewport_update_position(w); console.Execute("get location"); } diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 3e25146f7a..cc5e11ea85 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -3233,9 +3233,8 @@ template static void peep_head_for_nearest_ride(Guest* peep, bool co auto ride = get_ride(potentialRides[i]); if (ride != nullptr) { - int32_t rideX = ride->stations[0].Start.x * 32; - int32_t rideY = ride->stations[0].Start.y * 32; - int32_t distance = abs(rideX - peep->x) + abs(rideY - peep->y); + auto rideLocation = ride->stations[0].Start; + int32_t distance = abs(rideLocation.x - peep->x) + abs(rideLocation.y - peep->y); if (distance < closestRideDistance) { closestRide = ride; @@ -3541,11 +3540,9 @@ static constexpr const CoordsXY _MazeEntranceStart[] = { { 24, 8 }, }; -static void peep_update_ride_leave_entrance_maze(Guest* peep, Ride* ride, TileCoordsXYZD& entrance_loc) +static void peep_update_ride_leave_entrance_maze(Guest* peep, Ride* ride, CoordsXYZD& entrance_loc) { peep->maze_last_edge = entrance_loc.direction + 1; - entrance_loc.x *= 32; - entrance_loc.y *= 32; entrance_loc.x += CoordsDirectionDelta[entrance_loc.direction].x; entrance_loc.y += CoordsDirectionDelta[entrance_loc.direction].y; @@ -3574,10 +3571,9 @@ static void peep_update_ride_leave_entrance_maze(Guest* peep, Ride* ride, TileCo peep->sub_state = PEEP_RIDE_MAZE_PATHFINDING; } -static void peep_update_ride_leave_entrance_spiral_slide(Guest* peep, Ride* ride, TileCoordsXYZD& entrance_loc) +static void peep_update_ride_leave_entrance_spiral_slide(Guest* peep, Ride* ride, CoordsXYZD& entrance_loc) { - entrance_loc.x = ride->stations[peep->current_ride_station].Start.x * 32; - entrance_loc.y = ride->stations[peep->current_ride_station].Start.y * 32; + entrance_loc = { ride->stations[peep->current_ride_station].GetStart(), entrance_loc.direction }; TileElement* tile_element = ride_get_station_start_track_element(ride, peep->current_ride_station); @@ -3585,10 +3581,7 @@ static void peep_update_ride_leave_entrance_spiral_slide(Guest* peep, Ride* ride peep->var_37 = (entrance_loc.direction << 2) | (direction_track << 4); - const CoordsXY slidePlatformDestination = SpiralSlideWalkingPath[peep->var_37]; - - entrance_loc.x += slidePlatformDestination.x; - entrance_loc.y += slidePlatformDestination.y; + entrance_loc += SpiralSlideWalkingPath[peep->var_37]; peep->destination_x = entrance_loc.x; peep->destination_y = entrance_loc.y; @@ -3631,7 +3624,7 @@ static void peep_update_ride_leave_entrance_waypoints(Peep* peep, Ride* ride) Guard::Assert(!entranceLocation.isNull()); uint8_t direction_entrance = entranceLocation.direction; - CoordsXY waypoint = ride->stations[peep->current_ride_station].Start.ToCoordsXY().ToTileCentre(); + CoordsXY waypoint = ride->stations[peep->current_ride_station].Start.ToTileCentre(); TileElement* tile_element = ride_get_station_start_track_element(ride, peep->current_ride_station); @@ -3705,7 +3698,7 @@ void Guest::UpdateRideAdvanceThroughEntrance() Guard::Assert(sub_state == PEEP_RIDE_LEAVE_ENTRANCE, "Peep substate should be LEAVE_ENTRANCE"); if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_NO_VEHICLES)) { - TileCoordsXYZD entranceLocation = ride_get_entrance_location(ride, current_ride_station); + auto entranceLocation = ride_get_entrance_location(ride, current_ride_station).ToCoordsXYZD(); Guard::Assert(!entranceLocation.isNull()); if (ride->type == RIDE_TYPE_MAZE) @@ -4263,13 +4256,11 @@ void Guest::UpdateRideLeaveVehicle() return; } - TileCoordsXYZD exitLocation = ride_get_exit_location(ride, current_ride_station); + auto exitLocation = ride_get_exit_location(ride, current_ride_station).ToCoordsXYZD(); Guard::Assert(!exitLocation.isNull()); - CoordsXYZ waypointLoc; - waypointLoc.z = (int16_t)exitLocation.z * 8 + RideData5[ride->type].z; - waypointLoc.x = ride->stations[current_ride_station].Start.x * 32 + 16; - waypointLoc.y = ride->stations[current_ride_station].Start.y * 32 + 16; + auto waypointLoc = CoordsXYZ{ ride->stations[current_ride_station].Start.ToTileCentre(), + exitLocation.z + RideData5[ride->type].z }; TileElement* trackElement = ride_get_station_start_track_element(ride, current_ride_station); @@ -4462,9 +4453,7 @@ void Guest::UpdateRideApproachVehicleWaypoints() Vehicle* vehicle = GET_VEHICLE(ride->vehicles[current_train]); - CoordsXY targetLoc; - targetLoc.x = ride->stations[current_ride_station].Start.x * 32 + 16; - targetLoc.y = ride->stations[current_ride_station].Start.y * 32 + 16; + CoordsXY targetLoc = ride->stations[current_ride_station].Start.ToTileCentre(); if (ride->type == RIDE_TYPE_ENTERPRISE) { @@ -4532,9 +4521,7 @@ void Guest::UpdateRideApproachExitWaypoints() var_37--; Vehicle* vehicle = GET_VEHICLE(ride->vehicles[current_train]); - CoordsXY targetLoc; - targetLoc.x = ride->stations[current_ride_station].Start.x * 32 + 16; - targetLoc.y = ride->stations[current_ride_station].Start.y * 32 + 16; + CoordsXY targetLoc = ride->stations[current_ride_station].Start.ToTileCentre(); if (ride->type == RIDE_TYPE_ENTERPRISE) { @@ -4630,9 +4617,7 @@ void Guest::UpdateRideApproachSpiralSlide() auto exit = ride_get_exit_location(ride, current_ride_station); waypoint = 1; var_37 = (exit.direction * 4) | (var_37 & 0x30) | waypoint; - CoordsXY targetLoc; - targetLoc.x = ride->stations[current_ride_station].Start.x * 32; - targetLoc.y = ride->stations[current_ride_station].Start.y * 32; + CoordsXY targetLoc = ride->stations[current_ride_station].Start; assert(ride->type == RIDE_TYPE_SPIRAL_SLIDE); targetLoc += SpiralSlideWalkingPath[var_37]; @@ -4647,9 +4632,7 @@ void Guest::UpdateRideApproachSpiralSlide() // Actually increment the real peep waypoint var_37++; - CoordsXY targetLoc; - targetLoc.x = ride->stations[current_ride_station].Start.x * 32; - targetLoc.y = ride->stations[current_ride_station].Start.y * 32; + CoordsXY targetLoc = ride->stations[current_ride_station].Start; assert(ride->type == RIDE_TYPE_SPIRAL_SLIDE); targetLoc += SpiralSlideWalkingPath[var_37]; @@ -4707,19 +4690,18 @@ void Guest::UpdateRideOnSpiralSlide() return; case 3: { - int16_t newX = ride->stations[current_ride_station].Start.x * 32; - int16_t newY = ride->stations[current_ride_station].Start.y * 32; + auto newLocation = ride->stations[current_ride_station].Start; uint8_t dir = (var_37 / 4) & 3; // Set the location that the peep walks to go on slide again - destination_x = newX + _SpiralSlideEndWaypoint[dir].x; - destination_y = newY + _SpiralSlideEndWaypoint[dir].y; + destination_x = newLocation.x + _SpiralSlideEndWaypoint[dir].x; + destination_y = newLocation.y + _SpiralSlideEndWaypoint[dir].y; // Move the peep sprite to just at the end of the slide - newX += _SpiralSlideEnd[dir].x; - newY += _SpiralSlideEnd[dir].y; + newLocation.x += _SpiralSlideEnd[dir].x; + newLocation.y += _SpiralSlideEnd[dir].y; - MoveTo(newX, newY, z); + MoveTo(newLocation.x, newLocation.y, z); sprite_direction = (var_37 & 0xC) * 2; @@ -4740,9 +4722,7 @@ void Guest::UpdateRideOnSpiralSlide() uint8_t waypoint = 2; var_37 = (var_37 * 4 & 0x30) + waypoint; - CoordsXY targetLoc; - targetLoc.x = ride->stations[current_ride_station].Start.x * 32; - targetLoc.y = ride->stations[current_ride_station].Start.y * 32; + CoordsXY targetLoc = ride->stations[current_ride_station].Start; assert(ride->type == RIDE_TYPE_SPIRAL_SLIDE); targetLoc += SpiralSlideWalkingPath[var_37]; @@ -4783,9 +4763,7 @@ void Guest::UpdateRideLeaveSpiralSlide() waypoint--; // Actually decrement the peep waypoint var_37--; - CoordsXY targetLoc; - targetLoc.x = ride->stations[current_ride_station].Start.x * 32; - targetLoc.y = ride->stations[current_ride_station].Start.y * 32; + CoordsXY targetLoc = ride->stations[current_ride_station].Start; assert(ride->type == RIDE_TYPE_SPIRAL_SLIDE); targetLoc += SpiralSlideWalkingPath[var_37]; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index c3ecff6b07..bda05999fe 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -2115,7 +2115,7 @@ int32_t guest_path_finding(Guest* peep) if (numEntranceStations == 0) { // closestStationNum is always 0 here. - auto entranceXY = ride->stations[closestStationNum].Start; + auto entranceXY = TileCoordsXY(ride->stations[closestStationNum].Start); loc.x = entranceXY.x; loc.y = entranceXY.y; loc.z = ride->stations[closestStationNum].Height; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 60a62b308a..748d832630 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -757,9 +757,10 @@ private: } else { - dst->stations[i].Start = { src->station_starts[i].x, src->station_starts[i].y }; + auto tileStartLoc = TileCoordsXY{ src->station_starts[i].x, src->station_starts[i].y }; + dst->stations[i].Start = tileStartLoc.ToCoordsXY(); } - dst->stations[i].SetBaseZ(src->station_height[i] * 4); + dst->stations[i].SetBaseZ(src->station_height[i] * RCT1_COORDS_Z_STEP); dst->stations[i].Length = src->station_length[i]; dst->stations[i].Depart = src->station_light[i]; diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 8877f8cf14..fd385c09bb 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -555,8 +555,8 @@ void S6Exporter::ExportRide(rct2_ride* dst, const Ride* src) } else { - dst->station_starts[i] = { static_cast(src->stations[i].Start.x), - static_cast(src->stations[i].Start.y) }; + auto tileStartLoc = TileCoordsXY(src->stations[i].Start); + dst->station_starts[i] = { static_cast(tileStartLoc.x), static_cast(tileStartLoc.y) }; } dst->station_heights[i] = src->stations[i].Height; dst->station_length[i] = src->stations[i].Length; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index b7dc1c06db..09675231c4 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -540,7 +540,8 @@ public: } else { - dst->stations[i].Start = { src->station_starts[i].x, src->station_starts[i].y }; + auto tileStartLoc = TileCoordsXY(src->station_starts[i].x, src->station_starts[i].y); + dst->stations[i].Start = tileStartLoc.ToCoordsXY(); } dst->stations[i].Height = src->station_heights[i]; dst->stations[i].Length = src->station_length[i]; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index f17d8789cf..20b50b08fd 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -2226,20 +2226,16 @@ void Ride::UpdateSpiralSlide() if (stations[i].Start.isNull()) continue; - int32_t x = stations[i].Start.x; - int32_t y = stations[i].Start.y; + auto startLoc = stations[i].Start; TileElement* tileElement = ride_get_station_start_track_element(this, i); if (tileElement == nullptr) continue; int32_t rotation = tileElement->GetDirection(); - x *= 32; - y *= 32; - x += ride_spiral_slide_main_tile_offset[rotation][current_rotation].x; - y += ride_spiral_slide_main_tile_offset[rotation][current_rotation].y; + startLoc += ride_spiral_slide_main_tile_offset[rotation][current_rotation]; - map_invalidate_tile_zoom0({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); + map_invalidate_tile_zoom0({ startLoc, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }); } } @@ -3268,7 +3264,7 @@ static void ride_entrance_exit_connected(Ride* ride) static void ride_shop_connected(Ride* ride) { - TileCoordsXY shopLoc = ride->stations[0].Start; + auto shopLoc = TileCoordsXY(ride->stations[0].Start); if (shopLoc.isNull()) return; @@ -4888,11 +4884,11 @@ void loc_6DDF9C(Ride* ride, TileElement* tileElement) */ static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying) { - TileCoordsXY location; + CoordsXYZ location; int32_t stationIndex; for (stationIndex = 0; stationIndex < MAX_STATIONS; stationIndex++) { - location = ride->stations[stationIndex].Start; + location = ride->stations[stationIndex].GetStart(); if (!location.isNull()) break; if (stationIndex == (MAX_STATIONS - 1)) @@ -4902,9 +4898,9 @@ static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying) } } - int32_t x = location.x * 32; - int32_t y = location.y * 32; - int32_t z = ride->stations[stationIndex].GetBaseZ(); + int32_t x = location.x; + int32_t y = location.y; + int32_t z = location.z; bool success = false; TileElement* tileElement = map_get_first_element_at({ x, y }); @@ -5102,10 +5098,8 @@ static void loc_6B51C0(const Ride* ride) if (ride->type != RIDE_TYPE_MAZE) { - int32_t x = ride->stations[i].Start.x * 32; - int32_t y = ride->stations[i].Start.y * 32; - int32_t z = ride->stations[i].GetBaseZ(); - window_scroll_to_location(w, x, y, z); + auto location = ride->stations[i].GetStart(); + window_scroll_to_location(w, location.x, location.y, location.z); CoordsXYE trackElement; ride_try_get_origin_element(ride, &trackElement); @@ -5208,8 +5202,9 @@ int32_t ride_is_valid_for_test(Ride* ride, int32_t status, bool isApplying) } // z = ride->stations[i].GetBaseZ(); - trackElement.x = ride->stations[stationIndex].Start.x * 32; - trackElement.y = ride->stations[stationIndex].Start.y * 32; + auto startLoc = ride->stations[stationIndex].Start; + trackElement.x = startLoc.x; + trackElement.y = startLoc.y; trackElement.element = loc_6B4F6B(ride->id, trackElement.x, trackElement.y); if (trackElement.element == nullptr) { @@ -5344,8 +5339,9 @@ int32_t ride_is_valid_for_open(Ride* ride, int32_t goingToBeOpen, bool isApplyin } // z = ride->stations[i].GetBaseZ(); - trackElement.x = ride->stations[stationIndex].Start.x * 32; - trackElement.y = ride->stations[stationIndex].Start.y * 32; + auto startLoc = ride->stations[stationIndex].Start; + trackElement.x = startLoc.x; + trackElement.y = startLoc.y; trackElement.element = loc_6B4F6B(ride->id, trackElement.x, trackElement.y); if (trackElement.element == nullptr) { @@ -6260,8 +6256,8 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenC } else { - auto mapX = stationStart.x * 32; - auto mapY = stationStart.y * 32; + auto mapX = stationStart.x; + auto mapY = stationStart.y; entranceMinX = mapX; entranceMinY = mapY; @@ -6615,19 +6611,16 @@ static int32_t ride_get_track_length(Ride* ride) track_circuit_iterator it, slowIt; ride_id_t rideIndex; int32_t trackType, result; - CoordsXY trackStart; + CoordsXYZ trackStart; bool foundTrack = false; for (int32_t i = 0; i < MAX_STATIONS && !foundTrack; i++) { - const auto& stationTileLoc = ride->stations[i].Start; - if (stationTileLoc.isNull()) + trackStart = ride->stations[i].GetStart(); + if (trackStart.isNull()) continue; - trackStart = stationTileLoc.ToCoordsXY(); - auto z = ride->stations[i].GetBaseZ(); - - tileElement = map_get_first_element_at(stationTileLoc.ToCoordsXY()); + tileElement = map_get_first_element_at(trackStart); if (tileElement == nullptr) continue; do @@ -6639,7 +6632,7 @@ static int32_t ride_get_track_length(Ride* ride) if (!(TrackSequenceProperties[trackType][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) continue; - if (tileElement->GetBaseZ() != z) + if (tileElement->GetBaseZ() != trackStart.z) continue; foundTrack = true; @@ -6876,17 +6869,16 @@ void sub_6CB945(Ride* ride) if (ride->stations[stationId].Start.isNull()) continue; - CoordsXYZ location = { ride->stations[stationId].Start.x * 32, ride->stations[stationId].Start.y * 32, - ride->stations[stationId].GetBaseZ() }; + CoordsXYZ location = ride->stations[stationId].GetStart(); auto tileHeight = TileCoordsXYZ(location).z; - uint8_t direction = 0xFF; + uint8_t direction = INVALID_DIRECTION; bool specialTrack = false; TileElement* tileElement = nullptr; while (true) { - if (direction != 0xFF) + if (direction != INVALID_DIRECTION) { location.x -= CoordsDirectionDelta[direction].x; location.y -= CoordsDirectionDelta[direction].y; @@ -7331,7 +7323,7 @@ bool ride_has_adjacent_station(Ride* ride) * adjacent station on either side. */ for (int32_t stationNum = 0; stationNum < MAX_STATIONS; stationNum++) { - auto stationStart = ride->stations[stationNum].GetStart(); + auto stationStart = ride->stations[stationNum].Start; if (!stationStart.isNull()) { /* Get the map element for the station start. */ diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index f36a1d00a2..2e6652d31c 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -161,7 +161,7 @@ struct rct_ride_entry struct RideStation { - TileCoordsXY Start; + CoordsXY Start; uint8_t Height; uint8_t Length; uint8_t Depart; diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 3c31e85888..27c8cf29c7 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -406,17 +406,15 @@ static void ride_ratings_begin_proximity_loop() gRideRatingsCalcData.station_flags |= RIDE_RATING_STATION_FLAG_NO_ENTRANCE; } - int32_t x = ride->stations[i].Start.x * 32; - int32_t y = ride->stations[i].Start.y * 32; - int32_t z = ride->stations[i].GetBaseZ(); + auto location = ride->stations[i].GetStart(); - gRideRatingsCalcData.proximity_x = x; - gRideRatingsCalcData.proximity_y = y; - gRideRatingsCalcData.proximity_z = z; + gRideRatingsCalcData.proximity_x = location.x; + gRideRatingsCalcData.proximity_y = location.y; + gRideRatingsCalcData.proximity_z = location.z; gRideRatingsCalcData.proximity_track_type = 255; - gRideRatingsCalcData.proximity_start_x = x; - gRideRatingsCalcData.proximity_start_y = y; - gRideRatingsCalcData.proximity_start_z = z; + gRideRatingsCalcData.proximity_start_x = location.x; + gRideRatingsCalcData.proximity_start_y = location.y; + gRideRatingsCalcData.proximity_start_z = location.z; return; } } @@ -1430,7 +1428,7 @@ static rating_tuple ride_ratings_get_drop_ratings(Ride* ride) static int32_t ride_ratings_get_scenery_score(Ride* ride) { int8_t i = ride_get_first_valid_station_start(ride); - int32_t x, y; + CoordsXY location; if (i == -1) { @@ -1439,18 +1437,14 @@ static int32_t ride_ratings_get_scenery_score(Ride* ride) if (ride->type == RIDE_TYPE_MAZE) { - TileCoordsXYZD location = ride_get_entrance_location(ride, 0); - x = location.x; - y = location.y; + location = ride_get_entrance_location(ride, 0).ToCoordsXY(); } else { - auto location = ride->stations[i].Start; - x = location.x; - y = location.y; + location = ride->stations[i].Start; } - int32_t z = tile_element_height({ x * 32, y * 32 }); + int32_t z = tile_element_height(location); // Check if station is underground, returns a fixed mediocre score since you can't have scenery underground if (z > ride->stations[i].GetBaseZ()) @@ -1460,9 +1454,11 @@ static int32_t ride_ratings_get_scenery_score(Ride* ride) // Count surrounding scenery items int32_t numSceneryItems = 0; - for (int32_t yy = std::max(y - 5, 0); yy <= std::min(y + 5, 255); yy++) + auto tileLocation = TileCoordsXY(location); + for (int32_t yy = std::max(tileLocation.y - 5, 0); yy <= std::min(tileLocation.y + 5, MAXIMUM_MAP_SIZE_TECHNICAL - 1); yy++) { - for (int32_t xx = std::max(x - 5, 0); xx <= std::min(x + 5, 255); xx++) + for (int32_t xx = std::max(tileLocation.x - 5, 0); xx <= std::min(tileLocation.x + 5, MAXIMUM_MAP_SIZE_TECHNICAL - 1); + xx++) { // Count scenery items on this tile TileElement* tileElement = map_get_first_element_at(TileCoordsXY{ xx, yy }.ToCoordsXY()); diff --git a/src/openrct2/ride/Station.cpp b/src/openrct2/ride/Station.cpp index 5b6d65f0b4..a594fe2e1e 100644 --- a/src/openrct2/ride/Station.cpp +++ b/src/openrct2/ride/Station.cpp @@ -318,7 +318,7 @@ static void ride_race_init_vehicle_speeds(Ride* ride) */ static void ride_invalidate_station_start(Ride* ride, int32_t stationIndex, bool greenLight) { - auto startPos = ride->stations[stationIndex].GetStart(); + auto startPos = ride->stations[stationIndex].Start; TileElement* tileElement = ride_get_station_start_track_element(ride, stationIndex); // If no station track found return @@ -434,16 +434,15 @@ void ride_set_exit_location(Ride* ride, const int32_t stationIndex, const TileCo int32_t RideStation::GetBaseZ() const { - return Height * 8; + return Height * COORDS_Z_STEP; } void RideStation::SetBaseZ(int32_t newZ) { - Height = newZ / 8; + Height = newZ / COORDS_Z_STEP; } CoordsXYZ RideStation::GetStart() const { - TileCoordsXYZ stationTileCoords{ Start.x, Start.y, Height }; - return stationTileCoords.ToCoordsXYZ(); + return { Start, GetBaseZ() }; } diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index c1389947c8..b1c5103dde 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -661,8 +661,8 @@ bool track_add_station_element(int32_t x, int32_t y, int32_t z, int32_t directio int8_t stationIndex = ride_get_first_empty_station_start(ride); assert(stationIndex != -1); - ride->stations[stationIndex].Start.x = (x >> 5); - ride->stations[stationIndex].Start.y = (y >> 5); + ride->stations[stationIndex].Start.x = x; + ride->stations[stationIndex].Start.y = y; ride->stations[stationIndex].Height = z; ride->stations[stationIndex].Depart = 1; ride->stations[stationIndex].Length = 0; @@ -754,8 +754,8 @@ bool track_add_station_element(int32_t x, int32_t y, int32_t z, int32_t directio int8_t stationIndex = ride_get_first_empty_station_start(ride); assert(stationIndex != -1); - ride->stations[stationIndex].Start.x = (x >> 5); - ride->stations[stationIndex].Start.y = (y >> 5); + ride->stations[stationIndex].Start.x = x; + ride->stations[stationIndex].Start.y = y; ride->stations[stationIndex].Height = z; ride->stations[stationIndex].Depart = 1; ride->stations[stationIndex].Length = stationLength; @@ -901,8 +901,8 @@ bool track_remove_station_element(int32_t x, int32_t y, int32_t z, int32_t direc int8_t stationIndex = ride_get_first_empty_station_start(ride); assert(stationIndex != -1); - ride->stations[stationIndex].Start.x = (x >> 5); - ride->stations[stationIndex].Start.y = (y >> 5); + ride->stations[stationIndex].Start.x = x; + ride->stations[stationIndex].Start.y = y; ride->stations[stationIndex].Height = z; ride->stations[stationIndex].Depart = 1; ride->stations[stationIndex].Length = stationLength != 0 ? stationLength : byte_F441D1; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 77059fac26..61bd7e67f4 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -9258,8 +9258,7 @@ loc_6DCE68: for (int32_t i = 0; i < MAX_STATIONS; i++) { - auto trackLoc = TileCoordsXY(vehicle->TrackLocation); - if (trackLoc != ride->stations[i].Start) + if (vehicle->TrackLocation != ride->stations[i].Start) { continue; } From 9c7c57f7224a2755e23c55eda4ceee15106e25d9 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Thu, 5 Mar 2020 21:25:58 +0100 Subject: [PATCH 2/2] Apply review request --- src/openrct2/ride/Ride.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 20b50b08fd..24ac53cd8c 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -4898,19 +4898,15 @@ static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying) } } - int32_t x = location.x; - int32_t y = location.y; - int32_t z = location.z; - bool success = false; - TileElement* tileElement = map_get_first_element_at({ x, y }); + TileElement* tileElement = map_get_first_element_at(location); if (tileElement == nullptr) return success; do { if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) continue; - if (tileElement->GetBaseZ() != z) + if (tileElement->GetBaseZ() != location.z) continue; if (!(TrackSequenceProperties[tileElement->AsTrack()->GetTrackType()][0] & TRACK_SEQUENCE_FLAG_ORIGIN)) @@ -4933,7 +4929,7 @@ static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying) int32_t state = STATE_FIND_CABLE_LIFT; track_circuit_iterator it; - track_circuit_iterator_begin(&it, { x, y, tileElement }); + track_circuit_iterator_begin(&it, { location, tileElement }); while (track_circuit_iterator_previous(&it)) { tileElement = it.current.element; @@ -4975,12 +4971,10 @@ static bool ride_initialise_cable_lift_track(Ride* ride, bool isApplying) } if (isApplying) { - z = tileElement->GetBaseZ(); + auto tmpLoc = CoordsXYZ{ it.current, tileElement->GetBaseZ() }; int32_t direction = tileElement->GetDirection(); trackType = tileElement->AsTrack()->GetTrackType(); - x = it.current.x; - y = it.current.y; - sub_6C683D(&x, &y, &z, direction, trackType, 0, &tileElement, flags); + sub_6C683D(&tmpLoc.x, &tmpLoc.y, &tmpLoc.z, direction, trackType, 0, &tileElement, flags); } } return true;