private void ComputeReservedSpace(MyObjectBuilder_CubeGrid primaryGrid, IEnumerable <MyObjectBuilder_CubeGrid> allGrids, BlockSetInfo info) { m_reservedSpaces.Clear(); ReservedSpace = new BoundingBox(); foreach (var block in primaryGrid.CubeBlocks) { foreach (var name in block.ConfigNames()) { if (!name.StartsWithICase(ReservedSpacePrefix)) { continue; } var args = name.Substring(ReservedSpacePrefix.Length).Trim().Split(' ').Select(x => x.Trim()).Where(x => x.Length > 0).ToArray(); var box = PartDummyUtils.ParseReservedSpace(MyDefinitionManager.Static.GetCubeSize(primaryGrid.GridSizeEnum), block, args, Logger.Warning); box.Box.Max += (Vector3I)block.Min; box.Box.Min += (Vector3I)block.Min; if (m_reservedSpaces.Count == 0) { ReservedSpace = new BoundingBox(box.Box.Min, box.Box.Max); } ReservedSpace = ReservedSpace.Include(box.Box.Min); ReservedSpace = ReservedSpace.Include(box.Box.Max); m_reservedSpaces.Add(box); } } }
private void ComputeMountPoints(MyObjectBuilder_CubeGrid primaryGrid, IEnumerable <MyObjectBuilder_CubeGrid> allGrids, BlockSetInfo info) { m_mountPoints.Clear(); foreach (var block in primaryGrid.CubeBlocks) { foreach (var name in block.ConfigNames()) { if (!name.StartsWithICase(MountPrefix)) { continue; } var parts = PartDummyUtils.ConfigArguments(name.Substring(MountPrefix.Length)).ToArray(); if (parts.Length < 3) { continue; } var spec = parts[0].Split(':'); if (spec.Length != 2) { continue; } var mountType = spec[0]; var mountPiece = spec[1]; var mountName = parts[1]; Dictionary <string, PartMount> partsOfType; if (!m_mountPoints.TryGetValue(mountType, out partsOfType)) { partsOfType = m_mountPoints[mountType] = new Dictionary <string, PartMount>(); } PartMount mount; if (!partsOfType.TryGetValue(mountName, out mount)) { mount = partsOfType[mountName] = new PartMount(this, mountType, mountName); } var args = new string[parts.Length - 2]; for (var i = 2; i < parts.Length; i++) { args[i - 2] = parts[i]; } var pmpb = new PartMountPointBlock(mount); pmpb.Init(block, mountPiece, args); mount.Add(pmpb); } } m_mountPointBlocks.Clear(); foreach (var mount in MountPoints) { foreach (var block in mount.Blocks) { m_mountPointBlocks[block.AnchorLocation] = block; } } }
public void Init(MyObjectBuilder_CubeBlock block, string piece, IEnumerable <string> args) { Piece = piece; MountDirection6 = Base6Directions.GetOppositeDirection(Base6Directions.GetCross(block.BlockOrientation.Up, block.BlockOrientation.Forward)); AnchorLocation = block.Min; AdjacencyRule = AdjacencyRule.Any; BiasDirection6 = null; SecondBiasDirection6 = null; var blockOrientation = new MatrixI(block.BlockOrientation); foreach (var arg in args) { if (arg.StartsWithICase(PartDummyUtils.ArgumentMountDirection)) { Base6Directions.Direction tmpMountDirection; if (Enum.TryParse(arg.Substring(PartDummyUtils.ArgumentMountDirection.Length), out tmpMountDirection)) { MountDirection6 = blockOrientation.GetDirection(tmpMountDirection); } else { Logging.Error("Failed to parse mount point direction argument \"{0}\"", arg); } } else if (arg.StartsWithICase(PartDummyUtils.ArgumentBiasDirection)) { Base6Directions.Direction tmpBiasDirection; if (Enum.TryParse(arg.Substring(PartDummyUtils.ArgumentBiasDirection.Length), out tmpBiasDirection)) { BiasDirection6 = blockOrientation.GetDirection(tmpBiasDirection); } else { Logging.Error("Failed to parse bias direction argument \"{0}\"", arg); } } else if (arg.StartsWithICase(PartDummyUtils.ArgumentSecondBiasDirection)) { Base6Directions.Direction tmpBiasDirection; if (Enum.TryParse(arg.Substring(PartDummyUtils.ArgumentSecondBiasDirection.Length), out tmpBiasDirection)) { SecondBiasDirection6 = blockOrientation.GetDirection(tmpBiasDirection); } else { Logging.Error("Failed to parse second bias direction argument \"{0}\"", arg); } } else if (arg.StartsWithICase(PartDummyUtils.ArgumentAnchorPoint)) { Vector3I anchor; if (PartDummyUtils.TryParseVector(arg.Substring(PartDummyUtils.ArgumentAnchorPoint.Length), out anchor)) { AnchorLocation = block.Min + anchor; continue; } Logging.Error("Failed to parse anchor location argument \"{0}\"", arg); } else if (arg.StartsWithICase(PartDummyUtils.ArgumentAdjacencyRule)) // Adjacency Rule { AdjacencyRule rule; if (Enum.TryParse(arg.Substring(PartDummyUtils.ArgumentAdjacencyRule.Length), out rule)) { AdjacencyRule = rule; } else { Logging.Error("Failed to parse adjacency rule argument \"{0}\"", arg); } } else { Logging.Error("Failed to parse mount point argument \"{0}\"", arg); } } // ReSharper disable once InvertIf if (SecondBiasDirection6.HasValue && !BiasDirection6.HasValue) { BiasDirection6 = SecondBiasDirection6; SecondBiasDirection6 = null; } }
public static ReservedSpace ParseReservedSpace(float gridSize, MyObjectBuilder_CubeBlock src, string[] args, Utilities.LoggingCallback log = null) { var optional = false; var shared = false; var nSet = false; var pSet = false; var nExt = Vector3.Zero; var pExt = Vector3.Zero; foreach (var arg in args) { if (arg.StartsWithICase("NE:")) { Vector3 tmp; if (PartDummyUtils.TryParseVector(arg.Substring(3), out tmp)) { nSet = true; nExt = tmp; } else { log?.Invoke("Failed to decode negative extent argument \"{0}\"", arg); } } else if (arg.StartsWithICase("PE:")) { Vector3 tmp; if (PartDummyUtils.TryParseVector(arg.Substring(3), out tmp)) { pSet = true; pExt = tmp; } else { log?.Invoke("Failed to decode positive extent argument \"{0}\"", arg); } } else if (arg.Equals("share", StringComparison.CurrentCultureIgnoreCase) || arg.Equals("shared", StringComparison.CurrentCultureIgnoreCase)) { shared = true; } else if (arg.Equals("opt", StringComparison.CurrentCultureIgnoreCase) || arg.Equals("optional", StringComparison.CurrentCultureIgnoreCase) || arg.Equals("hint", StringComparison.CurrentCultureIgnoreCase)) { optional = true; } else { log?.Invoke("Failed to decode argument \"{0}\"", arg); } } if (!nSet || !pSet) { var sense = src as MyObjectBuilder_SensorBlock; if (sense != null) { if (!nSet) { nExt = (Vector3)sense.FieldMin / gridSize; } if (!pSet) { pExt = (Vector3)sense.FieldMax / gridSize; } } else { log?.Invoke("Isn't a sensor block and isn't fully specified"); } } var srcTra = new MatrixI(src.BlockOrientation).GetFloatMatrix(); nExt = Vector3.TransformNormal(nExt, srcTra); pExt = Vector3.TransformNormal(pExt, srcTra); return(new ReservedSpace() { Box = new BoundingBox(nExt, pExt), IsOptional = optional, IsShared = shared }); }