From 2e3d41f9b9af5e26cf18478752432ba18ee0e17a Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Thu, 9 May 2024 23:33:15 -0500 Subject: [PATCH 1/2] add filtering for what approximates in a ship --- .../Scripts/ScCoordWriter/ScCoordWriter.cs | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Utility Mods/Stable/SCCoordinateOutput/Data/Scripts/ScCoordWriter/ScCoordWriter.cs b/Utility Mods/Stable/SCCoordinateOutput/Data/Scripts/ScCoordWriter/ScCoordWriter.cs index 6a90c6298..afbc5d2a9 100644 --- a/Utility Mods/Stable/SCCoordinateOutput/Data/Scripts/ScCoordWriter/ScCoordWriter.cs +++ b/Utility Mods/Stable/SCCoordinateOutput/Data/Scripts/ScCoordWriter/ScCoordWriter.cs @@ -110,7 +110,47 @@ private void OnEntityRemove(IMyEntity entity) private bool ShouldBeTracked(IMyEntity entity) { var grid = entity as IMyCubeGrid; - return grid != null && !grid.IsStatic; + if (grid == null || grid.IsStatic || grid.Physics == null) + return false; + + bool hasPowerBlock = false; + bool hasGyro = false; + bool hasThruster = false; + + var blocks = new List(); + grid.GetBlocks(blocks, block => + { + // Check for functional power block (reactor or battery) + if (!hasPowerBlock) + { + var battery = block.FatBlock as IMyBatteryBlock; + var reactor = block.FatBlock as IMyReactor; + if ((battery != null && battery.IsFunctional) || (reactor != null && reactor.IsFunctional)) + hasPowerBlock = true; + } + + // Check for functional gyroscope + if (!hasGyro) + { + var gyro = block.FatBlock as IMyGyro; + if (gyro != null && gyro.IsFunctional) + hasGyro = true; + } + + // Check for functional thruster + if (!hasThruster) + { + var thruster = block.FatBlock as IMyThrust; + if (thruster != null && thruster.IsFunctional) + hasThruster = true; + } + + // Continue iterating until all conditions are checked or all are true + return !(hasPowerBlock && hasGyro && hasThruster); // Return false to stop iterating if all conditions are met + }); + + // Only track grids that have functional power blocks, gyroscopes, and thrusters + return hasPowerBlock && hasGyro && hasThruster; } protected override void UnloadData() From a3f4b0e2eb41b59e5ecca3653ca415604d7dc062 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Thu, 9 May 2024 23:58:06 -0500 Subject: [PATCH 2/2] get faction background color --- .../Scripts/ScCoordWriter/ScCoordWriter.cs | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/Utility Mods/Stable/SCCoordinateOutput/Data/Scripts/ScCoordWriter/ScCoordWriter.cs b/Utility Mods/Stable/SCCoordinateOutput/Data/Scripts/ScCoordWriter/ScCoordWriter.cs index afbc5d2a9..245ed0de3 100644 --- a/Utility Mods/Stable/SCCoordinateOutput/Data/Scripts/ScCoordWriter/ScCoordWriter.cs +++ b/Utility Mods/Stable/SCCoordinateOutput/Data/Scripts/ScCoordWriter/ScCoordWriter.cs @@ -23,10 +23,10 @@ public class ScCoordWriter : MySessionComponentBase private TextWriter Writer; private bool Recording; - private const int Version = 1; + private const int Version = 2; private readonly string[] _columns = { - "kind", "name", "owner", "faction", "entityId", "health", "position", "rotation" + "kind", "name", "owner", "faction", "factionColor", "entityId", "health", "position", "rotation" }; private const string Extension = ".scc"; @@ -212,7 +212,6 @@ public override void UpdateAfterSimulation() if (TickCounter++ < 60) { return; } TickCounter = 0; - // TODO: Use seconds, milliseconds, frames, or ticks since start of recording instead? Writer.WriteLine($"start_block,{DateTime.Now}"); TrackedItems.ForEach(element => { @@ -223,30 +222,13 @@ public override void UpdateAfterSimulation() } var grid = element.item as IMyCubeGrid; + var owner = GetGridOwner(grid); + var factionName = GetFactionName(owner); + var factionColor = GetFactionColor(owner); - // TODO: Just use the grid's matrix and forget cockpits? - IMyCockpit Cockpit = null; - var cubeGrid = grid as MyCubeGrid; - if (cubeGrid != null && cubeGrid.HasMainCockpit()) - { - Cockpit = cubeGrid.MainCockpit as IMyCockpit; - } - - if (Cockpit == null) - { - foreach (var cockpit in grid.GetFatBlocks()) - { - if (cockpit.IsOccupied) - { - Cockpit = cockpit; - break; - } - } - } - MatrixD worldMatrix = Cockpit?.WorldMatrix ?? grid.WorldMatrix; - Vector3D forwardDirection = worldMatrix.Forward; + MatrixD worldMatrix = grid.WorldMatrix; var position = grid.GetPosition(); - var rotation = Quaternion.CreateFromForwardUp(forwardDirection, grid.WorldMatrix.Up); + var rotation = Quaternion.CreateFromForwardUp(worldMatrix.Forward, worldMatrix.Up); var blockList = new List(); grid.GetBlocks(blockList); @@ -256,10 +238,8 @@ public override void UpdateAfterSimulation() element.initialBlockCount = currentBlockCount; } var healthPercent = (float)currentBlockCount / element.initialBlockCount; - var owner = GetGridOwner(grid); - var faction = GetFactionName(owner); - Writer.WriteLine($"grid,{grid.CustomName},{owner?.DisplayName ?? "Unowned"},{faction},{grid.EntityId},{SmallDouble(healthPercent)},{SmallVector3D(position)},{SmallQuaternion(rotation)}"); + Writer.WriteLine($"grid,{grid.CustomName},{owner?.DisplayName ?? "Unowned"},{factionName},{factionColor},{grid.EntityId},{SmallDouble(healthPercent)},{SmallVector3D(position)},{SmallQuaternion(rotation)}"); }); Writer.Flush(); } @@ -332,6 +312,21 @@ private string GetFactionName(IMyIdentity player) return playerFaction != null ? playerFaction.Name : "Unowned"; } + private string GetFactionColor(IMyIdentity owner) + { + if (owner == null) return SmallVector3D(Vector3D.Zero); + + var faction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(owner.IdentityId); + if (faction != null) + { + // Example, replace with actual way to get faction color if available + + return SmallVector3D(faction.CustomColor); + } + return "None"; // Default color if no faction or no color defined + } + + public IMyIdentity GetGridOwner(IMyCubeGrid grid) { IMyIdentity owner = null;