From 3e8eaf4abfdd9f8110805ebc988c17dd393e7aa2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 18 Aug 2026 01:57:00 +0200 Subject: [PATCH] Unify migration state references --- crates/ghostlight-dungeon/src/resolution.rs | 40 ++++++++++++++++ crates/ghostlight-dungeon/src/scheduler.rs | 48 ++++--------------- .../ghostlight-multiresolution-agency.md | 8 ++++ notes/fresh-workspace-handoff.md | 7 +++ notes/ghostlight-current-system-map.md | 6 +++ 5 files changed, 71 insertions(+), 38 deletions(-) diff --git a/crates/ghostlight-dungeon/src/resolution.rs b/crates/ghostlight-dungeon/src/resolution.rs index ed12e30..d601c3d 100644 --- a/crates/ghostlight-dungeon/src/resolution.rs +++ b/crates/ghostlight-dungeon/src/resolution.rs @@ -2162,6 +2162,40 @@ pub fn validate_member_migration( Ok(()) } +pub fn gestalt_migration_destinations( + campaign: &Campaign, + source_gestalt_id: &str, + origin_location_id: &str, +) -> BTreeMap { + campaign + .agency_relations + .values() + .filter(|relation| { + relation.active + && relation.kind == AgencyRelationKind::Migration + && relation.from_subject_id == source_gestalt_id + }) + .filter_map(|relation| { + let destination = campaign.gestalts.get(&relation.to_subject_id)?; + let profile = campaign.agency_profiles.get(&destination.id)?; + if !profile.active_leaf || !profile.simulation_eligible { + return None; + } + let reachable = origin_location_id == destination.home_location_id + || campaign + .locations + .get(origin_location_id) + .is_some_and(|location| { + location.routes.values().any(|route| { + route.destination_id == destination.home_location_id + && route.travel_minutes <= campaign.tick_hours.saturating_mul(60) + }) + }); + reachable.then(|| (destination.id.clone(), destination.home_location_id.clone())) + }) + .collect() +} + pub fn member_state_references(campaign: &Campaign, member_id: &str) -> Result> { let member = campaign .gestalt_members @@ -2342,6 +2376,12 @@ pub fn subject_state_references(campaign: &Campaign, subject_id: &str) -> Result .map(|value| format!("resource:{value}")), ), ); + for (destination_id, location_id) in + gestalt_migration_destinations(campaign, subject_id, &gestalt.home_location_id) + { + references.insert(format!("gestalt:{destination_id}")); + references.insert(format!("location:{location_id}")); + } } Ok(references) } diff --git a/crates/ghostlight-dungeon/src/scheduler.rs b/crates/ghostlight-dungeon/src/scheduler.rs index 496dec5..2e459d7 100644 --- a/crates/ghostlight-dungeon/src/scheduler.rs +++ b/crates/ghostlight-dungeon/src/scheduler.rs @@ -522,8 +522,11 @@ fn member_exceptions(campaign: &Campaign, cell: &SimulationCell) -> Result Result BTreeMap { - campaign - .agency_relations - .values() - .filter(|relation| { - relation.active - && relation.kind == crate::domain::AgencyRelationKind::Migration - && relation.from_subject_id == source_gestalt_id - }) - .filter_map(|relation| { - let destination = campaign.gestalts.get(&relation.to_subject_id)?; - let profile = campaign.agency_profiles.get(&destination.id)?; - if !profile.active_leaf || !profile.simulation_eligible { - return None; - } - let reachable = origin_location_id == destination.home_location_id - || campaign - .locations - .get(origin_location_id) - .is_some_and(|location| { - location.routes.values().any(|route| { - route.destination_id == destination.home_location_id - && route.travel_minutes <= campaign.tick_hours.saturating_mul(60) - }) - }); - reachable.then(|| (destination.id.clone(), destination.home_location_id.clone())) - }) - .collect() -} - fn overlay( baseline: &BTreeSet, additions: &BTreeSet, @@ -736,8 +705,11 @@ fn constituent_slice(campaign: &Campaign, id: &str) -> Result