2010-01-22 21:03:14 +01:00
|
|
|
function Cost() {}
|
|
|
|
|
2010-04-09 21:02:39 +02:00
|
|
|
Cost.prototype.Schema =
|
2010-04-23 18:09:03 +02:00
|
|
|
"<a:help>Specifies the construction/training costs of this entity.</a:help>" +
|
|
|
|
"<a:example>" +
|
|
|
|
"<Population>1</Population>" +
|
|
|
|
"<PopulationBonus>15</PopulationBonus>" +
|
|
|
|
"<BuildTime>20.0</BuildTime>" +
|
|
|
|
"<Resources>" +
|
|
|
|
"<food>50</food>" +
|
|
|
|
"<wood>0</wood>" +
|
|
|
|
"<stone>0</stone>" +
|
|
|
|
"<metal>25</metal>" +
|
|
|
|
"</Resources>" +
|
|
|
|
"</a:example>" +
|
2010-08-21 22:43:55 +02:00
|
|
|
"<element name='Population' a:help='Population cost'>" +
|
|
|
|
"<data type='nonNegativeInteger'/>" +
|
|
|
|
"</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 unit (in seconds)'>" +
|
|
|
|
"<ref name='positiveDecimal'/>" +
|
|
|
|
"</element>" +
|
2010-04-23 18:09:03 +02:00
|
|
|
"<element name='Resources' a:help='Resource costs to construct/train this unit'>" +
|
2010-04-09 21:02:39 +02:00
|
|
|
"<interleave>" +
|
|
|
|
"<element name='food'><data type='nonNegativeInteger'/></element>" +
|
|
|
|
"<element name='wood'><data type='nonNegativeInteger'/></element>" +
|
|
|
|
"<element name='stone'><data type='nonNegativeInteger'/></element>" +
|
|
|
|
"<element name='metal'><data type='nonNegativeInteger'/></element>" +
|
|
|
|
"</interleave>" +
|
|
|
|
"</element>";
|
|
|
|
|
2011-03-05 23:30:32 +01:00
|
|
|
Cost.prototype.Init = function()
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
Cost.prototype.Serialize = null; // we have no dynamic state to save
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
Cost.prototype.GetPopCost = function()
|
|
|
|
{
|
2010-08-21 22:43:55 +02:00
|
|
|
return +this.template.Population;
|
2010-01-24 18:24:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Cost.prototype.GetPopBonus = function()
|
|
|
|
{
|
2010-08-21 22:43:55 +02:00
|
|
|
return +this.template.PopulationBonus;
|
2010-01-22 21:03:14 +01:00
|
|
|
};
|
|
|
|
|
2010-03-12 23:28:51 +01:00
|
|
|
Cost.prototype.GetBuildTime = function()
|
|
|
|
{
|
2012-08-05 16:01:05 +02:00
|
|
|
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
|
|
|
|
var buildTime = (+this.template.BuildTime) * cmpPlayer.cheatTimeMultiplier;
|
2012-07-20 03:54:24 +02:00
|
|
|
var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
|
|
|
if (cmpTechnologyManager)
|
|
|
|
buildTime = cmpTechnologyManager.ApplyModifications("Cost/BuildTime", buildTime, this.entity);
|
|
|
|
return buildTime;
|
2010-03-12 23:28:51 +01:00
|
|
|
}
|
|
|
|
|
2010-02-12 23:46:53 +01:00
|
|
|
Cost.prototype.GetResourceCosts = function()
|
|
|
|
{
|
2012-07-20 03:54:24 +02:00
|
|
|
var costs = {};
|
|
|
|
var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager);
|
|
|
|
for (var r in this.template.Resources)
|
|
|
|
{
|
|
|
|
costs[r] = +this.template.Resources[r];
|
|
|
|
if (cmpTechnologyManager)
|
|
|
|
costs[r] = cmpTechnologyManager.ApplyModifications("Cost/Resources/"+r, costs[r], this.entity);
|
|
|
|
}
|
|
|
|
return costs;
|
2010-02-12 23:46:53 +01:00
|
|
|
};
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
Engine.RegisterComponentType(IID_Cost, "Cost", Cost);
|