Ticket #2076: entityLimits.diff

File entityLimits.diff, 13.3 KB (added by sanderd17, 11 years ago)
  • binaries/data/mods/public/gui/session/input.js

     
    16151615    var entLimit = undefined;
    16161616    var entCount = undefined;
    16171617    var canBeAddedCount = undefined;
    1618     if (entCategory && playerState.entityLimits[entCategory])
     1618    if (entCategory && playerState.entityLimits[entCategory] != null)
    16191619    {
    16201620        entLimit = playerState.entityLimits[entCategory];
    16211621        entCount = playerState.entityCounts[entCategory];
  • binaries/data/mods/public/simulation/components/BuildRestrictions.js

     
    5454            "<value>Apadana</value>" +
    5555            "<value>Embassy</value>" +
    5656            "<value>Monument</value>" +
     57            "<value>Pillar</value>" +
    5758        "</choice>" +
    5859    "</element>" +
    5960    "<optional>" +
  • binaries/data/mods/public/simulation/components/EntityLimits.js

     
    2323        "<zeroOrMore>" +
    2424            "<element a:help='Specifies a category of building/unit on which to apply this limit. See BuildRestrictions/TrainingRestrictions for list of categories.'>" +
    2525                "<anyName />" +
    26                 "<choice>" +
    27                     "<text />" +
    28                     "<element name='LimitPerCivCentre' a:help='Specifies that this limit is per number of civil centres.'>" +
    29                         "<data type='nonNegativeInteger'/>" +
    30                     "</element>" +
    31                 "</choice>" +
     26                "<data type='integer'/>" +
    3227            "</element>" +
    3328        "</zeroOrMore>" +
    3429    "</element>";
     
    4641    this.count = {};
    4742    for (var category in this.template.Limits)
    4843    {
    49         this.limit[category] = this.template.Limits[category];
     44        this.limit[category] = +this.template.Limits[category];
    5045        this.count[category] = 0;
    5146    }
    5247};
    5348
     49EntityLimits.prototype.IncreaseLimit = function(category, value)
     50{
     51    if (!this.limit[category])
     52        this.limit[category] = 0;
     53    this.limit[category] += value;
     54};
     55
     56EntityLimits.prototype.DecreaseLimit = function(category, value)
     57{
     58    if (!this.limit[category])
     59        this.limit[category] = 0;
     60    this.limit[category] -= value;
     61
     62};
     63
    5464EntityLimits.prototype.IncreaseCount = function(category, value)
    5565{
    5666    if (this.count[category] !== undefined)
     
    92102    if (this.count[category] === undefined || this.limit[category] === undefined)
    93103        return true;
    94104   
    95     // Rather than complicating the schema unecessarily, just handle special cases here
    96     if (this.limit[category].LimitPerCivCentre !== undefined)
     105    if (this.count[category] + count > this.limit[category])
    97106    {
    98         if (this.count[category] >= this.count["CivilCentre"] * this.limit[category].LimitPerCivCentre)
    99         {
    100             var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
    101             var notification = {
    102                 "player": cmpPlayer.GetPlayerID(),
    103                 "message": category + " " + limitType + " limit of " +
    104                     this.limit[category].LimitPerCivCentre + " per civil centre reached"
    105             };
    106             var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    107             cmpGUIInterface.PushNotification(notification);
    108            
    109             return false;
    110         }
    111     }
    112     else if (this.count[category] + count > this.limit[category])
    113     {
    114107        var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
    115108        var notification = {
    116109            "player": cmpPlayer.GetPlayerID(),
  • binaries/data/mods/public/simulation/components/EntityLimitsChanger.js

     
     1function EntityLimitsChanger() {}
     2
     3EntityLimitsChanger.prototype.Schema =
     4    "<oneOrMore>" +
     5        "<element a:help='Take as name the name of the category, and as value the number you want to increase the limit with.'>" +
     6            "<anyName/>" +
     7            "<data type='integer'/>" +
     8        "</element>" +
     9    "</oneOrMore>";
     10
     11EntityLimitsChanger.prototype.init = function()
     12{
     13};
     14
     15EntityLimitsChanger.prototype.OnOwnershipChanged = function(msg)
     16{
     17    if (!this.changes)
     18    {
     19        this.changes = {};
     20        for (var cat in this.template)
     21            this.changes[cat] = ApplyTechModificationsToEntity("EntityLimitsChanger/Value", +this.template[cat], this.entity);
     22    }
     23
     24    if (msg.from > -1)
     25    {
     26        var cmpEntityLimits = QueryPlayerIDInterface(msg.from, IID_EntityLimits);
     27        if (cmpEntityLimits)
     28            for (var cat in this.changes)
     29                cmpEntityLimits.DecreaseLimit(cat, this.changes[cat]);
     30    }
     31
     32    if (msg.to > -1)
     33    {
     34        var cmpEntityLimits = QueryPlayerIDInterface(msg.to, IID_EntityLimits);
     35        if (cmpEntityLimits)
     36            for (var cat in this.changes)
     37                cmpEntityLimits.IncreaseLimit(cat, this.changes[cat]);
     38    }
     39}
     40
     41EntityLimitsChanger.prototype.OnTechnologyModification = function(msg)
     42{
     43    if (msg.component != "EntityLimitsChanger")
     44        return;
     45
     46    var cmpEntityLimits = Engine.QueryOwnerInterface(this.entity, IID_EntityLimits);
     47    if (!cmpEntityLimits)
     48        return;
     49
     50    for (var cat in this.changes)
     51    {
     52        cmpEntityLimits.DecreaseLimit(cat, this.changes[cat]);
     53        this.changes[cat] = ApplyTechModificationsToEntity("EntityLimitsChanger/Value", +this.template[cat], this.entity);
     54        cmpEntityLimits.IncreaseLimit(cat, this.changes[cat]);
     55    }
     56};
     57
     58Engine.RegisterComponentType(IID_EntityLimitsChanger, "EntityLimitsChanger", EntityLimitsChanger);
  • binaries/data/mods/public/simulation/components/TrainingRestrictions.js

     
    1111        "<choice>" +
    1212            "<value>Hero</value>" +
    1313            "<value>FemaleCitizen</value>" +
     14            "<value>WarDog</value>" +
    1415        "</choice>" +
    1516    "</element>";
    1617
  • binaries/data/mods/public/simulation/components/interfaces/EntityLimitsChanger.js

     
     1Engine.RegisterInterface("EntityLimitsChanger");
  • binaries/data/mods/public/simulation/templates/special/player.xml

     
    33  <EntityLimits>
    44    <LimitMultiplier>1.0</LimitMultiplier>
    55    <Limits>
    6       <CivilCentre/>
    76      <DefenseTower>25</DefenseTower>
    87      <Fortress>10</Fortress>
    98      <Wonder>1</Wonder>
     
    1110      <Apadana>1</Apadana>
    1211      <Embassy>2</Embassy>
    1312      <Monument>5</Monument>
     13      <Pillar>0</Pillar>
     14      <WarDog>0</WarDog>
    1415    </Limits>
    1516  </EntityLimits>
    1617  <Player/>
  • binaries/data/mods/public/simulation/templates/structures/brit_kennel.xml

     
    1818      <stone>50</stone>
    1919    </Resources>
    2020  </Cost>
     21  <EntityLimitsChanger>
     22    <WarDog>10</WarDog>
     23  </EntityLimitsChanger>
    2124  <Footprint>
    2225    <Square width="8.0" depth="7.0"/>
    2326    <Height>5.0</Height>
     
    3134    <Civ>brit</Civ>
    3235    <GenericName>Special Building</GenericName>
    3336    <SpecificName>Kennel</SpecificName>
    34     <Tooltip>Train Celtic war dogs.</Tooltip>
     37    <Tooltip>Train Celtic war dogs. One kennel can only house 10 dogs.</Tooltip>
    3538    <Icon>structures/kennel.png</Icon>
    3639    <RequiredTechnology>phase_town</RequiredTechnology>
    3740  </Identity>
  • binaries/data/mods/public/simulation/templates/structures/celt_kennel.xml

     
    1818      <stone>50</stone>
    1919    </Resources>
    2020  </Cost>
     21  <EntityLimitsChanger>
     22    <WarDog>10</WarDog>
     23  </EntityLimitsChanger>
    2124  <Footprint>
    2225    <Square width="8.0" depth="7.0"/>
    2326    <Height>5.0</Height>
     
    3134    <Civ>celt</Civ>
    3235    <GenericName>Special Building</GenericName>
    3336    <SpecificName>Kennel</SpecificName>
    34     <Tooltip>Train Celtic war dogs.</Tooltip>
     37    <Tooltip>Train Celtic war dogs. One kennel can only house 10 dogs.</Tooltip>
    3538    <Icon>structures/kennel.png</Icon>
    3639    <RequiredTechnology>phase_town</RequiredTechnology>
    3740  </Identity>
  • binaries/data/mods/public/simulation/templates/structures/maur_pillar_ashoka.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_structure_special">
     3  <BuildRestrictions>
     4    <Category>Pillar</Category>
     5  </BuildRestrictions>
    36  <Cost>
    47    <BuildTime>80</BuildTime>
    58    <Resources>
     
    2326    <GenericName>Edict Pillar of Ashoka</GenericName>
    2427    <SpecificName>Śāsana Stambha Aśokā</SpecificName>
    2528    <Icon>structures/monument.png</Icon>
    26     <Tooltip>.</Tooltip>
     29    <Tooltip>The famous pillar of Ashoka. Can only be build when the hero Ashoka is alive. Currently a useless structure.</Tooltip>
    2730    <History>.</History>
    2831  </Identity>
    2932  <Obstruction>
  • binaries/data/mods/public/simulation/templates/template_unit_dog.xml

     
    5959  </Attack>
    6060  <Cost>
    6161    <BuildTime>10</BuildTime>
    62     <Population>1</Population>
     62    <Population>0</Population>
    6363    <Resources>
    6464      <food>100</food>
    6565      <wood>0</wood>
     
    119119  <StatusBars>
    120120    <HeightOffset>6.5</HeightOffset>
    121121  </StatusBars>
     122  <TrainingRestrictions>
     123    <Category>WarDog</Category>
     124  </TrainingRestrictions>
    122125  <UnitMotion>
    123126    <WalkSpeed>13.0</WalkSpeed>
    124127    <Run>
  • binaries/data/mods/public/simulation/templates/units/maur_hero_ashoka.xml

     
    1212      <MinRange>12.0</MinRange>
    1313    </Ranged>
    1414  </Attack>
    15   <Builder>
    16     <Rate>1.0</Rate>
    17     <Entities datatype="tokens">
    18       structures/maur_pillar_ashoka
    19     </Entities>
    20   </Builder>
    2115  <Cost>
    2216    <Population>4</Population>
    2317    <BuildTime>50</BuildTime>
     
    2721      <metal>100</metal>
    2822    </Resources>
    2923  </Cost>
     24  <EntityLimitsChanger>
     25    <Pillar>5</Pillar>
     26  </EntityLimitsChanger>
    3027  <Footprint replace="">
    3128    <Square width="6.0" depth="12.0"/>
    3229    <Height>5.0</Height>
  • binaries/data/mods/public/simulation/templates/units/maur_infantry_archer_b.xml

     
    99  <Builder>
    1010    <Entities datatype="tokens">
    1111      structures/maur_elephant_stables
     12      structures/maur_pillar_ashoka
    1213      structures/{civ}_wonder
    1314    </Entities>
    1415  </Builder>
  • binaries/data/mods/public/simulation/templates/units/maur_infantry_spearman_b.xml

     
    44    <Rate>1.0</Rate>
    55    <Entities datatype="tokens">
    66      structures/maur_elephant_stables
     7      structures/maur_pillar_ashoka
    78      structures/{civ}_wonder
    89    </Entities>
    910  </Builder>
  • binaries/data/mods/public/simulation/templates/units/maur_infantry_swordsman_b.xml

     
    1111  <Builder>
    1212    <Entities datatype="tokens">
    1313      structures/maur_elephant_stables
     14      structures/maur_pillar_ashoka
    1415      structures/{civ}_wonder
    1516    </Entities>
    1617  </Builder>