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);
        }
Esempio n. 2
0
        public void Update10()
        {
            if (Globals.ElapsedTime < m_nextHack)
            {
                return;
            }
            if (!m_hackBlock.IsWorking)
            {
                m_strengthLeft = 0f;
                return;
            }
            IMyCubeGrid attached = m_hackBlock.GetAttachedEntity() as IMyCubeGrid;

            if (attached == null)
            {
                m_strengthLeft = 0f;
                return;
            }

            // break force might be removed from game entirely
            //if (m_hackBlock.BreakForce > allowedBreakForce)
            //{
            //	Log.DebugLog("break force too high: " + m_hackBlock.BreakForce);
            //	ITerminalProperty<float> prop = m_hackBlock.GetProperty("BreakForce") as ITerminalProperty<float>;
            //	if (prop == null)
            //	{
            //		Log.DebugLog("break force is disabled in SE", Logger.severity.INFO);
            //		allowedBreakForce = float.PositiveInfinity;
            //	}
            //	else
            //		prop.SetValue(m_hackBlock, allowedBreakForce);
            //}
            //if (allowedBreakForce == float.PositiveInfinity)

            // landing gear is unbreakable, disconnect / fail if not otherwise attached
            if (!AttachedGrid.IsGridAttached(m_hackBlock.CubeGrid as IMyCubeGrid, attached, AttachedGrid.AttachmentKind.Physics))
            {
                Log.DebugLog("no other connection to attached, hacker must disconnect", Logger.severity.DEBUG);
                ITerminalProperty <bool> autolock = m_hackBlock.GetProperty("Autolock") as ITerminalProperty <bool>;
                if (autolock.GetValue(m_hackBlock))
                {
                    autolock.SetValue(m_hackBlock, false);
                }
                m_hackBlock.GetActionWithName("Unlock").Apply(m_hackBlock);
                return;
            }

            m_nextHack = Globals.ElapsedTime + s_hackFrequency;

            m_strengthLeft += s_hackStrength;

            foreach (int i in Enumerable.Range(0, 8).OrderBy(x => Globals.Random.Next()))
            {
                Disruption disrupt;
                switch (i)
                {
                case 0:
                    disrupt = new AirVentDepressurize();
                    break;

                case 1:
                    disrupt = new DoorLock();
                    break;

                case 2:
                    disrupt = new GravityReverse();
                    break;

                case 3:
                    disrupt = new DisableTurret();
                    break;

                case 4:
                    disrupt = new TraitorTurret();
                    break;

                case 5:
                    disrupt = new CryoChamberMurder();
                    break;

                case 6:
                    disrupt = new JumpDriveDrain();
                    break;

                case 7:
                    disrupt = new MedicalRoom();
                    break;

                default:
                    Log.AlwaysLog("Case not implemented: " + i, Logger.severity.FATAL);
                    continue;
                }
                foreach (IMyCubeGrid grid in AttachedGrid.AttachedGrids(attached, AttachedGrid.AttachmentKind.Terminal, true))
                {
                    disrupt.Start(grid, s_hackLength, ref m_strengthLeft, m_hackBlock.OwnerId);
                }
            }
        }