Refactor more path stuff (#25173)

* Pass entrance path type to game action

Fixes a desync when placing a park entrance in multiplayer

* Remove unused gFootpathSelectedId

* Move two footpath globals into the window

* Move FootpathGetDefaultSurface() into window

* Move WallInTheWay() to Wall.{cpp,h}

* Create FootpathGetPlacementFromScreenCoords()
This commit is contained in:
Michael Steenbeek authored and GitHub committed 2025-09-14 19:18:31 +02:00
commit 6e6e77bb57
14 files changed
+246 -246

No files matched your search

+1
View File
@@ -8,6 +8,7 @@
- Fix: [#25147] The wooden support clearance heights for steep Log Flume track pieces are too low.
- Fix: [#25160] The Go-Karts steep to flat track piece has incorrect wooden support clearance heights.
- Fix: [#25163] Some of the Junior Roller Coaster flat to steep track wooden support clearance heights are different to RCT1.
- Fix: [#25173] Desync when placing a park entrance in multiplayer.
0.4.26 (2025-09-06)
------------------------------------------------------------------------
@@ -195,8 +195,10 @@ namespace OpenRCT2::Ui::Windows
ParkEntranceRemoveGhost();
bool isLegacyPath = (gFootpathSelection.LegacyPath != kObjectEntryIndexNull);
auto pathIndex = isLegacyPath ? gFootpathSelection.LegacyPath : gFootpathSelection.NormalSurface;
auto gameAction = GameActions::ParkEntrancePlaceAction(
parkEntrancePosition, gFootpathSelectedId, _selectedEntranceType);
parkEntrancePosition, pathIndex, _selectedEntranceType, isLegacyPath);
gameAction.SetFlags(GAME_COMMAND_FLAG_GHOST);
auto result = GameActions::Execute(&gameAction, getGameState());
@@ -214,8 +216,10 @@ namespace OpenRCT2::Ui::Windows
CoordsXYZD parkEntrancePosition = PlaceParkEntranceGetMapPosition(screenCoords);
if (!parkEntrancePosition.IsNull())
{
bool isLegacyPath = (gFootpathSelection.LegacyPath != kObjectEntryIndexNull);
auto pathIndex = isLegacyPath ? gFootpathSelection.LegacyPath : gFootpathSelection.NormalSurface;
auto gameAction = GameActions::ParkEntrancePlaceAction(
parkEntrancePosition, gFootpathSelectedId, _selectedEntranceType);
parkEntrancePosition, pathIndex, _selectedEntranceType, isLegacyPath);
auto result = GameActions::Execute(&gameAction, getGameState());
if (result.Error == GameActions::Status::Ok)
{
+188 -60
View File
@@ -90,6 +90,8 @@ namespace OpenRCT2::Ui::Windows
};
static ProvisionalFootpath _provisionalFootpath;
static CoordsXYZ _footpathConstructFromPosition;
static uint8_t _footpathConstructSlope;
#pragma region Measurements
@@ -463,11 +465,11 @@ namespace OpenRCT2::Ui::Windows
// Get construction image
uint8_t direction = (_footpathConstructDirection + GetCurrentRotation()) % 4;
uint8_t slope = 0;
if (gFootpathConstructSlope == 2)
if (_footpathConstructSlope == 2)
{
slope = kTileSlopeNCornerUp;
}
else if (gFootpathConstructSlope == 6)
else if (_footpathConstructSlope == 6)
{
slope = kTileSlopeECornerUp;
}
@@ -529,6 +531,17 @@ namespace OpenRCT2::Ui::Windows
#pragma endregion
private:
FootpathPlacementResult FootpathGetPlacementFromScreenCoords(const ScreenCoordsXY& screenCoords)
{
if (_footpathPlaceZ > 0)
return { _footpathPlaceZ, kTileSlopeFlat };
auto info = GetMapCoordinatesFromPos(
screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath));
return FootpathGetPlacementFromInfo(info);
}
/**
*
* rct2: 0x006A7760
@@ -786,7 +799,7 @@ namespace OpenRCT2::Ui::Windows
void WindowFootpathMousedownSlope(int32_t slope)
{
FootpathUpdateProvisional();
gFootpathConstructSlope = slope;
_footpathConstructSlope = slope;
_windowFootpathCost = kMoney64Undefined;
WindowFootpathSetEnabledAndPressedWidgets();
}
@@ -977,30 +990,19 @@ namespace OpenRCT2::Ui::Windows
FootpathUpdateProvisional();
// Figure out what slope and height to use
int32_t slope = kTileSlopeFlat;
auto baseZ = _footpathPlaceZ;
if (baseZ == 0)
auto placement = FootpathGetPlacementFromScreenCoords(screenCoords);
if (!placement.isValid())
{
auto info = GetMapCoordinatesFromPos(
screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath));
auto result = FootpathGetPlacementFromInfo(info);
if (!result.isValid())
{
gMapSelectFlags.unset(MapSelectFlag::enable);
FootpathUpdateProvisional();
return;
}
baseZ = result.baseZ;
slope = result.slope;
gMapSelectFlags.unset(MapSelectFlag::enable);
FootpathUpdateProvisional();
return;
}
// Set provisional path
auto pathType = gFootpathSelection.GetSelectedSurface();
auto constructFlags = FootpathCreateConstructFlags(pathType);
const auto footpathCost = FootpathProvisionalSet(
pathType, gFootpathSelection.Railings, { *mapPos, baseZ }, slope, constructFlags);
pathType, gFootpathSelection.Railings, { *mapPos, placement.baseZ }, placement.slope, constructFlags);
if (_windowFootpathCost != footpathCost)
{
@@ -1068,24 +1070,15 @@ namespace OpenRCT2::Ui::Windows
if (!mapPos)
return;
auto slope = kTileSlopeFlat;
auto baseZ = _footpathPlaceZ;
if (baseZ == 0)
{
const auto info = GetMapCoordinatesFromPos(
screenCoords, EnumsToFlags(ViewportInteractionItem::Terrain, ViewportInteractionItem::Footpath));
auto result = FootpathGetPlacementFromInfo(info);
baseZ = result.baseZ;
slope = result.slope;
}
auto placement = FootpathGetPlacementFromScreenCoords(screenCoords);
// Try and place path
auto selectedType = gFootpathSelection.GetSelectedSurface();
PathConstructFlags constructFlags = FootpathCreateConstructFlags(selectedType);
auto footpathPlaceAction = GameActions::FootpathPlaceAction(
{ *mapPos, baseZ }, slope, selectedType, gFootpathSelection.Railings, kInvalidDirection, constructFlags);
{ *mapPos, placement.baseZ }, placement.slope, selectedType, gFootpathSelection.Railings, kInvalidDirection,
constructFlags);
footpathPlaceAction.SetCallback([this](const GameActions::GameAction* ga, const GameActions::Result* result) {
if (result->Error == GameActions::Status::Ok)
{
@@ -1151,10 +1144,10 @@ namespace OpenRCT2::Ui::Windows
}
ToolCancel();
gFootpathConstructFromPosition = { mapCoords, z };
_footpathConstructFromPosition = { mapCoords, z };
_footpathConstructDirection = direction;
_provisionalFootpath.flags.clearAll();
gFootpathConstructSlope = 0;
_footpathConstructSlope = 0;
_footpathConstructionMode = PathConstructionMode::bridgeOrTunnel;
_footpathConstructValidDirections = kInvalidDirection;
WindowFootpathSetEnabledAndPressedWidgets();
@@ -1195,7 +1188,7 @@ namespace OpenRCT2::Ui::Windows
if (result->Error == GameActions::Status::Ok)
{
if (gFootpathConstructSlope == 0)
if (_footpathConstructSlope == 0)
{
self->_footpathConstructValidDirections = kInvalidDirection;
}
@@ -1209,13 +1202,13 @@ namespace OpenRCT2::Ui::Windows
ViewportSetVisibility(ViewportVisibility::UndergroundViewOn);
}
gFootpathConstructFromPosition = footpathLoc;
_footpathConstructFromPosition = footpathLoc;
// If we have just built an upwards slope, the next path to construct is
// a bit higher. Note that the z returned by footpath_get_next_path_info
// already is lowered if we are building a downwards slope.
if (gFootpathConstructSlope == 2)
if (_footpathConstructSlope == 2)
{
gFootpathConstructFromPosition.z += kPathHeightStep;
_footpathConstructFromPosition.z += kPathHeightStep;
}
}
self->WindowFootpathSetEnabledAndPressedWidgets();
@@ -1259,15 +1252,15 @@ namespace OpenRCT2::Ui::Windows
}
}
gFootpathConstructFromPosition.z = tileElement->GetBaseZ();
auto action = GameActions::FootpathRemoveAction(gFootpathConstructFromPosition);
_footpathConstructFromPosition.z = tileElement->GetBaseZ();
auto action = GameActions::FootpathRemoveAction(_footpathConstructFromPosition);
GameActions::Execute(&action, getGameState());
// Move selection
edge = DirectionReverse(edge);
gFootpathConstructFromPosition.x -= CoordsDirectionDelta[edge].x;
gFootpathConstructFromPosition.y -= CoordsDirectionDelta[edge].y;
gFootpathConstructFromPosition.z = z;
_footpathConstructFromPosition.x -= CoordsDirectionDelta[edge].x;
_footpathConstructFromPosition.y -= CoordsDirectionDelta[edge].y;
_footpathConstructFromPosition.z = z;
_footpathConstructDirection = edge;
_footpathConstructValidDirections = kInvalidDirection;
}
@@ -1281,15 +1274,15 @@ namespace OpenRCT2::Ui::Windows
TileElement* tileElement;
int32_t z, zLow;
if (!MapIsLocationValid(gFootpathConstructFromPosition))
if (!MapIsLocationValid(_footpathConstructFromPosition))
{
return nullptr;
}
z = std::min(255 * kCoordsZStep, gFootpathConstructFromPosition.z);
z = std::min(255 * kCoordsZStep, _footpathConstructFromPosition.z);
zLow = z - kPathHeightStep;
tileElement = MapGetFirstElementAt(gFootpathConstructFromPosition);
tileElement = MapGetFirstElementAt(_footpathConstructFromPosition);
do
{
if (tileElement == nullptr)
@@ -1360,8 +1353,8 @@ namespace OpenRCT2::Ui::Windows
int32_t direction = _footpathConstructDirection;
gMapSelectionTiles.clear();
gMapSelectionTiles.push_back(
{ gFootpathConstructFromPosition.x + CoordsDirectionDelta[direction].x,
gFootpathConstructFromPosition.y + CoordsDirectionDelta[direction].y });
{ _footpathConstructFromPosition.x + CoordsDirectionDelta[direction].x,
_footpathConstructFromPosition.y + CoordsDirectionDelta[direction].y });
MapInvalidateMapSelectionTiles();
}
@@ -1377,7 +1370,7 @@ namespace OpenRCT2::Ui::Windows
pressedWidgets |= (1LL << (WIDX_DIRECTION_NW + direction));
// Set pressed slope widget
int32_t slope = gFootpathConstructSlope;
int32_t slope = _footpathConstructSlope;
if (slope == kTileSlopeSESideUp)
{
pressedWidgets |= (1uLL << WIDX_SLOPEDOWN);
@@ -1423,18 +1416,18 @@ namespace OpenRCT2::Ui::Windows
void FootpathGetNextPathInfo(ObjectEntryIndex* type, CoordsXYZ& footpathLoc, int32_t* slope)
{
auto direction = _footpathConstructDirection;
footpathLoc.x = gFootpathConstructFromPosition.x + CoordsDirectionDelta[direction].x;
footpathLoc.y = gFootpathConstructFromPosition.y + CoordsDirectionDelta[direction].y;
footpathLoc.z = gFootpathConstructFromPosition.z;
footpathLoc.x = _footpathConstructFromPosition.x + CoordsDirectionDelta[direction].x;
footpathLoc.y = _footpathConstructFromPosition.y + CoordsDirectionDelta[direction].y;
footpathLoc.z = _footpathConstructFromPosition.z;
if (type != nullptr)
{
*type = gFootpathSelection.GetSelectedSurface();
}
*slope = kTileSlopeFlat;
if (gFootpathConstructSlope != 0)
if (_footpathConstructSlope != 0)
{
*slope = _footpathConstructDirection | kTileSlopeSCornerUp;
if (gFootpathConstructSlope != 2)
if (_footpathConstructSlope != 2)
{
footpathLoc.z -= kPathHeightStep;
*slope ^= kTileSlopeECornerUp;
@@ -1491,7 +1484,7 @@ namespace OpenRCT2::Ui::Windows
return;
}
switch (gFootpathConstructSlope)
switch (_footpathConstructSlope)
{
case 0:
OnMouseDown(WIDX_SLOPEDOWN);
@@ -1513,7 +1506,7 @@ namespace OpenRCT2::Ui::Windows
return;
}
switch (gFootpathConstructSlope)
switch (_footpathConstructSlope)
{
case 6:
OnMouseDown(WIDX_LEVEL);
@@ -1530,7 +1523,7 @@ namespace OpenRCT2::Ui::Windows
void KeyboardShortcutSlopeLevel()
{
if (IsWidgetDisabled(WIDX_SLOPEDOWN) || IsWidgetDisabled(WIDX_LEVEL) || IsWidgetDisabled(WIDX_SLOPEUP)
|| widgets[WIDX_LEVEL].type == WidgetType::empty || gFootpathConstructSlope == 0)
|| widgets[WIDX_LEVEL].type == WidgetType::empty || _footpathConstructSlope == 0)
{
return;
}
@@ -1568,7 +1561,7 @@ namespace OpenRCT2::Ui::Windows
*/
WindowBase* FootpathOpen()
{
if (!FootpathSelectDefault())
if (!WindowFootpathSelectDefault())
{
// No path objects to select from, don't open window
return nullptr;
@@ -1730,7 +1723,7 @@ namespace OpenRCT2::Ui::Windows
}
else if (
_provisionalFootpath.slope == kTileSlopeFlat
|| _provisionalFootpath.position.z < gFootpathConstructFromPosition.z)
|| _provisionalFootpath.position.z < _footpathConstructFromPosition.z)
{
// Going either straight on, or down.
VirtualFloorSetHeight(_provisionalFootpath.position.z);
@@ -1772,7 +1765,7 @@ namespace OpenRCT2::Ui::Windows
_provisionalFootpath.flags.unset(ProvisionalPathFlag::showArrow);
gMapSelectFlags.unset(MapSelectFlag::enableArrow);
MapInvalidateTileFull(gFootpathConstructFromPosition);
MapInvalidateTileFull(_footpathConstructFromPosition);
}
FootpathRemoveProvisional();
}
@@ -1801,4 +1794,139 @@ namespace OpenRCT2::Ui::Windows
{
_provisionalFootpath.flags.set(ProvisionalPathFlag::forceRecheck);
}
static ObjectEntryIndex FootpathGetDefaultSurface(bool queue)
{
bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode);
for (ObjectEntryIndex i = 0; i < kMaxFootpathSurfaceObjects; i++)
{
auto pathEntry = GetPathSurfaceEntry(i);
if (pathEntry != nullptr)
{
if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR))
{
continue;
}
if (queue == ((pathEntry->Flags & FOOTPATH_ENTRY_FLAG_IS_QUEUE) != 0))
{
return i;
}
}
}
return kObjectEntryIndexNull;
}
static bool FootpathIsSurfaceEntryOkay(ObjectEntryIndex index, bool queue)
{
auto pathEntry = GetPathSurfaceEntry(index);
if (pathEntry != nullptr)
{
bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode);
if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR))
{
return false;
}
if (queue == ((pathEntry->Flags & FOOTPATH_ENTRY_FLAG_IS_QUEUE) != 0))
{
return true;
}
}
return false;
}
static ObjectEntryIndex FootpathGetDefaultRailings()
{
for (ObjectEntryIndex i = 0; i < kMaxFootpathRailingsObjects; i++)
{
const auto* railingEntry = GetPathRailingsEntry(i);
if (railingEntry != nullptr)
{
return i;
}
}
return kObjectEntryIndexNull;
}
static bool FootpathIsLegacyPathEntryOkay(ObjectEntryIndex index)
{
bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode);
auto& objManager = OpenRCT2::GetContext()->GetObjectManager();
auto footpathObj = objManager.GetLoadedObject<FootpathObject>(index);
if (footpathObj != nullptr)
{
auto pathEntry = reinterpret_cast<FootpathEntry*>(footpathObj->GetLegacyData());
return showEditorPaths || !(pathEntry->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR);
}
return false;
}
static ObjectEntryIndex FootpathGetDefaultLegacyPath()
{
for (ObjectEntryIndex i = 0; i < kMaxPathObjects; i++)
{
if (FootpathIsLegacyPathEntryOkay(i))
{
return i;
}
}
return kObjectEntryIndexNull;
}
bool WindowFootpathSelectDefault()
{
// Select default footpath
auto surfaceIndex = FootpathGetDefaultSurface(false);
if (FootpathIsSurfaceEntryOkay(gFootpathSelection.NormalSurface, false))
{
surfaceIndex = gFootpathSelection.NormalSurface;
}
// Select default queue
auto queueIndex = FootpathGetDefaultSurface(true);
if (FootpathIsSurfaceEntryOkay(gFootpathSelection.QueueSurface, true))
{
queueIndex = gFootpathSelection.QueueSurface;
}
// Select default railing
auto railingIndex = FootpathGetDefaultRailings();
const auto* railingEntry = GetPathRailingsEntry(gFootpathSelection.Railings);
if (railingEntry != nullptr)
{
railingIndex = gFootpathSelection.Railings;
}
// Select default legacy path
auto legacyPathIndex = FootpathGetDefaultLegacyPath();
if (gFootpathSelection.LegacyPath != kObjectEntryIndexNull)
{
if (FootpathIsLegacyPathEntryOkay(gFootpathSelection.LegacyPath))
{
// Keep legacy path selected
legacyPathIndex = gFootpathSelection.LegacyPath;
}
else
{
// Reset legacy path, we default to a surface (if there are any)
gFootpathSelection.LegacyPath = kObjectEntryIndexNull;
}
}
if (surfaceIndex == kObjectEntryIndexNull)
{
if (legacyPathIndex == kObjectEntryIndexNull)
{
// No surfaces or legacy paths available
return false;
}
// No surfaces available, so default to legacy path
gFootpathSelection.LegacyPath = legacyPathIndex;
}
gFootpathSelection.NormalSurface = surfaceIndex;
gFootpathSelection.QueueSurface = queueIndex;
gFootpathSelection.Railings = railingIndex;
return true;
}
} // namespace OpenRCT2::Ui::Windows
+1 -1
View File
@@ -252,7 +252,7 @@ namespace OpenRCT2::Ui::Windows
InitMap();
gWindowSceneryRotation = 0;
CentreMapOnViewPoint();
FootpathSelectDefault();
WindowFootpathSelectDefault();
auto& gameState = getGameState();
_mapWidthAndHeightLinked = gameState.mapSize.x == gameState.mapSize.y;
+1
View File
@@ -110,6 +110,7 @@ namespace OpenRCT2::Ui::Windows
void WindowFootpathKeyboardShortcutSlopeUp();
void WindowFootpathKeyboardShortcutBuildCurrent();
void WindowFootpathKeyboardShortcutDemolishCurrent();
bool WindowFootpathSelectDefault();
// GameBottomToolbar
extern uint8_t gToolbarDirtyFlags;
@@ -27,7 +27,7 @@
namespace OpenRCT2::GameActions
{
ParkEntrancePlaceAction::ParkEntrancePlaceAction(
const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType)
const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType, bool pathTypeIsLegacy)
: _loc(location)
, _pathType(pathType)
, _entranceType(entranceType)
@@ -39,6 +39,7 @@ namespace OpenRCT2::GameActions
visitor.Visit(_loc);
visitor.Visit("footpathSurfaceObject", _pathType);
visitor.Visit("entranceObject", _entranceType);
visitor.Visit("footpathTypeIsLegacy", _pathTypeIsLegacy);
}
uint16_t ParkEntrancePlaceAction::GetActionFlags() const
@@ -53,6 +54,7 @@ namespace OpenRCT2::GameActions
stream << DS_TAG(_loc);
stream << DS_TAG(_pathType);
stream << DS_TAG(_entranceType);
stream << DS_TAG(_pathTypeIsLegacy);
}
Result ParkEntrancePlaceAction::Query(GameState_t& gameState) const
@@ -64,7 +66,7 @@ namespace OpenRCT2::GameActions
auto res = Result();
res.Expenditure = ExpenditureType::landPurchase;
res.Position = { _loc.x, _loc.y, _loc.z };
res.Position = _loc;
auto mapSizeUnits = GetMapSizeUnits() - CoordsXY{ kCoordsXYStep, kCoordsXYStep };
if (!LocationValid(_loc) || _loc.x <= kCoordsXYStep || _loc.y <= kCoordsXYStep || _loc.x >= mapSizeUnits.x
@@ -159,13 +161,13 @@ namespace OpenRCT2::GameActions
entranceElement->SetSequenceIndex(index);
entranceElement->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE);
entranceElement->setEntryIndex(_entranceType);
if (gFootpathSelection.LegacyPath == kObjectEntryIndexNull)
if (!_pathTypeIsLegacy)
{
entranceElement->SetSurfaceEntryIndex(gFootpathSelection.NormalSurface);
entranceElement->SetSurfaceEntryIndex(_pathType);
}
else
{
entranceElement->SetLegacyPathEntryIndex(gFootpathSelection.LegacyPath);
entranceElement->SetLegacyPathEntryIndex(_pathType);
}
if (!entranceElement->IsGhost())
@@ -19,10 +19,12 @@ namespace OpenRCT2::GameActions
CoordsXYZD _loc;
ObjectEntryIndex _pathType;
ObjectEntryIndex _entranceType;
bool _pathTypeIsLegacy;
public:
ParkEntrancePlaceAction() = default;
ParkEntrancePlaceAction(const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType);
ParkEntrancePlaceAction(
const CoordsXYZD& location, ObjectEntryIndex pathType, ObjectEntryIndex entranceType, bool pathTypeIsLegacy);
void AcceptParameters(GameActionParameterVisitor&) final;
+1
View File
@@ -46,6 +46,7 @@
#include "../world/Footpath.h"
#include "../world/Map.h"
#include "../world/Scenery.h"
#include "../world/Wall.h"
#include "../world/tile_element/EntranceElement.h"
#include "../world/tile_element/PathElement.h"
#include "../world/tile_element/Slope.h"
+1 -1
View File
@@ -47,7 +47,7 @@
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
constexpr uint8_t kStreamVersion = 2;
constexpr uint8_t kStreamVersion = 3;
const std::string kStreamID = std::string(kOpenRCT2Version) + "-" + std::to_string(kStreamVersion);
+1
View File
@@ -22,6 +22,7 @@
#include "../world/Entrance.h"
#include "../world/Footpath.h"
#include "../world/Map.h"
#include "../world/Wall.h"
#include "../world/tile_element/BannerElement.h"
#include "../world/tile_element/EntranceElement.h"
#include "../world/tile_element/PathElement.h"
+1 -171
View File
@@ -36,6 +36,7 @@
#include "Location.hpp"
#include "Map.h"
#include "MapAnimation.h"
#include "Wall.h"
#include "tile_element/BannerElement.h"
#include "tile_element/EntranceElement.h"
#include "tile_element/PathElement.h"
@@ -52,9 +53,6 @@ using namespace OpenRCT2::TrackMetaData;
void FootpathUpdateQueueEntranceBanner(const CoordsXY& footpathPos, TileElement* tileElement);
FootpathSelection gFootpathSelection;
uint16_t gFootpathSelectedId;
CoordsXYZ gFootpathConstructFromPosition;
uint8_t gFootpathConstructSlope;
uint8_t gFootpathGroundFlags;
static RideId* _footpathQueueChainNext;
@@ -188,39 +186,6 @@ void FootpathInterruptPeeps(const CoordsXYZ& footpathPos)
}
}
/**
* Returns true if the edge of tile x, y specified by direction is occupied by a fence
* between heights z0 and z1.
*
* Note that there may still be a fence on the opposing tile.
*
* rct2: 0x006E59DC
*/
bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction)
{
TileElement* tileElement;
tileElement = MapGetFirstElementAt(fencePos);
if (tileElement == nullptr)
return false;
do
{
if (tileElement->GetType() != TileElementType::Wall)
continue;
if (tileElement->IsGhost())
continue;
if (fencePos.baseZ >= tileElement->GetClearanceZ())
continue;
if (fencePos.clearanceZ <= tileElement->GetBaseZ())
continue;
if ((tileElement->GetDirection()) != direction)
continue;
return true;
} while (!(tileElement++)->IsLastForTile());
return false;
}
static PathElement* FootpathConnectCornersGetNeighbour(const CoordsXYZ& footpathPos, int32_t requireEdges)
{
if (!MapIsLocationValid(footpathPos))
@@ -1827,141 +1792,6 @@ void FootpathRemoveEdgesAt(const CoordsXY& footpathPos, TileElement* tileElement
tileElement->AsPath()->SetEdgesAndCorners(0);
}
static ObjectEntryIndex FootpathGetDefaultSurface(bool queue)
{
bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode);
for (ObjectEntryIndex i = 0; i < kMaxFootpathSurfaceObjects; i++)
{
auto pathEntry = GetPathSurfaceEntry(i);
if (pathEntry != nullptr)
{
if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR))
{
continue;
}
if (queue == ((pathEntry->Flags & FOOTPATH_ENTRY_FLAG_IS_QUEUE) != 0))
{
return i;
}
}
}
return kObjectEntryIndexNull;
}
static bool FootpathIsSurfaceEntryOkay(ObjectEntryIndex index, bool queue)
{
auto pathEntry = GetPathSurfaceEntry(index);
if (pathEntry != nullptr)
{
bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode);
if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR))
{
return false;
}
if (queue == ((pathEntry->Flags & FOOTPATH_ENTRY_FLAG_IS_QUEUE) != 0))
{
return true;
}
}
return false;
}
static ObjectEntryIndex FootpathGetDefaultRailings()
{
for (ObjectEntryIndex i = 0; i < kMaxFootpathRailingsObjects; i++)
{
const auto* railingEntry = GetPathRailingsEntry(i);
if (railingEntry != nullptr)
{
return i;
}
}
return kObjectEntryIndexNull;
}
static bool FootpathIsLegacyPathEntryOkay(ObjectEntryIndex index)
{
bool showEditorPaths = (gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode);
auto& objManager = OpenRCT2::GetContext()->GetObjectManager();
auto footpathObj = objManager.GetLoadedObject<FootpathObject>(index);
if (footpathObj != nullptr)
{
auto pathEntry = reinterpret_cast<FootpathEntry*>(footpathObj->GetLegacyData());
return showEditorPaths || !(pathEntry->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR);
}
return false;
}
static ObjectEntryIndex FootpathGetDefaultLegacyPath()
{
for (ObjectEntryIndex i = 0; i < kMaxPathObjects; i++)
{
if (FootpathIsLegacyPathEntryOkay(i))
{
return i;
}
}
return kObjectEntryIndexNull;
}
bool FootpathSelectDefault()
{
// Select default footpath
auto surfaceIndex = FootpathGetDefaultSurface(false);
if (FootpathIsSurfaceEntryOkay(gFootpathSelection.NormalSurface, false))
{
surfaceIndex = gFootpathSelection.NormalSurface;
}
// Select default queue
auto queueIndex = FootpathGetDefaultSurface(true);
if (FootpathIsSurfaceEntryOkay(gFootpathSelection.QueueSurface, true))
{
queueIndex = gFootpathSelection.QueueSurface;
}
// Select default railing
auto railingIndex = FootpathGetDefaultRailings();
const auto* railingEntry = GetPathRailingsEntry(gFootpathSelection.Railings);
if (railingEntry != nullptr)
{
railingIndex = gFootpathSelection.Railings;
}
// Select default legacy path
auto legacyPathIndex = FootpathGetDefaultLegacyPath();
if (gFootpathSelection.LegacyPath != kObjectEntryIndexNull)
{
if (FootpathIsLegacyPathEntryOkay(gFootpathSelection.LegacyPath))
{
// Keep legacy path selected
legacyPathIndex = gFootpathSelection.LegacyPath;
}
else
{
// Reset legacy path, we default to a surface (if there are any)
gFootpathSelection.LegacyPath = kObjectEntryIndexNull;
}
}
if (surfaceIndex == kObjectEntryIndexNull)
{
if (legacyPathIndex == kObjectEntryIndexNull)
{
// No surfaces or legacy paths available
return false;
}
// No surfaces available, so default to legacy path
gFootpathSelection.LegacyPath = legacyPathIndex;
}
gFootpathSelection.NormalSurface = surfaceIndex;
gFootpathSelection.QueueSurface = queueIndex;
gFootpathSelection.Railings = railingIndex;
return true;
}
const FootpathObject* GetLegacyFootpathEntry(ObjectEntryIndex entryIndex)
{
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
-5
View File
@@ -136,9 +136,6 @@ enum
};
extern FootpathSelection gFootpathSelection;
extern uint16_t gFootpathSelectedId;
extern CoordsXYZ gFootpathConstructFromPosition;
extern uint8_t gFootpathConstructSlope;
extern uint8_t gFootpathGroundFlags;
// Given a direction, this will return how to increase/decrease the x and y coordinates.
@@ -151,7 +148,6 @@ void FootpathInterruptPeeps(const CoordsXYZ& footpathPos);
void FootpathRemoveLitter(const CoordsXYZ& footpathPos);
void FootpathConnectEdges(const CoordsXY& footpathPos, OpenRCT2::TileElement* tileElement, int32_t flags);
void FootpathUpdateQueueChains();
bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction);
void FootpathChainRideQueue(
RideId rideIndex, StationIndex entranceIndex, const CoordsXY& footpathPos, OpenRCT2::TileElement* tileElement,
int32_t direction);
@@ -161,7 +157,6 @@ bool FootpathIsBlockedByVehicle(const TileCoordsXYZ& position);
int32_t FootpathIsConnectedToMapEdge(const CoordsXYZ& footpathPos, int32_t direction, int32_t flags);
void FootpathRemoveEdgesAt(const CoordsXY& footpathPos, OpenRCT2::TileElement* tileElement);
bool FootpathSelectDefault();
const OpenRCT2::FootpathObject* GetLegacyFootpathEntry(OpenRCT2::ObjectEntryIndex entryIndex);
const OpenRCT2::FootpathSurfaceObject* GetPathSurfaceEntry(OpenRCT2::ObjectEntryIndex entryIndex);
const OpenRCT2::FootpathRailingsObject* GetPathRailingsEntry(OpenRCT2::ObjectEntryIndex entryIndex);
+33
View File
@@ -114,3 +114,36 @@ uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge)
{
return kLandSlopeToWallSlope[Slope][Edge];
}
/**
* Returns true if the edge of tile x, y specified by direction is occupied by a fence
* between heights z0 and z1.
*
* Note that there may still be a fence on the opposing tile.
*
* rct2: 0x006E59DC
*/
bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction)
{
TileElement* tileElement;
tileElement = MapGetFirstElementAt(fencePos);
if (tileElement == nullptr)
return false;
do
{
if (tileElement->GetType() != TileElementType::Wall)
continue;
if (tileElement->IsGhost())
continue;
if (fencePos.baseZ >= tileElement->GetClearanceZ())
continue;
if (fencePos.clearanceZ <= tileElement->GetBaseZ())
continue;
if ((tileElement->GetDirection()) != direction)
continue;
return true;
} while (!(tileElement++)->IsLastForTile());
return false;
}
+2
View File
@@ -26,3 +26,5 @@ void WallRemoveAtZ(const CoordsXYZ& wallPos);
void WallRemoveIntersectingWalls(const CoordsXYRangedZ& wallPos, Direction direction);
uint8_t GetWallSlopeFromEdgeSlope(uint8_t Slope, uint8_t Edge);
bool WallInTheWay(const CoordsXYRangedZ& fencePos, int32_t direction);