public void RemoveProducer(IMyPowerProducer producer) { Debug.Assert(producer != null); Debug.Assert(GetProducers(producer.Group).Contains(producer)); GetProducers(producer.Group).Remove(producer); --m_producerCount; m_needsRecompute = true; m_remainingFuelTimeDirty = true; producer.MaxPowerOutputChanged -= producer_MaxPowerOutputChanged; producer.HasCapacityRemainingChanged -= producer_HasRemainingCapacityChanged; if (m_producerCount == 0) { m_producersEnabled = MyMultipleEnabledEnum.NoObjects; } else if (m_producerCount == 1) { ChangeProducersState((GetFirstProducer().Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled, MySession.LocalPlayerId); } else if (ProducersEnabled == MyMultipleEnabledEnum.Mixed) { // We were in mixed state and need to check whether we still are. m_producersEnabledDirty = true; } }
public override void SetBlock(SuperBlock block) { IMyTerminalBlock tblock = block.TBlock; this.block = block; if (tblock.ResourceSink != null || tblock is IMyPowerProducer || tblock is IMyFunctionalBlock) { resourceId = MyDefinitionId.FromContent(block.TBlock.SlimBlock.GetObjectBuilder()); sink = tblock.ResourceSink; powerProducer = tblock as IMyPowerProducer; functionalBlock = tblock as IMyFunctionalBlock; if (sink != null || powerProducer != null) { SubtypeId |= TBlockSubtypes.Powered; } if (functionalBlock != null) { SubtypeId |= TBlockSubtypes.Functional; } block.SubtypeId |= SubtypeId; block.subtypeAccessors.Add(this); } }
// END // ============================================================================================================================ public override void Init(MyObjectBuilder_EntityBase objectBuilder) { block = (IMyReactor)Entity; powerBlock = (IMyPowerProducer)block; NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME; }
void AddPowerCapacityToGeneratorBlockName(IMyPowerProducer generator) { float availablePower = 100f; if (generator is IMyBatteryBlock) { var storedPower = (generator as IMyBatteryBlock).CurrentStoredPower; var maxPower = (generator as IMyBatteryBlock).MaxStoredPower; availablePower = storedPower / maxPower * 100; } else if (generator is IMySolarPanel) { availablePower = (generator as IMySolarPanel).MaxOutput / 0.160f * 100; } if (!generator.IsWorking) { availablePower = 0; } var idx = generator.CustomName.Trim().LastIndexOf('['); if (idx == -1) { idx = generator.CustomName.Count(); } generator.CustomName = string.Format("{0} [{1}%]", generator.CustomName.Substring(0, idx).Trim(), Math.Round(availablePower).ToString()); }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update10; _solar1 = GridTerminalSystem.GetBlockWithName("s1") as IMyPowerProducer; _solar2 = GridTerminalSystem.GetBlockWithName("s2") as IMyPowerProducer; _solar3 = GridTerminalSystem.GetBlockWithName("s3") as IMyPowerProducer; _solar4 = GridTerminalSystem.GetBlockWithName("s4") as IMyPowerProducer; _display1 = GridTerminalSystem.GetBlockWithName("display1") as IMyTextPanel; _display2 = GridTerminalSystem.GetBlockWithName("display2") as IMyTextPanel; _displayPower = GridTerminalSystem.GetBlockWithName("display-power") as IMyTextPanel; batteryInfo = new Dictionary <string, FixedSizedQueue <double> >(); batteryInfo["currentPower"] = new FixedSizedQueue <double>(5); batteryInfo["maxPower"] = new FixedSizedQueue <double>(1); batteryInfo["currentInput"] = new FixedSizedQueue <double>(20); batteryInfo["currentOutput"] = new FixedSizedQueue <double>(50); batteryInfo["currentNet"] = new FixedSizedQueue <double>(50); inventoryStats = new Dictionary <string, string>(); inventoryDisplayMapping = new Dictionary <string, IMyTextPanel>(); inventoryDisplayMapping["MyObjectBuilder_Ore"] = GridTerminalSystem.GetBlockWithName("display_ore") as IMyTextPanel; inventoryDisplayMapping["MyObjectBuilder_Ingot"] = GridTerminalSystem.GetBlockWithName("display_ingot") as IMyTextPanel; inventoryDisplayMapping["MyObjectBuilder_Component"] = GridTerminalSystem.GetBlockWithName("display_comp") as IMyTextPanel; tempItemList = new List <MyInventoryItem>(); buildingItemTypes = new[] { "Ore", "Ingot", "Component" }; _logText = new FixedSizedQueue <string>(15); }
public Efficiency(IMyPowerProducer powerProcuder, string description = "") : base(description) { Current = powerProcuder.MaxOutput; // <MaxPowerOutput> switch (powerProcuder.BlockDefinition.SubtypeId) { case "LargeBlockBatteryBlock": Max = 12.0f; break; case "SmallBlockBatteryBlock": Max = 4.0f; break; case "SmallBlockSmallBatteryBlock": Max = 0.05f; break; case "SmallBlockSmallGenerator": Max = 0.5f; break; case "SmallBlockLargeGenerator": Max = 14.75f; break; case "LargeBlockSmallGenerator": Max = 15.0f; break; case "LargeBlockLargeGenerator": Max = 300.0f; break; case "LargeHydrogenEngine": Max = 5.0f; break; case "SmallHydrogenEngine": Max = 0.5f; break; case "LargeBlockSolarPanel": Max = 0.16f; break; case "SmallBlockSolarPanel": Max = 0.04f; break; case "LargeBlockWindTurbine": Max = 0.4f; break; } }
public void AddProducer(IMyPowerProducer producer) { Debug.Assert(producer != null); Debug.Assert(!GetProducers(producer.Group).Contains(producer)); Debug.Assert(MatchesInfiniteCapacity(GetProducers(producer.Group), producer), "All producers in the same group must have same 'infinite capacity' state."); if (GetProducers(producer.Group).Contains(producer)) { return; } GetProducers(producer.Group).Add(producer); ++m_producerCount; m_needsRecompute = true; m_remainingFuelTimeDirty = true; producer.HasCapacityRemainingChanged += producer_HasRemainingCapacityChanged; producer.MaxPowerOutputChanged += producer_MaxPowerOutputChanged; if (m_producerCount == 1) { // This is the only producer we have, so the state of all is the same as of this one. m_producersEnabled = (producer.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled; } else if ((ProducersEnabled == MyMultipleEnabledEnum.AllEnabled && !producer.Enabled) || (ProducersEnabled == MyMultipleEnabledEnum.AllDisabled && producer.Enabled)) { m_producersEnabled = MyMultipleEnabledEnum.Mixed; } }
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 = (IMyPowerProducer)Entity; if (MyAPIGateway.Multiplayer.IsServer) { NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME; // allow UpdateOnceBeforeFrame() to execute, remove if not needed } var inv = (MyInventory)block.GetInventory(); //if(inv == null) //{ // inv = new MyInventory(); // block.Components.Add(inv); //} MyLog.Default.WriteLine($"got inventory {block.HasInventory} {inv} {inv == null}"); MyLog.Default.WriteLine($"got Constraint {inv.Constraint} {inv.Constraint == null}"); inv.Constraint.Add(new MyDefinitionId(typeof(MyObjectBuilder_Ore), "Ice")); MyLog.Default.WriteLine("add constraint"); }
public override void Reset() { base.Reset(); resourceId = default(MyDefinitionId); sink = null; powerProducer = null; functionalBlock = null; }
public static MyPowerProductionItemRenderer Find(IMyGridTerminalSystem gts, string name) { IMyPowerProducer powerProducer = gts.GetBlockWithName(name) as IMyPowerProducer; if (powerProducer == null) { return(null); } return(new MyPowerProductionItemRenderer(powerProducer)); }
private bool MatchesInfiniteCapacity(HashSet <IMyPowerProducer> group, IMyPowerProducer producer) { foreach (var member in group) { if (producer.IsInfiniteCapacity() != member.IsInfiniteCapacity()) { return(false); } } return(true); }
private string GetType(IMyPowerProducer producer) { string typeString = producer.BlockDefinition.TypeIdString; if (typeString.StartsWith("MyObjectBuilder_")) { return(typeString.Substring("MyObjectBuilder_".Length)); } return(typeString); }
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); } } } } }
private void producer_MaxPowerOutputChanged(IMyPowerProducer obj) { m_needsRecompute = true; m_remainingFuelTimeDirty = true; m_producersEnabledDirty = true; // Don't wait for next update with few producers. // Also ensures that when character enters cockpit, his battery is // turned off right away without waiting for update. if (m_producerCount == 1) { RecomputePowerDistribution(); } }
public static float GetHydrogenEngineFuelLevel(IMyPowerProducer hydrogenEngine) { string filledLine = ExtractData("Filled: ", hydrogenEngine.DetailedInfo); string[] fillValues = ExtractData(" (", filledLine).TrimEnd(')').Replace("L", string.Empty).Split('/'); if (fillValues.Length != 2) { return(0.0f); } float filled = float.Parse(fillValues[0]); float max = float.Parse(fillValues[1]); return(filled / max); }
public SunTracker(IMyGridTerminalSystem terminal, string solarPanelName, string rotor1Name, string rotor2Name, System.Action <string> echo) { Error = false; trackingState = TrackingState.Sleep; this.echo = echo; solarPanel = terminal.GetBlockWithName(solarPanelName) as IMyPowerProducer; rotor1 = terminal.GetBlockWithName(rotor1Name) as IMyMotorStator; rotor2 = terminal.GetBlockWithName(rotor2Name) as IMyMotorStator; if (solarPanel == null) { echo("Unable to locate solar panel: " + solarPanelName); Error = true; } if (rotor1 == null) { echo("Unable to locate rotor: " + rotor1Name); Error = true; } if (!solarPanel.IsFunctional) { echo("Solar panel is not functional"); Error = true; } if (!rotor1.IsFunctional) { echo("Rotor is not functional"); Error = true; } if (rotor2 != null && !rotor2.IsFunctional) { echo("Rotor is not functional"); Error = true; return; } bestPower = currentPower; rotor1.TargetVelocityRPM = 0; if (rotor2 != null) { rotor2.TargetVelocityRPM = 0; } sleepWaitCount = waitForSleep - 1; }
public Program() { //_PanelTextSurface = Me.GetSurface(0); _PanelTextSurface = GridTerminalSystem.GetBlockWithName("Transparent LCD") as IMyTextSurface; _PanelTextSurface.ContentType = VRage.Game.GUI.TextPanel.ContentType.TEXT_AND_IMAGE; _PanelTextSurface.FontSize = 2; _PanelTextSurface.Alignment = VRage.Game.GUI.TextPanel.TextAlignment.CENTER; Runtime.UpdateFrequency = UpdateFrequency.Update100; _Batteries = new List <IMyBatteryBlock>(); GridTerminalSystem.GetBlocksOfType(_Batteries); _Engine = GridTerminalSystem.GetBlockWithName("Hydrogen Engine") as IMyPowerProducer; _Engine.Enabled = false; }
public SunTracker(IMyPowerProducer sp, IMyMotorStator r1, IMyMotorStator r2, System.Action <string> echo) { trackingState = TrackingState.Sleep; this.echo = echo; solarPanel = sp; rotor1 = r1; rotor2 = r2; bestPower = currentPower; rotor1.TargetVelocityRPM = 0; if (rotor2 != null) { rotor2.TargetVelocityRPM = 0; } sleepWaitCount = waitForSleep - 1; }
public void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState, long playerId) { if (Sync.IsServer) { foreach (MyCubeBlock block in this.CubeGrid.GetFatBlocks()) { IMyPowerProducer producer = block as IMyPowerProducer; if ((producer != null) && (((playerId >= 0L) && ((MyFunctionalBlock)block).HasPlayerAccess(playerId)) || (playerId == -1L))) { producer.Enabled = enabledState == MyMultipleEnabledEnum.AllEnabled; } } } if (this.ResourceDistributor != null) { this.ResourceDistributor.ChangeSourcesState(MyResourceDistributorComponent.ElectricityId, enabledState, playerId); } this.CubeGrid.ActivatePhysics(); }
public Store(IMyPowerProducer producer, string description = "") : base(description) { if (producer.BlockDefinition.SubtypeId.Contains("HydrogenEngine")) { var textLines = producer.DetailedInfo.Split('\n'); foreach (string text in textLines) { if (text.Contains("Filled:")) { int i = 0, j; j = text.IndexOf('(', i); if (j == -1) { return; } i = j + 1; j = text.IndexOf('L', i); if (j == -1) { return; } Current = float.Parse(text.Substring(i, j - i)) * 0.001f; i = j + 2; // "L/" j = text.IndexOf('L', i); if (j == -1) { return; } Max = float.Parse(text.Substring(i, j - i)) * 0.001f; return; } } DefaultUnit = "kL"; } }
public virtual float getMaxGeneration() { if (block is IMyReactor) { return((block as IMyReactor).MaxOutput); } else if (block is IMyPowerProducer) { IMyPowerProducer pro = (IMyPowerProducer)block; bool flag = pro.Enabled; pro.Enabled = true; float ret = pro.MaxOutput; pro.Enabled = flag; return(ret); } else { return(0); } }
public void AddProducer(IMyPowerProducer producer) { Debug.Assert(producer != null); Debug.Assert(!GetProducers(producer.Group).Contains(producer)); Debug.Assert(MatchesInfiniteCapacity(GetProducers(producer.Group), producer), "All producers in the same group must have same 'infinite capacity' state."); if (GetProducers(producer.Group).Contains(producer)) return; GetProducers(producer.Group).Add(producer); ++m_producerCount; m_needsRecompute = true; m_remainingFuelTimeDirty = true; producer.HasCapacityRemainingChanged += producer_HasRemainingCapacityChanged; producer.MaxPowerOutputChanged += producer_MaxPowerOutputChanged; if (m_producerCount == 1) { // This is the only producer we have, so the state of all is the same as of this one. m_producersEnabled = (producer.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled; } else if ((ProducersEnabled == MyMultipleEnabledEnum.AllEnabled && !producer.Enabled) || (ProducersEnabled == MyMultipleEnabledEnum.AllDisabled && producer.Enabled)) { m_producersEnabled = MyMultipleEnabledEnum.Mixed; } }
private void producer_HasRemainingCapacityChanged(IMyPowerProducer producer) { m_needsRecompute = true; m_remainingFuelTimeDirty = true; }
public static string GetWindTurbineClearance(IMyPowerProducer block) { return(ExtractData("Wind Clearance: ", block.DetailedInfo)); }
private bool ValidatePowerProducer(IMyPowerProducer powerProducer) { //Check for the type of power producer required. //Reactors, Solar Panels, Hydrogen Engines, etc. return(powerProducer.BlockDefinition.SubtypeId == "LargeHydrogenEngine"); }
public static float OptimalMaxOutput(this IMyPowerProducer powerBlock) => powerBlock.Components.Get <MyResourceSourceComponent>().DefinedOutput;
public Output(IMyPowerProducer powerProcuder, string description = "") : base(description) { Current = powerProcuder.CurrentOutput; Max = powerProcuder.MaxOutput; }
public static bool IsInfiniteCapacity(this IMyPowerProducer self) { return(float.IsInfinity(self.RemainingCapacity)); }
private void producer_MaxPowerOutputChanged(IMyPowerProducer obj) { m_needsRecompute = true; m_remainingFuelTimeDirty = true; m_producersEnabledDirty = true; // Don't wait for next update with few producers. // Also ensures that when character enters cockpit, his battery is // turned off right away without waiting for update. if (m_producerCount == 1) RecomputePowerDistribution(); }
private bool MatchesInfiniteCapacity(HashSet<IMyPowerProducer> group, IMyPowerProducer producer) { foreach (var member in group) { if (producer.IsInfiniteCapacity() != member.IsInfiniteCapacity()) return false; } return true; }
public void RemoveProducer(IMyPowerProducer producer) { Debug.Assert(producer != null); Debug.Assert(GetProducers(producer.Group).Contains(producer)); GetProducers(producer.Group).Remove(producer); --m_producerCount; m_needsRecompute = true; m_remainingFuelTimeDirty = true; producer.MaxPowerOutputChanged -= producer_MaxPowerOutputChanged; producer.HasCapacityRemainingChanged -= producer_HasRemainingCapacityChanged; if (m_producerCount == 0) { m_producersEnabled = MyMultipleEnabledEnum.NoObjects; } else if (m_producerCount == 1) { ChangeProducersState((GetFirstProducer().Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled,MySession.LocalPlayerId); } else if (ProducersEnabled == MyMultipleEnabledEnum.Mixed) { // We were in mixed state and need to check whether we still are. m_producersEnabledDirty = true; } }
public MyPowerProductionItemRenderer(IMyPowerProducer block) { _block = block; }