pub struct Tile(usize);Expand description
Tile represents a tile on the map, where the usize is the index of the current tile.
The index indicates the tile’s position on the map, typically used to access or reference specific tiles.
Tuple Fields§
§0: usizeImplementations§
Source§impl Tile
impl Tile
Sourceconst SETTLER_MOVEMENT_RANGE: u32 = 2
const SETTLER_MOVEMENT_RANGE: u32 = 2
The maximum distance a Settler can move in one turn, without considering technologies, eras, improvements, etc.
TODO: This should be a parameter read from the ruleset directly.
pub const fn new(index: usize) -> Self
Sourcepub fn from_offset(offset_coordinate: OffsetCoordinate, grid: HexGrid) -> Self
pub fn from_offset(offset_coordinate: OffsetCoordinate, grid: HexGrid) -> Self
Creates a Tile from an OffsetCoordinate according to the specified HexGrid.
pub fn to_cell(&self) -> Cell
Sourcepub const fn index(&self) -> usize
pub const fn index(&self) -> usize
Get the index of the tile.
The index indicates the tile’s position on the map, typically used to access or reference specific tiles.
Sourcepub fn to_offset(&self, grid: HexGrid) -> OffsetCoordinate
pub fn to_offset(&self, grid: HexGrid) -> OffsetCoordinate
Converts a tile to the corresponding offset coordinate based on grid parameters.
§Arguments
grid: AHexGridthat contains the map size information.
§Returns
Returns an OffsetCoordinate that corresponds to the provided tile, calculated based on the grid parameters.
This coordinate represents the position of the tile within the map grid.
Sourcepub fn to_hex(&self, grid: HexGrid) -> Hex
pub fn to_hex(&self, grid: HexGrid) -> Hex
Converts the current tile to a hexagonal coordinate based on the map parameters.
§Returns
Returns a Hex coordinate that corresponds to the provided map position, calculated based on the map grid parameters.
This coordinate represents the position in hexagonal space within the map grid.
§Panics
This method will panic if the tile is out of bounds for the given map size.
Sourcepub fn latitude(&self, grid: HexGrid) -> f64
pub fn latitude(&self, grid: HexGrid) -> f64
Calculates the latitude of the tile on the tile map.
The latitude is defined such that:
- The equator corresponds to a latitude of
0.0. - The poles correspond to a latitude of
1.0.
As the latitude value approaches 0.0, the tile is closer to the equator,
while a value approaching 1.0 indicates proximity to the poles.
§Arguments
grid: AHexGridthat contains the map size information.
§Returns
A f64 representing the latitude of the tile, with values ranging from 0.0 (equator) to 1.0 (poles).
§Panics
This method will panic if the tile is out of bounds for the given map size.
Sourcepub fn terrain_type(&self, tile_map: &TileMap) -> TerrainType
pub fn terrain_type(&self, tile_map: &TileMap) -> TerrainType
Returns the terrain type of the tile at the given index.
Sourcepub fn base_terrain(&self, tile_map: &TileMap) -> BaseTerrain
pub fn base_terrain(&self, tile_map: &TileMap) -> BaseTerrain
Returns the base terrain of the tile at the given index.
Sourcepub fn feature(&self, tile_map: &TileMap) -> Option<Feature>
pub fn feature(&self, tile_map: &TileMap) -> Option<Feature>
Returns the feature of the tile at the given index.
Sourcepub fn natural_wonder(&self, tile_map: &TileMap) -> Option<NaturalWonder>
pub fn natural_wonder(&self, tile_map: &TileMap) -> Option<NaturalWonder>
Returns the natural wonder of the tile at the given index.
Sourcepub fn resource(&self, tile_map: &TileMap) -> Option<(Resource, u32)>
pub fn resource(&self, tile_map: &TileMap) -> Option<(Resource, u32)>
Returns the resource of the tile at the given index.
Sourcepub fn area_id(&self, tile_map: &TileMap) -> usize
pub fn area_id(&self, tile_map: &TileMap) -> usize
Returns the area ID of the tile at the given index.
Sourcepub fn landmass_id(&self, tile_map: &TileMap) -> usize
pub fn landmass_id(&self, tile_map: &TileMap) -> usize
Returns the landmass ID of the tile at the given index.
Sourcepub fn set_terrain_type(
&self,
tile_map: &mut TileMap,
terrain_type: TerrainType,
)
pub fn set_terrain_type( &self, tile_map: &mut TileMap, terrain_type: TerrainType, )
Sets the terrain type of the tile at the given index.
Sourcepub fn set_base_terrain(
&self,
tile_map: &mut TileMap,
base_terrain: BaseTerrain,
)
pub fn set_base_terrain( &self, tile_map: &mut TileMap, base_terrain: BaseTerrain, )
Sets the base terrain of the tile at the given index.
Sourcepub fn set_feature(&self, tile_map: &mut TileMap, feature: Feature)
pub fn set_feature(&self, tile_map: &mut TileMap, feature: Feature)
Sets the feature of the tile at the given index.
Sourcepub fn clear_feature(&self, tile_map: &mut TileMap)
pub fn clear_feature(&self, tile_map: &mut TileMap)
Clears the feature of the tile at the given index.
Sourcepub fn set_natural_wonder(
&self,
tile_map: &mut TileMap,
natural_wonder: NaturalWonder,
)
pub fn set_natural_wonder( &self, tile_map: &mut TileMap, natural_wonder: NaturalWonder, )
Sets the natural wonder of the tile at the given index.
Sourcepub fn clear_natural_wonder(&self, tile_map: &mut TileMap)
pub fn clear_natural_wonder(&self, tile_map: &mut TileMap)
Clears the natural wonder of the tile at the given index.
Sourcepub fn set_resource(
&self,
tile_map: &mut TileMap,
resource: Resource,
quantity: u32,
)
pub fn set_resource( &self, tile_map: &mut TileMap, resource: Resource, quantity: u32, )
Sets the resource of the tile at the given index.
Sourcepub fn clear_resource(&self, tile_map: &mut TileMap)
pub fn clear_resource(&self, tile_map: &mut TileMap)
Clears the resource of the tile at the given index.
Sourcepub fn set_area_id(&self, tile_map: &mut TileMap, area_id: usize)
pub fn set_area_id(&self, tile_map: &mut TileMap, area_id: usize)
Sets the area ID of the tile at the given index.
Sourcepub fn set_landmass_id(&self, tile_map: &mut TileMap, landmass_id: usize)
pub fn set_landmass_id(&self, tile_map: &mut TileMap, landmass_id: usize)
Sets the landmass ID of the tile at the given index.
Sourcepub fn neighbor_tiles(
&self,
grid: HexGrid,
) -> impl Iterator<Item = Self> + use<>
pub fn neighbor_tiles( &self, grid: HexGrid, ) -> impl Iterator<Item = Self> + use<>
Returns an iterator over the neighboring tiles of the current tile.
Sourcepub fn neighbor_tile(&self, direction: Direction, grid: HexGrid) -> Option<Self>
pub fn neighbor_tile(&self, direction: Direction, grid: HexGrid) -> Option<Self>
Retrieves the neighboring tile from the current tile in the specified direction.
§Arguments
direction: The direction to locate the neighboring tile.grid: The grid parameters that include layout and offset information.
§Returns
An Option<Tile>. This is Some if the neighboring tile exists,
or None if the neighboring tile is invalid.
§Panics
This method will panic if the current tile is out of bounds for the given map size.
Sourcepub fn tiles_at_distance(
&self,
distance: u32,
grid: HexGrid,
) -> impl Iterator<Item = Self> + use<>
pub fn tiles_at_distance( &self, distance: u32, grid: HexGrid, ) -> impl Iterator<Item = Self> + use<>
Returns an iterator over the tiles at the given distance from the current tile.
Sourcepub fn tiles_in_distance(
&self,
distance: u32,
grid: HexGrid,
) -> impl Iterator<Item = Self>
pub fn tiles_in_distance( &self, distance: u32, grid: HexGrid, ) -> impl Iterator<Item = Self>
Returns an iterator over the tiles within the given distance from the current tile, including the current tile.
Sourcepub fn has_river_in_direction(
&self,
direction: Direction,
tile_map: &TileMap,
) -> bool
pub fn has_river_in_direction( &self, direction: Direction, tile_map: &TileMap, ) -> bool
Sourcepub fn is_water(&self, tile_map: &TileMap) -> bool
pub fn is_water(&self, tile_map: &TileMap) -> bool
Checks if the tile is water.
When tile’s terrain type is TerrainType::Water, it is considered water.
Otherwise, it is not water.
Sourcepub fn is_impassable(&self, tile_map: &TileMap, ruleset: &Ruleset) -> bool
pub fn is_impassable(&self, tile_map: &TileMap, ruleset: &Ruleset) -> bool
Checks if the tile is impassable.
Sourcepub fn is_freshwater(&self, tile_map: &TileMap) -> bool
pub fn is_freshwater(&self, tile_map: &TileMap) -> bool
Check if the tile is freshwater
Freshwater is not water and is adjacent to lake, oasis or has a river
Sourcepub fn is_coastal_land(&self, tile_map: &TileMap) -> bool
pub fn is_coastal_land(&self, tile_map: &TileMap) -> bool
Check if the tile is coastal land.
A tile is considered coastal land if it is not Water and has at least one neighboring tile that is Coast.
§Notice
If the tile is not Water and has at least one neighboring tile that is Lake, but it has no neighboring tile that is Coast, it is not coastal land.
Sourcepub fn can_be_civilization_starting_tile(
&self,
tile_map: &TileMap,
map_parameters: &MapParameters,
) -> bool
pub fn can_be_civilization_starting_tile( &self, tile_map: &TileMap, map_parameters: &MapParameters, ) -> bool
Checks if a tile can be a starting tile of civilization.
A tile is considered a starting tile if it is either Flatland or Hill, and then it must meet one of the following conditions:
- The tile is a coastal land.
- If
civ_require_coastal_land_startisfalse, An inland tile (whose distance toCoastis greater than 2) can be a starting tile as well.
Why Inland Tiles with Distance 2 from Coast are Excluded
Because in the original game, the Settler unit can move 2 tiles per turn (ignoring terrain movement cost).
If such a tile were considered a starting tile, a Settler can move to the coastal land and build a city in just one turn, which is functionally equivalent to choosing a coastal land tile as the starting tile of civilization directly.
§Notice
The tile with nature wonder can not be a starting tile of civilization. But we don’t check the nature wonder in this function, because we generate the nature wonder after generating the civilization starting tile. That’s like in original CIV5. City state starting tile is the same as well. In CIV6, we should check the nature wonder in this function.
Sourcepub fn can_be_city_state_starting_tile(
&self,
tile_map: &TileMap,
region: Option<&Region>,
) -> bool
pub fn can_be_city_state_starting_tile( &self, tile_map: &TileMap, region: Option<&Region>, ) -> bool
Checks if a tile can be a starting tile of city state.
A tile is considered a starting tile, it must meet all of the following conditions:
- It is either
FlatlandorHill. - It is not
Snow.
§Arguments
tile_map: A reference toTileMap, which contains the tile data.region: An optional reference toRegion, which represents the region where the city state is located.
IfNone, the function considers the tile as a candidate regardless of its region. That usually happens when we place a city state in a unhabitated area.
Trait Implementations§
Source§impl Ord for Tile
impl Ord for Tile
Source§impl PartialOrd for Tile
impl PartialOrd for Tile
impl Copy for Tile
impl Eq for Tile
impl StructuralPartialEq for Tile
Auto Trait Implementations§
impl Freeze for Tile
impl RefUnwindSafe for Tile
impl Send for Tile
impl Sync for Tile
impl Unpin for Tile
impl UnsafeUnpin for Tile
impl UnwindSafe for Tile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more