1
0
forked from 0ad/0ad
0ad/binaries/data/mods/public/simulation/components/Builder.js
2010-03-12 22:28:51 +00:00

49 lines
1.1 KiB
JavaScript

function Builder() {}
Builder.prototype.Init = function()
{
};
Builder.prototype.GetEntitiesList = function()
{
var string = this.template.Entities._string;
// Replace the "{civ}" codes with this entity's civ ID
var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
if (cmpIdentity)
string = string.replace(/\{civ\}/g, cmpIdentity.GetCiv());
return string.split(/\s+/);
};
Builder.prototype.GetRange = function()
{
return { "max": 16, "min": 0 };
// maybe this should depend on the unit or target or something?
}
/**
* Build/repair the target entity. This should only be called after a successful range check.
* It should be called at a rate of once per second.
*/
Builder.prototype.PerformBuilding = function(target)
{
var rate = +this.template.Rate;
// If it's a foundation, then build it
var cmpFoundation = Engine.QueryInterface(target, IID_Foundation);
if (cmpFoundation)
{
var finished = cmpFoundation.Build(this.entity, rate);
return { "finished": finished };
}
else
{
// TODO: do some kind of repairing
return { "finished": true };
}
};
Engine.RegisterComponentType(IID_Builder, "Builder", Builder);