예제 #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;
        }
예제 #2
0
파일: Mover.cs 프로젝트: his1220/Autopilot
 /// <summary>
 /// Creates a Mover for a given ShipControllerBlock and AllNavigationSettings
 /// </summary>
 /// <param name="block">Controlling block for the grid</param>
 /// <param name="NavSet">Navigation settings to use.</param>
 public Mover(ShipControllerBlock block, AllNavigationSettings NavSet)
 {
     this.myLogger = new Logger("Mover", block.Controller);
     //this.myLogger.MinimumLevel = Logger.severity.DEBUG;
     this.Block = block;
     this.NavSet = NavSet;
 }
예제 #3
0
        public Waypoint(Mover mover, AllNavigationSettings navSet, AllNavigationSettings.SettingsLevelName level, IMyEntity targetEntity, Vector3D worldOffset)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock);
            this.m_level = level;
            this.m_targetEntity = targetEntity;
            this.m_targetOffset = worldOffset;

            m_logger.debugLog(targetEntity != targetEntity.GetTopMostParent(), "targetEntity is not top-most", Logger.severity.FATAL);

            IMyCubeGrid asGrid = targetEntity as IMyCubeGrid;
            if (asGrid != null && Attached.AttachedGrid.IsGridAttached(asGrid, m_controlBlock.CubeGrid, Attached.AttachedGrid.AttachmentKind.Physics))
            {
                m_logger.debugLog("Cannot fly to entity, attached: " + targetEntity.getBestName() + ", creating GOLIS", Logger.severity.WARNING);
                new GOLIS(mover, navSet, TargetPosition, level);
                return;
            }
            if (targetEntity.Physics == null)
            {
                m_logger.debugLog("Target has no physics: " + targetEntity.getBestName() + ", creating GOLIS", Logger.severity.WARNING);
                new GOLIS(mover, navSet, TargetPosition, level);
                return;
            }

            var setLevel = navSet.GetSettingsLevel(level);
            setLevel.NavigatorMover = this;
            //setLevel.DestinationEntity = mover.Block.CubeBlock; // to force avoidance

            m_logger.debugLog("created, level: " + level + ", target: " + targetEntity.getBestName() + ", target position: " + targetEntity.GetPosition() + ", offset: " + worldOffset + ", position: " + TargetPosition, Logger.severity.DEBUG);
        }
예제 #4
0
        public Coward(Mover mover, AllNavigationSettings navSet)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, () => m_controlBlock.CubeGrid.DisplayName);

            m_logger.debugLog("Initialized");
        }
예제 #5
0
 public Interpreter(ShipControllerBlock block)
 {
     this.m_logger = new Logger("Interpreter", block.Controller);
     this.Controller = block;
     this.NavSet = new AllNavigationSettings(block.Controller);
     this.Mover = new Mover(block, NavSet);
 }
예제 #6
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;
        }
예제 #7
0
        public Orbiter(Mover mover, AllNavigationSettings navSet, string entity)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock);
            this.m_navBlock = m_navSet.Settings_Current.NavigationBlock;

            switch (entity.LowerRemoveWhitespace())
            {
                case "asteroid":
                    SetOrbitClosestVoxel(true);
                    CalcFakeOrbitSpeedForce();
                    m_logger.debugLog("Orbiting asteroid: " + OrbitEntity.getBestName(), Logger.severity.INFO);
                    break;
                case "planet":
                    SetOrbitClosestVoxel(false);
                    OrbitSpeed = (float)Math.Sqrt((OrbitEntity as MyPlanet).GetGravityMultiplier(m_navBlock.WorldPosition) * 9.81f * Altitude);
                    if (OrbitSpeed < 1f)
                        CalcFakeOrbitSpeedForce();
                    m_logger.debugLog("Orbiting planet: " + OrbitEntity.getBestName(), Logger.severity.INFO);
                    break;
                default:
                    m_gridFinder = new GridFinder(navSet, mover.Block, entity, mustBeRecent: true);
                    m_logger.debugLog("Searching for a grid: " + entity, Logger.severity.INFO);
                    break;
            }

            m_navSet.Settings_Task_NavMove.NavigatorMover = this;
        }
예제 #8
0
파일: Mover.cs 프로젝트: Souper07/Autopilot
        /// <summary>
        /// Creates a Mover for a given ShipControllerBlock and AllNavigationSettings
        /// </summary>
        /// <param name="block">Controlling block for the grid</param>
        /// <param name="NavSet">Navigation settings to use.</param>
        public Mover(ShipControllerBlock block, AllNavigationSettings NavSet)
        {
            this.m_logger = new Logger("Mover", block.Controller);
            this.Block = block;
            this.m_navSet = NavSet;

            CheckGrid();
        }
예제 #9
0
        public FlyToCharacter(Mover mover, AllNavigationSettings navSet, string charName)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock, () => charName);
            this.m_charName = charName.LowerRemoveWhitespace();
            this.m_timeoutAt = Globals.ElapsedTime + timeout;

            m_navSet.Settings_Task_NavMove.NavigatorMover = this;
        }
예제 #10
0
        /// <summary>
        /// Creates a new Stopper
        /// </summary>
        /// <param name="mover">The Mover to use</param>
        /// <param name="navSet">The settings to use</param>
        public Stopper(Mover mover, AllNavigationSettings navSet, bool exitAfter = false)
            : base(mover, navSet)
        {
            _logger = new Logger("Stopper", m_controlBlock.Controller);
            m_exitAfter = exitAfter;

            m_mover.MoveAndRotateStop();

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;
        }
예제 #11
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;
        }
예제 #12
0
        public EnemyFinder(Mover mover, AllNavigationSettings navSet, long entityId)
            : base(navSet, mover.Block)
        {
            this.m_logger = new Logger(GetType().Name, mover.Block.CubeBlock, () => CurrentResponse.Response.ToString());
            this.m_mover = mover;
            this.m_navSet = navSet;
            this.m_targetEntityId = entityId;
            this.m_landingGear = m_navSet.Settings_Current.LandingBlock;

            m_logger.debugLog("Initialized");
        }
예제 #13
0
파일: GOLIS.cs 프로젝트: Souper07/Autopilot
        /// <summary>
        /// Creates a GOLIS
        /// </summary>
        /// <param name="mover">The mover to use</param>
        /// <param name="navSet">The settings to use</param>
        /// <param name="location">The location to fly to</param>
        public GOLIS(Mover mover, AllNavigationSettings navSet, Vector3D location, AllNavigationSettings.SettingsLevelName level = AllNavigationSettings.SettingsLevelName.NavMove)
            : base(mover, navSet)
        {
            this.myLogger = new Logger("GOLIS", m_controlBlock.CubeBlock);
            this.NavigationBlock = m_navSet.Settings_Current.NavigationBlock;
            this.location = location;
            this.m_level = level;

            var atLevel = m_navSet.GetSettingsLevel(level);
            atLevel.NavigatorMover = this;
            //atLevel.DestinationEntity = mover.Block.CubeBlock; // in case waypoint is blocked by moving target
        }
예제 #14
0
        public Shopper(AllNavigationSettings navSet, IMyCubeGrid grid, Dictionary<string, int> shopList)
        {
            this.m_logger = new Logger(GetType().Name, grid);
            this.m_navSet = navSet;
            this.m_shoppingList = shopList;
            this.m_grid = grid;

            this.m_currentTask = Return;

            foreach (var pair in m_shoppingList)
                m_logger.debugLog("Item: " + pair.Key + ", amount: " + pair.Value);
        }
예제 #15
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;
        }
예제 #16
0
파일: GOLIS.cs 프로젝트: helppass/Autopilot
		/// <summary>
		/// Creates a GOLIS
		/// </summary>
		/// <param name="mover">The mover to use</param>
		/// <param name="navSet">The settings to use</param>
		/// <param name="location">The location to fly to</param>
		public GOLIS(Mover mover, AllNavigationSettings navSet, Vector3 location, bool waypoint = false)
			: base(mover, navSet)
		{
			this.myLogger = new Logger("GOLIS", m_controlBlock.CubeBlock);
			this.NavigationBlock = m_navSet.Settings_Current.NavigationBlock;
			this.location = location;
			this.Waypoint = waypoint;

			var atLevel = waypoint ? m_navSet.Settings_Task_NavWay : m_navSet.Settings_Task_NavMove;
			atLevel.NavigatorMover = this;
			atLevel.DestinationEntity = mover.Block.CubeGrid; // in case waypoint is blocked by moving target
		}
예제 #17
0
        /// <summary>
        /// Creates an Orbiter for a specific entity, fake orbit only.
        /// Does not add itself to navSet.
        /// </summary>
        /// <param name="faceBlock">The block that will be faced towards the orbited entity</param>
        /// <param name="entity">The entity to be orbited</param>
        /// <param name="distance">The distance between the orbiter and the orbited entity</param>
        /// <param name="name">What to call the orbited entity</param>
        public Orbiter(Mover mover, AllNavigationSettings navSet, PseudoBlock faceBlock, IMyEntity entity, float distance, string name)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock);
            this.m_navBlock = faceBlock;
            this.m_orbitEntity_name = name;

            Altitude = distance;
            OrbitEntity = entity;

            CalcFakeOrbitSpeedForce();
            m_logger.debugLog("Orbiting: " + OrbitEntity.getBestName(), Logger.severity.INFO);
        }
예제 #18
0
        /// <summary>
        /// Creates a GridFinder to find an enemy grid based on distance.
        /// </summary>
        public GridFinder(AllNavigationSettings navSet, ShipControllerBlock controller, float maxRange = 0f)
        {
            this.m_logger = new Logger(GetType().Name, controller.CubeBlock);

            m_logger.debugLog(navSet == null, "navSet == null", Logger.severity.FATAL);
            m_logger.debugLog(controller == null, "controller == null", Logger.severity.FATAL);
            m_logger.debugLog(controller.CubeBlock == null, "controller.CubeBlock == null", Logger.severity.FATAL);

            this.m_controlBlock = controller;
            //this.m_enemies = new List<LastSeen>();

            this.MaximumRange = maxRange;
            this.m_navSet = navSet;
            this.m_mustBeRecent = true;
        }
예제 #19
0
        public EnemyLander(Mover mover, AllNavigationSettings navSet, PseudoBlock landingGear)
        {
            this.m_logger = new Logger(GetType().Name);
            this.m_navSet = navSet;

            if (landingGear == null)
            {
                m_logger.debugLog("landingGear param is null, not going to land");
                return;
            }
            this.m_hasLandingGear = landingGear.Block is IMyLandingGear;
            if (!this.m_hasLandingGear)
            {
                m_logger.debugLog("landingGear param is not landing geat: " + landingGear.Block.getBestName() + ", not going to land");
                return;
            }
            this.m_flyToGrid = new FlyToGrid(mover, navSet, finder: m_navSet.Settings_Current.EnemyFinder, landingBlock: landingGear);
        }
예제 #20
0
파일: Facer.cs 프로젝트: helppass/Autopilot
		/// <param name="mover">The mover to use</param>
		/// <param name="navSet">The settings to use</param>
		/// <param name="rotBlock">The block to rotate</param>
		public Facer(Mover mover, AllNavigationSettings navSet, PseudoBlock rotBlock)
			: base(mover, navSet)
		{
			this.m_logger = new Logger("Facer", m_controlBlock.CubeBlock);

			this.m_pseudoBlock = rotBlock;
			this.m_laser = rotBlock.Block as IMyLaserAntenna;
			if (this.m_laser == null)
			{
				if (!(rotBlock.Block is Ingame.IMySolarPanel) && !(rotBlock.Block is Ingame.IMyOxygenFarm))
				{
					m_logger.alwaysLog("Block is of wrong type: " + rotBlock.Block.DisplayNameText, "Facer()", Logger.severity.FATAL);
					throw new Exception("Block is of wrong type: " + rotBlock.Block.DisplayNameText);
				}
			}

			m_navSet.Settings_Task_NavRot.NavigatorRotator = this;
		}
예제 #21
0
		/// <summary>
		/// Creates a GridFinder to find an enemy grid based on distance.
		/// </summary>
		public GridFinder(AllNavigationSettings navSet, ShipControllerBlock controller, float maxRange = 0f)
		{
			this.m_logger = new Logger(GetType().Name + " enemy", controller.CubeBlock);

			m_logger.debugLog(navSet == null, "navSet == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(controller == null, "controller == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(controller.CubeBlock == null, "controller.CubeBlock == null", "GridFinder()", Logger.severity.FATAL);

			this.m_controlBlock = controller;
			this.m_enemies = new List<LastSeen>();

			if (!Registrar.TryGetValue(controller.CubeBlock.EntityId, out this.m_controller))
				throw new NullReferenceException("ShipControllerBlock is not a ShipController");

			this.MaximumRange = maxRange;
			this.m_navSet = navSet;
			this.m_mustBeRecent = true;
		}
예제 #22
0
        /// <summary>
        /// Creates a GridFinder to find a friendly grid based on its name.
        /// </summary>
        public GridFinder(AllNavigationSettings navSet, ShipControllerBlock controller, string targetGrid, string targetBlock = null,
			AttachedGrid.AttachmentKind allowedAttachment = AttachedGrid.AttachmentKind.Permanent, bool mustBeRecent = false)
        {
            this.m_logger = new Logger(GetType().Name, controller.CubeBlock);

            m_logger.debugLog(navSet == null, "navSet == null", Logger.severity.FATAL);
            m_logger.debugLog(controller == null, "controller == null", Logger.severity.FATAL);
            m_logger.debugLog(controller.CubeBlock == null, "controller.CubeBlock == null", Logger.severity.FATAL);
            m_logger.debugLog(targetGrid == null, "targetGrid == null", Logger.severity.FATAL);

            this.m_targetGridName = targetGrid.LowerRemoveWhitespace();
            if (targetBlock != null)
                this.m_targetBlockName = targetBlock.LowerRemoveWhitespace();
            this.m_controlBlock = controller;
            this.m_allowedAttachment = allowedAttachment;
            this.MaximumRange = float.MaxValue;
            this.m_navSet = navSet;
            this.m_mustBeRecent = mustBeRecent;
        }
예제 #23
0
		/// <summary>
		/// Creates a GridFinder to find a friendly grid based on its name.
		/// </summary>
		public GridFinder(AllNavigationSettings navSet, ShipControllerBlock controller, string targetGrid, string targetBlock = null,
			AttachedGrid.AttachmentKind allowedAttachment = AttachedGrid.AttachmentKind.Permanent)
		{
			this.m_logger = new Logger(GetType().Name + " friendly", controller.CubeBlock);

			m_logger.debugLog(navSet == null, "navSet == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(controller == null, "controller == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(controller.CubeBlock == null, "controller.CubeBlock == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(targetGrid == null, "targetGrid == null", "GridFinder()", Logger.severity.FATAL);

			if (!Registrar.TryGetValue(controller.CubeBlock.EntityId, out this.m_controller))
				throw new NullReferenceException("ShipControllerBlock is not a ShipController");
			this.m_targetGridName = targetGrid.LowerRemoveWhitespace();
			if (targetBlock != null)
				this.m_targetBlockName = targetBlock.LowerRemoveWhitespace();
			this.m_controlBlock = controller;
			this.m_allowedAttachment = allowedAttachment;
			this.MaximumRange = float.MaxValue;
			this.m_navSet = navSet;
		}
예제 #24
0
        public WeldBlock(Mover mover, AllNavigationSettings navSet, PseudoBlock welder, IMySlimBlock block)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, () => mover.Block.CubeGrid.DisplayName, () => block.getBestName(), () => m_stage.ToString());
            this.m_offset = welder.Block.LocalAABB.GetLongestDim() * 0.5f; // this works for default welders, may not work if mod has an exotic design
            this.m_welder = welder;
            this.m_targetSlim = block;
            this.m_timeout_start = Globals.UpdateCount + TimeoutStart;

            IMyCubeBlock Projector = ((MyCubeGrid)block.CubeGrid).Projector;
            if (Projector != null)
            {
                this.m_weldProjection = true;
                this.m_otherGrid = Projector.CubeGrid;
                this.m_slimTarget_initDmg = 1f;
                this.m_targetCell = Projector.CubeGrid.WorldToGridInteger(block.CubeGrid.GridIntegerToWorld(block.Position));
            }
            else
            {
                this.m_weldProjection = false;
                this.m_slimTarget_initDmg = block.Damage();
                this.m_targetCell = block.Position;
            }

            m_navSet.Settings_Task_NavEngage.NavigatorMover = this;
            m_navSet.Settings_Task_NavEngage.NavigatorRotator = this;
            m_navSet.Settings_Task_NavEngage.DestinationEntity = m_realGrid;

            IEnumerator<Vector3I> neighbours = this.m_targetSlim.ForEachNeighbourCell();
            while (neighbours.MoveNext())
            {
                Vector3I cell = m_weldProjection ? Projector.CubeGrid.WorldToGridInteger(block.CubeGrid.GridIntegerToWorld(neighbours.Current)) : neighbours.Current;
                m_neighbours.Add(cell);
                if (this.m_realGrid.GetCubeBlock(cell) == null)
                    m_emptyNeighbours.Add(cell);
            }

            m_targetSlim.ComputeWorldCenter(out m_targetWorld);
            m_lineUp.To = m_targetWorld;
        }
예제 #25
0
        public UnLander(Mover mover, AllNavigationSettings navSet, PseudoBlock unlandBlock = null)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock);
            this.m_unlandBlock = unlandBlock ?? m_navSet.Settings_Current.LandingBlock ?? m_navSet.LastLandingBlock;

            if (this.m_unlandBlock == null)
            {
                m_logger.debugLog("No unland block", "UnLander()", Logger.severity.INFO);
                return;
            }
            m_logger.debugLog(this.m_unlandBlock.Block == null, "Unland block is missing Block property", "UnLander()", Logger.severity.FATAL);

            IMyLandingGear asGear = m_unlandBlock.Block as IMyLandingGear;
            if (asGear != null)
            {
                m_attachedEntity = asGear.GetAttachedEntity();
                m_logger.debugLog("m_attachedEntity: " + m_attachedEntity, "UnLander()");
                if (m_attachedEntity == null)
                {
                    m_logger.debugLog("Not attached: " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.INFO);
                    return;
                }
                m_logger.debugLog("Got attached entity from Landing Gear : " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.DEBUG);
            }
            else
            {
                Ingame.IMyShipConnector asConn = m_unlandBlock.Block as Ingame.IMyShipConnector;
                if (asConn != null)
                {
                    m_logger.debugLog("connector", "UnLander()");
                    Ingame.IMyShipConnector other = asConn.OtherConnector;
                    if (other == null)
                    {
                        m_logger.debugLog("Not connected: " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.INFO);
                        return;
                    }
                    m_logger.debugLog("Got attached connector from Connector : " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.DEBUG);
                    m_attachedEntity = other.CubeGrid;
                }
                else
                {
                    m_logger.debugLog("Cannot unland block: " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.INFO);
                    return;
                }
            }

            IMyCubeBlock block = this.m_unlandBlock.Block;
            if (block is IMyLandingGear)
                MyAPIGateway.Utilities.TryInvokeOnGameThread(() => {
                    (block as IMyFunctionalBlock).RequestEnable(true);
                    if ((block.GetObjectBuilderCubeBlock() as MyObjectBuilder_LandingGear).AutoLock)
                        asGear.ApplyAction("Autolock");
                }, m_logger);

            Vector3D attachOffset = m_unlandBlock.Block.GetPosition() - m_attachedEntity.GetPosition();
            Vector3 leaveDirection = m_unlandBlock.WorldMatrix.Backward;
            m_detatchedOffset = attachOffset + leaveDirection * 20f;
            m_logger.debugLog("m_detatchedOffset: " + m_detatchedOffset, "UnLander()", Logger.severity.DEBUG);

            m_navSet.Settings_Task_NavMove.NavigatorMover = this;
            m_navSet.Settings_Task_NavMove.NavigatorRotator = this;
        }
예제 #26
0
		public Pathfinder(IMyCubeGrid grid, AllNavigationSettings navSet, Mover mover)
		{
			grid.throwIfNull_argument("grid");
			m_grid = grid;
			m_logger = new Logger("Pathfinder", () => grid.DisplayName, () => m_pathState.ToString(), () => m_rotateState.ToString());
			m_pathChecker = new PathChecker(grid);
			m_rotateChecker = new RotateChecker(grid);
			m_navSet = navSet;
			m_mover = mover;
			m_logger.debugLog("Initialized, grid: " + grid.DisplayName, "Pathfinder()");
		}
예제 #27
0
 public Fighter(Mover mover, AllNavigationSettings navSet)
     : base(mover, navSet)
 {
     this.m_logger = new Logger(GetType().Name, () => m_controlBlock.CubeGrid.DisplayName);
     Arm();
 }
예제 #28
0
		public FlyToGrid(Mover mover, AllNavigationSettings navSet, string targetGrid,
			AttachedGrid.AttachmentKind allowedAttachment = AttachedGrid.AttachmentKind.Permanent)
			: base(mover, navSet)
		{
			this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock, () => m_landingState.ToString());
			this.m_targetBlock = m_navSet.Settings_Current.DestinationBlock;
			string blockName = m_targetBlock == null ? null : m_targetBlock.BlockName;
			this.m_gridFinder = new GridFinder(m_navSet, m_mover.Block, targetGrid, blockName, allowedAttachment);
			this.m_contBlock = m_navSet.Settings_Commands.NavigationBlock;

			PseudoBlock landingBlock = m_navSet.Settings_Current.LandingBlock;
			m_navBlock = landingBlock ?? m_navSet.Settings_Current.NavigationBlock;

			if (landingBlock != null)
			{
				if (landingBlock.Block is IMyFunctionalBlock)
					m_landingState = LandingState.Approach;
				else
				{
					m_logger.debugLog("landingBlock is not functional, player error? : " + landingBlock.Block.DisplayNameText, "FlyToGrid()", Logger.severity.INFO);
					m_landingState = LandingState.None;
				}

				if (m_targetBlock == null)
				{
					if (!(landingBlock.Block is IMyLandingGear))
					{
						m_logger.debugLog("cannot land block without a target", "FlyToGrid()", Logger.severity.INFO);
						m_landingState = LandingState.None;
					}
					else
					{
						m_logger.debugLog("golden retriever mode enabled", "FlyToGrid()", Logger.severity.INFO);
						m_landGearWithoutTargetBlock = true;
					}
				}
				else if (landingBlock.Block is Ingame.IMyShipConnector)
				{
					m_gridFinder.BlockCondition = block => {
						Ingame.IMyShipConnector connector = block as Ingame.IMyShipConnector;
						return connector != null && (!connector.IsConnected || connector.OtherConnector == m_navBlock.Block);
					};
					m_landingDirection = m_targetBlock.Forward ?? Base6Directions.GetFlippedDirection(landingBlock.Block.GetFaceDirection()[0]);
				}
				else if (landingBlock.Block is IMyShipMergeBlock)
				{
					m_gridFinder.BlockCondition = block => block is IMyShipMergeBlock;
					m_landingDirection = m_targetBlock.Forward ?? Base6Directions.GetFlippedDirection(landingBlock.Block.GetFaceDirection()[0]);
					(landingBlock.Block as IMyShipMergeBlock).BeforeMerge += MergeBlock_BeforeMerge;
				}
				else if (m_targetBlock.Forward.HasValue)
					m_landingDirection = m_targetBlock.Forward.Value;
				else
				{
					m_logger.debugLog("Player failed to specify landing direction and it could not be determined.", "FlyToGrid()", Logger.severity.INFO);
					m_landingState = LandingState.None;
				}

				if (m_landingState != LandingState.None)
				{
					float minDestRadius = m_controlBlock.CubeGrid.GetLongestDim() * 5f;
					if (m_navSet.Settings_Current.DestinationRadius < minDestRadius)
					{
						m_logger.debugLog("Increasing DestinationRadius from " + m_navSet.Settings_Current.DestinationRadius + " to " + minDestRadius, "FlyToGrid()", Logger.severity.DEBUG);
						m_navSet.Settings_Task_NavRot.DestinationRadius = minDestRadius;
					}

					new UnLander(mover, navSet, landingBlock);

					m_landingHalfSize = landingBlock.Block.GetLengthInDirection(landingBlock.Block.LocalMatrix.GetClosestDirection(landingBlock.LocalMatrix.Forward)) * 0.5f;
					m_logger.debugLog("m_landing direction: " + m_landingDirection + ", m_landingBlockSize: " + m_landingHalfSize, "FlyToGrid()");
				}
			}

			m_navSet.Settings_Task_NavMove.NavigatorMover = this;
		}
예제 #29
0
		public EnemyFinder(Mover mover, AllNavigationSettings navSet)
			: base(navSet, mover.Block)
		{
			this.m_logger = new Logger(GetType().Name, mover.Block.CubeBlock, () => CurrentResponse.Response.ToString());
			this.m_mover = mover;
			this.m_navSet = navSet;

			m_logger.debugLog("Initialized", "EnemyFinder()");
		}
예제 #30
0
		/// <summary>
		/// Sets m_mover and m_navSet for the navigator.
		/// </summary>
		/// <param name="mover">The Mover to use</param>
		/// <param name="navSet">The settings to use</param>
		protected NavigatorRotator(Mover mover, AllNavigationSettings navSet)
			: base(mover, navSet) { }