diff options
author | metamuffin <metamuffin@disroot.org> | 2024-08-13 16:48:38 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-08-13 16:48:38 +0200 |
commit | c75b83236e4345f1a705d878acb1d59c1ad38746 (patch) | |
tree | 6d97e7e435940d7cd23ee5c4a572f8d671873ee2 /server/bot | |
parent | 8d83fcef94ce1558a2c0e29e8be6c966c7e10a5b (diff) | |
download | hurrycurry-c75b83236e4345f1a705d878acb1d59c1ad38746.tar hurrycurry-c75b83236e4345f1a705d878acb1d59c1ad38746.tar.bz2 hurrycurry-c75b83236e4345f1a705d878acb1d59c1ad38746.tar.zst |
customers work except for points and return to spawn
Diffstat (limited to 'server/bot')
-rw-r--r-- | server/bot/src/algos/customer.rs | 104 | ||||
-rw-r--r-- | server/bot/src/main.rs | 2 |
2 files changed, 60 insertions, 46 deletions
diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index 69712ba8..c1a13d31 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -22,7 +22,7 @@ use crate::{ use hurrycurry_client_lib::Game; use hurrycurry_protocol::{glam::IVec2, DemandIndex, Message, PacketS, PlayerID}; use log::info; -use rand::random; +use rand::{random, seq::IndexedRandom, thread_rng}; #[derive(Debug, Clone)] pub enum Customer { @@ -56,29 +56,28 @@ impl Default for Customer { impl BotAlgo for Customer { fn tick(&mut self, me: PlayerID, game: &Game, dt: f32) -> BotInput { let _ = (me, game, dt); - let Some(playerdata) = game.players.get_mut(&me) else { + let Some(playerdata) = game.players.get(&me) else { return BotInput::default(); }; let pos = playerdata.movement.position; match self { Customer::New => { - if let Some((chair, _)) = game + if let Some(&chair) = game .tiles .iter() - .find(|(_, t)| game.data.tile_name(t.kind) == "chair") + .filter(|(_, t)| game.data.tile_name(t.kind) == "chair") + .map(|(p, _)| *p) + .collect::<Vec<_>>() + .choose(&mut thread_rng()) { - if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), *chair) { + if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), chair) { info!("{me:?} -> entering"); - *self = Customer::Entering { - path, - chair: *chair, - }; + *self = Customer::Entering { path, chair }; } } BotInput::default() } Customer::Entering { path, chair } => { - let direction = path.next_direction(pos); if path.is_done() { let demand = DemandIndex(random::<u32>() as usize % game.data.demands.len()); info!("{me:?} -> waiting"); @@ -97,7 +96,7 @@ impl BotAlgo for Customer { } } else { BotInput { - direction, + direction: path.next_direction(pos), ..Default::default() } } @@ -107,9 +106,6 @@ impl BotAlgo for Customer { demand, timeout, } => { - playerdata - .movement - .input((chair.as_vec2() + 0.5) - pos, false); *timeout -= dt; if *timeout <= 0. { let path = find_path( @@ -194,7 +190,10 @@ impl BotAlgo for Customer { ..Default::default() } } else { - BotInput::default() + BotInput { + direction: (chair.as_vec2() + 0.5) - pos, + ..Default::default() + } } } } @@ -204,46 +203,59 @@ impl BotAlgo for Customer { progress, chair, } => { - playerdata - .movement - .input((chair.as_vec2() + 0.5) - playerdata.position(), false); let demand = &game.data.demands[demand.0]; *progress += dt / demand.duration; if *progress >= 1. { - self.cpackets.push_back(PacketS::ReplaceHand { - player, - item: demand.to, - }); - if demand.to.is_some() { - self.cpackets.push_back(PacketS::Interact { - player, - pos: Some(*target), + if let Some(path) = find_path( + &game.walkable, + pos.as_ivec2(), + pos.as_ivec2(), + // game.data.customer_spawn.as_ivec2(), + ) { + let mut packets = Vec::new(); + packets.push(PacketS::ReplaceHand { + player: me, + item: demand.output, }); - self.cpackets - .push_back(PacketS::Interact { player, pos: None }); + if demand.output.is_some() { + packets.push(PacketS::Interact { + player: me, + pos: Some(*target), + }); + packets.push(PacketS::Interact { + player: me, + pos: None, + }); + // *self.chairs.get_mut(chair).unwrap() = true; + // game.score.demands_completed += 1; + // game.score.points += demand.points; + // game.score_changed = true; + info!("{me:?} -> exiting"); + *self = Customer::Exiting { path }; + return BotInput { + extra: packets, + ..Default::default() + }; + } } - let path = find_path( - &game.walkable, - playerdata.position().as_ivec2(), - game.data.customer_spawn.as_ivec2(), - ) - .ok_or(anyhow!("no path to exit"))?; - *self.chairs.get_mut(chair).unwrap() = true; - game.score.demands_completed += 1; - game.score.points += demand.points; - game.score_changed = true; - info!("{player:?} -> exiting"); - *state = Customer::Exiting { path } + } + BotInput { + direction: (chair.as_vec2() + 0.5) - pos, + ..Default::default() } } Customer::Exiting { path } => { - playerdata - .movement - .input(path.next_direction(playerdata.position()), false); if path.is_done() { - info!("{player:?} -> leave"); - self.cpackets.push_back(PacketS::Leave { player }); - customers_to_remove.push(player); + info!("{me:?} -> leave"); + BotInput { + leave: true, + ..Default::default() + } + } else { + BotInput { + direction: path.next_direction(pos), + ..Default::default() + } } } } diff --git a/server/bot/src/main.rs b/server/bot/src/main.rs index cf115358..bb30cb68 100644 --- a/server/bot/src/main.rs +++ b/server/bot/src/main.rs @@ -92,6 +92,7 @@ fn main() -> Result<()> { boost, interact, leave, + extra, } = b.state.tick(b.id, &game, dt); if leave { @@ -112,6 +113,7 @@ fn main() -> Result<()> { boost, pos: None, }); + network.queue_out.extend(extra); true }); |