From 4c4f787c632434dff82ce8fc37beae2f41ae53a1 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Sun, 11 May 2025 10:39:08 +0200 Subject: [PATCH] Fix eslint rule 'prefer-const' in components/[A-B]* eslint --no-config-lookup --fix --rule '"prefer-const": 1' \ binaries/data/mods/public/simulation/components/A* \ binaries/data/mods/public/simulation/components/B* \ Ref: #7812 Signed-off-by: Ralph Sennhauser --- .../simulation/components/AIInterface.js | 60 +++++----- .../public/simulation/components/AIProxy.js | 40 +++---- .../simulation/components/AlertRaiser.js | 54 ++++----- .../public/simulation/components/Attack.js | 112 +++++++++--------- .../simulation/components/AttackDetection.js | 6 +- .../public/simulation/components/Auras.js | 104 ++++++++-------- .../simulation/components/AutoBuildable.js | 10 +- .../components/BuildRestrictions.js | 14 +-- .../public/simulation/components/Builder.js | 42 +++---- .../simulation/components/BuildingAI.js | 38 +++--- 10 files changed, 240 insertions(+), 240 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/AIInterface.js b/binaries/data/mods/public/simulation/components/AIInterface.js index ec0b1950eb..88ae8d89d1 100644 --- a/binaries/data/mods/public/simulation/components/AIInterface.js +++ b/binaries/data/mods/public/simulation/components/AIInterface.js @@ -30,7 +30,7 @@ AIInterface.prototype.EventNames = [ AIInterface.prototype.Init = function() { this.events = {}; - for (let name of this.EventNames) + for (const name of this.EventNames) this.events[name] = []; this.changedEntities = {}; @@ -45,7 +45,7 @@ AIInterface.prototype.Init = function() AIInterface.prototype.Serialize = function() { - let state = {}; + const state = {}; for (var key in this) { if (!this.hasOwnProperty(key)) @@ -61,7 +61,7 @@ AIInterface.prototype.Serialize = function() AIInterface.prototype.Deserialize = function(data) { - for (let key in data) + for (const key in data) { if (!data.hasOwnProperty(key)) continue; @@ -78,7 +78,7 @@ AIInterface.prototype.Deserialize = function(data) AIInterface.prototype.Disable = function() { this.enabled = false; - let nop = function(){}; + const nop = function(){}; this.ChangedEntity = nop; this.PushEvent = nop; this.OnGlobalPlayerDefeated = nop; @@ -90,15 +90,15 @@ AIInterface.prototype.Disable = function() AIInterface.prototype.GetNonEntityRepresentation = function() { - let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); + const cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); // Return the same game state as the GUI uses - let state = cmpGuiInterface.GetSimulationState(); + const state = cmpGuiInterface.GetSimulationState(); // Add some extra AI-specific data // add custom events and reset them for the next turn state.events = {}; - for (let name of this.EventNames) + for (const name of this.EventNames) { state.events[name] = this.events[name]; this.events[name] = []; @@ -109,14 +109,14 @@ AIInterface.prototype.GetNonEntityRepresentation = function() AIInterface.prototype.GetRepresentation = function() { - let state = this.GetNonEntityRepresentation(); + const state = this.GetNonEntityRepresentation(); // Add entity representations Engine.ProfileStart("proxy representations"); state.entities = {}; - for (let id in this.changedEntities) + for (const id in this.changedEntities) { - let cmpAIProxy = Engine.QueryInterface(+id, IID_AIProxy); + const cmpAIProxy = Engine.QueryInterface(+id, IID_AIProxy); if (cmpAIProxy) state.entities[id] = cmpAIProxy.GetRepresentation(); } @@ -136,17 +136,17 @@ AIInterface.prototype.GetRepresentation = function() */ AIInterface.prototype.GetFullRepresentation = function(flushEvents) { - let state = this.GetNonEntityRepresentation(); + const state = this.GetNonEntityRepresentation(); if (flushEvents) - for (let name of this.EventNames) + for (const name of this.EventNames) state.events[name] = []; // Add entity representations Engine.ProfileStart("proxy representations"); state.entities = {}; // all entities are changed in the initial state. - for (let id of Engine.GetEntitiesWithInterface(IID_AIProxy)) + for (const id of Engine.GetEntitiesWithInterface(IID_AIProxy)) state.entities[id] = Engine.QueryInterface(id, IID_AIProxy).GetFullRepresentation(); Engine.ProfileStop(); @@ -214,35 +214,35 @@ AIInterface.prototype.OnCeasefireEnded = function(msg) */ AIInterface.prototype.OnTemplateModification = function(msg) { - let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); + const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); if (!this.templates) { this.templates = []; - for (let templateName of cmpTemplateManager.FindAllTemplates(false)) + for (const templateName of cmpTemplateManager.FindAllTemplates(false)) { // Remove templates that we obviously don't care about. if (templateName.startsWith("campaigns/") || templateName.startsWith("rubble/") || templateName.startsWith("skirmish/")) continue; - let template = cmpTemplateManager.GetTemplateWithoutValidation(templateName); + const template = cmpTemplateManager.GetTemplateWithoutValidation(templateName); if (!template || !template.Identity || !template.Identity.Civ) continue; this.templates.push(templateName); } } - for (let name of this.templates) + for (const name of this.templates) { - let template = cmpTemplateManager.GetTemplateWithoutValidation(name); + const template = cmpTemplateManager.GetTemplateWithoutValidation(name); if (!template || !template[msg.component]) continue; - for (let valName of msg.valueNames) + for (const valName of msg.valueNames) { // let's get the base template value. - let strings = valName.split("/"); + const strings = valName.split("/"); let item = template; let ended = true; - for (let str of strings) + for (const str of strings) { if (item !== undefined && item[str] !== undefined) item = item[str]; @@ -252,7 +252,7 @@ AIInterface.prototype.OnTemplateModification = function(msg) if (!ended) continue; // item now contains the template value for this. - let oldValue = +item == item ? +item : item; + const oldValue = +item == item ? +item : item; let newValue = ApplyValueModificationsToTemplate(valName, oldValue, msg.player, template); // Apply the same roundings as in the components if (valName === "Player/MaxPopulation" || valName === "Cost/Population" || @@ -275,23 +275,23 @@ AIInterface.prototype.OnTemplateModification = function(msg) AIInterface.prototype.OnGlobalValueModification = function(msg) { this.events.ValueModification.push(msg); - let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); - for (let ent of msg.entities) + const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); + for (const ent of msg.entities) { - let templateName = cmpTemplateManager.GetCurrentTemplateName(ent); + const templateName = cmpTemplateManager.GetCurrentTemplateName(ent); // if there's no template name, the unit is probably killed, ignore it. if (!templateName || !templateName.length) continue; - let template = cmpTemplateManager.GetTemplateWithoutValidation(templateName); + const template = cmpTemplateManager.GetTemplateWithoutValidation(templateName); if (!template || !template[msg.component]) continue; - for (let valName of msg.valueNames) + for (const valName of msg.valueNames) { // let's get the base template value. - let strings = valName.split("/"); + const strings = valName.split("/"); let item = template; let ended = true; - for (let str of strings) + for (const str of strings) { if (item !== undefined && item[str] !== undefined) item = item[str]; @@ -301,7 +301,7 @@ AIInterface.prototype.OnGlobalValueModification = function(msg) if (!ended) continue; // "item" now contains the unmodified template value for this. - let oldValue = +item == item ? +item : item; + const oldValue = +item == item ? +item : item; let newValue = ApplyValueModificationsToEntity(valName, oldValue, ent); // Apply the same roundings as in the components if (valName === "Player/MaxPopulation" || valName === "Cost/Population" || diff --git a/binaries/data/mods/public/simulation/components/AIProxy.js b/binaries/data/mods/public/simulation/components/AIProxy.js index d398100949..89df8d441c 100644 --- a/binaries/data/mods/public/simulation/components/AIProxy.js +++ b/binaries/data/mods/public/simulation/components/AIProxy.js @@ -67,7 +67,7 @@ AIProxy.prototype.NotifyChange = function() { // not yet notified, be sure that the owner is set before doing so // as the Create event is sent only on first ownership changed - let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + const cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); if (!cmpOwnership || cmpOwnership.GetOwner() < 0) return false; } @@ -159,7 +159,7 @@ AIProxy.prototype.OnProductionQueueChanged = function(msg) { if (!this.NotifyChange()) return; - let cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); + const cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); this.changes.trainingQueue = cmpProductionQueue.GetQueue(); }; @@ -168,14 +168,14 @@ AIProxy.prototype.OnGarrisonedUnitsChanged = function(msg) if (!this.NotifyChange()) return; - let cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); + const cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); this.changes.garrisoned = cmpGarrisonHolder.GetEntities(); // Send a message telling a unit garrisoned or ungarrisoned. // I won't check if the unit is still alive so it'll be up to the AI. - for (let ent of msg.added) + for (const ent of msg.added) this.cmpAIInterface.PushEvent("Garrison", { "entity": ent, "holder": this.entity }); - for (let ent of msg.removed) + for (const ent of msg.removed) this.cmpAIInterface.PushEvent("UnGarrison", { "entity": ent, "holder": this.entity }); }; @@ -213,22 +213,22 @@ AIProxy.prototype.OnTerritoryDecayChanged = function(msg) AIProxy.prototype.GetFullRepresentation = function() { this.needsFullGet = false; - let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); + const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); - let ret = { + const ret = { // These properties are constant and won't need to be updated "id": this.entity, "template": cmpTemplateManager.GetCurrentTemplateName(this.entity) }; - let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); + const cmpPosition = Engine.QueryInterface(this.entity, IID_Position); if (cmpPosition) { // Updated by OnPositionChanged if (cmpPosition.IsInWorld()) { - let pos = cmpPosition.GetPosition2D(); + const pos = cmpPosition.GetPosition2D(); ret.position = [pos.x, pos.y]; ret.angle = cmpPosition.GetRotation().y; } @@ -239,25 +239,25 @@ AIProxy.prototype.GetFullRepresentation = function() } } - let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); + const cmpHealth = Engine.QueryInterface(this.entity, IID_Health); if (cmpHealth) { // Updated by OnHealthChanged ret.hitpoints = cmpHealth.GetHitpoints(); } - let cmpResistance = Engine.QueryInterface(this.entity, IID_Resistance); + const cmpResistance = Engine.QueryInterface(this.entity, IID_Resistance); if (cmpResistance) ret.invulnerability = cmpResistance.IsInvulnerable(); - let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + const cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); if (cmpOwnership) { // Updated by OnOwnershipChanged ret.owner = cmpOwnership.GetOwner(); } - let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); + const cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); if (cmpUnitAI) { // Updated by OnUnitIdleChanged @@ -270,46 +270,46 @@ AIProxy.prototype.GetFullRepresentation = function() ret.unitAIOrderData = cmpUnitAI.GetOrderData(); } - let cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); + const cmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); if (cmpProductionQueue) { // Updated by OnProductionQueueChanged ret.trainingQueue = cmpProductionQueue.GetQueue(); } - let cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); + const cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); if (cmpFoundation) { // Updated by OnFoundationProgressChanged ret.foundationProgress = cmpFoundation.GetBuildPercentage(); } - let cmpResourceDropsite = Engine.QueryInterface(this.entity, IID_ResourceDropsite); + const cmpResourceDropsite = Engine.QueryInterface(this.entity, IID_ResourceDropsite); if (cmpResourceDropsite) { // Updated by OnDropsiteSharingChanged ret.sharedDropsite = cmpResourceDropsite.IsShared(); } - let cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); + const cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); if (cmpGarrisonHolder) { // Updated by OnGarrisonedUnitsChanged ret.garrisoned = cmpGarrisonHolder.GetEntities(); } - let cmpGarrisonable = Engine.QueryInterface(this.entity, IID_Garrisonable); + const cmpGarrisonable = Engine.QueryInterface(this.entity, IID_Garrisonable); if (cmpGarrisonable) { // Updated by OnGarrisonedStateChanged ret.garrisonHolderID = cmpGarrisonable.HolderID(); } - let cmpTerritoryDecay = Engine.QueryInterface(this.entity, IID_TerritoryDecay); + const cmpTerritoryDecay = Engine.QueryInterface(this.entity, IID_TerritoryDecay); if (cmpTerritoryDecay) ret.decaying = cmpTerritoryDecay.IsDecaying(); - let cmpCapturable = Engine.QueryInterface(this.entity, IID_Capturable); + const cmpCapturable = Engine.QueryInterface(this.entity, IID_Capturable); if (cmpCapturable) ret.capturePoints = cmpCapturable.GetCapturePoints(); diff --git a/binaries/data/mods/public/simulation/components/AlertRaiser.js b/binaries/data/mods/public/simulation/components/AlertRaiser.js index 5693c50d18..cccc037a14 100644 --- a/binaries/data/mods/public/simulation/components/AlertRaiser.js +++ b/binaries/data/mods/public/simulation/components/AlertRaiser.js @@ -24,42 +24,42 @@ AlertRaiser.prototype.GetTargetClasses = function() AlertRaiser.prototype.UnitFilter = function(unit) { - let cmpIdentity = Engine.QueryInterface(unit, IID_Identity); + const cmpIdentity = Engine.QueryInterface(unit, IID_Identity); return cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), this.GetTargetClasses()); }; AlertRaiser.prototype.RaiseAlert = function() { - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); if (cmpTimer.GetTime() == this.lastTime) return; this.lastTime = cmpTimer.GetTime(); PlaySound("alert_raise", this.entity); - let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + const cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); if (!cmpOwnership || cmpOwnership.GetOwner() == INVALID_PLAYER) return; - let owner = cmpOwnership.GetOwner(); + const owner = cmpOwnership.GetOwner(); const cmpDiplomacy = QueryPlayerIDInterface(owner, IID_Diplomacy); const mutualAllies = cmpDiplomacy ? cmpDiplomacy.GetMutualAllies() : [owner]; - let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); // Store the number of available garrison spots so that units don't try to garrison in buildings that will be full - let reserved = new Map(); + const reserved = new Map(); - let units = cmpRangeManager.ExecuteQuery(this.entity, 0, +this.template.RaiseAlertRange, [owner], IID_UnitAI, true).filter(ent => this.UnitFilter(ent)); - for (let unit of units) + const units = cmpRangeManager.ExecuteQuery(this.entity, 0, +this.template.RaiseAlertRange, [owner], IID_UnitAI, true).filter(ent => this.UnitFilter(ent)); + for (const unit of units) { - let cmpGarrisonable = Engine.QueryInterface(unit, IID_Garrisonable); + const cmpGarrisonable = Engine.QueryInterface(unit, IID_Garrisonable); if (!cmpGarrisonable) continue; - let size = cmpGarrisonable.TotalSize(); - let cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI); + const size = cmpGarrisonable.TotalSize(); + const cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI); - let holder = cmpRangeManager.ExecuteQuery(unit, 0, +this.template.SearchRange, mutualAllies, IID_GarrisonHolder, true).find(ent => { + const holder = cmpRangeManager.ExecuteQuery(unit, 0, +this.template.SearchRange, mutualAllies, IID_GarrisonHolder, true).find(ent => { // Ignore moving garrison holders if (Engine.QueryInterface(ent, IID_UnitAI)) return false; @@ -71,7 +71,7 @@ AlertRaiser.prototype.RaiseAlert = function() if (!cmpUnitAI.CheckTargetVisible(ent)) return false; - let cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder); + const cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder); if (!reserved.has(ent)) reserved.set(ent, cmpGarrisonHolder.GetCapacity() - cmpGarrisonHolder.OccupiedSlots()); @@ -91,27 +91,27 @@ AlertRaiser.prototype.RaiseAlert = function() AlertRaiser.prototype.EndOfAlert = function() { - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); if (cmpTimer.GetTime() == this.lastTime) return; this.lastTime = cmpTimer.GetTime(); PlaySound("alert_end", this.entity); - let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + const cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); if (!cmpOwnership || cmpOwnership.GetOwner() == INVALID_PLAYER) return; - let owner = cmpOwnership.GetOwner(); + const owner = cmpOwnership.GetOwner(); const cmpDiplomacy = QueryPlayerIDInterface(owner, IID_Diplomacy); const mutualAllies = cmpDiplomacy ? cmpDiplomacy.GetMutualAllies() : [owner]; - let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); // Units that are not garrisoned should go back to work - let units = cmpRangeManager.ExecuteQuery(this.entity, 0, +this.template.EndOfAlertRange, [owner], IID_UnitAI, true).filter(ent => this.UnitFilter(ent)); - for (let unit of units) + const units = cmpRangeManager.ExecuteQuery(this.entity, 0, +this.template.EndOfAlertRange, [owner], IID_UnitAI, true).filter(ent => this.UnitFilter(ent)); + for (const unit of units) { - let cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI); + const cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI); if (cmpUnitAI.HasWorkOrders() && cmpUnitAI.ShouldRespondToEndOfAlert()) cmpUnitAI.BackToWork(); else if (cmpUnitAI.ShouldRespondToEndOfAlert()) @@ -120,25 +120,25 @@ AlertRaiser.prototype.EndOfAlert = function() } // Units that are garrisoned should ungarrison and go back to work - let holders = cmpRangeManager.ExecuteQuery(this.entity, 0, +this.template.EndOfAlertRange, mutualAllies, IID_GarrisonHolder, true); + const holders = cmpRangeManager.ExecuteQuery(this.entity, 0, +this.template.EndOfAlertRange, mutualAllies, IID_GarrisonHolder, true); if (Engine.QueryInterface(this.entity, IID_GarrisonHolder)) holders.push(this.entity); - for (let holder of holders) + for (const holder of holders) { if (Engine.QueryInterface(holder, IID_UnitAI)) continue; - let cmpGarrisonHolder = Engine.QueryInterface(holder, IID_GarrisonHolder); - let units = cmpGarrisonHolder.GetEntities().filter(ent => { - let cmpOwner = Engine.QueryInterface(ent, IID_Ownership); + const cmpGarrisonHolder = Engine.QueryInterface(holder, IID_GarrisonHolder); + const units = cmpGarrisonHolder.GetEntities().filter(ent => { + const cmpOwner = Engine.QueryInterface(ent, IID_Ownership); return cmpOwner && cmpOwner.GetOwner() == owner && this.UnitFilter(ent); }); - for (let unit of units) + for (const unit of units) if (cmpGarrisonHolder.Unload(unit)) { - let cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI); + const cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI); if (cmpUnitAI.HasWorkOrders()) cmpUnitAI.BackToWork(); else diff --git a/binaries/data/mods/public/simulation/components/Attack.js b/binaries/data/mods/public/simulation/components/Attack.js index 0135a6e18d..f479f87d85 100644 --- a/binaries/data/mods/public/simulation/components/Attack.js +++ b/binaries/data/mods/public/simulation/components/Attack.js @@ -209,11 +209,11 @@ Attack.prototype.Init = function() Attack.prototype.GetAttackTypes = function(wantedTypes) { - let types = g_AttackTypes.filter(type => !!this.template[type]); + const types = g_AttackTypes.filter(type => !!this.template[type]); if (!wantedTypes) return types; - let wantedTypesReal = wantedTypes.filter(wtype => wtype.indexOf("!") != 0); + const wantedTypesReal = wantedTypes.filter(wtype => wtype.indexOf("!") != 0); return types.filter(type => wantedTypes.indexOf("!" + type) == -1 && (!wantedTypesReal || !wantedTypesReal.length || wantedTypesReal.indexOf(type) != -1)); }; @@ -304,16 +304,16 @@ Attack.prototype.CanAttack = function(target, wantedTypes) */ Attack.prototype.GetPreference = function(target) { - let cmpIdentity = Engine.QueryInterface(target, IID_Identity); + const cmpIdentity = Engine.QueryInterface(target, IID_Identity); if (!cmpIdentity) return undefined; - let targetClasses = cmpIdentity.GetClassesList(); + const targetClasses = cmpIdentity.GetClassesList(); let minPref; - for (let type of this.GetAttackTypes()) + for (const type of this.GetAttackTypes()) { - let preferredClasses = this.GetPreferredClasses(type); + const preferredClasses = this.GetPreferredClasses(type); for (let pref = 0; pref < preferredClasses.length; ++pref) { if (MatchesClassList(targetClasses, preferredClasses[pref])) @@ -333,10 +333,10 @@ Attack.prototype.GetPreference = function(target) */ Attack.prototype.GetFullAttackRange = function() { - let ret = { "min": Infinity, "max": 0 }; - for (let type of this.GetAttackTypes()) + const ret = { "min": Infinity, "max": 0 }; + for (const type of this.GetAttackTypes()) { - let range = this.GetRange(type); + const range = this.GetRange(type); ret.min = Math.min(ret.min, range.min); ret.max = Math.max(ret.max, range.max); } @@ -361,7 +361,7 @@ Attack.prototype.GetAttackEffectsData = function(type, splash) */ Attack.prototype.GetBestAttackAgainst = function(target, allowCapture) { - let types = this.GetAttackTypes(); + const types = this.GetAttackTypes(); if (Engine.QueryInterface(target, IID_Formation)) // TODO: Formation against formation needs review return g_AttackTypes.find(attack => types.indexOf(attack) != -1); @@ -394,8 +394,8 @@ Attack.prototype.GetBestAttackAgainst = function(target, allowCapture) Attack.prototype.CompareEntitiesByPreference = function(a, b) { - let aPreference = this.GetPreference(a); - let bPreference = this.GetPreference(b); + const aPreference = this.GetPreference(a); + const bPreference = this.GetPreference(b); if (aPreference === null && bPreference === null) return 0; if (aPreference === null) return 1; @@ -487,19 +487,19 @@ Attack.prototype.StartAttacking = function(target, type, callerIID) if (!cmpResistance || !cmpResistance.AddAttacker(this.entity)) return false; - let timings = this.GetTimers(type); - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const timings = this.GetTimers(type); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); // If the repeat time since the last attack hasn't elapsed, // delay the action to avoid attacking too fast. let prepare = timings.prepare; if (this.lastAttacked) { - let repeatLeft = this.lastAttacked + timings.repeat - cmpTimer.GetTime(); + const repeatLeft = this.lastAttacked + timings.repeat - cmpTimer.GetTime(); prepare = Math.max(prepare, repeatLeft); } - let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); + const cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); if (cmpVisual) { cmpVisual.SelectAnimation("attack_" + type.toLowerCase(), false, 1.0); @@ -538,7 +538,7 @@ Attack.prototype.StopAttacking = function(reason) if (!this.target) return; - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); cmpTimer.CancelTimer(this.timer); cmpTimer.CancelTimer(this.checkTimer); delete this.timer; @@ -550,18 +550,18 @@ Attack.prototype.StopAttacking = function(reason) delete this.target; - let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); + const cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); if (cmpVisual) cmpVisual.SelectAnimation("idle", false, 1.0); // The callerIID component may start again, // replacing the callerIID, hence save that. - let callerIID = this.callerIID; + const callerIID = this.callerIID; delete this.callerIID; if (reason && callerIID) { - let component = Engine.QueryInterface(this.entity, callerIID); + const component = Engine.QueryInterface(this.entity, callerIID); if (component) component.ProcessMessage(reason, null); } @@ -583,7 +583,7 @@ Attack.prototype.Attack = function(type, lateness) // ToDo: Enable entities to keep facing a target. Engine.QueryInterface(this.entity, IID_UnitAI)?.FaceTowardsTarget(this.target); - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); this.lastAttacked = cmpTimer.GetTime() - lateness; // BuildingAI has its own attack routine. @@ -602,10 +602,10 @@ Attack.prototype.Attack = function(type, lateness) if (this.resyncAnimation) { - let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); + const cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); if (cmpVisual) { - let repeat = this.GetTimers(type).repeat; + const repeat = this.GetTimers(type).repeat; cmpVisual.SetAnimationSyncRepeat(repeat); cmpVisual.SetAnimationSyncOffset(repeat); } @@ -620,22 +620,22 @@ Attack.prototype.Attack = function(type, lateness) */ Attack.prototype.PerformAttack = function(type, target) { - let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); + const cmpPosition = Engine.QueryInterface(this.entity, IID_Position); if (!cmpPosition || !cmpPosition.IsInWorld()) return; - let selfPosition = cmpPosition.GetPosition(); + const selfPosition = cmpPosition.GetPosition(); - let cmpTargetPosition = Engine.QueryInterface(target, IID_Position); + const cmpTargetPosition = Engine.QueryInterface(target, IID_Position); if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) return; - let targetPosition = cmpTargetPosition.GetPosition(); + const targetPosition = cmpTargetPosition.GetPosition(); - let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + const cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); if (!cmpOwnership) return; - let attackerOwner = cmpOwnership.GetOwner(); + const attackerOwner = cmpOwnership.GetOwner(); - let data = { + const data = { "type": type, "attackData": this.GetAttackEffectsData(type), "splash": this.GetSplashData(type), @@ -648,20 +648,20 @@ Attack.prototype.PerformAttack = function(type, target) if (this.template[type].Projectile) { - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); - let turnLength = cmpTimer.GetLatestTurnLength()/1000; + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const turnLength = cmpTimer.GetLatestTurnLength()/1000; // In the future this could be extended: // * Obstacles like trees could reduce the probability of the target being hit // * Obstacles like walls should block projectiles entirely - let horizSpeed = +this.template[type].Projectile.Speed; - let gravity = +this.template[type].Projectile.Gravity; + const horizSpeed = +this.template[type].Projectile.Speed; + const gravity = +this.template[type].Projectile.Gravity; // horizSpeed /= 2; gravity /= 2; // slow it down for testing // We will try to estimate the position of the target, where we can hit it. // We first estimate the time-till-hit by extrapolating linearly the movement // of the last turn. We compute the time till an arrow will intersect the target. - let targetVelocity = Vector3D.sub(targetPosition, cmpTargetPosition.GetPreviousPosition()).div(turnLength); + const targetVelocity = Vector3D.sub(targetPosition, cmpTargetPosition.GetPreviousPosition()).div(turnLength); let timeToTarget = PositionHelper.PredictTimeToTarget(selfPosition, horizSpeed, targetPosition, targetVelocity); @@ -674,14 +674,14 @@ Attack.prototype.PerformAttack = function(type, target) { // Don't predict too far in the future, but avoid threshold effects. // After 1 second, always use the 'dumb' interpolated past-motion prediction. - let useUnitMotion = randBool(Math.max(0, 0.75 - timeToTarget / 1.333)); + const useUnitMotion = randBool(Math.max(0, 0.75 - timeToTarget / 1.333)); if (useUnitMotion) { - let cmpTargetUnitMotion = Engine.QueryInterface(target, IID_UnitMotion); - let cmpTargetUnitAI = Engine.QueryInterface(target, IID_UnitAI); + const cmpTargetUnitMotion = Engine.QueryInterface(target, IID_UnitMotion); + const cmpTargetUnitAI = Engine.QueryInterface(target, IID_UnitAI); if (cmpTargetUnitMotion && (!cmpTargetUnitAI || !cmpTargetUnitAI.IsFormationMember())) { - let pos2D = cmpTargetUnitMotion.EstimateFuturePosition(timeToTarget); + const pos2D = cmpTargetUnitMotion.EstimateFuturePosition(timeToTarget); predictedPosition.x = pos2D.x; predictedPosition.z = pos2D.y; } @@ -692,33 +692,33 @@ Attack.prototype.PerformAttack = function(type, target) predictedPosition = Vector3D.mult(targetVelocity, timeToTarget).add(targetPosition); } - let predictedHeight = cmpTargetPosition.GetHeightAt(predictedPosition.x, predictedPosition.z); + const predictedHeight = cmpTargetPosition.GetHeightAt(predictedPosition.x, predictedPosition.z); // Add inaccuracy based on spread. const distanceModifiedSpread = ApplyValueModificationsToEntity("Attack/" + type + "/Projectile/Spread", +this.template[type].Projectile.Spread, this.entity) * predictedPosition.horizDistanceTo(selfPosition) / 100; - let randNorm = randomNormal2D(); - let offsetX = randNorm[0] * distanceModifiedSpread; - let offsetZ = randNorm[1] * distanceModifiedSpread; + const randNorm = randomNormal2D(); + const offsetX = randNorm[0] * distanceModifiedSpread; + const offsetZ = randNorm[1] * distanceModifiedSpread; data.position = new Vector3D(predictedPosition.x + offsetX, predictedHeight, predictedPosition.z + offsetZ); - let realHorizDistance = data.position.horizDistanceTo(selfPosition); + const realHorizDistance = data.position.horizDistanceTo(selfPosition); timeToTarget = realHorizDistance / horizSpeed; delay += timeToTarget * 1000; data.direction = Vector3D.sub(data.position, selfPosition).div(realHorizDistance); let actorName = this.template[type].Projectile.ActorName || ""; - let impactActorName = this.template[type].Projectile.ImpactActorName || ""; - let impactAnimationLifetime = this.template[type].Projectile.ImpactAnimationLifetime || 0; + const impactActorName = this.template[type].Projectile.ImpactActorName || ""; + const impactAnimationLifetime = this.template[type].Projectile.ImpactAnimationLifetime || 0; // TODO: Use unit rotation to implement x/z offsets. - let deltaLaunchPoint = new Vector3D(0, +this.template[type].Projectile.LaunchPoint["@y"], 0); + const deltaLaunchPoint = new Vector3D(0, +this.template[type].Projectile.LaunchPoint["@y"], 0); let launchPoint = Vector3D.add(selfPosition, deltaLaunchPoint); - let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); + const cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); if (cmpVisual) { // if the projectile definition is missing from the template @@ -726,15 +726,15 @@ Attack.prototype.PerformAttack = function(type, target) if (!actorName) actorName = cmpVisual.GetProjectileActor(); - let visualActorLaunchPoint = cmpVisual.GetProjectileLaunchPoint(); + const visualActorLaunchPoint = cmpVisual.GetProjectileLaunchPoint(); if (visualActorLaunchPoint.length() > 0) launchPoint = visualActorLaunchPoint; } - let cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); + const cmpProjectileManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ProjectileManager); data.projectileId = cmpProjectileManager.LaunchProjectileAtPoint(launchPoint, data.position, horizSpeed, gravity, actorName, impactActorName, impactAnimationLifetime); - let cmpSound = Engine.QueryInterface(this.entity, IID_Sound); + const cmpSound = Engine.QueryInterface(this.entity, IID_Sound); data.attackImpactSound = cmpSound ? cmpSound.GetSoundGroup("attack_impact_" + type.toLowerCase()) : ""; data.friendlyFire = this.template[type].Projectile.FriendlyFire == "true"; @@ -746,7 +746,7 @@ Attack.prototype.PerformAttack = function(type, target) } if (delay) { - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); cmpTimer.SetTimeout(SYSTEM_ENTITY, IID_DelayedDamage, "Hit", delay, data); } else @@ -774,7 +774,7 @@ Attack.prototype.OnValueModification = function(msg) if (msg.component != "Attack") return; - let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); + const cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); if (!cmpUnitAI) return; @@ -788,9 +788,9 @@ Attack.prototype.GetRangeOverlays = function(type = "Ranged") if (!this.template[type] || !this.template[type].RangeOverlay) return []; - let range = this.GetRange(type); - let rangeOverlays = []; - for (let i in range) + const range = this.GetRange(type); + const rangeOverlays = []; + for (const i in range) if ((i == "min" || i == "max") && range[i]) rangeOverlays.push({ "radius": range[i], diff --git a/binaries/data/mods/public/simulation/components/AttackDetection.js b/binaries/data/mods/public/simulation/components/AttackDetection.js index 9f56f1ddfc..5d96a739b1 100644 --- a/binaries/data/mods/public/simulation/components/AttackDetection.js +++ b/binaries/data/mods/public/simulation/components/AttackDetection.js @@ -57,14 +57,14 @@ AttackDetection.prototype.OnGlobalAttacked = function(msg) AttackDetection.prototype.AttackAlert = function(target, attacker, type, attackerOwner) { - let playerID = Engine.QueryInterface(this.entity, IID_Player).GetPlayerID(); + const playerID = Engine.QueryInterface(this.entity, IID_Player).GetPlayerID(); // Don't register attacks dealt against other players if (Engine.QueryInterface(target, IID_Ownership).GetOwner() != playerID) return; - let cmpAttackerOwnership = Engine.QueryInterface(attacker, IID_Ownership); - let atkOwner = cmpAttackerOwnership && cmpAttackerOwnership.GetOwner() != INVALID_PLAYER ? cmpAttackerOwnership.GetOwner() : attackerOwner; + const cmpAttackerOwnership = Engine.QueryInterface(attacker, IID_Ownership); + const atkOwner = cmpAttackerOwnership && cmpAttackerOwnership.GetOwner() != INVALID_PLAYER ? cmpAttackerOwnership.GetOwner() : attackerOwner; // Don't register attacks dealt by myself if (atkOwner == playerID) return; diff --git a/binaries/data/mods/public/simulation/components/Auras.js b/binaries/data/mods/public/simulation/components/Auras.js index a21fb59a4f..ad5369e142 100644 --- a/binaries/data/mods/public/simulation/components/Auras.js +++ b/binaries/data/mods/public/simulation/components/Auras.js @@ -10,7 +10,7 @@ Auras.prototype.Init = function() { this.affectedPlayers = {}; - for (let name of this.GetAuraNames()) + for (const name of this.GetAuraNames()) this.affectedPlayers[name] = []; // In case of autogarrisoning, this component can be called before ownership is set. @@ -29,9 +29,9 @@ Auras.prototype.GetModifierIdentifier = function(name) Auras.prototype.GetDescriptions = function() { var ret = {}; - for (let auraID of this.GetAuraNames()) + for (const auraID of this.GetAuraNames()) { - let aura = AuraTemplates.Get(auraID); + const aura = AuraTemplates.Get(auraID); ret[auraID] = { "name": { "generic": aura.auraName @@ -82,14 +82,14 @@ Auras.prototype.GetAffectedPlayers = function(name) Auras.prototype.GetRangeOverlays = function() { - let rangeOverlays = []; + const rangeOverlays = []; - for (let name of this.GetAuraNames()) + for (const name of this.GetAuraNames()) { if (!this.IsRangeAura(name) || !this[name].isApplied) continue; - let rangeOverlay = AuraTemplates.Get(name).rangeOverlay; + const rangeOverlay = AuraTemplates.Get(name).rangeOverlay; rangeOverlays.push( rangeOverlay ? @@ -127,10 +127,10 @@ Auras.prototype.CalculateAffectedPlayers = function(name) const cmpDiplomacy = Engine.QueryInterface(this.entity, IID_Diplomacy) ?? QueryPlayerIDInterface(playerID, IID_Diplomacy); - let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); - for (let i of cmpPlayerManager.GetAllPlayers()) + const cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); + for (const i of cmpPlayerManager.GetAllPlayers()) { - let cmpAffectedPlayer = QueryPlayerIDInterface(i); + const cmpAffectedPlayer = QueryPlayerIDInterface(i); if (!cmpAffectedPlayer || cmpAffectedPlayer.IsDefeated()) continue; @@ -144,7 +144,7 @@ Auras.prototype.CanApply = function(name) if (!AuraTemplates.Get(name).requiredTechnology) return true; - let cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); + const cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); if (!cmpTechnologyManager) return false; @@ -213,10 +213,10 @@ Auras.prototype.Clean = function() { var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); var auraNames = this.GetAuraNames(); - let targetUnitsClone = {}; + const targetUnitsClone = {}; let needVisualizationUpdate = false; // remove all bonuses - for (let name of auraNames) + for (const name of auraNames) { targetUnitsClone[name] = []; if (!this[name]) @@ -237,7 +237,7 @@ Auras.prototype.Clean = function() cmpRangeManager.DestroyActiveQuery(this[name].rangeQuery); } - for (let name of auraNames) + for (const name of auraNames) { // only calculate the affected players on re-applying the bonuses // this makes sure the template bonuses are removed from the correct players @@ -256,14 +256,14 @@ Auras.prototype.Clean = function() this.ApplyTemplateAura(name, affectedPlayers); // Only need to call ApplyAura for the aura icons, so skip it if there are none. if (this.GetOverlayIcon(name)) - for (let player of affectedPlayers) + for (const player of affectedPlayers) this.ApplyAura(name, cmpRangeManager.GetEntitiesByPlayer(player)); continue; } if (this.IsPlayerAura(name)) { - let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); + const cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); this.ApplyAura(name, affectedPlayers.map(p => cmpPlayerManager.GetPlayerByID(p))); continue; } @@ -296,7 +296,7 @@ Auras.prototype.Clean = function() if (needVisualizationUpdate) { - let cmpRangeOverlayManager = Engine.QueryInterface(this.entity, IID_RangeOverlayManager); + const cmpRangeOverlayManager = Engine.QueryInterface(this.entity, IID_RangeOverlayManager); if (cmpRangeOverlayManager) { cmpRangeOverlayManager.UpdateRangeOverlays("Auras"); @@ -309,14 +309,14 @@ Auras.prototype.GiveMembersWithValidClass = function(auraName, entityList) { var match = this.GetClasses(auraName); return entityList.filter(ent => { - let cmpIdentity = Engine.QueryInterface(ent, IID_Identity); + const cmpIdentity = Engine.QueryInterface(ent, IID_Identity); return cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), match); }); }; Auras.prototype.OnRangeUpdate = function(msg) { - for (let name of this.GetAuraNames().filter(n => this[n] && msg.tag == this[n].rangeQuery)) + for (const name of this.GetAuraNames().filter(n => this[n] && msg.tag == this[n].rangeQuery)) { this.ApplyAura(name, msg.added); this.RemoveAura(name, msg.removed); @@ -325,7 +325,7 @@ Auras.prototype.OnRangeUpdate = function(msg) Auras.prototype.OnGarrisonedUnitsChanged = function(msg) { - for (let name of this.GetAuraNames().filter(n => this.IsGarrisonedUnitsAura(n))) + for (const name of this.GetAuraNames().filter(n => this.IsGarrisonedUnitsAura(n))) { this.ApplyAura(name, msg.added); this.RemoveAura(name, msg.removed); @@ -334,7 +334,7 @@ Auras.prototype.OnGarrisonedUnitsChanged = function(msg) Auras.prototype.OnTurretsChanged = function(msg) { - for (let name of this.GetAuraNames().filter(n => this.IsTurretedUnitsAura(n))) + for (const name of this.GetAuraNames().filter(n => this.IsTurretedUnitsAura(n))) { this.ApplyAura(name, msg.added); this.RemoveAura(name, msg.removed); @@ -343,13 +343,13 @@ Auras.prototype.OnTurretsChanged = function(msg) Auras.prototype.ApplyFormationAura = function(memberList) { - for (let name of this.GetAuraNames().filter(n => this.IsFormationAura(n))) + for (const name of this.GetAuraNames().filter(n => this.IsFormationAura(n))) this.ApplyAura(name, memberList); }; Auras.prototype.ApplyGarrisonAura = function(structure) { - for (let name of this.GetAuraNames().filter(n => this.IsGarrisonAura(n))) + for (const name of this.GetAuraNames().filter(n => this.IsGarrisonAura(n))) this.ApplyAura(name, [structure]); }; @@ -361,27 +361,27 @@ Auras.prototype.ApplyTemplateAura = function(name, players) if (!this.IsGlobalAura(name)) return; - let derivedModifiers = DeriveModificationsFromTech({ + const derivedModifiers = DeriveModificationsFromTech({ "modifications": this.GetModifications(name), "affects": this.GetClasses(name) }); - let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); - let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); + const cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); + const cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); - let modifName = this.GetModifierIdentifier(name); - for (let player of players) + const modifName = this.GetModifierIdentifier(name); + for (const player of players) cmpModifiersManager.AddModifiers(modifName, derivedModifiers, cmpPlayerManager.GetPlayerByID(player)); }; Auras.prototype.RemoveFormationAura = function(memberList) { - for (let name of this.GetAuraNames().filter(n => this.IsFormationAura(n))) + for (const name of this.GetAuraNames().filter(n => this.IsFormationAura(n))) this.RemoveAura(name, memberList); }; Auras.prototype.RemoveGarrisonAura = function(structure) { - for (let name of this.GetAuraNames().filter(n => this.IsGarrisonAura(n))) + for (const name of this.GetAuraNames().filter(n => this.IsGarrisonAura(n))) this.RemoveAura(name, [structure]); }; @@ -393,18 +393,18 @@ Auras.prototype.RemoveTemplateAura = function(name) if (!this.IsGlobalAura(name)) return; - let derivedModifiers = DeriveModificationsFromTech({ + const derivedModifiers = DeriveModificationsFromTech({ "modifications": this.GetModifications(name), "affects": this.GetClasses(name) }); - let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); - let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); + const cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); + const cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); - let modifName = this.GetModifierIdentifier(name); - for (let player of this.GetAffectedPlayers(name)) + const modifName = this.GetModifierIdentifier(name); + for (const player of this.GetAffectedPlayers(name)) { - let playerId = cmpPlayerManager.GetPlayerByID(player); - for (let modifierPath in derivedModifiers) + const playerId = cmpPlayerManager.GetPlayerByID(player); + for (const modifierPath in derivedModifiers) cmpModifiersManager.RemoveModifier(modifierPath, modifName, playerId); } }; @@ -422,9 +422,9 @@ Auras.prototype.ApplyAura = function(name, ents) // update status bars if this has an icon if (this.GetOverlayIcon(name)) - for (let ent of validEnts) + for (const ent of validEnts) { - let cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars); + const cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars); if (cmpStatusBars) cmpStatusBars.AddAuraSource(this.entity, name); } @@ -434,15 +434,15 @@ Auras.prototype.ApplyAura = function(name, ents) if (this.IsGlobalAura(name)) return; - let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); + const cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); - let derivedModifiers = DeriveModificationsFromTech({ + const derivedModifiers = DeriveModificationsFromTech({ "modifications": this.GetModifications(name), "affects": this.GetClasses(name) }); - let modifName = this.GetModifierIdentifier(name); - for (let ent of validEnts) + const modifName = this.GetModifierIdentifier(name); + for (const ent of validEnts) cmpModifiersManager.AddModifiers(modifName, derivedModifiers, ent); }; @@ -459,9 +459,9 @@ Auras.prototype.RemoveAura = function(name, ents, skipModifications = false) // update status bars if this has an icon if (this.GetOverlayIcon(name)) - for (let ent of validEnts) + for (const ent of validEnts) { - let cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars); + const cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars); if (cmpStatusBars) cmpStatusBars.RemoveAuraSource(this.entity, name); } @@ -471,16 +471,16 @@ Auras.prototype.RemoveAura = function(name, ents, skipModifications = false) if (this.IsGlobalAura(name)) return; - let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); + const cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager); - let derivedModifiers = DeriveModificationsFromTech({ + const derivedModifiers = DeriveModificationsFromTech({ "modifications": this.GetModifications(name), "affects": this.GetClasses(name) }); - let modifName = this.GetModifierIdentifier(name); - for (let ent of ents) - for (let modifierPath in derivedModifiers) + const modifName = this.GetModifierIdentifier(name); + for (const ent of ents) + for (const modifierPath in derivedModifiers) cmpModifiersManager.RemoveModifier(modifierPath, modifName, ent); }; @@ -503,9 +503,9 @@ Auras.prototype.OnGlobalResearchFinished = function(msg) var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); if ((!cmpPlayer || cmpPlayer.GetPlayerID() != msg.player) && !IsOwnedByPlayer(msg.player, this.entity)) return; - for (let name of this.GetAuraNames()) + for (const name of this.GetAuraNames()) { - let requiredTech = AuraTemplates.Get(name).requiredTechnology; + const requiredTech = AuraTemplates.Get(name).requiredTechnology; if (requiredTech && requiredTech == msg.tech) { this.Clean(); @@ -519,7 +519,7 @@ Auras.prototype.OnGlobalResearchFinished = function(msg) */ Auras.prototype.OnGlobalPlayerDefeated = function(msg) { - let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); + const cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); if (cmpPlayer && cmpPlayer.GetPlayerID() == msg.playerId || this.GetAuraNames().some(name => this.GetAffectedPlayers(name).indexOf(msg.playerId) != -1)) this.Clean(); diff --git a/binaries/data/mods/public/simulation/components/AutoBuildable.js b/binaries/data/mods/public/simulation/components/AutoBuildable.js index 94902a820e..1e39427461 100644 --- a/binaries/data/mods/public/simulation/components/AutoBuildable.js +++ b/binaries/data/mods/public/simulation/components/AutoBuildable.js @@ -25,12 +25,12 @@ class AutoBuildable if (this.timer || !this.rate) return; - let cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); + const cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); if (!cmpFoundation) return; cmpFoundation.AddBuilder(this.entity); - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); this.timer = cmpTimer.SetInterval(this.entity, IID_AutoBuildable, "AutoBuild", 0, 1000, undefined); } @@ -39,11 +39,11 @@ class AutoBuildable if (!this.timer) return; - let cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); + const cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); if (cmpFoundation) cmpFoundation.RemoveBuilder(this.entity); - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); cmpTimer.CancelTimer(this.timer); delete this.timer; } @@ -55,7 +55,7 @@ class AutoBuildable this.CancelTimer(); return; } - let cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); + const cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); if (!cmpFoundation) { this.CancelTimer(); diff --git a/binaries/data/mods/public/simulation/components/BuildRestrictions.js b/binaries/data/mods/public/simulation/components/BuildRestrictions.js index 792d592975..a5a26a1b6d 100644 --- a/binaries/data/mods/public/simulation/components/BuildRestrictions.js +++ b/binaries/data/mods/public/simulation/components/BuildRestrictions.js @@ -241,10 +241,10 @@ BuildRestrictions.prototype.CheckPlacement = function() } } - let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); + const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); - let templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); - let template = cmpTemplateManager.GetTemplate(removeFiltersFromTemplateName(templateName)); + const templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity); + const template = cmpTemplateManager.GetTemplate(removeFiltersFromTemplateName(templateName)); // Check distance restriction if (this.template.Distance) @@ -260,10 +260,10 @@ BuildRestrictions.prototype.CheckPlacement = function() if (this.template.Distance.MinDistance !== undefined) { - let minDistance = ApplyValueModificationsToTemplate("BuildRestrictions/Distance/MinDistance", +this.template.Distance.MinDistance, cmpPlayer.GetPlayerID(), template); + const minDistance = ApplyValueModificationsToTemplate("BuildRestrictions/Distance/MinDistance", +this.template.Distance.MinDistance, cmpPlayer.GetPlayerID(), template); if (cmpRangeManager.ExecuteQuery(this.entity, 0, minDistance, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions, false).some(filter)) { - let result = markForPluralTranslation( + const result = markForPluralTranslation( "%(name)s too close to a %(category)s, must be at least %(distance)s meter away", "%(name)s too close to a %(category)s, must be at least %(distance)s meters away", minDistance); @@ -281,10 +281,10 @@ BuildRestrictions.prototype.CheckPlacement = function() } if (this.template.Distance.MaxDistance !== undefined) { - let maxDistance = ApplyValueModificationsToTemplate("BuildRestrictions/Distance/MaxDistance", +this.template.Distance.MaxDistance, cmpPlayer.GetPlayerID(), template); + const maxDistance = ApplyValueModificationsToTemplate("BuildRestrictions/Distance/MaxDistance", +this.template.Distance.MaxDistance, cmpPlayer.GetPlayerID(), template); if (!cmpRangeManager.ExecuteQuery(this.entity, 0, maxDistance, [cmpPlayer.GetPlayerID()], IID_BuildRestrictions, false).some(filter)) { - let result = markForPluralTranslation( + const result = markForPluralTranslation( "%(name)s too far from a %(category)s, must be within %(distance)s meter", "%(name)s too far from a %(category)s, must be within %(distance)s meters", maxDistance); diff --git a/binaries/data/mods/public/simulation/components/Builder.js b/binaries/data/mods/public/simulation/components/Builder.js index 7d29f4c6d8..1f3da1b7bf 100644 --- a/binaries/data/mods/public/simulation/components/Builder.js +++ b/binaries/data/mods/public/simulation/components/Builder.js @@ -33,21 +33,21 @@ Builder.prototype.GetEntitiesList = function() if (!string) return []; - let cmpPlayer = QueryOwnerInterface(this.entity); + const cmpPlayer = QueryOwnerInterface(this.entity); if (!cmpPlayer) return []; string = ApplyValueModificationsToEntity("Builder/Entities/_string", string, this.entity); - let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); + const cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); if (cmpIdentity) string = string.replace(/\{native\}/g, cmpIdentity.GetCiv()); const entities = string.replace(/\{civ\}/g, QueryOwnerInterface(this.entity, IID_Identity).GetCiv()).split(/\s+/); - let disabledTemplates = cmpPlayer.GetDisabledTemplates(); + const disabledTemplates = cmpPlayer.GetDisabledTemplates(); - let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); + const cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); return entities.filter(ent => !disabledTemplates[ent] && cmpTemplateManager.TemplateExists(ent)); }; @@ -55,7 +55,7 @@ Builder.prototype.GetEntitiesList = function() Builder.prototype.GetRange = function() { let max = 2; - let cmpObstruction = Engine.QueryInterface(this.entity, IID_Obstruction); + const cmpObstruction = Engine.QueryInterface(this.entity, IID_Obstruction); if (cmpObstruction) max += cmpObstruction.GetSize(); @@ -73,12 +73,12 @@ Builder.prototype.GetRate = function() */ Builder.prototype.CanRepair = function(target) { - let cmpFoundation = QueryMiragedInterface(target, IID_Foundation); - let cmpRepairable = QueryMiragedInterface(target, IID_Repairable); + const cmpFoundation = QueryMiragedInterface(target, IID_Foundation); + const cmpRepairable = QueryMiragedInterface(target, IID_Repairable); if (!cmpFoundation && (!cmpRepairable || !cmpRepairable.IsRepairable())) return false; - let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); + const cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); return cmpOwnership && IsOwnedByAllyOfPlayer(cmpOwnership.GetOwner(), target); }; @@ -95,18 +95,18 @@ Builder.prototype.StartRepairing = function(target, callerIID) if (!this.CanRepair(target)) return false; - let cmpBuilderList = QueryBuilderListInterface(target); + const cmpBuilderList = QueryBuilderListInterface(target); if (cmpBuilderList) cmpBuilderList.AddBuilder(this.entity); - let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); + const cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); if (cmpVisual) cmpVisual.SelectAnimation("build", false, 1.0); this.target = target; this.callerIID = callerIID; - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); this.timer = cmpTimer.SetInterval(this.entity, IID_Builder, "PerformBuilding", this.BUILD_INTERVAL, this.BUILD_INTERVAL, null); return true; @@ -120,28 +120,28 @@ Builder.prototype.StopRepairing = function(reason) if (!this.target) return; - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); cmpTimer.CancelTimer(this.timer); delete this.timer; - let cmpBuilderList = QueryBuilderListInterface(this.target); + const cmpBuilderList = QueryBuilderListInterface(this.target); if (cmpBuilderList) cmpBuilderList.RemoveBuilder(this.entity); delete this.target; - let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); + const cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); if (cmpVisual) cmpVisual.SelectAnimation("idle", false, 1.0); // The callerIID component may start again, // replacing the callerIID, hence save that. - let callerIID = this.callerIID; + const callerIID = this.callerIID; delete this.callerIID; if (reason && callerIID) { - let component = Engine.QueryInterface(this.entity, callerIID); + const component = Engine.QueryInterface(this.entity, callerIID); if (component) component.ProcessMessage(reason, null); } @@ -168,14 +168,14 @@ Builder.prototype.PerformBuilding = function(data, lateness) // ToDo: Enable entities to keep facing a target. Engine.QueryInterface(this.entity, IID_UnitAI)?.FaceTowardsTarget(this.target); - let cmpFoundation = Engine.QueryInterface(this.target, IID_Foundation); + const cmpFoundation = Engine.QueryInterface(this.target, IID_Foundation); if (cmpFoundation) { cmpFoundation.Build(this.entity, this.GetRate()); return; } - let cmpRepairable = Engine.QueryInterface(this.target, IID_Repairable); + const cmpRepairable = Engine.QueryInterface(this.target, IID_Repairable); if (cmpRepairable) { cmpRepairable.Repair(this.entity, this.GetRate()); @@ -189,8 +189,8 @@ Builder.prototype.PerformBuilding = function(data, lateness) */ Builder.prototype.IsTargetInRange = function(target) { - let range = this.GetRange(); - let cmpObstructionManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager); + const range = this.GetRange(); + const cmpObstructionManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager); return cmpObstructionManager.IsInTargetRange(this.entity, target, range.min, range.max, false); }; @@ -200,7 +200,7 @@ Builder.prototype.OnValueModification = function(msg) return; // Token changes may require selection updates. - let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); + const cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); if (cmpPlayer) Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).SetSelectionDirty(cmpPlayer.GetPlayerID()); }; diff --git a/binaries/data/mods/public/simulation/components/BuildingAI.js b/binaries/data/mods/public/simulation/components/BuildingAI.js index 65e3a21235..7e47de0ce8 100644 --- a/binaries/data/mods/public/simulation/components/BuildingAI.js +++ b/binaries/data/mods/public/simulation/components/BuildingAI.js @@ -33,16 +33,16 @@ BuildingAI.prototype.Init = function() BuildingAI.prototype.OnGarrisonedUnitsChanged = function(msg) { - let classes = this.template.GarrisonArrowClasses; - for (let ent of msg.added) + const classes = this.template.GarrisonArrowClasses; + for (const ent of msg.added) { - let cmpIdentity = Engine.QueryInterface(ent, IID_Identity); + const cmpIdentity = Engine.QueryInterface(ent, IID_Identity); if (cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), classes)) ++this.archersGarrisoned; } - for (let ent of msg.removed) + for (const ent of msg.removed) { - let cmpIdentity = Engine.QueryInterface(ent, IID_Identity); + const cmpIdentity = Engine.QueryInterface(ent, IID_Identity); if (cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), classes)) --this.archersGarrisoned; } @@ -71,13 +71,13 @@ BuildingAI.prototype.OnDestroy = function() { if (this.timer) { - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); cmpTimer.CancelTimer(this.timer); this.timer = undefined; } // Clean up range queries. - let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); if (this.enemyUnitsQuery) cmpRangeManager.DestroyActiveQuery(this.enemyUnitsQuery); if (this.gaiaUnitsQuery) @@ -179,7 +179,7 @@ BuildingAI.prototype.OnRangeUpdate = function(msg) if (msg.tag == this.gaiaUnitsQuery) { msg.added = msg.added.filter(e => { - let cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI); + const cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI); return cmpUnitAI && (!cmpUnitAI.IsAnimal() || cmpUnitAI.IsDangerousAnimal()); }); } @@ -187,14 +187,14 @@ BuildingAI.prototype.OnRangeUpdate = function(msg) return; // Add new targets. - for (let entity of msg.added) + for (const entity of msg.added) if (cmpAttack.CanAttack(entity)) this.targetUnits.push(entity); // Remove targets outside of vision-range. - for (let entity of msg.removed) + for (const entity of msg.removed) { - let index = this.targetUnits.indexOf(entity); + const index = this.targetUnits.indexOf(entity); if (index > -1) this.targetUnits.splice(index, 1); } @@ -230,7 +230,7 @@ BuildingAI.prototype.GetMaxArrowCount = function() if (!this.template.MaxArrowCount) return Infinity; - let maxArrowCount = +this.template.MaxArrowCount; + const maxArrowCount = +this.template.MaxArrowCount; return Math.round(ApplyValueModificationsToEntity("BuildingAI/MaxArrowCount", maxArrowCount, this.entity)); }; @@ -255,7 +255,7 @@ BuildingAI.prototype.GetGarrisonArrowClasses = function() */ BuildingAI.prototype.GetArrowCount = function() { - let count = this.GetDefaultArrowCount() + + const count = this.GetDefaultArrowCount() + Math.round(this.archersGarrisoned * this.GetGarrisonArrowMultiplier()); return Math.min(count, this.GetMaxArrowCount()); @@ -295,13 +295,13 @@ BuildingAI.prototype.FireArrows = function() if (!this.timer) return; - let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + const cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); cmpTimer.CancelTimer(this.timer); this.timer = undefined; return; } - let cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); + const cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); if (!cmpAttack) return; @@ -329,7 +329,7 @@ BuildingAI.prototype.FireArrows = function() // Add targets to a list. let targets = []; - let addTarget = function(target) + const addTarget = function(target) { const pref = (cmpAttack.GetPreference(target) ?? 49); targets.push({ "entityId": target, "preference": pref }); @@ -344,7 +344,7 @@ BuildingAI.prototype.FireArrows = function() if (!this.focusTargets.length) { - for (let target of this.targetUnits) + for (const target of this.targetUnits) addTarget(target); // Sort targets by preference and then by proximity. targets.sort( (a, b) => { @@ -372,7 +372,7 @@ BuildingAI.prototype.FireArrows = function() while (firedArrows < arrowsToFire && targetIndex < targets.length) { - let selectedTarget = targets[targetIndex].entityId; + const selectedTarget = targets[targetIndex].entityId; if (this.CheckTargetVisible(selectedTarget) && cmpObstructionManager.IsInTargetParabolicRange( this.entity, selectedTarget, @@ -408,7 +408,7 @@ BuildingAI.prototype.CheckTargetVisible = function(target) return true; // Either visible directly, or visible in fog. - let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); return cmpRangeManager.GetLosVisibility(target, cmpOwnership.GetOwner()) != "hidden"; };