diff --git a/server/src/bridge/debug.rs b/server/src/bridge/debug.rs index b7b881c82..dd5287cab 100644 --- a/server/src/bridge/debug.rs +++ b/server/src/bridge/debug.rs @@ -12,10 +12,10 @@ use crate::bridge::types::{ DebugCommandKind, DebugEnabled, DebugResponsePayload, EconDebugEffect, EconParamKind, SnapshotBuffer, }; -use crate::simulation::economy::{EconSimResource, EconStateResource}; use crate::knowledge::EntityRegistry; use crate::npc::Npc; use crate::simulation::conversation::NpcName; +use crate::simulation::economy::{EconSimResource, EconStateResource}; use crate::simulation::movement::{PlayerCharacter, TilePosition, WalkabilityMap}; use crate::simulation::tier::ActiveSim; use crate::simulation::time::SimulationTime; @@ -337,7 +337,9 @@ pub fn handle_debug_commands( magnitude, duration_ticks, } => { - use econ_sim::events::{EconEvent, EconEventEffect, EconEventTarget, EconEventVisibility}; + use econ_sim::events::{ + EconEvent, EconEventEffect, EconEventTarget, EconEventVisibility, + }; if let Some(ref mut sim) = econ_sim { let econ_effect = match effect { EconDebugEffect::CapacityMultiplier => { @@ -346,9 +348,7 @@ pub fn handle_debug_commands( EconDebugEffect::ProductivityMultiplier => { EconEventEffect::ProductivityMultiplier(magnitude) } - EconDebugEffect::DemandShock => { - EconEventEffect::DemandShock(magnitude) - } + EconDebugEffect::DemandShock => EconEventEffect::DemandShock(magnitude), EconDebugEffect::ExchangeShock => { EconEventEffect::ExchangeShock(magnitude) } @@ -427,7 +427,10 @@ pub fn handle_debug_commands( } } else { let mut lines = vec![ - format!("=== Economy state for '{}' (econ_tick={}) ===", system_id, state.econ_tick), + format!( + "=== Economy state for '{}' (econ_tick={}) ===", + system_id, state.econ_tick + ), format!(" FX rate (Tractus/Mark): {:.4}", state.tractus_mark_rate), ]; for ((_, commodity_id), sig) in &signals { diff --git a/server/src/simulation/economy.rs b/server/src/simulation/economy.rs index c3107b6c3..38007a4d2 100644 --- a/server/src/simulation/economy.rs +++ b/server/src/simulation/economy.rs @@ -141,7 +141,7 @@ pub fn tick_economy_simulation( _ => return, // economy not loaded — no-op }; - if time.tick % ECON_TICK_RATE != 0 { + if !time.tick.is_multiple_of(ECON_TICK_RATE) { return; } @@ -196,9 +196,7 @@ fn rebuild_signals( let commodities: Vec<(String, f64, f64)> = node .commodities .iter() - .map(|(commodity_id, state)| { - (commodity_id.clone(), state.price, state.supply) - }) + .map(|(commodity_id, state)| (commodity_id.clone(), state.price, state.supply)) .collect(); (system_id.clone(), commodities) }) @@ -280,15 +278,6 @@ fn rebuild_signals( } } -// --------------------------------------------------------------------------- -// Startup helper -// --------------------------------------------------------------------------- - -/// Attempt to load the economy simulation. -/// -/// Returns `Some((EconSimResource, EconStateResource))` on success, `None` on -/// failure (with the error logged at warn level). The server inserts these as -/// resources when present; the economy features degrade gracefully when absent. // --------------------------------------------------------------------------- // IPC query buffer (#822) // --------------------------------------------------------------------------- @@ -361,6 +350,11 @@ pub fn serve_econ_state_query( // Startup helper // --------------------------------------------------------------------------- +/// Attempt to load the economy simulation. +/// +/// Returns `Some((EconSimResource, EconStateResource))` on success, `None` on +/// failure (with the error logged at warn level). The server inserts these as +/// resources when present; the economy features degrade gracefully when absent. pub fn try_load_economy(run_seed: u64) -> Option<(EconSimResource, EconStateResource)> { match Simulation::load_auto(run_seed) { Ok(sim) => { diff --git a/server/src/simulation/input.rs b/server/src/simulation/input.rs index acfc01fdb..74b0a1795 100644 --- a/server/src/simulation/input.rs +++ b/server/src/simulation/input.rs @@ -4,10 +4,10 @@ use crate::bridge::debug::DebugCommandBuffer; use crate::bridge::types::{FacingDirection, ObjectType, PlayerAction, PlayerInput}; -use crate::simulation::economy::EconQueryBuffer; use crate::knowledge::{EntityRegistry, StableId}; use crate::perception::vision_cone::{facing_from_delta, Facing}; use crate::settings::{SettingsCommand, SettingsCommandBuffer}; +use crate::simulation::economy::EconQueryBuffer; use crate::simulation::interaction::{DoorInteractRequest, DoorState, TerminalInteractRequest}; use crate::simulation::inventory::{ find_next_slot, occupied_slots_for, CarriedBy, InventorySlot, ItemName, MAX_INVENTORY_SLOTS, @@ -129,7 +129,7 @@ pub fn process_player_input( | PlayerAction::ChangeSetting { .. } | PlayerAction::RequestAllSettings | PlayerAction::DeleteSetting { .. } - | PlayerAction::EconStateQuery { .. } + | PlayerAction::EconStateQuery { .. } ) { continue; diff --git a/server/src/simulation/mod.rs b/server/src/simulation/mod.rs index c6f7d9ed0..d56e93ba0 100644 --- a/server/src/simulation/mod.rs +++ b/server/src/simulation/mod.rs @@ -170,8 +170,7 @@ impl Plugin for SimulationPlugin { // Economy simulation (#821, D-031) — loaded once at startup, no-op when DB absent. // Uses seed 0 for now; will be threaded through StartupMessage world seed (#TODO). if let Some((econ_sim, econ_state)) = economy::try_load_economy(0) { - app.insert_resource(econ_sim) - .insert_resource(econ_state); + 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).