Changeset - r20806:976f86294d6b
[Not reviewed]
master
0 1 0
zuu - 11 years ago 2013-10-12 22:17:11
zuu@openttd.org
(svn r25850) -Codechange: Merge IsBadFarmFieldTile and IsValidFarmFieldTile into IsSuitableForFarmField (cirdan, LordAro)
1 file changed with 14 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -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)
 
/**
 
 * 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_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)
 
{
 
	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 til
 
	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 til
 
	/* 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);
0 comments (0 inline, 0 general)