implement load config on game restart
This commit is contained in:
@@ -9,23 +9,23 @@
|
||||
#include "SurfaceMask.h"
|
||||
#include "WaveSystem.h"
|
||||
|
||||
Simulation::Simulation(const GameConfig& config, unsigned int seed)
|
||||
: m_config(config)
|
||||
Simulation::Simulation(GameConfig config, unsigned int seed)
|
||||
: m_config(std::move(config))
|
||||
, m_rng(seed)
|
||||
, m_currentTick(0)
|
||||
, m_nextId(1)
|
||||
, m_buildingBlocksStock(config.world.startingBuildingBlocks)
|
||||
, m_buildingBlocksStock(m_config.world.startingBuildingBlocks)
|
||||
, m_gameOver(false)
|
||||
, m_hqId(kInvalidEntityId)
|
||||
, m_playerStation1Id(kInvalidEntityId)
|
||||
, m_playerStation2Id(kInvalidEntityId)
|
||||
, m_beltSystem(config.world.beltSpeedTilesPerSecond)
|
||||
, m_beltSystem(m_config.world.beltSpeedTilesPerSecond)
|
||||
{
|
||||
m_currentEnemyStationIds[0] = kInvalidEntityId;
|
||||
m_currentEnemyStationIds[1] = kInvalidEntityId;
|
||||
|
||||
m_buildingSystem = std::make_unique<BuildingSystem>(
|
||||
config,
|
||||
m_config,
|
||||
m_beltSystem,
|
||||
[this]() { return allocateId(); },
|
||||
[this](int amount) { m_buildingBlocksStock += amount; },
|
||||
@@ -39,13 +39,13 @@ Simulation::Simulation(const GameConfig& config, unsigned int seed)
|
||||
m_shipSystem->spawn(id, it->second.level, pos, /*isEnemy=*/false);
|
||||
},
|
||||
m_rng);
|
||||
m_shipSystem = std::make_unique<ShipSystem>(config, [this]() { return allocateId(); });
|
||||
m_shipSystem = std::make_unique<ShipSystem>(m_config, [this]() { return allocateId(); });
|
||||
m_scrapSystem = std::make_unique<ScrapSystem>([this]() { return allocateId(); });
|
||||
m_waveSystem = std::make_unique<WaveSystem>(config, m_rng);
|
||||
m_combatSystem = std::make_unique<CombatSystem>(config);
|
||||
m_waveSystem = std::make_unique<WaveSystem>(m_config, m_rng);
|
||||
m_combatSystem = std::make_unique<CombatSystem>(m_config);
|
||||
|
||||
// Initialize blueprint unlock state.
|
||||
for (const ShipDef& def : config.ships.ships)
|
||||
for (const ShipDef& def : m_config.ships.ships)
|
||||
{
|
||||
BlueprintState state;
|
||||
state.unlocked = def.availableFromStart;
|
||||
@@ -58,6 +58,17 @@ Simulation::Simulation(const GameConfig& config, unsigned int seed)
|
||||
|
||||
Simulation::~Simulation() = default;
|
||||
|
||||
const GameConfig& Simulation::config() const
|
||||
{
|
||||
return m_config;
|
||||
}
|
||||
|
||||
void Simulation::reset(GameConfig newConfig, unsigned int seed)
|
||||
{
|
||||
m_config = std::move(newConfig);
|
||||
reset(seed);
|
||||
}
|
||||
|
||||
void Simulation::reset(unsigned int seed)
|
||||
{
|
||||
m_rng.seed(seed);
|
||||
|
||||
Reference in New Issue
Block a user