diff --git a/Data/Scripts/CoreSystems/Ai/AiConstruct.cs b/Data/Scripts/CoreSystems/Ai/AiConstruct.cs index c9350525..86f4499d 100644 --- a/Data/Scripts/CoreSystems/Ai/AiConstruct.cs +++ b/Data/Scripts/CoreSystems/Ai/AiConstruct.cs @@ -60,38 +60,15 @@ public void RegisterSubGrid(MyCubeGrid grid) grid.OnFatBlockAdded += FatBlockAdded; grid.OnFatBlockRemoved += FatBlockRemoved; - //BDC Temp debugging - var tempBlockArray = grid.GetFatBlocks().ToArray(); - try + foreach (var cube in grid.GetFatBlocks()) { - 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; + 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); - } - } - 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; + if (battery != null || cube.HasInventory || stator != null || tool != null || offense != null) + FatBlockAdded(cube); } SubGridsRegistered[grid] = byte.MaxValue; } diff --git a/Data/Scripts/CoreSystems/Ai/AiEvents.cs b/Data/Scripts/CoreSystems/Ai/AiEvents.cs index fd8d5832..9a2bfdc7 100644 --- a/Data/Scripts/CoreSystems/Ai/AiEvents.cs +++ b/Data/Scripts/CoreSystems/Ai/AiEvents.cs @@ -186,16 +186,20 @@ 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); + Session.I.FutureEvents.Schedule(QueuedBlockRemoval, cube, 10); + //cube.CubeGrid.RemoveBlock(cube.SlimBlock, true); } } } } + private void QueuedBlockRemoval(object o) + { + var cube = o as MyCubeBlock; + if (cube != null) + cube.CubeGrid.RemoveBlock(cube.SlimBlock, true); + } + private void FatBlockRemoved(MyCubeBlock cube) { var stator = cube as IMyMotorStator; diff --git a/Data/Scripts/CoreSystems/EntityComp/ModelSupport/Dummies.cs b/Data/Scripts/CoreSystems/EntityComp/ModelSupport/Dummies.cs index 1df226bd..e7b6ba75 100644 --- a/Data/Scripts/CoreSystems/EntityComp/ModelSupport/Dummies.cs +++ b/Data/Scripts/CoreSystems/EntityComp/ModelSupport/Dummies.cs @@ -39,6 +39,8 @@ internal MyEntity Entity internal Vector3D CachedPos; internal Vector3D CachedDir; internal Vector3D CachedUpDir; + internal bool Ejector; + private readonly string[] _path; private readonly Dictionary _tmp1 = new Dictionary(); @@ -46,11 +48,12 @@ internal MyEntity Entity private readonly Part _part; private readonly DummyInfo _info = new DummyInfo(); private MyEntity _entity; - public Dummy(MyEntity e, Part w, params string[] path) + public Dummy(MyEntity e, Part w, bool ejector, params string[] path) { _part = w; Entity = e; _path = path; + Ejector = ejector; } private bool _failed = true; @@ -133,7 +136,10 @@ public DummyInfo Info var offset = !wComp.Rifle.GunBase.HasIronSightsActive; partWorldMatrix = wComp.GetHandWeaponApproximateWorldMatrix(offset); Vector3D.Transform(ref localPos, ref partWorldMatrix, out CachedPos); - CachedDir = Vector3D.Normalize(wComp.CharacterPosComp.LogicalCrosshairPoint - CachedPos); + if (Ejector) + Vector3D.TransformNormal(ref localDir, ref partWorldMatrix, out CachedDir); + else + CachedDir = Vector3D.Normalize(wComp.CharacterPosComp.LogicalCrosshairPoint - CachedPos); CachedUpDir = partWorldMatrix.Up; } else @@ -146,7 +152,7 @@ public DummyInfo Info if (rifle) // I lack the words to describe the level of my disgust { var wComp = (Weapon.WeaponComponent)_part.BaseComp; - clientRifleOffset = !wComp.Rifle.GunBase.HasIronSightsActive; + clientRifleOffset = !wComp.Rifle.GunBase.HasIronSightsActive && !Ejector; var keenWhyPartWorldMatrix = wComp.GetHandWeaponApproximateWorldMatrix(clientRifleOffset); CachedUpDir = keenWhyPartWorldMatrix.Up; if (clientRifleOffset) diff --git a/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponFields.cs b/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponFields.cs index 3ad6dd2c..cdf11609 100644 --- a/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponFields.cs +++ b/Data/Scripts/CoreSystems/EntityComp/Parts/Weapon/WeaponFields.cs @@ -409,12 +409,12 @@ internal Weapon(MyEntity entity, WeaponSystem system, int partId, WeaponComponen string ejectorMatch; MyEntity ejectorPart; if (System.HasEjector && Comp.Platform.Parts.FindFirstDummyByName(System.Values.Assignments.Ejector, System.AltEjectorName, out ejectorPart, out ejectorMatch)) - Ejector = new Dummy(ejectorPart,this, System.Values.Assignments.Ejector); + Ejector = new Dummy(ejectorPart, this, true, System.Values.Assignments.Ejector); string scopeMatch; MyEntity scopePart; if (System.HasScope && Comp.Platform.Parts.FindFirstDummyByName(System.Values.Assignments.Scope, System.AltScopeName, out scopePart, out scopeMatch)) - Scope = new Dummy(scopePart, this, scopeMatch); + Scope = new Dummy(scopePart, this, false, scopeMatch); comp.Platform.SetupWeaponUi(this); diff --git a/Data/Scripts/CoreSystems/EntityComp/PlatformInit.cs b/Data/Scripts/CoreSystems/EntityComp/PlatformInit.cs index 4fdbe253..a8dca7ae 100644 --- a/Data/Scripts/CoreSystems/EntityComp/PlatformInit.cs +++ b/Data/Scripts/CoreSystems/EntityComp/PlatformInit.cs @@ -470,7 +470,7 @@ private void CompileTurret(Weapon weapon) var muzzleName = weaponSystem.Muzzles[i]; if (weapon.Muzzles[i] == null) { - weapon.Dummies[i] = new Dummy(weapon.MuzzlePart.Entity, weapon, muzzleName); + weapon.Dummies[i] = new Dummy(weapon.MuzzlePart.Entity, weapon, false, muzzleName); var muzzle = new Weapon.Muzzle(weapon, i); weapon.Muzzles[i] = muzzle; weapon.MuzzleIdToName.Add(i, muzzleName); diff --git a/Data/Scripts/CoreSystems/Session/SessionAnimationMgr.cs b/Data/Scripts/CoreSystems/Session/SessionAnimationMgr.cs index 7416dcba..7acbe86a 100644 --- a/Data/Scripts/CoreSystems/Session/SessionAnimationMgr.cs +++ b/Data/Scripts/CoreSystems/Session/SessionAnimationMgr.cs @@ -821,7 +821,7 @@ private static bool CreateParticleDummy(MyEntity cube, string emptyName, out Dum if (dummyPart != null) { - particleDummy = new Dummy(dummyPart, null, emptyName); + particleDummy = new Dummy(dummyPart, null, false, emptyName); partName = nameLookup[dummyPart]; return true; }