Ticket #2189: rallypointCleaning.diff

File rallypointCleaning.diff, 7.7 KB (added by mimo, 11 years ago)
  • binaries/data/mods/public/gui/session/input.js

     
    185185    if (!entState)
    186186        return {"possible": false};
    187187
    188     // If the selection isn't friendly units, no action
    189     var playerID = Engine.GetPlayerID();
    190     var allOwnedByPlayer = selection.every(function(ent) {
    191         var entState = GetEntityState(ent);
    192         return entState && entState.player == playerID;
    193     });
    194 
    195     if (!g_DevSettings.controlAll && !allOwnedByPlayer)
    196         return {"possible": false};
    197 
    198     // Work out whether the selection can have rally points
    199     var haveRallyPoints = selection.every(function(ent) {
    200         var entState = GetEntityState(ent);
    201         return entState && entState.rallyPoint;
    202     });
    203 
    204     // Work out whether at least part of the selection have UnitAI
    205     var haveUnitAI = selection.some(function(ent) {
    206         var entState = GetEntityState(ent);
    207         return entState && entState.unitAI;
    208     });
    209 
    210188    if (!target)
    211189    {
    212         if (action == "set-rallypoint" && haveRallyPoints)
     190        if (action == "set-rallypoint")
    213191        {
    214192            var cursor = "";
    215193            var data = {command: "walk"};
     
    220198            }
    221199            return {"possible": true, "data": data, "cursor": cursor};
    222200        }
    223         else if (haveUnitAI && (action == "move" || action == "attack-move"))
     201        else if (action == "move" || action == "attack-move")
    224202            return {"possible": true};
    225203        else
    226204            return {"possible": false};
    227205    }
    228206
    229     if (haveRallyPoints && selection.indexOf(target) != -1 && action == "unset-rallypoint")
     207    if (action == "unset-rallypoint" && selection.indexOf(target) != -1)
    230208        return {"possible": true};
    231209
    232210    // Look at the first targeted entity
     
    235213    var targetState = GetEntityState(target);
    236214
    237215    // Look to see what type of command units going to the rally point should use
    238     if (haveRallyPoints && action == "set-rallypoint")
     216    if (action == "set-rallypoint")
    239217    {
    240         // haveRallyPoints ensures all selected entities can have rally points.
    241218        // We assume that all entities are owned by the same player.
    242219        var entState = GetEntityState(selection[0]);
    243220
     
    248225        var enemyOwned = playerState.isEnemy[targetState.player];
    249226        var gaiaOwned = (targetState.player == 0);
    250227
    251         var cursor = "";
    252228        var tooltip;
    253 
    254         // default to walking there
     229        // default to walking there (or attack-walking if hotkey pressed)
    255230        var data = {command: "walk"};
     231        var cursor = "";
    256232        if (Engine.HotkeyIsPressed("session.attackmove"))
    257233        {
    258234            data = {command: "attack-walk"};
     
    273249        {
    274250            var resourceType = targetState.resourceSupply.type;
    275251            if (resourceType.generic == "treasure")
    276             {
    277252                cursor = "action-gather-" + resourceType.generic;
    278             }
    279253            else
    280             {
    281254                cursor = "action-gather-" + resourceType.specific;
    282             }
    283255            data.command = "gather";
    284256            data.resourceType = resourceType;
    285257            data.resourceTemplate = targetState.template;
     
    414386                for each (var unitClass in targetState.identity.classes)
    415387                {
    416388                    if (unhealableClasses.indexOf(unitClass) != -1)
    417                     {
    418389                        return {"possible": false};
    419                     }
    420390                }
    421391               
    422392                var healableClasses = entState.Healer.healableClasses;
    423393                for each (var unitClass in targetState.identity.classes)
    424394                {
    425395                    if (healableClasses.indexOf(unitClass) != -1)
    426                     {
    427396                        return {"possible": true};
    428                     }
    429397                }
    430398            }
    431399            break;
     
    455423            break;
    456424        }
    457425    }
    458     if (haveUnitAI && (action == "move" || action == "attack-move"))
     426    if (action == "move" || action == "attack-move")
    459427        return {"possible": true};
    460428    else
    461429        return {"possible": false};
     
    490458    if (!g_DevSettings.controlAll && !allOwnedByPlayer)
    491459        return undefined;
    492460
    493     // Work out whether the selection can have rally points
    494     var haveRallyPoints = selection.every(function(ent) {
     461    // Work out whether at least part of the selection have UnitAI
     462    var haveUnitAI = selection.some(function(ent) {
    495463        var entState = GetEntityState(ent);
     464        return entState && entState.unitAI;
     465    });
     466
     467    // Work out whether at least part the selection have rally points
     468    // while none have UnitAI
     469    var haveRallyPoints = !haveUnitAI && selection.some(function(ent) {
     470        var entState = GetEntityState(ent);
    496471        return entState && entState.rallyPoint;
    497472    });
    498473
    499474    var targets = [];
    500475    var target = undefined;
    501     var type = "none";
    502476    var cursor = "";
    503477    var targetState = undefined;
    504478    if (!fromMinimap)
    505479        targets = Engine.PickEntitiesAtPoint(x, y);
    506480
    507481    if (targets.length)
    508     {
    509482        target = targets[0];
    510     }
    511483
    512484    var actionInfo = undefined;
    513485    if (preSelectedAction != ACTION_NONE)
     
    536508    {
    537509        return {"type": "garrison", "cursor": "action-garrison", "tooltip": actionInfo.tooltip, "target": target};
    538510    }
    539     else if (Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target).possible)
     511    else if (haveUnitAI && Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target).possible)
    540512    {
    541513            return {"type": "attack-move", "cursor": "action-attack-move"};
    542514    }
     
    552524            return {"type": "build", "cursor": "action-build", "target": target};
    553525        else if (getActionInfo("repair", target).possible)
    554526            return {"type": "build", "cursor": "action-repair", "target": target};
    555         else if ((actionInfo = getActionInfo("set-rallypoint", target)).possible)
     527        else if (haveRallyPoints && (actionInfo = getActionInfo("set-rallypoint", target)).possible)
    556528            return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, "tooltip": actionInfo.tooltip, "position": actionInfo.position};
    557529        else if (getActionInfo("heal", target).possible)
    558530            return {"type": "heal", "cursor": "action-heal", "target": target};
    559531        else if (getActionInfo("attack", target).possible)
    560532            return {"type": "attack", "cursor": "action-attack", "target": target};
    561         else if (getActionInfo("unset-rallypoint", target).possible)
     533        else if (haveRallyPoints && getActionInfo("unset-rallypoint", target).possible)
    562534            return {"type": "unset-rallypoint"};
    563         else if (getActionInfo("move", target).possible)
     535        else if (haveUnitAI && getActionInfo("move", target).possible)
    564536            return {"type": "move"};
    565537    }
    566     return {"type": type, "cursor": cursor, "target": target};
     538    return {"type": "none", "cursor": cursor, "target": target};
    567539}
    568540
    569541
     
    577549        return false;
    578550    }
    579551
    580     var selection = g_Selection.toList();
    581 
    582552    // Use the preview to check it's a valid build location
    583553    if (!updateBuildingPlacementPreview())
    584554    {
     
    587557        return false;
    588558    }
    589559
     560    var selection = g_Selection.toList();
     561
    590562    // Start the construction
    591563    Engine.PostNetworkCommand({
    592564        "type": "construct",
     
    879851        case "mousebuttonup":
    880852            if (ev.button === SDL_BUTTON_LEFT)
    881853            {
    882                 inputState = INPUT_BUILDING_WALL_PATHING;
    883                 return true;
     854                inputState = INPUT_BUILDING_WALL_PATHING;
     855                return true;
    884856            }
    885857            break;
    886858           
     
    13231295                else
    13241296                {
    13251297                    placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y);
    1326                     dragStart = [ ev.x, ev.y ];
    1327                     inputState = INPUT_BUILDING_CLICK;
     1298                    dragStart = [ ev.x, ev.y ];
     1299                    inputState = INPUT_BUILDING_CLICK;
    13281300                }
    13291301                return true;
    13301302            }
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    10921092            var gates = [];
    10931093            for (var i in selection)
    10941094            {
    1095                 state = GetEntityState(selection[i]);
     1095                var state = GetEntityState(selection[i]);
    10961096                if (hasClass(state, "LongWall") && !state.gate && !longWallTypes[state.template])
    10971097                {
    10981098                    var gateTemplate = getWallGateTemplate(state.id);