Ticket #565: Victory_conditions.diff
File Victory_conditions.diff, 10.9 KB (added by , 14 years ago) |
---|
-
binaries/data/mods/public/gui/page_summary.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <page> 3 <include>common/setup.xml</include> 4 <include>common/styles.xml</include> 5 <include>common/sprite1.xml</include> 6 <include>common/init.xml</include> 7 <include>summary/summary.xml</include> 8 <include>common/global.xml</include> 9 </page> -
binaries/data/mods/public/gui/session_new/session.js
86 86 87 87 function onTick() 88 88 { 89 checkPlayerState(); 90 89 91 while (true) 90 92 { 91 93 var message = Engine.PollNetworkClient(); … … 119 121 getGUIObjectByName("resourcePop").textcolor = "0 0 0"; 120 122 } 121 123 124 function gotoSummary(/*string*/ gameResult) 125 { 126 stopMusic(); 127 endGame(); 128 Engine.SwitchGuiPage("page_summary.xml", { "gameResult" : gameResult }); 129 } 130 131 function checkPlayerState() 132 { 133 var simState = Engine.GuiInterfaceCall("GetSimulationState"); 134 var playerState = simState.players[Engine.GetPlayerID()]; 135 136 if (playerState.state == simState.player_states.DEFEATED) 137 { 138 gotoSummary("You have been defeated..."); 139 } 140 else if (playerState.state == simState.player_states.WON) 141 { 142 gotoSummary("You have won a battle!"); 143 } 144 } 145 122 146 function onSimulationUpdate() 123 147 { 124 148 g_Selection.dirty = false; -
binaries/data/mods/public/gui/summary/summary.js
1 function init(data) 2 { 3 getGUIObjectByName ("summaryTitleBar").caption = "Summary"; 4 getGUIObjectByName ("summaryText").caption = data.gameResult; 5 } -
binaries/data/mods/public/gui/summary/summary.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 3 <!-- 4 ========================================== 5 - SUMMARY SCREEN - 6 ========================================== 7 --> 8 9 <objects> 10 <script file="gui/summary/summary.js"/> 11 <object name="summary" 12 type="image" 13 sprite="bkFillBlack" 14 > 15 <!-- 16 ========================================== 17 - SUMMARY SCREEN - WINDOW 18 ========================================== 19 --> 20 21 <object name="summaryWindow" 22 style="wheatWindowGranite" 23 type="image" 24 size="25 35 100%-25 100%-25" 25 > 26 <object name="summaryTitleBar" 27 style="wheatWindowTitleBar" 28 type="button" 29 /> 30 31 <object name="summaryText" 32 type="text" 33 size="50 50 100%-50 100%-200" 34 font="serif-16" 35 text_align="center" 36 text_valign="center" 37 /> 38 39 <object type="button" style="wheatButton" size="100%-150 100%-40 100% 100%"> 40 Main menu 41 <action on="Press"><![CDATA[ 42 Engine.SwitchGuiPage("page_pregame.xml"); 43 ]]></action> 44 </object> 45 </object> 46 </object> 47 </objects> -
binaries/data/mods/public/simulation/components/EndGameManager.js
1 // Interval, which defines how often game will check end game conditions 2 var g_ProgressInterval = 1000; 3 4 /* 5 EndGameManager is the system component, which regularly (by timer) checks 6 victory/defeat conditions and if it is satisfied ends the game 7 */ 8 function EndGameManager() {} 9 10 EndGameManager.prototype.Schema = 11 "<a:component type='system'/><empty/>"; 12 13 // static member - gameTypes enum 14 EndGameManager.GameTypes = { CONQUEST : 0 }; 15 16 EndGameManager.prototype.Init = function() 17 { 18 print("EndGameManager init"); 19 // only CONQUEST mode for now 20 this.gameType = EndGameManager.GameTypes.CONQUEST; 21 22 // start the timer 23 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 24 this.timer = cmpTimer.SetTimeout(this.entity, IID_EndGameManager, "ProgressTimeout", g_ProgressInterval, {}); 25 }; 26 27 EndGameManager.prototype.OnDestroy = function() 28 { 29 if (this.timer) 30 { 31 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 32 cmpTimer.CancelTimer(this.timer); 33 } 34 }; 35 36 EndGameManager.prototype.ProgressTimeout = function(data) 37 { 38 this.UpdatePlayerStates(); 39 40 // repeat the timer 41 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 42 this.timer = cmpTimer.SetTimeout(this.entity, IID_EndGameManager, "ProgressTimeout", g_ProgressInterval, data); 43 } 44 45 EndGameManager.prototype.UpdatePlayerStates = function() 46 { 47 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 48 switch (this.gameType) 49 { 50 case EndGameManager.GameTypes.CONQUEST: 51 for (var i = 0; i < cmpPlayerManager.GetNumPlayers(); i++) 52 { 53 var playerEntityId = cmpPlayerManager.GetPlayerByID(i); 54 var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player); 55 if (cmpPlayer.state == cmpPlayer.GameStates.ACTIVE) 56 { 57 if (cmpPlayer.GetPopulationCount() == 0 && cmpPlayer.structuresCount == 0) 58 { 59 cmpPlayer.state = cmpPlayer.GameStates.DEFEATED; 60 } 61 } 62 } 63 // TODO: update this code for allies 64 var alivePlayersCount = 0; 65 var lastAlivePlayerId = -1; 66 for (var i = 0; i < cmpPlayerManager.GetNumPlayers(); i++) 67 { 68 var playerEntityId = cmpPlayerManager.GetPlayerByID(i); 69 var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player); 70 if (cmpPlayer.state == cmpPlayer.GameStates.ACTIVE) 71 { 72 alivePlayersCount++; 73 lastAlivePlayerId = i; 74 } 75 } 76 if (alivePlayersCount == 1) 77 { 78 var playerEntityId = cmpPlayerManager.GetPlayerByID(lastAlivePlayerId); 79 var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player); 80 cmpPlayer.state = cmpPlayer.GameStates.WON; 81 } 82 break; 83 default: 84 // strange game type ... 85 } 86 } 87 88 Engine.RegisterComponentType(IID_EndGameManager, "EndGameManager", EndGameManager); -
binaries/data/mods/public/simulation/components/GuiInterface.js
20 20 GuiInterface.prototype.GetSimulationState = function(player) 21 21 { 22 22 var ret = { 23 "players": [] 23 "players": [], 24 "player_states": undefined 24 25 }; 25 26 26 27 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); … … 36 37 "popCount": cmpPlayer.GetPopulationCount(), 37 38 "popLimit": cmpPlayer.GetPopulationLimit(), 38 39 "resourceCounts": cmpPlayer.GetResourceCounts(), 39 "trainingQueueBlocked": cmpPlayer.IsTrainingQueueBlocked() 40 "trainingQueueBlocked": cmpPlayer.IsTrainingQueueBlocked(), 41 "state": cmpPlayer.GetState() 40 42 }; 41 43 ret.players.push(playerData); 44 ret.player_states = cmpPlayer.GameStates; 42 45 } 43 46 44 47 return ret; -
binaries/data/mods/public/simulation/components/Identity.js
62 62 "<value>Mechanical</value>" + 63 63 "<value>Super</value>" + 64 64 "<value>Hero</value>" + 65 "<value>Structure</value>" + 65 66 "<value>Civic</value>" + 66 67 "<value>Economic</value>" + 67 68 "<value>Defensive</value>" + -
binaries/data/mods/public/simulation/components/interfaces/EndGameManager.js
1 Engine.RegisterInterface("EndGameManager"); -
binaries/data/mods/public/simulation/components/Player.js
19 19 "metal": 500, 20 20 "stone": 1000 21 21 }; 22 // player game state 23 this.state = this.GameStates.ACTIVE; 24 // buildings count 25 this.structuresCount = 0; 22 26 }; 23 27 28 // static enum: player game state 29 Player.prototype.GameStates = { ACTIVE : 0, DEFEATED : 1, WON : 2 }; 30 24 31 Player.prototype.SetPlayerID = function(id) 25 32 { 26 33 this.playerID = id; … … 146 153 return true; 147 154 }; 148 155 156 Player.prototype.GetState = function() 157 { 158 return this.state; 159 }; 160 149 161 // Keep track of population effects of all entities that 150 162 // become owned or unowned by this player 151 163 Player.prototype.OnGlobalOwnershipChanged = function(msg) 152 164 { 165 var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity); 166 // Is this entity a structure? 167 var isStructure = (cmpIdentity && cmpIdentity.GetClassesList().indexOf("Structure") != -1); 168 153 169 if (msg.from == this.playerID) 154 170 { 171 if (isStructure) 172 { 173 this.structuresCount--; 174 } 155 175 var cost = Engine.QueryInterface(msg.entity, IID_Cost); 156 176 if (cost) 157 177 { … … 162 182 163 183 if (msg.to == this.playerID) 164 184 { 185 if (isStructure) 186 { 187 this.structuresCount++; 188 } 165 189 var cost = Engine.QueryInterface(msg.entity, IID_Cost); 166 190 if (cost) 167 191 { -
binaries/data/mods/public/simulation/templates/template_structure.xml
2 2 <Entity parent="template_entity_full"> 3 3 <Identity> 4 4 <GenericName>Structure</GenericName> 5 <Classes datatype="tokens">Structure</Classes> 5 6 <IconSheet>snPortraitSheetBuildings</IconSheet> 6 7 </Identity> 7 8 <BuildRestrictions> -
source/simulation2/Simulation2.cpp
112 112 LOAD_SCRIPTED_COMPONENT("GuiInterface"); 113 113 LOAD_SCRIPTED_COMPONENT("PlayerManager"); 114 114 LOAD_SCRIPTED_COMPONENT("Timer"); 115 LOAD_SCRIPTED_COMPONENT("EndGameManager"); 115 116 116 117 #undef LOAD_SCRIPTED_COMPONENT 117 118 }