Index: ps/trunk/binaries/data/mods/public/simulation/components/StatisticsTracker.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/StatisticsTracker.js +++ ps/trunk/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 The statistics are consumed by the summary screen and lobby rankings." + + "" + + "Infantry FemaleCitizen" + + "House Wonder" + + "" + + "" + + "" + + "tokens" + + "" + + "" + + "" + + "" + + "" + + "tokens" + + "" + + "" + + ""; + +/** + * This number specifies the time in milliseconds 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: ps/trunk/binaries/data/mods/public/simulation/components/tests/test_StatisticsTracker.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/tests/test_StatisticsTracker.js +++ ps/trunk/binaries/data/mods/public/simulation/components/tests/test_StatisticsTracker.js @@ -10,27 +10,33 @@ "GetCodes": () => ["food", "metal", "stone", "wood"] }; -let cmpStatisticsTracker = ConstructComponent(SYSTEM_ENTITY, "StatisticsTracker"); -let obj1 = { +let cmpStatisticsTracker = ConstructComponent(SYSTEM_ENTITY, "StatisticsTracker", { + "UnitClasses": { "_string": "Infantry FishingBoat" }, + "StructureClasses": { "_string": "House Wonder" } +}); + +let fromData = { "successfulBribes": 3, "unitsTrained": { "Infantry": 5, "Worker": 7 } }; -let obj2 = { + +let toData = { "successfulBribes": [11, 13, 17], "unitsTrained": { "Infantry": [19, 23], - "Worker": 29 + "Worker": [29] } }; -cmpStatisticsTracker.PushValue(obj1, obj2); -TS_ASSERT_UNEVAL_EQUALS(obj2, { +// This function pushes without testing for Identity classes +cmpStatisticsTracker.PushValue(fromData, toData); +TS_ASSERT_UNEVAL_EQUALS(toData, { "successfulBribes": [11, 13, 17, 3], "unitsTrained": { "Infantry": [19, 23, 5], - "Worker": [7] + "Worker": [29, 7] } }); Index: ps/trunk/binaries/data/mods/public/simulation/templates/special/player/player.xml =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/templates/special/player/player.xml +++ ps/trunk/binaries/data/mods/public/simulation/templates/special/player/player.xml @@ -89,6 +89,29 @@ 1000 - + + + + Infantry + Worker + FemaleCitizen + Cavalry + Champion + Hero + Siege + Ship + Domestic + Trader + + + House + Economic + Outpost + Military + Fortress + CivCentre + Wonder + +