Entity

Struct Entity 

Source
pub struct Entity {
    pub name: String,
    pub description: String,
    pub id: Uuid,
    pub entity_type: EntityType,
    /* private fields */
}
Expand description

An entity that can be present in the game world.

Entities are mutable only through the entity system’s public API. Their fields are private to prevent accidental state corruption.

Fields§

§name: String

The name of the entity

§description: String

A short description of the entity

§id: Uuid

The global identifier for the entity

§entity_type: EntityType

The categorical type of the entity.

Currently an enum that distinguishes creatures, items, terrain, etc. It will be phased out in favor of a trait-based system for greater type safety.

Implementations§

Source§

impl Entity

Source

pub fn change_stat_strict(&mut self, pair: StatPair, delta: Modification)

Change one of the entity’s statistics.

The stat identified by pair is replaced with the new value specified in the StatPair. This is a direct overwrite and does not apply any delta.

§Arguments
  • pair - The stat pair containing the key and new value.
Source

pub fn change_stat_fuzzy(&mut self, pair: StatPair, delta: Modification)

Mutate a statistic in a “fuzzy” way.

This method behaves like change_stat_strict for ordinary stats, but for meta-stats it applies a random modification instead of an outright overwrite.

§Parameters
  • pair - a StatPair that contains the target statistic and the value that should be used for the fuzzy change.
Source

pub fn change_duration(&mut self, duration: EntityDuration)

Change the entity’s duration.

This simply replaces the current EntityDuration with the one supplied. No validation or transformation is performed; it is a direct overwrite.

§Arguments
  • duration - The new EntityDuration to assign to the entity.
Source

pub fn change_description(&mut self, descritption: String)

Change the entity’s description.

Replaces the current description string with the new one supplied.
This method performs a direct overwrite; the previous description is dropped.

§Arguments
  • descritption - The new description string for the entity.
Source

pub fn delta_stat(&mut self, pair: StatPair)

👎Deprecated

Apply a delta to all of the entity’s statistics.

The delta specified by pair is added to each of the statistics in self.stats. Positive values increase the stat, negative values decrease it.

§Arguments
  • pair - The stat pair representing the change to apply.
Source

pub fn modify_duration(&mut self, duration: EntityDuration)

Replace the entity’s duration.

The method simply overwrites the current duration field with the supplied value. It is primarily intended for use when an entity is instantiated from external data that already contains a duration value.

Source

pub fn modify_effect_application(&mut self, effect: EffectApplication)

Set the way the entity’s effects are applied.

The field effect_nature determines how the entity’s abilities or status effects interact with the world. This method overwrites the existing value with the supplied EffectApplication.

Source

pub fn modify_effect_bounds(&mut self, effect: EffectBounds)

Update the bounds that govern the entity’s effects.

effect_bounds controls the maximum/minimum strength, duration or other limits that can be applied to the entity’s effects. This method simply replaces the current bounds with the supplied EffectBounds.

Source

pub fn modify_position(&mut self, pos: Position)

Sets the entity’s position using a world-space Position.

This method updates the internal metadata to the specified world coordinates.

Source

pub fn modify_faction(&mut self, faction: Option<FactionId>)

Sets the entity’s faction identifier.

This method updates the internal metadata to reflect the provided faction. A None value indicates that the entity is not affiliated with any faction.

Source

pub fn modify_reach(&mut self, reach: Reach)

Sets the entity’s reach description.

The reach string typically contains information such as the distance or area the entity can affect. This method replaces the current reach value stored in the entity’s metadata.

Source

pub fn modify_position_grid(&mut self, pos: PositionGrid)

Sets the entity’s position using a grid-space PositionGrid.

The supplied grid coordinates are converted to world space before being stored.

Source

pub fn modify_description(&mut self, descritption: String)

Changes the entity’s description text.

Source

pub fn modify_prestige(&mut self, prestige: GenericStat, delta: Modification)

Sets the entity’s prestige stat to an absolute value.

The prestige value is stored directly in the entity’s metadata and overwrites any previous value.

Source

pub fn change_governor(&mut self, governor: CharacterId) -> Option<CharacterId>

Add a governor to the entity if the id exists and return the old governor if it existed

Source

pub fn remove_governor(&mut self) -> Option<CharacterId>

Remove the entity’s governor and return it

Source

pub fn change_capital(&mut self, capital: TownId) -> Option<TownId>

Add a governor to the entity if the id exists

Source

pub fn remove_capital(&mut self) -> Option<TownId>

Remove the entity’s governor and return it

Source

pub fn position(&self) -> &Position

Returns a read-only reference to the entity’s current position.

Source

pub fn update_metastats(&mut self)

Defer the update of all stats

Source

pub fn match_identifier( &self, entity_identifier: &Option<EntityIdentifier>, ) -> bool

Returns whether the entity match an optionnal identifier

Source§

impl Entity

Source

pub fn full_stats_to_table(&self) -> Result<TableDisplay, EpochError>

The table contains both the permanent and temporary statistics of the entity. The table is formatted with a custom border and separator using the cli_table crate.

§Returns

A Result containing the table display on success, or an EpochError if the conversion to a table string fails.

Adds a link (UUID) to the entity’s metadata.

If id_to_add is already present in the links vector, this method does nothing - it silently ignores duplicates. The method is idempotent: calling it repeatedly with the same UUID will not change the underlying state.

Removes a link (UUID) from the entity’s metadata.

If the supplied id_to_remove exists in self.metadata.links, it is removed and returned wrapped in Some. If the UUID is not present, the method returns None and leaves the link list unchanged.

Source

pub fn stats_to_table(&self) -> Result<TableDisplay, EpochError>

Display the entity’s statistics in a pretty table (same format as full_stats_to_table).

This method is provided for backward compatibility and forwards all work to full_stats_to_table.

§Returns

A Result containing the table display on success, or an EpochError if the conversion to a table string fails.

Source

pub fn reset_temporary_stats_to(&mut self, other: Option<OverallStats>)

Reset the temporary stats to a given base value.

Useful before performing an update: you can set the temporary stats to whatever snapshot you want to start from (or None to clear it).

Source

pub fn get_stats(&self) -> &OverallStats

Return an immutable reference to the entity’s live statistics.

Source

pub fn get_temp_stats(&self) -> &Option<OverallStats>

Return an immutable reference to the temporary statistics snapshot, if one is currently stored.

Source

pub fn to_pretty_tree(&self, epoch_info: &EpochInfo) -> String

Pretty-print the entity as a coloured tree.

The output is a String that visualises the entity’s metadata, type, duration, effect bounds, and any links. Colours are applied using colored::Colorize.

§Returns

A String containing the formatted tree.

Source

pub fn create_rng( e_type: &EntityType, rng: &RngLevel, ) -> Result<Self, EpochError>

Create an entity using a specific RNG level.

The entity is initialised with random statistics, a random position, and a random prestige value derived from the supplied RngLevel.

§Arguments
  • e_type - The type of entity to create.
  • rng - The RNG level to use when generating random values.
§Returns
  • Ok(Self) - The newly created entity.
  • Err(EpochError) - Propagated from any randomisation failure.
Source§

impl Entity

Iterate over all the links and do the appropriate action

Trait Implementations§

Source§

impl Clone for Entity

Source§

fn clone(&self) -> Entity

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 Entity

Source§

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

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

impl Default for Entity

Source§

fn default() -> Entity

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

impl<'de> Deserialize<'de> for Entity

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Diffable for Entity

Source§

fn delta(&self, other: &Self) -> Self

Compare self with another struct of the same type and return a new instance containing the difference
Source§

impl Displayable for Entity

Source§

fn oneline_display(&self) -> String

One-liner used for auto-generation of Vec<T> displays

Source§

fn print_full(&self, epoch_info: &EpochInfo)

Return a fully-described string representation.
Source§

fn short_display(&self, _epoch_info: &EpochInfo) -> String

Return a short, user-friendly string. Resolves Ids
Source§

impl Hash for Entity

Source§

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

Massive speedup at the cost of collision on updates, making eq for finding but not true equality However a .deep_eq() should be used for this

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 PartialEq for Entity

Source§

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

Time save and clash if not .deep_eq

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 Serialize for Entity

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Symbols for Entity

Source§

fn to_symbol(&self) -> String

Have a small Symbol to resume it
Source§

fn to_shortest(&self) -> String

Have the shortest display possible

Auto Trait Implementations§

§

impl Freeze for Entity

§

impl RefUnwindSafe for Entity

§

impl Send for Entity

§

impl Sync for Entity

§

impl Unpin for Entity

§

impl UnwindSafe for Entity

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<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,