Ticket #1391: shipgarrison-v4.diff
File shipgarrison-v4.diff, 5.8 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/UnitAI.js
328 328 } 329 329 }, 330 330 331 "Order.PickUpUnit": function(msg) { 332 if (this.MoveToTarget(this.order.data.target)) 333 { 334 this.SetNextState("INDIVIDUAL.PICKUP.APPROACHING"); 335 } 336 else 337 { 338 // We are already at the target, or can't move at all 339 this.StopMoving(); 340 this.SetNextState("INDIVIDUAL.PICKUP.LOADING"); 341 } 342 }, 343 331 344 "Order.Flee": function(msg) { 332 345 // We use the distance between the enities to account for ranged attacks 333 346 var distance = DistanceBetweenEntities(this.entity, this.order.data.target) + (+this.template.FleeDistance); … … 597 610 return; 598 611 } 599 612 613 // If to be garrisoned inside a ship, warn it so it can take needed action 614 var cmpIdentity = Engine.QueryInterface(this.order.data.target, IID_Identity); 615 if (cmpIdentity && cmpIdentity.HasClass("Ship")) 616 Engine.PostMessage(this.order.data.target, MT_TransportRequired, { "entity": this.entity }); 617 600 618 if (this.MoveToTarget(this.order.data.target)) 601 619 { 602 620 this.SetNextState("INDIVIDUAL.GARRISON.APPROACHING"); … … 724 742 // The target was destroyed 725 743 this.FinishOrder(); 726 744 else 745 { 727 746 // Out of range; move there in formation 728 747 this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); 748 // If to be garrisoned inside a ship, warn it so it can take needed action 749 var cmpIdentity = Engine.QueryInterface(msg.data.target, IID_Identity); 750 { 751 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); 752 var entity = cmpFormation.GetPrimaryMember(); 753 Engine.PostMessage(msg.data.target, MT_TransportRequired, { "entity": entity }); 754 } 755 } 729 756 return; 730 757 } 731 758 … … 2228 2255 { 2229 2256 // Unable to reach the target, try again 2230 2257 // (or follow if it's a moving target) 2258 // But first if garrisoning inside a ship, warn it again 2259 // in case the ship's orders have been changed 2260 var cmpIdentity = Engine.QueryInterface(target, IID_Identity); 2261 if (cmpIdentity && cmpIdentity.HasClass("Ship")) 2262 Engine.PostMessage(target, MT_TransportRequired, { "entity": this.entity }); 2263 2231 2264 if (this.MoveToTarget(target)) 2232 2265 { 2233 2266 this.SetNextState("APPROACHING"); … … 2307 2340 // Ignore attacks while unpacking 2308 2341 }, 2309 2342 }, 2343 2344 "PICKUP": { 2345 "APPROACHING": { 2346 "enter": function() { 2347 this.SelectAnimation("move"); 2348 }, 2349 2350 "MoveCompleted": function() { 2351 this.SetNextState("LOADING"); 2352 }, 2353 2354 "leave": function() { 2355 } 2356 }, 2357 2358 "LOADING": { 2359 "enter": function() { 2360 this.StartTimer(0, 1000); 2361 this.SelectAnimation("idle"); 2362 }, 2363 2364 "Timer": function() { 2365 var cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI); 2366 // Stop waiting if the target does not exist any more, or is already garrisoned or its orders have changed 2367 if (!cmpUnitAI || cmpUnitAI.isGarrisoned || !cmpUnitAI.order || cmpUnitAI.order.type != "Garrison" 2368 || cmpUnitAI.order.data.target != this.entity) 2369 this.FinishOrder(); 2370 // Or if the capacity is already full 2371 var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); 2372 if (cmpGarrisonHolder.GetEntities().length >= cmpGarrisonHolder.GetCapacity()) 2373 this.FinishOrder(); 2374 }, 2375 2376 "leave": function() { 2377 this.StopTimer(); 2378 }, 2379 }, 2380 }, 2310 2381 }, 2311 2382 2312 2383 "ANIMAL": { … … 2585 2656 this.SetupRangeQueries(); 2586 2657 }; 2587 2658 2659 UnitAI.prototype.OnTransportRequired = function(msg) 2660 { 2661 var cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); 2662 if (cmpGarrisonHolder && cmpGarrisonHolder.GetEntities().length < cmpGarrisonHolder.GetCapacity()) 2663 { 2664 // First check if we already have such a requirement 2665 for each (var order in this.orderQueue) 2666 { 2667 if (order.type == "PickUpUnit" && order.data.target == msg.entity) 2668 return; 2669 } 2670 // Insert the PickUp order after the last forced order 2671 this.PushOrderAfterForced("PickUpUnit", { "target": msg.entity }); 2672 } 2673 }; 2674 2588 2675 // Wrapper function that sets up the normal, healer, and Gaia range queries. 2589 2676 UnitAI.prototype.SetupRangeQueries = function() 2590 2677 { … … 2850 2937 } 2851 2938 }; 2852 2939 2940 /** 2941 * Insert an order after the last forced order onto the queue 2942 * and after the other orders of the same type 2943 */ 2944 UnitAI.prototype.PushOrderAfterForced = function(type, data) 2945 { 2946 if (!this.order || ((!this.order.data || !this.order.data.force) && this.order.type != type)) 2947 { 2948 this.PushOrderFront(type, data); 2949 } 2950 else 2951 { 2952 for (var i = 1; i < this.orderQueue.length; ++i) 2953 { 2954 if (this.orderQueue[i].data && this.orderQueue[i].data.force) 2955 continue; 2956 if (this.orderQueue[i].type == type) 2957 continue; 2958 this.orderQueue.splice(i, 0, {"type": type, "data": data}); 2959 return; 2960 } 2961 this.PushOrder(type, data); 2962 } 2963 }; 2964 2853 2965 UnitAI.prototype.ReplaceOrder = function(type, data) 2854 2966 { 2855 2967 // Special cases of orders that shouldn't be replaced: -
binaries/data/mods/public/simulation/components/interfaces/UnitAI.js
11 11 // Message of the form { "to": orderData }. 12 12 // sent whenever the unit changes state 13 13 Engine.RegisterMessageType("UnitAIOrderDataChanged"); 14 15 // Message of the form { "entity": entity }, 16 // sent whenever a transport (ship) is required 17 Engine.RegisterMessageType("TransportRequired");