aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_combat.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 09:41:04 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 09:41:04 +0300
commite4b903c58c6a03e726cad6db0ecba9d319470911 (patch)
tree436a587d402f535418986772ad4390dc7ca432cb /crates/fparkan-runtime/src/unit_combat.rs
parenta1e8e2fd3be9a4c761fed1e8a40c322e2d7d42d2 (diff)
downloadfparkan-e4b903c58c6a03e726cad6db0ecba9d319470911.tar.xz
fparkan-e4b903c58c6a03e726cad6db0ecba9d319470911.zip
feat(combat): spend directional shield charge before hull damage
Resolve the nearest sector in the target basis and apply the Control 9/21 capacity before the hull modifiers. Verify power queries and depletion with the original Control DLL, then check live AutoDemo and Two Fortresses encounters from stock starts.
Diffstat (limited to 'crates/fparkan-runtime/src/unit_combat.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_combat.rs35
1 files changed, 31 insertions, 4 deletions
diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs
index 593570cf..0491c078 100644
--- a/crates/fparkan-runtime/src/unit_combat.rs
+++ b/crates/fparkan-runtime/src/unit_combat.rs
@@ -744,6 +744,23 @@ mod tests {
let mut pose = transform_state(&engine.world, hero).unwrap();
pose.position = [x + 24.0, y, z + 6.0].map(f32::to_bits);
set_transform(&mut engine.world, hero, pose).unwrap();
+ let shield_charge = |engine: &Engine| {
+ let table = engine
+ .loaded
+ .as_ref()?
+ .control_device_tables
+ .iter()
+ .find(|table| table.handle == hero)?;
+ let crate::MissionControlDeviceTableStatus::Available(devices) = &table.status else {
+ return None;
+ };
+ let charge = devices
+ .iter()
+ .rfind(|device| device.factory_tag == 9)?
+ .class9_values_bits?;
+ Some(charge.map(f32::from_bits))
+ };
+ let before_shield = shield_charge(&engine);
let mut fired = false;
for now in (50..=1_500).step_by(50) {
let result = frame(&mut engine, now).unwrap();
@@ -762,13 +779,23 @@ mod tests {
&& engine.autodemo_combat.as_ref().unwrap().projectiles[projectile].name
== "ba_a_03"
});
- if fired
- && player_status(&engine, hero).and_then(|status| status.health_percent) == Some(30)
- {
+ let shield_was_hit =
+ shield_charge(&engine)
+ .zip(before_shield)
+ .is_some_and(|(after, before)| {
+ after
+ .into_iter()
+ .zip(before)
+ .any(|(after, before)| after < before)
+ });
+ let hull_was_hit = player_status(&engine, hero)
+ .and_then(|status| status.health_percent)
+ .is_some_and(|percent| percent < 100);
+ if fired && (shield_was_hit || hull_was_hit) {
return;
}
}
- panic!("the stock animal must fire its projectile and damage the hero (fired={fired})");
+ panic!("the stock animal must hit the nearby hero (fired={fired})");
}
#[test]