aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-14 11:18:33 +0300
committerValentin Popov <valentin@popov.link>2026-11-14 11:18:33 +0300
commitcca770a278954a0b029f2c173202ed1abe25b171 (patch)
treef365c7a3f67d08c29d1834c7fab9bf7d7b089be0 /crates/fparkan-runtime/src
parent9ecec64d5071a03ad7a5478579da4a59788ba755 (diff)
downloadfparkan-cca770a278954a0b029f2c173202ed1abe25b171.tar.xz
fparkan-cca770a278954a0b029f2c173202ed1abe25b171.zip
fix(runtime): recognize the generator capture platform
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/lib.rs42
-rw-r--r--crates/fparkan-runtime/src/mission_events.rs29
-rw-r--r--crates/fparkan-runtime/src/production.rs1
3 files changed, 67 insertions, 5 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 316336c6..6ec8c5c7 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -17812,6 +17812,35 @@ mod tests {
.notices
.iter()
.any(|notice| matches!(notice, MissionNotice::ObjectiveComplete(2 | 3))));
+ let cockpit = starting_cockpit(&engine).unwrap();
+ let generator = loaded_mission_object_drafts(&engine)
+ .unwrap()
+ .iter()
+ .find(|draft| draft.unit_dat_header_flags == Some(0x8000_0002))
+ .unwrap();
+ let id = generator.original_id.unwrap();
+ let handle = mission_object_handle(&engine, id).unwrap();
+ let mut hero = transform_state(&engine.world, cockpit.handle).unwrap();
+ let start = hero;
+ for z in [96.0_f32, 75.0] {
+ hero.position = [659.4, 1050.6, z].map(f32::to_bits);
+ set_transform(&mut engine.world, cockpit.handle, hero).unwrap();
+ assert_eq!(
+ capture_neutral_building(&mut engine, cockpit).unwrap(),
+ None
+ );
+ }
+ hero.position = [659.4_f32, 1050.6, 80.04].map(f32::to_bits);
+ set_transform(&mut engine.world, cockpit.handle, hero).unwrap();
+ assert_eq!(
+ capture_neutral_building(&mut engine, cockpit).unwrap(),
+ Some(id)
+ );
+ assert!(loaded_mission_behavior_distributors(&engine).unwrap()[0]
+ .registered_objects
+ .iter()
+ .any(|entry| entry.handle == handle));
+ set_transform(&mut engine.world, cockpit.handle, start).unwrap();
// The tutorial starts before a mine has been deployed.
let mine = construct_object(&mut engine.world, ObjectDraft { original_id: None }).unwrap();
fparkan_world::set_owner(&mut engine.world, mine, Some(fparkan_world::OwnerId(0))).unwrap();
@@ -17825,6 +17854,19 @@ mod tests {
let after = frame(&mut engine, 2001).unwrap().mission_event.unwrap();
assert!(after.stop.is_none(), "{:?}", after.stop);
assert!(
+ after.notices.contains(&MissionNotice::ObjectiveComplete(0)),
+ "{after:?}"
+ );
+ let power = loaded_mission_script_bundles(&engine)
+ .unwrap()
+ .iter()
+ .find(|bundle| bundle.clan_index == 0)
+ .unwrap()
+ .behavior_warm_start
+ .unwrap()
+ .cleared_words[0];
+ assert!(f32::from_bits(power) > 0.0);
+ assert!(
after.notices.contains(&MissionNotice::ObjectiveComplete(2)),
"{after:?}"
);
diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs
index f98c29e7..6f434390 100644
--- a/crates/fparkan-runtime/src/mission_events.rs
+++ b/crates/fparkan-runtime/src/mission_events.rs
@@ -308,9 +308,15 @@ pub fn capture_neutral_building(
let clan = mission.mission.clans.get(usize::from(owner.0))?;
(clan.mode == 3).then_some((handle, identity.original_id?, owner, class))
})
- .find(|&(handle, id, _, _)| {
+ .find(|&(handle, id, _, class)| {
transform_state(&engine.world, handle).is_ok_and(|pose| {
- on_communicator(&mission.mission_assets, id.0 as usize, pose, position)
+ on_communicator(
+ &mission.mission_assets,
+ id.0 as usize,
+ class,
+ pose,
+ position,
+ )
})
});
if let Some((handle, id, former_owner, class)) = candidate {
@@ -352,9 +358,16 @@ pub fn capture_neutral_building(
pub(super) fn on_communicator(
assets: &super::MissionAssets,
object_index: usize,
+ class: u32,
pose: super::TransformState,
[x, y, z]: [f32; 3],
) -> bool {
+ let is_generator = class == 0x8000_0002;
+ let material = if is_generator {
+ &b"B_MTP_07G"[..]
+ } else {
+ &b"B_COMP_4G"[..]
+ };
let Some(visual) = assets
.visual_for_object(object_index)
.and_then(|id| assets.visual_by_id(id))
@@ -386,8 +399,7 @@ pub(super) fn on_communicator(
orientation_radians: pose.orientation.map(f32::from_bits),
};
let scale = pose.scale.map(f32::from_bits);
- // shortcut: use the green platform mesh with clearance for the player's
- // feet until the original communicator volume is measured.
+ // shortcut: use the green platform mesh until the native volume is known.
let platform_height = hierarchy
.poses
.iter()
@@ -401,7 +413,7 @@ pub(super) fn on_communicator(
wear.table
.entries
.get(usize::from(batch.material_index))
- .is_some_and(|entry| entry.material.0.eq_ignore_ascii_case(b"B_COMP_4G"))
+ .is_some_and(|entry| entry.material.0.eq_ignore_ascii_case(material))
})
.flat_map(|(pose, batch)| {
let first = batch.index_start as usize;
@@ -415,6 +427,13 @@ pub(super) fn on_communicator(
transform.try_transform_scaled_point(pose.transform_point(local), scale)
});
let (a, b, c) = (a?, b?, c?);
+ if is_generator {
+ // The generator also uses this material on the underside.
+ let winding = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
+ if winding <= 0.0 {
+ return None;
+ }
+ }
in_tactical_polygon(&[a, b, c], x, y).then_some(a[2].max(b[2]).max(c[2]))
})
})
diff --git a/crates/fparkan-runtime/src/production.rs b/crates/fparkan-runtime/src/production.rs
index 1e09250c..1fb6dd44 100644
--- a/crates/fparkan-runtime/src/production.rs
+++ b/crates/fparkan-runtime/src/production.rs
@@ -178,6 +178,7 @@ pub fn order_factory_robot(
&& on_communicator(
&mission.mission_assets,
*index,
+ PLANT_CLASS,
transform_state(&engine.world, plant).ok()?,
position,
))