535 | | // Destroy the garrisoned units if the holder kill his entities on destroy or |
536 | | // is not in the world (generally means this holder is inside |
537 | | // a holder which kills its entities which has sunk). |
538 | | if (!this.EjectEntitiesOnDestroy() || !cmpPosition.IsInWorld()) |
| 538 | // Eject the units which can be ejected (if not in world, it generally means this holder |
| 539 | // is inside a holder which kills its entities, so do not eject) |
| 540 | if (cmpPosition.IsInWorld() && this.EjectEntitiesOnDestroy()) |
| 541 | this.PerformEject(entities, true); |
| 542 | |
| 543 | // And destroy all remaining entities |
| 544 | for each (var entity in entities) |
540 | | for each (var entity in entities) |
541 | | { |
542 | | var cmpHealth = Engine.QueryInterface(entity, IID_Health); |
543 | | if (cmpHealth) |
544 | | cmpHealth.Kill(); |
545 | | var entityIndex = this.entities.indexOf(entity); |
546 | | this.entities.splice(entityIndex, 1); |
547 | | Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {}); |
548 | | } |
549 | | this.UpdateGarrisonFlag(); |
| 546 | var entityIndex = this.entities.indexOf(entity); |
| 547 | if (entityIndex == -1) |
| 548 | continue; |
| 549 | var cmpHealth = Engine.QueryInterface(entity, IID_Health); |
| 550 | if (cmpHealth) |
| 551 | cmpHealth.Kill(); |
| 552 | this.entities.splice(entityIndex, 1); |
| 553 | Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {}); |