From 73c210f6fb4a63376aae929f84b3aea2d0737f0f Mon Sep 17 00:00:00 2001 From: leper Date: Sat, 12 Sep 2015 20:58:59 +0000 Subject: [PATCH] Clean up line endings. This was SVN commit r17010. --- .../components/StatisticsTracker.js | 210 +++++++++--------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/StatisticsTracker.js b/binaries/data/mods/public/simulation/components/StatisticsTracker.js index a141155077..9b8e7cef53 100644 --- a/binaries/data/mods/public/simulation/components/StatisticsTracker.js +++ b/binaries/data/mods/public/simulation/components/StatisticsTracker.js @@ -1,8 +1,8 @@ -function StatisticsTracker() {} - -StatisticsTracker.prototype.Schema = - ""; - +function StatisticsTracker() {} + +StatisticsTracker.prototype.Schema = + ""; + StatisticsTracker.prototype.Init = function() { // units @@ -13,8 +13,8 @@ StatisticsTracker.prototype.Init = function() "Cavalry", "Champion", "Hero", - "Ship", - "Trader" + "Ship", + "Trader" ]; this.unitsTrained = { "Infantry": 0, @@ -24,7 +24,7 @@ StatisticsTracker.prototype.Init = function() "Champion": 0, "Hero": 0, "Ship": 0, - "Trader": 0, + "Trader": 0, "total": 0 }; this.unitsLost = { @@ -35,7 +35,7 @@ StatisticsTracker.prototype.Init = function() "Champion": 0, "Hero": 0, "Ship": 0, - "Trader": 0, + "Trader": 0, "total": 0 }; this.unitsLostValue = 0; @@ -47,7 +47,7 @@ StatisticsTracker.prototype.Init = function() "Champion": 0, "Hero": 0, "Ship": 0, - "Trader": 0, + "Trader": 0, "total": 0 }; this.enemyUnitsKilledValue = 0; @@ -121,57 +121,57 @@ StatisticsTracker.prototype.Init = function() }; this.tributesSent = 0; this.tributesReceived = 0; - this.tradeIncome = 0; - this.treasuresCollected = 0; + this.tradeIncome = 0; + this.treasuresCollected = 0; this.lootCollected = 0; this.peakPercentMapControlled = 0; - this.teamPeakPercentMapControlled = 0; -}; - -/** - * Returns a subset of statistics that will be added to the simulation state, - * thus called each turn. Basic statistics should not contain data that would - * be expensive to compute. - * - * Note: as of now, nothing in the game needs that, but some AIs developed by - * modders need it in the API. - */ -StatisticsTracker.prototype.GetBasicStatistics = function() -{ - return { - "resourcesGathered": this.resourcesGathered, - "percentMapExplored": this.GetPercentMapExplored() - }; -}; - -StatisticsTracker.prototype.GetStatistics = function() -{ - return { - "unitsTrained": this.unitsTrained, - "unitsLost": this.unitsLost, - "unitsLostValue": this.unitsLostValue, - "enemyUnitsKilled": this.enemyUnitsKilled, - "enemyUnitsKilledValue": this.enemyUnitsKilledValue, - "buildingsConstructed": this.buildingsConstructed, - "buildingsLost": this.buildingsLost, + this.teamPeakPercentMapControlled = 0; +}; + +/** + * Returns a subset of statistics that will be added to the simulation state, + * thus called each turn. Basic statistics should not contain data that would + * be expensive to compute. + * + * Note: as of now, nothing in the game needs that, but some AIs developed by + * modders need it in the API. + */ +StatisticsTracker.prototype.GetBasicStatistics = function() +{ + return { + "resourcesGathered": this.resourcesGathered, + "percentMapExplored": this.GetPercentMapExplored() + }; +}; + +StatisticsTracker.prototype.GetStatistics = function() +{ + return { + "unitsTrained": this.unitsTrained, + "unitsLost": this.unitsLost, + "unitsLostValue": this.unitsLostValue, + "enemyUnitsKilled": this.enemyUnitsKilled, + "enemyUnitsKilledValue": this.enemyUnitsKilledValue, + "buildingsConstructed": this.buildingsConstructed, + "buildingsLost": this.buildingsLost, "buildingsLostValue": this.buildingsLostValue, "enemyBuildingsDestroyed": this.enemyBuildingsDestroyed, "enemyBuildingsDestroyedValue": this.enemyBuildingsDestroyedValue, "resourcesGathered": this.resourcesGathered, "resourcesUsed": this.resourcesUsed, "resourcesSold": this.resourcesSold, - "resourcesBought": this.resourcesBought, - "tributesSent": this.tributesSent, - "tributesReceived": this.tributesReceived, - "tradeIncome": this.tradeIncome, - "treasuresCollected": this.treasuresCollected, - "lootCollected": this.lootCollected, - "percentMapExplored": this.GetPercentMapExplored(), + "resourcesBought": this.resourcesBought, + "tributesSent": this.tributesSent, + "tributesReceived": this.tributesReceived, + "tradeIncome": this.tradeIncome, + "treasuresCollected": this.treasuresCollected, + "lootCollected": this.lootCollected, + "percentMapExplored": this.GetPercentMapExplored(), "teamPercentMapExplored": this.GetTeamPercentMapExplored(), "percentMapControlled": this.GetPercentMapControlled(), "teamPercentMapControlled": this.GetTeamPercentMapControlled(), "peakPercentMapControlled": this.peakPercentMapControlled, - "teamPeakPercentMapControlled": this.teamPeakPercentMapControlled + "teamPeakPercentMapControlled": this.teamPeakPercentMapControlled }; }; @@ -227,7 +227,7 @@ StatisticsTracker.prototype.IncreaseConstructedBuildingsCounter = function(const }; StatisticsTracker.prototype.KilledEntity = function(targetEntity) -{ +{ var cmpTargetEntityIdentity = Engine.QueryInterface(targetEntity, IID_Identity); var cmpCost = Engine.QueryInterface(targetEntity, IID_Cost); var costs = cmpCost.GetResourceCosts(); @@ -269,8 +269,8 @@ StatisticsTracker.prototype.KilledEntity = function(targetEntity) } }; -StatisticsTracker.prototype.LostEntity = function(lostEntity) -{ +StatisticsTracker.prototype.LostEntity = function(lostEntity) +{ var cmpLostEntityIdentity = Engine.QueryInterface(lostEntity, IID_Identity); var cmpCost = Engine.QueryInterface(lostEntity, IID_Cost); var costs = cmpCost.GetResourceCosts(); @@ -306,13 +306,13 @@ StatisticsTracker.prototype.LostEntity = function(lostEntity) } }; -/** - * @param type Generic type of resource (string) - * @param amount Amount of resource, whick should be added (integer) - * @param specificType Specific type of resource (string, optional) - */ -StatisticsTracker.prototype.IncreaseResourceGatheredCounter = function(type, amount, specificType) -{ +/** + * @param type Generic type of resource (string) + * @param amount Amount of resource, whick should be added (integer) + * @param specificType Specific type of resource (string, optional) + */ +StatisticsTracker.prototype.IncreaseResourceGatheredCounter = function(type, amount, specificType) +{ this.resourcesGathered[type] += amount; if (type == "food" && (specificType == "fruit" || specificType == "grain")) @@ -320,25 +320,25 @@ StatisticsTracker.prototype.IncreaseResourceGatheredCounter = function(type, amo }; /** - * @param type Generic type of resource (string) - * @param amount Amount of resource, which should be added (integer) - */ -StatisticsTracker.prototype.IncreaseResourceUsedCounter = function(type, amount) -{ - this.resourcesUsed[type] += amount; -}; + * @param type Generic type of resource (string) + * @param amount Amount of resource, which should be added (integer) + */ +StatisticsTracker.prototype.IncreaseResourceUsedCounter = function(type, amount) +{ + this.resourcesUsed[type] += amount; +}; StatisticsTracker.prototype.IncreaseTreasuresCollectedCounter = function() { this.treasuresCollected++; }; -StatisticsTracker.prototype.IncreaseLootCollectedCounter = function(amount) -{ - for (let type in amount) - this.lootCollected += amount[type]; -}; - +StatisticsTracker.prototype.IncreaseLootCollectedCounter = function(amount) +{ + for (let type in amount) + this.lootCollected += amount[type]; +}; + StatisticsTracker.prototype.IncreaseResourcesSoldCounter = function(type, amount) { this.resourcesSold[type] += amount; @@ -366,38 +366,38 @@ StatisticsTracker.prototype.IncreaseTradeIncomeCounter = function(amount) StatisticsTracker.prototype.GetPercentMapExplored = function() { - var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); - var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); - return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID()); -}; - -/** - * Note: cmpRangeManager.GetUnionPercentMapExplored computes statistics from scratch! - * As a consequence, this function should not be called too often. - */ -StatisticsTracker.prototype.GetTeamPercentMapExplored = function() -{ - var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); - - var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); - var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); - if (!cmpPlayer) - return 0; - - var team = cmpPlayer.GetTeam(); - // If teams are not locked, this statistic won't be displayed, so don't bother computing - if (team == -1 || !cmpPlayer.GetLockTeams()) - return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID()); - - var teamPlayers = []; - for (var i = 1; i < cmpPlayerManager.GetNumPlayers(); ++i) - { - let cmpOtherPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player); - if (cmpOtherPlayer && cmpOtherPlayer.GetTeam() == team) - teamPlayers.push(i); - } - - return cmpRangeManager.GetUnionPercentMapExplored(teamPlayers); + var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); + return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID()); +}; + +/** + * Note: cmpRangeManager.GetUnionPercentMapExplored computes statistics from scratch! + * As a consequence, this function should not be called too often. + */ +StatisticsTracker.prototype.GetTeamPercentMapExplored = function() +{ + var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + + var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); + var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); + if (!cmpPlayer) + return 0; + + var team = cmpPlayer.GetTeam(); + // If teams are not locked, this statistic won't be displayed, so don't bother computing + if (team == -1 || !cmpPlayer.GetLockTeams()) + return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID()); + + var teamPlayers = []; + for (var i = 1; i < cmpPlayerManager.GetNumPlayers(); ++i) + { + let cmpOtherPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player); + if (cmpOtherPlayer && cmpOtherPlayer.GetTeam() == team) + teamPlayers.push(i); + } + + return cmpRangeManager.GetUnionPercentMapExplored(teamPlayers); }; StatisticsTracker.prototype.GetPercentMapControlled = function() @@ -444,4 +444,4 @@ StatisticsTracker.prototype.OnTerritoriesChanged = function(msg) this.teamPeakPercentMapControlled = newPercent; }; -Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker); +Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker);