From c41604b505e80e7300f1508cdefd714ab6a2bed3 Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Tue, 3 Dec 2024 08:37:25 -0500 Subject: [PATCH] Development commit. Starting character systems and definitions. --- Cargo.lock | 194 ++++++++++++++++++++++++++++------------------ Cargo.toml | 4 +- src/characters.rs | 62 +++++++++++++++ src/events.rs | 16 ++++ src/main.rs | 173 ++++++++++++++++++++++++++++++++++++++++- src/utils.rs | 77 ++++++++++++++++++ 6 files changed, 450 insertions(+), 76 deletions(-) create mode 100644 src/characters.rs create mode 100644 src/events.rs create mode 100644 src/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 90de865..df6d0e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,142 +2,188 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +dependencies = [ + "serde", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "culling_of_the_sheep" version = "0.1.0" dependencies = [ - "terminal_size", + "rand", + "ron", + "serde", ] [[package]] -name = "errno" -version = "0.3.9" +name = "getrandom" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ + "cfg-if", "libc", - "windows-sys 0.52.0", + "wasi", ] [[package]] name = "libc" -version = "0.2.165" +version = "0.2.166" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb4d3d38eab6c5239a362fa8bae48c03baf980a6e7079f063942d563ef3533e" +checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" [[package]] -name = "linux-raw-sys" -version = "0.4.14" +name = "ppv-lite86" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "rustix" -version = "0.38.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "bitflags", - "errno", "libc", - "linux-raw-sys", - "windows-sys 0.52.0", + "rand_chacha", + "rand_core", ] [[package]] -name = "terminal_size" -version = "0.4.0" +name = "rand_chacha" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f599bd7ca042cfdf8f4512b277c02ba102247820f9d9d4a9f521f496751a6ef" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "rustix", - "windows-sys 0.59.0", + "ppv-lite86", + "rand_core", ] [[package]] -name = "windows-sys" -version = "0.52.0" +name = "rand_core" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "windows-targets", + "getrandom", ] [[package]] -name = "windows-sys" -version = "0.59.0" +name = "ron" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ - "windows-targets", + "base64", + "bitflags", + "serde", + "serde_derive", ] [[package]] -name = "windows-targets" -version = "0.52.6" +name = "serde" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "serde_derive", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" +name = "serde_derive" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" +name = "syn" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] -name = "windows_i686_gnu" -version = "0.52.6" +name = "unicode-ident" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "windows_i686_msvc" -version = "0.52.6" +name = "zerocopy" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] [[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" +name = "zerocopy-derive" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index d4ddee3..391b495 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -terminal_size = "0.4" \ No newline at end of file +serde = {version = "1.0", features = ["derive"]} +rand = "0.8" +ron = "0.8" \ No newline at end of file diff --git a/src/characters.rs b/src/characters.rs new file mode 100644 index 0000000..73b66e1 --- /dev/null +++ b/src/characters.rs @@ -0,0 +1,62 @@ +#[derive(Debug)] +pub struct Character { + pub name: &'static str, + pub standing: Standing +} + +#[derive(Debug)] +pub struct Standing { + pub society: i8, + pub court: i8, + pub friends: Vec<&'static People>, + pub enemies: Vec<&'static People> +} + +impl Standing { + pub fn calculate (mut self: Standing) -> i8 { + // Drain society points if mostly disliked. + if self.friends.len() < self.enemies.len() { + self.society = self.society.clone() - 2 + } + + // Points + { + self.friends.len() as i8 + - self.enemies.len() as i8 + + self.court + + self.society + } + } +} + +#[derive(Debug)] +pub enum People { + AbigailWilliams(Option), + AnnPutnam(Option), + BettyParris(Option), + DeputyGovernorDanforth(Option), + ElizabethProctor(Option), + EzekielCheever(Option), + FrancisNurse(Option), + RebeccaNurse(Option), + GilesCorey(Option), + GoodyOsborne(Option), + JohnProctor(Option), + JudgeHathorne(Option), + MaryWarren(Option), + MarshalHerrick(Option), + MarthaCorey(Option), + MercyLewis(Option), + ReverendParris(Option), + ReverendJohnHale(Option), + SarahGood(Option), + SusannaWalcott(Option), + ThomasPutnam(Option), + Tituba(Option) +} + +#[derive(Debug)] +pub enum SurvivalStatus { + PlayerLived, + PlayerDied +} \ No newline at end of file diff --git a/src/events.rs b/src/events.rs new file mode 100644 index 0000000..46306c1 --- /dev/null +++ b/src/events.rs @@ -0,0 +1,16 @@ +use crate::characters::{ + Character, + SurvivalStatus +}; + +pub fn get_event() {} + +pub struct Trial; + +impl Trial { + pub fn handle(&self, &mut player: &mut Character) -> SurvivalStatus { + let player_status = SurvivalStatus::PlayerDied; + + player_status + } +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..5c5b116 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,174 @@ +mod characters; +mod events; +mod utils; + +use characters::{ + Character, + People, + Standing, + SurvivalStatus +}; +use events::get_event; +use std::vec; +use utils::{ + fmt_args, + ArgType, + FlagType +}; + +//Number of game rounds. +const ROUNDS: u8 = 15; + fn main() { - println!("Hello, world!"); + let cmd_args = dbg!(fmt_args()); + let mut characters = build_characters(); + + // Set player default values based on gamemode. + let mut player = dbg!(build_player(dbg!(get_gamemode(cmd_args)))); + let end_status = SurvivalStatus::PlayerLived; + + for _r in 0..=ROUNDS { + get_event().handle(player); + + if player.standing.calculate() <= 0 { + let mut trial = events::Trial; + + match trial.handle(&mut player) { + SurvivalStatus::PlayerDied => { + end_status = SurvivalStatus::PlayerDied + }, + _ => () + } + } + }; } + +#[derive(Debug)] +enum Gamemode { + //Easy + Abigail, + //Normal + MaryWarren, + //Hard + JohnProctor, + //Just dead. + GoodyOsborne +} + +fn build_characters() -> Vec { + vec![ + People::AbigailWilliams(Some(Character { + name: "Abigail Williams", + standing: Standing { + society: 10, + court: 10, + friends: vec![ + &People::BettyParris(None), + &People::DeputyGovernorDanforth(None), + &People::ReverendParris(None), + ], + enemies: vec![ + &People::ElizabethProctor(None), + &People::JohnProctor(None), + &People::ReverendJohnHale(None) + ] + } + })), + People::BettyParris(Some(Character { + name: "Betty Parris", + standing: Standing { + society: 10, + court: 10, + friends: vec![ + &People::AbigailWilliams(None), + &People::ReverendParris(None) + ], + enemies: vec![ + &People::JohnProctor(None), + &People::ElizabethProctor(None) + ] + } + })), + People::ElizabethProctor(Some(Character{ + name: "Elizabeth Proctor", + standing: Standing { + society: 10, + court: 5, + friends: vec![ + &People::FrancisNurse(None), + &People::GilesCorey(None), + &People::JohnProctor(None), + &People::RebeccaNurse(None), + &People::ReverendJohnHale(None) + ], + enemies: vec![ + &People::AbigailWilliams(None), + &People::DeputyGovernorDanforth(None), + &People::EzekielCheever(None) + ] + } + })) + ] +} + +fn build_player(gamemode: Gamemode) -> Character { + Character { + name: "You", + standing: match gamemode { + Gamemode::Abigail => Standing { + society: 10, + court: 10, + friends: vec![], + enemies: vec![] + }, + Gamemode::MaryWarren => Standing { + society: 5, + court: 5, + friends: vec![], + enemies: vec![] + }, + Gamemode::JohnProctor => Standing { + society: 2, + court: 2, + friends: vec![], + enemies: vec![] + }, + Gamemode::GoodyOsborne => Standing { + society: -15, + court: -5, + friends: vec![], + enemies: vec![] + } + } + } +} + +fn get_gamemode(cmd_args: Vec) -> Gamemode { + if cmd_args.len() != 1 { + match &cmd_args[1] { + ArgType::Command(c) => match c.as_str() { + "abigail" => Gamemode::Abigail, + "john_proctor" => Gamemode::JohnProctor, + "goody_osborne" => Gamemode::GoodyOsborne, + _ => Gamemode::MaryWarren + }, + ArgType::Flag(f) => match f { + FlagType::Long(l) => match l.as_str() { + "abigail" => Gamemode::Abigail, + "john-proctor" => Gamemode::JohnProctor, + "goody-osborne" => Gamemode::GoodyOsborne, + _ => Gamemode::MaryWarren + }, + FlagType::Short(s) => match s.as_str() { + "a" => Gamemode::Abigail, + "j" => Gamemode::JohnProctor, + "o" => Gamemode::GoodyOsborne, + _ => Gamemode::MaryWarren + } + }, + _ => Gamemode::MaryWarren + } + } else { + Gamemode::MaryWarren + } +} \ No newline at end of file diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..51a10e6 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,77 @@ +use std::env::args; +use std::io; + + +const DASH:char = 45 as u8 as char; + +#[derive(Debug, Clone)] +pub enum ArgType { + #[allow(dead_code)] + Binary(String), + Command(String), + Flag(FlagType) +} + +#[derive(Debug, Clone)] +pub enum FlagType { + //Currently only handles single flags. eg. "-S", "-y" + Short(String), + Long(String) +} + +pub fn fmt_args() -> Vec { + let mut args_vec:Vec = Vec::new(); + + for x in args() { + match try_flag(x.clone()) { + None => args_vec.push(ArgType::Command(x)), + Some(f) => args_vec.push(ArgType::Flag(f)) + } + } + + args_vec[0] = { + ArgType::Binary({ + match args_vec[0].clone() { + ArgType::Command(c) => c, + err => panic!("Expected ArgType::Command at args_vec[0], found {:?}", err) + } + }) + }; + + args_vec +} + +fn try_flag(arg: String) -> Option { + if arg.chars().nth(1).unwrap() == DASH { + //eg. --my-flag + Some(FlagType::Long(break_flag_long(arg))) + } else if arg.chars().nth(0).unwrap() == DASH { + //eg. -Syu + Some(FlagType::Short(break_flag_short(arg))) + } else { + None + } +} + +fn break_flag_short(mut arg: String) -> String { + arg.remove(0); + arg +} + +fn break_flag_long(mut arg: String) -> String { + for _ in 1..=2 { + arg.remove(0); + }; + + arg +} + +pub fn input() -> String { + let mut input_buffer = String::new(); + + io::stdin() + .read_line( &mut input_buffer) + .expect("Failed to read line"); + + input_buffer +} \ No newline at end of file