Broaden chairman target scope event support
This commit is contained in:
parent
5c2156bcbf
commit
a63de904fa
15 changed files with 1257 additions and 30 deletions
|
|
@ -87,7 +87,6 @@ struct AppliedEffectsSummary {
|
|||
struct ResolvedConditionContext {
|
||||
matching_company_ids: BTreeSet<u32>,
|
||||
matching_player_ids: BTreeSet<u32>,
|
||||
#[allow(dead_code)]
|
||||
matching_chairman_profile_ids: BTreeSet<u32>,
|
||||
}
|
||||
|
||||
|
|
@ -363,6 +362,48 @@ fn apply_runtime_effects(
|
|||
chairman.current_cash = *value;
|
||||
}
|
||||
}
|
||||
RuntimeEffect::SetCompanyGovernanceScalar {
|
||||
target,
|
||||
metric,
|
||||
value,
|
||||
} => {
|
||||
let company_ids = resolve_company_target_ids(state, target, condition_context)?;
|
||||
for company_id in company_ids {
|
||||
let company = state
|
||||
.companies
|
||||
.iter_mut()
|
||||
.find(|company| company.company_id == company_id)
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"missing company_id {company_id} while applying governance effect"
|
||||
)
|
||||
})?;
|
||||
match metric {
|
||||
RuntimeCompanyMetric::CreditRating => {
|
||||
company.credit_rating_score = Some(*value);
|
||||
}
|
||||
RuntimeCompanyMetric::PrimeRate => {
|
||||
company.prime_rate = Some(*value);
|
||||
}
|
||||
RuntimeCompanyMetric::BookValuePerShare => {
|
||||
company.book_value_per_share = *value;
|
||||
}
|
||||
RuntimeCompanyMetric::InvestorConfidence => {
|
||||
company.investor_confidence = *value;
|
||||
}
|
||||
RuntimeCompanyMetric::ManagementAttitude => {
|
||||
company.management_attitude = *value;
|
||||
}
|
||||
_ => {
|
||||
return Err(format!(
|
||||
"unsupported governance metric {:?} in company governance effect",
|
||||
metric
|
||||
));
|
||||
}
|
||||
}
|
||||
mutated_company_ids.insert(company_id);
|
||||
}
|
||||
}
|
||||
RuntimeEffect::DeactivatePlayer { target } => {
|
||||
let player_ids = resolve_player_target_ids(state, target, condition_context)?;
|
||||
for player_id in player_ids {
|
||||
|
|
@ -1152,7 +1193,7 @@ fn resolve_player_target_ids(
|
|||
fn resolve_chairman_target_ids(
|
||||
state: &RuntimeState,
|
||||
target: &RuntimeChairmanTarget,
|
||||
_condition_context: &ResolvedConditionContext,
|
||||
condition_context: &ResolvedConditionContext,
|
||||
) -> Result<Vec<u32>, String> {
|
||||
match target {
|
||||
RuntimeChairmanTarget::AllActive => Ok(state
|
||||
|
|
@ -1161,6 +1202,30 @@ fn resolve_chairman_target_ids(
|
|||
.filter(|profile| profile.active)
|
||||
.map(|profile| profile.profile_id)
|
||||
.collect()),
|
||||
RuntimeChairmanTarget::HumanChairmen => Ok(state
|
||||
.chairman_profiles
|
||||
.iter()
|
||||
.filter(|profile| {
|
||||
chairman_profile_matches_company_controller_kind(
|
||||
state,
|
||||
profile,
|
||||
RuntimeCompanyControllerKind::Human,
|
||||
)
|
||||
})
|
||||
.map(|profile| profile.profile_id)
|
||||
.collect()),
|
||||
RuntimeChairmanTarget::AiChairmen => Ok(state
|
||||
.chairman_profiles
|
||||
.iter()
|
||||
.filter(|profile| {
|
||||
chairman_profile_matches_company_controller_kind(
|
||||
state,
|
||||
profile,
|
||||
RuntimeCompanyControllerKind::Ai,
|
||||
)
|
||||
})
|
||||
.map(|profile| profile.profile_id)
|
||||
.collect()),
|
||||
RuntimeChairmanTarget::Ids { ids } => {
|
||||
let known_ids = state
|
||||
.chairman_profiles
|
||||
|
|
@ -1193,9 +1258,37 @@ fn resolve_chairman_target_ids(
|
|||
)
|
||||
}
|
||||
}
|
||||
RuntimeChairmanTarget::ConditionTrueChairman => {
|
||||
if condition_context.matching_chairman_profile_ids.is_empty() {
|
||||
Err("target requires chairman condition-evaluation context".to_string())
|
||||
} else {
|
||||
Ok(condition_context
|
||||
.matching_chairman_profile_ids
|
||||
.iter()
|
||||
.copied()
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn chairman_profile_matches_company_controller_kind(
|
||||
state: &RuntimeState,
|
||||
profile: &crate::RuntimeChairmanProfile,
|
||||
controller_kind: RuntimeCompanyControllerKind,
|
||||
) -> bool {
|
||||
profile.active
|
||||
&& profile
|
||||
.linked_company_id
|
||||
.and_then(|company_id| {
|
||||
state
|
||||
.companies
|
||||
.iter()
|
||||
.find(|company| company.company_id == company_id)
|
||||
})
|
||||
.is_some_and(|company| company.controller_kind == controller_kind)
|
||||
}
|
||||
|
||||
fn resolve_territory_target_ids(
|
||||
state: &RuntimeState,
|
||||
target: &RuntimeTerritoryTarget,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue