Skip to main content

CitizenAi

Struct CitizenAi 

Source
pub struct CitizenAi {
    pub current: u32,
    pub queued: Option<u32>,
    pub eating: bool,
    pub warming: bool,
    pub cooldowns: [i64; 16],
    pub since_loiter: i64,
    pub carrying_time: i64,
}
Expand description

A citizen’s AI: the cooldown of each activity, the current and queued activity, and the urgent flags.

Fields§

§current: u32

The current activity.

§queued: Option<u32>

The queued activity, if any.

§eating: bool

Eating urgently.

§warming: bool

Warming up urgently.

§cooldowns: [i64; 16]

Per-activity cooldowns (ticks).

§since_loiter: i64

The time since the citizen last loitered.

§carrying_time: i64

How long the citizen has carried goods (reset while it carries nothing).

Implementations§

Source§

impl CitizenAi

Source

pub fn tick(&mut self, dt: i64, carrying: i32)

Count cooldowns down, advance the loiter and carry clocks.

Original: FUN_1401148b0 (timers).

Source

pub fn hunger_branch(&self, dt: i64, view: &CitizenView, d: &Thresholds) -> bool

Whether this update’s hunger branch is taken: urgently hungry, no urgent activity running or current, and the urgent meal’s cooldown out after this update’s dt. The caller then eats from the home’s storage first when it holds food (CitizenAi::update’s home_meal).

Original: FUN_1401148b0.

Source

pub fn update( &mut self, dt: i64, view: &CitizenView, d: &Thresholds, rng: &mut Random, home_meal: Option<f32>, busy: impl Fn() -> bool, run: impl FnMut(&mut CitizenAi, u32, &mut Random) -> bool, )

The scheduled update. busy is the character’s “has actions” test; run dispatches an activity (see CitizenAi::choose). home_meal is the citizen’s hunger after eating from the home’s storage, when CitizenAi::hunger_branch held and the home had food: the urgent choice is then made only if the citizen is still urgently hungry. Before the normal choice, run is asked for activity::REFRESH (the carried storage’s size and the model).

Original: FUN_14011a7b0, FUN_140114c70, FUN_140114d60, FUN_1401148b0.

Source

pub fn choose( &mut self, view: &CitizenView, d: &Thresholds, urgent_only: bool, rng: &mut Random, run: impl FnMut(&mut CitizenAi, u32, &mut Random) -> bool, )

Run the queued activity, or try candidates in order until run leaves the character busy. run(activity) is the dispatcher and returns whether the character now has actions queued.

Original: FUN_1401146c0, FUN_140113060.

Trait Implementations§

Source§

impl Clone for CitizenAi

Source§

fn clone(&self) -> CitizenAi

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 Debug for CitizenAi

Source§

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

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

impl Default for CitizenAi

Source§

fn default() -> Self

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

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.