Index: binaries/data/mods/public/simulation/components/StatisticsTracker.js =================================================================== --- binaries/data/mods/public/simulation/components/StatisticsTracker.js +++ binaries/data/mods/public/simulation/components/StatisticsTracker.js @@ -1,130 +1,68 @@ function StatisticsTracker() {} -const g_UpdateSequenceInterval = 30 * 1000; - StatisticsTracker.prototype.Schema = - ""; + "This component records statistics over the course of the match, such as the number of trained, lost, captured and destroyed units and buildings." + + "" + + "Infantry FemaleCitizen" + + "House Wonder" + + "" + + "" + + "" + + "tokens" + + "" + + "" + + "" + + "" + + "" + + "tokens" + + "" + + "" + + ""; + +/** + * This number specifies the time between consecutive statistics snapshots recorded. + */ +StatisticsTracker.prototype.UpdateSequenceInterval = 30 * 1000; StatisticsTracker.prototype.Init = function() { - this.unitsClasses = [ - "Infantry", - "Worker", - "FemaleCitizen", - "Cavalry", - "Champion", - "Hero", - "Siege", - "Ship", - "Domestic", - "Trader" - ]; - this.unitsTrained = { - "Infantry": 0, - "Worker": 0, - "FemaleCitizen": 0, - "Cavalry": 0, - "Champion": 0, - "Hero": 0, - "Siege": 0, - "Ship": 0, - "Trader": 0, - "Domestic": 0, - "total": 0 - }; - this.unitsLost = { - "Infantry": 0, - "Worker": 0, - "FemaleCitizen": 0, - "Cavalry": 0, - "Champion": 0, - "Hero": 0, - "Siege": 0, - "Ship": 0, - "Trader": 0, - "total": 0 - }; + this.unitsClasses = this.template.UnitClasses._string.split(/\s+/); + this.buildingsClasses = this.template.StructureClasses._string.split(/\s+/); + + this.unitsTrained = {}; + this.unitsLost = {}; + this.enemyUnitsKilled = {}; + this.unitsCaptured = {}; + this.unitsLostValue = 0; - this.enemyUnitsKilled = { - "Infantry": 0, - "Worker": 0, - "FemaleCitizen": 0, - "Cavalry": 0, - "Champion": 0, - "Hero": 0, - "Siege": 0, - "Ship": 0, - "Trader": 0, - "total": 0 - }; this.enemyUnitsKilledValue = 0; - this.unitsCaptured = { - "Infantry": 0, - "Worker": 0, - "FemaleCitizen": 0, - "Cavalry": 0, - "Champion": 0, - "Hero": 0, - "Siege": 0, - "Ship": 0, - "Trader": 0, - "total": 0 - }; this.unitsCapturedValue = 0; - this.buildingsClasses = [ - "House", - "Economic", - "Outpost", - "Military", - "Fortress", - "CivCentre", - "Wonder" - ]; - this.buildingsConstructed = { - "House": 0, - "Economic": 0, - "Outpost": 0, - "Military": 0, - "Fortress": 0, - "CivCentre": 0, - "Wonder": 0, - "total": 0 - }; - this.buildingsLost = { - "House": 0, - "Economic": 0, - "Outpost": 0, - "Military": 0, - "Fortress": 0, - "CivCentre": 0, - "Wonder": 0, - "total": 0 - }; + for (let counterName of ["unitsTrained", "unitsLost", "enemyUnitsKilled", "unitsCaptured"]) + { + this[counterName].total = 0; + for (let unitClass of this.unitsClasses) + // Domestic units are only counted for training + if (unitClass != "Domestic" || counterName == "unitsTrained") + this[counterName][unitClass] = 0; + } + + this.buildingsConstructed = {}; + this.buildingsLost = {}; + this.enemyBuildingsDestroyed = {}; + this.buildingsCaptured = {}; + this.buildingsLostValue = 0; - this.enemyBuildingsDestroyed = { - "House": 0, - "Economic": 0, - "Outpost": 0, - "Military": 0, - "Fortress": 0, - "CivCentre": 0, - "Wonder": 0, - "total": 0 - }; this.enemyBuildingsDestroyedValue = 0; - this.buildingsCaptured = { - "House": 0, - "Economic": 0, - "Outpost": 0, - "Military": 0, - "Fortress": 0, - "CivCentre": 0, - "Wonder": 0, - "total": 0 - }; this.buildingsCapturedValue = 0; + for (let counterName of ["buildingsConstructed", "buildingsLost", "enemyBuildingsDestroyed", "buildingsCaptured"]) + { + this[counterName].total = 0; + for (let unitClass of this.buildingsClasses) + this[counterName][unitClass] = 0; + } + this.resourcesGathered = { "vegetarianFood": 0 }; @@ -151,7 +89,7 @@ let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); this.updateTimer = cmpTimer.SetInterval( - this.entity, IID_StatisticsTracker, "UpdateSequences", 0, g_UpdateSequenceInterval); + this.entity, IID_StatisticsTracker, "UpdateSequences", 0, this.UpdateSequenceInterval); }; StatisticsTracker.prototype.OnGlobalInitGame = function() @@ -311,6 +249,7 @@ var cmpCost = Engine.QueryInterface(targetEntity, IID_Cost); var costs = cmpCost && cmpCost.GetResourceCosts(); + // Exclude gaia animals but not gaia soldiers if (cmpTargetEntityIdentity.HasClass("Unit") && !cmpTargetEntityIdentity.HasClass("Animal")) { for (let type of this.unitsClasses) Index: binaries/data/mods/public/simulation/components/tests/test_StatisticsTracker.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_StatisticsTracker.js +++ binaries/data/mods/public/simulation/components/tests/test_StatisticsTracker.js @@ -10,7 +10,11 @@ "GetCodes": () => ["food", "metal", "stone", "wood"] }; -let cmpStatisticsTracker = ConstructComponent(SYSTEM_ENTITY, "StatisticsTracker"); +let cmpStatisticsTracker = ConstructComponent(SYSTEM_ENTITY, "StatisticsTracker", { + "UnitClasses": { "_string": "Infantry Worker FishingBoat" }, + "StructureClasses": { "_string": "House Wonder" } +}); + let obj1 = { "successfulBribes": 3, "unitsTrained": { @@ -18,6 +22,7 @@ "Worker": 7 } }; + let obj2 = { "successfulBribes": [11, 13, 17], "unitsTrained": { Index: binaries/data/mods/public/simulation/templates/special/player/player.xml =================================================================== --- binaries/data/mods/public/simulation/templates/special/player/player.xml +++ binaries/data/mods/public/simulation/templates/special/player/player.xml @@ -89,6 +89,28 @@ 1000 - + + + Infantry + Worker + FemaleCitizen + Cavalry + Champion + Hero + Siege + Ship + Domestic + Trader + + + House + Economic + Outpost + Military + Fortress + CivCentre + Wonder + +