diff options
author | zuu <zuu@openttd.org> | 2013-10-12 22:17:11 +0000 |
---|---|---|
committer | zuu <zuu@openttd.org> | 2013-10-12 22:17:11 +0000 |
commit | e7c6786016e7c6cd1333c930a188c722f8739a34 (patch) | |
tree | eb5776e79ac8eed3b12f7f18241d8dc3270fbc86 | |
parent | dfb566331390a87f01d048f57ed6d51b2f329d65 (diff) | |
download | openttd-e7c6786016e7c6cd1333c930a188c722f8739a34.tar.xz |
(svn r25850) -Codechange: Merge IsBadFarmFieldTile and IsValidFarmFieldTile into IsSuitableForFarmField (cirdan, LordAro)
-rw-r--r-- | src/industry_cmd.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 7841ce84c..2155e7472 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -940,21 +940,19 @@ bool IsTileForestIndustry(TileIndex tile) static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; -static bool IsBadFarmFieldTile(TileIndex tile) -{ - switch (GetTileType(tile)) { - case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT); - case MP_TREES: return (GetTreeGround(tile) == TREE_GROUND_SHORE); - default: return true; - } -} - -static bool IsBadFarmFieldTile2(TileIndex tile) +/** + * Check whether the tile can be replaced by a farm field. + * @param tile the tile to investigate. + * @param allow_fields if true, the method will return true even if + * the tile is a farm tile, otherwise the tile may not be a farm tile + * @return true if the tile can become a farm field + */ +static bool IsSuitableForFarmField(TileIndex tile, bool allow_fields) { switch (GetTileType(tile)) { - case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT); - case MP_TREES: return (GetTreeGround(tile) == TREE_GROUND_SHORE); - default: return true; + case MP_CLEAR: return !IsClearGround(tile, CLEAR_SNOW) && !IsClearGround(tile, CLEAR_DESERT) && (allow_fields || !IsClearGround(tile, CLEAR_FIELDS)); + case MP_TREES: return GetTreeGround(tile) != TREE_GROUND_SHORE; + default: return false; } } @@ -1008,9 +1006,9 @@ static void PlantFarmField(TileIndex tile, IndustryID industry) int count = 0; TILE_AREA_LOOP(cur_tile, ta) { assert(cur_tile < MapSize()); - count += IsBadFarmFieldTile(cur_tile); + count += IsSuitableForFarmField(cur_tile, false); } - if (count * 2 >= ta.w * ta.h) return; + if (count * 2 < ta.w * ta.h) return; /* determine type of field */ r = Random(); @@ -1020,7 +1018,7 @@ static void PlantFarmField(TileIndex tile, IndustryID industry) /* make field */ TILE_AREA_LOOP(cur_tile, ta) { assert(cur_tile < MapSize()); - if (!IsBadFarmFieldTile2(cur_tile)) { + if (IsSuitableForFarmField(cur_tile, true)) { MakeField(cur_tile, field_type, industry); SetClearCounter(cur_tile, counter); MarkTileDirtyByTile(cur_tile); |