Added resource used counters that track all non-barter spending. Fixes #1605.
This was SVN commit r12543.
This commit is contained in:
parent
96ee70b75b
commit
08a4b12f01
@ -101,11 +101,12 @@ function init(data)
|
||||
|
||||
left = 50;
|
||||
getGUIObjectByName("playerName2Heading").size = left + " 26 " + (left + playerNameHeadingWidth) + " 100%"; left += playerNameHeadingWidth;
|
||||
getGUIObjectByName("foodGatheredHeading").size = left + " 16 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("resourceHeading").size = left + " 16 " + (left + width * 4) + " 100%";
|
||||
getGUIObjectByName("foodGatheredHeading").size = left + " 34 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("woodGatheredHeading").size = left + " 34 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("stoneGatheredHeading").size = left + " 34 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("metalGatheredHeading").size = left + " 34 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("vegetarianRatioHeading").size = left + " 16 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("woodGatheredHeading").size = left + " 16 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("stoneGatheredHeading").size = left + " 16 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("metalGatheredHeading").size = left + " 16 " + (left + width) + " 100%"; left += width;
|
||||
getGUIObjectByName("treasuresCollectedHeading").size = left + " 16 " + (left + width) + " 100%"; left += width;
|
||||
|
||||
left = 50;
|
||||
@ -158,10 +159,10 @@ function init(data)
|
||||
var mapExploration = getGUIObjectByName("mapExploration["+i+"]");
|
||||
|
||||
var foodGathered = getGUIObjectByName("foodGathered["+i+"]");
|
||||
var vegetarianRatio = getGUIObjectByName("vegetarianRatio["+i+"]");
|
||||
var woodGathered = getGUIObjectByName("woodGathered["+i+"]");
|
||||
var stoneGathered = getGUIObjectByName("stoneGathered["+i+"]");
|
||||
var metalGathered = getGUIObjectByName("metalGathered["+i+"]");
|
||||
var vegetarianRatio = getGUIObjectByName("vegetarianRatio["+i+"]");
|
||||
var treasuresCollected = getGUIObjectByName("treasuresCollected["+i+"]");
|
||||
|
||||
var exchangedFood = getGUIObjectByName("exchangedFood["+i+"]");
|
||||
@ -195,10 +196,10 @@ function init(data)
|
||||
|
||||
left = 240;
|
||||
foodGathered.size = left + " 2 " + (left + width) + " 100%"; left += width;
|
||||
vegetarianRatio.size = left + " 2 " + (left + width) + " 100%"; left += width;
|
||||
woodGathered.size = left + " 2 " + (left + width) + " 100%"; left += width;
|
||||
stoneGathered.size = left + " 2 " + (left + width) + " 100%"; left += width;
|
||||
metalGathered.size = left + " 2 " + (left + width) + " 100%"; left += width;
|
||||
vegetarianRatio.size = left + " 2 " + (left + width) + " 100%"; left += width;
|
||||
treasuresCollected.size = left + " 2 " + (left + width) + " 100%"; left += width;
|
||||
size = getGUIObjectByName("playerBox2["+i+"]").size;
|
||||
size.right = left + 10;
|
||||
@ -227,24 +228,28 @@ function init(data)
|
||||
enemyCivCentresDestroyed.caption = playerState.statistics.enemyCivCentresDestroyed;
|
||||
mapExploration.caption = playerState.statistics.percentMapExplored + "%";
|
||||
|
||||
foodGathered.caption = playerState.statistics.resourcesGathered.food;
|
||||
const SOLD_COLOR = '[color="201 255 200"]';
|
||||
const BOUGHT_COLOR = '[color="255 213 213"]';
|
||||
foodGathered.caption = SOLD_COLOR + playerState.statistics.resourcesGathered.food + "[/color] / " +
|
||||
BOUGHT_COLOR + (playerState.statistics.resourcesUsed.food - playerState.statistics.resourcesSold.food) + "[/color]";
|
||||
woodGathered.caption = SOLD_COLOR + playerState.statistics.resourcesGathered.wood + "[/color] / " +
|
||||
BOUGHT_COLOR + (playerState.statistics.resourcesUsed.wood - playerState.statistics.resourcesSold.wood) + "[/color]";
|
||||
stoneGathered.caption = SOLD_COLOR + playerState.statistics.resourcesGathered.stone + "[/color] / " +
|
||||
BOUGHT_COLOR + (playerState.statistics.resourcesUsed.stone - playerState.statistics.resourcesSold.stone) + "[/color]";
|
||||
metalGathered.caption = SOLD_COLOR + playerState.statistics.resourcesGathered.metal + "[/color] / " +
|
||||
BOUGHT_COLOR + (playerState.statistics.resourcesUsed.metal - playerState.statistics.resourcesSold.metal) + "[/color]";
|
||||
vegetarianRatio.caption = Math.floor(playerState.statistics.resourcesGathered.food > 0 ?
|
||||
(playerState.statistics.resourcesGathered.vegetarianFood / playerState.statistics.resourcesGathered.food) * 100 : 0) + "%";
|
||||
woodGathered.caption = playerState.statistics.resourcesGathered.wood;
|
||||
stoneGathered.caption = playerState.statistics.resourcesGathered.stone;
|
||||
metalGathered.caption = playerState.statistics.resourcesGathered.metal;
|
||||
treasuresCollected.caption = playerState.statistics.treasuresCollected;
|
||||
|
||||
const SOLD_COLOR = "201 255 200";
|
||||
const BOUGHT_COLOR = "255 213 213"
|
||||
exchangedFood.caption = '[color="' + SOLD_COLOR + '"]+' + playerState.statistics.resourcesBought.food
|
||||
+ '[/color] [color="' + BOUGHT_COLOR + '"]-' + playerState.statistics.resourcesSold.food + '[/color]';
|
||||
exchangedWood.caption = '[color="' + SOLD_COLOR + '"]+' + playerState.statistics.resourcesBought.wood
|
||||
+ '[/color] [color="' + BOUGHT_COLOR + '"]-' + playerState.statistics.resourcesSold.wood + '[/color]';
|
||||
exchangedStone.caption = '[color="' + SOLD_COLOR + '"]+' + playerState.statistics.resourcesBought.stone
|
||||
+ '[/color] [color="' + BOUGHT_COLOR + '"]-' + playerState.statistics.resourcesSold.stone + '[/color]';
|
||||
exchangedMetal.caption = '[color="' + SOLD_COLOR + '"]+' + playerState.statistics.resourcesBought.metal
|
||||
+ '[/color] [color="' + BOUGHT_COLOR + '"]-' + playerState.statistics.resourcesSold.metal + '[/color]';
|
||||
exchangedFood.caption = SOLD_COLOR + '+' + playerState.statistics.resourcesBought.food
|
||||
+ '[/color] ' + BOUGHT_COLOR + '-' + playerState.statistics.resourcesSold.food + '[/color]';
|
||||
exchangedWood.caption = SOLD_COLOR + '+' + playerState.statistics.resourcesBought.wood
|
||||
+ '[/color] ' + BOUGHT_COLOR + '-' + playerState.statistics.resourcesSold.wood + '[/color]';
|
||||
exchangedStone.caption = SOLD_COLOR + '+' + playerState.statistics.resourcesBought.stone
|
||||
+ '[/color] ' + BOUGHT_COLOR + '-' + playerState.statistics.resourcesSold.stone + '[/color]';
|
||||
exchangedMetal.caption = SOLD_COLOR + '+' + playerState.statistics.resourcesBought.metal
|
||||
+ '[/color] ' + BOUGHT_COLOR + '-' + playerState.statistics.resourcesSold.metal + '[/color]';
|
||||
var totalBought = 0;
|
||||
for each (var boughtAmount in playerState.statistics.resourcesBought)
|
||||
totalBought += boughtAmount;
|
||||
|
@ -158,21 +158,24 @@
|
||||
<object name="playerName2Heading" type="text" style="LeftTabLabelText">
|
||||
Player name
|
||||
</object>
|
||||
<object name="resourceHeading" type="text" style="CenteredTabLabelText">
|
||||
Resource Statistics (Gathered / Used)
|
||||
</object>
|
||||
<object name="foodGatheredHeading" type="text" style="CenteredTabLabelText">
|
||||
Food gathered
|
||||
Food
|
||||
</object>
|
||||
<object name="woodGatheredHeading" type="text" style="CenteredTabLabelText">
|
||||
Wood
|
||||
</object>
|
||||
<object name="stoneGatheredHeading" type="text" style="CenteredTabLabelText">
|
||||
Stone
|
||||
</object>
|
||||
<object name="metalGatheredHeading" type="text" style="CenteredTabLabelText">
|
||||
Metal
|
||||
</object>
|
||||
<object name="vegetarianRatioHeading" type="text" style="CenteredTabLabelText">
|
||||
Vegetarian ratio
|
||||
</object>
|
||||
<object name="woodGatheredHeading" type="text" style="CenteredTabLabelText">
|
||||
Wood gathered
|
||||
</object>
|
||||
<object name="stoneGatheredHeading" type="text" style="CenteredTabLabelText">
|
||||
Stone gathered
|
||||
</object>
|
||||
<object name="metalGatheredHeading" type="text" style="CenteredTabLabelText">
|
||||
Metal gathered
|
||||
</object>
|
||||
<object name="treasuresCollectedHeading" type="text" style="CenteredTabLabelText">
|
||||
Treasures collected
|
||||
</object>
|
||||
@ -185,10 +188,10 @@
|
||||
<object name="playerName2[n]" type="text" style="LeftLabelText" size="40 2 208 100%" />
|
||||
<object name="civIcon2[n]" type="image" size="208 0 240 32" tooltip_style="sessionToolTip"/>
|
||||
<object name="foodGathered[n]" type="text" style="CenteredLabelText"/>
|
||||
<object name="vegetarianRatio[n]" type="text" style="CenteredLabelText"/>
|
||||
<object name="woodGathered[n]" type="text" style="CenteredLabelText"/>
|
||||
<object name="stoneGathered[n]" type="text" style="CenteredLabelText" />
|
||||
<object name="metalGathered[n]" type="text" style="CenteredLabelText"/>
|
||||
<object name="vegetarianRatio[n]" type="text" style="CenteredLabelText"/>
|
||||
<object name="treasuresCollected[n]" type="text" style="CenteredLabelText"/>
|
||||
</object>
|
||||
</repeat>
|
||||
|
@ -80,7 +80,12 @@ Foundation.prototype.OnDestroy = function()
|
||||
{
|
||||
var scaled = Math.floor(this.costs[r] * (1.0 - this.buildProgress));
|
||||
if (scaled)
|
||||
{
|
||||
cmpPlayer.AddResource(r, scaled);
|
||||
var cmpStatisticsTracker = QueryPlayerIDInterface(this.owner, IID_StatisticsTracker);
|
||||
if (cmpStatisticsTracker)
|
||||
cmpStatisticsTracker.IncreaseResourceUsedCounter(r, -scaled);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the timer
|
||||
|
@ -191,8 +191,13 @@ Player.prototype.TrySubtractResources = function(amounts)
|
||||
else
|
||||
{
|
||||
// Subtract the resources
|
||||
var cmpStatisticsTracker = QueryPlayerIDInterface(this.playerID, IID_StatisticsTracker);
|
||||
for (var type in amounts)
|
||||
{
|
||||
this.resourceCount[type] -= amounts[type];
|
||||
if (cmpStatisticsTracker)
|
||||
cmpStatisticsTracker.IncreaseResourceUsedCounter(type, amounts[type]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -309,8 +309,13 @@ ProductionQueue.prototype.RemoveBatch = function(id)
|
||||
|
||||
// Refund the resource cost for this batch
|
||||
var totalCosts = {};
|
||||
var cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
|
||||
for each (var r in ["food", "wood", "stone", "metal"])
|
||||
{
|
||||
totalCosts[r] = Math.floor(item.count * item.resources[r]);
|
||||
if (cmpStatisticsTracker)
|
||||
cmpStatisticsTracker.IncreaseResourceUsedCounter(r, -totalCosts[r]);
|
||||
}
|
||||
|
||||
cmpPlayer.AddResources(totalCosts);
|
||||
|
||||
|
@ -24,6 +24,12 @@ StatisticsTracker.prototype.Init = function()
|
||||
"stone": 0,
|
||||
"vegetarianFood": 0
|
||||
};
|
||||
this.resourcesUsed = {
|
||||
"food": 0,
|
||||
"wood": 0,
|
||||
"metal": 0,
|
||||
"stone": 0,
|
||||
};
|
||||
this.resourcesSold = {
|
||||
"food": 0,
|
||||
"wood": 0,
|
||||
@ -52,6 +58,7 @@ StatisticsTracker.prototype.GetStatistics = function()
|
||||
"civCentresBuilt": this.civCentresBuilt,
|
||||
"enemyCivCentresDestroyed": this.enemyCivCentresDestroyed,
|
||||
"resourcesGathered": this.resourcesGathered,
|
||||
"resourcesUsed": this.resourcesUsed,
|
||||
"resourcesSold": this.resourcesSold,
|
||||
"resourcesBought": this.resourcesBought,
|
||||
"tradeIncome": this.tradeIncome,
|
||||
@ -135,6 +142,15 @@ StatisticsTracker.prototype.IncreaseResourceGatheredCounter = function(type, amo
|
||||
this.resourcesGathered["vegetarianFood"] += amount;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param type Generic type of resource (string)
|
||||
* @param amount Amount of resource, whick should be added (integer)
|
||||
*/
|
||||
StatisticsTracker.prototype.IncreaseResourceUsedCounter = function(type, amount)
|
||||
{
|
||||
this.resourcesUsed[type] += amount;
|
||||
};
|
||||
|
||||
StatisticsTracker.prototype.IncreaseTreasuresCollectedCounter = function()
|
||||
{
|
||||
return this.treasuresCollected++;
|
||||
|
Loading…
Reference in New Issue
Block a user