aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-15 00:39:41 +0300
committerValentin Popov <valentin@popov.link>2026-11-15 00:39:41 +0300
commit660332c32fdde77f2d5560a773ecddbf466359ca (patch)
tree27e139bf8bc4f6e3c69a1aeac93672ea81182053 /crates
parent3c0ff06870dd1490c9ff3e6a5ed25247875f4fee (diff)
downloadfparkan-660332c32fdde77f2d5560a773ecddbf466359ca.tar.xz
fparkan-660332c32fdde77f2d5560a773ecddbf466359ca.zip
fix(ai): dispatch attacks after a scripted unit dies
Match Handler(39) against the live logical-object registry and pass Problems0 attack orders to the existing task. The stock mission 20 regression exercises the branch with the checked warbot present and then removed. The original GOG AI query was called directly for present and missing IDs. Mission 20 completed 900 simulated seconds without a clan-script stop and started in the window with clean Vulkan validation.
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-runtime/src/clan_ai_events.rs16
-rw-r--r--crates/fparkan-runtime/src/mission_events.rs91
2 files changed, 107 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs
index 0ecea127..6e844899 100644
--- a/crates/fparkan-runtime/src/clan_ai_events.rs
+++ b/crates/fparkan-runtime/src/clan_ai_events.rs
@@ -548,6 +548,16 @@ impl LoadedMissionState {
.declarations
.resolve_handler15_with_values(instruction, values)
.map_err(|error| error.to_string())?;
+ if let (3, 3, Handler15TargetPayload::ByLogicId(target)) =
+ (order.word_1, order.word_2, order.target)
+ {
+ let patrol = self.unit_patrol.get_or_insert_with(crate::unit_patrol::UnitPatrol::scripted);
+ let accepted = crate::script_patrol::apply_attack_order(
+ patrol, &self.mission, &self.object_drafts, world,
+ order.word_0, target,
+ ).is_some();
+ return Ok(Some(VarSetDefault::Dword(u32::from(accepted))));
+ }
if let (7, 3, Handler15TargetPayload::ByPlace { first, second }) =
(order.word_1, order.word_2, order.target)
{
@@ -968,6 +978,12 @@ impl LoadedMissionState {
}
Ok(Some(VarSetDefault::Dword(1)))
}
+ ScriptDispatchSelector::Handler(39) => {
+ let id = single_dword(&instruction.references, values)
+ .ok_or("Handler(39) requires one DWORD logical ID")?;
+ let exists = self.mission_events.has_live_logic_object(&self.mission, world, id);
+ Ok(Some(VarSetDefault::Dword(u32::from(exists))))
+ }
ScriptDispatchSelector::Handler(49)
if instruction.references.is_empty() =>
{
diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs
index 67aea865..a00e449c 100644
--- a/crates/fparkan-runtime/src/mission_events.rs
+++ b/crates/fparkan-runtime/src/mission_events.rs
@@ -227,6 +227,20 @@ impl MissionEvents {
))
}
+ pub(super) fn has_live_logic_object(
+ &self,
+ mission: &super::MissionDocument,
+ world: &World,
+ id: u32,
+ ) -> bool {
+ self.logic_objects(mission, world, id).any(|handle| {
+ registration_sequence(world, handle)
+ .ok()
+ .flatten()
+ .is_some()
+ })
+ }
+
pub(super) fn issue_logic_id(
&mut self,
mission: &super::MissionDocument,
@@ -854,6 +868,15 @@ impl LoadedMissionState {
);
Ok(Some(count))
}
+ ScriptDispatchSelector::Handler(39) => {
+ let id = single_dword(instruction, values)
+ .ok_or("Handler(39) requires one DWORD logical ID")?;
+ Ok(Some(u32::from(mission_events.has_live_logic_object(
+ &self.mission,
+ world,
+ id,
+ ))))
+ }
ScriptDispatchSelector::Handler(52) => {
let id = single_dword(instruction, values)
.ok_or("Handler(52) requires one DWORD operand")?;
@@ -1072,6 +1095,74 @@ mod tests {
};
#[test]
+ #[ignore = "requires licensed corpus"]
+ fn licensed_clan_checks_for_live_unit_in_problems0() {
+ use crate::{EngineServices, MissionMode, MissionRequest, MissionStartupInput};
+ use fparkan_vfs::DirectoryVfs;
+ use std::sync::Arc;
+
+ let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap();
+ let mut engine =
+ crate::create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap();
+ crate::load_gameplay_mission(
+ &mut engine,
+ MissionRequest {
+ key: "MISSIONS/CAMPAIGN/CAMPAIGN.05/Mission.01/data.tma".into(),
+ mode: MissionMode::SingleMission,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ None,
+ )
+ .unwrap();
+
+ let loaded = engine.loaded.as_ref().unwrap();
+ let unit = super::placed_logic_objects(&loaded.mission, &engine.world, 25)
+ .next()
+ .unwrap();
+ let attackers = [2, 3, 23, 27, 28, 30].map(|id| {
+ super::placed_logic_objects(&loaded.mission, &engine.world, id)
+ .next()
+ .unwrap()
+ });
+ let hero = super::placed_logic_objects(&loaded.mission, &engine.world, 12)
+ .next()
+ .unwrap();
+ assert!(loaded
+ .mission_events
+ .has_live_logic_object(&loaded.mission, &engine.world, 25));
+ crate::clan_ai_events::tick(&mut engine, 7_000);
+ let patrol = engine
+ .loaded
+ .as_ref()
+ .unwrap()
+ .unit_patrol
+ .as_ref()
+ .unwrap();
+ assert_eq!(patrol.attack_target(attackers[0]), None);
+ request_delete(&mut engine.world, unit).unwrap();
+ crate::clan_ai_events::tick(&mut engine, 14_000);
+ let loaded = engine.loaded.as_ref().unwrap();
+ assert!(!loaded
+ .mission_events
+ .has_live_logic_object(&loaded.mission, &engine.world, 25));
+ assert!(!loaded.mission_events.has_live_logic_object(
+ &loaded.mission,
+ &engine.world,
+ u32::MAX
+ ));
+ assert!(loaded.clan_ai_events.stops().next().is_none());
+ let patrol = loaded.unit_patrol.as_ref().unwrap();
+ assert!(attackers.into_iter().all(|handle| {
+ patrol
+ .attack_target(handle)
+ .is_some_and(|(target, _)| target == hero)
+ }));
+ }
+
+ #[test]
fn exit_cylinder_includes_the_wall_and_caps() {
let center = [10., 20., 30.];
for (point, inside) in [