Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/ResourceSupply.js
Show All 16 Lines | ResourceSupply.prototype.Schema = | ||||
"</element>" + | "</element>" + | ||||
"<element name='MaxGatherers' a:help='Amount of gatherers who can gather resources from this entity at the same time'>" + | "<element name='MaxGatherers' a:help='Amount of gatherers who can gather resources from this entity at the same time'>" + | ||||
"<data type='nonNegativeInteger'/>" + | "<data type='nonNegativeInteger'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='DiminishingReturns' a:help='The relative rate of any new gatherer compared to the previous one (geometric sequence). Leave the element out for no diminishing returns.'>" + | "<element name='DiminishingReturns' a:help='The relative rate of any new gatherer compared to the previous one (geometric sequence). Leave the element out for no diminishing returns.'>" + | ||||
"<ref name='positiveDecimal'/>" + | "<ref name='positiveDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='MinHealthRate' a:help='When defined, the gather rate will depend on the health, with this value used as the minimum gather rate ratio (ratio = Math.max(MinHealthRate, health/healthMax)).'>" + | |||||
"<ref name='positiveDecimal'/>" + | |||||
"</element>" + | |||||
"</optional>"; | "</optional>"; | ||||
ResourceSupply.prototype.Init = function() | ResourceSupply.prototype.Init = function() | ||||
{ | { | ||||
// Current resource amount (non-negative) | // Current resource amount (non-negative) | ||||
this.amount = this.GetMaxAmount(); | this.amount = this.GetMaxAmount(); | ||||
this.gatherers = []; // list of IDs for each players | this.gatherers = []; // list of IDs for each players | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (diminishingReturns) | ||||
let numGatherers = this.GetNumGatherers(); | let numGatherers = this.GetNumGatherers(); | ||||
if (numGatherers > 1) | if (numGatherers > 1) | ||||
return diminishingReturns == 1 ? 1 : (1. - Math.pow(diminishingReturns, numGatherers)) / (1. - diminishingReturns) / numGatherers; | return diminishingReturns == 1 ? 1 : (1. - Math.pow(diminishingReturns, numGatherers)) / (1. - diminishingReturns) / numGatherers; | ||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
}; | }; | ||||
/* Health dependent factor to be applied on the gatherer rate */ | |||||
ResourceSupply.prototype.GetHealthRate = function() | |||||
{ | |||||
if (!("MinHealthRate" in this.template) || +this.template.MinHealthRate >= 1) | |||||
return 1; | |||||
let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); | |||||
if (!cmpHealth) | |||||
return 1; | |||||
return Math.max(+this.template.MinHealthRate, cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints()); | |||||
}; | |||||
ResourceSupply.prototype.TakeResources = function(rate) | ResourceSupply.prototype.TakeResources = function(rate) | ||||
{ | { | ||||
// Before changing the amount, activate Fogging if necessary to hide changes | // Before changing the amount, activate Fogging if necessary to hide changes | ||||
let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); | let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging); | ||||
if (cmpFogging) | if (cmpFogging) | ||||
cmpFogging.Activate(); | cmpFogging.Activate(); | ||||
if (this.infinite) | if (this.infinite) | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator