internal void PurgeAll()
        {
            FutureEvents.Purge((int)Tick);
            PurgeTerminalSystem();

            foreach (var reports in Reporter.ReportData.Values)
            {
                foreach (var report in reports)
                {
                    report.Clean();
                    Reporter.ReportPool.Return(report);
                }
                reports.Clear();
            }
            Reporter.ReportData.Clear();
            Reporter.ReportPool.Clean();

            PacketsToClient.Clear();
            PacketsToServer.Clear();

            foreach (var suit in (PacketType[])Enum.GetValues(typeof(PacketType)))
            {
                foreach (var pool in PacketPools.Values)
                {
                    pool.Clean();
                }
                PacketPools.Clear();
            }

            foreach (var item in _effectedCubes)
            {
                var cubeid     = item.Key;
                var blockInfo  = item.Value;
                var functBlock = blockInfo.FunctBlock;
                var cube       = blockInfo.CubeBlock;

                if (cube == null || cube.MarkedForClose)
                {
                    _effectPurge.Enqueue(cubeid);
                    continue;
                }

                functBlock.EnabledChanged -= ForceDisable;
                functBlock.Enabled         = blockInfo.FirstState;
                cube.SetDamageEffect(false);
                _effectPurge.Enqueue(cubeid);
            }

            while (_effectPurge.Count != 0)
            {
                _effectedCubes.Remove(_effectPurge.Dequeue());
            }

            Av.Glows.Clear();
            Av.AvShotPool.Clean();

            DeferedUpBlockTypeCleanUp(true);
            BlockTypeCleanUp.Clear();

            foreach (var map in GridToFatMap.Keys)
            {
                RemoveGridFromMap(map);
            }

            GridToFatMap.Clear();
            FatMapPool.Clean();

            DirtyGridsTmp.Clear();

            foreach (var structure in WeaponPlatforms.Values)
            {
                foreach (var system in structure.WeaponSystems)
                {
                    foreach (var ammo in system.Value.WeaponAmmoTypes)
                    {
                        ammo.AmmoDef.Const.PrimeEntityPool?.Clean();
                    }
                }

                structure.WeaponSystems.Clear();
            }
            WeaponPlatforms.Clear();

            foreach (var gridToMap in GridToBlockTypeMap)
            {
                foreach (var map in gridToMap.Value)
                {
                    map.Value.ClearImmediate();
                    ConcurrentListPool.Return(map.Value);
                }
                gridToMap.Value.Clear();
                BlockTypePool.Return(gridToMap.Value);
            }
            GridToBlockTypeMap.Clear();

            foreach (var playerGrids in PlayerEntityIdInRange)
            {
                playerGrids.Value.Clear();
            }

            PlayerEntityIdInRange.Clear();

            DirtyGrids.Clear();

            DsUtil.Purge();
            DsUtil2.Purge();

            _effectActive = false;
            ShootingWeapons.Clear();
            AcquireTargets.Clear();
            RemoveEffectsFromGrid.Clear();
            WeaponAmmoPullQueue.Clear();
            AmmoToPullQueue.Clear();
            Hits.Clear();
            AllArmorBaseDefinitions.Clear();
            HeavyArmorBaseDefinitions.Clear();
            AllArmorBaseDefinitions.Clear();
            AcquireTargets.Clear();
            ChargingWeapons.Clear();
            LargeBlockSphereDb.Clear();
            SmallBlockSphereDb.Clear();
            AnimationsToProcess.Clear();
            _subTypeIdToWeaponDefs.Clear();
            WeaponDefinitions.Clear();
            SlimsSortedList.Clear();
            _destroyedSlims.Clear();
            _destroyedSlimsClient.Clear();
            _slimHealthClient.Clear();
            _slimsSet.Clear();
            _turretDefinitions.Clear();

            foreach (var comp in CompsToStart)
            {
                PlatFormPool.Return(comp.Platform);
                comp.Platform = null;
            }

            foreach (var readd in CompReAdds)
            {
                PlatFormPool.Return(readd.Comp.Platform);
                readd.Comp.Platform = null;
            }
            foreach (var comp in CompsDelayed)
            {
                PlatFormPool.Return(comp.Platform);
                comp.Platform = null;
            }
            PlatFormPool.Clean();
            CompsToStart.ClearImmediate();

            CompsDelayed.Clear();
            CompReAdds.Clear();
            GridAiPool.Clean();

            Av.RipMap.Clear();
            foreach (var mess in Av.KeensBrokenParticles)
            {
                Av.KeenMessPool.Return(mess);
            }

            Av.KeensBrokenParticles.Clear();

            foreach (var av in Av.AvShots)
            {
                av.GlowSteps.Clear();
                Av.AvShotPool.Return(av);
            }
            Av.AvShotPool.Clean();
            Av.AvBarrels1.Clear();
            Av.AvBarrels2.Clear();
            Av.AvShots.Clear();
            Av.HitSounds.Clear();

            foreach (var errorpkt in ClientSideErrorPktList)
            {
                errorpkt.Packet.CleanUp();
            }
            ClientSideErrorPktList.Clear();

            GridEffectPool.Clean();
            GridEffectsPool.Clean();
            BlockTypePool.Clean();
            ConcurrentListPool.Clean();

            GroupInfoPool.Clean();
            TargetInfoPool.Clean();

            Projectiles.Clean();
            WeaponCoreBlockDefs.Clear();
            VanillaIds.Clear();
            VanillaCoreIds.Clear();
            WeaponCoreFixedBlockDefs.Clear();
            WeaponCoreTurretBlockDefs.Clear();

            foreach (var p in Projectiles.ProjectilePool)
            {
                p.AmmoEffect?.Stop();
            }

            Projectiles.ShrapnelToSpawn.Clear();
            Projectiles.ShrapnelPool.Clean();
            Projectiles.FragmentPool.Clean();
            Projectiles.ActiveProjetiles.ApplyChanges();
            Projectiles.ActiveProjetiles.Clear();
            Projectiles.ProjectilePool.Clear();
            Projectiles.HitEntityPool.Clean();
            Projectiles.CleanUp.Clear();
            Projectiles.VirtInfoPool.Clean();

            DbsToUpdate.Clear();
            GridTargetingAIs.Clear();

            DsUtil          = null;
            DsUtil2         = null;
            SlimsSortedList = null;
            Enforced        = null;
            StallReporter   = null;
            Proccessor      = null;
            Physics         = null;
            Camera          = null;
            Projectiles     = null;
            TrackingAi      = null;
            UiInput         = null;
            TargetUi        = null;
            Placer          = null;
            WheelUi         = null;
            TargetGps       = null;
            SApi.Unload();
            SApi                = null;
            Api                 = null;
            ApiServer           = null;
            Reporter            = null;
            WeaponDefinitions   = null;
            AnimationsToProcess = null;
            ProjectileTree.Clear();
            ProjectileTree     = null;
            Av                 = null;
            HudUi              = null;
            AllDefinitions     = null;
            SoundDefinitions   = null;
            ActiveCockPit      = null;
            ActiveControlBlock = null;
            ControlledEntity   = null;
        }
示例#2
0
        internal void Init()
        {
            if (Inited)
            {
                return;
            }
            Inited = true;
            Log.Init("debugdevelop.log");
            Log.Line($"Logging Started");

            foreach (var x in WeaponDefinitions)
            {
                foreach (var ammo in x.Ammos)
                {
                    var ae             = ammo.AreaEffect;
                    var areaRadius     = ae.AreaEffectRadius;
                    var detonateRadius = ae.Detonation.DetonationRadius;
                    var fragments      = ammo.Shrapnel.Fragments > 0 ? ammo.Shrapnel.Fragments : 1;
                    if (areaRadius > 0)
                    {
                        if (!LargeBlockSphereDb.ContainsKey(ModRadius(areaRadius, true)))
                        {
                            GenerateBlockSphere(MyCubeSize.Large, ModRadius(areaRadius, true));
                        }
                        if (!LargeBlockSphereDb.ContainsKey(ModRadius(areaRadius / fragments, true)))
                        {
                            GenerateBlockSphere(MyCubeSize.Large, ModRadius(areaRadius / fragments, true));
                        }

                        if (!SmallBlockSphereDb.ContainsKey(ModRadius(areaRadius, false)))
                        {
                            GenerateBlockSphere(MyCubeSize.Small, ModRadius(areaRadius, false));
                        }
                        if (!SmallBlockSphereDb.ContainsKey(ModRadius(areaRadius / fragments, false)))
                        {
                            GenerateBlockSphere(MyCubeSize.Small, ModRadius(areaRadius / fragments, false));
                        }
                    }
                    if (detonateRadius > 0)
                    {
                        if (!LargeBlockSphereDb.ContainsKey(ModRadius(detonateRadius, true)))
                        {
                            GenerateBlockSphere(MyCubeSize.Large, ModRadius(detonateRadius, true));
                        }
                        if (!LargeBlockSphereDb.ContainsKey(ModRadius(detonateRadius / fragments, true)))
                        {
                            GenerateBlockSphere(MyCubeSize.Large, ModRadius(detonateRadius / fragments, true));
                        }

                        if (!SmallBlockSphereDb.ContainsKey(ModRadius(detonateRadius, false)))
                        {
                            GenerateBlockSphere(MyCubeSize.Small, ModRadius(detonateRadius, false));
                        }
                        if (!SmallBlockSphereDb.ContainsKey(ModRadius(detonateRadius / fragments, false)))
                        {
                            GenerateBlockSphere(MyCubeSize.Small, ModRadius(detonateRadius / fragments, false));
                        }
                    }
                }
            }
            foreach (var weaponDef in WeaponDefinitions)
            {
                foreach (var mount in weaponDef.Assignments.MountPoints)
                {
                    var subTypeId       = mount.SubtypeId;
                    var muzzlePartId    = mount.MuzzlePartId;
                    var azimuthPartId   = mount.AzimuthPartId;
                    var elevationPartId = mount.ElevationPartId;

                    var extraInfo = new MyTuple <string, string, string> {
                        Item1 = weaponDef.HardPoint.WeaponName, Item2 = azimuthPartId, Item3 = elevationPartId
                    };

                    if (!_turretDefinitions.ContainsKey(subTypeId))
                    {
                        foreach (var def in AllDefinitions)
                        {
                            MyDefinitionId defid;
                            if (def.Id.SubtypeName == subTypeId || (ReplaceVanilla && VanillaCoreIds.TryGetValue(MyStringHash.GetOrCompute(subTypeId), out defid) && defid == def.Id))
                            {
                                var gunDef = def as MyLargeTurretBaseDefinition;
                                if (gunDef != null)
                                {
                                    var blockDefs = weaponDef.HardPoint.HardWare;

                                    gunDef.MinAzimuthDegrees   = blockDefs.MinAzimuth;
                                    gunDef.MaxAzimuthDegrees   = blockDefs.MaxAzimuth;
                                    gunDef.MinElevationDegrees = blockDefs.MinElevation;
                                    gunDef.MaxElevationDegrees = blockDefs.MaxElevation;
                                    gunDef.RotationSpeed       = blockDefs.RotateRate / 60;
                                    gunDef.ElevationSpeed      = blockDefs.ElevateRate / 60;
                                    gunDef.AiEnabled           = false;
                                }

                                WeaponCoreBlockDefs[subTypeId] = def.Id;
                            }
                        }
                        _turretDefinitions[subTypeId] = new Dictionary <string, MyTuple <string, string, string> >
                        {
                            [muzzlePartId] = extraInfo
                        };
                        _subTypeIdToWeaponDefs[subTypeId] = new List <WeaponDefinition> {
                            weaponDef
                        };
                    }
                    else
                    {
                        _turretDefinitions[subTypeId][muzzlePartId] = extraInfo;
                        _subTypeIdToWeaponDefs[subTypeId].Add(weaponDef);
                    }
                }
            }

            foreach (var tDef in _turretDefinitions)
            {
                var subTypeIdHash = MyStringHash.GetOrCompute(tDef.Key);
                SubTypeIdHashMap[tDef.Key] = subTypeIdHash;

                var weapons = _subTypeIdToWeaponDefs[tDef.Key];

                var hasTurret = false;
                foreach (var wepDef in weapons)
                {
                    if (wepDef.HardPoint.Ai.TurretAttached)
                    {
                        hasTurret = true;
                    }
                }

                MyDefinitionId defId;
                if (WeaponCoreBlockDefs.TryGetValue(tDef.Key, out defId))
                {
                    if (hasTurret)
                    {
                        WeaponCoreTurretBlockDefs.Add(defId);
                    }
                    else
                    {
                        WeaponCoreFixedBlockDefs.Add(defId);
                    }
                }

                WeaponPlatforms[subTypeIdHash] = new WeaponStructure(this, tDef, weapons);
            }

            MyAPIGateway.TerminalControls.CustomControlGetter += CustomControlHandler;
        }
示例#3
0
        internal void PurgeAll()
        {
            PurgedAll = true;
            FutureEvents.Purge((int)Tick);


            foreach (var comp in CompsToStart)
            {
                if (comp?.Platform != null)
                {
                    CloseComps(comp.MyCube);
                }
            }

            foreach (var readd in CompReAdds)
            {
                if (!readd.Ai.Closed)
                {
                    readd.Ai.AiForceClose();
                }
                if (readd.Comp?.Platform != null)
                {
                    CloseComps(readd.Comp.MyCube);
                }
            }

            foreach (var comp in CompsDelayed)
            {
                if (comp?.Platform != null)
                {
                    CloseComps(comp.MyCube);
                }
            }

            foreach (var gridAi in DelayedAiClean)
            {
                if (!gridAi.Closed)
                {
                    gridAi.AiForceClose();
                }
            }

            PlatFormPool.Clean();
            CompsToStart.ClearImmediate();
            DelayedAiClean.ClearImmediate();

            CompsDelayed.Clear();
            CompReAdds.Clear();
            GridAiPool.Clean();


            PurgeTerminalSystem(this);
            HudUi.Purge();
            TerminalMon.Purge();
            foreach (var reports in Reporter.ReportData.Values)
            {
                foreach (var report in reports)
                {
                    report.Clean();
                    Reporter.ReportPool.Return(report);
                }
                reports.Clear();
            }
            Reporter.ReportData.Clear();
            Reporter.ReportPool.Clean();

            PacketsToClient.Clear();
            PacketsToServer.Clear();

            AcqManager.Clean();

            CleanSounds(true);

            foreach (var e in Emitters)
            {
                e.StopSound(true);
            }
            foreach (var e in Av.HitEmitters)
            {
                e.StopSound(true);
            }
            foreach (var e in Av.FireEmitters)
            {
                e.StopSound(true);
            }
            foreach (var e in Av.TravelEmitters)
            {
                e.StopSound(true);
            }

            Emitters.Clear();
            Av.HitEmitters.Clear();
            Av.FireEmitters.Clear();
            Av.TravelEmitters.Clear();

            foreach (var item in EffectedCubes)
            {
                var cubeid     = item.Key;
                var blockInfo  = item.Value;
                var functBlock = blockInfo.FunctBlock;

                if (functBlock == null || functBlock.MarkedForClose)
                {
                    _effectPurge.Enqueue(cubeid);
                    continue;
                }

                functBlock.EnabledChanged -= ForceDisable;
                functBlock.Enabled         = blockInfo.FirstState;
                functBlock.SetDamageEffect(false);
                if (HandlesInput)
                {
                    functBlock.AppendingCustomInfo -= blockInfo.AppendCustomInfo;
                }
                _effectPurge.Enqueue(cubeid);
            }

            while (_effectPurge.Count != 0)
            {
                EffectedCubes.Remove(_effectPurge.Dequeue());
            }

            Av.Glows.Clear();
            Av.AvShotPool.Clean();

            DeferedUpBlockTypeCleanUp(true);
            BlockTypeCleanUp.Clear();

            foreach (var map in GridToInfoMap.Keys)
            {
                RemoveGridFromMap(map);
            }

            GridToInfoMap.Clear();
            GridMapPool.Clean();

            DirtyGridsTmp.Clear();

            foreach (var structure in WeaponPlatforms.Values)
            {
                foreach (var system in structure.WeaponSystems)
                {
                    system.Value.PreFirePairs.Clear();
                    system.Value.FireWhenDonePairs.Clear();
                    system.Value.FirePerShotPairs.Clear();
                    system.Value.RotatePairs.Clear();
                    system.Value.ReloadPairs.Clear();
                    foreach (var ammo in system.Value.AmmoTypes)
                    {
                        ammo.AmmoDef.Const.PrimeEntityPool?.Clean();
                        ammo.AmmoDef.Const.HitDefaultSoundPairs.Clear();
                        ammo.AmmoDef.Const.HitVoxelSoundPairs.Clear();
                        ammo.AmmoDef.Const.HitShieldSoundPairs.Clear();
                        ammo.AmmoDef.Const.HitFloatingSoundPairs.Clear();
                        ammo.AmmoDef.Const.HitPlayerSoundPairs.Clear();
                        ammo.AmmoDef.Const.TravelSoundPairs.Clear();
                        ammo.AmmoDef.Const.CustomSoundPairs.Clear();
                    }
                }

                structure.WeaponSystems.Clear();
            }
            WeaponPlatforms.Clear();

            foreach (var gridToMap in GridToBlockTypeMap)
            {
                foreach (var map in gridToMap.Value)
                {
                    ConcurrentListPool.Return(map.Value);
                }
                gridToMap.Value.Clear();
                BlockTypePool.Return(gridToMap.Value);
            }
            GridToBlockTypeMap.Clear();

            foreach (var playerGrids in PlayerEntityIdInRange)
            {
                playerGrids.Value.Clear();
            }

            PlayerEntityIdInRange.Clear();
            DirtyGridInfos.Clear();

            DsUtil.Purge();
            DsUtil2.Purge();

            ShootingWeapons.Clear();
            WeaponToPullAmmo.Clear();
            AmmoToPullQueue.Clear();
            ChargingWeaponsIndexer.Clear();
            WeaponsToRemoveAmmoIndexer.Clear();
            ChargingWeapons.Clear();
            Hits.Clear();
            HomingWeapons.Clear();
            GridToMasterAi.Clear();
            Players.Clear();
            IdToCompMap.Clear();
            AllArmorBaseDefinitions.Clear();
            HeavyArmorBaseDefinitions.Clear();
            AllArmorBaseDefinitions.Clear();
            AcquireTargets.Clear();
            LargeBlockSphereDb.Clear();
            SmallBlockSphereDb.Clear();
            AnimationsToProcess.Clear();
            _subTypeIdToWeaponDefs.Clear();
            WeaponDefinitions.Clear();
            SlimsSortedList.Clear();
            _destroyedSlims.Clear();
            _destroyedSlimsClient.Clear();
            _slimHealthClient.Clear();
            _slimsSet.Clear();
            _turretDefinitions.Clear();
            _tmpNearByBlocks.Clear();

            foreach (var av in Av.AvShots)
            {
                av.GlowSteps.Clear();
                Av.AvShotPool.Return(av);
            }
            Av.AvShotPool.Clean();
            Av.AvBarrels1.Clear();
            Av.AvBarrels2.Clear();
            Av.AvShots.Clear();
            Av.HitSounds.Clear();

            foreach (var errorpkt in ClientSideErrorPkt)
            {
                errorpkt.Packet.CleanUp();
            }
            ClientSideErrorPkt.Clear();

            GridEffectPool.Clean();
            GridEffectsPool.Clean();
            BlockTypePool.Clean();
            ConcurrentListPool.Clean();

            TargetInfoPool.Clean();
            PacketObjPool.Clean();

            InventoryMoveRequestPool.Clean();
            WeaponCoreBlockDefs.Clear();
            VanillaIds.Clear();
            VanillaCoreIds.Clear();
            WeaponCoreFixedBlockDefs.Clear();
            WeaponCoreTurretBlockDefs.Clear();
            VoxelCaches.Clear();
            ArmorCubes.Clear();

            foreach (var p in Projectiles.ProjectilePool)
            {
                p.Info?.AvShot?.AmmoEffect?.Stop();
            }

            Projectiles.ShrapnelToSpawn.Clear();
            Projectiles.ShrapnelPool.Clean();
            Projectiles.FragmentPool.Clean();
            Projectiles.ActiveProjetiles.Clear();
            Projectiles.ProjectilePool.Clear();
            Projectiles.HitEntityPool.Clean();
            Projectiles.VirtInfoPool.Clean();

            DbsToUpdate.Clear();
            GridTargetingAIs.Clear();

            DsUtil          = null;
            DsUtil2         = null;
            SlimsSortedList = null;
            Settings        = null;
            StallReporter   = null;
            TerminalMon     = null;
            Physics         = null;
            Camera          = null;
            Projectiles     = null;
            TrackingAi      = null;
            UiInput         = null;
            TargetUi        = null;
            Placer          = null;
            TargetGps       = null;
            SApi.Unload();
            SApi                = null;
            Api                 = null;
            ApiServer           = null;
            Reporter            = null;
            WeaponDefinitions   = null;
            AnimationsToProcess = null;
            ProjectileTree.Clear();
            ProjectileTree     = null;
            Av                 = null;
            HudUi              = null;
            AllDefinitions     = null;
            SoundDefinitions   = null;
            ActiveCockPit      = null;
            ActiveControlBlock = null;
            ControlledEntity   = null;
            TmpStorage         = null;
        }
示例#4
0
        internal void Init()
        {
            if (Inited)
            {
                return;
            }
            Inited = true;
            Log.Init("debug", this);
            Log.Init("perf", this, false);
            Log.Init("stats", this, false);
            Log.Init("net", this, false);
            Log.Init("report", this, false);
            Log.Init("combat", this, false);

            MpActive        = MyAPIGateway.Multiplayer.MultiplayerActive;
            IsServer        = MyAPIGateway.Multiplayer.IsServer;
            DedicatedServer = MyAPIGateway.Utilities.IsDedicated;
            IsCreative      = MyAPIGateway.Session.CreativeMode;
            IsClient        = !IsServer && !DedicatedServer && MpActive;
            HandlesInput    = !IsServer || IsServer && !DedicatedServer;
            IsHost          = IsServer && !DedicatedServer && MpActive;
            MpServer        = IsHost || DedicatedServer;

            foreach (var x in WeaponDefinitions)
            {
                foreach (var ammo in x.Ammos)
                {
                    var ae             = ammo.AreaEffect;
                    var areaRadius     = ae.Base.Radius > 0 ? ae.Base.Radius : ae.AreaEffectRadius;
                    var detonateRadius = ae.Detonation.DetonationRadius;
                    var fragments      = ammo.Shrapnel.Fragments > 0 ? ammo.Shrapnel.Fragments : 1;
                    if (areaRadius > 0)
                    {
                        if (!LargeBlockSphereDb.ContainsKey(ModRadius(areaRadius, true)))
                        {
                            GenerateBlockSphere(MyCubeSize.Large, ModRadius(areaRadius, true));
                        }
                        if (!LargeBlockSphereDb.ContainsKey(ModRadius(areaRadius / fragments, true)))
                        {
                            GenerateBlockSphere(MyCubeSize.Large, ModRadius(areaRadius / fragments, true));
                        }

                        if (!SmallBlockSphereDb.ContainsKey(ModRadius(areaRadius, false)))
                        {
                            GenerateBlockSphere(MyCubeSize.Small, ModRadius(areaRadius, false));
                        }
                        if (!SmallBlockSphereDb.ContainsKey(ModRadius(areaRadius / fragments, false)))
                        {
                            GenerateBlockSphere(MyCubeSize.Small, ModRadius(areaRadius / fragments, false));
                        }
                    }
                    if (detonateRadius > 0)
                    {
                        if (!LargeBlockSphereDb.ContainsKey(ModRadius(detonateRadius, true)))
                        {
                            GenerateBlockSphere(MyCubeSize.Large, ModRadius(detonateRadius, true));
                        }
                        if (!LargeBlockSphereDb.ContainsKey(ModRadius(detonateRadius / fragments, true)))
                        {
                            GenerateBlockSphere(MyCubeSize.Large, ModRadius(detonateRadius / fragments, true));
                        }

                        if (!SmallBlockSphereDb.ContainsKey(ModRadius(detonateRadius, false)))
                        {
                            GenerateBlockSphere(MyCubeSize.Small, ModRadius(detonateRadius, false));
                        }
                        if (!SmallBlockSphereDb.ContainsKey(ModRadius(detonateRadius / fragments, false)))
                        {
                            GenerateBlockSphere(MyCubeSize.Small, ModRadius(detonateRadius / fragments, false));
                        }
                    }
                }
            }
            foreach (var weaponDef in WeaponDefinitions)
            {
                foreach (var mount in weaponDef.Assignments.MountPoints)
                {
                    var subTypeId       = mount.SubtypeId;
                    var muzzlePartId    = mount.MuzzlePartId;
                    var azimuthPartId   = mount.AzimuthPartId;
                    var elevationPartId = mount.ElevationPartId;

                    var extraInfo = new MyTuple <string, string, string> {
                        Item1 = weaponDef.HardPoint.WeaponName, Item2 = azimuthPartId, Item3 = elevationPartId
                    };

                    if (!_turretDefinitions.ContainsKey(subTypeId))
                    {
                        _turretDefinitions[subTypeId] = new Dictionary <string, MyTuple <string, string, string> >
                        {
                            [muzzlePartId] = extraInfo
                        };
                        _subTypeIdToWeaponDefs[subTypeId] = new List <WeaponDefinition> {
                            weaponDef
                        };
                    }
                    else
                    {
                        _turretDefinitions[subTypeId][muzzlePartId] = extraInfo;
                        _subTypeIdToWeaponDefs[subTypeId].Add(weaponDef);
                    }
                }
            }

            foreach (var tDef in _turretDefinitions)
            {
                var subTypeIdHash = MyStringHash.GetOrCompute(tDef.Key);
                SubTypeIdHashMap[tDef.Key] = subTypeIdHash;

                WeaponAreaRestriction areaRestriction;
                if (this.WeaponAreaRestrictions.ContainsKey(subTypeIdHash))
                {
                    areaRestriction = this.WeaponAreaRestrictions[subTypeIdHash];
                }
                else
                {
                    areaRestriction = new WeaponAreaRestriction();
                    WeaponAreaRestrictions[subTypeIdHash] = areaRestriction;
                }

                var    weapons     = _subTypeIdToWeaponDefs[tDef.Key];
                var    hasTurret   = false;
                var    firstWeapon = true;
                string modPath     = null;
                foreach (var wepDef in weapons)
                {
                    try {
                        modPath = wepDef.ModPath;
                        if (wepDef.HardPoint.Ai.TurretAttached)
                        {
                            hasTurret = true;
                        }

                        if (wepDef.HardPoint.HardWare.Armor != WeaponDefinition.HardPointDef.HardwareDef.ArmorState.IsWeapon)
                        {
                            DamageHandler = true;
                        }

                        foreach (var def in AllDefinitions)
                        {
                            MyDefinitionId defid;
                            var            matchingDef = def.Id.SubtypeName == tDef.Key || (ReplaceVanilla && VanillaCoreIds.TryGetValue(MyStringHash.GetOrCompute(tDef.Key), out defid) && defid == def.Id);
                            if (matchingDef)
                            {
                                if (wepDef.HardPoint.Other.RestrictionRadius > 0)
                                {
                                    if (wepDef.HardPoint.Other.CheckForAnyWeapon && !areaRestriction.CheckForAnyWeapon)
                                    {
                                        areaRestriction.CheckForAnyWeapon = true;
                                    }
                                    if (wepDef.HardPoint.Other.CheckInflatedBox)
                                    {
                                        if (areaRestriction.RestrictionBoxInflation < wepDef.HardPoint.Other.RestrictionRadius)
                                        {
                                            areaRestriction.RestrictionBoxInflation = wepDef.HardPoint.Other.RestrictionRadius;
                                        }
                                    }
                                    else
                                    {
                                        if (areaRestriction.RestrictionRadius < wepDef.HardPoint.Other.RestrictionRadius)
                                        {
                                            areaRestriction.RestrictionRadius = wepDef.HardPoint.Other.RestrictionRadius;
                                        }
                                    }
                                }

                                WeaponCoreBlockDefs[tDef.Key] = def.Id;
                                var designator = false;

                                for (int i = 0; i < wepDef.Assignments.MountPoints.Length; i++)
                                {
                                    if (wepDef.Assignments.MountPoints[i].MuzzlePartId == "Designator")
                                    {
                                        designator = true;
                                        break;
                                    }
                                }

                                if (!designator)
                                {
                                    var wepBlockDef = def as MyWeaponBlockDefinition;
                                    if (wepBlockDef != null)
                                    {
                                        if (firstWeapon)
                                        {
                                            wepBlockDef.InventoryMaxVolume = 0;
                                        }

                                        wepBlockDef.InventoryMaxVolume += wepDef.HardPoint.HardWare.InventorySize;

                                        var weaponCsDef = MyDefinitionManager.Static.GetWeaponDefinition(wepBlockDef.WeaponDefinitionId);

                                        if (weaponCsDef.WeaponAmmoDatas[0] == null)
                                        {
                                            Log.Line($"WeaponAmmoData is null, check the Ammo definition for {tDef.Key}");
                                        }
                                        weaponCsDef.WeaponAmmoDatas[0].RateOfFire = wepDef.HardPoint.Loading.RateOfFire;

                                        weaponCsDef.WeaponAmmoDatas[0].ShotsInBurst = wepDef.HardPoint.Loading.ShotsInBurst;
                                    }
                                    else if (def is MyConveyorSorterDefinition)
                                    {
                                        if (firstWeapon)
                                        {
                                            ((MyConveyorSorterDefinition)def).InventorySize = Vector3.Zero;
                                        }

                                        var size = Math.Pow(wepDef.HardPoint.HardWare.InventorySize, 1d / 3d);

                                        ((MyConveyorSorterDefinition)def).InventorySize += new Vector3(size, size, size);
                                    }

                                    firstWeapon = false;

                                    for (int i = 0; i < wepDef.Assignments.MountPoints.Length; i++)
                                    {
                                        var az = !string.IsNullOrEmpty(wepDef.Assignments.MountPoints[i].AzimuthPartId) ? wepDef.Assignments.MountPoints[i].AzimuthPartId : "MissileTurretBase1";
                                        var el = !string.IsNullOrEmpty(wepDef.Assignments.MountPoints[i].ElevationPartId) ? wepDef.Assignments.MountPoints[i].ElevationPartId : "MissileTurretBarrels";

                                        if (def is MyLargeTurretBaseDefinition && (VanillaSubpartNames.Contains(az) || VanillaSubpartNames.Contains(el)))
                                        {
                                            var gunDef    = (MyLargeTurretBaseDefinition)def;
                                            var blockDefs = wepDef.HardPoint.HardWare;
                                            gunDef.MinAzimuthDegrees   = blockDefs.MinAzimuth;
                                            gunDef.MaxAzimuthDegrees   = blockDefs.MaxAzimuth;
                                            gunDef.MinElevationDegrees = blockDefs.MinElevation;
                                            gunDef.MaxElevationDegrees = blockDefs.MaxElevation;
                                            gunDef.RotationSpeed       = blockDefs.RotateRate / 60;
                                            gunDef.ElevationSpeed      = blockDefs.ElevateRate / 60;
                                            gunDef.AiEnabled           = false;
                                            gunDef.IdleRotation        = false;
                                        }

                                        var cubeDef = def as MyCubeBlockDefinition;
                                        if (cubeDef != null)
                                        {
                                            for (int x = 0; x < wepDef.Assignments.MountPoints.Length; x++)
                                            {
                                                var mp = wepDef.Assignments.MountPoints[x];
                                                if (mp.SubtypeId == def.Id.SubtypeName)
                                                {
                                                    cubeDef.GeneralDamageMultiplier = mp.DurabilityMod > 0 ? mp.DurabilityMod : cubeDef.CubeSize == MyCubeSize.Large ? 0.25f : 0.05f;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Line($"Failed to load {wepDef.HardPoint.WeaponName}");
                    }
                }

                MyDefinitionId defId;
                if (WeaponCoreBlockDefs.TryGetValue(tDef.Key, out defId))
                {
                    if (hasTurret)
                    {
                        WeaponCoreTurretBlockDefs.Add(defId);
                    }
                    else
                    {
                        WeaponCoreFixedBlockDefs.Add(defId);
                    }
                }
                WeaponPlatforms[defId] = new WeaponStructure(this, tDef, weapons, modPath);
            }

            MyAPIGateway.TerminalControls.CustomControlGetter += CustomControlHandler;
        }