Modules for Turrets (and Other Entities?)

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
shouperman
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu May 17, 2018 1:41 am
Contact:

Modules for Turrets (and Other Entities?)

Post by shouperman »

tl;dr
Can we ever expect module slots for all/most entities (e.g. turrets), or are they too ingrained into production entities?
Intent
I started working on a 'modular turret' concept which leveraged modules with the intent to tweak a turrets rate of fire, rotation speed, targeting radius, resistance types, etc. There are other concepts I won't address here as they're not related to this subject.

I was hoping to add options and diversity to turrets without taking the approach of most modders, who add x+n number of turrets/upgrades with y number of research options. Not that there's anything wrong with that.

Actions Taken
I thought it was only fair to give it a go and do my homework before making a request. I've attempted adding new turrets with "module_specification" (with sub properties) and "allowed_effects" defined, as well as altering the same values via data.raw. It appears that modules can only be added to entities of type "assembling-machine", "mining-drill", "lab", "rocket-silo", "furnace"*, and (obviously) "beacon".

I searched the forums (and /r/factorio) for requests, recommendations, and comments, and it looks like this feature hasn't been (formally) requested. Recently, (and independently) a similar mod request was posted (viewtopic.php?f=33&t=59542).

I dug into the code from both the API and prototype sides, and the following is what I have gathered. Please correct me where I'm wrong.

Speculation / Concerns
  1. I assume module settings are only defined on certain entities for performance reasons. Reading comments/feedback on certain features (e.g. the limit of 5 filters on entities), I can tell the dev team cares deeply about performance (for which I and my heat sink thank you).
    1. Calculating modules on every entity when only "production" entities can make use of them is a waste of resources.
    2. Not knowing when/where modules are applied nor checked, I'm not sure how intensive the calculations for turrets (which aren't active every tick) would be.
  2. It looks like modules are internally defined. They are clearly tailored toward production aspects, and applied in a very specific manner.
    1. Given the keys in "allowed_effects", it looks like only specific behavior is coded. E.g. "productivity" affects "crafting_speed" (or other internal value(s)), and not some value under a "productivity" property.
    2. There is likely no potential for adding custom "effects". E.g. Adding a "fire-resistance" or "impact-resistance" module, affecting the appropriate entry in entity.resistances (table lookup aside).
    3. Generalizing them may not be performant or clear; "speed" and "consumption" may mean different things to different entities.
  3. Given the naming used for effects in the technology tree and the naming used for existing modules, it may be possible to target specific behaviors in (new) modules as follows.
    E.g. the existing "mining-productivity-1" technology and "productivity-module" module.

    Code: Select all

    {
      type = "technology",
      name = "mining-productivity-1",
      effects =
      {
        {
          type = "mining-drill-productivity-bonus",
          modifier = 0.02
        }
      },
      ...
    }

    Code: Select all

    {
      type = "module",
      name = "productivity-module",
      effect =
      {
        productivity = {bonus = 0.04},
        consumption = {bonus = 0.4},
        pollution = {bonus = 0.05},
        speed = {bonus = -0.15}
      },
      ...
    }
    Using the above, and the "gun-turret-damage-1" technology suggests a possible pattern for an "attack-module" module

    Code: Select all

    {
      type = "technology",
      name = "gun-turret-damage-1",
      effects =
      {
        {
          type = "turret-attack",
          turret_id = "gun-turret",
          modifier = 0.1
        }
      },
      ...
    }

    Code: Select all

    {
      type = "module",
      name = "attack-module",
      effect =
      {
        attack = {bonus = 0.04},
        consumption = {bonus = 0.4},
        speed = {bonus = -0.15}
      },
      ...
    }
Yep. That's probably broken.

Post Reply

Return to “Modding interface requests”