Beispiel #1
0
        public Grinder(Mover mover, AllNavigationSettings navSet, float maxRange)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, () => m_controlBlock.CubeGrid.DisplayName, () => m_stage.ToString());
            this.m_startPostion = m_controlBlock.CubeBlock.GetPosition();
            this.m_longestDimension = m_controlBlock.CubeGrid.GetLongestDim();

            PseudoBlock navBlock = m_navSet.Settings_Current.NavigationBlock;
            m_navGrind = navBlock.Block is Ingame.IMyShipGrinder
                ? new MultiBlock<MyObjectBuilder_ShipGrinder>(navBlock.Block)
                : new MultiBlock<MyObjectBuilder_ShipGrinder>(() => m_mover.Block.CubeGrid);

            if (m_navGrind.FunctionalBlocks == 0)
            {
                m_logger.debugLog("no working grinders", Logger.severity.INFO);
                return;
            }

            m_grinderOffset = m_navGrind.Block.GetLengthInDirection(m_navGrind.Block.GetFaceDirection()[0]) * 0.5f + 2.5f;
            if (m_navSet.Settings_Current.DestinationRadius > m_longestDimension)
            {
                m_logger.debugLog("Reducing DestinationRadius from " + m_navSet.Settings_Current.DestinationRadius + " to " + m_longestDimension, Logger.severity.DEBUG);
                m_navSet.Settings_Task_NavRot.DestinationRadius = m_longestDimension;
            }

            this.m_finder = new GridFinder(m_navSet, mover.Block, maxRange);
            this.m_finder.GridCondition = GridCondition;

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;
            m_navSet.Settings_Task_NavRot.NavigatorRotator = this;
        }
Beispiel #2
0
    bool CanGrab(GameObject go, Collider2D col)
    {
        if (go.tag == "MultiBlock")
        {
            multiBlock = go.GetComponentInChildren <MultiBlock>();
            grabDir    = col.name;
            multiBlock.Activate(col.name);
            return(true);
        }

        if (go.tag == "Block" || go.tag == "Slippery" && dude.IsAttachedOrGrabbed())
        {
            Block block = go.GetComponent <Block>();
            if (!dude.HasActivated(block))
            {
                dude.ActivateBlock(block);
                block.Activate();
            }
            return(true);
        }

        if (go.tag == "Limb" && go.transform.parent != transform.parent)
        {
            var d = go.GetComponentInParent <Dude>();
            if (d && d.isAlive)
            {
                d.GetGrabbed();
            }

            return(true);
        }

        return(false);
    }
Beispiel #3
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;
        }
Beispiel #4
0
        public Grinder(Pathfinder pathfinder, float maxRange)
            : base(pathfinder)
        {
            this.m_startPostion     = m_controlBlock.CubeBlock.GetPosition();
            this.m_longestDimension = m_controlBlock.CubeGrid.GetLongestDim();

            PseudoBlock navBlock = m_navSet.Settings_Current.NavigationBlock;

            m_navGrind = navBlock.Block is IMyShipGrinder
                                ? new MultiBlock <MyObjectBuilder_ShipGrinder>(navBlock.Block)
                                : new MultiBlock <MyObjectBuilder_ShipGrinder>(() => m_mover.Block.CubeGrid);

            if (m_navGrind.FunctionalBlocks == 0)
            {
                Log.DebugLog("no working grinders", Logger.severity.INFO);
                return;
            }

            m_grinderOffset = m_navGrind.Block.GetLengthInDirection(m_navGrind.Block.FirstFaceDirection()) * 0.5f + 2.5f;
            if (m_navSet.Settings_Current.DestinationRadius > m_longestDimension)
            {
                Log.DebugLog("Reducing DestinationRadius from " + m_navSet.Settings_Current.DestinationRadius + " to " + m_longestDimension, Logger.severity.DEBUG);
                m_navSet.Settings_Task_NavRot.DestinationRadius = m_longestDimension;
            }

            this.m_finder            = new GridFinder(m_navSet, m_controlBlock, maxRange);
            this.m_finder.OrderValue = OrderValue;
            m_navSet.Settings_Task_NavRot.NavigatorMover   = this;
            m_navSet.Settings_Task_NavRot.NavigatorRotator = this;
            m_navSet.Settings_Task_NavRot.IgnoreEntity     = IgnoreEntity;
        }
Beispiel #5
0
        public WeldGrid(Mover mover, AllNavigationSettings navSet, string gridName, bool shopAfter)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, mover.Block.CubeBlock);
            this.m_finder = new GridFinder(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)
                {
                    m_logger.debugLog("failed to get cache", Logger.severity.WARNING);
                    return;
                }
                if (cache.CountByType(typeof(MyObjectBuilder_ShipWelder)) < 1)
                {
                    m_logger.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;
        }
Beispiel #6
0
        public MinerVoxel(Mover mover, AllNavigationSettings navSet, byte[] OreTargets)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock, () => m_state.ToString());
            this.OreTargets = OreTargets;

            // get blocks
            var cache = CubeGridCache.GetFor(m_controlBlock.CubeGrid);

            var allDrills = cache.GetBlocksOfType(typeof(MyObjectBuilder_Drill));
            if (allDrills == null || allDrills.Count == 0)
            {
                m_logger.debugLog("No Drills!", "MinerVoxel()", Logger.severity.INFO);
                return;
            }
            if (MyAPIGateway.Session.CreativeMode)
                foreach (IMyShipDrill drill in allDrills)
                    if (drill.UseConveyorSystem)
                        drill.ApplyAction("UseConveyor");

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

            if (m_navDrill.FunctionalBlocks == 0)
            {
                m_logger.debugLog("no working drills", "MinerVoxel()", Logger.severity.INFO);
                return;
            }

            var detectors = cache.GetBlocksOfType(typeof(MyObjectBuilder_OreDetector));
            if (detectors != null)
            {
                if (!Registrar.TryGetValue(detectors[0].EntityId, out m_oreDetector))
                    m_logger.debugLog("failed to get ore detector from block", "MinerVoxel()", Logger.severity.FATAL);
            }
            else
            {
                m_logger.debugLog("No ore detector, no ore for you", "MinerVoxel()", Logger.severity.INFO);
                return;
            }

            m_longestDimension = m_controlBlock.CubeGrid.GetLongestDim();
            if (m_navSet.Settings_Current.DestinationRadius > m_longestDimension)
            {
                m_logger.debugLog("Reducing DestinationRadius from " + m_navSet.Settings_Current.DestinationRadius + " to " + m_longestDimension, "MinerVoxel()", Logger.severity.DEBUG);
                m_navSet.Settings_Task_NavRot.DestinationRadius = m_longestDimension;
            }

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;
            m_state = State.GetTarget;
        }
Beispiel #7
0
        public MinerVoxel(Mover mover, AllNavigationSettings navSet, byte[] OreTargets)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock, () => m_state.ToString());
            this.OreTargets = OreTargets;

            // get blocks
            var cache = CubeGridCache.GetFor(m_controlBlock.CubeGrid);

            var allDrills = cache.GetBlocksOfType(typeof(MyObjectBuilder_Drill));
            if (allDrills == null || allDrills.Count == 0)
            {
                m_logger.debugLog("No Drills!", Logger.severity.INFO);
                return;
            }

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

            if (m_navDrill.FunctionalBlocks == 0)
            {
                m_logger.debugLog("no working drills", Logger.severity.INFO);
                return;
            }

            m_longestDimension = m_controlBlock.CubeGrid.GetLongestDim();

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;

            // check for currently touching voxel, usually resume from save
            BoundingSphereD nearby = new BoundingSphereD(m_navDrill.WorldPosition, m_longestDimension * 4d);
            List<MyVoxelBase> nearbyVoxels = new List<MyVoxelBase>();
            MyGamePruningStructure.GetAllVoxelMapsInSphere(ref nearby, nearbyVoxels);

            foreach (MyVoxelBase voxel in nearbyVoxels)
                // skip planet physics, ship should be near planet as well
                if (voxel is IMyVoxelMap || voxel is MyPlanet)
                {
                    m_logger.debugLog("near a voxel, escape first", Logger.severity.DEBUG);
                    m_targetVoxel = voxel;
                    m_state = State.Mining_Escape;
                    var setLevel = m_navSet.GetSettingsLevel(AllNavigationSettings.SettingsLevelName.NavMove);
                    setLevel.IgnoreAsteroid = true;
                    setLevel.SpeedTarget = 1f;
                    return;
                }

            m_state = State.GetTarget;
        }
Beispiel #8
0
 public void updateStructure(MultiBlock structure)
 {
     for (int x = 0; x < gridSize.x; x++)
     {
         for (int y = 0; y < gridSize.y; y++)
         {
             PathNode b = pathNodeGrid.GetGridObject(x, y);
             if (b.structure == structure)
             {
                 b.removeStructure();
             }
         }
     }
     addStructureToGrid(structure);
 }
Beispiel #9
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;
        }
Beispiel #10
0
    public bool canPlaceStructure(IStructure structure, Vector2 pos)
    {
        if (structure.getPathNodeList().Count <= 1)
        {
            PathNode pathNode = structure.getPathNodeList()[0];
            if (pathNode.structure != null && pathNode.structure != structure)
            {
                return(false);
            }
            return(true);
        }

        MultiBlock multiBlock = (MultiBlock)structure;

        float width = multiBlock.getDimensions().x, height = multiBlock.getDimensions().y;

        List <PathNode> pathNodes = new List <PathNode>();

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                pathNodes.Add(getPathNode((int)pos.x + x, (int)pos.y + y));
            }
        }


        foreach (var pathNode in pathNodes)
        {
            if (pathNode != null && pathNode.structure != null && pathNode.structure != structure)
            {
                return(false);
            }
        }

        return(true);
    }
Beispiel #11
0
        public MinerVoxel(Mover mover, byte[] OreTargets)
            : base(mover)
        {
            this.m_logger   = new Logger(m_controlBlock.CubeBlock, () => m_state.ToString());
            this.OreTargets = OreTargets;

            // get blocks
            var cache = CubeGridCache.GetFor(m_controlBlock.CubeGrid);

            var allDrills = cache.GetBlocksOfType(typeof(MyObjectBuilder_Drill));

            if (allDrills == null || allDrills.Count == 0)
            {
                m_logger.debugLog("No Drills!", Logger.severity.INFO);
                return;
            }

            // if a drill has been chosen by player, use it
            PseudoBlock navBlock = m_navSet.Settings_Current.NavigationBlock;

            if (navBlock.Block is IMyShipDrill)
            {
                m_navDrill = new MultiBlock <MyObjectBuilder_Drill>(navBlock.Block);
            }
            else
            {
                m_navDrill = new MultiBlock <MyObjectBuilder_Drill>(() => m_mover.Block.CubeGrid);
            }

            if (m_navDrill.FunctionalBlocks == 0)
            {
                m_logger.debugLog("no working drills", Logger.severity.INFO);
                return;
            }

            m_longestDimension = m_controlBlock.CubeGrid.GetLongestDim();

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;

            // check for currently touching voxel, usually resume from save
            BoundingSphereD    nearby       = new BoundingSphereD(m_navDrill.WorldPosition, m_longestDimension * 4d);
            List <MyVoxelBase> nearbyVoxels = new List <MyVoxelBase>();

            MyGamePruningStructure.GetAllVoxelMapsInSphere(ref nearby, nearbyVoxels);

            foreach (MyVoxelBase voxel in nearbyVoxels)
            {
                // skip planet physics, ship should be near planet as well
                if (voxel is IMyVoxelMap || voxel is MyPlanet)
                {
                    m_logger.debugLog("near a voxel, escape first", Logger.severity.DEBUG);
                    m_targetVoxel = voxel;
                    m_state       = State.Mining_Escape;
                    var setLevel = m_navSet.GetSettingsLevel(AllNavigationSettings.SettingsLevelName.NavMove);
                    setLevel.IgnoreAsteroid = true;
                    setLevel.SpeedTarget    = 1f;
                    return;
                }
            }

            m_state = State.GetTarget;
        }
Beispiel #12
0
 public void setStructure(MultiBlock structure)
 {
     this.structure = structure;
 }
Beispiel #13
0
 public static void addTemporaryPlacement(MultiBlock structure)
 {
     temporaryPlacements.Add(structure);
 }