aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 10:09:58 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 10:09:58 +0300
commit5f0b8c076b40f8eca67e2745367c731f803914f4 (patch)
tree95bf85609d44cebfaabb86dede135c728d994cdb /crates
parent7dfbf534267011ad629c11c7140d0f9c0fe9cd3b (diff)
downloadfparkan-5f0b8c076b40f8eca67e2745367c731f803914f4.tar.xz
fparkan-5f0b8c076b40f8eca67e2745367c731f803914f4.zip
feat(ui): select units from the strategic warbot roster
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-assets/src/lib.rs1
-rw-r--r--crates/fparkan-assets/src/strategic_roster.rs237
-rw-r--r--crates/fparkan-assets/src/strategy_toolbar.rs22
-rw-r--r--crates/fparkan-runtime/src/lib.rs8
-rw-r--r--crates/fparkan-runtime/src/satellite_contacts.rs2
-rw-r--r--crates/fparkan-runtime/src/strategic_roster.rs215
-rw-r--r--crates/fparkan-runtime/src/unit_patrol/orders.rs27
-rw-r--r--crates/fparkan-runtime/src/unit_size_class.rs2
-rw-r--r--crates/fparkan-runtime/src/unit_spawn.rs8
9 files changed, 509 insertions, 13 deletions
diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs
index d64425ef..090c6c78 100644
--- a/crates/fparkan-assets/src/lib.rs
+++ b/crates/fparkan-assets/src/lib.rs
@@ -47,6 +47,7 @@ pub mod mission_pager;
pub mod object_descriptions;
pub mod satellite_map;
pub mod strategic_balance;
+pub mod strategic_roster;
pub mod strategy_toolbar;
mod turret_elevation;
mod ui_configuration;
diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs
new file mode 100644
index 00000000..3a28ac2a
--- /dev/null
+++ b/crates/fparkan-assets/src/strategic_roster.rs
@@ -0,0 +1,237 @@
+//! The strategic warbot list assembled from installed compound controls.
+
+use crate::{
+ game_font::{load_layout_font, BitmapFont},
+ mission_pager::copy_sprite,
+ ui_sprite::{atlas_region, load_ui_page, load_ui_sprites},
+ RgbaImage,
+};
+use fparkan_vfs::Vfs;
+
+/// List origin and size in the original logical screen coordinates.
+pub const ORIGIN: [u32; 2] = [51, 0];
+pub const EXTENT: [u32; 2] = [319, 480];
+const ROW_TOP: u32 = 118;
+const ROW_PITCH: u32 = 20;
+const ROW_HEIGHT: u32 = 19;
+const TITLE_WIDTH: u32 = 278;
+const CLOSE_LEFT: u32 = 5 + TITLE_WIDTH;
+const TEXT_WIDTH: u32 = 248;
+const TEXT_LEFT: u32 = 10 + 19 * 2 + 5 + 10;
+
+/// The visible interactive area of the original list.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub enum ListHit {
+ Close,
+ Row(usize),
+}
+
+/// Locates a title close control or a list row, preserving the gap between rows.
+pub fn hit_test([x, y]: [f32; 2], row_count: usize) -> Option<ListHit> {
+ let x = x.round_ties_even() - ORIGIN[0] as f32;
+ let y = y.round_ties_even();
+ if !(0.0..(EXTENT[0] - 1) as f32).contains(&x) || !(0.0..480.0).contains(&y) {
+ return None;
+ }
+ if x >= CLOSE_LEFT as f32 && y < 20.0 {
+ return Some(ListHit::Close);
+ }
+ let y = (y as u32).checked_sub(ROW_TOP)?;
+ let row = (y / ROW_PITCH) as usize;
+ (row < row_count && y % ROW_PITCH < ROW_HEIGHT).then_some(ListHit::Row(row))
+}
+
+/// A localized row with the native icon selectors.
+pub struct Row<'a> {
+ pub label: &'a str,
+ pub size: u32,
+ pub chassis: u32,
+ pub selected: bool,
+}
+
+/// Resident art for the header, selected-unit frame, and rows.
+pub struct RosterImages {
+ background: RgbaImage,
+ font: BitmapFont,
+ cap: [RgbaImage; 2],
+ icon_frame: RgbaImage,
+ separator: RgbaImage,
+ emitter: [RgbaImage; 2],
+ ray: RgbaImage,
+ end: RgbaImage,
+ class_icon: RgbaImage,
+ chassis_icons: [RgbaImage; 4],
+}
+
+impl RosterImages {
+ /// Loads the same atlas crops used by the original compound controls.
+ pub fn load(vfs: &dyn Vfs, title: &str) -> Result<Self, String> {
+ let [title_cap, title_body, close, cap_off, cap_on, separator, emitter_off, emitter_on, ray, end, tl, tr, br, bl, horizontal, vertical] =
+ load_ui_sprites(
+ vfs,
+ "ui/compaund.cfg",
+ [
+ "ccres_ending_text",
+ "ccres_body_text",
+ "ccres_exit_button_pressed",
+ "ccres_lamp_text_ending_off",
+ "ccres_lamp_text_ending_normal",
+ "ccres_separator_left_text",
+ "ccres_ray_emitter_off",
+ "ccres_ray_emitter_normal",
+ "ccres_ray_body",
+ "ccres_ray_ending",
+ "ccres_frame_corner_1",
+ "ccres_frame_corner_2",
+ "ccres_frame_corner_3",
+ "ccres_frame_corner_4",
+ "ccres_frame_edge_h",
+ "ccres_frame_edge_v",
+ ],
+ )?;
+ let [exit_icon] = load_ui_sprites(vfs, "ui/hq.cfg", ["exit_icon"])?;
+ let [width, height] = EXTENT;
+ let mut background = RgbaImage {
+ width,
+ height,
+ rgba8: vec![0; (width * height * 4) as usize],
+ };
+ let font = load_layout_font(vfs)?;
+ let caption = font.centered_line(title, TITLE_WIDTH as u16, ROW_HEIGHT as u16)?;
+ stamp(&mut background, &title_cap, [0, 0, 6, 19], [255; 3]);
+ stamp(
+ &mut background,
+ &title_body,
+ [5, 0, CLOSE_LEFT + 1, 19],
+ [255; 3],
+ );
+ stamp(&mut background, &caption, [5, 0, CLOSE_LEFT, 19], [255; 3]);
+ stamp(&mut background, &close, [CLOSE_LEFT, 0, 318, 19], [255; 3]);
+ stamp(
+ &mut background,
+ &exit_icon,
+ [CLOSE_LEFT + 15, 3, CLOSE_LEFT + 28, 16],
+ [255; 3],
+ );
+
+ // iron3d+0x85910 supplies the frame rectangle and its ARGB fill.
+ let fill = RgbaImage {
+ width: 1,
+ height: 1,
+ rgba8: vec![0, 128, 0, 128],
+ };
+ for (sprite, bounds) in [
+ (&fill, [5, 25, 313, 112]),
+ (&horizontal, [8, 20, 310, 25]),
+ (&horizontal, [8, 112, 310, 117]),
+ (&vertical, [0, 28, 5, 109]),
+ (&vertical, [313, 28, 318, 109]),
+ (&tl, [0, 20, 8, 28]),
+ (&tr, [310, 20, 318, 28]),
+ (&br, [310, 109, 318, 117]),
+ (&bl, [0, 109, 8, 117]),
+ ] {
+ stamp(&mut background, sprite, bounds, [255; 3]);
+ }
+ let atlas = load_ui_page(vfs, "ui_menu")?;
+ let icon =
+ |x, y| atlas_region(&atlas, [x, y, 15, 15]).ok_or("warbot glyph outside ui_menu");
+ Ok(Self {
+ background,
+ font,
+ cap: [cap_off, cap_on],
+ icon_frame: title_body,
+ separator,
+ emitter: [emitter_off, emitter_on],
+ ray,
+ end,
+ class_icon: icon(49, 110)?,
+ chassis_icons: [icon(97, 94)?, icon(49, 94)?, icon(65, 94)?, icon(81, 94)?],
+ })
+ }
+
+ /// Renders the visible rows and the identity of the selected unit.
+ pub fn paint(&self, rows: &[Row<'_>]) -> Result<RgbaImage, String> {
+ let mut panel = self.background.clone();
+ if let Some(row) = rows.iter().find(|row| row.selected) {
+ self.icons(&mut panel, row, [9, 27]);
+ let width = u32::from(self.font.line_metrics(row.label)?[0]).min(263);
+ let name = self.font.centered_line(row.label, width as u16, 16)?;
+ stamp(&mut panel, &name, [49, 25, 49 + width, 41], [255, 255, 0]);
+ }
+ for (index, row) in rows.iter().take(19).enumerate() {
+ let y = ROW_TOP + index as u32 * ROW_PITCH;
+ let bottom = y + ROW_HEIGHT;
+ for (sprite, left, width) in [
+ (&self.cap[usize::from(row.selected)], 0, 11),
+ (&self.icon_frame, 10, 20),
+ (&self.icon_frame, 29, 20),
+ (&self.separator, 48, 6),
+ (&self.emitter[usize::from(row.selected)], 53, 11),
+ (&self.ray, TEXT_LEFT, TEXT_WIDTH + 1),
+ (&self.end, TEXT_LEFT + TEXT_WIDTH, 7),
+ ] {
+ stamp(
+ &mut panel,
+ sprite,
+ [left, y, left + width, bottom],
+ [255; 3],
+ );
+ }
+ self.icons(&mut panel, row, [12, y + 2]);
+ let name = self
+ .font
+ .centered_line(row.label, TEXT_WIDTH as u16, ROW_HEIGHT as u16)?;
+ let tint = if row.selected { [255; 3] } else { [128; 3] };
+ stamp(
+ &mut panel,
+ &name,
+ [TEXT_LEFT, y, TEXT_LEFT + TEXT_WIDTH, bottom],
+ tint,
+ );
+ }
+ Ok(panel)
+ }
+
+ fn icons(&self, panel: &mut RgbaImage, row: &Row<'_>, [left, top]: [u32; 2]) {
+ let tint = match row.size {
+ 1 => [255, 231, 255],
+ 2 => [255, 128, 128],
+ 3 => [128, 255, 128],
+ 4 => [128, 128, 255],
+ _ => [255; 3],
+ };
+ stamp(
+ panel,
+ &self.class_icon,
+ [left, top, left + 15, top + 15],
+ tint,
+ );
+ if let Some(icon) = row
+ .chassis
+ .checked_sub(1)
+ .and_then(|index| self.chassis_icons.get(index as usize))
+ {
+ stamp(panel, icon, [left + 19, top, left + 34, top + 15], tint);
+ }
+ }
+}
+
+fn stamp(panel: &mut RgbaImage, sprite: &RgbaImage, bounds: [u32; 4], tint: [u8; 3]) {
+ copy_sprite(panel, sprite, bounds, [false; 2], tint);
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn hit_testing_matches_visible_rows_and_the_close_button() {
+ assert_eq!(hit_test([350.0, 7.0], 3), Some(ListHit::Close));
+ assert_eq!(hit_test([200.0, 118.0], 3), Some(ListHit::Row(0)));
+ assert_eq!(hit_test([200.0, 137.0], 3), None);
+ assert_eq!(hit_test([200.0, 138.0], 3), Some(ListHit::Row(1)));
+ assert_eq!(hit_test([200.0, 158.0], 2), None);
+ assert_eq!(hit_test([200.0, 480.0], 20), None);
+ }
+}
diff --git a/crates/fparkan-assets/src/strategy_toolbar.rs b/crates/fparkan-assets/src/strategy_toolbar.rs
index 4c49e7f0..ac06e26e 100644
--- a/crates/fparkan-assets/src/strategy_toolbar.rs
+++ b/crates/fparkan-assets/src/strategy_toolbar.rs
@@ -21,6 +21,8 @@ const ENABLED_GLYPH: [u8; 3] = [128, 255, 128];
pub enum ToolbarAction {
/// Return to the hero in the suit.
Hero,
+ /// Toggle the clan's warbot list.
+ Warbots,
/// Toggle the satellite map.
Map,
}
@@ -32,12 +34,16 @@ pub fn command_button_at([x, y]: [f32; 2]) -> Option<ToolbarAction> {
return None;
}
let y = y.round_ties_even();
- [(0, ToolbarAction::Hero), (10, ToolbarAction::Map)]
- .into_iter()
- .find_map(|(index, action)| {
- let top = BUTTON_TOPS[index] as f32;
- (top..top + 29.0).contains(&y).then_some(action)
- })
+ [
+ (0, ToolbarAction::Hero),
+ (1, ToolbarAction::Warbots),
+ (10, ToolbarAction::Map),
+ ]
+ .into_iter()
+ .find_map(|(index, action)| {
+ let top = BUTTON_TOPS[index] as f32;
+ (top..top + 29.0).contains(&y).then_some(action)
+ })
}
/// Composes the fully expanded toolbar in its resting state.
@@ -112,6 +118,10 @@ mod tests {
#[test]
fn command_buttons_use_their_original_row_bounds() {
assert_eq!(command_button_at([16.0, 12.0]), Some(ToolbarAction::Hero));
+ assert_eq!(
+ command_button_at([16.0, 65.0]),
+ Some(ToolbarAction::Warbots)
+ );
assert_eq!(command_button_at([45.0, 427.0]), Some(ToolbarAction::Map));
assert_eq!(command_button_at([46.0, 400.0]), None);
assert_eq!(command_button_at([25.0, 428.0]), None);
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index cb8c53d5..96a39732 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -72,6 +72,7 @@ mod node_amount;
mod node_stage;
pub mod satellite_contacts;
pub mod strategic_balance;
+pub mod strategic_roster;
pub mod strategic_view;
pub use clan_clock::note_mission_pause_elapsed;
use control_profile::project_initial as project_control_owner_profile_fca0;
@@ -1532,6 +1533,7 @@ struct LoadedMissionState {
asset_plan: MissionAssetPlan,
object_drafts: Vec<MissionObjectDraft>,
unit_chassis_flags: std::collections::BTreeMap<u32, fparkan_assets::ChassisFlags>,
+ unit_serials: strategic_roster::UnitSerials,
behavior_distributors: Vec<BehaviorDistributorState>,
behavior_ore_states: Vec<BehaviorOreState>,
behavior_profiles: Vec<BehaviorProfileState>,
@@ -2888,6 +2890,11 @@ node_provider_distribution_suspended: false,
let free_research = research::FreeResearch::new(&object_drafts[..reserve_start]);
let chassis_resources = CachedResourceRepository::new(vfs.clone());
let unit_chassis_flags = unit_chassis::load_flags(&chassis_resources, &object_drafts);
+ let unit_serials = strategic_roster::UnitSerials::placed(
+ &engine.world,
+ &object_drafts[..reserve_start],
+ &handles,
+ );
engine.loaded = Some(LoadedMissionState {
summary: summary.clone(),
mission,
@@ -2900,6 +2907,7 @@ node_provider_distribution_suspended: false,
asset_plan: mission_asset_plan,
object_drafts,
unit_chassis_flags,
+ unit_serials,
behavior_distributors,
behavior_ore_states,
behavior_profiles,
diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs
index 68957250..e984baf3 100644
--- a/crates/fparkan-runtime/src/satellite_contacts.rs
+++ b/crates/fparkan-runtime/src/satellite_contacts.rs
@@ -68,7 +68,7 @@ pub fn visible_units(
selected: Option<ObjectHandle>,
) -> impl Iterator<Item = UnitContact> + '_ {
let boarded = crate::player_vehicle(engine).map(|vehicle| vehicle.handle);
- let selected = boarded.or(selected);
+ let selected = selected.or(boarded);
let patrol = engine
.loaded
.as_ref()
diff --git a/crates/fparkan-runtime/src/strategic_roster.rs b/crates/fparkan-runtime/src/strategic_roster.rs
new file mode 100644
index 00000000..acf22590
--- /dev/null
+++ b/crates/fparkan-runtime/src/strategic_roster.rs
@@ -0,0 +1,215 @@
+//! Clan unit registration and the live rows of the strategic warbot list.
+
+use crate::{Engine, MissionObjectDraft, StartingCockpit};
+use fparkan_world::{identity_metadata, registration_sequence, ObjectHandle, OwnerId, World};
+use std::collections::HashMap;
+
+const CATEGORY: u32 = 0x0101_8000;
+const WARBOT: u32 = 0x0100_8000;
+const COMMAND_WARBOT: u32 = 0x0101_0000;
+
+#[derive(Default)]
+pub(super) struct UnitSerials {
+ counts: HashMap<OwnerId, u32>,
+ slots: HashMap<u32, (u32, u32)>,
+}
+
+impl UnitSerials {
+ pub(super) fn placed(
+ world: &World,
+ drafts: &[MissionObjectDraft],
+ handles: &[ObjectHandle],
+ ) -> Self {
+ let mut serials = Self::default();
+ for (draft, &handle) in drafts.iter().zip(handles) {
+ if let (Some(class), Some(owner)) = (
+ draft.unit_dat_header_flags,
+ identity_metadata(world, handle)
+ .ok()
+ .and_then(|meta| meta.owner_id),
+ ) {
+ serials.register(handle, owner, class);
+ }
+ }
+ serials
+ }
+
+ pub(super) fn register(&mut self, handle: ObjectHandle, owner: OwnerId, class: u32) {
+ if class & crate::autodemo::MOBILE_UNIT == 0
+ && class != crate::projectile::ANIMAL_UNIT_CLASS
+ {
+ return;
+ }
+ // iron3d+0x761a0 advances the naming counter of the registering clan.
+ let serial = self.counts.entry(owner).or_default();
+ *serial += 1;
+ self.slots.insert(handle.slot, (handle.generation, *serial));
+ }
+
+ fn get(&self, handle: ObjectHandle) -> Option<u32> {
+ let &(generation, serial) = self.slots.get(&handle.slot)?;
+ (generation == handle.generation).then_some(serial)
+ }
+}
+
+/// Snapshot of an eligible unit for the strategic list.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct WarbotRow {
+ /// Unit represented by the row, including its generation.
+ pub handle: ObjectHandle,
+ /// Three ASCII letters identifying size, chassis, and class.
+ pub prefix: [char; 3],
+ /// Stable number assigned at creation in the original clan.
+ pub serial: u32,
+ /// String table ID for the name suffix.
+ pub class_label: u32,
+ /// String table ID for the active order.
+ pub order_label: u32,
+ /// Display class, from Behavior property 0x201.
+ pub size: u32,
+ /// Locomotion type, from Behavior property 0x207.
+ pub chassis: u32,
+ /// Whether the unit is eligible for automatic selection.
+ pub selectable: bool,
+}
+
+/// Returns the player's warbots in registration order, including any entries whose controller is depleted.
+pub fn warbot_rows(engine: &Engine, cockpit: StartingCockpit) -> Vec<WarbotRow> {
+ let Some((mission, owner)) = engine.loaded.as_ref().zip(
+ identity_metadata(&engine.world, cockpit.handle)
+ .ok()
+ .and_then(|meta| meta.owner_id),
+ ) else {
+ return Vec::new();
+ };
+ let mut rows: Vec<_> = mission
+ .control_device_tables
+ .iter()
+ .filter_map(|table| {
+ let handle = table.handle;
+ let draft = mission.object_drafts.get(table.original_id?.0 as usize)?;
+ let class = draft.unit_dat_header_flags?;
+ if class == 0
+ || class & CATEGORY != class
+ || identity_metadata(&engine.world, handle).ok()?.owner_id != Some(owner)
+ {
+ return None;
+ }
+ let (role, class_label) = match class {
+ WARBOT => ('W', 0x183a),
+ COMMAND_WARBOT => ('C', 0x183b),
+ _ => return None,
+ };
+ let sequence = registration_sequence(&engine.world, handle).ok()??;
+ let serial = mission.unit_serials.get(handle)?;
+ let size =
+ crate::unit_size_class::classify(4, &draft.unit_components.first()?.resource_raw);
+ let chassis = mission
+ .unit_chassis_flags
+ .get(&table.original_id?.0)
+ .and_then(|flags| flags.chassis_type)
+ .unwrap_or(0);
+ let order = mission
+ .unit_patrol
+ .as_ref()
+ .map_or(0, |patrol| patrol.active_order_code(handle));
+ let row = WarbotRow {
+ handle,
+ prefix: [letter(b"?TSML", size), letter(b"?FSWTAU", chassis), role],
+ serial,
+ class_label,
+ order_label: order_label(order),
+ size,
+ chassis,
+ selectable: !table.node_provider_depletion_marked,
+ };
+ Some((sequence, row))
+ })
+ .collect();
+ rows.sort_unstable_by_key(|&(sequence, _)| sequence);
+ rows.into_iter().map(|(_, row)| row).collect()
+}
+
+fn letter(alphabet: &[u8], value: u32) -> char {
+ char::from(alphabet.get(value as usize).copied().unwrap_or(b'?'))
+}
+
+fn order_label(order: u32) -> u32 {
+ match order {
+ 0 => 0x1824,
+ 2 => 0x1828,
+ 3 => 0x182c,
+ 4 => 0x182d,
+ 0x11 => 0x1833,
+ 0x13 => 0x1826,
+ 0x14 => 0x1829,
+ _ => 0x1835,
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn numbers_all_mobile_classes_per_creation_clan_without_reusing_a_stale_handle() {
+ let mut serials = UnitSerials::default();
+ let handle = |slot, generation| ObjectHandle { slot, generation };
+ let local = OwnerId(0);
+ serials.register(handle(0, 1), local, 0x8001_0000);
+ serials.register(handle(1, 1), local, 0x0100_2000);
+ serials.register(handle(2, 1), local, 0x0100_4000);
+ serials.register(handle(3, 1), OwnerId(1), WARBOT);
+ serials.register(handle(4, 1), local, WARBOT);
+ assert_eq!(serials.get(handle(4, 1)), Some(3));
+ assert_eq!(serials.get(handle(3, 1)), Some(1));
+ serials.register(handle(4, 2), local, COMMAND_WARBOT);
+ assert_eq!(serials.get(handle(4, 1)), None);
+ assert_eq!(serials.get(handle(4, 2)), Some(4));
+ }
+
+ #[test]
+ #[ignore = "requires licensed corpus"]
+ fn licensed_two_fortresses_roster_uses_live_clan_and_original_serials() {
+ use crate::{
+ create, load_gameplay_mission, starting_cockpit, EngineServices, MissionMode,
+ MissionRequest, MissionStartupInput,
+ };
+ use fparkan_vfs::DirectoryVfs;
+ use fparkan_world::set_owner;
+ use std::sync::Arc;
+
+ let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap();
+ let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap();
+ load_gameplay_mission(
+ &mut engine,
+ MissionRequest {
+ key: "MISSIONS/Single.01/data.tma".into(),
+ mode: MissionMode::SingleMission,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ None,
+ )
+ .unwrap();
+ let cockpit = starting_cockpit(&engine).unwrap();
+ let rows = warbot_rows(&engine, cockpit);
+ let labels: Vec<_> = rows
+ .iter()
+ .map(|row| (row.prefix, row.serial, row.order_label))
+ .collect();
+ assert_eq!(
+ labels,
+ [
+ (['L', 'T', 'W'], 3, 0x1824),
+ (['L', 'T', 'W'], 4, 0x1824),
+ (['M', 'T', 'W'], 5, 0x1824)
+ ]
+ );
+
+ set_owner(&mut engine.world, rows[0].handle, None).unwrap();
+ assert_eq!(warbot_rows(&engine, cockpit), rows[1..]);
+ }
+}
diff --git a/crates/fparkan-runtime/src/unit_patrol/orders.rs b/crates/fparkan-runtime/src/unit_patrol/orders.rs
index 560f2142..8e9260a1 100644
--- a/crates/fparkan-runtime/src/unit_patrol/orders.rs
+++ b/crates/fparkan-runtime/src/unit_patrol/orders.rs
@@ -50,6 +50,33 @@ pub(crate) fn supports_order(order: &Handler15Invocation) -> bool {
}
impl UnitPatrol {
+ pub(crate) fn active_order_code(&self, actor: ObjectHandle) -> u32 {
+ if self.is_leaving_factory(actor) {
+ return 0x14;
+ }
+ if self.is_shut_down(actor) {
+ return UnitOrder::Shutdown.opcode();
+ }
+ let Some(unit) = self.units.iter().find(|unit| unit.handle == actor) else {
+ return 0;
+ };
+ if unit.capture_target.is_some() {
+ 0x11
+ } else if unit.attack_target.is_some() || unit.raid_factory.is_some() {
+ 3
+ } else if unit
+ .destinations
+ .as_ref()
+ .is_some_and(|points| !points.is_empty())
+ {
+ 2
+ } else if unit.destinations.is_none() {
+ 4
+ } else {
+ 0
+ }
+ }
+
pub(crate) fn satellite_route(&self, actor: ObjectHandle) -> Vec<[f32; 2]> {
let active = self.units.iter().find(|unit| unit.handle == actor);
// iron3d+0x77ae0 prefers the path whenever there are unvisited points.
diff --git a/crates/fparkan-runtime/src/unit_size_class.rs b/crates/fparkan-runtime/src/unit_size_class.rs
index 8f9a2d93..a786c610 100644
--- a/crates/fparkan-runtime/src/unit_size_class.rs
+++ b/crates/fparkan-runtime/src/unit_size_class.rs
@@ -30,7 +30,7 @@ pub(super) fn query(
Ok(classify(kind, resource))
}
-fn classify(kind: u32, name: &[u8]) -> u32 {
+pub(super) fn classify(kind: u32, name: &[u8]) -> u32 {
let name = &name[..name
.iter()
.position(|&byte| byte == 0)
diff --git a/crates/fparkan-runtime/src/unit_spawn.rs b/crates/fparkan-runtime/src/unit_spawn.rs
index 09345192..7af5db10 100644
--- a/crates/fparkan-runtime/src/unit_spawn.rs
+++ b/crates/fparkan-runtime/src/unit_spawn.rs
@@ -60,11 +60,9 @@ pub(super) fn spawn_prepared_unit(
.behavior_control_groupings
.push(crate::project_mission_behavior_control_grouping(&table));
mission.control_device_tables.push(table);
- mission.mission_events.register_unit(
- world,
- handle,
- draft.unit_dat_header_flags.expect("prepared reserve"),
- );
+ let class = draft.unit_dat_header_flags.expect("prepared reserve");
+ mission.mission_events.register_unit(world, handle, class);
+ mission.unit_serials.register(handle, OwnerId(clan), class);
mission.note_clan_registration(OwnerId(clan), handle);
Ok(handle)
}