Ticket #643: Patch643.patch

File Patch643.patch, 9.8 KB (added by Matt Doerksen, 12 years ago)
  • gui/session/session.js

     
    338338    var playerState = simState.players[Engine.GetPlayerID()];
    339339    if (!playerState)
    340340        return;
     341       
     342    var numResourceGatherers = Engine.GuiInterfaceCall("FindResourceGathererByType", playerState);
    341343
    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] + ")";
    346348    getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit;
    347349
    348350    g_IsTrainingQueueBlocked = playerState.trainingQueueBlocked;
  • gui/session/session.xml

     
    4242            -->
    4343
    4444        <object hotkey="leave">
    45             <action on="Press">closeOpenDialogs();</action>
     45            <action on="Press">closeOpenDialogs(); pauseShowMenu();</action>
    4646        </object>
    4747
    4848        <!-- Chat: Depending on the current state, it either opens message window or closes message window / posts message -->
     
    5252
    5353        <!-- Menu -->
    5454        <object hotkey="menu.toggle">
    55             <action on="Press">openMenu();</action>
     55            <action on="Press">toggleMenu();</action>
    5656        </object>
    5757
    5858        <!-- Pause -->
     
    293293                size="10 0 45% 100%"
    294294            >
    295295                <!-- 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">
    297297                    <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/food.png"/>
    298298                    <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceFood"/>
    299299                </object>
    300300
    301301                <!-- 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">
    303303                    <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/wood.png"/>
    304304                    <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceWood"/>
    305305                </object>
    306306
    307307                <!-- 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">
    309309                    <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/stone.png"/>
    310310                    <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceStone"/>
    311311                </object>
    312312
    313313                <!-- 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">
    315315                    <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/metal.png"/>
    316316                    <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceMetal"/>
    317317                </object>
  • simulation/components/GuiInterface.js

     
    694694    PlaySound(data.name, data.entity);
    695695};
    696696
     697function 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
    697710function isIdleUnit(ent, idleClass)
    698711{
    699712    var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
     
    720733    return 0;
    721734};
    722735
     736GuiInterface.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
    723781GuiInterface.prototype.GetTradingDetails = function(player, data)
    724782{
    725783    var cmpEntityTrader = Engine.QueryInterface(data.trader, IID_Trader);
     
    826884    "GetFoundationSnapData": 1,
    827885    "PlaySound": 1,
    828886    "FindIdleUnit": 1,
     887    "FindResourceGathererByType": 1,
    829888    "GetTradingDetails": 1,
    830889
    831890    "SetPathfinderDebugOverlay": 1,
  • simulation/components/ResourceGatherer.js

     
    6565
    6666    // The last exact type gathered, so we can render appropriate props
    6767    this.lastCarriedType = undefined; // { generic, specific }
     68    this.lastGathered = undefined;
    6869};
    6970
    7071/**
     
    125126        return undefined;
    126127};
    127128
     129ResourceGatherer.prototype.GetLastGathered = function()
     130{
     131    if ( this.lastGathered )
     132        return this.lastGathered.generic;
     133    else
     134        return undefined;
     135}
     136
     137ResourceGatherer.prototype.SetIdleNoGathering = function()
     138{
     139    this.lastGathered = undefined;
     140}
     141
    128142ResourceGatherer.prototype.GetGatherRates = function()
    129143{
    130144    var ret = {};
     
    188202    this.carrying[type.generic] += status.amount;
    189203
    190204    this.lastCarriedType = type;
     205    this.lastGathered = type;
    191206
    192207    // Update stats of how much the player collected.
    193208    // (We have to do it here rather than at the dropsite, because we
  • simulation/helpers/Commands.js

     
    22//  are likely to fail, which may be useful for debugging AIs
    33var g_DebugCommands = false;
    44
     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
     7function 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
    527function ProcessCommand(player, cmd)
    628{
    729    // Do some basic checks here that commanding player is valid
     
    5072        GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) {
    5173            cmpUnitAI.Walk(cmd.x, cmd.z, cmd.queued);
    5274        });
     75        setNotGathering(entities);
    5376        break;
    5477
    5578    case "attack":
     
    6487        GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) {
    6588            cmpUnitAI.Attack(cmd.target, cmd.queued);
    6689        });
     90        setNotGathering(entities);
    6791        break;
    6892
    6993    case "heal":
     
    93117        GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) {
    94118            cmpUnitAI.Repair(cmd.target, cmd.autocontinue, cmd.queued);
    95119        });
     120        setNotGathering(entities);
    96121        break;
    97122
    98123    case "gather":
     
    107132        GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) {
    108133            cmpUnitAI.Gather(cmd.target, cmd.queued);
    109134        });
     135        setNotGathering(entities);
    110136        break;
    111137       
    112138    case "gather-near-position":
     
    114140        GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) {
    115141            cmpUnitAI.GatherNearPosition(cmd.x, cmd.z, cmd.resourceType, cmd.queued);
    116142        });
     143        setNotGathering(entities);
    117144        break;
    118145
    119146    case "returnresource":
     
    288315                "queued": cmd.queued
    289316            });
    290317        }
    291 
     318       
     319        setNotGathering(entities);
    292320        break;
    293321
    294322    case "delete-entities":
     
    339367            GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) {
    340368                cmpUnitAI.Garrison(cmd.target);
    341369            });
     370            setNotGathering(entities);
    342371        }
    343372        else if (g_DebugCommands)
    344373        {