Ticket #2160: Regicide_v1.5.patch

File Regicide_v1.5.patch, 13.9 KB (added by Sandarac, 8 years ago)

Disables the Production Queue of heroes until City Phase is reached. The GuiInterface.js changes need a bit of tweaking.

  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    498498        "ExploreMap": "exploreMap",
    499499        "DisableTreasures": "disableTreasures",
    500500        "LockTeams": "lockTeams",
    501         "LastManStanding" : "lastManStanding",
     501        "LastManStanding": "lastManStanding",
     502        "RegicideEarlyAttack": "regicideEarlyAttack",
    502503        "CheatsEnabled": "enableCheats"
    503504    };
    504505
     
    11831184    {
    11841185        delete g_GameAttributes.settings.WonderDuration;
    11851186        delete g_GameAttributes.settings.LastManStanding;
     1187        delete g_GameAttributes.settings.RegicideEarlyAttack;
    11861188    }
    11871189
    11881190    if (mapSettings.PlayerData)
     
    13801382    setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap);
    13811383    setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams);
    13821384    setGUIBoolean("lastManStanding", "lastManStandingText", !!mapSettings.LastManStanding);
     1385    setGUIBoolean("regicideEarlyAttack", "regicideEarlyAttackText", !!mapSettings.RegicideEarlyAttack);
    13831386    setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled);
    13841387
    13851388    Engine.GetGUIObjectByName("optionWonderDuration").hidden =
     
    13861389        g_GameAttributes.settings.GameType &&
    13871390        g_GameAttributes.settings.GameType != "wonder";
    13881391    Engine.GetGUIObjectByName("optionLastManStanding").hidden = mapSettings.LockTeams;
     1392    Engine.GetGUIObjectByName("optionRegicideEarlyAttack").hidden =
     1393        g_GameAttributes.settings.GameType &&
     1394        g_GameAttributes.settings.GameType != "regicide";
    13891395
    13901396    Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled;
    13911397
     
    14031409
    14041410    for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap",
    14051411                      "startingResources", "ceasefire", "revealMap",
    1406                       "exploreMap", "disableTreasures", "lockTeams", "lastManStanding"])
     1412                      "exploreMap", "disableTreasures", "lockTeams",
     1413                      "lastManStanding", "regicideEarlyAttack"])
    14071414        hideControl(ctrl, ctrl + "Text", notScenario);
    14081415
    14091416    Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario;
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    335335                    </object>
    336336                </object>
    337337
    338                 <object name="optionPopulationCap" size="14 98 94% 126">
     338                <object name="optionRegicideEarlyAttack" size="14 98 94% 126">
    339339                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     340                        <translatableAttribute id="caption">Early Hero Attack:</translatableAttribute>
     341                    </object>
     342                    <object name="regicideEarlyAttackText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
     343                    <object name="regicideEarlyAttack" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip">
     344                        <translatableAttribute id="tooltip">Toggle whether heroes can attack from the start of the game, or from City Phase.</translatableAttribute>
     345                    </object>
     346                </object>
     347
     348                <object name="optionPopulationCap" size="14 128 94% 156">
     349                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    340350                        <translatableAttribute id="caption">Population Cap:</translatableAttribute>
    341351                    </object>
    342352                    <object name="populationCapText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     
    345355                    </object>
    346356                </object>
    347357
    348                 <object name="optionStartingResources" size="14 128 94% 156">
     358                <object name="optionStartingResources" size="14 158 94% 186">
    349359                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    350360                        <translatableAttribute id="caption">Starting Resources:</translatableAttribute>
    351361                    </object>
     
    355365                    </object>
    356366                </object>
    357367
    358                 <object name="optionCeasefire" size="14 158 94% 186">
     368                <object name="optionCeasefire" size="14 188 94% 216">
    359369                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    360370                        <translatableAttribute id="caption">Ceasefire:</translatableAttribute>
    361371                    </object>
     
    440450                    name="hideMoreOptions"
    441451                    type="button"
    442452                    style="StoneButton"
    443                     size="50%-70 428 50%+70 456"
     453                    size="50%-70 458 50%+70 486"
    444454                    tooltip_style="onscreenToolTip"
    445455                    hotkey="cancel"
    446456                >
  • binaries/data/mods/public/gui/session/selection_panels.js

     
    992992            formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch) +
    993993            "[/color]");
    994994
     995        let productionQueueEnabled = Engine.GuiInterfaceCall("GetProductionQueueEnabled", {
     996            "player": data.unitEntState.player,
     997            "ents": data.selection
     998        });
     999
     1000        if (!productionQueueEnabled)
     1001            tooltips.push(sprintf(translate("The Production Queue is disabled for this entity")));
     1002
    9951003        if (!technologyEnabled)
    9961004            tooltips.push(sprintf(translate("Requires %(technology)s"), {
    9971005                "technology": getEntityNames(GetTechnologyData(template.requiredTechnology))
     
    10031011        data.button.tooltip = tooltips.filter(tip => tip).join("\n");
    10041012
    10051013        let modifier = "";
    1006         if (!technologyEnabled || limits.canBeAddedCount == 0)
     1014        if (!technologyEnabled || limits.canBeAddedCount == 0 || !productionQueueEnabled)
    10071015        {
    10081016            data.button.enabled = false;
    10091017            modifier = "color:0 0 0 127:grayscale:";
  • binaries/data/mods/public/maps/scripts/Regicide.js

     
    4545
    4646    // Attempt to spawn one hero per player
    4747    let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
     48    let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
     49    this.regicideEarlyAttack = !!cmpEndGameManager.GetGameTypeSettings().regicideEarlyAttack;
     50
    4851    for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID)
    4952    {
    5053        let spawnPoints = cmpRangeManager.GetEntitiesByPlayer(playerID).sort((entity1, entity2) =>
     
    5154            getSpawnPreference(entity2) - getSpawnPreference(entity1));
    5255
    5356        this.regicideHeroes[playerID] = this.SpawnRegicideHero(playerID, heroTemplates[playersCivs[playerID]], spawnPoints);
     57
     58        if (this.regicideEarlyAttack)
     59            continue;
     60
     61        let cmpAttack = Engine.QueryInterface(this.regicideHeroes[playerID], IID_Attack);
     62        if (cmpAttack)
     63            cmpAttack.SetEnabled(false);
     64
     65        let cmpAuras = Engine.QueryInterface(this.regicideHeroes[playerID], IID_Auras);
     66        if (cmpAuras)
     67            cmpAuras.SetEnabled(false);
     68
     69        let cmpProductionQueue = Engine.QueryInterface(this.regicideHeroes[playerID], IID_ProductionQueue);
     70        if (cmpProductionQueue)
     71            cmpProductionQueue.SetEnabled(false);
    5472    }
    5573};
    5674
     
    98116    return undefined;
    99117};
    100118
     119Trigger.prototype.CheckRegicideCityPhase = function(data)
     120{
     121    if (data.tech.indexOf("phase_city") == -1 || this.regicideEarlyAttack)
     122        return;
     123
     124    let cmpAttack = Engine.QueryInterface(this.regicideHeroes[data.player], IID_Attack);
     125    if (cmpAttack)
     126        cmpAttack.SetEnabled(true);
     127
     128    let cmpAuras = Engine.QueryInterface(this.regicideHeroes[data.player], IID_Auras);
     129    if (cmpAuras)
     130        cmpAuras.SetEnabled(true);
     131   
     132    let cmpProductionQueue = Engine.QueryInterface(this.regicideHeroes[data.player], IID_ProductionQueue);
     133    if (cmpProductionQueue)
     134        cmpProductionQueue.SetEnabled(true);
     135};
     136
    101137let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
    102138cmpTrigger.regicideHeroes = [];
     139cmpTrigger.regicideEarlyAttack = false;
    103140cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {});
    104141cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true });
     142cmpTrigger.RegisterTrigger("OnResearchFinished", "CheckRegicideCityPhase", { "enabled": true });
  • binaries/data/mods/public/simulation/components/Attack.js

     
    202202
    203203Attack.prototype.Init = function()
    204204{
     205    this.enabled = true;
    205206};
    206207
    207208Attack.prototype.Serialize = null; // we have no dynamic state to save
    208209
     210Attack.prototype.GetEnabled = function()
     211{
     212    return this.enabled;
     213};
     214
     215Attack.prototype.SetEnabled = function(enabled)
     216{
     217    this.enabled = enabled;
     218};
     219
    209220Attack.prototype.GetAttackTypes = function()
    210221{
    211222    return ["Melee", "Ranged", "Capture"].filter(type => !!this.template[type]);
     
    231242
    232243Attack.prototype.CanAttack = function(target)
    233244{
     245    if (!this.enabled)
     246        return false;
     247
    234248    let cmpFormation = Engine.QueryInterface(target, IID_Formation);
    235249    if (cmpFormation)
    236250        return true;
  • binaries/data/mods/public/simulation/components/Auras.js

     
    88
    99Auras.prototype.Init = function()
    1010{
     11    this.enabled = true;
    1112    let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager);
    1213    this.auras = {};
    1314    this.affectedPlayers = {};
     
    2223    this.Clean();
    2324};
    2425
     26Auras.prototype.GetEnabled = function()
     27{
     28    return this.enabled;
     29};
     30
     31Auras.prototype.SetEnabled = function(enabled)
     32{
     33    this.enabled = enabled;
     34    this.Clean();
     35};
     36
    2537// We can modify identifier if we want stackable auras in some case.
    2638Auras.prototype.GetModifierIdentifier = function(name)
    2739{
     
    109121
    110122Auras.prototype.CanApply = function(name)
    111123{
     124    if (!this.enabled)
     125        return false;
    112126    if (!this.auras[name].requiredTechnology)
    113127        return true;
    114128    let cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager);
  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    275275        cmpProductionQueue.PauseProduction();
    276276
    277277    var cmpAura = Engine.QueryInterface(entity, IID_Auras);
    278     if (cmpAura && cmpAura.HasGarrisonAura())
     278    if (cmpAura && cmpAura.HasGarrisonAura() && cmpAura.GetEnabled())
    279279        cmpAura.ApplyGarrisonBonus(this.entity);
    280280
    281281    Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [entity], "removed": [] });
     
    348348        cmpProductionQueue.UnpauseProduction();
    349349
    350350    var cmpAura = Engine.QueryInterface(entity, IID_Auras);
    351     if (cmpAura && cmpAura.HasGarrisonAura())
     351    if (cmpAura && cmpAura.HasGarrisonAura() && cmpAura.GetEnabled())
    352352        cmpAura.RemoveGarrisonBonus(this.entity);
    353353
    354354
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    757757    return this.timeNotifications.filter(n => n.players.indexOf(player) != -1 && n.endTime > time);
    758758};
    759759
     760GuiInterface.prototype.GetProductionQueueEnabled = function(player, data)
     761{
     762    for (let ent of data.ents)
     763    {
     764        let cmpProductionQueue = Engine.QueryInterface(ent, IID_ProductionQueue);
     765        if (!cmpProductionQueue)
     766            continue;
     767        else
     768            return cmpProductionQueue.GetEnabled();
     769    }
     770    return false;
     771};
     772
    760773GuiInterface.prototype.PushNotification = function(notification)
    761774{
    762775    if (!notification.type || notification.type == "text")
     
    19611974    "GetNeededResources": 1,
    19621975    "GetNotifications": 1,
    19631976    "GetTimeNotifications": 1,
     1977    "GetProductionQueueEnabled": 1,
    19641978
    19651979    "GetAvailableFormations": 1,
    19661980    "GetFormationRequirements": 1,
  • binaries/data/mods/public/simulation/components/ProductionQueue.js

     
    4242
    4343ProductionQueue.prototype.Init = function()
    4444{
     45    this.enabled = true;
    4546    this.nextID = 1;
    4647
    4748    this.queue = [];
     
    7879    this.alertRaiser = undefined;
    7980};
    8081
     82ProductionQueue.prototype.GetEnabled = function()
     83{
     84    return this.enabled;
     85};
     86
     87ProductionQueue.prototype.SetEnabled = function(enabled)
     88{
     89    this.enabled = enabled;
     90};
     91
    8192ProductionQueue.prototype.PutUnderAlert = function(raiser)
    8293{
    8394    this.alertRaiser = raiser;
     
    260271    // TODO: there should probably be a limit on the number of queued batches
    261272    // TODO: there should be a way for the GUI to determine whether it's going
    262273    // to be possible to add a batch (based on resource costs and length limits)
     274    if (!this.enabled)
     275        return;
    263276    var cmpPlayer = QueryOwnerInterface(this.entity);
    264277
    265278    if (this.queue.length < MAX_QUEUE_SIZE)
  • binaries/data/mods/public/simulation/helpers/Setup.js

     
    4747    let gameTypeSettings = {};
    4848    if (settings.WonderDuration)
    4949        gameTypeSettings.wonderDuration = settings.WonderDuration * 60 * 1000;
     50    if (settings.GameType == "regicide")
     51        gameTypeSettings.regicideEarlyAttack = settings.RegicideEarlyAttack;
    5052    if (settings.GameType)
    5153        cmpEndGameManager.SetGameType(settings.GameType, gameTypeSettings);
    5254