feat(net): nodes carry their cyberspace tile
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -52,6 +52,7 @@ impl NetStage {
|
|||||||
id,
|
id,
|
||||||
kind,
|
kind,
|
||||||
anchor,
|
anchor,
|
||||||
|
cyber: anchor.1,
|
||||||
subnet,
|
subnet,
|
||||||
building,
|
building,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ pub struct Node {
|
|||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub kind: NodeKind,
|
pub kind: NodeKind,
|
||||||
pub anchor: (StratumKind, Pos),
|
pub anchor: (StratumKind, Pos),
|
||||||
|
/// The node's tile on the Net stratum.
|
||||||
|
pub cyber: Pos,
|
||||||
pub subnet: SubnetId,
|
pub subnet: SubnetId,
|
||||||
pub building: Option<BuildingId>,
|
pub building: Option<BuildingId>,
|
||||||
}
|
}
|
||||||
@@ -79,6 +81,11 @@ impl Net {
|
|||||||
self.nodes.iter().find(|n| n.anchor == (k, p))
|
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 {
|
pub fn subnet(&self, id: SubnetId) -> &Subnet {
|
||||||
&self.subnets[id.index()]
|
&self.subnets[id.index()]
|
||||||
}
|
}
|
||||||
@@ -87,3 +94,32 @@ impl Net {
|
|||||||
&self.nodes[id.index()]
|
&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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user