use crate::{ pathfinding::{find_path_to_neighbour, Path}, BotAlgo, BotInput, }; use hurrycurry_client_lib::Game; use hurrycurry_protocol::{glam::IVec2, ItemIndex, Message, PlayerID}; use log::info; #[derive(Default)] pub struct Test { path: Option, } impl BotAlgo for Test { fn tick(&mut self, me: PlayerID, game: &Game, _dt: f32) -> BotInput { let Some(player) = game.players.get(&me) else { return BotInput::default(); }; let pos = player.movement.position; if let Some(path) = &mut self.path { let direction = path.next_direction(pos); return BotInput { direction, boost: false, interact: None, }; } else { if let Some((item, near)) = find_demand(game) { info!("demand {item:?} near {near}"); if let Some(path) = find_path_to_neighbour(&game.walkable, pos.as_ivec2(), near) { self.path = Some(path); } } } BotInput::default() } } fn find_demand(game: &Game) -> Option<(ItemIndex, IVec2)> { game.players .iter() .find_map(|(_, pl)| match &pl.communicate_persist { Some(Message::Item(item)) => { let pos = pl.movement.position.as_ivec2(); let t = pos; Some((*item, t)) } _ => None, }) }