diff --git a/src/elrail.cpp b/src/elrail.cpp index bdf4dd7bb2..667cda7815 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -365,7 +365,7 @@ static void DrawRailCatenaryRailway(const TileInfo *ti) ppp_allowed[i].Reset(); } - Foundation foundation = FOUNDATION_NONE; + Foundation foundation = Foundation::None; /* Station and road crossings are always "flat", so adjust the tileh accordingly */ if (IsTileType(neighbour, TileType::Station) || IsTileType(neighbour, TileType::Road)) tileh[TileSource::Neighbour] = SLOPE_FLAT; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 5f717b454e..4e3e4aa722 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -360,7 +360,7 @@ static void DrawTile_Industry(TileInfo *ti) SpriteID image = dits->ground.sprite; /* DrawFoundation() modifies ti->z and ti->tileh */ - if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); + if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, Foundation::Leveled); /* If the ground sprite is the default flat water sprite, draw also canal/river borders. * Do not do this if the tile's WaterClass is 'land'. */ @@ -401,7 +401,7 @@ static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh) const IndustryTileSpec *indts = GetIndustryTileSpec(gfx); if (indts->callback_mask.Test(IndustryTileCallbackMask::DrawFoundations)) { uint32_t callback_res = GetIndustryTileCallback(CBID_INDTILE_DRAW_FOUNDATIONS, 0, 0, gfx, Industry::GetByTile(tile), tile); - if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(indts->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res)) return FOUNDATION_NONE; + if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(indts->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res)) return Foundation::None; } } return FlatteningFoundation(tileh); diff --git a/src/landscape.cpp b/src/landscape.cpp index ee3393f75b..5744cd4bd2 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -187,7 +187,7 @@ uint ApplyFoundationToSlope(Foundation f, Slope &s) return dz; } - if (f != FOUNDATION_STEEP_BOTH && IsNonContinuousFoundation(f)) { + if (f != Foundation::SteepBoth && IsNonContinuousFoundation(f)) { s = HalftileSlope(s, GetHalftileFoundationCorner(f)); return 0; } @@ -201,19 +201,19 @@ uint ApplyFoundationToSlope(Foundation f, Slope &s) Corner highest_corner = GetHighestSlopeCorner(s); switch (f) { - case FOUNDATION_INCLINED_X: + case Foundation::InclinedX: s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE); break; - case FOUNDATION_INCLINED_Y: + case Foundation::InclinedY: s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW); break; - case FOUNDATION_STEEP_LOWER: + case Foundation::SteepLower: s = SlopeWithOneCornerRaised(highest_corner); break; - case FOUNDATION_STEEP_BOTH: + case Foundation::SteepBoth: s = HalftileSlope(SlopeWithOneCornerRaised(highest_corner), highest_corner); break; @@ -437,7 +437,7 @@ void DrawFoundation(TileInfo *ti, Foundation f) if (!IsFoundation(f)) return; /* Two part foundations must be drawn separately */ - assert(f != FOUNDATION_STEEP_BOTH); + assert(f != Foundation::SteepBoth); uint sprite_block = 0; auto [slope, z] = GetFoundationPixelSlope(ti->tile); @@ -468,18 +468,18 @@ void DrawFoundation(TileInfo *ti, Foundation f) if (IsInclinedFoundation(f)) { /* inclined foundation */ - uint8_t inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0); + uint8_t inclined = highest_corner * 2 + (f == Foundation::InclinedY ? 1 : 0); SpriteBounds bounds{{}, {1, 1, TILE_HEIGHT}, {}}; - if (f == FOUNDATION_INCLINED_X) bounds.extent.x = TILE_SIZE; - if (f == FOUNDATION_INCLINED_Y) bounds.extent.y = TILE_SIZE; + if (f == Foundation::InclinedX) bounds.extent.x = TILE_SIZE; + if (f == Foundation::InclinedY) bounds.extent.y = TILE_SIZE; AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, *ti, bounds); OffsetGroundSprite(0, 0); } else if (IsLeveledFoundation(f)) { static constexpr SpriteBounds bounds{{0, 0, -(int)TILE_HEIGHT}, {TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1}, {}}; AddSortableSpriteToDraw(leveled_base + SlopeWithOneCornerRaised(highest_corner), PAL_NONE, *ti, bounds); OffsetGroundSprite(0, -(int)TILE_HEIGHT); - } else if (f == FOUNDATION_STEEP_LOWER) { + } else if (f == Foundation::SteepLower) { /* one corner raised */ OffsetGroundSprite(0, -(int)TILE_HEIGHT); } else { @@ -527,11 +527,11 @@ void DrawFoundation(TileInfo *ti, Foundation f) OffsetGroundSprite(0, 0); } else { /* inclined foundation */ - uint8_t inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0); + uint8_t inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == Foundation::InclinedY ? 1 : 0); SpriteBounds bounds{{}, {1, 1, TILE_HEIGHT}, {}}; - if (f == FOUNDATION_INCLINED_X) bounds.extent.x = TILE_SIZE; - if (f == FOUNDATION_INCLINED_Y) bounds.extent.y = TILE_SIZE; + if (f == Foundation::InclinedX) bounds.extent.x = TILE_SIZE; + if (f == Foundation::InclinedY) bounds.extent.y = TILE_SIZE; AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, *ti, bounds); OffsetGroundSprite(0, 0); } diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp index 79306dd690..7e1a044386 100644 --- a/src/newgrf_airporttiles.cpp +++ b/src/newgrf_airporttiles.cpp @@ -267,7 +267,7 @@ bool DrawNewAirportTile(TileInfo *ti, Station *st, const AirportTileSpec *airts) if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(airts->grf_prop.grffile, CBID_AIRPTILE_DRAW_FOUNDATIONS, callback_res); } - if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED); + if (draw_old_one) DrawFoundation(ti, Foundation::Leveled); } AirportTileResolverObject object(airts, ti->tile, st); diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 03ca7e3f2d..81426db198 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -511,7 +511,7 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id) if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DRAW_FOUNDATIONS, callback_res); } - if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED); + if (draw_old_one) DrawFoundation(ti, Foundation::Leveled); } HouseResolverObject object(house_id, ti->tile, Town::GetByTile(ti->tile)); diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index bd76a9a852..beb6f04446 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -199,7 +199,7 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(inds->grf_prop.grffile, CBID_INDTILE_DRAW_FOUNDATIONS, callback_res); } - if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED); + if (draw_old_one) DrawFoundation(ti, Foundation::Leveled); } IndustryTileResolverObject object(gfx, ti->tile, i); diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index d131914da2..0dfb0a34d0 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -443,7 +443,7 @@ CommandCost CmdBuildObjectArea(DoCommandFlags flags, TileIndex tile, TileIndex s static Foundation GetFoundation_Object(TileIndex tile, Slope tileh) { const ObjectSpec *spec = ObjectSpec::Get(GetObjectType(tile)); - return spec->IsEnabled() && spec->flags.Test(ObjectFlag::HasNoFoundation) ? FOUNDATION_NONE : FlatteningFoundation(tileh); + return spec->IsEnabled() && spec->flags.Test(ObjectFlag::HasNoFoundation) ? Foundation::None : FlatteningFoundation(tileh); } /** @copydoc DrawTileProc */ diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 576a90b6df..d9db192f6c 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -306,16 +306,16 @@ static const TrackBits _valid_tracks_on_leveled_foundation[15] = { * * @param tileh Tile slope. * @param bits Trackbits. - * @return Needed foundation or FOUNDATION_INVALID if track/slope combination is not allowed. + * @return Needed foundation or Foundation::Invalid if track/slope combination is not allowed. */ Foundation GetRailFoundation(Slope tileh, TrackBits bits) { - if (bits == TRACK_BIT_NONE) return FOUNDATION_NONE; + if (bits == TRACK_BIT_NONE) return Foundation::None; if (IsSteepSlope(tileh)) { /* Test for inclined foundations */ - if (bits == TRACK_BIT_X) return FOUNDATION_INCLINED_X; - if (bits == TRACK_BIT_Y) return FOUNDATION_INCLINED_Y; + if (bits == TRACK_BIT_X) return Foundation::InclinedX; + if (bits == TRACK_BIT_Y) return Foundation::InclinedY; /* Get higher track */ Corner highest_corner = GetHighestSlopeCorner(tileh); @@ -325,12 +325,12 @@ Foundation GetRailFoundation(Slope tileh, TrackBits bits) if (bits == higher_track) return HalftileFoundation(highest_corner); /* Overlap with higher track? */ - if (TracksOverlap(bits | higher_track)) return FOUNDATION_INVALID; + if (TracksOverlap(bits | higher_track)) return Foundation::Invalid; /* either lower track or both higher and lower track */ - return ((bits & higher_track) != 0 ? FOUNDATION_STEEP_BOTH : FOUNDATION_STEEP_LOWER); + return ((bits & higher_track) != 0 ? Foundation::SteepBoth : Foundation::SteepLower); } else { - if ((~_valid_tracks_without_foundation[tileh] & bits) == 0) return FOUNDATION_NONE; + if ((~_valid_tracks_without_foundation[tileh] & bits) == 0) return Foundation::None; bool valid_on_leveled = ((~_valid_tracks_on_leveled_foundation[tileh] & bits) == 0); @@ -344,31 +344,31 @@ Foundation GetRailFoundation(Slope tileh, TrackBits bits) case TRACK_BIT_HORZ: if (tileh == SLOPE_N) return HalftileFoundation(CORNER_N); if (tileh == SLOPE_S) return HalftileFoundation(CORNER_S); - return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID); + return (valid_on_leveled ? Foundation::Leveled : Foundation::Invalid); case TRACK_BIT_VERT: if (tileh == SLOPE_W) return HalftileFoundation(CORNER_W); if (tileh == SLOPE_E) return HalftileFoundation(CORNER_E); - return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID); + return (valid_on_leveled ? Foundation::Leveled : Foundation::Invalid); case TRACK_BIT_X: - if (IsSlopeWithOneCornerRaised(tileh)) return FOUNDATION_INCLINED_X; - return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID); + if (IsSlopeWithOneCornerRaised(tileh)) return Foundation::InclinedX; + return (valid_on_leveled ? Foundation::Leveled : Foundation::Invalid); case TRACK_BIT_Y: - if (IsSlopeWithOneCornerRaised(tileh)) return FOUNDATION_INCLINED_Y; - return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID); + if (IsSlopeWithOneCornerRaised(tileh)) return Foundation::InclinedY; + return (valid_on_leveled ? Foundation::Leveled : Foundation::Invalid); default: - return (valid_on_leveled ? FOUNDATION_LEVELED : FOUNDATION_INVALID); + return (valid_on_leveled ? Foundation::Leveled : Foundation::Invalid); } /* Single diagonal track */ /* Track must be at least valid on leveled foundation */ - if (!valid_on_leveled) return FOUNDATION_INVALID; + if (!valid_on_leveled) return Foundation::Invalid; /* If slope has three raised corners, build leveled foundation */ - if (IsSlopeWithThreeCornersRaised(tileh)) return FOUNDATION_LEVELED; + if (IsSlopeWithThreeCornersRaised(tileh)) return Foundation::Leveled; /* If neighboured corners of track_corner are lowered, build halftile foundation */ if ((tileh & SlopeWithThreeCornersRaised(OppositeCorner(track_corner))) == SlopeWithOneCornerRaised(track_corner)) return HalftileFoundation(track_corner); @@ -398,8 +398,8 @@ static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits ex Foundation f_new = GetRailFoundation(tileh, rail_bits | existing); /* check track/slope combination */ - if ((f_new == FOUNDATION_INVALID) || - ((f_new != FOUNDATION_NONE) && (!_settings_game.construction.build_on_slopes))) { + if ((f_new == Foundation::Invalid) || + ((f_new != Foundation::None) && (!_settings_game.construction.build_on_slopes))) { return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); } @@ -2086,10 +2086,10 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailTypeIn if (IsNonContinuousFoundation(f)) { /* Save halftile corner */ - halftile_corner = (f == FOUNDATION_STEEP_BOTH ? GetHighestSlopeCorner(ti->tileh) : GetHalftileFoundationCorner(f)); + halftile_corner = (f == Foundation::SteepBoth ? GetHighestSlopeCorner(ti->tileh) : GetHalftileFoundationCorner(f)); /* Draw lower part first */ track &= ~CornerToTrackBits(halftile_corner); - f = (f == FOUNDATION_STEEP_BOTH ? FOUNDATION_STEEP_LOWER : FOUNDATION_NONE); + f = (f == Foundation::SteepBoth ? Foundation::SteepLower : Foundation::None); } DrawFoundation(ti, f); @@ -2277,10 +2277,10 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track) if (IsNonContinuousFoundation(f)) { /* Save halftile corner */ - halftile_corner = (f == FOUNDATION_STEEP_BOTH ? GetHighestSlopeCorner(ti->tileh) : GetHalftileFoundationCorner(f)); + halftile_corner = (f == Foundation::SteepBoth ? GetHighestSlopeCorner(ti->tileh) : GetHalftileFoundationCorner(f)); /* Draw lower part first */ track &= ~CornerToTrackBits(halftile_corner); - f = (f == FOUNDATION_STEEP_BOTH ? FOUNDATION_STEEP_LOWER : FOUNDATION_NONE); + f = (f == Foundation::SteepBoth ? Foundation::SteepLower : Foundation::None); } DrawFoundation(ti, f); @@ -2472,7 +2472,7 @@ static void DrawTile_Rail(TileInfo *ti) const DrawTileSprites *dts; DiagDirection dir = GetRailDepotDirection(ti->tile); - if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); + if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, Foundation::Leveled); if (IsInvisibilitySet(TransparencyOption::Buildings)) { /* Draw rail instead of depot */ @@ -2649,18 +2649,18 @@ static void TileLoop_Rail(TileIndex tile) Foundation f = GetRailFoundation(slope, track); switch (f) { - case FOUNDATION_NONE: + case Foundation::None: /* no foundation - is the track on the upper side of three corners raised tile? */ if (IsSlopeWithThreeCornersRaised(slope)) z++; break; - case FOUNDATION_INCLINED_X: - case FOUNDATION_INCLINED_Y: + case Foundation::InclinedX: + case Foundation::InclinedY: /* sloped track - is it on a steep slope? */ if (IsSteepSlope(slope)) z++; break; - case FOUNDATION_STEEP_LOWER: + case Foundation::SteepLower: /* only lower part of steep slope */ z++; break; @@ -2672,7 +2672,7 @@ static void TileLoop_Rail(TileIndex tile) break; } - half = IsInsideMM(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1); + half = IsNonContinuousFoundation(f); } else { /* is the depot on a non-flat tile? */ if (slope != SLOPE_FLAT) z++; diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index e31edbac4d..f151b84dba 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -478,7 +478,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlags flags, RoadBits pie CommandCost cost(ExpensesType::Construction, pieces.Count() * RoadClearCost(existing_rt)); /* If we build a foundation we have to pay for it. */ - if (f == FOUNDATION_NONE && GetRoadFoundation(tileh, present) != FOUNDATION_NONE) cost.AddCost(_price[Price::BuildFoundation]); + if (f == Foundation::None && GetRoadFoundation(tileh, present) != Foundation::None) cost.AddCost(_price[Price::BuildFoundation]); return cost; } @@ -583,7 +583,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi return CommandCost(); } } else { - if (existing.Count() == 1 && GetRoadFoundation(tileh, existing) == FOUNDATION_NONE) return CommandCost(ExpensesType::Construction, _price[Price::BuildFoundation]); + if (existing.Count() == 1 && GetRoadFoundation(tileh, existing) == Foundation::None) return CommandCost(ExpensesType::Construction, _price[Price::BuildFoundation]); return CommandCost(); } } @@ -1289,7 +1289,7 @@ struct DrawRoadTileStruct { static Foundation GetRoadFoundation(Slope tileh, RoadBits bits) { /* Flat land and land without a road doesn't require a foundation */ - if (tileh == SLOPE_FLAT || bits.None()) return FOUNDATION_NONE; + if (tileh == SLOPE_FLAT || bits.None()) return Foundation::None; /* Steep slopes behave the same as slopes with one corner raised. */ if (IsSteepSlope(tileh)) { @@ -1297,15 +1297,15 @@ static Foundation GetRoadFoundation(Slope tileh, RoadBits bits) } /* Leveled RoadBits on a slope */ - if (!_invalid_tileh_slopes_road[0][tileh].Any(bits)) return FOUNDATION_LEVELED; + if (!_invalid_tileh_slopes_road[0][tileh].Any(bits)) return Foundation::Leveled; /* Straight roads without foundation on a slope */ if (!IsSlopeWithOneCornerRaised(tileh) && !_invalid_tileh_slopes_road[1][tileh].Any(bits)) - return FOUNDATION_NONE; + return Foundation::None; /* Roads on steep Slopes or on Slopes with one corner raised */ - return (bits == ROAD_X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y); + return (bits == ROAD_X ? Foundation::InclinedX : Foundation::InclinedY); } const uint8_t _road_sloped_sprites[14] = { @@ -1723,7 +1723,7 @@ static void DrawTile_Road(TileInfo *ti) break; case RoadTileType::Crossing: { - if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); + if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, Foundation::Leveled); Axis axis = GetCrossingRailAxis(ti->tile); @@ -1845,7 +1845,7 @@ static void DrawTile_Road(TileInfo *ti) default: case RoadTileType::Depot: { - if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); + if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, Foundation::Leveled); PaletteID palette = GetCompanyPalette(GetTileOwner(ti->tile)); diff --git a/src/slope_func.h b/src/slope_func.h index f478559720..eaa3d0c762 100644 --- a/src/slope_func.h +++ b/src/slope_func.h @@ -279,14 +279,14 @@ static constexpr inline Slope HalftileSlope(Slope s, Corner corner) /** - * Tests for FOUNDATION_NONE. + * Tests whether the given foundation is a foundation. * * @param f Maybe a #Foundation. * @return true iff f is a foundation. */ inline bool IsFoundation(Foundation f) { - return f != FOUNDATION_NONE; + return f != Foundation::None; } /** @@ -297,7 +297,7 @@ inline bool IsFoundation(Foundation f) */ inline bool IsLeveledFoundation(Foundation f) { - return f == FOUNDATION_LEVELED; + return f == Foundation::Leveled; } /** @@ -308,32 +308,32 @@ inline bool IsLeveledFoundation(Foundation f) */ inline bool IsInclinedFoundation(Foundation f) { - return (f == FOUNDATION_INCLINED_X) || (f == FOUNDATION_INCLINED_Y); + return (f == Foundation::InclinedX) || (f == Foundation::InclinedY); } /** - * Tests if a foundation is a non-continuous foundation, i.e. halftile-foundation or FOUNDATION_STEEP_BOTH. + * Tests if a foundation is a non-continuous foundation, i.e. halftile-foundation or Foundation::SteepBoth. * * @param f The #Foundation. * @return true iff f is a non-continuous foundation */ inline bool IsNonContinuousFoundation(Foundation f) { - return IsInsideMM(f, FOUNDATION_STEEP_BOTH, FOUNDATION_HALFTILE_N + 1); + return IsInsideMM(f, Foundation::SteepBoth, Foundation::HalfTileEnd); } /** * Returns the halftile corner of a halftile-foundation * - * @pre f != FOUNDATION_STEEP_BOTH + * @pre f != Foundation::SteepBoth * * @param f The #Foundation. * @return The #Corner with track. */ inline Corner GetHalftileFoundationCorner(Foundation f) { - assert(IsInsideMM(f, FOUNDATION_HALFTILE_W, FOUNDATION_HALFTILE_N + 1)); - return (Corner)(f - FOUNDATION_HALFTILE_W); + assert(IsInsideMM(f, Foundation::HalfTileW, Foundation::HalfTileEnd)); + return static_cast(to_underlying(f) - to_underlying(Foundation::HalfTileW)); } /** @@ -344,7 +344,7 @@ inline Corner GetHalftileFoundationCorner(Foundation f) */ inline bool IsSpecialRailFoundation(Foundation f) { - return IsInsideMM(f, FOUNDATION_RAIL_W, FOUNDATION_RAIL_N + 1); + return IsInsideMM(f, Foundation::RailW, Foundation::End); } /** @@ -356,19 +356,17 @@ inline bool IsSpecialRailFoundation(Foundation f) inline Corner GetRailFoundationCorner(Foundation f) { assert(IsSpecialRailFoundation(f)); - return (Corner)(f - FOUNDATION_RAIL_W); + return static_cast(to_underlying(f) - to_underlying(Foundation::RailW)); } /** * Returns the foundation needed to flatten a slope. - * The returned foundation is either FOUNDATION_NONE if the tile was already flat, or FOUNDATION_LEVELED. - * * @param s The current #Slope. - * @return The needed #Foundation. + * @return Either Foundation::None if the tile was already flat, or Foundation::Leveled. */ inline Foundation FlatteningFoundation(Slope s) { - return (s == SLOPE_FLAT ? FOUNDATION_NONE : FOUNDATION_LEVELED); + return (s == SLOPE_FLAT ? Foundation::None : Foundation::Leveled); } /** @@ -379,7 +377,7 @@ inline Foundation FlatteningFoundation(Slope s) */ inline Foundation InclinedFoundation(Axis axis) { - return (axis == Axis::X ? FOUNDATION_INCLINED_X : FOUNDATION_INCLINED_Y); + return (axis == Axis::X ? Foundation::InclinedX : Foundation::InclinedY); } /** @@ -391,7 +389,7 @@ inline Foundation InclinedFoundation(Axis axis) inline Foundation HalftileFoundation(Corner corner) { assert(IsValidCorner(corner)); - return static_cast(static_cast(FOUNDATION_HALFTILE_W) + static_cast(corner)); + return static_cast(static_cast(Foundation::HalfTileW) + static_cast(corner)); } /** @@ -403,7 +401,7 @@ inline Foundation HalftileFoundation(Corner corner) inline Foundation SpecialRailFoundation(Corner corner) { assert(IsValidCorner(corner)); - return static_cast(static_cast(FOUNDATION_RAIL_W) + static_cast(corner)); + return static_cast(static_cast(Foundation::RailW) + static_cast(corner)); } /** diff --git a/src/slope_type.h b/src/slope_type.h index 2cf2001dcf..cdd79a4905 100644 --- a/src/slope_type.h +++ b/src/slope_type.h @@ -95,27 +95,29 @@ static const uint32_t VALID_LEVEL_CROSSING_SLOPES = M(SLOPE_SEN) | M(SLOPE_ENW) /** * Enumeration for Foundations. */ -enum Foundation : uint8_t { - FOUNDATION_NONE, ///< The tile has no foundation, the slope remains unchanged. - FOUNDATION_LEVELED, ///< The tile is leveled up to a flat slope. - FOUNDATION_INCLINED_X, ///< The tile has an along X-axis inclined foundation. - FOUNDATION_INCLINED_Y, ///< The tile has an along Y-axis inclined foundation. - FOUNDATION_STEEP_LOWER, ///< The tile has a steep slope. The lowest corner is raised by a foundation to allow building railroad on the lower halftile. +enum class Foundation : uint8_t { + None, ///< The tile has no foundation, the slope remains unchanged. + Leveled, ///< The tile is leveled up to a flat slope. + InclinedX, ///< The tile has an along X-axis inclined foundation. + InclinedY, ///< The tile has an along Y-axis inclined foundation. + SteepLower, ///< The tile has a steep slope. The lowest corner is raised by a foundation to allow building railroad on the lower halftile. /* Halftile foundations */ - FOUNDATION_STEEP_BOTH, ///< The tile has a steep slope. The lowest corner is raised by a foundation and the upper halftile is leveled. - FOUNDATION_HALFTILE_W, ///< Level west halftile non-continuously. - FOUNDATION_HALFTILE_S, ///< Level south halftile non-continuously. - FOUNDATION_HALFTILE_E, ///< Level east halftile non-continuously. - FOUNDATION_HALFTILE_N, ///< Level north halftile non-continuously. + SteepBoth, ///< The tile has a steep slope. The lowest corner is raised by a foundation and the upper halftile is leveled. + HalfTileW, ///< Level west halftile non-continuously. + HalfTileS, ///< Level south halftile non-continuously. + HalfTileE, ///< Level east halftile non-continuously. + HalfTileN, ///< Level north halftile non-continuously. + HalfTileEnd, ///< End marker for halftile foundations. /* Special anti-zig-zag foundations for single horizontal/vertical track */ - FOUNDATION_RAIL_W, ///< Foundation for TRACK_BIT_LEFT, but not a leveled foundation. - FOUNDATION_RAIL_S, ///< Foundation for TRACK_BIT_LOWER, but not a leveled foundation. - FOUNDATION_RAIL_E, ///< Foundation for TRACK_BIT_RIGHT, but not a leveled foundation. - FOUNDATION_RAIL_N, ///< Foundation for TRACK_BIT_UPPER, but not a leveled foundation. + RailW = Foundation::HalfTileEnd, ///< Foundation for TRACK_BIT_LEFT, but not a leveled foundation. + RailS, ///< Foundation for TRACK_BIT_LOWER, but not a leveled foundation. + RailE, ///< Foundation for TRACK_BIT_RIGHT, but not a leveled foundation. + RailN, ///< Foundation for TRACK_BIT_UPPER, but not a leveled foundation. + End, ///< End marker. - FOUNDATION_INVALID = 0xFF, ///< Used inside "rail_cmd.cpp" to indicate invalid slope/track combination. + Invalid = 0xFF, ///< Used inside "rail_cmd.cpp" to indicate invalid slope/track combination. }; #endif /* SLOPE_TYPE_H */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 6c852193e0..51c9613d0e 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3268,7 +3268,7 @@ static bool DrawCustomStationFoundations(const StationSpec *statspec, BaseStatio } OffsetGroundSprite(0, -static_cast(TILE_HEIGHT)); - ti->z += ApplyPixelFoundationToSlope(FOUNDATION_LEVELED, ti->tileh); + ti->z += ApplyPixelFoundationToSlope(Foundation::Leveled, ti->tileh); return true; } @@ -3368,7 +3368,7 @@ static void DrawTile_Station(TileInfo *ti) /* don't show foundation for docks */ if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) { if (!DrawCustomStationFoundations(statspec, st, ti, tile_layout)) { - DrawFoundation(ti, FOUNDATION_LEVELED); + DrawFoundation(ti, Foundation::Leveled); } } @@ -3401,7 +3401,7 @@ static void DrawTile_Station(TileInfo *ti) const RoadTypeInfo *tram_rti = (tram_rt != INVALID_ROADTYPE) ? GetRoadTypeInfo(tram_rt) : nullptr; if (ti->tileh != SLOPE_FLAT) { - DrawFoundation(ti, FOUNDATION_LEVELED); + DrawFoundation(ti, Foundation::Leveled); } DrawRoadGroundSprites(ti, road, tram, road_rti, tram_rti, GetRoadWaypointRoadside(ti->tile), IsRoadWaypointOnSnowOrDesert(ti->tile)); diff --git a/src/tile_cmd.h b/src/tile_cmd.h index 51955cde57..ff8aea8710 100644 --- a/src/tile_cmd.h +++ b/src/tile_cmd.h @@ -223,7 +223,7 @@ struct TileTypeProcs { ChangeTileOwnerProc *change_tile_owner_proc = [](TileIndex, CompanyID, CompanyID) {}; ///< Called to change the ownership of elements on a tile. AddProducedCargoProc *add_produced_cargo_proc = nullptr; ///< Adds produced cargo of the tile to cargo array supplied as parameter. VehicleEnterTileProc *vehicle_enter_tile_proc = nullptr; ///< Called when a vehicle enters a tile. - GetFoundationProc *get_foundation_proc = [](TileIndex, Slope) { return FOUNDATION_NONE; }; ///< Called to get the foundation. + GetFoundationProc *get_foundation_proc = [](TileIndex, Slope) { return Foundation::None; }; ///< Called to get the foundation. TerraformTileProc *terraform_tile_proc; ///< Called when a terraforming operation is about to take place. CheckBuildAboveProc *check_build_above_proc = nullptr; ///< Called to check whether a bridge can be build above. }; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 6f9483abc2..3de8130904 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -278,7 +278,7 @@ static void DrawTile_Town(TileInfo *ti) /* Retrieve pointer to the draw town tile struct */ const DrawBuildingsTileStruct *dcts = &_town_draw_tile_data[house_id << 4 | TileHash2Bit(ti->x, ti->y) << 2 | GetHouseBuildingStage(ti->tile)]; - if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); + if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, Foundation::Leveled); DrawGroundSprite(dcts->ground.sprite, dcts->ground.pal); @@ -313,7 +313,7 @@ static Foundation GetFoundation_Town(TileIndex tile, Slope tileh) const HouseSpec *hs = HouseSpec::Get(hid); if (hs->callback_mask.Test(HouseCallbackMask::DrawFoundations)) { uint32_t callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, hid, Town::GetByTile(tile), tile); - if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DRAW_FOUNDATIONS, callback_res)) return FOUNDATION_NONE; + if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DRAW_FOUNDATIONS, callback_res)) return Foundation::None; } } return FlatteningFoundation(tileh); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 91f3df3aaa..af1907410e 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -115,7 +115,7 @@ Foundation GetBridgeFoundation(Slope tileh, Axis axis) { if (tileh == SLOPE_FLAT || ((tileh == SLOPE_NE || tileh == SLOPE_SW) && axis == Axis::X) || - ((tileh == SLOPE_NW || tileh == SLOPE_SE) && axis == Axis::Y)) return FOUNDATION_NONE; + ((tileh == SLOPE_NW || tileh == SLOPE_SE) && axis == Axis::Y)) return Foundation::None; return (HasSlopeHighestCorner(tileh) ? InclinedFoundation(axis) : FlatteningFoundation(tileh)); } @@ -224,7 +224,7 @@ static CommandCost CheckBridgeSlope(BridgePieces bridge_piece, Axis axis, Slope } if ((tileh != SLOPE_FLAT) && (tileh != valid_inclined)) return CMD_ERROR; - if (f == FOUNDATION_NONE) return CommandCost(); + if (f == Foundation::None) return CommandCost(); return CommandCost(ExpensesType::Construction, _price[Price::BuildFoundation]); } @@ -1750,7 +1750,7 @@ static int GetSlopePixelZ_TunnelBridge(TileIndex tile, uint x, uint y, bool grou /** @copydoc GetFoundationProc */ static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh) { - return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile))); + return IsTunnel(tile) ? Foundation::None : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile))); } /** @copydoc GetTileDescProc */