aboutsummaryrefslogtreecommitdiff
path: root/server/bot/src/step.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/bot/src/step.rs')
-rw-r--r--server/bot/src/step.rs79
1 files changed, 52 insertions, 27 deletions
diff --git a/server/bot/src/step.rs b/server/bot/src/step.rs
index 34793466..8ef9556d 100644
--- a/server/bot/src/step.rs
+++ b/server/bot/src/step.rs
@@ -33,6 +33,8 @@ pub struct StepState {
interact_start_pending: bool,
interact_stop_pending: bool,
me: PlayerID,
+ #[cfg(feature = "debug_events")]
+ init: bool,
}
impl StepState {
@@ -50,6 +52,8 @@ impl StepState {
item_current: None,
path: Path::EMPTY,
wait_timer: timer,
+ #[cfg(feature = "debug_events")]
+ init: false,
}
}
pub fn new_segment(
@@ -74,16 +78,37 @@ impl StepState {
interact_start_pending: true,
interact_position: pos,
item_expected: destination_item,
- item_current: None,
+ 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.item_current == self.item_expected
+ (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};
+ 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(),
+ text: format!(
+ "done={} expected={}",
+ self.path.is_done(),
+ self.item_expected == self.item_current
+ ),
+ },
+ }));
+ self.init = true;
+ }
if self.path.is_done() {
if self.interact_start_pending {
self.interact_start_pending = false;
@@ -93,7 +118,9 @@ impl StepState {
target: Some(ItemLocation::Tile(self.interact_position)),
});
} else {
- if self.wait_timer < 0. {
+ if self.wait_timer > 0. {
+ self.wait_timer -= dt;
+ } else {
if self.interact_stop_pending {
self.interact_stop_pending = false;
out.push(PacketS::Interact {
@@ -102,34 +129,32 @@ impl StepState {
target: None,
});
}
- } else {
- self.wait_timer -= dt;
}
}
- }
-
- self.item_current = game
- .tiles
- .get(&self.interact_position)
- .and_then(|t| t.item.as_ref().map(|i| i.kind));
+ } else {
+ 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)
- .as_ref()
- .map(|p| p.movement.position)
- .unwrap_or_default();
+ let position = game
+ .players
+ .get(&self.me)
+ .as_ref()
+ .map(|p| p.movement.position)
+ .unwrap_or_default();
- let dir = self.path.next_direction(position, dt);
+ let dir = self.path.next_direction(position, dt);
- #[cfg(feature = "debug_events")]
- out.push(PacketS::Debug(self.path.debug(self.me)));
+ #[cfg(feature = "debug_events")]
+ out.push(PacketS::Debug(self.path.debug(self.me)));
- out.push(PacketS::Movement {
- player: self.me,
- dir,
- boost: false,
- pos: None,
- });
+ out.push(PacketS::Movement {
+ player: self.me,
+ dir,
+ boost: self.path.is_stuck(2.),
+ pos: None,
+ });
+ }
}
}