Ticket #643: gatherer-count-3.patch
File gatherer-count-3.patch, 13.2 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/session.js
416 416 if (!playerState) 417 417 return; 418 418 419 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food; 420 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood; 421 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone; 422 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal; 419 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food + 420 " (" + playerState.resourceGatherers.count.food + ")"; 421 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood + 422 " (" + playerState.resourceGatherers.count.wood + ")"; 423 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone + 424 " (" + playerState.resourceGatherers.count.stone + ")"; 425 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal + 426 " (" + playerState.resourceGatherers.count.metal + ")"; 423 427 getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit; 424 428 425 429 g_IsTrainingBlocked = playerState.trainingBlocked; -
binaries/data/mods/public/gui/session/session.xml
311 311 <!-- Player resource bar --> 312 312 <!-- ================================ ================================ --> 313 313 <object 314 size=" 10 0 45%100%"314 size="5 0 45%+5 100%" 315 315 > 316 316 <!-- Food --> 317 <object size="0 0 90 100%" type="image" style="resourceCounter" tooltip="Food" tooltip_style="sessionToolTipBold">317 <object size="0 0 100 100%" type="image" style="resourceCounter" tooltip="Food (Gatherers)" tooltip_style="sessionToolTipBold"> 318 318 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/food.png"/> 319 319 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceFood"/> 320 320 </object> 321 321 322 322 <!-- Wood --> 323 <object size="90 0 1 80 100%" type="image" style="resourceCounter" tooltip="Wood" tooltip_style="sessionToolTipBold">323 <object size="90 0 190 100%" type="image" style="resourceCounter" tooltip="Wood (Gatherers)" tooltip_style="sessionToolTipBold"> 324 324 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/wood.png"/> 325 325 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceWood"/> 326 326 </object> 327 327 328 328 <!-- Stone --> 329 <object size="180 0 2 70 100%" type="image" style="resourceCounter" tooltip="Stone" tooltip_style="sessionToolTipBold">329 <object size="180 0 280 100%" type="image" style="resourceCounter" tooltip="Stone (Gatherers)" tooltip_style="sessionToolTipBold"> 330 330 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/stone.png"/> 331 331 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceStone"/> 332 332 </object> 333 333 334 334 <!-- Metal --> 335 <object size="270 0 3 60 100%" type="image" style="resourceCounter" tooltip="Metal" tooltip_style="sessionToolTipBold">335 <object size="270 0 370 100%" type="image" style="resourceCounter" tooltip="Metal (Gatherers)" tooltip_style="sessionToolTipBold"> 336 336 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/metal.png"/> 337 337 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceMetal"/> 338 338 </object> 339 339 340 340 <!-- Population --> 341 <object size="36 00 450 100%" type="image" style="resourceCounter" tooltip="Population (current / limit)" tooltip_style="sessionToolTipBold">341 <object size="365 0 450 100%" type="image" style="resourceCounter" tooltip="Population (current / limit)" tooltip_style="sessionToolTipBold"> 342 342 <object size="0 -4 40 34" type="image" sprite="stretched:session/icons/resources/population.png"/> 343 343 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourcePop"/> 344 344 </object> -
binaries/data/mods/public/simulation/components/UnitAI.js
1043 1043 { 1044 1044 var typename = "gather_" + this.order.data.type.specific; 1045 1045 this.SelectAnimation(typename, false, 1.0, typename); 1046 1047 var cmpPlayer = this.GetOwner(this.entity); 1048 if (cmpPlayer) 1049 if (cmpPlayer.AddResourceGatherer(this.entity, this.order.data.type)) 1050 this.isGatherer = true; 1046 1051 } 1047 1052 }, 1048 1053 1049 1054 "leave": function() { 1055 var cmpPlayer = this.GetOwner(this.entity); 1056 if (cmpPlayer && cmpPlayer.RemoveResourceGatherer(this.entity, false)) 1057 this.isGatherer = false; 1058 1050 1059 this.StopTimer(); 1051 1060 }, 1052 1061 … … 1766 1775 this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to 1767 1776 this.isGarrisoned = false; 1768 1777 this.isIdle = false; 1778 this.isGatherer = false; 1769 1779 this.lastFormationName = ""; 1770 1780 1771 1781 this.SetStance(this.template.DefaultStance); … … 1799 1809 return this.isIdle; 1800 1810 }; 1801 1811 1812 UnitAI.prototype.SetGathering = function(gathering) 1813 { 1814 this.isGatherer = gathering; 1815 }; 1816 1817 UnitAI.prototype.IsGatherer = function() 1818 { 1819 return this.isGatherer; 1820 }; 1821 1802 1822 UnitAI.prototype.IsGarrisoned = function() 1803 1823 { 1804 1824 return this.isGarrisoned; … … 1819 1839 this.SetupRangeQuery(); 1820 1840 if (this.IsHealer()) 1821 1841 this.SetupHealRangeQuery(); 1842 1843 // Ensure the entity is no longer counted as gathering. 1844 if (msg.from != -1 && this.isGatherer && !this.IsFormationController()) 1845 { 1846 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 1847 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(msg.from), IID_Player); 1848 if (cmpPlayer) 1849 cmpPlayer.RemoveResourceGatherer(this.entity, true); 1850 } 1822 1851 }; 1823 1852 1824 1853 UnitAI.prototype.OnDestroy = function() … … 1934 1963 Engine.PostMessage(this.entity, MT_UnitAIStateChanged, { "to": state }); 1935 1964 }; 1936 1965 1966 UnitAI.prototype.GetOwner = function(entity) 1967 { 1968 var cmpOwnership = Engine.QueryInterface(entity, IID_Ownership); 1969 if (!cmpOwnership) 1970 return undefined; 1971 1972 var owner = cmpOwnership.GetOwner(); 1973 if (owner == -1) 1974 return undefined; 1975 1976 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 1977 var cmpPlayer = Engine.QueryInterface(cmpPlayerMan.GetPlayerByID(owner), IID_Player); 1978 if (!cmpPlayer) 1979 return undefined; 1980 1981 return cmpPlayer; 1982 }; 1983 1937 1984 /** 1938 1985 * Call when the current order has been completed (or failed). 1939 1986 * Removes the current order from the queue, and processes the … … 2049 2096 { 2050 2097 this.orderQueue = []; 2051 2098 this.PushOrder(type, data); 2099 2100 if (this.isGatherer) 2101 { 2102 var cmpPlayer = this.GetOwner(this.entity); 2103 if (cmpPlayer && cmpPlayer.RemoveResourceGatherer(this.entity, true)) 2104 this.isGatherer = false; 2105 } 2052 2106 } 2053 2107 }; 2054 2108 -
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.state = "active"; // game state - one of "active", "defeated", "won" … … 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 false; 157 158 var resource = cmpResourceGatherer.GetLastGathered(); 159 if (!resource) 160 return false; 161 162 var cmpUnitAI = Engine.QueryInterface(gatherer, IID_UnitAI); 163 var orders = cmpUnitAI.GetOrders(); 164 165 var gatheredResource = undefined; 166 for (var j = 0; j < orders.length; ++j) 167 { 168 var order = orders[j]; 169 if (order.type == "Gather" && !order.data.force) 170 gatheredResource = order.data.type.generic; 171 } 172 173 // Prune entities if they're no longer gathering or gathering a different resource. 174 if (!gatheredResource || gatheredResource != resource.generic || force) 175 { 176 cmpResourceGatherer.SetLastGathered(undefined); 177 var resourceType = (resource.generic == "treasure") ? resource.specific : resource.generic; 178 delete this.resourceGatherers[resourceType][gatherer]; 179 this.resourceGatherers.count[resourceType]--; 180 return true; 181 } 182 183 return false; 184 }; 185 186 Player.prototype.GetResourceGatherers = function() 187 { 188 return this.resourceGatherers; 189 }; 190 191 Player.prototype.AddResourceGatherer = function(gatherer, type) 192 { 193 // We want to add units that are gathering a new resource. 194 var cmpResourceGatherer = Engine.QueryInterface(gatherer, IID_ResourceGatherer); 195 if (cmpResourceGatherer) 196 { 197 var lastGathered = cmpResourceGatherer.GetLastGathered(); 198 if (!lastGathered || lastGathered.generic != type.generic) 199 { 200 cmpResourceGatherer.SetLastGathered(type); 201 var resourceType = (type.generic == "treasure") ? type.specific : type.generic; 202 this.resourceGatherers[resourceType][gatherer] = true; 203 this.resourceGatherers.count[resourceType]++; 204 return true; 205 } 206 } 207 return false; 208 }; 209 140 210 /** 141 211 * Add resource of specified type to player 142 212 * @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/GuiInterface.js
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/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 = {};