//! Orders issued by the player from the strategic warbot panel. use crate::{strategic_roster::warbot_rows, unit_patrol::UnitPatrol, Engine, StartingCockpit}; use fparkan_terrain::NavigationQuery; use fparkan_world::{identity_metadata, ObjectHandle}; /// Tests a route waypoint using the selected warbot's chassis and the native areal flag. pub fn accepts_waypoint(engine: &Engine, actor: ObjectHandle, [x, y]: [f32; 2]) -> bool { if !x.is_finite() || !y.is_finite() { return false; } let Some(mission) = &engine.loaded else { return false; }; let Some(original) = identity_metadata(&engine.world, actor) .ok() .and_then(|meta| meta.original_id) else { return false; }; let terrain = &mission.terrain; let Some(areal) = terrain.locate_areal([x, y, 0.0]).ok().flatten() else { return false; }; // iron3d+0x76bc0 allows chassis selector 1 in any resolved areal. mission .unit_chassis_flags .get(&original.0) .is_some_and(|flags| flags.chassis_type == Some(1)) || terrain .areal_logic_flag(areal) .is_some_and(|flag| flag != 0) } /// Stops the selected warbot and clears its outstanding movement orders. pub fn stand(engine: &mut Engine, cockpit: StartingCockpit, actor: ObjectHandle) -> bool { issue(engine, cockpit, actor, None) } /// Replaces the selected warbot's order with the confirmed sequence of world points. pub fn follow_route( engine: &mut Engine, cockpit: StartingCockpit, actor: ObjectHandle, points: &[[f32; 2]], ) -> bool { if points.is_empty() || !points .iter() .all(|&point| accepts_waypoint(engine, actor, point)) { return false; } issue(engine, cockpit, actor, Some(points.to_vec())) } fn issue( engine: &mut Engine, cockpit: StartingCockpit, actor: ObjectHandle, route: Option>, ) -> bool { if !warbot_rows(engine, cockpit) .iter() .any(|row| row.handle == actor && row.selectable) { return false; } let Some(mission) = engine.loaded.as_mut() else { return false; }; mission .unit_patrol .get_or_insert_with(UnitPatrol::scripted) .command_order(&engine.world, actor, route); true }