Turrets need energy source

by Morgott

This mod makes machine gun and rocket turrets consume electricity to operate.

Tweaks
9 days ago
2.0
258
Power

i Said power consumption

9 days ago

I don't want to self promote, but I'd want to see if this library solves for your problem. IF I read it correctly, you just want it to consume power constantly.
https://mods.factorio.com/mod/powered-machine

Adding this to the turrets should be enough:

    powered_machine                        = {
        heating_energy = "0kW",
        energy_usage   = "<your passive consumption>",
        energy_source  =
        {
            type = "electric",
            usage_priority = "secondary-input",
            emissions_per_minute = { pollution = 2 },
        },
    }
9 days ago
(updated 9 days ago)

I don't want to self promote, but I'd want to see if this library solves for your problem. IF I read it correctly, you just want it to consume power constantly.
https://mods.factorio.com/mod/powered-machine

Adding this to the turrets should be enough:
powered_machine = { heating_energy = "0kW", energy_usage = "<your passive consumption>", energy_source = { type = "electric", usage_priority = "secondary-input", emissions_per_minute = { pollution = 2 }, }, }

Thanks for reaching out, and don't worry about the self-promotion. I took a look through the 0.3.4 source. I like the spoil timer approach instead of running everything through on_tick.

I'm going to pass, though. It's not because there's anything wrong with your library, it just doesn't fit the design of this mod.

The idea here is that turret power cost has two parts. There's a small constant drain on the energy_source (10–50 kW depending on the turret), so keeping a turret powered isn't free, and then there's energy_per_shot, so the actual cost scales with how much it's firing. Idle turrets barely consume anything, but once they're under sustained fire the power demand goes up. That's the behaviour I wanted.

Your library can handle the constant drain, but it can't really model the per-shot part. For flamethrower and artillery turrets I'd have to fake it by increasing the idle power draw, and at that point it becomes a different design rather than an extension of this one.

Another reason is that this mod is currently data-stage only. There's no control.lua, no runtime state, and no migration logic to keep working across updates. It's been basically maintenance-free because of that. Pulling in a runtime dependency just to support two turret types doesn't feel like a worthwhile trade-off, especially when it would make every user install another mod.

As for the original request in this thread, VortiK's cannon turrets turned out to be ammo-turrets, so energy_source and energy_per_shot work natively. That support was added in 0.0.3.

So flamethrower and artillery turrets will stay unsupported for now. FluidTurretPrototype simply doesn't expose an energy field, and ArtilleryTurretPrototype isn't even derived from TurretPrototype. I'd rather leave that gap than implement something that only approximates the behaviour I want.

While I was looking through 0.3.4, I noticed a few things that might be worth checking (though I could absolutely be mistaken, or maybe you've already fixed them):

  • on_configuration_changed only seems to initialise storage, so entities that already exist in a save won't get a consumer if the library is added later. Newly built entities will, but existing ones don't appear to.
  • I couldn't find handlers for on_space_platform_built_entity or on_space_platform_mined_entity, which might matter for Space Age platforms.
  • In control.lua (around line 143), data.auto_toggle or data.auto_toggle ~= nil looks like it'll evaluate as truthy even when auto_toggle is explicitly false, so disabling auto-toggle may not actually work.

Anyway, thanks again for the offer.

9 days ago

Migration is intended to be handled by the mod that adds it, I need to document that. I have no good ways to determine what needs to be migrated.
The last one is safely handling older data that did not have that field.

The "it does not fit the design" part is my answer. :) I end up advertising a bit because it is a very powerful library.

New response