Ticket #1318: infinite-farms.patch
File infinite-farms.patch, 6.5 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/ResourceSupply.js
10 10 "<data type='boolean'/>" + 11 11 "</element>" + 12 12 "<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>" + 14 14 "</element>" + 15 15 "<element name='Type' a:help='Type of resources'>" + 16 16 "<choice>" + … … 32 32 "</element>" + 33 33 "<element name='MaxGatherers' a:help='Amount of gatherers who can gather resources from this entity at the same time'>" + 34 34 "<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>"; 36 41 37 42 ResourceSupply.prototype.Init = function() 38 43 { 39 44 // Current resource amount (non-negative) 40 45 this.amount = this.GetMaxAmount(); 41 46 this.gatherers = []; // list of IDs 47 this.infinite = !isFinite(+this.template.Amount); 42 48 }; 43 49 50 ResourceSupply.prototype.IsInfinite = function() 51 { 52 return this.infinite; 53 }; 54 44 55 ResourceSupply.prototype.GetKillBeforeGather = function() 45 56 { 46 57 return (this.template.KillBeforeGather == "true"); … … 48 59 49 60 ResourceSupply.prototype.GetMaxAmount = function() 50 61 { 51 return +this.template.Amount;62 return isFinite(+this.template.Amount) ? +this.template.Amount : 9; 52 63 }; 53 64 54 65 ResourceSupply.prototype.GetCurrentAmount = function() … … 66 77 return this.gatherers; 67 78 }; 68 79 80 ResourceSupply.prototype.GetDiminishingReturns = function() 81 { 82 if ("DiminishingReturns" in this.template) 83 return +this.template.DiminishingReturns; 84 return null; 85 }; 86 69 87 ResourceSupply.prototype.TakeResources = function(rate) 70 88 { 89 if (this.infinite) 90 return { "amount": rate, "exhausted": false }; 91 71 92 // 'rate' should be a non-negative integer 72 93 73 94 var old = this.amount; -
binaries/data/mods/public/simulation/components/ResourceGatherer.js
256 256 { 257 257 rate = rates[type.generic] / cmpPlayer.cheatTimeMultiplier; 258 258 } 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 260 265 return (rate || 0); 261 266 }; 262 267 -
binaries/data/mods/public/simulation/components/StatusBars.js
116 116 var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply); 117 117 if (cmpResourceSupply) 118 118 { 119 AddBar("supply", cmpResourceSupply. GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());119 AddBar("supply", cmpResourceSupply.IsInfinite() ? 1 : cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount()); 120 120 } 121 121 122 122 /* -
binaries/data/mods/public/simulation/components/GuiInterface.js
258 259 if (cmpResourceSupply) 259 260 { 260 261 ret.resourceSupply = { 262 "isInfinite": cmpResourceSupply.IsInfinite(), 261 263 "max": cmpResourceSupply.GetMaxAmount(), 262 264 "amount": cmpResourceSupply.GetCurrentAmount(), 263 265 "type": cmpResourceSupply.GetType(), -
binaries/data/mods/public/gui/session/selection_details.js
96 96 // Resource stats 97 97 if (entState.resourceSupply) 98 98 { 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; 100 101 var resourceType = entState.resourceSupply.type["generic"]; 101 102 if (resourceType == "treasure") 102 103 resourceType = entState.resourceSupply.type["specific"]; … … 104 105 var unitResourceBar = getGUIObjectByName("resourceBar"); 105 106 var resourceSize = unitResourceBar.size; 106 107 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)); 108 110 unitResourceBar.size = resourceSize; 109 111 getGUIObjectByName("resourceLabel").caption = toTitleCase(resourceType) + ":"; 110 112 getGUIObjectByName("resourceStats").caption = resources; -
binaries/data/mods/public/simulation/templates/template_structure_resource_field.xml
51 51 <RallyPoint disable=""/> 52 52 <ResourceSupply> 53 53 <KillBeforeGather>false</KillBeforeGather> 54 <Amount> 2000</Amount>54 <Amount>Infinity</Amount> 55 55 <Type>food.grain</Type> 56 <MaxGatherers>20</MaxGatherers> 56 <MaxGatherers>5</MaxGatherers> 57 <DiminishingReturns>107</DiminishingReturns> 57 58 </ResourceSupply> 58 59 <Sound> 59 60 <SoundGroups>