Implements resource trickle. Allows decimal player resources. Fixes #2413.
This was SVN commit r14710.
This commit is contained in:
parent
0157e640cc
commit
9fe465884d
@ -669,10 +669,10 @@ function updatePlayerDisplay()
|
|||||||
if (!playerState)
|
if (!playerState)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Engine.GetGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food;
|
Engine.GetGUIObjectByName("resourceFood").caption = Math.floor(playerState.resourceCounts.food);
|
||||||
Engine.GetGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood;
|
Engine.GetGUIObjectByName("resourceWood").caption = Math.floor(playerState.resourceCounts.wood);
|
||||||
Engine.GetGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone;
|
Engine.GetGUIObjectByName("resourceStone").caption = Math.floor(playerState.resourceCounts.stone);
|
||||||
Engine.GetGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal;
|
Engine.GetGUIObjectByName("resourceMetal").caption = Math.floor(playerState.resourceCounts.metal);
|
||||||
Engine.GetGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit;
|
Engine.GetGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit;
|
||||||
|
|
||||||
g_IsTrainingBlocked = playerState.trainingBlocked;
|
g_IsTrainingBlocked = playerState.trainingBlocked;
|
||||||
|
@ -199,7 +199,7 @@ Player.prototype.GetNeededResources = function(amounts)
|
|||||||
var amountsNeeded = {};
|
var amountsNeeded = {};
|
||||||
for (var type in amounts)
|
for (var type in amounts)
|
||||||
if (this.resourceCount[type] != undefined && amounts[type] > this.resourceCount[type])
|
if (this.resourceCount[type] != undefined && amounts[type] > this.resourceCount[type])
|
||||||
amountsNeeded[type] = amounts[type] - this.resourceCount[type];
|
amountsNeeded[type] = amounts[type] - Math.floor(this.resourceCount[type]);
|
||||||
|
|
||||||
if (Object.keys(amountsNeeded).length == 0)
|
if (Object.keys(amountsNeeded).length == 0)
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
function ResourceTrickle() {}
|
||||||
|
|
||||||
|
ResourceTrickle.prototype.Schema =
|
||||||
|
"<a:help>Controls the resource trickle ability of the unit.</a:help>" +
|
||||||
|
"<element name='FoodRate' a:help='Food given to the player every interval'>" +
|
||||||
|
"<ref name='nonNegativeDecimal'/>" +
|
||||||
|
"</element>" +
|
||||||
|
"<element name='WoodRate' a:help='Wood given to the player every interval'>" +
|
||||||
|
"<ref name='nonNegativeDecimal'/>" +
|
||||||
|
"</element>" +
|
||||||
|
"<element name='StoneRate' a:help='Stone given to the player every interval'>" +
|
||||||
|
"<ref name='nonNegativeDecimal'/>" +
|
||||||
|
"</element>" +
|
||||||
|
"<element name='MetalRate' a:help='Metal given to the player every interval'>" +
|
||||||
|
"<ref name='nonNegativeDecimal'/>" +
|
||||||
|
"</element>" +
|
||||||
|
"<element name='Interval' a:help='Number of miliseconds must pass for the player to gain the next trickle.'>" +
|
||||||
|
"<ref name='nonNegativeDecimal'/>" +
|
||||||
|
"</element>";
|
||||||
|
|
||||||
|
ResourceTrickle.prototype.Init = function()
|
||||||
|
{
|
||||||
|
// Call the timer
|
||||||
|
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||||
|
cmpTimer.SetInterval(this.entity, IID_ResourceTrickle, "Trickle", this.GetTimer(), this.GetTimer(), undefined)
|
||||||
|
};
|
||||||
|
|
||||||
|
ResourceTrickle.prototype.GetTimer = function()
|
||||||
|
{
|
||||||
|
var interval = +this.template.Interval;
|
||||||
|
return interval;
|
||||||
|
};
|
||||||
|
|
||||||
|
ResourceTrickle.prototype.GetRates = function()
|
||||||
|
{
|
||||||
|
var foodrate = +this.template.FoodRate;
|
||||||
|
var woodrate = +this.template.WoodRate;
|
||||||
|
var stonerate = +this.template.StoneRate;
|
||||||
|
var metalrate = +this.template.MetalRate;
|
||||||
|
|
||||||
|
foodrate = ApplyValueModificationsToEntity("ResourceTrickle/FoodRate", foodrate, this.entity);
|
||||||
|
woodrate = ApplyValueModificationsToEntity("ResourceTrickle/WoodRate", woodrate, this.entity);
|
||||||
|
stonerate = ApplyValueModificationsToEntity("ResourceTrickle/StoneRate", stonerate, this.entity);
|
||||||
|
metalrate = ApplyValueModificationsToEntity("ResourceTrickle/MetalRate", metalrate, this.entity);
|
||||||
|
|
||||||
|
return {"food": foodrate, "wood": woodrate, "stone": stonerate, "metal": metalrate };
|
||||||
|
};
|
||||||
|
|
||||||
|
// Do the actual work here
|
||||||
|
ResourceTrickle.prototype.Trickle = function(data, lateness)
|
||||||
|
{
|
||||||
|
// Get the rates
|
||||||
|
var rates = this.GetRates();
|
||||||
|
|
||||||
|
// Get the player
|
||||||
|
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
|
||||||
|
|
||||||
|
for (var resource in rates)
|
||||||
|
cmpPlayer.AddResource(resource, rates[resource]);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Engine.RegisterComponentType(IID_ResourceTrickle, "ResourceTrickle", ResourceTrickle);
|
@ -0,0 +1 @@
|
|||||||
|
Engine.RegisterInterface("ResourceTrickle");
|
@ -31,7 +31,7 @@
|
|||||||
</Classes>
|
</Classes>
|
||||||
<History>The term Apadana designates a large hypostyle palace found in Persia. The best known example, and by far the largest, was the great Apadana at Persepolis. Functioning as the empire's central audience hall, the palace is famous for the reliefs of the tribute-bearers and of the army, including the Immortals. The annual tribute that the Persians received from their satrapies and vassal states, as regularised by Darius the Great, accounted for incredible annual revenue.</History>
|
<History>The term Apadana designates a large hypostyle palace found in Persia. The best known example, and by far the largest, was the great Apadana at Persepolis. Functioning as the empire's central audience hall, the palace is famous for the reliefs of the tribute-bearers and of the army, including the Immortals. The annual tribute that the Persians received from their satrapies and vassal states, as regularised by Darius the Great, accounted for incredible annual revenue.</History>
|
||||||
<Icon>structures/palace.png</Icon>
|
<Icon>structures/palace.png</Icon>
|
||||||
<Tooltip>"Satrapy Tribute": Gain a trickle of food, wood, stone, and metal resources (not implemented yet). Train Persian heroes and their "Immortals" bodyguards. Build Limit: 1.</Tooltip>
|
<Tooltip>"Satrapy Tribute": Gain a trickle of food, wood, stone, and metal resources. Train Persian heroes and their "Immortals" bodyguards. Build Limit: 1.</Tooltip>
|
||||||
</Identity>
|
</Identity>
|
||||||
<Obstruction>
|
<Obstruction>
|
||||||
<Static width="30.0" depth="30.0"/>
|
<Static width="30.0" depth="30.0"/>
|
||||||
@ -52,6 +52,13 @@
|
|||||||
persians/immortals
|
persians/immortals
|
||||||
</Technologies>
|
</Technologies>
|
||||||
</ProductionQueue>
|
</ProductionQueue>
|
||||||
|
<ResourceTrickle>
|
||||||
|
<FoodRate>1.0</FoodRate>
|
||||||
|
<WoodRate>1.0</WoodRate>
|
||||||
|
<StoneRate>0.75</StoneRate>
|
||||||
|
<MetalRate>0.75</MetalRate>
|
||||||
|
<Interval>1000</Interval>
|
||||||
|
</ResourceTrickle>
|
||||||
<VisualActor>
|
<VisualActor>
|
||||||
<Actor>structures/persians/sb1_new.xml</Actor>
|
<Actor>structures/persians/sb1_new.xml</Actor>
|
||||||
<FoundationActor>structures/fndn_6x6.xml</FoundationActor>
|
<FoundationActor>structures/fndn_6x6.xml</FoundationActor>
|
||||||
|
Loading…
Reference in New Issue
Block a user