public Assembler(IMyAssembler assembler) { CurrentProgress = assembler.CurrentProgress; AssemblerMode = assembler.Mode; CooperativeMode = assembler.CooperativeMode; Repeating = assembler.Repeating; }
public void CheckAssemblers(ref List <ControlObject> controlObjectList) { IMyGridTerminalSystem myGridTerminalSystem = null; List <IMyAssembler> gridAssemblers = new List <IMyAssembler>(); myGridTerminalSystem.GetBlocksOfType <IMyAssembler>(gridAssemblers); int assemblerFound = 0; foreach (ControlObject controlObject in controlObjectList) { assemblerFound = 0; for (var i = 0; i < controlObject.getAssemblersNames().Count; i++) { IMyAssembler assembler = (IMyAssembler)myGridTerminalSystem.GetBlockWithName(controlObject.getAssemblersNames()[i]); if (assembler != null) { controlObject.setAssemblers(assembler); assemblerFound++; } } controlObject.setQtdyOfAssemblersFound(assemblerFound); if (controlObject.getAssemblersNames().Count == assemblerFound) { controlObject.setFoundAllAssemblers(true); } else { controlObject.setFoundAllAssemblers(false); } } }
private void QueueAssemblyLine(InventoryComponent targetInventory, InventoryComponent actualInventory, IEnumerable <IMyAssembler> assemblers) { if (assemblers == null || assemblers.Count() == 0) { return; } IMyAssembler assembler = FindMasterAssembler(assemblers); if (assembler == null) { assembler = FindRandomAssembler(assemblers); } IEnumerable <ComponentType> componentTypes = actualInventory.GetKeys(); foreach (ComponentType componentType in componentTypes) { var difference = targetInventory.GetValue(componentType) - actualInventory.GetValue(componentType); if (difference > 0) { assembler.AddQueueItem(MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/" + componentType.ToString()), difference); } } }
void ProcessProjection(IMyAssembler assembler, IMyProjector projector, bool allBlocks) { var queueDictionary = GetBlocksForQueue(projector, allBlocks); if (allBlocks == false) { var existingParts = GetExistingParts(assembler); foreach (var component in existingParts.Keys.Where(component => queueDictionary.ContainsKey(component))) { if (existingParts[component] >= queueDictionary[component]) { queueDictionary[component] = 0; } else { queueDictionary[component] -= existingParts[component]; } } } foreach (var component in queueDictionary.Keys.Where(component => blueprintDictionary.ContainsKey(component))) { var blueprint = new MyDefinitionId(); var definition = $"MyObjectBuilder_BlueprintDefinition/{blueprintDictionary[component]}"; if (MyDefinitionId.TryParse(definition, out blueprint) && assembler.CanUseBlueprint(blueprint)) { assembler.AddQueueItem(blueprint, (MyFixedPoint)queueDictionary[component]); } } }
public Program() { m_MainCargoContainer = GridTerminalSystem.GetBlockWithName(MainCargoName) as IMyCargoContainer; m_ToolsCargoContainer = GridTerminalSystem.GetBlockWithName(ToolsCargoName) as IMyCargoContainer; GridTerminalSystem.GetBlocksOfType(m_Assemblers, a => (a is IMyAssembler && a.CubeGrid == m_MainCargoContainer.CubeGrid)); GridTerminalSystem.GetBlocksOfType(m_Refineries, a => (a is IMyRefinery && a.CubeGrid == m_MainCargoContainer.CubeGrid)); m_MainAssembler = m_Assemblers.First(a => a.CustomName == MainAssemblerName); m_MainGasGenerator = GridTerminalSystem.GetBlockWithName(MainGasGeneratorName) as IMyGasGenerator; m_FrontLcdOres = GridTerminalSystem.GetBlockWithName(OresIngotsLcdName) as IMyTextSurface; m_FrontLcdComponents = GridTerminalSystem.GetBlockWithName(ComponentsLcdName) as IMyTextSurface; #region Лист заказов кроме стальных пластин m_OrderList = new List <MyItemType>(); m_OrderList.Add(TypeInteriorPlate); m_OrderList.Add(TypeConstructionComponent); m_OrderList.Add(TypeMetalGrid); m_OrderList.Add(TypeComputer); m_OrderList.Add(TypeLargeTube); m_OrderList.Add(TypeSmallTube); m_OrderList.Add(TypeMotor); m_OrderList.Add(TypeDisplay); m_OrderList.Add(TypePowerCell); m_OrderList.Add(TypeGirder); m_OrderList.Add(TypeDetector); m_OrderList.Add(TypeRadioCommunication); m_OrderList.Add(TypeBulletproofGlass); #endregion Runtime.UpdateFrequency = UpdateFrequency.Update100; }
Dictionary <string, int> GetExistingParts(IMyAssembler assembler) { var resultDict = new Dictionary <string, int>(); var cubeGrid = (VRage.Game.ModAPI.IMyCubeGrid)assembler.CubeGrid; var gts = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(cubeGrid); var blockList = new List <IMyTerminalBlock>(); gts.GetBlocksOfType <IMyTerminalBlock>(blockList); foreach (var block in blockList.Where(block => block.HasInventory)) { for (var i = 0; i < block.InventoryCount; i++) { var blockInv = block.GetInventory(i); var blockItems = blockInv.GetItems(); foreach (var item in blockItems.Where(item => item.Content.TypeId.ToString().Contains("Component"))) { var subtype = item.Content.SubtypeId.ToString(); var amount = (int)item.Amount; if (resultDict.ContainsKey(subtype) == true) { resultDict[subtype] += amount; } else { resultDict.Add(subtype, amount); } } } } return(resultDict); }
private void BuildComponent(string componentName, double buildAmount, double batchAmount) { //Echo($"Build {buildAmount} {componentName}"); componentName = CorrectComponent(componentName); MyDefinitionId blueprint = MyDefinitionId.Parse($"MyObjectBuilder_BlueprintDefinition/{componentName}"); //Echo(blueprint.ToString()); List <IMyAssembler> assemblerList = new List <IMyAssembler>(); GridTerminalSystem.GetBlocksOfType <IMyAssembler>(assemblerList, assembler => assembler.CubeGrid == Me.CubeGrid); double thisOrder; while (buildAmount > 0) { thisOrder = Math.Min(buildAmount, batchAmount); buildAmount -= thisOrder; string assemblerName = ""; double minAmount = 1000000, thisAmount; foreach (IMyAssembler assembler in assemblerList) { thisAmount = 0; Echo($"{assembler.DisplayNameText}\n{assembler.GetType()}\n"); if (assembler.DisplayNameText == "[Base] Survival kit") { Echo("Survival Kits are gay"); } else { List <MyProductionItem> productionList = new List <MyProductionItem>(); assembler.GetQueue(productionList); foreach (MyProductionItem item in productionList) { thisAmount += (double)item.Amount; } //Echo($"ThisAmount={thisAmount}"); if (thisAmount < minAmount) { minAmount = thisAmount; assemblerName = assembler.DisplayNameText; //Echo($"Min {assemblerName}={minAmount}"); } } } IMyAssembler minAssembler = (IMyAssembler)GridTerminalSystem.GetBlockWithName(assemblerName); bool canUseBlueprint = minAssembler.CanUseBlueprint(blueprint); //Echo($"Does it assemble? {canUseBlueprint}"); if (canUseBlueprint) { minAssembler.AddQueueItem(blueprint, thisOrder); } } }
void UnClogAssembler(IMyAssembler assembler) { List <MyInventoryItem> items = new List <MyInventoryItem>(); IMyInventory assemblerInventory = assembler.InputInventory; assemblerInventory.GetItems(items, (MyInventoryItem item) => item.Amount >= ITEM_AMOUNT_THRESHOLD); items.ForEach((MyInventoryItem item) => TransferItemToAvailableInventory(item, (MyFixedPoint)(item.Amount - ITEM_AMOUNT_THRESHOLD), assemblerInventory, ContainerInventories)); }
private void SaveAndApply(IBlockConfiguration block, IMyAssembler assembler, Action <IMyAssembler> action) { if (!block.HasStyle) { block.SetStyle(nameof(IMyAssembler.Enabled), assembler.Enabled); } action(assembler); }
void ClearAssembler(IMyAssembler assembler) { ClearInventory(assembler.OutputInventory, assembler.CubeGrid); if (assembler.IsProducing) { return; } ClearInventory(assembler.InputInventory, assembler.CubeGrid); }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update10; AssemblerQueue = GridTerminalSystem.GetBlockWithName("Assembler BuildList") as IMyAssembler; WelderContainer = GridTerminalSystem.GetBlockWithName("Welder Container") as IMyCargoContainer; //This need to be change to get all invetory on welding ship, including connectors, welders and containers CargoContainers = GridTerminalSystem.GetBlockWithName("Small Cargo Container") as IMyCargoContainer; //This need to be change to exclude inventories on welding ship and take stuff from inventory at base WelderLCD = GridTerminalSystem.GetBlockWithName("LCD Welder") as IMyTextPanel; ErrorLCD = GridTerminalSystem.GetBlockWithName("LCD Error") as IMyTextPanel; }
public void DeleteTerminalValues(IMyAssembler drill) { Logger.Instance.LogDebug("DeleteTerminalValues"); var settings = m_platformSettings.FirstOrDefault((x) => x.EntityId == drill.EntityId); if (settings != null) { DrillSettings.Instance.m_platformSettings.Remove(settings); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { m_generator = Entity as IMyAssembler; m_parent = Entity as IMyCubeBlock; builder = objectBuilder; Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; terminalBlock = Entity as IMyTerminalBlock; }
bool FuncTest(IMyAssembler block) { //Assembler //Interface name: IMyAssembler //Parent: IMyProductionBlock //Parent: IMyFunctionalBlock bool UseConveyorSystem = block.UseConveyorSystem; return(true); }
public void ClearAssemblerQueue(IMyAssembler AssemblerQueue, IMyCargoContainer WelderContainer, IMyCargoContainer CargoContainers) //This clear queue in assebler and remove items from welding ship container { AssemblerQueue.ClearQueue(); for (int i = WelderContainer.GetInventory(0).ItemCount - 1; i >= 0; i--) { if (CargoContainers.GetInventory(0).CanItemsBeAdded(WelderContainer.GetInventory(0).GetItemAt(i).Value.Amount, WelderContainer.GetInventory(0).GetItemAt(i).Value.Type)) { WelderContainer.GetInventory(0).TransferItemTo(CargoContainers.GetInventory(0), WelderContainer.GetInventory(0).GetItemAt(i).Value); } } }
public DrillPlatformSetting RetrieveTerminalValues(IMyAssembler drill) { Logger.Instance.LogDebug("RetrieveTerminalValues"); var settings = m_platformSettings.FirstOrDefault((x) => x.EntityId == drill.EntityId); if (settings != null) { Logger.Instance.LogDebug("Found settings for block: " + drill.CustomName); } return(settings); }
public bool TryAttachBlock(IMyTerminalBlock block) { if (block != null && EID == block.EntityId) { Block = block as IMyAssembler; return(true); } else { return(false); } }
public void StoreTerminalValues(IMyAssembler drill) { var settings = m_platformSettings.FirstOrDefault((x) => x.EntityId == drill.EntityId); if (settings == null) { settings = new DrillPlatformSetting(); settings.EntityId = drill.EntityId; m_platformSettings.Add(settings); } settings.StoneEnabled = drill.GameLogic.GetAs <Rig>().StoneEnabled; }
/// <summary> /// Loads an assembler's queue into the Blocks dictionary. /// </summary> /// <param name="assembler"></param> public void SetBlocksFromAssembler(IMyAssembler assembler) { var queue = new List <MyProductionItem>(); assembler.GetQueue(queue); Blocks.Clear(); queue.ForEach(item => { var blueprintId = item.BlueprintId.ToString(); var amount = (int)item.Amount; Blocks.Add(blueprintId, amount); }); }
public string GetAssemblerStatus(IMyAssembler assembler) { if (assembler.IsProducing) { return(assembler.CurrentProgress + "%.\n"); } else if (assembler.IsQueueEmpty) { return(" idle.\n"); } else { return(assembler.CurrentProgress + "% - Waiting....\n"); } }
public void FindLeadAssembler() { // Echo("dbg: FindLeadAssembler()"); tempAssemblers.Clear(); GridTerminalSystem.GetBlocksOfType <IMyAssembler>(tempAssemblers, a => a.IsWorking && !a.CooperativeMode); leadAssembler = tempAssemblers.Count() > 0 ? tempAssemblers[0] : null; if (tempAssemblers.Count() > 1) { Echo($"Warning: multiple non-cooperative assemblers found: {String.Join(", ", tempAssemblers)}"); } else if (tempAssemblers.Count() == 0) { Echo($"Warning: no non-cooperative assemblers found."); return; } Echo($"Lead assembler is: {leadAssembler.CustomName}."); }
// This file contains your actual script. // // You can either keep all your code here, or you can create separate // code files to make your program easier to navigate while coding. // // In order to add a new utility class, right-click on your project, // select 'New' then 'Add Item...'. Now find the 'Space Engineers' // category under 'Visual C# Items' on the left hand side, and select // 'Utility Class' in the main area. Name it in the box below, and // press OK. This utility class will be merged in with your code when // deploying your final script. // // You can also simply create a new utility class manually, you don't // have to use the template if you don't want to. Just do so the first // time to see what a utility class looks like. // // Go to: // https://github.com/malware-dev/MDK-SE/wiki/Quick-Introduction-to-Space-Engineers-Ingame-Scripts // // to learn more about ingame scripts. 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 Runtime.UpdateFrequency // here, which will allow your script to run itself without a // timer block. string className = "[AUTO]"; BlueprintIdBaseString = "MyObjectBuilder_BlueprintDefinition/"; // Assembler List <IMyAssembler> assemblers = new List <IMyAssembler>(); GridTerminalSystem.GetBlocksOfType(assemblers); Assembler = assemblers.Find(assembler => assembler.CustomName.EndsWith(className)); Echo("Found Assembler \"" + Assembler.CustomName + "\""); // Containers Containers = new List <IMyCargoContainer>(); GridTerminalSystem.GetBlocksOfType(Containers); Containers = Containers.FindAll(container => container.CustomName.EndsWith(className)); Echo("Found " + Containers.Count.ToString() + " Containers"); // Text Panels TextPanels = new List <IMyTextPanel>(); GridTerminalSystem.GetBlocksOfType(TextPanels); TextPanels = TextPanels.FindAll(textPanel => textPanel.CustomName.EndsWith(className)); Echo("Found " + TextPanels.Count.ToString() + " Text Panels"); foreach (IMyTextPanel textPanel in TextPanels) { textPanel.ContentType = ContentType.TEXT_AND_IMAGE; Echo("Setup panel \"" + textPanel.CustomName + "\""); } // Runtime (about 1 Tick probably about 1ms) Runtime.UpdateFrequency = UpdateFrequency.Update100; }
public Program() { _buttonEnabled = new bool[2][]; _buttonEnabled[0] = new bool[9]; _buttonEnabled[1] = new bool[9]; _buttonText = new string[2][]; _buttonText[0] = new string[9]; _buttonText[1] = new string[9]; _buttonData = new PressedButton[2][]; _buttonData[0] = new PressedButton[9]; _buttonData[1] = new PressedButton[9]; _oreStatus = new MaterialStatus(); _ignotStatus = new MaterialStatus(); // Find LCD Displays if (!InitDisplays()) { Echo("ERROR ON STARTUP: LCD ERROR"); return; } // Get Blocks we care about _cockpit = GridTerminalSystem.GetBlockWithName("ACockpit") as IMyCockpit; _assembler = GridTerminalSystem.GetBlockWithName("Assembler") as IMyAssembler; _oreCargo = GridTerminalSystem.GetBlockWithName("Ore Cargo Bin") as IMyCargoContainer; _ignotCargo = GridTerminalSystem.GetBlockWithName("Ignot Cargo Bin") as IMyCargoContainer; _materialCargo = GridTerminalSystem.GetBlockWithName("Material Cargo Bin") as IMyCargoContainer; _bay1Connector = GridTerminalSystem.GetBlockWithName("Bay 1 Connector") as IMyShipConnector; _bay2Connector = GridTerminalSystem.GetBlockWithName("Bay 2 Connector") as IMyShipConnector; _bay3Connector = GridTerminalSystem.GetBlockWithName("Bay 3 Connector") as IMyShipConnector; _bay4Connector = GridTerminalSystem.GetBlockWithName("Bay 4 Connector") as IMyShipConnector; ////Runtime.UpdateFrequency = UpdateFrequency.Update100; init = true; Echo("Startup complete"); StartWizard(); }
public AssemblerInfo(string eid, string saved) { EID = long.Parse(eid); Block = null; string[] parts = saved.Split('\n'); if (parts.Length != 4) { throw new ArgumentException("Invalid saved string"); } if (!float.TryParse(parts[0], out Assembly.Current) || !float.TryParse(parts[1], out Assembly.Total) || !float.TryParse(parts[2], out Disassembly.Current) || !float.TryParse(parts[3], out Disassembly.Total) ) { Assembly.Reset(); Disassembly.Reset(); } }
/// <summary> /// Assigns the assemblers. If multiple assemblers are tagged with assemblerMasterTag only one will be used /// </summary> private void GetAssemblers() { if (!useAssemblers) { return; } //Master tempBlockList = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName(assemblerMasterTag, tempBlockList); if (tempBlockList.Count == 0) { Echo("No Tagged Assembler Found!"); return; } assemblerMaster = tempBlockList[0] as IMyAssembler; //All Assemblers tempBlockList.Clear(); GridTerminalSystem.GetBlocksOfType <IMyAssembler>(tempBlockList); }
public void Main(string argument, UpdateType updateSource) { //Create support for an ini file that contains the name of the target assembler and an optional LCD to indicate percentage as well as the id of the projector // Also create a flag for large or small grid requirements Dictionary <string, int> REQUIRED_COMPONENTS = new Dictionary <string, int>(); List <IMyProjector> LIST = new List <IMyProjector>(); GridTerminalSystem.GetBlocksOfType <IMyProjector>(LIST); assembler = GridTerminalSystem.GetBlockWithName("Basic Assembler") as IMyAssembler; if (LIST.Count == 0) { throw new Exception("Projector is required"); } // Parse detailed info from projector IMyProjector projector = LIST[0]; ProjectorDetails details = new ProjectorDetails(projector.DetailedInfo, Echo); // Convert parsed info into a list of required components foreach (String blockName in details.BlocksRemaining.Keys) { Dictionary <string, int> requiredComponentsForBlock; if (ComponentUtils.SmallShipComponentPieces.TryGetValue(blockName, out requiredComponentsForBlock)) { foreach (string componentName in requiredComponentsForBlock.Keys) { int currentAmount; REQUIRED_COMPONENTS.TryGetValue(componentName, out currentAmount); // Multiply the new required components by the total amount of that block we are needing to build currentAmount += (requiredComponentsForBlock.GetValueOrDefault(componentName) * details.BlocksRemaining[blockName]); REQUIRED_COMPONENTS[componentName] = currentAmount; } } } foreach (string k in REQUIRED_COMPONENTS.Keys) { this.AddToProduction(k, REQUIRED_COMPONENTS[k]); } }
void CleanAssembler(IMyAssembler assembler) { if (assembler.IsProducing || !IsFull(assembler.GetInventory(0))) { return; } IMyInventory containerDestination = null; // search our containers until we find an empty one for (int n = 0; n < containers.Count; n++) { var container = containers[n]; var containerInv = container.GetInventory(0); if (!IsFull(containerInv)) { Echo("Cont Dest: " + container.CustomName); containerDestination = containerInv; break; } } if (containerDestination == null) { return; } var assemblerInv = assembler.GetInventory(0); List <MyInventoryItem> assemblerItems = new List <MyInventoryItem>(); assemblerInv.GetItems(assemblerItems); for (int i = 0; i < assemblerItems.Count; i++) { Echo("Trying to move from " + assembler.CustomName); assemblerInv.TransferItemTo(containerDestination, i, null, true, null); } }
public void Main() //called each cycle //tick++; //if (tick%4 != 0) // return; { tick++; bool cancel = false; foreach (IMyShipConnector conn in connectors) { if (conn.Enabled && conn.Status == MyShipConnectorStatus.Connected) { if (shutdownWhenDockedTo(conn.DisplayName, conn.OtherConnector.DisplayName, conn.OtherConnector.CubeGrid.DisplayName)) { cancel = true; break; } } } if (cancel) { Echo("Docked to dominant grid; not managing inventories."); return; } Echo("Managing " + refineryCount + " refineries, " + assemblers.Count + " assemblers, " + oxyGenerators.Count + " O2 gens, and " + cargo.Count + " cargo containers."); if (tick % 50 == 0) { cacheSources(); } if (ENABLE_ORE_SORTING) { foreach (var entry in refineries) { Refinery r = getRandom <Refinery>(entry.Value); if (r != null && (r.refinery.Enabled || !SKIP_OFFLINE_REFINERIES)) { ICollection <string> li = r.validOres; if (ORE_PRIORITY.Length > 0) { li = applyPriorityRules(li); } foreach (string ore in li) { if (isOreValid(ore, r)) { tryMoveOre(ore, r); } } empty(r.refinery.OutputInventory); if (!SKIP_OFFLINE_REFINERIES) { r.refinery.Enabled = r.hasWork(); } } } IMyAssembler ass = getRandom <IMyAssembler>(assemblers); if (ass != null) { empty(ass.Mode == MyAssemblerMode.Disassembly ? ass.InputInventory : ass.OutputInventory); List <MyProductionItem> li = new List <MyProductionItem>(); ass.GetQueue(li); ass.Enabled = li.Count > 0 || ass.CooperativeMode || ass.BlockDefinition.SubtypeName.ToLowerInvariant().Contains("survivalkit"); } IMyGasGenerator gas = getRandom <IMyGasGenerator>(oxyGenerators); if (gas != null && (gas.Enabled || ENABLE_O2_GENS)) { tryMoveIce(gas); if (ENABLE_O2_GENS) { gas.Enabled = true; // || gas.GetInventory().ItemCount > 0; } } } if (MOVE_FROM_SMALL_TO_LARGE) { IMyCargoContainer box = getRandom <IMyCargoContainer>(cargo); if (box != null) { if (box.GetInventory().ItemCount > 0 && box.BlockDefinition.SubtypeName.ToLowerInvariant().Contains("small")) { IMyInventory inv = box.GetInventory(); empty(inv, false); //break; } } } if (tick % 5 == 0) { bool flag = false; if (ejectionWatchers.Count > 0 && usedVolume / (float)maxCapacity >= EJECTION_THRESHOLD) { foreach (ItemProfile p in ejectionWatchers) { float f = getItemFraction(p); Echo("Item type " + p.ToString() + " represents " + f * 100 + "% of items."); if (f >= EJECTION_THRESHOLD) { Echo("Ejecting excess."); tryPrepareEjection(p); flag = true; } } } if (!flag) { Echo("No excess to eject."); foreach (IMyShipConnector conn in ejectors) { conn.ThrowOut = false; } } /* * foreach (IMyShipConnector con in connectors) { * if (con.Status == MyShipConnectorStatus.Connected) { * FlowDirection flow = getActiveFlowDirection(con.CustomName, con.OtherConnector.CustomName, con.OtherConnector.CubeGrid.CustomName); * if (flow != FlowDirection.INERT) { * * } * } * }*/ } }
private void Restore(IBlockConfiguration block, IMyAssembler assembler) => assembler.Enabled = block.GetBooleanStyle(nameof(IMyAssembler.Enabled), true);
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update10; Assembler = GridTerminalSystem.GetBlockWithName("Assembler") as IMyAssembler; CompContainer = GridTerminalSystem.GetBlockWithName("Small Cargo Container") as IMyCargoContainer; }