Rehost world locomotive policy owner state

This commit is contained in:
Jan Petykiewicz 2026-04-18 06:51:22 -07:00
commit 95215d836e
11 changed files with 536 additions and 6 deletions

View file

@ -2289,6 +2289,40 @@ pub struct SmpLoadedWorldFinanceNeighborhoodState {
pub value_f32_text: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpLoadedWorldLocomotivePolicyState {
pub source_kind: String,
pub semantic_family: String,
#[serde(default)]
pub selected_year_gap_scalar_raw_u32: Option<u32>,
#[serde(default)]
pub selected_year_gap_scalar_raw_hex: Option<String>,
#[serde(default)]
pub selected_year_gap_scalar_value_f32_text: Option<String>,
#[serde(default)]
pub linked_site_removal_follow_on_gate_raw_u8: Option<u8>,
#[serde(default)]
pub linked_site_removal_follow_on_gate_raw_hex: Option<String>,
#[serde(default)]
pub all_steam_locomotives_available_raw_u8: Option<u8>,
#[serde(default)]
pub all_steam_locomotives_available_raw_hex: Option<String>,
#[serde(default)]
pub all_diesel_locomotives_available_raw_u8: Option<u8>,
#[serde(default)]
pub all_diesel_locomotives_available_raw_hex: Option<String>,
#[serde(default)]
pub all_electric_locomotives_available_raw_u8: Option<u8>,
#[serde(default)]
pub all_electric_locomotives_available_raw_hex: Option<String>,
#[serde(default)]
pub cached_available_locomotive_rating_raw_u32: Option<u32>,
#[serde(default)]
pub cached_available_locomotive_rating_raw_hex: Option<String>,
#[serde(default)]
pub cached_available_locomotive_rating_value_f32_text: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpLoadedCompanyRosterEntry {
pub company_id: u32,
@ -2699,6 +2733,8 @@ pub struct SmpLoadedSaveSlice {
#[serde(default)]
pub world_finance_neighborhood_state: Option<SmpLoadedWorldFinanceNeighborhoodState>,
#[serde(default)]
pub world_locomotive_policy_state: Option<SmpLoadedWorldLocomotivePolicyState>,
#[serde(default)]
pub company_roster: Option<SmpLoadedCompanyRoster>,
#[serde(default)]
pub chairman_profile_table: Option<SmpLoadedChairmanProfileTable>,
@ -2892,6 +2928,10 @@ pub fn load_save_slice_from_report(
.save_world_finance_neighborhood_probe
.as_ref()
.map(derive_loaded_world_finance_neighborhood_state_from_probe);
let world_locomotive_policy_state = report
.locomotive_policy_neighborhood_probe
.as_ref()
.map(derive_loaded_world_locomotive_policy_state_from_probe);
let company_roster = report.save_company_roster_probe.clone().or_else(|| {
report
.save_world_selection_context_probe
@ -3028,6 +3068,7 @@ pub fn load_save_slice_from_report(
world_issue_37_state,
world_economic_tuning_state,
world_finance_neighborhood_state,
world_locomotive_policy_state,
company_roster,
chairman_profile_table,
special_conditions_table,
@ -3585,6 +3626,52 @@ fn derive_loaded_world_finance_neighborhood_state_from_probe(
}
}
fn derive_loaded_world_locomotive_policy_state_from_probe(
probe: &SmpLocomotivePolicyNeighborhoodProbe,
) -> SmpLoadedWorldLocomotivePolicyState {
let field_by_name = |name: &str| {
probe
.grounded_field_observations
.iter()
.find(|field| field.field_name == name)
};
let selected_year_gap_scalar = field_by_name("selected-year bucket companion scalar");
let linked_site_gate = field_by_name("linked-site removal follow-on gate");
let all_steam = field_by_name("All Steam Locos Avail.");
let all_diesel = field_by_name("All Diesel Locos Avail.");
let all_electric = field_by_name("All Electric Locos Avail.");
let cached_available_rating = field_by_name("cached available-locomotive rating");
SmpLoadedWorldLocomotivePolicyState {
source_kind: probe.source_kind.clone(),
semantic_family: "world-locomotive-policy".to_string(),
selected_year_gap_scalar_raw_u32: selected_year_gap_scalar
.and_then(|field| field.value_u32),
selected_year_gap_scalar_raw_hex: selected_year_gap_scalar
.and_then(|field| field.value_u32_hex.clone()),
selected_year_gap_scalar_value_f32_text: selected_year_gap_scalar
.and_then(|field| field.probable_f32_le.clone()),
linked_site_removal_follow_on_gate_raw_u8: linked_site_gate
.and_then(|field| field.value_u8),
linked_site_removal_follow_on_gate_raw_hex: linked_site_gate
.and_then(|field| field.value_u8_hex.clone()),
all_steam_locomotives_available_raw_u8: all_steam.and_then(|field| field.value_u8),
all_steam_locomotives_available_raw_hex: all_steam
.and_then(|field| field.value_u8_hex.clone()),
all_diesel_locomotives_available_raw_u8: all_diesel.and_then(|field| field.value_u8),
all_diesel_locomotives_available_raw_hex: all_diesel
.and_then(|field| field.value_u8_hex.clone()),
all_electric_locomotives_available_raw_u8: all_electric.and_then(|field| field.value_u8),
all_electric_locomotives_available_raw_hex: all_electric
.and_then(|field| field.value_u8_hex.clone()),
cached_available_locomotive_rating_raw_u32: cached_available_rating
.and_then(|field| field.value_u32),
cached_available_locomotive_rating_raw_hex: cached_available_rating
.and_then(|field| field.value_u32_hex.clone()),
cached_available_locomotive_rating_value_f32_text: cached_available_rating
.and_then(|field| field.probable_f32_le.clone()),
}
}
fn derive_selection_only_company_roster_from_save_world_probe(
probe: &SmpSaveWorldSelectionContextProbe,
header_probe: Option<&SmpSaveTaggedCollectionHeaderProbe>,