Пример #1
0
        public WeldGrid(Pathfinder pathfinder, string gridName, bool shopAfter)
            : base(pathfinder)
        {
            this.m_finder    = new GridFinder(pathfinder.NavSet, m_controlBlock, gridName);
            this.m_shopAfter = shopAfter;

            PseudoBlock navBlock = m_navSet.Settings_Current.NavigationBlock;

            if (navBlock.Block is IMyShipWelder)
            {
                m_navWeld = new MultiBlock <MyObjectBuilder_ShipWelder>(navBlock.Block);
            }
            else
            {
                CubeGridCache cache = CubeGridCache.GetFor(m_controlBlock.CubeGrid);
                if (cache == null)
                {
                    Log.DebugLog("failed to get cache", Logger.severity.WARNING);
                    return;
                }
                if (cache.CountByType(typeof(MyObjectBuilder_ShipWelder)) < 1)
                {
                    Log.DebugLog("no welders on ship", Logger.severity.WARNING);
                    return;
                }
                m_navWeld = new MultiBlock <MyObjectBuilder_ShipWelder>(() => m_mover.Block.CubeGrid);
            }

            UpdateTimeout();

            m_navSet.Settings_Task_NavMove.NavigatorMover = this;
        }
Пример #2
0
        public Miner(Pathfinder pathfinder, byte[] oreTargets) : base(pathfinder)
        {
            m_oreTargets = oreTargets;

            CubeGridCache cache = CubeGridCache.GetFor(m_controlBlock.CubeGrid);

            if (cache == null)
            {
                return;
            }

            if (cache.CountByType(typeof(MyObjectBuilder_Drill)) == 0)
            {
                Logger.DebugLog("No drills", Logger.severity.WARNING);
                return;
            }

            // if a drill has been chosen by player, use it
            PseudoBlock navBlock = m_navSet.Settings_Current.NavigationBlock;
            MultiBlock <MyObjectBuilder_Drill> navDrill = navBlock.Block is IMyShipDrill ? new MultiBlock <MyObjectBuilder_Drill>(navBlock.Block) : navDrill = new MultiBlock <MyObjectBuilder_Drill>(() => m_mover.Block.CubeGrid);

            if (navDrill.FunctionalBlocks == 0)
            {
                Logger.DebugLog("no working drills", Logger.severity.WARNING);
                return;
            }

            m_navSet.Settings_Task_NavRot.NavigatorMover  = this;
            m_navSet.Settings_Task_NavRot.NavigationBlock = navDrill;

            BoundingSphereD    nearby       = new BoundingSphereD(navDrill.WorldPosition, m_controlBlock.CubeGrid.LocalVolume.Radius * 2d);
            List <MyVoxelBase> nearbyVoxels = new List <MyVoxelBase>();

            MyGamePruningStructure.GetAllVoxelMapsInSphere(ref nearby, nearbyVoxels);

            foreach (MyVoxelBase voxel in nearbyVoxels)
            {
                if ((voxel is IMyVoxelMap || voxel is MyPlanet) && voxel.ContainsOrIntersects(ref nearby))
                {
                    Log.DebugLog("near a voxel, escape first", Logger.severity.DEBUG);
                    m_stage = Stage.Mining;
                    new EscapeMiner(m_pathfinder, voxel);
                    return;
                }
            }

            m_stage = Stage.GetDeposit;
        }
Пример #3
0
        /// <summary>
        /// Determines if the ship is capable of digging a tunnel.
        /// </summary>
        private bool CanTunnel()
        {
            CubeGridCache cache = CubeGridCache.GetFor(m_grid);

            if (cache == null)
            {
                return(false);
            }

            BoundingSphere[] sensors = new BoundingSphere[cache.CountByType(typeof(MyObjectBuilder_Drill))];
            int drillIndex           = 0;

            foreach (MyShipDrill drill in cache.BlocksOfType(typeof(MyObjectBuilder_Drill)))
            {
                float offset = (float)MyShipDrillDefinition__SensorOffset.GetValue(drill.BlockDefinition);
                float radius = (float)MyShipDrillDefinition__SensorRadius.GetValue(drill.BlockDefinition);
                sensors[drillIndex++] = new BoundingSphere(drill.LocalPosition() + drill.PositionComp.LocalMatrix.Forward * offset, radius + MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF);
            }

            Vector3 forward = m_navBlock.LocalMatrix.Forward;

            foreach (Vector3I cell in m_grid.FirstBlocks(m_navBlock.LocalMatrix.Backward))
            {
                IMySlimBlock block = m_grid.GetCubeBlock(cell);
                if (!(block.FatBlock is IMyShipDrill))
                {
                    Ray ray = new Ray(cell * m_grid.GridSize, forward);

                    foreach (BoundingSphere sensor in sensors)
                    {
                        if (ray.Intersects(sensor).HasValue)
                        {
                            //Log.DebugLog(block.getBestName() + " is behind a drill");
                            goto NextBlock;
                        }
                    }

                    //Log.DebugLog(block.getBestName() + " is not behind any drill");
                    return(false);
                }

                NextBlock :;
            }

            return(true);
        }
Пример #4
0
        private int WorkingDecoys(IMyEntity target)
        {
            IMyCubeGrid grid = target as IMyCubeGrid;

            if (grid == null || RelationsBlock.canConsiderFriendly(grid))
            {
                return(0);
            }

            CubeGridCache cache = CubeGridCache.GetFor(grid);

            if (cache == null)
            {
                return(0);
            }
            return(cache.CountByType(typeof(MyObjectBuilder_Decoy), block => block.IsWorking));
        }