Ticket #3481: visibleGarrison.diff
File visibleGarrison.diff, 5.8 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/GarrisonHolder.js
224 224 * Garrison a unit inside. 225 225 * Returns true if successful, false if not 226 226 * The timer for AutoHeal is started here 227 * if vgpEntity is given, this visualGarrisonPoint will be used for the entity 227 228 */ 228 GarrisonHolder.prototype.Garrison = function(entity )229 GarrisonHolder.prototype.Garrison = function(entity, vgpEntity) 229 230 { 230 231 var cmpPosition = Engine.QueryInterface(entity, IID_Position); 231 232 if (!cmpPosition) … … 234 235 if (!this.PerformGarrison(entity)) 235 236 return false; 236 237 237 var visiblyGarrisoned = false;238 for (var vgp of this.visibleGarrisonPoints)238 let visibleGarrisonPoint = vgpEntity; 239 if (!visibleGarrisonPoint) 239 240 { 240 if (vgp.entity) 241 continue; 242 vgp.entity = entity; 243 cmpPosition.SetTurretParent(this.entity, vgp.offset); 244 visiblyGarrisoned = true; 245 var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 241 for (let vgp of this.visibleGarrisonPoints) 242 { 243 if (vgp.entity) 244 continue; 245 visibleGarrisonPoint = vgp; 246 break; 247 } 248 } 249 250 if (visibleGarrisonPoint) 251 { 252 visibleGarrisonPoint.entity = entity; 253 cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset); 254 let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 246 255 if (cmpUnitAI) 247 256 cmpUnitAI.SetTurretStance(); 248 break;249 257 } 250 if (!visiblyGarrisoned)258 else 251 259 cmpPosition.MoveOutOfWorld(); 260 252 261 return true; 253 262 }; 254 263 … … 674 683 var entityIndex = this.entities.indexOf(msg.entity); 675 684 if (entityIndex != -1) 676 685 { 686 let vgpRenamed; 687 for (let vgp of this.visibleGarrisonPoints) 688 { 689 if (vgp.entity != msg.entity) 690 continue; 691 vgpRenamed = vgp; 692 break; 693 } 677 694 this.Eject(msg.entity); 678 this.Garrison(msg.newentity );695 this.Garrison(msg.newentity, vgpRenamed); 679 696 } 680 697 681 698 if (!this.initGarrison) -
binaries/data/mods/public/simulation/components/Promotion.js
80 80 81 81 var orders = cmpCurrentUnitAI.GetOrders(); 82 82 if (cmpCurrentUnitAI.IsGarrisoned()) 83 { 84 if (orders.length > 0 && (orders[0].type == "Garrison" || orders[0].type == "Autogarrison")) 85 { 86 // Replace the garrison order by an autogarrison order, 87 // as we are already garrisoned and do not need to do 88 // any further checks (or else we should do them here). 89 var garrisonHolder = orders[0].data.target; 90 orders.shift(); 91 cmpPromotedUnitAI.Autogarrison(garrisonHolder); 92 } 93 else 94 warn("Promoted garrisoned entity with empty order queue."); 95 } 96 else 97 cmpPromotedUnitAI.Cheer(); 98 83 cmpPromotedUnitAI.isGarrisoned = true; 84 if (cmpCurrentUnitPosition.IsInWorld()) // do not cheer if not visibly garrisoned 85 cmpPromotedUnitAI.Cheer(); 99 86 cmpPromotedUnitAI.AddOrders(orders); 100 87 101 88 var workOrders = cmpCurrentUnitAI.GetWorkOrders(); -
binaries/data/mods/public/simulation/components/UnitAI.js
687 687 "Order.Garrison": function(msg) { 688 688 if (this.IsTurret()) 689 689 { 690 this. FinishOrder();690 this.SetNextState("IDLE"); 691 691 return; 692 692 } 693 else if (this.IsGarrisoned()) 694 { 695 this.SetNextState("INDIVIDUAL.AUTOGARRISON"); 696 return; 697 } 698 693 699 // For packable units: 694 700 // 1. If packed, we can move to the garrison target. 695 701 // 2. If unpacked, we first need to pack, then follow case 1. … … 713 719 }, 714 720 715 721 "Order.Autogarrison": function(msg) { 722 if (this.IsTurret()) 723 { 724 this.SetNextState("IDLE"); 725 return; 726 } 727 716 728 this.SetNextState("INDIVIDUAL.AUTOGARRISON"); 717 729 }, 718 730 … … 1438 1450 // from FinishOrder (SetNextState("IDLE") is only executed when we get 1439 1451 // a ProcessMessage), and thus we should not start an attack which could 1440 1452 // put us in a weird state 1441 if (this.orderQueue.length > 0 )1453 if (this.orderQueue.length > 0 && !this.IsGarrisoned()) 1442 1454 return false; 1443 1455 1444 1456 // If a unit can heal and attack we first want to heal wounded units, … … 1501 1513 Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle }); 1502 1514 } 1503 1515 }, 1516 1517 "Order.Ungarrison": function() { // Needed for turrets 1518 this.FinishOrder(); 1519 this.isGarrisoned = false; 1520 }, 1504 1521 }, 1505 1522 1506 1523 "WALKING": { … … 2918 2935 }, 2919 2936 2920 2937 "Order.Ungarrison": function() { 2921 if (this.FinishOrder())2922 return;2938 this.FinishOrder(); 2939 this.isGarrisoned = false; 2923 2940 }, 2924 2941 2925 2942 "leave": function() { 2926 this.isGarrisoned = false;2927 2943 } 2928 2944 }, 2929 2945 }, … … 2935 2951 }, 2936 2952 2937 2953 "Order.Ungarrison": function() { 2938 if (this.FinishOrder())2939 return;2954 this.FinishOrder(); 2955 this.isGarrisoned = false; 2940 2956 }, 2941 2957 2942 2958 "leave": function() { 2943 this.isGarrisoned = false;2944 2959 } 2945 2960 }, 2946 2961 … … 3318 3333 { 3319 3334 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 3320 3335 if (cmpOwnership && cmpOwnership.GetOwner() == msg.player) 3321 this.SetupRangeQuer y();3336 this.SetupRangeQueries(); 3322 3337 }; 3323 3338 3324 3339 UnitAI.prototype.OnOwnershipChanged = function(msg) … … 4976 4991 UnitAI.prototype.Ungarrison = function() 4977 4992 { 4978 4993 if (this.IsGarrisoned()) 4994 { 4995 // Turret may be attacking, so we must finish all orders except the last one 4996 // which must be Garrison or Autogarrison 4997 while (this.orderQueue.length > 1) 4998 this.FinishOrder(); 4979 4999 this.AddOrder("Ungarrison", null, false); 5000 } 4980 5001 }; 4981 5002 4982 5003 /**