Ticket #4126: promotion.diff

File promotion.diff, 6.5 KB (added by fatherbushido, 8 years ago)
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

    ProductionQueue.prototype.CalculateEntit  
    119119    entitiesList = entitiesList.filter(
    120120        function(v) { return !disabledEntities[v] && cmpTemplateManager.TemplateExists(v); }
    121121    );
    122122
    123123    // check if some templates need to show their advanced or elite version
    124     var upgradeTemplate = function(templateName)
     124    var upgradeTemplate = function(templateName, player)
    125125    {
    126126        var template = cmpTemplateManager.GetTemplate(templateName);
    127127        while (template && template.Promotion !== undefined)
    128128        {
    129             var requiredXp = ApplyValueModificationsToTemplate("Promotion/RequiredXp", +template.Promotion.RequiredXp, cmpPlayer.GetPlayerID(), template);
     129            if (template.Promotion.RequiredTechnology)
     130            {
     131                let cmpTechnologyManager = QueryPlayerIDInterface(player, IID_TechnologyManager);
     132                if (!cmpTechnologyManager || !cmpTechnologyManager.IsTechnologyResearched(template.Promotion.RequiredTechnology))
     133                    break;
     134            }
     135            var requiredXp = ApplyValueModificationsToTemplate("Promotion/RequiredXp", +template.Promotion.RequiredXp, player, template);
    130136            if (requiredXp > 0)
    131137                break;
    132138            templateName = template.Promotion.Entity;
    133139            template = cmpTemplateManager.GetTemplate(templateName);
    134140        }
    135141        return templateName;
    136142    };
    137143
    138144    for (let templateName of entitiesList)
    139         this.entitiesList.push(upgradeTemplate(templateName));
     145        this.entitiesList.push(upgradeTemplate(templateName, cmpPlayer.GetPlayerID()));
    140146
    141147    for (let item of this.queue)
    142148        if (item.unitTemplate)
    143             item.unitTemplate = upgradeTemplate(item.unitTemplate);
     149            item.unitTemplate = upgradeTemplate(item.unitTemplate, cmpPlayer.GetPlayerID());
    144150};
    145151
    146152/*
    147153 * Returns list of technologies that can be researched by this building.
    148154 */
    ProductionQueue.prototype.AddBatch = fun  
    276282            {
    277283                var requiredXp = ApplyValueModificationsToTemplate("Promotion/RequiredXp", +template.Promotion.RequiredXp, cmpPlayer.GetPlayerID(), template);
    278284
    279285                if (requiredXp == 0)
    280286                {
    281                     this.AddBatch(template.Promotion.Entity, type, count, metadata);
    282                     return;
     287                    if (template.Promotion.RequiredTechnology)
     288                    {
     289                        let cmpTechnologyManager = QueryPlayerIDInterface(cmpPlayer.GetPlayerID(), IID_TechnologyManager);
     290                        if (cmpTechnologyManager && cmpTechnologyManager.IsTechnologyResearched(template.Promotion.RequiredTechnology))
     291                        {
     292                            this.AddBatch(template.Promotion.Entity, type, count, metadata);
     293                            return;
     294                        }
     295                    }
     296                    else
     297                    {
     298                        this.AddBatch(template.Promotion.Entity, type, count, metadata);
     299                        return;
     300                    }
    283301                }
    284302            }
    285303
    286304            // Apply a time discount to larger batches.
    287305            var timeMult = this.GetBatchTime(count);
  • binaries/data/mods/public/simulation/components/Promotion.js

    function Promotion() {}  
    33Promotion.prototype.Schema =
    44    "<element name='Entity'>" +
    55        "<text/>" +
    66    "</element>" +
    77    "<element name='RequiredXp'>" +
    8         "<data type='positiveInteger'/>" +
    9     "</element>";
     8        "<data type='nonNegativeInteger'/>" +
     9    "</element>" +
     10    "<optional>" +
     11        "<element name='AllowPromotedUnitProduction' a:help='Optional name of a technology which must be researched before the entity can be promoted'>" +
     12            "<data type='boolean'/>" +
     13        "</element>" +
     14    "</optional>" +
     15    "<optional>" +
     16        "<element name='RequiredTechnology' a:help='Optional name of a technology which must be researched before the entity can be promoted'>" +
     17            "<text/>" +
     18        "</element>" +
     19    "</optional>";
    1020
    1121Promotion.prototype.Init = function()
    1222{
    1323    this.currentXp = 0;
    1424};
    Promotion.prototype.Promote = function(p  
    3343    // If the unit is dead, don't promote it
    3444    var cmpCurrentUnitHealth = Engine.QueryInterface(this.entity, IID_Health);
    3545    if (cmpCurrentUnitHealth.GetHitpoints() == 0)
    3646        return;
    3747
     48    // If the required technology is not researched, don't promote the unit
     49    let cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager);
     50    if (!cmpTechnologyManager || !cmpTechnologyManager.IsTechnologyResearched(this.template.RequiredTechnology))
     51        return;
     52
    3853    // Create promoted unit entity
    3954    var promotedUnitEntity = Engine.AddEntity(promotedTemplateName);
    4055
    4156    // Copy parameters from current entity to promoted one
    4257    var cmpCurrentUnitPosition = Engine.QueryInterface(this.entity, IID_Position);
  • binaries/data/mods/public/simulation/data/technologies/successors/upgrade_mace_silvershields.json

     
    55    "requirements": {"all": [{"tech": "phase_city"}, {"civ": "mace"}]},
    66    "requirementsTooltip": "Unlocked in City Phase.",
    77    "icon": "shields_generic_silver.png",
    88    "researchTime": 40,
    99    "tooltip": "Upgrade Shield Bearer Champion Infantry to Silver Shields, with greater health and armor.",
    10     "modifications": [{"value": "Promotion/RequiredXp", "replace": 0}],
    1110    "affects": ["Champion Infantry"],
    1211    "soundComplete": "interface/alarm/alarm_upgradearmory.xml"
    1312}
  • binaries/data/mods/public/simulation/templates/units/mace_champion_infantry_a.xml

     
    1010    <SelectionGroupName>units/mace_champion_infantry_a</SelectionGroupName>
    1111    <RequiredTechnology>phase_city</RequiredTechnology>
    1212  </Identity>
    1313  <Promotion>
    1414    <Entity>units/mace_champion_infantry_e</Entity>
    15     <RequiredXp>2000</RequiredXp>
     15    <RequiredXp>0</RequiredXp>
     16    <RequiredTechnology>successors/upgrade_mace_silvershields</RequiredTechnology>
    1617  </Promotion>
    1718  <VisualActor>
    1819    <Actor>units/macedonians/mace_champion_hypaspist.xml</Actor>
    1920  </VisualActor>
    2021</Entity>