diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 04b428376f..94bd5aa823 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1009,7 +1009,7 @@ static bool IsSuitableForFarmField(TileIndex tile, bool allow_fields, bool allow case ClearGround::Fields: return allow_fields; default: return true; } - case TileType::Trees: return GetTreeGround(tile) != TREE_GROUND_SHORE && (allow_rough || GetTreeGround(tile) != TREE_GROUND_ROUGH); + case TileType::Trees: return GetTreeGround(tile) != TreeGround::Shore && (allow_rough || GetTreeGround(tile) != TreeGround::Rough); default: return false; } } diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index 7558639e16..31601dff09 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -361,7 +361,7 @@ uint32_t GetTerrainType(TileIndex tile, TileContext context) /* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */ if (_generating_world) goto genworld; TreeGround ground = GetTreeGround(tile); - has_snow = (ground == TREE_GROUND_SNOW_DESERT || ground == TREE_GROUND_ROUGH_SNOW) && GetTreeDensity(tile) >= 2; + has_snow = (ground == TreeGround::SnowOrDesert || ground == TreeGround::RoughSnow) && GetTreeDensity(tile) >= 2; break; } @@ -433,7 +433,7 @@ uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8) TileType tile_type = GetTileType(tile); /* Fake tile type for trees on shore */ - if (IsTileType(tile, TileType::Trees) && GetTreeGround(tile) == TREE_GROUND_SHORE) tile_type = TileType::Water; + if (IsTileType(tile, TileType::Trees) && GetTreeGround(tile) == TreeGround::Shore) tile_type = TileType::Water; /* Fake tile type for road waypoints */ if (IsRoadWaypointTile(tile)) tile_type = TileType::Road; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index f701a2585b..0853c57fdc 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -138,7 +138,7 @@ void SetWaterClassDependingOnSurroundings(Tile t, bool include_invalid_water_cla case TileType::Trees: /* trees on shore */ - has_water |= (GB(neighbour.m2(), 4, 2) == TREE_GROUND_SHORE); + has_water |= (static_cast(GB(neighbour.m2(), 4, 2)) == TreeGround::Shore); break; default: break; @@ -1805,7 +1805,7 @@ bool AfterLoadGame() for (auto t : Map::Iterate()) { if (GetTileType(t) == TileType::Trees) { TreeGround ground_type = (TreeGround)GB(t.m2(), 4, 2); - if (ground_type != TREE_GROUND_SNOW_DESERT) SB(t.m2(), 6, 2, 3); + if (ground_type != TreeGround::SnowOrDesert) SB(t.m2(), 6, 2, 3); } } } @@ -3216,7 +3216,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_TREES_WATER_CLASS)) { /* Update water class for trees. */ for (const auto t : Map::Iterate()) { - if (IsTileType(t, TileType::Trees)) SetWaterClass(t, GetTreeGround(t) == TREE_GROUND_SHORE ? WaterClass::Sea : WaterClass::Invalid); + if (IsTileType(t, TileType::Trees)) SetWaterClass(t, GetTreeGround(t) == TreeGround::Shore ? WaterClass::Sea : WaterClass::Invalid); } } diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp index 2c85173da9..8235831e55 100644 --- a/src/script/api/script_tile.cpp +++ b/src/script/api/script_tile.cpp @@ -88,7 +88,7 @@ if (!::IsValidTile(tile)) return false; return (::IsTileType(tile, TileType::Water) && ::IsCoast(tile)) || - (::IsTileType(tile, TileType::Trees) && ::GetTreeGround(tile) == TREE_GROUND_SHORE); + (::IsTileType(tile, TileType::Trees) && ::GetTreeGround(tile) == TreeGround::Shore); } /* static */ bool ScriptTile::IsStationTile(TileIndex tile) diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index cecfa3ca23..2f039c512d 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -560,7 +560,7 @@ static inline uint32_t GetSmallMapVegetationPixels(TileIndex tile, TileType t) return IsTileForestIndustry(tile) ? MKCOLOUR_XXXX(PC_GREEN) : MKCOLOUR_XXXX(PC_DARK_RED); case TileType::Trees: - if (GetTreeGround(tile) == TREE_GROUND_SNOW_DESERT || GetTreeGround(tile) == TREE_GROUND_ROUGH_SNOW) { + if (GetTreeGround(tile) == TreeGround::SnowOrDesert || GetTreeGround(tile) == TreeGround::RoughSnow) { return (_settings_game.game_creation.landscape == LandscapeType::Arctic) ? MKCOLOUR_XYYX(PC_LIGHT_BLUE, PC_TREES) : MKCOLOUR_XYYX(PC_ORANGE, PC_TREES); } return (GetTropicZone(tile) == TROPICZONE_RAINFOREST) ? MKCOLOUR_XYYX(PC_RAINFOREST, PC_TREES) : MKCOLOUR_XYYX(PC_GRASS_LAND, PC_TREES); diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 9b8f6a38dd..632feaf5c6 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -83,7 +83,7 @@ static void GenerateRockyArea(TileIndex end, TileIndex start) for (TileIndex tile : ta) { switch (GetTileType(tile)) { case TileType::Trees: - if (GetTreeGround(tile) == TREE_GROUND_SHORE) continue; + if (GetTreeGround(tile) == TreeGround::Shore) continue; [[fallthrough]]; case TileType::Clear: diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 7e6b1ff456..f99e69ee68 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2156,7 +2156,7 @@ static CommandCost TownCanBePlacedHere(TileIndex tile, bool check_surrounding) case TileType::Trees: /* Don't allow rough trees, as they are likely wetlands. */ - if (GetTreeGround(t) == TREE_GROUND_ROUGH) continue; + if (GetTreeGround(t) == TreeGround::Rough) continue; break; default: diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index e814b6051a..7bc83d734a 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -70,6 +70,20 @@ static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert) } } +/** + * Get equivalent TreeGround for a ClearGround. + * @param clearground The ClearGround. + * @return Equivalent TreeGround. + */ +static TreeGround TreeGroundFromClearGround(ClearGround clearground) +{ + switch (clearground) { + case ClearGround::Grass: return TreeGround::Grass; + case ClearGround::Rough: return TreeGround::Rough; + default: return TreeGround::SnowOrDesert; + } +} + /** * Creates a tree tile * Ground type and density is preserved. @@ -91,20 +105,16 @@ static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, Tree switch (GetTileType(tile)) { case TileType::Water: - ground = TREE_GROUND_SHORE; + ground = TreeGround::Shore; ClearNeighbourNonFloodingStates(tile); break; case TileType::Clear: { ClearGround clearground = GetClearGround(tile); if (IsSnowTile(tile)) { - ground = clearground == ClearGround::Rough ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT; + ground = clearground == ClearGround::Rough ? TreeGround::RoughSnow : TreeGround::SnowOrDesert; } else { - switch (clearground) { - case ClearGround::Grass: ground = TREE_GROUND_GRASS; break; - case ClearGround::Rough: ground = TREE_GROUND_ROUGH; break; - default: ground = TREE_GROUND_SNOW_DESERT; break; - } + ground = TreeGroundFromClearGround(clearground); } if (clearground != ClearGround::Rough) density = GetClearDensity(tile); break; @@ -171,7 +181,7 @@ void PlaceTree(TileIndex tile, uint32_t r, bool keep_density) /* Rerandomize ground, if neither snow nor shore */ TreeGround ground = GetTreeGround(tile); - if (ground != TREE_GROUND_SNOW_DESERT && ground != TREE_GROUND_ROUGH_SNOW && ground != TREE_GROUND_SHORE) { + if (ground != TreeGround::SnowOrDesert && ground != TreeGround::RoughSnow && ground != TreeGround::Shore) { SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 3); } } @@ -634,9 +644,9 @@ struct TreeListEnt : PalSpriteID { static void DrawTile_Trees(TileInfo *ti) { switch (GetTreeGround(ti->tile)) { - case TREE_GROUND_SHORE: DrawShoreTile(ti->tileh); break; - case TREE_GROUND_GRASS: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break; - case TREE_GROUND_ROUGH: DrawHillyLandTile(ti); break; + case TreeGround::Shore: DrawShoreTile(ti->tileh); break; + case TreeGround::Grass: DrawClearLandTile(ti, GetTreeDensity(ti->tile)); break; + case TreeGround::Rough: DrawHillyLandTile(ti); break; default: DrawGroundSprite(_clear_land_sprites_snow_desert[GetTreeDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; } @@ -647,7 +657,7 @@ static void DrawTile_Trees(TileInfo *ti) uint index = GB(tmp, 0, 2) + (GetTreeType(ti->tile) << 2); /* different tree styles above one of the grounds */ - if ((GetTreeGround(ti->tile) == TREE_GROUND_SNOW_DESERT || GetTreeGround(ti->tile) == TREE_GROUND_ROUGH_SNOW) && + if ((GetTreeGround(ti->tile) == TreeGround::SnowOrDesert || GetTreeGround(ti->tile) == TreeGround::RoughSnow) && GetTreeDensity(ti->tile) >= 2 && IsInsideMM(index, TREE_SUB_ARCTIC << 2, TREE_RAINFOREST << 2)) { index += 164 - (TREE_SUB_ARCTIC << 2); @@ -749,8 +759,8 @@ static void TileLoopTreesDesert(TileIndex tile) { switch (GetTropicZone(tile)) { case TROPICZONE_DESERT: - if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) { - SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3); + if (GetTreeGround(tile) != TreeGround::SnowOrDesert) { + SetTreeGroundDensity(tile, TreeGround::SnowOrDesert, 3); MarkTileDirtyByTile(tile); } break; @@ -778,15 +788,15 @@ static void TileLoopTreesAlps(TileIndex tile) if (k < 0) { switch (GetTreeGround(tile)) { - case TREE_GROUND_SNOW_DESERT: SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3); break; - case TREE_GROUND_ROUGH_SNOW: SetTreeGroundDensity(tile, TREE_GROUND_ROUGH, 3); break; + case TreeGround::SnowOrDesert: SetTreeGroundDensity(tile, TreeGround::Grass, 3); break; + case TreeGround::RoughSnow: SetTreeGroundDensity(tile, TreeGround::Rough, 3); break; default: return; } } else { uint density = std::min(k, 3); - if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT && GetTreeGround(tile) != TREE_GROUND_ROUGH_SNOW) { - TreeGround tg = GetTreeGround(tile) == TREE_GROUND_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT; + if (GetTreeGround(tile) != TreeGround::SnowOrDesert && GetTreeGround(tile) != TreeGround::RoughSnow) { + TreeGround tg = GetTreeGround(tile) == TreeGround::Rough ? TreeGround::RoughSnow : TreeGround::SnowOrDesert; SetTreeGroundDensity(tile, tg, density); } else if (GetTreeDensity(tile) != density) { SetTreeGroundDensity(tile, GetTreeGround(tile), density); @@ -829,7 +839,7 @@ static bool TreesOnTileCanSpread(TileIndex tile) static void TileLoop_Trees(TileIndex tile) { - if (GetTreeGround(tile) == TREE_GROUND_SHORE) { + if (GetTreeGround(tile) == TreeGround::Shore) { TileLoop_Water(tile); } else { switch (_settings_game.game_creation.landscape) { @@ -848,10 +858,10 @@ static void TileLoop_Trees(TileIndex tile) uint32_t cycle = 11 * TileX(tile) + 9 * TileY(tile) + (TimerGameTick::counter >> 8); /* Handle growth of grass (under trees/on TileType::Trees tiles) at every 8th processings, like it's done for grass on TileType::Clear tiles. */ - if ((cycle & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) { + if ((cycle & 7) == 7 && GetTreeGround(tile) == TreeGround::Grass) { uint density = GetTreeDensity(tile); if (density < 3) { - SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1); + SetTreeGroundDensity(tile, TreeGround::Grass, density + 1); MarkTileDirtyByTile(tile); } } @@ -915,10 +925,10 @@ static void TileLoop_Trees(TileIndex tile) } else { /* just one tree, change type into TileType::Clear */ switch (GetTreeGround(tile)) { - case TREE_GROUND_SHORE: MakeShore(tile); break; - case TREE_GROUND_GRASS: MakeClear(tile, ClearGround::Grass, GetTreeDensity(tile)); break; - case TREE_GROUND_ROUGH: MakeClear(tile, ClearGround::Rough, 3); break; - case TREE_GROUND_ROUGH_SNOW: { + case TreeGround::Shore: MakeShore(tile); break; + case TreeGround::Grass: MakeClear(tile, ClearGround::Grass, GetTreeDensity(tile)); break; + case TreeGround::Rough: MakeClear(tile, ClearGround::Rough, 3); break; + case TreeGround::RoughSnow: { uint density = GetTreeDensity(tile); MakeClear(tile, ClearGround::Rough, 3); MakeSnow(tile, density); diff --git a/src/tree_map.h b/src/tree_map.h index 3d9f127955..4f72c35dfa 100644 --- a/src/tree_map.h +++ b/src/tree_map.h @@ -49,12 +49,12 @@ static const uint TREE_COUNT_TOYLAND = 9; * * This enumeration defines the ground types for tiles with trees on it. */ -enum TreeGround : uint8_t { - TREE_GROUND_GRASS = 0, ///< normal grass - TREE_GROUND_ROUGH = 1, ///< some rough tile - TREE_GROUND_SNOW_DESERT = 2, ///< a desert or snow tile, depend on landscape - TREE_GROUND_SHORE = 3, ///< shore - TREE_GROUND_ROUGH_SNOW = 4, ///< A snow tile that is rough underneath. +enum class TreeGround : uint8_t { + Grass = 0, ///< Normal grass. + Rough = 1, ///< Rough land. + SnowOrDesert = 2, ///< Snow or desert, depending on landscape. + Shore = 3, ///< Shore. + RoughSnow = 4, ///< A snow tile that is rough underneath. }; /** @@ -145,8 +145,8 @@ inline void SetTreeGroundDensity(Tile t, TreeGround g, uint d) { assert(IsTileType(t, TileType::Trees)); // XXX incomplete SB(t.m2(), 4, 2, d); - SB(t.m2(), 6, 3, g); - SetWaterClass(t, g == TREE_GROUND_SHORE ? WaterClass::Sea : WaterClass::Invalid); + SB(t.m2(), 6, 3, to_underlying(g)); + SetWaterClass(t, g == TreeGround::Shore ? WaterClass::Sea : WaterClass::Invalid); } /** @@ -245,8 +245,8 @@ inline void MakeTree(Tile t, TreeType type, uint count, TreeGrowthStage growth, { SetTileType(t, TileType::Trees); SetTileOwner(t, OWNER_NONE); - SetWaterClass(t, ground == TREE_GROUND_SHORE ? WaterClass::Sea : WaterClass::Invalid); - t.m2() = ground << 6 | density << 4 | 0; + SetWaterClass(t, ground == TreeGround::Shore ? WaterClass::Sea : WaterClass::Invalid); + t.m2() = to_underlying(ground) << 6 | density << 4 | 0; t.m3() = type; t.m4() = 0 << 5 | 0 << 2; t.m5() = count << 6 | to_underlying(growth); diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index ab7585df2c..0a6c60b6e3 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -1149,7 +1149,7 @@ FloodingBehaviour GetFloodingBehaviour(TileIndex tile) return FLOOD_NONE; case TileType::Trees: - return (GetTreeGround(tile) == TREE_GROUND_SHORE ? FLOOD_DRYUP : FLOOD_NONE); + return (GetTreeGround(tile) == TreeGround::Shore ? FLOOD_DRYUP : FLOOD_NONE); case TileType::Void: return FLOOD_ACTIVE; @@ -1183,7 +1183,7 @@ static void DoFloodTile(TileIndex target) case TileType::Trees: if (!IsSlopeWithOneCornerRaised(tileh)) { - SetTreeGroundDensity(target, TREE_GROUND_SHORE, 3); + SetTreeGroundDensity(target, TreeGround::Shore, 3); MarkTileDirtyByTile(target); flooded = true; break; @@ -1252,7 +1252,7 @@ static void DoDryUp(TileIndex tile) break; case TileType::Trees: - SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 3); + SetTreeGroundDensity(tile, TreeGround::Grass, 3); MarkTileDirtyByTile(tile); break; @@ -1300,8 +1300,8 @@ void TileLoop_Water(TileIndex tile) /* This neighbour tile might be floodable later if the tile is cleared, so allow flooding to continue. */ continue_flooding = true; - /* TREE_GROUND_SHORE is the sign of a previous flood. */ - if (IsTileType(dest, TileType::Trees) && GetTreeGround(dest) == TREE_GROUND_SHORE) continue; + /* TreeGround::Shore is the sign of a previous flood. */ + if (IsTileType(dest, TileType::Trees) && GetTreeGround(dest) == TreeGround::Shore) continue; auto [slope_dest, z_dest] = GetFoundationSlope(dest); if (z_dest > 0) continue;