function Cost() {} Cost.prototype.Schema = "Specifies the construction/training costs of this entity." + "" + "1" + "15" + "20.0" + "" + "50" + "0" + "0" + "25" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; Cost.prototype.Init = function() { this.populationBonus = +this.template.PopulationBonus; }; Cost.prototype.GetPopCost = function() { return +this.template.Population; }; Cost.prototype.GetPopBonus = function() { return this.populationBonus; }; Cost.prototype.GetBuildTime = function() { var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); var buildTime = (+this.template.BuildTime) * cmpPlayer.cheatTimeMultiplier; return ApplyValueModificationsToEntity("Cost/BuildTime", buildTime, this.entity); } Cost.prototype.GetResourceCosts = function() { var costs = {}; for (var r in this.template.Resources) { costs[r] = +this.template.Resources[r]; costs[r] = ApplyValueModificationsToEntity("Cost/Resources/"+r, costs[r], this.entity); } return costs; }; Cost.prototype.OnOwnershipChanged = function(msg) { if (msg.from != -1) { var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(msg.from), IID_Player); if (cmpPlayer) cmpPlayer.AddPopulationBonuses(-this.GetPopBonus()); } if (msg.to != -1) { var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(msg.to), IID_Player); if (cmpPlayer) cmpPlayer.AddPopulationBonuses(this.GetPopBonus()); } }; Cost.prototype.OnValueModification = function(msg) { if (msg.component != "Cost") return; // update the population bonuses var newPopBonus = ApplyValueModificationsToEntity("Cost/PopulationBonus", +this.template.PopulationBonus, this.entity); var popDifference = newPopBonus - this.populationBonus; if (!popDifference) return; var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); if (cmpPlayer) cmpPlayer.AddPopulationBonuses(popDifference); }; Engine.RegisterComponentType(IID_Cost, "Cost", Cost);