Ticket #643: Patch643.patch
File Patch643.patch, 9.8 KB (added by , 12 years ago) |
---|
-
gui/session/session.js
338 338 var playerState = simState.players[Engine.GetPlayerID()]; 339 339 if (!playerState) 340 340 return; 341 342 var numResourceGatherers = Engine.GuiInterfaceCall("FindResourceGathererByType", playerState); 341 343 342 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food ;343 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood ;344 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone ;345 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal ;344 getGUIObjectByName("resourceFood").caption = playerState.resourceCounts.food + "(" + numResourceGatherers[0] + ")"; 345 getGUIObjectByName("resourceWood").caption = playerState.resourceCounts.wood + "(" + numResourceGatherers[1] + ")"; 346 getGUIObjectByName("resourceStone").caption = playerState.resourceCounts.stone + "(" + numResourceGatherers[2] + ")"; 347 getGUIObjectByName("resourceMetal").caption = playerState.resourceCounts.metal + "(" + numResourceGatherers[3] + ")"; 346 348 getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit; 347 349 348 350 g_IsTrainingQueueBlocked = playerState.trainingQueueBlocked; -
gui/session/session.xml
42 42 --> 43 43 44 44 <object hotkey="leave"> 45 <action on="Press">closeOpenDialogs(); </action>45 <action on="Press">closeOpenDialogs(); pauseShowMenu();</action> 46 46 </object> 47 47 48 48 <!-- Chat: Depending on the current state, it either opens message window or closes message window / posts message --> … … 52 52 53 53 <!-- Menu --> 54 54 <object hotkey="menu.toggle"> 55 <action on="Press"> openMenu();</action>55 <action on="Press">toggleMenu();</action> 56 56 </object> 57 57 58 58 <!-- Pause --> … … 293 293 size="10 0 45% 100%" 294 294 > 295 295 <!-- Food --> 296 <object size="0 0 90 100%" type="image" style="resourceCounter" tooltip="Food " tooltip_style="sessionToolTipBold">296 <object size="0 0 90 100%" type="image" style="resourceCounter" tooltip="Food (Gatherers)" tooltip_style="sessionToolTipBold"> 297 297 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/food.png"/> 298 298 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceFood"/> 299 299 </object> 300 300 301 301 <!-- Wood --> 302 <object size="90 0 180 100%" type="image" style="resourceCounter" tooltip="Wood " tooltip_style="sessionToolTipBold">302 <object size="90 0 180 100%" type="image" style="resourceCounter" tooltip="Wood (Gatherers)" tooltip_style="sessionToolTipBold"> 303 303 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/wood.png"/> 304 304 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceWood"/> 305 305 </object> 306 306 307 307 <!-- Stone --> 308 <object size="180 0 270 100%" type="image" style="resourceCounter" tooltip="Stone " tooltip_style="sessionToolTipBold">308 <object size="180 0 270 100%" type="image" style="resourceCounter" tooltip="Stone (Gatherers)" tooltip_style="sessionToolTipBold"> 309 309 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/stone.png"/> 310 310 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceStone"/> 311 311 </object> 312 312 313 313 <!-- Metal --> 314 <object size="270 0 360 100%" type="image" style="resourceCounter" tooltip="Metal " tooltip_style="sessionToolTipBold">314 <object size="270 0 360 100%" type="image" style="resourceCounter" tooltip="Metal (Gatherers)" tooltip_style="sessionToolTipBold"> 315 315 <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/metal.png"/> 316 316 <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceMetal"/> 317 317 </object> -
simulation/components/GuiInterface.js
694 694 PlaySound(data.name, data.entity); 695 695 }; 696 696 697 function isWorkerGathering(ent) 698 { 699 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 700 if ( !cmpUnitAI ) 701 return false; 702 703 var cmpResourceGatherer = Engine.QueryInterface(ent, IID_ResourceGatherer); 704 if ( !cmpResourceGatherer ) 705 return false; 706 707 return (cmpResourceGatherer.GetLastGathered() == undefined || cmpUnitAI.IsIdle()) ? false : true; 708 } 709 697 710 function isIdleUnit(ent, idleClass) 698 711 { 699 712 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); … … 720 733 return 0; 721 734 }; 722 735 736 GuiInterface.prototype.FindResourceGathererByType = function(player) 737 { 738 var cmpResourceGatherer; 739 var numResourceGatherers = new Array(); 740 numResourceGatherers[0] = 0; 741 numResourceGatherers[1] = 0; 742 numResourceGatherers[2] = 0; 743 numResourceGatherers[3] = 0; 744 745 // TODO: can we filter this list to just workers to save time? 746 var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 747 var playerEntities = rangeMan.GetEntitiesByPlayer(player); 748 749 for each (var ent in playerEntities) 750 { 751 if ( isWorkerGathering(ent) ) 752 { 753 cmpResourceGatherer = Engine.QueryInterface(ent, IID_ResourceGatherer); 754 if ( cmpResourceGatherer ) 755 { 756 // ensure they're actively gathering something 757 var resourceType = cmpResourceGatherer.GetLastGathered(); 758 759 if ( resourceType == "food" ) 760 { 761 numResourceGatherers[0]++; 762 } 763 else if ( resourceType == "wood" ) 764 { 765 numResourceGatherers[1]++; 766 } 767 else if ( resourceType == "stone" ) 768 { 769 numResourceGatherers[2]++; 770 } 771 else if ( resourceType == "metal" ) 772 { 773 numResourceGatherers[3]++; 774 } 775 } 776 } 777 } 778 return numResourceGatherers; 779 }; 780 723 781 GuiInterface.prototype.GetTradingDetails = function(player, data) 724 782 { 725 783 var cmpEntityTrader = Engine.QueryInterface(data.trader, IID_Trader); … … 826 884 "GetFoundationSnapData": 1, 827 885 "PlaySound": 1, 828 886 "FindIdleUnit": 1, 887 "FindResourceGathererByType": 1, 829 888 "GetTradingDetails": 1, 830 889 831 890 "SetPathfinderDebugOverlay": 1, -
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 /** … … 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 137 ResourceGatherer.prototype.SetIdleNoGathering = function() 138 { 139 this.lastGathered = undefined; 140 } 141 128 142 ResourceGatherer.prototype.GetGatherRates = function() 129 143 { 130 144 var ret = {}; … … 188 202 this.carrying[type.generic] += status.amount; 189 203 190 204 this.lastCarriedType = type; 205 this.lastGathered = type; 191 206 192 207 // Update stats of how much the player collected. 193 208 // (We have to do it here rather than at the dropsite, because we -
simulation/helpers/Commands.js
2 2 // are likely to fail, which may be useful for debugging AIs 3 3 var g_DebugCommands = false; 4 4 5 // cycles through all entities (after a command is given) and sets their gathering status to idle 6 // if the unit has been instructed to gather resources, gathering status is updated once it begins gathering 7 function setNotGathering(entities) 8 { 9 for each ( var ent in entities ) 10 { 11 var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); 12 if ( cmpIdentity ) 13 { 14 if ( cmpIdentity.HasClass("Worker") || cmpIdentity.HasClass("Female") || 15 cmpIdentity.HasClass("CitizenSoldier") || cmpIdentity.HasClass("FishingBoat") ) 16 { 17 var cmpResourceGatherer = Engine.QueryInterface(ent, IID_ResourceGatherer); 18 if ( cmpResourceGatherer ) 19 { 20 cmpResourceGatherer.SetIdleNoGathering(); 21 } 22 } 23 } 24 } 25 } 26 5 27 function ProcessCommand(player, cmd) 6 28 { 7 29 // Do some basic checks here that commanding player is valid … … 50 72 GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) { 51 73 cmpUnitAI.Walk(cmd.x, cmd.z, cmd.queued); 52 74 }); 75 setNotGathering(entities); 53 76 break; 54 77 55 78 case "attack": … … 64 87 GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) { 65 88 cmpUnitAI.Attack(cmd.target, cmd.queued); 66 89 }); 90 setNotGathering(entities); 67 91 break; 68 92 69 93 case "heal": … … 93 117 GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) { 94 118 cmpUnitAI.Repair(cmd.target, cmd.autocontinue, cmd.queued); 95 119 }); 120 setNotGathering(entities); 96 121 break; 97 122 98 123 case "gather": … … 107 132 GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) { 108 133 cmpUnitAI.Gather(cmd.target, cmd.queued); 109 134 }); 135 setNotGathering(entities); 110 136 break; 111 137 112 138 case "gather-near-position": … … 114 140 GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) { 115 141 cmpUnitAI.GatherNearPosition(cmd.x, cmd.z, cmd.resourceType, cmd.queued); 116 142 }); 143 setNotGathering(entities); 117 144 break; 118 145 119 146 case "returnresource": … … 288 315 "queued": cmd.queued 289 316 }); 290 317 } 291 318 319 setNotGathering(entities); 292 320 break; 293 321 294 322 case "delete-entities": … … 339 367 GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) { 340 368 cmpUnitAI.Garrison(cmd.target); 341 369 }); 370 setNotGathering(entities); 342 371 } 343 372 else if (g_DebugCommands) 344 373 {