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; }
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; }