Fix issues in code review

Implement operator== and operator!= for CoordsXYZD
Set location to null before returning from ride_get_entrance_or_exit_position_from_screen_position
This commit is contained in:
Tulio Leao 2019-11-13 18:46:02 -03:00
parent 27f47e1407
commit 7e65aeaea3
3 changed files with 24 additions and 10 deletions

View File

@ -3717,10 +3717,7 @@ void ride_construction_toolupdate_entrance_exit(ScreenCoordsXY screenCoords)
entranceOrExitCoords.direction = direction_reverse(gRideEntranceExitPlaceDirection);
stationNum = gRideEntranceExitPlaceStationIndex;
if (!(_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT)
|| entranceOrExitCoords.x != gRideEntranceExitGhostPosition.x
|| entranceOrExitCoords.y != gRideEntranceExitGhostPosition.y
|| entranceOrExitCoords.direction != gRideEntranceExitGhostPosition.direction
|| stationNum != gRideEntranceExitGhostStationIndex)
|| entranceOrExitCoords != gRideEntranceExitGhostPosition || stationNum != gRideEntranceExitGhostStationIndex)
{
auto ride = get_ride(_currentRideIndex);
if (ride != nullptr)

View File

@ -6175,7 +6175,8 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
{
int16_t mapX, mapY;
int16_t entranceMinX, entranceMinY, entranceMaxX, entranceMaxY, word_F4418C, word_F4418E;
int32_t interactionType, stationHeight, stationDirection;
int32_t interactionType, stationDirection;
uint8_t stationHeight;
TileElement* tileElement;
rct_viewport* viewport;
Ride* ride;
@ -6207,7 +6208,10 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
ride = get_ride(gRideEntranceExitPlaceRideIndex);
if (ride == nullptr)
{
entranceExitCoords.x = LOCATION_NULL;
return entranceExitCoords;
}
stationHeight = ride->stations[gRideEntranceExitPlaceStationIndex].Height;
@ -6221,16 +6225,20 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
word_F4418C = mapX;
word_F4418E = mapY;
entranceExitCoords = { floor2(mapX, 32), floor2(mapY, 32), entranceExitCoords.z, INVALID_DIRECTION };
entranceExitCoords = { floor2(mapX, 32), floor2(mapY, 32), entranceExitCoords.z, stationHeight };
if (ride->type == RIDE_TYPE_NULL)
{
entranceExitCoords.x = LOCATION_NULL;
return entranceExitCoords;
}
LocationXY8 stationStart = ride->stations[gRideEntranceExitPlaceStationIndex].Start;
if (stationStart.xy == RCT_XY8_UNDEFINED)
{
entranceExitCoords.x = LOCATION_NULL;
return entranceExitCoords;
entranceExitCoords.z = stationHeight;
}
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_3))
{
@ -6353,8 +6361,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(ScreenCoordsX
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))
if (direction != -1 && direction != stationDirection && direction != direction_reverse(stationDirection))
{
entranceExitCoords.direction = direction;
gRideEntranceExitPlaceDirection = entranceExitCoords.direction;

View File

@ -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;