From d04fb4c69a41cb092b5259e121664da2ad4f8c9b Mon Sep 17 00:00:00 2001 From: James Sherratt Date: Fri, 4 Jun 2021 00:16:57 +0100 Subject: [PATCH] js files updated and based off of A24, not A23. (#6) --- .../common/gamedescription_CartographyMode.js | 16 +- .../Checkboxes/AlliedMap.js} | 10 +- ...GB.public-gui-gamesetup-CartographyMode.po | 2 +- a24/mod.json | 2 +- a24/simulation/helpers/InitGame.js | 162 +++++++++++------- 5 files changed, 117 insertions(+), 75 deletions(-) rename a24/gui/gamesetup/Pages/GameSetupPage/GameSettings/{_AlliedMap_CheckBox.js => Single/Checkboxes/AlliedMap.js} (81%) diff --git a/a24/gui/common/gamedescription_CartographyMode.js b/a24/gui/common/gamedescription_CartographyMode.js index 89a4469..6763f60 100644 --- a/a24/gui/common/gamedescription_CartographyMode.js +++ b/a24/gui/common/gamedescription_CartographyMode.js @@ -200,6 +200,15 @@ function getGameDescriptionList(mapCache) g_GameAttributes.settings.PopulationCap)] }); + if (g_GameAttributes.settings.WorldPopulationCap !== undefined) + titles.push({ + "label": translate("World Population Cap"), + "value": + g_WorldPopulationCapacities.Title[ + g_WorldPopulationCapacities.Population.indexOf( + g_GameAttributes.settings.WorldPopulationCap)] + }); + titles.push({ "label": translate("Treasures"), "value": g_GameAttributes.settings.DisableTreasures ? @@ -222,7 +231,7 @@ function getGameDescriptionList(mapCache) "value": g_GameAttributes.settings.CheatsEnabled }); - return titles + return titles; } function modDescriptions(mapCache, titles) { @@ -239,8 +248,7 @@ function getGameDescription(mapCache) { return titles.map(title => sprintf(translate("%(label)s %(details)s"), { "label": coloredText(title.label, g_DescriptionHighlight), "details": - title.value === true ? translateWithContext("gamesetup option", "enabled") : - title.value || translateWithContext("gamesetup option", "disabled") + title.value === true ? translateWithContext("game setup option", "enabled") : + title.value || translateWithContext("game setup option", "disabled") })).join("\n"); } - diff --git a/a24/gui/gamesetup/Pages/GameSetupPage/GameSettings/_AlliedMap_CheckBox.js b/a24/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Checkboxes/AlliedMap.js similarity index 81% rename from a24/gui/gamesetup/Pages/GameSetupPage/GameSettings/_AlliedMap_CheckBox.js rename to a24/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Checkboxes/AlliedMap.js index 040b9d3..e92ba70 100644 --- a/a24/gui/gamesetup/Pages/GameSetupPage/GameSettings/_AlliedMap_CheckBox.js +++ b/a24/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Checkboxes/AlliedMap.js @@ -1,12 +1,12 @@ -// This needs loading before GameSettingsLayout, so filename begins with "_". GameSettingControls.AlliedMap = class extends GameSettingControlCheckbox { onMapChange(mapData) { - let mapValue = - mapData && + let mapValue; + if (mapData && mapData.settings && - mapData.settings.AllyMap || undefined; + mapData.settings.AllyMap !== undefined) + mapValue = mapData.settings.AllyMap; if (mapValue !== undefined && mapValue != g_GameAttributes.settings.AllyMap) { @@ -51,9 +51,7 @@ GameSettingControls.AlliedMap = class extends GameSettingControlCheckbox }; GameSettingControls.AlliedMap.prototype.TitleCaption = - // Translation: Make sure to differentiate between the revealed map and settings! translate("Allied Map"); GameSettingControls.AlliedMap.prototype.Tooltip = - // Translation: Make sure to differentiate between the revealed map and settings! translate("Toggle allied map (see what your allies see)."); diff --git a/a24/l10n/en_GB.public-gui-gamesetup-CartographyMode.po b/a24/l10n/en_GB.public-gui-gamesetup-CartographyMode.po index 104feec..c3fb8d7 100644 --- a/a24/l10n/en_GB.public-gui-gamesetup-CartographyMode.po +++ b/a24/l10n/en_GB.public-gui-gamesetup-CartographyMode.po @@ -8,4 +8,4 @@ msgstr "Ally Map" #. ally map settings! #: gui/gamesetup/gamesetup_CarographyMode.js msgid "Toggle allied map (see everything you + allies can see)." -msgstr "Toggle allied map (see everything you + allies can see)." \ No newline at end of file +msgstr "Toggle allied map (see everything you + allies can see)." diff --git a/a24/mod.json b/a24/mod.json index 09a8ff2..6dfc195 100644 --- a/a24/mod.json +++ b/a24/mod.json @@ -1,6 +1,6 @@ { "name": "CartographyMode", - "version": "1.0.0", + "version": "1.0.1", "label": "Cartography Mode", "description": "Start a game with \"cartography mode\" set for all players.", "dependencies": ["0ad=0.0.24"] diff --git a/a24/simulation/helpers/InitGame.js b/a24/simulation/helpers/InitGame.js index 98d98c7..a4873b5 100644 --- a/a24/simulation/helpers/InitGame.js +++ b/a24/simulation/helpers/InitGame.js @@ -1,64 +1,100 @@ -function InitGame(settings) -{ - // No settings when loading a map in Atlas, so do nothing - if (!settings) - { - // Map dependent initialisations of components (i.e. garrisoned units) - Engine.BroadcastMessage(MT_InitGame, {}); - return; - } +/** + * Called when the map has been loaded, but before the simulation has started. + * Only called when a new game is started, not when loading a saved game. + */ + function PreInitGame() + { + // We need to replace skirmish "default" entities with real ones. + // This needs to happen before AI initialization (in InitGame). + // And we need to flush destroyed entities otherwise the AI gets the wrong game state in + // the beginning and a bunch of "destroy" messages on turn 0, which just shouldn't happen. + Engine.BroadcastMessage(MT_SkirmishReplace, {}); + Engine.FlushDestroyedEntities(); + + let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers(); + for (let i = 1; i < numPlayers; ++i) // ignore gaia + { + let cmpTechnologyManager = QueryPlayerIDInterface(i, IID_TechnologyManager); + if (cmpTechnologyManager) + cmpTechnologyManager.UpdateAutoResearch(); + } + + // Explore the map inside the players' territory borders + let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + cmpRangeManager.ExploreTerritories(); + } + + function InitGame(settings) + { + // No settings when loading a map in Atlas, so do nothing + if (!settings) + { + // Map dependent initialisations of components (i.e. garrisoned units) + Engine.BroadcastMessage(MT_InitGame, {}); + return; + } + + if (settings.ExploreMap) + { + let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + for (let i = 1; i < settings.PlayerData.length; ++i) + cmpRangeManager.ExploreAllTiles(i); + } - if (settings.ExploreMap) - { - let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); - for (let i = 1; i < settings.PlayerData.length; ++i) - cmpRangeManager.ExploreAllTiles(i); - } - - if (settings.AllyMap) - { - for (let i = 1; i < settings.PlayerData.length; ++i) - { - let cmpPlayer = QueryPlayerIDInterface(i); - let cmpTechnologyManager = Engine.QueryInterface(cmpPlayer.entity, IID_TechnologyManager); - if (cmpTechnologyManager) - { - cmpTechnologyManager.ResearchTechnology(cmpPlayer.template.SharedLosTech); - cmpPlayer.UpdateSharedLos(); - } - } - } - - // Sandbox, Very Easy, Easy, Medium, Hard, Very Hard - // rate apply on resource stockpiling as gathering and trading - // time apply on building, upgrading, packing, training and technologies - let rate = [ 0.42, 0.56, 0.75, 1.00, 1.25, 1.56 ]; - let time = [ 1.40, 1.25, 1.10, 1.00, 1.00, 1.00 ]; - let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); - let cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager); - for (let i = 0; i < settings.PlayerData.length; ++i) - { - let cmpPlayer = QueryPlayerIDInterface(i); - cmpPlayer.SetCheatsEnabled(!!settings.CheatsEnabled); - - if (settings.PlayerData[i] && !!settings.PlayerData[i].AI) - { - let AIDiff = +settings.PlayerData[i].AIDiff; - cmpAIManager.AddPlayer(settings.PlayerData[i].AI, i, AIDiff, settings.PlayerData[i].AIBehavior || "random"); - cmpPlayer.SetAI(true); - AIDiff = Math.min(AIDiff, rate.length - 1); - cmpModifiersManager.AddModifiers("AI Bonus", { - "ResourceGatherer/BaseSpeed": [{ "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] }], - "Trader/GainMultiplier": [{ "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] }], - "Cost/BuildTime": [{ "affects": ["Unit", "Structure"], "multiply": time[AIDiff] }], - }, cmpPlayer.entity); - } - } - // Map or player data (handicap...) dependent initialisations of components (i.e. garrisoned units) - Engine.BroadcastMessage(MT_InitGame, {}); - - cmpAIManager.TryLoadSharedComponent(); - cmpAIManager.RunGamestateInit(); -} - -Engine.RegisterGlobal("InitGame", InitGame); + if (settings.AllyMap) + { + for (let i = 1; i < settings.PlayerData.length; ++i) + { + let cmpPlayer = QueryPlayerIDInterface(i); + let cmpTechnologyManager = Engine.QueryInterface(cmpPlayer.entity, IID_TechnologyManager); + if (cmpTechnologyManager) + { + cmpTechnologyManager.ResearchTechnology(cmpPlayer.template.SharedLosTech); + cmpPlayer.UpdateSharedLos(); + } + } + } + + // Sandbox, Very Easy, Easy, Medium, Hard, Very Hard + // rate apply on resource stockpiling as gathering and trading + // time apply on building, upgrading, packing, training and technologies + let rate = [ 0.42, 0.56, 0.75, 1.00, 1.25, 1.56 ]; + let time = [ 1.40, 1.25, 1.10, 1.00, 1.00, 1.00 ]; + let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); + let cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager); + for (let i = 0; i < settings.PlayerData.length; ++i) + { + let cmpPlayer = QueryPlayerIDInterface(i); + cmpPlayer.SetCheatsEnabled(!!settings.CheatsEnabled); + + if (settings.PlayerData[i] && !!settings.PlayerData[i].AI) + { + let AIDiff = +settings.PlayerData[i].AIDiff; + cmpAIManager.AddPlayer(settings.PlayerData[i].AI, i, AIDiff, settings.PlayerData[i].AIBehavior || "random"); + cmpPlayer.SetAI(true); + AIDiff = Math.min(AIDiff, rate.length - 1); + cmpModifiersManager.AddModifiers("AI Bonus", { + "ResourceGatherer/BaseSpeed": [{ "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] }], + "Trader/GainMultiplier": [{ "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] }], + "Cost/BuildTime": [{ "affects": ["Unit", "Structure"], "multiply": time[AIDiff] }], + }, cmpPlayer.entity); + } + + if (settings.PopulationCap) + cmpPlayer.SetMaxPopulation(settings.PopulationCap); + } + if (settings.WorldPopulationCap) + Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).SetMaxWorldPopulation(settings.WorldPopulationCap); + + // Update the grid with all entities created for the map init. + Engine.QueryInterface(SYSTEM_ENTITY, IID_Pathfinder).UpdateGrid(); + + // Map or player data (handicap...) dependent initialisations of components (i.e. garrisoned units). + Engine.BroadcastMessage(MT_InitGame, {}); + + cmpAIManager.TryLoadSharedComponent(); + cmpAIManager.RunGamestateInit(); + } + + Engine.RegisterGlobal("PreInitGame", PreInitGame); + Engine.RegisterGlobal("InitGame", InitGame);