Help: Activating burner leech via research

Place to get help with not working mods / modding interface.
Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Help: Activating burner leech via research

Post by Honktown »

darkfrei wrote:
Tue Jan 28, 2020 6:54 pm
Honktown wrote:
Tue Jan 28, 2020 3:38 pm
darkfrei wrote:
Tue Jan 28, 2020 2:30 pm
4) partially [1], but the technology unlocks the recipe to convert normal inserters into leeches.
That's... not a bad idea. The recipe could take .5 seconds and cost nothing, and would be available via upgrade planner and completely bypass blueprinting issues.
The code wasn't tested, but must be clear. We made the technology and then going through all inserters. If the inserter is not leech, then we made new leech inserter, new recipe to convert old inserter into the new one, then adding this recipe to the technology effects.

Code: Select all

local prototypes = {}

local new_technology = {
    type = "technology",
    name = "leech-inserters",
    icon_size = 128,
    icon = "__new_mod_name__/graphics/technology/leech-inserters.png", -- picture 128x128
    enabled = false, 
    effects = {},
    unit.count = 8,
    unit.ingredients = {{"automation-science-pack", 1}},
    unit.time = 1,
    order = "li-a", 
  }

for inserter_name, inserter_prototype in pairs (data.raw.inserter) do
  if not (inserter_prototype.allow_burner_leech) then
    --create new prototype!
    local new_inserter_prototype = table.deepcopy (inserter_prototype)
    local new_inserter_name = 'leech-' .. inserter_name
    new_inserter_prototype.name = new_inserter_name
    new_inserter_prototype.minable = {mining_time = 0.1, result = new_inserter_name} 
    new_inserter_prototype.allow_burner_leech = true
    table.insert (prototypes, new_inserter_prototype)
    
    -- recipe for it
    local new_recipe = {
        type = 'recipe',
        name = new_inserter_name,
        ingredients = {{inserter_name, 1}},
        result = new_inserter_name
      }
     table.insert (prototypes, new_recipe)
     
     -- add them to the technology effect
     table.insert(new_technology.effects, {type = "unlock-recipe", recipe = new_inserter_name})
  end
end

if #prototypes > 1 then -- vanilla cannot be extended with empty table; you don't need the technology without effects
  table.insert (prototypes, new_technology)
  data:extend (prototypes)
end
1) need to add items for each inserter

2) stuff needs to be added to proper sections (data.raw.inserter, item, recipe).

I'd probably do some minor style changes: directly do data.raw.inserter["leeching-" .. other_inserter.name] = table.deepcopy(other_inserter), inserter = data.raw.inserter["leeching-" .. other_inserter.name] and continue to edit that way, unless there's additional modifications you want to do after. You can always do the deepcopy, and then store the table into an "our" table, or vice-versa, store into "our" table, and then a for name, inserter in pairs(leeching_prototypes) do data.raw.inserter[name] = inserter

I think table.deepcopy requires "util" from base or core.

Edit: don't forget to add the technology itself!
Last edited by Honktown on Tue Jan 28, 2020 7:08 pm, edited 2 times in total.
I have mods! I guess!
Link

Molay
Fast Inserter
Fast Inserter
Posts: 177
Joined: Thu May 01, 2014 8:01 am
Contact:

Re: Help: Activating burner leech via research

Post by Molay »

Just to be clear. As scenarios are severely limited an can not use things like data:extend, can I circumvent that by bundling my scenarios in an overlying mod, putting this code in a file within the mod, and then call it from control.lua in the scenario folder within the mod?

There's a few bits in the campaign that may require other mods. Like alien biomes for a couple missions. Will this successfully load into my scenario, even if outside the mod folder containing the scenarios? (Not even sure if I can package all scenarios in one mod or if I need many).

I have to say working with scenarios is surprisingly more difficult than I had anticipated.

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Help: Activating burner leech via research

Post by Honktown »

Molay wrote:
Tue Jan 28, 2020 7:07 pm
Just to be clear. As scenarios are severely limited an can not use things like data:extend, can I circumvent that by bundling my scenarios in an overlying mod, putting this code in a file within the mod, and then call it from control.lua in the scenario folder within the mod?

There's a few bits in the campaign that may require other mods. Like alien biomes for a couple missions. Will this successfully load into my scenario, even if outside the mod folder containing the scenarios? (Not even sure if I can package all scenarios in one mod or if I need many).

I have to say working with scenarios is surprisingly more difficult than I had anticipated.
Scenarios are stored in a separate folder than mods. I honestly don't know if you can even add them from a mod. You can disable certain things if you are/are not in a scenario (event on_game_created_from_scenario).
I have mods! I guess!
Link

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help: Activating burner leech via research

Post by darkfrei »

Honktown wrote:
Tue Jan 28, 2020 7:07 pm
1) need to add items for each inserter
You are right
Honktown wrote:
Tue Jan 28, 2020 7:07 pm
2) stuff needs to be added to proper sections (data.raw.inserter, item, recipe).
No, just put it into the data:extend().
Honktown wrote:
Tue Jan 28, 2020 7:07 pm
Edit: don't forget to add the technology itself!
Already here!

Code: Select all

  table.insert (prototypes, new_technology)
  data:extend (prototypes)

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Help: Activating burner leech via research

Post by Honktown »

darkfrei wrote:
Tue Jan 28, 2020 7:17 pm
...
Ah, I missed that the recipe was added to prototypes. I don't know if there's a page on data:extend anywhere (would like to know more). I mainly used C89/other old stuff so a lot of my editing is direct and primitive :)
I have mods! I guess!
Link

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Help: Activating burner leech via research

Post by eradicator »

Molay wrote:
Tue Jan 28, 2020 7:07 pm
Just to be clear. As scenarios are severely limited an can not use things like data:extend, can I circumvent that by bundling my scenarios in an overlying mod, putting this code in a file within the mod, and then call it from control.lua in the scenario folder within the mod?
Yes, but the other way around. You can make a mod that does the nessecary data changes and include the scenario inside the mod.zip in a subfolder just like base mod* includes freeplay etc. You don't need to call anything from the scenarios control.lua because the scenario will only be available when the mod is active anyway. But if you want to you can use require("__my-mod-name__/some/file.lua") to fetch stuff like libraries from the mod directory.

*Base really is a mod. So if it can do something so can you!
Molay wrote:
Tue Jan 28, 2020 7:07 pm
There's a few bits in the campaign that may require other mods. Like alien biomes for a couple missions.
If you need other mods you can simply depend on them in info.json.
However this means that the other mods will be active for *all* scenarios, not just a subset (that's just how mods work). So if you want to enforce a specific "mod pack" for each scenario then you have to scan game.active_mods in script.on_init, and inform the user...somehow. There's no official support for any sort of scenario-based mod restrictions. Not too difficult if you just want "at least these mods". More annoying if you want "exactly these mods and nothing else".
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”