1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Use CoordsXYRangedZ on fence_in_the_way()

This commit is contained in:
Tulio Leao
2020-01-04 08:01:35 -03:00
parent 78611b664f
commit b829b22415
5 changed files with 41 additions and 35 deletions

View File

@@ -137,20 +137,19 @@ static int32_t peep_move_one_tile(Direction direction, Peep* peep)
*/
static int32_t guest_surface_path_finding(Peep* peep)
{
int16_t x = peep->next_x;
int16_t y = peep->next_y;
int16_t z = peep->next_z;
auto pathPos = CoordsXYRangedZ{ peep->next_x, peep->next_y, peep->next_z * COORDS_Z_STEP,
(peep->next_z * COORDS_Z_STEP) + PATH_HEIGHT };
Direction randDirection = scenario_rand() & 3;
if (!fence_in_the_way(x, y, z, z + 4, randDirection))
if (!fence_in_the_way(pathPos, randDirection))
{
x += CoordsDirectionDelta[randDirection].x;
y += CoordsDirectionDelta[randDirection].y;
pathPos.x += CoordsDirectionDelta[randDirection].x;
pathPos.y += CoordsDirectionDelta[randDirection].y;
Direction backwardsDirection = direction_reverse(randDirection);
if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection))
if (!fence_in_the_way(pathPos, backwardsDirection))
{
if (!map_surface_is_blocked({ x, y }))
if (!map_surface_is_blocked(pathPos))
{
return peep_move_one_tile(randDirection, peep);
}
@@ -165,17 +164,17 @@ static int32_t guest_surface_path_finding(Peep* peep)
}
randDirection &= 3;
x = peep->next_x;
y = peep->next_y;
if (!fence_in_the_way(x, y, z, z + 4, randDirection))
pathPos.x = peep->next_x;
pathPos.y = peep->next_y;
if (!fence_in_the_way(pathPos, randDirection))
{
x += CoordsDirectionDelta[randDirection].x;
y += CoordsDirectionDelta[randDirection].y;
pathPos.x += CoordsDirectionDelta[randDirection].x;
pathPos.y += CoordsDirectionDelta[randDirection].y;
Direction backwardsDirection = direction_reverse(randDirection);
if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection))
if (!fence_in_the_way(pathPos, backwardsDirection))
{
if (!map_surface_is_blocked({ x, y }))
if (!map_surface_is_blocked(pathPos))
{
return peep_move_one_tile(randDirection, peep);
}
@@ -185,17 +184,17 @@ static int32_t guest_surface_path_finding(Peep* peep)
randDirection -= 2;
randDirection &= 3;
x = peep->next_x;
y = peep->next_y;
if (!fence_in_the_way(x, y, z, z + 4, randDirection))
pathPos.x = peep->next_x;
pathPos.y = peep->next_y;
if (!fence_in_the_way(pathPos, randDirection))
{
x += CoordsDirectionDelta[randDirection].x;
y += CoordsDirectionDelta[randDirection].y;
pathPos.x += CoordsDirectionDelta[randDirection].x;
pathPos.y += CoordsDirectionDelta[randDirection].y;
Direction backwardsDirection = direction_reverse(randDirection);
if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection))
if (!fence_in_the_way(pathPos, backwardsDirection))
{
if (!map_surface_is_blocked({ x, y }))
if (!map_surface_is_blocked(pathPos))
{
return peep_move_one_tile(randDirection, peep);
}

View File

@@ -42,6 +42,8 @@
#define PEEP_MAX_NAUSEA 255
#define PEEP_MAX_THIRST 255
constexpr auto PEEP_CLEARANCE_HEIGHT = 4 * COORDS_Z_STEP;
struct TileElement;
struct Ride;

View File

@@ -727,10 +727,16 @@ static uint8_t staff_direction_surface(Peep* peep, uint8_t initialDirection)
direction &= 3;
if (fence_in_the_way(peep->next_x, peep->next_y, peep->next_z, peep->next_z + 4, direction))
if (fence_in_the_way(
{ peep->next_x, peep->next_y, peep->next_z * COORDS_Z_STEP,
(peep->next_z * COORDS_Z_STEP) + PEEP_CLEARANCE_HEIGHT },
direction))
continue;
if (fence_in_the_way(peep->next_x, peep->next_y, peep->next_z, peep->next_z + 4, direction_reverse(direction)))
if (fence_in_the_way(
{ peep->next_x, peep->next_y, peep->next_z * COORDS_Z_STEP,
(peep->next_z * COORDS_Z_STEP) + PEEP_CLEARANCE_HEIGHT },
direction_reverse(direction)))
continue;
CoordsXY chosenTile = { peep->next_x + CoordsDirectionDelta[direction].x,

View File

@@ -454,11 +454,11 @@ void footpath_interrupt_peeps(int32_t x, int32_t y, int32_t z)
*
* rct2: 0x006E59DC
*/
bool fence_in_the_way(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction)
bool fence_in_the_way(const CoordsXYRangedZ& fencePos, int32_t direction)
{
TileElement* tileElement;
tileElement = map_get_first_element_at({ x, y });
tileElement = map_get_first_element_at(fencePos);
if (tileElement == nullptr)
return false;
do
@@ -467,9 +467,9 @@ bool fence_in_the_way(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t dire
continue;
if (tileElement->IsGhost())
continue;
if (z0 >= tileElement->clearance_height)
if (fencePos.baseZ >= tileElement->GetClearanceZ())
continue;
if (z1 <= tileElement->base_height)
if (fencePos.clearanceZ <= tileElement->GetBaseZ())
continue;
if ((tileElement->GetDirection()) != direction)
continue;
@@ -710,10 +710,10 @@ static bool footpath_reconnect_queue_to_path(int32_t x, int32_t y, TileElement*
if (action < 0)
{
if (fence_in_the_way(x, y, tileElement->base_height, tileElement->clearance_height, direction))
if (fence_in_the_way({ x, y, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction))
return false;
if (fence_in_the_way(x1, y1, tileElement->base_height, tileElement->clearance_height, direction_reverse(direction)))
if (fence_in_the_way({ x1, y1, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction_reverse(direction)))
return false;
}
@@ -876,8 +876,7 @@ static void loc_6A6D7E(
if (query)
{
if (fence_in_the_way(
targetPos.x, targetPos.y, tileElement->base_height, tileElement->clearance_height,
direction_reverse(direction)))
{ targetPos, tileElement->GetBaseZ(), tileElement->GetClearanceZ() }, direction_reverse(direction)))
{
return;
}
@@ -941,8 +940,7 @@ static void loc_6A6C85(
{
if (query
&& fence_in_the_way(
tileElementPos.x, tileElementPos.y, tileElementPos.element->base_height, tileElementPos.element->clearance_height,
direction))
{ tileElementPos, tileElementPos.element->GetBaseZ(), tileElementPos.element->GetClearanceZ() }, direction))
return;
if (tileElementPos.element->GetType() == TILE_ELEMENT_TYPE_ENTRANCE)

View File

@@ -24,6 +24,7 @@ enum
constexpr auto FootpathMaxHeight = 248;
constexpr auto FootpathMinHeight = 2;
constexpr auto PATH_HEIGHT_STEP = 2 * COORDS_Z_STEP;
constexpr auto PATH_HEIGHT = 4 * COORDS_Z_STEP;
#define FOOTPATH_ELEMENT_INSERT_QUEUE 0x80
@@ -189,7 +190,7 @@ void footpath_bridge_get_info_from_pos(
void footpath_remove_litter(int32_t x, int32_t y, int32_t z);
void footpath_connect_edges(const CoordsXY& footpathPos, TileElement* tileElement, int32_t flags);
void footpath_update_queue_chains();
bool fence_in_the_way(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t direction);
bool fence_in_the_way(const CoordsXYRangedZ& fencePos, int32_t direction);
void footpath_chain_ride_queue(
ride_id_t rideIndex, int32_t entranceIndex, int32_t x, int32_t y, TileElement* tileElement, int32_t direction);
void footpath_update_path_wide_flags(int32_t x, int32_t y);