Ticket #4102: 4102.1.diff
File 4102.1.diff, 7.3 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/GarrisonHolder.js
65 65 this.allowGarrisoning = {}; 66 66 this.visibleGarrisonPoints = []; 67 67 if (this.template.VisibleGarrisonPoints) 68 { 69 for each (var offset in this.template.VisibleGarrisonPoints) 70 { 71 var o = {}; 72 o.x = +offset.X; 73 o.y = +offset.Y; 74 o.z = +offset.Z; 75 this.visibleGarrisonPoints.push({"offset":o, "entity": null}); 76 } 77 } 68 for (let name in this.template.VisibleGarrisonPoints) 69 this.visibleGarrisonPoints.push({ 70 "offset": { 71 "x": this.template.VisibleGarrisonPoints[name].X, 72 "y": this.template.VisibleGarrisonPoints[name].Y, 73 "z": this.template.VisibleGarrisonPoints[name].Z 74 }, "entity": null }); 78 75 }; 79 76 80 77 /** … … 163 160 */ 164 161 GarrisonHolder.prototype.IsGarrisoningAllowed = function() 165 162 { 166 for each (var allow in this.allowGarrisoning) 167 { 168 if (!allow) 163 for (let allow in this.allowGarrisoning) 164 if (!this.allowGarrisoning[allow]) 169 165 return false; 170 } 166 171 167 return true; 172 168 }; 173 169 … … 177 173 GarrisonHolder.prototype.GetGarrisonedEntitiesCount = function() 178 174 { 179 175 var count = 0; 180 for each (var entin this.entities)176 for (let entity in this.entities) 181 177 { 182 count++;183 var cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder);178 ++count; 179 let cmpGarrisonHolder = Engine.QueryInterface(this.entities[entity], IID_GarrisonHolder); 184 180 if (cmpGarrisonHolder) 185 181 count += cmpGarrisonHolder.GetGarrisonedEntitiesCount(); 186 182 } … … 263 259 264 260 if (!this.timer && this.GetHealRate() > 0) 265 261 { 266 262 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 267 263 this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); 268 264 } 269 265 … … 282 278 283 279 var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 284 280 if (cmpUnitAI && cmpUnitAI.IsUnderAlert()) 285 Engine.PostMessage(cmpUnitAI.GetAlertRaiser(), MT_UnitGarrisonedAfterAlert, { "holder": this.entity, "unit": entity});281 Engine.PostMessage(cmpUnitAI.GetAlertRaiser(), MT_UnitGarrisonedAfterAlert, { "holder": this.entity, "unit": entity }); 286 282 287 283 return true; 288 284 }; … … 305 301 var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); 306 302 // If the garrisonHolder is a sinking ship, restrict the location to the intersection of both passabilities 307 303 // TODO: should use passability classes to be more generic 308 if ((!cmpHealth || cmpHealth.GetHitpoints() == 0) && cmpIdentity && cmpIdentity.HasClass("Ship")) 309 var pos = cmpFootprint.PickSpawnPointBothPass(entity); 310 else 311 var pos = cmpFootprint.PickSpawnPoint(entity); 304 let pos = (!cmpHealth || cmpHealth.GetHitpoints() === 0) && cmpIdentity && cmpIdentity.HasClass("Ship") ? 305 cmpFootprint.PickSpawnPointBothPass(entity) : 306 cmpFootprint.PickSpawnPoint(entity); 312 307 313 308 if (pos.y < 0) 314 309 { … … 332 327 if (vgp.entity != entity) 333 328 continue; 334 329 cmpNewPosition.SetTurretParent(INVALID_ENTITY, new Vector3D()); 335 varcmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);330 let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 336 331 if (cmpUnitAI) 337 332 cmpUnitAI.ResetTurretStance(); 338 333 vgp.entity = null; … … 377 372 // ignore the rally point if it is autogarrison 378 373 if (commands[0].type == "garrison" && commands[0].target == this.entity) 379 374 return; 380 for each (var com in commands) 381 { 382 ProcessCommand(cmpOwnership.GetOwner(), com); 383 } 375 for (let command of commands) 376 ProcessCommand(cmpOwnership.GetOwner(), command); 384 377 } 385 378 } 386 379 }; … … 411 404 412 405 if (this.Eject(entity, forced)) 413 406 { 414 varcmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);415 varcmpEntOwnership = Engine.QueryInterface(entity, IID_Ownership);407 let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 408 let cmpEntOwnership = Engine.QueryInterface(entity, IID_Ownership); 416 409 if (cmpOwnership && cmpEntOwnership && cmpOwnership.GetOwner() == cmpEntOwnership.GetOwner()) 417 410 ejectedEntities.push(entity); 418 411 } … … 423 416 failedRadius = Math.min(failedRadius, radius); 424 417 else 425 418 { 426 varcmpObstruction = Engine.QueryInterface(entity, IID_Obstruction);419 let cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction); 427 420 failedRadius = cmpObstruction ? cmpObstruction.GetUnitRadius() : 0; 428 421 } 429 422 } … … 463 456 464 457 var entities = []; 465 458 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 466 for each (var entity inthis.entities)459 for (let entity of this.entities) 467 460 { 468 461 var cmpIdentity = Engine.QueryInterface(entity, IID_Identity); 469 462 470 463 // Units with multiple ranks are grouped together. 471 var name = cmpIdentity.GetSelectionGroupName() 472 || cmpTemplateManager.GetCurrentTemplateName(entity); 464 let name = cmpIdentity.GetSelectionGroupName() || cmpTemplateManager.GetCurrentTemplateName(entity); 473 465 474 466 if (name != template) 475 467 continue; … … 541 533 */ 542 534 GarrisonHolder.prototype.HealTimeout = function(data) 543 535 { 544 if (this.entities.length == 0) 536 let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 537 if (this.entities.length) 545 538 { 546 539 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 547 540 cmpTimer.CancelTimer(this.timer); … … 549 542 } 550 543 else 551 544 { 552 for each (var entity inthis.entities)545 for (let entity of this.entities) 553 546 { 554 547 var cmpHealth = Engine.QueryInterface(entity, IID_Health); 555 548 if (cmpHealth) … … 559 552 cmpHealth.Increase(this.GetHealRate()); 560 553 } 561 554 } 562 varcmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);555 cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 563 556 this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); 564 557 } 565 558 }; … … 612 605 { 613 606 // If the entity is dead, remove it directly instead of ejecting the corpse 614 607 var cmpHealth = Engine.QueryInterface(msg.entity, IID_Health); 615 if (cmpHealth && cmpHealth.GetHitpoints() == 0)608 if (cmpHealth && cmpHealth.GetHitpoints() === 0) 616 609 { 617 610 this.entities.splice(entityIndex, 1); 618 611 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed": [msg.entity] }); … … 694 687 695 688 // And destroy all remaining entities 696 689 var killedEntities = []; 697 for each (var entity inentities)690 for (let entity of entities) 698 691 { 699 692 var entityIndex = this.entities.indexOf(entity); 700 693 if (entityIndex == -1) … … 719 712 var ejectableClasses = this.template.EjectClassesOnDestroy._string; 720 713 ejectableClasses = ejectableClasses ? ejectableClasses.split(/\s+/) : []; 721 714 var entityClasses = (Engine.QueryInterface(entity, IID_Identity)).GetClassesList(); 722 for each (var ejectableClass in ejectableClasses) 723 if (entityClasses.indexOf(ejectableClass) != -1) 724 return true; 715 if (ejectableClasses.some(ejectableClass => entityClasses.indexOf(ejectableClass) != -1)) 716 return true; 725 717 726 718 return false; 727 719 }; … … 743 735 this.initGarrison = undefined; 744 736 }; 745 737 746 Engine.RegisterComponentType(IID_GarrisonHolder, "GarrisonHolder", GarrisonHolder); 747 738 Engine.RegisterComponentType(IID_GarrisonHolder, "GarrisonHolder", GarrisonHolder); 739 No newline at end of file