aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime')
-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 [