Page 1 of 1

Change turret_id in technology modifier effects to an array

Posted: Thu Jan 07, 2021 11:05 am
by ickputzdirwech
Right now if a technology has the modifier effect "turret-attack" you have to add the effect for every single turret entity that should be effected. It would be much simpler if turret_id would be an array, so you can just add the list of all turrets that should be effected. This would be nice for mods that add multiple new tiers and types of gun turrets. it wouldn't only save some work but also shrink the list of effects visible in the technoloy GUI.

Another not so nice side effect of the current system is that every single turret has it's own category in the bonus GUI, even though they have the same bonuses.

Re: Change turret_id in technology modifier effects to an array

Posted: Thu Jan 07, 2021 11:14 am
by PFQNiet
It might be nice if we could define "groups" of turret types, and then apply a bonus to that group as a whole.

Re: Change turret_id in technology modifier effects to an array

Posted: Thu Jan 07, 2021 5:30 pm
by Rseding91
Just a note; the bonus GUI and the technology effect definition are unrelated. If the technology modifier allowed an array it would still show them separate in the bonus GUI.

The game has no way to know that bonuses are related - since they aren't. Bonuses are a simple number bonus stored on LuaForce where each one is the bonus for a given turret.

So I guess with that said; this won't be happening since it wouldn't actually make anything better.

Re: Change turret_id in technology modifier effects to an array

Posted: Fri Jan 08, 2021 11:56 am
by ickputzdirwech
Rseding91 wrote: Thu Jan 07, 2021 5:30 pm the bonus GUI and the technology effect definition are unrelated
Thanks for your answer, I didn't know that. I just assumed the bonus GUI makes one group for every effect. But good to know.
Rseding91 wrote: Thu Jan 07, 2021 5:30 pm The game has no way to know that bonuses are related - since they aren't. Bonuses are a simple number bonus stored on LuaForce where each one is the bonus for a given turret.
How are the laser and plasma turrets than all grouped together (bottom right corner of the image in the first post)? I assume this is because there is one bonus that effects all these kinds of turrets. Couldn't you implement the same thing for all gun turrets? One bonus that effects all gun turrets?
Rseding91 wrote: Thu Jan 07, 2021 5:30 pm this won't be happening since it wouldn't actually make anything better.
At least it would reduce the number of effects you have to add and that would show up in the tech GUI (see picture below). But I agree it's probably not worth the effort. Somehow grouping the entities in the bonus GUI would be much more of an improvement. But well, not that big of a deal.

Re: Change turret_id in technology modifier effects to an array

Posted: Fri Jan 08, 2021 5:01 pm
by Rseding91
There are entity-specific damage bonuses and there are damage type bonuses. A given entity is its own entity and will show up when it has a bonus set for it. The damage type can be used by any number of entities and will be grouped.

Re: Change turret_id in technology modifier effects to an array

Posted: Mon Jan 25, 2021 2:29 pm
by ickputzdirwech
In case anyone stumbles upon this, with the same issue. I found a way around this. It includes a dummy turret entity, some hidden technologies and a control script to automatically research these technologies. Feel free to use the code below.

data-final-fixes.lua

Code: Select all

if data.raw.technology["physical-projectile-damage-1"] and data.raw.technology["physical-projectile-damage-7"] then

  local turret_list = {}

  for _, turret in pairs(data.raw["ammo-turret"]) do
    table.insert(turret_list, turret.name)
  end

  data:extend({
    {
      name = "ammo-turret-dummy",
      type = "ammo-turret",
      icons = {
        {
          icon = "__base__/graphics/icons/gun-turret.png",
          icon_mipmaps = 4,
        },
        {
          icon = "__core__/graphics/icons/technology/effect-constant/effect-constant-damage.png",
          icon_mipmaps = 2,
        }
      },
      icon_size = 64,
      localised_description = {"", "\n"},
      attack_parameters = {type = "projectile", range = 0, cooldown = 0},
      call_for_help_radius = 0,
      folded_animation = data.raw["ammo-turret"][turret_list[1]].folded_animation,
      automated_ammo_count= 0,
      inventory_size = 0,
    }
  })

  local tech_list = {
    {name = "physical-projectile-damage-1", value = 0.1},
    {name = "physical-projectile-damage-2", value = 0.1},
    {name = "physical-projectile-damage-3", value = 0.2},
    {name = "physical-projectile-damage-4", value = 0.2},
    {name = "physical-projectile-damage-5", value = 0.2},
    {name = "physical-projectile-damage-6", value = 0.4},
    {name = "physical-projectile-damage-7", value = 0.7},
  }

  for _, tech in pairs(tech_list) do
    local visible_tech = data.raw.technology[tech.name]
    local hidden_tech = table.deepcopy(visible_tech)
      hidden_tech.name = "hidden-"..tech.name
      hidden_tech.effects = {}
      for _, turret in pairs(turret_list) do
        table.insert(hidden_tech.effects, {type = "turret-attack", turret_id = turret, modifier = tech.value})
        for i, effect in pairs(visible_tech.effects) do
          if effect.type == "turret-attack" and effect.turret_id == turret then
            table.remove(visible_tech.effects, i)
          end
        end
      end
      hidden_tech.hidden = true
    data:extend({hidden_tech})

    if visible_tech and visible_tech.effects then
      table.insert(visible_tech.effects, {type = "turret-attack", turret_id = "ammo-turret-dummy", modifier = tech.value})
    end

  end

  for i, turret in pairs(turret_list) do
    if data.raw["ammo-turret"][turret].flags then
      table.insert(data.raw["ammo-turret"][turret].flags, "hidden")
    else
      data.raw["ammo-turret"][turret].flags = {"hidden"}
    end
  end

  for i, turret in pairs(turret_list) do
    local description = data.raw["ammo-turret"]["ammo-turret-dummy"].localised_description
    if i == 1 then
      table.insert(description, 2, "\n[font=heading-1][entity="..turret.."] [.font]")
      table.insert(description, 3, {"entity-name."..turret})
    elseif i < 10 then
      table.insert(description, i*2, "\n\n[font=heading-1][entity="..turret.."] [.font]")
      table.insert(description, i*2+1, {"entity-name."..turret})
    else
      local size = table_size(turret_list)-9
      table.remove(description, 20)
      table.insert(description, 20, "\n\n and "..size.." more")
      break
    end
  end

end
control.lua

Code: Select all

local tech_list = {
  "physical-projectile-damage-1",
  "physical-projectile-damage-2",
  "physical-projectile-damage-3",
  "physical-projectile-damage-4",
  "physical-projectile-damage-5",
  "physical-projectile-damage-6",
  "physical-projectile-damage-7",
}

local function fix_turret_modifiers(force)
  for _, tech in pairs(tech_list) do
    if force.technologies[tech] and force.technologies["hidden-"..tech] then
      if tech == "physical-projectile-damage-7" then
        force.technologies["hidden-physical-projectile-damage-7"].level = force.technologies[tech].level
      else
        force.technologies["hidden-"..tech].researched = force.technologies[tech].researched
      end
    end
  end
end

script.on_event(defines.events.on_research_finished, function(event)
  fix_turret_modifiers(event.research.force)
end)

script.on_event(defines.events.on_technology_effects_reset, function(event)
  for _, force in pairs(game.forces) do
    fix_turret_modifiers(force)
  end
end)