aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-22 16:55:17 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-22 16:55:17 +0200
commit04e212f3ac61e9af772d803271875e057e498072 (patch)
treed58197e626869463b3e8d49b03135c2861551c66
parentb34b2a5b8d118974502c015912e1ed67fa6965b0 (diff)
downloadhurrycurry-04e212f3ac61e9af772d803271875e057e498072.tar
hurrycurry-04e212f3ac61e9af772d803271875e057e498072.tar.bz2
hurrycurry-04e212f3ac61e9af772d803271875e057e498072.tar.zst
Fix step is_busy and stop moving when interacting
-rw-r--r--server/bot/src/pathfinding.rs1
-rw-r--r--server/bot/src/step.rs46
-rw-r--r--server/protocol/src/lib.rs1
-rw-r--r--test-client/main.ts2
-rw-r--r--test-client/protocol.ts3
-rw-r--r--test-client/visual.ts4
6 files changed, 32 insertions, 25 deletions
diff --git a/server/bot/src/pathfinding.rs b/server/bot/src/pathfinding.rs
index 936f99dd..4aa7c2ff 100644
--- a/server/bot/src/pathfinding.rs
+++ b/server/bot/src/pathfinding.rs
@@ -69,6 +69,7 @@ impl Path {
display: DebugEventDisplay::Path {
points: self.segments.clone(),
},
+ timeout: 0.1,
}
}
}
diff --git a/server/bot/src/step.rs b/server/bot/src/step.rs
index 8ef9556d..f5f74f38 100644
--- a/server/bot/src/step.rs
+++ b/server/bot/src/step.rs
@@ -21,7 +21,10 @@ use crate::{
pathfinding::{Path, find_path_to_neighbour},
};
use hurrycurry_game_core::Game;
-use hurrycurry_protocol::{Hand, ItemIndex, ItemLocation, PacketS, PlayerID, glam::IVec2};
+use hurrycurry_protocol::{
+ Hand, ItemIndex, ItemLocation, PacketS, PlayerID,
+ glam::{IVec2, Vec2},
+};
pub struct StepState {
path: Path,
@@ -33,8 +36,6 @@ pub struct StepState {
interact_start_pending: bool,
interact_stop_pending: bool,
me: PlayerID,
- #[cfg(feature = "debug_events")]
- init: bool,
}
impl StepState {
@@ -43,17 +44,15 @@ impl StepState {
}
pub fn new_wait(me: PlayerID, timer: f32) -> Self {
Self {
- item_expected: None,
- interact_position: IVec2::ZERO,
+ me,
+ path: Path::EMPTY,
hand: Hand(0),
+ wait_timer: timer,
interact_start_pending: false,
interact_stop_pending: false,
- me,
+ interact_position: IVec2::ZERO,
+ item_expected: None,
item_current: None,
- path: Path::EMPTY,
- wait_timer: timer,
- #[cfg(feature = "debug_events")]
- init: false,
}
}
pub fn new_segment(
@@ -74,40 +73,39 @@ impl StepState {
path,
hand,
wait_timer: interact,
- interact_stop_pending: true,
interact_start_pending: true,
+ interact_stop_pending: true,
interact_position: pos,
item_expected: destination_item,
item_current: destination_item,
- #[cfg(feature = "debug_events")]
- init: false,
})
}
pub fn is_busy(&self) -> bool {
- (self.wait_timer >= 0. || self.interact_stop_pending)
+ (self.wait_timer > 0. || self.interact_stop_pending)
&& !self.path.is_stuck(3.)
&& (self.path.is_done() || self.item_current == self.item_expected)
}
pub fn tick(&mut self, out: &mut PacketSink, game: &Game, dt: f32) {
#[cfg(feature = "debug_events")]
- if !self.init {
+ {
use crate::debug_player_color;
- use hurrycurry_protocol::{DebugEvent, DebugEventDisplay};
+ use hurrycurry_protocol::{DebugEvent, DebugEventDisplay, glam::Vec2};
out.push(PacketS::Debug(DebugEvent {
key: format!("step-{}", self.me),
color: debug_player_color(self.me),
display: DebugEventDisplay::Label {
- pos: self.interact_position.as_vec2(),
+ pos: self.interact_position.as_vec2() + Vec2::splat(0.5),
text: format!(
- "done={} expected={}",
- self.path.is_done(),
- self.item_expected == self.item_current
+ "D={} E={} T={:.01}",
+ self.path.is_done() as u8,
+ (self.item_expected == self.item_current) as u8,
+ self.wait_timer
),
},
+ timeout: 1.,
}));
- self.init = true;
}
if self.path.is_done() {
if self.interact_start_pending {
@@ -117,6 +115,12 @@ impl StepState {
hand: self.hand,
target: Some(ItemLocation::Tile(self.interact_position)),
});
+ out.push(PacketS::Movement {
+ player: self.me,
+ dir: Vec2::ZERO,
+ boost: false,
+ pos: None,
+ });
} else {
if self.wait_timer > 0. {
self.wait_timer -= dt;
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs
index 2d9aa0f0..09134a4f 100644
--- a/server/protocol/src/lib.rs
+++ b/server/protocol/src/lib.rs
@@ -384,6 +384,7 @@ pub struct DebugEvent {
pub key: String,
pub color: Vec3,
pub display: DebugEventDisplay,
+ pub timeout: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "ty")]
diff --git a/test-client/main.ts b/test-client/main.ts
index 9267270b..fe21f1ac 100644
--- a/test-client/main.ts
+++ b/test-client/main.ts
@@ -338,7 +338,7 @@ function packet(p: PacketC) {
}
break;
case "debug":
- debug_events.set(p.key, { timeout: 0.5, ...p })
+ debug_events.set(p.key, p)
break;
default:
console.warn("unknown packet", p);
diff --git a/test-client/protocol.ts b/test-client/protocol.ts
index d0789376..609a4518 100644
--- a/test-client/protocol.ts
+++ b/test-client/protocol.ts
@@ -159,7 +159,8 @@ export interface DebugEvent {
key: string,
color: [number, number, number]
display: DebugEventDisplay
+ timeout: number
}
export type DebugEventDisplay =
{ ty: "path", points: Vec2[] }
- | { ty: "label", pos: Vec2, text: string } \ No newline at end of file
+ | { ty: "label", pos: Vec2, text: string }
diff --git a/test-client/visual.ts b/test-client/visual.ts
index c06edff0..823fc006 100644
--- a/test-client/visual.ts
+++ b/test-client/visual.ts
@@ -114,9 +114,9 @@ function draw_debug_events() {
ctx.stroke()
} else if (ev.display.ty == "label") {
ctx.font = "0.2px sans-serif"
- ctx.strokeStyle = "black"
+ ctx.strokeStyle = "white"
ctx.fillStyle = color
- ctx.lineWidth = 0.1
+ ctx.lineWidth = 0.05
ctx.textAlign = "center"
ctx.textBaseline = "middle"
ctx.lineJoin = "round"