Ticket #4356: diminishingReturn.patch
File diminishingReturn.patch, 5.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/ResourceGatherer.js
255 255 if ("Mirages" in cmpResourceSupply) 256 256 return rate; 257 257 258 // Apply diminishing returns with more gatherers, for e.g. infinite farms. For most resources this has no effect. (GetDiminishingReturns will return null.) 259 // We can assume that for resources that are miraged this is the case. (else just add the diminishing returns data to the mirage data and remove the 260 // early return above) 261 // Note to people looking to change <DiminishingReturns> in a template: This is a bit complicated. Basically, the lower that number is 262 // the steeper diminishing returns will be. I suggest playing around with Wolfram Alpha or a graphing calculator a bit. 263 // In each of the following links, replace 0.65 with the gather rate of your worker for the resource with diminishing returns and 264 // 14 with the constant you wish to use to control the diminishing returns. 265 // (In this case 0.65 is the women farming rate, in resources/second, and 14 is a good constant for farming.) 266 // This is the gather rate in resources/second of each individual worker as the total number of workers goes up: 267 // 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 268 // This is the total output of the resource in resources/second: 269 // 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 270 // 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): 271 // 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 272 // Here's how this technically works: 273 // The cosine function is an oscillating curve, normally between -1 and 1. Multiplying by 0.5 squishes that down to 274 // between -0.5 and 0.5. Adding 0.5 to that changes the range to 0 to 1. The diminishingReturns constant 275 // adjusts the period of the curve. 258 // Apply diminishing returns with more gatherers, for e.g. infinite farms. For most resources this has no effect 259 // (GetDiminishingReturns will return null). We can assume that for resources that are miraged this is the case 260 // (else just add the diminishing returns data to the mirage data and remove the early return above) 276 261 let diminishingReturns = cmpResourceSupply.GetDiminishingReturns(); 277 262 if (diminishingReturns) 278 rate = (0.5 * Math.cos((cmpResourceSupply.GetNumGatherers() - 1) * Math.PI / diminishingReturns) + 0.5) * rate;263 rate *= diminishingReturns; 279 264 280 265 return rate; 281 266 }; -
binaries/data/mods/public/simulation/components/ResourceSupply.js
79 79 return this.gatherers.reduce((a, b) => a + b.length, 0); 80 80 }; 81 81 82 /** Note to people looking to change <DiminishingReturns> in a template: This is a bit complicated. Basically, the lower that number is 83 * the steeper diminishing returns will be. I suggest playing around with Wolfram Alpha or a graphing calculator a bit. 84 * In each of the following links, replace 0.65 with the gather rate of your worker for the resource with diminishing returns and 85 * 14 with the constant you wish to use to control the diminishing returns. 86 * (In this case 0.65 is the women farming rate, in resources/second, and 14 is a good constant for farming.) 87 * This is the gather rate in resources/second of each individual worker as the total number of workers goes up: 88 * 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 89 * This is the total output of the resource in resources/second: 90 * 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 91 * 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): 92 * 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 93 * Here's how this technically works: 94 * The cosine function is an oscillating curve, normally between -1 and 1. Multiplying by 0.5 squishes that down to 95 * between -0.5 and 0.5. Adding 0.5 to that changes the range to 0 to 1. The diminishingReturns constant 96 * adjusts the period of the curve. 97 */ 82 98 ResourceSupply.prototype.GetDiminishingReturns = function() 83 99 { 84 100 if ("DiminishingReturns" in this.template) 85 return ApplyValueModificationsToEntity("ResourceSupply/DiminishingReturns", +this.template.DiminishingReturns, this.entity); 101 { 102 let diminishingReturns = ApplyValueModificationsToEntity("ResourceSupply/DiminishingReturns", +this.template.DiminishingReturns, this.entity); 103 if (diminishingReturns) 104 return (0.5 * Math.cos((this.GetNumGatherers() - 1) * Math.PI / diminishingReturns) + 0.5); 105 } 86 106 return null; 87 107 }; 88 108