aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-25 23:57:43 +0300
committerValentin Popov <valentin@popov.link>2026-11-25 23:57:43 +0300
commit530afea388f4e487a5a1320381c59e7d217717d8 (patch)
tree535b5722ff694d3d666c18aa143a8447d86c068a /crates
parent2d7c17b13b0dc2e4a4712fee25aa8f06161a141b (diff)
downloadfparkan-530afea388f4e487a5a1320381c59e7d217717d8.tar.xz
fparkan-530afea388f4e487a5a1320381c59e7d217717d8.zip
fix(control): refresh motion limits after node damage
Run the supported dirty Control profile branch on the resource clock, before the existing factory/laboratory budget pass. Mobile owners now participate in these clocks. Root hits reduce the drive's current E00 value and the next place-patrol speed request uses the updated limit. Keep mutable node-group means and publish profile words atomically. Move FCA0 projection into control_profile rather than extending lib.rs. Count clock checks, publications and unsupported updates per object; alarm damage, activation and mobile device budgets remain explicit gaps. Native Control.dll RVA 0x12a40 -> 0xfca0 confirms mean retention, clean-call behavior and the healthy-critical-group branch that bypasses the aggregate threshold. Golden outputs are covered by Rust tests. SHA-256: bcb86318089028548a178b03a21accdce15df0cc85ddd91674cf3c2f55012c6e. Validated fmt, workspace check/tests, release, licensed stock damage, combat and patrol regressions, plus all 29 stock missions for 900 seconds without new profile-update stops. Stock window AI hits change limits. The additional live native interception yielded no usable sample; its supported calculation branches were executed directly in the DLL.
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-runtime/src/control_profile.rs392
-rw-r--r--crates/fparkan-runtime/src/control_resources.rs66
-rw-r--r--crates/fparkan-runtime/src/lib.rs106
-rw-r--r--crates/fparkan-runtime/src/patrol_speed.rs2
4 files changed, 459 insertions, 107 deletions
diff --git a/crates/fparkan-runtime/src/control_profile.rs b/crates/fparkan-runtime/src/control_profile.rs
new file mode 100644
index 00000000..eb09b66b
--- /dev/null
+++ b/crates/fparkan-runtime/src/control_profile.rs
@@ -0,0 +1,392 @@
+//! Mutable Control motion limits after provider amounts change.
+
+use crate::{
+ control_fca0_clamp_to_profile_cap, control_fca0_float, control_fca0_product,
+ control_fca0_ratio, control_fca0_sum, query_control_device_selector, EffectiveControlDevice,
+ MissionControlClassProjection, MissionControlDeviceTableState, MissionControlDeviceTableStatus,
+ MissionControlNodeProviderTableStatus, MissionControlOwnerProfileFca0UnavailableReason,
+ MissionControlOwnerProfileLoadProjection,
+ MissionControlOwnerProfileLoadProjectionUnavailableReason,
+};
+use std::{collections::BTreeMap, sync::Arc};
+
+/// Native owner fields +0x1a8, +0x354 and +0x358, retained across dirty updates.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub struct ControlProfileScalars {
+ pub scalar_bits: u32,
+ pub mean_a_bits: u32,
+ pub mean_b_bits: u32,
+}
+
+impl Default for ControlProfileScalars {
+ fn default() -> Self {
+ Self {
+ scalar_bits: 1.0_f32.to_bits(),
+ mean_a_bits: 1.0_f32.to_bits(),
+ mean_b_bits: 1.0_f32.to_bits(),
+ }
+ }
+}
+
+/// Resource-clock checks, dirty profile publications and unresolved updates.
+#[derive(Clone, Debug, Default, Eq, PartialEq)]
+pub struct ControlProfileReport {
+ pub ticks: BTreeMap<u32, u64>,
+ /// Object -> (updates, previous forward-limit bits, latest forward-limit bits).
+ pub updates: BTreeMap<u32, (u64, u32, u32)>,
+ pub stubs: BTreeMap<(u32, String), u64>,
+}
+
+pub(super) fn project_initial(
+ native_class: Option<MissionControlClassProjection>,
+ original_words: &[u32; 27],
+ current_words: &[u32; 27],
+ fac0_projection: &Result<
+ MissionControlOwnerProfileLoadProjection,
+ MissionControlOwnerProfileLoadProjectionUnavailableReason,
+ >,
+ devices: &[EffectiveControlDevice],
+ provider_status: &MissionControlNodeProviderTableStatus,
+) -> Result<[u32; 27], MissionControlOwnerProfileFca0UnavailableReason> {
+ project(
+ native_class,
+ original_words,
+ current_words,
+ fac0_projection,
+ devices,
+ provider_status,
+ ControlProfileScalars::default(),
+ )
+}
+
+fn node_means(
+ mut scalars: ControlProfileScalars,
+ rows: impl IntoIterator<Item = (u32, f32)>,
+ low_total_amount: bool,
+) -> Result<ControlProfileScalars, &'static str> {
+ let mut sums = [0.0_f32; 3];
+ let mut counts = [0.0_f32; 3];
+ for (flags, value) in rows {
+ if flags & 0x70 == 0 {
+ continue;
+ }
+ if !value.is_finite() || !(0.0..=1.0).contains(&value) {
+ return Err("node_ratio");
+ }
+ for (group, mask) in [0x70, 0x20, 0x40].into_iter().enumerate() {
+ if flags & mask != 0 {
+ sums[group] += value;
+ counts[group] += 1.0;
+ }
+ }
+ }
+ // Control+0x12a40 enters its damage/alarm path at this boundary.
+ if counts[0] > 1.0 {
+ if sums[0] <= counts[0] * 0.5 - 1.0 {
+ return Err("critical_nodes_alarm");
+ }
+ } else if low_total_amount {
+ return Err("provider_amount_alarm");
+ }
+ if counts[1] > 0.0 {
+ scalars.mean_a_bits = (sums[1] / counts[1]).to_bits();
+ }
+ if counts[2] > 0.0 {
+ scalars.mean_b_bits = (sums[2] / counts[2]).to_bits();
+ }
+ Ok(scalars)
+}
+
+/// The non-alarm dirty branch of Control+0x12a40, before the budget pass.
+pub(super) fn refresh(table: &mut MissionControlDeviceTableState) -> Result<bool, String> {
+ if !table.node_provider_dirty {
+ return Ok(false);
+ }
+ let profile = table.owner_profile.as_ref().ok_or("owner_profile")?;
+ let rows = match &table.node_provider_status {
+ MissionControlNodeProviderTableStatus::Available(rows) => rows,
+ MissionControlNodeProviderTableStatus::Unavailable(_) => {
+ return Err("provider_table".into())
+ }
+ };
+ let amount = table
+ .node_provider_amount_bits
+ .map(f32::from_bits)
+ .ok_or("provider_amount")?;
+ let maximum = table
+ .node_provider_maximum_amount_bits
+ .map(f32::from_bits)
+ .ok_or("provider_maximum")?;
+ let class = table.native_control_class.ok_or("owner_class")?;
+ let threshold = maximum * if class.class_id == 10 { 0.3 } else { 0.2 };
+ if !amount.is_finite() || !maximum.is_finite() || maximum <= 0.0 {
+ return Err("provider_amount_range".into());
+ }
+ let scalars = node_means(
+ profile.scalars,
+ rows.iter().map(|row| {
+ (
+ row.source_row.raw_flags,
+ f32::from_bits(row.current_type1_value_bits),
+ )
+ }),
+ amount < threshold,
+ )?;
+ let devices = match &table.status {
+ MissionControlDeviceTableStatus::Available(devices) => devices,
+ MissionControlDeviceTableStatus::Unavailable(_) => return Err("device_table".into()),
+ };
+ let words = project(
+ table.native_control_class,
+ &profile.original_words,
+ &profile.current_words,
+ &profile.load_projection,
+ devices,
+ &table.node_provider_status,
+ scalars,
+ )
+ .map_err(|reason| format!("{reason:?}"))?;
+ let profile = table.owner_profile.as_mut().expect("checked profile");
+ profile.current_words = words;
+ profile.scalars = scalars;
+ table.node_provider_dirty = false;
+ Ok(true)
+}
+
+pub(super) fn project(
+ native_class: Option<MissionControlClassProjection>,
+ original_words: &[u32; 27],
+ current_words: &[u32; 27],
+ fac0_projection: &Result<
+ MissionControlOwnerProfileLoadProjection,
+ MissionControlOwnerProfileLoadProjectionUnavailableReason,
+ >,
+ devices: &[EffectiveControlDevice],
+ provider_status: &MissionControlNodeProviderTableStatus,
+ scalars: ControlProfileScalars,
+) -> Result<[u32; 27], MissionControlOwnerProfileFca0UnavailableReason> {
+ use MissionControlOwnerProfileFca0UnavailableReason as Unavailable;
+
+ if native_class.is_some_and(|class| class.class_id == 9) {
+ return Ok(*current_words);
+ }
+ if native_class.is_none() {
+ return Err(Unavailable::MissingNativeControlClass);
+ }
+ if let Err(reason) = fac0_projection {
+ return Err(Unavailable::Fac0Unavailable(reason.clone()));
+ }
+
+ let mut e00_sum = 0.0_f32;
+ for device_index in (0..devices.len()).rev() {
+ if devices[device_index].descriptor.tag != 5 {
+ continue;
+ }
+ if let Some(value) = query_control_device_selector(&devices[device_index], provider_status)
+ .map_err(|error| Unavailable::QueryUnavailable(Arc::new(error)))?
+ {
+ e00_sum = control_fca0_sum(e00_sum, value, "FCA0 reverse E00 sum")?;
+ }
+ }
+
+ scale_words(original_words, current_words, scalars, e00_sum)
+}
+
+fn scale_words(
+ original_words: &[u32; 27],
+ current_words: &[u32; 27],
+ scalars: ControlProfileScalars,
+ e00_sum: f32,
+) -> Result<[u32; 27], MissionControlOwnerProfileFca0UnavailableReason> {
+ let owner_scalar =
+ control_fca0_float(f32::from_bits(scalars.scalar_bits), "FCA0 owner scalar")?;
+ let owner_mean = control_fca0_sum(
+ f32::from_bits(scalars.mean_a_bits),
+ f32::from_bits(scalars.mean_b_bits),
+ "FCA0 owner scalar mean",
+ )?;
+ let owner_mean = control_fca0_product(owner_mean, 0.5, "FCA0 owner scalar mean")?;
+ let weight = control_fca0_product(owner_mean, e00_sum, "FCA0 weighted E00 sum")?;
+ let ratio = control_fca0_ratio(
+ control_fca0_float(f32::from_bits(current_words[26]), "current profile word 26")?,
+ control_fca0_float(
+ f32::from_bits(original_words[26]),
+ "original profile word 26",
+ )?,
+ "FCA0 profile word 26 ratio",
+ )?;
+ let factor_a = control_fca0_product(
+ control_fca0_sum(ratio, 1.0, "FCA0 factor A")?,
+ 0.5,
+ "FCA0 factor A",
+ )?;
+ let factor_b = control_fca0_sum(
+ control_fca0_product(ratio, 0.75, "FCA0 factor B")?,
+ 0.25,
+ "FCA0 factor B",
+ )?;
+
+ let mut current_words = *current_words;
+ for index in 6..9 {
+ let original = control_fca0_float(
+ f32::from_bits(original_words[index]),
+ "original profile words 6..8",
+ )?;
+ let owner_scaled =
+ control_fca0_product(owner_scalar, original, "FCA0 first profile triple")?;
+ let weighted = control_fca0_product(owner_scaled, weight, "FCA0 first profile triple")?;
+ let factored = control_fca0_product(weighted, factor_a, "FCA0 first profile triple")?;
+ current_words[index] =
+ control_fca0_clamp_to_profile_cap(factored, original, "FCA0 first profile triple")?
+ .to_bits();
+ }
+ for index in 9..12 {
+ let original = control_fca0_float(
+ f32::from_bits(original_words[index]),
+ "original profile words 9..11",
+ )?;
+ let weighted = control_fca0_product(weight, original, "FCA0 second profile triple")?;
+ let factored = control_fca0_product(weighted, factor_b, "FCA0 second profile triple")?;
+ current_words[index] =
+ control_fca0_sum(factored, factored, "FCA0 doubled second profile triple")?.to_bits();
+ }
+ for index in 0..3 {
+ let original = control_fca0_float(
+ f32::from_bits(original_words[index]),
+ "original profile words 0..2",
+ )?;
+ current_words[index] =
+ control_fca0_sum(original, original, "FCA0 doubled profile words")?.to_bits();
+ }
+ Ok(current_words)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn native_dirty_update_uses_means_and_retains_an_absent_group() {
+ // GOG Control.dll RVA 0x12a40 -> 0xfca0, x87 CW 0x007f.
+ let mut scalars = ControlProfileScalars::default();
+ let mut original = [0; 27];
+ original[6..9].copy_from_slice(&[10.0_f32, 20.0, 30.0].map(f32::to_bits));
+ original[26] = 4.0_f32.to_bits();
+ for (rows, a, b, limit) in [
+ (
+ [(0x20, 0.25), (0x40, 0.75)],
+ 0x3e800000,
+ 0x3f400000,
+ 0x40f00000,
+ ),
+ (
+ [(0x20, 1.0), (0x40, 0.5)],
+ 0x3f800000,
+ 0x3f000000,
+ 0x41340000,
+ ),
+ (
+ [(0x10, 0.5), (0x40, 1.0)],
+ 0x3f800000,
+ 0x3f800000,
+ 0x41700000,
+ ),
+ ] {
+ scalars = node_means(scalars, rows, false).unwrap();
+ assert_eq!((scalars.mean_a_bits, scalars.mean_b_bits), (a, b));
+ let words = scale_words(&original, &original, scalars, 0.75).unwrap();
+ assert_eq!(words[7], limit);
+ }
+ }
+
+ #[test]
+ fn node_means_count_each_membership_and_reject_the_alarm_branch() {
+ let means = node_means(
+ ControlProfileScalars::default(),
+ [(0x60, 0.5), (0x20, 1.0), (0, 0.0)],
+ false,
+ )
+ .unwrap();
+ assert_eq!(f32::from_bits(means.mean_a_bits), 0.75);
+ assert_eq!(f32::from_bits(means.mean_b_bits), 0.5);
+ assert!(node_means(
+ ControlProfileScalars::default(),
+ [(0x20, 0.0), (0x40, 0.0)],
+ false
+ )
+ .is_err());
+ // Native 0x12a40 bypasses the aggregate threshold when >1 critical
+ // rows pass their own health test: 10 total / 100 max still updates.
+ assert!(node_means(
+ ControlProfileScalars::default(),
+ [(0x20, 1.0), (0x40, 1.0)],
+ true
+ )
+ .is_ok());
+ assert_eq!(
+ node_means(ControlProfileScalars::default(), [(0x20, 1.0)], true),
+ Err("provider_amount_alarm")
+ );
+ }
+
+ #[test]
+ #[ignore = "requires licensed corpus"]
+ fn licensed_stock_damage_changes_patrol_limit_on_the_resource_clock() {
+ use crate::{
+ apply_projectile_hit, create, frame, load_gameplay_mission, EngineServices,
+ MissionMode, MissionRequest, MissionStartupInput,
+ };
+ use fparkan_vfs::DirectoryVfs;
+
+ 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/Autodemo.00/data.tma".into(),
+ mode: MissionMode::AutoDemo,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ None,
+ )
+ .unwrap();
+ frame(&mut engine, 0).unwrap();
+ let table = &engine.loaded.as_ref().unwrap().control_device_tables[0];
+ let handle = table.handle;
+ let before = f32::from_bits(table.owner_profile.as_ref().unwrap().current_words[7]);
+ let MissionControlNodeProviderTableStatus::Available(rows) = &table.node_provider_status
+ else {
+ panic!("stock provider rows");
+ };
+ let damage = f32::from_bits(rows[0].current_amount_bits) * 0.25;
+ assert!(apply_projectile_hit(&mut engine, handle, damage)
+ .unwrap()
+ .is_some());
+ frame(&mut engine, 200).unwrap();
+ let table = &engine.loaded.as_ref().unwrap().control_device_tables[0];
+ assert_eq!(
+ f32::from_bits(table.owner_profile.as_ref().unwrap().current_words[7]),
+ before
+ );
+ frame(&mut engine, 300).unwrap();
+ frame(&mut engine, 350).unwrap();
+ let mission = engine.loaded.as_ref().unwrap();
+ let profile = mission.control_device_tables[0]
+ .owner_profile
+ .as_ref()
+ .unwrap();
+ let after = f32::from_bits(profile.current_words[7]);
+ assert!(
+ (after - before * 0.75).abs() < 0.00001,
+ "{before} -> {after}"
+ );
+ let report = &mission.control_resources.profiles;
+ assert_eq!(report.updates[&0].0, 1);
+ assert!(report.stubs.is_empty(), "{:?}", report.stubs);
+ let patrol = mission.unit_patrol.as_ref().unwrap();
+ assert_eq!(patrol.speed_report.samples[&0].2, (after * 0.8).to_bits());
+ }
+}
diff --git a/crates/fparkan-runtime/src/control_resources.rs b/crates/fparkan-runtime/src/control_resources.rs
index 18af1975..86a402e1 100644
--- a/crates/fparkan-runtime/src/control_resources.rs
+++ b/crates/fparkan-runtime/src/control_resources.rs
@@ -1,4 +1,6 @@
-use crate::{control_resource_budget_pass, LoadedMissionState};
+use crate::{
+ control_profile, control_resource_budget_pass, ControlProfileReport, LoadedMissionState,
+};
use fparkan_world::{transform_state, ObjectHandle, World};
use std::collections::BTreeMap;
@@ -8,6 +10,7 @@ pub(super) struct Resources {
rng: u32,
ticks: BTreeMap<u32, u64>,
stops: BTreeMap<u32, (u64, String)>,
+ pub(super) profiles: ControlProfileReport,
}
impl Default for Resources {
@@ -18,6 +21,7 @@ impl Default for Resources {
rng: 1,
ticks: BTreeMap::new(),
stops: BTreeMap::new(),
+ profiles: ControlProfileReport::default(),
}
}
}
@@ -40,17 +44,16 @@ pub(super) fn tick(mission: &mut LoadedMissionState, world: &World, now_ms: u32)
.clocks
.retain(|(handle, _)| transform_state(world, *handle).is_ok());
for table in &mut mission.control_device_tables {
- if !table
+ let flags = table
.original_id
.and_then(|id| mission.object_drafts.get(id.0 as usize))
- .is_some_and(|draft| {
- matches!(
- draft.unit_dat_header_flags,
- Some(crate::autodemo::PLANT_CLASS | crate::laboratory::LAB_CLASS)
- )
- })
- || transform_state(world, table.handle).is_err()
- {
+ .and_then(|draft| draft.unit_dat_header_flags);
+ let budget_owner = matches!(
+ flags,
+ Some(crate::autodemo::PLANT_CLASS | crate::laboratory::LAB_CLASS)
+ );
+ let mobile_owner = flags.is_some_and(|flags| flags & crate::autodemo::MOBILE_UNIT != 0);
+ if (!budget_owner && !mobile_owner) || transform_state(world, table.handle).is_err() {
continue;
}
let clock = if let Some(index) = state
@@ -78,6 +81,49 @@ pub(super) fn tick(mission: &mut LoadedMissionState, world: &World, now_ms: u32)
let Some(seconds) = clock.step(now_ms as f32, true, 250.0, &mut state.rng) else {
continue;
};
+ let object = table.original_id.map_or(table.handle.slot, |id| id.0);
+ let ticks = state.profiles.ticks.entry(object).or_default();
+ *ticks += 1;
+ if *ticks == 1 {
+ eprintln!("control_profile_clock_approx object={object} (Control RNG seed, owner order and activation remain open)");
+ }
+ let before = table
+ .owner_profile
+ .as_ref()
+ .map_or(0, |profile| profile.current_words[7]);
+ match control_profile::refresh(table) {
+ Ok(true) => {
+ let after = table
+ .owner_profile
+ .as_ref()
+ .expect("refreshed profile")
+ .current_words[7];
+ let update = state.profiles.updates.entry(object).or_default();
+ *update = (update.0 + 1, before, after);
+ if before != after {
+ eprintln!(
+ "control_profile_updated object={object} forward_limit={} -> {}",
+ f32::from_bits(before),
+ f32::from_bits(after)
+ );
+ }
+ }
+ Ok(false) => {}
+ Err(reason) => {
+ let count = state
+ .profiles
+ .stubs
+ .entry((object, reason.clone()))
+ .or_default();
+ *count += 1;
+ if *count == 1 {
+ eprintln!("control_profile_update_stub object={object} reason={reason}");
+ }
+ }
+ }
+ if !budget_owner {
+ continue;
+ }
match control_resource_budget_pass(table, seconds) {
Ok(()) => {
let count = state.ticks.entry(table.handle.slot).or_default();
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 6b84baab..a1866dd3 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -51,8 +51,11 @@ mod clan_area_strength;
mod clan_build_limits;
mod clan_building_queries;
mod clan_clock;
+mod control_profile;
mod control_resources;
pub use clan_clock::note_mission_pause_elapsed;
+use control_profile::project_initial as project_control_owner_profile_fca0;
+pub use control_profile::{ControlProfileReport, ControlProfileScalars};
mod clan_combat_groups;
mod clan_combat_strength;
mod clan_factory_schemes;
@@ -884,8 +887,10 @@ pub struct MissionControlOwnerProfile {
pub native_component_id: u32,
/// Original profile words held by the Control resource cache.
pub original_words: [u32; 27],
- /// Initial per-owner copy; this is mutated independently from `original_words`.
+ /// Per-owner copy, mutated independently from `original_words`.
pub current_words: [u32; 27],
+ /// Mutable owner scalar and node-group means used by FCA0.
+ pub scalars: ControlProfileScalars,
/// Initial FAC0 projection, separate from base device-table availability.
pub load_projection: Result<
MissionControlOwnerProfileLoadProjection,
@@ -2982,6 +2987,7 @@ pub struct SimulationReport {
pub weapon_poses: WeaponPoseReport,
pub patrol_points: PatrolPointReport,
pub patrol_speeds: PatrolSpeedReport,
+ pub control_profiles: ControlProfileReport,
/// Approximate clan strength queries, grouped by caller and target clan.
pub script_strength_queries: Vec<(usize, u16, u64)>,
pub script_capture_queries: Vec<(usize, u64)>,
@@ -3061,6 +3067,7 @@ pub fn simulate_mission_report(
weapon_poses: WeaponPoseReport::default(),
patrol_points: PatrolPointReport::default(),
patrol_speeds: PatrolSpeedReport::default(),
+ control_profiles: ControlProfileReport::default(),
script_strength_queries: Vec::new(),
script_capture_queries: Vec::new(),
script_attack_queries: Vec::new(),
@@ -3168,6 +3175,7 @@ pub fn simulate_mission_report(
.clan_research_catalogs
.extend(loaded.clan_ai_events.research_catalogs());
report.laboratory = loaded.laboratories.report();
+ report.control_profiles = loaded.control_resources.profiles.clone();
if let Some(patrol) = &loaded.unit_patrol {
report.patrol_points = patrol.point_report.clone();
report.patrol_speeds = patrol.speed_report.clone();
@@ -6866,101 +6874,6 @@ fn control_fca0_clamp_to_profile_cap(
})
}
-fn project_control_owner_profile_fca0(
- native_class: Option<MissionControlClassProjection>,
- original_words: &[u32; 27],
- current_words: &[u32; 27],
- fac0_projection: &Result<
- MissionControlOwnerProfileLoadProjection,
- MissionControlOwnerProfileLoadProjectionUnavailableReason,
- >,
- devices: &[EffectiveControlDevice],
- provider_status: &MissionControlNodeProviderTableStatus,
-) -> Result<[u32; 27], MissionControlOwnerProfileFca0UnavailableReason> {
- use MissionControlOwnerProfileFca0UnavailableReason as Unavailable;
-
- if native_class.is_some_and(|class| class.class_id == 9) {
- return Ok(*current_words);
- }
- if native_class.is_none() {
- return Err(Unavailable::MissingNativeControlClass);
- }
- if let Err(reason) = fac0_projection {
- return Err(Unavailable::Fac0Unavailable(reason.clone()));
- }
-
- let mut e00_sum = 0.0_f32;
- for device_index in (0..devices.len()).rev() {
- if devices[device_index].descriptor.tag != 5 {
- continue;
- }
- if let Some(value) = query_control_device_selector(&devices[device_index], provider_status)
- .map_err(|error| Unavailable::QueryUnavailable(Arc::new(error)))?
- {
- e00_sum = control_fca0_sum(e00_sum, value, "FCA0 reverse E00 sum")?;
- }
- }
-
- // The canonical owner constructor initializes +0x1a8, +0x354, and +0x358
- // to 1.0; the traced event-4 loader does not overwrite these fields.
- let owner_scalar = 1.0_f32;
- let owner_mean = control_fca0_sum(1.0, 1.0, "FCA0 owner scalar mean")?;
- let owner_mean = control_fca0_product(owner_mean, 0.5, "FCA0 owner scalar mean")?;
- let weight = control_fca0_product(owner_mean, e00_sum, "FCA0 weighted E00 sum")?;
- let ratio = control_fca0_ratio(
- control_fca0_float(f32::from_bits(current_words[26]), "current profile word 26")?,
- control_fca0_float(
- f32::from_bits(original_words[26]),
- "original profile word 26",
- )?,
- "FCA0 profile word 26 ratio",
- )?;
- let factor_a = control_fca0_product(
- control_fca0_sum(ratio, 1.0, "FCA0 factor A")?,
- 0.5,
- "FCA0 factor A",
- )?;
- let factor_b = control_fca0_sum(
- control_fca0_product(ratio, 0.75, "FCA0 factor B")?,
- 0.25,
- "FCA0 factor B",
- )?;
-
- let mut current_words = *current_words;
- for index in 6..9 {
- let original = control_fca0_float(
- f32::from_bits(original_words[index]),
- "original profile words 6..8",
- )?;
- let owner_scaled =
- control_fca0_product(owner_scalar, original, "FCA0 first profile triple")?;
- let weighted = control_fca0_product(owner_scaled, weight, "FCA0 first profile triple")?;
- let factored = control_fca0_product(weighted, factor_a, "FCA0 first profile triple")?;
- current_words[index] =
- control_fca0_clamp_to_profile_cap(factored, original, "FCA0 first profile triple")?
- .to_bits();
- }
- for index in 9..12 {
- let original = control_fca0_float(
- f32::from_bits(original_words[index]),
- "original profile words 9..11",
- )?;
- let weighted = control_fca0_product(weight, original, "FCA0 second profile triple")?;
- let factored = control_fca0_product(weighted, factor_b, "FCA0 second profile triple")?;
- current_words[index] =
- control_fca0_sum(factored, factored, "FCA0 doubled second profile triple")?.to_bits();
- }
- for index in 0..3 {
- let original = control_fca0_float(
- f32::from_bits(original_words[index]),
- "original profile words 0..2",
- )?;
- current_words[index] =
- control_fca0_sum(original, original, "FCA0 doubled profile words")?.to_bits();
- }
- Ok(current_words)
-}
-
fn behavior_clan_for_selector(
selector: u32,
clan_count: usize,
@@ -7946,6 +7859,7 @@ fn build_control_device_projection_with_class(
native_component_id,
original_words,
current_words,
+ scalars: ControlProfileScalars::default(),
load_projection,
fca0_projection,
}
diff --git a/crates/fparkan-runtime/src/patrol_speed.rs b/crates/fparkan-runtime/src/patrol_speed.rs
index e9e4fc1c..4f8b88ca 100644
--- a/crates/fparkan-runtime/src/patrol_speed.rs
+++ b/crates/fparkan-runtime/src/patrol_speed.rs
@@ -37,7 +37,7 @@ pub(super) fn place_speed(
Ok((limit, speed)) => {
let sample = report.samples.entry(object).or_default();
if sample.0 == 0 {
- eprintln!("patrol_speed_profile_approx object={object} limit={} requested={speed} (runtime Control profile updates remain open)", f32::from_bits(limit));
+ eprintln!("patrol_speed_profile_approx object={object} limit={} requested={speed} (mobile Control budgets and owner activation remain open)", f32::from_bits(limit));
}
*sample = (sample.0 + 1, limit, speed.to_bits());
speed