1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 12:33:17 +01:00

Refactor provisional footpath flags

This commit is contained in:
Gymnasiast
2024-09-03 20:00:33 +02:00
parent 4ff99d6fd1
commit 8715264e1e
2 changed files with 71 additions and 47 deletions

View File

@@ -35,6 +35,7 @@
#include <openrct2/paint/VirtualFloor.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include <openrct2/world/Footpath.h>
#include <openrct2/world/Park.h>
#include <openrct2/world/Surface.h>
@@ -53,6 +54,47 @@ namespace OpenRCT2::Ui::Windows
PATH_CONSTRUCTION_MODE_BRIDGE_OR_TUNNEL
};
enum class ProvisionalPathFlag : uint8_t
{
showArrow = 0,
/**
* Set when any provisional path is present.
*/
placed = 1,
forceRecheck = 2,
};
struct ProvisionalFootpath
{
ObjectEntryIndex type;
CoordsXYZ position;
uint8_t slope;
uint8_t flags;
ObjectEntryIndex surfaceIndex;
ObjectEntryIndex railingsIndex;
PathConstructFlags constructFlags;
bool hasFlag(ProvisionalPathFlag flag)
{
return HasFlag(flags, flag);
}
void setFlag(ProvisionalPathFlag flag)
{
flags |= EnumToFlag(flag);
}
void clearFlag(ProvisionalPathFlag flag)
{
flags &= ~EnumToFlag(flag);
}
void flipFlag(ProvisionalPathFlag flag)
{
flags ^= EnumToFlag(flag);
}
};
static ProvisionalFootpath _provisionalFootpath;
#pragma region Measurements
@@ -530,14 +572,14 @@ namespace OpenRCT2::Ui::Windows
}
// Recheck area for construction. Set by ride_construction window
if (_provisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_2)
if (_provisionalFootpath.hasFlag(ProvisionalPathFlag::forceRecheck))
{
FootpathRemoveProvisional();
_provisionalFootpath.Flags &= ~PROVISIONAL_PATH_FLAG_2;
_provisionalFootpath.clearFlag(ProvisionalPathFlag::forceRecheck);
}
// Update provisional bridge mode path
if (!(_provisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1))
if (!(_provisionalFootpath.hasFlag(ProvisionalPathFlag::placed)))
{
ObjectEntryIndex type;
ObjectEntryIndex railings = gFootpathSelection.Railings;
@@ -558,13 +600,13 @@ namespace OpenRCT2::Ui::Windows
{
_footpathConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION;
_provisionalFootpath.Flags ^= PROVISIONAL_PATH_FLAG_SHOW_ARROW;
_provisionalFootpath.flipFlag(ProvisionalPathFlag::showArrow);
CoordsXYZ footpathLoc;
int32_t slope;
FootpathGetNextPathInfo(nullptr, footpathLoc, &slope);
gMapSelectArrowPosition = footpathLoc;
gMapSelectArrowDirection = _footpathConstructDirection;
if (_provisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_SHOW_ARROW)
if (_provisionalFootpath.hasFlag(ProvisionalPathFlag::showArrow))
{
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW;
}
@@ -983,7 +1025,7 @@ namespace OpenRCT2::Ui::Windows
// Check for change
auto provisionalPos = CoordsXYZ(*mapPos, _footpathPlaceZ);
if ((_provisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1) && _provisionalFootpath.Position == provisionalPos)
if ((_provisionalFootpath.hasFlag(ProvisionalPathFlag::placed)) && _provisionalFootpath.position == provisionalPos)
{
return;
}
@@ -1178,7 +1220,7 @@ namespace OpenRCT2::Ui::Windows
ToolCancel();
gFootpathConstructFromPosition = { mapCoords, z };
_footpathConstructDirection = direction;
_provisionalFootpath.Flags = 0;
_provisionalFootpath.flags = 0;
gFootpathConstructSlope = 0;
_footpathConstructionMode = PATH_CONSTRUCTION_MODE_BRIDGE_OR_TUNNEL;
_footpathConstructValidDirections = INVALID_DIRECTION;
@@ -1722,12 +1764,12 @@ namespace OpenRCT2::Ui::Windows
cost = res.Error == GameActions::Status::Ok ? res.Cost : kMoney64Undefined;
if (res.Error == GameActions::Status::Ok)
{
_provisionalFootpath.SurfaceIndex = type;
_provisionalFootpath.RailingsIndex = railingsType;
_provisionalFootpath.Position = footpathLoc;
_provisionalFootpath.Slope = slope;
_provisionalFootpath.ConstructFlags = constructFlags;
_provisionalFootpath.Flags |= PROVISIONAL_PATH_FLAG_1;
_provisionalFootpath.surfaceIndex = type;
_provisionalFootpath.railingsIndex = railingsType;
_provisionalFootpath.position = footpathLoc;
_provisionalFootpath.slope = slope;
_provisionalFootpath.constructFlags = constructFlags;
_provisionalFootpath.setFlag(ProvisionalPathFlag::placed);
if (gFootpathGroundFlags & ELEMENT_IS_UNDERGROUND)
{
@@ -1750,16 +1792,16 @@ namespace OpenRCT2::Ui::Windows
VirtualFloorSetHeight(0);
}
else if (
_provisionalFootpath.Slope == kTileSlopeFlat
|| _provisionalFootpath.Position.z < gFootpathConstructFromPosition.z)
_provisionalFootpath.slope == kTileSlopeFlat
|| _provisionalFootpath.position.z < gFootpathConstructFromPosition.z)
{
// Going either straight on, or down.
VirtualFloorSetHeight(_provisionalFootpath.Position.z);
VirtualFloorSetHeight(_provisionalFootpath.position.z);
}
else
{
// Going up in the world!
VirtualFloorSetHeight(_provisionalFootpath.Position.z + LAND_HEIGHT_STEP);
VirtualFloorSetHeight(_provisionalFootpath.position.z + LAND_HEIGHT_STEP);
}
}
@@ -1772,11 +1814,11 @@ namespace OpenRCT2::Ui::Windows
*/
void FootpathRemoveProvisional()
{
if (_provisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1)
if (_provisionalFootpath.hasFlag(ProvisionalPathFlag::placed))
{
_provisionalFootpath.Flags &= ~PROVISIONAL_PATH_FLAG_1;
_provisionalFootpath.clearFlag(ProvisionalPathFlag::placed);
auto action = FootpathRemoveAction(_provisionalFootpath.Position);
auto action = FootpathRemoveAction(_provisionalFootpath.position);
action.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST);
GameActions::Execute(&action);
}
@@ -1788,9 +1830,9 @@ namespace OpenRCT2::Ui::Windows
*/
void FootpathUpdateProvisional()
{
if (_provisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_SHOW_ARROW)
if (_provisionalFootpath.hasFlag(ProvisionalPathFlag::showArrow))
{
_provisionalFootpath.Flags &= ~PROVISIONAL_PATH_FLAG_SHOW_ARROW;
_provisionalFootpath.clearFlag(ProvisionalPathFlag::showArrow);
gMapSelectFlags &= ~MAP_SELECT_FLAG_ENABLE_ARROW;
MapInvalidateTileFull(gFootpathConstructFromPosition);
@@ -1800,26 +1842,26 @@ namespace OpenRCT2::Ui::Windows
void FootpathRemoveProvisionalTemporarily()
{
if (_provisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1)
if (_provisionalFootpath.hasFlag(ProvisionalPathFlag::placed))
{
FootpathRemoveProvisional();
_provisionalFootpath.Flags |= PROVISIONAL_PATH_FLAG_1;
_provisionalFootpath.setFlag(ProvisionalPathFlag::placed);
}
}
void FootpathRestoreProvisional()
{
if (_provisionalFootpath.Flags & PROVISIONAL_PATH_FLAG_1)
if (_provisionalFootpath.hasFlag(ProvisionalPathFlag::placed))
{
_provisionalFootpath.Flags &= ~PROVISIONAL_PATH_FLAG_1;
_provisionalFootpath.clearFlag(ProvisionalPathFlag::placed);
FootpathProvisionalSet(
_provisionalFootpath.SurfaceIndex, _provisionalFootpath.RailingsIndex, _provisionalFootpath.Position,
_provisionalFootpath.Slope, _provisionalFootpath.ConstructFlags);
_provisionalFootpath.surfaceIndex, _provisionalFootpath.railingsIndex, _provisionalFootpath.position,
_provisionalFootpath.slope, _provisionalFootpath.constructFlags);
}
}
void FootpathRecheckProvisional()
{
_provisionalFootpath.Flags |= PROVISIONAL_PATH_FLAG_2;
_provisionalFootpath.setFlag(ProvisionalPathFlag::forceRecheck);
}
} // namespace OpenRCT2::Ui::Windows

View File

@@ -18,13 +18,6 @@ class FootpathRailingsObject;
struct PathElement;
struct TileElement;
enum
{
PROVISIONAL_PATH_FLAG_SHOW_ARROW = (1 << 0),
PROVISIONAL_PATH_FLAG_1 = (1 << 1),
PROVISIONAL_PATH_FLAG_2 = (1 << 2),
};
constexpr auto kFootpathMaxHeight = 248 * kCoordsZStep;
constexpr auto kFootpathMinHeight = 2 * kCoordsZStep;
constexpr auto kPathHeightStep = 2 * kCoordsZStep;
@@ -78,17 +71,6 @@ struct FootpathSelection
}
};
struct ProvisionalFootpath
{
ObjectEntryIndex Type;
CoordsXYZ Position;
uint8_t Slope;
uint8_t Flags;
ObjectEntryIndex SurfaceIndex;
ObjectEntryIndex RailingsIndex;
PathConstructFlags ConstructFlags;
};
// Masks for values stored in TileElement.type
enum
{