use by default a random seed for the AI to make it less repetitive
This was SVN commit r15973.
This commit is contained in:
parent
94e6e29a34
commit
f88ee2766e
@ -806,6 +806,7 @@ function selectMapType(type)
|
||||
// TODO: This should be remembered from the last session
|
||||
g_GameAttributes.mapPath = "maps/scenarios/";
|
||||
g_GameAttributes.map = g_GameAttributes.mapPath + (g_IsNetworked ? DEFAULT_NETWORKED_MAP : DEFAULT_OFFLINE_MAP);
|
||||
g_GameAttributes.settings.AISeed = Math.floor(Math.random() * 65536);
|
||||
break;
|
||||
|
||||
case "skirmish":
|
||||
@ -813,6 +814,7 @@ function selectMapType(type)
|
||||
g_GameAttributes.settings = {
|
||||
PlayerData: g_DefaultPlayerData.slice(0, 4),
|
||||
Seed: Math.floor(Math.random() * 65536),
|
||||
AISeed: Math.floor(Math.random() * 65536),
|
||||
CheatsEnabled: g_GameAttributes.settings.CheatsEnabled
|
||||
};
|
||||
break;
|
||||
@ -822,6 +824,7 @@ function selectMapType(type)
|
||||
g_GameAttributes.settings = {
|
||||
PlayerData: g_DefaultPlayerData.slice(0, 4),
|
||||
Seed: Math.floor(Math.random() * 65536),
|
||||
AISeed: Math.floor(Math.random() * 65536),
|
||||
CheatsEnabled: g_GameAttributes.settings.CheatsEnabled
|
||||
};
|
||||
break;
|
||||
|
@ -51,6 +51,8 @@ function InitGame(settings)
|
||||
cmpPlayer.SetResourceCounts(newResourceCounts);
|
||||
}
|
||||
}
|
||||
let seed = settings.AISeed ? settings.AISeed : 0;
|
||||
cmpAIManager.SetRNGSeed(seed);
|
||||
cmpAIManager.TryLoadSharedComponent();
|
||||
cmpAIManager.RunGamestateInit();
|
||||
}
|
||||
|
@ -9,8 +9,9 @@ Basic gameplay:
|
||||
Autostart:
|
||||
-autostart="TYPEDIR/MAPNAME" enables autostart and sets MAPNAME; TYPEDIR is skirmishes, scenarios, or random
|
||||
-autostart-ai=PLAYER:AI sets the AI for PLAYER (e.g. 2:petra)
|
||||
-autostart-aidiff=PLAYER:DIFF sets the DIFFiculty of PLAYER's AI (0: easy, 3: very hard)
|
||||
-autostart-aidiff=PLAYER:DIFF sets the DIFFiculty of PLAYER's AI (0: sandbox, 4: very hard)
|
||||
-autostart-civ=PLAYER:CIV sets PLAYER's civilisation to CIV (skirmish and random maps only)
|
||||
-autostart-aiseed=AISEED sets the seed used for the AI random generator (default 0, use -1 for random)
|
||||
Multiplayer:
|
||||
-autostart-playername=NAME sets local player NAME (default 'anonymous')
|
||||
-autostart-host sets multiplayer host mode
|
||||
|
@ -1163,8 +1163,9 @@ CStr8 LoadSettingsOfScenarioMap(const VfsPath &mapPath)
|
||||
*
|
||||
* -autostart="TYPEDIR/MAPNAME" enables autostart and sets MAPNAME; TYPEDIR is skirmishes, scenarios, or random
|
||||
* -autostart-ai=PLAYER:AI sets the AI for PLAYER (e.g. 2:petra)
|
||||
* -autostart-aidiff=PLAYER:DIFF sets the DIFFiculty of PLAYER's AI (0: easy, 3: very hard)
|
||||
* -autostart-aidiff=PLAYER:DIFF sets the DIFFiculty of PLAYER's AI (0: sandbox, 4: very hard)
|
||||
* -autostart-civ=PLAYER:CIV sets PLAYER's civilisation to CIV (skirmish and random maps only)
|
||||
* -autostart-aiseed=AISEED sets the seed used for the AI random generator (default 0, use -1 for random)
|
||||
* Multiplayer:
|
||||
* -autostart-playername=NAME sets local player NAME (default 'anonymous')
|
||||
* -autostart-host sets multiplayer host mode
|
||||
@ -1225,7 +1226,7 @@ bool Autostart(const CmdLineArgs& args)
|
||||
if (!seedArg.empty())
|
||||
{
|
||||
// Random seed value
|
||||
if (seedArg != "-1")
|
||||
if (seedArg == "-1")
|
||||
seed = rand();
|
||||
else
|
||||
seed = seedArg.ToULong();
|
||||
@ -1307,6 +1308,18 @@ bool Autostart(const CmdLineArgs& args)
|
||||
scriptInterface.SetProperty(attrs, "map", std::string("maps/" + autoStartName));
|
||||
scriptInterface.SetProperty(settings, "mapType", mapType);
|
||||
|
||||
// Set seed for AIs
|
||||
u32 aiseed = 0;
|
||||
if (args.Has("autostart-aiseed"))
|
||||
{
|
||||
CStr seedArg = args.Get("autostart-aiseed");
|
||||
if (seedArg == "-1")
|
||||
aiseed = rand();
|
||||
else
|
||||
aiseed = seedArg.ToULong();
|
||||
}
|
||||
scriptInterface.SetProperty(settings, "AISeed", aiseed);
|
||||
|
||||
// Set player data for AIs
|
||||
// attrs.settings = { PlayerData: [ { AI: ... }, ... ] }:
|
||||
if (args.Has("autostart-ai"))
|
||||
|
@ -225,7 +225,6 @@ public:
|
||||
m_HasSharedComponent(false)
|
||||
{
|
||||
|
||||
// TODO: ought to seed the RNG (in a network-synchronised way) before we use it
|
||||
m_ScriptInterface->ReplaceNondeterministicRNG(m_RNG);
|
||||
m_ScriptInterface->LoadGlobalScripts();
|
||||
|
||||
@ -361,6 +360,11 @@ public:
|
||||
tex_write(&t, filename);
|
||||
}
|
||||
|
||||
void SetRNGSeed(uint32_t seed)
|
||||
{
|
||||
m_RNG.seed(seed);
|
||||
}
|
||||
|
||||
bool TryLoadSharedComponent(bool hasTechs)
|
||||
{
|
||||
JSContext* cx = m_ScriptInterface->GetContext();
|
||||
@ -917,6 +921,11 @@ public:
|
||||
cmpRangeManager->SetLosRevealAll(player, true);
|
||||
}
|
||||
|
||||
virtual void SetRNGSeed(uint32_t seed)
|
||||
{
|
||||
m_Worker.SetRNGSeed(seed);
|
||||
}
|
||||
|
||||
virtual void TryLoadSharedComponent()
|
||||
{
|
||||
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
BEGIN_INTERFACE_WRAPPER(AIManager)
|
||||
DEFINE_INTERFACE_METHOD_3("AddPlayer", void, ICmpAIManager, AddPlayer, std::wstring, player_id_t, uint8_t)
|
||||
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)
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
* to control player @p player.
|
||||
*/
|
||||
virtual void AddPlayer(std::wstring id, player_id_t player, uint8_t difficulty) = 0;
|
||||
virtual void SetRNGSeed(uint32_t seed) = 0;
|
||||
virtual void TryLoadSharedComponent() = 0;
|
||||
virtual void RunGamestateInit() = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user