Help: Activating burner leech via research

Place to get help with not working mods / modding interface.
Molay
Fast Inserter
Fast Inserter
Posts: 203
Joined: Thu May 01, 2014 8:01 am
Contact:

Help: Activating burner leech via research

Post by Molay »

I'm working on a set of scenarios and would like to enable the burner leech [mod] functionality during the playthrough with a research (to make players aware of it in an organic way). How would I go about disabling it when loaded and activating it after a certain research?
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help: Activating burner leech via research

Post by darkfrei »

Technology: Recipe unlock: leech inserter.
Molay
Fast Inserter
Fast Inserter
Posts: 203
Joined: Thu May 01, 2014 8:01 am
Contact:

Re: Help: Activating burner leech via research

Post by Molay »

It's that easy? Thank you!
User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 3110
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Help: Activating burner leech via research

Post by BlueTemplar »

It isn't, because it's not a new dedicated inserter, but instead new functionality for burner inserters ?
BobDiggity (mod-scenario-pack)
Molay
Fast Inserter
Fast Inserter
Posts: 203
Joined: Thu May 01, 2014 8:01 am
Contact:

Re: Help: Activating burner leech via research

Post by Molay »

Yes it's a new functionality for an existing entity. I haven't had a chance yet to test it.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help: Activating burner leech via research

Post by darkfrei »

I mean that you need to add new leech inserter on data stage and unlock it as the technology effect.
User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: Help: Activating burner leech via research

Post by AmatorPhasma »

Its not that easy, you can't use the build-in function:
https://lua-api.factorio.com/latest/Lua ... rner_leech
it's read only and can only be set in the data stage.

And to todo it with a own script is not that easy, you can look into my script, this also clears the burnt-fuel-inventroy from machines.
"Disclaimer: this script is not the nicest code :D"
User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 3110
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Help: Activating burner leech via research

Post by BlueTemplar »

darkfrei wrote: Mon Jan 27, 2020 3:48 pm I mean that you need to add new leech inserter on data stage and unlock it as the technology effect.
This would also work poorly with mods adding other burner inserters or those that convert electric inserter to burner ones ?
BobDiggity (mod-scenario-pack)
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help: Activating burner leech via research

Post by darkfrei »

BlueTemplar wrote: Mon Jan 27, 2020 5:05 pm
darkfrei wrote: Mon Jan 27, 2020 3:48 pm I mean that you need to add new leech inserter on data stage and unlock it as the technology effect.
This would also work poorly with mods adding other burner inserters or those that convert electric inserter to burner ones ?
Change them as you want.

Code: Select all

for inserter_name, inserter_prototype in pairs (data.raw.inserter) do
  -- do what you want, for example
  inserter_prototype.allow_burner_leech = true
end
Another solution: enable them if they are fuel leeches. Look through all inserter and this list can be used by technology effects.
Molay
Fast Inserter
Fast Inserter
Posts: 203
Joined: Thu May 01, 2014 8:01 am
Contact:

Re: Help: Activating burner leech via research

Post by Molay »

Thank you so much darkfrei! I'm still in the process to getting accustomed to LUA and factorio modding and this has been most helpful. I really want a campaign so I'll have to learn a lot ;) lovely to have such a helpful community around!

Cheers guys
Honktown
Smart Inserter
Smart Inserter
Posts: 1042
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Help: Activating burner leech via research

Post by Honktown »

You can write a control script that does a lot of things when the tech is researched. I don't know how to convert entities doing stuff, but you could create a duplicate inserter in the data phase. When the research finishes, convert all the specific inserters on all surfaces, and then enable a conversion when a player or robot builds it. Not sure how it works with blueprints, but the mining result of the new inserter can be the old one, since it is on building it is changed.
I have mods! I guess!
Link
User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 3110
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Help: Activating burner leech via research

Post by BlueTemplar »

darkfrei wrote: Mon Jan 27, 2020 7:01 pm
BlueTemplar wrote: Mon Jan 27, 2020 5:05 pm
darkfrei wrote: Mon Jan 27, 2020 3:48 pm I mean that you need to add new leech inserter on data stage and unlock it as the technology effect.
This would also work poorly with mods adding other burner inserters or those that convert electric inserter to burner ones ?
Change them as you want.

Code: Select all

for inserter_name, inserter_prototype in pairs (data.raw.inserter) do
  -- do what you want, for example
  inserter_prototype.allow_burner_leech = true
end
Another solution: enable them if they are fuel leeches. Look through all inserter and this list can be used by technology effects.
AFAIK, both Burner Leech and InserterFuelLeech do quite a bit more than just inserter_prototype.allow_burner_leech ? Could not it get complicated, fast ?
BobDiggity (mod-scenario-pack)
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help: Activating burner leech via research

Post by darkfrei »

BlueTemplar wrote: Tue Jan 28, 2020 12:06 am AFAIK, both Burner Leech and InserterFuelLeech do quite a bit more than just inserter_prototype.allow_burner_leech ? Could not it get complicated, fast ?
The Inserter Fuel Leech is the fork of Klonan's mod, all stuff is done via the script.

The Burner Leech has both parts, but my opinion is, that the C++ side (vanilla Factorio engine) is enough. I haven't tested it before.

So it must be enough to set inserter_prototype.allow_burner_leech = true in data stage and it works as expected.
User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 3110
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Help: Activating burner leech via research

Post by BlueTemplar »

Zaflis wrote:
kingarthur wrote:all the leech function does is allow a burner inserter to take fuel out of a assembler/furnace to feed its self if its set to pull items out from that entity
But it will only ever pull fuel from the input side of inserter. If it puts in an assembler that already has coal in, it can't take it out.
BobDiggity (mod-scenario-pack)
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Help: Activating burner leech via research

Post by eradicator »

Summary:

1) data-final-fixes method:
Make a copy of every fucking inserter. In on_research_finished replace every fucking normal inserter in the entire world with it's leech-enabled version. Edit: Oh, and replace all assembler recipes and all inserter items in the world, or try and fail to monitor every fucking on_built event.
Benefit: No on_tick UPS cost, relatively low moderate maintenance cost.
Drawback: Huge UPS spike when replacing (not as bad if the scenario only allows small factories), can't be done in pure control.lua.

2) scripted leech method:
Hope that none of the inserters have have leech enabled in the prototype. Dis/Enable the script as you like.
Benefit: Allows clean dis/enabled in pure control.lua.
Drawback: Scripts have a continous UPS cost and are more prone to bugs. If the licenses allows to steal someone elses code it might not be too bad. And if the scenario implies that burners are not used in huge quantities (early-game-only) the UPS cost might be negligible.

3) fake method:
Add a technology with an empty effect that describes the leech-effect but doesn't actually change anything. This would make the player *aware* of the leech feature.
Benefit: Trivial to implement and maintain.
Drawback: Players can use leech without the technology if they know how to do it.
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.
Honktown
Smart Inserter
Smart Inserter
Posts: 1042
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Help: Activating burner leech via research

Post by Honktown »

eradicator wrote: Tue Jan 28, 2020 1:16 pm Summary:

1) data-final-fixes method:
Make a copy of every fucking inserter. In on_research_finished replace every fucking normal inserter in the entire world with it's leech-enabled version. Edit: Oh, and replace all assembler recipes and all inserter items in the world, or try and fail to monitor every fucking on_built event.
Benefit: No on_tick UPS cost, relatively low moderate maintenance cost.
Drawback: Huge UPS spike when replacing (not as bad if the scenario only allows small factories), can't be done in pure control.lua.

2) scripted leech method:
Hope that none of the inserters have have leech enabled in the prototype. Dis/Enable the script as you like.
Benefit: Allows clean dis/enabled in pure control.lua.
Drawback: Scripts have a continous UPS cost and are more prone to bugs. If the licenses allows to steal someone elses code it might not be too bad. And if the scenario implies that burners are not used in huge quantities (early-game-only) the UPS cost might be negligible.

3) fake method:
Add a technology with an empty effect that describes the leech-effect but doesn't actually change anything. This would make the player *aware* of the leech feature.
Benefit: Trivial to implement and maintain.
Drawback: Players can use leech without the technology if they know how to do it.
1) The entity replacements can be spread out. Find all inserters on the surfaces, divide by s seconds * 60 ticks, and only replace n inserters per tick. Benefit: to find the number of replaceable inserters, you also have the entity table, and only need to find_entities_filtered on the first tick. If there's more than one kind of inserter, you can spread out that, too. You don't have to replace the recipes nor items, because inserters can be changed on placement/mining (the mining result is static in prototypes, on placement would be control events), they do not need to be changed in inventory(s). Only drawback I see is blueprinting.

2) Haha no. That would be such a massive UPS overhead.

3) I'm trying to think of a better way to restrict an inserter but I can't think of any.
I have mods! I guess!
Link
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help: Activating burner leech via research

Post by darkfrei »

4) partially [1], but the technology unlocks the recipe to convert normal inserters into leeches.
Honktown
Smart Inserter
Smart Inserter
Posts: 1042
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 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.
I have mods! I guess!
Link
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Help: Activating burner leech via research

Post by eradicator »

darkfrei wrote: Tue Jan 28, 2020 2:30 pm 4) partially [1], but the technology unlocks the recipe to convert normal inserters into leeches.
Congratualtions. 1 was the ugliest option for the programmer. You managed to make it the ugliest option for the player instead :twisted: .
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.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
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 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
Post Reply

Return to “Modding help”