diff --git a/bin_efo/src/main.rs b/bin_efo/src/main.rs index e7f70c2..018696c 100644 --- a/bin_efo/src/main.rs +++ b/bin_efo/src/main.rs @@ -22,6 +22,7 @@ #![warn(missing_docs, clippy::missing_docs_in_private_items)] #![deny(clippy::unwrap_used)] + use clap::{ArgAction, Parser, Subcommand}; use lib_efo::naming::NAMING; @@ -71,6 +72,7 @@ enum TopLevelCmd { /// Parses the command‑line arguments and dispatches to the selected /// sub‑command. Errors returned by the sub‑command handlers are shown /// in stdout and returned as a `miette::Result<()>`. +#[allow(clippy::unwrap_used)] fn main() -> miette::Result<()> { env_logger::init(); // 1. Generate a character name diff --git a/lib_efo/naming.json b/lib_efo/naming.json index 808a66d..ebcba9f 100644 --- a/lib_efo/naming.json +++ b/lib_efo/naming.json @@ -432,7 +432,7 @@ }, { "name": "earthquake", - "description": "A massive quake ripples across the continent, cracking roads and collapsing half the cities.", + "description": "A massive quake ripples across the region.", "stats": [ { "stat": "Infrastructure", "value": -15 }, { "stat": "Population", "value": -10 }, @@ -511,15 +511,6 @@ { "stat": "Trade", "value": -10 } ] }, - { - "name": "town_fall_of_mages", - "description": "A rogue wizard unleashes a catastrophic spell, destroying a town's center and leaving a scar in reality.", - "stats": [ - { "stat": "Science", "value": -8 }, - { "stat": "Population", "value": -10 }, - { "stat": "Fortification", "value": -6 } - ] - }, { "name": "region_wind_of_gods", "description": "A relentless gale from the gods tears through the region, scattering armies and wrecking supply lines.", @@ -546,6 +537,502 @@ { "stat": "Crime", "value": 7 }, { "stat": "Population", "value": -5 } ] + }, + { + "name": "city_corruption_scandal", + "description": "A high‑ranking magistrate is discovered embezzling city funds, sparking public outrage and a demand for accountability.", + "stats": [ + { "stat": "Economy", "value": -9 }, + { "stat": "Bureaucracy", "value": -7 }, + { "stat": "Crime", "value": 5 } + ] + }, + { + "name": "city_tax_reform", + "description": "The council implements a sweeping tax overhaul that raises revenue but triggers protests among merchants.", + "stats": [ + { "stat": "Economy", "value": 12 }, + { "stat": "Population", "value": -4 }, + { "stat": "Crime", "value": 3 } + ] + }, + { + "name": "city_watch_mutiny", + "description": "The city guard, disgruntled by unpaid wages, mutinies and seizes control of the main gate.", + "stats": [ + { "stat": "Military", "value": -6 }, + { "stat": "Crime", "value": 8 }, + { "stat": "Population", "value": -2 } + ] + }, + { + "name": "city_water_contamination", + "description": "Tainted water leaks into the municipal supply, causing a sudden spike in illnesses.", + "stats": [ + { "stat": "Health", "value": -14 }, + { "stat": "Population", "value": -5 }, + { "stat": "Bureaucracy", "value": -3 } + ] + }, + { + "name": "city_bureaucratic_bureaucracy", + "description": "A new procedural reform overhauls city administration, halting projects for months and stalling economic growth.", + "stats": [ + { "stat": "Infrastructure", "value": -7 }, + { "stat": "Economy", "value": -5 }, + { "stat": "Bureaucracy", "value": 10 } + ] + }, + { + "name": "city_guild_suppression", + "description": "The council cracks down on the city’s merchant guilds, confiscating goods and driving merchants underground.", + "stats": [ + { "stat": "Trade", "value": -11 }, + { "stat": "Crime", "value": 6 }, + { "stat": "Population", "value": -3 } + ] + }, + { + "name": "city_civic_riot", + "description": "An assembly of disgruntled workers erupts into a violent riot, tearing through market stalls and public buildings.", + "stats": [ + { "stat": "Infrastructure", "value": -12 }, + { "stat": "Happiness", "value": -9 }, + { "stat": "Crime", "value": 10 } + ] + }, + { + "name": "city_public_health_crisis", + "description": "A mysterious disease spreads through the city’s crowded streets, overwhelming the local infirmaries.", + "stats": [ + { "stat": "Health", "value": -16 }, + { "stat": "Population", "value": -8 }, + { "stat": "Happiness", "value": -7 } + ] + }, + { + "name": "city_transport_infrastructure_fail", + "description": "The city’s main aqueduct collapses, cutting off water supply to half the districts.", + "stats": [ + { "stat": "Infrastructure", "value": -15 }, + { "stat": "Population", "value": -4 }, + { "stat": "Bureaucracy", "value": -2 } + ] + }, + { + "name": "city_festival_corruption", + "description": "During a grand city festival, officials accept bribes to award contracts, compromising civic integrity.", + "stats": [ + { "stat": "Bureaucracy", "value": -8 }, + { "stat": "Crime", "value": 4 }, + { "stat": "Happiness", "value": -3 } + ] + }, + { + "name": "city_gold_exodus", + "description": "A sudden discovery of gold in the hinterlands draws merchants away, leaving local markets starved of currency.", + "stats": [ + { "stat": "Economy", "value": -11 }, + { "stat": "Trade", "value": -8 }, + { "stat": "Population", "value": -2 } + ] + }, + { + "name": "regional_drought", + "description": "An extended dry spell cripples crop yields, driving up food prices and crippling the agrarian economy.", + "stats": [ + { "stat": "Food", "value": -15 }, + { "stat": "Economy", "value": -9 }, + { "stat": "Happiness", "value": -5 } + ] + }, + { + "name": "city_tariff_levy", + "description": "The city council imposes a high tariff on imported goods to boost local industry, sparking backlash from merchants.", + "stats": [ + { "stat": "Trade", "value": -10 }, + { "stat": "Economy", "value": 7 }, + { "stat": "Crime", "value": 4 } + ] + }, + { + "name": "market_hoarding", + "description": "A powerful merchant cartel hoards staple goods, manipulating prices to inflate profits at the cost of ordinary citizens.", + "stats": [ + { "stat": "Economy", "value": -8 }, + { "stat": "Trade", "value": -7 }, + { "stat": "Population", "value": -3 } + ] + }, + { + "name": "industrial_explosion", + "description": "A catastrophic blast at the main ironworks destroys equipment and halts production for months.", + "stats": [ + { "stat": "Industry", "value": -18 }, + { "stat": "Economy", "value": -12 }, + { "stat": "Population", "value": -4 } + ] + }, + { + "name": "foreign_investment_boom", + "description": "A foreign dynasty invests heavily in local mining, sparking a surge in jobs and wealth but also widening inequality.", + "stats": [ + { "stat": "Industry", "value": 12 }, + { "stat": "Economy", "value": 9 }, + { "stat": "Crime", "value": 5 } + ] + }, + { + "name": "tax_evasion_scheme", + "description": "A sophisticated tax evasion network siphons off a large portion of city revenue, forcing austerity measures.", + "stats": [ + { "stat": "Economy", "value": -10 }, + { "stat": "Bureaucracy", "value": -6 }, + { "stat": "Population", "value": -2 } + ] + }, + { + "name": "currency_devaluation", + "description": "The city’s coinage is devalued by a sudden policy shift, causing imported goods to skyrocket in price.", + "stats": [ + { "stat": "Economy", "value": -13 }, + { "stat": "Trade", "value": -9 }, + { "stat": "Health", "value": -4 } + ] + }, + { + "name": "artisan_fair_success", + "description": "A grand artisan fair attracts wealthy patrons, boosting local crafts and increasing export revenues.", + "stats": [ + { "stat": "Industry", "value": 8 }, + { "stat": "Economy", "value": 6 }, + { "stat": "Population", "value": 2 } + ] + }, + { + "name": "resource_piracy", + "description": "Sea‑borne raiders seize a shipment of precious stones destined for the city, flooding the market with counterfeit goods.", + "stats": [ + { "stat": "Trade", "value": -12 }, + { "stat": "Economy", "value": -7 }, + { "stat": "Crime", "value": 9 } + ] + }, + { + "name": "steel_furnace_overheat", + "description": "A critical failure in the city’s primary steel furnace sparks an uncontrollable fire, destroying production lines.", + "stats": [ + { "stat": "Industry", "value": -17 }, + { "stat": "Economy", "value": -10 }, + { "stat": "Population", "value": -3 } + ] + }, + { + "name": "artisan_tech_innovation", + "description": "A guild of master craftsmen invents a new forging technique that doubles output and lowers raw material usage.", + "stats": [ + { "stat": "Industry", "value": 14 }, + { "stat": "Economy", "value": 8 }, + { "stat": "Crime", "value": 3 } + ] + }, + { + "name": "coal_mine_sabotage", + "description": "Covert saboteurs collapse a major coal shaft, halting fuel supply to all local factories for weeks.", + "stats": [ + { "stat": "Industry", "value": -15 }, + { "stat": "Economy", "value": -9 }, + { "stat": "Crime", "value": 6 } + ] + }, + { + "name": "foreign_factory_purchase", + "description": "A foreign conglomerate purchases the city’s largest textile mill, imposing new quotas that reduce local employment.", + "stats": [ + { "stat": "Industry", "value": -9 }, + { "stat": "Economy", "value": -7 }, + { "stat": "Population", "value": -4 } + ] + }, + { + "name": "blacksmiths_rebel", + "description": "Skilled blacksmiths organize a strike demanding better wages, halting the production of critical weapons.", + "stats": [ + { "stat": "Industry", "value": -10 }, + { "stat": "Military", "value": -5 }, + { "stat": "Crime", "value": 4 } + ] + }, + { + "name": "machine_revolution", + "description": "The introduction of automated presses in the leather works cuts labor costs but renders many artisans obsolete.", + "stats": [ + { "stat": "Industry", "value": 11 }, + { "stat": "Population", "value": -5 }, + { "stat": "Crime", "value": 3 } + ] + }, + { + "name": "bottleneck_transportation", + "description": "The city’s main rail line is seized by gangsters, disrupting the flow of raw materials to factories.", + "stats": [ + { "stat": "Infrastructure", "value": -8 }, + { "stat": "Industry", "value": -6 }, + { "stat": "Crime", "value": 7 } + ] + }, + { + "name": "energy_rationing", + "description": "A sudden spike in electricity prices forces factories to shut down during peak hours, halving output.", + "stats": [ + { "stat": "Industry", "value": -13 }, + { "stat": "Economy", "value": -8 }, + { "stat": "Population", "value": -2 } + ] + }, + { + "name": "export_tariff_relief", + "description": "An unexpected removal of export tariffs on metal goods opens new markets, boosting production rates.", + "stats": [ + { "stat": "Industry", "value": 12 }, + { "stat": "Trade", "value": 9 }, + { "stat": "Economy", "value": 6 } + ] + }, + { + "name": "smelter_piracy", + "description": "A band of raiders captures a shipment of precious ores destined for the city, flooding the market with cheap counterfeit.", + "stats": [ + { "stat": "Industry", "value": -11 }, + { "stat": "Trade", "value": -7 }, + { "stat": "Crime", "value": 10 } + ] + }, + { + "name": "frontline_betrayal", + "description": "A key vanguard commander secretly defects, scattering a significant portion of the army and boosting enemy threat.", + "stats": [ + { "stat": "Army", "value": -10 }, + { "stat": "Military", "value": -6 }, + { "stat": "Threat", "value": 8 } + ] + }, + { + "name": "naval_battle_victory", + "description": "The city’s navy defeats a hostile threat, securing coastal trade routes and striking a blow to the enemy’s threat level.", + "stats": [ + { "stat": "Military", "value": 12 }, + { "stat": "Threat", "value": -9 }, + { "stat": "Economy", "value": 4 } + ] + }, + { + "name": "disease_in_soldiers", + "description": "A virulent pestilence breaks out among the ranks, lowering army numbers and damaging overall health.", + "stats": [ + { "stat": "Army", "value": -14 }, + { "stat": "Health", "value": -10 }, + { "stat": "Military", "value": -5 } + ] + }, + { + "name": "recruitment_panic", + "description": "A surge of conscripts floods the army, but poor training causes a sharp drop in combat effectiveness.", + "stats": [ + { "stat": "Army", "value": 8 }, + { "stat": "Strength", "value": -9 }, + { "stat": "Military", "value": -3 } + ] + }, + { + "name": "training_expedition", + "description": "A focused military academy expedition hones the troops’ skills, raising overall strength at the cost of a temporary manpower drain.", + "stats": [ + { "stat": "Strength", "value": 11 }, + { "stat": "Army", "value": -6 }, + { "stat": "Military", "value": 4 } + ] + }, + { + "name": "spy_operation_success", + "description": "A covert spy network uncovers threats around, reducing the threat level and providing a tactical advantage.", + "stats": [ + { "stat": "Threat", "value": -10 }, + { "stat": "Military", "value": 3 }, + { "stat": "Strength", "value": 4 } + ] + }, + { + "name": "war_taxes_harsh", + "description": "The council imposes severe war taxes to fund the army, inflating military budgets but cracking public happiness.", + "stats": [ + { "stat": "Military", "value": 9 }, + { "stat": "Happiness", "value": -8 }, + { "stat": "Economy", "value": -5 } + ] + }, + { + "name": "battlefield_innovation", + "description": "A revolutionary tactic is adopted on the front lines, dramatically boosting army strength and lowering enemy threat.", + "stats": [ + { "stat": "Strength", "value": 13 }, + { "stat": "Threat", "value": -8 }, + { "stat": "Military", "value": 2 } + ] + }, + { + "name": "trade_agreement", + "description": "The city brokered a favorable trade pact with a neighboring realm, opening new markets for local goods.", + "stats": [ + { "stat": "Trade", "value": 12 }, + { "stat": "Economy", "value": 8 }, + { "stat": "Population", "value": 3 } + ] + }, + { + "name": "peace_council", + "description": "A diplomatic summit ends a long‑standing border conflict, reducing threat levels and fostering cultural exchange.", + "stats": [ + { "stat": "Trade", "value": 10 }, + { "stat": "Culture", "value": 7 }, + { "stat": "Happiness", "value": 5 } + ] + }, + { + "name": "bounty_hunt_success", + "description": "A coordinated hunt eliminates a notorious calamity, restoring safety to nearby villages.", + "stats": [ + { "stat": "Crime", "value": -12 }, + { "stat": "Threat", "value": -8 }, + { "stat": "Happiness", "value": 4 } + ] + }, + { + "name": "technological_breakthrough", + "description": "Inventors in the city unveiled new technologies with huge applications in the industrial field.", + "stats": [ + { "stat": "Science", "value": 15 }, + { "stat": "Industry", "value": 6 }, + { "stat": "Economy", "value": 5 } + ] + }, + { + "name": "festival_of_luxury", + "description": "A grand festival draws wealthy merchants and foreign dignitaries, boosting tourism and local pride.", + "stats": [ + { "stat": "Tourism", "value": 13 }, + { "stat": "Economy", "value": 7 }, + { "stat": "Happiness", "value": 6 } + ] + }, + { + "name": "military_training_expedition", + "description": "An intensive training expedition sharpens the army’s tactics, increasing overall strength without cost.", + "stats": [ + { "stat": "Strength", "value": 12 }, + { "stat": "Army", "value": 3 }, + { "stat": "Military", "value": 4 } + ] + }, + { + "name": "health_initiative", + "description": "A citywide vaccination campaign eradicates a deadly plague, dramatically improving public health.", + "stats": [ + { "stat": "Health", "value": 16 }, + { "stat": "Population", "value": 4 }, + { "stat": "Happiness", "value": 5 } + ] + }, + { + "name": "artisan_summit", + "description": "A gathering of master artisans leads to the sharing of techniques that double production efficiency.", + "stats": [ + { "stat": "Industry", "value": 14 }, + { "stat": "Economy", "value": 6 }, + { "stat": "Population", "value": 2 } + ] + }, + { + "name": "infrastructure_repair", + "description": "A massive repair drive restores crumbling roads and bridges, slashing travel time and boosting trade.", + "stats": [ + { "stat": "Infrastructure", "value": 15 }, + { "stat": "Trade", "value": 5 }, + { "stat": "Economy", "value": 3 } + ] + }, + { + "name": "cultural_exposition", + "description": "The city hosts an international exposition, showcasing its heritage and attracting scholars and tourists alike.", + "stats": [ + { "stat": "Culture", "value": 12 }, + { "stat": "Tourism", "value": 10 }, + { "stat": "Happiness", "value": 4 }, + { "stat": "Influence", "value": 4 } + ] + }, + { + "name": "great_earthquake", + "description": "A massive quake rips through the city, shattering buildings, collapsing bridges, and killing thousands.", + "stats": [ + { "stat": "Infrastructure", "value": -20 }, + { "stat": "Population", "value": -18 }, + { "stat": "Happiness", "value": -15 } + ] + }, + { + "name": "plague_of_scorpion", + "description": "A deadly disease spreads through the populace, turning citizens into venom‑infused monsters.", + "stats": [ + { "stat": "Health", "value": -22 }, + { "stat": "Population", "value": -16 }, + { "stat": "Crime", "value": 8 } + ] + }, + { + "name": "oil_fire_in_barnyard", + "description": "An oil storage depot explodes, sending a wave of fire over the city that reduces the army’s morale and strength.", + "stats": [ + { "stat": "Industry", "value": -19 }, + { "stat": "Military", "value": -12 }, + { "stat": "Threat", "value": 10 } + ] + }, + { + "name": "fire_of_sacred_temple", + "description": "The city’s most revered temple is consumed by a supernatural inferno, spilling holy ash into the streets and igniting widespread panic.", + "stats": [ + { "stat": "Culture", "value": -15 }, + { "stat": "Threat", "value": 12 }, + { "stat": "Happiness", "value": -6 } + ] + }, + { + "name": "cursed_great_flood", + "description": "An unseasonal deluge swallows the city, flooding every district, destroying crops, and causing widespread disease.", + "stats": [ + { "stat": "Food", "value": -20 }, + { "stat": "Economy", "value": -17 }, + { "stat": "Threat", "value": 13 } + ] + }, + { + "name": "massive_barricade_breach", + "description": "A minor calamity overpowers the city’s fortifications, unleashing a wave of slaughter and chaos.", + "stats": [ + { "stat": "Fortification", "value": -19 }, + { "stat": "Threat", "value": 20 }, + { "stat": "Happiness", "value": -12 } + ] + }, + { + "name": "invasion_of_the_undead", + "description": "A horde of reanimated skeletons breaks through the gates, attacking citizens and military alike.", + "stats": [ + { "stat": "Threat", "value": 25 }, + { "stat": "Crime", "value": -10 }, + { "stat": "Population", "value": -12 } + ] } ] } diff --git a/lib_efo/src/naming.rs b/lib_efo/src/naming.rs index 1d24bcd..02aa54c 100644 --- a/lib_efo/src/naming.rs +++ b/lib_efo/src/naming.rs @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf}; use crate::stats::StatPair; /// The structure that holds everything we need for name generation. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Default)] pub struct NamingData { /// First name for characters pub first_names: Vec, @@ -43,40 +43,6 @@ pub struct EventDescription { pub stats: Vec, } -// /// A generic stat pair with (stat, value), used mainly for clap -// /// Accepts two forms -// /// 1. "cri 10" (two separate tokens) -// /// 2. "cri:10" (one token with a separator) -// pub struct StatPair(ListStats, GenericStat); -// -// pub enum ListStats { -// Demographics, -// Population, -// Growthrate, -// Crime, -// Happiness, -// Economy, -// Food, -// Industry, -// Science, -// Trade, -// Social, -// Culture, -// Education, -// Tourism, -// Influence, -// Military, -// Army, -// Strength, -// Fortification, -// Threat, -// Infrastructure, -// Bureaucracy, -// Transportation, -// Sprawl, -// Health, -// } - impl NamingData { /// Load the data from the supplied path. /// If the file does **not** exist, a default (embedded) version is written @@ -123,14 +89,12 @@ impl NamingData { format!("{}{}", prefix, suffix).trim().to_string() } - // /// Pick a random event idea (you can reuse this or make a dedicated method). - // pub fn random_event_idea(&self) -> &str { - // let mut rng = rand::rng(); - // self.event_ideas - // .choose(&mut rng) - // .map(String::as_str) - // .unwrap_or("No Event.") - // } + /// Pick a random event idea (you can reuse this or make a dedicated method). + #[allow(clippy::unwrap_used)] + pub fn random_event_idea(&self) -> &EventDescription { + let mut rng = rand::rng(); + self.event_ideas.choose(&mut rng).unwrap() + } /// Generates something like: /// “The Magnificent Sir Aurelius Blackthorn the Swift” @@ -181,3 +145,34 @@ pub static NAMING: Lazy = Lazy::new(|| { let path = naming_file_path(); NamingData::load_or_create(path).expect("Failed to load naming data") }); + +#[cfg(test)] +mod tests { + use super::*; + // use std::fs::{self, File}; + // use std::io::Write; + // use std::path::PathBuf; + + /// Helper that deserialises the embedded default JSON so we can compare against it. + fn default_data() -> NamingData { + serde_json::from_str::(DEFAULT_JSON_STR) + .expect("DEFAULT_JSON_STR should be a valid JSON") + } + + #[test] + fn try_load() {} + #[test] + fn basic_testing() { + // 1. Generate a character name + let character = NAMING.generate_character_name(); + println!("Character: {}", character); + + // 2. Generate a town name + let town = NAMING.generate_town_name(); + println!("Town: {}", town); + + // 3. Pick an event idea + let event = NAMING.generate_long_character_name(); + println!("Event idea: {}", event); + } +} diff --git a/lib_efo/src/stats.rs b/lib_efo/src/stats.rs index e74555d..4290d4a 100644 --- a/lib_efo/src/stats.rs +++ b/lib_efo/src/stats.rs @@ -291,7 +291,12 @@ pub struct MetaStats { /// 1. "cri 10" (two separate tokens) /// 2. "cri:10" (one token with a separator) #[derive(Debug, Serialize, Deserialize)] -pub struct StatPair(ListStats, GenericStat); +pub struct StatPair { + /// The stat selected + pub stat: ListStats, + /// The value of the modifier + pub value: GenericStat, +} /// Structure used to indicate position, possess nice helper methods to use as is in the program #[derive(Debug, Default, Serialize, Deserialize, Clone)] diff --git a/lib_efo/src/stats/implementations.rs b/lib_efo/src/stats/implementations.rs index 5eabfcb..b55f8ad 100644 --- a/lib_efo/src/stats/implementations.rs +++ b/lib_efo/src/stats/implementations.rs @@ -226,7 +226,10 @@ impl FromStr for StatPair { let value: isize = val_str .parse() .map_err(|_| EpochError::IllFormedStatQualifier(val_str.to_owned()))?; - Ok(StatPair(stat, stats::GenericStat(value))) + Ok(StatPair { + stat, + value: stats::GenericStat(value), + }) } } @@ -272,8 +275,8 @@ pub(crate) mod test { /// Helper that asserts that a stat pair string parses to the expected `StatPair`. fn assert_pair_ok(input: &str, expected_stat: ListStats, expected_val: isize) { let pair = StatPair::from_str(input).expect("should parse"); - assert_eq!(pair.0, expected_stat, "stat mismatch"); - assert_eq!(pair.1.0, expected_val, "value mismatch"); + assert_eq!(pair.stat, expected_stat, "stat mismatch"); + assert_eq!(pair.value.0, expected_val, "value mismatch"); } #[test] fn test_stat_pair_parsing() {