Index: binaries/data/mods/public/gui/gamesetup/gamesetup.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/gamesetup.js (revision 18341)
+++ binaries/data/mods/public/gui/gamesetup/gamesetup.js (working copy)
@@ -494,6 +494,7 @@
"ExploreMap": "exploreMap",
"DisableTreasures": "disableTreasures",
"LockTeams": "lockTeams",
+ "LastManStanding" : "lastManStanding",
"CheatsEnabled": "enableCheats"
};
@@ -511,6 +512,12 @@
Engine.GetGUIObjectByName("lockTeams").enabled = !this.checked;
updateGameAttributes();
};
+
+ Engine.GetGUIObjectByName("lockTeams").onPress = function() {
+ g_GameAttributes.settings.LockTeams = this.checked;
+ g_GameAttributes.settings.LastManStanding = !this.checked ? this.checked : !this.checked;
+ updateGameAttributes();
+ };
}
/**
@@ -1151,7 +1158,10 @@
}
if (g_GameAttributes.mapType == "scenario")
+ {
delete g_GameAttributes.settings.WonderDuration;
+ delete g_GameAttributes.settings.LastManStanding;
+ }
if (mapSettings.PlayerData)
sanitizePlayerData(mapSettings.PlayerData);
@@ -1362,6 +1372,7 @@
setGUIBoolean("exploreMap", "exploreMapText", !!mapSettings.ExploreMap);
setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap);
setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams);
+ setGUIBoolean("lastManStanding", "lastManStandingText", !!mapSettings.LastManStanding);
setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled);
Engine.GetGUIObjectByName("optionWonderDuration").hidden =
@@ -1372,6 +1383,7 @@
Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled;
Engine.GetGUIObjectByName("lockTeams").enabled = !mapSettings.RatingEnabled;
+ Engine.GetGUIObjectByName("optionLastManStanding").hidden = mapSettings.LockTeams;
// Mapsize completely hidden for non-random maps
let isRandom = g_GameAttributes.mapType == "random";
@@ -1384,7 +1396,7 @@
for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap",
"startingResources", "ceasefire", "revealMap",
- "exploreMap", "disableTreasures", "lockTeams"])
+ "exploreMap", "disableTreasures", "lockTeams", "lastManStanding"])
hideControl(ctrl, ctrl + "Text", notScenario);
Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario;
Index: binaries/data/mods/public/gui/gamesetup/gamesetup.xml
===================================================================
--- binaries/data/mods/public/gui/gamesetup/gamesetup.xml (revision 18341)
+++ binaries/data/mods/public/gui/gamesetup/gamesetup.xml (working copy)
@@ -386,8 +386,18 @@
-
-
+
Rated Game:
Index: binaries/data/mods/public/simulation/components/EndGameManager.js
===================================================================
--- binaries/data/mods/public/simulation/components/EndGameManager.js (revision 18341)
+++ binaries/data/mods/public/simulation/components/EndGameManager.js (working copy)
@@ -19,8 +19,9 @@
this.wonderDuration = 10 * 60 * 1000;
// Allied victory means allied players can win if victory conditions are met for each of them
- // Would be false for a "last man standing" game (when diplomacy is fully implemented)
+ // False for a "last man standing" game
this.alliedVictory = true;
+ this.noAlliesLeftMessage = {};
};
EndGameManager.prototype.GetGameType = function()
@@ -75,35 +76,89 @@
this.alliedVictory = flag;
};
-EndGameManager.prototype.OnGlobalPlayerDefeated = function(msg)
+function LastManStandingCheck(onlyAlliesLeft)
{
- if (msg.skip)
+ var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
+ var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
+ var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
+
+ if (!cmpGuiInterface || !cmpPlayerManager)
return;
- var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
- var cmpPlayers = [];
+ if (cmpEndGameManager.alliedVictory)
+ {
+ cmpGuiInterface.DeleteTimeNotification(cmpEndGameManager.noAlliesLeftMessage);
+ return;
+ }
+ if (!cmpEndGameManager.alliedVictory && onlyAlliesLeft)
+ {
+ cmpGuiInterface.DeleteTimeNotification(cmpEndGameManager.noAlliesLeftMessage);
+ cmpEndGameManager.noAlliesLeftMessage = cmpGuiInterface.AddTimeNotification({
+ "message": markForTranslation("Last player remaining wins."),
+ "translateMessage": true,
+ }, 90 * 60 * 1000);
+ }
+
+ else if (!cmpEndGameManager.alliedVictory && !onlyAlliesLeft)
+ cmpGuiInterface.DeleteTimeNotification(cmpEndGameManager.noAlliesLeftMessage);
+
+};
+
+function OnlyAlliesLeft(msg)
+{
+ var numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers();
var allies = [];
var onlyAlliesLeft = true;
- var numPlayers = cmpPlayerManager.GetNumPlayers();
+ var cmpPlayers = [];
for (var i = 1; i < numPlayers; ++i)
{
cmpPlayers[i] = QueryPlayerIDInterface(i);
- if (cmpPlayers[i].GetState() != "active" || i == msg.playerId)
+ if (cmpPlayers[i].GetState() != "active" || i == msg.playerId)
continue;
if (!allies.length || cmpPlayers[allies[0]].IsMutualAlly(i))
allies.push(i);
else
- onlyAlliesLeft = false;
+ return false;
}
+ return allies;
+}
+EndGameManager.prototype.OnInitGame = function(msg)
+{
+ LastManStandingCheck(OnlyAlliesLeft(msg));
+};
+
+EndGameManager.prototype.OnGlobalDiplomacyChanged = function(msg)
+{
+ LastManStandingCheck(OnlyAlliesLeft(msg));
+};
+
+EndGameManager.prototype.OnGlobalPlayerDefeated = function(msg)
+{
+ if (msg.skip)
+ return;
+
+ var numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers();
+ var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
+ var cmpPlayers = [];
+
+ for (var i = 1; i < numPlayers; ++i)
+ cmpPlayers[i] = QueryPlayerIDInterface(i);
+
+ let allies = OnlyAlliesLeft(msg);
+ LastManStandingCheck(allies);
+
// check if there are winners, or the game needs to continue
- if (!allies.length || !onlyAlliesLeft || !this.alliedVictory)
- return;
+ if (!allies.length || !allies ||
+ !this.alliedVictory && cmpPlayers.filter(pData => pData.GetState() == "active").length != 1)
+ return;
+ cmpGuiInterface.DeleteTimeNotification(this.noAlliesLeftMessage);
+
for (var p of allies)
cmpPlayers[p].SetState("won");
Index: binaries/data/mods/public/simulation/helpers/Setup.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Setup.js (revision 18341)
+++ binaries/data/mods/public/simulation/helpers/Setup.js (working copy)
@@ -51,6 +51,8 @@
cmpEndGameManager.SetGameType(settings.GameType);
if (settings.WonderDuration)
cmpEndGameManager.SetWonderDuration(settings.WonderDuration * 60 * 1000);
+ if (settings.LastManStanding)
+ cmpEndGameManager.SetAlliedVictory(false);
if (settings.Garrison)
{