Ticket #3970: lastmanstanding_v2.patch

File lastmanstanding_v2.patch, 6.7 KB (added by Sandarac, 8 years ago)

All code in EndGameManager.js is called in OnGlobalPlayerDefeated()

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

     
    353353        "optionExploreMap",
    354354        "optionDisableTreasures",
    355355        "optionLockTeams",
     356        "optionLastManStanding",
    356357        "optionCheats",
    357358        "optionRating",
    358359        "hideMoreOptions"
     
    508509        "ExploreMap": "exploreMap",
    509510        "DisableTreasures": "disableTreasures",
    510511        "LockTeams": "lockTeams",
     512        "LastManStanding" : "lastManStanding",
    511513        "CheatsEnabled": "enableCheats"
    512514    };
    513515
     
    525527        Engine.GetGUIObjectByName("lockTeams").enabled = !this.checked;
    526528        updateGameAttributes();
    527529    };
     530    Engine.GetGUIObjectByName("lockTeams").onPress = function() {
     531        g_GameAttributes.settings.LockTeams = this.checked;
     532        g_GameAttributes.settings.LastManStanding = !this.checked;
     533        hideControl("lastManStanding", "lastManStandingText", !g_GameAttributes.settings.LockTeams);
     534        updateGameAttributes();
     535    };
    528536}
    529537
    530538/**
     
    11731181
    11741182    if (g_GameAttributes.mapType == "scenario")
    11751183        delete g_GameAttributes.settings.WonderDuration;
     1184        delete g_GameAttributes.settings.LastManStanding;
    11761185
    11771186    if (mapSettings.PlayerData)
    11781187        sanitizePlayerData(mapSettings.PlayerData);
     
    13711380    setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap);
    13721381    setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap);
    13731382    setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams);
     1383    setGUIBoolean("lastManStanding", "lastManStandingText", !!mapSettings.LastManStanding);
    13741384    setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled);
    13751385
    13761386    Engine.GetGUIObjectByName("optionWonderDuration").hidden =
     
    13811391
    13821392    Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled;
    13831393    Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled;
     1394    Engine.GetGUIObjectByName("lastManStandingText").hidden = mapSettings.LockTeams;
    13841395
    13851396    // Mapsize completely hidden for non-random maps
    13861397    let isRandom = g_GameAttributes.mapType == "random";
     
    13891400    Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController;
    13901401    hideControl("numPlayers", "numPlayersText", isRandom && g_IsController);
    13911402
    1392     let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
     1403    let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController;
    13931404
    13941405    for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap",
    13951406                      "startingResources", "ceasefire", "revealMap",
    13961407                      "exploreMap", "disableTreasures", "lockTeams"])
    13971408        hideControl(ctrl, ctrl + "Text", notScenario);
     1409    hideControl("lastManStanding", "lastManStandingText", !mapSettings.LockTeams && notScenario);
    13981410
    13991411    Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario;
    14001412
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    385385                        <translatableAttribute id="tooltip">Toggle locked teams.</translatableAttribute>
    386386                    </object>
    387387                </object>
     388               
     389                <object name="optionLastManStanding" size="14 338 94% 366">
     390                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     391                        <translatableAttribute id="caption">Last Man Standing:</translatableAttribute>
     392                    </object>
     393                    <object name="lastManStandingText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/>
     394                    <object name="lastManStanding" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip">
     395                        <translatableAttribute id="tooltip">Toggle if only one player can win (disables allied victory).</translatableAttribute>
     396                    </object>
     397                </object>
    388398
    389                 <object name="optionCheats" size="14 338 94% 366" hidden="true">
     399                <object name="optionCheats" size="14 368 94% 396" hidden="true">
    390400                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    391401                        <translatableAttribute id="caption">Cheats:</translatableAttribute>
    392402                    </object>
     
    396406                    </object>
    397407                </object>
    398408
    399                 <object name="optionRating" size="14 368 94% 396" hidden="true">
     409                <object name="optionRating" size="14 398 94% 426" hidden="true">
    400410                    <object size="0 0 40% 28" hidden="false" type="text" style="ModernRightLabelText">
    401411                        <translatableAttribute id="caption">Rated Game:</translatableAttribute>
    402412                    </object>
  • binaries/data/mods/public/simulation/components/EndGameManager.js

     
    1919    this.wonderDuration = 10 * 60 * 1000;
    2020
    2121    // Allied victory means allied players can win if victory conditions are met for each of them
    22     // Would be false for a "last man standing" game (when diplomacy is fully implemented)
     22    // False for a "last man standing" game
    2323    this.alliedVictory = true;
    2424};
    2525
     
    8181        return;
    8282
    8383    var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     84    var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    8485    var cmpPlayers = [];
    8586
    8687    var allies = [];
     
    100101            onlyAlliesLeft = false;
    101102    }
    102103
     104    if (!this.alliedVictory && onlyAlliesLeft)
     105        cmpGUIInterface.PushNotification({
     106            "message": markForTranslation("Last player remaining wins"),
     107            "translateMessage": true
     108        });
     109
    103110    // check if there are winners, or the game needs to continue
    104     if (!allies.length || !onlyAlliesLeft || !this.alliedVictory)
    105         return;
     111    if (!allies.length || !onlyAlliesLeft ||
     112        !this.alliedVictory && cmpPlayers.filter(pData => pData.GetState() == "active").length != 1)
     113        return;
    106114
    107115    for (var p of allies)
    108116        cmpPlayers[p].SetState("won");
  • binaries/data/mods/public/simulation/helpers/Setup.js

     
    5151        cmpEndGameManager.SetGameType(settings.GameType);
    5252    if (settings.WonderDuration)
    5353        cmpEndGameManager.SetWonderDuration(settings.WonderDuration * 60 * 1000);
     54    if (settings.LastManStanding)
     55        cmpEndGameManager.SetAlliedVictory(false);
    5456
    5557    if (settings.Garrison)
    5658    {