diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-14 18:48:15 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-14 18:48:15 +0300 |
| commit | 55c4aa3ad801b0599fab9e4f669898d02f38c627 (patch) | |
| tree | 1bf0ee4ee308406142815f2e8f738914b1b7e540 /crates/fparkan-runtime/src | |
| parent | 99abb6bf77c259a1afb629f418f5aad64e20de75 (diff) | |
| download | fparkan-55c4aa3ad801b0599fab9e4f669898d02f38c627.tar.xz fparkan-55c4aa3ad801b0599fab9e4f669898d02f38c627.zip | |
fix(player): read flight capability from chassis profile
Diffstat (limited to 'crates/fparkan-runtime/src')
| -rw-r--r-- | crates/fparkan-runtime/src/boarding.rs | 9 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/player_motion.rs | 60 |
2 files changed, 44 insertions, 25 deletions
diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs index ec786a21..9a1479f8 100644 --- a/crates/fparkan-runtime/src/boarding.rs +++ b/crates/fparkan-runtime/src/boarding.rs @@ -13,6 +13,7 @@ pub(super) const WARBOT_CLASS: u32 = 0x0100_8000; pub(super) struct Boarding { pub(super) cockpit: StartingCockpit, pub(super) hero: StartingCockpit, + pub(super) can_fly: bool, } /// The vehicle cockpit while the player is aboard. @@ -83,6 +84,7 @@ pub fn board_friendly_warbot(engine: &mut Engine) -> Result<Option<StartingCockp let Some((_, cockpit, position)) = candidate else { return Ok(None); }; + let can_fly = crate::player_motion::warbot_can_fly(engine, cockpit.object_index); set_transform( &mut engine.world, hero.handle, @@ -92,7 +94,11 @@ pub fn board_friendly_warbot(engine: &mut Engine) -> Result<Option<StartingCockp }, )?; if let Some(mission) = &mut engine.loaded { - mission.boarding = Some(Boarding { cockpit, hero }); + mission.boarding = Some(Boarding { + cockpit, + hero, + can_fly, + }); mission.player_pitch_bits = 0; } Ok(Some(cockpit)) @@ -122,6 +128,7 @@ pub fn disembark_warbot(engine: &mut Engine) -> Result<Option<StartingCockpit>, let Some(Boarding { cockpit: vehicle, hero, + .. }) = mission.boarding else { return Ok(None); diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs index 877063f3..37ccbf4e 100644 --- a/crates/fparkan-runtime/src/player_motion.rs +++ b/crates/fparkan-runtime/src/player_motion.rs @@ -1,5 +1,38 @@ use super::{transform_state, Engine, EngineError, StartingCockpit, SurfaceQuery, TransformState}; use crate::TerrainWorld; +use fparkan_resource::{resource_name, CachedResourceRepository, ResourceRepository}; + +pub(super) fn warbot_can_fly(engine: &crate::Engine, object_index: usize) -> bool { + let profile = || { + let draft = engine.loaded.as_ref()?.object_drafts.get(object_index)?; + let chassis = draft.unit_components.first()?; + let archive = crate::bounded_ascii_c_string(&chassis.archive_raw)?; + let registry_path = crate::normalize_engine_path("chassis archive", &archive).ok()?; + let resources = CachedResourceRepository::new(engine.services.vfs.as_ref()?.clone()); + let registry = resources.open_archive(®istry_path).ok()?; + let name = crate::bounded_ascii_c_string(&chassis.resource_raw)?; + let entry = resources + .find(registry, &resource_name(name.as_bytes())) + .ok()??; + let references = + fparkan_prototype::decode_registry_entry(resources.read(entry).ok()?.as_slice()) + .ok()?; + // AniMesh supplies the sixth resource pair to CreateBehaviour. + let profile = references.get(5)?; + let archive = crate::bounded_ascii_c_string(&profile.archive_raw)?; + let path = crate::normalize_engine_path("chassis profile archive", &archive).ok()?; + let name = crate::bounded_ascii_c_string(&profile.resource_raw)?; + let archive = resources.open_archive(&path).ok()?; + let entry = resources + .find(archive, &resource_name(name.as_bytes())) + .ok()??; + fparkan_assets::decode_chassis_can_fly(resources.read(entry).ok()?.as_slice()).ok()? + }; + profile().unwrap_or_else(|| { + eprintln!("sim_coverage player_chassis_profile_stub=1 object={object_index}"); + false + }) +} // shortcut: bound stair steps and drops until the native hero collider is wired. const STEP_UP: f32 = 0.85; @@ -161,30 +194,9 @@ fn plan_player_steps( ) else { return Ok(None); }; - let flying = mission.boarding.is_some_and(|boarding| { - boarding.cockpit.handle == cockpit.handle - && mission - .object_drafts - .get(cockpit.object_index) - .and_then(|draft| draft.unit_components.first()) - .is_some_and(|chassis| { - let key = chassis.resource_raw.split(|&byte| byte == 0).next(); - // shortcut: use the stock flying chassis until Behavior's CanFly is wired. - matches!( - key, - Some( - b"R_T_02" - | b"R_L_02" - | b"R_L_05" - | b"R_L_07" - | b"R_M_02" - | b"R_B_02" - | b"R_B_07" - | b"R_B_08" - ) - ) - }) - }); + let flying = mission + .boarding + .is_some_and(|boarding| boarding.cockpit.handle == cockpit.handle && boarding.can_fly); if input.movement == [0.0; 2] && (!flying || input.climb == 0.0) && input.mouse_x == 0.0 |
