aboutsummaryrefslogtreecommitdiff
path: root/server/bot/src/algos/customer.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-24 00:38:16 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-24 00:38:46 +0200
commite00492214438711c3af7fcad75505539d41e2285 (patch)
treefaf8d44a5282846b537ed347b2f839607aa9df89 /server/bot/src/algos/customer.rs
parentf1f0ae07172c24deb5815f8ee7926018db6d7dbc (diff)
downloadhurrycurry-e00492214438711c3af7fcad75505539d41e2285.tar
hurrycurry-e00492214438711c3af7fcad75505539d41e2285.tar.bz2
hurrycurry-e00492214438711c3af7fcad75505539d41e2285.tar.zst
pinned orders
Diffstat (limited to 'server/bot/src/algos/customer.rs')
-rw-r--r--server/bot/src/algos/customer.rs59
1 files changed, 49 insertions, 10 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs
index ec8f2283..e602addc 100644
--- a/server/bot/src/algos/customer.rs
+++ b/server/bot/src/algos/customer.rs
@@ -39,6 +39,8 @@ pub enum Customer {
chair: IVec2,
timeout: f32,
origin: IVec2,
+ check: u8,
+ pinned: bool,
},
Eating {
demand: DemandIndex,
@@ -104,12 +106,15 @@ impl BotAlgo for Customer {
timeout,
demand,
origin: *origin,
+ check: 0,
+ pinned: false,
};
BotInput {
extra: vec![PacketS::Communicate {
message: Some(Message::Item(game.data.demands[demand.0].input)),
timeout: Some(timeout),
player: me,
+ pin: Some(false),
}],
..Default::default()
}
@@ -144,19 +149,23 @@ impl BotAlgo for Customer {
demand,
timeout,
origin,
+ check,
+ pinned,
} => {
*timeout -= dt;
+ *check += 1;
if *timeout <= 0. {
let path = find_path(&game.walkable, pos.as_ivec2(), *origin)
.expect("no path to exit");
info!("{me:?} -> exiting");
*self = Customer::Exiting { path };
- BotInput {
+ return BotInput {
extra: vec![
PacketS::Communicate {
message: None,
timeout: Some(0.),
player: me,
+ pin: Some(false),
},
PacketS::ApplyScore(Score {
points: -1,
@@ -169,9 +178,32 @@ impl BotAlgo for Customer {
},
],
..Default::default()
- }
- } else {
+ };
+ } else if *check > 10 {
let demand_data = &game.data.demands[demand.0];
+ *check = 0;
+
+ if !*pinned {
+ let mut pin = false;
+ game.players_spatial_index.query(pos, 3., |pid, _| {
+ if game.players.get(&pid).map_or(false, |p| p.character >= 0) {
+ pin = true
+ }
+ });
+ if pin {
+ *pinned = true;
+ return BotInput {
+ extra: vec![PacketS::Communicate {
+ player: me,
+ message: Some(Message::Item(demand_data.input)),
+ timeout: Some(*timeout),
+ pin: Some(true),
+ }],
+ ..Default::default()
+ };
+ }
+ }
+
let demand_pos = [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y]
.into_iter()
.find_map(|off| {
@@ -201,12 +233,19 @@ impl BotAlgo for Customer {
chair: *chair,
origin: *origin,
};
- BotInput {
+ return BotInput {
extra: vec![
PacketS::Communicate {
message: None,
timeout: Some(0.),
player: me,
+ pin: Some(false),
+ },
+ PacketS::Communicate {
+ message: None,
+ timeout: Some(0.),
+ player: me,
+ pin: Some(true),
},
PacketS::Effect {
name: "satisfied".to_string(),
@@ -222,15 +261,15 @@ impl BotAlgo for Customer {
},
],
..Default::default()
- }
- } else {
- BotInput {
- direction: (chair.as_vec2() + 0.5) - pos,
- ..Default::default()
- }
+ };
}
}
+ BotInput {
+ direction: (chair.as_vec2() + 0.5) - pos,
+ ..Default::default()
+ }
}
+
Customer::Eating {
demand,
target,