public void Main(string argument, UpdateType updateSource) { blocks.GetBlocks <IMyLightingBlock>("Interior Light").ForEach(light => { Echo(light.DisplayNameText); if (!light.DisplayNameText.Contains("[")) { light.CustomName = "Interior Light"; light.Radius = 10; light.Falloff = .5f; light.Intensity = 4; } }); blocks.GetBlocks <IMyLightingBlock>("Corner Light").ForEach(light => { Echo(light.DisplayNameText); if (!light.DisplayNameText.Contains("[")) { if (light.DisplayNameText.Contains("Double")) { light.CustomName = "Corner Light - Double"; } else { light.CustomName = "Corner Light"; } light.Radius = 10; light.Falloff = .5f; light.Intensity = 3; } }); }
public void Main(string argument, UpdateType updateSource) { if ((updateSource & UpdateType.Trigger) == UpdateType.Trigger) { if (open) { blocks.GetBlocks <IMyMotorStator>(ROTOR_DOOR_POWER).ForEach(r => r.TargetVelocityRPM = -ROTOR_VELOCITY); Runtime.UpdateFrequency = UpdateFrequency.Update10; } else { blocks.GetBlocks <IMyMotorStator>(ROTOR_DOOR_POWER).ForEach(r => r.TargetVelocityRPM = ROTOR_VELOCITY); blocks.GetBlocks <IMyPistonBase>(PISTON_DOOR).ForEach(p => p.Velocity = PISTON_VELOCITY); } open = !open; } if ((updateSource & UpdateType.Update10) == UpdateType.Update10) { if (open) { Runtime.UpdateFrequency = UpdateFrequency.None; } else if (blocks.GetBlocks <IMyMotorStator>(ROTOR_DOOR_POWER).All(r => r.Angle * 180 / Math.PI <= SAFE_ROTOR_ANGLE)) { blocks.GetBlocks <IMyPistonBase>(PISTON_DOOR).ForEach(p => p.Velocity = -PISTON_VELOCITY); Runtime.UpdateFrequency = UpdateFrequency.None; } } }
public ThrustControl(ExpectedBlocks blocks) { thrusters = blocks.GetBlocks <IMyThrust>(CRANE_ARM_THRUSTER); rotor = blocks.GetBlock <IMyMotorStator>(CRANE_ARM_ROTOR); piston = blocks.GetBlock <IMyPistonBase>(CRANE_ARM_PISTON); thrust = thrusters[0].ThrustOverride / 1000; targetAngle = BOTTOM_ANGLE; previousAngle = ConvertAngle(rotor.Angle); speedHistory = new float[60]; accelerationHistory = new float[120]; }
public PayloadTransportStateMachine(ExpectedBlocks blocks, ThrustControl thrustControl) { craneArmRotor = blocks.GetBlock <IMyMotorStator>(CRANE_ARM_ROTOR); craneLiftPistons = blocks.GetBlocks <IMyPistonBase>(CRANE_LIFT_PISTON); this.thrustControl = thrustControl; }
public void Main(string argument, UpdateType updateType) { if ((updateType & UpdateType.Update1) == UpdateType.Update1) { thrustControl.Update(); blocks.GetBlock <IMyTextPanel>(CRANE_ARM_STATUS_PANEL).WritePublicText("Crane Arm Status\n\n" + "Program\n" + " State: " + state.ToString() + "\n\n" + thrustControl.GetDebugText()); } if ((updateType & UpdateType.Terminal) == UpdateType.Terminal || (updateType & UpdateType.Trigger) == UpdateType.Trigger) { switch (argument) { case LOW: thrustControl.Adjust(ThrustControl.BOTTOM_ANGLE); break; case HIGH: thrustControl.Adjust(ThrustControl.TOP_ANGLE); break; case PICKUP: if (state == State.WaitingForPayload) { state = State.AcceptingPayload; stateMachine = payloadPickupStateMachine.GenerateStateMachine(); Runtime.UpdateFrequency |= UpdateFrequency.Once; } break; case DUMP: if (state == State.WaitingForTransport || state == State.WaitingForPayload) { blocks.GetBlocks <IMyShipConnector>(CRANE_ARM_CONNECTOR).ForEach(connector => { connector.Disconnect(); connector.Enabled = false; }); thrustControl.OverrideThrust(50); state = State.WaitingForPayload; } break; case TRANSPORT: if (state == State.WaitingForTransport) { state = State.TransportingPayload; stateMachine = payloadTransportStateMachine.GenerateStateMachine(); Runtime.UpdateFrequency |= UpdateFrequency.Once; } break; case DROPOFF: if (state == State.WaitingForDropoff) { blocks.GetBlocks <IMyShipConnector>(CRANE_ARM_CONNECTOR).ForEach(connector => { connector.Disconnect(); connector.Enabled = false; }); state = State.WaitingForReset; } break; case RESET: state = State.Reseting; stateMachine = craneArmResetStateMachine.GenerateStateMachine(); Runtime.UpdateFrequency |= UpdateFrequency.Once; break; default: if (argument.Length == 0) { Echo("ERROR Missing argument"); } else { Echo("ERROR Unrecognized argument: " + argument); } break; } } if ((updateType & UpdateType.Once) == UpdateType.Once) { RunStateMachine(); } }
public PayloadPickupStateMachine(ExpectedBlocks blocks) { craneLiftPistons = blocks.GetBlocks <IMyPistonBase>(CRANE_LIFT_PISTON); craneConnectors = blocks.GetBlocks <IMyShipConnector>(CRANE_ARM_CONNECTOR); }
public CraneArmResetStateMachine(ExpectedBlocks blocks, ThrustControl thrustControl) { craneLiftPistons = blocks.GetBlocks <IMyPistonBase>(CRANE_LIFT_PISTON); this.thrustControl = thrustControl; }