This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Ticket #2160: regicide_garrison_option_v3.patch

File regicide_garrison_option_v3.patch, 13.2 KB (added by Sandarac, 8 years ago)

Uses dynamic templates, requires #2951.

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

     
    498498        "ExploreMap": "exploreMap",
    499499        "DisableTreasures": "disableTreasures",
    500500        "LockTeams": "lockTeams",
    501         "LastManStanding" : "lastManStanding",
     501        "LastManStanding": "lastManStanding",
     502        "RegicideGarrison": "regicideGarrison",
    502503        "CheatsEnabled": "enableCheats"
    503504    };
    504505
     
    11831184    {
    11841185        delete g_GameAttributes.settings.WonderDuration;
    11851186        delete g_GameAttributes.settings.LastManStanding;
     1187        delete g_GameAttributes.settings.RegicideGarrison;
    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("regicideGarrison", "regicideGarrisonText", !!mapSettings.RegicideGarrison);
    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("optionRegicideGarrison").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", "regicideGarrison"])
    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="optionRegicideGarrison" size="14 98 94% 126">
    339339                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     340                        <translatableAttribute id="caption">Hero Garrison:</translatableAttribute>
     341                    </object>
     342                    <object name="regicideGarrisonText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
     343                    <object name="regicideGarrison" 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 be garrisoned.</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/maps/scripts/Regicide.js

     
    66
    77Trigger.prototype.InitRegicideGame = function(msg)
    88{
     9    let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
     10    this.regicideGarrison = cmpEndGameManager.GetGameTypeSettings().regicideGarrison;
     11
    912    let playersCivs = [];
    1013    for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID)
    1114        playersCivs[playerID] = QueryPlayerIDInterface(playerID).GetCiv();
     
    3033
    3134        if (heroTemplates[identity.Civ].indexOf(templateName) == -1)
    3235            heroTemplates[identity.Civ].push({
    33                 "templateName": templateName,
     36                "templateName": this.regicideGarrison ? templateName : "regicide_hero_ungarrisonable|" + templateName,
    3437                "classes": classes
    3538            });
    3639    }
     
    104107
    105108let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
    106109cmpTrigger.regicideHeroes = [];
     110cmpTrigger.regicideGarrison = false;
    107111cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {});
    108112cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true });
  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    200200    if (!cmpIdentity)
    201201        return false;
    202202    var entityClasses = cmpIdentity.GetClassesList();
    203     return MatchesClassList(entityClasses, this.template.List._string);
     203    return MatchesClassList(entityClasses, this.template.List._string) && cmpIdentity.GetCanGarrison();
    204204};
    205205
    206206/**
  • binaries/data/mods/public/simulation/components/Identity.js

     
    9191        "<element name='RequiredTechnology' a:help='Optional name of a technology which must be researched before the entity can be produced'>" +
    9292            "<text/>" +
    9393        "</element>" +
     94    "</optional>" +
     95    "<optional>" +
     96        "<element name='CanGarrison' a:help='If the entity can garrison'>" +
     97            "<data type='boolean'/>" +
     98        "</element>" +
    9499    "</optional>";
    95100
    96101
     
    168173    return this.template.GenericName;
    169174};
    170175
     176Identity.prototype.GetCanGarrison = function()
     177{
     178    return this.template.CanGarrison == "true";
     179};
     180
    171181Engine.RegisterComponentType(IID_Identity, "Identity", Identity);
  • binaries/data/mods/public/simulation/components/tests/test_GarrisonHolder.js

     
     1Engine.LoadHelperScript("Player.js");
     2Engine.LoadHelperScript("ValueModification.js");
     3Engine.LoadComponentScript("interfaces/GarrisonHolder.js");
     4Engine.LoadComponentScript("interfaces/Health.js");
     5Engine.LoadComponentScript("interfaces/Trigger.js");
     6Engine.LoadComponentScript("interfaces/Player.js");
     7Engine.LoadComponentScript("GarrisonHolder.js");
     8Engine.LoadComponentScript("Identity.js");
     9Engine.LoadComponentScript("Player.js");
     10Engine.LoadComponentScript("PlayerManager.js");
     11
     12let garrisonEnt = 15;
     13let unitEnt = 33;
     14let entHP = 1000;
     15let playerEnt = 1;
     16
     17AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
     18    "GetPlayerByID": (id) => playerEnt,
     19});
     20
     21AddMock(garrisonEnt, IID_Health, {
     22    "GetHitpoints": () => entHP,
     23    "Decrease": hp => {
     24        entHP = Math.max(entHP - hp, 0);
     25    },
     26});
     27
     28AddMock(unitEnt, IID_Identity, {
     29    "GetClassesList": () => ["Hero", "Infantry"],
     30    "GetVisibleClassesList": () => ["Hero", "Infantry"],
     31    "HasClass": () => true,
     32    "GetCanGarrison": () => true,
     33});
     34
     35AddMock(garrisonEnt, IID_Ownership, {
     36    "GetOwner": () => playerEnt,
     37});
     38
     39AddMock(playerEnt, IID_Ownership, {
     40    "GetOwner": () => playerEnt,
     41});
     42
     43let cmpGarrisonHolder = ConstructComponent(garrisonEnt, "GarrisonHolder", {
     44    "LoadingRange": "2.0",
     45    "Max": "20",
     46    "List": { "_string": "Support Infantry Cavalry"},
     47    "entity": garrisonEnt,
     48});
     49
     50let cmpPlayer = ConstructComponent(playerEnt, "Player")
     51
     52TS_ASSERT_EQUALS(cmpGarrisonHolder.GetGarrisonedEntitiesCount(), 0);
     53TS_ASSERT_EQUALS(cmpGarrisonHolder.entities.length, 0);
     54TS_ASSERT_EQUALS(cmpGarrisonHolder.visibleGarrisonPoints.length, 0);
     55TS_ASSERT_EQUALS(+cmpGarrisonHolder.template.Max, 20);
     56TS_ASSERT_EQUALS(cmpGarrisonHolder.GetLoadingRange().max, 2.0);
     57TS_ASSERT_EQUALS(cmpGarrisonHolder.IsGarrisoningAllowed(), true);
     58TS_ASSERT_EQUALS(cmpGarrisonHolder.AllowedToGarrison(unitEnt), true);
     59TS_ASSERT(cmpGarrisonHolder.GetAllowedClasses().indexOf("Infantry") != -1);
  • binaries/data/mods/public/simulation/components/tests/test_Identity.js

    Property changes on: binaries/data/mods/public/simulation/components/tests/test_GarrisonHolder.js
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
     1Engine.LoadHelperScript("Player.js");
     2Engine.LoadHelperScript("ValueModification.js");
     3Engine.LoadComponentScript("interfaces/Health.js");
     4Engine.LoadComponentScript("interfaces/Trigger.js");
     5Engine.LoadComponentScript("interfaces/Player.js");
     6Engine.LoadComponentScript("Identity.js");
     7Engine.LoadComponentScript("Player.js");
     8Engine.LoadComponentScript("PlayerManager.js");
     9
     10let unitEnt = 33;
     11let playerEnt = 1;
     12
     13AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
     14    "GetPlayerByID": (id) => playerEnt,
     15});
     16
     17AddMock(playerEnt, IID_Ownership, {
     18    "GetOwner": () => playerEnt,
     19});
     20
     21let cmpIdentity = ConstructComponent(unitEnt, "Identity", {
     22    "Classes": "Infantry Champion",
     23    "VisibleClasses": "Champion",
     24    "Civ": "athen",
     25    "entity": unitEnt,
     26    "CanGarrison": "true",
     27});
     28
     29TS_ASSERT_EQUALS(cmpIdentity.GetCiv(), "athen");
     30TS_ASSERT_EQUALS(cmpIdentity.GetGender(), "male");
     31TS_ASSERT_EQUALS(cmpIdentity.GetLang(), "greek");
     32TS_ASSERT_EQUALS(cmpIdentity.GetCanGarrison(), true);
  • binaries/data/mods/public/simulation/helpers/Setup.js

    Property changes on: binaries/data/mods/public/simulation/components/tests/test_Identity.js
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    4747    let gameTypeSettings = {};
    4848    if (settings.WonderDuration)
    4949        gameTypeSettings.wonderDuration = settings.WonderDuration * 60 * 1000;
     50    if (settings.GameType == "regicide")
     51        gameTypeSettings.regicideGarrison = settings.RegicideGarrison;
    5052    if (settings.GameType)
    5153        cmpEndGameManager.SetGameType(settings.GameType, gameTypeSettings);
    5254
  • binaries/data/mods/public/simulation/templates/special_filter/regicide_hero_ungarrisonable.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<Entity merge="">
     3  <Identity merge="">
     4    <CanGarrison>false</CanGarrison>
     5  </Identity>
     6</Entity>
  • binaries/data/mods/public/simulation/templates/template_unit.xml

    Property changes on: binaries/data/mods/public/simulation/templates/special_filter/regicide_hero_ungarrisonable.xml
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    3636    <Unhealable>false</Unhealable>
    3737  </Health>
    3838  <Identity>
     39    <CanGarrison>true</CanGarrison>
    3940    <GenericName>Unit</GenericName>
    4041    <Classes datatype="tokens">Unit ConquestCritical</Classes>
    4142    <Formations datatype="tokens">