public void Main(string argument) { switch (state) { case Mode.Idle: if (argument == "Wreck") { state = Mode.Grinding; } if (argument == "Start") { if (visor.AvailableScanRange >= 1000) { Echo("Search for target"); target = visor.Raycast(1000); } } if (target.IsEmpty()) { Echo("Target not found"); return; } Echo("Target found!"); Vector3D targetPos; if (target.HitPosition != null) { targetPos = (Vector3D)target.HitPosition; Vector3D targetVector = targetPos - control.GetPosition(); targetVector.Normalize(); targetPos = targetPos - 20 * targetVector; control.ClearWaypoints(); control.AddWaypoint(targetPos, "Target"); control.GetActionWithName("CollisionAvoidance_On").Apply(control); control.GetActionWithName("DockingMode_On").Apply(control); //!!!Erst einstellungen, dann aktivieren!!! control.GetActionWithName("AutoPilot_On").Apply(control); state = Mode.Flying; } break; case Mode.Flying: break; case Mode.Grinding: List <string> activSensors = CheckSensors(mainGrinderSensors); Vector3D instructions = CheckDirection(activSensors); instructions = CheckObstacles(instructions); float massFactor = control.CalculateShipMass().TotalMass / baseMass; double thrustFactor = Math.Pow(2, massFactor); foreach (IMyThrust thrust in allThruster) { thrust.SetValueFloat("Override", 0); } SetGyros(0, 0, 0); Echo("Vector is: " + (int)instructions.X + " " + (int)instructions.Y + " " + (int)instructions.Z); if (activSensors.Count == 0 && CheckSensors(mainCollisionSensors).Count == 0) { Echo("Going forward"); foreach (IMyThrust thrust in thruster[Side.Front]) { thrust.SetValueFloat("Override", (float)(10 * thrustFactor)); } } else if (IsZero(instructions)) { Echo("Is zero"); foreach (IMyThrust thrust in thruster[Side.Back]) { thrust.SetValueFloat("Override", (float)(5 * thrustFactor)); } } else { Echo("Working"); int basethrust = 35; if (instructions.Z == 0) { instructions.X = Math.Sign(instructions.X) * thrustFactor; instructions.Y = Math.Sign(instructions.Y) * thrustFactor; SetGyros((float)instructions.Y, (float)instructions.X, 0); instructions.X = -instructions.X; instructions.Y = -instructions.Y; basethrust = 5; } List <IMyThrust> neededThruster = instructions.X > 0 ? thruster[Side.Right] : thruster[Side.Left]; if (instructions.X != 0) { foreach (IMyThrust thrust in neededThruster) { thrust.SetValueFloat("Override", (float)(thrustFactor * basethrust)); } foreach (IMyThrust thrust in thruster[Side.Front]) { thrust.SetValueFloat("Override", (float)(5 * thrustFactor)); } } if (instructions.Y != 0) { neededThruster = instructions.Y > 0 ? thruster[Side.Up] : thruster[Side.Down]; foreach (IMyThrust thrust in neededThruster) { thrust.SetValueFloat("Override", (float)(thrustFactor * basethrust)); } foreach (IMyThrust thrust in thruster[Side.Front]) { thrust.SetValueFloat("Override", (float)(5 * thrustFactor)); } } } break; } }