void TanksStockpile(bool bStockPile = true, int iTypes = 0xff) { if (tankList.Count < 1) { tanksInit(); } if (tankList.Count < 1) { return; } for (int i = 0; i < tankList.Count; ++i) { int iTankType = tankType(tankList[i]); if ((iTankType & iTypes) > 0) { IMyGasTank tank = tankList[i] as IMyGasTank; if (tank == null) { continue; // not a tank } tank.Stockpile = bStockPile; } } }
public double tanksFill(int iTypes = 0xff) { // if (tankList.Count < 1) tanksInit(); if (tankList.Count < 1) { return(-1); } double totalLevel = 0; int iTanksCount = 0; for (int i = 0; i < tankList.Count; ++i) { int iTankType = TankType(tankList[i]); if ((iTankType & iTypes) > 0) { IMyGasTank tank = tankList[i] as IMyGasTank; if (tank == null) { continue; // not a tank } var tankLevel = tank.FilledRatio; totalLevel += tankLevel; iTanksCount++; } } if (iTanksCount > 0) { return(totalLevel / iTanksCount); } else { return(-1); } }
public double TanksFill(List <IMyTerminalBlock> tankList) { double totalPercent = 0; int iTanksCount = 0; for (int i = 0; i < tankList.Count; ++i) { // int iTankType = tankType(tankList[i]); // if ((iTankType & iTypes) > 0) { IMyGasTank tank = tankList[i] as IMyGasTank; if (tank == null) { continue; // not a tank } float tankLevel = (float)tank.FilledRatio; totalPercent += tankLevel; iTanksCount++; } } if (iTanksCount > 0) { return(totalPercent * 100 / iTanksCount); } else { return(0); } }
public TankSnapshot(IMyTerminalBlock block) { Tank = (IMyGasTank)block; Amount = 0; var sink = Tank.Components.Get <MyResourceSinkComponent>(); type = sink.AcceptedResources.Contains(Oxygen) ? Oxygen : Hydrogen; }
public GasTank(IMyGasTank gasTank) { MyGasTank = gasTank; if (!Enum.TryParse(gasTank.Components.Get <MyResourceSourceComponent>() .ResourceTypes[0].SubtypeName, out MyGasType)) { throw new Exception("Unknown gas type"); } }
List <IMyFunctionalBlock> Everything; // Now this.... This is an Absolute Madness void GetNeededBlocks() { List <IMyFunctionalBlock> temp = new List <IMyFunctionalBlock>(); GridTerminalSystem.GetBlocksOfType(temp); Power = new List <IMyPowerProducer>(); Batteries = new List <IMyBatteryBlock>(); Reactors = new List <IMyReactor>(); Producers = new List <IMyProductionBlock>(); Tanks = new List <IMyGasTank>(); Everything = new List <IMyFunctionalBlock>(); foreach (IMyFunctionalBlock block in temp) { if (isOnThisGrid(block)) { Everything.Add(block); if (block is IMyPowerProducer) { IMyPowerProducer power = (IMyPowerProducer)block; Power.Add(power); if (block is IMyBatteryBlock) { IMyBatteryBlock battery = (IMyBatteryBlock)block; Batteries.Add(battery); } else if (block is IMyReactor) { IMyReactor reactor = (IMyReactor)block; Reactors.Add(reactor); } } else if (block is IMyProductionBlock) { IMyProductionBlock producer = (IMyProductionBlock)block; Producers.Add(producer); } else if (block is IMyGasTank) { IMyGasTank tank = (IMyGasTank)block; if (tank.BlockDefinition.SubtypeName.Contains("HydrogenTank")) { Tanks.Add(tank); } } } } }
public void Refresh(OutputPanel _lcd, AlignModule _align, IMyShipController _sc = null) { lcd = _lcd; align = _align; sc = _sc ?? Pgm.GetShipController(MultiMix_UsedBlocks); RefreshThrustsList(_align?.RocketMode ?? false); hydrogenTanks.Clear(); if (null != downCamera) { downCamera.EnableRaycast = false; } downCamera = null; parachute = null; IMyGasTank hb = null; IMyBatteryBlock bb = null; IMyCameraBlock cb = null; IMyParachute pb = null; GatherBlocks(Pgm , a => SameGrid(Me, a) && !NameContains(a, MultiMix_IgnoreBlocks) , b => { if (ToType(b, ref hb) && hb.IsWorking && SubtypeContains(hb, "Hydrogen")) { hydrogenTanks.Add(hb); return(false); } return(true); } , c => { if (ToType(c, ref bb) && bb.IsWorking) { batteries.Add(bb); return(false); } return(true); } , d => { if (ToType(d, ref cb) && cb.IsWorking && NameContains(cb, "Down")) { downCamera = cb; cb.EnableRaycast = true; return(false); } return(true); } , e => { if (ToType(e, ref pb) && pb.IsWorking) { parachute = pb; return(false); } return(true); } ); if (null == stateMachine) { SetRunState(false); } }
private bool TryGetOxygenTank(IMyTerminalBlock block, out IMyGasTank tank) { tank = block as IMyGasTank; if (tank == null) { return(false); } if (tank.BlockDefinition.SubtypeId.Contains("Hydrogen")) { return(false); } return(true); }
public Store(IMyGasTank gasTank, string description = "") : base(description) { // <Capacity> switch (gasTank.BlockDefinition.SubtypeId) { case "OxygenTankSmall": Max = 50.000f; break; case "LargeHydrogenTank": Max = 5000.000f; break; case "SmallHydrogenTank": Max = 160.000f; break; default: Max = 100.000f; break; // LargeOxygenTank } Current = Max * (float)gasTank.FilledRatio; DefaultUnit = "kL"; }
string parseTanks(List <IMyGasTank> tanks, string title) { string rtn = ""; float capacity = 0; double filled = 0; for (int i = 0; i < tanks.Count; i++) { IMyGasTank tank = tanks[i]; capacity += tank.Capacity; filled += tank.FilledRatio * tank.Capacity; } string msg = "{0}: \n{3} {1:00.00}/{2:00.00} ML\n"; string prog = Utilities.progressBar(filled, capacity); rtn += string.Format(msg, title, filled / 1e6, capacity / 1e6, prog); return(rtn); }
public static GasType GetContentType(IMyGasTank tank) { MyResourceSinkComponent sinkComponent; if (tank.Components.TryGet(out sinkComponent)) { var resources = sinkComponent.AcceptedResources; if (resources.Contains(Hydrogen)) { return(GasType.Hydrogen); } if (resources.Contains(Oxygen)) { return(GasType.Oxygen); } } return(GasType.None); }
public static bool IsValidGasConnection(MyCubeBlock factoryBlock, IMyGasTank gasTank) { try { if (gasTank == null || gasTank.GetInventory() == null || !((IMyInventory)factoryBlock.GetInventory()).IsConnectedTo(gasTank.GetInventory()) || !MyRelationsBetweenPlayerAndBlockExtensions.IsFriendly(factoryBlock.GetUserRelationToOwner(gasTank.OwnerId))) { return(false); } return(true); } catch (Exception e) { Logging.Instance.WriteLine($"IsValidGasConnection exception:\n{e}."); return(false); } }
private String WriteOutput(IMyGasTank pTank) { String output = ""; output += pTank.DisplayNameText; // underline this shit output += "\n" + new string('=', pTank.DisplayNameText.Length) + "\n\n"; output += "Level:\n"; output += " " + Math.Round((pTank.Capacity * pTank.FilledRatio) / 1000, 1).ToString("0000.0") + "m^3 (" + Math.Round(pTank.FilledRatio * 100, 1).ToString("000.0") + "%)\nCapacity\n"; output += " " + Math.Round(pTank.Capacity / 1000, 1).ToString("0000.0") + "m^3\n\n"; return(output); }
public override void UpdateAfterSimulation10() { base.UpdateAfterSimulation10(); bool running = shouldUsePower(); if (running) { //check for gas; if has gas, make "internal processable" item which the centrifuge can refine to ore; try to move it there if possible //appears to be impossible to take gas from the tank; what about secret bottle refilling? IMyGasTank tank = thisBlock as IMyGasTank; IMyInventory inv = tank.GetInventory(); List <MyInventoryItem> li = new List <MyInventoryItem>(); inv.GetItems(li, isFullUraniumBottle); } else { } sync(); thisBlock.RefreshCustomInfo(); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { // this method is called async! always do stuff in the first update unless you're sure it must be in this one. // NOTE the objectBuilder arg is not the Entity's but the component's, and since the component wasn't loaded from an OB that means it's always null, which it is (AFAIK). block = (IMyGasTank)Entity; if (MyAPIGateway.Multiplayer.IsServer) { NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; // allow UpdateOnceBeforeFrame() to execute, remove if not needed addedMass = AddedMassInventory.SetupFor(block); var tankType = block.DefinitionDisplayNameText; if (tankType.Contains("Hydrogen")) { gasKgPerL = 0.071f; } if (tankType.Contains("Oxygen")) { gasKgPerL = 1.140f; } } }
public void Main(string argument, UpdateType updateSource) { IMyGasTank oxygenTank = GridTerminalSystem.GetBlockWithName("Oxygen Tank") as IMyGasTank; IMyBlockGroup oxygenFarmGroup = GridTerminalSystem.GetBlockGroupWithName("Oxygen Farms"); List <IMyOxygenFarm> oxygenFarms = new List <IMyOxygenFarm>(); oxygenFarmGroup.GetBlocksOfType(oxygenFarms); float generating = 0.0f; if (oxygenTank.FilledRatio < 0.9f) { oxygenFarms.ForEach((IMyOxygenFarm farm) => { if (_on == false) { farm.ApplyAction("OnOff_On"); } generating += farm.GetOutput(); }); _on = true; } else { if (_on == true) { oxygenFarms.ForEach((IMyOxygenFarm farm) => { farm.ApplyAction("OnOff_Off"); }); _on = false; } } _PanelTextSurface.WriteText(String.Format( "Oxygen: {0:0.000}\nFarms {1}\nGenerating: {2}", oxygenTank.FilledRatio, _on ? "Enabled" : "Disabled", generating )); }
public bool UpdateStock(Dictionary <MyItemType, ItemTypeDescriptor> stock) { ClearStock(stock); if (Alive) { Amount = Tank.Capacity * Tank.FilledRatio; if (stock.ContainsKey(type)) { stock[type].Amount += Amount; } else { stock[type] = new ItemTypeDescriptor(type, Amount); } return(true); } else { Tank = null; Amount = 0; return(false); } }
private double GetStockpiledOxygen(List <IMyTerminalBlock> oxyTanks = null) { double result = 0; int count = 0; var source = oxyTanks ?? new List <IMyTerminalBlock>(); if (oxyTanks == null) { GridTerminalSystem.GetBlocksOfType <IMyGasTank>(source); } for (int i = 0; i < source.Count; i++) { IMyGasTank oxygenTank = source[i] as IMyGasTank; if (oxygenTank == null) { continue; } result += oxygenTank.FilledRatio; count++; } return(count != 0 ? result / count : 0); }
public static float GetTankFill(IMyGasTank block) { return((float)(block.FilledRatio * block.Capacity)); }
public static bool IsHydrogenTank(IMyGasTank block) { return(block.BlockDefinition.SubtypeId.ToString().Contains(SUBTYPEID_HYDROGEN_TANK)); }
public static bool IsOxygenTank(IMyGasTank block) { return(block.BlockDefinition.TypeId.ToString() == TYPEID_OXYGEN_TANK); }
private void SortAndCount() { oxStor = 0; oxCap = 0; hyStor = 0; hyCap = 0; naStor = 0; naCap = 0; foreach (Mineral m in mineralList) { m.ResetAmount(); } foreach (Component c in componentList) { c.Amount = 0; } iceAmount = 0; assemblers.Clear(); List <IMyInventory> storage = new List <IMyInventory>(); List <IMyCargoContainer> cargos = new List <IMyCargoContainer>(); GridTerminalSystem.GetBlocksOfType <IMyCargoContainer>(cargos); foreach (IMyCargoContainer car in cargos) { if (car.CustomData.Contains("MainStorage")) { storage.Add(car.GetInventory(0)); } } var blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName("", blocks); foreach (var b in blocks) { if (b.CustomData.Contains(gridCallingCard) && b.HasInventory) { if (b.CustomData.Contains("MainStorage")) { continue; } if (b.GetType().Name == "MyAssembler") { assemblers.Add((IMyAssembler)b); SortInventory(b.GetInventory(1), storage); CountInventory(b.GetInventory(0)); CountInventory(b.GetInventory(1)); continue; } if (b.GetType().Name == "MyRefinery") { SortInventory(b.GetInventory(1), storage); CountInventory(b.GetInventory(0)); CountInventory(b.GetInventory(1)); continue; } if (b.GetType().Name == "MyGasTank") { IMyGasTank t = (IMyGasTank)b; if (t.Capacity == oxygenTankMaxCapaxity) { oxStor += t.FilledRatio * t.Capacity; oxCap += t.Capacity; } else if (t.Capacity == hydrogenTankMaxCapaxity) { hyStor += t.FilledRatio * t.Capacity; hyCap += t.Capacity; } else { naStor += t.FilledRatio * t.Capacity; naCap += t.Capacity; } } for (int i = 0; i < b.InventoryCount; i++) { SortInventory(b.GetInventory(i), storage); CountInventory(b.GetInventory(i)); } } } foreach (IMyInventory inv in storage) { CountInventory(inv); } }
private static bool CanAcceptResource(IMyGasTank block, MyDefinitionId defId) { MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); return(sink != null ? sink.AcceptedResources.Any(r => r == defId) : false); }
protected override void OnExecuting(IMyGasTank gasTank) => gasTank.Stockpile = false;
public static bool TotallyNotEitherAHydrogenTankOrAOxygenTankWTF(IMyGasTank tank) { GetContentType(tank) == GasType.None; }
public void Add(IMyGasTank gasTank) { gasTankList.Add(gasTank); }
public GasTanksManager(IMyGasTank gasTank) { gasTankList = new List <IMyGasTank>(); Add(gasTank); }
public static bool IsOxygenTank(IMyGasTank tank) { GetContentType(tank) == GasType.Oxygen; }
public void Remove(IMyGasTank gasTank) { gasTankList.Remove(gasTank); }
private void CountStock() { oxStor = 0; oxCap = 0; hyStor = 0; hyCap = 0; naStor = 0; naCap = 0; foreach (Mineral m in minerals) { m.ResetAmount(); } foreach (Component c in components) { c.Amount = 0; } iceAmount = 0; var blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.SearchBlocksOfName("", blocks); foreach (var b in blocks) { if (b.HasInventory) { for (int i = 0; i < b.InventoryCount; i++) { IMyInventory inv = b.GetInventory(i); if (inv.GetItems().Count > 0) { for (int j = 0; inv.GetItems().Count > j; j++) { if ("" + inv.GetItems()[j].GetDefinitionId() == "MyObjectBuilder_Ore/Ice") { float y = 0; float.TryParse("" + inv.GetItems()[j].Amount, out y); iceAmount += y; continue; } foreach (Mineral m in minerals) { if ("" + inv.GetItems()[j].GetDefinitionId() == m.IngotId) { float y = 0; float.TryParse("" + inv.GetItems()[j].Amount, out y); m.IngotAmount += y; break; } if ("" + inv.GetItems()[j].GetDefinitionId() == m.OreId) { float y = 0; float.TryParse("" + inv.GetItems()[j].Amount, out y); m.OreAmount += y; break; } } foreach (Component c in components) { if ("" + inv.GetItems()[j].GetDefinitionId() == c.Id) { float y = 0; float.TryParse("" + inv.GetItems()[j].Amount, out y); c.Amount += y; break; } } } } } } if (b.GetType().Name == "MyGasTank") { IMyGasTank t = (IMyGasTank)b; if (t.Capacity == smallOxygenTankMaxCapaxity || t.Capacity == largeOxygenTankMaxCapaxity) { oxStor += t.FilledRatio * t.Capacity; oxCap += t.Capacity; } else if (t.Capacity == smallHydrogenTankMaxCapaxity || t.Capacity == largeHydrogenTankMaxCapaxity) { hyStor += t.FilledRatio * t.Capacity; hyCap += t.Capacity; } else { naStor += t.FilledRatio * t.Capacity; naCap += t.Capacity; } } } }