Project directly perceived world events

This commit is contained in:
Meta Vens 2026-08-23 11:47:40 +02:00
commit 41ff563459
2 changed files with 95 additions and 18 deletions

View file

@ -549,17 +549,12 @@ fn cell_perceived_events(
let mut perceived_by_subject_ids = constituents
.iter()
.filter(|subject| {
event.actor_ids.contains(&subject.subject_id)
|| event.institution_ids.contains(&subject.subject_id)
|| event.gestalt_ids.contains(&subject.subject_id)
|| !event
.location_ids
.iter()
.all(|location_id| !subject.location_ids.contains(location_id))
|| !event
.public_channels
.iter()
.all(|channel| !subject.information_channels.contains(channel))
subject_perceives_event(
&subject.subject_id,
&subject.location_ids,
&subject.information_channels,
event,
)
})
.map(|subject| subject.subject_id.clone())
.collect::<BTreeSet<_>>();
@ -585,6 +580,25 @@ fn cell_perceived_events(
.collect()
}
pub(crate) fn subject_perceives_event(
subject_id: &str,
location_ids: &BTreeSet<String>,
information_channels: &BTreeSet<String>,
event: &crate::domain::Event,
) -> bool {
event.actor_ids.iter().any(|id| id == subject_id)
|| event.institution_ids.iter().any(|id| id == subject_id)
|| event.gestalt_ids.iter().any(|id| id == subject_id)
|| event
.location_ids
.iter()
.any(|location_id| location_ids.contains(location_id))
|| event
.public_channels
.iter()
.any(|channel| information_channels.contains(channel))
}
fn member_exceptions(campaign: &Campaign, cell: &SimulationCell) -> Result<Vec<CellMemberSlice>> {
let player_id = &campaign.player_actor_id;
let mut candidates = campaign

View file

@ -76,20 +76,49 @@ pub fn player_surface_for_actor(
.collect::<Vec<_>>()
.join(", ")
};
let player_profile = campaign.agency_profiles.get(viewer_actor_id);
let information_channels = player_profile
.map(|profile| join(&profile.information_channels))
.unwrap_or_else(|| "none".into());
let ledger = format!(
"Capabilities: {}\nEquipment: {}\nConditions: {}\nObligations: {}\nRelationships: {}\nKnown facts: {}",
"Capabilities: {}\nEquipment: {}\nConditions: {}\nObligations: {}\nRelationships: {}\nKnown facts: {}\nInformation access: {}",
join(&player.capabilities),
join(&player.equipment),
join(&player.conditions),
join(&player.obligations),
relationships,
join(&player.knowledge)
join(&player.knowledge),
information_channels,
);
let accessible_channels = campaign
.agency_profiles
.get(viewer_actor_id)
.map(|profile| &profile.information_channels);
let news=campaign.news.iter().filter(|item| accessible_channels.is_some_and(|channels| channels.contains(&item.channel))).map(|item|json!({"id":item.id,"kind":"text","props":{"value":format!("[{}] {}",item.channel,item.headline)} ,"children":[]})).collect::<Vec<_>>();
let accessible_channels = player_profile.map(|profile| &profile.information_channels);
let accessible_news = campaign
.news
.iter()
.filter(|item| accessible_channels.is_some_and(|channels| channels.contains(&item.channel)))
.collect::<Vec<_>>();
let reported_event_ids = accessible_news
.iter()
.flat_map(|item| item.event_ids.iter().cloned())
.collect::<std::collections::BTreeSet<_>>();
let mut news = campaign
.events
.iter()
.rev()
.filter(|event| !reported_event_ids.contains(&event.id))
.filter(|event| {
player_profile.is_some_and(|profile| {
crate::scheduler::subject_perceives_event(
viewer_actor_id,
&profile.location_ids,
&profile.information_channels,
event,
)
})
})
.take(12)
.map(|event| json!({"id":format!("observed:{}",event.id),"kind":"text","props":{"value":format!("[observed] {}",event.summary)},"children":[]}))
.collect::<Vec<_>>();
news.extend(accessible_news.into_iter().map(|item|json!({"id":item.id,"kind":"text","props":{"value":format!("[{}] {}",item.channel,item.headline)},"children":[]})));
let effective_budget = campaign
.resolution_cover
.as_ref()
@ -570,6 +599,40 @@ mod tests {
assert!(!encoded.contains("SECRET_COMMAND_MOVEMENT"));
}
#[test]
fn player_surface_projects_directly_perceived_events_but_not_remote_secrets() {
let mut campaign = crate::resolution::tests::campaign(1, 1);
campaign.events.extend([
crate::domain::Event {
id: "event:local".into(),
at: Utc::now(),
kind: "local-change".into(),
summary: "The junction workers reopen the water line.".into(),
actor_ids: vec![],
institution_ids: vec![],
gestalt_ids: vec!["faction-0000".into()],
location_ids: vec!["center".into()],
public_channels: vec![],
},
crate::domain::Event {
id: "event:remote".into(),
at: Utc::now(),
kind: "remote-secret".into(),
summary: "SECRET_REMOTE_EVENT".into(),
actor_ids: vec![],
institution_ids: vec!["faction-0000".into()],
gestalt_ids: vec![],
location_ids: vec!["remote".into()],
public_channels: vec![],
},
]);
let encoded = serde_json::to_string(&player_surface(&campaign, &[])).unwrap();
assert!(encoded.contains("The junction workers reopen the water line."));
assert!(!encoded.contains("SECRET_REMOTE_EVENT"));
}
#[test]
fn player_surface_offers_only_local_population_fission_targets() {
let mut campaign = crate::resolution::tests::campaign(1, 1);