Ticket #1720: patrol_V3.8.patch
File patrol_V3.8.patch, 8.6 KB (added by , 8 years ago) |
---|
-
binaries/data/config/default.cfg
286 286 garrison = Ctrl ; Modifier to garrison when clicking on building 287 287 autorallypoint = Ctrl ; Modifier to set the rally point on the building itself 288 288 guard = "G" ; Modifier to escort/guard when clicking on unit/building 289 patrol = "P" ; Modifier to patrol a unit 289 290 repair = "J" ; Modifier to repair when clicking on building/mechanical unit 290 291 queue = Shift ; Modifier to queue unit orders instead of replacing 291 292 batchtrain = Shift ; Modifier to train units in batches -
binaries/data/mods/public/gui/session/input.js
16 16 const ACTION_GARRISON = 1; 17 17 const ACTION_REPAIR = 2; 18 18 const ACTION_GUARD = 3; 19 const ACTION_PATROL = 4; 19 20 var preSelectedAction = ACTION_NONE; 20 21 21 22 const INPUT_NORMAL = 0; … … 208 209 return { "possible": true, "data": data, "cursor": cursor }; 209 210 } 210 211 211 return { "possible": (action == "move" || action == "attack-move" || action == "remove-guard" ) };212 return { "possible": (action == "move" || action == "attack-move" || action == "remove-guard" || action == "patrol") }; 212 213 } 213 214 214 215 // Look at the first targeted entity -
binaries/data/mods/public/gui/session/unit_actions.js
208 208 "specificness": 10, 209 209 }, 210 210 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 211 255 "heal": 212 256 { 213 257 "execute": function(target, action, selection, queued) … … 1218 1262 }, 1219 1263 }, 1220 1264 1265 "patrol": { 1266 "getInfo": function(entState) 1267 { 1268 if (!entState.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 1221 1282 "share-dropsite": { 1222 1283 "getInfo": function(entState) 1223 1284 { -
binaries/data/mods/public/simulation/components/UnitAI.js
514 514 this.FinishOrder(); 515 515 }, 516 516 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 517 539 "Order.Heal": function(msg) { 518 540 // Check the target is alive 519 541 if (!this.TargetIsAlive(this.order.data.target)) … … 829 851 this.FinishOrder(); 830 852 }, 831 853 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 832 861 "Order.Guard": function(msg) { 833 862 this.CallMemberFunction("Guard", [msg.data.target, false]); 834 863 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); … … 1078 1107 }, 1079 1108 }, 1080 1109 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 this.orderQueue.push({ "type": "Patrol", "data": this.patrolStartPos }); 1149 1150 this.orderQueue.push(this.order); 1151 this.FinishOrder(); 1152 }, 1153 }, 1154 1081 1155 "GARRISON":{ 1082 1156 "enter": function() { 1083 1157 // If the garrisonholder should pickup, warn it so it can take needed action … … 1555 1629 }, 1556 1630 }, 1557 1631 1632 "PATROL": { 1633 "enter": function () { 1634 this.StartTimer(0, 1000); 1635 this.SelectAnimation("move"); 1636 1637 // memorize the origin position in case that we want to go back 1638 let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); 1639 if (!cmpPosition || !cmpPosition.IsInWorld()) 1640 { 1641 this.FinishOrder(); 1642 return; 1643 } 1644 this.patrolStartPos = cmpPosition.GetPosition(); 1645 }, 1646 1647 "leave": function() { 1648 this.StopTimer(); 1649 }, 1650 1651 "Timer": function(msg) { 1652 this.FindWalkAndFightTargets(); 1653 }, 1654 1655 "MoveCompleted": function() { 1656 if (this.orderQueue.length == 1) 1657 this.orderQueue.push({ "type": "Patrol", "data": this.patrolStartPos }); 1658 1659 this.orderQueue.push(this.order); 1660 this.FinishOrder(); 1661 }, 1662 }, 1663 1558 1664 "GUARD": { 1559 1665 "RemoveGuard": function() { 1560 1666 this.StopMoving(); … … 4779 4885 case "WalkToPointRange": 4780 4886 case "MoveIntoFormation": 4781 4887 case "GatherNearPosition": 4888 case "Patrol": 4782 4889 targetPositions.push(new Vector2D(order.data.x, order.data.z)); 4783 4890 break; // and continue the loop 4784 4891 … … 4991 5098 this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); 4992 5099 }; 4993 5100 5101 UnitAI.prototype.Patrol = function(x, z, targetClasses, queued) 5102 { 5103 this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); 5104 }; 5105 4994 5106 /** 4995 5107 * Adds leave foundation order to queue, treated as forced. 4996 5108 */ -
binaries/data/mods/public/simulation/helpers/Commands.js
176 176 }); 177 177 }, 178 178 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 179 186 "heal": function(player, cmd, data) 180 187 { 181 188 if (g_DebugCommands && !(IsOwnedByPlayer(player, cmd.target) || IsOwnedByAllyOfPlayer(player, cmd.target)))