public void RetractPistons() { if (PistonBack1.Status == PistonStatus.Retracting || PistonBack2.Status == PistonStatus.Retracting || PistonFront1.Status == PistonStatus.Retracting || PistonFront2.Status == PistonStatus.Retracting) { // Nothing.. something is already happening } else { if (PistonBack1.Status != PistonStatus.Retracted) { PistonBack1.Retract(); } else if (PistonBack2.Status != PistonStatus.Retracted) { PistonBack2.Retract(); } else if (PistonFront1.Status != PistonStatus.Retracted) { PistonFront1.Retract(); } else if (PistonFront2.Status != PistonStatus.Retracted) { PistonFront2.Retract(); } else { Message += "ERROR: Pistons are stuck in retracted position."; } } }
public void ActionRetractPistons() { PrintLine($"Do Action <ActionRetractPistons>"); top_piston.Velocity = PISTON_VELOCITY; bottom_piston.Velocity = PISTON_VELOCITY; top_piston.Retract(); bottom_piston.Retract(); }
private static void SetPistonDirection(IMyPistonBase piston, int direction) { if (direction > 0) { piston.Extend(); } else { piston.Retract(); } }
static void ExtendPistonToValue(IMyPistonBase piston, float value) { if (piston.CurrentPosition < value) { piston.SetValue("UpperLimit", value); piston.Extend(); } else { piston.SetValue("LowerLimit", value); piston.Retract(); } }
public void Main(string argument, UpdateType updateSource) { if (argument.Equals("door")) { packet = listeners[0].AcceptMessage(); data = packet.Data.ToString(); if (data.Equals("password")) { open = !open; } } if (argument.Equals("doorLocal")) { open = !open; } if (open) { out1.Extend(); out2.Extend(); if (out1.CurrentPosition == 5) { up1.Extend(); up2.Extend(); } } else { up1.Retract(); up2.Retract(); if (up1.CurrentPosition == 0) { out1.Retract(); out2.Retract(); } } }
private bool ProcessRetract(IMyPistonBase piston) { switch (piston.Status) { case PistonStatus.Retracted: { Echo($"{piston.DisplayNameText} already retracted"); return(true); } case PistonStatus.Retracting: { Echo($"{piston.DisplayNameText} is retracting"); return(false); } default: { Echo($"{piston.DisplayNameText} retracted"); piston.Retract(); return(false); } } }
public void Main(string argument) { //THIS STEP IS IMPORTANT BECAUSE THE TIMER RUNS THE PB WITH DEFAULT PARAMETER, WICH IS EMPTY. //IF YOU WERE TO REMOVE THIS, THE FOLLOWING SWITCH WOULDN'T WORK if (!String.IsNullOrEmpty(argument)) { timer.CustomData = argument.ToLower() + "1"; //the ToLower method makes argument case not matter } //DIFFERENT PHASES ARE REGULATED VIA TIMER'S CUSTOM DATA //notice that extend and retract processes are not the same in reverse because I found out that it would bump into obstacles switch (timer.CustomData) { case "extend1": piston1.Extend(); piston2.Extend(); Sleep(1f); timer.CustomData = "extend2"; //timer's customData gets updated so next time it runs the PB the next phase gets executed break; case "extend2": if (rotor1.TargetVelocityRPM > 0) //just to be sure it doesn't reverse in the wrong way { rotor1.TargetVelocityRPM *= -1; } Sleep(2f); timer.CustomData = "extend3"; break; case "extend3": piston3.Extend(); if (rotor2.TargetVelocityRPM > 0) { rotor2.TargetVelocityRPM *= -1; } Sleep(2f); timer.CustomData = "extend4"; break; case "extend4": piston4.Extend(); Sleep(1.5f); timer.CustomData = "extend5"; break; case "extend5": connector.Connect(); timer.CustomData = ""; break; case "retract1": connector.Disconnect(); piston4.Retract(); if (rotor2.TargetVelocityRPM < 0) { rotor2.TargetVelocityRPM *= -1; } piston3.Retract(); piston2.Retract(); if (rotor1.TargetVelocityRPM < 0) { rotor1.TargetVelocityRPM *= -1; } Sleep(1f); timer.CustomData = "retract2"; break; case "retract2": piston1.Retract(); timer.CustomData = ""; break; default: Echo("unknown timer customdata"); break; } }
public void Main(string argument, UpdateType updateSource) { if (!setupError) { if ((updateSource & UpdateType.Update1) != 0) { switch (reloadState) { case ReloadStates.RELOAD_COMPLETE: // All done! break; case ReloadStates.RETRACTING_PLACER: if (PlacerPiston.CurrentPosition == PlacerPiston.MinLimit) { Echo("Moving clip."); reloadState = ReloadStates.MOVING_CLIP; GridTerminalSystem.GetBlocksOfType <IMyWarhead>(warheads); } else { PlacerPiston.Retract(); } break; case ReloadStates.MOVING_CLIP: var closestWarheadDistance = GetClosestDistance(warheads, PlacerRotor); if (closestWarheadDistance < 0.5) { ClipPiston.Enabled = false; Echo("Loading warhead."); reloadState = ReloadStates.LOADING_WARHEAD; } else if (warheads.Count() == 0 && ClipPiston.CurrentPosition == ClipPiston.MaxLimit) { Echo("Out of warheads."); reloadState = ReloadStates.RELOAD_COMPLETE; } else { ClipPiston.Enabled = true; ClipPiston.Extend(); } break; case ReloadStates.LOADING_WARHEAD: if (PlacerRotor.IsAttached) { var rotors = new List <IMyMotorStator>(); GridTerminalSystem.GetBlocksOfType <IMyMotorStator>(rotors, (IMyMotorStator x) => x.CubeGrid == ClipPiston.TopGrid && x.TopGrid == PlacerRotor.TopGrid); if (rotors.Count() > 0) { var otherRotor = rotors.First(); otherRotor.Detach(); } Echo("Extending placer."); reloadState = ReloadStates.EXTENDING_PLACER; } else { Echo("Attaching."); PlacerRotor.Attach(); } break; case ReloadStates.EXTENDING_PLACER: if (PlacerPiston.CurrentPosition == PlacerPiston.MaxLimit) { Echo("Reload complete."); reloadState = ReloadStates.RELOAD_COMPLETE; } else { PlacerPiston.Extend(); } break; default: Echo("Encountered unexpected state while reloading."); break; } } else if (argument.ToLower() == "reload") { Echo("Retracting placer piston."); PlacerRotor.Detach(); reloadState = ReloadStates.RETRACTING_PLACER; } else if (argument.ToLower() == "fire") { if (PlacerRotor.IsAttached) { Echo("Deploying payload."); var viableWarheads = new List <IMyWarhead>(); GridTerminalSystem.GetBlocksOfType <IMyWarhead>(viableWarheads, (IMyWarhead x) => x.CubeGrid == PlacerRotor.TopGrid); foreach (var warhead in viableWarheads) { warhead.DetonationTime = DetonationTime; warhead.StartCountdown(); } if (viableWarheads.Count() > 0) { countdown = DetonationTime; bombPosition = PlacerRotor.GetPosition(); } PlacerRotor.Detach(); reloadState = ReloadStates.RETRACTING_PLACER; } } else if (argument.ToLower().StartsWith("timer")) { int.TryParse(argument.ToLower().Substring("timer".Length), out DetonationTime); } } }