private static void CheckGridConnection(IMyEntity block) { IMyCubeBlock cubeBlock = block as IMyCubeBlock; if (cubeBlock == null) { return; } if (cubeBlock is IMyPistonBase) { IMyPistonBase pistonBase = cubeBlock as IMyPistonBase; if (pistonBase != null && pistonBase.IsAttached && pistonBase.Top != null && pistonBase.Top.Parent != null) { if (!m_conveyorConnected.ContainsKey(pistonBase.Top.Parent.EntityId)) { m_conveyorConnected.Add(pistonBase.Top.Parent.EntityId, new long[] { pistonBase.Top.EntityId, pistonBase.EntityId }); } } } else if (cubeBlock is IMyShipConnector) { Ingame.IMyShipConnector connector = cubeBlock as IMyShipConnector; if (connector != null && connector.Status == Sandbox.ModAPI.Ingame.MyShipConnectorStatus.Connected && connector.OtherConnector != null && connector.OtherConnector.CubeGrid != null) { if (!m_conveyorConnected.ContainsKey(connector.OtherConnector.CubeGrid.EntityId)) { m_conveyorConnected.Add(connector.OtherConnector.CubeGrid.EntityId, new long[] { connector.OtherConnector.EntityId, connector.EntityId }); } } } else if (cubeBlock is IMyAttachableTopBlock) { var motorRotor = cubeBlock as IMyAttachableTopBlock; if (motorRotor != null && motorRotor.IsAttached && motorRotor.Base != null && motorRotor.Parent != null) { if (!m_conveyorConnected.ContainsKey(motorRotor.Base.Parent.EntityId)) { m_conveyorConnected.Add(motorRotor.Base.Parent.EntityId, new long[] { motorRotor.Base.EntityId, motorRotor.EntityId }); } } } else if (cubeBlock is IMyMechanicalConnectionBlock) { var motorBase = cubeBlock as IMyMechanicalConnectionBlock; if (motorBase != null && motorBase.IsAttached && motorBase.Top != null && motorBase.Top.Parent != null) { if (!m_conveyorConnected.ContainsKey(motorBase.Top.Parent.EntityId)) { m_conveyorConnected.Add(motorBase.Top.Parent.EntityId, new long[] { motorBase.Top.EntityId, motorBase.EntityId }); } } } }
private bool lockLanding() { Ingame.IMyShipConnector connector = CNS.landLocalBlock as Ingame.IMyShipConnector; if (connector != null) { if (!connector.IsLocked) // this actually checks for ready to lock (yellow light) { connector.GetActionWithName("OnOff_On").Apply(connector); // on return(false); } log("trying to lock connector", "lockLanding()", Logger.severity.TRACE); connector.GetActionWithName("SwitchLock").Apply(connector); // lock return(true); } Ingame.IMyLandingGear landingGear = CNS.landLocalBlock as Ingame.IMyLandingGear; if (landingGear != null) { MyObjectBuilder_LandingGear builder = CNS.landLocalBlock.GetObjectBuilderCubeBlock() as MyObjectBuilder_LandingGear; landingGear.GetActionWithName("OnOff_On").Apply(landingGear); // on if (!builder.AutoLock) { log("setting autolock", "lockLanding()", Logger.severity.TRACE); landingGear.GetActionWithName("Autolock").Apply(landingGear); // autolock on return(false); } return(builder.IsLocked); } Ingame.IMyShipMergeBlock mergeBlock = CNS.landLocalBlock as Ingame.IMyShipMergeBlock; if (mergeBlock != null) { MyObjectBuilder_MergeBlock builder = CNS.landLocalBlock.GetObjectBuilderCubeBlock() as MyObjectBuilder_MergeBlock; if (builder.SubBlocks != null && builder.SubBlocks.Length > 0) { log("subblock[0]=" + builder.SubBlocks[0].SubGridName, "lockLanding()", Logger.severity.TRACE); } if (!mergeBlock.IsFunctional || !mergeBlock.IsWorking) //&& mergeMonitor.mergeStatus == MergeMonitor.MergeStatus.OFF) { log("merge block set", "lockLanding()", Logger.severity.TRACE); mergeBlock.GetActionWithName("OnOff_On").Apply(mergeBlock); // on } return(false); } log("unknown lander block type " + CNS.landLocalBlock.DefinitionDisplayNameText, "lockLanding()", Logger.severity.INFO); return(true); // assume there is nothing to lock }
private bool unlockLanding() { if (CNS.landingSeparateBlock == null) { alwaysLog("CNS.landingSeparateBlock == null", "unlockLanding()", Logger.severity.FATAL); return(false); // do not allow Navigator to proceed } Ingame.IMyShipConnector connector = CNS.landingSeparateBlock as Ingame.IMyShipConnector; if (connector != null) { // due to a bug in Space Engineers, Autopilot should not unlock a connector while a player is in any passenger seat if (hasPilot()) { myNav.GET_OUT_OF_SEAT = true; myNav.reportState(Navigator.ReportableState.GET_OUT_OF_SEAT); return(false); } myNav.GET_OUT_OF_SEAT = false; bool disconnected = true; if ((CNS.landingSeparateBlock.GetObjectBuilderCubeBlock() as MyObjectBuilder_ShipConnector).Connected) { disconnected = false; log("switching lock", "unlockLanding()", Logger.severity.TRACE); connector.GetActionWithName("SwitchLock").Apply(connector); // unlock } if ((CNS.landingSeparateBlock as Ingame.IMyFunctionalBlock).Enabled) { disconnected = false; log("turning off", "unlockLanding()", Logger.severity.TRACE); connector.GetActionWithName("OnOff_Off").Apply(connector); // off } return(disconnected); } Ingame.IMyLandingGear landingGear = CNS.landingSeparateBlock as Ingame.IMyLandingGear; if (landingGear != null) { // due to a bug in Space Engineers, Autopilot should not unlock a landing gear while a player is in any passenger seat if (hasPilot()) { myNav.GET_OUT_OF_SEAT = true; myNav.reportState(Navigator.ReportableState.GET_OUT_OF_SEAT); return(false); } myNav.GET_OUT_OF_SEAT = false; bool disconnected = true; MyObjectBuilder_LandingGear builder = CNS.landingSeparateBlock.GetObjectBuilderCubeBlock() as MyObjectBuilder_LandingGear; if (builder.AutoLock) { disconnected = false; log("autolock off", "unlockLanding()", Logger.severity.TRACE); landingGear.GetActionWithName("Autolock").Apply(landingGear); // autolock off } if (builder.IsLocked) { disconnected = false; log("landing gear switching lock", "unlockLanding()", Logger.severity.TRACE); landingGear.GetActionWithName("SwitchLock").Apply(landingGear); // unlock } return(disconnected); } Ingame.IMyShipMergeBlock mergeBlock = CNS.landingSeparateBlock as Ingame.IMyShipMergeBlock; if (mergeBlock != null) { bool disconnected = true; if ((CNS.landingSeparateBlock as Ingame.IMyFunctionalBlock).Enabled) { disconnected = false; log("turning off merge block", "unlockLanding()", Logger.severity.TRACE); mergeBlock.GetActionWithName("OnOff_Off").Apply(connector); // off } return(disconnected); } log("unknown separate block type: " + CNS.landingSeparateBlock.DefinitionDisplayNameText, "unlockLanding()", Logger.severity.INFO); return(true); // assume there is nothing to unlock }
private long GetGridGroupOwner(IMyCubeGrid grid) { Ingame.IMyGridTerminalSystem system = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid); List <Ingame.IMyTerminalBlock> terminalBlocks = new List <Ingame.IMyTerminalBlock>(); system.GetBlocks(terminalBlocks); foreach (var item in terminalBlocks) { if (((IMyCubeGrid)item.CubeGrid).BigOwners.Count > 0) { return(((IMyCubeGrid)item.CubeGrid).BigOwners.First()); } if (item is IMyPistonBase) { IMyPistonBase pistonBase = (IMyPistonBase)item; if (pistonBase.TopGrid != null) { if (pistonBase.TopGrid.BigOwners.Count > 0) { return(pistonBase.TopGrid.BigOwners.First()); } } } if (item is IMyMechanicalConnectionBlock) { var motorBase = item as IMyMechanicalConnectionBlock; if (motorBase.TopGrid != null) { if (motorBase.TopGrid.BigOwners.Count > 0) { return(motorBase.TopGrid.BigOwners.First()); } } } if (item is Ingame.IMyShipConnector) { Ingame.IMyShipConnector connector = (Ingame.IMyShipConnector)item; if (connector.Status == Sandbox.ModAPI.Ingame.MyShipConnectorStatus.Connected && connector.OtherConnector != null) { if (((IMyCubeGrid)connector.OtherConnector.CubeGrid).BigOwners.Count > 0) { return(((IMyCubeGrid)connector.OtherConnector.CubeGrid).BigOwners.First()); } } } if (item is IMyAttachableTopBlock) { var motorRotor = item as IMyAttachableTopBlock; if (motorRotor.IsAttached && motorRotor.Base != null) { if (motorRotor.Base.CubeGrid.BigOwners.Count > 0) { return(motorRotor.Base.CubeGrid.BigOwners.First()); } } } } return(0); }
private void AddConnectedGridBlock(NaniteDeconstructionGrid deconstruct, IMySlimBlock slimBlock) { if (slimBlock.FatBlock == null) { return; } IMyCubeBlock cubeBlock = (IMyCubeBlock)slimBlock.FatBlock; IMySlimBlock otherBlock = null; if (cubeBlock is IMyPistonBase) { IMyPistonBase pistonBase = (IMyPistonBase)cubeBlock; if (pistonBase.Top != null) { MyCubeBlock cubeOther = (MyCubeBlock)pistonBase.Top; if (deconstruct.GridsProcessed.Contains(cubeOther.CubeGrid)) { return; } if (!deconstruct.AddingGridList.Contains(cubeOther.SlimBlock)) { deconstruct.AddingGridList.Add(cubeOther.SlimBlock); otherBlock = cubeOther.SlimBlock; } } } else if (cubeBlock is Ingame.IMyShipConnector) { Ingame.IMyShipConnector connector = (Ingame.IMyShipConnector)cubeBlock; if (connector.Status == Sandbox.ModAPI.Ingame.MyShipConnectorStatus.Connected) { MyCubeBlock cubeOther = (MyCubeBlock)connector.OtherConnector; if (deconstruct.GridsProcessed.Contains(cubeOther.CubeGrid)) { return; } if (!deconstruct.AddingGridList.Contains(cubeOther.SlimBlock)) { deconstruct.AddingGridList.Add(cubeOther.SlimBlock); otherBlock = cubeOther.SlimBlock; } } } else if (cubeBlock is IMyAttachableTopBlock) { var motorRotor = cubeBlock as IMyAttachableTopBlock; if (motorRotor.Base != null) { MyCubeBlock cubeOther = motorRotor.Base as MyCubeBlock; if (deconstruct.GridsProcessed.Contains(cubeOther.CubeGrid)) { return; } if (!deconstruct.AddingGridList.Contains(cubeOther.SlimBlock)) { deconstruct.AddingGridList.Add(cubeOther.SlimBlock); otherBlock = cubeOther.SlimBlock; } } } else if (cubeBlock is IMyMechanicalConnectionBlock) { var motorBase = cubeBlock as IMyMechanicalConnectionBlock; if (motorBase.TopGrid != null) { var cubeOther = motorBase.Top as MyCubeBlock; if (deconstruct.GridsProcessed.Contains(cubeOther.CubeGrid)) { return; } if (!deconstruct.AddingGridList.Contains(cubeOther.SlimBlock)) { deconstruct.AddingGridList.Add(cubeOther.SlimBlock); otherBlock = cubeOther.SlimBlock; } } } }
public static List <IMyCubeGrid> GetGridGroup(IMyCubeGrid grid) { List <IMyCubeGrid> gridList = new List <IMyCubeGrid>(); gridList.Add(grid); //int pos = 0; try { List <Ingame.IMyTerminalBlock> terminalBlocks = new List <Ingame.IMyTerminalBlock>(); Ingame.IMyGridTerminalSystem system = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid); if (system != null) { system.GetBlocks(terminalBlocks); foreach (var item in terminalBlocks) { if (!gridList.Contains((IMyCubeGrid)item.CubeGrid)) { gridList.Add((IMyCubeGrid)item.CubeGrid); } if (item is IMyPistonBase) { IMyPistonBase pistonBase = (IMyPistonBase)item; if (pistonBase.TopGrid != null && !gridList.Contains(pistonBase.TopGrid)) { gridList.Add(pistonBase.TopGrid); } } if (item is IMyMechanicalConnectionBlock) { var motorBase = item as IMyMechanicalConnectionBlock; if (motorBase.TopGrid != null && !gridList.Contains(motorBase.TopGrid)) { gridList.Add(motorBase.TopGrid); } } if (item is Ingame.IMyShipConnector) { Ingame.IMyShipConnector connector = (Ingame.IMyShipConnector)item; if (connector.Status == Sandbox.ModAPI.Ingame.MyShipConnectorStatus.Connected && connector.OtherConnector != null) { if (!gridList.Contains((IMyCubeGrid)connector.OtherConnector.CubeGrid)) { gridList.Add((IMyCubeGrid)connector.OtherConnector.CubeGrid); } } } if (item is IMyAttachableTopBlock) { var motorRotor = item as IMyAttachableTopBlock; if (motorRotor.IsAttached && motorRotor.Base != null) { if (!gridList.Contains((IMyCubeGrid)motorRotor.Base.CubeGrid)) { gridList.Add((IMyCubeGrid)motorRotor.Base.CubeGrid); } } } } } } catch (Exception ex) { Logging.Instance.WriteLine(string.Format("GetGridGroup Error: {0}", ex.ToString())); } return(gridList); }
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; }