MrSmoothieHuman wrote: ↑Sun Aug 06, 2023 6:49 pm
if you really dont mind me asking, since i dont want to go offtopic from my original point, but how do you implement autoplace? i copied over the uranium ore code (without realising why the code was different from the normal 4 ores), but it seems to all work after name-changes and things.
However, i (think) i have succesfully implemented autoplace into my code […]
but of course, i want to be sure i have everything down correctly. Sorry if its too offtpoic, but thank you for helping so far!
So far, I have no personal experience in modding resources. But you are calling the function resource_autoplace_settings defined in data/core/lualib/resource-autoplace.lua, which is preceded by this comment:
Code: Select all
--- Creates and returns an AutoplaceSpecification that will generate spot-based ore patches.
-- Required parameters:
-- - name - name for the type, used as the default autoplace control name and patch set name
-- (each of which can be overridden separately)
-- - base_density - amount of stuff, on average, to be placed per tile
-- Optional parameters:
-- - patch_set_name - name of the patch set; patches sets of the same name and seed1 will overlap; default: name
-- - autoplace_control_name - name of the corresponding autoplace control; default: name
-- - random_probability - probability of placement at any given tile within a patch; default: 1
-- - base_spots_per_km2 - number of patches per square kilometer near the starting area
-- - has_starting_area_placement - true|false|nil - yes, no, and there is no special starting area, respectively
-- - seed1 - random seed to use when generating patch positions; default: 100
-- More obscure parameters can be read about in the inline comments.
According to your screenshot, the required parameter base_density is missing, so you should fix that. Comparing the code of the function with your screenshot, "name" seems to be the only valid parameter you've used. Also, the description of
AutoplaceSpecification doesn't contain anything about "type", "category", "richness", and "can_be_disabled". There are some parameters you didn't include (e.g. "order" and "control"), but it seems the function will provide default values to fall back on.
Regarding "richness", this is not supposed to be a Boolean value. Instead, there are "richness_base", "richness_multiplier", and "richness_multiplier_distance_bonus" which will be used to
calculate richness.
In
Pyanodons Raw Ores, I've found two different ways to set "autoplace". This one is used for pure ores (e.g. in prototypes/ores/aluminium.lua):
Code: Select all
autoplace = resource_autoplace.resource_autoplace_settings {
name = "ore-aluminium",
order = "b",
base_density = 10,
base_spots_per_km2 = 1.25,
has_starting_area_placement = true,
random_spot_size_minimum = 2,
random_spot_size_maximum = 4,
regular_rq_factor_multiplier = 1,
starting_rq_factor_multiplier = 2,
candidate_spot_count = 20
},
This one is used for a combination of a particular ore and rock, which seems to not use resource_autoplace.resource_autoplace_settings (e.g. in prototypes/ores/aluminium-rock.lua):
Code: Select all
autoplace = {
name = "aluminium-rock",
order = "b-aluminium-rock",
-- We return the chance of spawning on any given tile here
probability_expression = noise.define_noise_function( function(x, y, tile, map)
-- This is the user's map setting for the frequency of this ore
local frequency_multiplier = noise.var("control-setting:aluminium-rock:frequency:multiplier")
-- 0% chance of spawning in starting area (tier == 0)
-- Using this is equivalent to has_starting_area_placement = false
local tier = noise.clamp(noise.var("tier"), 0, 1)
-- 1 in 64 chunks (each chunk is 64x64 tiles)
local desired_frequency = 1 / (64 * 64^2)
-- Our final chance, likely a very, very small decimal
return tier * desired_frequency * frequency_multiplier
end),
-- We return the richness here, which is just the quantity the resource tile yields
richness_expression = noise.define_noise_function( function(x, y, tile, map)
-- This is the user's map setting for richness of this ore
-- We ignore size here because we're always a single tile resource
local richness_multiplier = noise.var("control-setting:aluminium-rock:richness:multiplier")
-- This is the distance from the starting position, which is how vanilla scales ore yield
local distance_value = noise.var("distance")
-- This is our multiplier for the above, determining the yield gains over distance
local scalar = 2^16
-- Add it all together or what is likely a pretty big number
return distance_value * scalar * richness_multiplier
end)
},
I hope these examples are useful! Otherwise, you should open a separate thread regarding autoplacing of resources. This would increase your chances that some real experts in this field may help you.