Ticket #3234: wonderOptions_V2.3.patch

File wonderOptions_V2.3.patch, 21.0 KB (added by elexis, 8 years ago)
  • binaries/data/mods/public/simulation/components/EndGameManager.js

    EndGameManager.prototype.Init = function  
    1717    this.gameType = "conquest";
    1818   
    1919    // Allied victory means allied players can win if victory conditions are met for each of them
    2020    // Would be false for a "last man standing" game (when diplomacy is fully implemented)
    2121    this.alliedVictory = true;
     22
     23    this.wonderDuration = 5;
    2224};
    2325
    2426EndGameManager.prototype.GetGameType = function()
    2527{
    2628    return this.gameType;
    EndGameManager.prototype.SetGameType = f  
    3537EndGameManager.prototype.CheckGameType = function(type)
    3638{
    3739    return this.gameType == type;
    3840};
    3941
     42EndGameManager.prototype.SetWonderDuration = function(wonderDuration)
     43{
     44    this.wonderDuration = wonderDuration;
     45};
     46
     47EndGameManager.prototype.GetWonderDuration = function()
     48{
     49    return this.wonderDuration;
     50};
     51
    4052EndGameManager.prototype.MarkPlayerAsWon = function(playerID)
    4153{
    4254    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    4355    var numPlayers = cmpPlayerManager.GetNumPlayers();
    4456    for (var i = 1; i < numPlayers; i++)
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

    const g_GameSpeeds = prepareForDropdown(  
    66const g_MapSizes = prepareForDropdown(g_Settings ? g_Settings.MapSizes : undefined);
    77const g_MapTypes = prepareForDropdown(g_Settings ? g_Settings.MapTypes : undefined);
    88const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined);
    99const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined);
    1010const g_VictoryConditions = prepareForDropdown(g_Settings ? g_Settings.VictoryConditions : undefined);
     11const g_WonderDurations = prepareForDropdown(g_Settings ? g_Settings.WonderDurations : undefined);
    1112
    1213/**
    1314 * All selectable playercolors except gaia.
    1415 */
    1516const g_PlayerColors = g_Settings ? g_Settings.PlayerDefaults.slice(1).map(pData => pData.Color) : undefined;
    function initGUIObjects()  
    241242        initNumberOfPlayers();
    242243        initGameSpeed();
    243244        initPopulationCaps();
    244245        initStartingResources();
    245246        initCeasefire();
     247        initWonderDurations();
    246248        initVictoryConditions();
    247249        initMapSizes();
    248250        initRadioButtons();
    249251    }
    250252    else
    function initMapFilters()  
    300302function resizeMoreOptionsWindow()
    301303{
    302304    // For singleplayer reduce the size of more options dialog by two options (cheats, rated game = 60px)
    303305    if (!g_IsNetworked)
    304306    {
    305         Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+160";
    306         Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 310 50%+70 336";
     307        Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+190";
     308        Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 340 50%+70 366";
    307309    }
    308310    // For non-lobby multiplayergames reduce the size of the dialog by one option (rated game, 30px)
    309311    else if (!Engine.HasXmppClient())
    310312    {
    311313        Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+190";
    312         Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 340 50%+70 366";
     314        Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 370 50%+70 396";
    313315    }
    314316}
    315317
    316318function initNumberOfPlayers()
    317319{
    function initVictoryConditions()  
    399401        updateGameAttributes();
    400402    };
    401403    victoryConditions.selected = g_VictoryConditions.Default;
    402404}
    403405
     406function initWonderDurations()
     407{
     408    let wonderConditions = Engine.GetGUIObjectByName("wonderDuration");
     409    wonderConditions.list = g_WonderDurations.Title;
     410    wonderConditions.list_data = g_WonderDurations.Duration;
     411    wonderConditions.selected = g_WonderDurations.Default;
     412    wonderConditions.onSelectionChange = function()
     413    {
     414        if (this.selected != -1)
     415            g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected];
     416
     417        updateGameAttributes();
     418    };
     419}
     420
    404421function initMapSizes()
    405422{
    406423    let mapSize = Engine.GetGUIObjectByName("mapSize");
    407424    mapSize.list = g_MapSizes.LongName;
    408425    mapSize.list_data = g_MapSizes.Tiles;
    function updateGUIObjects()  
    12361253    let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default;
    12371254
    12381255    // These dropdowns might set the default (as they ignore g_IsInGuiUpdate)
    12391256    let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default;
    12401257    let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default;
     1258    let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default;
    12411259    let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default;
    12421260    let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default;
    12431261    let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
    12441262    let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers;
    12451263
    function updateGUIObjects()  
    12521270        Engine.GetGUIObjectByName("numPlayersSelection").selected = numPlayers - 1;
    12531271        Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
    12541272        Engine.GetGUIObjectByName("populationCap").selected = popIdx;
    12551273        Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
    12561274        Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
     1275        Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
    12571276        Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
    12581277    }
    12591278    else
    12601279    {
    12611280        Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx];
    function updateGUIObjects()  
    12661285
    12671286    // Can be visible to both host and clients
    12681287    Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default");
    12691288    Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers;
    12701289    Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx];
     1290    Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx];
    12711291    Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx];
    12721292    Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx];
    12731293    Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx];
    12741294    Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx];
    12751295
    function updateGUIObjects()  
    12781298    setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap);
    12791299    setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap);
    12801300    setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams);
    12811301    setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled);
    12821302
     1303    Engine.GetGUIObjectByName("optionWonderDuration").hidden =
     1304        g_GameAttributes.settings.GameType &&
     1305        g_GameAttributes.settings.GameType != "wonder";
     1306
    12831307    Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled;
    12841308
    12851309    Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled;
    12861310    Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled;
    12871311
    function updateGUIObjects()  
    12921316    Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController;
    12931317    hideControl("numPlayersSelection", "numPlayersText", isRandom && g_IsController);
    12941318
    12951319    let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
    12961320    hideControl("victoryCondition", "victoryConditionText", notScenario);
     1321    hideControl("wonderDuration", "wonderDurationText", notScenario);
    12971322    hideControl("populationCap", "populationCapText", notScenario);
    12981323    hideControl("startingResources", "startingResourcesText", notScenario);
    12991324    hideControl("ceasefire", "ceasefireText", notScenario);
    13001325    hideControl("revealMap", "revealMapText", notScenario);
    13011326    hideControl("exploreMap", "exploreMapText", notScenario);
    function updateGUIObjects()  
    13491374        pColorPickerHeading.hidden = !canChangeColors;
    13501375        if (canChangeColors)
    13511376            pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color));
    13521377    }
    13531378
     1379    resizeMoreOptionsWindow();
     1380
    13541381    g_IsInGuiUpdate = false;
    13551382
    13561383    // Game attributes include AI settings, so update the player list
    13571384    updatePlayerList();
    13581385
    function setMapDescription()  
    13671394{
    13681395    let numPlayers = g_GameAttributes.settings.PlayerData ? g_GameAttributes.settings.PlayerData.length : 0;
    13691396    let mapName = g_GameAttributes.map || "";
    13701397
    13711398    let victoryIdx = Math.max(0, g_VictoryConditions.Name.indexOf(g_GameAttributes.settings.GameType || ""));
    1372     let victoryTitle = g_VictoryConditions.Title[victoryIdx];
     1399    let victoryTitle;
     1400
     1401    if (g_VictoryConditions.Name[victoryIdx] == "wonder")
     1402        victoryTitle = sprintf(
     1403                translatePluralWithContext(
     1404                    "victory condition",
     1405                    "Wonder (%(min)s minute)",
     1406                    "Wonder (%(min)s minutes)",
     1407                    g_GameAttributes.settings.WonderDuration
     1408                ),
     1409                { "min": g_GameAttributes.settings.WonderDuration }
     1410        );
     1411    else
     1412        victoryTitle = g_VictoryConditions.Title[victoryIdx];
     1413
    13731414    if (victoryIdx != g_VictoryConditions.Default)
    13741415        victoryTitle = "[color=\"" + g_VictoryColor + "\"]" + victoryTitle + "[/color]";
    13751416
    13761417    let mapDescription = g_GameAttributes.settings.Description ? translate(g_GameAttributes.settings.Description) : translate("Sorry, no description available.");
    13771418    if (mapName == "random")
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    269269            <!-- End Options -->
    270270            </object>
    271271
    272272            <!-- More Options -->
    273273            <object hidden="true" name="moreOptionsFade" type="image" z="60" sprite="ModernFade"/>
    274             <object name="moreOptions" type="image" sprite="ModernDialog" size="50%-200 50%-195 50%+200 50%+220" z="70" hidden="true">
     274            <object name="moreOptions" type="image" sprite="ModernDialog" size="50%-200 50%-120 50%+200 50%+220" z="70" hidden="true">
    275275                <object style="ModernLabelText" type="text" size="50%-128 -18 50%+128 14">
    276276                    <translatableAttribute id="caption">More Options</translatableAttribute>
    277277                </object>
    278278
    279279                <object size="14 38 94% 66">
     
    324324                    <object name="ceasefire" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
    325325                        <translatableAttribute id="tooltip">Set time where no attacks are possible.</translatableAttribute>
    326326                    </object>
    327327                </object>
    328328
    329                 <object size="14 188 94% 216">
     329                <object name="optionWonderDuration" size="14 188 94% 216">
     330                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     331                        <translatableAttribute id="caption">Wonder:</translatableAttribute>
     332                    </object>
     333                    <object name="wonderDurationText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     334                    <object name="wonderDuration" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
     335                        <translatableAttribute id="tooltip">Number of minutes that the player has to keep the wonder in order to win.</translatableAttribute>
     336                    </object>
     337                </object>
     338
     339                <object size="14 218 94% 246">
    330340                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    331341                        <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute>
    332342                    </object>
    333343                    <object name="revealMapText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
    334344                    <object name="revealMap" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip">
    335345                        <translatableAttribute id="tooltip" comment="Make sure to differentiate between the revealed map and explored map options!">Toggle revealed map (see everything).</translatableAttribute>
    336346                    </object>
    337347                </object>
    338348
    339                 <object size="14 218 94% 246">
     349                <object size="14 248 94% 276">
    340350                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    341351                        <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Explored Map:</translatableAttribute>
    342352                    </object>
    343353                    <object name="exploreMapText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
    344354                    <object name="exploreMap" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip">
    345355                        <translatableAttribute id="tooltip" comment="Make sure to differentiate between the revealed map and explored map options!">Toggle explored map (see initial map).</translatableAttribute>
    346356                    </object>
    347357                </object>
    348358
    349                 <object size="14 248 94% 276">
     359                <object size="14 278 94% 306">
    350360                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    351361                        <translatableAttribute id="caption">Disable Treasures:</translatableAttribute>
    352362                    </object>
    353363                    <object name="disableTreasuresText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
    354364                    <object name="disableTreasures" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip">
    355365                        <translatableAttribute id="tooltip">Disable all treasures on the map.</translatableAttribute>
    356366                    </object>
    357367                </object>
    358368
    359                 <object size="14 278 94% 306">
     369                <object size="14 308 94% 336">
    360370                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    361371                        <translatableAttribute id="caption">Teams Locked:</translatableAttribute>
    362372                    </object>
    363373                    <object name="lockTeamsText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
    364374                    <object name="lockTeams" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip">
    365375                        <translatableAttribute id="tooltip">Toggle locked teams.</translatableAttribute>
    366376                    </object>
    367377                </object>
    368378
    369                 <object name="optionCheats" size="14 308 94% 336" hidden="true">
     379                <object name="optionCheats" size="14 338 94% 366" hidden="true">
    370380                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    371381                        <translatableAttribute id="caption">Cheats:</translatableAttribute>
    372382                    </object>
    373383                    <object name="enableCheatsText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
    374384                    <object name="enableCheats" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip">
    375385                        <translatableAttribute id="tooltip">Toggle the usability of cheats.</translatableAttribute>
    376386                    </object>
    377387                </object>
    378388
    379                 <object name="optionRating" size="14 338 94% 366" hidden="true">
     389                <object name="optionRating" size="14 368 94% 396" hidden="true">
    380390                    <object size="0 0 40% 28" hidden="false" type="text" style="ModernRightLabelText">
    381391                        <translatableAttribute id="caption">Rated Game:</translatableAttribute>
    382392                    </object>
    383393                    <object name="enableRatingText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
    384394                    <object name="enableRating" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip">
  • binaries/data/mods/public/gui/common/settings.js

    function loadSettingsValues()  
    3030{
    3131    var settings = {
    3232        "AIDescriptions": loadAIDescriptions(),
    3333        "AIDifficulties": loadAIDifficulties(),
    3434        "Ceasefire": loadCeasefire(),
     35        "WonderDurations": loadWonderDuration(),
    3536        "GameSpeeds": loadSettingValuesFile("game_speeds.json"),
    3637        "MapTypes": loadMapTypes(),
    3738        "MapSizes": loadSettingValuesFile("map_sizes.json"),
    3839        "PlayerDefaults": loadPlayerDefaults(),
    3940        "PopulationCapacities": loadPopulationCapacities(),
    function loadAIDifficulties()  
    129130        }
    130131    ];
    131132}
    132133
    133134/**
     135 * Loads available wonder-victory times
     136 */
     137function loadWonderDuration()
     138{
     139    var jsonFile = "wonder_times.json";
     140    var json = Engine.ReadJSONFile(g_SettingsDirectory + jsonFile);
     141
     142    if (!json || json.Default === undefined || !json.Times || !Array.isArray(json.Times))
     143    {
     144        error("Could not load " + jsonFile);
     145        return undefined;
     146    }
     147
     148    return json.Times.map(duration => ({
     149        "Duration": duration,
     150        "Default": duration == json.Default,
     151        "Title": sprintf(translatePluralWithContext("wonder victory", "%(min)s minute", "%(min)s minutes", duration), { "min": duration })
     152    }));
     153}
     154
     155/**
    134156 * Loads available ceasefire settings.
    135157 *
    136158 * @returns {Array|undefined}
    137159 */
    138160function loadCeasefire()
  • binaries/data/mods/public/simulation/helpers/Setup.js

    function LoadMapSettings(settings)  
    4747    }
    4848
    4949    var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
    5050    if (settings.GameType)
    5151        cmpEndGameManager.SetGameType(settings.GameType);
     52    if (settings.WonderDuration)
     53        cmpEndGameManager.SetWonderDuration(settings.WonderDuration * 60 * 1000);
    5254
    5355    if (settings.Garrison)
    5456    {
    5557        for (let holder in settings.Garrison)
    5658        {
  • binaries/data/mods/public/simulation/templates/template_structure_wonder.xml

     
    8888  </Vision>
    8989  <VisualActor>
    9090    <FoundationActor>structures/fndn_6x6.xml</FoundationActor>
    9191  </VisualActor>
    9292  <Wonder>
    93     <TimeTillVictory>300</TimeTillVictory>
     93    <DurationMultiplier>1</DurationMultiplier>
    9494  </Wonder>
    9595</Entity>
  • binaries/data/mods/public/simulation/components/Wonder.js

     
    11function Wonder() {}
    22
    33Wonder.prototype.Schema =
    4     "<element name='TimeTillVictory'>" +
    5         "<data type='nonNegativeInteger'/>" +
     4    "<element name='DurationMultiplier' a:help='A civ-specific time-bonus/handicap for the wonder-victory-condition.'>" +
     5        "<ref name='nonNegativeDecimal'/>" +
    66    "</element>";
    77
    88Wonder.prototype.Init = function()
    99{
    1010};
    1111
    1212Wonder.prototype.Serialize = null;
    1313
    14 Wonder.prototype.GetTimeTillVictory = function()
     14/**
     15 * Returns the number of minutes that a player has to keep the wonder in order to win.
     16 */
     17Wonder.prototype.GetVictoryDuration = function()
    1518{
    16     return +this.template.TimeTillVictory;
     19    var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
     20    return cmpEndGameManager.GetWonderDuration() * this.template.DurationMultiplier;
    1721};
    1822
    1923Engine.RegisterComponentType(IID_Wonder, "Wonder", Wonder);
  • binaries/data/mods/public/simulation/data/settings/wonder_times.json

     
     1{
     2    "Times": [1, 5, 10, 15, 20, 25, 30],
     3    "Default": 15
     4}
  • binaries/data/mods/public/maps/scripts/WonderVictory.js

    Trigger.prototype.CheckWonderVictory = f  
    2929    var players = [-1];
    3030    for (var i = 1; i < numPlayers; i++)
    3131        if (i != data.to)
    3232            players.push(i);
    3333
    34     var time = cmpWonder.GetTimeTillVictory()*1000;
     34    var time = cmpWonder.GetVictoryDuration();
    3535    messages.otherMessage = cmpGuiInterface.AddTimeNotification({
    3636        "message": markForTranslation("%(player)s will have won in %(time)s"),
    3737        "players": players,
    3838        "parameters": {"player": cmpPlayer.GetName()},
    3939        "translateMessage": true,