From f535a4a0c4a0c6ac05ca215606e68b447f1ff128 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 16:26:51 -0300 Subject: [PATCH 1/4] Remove undefined and unused wall_remove function --- src/openrct2/world/Wall.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/openrct2/world/Wall.h b/src/openrct2/world/Wall.h index bde25e1ad5..080517406f 100644 --- a/src/openrct2/world/Wall.h +++ b/src/openrct2/world/Wall.h @@ -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); From 1a7943a5abef6a8c3967297686a8a60697b404a1 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 16:30:58 -0300 Subject: [PATCH 2/4] Make DrawOpenRCT2 use ScreenCoordsXY --- src/openrct2/paint/Painter.cpp | 2 +- src/openrct2/title/TitleScreen.cpp | 7 ++++--- src/openrct2/title/TitleScreen.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index 5da1170907..684ee39672 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -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); diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/title/TitleScreen.cpp index a9c687b405..8835854787 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/title/TitleScreen.cpp @@ -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(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); diff --git a/src/openrct2/title/TitleScreen.h b/src/openrct2/title/TitleScreen.h index 4ded4f646a..cacf106029 100644 --- a/src/openrct2/title/TitleScreen.h +++ b/src/openrct2/title/TitleScreen.h @@ -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); From caeed92cf0d657f78c0dbf006a739659dc3f6634 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 16:41:18 -0300 Subject: [PATCH 3/4] Make staff_is_location_on_patrol_edge use CoordsXY --- src/openrct2/peep/Staff.cpp | 23 ++++++++++------------- src/openrct2/peep/Staff.h | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 0be73aa635..34b903fbec 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -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,9 +195,8 @@ 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; @@ -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, { x, y })) { 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 = CoordsXYZ{ x + CoordsDirectionDelta[adjac_dir].x, y + CoordsDirectionDelta[adjac_dir].y, z }; /* 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 = z + 2; } } /* 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, adjac_dir)) continue; /* test_element is a connected path */ diff --git a/src/openrct2/peep/Staff.h b/src/openrct2/peep/Staff.h index 85d83d960d..76ae22b9a6 100644 --- a/src/openrct2/peep/Staff.h +++ b/src/openrct2/peep/Staff.h @@ -77,7 +77,7 @@ 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_is_location_on_patrol_edge(Peep* mechanic, const CoordsXY& loc); bool staff_can_ignore_wide_flag(Peep* mechanic, int32_t x, int32_t y, uint8_t z, TileElement* path); void staff_reset_stats(); bool staff_is_patrol_area_set_for_type(STAFF_TYPE type, const CoordsXY& coords); From abcb50ff9697d5920c798b6208f750b3b208ba85 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sun, 21 Jun 2020 22:25:22 -0300 Subject: [PATCH 4/4] Make staff_can_ignore_wide_flag use CoordsXYZ --- src/openrct2/peep/GuestPathfinding.cpp | 5 ++--- src/openrct2/peep/Staff.cpp | 10 +++++----- src/openrct2/peep/Staff.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 137162ab7c..e957f1a321 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -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; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 34b903fbec..d71181bf8a 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -202,7 +202,7 @@ bool staff_is_location_on_patrol_edge(Peep* mechanic, const CoordsXY& loc) 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. @@ -228,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; } @@ -240,7 +240,7 @@ 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) { - auto adjacPos = CoordsXYZ{ x + CoordsDirectionDelta[adjac_dir].x, y + CoordsDirectionDelta[adjac_dir].y, 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(adjacPos)) @@ -264,7 +264,7 @@ bool staff_can_ignore_wide_flag(Peep* staff, int32_t x, int32_t y, uint8_t z, Ti { if (path->AsPath()->GetSlopeDirection() == adjac_dir) { - adjacPos.z = z + 2; + adjacPos.z += PATH_HEIGHT_STEP; } } @@ -282,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, adjacPos.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 */ diff --git a/src/openrct2/peep/Staff.h b/src/openrct2/peep/Staff.h index 76ae22b9a6..3826dee4d0 100644 --- a/src/openrct2/peep/Staff.h +++ b/src/openrct2/peep/Staff.h @@ -78,7 +78,7 @@ 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, const CoordsXY& loc); -bool staff_can_ignore_wide_flag(Peep* mechanic, int32_t x, int32_t y, uint8_t z, TileElement* path); +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);