diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-14 14:16:34 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-14 14:16:34 +0300 |
| commit | 6fb7d7d4c515da290b10543549e8f564e65ab882 (patch) | |
| tree | 6f5209d5b2e5e72cd8a3f5a07dcb465637f973b4 /crates/fparkan-runtime/src/mission_events.rs | |
| parent | 3691f55788b861c424e913daed31fc097266abe9 (diff) | |
| download | fparkan-6fb7d7d4c515da290b10543549e8f564e65ab882.tar.xz fparkan-6fb7d7d4c515da290b10543549e8f564e65ab882.zip | |
feat(runtime): capture enemy buildings from communicators
Diffstat (limited to 'crates/fparkan-runtime/src/mission_events.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/mission_events.rs | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs index cdb2812e..7a86de19 100644 --- a/crates/fparkan-runtime/src/mission_events.rs +++ b/crates/fparkan-runtime/src/mission_events.rs @@ -287,20 +287,39 @@ pub fn capture_neutral_building( engine: &mut Engine, cockpit: StartingCockpit, ) -> Result<Option<OriginalObjectId>, EngineError> { + capture_building_at_communicator(engine, cockpit, false) +} + +/// Transfers a neutral or hostile building at the player's communicator. +/// +/// # Errors +/// Returns an error if the player's world handle or the ownership update fails. +pub fn capture_building( + engine: &mut Engine, + cockpit: StartingCockpit, +) -> Result<Option<OriginalObjectId>, EngineError> { + capture_building_at_communicator(engine, cockpit, true) +} + +fn capture_building_at_communicator( + engine: &mut Engine, + cockpit: StartingCockpit, + allow_hostile: bool, +) -> Result<Option<OriginalObjectId>, EngineError> { let Some(mission) = &mut engine.loaded else { return Ok(None); }; let Some(player_owner) = identity_metadata(&engine.world, cockpit.handle)?.owner_id else { return Ok(None); }; - if !mission + let Some(player_clan) = mission .mission .clans .get(usize::from(player_owner.0)) - .is_some_and(|clan| clan.mode == 1) - { + .filter(|clan| clan.mode == 1) + else { return Ok(None); - } + }; let position = transform_state(&engine.world, cockpit.handle)? .position .map(f32::from_bits); @@ -313,7 +332,18 @@ pub fn capture_neutral_building( let identity = identity_metadata(&engine.world, handle).ok()?; let owner = identity.owner_id?; let clan = mission.mission.clans.get(usize::from(owner.0))?; - (clan.mode == 3).then_some((handle, identity.original_id?, owner, class)) + // shortcut: use TMA diplomacy and the same communicator as a neutral transfer. + let hostile = allow_hostile + && owner != player_owner + && 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(( + handle, + identity.original_id?, + owner, + class, + )) }) .find(|&(handle, id, _, class)| { transform_state(&engine.world, handle).is_ok_and(|pose| { |
