summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-11-22 15:41:45 +0100
committermetamuffin <metamuffin@disroot.org>2024-11-22 15:44:23 +0100
commitf27329f252a7844686249159cec721abbab0b47b (patch)
treef6cfcb2e56f765af5051712306f557af8a925265
parent43b84664344b461bfb4128bb10111c3099029c7a (diff)
downloadhurrycurry-f27329f252a7844686249159cec721abbab0b47b.tar
hurrycurry-f27329f252a7844686249159cec721abbab0b47b.tar.bz2
hurrycurry-f27329f252a7844686249159cec721abbab0b47b.tar.zst
disable unknown oders for autosushi; fix #204
-rw-r--r--data/maps/auto_sushi.yaml3
-rw-r--r--server/bot/src/algos/customer.rs96
-rw-r--r--server/bot/src/algos/mod.rs6
-rw-r--r--server/src/data/mod.rs11
-rw-r--r--server/src/entity/customers.rs6
5 files changed, 87 insertions, 35 deletions
diff --git a/data/maps/auto_sushi.yaml b/data/maps/auto_sushi.yaml
index 0c6ff4f1..4f1e60ff 100644
--- a/data/maps/auto_sushi.yaml
+++ b/data/maps/auto_sushi.yaml
@@ -14,6 +14,9 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
score_baseline: 200
+flags:
+ disable_unknown_orders: true
+
map:
- "''''''''''''''''''*''''''"
- "'__~_█████████''*''''''''"
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)] = &[
diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs
index 549574c7..57051fe9 100644
--- a/server/src/data/mod.rs
+++ b/server/src/data/mod.rs
@@ -77,6 +77,7 @@ pub struct MapDecl {
#[serde(default)] tile_entities: HashMap<char, EntityDecl>,
#[serde(default)] score_baseline: i64,
#[serde(default)] default_timer: Option<u64>,
+ #[serde(default)] flags: ServerdataFlags,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -95,7 +96,14 @@ pub struct Serverdata {
pub customer_spawn: Vec2,
pub score_baseline: i64,
pub default_timer: Option<Duration>,
- pub book: DocumentElement
+ pub book: DocumentElement,
+ pub flags: ServerdataFlags,
+}
+
+#[rustfmt::skip]
+#[derive(Debug, Clone, Default, Deserialize)]
+pub struct ServerdataFlags {
+ #[serde(default)] pub disable_unknown_orders: bool,
}
#[derive(Debug, Deserialize, Default)]
@@ -310,6 +318,7 @@ pub fn build_data(
Serverdata {
initial_map,
chef_spawn,
+ flags: map_in.flags,
customer_spawn,
default_timer,
book,
diff --git a/server/src/entity/customers.rs b/server/src/entity/customers.rs
index 0c3ced8d..02051901 100644
--- a/server/src/entity/customers.rs
+++ b/server/src/entity/customers.rs
@@ -17,7 +17,7 @@
*/
use super::{bot::BotDriver, Entity, EntityContext};
use anyhow::Result;
-use hurrycurry_bot::algos::Customer;
+use hurrycurry_bot::algos::{Customer, CustomerConfig};
use hurrycurry_protocol::PlayerClass;
use rand::random;
@@ -58,7 +58,9 @@ impl Entity for Customers {
"".to_string(),
-1 - random::<u16>() as i32,
PlayerClass::Customer,
- Customer::default(),
+ Customer::new(CustomerConfig {
+ unknown_order: !c.serverdata.flags.disable_unknown_orders,
+ }),
);
self.customers.push(bot)
}