Index: binaries/data/mods/public/gui/common/functions_utility.js
===================================================================
--- binaries/data/mods/public/gui/common/functions_utility.js (revision 18437)
+++ binaries/data/mods/public/gui/common/functions_utility.js (working copy)
@@ -211,42 +211,70 @@ function clearChatMessages()
}
}
/**
* Returns a formatted string describing the player assignments.
- * Including civs, teams, AI settings and player colors
- * which are given in data (array of objects per player).
+ * Needs g_CivData to translate!
*
+ * @param {object} playerDataArray - As known from gamesetup and simstate.
+ * @param {(string[]|false)} playerStates - One of "won", "defeated", "active" for each player.
* @returns {string}
*/
-function formatPlayerInfo(data)
+function formatPlayerInfo(playerDataArray, playerStates)
{
let playerDescriptions = {};
let playerIdx = 0;
- for (let playerData of data)
+
+ for (let playerData of playerDataArray)
{
+ if (playerData == null || playerData.Civ == "gaia")
+ continue;
+
++playerIdx;
let teamIdx = playerData.Team;
- let showDefeated = playerData.state && playerData.state == "defeated";
let isAI = playerData.AI && playerData.AI != "";
+ let playerState = playerStates && playerStates[playerIdx];
+ let isActive = !playerState || playerState == "active";
- let translated;
- if (!isAI && !showDefeated)
- translated = translateWithContext("replay", "%(playerName)s (%(civ)s)");
- else if (!isAI && showDefeated)
- translated = translateWithContext("replay", "%(playerName)s (%(civ)s, defeated)");
- else if (isAI && !showDefeated)
- translated = translateWithContext("replay", "%(playerName)s (%(civ)s, %(AIdifficulty)s %(AIname)s)");
+ let playerDescription;
+ if (isAI)
+ {
+ if (isActive)
+ playerDescription = translateWithContext("replay", "%(playerName)s (%(civ)s, %(AIdifficulty)s %(AIname)s, %(state)s)");
+ else
+ playerDescription = translateWithContext("replay", "%(playerName)s (%(civ)s, %(AIdifficulty)s %(AIname)s)");
+ }
else
- translated = translateWithContext("replay", "%(playerName)s (%(civ)s, %(AIdifficulty)s %(AIname)s, defeated)");
+ {
+ if (isActive)
+ playerDescription = translateWithContext("replay", "%(playerName)s (%(civ)s, %(state)s)");
+ else
+ playerDescription = translateWithContext("replay", "%(playerName)s (%(civ)s)");
+ }
// Sort player descriptions by team
if (!playerDescriptions[teamIdx])
playerDescriptions[teamIdx] = [];
- playerDescriptions[teamIdx].push(sprintf(translated, {
- "playerName": '[color="' + rgbToGuiColor(playerData.Color) + '"]' + escapeText(playerData.Name) + "[/color]",
- "civ": playerData.Civ,
+
+ playerDescriptions[teamIdx].push(sprintf(playerDescription, {
+ "playerName":
+ '[color="' +
+ rgbToGuiColor(playerData.Color || g_Settings.PlayerDefaults[playerIdx].Color) +
+ '"]' + escapeText(playerData.Name) + "[/color]",
+
+ "civ":
+ !playerData.Civ ?
+ translate("Unknown Civilization") :
+ g_CivData && g_CivData[playerData.Civ] && g_CivData[playerData.Civ].Name ?
+ translate(g_CivData[playerData.Civ].Name) :
+ playerData.Civ,
+
+ "state":
+ playerState == "defeated" ?
+ translateWithContext("playerState", "Defeated") :
+ translateWithContext("playerState", "Won"),
+
"AIname": isAI ? translateAIName(playerData.AI) : "",
"AIdifficulty": isAI ? translateAIDifficulty(playerData.AIDiff) : ""
}));
}
@@ -256,9 +284,16 @@ function formatPlayerInfo(data)
if (teams.length == 1)
return playerDescriptions[teams[0]].join("\n") + "\n";
// If there are teams, merge "Team N:" + playerDescriptions
return teams.map(team => {
- let teamCaption = (team == -1) ? translate("No Team") : sprintf(translate("Team %(team)s"), { "team": +team + 1 });
- return '[font="sans-bold-14"]' + teamCaption + "[/font]:\n" + playerDescriptions[team].join("\n");
+
+ let teamCaption = team == -1 ?
+ translate("No Team") :
+ sprintf(translate("Team %(team)s"), { "team": +team + 1 });
+
+ return sprintf(translateWithContext("replay", "%(team)s:\n%(playerDescriptions)s"), {
+ "team": '[font="sans-bold-14"]' + teamCaption + "[/font]",
+ "playerDescriptions": playerDescriptions[team].join("\n")
+ });
}).join("\n\n");
}
Index: binaries/data/mods/public/gui/replaymenu/replay_menu.js
===================================================================
--- binaries/data/mods/public/gui/replaymenu/replay_menu.js (revision 18437)
+++ binaries/data/mods/public/gui/replaymenu/replay_menu.js (working copy)
@@ -2,11 +2,11 @@
* Used for checking replay compatibility.
*/
const g_EngineInfo = Engine.GetEngineInfo();
/**
- * To show the titles of the selected civs in the replay details.
+ * Needed for formatPlayerInfo to show the player civs in the details.
*/
const g_CivData = loadCivData();
/**
* Used for creating the mapsize filter.
@@ -188,11 +188,10 @@ function displayReplayList()
if (replaySelection.selected != -1)
g_SelectedReplayDirectory = g_ReplaysFiltered[replaySelection.selected].directory;
filterReplays();
- // Create GUI list data
var list = g_ReplaysFiltered.map(replay => {
let works = replay.isCompatible;
return {
"directories": replay.directory,
"months": greyout(getReplayDateTime(replay), works),
@@ -202,11 +201,10 @@ function displayReplayList()
"durations": greyout(getReplayDuration(replay), works),
"playerNames": greyout(getReplayPlayernames(replay), works)
};
});
- // Extract arrays
if (list.length)
list = prepareForDropdown(list);
// Push to GUI
replaySelection.selected = -1;
@@ -219,43 +217,49 @@ function displayReplayList()
// Change these last, otherwise crash
replaySelection.list = list.directories || [];
replaySelection.list_data = list.directories || [];
- // Restore selection
replaySelection.selected = replaySelection.list.findIndex(directory => directory == g_SelectedReplayDirectory);
displayReplayDetails();
}
/**
* Shows preview image, description and player text in the right panel.
*/
function displayReplayDetails()
{
- var selected = Engine.GetGUIObjectByName("replaySelection").selected;
- var replaySelected = selected > -1;
+ let selected = Engine.GetGUIObjectByName("replaySelection").selected;
+ let replaySelected = selected > -1;
Engine.GetGUIObjectByName("replayInfo").hidden = !replaySelected;
Engine.GetGUIObjectByName("replayInfoEmpty").hidden = replaySelected;
Engine.GetGUIObjectByName("startReplayButton").enabled = replaySelected;
Engine.GetGUIObjectByName("deleteReplayButton").enabled = replaySelected;
Engine.GetGUIObjectByName("summaryButton").hidden = true;
if (!replaySelected)
return;
- var replay = g_ReplaysFiltered[selected];
- var mapData = getMapDescriptionAndPreview(replay.attribs.settings.mapType, replay.attribs.map);
+ let replay = g_ReplaysFiltered[selected];
- // Update GUI
Engine.GetGUIObjectByName("sgMapName").caption = translate(replay.attribs.settings.Name);
Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(replay.attribs.settings.Size);
Engine.GetGUIObjectByName("sgMapType").caption = translateMapType(replay.attribs.settings.mapType);
Engine.GetGUIObjectByName("sgVictory").caption = translateVictoryCondition(replay.attribs.settings.GameType);
Engine.GetGUIObjectByName("sgNbPlayers").caption = replay.attribs.settings.PlayerData.length;
- Engine.GetGUIObjectByName("sgPlayersNames").caption = getReplayTeamText(replay);
+
+ let metadata = Engine.GetReplayMetadata(replay.directory);
+ let mapData = getMapDescriptionAndPreview(replay.attribs.settings.mapType, replay.attribs.map);
+ let playerStates =
+ Engine.GetGUIObjectByName("showSpoiler").checked &&
+ metadata &&
+ metadata.playerStates &&
+ metadata.playerStates.map(pState => pState.state);
+
+ Engine.GetGUIObjectByName("sgPlayersNames").caption = formatPlayerInfo(replay.attribs.settings.PlayerData, playerStates);
Engine.GetGUIObjectByName("sgMapDescription").caption = mapData.description;
Engine.GetGUIObjectByName("summaryButton").hidden = !Engine.HasReplayMetadata(replay.directory);
setMapPreviewImage("sgMapPreview", mapData.preview);
}
@@ -329,39 +333,5 @@ function isReplayCompatible(replay)
*/
function replayHasSameEngineVersion(replay)
{
return replay.attribs.engine_version && replay.attribs.engine_version == g_EngineInfo.engine_version;
}
-
-/**
- * Returns a description of the player assignments.
- * Including civs, teams, AI settings and player colors.
- *
- * If the spoiler-checkbox is checked, it also shows defeated players.
- *
- * @returns {string}
- */
-function getReplayTeamText(replay)
-{
- // Load replay metadata
- const metadata = Engine.GetReplayMetadata(replay.directory);
- const spoiler = Engine.GetGUIObjectByName("showSpoiler").checked;
-
- let data = [];
- let playerIdx = 0;
- for (let playerData of replay.attribs.settings.PlayerData)
- {
- ++playerIdx;
- data.push({
- "Team": playerData.Team,
- "Name": playerData.Name,
- "Civ": !playerData.Civ ? translate("Unknown Civilization") :
- (g_CivData[playerData.Civ] && g_CivData[playerData.Civ].Name ? translate(g_CivData[playerData.Civ].Name) : playerData.Civ),
- "Color": playerData.Color ? playerData.Color : g_Settings.PlayerDefaults[playerIdx].Color,
- "AI": playerData.AI,
- "AIDiff": playerData.AIDiff,
- "Defeated": spoiler && metadata && metadata.playerStates && metadata.playerStates[playerIdx].state == "defeated"
- });
- }
-
- return formatPlayerInfo(data);
-}
Index: binaries/data/mods/public/gui/savedgames/load.js
===================================================================
--- binaries/data/mods/public/gui/savedgames/load.js (revision 18437)
+++ binaries/data/mods/public/gui/savedgames/load.js (working copy)
@@ -1,7 +1,12 @@
var g_SavedGamesMetadata = [];
+/**
+ * Needed for formatPlayerInfo to show the player civs in the details.
+ */
+const g_CivData = loadCivData();
+
function init()
{
let gameSelection = Engine.GetGUIObjectByName("gameSelection");
let savedGames = Engine.GetSavedGames().sort(sortDecreasingDate);
@@ -56,29 +61,14 @@ function selectionChanged()
let caption = sprintf(translate("Mods: %(mods)s"), { "mods": metadata.mods.join(translate(", ")) });
if (!hasSameMods(metadata, Engine.GetEngineInfo()))
caption = "[color=\"orange\"]" + caption + "[/color]";
Engine.GetGUIObjectByName("savedMods").caption = caption;
- let data = [];
- let playerIdx = 0;
- for (let playerData of metadata.initAttributes.settings.PlayerData)
- {
- if (playerData == null || playerData.Civ == "gaia")
- continue;
- ++playerIdx;
- data.push({
- "Team": playerData.Team,
- "Name": playerData.Name,
- "Civ": playerData.Civ,
- "Color": playerData.Color,
- "AI": playerData.AI,
- "AIDiff": playerData.AIDiff,
- "Defeated": metadata.gui.states && metadata.gui.states[playerIdx] == "defeated"
- });
- }
-
- Engine.GetGUIObjectByName("savedPlayersNames").caption = formatPlayerInfo(data);
+ Engine.GetGUIObjectByName("savedPlayersNames").caption = formatPlayerInfo(
+ metadata.initAttributes.settings.PlayerData,
+ metadata.gui.states
+ );
}
function loadGame()
{
let gameSelection = Engine.GetGUIObjectByName("gameSelection");
Index: binaries/data/mods/public/gui/savedgames/load.xml
===================================================================
--- binaries/data/mods/public/gui/savedgames/load.xml (revision 18437)
+++ binaries/data/mods/public/gui/savedgames/load.xml (working copy)
@@ -1,10 +1,11 @@
+
@@ -28,18 +29,11 @@
Engine.PopGuiPage();
Index: binaries/data/mods/public/maps/scripts/ConquestCommon.js
===================================================================
--- binaries/data/mods/public/maps/scripts/ConquestCommon.js (revision 18437)
+++ binaries/data/mods/public/maps/scripts/ConquestCommon.js (working copy)
@@ -23,12 +23,16 @@ Trigger.prototype.ConquestHandlerOwnerSh
let index = entities.indexOf(msg.entity);
if (index >= 0)
{
entities.splice(index, 1);
- if (!entities.length && Engine.QueryInterface(this.conquestEntitiesByPlayer[msg.from].player, IID_Player).GetState() == "active")
- Engine.PostMessage(this.conquestEntitiesByPlayer[msg.from].player, MT_PlayerDefeated, { "playerId": msg.from } );
+ if (!entities.length)
+ {
+ let cmpPlayer = QueryPlayerIDInterface(msg.from);
+ if (cmpPlayer)
+ cmpPlayer.SetState("defeated");
+ }
}
}
Trigger.prototype.ConquestAddStructure = function(msg)
{
Index: binaries/data/mods/public/maps/scripts/TriggerHelper.js
===================================================================
--- binaries/data/mods/public/maps/scripts/TriggerHelper.js (revision 18437)
+++ binaries/data/mods/public/maps/scripts/TriggerHelper.js (working copy)
@@ -112,11 +112,12 @@ TriggerHelper.GetResourceType = function
return cmpResourceSupply.GetType();
};
/**
- * Wins the game for a player
+ * The given player will win the game.
+ * If it's not a last man standing game, the allies will win too.
*/
TriggerHelper.SetPlayerWon = function(playerID)
{
let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
cmpEndGameManager.MarkPlayerAsWon(playerID);
@@ -125,14 +126,13 @@ TriggerHelper.SetPlayerWon = function(pl
/**
* Defeats a player
*/
TriggerHelper.DefeatPlayer = function(playerID)
{
- let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
- let playerEnt = cmpPlayerManager.GetPlayerByID(playerID);
-
- Engine.PostMessage(playerEnt, MT_PlayerDefeated, { "playerId": playerID } );
+ let cmpPlayer = QueryPlayerIDInterface(playerID);
+ if (cmpPlayer)
+ cmpPlayer.SetState("defeated");
};
/**
* Returns the number of current players
*/
Index: binaries/data/mods/public/simulation/components/EndGameManager.js
===================================================================
--- binaries/data/mods/public/simulation/components/EndGameManager.js (revision 18437)
+++ binaries/data/mods/public/simulation/components/EndGameManager.js (working copy)
@@ -1,8 +1,8 @@
/**
- * System component which regularly checks victory/defeat conditions
- * and if they are satisfied then it marks the player as victorious/defeated.
+ * System component to store the gametype, gametype settings and
+ * check for allied victory / last-man-standing.
*/
function EndGameManager() {}
EndGameManager.prototype.Schema =
"";
@@ -17,10 +17,14 @@ EndGameManager.prototype.Init = function
// Allied victory means allied players can win if victory conditions are met for each of them
// False for a "last man standing" game
this.alliedVictory = true;
+ // Don't do any checks before the diplomacies were set for each player
+ // or when marking a player as won.
+ this.skipAlliedVictoryCheck = true;
+
this.lastManStandingMessage = undefined;
};
EndGameManager.prototype.GetGameType = function()
{
@@ -39,48 +43,46 @@ EndGameManager.prototype.CheckGameType =
EndGameManager.prototype.SetGameType = function(newGameType, newSettings = {})
{
this.gameType = newGameType;
this.gameTypeSettings = newSettings;
+ this.skipAlliedVictoryCheck = false;
Engine.BroadcastMessage(MT_GameTypeChanged, {});
};
EndGameManager.prototype.MarkPlayerAsWon = function(playerID)
{
let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
let numPlayers = cmpPlayerManager.GetNumPlayers();
- for (let i = 1; i < numPlayers; ++i)
- {
- let playerEntityId = cmpPlayerManager.GetPlayerByID(i);
- let cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
+ this.skipAlliedVictoryCheck = true;
- if (cmpPlayer.GetState() != "active")
- continue;
+ // Group win/defeat messages
+ for (let won of [false, true])
+ for (let i = 1; i < numPlayers; ++i)
+ {
+ let cmpPlayer = QueryPlayerIDInterface(i);
+ let hasWon = playerID == i || this.alliedVictory && cmpPlayer.IsMutualAlly(playerID);
- if (playerID == cmpPlayer.GetPlayerID() || this.alliedVictory && cmpPlayer.IsMutualAlly(playerID))
- cmpPlayer.SetState("won");
- else
- Engine.PostMessage(playerEntityId, MT_PlayerDefeated, {
- "playerId": i,
- "skipAlliedVictoryCheck": true
- });
- }
+ if (hasWon == won)
+ cmpPlayer.SetState(won ? "won" : "defeated");
+ }
- // Reveal the map to all players
- let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
- cmpRangeManager.SetLosRevealAll(-1, true);
+ this.skipAlliedVictoryCheck = false;
};
EndGameManager.prototype.SetAlliedVictory = function(flag)
{
this.alliedVictory = flag;
};
EndGameManager.prototype.AlliedVictoryCheck = function()
{
+ if (this.skipAlliedVictoryCheck)
+ return;
+
let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
if (!cmpGuiInterface || !cmpPlayerManager)
return;
@@ -99,22 +101,16 @@ EndGameManager.prototype.AlliedVictoryCh
allies.push(playerID);
}
if (this.alliedVictory || allies.length == 1)
- {
for (let playerID of allies)
{
let cmpPlayer = QueryPlayerIDInterface(playerID);
if (cmpPlayer)
cmpPlayer.SetState("won");
}
-
- let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
- if (cmpRangeManager)
- cmpRangeManager.SetLosRevealAll(-1, true);
- }
else
this.lastManStandingMessage = cmpGuiInterface.AddTimeNotification({
"message": markForTranslation("Last remaining player wins."),
"translateMessage": true,
}, 12 * 60 * 60 * 1000); // 12 hours
@@ -125,16 +121,14 @@ EndGameManager.prototype.OnInitGame = fu
this.AlliedVictoryCheck();
};
EndGameManager.prototype.OnGlobalDiplomacyChanged = function(msg)
{
- if (!msg.skipAlliedVictoryCheck)
- this.AlliedVictoryCheck();
+ this.AlliedVictoryCheck();
};
EndGameManager.prototype.OnGlobalPlayerDefeated = function(msg)
{
- if (!msg.skipAlliedVictoryCheck)
- this.AlliedVictoryCheck();
+ this.AlliedVictoryCheck();
};
Engine.RegisterSystemComponentType(IID_EndGameManager, "EndGameManager", EndGameManager);
Index: binaries/data/mods/public/simulation/components/Player.js
===================================================================
--- binaries/data/mods/public/simulation/components/Player.js (revision 18437)
+++ binaries/data/mods/public/simulation/components/Player.js (working copy)
@@ -357,21 +357,74 @@ Player.prototype.SetTradingGoods = funct
Player.prototype.GetState = function()
{
return this.state;
};
-Player.prototype.SetState = function(newState)
+Player.prototype.SetState = function(newState, resign)
{
+ if (this.state != "active")
+ return;
+
+ if (newState != "won" && newState != "defeated")
+ {
+ warn("Can't change playerstate to " + this.state);
+ return;
+ }
+
this.state = newState;
+
+ let won = newState == "won";
+
+ // Reveal map to all or only that player
+ let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
+ cmpRangeManager.SetLosRevealAll(won ? -1 : this.playerID, true);
+
+ if (!won)
+ {
+ // Reassign all player's entities to Gaia
+ let entities = cmpRangeManager.GetEntitiesByPlayer(this.playerID);
+
+ // The ownership change is done in two steps so that entities don't hit idle
+ // (and thus possibly look for "enemies" to attack) before nearby allies get
+ // converted to Gaia as well.
+ for (let entity of entities)
+ {
+ let cmpOwnership = Engine.QueryInterface(entity, IID_Ownership);
+ cmpOwnership.SetOwnerQuiet(0);
+ }
+
+ // With the real ownership change complete, send OwnershipChanged messages.
+ for (let entity of entities)
+ Engine.PostMessage(entity, MT_OwnershipChanged, {
+ "entity": entity,
+ "from": this.playerID,
+ "to": 0
+ });
+ }
+
+ Engine.BroadcastMessage(won ? MT_PlayerWon : MT_PlayerDefeated, { "playerId": this.playerID });
+
+ let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
+ if (won)
+ cmpGUIInterface.PushNotification({
+ "type": "won",
+ "players": [this.playerID]
+ });
+ else
+ cmpGUIInterface.PushNotification({
+ "type": "defeat",
+ "players": [this.playerID],
+ "resign": resign
+ });
};
Player.prototype.GetTeam = function()
{
return this.team;
};
-Player.prototype.SetTeam = function(team, skipAlliedVictoryCheck = false)
+Player.prototype.SetTeam = function(team)
{
if (this.teamsLocked)
return;
this.team = team;
@@ -383,18 +436,17 @@ Player.prototype.SetTeam = function(team
{
let cmpPlayer = QueryPlayerIDInterface(i);
if (this.team != cmpPlayer.GetTeam())
continue;
- this.SetAlly(i, skipAlliedVictoryCheck);
- cmpPlayer.SetAlly(this.playerID, skipAlliedVictoryCheck);
+ this.SetAlly(i);
+ cmpPlayer.SetAlly(this.playerID);
}
Engine.BroadcastMessage(MT_DiplomacyChanged, {
"player": this.playerID,
- "otherPlayer": null,
- "skipAlliedVictoryCheck": skipAlliedVictoryCheck
+ "otherPlayer": null
});
};
Player.prototype.SetLockTeams = function(value)
{
@@ -409,22 +461,21 @@ Player.prototype.GetLockTeams = function
Player.prototype.GetDiplomacy = function()
{
return this.diplomacy;
};
-Player.prototype.SetDiplomacy = function(dipl, skipAlliedVictoryCheck = false)
+Player.prototype.SetDiplomacy = function(dipl)
{
this.diplomacy = dipl;
Engine.BroadcastMessage(MT_DiplomacyChanged, {
"player": this.playerID,
- "otherPlayer": null,
- "skipAlliedVictoryCheck": skipAlliedVictoryCheck
+ "otherPlayer": null
});
};
-Player.prototype.SetDiplomacyIndex = function(idx, value, skipAlliedVictoryCheck = false)
+Player.prototype.SetDiplomacyIndex = function(idx, value)
{
let cmpPlayer = QueryPlayerIDInterface(idx);
if (!cmpPlayer)
return;
@@ -433,17 +484,16 @@ Player.prototype.SetDiplomacyIndex = fun
this.diplomacy[idx] = value;
Engine.BroadcastMessage(MT_DiplomacyChanged, {
"player": this.playerID,
- "otherPlayer": cmpPlayer.GetPlayerID(),
- "skipAlliedVictoryCheck": skipAlliedVictoryCheck
+ "otherPlayer": cmpPlayer.GetPlayerID()
});
// Mutual worsening of relations
if (cmpPlayer.diplomacy[this.playerID] > value)
- cmpPlayer.SetDiplomacyIndex(this.playerID, value, skipAlliedVictoryCheck);
+ cmpPlayer.SetDiplomacyIndex(this.playerID, value);
};
Player.prototype.UpdateSharedLos = function()
{
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
@@ -518,13 +568,13 @@ Player.prototype.SetAI = function(flag)
Player.prototype.IsAI = function()
{
return this.isAI;
};
-Player.prototype.SetAlly = function(id, skipAlliedVictoryCheck = false)
+Player.prototype.SetAlly = function(id)
{
- this.SetDiplomacyIndex(id, 1, skipAlliedVictoryCheck);
+ this.SetDiplomacyIndex(id, 1);
};
/**
* Check if given player is our ally
*/
@@ -556,13 +606,13 @@ Player.prototype.IsMutualAlly = function
Player.prototype.IsExclusiveMutualAlly = function(id)
{
return this.playerID != id && this.IsMutualAlly(id);
};
-Player.prototype.SetEnemy = function(id, skipAlliedVictoryCheck = false)
+Player.prototype.SetEnemy = function(id)
{
- this.SetDiplomacyIndex(id, -1, skipAlliedVictoryCheck);
+ this.SetDiplomacyIndex(id, -1);
};
/**
* Get all enemies of a given player.
*/
@@ -581,13 +631,13 @@ Player.prototype.GetEnemies = function()
Player.prototype.IsEnemy = function(id)
{
return this.diplomacy[id] < 0;
};
-Player.prototype.SetNeutral = function(id, skipAlliedVictoryCheck = false)
+Player.prototype.SetNeutral = function(id)
{
- this.SetDiplomacyIndex(id, 0, skipAlliedVictoryCheck);
+ this.SetDiplomacyIndex(id, 0);
};
/**
* Check if given player is neutral
*/
@@ -647,47 +697,10 @@ Player.prototype.OnGlobalOwnershipChange
if (cmpIdentity && cmpIdentity.HasClass("Hero"))
this.heroes.push(msg.entity);
}
};
-Player.prototype.OnPlayerDefeated = function(msg)
-{
- this.state = "defeated";
-
- // Reassign all player's entities to Gaia
- var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
- var entities = cmpRangeManager.GetEntitiesByPlayer(this.playerID);
-
- // The ownership change is done in two steps so that entities don't hit idle
- // (and thus possibly look for "enemies" to attack) before nearby allies get
- // converted to Gaia as well.
- for (var entity of entities)
- {
- var cmpOwnership = Engine.QueryInterface(entity, IID_Ownership);
- cmpOwnership.SetOwnerQuiet(0);
- }
-
- // With the real ownership change complete, send OwnershipChanged messages.
- for (var entity of entities)
- Engine.PostMessage(entity, MT_OwnershipChanged, {
- "entity": entity,
- "from": this.playerID,
- "to": 0
- });
-
- // Reveal the map for this player.
- cmpRangeManager.SetLosRevealAll(this.playerID, true);
-
- // Send a chat message notifying of the player's defeat.
- var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
- cmpGUIInterface.PushNotification({
- "type": "defeat",
- "players": [this.playerID],
- "resign": !!msg.resign
- });
-};
-
Player.prototype.OnResearchFinished = function(msg)
{
if (msg.tech == this.template.SharedLosTech)
this.UpdateSharedLos();
else if (msg.tech == this.template.SharedDropsitesTech)
Index: binaries/data/mods/public/simulation/components/PlayerManager.js
===================================================================
--- binaries/data/mods/public/simulation/components/PlayerManager.js (revision 18437)
+++ binaries/data/mods/public/simulation/components/PlayerManager.js (working copy)
@@ -21,11 +21,11 @@ PlayerManager.prototype.AddPlayer = func
var cmpOtherPlayer = Engine.QueryInterface(this.GetPlayerByID(i), IID_Player);
cmpOtherPlayer.diplomacy[id] = -1;
newDiplo[i] = -1;
}
newDiplo[id] = 1;
- cmpPlayer.SetDiplomacy(newDiplo, true);
+ cmpPlayer.SetDiplomacy(newDiplo);
return id;
};
/**
Index: binaries/data/mods/public/simulation/components/interfaces/EndGameManager.js
===================================================================
--- binaries/data/mods/public/simulation/components/interfaces/EndGameManager.js (revision 18437)
+++ binaries/data/mods/public/simulation/components/interfaces/EndGameManager.js (working copy)
@@ -1,3 +1,4 @@
Engine.RegisterInterface("EndGameManager");
Engine.RegisterMessageType("PlayerDefeated");
+Engine.RegisterMessageType("PlayerWon");
Engine.RegisterMessageType("GameTypeChanged");
Index: binaries/data/mods/public/simulation/helpers/Cheat.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Cheat.js (revision 18437)
+++ binaries/data/mods/public/simulation/helpers/Cheat.js (working copy)
@@ -46,14 +46,13 @@ function Cheat(input)
else
Engine.DestroyEntity(ent);
}
return;
case "defeatplayer":
- var playerEnt = cmpPlayerManager.GetPlayerByID(input.parameter);
- if (playerEnt == INVALID_ENTITY)
- return;
- Engine.PostMessage(playerEnt, MT_PlayerDefeated, { "playerId": input.parameter });
+ cmpPlayer = QueryPlayerIDInterface(input.parameter);
+ if (cmpPlayer)
+ cmpPlayer.SetState("defeated");
return;
case "createunits":
var cmpProductionQueue = input.selected.length && Engine.QueryInterface(input.selected[0], IID_ProductionQueue);
if (!cmpProductionQueue)
{
Index: binaries/data/mods/public/simulation/helpers/Commands.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Commands.js (revision 18437)
+++ binaries/data/mods/public/simulation/helpers/Commands.js (working copy)
@@ -412,12 +412,13 @@ var g_Commands = {
}
},
"defeat-player": function(player, cmd, data)
{
- // Send "OnPlayerDefeated" message to player
- Engine.PostMessage(data.playerEnt, MT_PlayerDefeated, { "playerId": player, "resign": !!cmd.resign });
+ let cmpPlayer = QueryPlayerIDInterface(player);
+ if (cmpPlayer)
+ cmpPlayer.SetState("defeated", !!cmd.resign);
},
"garrison": function(player, cmd, data)
{
// Verify that the building can be controlled by the player or is mutualAlly
Index: binaries/data/mods/public/simulation/helpers/Player.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Player.js (revision 18437)
+++ binaries/data/mods/public/simulation/helpers/Player.js (working copy)
@@ -121,11 +121,11 @@ function LoadPlayerSettings(settings, ne
if (disabledTemplates.length)
cmpPlayer.SetDisabledTemplates(disabledTemplates);
// If diplomacy explicitly defined, use that; otherwise use teams
if (getSetting(playerData, playerDefaults, i, "Diplomacy") !== undefined)
- cmpPlayer.SetDiplomacy(getSetting(playerData, playerDefaults, i, "Diplomacy"), true);
+ cmpPlayer.SetDiplomacy(getSetting(playerData, playerDefaults, i, "Diplomacy"));
else
{
// Init diplomacy
var myTeam = getSetting(playerData, playerDefaults, i, "Team");
@@ -135,11 +135,11 @@ function LoadPlayerSettings(settings, ne
if (i == j)
cmpPlayer.SetAlly(j);
else
cmpPlayer.SetEnemy(j);
}
- cmpPlayer.SetTeam(myTeam === undefined ? -1 : myTeam, true);
+ cmpPlayer.SetTeam(myTeam === undefined ? -1 : myTeam);
}
// If formations explicitly defined, use that; otherwise use civ defaults
var formations = getSetting(playerData, playerDefaults, i, "Formations");
if (formations !== undefined)