Coloring and diff
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good
Details
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good
Details
This commit is contained in:
parent
08b773698b
commit
e0ef469088
|
|
@ -142,6 +142,7 @@ impl Entity {
|
|||
.row(Some(HorizontalLine::new('├', '┤', '┼', '─')))
|
||||
.build(),
|
||||
)
|
||||
// .foreground_color(Some(cli_table::Color::Blue)) // Border Color
|
||||
.display()
|
||||
.map_err(|_e| EpochError::TableStringConversionError {
|
||||
name: self.name.clone(),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ impl FromStr for EntityDuration {
|
|||
let raw = s.trim().to_ascii_lowercase();
|
||||
|
||||
match raw.as_str() {
|
||||
"permanent" => Ok(EntityDuration::Permanent),
|
||||
"permanent" | "perm" => Ok(EntityDuration::Permanent),
|
||||
"done" => Ok(EntityDuration::Done),
|
||||
|
||||
// Handle the `duration:NNN` form.
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ impl EpochId {
|
|||
/// Return a new epoch Id derived from this one
|
||||
pub fn add_to_epoch(&self, other: i64) -> Self {
|
||||
Self {
|
||||
id: self.id.saturating_sub_signed(other),
|
||||
id: self.id.saturating_add_signed(other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@
|
|||
use crate::error::EpochError;
|
||||
use crate::thin_newtype;
|
||||
use crate::utils::RngLevel;
|
||||
use cli_table::CellStruct;
|
||||
use cli_table::Color;
|
||||
use cli_table::Style;
|
||||
use cli_table::Table;
|
||||
use colored::Colorize;
|
||||
use derive_more::Add;
|
||||
|
|
@ -41,14 +43,14 @@ pub struct OverallStats {
|
|||
/// **Purpose** - A single value summarizing all economic indicators.
|
||||
/// **Effect** - Drives tax revenue, spending power, and overall economic influence.
|
||||
/// **Source** - Sum of `industry`, `science`, `trade`, and other economic contributors.
|
||||
#[table(title = "DEM", color = "Color::Blue", bold)]
|
||||
#[table(title = "DEM", customize_fn = "color_cell_categories")]
|
||||
pub demographics: GenericStat,
|
||||
/// Population count.
|
||||
///
|
||||
/// **Purpose** - The number of citizens living in the entity.
|
||||
/// **Effect** - Determines resource consumption, tax base, and potential unrest.
|
||||
/// **Source** - Updated by the growth/decay formulas each turn.
|
||||
#[table(title = "POP")]
|
||||
#[table(title = "POP", customize_fn = "color_cell")]
|
||||
pub population: GenericStat,
|
||||
|
||||
/// Per-turn change in population.
|
||||
|
|
@ -56,7 +58,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - The growth rate of the population.
|
||||
/// **Effect** - Predicts future needs and signals potential social unrest.
|
||||
/// **Source** - Derived from `population`, `happiness`, and `stability`.
|
||||
#[table(title = "GRW")]
|
||||
#[table(title = "GRW", customize_fn = "color_cell")]
|
||||
pub growth_rate: GenericStat,
|
||||
|
||||
/// Crime level (0-1 scale).
|
||||
|
|
@ -64,7 +66,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - How frequently crimes occur.
|
||||
/// **Effect** - Can trigger riots and reduce stability.
|
||||
/// **Source** - Result of the crime function (influenced by class disparity and law enforcement).
|
||||
#[table(title = "CRM")]
|
||||
#[table(title = "CRM", customize_fn = "color_cell")]
|
||||
pub crime: GenericStat,
|
||||
|
||||
/// Base happiness of the population (0-1 scale).
|
||||
|
|
@ -72,7 +74,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - A measure of citizen contentment.
|
||||
/// **Effect** - Influences productivity, tax compliance, and unrest.
|
||||
/// **Source** - Output of the happiness function (affected by class, war, infrastructure).
|
||||
#[table(title = "HPY")]
|
||||
#[table(title = "HPY", customize_fn = "color_cell")]
|
||||
pub happiness: GenericStat,
|
||||
|
||||
// ──────────────────────── Economy ────────────────────────
|
||||
|
|
@ -81,7 +83,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - A single value summarizing all economic metrics.
|
||||
/// **Effect** - Drives revenue, spending, and empire-wide economic influence.
|
||||
/// **Source** - Sum of `food`, `industry`, `science`, `trade`, etc.
|
||||
#[table(title = "ECO", color = "Color::Blue", bold)]
|
||||
#[table(title = "ECO", customize_fn = "color_cell_categories")]
|
||||
pub economy: GenericStat,
|
||||
|
||||
/// Food produced by the entity.
|
||||
|
|
@ -89,7 +91,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Amount of consumable resources available.
|
||||
/// **Effect** - Keeps the population alive and productive.
|
||||
/// **Source** - `food = farm_yield + tech_level`.
|
||||
#[table(title = "FOD")]
|
||||
#[table(title = "FOD", customize_fn = "color_cell")]
|
||||
pub food: GenericStat,
|
||||
|
||||
/// Strength of the industry.
|
||||
|
|
@ -97,7 +99,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Industrial production capacity.
|
||||
/// **Effect** - Drives tax revenue and unit production.
|
||||
/// **Source** - `industry = factory_output + tech_level`.
|
||||
#[table(title = "IND")]
|
||||
#[table(title = "IND", customize_fn = "color_cell")]
|
||||
pub industry: GenericStat,
|
||||
|
||||
/// Scientific output.
|
||||
|
|
@ -105,7 +107,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Rate of research progress.
|
||||
/// **Effect** - Determines how quickly new technologies are unlocked.
|
||||
/// **Source** - `science = research_center_output + tech_level`.
|
||||
#[table(title = "SCI")]
|
||||
#[table(title = "SCI", customize_fn = "color_cell")]
|
||||
pub science: GenericStat,
|
||||
|
||||
/// Trade volume / exports.
|
||||
|
|
@ -113,7 +115,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Measure of export activity.
|
||||
/// **Effect** - Influences influence and wealth.
|
||||
/// **Source** - `trade = trade_network_output`.
|
||||
#[table(title = "TRD")]
|
||||
#[table(title = "TRD", customize_fn = "color_cell")]
|
||||
pub trade: GenericStat,
|
||||
// // ──────────────────────── Social ────────────────────────
|
||||
// /// Overall social prestige.
|
||||
|
|
@ -121,7 +123,7 @@ pub struct OverallStats {
|
|||
// /// **Purpose** - Reflects the cultural standing of the entity.
|
||||
// /// **Effect** - Affects diplomacy and citizen morale.
|
||||
// /// **Source** - Sum of `culture`, `education`, `tourism`, etc.
|
||||
// #[table(title = "SOC", color = "Color::Blue", bold)]
|
||||
// #[table(title = "SOC", color = "Color::Blue", bold, customize_fn = "color_cell")]
|
||||
// pub social: GenericStat,
|
||||
|
||||
// /// Cultural output from arts, theatres, museums, etc.
|
||||
|
|
@ -129,7 +131,7 @@ pub struct OverallStats {
|
|||
// /// **Purpose** - Measure of cultural production.
|
||||
// /// **Effect** - Drives tourism, prestige, and happiness.
|
||||
// /// **Source** - `culture = Σ(cultural_building_output)`.
|
||||
// #[table(title = "CLU")]
|
||||
// #[table(title = "CLU", customize_fn = "color_cell")]
|
||||
// pub culture: GenericStat,
|
||||
|
||||
// /// Level of education/literacy.
|
||||
|
|
@ -137,7 +139,7 @@ pub struct OverallStats {
|
|||
// /// **Purpose** - Measure of the citizenry's knowledge.
|
||||
// /// **Effect** - Improves productivity, science output, and reduces unrest.
|
||||
// /// **Source** - `education = Σ(education_building_output)`.
|
||||
// #[table(title = "EDU")]
|
||||
// #[table(title = "EDU", customize_fn = "color_cell")]
|
||||
// pub education: GenericStat,
|
||||
|
||||
// /// Tourism revenue.
|
||||
|
|
@ -145,7 +147,7 @@ pub struct OverallStats {
|
|||
// /// **Purpose** - Income generated by visitors.
|
||||
// /// **Effect** - Provides an additional income stream.
|
||||
// /// **Source** - `tourism = number_of_tourists x price_per_tourist`.
|
||||
// #[table(title = "TOR")]
|
||||
// #[table(title = "TOR", customize_fn = "color_cell")]
|
||||
// pub tourism: GenericStat,
|
||||
|
||||
// /// Cultural influence over the region.
|
||||
|
|
@ -153,7 +155,7 @@ pub struct OverallStats {
|
|||
// /// **Purpose** - Measure of soft power.
|
||||
// /// **Effect** - Grants diplomatic bonuses and increases sway in the empire.
|
||||
// /// **Source** - `influence = culture x population`.
|
||||
// #[table(title = "INF")]
|
||||
// #[table(title = "INF", customize_fn = "color_cell")]
|
||||
// pub influence: GenericStat,
|
||||
|
||||
// ──────────────────────── Military ────────────────────────
|
||||
|
|
@ -162,7 +164,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Composite measure of combat capability.
|
||||
/// **Effect** - Determines defensive and offensive strength.
|
||||
/// **Source** - Sum of `army`, `strength`, `fortification`, etc.
|
||||
#[table(title = "MIL", color = "Color::Blue", bold)]
|
||||
#[table(title = "MIL", customize_fn = "color_cell_categories")]
|
||||
pub military: GenericStat,
|
||||
|
||||
/// Number of battle-ready units.
|
||||
|
|
@ -170,7 +172,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Size of the active army.
|
||||
/// **Effect** - Directly dictates defense and attack potential.
|
||||
/// **Source** - Sum of all trained and equipped units.
|
||||
#[table(title = "ARM")]
|
||||
#[table(title = "ARM", customize_fn = "color_cell")]
|
||||
pub army: GenericStat,
|
||||
|
||||
/// Composite strength of the army.
|
||||
|
|
@ -178,7 +180,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Tech, training, and equipment bonuses aggregated.
|
||||
/// **Effect** - Determines combat effectiveness and required force to defeat an enemy.
|
||||
/// **Source** - `strength = Σ(unit_strength) x tech_bonus x training_bonus`.
|
||||
#[table(title = "STR")]
|
||||
#[table(title = "STR", customize_fn = "color_cell")]
|
||||
pub strength: GenericStat,
|
||||
|
||||
/// Defensive bonus from fortifications.
|
||||
|
|
@ -186,7 +188,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Wall and tower defenses.
|
||||
/// **Effect** - Adds a multiplier to overall defense.
|
||||
/// **Source** - `fortification = Σ(fortification_building_bonus)`.
|
||||
#[table(title = "FRT")]
|
||||
#[table(title = "FRT", customize_fn = "color_cell")]
|
||||
pub fortification: GenericStat,
|
||||
|
||||
/// Threat level facing the entity.
|
||||
|
|
@ -194,7 +196,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Likelihood of being attacked.
|
||||
/// **Effect** - Triggers early warning alerts and strategic decisions.
|
||||
/// **Source** - `threat = (enemy_proximity + enemy_strength) / defense`.
|
||||
#[table(title = "THR")]
|
||||
#[table(title = "THR", customize_fn = "color_cell")]
|
||||
pub threat: GenericStat,
|
||||
|
||||
// ──────────────────────── Infrastructure ────────────────────────
|
||||
|
|
@ -203,7 +205,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Overall built-environment capacity.
|
||||
/// **Effect** - Supports population size and efficiency.
|
||||
/// **Source** - Sum of all infrastructure components.
|
||||
#[table(title = "IFR", color = "Color::Blue", bold)]
|
||||
#[table(title = "IFR", customize_fn = "color_cell_categories")]
|
||||
pub infrastructure: GenericStat,
|
||||
|
||||
/// Bureaucratic power.
|
||||
|
|
@ -211,7 +213,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Efficiency of the city's administrative machinery.
|
||||
/// **Effect** - Improves resource management and policy implementation.
|
||||
/// **Source** - `bureaucracy = Σ(bureaucracy_building_output)`.
|
||||
#[table(title = "BUR")]
|
||||
#[table(title = "BUR", customize_fn = "color_cell")]
|
||||
pub bureaucracy: GenericStat,
|
||||
|
||||
/// Transportation level.
|
||||
|
|
@ -219,7 +221,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Availability and quality of transport infrastructure.
|
||||
/// **Effect** - Impacts logistics, mobility, and trade.
|
||||
/// **Source** - `transportation = Σ(transport_building_output)`.
|
||||
#[table(title = "TRP")]
|
||||
#[table(title = "TRP", customize_fn = "color_cell")]
|
||||
pub transportation: GenericStat,
|
||||
|
||||
/// Sprawl / urban density.
|
||||
|
|
@ -227,7 +229,7 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Measure of city sprawl and clutter.
|
||||
/// **Effect** - Affects health, happiness, and infrastructure efficiency.
|
||||
/// **Source** - `sprawl = Σ(sprawl_factor)`.
|
||||
#[table(title = "SPR")]
|
||||
#[table(title = "SPR", customize_fn = "color_cell")]
|
||||
pub sprawl: GenericStat,
|
||||
|
||||
/// Health infrastructure quality.
|
||||
|
|
@ -235,9 +237,28 @@ pub struct OverallStats {
|
|||
/// **Purpose** - Public health capacity.
|
||||
/// **Effect** - Affects population health and can generate unrest.
|
||||
/// **Source** - `health = output_of_health_function` (influenced by sanitation, disease spread, etc.).
|
||||
#[table(title = "HLT")]
|
||||
#[table(title = "HLT", customize_fn = "color_cell")]
|
||||
pub health: GenericStat,
|
||||
}
|
||||
|
||||
/// Color the base cells
|
||||
fn color_cell(cell: CellStruct, value: &GenericStat) -> CellStruct {
|
||||
match (**value).cmp(&0) {
|
||||
std::cmp::Ordering::Less => cell.foreground_color(Some(Color::Red)),
|
||||
std::cmp::Ordering::Equal => cell,
|
||||
std::cmp::Ordering::Greater => cell, //.foreground_color(Some(Color::Green)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Color the cell categories
|
||||
fn color_cell_categories(cell: CellStruct, value: &GenericStat) -> CellStruct {
|
||||
match (**value).cmp(&0) {
|
||||
std::cmp::Ordering::Less => cell.foreground_color(Some(Color::Red)).bold(true),
|
||||
std::cmp::Ordering::Equal => cell.foreground_color(Some(Color::Blue)).bold(true),
|
||||
std::cmp::Ordering::Greater => cell.foreground_color(Some(Color::Green)).bold(true),
|
||||
}
|
||||
}
|
||||
|
||||
impl OverallStats {
|
||||
/// Create Stats with a given rng distribution
|
||||
// TODO[6]: Use an iterator over the stat enum
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ impl FromStr for ListStats {
|
|||
"cri" | "crim" | "crimes" => Ok(ListStats::Crime),
|
||||
"hapn" | "happines" | "hap" => Ok(ListStats::Happiness),
|
||||
"eco" | "economy" | "econ" => Ok(ListStats::Economy),
|
||||
"food" | "fo" | "agr" | "agri" => Ok(ListStats::Food),
|
||||
"food" | "fo" | "agr" | "agri" | "fod" => Ok(ListStats::Food),
|
||||
"industry" | "indus" | "ind" => Ok(ListStats::Industry),
|
||||
"science" | "sci" | "sc" => Ok(ListStats::Science),
|
||||
"trade" | "trd" | "tr" => Ok(ListStats::Trade),
|
||||
|
|
|
|||
Loading…
Reference in New Issue