2020-04-18 20:26:43 +00:00
|
|
|
use crate::{
|
2020-04-19 03:56:14 +00:00
|
|
|
comp::{self, humanoid, Alignment, Body, Item},
|
2020-04-18 20:26:43 +00:00
|
|
|
npc::{self, NPC_NAMES},
|
|
|
|
};
|
2020-04-19 03:56:14 +00:00
|
|
|
use vek::*;
|
2020-04-18 20:26:43 +00:00
|
|
|
|
|
|
|
pub enum EntityTemplate {
|
|
|
|
Traveller,
|
|
|
|
}
|
2020-01-25 02:15:15 +00:00
|
|
|
|
|
|
|
pub struct EntityInfo {
|
2020-01-22 03:12:17 +00:00
|
|
|
pub pos: Vec3<f32>,
|
2020-04-17 20:58:36 +00:00
|
|
|
pub is_waypoint: bool, // Edge case, overrides everything else
|
|
|
|
pub is_giant: bool,
|
2020-07-05 12:39:28 +00:00
|
|
|
pub has_agency: bool,
|
2020-04-17 20:58:36 +00:00
|
|
|
pub alignment: Alignment,
|
2020-04-18 20:26:43 +00:00
|
|
|
pub body: Body,
|
|
|
|
pub name: Option<String>,
|
|
|
|
pub main_tool: Option<Item>,
|
2020-07-01 09:51:06 +00:00
|
|
|
pub second_tool: Option<Item>,
|
2020-05-15 15:05:50 +00:00
|
|
|
pub scale: f32,
|
|
|
|
pub level: Option<u32>,
|
|
|
|
pub loot_drop: Option<Item>,
|
2020-04-17 20:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EntityInfo {
|
|
|
|
pub fn at(pos: Vec3<f32>) -> Self {
|
|
|
|
Self {
|
|
|
|
pos,
|
|
|
|
is_waypoint: false,
|
|
|
|
is_giant: false,
|
2020-07-05 12:39:28 +00:00
|
|
|
has_agency: true,
|
2020-04-17 20:58:36 +00:00
|
|
|
alignment: Alignment::Wild,
|
2020-04-18 20:26:43 +00:00
|
|
|
body: Body::Humanoid(humanoid::Body::random()),
|
|
|
|
name: None,
|
2020-04-23 12:29:22 +00:00
|
|
|
main_tool: Some(Item::empty()),
|
2020-07-01 09:51:06 +00:00
|
|
|
second_tool: Some(Item::empty()),
|
2020-05-15 15:05:50 +00:00
|
|
|
scale: 1.0,
|
|
|
|
level: None,
|
|
|
|
loot_drop: None,
|
2020-04-17 20:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn do_if(mut self, cond: bool, f: impl FnOnce(Self) -> Self) -> Self {
|
|
|
|
if cond {
|
|
|
|
self = f(self);
|
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn into_waypoint(mut self) -> Self {
|
|
|
|
self.is_waypoint = true;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn into_giant(mut self) -> Self {
|
|
|
|
self.is_giant = true;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_alignment(mut self, alignment: Alignment) -> Self {
|
|
|
|
self.alignment = alignment;
|
|
|
|
self
|
|
|
|
}
|
2020-04-18 20:26:43 +00:00
|
|
|
|
|
|
|
pub fn with_body(mut self, body: Body) -> Self {
|
|
|
|
self.body = body;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-07-05 12:39:28 +00:00
|
|
|
pub fn with_name(mut self, name: impl Into<String>) -> Self {
|
|
|
|
self.name = Some(name.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_agency(mut self, agency: bool) -> Self {
|
|
|
|
self.has_agency = agency;
|
2020-04-18 20:26:43 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_main_tool(mut self, main_tool: Item) -> Self {
|
|
|
|
self.main_tool = Some(main_tool);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-07-01 09:51:06 +00:00
|
|
|
pub fn with_second_tool(mut self, second_tool: Item) -> Self {
|
|
|
|
self.second_tool = Some(second_tool);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 15:05:50 +00:00
|
|
|
pub fn with_loot_drop(mut self, loot_drop: Item) -> Self {
|
|
|
|
self.loot_drop = Some(loot_drop);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_scale(mut self, scale: f32) -> Self {
|
|
|
|
self.scale = scale;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_level(mut self, level: u32) -> Self {
|
|
|
|
self.level = Some(level);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-04-18 20:26:43 +00:00
|
|
|
pub fn with_automatic_name(mut self) -> Self {
|
|
|
|
self.name = match &self.body {
|
2020-05-29 18:23:00 +00:00
|
|
|
Body::Humanoid(body) => Some(get_npc_name(&NPC_NAMES.humanoid, body.species)),
|
2020-04-19 03:56:14 +00:00
|
|
|
Body::QuadrupedMedium(body) => {
|
|
|
|
Some(get_npc_name(&NPC_NAMES.quadruped_medium, body.species))
|
|
|
|
},
|
2020-04-18 20:26:43 +00:00
|
|
|
Body::BirdMedium(body) => Some(get_npc_name(&NPC_NAMES.bird_medium, body.species)),
|
|
|
|
Body::Critter(body) => Some(get_npc_name(&NPC_NAMES.critter, body.species)),
|
2020-04-19 03:56:14 +00:00
|
|
|
Body::QuadrupedSmall(body) => {
|
|
|
|
Some(get_npc_name(&NPC_NAMES.quadruped_small, body.species))
|
|
|
|
},
|
2020-05-09 22:02:27 +00:00
|
|
|
Body::Dragon(body) => Some(get_npc_name(&NPC_NAMES.dragon, body.species)),
|
2020-06-01 23:56:50 +00:00
|
|
|
Body::QuadrupedLow(body) => Some(get_npc_name(&NPC_NAMES.quadruped_low, body.species)),
|
2020-04-18 20:26:43 +00:00
|
|
|
_ => None,
|
2020-04-19 03:56:14 +00:00
|
|
|
}
|
|
|
|
.map(|s| {
|
|
|
|
if self.is_giant {
|
|
|
|
format!("Giant {}", s)
|
|
|
|
} else {
|
|
|
|
s.to_string()
|
|
|
|
}
|
2020-04-18 20:26:43 +00:00
|
|
|
});
|
|
|
|
self
|
|
|
|
}
|
2020-01-22 03:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct ChunkSupplement {
|
2020-01-25 02:15:15 +00:00
|
|
|
pub entities: Vec<EntityInfo>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ChunkSupplement {
|
2020-04-17 23:29:01 +00:00
|
|
|
pub fn add_entity(&mut self, entity: EntityInfo) { self.entities.push(entity); }
|
2020-01-22 03:12:17 +00:00
|
|
|
}
|
2020-04-18 20:26:43 +00:00
|
|
|
|
2020-04-23 14:01:37 +00:00
|
|
|
pub fn get_npc_name<
|
2020-04-18 20:26:43 +00:00
|
|
|
'a,
|
|
|
|
Species,
|
|
|
|
SpeciesData: for<'b> core::ops::Index<&'b Species, Output = npc::SpeciesNames>,
|
|
|
|
>(
|
|
|
|
body_data: &'a comp::BodyData<npc::BodyNames, SpeciesData>,
|
|
|
|
species: Species,
|
|
|
|
) -> &'a str {
|
|
|
|
&body_data.species[&species].generic
|
|
|
|
}
|