Skip to main content

wde_terrain_navigation/
lib.rs

1use bevy::prelude::*;
2
3mod navgrid;
4mod navigation;
5
6pub mod prelude {
7    pub use super::TerrainNavigator;
8    pub use super::navgrid::{CONTROL_ROOM_ROLE, NavBase, NavBuilding, NavGrid, NavNeighbor};
9    pub use super::navigation::{AIRLOCK_ROLE, Indoors, NavAgent, WalkSpeeds};
10}
11
12pub struct TerrainNavigationPlugin;
13impl Plugin for TerrainNavigationPlugin {
14    fn build(&self, app: &mut App) {
15        app.add_plugins((navigation::NavigationPlugin, navgrid::NavMapPlugin))
16            .init_resource::<TerrainNavigator>();
17    }
18}
19
20/// Requests movements: entities walk to their destination along a path through the colony
21/// (outdoor tiles, paths, airlocks, tunnels and buildings).
22#[derive(Resource, Default)]
23pub struct TerrainNavigator {
24    new_entities: Vec<(Entity, Vec3)>,
25    groups: Vec<(Vec<Entity>, Vec3)>,
26    removed_entities: Vec<Entity>
27}
28impl TerrainNavigator {
29    /// Sends `entity` toward the world position `destination`.
30    pub fn add(&mut self, entity: Entity, destination: Vec3) {
31        self.new_entities.push((entity, destination));
32    }
33
34    /// Sends `entities` toward `destination` together: each one gets its own standing spot
35    /// around it, so that they do not pile up on the same point.
36    pub fn add_group(&mut self, entities: impl IntoIterator<Item = Entity>, destination: Vec3) {
37        self.groups
38            .push((entities.into_iter().collect(), destination));
39    }
40
41    /// Stops `entity`.
42    pub fn remove(&mut self, entity: Entity) {
43        self.removed_entities.push(entity);
44    }
45}