diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-10-20 20:58:14 +0200 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-10-21 00:18:11 +0200 |
| commit | eaed442578c3b1765ec48c84489a122096b6a08f (patch) | |
| tree | bd5eeb82ea6f49691a4c5bad91a1b1614f0948a8 /server/bot/src | |
| parent | a3b0879a98bf5a0881b426913d7dd4cb9010e327 (diff) | |
| download | hurrycurry-eaed442578c3b1765ec48c84489a122096b6a08f.tar hurrycurry-eaed442578c3b1765ec48c84489a122096b6a08f.tar.bz2 hurrycurry-eaed442578c3b1765ec48c84489a122096b6a08f.tar.zst | |
Send paths as debug events
Diffstat (limited to 'server/bot/src')
| -rw-r--r-- | server/bot/src/algos/customer.rs | 5 | ||||
| -rw-r--r-- | server/bot/src/pathfinding.rs | 26 | ||||
| -rw-r--r-- | server/bot/src/step.rs | 26 |
3 files changed, 50 insertions, 7 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index 6ae67f69..fa10410b 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -180,6 +180,8 @@ impl CustomerState { *self = CustomerState::Exiting { path }; } } else { + #[cfg(feature = "debug_events")] + out.push(PacketS::Debug(path.debug(me))); out.push(PacketS::Movement { player: me, dir: path.next_direction(pos, dt) * 0.6, @@ -380,6 +382,7 @@ impl CustomerState { hand: Hand(0), }); } + out.push(PacketS::Movement { player: me, dir: (table.as_vec2() + 0.5) - pos, @@ -393,6 +396,8 @@ impl CustomerState { debug!("{me:?} -> leave"); *self = CustomerState::Exited } else { + #[cfg(feature = "debug_events")] + out.push(PacketS::Debug(path.debug(me))); out.push(PacketS::Movement { player: me, dir: path.next_direction(pos, dt) * 0.6, diff --git a/server/bot/src/pathfinding.rs b/server/bot/src/pathfinding.rs index ec098495..5c5551dd 100644 --- a/server/bot/src/pathfinding.rs +++ b/server/bot/src/pathfinding.rs @@ -16,7 +16,12 @@ */ use hurrycurry_game_core::Game; -use hurrycurry_protocol::glam::{IVec2, Vec2}; +#[cfg(feature = "debug_events")] +use hurrycurry_protocol::{DebugEvent, PlayerID}; +use hurrycurry_protocol::{ + DebugEventDisplay, + glam::{IVec2, Vec2}, +}; use log::{debug, trace}; use std::{ cmp::Ordering, @@ -57,6 +62,25 @@ impl Path { pub fn remaining_segments(&self) -> usize { self.segments.len() } + + #[cfg(feature = "debug_events")] + pub fn debug(&self, id: PlayerID) -> DebugEvent { + use std::f32::consts::TAU; + + use hurrycurry_protocol::glam::Vec3; + let a = id.0 as f32; + DebugEvent { + key: format!("path-{id}"), + color: Vec3::new( + (a + TAU / 3. * 0.).sin(), + (a + TAU / 3. * 1.).sin(), + (a + TAU / 3. * 2.).sin(), + ), + display: DebugEventDisplay::Path { + points: self.segments.clone(), + }, + } + } } pub fn find_path_to_neighbour(game: &Game, from: IVec2, to: IVec2) -> Option<Path> { diff --git a/server/bot/src/step.rs b/server/bot/src/step.rs index 001935ac..34793466 100644 --- a/server/bot/src/step.rs +++ b/server/bot/src/step.rs @@ -26,7 +26,8 @@ use hurrycurry_protocol::{Hand, ItemIndex, ItemLocation, PacketS, PlayerID, glam pub struct StepState { path: Path, interact_position: IVec2, - destination_item: Option<ItemIndex>, + item_expected: Option<ItemIndex>, + item_current: Option<ItemIndex>, hand: Hand, wait_timer: f32, interact_start_pending: bool, @@ -40,12 +41,13 @@ impl StepState { } pub fn new_wait(me: PlayerID, timer: f32) -> Self { Self { - destination_item: None, + item_expected: None, interact_position: IVec2::ZERO, hand: Hand(0), interact_start_pending: false, interact_stop_pending: false, me, + item_current: None, path: Path::EMPTY, wait_timer: timer, } @@ -59,6 +61,10 @@ impl StepState { ) -> Option<Self> { let own_pos = game.players.get(&me)?.movement.position.as_ivec2(); let path = find_path_to_neighbour(game, own_pos, pos)?; + let destination_item = game + .tiles + .get(&pos) + .and_then(|t| t.item.as_ref().map(|i| i.kind)); Some(Self { me, path, @@ -67,15 +73,14 @@ impl StepState { interact_stop_pending: true, interact_start_pending: true, interact_position: pos, - destination_item: game - .tiles - .get(&pos) - .and_then(|t| t.item.as_ref().map(|i| i.kind)), + item_expected: destination_item, + item_current: None, }) } pub fn is_busy(&self) -> bool { self.wait_timer >= 0. || self.interact_stop_pending + // && self.item_current == self.item_expected } pub fn tick(&mut self, out: &mut PacketSink, game: &Game, dt: f32) { @@ -103,6 +108,11 @@ impl StepState { } } + self.item_current = game + .tiles + .get(&self.interact_position) + .and_then(|t| t.item.as_ref().map(|i| i.kind)); + let position = game .players .get(&self.me) @@ -111,6 +121,10 @@ impl StepState { .unwrap_or_default(); let dir = self.path.next_direction(position, dt); + + #[cfg(feature = "debug_events")] + out.push(PacketS::Debug(self.path.debug(self.me))); + out.push(PacketS::Movement { player: self.me, dir, |