- Timestamp:
- 06/26/11 04:03:36 (14 years ago)
- Location:
- ps/trunk/binaries/data/mods/public/simulation
- Files:
-
- 3 edited
-
components/Promotion.js (modified) (1 diff)
-
components/UnitAI.js (modified) (4 diffs)
-
helpers/Entity.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/simulation/components/Promotion.js
r9631 r9663 68 68 cmpPromotedUnitAI.SetHeldPosition(cmpCurrentUnitAI.GetHeldPosition()); 69 69 if (cmpCurrentUnitAI.GetStanceName()) 70 cmpPromotedUnitAI.S etStance(cmpCurrentUnitAI.GetStanceName());70 cmpPromotedUnitAI.SwitchToStance(cmpCurrentUnitAI.GetStanceName()); 71 71 cmpPromotedUnitAI.Cheer(); 72 72 var orders = cmpCurrentUnitAI.GetOrders(); -
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
r9661 r9663 284 284 285 285 "Order.Gather": function(msg) { 286 //If target is not visible anymore, give up287 if (!this.CheckTargetVisible(this.order.data.target))288 {289 this.FinishOrder();290 return;291 }292 293 286 // If the target is still alive, we need to kill it first 294 if (this.MustKillGatherTarget(this.order.data.target) )287 if (this.MustKillGatherTarget(this.order.data.target) && this.CheckTargetVisible(this.order.data.target)) 295 288 { 296 289 // Make sure we can attack the target, else we'll get very stuck … … 382 375 383 376 "Order.Walk": function(msg) { 377 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); 378 cmpFormation.CallMemberFunction("SetHeldPosition", [msg.data.x, msg.data.z]); 379 384 380 this.MoveToPoint(this.order.data.x, this.order.data.z); 385 381 this.SetNextState("WALKING"); … … 734 730 // TODO: respond to target deaths immediately, rather than waiting 735 731 // until the next Timer event 732 733 "Attacked": function(msg) { 734 if (this.order.data.target != msg.data.attacker) 735 { 736 // If we're attacked by a close enemy stronger than our current target, we choose to attack him 737 if (this.GetStance().targetAttackers && msg.data.type == "Melee") 738 { 739 var ents = [this.order.data.target, msg.data.attacker]; 740 SortEntitiesByPriority(ents); 741 if (ents[0] != this.order.data.target) 742 { 743 this.RespondToTargetedEntities(ents); 744 } 745 } 746 } 747 }, 736 748 }, 737 749 … … 2361 2373 return false; 2362 2374 2375 SortEntitiesByPriority(ents); 2363 2376 return this.RespondToTargetedEntities(ents); 2364 2377 }; -
ps/trunk/binaries/data/mods/public/simulation/helpers/Entity.js
r9631 r9663 18 18 } 19 19 20 /** 21 * Returns entities ordered by decreasing priority 22 * Do not alter order when units have the same priority 23 */ 24 function SortEntitiesByPriority(ents) 25 { 26 // Priority list, weakers first 27 var types = ["Structure", "Worker"]; 28 29 ents.sort(function (a, b) { 30 var cmpIdentityA = Engine.QueryInterface(a, IID_Identity); 31 var cmpIdentityB = Engine.QueryInterface(b, IID_Identity); 32 if (!cmpIdentityA || !cmpIdentityB) 33 return 0; 34 var classesA = cmpIdentityA.GetClassesList(); 35 var classesB = cmpIdentityB.GetClassesList(); 36 for each (var type in types) 37 { 38 var inA = classesA.indexOf(type) != -1; 39 var inB = classesB.indexOf(type) != -1; 40 if (inA && !inB) 41 return +1; 42 if (inB && !inA) 43 return -1; 44 } 45 return 0; 46 }); 47 } 48 20 49 Engine.RegisterGlobal("DistanceBetweenEntities", DistanceBetweenEntities); 50 Engine.RegisterGlobal("SortEntitiesByPriority", SortEntitiesByPriority);
Note:
See TracChangeset
for help on using the changeset viewer.
