Skip to main content

rpfm_extensions/startpos/world/writer/
spying.rs

1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2026 Ismael Gutiérrez González. All rights reserved.
3//
4// This file is part of the Rusted PackFile Manager (RPFM) project,
5// which can be found here: https://github.com/Frodo45127/rpfm.
6//
7// This file is licensed under the MIT license, which can be found here:
8// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
9//---------------------------------------------------------------------------//
10
11//! Writer of the factions' spying state (`WORLD/SPYING_ARRAY`): one entry per faction, in world order, with nothing
12//! spied yet.
13
14use rpfm_lib::error::Result;
15use rpfm_lib::files::esf::RecordNode;
16
17use super::{WorldInputs, WorldPlan, WORLD_PATH};
18use crate::startpos::layout::child_path;
19
20#[cfg(test)] #[path = "spying_test.rs"] mod spying_test;
21
22/// Writes the spying state of the factions.
23///
24/// # Arguments
25///
26/// * `inputs` - Tables, startpos rows and layouts.
27/// * `plan` - Order of the factions.
28///
29/// # Errors
30///
31/// Returns an error if the layout lacks the records.
32pub fn write_spying_array(inputs: &WorldInputs, plan: &WorldPlan) -> Result<RecordNode> {
33    let path = child_path(WORLD_PATH, "SPYING_ARRAY");
34    let spying = inputs.layout.default_record(&child_path(&path, "CAMPAIGN_SPYING"))?;
35    let mut array = inputs.layout.builder(&path)?;
36    for faction in plan.factions() {
37        array.push_group()?
38            .set_str("^+1", faction.key())?
39            .set_record("CAMPAIGN_SPYING", Some(spying.clone()))?;
40    }
41    array.build()
42}