Ticket #643: gatherer-count-2.patch
File gatherer-count-2.patch, 11.0 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..64162a0 100644
a b function updatePlayerDisplay(simState) 406 406 if (!playerState) 407 407 return; 408 408 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; 409 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food + 410 " (" + playerState.resourceGatherers.count.food + ")"; 411 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood + 412 " (" + playerState.resourceGatherers.count.wood + ")"; 413 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone + 414 " (" + playerState.resourceGatherers.count.stone + ")"; 415 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal + 416 " (" + playerState.resourceGatherers.count.metal + ")"; 413 417 getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit; 414 418 415 419 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..4f64329 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(), -
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..f7e6c89 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 "count": { 28 "food": 0, 29 "wood": 0, 30 "metal": 0, 31 "stone": 0 32 } 33 }; 22 34 23 35 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 36 this.state = "active"; // game state - one of "active", "defeated", "won" … … Player.prototype.GetResourceCounts = function() 137 149 return this.resourceCount; 138 150 }; 139 151 152 Player.prototype.RemoveResourceGatherer = function(gatherer, force) 153 { 154 var cmpResourceGatherer = Engine.QueryInterface(gatherer, IID_ResourceGatherer); 155 if (!cmpResourceGatherer) 156 return; 157 158 var resource = cmpResourceGatherer.GetLastGathered(); 159 if (!resource) 160 return; 161 162 var cmpUnitAI = Engine.QueryInterface(gatherer, IID_UnitAI); 163 var gatheredResource = undefined; 164 for (var j = 0; j < cmpUnitAI.orderQueue.length; j++ ) 165 { 166 var order = cmpUnitAI.orderQueue[j]; 167 if (order.type == "Gather" && !order.data.force) 168 gatheredResource = order.data.type.generic; 169 } 170 171 // Prune entities if they're no longer gathering or gathering a different resource. 172 if (!gatheredResource || gatheredResource != resource.generic || force) 173 { 174 cmpResourceGatherer.lastGathered = undefined; 175 var resourceType = (resource.generic == "treasure") ? resource.specific : resource.generic; 176 delete this.resourceGatherers[resourceType][gatherer]; 177 this.resourceGatherers.count[resourceType]--; 178 } 179 }; 180 181 Player.prototype.GetResourceGatherers = function() 182 { 183 // Define if necessary, for older saves. 184 if (typeof this.resourceGatherers === "undefined") 185 { 186 this.resourceGatherers = { 187 "food": {}, 188 "wood": {}, 189 "metal": {}, 190 "stone": {}, 191 "count": { 192 "food": 0, 193 "wood": 0, 194 "metal": 0, 195 "stone": 0 196 } 197 }; 198 } 199 200 return this.resourceGatherers; 201 }; 202 203 Player.prototype.AddResourceGatherer = function(gatherer, type) 204 { 205 // We want to add units that are gathering a new resource. 206 var cmpResourceGatherer = Engine.QueryInterface(gatherer, IID_ResourceGatherer); 207 if (cmpResourceGatherer) 208 { 209 var lastGathered = cmpResourceGatherer.GetLastGathered(); 210 if (!lastGathered || lastGathered.generic != type.generic) 211 { 212 cmpResourceGatherer.lastGathered = type; 213 var resourceType = (type.generic == "treasure") ? type.specific : type.generic; 214 this.resourceGatherers[resourceType][gatherer] = true; 215 this.resourceGatherers.count[resourceType]++; 216 } 217 } 218 }; 219 140 220 /** 141 221 * Add resource of specified type to player 142 222 * @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..47559d5 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; 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..ef9cd3d 100644
a b var UnitFsmSpec = { 1022 1022 return; 1023 1023 } 1024 1024 1025 var cmpPlayer = this.GetOwner(this.entity); 1026 if (cmpPlayer) 1027 cmpPlayer.AddResourceGatherer(this.entity, this.order.data.type); 1028 1025 1029 // Scale timing interval based on rate, and start timer 1026 1030 // The offset should be at least as long as the repeat time so we use the same value for both. 1027 1031 var offset = 1000/rate; … … var UnitFsmSpec = { 1041 1045 }, 1042 1046 1043 1047 "leave": function() { 1048 var cmpPlayer = this.GetOwner(this.entity); 1049 if (cmpPlayer) 1050 cmpPlayer.RemoveResourceGatherer(this.entity, false); 1051 1044 1052 this.StopTimer(); 1045 1053 }, 1046 1054 … … UnitAI.prototype.OnOwnershipChanged = function(msg) 1812 1820 this.SetupRangeQuery(); 1813 1821 if (this.IsHealer()) 1814 1822 this.SetupHealRangeQuery(); 1823 1824 // Ensure the entity is no longer counted as gathering. 1825 if (msg.from != -1) 1826 { 1827 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 1828 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(msg.from), IID_Player); 1829 if (cmpPlayer) 1830 cmpPlayer.RemoveResourceGatherer(this.entity, true); 1831 } 1815 1832 }; 1816 1833 1817 1834 UnitAI.prototype.OnDestroy = function() … … UnitAI.prototype.FsmStateNameChanged = function(state) 1927 1944 Engine.PostMessage(this.entity, MT_UnitAIStateChanged, { "to": state }); 1928 1945 }; 1929 1946 1947 UnitAI.prototype.GetOwner = function(entity) 1948 { 1949 var cmpOwnership = Engine.QueryInterface(entity, IID_Ownership); 1950 if (!cmpOwnership) 1951 return undefined; 1952 1953 var owner = cmpOwnership.GetOwner(); 1954 if (owner == -1) 1955 return undefined; 1956 1957 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 1958 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(owner), IID_Player); 1959 if (!cmpPlayer) 1960 return undefined; 1961 1962 return cmpPlayer; 1963 }; 1964 1930 1965 /** 1931 1966 * Call when the current order has been completed (or failed). 1932 1967 * Removes the current order from the queue, and processes the