From 8e5f74c00cc54664d165aeaf72bb4da68a67aea8 Mon Sep 17 00:00:00 2001 From: James Melkonian Date: Fri, 21 May 2021 11:19:58 -0700 Subject: [PATCH] Give ships species --- client/src/lib.rs | 2 + common/net/src/msg/server.rs | 3 +- common/src/comp/body.rs | 231 +++++++++++++++-------- common/src/comp/body/biped_large.rs | 2 +- common/src/comp/body/biped_small.rs | 2 +- common/src/comp/body/bird_large.rs | 2 +- common/src/comp/body/bird_medium.rs | 2 +- common/src/comp/body/dragon.rs | 2 +- common/src/comp/body/fish_medium.rs | 2 +- common/src/comp/body/fish_small.rs | 2 +- common/src/comp/body/golem.rs | 2 +- common/src/comp/body/quadruped_low.rs | 2 +- common/src/comp/body/quadruped_medium.rs | 2 +- common/src/comp/body/quadruped_small.rs | 2 +- common/src/comp/body/ship.rs | 54 +++++- common/src/states/utils.rs | 45 +++-- server/src/cmd.rs | 2 +- server/src/lib.rs | 1 + server/src/rtsim/entity.rs | 4 +- server/src/state_ext.rs | 9 +- 20 files changed, 245 insertions(+), 128 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index df73a2a780..2bc307025f 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -284,6 +284,7 @@ impl Client { client_timeout, world_map, recipe_book, + body_attributes, material_stats, ability_map, } => { @@ -297,6 +298,7 @@ impl Client { let entity = state.ecs_mut().apply_entity_package(entity_package); *state.ecs_mut().write_resource() = time_of_day; *state.ecs_mut().write_resource() = PlayerEntity(Some(entity)); + state.ecs_mut().insert(body_attributes); state.ecs_mut().insert(material_stats); state.ecs_mut().insert(ability_map); diff --git a/common/net/src/msg/server.rs b/common/net/src/msg/server.rs index 818f49c38f..a461dc5a3e 100644 --- a/common/net/src/msg/server.rs +++ b/common/net/src/msg/server.rs @@ -5,7 +5,7 @@ use super::{ use crate::sync; use common::{ character::{self, CharacterItem}, - comp::{self, invite::InviteKind, item::MaterialStatManifest}, + comp::{self, body::BodyAttributes, invite::InviteKind, item::MaterialStatManifest}, outcome::Outcome, recipe::RecipeBook, resources::TimeOfDay, @@ -60,6 +60,7 @@ pub enum ServerInit { world_map: crate::msg::world_msg::WorldMapMsg, recipe_book: RecipeBook, material_stats: MaterialStatManifest, + body_attributes: BodyAttributes, ability_map: comp::item::tool::AbilityMap, }, } diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index f212994044..5554382885 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -31,20 +31,20 @@ make_case_elim!( #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[repr(u32)] pub enum Body { - Humanoid(body: humanoid::Body) = 0, - QuadrupedSmall(body: quadruped_small::Body) = 1, - QuadrupedMedium(body: quadruped_medium::Body) = 2, - BirdMedium(body: bird_medium::Body) = 3, - FishMedium(body: fish_medium::Body) = 4, - Dragon(body: dragon::Body) = 5, - BirdLarge(body: bird_large::Body) = 6, - FishSmall(body: fish_small::Body) = 7, BipedLarge(body: biped_large::Body)= 8, BipedSmall(body: biped_small::Body)= 9, - Object(body: object::Body) = 10, + BirdLarge(body: bird_large::Body) = 6, + BirdMedium(body: bird_medium::Body) = 3, + Dragon(body: dragon::Body) = 5, + FishMedium(body: fish_medium::Body) = 4, + FishSmall(body: fish_small::Body) = 7, Golem(body: golem::Body) = 11, - Theropod(body: theropod::Body) = 12, + Humanoid(body: humanoid::Body) = 0, QuadrupedLow(body: quadruped_low::Body) = 13, + QuadrupedMedium(body: quadruped_medium::Body) = 2, + QuadrupedSmall(body: quadruped_small::Body) = 1, + Theropod(body: theropod::Body) = 12, + Object(body: object::Body) = 10, Ship(body: ship::Body) = 14, } ); @@ -52,7 +52,7 @@ make_case_elim!( /// Data representing data generic to the body together with per-species data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct BodyData { /// Shared metadata for this whole body type. pub body: BodyMeta, @@ -64,9 +64,23 @@ pub struct BodyData { /// stored for each species for each body. /// /// NOTE: Deliberately don't (yet?) implement serialize. +/// +/// +/// ############################################################################################## +/// ############################################################################################## +/// +/// ############################################################################################## +/// ############################################################################################## +/// TALK TO SHARP ABOUT IMPLEMENTING SERIALIZE!!!!!! +/// ############################################################################################## +/// ############################################################################################## +/// +/// ############################################################################################## +/// ############################################################################################## +/// /// NOTE: If you are adding new body kind and it should be spawned via /spawn /// please add it to `[ENTITIES](crate::cmd::ENTITIES)` -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllBodies { pub humanoid: BodyData>, pub quadruped_small: BodyData>, @@ -175,7 +189,7 @@ pub type SpeciesBaseHealthIncrease = Option; /// Type holding mass data for bodies and species. pub type AllBodiesBaseHealthIncrease = AllBodies; -#[derive(Clone, Debug, Default, Deserialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct BodyAttributes { pub aggro: Option, pub density: Option, @@ -251,83 +265,134 @@ pub fn get_body_u32_attribute< body_data.species[&species].unwrap_or_else(|| body_data.body) } +pub fn get_body_attribute< + 'a, + T: Copy, + Species, + SpeciesData: for<'b> core::ops::Index<&'b Species, Output = Option>, +>( + body_data: &'a BodyData, + species: Species, +) -> T { + body_data.species[&species].unwrap_or_else(|| body_data.body) +} + impl Body { pub fn is_humanoid(&self) -> bool { matches!(self, Body::Humanoid(_)) } + pub fn get_attribute_value(&self, body_attribute: &AllBodies>) -> T { + match self { + Body::BipedLarge(body) => { + get_body_attribute(&body_attribute.biped_large, body.species) + }, + Body::BipedSmall(body) => { + get_body_attribute(&body_attribute.biped_small, body.species) + }, + Body::BirdMedium(body) => { + get_body_attribute(&body_attribute.bird_medium, body.species) + }, + Body::BirdLarge(body) => { + get_body_attribute(&body_attribute.bird_large, body.species) + }, + Body::Dragon(body) => get_body_attribute(&body_attribute.dragon, body.species), + Body::FishMedium(body) => { + get_body_attribute(&body_attribute.fish_medium, body.species) + }, + Body::FishSmall(body) => { + get_body_attribute(&body_attribute.fish_small, body.species) + }, + Body::Golem(body) => get_body_attribute(&body_attribute.golem, body.species), + Body::Humanoid(body) => get_body_attribute(&body_attribute.humanoid, body.species), + Body::QuadrupedLow(body) => { + get_body_attribute(&body_attribute.quadruped_low, body.species) + }, + Body::QuadrupedMedium(body) => { + get_body_attribute(&body_attribute.quadruped_medium, body.species) + }, + Body::QuadrupedSmall(body) => { + get_body_attribute(&body_attribute.quadruped_small, body.species) + }, + Body::Theropod(body) => get_body_attribute(&body_attribute.theropod, body.species), + // TODO fix this for ships and objects to read from the ron files + Body::Ship(ship) => T::default(), + Body::Object(object) => T::default(), + } + } + /// Average density of the body /// Units are based on kg/m³ pub fn density(&self, body_densities: &AllBodiesDensity) -> Density { - let density_value = match self { - Body::BipedLarge(body) => { - get_body_f32_attribute(&body_densities.biped_large, body.species) - }, - Body::BipedSmall(body) => { - get_body_f32_attribute(&body_densities.biped_small, body.species) - }, - Body::BirdMedium(body) => { - get_body_f32_attribute(&body_densities.bird_medium, body.species) - }, - Body::BirdLarge(body) => { - get_body_f32_attribute(&body_densities.bird_large, body.species) - }, - Body::Dragon(body) => get_body_f32_attribute(&body_densities.dragon, body.species), - Body::FishMedium(body) => { - get_body_f32_attribute(&body_densities.fish_medium, body.species) - }, - Body::FishSmall(body) => { - get_body_f32_attribute(&body_densities.fish_small, body.species) - }, - Body::Golem(body) => get_body_f32_attribute(&body_densities.golem, body.species), - Body::Humanoid(body) => get_body_f32_attribute(&body_densities.humanoid, body.species), - Body::QuadrupedLow(body) => { - get_body_f32_attribute(&body_densities.quadruped_low, body.species) - }, - Body::QuadrupedMedium(body) => { - get_body_f32_attribute(&body_densities.quadruped_medium, body.species) - }, - Body::QuadrupedSmall(body) => { - get_body_f32_attribute(&body_densities.quadruped_small, body.species) - }, - Body::Theropod(body) => get_body_f32_attribute(&body_densities.theropod, body.species), - Body::Ship(ship) => ship.density().0, - Body::Object(object) => object.density().0, - }; + let density_value = 1000.0;//match self { + // Body::BipedLarge(body) => { + // get_body_f32_attribute(&body_densities.biped_large, body.species) + // }, + // Body::BipedSmall(body) => { + // get_body_f32_attribute(&body_densities.biped_small, body.species) + // }, + // Body::BirdMedium(body) => { + // get_body_f32_attribute(&body_densities.bird_medium, body.species) + // }, + // Body::BirdLarge(body) => { + // get_body_f32_attribute(&body_densities.bird_large, body.species) + // }, + // Body::Dragon(body) => get_body_f32_attribute(&body_densities.dragon, body.species), + // Body::FishMedium(body) => { + // get_body_f32_attribute(&body_densities.fish_medium, body.species) + // }, + // Body::FishSmall(body) => { + // get_body_f32_attribute(&body_densities.fish_small, body.species) + // }, + // Body::Golem(body) => get_body_f32_attribute(&body_densities.golem, body.species), + // Body::Humanoid(body) => get_body_f32_attribute(&body_densities.humanoid, body.species), + // Body::QuadrupedLow(body) => { + // get_body_f32_attribute(&body_densities.quadruped_low, body.species) + // }, + // Body::QuadrupedMedium(body) => { + // get_body_f32_attribute(&body_densities.quadruped_medium, body.species) + // }, + // Body::QuadrupedSmall(body) => { + // get_body_f32_attribute(&body_densities.quadruped_small, body.species) + // }, + // Body::Theropod(body) => get_body_f32_attribute(&body_densities.theropod, body.species), + // Body::Ship(body) => get_body_f32_attribute(&body_densities.ship, body.species), + // Body::Object(object) => object.density().0, + //}; Density(density_value) } /// Units are kg pub fn mass(&self, body_masses: &AllBodiesMass) -> Mass { - let m = match self { - Body::BipedLarge(body) => { - get_body_f32_attribute(&body_masses.biped_large, body.species) - }, - Body::BipedSmall(body) => { - get_body_f32_attribute(&body_masses.biped_small, body.species) - }, - Body::BirdMedium(body) => { - get_body_f32_attribute(&body_masses.bird_medium, body.species) - }, - Body::BirdLarge(body) => get_body_f32_attribute(&body_masses.bird_large, body.species), - Body::Dragon(body) => get_body_f32_attribute(&body_masses.dragon, body.species), - Body::FishMedium(body) => { - get_body_f32_attribute(&body_masses.fish_medium, body.species) - }, - Body::FishSmall(body) => get_body_f32_attribute(&body_masses.fish_small, body.species), - Body::Golem(body) => get_body_f32_attribute(&body_masses.golem, body.species), - Body::Humanoid(body) => get_body_f32_attribute(&body_masses.humanoid, body.species), - Body::QuadrupedLow(body) => { - get_body_f32_attribute(&body_masses.quadruped_low, body.species) - }, - Body::QuadrupedMedium(body) => { - get_body_f32_attribute(&body_masses.quadruped_medium, body.species) - }, - Body::QuadrupedSmall(body) => { - get_body_f32_attribute(&body_masses.quadruped_small, body.species) - }, - Body::Theropod(body) => get_body_f32_attribute(&body_masses.theropod, body.species), - Body::Ship(ship) => ship.density().0, - Body::Object(object) => object.density().0, - }; + let m = 100.0;//match self { + // Body::BipedLarge(body) => { + // get_body_f32_attribute(&body_masses.biped_large, body.species) + // }, + // Body::BipedSmall(body) => { + // get_body_f32_attribute(&body_masses.biped_small, body.species) + // }, + // Body::BirdMedium(body) => { + // get_body_f32_attribute(&body_masses.bird_medium, body.species) + // }, + // Body::BirdLarge(body) => get_body_f32_attribute(&body_masses.bird_large, body.species), + // Body::Dragon(body) => get_body_f32_attribute(&body_masses.dragon, body.species), + // Body::FishMedium(body) => { + // get_body_f32_attribute(&body_masses.fish_medium, body.species) + // }, + // Body::FishSmall(body) => get_body_f32_attribute(&body_masses.fish_small, body.species), + // Body::Golem(body) => get_body_f32_attribute(&body_masses.golem, body.species), + // Body::Humanoid(body) => get_body_f32_attribute(&body_masses.humanoid, body.species), + // Body::QuadrupedLow(body) => { + // get_body_f32_attribute(&body_masses.quadruped_low, body.species) + // }, + // Body::QuadrupedMedium(body) => { + // get_body_f32_attribute(&body_masses.quadruped_medium, body.species) + // }, + // Body::QuadrupedSmall(body) => { + // get_body_f32_attribute(&body_masses.quadruped_small, body.species) + // }, + // Body::Theropod(body) => get_body_f32_attribute(&body_masses.theropod, body.species), + // Body::Ship(body) => get_body_f32_attribute(&body_masses.ship, body.species), + // Body::Object(object) => object.density().0, + //}; Mass(m) } @@ -441,7 +506,7 @@ impl Body { quadruped_low::Species::Tortoise => Vec3::new(1.0, 1.6, 2.0), _ => Vec3::new(1.0, 1.6, 1.3), }, - Body::Ship(ship) => ship.dimensions(), + Body::Ship(ship) => Vec3::new(1.0, 1.0, 1.0),//ship.dimensions(), Body::Theropod(body) => match body.species { theropod::Species::Archaeos => Vec3::new(4.0, 7.0, 8.0), theropod::Species::Ntouka => Vec3::new(4.0, 6.0, 8.0), @@ -590,7 +655,8 @@ impl Body { Body::BirdLarge(_) => 50.0, Body::BirdMedium(_) => 40.0, Body::Dragon(_) => 60.0, - Body::Ship(ship::Body::DefaultAirship) => 60.0, + //Body::Ship(ship::Body::DefaultAirship) => 60.0, + Body::Ship(_) => 60.0, _ => 0.0, } } @@ -656,7 +722,8 @@ impl Body { pub fn mounting_offset(&self) -> Vec3 { match self { - Body::Ship(ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]), + //Body::Ship(ship::Body::DefaultAirship) => Vec3::from([0.0, 0.0, 10.0]), + Body::Ship(_) => Vec3::from([0.0, 0.0, 10.0]), _ => Vec3::unit_z(), } } diff --git a/common/src/comp/body/biped_large.rs b/common/src/comp/body/biped_large.rs index 3891c0a4f8..67c24c36af 100644 --- a/common/src/comp/body/biped_large.rs +++ b/common/src/comp/body/biped_large.rs @@ -56,7 +56,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub ogre: SpeciesMeta, pub cyclops: SpeciesMeta, diff --git a/common/src/comp/body/biped_small.rs b/common/src/comp/body/biped_small.rs index 945586f393..5dde761fca 100644 --- a/common/src/comp/body/biped_small.rs +++ b/common/src/comp/body/biped_small.rs @@ -51,7 +51,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub gnome: SpeciesMeta, pub sahagin: SpeciesMeta, diff --git a/common/src/comp/body/bird_large.rs b/common/src/comp/body/bird_large.rs index 629317082a..3346c68737 100644 --- a/common/src/comp/body/bird_large.rs +++ b/common/src/comp/body/bird_large.rs @@ -42,7 +42,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub phoenix: SpeciesMeta, pub cockatrice: SpeciesMeta, diff --git a/common/src/comp/body/bird_medium.rs b/common/src/comp/body/bird_medium.rs index 5eb7dbee65..428da6e1b4 100644 --- a/common/src/comp/body/bird_medium.rs +++ b/common/src/comp/body/bird_medium.rs @@ -47,7 +47,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub duck: SpeciesMeta, pub chicken: SpeciesMeta, diff --git a/common/src/comp/body/dragon.rs b/common/src/comp/body/dragon.rs index 07c3991a44..8653aadde3 100644 --- a/common/src/comp/body/dragon.rs +++ b/common/src/comp/body/dragon.rs @@ -41,7 +41,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub reddragon: SpeciesMeta, } diff --git a/common/src/comp/body/fish_medium.rs b/common/src/comp/body/fish_medium.rs index 924bf09f36..d264518122 100644 --- a/common/src/comp/body/fish_medium.rs +++ b/common/src/comp/body/fish_medium.rs @@ -42,7 +42,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub marlin: SpeciesMeta, pub icepike: SpeciesMeta, diff --git a/common/src/comp/body/fish_small.rs b/common/src/comp/body/fish_small.rs index 952a3f5412..616de92691 100644 --- a/common/src/comp/body/fish_small.rs +++ b/common/src/comp/body/fish_small.rs @@ -42,7 +42,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub clownfish: SpeciesMeta, pub piranha: SpeciesMeta, diff --git a/common/src/comp/body/golem.rs b/common/src/comp/body/golem.rs index a0549a5595..d096933a70 100644 --- a/common/src/comp/body/golem.rs +++ b/common/src/comp/body/golem.rs @@ -43,7 +43,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub stonegolem: SpeciesMeta, pub treant: SpeciesMeta, diff --git a/common/src/comp/body/quadruped_low.rs b/common/src/comp/body/quadruped_low.rs index f2c14091e2..5a3eaee3e5 100644 --- a/common/src/comp/body/quadruped_low.rs +++ b/common/src/comp/body/quadruped_low.rs @@ -54,7 +54,7 @@ make_case_elim!( /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub crocodile: SpeciesMeta, pub alligator: SpeciesMeta, diff --git a/common/src/comp/body/quadruped_medium.rs b/common/src/comp/body/quadruped_medium.rs index 192e7559b5..272600e550 100644 --- a/common/src/comp/body/quadruped_medium.rs +++ b/common/src/comp/body/quadruped_medium.rs @@ -67,7 +67,7 @@ pub enum Species { /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub grolgar: SpeciesMeta, pub saber: SpeciesMeta, diff --git a/common/src/comp/body/quadruped_small.rs b/common/src/comp/body/quadruped_small.rs index 1d4f294e64..56c09e69db 100644 --- a/common/src/comp/body/quadruped_small.rs +++ b/common/src/comp/body/quadruped_small.rs @@ -64,7 +64,7 @@ pub enum Species { /// Data representing per-species generic data. /// /// NOTE: Deliberately don't (yet?) implement serialize. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AllSpecies { pub pig: SpeciesMeta, pub fox: SpeciesMeta, diff --git a/common/src/comp/body/ship.rs b/common/src/comp/body/ship.rs index f880683d47..d36c8823e7 100644 --- a/common/src/comp/body/ship.rs +++ b/common/src/comp/body/ship.rs @@ -2,16 +2,16 @@ use crate::{ comp::{Density, Mass}, consts::AIR_DENSITY, make_case_elim, + make_proj_elim, }; use serde::{Deserialize, Serialize}; use vek::Vec3; -make_case_elim!( +make_proj_elim!( body, #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] - #[repr(u32)] - pub enum Body { - DefaultAirship = 0, + pub struct Body { + pub species: Species, } ); @@ -19,10 +19,52 @@ impl From for super::Body { fn from(body: Body) -> Self { super::Body::Ship(body) } } -impl Body { +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[repr(u32)] +pub enum Species { + DefaultAirship = 0, + NonDefaultAirship = 1, +} + +/// Data representing per-species generic data. +/// +/// NOTE: Deliberately don't (yet?) implement serialize. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct AllSpecies { + pub default_airship: SpeciesMeta, + // TODO remove this + pub non_default_airship: SpeciesMeta, +} + +impl<'a, SpeciesMeta> core::ops::Index<&'a Species> for AllSpecies { + type Output = SpeciesMeta; + + #[inline] + fn index(&self, &index: &'a Species) -> &Self::Output { + match index { + Species::DefaultAirship => &self.default_airship, + Species::NonDefaultAirship => &self.non_default_airship, + } + } +} + +pub const ALL_SPECIES: [Species; 2] = [ + Species::DefaultAirship, + Species::NonDefaultAirship, +]; + +impl<'a, SpeciesMeta: 'a> IntoIterator for &'a AllSpecies { + type IntoIter = std::iter::Copied>; + type Item = Species; + + fn into_iter(self) -> Self::IntoIter { ALL_SPECIES.iter().copied() } +} + +impl Species { pub fn manifest_entry(&self) -> &'static str { match self { - Body::DefaultAirship => "Human_Airship", + Species::DefaultAirship => "Human_Airship", + Species::NonDefaultAirship => "Nonexistent_Airship", } } diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index cd68e8fb92..97283c2784 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -195,7 +195,7 @@ impl Body { Body::BirdMedium(_) => Some(GRAVITY * 0.5), Body::BirdLarge(_) => Some(GRAVITY * 2.0), Body::Dragon(_) => Some(200_000.0), - Body::Ship(ship::Body::DefaultAirship) => Some(300_000.0), + Body::Ship(_) => Some(300_000.0), _ => None, } } @@ -395,28 +395,27 @@ pub fn fly_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) -> b let anti_grav = GRAVITY * (1.0 + data.inputs.move_z.min(0.0)); update.vel.0.z += data.dt.0 * (anti_grav + accel * data.inputs.move_z.max(0.0)); }, - // floaty floaty - Body::Ship(ship @ ship::Body::DefaultAirship) => { - let regulate_density = |min: f32, max: f32, def: f32, rate: f32| -> Density { - // Reset to default on no input - let change = if data.inputs.move_z.abs() > std::f32::EPSILON { - -data.inputs.move_z - } else { - (def - data.density.0).max(-1.0).min(1.0) - }; - Density((update.density.0 + data.dt.0 * rate * change).clamp(min, max)) - }; - let def_density = ship.density().0; - if data.physics.in_liquid().is_some() { - let hull_density = ship.hull_density().0; - update.density.0 = - regulate_density(def_density * 0.6, hull_density, hull_density, 25.0).0; - } else { - update.density.0 = - regulate_density(def_density * 0.5, def_density * 1.5, def_density, 0.5).0; - }; - }, - // oopsie woopsie + // TODO fix this + //Body::Ship(ship @ ship::Body::DefaultAirship) => { + // let regulate_density = |min: f32, max: f32, def: f32, rate: f32| -> Density { + // // Reset to default on no input + // let change = if data.inputs.move_z.abs() > std::f32::EPSILON { + // -data.inputs.move_z + // } else { + // (def - data.density.0).max(-1.0).min(1.0) + // }; + // Density((update.density.0 + data.dt.0 * rate * change).clamp(min, max)) + // }; + // let def_density = 1000.0;//ship.density().0; + // if data.physics.in_liquid().is_some() { + // let hull_density = 1000.0;//ship.hull_density().0; + // update.density.0 = + // regulate_density(def_density * 0.6, hull_density, hull_density, 25.0).0; + // } else { + // update.density.0 = + // regulate_density(def_density * 0.5, def_density * 1.5, def_density, 0.5).0; + // }; + //}, // TODO: refactor to make this state impossible _ => {}, }; diff --git a/server/src/cmd.rs b/server/src/cmd.rs index fefe425924..0d4ebd855b 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1188,7 +1188,7 @@ fn handle_spawn_airship( }); let mut builder = server .state - .create_ship(pos, comp::ship::Body::DefaultAirship, true) + .create_ship(pos, comp::ship::Body { species: comp::ship::Species::DefaultAirship }, true) .with(LightEmitter { col: Rgb::new(1.0, 0.65, 0.2), strength: 2.0, diff --git a/server/src/lib.rs b/server/src/lib.rs index 54fab914a0..ec9ef8326e 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -837,6 +837,7 @@ impl Server { client_timeout: self.settings().client_timeout, world_map: self.map.clone(), recipe_book: default_recipe_book().cloned(), + body_attributes: (&*self.state.ecs().read_resource::()).clone(), material_stats: MaterialStatManifest::default(), ability_map: (&*self .state diff --git a/server/src/rtsim/entity.rs b/server/src/rtsim/entity.rs index 1e299d62c5..729190d009 100644 --- a/server/src/rtsim/entity.rs +++ b/server/src/rtsim/entity.rs @@ -37,7 +37,9 @@ impl Entity { pub fn get_body(&self) -> comp::Body { match self.rng(PERM_GENUS).gen::() { // we want 5% airships, 45% birds, 50% humans - x if x < 0.05 => comp::Body::Ship(comp::ship::Body::DefaultAirship), + x if x < 0.05 => comp::Body::Ship(comp::ship::Body { + species: comp::ship::Species::DefaultAirship, + }), x if x < 0.45 => { let species = *(&comp::bird_medium::ALL_SPECIES) .choose(&mut self.rng(PERM_SPECIES)) diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index 72dad300d4..7d10b9f53b 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -213,8 +213,8 @@ impl StateExt for State { .with(mass) .with(density) .with(match body { - comp::Body::Ship(ship) => comp::Collider::Voxel { - id: ship.manifest_entry().to_string(), + comp::Body::Ship(comp::ship::Body { species }) => comp::Collider::Voxel { + id: species.manifest_entry().to_string(), }, _ => comp::Collider::Box { radius: body.radius(), @@ -307,8 +307,11 @@ impl StateExt for State { .with(comp::Ori::default()) .with(mass) .with(density) + //.with(comp::Collider::Voxel { + // id: ship.manifest_entry().to_string(), + //}) .with(comp::Collider::Voxel { - id: ship.manifest_entry().to_string(), + id: ship.species.manifest_entry().to_string(), }) .with(body) .with(comp::Scale(comp::ship::AIRSHIP_SCALE))