veloren/common/src/rtsim.rs

96 lines
2.8 KiB
Rust
Raw Normal View History

// We'd like to not have this file in `common`, but sadly there are
// things in `common` that require it (currently, `ServerEvent` and
// `Agent`). When possible, this should be moved to the `rtsim`
// module in `server`.
use specs::Component;
use serde::{Serialize, Deserialize};
use vek::*;
2021-03-29 14:47:42 +00:00
use crate::comp::dialogue::MoodState;
2022-08-11 10:05:01 +00:00
slotmap::new_key_type! { pub struct NpcId; }
#[derive(Copy, Clone, Debug)]
2022-08-11 10:05:01 +00:00
pub struct RtSimEntity(pub NpcId);
impl Component for RtSimEntity {
type Storage = specs::VecStorage<Self>;
}
#[derive(Clone, Debug)]
pub enum RtSimEvent {
AddMemory(Memory),
2021-03-29 14:47:42 +00:00
SetMood(Memory),
2021-07-14 15:26:29 +00:00
ForgetEnemy(String),
PrintMemories,
}
#[derive(Clone, Debug)]
pub struct Memory {
pub item: MemoryItem,
pub time_to_forget: f64,
}
#[derive(Clone, Debug)]
pub enum MemoryItem {
// These are structs to allow more data beyond name to be stored
// such as clothing worn, weapon used, etc.
CharacterInteraction { name: String },
CharacterFight { name: String },
2021-03-29 14:47:42 +00:00
Mood { state: MoodState },
}
2020-11-23 15:39:03 +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
2020-11-23 15:39:03 +00:00
/// toward the given location, accounting for obstacles and other
/// high-priority situations like being attacked.
pub travel_to: Option<(Vec3<f32>, String)>,
/// Proportion of full speed to move
pub speed_factor: f32,
/// Events
pub events: Vec<RtSimEvent>,
}
impl Default for RtSimController {
fn default() -> Self {
Self {
travel_to: None,
speed_factor: 1.0,
events: Vec::new(),
}
}
}
impl RtSimController {
2020-11-23 15:39:03 +00:00
pub fn reset(&mut self) { *self = Self::default(); }
pub fn with_destination(pos: Vec3<f32>) -> Self {
2021-03-12 02:58:57 +00:00
Self {
travel_to: Some((pos, format!("{:0.1?}", pos))),
speed_factor: 0.25,
events: Vec::new(),
2021-03-12 02:58:57 +00:00
}
}
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, enum_map::Enum)]
pub enum ChunkResource {
#[serde(rename = "0")]
Grass,
#[serde(rename = "1")]
Flax,
#[serde(rename = "2")]
Cotton,
}