aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/control_resources.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 07:33:51 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 07:33:51 +0300
commit777f48345c7faf891ac105fc4a831114914aff5d (patch)
treea9e550c582aa976d87e6c0ae4297e7c29e6e5526 /crates/fparkan-runtime/src/control_resources.rs
parent352026c1ce039443efc779876b27654d992bfff1 (diff)
downloadfparkan-777f48345c7faf891ac105fc4a831114914aff5d.tar.xz
fparkan-777f48345c7faf891ac105fc4a831114914aff5d.zip
fix(combat): charge the drive before refilling weapons
Read the resource multiplier from CTL when all authored states agree and price the latest local motion in the existing Control budget. A licensed AutoDemo flyer charges its weapons more slowly when the drive is drawing from the same supply. Control.dll oracle vectors, the AutoDemo window, and all 29 mission startup sweeps pass.
Diffstat (limited to 'crates/fparkan-runtime/src/control_resources.rs')
-rw-r--r--crates/fparkan-runtime/src/control_resources.rs35
1 files changed, 26 insertions, 9 deletions
diff --git a/crates/fparkan-runtime/src/control_resources.rs b/crates/fparkan-runtime/src/control_resources.rs
index e34a3dfc..0b1f853b 100644
--- a/crates/fparkan-runtime/src/control_resources.rs
+++ b/crates/fparkan-runtime/src/control_resources.rs
@@ -1,11 +1,11 @@
use crate::{
- control_profile, control_resource_budget_pass, repair_zone, ControlProfileReport, Engine,
- MissionControlDeviceTableStatus, MobileBudgetReport,
+ control_profile, control_resource_budget_pass_with_motion, mobile_budget::DriveMotion,
+ repair_zone, ControlProfileReport, Engine, MissionControlDeviceTableStatus, MobileBudgetReport,
};
-use fparkan_world::{transform_state, ObjectHandle};
+use fparkan_world::{transform_state, ObjectHandle, TransformState};
use std::collections::BTreeMap;
-/// Supported Control budgets; motion callbacks and global RNG ordering remain open.
+/// Supported Control budgets and per-owner resource clocks.
pub(super) struct Resources {
clocks: Vec<(ObjectHandle, ResourceClock)>,
rng: u32,
@@ -109,6 +109,8 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) {
.expect("new Control resource clock")
.1
};
+ let frame_seconds = (now_ms as f32 - clock.frame_ms) * 0.001;
+ let previous_pose = clock.previous_pose.replace(pose);
// Control.dll+0x42480: default resource period; this is a separate RNG from Behavior.
let Some(seconds) = clock.step(now_ms as f32, true, 250.0, &mut state.rng) else {
continue;
@@ -160,7 +162,20 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) {
}
}
}
- match control_resource_budget_pass(table, seconds) {
+ let motion = previous_pose.filter(|_| mobile_owner).and_then(|previous| {
+ let can_fly = table
+ .original_id
+ .and_then(|id| mission.unit_chassis_flags.get(&id.0))
+ .and_then(|flags| flags.can_fly)?;
+ DriveMotion::sample(
+ table,
+ &mission.mission_assets,
+ [previous, pose],
+ frame_seconds,
+ can_fly,
+ )
+ });
+ match control_resource_budget_pass_with_motion(table, seconds, motion) {
Ok(()) => {
state
.blocked_budgets
@@ -169,10 +184,11 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) {
*state.mobile.ticks.entry(object).or_default() += 1;
if let MissionControlDeviceTableStatus::Available(devices) = &table.status {
for device in devices {
- if device.factory_tag == 5 && device.native_word_50_bits != Some(0) {
- state
- .mobile
- .stub(object, format!("motion_factory_{}", device.factory_tag));
+ if motion.is_none()
+ && device.factory_tag == 5
+ && device.native_word_50_bits != Some(0)
+ {
+ state.mobile.stub(object, "motion_factory_5".into());
}
if matches!(device.factory_tag, 2 | 30)
&& f32::from_bits(device.descriptor.fixed_words[8]) != 0.0
@@ -220,6 +236,7 @@ pub(super) fn tick(engine: &mut Engine, now_ms: u32) {
#[derive(Default)]
struct ResourceClock {
frame_ms: f32,
+ previous_pose: Option<TransformState>,
resource_ms: f32,
forced: u32,
alarm: control_profile::DamageAlarm,