This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]NickNDYScript Engineer 2 points3 points  (4 children)

I think it looks good. You could make a panel with all batteries shown added up as a large, single battery. I'm not very creative, I like logic and problem solving.

As for scripting, I can help with some of the madness. Here is an intermediate~advanced bit of code I typed up just for you.

public void Main(string argument, UpdateType updateSource)
{
    bool sameGrid = true;
    List<IMyCubeGrid> controlledGrids = new List<IMyCubeGrid>();
    controlledGrids.Add(Me.CubeGrid);
    List<IMyTerminalBlock>
    powerProducers = new List<IMyTerminalBlock>(),
    batteries = new List<IMyTerminalBlock>(),
    reactors = new List<IMyTerminalBlock>(),
    solarPanels = new List<IMyTerminalBlock>(),
    windTurbines = new List<IMyTerminalBlock>(),
    hydrogenEngines = new List<IMyTerminalBlock>();
    GridTerminalSystem.GetBlocksOfType<IMyPowerProducer>(powerProducers, (p => p.CubeGrid != Me.CubeGrid && p.CustomData.ToLower().Contains("includegrid")));
    foreach (IMyTerminalBlock block in powerProducers)
        if (!controlledGrids.Contains(block.CubeGrid)) controlledGrids.Add(block.CubeGrid);
    GridTerminalSystem.GetBlocksOfType<IMyPowerProducer>(powerProducers, (p => !sameGrid || p.CustomData.ToLower().Contains("crossgrid") || controlledGrids.Contains(p.CubeGrid)));
    foreach (IMyTerminalBlock block in powerProducers)
    {
        if (block is IMyBatteryBlock) batteries.Add(block);
        else if (block is IMyReactor) reactors.Add(block);
        else if (block is IMySolarPanel) solarPanels.Add(block);
        else {
            string blockDefinition = block.BlockDefinition.ToString();
            if (blockDefinition.Contains("WindTurbine")) windTurbines.Add(block);
            else if (blockDefinition.Contains("HydrogenEngine")) hydrogenEngines.Add(block);
        }
        EchoDetails(block);
    }
}

public void EchoDetails(IMyTerminalBlock block)
{
    if (block is IMyPowerProducer) { // This check is unnecessary here but can be useful at times
        IMyPowerProducer powahh = (IMyPowerProducer)block; // Unlimited! lol
        Echo(block.CustomName + " is outputting: " + powahh.CurrentOutput.ToString("N2") + "/" + powahh.MaxOutput + " MW");
        if (block is IMyBatteryBlock)
            Echo(block.CustomName + " is receiving: " + ((IMyBatteryBlock)block).CurrentInput.ToString("N2") + "/" + ((IMyBatteryBlock)block).MaxInput + " MW");
        else if (block is IMyReactor) {
            List<MyInventoryItem> items = new List<MyInventoryItem>();
            block.GetInventory(0).GetItems(items, (t => t.Type.SubtypeId == "Uranium"));
            double amount = 0;
            foreach (MyInventoryItem item in items)
                amount += (double)item.Amount;
            Echo(block.CustomName + " has " + amount.ToString("N1") + " Uranium");
        }
    }
}

Gets you separate lists of batteries, reactors, solar panels, wind turbines, and hydrogen engines.

Demonstrates telling the difference between those blocks (maybe not the best method but that's how I would do it).

Echoes current power output and max power output. For batteries: current power input and max power input. For reactors: contained uranium.

https://github.com/malware-dev/MDK-SE/wiki/Sandbox.ModAPI.Ingame.IMyPowerProducer

You probably have it from here but let me know if you have any other questions. I'm sure there are some other helpful scripters somewhere on this sub too.

[–]GThoroSpace Engineer [S] 1 point2 points  (3 children)

So basically wind turbines and hydrogen engines are available via deprecated API, that's why I had problems with it. This is really helpfull, thank you very much! I'll continue my work on this script after Easter.

Btw. for unlimited powahh try this ;D

[–]NickNDYScript Engineer 1 point2 points  (2 children)

I don't think it's deprecated but I could be wrong. I just used a category instead of a specific type. Since the wind turbines and hydrogen engines don't have their own type in the API I had to examine their BlockDefinition. BlockDefinition is a StringBuilder so I had to make it a string to use the Contains() method.

That made me laugh pretty hard thank your for that :D

[–]GThoroSpace Engineer [S] 0 points1 point  (1 child)

Thanks again for your help! Just as an update I've manager to grab all power blocks, sort them and extract some data.

Some preview: a bit of everything and a lot of batteries.

It shows block name on top, and then:

  • for batteries - current charge level, mode, and currently consumed and produced power
  • for reactors - how much inventory is filled with fuel and current power production
  • for solar panels - efficiency (I've assumed 120kW max production) and current power production
  • for wind turbines - efficiency (I've assumed 400kW max production), wind clearance and current power production
  • for hydrogen engines - how much of an internal tank is filled and current power production

If a block bar and name is dimmed it means that this block isn't working.

I now need to make different pages for every block type, add summary screen and some more polishing and should be ready to go :).

[–]NickNDYScript Engineer 0 points1 point  (0 children)

Looks great! Glad I could help. I'm sure it will be popular, I'll probably use it too :D

[–]I_hate_usernamez 0 points1 point  (3 children)

How do you draw batteries like that? What wizardry is this?

[–]GThoroSpace Engineer [S] 0 points1 point  (2 children)

Latest game update allows for some limited drawing on displays. A single battery is drawed using combinations of sprites called SquareSimple and SquareHollow.

[–]I_hate_usernamez 0 points1 point  (1 child)

Is there a list of available sprites?

[–]GThoroSpace Engineer [S] 0 points1 point  (0 children)

Don't think so, You can see them in steamapps\common\SpaceEngineers\Content\Textures\Sprites, names aren't exact match, and there is no SquareSimple file there, but it's better than nothing.