Beispiel #1
0
        protected AttachableBlockBase(IMyCubeBlock block, AttachedGrid.AttachmentKind kind)
        {
            AttachmentKind = kind;
            myBlock        = block;

            Logger.DebugLog("Created for: " + block.DisplayNameText);

            block.OnMarkForClose += Detach;
        }
		protected AttachableBlockBase(IMyCubeBlock block, AttachedGrid.AttachmentKind kind)
		{
			myLogger = new Logger("AttachableBlockBase", block);
			AttachmentKind = kind;
			myBlock = block;

			myLogger.debugLog("Created for: " + block.DisplayNameText, "AttachableBlockBase()");

			block.OnClose += Detach;
			Registrar.Add(this.myBlock, this);
		}
Beispiel #3
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;
        }
Beispiel #4
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)
        {
            Log.DebugLog("navSet == null", Logger.severity.FATAL, condition: navSet == null);
            Log.DebugLog("controller == null", Logger.severity.FATAL, condition: controller == null);
            Log.DebugLog("controller.CubeBlock == null", Logger.severity.FATAL, condition: controller.CubeBlock == null);
            Log.DebugLog("targetGrid == null", Logger.severity.FATAL, condition: targetGrid == null);

            this.m_targetGridName = targetGrid.LowerRemoveWhitespace();
            if (targetBlock != null)
            {
                this.m_targetBlockName = targetBlock.LowerRemoveWhitespace();
            }
            this.m_controlBlock      = controller;
            this.m_allowedAttachment = allowedAttachment;
            this.MaximumRange        = 0f;
            this.m_navSet            = navSet;
            this.m_mustBeRecent      = mustBeRecent;
            this.m_startPosition     = m_controlBlock.CubeBlock.GetPosition();
        }
Beispiel #5
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;
		}
Beispiel #6
0
 public AttachableBlockUpdate(IMyCubeBlock block, AttachedGrid.AttachmentKind kind)
     : base(block, kind)
 {
 }
Beispiel #7
0
        /// <summary>
        /// Finds a block that is attached to Controller
        /// </summary>
        /// <remarks>
        /// Search is performed immediately.
        /// For a navigating block, always use AttachedGrid.AttachmentKind.None.
        /// </remarks>
        protected bool GetLocalBlock(IMyCubeBlock autopilot, string searchFor, out IMyCubeBlock localBlock, out string message, AttachedGrid.AttachmentKind allowedAttachments = AttachedGrid.AttachmentKind.None)
        {
            searchFor = searchFor.RemoveWhitespace();
            IMyCubeBlock foundBlock     = null;
            int          bestNameLength = int.MaxValue;

            foreach (IMyCubeBlock block in AttachedGrid.AttachedCubeBlocks(autopilot.CubeGrid, allowedAttachments, true))
            {
                if (autopilot.canControlBlock(block))
                {
                    string blockName = block.DisplayNameText.RemoveWhitespace();
                    if (blockName.Length < bestNameLength && blockName.Contains(searchFor, StringComparison.InvariantCultureIgnoreCase))
                    {
                        foundBlock     = block;
                        bestNameLength = blockName.Length;
                        if (searchFor.Length == bestNameLength)
                        {
                            break;
                        }
                    }
                }
            }

            if (foundBlock == null)
            {
                message    = "Not found: " + searchFor;
                localBlock = null;
                return(false);
            }

            message    = null;
            localBlock = foundBlock;
            return(true);
        }
Beispiel #8
0
        public FlyToGrid(Pathfinder pathfinder, string targetGrid = null, AttachedGrid.AttachmentKind allowedAttachment = AttachedGrid.AttachmentKind.Permanent, GridFinder finder = null, PseudoBlock landingBlock = null)
            : base(pathfinder)
        {
            this.m_targetBlock = m_navSet.Settings_Current.DestinationBlock;
            string blockName = m_targetBlock == null ? null : m_targetBlock.BlockName;

            if (finder != null)
            {
                this.m_gridFinder = finder;
            }
            else
            {
                this.m_gridFinder = new GridFinder(m_navSet, m_controlBlock, targetGrid, blockName, allowedAttachment);
            }
            this.m_landingFriend = !(this.m_gridFinder is EnemyFinder);

            if (landingBlock == null)
            {
                landingBlock = m_navSet.Settings_Current.LandingBlock;
            }
            m_navSet.Settings_Task_NavRot.NavigationBlock = landingBlock;

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

                if (m_targetBlock == null)
                {
                    if (!(landingBlock.Block is IMyLandingGear))
                    {
                        Log.DebugLog("cannot land block without a target", Logger.severity.INFO);
                        m_landingState = LandingState.None;
                    }
                    else
                    {
                        Log.DebugLog("golden retriever mode enabled", 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.Status == Ingame.MyShipConnectorStatus.Unconnected || connector.OtherConnector == m_navBlock.Block) && CanReserveTarget(connector.EntityId));
                    };
                    m_landingDirection = m_targetBlock.Forward ?? Base6Directions.GetFlippedDirection(landingBlock.Block.FirstFaceDirection());
                }
                else if (landingBlock.Block is IMyShipMergeBlock)
                {
                    m_gridFinder.BlockCondition = block => block is IMyShipMergeBlock && CanReserveTarget(block.EntityId);
                    m_landingDirection          = m_targetBlock.Forward ?? Base6Directions.GetFlippedDirection(landingBlock.Block.FirstFaceDirection());
                    (landingBlock.Block as IMyShipMergeBlock).BeforeMerge += MergeBlock_BeforeMerge;
                }
                else if (m_targetBlock.Forward.HasValue)
                {
                    m_landingDirection = m_targetBlock.Forward.Value;
                }
                else
                {
                    Log.DebugLog("Player failed to specify landing direction and it could not be determined.", 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)
                    //{
                    //	Log.DebugLog("Increasing DestinationRadius from " + m_navSet.Settings_Current.DestinationRadius + " to " + minDestRadius, "FlyToGrid()", Logger.severity.DEBUG);
                    //	m_navSet.Settings_Task_NavRot.DestinationRadius = minDestRadius;
                    //}

                    new UnLander(m_pathfinder, landingBlock);

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

            m_settingLevel = m_landingState != LandingState.None ? AllNavigationSettings.SettingsLevelName.NavRot : AllNavigationSettings.SettingsLevelName.NavMove;
            m_navSet.GetSettingsLevel(m_settingLevel).NavigatorMover = this;
        }