diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp index 1fde49f6a7..8c4f0bb2d1 100644 --- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -25,7 +25,7 @@ static CommandCost ClearTile_Clear(TileIndex tile, DoCommandFlags flags) { - static const Price clear_price_table[] = { + static constexpr Price clear_price_table[] = { PR_CLEAR_GRASS, PR_CLEAR_ROUGH, PR_CLEAR_ROCKS, @@ -35,7 +35,9 @@ static CommandCost ClearTile_Clear(TileIndex tile, DoCommandFlags flags) }; CommandCost price(EXPENSES_CONSTRUCTION); - if (!IsClearGround(tile, CLEAR_GRASS) || GetClearDensity(tile) != 0) { + if (IsSnowTile(tile)) { + price.AddCost(_price[clear_price_table[CLEAR_SNOW]]); + } else if (!IsClearGround(tile, CLEAR_GRASS) || GetClearDensity(tile) != 0) { price.AddCost(_price[clear_price_table[GetClearGround(tile)]]); } @@ -100,7 +102,9 @@ static void DrawClearLandFence(const TileInfo *ti) static void DrawTile_Clear(TileInfo *ti) { - switch (GetClearGround(ti->tile)) { + ClearGround ground = IsSnowTile(ti->tile) ? CLEAR_SNOW : GetClearGround(ti->tile); + + switch (ground) { case CLEAR_GRASS: DrawClearLandTile(ti, GetClearDensity(ti->tile)); break; @@ -237,6 +241,8 @@ static void TileLoop_Clear(TileIndex tile) default: break; } + if (IsSnowTile(tile)) return; + switch (GetClearGround(tile)) { case CLEAR_GRASS: if (GetClearDensity(tile) == 3) return; diff --git a/src/clear_map.h b/src/clear_map.h index 765a8d60d1..a1a58612ce 100644 --- a/src/clear_map.h +++ b/src/clear_map.h @@ -21,7 +21,7 @@ enum ClearGround : uint8_t { CLEAR_ROUGH = 1, ///< 3 CLEAR_ROCKS = 2, ///< 3 CLEAR_FIELDS = 3, ///< 3 - CLEAR_SNOW = 4, ///< 0-3 + CLEAR_SNOW = 4, ///< 0-3 (Not stored in map.) CLEAR_DESERT = 5, ///< 1,3 }; @@ -38,18 +38,6 @@ inline bool IsSnowTile(Tile t) return HasBit(t.m3(), 4); } -/** - * Get the type of clear tile but never return CLEAR_SNOW. - * @param t the tile to get the clear ground type of - * @pre IsTileType(t, MP_CLEAR) - * @return the ground type - */ -inline ClearGround GetRawClearGround(Tile t) -{ - assert(IsTileType(t, MP_CLEAR)); - return (ClearGround)GB(t.m5(), 2, 3); -} - /** * Get the type of clear tile. * @param t the tile to get the clear ground type of @@ -58,8 +46,8 @@ inline ClearGround GetRawClearGround(Tile t) */ inline ClearGround GetClearGround(Tile t) { - if (IsSnowTile(t)) return CLEAR_SNOW; - return GetRawClearGround(t); + assert(IsTileType(t, MP_CLEAR)); + return static_cast(GB(t.m5(), 2, 3)); } /** @@ -295,13 +283,13 @@ inline void MakeField(Tile t, uint field_type, IndustryID industry) * Make a snow tile. * @param t the tile to make snowy * @param density The density of snowiness. - * @pre GetClearGround(t) != CLEAR_SNOW + * @pre !IsSnowTile(t) */ inline void MakeSnow(Tile t, uint density = 0) { - assert(GetClearGround(t) != CLEAR_SNOW); + assert(!IsSnowTile(t)); SetBit(t.m3(), 4); - if (GetRawClearGround(t) == CLEAR_FIELDS) { + if (GetClearGround(t) == CLEAR_FIELDS) { SetClearGroundDensity(t, CLEAR_GRASS, density); } else { SetClearDensity(t, density); @@ -311,11 +299,11 @@ inline void MakeSnow(Tile t, uint density = 0) /** * Clear the snow from a tile and return it to its previous type. * @param t the tile to clear of snow - * @pre GetClearGround(t) == CLEAR_SNOW + * @pre IsSnowTile(t) */ inline void ClearSnow(Tile t) { - assert(GetClearGround(t) == CLEAR_SNOW); + assert(IsSnowTile(t)); ClrBit(t.m3(), 4); SetClearDensity(t, 3); } diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index f10f9d421b..28804931d8 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1004,7 +1004,7 @@ static const uint8_t _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, static bool IsSuitableForFarmField(TileIndex tile, bool allow_fields) { switch (GetTileType(tile)) { - case MP_CLEAR: return !IsClearGround(tile, CLEAR_SNOW) && !IsClearGround(tile, CLEAR_DESERT) && (allow_fields || !IsClearGround(tile, CLEAR_FIELDS)); + case MP_CLEAR: return !IsSnowTile(tile) && !IsClearGround(tile, CLEAR_DESERT) && (allow_fields || !IsClearGround(tile, CLEAR_FIELDS)); case MP_TREES: return GetTreeGround(tile) != TREE_GROUND_SHORE; default: return false; } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 007d5f7c22..3eb2787c2b 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -633,7 +633,7 @@ public: /* Clear farmland. */ for (const auto tile : Map::Iterate()) { - if (IsTileType(tile, MP_CLEAR) && GetRawClearGround(tile) == CLEAR_FIELDS) { + if (IsTileType(tile, MP_CLEAR) && GetClearGround(tile) == CLEAR_FIELDS) { MakeClear(tile, CLEAR_GRASS, 3); } } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index f91cdd2e6c..792f28a846 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2387,7 +2387,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_135)) { for (auto t : Map::Iterate()) { if (IsTileType(t, MP_CLEAR)) { - if (GetRawClearGround(t) == CLEAR_SNOW) { + if (GetClearGround(t) == CLEAR_SNOW) { // CLEAR_SNOW becomes CLEAR_GRASS with IsSnowTile() set. SetClearGroundDensity(t, CLEAR_GRASS, GetClearDensity(t)); SetBit(t.m3(), 4); } else { diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp index 9cc3264ef4..57ba12ca78 100644 --- a/src/script/api/script_tile.cpp +++ b/src/script/api/script_tile.cpp @@ -130,14 +130,14 @@ { if (!::IsValidTile(tile)) return false; - return (::IsTileType(tile, MP_CLEAR) && ::GetRawClearGround(tile) == ::CLEAR_ROCKS); + return (::IsTileType(tile, MP_CLEAR) && ::GetClearGround(tile) == ::CLEAR_ROCKS); } /* static */ bool ScriptTile::IsRoughTile(TileIndex tile) { if (!::IsValidTile(tile)) return false; - return (::IsTileType(tile, MP_CLEAR) && ::GetRawClearGround(tile) == ::CLEAR_ROUGH); + return (::IsTileType(tile, MP_CLEAR) && ::GetClearGround(tile) == ::CLEAR_ROUGH); } /* static */ bool ScriptTile::IsSnowTile(TileIndex tile) diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 7b71bd67b6..7df13e934b 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -74,7 +74,7 @@ static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert) return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile)); case MP_CLEAR: - return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && GetRawClearGround(tile) != CLEAR_ROCKS && + return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && !IsClearGround(tile, CLEAR_ROCKS) && (allow_desert || !IsClearGround(tile, CLEAR_DESERT)); default: return false; @@ -106,15 +106,20 @@ static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, Tree ClearNeighbourNonFloodingStates(tile); break; - case MP_CLEAR: - switch (GetClearGround(tile)) { - case CLEAR_GRASS: ground = TREE_GROUND_GRASS; break; - case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break; - case CLEAR_SNOW: ground = GetRawClearGround(tile) == CLEAR_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT; break; - default: ground = TREE_GROUND_SNOW_DESERT; break; + case MP_CLEAR: { + ClearGround clearground = GetClearGround(tile); + if (IsSnowTile(tile)) { + ground = clearground == CLEAR_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT; + } else { + switch (clearground) { + case CLEAR_GRASS: ground = TREE_GROUND_GRASS; break; + case CLEAR_ROUGH: ground = TREE_GROUND_ROUGH; break; + default: ground = TREE_GROUND_SNOW_DESERT; break; + } } - if (GetClearGround(tile) != CLEAR_ROUGH) density = GetClearDensity(tile); + if (clearground != CLEAR_ROUGH) density = GetClearDensity(tile); break; + } default: NOT_REACHED(); } @@ -575,7 +580,7 @@ CommandCost CmdPlantTree(DoCommandFlags flags, TileIndex tile, TileIndex start_t if (IsTileType(current_tile, MP_CLEAR)) { /* Remove fields or rocks. Note that the ground will get barrened */ - switch (GetRawClearGround(current_tile)) { + switch (GetClearGround(current_tile)) { case CLEAR_FIELDS: case CLEAR_ROCKS: { CommandCost ret = Command::Do(flags, current_tile);