diff options
Diffstat (limited to 'server/bot/src/algos/customer.rs')
| -rw-r--r-- | server/bot/src/algos/customer.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index ebc6e64a..0ed1ba9a 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -22,7 +22,7 @@ use crate::{ }; use hurrycurry_game_core::Game; use hurrycurry_protocol::{ - DemandIndex, Hand, ItemLocation, Message, PacketS, PlayerClass, PlayerID, Score, + DemandIndex, Hand, ItemLocation, Message, PacketS, PlayerClass, PlayerID, Score, TileIndex, glam::{IVec2, Vec2}, }; use log::debug; @@ -101,12 +101,14 @@ impl CustomerState { match self { CustomerState::New => { if !game.data.demands.is_empty() { + let chair_ti = game.data.get_tile_by_name("chair").unwrap_or(TileIndex(0)); // TODO let chairs = game - .tiles - .iter() - .filter(|(_, t)| game.data.tile_name(t.kind) == "chair") - .map(|(p, _)| *p) - .collect::<Vec<_>>(); + .tile_index + .get(&chair_ti) + .into_iter() + .flatten() + .copied() + .collect::<Vec<_>>(); //? maybe opt alloc if let Some(&chair) = chairs.get(random::<usize>(..) % chairs.len().max(1)) && let Some(path) = find_path(game, pos.as_ivec2(), chair) { @@ -135,12 +137,11 @@ impl CustomerState { let timeout = 90. + random_float() * 60.; let mut facing = Vec2::ZERO; for off in [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y] { - if game.tiles.get(&(off + *chair)).is_some_and(|t| { - game.data - .tile_placeable_items - .get(&t.kind) - .is_none_or(|p| p.contains(&requested_item)) - }) { + if game + .tiles + .get(&(off + *chair)) + .is_some_and(|t| game.data.can_place_item(&t.parts, requested_item)) + { facing = off.as_vec2(); } } |