internal void RemoveCoreToolbarWeapons(MyCubeGrid grid) { foreach (var cube in grid.GetFatBlocks()) { if (cube is MyShipController) { var ob = (MyObjectBuilder_ShipController)cube.GetObjectBuilderCubeBlock(); var reinit = false; for (int i = 0; i < ob.Toolbar.Slots.Count; i++) { var toolbarItem = ob.Toolbar.Slots[i].Data as MyObjectBuilder_ToolbarItemWeapon; if (toolbarItem != null) { var defId = (MyDefinitionId)toolbarItem.defId; if ((ReplaceVanilla && VanillaIds.ContainsKey(defId)) || WeaponPlatforms.ContainsKey(defId.SubtypeId)) { var index = ob.Toolbar.Slots[i].Index; var item = ob.Toolbar.Slots[i].Item; ob.Toolbar.Slots[i] = new MyObjectBuilder_Toolbar.Slot { Index = index, Item = item }; reinit = true; } } } if (reinit) { cube.Init(ob, grid); } } } }
private void InitComp(MyCubeBlock cube, bool thread = true) { using (cube.Pin()) { if (cube.MarkedForClose) { return; } GridAi gridAi; if (!GridTargetingAIs.TryGetValue(cube.CubeGrid, out gridAi)) { gridAi = GridAiPool.Get(); gridAi.Init(cube.CubeGrid, this); GridTargetingAIs.TryAdd(cube.CubeGrid, gridAi); } var blockDef = ReplaceVanilla && VanillaIds.ContainsKey(cube.BlockDefinition.Id) ? VanillaIds[cube.BlockDefinition.Id] : cube.BlockDefinition.Id.SubtypeId; var weaponComp = new WeaponComponent(this, gridAi, cube, blockDef); if (gridAi != null && gridAi.WeaponBase.TryAdd(cube, weaponComp)) { if (!gridAi.WeaponCounter.ContainsKey(blockDef)) { gridAi.WeaponCounter.TryAdd(blockDef, WeaponCountPool.Get()); } CompsToStart.Add(weaponComp); if (thread) { CompsToStart.ApplyAdditions(); } } } }
internal void OnEntityCreate(MyEntity myEntity) { try { if (!Inited) { lock (InitObj) Init(); } var grid = myEntity as MyCubeGrid; if (grid != null) { grid.AddedToScene += GridAddedToScene; } var placer = myEntity as IMyBlockPlacerBase; if (placer != null && Placer == null) { Placer = placer; } var cube = myEntity as MyCubeBlock; var sorter = cube as MyConveyorSorter; var turret = cube as IMyLargeTurretBase; var controllableGun = cube as IMyUserControllableGun; if (sorter != null || turret != null || controllableGun != null) { if (!(ReplaceVanilla && VanillaIds.ContainsKey(cube.BlockDefinition.Id)) && !WeaponPlatforms.ContainsKey(cube.BlockDefinition.Id.SubtypeId)) { return; } lock (InitObj) { if (!SorterControls && myEntity is MyConveyorSorter) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMyConveyorSorter>(this)); SorterControls = true; } else if (!TurretControls && turret != null) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMyLargeTurretBase>(this)); TurretControls = true; } else if (!FixedMissileControls && controllableGun is IMySmallMissileLauncher) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMySmallMissileLauncher>(this)); FixedMissileControls = true; } else if (!FixedGunControls && controllableGun is IMySmallGatlingGun) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMySmallGatlingGun>(this)); FixedGunControls = true; } } InitComp(cube); } } catch (Exception ex) { Log.Line($"Exception in OnEntityCreate: {ex}"); } }
private void InitComp(MyCubeBlock cube, bool thread = true) { using (cube.Pin()) { if (cube.MarkedForClose) { return; } var blockDef = ReplaceVanilla && VanillaIds.ContainsKey(cube.BlockDefinition.Id) ? VanillaIds[cube.BlockDefinition.Id] : cube.BlockDefinition.Id.SubtypeId; var weaponComp = new CoreComponent(this, cube, blockDef); CompsToStart.Add(weaponComp); if (thread) { CompsToStart.ApplyAdditions(); } } }
internal void OnEntityCreate(MyEntity myEntity) { try { if (!Inited) { lock (InitObj) Init(); } var planet = myEntity as MyPlanet; if (planet != null) { PlanetMap.TryAdd(planet.EntityId, planet); } var grid = myEntity as MyCubeGrid; if (grid != null) { grid.AddedToScene += GridAddedToScene; } if (!PbApiInited && myEntity is IMyProgrammableBlock) { PbActivate = true; } var placer = myEntity as IMyBlockPlacerBase; if (placer != null && Placer == null) { Placer = placer; } var cube = myEntity as MyCubeBlock; var sorter = cube as MyConveyorSorter; var turret = cube as IMyLargeTurretBase; var controllableGun = cube as IMyUserControllableGun; var decoy = cube as IMyDecoy; var camera = cube as MyCameraBlock; if (sorter != null || turret != null || controllableGun != null) { if (!(ReplaceVanilla && VanillaIds.ContainsKey(cube.BlockDefinition.Id)) && !WeaponPlatforms.ContainsKey(cube.BlockDefinition.Id)) { return; } lock (InitObj) { if (!SorterDetected && myEntity is MyConveyorSorter) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMyConveyorSorter>(this)); if (!EarlyInitOver) { ControlQueue.Enqueue(typeof(IMyConveyorSorter)); } SorterDetected = true; } else if (!TurretDetected && turret != null) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMyLargeTurretBase>(this)); if (!EarlyInitOver) { ControlQueue.Enqueue(typeof(IMyLargeTurretBase)); } TurretDetected = true; } else if (!FixedMissileReloadDetected && controllableGun is IMySmallMissileLauncherReload) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMySmallMissileLauncherReload>(this)); if (!EarlyInitOver) { ControlQueue.Enqueue(typeof(IMySmallMissileLauncherReload)); } FixedMissileReloadDetected = true; } else if (!FixedMissileDetected && controllableGun is IMySmallMissileLauncher) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMySmallMissileLauncher>(this)); if (!EarlyInitOver) { ControlQueue.Enqueue(typeof(IMySmallMissileLauncher)); } FixedMissileDetected = true; } else if (!FixedGunDetected && controllableGun is IMySmallGatlingGun) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateTerminalUi <IMySmallGatlingGun>(this)); if (!EarlyInitOver) { ControlQueue.Enqueue(typeof(IMySmallGatlingGun)); } FixedGunDetected = true; } } InitComp(cube); } else if (decoy != null) { if (!DecoyDetected) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateDecoyTerminalUi <IMyDecoy>(this)); DecoyDetected = true; } cube.AddedToScene += DecoyAddedToScene; } else if (camera != null) { if (!CameraDetected) { MyAPIGateway.Utilities.InvokeOnGameThread(() => CreateCameraTerminalUi <IMyCameraBlock>(this)); CameraDetected = true; } cube.AddedToScene += CameraAddedToScene; } } catch (Exception ex) { Log.Line($"Exception in OnEntityCreate: {ex}"); } }