Funked Ore


Write custom rules to change or mix ore patches. Change every copper patch into a 10-to-1 mix of copper and a random different ore. Or delete all oil patches within 1000 tiles of spawn.

Tweaks
4 days ago
1.1
23
Environment Mining
Owner:
StephenB
Source:
https://github.com/StephenBarnes/FunkedOre
Homepage:
N/A
License:
MIT
Created:
a month ago
Latest Version:
1.1.0 (4 days ago)
Factorio version:
1.1
Downloaded by:
23 users

Inspired by the DivOresity mod by Mylon, and the Ore Chaos mod by unique_2. This mod does something similar, but with more complicated and flexible configuration options.

How to use this mod

See the pictures above for a tutorial.

Why?

I made this for my upcoming modpack, but decided to release it separately so other people can use it too.
So why would you want this in a modpack? There are several reasons:

  • Maybe you want progression to depend on exploring to find a certain ore and hauling it back to your base. But sometimes you get "lucky" enough to have the resource spawn close to your starting position, ruining the progression. So you can use this mod to erase all of that resource close to spawn.
    • For example, the vanilla game has this problem - blue science ought to be locked behind setting up an oil outpost, but sometimes you can already see oil immediately after you spawn. With this mod, you can fix that with a rule like oil(<1000)=>nothing
  • In Factorio's worldgen settings, you can't set ore frequency to lower than 17%, because Wube assumes you are not strong enough to handle lower values. To preserve your pride, you can use this mod to delete some of those ore patches, reducing it further.
    • For example, to delete 2/3 of the iron patches, excluding the starting patch: iron(>400)=>iron/nothing/nothing
  • You can mix ores to create new logistical challenges - outposts will produce multiple ores, in different amounts that you need to balance. If you have an iron shortage, but all your iron mining operations are on combined iron+copper patches, and your copper lines are saturated, then you have a problem. It's a bit like what Bob/Angel does with ore processing, except the mixing appears when the ore is mined, rather than when it is crushed/washed/sorted.
    • For example, in a vanilla game, you could use something like this: iron => 9iron+copper / 2iron+copper & copper => 9copper+iron / 2copper+iron & coal => 20coal+stone / 3coal+stone & stone => stone / 2stone+coal
  • You can use it to make ores more mixed as distance from spawn increases, to add new challenges as the base expands.
    • For example: copper(>500)(<2000)=>3copper+1iron & copper(>2000)=>1copper+1iron

When using Funked Ore, be careful not to screw up your modpack's balance. If you take vanilla Factorio and just add a reasonable-looking rule like copper=>copper+iron & iron=>copper+iron, the player won't have exactly the same demand for copper and iron, so now you've forced them to build tons of chests to store unneeded copper.

Mod compatibility

  • Fully compatible with Bob's Ores, Angel's Refining, and Industrial Revolution 3.
  • Should be compatible with any other mod that adds new ores.
  • Resource Spawner Overhaul (RSO) is not compatible. Ore patches are sometimes changed, sometimes not, sometimes half the patch is changed. Not sure why.
  • Mods that spawn very large resource patches, like dangOreus, will work. However, if you have transform rules with slashes, such as iron=>copper/stone, the mod will count all nearby iron as the same patch, so it will all become copper. You can fix this by setting the "early stopping distance" to zero and the "reproduction distance" to a high value like 500.

If you write a rule for a modded game but FunkedOre says an ore from the mod does not exist: Find the ore in the world, hold your mouse over it, and press ctrl-shift-F. You will get a window with info about the ore's prototype, including the "name". When writing your rules, you should use that name for it.

Adding/changing/removing in an existing game

  • If you add the mod to an existing game, the transform rules will only apply to new ore patches that are generated, not to already-existing patches.
  • If you change the "transform rules" setting, the new transform rules will apply to new ore patches that are generated, though patches that have already been partially generated will still use the old rules.
  • If you remove the mod from an existing game, ores that have already been changed will stay changed, but newly generated ore patches will not be changed.

Things to fix/add

Pull requests welcome. I don't have any plans to implement/fix the issues below any time soon, because the mod as it is right now is enough for my modpack.

  • Add RSO compatibility. (This is not as simple as adding an optional dependency on RSO, I checked.)
  • Currently all transform rules are applied on all surfaces. Add a way to restrict to specific surfaces or specify different rules for different surfaces. Maybe use a syntax like stone(@nauvis)=>whatever & stone(@gleba)=>whatever, and handle it the same way distance arguments are handled.
  • Add a way to multiply the richness of tiles, so you could do something like stone => 1stone*5+4nothing to delete 80% of the tiles in stone patches but make the remaining tiles 5x richer.
  • Add a way to specify probability weights for the mix options, so you can have rules like stone => stone+iron / stone+copper / 8: stone+coal to make 80% of stone patches get converted to stone and coal while 10% get converted to stone+iron and 10% get converted to stone+copper. Note that you can already do this by just repeating the mix option multiple times, like iron=>iron/iron/iron/nothing will delete 25% of iron ore patches; but it would be nice to do this more compactly.
  • This mod cannot (yet) change ore patches after they've been generated and converted the first time. For that, try Schall Ore Conversion. Funked Ore could do something similar if you add a console command or selection tool or something that takes a string argument with some transform rules, and then applies those rules to the entire surface, or to any ore patch you select.

Technical details

The transform string setting is re-parsed every time the setting changes, with the parsed table logged to factorio-current.log. The mod listens to the on-chunk-generated event, and whenever it fires, it checks if the transform setting needs to be re-parsed, then applies the parsed transform rules to all resource entities in the new chunk.

In a rule like iron=>copper+coal, there is only one "mix option" (namely copper+stone) applied over any patch, while in a rule like iron=>copper/stone there are two mix options (copper and stone). If there's more than one mix option, we need to decide which of the two options to pick for each ore patch, and the choice must be consistent over that ore patch - we must not change partway through, or pick it independently for every ore entity. This is a problem because Factorio doesn't generate ore by choosing centers for ore "patches" and then drawing circles around those centers; it generates ores wherever a noise function is over some threshold. So we need some system for deciding what counts as one patch. There are multiple ways to do this, but this mod uses a system based on "control points".

A control point is a position plus a chosen mixture applied at that point. When we need to transform an ore, we look for nearby control points for that particular ore. If there are no existing control points within the "reach distance" setting, we pick a mix to use and place a new control point at that position. If there are control points within the "reach distance", we find the closest one and use the same mix. When looking for the closest one, we have an "early stopping distance" setting so we don't need to look through all the control points every time. These control points are stored in globals so they are saved/loaded with the game.

There is one additional detail. When we change an ore tile with a nearby control point, but the control point is outside the "reproduction distance", we place a new control point with the same mix. This has two benefits: it causes early stopping to occur more frequently, saving time, and it also causes control points to spread across a large ore patch, ensuring consistency of the mix choice. You can think of it as a sort of sparse flood fill.