aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/fparkan-game/src/main.rs6
-rw-r--r--crates/fparkan-runtime/src/clan_ai_events.rs11
-rw-r--r--crates/fparkan-runtime/src/construction.rs28
-rw-r--r--crates/fparkan-runtime/src/lib.rs8
-rw-r--r--docs/tomes/06-behavior.md5
5 files changed, 43 insertions, 15 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 8c2e12f9..4a76f016 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -11201,6 +11201,12 @@ impl StaticVulkanApp {
.iter()
.map(|unit| (unit, "factory_robot_completed")),
)
+ .chain(
+ frame
+ .constructed_buildings
+ .iter()
+ .map(|building| (building, "building_constructed")),
+ )
.chain(deployed_mine.iter().map(|unit| (unit, "mine_deployed")))
{
let index = reinforcement.object_index;
diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs
index 0ccebdcb..e544a9d9 100644
--- a/crates/fparkan-runtime/src/clan_ai_events.rs
+++ b/crates/fparkan-runtime/src/clan_ai_events.rs
@@ -88,10 +88,13 @@ pub(super) fn resolve_captures(
Ok(captured)
}
-pub(super) fn tick(engine: &mut crate::Engine, now_ms: u32) -> Vec<MissionNotice> {
+pub(super) fn tick(
+ engine: &mut crate::Engine,
+ now_ms: u32,
+) -> (Vec<MissionNotice>, Vec<crate::SpawnedUnit>) {
let mut notices = Vec::new();
let Some(loaded) = &mut engine.loaded else {
- return notices;
+ return (notices, Vec::new());
};
crate::laboratory::tick(
loaded,
@@ -99,7 +102,7 @@ pub(super) fn tick(engine: &mut crate::Engine, now_ms: u32) -> Vec<MissionNotice
now_ms,
&mut engine.behavior_rng_state,
);
- crate::construction::tick(
+ let constructed_buildings = crate::construction::tick(
loaded,
&mut engine.world,
engine.production.as_mut(),
@@ -238,7 +241,7 @@ pub(super) fn tick(engine: &mut crate::Engine, now_ms: u32) -> Vec<MissionNotice
}
}
}
- notices
+ (notices, constructed_buildings)
}
#[derive(Default)]
diff --git a/crates/fparkan-runtime/src/construction.rs b/crates/fparkan-runtime/src/construction.rs
index d0b4c69e..0e617147 100644
--- a/crates/fparkan-runtime/src/construction.rs
+++ b/crates/fparkan-runtime/src/construction.rs
@@ -1,4 +1,4 @@
-use crate::unit_spawn::spawn_prepared_unit;
+use crate::unit_spawn::{spawn_prepared_unit, SpawnedUnit};
use crate::{LoadedMissionState, MissionScriptBundle};
use fparkan_path::ResourceName;
use fparkan_script::ScriptDispatchSelector;
@@ -209,7 +209,8 @@ pub(super) fn tick(
world: &mut World,
mut production: Option<&mut crate::production::Production>,
now_ms: u32,
-) {
+) -> Vec<SpawnedUnit> {
+ let mut constructed = Vec::new();
let mut index = 0;
while let Some(task) = mission.construction.tasks.get_mut(index) {
let owned =
@@ -286,14 +287,16 @@ pub(super) fn tick(
patrol.clear_move(task.builder);
}
if finish {
- if let Err(error) = complete(mission, world, &task, production.as_deref_mut()) {
- eprintln!(
+ match complete(mission, world, &task, production.as_deref_mut()) {
+ Ok(building) => constructed.push(building),
+ Err(error) => eprintln!(
"script_building_construction_failed clan={} builder={} reason={error}",
task.owner.0, task.builder.slot
- );
+ ),
}
}
}
+ constructed
}
fn complete(
@@ -301,7 +304,7 @@ fn complete(
world: &mut World,
task: &Task,
production: Option<&mut crate::production::Production>,
-) -> Result<(), crate::EngineError> {
+) -> Result<SpawnedUnit, crate::EngineError> {
let index = crate::behavior_ore_index_for_handle(&mission.behavior_ore_states, task.builder)
.map_err(crate::EngineError::Production)?;
let stock = f32::from_bits(mission.behavior_ore_states[index].current_ore_bits);
@@ -382,7 +385,11 @@ fn complete(
"script_building_constructed clan={} builder={} building={} class={class:#010x}",
task.owner.0, task.builder.slot, handle.slot
);
- Ok(())
+ Ok(SpawnedUnit {
+ object_index: task.slot,
+ handle,
+ clan: task.owner.0,
+ })
}
fn destination(
@@ -514,13 +521,18 @@ mod tests {
}
}
for now in (0..=900_000).step_by(100) {
- crate::frame(&mut engine, now).unwrap();
+ let frame = crate::frame(&mut engine, now).unwrap();
let loaded = engine.loaded.as_ref().unwrap();
if let Some(handle) = loaded.object_drafts[start..end].iter().find_map(|draft| {
(draft.unit_dat_header_flags == Some(0x8000_0010))
.then(|| handle_by_original_id(&engine.world, draft.original_id.unwrap()))
.flatten()
}) {
+ assert!(frame
+ .constructed_buildings
+ .iter()
+ .any(|building| building.handle == handle));
+ assert!(frame.snapshot.objects.contains(&handle));
assert_eq!(
identity_metadata(&engine.world, handle).unwrap().owner_id,
Some(OwnerId(1))
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 3b177b0a..312774ff 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -1411,6 +1411,8 @@ pub struct FrameResult {
pub autodemo_reinforcement_unavailable: usize,
/// Robot completed by a player factory order on this tick.
pub produced_unit: Option<SpawnedUnit>,
+ /// Buildings completed by scripted construction on this tick.
+ pub constructed_buildings: Vec<SpawnedUnit>,
/// Diagnostic for a production order whose unit could not be created.
pub production_failure: Option<String>,
/// Technology completed by a player laboratory order on this tick.
@@ -2949,7 +2951,10 @@ pub fn step_headless(
.loaded
.as_mut()
.and_then(|state| state.tick_mission_event(&engine.world, queue_time_ms));
- let clan_notices = clan_ai_events::tick(engine, queue_time_ms);
+ let (clan_notices, constructed_buildings) = clan_ai_events::tick(engine, queue_time_ms);
+ if !constructed_buildings.is_empty() {
+ snapshot = fparkan_world::world_snapshot(&engine.world, snapshot.events);
+ }
let researched_component = engine
.loaded
.as_mut()
@@ -2963,6 +2968,7 @@ pub fn step_headless(
autodemo_reinforcements,
autodemo_reinforcement_unavailable,
produced_unit,
+ constructed_buildings,
production_failure,
researched_component,
player_footstep: None,
diff --git a/docs/tomes/06-behavior.md b/docs/tomes/06-behavior.md
index 59620fd4..61490626 100644
--- a/docs/tomes/06-behavior.md
+++ b/docs/tomes/06-behavior.md
@@ -777,8 +777,9 @@ RVA `0x28800` проверяет детали и считает цену. Ког
В FParkan сценарий этой миссии со штатного старта уже ставит завод и
лабораторию. Готовое здание получает контроллер, запас руды и логический
ID, а завод входит в список производства и принимает заказ транспортника.
-Резервные модели будущих зданий не вырезают фундаменты в стартовом рельефе.
-Перестройка рельефа при их появлении ещё открыта.
+В кадре завершения стройки подготовленная модель занимает площадку, и её
+коллизия становится доступна игроку. Вырезание подземной части фундамента
+при завершении стройки ещё открыто.
### Первый запуск сценария