aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/clan_ai_events.rs62
-rw-r--r--crates/fparkan-runtime/src/clan_mining.rs349
-rw-r--r--crates/fparkan-runtime/src/construction.rs29
-rw-r--r--crates/fparkan-runtime/src/construction_site.rs35
-rw-r--r--crates/fparkan-runtime/src/lib.rs6
-rw-r--r--crates/fparkan-runtime/src/mission_events.rs22
6 files changed, 467 insertions, 36 deletions
diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs
index 8ac5b238..ac45745e 100644
--- a/crates/fparkan-runtime/src/clan_ai_events.rs
+++ b/crates/fparkan-runtime/src/clan_ai_events.rs
@@ -19,6 +19,7 @@ const PLACE_PROTECT: u32 = 11;
const ATTACK_UNIT: u32 = 13;
const OPTIMAL_TRANSPORT: u32 = 4;
const BUILDING_NEEDED: u32 = 3;
+const MINE_NEEDED: u32 = 1;
pub(super) struct ScriptFactoryOrder {
pub owner: OwnerId,
@@ -264,6 +265,7 @@ pub(super) struct ClanAiEvents {
class_target_queries: BTreeMap<(usize, u32, u32), u64>,
size_class_queries: BTreeMap<(usize, u32), u64>,
class_limit_queries: BTreeMap<(usize, u32, bool), u64>,
+ mine_queries: BTreeMap<(usize, u32, u32, u32), u64>,
}
impl LoadedMissionState {
@@ -385,7 +387,7 @@ impl LoadedMissionState {
next = Some((index, event, Some(problem)));
break;
}
- let Some((event_index, event, problem)) = next.or_else(|| problems_event.take())
+ let Some((event_index, _event, problem)) = next.or_else(|| problems_event.take())
else {
break;
};
@@ -396,22 +398,40 @@ impl LoadedMissionState {
let mut capturer = None;
let mut group = None;
let mut conditions = Vec::new();
- let result = varset.declarations.execute_event_prefix(
- event,
+ let result = varset.declarations.execute_package_event_prefix(
+ &bundle.package,
+ event_index,
bundle.formula_table.as_ref(),
&mut state.values,
- |instruction, values| match instruction.dispatch_selector() {
+ |active_event_index, instruction, values| match instruction.dispatch_selector() {
+ ScriptDispatchSelector::Handler(40) => {
+ let selected = crate::clan_mining::query(
+ &self.mission, &self.mission_events, world, &self.object_drafts,
+ &self.control_device_tables, &self.mine_sites, clan,
+ );
+ let result = selected.write(&instruction.references, values)?;
+ if let Some(position) = selected.reservation() {
+ self.clan_ai_events.building_sites.reserve(position, now_ms);
+ }
+ let (target, [x, y]) = selected.report_key();
+ let count = self.clan_ai_events.mine_queries.entry((clan, target, x, y)).or_default();
+ *count += 1;
+ if *count == 1 {
+ eprintln!("sim_coverage script_mine_target_approx=1 clan={clan} target={target} x={x} y={y}");
+ }
+ Ok(Some(VarSetDefault::Dword(result)))
+ }
ScriptDispatchSelector::Handler(44) => {
let strength = crate::clan_area_strength::query(
&self.mission, &self.mission_events, world, &self.object_drafts,
&self.control_device_tables, clan, instruction, values,
)?;
- let index = event.instructions.iter().position(|item| std::ptr::eq(item, instruction))
+ let index = bundle.package.events[active_event_index].instructions.iter().position(|item| std::ptr::eq(item, instruction))
.expect("instruction belongs to the executing event");
- let count = self.clan_ai_events.area_strength_queries.entry((clan, event_index, index)).or_default();
+ let count = self.clan_ai_events.area_strength_queries.entry((clan, active_event_index, index)).or_default();
*count += 1;
if *count == 1 {
- eprintln!("sim_coverage script_area_strength_approx=1 clan={clan} event={event_index} instruction={index} strength={strength}");
+ eprintln!("sim_coverage script_area_strength_approx=1 clan={clan} event={active_event_index} instruction={index} strength={strength}");
}
Ok(Some(VarSetDefault::Dword(strength)))
}
@@ -698,8 +718,12 @@ impl LoadedMissionState {
if let (7, 3, Handler15TargetPayload::ByPlace { first, second }) =
(order.word_1, order.word_2, order.target)
{
- if !problem.as_ref().is_some_and(|p| p.key.word_0 == BUILDING_NEEDED)
- || !crate::construction::supports_class(order.word_3)
+ let supported = problem.as_ref().is_some_and(|p| match p.key.word_0 {
+ MINE_NEEDED => order.word_3 == crate::mining::MINE_CLASS,
+ BUILDING_NEEDED => crate::construction::supports_class(order.word_3),
+ _ => false,
+ });
+ if !supported
{
return Err("ORDER_ROBOT_BUILD requires a supported building scheme".into());
}
@@ -708,7 +732,7 @@ impl LoadedMissionState {
.find(|&handle| identity_metadata(world, handle).is_ok_and(|identity| identity.owner_id == Some(owner)));
let result = crate::construction::order(
&mut self.construction, &mut self.unit_patrol, world, &self.terrain, &self.mission,
- &self.object_drafts, &self.behavior_ore_states, &self.free_research,
+ &self.object_drafts, &self.mine_sites, &self.behavior_ore_states, &self.free_research,
vfs, builder, owner, order.word_3, [first, second],
);
let rates = self.clan_ai_events.construction_orders.entry((clan, order.word_0, order.word_3)).or_default();
@@ -883,7 +907,7 @@ impl LoadedMissionState {
Some(1)
if problem
.as_ref()
- .is_some_and(|record| matches!(record.key.word_0, OPTIMAL_TRANSPORT | 6 | BUILDING_PROTECT | PLACE_PROTECT))
+ .is_some_and(|record| matches!(record.key.word_0, OPTIMAL_TRANSPORT | MINE_NEEDED | 6 | BUILDING_PROTECT | PLACE_PROTECT))
|| !conditions.is_empty() =>
{
solving = true
@@ -911,7 +935,7 @@ impl LoadedMissionState {
};
let key = problem.as_ref().expect("condition requires a problem").key;
let condition = match (action, mode) {
- (2, 0) if key.word_0 == BUILDING_NEEDED || (key.word_0 == OPTIMAL_TRANSPORT && solving) => {
+ (2, 0) if matches!(key.word_0, BUILDING_NEEDED | MINE_NEEDED) || (key.word_0 == OPTIMAL_TRANSPORT && solving) => {
let unit = assignment.filter(|&unit| self.mission_events
.logic_objects(&self.mission, world, id).any(|handle| handle == unit))
.ok_or("Handler(27) task wait requires the assigned unit")?;
@@ -1215,17 +1239,17 @@ impl LoadedMissionState {
selector => Err(format!("{selector:?}")),
},
);
- if let Err((instruction_index, reason)) = result {
+ if let Err((stopped_event, instruction_index, reason)) = result {
let (stop, count) = self
.clan_ai_events
.stops
- .entry((clan, event_index, instruction_index))
+ .entry((clan, stopped_event, instruction_index))
.or_insert_with(|| {
(
MissionEventStop {
clan_index: clan,
script_path: bundle.script_path.clone(),
- event_index,
+ event_index: stopped_event,
instruction_index,
reason,
},
@@ -1234,7 +1258,7 @@ impl LoadedMissionState {
});
*count += 1;
if *count == 1 {
- eprintln!("sim_coverage script_clan_ai_unsupported=1 clan={clan} script={} event={event_index} instruction={instruction_index} reason={}", stop.script_path, stop.reason);
+ eprintln!("sim_coverage script_clan_ai_unsupported=1 clan={clan} script={} event={stopped_event} instruction={instruction_index} reason={}", stop.script_path, stop.reason);
}
}
if let Some(problem) = problem {
@@ -1480,6 +1504,12 @@ impl ClanAiEvents {
.map(|(&(clan, class, blocked), &count)| (clan, class, blocked, count))
}
+ pub(super) fn mine_queries(&self) -> impl Iterator<Item = (usize, u32, u32, u32, u64)> + '_ {
+ self.mine_queries
+ .iter()
+ .map(|(&(clan, target, x, y), &count)| (clan, target, x, y, count))
+ }
+
pub(super) fn construction_orders(
&self,
) -> impl Iterator<Item = (usize, u32, u32, u64, u64)> + '_ {
diff --git a/crates/fparkan-runtime/src/clan_mining.rs b/crates/fparkan-runtime/src/clan_mining.rs
new file mode 100644
index 00000000..a9ae9fe4
--- /dev/null
+++ b/crates/fparkan-runtime/src/clan_mining.rs
@@ -0,0 +1,349 @@
+use crate::{
+ mining::MineSite, mission_events::MissionEvents, MissionControlDeviceTableState,
+ MissionDocument, MissionObjectDraft,
+};
+use fparkan_script::VarSetDefault;
+use fparkan_world::{identity_metadata, transform_state, OwnerId, World};
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub(super) enum Selection {
+ Vacant([f32; 3], f32),
+ Mine(u32, f32),
+ None,
+}
+
+struct Candidate {
+ position: [f32; 3],
+ occupied: bool,
+ target: Option<(u32, f32)>,
+}
+
+pub(super) fn query(
+ mission: &MissionDocument,
+ roster: &MissionEvents,
+ world: &World,
+ drafts: &[MissionObjectDraft],
+ controls: &[MissionControlDeviceTableState],
+ sites: &[MineSite],
+ caller: usize,
+) -> Selection {
+ let source = &mission.clans[caller];
+ let enemy_clans: Vec<_> = mission
+ .clans
+ .iter()
+ .enumerate()
+ .filter_map(|(index, other)| {
+ (index != caller
+ && source.relations.iter().any(|relation| {
+ relation.relation_value == 0 && relation.other_clan_name.raw == other.name.raw
+ }))
+ .then_some(OwnerId(index as u16))
+ })
+ .collect();
+ let enemies: Vec<_> = enemy_clans
+ .iter()
+ .flat_map(|&owner| roster.clan_units(world, owner, false))
+ .collect();
+ let strength = |position| {
+ crate::clan_targeting::area_strength(
+ world,
+ drafts,
+ controls,
+ enemies.iter().copied(),
+ position,
+ 350.0,
+ )
+ };
+ // shortcut: use the current lode bindings until native ArealMap mineral records are wired.
+ let candidates: Vec<_> = sites
+ .iter()
+ .map(|site| {
+ let mine = site.live_mine(world);
+ let target = mine.and_then(|handle| {
+ let owner = identity_metadata(world, handle).ok()?.owner_id?;
+ if !enemy_clans.contains(&owner) {
+ return None;
+ }
+ let id = roster.logic_id(mission, world, handle)?;
+ let position = transform_state(world, handle)
+ .ok()?
+ .position
+ .map(f32::from_bits);
+ Some((id, strength(position)))
+ });
+ Candidate {
+ position: site.position,
+ occupied: mine.is_some(),
+ target,
+ }
+ })
+ .collect();
+ select(&candidates, source.anchor, strength)
+}
+
+fn select(
+ candidates: &[Candidate],
+ base: [f32; 2],
+ strength: impl Fn([f32; 3]) -> f32,
+) -> Selection {
+ let mut nearest = None;
+ let mut distance = 999_999_999;
+ for site in candidates.iter().filter(|site| !site.occupied) {
+ let dx = (site.position[0] - base[0]).abs();
+ let dy = (site.position[1] - base[1]).abs();
+ // The x87 result is truncated to a DWORD before comparing distances.
+ let next = (dx * dx + dy * dy).sqrt() as u32;
+ if next < distance {
+ distance = next;
+ nearest = Some(site.position);
+ }
+ }
+ if let Some(position) = nearest {
+ return Selection::Vacant(position, strength(position));
+ }
+ let mut weakest = Selection::None;
+ let mut power = 1e12_f32;
+ for &(id, candidate) in candidates.iter().filter_map(|site| site.target.as_ref()) {
+ if candidate < power {
+ power = candidate;
+ weakest = Selection::Mine(id, candidate);
+ }
+ }
+ weakest
+}
+
+impl Selection {
+ pub(super) fn reservation(self) -> Option<[f32; 2]> {
+ match self {
+ Self::Vacant([x, y, _], _) => Some([x, y]),
+ _ => None,
+ }
+ }
+
+ pub(super) fn report_key(self) -> (u32, [u32; 2]) {
+ match self {
+ Self::Vacant([x, y, _], _) => (u32::MAX, [word(x), word(y)]),
+ Self::Mine(id, _) => (id, [0; 2]),
+ Self::None => (u32::MAX, [0; 2]),
+ }
+ }
+
+ pub(super) fn write(
+ self,
+ references: &[u32],
+ values: &mut [VarSetDefault],
+ ) -> Result<u32, String> {
+ let &[x, y, power] = references else {
+ return Err("Handler(40) requires X, Y and strength outputs".into());
+ };
+ if [x, y, power]
+ .iter()
+ .any(|&index| values.get(index as usize).is_none())
+ {
+ return Err("Handler(40) output is unavailable".into());
+ }
+ let (id, outputs) = match self {
+ Self::Vacant([x, y, _], power) => (
+ u32::MAX,
+ [
+ Some(word(x)),
+ Some(word(y)),
+ Some(crate::clan_targeting::encode_strength(power) as u32),
+ ],
+ ),
+ Self::Mine(id, power) => (
+ id,
+ [
+ None,
+ None,
+ Some(crate::clan_targeting::encode_strength(power) as u32),
+ ],
+ ),
+ Self::None => (u32::MAX, [Some(0), Some(0), None]),
+ };
+ for (index, output) in [x, y, power].into_iter().zip(outputs) {
+ if let Some(output) = output {
+ let cell = &mut values[index as usize];
+ *cell = match *cell {
+ VarSetDefault::Dword(_) => VarSetDefault::Dword(output),
+ VarSetDefault::FloatBits(_) => {
+ VarSetDefault::FloatBits((output as f32).to_bits())
+ }
+ };
+ }
+ }
+ Ok(id)
+ }
+}
+
+fn word(value: f32) -> u32 {
+ value.trunc() as i64 as u32
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ #[ignore = "requires licensed corpus"]
+ fn licensed_stock_clan_builds_a_mine_and_extracts_ore() {
+ use crate::{EngineServices, MissionMode, MissionRequest, MissionStartupInput};
+ use fparkan_vfs::DirectoryVfs;
+ use std::sync::Arc;
+
+ let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap();
+ let mut engine =
+ crate::create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap();
+ crate::load_gameplay_mission(
+ &mut engine,
+ MissionRequest {
+ key: "MISSIONS/Single.02/data.tma".into(),
+ mode: MissionMode::SingleMission,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ None,
+ )
+ .unwrap();
+ let loaded = engine.loaded.as_ref().unwrap();
+ assert!(loaded
+ .mine_sites
+ .iter()
+ .all(|site| site.live_mine(&engine.world).is_none()));
+ for now in (0..=120_000).step_by(100) {
+ crate::frame(&mut engine, now).unwrap();
+ let loaded = engine.loaded.as_ref().unwrap();
+ if let Some((site_index, handle)) =
+ loaded
+ .mine_sites
+ .iter()
+ .enumerate()
+ .find_map(|(index, site)| {
+ site.live_mine(&engine.world).map(|handle| (index, handle))
+ })
+ {
+ assert_eq!(
+ identity_metadata(&engine.world, handle).unwrap().owner_id,
+ Some(OwnerId(1))
+ );
+ assert!(loaded
+ .clan_ai_events
+ .mine_queries()
+ .any(|(clan, id, x, y, count)| clan == 1
+ && id == u32::MAX
+ && x > 0
+ && y > 0
+ && count > 0));
+ assert!(!loaded
+ .clan_ai_events
+ .stops()
+ .any(|(stop, _)| stop.event_index == 21 || stop.event_index == 23));
+ let [x, y, _] = loaded.mine_sites[site_index].position;
+ let [mx, my, _] = transform_state(&engine.world, handle)
+ .unwrap()
+ .position
+ .map(f32::from_bits);
+ assert!((x - mx).hypot(y - my) < 1.5);
+ for later in (now + 100..=now + 2_000).step_by(100) {
+ crate::frame(&mut engine, later).unwrap();
+ }
+ let loaded = engine.loaded.as_ref().unwrap();
+ let ore = loaded
+ .behavior_ore_states
+ .iter()
+ .find(|ore| ore.handle == handle)
+ .unwrap();
+ assert!(f32::from_bits(ore.current_ore_bits) > 0.0);
+ assert_eq!(f32::from_bits(ore.maximum_ore_bits), 500.0);
+ return;
+ }
+ }
+ panic!("no clan completed a mine from the stock start");
+ }
+
+ #[test]
+ fn vacant_lode_precedes_enemy_mine_and_keeps_first_integer_distance_tie() {
+ let sites = [
+ Candidate {
+ position: [1.0, 0.0, 0.0],
+ occupied: true,
+ target: Some((10, 0.0)),
+ },
+ Candidate {
+ position: [100.9, 0.1, 0.0],
+ occupied: false,
+ target: None,
+ },
+ Candidate {
+ position: [100.1, 0.1, 0.0],
+ occupied: false,
+ target: None,
+ },
+ ];
+ assert_eq!(
+ select(&sites, [0.0; 2], |_| 8.2),
+ Selection::Vacant(sites[1].position, 8.2)
+ );
+ }
+
+ #[test]
+ fn occupied_lodes_choose_weakest_enemy_and_first_strength_tie() {
+ let sites = [
+ Candidate {
+ position: [0.0; 3],
+ occupied: true,
+ target: None,
+ },
+ Candidate {
+ position: [0.0; 3],
+ occupied: true,
+ target: Some((10, 8.0)),
+ },
+ Candidate {
+ position: [0.0; 3],
+ occupied: true,
+ target: Some((11, 0.0)),
+ },
+ Candidate {
+ position: [0.0; 3],
+ occupied: true,
+ target: Some((12, 0.0)),
+ },
+ ];
+ assert_eq!(
+ select(&sites, [0.0; 2], |_| unreachable!()),
+ Selection::Mine(11, 0.0)
+ );
+ assert_eq!(
+ select(&sites[..1], [0.0; 2], |_| unreachable!()),
+ Selection::None
+ );
+ }
+
+ #[test]
+ fn output_writes_preserve_the_native_untouched_cells() {
+ let mut values = [111, 222, 333].map(VarSetDefault::Dword);
+ assert_eq!(
+ Selection::None.write(&[0, 1, 2], &mut values).unwrap(),
+ u32::MAX
+ );
+ assert_eq!(values, [0, 0, 333].map(VarSetDefault::Dword));
+ values = [111, 222, 333].map(VarSetDefault::Dword);
+ assert_eq!(
+ Selection::Mine(10, 8.2)
+ .write(&[0, 1, 2], &mut values)
+ .unwrap(),
+ 10
+ );
+ assert_eq!(values, [111, 222, 8].map(VarSetDefault::Dword));
+ assert_eq!(
+ Selection::Vacant([500.9, 600.8, 0.0], 8.2)
+ .write(&[0, 1, 2], &mut values)
+ .unwrap(),
+ u32::MAX
+ );
+ assert_eq!(values, [500, 600, 8].map(VarSetDefault::Dword));
+ }
+}
diff --git a/crates/fparkan-runtime/src/construction.rs b/crates/fparkan-runtime/src/construction.rs
index 3f347d9f..571617b3 100644
--- a/crates/fparkan-runtime/src/construction.rs
+++ b/crates/fparkan-runtime/src/construction.rs
@@ -124,6 +124,7 @@ pub(super) fn order(
terrain: &fparkan_terrain::TerrainWorld,
mission: &crate::MissionDocument,
drafts: &[crate::MissionObjectDraft],
+ mine_sites: &[crate::mining::MineSite],
ores: &[crate::BehaviorOreState],
research: &crate::research::FreeResearch,
vfs: Option<&dyn fparkan_vfs::Vfs>,
@@ -146,9 +147,17 @@ pub(super) fn order(
.iter()
.find(|ore| ore.handle == builder && ore.class_flags == BUILDER_CLASS)
.ok_or("unit has no builder ore state")?;
- let slot = construction
- .available_slot(world, drafts, class)
- .ok_or("no free prepared building slot")?;
+ let slot = if class == crate::mining::MINE_CLASS {
+ mine_sites.iter().find_map(|site| {
+ let point = [site.position[0], site.position[1]].map(|axis| axis.trunc() as i64 as u32);
+ let id = site.control.as_ref()?.original_id?;
+ (point == xy && site.live_mine(world).is_none()).then_some(id.0 as usize)
+ })
+ } else {
+ construction.available_slot(world, drafts, class)
+ }
+ .filter(|&slot| !construction.tasks.iter().any(|task| task.slot == slot))
+ .ok_or("no free prepared building slot")?;
let table = crate::research::load_technology_table(
vfs.ok_or("no clan technology provider")?,
mission,
@@ -263,8 +272,17 @@ fn complete(
.behavior_profiles
.iter()
.position(|profile| profile.original_id == id);
- let control =
- mission.construction.controls[task.slot - mission.construction.first_slot].clone();
+ let control = if class == crate::mining::MINE_CLASS {
+ mission
+ .mine_sites
+ .iter()
+ .filter_map(|site| site.control.as_ref())
+ .find(|control| control.original_id == Some(id))
+ .cloned()
+ .ok_or_else(|| crate::EngineError::Production("mine control is unavailable".into()))?
+ } else {
+ mission.construction.controls[task.slot - mission.construction.first_slot].clone()
+ };
let handle = spawn_prepared_unit(
world,
mission,
@@ -461,6 +479,7 @@ mod tests {
&mission.terrain,
&mission.mission,
&mission.object_drafts,
+ &mission.mine_sites,
&mission.behavior_ore_states,
&mission.free_research,
Some(vfs.as_ref()),
diff --git a/crates/fparkan-runtime/src/construction_site.rs b/crates/fparkan-runtime/src/construction_site.rs
index ddb92a8e..dd3851d2 100644
--- a/crates/fparkan-runtime/src/construction_site.rs
+++ b/crates/fparkan-runtime/src/construction_site.rs
@@ -4,7 +4,7 @@ use fparkan_world::{handle_by_original_id, registration_sequence, transform_stat
use crate::{mining::MineSite, MissionObjectDraft};
#[derive(Default)]
-pub(super) struct SiteReservations(Vec<([u32; 2], u32)>);
+pub(super) struct SiteReservations(Vec<([f32; 2], u32)>);
pub(super) fn building_centers<'a>(
world: &'a World,
@@ -29,6 +29,14 @@ pub(super) fn separated([x, y]: [f32; 2], [a, b]: [f32; 2]) -> bool {
}
impl SiteReservations {
+ pub(super) fn reserve(&mut self, position: [f32; 2], now_ms: u32) {
+ self.0
+ .retain(|&(_, time)| now_ms.wrapping_sub(time) <= 60_000);
+ if position != [0.0; 2] && self.0.len() < 20 {
+ self.0.push((position, now_ms));
+ }
+ }
+
pub(super) fn find(
&mut self,
terrain: &TerrainWorld,
@@ -47,20 +55,14 @@ impl SiteReservations {
});
let occupied = occupied
.chain(deposits)
- .chain(
- self.0
- .iter()
- .map(|&(position, _)| position.map(|axis| axis as f32)),
- )
+ .chain(self.0.iter().map(|&(position, _)| position))
.collect::<Vec<_>>();
let position = find_site(base, &occupied, |[x, y]| {
// shortcut: use navigable terrain polygons until the ArealMap placement bit is mapped.
terrain.locate_areal([x, y, 0.0]).ok()??;
terrain.height_at([x, y]).ok()?
})?;
- if self.0.len() < 20 {
- self.0.push((position, now_ms));
- }
+ self.reserve(position.map(|axis| axis as f32), now_ms);
Some(position)
}
}
@@ -109,6 +111,21 @@ fn find_site(
#[cfg(test)]
mod tests {
+ #[test]
+ fn reservations_keep_fractional_coordinates_and_expire_after_one_minute() {
+ let mut sites = super::SiteReservations::default();
+ sites.reserve([0.0; 2], 1);
+ assert!(sites.0.is_empty());
+ for _ in 0..25 {
+ sites.reserve([10.25, 20.75], 1);
+ }
+ assert_eq!(sites.0.len(), 20);
+ sites.reserve([30.5, 40.5], 60_001);
+ assert_eq!(sites.0[0], ([10.25, 20.75], 1));
+ sites.reserve([30.5, 40.5], 60_002);
+ assert_eq!(sites.0, vec![([30.5, 40.5], 60_002)]);
+ }
+
use super::*;
#[test]
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 0d43384f..d297029a 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -50,6 +50,7 @@ mod clan_build_limits;
mod clan_building_queries;
mod clan_combat_groups;
mod clan_combat_strength;
+mod clan_mining;
mod clan_problem_conditions;
mod clan_script_init;
mod clan_targeting;
@@ -2937,6 +2938,7 @@ pub struct SimulationReport {
pub script_ore_transport_orders: Vec<(usize, u32, u64)>,
pub script_building_site_queries: Vec<(usize, u32, u64)>,
pub script_class_limit_queries: Vec<(usize, u32, bool, u64)>,
+ pub script_mine_queries: Vec<(usize, u32, u32, u32, u64)>,
pub script_construction_orders: Vec<(usize, u32, u32, u64, u64)>,
pub script_capturer_queries: Vec<(usize, u64)>,
pub script_capture_approaches: Vec<(u32, u32, u64)>,
@@ -3001,6 +3003,7 @@ pub fn simulate_mission_report(
script_ore_transport_orders: Vec::new(),
script_building_site_queries: Vec::new(),
script_class_limit_queries: Vec::new(),
+ script_mine_queries: Vec::new(),
script_construction_orders: Vec::new(),
script_capturer_queries: Vec::new(),
script_capture_approaches: Vec::new(),
@@ -3148,6 +3151,9 @@ pub fn simulate_mission_report(
.script_class_limit_queries
.extend(loaded.clan_ai_events.class_limit_queries());
report
+ .script_mine_queries
+ .extend(loaded.clan_ai_events.mine_queries());
+ report
.script_construction_orders
.extend(loaded.clan_ai_events.construction_orders());
report
diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs
index a4abc343..7d84eb68 100644
--- a/crates/fparkan-runtime/src/mission_events.rs
+++ b/crates/fparkan-runtime/src/mission_events.rs
@@ -208,15 +208,25 @@ impl MissionEvents {
if identity.owner_id != Some(OwnerId(clan as u16)) {
return None;
}
- self.issued_logic_ids.get(&handle).copied().or_else(|| {
- mission
- .objects
- .get(identity.original_id?.0 as usize)
- .map(|object| object.identity_or_clan_raw)
- })
+ self.logic_id(mission, world, handle)
})
}
+ pub(super) fn logic_id(
+ &self,
+ mission: &super::MissionDocument,
+ world: &World,
+ handle: ObjectHandle,
+ ) -> Option<u32> {
+ self.issued_logic_ids.get(&handle).copied().or_else(|| {
+ let identity = identity_metadata(world, handle).ok()?;
+ mission
+ .objects
+ .get(identity.original_id?.0 as usize)
+ .map(|object| object.identity_or_clan_raw)
+ })
+ }
+
pub(super) fn logic_objects<'a>(
&'a self,
mission: &'a super::MissionDocument,