diff --git a/lib_efo/src/entity/implementations.rs b/lib_efo/src/entity/implementations.rs index 94bd623..ea8324d 100644 --- a/lib_efo/src/entity/implementations.rs +++ b/lib_efo/src/entity/implementations.rs @@ -1,13 +1,14 @@ //! Implementation of all needed traits for the Entity struct use cli_table::{Style, WithTitle, print_stdout}; use colored::*; +use rand::distr::Distribution; use uuid::Uuid; // [3] - colored-rs examples use crate::Displayable; use crate::entity::Entity; use crate::epoch::epoch_traits::Diffable; use crate::error::EpochError; -use crate::stats::{EntityType, MetaStats, OverallStats, Symbols}; +use crate::stats::{EntityType, MetaStats, OverallStats, Position, Symbols}; use crate::utils::RngLevel; // ---------- Implementation ---------- @@ -18,7 +19,7 @@ impl Displayable for Entity { "{:?}\n{}", self.metadata.position, // Display format!( - "{:?} | {:?} | {} | {:?} | {}", + "{:?} | {:?} | {:?} | {:?} | {}", self.metadata.capital, self.metadata.governor, self.metadata.faction, @@ -74,7 +75,7 @@ impl Displayable for Entity { ); let line2 = format!( - "│ └─ Faction: {}{}{}{} │ Effect: {} {}, Stats: {}", + "│ └─ Faction: {:?}{}{}{} │ Effect: {} {}, Stats: {}", self.metadata.faction, capital, governor, @@ -138,7 +139,8 @@ impl Entity { stats: OverallStats::create_rng(rng, &mut r)?, temp_stats: OverallStats::default(), metadata: MetaStats { - prestige: 12, + prestige: (rng.to_rng()?.sample(&mut r) as usize), + position: Position::create_rng(&mut r)?, ..Default::default() }, entity_type: e_type, @@ -189,7 +191,14 @@ impl Diffable for MetaStats { position: self.position.clone() - other.position.clone(), capital, governor, - faction: self.faction.clone() - other.faction.clone(), + faction: { + match (self.faction.as_ref(), other.faction.as_ref()) { + (None, None) => None, + (None, Some(a)) => Some(a.clone()), + (Some(a), None) => Some(a.clone()), + (Some(a), Some(b)) => Some(a.clone() - b.clone()), + } + }, links: self .links .clone() diff --git a/lib_efo/src/stats.rs b/lib_efo/src/stats.rs index 91feb40..cd985fd 100644 --- a/lib_efo/src/stats.rs +++ b/lib_efo/src/stats.rs @@ -21,6 +21,7 @@ use colored::Colorize; use derive_more::Add; use derive_more::Display; use derive_more::Sub; +use rand::Rng; use rand::distr::Distribution; use rand::rngs::ThreadRng; use serde::{Deserialize, Serialize}; @@ -325,7 +326,7 @@ pub struct MetaStats { /// **Effect** - Determines diplomatic relations, war status, /// and access to empire-wide bonuses. /// **Source** - `faction = current_faction_uuid`. - pub faction: FactionId, + pub faction: Option, /// UIDs of all entities the entity is linked to (roads, trade routes, /// alliances, war declarations, etc.). @@ -363,6 +364,10 @@ pub struct StatPair { #[derive(Debug, Default, Serialize, Deserialize, Clone, Add, Sub)] pub struct Position(isize, isize); +/// The grid size, as a static like a degenerate +// TODO[9]: Change to be at least initialized with the world ? +const GRID_SIZE: (i32, i32) = (1920, 1080); + impl Position { /// The euclidian distance between two points fn distance(&self, other: &Self) -> isize { @@ -373,6 +378,15 @@ impl Position { fn to_grid_distance(&self) -> (isize, isize) { (self.0 / 200, self.1 / 200) } + + /// Create a random position + /// None that there is no concept to either city or continent making this position rather unrelyable + // TODO[2]: Make a create_rng_from_town & create_rng_from_continents + pub fn create_rng(r: &mut ThreadRng) -> Result { + let x = r.random_range(0..GRID_SIZE.0); + let y = r.random_range(0..GRID_SIZE.1); + Ok(Self(x as isize, y as isize)) + } } /// A summary of the stats, only for display purposes #[allow(clippy::missing_docs_in_private_items)]