Surface annual bond retired and issued totals

This commit is contained in:
Jan Petykiewicz 2026-04-18 01:59:36 -07:00
commit ec359ec2f9
7 changed files with 64 additions and 8 deletions

View file

@ -13993,6 +13993,8 @@ mod tests {
annual_finance_last_actions: BTreeMap::new(),
annual_finance_action_counts: BTreeMap::new(),
annual_dividend_adjustment_commit_count: 0,
annual_bond_last_retired_principal_total: 0,
annual_bond_last_issued_principal_total: 0,
chairman_issue_opinion_terms_raw_i32: BTreeMap::new(),
chairman_personality_raw_u8: BTreeMap::new(),
},

View file

@ -1237,6 +1237,10 @@ pub struct RuntimeServiceState {
#[serde(default)]
pub annual_dividend_adjustment_commit_count: u64,
#[serde(default)]
pub annual_bond_last_retired_principal_total: u64,
#[serde(default)]
pub annual_bond_last_issued_principal_total: u64,
#[serde(default)]
pub chairman_issue_opinion_terms_raw_i32: BTreeMap<u32, Vec<i32>>,
#[serde(default)]
pub chairman_personality_raw_u8: BTreeMap<u32, u8>,

View file

@ -385,14 +385,14 @@ fn service_apply_company_bankruptcy(state: &mut RuntimeState, company_id: u32) -
fn service_repay_matured_company_live_bonds_and_compact(
state: &mut RuntimeState,
company_id: u32,
) -> bool {
) -> Option<u64> {
let Some(current_year_word) = state
.world_restore
.packed_year_word_raw_u16
.map(u32::from)
.or_else(|| Some(state.calendar.year))
else {
return false;
return None;
};
let retired_principal_total = state
.service_state
@ -408,7 +408,7 @@ fn service_repay_matured_company_live_bonds_and_compact(
})
.unwrap_or(0);
if retired_principal_total == 0 {
return false;
return None;
}
let retired_principal_total_f64 = retired_principal_total as f64;
@ -481,7 +481,7 @@ fn service_repay_matured_company_live_bonds_and_compact(
company_mutated = true;
}
company_mutated
company_mutated.then_some(retired_principal_total)
}
fn service_company_annual_finance_policy(
@ -500,6 +500,8 @@ fn service_company_annual_finance_policy(
.annual_finance_last_actions
.retain(|company_id, _| active_company_id_set.contains(company_id));
state.service_state.annual_finance_service_calls += 1;
state.service_state.annual_bond_last_retired_principal_total = 0;
state.service_state.annual_bond_last_issued_principal_total = 0;
let mut mutated_company_ids = BTreeSet::new();
let mut applied_effect_count = 0u32;
@ -632,7 +634,14 @@ fn service_company_annual_finance_policy(
if !bond_state.eligible_for_bond_issue_branch {
continue;
}
mutated |= service_repay_matured_company_live_bonds_and_compact(state, company_id);
let retired_principal_total =
service_repay_matured_company_live_bonds_and_compact(state, company_id)
.unwrap_or(0);
mutated |= retired_principal_total > 0;
state.service_state.annual_bond_last_retired_principal_total = state
.service_state
.annual_bond_last_retired_principal_total
.saturating_add(retired_principal_total);
let issue_bond_count = bond_state.proposed_issue_bond_count.unwrap_or(0);
let Some(principal) = bond_state.issue_principal_step else {
@ -734,6 +743,10 @@ fn service_company_annual_finance_policy(
})
.map(|(_, principal)| principal);
market_state.highest_coupon_live_bond_principal = highest_coupon_live_principal;
state.service_state.annual_bond_last_issued_principal_total = state
.service_state
.annual_bond_last_issued_principal_total
.saturating_add(u64::from(principal));
}
if let Some(company) = state
.companies
@ -3165,6 +3178,14 @@ mod tests {
);
assert_eq!(state.companies[0].current_cash, 100_000);
assert_eq!(state.service_state.company_market_state[&24].bond_count, 1);
assert_eq!(
state.service_state.annual_bond_last_retired_principal_total,
0
);
assert_eq!(
state.service_state.annual_bond_last_issued_principal_total,
500_000
);
assert_eq!(
state.service_state.company_market_state[&24].largest_live_bond_principal,
Some(500_000)
@ -3314,6 +3335,14 @@ mod tests {
);
assert_eq!(state.companies[0].current_cash, 550_000);
assert_eq!(state.companies[0].debt, 0);
assert_eq!(
state.service_state.annual_bond_last_retired_principal_total,
350_000
);
assert_eq!(
state.service_state.annual_bond_last_issued_principal_total,
0
);
assert_eq!(state.service_state.company_market_state[&25].bond_count, 0);
assert!(
state.service_state.company_market_state[&25]
@ -3461,6 +3490,14 @@ mod tests {
);
assert_eq!(state.companies[0].current_cash, 250_000);
assert_eq!(state.companies[0].debt, 1_000_000);
assert_eq!(
state.service_state.annual_bond_last_retired_principal_total,
350_000
);
assert_eq!(
state.service_state.annual_bond_last_issued_principal_total,
1_000_000
);
assert_eq!(state.service_state.company_market_state[&26].bond_count, 2);
assert_eq!(
state.service_state.company_market_state[&26].largest_live_bond_principal,

View file

@ -259,6 +259,8 @@ pub struct RuntimeSummary {
pub periodic_boundary_call_count: u64,
pub annual_finance_service_call_count: u64,
pub annual_dividend_adjustment_commit_count: u64,
pub annual_bond_last_retired_principal_total: u64,
pub annual_bond_last_issued_principal_total: u64,
pub total_trigger_dispatch_count: u64,
pub dirty_rerun_count: u64,
pub total_company_cash: i64,
@ -1381,6 +1383,12 @@ impl RuntimeSummary {
annual_dividend_adjustment_commit_count: state
.service_state
.annual_dividend_adjustment_commit_count,
annual_bond_last_retired_principal_total: state
.service_state
.annual_bond_last_retired_principal_total,
annual_bond_last_issued_principal_total: state
.service_state
.annual_bond_last_issued_principal_total,
total_trigger_dispatch_count: state
.service_state
.trigger_dispatch_counts