Ticket #3196: arrowLimit.diff
File arrowLimit.diff, 6.9 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/BuildingAI.js
8 8 "<element name='DefaultArrowCount'>" + 9 9 "<data type='nonNegativeInteger'/>" + 10 10 "</element>" + 11 "<optional>" + 12 "<element name='MaxArrowCount' a:help='Limit the number of arrows to a certain amount'>" + 13 "<data type='nonNegativeInteger'/>" + 14 "</element>" + 15 "</optional>" + 11 16 "<element name='GarrisonArrowMultiplier'>" + 12 17 "<ref name='nonNegativeDecimal'/>" + 13 18 "</element>" + 14 "<element name='GarrisonArrowClasses' >" +19 "<element name='GarrisonArrowClasses' a:help='Add extra arrows for this class list'>" + 15 20 "<text/>" + 16 21 "</element>"; 17 22 … … 23 28 BuildingAI.prototype.Init = function() 24 29 { 25 30 this.currentRound = 0; 31 this.archersGarrisoned = 0; 26 32 //Arrows left to fire 27 33 this.arrowsLeft = 0; 28 34 this.targetUnits = []; 29 35 }; 30 36 37 BuildingAI.prototype.OnGarrisonedUnitsChanged = function(msg) 38 { 39 var classes = this.GetGarrisonArrowClasses(); 40 for (let ent of msg.added) 41 { 42 var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); 43 if (!cmpIdentity) 44 continue; 45 if (MatchesClassList(cmpIdentity.GetClassesList(), classes)) 46 this.archersGarrisoned++; 47 } 48 49 for (let ent of msg.removed) 50 { 51 var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); 52 if (!cmpIdentity) 53 continue; 54 if (MatchesClassList(cmpIdentity.GetClassesList(), classes)) 55 this.archersGarrisoned--; 56 } 57 }; 58 31 59 BuildingAI.prototype.OnOwnershipChanged = function(msg) 32 60 { 33 61 // Remove current targets, to prevent them from being added twice … … 205 233 return ApplyValueModificationsToEntity("BuildingAI/DefaultArrowCount", arrowCount, this.entity); 206 234 }; 207 235 236 BuildingAI.prototype.GetMaxArrowCount = function() 237 { 238 if (!this.template.MaxArrowCount) 239 return undefined; 240 241 var maxArrowCount = +this.template.MaxArrowCount; 242 return Math.round(ApplyValueModificationsToEntity("BuildingAI/MaxArrowCount", maxArrowCount, this.entity)); 243 }; 244 208 245 BuildingAI.prototype.GetGarrisonArrowMultiplier = function() 209 246 { 210 247 var arrowMult = +this.template.GarrisonArrowMultiplier; … … 213 250 214 251 BuildingAI.prototype.GetGarrisonArrowClasses = function() 215 252 { 216 var string = this.template.GarrisonArrowClasses; 217 if (string) 218 return string.split(/\s+/); 219 return []; 253 return this.template.GarrisonArrowClasses; 220 254 }; 221 255 222 256 /** … … 229 263 var count = this.GetDefaultArrowCount(); 230 264 var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); 231 265 if (cmpGarrisonHolder) 232 { 233 count += Math.round(cmpGarrisonHolder.GetGarrisonedArcherCount(this.GetGarrisonArrowClasses()) * this.GetGarrisonArrowMultiplier()); 234 } 266 count += Math.round(this.archersGarrisoned * this.GetGarrisonArrowMultiplier()); 267 268 if (this.GetMaxArrowCount() < count) 269 return this.GetMaxArrowCount(); 235 270 return count; 236 271 }; 237 272 -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
188 188 }; 189 189 190 190 /** 191 * Get number of garrisoned units capable of shooting arrows192 * Not necessarily archers193 */194 GarrisonHolder.prototype.GetGarrisonedArcherCount = function(garrisonArrowClasses)195 {196 var count = 0;197 for each (var entity in this.entities)198 {199 var cmpIdentity = Engine.QueryInterface(entity, IID_Identity);200 var classes = cmpIdentity.GetClassesList();201 if (classes.some(function(c){return garrisonArrowClasses.indexOf(c) > -1;}))202 count++;203 }204 return count;205 };206 207 /**208 191 * Checks if an entity can be allowed to garrison in the building 209 192 * based on its class 210 193 */ -
binaries/data/mods/public/simulation/templates/structures/rome_army_camp.xml
24 24 </Ranged> 25 25 </Attack> 26 26 <BuildingAI> 27 <DefaultArrowCount>3</DefaultArrowCount> 28 <GarrisonArrowMultiplier>0.5</GarrisonArrowMultiplier> 27 <DefaultArrowCount>1</DefaultArrowCount> 28 <MaxArrowCount>11</MaxArrowCount> 29 <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier> 29 30 </BuildingAI> 30 31 <BuildRestrictions> 31 32 <Territory>own neutral enemy</Territory> -
binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_bireme.xml
15 15 </Attack> 16 16 <BuildingAI> 17 17 <DefaultArrowCount>2</DefaultArrowCount> 18 <MaxArrowCount>7</MaxArrowCount> 18 19 <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier> 19 20 <GarrisonArrowClasses>Infantry Ranged</GarrisonArrowClasses> 20 21 </BuildingAI> -
binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_quinquereme.xml
23 23 </Attack> 24 24 <BuildingAI> 25 25 <DefaultArrowCount>0</DefaultArrowCount> 26 <MaxArrowCount>10</MaxArrowCount> 26 27 <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier> 27 28 <GarrisonArrowClasses>Catapult</GarrisonArrowClasses> 28 29 </BuildingAI> … … 52 53 </Health> 53 54 <Identity> 54 55 <GenericName>Heavy Warship</GenericName> 55 <Tooltip>Garrison with catapults to increase rangedfire power.</Tooltip>56 <Tooltip>Garrison up to 10 catapults to increase fire power.</Tooltip> 56 57 <Classes datatype="tokens">Warship Heavy Ranged</Classes> 57 58 <RequiredTechnology>phase_city</RequiredTechnology> 58 59 </Identity> -
binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_trireme.xml
15 15 </Attack> 16 16 <BuildingAI> 17 17 <DefaultArrowCount>3</DefaultArrowCount> 18 <MaxArrowCount>13</MaxArrowCount> 18 19 <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier> 19 20 <GarrisonArrowClasses>Infantry Ranged</GarrisonArrowClasses> 20 21 </BuildingAI>