aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 18:05:52 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 18:05:52 +0300
commit9f442fa339371869dda44a32a9e0ec2f763d830c (patch)
treebec91edfe30d42a278502561af155c11a32de764 /crates/fparkan-runtime
parent3b5a8aa4e6465ca56763cb96b4100bb1ff1c0ccf (diff)
downloadfparkan-9f442fa339371869dda44a32a9e0ec2f763d830c.tar.xz
fparkan-9f442fa339371869dda44a32a9e0ec2f763d830c.zip
feat(ui): connect the bunker list to the strategic camera
Show clan bunkers with the original compound controls and map selection. The strategic command button switches the camera anchor and preserves a view already bound to that bunker. Check the stock Two Fortresses window with Vulkan validation and exercise retargeting and the ownership guard with the licensed runtime test.
Diffstat (limited to 'crates/fparkan-runtime')
-rw-r--r--crates/fparkan-runtime/src/strategic_buildings.rs30
-rw-r--r--crates/fparkan-runtime/src/strategic_toolbar.rs2
-rw-r--r--crates/fparkan-runtime/src/strategic_view.rs55
3 files changed, 80 insertions, 7 deletions
diff --git a/crates/fparkan-runtime/src/strategic_buildings.rs b/crates/fparkan-runtime/src/strategic_buildings.rs
index 91024136..2c97c3c9 100644
--- a/crates/fparkan-runtime/src/strategic_buildings.rs
+++ b/crates/fparkan-runtime/src/strategic_buildings.rs
@@ -1,10 +1,27 @@
-//! Live rows of the strategic «Другие здания» section.
+//! Live rows of the strategic building sections.
use crate::{strategic_map_readout::building_label, Engine, StartingCockpit};
use fparkan_world::{identity_metadata, registration_sequence, ObjectHandle};
use std::cmp::Reverse;
pub(super) const OTHER_BUILDINGS: u32 = 0x8000_044e;
+pub(super) const BUNKERS: u32 = 0x8007_0000;
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum BuildingSection {
+ Bunkers,
+ Other,
+}
+
+impl BuildingSection {
+ pub fn matches(self, class: u32) -> bool {
+ let mask = match self {
+ Self::Bunkers => BUNKERS,
+ Self::Other => OTHER_BUILDINGS,
+ };
+ class != 0 && class & mask == class
+ }
+}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct BuildingRow {
@@ -16,7 +33,11 @@ pub struct BuildingRow {
}
/// Buildings of the operator's clan, most recently registered first.
-pub fn other_buildings(engine: &Engine, cockpit: StartingCockpit) -> Vec<BuildingRow> {
+pub fn building_rows(
+ engine: &Engine,
+ cockpit: StartingCockpit,
+ section: BuildingSection,
+) -> Vec<BuildingRow> {
let Some((mission, owner)) = engine.loaded.as_ref().zip(
identity_metadata(&engine.world, cockpit.handle)
.ok()
@@ -31,8 +52,7 @@ pub fn other_buildings(engine: &Engine, cockpit: StartingCockpit) -> Vec<Buildin
let handle = table.handle;
let draft = mission.object_drafts.get(table.original_id?.0 as usize)?;
let class = draft.unit_dat_header_flags?;
- if class == 0
- || class & OTHER_BUILDINGS != class
+ if !section.matches(class)
|| table.node_provider_depletion_marked
|| identity_metadata(&engine.world, handle).ok()?.owner_id != Some(owner)
{
@@ -85,7 +105,7 @@ mod tests {
.unwrap();
frame(&mut engine, 1).unwrap();
let cockpit = starting_cockpit(&engine).unwrap();
- let rows = other_buildings(&engine, cockpit);
+ let rows = building_rows(&engine, cockpit, BuildingSection::Other);
assert_eq!(
rows.iter().map(|row| row.label).collect::<Vec<_>>(),
[0x179e, 0x178f, 0x1794, 0x1799]
diff --git a/crates/fparkan-runtime/src/strategic_toolbar.rs b/crates/fparkan-runtime/src/strategic_toolbar.rs
index de35f695..a086a482 100644
--- a/crates/fparkan-runtime/src/strategic_toolbar.rs
+++ b/crates/fparkan-runtime/src/strategic_toolbar.rs
@@ -11,7 +11,7 @@ const SECTION_MASKS: [u32; 8] = [
0x8000_0400,
0x8000_0010,
0x8030_0000,
- 0x8007_0000,
+ crate::strategic_buildings::BUNKERS,
crate::strategic_buildings::OTHER_BUILDINGS,
];
diff --git a/crates/fparkan-runtime/src/strategic_view.rs b/crates/fparkan-runtime/src/strategic_view.rs
index daf6f17f..ccef3b82 100644
--- a/crates/fparkan-runtime/src/strategic_view.rs
+++ b/crates/fparkan-runtime/src/strategic_view.rs
@@ -201,6 +201,28 @@ impl CommandCamera {
})
}
+ /// Switches to a live bunker of the player clan and returns the previous post.
+ pub fn focus_bunker(
+ &mut self,
+ engine: &Engine,
+ cockpit: StartingCockpit,
+ target: ObjectHandle,
+ ) -> Option<CommandPost> {
+ use crate::strategic_buildings::{building_rows, BuildingSection};
+ let post = CommandPost::Bunker(target);
+ // iron3d+0x62ee0 skips the transition when this post already supplies the view.
+ if self.post == post
+ || !building_rows(engine, cockpit, BuildingSection::Bunkers)
+ .iter()
+ .any(|row| row.handle == target)
+ {
+ return None;
+ }
+ let previous = self.post;
+ *self = Self::new(engine, post)?;
+ Some(previous)
+ }
+
/// Advances the external view and returns the pose for this frame.
/// `building_height` reports the highest building hit on the downward segment.
pub fn sample(
@@ -325,7 +347,7 @@ mod tests {
MissionRequest, MissionStartupInput,
};
use fparkan_vfs::DirectoryVfs;
- use fparkan_world::OriginalObjectId;
+ use fparkan_world::{set_owner, OriginalObjectId};
use std::sync::Arc;
#[test]
@@ -425,5 +447,36 @@ mod tests {
})
.unwrap();
assert_eq!(raised.translation(), [previous[0], previous[1], 144.54639]);
+
+ use crate::strategic_buildings::{building_rows, BuildingSection};
+ let rows = building_rows(&engine, hero, BuildingSection::Bunkers);
+ assert_eq!(rows.len(), 1);
+ assert_eq!((rows[0].handle, rows[0].label), (bunker, 0x17cc));
+
+ camera.position[0] += 10.0;
+ assert_eq!(camera.focus_bunker(&engine, hero, bunker), None);
+ assert_eq!(camera.position[0], previous[0] + 10.0);
+ let other = engine
+ .loaded
+ .as_ref()
+ .unwrap()
+ .object_drafts
+ .iter()
+ .filter(|draft| {
+ draft
+ .unit_dat_header_flags
+ .is_some_and(|class| BuildingSection::Bunkers.matches(class))
+ })
+ .filter_map(|draft| crate::mission_object_handle(&engine, draft.original_id?))
+ .find(|&handle| handle != bunker)
+ .unwrap();
+ assert_eq!(camera.focus_bunker(&engine, hero, other), None);
+ let owner = identity_metadata(&engine.world, hero.handle)
+ .unwrap()
+ .owner_id;
+ set_owner(&mut engine.world, other, owner).unwrap();
+ assert_eq!(camera.focus_bunker(&engine, hero, other), post);
+ assert_eq!(camera.post, CommandPost::Bunker(other));
+ assert_eq!(camera.position, post_position(&engine, other).unwrap());
}
}