Ticket #3970: lastmanstanding_v3.patch
File lastmanstanding_v3.patch, 8.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/gamesetup/gamesetup.js
494 494 "ExploreMap": "exploreMap", 495 495 "DisableTreasures": "disableTreasures", 496 496 "LockTeams": "lockTeams", 497 "LastManStanding" : "lastManStanding", 497 498 "CheatsEnabled": "enableCheats" 498 499 }; 499 500 … … 511 512 Engine.GetGUIObjectByName("lockTeams").enabled = !this.checked; 512 513 updateGameAttributes(); 513 514 }; 515 Engine.GetGUIObjectByName("lockTeams").onPress = function() { 516 g_GameAttributes.settings.LockTeams = this.checked; 517 g_GameAttributes.settings.LastManStanding = !this.checked; 518 updateGameAttributes(); 519 }; 514 520 } 515 521 516 522 /** … … 1151 1157 } 1152 1158 1153 1159 if (g_GameAttributes.mapType == "scenario") 1160 { 1154 1161 delete g_GameAttributes.settings.WonderDuration; 1162 delete g_GameAttributes.settings.LastManStanding; 1163 } 1155 1164 1156 1165 if (mapSettings.PlayerData) 1157 1166 sanitizePlayerData(mapSettings.PlayerData); … … 1362 1371 setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap); 1363 1372 setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap); 1364 1373 setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); 1374 setGUIBoolean("lastManStanding", "lastManStandingText", !!mapSettings.LastManStanding); 1365 1375 setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); 1366 1376 1367 1377 Engine.GetGUIObjectByName("optionWonderDuration").hidden = … … 1372 1382 1373 1383 Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled; 1374 1384 Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled; 1385 Engine.GetGUIObjectByName("optionLastManStanding").hidden = mapSettings.LockTeams; 1375 1386 1376 1387 // Mapsize completely hidden for non-random maps 1377 1388 let isRandom = g_GameAttributes.mapType == "random"; … … 1384 1395 1385 1396 for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap", 1386 1397 "startingResources", "ceasefire", "revealMap", 1387 "exploreMap", "disableTreasures", "lockTeams" ])1398 "exploreMap", "disableTreasures", "lockTeams", "lastManStanding"]) 1388 1399 hideControl(ctrl, ctrl + "Text", notScenario); 1389 1400 1390 1401 Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario; -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
386 386 </object> 387 387 </object> 388 388 389 <object name="option Cheats" size="14 338 94% 366" hidden="true">389 <object name="optionLastManStanding" size="14 338 94% 366"> 390 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> 398 399 <object name="optionCheats" size="14 368 94% 396" hidden="true"> 400 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 391 401 <translatableAttribute id="caption">Cheats:</translatableAttribute> 392 402 </object> 393 403 <object name="enableCheatsText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> … … 396 406 </object> 397 407 </object> 398 408 399 <object name="optionRating" size="14 3 68 94% 396" hidden="true">409 <object name="optionRating" size="14 398 94% 426" hidden="true"> 400 410 <object size="0 0 40% 28" hidden="false" type="text" style="ModernRightLabelText"> 401 411 <translatableAttribute id="caption">Rated Game:</translatableAttribute> 402 412 </object> -
binaries/data/mods/public/simulation/components/EndGameManager.js
19 19 this.wonderDuration = 10 * 60 * 1000; 20 20 21 21 // 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 23 23 this.alliedVictory = true; 24 this.disabledAlliedVictoryMessages = {}; 24 25 }; 25 26 26 27 EndGameManager.prototype.GetGameType = function() … … 75 76 this.alliedVictory = flag; 76 77 }; 77 78 79 function DisableAlliedVictoryCheck(msg) 80 { 81 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 82 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 83 var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager) 84 var cmpPlayers = []; 85 var messages = cmpEndGameManager.disabledAlliedVictoryMessages || {}; 86 var allies = []; 87 var onlyAlliesLeft = true; 88 89 var numPlayers = cmpPlayerManager.GetNumPlayers(); 90 91 for (var i = 1; i < numPlayers; ++i) 92 { 93 cmpPlayers[i] = QueryPlayerIDInterface(i); 94 if (cmpPlayers[i].GetState() != "active" || i == msg.playerId) 95 continue; 96 97 if (!allies.length || cmpPlayers[allies[0]].IsMutualAlly(i)) 98 allies.push(i); 99 else 100 onlyAlliesLeft = false; 101 } 102 if (!cmpEndGameManager.alliedVictory && onlyAlliesLeft) 103 { 104 if (messages.noAlliesLeftMessage) 105 cmpGuiInterface.DeleteTimeNotification(messages.noAlliesLeftMessage); 106 messages.noAlliesLeftMessage = cmpGuiInterface.AddTimeNotification({ 107 "message": markForTranslation("Last player remaining wins"), 108 "translateMessage": true, 109 }, 10 * 60 * 9000); 110 } 111 else if (!cmpEndGameManager.alliedVictory && !onlyAlliesLeft) 112 if (messages.noAlliesLeftMessage) 113 cmpGuiInterface.DeleteTimeNotification(messages.noAlliesLeftMessage); 114 115 cmpEndGameManager.disabledAlliedVictoryMessages = messages; 116 }; 117 118 EndGameManager.prototype.OnInitGame = function(msg) 119 { 120 DisableAlliedVictoryCheck(msg); 121 }; 122 123 EndGameManager.prototype.OnGlobalDiplomacyChanged = function(msg) 124 { 125 DisableAlliedVictoryCheck(msg); 126 }; 127 78 128 EndGameManager.prototype.OnGlobalPlayerDefeated = function(msg) 79 129 { 80 130 if (msg.skip) … … 81 131 return; 82 132 83 133 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 134 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 84 135 var cmpPlayers = []; 85 136 137 var messages = this.disabledAlliedVictoryMessages || {}; 86 138 var allies = []; 87 139 var onlyAlliesLeft = true; 88 140 … … 100 152 onlyAlliesLeft = false; 101 153 } 102 154 155 if (!this.alliedVictory && onlyAlliesLeft) 156 { 157 if (messages.noAlliesLeftMessage) 158 cmpGuiInterface.DeleteTimeNotification(messages.noAlliesLeftMessage); 159 messages.noAlliesLeftMessage = cmpGuiInterface.AddTimeNotification({ 160 "message": markForTranslation("Last player remaining wins"), 161 "translateMessage": true, 162 }, 10 * 60 * 9000); 163 } 164 this.disabledAlliedVictoryMessages = messages; 165 103 166 // check if there are winners, or the game needs to continue 104 if (!allies.length || !onlyAlliesLeft || !this.alliedVictory) 105 return; 167 if (!allies.length || !onlyAlliesLeft || 168 !this.alliedVictory && cmpPlayers.filter(pData => pData.GetState() == "active").length != 1) 169 return; 170 if (messages.noAlliesLeftMessage) 171 cmpGuiInterface.DeleteTimeNotification(messages.noAlliesLeftMessage); 106 172 107 173 for (var p of allies) 108 174 cmpPlayers[p].SetState("won"); -
binaries/data/mods/public/simulation/helpers/Setup.js
51 51 cmpEndGameManager.SetGameType(settings.GameType); 52 52 if (settings.WonderDuration) 53 53 cmpEndGameManager.SetWonderDuration(settings.WonderDuration * 60 * 1000); 54 if (settings.LastManStanding) 55 cmpEndGameManager.SetAlliedVictory(false); 54 56 55 57 if (settings.Garrison) 56 58 {