Ticket #2931: seed.2.diff
File seed.2.diff, 5.8 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/helpers/InitGame.js
51 51 cmpPlayer.SetResourceCounts(newResourceCounts); 52 52 } 53 53 } 54 let seed = settings.Seed ? settings.Seed : 0; 55 cmpAIManager.SetRNGSeed(seed); 54 56 cmpAIManager.TryLoadSharedComponent(); 55 57 cmpAIManager.RunGamestateInit(); 56 58 } -
source/ps/GameSetup/GameSetup.cpp
1162 1162 * Command line options for autostart (keep synchronized with readme.txt): 1163 1163 * 1164 1164 * -autostart="TYPEDIR/MAPNAME" enables autostart and sets MAPNAME; TYPEDIR is skirmishes, scenarios, or random 1165 * -autostart-ai=PLAYER:AI 1165 * -autostart-ai=PLAYER:AI sets the AI for PLAYER (e.g. 2:petra) 1166 1166 * -autostart-aidiff=PLAYER:DIFF sets the DIFFiculty of PLAYER's AI (0: easy, 3: very hard) 1167 1167 * -autostart-civ=PLAYER:CIV sets PLAYER's civilisation to CIV (skirmish and random maps only) 1168 * -autostart-seed=SEED sets (AI + random map) SEED value (default 0, use -1 for random) 1168 1169 * Multiplayer: 1169 1170 * -autostart-playername=NAME sets local player NAME (default 'anonymous') 1170 * -autostart-host 1171 * -autostart-host sets multiplayer host mode 1171 1172 * -autostart-host-players=NUMBER sets NUMBER of human players for multiplayer game (default 2) 1172 * -autostart-client=IP 1173 * -autostart-client=IP sets multiplayer client to join host at given IP address 1173 1174 * Random maps only: 1174 * -autostart-seed=SEED sets random map SEED value (default 0, use -1 for random) 1175 * -autostart-size=TILES sets random map size in TILES (default 192) 1175 * -autostart-size=TILES sets random map size in TILES (default 192) 1176 1176 * -autostart-players=NUMBER sets NUMBER of players on random map (default 2) 1177 1177 * 1178 1178 * Examples: … … 1218 1218 1219 1219 if (mapDirectory == L"random") 1220 1220 { 1221 // Default seed is 01222 u32 seed = 0;1223 CStr seedArg = args.Get("autostart-seed");1224 1225 if (!seedArg.empty())1226 {1227 // Random seed value1228 if (seedArg != "-1")1229 seed = rand();1230 else1231 seed = seedArg.ToULong();1232 }1233 1234 1221 // Random map definition will be loaded from JSON file, so we need to parse it 1235 1222 std::wstring scriptPath = L"maps/" + autoStartName.FromUTF8() + L".json"; 1236 1223 JS::RootedValue scriptData(cx); … … 1257 1244 mapSize = size.ToUInt(); 1258 1245 } 1259 1246 1260 scriptInterface.SetProperty(settings, "Seed", seed); // Random seed1261 1247 scriptInterface.SetProperty(settings, "Size", mapSize); // Random map size (in patches) 1262 1248 1263 1249 // Get optional number of players (default 2) … … 1307 1293 scriptInterface.SetProperty(attrs, "map", std::string("maps/" + autoStartName)); 1308 1294 scriptInterface.SetProperty(settings, "mapType", mapType); 1309 1295 1296 // Random seed value for random maps and AIs, default is 0 1297 u32 seed = 0; 1298 if (args.Has("autostart-seed")) 1299 { 1300 CStr seedArg = args.Get("autostart-seed"); 1301 if (seedArg == "-1") 1302 seed = rand(); 1303 else 1304 seed = seedArg.ToULong(); 1305 LOGWARNING(L"Autostart: random seed %d ", seed); 1306 } 1307 scriptInterface.SetProperty(settings, "Seed", seed); 1308 1310 1309 // Set player data for AIs 1311 1310 // attrs.settings = { PlayerData: [ { AI: ... }, ... ] }: 1312 1311 if (args.Has("autostart-ai")) -
source/simulation2/components/CCmpAIManager.cpp
225 225 m_HasSharedComponent(false) 226 226 { 227 227 228 // TODO: ought to seed the RNG (in a network-synchronised way) before we use it229 228 m_ScriptInterface->ReplaceNondeterministicRNG(m_RNG); 230 229 m_ScriptInterface->LoadGlobalScripts(); 231 230 … … 361 360 tex_write(&t, filename); 362 361 } 363 362 363 void SetRNGSeed(uint32_t seed) 364 { 365 m_RNG.seed(seed); 366 } 367 364 368 bool TryLoadSharedComponent(bool hasTechs) 365 369 { 366 370 JSContext* cx = m_ScriptInterface->GetContext(); … … 917 921 cmpRangeManager->SetLosRevealAll(player, true); 918 922 } 919 923 924 virtual void SetRNGSeed(uint32_t seed) 925 { 926 m_Worker.SetRNGSeed(seed); 927 } 928 920 929 virtual void TryLoadSharedComponent() 921 930 { 922 931 ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); -
source/simulation2/components/ICmpAIManager.cpp
26 26 27 27 BEGIN_INTERFACE_WRAPPER(AIManager) 28 28 DEFINE_INTERFACE_METHOD_3("AddPlayer", void, ICmpAIManager, AddPlayer, std::wstring, player_id_t, uint8_t) 29 DEFINE_INTERFACE_METHOD_1("SetRNGSeed", void, ICmpAIManager, SetRNGSeed, uint32_t) 29 30 DEFINE_INTERFACE_METHOD_0("TryLoadSharedComponent", void, ICmpAIManager, TryLoadSharedComponent) 30 31 DEFINE_INTERFACE_METHOD_0("RunGamestateInit", void, ICmpAIManager, RunGamestateInit) 31 32 END_INTERFACE_WRAPPER(AIManager) -
source/simulation2/components/ICmpAIManager.h
31 31 * to control player @p player. 32 32 */ 33 33 virtual void AddPlayer(std::wstring id, player_id_t player, uint8_t difficulty) = 0; 34 virtual void SetRNGSeed(uint32_t seed) = 0; 34 35 virtual void TryLoadSharedComponent() = 0; 35 36 virtual void RunGamestateInit() = 0; 36 37