From 4243433f949219c48712c14d173e46c8fa6537a3 Mon Sep 17 00:00:00 2001 From: leper Date: Wed, 7 Jan 2015 20:33:19 +0000 Subject: [PATCH] Use a gaia specific player entity. Fix some code that assumed components exist instead of testing for them. EntityLimits and TechnologyManager are not needed for gaia and will be removed in the future. This was SVN commit r16119. --- .../mods/public/simulation/components/Armour.js | 15 ++++++++------- .../public/simulation/components/GuiInterface.js | 13 ++++++------- .../data/mods/public/simulation/helpers/Player.js | 4 ++-- .../simulation/templates/special/player_gaia.xml | 10 ++++++++++ 4 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 binaries/data/mods/public/simulation/templates/special/player_gaia.xml diff --git a/binaries/data/mods/public/simulation/components/Armour.js b/binaries/data/mods/public/simulation/components/Armour.js index ff9a84c725..474eb94f8b 100644 --- a/binaries/data/mods/public/simulation/components/Armour.js +++ b/binaries/data/mods/public/simulation/components/Armour.js @@ -50,14 +50,15 @@ Armour.prototype.SetInvulnerability = function(invulnerability) Armour.prototype.TakeDamage = function(hack, pierce, crush, source) { // Alert target owner of attack - var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); - var cmpAttackDetection = QueryPlayerIDInterface(cmpOwnership.GetOwner(), IID_AttackDetection); - var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); - var now = cmpTimer.GetTime(); - if (now > this.nextAlertTime) + var cmpAttackDetection = QueryOwnerInterface(this.entity, IID_AttackDetection); + if (cmpAttackDetection) { - this.nextAlertTime = now + cmpAttackDetection.GetSuppressionTime(); - cmpAttackDetection.AttackAlert(this.entity, source); + var now = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime(); + if (now > this.nextAlertTime) + { + this.nextAlertTime = now + cmpAttackDetection.GetSuppressionTime(); + cmpAttackDetection.AttackAlert(this.entity, source); + } } if (this.invulnerable) diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 6a70d26772..b3b722a77b 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -46,7 +46,7 @@ GuiInterface.prototype.GetSimulationState = function(player) var ret = { "players": [] }; - + var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); var n = cmpPlayerMan.GetNumPlayers(); for (var i = 0; i < n; ++i) @@ -54,7 +54,7 @@ GuiInterface.prototype.GetSimulationState = function(player) var playerEnt = cmpPlayerMan.GetPlayerByID(i); var cmpPlayerEntityLimits = Engine.QueryInterface(playerEnt, IID_EntityLimits); var cmpPlayer = Engine.QueryInterface(playerEnt, IID_Player); - + // Work out what phase we are in var cmpTechnologyManager = Engine.QueryInterface(playerEnt, IID_TechnologyManager); var phase = ""; @@ -64,7 +64,7 @@ GuiInterface.prototype.GetSimulationState = function(player) phase = "town"; else if (cmpTechnologyManager.IsTechnologyResearched("phase_village")) phase = "village"; - + // store player ally/neutral/enemy data as arrays var allies = []; var mutualAllies = []; @@ -111,10 +111,8 @@ GuiInterface.prototype.GetSimulationState = function(player) var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); if (cmpRangeManager) - { ret.circularMap = cmpRangeManager.GetLosCircular(); - } - + // Add timeElapsed var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); ret.timeElapsed = cmpTimer.GetTime(); @@ -148,7 +146,8 @@ GuiInterface.prototype.GetExtendedSimulationState = function(player) { var playerEnt = cmpPlayerMan.GetPlayerByID(i); var cmpPlayerStatisticsTracker = Engine.QueryInterface(playerEnt, IID_StatisticsTracker); - ret.players[i].statistics = cmpPlayerStatisticsTracker.GetStatistics(); + if (cmpPlayerStatisticsTracker) + ret.players[i].statistics = cmpPlayerStatisticsTracker.GetStatistics(); } return ret; diff --git a/binaries/data/mods/public/simulation/helpers/Player.js b/binaries/data/mods/public/simulation/helpers/Player.js index d32b415598..abf4f683c3 100644 --- a/binaries/data/mods/public/simulation/helpers/Player.js +++ b/binaries/data/mods/public/simulation/helpers/Player.js @@ -46,7 +46,7 @@ function LoadPlayerSettings(settings, newPlayers) { // Add player entity to engine var civ = getSetting(playerData, playerDefaults, numPlayers, "Civ"); - var template = cmpTemplateManager.TemplateExists("special/"+civ+"_player") ? "special/"+civ+"_player" : "special/player"; + var template = cmpTemplateManager.TemplateExists("special/player_"+civ) ? "special/player_"+civ : "special/player"; var entID = Engine.AddEntity(template); var cmpPlayer = Engine.QueryInterface(entID, IID_Player); if (!cmpPlayer) @@ -67,7 +67,7 @@ function LoadPlayerSettings(settings, newPlayers) for (var i = 0; i < numPlayers; ++i) { var civ = getSetting(playerData, playerDefaults, i, "Civ"); - var template = cmpTemplateManager.TemplateExists("special/"+civ+"_player") ? "special/"+civ+"_player" : "special/player"; + var template = cmpTemplateManager.TemplateExists("special/player_"+civ) ? "special/player_"+civ : "special/player"; var entID = cmpPlayerManager.GetPlayerByID(i); if (cmpTemplateManager.GetCurrentTemplateName(entID) === template) continue; diff --git a/binaries/data/mods/public/simulation/templates/special/player_gaia.xml b/binaries/data/mods/public/simulation/templates/special/player_gaia.xml new file mode 100644 index 0000000000..cf82966c58 --- /dev/null +++ b/binaries/data/mods/public/simulation/templates/special/player_gaia.xml @@ -0,0 +1,10 @@ + + + + + + + + + +