Ticket #1357: farm_supply_tech.patch

File farm_supply_tech.patch, 1.8 KB (added by Kieran P, 12 years ago)

Initial go at farm supply upgrade - not working

  • binaries/data/mods/public/simulation/components/ResourceSupply.js

     
    3333
    3434ResourceSupply.prototype.Init = function()
    3535{
    36     // Current resource amount (non-negative; can be a fractional amount)
    37     this.amount = this.GetMaxAmount();
     36    this.maxAmount = this.GetMaxAmount();
     37    this.amount = this.maxAmount;
    3838};
    3939
    4040ResourceSupply.prototype.GetKillBeforeGather = function()
     
    4242    return (this.template.KillBeforeGather == "true");
    4343};
    4444
     45ResourceSupply.prototype.GetDefaultAmount = function()
     46{
     47    return +this.template.Amount;
     48}
     49
     50ResourceSupply.prototype.GetUpgradedAmount = function()
     51{
     52    var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     53    if (!cmpOwnership || cmpOwnership.GetOwner() === -1)
     54        warn('No ownership or player is -1');
     55        return this.GetDefaultAmount();
     56
     57    var cmpTechMan = QueryOwnerInterface(this.entity, IID_TechnologyManager);
     58    return cmpTechMan.ApplyModifications("ResourceSupply/Amount", this.GetDefaultAmount(), this.entity);
     59}
     60
    4561ResourceSupply.prototype.GetMaxAmount = function()
    4662{
    47     return +this.template.Amount;
     63    return this.GetUpgradedAmount() || this.GetDefaultAmount();
    4864};
    4965
    5066ResourceSupply.prototype.GetCurrentAmount = function()
     
    8298    return { "generic": type, "specific": subtype };
    8399};
    84100
     101ResourceSupply.prototype.OnTechnologyModificationChange = function(msg)
     102{
     103    var oldAmount = this.maxAmount;
     104    this.maxAmount = this.GetMaxAmount();
     105
     106    var difference = this.maxAmount - oldAmount;
     107    this.amount += difference;
     108}
     109
    85110Engine.RegisterComponentType(IID_ResourceSupply, "ResourceSupply", ResourceSupply);