Resource Spawner Overhaul

by orzelek

Makes resources more sparse than base game. You will need to use trains much earlier to get resources. Game will be more difficult especially with higher enemy settings.

Tweaks
22 hours ago
0.14 - 2.0
143K
Environment

i Interface for mod defined region and find_random_chunk

2 years ago

When using a custom map generator RSO has no way of knowing where to place ores. It simply divides the map into rectangular regions and randomly places ores in each region.

So my suggestion is to change both those things to make it possible for mods to override them:

The first is in roll_region:

local function roll_region(surface, c_x, c_y)
--in what region is this chunk?
local r_x=floor(c_x/REGION_TILE_SIZE)
local r_y=floor(c_y/REGION_TILE_SIZE)

This should be a call to a function that mods can override and should probably return the center of a region or nil if outside of anywhere resources should be placed.

The other place is

local function find_random_chunk(r_x, r_y, rng)

This returns a random chunk inside the region. A mod might want to overload this so it uses a different distribution, e.g. favor ores in the center of regions or avoid chunks next to water. Changing the distribution will make regions become obvious as a pattern in the map but when the regions aren't just rectangles covering all the map that isn't a bad thing.

Other functions that will have to be adapted:

local function is_same_region(c_x1, c_y1, c_x2, c_y2)

This has to find the region for each point and compare them.

local function find_random_neighbour_chunk(ocx, ocy, rng)

For best results this should be overridable too. For example a mod might generate an island map with nice beaches flowing into grassy and wooded areas and mountain peaks in the middle with stone. Ores could be preferred in the mountains with smaller probability for the wooded areas. But if a wood chunk was picked initially then neighbour chunks should not include any beach chunks. (I know chunks won't be always one type but the occasional ore on beach because the chunk is half/half is fine).

Note: this function is the only to call is_same_region.

New response