diff --git a/src/lib/sim/Simulation.cpp b/src/lib/sim/Simulation.cpp index 17d14df..27140d2 100644 --- a/src/lib/sim/Simulation.cpp +++ b/src/lib/sim/Simulation.cpp @@ -48,32 +48,7 @@ Simulation::Simulation(GameConfig config, unsigned int seed) m_currentEnemyStationEntities[0] = entt::null; m_currentEnemyStationEntities[1] = entt::null; - m_buildingSystem = std::make_unique( - m_config, - m_beltSystem, - [this]() { return allocateBuildingId(); }, - [this](int amount) { m_buildingBlocksStock += amount; }, - [this](const std::string& id, QVector2D pos, - const std::optional& layout) { - const std::map::const_iterator it = - m_schematicLevels.find(id); - if (it == m_schematicLevels.end() || !it->second.unlocked) - { - return; - } - m_shipSystem->spawn(id, pos, /*isEnemy=*/false, layout); - }, - [this](const std::string& itemId) -> bool { return isItemUnlocked(itemId); }, - m_rng); - m_shipSystem = std::make_unique(m_config, m_admin); - m_aiSystem = std::make_unique(m_config); - m_movementIntentSystem = std::make_unique(); - m_dynamicBodySystem = std::make_unique(); - m_debrisSystem = std::make_unique(m_admin); - m_salvagerSystem = std::make_unique(m_admin); - m_repairSystem = std::make_unique(m_admin); - m_waveSystem = std::make_unique(m_config, m_rng); - m_combatSystem = std::make_unique(m_config); + initializeSubsystems(); initializeUnlockState(); placeInitialStructures(); @@ -120,6 +95,14 @@ void Simulation::reset(unsigned int seed) m_admin.clear(); m_beltSystem = BeltSystem(m_config.world.beltSpeed_tps); + initializeSubsystems(); + + initializeUnlockState(); + placeInitialStructures(); +} + +void Simulation::initializeSubsystems() +{ m_buildingSystem = std::make_unique( m_config, m_beltSystem, @@ -146,9 +129,6 @@ void Simulation::reset(unsigned int seed) m_repairSystem = std::make_unique(m_admin); m_waveSystem = std::make_unique(m_config, m_rng); m_combatSystem = std::make_unique(m_config); - - initializeUnlockState(); - placeInitialStructures(); } void Simulation::initializeUnlockState() diff --git a/src/lib/sim/Simulation.h b/src/lib/sim/Simulation.h index 851787c..bacb185 100644 --- a/src/lib/sim/Simulation.h +++ b/src/lib/sim/Simulation.h @@ -165,6 +165,11 @@ private: BuildingId allocateBuildingId(); // Strictly increasing; never returns kInvalidBuildingId. + // (Re-)create every owned subsystem. Shared by the constructor and reset(); + // the construction order is load-bearing for determinism, so both paths must + // go through here. Only called before the first tick of a run. + void initializeSubsystems(); + // Populate HQ, player defence stations, and the first enemy station set. void placeInitialStructures();