Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/Cost.js
function Cost() {} | function Cost() {} | ||||
Cost.prototype.Schema = | Cost.prototype.Schema = | ||||
"<a:help>Specifies the construction/training costs of this entity.</a:help>" + | "<a:help>Specifies the construction/training costs of this entity.</a:help>" + | ||||
"<a:example>" + | "<a:example>" + | ||||
"<Population>1</Population>" + | "<Population>1</Population>" + | ||||
"<PopulationBonus>15</PopulationBonus>" + | |||||
"<BuildTime>20.0</BuildTime>" + | "<BuildTime>20.0</BuildTime>" + | ||||
"<Resources>" + | "<Resources>" + | ||||
"<food>50</food>" + | "<food>50</food>" + | ||||
"<wood>0</wood>" + | "<wood>0</wood>" + | ||||
"<stone>0</stone>" + | "<stone>0</stone>" + | ||||
"<metal>25</metal>" + | "<metal>25</metal>" + | ||||
"</Resources>" + | "</Resources>" + | ||||
"</a:example>" + | "</a:example>" + | ||||
"<element name='Population' a:help='Population cost'>" + | "<element name='Population' a:help='Population cost'>" + | ||||
"<data type='nonNegativeInteger'/>" + | "<data type='nonNegativeInteger'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='PopulationBonus' a:help='Population cap increase while this entity exists'>" + | |||||
"<data type='nonNegativeInteger'/>" + | |||||
"</element>" + | |||||
"<element name='BuildTime' a:help='Time taken to construct/train this entity (in seconds)'>" + | "<element name='BuildTime' a:help='Time taken to construct/train this entity (in seconds)'>" + | ||||
"<ref name='nonNegativeDecimal'/>" + | "<ref name='nonNegativeDecimal'/>" + | ||||
"</element>" + | "</element>" + | ||||
"<element name='Resources' a:help='Resource costs to construct/train this entity'>" + | "<element name='Resources' a:help='Resource costs to construct/train this entity'>" + | ||||
Resources.BuildSchema("nonNegativeInteger") + | Resources.BuildSchema("nonNegativeInteger") + | ||||
"</element>"; | "</element>"; | ||||
Cost.prototype.Init = function() | Cost.prototype.Init = function() | ||||
{ | { | ||||
this.populationCost = +this.template.Population; | this.populationCost = +this.template.Population; | ||||
this.populationBonus = +this.template.PopulationBonus; | |||||
}; | }; | ||||
Cost.prototype.GetPopCost = function() | Cost.prototype.GetPopCost = function() | ||||
{ | { | ||||
return this.populationCost; | return this.populationCost; | ||||
}; | }; | ||||
Cost.prototype.GetPopBonus = function() | |||||
{ | |||||
return this.populationBonus; | |||||
}; | |||||
Cost.prototype.GetBuildTime = function() | Cost.prototype.GetBuildTime = function() | ||||
{ | { | ||||
return ApplyValueModificationsToEntity("Cost/BuildTime", +this.template.BuildTime, this.entity); | return ApplyValueModificationsToEntity("Cost/BuildTime", +this.template.BuildTime, this.entity); | ||||
}; | }; | ||||
Cost.prototype.GetResourceCosts = function(owner) | Cost.prototype.GetResourceCosts = function(owner) | ||||
{ | { | ||||
Show All 12 Lines | Cost.prototype.GetResourceCosts = function(owner) | ||||
let costs = {}; | let costs = {}; | ||||
for (let res in this.template.Resources) | for (let res in this.template.Resources) | ||||
costs[res] = ApplyValueModificationsToTemplate("Cost/Resources/"+res, +this.template.Resources[res], owner, entityTemplate); | costs[res] = ApplyValueModificationsToTemplate("Cost/Resources/"+res, +this.template.Resources[res], owner, entityTemplate); | ||||
return costs; | return costs; | ||||
}; | }; | ||||
Cost.prototype.OnOwnershipChanged = function(msg) | |||||
{ | |||||
if (msg.from != INVALID_PLAYER) | |||||
{ | |||||
let cmpPlayer = QueryPlayerIDInterface(msg.from); | |||||
if (cmpPlayer) | |||||
cmpPlayer.AddPopulationBonuses(-this.GetPopBonus()); | |||||
} | |||||
if (msg.to != INVALID_PLAYER) | |||||
{ | |||||
let cmpPlayer = QueryPlayerIDInterface(msg.to); | |||||
if (cmpPlayer) | |||||
cmpPlayer.AddPopulationBonuses(this.GetPopBonus()); | |||||
} | |||||
}; | |||||
Cost.prototype.OnValueModification = function(msg) | Cost.prototype.OnValueModification = function(msg) | ||||
{ | { | ||||
if (msg.component != "Cost") | if (msg.component != "Cost") | ||||
return; | return; | ||||
// foundations shouldn't give a pop bonus and a pop cost | // Foundations shouldn't give a pop bonus and a pop cost | ||||
Freagarach: Sice you touch the string: Captial and `.` please :) | |||||
Not Done Inline ActionsRe-remove the pop bonus :) Freagarach: Re-remove the pop bonus :) | |||||
Not Done Inline ActionsThis is wrong actually and thus should be addressed in a separate diff. Freagarach: This is wrong actually and thus should be addressed in a separate diff. | |||||
var cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); | var cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); | ||||
if (cmpFoundation) | if (cmpFoundation) | ||||
return; | return; | ||||
// update the population costs | // update the population costs | ||||
var newPopCost = Math.round(ApplyValueModificationsToEntity("Cost/Population", +this.template.Population, this.entity)); | var newPopCost = Math.round(ApplyValueModificationsToEntity("Cost/Population", +this.template.Population, this.entity)); | ||||
var popCostDifference = newPopCost - this.populationCost; | var popCostDifference = newPopCost - this.populationCost; | ||||
this.populationCost = newPopCost; | this.populationCost = newPopCost; | ||||
// update the population bonuses | |||||
var newPopBonus = Math.round(ApplyValueModificationsToEntity("Cost/PopulationBonus", +this.template.PopulationBonus, this.entity)); | |||||
var popDifference = newPopBonus - this.populationBonus; | |||||
this.populationBonus = newPopBonus; | |||||
var cmpPlayer = QueryOwnerInterface(this.entity); | var cmpPlayer = QueryOwnerInterface(this.entity); | ||||
if (!cmpPlayer) | if (!cmpPlayer) | ||||
return; | return; | ||||
if (popCostDifference) | if (popCostDifference) | ||||
cmpPlayer.AddPopulation(popCostDifference); | cmpPlayer.AddPopulation(popCostDifference); | ||||
if (popDifference) | |||||
cmpPlayer.AddPopulationBonuses(popDifference); | |||||
}; | }; | ||||
Engine.RegisterComponentType(IID_Cost, "Cost", Cost); | Engine.RegisterComponentType(IID_Cost, "Cost", Cost); |
Wildfire Games · Phabricator
Sice you touch the string: Captial and . please :)