/// <summary> /// Determines if the connector, landing gear, or merge block is locked. False if m_navBlock is none of those. /// </summary> private bool IsLocked() { if (m_landingState == LandingState.None) { return(false); } if (m_beforeMerge) { return(true); } IMyLandingGear asGear = m_navBlock.Block as IMyLandingGear; if (asGear != null) { return(asGear.IsLocked); } IMyShipConnector asConn = m_navBlock.Block as IMyShipConnector; if (asConn != null) { //Log.DebugLog("locked: " + asConn.IsLocked + ", connected: " + asConn.IsConnected + ", other: " + asConn.OtherConnector, "IsLocked()"); return(asConn.Status == Ingame.MyShipConnectorStatus.Connected); } return(false); }
public Leg(IMyGridTerminalSystem gts, string id) //id will here be "Left" or "Right" but could e.g. also be numerals { this.rotors = new Dictionary <string, IMyMotorStator>() { ["yaw 1"] = gts.GetBlockWithName($"LWE Walk Rotor {id} 1 (Yaw 1)") as IMyMotorStator, ["yaw 2"] = gts.GetBlockWithName($"LWE Walk Rotor {id} 4 (Yaw 2)") as IMyMotorStator, ["pitch 1"] = gts.GetBlockWithName($"LWE Walk Rotor {id} 2 (Pitch 1)") as IMyMotorStator, ["pitch 2"] = gts.GetBlockWithName($"LWE Walk Rotor {id} 5 (Pitch 2)") as IMyMotorStator, ["pitch 3"] = gts.GetBlockWithName($"LWE Walk Rotor {id} 6 (Pitch 3)") as IMyMotorStator, ["roll 1"] = gts.GetBlockWithName($"LWE Walk Rotor {id} 3 (Roll 1)") as IMyMotorStator, ["roll 2"] = gts.GetBlockWithName($"LWE Walk Rotor {id} 7 (Roll 2)") as IMyMotorStator }; this.pistons = new Dictionary <string, IMyPistonBase>() { ["forward"] = gts.GetBlockWithName($"LWE Walk Piston {id} 1 (Forward)") as IMyPistonBase, ["forward support"] = gts.GetBlockWithName($"LWE Walk Piston {id} 3 (Forward Support)") as IMyPistonBase, ["down"] = gts.GetBlockWithName($"LWE Walk Piston {id} 2 (Down)") as IMyPistonBase, ["down support"] = gts.GetBlockWithName($"LWE Walk Piston {id} 4 (Down Support)") as IMyPistonBase }; this.mergeBlocks = new Dictionary <string, IMyShipMergeBlock>() { ["knee"] = gts.GetBlockWithName($"LWE Merge {id} Knee") as IMyShipMergeBlock, ["foot"] = gts.GetBlockWithName($"LWE Merge {id} Foot") as IMyShipMergeBlock }; this.landingGear = gts.GetBlockWithName($"LWE Landing Gear {id}") as IMyLandingGear; }
public UnlockSafe(IMyLandingGear landingGearToUnlock, IMyLandingGear landingGearControl) // to make sure at least one landing gear is always locked to the ground { this.landingGearToUnlock = landingGearToUnlock; this.landingGearControl = landingGearControl; ExecuteLockSwitch(); // in this case just one action }
public List <IMyPistonBase> GetNextPistonInHierarchy(List <IMyPistonBase> tree, List <IMyPistonBase> allPistons) { IEnumerable <IMyPistonBase> nextPistons = allPistons.Where(p => p.TopGrid.EntityId == tree[0].CubeGrid.EntityId); IEnumerable <IMyPistonBase> siblingPistons = allPistons.Where(p => p.CubeGrid.EntityId == tree[0].CubeGrid.EntityId && p.EntityId != tree[0].EntityId); Echo($"Finding Next Piston"); if (nextPistons.Count() == 0) { Echo("No More pistons found"); return(tree); } // this one has a landing gear piston on it else if (siblingPistons.Count() == 1) { IEnumerable <IMyPistonBase> pistons = nextPistons.Concat(siblingPistons); IMyPistonBase landingGearPiston = landingGearGridIds.Contains(pistons.ElementAt(0).TopGrid.EntityId) ? pistons.ElementAt(0) : pistons.ElementAt(1); IMyPistonBase drillPiston = landingGearPiston == pistons.ElementAt(0) ? pistons.ElementAt(1) : pistons.ElementAt(0); IMyLandingGear landingGear = ALL_LANDING_GEAR.Find(l => l.CubeGrid.EntityId == landingGearPiston.TopGrid.EntityId); tree.Insert(0, drillPiston); LANDING_GEAR_PISTONS_BY_DRILL_PISTON.Add(drillPiston, landingGearPiston); PISTONS_BY_LANDING_GEAR.Add(landingGear, landingGearPiston); return(GetNextPistonInHierarchy(tree, allPistons)); } else { tree.Insert(0, nextPistons.ElementAt(0)); return(GetNextPistonInHierarchy(tree, allPistons)); } }
public Hacker(IMyCubeBlock block) { m_hackBlock = block as IMyLandingGear; Log.DebugLog("created for: " + block.DisplayNameText); Log.DebugLog("Not a hacker", Logger.severity.FATAL, condition: !IsHacker(block)); }
private void Grid_OnBlockRemoved(IMySlimBlock obj) { MyCubeGrid grid = (MyCubeGrid)obj.CubeGrid; IMyCubeBlock fat = obj.FatBlock; if (fat == null || grid == null) { return; } foreach (BlockCounter counter in BlockCounters.Values) { counter.TryRemoveCount(fat); } if (IsShipController(fat)) { HashSet <IMyShipController> gridCockpits; if (cockpits.TryGetValue(grid, out gridCockpits)) { gridCockpits.Remove((IMyShipController)fat); cockpits [grid] = gridCockpits; } } else { IMyLandingGear gear = fat as IMyLandingGear; if (gear != null) { this.gear.Remove(gear); } } Resort(grid); }
public PistonAndLandingGearExtendAndLock(IMyPistonBase piston, IMyLandingGear landingGear, IMyPistonBase supportPiston = null) { this.piston = piston; this.supportPiston = supportPiston; this.landingGear = landingGear; this.StartMovement(); }
public Hacker(IMyCubeBlock block) { m_logger = new Logger(GetType().Name, block); m_hackBlock = block as IMyLandingGear; m_logger.debugLog("created for: " + block.DisplayNameText); m_logger.debugLog(!IsHacker(block), "Not a hacker", Logger.severity.FATAL); }
bool FuncTest(IMyLandingGear block) { //Landing Gear //Interface name: IMyLandingGear //Parent: IMyFunctionalBlock //Fields: float BreakForce = block.BreakForce; return(true); }
private Leg(IMyMotorStator R1, IMyMotorStator H1, IMyMotorStator H2, IMyMotorStator H3, IMyMotorStator H4, IMyMotorStator R2, IMyLandingGear LG, Base6Directions.Direction S) { Rotor1 = R1; Hinge1 = H1; Hinge2 = H2; Hinge3 = H3; Hinge4 = H4; Rotor2 = R2; LandingGear = LG; Side = S; }
void StateChanged(IMyLandingGear gear, LandingGearMode oldMode) { if (oldMode == LandingGearMode.ReadyToLock && gear.LockMode == LandingGearMode.Locked) HudMessage = MySpaceTexts.NotificationLandingGearSwitchLocked; else if (oldMode == LandingGearMode.Locked && gear.LockMode == LandingGearMode.Unlocked) HudMessage = MySpaceTexts.NotificationLandingGearSwitchUnlocked; else //if (oldMode == LandingGearMode.ReadyToLock && gear.LockMode == LandingGearMode.Unlocked) HudMessage = MyStringId.NullOrEmpty; m_gearStates[(int)oldMode].Remove(gear); m_gearStates[(int)gear.LockMode].Add(gear); }
private void ToggleGear(IMyLandingGear gear, bool state) { if (state) { gear.Lock(); gear.AutoLock = true; } else { gear.Unlock(); gear.AutoLock = false; } }
private void UpdateState(IMyLandingGear clamp) { clamp.AutoLock = false; if (!clamp.IsOperational()) { return; } Operable++; if (clamp.IsLocked) { Locked++; } }
bool TryLockInLGear(double distance) { IMyLandingGear clamp = Reference as IMyLandingGear; clamp.Enabled = true; if (AutoLockDistance > 0) { clamp.AutoLock = distance < AutoLockDistance; } if (clamp.LockMode == LandingGearMode.ReadyToLock) { clamp.Lock(); } return(clamp.LockMode == LandingGearMode.Locked); }
public void SetupGrid() { foreach (MyCubeBlock block in _thisGrid.GetFatBlocks()) { MyThrust myThrust = block as MyThrust; if (myThrust != null) { _gridSystems.ControllableThrusters.AddNewThruster(myThrust); WriteToLog("SetupGrid", $"Adding Thruster {myThrust.GridThrustDirection}", LogType.General); continue; } MyGyro myGyro = block as MyGyro; if (myGyro != null) { _gridSystems.ControllableGyros.Add(myGyro); WriteToLog("SetupGrid", $"Adding Gyro", LogType.General); continue; } IMyTextSurface surface = block as IMyTextSurface; if (surface != null) { if (((IMyTerminalBlock)surface).CustomData.Contains("DebugL")) { _gridSystems.DebugScreens.AddLeftScreen(surface); _gridSystems.DebugScreens.WriteToLeft(new StringBuilder("Left Debug Screen Detected")); WriteToLog("SetupGrid", $"Adding Left Debug Screen", LogType.General); } if (((IMyTerminalBlock)surface).CustomData.Contains("DebugR")) { _gridSystems.DebugScreens.AddRightScreen(surface); _gridSystems.DebugScreens.WriteToRight(new StringBuilder("Right Debug Screen Detected")); WriteToLog("SetupGrid", $"Adding Right Debug Screen", LogType.General); } continue; } IMyLandingGear gear = block as IMyLandingGear; if (gear == null) { continue; } _gridSystems.ControllableLandingGear.Add(gear); } }
public void ExtendNextPiston(string argument) { float SPEED; float.TryParse(argument, out SPEED); if (SPEED == 0) { SPEED = .5f; } if (DRILL_PISTONS.Count == 0) { return; } bool found = false; foreach (IMyPistonBase p in DRILL_PISTONS) { if (p.Status == PistonStatus.Extended) { continue; } else { Echo($"Extending at {SPEED}m/s"); p.Velocity = SPEED; found = true; IMyPistonBase lp; if (LANDING_GEAR_PISTONS_BY_DRILL_PISTON.TryGetValue(p, out lp)) { IMyLandingGear landingGear = PISTONS_BY_LANDING_GEAR.FirstOrDefault(x => x.Value == lp).Key; landingGear.AutoLock = true; if (!landingGear.IsLocked) { lp.Velocity = SPEED; } } break; } } if (found == false) { Runtime.UpdateFrequency = UpdateFrequency.None; } }
private void _Init() { if (_isInitialized) { return; } _isInitialized = true; _landingGear = Entity as IMyLandingGear; if (_landingGear == null) { return; } _landingGear.StateChanged += LandingGearOnStateChanged; }
void StateChanged(IMyLandingGear gear, LandingGearMode oldMode) { if (oldMode == LandingGearMode.ReadyToLock && gear.LockMode == LandingGearMode.Locked) { HudMessage = MySpaceTexts.NotificationLandingGearSwitchLocked; } else if (oldMode == LandingGearMode.Locked && gear.LockMode == LandingGearMode.Unlocked) { HudMessage = MySpaceTexts.NotificationLandingGearSwitchUnlocked; } else //if (oldMode == LandingGearMode.ReadyToLock && gear.LockMode == LandingGearMode.Unlocked) { HudMessage = MyStringId.NullOrEmpty; } m_gearStates[(int)oldMode].Remove(gear); m_gearStates[(int)gear.LockMode].Add(gear); }
public Program() { // The constructor, called only once every session and // always before any other method is called. Use it to // initialize your script. // // The constructor is optional and can be removed if not // needed. // // It's recommended to set RuntimeInfo.UpdateFrequency // here, which will allow your script to run itself without a // timer block. _timer = GridTerminalSystem.GetBlockWithName("MSD_Timer") as IMyTimerBlock; _pistonInOut = GridTerminalSystem.GetBlockWithName("MSD_pInOut") as IMyPistonBase; _pistonSlide = GridTerminalSystem.GetBlockWithName("MSD_pSlide") as IMyPistonBase; _gear = GridTerminalSystem.GetBlockWithName("MSD_Gear") as IMyLandingGear; }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { this.objectBuilder = objectBuilder; try { gear = (IMyLandingGear)Entity; initBlockSettings(); if (gear.BlockDefinition.SubtypeName.EndsWith("_D_RAIL") || def.valid) { valid = true; updateHook = true; CoreMagRails.UpdateHook += Update; //constrain its position } } catch (Exception ex) { Log.DebugWrite(DebugLevel.Error, ex); } }
public void GearsLock(bool bLock = true) { for (int i = 0; i < gearList.Count; i++) { IMyLandingGear g = gearList[i] as IMyLandingGear; if (g == null) { continue; } if (bLock) { g.Lock(); } else { g.Unlock(); } // blockApplyAction(gearList[i], "Lock"); } }
private void Disconnect() { IMyLandingGear asGear = m_unlandBlock.Block as IMyLandingGear; if (asGear != null) { m_attached = asGear.GetAttachedEntity() != null; if (m_attached) { Log.DebugLog("Unlocking landing gear", Logger.severity.DEBUG); MyAPIGateway.Utilities.TryInvokeOnGameThread(() => { asGear.ApplyAction("Unlock"); }); } } else { MyShipConnector asConn = (MyShipConnector)m_unlandBlock.Block; if (asConn != null) { m_attached = asConn.Connected; if (m_attached) { MyShipConnector otherConnector = (MyShipConnector)((IMyShipConnector)asConn).OtherConnector; ReserveTarget(otherConnector.EntityId); Log.DebugLog("Unlocking connector", Logger.severity.DEBUG); MyAPIGateway.Utilities.TryInvokeOnGameThread(() => { asConn.Enabled = true; otherConnector.Enabled = true; asConn.ApplyAction("Unlock"); }); } } else { Log.DebugLog("cannot unlock: " + m_unlandBlock.Block.DisplayNameText, Logger.severity.INFO); m_attached = false; } } }
bool gearReadyToLock(IMyTerminalBlock block) { IMyLandingGear g = block as IMyLandingGear; if (g == null) { return(false); } return((int)g.LockMode == 1); // LandingGearMode.ReadyToLock); /* * StringBuilder temp = new StringBuilder(); * ITerminalAction theAction; * * temp.Clear(); * theAction = block.GetActionWithName("Lock"); * block.GetActionWithName(theAction.Id.ToString()).WriteValue(block, temp); * if (temp.ToString().Contains("Ready")) * return true; * return false; */ }
public VoxelLander(Pathfinder pathfinder, bool planet, PseudoBlock landBlock = null) : base(pathfinder) { this.m_landBlock = landBlock ?? m_navSet.Settings_Current.LandingBlock; this.m_targetType = planet ? "Planet" : "Asteroid"; if (this.m_landBlock == null) { Log.DebugLog("No landing block", Logger.severity.INFO); return; } IMyLandingGear asGear = m_landBlock.Block as IMyLandingGear; if (asGear != null) { ITerminalProperty <bool> autolock = asGear.GetProperty("Autolock") as ITerminalProperty <bool>; Log.DebugLog("autolock == null", Logger.severity.FATAL, condition: autolock == null); if (!autolock.GetValue(asGear)) { autolock.SetValue(asGear, true); } } Vector3D currentPostion = m_landBlock.WorldPosition; MyVoxelBase closest = null; if (planet) { closest = MyPlanetExtensions.GetClosestPlanet(m_landBlock.WorldPosition); if (closest == null) { Log.DebugLog("No planets in the world", Logger.severity.WARNING); return; } } else { BoundingSphereD search = new BoundingSphereD(currentPostion, 10000d); List <MyVoxelBase> nearby = new List <MyVoxelBase>(); MyGamePruningStructure.GetAllVoxelMapsInSphere(ref search, nearby); double closestDistSquared = double.MaxValue; foreach (MyVoxelBase voxel in nearby) { if (!(voxel is MyVoxelMap)) { continue; } double distSquared = Vector3D.DistanceSquared(currentPostion, voxel.GetCentre()); if (distSquared < closestDistSquared) { closestDistSquared = distSquared; closest = voxel; } } if (closest == null) { Log.DebugLog("No asteroids nearby", Logger.severity.WARNING); return; } } Vector3D end = closest.GetCentre(); MyVoxelBase hitVoxel; Vector3D hitPosition; if (!RayCast.RayCastVoxels(ref currentPostion, ref end, out hitVoxel, out hitPosition)) { throw new Exception("Failed to intersect voxel"); } m_targetPostion = Destination.FromWorld(hitVoxel, hitPosition); m_navSet.Settings_Task_NavRot.NavigatorMover = this; m_navSet.Settings_Task_NavRot.IgnoreAsteroid = true; Log.DebugLog("Landing on " + m_targetType + " at " + m_targetPostion, Logger.severity.DEBUG); }
public Program() { gear = GridTerminalSystem.GetBlockWithName("[DOCK] Landing Gear") as IMyLandingGear; }
public virtual void UnregisterFromSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.RemoveSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (sink != null) { this.ResourceDistributor.RemoveSink(sink, true, false); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = null; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Unregister(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block5 = block as MyTerminalBlock; if (block5 != null) { this.TerminalSystem.Remove(block5); } } if (block.HasInventory) { this.ConveyorSystem.Remove(block); } IMyConveyorEndpointBlock block2 = block as IMyConveyorEndpointBlock; if (block2 != null) { this.ConveyorSystem.RemoveConveyorBlock(block2); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { this.ConveyorSystem.RemoveSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Unregister(reflector); } MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); if (broadcaster != null) { this.RadioSystem.Unregister(broadcaster); } MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); if (reciever != null) { this.RadioSystem.Unregister(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Unregister(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Unregister(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Unregister(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Unregister(camera); } } block.OnUnregisteredFromGridSystems(); }
public virtual void RegisterInSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { MyCubeBlock block1; if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.AddSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (!(block is MyThrust) && (sink != null)) { this.ResourceDistributor.AddSink(sink); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = this.ResourceDistributor; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Register(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block6 = block as MyTerminalBlock; if (block6 != null) { this.TerminalSystem.Add(block6); } } if ((block == null) || !block.HasInventory) { block1 = null; } else { block1 = block; } MyCubeBlock block2 = block1; if (block2 != null) { this.ConveyorSystem.Add(block2); } IMyConveyorEndpointBlock endpointBlock = block as IMyConveyorEndpointBlock; if (endpointBlock != null) { endpointBlock.InitializeConveyorEndpoint(); this.ConveyorSystem.AddConveyorBlock(endpointBlock); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { segmentBlock.InitializeConveyorSegment(); this.ConveyorSystem.AddSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Register(reflector); } if (block.Components.Contains(typeof(MyDataBroadcaster))) { MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); this.RadioSystem.Register(broadcaster); } if (block.Components.Contains(typeof(MyDataReceiver))) { MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); this.RadioSystem.Register(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Register(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Register(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Register(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Register(camera); } } block.OnRegisteredToGridSystems(); }
public void Unregister(IMyLandingGear gear) { m_gearStates[(int)gear.LockMode].Remove(gear); gear.LockModeChanged -= m_onStateChanged; }
void StateChanged(IMyLandingGear gear, LandingGearMode oldMode) { m_gearStates[(int)oldMode].Remove(gear); m_gearStates[(int)gear.LockMode].Add(gear); }
public void Register(IMyLandingGear gear) { gear.LockModeChanged += m_onStateChanged; m_gearStates[(int)gear.LockMode].Add(gear); }
public Program() { GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(null, (b) => { if (b.CubeGrid.EntityId == Me.CubeGrid.EntityId) { if (b is IMyThrust) { Thrusters.Add(b as IMyThrust); } else if (b is IMyGyro) { Gyros.Add(b as IMyGyro); } else if (b is IMySensorBlock) { Sensors.Add(b as IMySensorBlock); } else if (b is IMyBatteryBlock) { Batteries.Add(b as IMyBatteryBlock); } else if (b is IMyShipController) { Controller = b as IMyShipController; } else if (b is IMyShipConnector) { Connector = b as IMyShipConnector; } else if (b is IMyRadioAntenna) { Antenna = b as IMyRadioAntenna; } else if (b is IMyLandingGear) { Clamp = b as IMyLandingGear; } else if (b is IMyCameraBlock) { Cameras.Add(b as IMyCameraBlock); } } return(false); }); if (Controller == null) { throw new Exception("Controller not found."); } if (Thrusters.Count == 0) { throw new Exception("Thrusters not found."); } if (Gyros.Count == 0) { throw new Exception("Gyros not found."); } if (Connector == null) { throw new Exception("Connector not found."); } if (Clamp == null) { throw new Exception("Clamp not found."); } if (Sensors.Count == 0) { throw new Exception("Sensors not found."); } foreach (var cam in Cameras) { cam.EnableRaycast = true; } Pilot = new AutoPilot(Controller, Thrusters, Gyros); try { Configure(Storage, true); Message("Retriever Drone state restored."); } catch (Exception) { Configure(Me.CustomData, false); Message("Retriever Drone initialized."); } Message($"Drone {Me.CubeGrid.CustomName} IGC ID: 0x{IGC.Me:X}"); logScreen = Me.GetSurface(0); logScreen.ContentType = ContentType.TEXT_AND_IMAGE; //Pilot.Log = (s) => logScreen?.WriteText(s, true); }
public static bool TryGet(MyGridProgram Prog, Base6Directions.Direction S, IMyMotorStator R1, out Leg output) { output = null; if (R1 == null) { return(false); } if (S != Base6Directions.Direction.Left && S != Base6Directions.Direction.Right) { return(false); } List <IMyMotorStator> MotorList = (new GenericMethods <IMyMotorStator>(Prog)).GetAllIncluding("Leg Hinge 1"); IMyMotorStator H1 = null; foreach (IMyMotorStator Hinge in MotorList) { if (R1.TopGrid == Hinge.CubeGrid) { H1 = Hinge; break; } } if (H1 == null) { return(false); } MotorList = (new GenericMethods <IMyMotorStator>(Prog)).GetAllIncluding("Leg Hinge 2"); IMyMotorStator H2 = null; foreach (IMyMotorStator Hinge in MotorList) { if (H1.TopGrid == Hinge.CubeGrid) { H2 = Hinge; break; } } if (H2 == null) { return(false); } MotorList = (new GenericMethods <IMyMotorStator>(Prog)).GetAllIncluding("Leg Hinge 3"); IMyMotorStator H3 = null; foreach (IMyMotorStator Hinge in MotorList) { if (H2.TopGrid == Hinge.CubeGrid) { H3 = Hinge; break; } } if (H3 == null) { return(false); } MotorList = (new GenericMethods <IMyMotorStator>(Prog)).GetAllIncluding("Leg Hinge 4"); IMyMotorStator H4 = null; foreach (IMyMotorStator Hinge in MotorList) { if (H3.TopGrid == Hinge.CubeGrid) { H4 = Hinge; break; } } if (H4 == null) { return(false); } MotorList = (new GenericMethods <IMyMotorStator>(Prog)).GetAllIncluding("Ankle Rotor"); IMyMotorStator R2 = null; foreach (IMyMotorStator Rotor in MotorList) { if (H4.TopGrid == Rotor.CubeGrid) { R2 = Rotor; break; } } if (R2 == null) { return(false); } List <IMyLandingGear> GearList = (new GenericMethods <IMyLandingGear>(Prog)).GetAllIncluding("Foot"); IMyLandingGear LG = null; foreach (IMyLandingGear LandingGear in GearList) { if (R2.TopGrid == LandingGear.CubeGrid) { LG = LandingGear; break; } } if (LG == null) { return(false); } output = new Leg(R1, H1, H2, H3, H4, R2, LG, S); output.Program = Prog; return(true); }
private void init() { #region initialization oldPBName = Me.CustomName; unique_id = (new Random()).Next(); all_blocks_found = true; autopilot_en = true; location_name = "UNKNOWN"; // For spinner counter = 0; string parse = Me.CustomName.Replace(BLOCK_PREFIX, ""); int id1 = Me.CustomName.IndexOf('['); int id2 = Me.CustomName.IndexOf(']'); if (id1 >= 0 && id2 >= 0) { parse = parse.Substring(id1 + 1, id2 - id1 - 1); } else { parse = ""; } BaconArgs Args = BaconArgs.parse(parse); IS_BASE = (Args.getFlag('b') > 0); DOCK_LEFT = (Args.getFlag('l') > 0); IS_PLANET = (Args.getFlag('p') > 0); if (IS_PLANET) { IS_BASE = true; } List <string> nameArg = Args.getOption("name"); if (nameArg.Count > 0 && nameArg[0] != null) { location_name = nameArg[0]; } // Set all known blocks to null or clear lists lcdPanel = null; messageReceiver = null; WANProgram = null; connector = null; remoteControl = null; door = null; timer = null; landLight = null; mainGear = 0; gyros.Clear(); destinations.Clear(); gears.Clear(); // Get all blocks List <IMyTerminalBlock> blks = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName(BLOCK_PREFIX, blks, hasPrefix); num_blocks_found = blks.Count; // Assign blocks to variables as appropriate foreach (var blk in blks) { // LCD panel for printing if (blk is IMyTextPanel) { lcdPanel = blk as IMyTextPanel; lcdPanel.ShowPublicTextOnScreen(); lcdPanel.SetValueFloat("FontSize", 1.2f); } // Wico Area Network programmable block else if (blk is IMyProgrammableBlock && !blk.Equals(Me)) { WANProgram = blk as IMyProgrammableBlock; } // Autopilot else if (!IS_BASE && blk is IMyRemoteControl) { remoteControl = blk as IMyRemoteControl; } /* Ship or station connector for docking * Used to connect to station and for orientation info */ else if (!IS_PLANET && blk is IMyShipConnector) { connector = blk as IMyShipConnector; } /* Door used for docking; used for orientation information * since it's more obvious which way a door faces than a connector */ else if (!IS_PLANET && blk is IMyDoor) { door = blk as IMyDoor; } // Gyros for ship orientation else if (!IS_BASE && blk is IMyGyro) { IMyGyro g = blk as IMyGyro; gyros.Add(g); } // Timer block so that we can orient ship properly - requires multiple calls/sec else if (!IS_BASE && blk is IMyTimerBlock) { timer = blk as IMyTimerBlock; timer.SetValueFloat("TriggerDelay", 1.0f); } // Light (interior or spotlight) determines where we will land else if (IS_BASE && IS_PLANET && blk is IMyInteriorLight) { landLight = blk as IMyInteriorLight; } // Landing gear.... else if (!IS_BASE && blk is IMyLandingGear) { IMyLandingGear gear = blk as IMyLandingGear; gears.Add(gear); if (gear.CustomName.ToLower().Contains("main")) { mainGear = gears.Count - 1; } } } // Make sure all gyros reset resetGyros(); // Clear block list blks.Clear(); // Get text panel blocks used by Wico Area Network for communication GridTerminalSystem.GetBlocksOfType <IMyTextPanel>(blks, hasWANRPrefix); if (blks.Count == 0) { Echo("Error: Can't find message received text panel for Wico Area Network"); all_blocks_found = false; } else { messageReceiver = blks[0] as IMyTextPanel; messageReceiver.WritePublicTitle(""); messageReceiver.WritePrivateTitle("NAV"); } if (WANProgram == null) { Echo("Error: Can't find programming block for Wico Area Network"); all_blocks_found = false; } if (lcdPanel == null) { Echo("Error: Expect 1 LCD"); all_blocks_found = false; } if (!IS_PLANET && connector == null) { Echo("Error: Can't find any connectors to use for docking"); all_blocks_found = false; } if (!IS_BASE && remoteControl == null) { Echo("Error: Can't find any remote control blocks"); all_blocks_found = false; } if (!IS_PLANET && door == null) { Echo("Error: Can't find door"); all_blocks_found = false; } if (!IS_BASE && gyros.Count == 0) { Echo("Error: No gyros detected"); all_blocks_found = false; } if (!IS_BASE && timer == null) { Echo("Error: No timer found"); all_blocks_found = false; } if (IS_PLANET && landLight == null) { Echo("Error: No light for landing ship destination found"); all_blocks_found = false; } if (!IS_BASE && gears.Count == 0) { Echo("Warning: no landing gear found. You will not be able to land on planets"); } // Init communicator state machine comm = communicate().GetEnumerator(); // Clear autopilot state machine fly = null; #endregion }