forked from mirrors/0ad
Add resource and population counts to the summary screen.
Patch by: @toonijn Differential revision: D3395 Fixes: #4554 Reviewed by: @Freagarach, @wraitii Comments by: @Angen, @Imarok, @Stan This was SVN commit r24721.
This commit is contained in:
@@ -251,6 +251,7 @@
|
||||
{ "nick": "thamlett", "name": "Timothy Hamlett" },
|
||||
{ "nick": "thedrunkyak", "name": "Dan Fuhr" },
|
||||
{ "nick": "Tobbi" },
|
||||
{ "nick": "Toonijn", "name": "Toon Baeyens" },
|
||||
{ "nick": "TrinityDeath", "name": "Jethro Lu" },
|
||||
{ "nick": "triumvir", "name": "Corin Schedler" },
|
||||
{ "nick": "trompetin17", "name": "Juan Guillermo" },
|
||||
|
||||
@@ -17,9 +17,10 @@ function formatSummaryValue(values)
|
||||
|
||||
let ret = "";
|
||||
for (let type in values)
|
||||
ret += (g_SummaryTypes[type].color ?
|
||||
coloredText(values[type], g_SummaryTypes[type].color) :
|
||||
values[type]) + g_SummaryTypes[type].postfix;
|
||||
if (!g_SummaryTypes[type].hideInSummary)
|
||||
ret += (g_SummaryTypes[type].color ?
|
||||
coloredText(values[type], g_SummaryTypes[type].color) :
|
||||
values[type]) + g_SummaryTypes[type].postfix;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -157,7 +158,7 @@ function calculateExplorationScore(playerState, index)
|
||||
/**
|
||||
* Keep this in sync with the score computation in session/ for the lobby rating reports!
|
||||
*/
|
||||
function calculateScoreTotal(playerState, index)
|
||||
function calculateScoreTotal(playerState, index)
|
||||
{
|
||||
return calculateEconomyScore(playerState, index) +
|
||||
calculateMilitaryScore(playerState, index) +
|
||||
@@ -218,6 +219,7 @@ function calculateUnits(playerState, index, type)
|
||||
function calculateResources(playerState, index, type)
|
||||
{
|
||||
return {
|
||||
"count": playerState.sequences.resourcesCount[type][index],
|
||||
"gathered": playerState.sequences.resourcesGathered[type][index],
|
||||
"used": playerState.sequences.resourcesUsed[type][index] - playerState.sequences.resourcesSold[type][index]
|
||||
};
|
||||
@@ -227,14 +229,16 @@ function calculateTotalResources(playerState, index)
|
||||
{
|
||||
let totalGathered = 0;
|
||||
let totalUsed = 0;
|
||||
let totalCount = 0;
|
||||
|
||||
for (let type of g_ResourceData.GetCodes())
|
||||
{
|
||||
totalCount += playerState.sequences.resourcesCount[type][index];
|
||||
totalGathered += playerState.sequences.resourcesGathered[type][index];
|
||||
totalUsed += playerState.sequences.resourcesUsed[type][index] - playerState.sequences.resourcesSold[type][index];
|
||||
}
|
||||
|
||||
return { "gathered": totalGathered, "used": totalUsed };
|
||||
return { "count": totalCount, "gathered": totalGathered, "used": totalUsed };
|
||||
}
|
||||
|
||||
function calculateTreasureCollected(playerState, index)
|
||||
@@ -321,6 +325,11 @@ function calculateKillDeathRatio(playerState, index)
|
||||
playerState.sequences.unitsLost.total[index]);
|
||||
}
|
||||
|
||||
function calculatePopulationCount(playerState, index)
|
||||
{
|
||||
return { "population": playerState.sequences.populationCount[index] };
|
||||
}
|
||||
|
||||
function calculateMapExploration(playerState, index)
|
||||
{
|
||||
return { "percent": playerState.sequences.percentMapExplored[index] };
|
||||
|
||||
@@ -193,6 +193,7 @@ var getScorePanelsData = () => [
|
||||
"headings": [
|
||||
{ "identifier": "playername", "caption": translate("Player name"), "yStart": 26, "width": 200 },
|
||||
{ "identifier": "killDeath", "caption": translate("Kill / Death ratio"), "yStart": 16, "width": 100, "format": "DECIMAL2" },
|
||||
{ "identifier": "population", "caption": translate("Population"), "yStart": 16, "width": 100, "hideInSummary": true },
|
||||
{ "identifier": "mapControlPeak", "caption": translate("Map control (peak)"), "yStart": 16, "width": 100, "format": "PERCENTAGE" },
|
||||
{ "identifier": "mapControl", "caption": translate("Map control (finish)"), "yStart": 16, "width": 100, "format": "PERCENTAGE" },
|
||||
{ "identifier": "mapExploration", "caption": translate("Map exploration"), "yStart": 16, "width": 100, "format": "PERCENTAGE" },
|
||||
@@ -213,6 +214,7 @@ var getScorePanelsData = () => [
|
||||
"titleHeadings": [],
|
||||
"counters": [
|
||||
{ "width": 100, "fn": calculateKillDeathRatio, "verticalOffset": 12 },
|
||||
{ "width": 100, "fn": calculatePopulationCount, "verticalOffset": 12, "hideInSummary": true },
|
||||
{ "width": 100, "fn": calculateMapPeakControl, "verticalOffset": 12 },
|
||||
{ "width": 100, "fn": calculateMapFinalControl, "verticalOffset": 12 },
|
||||
{ "width": 100, "fn": calculateMapExploration, "verticalOffset": 12 },
|
||||
@@ -255,8 +257,10 @@ function resetGeneralPanel()
|
||||
}
|
||||
}
|
||||
|
||||
function updateGeneralPanelHeadings(headings)
|
||||
function updateGeneralPanelHeadings(allHeadings)
|
||||
{
|
||||
let headings = allHeadings.filter(heading => !heading.hideInSummary);
|
||||
|
||||
let left = 50;
|
||||
for (let h in headings)
|
||||
{
|
||||
@@ -295,8 +299,9 @@ function updateGeneralPanelTitles(titleHeadings)
|
||||
}
|
||||
}
|
||||
|
||||
function updateGeneralPanelCounter(counters)
|
||||
function updateGeneralPanelCounter(allCounters)
|
||||
{
|
||||
let counters = allCounters.filter(counter => !counter.hideInSummary);
|
||||
let rowPlayerObjectWidth = 0;
|
||||
let left = 0;
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ var g_SummaryTypes = {
|
||||
"caption": translate("Gathered"),
|
||||
"postfix": " / "
|
||||
},
|
||||
"count": {
|
||||
"caption": translate("Count"),
|
||||
"hideInSummary": true
|
||||
},
|
||||
"sent": {
|
||||
"color": g_TypeColors.green,
|
||||
"caption": translate("Sent"),
|
||||
@@ -90,6 +94,11 @@ var g_SummaryTypes = {
|
||||
"caption": translate("Received"),
|
||||
"postfix": ""
|
||||
},
|
||||
"population": {
|
||||
"color": g_TypeColors.red,
|
||||
"caption": translate("Population"),
|
||||
"postfix": ""
|
||||
},
|
||||
"sold": {
|
||||
"color": g_TypeColors.red,
|
||||
"caption": translate("Sold"),
|
||||
|
||||
@@ -131,6 +131,7 @@ StatisticsTracker.prototype.GetStatistics = function()
|
||||
"enemyBuildingsDestroyedValue": this.enemyBuildingsDestroyedValue,
|
||||
"buildingsCaptured": this.buildingsCaptured,
|
||||
"buildingsCapturedValue": this.buildingsCapturedValue,
|
||||
"resourcesCount": this.GetResourceCounts(),
|
||||
"resourcesGathered": this.resourcesGathered,
|
||||
"resourcesUsed": this.resourcesUsed,
|
||||
"resourcesSold": this.resourcesSold,
|
||||
@@ -140,6 +141,7 @@ StatisticsTracker.prototype.GetStatistics = function()
|
||||
"tradeIncome": this.tradeIncome,
|
||||
"treasuresCollected": this.treasuresCollected,
|
||||
"lootCollected": this.lootCollected,
|
||||
"populationCount": this.GetPopulationCount(),
|
||||
"percentMapExplored": this.GetPercentMapExplored(),
|
||||
"teamPercentMapExplored": this.GetTeamPercentMapExplored(),
|
||||
"percentMapControlled": this.GetPercentMapControlled(),
|
||||
@@ -345,6 +347,17 @@ StatisticsTracker.prototype.CapturedEntity = function(capturedEntity)
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Object} - The amount of available resources.
|
||||
*/
|
||||
StatisticsTracker.prototype.GetResourceCounts = function()
|
||||
{
|
||||
let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
|
||||
return cmpPlayer ?
|
||||
cmpPlayer.GetResourceCounts() :
|
||||
Object.fromEntries(Resources.GetCodes().map(res => [res, 0]));
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} type - generic type of resource.
|
||||
* @param {number} amount - amount of resource, whick should be added.
|
||||
@@ -403,6 +416,12 @@ StatisticsTracker.prototype.IncreaseTradeIncomeCounter = function(amount)
|
||||
this.tradeIncome += amount;
|
||||
};
|
||||
|
||||
StatisticsTracker.prototype.GetPopulationCount = function()
|
||||
{
|
||||
let cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
|
||||
return cmpPlayer ? cmpPlayer.GetPopulationCount() : 0;
|
||||
};
|
||||
|
||||
StatisticsTracker.prototype.IncreaseSuccessfulBribesCounter = function()
|
||||
{
|
||||
++this.successfulBribes;
|
||||
|
||||
Reference in New Issue
Block a user