Esempio n. 1
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);
        }