1
0
forked from 0ad/0ad

Don't subtract lifestock from used/gathered resources.

Also some cleaning in the statistics tracker.
(`total` is used by the lobby bots and hence not removed.)

References 215a102c27 and #3948.
Differential revision: Don't subtract lifestock from used/gathered
resources.
Tested by: @Langbart
Fixes #6744

This was SVN commit r27562.
This commit is contained in:
Freagarach 2023-02-24 09:26:56 +00:00
parent 8d4bf38d1d
commit 4bb9d2a997
4 changed files with 50 additions and 79 deletions

View File

@ -109,8 +109,8 @@ function calculateTeamCounterDataHelper()
summaryAddObject(g_TeamHelperData[playerState.team].femaleCitizen, playerState.sequences.unitsTrained.FemaleCitizen);
summaryAddObject(g_TeamHelperData[playerState.team].worker, playerState.sequences.unitsTrained.Worker);
summaryAddObject(g_TeamHelperData[playerState.team].enemyUnitsKilled, playerState.sequences.enemyUnitsKilled.total);
summaryAddObject(g_TeamHelperData[playerState.team].unitsLost, playerState.sequences.unitsLost.total);
summaryAddObject(g_TeamHelperData[playerState.team].enemyUnitsKilled, playerState.sequences.enemyUnitsKilled.Unit);
summaryAddObject(g_TeamHelperData[playerState.team].unitsLost, playerState.sequences.unitsLost.Unit);
g_TeamHelperData[playerState.team].mapControl = playerState.sequences.teamPercentMapControlled;
g_TeamHelperData[playerState.team].mapControlPeak = playerState.sequences.teamPeakPercentMapControlled;
@ -325,8 +325,8 @@ function calculateFeminization(playerState, index)
function calculateKillDeathRatio(playerState, index)
{
return calculateRatio(
playerState.sequences.enemyUnitsKilled.total[index],
playerState.sequences.unitsLost.total[index]);
playerState.sequences.enemyUnitsKilled.Unit[index],
playerState.sequences.unitsLost.Unit[index]);
}
function calculatePopulationCount(playerState, index)

View File

@ -31,7 +31,7 @@ var getScorePanelsData = () => [
"label": translate("Structures"),
"headings": [
{ "identifier": "playername", "caption": translate("Player name"), "yStart": 26, "width": 200 },
{ "identifier": "total", "caption": translate("Total"), "yStart": 34, "width": 105 },
{ "identifier": "Structure", "caption": translate("Total"), "yStart": 34, "width": 105 },
{ "identifier": "House", "caption": translate("Houses"), "yStart": 34, "width": 85 },
{ "identifier": "Economic", "caption": translate("Economic"), "yStart": 34, "width": 85 },
{ "identifier": "Outpost", "caption": translate("Outposts"), "yStart": 34, "width": 85 },
@ -69,7 +69,7 @@ var getScorePanelsData = () => [
"label": translate("Units"),
"headings": [
{ "identifier": "playername", "caption": translate("Player name"), "yStart": 26, "width": 200 },
{ "identifier": "total", "caption": translate("Total"), "yStart": 34, "width": 105 },
{ "identifier": "Unit", "caption": translate("Total"), "yStart": 34, "width": 105 },
{ "identifier": "Infantry", "caption": translate("Infantry"), "yStart": 34, "width": 85 },
{ "identifier": "Worker", "caption": translate("Worker"), "yStart": 34, "width": 85 },
{ "identifier": "Cavalry", "caption": translate("Cavalry"), "yStart": 34, "width": 85 },

View File

@ -182,17 +182,16 @@ StatisticsTracker.prototype.GetStatisticsJSON = function()
/**
* Increments counter associated with certain entity/counter and type of given entity.
* @param cmpIdentity - the entity identity component.
* @param classes - The classes an entity has.
* @param counter - the name of the counter to increment (e.g. "unitsTrained").
* @param type - the type of the counter (e.g. "workers").
*/
StatisticsTracker.prototype.CounterIncrement = function(cmpIdentity, counter, type)
StatisticsTracker.prototype.CounterIncrement = function(classes, counter, type)
{
var classes = cmpIdentity.GetClassesList();
if (!classes)
return;
if (classes.indexOf(type) != -1)
if (classes.includes(type))
++this[counter][type];
};
@ -202,27 +201,15 @@ StatisticsTracker.prototype.CounterIncrement = function(cmpIdentity, counter, ty
*/
StatisticsTracker.prototype.IncreaseTrainedUnitsCounter = function(trainedUnit)
{
let cmpUnitEntityIdentity = Engine.QueryInterface(trainedUnit, IID_Identity);
if (!cmpUnitEntityIdentity)
const classes = Engine.QueryInterface(trainedUnit, IID_Identity)?.GetClassesList();
if (!classes)
return;
let cmpCost = Engine.QueryInterface(trainedUnit, IID_Cost);
let costs = cmpCost && cmpCost.GetResourceCosts();
for (const type of this.unitsClasses)
this.CounterIncrement(classes, "unitsTrained", type);
for (let type of this.unitsClasses)
this.CounterIncrement(cmpUnitEntityIdentity, "unitsTrained", type);
if (!cmpUnitEntityIdentity.HasClass("Domestic"))
if (!classes.includes("Domestic"))
++this.unitsTrained.total;
if (cmpUnitEntityIdentity.HasClass("Domestic") && costs)
{
// Subtract costs for sheep/goats/pigs to get the net food gain/use for corralling
this.resourcesUsed.food -= costs.food;
this.resourcesGathered.food -= costs.food;
}
};
/**
@ -231,118 +218,102 @@ StatisticsTracker.prototype.IncreaseTrainedUnitsCounter = function(trainedUnit)
*/
StatisticsTracker.prototype.IncreaseConstructedBuildingsCounter = function(constructedBuilding)
{
var cmpBuildingEntityIdentity = Engine.QueryInterface(constructedBuilding, IID_Identity);
if (!cmpBuildingEntityIdentity)
const classes = Engine.QueryInterface(constructedBuilding, IID_Identity)?.GetClassesList();
if (!classes)
return;
for (let type of this.buildingsClasses)
this.CounterIncrement(cmpBuildingEntityIdentity, "buildingsConstructed", type);
for (const type of this.buildingsClasses)
this.CounterIncrement(classes, "buildingsConstructed", type);
++this.buildingsConstructed.total;
};
StatisticsTracker.prototype.KilledEntity = function(targetEntity)
{
var cmpTargetEntityIdentity = Engine.QueryInterface(targetEntity, IID_Identity);
const cmpTargetEntityIdentity = Engine.QueryInterface(targetEntity, IID_Identity);
if (!cmpTargetEntityIdentity)
return;
var cmpCost = Engine.QueryInterface(targetEntity, IID_Cost);
var costs = cmpCost && cmpCost.GetResourceCosts();
const classes = cmpTargetEntityIdentity.GetClassesList();
const costs = Engine.QueryInterface(targetEntity, IID_Cost)?.GetResourceCosts();
// Exclude gaia animals but not gaia soldiers.
if (cmpTargetEntityIdentity.HasClass("Unit") && !cmpTargetEntityIdentity.HasClass("Animal"))
{
for (let type of this.unitsClasses)
this.CounterIncrement(cmpTargetEntityIdentity, "enemyUnitsKilled", type);
++this.enemyUnitsKilled.total;
for (const type of this.unitsClasses)
this.CounterIncrement(classes, "enemyUnitsKilled", type);
if (costs)
for (let type in costs)
for (const type in costs)
this.enemyUnitsKilledValue += costs[type];
}
let cmpFoundation = Engine.QueryInterface(targetEntity, IID_Foundation);
if (cmpTargetEntityIdentity.HasClass("Structure") && !cmpFoundation)
if (cmpTargetEntityIdentity.HasClass("Structure") && !Engine.QueryInterface(targetEntity, IID_Foundation))
{
for (let type of this.buildingsClasses)
this.CounterIncrement(cmpTargetEntityIdentity, "enemyBuildingsDestroyed", type);
++this.enemyBuildingsDestroyed.total;
for (const type of this.buildingsClasses)
this.CounterIncrement(classes, "enemyBuildingsDestroyed", type);
if (costs)
for (let type in costs)
for (const type in costs)
this.enemyBuildingsDestroyedValue += costs[type];
}
};
StatisticsTracker.prototype.LostEntity = function(lostEntity)
{
var cmpLostEntityIdentity = Engine.QueryInterface(lostEntity, IID_Identity);
const cmpLostEntityIdentity = Engine.QueryInterface(lostEntity, IID_Identity);
if (!cmpLostEntityIdentity)
return;
var cmpCost = Engine.QueryInterface(lostEntity, IID_Cost);
var costs = cmpCost && cmpCost.GetResourceCosts();
const classes = cmpLostEntityIdentity.GetClassesList();
const costs = Engine.QueryInterface(lostEntity, IID_Cost)?.GetResourceCosts();
if (cmpLostEntityIdentity.HasClass("Unit") && !cmpLostEntityIdentity.HasClass("Domestic"))
{
for (let type of this.unitsClasses)
this.CounterIncrement(cmpLostEntityIdentity, "unitsLost", type);
++this.unitsLost.total;
for (const type of this.unitsClasses)
this.CounterIncrement(classes, "unitsLost", type);
if (costs)
for (let type in costs)
for (const type in costs)
this.unitsLostValue += costs[type];
}
let cmpFoundation = Engine.QueryInterface(lostEntity, IID_Foundation);
if (cmpLostEntityIdentity.HasClass("Structure") && !cmpFoundation)
if (cmpLostEntityIdentity.HasClass("Structure") && !Engine.QueryInterface(lostEntity, IID_Foundation))
{
for (let type of this.buildingsClasses)
this.CounterIncrement(cmpLostEntityIdentity, "buildingsLost", type);
++this.buildingsLost.total;
for (const type of this.buildingsClasses)
this.CounterIncrement(classes, "buildingsLost", type);
if (costs)
for (let type in costs)
for (const type in costs)
this.buildingsLostValue += costs[type];
}
};
StatisticsTracker.prototype.CapturedEntity = function(capturedEntity)
{
let cmpCapturedEntityIdentity = Engine.QueryInterface(capturedEntity, IID_Identity);
const cmpCapturedEntityIdentity = Engine.QueryInterface(capturedEntity, IID_Identity);
if (!cmpCapturedEntityIdentity)
return;
let cmpCost = Engine.QueryInterface(capturedEntity, IID_Cost);
let costs = cmpCost && cmpCost.GetResourceCosts();
const classes = cmpCapturedEntityIdentity.GetClassesList();
const costs = Engine.QueryInterface(capturedEntity, IID_Cost)?.GetResourceCosts();
if (cmpCapturedEntityIdentity.HasClass("Unit"))
{
for (let type of this.unitsClasses)
this.CounterIncrement(cmpCapturedEntityIdentity, "unitsCaptured", type);
++this.unitsCaptured.total;
for (const type of this.unitsClasses)
this.CounterIncrement(classes, "unitsCaptured", type);
if (costs)
for (let type in costs)
for (const type in costs)
this.unitsCapturedValue += costs[type];
}
if (cmpCapturedEntityIdentity.HasClass("Structure"))
{
for (let type of this.buildingsClasses)
this.CounterIncrement(cmpCapturedEntityIdentity, "buildingsCaptured", type);
++this.buildingsCaptured.total;
for (const type of this.buildingsClasses)
this.CounterIncrement(classes, "buildingsCaptured", type);
if (costs)
for (let type in costs)
for (const type in costs)
this.buildingsCapturedValue += costs[type];
}
};
@ -352,9 +323,7 @@ StatisticsTracker.prototype.CapturedEntity = function(capturedEntity)
*/
StatisticsTracker.prototype.GetResourceCounts = function()
{
let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
return cmpPlayer ?
cmpPlayer.GetResourceCounts() :
return Engine.QueryInterface(this.entity, IID_Player)?.GetResourceCounts() ??
Object.fromEntries(Resources.GetCodes().map(res => [res, 0]));
};

View File

@ -115,6 +115,7 @@
Ship
Siege
Trader
Unit
Worker
</UnitClasses>
<StructureClasses datatype="tokens">
@ -124,6 +125,7 @@
House
Military
Outpost
Structure
Wonder
</StructureClasses>
</StatisticsTracker>