2020-11-11 23:59:09 +00:00
|
|
|
// We'd like to not have this file in `common`, but sadly there are
|
2020-11-12 21:31:28 +00:00
|
|
|
// things in `common` that require it (currently, `ServerEvent` and
|
|
|
|
// `Agent`). When possible, this should be moved to the `rtsim`
|
|
|
|
// module in `server`.
|
2020-11-11 23:59:09 +00:00
|
|
|
|
|
|
|
use specs_idvs::IdvStorage;
|
|
|
|
use specs::Component;
|
2020-11-12 21:31:28 +00:00
|
|
|
use vek::*;
|
2020-11-11 23:59:09 +00:00
|
|
|
|
|
|
|
pub type RtSimId = usize;
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
pub struct RtSimEntity(pub RtSimId);
|
|
|
|
|
|
|
|
impl Component for RtSimEntity {
|
|
|
|
type Storage = IdvStorage<Self>;
|
|
|
|
}
|
2020-11-12 21:31:28 +00:00
|
|
|
|
|
|
|
/// This type is the map route through which the rtsim (real-time simulation) aspect
|
|
|
|
/// of the game communicates with the rest of the game. It is analagous to
|
|
|
|
/// `comp::Controller` in that it provides a consistent interface for simulation NPCs
|
|
|
|
/// to control their actions. Unlike `comp::Controller`, it is very abstract and is
|
|
|
|
/// intended for consumption by both the agent code and the internal rtsim simulation
|
|
|
|
/// code (depending on whether the entity is loaded into the game as a physical entity
|
|
|
|
/// or not). Agent code should attempt to act upon its instructions where reasonable
|
|
|
|
/// although deviations for various reasons (obstacle avoidance, counter-attacking,
|
|
|
|
/// etc.) are expected.
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct RtSimController {
|
|
|
|
/// When this field is `Some(..)`, the agent should attempt to make progress
|
|
|
|
/// toward the given location, accounting for obstacles and other high-priority
|
|
|
|
/// situations like being attacked.
|
|
|
|
pub travel_to: Option<Vec3<f32>>,
|
|
|
|
/// Proportion of full speed to move
|
|
|
|
pub speed_factor: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RtSimController {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
travel_to: None,
|
|
|
|
speed_factor: 1.0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RtSimController {
|
|
|
|
pub fn reset(&mut self) {
|
|
|
|
*self = Self::default();
|
|
|
|
}
|
|
|
|
}
|