Ticket #1001: attack-move-v2.diff
File attack-move-v2.diff, 8.1 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
177 177 { 178 178 if (action == "set-rallypoint" && haveRallyPoints) 179 179 return {"possible": true}; 180 else if (action == "move" )180 else if (action == "move" || action == "attack-move") 181 181 return {"possible": true}; 182 182 else 183 183 return {"possible": false}; … … 394 394 break; 395 395 } 396 396 } 397 if (action == "move" )397 if (action == "move" || action == "attack-move") 398 398 return {"possible": true}; 399 399 else 400 400 return {"possible": false}; … … 474 474 { 475 475 if (getActionInfo("garrison", target).possible) 476 476 return {"type": "garrison", "cursor": "action-garrison", "target": target}; 477 else if (getActionInfo("attack-move", target).possible) 478 return {"type": "attack-move", "cursor": "action-attack"}; 477 479 else 478 return 480 return {"type": "none", "cursor": "action-garrison-disabled", "target": undefined}; 479 481 } 480 482 else 481 483 { … … 1307 1309 Engine.GuiInterfaceCall("PlaySound", { "name": "order_walk", "entity": selection[0] }); 1308 1310 return true; 1309 1311 1312 case "attack-move": 1313 var target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); 1314 Engine.PostNetworkCommand({"type": "attack-walk", "entities": selection, "x": target.x, "z": target.z, "queued": queued}); 1315 Engine.GuiInterfaceCall("PlaySound", { "name": "order_walk", "entity": selection[0] }); 1316 return true; 1317 1310 1318 case "attack": 1311 1319 Engine.PostNetworkCommand({"type": "attack", "entities": selection, "target": action.target, "queued": queued}); 1312 1320 Engine.GuiInterfaceCall("PlaySound", { "name": "order_attack", "entity": selection[0] }); … … 1406 1414 Engine.GuiInterfaceCall("PlaySound", { "name": "order_walk", "entity": selection[0] }); 1407 1415 return true; 1408 1416 1417 case "attack-move": 1418 Engine.PostNetworkCommand({"type": "attack-walk", "entities": selection, "x": target.x, "z": target.z, "queued": queued}); 1419 Engine.GuiInterfaceCall("PlaySound", { "name": "order_walk", "entity": selection[0] }); 1420 return true; 1421 1409 1422 case "set-rallypoint": 1410 1423 Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": target.x, "z": target.z}); 1411 1424 // Display rally point at the new coordinates, to avoid display lag -
binaries/data/mods/public/simulation/helpers/Commands.js
88 88 }); 89 89 break; 90 90 91 case "attack-walk": 92 var entities = FilterEntityList(cmd.entities, player, controlAllUnits); 93 GetFormationUnitAIs(entities, player).forEach(function(cmpUnitAI) { 94 cmpUnitAI.WalkAndFight(cmd.x, cmd.z, cmd.queued); 95 }); 96 break; 97 91 98 case "attack": 92 99 if (g_DebugCommands && !(IsOwnedByEnemyOfPlayer(player, cmd.target) || IsOwnedByNeutralOfPlayer(player, cmd.target))) 93 100 { -
binaries/data/mods/public/simulation/components/UnitAI.js
270 270 this.SetNextState("INDIVIDUAL.WALKING"); 271 271 }, 272 272 273 "Order.WalkAndFight": function(msg) { 274 // Let players move captured domestic animals around 275 if (this.IsAnimal() && !this.IsDomestic()) 276 { 277 this.FinishOrder(); 278 return; 279 } 280 281 // For packable units: 282 // 1. If packed, we can move. 283 // 2. If unpacked, we first need to pack, then follow case 1. 284 if (this.CanPack()) 285 { 286 // Case 2: pack 287 this.PushOrderFront("Pack", { "force": true }); 288 return; 289 } 290 291 this.SetHeldPosition(this.order.data.x, this.order.data.z); 292 this.MoveToPoint(this.order.data.x, this.order.data.z); 293 if (this.IsAnimal()) 294 this.SetNextState("ANIMAL.WALKING"); // WalkAndFight not applicable for animals 295 else 296 this.SetNextState("INDIVIDUAL.WALKINGANDFIGHTING"); 297 }, 298 299 273 300 "Order.WalkToTarget": function(msg) { 274 301 // Let players move captured domestic animals around 275 302 if (this.IsAnimal() && !this.IsDomestic()) … … 353 380 if (this.CanUnpack()) 354 381 { 355 382 // Ignore unforced attacks 383 // this would prevent attacks from AttackVisibleEntity or AttackEntityInZone ? 384 // so we accept attacks against targets for which we have a bonus 356 385 // TODO: use special stances instead? 357 if (!this.order.data.force )386 if (!this.order.data.force && this.GetAttackBonus(type, this.order.data.target) < 1.5) 358 387 { 359 388 this.FinishOrder(); 360 389 return; … … 613 642 this.MoveToPoint(this.order.data.x, this.order.data.z); 614 643 this.SetNextState("WALKING"); 615 644 }, 645 646 "Order.WalkAndFight": function(msg) { 647 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); 648 cmpFormation.CallMemberFunction("SetHeldPosition", [msg.data.x, msg.data.z]); 649 650 this.MoveToPoint(this.order.data.x, this.order.data.z); 651 this.SetNextState("WALKINGANDFIGHTING"); 652 }, 616 653 617 654 "Order.MoveIntoFormation": function(msg) { 618 655 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); … … 853 890 }, 854 891 }, 855 892 893 "WALKINGANDFIGHTING": { 894 "enter": function(msg) { 895 this.StartTimer(0, 1000); 896 }, 897 898 "Timer": function(msg) { 899 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); 900 for each (var ent in cmpFormation.members) 901 { 902 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 903 if (cmpUnitAI.FindNewTargets()) 904 { 905 if (cmpUnitAI.orderQueue[0] && cmpUnitAI.orderQueue[0].type == "Attack") 906 { 907 var data = cmpUnitAI.orderQueue[0].data; 908 cmpUnitAI.FinishOrder(); 909 this.PushOrderFront("Attack", { "target": data.target, "force": false, "forceResponse": data.forceResponse }); 910 break; 911 } 912 } 913 } 914 }, 915 916 "leave": function(msg) { 917 this.StopTimer(); 918 }, 919 920 "MoveStarted": function(msg) { 921 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); 922 cmpFormation.SetRearrange(true); 923 cmpFormation.MoveMembersIntoFormation(true, true); 924 }, 925 926 "MoveCompleted": function(msg) { 927 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); 928 929 if (this.FinishOrder()) 930 { 931 cmpFormation.CallMemberFunction("ResetFinishOrder", []); 932 return; 933 } 934 935 // No more orders left. 936 cmpFormation.Disband(); 937 }, 938 }, 939 856 940 "FORMING": { 857 941 "MoveStarted": function(msg) { 858 942 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); … … 1114 1198 }, 1115 1199 }, 1116 1200 1201 "WALKINGANDFIGHTING": { 1202 "enter": function () { 1203 this.StartTimer(0, 1000); 1204 this.SelectAnimation("move"); 1205 }, 1206 1207 "Timer": function(msg) { 1208 this.FindNewTargets(); 1209 }, 1210 1211 "leave": function(msg) { 1212 this.StopTimer(); 1213 }, 1214 1215 "MoveCompleted": function() { 1216 this.FinishOrder(); 1217 }, 1218 }, 1219 1117 1220 "FLEEING": { 1118 1221 "enter": function() { 1119 1222 this.PlaySound("panic"); … … 3181 3284 return cmpAttack.GetBestAttackAgainst(target); 3182 3285 }; 3183 3286 3287 UnitAI.prototype.GetAttackBonus = function(type, target) 3288 { 3289 var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); 3290 if (!cmpAttack) 3291 return 1; 3292 return cmpAttack.GetAttackBonus(type, target); 3293 }; 3294 3184 3295 /** 3185 3296 * Try to find one of the given entities which can be attacked, 3186 3297 * and start attacking it. … … 3393 3504 switch (order.type) 3394 3505 { 3395 3506 case "Walk": 3507 case "WalkAndFight": 3396 3508 case "WalkToPointRange": 3397 3509 case "MoveIntoFormation": 3398 3510 case "GatherNearPosition": … … 3479 3591 }; 3480 3592 3481 3593 /** 3594 * Adds walk-to-target order to queue, this only occurs in response 3595 * to a player order, and so is forced. 3596 */ 3597 UnitAI.prototype.WalkAndFight = function(x, z, queued) 3598 { 3599 this.AddOrder("WalkAndFight", { "x": x, "z": z, "force": true }, queued); 3600 }; 3601 3602 /** 3482 3603 * Adds leave foundation order to queue, treated as forced. 3483 3604 */ 3484 3605 UnitAI.prototype.LeaveFoundation = function(target)