aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-14 09:19:30 +0300
committerValentin Popov <valentin@popov.link>2026-11-14 09:19:30 +0300
commit6b48c7130acbaa8eb72335e6736913b7838e19b3 (patch)
tree6fcf5013b55c16a52658647fe5bae2b407c56faf /crates/fparkan-runtime/src
parentd4c2ee22771b20208ee07ec38d868c3b0ce963bf (diff)
downloadfparkan-6b48c7130acbaa8eb72335e6736913b7838e19b3.tar.xz
fparkan-6b48c7130acbaa8eb72335e6736913b7838e19b3.zip
feat(runtime): expose live clan ownership to mission scripts
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/lib.rs57
-rw-r--r--crates/fparkan-runtime/src/mission_events.rs42
2 files changed, 88 insertions, 11 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 845afa57..8f396629 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -17630,6 +17630,63 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
+ fn licensed_constructor_checks_current_factory_and_hangar_owners() {
+ use fparkan_world::{identity_metadata, set_owner, OwnerId};
+
+ let vfs: Arc<dyn Vfs> = Arc::new(DirectoryVfs::new(licensed_root("IS")));
+ let mut engine = create(EngineServices::new(vfs)).unwrap();
+ load_mission_with_init_stubs(
+ &mut engine,
+ MissionRequest {
+ key: "MISSIONS/CAMPAIGN/CAMPAIGN.00/Mission.02/data.tma".into(),
+ mode: MissionMode::SingleMission,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ )
+ .unwrap();
+ let initial = frame(&mut engine, 1).unwrap().mission_event.unwrap();
+ assert!(initial.stop.is_none(), "{:?}", initial.stop);
+ assert!(!initial
+ .notices
+ .iter()
+ .any(|notice| matches!(notice, MissionNotice::ObjectiveComplete(0 | 2))));
+ for (time, logic_id, objective_index) in [(2001, 0x8000_0001, 0), (4001, 0x8000_0003, 2)] {
+ let slot = engine
+ .loaded
+ .as_ref()
+ .unwrap()
+ .mission
+ .objects
+ .iter()
+ .position(|object| object.identity_or_clan_raw == logic_id)
+ .unwrap();
+ let handle = mission_object_handle(&engine, OriginalObjectId(slot as u32)).unwrap();
+ assert_eq!(
+ identity_metadata(&engine.world, handle).unwrap().owner_id,
+ Some(OwnerId(2))
+ );
+ set_owner(&mut engine.world, handle, Some(OwnerId(0))).unwrap();
+ let event = frame(&mut engine, time).unwrap().mission_event.unwrap();
+ assert!(event.stop.is_none(), "{:?}", event.stop);
+ assert!(
+ event
+ .notices
+ .contains(&MissionNotice::ObjectiveComplete(objective_index)),
+ "{:?}",
+ event.notices
+ );
+ }
+ assert_eq!(
+ loaded_mission_script_outcome(&engine),
+ Some(MissionScriptOutcome::Active)
+ );
+ }
+
+ #[test]
+ #[ignore = "requires licensed corpus"]
fn licensed_firing_range_reports_target_loss_and_completes_all_objectives() {
let vfs: Arc<dyn Vfs> = Arc::new(DirectoryVfs::new(licensed_root("IS")));
let mut engine = create(EngineServices::new(vfs)).unwrap();
diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs
index 098cf47d..35d9e7b7 100644
--- a/crates/fparkan-runtime/src/mission_events.rs
+++ b/crates/fparkan-runtime/src/mission_events.rs
@@ -310,6 +310,17 @@ impl LoadedMissionState {
let inside = tactical_area_contains(&self.mission, world, area, id);
Ok(Some(u32::from(inside)))
}
+ ScriptDispatchSelector::Handler(52) => {
+ let [id] = *instruction.references.as_slice() else {
+ return Err("Handler(52) requires one DWORD operand".into());
+ };
+ let Some(&VarSetDefault::Dword(id)) = values.get(id as usize) else {
+ return Err("Handler(52) requires one DWORD operand".into());
+ };
+ let clan = placed_logic_objects(&self.mission, world, id)
+ .find_map(|handle| identity_metadata(world, handle).ok()?.owner_id);
+ Ok(Some(clan.map_or(u32::MAX, |owner| u32::from(owner.0))))
+ }
ScriptDispatchSelector::Handler(30) => {
let command = declarations
.resolve_handler30_with_values(instruction, values)
@@ -408,25 +419,34 @@ fn tactical_area_contains(
) -> bool {
// MisLoad allocates a slot per path and selects the first record matching
// the slot ID. Out-of-range IDs and unfilled slots yield an empty list.
- if area as usize >= mission.paths.len() || id == u32::MAX {
+ if area as usize >= mission.paths.len() {
return false;
}
let Some(path) = mission.paths.iter().find(|path| path.id as u32 == area) else {
return false;
};
- // shortcut: resolve placed objects through their TMA logic ID until the
- // world assigns native logic IDs to units created during gameplay.
- mission.objects.iter().enumerate().any(|(index, object)| {
- object.identity_or_clan_raw == id
- && handle_by_original_id(world, OriginalObjectId(index as u32))
- .and_then(|handle| transform_state(world, handle).ok())
- .is_some_and(|pose| {
- let [x, y, _] = pose.position.map(f32::from_bits);
- in_tactical_polygon(&path.points, x, y)
- })
+ placed_logic_objects(mission, world, id).any(|handle| {
+ transform_state(world, handle).is_ok_and(|pose| {
+ let [x, y, _] = pose.position.map(f32::from_bits);
+ in_tactical_polygon(&path.points, x, y)
+ })
})
}
+fn placed_logic_objects<'a>(
+ mission: &'a super::MissionDocument,
+ world: &'a World,
+ id: u32,
+) -> impl Iterator<Item = ObjectHandle> + 'a {
+ // shortcut: only TMA IDs, until the world assigns native IDs at runtime.
+ mission
+ .objects
+ .iter()
+ .enumerate()
+ .filter(move |(_, object)| id != u32::MAX && object.identity_or_clan_raw == id)
+ .filter_map(|(index, _)| handle_by_original_id(world, OriginalObjectId(index as u32)))
+}
+
fn in_tactical_polygon(vertices: &[[f32; 3]], x: f32, y: f32) -> bool {
let Some(&[mut previous_x, mut previous_y, _]) = vertices.last() else {
return false;