Index: binaries/data/mods/public/simulation/components/Foundation.js =================================================================== --- binaries/data/mods/public/simulation/components/Foundation.js +++ binaries/data/mods/public/simulation/components/Foundation.js @@ -1,7 +1,11 @@ function Foundation() {} Foundation.prototype.Schema = - ""; + "" + + "" + + "" + + "" + + ""; Foundation.prototype.Init = function() { @@ -18,6 +22,9 @@ this.buildTimePenalty = 0.7; // Penalty for having multiple builders this.previewEntity = INVALID_ENTITY; + + if ("AutoBuild" in this.template) + this.StartTimer(); }; Foundation.prototype.InitialiseConstruction = function(owner, template) @@ -421,5 +428,41 @@ return cmpHealth.GetMaxHitpoints() / cmpCost.GetBuildTime(); }; +Foundation.prototype.StartTimer = function() +{ + if (this.timer) + return; + + if (this.IsFinished()) + { + this.CancelTimer(); + return; + } + + this.AddBuilder(this.entity); + var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + this.timer = cmpTimer.SetInterval(this.entity, IID_Foundation, "AutoBuild", 0, 1000, undefined); +}; + +Foundation.prototype.StopTimer = function() +{ + if (!this.timer) + return; + + var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); + cmpTimer.CancelTimer(this.timer); + delete this.timer; +}; + + +Foundation.prototype.AutoBuild = function() +{ + var cmpBuilder = Engine.QueryInterface(this.entity, IID_Builder); + if (!cmpBuilder) + cmpTimer.CancelTimer(this.timer); + + this.Build(this.entity, this.GetAutoBuildRate()); +}; + Engine.RegisterComponentType(IID_Foundation, "Foundation", Foundation);