Ticket #1720: patrol_V3.7.patch

File patrol_V3.7.patch, 8.6 KB (added by Imarok, 8 years ago)

Made the changes of comment 15

  • binaries/data/config/default.cfg

     
    284284garrison = Ctrl              ; Modifier to garrison when clicking on building
    285285autorallypoint = Ctrl        ; Modifier to set the rally point on the building itself
    286286guard = "G"                  ; Modifier to escort/guard when clicking on unit/building
     287patrol = "P"                 ; Modifier to patrol a unit
    287288queue = Shift                ; Modifier to queue unit orders instead of replacing
    288289batchtrain = Shift           ; Modifier to train units in batches
    289290massbarter = Shift           ; Modifier to barter bunch of resources
  • 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;
     
    208209            return { "possible": true, "data": data, "cursor": cursor };
    209210        }
    210211
    211         return { "possible": (action == "move" || action == "attack-move" || action == "remove-guard") };
     212        return { "possible": (action == "move" || action == "attack-move" || action == "remove-guard" || action == "patrol") };
    212213    }
    213214
    214215    // 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)
     
    12091253        },
    12101254    },
    12111255
     1256    "patrol": {
     1257        "getInfo": function(entState)
     1258        {
     1259            if (!entState.unitAI)
     1260                return false;
     1261            return {
     1262                "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.patrol") + translate("Patrol"),
     1263                "icon": "patrol.png"
     1264            };
     1265        },
     1266        "execute": function(entState)
     1267        {
     1268            inputState = INPUT_PRESELECTEDACTION;
     1269            preSelectedAction = ACTION_PATROL;
     1270        },
     1271    },
     1272
    12121273    "share-dropsite": {
    12131274        "getInfo": function(entState)
    12141275        {
  • 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        // For packable units:
     526        // 1. If packed, we can move.
     527        // 2. If unpacked, we first need to pack, then follow case 1.
     528        if (this.CanPack())
     529        {
     530            // Case 2: pack
     531            this.PushOrderFront("Pack", { "force": true });
     532            return;
     533        }
     534
     535        this.MoveToPoint(this.order.data.x, this.order.data.z);
     536        this.SetNextState("INDIVIDUAL.PATROL");
     537    },
     538
    517539    "Order.Heal": function(msg) {
    518540        // Check the target is alive
    519541        if (!this.TargetIsAlive(this.order.data.target))
     
    829851                this.FinishOrder();
    830852        },
    831853
     854        "Order.Patrol": function(msg) {
     855            this.CallMemberFunction("SetHeldPosition", [msg.data.x, msg.data.z]);
     856
     857            this.MoveToPoint(this.order.data.x, this.order.data.z);
     858            this.SetNextState("PATROL");
     859        },
     860
    832861        "Order.Guard": function(msg) {
    833862            this.CallMemberFunction("Guard", [msg.data.target, false]);
    834863            var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
     
    10781107            },
    10791108        },
    10801109
     1110        "PATROL": {
     1111            "enter": function(msg) {
     1112                this.StartTimer(0, 1000);
     1113
     1114                // memorize the origin position in case that we want to go back
     1115                let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     1116                if (!cmpPosition || !cmpPosition.IsInWorld())
     1117                {
     1118                    this.FinishOrder();
     1119                    return;
     1120                }
     1121                this.patrolStartPos = cmpPosition.GetPosition();
     1122            },
     1123
     1124            "Timer": function(msg) {
     1125                // check if there are no enemies to attack
     1126                this.FindWalkAndFightTargets();
     1127            },
     1128
     1129            "leave": function(msg) {
     1130                this.StopTimer();
     1131            },
     1132
     1133            "MoveStarted": function(msg) {
     1134                let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation);
     1135                cmpFormation.SetRearrange(true);
     1136                cmpFormation.MoveMembersIntoFormation(true, true);
     1137            },
     1138
     1139            "MoveCompleted": function() {   
     1140                // A-B-A-B-..:
     1141                // if the user only commands one patrol order, the patrol will be between
     1142                // the last position and the defined waypoint
     1143                // A-B-C-..-A-B-..:
     1144                // otherwise, the patrol is only between the given patrol commands and the
     1145                // last position is not included (last position = the position where the unit
     1146                // is located at the time of the first patrol order)
     1147                if (this.orderQueue.length == 1)
     1148                {
     1149                    this.orderQueue.push({ "type": "Patrol", "data": this.patrolStartPos });
     1150                }
     1151
     1152                this.orderQueue.push(this.order);
     1153                this.FinishOrder();
     1154            },
     1155        },
     1156
    10811157        "GARRISON":{
    10821158            "enter": function() {
    10831159                // If the garrisonholder should pickup, warn it so it can take needed action
     
    15551631            },
    15561632        },
    15571633
     1634        "PATROL": {
     1635            "enter": function () {
     1636                this.StartTimer(0, 1000);
     1637                this.SelectAnimation("move");
     1638
     1639                // memorize the origin position in case that we want to go back
     1640                let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
     1641                if (!cmpPosition || !cmpPosition.IsInWorld())
     1642                {
     1643                    this.FinishOrder();
     1644                    return;
     1645                }
     1646                this.patrolStartPos = cmpPosition.GetPosition();
     1647            },
     1648
     1649            "leave": function() {
     1650                this.StopTimer();
     1651            },
     1652
     1653            "Timer": function(msg) {
     1654                this.FindWalkAndFightTargets();
     1655            },
     1656
     1657            "MoveCompleted": function() {
     1658                if (this.orderQueue.length == 1)
     1659                {
     1660                    this.orderQueue.push({"type": "Patrol", "data": this.patrolStartPos});
     1661                }
     1662
     1663                this.orderQueue.push(this.order);
     1664                this.FinishOrder();
     1665            },
     1666        },
     1667
    15581668        "GUARD": {
    15591669            "RemoveGuard": function() {
    15601670                this.StopMoving();
     
    47854895        case "WalkToPointRange":
    47864896        case "MoveIntoFormation":
    47874897        case "GatherNearPosition":
     4898        case "Patrol":
    47884899            targetPositions.push(new Vector2D(order.data.x, order.data.z));
    47894900            break; // and continue the loop
    47904901
     
    49975108    this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued);
    49985109};
    49995110
     5111UnitAI.prototype.Patrol = function(x, z, targetClasses, queued)
     5112{
     5113    this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued);
     5114};
     5115
    50005116/**
    50015117 * Adds leave foundation order to queue, treated as forced.
    50025118 */
  • 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)))