Skip to main content

LuaTerritory

Struct LuaTerritory 

Source
pub struct LuaTerritory;
Expand description

A set of chunks on a single LuaSurface that can be guarded by one or more LuaSegmentedUnits.

A territory is owned by the surface for which it was created. It comprises any number of disconnected or connected chunks. A chunk can only be owned by at most one territory. A territory’s chunks may or may not be generated.

Territories may be patrolled by any number of LuaSegmentedUnits. A territory with default visibility condition but with no units will not appear on player’s maps.

Territories may define a patrol path that LuaSegmentedUnits will follow. If no such path is defined, then units will wander randomly throughout the territory chunks. If a territory contains no patrol path and no chunks, then units will behave as if they are assigned to any territory.

The game will automatically destroy any territory that does not have at least one chunk that is generated or requested to be generated. This is to prevent bloat when chunks are deleted. This can happen as a result of any operation that modifies a territory’s chunks, including but not limited to LuaSurface::delete_chunk, LuaSurface::set_territory_for_chunks, and LuaSurface::clear_territory_for_chunks.

Implementations§

Source§

impl LuaTerritory

Source

pub fn object_name(&self) -> &'static str

The class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.

Source

pub fn surface(&self) -> LuaSurface

The surface on which this territory is located.

Source

pub fn valid(&self) -> bool

Is this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be false. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.

Source

pub fn visibility_condition(&self) -> TerritoryVisibilityCondition

Condition when this territory is visible.

Source

pub fn destroy(&self)

Immediately destroys the territory, along with any segmented units guarding it. All associated chunks are cleared from the territory system, allowing the map generator to potentially generate new territories for these chunks in the future.

This LuaTerritory is no longer valid after calling this.

Source

pub fn get_chunks(&self) -> Vec<ChunkPositionAndArea>

Gets all chunks that are a part of the territory.

Chunks may or may not be generated; use LuaSurface::is_chunk_generated to check a chunk’s state before accessing it.

Source

pub fn get_patrol_path(&self) -> Vec<MapPosition>

Get the path that the territory’s units follow when patrolling the territory. Will not be empty.

It is common that the territory’s patrol path is fully contained within the territory’s chunks, but it is not strictly necessary.

Source

pub fn get_segmented_units(&self) -> Vec<LuaSegmentedUnit>

Gets the LuaSegmentedUnits that guard this territory.

Source

pub fn regenerate_patrol_path(&self)

Regenerates the patrol path for the territory according to the game’s default territory generation algorithm and overwrites the territory’s current patrol path.

Source

pub fn regenerate_segmented_units(&self)

Regenerates any segmented units that were created when the territory was generated by the map generator. If the territory was created or modified by a script, and the surface’s map generator is configured to create segmented units with territories, then this function will create the segmented units that would have been created along with the script-modified or script-created territory. If the surface’s map generator is not configured to create segmented units at all, then no segmented units will be created.

Note: this does not destroy or replace existing units guarding the territory, and existing units will not prevent the generation of new units. Calling this repeatedly on a territory that generates a segmented unit will simply repeatedly add new segmented units to the map, all guarding this territory.

Source

pub fn set_patrol_path(&self, patrol_path: Vec<MapPosition>)

Overwrite the territory patrol path for units that guard the territory.

It is recommended that the territory’s patrol path be fully contained within the territory’s chunks, but it is not strictly necessary.

To let the territory system generate a patrol path, use LuaTerritory::regenerate_patrol_path.

Trait Implementations§

Source§

impl Clone for LuaTerritory

Source§

fn clone(&self) -> LuaTerritory

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for LuaTerritory

Source§

impl Debug for LuaTerritory

Source§

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

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

impl Default for LuaTerritory

Source§

fn default() -> LuaTerritory

Returns the “default value” for a type. Read more
Source§

impl Eq for LuaTerritory

Source§

impl From<LuaTerritory> for LuaAny

Source§

fn from(_: LuaTerritory) -> Self

Converts to this type from the input type.
Source§

impl From<LuaTerritory> for RegistrationTarget

Source§

fn from(value: LuaTerritory) -> Self

Converts to this type from the input type.
Source§

impl LuaObject for LuaTerritory

Source§

impl PartialEq for LuaTerritory

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LuaTerritory

Auto Trait Implementations§

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> 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.