aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/clan_problem_conditions.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-14 22:11:20 +0300
committerValentin Popov <valentin@popov.link>2026-11-14 22:11:20 +0300
commit16450724fa9d3052d315442a07b71e8d445c6cc3 (patch)
treebd0c982ce51976e810addcc627ea299b4d9e5318 /crates/fparkan-runtime/src/clan_problem_conditions.rs
parente1f26ba007532eca4b6afe4d49aca58799c1ce05 (diff)
downloadfparkan-16450724fa9d3052d315442a07b71e8d445c6cc3.tar.xz
fparkan-16450724fa9d3052d315442a07b71e8d445c6cc3.zip
feat(ai): wait on scripted capture and group conditions
Single.01 now reaches ST_SOLVING after dispatching a capturer and patrol. Compare the capture and destruction predicates with the original ai.dll at RVA 0x5180. Keep the default OR_TASK behavior and report the approximate lifecycle.
Diffstat (limited to 'crates/fparkan-runtime/src/clan_problem_conditions.rs')
-rw-r--r--crates/fparkan-runtime/src/clan_problem_conditions.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/clan_problem_conditions.rs b/crates/fparkan-runtime/src/clan_problem_conditions.rs
new file mode 100644
index 00000000..bace9ec6
--- /dev/null
+++ b/crates/fparkan-runtime/src/clan_problem_conditions.rs
@@ -0,0 +1,65 @@
+use crate::clan_combat_groups::CombatGroup;
+use crate::unit_patrol::UnitPatrol;
+use fparkan_world::{identity_metadata, registration_sequence, ObjectHandle, OwnerId, World};
+
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub(super) enum Condition {
+ ObjectDestroyed(Option<ObjectHandle>),
+ BuildingCaptured(ObjectHandle),
+ GroupDestroyed,
+ GroupIdle,
+}
+
+impl Condition {
+ pub(super) fn met(
+ self,
+ world: &World,
+ clan: OwnerId,
+ patrol: Option<&UnitPatrol>,
+ group: Option<&CombatGroup>,
+ ) -> 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) => {
+ 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)))
+ }
+ Self::GroupIdle => group.is_none_or(|group| {
+ group.members.iter().all(|&unit| {
+ !live(unit) || patrol.is_none_or(|patrol| !patrol.is_patrolling(unit))
+ })
+ }),
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use fparkan_world::{
+ construct_object, new, register_object, set_owner, ObjectDraft, WorldConfig,
+ };
+
+ #[test]
+ fn capture_waits_for_the_requested_clan_and_destruction_waits_for_removal() {
+ let mut world = new(WorldConfig);
+ let target = construct_object(&mut world, ObjectDraft { original_id: None }).unwrap();
+ register_object(&mut world, target).unwrap();
+ let clan = OwnerId(1);
+ set_owner(&mut world, target, Some(OwnerId(0))).unwrap();
+ assert!(!Condition::BuildingCaptured(target).met(&world, clan, None, None));
+ assert!(!Condition::ObjectDestroyed(Some(target)).met(&world, clan, None, None));
+ set_owner(&mut world, target, Some(clan)).unwrap();
+ assert!(Condition::BuildingCaptured(target).met(&world, clan, None, None));
+ 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));
+ assert!(!Condition::BuildingCaptured(target).met(&world, clan, None, None));
+ }
+}