Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/StatisticsTracker.js
Show All 18 Lines | "<element name='StructureClasses' a:help='The tracker records constructed, lost, destroyed and captured structures of entities that match any of these Identity classes.'>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>"; | "</element>"; | ||||
/** | /** | ||||
* This number specifies the time in milliseconds between consecutive statistics snapshots recorded. | * This number specifies the time in milliseconds between consecutive statistics snapshots recorded. | ||||
*/ | */ | ||||
StatisticsTracker.prototype.UpdateSequenceInterval = 30 * 1000; | StatisticsTracker.prototype.UpdateSequenceInterval = 30 * 1000; | ||||
/** | |||||
* This number specifies the time in milliseconds between consecutive times the idle units should be counted. | |||||
*/ | |||||
StatisticsTracker.prototype.UpdateIdleUnitsInterval = 1 * 1000; | |||||
StatisticsTracker.prototype.Init = function() | StatisticsTracker.prototype.Init = function() | ||||
{ | { | ||||
this.unitsClasses = this.template.UnitClasses._string.split(/\s+/); | this.unitsClasses = this.template.UnitClasses._string.split(/\s+/); | ||||
this.buildingsClasses = this.template.StructureClasses._string.split(/\s+/); | this.buildingsClasses = this.template.StructureClasses._string.split(/\s+/); | ||||
this.unitsTrained = {}; | this.unitsTrained = {}; | ||||
this.unitsLost = {}; | this.unitsLost = {}; | ||||
this.enemyUnitsKilled = {}; | this.enemyUnitsKilled = {}; | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | StatisticsTracker.prototype.Init = function() | ||||
this.tradeIncome = 0; | this.tradeIncome = 0; | ||||
this.treasuresCollected = 0; | this.treasuresCollected = 0; | ||||
this.lootCollected = 0; | this.lootCollected = 0; | ||||
this.peakPercentMapControlled = 0; | this.peakPercentMapControlled = 0; | ||||
this.teamPeakPercentMapControlled = 0; | this.teamPeakPercentMapControlled = 0; | ||||
this.successfulBribes = 0; | this.successfulBribes = 0; | ||||
this.failedBribes = 0; | this.failedBribes = 0; | ||||
this.prevIdleUnits = 0; | |||||
this.idleTime = 0; | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
this.prevIdleUpdate = cmpTimer.GetTime(); | |||||
this.updateTimer = cmpTimer.SetInterval( | this.updateTimer = cmpTimer.SetInterval( | ||||
this.entity, IID_StatisticsTracker, "UpdateSequences", 0, this.UpdateSequenceInterval); | this.entity, IID_StatisticsTracker, "UpdateSequences", 0, this.UpdateSequenceInterval); | ||||
this.idleUnitsTimer = cmpTimer.SetInterval( | |||||
this.entity, IID_StatisticsTracker, "UpdateIdleUnits", 0, this.UpdateIdleUnitsInterval); | |||||
}; | }; | ||||
StatisticsTracker.prototype.OnGlobalInitGame = function() | StatisticsTracker.prototype.OnGlobalInitGame = function() | ||||
{ | { | ||||
this.sequences = clone(this.GetStatistics()); | this.sequences = clone(this.GetStatistics()); | ||||
this.sequences.time = []; | this.sequences.time = []; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | return { | ||||
"populationCount": this.GetPopulationCount(), | "populationCount": this.GetPopulationCount(), | ||||
"percentMapExplored": this.GetPercentMapExplored(), | "percentMapExplored": this.GetPercentMapExplored(), | ||||
"teamPercentMapExplored": this.GetTeamPercentMapExplored(), | "teamPercentMapExplored": this.GetTeamPercentMapExplored(), | ||||
"percentMapControlled": this.GetPercentMapControlled(), | "percentMapControlled": this.GetPercentMapControlled(), | ||||
"teamPercentMapControlled": this.GetTeamPercentMapControlled(), | "teamPercentMapControlled": this.GetTeamPercentMapControlled(), | ||||
"peakPercentMapControlled": this.peakPercentMapControlled, | "peakPercentMapControlled": this.peakPercentMapControlled, | ||||
"teamPeakPercentMapControlled": this.teamPeakPercentMapControlled, | "teamPeakPercentMapControlled": this.teamPeakPercentMapControlled, | ||||
"successfulBribes": this.successfulBribes, | "successfulBribes": this.successfulBribes, | ||||
"failedBribes": this.failedBribes | "failedBribes": this.failedBribes, | ||||
"idleTime": this.idleTime | |||||
}; | }; | ||||
}; | }; | ||||
StatisticsTracker.prototype.GetSequences = function() | StatisticsTracker.prototype.GetSequences = function() | ||||
{ | { | ||||
let ret = clone(this.sequences); | let ret = clone(this.sequences); | ||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | ||||
▲ Show 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | if (!cmpPlayer) | ||||
return 0; | return 0; | ||||
return Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager).GetTerritoryPercentage(cmpPlayer.GetPlayerID()); | return Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager).GetTerritoryPercentage(cmpPlayer.GetPlayerID()); | ||||
}; | }; | ||||
StatisticsTracker.prototype.GetTeamPercentMapControlled = function() | StatisticsTracker.prototype.GetTeamPercentMapControlled = function() | ||||
{ | { | ||||
let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); | let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); | ||||
if (!cmpPlayer) | if (!cmpPlayer) | ||||
Freagarach: ? ;P | |||||
return 0; | return 0; | ||||
let team = cmpPlayer.GetTeam(); | let team = cmpPlayer.GetTeam(); | ||||
let cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager); | let cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager); | ||||
if (team == -1 || !cmpPlayer.GetLockTeams()) | if (team == -1 || !cmpPlayer.GetLockTeams()) | ||||
return cmpTerritoryManager.GetTerritoryPercentage(cmpPlayer.GetPlayerID()); | return cmpTerritoryManager.GetTerritoryPercentage(cmpPlayer.GetPlayerID()); | ||||
let teamPercent = 0; | let teamPercent = 0; | ||||
Show All 24 Lines | |||||
}; | }; | ||||
StatisticsTracker.prototype.UpdatePeakPercentages = function() | StatisticsTracker.prototype.UpdatePeakPercentages = function() | ||||
{ | { | ||||
this.peakPercentMapControlled = Math.max(this.peakPercentMapControlled, this.GetPercentMapControlled()); | this.peakPercentMapControlled = Math.max(this.peakPercentMapControlled, this.GetPercentMapControlled()); | ||||
this.teamPeakPercentMapControlled = Math.max(this.teamPeakPercentMapControlled, this.GetTeamPercentMapControlled()); | this.teamPeakPercentMapControlled = Math.max(this.teamPeakPercentMapControlled, this.GetTeamPercentMapControlled()); | ||||
}; | }; | ||||
StatisticsTracker.prototype.UpdateIdleUnits = function() | |||||
{ | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
Not Done Inline ActionsWe usually safeguard against cmpPlayer being null. Freagarach: We usually safeguard against `cmpPlayer` being `null`. | |||||
Not Done Inline Actionsusually yes, but we do not care in this file as far as i can see Silier: usually yes, but we do not care in this file as far as i can see | |||||
let time = cmpTimer.GetTime(); | |||||
let passed = time - this.prevIdleUpdate; | |||||
this.prevIdleUpdate = time; | |||||
let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); | |||||
let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); | |||||
let idleUnits = cmpGUIInterface.CountIdleUnits(cmpPlayer.GetPlayerID(), { | |||||
"idleClasses": ["FemaleCitizen", "Trader", "FishingBoat", "Citizen"], | |||||
"excludeUnits": [] | |||||
}); | |||||
let stayedIdle = Math.min(this.prevIdleUnits, idleUnits); | |||||
let changedIdle = Math.max(this.prevIdleUnits, idleUnits) - stayedIdle; | |||||
this.prevIdleUnits = idleUnits; | |||||
this.idleTime += passed * (stayedIdle + changedIdle / 2); | |||||
print(this.entity + ": " + this.idleTime + "\n"); | |||||
} | |||||
/** | /** | ||||
* Adds the values of fromData to the end of the arrays of toData. | * Adds the values of fromData to the end of the arrays of toData. | ||||
* If toData misses the needed array, one will be created. | * If toData misses the needed array, one will be created. | ||||
* | * | ||||
* @param fromData - an object of values or a value. | * @param fromData - an object of values or a value. | ||||
* @param toData - an object of arrays or an array. | * @param toData - an object of arrays or an array. | ||||
**/ | **/ | ||||
StatisticsTracker.prototype.PushValue = function(fromData, toData) | StatisticsTracker.prototype.PushValue = function(fromData, toData) | ||||
Show All 21 Lines |
Wildfire Games · Phabricator
? ;P