Ticket #1318: infinite-farms.patch

File infinite-farms.patch, 6.5 KB (added by alpha123, 11 years ago)
  • binaries/data/mods/public/simulation/components/ResourceSupply.js

     
    1010        "<data type='boolean'/>" +
    1111    "</element>" +
    1212    "<element name='Amount' a:help='Amount of resources available from this entity'>" +
    13         "<data type='nonNegativeInteger'/>" +
     13        "<choice><data type='nonNegativeInteger'/><value>Infinity</value></choice>" +
    1414    "</element>" +
    1515    "<element name='Type' a:help='Type of resources'>" +
    1616        "<choice>" +
     
    3232    "</element>" +
    3333    "<element name='MaxGatherers' a:help='Amount of gatherers who can gather resources from this entity at the same time'>" +
    3434        "<data type='nonNegativeInteger'/>" +
    35     "</element>";
     35    "</element>" +
     36    "<optional>" +
     37        "<element name='DiminishingReturns' a:help='The rate at which adding more gatherers decreases overall efficiency. Lower numbers = faster dropoff. Leave the element out for no diminishing returns.'>" +
     38            "<ref name='positiveDecimal'/>" +
     39        "</element>" +
     40    "</optional>";
    3641
    3742ResourceSupply.prototype.Init = function()
    3843{
    3944    // Current resource amount (non-negative)
    4045    this.amount = this.GetMaxAmount();
    4146    this.gatherers = [];    // list of IDs
     47    this.infinite = !isFinite(+this.template.Amount);
    4248};
    4349
     50ResourceSupply.prototype.IsInfinite = function()
     51{
     52    return this.infinite;
     53};
     54
    4455ResourceSupply.prototype.GetKillBeforeGather = function()
    4556{
    4657    return (this.template.KillBeforeGather == "true");
     
    4859
    4960ResourceSupply.prototype.GetMaxAmount = function()
    5061{
    51     return +this.template.Amount;
     62    return isFinite(+this.template.Amount) ? +this.template.Amount : 9;
    5263};
    5364
    5465ResourceSupply.prototype.GetCurrentAmount = function()
     
    6677    return this.gatherers;
    6778};
    6879
     80ResourceSupply.prototype.GetDiminishingReturns = function()
     81{
     82    if ("DiminishingReturns" in this.template)
     83        return +this.template.DiminishingReturns;
     84    return null;
     85};
     86
    6987ResourceSupply.prototype.TakeResources = function(rate)
    7088{
     89    if (this.infinite)
     90        return { "amount": rate, "exhausted": false };
     91
    7192    // 'rate' should be a non-negative integer
    7293
    7394    var old = this.amount;
  • binaries/data/mods/public/simulation/components/ResourceGatherer.js

     
    256256    {
    257257        rate = rates[type.generic] / cmpPlayer.cheatTimeMultiplier;
    258258    }
    259    
     259
     260    // Apply diminishing returns with more gatherers, e.g. for infinite farms. For most resources this has no effect. (GetDiminishingReturns will return Infinity.)
     261    var diminishingReturns = cmpResourceSupply.GetDiminishingReturns();
     262    if (diminishingReturns)
     263        rate = +(rate - Math.pow((cmpResourceSupply.GetGatherers().length || 1) - 1, 2) / diminishingReturns).toFixed(2);
     264
    260265    return (rate || 0);
    261266};
    262267
  • binaries/data/mods/public/simulation/components/StatusBars.js

     
    116116    var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
    117117    if (cmpResourceSupply)
    118118    {
    119         AddBar("supply", cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());
     119        AddBar("supply", cmpResourceSupply.IsInfinite() ? 1 : cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());
    120120    }
    121121
    122122    /*
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    258259    if (cmpResourceSupply)
    259260    {
    260261        ret.resourceSupply = {
     262            "isInfinite": cmpResourceSupply.IsInfinite(),
    261263            "max": cmpResourceSupply.GetMaxAmount(),
    262264            "amount": cmpResourceSupply.GetCurrentAmount(),
    263265            "type": cmpResourceSupply.GetType(),
  • binaries/data/mods/public/gui/session/selection_details.js

     
    9696    // Resource stats
    9797    if (entState.resourceSupply)
    9898    {
    99         var resources = Math.ceil(+entState.resourceSupply.amount) + " / " + entState.resourceSupply.max;
     99        var resources = entState.resourceSupply.isInfinite ? "\u221E" :  // Infinity symbol
     100                        Math.ceil(+entState.resourceSupply.amount) + " / " + entState.resourceSupply.max;
    100101        var resourceType = entState.resourceSupply.type["generic"];
    101102        if (resourceType == "treasure")
    102103            resourceType = entState.resourceSupply.type["specific"];
     
    104105        var unitResourceBar = getGUIObjectByName("resourceBar");
    105106        var resourceSize = unitResourceBar.size;
    106107
    107         resourceSize.rright = 100 * Math.max(0, Math.min(1, +entState.resourceSupply.amount / +entState.resourceSupply.max));
     108        resourceSize.rright = entState.resourceSupply.isInfinite ? 100 :
     109                        100 * Math.max(0, Math.min(1, +entState.resourceSupply.amount / +entState.resourceSupply.max));
    108110        unitResourceBar.size = resourceSize;
    109111        getGUIObjectByName("resourceLabel").caption = toTitleCase(resourceType) + ":";
    110112        getGUIObjectByName("resourceStats").caption = resources;
  • binaries/data/mods/public/simulation/templates/template_structure_resource_field.xml

     
    5151  <RallyPoint disable=""/>
    5252  <ResourceSupply>
    5353    <KillBeforeGather>false</KillBeforeGather>
    54     <Amount>2000</Amount>
     54    <Amount>Infinity</Amount>
    5555    <Type>food.grain</Type>
    56     <MaxGatherers>20</MaxGatherers>
     56    <MaxGatherers>5</MaxGatherers>
     57    <DiminishingReturns>107</DiminishingReturns>
    5758  </ResourceSupply>
    5859  <Sound>
    5960    <SoundGroups>