From 48534b07f517ae8051c078e285da06e55dad10cb Mon Sep 17 00:00:00 2001 From: BDCarrillo <90526940+BDCarrillo@users.noreply.github.com> Date: Tue, 28 May 2024 23:16:52 -0500 Subject: [PATCH] Casting a net for errors --- Data/Scripts/CoreSystems/Ai/AiConstruct.cs | 38 +++++++++++++++---- Data/Scripts/CoreSystems/Ai/AiEvents.cs | 5 +++ .../Scripts/CoreSystems/AudioVisual/AvShot.cs | 5 ++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Data/Scripts/CoreSystems/Ai/AiConstruct.cs b/Data/Scripts/CoreSystems/Ai/AiConstruct.cs index 781738e7..c9350525 100644 --- a/Data/Scripts/CoreSystems/Ai/AiConstruct.cs +++ b/Data/Scripts/CoreSystems/Ai/AiConstruct.cs @@ -59,15 +59,39 @@ public void RegisterSubGrid(MyCubeGrid grid) grid.Flags |= (EntityFlags)(1 << 31); grid.OnFatBlockAdded += FatBlockAdded; grid.OnFatBlockRemoved += FatBlockRemoved; - foreach (var cube in grid.GetFatBlocks().ToArray()) + + //BDC Temp debugging + var tempBlockArray = grid.GetFatBlocks().ToArray(); + try { - var battery = cube as MyBatteryBlock; - var stator = cube as IMyMotorStator; - var tool = cube as IMyShipToolBase; - var offense = cube as IMyOffensiveCombatBlock; + foreach (var cube in grid.GetFatBlocks()) + { + var battery = cube as MyBatteryBlock; + var stator = cube as IMyMotorStator; + var tool = cube as IMyShipToolBase; + var offense = cube as IMyOffensiveCombatBlock; - if (battery != null || cube.HasInventory || stator != null || tool != null || offense != null) - FatBlockAdded(cube); + if (battery != null || cube.HasInventory || stator != null || tool != null || offense != null) + FatBlockAdded(cube); + } + } + catch (Exception ex) + { + var modifiedBlockArray = grid.GetFatBlocks(); + var msg = $"Original GetFatBlocks contained {tempBlockArray.Length} items, modified contains {modifiedBlockArray.Count}"; + foreach (var original in tempBlockArray) + { + if(!modifiedBlockArray.Contains(original)) + msg += $"Block {original.DisplayName} was removed \n"; + } + foreach (var modified in modifiedBlockArray) + { + if (!tempBlockArray.Contains(modified)) + msg += $"Block {modified.DisplayName} was added \n"; + } + Log.Line(msg); + MyLog.Default.WriteLine(msg); + throw ex; } SubGridsRegistered[grid] = byte.MaxValue; } diff --git a/Data/Scripts/CoreSystems/Ai/AiEvents.cs b/Data/Scripts/CoreSystems/Ai/AiEvents.cs index 6dfe58d2..fd8d5832 100644 --- a/Data/Scripts/CoreSystems/Ai/AiEvents.cs +++ b/Data/Scripts/CoreSystems/Ai/AiEvents.cs @@ -8,6 +8,7 @@ using VRage.Collections; using VRage.Game.Entity; using VRage.Game.ModAPI; +using VRage.Utils; using VRageMath; namespace CoreSystems.Support @@ -186,6 +187,10 @@ internal void FatBlockAdded(MyCubeBlock cube) if (Session.I.IsServer) { cube.CubeGrid.RemoveBlock(cube.SlimBlock, true); + //BDC Temp debugging + var msg = $"WeaponCore Removed {cube.BlockDefinition.Id.SubtypeId} block due to placement violations"; + Log.Line(msg); + MyLog.Default.WriteLine(msg); } } } diff --git a/Data/Scripts/CoreSystems/AudioVisual/AvShot.cs b/Data/Scripts/CoreSystems/AudioVisual/AvShot.cs index 340e50f2..2e4ab009 100644 --- a/Data/Scripts/CoreSystems/AudioVisual/AvShot.cs +++ b/Data/Scripts/CoreSystems/AudioVisual/AvShot.cs @@ -1051,8 +1051,9 @@ internal void SetupSounds(double distanceFromCameraSqr) } catch (Exception e) { - MyLog.Default.Error($"Sound error with ammo: {AmmoDef.AmmoRound} from {Weapon.Comp.SubtypeName} soundID {AmmoDef.Const.ShotSoundPair.SoundId} cuename {AmmoDef.Const.ShotSoundPair.GetCueName()}"); - throw; + MyLog.Default.Error($"Sound error with ammo: {AmmoDef.AmmoRound} from {Weapon.Comp.TerminalBlock.DisplayName} soundID {AmmoDef.Const.ShotSoundPair.SoundId} cuename {AmmoDef.Const.ShotSoundPair.GetCueName()}" + + $"FireEmitter.Entity null? {FireEmitter?.Entity == null} \n Origin: {Origin}"); + throw e; } } }