Ticket #1720: patrol_V3.3.patch
File patrol_V3.3.patch, 10.3 KB (added by , 8 years ago) |
---|
-
binaries/data/config/default.cfg
280 280 garrison = Ctrl ; Modifier to garrison when clicking on building 281 281 autorallypoint = Ctrl ; Modifier to set the rally point on the building itself 282 282 guard = "G" ; Modifier to escort/guard when clicking on unit/building 283 patrol = "Y" ; Modifier to patrol a unit 283 284 queue = Shift ; Modifier to queue unit orders instead of replacing 284 285 batchtrain = Shift ; Modifier to train units in batches 285 286 massbarter = Shift ; Modifier to barter bunch of resources -
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; … … 207 208 } 208 209 return { "possible": true, "data": data, "cursor": cursor }; 209 210 } 210 211 return { "possible": (action == "move" || action == "attack-move" || action == "remove-guard" ) };211 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 … … 1160 1161 // of running it immediately 1161 1162 var queued = Engine.HotkeyIsPressed("session.queue"); 1162 1163 var target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); 1163 1164 1164 1165 if (unitActions[action.type] && unitActions[action.type].execute) 1165 1166 return unitActions[action.type].execute(target, action, selection, queued); 1166 1167 error("Invalid action.type "+action.type); -
binaries/data/mods/public/gui/session/unit_actions.js
139 139 "specificness": 10, 140 140 }, 141 141 142 "patrol": 143 { 144 "execute": function(target, action, selection, queued) 145 { 146 var targetClasses = { "attack": ["Unit"] }; // patrol should only attack units - if a new strucure is build near to the patrol, the patrol will recognize the units 147 Engine.PostNetworkCommand({ "type": "patrol", "entities": selection, "x": target.x, "z": target.z, "target": action.target, "targetClasses": targetClasses, "queued": queued, "allowCapture": false }); 148 Engine.GuiInterfaceCall("PlaySound", { "name": "order_patrol", "entity": selection[0] }); 149 return true; 150 }, 151 "getActionInfo": function(entState, targetState) 152 { 153 return { "possible": true }; 154 }, 155 "hotkeyActionCheck": function(target) 156 { 157 if (Engine.HotkeyIsPressed("session.patrol") && getActionInfo("patrol", target).possible) 158 return { "type": "patrol", "cursor": "action-patrol", "target": target }; 159 return false; 160 }, 161 "preSelectedActionCheck" : function(target) 162 { 163 if (preSelectedAction != ACTION_PATROL) 164 return false; 165 if (getActionInfo("patrol", target).possible) 166 return { "type": "patrol", "cursor": "action-patrol", "target": target }; 167 return false; 168 }, 169 "specificness": 37, 170 171 }, 172 142 173 "heal": 143 174 { 144 175 "execute": function(target, action, selection, queued) … … 894 925 toggleTrade(); 895 926 }, 896 927 }, 928 // Patrol 929 "patrol": { 930 "getInfo": function(entState) 931 { 932 if (!entState.unitAI) 933 return false; 934 return { 935 "tooltip": translate("Patrol"), 936 "icon": "patrol.png" 937 }; 938 }, 939 "execute": function(entState) 940 { 941 inputState = INPUT_PRESELECTEDACTION; 942 preSelectedAction = ACTION_PATROL; 943 }, 944 }, 897 945 // Dropsite sharing 898 946 "share-dropsite": { 899 947 "getInfo": function(entState) -
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 cntPosition = Engine.QueryInterface(this.entity, IID_Position); 1116 if (!cntPosition || !cntPosition.IsInWorld()) 1117 { 1118 this.FinishOrder(); 1119 return; 1120 } 1121 this.patrolStartPos = cntPosition.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 var 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 1081 1157 "GARRISON":{ 1082 1158 "enter": function() { 1083 1159 // If the garrisonholder should pickup, warn it so it can take needed action … … 1555 1631 }, 1556 1632 }, 1557 1633 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 cntPosition = Engine.QueryInterface(this.entity, IID_Position); 1641 if (!cntPosition || !cntPosition.IsInWorld()) 1642 { 1643 this.FinishOrder(); 1644 return; 1645 } 1646 this.patrolStartPos = cntPosition.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 1558 1668 "GUARD": { 1559 1669 "RemoveGuard": function() { 1560 1670 this.StopMoving(); … … 1799 1909 } 1800 1910 // Check the target is still alive and attackable 1801 1911 if (this.TargetIsAlive(target) && 1802 1803 1912 this.CanAttack(target, this.order.data.forceResponse || null) && 1913 !this.CheckTargetAttackRange(target, this.order.data.attackType)) 1804 1914 { 1805 1915 // Can't reach it - try to chase after it 1806 1916 if (this.ShouldChaseTargetedEntity(target, this.order.data.force)) … … 2041 2151 var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); 2042 2152 var cmpMirage = Engine.QueryInterface(this.gatheringTarget, IID_Mirage); 2043 2153 if ((!cmpMirage || !cmpMirage.Mirages(IID_ResourceSupply)) && 2044 2154 (!cmpSupply || !cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity))) 2045 2155 { 2046 2156 // Save the current order's data in case we need it later 2047 2157 var oldType = this.order.data.type; … … 3574 3684 error("FinishOrder called for entity " + this.entity + " (" + template + ") when order queue is empty\n" + stack); 3575 3685 } 3576 3686 3687 // next order 3577 3688 this.orderQueue.shift(); 3578 3689 this.order = this.orderQueue[0]; 3579 3690 … … 4785 4896 case "WalkToPointRange": 4786 4897 case "MoveIntoFormation": 4787 4898 case "GatherNearPosition": 4899 case "Patrol": 4788 4900 targetPositions.push(new Vector2D(order.data.x, order.data.z)); 4789 4901 break; // and continue the loop 4790 4902 … … 4997 5109 this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); 4998 5110 }; 4999 5111 5112 UnitAI.prototype.Patrol = function(x, z, targetClasses, queued) 5113 { 5114 this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); 5115 }; 5116 5000 5117 /** 5001 5118 * Adds leave foundation order to queue, treated as forced. 5002 5119 */ -
binaries/data/mods/public/simulation/helpers/Commands.js
174 174 }); 175 175 }, 176 176 177 "patrol": function(player, cmd, data) 178 { 179 GetFormationUnitAIs(data.entities, player).forEach(cmpUnitAI => { 180 cmpUnitAI.Patrol(cmd.x, cmd.z, cmd.targetClasses, cmd.queued); 181 }); 182 }, 183 177 184 "heal": function(player, cmd, data) 178 185 { 179 186 if (g_DebugCommands && !(IsOwnedByPlayer(player, cmd.target) || IsOwnedByAllyOfPlayer(player, cmd.target)))