private bool moveItem(IMyInventory src, IMyInventory tgt, MyInventoryItem item, MyFixedPoint amt) { bool ret = false; IMyRefinery prod1 = src as IMyRefinery; IMyRefinery prod2 = tgt as IMyRefinery; if (prod1 != null) { prod1.UseConveyorSystem = true; } if (prod2 != null) { prod2.UseConveyorSystem = true; } if (src.TransferItemTo(tgt, item, amt)) { //show("Moved "+amt+" of "+item.Type.SubtypeId+" from "+src.Owner.Name+" to "+tgt.Owner.Name); ret = true; } else { //show("Could not move "+item.Type.SubtypeId+" from "+src.Owner.Name+" to "+tgt.Owner.Name); ret = false; } if (prod1 != null) { prod1.UseConveyorSystem = false; } if (prod2 != null) { prod2.UseConveyorSystem = false; } return(ret); }
void ClearRefinery(IMyRefinery refinery) { for (int i = 0; i < refinery.InventoryCount; ++i) { ClearInventory(refinery.GetInventory(i), refinery.CubeGrid); } }
private void SaveAndApply(IBlockConfiguration block, IMyRefinery refinery, Action <IMyRefinery> action) { if (!block.HasStyle) { block.SetStyle(nameof(IMyRefinery.Enabled), refinery.Enabled); } action(refinery); }
public RefineryWrapper(IMyRefinery refinery) { Refinery = refinery; Inventory = refinery.GetInventory(0); var items = Inventory.GetItems(); Item = items.Count > 0 ? items[0] : null; Amount = Item != null ? (float)Item.Amount : 0.0f; }
public Refinery TryResolveRefinery(IMyRefinery block, double refinerySpeedFactor) { RefineryType type; if (refineryTypesByBlockDefinitionString.TryGetValue(block.BlockDefinition.ToString(), out type)) { return(Refinery.Get(block, type, refinerySpeedFactor)); } return(null); }
ProductionStatus GetRefineryStatus(IMyRefinery block) { if (!block.IsAlive() || !block.IsWorking) { return(ProductionStatus.Disabled); } else { return(block.IsProducing ? ProductionStatus.Producing : ProductionStatus.Waiting); } }
bool FuncTest(IMyRefinery block) { //Arc furnace //Refinery //Parent: IMyProductionBlock //Parent: IMyFunctionalBlock //Fields: bool UseConveyorSystem = block.UseConveyorSystem; return(true); }
internal Refinery(IMyRefinery imr, RefineryType type) { refinery = imr; refinery.UseConveyorSystem = false; this.type = type; switch (type) { case RefineryType.NORMAL: validOres.Add("iron"); validOres.Add("nickel"); validOres.Add("silicon"); validOres.Add("cobalt"); validOres.Add("silver"); validOres.Add("gold"); validOres.Add("uranium"); validOres.Add("platinum"); validOres.Add("magnesium"); validOres.Add("stone"); validOres.Add("scrap"); break; case RefineryType.BASIC: validOres.Add("iron"); validOres.Add("nickel"); validOres.Add("silicon"); validOres.Add("cobalt"); validOres.Add("stone"); validOres.Add("scrap"); break; case RefineryType.BLAST: validOres.Add("iron"); validOres.Add("nickel"); validOres.Add("silicon"); validOres.Add("cobalt"); validOres.Add("scrap"); break; case RefineryType.STONE: validOres.Add("stone"); break; case RefineryType.URANIUM: validOres.Add("uranium"); break; case RefineryType.PLATINUM: validOres.Add("platinum"); break; } }
float CalculateProgressForRefinery(IMyRefinery block) { if (!block.IsAlive()) { return(float.NaN); } IMyInventory inv = block.GetInventory(0); if ((double)inv.CurrentVolume > 0) { return((float)(1.0 - (double)inv.CurrentVolume / (double)inv.MaxVolume)); } else { return(float.NaN); } }
public static Refinery Get(IMyRefinery block, RefineryType type, double speedFactor) { var item = GetOrCreate(); item.block = block; item.refineSpeed = type.Speed; item.materialEfficiency = type.Efficiency; item.BlockDefinitionString = type.BlockDefinitionName; var moduleBonuses = SupportUtil.ParseModuleBonuses(block.DetailedInfo); if (moduleBonuses.Count > 0) { var speedModifier = moduleBonuses[0] - 1; // +1 Speed per 100%. item.refineSpeed += speedModifier; } if (moduleBonuses.Count > 1) { var efficiencyModifier = moduleBonuses[1]; item.materialEfficiency *= efficiencyModifier; } item.refineSpeed *= speedFactor; return(item); }
private void Restore(IBlockConfiguration block, IMyRefinery refinery) => refinery.Enabled = block.GetBooleanStyle(nameof(IMyRefinery.Enabled), true);
private void OnRefineryUpdate(ProductionBlueprintProhibitor prohibit, IMyRefinery refinery, PlayerState owner) { var refineryDef = MyDefinitionManager.Static.GetCubeBlockDefinition(refinery.BlockDefinition) as MyRefineryDefinition; if (refineryDef == null) { return; } var canBeLocked = false; foreach (var clazz in refineryDef.BlueprintClasses) { if (Manager.Definitions.Unlocks.Contains(clazz.Id)) { canBeLocked = true; break; } foreach (var sub in clazz) { if (Manager.Definitions.Unlocks.Contains(sub.Id)) { canBeLocked = true; break; } } if (canBeLocked) { break; } } if (!canBeLocked) { return; } var isLockedForOwner = owner == null || !owner.HasUnlockedAnything; foreach (var clazz in refineryDef.BlueprintClasses) { if (isLockedForOwner) { break; } isLockedForOwner |= !owner.HasUnlocked(clazz.Id); } foreach (var clazz in refineryDef.BlueprintClasses) { if (isLockedForOwner) { break; } foreach (var sub in clazz) { if (isLockedForOwner) { break; } isLockedForOwner |= !owner.HasUnlocked(sub.Id); } } if (!isLockedForOwner) { if (_wasRefineryEnabled.Remove(refinery.EntityId)) { refinery.Enabled = true; } return; } // Move first processable slot to start of inventory. // Disgusting allocation. Can we do better? Track inventory changes? Something similar? var lockEverything = false; if (owner != null) { var items = refinery.InputInventory.GetItems(); int firstUnlockedSlot; for (firstUnlockedSlot = 0; firstUnlockedSlot < items.Count; firstUnlockedSlot++) { MyBlueprintDefinitionBase blueprint = null; var id = new MyDefinitionId(items[firstUnlockedSlot].Content.TypeId, items[firstUnlockedSlot].Content.SubtypeId); foreach (var clazz in refineryDef.BlueprintClasses) { blueprint = BlueprintLookup(clazz, id); if (blueprint != null) { break; } } if (blueprint != null && owner.HasUnlocked(blueprint.Id)) { break; } } if (firstUnlockedSlot >= items.Count) { lockEverything = true; } else if (firstUnlockedSlot > 0) { var amount = items[firstUnlockedSlot].Amount; var content = items[firstUnlockedSlot].Content as MyObjectBuilder_PhysicalObject; if (content == null) { lockEverything = true; } else { refinery.InputInventory.RemoveItemsAt(firstUnlockedSlot); refinery.InputInventory.AddItems(amount, content, 0); } } } else { lockEverything = true; } if (lockEverything) { if (refinery.Enabled) { _wasRefineryEnabled.Add(refinery.EntityId); refinery.Enabled = false; } } else if (_wasRefineryEnabled.Remove(refinery.EntityId)) { refinery.Enabled = true; } }
void Initialize() // Handles the initialization of blocks. Is run at the end of each loop to ensure everything is there. { inventories.Clear(); // This must be done to avoid memory leaks. refineries.Clear(); furnaces.Clear(); assemblers.Clear(); reactors.Clear(); gasGenerators.Clear(); gatlings.Clear(); missileLaunchers.Clear(); lcds.Clear(); if (!Me.CustomName.ToLower().Contains(TAG.ToLower())) // If we have no tag at all. { Me.CustomName += " " + TAG; // Add a tag. }// else if (!Me.CustomName.Contains(TAG)) // We know we have a tag, but run this when the tag isn't exactly equal. { string customName = Me.CustomName; // Replacing the incorrect tag with the proper version. int index = customName.ToLower().IndexOf(TAG.ToLower()); customName = customName.Remove(index, TAG.Length); customName = customName.Insert(index, TAG); Me.CustomName = customName; }// GridTerminalSystem.SearchBlocksOfName(TAG, blocks); foreach (IMyTerminalBlock block in blocks) { if (!block.CustomName.Contains(TAG))// If the tag doesn't match up exactly, correct the tag. { string customName = block.CustomName; int index = customName.ToLower().IndexOf(TAG.ToLower()); customName = customName.Remove(index, TAG.Length); customName = customName.Insert(index, TAG); block.CustomName = customName; }// IMyRefinery refinery = block as IMyRefinery;// This will return null if the block isn't a refinery block. if (refinery != null) { if (refinery.BlockDefinition.SubtypeId.Equals(FURNACE_TYPE_ID))// Both Refinieries and Arc Furnaces are refineries. Seperate them by subtype. { furnaces.Add(refinery); } else { refineries.Add(refinery); } continue; }// IMyAssembler assembler = block as IMyAssembler; if (assembler != null) { assemblers.Add(assembler); continue; }// IMyReactor reactor = block as IMyReactor; if (reactor != null) { reactors.Add(reactor); continue; }// IMyGasGenerator gasGenerator = block as IMyGasGenerator; if (gasGenerator != null) { gasGenerators.Add(gasGenerator); continue; }// IMyLargeGatlingTurret gatlingTurret = block as IMyLargeGatlingTurret; IMySmallGatlingGun gatlingGun = block as IMySmallGatlingGun; if ((gatlingTurret != null) | (gatlingGun != null)) { gatlings.Add(block); continue; }// IMyLargeMissileTurret missileTurret = block as IMyLargeMissileTurret; IMySmallMissileLauncherReload smallLauncherReload = block as IMySmallMissileLauncherReload; if ((missileTurret != null) | (smallLauncherReload != null)) { missileLaunchers.Add(block); continue; }// IMySmallMissileLauncher missileLauncher = block as IMySmallMissileLauncher; if ((missileLauncher != null) & (block.BlockDefinition.SubtypeId.Equals("LargeMissileLauncher"))) { missileLaunchers.Add(block); continue; }// IMyProgrammableBlock programmableBlock = block as IMyProgrammableBlock; if (programmableBlock != null) { if (!programmableBlock.Equals(Me) & programmableBlock.IsWorking) // If the programmable block isn't the one running this instance and it is working. { if (programmableBlock.CustomName.ToLower().Contains(CONNECTED_PB_TAG.ToLower())) // Check if it has the connected PB tag. { if (!programmableBlock.CustomName.Contains(CONNECTED_PB_TAG)) { string customName = programmableBlock.CustomName; int index = customName.ToLower().IndexOf(CONNECTED_PB_TAG.ToLower()); customName = customName.Remove(index, CONNECTED_PB_TAG.Length); customName = customName.Insert(index, CONNECTED_PB_TAG); programmableBlock.CustomName = customName; }// connectedPBs.Add(programmableBlock); continue; } // else // Assume this PB is running the same script. { if (programmableBlock.CubeGrid.EntityId == Me.CubeGrid.EntityId) { Echo("ERROR: MORE THAN ONE IAN ON ONE GRID"); active = false;// Both PBs will disable themselves and show an error. continue; }// else if (programmableBlock.CubeGrid.GridSize > Me.CubeGrid.GridSize)// The PB with the biggest grid size will be dominant. { active = false; continue; } active = true;// None of the exceptions have occured, so we are free to resume functioning. This will ensure IAN plays nice with it's double. continue; }// } // } // IMyTextPanel panel = block as IMyTextPanel; if (panel != null) { lcds.Add(panel); } } // } //