aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/clan_problem_conditions.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 08:06:11 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 08:06:11 +0300
commit594e910853c98b1b35809799657b058d7b7dc2a0 (patch)
tree79fb97d2f231113c7d34031293966675c8c6ce87 /crates/fparkan-runtime/src/clan_problem_conditions.rs
parent79635316902c69a363f1d1a9ebef110d94190356 (diff)
downloadfparkan-594e910853c98b1b35809799657b058d7b7dc2a0.tar.xz
fparkan-594e910853c98b1b35809799657b058d7b7dc2a0.zip
fix(ai): wait for mine recapture in clan requests
Follow the current world object for logical-ID wait conditions. Check the stock Two Fortresses recapture event against the original AI condition oracle and a licensed regression.
Diffstat (limited to 'crates/fparkan-runtime/src/clan_problem_conditions.rs')
-rw-r--r--crates/fparkan-runtime/src/clan_problem_conditions.rs32
1 files changed, 22 insertions, 10 deletions
diff --git a/crates/fparkan-runtime/src/clan_problem_conditions.rs b/crates/fparkan-runtime/src/clan_problem_conditions.rs
index e0d11336..a7c2c298 100644
--- a/crates/fparkan-runtime/src/clan_problem_conditions.rs
+++ b/crates/fparkan-runtime/src/clan_problem_conditions.rs
@@ -4,8 +4,8 @@ use fparkan_world::{identity_metadata, registration_sequence, ObjectHandle, Owne
#[derive(Clone, Copy, PartialEq, Eq)]
pub(super) enum Condition {
- ObjectDestroyed(Option<ObjectHandle>),
- BuildingCaptured(ObjectHandle),
+ ObjectDestroyed(u32),
+ BuildingCaptured(u32),
GroupDestroyed,
GroupIdle,
TaskInactive(ObjectHandle),
@@ -18,17 +18,18 @@ impl Condition {
clan: OwnerId,
patrol: Option<&UnitPatrol>,
group: Option<&CombatGroup>,
+ lookup: impl Fn(u32) -> Option<ObjectHandle>,
task_active: impl Fn(ObjectHandle) -> bool,
) -> bool {
let live =
|unit| registration_sequence(world, unit).is_ok_and(|sequence| sequence.is_some());
match self {
- Self::ObjectDestroyed(target) => target.is_none_or(|target| !live(target)),
- Self::BuildingCaptured(target) => {
+ Self::ObjectDestroyed(id) => lookup(id).is_none_or(|target| !live(target)),
+ Self::BuildingCaptured(id) => lookup(id).is_some_and(|target| {
live(target)
&& identity_metadata(world, target)
.is_ok_and(|identity| identity.owner_id == Some(clan))
- }
+ }),
Self::GroupDestroyed => {
group.is_none_or(|group| group.members.iter().all(|&unit| !live(unit)))
}
@@ -55,14 +56,25 @@ mod tests {
let target = construct_object(&mut world, ObjectDraft { original_id: None }).unwrap();
register_object(&mut world, target).unwrap();
let clan = OwnerId(1);
+ let id = 0x8000_0009;
+ let lookup = |candidate| (candidate == id).then_some(target);
+ let captured = Condition::BuildingCaptured(id);
+ let destroyed = Condition::ObjectDestroyed(id);
set_owner(&mut world, target, Some(OwnerId(0))).unwrap();
- assert!(!Condition::BuildingCaptured(target).met(&world, clan, None, None, |_| false));
- assert!(!Condition::ObjectDestroyed(Some(target)).met(&world, clan, None, None, |_| false));
+ assert!(!captured.met(&world, clan, None, None, lookup, |_| false));
+ assert!(!destroyed.met(&world, clan, None, None, lookup, |_| false));
set_owner(&mut world, target, Some(clan)).unwrap();
- assert!(Condition::BuildingCaptured(target).met(&world, clan, None, None, |_| false));
+ assert!(captured.met(&world, clan, None, None, lookup, |_| false));
fparkan_world::request_delete(&mut world, target).unwrap();
fparkan_world::step(&mut world, &fparkan_world::InputSnapshot).unwrap();
- assert!(Condition::ObjectDestroyed(Some(target)).met(&world, clan, None, None, |_| false));
- assert!(!Condition::BuildingCaptured(target).met(&world, clan, None, None, |_| false));
+ assert!(destroyed.met(&world, clan, None, None, |_| None, |_| false));
+ assert!(!captured.met(&world, clan, None, None, |_| None, |_| false));
+
+ let replacement = construct_object(&mut world, ObjectDraft { original_id: None }).unwrap();
+ register_object(&mut world, replacement).unwrap();
+ let lookup = |candidate| (candidate == id).then_some(replacement);
+ assert!(!destroyed.met(&world, clan, None, None, lookup, |_| false));
+ set_owner(&mut world, replacement, Some(clan)).unwrap();
+ assert!(captured.met(&world, clan, None, None, lookup, |_| false));
}
}