Ticket #1720: patrol_V2.patch
File patrol_V2.patch, 8.0 KB (added by , 8 years ago) |
---|
-
binaries/data/config/default.cfg
278 278 garrison = Ctrl ; Modifier to garrison when clicking on building 279 279 autorallypoint = Ctrl ; Modifier to set the rally point on the building itself 280 280 guard = "G" ; Modifier to escort/guard when clicking on unit/building 281 patrol = "X" ; Modifier to patrol a unit 281 282 queue = Shift ; Modifier to queue unit orders instead of replacing 282 283 batchtrain = Shift ; Modifier to train units in batches 283 284 massbarter = Shift ; Modifier to barter bunch of resources -
binaries/data/mods/public/gui/session/input.js
208 208 return { "possible": true, "data": data, "cursor": cursor }; 209 209 } 210 210 211 if (action == "patrol") 212 { 213 // dirty hack 214 return { "possible": true }; 215 } 216 211 217 return { "possible": (action == "move" || action == "attack-move" || action == "remove-guard") }; 212 218 } 213 219 … … 1161 1167 // of running it immediately 1162 1168 var queued = Engine.HotkeyIsPressed("session.queue"); 1163 1169 var target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); 1164 1170 1165 1171 if (unitActions[action.type] && unitActions[action.type].execute) 1166 1172 return unitActions[action.type].execute(target, action, selection, queued); 1167 1173 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 queued = true; 147 Engine.PostNetworkCommand({"type": "patrol", "entities": selection, "x": target.x, "z": target.z, "target": action.target, "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 let ACTION_PATROL = 9999; // TODO add in input.js and a gui btn 164 /*if (preSelectedAction != ACTION_PATROL) 165 return false; 166 if (getActionInfo("patrol", target).possible) 167 return {"type": "patrol", "cursor": "action-patrol", "target": target}; 168 */ 169 return false; 170 }, 171 "specificness": 37, 172 173 }, 174 142 175 "heal": 143 176 { 144 177 "execute": function(target, action, selection, queued) -
binaries/data/mods/public/simulation/components/UnitAI.js
510 510 this.FinishOrder(); 511 511 }, 512 512 513 "Order.Patrol": function(msg) { 514 // Let players move captured domestic animals around 515 if (this.IsAnimal() && !this.IsDomestic() || this.IsTurret()) 516 { 517 this.FinishOrder(); 518 return; 519 } 520 521 // For packable units: 522 // 1. If packed, we can move. 523 // 2. If unpacked, we first need to pack, then follow case 1. 524 if (this.CanPack()) 525 { 526 // Case 2: pack 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 513 535 "Order.Heal": function(msg) { 514 536 // Check the target is alive 515 537 if (!this.TargetIsAlive(this.order.data.target)) … … 1555 1577 }, 1556 1578 }, 1557 1579 1580 "PATROL": { 1581 "enter": function () { 1582 this.StartTimer(0, 1000); 1583 this.SelectAnimation("move"); 1584 1585 // memorize the origin position in case that we want to go back 1586 let cntPosition = Engine.QueryInterface(this.entity, IID_Position); 1587 if (!cntPosition || !cntPosition.IsInWorld()) 1588 { 1589 this.FinishOrder(); 1590 return; 1591 } 1592 this.patrolStartPos = cntPosition.GetPosition() 1593 }, 1594 1595 "leave": function() { 1596 this.StopTimer(); 1597 }, 1598 1599 "Timer": function(msg) { 1600 this.FindWalkAndFightTargets(); 1601 }, 1602 1603 "MoveCompleted": function() { 1604 1605 // A-B-A-B-..: 1606 // if the user only commands one patrol order, the patrol will be between 1607 // last position and the defined waypoint 1608 // A-B-C-..-A-B-..: 1609 // otherwise, the patrol is only between the given patrol commands and the 1610 // last position (position of the unit at the time of the first order) is 1611 // not included 1612 // -- this is a design decision because the order queue can be extended at 1613 // any time and this makes it difficult to estimate the last walk back to the 1614 // origin position 1615 if (this.orderQueue.length == 1) 1616 { 1617 this.orderQueue.push({"type": "Patrol", "data": this.patrolStartPos}); 1618 } 1619 1620 this.orderQueue.push(this.order); 1621 this.FinishOrder(); 1622 }, 1623 }, 1624 1558 1625 "GUARD": { 1559 1626 "RemoveGuard": function() { 1560 1627 this.StopMoving(); … … 1799 1866 } 1800 1867 // Check the target is still alive and attackable 1801 1868 if (this.TargetIsAlive(target) && 1802 1803 1869 this.CanAttack(target, this.order.data.forceResponse || null) && 1870 !this.CheckTargetAttackRange(target, this.order.data.attackType)) 1804 1871 { 1805 1872 // Can't reach it - try to chase after it 1806 1873 if (this.ShouldChaseTargetedEntity(target, this.order.data.force)) … … 2035 2102 var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply); 2036 2103 var cmpMirage = Engine.QueryInterface(this.gatheringTarget, IID_Mirage); 2037 2104 if ((!cmpMirage || !cmpMirage.Mirages(IID_ResourceSupply)) && 2038 2105 (!cmpSupply || !cmpSupply.AddGatherer(cmpOwnership.GetOwner(), this.entity))) 2039 2106 { 2040 2107 // Save the current order's data in case we need it later 2041 2108 var oldType = this.order.data.type; … … 3563 3630 error("FinishOrder called for entity " + this.entity + " (" + template + ") when order queue is empty\n" + stack); 3564 3631 } 3565 3632 3633 // next order 3566 3634 this.orderQueue.shift(); 3567 3635 this.order = this.orderQueue[0]; 3568 3636 … … 4759 4827 case "WalkToPointRange": 4760 4828 case "MoveIntoFormation": 4761 4829 case "GatherNearPosition": 4830 case "Patrol": 4762 4831 targetPositions.push(new Vector2D(order.data.x, order.data.z)); 4763 4832 break; // and continue the loop 4764 4833 … … 4971 5040 this.AddOrder("WalkAndFight", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued); 4972 5041 }; 4973 5042 5043 UnitAI.prototype.Patrol = function(x, z, queued) 5044 { 5045 this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": "[ UNIT ]", "force": true }, queued); 5046 }; 5047 4974 5048 /** 4975 5049 * Adds leave foundation order to queue, treated as forced. 4976 5050 */ -
binaries/data/mods/public/simulation/helpers/Commands.js
156 156 }); 157 157 }, 158 158 159 "patrol": function(player, cmd, data) 160 { 161 GetFormationUnitAIs(data.entities, player).forEach(function(cmpUnitAI) { 162 cmpUnitAI.Patrol(cmd.x, cmd.z, cmd.queued); 163 }); 164 }, 165 159 166 "heal": function(player, cmd, data) 160 167 { 161 168 if (g_DebugCommands && !(IsOwnedByPlayer(player, cmd.target) || IsOwnedByAllyOfPlayer(player, cmd.target)))