Ticket #1387: Gatherers3.patch
File Gatherers3.patch, 4.1 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/ResourceGatherer.js
190 190 if (!this.GetTargetGatherRate(target)) 191 191 return { "exhausted": true }; 192 192 193 var cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply); 194 if (!cmpResourceSupply.AddGatherer(this.entity)) 195 return { "exhausted": true }; 196 193 197 var gatherAmount = 1; 194 195 var cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply); 198 196 199 var type = cmpResourceSupply.GetType(); 197 200 198 201 // Initialise the carried count if necessary -
binaries/data/mods/public/simulation/components/ResourceSupply.js
29 29 "<value>treasure.metal</value>" + 30 30 "<value>treasure.food</value>" + 31 31 "</choice>" + 32 "</element>" + 33 "<element name='MaxGatherers' a:help='Amount of gatherers who can gather resources from this entity at the same time'>" + 34 "<data type='nonNegativeInteger'/>" + 32 35 "</element>"; 33 36 34 37 ResourceSupply.prototype.Init = function() 35 38 { 36 39 // Current resource amount (non-negative) 37 40 this.amount = this.GetMaxAmount(); 41 this.gatherersAmount = 0; 42 this.gatherers = {}; 38 43 }; 39 44 40 45 ResourceSupply.prototype.GetKillBeforeGather = function() … … 52 57 return this.amount; 53 58 }; 54 59 60 ResourceSupply.prototype.GetMaxGatherers = function() 61 { 62 return +this.template.MaxGatherers; 63 }; 64 55 65 ResourceSupply.prototype.TakeResources = function(rate) 56 66 { 57 67 // 'rate' should be a non-negative integer … … 77 87 return { "generic": type, "specific": subtype }; 78 88 }; 79 89 90 ResourceSupply.prototype.RefreshGatherers = function() 91 { 92 for (var gatherer in this.gatherers) 93 { 94 var cmpUnitAI = Engine.QueryInterface(+gatherer, IID_UnitAI); 95 var orders = cmpUnitAI.GetOrders(); 96 if (orders.length == 0 || orders[0].type != 'Gather' || orders[0].data.target != this.entity) 97 { 98 delete this.gatherers[gatherer]; 99 this.gatherersAmount--; 100 } 101 } 102 }; 103 104 ResourceSupply.prototype.IsAvailable = function(gatherer) 105 { 106 // Check if supply is available for gatherer 107 108 if (gatherer in this.gatherers || this.gatherersAmount < this.GetMaxGatherers()) return true; 109 this.RefreshGatherers(); 110 if (this.gatherersAmount < this.GetMaxGatherers()) return true; 111 return false; 112 }; 113 114 ResourceSupply.prototype.AddGatherer = function(gatherer) 115 { 116 if (!this.IsAvailable(gatherer)) return false; 117 118 if (!(gatherer in this.gatherers)) this.gatherersAmount++; 119 this.gatherers[gatherer] = true; 120 return true; 121 }; 122 80 123 Engine.RegisterComponentType(IID_ResourceSupply, "ResourceSupply", ResourceSupply); -
binaries/data/mods/public/simulation/components/UnitAI.js
2997 2997 if (template.indexOf("resource|") != -1) 2998 2998 template = template.slice(9); 2999 2999 3000 if (amount > 0 && filter(ent, type, template) )3000 if (amount > 0 && filter(ent, type, template) && cmpResourceSupply.IsAvailable(this.entity)) { 3001 3001 return ent; 3002 } 3002 3003 } 3003 3004 3004 3005 return undefined; -
binaries/data/mods/public/simulation/templates/template_structure_resource_field.xml
53 53 <KillBeforeGather>false</KillBeforeGather> 54 54 <Amount>2000</Amount> 55 55 <Type>food.grain</Type> 56 <MaxGatherers>5</MaxGatherers> 56 57 </ResourceSupply> 57 58 <Sound> 58 59 <SoundGroups>