public override void Perform() { Drone.Program.Echo($"Miner: {this.State}"); switch (this.State) { case 0: // Startup and Depart Drone.Wake(); Drone.Startup(); Drone.DockingConnector.Disconnect(); Drone.DockingConnector.Enabled = false; Drone.OpenFuelTanks(); InitializeMiningRun(); if (ComputeDeparturePoint) { DeparturePoint = Drone.DockingConnector.GetPosition() + 15 * Drone.DockingConnector.WorldMatrix.Backward; } State = 1; break; case 1: if (Move == null) { Move = new Move(Drone, new Queue <Vector3D>(new[] { DeparturePoint }), Drone.Remote, false); } // Departing if (Move.Perform()) { Move = null; State = 2; } break; case 2: if (ManualSiteApproach) { Drone.Sleep(); return; } if (Move == null) { Move = new Move(Drone, new Queue <Vector3D>(new[] { MiningSite }), Drone.Remote, true); } if (Move.Perform()) { Move = null; State = 3; } break; case 3: if (ManualMining) { Drone.Program.IGC.SendUnicastMessage(ForemanAddress, "Notifications", "I have arrived at the mining site"); Drone.Sleep(); return; } else { Drone.Log("Automated"); ActivateDrills(); if (Tunnel.Mine()) { State = 4; DeactivateDrills(); } } break; case 4: Drone.Wake(); if (DockingAttempt == null) { DockingAttempt = new DockingAttempt(Drone, Drone.DockingConnector, ForemanAddress, DockingRequestChannel); } if (DockingAttempt.Perform()) { State = 5; } break; case 5: DockingAttempt = null; Drone.LogToLcd("Miner Shutting Down"); Drone.Shutdown(); Drone.Sleep(); break; } }
public override void Perform() { Drone.Log($"Performing surveyor: {State}"); switch (this.State) { case "initial": // Startup and Depart Drone.Wake(); Drone.Startup(); Drone.DockingConnector.Disconnect(); Drone.DockingConnector.Enabled = false; Drone.OpenFuelTanks(); Drone.Eye.EnableRaycast = true; DeparturePoint = Drone.DockingConnector.GetPosition() + 15 * Drone.DockingConnector.WorldMatrix.Backward; State = "departing"; break; case "departing": if (Move == null) { Move = new Move(Drone, new Queue <Vector3D>(new[] { DeparturePoint }), Drone.Remote, false); } // Departing if (Move.Perform()) { Move = null; State = "point"; } break; case "point": // Waiting to be oriented by the player Drone.Sleep(); break; case "preparing to move": // fly to obstacle immediately in front and stop on the nearest bounding box corner Drone.Eye.EnableRaycast = true; Drone.Log($"Scan Range: {Drone.Eye.AvailableScanRange}"); if (Drone.Eye.CanScan(20000)) { Obstacle = Drone.Eye.Raycast(20000, 0, 0); if (!Obstacle.IsEmpty()) { StringBuilder sb = new StringBuilder(); sb.Clear(); sb.Append("EntityID: " + Obstacle.EntityId); sb.AppendLine(); sb.Append("Name: " + Obstacle.Name); sb.AppendLine(); sb.Append("Type: " + Obstacle.Type); sb.AppendLine(); sb.Append("Velocity: " + Obstacle.Velocity.ToString("0.000")); sb.AppendLine(); sb.Append("Relationship: " + Obstacle.Relationship); sb.AppendLine(); sb.Append("Size: " + Obstacle.BoundingBox.Size.ToString("0.000")); sb.AppendLine(); sb.Append("Position: " + Obstacle.Position.ToString("0.000")); Drone.LogToLcd($"Found Obstacle: \n{sb}"); State = "shoot"; } } break; case "shoot": MyTuple <double, Vector3D> candidate = new MyTuple <double, Vector3D>( (Obstacle.BoundingBox.GetCorners().First() - Drone.Remote.GetPosition()).Length(), Obstacle.BoundingBox.GetCorners().First() ); foreach (Vector3D corner in Obstacle.BoundingBox.GetCorners()) { double distance = (corner - Drone.Remote.GetPosition()).Length(); if (distance < candidate.Item1) { candidate.Item1 = distance; candidate.Item2 = corner; } } Move = new Move(Drone, new Queue <Vector3D>(new[] { candidate.Item2 }), Drone.Remote, true); State = "flying"; break; case "flying": if (Move.Perform()) { State = "arrived"; } break; case "arrived": Drone.Program.IGC.SendUnicastMessage(ParentAddress, "Notifications", "I have arrived at the survey site"); Drone.Sleep(); return; case "surveying": Drone.Sleep(); break; case "returning": Drone.Wake(); if (DockingAttempt == null) { DockingAttempt = new DockingAttempt(Drone, Drone.DockingConnector, ParentAddress, DockingRequestChannel); } if (DockingAttempt.Perform()) { State = "shutting down"; } ; break; case "shutting down": DockingAttempt = null; Drone.Shutdown(); Drone.Sleep(); break; } }