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.rs26
1 files changed, 20 insertions, 6 deletions
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,