Ticket #2877: newlimit-v3.diff

File newlimit-v3.diff, 26.5 KB (added by mimo, 9 years ago)
  • binaries/data/mods/public/simulation/components/EntityLimits.js

     
    1313        "</Limits>" +
    1414        "<LimitChangers>" +
    1515            "<Monument>" +
    16                 "<CivCentre>2</CivCentre>" +
     16                "<CivilCentre>2</CivilCentre>" +
    1717            "</Monument>" +
    1818        "</LimitChangers>" +
     19        "<LimitRemovers>" +
     20            "<CivilCentre>" +
     21                "<RequiredTechs datatype=\"tokens\">town_phase</RequiredTechs>" +
     22            "</CivilCentre>" +
     23        "</LimitRemovers>" +
    1924    "</a:example>" +
    2025    "<element name='Limits'>" +
    2126        "<zeroOrMore>" +
     
    3742                "</zeroOrMore>" +
    3843            "</element>" +
    3944        "</zeroOrMore>" +
     45    "</element>" +
     46    "<element name='LimitRemovers'>" +
     47        "<zeroOrMore>" +
     48            "<element a:help='Specifies a category of building/unit on which to remove this limit. The limit will be removed if all the followings requirements are satisfied'>" +
     49                "<anyName />" +
     50                "<oneOrMore>" +
     51                    "<element a:help='Possible requirements are: RequiredTechs and RequiredClasses'>" +
     52                        "<anyName />" +
     53                        "<attribute name='datatype'>" +
     54                            "<value>tokens</value>" +
     55                        "</attribute>" +
     56                        "<text/>" +
     57                    "</element>" +
     58                "</oneOrMore>" +
     59            "</element>" +
     60        "</zeroOrMore>" +
    4061    "</element>";
    4162
    4263
    43 /*
    44  *  TODO: Use an inheriting player_{civ}.xml template for civ-specific limits
    45  */
    46 
    4764const TRAINING = "training";
    4865const BUILD = "build";
    4966
     
    5269    this.limit = {};
    5370    this.count = {};
    5471    this.changers = {};
     72    this.removers = {};
     73    this.removedLimit = {};
    5574    for (var category in this.template.Limits)
    5675    {
    5776        this.limit[category] = +this.template.Limits[category];
    5877        this.count[category] = 0;
    59         if (!(category in this.template.LimitChangers))
    60             continue;
    61         this.changers[category] = {};
    62         for (var c in this.template.LimitChangers[category])
    63             this.changers[category][c] = +this.template.LimitChangers[category][c];
     78        if (category in this.template.LimitChangers)
     79        {
     80            this.changers[category] = {};
     81            for (var c in this.template.LimitChangers[category])
     82                this.changers[category][c] = +this.template.LimitChangers[category][c];
     83        }
     84        if (category in this.template.LimitRemovers)
     85        {
     86            this.removedLimit[category] = this.limit[category]; // keep a copy of removeable limits for possible restoration
     87            this.removers[category] = {};
     88            for (var c in this.template.LimitRemovers[category])
     89            {
     90                this.removers[category][c] = this.template.LimitRemovers[category][c]._string.split(/\s+/);
     91                if (c === "RequiredClasses")
     92                    for (var cls of this.removers[category][c])
     93                        this.count["_"+cls] = 0;
     94            }
     95        }
    6496    }
    6597};
    6698
    67 EntityLimits.prototype.ChangeLimit = function(category, value)
    68 {
    69     this.limit[category] += value;
    70 };
    71 
    7299EntityLimits.prototype.ChangeCount = function(category, value)
    73100{
    74101    if (this.count[category] !== undefined)
     
    90117    return this.changers;
    91118};
    92119
     120EntityLimits.prototype.UpdateLimitsFromTech = function(tech)
     121{
     122    for (var category in this.removers)
     123        if ("RequiredTechs" in this.removers[category] && this.removers[category]["RequiredTechs"].indexOf(tech) !== -1)
     124            this.removers[category]["RequiredTechs"].splice(this.removers[category]["RequiredTechs"].indexOf(tech), 1);
     125
     126    this.UpdateLimitRemoval();
     127};
     128
     129EntityLimits.prototype.UpdateLimitRemoval = function()
     130{
     131    for (var category in this.removers)
     132    {
     133        var nolimit = true;
     134        if ("RequiredTechs" in this.removers[category])
     135            nolimit = !this.removers[category]["RequiredTechs"].length;
     136        if ("RequiredClasses" in this.removers[category])
     137            for (var cls of this.removers[category]["RequiredClasses"])
     138                nolimit = nolimit && this.count["_"+cls] > 0;
     139
     140        if (nolimit && this.limit[category] !== undefined)
     141            this.limit[category] = undefined;
     142        else if (!nolimit && this.limit[category] === undefined)
     143            this.limit[category] = this.removedLimit[category];
     144    }
     145};
     146
     147
    93148EntityLimits.prototype.AllowedToCreate = function(limitType, category, count)
    94149{
    95150    // Allow unspecified categories and those with no limit
     
    137192};
    138193
    139194EntityLimits.prototype.OnGlobalOwnershipChanged = function(msg)
    140 {   
     195{
    141196    // check if we are adding or removing an entity from this player
    142197    var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
    143198    if (!cmpPlayer)
     
    161216    if (cmpTrainingRestrictions)
    162217        category = cmpTrainingRestrictions.GetCategory();
    163218    if (category)
    164         this.ChangeCount(category,modifier);
     219        this.ChangeCount(category, modifier);
    165220
    166221    // Update entity limits
    167222    var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity);
    168223    if (!cmpIdentity)
    169224        return;
     225
    170226    // foundations shouldn't change the entity limits until they're completed
    171227    var cmpFoundation = Engine.QueryInterface(msg.entity, IID_Foundation);
    172228    if (cmpFoundation)
     
    175231    for (var category in this.changers)
    176232        for (var c in this.changers[category])
    177233            if (classes.indexOf(c) >= 0)
    178                 this.ChangeLimit(category, modifier * this.changers[category][c]);
     234            {
     235                if (this.limit[category])
     236                    this.limit[category] += modifier * this.changers[category][c];
     237                if (this.removedLimit[category])    // update removed limits in case we want to restore it
     238                    this.removedLimit[category] += modifier * this.changers[category][c];
     239            }
     240
     241    for (var category in this.removers)
     242        if ("RequiredClasses" in this.removers[category])
     243            for (var cls of this.removers[category]["RequiredClasses"])
     244                if (classes.indexOf(cls) !== -1)
     245                    this.ChangeCount("_"+cls, modifier);
     246
     247    this.UpdateLimitRemoval();
    179248};
    180249
    181250Engine.RegisterComponentType(IID_EntityLimits, "EntityLimits", EntityLimits);
  • binaries/data/mods/public/simulation/components/TechnologyManager.js

     
    346346    var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    347347    var ents = cmpRangeManager.GetEntitiesByPlayer(playerID);
    348348
     349    // Change the EntityLimit if any
     350    var cmpPlayerEntityLimits = QueryPlayerIDInterface(playerID, IID_EntityLimits);
     351    if (cmpPlayerEntityLimits)
     352        cmpPlayerEntityLimits.UpdateLimitsFromTech(tech);
     353
    349354    // Call the related trigger event
    350355    var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
    351356    cmpTrigger.CallEvent("ResearchFinished", {"player": playerID, "tech": tech});
  • binaries/data/mods/public/simulation/helpers/Player.js

     
    2525    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    2626    var numPlayers = cmpPlayerManager.GetNumPlayers();
    2727
     28    var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
     29    var templatesList = cmpTemplateManager.FindAllTemplates(false);
     30
    2831    // Remove existing players or add new ones
    2932    if (newPlayers)
    3033    {
     
    3538        else
    3639            warn("Player.js: Setup has no player data - using defaults");
    3740
     41        for (var i = 1; i < Math.min(numPlayers, settingsNumPlayers); ++i)
     42        {
     43            var pDefs = playerDefaults ? playerDefaults[i] : {};
     44            var pData = settings.PlayerData ? settings.PlayerData[i-1] : {};
     45            var civ = getSetting(pData, pDefs, "Civ");
     46            var neededTemplate = "special/player";
     47            if (templatesList.indexOf("special/"+civ+"_player") !== -1)
     48                neededTemplate = "special/"+civ+"_player";
     49            var entID = cmpPlayerManager.GetPlayerByID(i);
     50            if (cmpTemplateManager.GetCurrentTemplateName(entID) !== neededTemplate)
     51                warn("We need to reload the player " + i);
     52        }
     53
     54
    3855        while (settingsNumPlayers > numPlayers)
    3956        {
    4057            // Add player entity to engine
    41             // TODO: Get player template name from civ data
    42             var entID = Engine.AddEntity("special/player");
     58            var playerTemplate = "special/player";
     59            if (numPlayers > 0)
     60            {
     61                var pDefs = playerDefaults ? playerDefaults[numPlayers] : {};
     62                var pData = settings.PlayerData ? settings.PlayerData[numPlayers-1] : {};
     63                var civ = getSetting(pData, pDefs, "Civ");
     64                if (templatesList.indexOf("special/"+civ+"_player") !== -1)
     65                    playerTemplate = "special/"+civ+"_player";
     66            }
     67            var entID = Engine.AddEntity(playerTemplate);
    4368            var cmpPlayer = Engine.QueryInterface(entID, IID_Player);
    4469            if (!cmpPlayer)
    4570                throw("Player.js: Error creating player entity " + numPlayers);
  • binaries/data/mods/public/simulation/templates/special/player.xml

     
    1515  </BattleDetection>
    1616  <EntityLimits>
    1717    <Limits>
     18      <CivilCentre>1</CivilCentre>
    1819      <DefenseTower>30</DefenseTower>
    1920      <Fortress>10</Fortress>
    2021      <Wonder>1</Wonder>
     
    4142        <PtolemyIV>4</PtolemyIV>
    4243      </Juggernaut>
    4344    </LimitChangers>
     45    <LimitRemovers>
     46      <CivilCentre>
     47        <RequiredTechs datatype="tokens">phase_town</RequiredTechs>
     48      </CivilCentre>
     49    </LimitRemovers>
    4450  </EntityLimits>
    4551  <Player/>
    4652  <StatisticsTracker/>
  • binaries/data/mods/public/simulation/templates/special/ptol_player.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<Entity parent="special/player">
     3  <EntityLimits>
     4    <LimitRemovers>
     5      <CivilCentre>
     6        <RequiredTechs datatype="tokens">phase_town</RequiredTechs>
     7        <RequiredClasses datatype="tokens">Hero</RequiredClasses>
     8      </CivilCentre>
     9    </LimitRemovers>
     10  </EntityLimits>
     11</Entity>
  • binaries/data/mods/public/simulation/templates/special/sele_player.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<Entity parent="special/player">
     3  <EntityLimits>
     4    <LimitRemovers>
     5      <CivilCentre>
     6        <RequiredTechs datatype="tokens">phase_town</RequiredTechs>
     7        <RequiredClasses datatype="tokens">Hero</RequiredClasses>
     8      </CivilCentre>
     9    </LimitRemovers>
     10  </EntityLimits>
     11</Entity>
  • binaries/data/mods/public/simulation/templates/structures/ptol_military_colony.xml

     
    33  <Attack disable=""/>
    44  <BuildRestrictions>
    55    <Territory>own neutral</Territory>
     6    <Category>Colony</Category>
    67    <Distance>
    78      <FromClass>Colony</FromClass>
    89      <MinDistance>120</MinDistance>
     
    4243  <ProductionQueue>
    4344    <Entities datatype="tokens">
    4445      units/ptol_infantry_spearman_2_b
    45       units/ptol_infantry_swordsman_b
     46      units/ptol_infantry_swordsman_b
    4647      units/ptol_cavalry_spearman_b
    4748      units/ptol_cavalry_javelinist_b
    4849    </Entities>
  • binaries/data/mods/public/simulation/templates/structures/sele_military_colony.xml

     
    33  <Attack disable=""/>
    44  <BuildRestrictions>
    55    <Territory>own neutral</Territory>
     6    <Category>Colony</Category>
    67    <Distance>
    78      <FromClass>Colony</FromClass>
    89      <MinDistance>120</MinDistance>
     
    4142  </Obstruction>
    4243  <ProductionQueue>
    4344    <Entities datatype="tokens">
    44       units/sele_infantry_swordsman_b
    45       units/sele_infantry_archer_b
     45      units/sele_infantry_swordsman_b
     46      units/sele_infantry_archer_b
    4647      units/sele_cavalry_spearman_b
    4748    </Entities>
    4849    <Technologies datatype="tokens">
  • binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml

     
    7070    </Classes>
    7171    <VisibleClasses datatype="tokens">CivilCentre</VisibleClasses>
    7272    <Icon>structures/civic_centre.png</Icon>
    73     <RequiredTechnology>phase_town</RequiredTechnology>
    7473  </Identity>
    7574  <Loot>
    7675    <xp>200</xp>
  • binaries/data/mods/public/simulation/templates/units/athen_hero_pericles.xml

     
    2323  </Auras>
    2424  <Identity>
    2525    <Civ>athen</Civ>
    26     <GenericName>Pericles</GenericName>
     26    <GenericName>Pericles</GenericName>
    2727    <SpecificName>Periklēs</SpecificName>
    2828    <History>Pericles was the foremost Athenian politician of the 5th Century.</History>
    2929    <Icon>units/athen_hero_pericles.png</Icon>
  • binaries/data/mods/public/simulation/templates/units/ptol_hero_cleopatra.xml

     
    1313      <AuraDescription>Egyptian units fight 20% faster in her vision range.</AuraDescription>
    1414    </unit_attack_speed_20>
    1515  </Auras>
    16   <Builder>
    17     <Rate>1.0</Rate>
    18     <Entities datatype="tokens">
    19       structures/{civ}_civil_centre
    20     </Entities>
    21   </Builder>
    2216  <Identity>
    2317    <Civ>ptol</Civ>
    2418    <GenericName>Cleopatra VII</GenericName>
  • binaries/data/mods/public/simulation/templates/units/ptol_hero_ptolemy_I.xml

     
    2424      <AuraDescription>Mercenaries cost -50% resources during his lifetime.</AuraDescription>
    2525    </Aura2>
    2626  </Auras>
    27   <Builder>
    28     <Rate>1.0</Rate>
    29     <Entities datatype="tokens">
    30       structures/{civ}_civil_centre
    31     </Entities>
    32   </Builder>
    3327  <Identity>
    3428    <Civ>ptol</Civ>
    3529    <GenericName>Ptolemy I "Savior"</GenericName>
  • binaries/data/mods/public/simulation/templates/units/ptol_hero_ptolemy_IV.xml

     
    1111      <AuraDescription>Egyptian Pikemen have 40% greater health during his lifetime.</AuraDescription>
    1212    </Aura1>
    1313  </Auras>
    14   <Builder>
    15     <Rate>1.0</Rate>
    16     <Entities datatype="tokens">
    17       structures/{civ}_civil_centre
    18     </Entities>
    19   </Builder>
    2014  <Identity>
    2115    <Civ>ptol</Civ>
    2216    <GenericName>Ptolemy IV "Father Loving"</GenericName>
  • binaries/data/mods/public/simulation/templates/units/ptol_infantry_archer_b.xml

     
    22<Entity parent="template_unit_infantry_ranged_archer">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    65      structures/ptol_military_colony
    76      structures/ptol_lighthouse
    87      structures/ptol_library
  • binaries/data/mods/public/simulation/templates/units/ptol_infantry_javelinist_b.xml

     
    22<Entity parent="template_unit_infantry_ranged_javelinist">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    65      structures/ptol_military_colony
    76      structures/ptol_lighthouse
    87      structures/ptol_library
  • binaries/data/mods/public/simulation/templates/units/ptol_infantry_slinger_b.xml

     
    22<Entity parent="template_unit_infantry_ranged_slinger">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    65      structures/ptol_military_colony
    76      structures/ptol_lighthouse
    87      structures/ptol_library
  • binaries/data/mods/public/simulation/templates/units/ptol_infantry_spearman_2_b.xml

     
    22<Entity parent="template_unit_infantry_melee_spearman">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    65      structures/ptol_military_colony
    76      structures/ptol_lighthouse
    87      structures/ptol_library
  • binaries/data/mods/public/simulation/templates/units/ptol_infantry_spearman_b.xml

     
    22<Entity parent="template_unit_infantry_melee_pikeman">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    65      structures/ptol_military_colony
    76      structures/ptol_lighthouse
    87      structures/ptol_library
  • binaries/data/mods/public/simulation/templates/units/ptol_infantry_swordsman_b.xml

     
    22<Entity parent="template_unit_infantry_melee_swordsman">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    65      structures/ptol_military_colony
    76      structures/ptol_lighthouse
    87      structures/ptol_library
  • binaries/data/mods/public/simulation/templates/units/ptol_support_female_citizen.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_unit_support_female_citizen">
    3   <Builder>
    4     <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    6     </Entities>
    7   </Builder>
    83  <Identity>
    94    <Civ>ptol</Civ>
    105    <SpecificName>Gýnē Aigyptiakós</SpecificName>
  • binaries/data/mods/public/simulation/templates/units/sele_hero_antiochus_great.xml

     
    1313      <AuraDescription>All cavalry gains +2 levels of all armour types.</AuraDescription>
    1414    </Aura1>
    1515  </Auras>
    16   <Builder>
    17     <Rate>1.0</Rate>
    18     <Entities datatype="tokens">
    19       structures/{civ}_civil_centre
    20     </Entities>
    21   </Builder>
    2216  <Identity>
    2317    <Civ>sele</Civ>
    2418    <GenericName>Antiochus III "The Great"</GenericName>
  • binaries/data/mods/public/simulation/templates/units/sele_hero_antiochus_righteous.xml

     
    1313      <AuraDescription>All nearby enemy buildings, siege engines, and ships have their health reduced by 20%.</AuraDescription>
    1414    </Aura1>
    1515  </Auras>
    16   <Builder>
    17     <Rate>1.0</Rate>
    18     <Entities datatype="tokens">
    19       structures/{civ}_civil_centre
    20     </Entities>
    21   </Builder>
    2216  <Identity>
    2317    <Civ>sele</Civ>
    2418    <GenericName>Antiochus IV "The Righteous"</GenericName>
  • binaries/data/mods/public/simulation/templates/units/sele_hero_seleucus_victor.xml

     
    1414      <AuraDescription>Boosts War Elephant attack and speed +20% within his vision.</AuraDescription>
    1515    </Aura1>
    1616  </Auras>
    17   <Builder>
    18     <Rate>1.0</Rate>
    19     <Entities datatype="tokens">
    20       structures/{civ}_civil_centre
    21     </Entities>
    22   </Builder>
    2317  <Identity>
    2418    <Civ>sele</Civ>
    2519    <GenericName>Seleucus I "The Victor"</GenericName>
  • binaries/data/mods/public/simulation/templates/units/sele_infantry_archer_b.xml

     
    22<Entity parent="template_unit_infantry_ranged_archer">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    6       structures/sele_military_colony
     5      structures/sele_military_colony
    76      structures/sele_library
    87      structures/sele_wonder
    98    </Entities>
  • binaries/data/mods/public/simulation/templates/units/sele_infantry_javelinist_b.xml

     
    22<Entity parent="template_unit_infantry_ranged_javelinist">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    6       structures/sele_military_colony
     5      structures/sele_military_colony
    76      structures/sele_library
    87      structures/sele_wonder
    98    </Entities>
  • binaries/data/mods/public/simulation/templates/units/sele_infantry_spearman_2_b.xml

     
    22<Entity parent="template_unit_infantry_melee_spearman">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    6       structures/sele_military_colony
     5      structures/sele_military_colony
    76      structures/sele_library
    87      structures/sele_wonder
    98    </Entities>
  • binaries/data/mods/public/simulation/templates/units/sele_infantry_spearman_b.xml

     
    22<Entity parent="template_unit_infantry_melee_pikeman">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    6       structures/sele_military_colony
     5      structures/sele_military_colony
    76      structures/sele_library
    87      structures/sele_wonder
    98    </Entities>
  • binaries/data/mods/public/simulation/templates/units/sele_infantry_swordsman_b.xml

     
    22<Entity parent="template_unit_infantry_melee_swordsman">
    33  <Builder>
    44    <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    6       structures/sele_military_colony
     5      structures/sele_military_colony
    76      structures/sele_library
    87      structures/sele_wonder
    98    </Entities>
  • binaries/data/mods/public/simulation/templates/units/sele_support_female_citizen.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_unit_support_female_citizen">
    3   <Builder>
    4     <Entities datatype="tokens">
    5       -structures/{civ}_civil_centre
    6     </Entities>
    7   </Builder>
    83  <Identity>
    94    <Civ>sele</Civ>
    105    <SpecificName>Syrías Gýnē</SpecificName>