From b634bad931f530ee0a207e1461ffc5e52ebb83e3 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 10 Jan 2026 17:16:03 +0100 Subject: compiles with tile stacks --- server/protocol/src/helpers.rs | 22 ++++++++++++++++------ server/protocol/src/lib.rs | 8 +++----- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'server/protocol') diff --git a/server/protocol/src/helpers.rs b/server/protocol/src/helpers.rs index 679e6301..1be37a36 100644 --- a/server/protocol/src/helpers.rs +++ b/server/protocol/src/helpers.rs @@ -45,6 +45,20 @@ impl Gamedata { .enumerate() .map(|(i, e)| (RecipeIndex(i), e)) } + pub fn can_place_item(&self, tiles: &[TileIndex], item: ItemIndex) -> bool { + for t in tiles.iter().rev() { + if let Some(whitelist) = self.tile_placeable_items.get(t) { + return whitelist.contains(&item); + } + if self.tile_placeable_any.contains(t) { + return true; + } + } + false + } + pub fn walkable(&self, tiles: &[TileIndex]) -> bool { + tiles.iter().any(|t| self.tile_collide.contains(t)) + } } impl Recipe { @@ -92,13 +106,9 @@ impl Recipe { a.iter().chain(b.iter()).copied() } - pub fn supports_tile(&self, tile: Option) -> bool { + pub fn supports_tile(&self, tile: TileIndex) -> bool { if let Some(tile_constraint) = self.tile() { - if let Some(tile) = tile { - tile == tile_constraint - } else { - false - } + tile == tile_constraint } else { true } diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index d7cd2cd9..8a6e282e 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -87,9 +87,10 @@ pub struct Gamedata { pub current_map: String, pub item_names: Vec, pub tile_names: Vec, - pub tile_walkable: HashSet, + pub tile_collide: HashSet, #[serde(deserialize_with = "deser_tile_index_map")] pub tile_placeable_items: BTreeMap>, + pub tile_placeable_any: HashSet, pub tile_interactable_empty: HashSet, pub maps: Vec<(String, MapMetadata)>, pub bot_algos: Vec, @@ -257,11 +258,8 @@ pub enum PacketC { warn: bool, }, UpdateMap { - tile: IVec2, - kind: Option, - neighbors: [Option; 4], + changes: Vec<(IVec2, Vec)>, }, - FlushMap, Communicate { player: PlayerID, message: Option, -- cgit v1.3