Replaces the hardcoded seed=0 with the seed received in StartupMessage,
threading it through SimulationPlugin -> EconomyPlugin / SimRng. Integration
test fixtures updated for the new SimulationPlugin { seed } signature.
38 lines
1.5 KiB
Rust
38 lines
1.5 KiB
Rust
//! Economy phase plugin — tâtonnement simulation tick and IPC query serving.
|
|
//!
|
|
//! All systems run in [`TickPhase::Economy`]. Intra-phase ordering:
|
|
//! - tick_economy_simulation → serve_econ_state_query (query reads fresh signals)
|
|
|
|
use bevy_app::prelude::*;
|
|
use bevy_ecs::schedule::IntoScheduleConfigs;
|
|
|
|
use crate::tick_phases::TickPhase;
|
|
|
|
pub struct EconomyPlugin {
|
|
/// World seed from `StartupMessage` (#826). Passed to `try_load_economy` so the
|
|
/// tâtonnement simulation is seeded deterministically from the client's world seed.
|
|
pub seed: u64,
|
|
}
|
|
|
|
impl Plugin for EconomyPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
// Economy simulation (#821, D-031) — loaded once at startup, no-op when DB absent.
|
|
// Seed comes from StartupMessage.world_seed, threaded via SimulationPlugin (#826).
|
|
if let Some((econ_sim, econ_state)) = super::economy::try_load_economy(self.seed) {
|
|
app.insert_resource(econ_sim).insert_resource(econ_state);
|
|
}
|
|
// EconQueryBuffer: always registered so EconStateQuery PlayerActions are accepted
|
|
// even when the economy DB is absent (queries just produce no response).
|
|
app.init_resource::<super::economy::EconQueryBuffer>()
|
|
.add_systems(
|
|
Update,
|
|
(
|
|
super::economy::tick_economy_simulation,
|
|
super::economy::serve_econ_state_query
|
|
.after(super::economy::tick_economy_simulation),
|
|
)
|
|
.in_set(TickPhase::Economy),
|
|
);
|
|
}
|
|
}
|