diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-03 10:34:53 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-03 10:34:53 +0300 |
| commit | f4286bc592d629288f5fa7a58277a84474af6154 (patch) | |
| tree | 333af29a34abeac865d79d0b347dfe393ac01249 /crates/fparkan-runtime/src/lib.rs | |
| parent | bd3e9f385eae92ae92a153bff6385f92d3ea76b7 (diff) | |
| download | fparkan-f4286bc592d629288f5fa7a58277a84474af6154.tar.xz fparkan-f4286bc592d629288f5fa7a58277a84474af6154.zip | |
fix(runtime): select the local starting hero for mission control
Diffstat (limited to 'crates/fparkan-runtime/src/lib.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index a432ed17..d5c5b30f 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -2871,16 +2871,13 @@ node_provider_distribution_suspended: false, }; let local_hero = (request.mode == MissionMode::SingleMission) .then(|| { - let mut heroes = - object_drafts[..reserve_start] - .iter() - .zip(&handles) - .filter(|(draft, _)| { - draft.unit_dat_header_flags == Some(HERO_UNIT_CLASS) - && draft.raw_after_resource == 0 - }); - let (_, &hero) = heroes.next()?; - heroes.next().is_none().then_some(hero) + mission_events.starting_hero(&new_runtime_world, fparkan_world::OwnerId(0), |handle| { + control_device_tables.iter().any(|table| { + table.handle == handle + && table.native_control_class.is_some() + && !table.node_provider_depletion_marked + }) + }) }) .flatten(); engine.world = new_runtime_world; @@ -3874,7 +3871,7 @@ pub fn mission_object_handle(engine: &Engine, id: OriginalObjectId) -> Option<Ob handle_by_original_id(&engine.world, id) } -/// Camera point of the single unambiguous starting hero in a mission. +/// Camera point of the local player's starting hero. #[derive(Clone, Copy, Debug, PartialEq)] pub struct StartingCockpit { /// Live world object whose transform drives the viewpoint. @@ -3893,21 +3890,14 @@ pub struct StartingCockpit { #[must_use] pub fn starting_cockpit(engine: &Engine) -> Option<StartingCockpit> { let mission = engine.loaded.as_ref()?; - if mission.script_host_mode != MissionMode::SingleMission { - return None; - } - // shortcut: pick only a unique hero until native local ownership is wired. - let mut heroes = mission - .object_drafts - .iter() - .enumerate() - .filter(|(_, object)| object.unit_dat_header_flags == Some(HERO_UNIT_CLASS)); - let (object_index, hero) = heroes.next()?; - if heroes.next().is_some() { + let hero = mission.local_hero?; + let id = fparkan_world::identity_metadata(&engine.world, hero) + .ok()? + .original_id?; + if mission_object_handle(engine, id)? != hero { return None; } - let handle = mission_object_handle(engine, hero.original_id?)?; - component_cockpit(mission, object_index, handle) + component_cockpit(mission, id.0 as usize, hero) } fn component_cockpit( |
