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::Component;
|
2022-08-08 22:15:45 +00:00
|
|
|
use serde::{Serialize, Deserialize};
|
2020-11-12 21:31:28 +00:00
|
|
|
use vek::*;
|
2020-11-11 23:59:09 +00:00
|
|
|
|
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; }
|
2020-11-11 23:59:09 +00:00
|
|
|
|
2022-08-11 14:44:57 +00:00
|
|
|
slotmap::new_key_type! { pub struct SiteId; }
|
|
|
|
|
2020-11-11 23:59:09 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2022-08-11 10:05:01 +00:00
|
|
|
pub struct RtSimEntity(pub NpcId);
|
2020-11-11 23:59:09 +00:00
|
|
|
|
|
|
|
impl Component for RtSimEntity {
|
2022-08-08 04:38:20 +00:00
|
|
|
type Storage = specs::VecStorage<Self>;
|
2020-11-11 23:59:09 +00:00
|
|
|
}
|
2020-11-12 21:31:28 +00:00
|
|
|
|
2021-03-16 01:30:35 +00:00
|
|
|
#[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),
|
2021-03-16 01:30:35 +00:00
|
|
|
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 },
|
2021-03-16 01:30:35 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2020-11-12 21:31:28 +00:00
|
|
|
#[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.
|
2022-08-11 20:54:35 +00:00
|
|
|
pub travel_to: Option<Vec3<f32>>,
|
2020-11-12 21:31:28 +00:00
|
|
|
/// Proportion of full speed to move
|
|
|
|
pub speed_factor: f32,
|
2021-03-16 01:30:35 +00:00
|
|
|
/// Events
|
|
|
|
pub events: Vec<RtSimEvent>,
|
2020-11-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RtSimController {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
travel_to: None,
|
|
|
|
speed_factor: 1.0,
|
2021-03-16 01:30:35 +00:00
|
|
|
events: Vec::new(),
|
2020-11-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RtSimController {
|
2021-03-12 18:53:06 +00:00
|
|
|
pub fn with_destination(pos: Vec3<f32>) -> Self {
|
2021-03-12 02:58:57 +00:00
|
|
|
Self {
|
2022-08-11 20:54:35 +00:00
|
|
|
travel_to: Some(pos),
|
|
|
|
speed_factor: 0.5,
|
2021-03-16 01:30:35 +00:00
|
|
|
events: Vec::new(),
|
2021-03-12 02:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-12 21:31:28 +00:00
|
|
|
}
|
2022-08-08 22:15:45 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, enum_map::Enum)]
|
|
|
|
pub enum ChunkResource {
|
2022-08-10 23:40:30 +00:00
|
|
|
#[serde(rename = "0")]
|
2022-08-08 22:15:45 +00:00
|
|
|
Grass,
|
2022-08-10 23:40:30 +00:00
|
|
|
#[serde(rename = "1")]
|
2022-08-08 22:15:45 +00:00
|
|
|
Flax,
|
2022-08-10 23:40:30 +00:00
|
|
|
#[serde(rename = "2")]
|
2022-08-08 22:15:45 +00:00
|
|
|
Cotton,
|
|
|
|
}
|
2022-08-14 15:08:10 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
|
|
pub enum Profession {
|
|
|
|
#[serde(rename = "0")]
|
|
|
|
Farmer,
|
|
|
|
#[serde(rename = "1")]
|
|
|
|
Hunter,
|
|
|
|
#[serde(rename = "2")]
|
|
|
|
Merchant,
|
|
|
|
#[serde(rename = "3")]
|
|
|
|
Guard,
|
|
|
|
#[serde(rename = "4")]
|
|
|
|
Adventurer(u32),
|
2022-08-14 15:18:47 +00:00
|
|
|
#[serde(rename = "5")]
|
|
|
|
Blacksmith,
|
2022-08-15 10:02:38 +00:00
|
|
|
#[serde(rename = "6")]
|
|
|
|
Chef,
|
|
|
|
#[serde(rename = "7")]
|
|
|
|
Alchemist,
|
|
|
|
#[serde(rename = "8")]
|
|
|
|
Pirate,
|
|
|
|
#[serde(rename = "9")]
|
|
|
|
Cultist,
|
2022-08-14 15:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Profession {
|
|
|
|
pub fn to_name(&self) -> String {
|
|
|
|
match self {
|
|
|
|
Self::Farmer => "Farmer".to_string(),
|
|
|
|
Self::Hunter => "Hunter".to_string(),
|
|
|
|
Self::Merchant => "Merchant".to_string(),
|
|
|
|
Self::Guard => "Guard".to_string(),
|
|
|
|
Self::Adventurer(_) => "Adventurer".to_string(),
|
2022-08-14 15:18:47 +00:00
|
|
|
Self::Blacksmith => "Blacksmith".to_string(),
|
2022-08-15 10:02:38 +00:00
|
|
|
Self::Chef => "Chef".to_string(),
|
|
|
|
Self::Alchemist => "Alchemist".to_string(),
|
|
|
|
Self::Pirate => "Pirate".to_string(),
|
|
|
|
Self::Cultist => "Cultist".to_string(),
|
2022-08-14 15:08:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-14 15:38:31 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct WorldSettings {
|
|
|
|
pub start_time: f64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for WorldSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
start_time: 9.0 * 3600.0, // 9am
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|