LuaEntity.electric_supply_poles() for entities powered by electricity

Things that we aren't going to implement
thatspsychotic
Burner Inserter
Burner Inserter
Posts: 15
Joined: Thu Mar 14, 2019 12:51 am
Contact:

LuaEntity.electric_supply_poles() for entities powered by electricity

Post by thatspsychotic »

Hi,

I'm working on a mod that depends on the association between electric-poles and the entities that they are powering. Without a programmatic way to leverage the association between entities and the electric-poles that supply them, I would have to calculate the taxicab distance between the entity and every electric-pole on the LuaSurface to develop the assocation, which seems unnecessarily expensive since the engine appears to already make that association (when an entity is selected, the electric-pole(s) supplying the entity are highlighted with a blue box).

Separately, I would absolutely love a uniform way to query an entity's real-time electric power consumption (in watts or kW). It seems to take a lot of excess steps depending on the type of entity (entity.prototype.energy_usage is the nameplate consumption, and querying power consumption of devices with energy storage is done entirely differently)

Thanks!

P.S. Yes my goal is to implement DC approximation powerflow solution so that the amount of power flowing on any copper wire (or more accurately between any two electric-poles) can be calculated.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14601
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaEntity.electric_supply_poles() for entities powered by electricity

Post by Rseding91 »

thatspsychotic wrote: I would have to calculate the taxicab distance between the entity and every electric-pole on the LuaSurface to develop the assocation, which seems unnecessarily expensive since the engine appears to already make that association (when an entity is selected, the electric-pole(s) supplying the entity are highlighted with a blue box).
That's exactly what the game engine does to show which electric poles are connected to an entity. It entity-searches around the entity using MAX(all-electric-pole-connection-distance) for the radius and checks which ones it finds to be connected to that entity.
thatspsychotic wrote: I would absolutely love a uniform way to query an entity's real-time electric power consumption (in watts or kW). It seems to take a lot of excess steps depending on the type of entity (entity.prototype.energy_usage is the nameplate consumption, and querying power consumption of devices with energy storage is done entirely differently)
Unfortunately that information simply doesn't exist. The game doesn't know how much power an entity is consuming at any given tick until after it consumes it and then it's lost once the entity is tick is over.
If you want to get ahold of me I'm almost always on Discord.
thatspsychotic
Burner Inserter
Burner Inserter
Posts: 15
Joined: Thu Mar 14, 2019 12:51 am
Contact:

Re: LuaEntity.electric_supply_poles() for entities powered by electricity

Post by thatspsychotic »

Rseding91 wrote: Thu Mar 14, 2019 9:01 pm
That's exactly what the game engine does to show which electric poles are connected to an entity. It entity-searches around the entity using MAX(all-electric-pole-connection-distance) for the radius and checks which ones it finds to be connected to that entity.
That's fair, I'll do that then, and that's a bit smarter than how I was thinking of approaching it.

Rseding91 wrote: Thu Mar 14, 2019 9:01 pm Unfortunately that information simply doesn't exist. The game doesn't know how much power an entity is consuming at any given tick until after it consumes it and then it's lost once the entity is tick is over.
How does the game calculate the total power consumption of a class of entities then? Does this mean that all the power statistics are representative of the previous tick? That would honestly be fine for what I'm trying to do, or would it be too much of a lift to implement a LuaEntity.power_consumed_last_tick()?
Post Reply

Return to “Won't implement”