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(); } } } }
private void StartComps() { var reassign = false; for (int i = 0; i < CompsToStart.Count; i++) { var weaponComp = CompsToStart[i]; if (weaponComp.MyCube.CubeGrid.IsPreview) { //Log.Line($"[IsPreview] MyCubeId:{weaponComp.MyCube.EntityId} - Grid:{weaponComp.MyCube.CubeGrid.DebugName} - !Marked:{!weaponComp.MyCube.MarkedForClose} - inScene:{weaponComp.MyCube.InScene} - gridMatch:{weaponComp.MyCube.CubeGrid == weaponComp.Ai.MyGrid}"); weaponComp.RemoveComp(); PlatFormPool.Return(weaponComp.Platform); weaponComp.Platform = null; CompsToStart.Remove(weaponComp); continue; } if (weaponComp.MyCube.CubeGrid.Physics == null && !weaponComp.MyCube.CubeGrid.MarkedForClose && weaponComp.MyCube.BlockDefinition.HasPhysics) { continue; } if (weaponComp.Ai.MyGrid != weaponComp.MyCube.CubeGrid) { if (!GridToFatMap.ContainsKey(weaponComp.MyCube.CubeGrid)) { continue; } Log.Line($"[StartComps - gridMisMatch] MyCubeId:{weaponComp.MyCube.EntityId} - Grid:{weaponComp.MyCube.CubeGrid.DebugName} - WeaponName:{weaponComp.MyCube.BlockDefinition.Id.SubtypeId.String} - !Marked:{!weaponComp.MyCube.MarkedForClose} - inScene:{weaponComp.MyCube.InScene} - gridMatch:{weaponComp.MyCube.CubeGrid == weaponComp.Ai.MyGrid} - {weaponComp.Ai.MyGrid.MarkedForClose}"); InitComp(weaponComp.MyCube, false); reassign = true; CompsToStart.Remove(weaponComp); } else if (weaponComp.Platform.State == MyWeaponPlatform.PlatformState.Fresh) { if (weaponComp.MyCube.MarkedForClose) { CompsToStart.Remove(weaponComp); continue; } if (!GridToFatMap.ContainsKey(weaponComp.MyCube.CubeGrid)) { continue; } weaponComp.MyCube.Components.Add(weaponComp); CompsToStart.Remove(weaponComp); } else { Log.Line($"comp didn't match CompsToStart condition, removing"); CompsToStart.Remove(weaponComp); } } CompsToStart.ApplyRemovals(); if (reassign) { CompsToStart.ApplyAdditions(); StartComps(); } }
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(); } } }