public WelderController(GridProgramRef gridProgramRef, WelderConfig welderConfig) { // Safe guard: Throw an exception if GridTerminalSystem is null if (gridProgramRef.GridTerminalSystem == null) { throw new ArgumentNullException("Passed GTS reference was null."); } if (gridProgramRef.Echo == null) { throw new ArgumentNullException("Passed Echo reference was null."); } // Initialize initial variables WelderList = new List <IMyShipWelder>(); GridTerminalSystem = gridProgramRef.GridTerminalSystem; Echo = gridProgramRef.Echo; WelderConfig = welderConfig; // Safe guard: Throw an exception if group is non existent var blocks = GridTerminalSystem.GetBlockGroupWithName(WelderConfig.WelderGroupName); if (blocks == null) { throw new ArgumentException("Welder block group was not found."); } blocks.GetBlocksOfType(WelderList); ApplyConfig(); }
public ProjectionController(GridProgramRef gridProgramRef, string projectorName, ProjectorState projectorState) { if (gridProgramRef.GridTerminalSystem == null) { throw new ArgumentNullException("Passed GTS reference was null."); } if (gridProgramRef.Echo == null) { throw new ArgumentNullException("Passed Echo reference was null."); } if (gridProgramRef.Utils == null) { throw new ArgumentNullException("Passed UtilsClass reference was null."); } if (projectorName == null) { throw new ArgumentNullException("projectorName was null."); } if (!gridProgramRef.Utils.BlockWithNameExists(projectorName)) { throw new ArgumentNullException("Projector was not found."); } Projector = gridProgramRef.GridTerminalSystem.GetBlockWithName(projectorName) as IMyProjector; GridProgram = gridProgramRef; ProjectorName = projectorName; ProjectorState = projectorState; GridTerminalSystem = GridProgram.GridTerminalSystem; Safeguard_Check(); }
public TrackerConfig(GridProgramRef gridref, string trackerTopLeft_Name, string trackerTopRight_Name, string trackerBottomLeft_Name, string trackerBottomRight_Name, int shipyard_Length) : this() { if (shipyard_Length <= 0) { throw new ArgumentNullException("Shipyard_Length must be a positive value."); } Shipyard_Length = shipyard_Length; if (trackerTopLeft_Name == null) { throw new ArgumentNullException("trackerTopLeft_Name was null."); } if (trackerTopRight_Name == null) { throw new ArgumentNullException("trackerTopRight_Name was null."); } if (trackerBottomLeft_Name == null) { throw new ArgumentNullException("trackerBottomLeft_Name was null."); } if (trackerBottomRight_Name == null) { throw new ArgumentNullException("trackerBottomRight_Name was null."); } TrackerTopLeft_Name = trackerTopLeft_Name; TrackerTopRight_Name = trackerTopRight_Name; TrackerBottomLeft_Name = trackerBottomLeft_Name; TrackerBottomRight_Name = trackerBottomRight_Name; if (gridref.GridTerminalSystem == null) { throw new ArgumentNullException("Passed GTS reference was null."); } if (!gridref.Utils.BlockWithNameExists(trackerTopLeft_Name)) { throw new ArgumentNullException("TrackerTopLeft was not found."); } if (!gridref.Utils.BlockWithNameExists(trackerTopRight_Name)) { throw new ArgumentNullException("TrackerTopRight was not found."); } if (!gridref.Utils.BlockWithNameExists(trackerBottomLeft_Name)) { throw new ArgumentNullException("TrackerBottomLeft was not found."); } if (!gridref.Utils.BlockWithNameExists(trackerBottomRight_Name)) { throw new ArgumentNullException("TrackerBottomRight was not found."); } TrackerTopLeft = gridref.GridTerminalSystem.GetBlockWithName(trackerTopLeft_Name) as IMyCameraBlock; TrackerTopRight = gridref.GridTerminalSystem.GetBlockWithName(trackerTopRight_Name) as IMyCameraBlock; TrackerBottomLeft = gridref.GridTerminalSystem.GetBlockWithName(trackerBottomLeft_Name) as IMyCameraBlock; TrackerBottomRight = gridref.GridTerminalSystem.GetBlockWithName(trackerBottomRight_Name) as IMyCameraBlock; }
public CargoController(GridProgramRef gridProgramRef, bool sameGridOnly) { if (gridProgramRef.GridTerminalSystem == null) { throw new ArgumentNullException("Passed GTS reference was null."); } if (gridProgramRef.Echo == null) { throw new ArgumentNullException("Passed Echo reference was null."); } GridProgramRef = gridProgramRef; CargoContainers = new List <IMyCargoContainer>(); GridProgramRef.GridTerminalSystem.GetBlocksOfType(CargoContainers, b => b.CubeGrid == GridProgramRef.Me.CubeGrid || !sameGridOnly); if (CargoContainers.Count == 0) { throw new Exception("No cargo containers were found."); } }
public PlatformMotor(GridProgramRef gridProgramRef, string pistonGroupName, MotorConfig motorConfig) { // Safe guard: Throw an exception if GridTerminalSystem is null if (gridProgramRef.GridTerminalSystem == null) { throw new ArgumentNullException("Passed GTS reference was null."); } if (gridProgramRef.Echo == null) { throw new ArgumentNullException("Passed Echo reference was null."); } // Initialize initial variables PistonGroupName = pistonGroupName; PistonList = new List <IMyPistonBase>(); MotorState = MotorState.Idle; GridTerminalSystem = gridProgramRef.GridTerminalSystem; Echo = gridProgramRef.Echo; MotorConfig = motorConfig; // Validate motor config if (MotorConfig.MotorSpeed < 0) { throw new ArgumentException("MotorConfig: Velocity must be a signed number."); } if (MotorConfig.MotorMaxElevation < 0) { throw new ArgumentException("MotorConfig: Max elevation must be a signed number."); } if (MotorConfig.MotorMinElevation < 0) { throw new ArgumentException("MotorConfig: Min elevation must be a signed number."); } // Validate motor config end // Safe guard: Throw an exception if group is non existent var blocks = GridTerminalSystem.GetBlockGroupWithName(PistonGroupName); if (blocks == null) { throw new ArgumentException("Piston block group was not found."); } blocks.GetBlocksOfType(PistonList); ApplyConfig(); }
public ProjectionController(GridProgramRef gridProgramRef, IMyProjector projector, ProjectorState projectorState) { if (gridProgramRef.GridTerminalSystem == null) { throw new ArgumentNullException("Passed GTS reference was null."); } if (gridProgramRef.Echo == null) { throw new ArgumentNullException("Passed Echo reference was null."); } if (projector == null) { throw new ArgumentNullException("Passed projector reference was null."); } GridProgram = gridProgramRef; Projector = projector; ProjectorName = projector.Name; ProjectorState = projectorState; GridTerminalSystem = GridProgram.GridTerminalSystem; Safeguard_Check(); }
public PlatformTracker(TrackerConfig trackerConfig, GridProgramRef gridprogramref) { TrackerConfig = trackerConfig; gridProgramRef = gridprogramref; Safeguard_Check(); }
public void SetGridProgramRef(GridProgramRef gridProgramRef) { GridProgramRef = gridProgramRef; }
public UtilsClass(GridProgramRef gridProgramRef) { GridProgramRef = gridProgramRef; }
public static void Initialize(GridProgramRef gridProgramRef) { if (gridProgramRef.GridTerminalSystem == null) { throw new ArgumentNullException("Passed GTS reference was null."); } if (gridProgramRef.Echo == null) { throw new ArgumentNullException("Passed Echo reference was null."); } if (gridProgramRef.Me == null) { throw new ArgumentNullException("Passed Me reference was null."); } GridProgramRef = gridProgramRef; GridTerminalSystem = gridProgramRef.GridTerminalSystem; Echo = gridProgramRef.Echo; Me = gridProgramRef.Me; Utils = gridProgramRef.Utils; // get data from customdata string[] splitted = Me.CustomData.Split(new char[] { '$' }); string[] componentNames = splitted[0].Split(new char[] { '*' }); for (var i = 0; i < componentNames.Length; i++) { componentNames[i] = "MyObjectBuilder_BlueprintDefinition/" + componentNames[i]; } //$SmallMissileLauncher*(null)=0:4,2:2,5:1,7:4,8:1,4:1*LargeMissileLauncher=0:35,2:8,5:30,7:25,8:6,4:4$ char[] asterisk = new char[] { '*' }; char[] equalsign = new char[] { '=' }; char[] comma = new char[] { ',' }; char[] colon = new char[] { ':' }; for (var i = 1; i < splitted.Length; i++) { // splitted[1 to n] are type names and all associated subtypes // blocks[0] is the type name, blocks[1 to n] are subtypes and component amounts string[] blocks = splitted[i].Split(asterisk); string typeName = "MyObjectBuilder_" + blocks[0]; for (var j = 1; j < blocks.Length; j++) { string[] compSplit = blocks[j].Split(equalsign); string blockName = typeName + '/' + compSplit[0]; // add a new dict for the block try { blueprints.Add(blockName, new Dictionary <string, int>()); } catch (Exception e) { Echo("Error adding block: " + blockName); } var components = compSplit[1].Split(comma); foreach (var component in components) { string[] amounts = component.Split(colon); int idx = Convert.ToInt32(amounts[0]); int amount = Convert.ToInt32(amounts[1]); string compName = componentNames[idx]; blueprints[blockName].Add(compName, amount); } } } }
public void Main(string arguments, UpdateType updateSource) { if (arguments == "i") { GridProgram = new GridProgramRef(GridTerminalSystem, null, Echo, Me); GridProgram.Utils = new UtilsClass(GridProgram); BlueprintDefinitions.Initialize(GridProgram); Echo("Initialized blueprint definitions."); Echo($"{BlueprintDefinitions.blueprints.Count} definitions loaded."); projectionController = new ProjectionController(GridProgram, "Projector", ProjectorState.Unpowered); projectionController.SetProjectorState(ProjectorState.Powered); if (!projectionController.Projector.IsProjecting) { Echo("Projector wasn't projecting."); return; } Dictionary <string, int> components = projectionController.GetRequiredComponents(); foreach (KeyValuePair <string, int> kvp in components) { Echo($"{kvp.Key}: {kvp.Value}"); } } if (arguments == "a") { List <IMyAssembler> assemblers = new List <IMyAssembler>(); GridTerminalSystem.GetBlocksOfType(assemblers); IMyAssembler assembler = assemblers[0]; IMyTextPanel textpanel = GridTerminalSystem.GetBlockWithName("TXTPNL") as IMyTextPanel; MyDefinitionId id = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/BulletproofGlass"); assembler.AddQueueItem(id, 1.0); return; } if (arguments == "p") { IMyTextPanel textpanel = GridTerminalSystem.GetBlockWithName("TXTPNL") as IMyTextPanel; textpanel.WriteText(projectionController.Projector.DetailedInfo); return; } if (arguments == "m") { return; } switch (internal_state) { case 0: // config try { GridProgram = new GridProgramRef(GridTerminalSystem, null, Echo, Me); GridProgram.Utils = new UtilsClass(GridProgram); platformMotor = new PlatformMotor(GridProgram, "Pistons", new MotorConfig(0.05f, 10f, 0.05f, MotorExtendType.POSITIVE)); platformTracker = new PlatformTracker(new TrackerConfig(GridProgram, "Camera X1", "Camera X2", "Camera Y1", "Camera Y2", 370), GridProgram); welderController = new WelderController(GridProgram, new WelderConfig("Welders", WelderState.Unpowered)); cargoController = new CargoController(GridProgram, true); projectionController = new ProjectionController(GridProgram, "Projector", ProjectorState.Unpowered); platformTracker.EnableRaycast(); internal_state = 1; } catch (Exception ex) { Echo($"Execution halted, safeguard violation raised in {ex.TargetSite}: {ex.Message}"); } break; case 1: try { platformMotor.SetMotorState(MotorState.Extend); internal_state = 2; } catch (Exception ex) { Echo($"Execution halted, safeguard violation raised in {ex.TargetSite}: {ex.Message}"); } break; case 2: try { TrackedPlatform tp = platformTracker.Track(); platformTracker.IsPlatformSafe(tp); } catch (Exception ex) { Echo($"Execution halted, safeguard violation raised in {ex.TargetSite}: {ex.Message}"); } break; } }