standardized energy sources for improved possibilities

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
der Papst
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Mar 20, 2016 6:15 pm
Contact:

standardized energy sources for improved possibilities

Post by der Papst »

Please post your opinion on the described idea!

Introduction:
I'm an electric engineer, my modding-focus in factorio has always been on realistic energy sources (Maybe other parts of the game would also benefit from this type of standardization)
I've read tons of source code to learn from others, but every energy mod had something in common: A lua script, running for every tick and every unit for circumventing limitations of entity types (for example a diesel-generator with a lua script transforming fuel into steam).

I've once tried to create a solarthermic plant (a solar powered boiler). Only way I've found to implement it was a storage tank and a lua script filling with steam out of nowhere by a filling rate depending on game_darkness.
It works but after building hundreds of it, the lua script made the game running at half speed - that's why I've never published the mod.

For example, let's take a look at the energy sources of (vanilla) solar panel, steam engine, electric and stone furnace:
steam-engine:

Code: Select all

type = "generator",
    name = "steam-engine",
    energy_source =
    {
      type = "electric",
      usage_priority = "secondary-output"
    }
energy_source only specifies the output type of power (electric) but the power input type for a generator has to be hot liquid.

solar panel:

Code: Select all

type = "solar-panel",
name = "solar-panel",
energy_source =
    {
      type = "electric",
      usage_priority = "solar"
    },
production = "60kW"
Same here, output type of power = electric, but type = "solar-panel" tells the game it's input type of power = solar energy

furnaces:

Code: Select all

    type = "furnace",
    name = "stone-furnace",
    energy_source =
    {
      type = "burner",
      fuel_category = "chemical",
    }

Code: Select all

    type = "furnace",
    name = "electric-furnace"
    energy_source =
    {
      type = "electric",
      usage_priority = "secondary-input",
      emissions = 0.005
    }
For furnaces, the implementation is already like I imagine: every furnace is of type="furnace", energy_source= tells the game where the required energy comes from.


If hot liquid, wind and solar power would be implemented as an energy_source additional to existing (electric, burner,...) above examples would be easily defined like this:
steam-engine:

Code: Select all

type = "generator",
    name = "steam-engine",
    energy_input_source =
    {
      type = "hot liquid"
    }
    energy_output_source =
    {
      type = "electric",
      usage_priority = "secondary-output"
    }
solar panel:

Code: Select all

type = "generator", //(!)
name = "solar-panel",
    energy_input_source =
    {
      type = "solar"
    }
energy_output_source =
    {
      type = "electric",
      usage_priority = "solar"
    },
production = "60kW"
Diesel generator:

Code: Select all

    type = "generator",
    name = "diesel-generator",
    energy_input_source =
    {
      type = "burner",
      fuel_category = "chemical",
    }
    energy_output_source =
    {
      type = "electric",
      usage_priority = "secondary-output"
    }
solar boiler

Code: Select all

    type = "boiler,
    name = "solar-boiler,
    energy_input_source =
    {
      type = "solar",
    }

    //Edit: Removed energy_output_source for boiler, because type=boiler already defines what it does
solar car

Code: Select all

    type = "car",
    name = "solar-car"
    energy_input_source =
    {
      type = "solar",
    }
Of course parameters for maximum power, min. and max. temp for hot liquids,... would be necessary but I just wanted to give a few examples to show what I'm talking writing about


(English is not my native language. If there are disturbing mistakes or parts even not understandable please notify me)

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: standardized energy sources for improved possibilities

Post by Bilka »

I find your post titel misleading tbh. Your aim is not really to have a standard energy source (which you know.. is already standardized) but: The ability to have solar power/liquid/burner consuming power on entities that currently don't support that. And all I can say to that is: Would be nice, won't happen. For example implementing the ability to make a car solar powered from the game's side means that every car in every game can potentially get power from solar, so the code for that has to be present and has to be saved etc. The car is an example where adding that doesn't seem so crucial, but since you seem to propose that it should be added to all entity types, this would mean MASSIVE overhead for everyone although the actual feature is only used in some mods.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: standardized energy sources for improved possibilities

Post by Rseding91 »

I'm not sure what you're actually asking for?
If you want to get ahold of me I'm almost always on Discord.

der Papst
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Mar 20, 2016 6:15 pm
Contact:

Re: standardized energy sources for improved possibilities

Post by der Papst »

Bilka wrote:I find your post titel misleading tbh. Your aim is not really to have a standard energy source (which you know.. is already standardized) but: The ability to have solar power/liquid/burner consuming power on entities that currently don't support that.
This is exactly a "standardized energy source": You can use it in every entity consuming energy.
Bilka wrote: And all I can say to that is: Would be nice, won't happen. For example implementing the ability to make a car solar powered from the game's side means that every car in every game can potentially get power from solar, so the code for that has to be present and has to be saved etc. The car is an example where adding that doesn't seem so crucial, but since you seem to propose that it should be added to all entity types, this would mean MASSIVE overhead for everyone although the actual feature is only used in some mods.
You don't have to implement every energy source for every entity so there is no overhead at all.

In C++ it could look like this:
An abstract class energy_input_source has a function int consume_power(); When it is called, it consumes power and returns the consumable power (limited by solar yield, fuel storage,...).
You have to implement those energy sources just once inheriting the same class, than you can use it in every unit.
This is called polymorph and is a great advantage of object oriented programming languages.
Rseding91 wrote:I'm not sure what you're actually asking for?
For being able to use any energy_source to power everything - which has improved, for example a boiler now takes "electric" as energy source which it didn't when I tried last time (~0.12) as far as i remember.
But I can't give a boiler energy_source = { type = "solar" } } because solar is not an energy source but only available for type = "solar panel" and i don't understand why.

Even better would be if every energy consuming unit would accept an energy_source, for example a car or a generator (which can use only hot fluids as energy source by now)

Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: standardized energy sources for improved possibilities

Post by Rseding91 »

Any entity that doesn't support a specific energy source type is made that way for performance reasons.

Solar panels have no internal energy buffer and don't support concepts like drain or flow limits and as such they're optimized to O(1) cost no matter how many solar panels you have. You can't have any other entity use the solar type with those restrictions.

Things like a locomotive don't support other energy source types because electric makes no sense for a moving entity - it would be insanely expensive if they had to re-connect to electric poles every time a locomotive moved. The same for cars.
If you want to get ahold of me I'm almost always on Discord.

Angamara
Inserter
Inserter
Posts: 39
Joined: Mon Oct 30, 2017 3:52 pm
Contact:

Re: standardized energy sources for improved possibilities

Post by Angamara »

Just to support a point.
In real life, electric vehicles are starting to be sold more and more.

For example in Paris (France), there is an electric vehicle rental service, special parking for these vehicles have been installed in several places in the city.
.
But the idea of Factorio and the reality may not go in the same direction

Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: standardized energy sources for improved possibilities

Post by Rseding91 »

Real life has no relation to Factorios cars :P
If you want to get ahold of me I'm almost always on Discord.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: standardized energy sources for improved possibilities

Post by orzelek »

It would be really cool if cars/tanks/locos could use energy from their own energy grid as a power source.

galibert
Inserter
Inserter
Posts: 42
Joined: Fri Sep 15, 2017 7:42 am
Contact:

Re: standardized energy sources for improved possibilities

Post by galibert »

Rseding91 wrote:Things like a locomotive don't support other energy source types because electric makes no sense for a moving entity - it would be insanely expensive if they had to re-connect to electric poles every time a locomotive moved.
You could have "electrified rail" which connect to a power source (and transfer electricity between outposts). It becomes mostly static then.

OG.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: standardized energy sources for improved possibilities

Post by Rseding91 »

galibert wrote:
Rseding91 wrote:Things like a locomotive don't support other energy source types because electric makes no sense for a moving entity - it would be insanely expensive if they had to re-connect to electric poles every time a locomotive moved.
You could have "electrified rail" which connect to a power source (and transfer electricity between outposts). It becomes mostly static then.

OG.
No it doesn't, then rails would have to transfer electricity and that increases RAM usage, save file size, and makes them slower to create and destroy.
If you want to get ahold of me I'm almost always on Discord.

der Papst
Burner Inserter
Burner Inserter
Posts: 15
Joined: Sun Mar 20, 2016 6:15 pm
Contact:

Re: standardized energy sources for improved possibilities

Post by der Papst »

Rseding91 wrote:Any entity that doesn't support a specific energy source type is made that way for performance reasons.

Solar panels have no internal energy buffer and don't support concepts like drain or flow limits and as such they're optimized to O(1) cost no matter how many solar panels you have. You can't have any other entity use the solar type with those restrictions.
Thx for your explanation!
Would it be possible to create a second entity which converts solar power into heat (as produced by the nuclear reactor?)
This would simulate solarthermic powerplants using molten salt for transporting and storing thermal energy and this heat can be used to heat up water since boilers accept heat as energy source - the heat-exchanger already does it.
I didn't try yet if furnaces also accept heat as energy_source

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: standardized energy sources for improved possibilities

Post by bobingabout »

der Papst wrote: Diesel generator:

Code: Select all

    type = "generator",
    name = "diesel-generator",
    energy_input_source =
    {
      type = "burner",
      fuel_category = "chemical",
    }
    energy_output_source =
    {
      type = "electric",
      usage_priority = "secondary-output"
    }
It would be nice if this was possible.
you can burn fuel to make heat. (which can be used to power a fair few things if you mod them in)
you can get electricity from temperature in a fluid
you can get electricity from solar power.

but there is no way that I know of to generate heat from electricity, or electricity from heat/burner directly.
I mean, I might be out of date with this information but... it would be nice if these were possible.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

galibert
Inserter
Inserter
Posts: 42
Joined: Fri Sep 15, 2017 7:42 am
Contact:

Re: standardized energy sources for improved possibilities

Post by galibert »

Rseding91 wrote:
galibert wrote:
Rseding91 wrote:Things like a locomotive don't support other energy source types because electric makes no sense for a moving entity - it would be insanely expensive if they had to re-connect to electric poles every time a locomotive moved.
You could have "electrified rail" which connect to a power source (and transfer electricity between outposts). It becomes mostly static then.

OG.
No it doesn't, then rails would have to transfer electricity and that increases RAM usage, save file size, and makes them slower to create and destroy.
Huh? I've been able to see you're way more competent than that, you're either damn tired or knee-jerked :-) For the other people out there, let's expand on what I meant.

To have electric locomotives, and not have them cost an insane amount of cpu/ram bandwidth at update time, they must be integrated in the static power distribution network. What's the static distribution network, you ask? Everty entity/power provider/accumulator/etc which are electrically connected together point to an identical electrical network object (lua API users, that's the LuaCircuitNetwork you get from get_circuit_network(defines.wire_type.copper), I think). On update that object accumulates all the electricity requests and providers, and is used to compute the satisfaction and the repartition of electricity. That's also what makes solar panels and accumulators so efficient: it's only one update for all of them, multiplying they capacity by their number. No need to go over each individual entity. To get an idea of how powerful that concept is, realize that there usually only one object per entire base. Some more appear when if you use power switches or when you're placing not-yet-connected power poles, but that's mostly it.

So, to make locomotives efficient they need to be associated to an electrical network object and that object must essentially never change. Then they're no more expensive than an assembler or an inserter. Looking for power poles around the locomotive is out of the picture. It's horribly costly whatever you do. So a trick is to associate the rails to the network, and the locomotive to the rails. But that's still not good enough, you don't want to look up the rail entity when the locomotive moves. So you have to ensure that the locomotive never changes of network, which can be easily done by saying that connected electric rails are on the same network, and that an electric locomotive can't go on a non-electric rail. The result will be that the circuit network will be chosen when placing the locomotive on the rail, and everything else being equal, will never change. If you move rails, change connections, etc, it may change of course, but not as a result of simply moving around. The locomotive then becomes a normal powered entity.

A side effect is that there rails virtually transfer electricity, as in whichever way you use to connect them to the grid, the magic of the electrical circuit object will ensure that if you connect the same set of rails in two places, these two places will be electrically connected together. That's something easily turned into a feature: you power your far away outposts without needing power lines, making the rail planner more interesting compared to tiled blueprints with poles integrated (and signals and double-tracking, the other two missing things with the rail planner).

Now, the costs. RAM usage, a little. Having two types of rail has a cost, having the routing of electric locomotives not being able to go over traditional rails is not entirely trivial to handle. The pointer to the electric network object doesn't have to be in the rail entity. It can be at a higher level, probably the block, since there's no reason to scan over the rails at update time, at least to reach electricity. You'd have a pointer to the electric network object in the locomotive too (but you'd lose the fuel information if your inheritance structure allows for it). An option that would simplify everything is to decide that electric-rail is the only type of rail, possibly adding some copper circuit to its recipe, making copper more useful mid-game (but requiring an assembler-2). That would drop a lot of tests in the (potential) code. Gameplay-wise, the choice will be done between loco types given the cost of building the locomotive (electric motors) and their capabilities (speed, traction, comsumption). If the base electric locomotive is slightly less powerful than the standard loco-on-coal, but otoh can take modules to enhance its performace, the tradeoffs will get interesting.

Save game size, there's some electric network information to save, but with the removal of tens of power poles, I'd bet on a net reduction.

For placement cost, yes there will be one. It will add, roughly, the cost of placing/removing a power pole to the cost of placing/removing a rail. Not sure that's really noticeable.

Did I miss something huge there?

OG.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7351
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: standardized energy sources for improved possibilities

Post by bobingabout »

Part of the issue with electrified rail comes in with the problem of "Multiple rail types"

As someone, Rseding most likely, previously pointed out... Part of the reason why electrified rail will never happen is down to the whole issue of whether or not a train should be allowed to travel along certain rails. The train will need to consider 3 things:
1. While path finding, is the track is a type that will allow the train to actually travel on it.
2. While manually driving a train, is the track is a type that will allow the train to actually travel on it.
3. If you add Electrified rail in the mix... is the track capable of providing power to the train?

For every point, extra processing power is required to make a decision. For 1 and 2 the decision will likely be on a tile per tile basis. For point 3 it could potentially be a per tick issue.

Point 3 is not so much an issue if the train has duel power, or an accumulator or such to it, it would still be able to travel over normal rail, the question then becomes how much normal rail, or what power system it should use, it will be more of a test of where the power is coming from rather than if it can travel on the track, but either way it still has to expend processing power.

And from what I understand... adding more processing time per tick is not something they want to add to the game, remember, to even add support for this sort of thing, the game will need to do these checks even in the unmodded basegame where they items don't exist, just to allow for cases where they might exist in mods.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

galibert
Inserter
Inserter
Posts: 42
Joined: Fri Sep 15, 2017 7:42 am
Contact:

Re: standardized energy sources for improved possibilities

Post by galibert »

bobingabout wrote:Part of the issue with electrified rail comes in with the problem of "Multiple rail types"

As someone, Rseding most likely, previously pointed out... Part of the reason why electrified rail will never happen is down to the whole issue of whether or not a train should be allowed to travel along certain rails. The train will need to consider 3 things:
1. While path finding, is the track is a type that will allow the train to actually travel on it.
2. While manually driving a train, is the track is a type that will allow the train to actually travel on it.
3. If you add Electrified rail in the mix... is the track capable of providing power to the train?

For every point, extra processing power is required to make a decision. For 1 and 2 the decision will likely be on a tile per tile basis. For point 3 it could potentially be a per tick issue.

Point 3 is not so much an issue if the train has duel power, or an accumulator or such to it, it would still be able to travel over normal rail, the question then becomes how much normal rail, or what power system it should use, it will be more of a test of where the power is coming from rather than if it can travel on the track, but either way it still has to expend processing power.

And from what I understand... adding more processing time per tick is not something they want to add to the game, remember, to even add support for this sort of thing, the game will need to do these checks even in the unmodded basegame where they items don't exist, just to allow for cases where they might exist in mods.
I don't know what the internal organization is, but I hope everything is decomposed into rail blocks and at least for path finding blocks are the decision unit. In any case, yes there's a cost, and I think the best solution is to not have multiple rail types but instead make the only rail type electrified. The power transport advantage is such that everybody would use electrified rail anyway unless their cost is stupid high. So there's no point is having two types, just keep to more capable one. As for point 3, the question becomes then "is there enough electricity available for the locomotive", which is a question already answered by every power-using element in the game, so well optimized already as long as the locomotives plug correctly in the electricity network concept. And it's I think actually more efficient than the burning fuel computation, since electricity only has one type.

OG.

Brambor
Fast Inserter
Fast Inserter
Posts: 125
Joined: Thu May 07, 2015 1:52 pm
Contact:

Re: standardized energy sources for improved possibilities

Post by Brambor »

bobingabout wrote:Part of the issue with electrified rail comes in with the problem of "Multiple rail types"

As someone, Rseding most likely, previously pointed out... Part of the reason why electrified rail will never happen is down to the whole issue of whether or not a train should be allowed to travel along certain rails. The train will need to consider 3 things:
1. While path finding, is the track is a type that will allow the train to actually travel on it.
2. While manually driving a train, is the track is a type that will allow the train to actually travel on it.
3. If you add Electrified rail in the mix... is the track capable of providing power to the train?

For every point, extra processing power is required to make a decision. For 1 and 2 the decision will likely be on a tile per tile basis. For point 3 it could potentially be a per tick issue.

Point 3 is not so much an issue if the train has duel power, or an accumulator or such to it, it would still be able to travel over normal rail, the question then becomes how much normal rail, or what power system it should use, it will be more of a test of where the power is coming from rather than if it can travel on the track, but either way it still has to expend processing power.

And from what I understand... adding more processing time per tick is not something they want to add to the game, remember, to even add support for this sort of thing, the game will need to do these checks even in the unmodded basegame where they items don't exist, just to allow for cases where they might exist in mods.

Easy solution for that is to forbit mixing regular rail with electrified one.
You will simply not be able to connect two blocks: one electrified and one not, or extend existing block with rail of the other type.

And then you forbit placing electric-locomotive on any regular (non enectric) rail.
(You can also forbit placing diesel-locomotive on electrified rails, but you may leave it, it doesn't mess with anything.)

This solves all three of these problems.

It might actually be faster, as 20 electric-locomotives would be in one electric grid and could then behave as one entity (from the point of view of energy consumption).
Either they are accelerating, thus consuming power, or they are not, thus consuming just the drain cost.

Post Reply

Return to “Modding interface requests”