aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/autodemo.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-25 18:41:17 +0300
committerValentin Popov <valentin@popov.link>2026-11-25 18:41:17 +0300
commit85474bcd60f66b610985c90a697351837208528b (patch)
tree34f18cd85dac1f85efbeaba15926ba9fb2ec3bb5 /crates/fparkan-runtime/src/autodemo.rs
parentd4e008fe33337494c0a28d9e35da9986a7dd42c7 (diff)
downloadfparkan-85474bcd60f66b610985c90a697351837208528b.tar.xz
fparkan-85474bcd60f66b610985c90a697351837208528b.zip
fix(ai): advance clan cycles when units register
Advance the signed AI deadline by 1400 ms when an active clan receives a new unit. Connect production, construction, mines, reinforcements and ownership transfers through the shared spawn path. Preserve negative deadlines and count registration notifications per clan. Move the common spawn code and result type out of AutoDemo without changing its public API. Native ai.dll calls cover duplicate and missing IDs, the disabled guard, both registration kinds, negative deadlines and unchanged RNG. A live original warbot registration confirms the same advance. Workspace checks, the licensed stock factory timing test and all 29 900-second reports pass; a stock mission-28 window runs through successive factory outputs. Initial clock phase, complete RNG ordering and full G7 chronology remain open.
Diffstat (limited to 'crates/fparkan-runtime/src/autodemo.rs')
-rw-r--r--crates/fparkan-runtime/src/autodemo.rs61
1 files changed, 2 insertions, 59 deletions
diff --git a/crates/fparkan-runtime/src/autodemo.rs b/crates/fparkan-runtime/src/autodemo.rs
index 15338b0f..fe0bfd19 100644
--- a/crates/fparkan-runtime/src/autodemo.rs
+++ b/crates/fparkan-runtime/src/autodemo.rs
@@ -2,14 +2,14 @@ use super::{
component_cockpit, mission_object_handle, normalize_engine_path, read_vfs, Engine, EngineError,
MissionControlDeviceTableState, MissionMode, StartingCockpit, World, WorldSnapshot,
};
+use crate::unit_spawn::{spawn_prepared_unit, SpawnedUnit};
use fparkan_path::{normalize_relative, NormalizedPath, PathPolicy};
use fparkan_prototype::decode_unit_dat;
use fparkan_render::{LegacyIron3dEulerTransform, RawCameraTransform};
use fparkan_terrain::{SurfaceQuery, TerrainWorld};
use fparkan_vfs::{Vfs, VfsError};
use fparkan_world::{
- construct_replacement, handle_by_original_id, identity_metadata, register_object, set_owner,
- set_transform, transform_state, ObjectDraft, ObjectHandle, OwnerId, TransformState,
+ handle_by_original_id, identity_metadata, transform_state, ObjectHandle, OwnerId,
};
use std::sync::Arc;
@@ -47,17 +47,6 @@ pub(super) struct LiveReinforcements {
controls: Vec<MissionControlDeviceTableState>,
}
-/// A reserve model activated with a newly registered world object.
-#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-pub struct SpawnedUnit {
- /// Prepared scene object index.
- pub object_index: usize,
- /// New world handle.
- pub handle: ObjectHandle,
- /// Clan receiving the replacement.
- pub clan: u16,
-}
-
/// A unit created by AutoDemo's replacement policy.
pub type AutoDemoReinforcement = SpawnedUnit;
@@ -175,52 +164,6 @@ impl LiveReinforcements {
}
}
-pub(super) fn spawn_prepared_unit(
- world: &mut World,
- mission: &mut super::LoadedMissionState,
- index: usize,
- clan: u16,
- position: [f32; 3],
- mut table: MissionControlDeviceTableState,
-) -> Result<ObjectHandle, EngineError> {
- let draft = &mission.object_drafts[index];
- let handle = construct_replacement(
- world,
- ObjectDraft {
- original_id: draft.original_id,
- },
- )?;
- let pose = TransformState {
- position: position.map(f32::to_bits),
- orientation: draft.orientation_raw.map(f32::to_bits),
- scale: draft.scale.map(f32::to_bits),
- };
- if let Err(error) = set_transform(world, handle, pose)
- .and_then(|()| set_owner(world, handle, Some(OwnerId(clan))))
- .and_then(|()| register_object(world, handle))
- {
- fparkan_world::request_delete(world, handle)?;
- return Err(error.into());
- }
- mission
- .control_device_tables
- .retain(|table| transform_state(world, table.handle).is_ok());
- mission
- .behavior_control_groupings
- .retain(|group| transform_state(world, group.handle).is_ok());
- table.handle = handle;
- mission
- .behavior_control_groupings
- .push(super::project_mission_behavior_control_grouping(&table));
- mission.control_device_tables.push(table);
- mission.mission_events.register_unit(
- world,
- handle,
- draft.unit_dat_header_flags.expect("mobile reserve"),
- );
- Ok(handle)
-}
-
pub(super) fn plan_reinforcements(
vfs: &Arc<dyn Vfs>,
mission: &super::MissionDocument,