tl;dr: I want a Lamp that produces energy at day like a solar panel, stores the energy like an accumulator and consumes the energy at night like a lamp. How can i achieve that?
I'm new to Factorio Modding, started today. I've done some tutorials, but those were kind of outdated or very basic. Didn't help me much concerning this problem. As far as i know, every entity has a type. However, the SolarLamp i desire is basically a SolarPanel, Accumulator and Lamp at the same time. Can i assign multiple types to one entity, some kind of hybrid. Or is it possible to create new types?
Links and/or examples appreciated.
Thanks in advance, best regards.
Astarch
Re: SolarLamp - Producer at day, consumer at Night.
Posted: Sun Feb 28, 2016 9:32 pm
by Adil
No, you can't have mixed\multiple classes.
But you can have overlapping and invisible entities to emulate that when buildings are considered.
Most hybrid entities, like burner generators are actually several entities spawned together when a specific item is built.
I remember there were also some mods, dealing with composite electrics, wind turbines I believe.
On the other hand entity has "energy" field, if you don't need your lamp to double as a power source for main energy grid, I believe you could try simply giving it huge internal buffer and refilling it by script every once in a while.
Re: SolarLamp - Producer at day, consumer at Night.
Posted: Sun Feb 28, 2016 10:58 pm
by Astarch
Thanks for your reply.
I believe you could try simply giving it huge internal buffer and refilling it by script every once in a while.
That sounds as a good idea. However, i am more interested in the "several entities spawned together" part, because i will use this more often.
I tried to figure out what exactly has been done in the Burner Generator mod, but i don't get it.
TLDR
As far as i understand the code in control.lua, there are two functions triggered when a player or a robot builds the "burner-generator". Both functions do the same (they only differ in a value at the bottom line). If i got this right, this trigger places a "burner-generator-power" at the same location. Same happens when the entity is mined/destroyed. Although i don't exactly know what the code does (I'm inexperienced in LUA).
The more interesting part is the burner-generator.lua, containing even more stuff i don't understand:
There are two items (the "burner-generator" and the "burner-generator-power"), the recipe and the two placeable entities ("burner-generator" and "burner-generator-power").
The "burner-generator" entity is a boiler, which consumes energy (120kW) and stores the fuel (fuel_inventory_size=2).
The "burner-generator-power" entity is not selectable (selectable_in_game=false), provides the textures and sound, and somehow also uses fluid (fluid_usage_per_tick = 0.005).
My questions are:
1) Why is there an item "burner-generator-power"? It can never appear ingame.
2) Why is "burner-generator" (entity) of type "boiler"? Just to provide a fuel inventory?
3) Why does "burner-generator" (entity) consume 120kW as a generator?
4) Why does "burner-generator-power" (entity) use fluid per tick (0.005) of its initial amount of 100? When is it refilled? Based on these values it should be depleted within ~6min.
Thanks in advance.
Best regards.
Astarch
Re: SolarLamp - Producer at day, consumer at Night.
Posted: Mon Feb 29, 2016 12:19 am
by Klonan
Astarch wrote:Thanks for your reply.
I believe you could try simply giving it huge internal buffer and refilling it by script every once in a while.
That sounds as a good idea. However, i am more interested in the "several entities spawned together" part, because i will use this more often.
I tried to figure out what exactly has been done in the Burner Generator mod, but i don't get it.
TLDR
As far as i understand the code in control.lua, there are two functions triggered when a player or a robot builds the "burner-generator". Both functions do the same (they only differ in a value at the bottom line). If i got this right, this trigger places a "burner-generator-power" at the same location. Same happens when the entity is mined/destroyed. Although i don't exactly know what the code does (I'm inexperienced in LUA).
The more interesting part is the burner-generator.lua, containing even more stuff i don't understand:
There are two items (the "burner-generator" and the "burner-generator-power"), the recipe and the two placeable entities ("burner-generator" and "burner-generator-power").
The "burner-generator" entity is a boiler, which consumes energy (120kW) and stores the fuel (fuel_inventory_size=2).
The "burner-generator-power" entity is not selectable (selectable_in_game=false), provides the textures and sound, and somehow also uses fluid (fluid_usage_per_tick = 0.005).
My questions are:
1) Why is there an item "burner-generator-power"? It can never appear ingame.
2) Why is "burner-generator" (entity) of type "boiler"? Just to provide a fuel inventory?
3) Why does "burner-generator" (entity) consume 120kW as a generator?
4) Why does "burner-generator-power" (entity) use fluid per tick (0.005) of its initial amount of 100? When is it refilled? Based on these values it should be depleted within ~6min.
Thanks in advance.
Best regards.
Astarch
The way burner generator works is as follows:
Burner generator is a boiler
burner generator power is a steam engine
When you place the boiler, it spawn the steam engine on top.
The boiler is needed because it only accepts fuel, and also has a fluid box
The fluid box is filled with water by script
The boiler burns fuel to increase the temperature of the fluid
Every so often, some logic is done to determine whether to top up the steam engine
The steam engine's fluid box is then topped up by script, and the boilers fluid box is adjusted to compensate
The steam engine consumes the hot fluid to produce electricity, at a rate of 0.005 per tick
In essence is recreates a traditional steam engine/boiler/water pump setup as a single entity, with the fluid transfer being handled by script
Now for your mod, i think it is fairly simple, and i think you should look at Conrete lamppost for a better idea of just the entity spawning.
You would need to make:
A small solar panel entity
A small lamp entity
and when you place the solar panel, you spawn the lamp on top of it. Make sure the lamp is force neutral, make sure it is off grid, not selectable in game and stuff.. and yadda yadda
That pretty much the only way to make what i call a 'complex' entity in the game
Re: SolarLamp - Producer at day, consumer at Night.
Posted: Mon Feb 29, 2016 1:32 am
by Astarch
I tried to implement your suggestions. First i had some problems caused by a little offset of the images which led to a double-vision of the entity in the world. At least i can assume that the trigger to plant the 2nd entity is works.
Now i have the following Problem: (see Pictures)
The (left) lamp is glowing when placed within the power grid. The other (right) lamp is not glowing (bottom image). But that' s low priority. More annoying is the blinking warning signs. How can i prevent this?
function destroy(event)
if event.created_entity.name == "solartorch" then
local e = event.created_entity
local s = e.surface
local X = e.position.x
local Y = e.position.y
local l = s.create_entity{name = "solartorchpanel", position = {X,Y}, force= game.forces.neutral}
l.destructible = false
end
end
function destroy(event)
if event.entity.name == "solartorch" then
local X = event.entity.position.x
local Y = event.entity.position.y + 0.5
local power = {}
panels = game.players[1].surface.find_entities_filtered{area = {{X -0.5, Y - 0.5 }, {X + 0.5 , Y +0.5 }}, name= "solartorchpanel"}
if panels[1] ~= nil then
panels[1].destroy()
end
end
end
Re: SolarLamp - Producer at day, consumer at Night.
Posted: Mon Feb 29, 2016 1:35 am
by Klonan
I'd suggest spawning a small invisible power pole, maybe a small accumulator too,
This will mean you can put the solar lamps outside the electric network,
and that they will be self-sufficient
This will also stop the annoying flashing icon for disconnected.
The electric pole should have a supply of 1x1, and wire connect of 0