Ground named cargo price event descriptors
This commit is contained in:
parent
6b8f849731
commit
09ccc77a45
13 changed files with 1281 additions and 598 deletions
|
|
@ -1463,13 +1463,16 @@ fn lower_contextual_cargo_price_effect(
|
|||
let Some(value) = u32::try_from(row.raw_scalar_value).ok() else {
|
||||
return Ok(None);
|
||||
};
|
||||
if row.descriptor_id != 105 {
|
||||
let target = if row.descriptor_id == 105 {
|
||||
RuntimeCargoPriceTarget::All
|
||||
} else if let Some(name) = row.recovered_cargo_label.as_deref() {
|
||||
RuntimeCargoPriceTarget::Named {
|
||||
name: name.to_string(),
|
||||
}
|
||||
} else {
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some(RuntimeEffect::SetCargoPriceOverride {
|
||||
target: RuntimeCargoPriceTarget::All,
|
||||
value,
|
||||
}))
|
||||
};
|
||||
Ok(Some(RuntimeEffect::SetCargoPriceOverride { target, value }))
|
||||
}
|
||||
|
||||
fn lower_contextual_world_scalar_override_effect(
|
||||
|
|
@ -3234,8 +3237,7 @@ fn real_grouped_row_is_unsupported_executable_descriptor_variant(
|
|||
!(row.row_shape == "scalar_assignment" && row.raw_scalar_value >= 0)
|
||||
}
|
||||
Some("cargo_price_scalar") => {
|
||||
row.descriptor_id == 105
|
||||
&& !(row.row_shape == "scalar_assignment" && row.raw_scalar_value >= 0)
|
||||
!(row.row_shape == "scalar_assignment" && row.raw_scalar_value >= 0)
|
||||
}
|
||||
Some("cargo_production_scalar") => {
|
||||
matches!(row.descriptor_id, 177 | 178 | 179 | 230..=240)
|
||||
|
|
@ -4997,12 +4999,22 @@ mod tests {
|
|||
descriptor_id: u32,
|
||||
value: i32,
|
||||
) -> crate::SmpLoadedPackedEventGroupedEffectRowSummary {
|
||||
let slot = descriptor_id.saturating_sub(105);
|
||||
let cargo_label =
|
||||
crate::smp::grounded_named_cargo_price_label(descriptor_id).map(ToString::to_string);
|
||||
let descriptor_label = cargo_label
|
||||
.as_deref()
|
||||
.map(|label| format!("{label} Price"))
|
||||
.unwrap_or_else(|| {
|
||||
format!(
|
||||
"Named Cargo Price Slot {}",
|
||||
descriptor_id.saturating_sub(105)
|
||||
)
|
||||
});
|
||||
crate::SmpLoadedPackedEventGroupedEffectRowSummary {
|
||||
group_index: 0,
|
||||
row_index: 0,
|
||||
descriptor_id,
|
||||
descriptor_label: Some(format!("Named Cargo Price Slot {slot}")),
|
||||
descriptor_label: Some(descriptor_label.clone()),
|
||||
target_mask_bits: Some(0x08),
|
||||
parameter_family: Some("cargo_price_scalar".to_string()),
|
||||
grouped_target_subject: None,
|
||||
|
|
@ -5017,10 +5029,10 @@ mod tests {
|
|||
value_word_0x16: 0,
|
||||
row_shape: "scalar_assignment".to_string(),
|
||||
semantic_family: Some("scalar_assignment".to_string()),
|
||||
semantic_preview: Some(format!("Set Named Cargo Price Slot {slot} to {value}")),
|
||||
semantic_preview: Some(format!("Set {descriptor_label} to {value}")),
|
||||
recovered_cargo_slot: None,
|
||||
recovered_cargo_class: None,
|
||||
recovered_cargo_label: None,
|
||||
recovered_cargo_label: cargo_label,
|
||||
recovered_locomotive_id: None,
|
||||
locomotive_name: None,
|
||||
notes: vec![
|
||||
|
|
@ -8457,7 +8469,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_named_cargo_price_rows_evidence_blocked() {
|
||||
fn imports_named_cargo_price_rows_when_binding_is_grounded() {
|
||||
let save_slice = SmpLoadedSaveSlice {
|
||||
file_extension_hint: Some("gms".to_string()),
|
||||
container_profile_family: Some("rt3-classic-save-container-v1".to_string()),
|
||||
|
|
@ -8487,13 +8499,13 @@ mod tests {
|
|||
live_record_count: 1,
|
||||
live_entry_ids: vec![39],
|
||||
decoded_record_count: 1,
|
||||
imported_runtime_record_count: 0,
|
||||
imported_runtime_record_count: 1,
|
||||
records: vec![crate::SmpLoadedPackedEventRecordSummary {
|
||||
record_index: 0,
|
||||
live_entry_id: 39,
|
||||
payload_offset: Some(0x7202),
|
||||
payload_len: Some(96),
|
||||
decode_status: "parity_only".to_string(),
|
||||
decode_status: "executable".to_string(),
|
||||
payload_family: "real_packed_v1".to_string(),
|
||||
trigger_kind: Some(7),
|
||||
active: None,
|
||||
|
|
@ -8507,30 +8519,47 @@ mod tests {
|
|||
grouped_effect_row_counts: vec![1, 0, 0, 0],
|
||||
grouped_effect_rows: vec![real_named_cargo_price_row(106, 140)],
|
||||
decoded_conditions: Vec::new(),
|
||||
decoded_actions: vec![],
|
||||
executable_import_ready: false,
|
||||
notes: vec!["named cargo price descriptors remain evidence-blocked until cargo ordering is pinned"
|
||||
.to_string()],
|
||||
decoded_actions: vec![RuntimeEffect::SetCargoPriceOverride {
|
||||
target: RuntimeCargoPriceTarget::Named {
|
||||
name: "Alcohol".to_string(),
|
||||
},
|
||||
value: 140,
|
||||
}],
|
||||
executable_import_ready: true,
|
||||
notes: vec![
|
||||
"named cargo price descriptors now import through named cargo overrides"
|
||||
.to_string(),
|
||||
],
|
||||
}],
|
||||
}),
|
||||
notes: vec![],
|
||||
};
|
||||
|
||||
let import = project_save_slice_to_runtime_state_import(
|
||||
let mut import = project_save_slice_to_runtime_state_import(
|
||||
&save_slice,
|
||||
"packed-events-named-cargo-price-parity",
|
||||
"packed-events-named-cargo-price-import",
|
||||
None,
|
||||
)
|
||||
.expect("save slice should project");
|
||||
|
||||
assert!(import.state.event_runtime_records.is_empty());
|
||||
assert_eq!(import.state.event_runtime_records.len(), 1);
|
||||
execute_step_command(
|
||||
&mut import.state,
|
||||
&StepCommand::ServiceTriggerKind { trigger_kind: 7 },
|
||||
)
|
||||
.expect("named cargo price runtime record should run");
|
||||
|
||||
assert_eq!(
|
||||
import.state.named_cargo_price_overrides.get("Alcohol"),
|
||||
Some(&140)
|
||||
);
|
||||
assert_eq!(
|
||||
import
|
||||
.state
|
||||
.packed_event_collection
|
||||
.as_ref()
|
||||
.and_then(|summary| summary.records[0].import_outcome.as_deref()),
|
||||
Some("blocked_evidence_blocked_descriptor")
|
||||
Some("imported")
|
||||
);
|
||||
assert_eq!(
|
||||
import
|
||||
|
|
@ -8539,7 +8568,7 @@ mod tests {
|
|||
.as_ref()
|
||||
.and_then(|summary| summary.records[0].grouped_effect_rows.first())
|
||||
.and_then(|row| row.descriptor_label.as_deref()),
|
||||
Some("Named Cargo Price Slot 1")
|
||||
Some("Alcohol Price")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue