Skip to main content

banished_game/behaviour/agents/
paths.rs

1//! Paths for citizens: road and walking paths and the commute.
2
3use super::*;
4
5impl Agents {
6    /// The cells of a road from `a` to `b`, over `mask`, avoiding the cells of zones. The road
7    /// tool uses it.
8    ///
9    /// Original: `FUN_1400a22d0`.
10    pub fn road_path(
11        &mut self,
12        cells: &Cells,
13        a: i32,
14        b: i32,
15        mask: u32,
16        manhattan: bool,
17    ) -> Option<Vec<i32>> {
18        self.sync_map(cells);
19        let blocked: Vec<bool> = cells.occupants.iter().map(Option::is_some).collect();
20        self.pathfinder.find_road(a, b, mask, manhattan, &blocked)
21    }
22
23    /// A citizen's walk from `a` to `b` as the path manager finds it (mask `0xe1f`, mode 0), for
24    /// the Path tool; the finder's state is kept.
25    ///
26    /// Original: `FUN_1400a2480`, `FUN_1400e2c40`.
27    pub fn walk_path(&mut self, cells: &Cells, a: i32, b: i32) -> Option<Vec<i32>> {
28        self.sync_map(cells);
29        let regions = &self.regions;
30        self.pathfinder.keeping_state(|f| {
31            f.set_mode(0);
32            crate::pathfind::request(f, &cells.types, regions, crate::pathfind::WALKABLE, a, b)
33        })
34    }
35
36    /// StockManager::Update's commute optimisation (see [`crate::behaviour::commute`]) by `dt`
37    /// ticks.
38    ///
39    /// Original: `FUN_140091780`.
40    pub fn update_commute(
41        &mut self,
42        citizens: &[Citizen],
43        env: &mut Env,
44        groups: &[Option<&AnimationGroup>],
45        dt: i64,
46    ) {
47        self.sync_map(env.cells);
48        let mut job = std::mem::take(&mut env.construction.commute);
49        let entities = entity_views(env.placed, env.templates, env.construction);
50        let adult = self.adults(citizens);
51        let (mut sim, _) = self.sim(citizens, env, groups, &adult, &entities);
52        sim.update_commute(&mut job, citizens, dt);
53        env.construction.commute = job;
54    }
55}