Allows trigger script with different difficulty levels

Reviewed By: elexis
Differential Revision: https://code.wildfiregames.com/D1189
This was SVN commit r20760.
This commit is contained in:
mimo
2018-01-03 11:21:37 +00:00
parent cdd96d8ae2
commit 9daa7520ef
6 changed files with 124 additions and 7 deletions
@@ -47,7 +47,8 @@ function loadSettingsValues()
"PlayerDefaults": loadPlayerDefaults(),
"PopulationCapacities": loadPopulationCapacities(),
"StartingResources": loadSettingValuesFile("starting_resources.json"),
"VictoryConditions": loadVictoryConditions()
"VictoryConditions": loadVictoryConditions(),
"TriggerDifficulties": loadSettingValuesFile("trigger_difficulties.json")
};
if (Object.keys(settings).some(key => settings[key] === undefined))
@@ -4,6 +4,7 @@ const g_MatchSettings_MP = "config/matchsettings.mp.json";
const g_Ceasefire = prepareForDropdown(g_Settings && g_Settings.Ceasefire);
const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes);
const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes);
const g_TriggerDifficulties = prepareForDropdown(g_Settings && g_Settings.TriggerDifficulties);
const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities);
const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources);
const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions);
@@ -207,6 +208,11 @@ var g_MapFilterList;
*/
var g_BiomeList;
/**
* Array of trigger difficulties identifiers supported by the currently selected map.
*/
var g_TriggerDifficultyList;
/**
* Whether this is a single- or multiplayer match.
*/
@@ -356,6 +362,7 @@ var g_OptionOrderGUI = {
"mapSize"
],
"more": [
"triggerDifficulty",
"biome",
"gameSpeed",
"victoryCondition",
@@ -646,6 +653,21 @@ var g_Dropdowns = {
},
"initOrder": 1000
},
"triggerDifficulty": {
"title": () => translate("Difficulty"),
"tooltip": (hoverIdx) => g_TriggerDifficultyList && g_TriggerDifficultyList.Description[hoverIdx] ||
translate("Select the difficulty of this scenario."),
"labels": () => g_TriggerDifficultyList ? g_TriggerDifficultyList.Title : [],
"ids": () => g_TriggerDifficultyList ? g_TriggerDifficultyList.Id : [],
"default": () => g_TriggerDifficultyList ? g_TriggerDifficultyList.Default : 0,
"defined": () => g_GameAttributes.settings.TriggerDifficulty !== undefined,
"get": () => g_GameAttributes.settings.TriggerDifficulty,
"select": (itemIdx) => {
g_GameAttributes.settings.TriggerDifficulty = g_TriggerDifficultyList && g_TriggerDifficultyList.Id[itemIdx];
},
"hidden": () => !g_TriggerDifficultyList,
"initOrder": 1000
},
};
/**
@@ -1499,6 +1521,15 @@ function reloadMapList()
initDropdown("mapSelection");
}
/**
* Initialize the dropdowns specific to each map.
*/
function reloadMapSpecific()
{
reloadBiomeList();
reloadTriggerDifficulties();
}
function reloadBiomeList()
{
let biomeList;
@@ -1528,6 +1559,35 @@ function reloadBiomeList()
initDropdown("biome");
}
function reloadTriggerDifficulties()
{
g_TriggerDifficultyList = undefined;
if (!g_GameAttributes.settings.SupportedTriggerDifficulties)
return;
let triggerDifficultyList;
if (g_GameAttributes.settings.SupportedTriggerDifficulties.Values === true)
triggerDifficultyList = g_Settings.TriggerDifficulties;
else
{
triggerDifficultyList = g_Settings.TriggerDifficulties.filter(
diff => g_GameAttributes.settings.SupportedTriggerDifficulties.Values.indexOf(diff.Name) != -1);
if (!triggerDifficultyList.length)
return;
}
g_TriggerDifficultyList = prepareForDropdown(
triggerDifficultyList.map(diff => ({
"Id": diff.Difficulty,
"Title": diff.Name,
"Description": diff.Tooltip,
"Default": diff.Name == g_GameAttributes.settings.SupportedTriggerDifficulties.Default
})));
initDropdown("triggerDifficulty");
}
function reloadGameSpeedChoices()
{
g_GameSpeeds = getGameSpeedChoices(Object.keys(g_PlayerAssignments).every(guid => g_PlayerAssignments[guid].player == -1));
@@ -1600,7 +1660,7 @@ function loadPersistMatchSettings()
// Reload, as the maptype or mapfilter might have changed
reloadMapFilterList();
reloadBiomeList();
reloadMapSpecific();
g_GameAttributes.settings.RatingEnabled = Engine.HasXmppClient();
Engine.SetRankedGame(g_GameAttributes.settings.RatingEnabled);
@@ -1735,7 +1795,7 @@ function ensureUniquePlayerColors(playerData)
function selectMap(name)
{
// Reset some map specific properties which are not necessarily redefined on each map
for (let prop of ["TriggerScripts", "CircularMap", "Garrison", "DisabledTemplates", "Biome", "SupportedBiomes"])
for (let prop of ["TriggerScripts", "CircularMap", "Garrison", "DisabledTemplates", "Biome", "SupportedBiomes", "SupportedTriggerDifficulties", "TriggerDifficulty"])
g_GameAttributes.settings[prop] = undefined;
let mapData = loadMapData(name);
@@ -1767,7 +1827,7 @@ function selectMap(name)
for (let prop in mapSettings)
g_GameAttributes.settings[prop] = mapSettings[prop];
reloadBiomeList();
reloadMapSpecific();
unassignInvalidPlayers(g_GameAttributes.settings.PlayerData.length);
supplementDefaults();
}
@@ -2000,7 +2060,7 @@ function updateGUIObjects()
g_IsInGuiUpdate = true;
reloadMapFilterList();
reloadBiomeList();
reloadMapSpecific();
reloadGameSpeedChoices();
reloadPlayerAssignmentChoices();
+3 -2
View File
@@ -596,10 +596,11 @@
"context": "startingResources"
}
},
{
{
"extractor": "json",
"filemasks": [
"simulation/data/settings/map_sizes.json"
"simulation/data/settings/map_sizes.json",
"simulation/data/settings/trigger_difficulties.json"
],
"options": {
"keywords": [
@@ -30,6 +30,8 @@ Trigger.prototype.eventNames =
Trigger.prototype.Init = function()
{
// Difficulty used by trigger scripts (as defined in data/settings/trigger_difficulties.json).
this.difficulty = 3;
this.triggerPoints = {};
// Each event has its own set of actions determined by the map maker.
@@ -330,4 +332,17 @@ Trigger.prototype.DoAction = function(msg)
warn("Trigger.js: called a trigger action '" + msg.action + "' that wasn't found");
};
/**
* Level of difficulty used by trigger scripts.
*/
Trigger.prototype.GetDifficulty = function(diff)
{
return this.difficulty;
};
Trigger.prototype.SetDifficulty = function(diff)
{
this.difficulty = diff;
};
Engine.RegisterSystemComponentType(IID_Trigger, "Trigger", Trigger);
@@ -0,0 +1,31 @@
{
"TranslatedKeys": ["Name", "Tooltip"],
"Data":
[
{
"Difficulty": 1,
"Name": "Very Easy",
"Tooltip": "Choose this difficulty if you are discovering 0 A.D.."
},
{
"Difficulty": 2,
"Name": "Easy",
"Tooltip": "Choose this difficulty if you do not like being knocked down."
},
{
"Difficulty": 3,
"Name": "Medium",
"Tooltip": "Choose this difficulty if you have already a good experience with 0 A.D.."
},
{
"Difficulty": 4,
"Name": "Hard",
"Tooltip": "Choose this difficulty if you want to be really challenged."
},
{
"Difficulty": 5,
"Name": "Very Hard",
"Tooltip": "Choose this difficulty if you do not mind being swept out."
}
]
}
@@ -43,6 +43,15 @@ function LoadMapSettings(settings)
cmpObstructionManager.SetPassabilityCircular(true);
}
if (settings.TriggerDifficulty)
Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).SetDifficulty(settings.TriggerDifficulty);
else if (settings.SupportedTriggerDifficulties) // used by Atlas and autostart games
{
let difficulties = Engine.ReadJSONFile("simulation/data/settings/trigger_difficulties.json").Data;
let defaultDiff = difficulties.find(d => d.Name == settings.SupportedTriggerDifficulties.Default).Difficulty;
Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).SetDifficulty(defaultDiff);
}
let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
let gameTypeSettings = {};
if (settings.GameType && settings.GameType == "capture_the_relic")