mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #10229 from tupaschoal/refactor_ride_get_entrance_or_exit
Refactor ride_get_entrance_or_exit_position_from_screen_position()
This commit is contained in:
commit
3f7a4a9f42
|
@ -362,10 +362,7 @@ static void window_maze_construction_entrance_tooldown(ScreenCoordsXY screenCoor
|
|||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW;
|
||||
|
||||
int32_t direction = 0;
|
||||
CoordsXY entranceOrExitCoords;
|
||||
ride_get_entrance_or_exit_position_from_screen_position(
|
||||
screenCoords.x, screenCoords.y, &entranceOrExitCoords.x, &entranceOrExitCoords.y, &direction);
|
||||
CoordsXYZD entranceOrExitCoords = ride_get_entrance_or_exit_position_from_screen_position(screenCoords);
|
||||
if (entranceOrExitCoords.x == LOCATION_NULL)
|
||||
return;
|
||||
|
||||
|
@ -375,7 +372,7 @@ static void window_maze_construction_entrance_tooldown(ScreenCoordsXY screenCoor
|
|||
ride_id_t rideIndex = gRideEntranceExitPlaceRideIndex;
|
||||
|
||||
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(
|
||||
entranceOrExitCoords, direction_reverse(direction), rideIndex, gRideEntranceExitPlaceStationIndex,
|
||||
entranceOrExitCoords, direction_reverse(entranceOrExitCoords.direction), rideIndex, gRideEntranceExitPlaceStationIndex,
|
||||
gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT);
|
||||
|
||||
rideEntranceExitPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
|
||||
|
|
|
@ -3688,7 +3688,6 @@ void ride_construction_toolupdate_construct(ScreenCoordsXY screenCoords)
|
|||
*/
|
||||
void ride_construction_toolupdate_entrance_exit(ScreenCoordsXY screenCoords)
|
||||
{
|
||||
int32_t x, y, direction;
|
||||
uint8_t stationNum;
|
||||
|
||||
map_invalidate_selection_rect();
|
||||
|
@ -3696,7 +3695,7 @@ void ride_construction_toolupdate_entrance_exit(ScreenCoordsXY screenCoords)
|
|||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_CONSTRUCT;
|
||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW;
|
||||
ride_get_entrance_or_exit_position_from_screen_position(screenCoords.x, screenCoords.y, &x, &y, &direction);
|
||||
CoordsXYZD entranceOrExitCoords = ride_get_entrance_or_exit_position_from_screen_position(screenCoords);
|
||||
if (gRideEntranceExitPlaceDirection == 255)
|
||||
{
|
||||
ride_construction_invalidate_current_track();
|
||||
|
@ -3705,26 +3704,27 @@ void ride_construction_toolupdate_entrance_exit(ScreenCoordsXY screenCoords)
|
|||
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE;
|
||||
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW;
|
||||
gMapSelectType = MAP_SELECT_TYPE_FULL;
|
||||
gMapSelectPositionA.x = x;
|
||||
gMapSelectPositionA.y = y;
|
||||
gMapSelectPositionB.x = x;
|
||||
gMapSelectPositionB.y = y;
|
||||
gMapSelectArrowDirection = direction_reverse(direction);
|
||||
gMapSelectArrowPosition.x = x;
|
||||
gMapSelectArrowPosition.y = y;
|
||||
gMapSelectArrowPosition.z = _unkF44188.z * 8;
|
||||
gMapSelectPositionA.x = entranceOrExitCoords.x;
|
||||
gMapSelectPositionA.y = entranceOrExitCoords.y;
|
||||
gMapSelectPositionB.x = entranceOrExitCoords.x;
|
||||
gMapSelectPositionB.y = entranceOrExitCoords.y;
|
||||
gMapSelectArrowDirection = direction_reverse(entranceOrExitCoords.direction);
|
||||
gMapSelectArrowPosition.x = entranceOrExitCoords.x;
|
||||
gMapSelectArrowPosition.y = entranceOrExitCoords.y;
|
||||
gMapSelectArrowPosition.z = entranceOrExitCoords.z * 8;
|
||||
map_invalidate_selection_rect();
|
||||
|
||||
direction = direction_reverse(gRideEntranceExitPlaceDirection);
|
||||
entranceOrExitCoords.direction = direction_reverse(gRideEntranceExitPlaceDirection);
|
||||
stationNum = gRideEntranceExitPlaceStationIndex;
|
||||
if (!(_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT) || x != gRideEntranceExitGhostPosition.x
|
||||
|| y != gRideEntranceExitGhostPosition.y || direction != gRideEntranceExitGhostPosition.direction
|
||||
|| stationNum != gRideEntranceExitGhostStationIndex)
|
||||
if (!(_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT)
|
||||
|| entranceOrExitCoords != gRideEntranceExitGhostPosition || stationNum != gRideEntranceExitGhostStationIndex)
|
||||
{
|
||||
auto ride = get_ride(_currentRideIndex);
|
||||
if (ride != nullptr)
|
||||
{
|
||||
_currentTrackPrice = ride_entrance_exit_place_ghost(ride, x, y, direction, gRideEntranceExitPlaceType, stationNum);
|
||||
_currentTrackPrice = ride_entrance_exit_place_ghost(
|
||||
ride, entranceOrExitCoords.x, entranceOrExitCoords.y, entranceOrExitCoords.direction,
|
||||
gRideEntranceExitPlaceType, stationNum);
|
||||
}
|
||||
window_ride_construction_update_active_elements();
|
||||
}
|
||||
|
@ -3936,13 +3936,12 @@ static void ride_construction_tooldown_entrance_exit(ScreenCoordsXY screenCoords
|
|||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE;
|
||||
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW;
|
||||
|
||||
int32_t mapX, mapY, direction;
|
||||
ride_get_entrance_or_exit_position_from_screen_position(screenCoords.x, screenCoords.y, &mapX, &mapY, &direction);
|
||||
CoordsXYZD entranceOrExitCoords = ride_get_entrance_or_exit_position_from_screen_position(screenCoords);
|
||||
if (gRideEntranceExitPlaceDirection == 255)
|
||||
return;
|
||||
|
||||
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(
|
||||
{ _unkF44188.x, _unkF44188.y }, direction_reverse(gRideEntranceExitPlaceDirection), gRideEntranceExitPlaceRideIndex,
|
||||
entranceOrExitCoords, direction_reverse(gRideEntranceExitPlaceDirection), gRideEntranceExitPlaceRideIndex,
|
||||
gRideEntranceExitPlaceStationIndex, gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT);
|
||||
|
||||
rideEntranceExitPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
|
||||
|
|
|
@ -111,8 +111,6 @@ CoordsXYZ _previousTrackPiece;
|
|||
uint8_t _currentBrakeSpeed2;
|
||||
uint8_t _currentSeatRotationAngle;
|
||||
|
||||
LocationXYZ16 _unkF44188;
|
||||
|
||||
CoordsXYZD _unkF440C5;
|
||||
|
||||
uint8_t gRideEntranceExitPlaceType;
|
||||
|
@ -6173,18 +6171,20 @@ static int32_t loc_6CD18E(
|
|||
*
|
||||
* rct2: 0x006CCF70
|
||||
*/
|
||||
void ride_get_entrance_or_exit_position_from_screen_position(
|
||||
int32_t screenX, int32_t screenY, int32_t* outX, int32_t* outY, int32_t* outDirection)
|
||||
CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsXY screenCoords)
|
||||
{
|
||||
int16_t mapX, mapY;
|
||||
int16_t entranceMinX, entranceMinY, entranceMaxX, entranceMaxY, word_F4418C, word_F4418E;
|
||||
int32_t interactionType, direction, stationHeight, stationDirection;
|
||||
int32_t interactionType, stationDirection;
|
||||
uint8_t stationHeight;
|
||||
TileElement* tileElement;
|
||||
rct_viewport* viewport;
|
||||
Ride* ride;
|
||||
CoordsXYZD entranceExitCoords{};
|
||||
|
||||
gRideEntranceExitPlaceDirection = 255;
|
||||
get_map_coordinates_from_pos(screenX, screenY, 0xFFFB, &mapX, &mapY, &interactionType, &tileElement, &viewport);
|
||||
get_map_coordinates_from_pos(
|
||||
screenCoords.x, screenCoords.y, 0xFFFB, &mapX, &mapY, &interactionType, &tileElement, &viewport);
|
||||
if (interactionType != 0)
|
||||
{
|
||||
if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK)
|
||||
|
@ -6208,32 +6208,37 @@ void ride_get_entrance_or_exit_position_from_screen_position(
|
|||
|
||||
ride = get_ride(gRideEntranceExitPlaceRideIndex);
|
||||
if (ride == nullptr)
|
||||
return;
|
||||
{
|
||||
entranceExitCoords.x = LOCATION_NULL;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
|
||||
stationHeight = ride->stations[gRideEntranceExitPlaceStationIndex].Height;
|
||||
|
||||
screen_get_map_xy_with_z(screenX, screenY, stationHeight * 8, &mapX, &mapY);
|
||||
screen_get_map_xy_with_z(screenCoords.x, screenCoords.y, stationHeight * 8, &mapX, &mapY);
|
||||
if (mapX == LOCATION_NULL)
|
||||
{
|
||||
*outX = 0x8000;
|
||||
return;
|
||||
entranceExitCoords.x = LOCATION_NULL;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
|
||||
word_F4418C = mapX;
|
||||
word_F4418E = mapY;
|
||||
_unkF44188.x = floor2(mapX, 32);
|
||||
_unkF44188.y = floor2(mapY, 32);
|
||||
*outX = _unkF44188.x;
|
||||
*outY = _unkF44188.y;
|
||||
|
||||
entranceExitCoords = { floor2(mapX, 32), floor2(mapY, 32), stationHeight, INVALID_DIRECTION };
|
||||
|
||||
if (ride->type == RIDE_TYPE_NULL)
|
||||
return;
|
||||
{
|
||||
entranceExitCoords.x = LOCATION_NULL;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
|
||||
LocationXY8 stationStart = ride->stations[gRideEntranceExitPlaceStationIndex].Start;
|
||||
if (stationStart.xy == RCT_XY8_UNDEFINED)
|
||||
return;
|
||||
|
||||
_unkF44188.z = stationHeight;
|
||||
{
|
||||
entranceExitCoords.x = LOCATION_NULL;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
|
||||
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_3))
|
||||
{
|
||||
|
@ -6241,17 +6246,17 @@ void ride_get_entrance_or_exit_position_from_screen_position(
|
|||
mapY = (word_F4418E & 0x1F) - 16;
|
||||
if (std::abs(mapX) < std::abs(mapY))
|
||||
{
|
||||
direction = mapY < 0 ? 3 : 1;
|
||||
entranceExitCoords.direction = mapY < 0 ? 3 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = mapX < 0 ? 0 : 2;
|
||||
entranceExitCoords.direction = mapX < 0 ? 0 : 2;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < MAX_STATIONS; i++)
|
||||
{
|
||||
mapX = _unkF44188.x + CoordsDirectionDelta[direction].x;
|
||||
mapY = _unkF44188.y + CoordsDirectionDelta[direction].y;
|
||||
mapX = entranceExitCoords.x + CoordsDirectionDelta[entranceExitCoords.direction].x;
|
||||
mapY = entranceExitCoords.y + CoordsDirectionDelta[entranceExitCoords.direction].y;
|
||||
if (mapX >= 0 && mapY >= 0 && mapX < (256 * 32) && mapY < (256 * 32))
|
||||
{
|
||||
tileElement = map_get_first_element_at(mapX >> 5, mapY >> 5);
|
||||
|
@ -6267,25 +6272,26 @@ void ride_get_entrance_or_exit_position_from_screen_position(
|
|||
continue;
|
||||
if (tileElement->AsTrack()->GetTrackType() == TRACK_ELEM_MAZE)
|
||||
{
|
||||
gRideEntranceExitPlaceDirection = direction_reverse(direction);
|
||||
*outDirection = direction_reverse(direction);
|
||||
return;
|
||||
entranceExitCoords.direction = direction_reverse(entranceExitCoords.direction);
|
||||
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
if (tileElement->AsTrack()->GetStationIndex() != gRideEntranceExitPlaceStationIndex)
|
||||
continue;
|
||||
|
||||
int32_t eax = (direction + 2 - tileElement->GetDirection()) & TILE_ELEMENT_DIRECTION_MASK;
|
||||
int32_t eax = (entranceExitCoords.direction + 2 - tileElement->GetDirection())
|
||||
& TILE_ELEMENT_DIRECTION_MASK;
|
||||
if (FlatRideTrackSequenceProperties[tileElement->AsTrack()->GetTrackType()]
|
||||
[tileElement->AsTrack()->GetSequenceIndex()]
|
||||
& (1 << eax))
|
||||
{
|
||||
gRideEntranceExitPlaceDirection = direction_reverse(direction);
|
||||
*outDirection = direction_reverse(direction);
|
||||
return;
|
||||
entranceExitCoords.direction = direction_reverse(entranceExitCoords.direction);
|
||||
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
} while (!(tileElement++)->IsLastForTile());
|
||||
}
|
||||
direction = (direction + 1) & 3;
|
||||
entranceExitCoords.direction = (entranceExitCoords.direction + 1) & 3;
|
||||
}
|
||||
gRideEntranceExitPlaceDirection = 0xFF;
|
||||
}
|
||||
|
@ -6299,18 +6305,18 @@ void ride_get_entrance_or_exit_position_from_screen_position(
|
|||
tileElement = ride_get_station_start_track_element(ride, gRideEntranceExitPlaceStationIndex);
|
||||
if (tileElement == nullptr)
|
||||
{
|
||||
*outX = 0x8000;
|
||||
return;
|
||||
entranceExitCoords.x = LOCATION_NULL;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
direction = tileElement->GetDirection();
|
||||
stationDirection = direction;
|
||||
entranceExitCoords.direction = tileElement->GetDirection();
|
||||
stationDirection = entranceExitCoords.direction;
|
||||
|
||||
while (true)
|
||||
{
|
||||
entranceMaxX = mapX;
|
||||
entranceMaxY = mapY;
|
||||
mapX -= CoordsDirectionDelta[direction].x;
|
||||
mapY -= CoordsDirectionDelta[direction].y;
|
||||
mapX -= CoordsDirectionDelta[entranceExitCoords.direction].x;
|
||||
mapY -= CoordsDirectionDelta[entranceExitCoords.direction].y;
|
||||
tileElement = map_get_first_element_at(mapX >> 5, mapY >> 5);
|
||||
if (tileElement == nullptr)
|
||||
break;
|
||||
|
@ -6352,14 +6358,17 @@ void ride_get_entrance_or_exit_position_from_screen_position(
|
|||
entranceMaxY = mapY;
|
||||
}
|
||||
|
||||
direction = loc_6CD18E(*outX, *outY, entranceMinX - 32, entranceMinY - 32, entranceMaxX + 32, entranceMaxY + 32);
|
||||
auto direction = loc_6CD18E(
|
||||
entranceExitCoords.x, entranceExitCoords.y, entranceMinX - 32, entranceMinY - 32, entranceMaxX + 32,
|
||||
entranceMaxY + 32);
|
||||
if (direction != -1 && direction != stationDirection && direction != direction_reverse(stationDirection))
|
||||
{
|
||||
gRideEntranceExitPlaceDirection = direction;
|
||||
*outDirection = direction;
|
||||
return;
|
||||
entranceExitCoords.direction = direction;
|
||||
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;
|
||||
return entranceExitCoords;
|
||||
}
|
||||
}
|
||||
return entranceExitCoords;
|
||||
}
|
||||
|
||||
bool ride_select_backwards_from_front()
|
||||
|
|
|
@ -1120,8 +1120,6 @@ extern CoordsXYZ _previousTrackPiece;
|
|||
extern uint8_t _currentBrakeSpeed2;
|
||||
extern uint8_t _currentSeatRotationAngle;
|
||||
|
||||
extern LocationXYZ16 _unkF44188;
|
||||
|
||||
extern CoordsXYZD _unkF440C5;
|
||||
|
||||
extern uint8_t gRideEntranceExitPlaceType;
|
||||
|
@ -1227,8 +1225,7 @@ void window_ride_construction_update_active_elements();
|
|||
void ride_construction_remove_ghosts();
|
||||
money32 ride_entrance_exit_place_ghost(
|
||||
Ride* ride, int32_t x, int32_t y, int32_t direction, int32_t placeType, int32_t stationNum);
|
||||
void ride_get_entrance_or_exit_position_from_screen_position(
|
||||
int32_t x, int32_t y, int32_t* outX, int32_t* outY, int32_t* outDirection);
|
||||
CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsXY screenCoords);
|
||||
|
||||
bool ride_select_backwards_from_front();
|
||||
bool ride_select_forwards_from_back();
|
||||
|
|
|
@ -323,6 +323,16 @@ struct CoordsXYZD : public CoordsXYZ
|
|||
{
|
||||
}
|
||||
|
||||
bool operator==(const CoordsXYZD& other) const
|
||||
{
|
||||
return x == other.x && y == other.y && z == other.z && direction == other.direction;
|
||||
}
|
||||
|
||||
bool operator!=(const CoordsXYZD& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool isNull() const
|
||||
{
|
||||
return x == COORDS_NULL;
|
||||
|
|
Loading…
Reference in New Issue