Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Setup.js
/** | /** | ||||
* Used to initialize non-player settings relevant to the map, like | * Used to initialize non-player settings relevant to the map, like | ||||
* default stance and victory conditions. DO NOT load players here | * default stance and victory conditions. DO NOT load players here | ||||
*/ | */ | ||||
function LoadMapSettings(settings) | function ParseMapSettings(gameSettings) | ||||
{ | { | ||||
var settings = gameSettings.settings; | |||||
if (!settings) | if (!settings) | ||||
settings = {}; | settings = {}; | ||||
if (settings.DefaultStance) | if (settings.DefaultStance) | ||||
for (let ent of Engine.GetEntitiesWithInterface(IID_UnitAI)) | for (let ent of Engine.GetEntitiesWithInterface(IID_UnitAI)) | ||||
{ | { | ||||
let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); | ||||
cmpUnitAI.SwitchToStance(settings.DefaultStance); | cmpUnitAI.SwitchToStance(settings.DefaultStance); | ||||
Show All 23 Lines | function ParseMapSettings(gameSettings) | ||||
else if (settings.SupportedTriggerDifficulties) // used by Atlas and autostart games | else if (settings.SupportedTriggerDifficulties) // used by Atlas and autostart games | ||||
{ | { | ||||
let difficulties = Engine.ReadJSONFile("simulation/data/settings/trigger_difficulties.json").Data; | let difficulties = Engine.ReadJSONFile("simulation/data/settings/trigger_difficulties.json").Data; | ||||
let defaultDiff = difficulties.find(d => d.Name == settings.SupportedTriggerDifficulties.Default).Difficulty; | let defaultDiff = difficulties.find(d => d.Name == settings.SupportedTriggerDifficulties.Default).Difficulty; | ||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).SetDifficulty(defaultDiff); | Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).SetDifficulty(defaultDiff); | ||||
} | } | ||||
let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); | let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); | ||||
let gameSettings = { "victoryConditions": clone(settings.VictoryConditions) }; | let gameRuleset = { "victoryConditions": clone(settings.VictoryConditions) }; | ||||
if (gameSettings.victoryConditions.indexOf("capture_the_relic") != -1) | if (gameRuleset.victoryConditions.indexOf("capture_the_relic") != -1) | ||||
{ | { | ||||
gameSettings.relicCount = settings.RelicCount; | gameRuleset.relicCount = settings.RelicCount; | ||||
gameSettings.relicDuration = settings.RelicDuration * 60 * 1000; | gameRuleset.relicDuration = settings.RelicDuration * 60 * 1000; | ||||
} | } | ||||
if (gameSettings.victoryConditions.indexOf("wonder") != -1) | if (gameRuleset.victoryConditions.indexOf("wonder") != -1) | ||||
gameSettings.wonderDuration = settings.WonderDuration * 60 * 1000; | gameRuleset.wonderDuration = settings.WonderDuration * 60 * 1000; | ||||
if (gameSettings.victoryConditions.indexOf("regicide") != -1) | if (gameRuleset.victoryConditions.indexOf("regicide") != -1) | ||||
gameSettings.regicideGarrison = settings.RegicideGarrison; | gameRuleset.regicideGarrison = settings.RegicideGarrison; | ||||
cmpEndGameManager.SetGameSettings(gameSettings); | cmpEndGameManager.SetGameSettings(gameRuleset); | ||||
cmpEndGameManager.SetAlliedVictory(settings.LockTeams || !settings.LastManStanding); | cmpEndGameManager.SetAlliedVictory(settings.LockTeams || !settings.LastManStanding); | ||||
if (settings.LockTeams && settings.LastManStanding) | if (settings.LockTeams && settings.LastManStanding) | ||||
warn("Last man standing is only available in games with unlocked teams!"); | warn("Last man standing is only available in games with unlocked teams!"); | ||||
let cmpCeasefireManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager); | let cmpCeasefireManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager); | ||||
if (settings.Ceasefire) | if (settings.Ceasefire) | ||||
cmpCeasefireManager.StartCeasefire(settings.Ceasefire * 60 * 1000); | cmpCeasefireManager.StartCeasefire(settings.Ceasefire * 60 * 1000); | ||||
} | } | ||||
Engine.RegisterGlobal("LoadMapSettings", LoadMapSettings); | Engine.RegisterGlobal("ParseMapSettings", ParseMapSettings); |
Wildfire Games · Phabricator