Skip to main content

Tile

Struct Tile 

Source
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: usize

Implementations§

Source§

impl Tile

Source

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.

Source

pub const fn new(index: usize) -> Self

Source

pub fn from_offset(offset_coordinate: OffsetCoordinate, grid: HexGrid) -> Self

Creates a Tile from an OffsetCoordinate according to the specified HexGrid.

Source

pub fn from_cell(cell: Cell) -> Self

Creates a Tile from a Cell.

Source

pub fn to_cell(&self) -> Cell

Source

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.

Source

pub fn to_offset(&self, grid: HexGrid) -> OffsetCoordinate

Converts a tile to the corresponding offset coordinate based on grid parameters.

§Arguments
  • grid: A HexGrid that 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.

Source

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.

Source

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: A HexGrid that 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.

Source

pub fn terrain_type(&self, tile_map: &TileMap) -> TerrainType

Returns the terrain type of the tile at the given index.

Source

pub fn base_terrain(&self, tile_map: &TileMap) -> BaseTerrain

Returns the base terrain of the tile at the given index.

Source

pub fn feature(&self, tile_map: &TileMap) -> Option<Feature>

Returns the feature of the tile at the given index.

Source

pub fn natural_wonder(&self, tile_map: &TileMap) -> Option<NaturalWonder>

Returns the natural wonder of the tile at the given index.

Source

pub fn resource(&self, tile_map: &TileMap) -> Option<(Resource, u32)>

Returns the resource of the tile at the given index.

Source

pub fn area_id(&self, tile_map: &TileMap) -> usize

Returns the area ID of the tile at the given index.

Source

pub fn landmass_id(&self, tile_map: &TileMap) -> usize

Returns the landmass ID of the tile at the given index.

Source

pub fn set_terrain_type( &self, tile_map: &mut TileMap, terrain_type: TerrainType, )

Sets the terrain type of the tile at the given index.

Source

pub fn set_base_terrain( &self, tile_map: &mut TileMap, base_terrain: BaseTerrain, )

Sets the base terrain of the tile at the given index.

Source

pub fn set_feature(&self, tile_map: &mut TileMap, feature: Feature)

Sets the feature of the tile at the given index.

Source

pub fn clear_feature(&self, tile_map: &mut TileMap)

Clears the feature of the tile at the given index.

Source

pub fn set_natural_wonder( &self, tile_map: &mut TileMap, natural_wonder: NaturalWonder, )

Sets the natural wonder of the tile at the given index.

Source

pub fn clear_natural_wonder(&self, tile_map: &mut TileMap)

Clears the natural wonder of the tile at the given index.

Source

pub fn set_resource( &self, tile_map: &mut TileMap, resource: Resource, quantity: u32, )

Sets the resource of the tile at the given index.

Source

pub fn clear_resource(&self, tile_map: &mut TileMap)

Clears the resource of the tile at the given index.

Source

pub fn set_area_id(&self, tile_map: &mut TileMap, area_id: usize)

Sets the area ID of the tile at the given index.

Source

pub fn set_landmass_id(&self, tile_map: &mut TileMap, landmass_id: usize)

Sets the landmass ID of the tile at the given index.

Source

pub fn neighbor_tiles( &self, grid: HexGrid, ) -> impl Iterator<Item = Self> + use<>

Returns an iterator over the neighboring tiles of the current tile.

Source

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.

Source

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.

Source

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.

Source

pub fn has_river(&self, tile_map: &TileMap) -> bool

Checks if there is a river on the current tile.

§Arguments
  • tile_map: A reference to the TileMap containing river information.
§Returns
  • bool: Returns true if there is a river on the current tile, false otherwise.
Source

pub fn has_river_in_direction( &self, direction: Direction, tile_map: &TileMap, ) -> bool

Checks if there is a river on the current tile in the specified direction.

§Arguments
  • direction: The direction to check for the river.
  • tile_map: A reference to the TileMap containing river information.
§Returns
  • bool: Returns true if there is a river in the specified direction, false otherwise.
Source

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.

Source

pub fn is_impassable(&self, tile_map: &TileMap, ruleset: &Ruleset) -> bool

Checks if the tile is impassable.

Source

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

Source

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.

Source

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:

  1. The tile is a coastal land.
  2. If civ_require_coastal_land_start is false, An inland tile (whose distance to Coast is 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.

Source

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:

  1. It is either Flatland or Hill.
  2. It is not Snow.
§Arguments
  • tile_map: A reference to TileMap, which contains the tile data.
  • region: An optional reference to Region, which represents the region where the city state is located.
    If None, 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 Clone for Tile

Source§

fn clone(&self) -> Tile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Tile

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Tile

Source§

fn cmp(&self, other: &Tile) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Tile

Source§

fn eq(&self, other: &Tile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Tile

Source§

fn partial_cmp(&self, other: &Tile) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Tile

Source§

impl Eq for Tile

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V