From cc4af6d2d461e22746f59f3fc64689d73b202a79 Mon Sep 17 00:00:00 2001 From: sanderd17 Date: Fri, 19 Jun 2015 09:24:55 +0000 Subject: [PATCH] Allies only share vision when researching a tech. Based on patch by niektb. Fixes #2055 This was SVN commit r16795. --- .../portraits/technologies/shared_los.png | 3 ++ .../public/simulation/components/Player.js | 35 +++++++++++++------ .../components/TechnologyManager.js | 7 ++-- .../public/simulation/components/Trigger.js | 8 +++++ .../interfaces/TechnologyManager.js | 2 ++ .../data/technologies/unlock_shared_los.json | 11 ++++++ .../simulation/templates/special/player.xml | 4 ++- .../templates/special/player_gaia.xml | 4 ++- .../template_structure_economic_market.xml | 1 + 9 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 binaries/data/mods/public/art/textures/ui/session/portraits/technologies/shared_los.png create mode 100644 binaries/data/mods/public/simulation/data/technologies/unlock_shared_los.json diff --git a/binaries/data/mods/public/art/textures/ui/session/portraits/technologies/shared_los.png b/binaries/data/mods/public/art/textures/ui/session/portraits/technologies/shared_los.png new file mode 100644 index 0000000000..8a3d547104 --- /dev/null +++ b/binaries/data/mods/public/art/textures/ui/session/portraits/technologies/shared_los.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b5886a5a5a2fdf8d5c45ebc78a5b7c14cbf56242067961f6a111265314b2c85 +size 24069 diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index b8d942f901..1c4fa8341b 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -1,7 +1,9 @@ function Player() {} Player.prototype.Schema = - ""; + "" + + "" + + ""; Player.prototype.Init = function() { @@ -19,10 +21,12 @@ Player.prototype.Init = function() "metal": 300, "stone": 300 }; - this.tradingGoods = [ // goods for next trade-route and its proba in % (the sum of probas must be 100) + // goods for next trade-route and its proba in % (the sum of probas must be 100) + this.tradingGoods = [ { "goods": "wood", "proba": 30 }, { "goods": "stone", "proba": 35 }, - { "goods": "metal", "proba": 35 } ]; + { "goods": "metal", "proba": 35 }, + ]; this.team = -1; // team number of the player, players on the same team will always have ally diplomatic status - also this is useful for team emblems, scoring, etc. this.teamsLocked = false; this.state = "active"; // game state - one of "active", "defeated", "won" @@ -40,7 +44,7 @@ Player.prototype.Init = function() "wood": markForTranslation("Wood"), "metal": markForTranslation("Metal"), "stone": markForTranslation("Stone"), - } + }; this.disabledTemplates = {}; this.disabledTechnologies = {}; this.startingTechnologies = []; @@ -114,7 +118,7 @@ Player.prototype.GetPopulationCount = function() Player.prototype.AddPopulation = function(num) { - this.popUsed += num; + this.popUsed += num; }; Player.prototype.SetPopulationBonuses = function(num) @@ -445,15 +449,18 @@ Player.prototype.SetDiplomacyIndex = function(idx, value) Player.prototype.UpdateSharedLos = function() { - var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); - if (!cmpRangeManager) + let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); + let cmpTechnologyManager = Engine.QueryInterface(this.entity, IID_TechnologyManager); + if (!cmpRangeManager || !cmpPlayerManager || !cmpTechnologyManager) return; - var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); - if (!cmpPlayerManager) + let sharedLos = []; + if (!cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech)) + { + cmpRangeManager.SetSharedLos(this.playerID, [this.playerID]); return; - - var sharedLos = []; + } for (var i = 0; i < cmpPlayerManager.GetNumPlayers(); ++i) if (this.IsMutualAlly(i)) sharedLos.push(i); @@ -662,6 +669,12 @@ Player.prototype.OnPlayerDefeated = function(msg) cmpGUIInterface.PushNotification(notification); }; +Player.prototype.OnResearchFinished = function(msg) +{ + if (msg.tech == this.template.SharedLosTech) + this.UpdateSharedLos(); +}; + Player.prototype.OnDiplomacyChanged = function() { this.UpdateSharedLos(); diff --git a/binaries/data/mods/public/simulation/components/TechnologyManager.js b/binaries/data/mods/public/simulation/components/TechnologyManager.js index 019cda483c..3570c285b2 100644 --- a/binaries/data/mods/public/simulation/components/TechnologyManager.js +++ b/binaries/data/mods/public/simulation/components/TechnologyManager.js @@ -373,10 +373,9 @@ TechnologyManager.prototype.ResearchTechnology = function(tech) if (cmpPlayerEntityLimits) cmpPlayerEntityLimits.UpdateLimitsFromTech(tech); - // Call the related trigger event - var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); - cmpTrigger.CallEvent("ResearchFinished", {"player": playerID, "tech": tech}); - + // always send research finished message + Engine.PostMessage(this.entity, MT_ResearchFinished, {"player": playerID, "tech": tech}); + for (var component in modifiedComponents) { Engine.PostMessage(SYSTEM_ENTITY, MT_TemplateModification, { "player": playerID, "component": component, "valueNames": modifiedComponents[component]}); diff --git a/binaries/data/mods/public/simulation/components/Trigger.js b/binaries/data/mods/public/simulation/components/Trigger.js index 99bbddb2a4..8e3ea88ac5 100644 --- a/binaries/data/mods/public/simulation/components/Trigger.js +++ b/binaries/data/mods/public/simulation/components/Trigger.js @@ -234,6 +234,14 @@ Trigger.prototype.OnGlobalTrainingFinished = function(msg) // See function "SpawnUnits" in ProductionQueue for more details }; +// Handles "OnTrainingFinished" event. +Trigger.prototype.OnGlobalResearchFinished = function(msg) +{ + this.CallEvent("ResearchFinished", msg); + // The data for this one is {"player": playerID, + // "tech": tech} +}; + Trigger.prototype.OnGlobalOwnershipChanged = function(msg) { this.CallEvent("OwnershipChanged", msg); diff --git a/binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js b/binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js index 7764e87726..934bbc008a 100644 --- a/binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js +++ b/binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js @@ -1,2 +1,4 @@ Engine.RegisterInterface("TechnologyManager"); +Engine.RegisterMessageType("ResearchFinished"); + diff --git a/binaries/data/mods/public/simulation/data/technologies/unlock_shared_los.json b/binaries/data/mods/public/simulation/data/technologies/unlock_shared_los.json new file mode 100644 index 0000000000..3dc5844b6f --- /dev/null +++ b/binaries/data/mods/public/simulation/data/technologies/unlock_shared_los.json @@ -0,0 +1,11 @@ +{ + "genericName": "Carthography", + "description": "By means of trading and travelling people explored beyond the boundaries of their lands and drew maps of it in order to share and memorize their discoveries.", + "cost": {"food": 100, "wood": 0, "stone": 0, "metal": 100}, + "requirements": {"tech": "phase_village"}, + "icon": "shared_los.png", + "researchTime": 40, + "tooltip": "Player sees what his allies see.", + "modifications": [{"value": "Player/sharedLos", "replace": true}], + "soundComplete": "interface/alarm/alarm_upgradearmory.xml" +} \ No newline at end of file diff --git a/binaries/data/mods/public/simulation/templates/special/player.xml b/binaries/data/mods/public/simulation/templates/special/player.xml index 9222854103..e7a2ad8912 100644 --- a/binaries/data/mods/public/simulation/templates/special/player.xml +++ b/binaries/data/mods/public/simulation/templates/special/player.xml @@ -48,7 +48,9 @@ - + + unlock_shared_los + diff --git a/binaries/data/mods/public/simulation/templates/special/player_gaia.xml b/binaries/data/mods/public/simulation/templates/special/player_gaia.xml index 5de2278dcd..441b7c051c 100644 --- a/binaries/data/mods/public/simulation/templates/special/player_gaia.xml +++ b/binaries/data/mods/public/simulation/templates/special/player_gaia.xml @@ -1,4 +1,6 @@ - + + + diff --git a/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml b/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml index f883520731..eef49fdf4a 100644 --- a/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml +++ b/binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml @@ -51,6 +51,7 @@ 0.7 speed_trader_01 + unlock_shared_los units/{civ}_support_trader