public Waypoint(Pathfinder pathfinder, AllNavigationSettings.SettingsLevelName level, Destination destination) : base(pathfinder) { this.m_level = level; this.m_destination = destination; Log.DebugLog("targetEntity is not top-most", Logger.severity.FATAL, condition: destination.Entity != destination.Entity.GetTopMostParent()); IMyCubeGrid asGrid = destination.Entity as IMyCubeGrid; if (asGrid != null && Attached.AttachedGrid.IsGridAttached(asGrid, m_controlBlock.CubeGrid, Attached.AttachedGrid.AttachmentKind.Physics)) { Log.DebugLog("Cannot fly to entity, attached: " + destination.Entity.getBestName() + ", creating GOLIS", Logger.severity.WARNING); new GOLIS(pathfinder, m_destination.WorldPosition(), level); return; } if (destination.Entity.Physics == null) { Log.DebugLog("Target has no physics: " + destination.Entity.getBestName() + ", creating GOLIS", Logger.severity.WARNING); new GOLIS(pathfinder, m_destination.WorldPosition(), level); return; } var setLevel = m_navSet.GetSettingsLevel(level); setLevel.NavigatorMover = this; Log.DebugLog("created, level: " + level + ", target: " + destination.Entity.getBestName() + ", target: " + m_destination + ", position: " + m_destination.WorldPosition(), Logger.severity.DEBUG); }
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); }
public void ResumeFromSave(Builder_Autopilot builder) { using (lock_execution.AcquireExclusiveUsing()) { m_navSet.OnStartOfCommands(); Log.DebugLog("resume: " + builder.Commands + ", current: " + builder.CurrentCommand, Logger.severity.DEBUG); m_autopilotActions = m_commands.GetActions(builder.Commands); while (m_autopilotActions.CurrentIndex < builder.CurrentCommand - 1 && m_autopilotActions.MoveNext()) { m_autopilotActions.Current.Invoke(m_pathfinder); Log.DebugLog("fast forward: " + m_autopilotActions.CurrentIndex); // clear navigators' levels for (AllNavigationSettings.SettingsLevelName levelName = AllNavigationSettings.SettingsLevelName.NavRot; levelName < AllNavigationSettings.SettingsLevelName.NavWay; levelName++) { AllNavigationSettings.SettingsLevel settingsAtLevel = m_navSet.GetSettingsLevel(levelName); if (settingsAtLevel.NavigatorMover != null || settingsAtLevel.NavigatorRotator != null) { Log.DebugLog("clear " + levelName); m_navSet.OnTaskComplete(levelName); break; } } } if (m_autopilotActions.MoveNext()) { m_autopilotActions.Current.Invoke(m_pathfinder); } // clear wait m_navSet.OnTaskComplete(AllNavigationSettings.SettingsLevelName.NavWay); EnemyFinder finder = m_navSet.Settings_Current.EnemyFinder; if (finder != null) { if (builder.EngagerOriginalEntity != 0L) { if (!MyAPIGateway.Entities.TryGetEntityById(builder.EngagerOriginalEntity, out finder.m_originalDestEntity)) { Log.AlwaysLog("Failed to restore original destination enitity for enemy finder: " + builder.EngagerOriginalEntity, Logger.severity.WARNING); finder.m_originalDestEntity = null; } else { Log.DebugLog("Restored original destination enitity for enemy finder: " + finder.m_originalDestEntity.getBestName()); } } if (builder.EngagerOriginalPosition.IsValid()) { finder.m_originalPosition = builder.EngagerOriginalPosition; Log.DebugLog("Restored original position for enemy finder: " + builder.EngagerOriginalPosition); } } } }
/// <summary> /// Creates a GOLIS /// </summary> /// <param name="pathfinder">The mover to use</param> /// <param name="navSet">The settings to use</param> /// <param name="location">The location to fly to</param> public GOLIS(Pathfinder pathfinder, Vector3D location, AllNavigationSettings.SettingsLevelName level = AllNavigationSettings.SettingsLevelName.NavMove) : base(pathfinder) { 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 }
/// <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 }
public Waypoint(Pathfinder pathfinder, AllNavigationSettings.SettingsLevelName level, IMyEntity targetEntity, Vector3D worldOffset) : this(pathfinder, level, new Destination(targetEntity, ref worldOffset)) { }
public FlyToGrid(Mover mover, AllNavigationSettings navSet, string targetGrid = null, AttachedGrid.AttachmentKind allowedAttachment = AttachedGrid.AttachmentKind.Permanent, GridFinder finder = null, PseudoBlock landingBlock = null) : 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; if (finder != null) this.m_gridFinder = finder; else this.m_gridFinder = new GridFinder(m_navSet, m_mover.Block, targetGrid, blockName, allowedAttachment); this.m_landingFriend = !(this.m_gridFinder is EnemyFinder); this.m_contBlock = m_navSet.Settings_Commands.NavigationBlock; if (landingBlock == null) 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, 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", Logger.severity.INFO); m_landingState = LandingState.None; } else { m_logger.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.IsConnected || connector.OtherConnector == m_navBlock.Block) && ReserveTarget(connector.EntityId); }; m_landingDirection = m_targetBlock.Forward ?? Base6Directions.GetFlippedDirection(landingBlock.Block.GetFaceDirection()[0]); } else if (landingBlock.Block is IMyShipMergeBlock) { m_gridFinder.BlockCondition = block => block is IMyShipMergeBlock && ReserveTarget(block.EntityId); 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.", 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); } } m_settingLevel = m_landingState != LandingState.None ? AllNavigationSettings.SettingsLevelName.NavRot : AllNavigationSettings.SettingsLevelName.NavMove; m_navSet.GetSettingsLevel(m_settingLevel).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; }