Execute recovered world scalar event descriptors

This commit is contained in:
Jan Petykiewicz 2026-04-16 11:39:59 -07:00
commit 13c7268b0d
23 changed files with 675 additions and 98 deletions

View file

@ -495,9 +495,20 @@ fn apply_runtime_effects(
.named_locomotive_availability
.insert(name.clone(), u32::from(*value));
}
RuntimeEffect::SetNamedLocomotiveAvailabilityValue { name, value } => {
state
.named_locomotive_availability
.insert(name.clone(), *value);
}
RuntimeEffect::SetNamedLocomotiveCost { name, value } => {
state.named_locomotive_cost.insert(name.clone(), *value);
}
RuntimeEffect::SetCargoProductionSlot { slot, value } => {
state.cargo_production_overrides.insert(*slot, *value);
}
RuntimeEffect::SetTerritoryAccessCost { value } => {
state.world_restore.territory_access_cost = Some(*value);
}
RuntimeEffect::SetSpecialCondition { label, value } => {
state.special_conditions.insert(label.clone(), *value);
}
@ -1169,6 +1180,7 @@ mod tests {
candidate_availability: BTreeMap::new(),
named_locomotive_availability: BTreeMap::new(),
named_locomotive_cost: BTreeMap::new(),
cargo_production_overrides: BTreeMap::new(),
special_conditions: BTreeMap::new(),
service_state: RuntimeServiceState::default(),
}
@ -1457,6 +1469,80 @@ mod tests {
assert_eq!(result.service_events[0].applied_effect_count, 2);
}
#[test]
fn applies_scalar_named_locomotive_availability_effects() {
let mut state = RuntimeState {
event_runtime_records: vec![RuntimeEventRecord {
record_id: 12,
trigger_kind: 7,
active: true,
service_count: 0,
marks_collection_dirty: false,
one_shot: false,
has_fired: false,
conditions: Vec::new(),
effects: vec![
RuntimeEffect::SetNamedLocomotiveAvailabilityValue {
name: "Big Boy".to_string(),
value: 42,
},
RuntimeEffect::SetNamedLocomotiveAvailabilityValue {
name: "GP7".to_string(),
value: 7,
},
],
}],
..state()
};
let result = execute_step_command(
&mut state,
&StepCommand::ServiceTriggerKind { trigger_kind: 7 },
)
.expect("scalar named locomotive availability effects should succeed");
assert_eq!(
state.named_locomotive_availability.get("Big Boy"),
Some(&42)
);
assert_eq!(state.named_locomotive_availability.get("GP7"), Some(&7));
assert_eq!(result.service_events[0].applied_effect_count, 2);
}
#[test]
fn applies_world_scalar_override_effects() {
let mut state = RuntimeState {
event_runtime_records: vec![RuntimeEventRecord {
record_id: 13,
trigger_kind: 7,
active: true,
service_count: 0,
marks_collection_dirty: false,
one_shot: false,
has_fired: false,
conditions: Vec::new(),
effects: vec![
RuntimeEffect::SetCargoProductionSlot {
slot: 1,
value: 125,
},
RuntimeEffect::SetTerritoryAccessCost { value: 750000 },
],
}],
..state()
};
let result = execute_step_command(
&mut state,
&StepCommand::ServiceTriggerKind { trigger_kind: 7 },
)
.expect("world scalar override effects should succeed");
assert_eq!(state.cargo_production_overrides.get(&1), Some(&125));
assert_eq!(state.world_restore.territory_access_cost, Some(750000));
assert_eq!(result.service_events[0].applied_effect_count, 2);
}
#[test]
fn resolves_symbolic_company_targets() {
let mut state = RuntimeState {