Ticket #1720: patrol_V3.11.patch

File patrol_V3.11.patch, 9.1 KB (added by Imarok, 8 years ago)

Fix units just moving and not attack-moving when patrolling (Found by fatherbushido)

  • binaries/data/config/default.cfg

     
    286286garrison = Ctrl              ; Modifier to garrison when clicking on building
    287287autorallypoint = Ctrl        ; Modifier to set the rally point on the building itself
    288288guard = "G"                  ; Modifier to escort/guard when clicking on unit/building
     289patrol = "P"                 ; Modifier to patrol a unit
    289290repair = "J"                 ; Modifier to repair when clicking on building/mechanical unit
    290291queue = Shift                ; Modifier to queue unit orders instead of replacing
    291292batchtrain = Shift           ; Modifier to train units in batches
  • binaries/data/mods/public/gui/manual/intro.txt

     
    8484[font="sans-bold-14"]Modify mouse action
    8585[font="sans-14"]Ctrl + Right Click on building: Garrison
    8686J + Right Click on building: Repair
     87P + Right Click: Patrol
    8788Shift + Right Click: Queue the move/build/gather/etc order
    8889Shift + Left click when training unit/s: Add units in batches of five
    8990Shift + Left Click or Left Drag over unit on map: Add unit to selection
  • binaries/data/mods/public/gui/session/input.js

     
    1616const ACTION_GARRISON = 1;
    1717const ACTION_REPAIR = 2;
    1818const ACTION_GUARD = 3;
     19const ACTION_PATROL = 4;
    1920var preSelectedAction = ACTION_NONE;
    2021
    2122const INPUT_NORMAL = 0;
     
    207208            }
    208209            return { "possible": true, "data": data, "cursor": cursor };
    209210        }
    210 
    211         return { "possible": (action == "move" || action == "attack-move" || action == "remove-guard") };
     211        return { "possible": ["move", "attack-move", "remove-guard", "patrol"].indexOf(action) > -1 };
    212212    }
    213213
    214214    // Look at the first targeted entity
  • binaries/data/mods/public/gui/session/unit_actions.js

     
    208208        "specificness": 10,
    209209    },
    210210
     211    "patrol":
     212    {
     213        "execute": function(target, action, selection, queued)
     214        {
     215            Engine.PostNetworkCommand({
     216                "type": "patrol",
     217                "entities": selection,
     218                "x": target.x,
     219                "z": target.z,
     220                "target": action.target,
     221                "targetClasses": { "attack": ["Unit"] }, // patrol should only attack units
     222                "queued": queued,
     223                "allowCapture": false
     224            });
     225            Engine.GuiInterfaceCall("PlaySound", { "name": "order_patrol", "entity": selection[0] });
     226            return true;
     227        },
     228        "getActionInfo": function(entState, targetState)
     229        {
     230            return { "possible": true };
     231        },
     232        "hotkeyActionCheck": function(target)
     233        {
     234            if (!Engine.HotkeyIsPressed("session.patrol") || !getActionInfo("patrol", target).possible)
     235                return false;
     236            return {
     237                "type": "patrol",
     238                "cursor": "action-patrol",
     239                "target": target
     240            };
     241        },
     242        "preSelectedActionCheck" : function(target)
     243        {
     244            if (preSelectedAction != ACTION_PATROL || !getActionInfo("patrol", target).possible)
     245                return false;
     246            return {
     247                "type": "patrol",
     248                "cursor": "action-patrol",
     249                "target": target
     250            };
     251        },
     252        "specificness": 37,
     253    },
     254
    211255    "heal":
    212256    {
    213257        "execute": function(target, action, selection, queued)
     
    12181262        },
    12191263    },
    12201264
     1265    "patrol": {
     1266        "getInfo": function(entState)
     1267        {
     1268            if (g_Selection.toList().every(ent => !GetExtendedEntityState(ent).unitAI))
     1269                return false;
     1270            return {
     1271                "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.patrol") + translate("Patrol"),
     1272                "icon": "patrol.png"
     1273            };
     1274        },
     1275        "execute": function(entState)
     1276        {
     1277            inputState = INPUT_PRESELECTEDACTION;
     1278            preSelectedAction = ACTION_PATROL;
     1279        },
     1280    },
     1281
    12211282    "share-dropsite": {
    12221283        "getInfo": function(entState)
    12231284        {
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    514514        this.FinishOrder();
    515515    },
    516516
     517    "Order.Patrol": function(msg) {
     518        // Let players move captured domestic animals around
     519        if (this.IsAnimal() || this.IsTurret())
     520        {
     521            this.FinishOrder();
     522            return;
     523        }
     524
     525        if (this.CanPack())
     526        {
     527            this.PushOrderFront("Pack", { "force": true });
     528            return;
     529        }
     530
     531        this.MoveToPoint(this.order.data.x, this.order.data.z);
     532        this.SetNextState("INDIVIDUAL.PATROL");
     533    },
     534
    517535    "Order.Heal": function(msg) {
    518536        // Check the target is alive
    519537        if (!this.TargetIsAlive(this.order.data.target))
     
    829847                this.FinishOrder();
    830848        },
    831849
     850        "Order.Patrol": function(msg) {
     851            this.CallMemberFunction("SetHeldPosition", [msg.data.x, msg.data.z]);
     852
     853            this.MoveToPoint(this.order.data.x, this.order.data.z);
     854            this.SetNextState("PATROL");
     855        },
     856
    832857        "Order.Guard": function(msg) {
    833858            this.CallMemberFunction("Guard", [msg.data.target, false]);
    834859            var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
     
    10781103            },
    10791104        },
    10801105
     1106        "PATROL": {
     1107            "enter": function(msg) {
     1108                // Memorize the origin position in case that we want to go back
     1109                let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     1110                if (!cmpPosition || !cmpPosition.IsInWorld())
     1111                {
     1112                    this.FinishOrder();
     1113                    return;
     1114                }
     1115                this.StartTimer(0, 1000);
     1116                this.patrolStartPos = cmpPosition.GetPosition();
     1117            },
     1118
     1119            "Timer": function(msg) {
     1120                // Check if there are no enemies to attack
     1121                this.FindWalkAndFightTargets();
     1122            },
     1123
     1124            "leave": function(msg) {
     1125                this.StopTimer();
     1126            },
     1127
     1128            "MoveStarted": function(msg) {
     1129                let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
     1130                cmpFormation.SetRearrange(true);
     1131                cmpFormation.MoveMembersIntoFormation(true, true);
     1132            },
     1133
     1134            "MoveCompleted": function() {
     1135                /**
     1136                 * A-B-A-B-..:
     1137                 * if the user only commands one patrol order, the patrol will be between
     1138                 * the last position and the defined waypoint
     1139                 * A-B-C-..-A-B-..:
     1140                 * otherwise, the patrol is only between the given patrol commands and the
     1141                 * last position is not included (last position = the position where the unit
     1142                 * is located at the time of the first patrol order)
     1143                 */
     1144
     1145                if (this.orderQueue.length == 1)
     1146                    this.PushOrder("Patrol", this.patrolStartPos);
     1147
     1148                this.PushOrder(this.order.type, this.order.data);
     1149                this.FinishOrder();
     1150            },
     1151        },
     1152
    10811153        "GARRISON":{
    10821154            "enter": function() {
    10831155                // If the garrisonholder should pickup, warn it so it can take needed action
     
    15551627            },
    15561628        },
    15571629
     1630        "PATROL": {
     1631            "enter": function () {
     1632                this.StartTimer(0, 1000);
     1633                this.SelectAnimation("move");
     1634
     1635                // Memorize the origin position in case that we want to go back
     1636                let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     1637                if (!cmpPosition || !cmpPosition.IsInWorld())
     1638                {
     1639                    this.FinishOrder();
     1640                    return;
     1641                }
     1642                this.patrolStartPos = cmpPosition.GetPosition();
     1643            },
     1644
     1645            "leave": function() {
     1646                this.StopTimer();
     1647            },
     1648
     1649            "Timer": function(msg) {
     1650                this.FindWalkAndFightTargets();
     1651            },
     1652
     1653            "MoveCompleted": function() {
     1654                if (this.orderQueue.length == 1)
     1655                    this.PushOrder("Patrol",this.patrolStartPos);
     1656
     1657                this.PushOrder(this.order.type, this.order.data);
     1658                this.FinishOrder();
     1659            },
     1660        },
     1661
    15581662        "GUARD": {
    15591663            "RemoveGuard": function() {
    15601664                this.StopMoving();
     
    47574861        case "WalkToPointRange":
    47584862        case "MoveIntoFormation":
    47594863        case "GatherNearPosition":
     4864        case "Patrol":
    47604865            targetPositions.push(new Vector2D(order.data.x, order.data.z));
    47614866            break; // and continue the loop
    47624867
     
    49695074    this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued);
    49705075};
    49715076
     5077UnitAI.prototype.Patrol = function(x, z, targetClasses, queued)
     5078{
     5079    this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued);
     5080};
     5081
    49725082/**
    49735083 * Adds leave foundation order to queue, treated as forced.
    49745084 */
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    176176        });
    177177    },
    178178
     179    "patrol": function(player, cmd, data)
     180    {
     181        GetFormationUnitAIs(data.entities, player).forEach(cmpUnitAI =>
     182            cmpUnitAI.Patrol(cmd.x, cmd.z, cmd.targetClasses, cmd.queued)
     183        );
     184    },
     185
    179186    "heal": function(player, cmd, data)
    180187    {
    181188        if (g_DebugCommands && !(IsOwnedByPlayer(player, cmd.target) || IsOwnedByAllyOfPlayer(player, cmd.target)))