/// <summary>Start harvesting.</summary> /// <returns>true iff harvesting could be started</returns> public bool Start() { LogEntered("Start()"); HarvestState = Navigator.ReportableState.H_Ready; try { IEnumerator <Ingame.IMyTerminalBlock> drillEnum = GetDrills().GetEnumerator(); drillEnum.MoveNext(); NavigationDrill = drillEnum.Current as IMyCubeBlock; // while harvester is random, drill choice does not matter (assuming all drills face the same way) //EnableDrills(false); CNS_Store(); //CNS_SetHarvest(); myLogger.debugLog("Started harvester", "Start()"); SetNextStage(Ready, false); return(Run()); } catch (Exception ex) { myLogger.debugLog("Failed to start, Ex: " + ex, "Start()"); return(false); } }
///// <summary>Current stage of harvesting</summary> //private Action StageAction; public HarvesterAsteroid(Navigator myNav) { this.myNav = myNav; this.myCache = CubeGridCache.GetFor(myCubeGrid); this.myLogger = new Logger("HarvesterAsteroid", () => myCubeGrid.DisplayName, () => { return(CNS.moveState + ":" + CNS.rotateState); }); HarvestState = Navigator.ReportableState.H_Ready; }
/// <summary> /// Starts harvesting. /// </summary> private void StartHarvest() { LogEntered("StartHarvest()"); HarvestState = Navigator.ReportableState.Harvest; CNS.setDestination(targetVoxel); if (!VoxelsBetweenNavAndPoint((Vector3D)CNS.getWayDest())) { myLogger.debugLog("no voxels between nav drill and destination", "StartHarvest()"); SetNextStage(Ready, false); return; } if (myNav.MM.rotLenSq > rotLenSq_offCourse) { myLogger.debugLog("too far from correct direction", "StartHarvest()"); SetNextStage(StartTunnelThrough, false); return; } if (IsInsideAsteroid()) { myLogger.debugLog("now inside asteroid", "StartHarvest()"); SetNextStage(Harvest, true); } myNav.collisionCheckMoveAndRotate(); }
/// <summary> /// Prepare for harvesting /// </summary> /// <remarks> /// <para>If drills are full, change stage to Finished.</para> /// <para>Get closest asteroid, pick a random point.</para> /// <para>Set CNS settings</para> /// <para>Enables Drills.</para> /// </remarks>> private void Ready() { LogEntered("Ready()"); HarvestState = Navigator.ReportableState.H_Ready; if (DrillFullness(GetDrills()) > FullAmount_Return) { myLogger.debugLog("Drills are full: " + DrillFullness(GetDrills()) + " > " + FullAmount_Return, "Ready()"); SetNextStage(Finished, false); return; } Vector3D?target = GetUsefulTarget(GetClosestAsteroid().WorldVolume); if (!target.HasValue) { myLogger.debugLog("failed to get a useful point inside asteroid", "Ready()"); SetNextStage(Ready, false); return; } targetVoxel = (Vector3)target; CNS_RestorePrevious(); CNS.setDestination(closestVoxel); CNS.ignoreAsteroids = true; ReadyPoint = NavigationDrill.GetPosition(); myLogger.debugLog("Ready", "Ready()"); SetNextStage(ApproachAsteroid, false); }
/// <summary> /// Starts backing out /// </summary> private void StartBackout() { LogEntered("StartBackout()"); HarvestState = Navigator.ReportableState.H_Back; //CNS.atWayDest(); // consider destination reached CNS_SetHarvest(); CNS.setDestination(ReadyPoint); CNS.SpecialFlyingInstructions = NavSettings.SpecialFlying.Line_SidelForward; myNav.fullStop("StartBackout"); SetNextStage(Backout, false); }
private void StartTunnelThrough() { LogEntered("StartTunnelThrough()"); HarvestState = Navigator.ReportableState.H_Tunnel; //CNS.atWayDest(); // consider destination reached Vector3D current = NavigationDrill.GetPosition(); Vector3D forwardVect = NavigationDrill.WorldMatrix.Forward; CNS_SetHarvest(); CNS.setDestination(current + forwardVect * 128); CNS.SpecialFlyingInstructions = NavSettings.SpecialFlying.Line_Any; myNav.fullStop("start tunneling through"); SetNextStage(TunnelThrough, true); }