diff options
Diffstat (limited to 'server/bot/src/algos')
| -rw-r--r-- | server/bot/src/algos/customer.rs | 60 |
1 files changed, 17 insertions, 43 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index fe665f47..ebc6e64a 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -17,7 +17,7 @@ */ use crate::{ BotAlgo, PacketSink, - pathfinding::{Path, find_path}, + pathfinding::{HoldLocation, Path, find_path}, random_float, }; use hurrycurry_game_core::Game; @@ -50,19 +50,19 @@ enum CustomerState { ticks: usize, }, Waiting { + hold_location: HoldLocation, demand: DemandIndex, chair: IVec2, - facing: Vec2, timeout: f32, origin: IVec2, check: u8, pinned: bool, }, Eating { + hold_location: HoldLocation, demand: DemandIndex, table: IVec2, progress: f32, - chair: IVec2, origin: IVec2, }, Finishing { @@ -148,10 +148,10 @@ impl CustomerState { chair: *chair, timeout, demand, - facing, origin: *origin, check: 0, pinned: false, + hold_location: HoldLocation::new(chair.as_vec2(), facing), }; let message_item = if !game.data.flags.disable_unknown_orders { game.data @@ -182,22 +182,17 @@ impl CustomerState { } 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, - boost: false, - pos: None, - }); + path.update(out, me, pos, dt, 0.6, false); } } CustomerState::Waiting { + hold_location, chair, demand, timeout, origin, check, pinned, - facing, } => { *timeout -= dt; *check += 1; @@ -271,7 +266,7 @@ impl CustomerState { None } }); - if let Some(pos) = demand_pos { + if let Some(table) = demand_pos { debug!("{me:?} -> eating"); let points = game.data.demands[demand.0].points; out.push(PacketS::Communicate { @@ -291,7 +286,7 @@ impl CustomerState { player: me, }); out.push(PacketS::Interact { - target: Some(ItemLocation::Tile(pos)), + target: Some(ItemLocation::Tile(table)), player: me, hand: Hand(0), }); @@ -306,28 +301,26 @@ impl CustomerState { hand: Hand(0), }); *self = CustomerState::Eating { + hold_location: HoldLocation::new( + chair.as_vec2(), + (table - *chair).as_vec2(), + ), demand: *demand, - table: pos, + table, progress: 0., - chair: *chair, origin: *origin, }; return; } } - out.push(PacketS::Movement { - player: me, - dir: dir_input(pos, *chair, *facing), - boost: false, - pos: None, - }); + hold_location.update(out, me, pos); } CustomerState::Eating { + hold_location, demand, table, progress, - chair, origin, } => { let demand = &game.data.demands[demand.0]; @@ -346,12 +339,7 @@ impl CustomerState { }); return; } - out.push(PacketS::Movement { - player: me, - dir: dir_input(pos, *chair, (*table - *chair).as_vec2()), - boost: false, - pos: None, - }); + hold_location.update(out, me, pos); } CustomerState::Finishing { table, @@ -398,24 +386,10 @@ impl CustomerState { } 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, - boost: false, - pos: None, - }); + path.update(out, me, pos, dt, 0.6, false); } } CustomerState::Exited => (), } } } - -fn dir_input(pos: Vec2, target: IVec2, facing: Vec2) -> Vec2 { - let diff = (target.as_vec2() + 0.5) - pos; - (if diff.length() > 0.3 { - diff.normalize() - } else { - diff * 0.5 - }) + facing.clamp_length_max(1.) * 0.3 -} |