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: StringThe name of the entity
description: StringA short description of the entity
id: UuidThe global identifier for the entity
entity_type: EntityTypeThe 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
impl Entity
Sourcepub fn change_stat_strict(&mut self, pair: StatPair, delta: Modification)
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.
Sourcepub fn change_stat_fuzzy(&mut self, pair: StatPair, delta: Modification)
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- aStatPairthat contains the target statistic and the value that should be used for the fuzzy change.
Sourcepub fn change_duration(&mut self, duration: EntityDuration)
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 newEntityDurationto assign to the entity.
Sourcepub fn change_description(&mut self, descritption: String)
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.
Sourcepub fn delta_stat(&mut self, pair: StatPair)
👎Deprecated
pub fn delta_stat(&mut self, pair: StatPair)
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.
Sourcepub fn modify_duration(&mut self, duration: EntityDuration)
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.
Sourcepub fn modify_effect_application(&mut self, effect: EffectApplication)
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.
Sourcepub fn modify_effect_bounds(&mut self, effect: EffectBounds)
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.
Sourcepub fn modify_position(&mut self, pos: Position)
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.
Sourcepub fn modify_faction(&mut self, faction: Option<FactionId>)
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.
Sourcepub fn modify_reach(&mut self, reach: Reach)
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.
Sourcepub fn modify_position_grid(&mut self, pos: PositionGrid)
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.
Sourcepub fn modify_description(&mut self, descritption: String)
pub fn modify_description(&mut self, descritption: String)
Changes the entity’s description text.
Sourcepub fn modify_prestige(&mut self, prestige: GenericStat, delta: Modification)
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.
Sourcepub fn change_governor(&mut self, governor: CharacterId) -> Option<CharacterId>
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
Sourcepub fn remove_governor(&mut self) -> Option<CharacterId>
pub fn remove_governor(&mut self) -> Option<CharacterId>
Remove the entity’s governor and return it
Sourcepub fn change_capital(&mut self, capital: TownId) -> Option<TownId>
pub fn change_capital(&mut self, capital: TownId) -> Option<TownId>
Add a governor to the entity if the id exists
Sourcepub fn remove_capital(&mut self) -> Option<TownId>
pub fn remove_capital(&mut self) -> Option<TownId>
Remove the entity’s governor and return it
Sourcepub fn position(&self) -> &Position
pub fn position(&self) -> &Position
Returns a read-only reference to the entity’s current position.
Sourcepub fn update_metastats(&mut self)
pub fn update_metastats(&mut self)
Defer the update of all stats
Sourcepub fn match_identifier(
&self,
entity_identifier: &Option<EntityIdentifier>,
) -> bool
pub fn match_identifier( &self, entity_identifier: &Option<EntityIdentifier>, ) -> bool
Returns whether the entity match an optionnal identifier
Source§impl Entity
impl Entity
Sourcepub fn full_stats_to_table(&self) -> Result<TableDisplay, EpochError>
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.
Sourcepub fn add_to_links(&mut self, id_to_add: TypedLink)
pub fn add_to_links(&mut self, id_to_add: TypedLink)
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.
Sourcepub fn del_from_links(&mut self, id_to_remove: TypedLink) -> Option<TypedLink>
pub fn del_from_links(&mut self, id_to_remove: TypedLink) -> Option<TypedLink>
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.
Sourcepub fn stats_to_table(&self) -> Result<TableDisplay, EpochError>
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.
Sourcepub fn reset_temporary_stats_to(&mut self, other: Option<OverallStats>)
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).
Sourcepub fn get_stats(&self) -> &OverallStats
pub fn get_stats(&self) -> &OverallStats
Return an immutable reference to the entity’s live statistics.
Sourcepub fn get_temp_stats(&self) -> &Option<OverallStats>
pub fn get_temp_stats(&self) -> &Option<OverallStats>
Return an immutable reference to the temporary statistics snapshot, if one is currently stored.
Sourcepub fn to_pretty_tree(&self, epoch_info: &EpochInfo) -> String
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.
Sourcepub fn create_rng(
e_type: &EntityType,
rng: &RngLevel,
) -> Result<Self, EpochError>
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
impl Entity
Sourcepub fn remove_all_links(
&self,
epoch_info: &mut EpochInfo,
) -> Result<(), EpochError>
pub fn remove_all_links( &self, epoch_info: &mut EpochInfo, ) -> Result<(), EpochError>
Iterate over all the links and do the appropriate action
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Entity
impl<'de> Deserialize<'de> for Entity
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Displayable for Entity
impl Displayable for Entity
Source§fn oneline_display(&self) -> String
fn oneline_display(&self) -> String
One-liner used for auto-generation of Vec<T> displays
Source§fn print_full(&self, epoch_info: &EpochInfo)
fn print_full(&self, epoch_info: &EpochInfo)
Source§fn short_display(&self, _epoch_info: &EpochInfo) -> String
fn short_display(&self, _epoch_info: &EpochInfo) -> String
Source§impl Hash for Entity
impl Hash for Entity
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> 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<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more