diff options
author | Katharina Fey <kookie@spacekookie.de> | 2020-01-29 17:10:36 +0000 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2020-01-29 17:10:36 +0000 |
commit | eb86eb246e5a98867d0d8766a236d73b44bb46c7 (patch) | |
tree | 9e209a9cb5b29ddf7e30ec14ce474142acab84be | |
parent | 977dadaa07f86a3ebabedb425cc6f68b2e14d569 (diff) |
Adding some more packet sending utilities
-rw-r--r-- | src/data.rs | 2 | ||||
-rw-r--r-- | src/gens.rs | 53 | ||||
-rw-r--r-- | src/stats.rs | 33 |
3 files changed, 83 insertions, 5 deletions
diff --git a/src/data.rs b/src/data.rs index 2a4ab8a03019..77a547255536 100644 --- a/src/data.rs +++ b/src/data.rs @@ -62,6 +62,8 @@ pub struct Player { name: String, /// Player color color: Color, + /// The player's money + money: AtomicU16, } /// Optionally, players can create teams diff --git a/src/gens.rs b/src/gens.rs index cd0af16754f3..7374731c826d 100644 --- a/src/gens.rs +++ b/src/gens.rs @@ -33,11 +33,9 @@ pub mod can_send { } } - /// Compute nodes can sennd compute packets + /// Compute nodes can ping and compute but not capture pub fn compute() -> Vec<&'static str> { - let mut p = base(); - p.append(&mut vec!["compute"]); - p + vec!["ping", "compute"] } /// Relays only relay! @@ -45,3 +43,50 @@ pub mod can_send { vec![] } } + +pub mod send { + use crate::{ + data::{ + Level::*, + PacketType as Pkt, + Upgrade::{self, *}, + }, + stats::strengths, + }; + + /// Turn the string type identifier into a packet + /// + /// This function makes heavy use of the stats module, which is + /// responsible for balancing all of these values. + pub fn build_packet(node: Upgrade, type_: &'static str, prev: Option<Pkt>) -> Pkt { + match (prev, node, type_) { + // All pings are the same + (None, _, "ping") => Pkt::Ping, + + // TODO: captures should improve + (None, Base, "capture") | (None, Guard(_), "capture") => Pkt::Capture, + + (None, Compute(lvl), "compute") => Pkt::Compute { + curr: Default::default(), + max: strengths::compute_max(lvl), + step: strengths::compute_step(lvl), + }, + + (Some(prev), Guard(lvl), "payload") => Pkt::Payload { + inner: Box::new(prev), + reward: strengths::payload_reward(lvl), + }, + + (None, Guard(_), "cns") => Pkt::CNS, + (None, Guard(_), "reset") => Pkt::Reset, + (None, Guard(_), "nitm") => Pkt::Nitm, + (None, Guard(_), "virus") => Pkt::Virus, + + // Only level 3 guards can send takeovers + (None, Guard(Three), "takeover") => Pkt::TakeOver, + + // Can't touch this + (_, _, _) => unreachable!(), + } + } +} diff --git a/src/stats.rs b/src/stats.rs index 7755821e4742..99340f2989dc 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -8,7 +8,7 @@ pub type Money = u16; /// The cost of doing business -pub mod cost { +pub mod costs { use super::Money; use crate::data::{Level, PacketType, Upgrade}; @@ -150,3 +150,34 @@ pub mod gains { } } } + +pub mod strengths { + use crate::data::Level::{self, *}; + + /// Determine the maximum amount of resources for a compute packet + pub fn compute_max(lvl: Level) -> u16 { + match lvl { + One => 65, + Two => 120, + Three => 250, + } + } + + /// Determine the step size by which a computation advances + pub fn compute_step(lvl: Level) -> u16 { + match lvl { + One => 7, + Two => 20, + Three => 32, + } + } + + /// Determine the reward gained from processing a payload packet + pub fn payload_reward(lvl: Level) -> u16 { + match lvl { + One => 70, + Two => 150, + Three => 275, + } + } +} |