public void FindSortedContainers() { // Echo("dbg: FindSortedContainers()"); sortedContainers.Clear(); GridTerminalSystem.GetBlocksOfType( sortedContainers, block => block.IsWorking && block.CustomName.StartsWith("store")); // sortedContainers.ForEach(s => Echo($"dbg: Found store: '{s.CustomName}'")); }
void ProcessStepMoveAwayFromDock() { SkipIfOrbitMode(); SkipIfNoGridNearby(); var _rb = ReferenceBlock; var thrusters = new List <IMyThrust>(); if (!IsObstructed(_rb.WorldMatrix.Forward)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Backward); } else if (!IsObstructed(_rb.WorldMatrix.Backward)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Forward); } else if (!IsObstructed(_rb.WorldMatrix.Left)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Right); } else if (!IsObstructed(_rb.WorldMatrix.Right)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Left); } else if (!IsObstructed(_rb.WorldMatrix.Up)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Down); } else if (!IsObstructed(_rb.WorldMatrix.Down)) { GridTerminalSystem.GetBlocksOfType(thrusters, thruster => thruster.WorldMatrix.Forward == _rb.WorldMatrix.Up); } else { ZeroThrustOverride(); EchoR("Ship is obstructed, waiting clearance"); throw new PutOffExecutionException(); } double currentSpeed = RemoteControl.GetShipSpeed(); double distanceFromDock = Vector3D.Distance(lastShipPosition, ReferenceBlock.GetPosition()); if (distanceFromDock < SafeDistanceFromDock && currentSpeed < 5) { thrusters.ForEach(thrust => { if (thrust.CurrentThrust > thrust.ThrustOverride) { thrust.ThrustOverride = thrust.CurrentThrust + 5000f; } thrust.ThrustOverride += 2000f; }); } else if (distanceFromDock > SafeDistanceFromDock) { processStep++; } }
void Main() { // initialize VRage.MyFixedPoint totalVolume = 0; VRage.MyFixedPoint totalMaxVolume = 0; var blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyInventoryOwner>(blocks, FilterInventoryOwner); if (blocks.Count == 0) { throw new Exception("Did not find any cargo container."); } for (int i = 0; i < blocks.Count; ++i) { var invOwner = blocks[i] as IMyInventoryOwner; for (int j = 0; j < invOwner.InventoryCount; ++j) { var inv = invOwner.GetInventory(j); totalVolume += inv.CurrentVolume; totalMaxVolume += inv.MaxVolume; } } blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyBeacon>(blocks, FilterAntenna); GridTerminalSystem.GetBlocksOfType <IMyRadioAntenna>(blocks, FilterAntenna); if (blocks.Count == 0) { throw new Exception("Did not find the specified antenna"); } var antenna = blocks[0]; StringBuilder sb = new StringBuilder(); sb.Append(antennaName).Append(" - "); sb.Append((long)(totalVolume * K)).Append(" / ").Append((long)(totalMaxVolume * K)); sb.Append(" (").Append(VRageMath.MathHelper.RoundOn2(100 * (float)(totalVolume * K) / (float)(totalMaxVolume * K))).Append("%)"); //antenna.SetCustomName(sb.ToString()); if (totalVolume == totalMaxVolume) { IMyTerminalBlock block = GridTerminalSystem.GetBlockWithName(stop); if (block == null) { throw new Exception("Could not find block with name: '" + stop + "'"); } block.SetCustomName(block.CustomName + "full,"); block.ApplyAction("Run"); } Echo(sb.ToString()); debug.Clear(); }
private void Setup() { _groupList.Clear(); List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); // Find all blocks with a "[LandingPad]" section in custom data. GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(blocks, block => MyIni.HasSection(block.CustomData, MyConstants.SectionName) && block.IsSameConstructAs(Me)); // Step through each block and determine groups foreach (IMyTerminalBlock block in blocks) { // parse the custom data for the block MyIniParseResult parsedIniResult; if (_data.TryParse(block.CustomData, out parsedIniResult)) { MyConfiguration blockConfig = new MyConfiguration(_data); // Get the Group value. string groupName = blockConfig.GroupName; // If there is no group specified and if this is a text panel, use that as a main panel, // otherwise continue with next block. if (blockConfig.GroupName == MyConstants.DefaultGroupName) { IMyTextPanel lcdPanel = block as IMyTextPanel; if (lcdPanel != null) { DisplayPanel panel = new DisplayPanel(_groupList, lcdPanel); _mainPanels.Add(panel); } continue; } ; // If group does not exist, add a new group with this name. if (!_groupList.Exists(x => x.GroupName == groupName)) { LandingPadGroup landingLightGroup = new LandingPadGroup(groupName); _groupList.Add(landingLightGroup); } // Get the group for this block it should be added to. LandingPadGroup group = _groupList.Find(x => x.GroupName == groupName); AddBlockToGroup(group, block, blockConfig); } } // All block should now be assigned. // Configure the individual blocks for each group. foreach (LandingPadGroup group in _groupList) { group.ConfigureBlocks(); } }
public void Main(string argument, UpdateType updateSource) { // The main entry point of the script, invoked every time // one of the programmable block's Run actions are invoked, // or the script updates itself. The updateSource argument // describes where the update came from. Be aware that the // updateSource is a bitfield and might contain more than // one update type. // // The method itself is required, but the arguments above // can be removed if not needed. List <IMyCargoContainer> cargoContainers = new List <IMyCargoContainer>(); GridTerminalSystem.GetBlocksOfType(blocks: cargoContainers); List <MyInventoryItem> inventoryItems = new List <MyInventoryItem>(); foreach (IMyCargoContainer container in cargoContainers) { IMyInventory myInventory = container.GetInventory(); List <MyInventoryItem> items = new List <MyInventoryItem>(); myInventory.GetItems(items: items); foreach (MyInventoryItem item in items) { inventoryItems.Add(item: item); } } List <ItemCount> itemCounts = new List <ItemCount>(); foreach (MyInventoryItem item in inventoryItems) { if (itemCounts.All(x => x.Type != item.Type)) { ItemCount itemCount = new ItemCount(item.Type); itemCounts.Add(itemCount); itemCount.Amount += item.Amount; } else { ItemCount itemCount = itemCounts.FirstOrDefault(x => x.Type == item.Type); if (itemCount != null) { itemCount.Amount += item.Amount; } } } foreach (ItemCount count in itemCounts.OrderBy(x => x.Type).ToList()) { Echo("1"); Echo($"{count} : {count.Amount}"); } }
void ShutownSystems() { foreach (IMyThrust thisThrust in brakingThrusters) { thisThrust.ThrustOverridePercentage = 0f; if (disableThrustOnLanding && attemptToLand) { thisThrust.Enabled = false; } else { thisThrust.Enabled = true; } } foreach (IMyGyro thisGyro in gyros) { thisGyro.GyroOverride = false; } foreach (IMyTimerBlock thisTimer in landingTimers) { thisTimer.Trigger(); } foreach (IMyThrust thisThrust in otherThrusters) { thisThrust.ThrustOverridePercentage = 0f; if (disableThrustOnLanding) { thisThrust.Enabled = false; } else { thisThrust.Enabled = true; } } referenceBlock.DampenersOverride = true; Echo("Landing successful\nShutting down systems...\n\nGood Luck Pilot!"); Runtime.UpdateFrequency = UpdateFrequency.None; string message = $" {shipName}\n--------------------------------------------------\nLanding successful\nShutting down systems...\n\nGood Luck Pilot!"; //---Write to screens statusScreens.Clear(); GridTerminalSystem.GetBlocksOfType(statusScreens, block => block.CustomName.ToLower().Contains(statusScreenName.ToLower())); foreach (IMyTextPanel thisScreen in statusScreens) { thisScreen.WriteText(message); thisScreen.ContentType = ContentType.TEXT_AND_IMAGE; thisScreen.TextPadding = 0f; //thisScreen.SetValue("FontSize", 1.5f); thisScreen.Font = "Monospace"; } }
void initReactors() { reactorList.Clear(); GridTerminalSystem.GetBlocksOfType <IMyReactor>(reactorList, localGridFilter); float currentOutput; reactorCheck(out currentOutput); }
//конструктор public Program() { RemCon = GridTerminalSystem.GetBlockWithName("RemCon") as IMyRemoteControl; Gyros = new List <IMyGyro>(); GridTerminalSystem.GetBlocksOfType <IMyGyro>(Gyros); Runtime.UpdateFrequency = UpdateFrequency.Update1; Forward = RemCon.WorldMatrix.Forward; Forward = Vector3D.Reject(Forward, Vector3D.Normalize(RemCon.GetNaturalGravity())); }
private void RefreshBlockList() { GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(_blocksWithInventory, block => block.HasInventory && block.IsSameConstructAs(Me) && (!_optInWithTag || MyIni.HasSection(block.CustomData, _tagName))); _inventories.Clear(); _inventories.AddRange(_blocksWithInventory.SelectMany(block => Enumerable.Range(0, block.InventoryCount).Select(block.GetInventory))); }
private void UpdateComponents() { string tag = Me.CustomData.Trim(); shipConnectors.Clear(); pistons.Clear(); GridTerminalSystem.GetBlocksOfType(shipConnectors, (ship_connector) => (ship_connector.CustomData.Trim() == tag)); GridTerminalSystem.GetBlocksOfType(pistons, (piston) => (piston.CustomData.Trim() == tag)); }
//MyFunctions,Methods //Создаёт лист блоков в имени которых содержится текст из переменной. public List <IMyTerminalBlock> FindBlockByPartOfName(string blockName) { List <IMyTerminalBlock> blockList; blockList = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(blockList); GridTerminalSystem.SearchBlocksOfName(blockName, blockList); return(blockList); }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update100; List <IMyProjector> li = new List <IMyProjector>(); GridTerminalSystem.GetBlocksOfType <IMyProjector>(li, b => b.CubeGrid == Me.CubeGrid); this.projector = li[0]; }
} // Initialize() public bool Init0 () { int i; // counter Color computerColor = new Color(255, 69, 0); blockList.Clear(); // clear the block list GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(blockList, b => b.IsSameConstructAs(Me)); // get text panels cockpitLCD1 = null; cockpitLCD2 = null; for (i = 0; i < blockList.Count; i++) { if (blockList[i].CustomData.Contains(cockpitLCD1ID)) { cockpitLCD1 = blockList[i] as IMyTextPanel; } // if contains cockpitLCD1ID else if (blockList[i].CustomData.Contains(cockpitLCD2ID)) { cockpitLCD2 = blockList[i] as IMyTextPanel; } // else if contains cockpitLCD2ID } // for i if (cockpitLCD1 == null) { Echo("System: Unable to find LCD1\n"); } // if cockpitLCD1 == null else { cockpitLCD1.Enabled = true; //cockpitLCD1.Font = ""; cockpitLCD1.BackgroundColor = Color.Black; cockpitLCD1.FontColor = computerColor; cockpitLCD1.FontSize = 2.0f; cockpitLCD1.ShowPublicTextOnScreen(); cockpitLCD1.WritePublicTitle(cockpitLCD1Title); WriteLCD("LCD1 found.\n", 1); } // else cockpitLCD1 == null if (cockpitLCD2 == null) { Echo("System: Unable to find LCD2\n"); } // if cockpitLCD2 == null else { cockpitLCD2.Enabled = true; //cockpitLCD2.Font = ""; cockpitLCD2.BackgroundColor = Color.Black; cockpitLCD2.FontColor = computerColor; cockpitLCD2.FontSize = 2.0f; cockpitLCD2.ShowPublicTextOnScreen(); cockpitLCD2.WritePublicTitle(cockpitLCD2Title); WriteLCD("LCD2 found.\n", 2); } // else cockpitLCD2 == null return true; } // Init0()
IMyCockpit GetCockPit() { if (cachedCockpit == null || GridTerminalSystem.GetBlockWithId(cachedCockpit.EntityId) == null) { GridTerminalSystem.GetBlocksOfType(cockpitList, x => x.IsSameConstructAs(Me)); cachedCockpit = cockpitList.FirstOrDefault(x => cockpitName == null || x.CustomName == cockpitName); } return(cachedCockpit); }
private void Main(string argument, UpdateType updateType) { float current_battery_output = 0.0f; float maximal_battery_output = 0.0f; float current_battery_input = 0.0f; float maximal_battery_input = 0.0f; float current_battery_stored_power = 0.0f; float maximal_battery_stored_power = 0.0f; float current_non_battery_output = 0.0f; float maximal_non_battery_output = 0.0f; textPanels.Clear(); GridTerminalSystem.GetBlocksOfType(textPanels, (text_panel) => (text_panel.CustomData.Trim().ToLower() == "powerinfo")); foreach (long key in storageDisplays.Keys) { missingStorageDisplays.Add(key); } foreach (IMyTextPanel text_panel in textPanels) { if (!(missingStorageDisplays.Remove(text_panel.EntityId))) { storageDisplays.Add(text_panel.EntityId, new PowerDisplay(text_panel)); } } foreach (long key in missingStorageDisplays) { storageDisplays.Remove(key); } missingStorageDisplays.Clear(); powerProducers.Clear(); GridTerminalSystem.GetBlocksOfType(powerProducers); foreach (IMyPowerProducer power_producer in powerProducers) { if (power_producer.IsWorking) { if (power_producer is IMyBatteryBlock) { IMyBatteryBlock battery_block = (IMyBatteryBlock)power_producer; current_battery_output += battery_block.CurrentOutput; maximal_battery_output += battery_block.MaxOutput; current_battery_input += battery_block.CurrentInput; maximal_battery_input += battery_block.MaxInput; current_battery_stored_power += battery_block.CurrentStoredPower; maximal_battery_stored_power += battery_block.MaxStoredPower; } else { current_non_battery_output += power_producer.CurrentOutput; maximal_non_battery_output += power_producer.MaxOutput; } } } foreach (PowerDisplay storage_display in storageDisplays.Values) { storage_display.UpdateValues(current_battery_output, current_non_battery_output, maximal_battery_output, maximal_non_battery_output, current_battery_input, maximal_battery_input, current_battery_stored_power, maximal_battery_stored_power); } }
public Program() { var clipPistons = new List <IMyPistonBase>(); GridTerminalSystem.GetBlocksOfType <IMyPistonBase>(clipPistons, (IMyPistonBase x) => x.CustomData.ToLower().Contains("warhead clip")); if (clipPistons.Count() > 0) { ClipPiston = clipPistons.First(); var pistons = new List <IMyPistonBase>(); GridTerminalSystem.GetBlocksOfType <IMyPistonBase>(pistons, (IMyPistonBase x) => x.CubeGrid == ClipPiston.CubeGrid && x != ClipPiston); if (pistons.Count() > 0) { PlacerPiston = pistons.First(); var rotors = new List <IMyMotorStator>(); GridTerminalSystem.GetBlocksOfType <IMyMotorStator>(rotors, (IMyMotorStator x) => x.CubeGrid == PlacerPiston.TopGrid); if (rotors.Count() > 0) { PlacerRotor = rotors.First(); setupError = false; } else { Echo("Setup error. Make sure there is a rotor on the end of the placer piston and recompile the script."); } } else { Echo("Setup error. Make sure the placer piston is on the same subgrid as the clip piston and recompile the script."); } } else { Echo("Setup error. Make sure the clip piston has \"warhead clip\" in the custom data and recompile the script."); } if (!setupError) { Echo("Setup complete with no errors."); var payloadRotors = new List <IMyMotorStator>(); GridTerminalSystem.GetBlocksOfType <IMyMotorStator>(payloadRotors, (IMyMotorStator x) => x.CubeGrid == ClipPiston.TopGrid); if (payloadRotors.Count() == 0) { Echo("Warning: no payload rotors found!"); } Runtime.UpdateFrequency = UpdateFrequency.Update1; } }
public void Main(string argument, UpdateType updateSource) { if (OreInventories == null || ComponentInventories == null) { OreInventories = new List <IMyInventory>(); ComponentInventories = new List <IMyInventory>(); GridTerminalSystem.GetBlocksOfType(Containers, container => container.CustomData.StartsWith(CUSTOMDATA_CONFIG_PREFIX) && container.IsSameConstructAs(Me)); bool encounteredError = false; foreach (var container in Containers) { var inventoryType = container.CustomData.Substring(CUSTOMDATA_CONFIG_PREFIX.Length); if (inventoryType == "Ores") { OreInventories.Add(container.GetInventory()); } else if (inventoryType == "Components") { ComponentInventories.Add(container.GetInventory()); } else { Echo($"Invalid inventory type on container {inventoryType}"); encounteredError = true; } } if (OreInventories.Count == 0) { Echo("Could not find any ore inventories"); encounteredError = true; } if (ComponentInventories.Count == 0) { Echo("Could not find any component inventories"); encounteredError = true; } if (encounteredError) { OreInventories = ComponentInventories = null; Coroutine.Dispose(); Coroutine = null; Runtime.UpdateFrequency = UpdateFrequency.None; return; } } if (!Coroutine.MoveNext()) { Coroutine.Dispose(); Coroutine = RunProcess(); } }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update1; camera = GridTerminalSystem.GetBlockWithName("camera (atmo miner)") as IMyCameraBlock; rotor1 = GridTerminalSystem.GetBlockWithName("rotor 1 (cam)") as IMyMotorStator; rotor2 = GridTerminalSystem.GetBlockWithName("rotor 2 (cam)") as IMyMotorStator; cockpit = GridTerminalSystem.GetBlockWithName("Industrial Cockpit (atmo miner)") as IMyShipController; gyros = new List <IMyGyro>(); GridTerminalSystem.GetBlocksOfType <IMyGyro>(gyros); }
// "[COS-T] Targets" public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update1; GridTerminalSystem.GetBlocksOfType(sensors); GridTerminalSystem.GetBlocksOfType(turrets); GridTerminalSystem.GetBlocksOfType(screens); InitBlocks(); }
public Program() { var gyros = new List<IMyGyro>(); var thrusters = new List<IMyThrust>(); GridTerminalSystem.GetBlocksOfType(gyros); GridTerminalSystem.GetBlocksOfType(thrusters); shipController = GridTerminalSystem.GetBlockWithName("Controller") as IMyShipController; gridControl = new GridControl(gyros, thrusters, shipController); Runtime.UpdateFrequency = UpdateFrequency.Update1; }
public List <IMyMotorStator> GetRotors() { List <IMyMotorStator> rotors = new List <IMyMotorStator>(); GridTerminalSystem.GetBlocksOfType <IMyMotorStator>(rotors); logger.log(rotors.Count.ToString()); return(rotors); }
public void Main(string argument, UpdateType updateSource) { int percentage = CalcCargoSpace(); List <IMyCockpit> cocks = new List <IMyCockpit>(); GridTerminalSystem.GetBlocksOfType(cocks, c**k => c**k.CubeGrid == Me.CubeGrid); //Echo($"{msg}"); }
void AddInvOfType <T>(int idx) { List <IMyTerminalBlock> TermBlks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <T>(TermBlks); for (int i = 0; i < TermBlks.Count; i++) { OtherInv.Add(TermBlks[i].GetInventory(idx)); } }
void addPistonsConnectedToGrids(IMyCubeGrid grid) { List <IMyPistonBase> gridPistons = new List <IMyPistonBase>(); GridTerminalSystem.GetBlocksOfType <IMyPistonBase>(gridPistons, (x => x.TopGrid == grid)); foreach (var piston in gridPistons) { addGridToLocal(piston.CubeGrid); } }
// Returns a list of assemblers that are on the current grid. private List <IMyAssembler> GetAssemblerBlocks(IMyTerminalBlock parentGridBlock) { var blocks = new List <IMyAssembler>(); GridTerminalSystem.GetBlocksOfType(blocks, delegate(IMyAssembler a) { return(a.CubeGrid == parentGridBlock.CubeGrid); }); return(blocks); }
/** * Returns a list of functional (fully assembled and not below hack line) blocks of a given type. * Type must be a descendent of IMyTerminalBlock. */ private List <T> GetFunctionalBlocksOfType <T>(bool thisGridOnly = true) where T : class, IMyTerminalBlock { List <T> blockList = new List <T>(); GridTerminalSystem.GetBlocksOfType(blockList); return(thisGridOnly ? blockList.FindAll(block => block.IsSameConstructAs(Me) && block.IsFunctional) : blockList); }
private List <ExtendedBattery> GetBatteries() { var batteryArray = new List <IMyBatteryBlock>(); GridTerminalSystem.GetBlocksOfType <IMyBatteryBlock>(batteryArray); var extendedBatteries = new List <ExtendedBattery>(); batteryArray.ForEach(x => extendedBatteries.Add(new ExtendedBattery(x))); return(extendedBatteries); }
void EnableBlocks(Func <IMyFunctionalBlock, bool> collect, bool enable = true) { var blocks = new List <IMyFunctionalBlock>(); GridTerminalSystem.GetBlocksOfType(blocks, blk => collect(blk)); foreach (var blk in blocks) { blk.Enabled = enable; } }
private void ClearQueue() { List <IMyAssembler> assemblerList = new List <IMyAssembler>(); GridTerminalSystem.GetBlocksOfType <IMyAssembler>(assemblerList, assembler => assembler.CubeGrid == Me.CubeGrid); foreach (IMyAssembler assembler in assemblerList) { assembler.ClearQueue(); } }
public Program() { var cockpits = new List <IMyShipController>(); GridTerminalSystem.GetBlocksOfType(cockpits); m_Cockpit = cockpits.First(); m_Gyros = new List <IMyGyro>(); GridTerminalSystem.GetBlocksOfType(m_Gyros, a => a.IsSameConstructAs(m_Cockpit)); }