aboutsummaryrefslogtreecommitdiff
path: root/server/bot/src/main.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-08-13 14:50:10 +0200
committermetamuffin <metamuffin@disroot.org>2024-08-13 16:03:38 +0200
commit0f94e292bde8b9614aa48a6ba87f1a8d927b8133 (patch)
treefd8bb8c3d38c4b668c46b3b8d8a2b40e99ce2b97 /server/bot/src/main.rs
parenta8376aab4159a449a205de3ed7fdcaa5f6ca6369 (diff)
downloadhurrycurry-0f94e292bde8b9614aa48a6ba87f1a8d927b8133.tar
hurrycurry-0f94e292bde8b9614aa48a6ba87f1a8d927b8133.tar.bz2
hurrycurry-0f94e292bde8b9614aa48a6ba87f1a8d927b8133.tar.zst
replace customers with bots and refactor some more server code.
Diffstat (limited to 'server/bot/src/main.rs')
-rw-r--r--server/bot/src/main.rs13
1 files changed, 11 insertions, 2 deletions
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));
}