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
 
@@ -50,121 +50,133 @@
 
	ty = AIMap::GetTileY(tile);
 

	
 
	for (uint x = tx; x < width + tx; x++) {
 
		for (uint y = ty; y < height + ty; y++) {
 
			if (!IsBuildable(AIMap::GetTileIndex(x, y))) return false;
 
		}
 
	}
 

	
 
	return true;
 
}
 

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

	
 
	return ::IsTileType(tile, MP_WATER) && !::IsCoast(tile);
 
}
 

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

	
 
	return ::IsTileType(tile, MP_WATER) && ::IsCoast(tile);
 
}
 

	
 
/* 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;
 
}
 

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

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

	
 
/* static */ int32 AITile::GetCornerHeight(TileIndex tile, Corner corner)
 
{
 
	if (!::IsValidTile(tile) || !::IsValidCorner((::Corner)corner)) return -1;
 

	
 
	uint z;
 
	::Slope slope = ::GetTileSlope(tile, &z);
 
	return (z + ::GetSlopeZInCorner(slope, (::Corner)corner)) / ::TILE_HEIGHT;
 
}
 

	
 
/* static */ AICompany::CompanyID AITile::GetOwner(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return AICompany::COMPANY_INVALID;
 
	if (::IsTileType(tile, MP_HOUSE)) return AICompany::COMPANY_INVALID;
 
	if (::IsTileType(tile, MP_INDUSTRY)) return AICompany::COMPANY_INVALID;
 

	
 
	return AICompany::ResolveCompanyID((AICompany::CompanyID)(byte)::GetTileOwner(tile));
 
}
0 comments (0 inline, 0 general)