//! Data structures for the game use async_std::sync::Arc; use std::{ collections::BTreeMap, sync::atomic::{AtomicBool, AtomicU32, AtomicU16}, }; /// A node is a computer on the network graph /// /// It's owned by a player, and has some upgrade state, as well as /// base stats. pub struct Node { /// Each node has a unique ID by which it's addressed id: u16, /// The current health health: AtomicU32, /// The max health max_health: AtomicU32, /// The owner of this node owner: Owner, /// Upgrade state type_: Upgrade, /// Number of links on the map links: u8, /// Active link states link_states: Vec>, /// Input buffer buffer: Vec, } /// A one-to-one link between two nodes pub struct Link { /// This link ID id: u16, /// Node 1 a: u16, /// Node 2 b: u16, length: u32, /// Packets present on this link pp: Vec<(Packet, AtomicU32)>, } /// A packet going across the network pub struct Packet { /// The packet ID id: u16, /// Declare this packet to be removed dead: AtomicBool, /// Each packet is owned by a player owner: Arc, /// What type of packet this is data_: PacketType, } /// A player who's having fun pub struct Player { /// A unique player ID (per match) id: u16, /// The player name name: String, /// Player color color: Color, } /// Optionally, players can create teams pub struct Team { /// Name of the team name: String, /// Unified color of the team color: Color, /// All team members by their ID roster: Vec } /// An RGB color without alpha pub struct Color(u8, u8, u8); /// Describes ownership state pub enum Owner { /// Nobody owns this Neutral, /// A player owns this Player(Player), } /// Encodes upgrade level without numbers pub enum Level { /// 1 One, /// 2 Two, /// 3 (wow) Three, } /// Describes upgrade state pub enum Upgrade { /// A basic node Base, /// Battle (attack/defence) nodes Guard(Level), /// These nodes make money Compute(Level), /// Good at packet switching Relay(Level), } /// Possible types of packets pub enum PacketType { /// A keepalive packet /// /// These are sent by all nodes if their neighbours are either /// friendly or neutral, and used to keep the network alive. /// Sending them costs nothing, and when they are received, they /// yield a small amount of funds, and restoring health of a node. Ping, /// A non exploit capture /// /// This is a packet that can be sent out by any node (except a /// switch) to claim a neutral node on the network. The path to /// the node needs to consist only of friendlies, and if an enemy /// node processes this type, nothing happens. Capture, /// A compute packet /// /// The first value is the target compute value, which each /// compute node adds on to. The second value is the current. If /// a compute packet passes through a compromised or enemy node, /// it might subtract from the second value, before palling it on. Compute { max: u16, curr: AtomicU16, step: u16, }, /// A special wrapper packet generated by guards /// /// Sometimes, when a hostily attack packet encounters a guard, it /// manages to capture the attack, and forwards it to a random /// compute node. If the node manages to handle the packet, /// without it getting dropped in the meantime), it yields a /// specified reward, like a computation would. Payload { inner: Box, reward: u16 }, /// A reset attack packet /// /// When encountering a hostile node, it will make that node drop /// all packets in it's buffers. Reset, /// Cross-node-scripting attack /// /// Decreases the strength of a node, also having a small chance /// of spawning a new packet into a random output buffer. When /// applied to a neutral node, it makes capturing nodes go faster. CNS, /// Node-in-the-middle attack /// /// Infect the routing behaviour of a node to route all traffic to /// a specified enemy node instead Nitm, /// Virus infection attack /// /// Infects a node to capture it's earnings, both active and /// passive, for a short time, without taking on it's costs. Virus, /// A total control exploit /// /// This is very hard to do, and a node will basically always /// resist it, but if successful, transforms the node into a guard /// node and yields control to the attackinng player. TakeOver, }