From 0f94e292bde8b9614aa48a6ba87f1a8d927b8133 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 13 Aug 2024 14:50:10 +0200 Subject: replace customers with bots and refactor some more server code. --- server/bot/src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'server/bot/src/main.rs') diff --git a/server/bot/src/main.rs b/server/bot/src/main.rs index 9ecd0a84..cf115358 100644 --- a/server/bot/src/main.rs +++ b/server/bot/src/main.rs @@ -57,6 +57,7 @@ fn main() -> Result<()> { network.queue_out.push_back(PacketS::Join { name: format!("{}-bot", args.username.clone().unwrap_or(args.algo.clone())), character: args.character, + id: None, }); let mut bots = Vec::new(); @@ -85,12 +86,19 @@ fn main() -> Result<()> { game.apply_packet(packet); } - for b in &mut bots { + bots.retain_mut(|b| { let BotInput { direction, boost, interact, + leave, } = b.state.tick(b.id, &game, dt); + + if leave { + network.queue_out.push_back(PacketS::Leave { player: b.id }); + return false; + } + if interact.is_some() != b.interacting { b.interacting = interact.is_some(); network.queue_out.push_back(PacketS::Interact { @@ -104,7 +112,8 @@ fn main() -> Result<()> { boost, pos: None, }); - } + true + }); sleep(Duration::from_secs_f32(dt)); } -- cgit v1.2.3-70-g09d2