aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/clan_targeting.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 18:34:08 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 18:34:08 +0300
commit2d01cd35b069d0d1aa78a064593b54f51b23540d (patch)
tree07fe0aa111c41cadc6b14548881731886dc8f0d1 /crates/fparkan-runtime/src/clan_targeting.rs
parent72ae7666d428c783a03b5378658890947f205de0 (diff)
downloadfparkan-2d01cd35b069d0d1aa78a064593b54f51b23540d.tar.xz
fparkan-2d01cd35b069d0d1aa78a064593b54f51b23540d.zip
fix(ai): resume building capture after losing its assignee
Diffstat (limited to 'crates/fparkan-runtime/src/clan_targeting.rs')
-rw-r--r--crates/fparkan-runtime/src/clan_targeting.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/crates/fparkan-runtime/src/clan_targeting.rs b/crates/fparkan-runtime/src/clan_targeting.rs
index 4e710bca..78967333 100644
--- a/crates/fparkan-runtime/src/clan_targeting.rs
+++ b/crates/fparkan-runtime/src/clan_targeting.rs
@@ -39,7 +39,7 @@ pub(super) fn send_capturer(
let index = target.original_id?.0 as usize;
let class = drafts.get(index)?.unit_dat_header_flags?;
if unit.target_id != target_id
- || target_id & 0x8000_0000 == 0
+ || class & 0x8000_0000 == 0
|| target.owner_id == identity_metadata(world, unit.handle).ok()?.owner_id
|| class == 0x8000_0200
{
@@ -67,7 +67,7 @@ pub(super) fn send_capturer(
let indoor_route = passage.is_some();
patrol
.get_or_insert_with(crate::unit_patrol::UnitPatrol::scripted)
- .move_to_capture(world, unit.handle, destination, passage);
+ .move_to_capture(world, unit.handle, unit.target, destination, passage);
if !indoor_route {
eprintln!(
"sim_coverage script_capture_approach_stub=1 unit={} target={} target_id={target_id} destination={destination:?}",
@@ -97,6 +97,16 @@ fn distance_squared(from: [f32; 3], to: [f32; 3]) -> f32 {
}
impl CaptureApproach {
+ pub(super) fn is_active(
+ self,
+ world: &World,
+ patrol: Option<&crate::unit_patrol::UnitPatrol>,
+ owner: OwnerId,
+ ) -> bool {
+ identity_metadata(world, self.unit).is_ok_and(|identity| identity.owner_id == Some(owner))
+ && patrol.is_some_and(|patrol| patrol.has_capture_order(self.unit, self.target))
+ }
+
pub(super) fn reached(self, world: &World) -> bool {
transform_state(world, self.unit)
.is_ok_and(|pose| at_platform(pose.position.map(f32::from_bits), self.point))
@@ -116,7 +126,7 @@ pub(super) fn nearest_capturer<'a>(
target_id: u32,
available_control: impl Fn(ObjectHandle) -> Option<&'a MissionControlDeviceTableState>,
) -> Option<Capturer> {
- let target = crate::mission_events::placed_logic_objects(mission, world, target_id).next()?;
+ let target = roster.logic_objects(mission, world, target_id).next()?;
let point = transform_state(world, target)
.ok()?
.position
@@ -137,11 +147,7 @@ pub(super) fn nearest_capturer<'a>(
.map(f32::from_bits);
let score =
capture_arrival_score(position, point, f32::from_bits(profile.current_words[7]))?;
- // shortcut: generated ID is local to this script section until native robot IDs are allocated.
- let id = mission
- .objects
- .get(index)
- .map_or(original_id, |object| object.identity_or_clan_raw);
+ let id = roster.logic_id(mission, world, handle)?;
(id != u32::MAX).then_some((
Capturer {
handle,