Ticket #4356: ticket4356.patch
File ticket4356.patch, 4.0 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/ResourceSupply.js
19 19 "<data type='nonNegativeInteger'/>" + 20 20 "</element>" + 21 21 "<optional>" + 22 "<element name='DiminishingReturns' a:help='The r ate at which adding more gatherers decreases overall efficiency. Lower numbers = faster dropoff. Leave the element out for no diminishing returns.'>" +22 "<element name='DiminishingReturns' a:help='The relative rate of any new gatherer compared to the previous one (geometric progression). Should be between 0 and 1 exclusives. Leave the element out for no diminishing returns.'>" + 23 23 "<ref name='positiveDecimal'/>" + 24 24 "</element>" + 25 25 "</optional>"; … … 81 81 return this.gatherers.reduce((a, b) => a + b.length, 0); 82 82 }; 83 83 84 /** Note to people looking to change <DiminishingReturns> in a template: This is a bit complicated. Basically, the lower that number is 85 * the steeper diminishing returns will be. I suggest playing around with Wolfram Alpha or a graphing calculator a bit. 86 * In each of the following links, replace 0.65 with the gather rate of your worker for the resource with diminishing returns and 87 * 14 with the constant you wish to use to control the diminishing returns. 88 * (In this case 0.65 is the women farming rate, in resources/second, and 14 is a good constant for farming.) 89 * This is the gather rate in resources/second of each individual worker as the total number of workers goes up: 90 * http://www.wolframalpha.com/input/?i=plot+%281%2F2+cos%28%28x-1%29*pi%2F14%29+%2B+1%2F2%29+*+0.65+from+1+to+5 91 * This is the total output of the resource in resources/second: 92 * http://www.wolframalpha.com/input/?i=plot+x%281%2F2+cos%28%28x-1%29*pi%2F14%29+%2B+1%2F2%29+*+0.65+from+1+to+5 93 * This is the fraction of a worker each new worker is worth (the 5th worker in this example is only producing about half as much as the first one): 94 * http://www.wolframalpha.com/input/?i=plot+x%281%2F2+cos%28%28x-1%29*pi%2F14%29+%2B+1%2F2%29+-++%28x-1%29%281%2F2+cos%28%28x-2%29*pi%2F14%29+%2B+1%2F2%29+from+x%3D1+to+5+and+y%3D0+to+1 95 * Here's how this technically works: 96 * The cosine function is an oscillating curve, normally between -1 and 1. Multiplying by 0.5 squishes that down to 97 * between -0.5 and 0.5. Adding 0.5 to that changes the range to 0 to 1. The diminishingReturns constant 98 * adjusts the period of the curve. 99 */ 84 /* The rate of each additionnal gatherer rate follow a geometric sequence, with diminishingReturns as common ratio. */ 100 85 ResourceSupply.prototype.GetDiminishingReturns = function() 101 86 { 102 87 if ("DiminishingReturns" in this.template) … … 103 88 { 104 89 let diminishingReturns = ApplyValueModificationsToEntity("ResourceSupply/DiminishingReturns", +this.template.DiminishingReturns, this.entity); 105 90 if (diminishingReturns) 106 return (0.5 * Math.cos((this.GetNumGatherers() - 1) * Math.PI / diminishingReturns) + 0.5); 91 { 92 let numGatherers = this.GetNumGatherers(); 93 if (numGatherers > 1) 94 return (1. - Math.pow(diminishingReturns, numGatherers)) / (1. - diminishingReturns) / numGatherers; 95 } 107 96 } 108 97 return null; 109 98 }; -
binaries/data/mods/public/simulation/templates/template_structure_resource_field.xml
49 49 <Amount>Infinity</Amount> 50 50 <Type>food.grain</Type> 51 51 <MaxGatherers>5</MaxGatherers> 52 <!-- 53 See the comment of the function GetTargetGatherRate 54 of the ResourceGatherer component. 55 --> 56 <DiminishingReturns>14</DiminishingReturns> 52 <DiminishingReturns>0.90</DiminishingReturns> 57 53 </ResourceSupply> 58 54 <Sound> 59 55 <SoundGroups>