Skip to content

Commit

Permalink
Modify next_x/y/z to become a CoordsXYZ (#10680)
Browse files Browse the repository at this point in the history
* Modify next_x/y/z to become a CoordsXYZ

Should be further scope for refactoring from this.

* Make suggested changes

* Fix default construct issues
  • Loading branch information
duncanspumpkin committed Feb 11, 2020
1 parent 3df79cb commit b8b539c
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 185 deletions.
2 changes: 1 addition & 1 deletion src/openrct2-ui/windows/Guest.cpp
Expand Up @@ -2093,7 +2093,7 @@ void window_guest_debug_paint(rct_window* w, rct_drawpixelinfo* dpi)
}
y += LIST_ROW_HEIGHT;
{
int32_t args[] = { peep->next_x, peep->next_y, peep->next_z };
int32_t args[] = { peep->NextLoc.x, peep->NextLoc.y, peep->NextLoc.z };
format_string(buffer, sizeof(buffer), STR_PEEP_DEBUG_NEXT, args);
if (peep->GetNextIsSurface())
{
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/GameStateSnapshots.cpp
Expand Up @@ -202,9 +202,9 @@ struct GameStateSnapshots : public IGameStateSnapshots

void CompareSpriteDataPeep(const Peep& spriteBase, const Peep& spriteCmp, GameStateSpriteChange_t& changeData) const
{
COMPARE_FIELD(Peep, next_x);
COMPARE_FIELD(Peep, next_y);
COMPARE_FIELD(Peep, next_z);
COMPARE_FIELD(Peep, NextLoc.x);
COMPARE_FIELD(Peep, NextLoc.y);
COMPARE_FIELD(Peep, NextLoc.z);
COMPARE_FIELD(Peep, next_flags);
COMPARE_FIELD(Peep, outside_of_park);
COMPARE_FIELD(Peep, state);
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/StaffHireNewAction.hpp
Expand Up @@ -283,7 +283,7 @@ DEFINE_GAME_ACTION(StaffHireNewAction, GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, Staff
if (guest->state == PEEP_STATE_WALKING)
{
// Check the walking guest's tile. Only count them if they're on a path tile.
guest_tile = map_get_path_element_at({ guest->next_x / 32, guest->next_y / 32, guest->next_z });
guest_tile = map_get_path_element_at(TileCoordsXYZ{ guest->NextLoc });
if (guest_tile != nullptr)
++count;
}
Expand All @@ -297,7 +297,7 @@ DEFINE_GAME_ACTION(StaffHireNewAction, GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, Staff
{
if (guest->state == PEEP_STATE_WALKING)
{
guest_tile = map_get_path_element_at({ guest->next_x / 32, guest->next_y / 32, guest->next_z });
guest_tile = map_get_path_element_at(TileCoordsXYZ{ guest->NextLoc });
if (guest_tile != nullptr)
{
if (rand == 0)
Expand Down
96 changes: 48 additions & 48 deletions src/openrct2/peep/Guest.cpp
Expand Up @@ -957,15 +957,15 @@ void Guest::Tick128UpdateGuest(int32_t index)
{
/* Peep happiness is affected once the peep has been waiting
* too long in a queue. */
TileElement* tileElement = map_get_first_element_at({ next_x, next_y });
TileElement* tileElement = map_get_first_element_at(NextLoc);
bool found = false;
do
{
if (tileElement == nullptr)
break;
if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH)
continue;
if (tileElement->base_height != next_z)
if (tileElement->GetBaseZ() == NextLoc.z)
continue;

// Check if the footpath has a queue line TV monitor on it
Expand Down Expand Up @@ -3385,8 +3385,8 @@ void Guest::UpdateBuying()
window_invalidate_by_number(WC_PEEP, sprite_index);
}
sprite_direction ^= 0x10;
destination_x = next_x + 16;
destination_y = next_y + 16;
destination_x = NextLoc.x + 16;
destination_y = NextLoc.y + 16;
direction = direction_reverse(direction);

SetState(PEEP_STATE_WALKING);
Expand Down Expand Up @@ -5079,8 +5079,8 @@ void Guest::UpdateRideShopInteract()
if (ride == nullptr)
return;

const int16_t tileCenterX = next_x + 16;
const int16_t tileCenterY = next_y + 16;
const int16_t tileCenterX = NextLoc.x + 16;
const int16_t tileCenterY = NextLoc.y + 16;
if (ride->type == RIDE_TYPE_FIRST_AID)
{
if (nausea <= 35)
Expand Down Expand Up @@ -5134,9 +5134,9 @@ void Guest::UpdateRideShopLeave()
{
MoveTo((*loc).x, (*loc).y, z);

if ((x & 0xFFE0) != next_x)
if ((x & 0xFFE0) != NextLoc.x)
return;
if ((y & 0xFFE0) != next_y)
if ((y & 0xFFE0) != NextLoc.y)
return;
}

Expand Down Expand Up @@ -5390,7 +5390,7 @@ void Guest::UpdateWalking()

// Check if vehicle is blocking the destination tile
auto curPos = TileCoordsXYZ(CoordsXYZ{ x, y, z });
auto dstPos = TileCoordsXYZ(CoordsXY{ destination_x, destination_y }, next_z);
auto dstPos = TileCoordsXYZ(CoordsXYZ{ destination_x, destination_y, NextLoc.z });
if (curPos.x != dstPos.x || curPos.y != dstPos.y)
{
if (footpath_is_blocked_by_vehicle(dstPos))
Expand All @@ -5407,7 +5407,7 @@ void Guest::UpdateWalking()

if (GetNextIsSurface())
{
auto surfaceElement = map_get_surface_element_at(CoordsXY{ next_x, next_y });
auto surfaceElement = map_get_surface_element_at(NextLoc);

if (surfaceElement != nullptr)
{
Expand Down Expand Up @@ -5456,15 +5456,15 @@ void Guest::UpdateWalking()
if (GetNextIsSurface() || GetNextIsSloped())
return;

TileElement* tileElement = map_get_first_element_at({ next_x, next_y });
TileElement* tileElement = map_get_first_element_at(NextLoc);
if (tileElement == nullptr)
return;

for (;; tileElement++)
{
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
{
if (next_z == tileElement->base_height)
if (NextLoc.z == tileElement->GetBaseZ())
break;
}
if (tileElement->IsLastForTile())
Expand Down Expand Up @@ -5874,7 +5874,7 @@ void Guest::UpdateUsingBin()
return;
}

TileElement* tileElement = map_get_first_element_at({ next_x, next_y });
TileElement* tileElement = map_get_first_element_at(NextLoc);
if (tileElement == nullptr)
return;

Expand All @@ -5885,7 +5885,7 @@ void Guest::UpdateUsingBin()
continue;
}

if (tileElement->base_height == next_z)
if (tileElement->GetBaseZ() == NextLoc.z)
break;

if (tileElement->IsLastForTile())
Expand Down Expand Up @@ -5997,7 +5997,7 @@ void Guest::UpdateUsingBin()
additionStatus |= space_left_in_bin << selected_bin;
tileElement->AsPath()->SetAdditionStatus(additionStatus);

map_invalidate_tile_zoom0({ next_x, next_y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() });
map_invalidate_tile_zoom0({ NextLoc, tileElement->GetBaseZ(), tileElement->GetClearanceZ() });
StateReset();
break;
}
Expand Down Expand Up @@ -6044,15 +6044,15 @@ bool Guest::UpdateWalkingFindBench()
if (!ShouldFindBench())
return false;

TileElement* tileElement = map_get_first_element_at({ next_x, next_y });
TileElement* tileElement = map_get_first_element_at(NextLoc);
if (tileElement == nullptr)
return false;

for (;; tileElement++)
{
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
{
if (next_z == tileElement->base_height)
if (NextLoc.z == tileElement->GetBaseZ())
break;
}
if (tileElement->IsLastForTile())
Expand Down Expand Up @@ -6141,15 +6141,15 @@ bool Guest::UpdateWalkingFindBin()
if (peep->GetNextIsSurface())
return false;

TileElement* tileElement = map_get_first_element_at({ peep->next_x, peep->next_y });
TileElement* tileElement = map_get_first_element_at(peep->NextLoc);
if (tileElement == nullptr)
return false;

for (;; tileElement++)
{
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
{
if (peep->next_z == tileElement->base_height)
if (peep->NextLoc.z == tileElement->GetBaseZ())
break;
}
if (tileElement->IsLastForTile())
Expand Down Expand Up @@ -6244,15 +6244,15 @@ static void peep_update_walking_break_scenery(Peep* peep)
if (peep->GetNextIsSurface())
return;

TileElement* tileElement = map_get_first_element_at({ peep->next_x, peep->next_y });
TileElement* tileElement = map_get_first_element_at(peep->NextLoc);
if (tileElement == nullptr)
return;

for (;; tileElement++)
{
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
{
if (peep->next_z == tileElement->base_height)
if (peep->NextLoc.z == tileElement->GetBaseZ())
break;
}
if (tileElement->IsLastForTile())
Expand Down Expand Up @@ -6314,7 +6314,7 @@ static void peep_update_walking_break_scenery(Peep* peep)

tileElement->AsPath()->SetIsBroken(true);

map_invalidate_tile_zoom1({ peep->next_x, peep->next_y, tileElement->GetBaseZ(), tileElement->GetBaseZ() + 32 });
map_invalidate_tile_zoom1({ peep->NextLoc, tileElement->GetBaseZ(), tileElement->GetBaseZ() + 32 });

peep->angriness = 16;
}
Expand Down Expand Up @@ -6390,7 +6390,7 @@ bool loc_690FD0(Peep* peep, uint8_t* rideToView, uint8_t* rideSeatToView, TileEl
*rideSeatToView = 1;
if (ride->status != RIDE_STATUS_OPEN)
{
if (tileElement->clearance_height > peep->next_z + 8)
if (tileElement->GetClearanceZ() > peep->NextLoc.z + (8 * COORDS_Z_STEP))
{
*rideSeatToView |= (1 << 1);
}
Expand All @@ -6403,7 +6403,7 @@ bool loc_690FD0(Peep* peep, uint8_t* rideToView, uint8_t* rideSeatToView, TileEl
*rideSeatToView = 0;
if (ride->status == RIDE_STATUS_OPEN && !(ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN))
{
if (tileElement->clearance_height > peep->next_z + 8)
if (tileElement->GetClearanceZ() > peep->NextLoc.z + (8 * COORDS_Z_STEP))
{
*rideSeatToView = 0x02;
}
Expand All @@ -6429,7 +6429,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
{
TileElement* tileElement;

auto surfaceElement = map_get_surface_element_at(CoordsXY{ peep->next_x, peep->next_y });
auto surfaceElement = map_get_surface_element_at(peep->NextLoc);

tileElement = reinterpret_cast<TileElement*>(surfaceElement);
if (tileElement == nullptr)
Expand All @@ -6453,16 +6453,16 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
auto wallEntry = tileElement->AsWall()->GetEntry();
if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE))
continue;
if (peep->next_z + 4 <= tileElement->base_height)
if (peep->NextLoc.z + (4 * COORDS_Z_STEP) <= tileElement->GetBaseZ())
continue;
if (peep->next_z + 1 >= tileElement->clearance_height)
if (peep->NextLoc.z + (1 * COORDS_Z_STEP) >= tileElement->GetClearanceZ())
continue;

return false;
} while (!(tileElement++)->IsLastForTile());

uint16_t x = peep->next_x + CoordsDirectionDelta[edge].x;
uint16_t y = peep->next_y + CoordsDirectionDelta[edge].y;
uint16_t x = peep->NextLoc.x + CoordsDirectionDelta[edge].x;
uint16_t y = peep->NextLoc.y + CoordsDirectionDelta[edge].y;
if (x > 255 * 32 || y > 255 * 32)
{
return false;
Expand Down Expand Up @@ -6493,9 +6493,9 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE))
continue;
// TODO: Check whether this shouldn't be <=, as the other loops use. If so, also extract as loop A.
if (peep->next_z + 4 >= tileElement->base_height)
if (peep->NextLoc.z + (4 * COORDS_Z_STEP) >= tileElement->GetBaseZ())
continue;
if (peep->next_z + 1 >= tileElement->clearance_height)
if (peep->NextLoc.z + (1 * COORDS_Z_STEP) >= tileElement->GetClearanceZ())
continue;

return false;
Expand All @@ -6513,9 +6513,9 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
continue;
}

if (tileElement->clearance_height + 1 < peep->next_z)
if (tileElement->GetClearanceZ() + (1 * COORDS_Z_STEP) < peep->NextLoc.z)
continue;
if (peep->next_z + 6 < tileElement->base_height)
if (peep->NextLoc.z + (6 * COORDS_Z_STEP) < tileElement->GetBaseZ())
continue;

if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK)
Expand All @@ -6534,7 +6534,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
}

*rideSeatToView = 0;
if (tileElement->clearance_height >= peep->next_z + 8)
if (tileElement->GetClearanceZ() >= peep->NextLoc.z + (8 * COORDS_Z_STEP))
{
*rideSeatToView = 0x02;
}
Expand All @@ -6556,9 +6556,9 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
if (tileElement->IsGhost())
continue;
}
if (tileElement->clearance_height + 1 < peep->next_z)
if (tileElement->GetClearanceZ() + (1 * COORDS_Z_STEP) < peep->NextLoc.z)
continue;
if (peep->next_z + 6 < tileElement->base_height)
if (peep->NextLoc.z + (6 * COORDS_Z_STEP) < tileElement->GetBaseZ())
continue;
if (tileElement->GetType() == TILE_ELEMENT_TYPE_SURFACE)
continue;
Expand Down Expand Up @@ -6610,9 +6610,9 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
auto wallEntry = tileElement->AsWall()->GetEntry();
if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE))
continue;
if (peep->next_z + 6 <= tileElement->base_height)
if (peep->NextLoc.z + (6 * COORDS_Z_STEP) <= tileElement->GetBaseZ())
continue;
if (peep->next_z >= tileElement->clearance_height)
if (peep->NextLoc.z >= tileElement->GetClearanceZ())
continue;

return false;
Expand All @@ -6629,9 +6629,9 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
if (tileElement->IsGhost())
continue;
}
if (tileElement->clearance_height + 1 < peep->next_z)
if (tileElement->GetClearanceZ() + (1 * COORDS_Z_STEP) < peep->NextLoc.z)
continue;
if (peep->next_z + 8 < tileElement->base_height)
if (peep->NextLoc.z + (8 * COORDS_Z_STEP) < tileElement->GetBaseZ())
continue;

if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK)
Expand All @@ -6651,7 +6651,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
}

*rideSeatToView = 0;
if (tileElement->clearance_height >= peep->next_z + 8)
if (tileElement->GetClearanceZ() >= peep->NextLoc.z + (8 * COORDS_Z_STEP))
{
*rideSeatToView = 0x02;
}
Expand All @@ -6673,9 +6673,9 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
if (tileElement->IsGhost())
continue;
}
if (tileElement->clearance_height + 1 < peep->next_z)
if (tileElement->GetClearanceZ() + (1 * COORDS_Z_STEP) < peep->NextLoc.z)
continue;
if (peep->next_z + 8 < tileElement->base_height)
if (peep->NextLoc.z + (8 * COORDS_Z_STEP) < tileElement->GetBaseZ())
continue;
if (tileElement->GetType() == TILE_ELEMENT_TYPE_SURFACE)
continue;
Expand Down Expand Up @@ -6726,9 +6726,9 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
auto wallEntry = tileElement->AsWall()->GetEntry();
if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE))
continue;
if (peep->next_z + 8 <= tileElement->base_height)
if (peep->NextLoc.z + (8 * COORDS_Z_STEP) <= tileElement->GetBaseZ())
continue;
if (peep->next_z >= tileElement->clearance_height)
if (peep->NextLoc.z >= tileElement->GetClearanceZ())
continue;

return false;
Expand All @@ -6745,9 +6745,9 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
if (tileElement->IsGhost())
continue;
}
if (tileElement->clearance_height + 1 < peep->next_z)
if (tileElement->GetClearanceZ() + (1 * COORDS_Z_STEP) < peep->NextLoc.z)
continue;
if (peep->next_z + 10 < tileElement->base_height)
if (peep->NextLoc.z + (10 * COORDS_Z_STEP) < tileElement->GetBaseZ())
continue;

if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK)
Expand All @@ -6766,7 +6766,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV
}

*rideSeatToView = 0;
if (tileElement->clearance_height >= peep->next_z + 8)
if (tileElement->GetClearanceZ() >= peep->NextLoc.z + (8 * COORDS_Z_STEP))
{
*rideSeatToView = 0x02;
}
Expand Down

0 comments on commit b8b539c

Please sign in to comment.