Execute real packed event world and train descriptors
This commit is contained in:
parent
ca208f74e0
commit
e481274243
31 changed files with 3287 additions and 206 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -44,7 +44,7 @@ pub use runtime::{
|
|||
RuntimePackedEventRecordSummary, RuntimePackedEventTextBandSummary, RuntimePlayer,
|
||||
RuntimePlayerConditionTestScope, RuntimePlayerTarget, RuntimeSaveProfileState,
|
||||
RuntimeServiceState, RuntimeState, RuntimeTerritory, RuntimeTerritoryMetric,
|
||||
RuntimeTerritoryTarget, RuntimeTrackMetric, RuntimeTrackPieceCounts,
|
||||
RuntimeTerritoryTarget, RuntimeTrackMetric, RuntimeTrackPieceCounts, RuntimeTrain,
|
||||
RuntimeWorldRestoreState,
|
||||
};
|
||||
pub use smp::{
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
|
|||
|
|
@ -83,6 +83,24 @@ pub struct RuntimePlayer {
|
|||
pub controller_kind: RuntimeCompanyControllerKind,
|
||||
}
|
||||
|
||||
fn runtime_train_default_active() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RuntimeTrain {
|
||||
pub train_id: u32,
|
||||
pub owner_company_id: u32,
|
||||
#[serde(default)]
|
||||
pub territory_id: Option<u32>,
|
||||
#[serde(default)]
|
||||
pub locomotive_name: Option<String>,
|
||||
#[serde(default = "runtime_train_default_active")]
|
||||
pub active: bool,
|
||||
#[serde(default)]
|
||||
pub retired: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
pub enum RuntimeCompanyTarget {
|
||||
|
|
@ -213,6 +231,9 @@ pub enum RuntimeEffect {
|
|||
key: String,
|
||||
value: bool,
|
||||
},
|
||||
SetEconomicStatusCode {
|
||||
value: i32,
|
||||
},
|
||||
SetCompanyCash {
|
||||
target: RuntimeCompanyTarget,
|
||||
value: i64,
|
||||
|
|
@ -221,6 +242,9 @@ pub enum RuntimeEffect {
|
|||
target: RuntimePlayerTarget,
|
||||
value: i64,
|
||||
},
|
||||
ConfiscateCompanyAssets {
|
||||
target: RuntimeCompanyTarget,
|
||||
},
|
||||
DeactivateCompany {
|
||||
target: RuntimeCompanyTarget,
|
||||
},
|
||||
|
|
@ -228,6 +252,14 @@ pub enum RuntimeEffect {
|
|||
target: RuntimeCompanyTarget,
|
||||
value: Option<u32>,
|
||||
},
|
||||
RetireTrains {
|
||||
#[serde(default)]
|
||||
company_target: Option<RuntimeCompanyTarget>,
|
||||
#[serde(default)]
|
||||
territory_target: Option<RuntimeTerritoryTarget>,
|
||||
#[serde(default)]
|
||||
locomotive_name: Option<String>,
|
||||
},
|
||||
AdjustCompanyCash {
|
||||
target: RuntimeCompanyTarget,
|
||||
delta: i64,
|
||||
|
|
@ -527,6 +559,8 @@ pub struct RuntimeWorldRestoreState {
|
|||
#[serde(default)]
|
||||
pub ai_ignore_territories_at_startup_enabled: Option<bool>,
|
||||
#[serde(default)]
|
||||
pub economic_status_code: Option<i32>,
|
||||
#[serde(default)]
|
||||
pub absolute_counter_restore_kind: Option<String>,
|
||||
#[serde(default)]
|
||||
pub absolute_counter_adjustment_context: Option<String>,
|
||||
|
|
@ -552,6 +586,8 @@ pub struct RuntimeState {
|
|||
#[serde(default)]
|
||||
pub selected_player_id: Option<u32>,
|
||||
#[serde(default)]
|
||||
pub trains: Vec<RuntimeTrain>,
|
||||
#[serde(default)]
|
||||
pub territories: Vec<RuntimeTerritory>,
|
||||
#[serde(default)]
|
||||
pub company_territory_track_piece_counts: Vec<RuntimeCompanyTerritoryTrackPieceCount>,
|
||||
|
|
@ -639,6 +675,42 @@ impl RuntimeState {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut seen_train_ids = BTreeSet::new();
|
||||
for train in &self.trains {
|
||||
if !seen_train_ids.insert(train.train_id) {
|
||||
return Err(format!("duplicate train_id {}", train.train_id));
|
||||
}
|
||||
if !seen_company_ids.contains(&train.owner_company_id) {
|
||||
return Err(format!(
|
||||
"train_id {} references unknown owner_company_id {}",
|
||||
train.train_id, train.owner_company_id
|
||||
));
|
||||
}
|
||||
if let Some(territory_id) = train.territory_id {
|
||||
if !seen_territory_ids.contains(&territory_id) {
|
||||
return Err(format!(
|
||||
"train_id {} references unknown territory_id {}",
|
||||
train.train_id, territory_id
|
||||
));
|
||||
}
|
||||
}
|
||||
if train.retired && train.active {
|
||||
return Err(format!(
|
||||
"train_id {} cannot be active and retired at the same time",
|
||||
train.train_id
|
||||
));
|
||||
}
|
||||
if train
|
||||
.locomotive_name
|
||||
.as_deref()
|
||||
.is_some_and(|value| value.trim().is_empty())
|
||||
{
|
||||
return Err(format!(
|
||||
"train_id {} has an empty locomotive_name",
|
||||
train.train_id
|
||||
));
|
||||
}
|
||||
}
|
||||
for entry in &self.company_territory_track_piece_counts {
|
||||
if !seen_company_ids.contains(&entry.company_id) {
|
||||
return Err(format!(
|
||||
|
|
@ -1009,7 +1081,9 @@ fn validate_runtime_effect(
|
|||
return Err("key must not be empty".to_string());
|
||||
}
|
||||
}
|
||||
RuntimeEffect::SetEconomicStatusCode { .. } => {}
|
||||
RuntimeEffect::SetCompanyCash { target, .. }
|
||||
| RuntimeEffect::ConfiscateCompanyAssets { target }
|
||||
| RuntimeEffect::DeactivateCompany { target }
|
||||
| RuntimeEffect::SetCompanyTrackLayingCapacity { target, .. }
|
||||
| RuntimeEffect::AdjustCompanyCash { target, .. }
|
||||
|
|
@ -1019,6 +1093,30 @@ fn validate_runtime_effect(
|
|||
RuntimeEffect::SetPlayerCash { target, .. } => {
|
||||
validate_player_target(target, valid_player_ids)?;
|
||||
}
|
||||
RuntimeEffect::RetireTrains {
|
||||
company_target,
|
||||
territory_target,
|
||||
locomotive_name,
|
||||
} => {
|
||||
if let Some(company_target) = company_target {
|
||||
validate_company_target(company_target, valid_company_ids)?;
|
||||
}
|
||||
if let Some(territory_target) = territory_target {
|
||||
validate_territory_target(territory_target, valid_territory_ids)?;
|
||||
}
|
||||
if company_target.is_none() && territory_target.is_none() && locomotive_name.is_none() {
|
||||
return Err(
|
||||
"retire_trains requires at least one company_target, territory_target, or locomotive_name filter"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if locomotive_name
|
||||
.as_deref()
|
||||
.is_some_and(|value| value.trim().is_empty())
|
||||
{
|
||||
return Err("locomotive_name must not be empty".to_string());
|
||||
}
|
||||
}
|
||||
RuntimeEffect::SetCandidateAvailability { name, .. } => {
|
||||
if name.trim().is_empty() {
|
||||
return Err("name must not be empty".to_string());
|
||||
|
|
@ -1054,10 +1152,10 @@ fn validate_event_record_template(
|
|||
for (condition_index, condition) in record.conditions.iter().enumerate() {
|
||||
validate_runtime_condition(condition, valid_company_ids, valid_territory_ids).map_err(
|
||||
|err| {
|
||||
format!(
|
||||
"template record_id={}.conditions[{condition_index}] {err}",
|
||||
record.record_id
|
||||
)
|
||||
format!(
|
||||
"template record_id={}.conditions[{condition_index}] {err}",
|
||||
record.record_id
|
||||
)
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
|
@ -1092,9 +1190,7 @@ fn validate_runtime_condition(
|
|||
validate_territory_target(target, valid_territory_ids)
|
||||
}
|
||||
RuntimeCondition::CompanyTerritoryNumericThreshold {
|
||||
target,
|
||||
territory,
|
||||
..
|
||||
target, territory, ..
|
||||
} => {
|
||||
validate_company_target(target, valid_company_ids)?;
|
||||
validate_territory_target(territory, valid_territory_ids)
|
||||
|
|
@ -1216,6 +1312,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
@ -1255,6 +1352,7 @@ mod tests {
|
|||
disable_train_crashes_enabled: Some(false),
|
||||
disable_train_crashes_and_breakdowns_enabled: Some(false),
|
||||
ai_ignore_territories_at_startup_enabled: Some(false),
|
||||
economic_status_code: None,
|
||||
absolute_counter_restore_kind: Some(
|
||||
"mode-adjusted-selected-year-lane".to_string(),
|
||||
),
|
||||
|
|
@ -1267,6 +1365,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
@ -1306,6 +1405,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
@ -1358,6 +1458,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
@ -1410,6 +1511,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: Some(RuntimePackedEventCollectionSummary {
|
||||
|
|
@ -1513,6 +1615,7 @@ mod tests {
|
|||
selected_company_id: Some(2),
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
@ -1552,6 +1655,209 @@ mod tests {
|
|||
selected_company_id: Some(1),
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
event_runtime_records: Vec::new(),
|
||||
candidate_availability: BTreeMap::new(),
|
||||
special_conditions: BTreeMap::new(),
|
||||
service_state: RuntimeServiceState::default(),
|
||||
};
|
||||
|
||||
assert!(state.validate().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_duplicate_train_ids() {
|
||||
let state = RuntimeState {
|
||||
calendar: CalendarPoint {
|
||||
year: 1830,
|
||||
month_slot: 0,
|
||||
phase_slot: 0,
|
||||
tick_slot: 0,
|
||||
},
|
||||
world_flags: BTreeMap::new(),
|
||||
save_profile: RuntimeSaveProfileState::default(),
|
||||
world_restore: RuntimeWorldRestoreState::default(),
|
||||
metadata: BTreeMap::new(),
|
||||
companies: vec![RuntimeCompany {
|
||||
company_id: 1,
|
||||
current_cash: 100,
|
||||
debt: 0,
|
||||
credit_rating_score: None,
|
||||
prime_rate: None,
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
active: true,
|
||||
available_track_laying_capacity: None,
|
||||
controller_kind: RuntimeCompanyControllerKind::Human,
|
||||
}],
|
||||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: vec![
|
||||
RuntimeTrain {
|
||||
train_id: 7,
|
||||
owner_company_id: 1,
|
||||
territory_id: None,
|
||||
locomotive_name: Some("Mikado".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
},
|
||||
RuntimeTrain {
|
||||
train_id: 7,
|
||||
owner_company_id: 1,
|
||||
territory_id: None,
|
||||
locomotive_name: Some("Orca".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
},
|
||||
],
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
event_runtime_records: Vec::new(),
|
||||
candidate_availability: BTreeMap::new(),
|
||||
special_conditions: BTreeMap::new(),
|
||||
service_state: RuntimeServiceState::default(),
|
||||
};
|
||||
|
||||
assert!(state.validate().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_train_with_unknown_owner_company() {
|
||||
let state = RuntimeState {
|
||||
calendar: CalendarPoint {
|
||||
year: 1830,
|
||||
month_slot: 0,
|
||||
phase_slot: 0,
|
||||
tick_slot: 0,
|
||||
},
|
||||
world_flags: BTreeMap::new(),
|
||||
save_profile: RuntimeSaveProfileState::default(),
|
||||
world_restore: RuntimeWorldRestoreState::default(),
|
||||
metadata: BTreeMap::new(),
|
||||
companies: vec![RuntimeCompany {
|
||||
company_id: 1,
|
||||
current_cash: 100,
|
||||
debt: 0,
|
||||
credit_rating_score: None,
|
||||
prime_rate: None,
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
active: true,
|
||||
available_track_laying_capacity: None,
|
||||
controller_kind: RuntimeCompanyControllerKind::Human,
|
||||
}],
|
||||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: vec![RuntimeTrain {
|
||||
train_id: 7,
|
||||
owner_company_id: 2,
|
||||
territory_id: None,
|
||||
locomotive_name: Some("Mikado".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
}],
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
event_runtime_records: Vec::new(),
|
||||
candidate_availability: BTreeMap::new(),
|
||||
special_conditions: BTreeMap::new(),
|
||||
service_state: RuntimeServiceState::default(),
|
||||
};
|
||||
|
||||
assert!(state.validate().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_train_with_unknown_territory() {
|
||||
let state = RuntimeState {
|
||||
calendar: CalendarPoint {
|
||||
year: 1830,
|
||||
month_slot: 0,
|
||||
phase_slot: 0,
|
||||
tick_slot: 0,
|
||||
},
|
||||
world_flags: BTreeMap::new(),
|
||||
save_profile: RuntimeSaveProfileState::default(),
|
||||
world_restore: RuntimeWorldRestoreState::default(),
|
||||
metadata: BTreeMap::new(),
|
||||
companies: vec![RuntimeCompany {
|
||||
company_id: 1,
|
||||
current_cash: 100,
|
||||
debt: 0,
|
||||
credit_rating_score: None,
|
||||
prime_rate: None,
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
active: true,
|
||||
available_track_laying_capacity: None,
|
||||
controller_kind: RuntimeCompanyControllerKind::Human,
|
||||
}],
|
||||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: vec![RuntimeTrain {
|
||||
train_id: 7,
|
||||
owner_company_id: 1,
|
||||
territory_id: Some(9),
|
||||
locomotive_name: Some("Mikado".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
}],
|
||||
territories: vec![RuntimeTerritory {
|
||||
territory_id: 1,
|
||||
name: Some("Appalachia".to_string()),
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
}],
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
event_runtime_records: Vec::new(),
|
||||
candidate_availability: BTreeMap::new(),
|
||||
special_conditions: BTreeMap::new(),
|
||||
service_state: RuntimeServiceState::default(),
|
||||
};
|
||||
|
||||
assert!(state.validate().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_train_marked_active_and_retired() {
|
||||
let state = RuntimeState {
|
||||
calendar: CalendarPoint {
|
||||
year: 1830,
|
||||
month_slot: 0,
|
||||
phase_slot: 0,
|
||||
tick_slot: 0,
|
||||
},
|
||||
world_flags: BTreeMap::new(),
|
||||
save_profile: RuntimeSaveProfileState::default(),
|
||||
world_restore: RuntimeWorldRestoreState::default(),
|
||||
metadata: BTreeMap::new(),
|
||||
companies: vec![RuntimeCompany {
|
||||
company_id: 1,
|
||||
current_cash: 100,
|
||||
debt: 0,
|
||||
credit_rating_score: None,
|
||||
prime_rate: None,
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
active: true,
|
||||
available_track_laying_capacity: None,
|
||||
controller_kind: RuntimeCompanyControllerKind::Human,
|
||||
}],
|
||||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: vec![RuntimeTrain {
|
||||
train_id: 7,
|
||||
owner_company_id: 1,
|
||||
territory_id: None,
|
||||
locomotive_name: Some("Mikado".to_string()),
|
||||
active: true,
|
||||
retired: true,
|
||||
}],
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ use serde::{Deserialize, Serialize};
|
|||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::{
|
||||
RuntimeCompanyConditionTestScope, RuntimeCompanyMetric, RuntimeCompanyTarget,
|
||||
RuntimeCondition, RuntimeConditionComparator, RuntimeEffect, RuntimeEventRecordTemplate,
|
||||
RuntimeCompanyConditionTestScope, RuntimeCompanyMetric, RuntimeCompanyTarget, RuntimeCondition,
|
||||
RuntimeConditionComparator, RuntimeEffect, RuntimeEventRecordTemplate,
|
||||
RuntimePlayerConditionTestScope, RuntimePlayerTarget, RuntimeTerritoryMetric,
|
||||
RuntimeTerritoryTarget, RuntimeTrackMetric,
|
||||
};
|
||||
|
|
@ -154,14 +154,14 @@ const REAL_GROUPED_EFFECT_DESCRIPTOR_METADATA: [RealGroupedEffectDescriptorMetad
|
|||
label: "Economic Status",
|
||||
target_mask_bits: 0x08,
|
||||
parameter_family: "whole_game_state_enum",
|
||||
executable_in_runtime: false,
|
||||
executable_in_runtime: true,
|
||||
},
|
||||
RealGroupedEffectDescriptorMetadata {
|
||||
descriptor_id: 9,
|
||||
label: "Confiscate All",
|
||||
target_mask_bits: 0x01,
|
||||
parameter_family: "company_confiscation_variant",
|
||||
executable_in_runtime: false,
|
||||
executable_in_runtime: true,
|
||||
},
|
||||
RealGroupedEffectDescriptorMetadata {
|
||||
descriptor_id: 13,
|
||||
|
|
@ -175,7 +175,7 @@ const REAL_GROUPED_EFFECT_DESCRIPTOR_METADATA: [RealGroupedEffectDescriptorMetad
|
|||
label: "Retire Train",
|
||||
target_mask_bits: 0x0d,
|
||||
parameter_family: "company_or_territory_asset_toggle",
|
||||
executable_in_runtime: false,
|
||||
executable_in_runtime: true,
|
||||
},
|
||||
RealGroupedEffectDescriptorMetadata {
|
||||
descriptor_id: 16,
|
||||
|
|
@ -269,7 +269,9 @@ const REAL_ORDINARY_CONDITION_METADATA: [RealOrdinaryConditionMetadata; 22] = [
|
|||
RealOrdinaryConditionMetadata {
|
||||
raw_condition_id: 2316,
|
||||
label: "Territory Transition Track Pieces",
|
||||
metric: RealOrdinaryConditionMetric::Territory(RuntimeTerritoryMetric::TrackPiecesTransition),
|
||||
metric: RealOrdinaryConditionMetric::Territory(
|
||||
RuntimeTerritoryMetric::TrackPiecesTransition,
|
||||
),
|
||||
},
|
||||
RealOrdinaryConditionMetadata {
|
||||
raw_condition_id: 2317,
|
||||
|
|
@ -279,7 +281,9 @@ const REAL_ORDINARY_CONDITION_METADATA: [RealOrdinaryConditionMetadata; 22] = [
|
|||
RealOrdinaryConditionMetadata {
|
||||
raw_condition_id: 2318,
|
||||
label: "Territory Non-Electric Track Pieces",
|
||||
metric: RealOrdinaryConditionMetric::Territory(RuntimeTerritoryMetric::TrackPiecesNonElectric),
|
||||
metric: RealOrdinaryConditionMetric::Territory(
|
||||
RuntimeTerritoryMetric::TrackPiecesNonElectric,
|
||||
),
|
||||
},
|
||||
RealOrdinaryConditionMetadata {
|
||||
raw_condition_id: 2323,
|
||||
|
|
@ -2096,14 +2100,36 @@ fn parse_real_event_runtime_record_summary(
|
|||
)?);
|
||||
}
|
||||
}
|
||||
if let Some(control) = compact_control.as_ref() {
|
||||
for row in &mut grouped_effect_rows {
|
||||
if row.descriptor_id != 15
|
||||
|| row.row_shape != "bool_toggle"
|
||||
|| row.raw_scalar_value == 0
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let company_target_present = control
|
||||
.grouped_target_scope_ordinals_0x7fb
|
||||
.get(row.group_index)
|
||||
.copied()
|
||||
.and_then(real_grouped_company_target)
|
||||
.is_some();
|
||||
let territory_target_present = control
|
||||
.grouped_territory_selectors_0x80f
|
||||
.get(row.group_index)
|
||||
.is_some_and(|selector| *selector >= 0);
|
||||
if !company_target_present && !territory_target_present {
|
||||
row.notes
|
||||
.push("retire train row is missing company and territory scope".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let negative_sentinel_scope = compact_control.as_ref().and_then(|control| {
|
||||
derive_negative_sentinel_scope_summary(&standalone_condition_rows, control)
|
||||
});
|
||||
let decoded_conditions = decode_real_condition_rows(
|
||||
&standalone_condition_rows,
|
||||
negative_sentinel_scope.as_ref(),
|
||||
);
|
||||
let decoded_conditions =
|
||||
decode_real_condition_rows(&standalone_condition_rows, negative_sentinel_scope.as_ref());
|
||||
let decoded_actions = compact_control
|
||||
.as_ref()
|
||||
.map(|control| decode_real_grouped_effect_actions(&grouped_effect_rows, control))
|
||||
|
|
@ -2253,7 +2279,10 @@ fn parse_real_condition_row_summary(
|
|||
notes.push("condition row carries candidate-name side string".to_string());
|
||||
}
|
||||
if ordinary_metadata.is_none() && raw_condition_id >= 0 {
|
||||
notes.push("ordinary condition id is not yet recovered in the checked-in condition table".to_string());
|
||||
notes.push(
|
||||
"ordinary condition id is not yet recovered in the checked-in condition table"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
Some(SmpLoadedPackedEventConditionRowSummary {
|
||||
row_index,
|
||||
|
|
@ -2462,33 +2491,31 @@ fn decode_real_condition_row(
|
|||
let comparator = decode_real_condition_comparator(row.subtype)?;
|
||||
let value = decode_real_condition_threshold(&row.flag_bytes)?;
|
||||
match metadata.metric {
|
||||
RealOrdinaryConditionMetric::Company(metric) => Some(RuntimeCondition::CompanyNumericThreshold {
|
||||
target: RuntimeCompanyTarget::ConditionTrueCompany,
|
||||
metric,
|
||||
comparator,
|
||||
value,
|
||||
}),
|
||||
RealOrdinaryConditionMetric::Territory(metric) => {
|
||||
negative_sentinel_scope
|
||||
.filter(|scope| scope.territory_scope_selector_is_0x63)
|
||||
.map(|_| RuntimeCondition::TerritoryNumericThreshold {
|
||||
target: RuntimeTerritoryTarget::AllTerritories,
|
||||
metric,
|
||||
comparator,
|
||||
value,
|
||||
})
|
||||
}
|
||||
RealOrdinaryConditionMetric::CompanyTerritory(metric) => {
|
||||
negative_sentinel_scope
|
||||
.filter(|scope| scope.territory_scope_selector_is_0x63)
|
||||
.map(|_| RuntimeCondition::CompanyTerritoryNumericThreshold {
|
||||
target: RuntimeCompanyTarget::ConditionTrueCompany,
|
||||
territory: RuntimeTerritoryTarget::AllTerritories,
|
||||
metric,
|
||||
comparator,
|
||||
value,
|
||||
})
|
||||
RealOrdinaryConditionMetric::Company(metric) => {
|
||||
Some(RuntimeCondition::CompanyNumericThreshold {
|
||||
target: RuntimeCompanyTarget::ConditionTrueCompany,
|
||||
metric,
|
||||
comparator,
|
||||
value,
|
||||
})
|
||||
}
|
||||
RealOrdinaryConditionMetric::Territory(metric) => negative_sentinel_scope
|
||||
.filter(|scope| scope.territory_scope_selector_is_0x63)
|
||||
.map(|_| RuntimeCondition::TerritoryNumericThreshold {
|
||||
target: RuntimeTerritoryTarget::AllTerritories,
|
||||
metric,
|
||||
comparator,
|
||||
value,
|
||||
}),
|
||||
RealOrdinaryConditionMetric::CompanyTerritory(metric) => negative_sentinel_scope
|
||||
.filter(|scope| scope.territory_scope_selector_is_0x63)
|
||||
.map(|_| RuntimeCondition::CompanyTerritoryNumericThreshold {
|
||||
target: RuntimeCompanyTarget::ConditionTrueCompany,
|
||||
territory: RuntimeTerritoryTarget::AllTerritories,
|
||||
metric,
|
||||
comparator,
|
||||
value,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2616,6 +2643,24 @@ fn decode_real_grouped_effect_action(
|
|||
});
|
||||
}
|
||||
|
||||
if descriptor_metadata.executable_in_runtime
|
||||
&& descriptor_metadata.descriptor_id == 8
|
||||
&& row.row_shape == "scalar_assignment"
|
||||
{
|
||||
return Some(RuntimeEffect::SetEconomicStatusCode {
|
||||
value: row.raw_scalar_value,
|
||||
});
|
||||
}
|
||||
|
||||
if descriptor_metadata.executable_in_runtime
|
||||
&& descriptor_metadata.descriptor_id == 9
|
||||
&& row.row_shape == "bool_toggle"
|
||||
&& row.raw_scalar_value != 0
|
||||
{
|
||||
let target = real_grouped_company_target(target_scope_ordinal)?;
|
||||
return Some(RuntimeEffect::ConfiscateCompanyAssets { target });
|
||||
}
|
||||
|
||||
if descriptor_metadata.executable_in_runtime
|
||||
&& descriptor_metadata.descriptor_id == 13
|
||||
&& row.row_shape == "bool_toggle"
|
||||
|
|
@ -2637,6 +2682,30 @@ fn decode_real_grouped_effect_action(
|
|||
});
|
||||
}
|
||||
|
||||
if descriptor_metadata.executable_in_runtime
|
||||
&& descriptor_metadata.descriptor_id == 15
|
||||
&& row.row_shape == "bool_toggle"
|
||||
&& row.raw_scalar_value != 0
|
||||
{
|
||||
let company_target = real_grouped_company_target(target_scope_ordinal);
|
||||
let territory_target = compact_control
|
||||
.grouped_territory_selectors_0x80f
|
||||
.get(row.group_index)
|
||||
.copied()
|
||||
.filter(|selector| *selector >= 0)
|
||||
.map(|selector| RuntimeTerritoryTarget::Ids {
|
||||
ids: vec![selector as u32],
|
||||
});
|
||||
if company_target.is_none() && territory_target.is_none() {
|
||||
return None;
|
||||
}
|
||||
return Some(RuntimeEffect::RetireTrains {
|
||||
company_target,
|
||||
territory_target,
|
||||
locomotive_name: row.locomotive_name.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
|
|
@ -2808,10 +2877,13 @@ fn parse_optional_u16_len_prefixed_string(
|
|||
fn runtime_effect_supported_for_save_import(effect: &RuntimeEffect) -> bool {
|
||||
match effect {
|
||||
RuntimeEffect::SetWorldFlag { .. }
|
||||
| RuntimeEffect::SetEconomicStatusCode { .. }
|
||||
| RuntimeEffect::SetCandidateAvailability { .. }
|
||||
| RuntimeEffect::SetSpecialCondition { .. }
|
||||
| RuntimeEffect::ConfiscateCompanyAssets { .. }
|
||||
| RuntimeEffect::DeactivateCompany { .. }
|
||||
| RuntimeEffect::SetCompanyTrackLayingCapacity { .. }
|
||||
| RuntimeEffect::RetireTrains { .. }
|
||||
| RuntimeEffect::ActivateEventRecord { .. }
|
||||
| RuntimeEffect::DeactivateEventRecord { .. }
|
||||
| RuntimeEffect::RemoveEventRecord { .. } => true,
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
RuntimeCompanyControllerKind, RuntimeCompanyMetric, RuntimeCompanyTarget, RuntimeCondition,
|
||||
RuntimeConditionComparator, RuntimeEffect, RuntimeEventRecordTemplate, RuntimePlayerTarget,
|
||||
RuntimeState, RuntimeSummary, RuntimeTerritoryMetric, RuntimeTerritoryTarget,
|
||||
RuntimeTrackMetric, RuntimeTrackPieceCounts,
|
||||
calendar::BoundaryEventKind,
|
||||
RuntimeTrackMetric, RuntimeTrackPieceCounts, calendar::BoundaryEventKind,
|
||||
};
|
||||
|
||||
const PERIODIC_TRIGGER_KIND_ORDER: [u8; 6] = [1, 0, 3, 2, 5, 4];
|
||||
|
|
@ -312,6 +311,9 @@ fn apply_runtime_effects(
|
|||
RuntimeEffect::SetWorldFlag { key, value } => {
|
||||
state.world_flags.insert(key.clone(), *value);
|
||||
}
|
||||
RuntimeEffect::SetEconomicStatusCode { value } => {
|
||||
state.world_restore.economic_status_code = Some(*value);
|
||||
}
|
||||
RuntimeEffect::SetCompanyCash { target, value } => {
|
||||
let company_ids = resolve_company_target_ids(state, target, condition_context)?;
|
||||
for company_id in company_ids {
|
||||
|
|
@ -340,6 +342,28 @@ fn apply_runtime_effects(
|
|||
mutated_player_ids.insert(player_id);
|
||||
}
|
||||
}
|
||||
RuntimeEffect::ConfiscateCompanyAssets { target } => {
|
||||
let company_ids = resolve_company_target_ids(state, target, condition_context)?;
|
||||
for company_id in company_ids.iter().copied() {
|
||||
let company = state
|
||||
.companies
|
||||
.iter_mut()
|
||||
.find(|company| company.company_id == company_id)
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"missing company_id {company_id} while applying confiscate effect"
|
||||
)
|
||||
})?;
|
||||
company.current_cash = 0;
|
||||
company.debt = 0;
|
||||
company.active = false;
|
||||
mutated_company_ids.insert(company_id);
|
||||
if state.selected_company_id == Some(company_id) {
|
||||
state.selected_company_id = None;
|
||||
}
|
||||
}
|
||||
retire_matching_trains(&mut state.trains, Some(&company_ids), None, None);
|
||||
}
|
||||
RuntimeEffect::DeactivateCompany { target } => {
|
||||
let company_ids = resolve_company_target_ids(state, target, condition_context)?;
|
||||
for company_id in company_ids {
|
||||
|
|
@ -375,6 +399,26 @@ fn apply_runtime_effects(
|
|||
mutated_company_ids.insert(company_id);
|
||||
}
|
||||
}
|
||||
RuntimeEffect::RetireTrains {
|
||||
company_target,
|
||||
territory_target,
|
||||
locomotive_name,
|
||||
} => {
|
||||
let company_ids = company_target
|
||||
.as_ref()
|
||||
.map(|target| resolve_company_target_ids(state, target, condition_context))
|
||||
.transpose()?;
|
||||
let territory_ids = territory_target
|
||||
.as_ref()
|
||||
.map(|target| resolve_territory_target_ids(state, target))
|
||||
.transpose()?;
|
||||
retire_matching_trains(
|
||||
&mut state.trains,
|
||||
company_ids.as_ref(),
|
||||
territory_ids.as_ref(),
|
||||
locomotive_name.as_deref(),
|
||||
);
|
||||
}
|
||||
RuntimeEffect::AdjustCompanyCash { target, delta } => {
|
||||
let company_ids = resolve_company_target_ids(state, target, condition_context)?;
|
||||
for company_id in company_ids {
|
||||
|
|
@ -523,13 +567,17 @@ fn evaluate_record_conditions(
|
|||
let matching = resolved
|
||||
.into_iter()
|
||||
.filter(|company_id| {
|
||||
state.companies.iter().find(|company| company.company_id == *company_id).is_some_and(
|
||||
|company| compare_condition_value(
|
||||
company_metric_value(company, *metric),
|
||||
*comparator,
|
||||
*value,
|
||||
),
|
||||
)
|
||||
state
|
||||
.companies
|
||||
.iter()
|
||||
.find(|company| company.company_id == *company_id)
|
||||
.is_some_and(|company| {
|
||||
compare_condition_value(
|
||||
company_metric_value(company, *metric),
|
||||
*comparator,
|
||||
*value,
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect::<BTreeSet<_>>();
|
||||
if matching.is_empty() {
|
||||
|
|
@ -597,10 +645,7 @@ fn evaluate_record_conditions(
|
|||
}))
|
||||
}
|
||||
|
||||
fn intersect_company_matches(
|
||||
company_matches: &mut Option<BTreeSet<u32>>,
|
||||
next: BTreeSet<u32>,
|
||||
) {
|
||||
fn intersect_company_matches(company_matches: &mut Option<BTreeSet<u32>>, next: BTreeSet<u32>) {
|
||||
match company_matches {
|
||||
Some(existing) => {
|
||||
existing.retain(|company_id| next.contains(company_id));
|
||||
|
|
@ -790,7 +835,11 @@ fn resolve_player_target_ids(
|
|||
if condition_context.matching_player_ids.is_empty() {
|
||||
Err("target requires player condition-evaluation context".to_string())
|
||||
} else {
|
||||
Ok(condition_context.matching_player_ids.iter().copied().collect())
|
||||
Ok(condition_context
|
||||
.matching_player_ids
|
||||
.iter()
|
||||
.copied()
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -801,9 +850,11 @@ fn resolve_territory_target_ids(
|
|||
target: &RuntimeTerritoryTarget,
|
||||
) -> Result<Vec<u32>, String> {
|
||||
match target {
|
||||
RuntimeTerritoryTarget::AllTerritories => {
|
||||
Ok(state.territories.iter().map(|territory| territory.territory_id).collect())
|
||||
}
|
||||
RuntimeTerritoryTarget::AllTerritories => Ok(state
|
||||
.territories
|
||||
.iter()
|
||||
.map(|territory| territory.territory_id)
|
||||
.collect()),
|
||||
RuntimeTerritoryTarget::Ids { ids } => {
|
||||
let known_ids = state
|
||||
.territories
|
||||
|
|
@ -812,7 +863,9 @@ fn resolve_territory_target_ids(
|
|||
.collect::<BTreeSet<_>>();
|
||||
for territory_id in ids {
|
||||
if !known_ids.contains(territory_id) {
|
||||
return Err(format!("territory target references unknown territory_id {territory_id}"));
|
||||
return Err(format!(
|
||||
"territory target references unknown territory_id {territory_id}"
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(ids.clone())
|
||||
|
|
@ -832,9 +885,7 @@ fn company_metric_value(company: &crate::RuntimeCompany, metric: RuntimeCompanyM
|
|||
RuntimeCompanyMetric::TrackPiecesTransition => {
|
||||
i64::from(company.track_piece_counts.transition)
|
||||
}
|
||||
RuntimeCompanyMetric::TrackPiecesElectric => {
|
||||
i64::from(company.track_piece_counts.electric)
|
||||
}
|
||||
RuntimeCompanyMetric::TrackPiecesElectric => i64::from(company.track_piece_counts.electric),
|
||||
RuntimeCompanyMetric::TrackPiecesNonElectric => {
|
||||
i64::from(company.track_piece_counts.non_electric)
|
||||
}
|
||||
|
|
@ -846,7 +897,8 @@ fn territory_metric_value(
|
|||
territory_ids: &[u32],
|
||||
metric: RuntimeTerritoryMetric,
|
||||
) -> i64 {
|
||||
state.territories
|
||||
state
|
||||
.territories
|
||||
.iter()
|
||||
.filter(|territory| territory_ids.contains(&territory.territory_id))
|
||||
.map(|territory| {
|
||||
|
|
@ -864,9 +916,12 @@ fn company_territory_metric_value(
|
|||
territory_ids: &[u32],
|
||||
metric: RuntimeTrackMetric,
|
||||
) -> i64 {
|
||||
state.company_territory_track_piece_counts
|
||||
state
|
||||
.company_territory_track_piece_counts
|
||||
.iter()
|
||||
.filter(|entry| entry.company_id == company_id && territory_ids.contains(&entry.territory_id))
|
||||
.filter(|entry| {
|
||||
entry.company_id == company_id && territory_ids.contains(&entry.territory_id)
|
||||
})
|
||||
.map(|entry| track_piece_metric_value(entry.track_piece_counts, metric))
|
||||
.sum()
|
||||
}
|
||||
|
|
@ -920,6 +975,34 @@ fn apply_u64_delta(current: u64, delta: i64, company_id: u32) -> Result<u64, Str
|
|||
}
|
||||
}
|
||||
|
||||
fn retire_matching_trains(
|
||||
trains: &mut [crate::RuntimeTrain],
|
||||
company_ids: Option<&Vec<u32>>,
|
||||
territory_ids: Option<&Vec<u32>>,
|
||||
locomotive_name: Option<&str>,
|
||||
) {
|
||||
for train in trains.iter_mut() {
|
||||
if !train.active || train.retired {
|
||||
continue;
|
||||
}
|
||||
if company_ids.is_some_and(|company_ids| !company_ids.contains(&train.owner_company_id)) {
|
||||
continue;
|
||||
}
|
||||
if territory_ids.is_some_and(|territory_ids| {
|
||||
!train
|
||||
.territory_id
|
||||
.is_some_and(|territory_id| territory_ids.contains(&territory_id))
|
||||
}) {
|
||||
continue;
|
||||
}
|
||||
if locomotive_name.is_some_and(|name| train.locomotive_name.as_deref() != Some(name)) {
|
||||
continue;
|
||||
}
|
||||
train.active = false;
|
||||
train.retired = true;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::BTreeMap;
|
||||
|
|
@ -928,7 +1011,8 @@ mod tests {
|
|||
use crate::{
|
||||
CalendarPoint, RuntimeCompany, RuntimeCompanyControllerKind, RuntimeCompanyTarget,
|
||||
RuntimeEffect, RuntimeEventRecord, RuntimeEventRecordTemplate, RuntimeSaveProfileState,
|
||||
RuntimeServiceState, RuntimeWorldRestoreState,
|
||||
RuntimeServiceState, RuntimeTerritory, RuntimeTerritoryTarget, RuntimeTrackPieceCounts,
|
||||
RuntimeTrain, RuntimeWorldRestoreState,
|
||||
};
|
||||
|
||||
fn state() -> RuntimeState {
|
||||
|
|
@ -957,6 +1041,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
@ -1927,4 +2012,177 @@ mod tests {
|
|||
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn applies_economic_status_code_effect() {
|
||||
let mut state = RuntimeState {
|
||||
event_runtime_records: vec![RuntimeEventRecord {
|
||||
record_id: 90,
|
||||
trigger_kind: 6,
|
||||
active: true,
|
||||
service_count: 0,
|
||||
marks_collection_dirty: false,
|
||||
one_shot: false,
|
||||
has_fired: false,
|
||||
conditions: Vec::new(),
|
||||
effects: vec![RuntimeEffect::SetEconomicStatusCode { value: 3 }],
|
||||
}],
|
||||
..state()
|
||||
};
|
||||
|
||||
execute_step_command(
|
||||
&mut state,
|
||||
&StepCommand::ServiceTriggerKind { trigger_kind: 6 },
|
||||
)
|
||||
.expect("economic-status effect should succeed");
|
||||
|
||||
assert_eq!(state.world_restore.economic_status_code, Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confiscate_company_assets_zeros_company_and_retires_owned_trains() {
|
||||
let mut state = RuntimeState {
|
||||
companies: vec![
|
||||
RuntimeCompany {
|
||||
company_id: 1,
|
||||
controller_kind: RuntimeCompanyControllerKind::Human,
|
||||
current_cash: 50,
|
||||
debt: 7,
|
||||
credit_rating_score: None,
|
||||
prime_rate: None,
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
active: true,
|
||||
available_track_laying_capacity: None,
|
||||
},
|
||||
RuntimeCompany {
|
||||
company_id: 2,
|
||||
controller_kind: RuntimeCompanyControllerKind::Ai,
|
||||
current_cash: 80,
|
||||
debt: 9,
|
||||
credit_rating_score: None,
|
||||
prime_rate: None,
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
active: true,
|
||||
available_track_laying_capacity: None,
|
||||
},
|
||||
],
|
||||
selected_company_id: Some(1),
|
||||
trains: vec![
|
||||
RuntimeTrain {
|
||||
train_id: 10,
|
||||
owner_company_id: 1,
|
||||
territory_id: None,
|
||||
locomotive_name: Some("Mikado".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
},
|
||||
RuntimeTrain {
|
||||
train_id: 11,
|
||||
owner_company_id: 2,
|
||||
territory_id: None,
|
||||
locomotive_name: Some("Orca".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
},
|
||||
],
|
||||
event_runtime_records: vec![RuntimeEventRecord {
|
||||
record_id: 91,
|
||||
trigger_kind: 6,
|
||||
active: true,
|
||||
service_count: 0,
|
||||
marks_collection_dirty: false,
|
||||
one_shot: false,
|
||||
has_fired: false,
|
||||
conditions: Vec::new(),
|
||||
effects: vec![RuntimeEffect::ConfiscateCompanyAssets {
|
||||
target: RuntimeCompanyTarget::SelectedCompany,
|
||||
}],
|
||||
}],
|
||||
..state()
|
||||
};
|
||||
|
||||
execute_step_command(
|
||||
&mut state,
|
||||
&StepCommand::ServiceTriggerKind { trigger_kind: 6 },
|
||||
)
|
||||
.expect("confiscation effect should succeed");
|
||||
|
||||
assert_eq!(state.companies[0].current_cash, 0);
|
||||
assert_eq!(state.companies[0].debt, 0);
|
||||
assert!(!state.companies[0].active);
|
||||
assert_eq!(state.selected_company_id, None);
|
||||
assert!(state.trains[0].retired);
|
||||
assert!(!state.trains[1].retired);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retire_trains_respects_company_territory_and_locomotive_filters() {
|
||||
let mut state = RuntimeState {
|
||||
territories: vec![
|
||||
RuntimeTerritory {
|
||||
territory_id: 7,
|
||||
name: Some("Appalachia".to_string()),
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
},
|
||||
RuntimeTerritory {
|
||||
territory_id: 8,
|
||||
name: Some("Great Plains".to_string()),
|
||||
track_piece_counts: RuntimeTrackPieceCounts::default(),
|
||||
},
|
||||
],
|
||||
trains: vec![
|
||||
RuntimeTrain {
|
||||
train_id: 10,
|
||||
owner_company_id: 1,
|
||||
territory_id: Some(7),
|
||||
locomotive_name: Some("Mikado".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
},
|
||||
RuntimeTrain {
|
||||
train_id: 11,
|
||||
owner_company_id: 1,
|
||||
territory_id: Some(7),
|
||||
locomotive_name: Some("Orca".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
},
|
||||
RuntimeTrain {
|
||||
train_id: 12,
|
||||
owner_company_id: 1,
|
||||
territory_id: Some(8),
|
||||
locomotive_name: Some("Mikado".to_string()),
|
||||
active: true,
|
||||
retired: false,
|
||||
},
|
||||
],
|
||||
event_runtime_records: vec![RuntimeEventRecord {
|
||||
record_id: 92,
|
||||
trigger_kind: 6,
|
||||
active: true,
|
||||
service_count: 0,
|
||||
marks_collection_dirty: false,
|
||||
one_shot: false,
|
||||
has_fired: false,
|
||||
conditions: Vec::new(),
|
||||
effects: vec![RuntimeEffect::RetireTrains {
|
||||
company_target: Some(RuntimeCompanyTarget::SelectedCompany),
|
||||
territory_target: Some(RuntimeTerritoryTarget::Ids { ids: vec![7] }),
|
||||
locomotive_name: Some("Mikado".to_string()),
|
||||
}],
|
||||
}],
|
||||
selected_company_id: Some(1),
|
||||
..state()
|
||||
};
|
||||
|
||||
execute_step_command(
|
||||
&mut state,
|
||||
&StepCommand::ServiceTriggerKind { trigger_kind: 6 },
|
||||
)
|
||||
.expect("retire-trains effect should succeed");
|
||||
|
||||
assert!(state.trains[0].retired);
|
||||
assert!(!state.trains[1].retired);
|
||||
assert!(!state.trains[2].retired);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,16 @@ pub struct RuntimeSummary {
|
|||
pub world_restore_disable_train_crashes_enabled: Option<bool>,
|
||||
pub world_restore_disable_train_crashes_and_breakdowns_enabled: Option<bool>,
|
||||
pub world_restore_ai_ignore_territories_at_startup_enabled: Option<bool>,
|
||||
pub world_restore_economic_status_code: Option<i32>,
|
||||
pub world_restore_absolute_counter_restore_kind: Option<String>,
|
||||
pub world_restore_absolute_counter_adjustment_context: Option<String>,
|
||||
pub metadata_count: usize,
|
||||
pub company_count: usize,
|
||||
pub active_company_count: usize,
|
||||
pub player_count: usize,
|
||||
pub train_count: usize,
|
||||
pub active_train_count: usize,
|
||||
pub retired_train_count: usize,
|
||||
pub territory_count: usize,
|
||||
pub company_territory_track_count: usize,
|
||||
pub packed_event_collection_present: bool,
|
||||
|
|
@ -55,6 +59,11 @@ pub struct RuntimeSummary {
|
|||
pub packed_event_blocked_missing_compact_control_count: usize,
|
||||
pub packed_event_blocked_unmapped_real_descriptor_count: usize,
|
||||
pub packed_event_blocked_territory_policy_descriptor_count: usize,
|
||||
pub packed_event_blocked_missing_train_context_count: usize,
|
||||
pub packed_event_blocked_missing_train_territory_context_count: usize,
|
||||
pub packed_event_blocked_confiscation_variant_count: usize,
|
||||
pub packed_event_blocked_retire_train_variant_count: usize,
|
||||
pub packed_event_blocked_retire_train_scope_count: usize,
|
||||
pub packed_event_blocked_structural_only_count: usize,
|
||||
pub event_runtime_record_count: usize,
|
||||
pub candidate_availability_count: usize,
|
||||
|
|
@ -127,6 +136,7 @@ impl RuntimeSummary {
|
|||
world_restore_ai_ignore_territories_at_startup_enabled: state
|
||||
.world_restore
|
||||
.ai_ignore_territories_at_startup_enabled,
|
||||
world_restore_economic_status_code: state.world_restore.economic_status_code,
|
||||
world_restore_absolute_counter_restore_kind: state
|
||||
.world_restore
|
||||
.absolute_counter_restore_kind
|
||||
|
|
@ -143,6 +153,9 @@ impl RuntimeSummary {
|
|||
.filter(|company| company.active)
|
||||
.count(),
|
||||
player_count: state.players.len(),
|
||||
train_count: state.trains.len(),
|
||||
active_train_count: state.trains.iter().filter(|train| train.active).count(),
|
||||
retired_train_count: state.trains.iter().filter(|train| train.retired).count(),
|
||||
territory_count: state.territories.len(),
|
||||
company_territory_track_count: state.company_territory_track_piece_counts.len(),
|
||||
packed_event_collection_present: state.packed_event_collection.is_some(),
|
||||
|
|
@ -421,6 +434,73 @@ impl RuntimeSummary {
|
|||
.count()
|
||||
})
|
||||
.unwrap_or(0),
|
||||
packed_event_blocked_missing_train_context_count: state
|
||||
.packed_event_collection
|
||||
.as_ref()
|
||||
.map(|summary| {
|
||||
summary
|
||||
.records
|
||||
.iter()
|
||||
.filter(|record| {
|
||||
record.import_outcome.as_deref()
|
||||
== Some("blocked_missing_train_context")
|
||||
})
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(0),
|
||||
packed_event_blocked_missing_train_territory_context_count: state
|
||||
.packed_event_collection
|
||||
.as_ref()
|
||||
.map(|summary| {
|
||||
summary
|
||||
.records
|
||||
.iter()
|
||||
.filter(|record| {
|
||||
record.import_outcome.as_deref()
|
||||
== Some("blocked_missing_train_territory_context")
|
||||
})
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(0),
|
||||
packed_event_blocked_confiscation_variant_count: state
|
||||
.packed_event_collection
|
||||
.as_ref()
|
||||
.map(|summary| {
|
||||
summary
|
||||
.records
|
||||
.iter()
|
||||
.filter(|record| {
|
||||
record.import_outcome.as_deref() == Some("blocked_confiscation_variant")
|
||||
})
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(0),
|
||||
packed_event_blocked_retire_train_variant_count: state
|
||||
.packed_event_collection
|
||||
.as_ref()
|
||||
.map(|summary| {
|
||||
summary
|
||||
.records
|
||||
.iter()
|
||||
.filter(|record| {
|
||||
record.import_outcome.as_deref() == Some("blocked_retire_train_variant")
|
||||
})
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(0),
|
||||
packed_event_blocked_retire_train_scope_count: state
|
||||
.packed_event_collection
|
||||
.as_ref()
|
||||
.map(|summary| {
|
||||
summary
|
||||
.records
|
||||
.iter()
|
||||
.filter(|record| {
|
||||
record.import_outcome.as_deref() == Some("blocked_retire_train_scope")
|
||||
})
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(0),
|
||||
packed_event_blocked_structural_only_count: state
|
||||
.packed_event_collection
|
||||
.as_ref()
|
||||
|
|
@ -481,8 +561,8 @@ mod tests {
|
|||
use crate::{
|
||||
CalendarPoint, RuntimeCompany, RuntimeCompanyControllerKind,
|
||||
RuntimePackedEventCollectionSummary, RuntimePackedEventRecordSummary,
|
||||
RuntimeTrackPieceCounts,
|
||||
RuntimeSaveProfileState, RuntimeServiceState, RuntimeState, RuntimeWorldRestoreState,
|
||||
RuntimeSaveProfileState, RuntimeServiceState, RuntimeState, RuntimeTrackPieceCounts,
|
||||
RuntimeWorldRestoreState,
|
||||
};
|
||||
|
||||
use super::RuntimeSummary;
|
||||
|
|
@ -504,6 +584,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: Some(RuntimePackedEventCollectionSummary {
|
||||
|
|
@ -731,6 +812,7 @@ mod tests {
|
|||
selected_company_id: None,
|
||||
players: Vec::new(),
|
||||
selected_player_id: None,
|
||||
trains: Vec::new(),
|
||||
territories: Vec::new(),
|
||||
company_territory_track_piece_counts: Vec::new(),
|
||||
packed_event_collection: None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue