diff --git a/binaries/data/mods/public/simulation/helpers/InitGame.js b/binaries/data/mods/public/simulation/helpers/InitGame.js index ccc40f3d07..3aac58316a 100644 --- a/binaries/data/mods/public/simulation/helpers/InitGame.js +++ b/binaries/data/mods/public/simulation/helpers/InitGame.js @@ -72,8 +72,6 @@ function InitGame(settings) // Map or player data (handicap...) dependent initialisations of components (i.e. garrisoned units) Engine.BroadcastMessage(MT_InitGame, {}); - let seed = settings.AISeed ? settings.AISeed : 0; - cmpAIManager.SetRNGSeed(seed); cmpAIManager.TryLoadSharedComponent(); cmpAIManager.RunGamestateInit(); } diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 5f531c8221..5ba4ce76ed 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -161,6 +161,9 @@ public: SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter, SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter); + void InitRNGSeedSimulation(); + void InitRNGSeedAI(); + static std::vector CloneCommandsFromOtherContext(const ScriptInterface& oldScript, const ScriptInterface& newScript, const std::vector& commands) { @@ -334,6 +337,28 @@ void CSimulation2Impl::ReportSerializationFailure( debug_warn(L"Serialization test failure"); } +void CSimulation2Impl::InitRNGSeedSimulation() +{ + u32 seed = 0; + if (!m_ComponentManager.GetScriptInterface().HasProperty(m_MapSettings, "Seed") || + !m_ComponentManager.GetScriptInterface().GetProperty(m_MapSettings, "Seed", seed)) + LOGWARNING("CSimulation2Impl::InitRNGSeedSimulation: No seed value specified - using %d", seed); + + m_ComponentManager.SetRNGSeed(seed); +} + +void CSimulation2Impl::InitRNGSeedAI() +{ + u32 seed = 0; + if (!m_ComponentManager.GetScriptInterface().HasProperty(m_MapSettings, "AISeed") || + !m_ComponentManager.GetScriptInterface().GetProperty(m_MapSettings, "AISeed", seed)) + LOGWARNING("CSimulation2Impl::InitRNGSeedAI: No seed value specified - using %d", seed); + + CmpPtr cmpAIManager(m_SimContext, SYSTEM_ENTITY); + if (cmpAIManager) + cmpAIManager->SetRNGSeed(seed); +} + void CSimulation2Impl::Update(int turnLength, const std::vector& commands) { PROFILE3("sim update"); @@ -793,12 +818,8 @@ void CSimulation2::SetMapSettings(JS::HandleValue settings) { m->m_MapSettings = settings; - u32 seed = 0; - if (!m->m_ComponentManager.GetScriptInterface().HasProperty(m->m_MapSettings, "Seed") || - !m->m_ComponentManager.GetScriptInterface().GetProperty(m->m_MapSettings, "Seed", seed)) - LOGWARNING("CSimulation2::SetInitAttributes: No seed value specified - using %d", seed); - - m->m_ComponentManager.SetRNGSeed(seed); + m->InitRNGSeedSimulation(); + m->InitRNGSeedAI(); } std::string CSimulation2::GetMapSettingsString() diff --git a/source/simulation2/components/ICmpAIManager.cpp b/source/simulation2/components/ICmpAIManager.cpp index a217a3620e..20d5a2bfb5 100644 --- a/source/simulation2/components/ICmpAIManager.cpp +++ b/source/simulation2/components/ICmpAIManager.cpp @@ -26,7 +26,6 @@ BEGIN_INTERFACE_WRAPPER(AIManager) DEFINE_INTERFACE_METHOD_4("AddPlayer", void, ICmpAIManager, AddPlayer, std::wstring, player_id_t, uint8_t, std::wstring) -DEFINE_INTERFACE_METHOD_1("SetRNGSeed", void, ICmpAIManager, SetRNGSeed, uint32_t) DEFINE_INTERFACE_METHOD_0("TryLoadSharedComponent", void, ICmpAIManager, TryLoadSharedComponent) DEFINE_INTERFACE_METHOD_0("RunGamestateInit", void, ICmpAIManager, RunGamestateInit) END_INTERFACE_WRAPPER(AIManager)