feat(net): nodes carry their cyberspace tile

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jeffrey Wilcke
2026-10-12 21:34:59 +02:00
parent b740b9d334
commit a491841639
2 changed files with 37 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ impl NetStage {
id,
kind,
anchor,
cyber: anchor.1,
subnet,
building,
});

View File

@@ -66,6 +66,8 @@ pub struct Node {
pub id: NodeId,
pub kind: NodeKind,
pub anchor: (StratumKind, Pos),
/// The node's tile on the Net stratum.
pub cyber: Pos,
pub subnet: SubnetId,
pub building: Option<BuildingId>,
}
@@ -79,6 +81,11 @@ impl Net {
self.nodes.iter().find(|n| n.anchor == (k, p))
}
/// The node standing on a cyberspace tile.
pub fn node_in_cyber(&self, p: Pos) -> Option<&Node> {
self.nodes.iter().find(|n| n.cyber == p)
}
pub fn subnet(&self, id: SubnetId) -> &Subnet {
&self.subnets[id.index()]
}
@@ -87,3 +94,32 @@ impl Net {
&self.nodes[id.index()]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn nodes_are_found_by_cyber_tile() {
let mut net = Net::default();
net.subnets.push(Subnet {
id: SubnetId(0),
owner: SubnetOwner::City,
security: 10,
});
net.nodes.push(Node {
id: NodeId(0),
kind: NodeKind::Server,
anchor: (StratumKind::Street, Pos::new(5, 5)),
cyber: Pos::new(7, 5),
subnet: SubnetId(0),
building: None,
});
assert_eq!(
net.node_in_cyber(Pos::new(7, 5)).map(|n| n.id),
Some(NodeId(0))
);
assert_eq!(net.node_in_cyber(Pos::new(5, 5)), None);
assert!(net.node_at(StratumKind::Street, Pos::new(5, 5)).is_some());
}
}