Changeset - r12876:f6a9a5783c12
[Not reviewed]
master
0 1 0
yexo - 15 years ago 2009-09-02 12:48:23
yexo@openttd.org
(svn r17378) -Fix [NoAI]: Several AITile::* functions didn't check whether their parameters were valid
1 file changed with 12 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_tile.cpp
Show inline comments
 
@@ -74,73 +74,85 @@
 

	
 
/* static */ bool AITile::IsStationTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return false;
 

	
 
	return ::IsTileType(tile, MP_STATION);
 
}
 

	
 
/* static */ bool AITile::IsSteepSlope(Slope slope)
 
{
 
	if ((slope & ~(SLOPE_ELEVATED | SLOPE_STEEP | SLOPE_HALFTILE_MASK)) != 0) return false;
 

	
 
	return ::IsSteepSlope((::Slope)slope);
 
}
 

	
 
/* static */ bool AITile::IsHalftileSlope(Slope slope)
 
{
 
	if ((slope & ~(SLOPE_ELEVATED | SLOPE_STEEP | SLOPE_HALFTILE_MASK)) != 0) return false;
 

	
 
	return ::IsHalftileSlope((::Slope)slope);
 
}
 

	
 
/* static */ bool AITile::HasTreeOnTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return false;
 

	
 
	return ::IsTileType(tile, MP_TREES);
 
}
 

	
 
/* static */ bool AITile::IsFarmTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return false;
 

	
 
	return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_FIELDS));
 
}
 

	
 
/* static */ bool AITile::IsRockTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return false;
 

	
 
	return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_ROCKS));
 
}
 

	
 
/* static */ bool AITile::IsRoughTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return false;
 

	
 
	return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_ROUGH));
 
}
 

	
 
/* static */ bool AITile::IsSnowTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return false;
 

	
 
	return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_SNOW));
 
}
 

	
 
/* static */ bool AITile::IsDesertTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return false;
 

	
 
	return (::IsTileType(tile, MP_CLEAR) && ::IsClearGround(tile, CLEAR_DESERT));
 
}
 

	
 
/* static */ AITile::Slope AITile::GetSlope(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return SLOPE_INVALID;
 

	
 
	return (Slope)::GetTileSlope(tile, NULL);
 
}
 

	
 
/* static */ AITile::Slope AITile::GetComplementSlope(Slope slope)
 
{
 
	if ((slope & ~SLOPE_ELEVATED) != 0) return SLOPE_INVALID;
 

	
 
	return (Slope)::ComplementSlope((::Slope)slope);
 
}
 

	
 
/* static */ int32 AITile::GetMinHeight(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return -1;
 

	
 
	return ::GetTileZ(tile) / ::TILE_HEIGHT;
 
}
 

	
0 comments (0 inline, 0 general)