Ticket #52: DisablingTemplatesByTriggers.2.patch
File DisablingTemplatesByTriggers.2.patch, 6.6 KB (added by , 10 years ago) |
---|
-
public/gui/session/messages.js
117 117 if (player == Engine.GetPlayerID()) 118 118 openDialog(notification.dialogName, notification.data, player); 119 119 }, 120 "resetselectionpannel": function(notification, player) 121 { 122 if (player != Engine.GetPlayerID()) 123 return; 124 g_Selection.rebuildSelection([]); 125 } 120 126 }; 121 127 122 128 // Notifications -
public/maps/random/survivalofthefittest_triggers.js
100 100 } 101 101 } 102 102 103 // Fix alliances 104 for (var i = 1; i < numberOfPlayers; ++i) 105 { 106 var cmpPlayer = TriggerHelper.GetPlayerComponent(i); 107 for (var j = 1; j < numberOfPlayers; ++j) 108 if (i != j) 109 cmpPlayer.SetAlly(j); 110 cmpPlayer.SetLockTeams(true); 111 } 112 103 113 // make gaia black 104 114 TriggerHelper.GetPlayerComponent(0).SetColour(0, 0, 0); 105 115 … … 133 143 { 134 144 // Defeat a player that has lost his civic center 135 145 if (data.entity == cmpTrigger.playerCivicCenter[data.from] && data.to == -1) 146 { 136 147 TriggerHelper.DefeatPlayer(data.from); 137 148 138 // Check if only one player remains. He will be the winner. 139 var lastPlayerStanding = 0; 140 var numPlayersStanding = 0; 141 var numberOfPlayers = TriggerHelper.GetNumberOfPlayers(); 142 for (var i = 1; i < numberOfPlayers; ++i) 143 { 144 if (TriggerHelper.GetPlayerComponent(i).GetState() == "active") 149 // Check if only one player remains. He will be the winner. 150 var lastPlayerStanding = 0; 151 var numPlayersStanding = 0; 152 var numberOfPlayers = TriggerHelper.GetNumberOfPlayers(); 153 for (var i = 1; i < numberOfPlayers; ++i) 145 154 { 146 lastPlayerStanding = i; 147 ++numPlayersStanding; 155 if (TriggerHelper.GetPlayerComponent(i).GetState() == "active") 156 { 157 lastPlayerStanding = i; 158 ++numPlayersStanding; 159 } 148 160 } 161 if (numPlayersStanding == 1) 162 TriggerHelper.SetPlayerWon(lastPlayerStanding); 149 163 } 150 if (numPlayersStanding == 1)151 TriggerHelper.SetPlayerWon(lastPlayerStanding);152 164 } 153 165 154 166 var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); -
public/simulation/components/Builder.js
35 35 if (cmpIdentity) 36 36 string = string.replace(/\{civ\}/g, cmpIdentity.GetCiv()); 37 37 entities = string.split(/\s+/); 38 39 // Remove disabled entities 40 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player) 41 var disabledEntities = cmpPlayer.GetDisabledTemplates(); 42 43 for (var i = entities.length - 1; i >= 0; --i) 44 if (disabledEntities[entities[i]]) 45 entities.splice(i, 1); 38 46 } 39 47 return entities; 40 48 }; -
public/simulation/components/Player.js
42 42 "metal": markForTranslation("Metal"), 43 43 "stone": markForTranslation("Stone"), 44 44 } 45 this.disabledTemplates = {}; 45 46 }; 46 47 47 48 Player.prototype.SetPlayerID = function(id) … … 699 700 cmpGUIInterface.PushNotification(notification); 700 701 }; 701 702 703 Player.prototype.AddDisabledTemplate = function(template) 704 { 705 this.disabledTemplates[template] = true; 706 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 707 var ents = cmpRangeManager.GetEntitiesByPlayer(this.playerID); 708 Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {}); 709 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 710 cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]}); 711 }; 712 713 Player.prototype.RemoveDisabledTemplate = function(template) 714 { 715 this.disabledTemplates[template] = false; 716 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 717 var ents = cmpRangeManager.GetEntitiesByPlayer(this.playerID); 718 Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {}); 719 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 720 cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]}); 721 }; 722 723 Player.prototype.SetDisabledTemplates = function(templates) 724 { 725 this.disabledTemplates = templates; 726 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 727 var ents = cmpRangeManager.GetEntitiesByPlayer(this.playerID); 728 Engine.BroadcastMessage(MT_DisabledTemplatesChanged, {}); 729 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 730 cmpGuiInterface.PushNotification({"type": "resetselectionpannel", "players": [this.GetPlayerID()]}); 731 }; 732 733 Player.prototype.GetDisabledTemplates = function(templates) 734 { 735 return this.disabledTemplates; 736 }; 737 702 738 Engine.RegisterComponentType(IID_Player, "Player", Player); -
public/simulation/components/ProductionQueue.js
103 103 string = string.replace(/\{civ\}/g, cmpIdentity.GetCiv()); 104 104 105 105 var entitiesList = string.split(/\s+/); 106 106 107 // Remove disabled entities 108 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player) 109 var disabledEntities = cmpPlayer.GetDisabledTemplates(); 110 111 for (var i = entitiesList.length - 1; i >= 0; --i) 112 if (disabledEntities[entitiesList[i]]) 113 entitiesList.splice(i, 1); 114 107 115 // check if some templates need to show their advanced or elite version 108 116 var upgradeTemplate = function(templateName) 109 117 { … … 120 128 }; 121 129 122 130 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 123 var playerID = QueryOwnerInterface(this.entity, IID_Player).GetPlayerID();131 var playerID = cmpPlayer.GetPlayerID(); 124 132 for each (var templateName in entitiesList) 125 133 this.entitiesList.push(upgradeTemplate(templateName)); 126 134 for each (var item in this.queue) … … 785 793 this.CalculateEntitiesList(); 786 794 }; 787 795 796 ProductionQueue.prototype.OnDisabledTemplatesChanged = function(msg) 797 { 798 // if the disabled templates of the player is changed, 799 // update the entities list so that this is reflected there 800 this.CalculateEntitiesList(); 801 }; 802 788 803 Engine.RegisterComponentType(IID_ProductionQueue, "ProductionQueue", ProductionQueue);