mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-17 12:03:07 +01:00
Merge pull request #12030 from tupaschoal/more-coords-stuff
Small CoordsXY* Refactor
This commit is contained in:
@@ -50,7 +50,7 @@ void Painter::Paint(IDrawingEngine& de)
|
||||
|
||||
if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !title_should_hide_version_info())
|
||||
{
|
||||
DrawOpenRCT2(dpi, 0, _uiContext->GetHeight() - 20);
|
||||
DrawOpenRCT2(dpi, { 0, _uiContext->GetHeight() - 20 });
|
||||
}
|
||||
|
||||
gfx_draw_pickedup_peep(dpi);
|
||||
|
||||
@@ -602,8 +602,7 @@ static void peep_pathfind_heuristic_search(
|
||||
uint8_t searchResult = PATH_SEARCH_FAILED;
|
||||
|
||||
bool currentElementIsWide
|
||||
= (currentTileElement->AsPath()->IsWide()
|
||||
&& !staff_can_ignore_wide_flag(peep, loc.x * 32, loc.y * 32, loc.z, currentTileElement));
|
||||
= (currentTileElement->AsPath()->IsWide() && !staff_can_ignore_wide_flag(peep, loc.ToCoordsXYZ(), currentTileElement));
|
||||
|
||||
loc += TileDirectionDelta[test_edge];
|
||||
|
||||
@@ -737,7 +736,7 @@ static void peep_pathfind_heuristic_search(
|
||||
if (tileElement->AsPath()->IsWide())
|
||||
{
|
||||
/* Check if staff can ignore this wide flag. */
|
||||
if (!staff_can_ignore_wide_flag(peep, loc.x * 32, loc.y * 32, loc.z, tileElement))
|
||||
if (!staff_can_ignore_wide_flag(peep, loc.ToCoordsXYZ(), tileElement))
|
||||
{
|
||||
searchResult = PATH_SEARCH_WIDE;
|
||||
found = true;
|
||||
|
||||
@@ -187,7 +187,7 @@ bool Staff::IsLocationInPatrol(const CoordsXY& loc) const
|
||||
return IsPatrolAreaSet(loc);
|
||||
}
|
||||
|
||||
bool staff_is_location_on_patrol_edge(Peep* mechanic, int32_t x, int32_t y)
|
||||
bool staff_is_location_on_patrol_edge(Peep* mechanic, const CoordsXY& loc)
|
||||
{
|
||||
// Check whether the location x,y is inside and on the edge of the
|
||||
// patrol zone for mechanic.
|
||||
@@ -195,15 +195,14 @@ bool staff_is_location_on_patrol_edge(Peep* mechanic, int32_t x, int32_t y)
|
||||
int32_t neighbourDir = 0;
|
||||
while (!onZoneEdge && neighbourDir <= 7)
|
||||
{
|
||||
int32_t neighbourX = x + CoordsDirectionDelta[neighbourDir].x;
|
||||
int32_t neighbourY = y + CoordsDirectionDelta[neighbourDir].y;
|
||||
onZoneEdge = !mechanic->AsStaff()->IsLocationInPatrol({ neighbourX, neighbourY });
|
||||
auto neighbourPos = loc + CoordsDirectionDelta[neighbourDir];
|
||||
onZoneEdge = !mechanic->AsStaff()->IsLocationInPatrol(neighbourPos);
|
||||
neighbourDir++;
|
||||
}
|
||||
return onZoneEdge;
|
||||
}
|
||||
|
||||
bool staff_can_ignore_wide_flag(Peep* staff, int32_t x, int32_t y, uint8_t z, TileElement* path)
|
||||
bool staff_can_ignore_wide_flag(Peep* staff, const CoordsXYZ& staffPos, TileElement* path)
|
||||
{
|
||||
/* Wide flags can potentially wall off parts of a staff patrol zone
|
||||
* for the heuristic search.
|
||||
@@ -229,7 +228,7 @@ bool staff_can_ignore_wide_flag(Peep* staff, int32_t x, int32_t y, uint8_t z, Ti
|
||||
if (staff->AssignedPeepType != PEEP_TYPE_STAFF)
|
||||
return false;
|
||||
|
||||
if (!staff_is_location_on_patrol_edge(staff, x, y))
|
||||
if (!staff_is_location_on_patrol_edge(staff, staffPos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -241,16 +240,14 @@ bool staff_can_ignore_wide_flag(Peep* staff, int32_t x, int32_t y, uint8_t z, Ti
|
||||
uint8_t widecount = 0;
|
||||
for (Direction adjac_dir : ALL_DIRECTIONS)
|
||||
{
|
||||
int32_t adjac_x = x + CoordsDirectionDelta[adjac_dir].x;
|
||||
int32_t adjac_y = y + CoordsDirectionDelta[adjac_dir].y;
|
||||
uint8_t adjac_z = z;
|
||||
auto adjacPos = staffPos + CoordsXYZ{ CoordsDirectionDelta[adjac_dir].x, CoordsDirectionDelta[adjac_dir].y, 0 };
|
||||
|
||||
/* Ignore adjacent tiles outside the patrol zone. */
|
||||
if (!staff->AsStaff()->IsLocationInPatrol({ adjac_x, adjac_y }))
|
||||
if (!staff->AsStaff()->IsLocationInPatrol(adjacPos))
|
||||
continue;
|
||||
|
||||
/* Ignore adjacent tiles on the patrol zone edge. */
|
||||
if (staff_is_location_on_patrol_edge(staff, adjac_x, adjac_y))
|
||||
if (staff_is_location_on_patrol_edge(staff, adjacPos))
|
||||
continue;
|
||||
|
||||
/* Adjacent tile is inside the patrol zone but not on the
|
||||
@@ -267,12 +264,12 @@ bool staff_can_ignore_wide_flag(Peep* staff, int32_t x, int32_t y, uint8_t z, Ti
|
||||
{
|
||||
if (path->AsPath()->GetSlopeDirection() == adjac_dir)
|
||||
{
|
||||
adjac_z = z + 2;
|
||||
adjacPos.z += PATH_HEIGHT_STEP;
|
||||
}
|
||||
}
|
||||
|
||||
/* Search through all adjacent map elements */
|
||||
TileElement* test_element = map_get_first_element_at({ adjac_x, adjac_y });
|
||||
TileElement* test_element = map_get_first_element_at(adjacPos);
|
||||
if (test_element == nullptr)
|
||||
return false;
|
||||
bool pathfound = false;
|
||||
@@ -285,7 +282,7 @@ bool staff_can_ignore_wide_flag(Peep* staff, int32_t x, int32_t y, uint8_t z, Ti
|
||||
}
|
||||
|
||||
/* test_element is a path */
|
||||
if (!is_valid_path_z_and_direction(test_element, adjac_z, adjac_dir))
|
||||
if (!is_valid_path_z_and_direction(test_element, adjacPos.z / COORDS_Z_STEP, adjac_dir))
|
||||
continue;
|
||||
|
||||
/* test_element is a connected path */
|
||||
|
||||
@@ -77,8 +77,8 @@ void staff_reset_modes();
|
||||
void staff_set_name(uint16_t spriteIndex, const char* name);
|
||||
bool staff_hire_new_member(STAFF_TYPE staffType, ENTERTAINER_COSTUME entertainerType);
|
||||
void staff_update_greyed_patrol_areas();
|
||||
bool staff_is_location_on_patrol_edge(Peep* mechanic, int32_t x, int32_t y);
|
||||
bool staff_can_ignore_wide_flag(Peep* mechanic, int32_t x, int32_t y, uint8_t z, TileElement* path);
|
||||
bool staff_is_location_on_patrol_edge(Peep* mechanic, const CoordsXY& loc);
|
||||
bool staff_can_ignore_wide_flag(Peep* mechanic, const CoordsXYZ& staffPos, TileElement* path);
|
||||
void staff_reset_stats();
|
||||
bool staff_is_patrol_area_set_for_type(STAFF_TYPE type, const CoordsXY& coords);
|
||||
void staff_set_patrol_area(int32_t staffIndex, int32_t x, int32_t y, bool value);
|
||||
|
||||
@@ -427,10 +427,9 @@ bool title_is_previewing_sequence()
|
||||
return false;
|
||||
}
|
||||
|
||||
void DrawOpenRCT2(rct_drawpixelinfo* dpi, int32_t x, int32_t y)
|
||||
void DrawOpenRCT2(rct_drawpixelinfo* dpi, const ScreenCoordsXY& screenCoords)
|
||||
{
|
||||
utf8 buffer[256];
|
||||
ScreenCoordsXY screenCoords(x, y);
|
||||
|
||||
// Write format codes
|
||||
utf8* ch = buffer;
|
||||
@@ -444,7 +443,9 @@ void DrawOpenRCT2(rct_drawpixelinfo* dpi, int32_t x, int32_t y)
|
||||
|
||||
// Invalidate screen area
|
||||
int16_t width = static_cast<int16_t>(gfx_get_string_width(buffer));
|
||||
gfx_set_dirty_blocks(x, y, x + width, y + 30); // 30 is an arbitrary height to catch both strings
|
||||
gfx_set_dirty_blocks(
|
||||
screenCoords.x, screenCoords.y, screenCoords.x + width,
|
||||
screenCoords.y + 30); // 30 is an arbitrary height to catch both strings
|
||||
|
||||
// Write platform information
|
||||
snprintf(ch, 256 - (ch - buffer), "%s (%s)", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE);
|
||||
|
||||
@@ -65,4 +65,4 @@ size_t title_get_current_sequence();
|
||||
bool title_preview_sequence(size_t value);
|
||||
void title_stop_previewing_sequence();
|
||||
bool title_is_previewing_sequence();
|
||||
void DrawOpenRCT2(rct_drawpixelinfo* dpi, int32_t x, int32_t y);
|
||||
void DrawOpenRCT2(rct_drawpixelinfo* dpi, const ScreenCoordsXY& screenCoords);
|
||||
|
||||
@@ -72,5 +72,3 @@ constexpr const uint8_t LandSlopeToWallSlope[][NumOrthogonalDirections] = {
|
||||
// clang-format on
|
||||
|
||||
#pragma endregion
|
||||
|
||||
money32 wall_remove(int16_t x, int16_t y, uint8_t baseHeight, uint8_t direction, uint8_t flags);
|
||||
|
||||
Reference in New Issue
Block a user