Exemple #1
0
 private void MoveToTarget()
 {
     if (m_navSet.DistanceLessThan(1f))
     {
         Log.DebugLog("Reached position: " + m_target, Logger.severity.WARNING);
         if (m_stage == Stage.Backout)
         {
             m_target.SetWorld(m_target.WorldPosition() + m_navBlock.WorldMatrix.Backward * 100d);
         }
         else
         {
             Vector3D    targetWorld = m_target.WorldPosition();
             MyVoxelBase voxel       = TargetVoxel;
             m_target.SetWorld(targetWorld + Vector3D.Normalize(targetWorld - voxel.GetCentre()) * voxel.PositionComp.LocalVolume.Radius);
         }
     }
     else if (IsStuck)
     {
         if (m_stage == Stage.Backout)
         {
             Log.DebugLog("Stuck", Logger.severity.DEBUG);
             m_stage = Stage.FromCentre;
         }
         else
         {
             Log.DebugLog("Stuck", Logger.severity.DEBUG);
             m_navSet.OnTaskComplete_NavWay();
         }
     }
     else if (!IsNearVoxel(2d))
     {
         Log.DebugLog("Outside of voxel", Logger.severity.INFO);
         m_mover.MoveAndRotateStop();
         m_navSet.OnTaskComplete_NavMove();
     }
     else
     {
         m_pathfinder.MoveTo(destinations: m_target);
     }
 }
Exemple #2
0
        public VoxelLander(Pathfinder pathfinder, bool planet, PseudoBlock landBlock = null)
            : base(pathfinder)
        {
            this.m_landBlock  = landBlock ?? m_navSet.Settings_Current.LandingBlock;
            this.m_targetType = planet ? "Planet" : "Asteroid";

            if (this.m_landBlock == null)
            {
                Log.DebugLog("No landing block", Logger.severity.INFO);
                return;
            }

            IMyLandingGear asGear = m_landBlock.Block as IMyLandingGear;

            if (asGear != null)
            {
                ITerminalProperty <bool> autolock = asGear.GetProperty("Autolock") as ITerminalProperty <bool>;
                Log.DebugLog("autolock == null", Logger.severity.FATAL, condition: autolock == null);
                if (!autolock.GetValue(asGear))
                {
                    autolock.SetValue(asGear, true);
                }
            }

            Vector3D    currentPostion = m_landBlock.WorldPosition;
            MyVoxelBase closest        = null;

            if (planet)
            {
                closest = MyPlanetExtensions.GetClosestPlanet(m_landBlock.WorldPosition);

                if (closest == null)
                {
                    Log.DebugLog("No planets in the world", Logger.severity.WARNING);
                    return;
                }
            }
            else
            {
                BoundingSphereD    search = new BoundingSphereD(currentPostion, 10000d);
                List <MyVoxelBase> nearby = new List <MyVoxelBase>();
                MyGamePruningStructure.GetAllVoxelMapsInSphere(ref search, nearby);

                double closestDistSquared = double.MaxValue;

                foreach (MyVoxelBase voxel in nearby)
                {
                    if (!(voxel is MyVoxelMap))
                    {
                        continue;
                    }

                    double distSquared = Vector3D.DistanceSquared(currentPostion, voxel.GetCentre());
                    if (distSquared < closestDistSquared)
                    {
                        closestDistSquared = distSquared;
                        closest            = voxel;
                    }
                }

                if (closest == null)
                {
                    Log.DebugLog("No asteroids nearby", Logger.severity.WARNING);
                    return;
                }
            }

            Vector3D    end = closest.GetCentre();
            MyVoxelBase hitVoxel;
            Vector3D    hitPosition;

            if (!RayCast.RayCastVoxels(ref currentPostion, ref end, out hitVoxel, out hitPosition))
            {
                throw new Exception("Failed to intersect voxel");
            }

            m_targetPostion = Destination.FromWorld(hitVoxel, hitPosition);

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;
            m_navSet.Settings_Task_NavRot.IgnoreAsteroid = true;

            Log.DebugLog("Landing on " + m_targetType + " at " + m_targetPostion, Logger.severity.DEBUG);
        }