Ticket #4102: 4102.diff
File 4102.diff, 7.0 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/GarrisonHolder.js
66 66 this.visibleGarrisonPoints = []; 67 67 if (this.template.VisibleGarrisonPoints) 68 68 { 69 for each (varoffset in this.template.VisibleGarrisonPoints)69 for (let offset in this.template.VisibleGarrisonPoints) 70 70 { 71 varo = {};71 let o = {}; 72 72 o.x = +offset.X; 73 73 o.y = +offset.Y; 74 74 o.z = +offset.Z; 75 this.visibleGarrisonPoints.push({ "offset":o, "entity": null});75 this.visibleGarrisonPoints.push({ "offset": o, "entity": null }); 76 76 } 77 77 } 78 78 }; … … 163 163 */ 164 164 GarrisonHolder.prototype.IsGarrisoningAllowed = function() 165 165 { 166 for each (var allow in this.allowGarrisoning) 167 { 166 for (let allow in this.allowGarrisoning) 168 167 if (!allow) 169 168 return false; 170 } 169 171 170 return true; 172 171 }; 173 172 … … 177 176 GarrisonHolder.prototype.GetGarrisonedEntitiesCount = function() 178 177 { 179 178 var count = 0; 180 for each (var ent inthis.entities)179 for (let ent of this.entities) 181 180 { 182 count++;183 varcmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder);181 ++count; 182 let cmpGarrisonHolder = Engine.QueryInterface(ent, IID_GarrisonHolder); 184 183 if (cmpGarrisonHolder) 185 184 count += cmpGarrisonHolder.GetGarrisonedEntitiesCount(); 186 185 } … … 305 304 var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity); 306 305 // If the garrisonHolder is a sinking ship, restrict the location to the intersection of both passabilities 307 306 // 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); 307 var pos = (!cmpHealth || cmpHealth.GetHitpoints() === 0) && cmpIdentity && cmpIdentity.HasClass("Ship") ? 308 cmpFootprint.PickSpawnPointBothPass(entity) : 309 cmpFootprint.PickSpawnPoint(entity); 312 310 313 311 if (pos.y < 0) 314 312 { … … 332 330 if (vgp.entity != entity) 333 331 continue; 334 332 cmpNewPosition.SetTurretParent(INVALID_ENTITY, new Vector3D()); 335 varcmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);333 let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 336 334 if (cmpUnitAI) 337 335 cmpUnitAI.ResetTurretStance(); 338 336 vgp.entity = null; … … 377 375 // ignore the rally point if it is autogarrison 378 376 if (commands[0].type == "garrison" && commands[0].target == this.entity) 379 377 return; 380 for each (var com incommands)378 for (let command of commands) 381 379 { 382 ProcessCommand(cmpOwnership.GetOwner(), com );380 ProcessCommand(cmpOwnership.GetOwner(), command); 383 381 } 384 382 } 385 383 } … … 403 401 { 404 402 if (failedRadius !== undefined) 405 403 { 406 varcmpObstruction = Engine.QueryInterface(entity, IID_Obstruction);407 varradius = cmpObstruction ? cmpObstruction.GetUnitRadius() : 0;404 let cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction); 405 let radius = cmpObstruction ? cmpObstruction.GetUnitRadius() : 0; 408 406 if (radius >= failedRadius) 409 407 continue; 410 408 } … … 411 409 412 410 if (this.Eject(entity, forced)) 413 411 { 414 varcmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);415 varcmpEntOwnership = Engine.QueryInterface(entity, IID_Ownership);412 let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 413 let cmpEntOwnership = Engine.QueryInterface(entity, IID_Ownership); 416 414 if (cmpOwnership && cmpEntOwnership && cmpOwnership.GetOwner() == cmpEntOwnership.GetOwner()) 417 415 ejectedEntities.push(entity); 418 416 } … … 423 421 failedRadius = Math.min(failedRadius, radius); 424 422 else 425 423 { 426 varcmpObstruction = Engine.QueryInterface(entity, IID_Obstruction);424 let cmpObstruction = Engine.QueryInterface(entity, IID_Obstruction); 427 425 failedRadius = cmpObstruction ? cmpObstruction.GetUnitRadius() : 0; 428 426 } 429 427 } … … 463 461 464 462 var entities = []; 465 463 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 466 for each (var entity inthis.entities)464 for (let entity of this.entities) 467 465 { 468 466 var cmpIdentity = Engine.QueryInterface(entity, IID_Identity); 469 467 470 468 // Units with multiple ranks are grouped together. 471 var name = cmpIdentity.GetSelectionGroupName() 472 || cmpTemplateManager.GetCurrentTemplateName(entity); 469 var name = cmpIdentity.GetSelectionGroupName() || cmpTemplateManager.GetCurrentTemplateName(entity); 473 470 474 471 if (name != template) 475 472 continue; … … 541 538 */ 542 539 GarrisonHolder.prototype.HealTimeout = function(data) 543 540 { 544 if (this.entities.length == 0) 541 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 542 if (this.entities.length) 545 543 { 546 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);547 544 cmpTimer.CancelTimer(this.timer); 548 545 this.timer = undefined; 549 546 } 550 547 else 551 548 { 552 for each (var entity inthis.entities)549 for (let entity of this.entities) 553 550 { 554 551 var cmpHealth = Engine.QueryInterface(entity, IID_Health); 555 552 if (cmpHealth) … … 559 556 cmpHealth.Increase(this.GetHealRate()); 560 557 } 561 558 } 562 varcmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);559 cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 563 560 this.timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); 564 561 } 565 562 }; … … 596 593 if (this.entity == msg.entity) 597 594 { 598 595 var entities = []; 599 for each (var entity inthis.entities)596 for (let entity of this.entities) 600 597 { 601 598 if (msg.to == -1 || !IsOwnedByMutualAllyOfEntity(this.entity, entity)) 602 599 entities.push(entity); … … 612 609 { 613 610 // If the entity is dead, remove it directly instead of ejecting the corpse 614 611 var cmpHealth = Engine.QueryInterface(msg.entity, IID_Health); 615 if (cmpHealth && cmpHealth.GetHitpoints() == 0)612 if (cmpHealth && cmpHealth.GetHitpoints() === 0) 616 613 { 617 614 this.entities.splice(entityIndex, 1); 618 615 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed": [msg.entity] }); … … 694 691 695 692 // And destroy all remaining entities 696 693 var killedEntities = []; 697 for each (var entity inentities)694 for (let entity of entities) 698 695 { 699 696 var entityIndex = this.entities.indexOf(entity); 700 697 if (entityIndex == -1) … … 719 716 var ejectableClasses = this.template.EjectClassesOnDestroy._string; 720 717 ejectableClasses = ejectableClasses ? ejectableClasses.split(/\s+/) : []; 721 718 var entityClasses = (Engine.QueryInterface(entity, IID_Identity)).GetClassesList(); 722 for each (var ejectableClass in ejectableClasses) 723 if (entityClasses.indexOf(ejectableClass) != -1) 724 return true; 725 719 if (ejectableClasses.some(ejectableClass => entityClasses.indexOf(ejectableClass) != -1)) 720 return true; 726 721 return false; 727 722 };