How to rewrite drill behavior?

Place to get help with not working mods / modding interface.
computerneek
Burner Inserter
Burner Inserter
Posts: 7
Joined: Thu May 23, 2019 8:45 am
Contact:

How to rewrite drill behavior?

Post by computerneek »

I have a bit of a problem. It's a rather unusual problem...

Thing is, I'm using an infinite-ores mod on my world, so the mining drills display such numbers as 350/s... yet still produce at their 0.5/s rate. What's more, if the overall drill has a displayed rate of 60/s or so but one of the ores it's on has a yield of just 8% (I have one such drill), it'll occasionally produce 0/s for several seconds while it tries to mine that.

The solution... As a programmer, I want to make a mod, to rework how the drills work. What this mod would do, is get it to always produce 1 ore each time it finishes a job- but the duration of that job would vary dynamically with the yield of the ores under it. I'd have it calculate the rates for each affected ore and calculate the best one to drill from, resulting in a (gradual) evening of infinite resource amounts long before it hits the minimum. Which, I may also want to adjust those minimums... Non-infinite ores would be treated as 100% yield until depleted, configurable.

The problem is, I can't find any documentation or anything on how to modify the algorithm that works the drill, only configuration for it. Is that accessible to mods? If so, how?
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: How to rewrite drill behavior?

Post by Adamo »

computerneek wrote: Mon Aug 12, 2019 12:43 am
All you really get to play with are the resource prototype, mining-drill prototype, and scripting in control.lua. The amount of resource and speed with which it gets mined is in the resource prototype, e.g., from the deep core drilling mod,

Code: Select all

minable =
    {
      mining_time = miningtime*2,
      mining_particle = miningparticle,
      results =
      {
        {
          type = "item",
          name = ore_result,
          amount_min = 4,
          amount_max = 4,
          probability = 1
        }
      }
},
The mining drill can of course have a speed, but the only way I know of to vary that speed would be with any of the stuff available in the prototype or the API(e.g. you can set the productivity bonus through a control script on a luaentity, see here: https://lua-api.factorio.com/latest/LuaEntity.html).

To be honest, I'm not sure there's going to be an easy way to do what you want to do, but starting ground up to find all your options I think would be to look at everything available in the resource prototype and controls, and then the mining-drill prototype. That's pretty much all the access you have, and then anything else would need to be written in control.lua. Of course you can write a control.lua script that recognizes a new mining-drill you've created that puts ore into its output box according to some new algorithm you wrote, but I think this is generally considered to be CPU-intensive and undesirable. I did something not totally dissimilar, that makes compilatrons walk around and eat trees, pooping them out in a box once they get full, so it can be done, but I had to be very cautious about optimizing the code so it didn't use a lot of cycles.
computerneek
Burner Inserter
Burner Inserter
Posts: 7
Joined: Thu May 23, 2019 8:45 am
Contact:

Re: How to rewrite drill behavior?

Post by computerneek »

Yeah, it does look like the access is not granted. Since the idea is to make the drill more consistent without modifying individual ores or drills, so it'd work with all non-special modded ores, it seems to be impossible. No event fires when the drill produces... and without overwriting ore deposits (and opening an entire can of worms related to that), there's no real way to guarantee the thing actually produces each time it finishes its task! Maybe I can make it a feature request, as this mod- and algorithm change- wouldn't make any behavior change on an otherwise vanilla world. Or any world without an infinite resource accessible by mining drill...

Lag shouldn't be an issue, since it wouldn't do much more processing than a circuit network "read minable" operation.
Post Reply

Return to “Modding help”