Ticket #3196: arrowLimit.diff

File arrowLimit.diff, 6.9 KB (added by sanderd17, 9 years ago)
  • binaries/data/mods/public/simulation/components/BuildingAI.js

     
    88    "<element name='DefaultArrowCount'>" +
    99        "<data type='nonNegativeInteger'/>" +
    1010    "</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>" +
    1116    "<element name='GarrisonArrowMultiplier'>" +
    1217        "<ref name='nonNegativeDecimal'/>" +
    1318    "</element>" +
    14     "<element name='GarrisonArrowClasses'>" +
     19    "<element name='GarrisonArrowClasses' a:help='Add extra arrows for this class list'>" +
    1520        "<text/>" +
    1621    "</element>";
    1722
     
    2328BuildingAI.prototype.Init = function()
    2429{
    2530    this.currentRound = 0;
     31    this.archersGarrisoned = 0;
    2632    //Arrows left to fire
    2733    this.arrowsLeft = 0;
    2834    this.targetUnits = [];
    2935};
    3036
     37BuildingAI.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
    3159BuildingAI.prototype.OnOwnershipChanged = function(msg)
    3260{
    3361    // Remove current targets, to prevent them from being added twice
     
    205233    return ApplyValueModificationsToEntity("BuildingAI/DefaultArrowCount", arrowCount, this.entity);
    206234};
    207235
     236BuildingAI.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
    208245BuildingAI.prototype.GetGarrisonArrowMultiplier = function()
    209246{
    210247    var arrowMult = +this.template.GarrisonArrowMultiplier;
     
    213250
    214251BuildingAI.prototype.GetGarrisonArrowClasses = function()
    215252{
    216     var string = this.template.GarrisonArrowClasses;
    217     if (string)
    218         return string.split(/\s+/);
    219     return [];
     253    return this.template.GarrisonArrowClasses;
    220254};
    221255
    222256/**
     
    229263    var count = this.GetDefaultArrowCount();
    230264    var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder);
    231265    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();
    235270    return count;
    236271};
    237272
  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    188188};
    189189
    190190/**
    191  * Get number of garrisoned units capable of shooting arrows
    192  * Not necessarily archers
    193  */
    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 /**
    208191 * Checks if an entity can be allowed to garrison in the building
    209192 * based on its class
    210193 */
  • binaries/data/mods/public/simulation/templates/structures/rome_army_camp.xml

     
    2424    </Ranged>
    2525  </Attack>
    2626  <BuildingAI>
    27     <DefaultArrowCount>3</DefaultArrowCount>
    28     <GarrisonArrowMultiplier>0.5</GarrisonArrowMultiplier>
     27    <DefaultArrowCount>1</DefaultArrowCount>
     28    <MaxArrowCount>11</MaxArrowCount>
     29    <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier>
    2930  </BuildingAI>
    3031  <BuildRestrictions>
    3132    <Territory>own neutral enemy</Territory>
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_bireme.xml

     
    1515  </Attack>
    1616  <BuildingAI>
    1717    <DefaultArrowCount>2</DefaultArrowCount>
     18    <MaxArrowCount>7</MaxArrowCount>
    1819    <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier>
    1920    <GarrisonArrowClasses>Infantry Ranged</GarrisonArrowClasses>
    2021  </BuildingAI>
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_quinquereme.xml

     
    2323  </Attack>
    2424  <BuildingAI>
    2525    <DefaultArrowCount>0</DefaultArrowCount>
     26    <MaxArrowCount>10</MaxArrowCount>
    2627    <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier>
    2728    <GarrisonArrowClasses>Catapult</GarrisonArrowClasses>
    2829  </BuildingAI>
     
    5253  </Health>
    5354  <Identity>
    5455    <GenericName>Heavy Warship</GenericName>
    55     <Tooltip>Garrison with catapults to increase ranged fire power.</Tooltip>
     56    <Tooltip>Garrison up to 10 catapults to increase fire power.</Tooltip>
    5657    <Classes datatype="tokens">Warship Heavy Ranged</Classes>
    5758    <RequiredTechnology>phase_city</RequiredTechnology>
    5859  </Identity>
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_trireme.xml

     
    1515  </Attack>
    1616  <BuildingAI>
    1717    <DefaultArrowCount>3</DefaultArrowCount>
     18    <MaxArrowCount>13</MaxArrowCount>
    1819    <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier>
    1920    <GarrisonArrowClasses>Infantry Ranged</GarrisonArrowClasses>
    2021  </BuildingAI>