diff options
Diffstat (limited to 'crates/fparkan-runtime/src')
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 11 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/mission_events.rs | 27 |
2 files changed, 29 insertions, 9 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index a67276a3..701a4a2e 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -149,8 +149,8 @@ pub use mesh_collision::{query_building_segment_world, BuildingMeshHit, Building pub use mining::deploy_mine; use mission_events::MissionEvents; pub use mission_events::{ - capture_building, capture_neutral_building, capture_neutral_warbot, MissionEventStop, - MissionEventTick, MissionNotice, + capture_building, capture_building_with_notice, capture_neutral_building, + capture_neutral_warbot, MissionEventStop, MissionEventTick, MissionNotice, }; pub use player_motion::{ plan_player_motion, plan_player_motion_with_collision, PlayerMotion, PlayerMotionStep, @@ -18228,8 +18228,11 @@ mod tests { }; let initial_count = count(&engine); assert_eq!( - capture_building(&mut engine, hero).unwrap(), - Some(factory_id) + capture_building_with_notice(&mut engine, hero).unwrap(), + Some(( + factory_id, + MissionNotice::BuildingCaptured { neutral: false } + )) ); assert_eq!( identity_metadata(&engine.world, factory).unwrap().owner_id, diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs index ec976224..5108a058 100644 --- a/crates/fparkan-runtime/src/mission_events.rs +++ b/crates/fparkan-runtime/src/mission_events.rs @@ -51,6 +51,8 @@ pub enum MissionNotice { Information(u32), /// Objective changed from pending to complete. ObjectiveComplete(u32), + /// The player's capture took a building from a neutral or enemy clan. + BuildingCaptured { neutral: bool }, /// Mission completed. Completed, /// Mission failed. @@ -472,6 +474,7 @@ pub fn capture_neutral_building( cockpit: StartingCockpit, ) -> Result<Option<OriginalObjectId>, EngineError> { capture_building_at_communicator(engine, cockpit, false) + .map(|capture| capture.map(|(id, _)| id)) } /// Transfers a neutral or hostile building at the player's communicator. @@ -482,6 +485,18 @@ pub fn capture_building( engine: &mut Engine, cockpit: StartingCockpit, ) -> Result<Option<OriginalObjectId>, EngineError> { + capture_building_with_notice(engine, cockpit).map(|capture| capture.map(|(id, _)| id)) +} + +/// Transfers a building and reports which capture announcement to play. +/// +/// # Errors +/// +/// Returns an error if the player's world handle or the ownership update fails. +pub fn capture_building_with_notice( + engine: &mut Engine, + cockpit: StartingCockpit, +) -> Result<Option<(OriginalObjectId, MissionNotice)>, EngineError> { capture_building_at_communicator(engine, cockpit, true) } @@ -489,7 +504,7 @@ fn capture_building_at_communicator( engine: &mut Engine, cockpit: StartingCockpit, allow_hostile: bool, -) -> Result<Option<OriginalObjectId>, EngineError> { +) -> Result<Option<(OriginalObjectId, MissionNotice)>, EngineError> { let Some(mission) = &mut engine.loaded else { return Ok(None); }; @@ -522,14 +537,16 @@ fn capture_building_at_communicator( && player_clan.relations.iter().any(|relation| { relation.relation_value == 0 && relation.other_clan_name.raw == clan.name.raw }); - (class & 0x8000_0000 != 0 && (clan.mode == 3 || hostile)).then_some(( + let neutral = clan.mode == 3; + (class & 0x8000_0000 != 0 && (neutral || hostile)).then_some(( handle, identity.original_id?, owner, class, + neutral, )) }) - .find(|&(handle, id, _, class)| { + .find(|&(handle, id, _, class, _)| { transform_state(&engine.world, handle).is_ok_and(|pose| { on_communicator( &mission.mission_assets, @@ -540,7 +557,7 @@ fn capture_building_at_communicator( ) }) }); - if let Some((handle, id, former_owner, class)) = candidate { + if let Some((handle, id, former_owner, class, neutral)) = candidate { mission.transfer_building( &mut engine.world, handle, @@ -549,7 +566,7 @@ fn capture_building_at_communicator( player_owner, class, )?; - Ok(Some(id)) + Ok(Some((id, MissionNotice::BuildingCaptured { neutral }))) } else { Ok(None) } |
