|
|
|
@ -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!(), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|