Ticket #3284: attack_patch.2.diff
File attack_patch.2.diff, 4.0 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Attack.js
309 309 }; 310 310 311 311 /** 312 * Return the type of the best attack. 313 * TODO: this should probably depend on range, target, etc, 314 * so we can automatically switch between ranged and melee 312 * Get the full range of attack regarding available attack types. 315 313 */ 316 Attack.prototype.Get BestAttack= function()314 Attack.prototype.GetFullAttackRange = function() 317 315 { 318 return this.GetAttackTypes().pop(); 319 }; 316 var ret = {"min": Infinity, "max": 0}; 317 var types = this.GetAttackTypes(); 318 for (var key in types) 319 { 320 var type = types[key]; 321 if (type != "Slaughter") 322 { 323 // Ignore the special attack "slaughter" 324 var range = this.GetRange(type); 325 if (range.min < ret.min) 326 ret.min = range.min; 327 if (range.max > ret.max) 328 ret.max = range.max; 329 } 330 } 331 return ret; 332 } 320 333 321 334 Attack.prototype.GetBestAttackAgainst = function(target, allowCapture) 322 335 { 323 336 var cmpFormation = Engine.QueryInterface(target, IID_Formation); 324 337 if (cmpFormation) 325 return this.GetBestAttack(); 338 { 339 // TODO: Formation against formation needs review 340 var best = ["Ranged", "Melee", "Capture"]; 341 var types = this.GetAttackTypes(); 342 for (var key in best) 343 { 344 if (types.indexOf(best[key]) != -1) 345 return best[key]; 346 } 347 return undefined; 348 } 326 349 327 350 var cmpIdentity = Engine.QueryInterface(target, IID_Identity); 328 351 if (!cmpIdentity) -
binaries/data/mods/public/simulation/components/UnitAI.js
4458 4458 return distance < range; 4459 4459 }; 4460 4460 4461 UnitAI.prototype.GetBestAttack = function()4462 {4463 var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);4464 if (!cmpAttack)4465 return undefined;4466 return cmpAttack.GetBestAttack();4467 };4468 4469 4461 UnitAI.prototype.GetBestAttackAgainst = function(target, allowCapture) 4470 4462 { 4471 4463 var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); … … 5458 5450 var cmpRanged = Engine.QueryInterface(this.entity, iid); 5459 5451 if (!cmpRanged) 5460 5452 return ret; 5461 var range = iid !== IID_Attack ? cmpRanged.GetRange() : cmpRanged.Get Range(cmpRanged.GetBestAttack());5453 var range = iid !== IID_Attack ? cmpRanged.GetRange() : cmpRanged.GetFullAttackRange(); 5462 5454 ret.min = range.min; 5463 5455 ret.max = range.max; 5464 5456 } … … 5475 5467 var cmpRanged = Engine.QueryInterface(this.entity, iid); 5476 5468 if (!cmpRanged) 5477 5469 return ret; 5478 var range = iid !== IID_Attack ? cmpRanged.GetRange() : cmpRanged.Get Range(cmpRanged.GetBestAttack());5470 var range = iid !== IID_Attack ? cmpRanged.GetRange() : cmpRanged.GetFullAttackRange(); 5479 5471 var cmpVision = Engine.QueryInterface(this.entity, IID_Vision); 5480 5472 if (!cmpVision) 5481 5473 return ret; -
binaries/data/mods/public/simulation/components/tests/test_UnitAI.js
97 97 98 98 AddMock(unit, IID_Attack, { 99 99 GetRange: function() { return { "max": 10, "min": 0}; }, 100 GetBestAttack: function() { return "melee"; },101 100 GetBestAttackAgainst: function(t) { return "melee"; }, 102 101 GetTimers: function() { return { "prepare": 500, "repeat": 1000 }; }, 103 102 CanAttack: function(v) { return true; }, … … 249 248 250 249 AddMock(unit + i, IID_Attack, { 251 250 GetRange: function() { return {"max":10, "min": 0}; }, 252 GetBestAttack: function() { return "melee"; },253 251 GetBestAttackAgainst: function(t) { return "melee"; }, 254 252 GetTimers: function() { return { "prepare": 500, "repeat": 1000 }; }, 255 253 CanAttack: function(v) { return true; },