diff --git a/binaries/data/mods/public/gui/session/messages.js b/binaries/data/mods/public/gui/session/messages.js index aa3be1dd90..dd875274a6 100644 --- a/binaries/data/mods/public/gui/session/messages.js +++ b/binaries/data/mods/public/gui/session/messages.js @@ -117,6 +117,12 @@ var g_NotificationsTypes = if (player == Engine.GetPlayerID()) openDialog(notification.dialogName, notification.data, player); }, + "resetselectionpannel": function(notification, player) + { + if (player != Engine.GetPlayerID()) + return; + g_Selection.rebuildSelection([]); + } }; // Notifications diff --git a/binaries/data/mods/public/maps/random/survivalofthefittest.json b/binaries/data/mods/public/maps/random/survivalofthefittest.json index 457f23f708..67a2892b45 100644 --- a/binaries/data/mods/public/maps/random/survivalofthefittest.json +++ b/binaries/data/mods/public/maps/random/survivalofthefittest.json @@ -6,7 +6,6 @@ "BaseTerrain" : ["medit_sea_depths"], "BaseHeight" : 30, "CircularMap" : true, - "Keywords": ["demo"], "TriggerScripts": [ "scripts/TriggerHelper.js", "random/survivalofthefittest_triggers.js" diff --git a/binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js b/binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js index 08da0c04a8..6076d990d8 100644 --- a/binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js +++ b/binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js @@ -100,6 +100,16 @@ Trigger.prototype.InitGame = function() } } + // Fix alliances + for (var i = 1; i < numberOfPlayers; ++i) + { + var cmpPlayer = TriggerHelper.GetPlayerComponent(i); + for (var j = 1; j < numberOfPlayers; ++j) + if (i != j) + cmpPlayer.SetAlly(j); + cmpPlayer.SetLockTeams(true); + } + // make gaia black TriggerHelper.GetPlayerComponent(0).SetColour(0, 0, 0); @@ -133,22 +143,24 @@ Trigger.prototype.DefeatPlayerOnceCCIsDestroyed = function(data) { // Defeat a player that has lost his civic center if (data.entity == cmpTrigger.playerCivicCenter[data.from] && data.to == -1) + { TriggerHelper.DefeatPlayer(data.from); - // Check if only one player remains. He will be the winner. - var lastPlayerStanding = 0; - var numPlayersStanding = 0; - var numberOfPlayers = TriggerHelper.GetNumberOfPlayers(); - for (var i = 1; i < numberOfPlayers; ++i) - { - if (TriggerHelper.GetPlayerComponent(i).GetState() == "active") + // Check if only one player remains. He will be the winner. + var lastPlayerStanding = 0; + var numPlayersStanding = 0; + var numberOfPlayers = TriggerHelper.GetNumberOfPlayers(); + for (var i = 1; i < numberOfPlayers; ++i) { - lastPlayerStanding = i; - ++numPlayersStanding; + if (TriggerHelper.GetPlayerComponent(i).GetState() == "active") + { + lastPlayerStanding = i; + ++numPlayersStanding; + } } + if (numPlayersStanding == 1) + TriggerHelper.SetPlayerWon(lastPlayerStanding); } - if (numPlayersStanding == 1) - TriggerHelper.SetPlayerWon(lastPlayerStanding); } var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); diff --git a/binaries/data/mods/public/simulation/components/Builder.js b/binaries/data/mods/public/simulation/components/Builder.js index e0e1112647..a8dfe0da77 100644 --- a/binaries/data/mods/public/simulation/components/Builder.js +++ b/binaries/data/mods/public/simulation/components/Builder.js @@ -35,6 +35,14 @@ Builder.prototype.GetEntitiesList = function() if (cmpIdentity) string = string.replace(/\{civ\}/g, cmpIdentity.GetCiv()); entities = string.split(/\s+/); + + // Remove disabled entities + var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player) + var disabledEntities = cmpPlayer.GetDisabledTemplates(); + + for (var i = entities.length - 1; i >= 0; --i) + if (disabledEntities[entities[i]]) + entities.splice(i, 1); } return entities; }; diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index b636cee5ba..d84e3e3b97 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -42,6 +42,7 @@ Player.prototype.Init = function() "metal": markForTranslation("Metal"), "stone": markForTranslation("Stone"), } + this.disabledTemplates = {}; }; Player.prototype.SetPlayerID = function(id) @@ -699,4 +700,33 @@ Player.prototype.TributeResource = function(player, amounts) cmpGUIInterface.PushNotification(notification); }; +Player.prototype.AddDisabledTemplate = function(template) +{ + this.disabledTemplates[template] = true; + Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {}); + var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); + cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]}); +}; + +Player.prototype.RemoveDisabledTemplate = function(template) +{ + this.disabledTemplates[template] = false; + Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {}); + var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); + cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]}); +}; + +Player.prototype.SetDisabledTemplates = function(templates) +{ + this.disabledTemplates = templates; + Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {}); + var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); + cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]}); +}; + +Player.prototype.GetDisabledTemplates = function(templates) +{ + return this.disabledTemplates; +}; + Engine.RegisterComponentType(IID_Player, "Player", Player); diff --git a/binaries/data/mods/public/simulation/components/ProductionQueue.js b/binaries/data/mods/public/simulation/components/ProductionQueue.js index dd6851304a..479f56f070 100644 --- a/binaries/data/mods/public/simulation/components/ProductionQueue.js +++ b/binaries/data/mods/public/simulation/components/ProductionQueue.js @@ -103,7 +103,15 @@ ProductionQueue.prototype.CalculateEntitiesList = function() string = string.replace(/\{civ\}/g, cmpIdentity.GetCiv()); var entitiesList = string.split(/\s+/); - + + // Remove disabled entities + var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player) + var disabledEntities = cmpPlayer.GetDisabledTemplates(); + + for (var i = entitiesList.length - 1; i >= 0; --i) + if (disabledEntities[entitiesList[i]]) + entitiesList.splice(i, 1); + // check if some templates need to show their advanced or elite version var upgradeTemplate = function(templateName) { @@ -120,7 +128,7 @@ ProductionQueue.prototype.CalculateEntitiesList = function() }; var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); - var playerID = QueryOwnerInterface(this.entity, IID_Player).GetPlayerID(); + var playerID = cmpPlayer.GetPlayerID(); for each (var templateName in entitiesList) this.entitiesList.push(upgradeTemplate(templateName)); for each (var item in this.queue) @@ -785,4 +793,11 @@ ProductionQueue.prototype.OnValueModification = function(msg) this.CalculateEntitiesList(); }; +ProductionQueue.prototype.OnDisabledTemplatesChanged = function(msg) +{ + // if the disabled templates of the player is changed, + // update the entities list so that this is reflected there + this.CalculateEntitiesList(); +}; + Engine.RegisterComponentType(IID_ProductionQueue, "ProductionQueue", ProductionQueue);