diff options
author | metamuffin <metamuffin@disroot.org> | 2024-11-22 15:41:45 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-11-22 15:44:23 +0100 |
commit | f27329f252a7844686249159cec721abbab0b47b (patch) | |
tree | f6cfcb2e56f765af5051712306f557af8a925265 /server/bot/src | |
parent | 43b84664344b461bfb4128bb10111c3099029c7a (diff) | |
download | hurrycurry-f27329f252a7844686249159cec721abbab0b47b.tar hurrycurry-f27329f252a7844686249159cec721abbab0b47b.tar.bz2 hurrycurry-f27329f252a7844686249159cec721abbab0b47b.tar.zst |
disable unknown oders for autosushi; fix #204
Diffstat (limited to 'server/bot/src')
-rw-r--r-- | server/bot/src/algos/customer.rs | 96 | ||||
-rw-r--r-- | server/bot/src/algos/mod.rs | 6 |
2 files changed, 70 insertions, 32 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index b3b029c3..67605ad5 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -28,7 +28,18 @@ use log::info; use rand::{random, seq::IndexedRandom, thread_rng}; #[derive(Debug, Clone, Default)] -pub enum Customer { +pub struct Customer { + config: CustomerConfig, + state: CustomerState, +} + +#[derive(Debug, Clone, Default)] +pub struct CustomerConfig { + pub unknown_order: bool, +} + +#[derive(Debug, Clone, Default)] +enum CustomerState { #[default] New, Entering { @@ -63,14 +74,34 @@ pub enum Customer { }, } +impl Customer { + pub fn new(config: CustomerConfig) -> Self { + Customer { + config, + state: CustomerState::default(), + } + } +} impl BotAlgo for Customer { fn tick(&mut self, me: PlayerID, game: &Game, dt: f32) -> BotInput { let Some(playerdata) = game.players.get(&me) else { return BotInput::default(); }; let pos = playerdata.movement.position; + self.state.tick(me, &self.config, pos, game, dt) + } +} +impl CustomerState { + fn tick( + &mut self, + me: PlayerID, + config: &CustomerConfig, + pos: Vec2, + game: &Game, + dt: f32, + ) -> BotInput { match self { - Customer::New => { + CustomerState::New => { if !game.data.demands.is_empty() { if let Some(&chair) = game .tiles @@ -82,7 +113,7 @@ impl BotAlgo for Customer { { if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), chair) { info!("{me:?} -> entering"); - *self = Customer::Entering { + *self = CustomerState::Entering { path, chair, origin: pos.as_ivec2(), @@ -93,7 +124,7 @@ impl BotAlgo for Customer { } BotInput::default() } - Customer::Entering { + CustomerState::Entering { path, chair, origin, @@ -115,7 +146,7 @@ impl BotAlgo for Customer { facing = off.as_vec2(); } } - *self = Customer::Waiting { + *self = CustomerState::Waiting { chair: *chair, timeout, demand, @@ -124,13 +155,16 @@ impl BotAlgo for Customer { check: 0, pinned: false, }; - let unknown_item = game - .data - .get_item_by_name("unknown-order") - .unwrap_or(game.data.demands[demand.0].input); + let message_item = if config.unknown_order { + game.data + .get_item_by_name("unknown-order") + .unwrap_or(game.data.demands[demand.0].input) + } else { + game.data.demands[demand.0].input + }; BotInput { extra: vec![PacketS::Communicate { - message: Some(Message::Item(unknown_item)), + message: Some(Message::Item(message_item)), timeout: Some(timeout), player: me, pin: Some(false), @@ -149,11 +183,11 @@ impl BotAlgo for Customer { }) .is_some() { - *self = Customer::New; + *self = CustomerState::New; BotInput::default() } else if path.is_stuck() { if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), *origin) { - *self = Customer::Exiting { path }; + *self = CustomerState::Exiting { path }; } BotInput::default() } else { @@ -163,7 +197,7 @@ impl BotAlgo for Customer { } } } - Customer::Waiting { + CustomerState::Waiting { chair, demand, timeout, @@ -178,7 +212,7 @@ impl BotAlgo for Customer { let path = find_path(&game.walkable, pos.as_ivec2(), *origin) .expect("no path to exit"); info!("{me:?} -> exiting"); - *self = Customer::Exiting { path }; + *self = CustomerState::Exiting { path }; return BotInput { extra: vec![ PacketS::Communicate { @@ -205,15 +239,19 @@ impl BotAlgo for Customer { if !*pinned { let mut pin = false; - game.players_spatial_index.query(pos, 3., |pid, _| { - if game - .players - .get(&pid) - .map_or(false, |p| p.class.is_cheflike()) - { - pin = true - } - }); + if config.unknown_order { + game.players_spatial_index.query(pos, 3., |pid, _| { + if game + .players + .get(&pid) + .map_or(false, |p| p.class.is_cheflike()) + { + pin = true + } + }); + } else { + pin = true; + } if pin { *pinned = true; return BotInput { @@ -251,7 +289,7 @@ impl BotAlgo for Customer { if let Some(pos) = demand_pos { info!("{me:?} -> eating"); let points = game.data.demands[demand.0].points; - *self = Customer::Eating { + *self = CustomerState::Eating { demand: *demand, table: pos, progress: 0., @@ -300,7 +338,7 @@ impl BotAlgo for Customer { } } - Customer::Eating { + CustomerState::Eating { demand, table, progress, @@ -311,7 +349,7 @@ impl BotAlgo for Customer { *progress += dt / demand.duration; if *progress >= 1. { info!("{me:?} -> finishing"); - *self = Customer::Finishing { + *self = CustomerState::Finishing { table: *table, origin: *origin, cooldown: 0.5, @@ -329,7 +367,7 @@ impl BotAlgo for Customer { ..Default::default() } } - Customer::Finishing { + CustomerState::Finishing { table, origin, cooldown, @@ -337,7 +375,7 @@ impl BotAlgo for Customer { *cooldown -= dt; if game.players.get(&me).map_or(false, |pl| pl.item.is_none()) { if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), *origin) { - *self = Customer::Exiting { path }; + *self = CustomerState::Exiting { path }; } BotInput::default() } else { @@ -366,7 +404,7 @@ impl BotAlgo for Customer { } } } - Customer::Exiting { path } => { + CustomerState::Exiting { path } => { if path.is_done() || path.is_stuck() { info!("{me:?} -> leave"); BotInput { diff --git a/server/bot/src/algos/mod.rs b/server/bot/src/algos/mod.rs index 0b8e4339..059b9e89 100644 --- a/server/bot/src/algos/mod.rs +++ b/server/bot/src/algos/mod.rs @@ -16,18 +16,18 @@ */ mod customer; +mod dishwasher; mod frank; mod simple; mod test; mod waiter; -mod dishwasher; -pub use customer::Customer; +pub use customer::{Customer, CustomerConfig}; +pub use dishwasher::DishWasher; pub use frank::Frank; pub use simple::Simple; pub use test::Test; pub use waiter::Waiter; -pub use dishwasher::DishWasher; #[allow(clippy::type_complexity)] pub const ALGO_CONSTRUCTORS: &[(&str, fn() -> crate::DynBotAlgo)] = &[ |