Page 1 of 1

Create light source entity

Posted: Thu Apr 05, 2018 8:45 pm
by lovely_santa
Hi,

Afther some mods, I keep trying to create light entities, but it never works out right. If I want to create a light source, it always needs a default entity, for example a lamp, a vehicle, etc...

A simple entity with light source would be handy. The ability to force it on and off through the api (example not needing energy at all, but still lighting up) would be a nice addition, or ability to give it an infinite fuel source so it never runs out. With infinity i mean for example support for burner fuel source (rest can be done through scripting already). (Why doesn't this gets supported for all prototypes?)

A nice addition to this enitty could be also able to select the type of light source (the circle uniform one or the cone shaped one + orientation?)

If this forcing on/off get implemented, maybe some extra events could be handy about the darkness of the map (not with the time, in case this gets changed in the base game sometime)

Examples: (mainly the upper two would be extremely usefull)
  • on_dawn : when it gets light (aka vanilla lamps turn off)
  • on_nightfall : when lights turn on
  • on_midnight : middle of the night
  • on_noon: middle of the day
Greetings
lovely_santa

Re: Create light source entity

Posted: Fri Apr 06, 2018 3:56 am
by betrok
Yep, such kind of entity will be useful.

For now you can create lamps with oriented light and minimum darkness setting:

Code: Select all

local cone_lamp = table.deepcopy(data.raw.lamp["small-lamp"])
cone_lamp.name = "cone-lamp"
cone_lamp.light = {
	type = "oriented",
	picture =
	{
		filename = "__core__/graphics/light-cone.png",
		priority = "extra-high",
		flags = { "light" },
		scale = 2,
		width = 200,
		height = 200
	},
	minimum_darkness = 0.8,
	shift = {0, -18},
	size = 4,
	intensity = 0.9,
	color = {r=1.0, g=1.0, b=1.0}
}
But there is still all that extra logic with energy sources, circuit and health.

Btw i'm working on light-related mod now as well, pm me if you want to cooperate.

Re: Create light source entity

Posted: Fri Apr 06, 2018 8:36 am
by lovely_santa
The circuit logic is easy: make selection_box = {} so you can't select it in the first place

The energy is another issue that i can't solve yet.. It has no buffer so i can't give it some energy..
Making a new force for it, place invisible pole, invisible simple accumulator and a lamp is like overkill... using burner energy doesn't work either..

Health isn't an issue either.. Make it indestructible (entity.destructible = false)

PS: I've send you a pm

Re: Create light source entity

Posted: Fri Apr 06, 2018 10:19 am
by darkfrei
lovely_santa wrote: The energy is another issue that i can't solve yet.. It has no buffer so i can't give it some energy..
Making a new force for it, place invisible pole, invisible simple accumulator and a lamp is like overkill... using burner energy doesn't work either.
We are need universal power description for all powered entities: electrical, burner, fluid (with temperature), fluid (with burner), and nothing, if this entity doesn't need any energy source.

Re: Create light source entity

Posted: Fri Apr 06, 2018 11:07 am
by eradicator
Feel free to bump my interface request for a free energy source: viewtopic.php?f=28&t=57793 and don't forget to link back to this thread. More examples help suggestions.

Re: Create light source entity

Posted: Fri Apr 06, 2018 1:45 pm
by betrok
After some investigations i ended up with such variants of bases for abstract light sources:
  • player(type for characters) — easy way to get 8-way rotatable light. Have tons of extra properties and logic around it. Does not have smooth orientation.
  • explosion — non-rotatable at all. Lifetime is based on animation. Rather small footprint, but there are still sound, smoke and effects.
  • projectile — actuality still is not rotatable: only sprite rotates following target, light does not. Need target to follow it and will dissapear after reaches it(unless speed and acceleration both zero).
  • car with player-type entity mounted as driver — finaly smooth rotation. Tons of extra logic around again though.
Btw rotation(even smooth one) could be emulated with set of various entity protopytes with single difference in orientation of light. But creation and destruction of entity is probably much heavier operation than move and rotation.

Re: Create light source entity

Posted: Sat Apr 07, 2018 9:03 pm
by lovely_santa
betrok wrote:After some investigations i ended up with such variants of bases for abstract light sources:
  • player(type for characters) — easy way to get 8-way rotatable light. Have tons of extra properties and logic around it. Does not have smooth orientation.
  • explosion — non-rotatable at all. Lifetime is based on animation. Rather small footprint, but there are still sound, smoke and effects.
  • projectile — actuality still is not rotatable: only sprite rotates following target, light does not. Need target to follow it and will dissapear after reaches it(unless speed and acceleration both zero).
  • car with player-type entity mounted as driver — finaly smooth rotation. Tons of extra logic around again though.
Btw rotation(even smooth one) could be emulated with set of various entity protopytes with single difference in orientation of light. But creation and destruction of entity is probably much heavier operation than move and rotation.
The car is the only 'hacky' sollution i can find usefull.. or the explosion for the round light.. but what if i want to re-use those to use power.. well then I cant...
Why not allow small-lamps to have the burner fuel enabled just like other prototypes can have a fuel inventory... I guess there is a reason otherwise it would work.. So thats why I requested the simple entity version of a light source.. and the extra events to extend the controlability it...

Re: Create light source entity

Posted: Sat Apr 07, 2018 10:20 pm
by Deadlock989
+1 for a burner lamp.

Re: Create light source entity

Posted: Sun Apr 08, 2018 4:23 pm
by Xalos
+1 for burner energy_source support for all entities.

Re: Create light source entity

Posted: Fri Jan 04, 2019 6:14 pm
by Bilka
Hey, I implemented the ability to draw arbitrary lights in 0.17: https://lua-api.factorio.com/0.17.0-pre ... draw_light I hope this helps you, though please let me know if you are still looking for a burner lamp.

Re: Create light source entity

Posted: Fri Jan 04, 2019 7:04 pm
by darkfrei
Bilka wrote:
Fri Jan 04, 2019 6:14 pm
Hey, I implemented the ability to draw arbitrary lights in 0.17: https://lua-api.factorio.com/0.17.0-pre ... draw_light I hope this helps you, though please let me know if you are still looking for a burner lamp.

Code: Select all

draw_light{sprite=…,
So this sprite can be used as glowing mask?

Re: Create light source entity

Posted: Fri Jan 04, 2019 7:08 pm
by Bilka
darkfrei wrote:
Fri Jan 04, 2019 7:04 pm

Code: Select all

draw_light{sprite=…,
So this sprite can be used as glowing mask?
Yes :)

Re: Create light source entity

Posted: Sun Mar 03, 2019 2:53 pm
by darkfrei
Bilka wrote:
Fri Jan 04, 2019 7:08 pm
darkfrei wrote:
Fri Jan 04, 2019 7:04 pm

Code: Select all

draw_light{sprite=…,
So this sprite can be used as glowing mask?
Yes :)
How it works? https://lua-api.factorio.com/latest/Lua ... draw_light

For example I want to set image as light Factorio_0.17/data/core/graphics/light-medium.png to selected entity:

Code: Select all

/c
local entity = game.player.selected
local filename = "__core__/graphics/light-medium.png"
rendering.draw_light = 
  {
    sprite = filename,
    surface = entity.surface,
    target = entity
  }
Why it doesn't working?

UPD: this works

Code: Select all

/c 
local entity = game.player.selected 
local filename = "utility/light_medium" 
rendering.draw_light {sprite = filename, surface = entity.surface, target = entity}

Re: Create light source entity

Posted: Sun Mar 03, 2019 4:44 pm
by darkfrei
It works great for vanilla sprite.

But not for modded utility (data.raw["utility-sprites"].default):

Code: Select all

data.raw["utility-sprites"].default.riteg_glow =
    {
      filename = "__RITEG__/graphics/riteg-glow.png",
      priority = "extra-high",
      flags = {"light"},
      width = 102, height = 133
    }
and then this command

Code: Select all

/c 
local entity = game.player.selected 
local filename = "utility/riteg_glow" 
rendering.draw_light {sprite = filename, surface = entity.surface, target = entity}
makes error:
2019-03-03 17_43_35-Factorio 0.17.4.png
2019-03-03 17_43_35-Factorio 0.17.4.png (103.71 KiB) Viewed 3502 times
But I am sure that it was added to the data.raw:
2019-03-03 17_46_08-Calculator.png
2019-03-03 17_46_08-Calculator.png (21.19 KiB) Viewed 3499 times

Re: Create light source entity

Posted: Sun Mar 03, 2019 4:45 pm
by Bilka
You cannot add additional utility sprites. Make a sprite prototype (type = "sprite").

Re: Create light source entity

Posted: Sun Mar 03, 2019 5:00 pm
by darkfrei
Bilka wrote:
Sun Mar 03, 2019 4:45 pm
You cannot add additional utility sprites. Make a sprite prototype (type = "sprite").
Thanks, it works!

Code: Select all

data:extend ({
  {
    type = "sprite",
    name = 'riteg_glow',
    filename = "__RITEG__/graphics/riteg-glow.png",
    priority = "extra-high",
    flags = {"no-crop" },
    width = 102, height = 174
  }
})
2019-03-03 17_59_56-Factorio 0.17.4.png
2019-03-03 17_59_56-Factorio 0.17.4.png (80.74 KiB) Viewed 3497 times
Works as well:

Code: Select all

  rendering.draw_light 
    {
      -- sprite = "riteg_glow", -- not nice :(
      sprite = "utility/light_small",
      surface = entity.surface,
      target = entity
    }