Prefered Max Patch Sizes

Replaces resource spawning system, so that the distances between resources are much bigger. Railway is needed then.

Moderators: orzelek, Dark

Post Reply
User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Prefered Max Patch Sizes

Post by Muppet9010 »

Is there any chance of adding options to set a prefered maximum patch size range to the mod?
For example, for a multiplayer game, we would like to have patches not be generally bigger than 1 million by a significant quantity after exploring out a reasonable way. We don't want to disable any of the range growth settings, just apply an approximate cap.


I have made a hack to the mod to achieve this (won't publish), but I'm not great at maths so it contains some bodges to avoid the worst side effects.
Included below as a demonstration of the concept.

Changes to control.lua commented

Code: Select all

--[[ entity-field ]]--
--Muppet - modified constructor to add no_reduce (optional argument)
local function spawn_resource_ore(surface, rname, pos, size, richness, startingArea, restrictions, rng, no_reduce)
	-- blob generator, centered at pos, size controls blob diameter
	restrictions = restrictions or ''
	debug("Entering spawn_resource_ore "..rname.." at:"..pos.x..","..pos.y.." size:"..size.." richness:"..richness.." isStart:"..tostring(startingArea).." restrictions:"..restrictions)
	
	--Muppet - added to capture size at start of function 
	local orig_size = size
	
	size = modify_resource_size(rname, size, startingArea)
	local radius = size / 2 -- to radius
later in control.lua\spawn_resource_ore()

Code: Select all

		if startingArea then
			richnessMultiplier = settings.global["rso-starting-richness-mult"].value
		end
--		if game.players[1] then
--			game.players[1].print("Spawning "..rname.." total amount "..(approxDepositSize + validCount * min_amount)*richnessMultiplier)
--		end

		--Muppet - START
		local function utillogging_log(text)
			if game ~= nil then
				game.write_file("RsoMuppet_logOutput.txt", tostring(text) .. "\r\n", true)
			end
		end
		local simple_debug_logging = false
		local detailed_debug_logging = false
		local approxPatchSize = (approxDepositSize + validCount * min_amount)*richnessMultiplier
		if detailed_debug_logging then utillogging_log("RSO stock ore: "..rname.." --- at:"..pos.x..","..pos.y.. " --- approxPatchSize: " .. approxPatchSize .. " --- orig_size: " .. orig_size .. " --- richness: " .. richness) end
		local prefered_max_patch_size = 1000000 -- hard coded for test
		--Only regenerate once if too large
		if (no_reduce == nil or no_reduce == false) and approxPatchSize > prefered_max_patch_size then
			local reduce_factor = math.min(((prefered_max_patch_size / approxPatchSize) * 1.5), 0.8)
			local size_reduce_random = (rng(9, 11) / 10)*1.5
			local richness_reduce_random = (rng(9, 11) / 10)/1.5
			if detailed_debug_logging then utillogging_log("reducing to: " .. reduce_factor .. " --- size_reduce_random: " .. size_reduce_random .. " --- richness_reduce_random: " .. richness_reduce_random) end
			orig_size = math.min((orig_size * (size_reduce_random * reduce_factor)), orig_size)
			richness = richness * (richness_reduce_random * reduce_factor)
			if detailed_debug_logging then utillogging_log("REDCUED ore request: "..rname.." --- at:"..pos.x..","..pos.y.. " --- orig_size: " .. orig_size .. " --- richness: " .. richness) end
			return spawn_resource_ore(surface, rname, pos, orig_size, richness, startingArea, restrictions, rng, true)
		else
			if detailed_debug_logging then utillogging_log("") end
			if simple_debug_logging then utillogging_log("ore generated: "..rname.." --- at:"..pos.x..","..pos.y.. " --- approxPatchSize: " .. approxPatchSize) end
		end
		--Muppet - END
				
		-- infinite ore handling for Angels Ores mod
		local infiniteOrePresent = false
		local infiniteOreName = "infinite-"..rname
When using a Creative Mod Super Radar 2 to explore out it gives the below patch sizes. This is on default RSO settings and only includes patches (not oil) outside of spawn area that have been reduced from above 1 million.
Initial patches generated by radar from outer left side inwards
Last edited by Muppet9010 on Sun May 06, 2018 2:01 pm, edited 2 times in total.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Prefered Max Patch Sizes

Post by orzelek »

It seems to me you are trying to reach some contradictory goals for reasons you did not give.
There is no way to achieve what you want really.

You can't cap ore patch amount at a constant and keep range increase - it will lead to range being ignored pretty quickly. And in that case you can just set richness to around 2 and remove the range scaling completely - effect will be identical with exception of first few thousand tiles. And 1.5k tiles area you used for testing is not a lot - try going out 5k or so to see the results.

Also please check if actual ore amounts are what you printed in log - your code doesn't take into account enforcement of minimum ore value per pile thats done in spawning code. (And it actually seems to have a small bug but thats different story).

User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: Prefered Max Patch Sizes

Post by Muppet9010 »

We want a reason to have to expand the rail network in the end game, both to increase concurrent ore minning and so that patches continue to run out so our mining outposts get further away. In effect creating work for ouselves.
Ideally, so that the patch size did still increase from starting level up to "large" over x tiles (1k-2k tiles) and then stay at this "large" size from there on.

The hope was that the mod would remain vanilla for all increases from spawn and then just "cap" the maximum size at distance. In testing, I used default settings to avoid long waits for generating large maps on my slow pc.
The actual ore amounts appear to be within the expected range logged from a random sample.

I have just tried going out to 4000 tiles and I see what you mean. The results aren't what we desired. I was worried my bodge may not scale nicely.


Will try the settings you suggested and see if we can get something, thanks

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Prefered Max Patch Sizes

Post by orzelek »

You are first person that want's to be.. more busy.
Usually people want ore patches to grow to feed their growing production without rebuilding the outposts very often.

I can see I did cap exponent for distance at 0.1 in settings file so you might need to edit it for game to accept 0 there.
You might also reduce the size increase from distance since size also affects overall richness of resource patch.

I did not do much testing with those set to 0 so strange things might happen :D

User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: Prefered Max Patch Sizes

Post by Muppet9010 »

yea its for a challenge multiplayer game where we want to have to balance base expanding with completing infinite shorter-term objectives.

I tried the suggestion of just setting 0 distance multiplier (in code), but it makes the nearby patches overly large.

looking at your comments with size and richness exponents I understand your comment about my odd "fix" approach. If i apply a limit to the size and richness value in the roll_chunk() function it limits the max growth while still letting the value build-up naturally. The hardcoded example test values below make the average on map around 1.1 million (1.6 is peak value). I went out to 6000 tiles and found that after 3000~ the patch amounts stopped increasing (visually obtained average in-game). So I think this has done what we were after without "breaking" the mod core logic.

Mod values, all default except:
distance ore richness exponent 0.1
distance size exponent: 0.1


added to roll_chunk() before spawn_resource_ore is called:

Code: Select all

					local richness_max = 20000
					local size_max = 30
					if richness > richness_max or size > size_max then
						--logging of reduction
						richness = math.min(richness, richness_max)
						size = math.min(size, size_max)
					end

So I guess my mod request should be; can you consider adding max distance size and distance richness settings.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Prefered Max Patch Sizes

Post by orzelek »

I'd rather not add more setting for very specific approach - I'll modify how exponents work so it doesn't behave strangely when distance is below 1. This will allow to set them to 0 without unwanted effects on close range.
This should mean that ore patches will keep their base richness when going outward and will only vary based on the random factor.

This will also allow you to set factor to about 0.001 or something similar to keep slight increase over distance.

I'll wait few days with release to take a look at other issue thread when I get more info from OP.
I'm attaching modified control.lua so you can take a look and see if it works for you.
Attachments
control.zip
(14.76 KiB) Downloaded 94 times

User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: Prefered Max Patch Sizes

Post by Muppet9010 »

Fair enough.
Thank you for the pointers on my changes.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Prefered Max Patch Sizes

Post by orzelek »

I've attached control lua above (in edit). You'll need to edit settings.lua to allow 0 for distance factor - I'll update it in mod also for next version.

mmppolton
Long Handed Inserter
Long Handed Inserter
Posts: 58
Joined: Sun Apr 16, 2017 11:38 pm
Contact:

Re: Prefered Max Patch Sizes

Post by mmppolton »

i do want a limit too it can be ajust later most map i gen in rso have so big ore patch that it reach a point when the map is done since ore never run out and the base base just run

Post Reply

Return to “Resource Spawner Overhaul”