Ticket #252: t252_cleanupattack.diff
File t252_cleanupattack.diff, 3.2 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Attack.js
218 218 219 219 Attack.prototype.GetPreferredClasses = function(type) 220 220 { 221 if (this.template[type] && this.template[type].PreferredClasses && 222 this.template[type].PreferredClasses._string) 223 { 221 if (this.template[type] && this.template[type].PreferredClasses && this.template[type].PreferredClasses._string) 224 222 return this.template[type].PreferredClasses._string.split(/\s+/); 225 }226 223 return []; 227 224 }; 228 225 229 226 Attack.prototype.GetRestrictedClasses = function(type) 230 227 { 231 if (this.template[type] && this.template[type].RestrictedClasses && 232 this.template[type].RestrictedClasses._string) 233 { 228 if (this.template[type] && this.template[type].RestrictedClasses && this.template[type].RestrictedClasses._string) 234 229 return this.template[type].RestrictedClasses._string.split(/\s+/); 235 }236 230 return []; 237 231 }; 238 232 … … 281 275 canAttack = false; 282 276 break; 283 277 } 284 if (canAttack )278 if (canAttack == "true") 285 279 return true; 286 280 } 287 281 … … 327 321 if (type == "Slaughter") 328 322 continue; 329 323 let range = this.GetRange(type); 330 if (range.min < ret.min) 331 ret.min = range.min; 332 if (range.max > ret.max) 333 ret.max = range.max; 324 ret.min = Math.min(ret.min, Range.min) 325 ret.max = Math.max(ret.max, Range.max) 334 326 } 335 327 return ret; 336 328 }; … … 486 478 let a = Math.random(); 487 479 let b = Math.random(); 488 480 489 let c = Math.sqrt(-2 *Math.log(a)) * Math.cos(2*Math.PI*b);490 let d = Math.sqrt(-2 *Math.log(a)) * Math.sin(2*Math.PI*b);481 let c = Math.sqrt(-2 * Math.log(a)) * Math.cos(2 * Math.PI * b); 482 let d = Math.sqrt(-2 * Math.log(a)) * Math.sin(2 * Math.PI * b); 491 483 492 484 return [c, d]; 493 485 }; … … 503 495 if (type == "Ranged") 504 496 { 505 497 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 506 let turnLength = cmpTimer.GetLatestTurnLength() /1000;498 let turnLength = cmpTimer.GetLatestTurnLength() / 1000; 507 499 // In the future this could be extended: 508 500 // * Obstacles like trees could reduce the probability of the target being hit 509 501 // * Obstacles like walls should block projectiles entirely … … 620 612 Attack.prototype.InterpolatedLocation = function(ent, lateness) 621 613 { 622 614 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 623 let turnLength = cmpTimer.GetLatestTurnLength() /1000;615 let turnLength = cmpTimer.GetLatestTurnLength() / 1000; 624 616 let cmpTargetPosition = Engine.QueryInterface(ent, IID_Position); 625 617 if (!cmpTargetPosition || !cmpTargetPosition.IsInWorld()) // TODO: handle dead target properly 626 618 return undefined; … … 658 650 let d = Vector3D.sub(point, targetPosition); 659 651 d = Vector2D.from3D(d).rotate(-angle); 660 652 661 return d.x < Math.abs(targetShape.width /2) && d.y < Math.abs(targetShape.depth/2);653 return d.x < Math.abs(targetShape.width / 2) && d.y < Math.abs(targetShape.depth / 2); 662 654 } 663 655 }; 664 656 … … 740 732 return; 741 733 742 734 for (let type of this.GetAttackTypes()) 743 if (msg.valueNames.indexOf("Attack/" +type+"/MaxRange") !== -1)735 if (msg.valueNames.indexOf("Attack/" + type + "/MaxRange") !== -1) 744 736 { 745 737 cmpUnitAI.UpdateRangeQueries(); 746 738 return;