Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #22014: Change crossingMode to a strong enum #22020

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/openrct2/actions/FootpathLayoutPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ GameActions::Result FootpathLayoutPlaceAction::ElementInsertQuery(GameActions::R

// Do not attempt to build a crossing with a queue or a sloped path.
auto isQueue = _constructFlags & PathConstructFlag::IsQueue;
uint8_t crossingMode = isQueue || (_slope != kTileSlopeFlat) ? CREATE_CROSSING_MODE_NONE
: CREATE_CROSSING_MODE_PATH_OVER_TRACK;
auto crossingMode = isQueue || (_slope != kTileSlopeFlat) ? CreateCrossingMode::none : CreateCrossingMode::pathOverTrack;
auto canBuild = MapCanConstructWithClearAt(
{ _loc, zLow, zHigh }, &MapPlaceNonSceneryClearFunc, quarterTile, GetFlags(), crossingMode);
if (!entrancePath && canBuild.Error != GameActions::Status::Ok)
Expand Down Expand Up @@ -225,8 +224,7 @@ GameActions::Result FootpathLayoutPlaceAction::ElementInsertExecute(GameActions:

// Do not attempt to build a crossing with a queue or a sloped path.
auto isQueue = _constructFlags & PathConstructFlag::IsQueue;
uint8_t crossingMode = isQueue || (_slope != kTileSlopeFlat) ? CREATE_CROSSING_MODE_NONE
: CREATE_CROSSING_MODE_PATH_OVER_TRACK;
auto crossingMode = isQueue || (_slope != kTileSlopeFlat) ? CreateCrossingMode::none : CreateCrossingMode::pathOverTrack;
auto canBuild = MapCanConstructWithClearAt(
{ _loc, zLow, zHigh }, &MapPlaceNonSceneryClearFunc, quarterTile, GAME_COMMAND_FLAG_APPLY | GetFlags(), crossingMode);
if (!entrancePath && canBuild.Error != GameActions::Status::Ok)
Expand Down
6 changes: 2 additions & 4 deletions src/openrct2/actions/FootpathPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ GameActions::Result FootpathPlaceAction::ElementInsertQuery(GameActions::Result

// Do not attempt to build a crossing with a queue or a sloped path.
auto isQueue = _constructFlags & PathConstructFlag::IsQueue;
uint8_t crossingMode = isQueue || (_slope != kTileSlopeFlat) ? CREATE_CROSSING_MODE_NONE
: CREATE_CROSSING_MODE_PATH_OVER_TRACK;
auto crossingMode = isQueue || (_slope != kTileSlopeFlat) ? CreateCrossingMode::none : CreateCrossingMode::pathOverTrack;
auto canBuild = MapCanConstructWithClearAt(
{ _loc, zLow, zHigh }, &MapPlaceNonSceneryClearFunc, quarterTile, GetFlags(), crossingMode);
if (!entrancePath && canBuild.Error != GameActions::Status::Ok)
Expand Down Expand Up @@ -373,8 +372,7 @@ GameActions::Result FootpathPlaceAction::ElementInsertExecute(GameActions::Resul

// Do not attempt to build a crossing with a queue or a sloped.
auto isQueue = _constructFlags & PathConstructFlag::IsQueue;
uint8_t crossingMode = isQueue || (_slope != kTileSlopeFlat) ? CREATE_CROSSING_MODE_NONE
: CREATE_CROSSING_MODE_PATH_OVER_TRACK;
auto crossingMode = isQueue || (_slope != kTileSlopeFlat) ? CreateCrossingMode::none : CreateCrossingMode::pathOverTrack;
auto canBuild = MapCanConstructWithClearAt(
{ _loc, zLow, zHigh }, &MapPlaceNonSceneryClearFunc, quarterTile, GAME_COMMAND_FLAG_APPLY | GetFlags(), crossingMode);
if (!entrancePath && canBuild.Error != GameActions::Status::Ok)
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/actions/LandSetHeightAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ GameActions::Result LandSetHeightAction::Query() const

auto clearResult = MapCanConstructWithClearAt(
{ _coords, _height * COORDS_Z_STEP, zCorner * COORDS_Z_STEP }, &MapSetLandHeightClearFunc, { 0b1111, 0 }, 0,
CREATE_CROSSING_MODE_NONE);
CreateCrossingMode::none);
if (clearResult.Error != GameActions::Status::Ok)
{
clearResult.Error = GameActions::Status::Disallowed;
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/LargeSceneryPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ GameActions::Result LargeSceneryPlaceAction::Query() const
QuarterTile quarterTile = QuarterTile{ static_cast<uint8_t>(tile->flags >> 12), 0 }.Rotate(_loc.direction);
const auto isTree = (sceneryEntry->flags & LARGE_SCENERY_FLAG_IS_TREE) != 0;
auto canBuild = MapCanConstructWithClearAt(
{ curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CREATE_CROSSING_MODE_NONE, isTree);
{ curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree);
if (canBuild.Error != GameActions::Status::Ok)
{
canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE;
Expand Down Expand Up @@ -273,7 +273,7 @@ GameActions::Result LargeSceneryPlaceAction::Execute() const
QuarterTile quarterTile = QuarterTile{ static_cast<uint8_t>(tile->flags >> 12), 0 }.Rotate(_loc.direction);
const auto isTree = (sceneryEntry->flags & LARGE_SCENERY_FLAG_IS_TREE) != 0;
auto canBuild = MapCanConstructWithClearAt(
{ curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CREATE_CROSSING_MODE_NONE, isTree);
{ curTile, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree);
if (canBuild.Error != GameActions::Status::Ok)
{
if (banner != nullptr)
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/SmallSceneryPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ GameActions::Result SmallSceneryPlaceAction::Query() const
QuarterTile quarterTile = QuarterTile{ collisionQuadrants, supports }.Rotate(quadRotation);
const auto isTree = sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_TREE);
auto canBuild = MapCanConstructWithClearAt(
{ _loc, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CREATE_CROSSING_MODE_NONE, isTree);
{ _loc, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags(), CreateCrossingMode::none, isTree);
if (canBuild.Error != GameActions::Status::Ok)
{
canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE;
Expand Down Expand Up @@ -411,7 +411,7 @@ GameActions::Result SmallSceneryPlaceAction::Execute() const
const auto isTree = sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_IS_TREE);
auto canBuild = MapCanConstructWithClearAt(
{ _loc, zLow, zHigh }, &MapPlaceSceneryClearFunc, quarterTile, GetFlags() | GAME_COMMAND_FLAG_APPLY,
CREATE_CROSSING_MODE_NONE, isTree);
CreateCrossingMode::none, isTree);
if (canBuild.Error != GameActions::Status::Ok)
{
canBuild.ErrorTitle = STR_CANT_POSITION_THIS_HERE;
Expand Down
18 changes: 9 additions & 9 deletions src/openrct2/actions/TrackPlaceAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ GameActions::Result TrackPlaceAction::Query() const
GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_TOO_HIGH);
}

uint8_t crossingMode = (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS)
&& _trackType == TrackElemType::Flat)
? CREATE_CROSSING_MODE_TRACK_OVER_PATH
: CREATE_CROSSING_MODE_NONE;
auto crossingMode = (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS)
&& _trackType == TrackElemType::Flat)
? CreateCrossingMode::trackOverPath
: CreateCrossingMode::none;
auto canBuild = MapCanConstructWithClearAt(
{ mapLoc, baseZ, clearanceZ }, &MapPlaceNonSceneryClearFunc, quarterTile, GetFlags(), crossingMode);
if (canBuild.Error != GameActions::Status::Ok)
Expand Down Expand Up @@ -477,10 +477,10 @@ GameActions::Result TrackPlaceAction::Execute() const
clearanceZ = Floor2(clearanceZ, COORDS_Z_STEP) + baseZ;
const auto mapLocWithClearance = CoordsXYRangedZ(mapLoc, baseZ, clearanceZ);

uint8_t crossingMode = (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS)
&& _trackType == TrackElemType::Flat)
? CREATE_CROSSING_MODE_TRACK_OVER_PATH
: CREATE_CROSSING_MODE_NONE;
auto crossingMode = (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS)
&& _trackType == TrackElemType::Flat)
? CreateCrossingMode::trackOverPath
: CreateCrossingMode::none;
auto canBuild = MapCanConstructWithClearAt(
mapLocWithClearance, &MapPlaceNonSceneryClearFunc, quarterTile, GetFlags() | GAME_COMMAND_FLAG_APPLY, crossingMode);
if (canBuild.Error != GameActions::Status::Ok)
Expand All @@ -491,7 +491,7 @@ GameActions::Result TrackPlaceAction::Execute() const
costs += canBuild.Cost;

// When building a level crossing, remove any pre-existing path furniture.
if (crossingMode == CREATE_CROSSING_MODE_TRACK_OVER_PATH && !(GetFlags() & GAME_COMMAND_FLAG_GHOST))
if (crossingMode == CreateCrossingMode::trackOverPath && !(GetFlags() & GAME_COMMAND_FLAG_GHOST))
{
auto footpathElement = MapGetFootpathElement(mapLoc);
if (footpathElement != nullptr && footpathElement->HasAddition())
Expand Down
14 changes: 7 additions & 7 deletions src/openrct2/world/ConstructionClearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int32_t MapPlaceNonSceneryClearFunc(TileElement** tile_element, const CoordsXY&

static bool MapLoc68BABCShouldContinue(
TileElement** tileElementPtr, const CoordsXYRangedZ& pos, CLEAR_FUNC clearFunc, uint8_t flags, money64& price,
uint8_t crossingMode, bool canBuildCrossing)
CreateCrossingMode crossingMode, bool canBuildCrossing)
{
if (clearFunc != nullptr)
{
Expand All @@ -90,17 +90,16 @@ static bool MapLoc68BABCShouldContinue(
}
}

// Crossing mode 1: building track over path
auto tileElement = *tileElementPtr;
if (crossingMode == 1 && canBuildCrossing && tileElement->GetType() == TileElementType::Path
if (crossingMode == CreateCrossingMode::trackOverPath && canBuildCrossing && tileElement->GetType() == TileElementType::Path
&& tileElement->GetBaseZ() == pos.baseZ && !tileElement->AsPath()->IsQueue() && !tileElement->AsPath()->IsSloped())
{
return true;
}
// Crossing mode 2: building path over track
else if (
crossingMode == 2 && canBuildCrossing && tileElement->GetType() == TileElementType::Track
&& tileElement->GetBaseZ() == pos.baseZ && tileElement->AsTrack()->GetTrackType() == TrackElemType::Flat)
crossingMode == CreateCrossingMode::pathOverTrack && canBuildCrossing
&& tileElement->GetType() == TileElementType::Track && tileElement->GetBaseZ() == pos.baseZ
&& tileElement->AsTrack()->GetTrackType() == TrackElemType::Flat)
{
auto ride = GetRide(tileElement->AsTrack()->GetRideIndex());
if (ride != nullptr && ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SUPPORTS_LEVEL_CROSSINGS))
Expand All @@ -123,7 +122,8 @@ static bool MapLoc68BABCShouldContinue(
* bl = bl
*/
GameActions::Result MapCanConstructWithClearAt(
const CoordsXYRangedZ& pos, CLEAR_FUNC clearFunc, QuarterTile quarterTile, uint8_t flags, uint8_t crossingMode, bool isTree)
const CoordsXYRangedZ& pos, CLEAR_FUNC clearFunc, QuarterTile quarterTile, uint8_t flags, CreateCrossingMode crossingMode,
bool isTree)
{
auto res = GameActions::Result();

Expand Down
12 changes: 11 additions & 1 deletion src/openrct2/world/ConstructionClearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class QuarterTile;

using CLEAR_FUNC = int32_t (*)(TileElement** tile_element, const CoordsXY& coords, uint8_t flags, money64* price);

// Used when calling MapCanConstructWithClearAt();
// This assumes that the caller has already done the check on the element it wants to place,
// as this function can only check the element the player wants to build through.
enum class CreateCrossingMode
{
none,
trackOverPath,
pathOverTrack,
Comment on lines +30 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be TitleCase? I'm confused as to whether this changed recently

Suggested change
none,
trackOverPath,
pathOverTrack,
None,
TrackOverPath,
PathOverTrack,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was recently changed to lowerCamelCase, in line with how OpenLoco does it.

};

int32_t MapPlaceNonSceneryClearFunc(TileElement** tile_element, const CoordsXY& coords, uint8_t flags, money64* price);
int32_t MapPlaceSceneryClearFunc(TileElement** tile_element, const CoordsXY& coords, uint8_t flags, money64* price);

Expand All @@ -32,7 +42,7 @@ struct ConstructClearResult

[[nodiscard]] GameActions::Result MapCanConstructWithClearAt(
const CoordsXYRangedZ& pos, CLEAR_FUNC clearFunc, QuarterTile quarterTile, uint8_t flags,
uint8_t crossingMode = CREATE_CROSSING_MODE_NONE, bool isTree = false);
CreateCrossingMode crossingMode = CreateCrossingMode::none, bool isTree = false);

[[nodiscard]] GameActions::Result MapCanConstructAt(const CoordsXYRangedZ& pos, QuarterTile bl);

Expand Down
10 changes: 0 additions & 10 deletions src/openrct2/world/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,6 @@ enum
MAP_SELECT_TYPE_EDGE_3,
};

// Used when calling MapCanConstructWithClearAt();
// This assumes that the caller has already done the check on the element it wants to place,
// as this function can only check the element the player wants to build through.
enum
{
CREATE_CROSSING_MODE_NONE,
CREATE_CROSSING_MODE_TRACK_OVER_PATH,
CREATE_CROSSING_MODE_PATH_OVER_TRACK,
};

extern const std::array<CoordsXY, 8> CoordsDirectionDelta;
extern const TileCoordsXY TileDirectionDelta[];

Expand Down