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: u32The current activity.
queued: Option<u32>The queued activity, if any.
eating: boolEating urgently.
warming: boolWarming up urgently.
cooldowns: [i64; 16]Per-activity cooldowns (ticks).
since_loiter: i64The time since the citizen last loitered.
carrying_time: i64How long the citizen has carried goods (reset while it carries nothing).
Implementations§
Source§impl CitizenAi
impl CitizenAi
Sourcepub fn tick(&mut self, dt: i64, carrying: i32)
pub fn tick(&mut self, dt: i64, carrying: i32)
Count cooldowns down, advance the loiter and carry clocks.
Original: FUN_1401148b0 (timers).
Sourcepub fn hunger_branch(&self, dt: i64, view: &CitizenView, d: &Thresholds) -> bool
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.
Sourcepub 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,
)
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.
Sourcepub fn choose(
&mut self,
view: &CitizenView,
d: &Thresholds,
urgent_only: bool,
rng: &mut Random,
run: impl FnMut(&mut CitizenAi, u32, &mut Random) -> bool,
)
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.