Ticket #643: gatherer-count.patch
File gatherer-count.patch, 11.2 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/session.js
diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 1204df5..b668ee8 100644
a b var g_EntityStates = {}; // {id:entState} 23 23 // Whether the player has lost/won and reached the end of their game 24 24 var g_GameEnded = false; 25 25 26 // The current ID of the timer that updates gatherer counters. 27 var g_GathererPruneTimerID = undefined; 28 26 29 // Colors to flash when pop limit reached 27 30 const DEFAULT_POPULATION_COLOR = "white"; 28 31 const POPULATION_ALERT_COLOR = "orange"; … … function updatePlayerDisplay(simState) 406 409 if (!playerState) 407 410 return; 408 411 409 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food; 410 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood; 411 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone; 412 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal; 412 // Remove dead or non-gathering workers from the gatherer arrays once per second. 413 if (!g_GathererPruneTimerID) 414 { 415 g_GathererPruneTimerID = setTimeout( 416 function() { Engine.GuiInterfaceCall("PruneResourceGatherers", Engine.GetPlayerID()); 417 g_GathererPruneTimerID = undefined; }, 1000 418 ); 419 } 420 421 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food + 422 " (" + playerState.resourceGatherers.food.length + ")"; 423 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood + 424 " (" + playerState.resourceGatherers.wood.length + ")"; 425 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone + 426 " (" + playerState.resourceGatherers.stone.length + ")"; 427 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal + 428 " (" + playerState.resourceGatherers.metal.length + ")"; 413 429 getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit; 414 430 415 431 g_IsTrainingBlocked = playerState.trainingBlocked; -
binaries/data/mods/public/gui/session/session.xml
diff --git a/binaries/data/mods/public/gui/session/session.xml b/binaries/data/mods/public/gui/session/session.xml index 8aedbf8..24f0273 100644
a b 310 310 <!-- Player resource bar --> 311 311 <!-- ================================ ================================ --> 312 312 <object 313 size=" 10 0 45%100%"313 size="5 0 45%+5 100%" 314 314 > 315 315 <!-- Food --> 316 <object size="0 0 90 100%" type="image" style="resourceCounter" tooltip="Food" tooltip_style="sessionToolTipBold">316 <object size="0 0 100 100%" type="image" style="resourceCounter" tooltip="Food (Gatherers)" tooltip_style="sessionToolTipBold"> 317 317 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/food.png"/> 318 318 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceFood"/> 319 319 </object> 320 320 321 321 <!-- Wood --> 322 <object size="90 0 1 80 100%" type="image" style="resourceCounter" tooltip="Wood" tooltip_style="sessionToolTipBold">322 <object size="90 0 190 100%" type="image" style="resourceCounter" tooltip="Wood (Gatherers)" tooltip_style="sessionToolTipBold"> 323 323 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/wood.png"/> 324 324 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceWood"/> 325 325 </object> 326 326 327 327 <!-- Stone --> 328 <object size="180 0 2 70 100%" type="image" style="resourceCounter" tooltip="Stone" tooltip_style="sessionToolTipBold">328 <object size="180 0 280 100%" type="image" style="resourceCounter" tooltip="Stone (Gatherers)" tooltip_style="sessionToolTipBold"> 329 329 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/stone.png"/> 330 330 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceStone"/> 331 331 </object> 332 332 333 333 <!-- Metal --> 334 <object size="270 0 3 60 100%" type="image" style="resourceCounter" tooltip="Metal" tooltip_style="sessionToolTipBold">334 <object size="270 0 370 100%" type="image" style="resourceCounter" tooltip="Metal (Gatherers)" tooltip_style="sessionToolTipBold"> 335 335 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/metal.png"/> 336 336 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceMetal"/> 337 337 </object> 338 338 339 339 <!-- Population --> 340 <object size="36 00 450 100%" type="image" style="resourceCounter" tooltip="Population (current / limit)" tooltip_style="sessionToolTipBold">340 <object size="365 0 450 100%" type="image" style="resourceCounter" tooltip="Population (current / limit)" tooltip_style="sessionToolTipBold"> 341 341 <object size="0 -4 40 34" type="image" sprite="stretched:session/icons/resources/population.png"/> 342 342 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourcePop"/> 343 343 </object> -
binaries/data/mods/public/simulation/components/GuiInterface.js
diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index 4ce8c71..346976a 100644
a b GuiInterface.prototype.GetSimulationState = function(player) 78 78 "popLimit": cmpPlayer.GetPopulationLimit(), 79 79 "popMax": cmpPlayer.GetMaxPopulation(), 80 80 "resourceCounts": cmpPlayer.GetResourceCounts(), 81 "resourceGatherers": cmpPlayer.GetResourceGatherers(), 81 82 "trainingBlocked": cmpPlayer.IsTrainingBlocked(), 82 83 "state": cmpPlayer.GetState(), 83 84 "team": cmpPlayer.GetTeam(), … … GuiInterface.prototype.FindIdleUnit = function(player, data) 1452 1453 return 0; 1453 1454 }; 1454 1455 1456 GuiInterface.prototype.PruneResourceGatherers = function(player) 1457 { 1458 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 1459 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(player), IID_Player); 1460 cmpPlayer.PruneResourceGatherers(); 1461 }; 1462 1455 1463 GuiInterface.prototype.GetTradingDetails = function(player, data) 1456 1464 { 1457 1465 var cmpEntityTrader = Engine.QueryInterface(data.trader, IID_Trader); … … var exposedFunctions = { 1572 1580 "GetFoundationSnapData": 1, 1573 1581 "PlaySound": 1, 1574 1582 "FindIdleUnit": 1, 1583 "PruneResourceGatherers": 1, 1575 1584 "GetTradingDetails": 1, 1576 1585 "CanAttack": 1, 1577 1586 -
binaries/data/mods/public/simulation/components/Player.js
diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index cb73201..c3cd07e 100644
a b Player.prototype.Init = function() 19 19 "metal": 300, 20 20 "stone": 300 21 21 }; 22 this.resourceGatherers = { 23 "food": [], 24 "wood": [], 25 "metal": [], 26 "stone": [] 27 }; 22 28 23 29 this.team = -1; // team number of the player, players on the same team will always have ally diplomatic status - also this is useful for team emblems, scoring, etc. 24 30 this.state = "active"; // game state - one of "active", "defeated", "won" … … Player.prototype.GetResourceCounts = function() 137 143 return this.resourceCount; 138 144 }; 139 145 146 Player.prototype.PruneResourceGatherers = function() 147 { 148 for (var resource in this.resourceGatherers) 149 { 150 for (var i = 0; i < this.resourceGatherers[resource].length; i++) 151 { 152 var gatherer = this.resourceGatherers[resource][i]; 153 var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 154 var entState = cmpTempMan.GetCurrentTemplateName(gatherer); 155 156 // Prune entities if they no longer exist. 157 if (!entState) 158 { 159 delete this.resourceGatherers[resource][i]; 160 continue; 161 } 162 163 var cmpResourceGatherer = Engine.QueryInterface(gatherer, IID_ResourceGatherer); 164 var cmpUnitAI = Engine.QueryInterface(gatherer, IID_UnitAI); 165 var gatheredResource = undefined; 166 for (var j = 0; j < cmpUnitAI.orderQueue.length; j++ ) 167 { 168 var order = cmpUnitAI.orderQueue[j]; 169 if (order.type == "Gather" && !order.data.force) 170 var gatheredResource = order.data.type.generic; 171 } 172 173 // Prune entities if they're no longer gathering or gathering a different resource. 174 if (!cmpResourceGatherer || !gatheredResource || gatheredResource != resource) 175 { 176 cmpResourceGatherer.lastGathered = undefined; 177 delete this.resourceGatherers[resource][i]; 178 } 179 } 180 181 // Remove undefined elements. 182 this.resourceGatherers[resource] = this.resourceGatherers[resource].filter(Number); 183 } 184 }; 185 186 Player.prototype.GetResourceGatherers = function() 187 { 188 // Define if necessary, for older saves. 189 if (typeof this.resourceGatherers === "undefined") 190 { 191 this.resourceGatherers = { 192 "food": [], 193 "wood": [], 194 "metal": [], 195 "stone": [] 196 }; 197 } 198 return this.resourceGatherers; 199 }; 200 201 Player.prototype.AddResourceGatherer = function(gatherer, type) 202 { 203 // We want to add units that are gathering a new resource. 204 var cmpResourceGatherer = Engine.QueryInterface(gatherer, IID_ResourceGatherer); 205 if (cmpResourceGatherer) 206 { 207 var lastGathered = cmpResourceGatherer.GetLastGathered(); 208 if (!lastGathered || lastGathered != type.generic) 209 { 210 cmpResourceGatherer.lastGathered = type; 211 this.resourceGatherers[type.generic].push(gatherer); 212 } 213 } 214 }; 215 140 216 /** 141 217 * Add resource of specified type to player 142 218 * @param type Generic type of resource (string) -
binaries/data/mods/public/simulation/components/ResourceGatherer.js
diff --git a/binaries/data/mods/public/simulation/components/ResourceGatherer.js b/binaries/data/mods/public/simulation/components/ResourceGatherer.js index 503c1b5..7df8ce2 100644
a b ResourceGatherer.prototype.Init = function() 65 65 66 66 // The last exact type gathered, so we can render appropriate props 67 67 this.lastCarriedType = undefined; // { generic, specific } 68 this.lastGathered = undefined; 68 69 }; 69 70 70 71 /** … … ResourceGatherer.prototype.GetLastCarriedType = function() 125 126 return undefined; 126 127 }; 127 128 129 ResourceGatherer.prototype.GetLastGathered = function() 130 { 131 if ( this.lastGathered ) 132 return this.lastGathered.generic; 133 else 134 return undefined; 135 } 136 128 137 ResourceGatherer.prototype.GetGatherRates = function() 129 138 { 130 139 var ret = {}; -
binaries/data/mods/public/simulation/components/UnitAI.js
diff --git a/binaries/data/mods/public/simulation/components/UnitAI.js b/binaries/data/mods/public/simulation/components/UnitAI.js index 2d38f61..fe18f7a 100644
a b var UnitFsmSpec = { 1022 1022 return; 1023 1023 } 1024 1024 1025 // Attempt to put the gatherer into the player's gatherer array. 1026 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 1027 if (cmpOwnership) 1028 { 1029 var owner = cmpOwnership.GetOwner(); 1030 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 1031 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(owner), IID_Player); 1032 if (cmpPlayer) 1033 cmpPlayer.AddResourceGatherer(this.entity, this.order.data.type); 1034 } 1035 1025 1036 // Scale timing interval based on rate, and start timer 1026 1037 // The offset should be at least as long as the repeat time so we use the same value for both. 1027 1038 var offset = 1000/rate;