Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue#8725: refactoring _currentTrackBegin and _previousTrackPiece in Ride.cpp to use CoordsXYZ struct #8759

Merged
merged 6 commits into from Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/openrct2-ui/windows/MazeConstruction.cpp
Expand Up @@ -482,9 +482,9 @@ static void window_maze_construction_construct(int32_t direction)

ride_construction_invalidate_current_track();

x = _currentTrackBeginX + (CoordsDirectionDelta[direction].x / 2);
y = _currentTrackBeginY + (CoordsDirectionDelta[direction].y / 2);
z = _currentTrackBeginZ;
x = _currentTrackBegin.x + (CoordsDirectionDelta[direction].x / 2);
y = _currentTrackBegin.y + (CoordsDirectionDelta[direction].y / 2);
z = _currentTrackBegin.z;
switch (_rideConstructionState)
{
case RIDE_CONSTRUCTION_STATE_MAZE_BUILD:
Expand All @@ -508,8 +508,8 @@ static void window_maze_construction_construct(int32_t direction)
return;
}

_currentTrackBeginX = x;
_currentTrackBeginY = y;
_currentTrackBegin.x = x;
_currentTrackBegin.y = y;
if (_rideConstructionState != RIDE_CONSTRUCTION_STATE_MAZE_MOVE)
{
audio_play_sound_at_location(SOUND_PLACE_ITEM, x, y, z);
Expand Down
142 changes: 71 additions & 71 deletions src/openrct2-ui/windows/RideConstruction.cpp
Expand Up @@ -289,7 +289,7 @@ static constexpr const rct_string_id RideConfigurationStringIds[] = {
STR_HELIX_DOWN_LEFT, // 108
STR_HELIX_DOWN_RIGHT, // 109
STR_BASE_SIZE_2_X_2, // 110
STR_BASE_SIZE_4_X_4, // 111
STR_BASE_SIZE_4_X_4, // ****111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure what this change has been made for. Please revert.

STR_WATERFALLS, // 112
STR_RAPIDS, // 113
STR_ON_RIDE_PHOTO_SECTION, // 114
Expand Down Expand Up @@ -1680,9 +1680,9 @@ static void RideConstructPlacedForwardGameActionCallback(const GameAction* ga, c
if (ride != nullptr)
{
int32_t trackDirection = _currentTrackPieceDirection;
int32_t x = _currentTrackBeginX;
int32_t y = _currentTrackBeginY;
int32_t z = _currentTrackBeginZ;
int32_t x = _currentTrackBegin.x;
int32_t y = _currentTrackBegin.y;
int32_t z = _currentTrackBegin.z;
if (!(trackDirection & 4))
{
x -= CoordsDirectionDelta[trackDirection].x;
Expand All @@ -1692,9 +1692,9 @@ static void RideConstructPlacedForwardGameActionCallback(const GameAction* ga, c
CoordsXYE next_track;
if (track_block_get_next_from_zero(x, y, z, ride, trackDirection, &next_track, &z, &trackDirection, false))
{
_currentTrackBeginX = next_track.x;
_currentTrackBeginY = next_track.y;
_currentTrackBeginZ = z;
_currentTrackBegin.x = next_track.x;
_currentTrackBegin.y = next_track.y;
_currentTrackBegin.z = z;
_currentTrackPieceDirection = next_track.element->GetDirection();
_currentTrackPieceType = next_track.element->AsTrack()->GetTrackType();
_currentTrackSelectionFlags = 0;
Expand Down Expand Up @@ -1727,9 +1727,9 @@ static void RideConstructPlacedBackwardGameActionCallback(const GameAction* ga,
if (ride != nullptr)
{
auto trackDirection = direction_reverse(_currentTrackPieceDirection);
auto x = _currentTrackBeginX;
auto y = _currentTrackBeginY;
auto z = _currentTrackBeginZ;
auto x = _currentTrackBegin.x;
auto y = _currentTrackBegin.y;
auto z = _currentTrackBegin.z;
if (!(trackDirection & 4))
{
x += CoordsDirectionDelta[trackDirection].x;
Expand All @@ -1739,9 +1739,9 @@ static void RideConstructPlacedBackwardGameActionCallback(const GameAction* ga,
track_begin_end trackBeginEnd;
if (track_block_get_previous_from_zero(x, y, z, ride, trackDirection, &trackBeginEnd))
{
_currentTrackBeginX = trackBeginEnd.begin_x;
_currentTrackBeginY = trackBeginEnd.begin_y;
_currentTrackBeginZ = trackBeginEnd.begin_z;
_currentTrackBegin.x = trackBeginEnd.begin_x;
_currentTrackBegin.y = trackBeginEnd.begin_y;
_currentTrackBegin.z = trackBeginEnd.begin_z;
_currentTrackPieceDirection = trackBeginEnd.begin_direction;
_currentTrackPieceType = trackBeginEnd.begin_element->AsTrack()->GetTrackType();
_currentTrackSelectionFlags = 0;
Expand Down Expand Up @@ -1859,9 +1859,9 @@ static void window_ride_construction_mouseup_demolish(rct_window* w)
}

// Invalidate the selected track element or make sure it's at origin???
x = _currentTrackBeginX;
y = _currentTrackBeginY;
z = _currentTrackBeginZ;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
z = _currentTrackBegin.z;
direction = _currentTrackPieceDirection;
type = _currentTrackPieceType;
if (sub_6C683D(&x, &y, &z, direction & 3, type, 0, &tileElement, 0))
Expand Down Expand Up @@ -1893,9 +1893,9 @@ static void window_ride_construction_mouseup_demolish(rct_window* w)
}
else
{
x = _currentTrackBeginX;
y = _currentTrackBeginY;
z = _currentTrackBeginZ;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
z = _currentTrackBegin.z;
direction = _currentTrackPieceDirection;
type = _currentTrackPieceType;

Expand All @@ -1913,7 +1913,7 @@ static void window_ride_construction_mouseup_demolish(rct_window* w)

auto trackRemoveAction = TrackRemoveAction(
_currentTrackPieceType, 0,
{ _currentTrackBeginX, _currentTrackBeginY, _currentTrackBeginZ, _currentTrackPieceDirection });
{ _currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z, _currentTrackPieceDirection });

trackRemoveAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
_stationConstructed = get_ride(w->number)->num_stations != 0;
Expand Down Expand Up @@ -2506,9 +2506,9 @@ void window_ride_construction_update_active_elements_impl()
_selectedTrackType = 255;
if (_rideConstructionState == RIDE_CONSTRUCTION_STATE_SELECTED)
{
int32_t x = _currentTrackBeginX;
int32_t y = _currentTrackBeginY;
int32_t z = _currentTrackBeginZ;
int32_t x = _currentTrackBegin.x;
int32_t y = _currentTrackBegin.y;
int32_t z = _currentTrackBegin.z;
if (!sub_6C683D(&x, &y, &z, _currentTrackPieceDirection & 3, _currentTrackPieceType, 0, &tileElement, 0))
{
_selectedTrackType = tileElement->AsTrack()->GetTrackType();
Expand Down Expand Up @@ -2599,9 +2599,9 @@ void sub_6C94D8()

_rideConstructionArrowPulseTime = 5;
_currentTrackSelectionFlags ^= TRACK_SELECTION_FLAG_ARROW;
x = _currentTrackBeginX;
y = _currentTrackBeginY;
z = _currentTrackBeginZ;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
z = _currentTrackBegin.z;
direction = _currentTrackPieceDirection;
type = _currentTrackPieceType;
gMapSelectArrowPosition.x = x;
Expand All @@ -2624,9 +2624,9 @@ void sub_6C94D8()

_rideConstructionArrowPulseTime = 5;
_currentTrackSelectionFlags ^= TRACK_SELECTION_FLAG_ARROW;
x = _currentTrackBeginX;
y = _currentTrackBeginY;
z = _currentTrackBeginZ;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
z = _currentTrackBegin.z;
direction = _currentTrackPieceDirection & 3;
type = _currentTrackPieceType;
if (sub_6C683D(
Expand All @@ -2645,20 +2645,20 @@ void sub_6C94D8()

_rideConstructionArrowPulseTime = 5;
_currentTrackSelectionFlags ^= TRACK_SELECTION_FLAG_ARROW;
x = _currentTrackBeginX & 0xFFE0;
y = _currentTrackBeginY & 0xFFE0;
z = _currentTrackBeginZ + 15;
x = _currentTrackBegin.x & 0xFFE0;
y = _currentTrackBegin.y & 0xFFE0;
z = _currentTrackBegin.z + 15;
gMapSelectArrowPosition.x = x;
gMapSelectArrowPosition.y = y;
gMapSelectArrowPosition.z = z;
gMapSelectArrowDirection = 4;
if (((_currentTrackBeginX & 0x1F) | (_currentTrackBeginY & 0x1F)) != 0)
if (((_currentTrackBegin.x & 0x1F) | (_currentTrackBegin.y & 0x1F)) != 0)
{
gMapSelectArrowDirection = 6;
if (((_currentTrackBeginX & 0x1F) & (_currentTrackBeginY & 0x1F)) == 0)
if (((_currentTrackBegin.x & 0x1F) & (_currentTrackBegin.y & 0x1F)) == 0)
{
gMapSelectArrowDirection = 5;
if ((_currentTrackBeginY & 0x1F) == 0)
if ((_currentTrackBegin.y & 0x1F) == 0)
gMapSelectArrowDirection = 7;
}
}
Expand Down Expand Up @@ -2688,22 +2688,22 @@ static void window_ride_construction_update_map_selection()
case RIDE_CONSTRUCTION_STATE_0:
trackDirection = _currentTrackPieceDirection;
trackType = 0;
x = _currentTrackBeginX;
y = _currentTrackBeginY;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
break;
case RIDE_CONSTRUCTION_STATE_SELECTED:
trackDirection = _currentTrackPieceDirection;
trackType = _currentTrackPieceType;
x = _currentTrackBeginX;
y = _currentTrackBeginY;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
break;
default:
if (window_ride_construction_update_state(&trackType, &trackDirection, nullptr, nullptr, &x, &y, nullptr, nullptr))
{
trackDirection = _currentTrackPieceDirection;
trackType = 0;
x = _currentTrackBeginX;
y = _currentTrackBeginY;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
}
break;
}
Expand Down Expand Up @@ -3431,9 +3431,9 @@ static void window_ride_construction_show_special_track_dropdown(rct_window* w,
static void ride_selected_track_set_seat_rotation(int32_t seatRotation)
{
int32_t x, y, z;
x = _currentTrackBeginX;
y = _currentTrackBeginY;
z = _currentTrackBeginZ;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
z = _currentTrackBegin.z;
sub_6C683D(&x, &y, &z, _currentTrackPieceDirection & 3, _currentTrackPieceType, seatRotation, nullptr, (1 << 5));
window_ride_construction_update_active_elements();
}
Expand Down Expand Up @@ -3465,14 +3465,14 @@ static void ride_construction_set_brakes_speed(int32_t brakesSpeed)
TileElement* tileElement;
int32_t x, y, z;

x = _currentTrackBeginX;
y = _currentTrackBeginY;
z = _currentTrackBeginZ;
x = _currentTrackBegin.x;
y = _currentTrackBegin.y;
z = _currentTrackBegin.z;
if (!sub_6C683D(&x, &y, &z, _currentTrackPieceDirection & 3, _currentTrackPieceType, 0, &tileElement, 0))
{
game_do_command(
_currentTrackBeginX, GAME_COMMAND_FLAG_APPLY | ((brakesSpeed) << 8), _currentTrackBeginY,
tileElement->AsTrack()->GetTrackType(), GAME_COMMAND_SET_BRAKES_SPEED, _currentTrackBeginZ, 0);
_currentTrackBegin.x, GAME_COMMAND_FLAG_APPLY | ((brakesSpeed) << 8), _currentTrackBegin.y,
tileElement->AsTrack()->GetTrackType(), GAME_COMMAND_SET_BRAKES_SPEED, _currentTrackBegin.z, 0);
}
window_ride_construction_update_active_elements();
}
Expand Down Expand Up @@ -3565,19 +3565,19 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY)

gMapSelectArrowPosition.z = z;
bx = 41;
_currentTrackBeginX = x;
_currentTrackBeginY = y;
_currentTrackBeginZ = z;
if ((_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_TRACK) && x == _previousTrackPieceX && y == _previousTrackPieceY
&& z == _previousTrackPieceZ)
_currentTrackBegin.x = x;
_currentTrackBegin.y = y;
_currentTrackBegin.z = z;
if ((_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_TRACK) && x == _previousTrackPiece.x && y == _previousTrackPiece.y
&& z == _previousTrackPiece.z)
{
map_invalidate_map_selection_tiles();
return;
}

_previousTrackPieceX = x;
_previousTrackPieceY = y;
_previousTrackPieceZ = z;
_previousTrackPiece.x = x;
_previousTrackPiece.y = y;
_previousTrackPiece.z = z;
if (ride->type == RIDE_TYPE_MAZE)
{
for (;;)
Expand All @@ -3593,12 +3593,12 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY)
if (bx == 0)
break;

_currentTrackBeginZ -= 8;
if (_currentTrackBeginZ & LOCATION_NULL)
_currentTrackBegin.z -= 8;
if (_currentTrackBegin.z & LOCATION_NULL)
break;

if (bx >= 0)
_currentTrackBeginZ += 16;
_currentTrackBegin.z += 16;
}

auto intent = Intent(INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION);
Expand All @@ -3620,12 +3620,12 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY)
if (bx == 0)
break;

_currentTrackBeginZ -= 8;
if (_currentTrackBeginZ & LOCATION_NULL)
_currentTrackBegin.z -= 8;
if (_currentTrackBegin.z & LOCATION_NULL)
break;

if (bx >= 0)
_currentTrackBeginZ += 16;
_currentTrackBegin.z += 16;
}

if (_autoRotatingShop && _rideConstructionState == RIDE_CONSTRUCTION_STATE_PLACE
Expand Down Expand Up @@ -3817,9 +3817,9 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)
for (int32_t zAttempts = 41; zAttempts >= 0; zAttempts--)
{
_rideConstructionState = RIDE_CONSTRUCTION_STATE_MAZE_BUILD;
_currentTrackBeginX = x;
_currentTrackBeginY = y;
_currentTrackBeginZ = z;
_currentTrackBegin.x = x;
_currentTrackBegin.y = y;
_currentTrackBegin.z = z;
_currentTrackSelectionFlags = 0;
_rideConstructionArrowPulseTime = 0;
auto intent = Intent(INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION);
Expand All @@ -3831,7 +3831,7 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)
gDisableErrorWindowSound = true;

_trackPlaceCost = maze_set_track(
_currentTrackBeginX, _currentTrackBeginY, _currentTrackBeginZ, GAME_COMMAND_FLAG_APPLY, true, 0,
_currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z, GAME_COMMAND_FLAG_APPLY, true, 0,
_currentRideIndex, GC_SET_MAZE_TRACK_BUILD);

gDisableErrorWindowSound = false;
Expand Down Expand Up @@ -3867,7 +3867,7 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)
else
{
window_close_by_class(WC_ERROR);
audio_play_sound_at_location(SOUND_PLACE_ITEM, _currentTrackBeginX, _currentTrackBeginY, _currentTrackBeginZ);
audio_play_sound_at_location(SOUND_PLACE_ITEM, _currentTrackBegin.x, _currentTrackBegin.y, _currentTrackBegin.z);
break;
}
}
Expand All @@ -3877,9 +3877,9 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)
for (int32_t zAttempts = 41; zAttempts >= 0; zAttempts--)
{
_rideConstructionState = RIDE_CONSTRUCTION_STATE_FRONT;
_currentTrackBeginX = x;
_currentTrackBeginY = y;
_currentTrackBeginZ = z;
_currentTrackBegin.x = x;
_currentTrackBegin.y = y;
_currentTrackBegin.z = z;
_currentTrackSelectionFlags = 0;
_rideConstructionArrowPulseTime = 0;
window_ride_construction_update_active_elements();
Expand Down