Ticket #1720: patrol_V3.12.patch
File patrol_V3.12.patch, 10.2 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/manual/intro.txt
84 84 [font="sans-bold-14"]Modify mouse action 85 85 [font="sans-14"]Ctrl + Right Click on building: Garrison 86 86 J + Right Click on building: Repair 87 P + Right Click: Patrol 87 88 Shift + Right Click: Queue the move/build/gather/etc order 88 89 Shift + Left click when training unit/s: Add units in batches of five 89 90 Shift + Left Click or Left Drag over unit on map: Add unit to selection -
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; … … 205 206 data.targetClasses = Engine.HotkeyIsPressed("session.attackmoveUnit") ? { "attack": ["Unit"] } : { "attack": ["Unit", "Structure"] }; 206 207 cursor = "action-attack-move"; 207 208 } 209 else if (Engine.HotkeyIsPressed("session.patrol")) 210 { 211 data.command = "patrol"; 212 data.targetClasses = { "attack": ["Unit"] }; 213 cursor = "action-patrol"; 214 } 208 215 return { "possible": true, "data": data, "cursor": cursor }; 209 216 } 210 217 211 return { "possible": (action == "move" || action == "attack-move" || action == "remove-guard")};218 return { "possible": ["move", "attack-move", "remove-guard", "patrol"].indexOf(action) > -1 }; 212 219 } 213 220 214 221 // 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, selection) 233 { 234 if (!someUnitAI(selection) || 235 !Engine.HotkeyIsPressed("session.patrol") || 236 !getActionInfo("patrol", target).possible) 237 return false; 238 return { 239 "type": "patrol", 240 "cursor": "action-patrol", 241 "target": target 242 }; 243 }, 244 "preSelectedActionCheck" : function(target) 245 { 246 if (preSelectedAction != ACTION_PATROL || !getActionInfo("patrol", target).possible) 247 return false; 248 return { 249 "type": "patrol", 250 "cursor": "action-patrol", 251 "target": target 252 }; 253 }, 254 "specificness": 37, 255 }, 256 211 257 "heal": 212 258 { 213 259 "execute": function(target, action, selection, queued) … … 1218 1264 }, 1219 1265 }, 1220 1266 1267 "patrol": { 1268 "getInfo": function(entState) 1269 { 1270 if (g_Selection.toList().every(ent => !GetExtendedEntityState(ent).unitAI)) 1271 return false; 1272 return { 1273 "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.patrol") + translate("Patrol"), 1274 "icon": "patrol.png" 1275 }; 1276 }, 1277 "execute": function(entState) 1278 { 1279 inputState = INPUT_PRESELECTEDACTION; 1280 preSelectedAction = ACTION_PATROL; 1281 }, 1282 }, 1283 1221 1284 "share-dropsite": { 1222 1285 "getInfo": function(entState) 1223 1286 { -
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 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 517 535 "Order.Heal": function(msg) { 518 536 // Check the target is alive 519 537 if (!this.TargetIsAlive(this.order.data.target)) … … 829 847 this.FinishOrder(); 830 848 }, 831 849 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 832 857 "Order.Guard": function(msg) { 833 858 this.CallMemberFunction("Guard", [msg.data.target, false]); 834 859 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); … … 1078 1103 }, 1079 1104 }, 1080 1105 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 1081 1153 "GARRISON":{ 1082 1154 "enter": function() { 1083 1155 // If the garrisonholder should pickup, warn it so it can take needed action … … 1555 1627 }, 1556 1628 }, 1557 1629 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 1558 1662 "GUARD": { 1559 1663 "RemoveGuard": function() { 1560 1664 this.StopMoving(); … … 4757 4861 case "WalkToPointRange": 4758 4862 case "MoveIntoFormation": 4759 4863 case "GatherNearPosition": 4864 case "Patrol": 4760 4865 targetPositions.push(new Vector2D(order.data.x, order.data.z)); 4761 4866 break; // and continue the loop 4762 4867 … … 4969 5074 this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); 4970 5075 }; 4971 5076 5077 UnitAI.prototype.Patrol = function(x, z, targetClasses, queued) 5078 { 5079 this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); 5080 }; 5081 4972 5082 /** 4973 5083 * Adds leave foundation order to queue, treated as forced. 4974 5084 */ -
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))) -
binaries/data/mods/public/simulation/helpers/RallyPointCommands.js
70 70 "queued": true 71 71 }); 72 72 break; 73 case "patrol": 74 ret.push( { 75 "type": "patrol", 76 "entities": spawnedEnts, 77 "x": rallyPos[i].x, 78 "z": rallyPos[i].z, 79 "target": data[i].target, 80 "targetClasses": data[i].targetClasses, 81 "queued": true 82 }); 83 break; 73 84 case "attack": 74 85 ret.push( { 75 86 "type": "attack",