Ticket #643: gatherer-count-11052012.patch
File gatherer-count-11052012.patch, 13.3 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/session.js
443 443 if (!playerState) 444 444 return; 445 445 446 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food; 447 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood; 448 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone; 449 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal; 446 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food + 447 " (" + playerState.resourceGatherers.count.food + ")"; 448 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood + 449 " (" + playerState.resourceGatherers.count.wood + ")"; 450 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone + 451 " (" + playerState.resourceGatherers.count.stone + ")"; 452 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal + 453 " (" + playerState.resourceGatherers.count.metal + ")"; 450 454 getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit; 451 455 452 456 g_IsTrainingBlocked = playerState.trainingBlocked; -
binaries/data/mods/public/gui/session/session.xml
422 422 <!-- Player resource bar --> 423 423 <!-- ================================ ================================ --> 424 424 <object 425 size=" 10 0 45%100%"425 size="5 0 45%+5 100%" 426 426 > 427 427 <!-- Food --> 428 <object size="0 0 90 100%" type="image" style="resourceCounter" tooltip="Food" tooltip_style="sessionToolTipBold">428 <object size="0 0 20% 100%" type="image" style="resourceCounter" tooltip="Food (Gatherers)" tooltip_style="sessionToolTipBold"> 429 429 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/food.png" ghost="true"/> 430 430 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceFood"/> 431 431 </object> 432 432 433 433 <!-- Wood --> 434 <object size=" 90 0 180 100%" type="image" style="resourceCounter" tooltip="Wood" tooltip_style="sessionToolTipBold">434 <object size="20% 0 40% 100%" type="image" style="resourceCounter" tooltip="Wood (Gatherers)" tooltip_style="sessionToolTipBold"> 435 435 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/wood.png" ghost="true"/> 436 436 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceWood"/> 437 437 </object> 438 438 439 439 <!-- Stone --> 440 <object size=" 180 0 270 100%" type="image" style="resourceCounter" tooltip="Stone" tooltip_style="sessionToolTipBold">440 <object size="40% 0 60% 100%" type="image" style="resourceCounter" tooltip="Stone (Gatherers)" tooltip_style="sessionToolTipBold"> 441 441 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/stone.png" ghost="true"/> 442 442 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceStone"/> 443 443 </object> 444 444 445 445 <!-- Metal --> 446 <object size=" 270 0 360 100%" type="image" style="resourceCounter" tooltip="Metal" tooltip_style="sessionToolTipBold">446 <object size="60% 0 80% 100%" type="image" style="resourceCounter" tooltip="Metal (Gatherers)" tooltip_style="sessionToolTipBold"> 447 447 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/metal.png" ghost="true"/> 448 448 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceMetal"/> 449 449 </object> 450 450 451 451 <!-- Population --> 452 <object size=" 360 0 450100%" type="image" style="resourceCounter" tooltip="Population (current / limit)" tooltip_style="sessionToolTipBold">452 <object size="80% 0 100% 100%" type="image" style="resourceCounter" tooltip="Population (current / limit)" tooltip_style="sessionToolTipBold"> 453 453 <object size="0 -4 40 34" type="image" sprite="stretched:session/icons/resources/population.png" ghost="true"/> 454 454 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourcePop"/> 455 455 </object> -
binaries/data/mods/public/simulation/components/GuiInterface.js
85 85 "popLimit": cmpPlayer.GetPopulationLimit(), 86 86 "popMax": cmpPlayer.GetMaxPopulation(), 87 87 "resourceCounts": cmpPlayer.GetResourceCounts(), 88 "resourceGatherers": cmpPlayer.GetResourceGatherers(), 88 89 "trainingBlocked": cmpPlayer.IsTrainingBlocked(), 89 90 "state": cmpPlayer.GetState(), 90 91 "team": cmpPlayer.GetTeam(), -
binaries/data/mods/public/simulation/components/Player.js
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.teamsLocked = false; … … 144 156 return this.resourceCount; 145 157 }; 146 158 159 Player.prototype.RemoveResourceGatherer = function(gatherer, force) 160 { 161 var cmpResourceGatherer = Engine.QueryInterface(gatherer, IID_ResourceGatherer); 162 if (!cmpResourceGatherer) 163 return false; 164 165 var resource = cmpResourceGatherer.GetLastGathered(); 166 if (!resource) 167 return false; 168 169 var cmpUnitAI = Engine.QueryInterface(gatherer, IID_UnitAI); 170 var orders = cmpUnitAI.GetOrders(); 171 172 var gatheredResource = undefined; 173 for (var j = 0; j < orders.length; ++j) 174 { 175 var order = orders[j]; 176 if (order.type == "Gather" && !order.data.force) 177 gatheredResource = order.data.type.generic; 178 } 179 180 // Prune entities if they're no longer gathering or gathering a different resource. 181 if (!gatheredResource || gatheredResource != resource.generic || force) 182 { 183 cmpResourceGatherer.SetLastGathered(undefined); 184 var resourceType = (resource.generic == "treasure") ? resource.specific : resource.generic; 185 delete this.resourceGatherers[resourceType][gatherer]; 186 this.resourceGatherers.count[resourceType]--; 187 return true; 188 } 189 190 return false; 191 }; 192 193 Player.prototype.GetResourceGatherers = function() 194 { 195 return this.resourceGatherers; 196 }; 197 198 Player.prototype.AddResourceGatherer = function(gatherer, type) 199 { 200 // We want to add units that are gathering a new resource. 201 var cmpResourceGatherer = Engine.QueryInterface(gatherer, IID_ResourceGatherer); 202 if (cmpResourceGatherer) 203 { 204 var lastGathered = cmpResourceGatherer.GetLastGathered(); 205 if (!lastGathered || lastGathered.generic != type.generic) 206 { 207 cmpResourceGatherer.SetLastGathered(type); 208 var resourceType = (type.generic == "treasure") ? type.specific : type.generic; 209 this.resourceGatherers[resourceType][gatherer] = true; 210 this.resourceGatherers.count[resourceType]++; 211 return true; 212 } 213 } 214 return false; 215 }; 216 147 217 /** 148 218 * Add resource of specified type to player 149 219 * @param type Generic type of resource (string) -
binaries/data/mods/public/simulation/components/Promotion.js
74 74 { 75 75 var carriedResorces = cmpCurrentUnitResourceGatherer.GetCarryingStatus(); 76 76 cmpPromotedUnitResourceGatherer.GiveResources(carriedResorces); 77 cmpPromotedUnitResourceGatherer.SetLastCarriedType( cmpCurrentUnitResourceGatherer.GetLastCarriedType() ); 77 78 } 78 79 79 80 var cmpCurrentUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); … … 85 86 var orders = cmpCurrentUnitAI.GetOrders(); 86 87 cmpPromotedUnitAI.AddOrders(orders); 87 88 89 // Add the promoted entity to the gatherer counter if necessary. The 90 // old entity will be removed from the counter upon its destruction. 91 if (cmpCurrentUnitAI.IsGatherer() && cmpCurrentUnitResourceGatherer && cmpPromotedUnitResourceGatherer) 92 { 93 var cmpPlayer = cmpPromotedUnitAI.GetOwner(promotedUnitEntity); 94 if (cmpPlayer) 95 cmpPromotedUnitAI.SetGathering( cmpPlayer.AddResourceGatherer(promotedUnitEntity, 96 cmpCurrentUnitResourceGatherer.GetLastGathered()) ); 97 } 98 88 99 Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: promotedUnitEntity }); 89 100 90 101 // Destroy current entity -
binaries/data/mods/public/simulation/components/ResourceGatherer.js
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 /** … … 87 88 88 89 /** 89 90 * Used to instantly give resources to unit 90 * @param resources The same structure as returned f orm GetCarryingStatus91 * @param resources The same structure as returned from GetCarryingStatus 91 92 */ 92 93 ResourceGatherer.prototype.GiveResources = function(resources) 93 94 { … … 125 126 return undefined; 126 127 }; 127 128 129 ResourceGatherer.prototype.SetLastCarriedType = function(type) 130 { 131 this.lastCarriedType = type; 132 }; 133 134 /** 135 * Gets the type of the last resource that was gathered. Unlike 136 * lastCarriedType, this is updated as soon as a unit initiates 137 * gathering, not when it completes its first full action. 138 */ 139 ResourceGatherer.prototype.GetLastGathered = function() 140 { 141 if (this.lastGathered) 142 return this.lastGathered; 143 else 144 return undefined; 145 } 146 147 ResourceGatherer.prototype.SetLastGathered = function(type) 148 { 149 this.lastGathered = type; 150 } 151 128 152 ResourceGatherer.prototype.GetGatherRates = function() 129 153 { 130 154 var ret = {}; -
binaries/data/mods/public/simulation/components/UnitAI.js
1143 1143 { 1144 1144 var typename = "gather_" + this.order.data.type.specific; 1145 1145 this.SelectAnimation(typename, false, 1.0, typename); 1146 1147 var cmpPlayer = this.GetOwnerPlayer(this.entity); 1148 if (cmpPlayer && cmpPlayer.AddResourceGatherer(this.entity, this.order.data.type)) 1149 this.isGatherer = true; 1146 1150 } 1147 1151 return false; 1148 1152 }, 1149 1153 1150 1154 "leave": function() { 1155 var cmpPlayer = this.GetOwnerPlayer(this.entity); 1156 if (cmpPlayer && cmpPlayer.RemoveResourceGatherer(this.entity, false)) 1157 this.isGatherer = false; 1158 1151 1159 this.StopTimer(); 1152 1160 }, 1153 1161 … … 1848 1856 this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to 1849 1857 this.isGarrisoned = false; 1850 1858 this.isIdle = false; 1859 this.isGatherer = false; 1851 1860 this.lastFormationName = ""; 1852 1861 1853 1862 // For preventing increased action rate due to Stop orders or target death. … … 1891 1900 return this.isIdle; 1892 1901 }; 1893 1902 1903 UnitAI.prototype.SetGathering = function(gathering) 1904 { 1905 this.isGatherer = gathering; 1906 }; 1907 1908 UnitAI.prototype.IsGatherer = function() 1909 { 1910 return this.isGatherer; 1911 }; 1912 1894 1913 UnitAI.prototype.IsGarrisoned = function() 1895 1914 { 1896 1915 return this.isGarrisoned; … … 1943 1962 this.SetStance(this.template.DefaultStance); 1944 1963 this.Stop(false); 1945 1964 } 1965 1966 // Ensure the entity is no longer counted as gathering. 1967 if (msg.from != -1 && this.isGatherer && !this.IsFormationController()) 1968 { 1969 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 1970 var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(msg.from), IID_Player); 1971 if (cmpPlayer) 1972 cmpPlayer.RemoveResourceGatherer(this.entity, true); 1973 } 1946 1974 }; 1947 1975 1948 1976 UnitAI.prototype.OnDestroy = function() … … 2109 2137 Engine.PostMessage(this.entity, MT_UnitAIStateChanged, { "to": state }); 2110 2138 }; 2111 2139 2140 UnitAI.prototype.GetOwnerPlayer = function(entity) 2141 { 2142 var cmpOwnership = Engine.QueryInterface(entity, IID_Ownership); 2143 if (!cmpOwnership) 2144 return undefined; 2145 2146 var owner = cmpOwnership.GetOwner(); 2147 if (owner == -1) 2148 return undefined; 2149 2150 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 2151 var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(owner), IID_Player); 2152 if (!cmpPlayer) 2153 return undefined; 2154 2155 return cmpPlayer; 2156 }; 2157 2112 2158 /** 2113 2159 * Call when the current order has been completed (or failed). 2114 2160 * Removes the current order from the queue, and processes the … … 2229 2275 { 2230 2276 this.orderQueue = []; 2231 2277 this.PushOrder(type, data); 2278 2279 if (this.isGatherer) 2280 { 2281 var cmpPlayer = this.GetOwnerPlayer(this.entity); 2282 if (cmpPlayer && cmpPlayer.RemoveResourceGatherer(this.entity, true)) 2283 this.isGatherer = false; 2284 } 2232 2285 } 2233 2286 }; 2234 2287