Index: binaries/data/mods/public/maps/random/polar_sea_triggers.js =================================================================== --- binaries/data/mods/public/maps/random/polar_sea_triggers.js +++ binaries/data/mods/public/maps/random/polar_sea_triggers.js @@ -18,7 +18,7 @@ Trigger.prototype.DisableTechnologies = function() { for (let i = 1; i < TriggerHelper.GetNumberOfPlayers(); ++i) - QueryPlayerIDInterface(i).SetDisabledTechnologies([ + QueryPlayerIDInterface(i, IID_TechnologyManager).SetDisabledTechnologies([ "gather_lumbering_ironaxes", "gather_lumbering_sharpaxes", "gather_lumbering_strongeraxes", Index: binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js =================================================================== --- binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js +++ binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js @@ -137,10 +137,9 @@ Trigger.prototype.SetDisableTemplates = function() { for (let i = 1; i < TriggerHelper.GetNumberOfPlayers(); ++i) - { - let cmpPlayer = QueryPlayerIDInterface(i); - cmpPlayer.SetDisabledTemplates(disabledTemplates(cmpPlayer.GetCiv())); - } + QueryPlayerIDInterface(i, IID_TechnologyManager).SetDisabledTemplates( + disabledTemplates(QueryPlayerIDInterface(i).GetCiv()) + ); }; /** Index: binaries/data/mods/public/simulation/ai/common-api/gamestate.js =================================================================== --- binaries/data/mods/public/simulation/ai/common-api/gamestate.js +++ binaries/data/mods/public/simulation/ai/common-api/gamestate.js @@ -44,7 +44,7 @@ if (techData._definesPair) { // Randomly pick a non-disabled choice from the phase-pair. - techName = pickRandom([techData._template.top, techData._template.bottom].filter(tech => !this.playerData.disabledTechnologies[tech])) || techData._template.top; + techName = pickRandom([techData._template.top, techData._template.bottom].filter(tech => !this.playerData.disabledTechnologies.has(tech))) || techData._template.top; let supersedes = techData._template.supersedes; techData = clone(this.getTemplate(techName)); @@ -220,7 +220,7 @@ /** this is an "in-absolute" check that doesn't check if we have a building to research from. */ m.GameState.prototype.canResearch = function(techTemplateName, noRequirementCheck) { - if (this.playerData.disabledTechnologies[techTemplateName]) + if (this.playerData.disabledTechnologies.has(techTemplateName)) return false; let template = this.getTemplate(techTemplateName); @@ -747,7 +747,7 @@ if (!searchable) continue; for (let tech of searchable) - if (!this.playerData.disabledTechnologies[tech] && allResearchable.indexOf(tech) === -1) + if (!this.playerData.disabledTechnologies.has(tech) && allResearchable.indexOf(tech) === -1) allResearchable.push(tech); } @@ -901,9 +901,7 @@ m.GameState.prototype.isTemplateDisabled = function(templateName) { - if (!this.playerData.disabledTemplates[templateName]) - return false; - return this.playerData.disabledTemplates[templateName]; + return this.playerData.disabledTemplates.has(templateName); }; /** Checks whether the maximum number of buildings have been constructed for a certain catergory */ Index: binaries/data/mods/public/simulation/components/Builder.js =================================================================== --- binaries/data/mods/public/simulation/components/Builder.js +++ binaries/data/mods/public/simulation/components/Builder.js @@ -45,11 +45,11 @@ let entities = string.replace(/\{civ\}/g, cmpPlayer.GetCiv()).split(/\s+/); - let disabledTemplates = cmpPlayer.GetDisabledTemplates(); + const disabledTemplates = QueryOwnerInterface(this.entity, IID_TechnologyManager)?.GetDisabledTemplates() || new Set(); let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); - return entities.filter(ent => !disabledTemplates[ent] && cmpTemplateManager.TemplateExists(ent)); + return entities.filter(ent => !disabledTemplates.has(ent) && cmpTemplateManager.TemplateExists(ent)); }; Builder.prototype.GetRange = function() Index: binaries/data/mods/public/simulation/components/GuiInterface.js =================================================================== --- binaries/data/mods/public/simulation/components/GuiInterface.js +++ binaries/data/mods/public/simulation/components/GuiInterface.js @@ -107,8 +107,8 @@ "team": cmpPlayer.GetTeam(), "teamsLocked": cmpPlayer.GetLockTeams(), "cheatsEnabled": cmpPlayer.GetCheatsEnabled(), - "disabledTemplates": cmpPlayer.GetDisabledTemplates(), - "disabledTechnologies": cmpPlayer.GetDisabledTechnologies(), + "disabledTemplates": cmpTechnologyManager ? cmpTechnologyManager.GetDisabledTemplates() : null, + "disabledTechnologies": cmpTechnologyManager ? cmpTechnologyManager.GetDisabledTechnologies() : null, "hasSharedDropsites": cmpPlayer.HasSharedDropsites(), "hasSharedLos": cmpPlayer.HasSharedLos(), "spyCostMultiplier": cmpPlayer.GetSpyCostMultiplier(), Index: binaries/data/mods/public/simulation/components/Player.js =================================================================== --- binaries/data/mods/public/simulation/components/Player.js +++ binaries/data/mods/public/simulation/components/Player.js @@ -74,8 +74,6 @@ this.cheatsEnabled = false; this.panelEntities = []; this.resourceNames = {}; - this.disabledTemplates = {}; - this.disabledTechnologies = {}; this.spyCostMultiplier = +this.template.SpyCostMultiplier; this.barterEntities = []; this.barterMultiplier = { @@ -905,56 +903,6 @@ }); }; -Player.prototype.AddDisabledTemplate = function(template) -{ - this.disabledTemplates[template] = true; - Engine.BroadcastMessage(MT_DisabledTemplatesChanged, { "player": this.playerID }); -}; - -Player.prototype.RemoveDisabledTemplate = function(template) -{ - this.disabledTemplates[template] = false; - Engine.BroadcastMessage(MT_DisabledTemplatesChanged, { "player": this.playerID }); -}; - -Player.prototype.SetDisabledTemplates = function(templates) -{ - this.disabledTemplates = {}; - for (let template of templates) - this.disabledTemplates[template] = true; - Engine.BroadcastMessage(MT_DisabledTemplatesChanged, { "player": this.playerID }); -}; - -Player.prototype.GetDisabledTemplates = function() -{ - return this.disabledTemplates; -}; - -Player.prototype.AddDisabledTechnology = function(tech) -{ - this.disabledTechnologies[tech] = true; - Engine.BroadcastMessage(MT_DisabledTechnologiesChanged, { "player": this.playerID }); -}; - -Player.prototype.RemoveDisabledTechnology = function(tech) -{ - this.disabledTechnologies[tech] = false; - Engine.BroadcastMessage(MT_DisabledTechnologiesChanged, { "player": this.playerID }); -}; - -Player.prototype.SetDisabledTechnologies = function(techs) -{ - this.disabledTechnologies = {}; - for (let tech of techs) - this.disabledTechnologies[tech] = true; - Engine.BroadcastMessage(MT_DisabledTechnologiesChanged, { "player": this.playerID }); -}; - -Player.prototype.GetDisabledTechnologies = function() -{ - return this.disabledTechnologies; -}; - Player.prototype.OnGlobalPlayerDefeated = function(msg) { let cmpSound = Engine.QueryInterface(this.entity, IID_Sound); Index: binaries/data/mods/public/simulation/components/Researcher.js =================================================================== --- binaries/data/mods/public/simulation/components/Researcher.js +++ binaries/data/mods/public/simulation/components/Researcher.js @@ -184,10 +184,9 @@ if (!cmpTechnologyManager) return []; - const cmpPlayer = QueryOwnerInterface(this.entity); - if (!cmpPlayer) + const civ = QueryOwnerInterface(this.entity)?.GetCiv(); + if (!civ) return []; - const civ = cmpPlayer.GetCiv(); let techs = string.split(/\s+/); @@ -210,13 +209,13 @@ const techList = []; const superseded = {}; - const disabledTechnologies = cmpPlayer.GetDisabledTechnologies(); + const disabledTechnologies = cmpTechnologyManager.GetDisabledTechnologies(); // Add any top level technologies to an array which corresponds to the displayed icons. // Also store what technology is superseded in the superseded object { "tech1":"techWhichSupercedesTech1", ... }. for (const tech of techs) { - if (disabledTechnologies && disabledTechnologies[tech]) + if (disabledTechnologies?.has(tech)) continue; const template = TechnologyTemplates.Get(tech); Index: binaries/data/mods/public/simulation/components/TechnologyManager.js =================================================================== --- binaries/data/mods/public/simulation/components/TechnologyManager.js +++ binaries/data/mods/public/simulation/components/TechnologyManager.js @@ -204,6 +204,9 @@ this.typeCountsByClass = {}; // stores the number of entities of each type for each class i.e. // {"someClass": {"unit/spearman": 2, "unit/cav": 5} "someOtherClass":...} + this.disabledTechnologies = new Set(); + this.disabledTemplates = new Set(); + // Some technologies are automatically researched when their conditions are met. They have no cost and are // researched instantly. This allows civ bonuses and more complicated technologies. this.unresearchedAutoResearchTechs = new Set(); @@ -214,8 +217,10 @@ }; TechnologyManager.prototype.SerializableAttributes = [ - "researchedTechs", "classCounts", + "disabledTechnologies", + "disabledTemplates", + "researchedTechs", "typeCountsByClass", "unresearchedAutoResearchTechs" ]; @@ -549,4 +554,96 @@ return this.typeCountsByClass; }; +/** + * @param {string} tech - + */ +TechnologyManager.prototype.AddDisabledTechnology = function(tech) +{ + if (this.disabledTechnologies.has(tech)) + return; + this.disabledTechnologies.add(tech); + Engine.BroadcastMessage(MT_DisabledTechnologiesChanged, { + "player": Engine.QueryInterface(this.entity, IID_Player).GetPlayerID() + }); +}; + +/** + * @param {string} tech - + */ +TechnologyManager.prototype.RemoveDisabledTechnology = function(tech) +{ + if (this.disabledTechnologies.delete(tech)) + Engine.BroadcastMessage(MT_DisabledTechnologiesChanged, { + "player": Engine.QueryInterface(this.entity, IID_Player).GetPlayerID() + }); +}; + +/** + * Enables previously disabled technologies. + * @param {string[]} techs - The technologies to disable. + */ +TechnologyManager.prototype.SetDisabledTechnologies = function(techs) +{ + this.disabledTechnologies.clear(); + for (const tech of techs) + this.disabledTechnologies.add(tech); + Engine.BroadcastMessage(MT_DisabledTechnologiesChanged, { + "player": Engine.QueryInterface(this.entity, IID_Player).GetPlayerID() + }); +}; + +/** + * @return {Set} - The currently disabled technologies. + */ +TechnologyManager.prototype.GetDisabledTechnologies = function() +{ + return this.disabledTechnologies; +}; + +/** + * @param {string} template - + */ +TechnologyManager.prototype.AddDisabledTemplate = function(template) +{ + if (this.disabledTemplates.has(template)) + return; + this.disabledTemplates.add(template); + Engine.BroadcastMessage(MT_DisabledTemplatesChanged, { + "player": Engine.QueryInterface(this.entity, IID_Player).GetPlayerID() + }); +}; + +/** + * @param {string} template - + */ +TechnologyManager.prototype.RemoveDisabledTemplate = function(template) +{ + if (this.disabledTemplates.delete(template)) + Engine.BroadcastMessage(MT_DisabledTemplatesChanged, { + "player": Engine.QueryInterface(this.entity, IID_Player).GetPlayerID() + }); +}; + +/** + * Enables previously disabled templates. + * @param {string[]} techs - The templates to disable. + */ +TechnologyManager.prototype.SetDisabledTemplates = function(templates) +{ + this.disabledTemplates.clear(); + for (const template of templates) + this.disabledTemplates.add(template); + Engine.BroadcastMessage(MT_DisabledTemplatesChanged, { + "player": Engine.QueryInterface(this.entity, IID_Player).GetPlayerID() + }); +}; + +/** + * @return {Set} - The currently disabled templates. + */ +TechnologyManager.prototype.GetDisabledTemplates = function() +{ + return this.disabledTemplates; +}; + Engine.RegisterComponentType(IID_TechnologyManager, "TechnologyManager", TechnologyManager); Index: binaries/data/mods/public/simulation/components/Trainer.js =================================================================== --- binaries/data/mods/public/simulation/components/Trainer.js +++ binaries/data/mods/public/simulation/components/Trainer.js @@ -479,9 +479,6 @@ addedTokens = addedTokens == "" ? [] : addedTokens.split(/\s+/); const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); - const cmpPlayer = QueryOwnerInterface(this.entity); - - const disabledEntities = cmpPlayer ? cmpPlayer.GetDisabledTemplates() : {}; /** * Process tokens: @@ -512,8 +509,9 @@ for (const tok of addedTokens) toks.push(tok); + const disabledEntities = QueryOwnerInterface(this.entity, IID_TechnologyManager)?.GetDisabledTemplates() || new Set(); const nativeCiv = Engine.QueryInterface(this.entity, IID_Identity)?.GetCiv(); - const playerCiv = cmpPlayer?.GetCiv(); + const playerCiv = QueryOwnerInterface(this.entity)?.GetCiv(); const addedDict = addedTokens.reduce((out, token) => { out[token] = true; return out; }, {}); this.entitiesMap = toks.reduce((entMap, token) => { @@ -538,7 +536,7 @@ token = token.replace(/\{civ\}/g, playerCiv); // Filter out disabled and invalid entities. - if (disabledEntities[token] || !cmpTemplateManager.TemplateExists(token)) + if (disabledEntities.has(token) || !cmpTemplateManager.TemplateExists(token)) { removeAllQueuedTemplate(rawToken); return entMap; Index: binaries/data/mods/public/simulation/components/interfaces/Player.js =================================================================== --- binaries/data/mods/public/simulation/components/interfaces/Player.js +++ binaries/data/mods/public/simulation/components/interfaces/Player.js @@ -12,18 +12,6 @@ Engine.RegisterMessageType("DiplomacyChanged"); /** - * Message of the form {} - * sent from Player component. - */ -Engine.RegisterMessageType("DisabledTechnologiesChanged"); - -/** - * Message of the form {} - * sent from Player component. - */ -Engine.RegisterMessageType("DisabledTemplatesChanged"); - -/** * Message of the form { "playerID": number } * sent from Player component when a player is defeated. */ Index: binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js =================================================================== --- binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js +++ binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js @@ -5,3 +5,15 @@ * sent from TechnologyManager component whenever a technology research is finished. */ Engine.RegisterMessageType("ResearchFinished"); + +/** + * Message of the form {} + * sent from the TechnologyManager component. + */ +Engine.RegisterMessageType("DisabledTechnologiesChanged"); + +/** + * Message of the form {} + * sent from the TechnologyManager component. + */ +Engine.RegisterMessageType("DisabledTemplatesChanged"); Index: binaries/data/mods/public/simulation/components/tests/test_Builder.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Builder.js +++ binaries/data/mods/public/simulation/components/tests/test_Builder.js @@ -4,6 +4,7 @@ Engine.LoadComponentScript("interfaces/Foundation.js"); Engine.LoadComponentScript("interfaces/Health.js"); Engine.LoadComponentScript("interfaces/Repairable.js"); +Engine.LoadComponentScript("interfaces/TechnologyManager.js"); Engine.LoadComponentScript("interfaces/Timer.js"); Engine.LoadComponentScript("interfaces/UnitAI.js"); Engine.LoadComponentScript("Builder.js"); @@ -41,10 +42,13 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "iber", - "GetDisabledTemplates": () => ({}), "GetPlayerID": () => playerId }); + AddMock(playerEntityID, IID_TechnologyManager, { + "GetDisabledTemplates": () => new Set() + }); + AddMock(builderId, IID_Ownership, { "GetOwner": () => playerId }); @@ -65,27 +69,25 @@ "TemplateExists": () => true }); - AddMock(playerEntityID, IID_Player, { - "GetCiv": () => "iber", - "GetDisabledTemplates": () => ({ "structures/athen/barracks": true }), - "GetPlayerID": () => playerId + AddMock(playerEntityID, IID_TechnologyManager, { + "GetDisabledTemplates": () => new Set(["structures/athen/barracks"]) }); TS_ASSERT_UNEVAL_EQUALS(cmpBuilder.GetEntitiesList(), ["structures/iber/barracks", "structures/iber/civil_centre", "structures/iber/house"]); - AddMock(playerEntityID, IID_Player, { - "GetCiv": () => "iber", - "GetDisabledTemplates": () => ({ "structures/iber/barracks": true }), - "GetPlayerID": () => playerId + AddMock(playerEntityID, IID_TechnologyManager, { + "GetDisabledTemplates": () => new Set(["structures/iber/barracks"]) }); TS_ASSERT_UNEVAL_EQUALS(cmpBuilder.GetEntitiesList(), ["structures/iber/civil_centre", "structures/iber/house"]); AddMock(playerEntityID, IID_Player, { "GetCiv": () => "athen", - "GetDisabledTemplates": () => ({ "structures/athen/barracks": true }), "GetPlayerID": () => playerId }); + AddMock(playerEntityID, IID_TechnologyManager, { + "GetDisabledTemplates": () => new Set(["structures/athen/barracks"]) + }); TS_ASSERT_UNEVAL_EQUALS(cmpBuilder.GetEntitiesList(), ["structures/athen/civil_centre", "structures/iber/house"]); Index: binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js +++ binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js @@ -120,8 +120,6 @@ "IsMutualAlly": function() { return false; }, "IsNeutral": function() { return false; }, "IsEnemy": function() { return true; }, - "GetDisabledTemplates": function() { return {}; }, - "GetDisabledTechnologies": function() { return {}; }, "CanBarter": function() { return false; }, "GetSpyCostMultiplier": function() { return 1; }, "HasSharedDropsites": function() { return false; }, @@ -136,6 +134,8 @@ }); AddMock(100, IID_TechnologyManager, { + "GetDisabledTemplates": function() { return new Set(); }, + "GetDisabledTechnologies": function() { return new Set(); }, "IsTechnologyResearched": tech => tech == "phase_village", "GetQueuedResearch": () => new Map(), "GetStartedTechs": () => new Set(), @@ -208,8 +208,6 @@ "IsMutualAlly": function() {return false; }, "IsNeutral": function() { return false; }, "IsEnemy": function() { return false; }, - "GetDisabledTemplates": function() { return {}; }, - "GetDisabledTechnologies": function() { return {}; }, "CanBarter": function() { return false; }, "GetSpyCostMultiplier": function() { return 1; }, "HasSharedDropsites": function() { return false; }, @@ -224,6 +222,8 @@ }); AddMock(101, IID_TechnologyManager, { + "GetDisabledTemplates": function() { return new Set(); }, + "GetDisabledTechnologies": function() { return new Set(); }, "IsTechnologyResearched": tech => tech == "phase_village", "GetQueuedResearch": () => new Map(), "GetStartedTechs": () => new Set(), @@ -296,8 +296,8 @@ "team": -1, "teamsLocked": false, "cheatsEnabled": false, - "disabledTemplates": {}, - "disabledTechnologies": {}, + "disabledTemplates": new Set(), + "disabledTechnologies": new Set(), "hasSharedDropsites": false, "hasSharedLos": false, "spyCostMultiplier": 1, @@ -346,8 +346,8 @@ "team": -1, "teamsLocked": false, "cheatsEnabled": false, - "disabledTemplates": {}, - "disabledTechnologies": {}, + "disabledTemplates": new Set(), + "disabledTechnologies": new Set(), "hasSharedDropsites": false, "hasSharedLos": false, "spyCostMultiplier": 1, @@ -406,8 +406,8 @@ "team": -1, "teamsLocked": false, "cheatsEnabled": false, - "disabledTemplates": {}, - "disabledTechnologies": {}, + "disabledTemplates": new Set(), + "disabledTechnologies": new Set(), "hasSharedDropsites": false, "hasSharedLos": false, "spyCostMultiplier": 1, @@ -479,8 +479,8 @@ "team": -1, "teamsLocked": false, "cheatsEnabled": false, - "disabledTemplates": {}, - "disabledTechnologies": {}, + "disabledTemplates": new Set(), + "disabledTechnologies": new Set(), "hasSharedDropsites": false, "hasSharedLos": false, "spyCostMultiplier": 1, Index: binaries/data/mods/public/simulation/components/tests/test_Researcher.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Researcher.js +++ binaries/data/mods/public/simulation/components/tests/test_Researcher.js @@ -24,11 +24,11 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "iber", - "GetDisabledTechnologies": () => ({}) // ToDo: Should be in the techmanager. }); AddMock(playerEntityID, IID_TechnologyManager, { "CheckTechnologyRequirements": () => true, + "GetDisabledTechnologies": () => new Set(), "IsInProgress": () => false, "IsTechnologyResearched": () => false }); @@ -54,12 +54,19 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "athen", - "GetDisabledTechnologies": () => ({ "gather_fishing_net": true }) +}); + +AddMock(playerEntityID, IID_TechnologyManager, { + "CheckTechnologyRequirements": () => true, + "GetDisabledTechnologies": () => new Set(["gather_fishing_net"]), + "IsInProgress": () => false, + "IsTechnologyResearched": () => false }); TS_ASSERT_UNEVAL_EQUALS(cmpResearcher.GetTechnologiesList(), ["phase_town_athen", "phase_city_athen"]); AddMock(playerEntityID, IID_TechnologyManager, { "CheckTechnologyRequirements": () => true, + "GetDisabledTechnologies": () => new Set(["gather_fishing_net"]), "IsInProgress": () => false, "IsTechnologyResearched": tech => tech == "phase_town_athen" }); @@ -67,7 +74,12 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "iber", - "GetDisabledTechnologies": () => ({}) +}); +AddMock(playerEntityID, IID_TechnologyManager, { + "CheckTechnologyRequirements": () => true, + "GetDisabledTechnologies": () => new Set(), + "IsInProgress": () => false, + "IsTechnologyResearched": tech => tech == "phase_town_athen" }); TS_ASSERT_UNEVAL_EQUALS( cmpResearcher.GetTechnologiesList(), @@ -96,11 +108,11 @@ const cmpPlayer = AddMock(playerEntityID, IID_Player, { "GetCiv": () => "iber", - "GetDisabledTechnologies": () => ({}), "GetPlayerID": () => playerID, }); const techManager = AddMock(playerEntityID, IID_TechnologyManager, { "CheckTechnologyRequirements": () => true, + "GetDisabledTechnologies": () => new Set(), "IsInProgress": () => false, "IsTechnologyResearched": () => false, "QueuedResearch": (templateName, researcher, techCostMultiplier) => { Index: binaries/data/mods/public/simulation/components/tests/test_Technologies.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Technologies.js +++ binaries/data/mods/public/simulation/components/tests/test_Technologies.js @@ -87,6 +87,7 @@ "Sell": {} } }); +cmpPlayer.SetCiv("gaia"); const spyPlayerResSub = new Spy(cmpPlayer, "TrySubtractResources"); const spyPlayerResRefund = new Spy(cmpPlayer, "RefundResources"); Index: binaries/data/mods/public/simulation/components/tests/test_Trainer.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Trainer.js +++ binaries/data/mods/public/simulation/components/tests/test_Trainer.js @@ -8,6 +8,7 @@ Engine.LoadComponentScript("interfaces/EntityLimits.js"); Engine.LoadComponentScript("interfaces/Foundation.js"); Engine.LoadComponentScript("interfaces/StatisticsTracker.js"); +Engine.LoadComponentScript("interfaces/TechnologyManager.js"); Engine.LoadComponentScript("interfaces/Trainer.js"); Engine.LoadComponentScript("interfaces/TrainingRestrictions.js"); Engine.LoadComponentScript("interfaces/Trigger.js"); @@ -40,7 +41,6 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "iber", - "GetDisabledTemplates": () => ({}), "GetPlayerID": () => playerID }); @@ -73,9 +73,11 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "iber", - "GetDisabledTemplates": () => ({ "units/athen/infantry_swordsman_b": true }), "GetPlayerID": () => playerID }); +AddMock(playerEntityID, IID_TechnologyManager, { + "GetDisabledTemplates": () => new Set(["units/athen/infantry_swordsman_b"]) +}); cmpTrainer.CalculateEntitiesMap(); TS_ASSERT_UNEVAL_EQUALS( @@ -85,9 +87,11 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "iber", - "GetDisabledTemplates": () => ({ "units/iber/infantry_swordsman_b": true }), "GetPlayerID": () => playerID }); +AddMock(playerEntityID, IID_TechnologyManager, { + "GetDisabledTemplates": () => new Set(["units/iber/infantry_swordsman_b"]) +}); cmpTrainer.CalculateEntitiesMap(); TS_ASSERT_UNEVAL_EQUALS( @@ -97,9 +101,11 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "athen", - "GetDisabledTemplates": () => ({ "units/athen/infantry_swordsman_b": true }), "GetPlayerID": () => playerID }); +AddMock(playerEntityID, IID_TechnologyManager, { + "GetDisabledTemplates": () => new Set(["units/athen/infantry_swordsman_b"]) +}); cmpTrainer.CalculateEntitiesMap(); TS_ASSERT_UNEVAL_EQUALS( @@ -109,9 +115,11 @@ AddMock(playerEntityID, IID_Player, { "GetCiv": () => "iber", - "GetDisabledTemplates": () => ({ "units/iber/infantry_swordsman_b": false }), "GetPlayerID": () => playerID }); +AddMock(playerEntityID, IID_TechnologyManager, { + "GetDisabledTemplates": () => new Set() +}); cmpTrainer.CalculateEntitiesMap(); TS_ASSERT_UNEVAL_EQUALS( @@ -163,7 +171,6 @@ "TryReservePopulationSlots": () => false, // Always have pop space. "UnReservePopulationSlots": () => {}, // Always have pop space. "UnBlockTraining": () => {}, - "GetDisabledTemplates": () => ({}) }); const spyCmpPlayerSubtract = new Spy(cmpPlayer, "TrySubtractResources"); const spyCmpPlayerRefund = new Spy(cmpPlayer, "RefundResources"); Index: binaries/data/mods/public/simulation/helpers/Player.js =================================================================== --- binaries/data/mods/public/simulation/helpers/Player.js +++ binaries/data/mods/public/simulation/helpers/Player.js @@ -127,8 +127,9 @@ // DisableSpies if (settings.DisableSpies) { - cmpPlayer.AddDisabledTechnology("unlock_spies"); - cmpPlayer.AddDisabledTemplate("special/spy"); + const cmpTechnologyManager = QueryPlayerIDInterface(i, IID_TechnologyManager); + cmpTechnologyManager.AddDisabledTechnology("unlock_spies"); + cmpTechnologyManager.AddDisabledTemplate("special/spy"); } // If diplomacy explicitly defined, use that; otherwise use teams