Ticket #1391: shipgarrison.diff
File shipgarrison.diff, 4.5 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/UnitAI.js
332 332 } 333 333 }, 334 334 335 "Order.PickUpUnit": function(msg) { 336 if (this.MoveToTarget(this.order.data.target)) 337 { 338 this.SetNextState("INDIVIDUAL.PICKUP.APPROACHING"); 339 } 340 else 341 { 342 // We are already at the target, or can't move at all 343 this.StopMoving(); 344 this.SetNextState("INDIVIDUAL.PICKUP.LOADING"); 345 } 346 }, 347 335 348 "Order.Flee": function(msg) { 336 349 // We use the distance between the enities to account for ranged attacks 337 350 var distance = DistanceBetweenEntities(this.entity, this.order.data.target) + (+this.template.FleeDistance); … … 601 614 return; 602 615 } 603 616 617 // If to be garrisoned inside a ship, warn it so it can take needed action 618 var cmpIdentity = Engine.QueryInterface(this.order.data.target, IID_Identity); 619 if (cmpIdentity && cmpIdentity.HasClass("Ship")) 620 Engine.PostMessage(this.order.data.target, MT_TransportRequired, { "entity": this.entity }); 621 604 622 if (this.MoveToTarget(this.order.data.target)) 605 623 { 606 624 this.SetNextState("INDIVIDUAL.GARRISON.APPROACHING"); … … 728 746 // The target was destroyed 729 747 this.FinishOrder(); 730 748 else 749 { 731 750 // Out of range; move there in formation 732 751 this.PushOrderFront("WalkToTargetRange", { "target": msg.data.target, "min": 0, "max": 10 }); 752 // If to be garrisoned inside a ship, warn it so it can take needed action 753 var cmpIdentity = Engine.QueryInterface(msg.data.target, IID_Identity); 754 { 755 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); 756 var entity = cmpFormation.GetPrimaryMember(); 757 Engine.PostMessage(msg.data.target, MT_TransportRequired, { "entity": entity }); 758 } 759 } 733 760 return; 734 761 } 735 762 … … 2265 2292 { 2266 2293 // Unable to reach the target, try again 2267 2294 // (or follow if it's a moving target) 2295 // But first if garrisoning inside a ship, warn it again 2296 // in case the ship's orders have been changed 2297 var cmpIdentity = Engine.QueryInterface(target, IID_Identity); 2298 if (cmpIdentity && cmpIdentity.HasClass("Ship")) 2299 Engine.PostMessage(target, MT_TransportRequired, { "entity": this.entity }); 2300 2268 2301 if (this.MoveToTarget(target)) 2269 2302 { 2270 2303 this.SetNextState("APPROACHING"); … … 2344 2377 // Ignore attacks while unpacking 2345 2378 }, 2346 2379 }, 2380 2381 "PICKUP": { 2382 "APPROACHING": { 2383 "enter": function() { 2384 this.SelectAnimation("move"); 2385 }, 2386 2387 "MoveCompleted": function() { 2388 this.SetNextState("LOADING"); 2389 }, 2390 2391 "leave": function() { 2392 } 2393 }, 2394 2395 "LOADING": { 2396 "enter": function() { 2397 this.StartTimer(0, 1000); 2398 this.SelectAnimation("idle"); 2399 }, 2400 2401 "Timer": function() { 2402 var cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI); 2403 // stop waiting if the target does not exist any more, or is already garrisoned or its orders have changed 2404 if (!cmpUnitAI || cmpUnitAI.isGarrisoned || !cmpUnitAI.order || cmpUnitAI.order.type != "Garrison" 2405 || cmpUnitAI.order.data.target != this.entity) 2406 this.FinishOrder(); 2407 }, 2408 2409 "leave": function() { 2410 this.StopTimer(); 2411 }, 2412 }, 2413 }, 2347 2414 }, 2348 2415 2349 2416 "ANIMAL": { … … 2622 2689 this.SetupRangeQueries(); 2623 2690 }; 2624 2691 2692 UnitAI.prototype.OnTransportRequired = function(msg) 2693 { 2694 // First check if we already have such a requirement 2695 for each (var order in this.orderQueue) 2696 { 2697 if (order.type == "PickUpUnit" && order.data.target == msg.entity) 2698 return; 2699 } 2700 this.PushOrderFront("PickUpUnit", { "target": msg.entity, "force": true }); 2701 }; 2702 2625 2703 // Wrapper function that sets up the normal, healer, and Gaia range queries. 2626 2704 UnitAI.prototype.SetupRangeQueries = function() 2627 2705 { -
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");