Command to spawn a naturally-looking ore patch
Command to spawn a naturally-looking ore patch
There's a command to spawn a square resource patch at https://wiki.factorio.com/Console#Add_n ... urce_patch. I tried to look for a full list of RSO's commands, but there doesn't seem to be one, or there are only very few special commands implemented at all. So I'm looking for any way to manually spawn naturally looking ore patches. Can anybody help please?
Re: Command to spawn a naturally-looking ore patch
RSO only spawns those automatically based on random rolls. There is no interface to spawn certain ore patch at specific location.YunoAloe wrote: ↑Sun Jun 30, 2019 3:30 pm There's a command to spawn a square resource patch at https://wiki.factorio.com/Console#Add_n ... urce_patch. I tried to look for a full list of RSO's commands, but there doesn't seem to be one, or there are only very few special commands implemented at all. So I'm looking for any way to manually spawn naturally looking ore patches. Can anybody help please?
Adding that kind of interface could work but it will not be fully recognized - it would get removed when regenerating ores for example. And it wouldn't be counted for natural spawn limits.
Question is what do you mean by naturally looking ore patch - RSO can only spawn ones similar to what it generates already. And it would not be able to spawn exaclty what you want in terms of size for example - there is a lot of calculations going to create nice patch shape.
Best what it could potentially do would be a method that asks for ore name (needs to be ingame name can't parse natural displayed name I think) and location, size and approximate richness of patch. It would then proceed with normal generation schema (it will very richness by certain amount and potentially modify size) and then place what it calculated.
I'd need to check how easy it is to add it but it might mean some non-trivial work to make sure it won't break anything.
Re: Command to spawn a naturally-looking ore patch
Natural shape is whatever it spawns naturally, not a square. I'm looking for this as a balance feature, since ABPy+SpaceX game is hard to predict on how much of which ores will really be needed (some people even use infinite ores for that). I tried regenerating chunks in many various ways, but they're all bad for one reason or other, especially if all I need is just one big molybdenum patch, and I can't expand very far due to performance reasons. I thought maybe there's a way to randomize the shape using some vanilla functions.
This isn't critical though. If it means unnecessary effort, I can live with a square.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Command to spawn a naturally-looking ore patch
Gosh. I've never done ore patch generation, but here's a crude, ugly and inefficient code bit that generates a circular-ish-shaped ore blob at your current position. You can tune the tile count, total amount and ore type at the top.
Code: Select all
/c
local name = 'iron-ore'
local amount = 50000000
local tiles = 4000
local w_max = 256
local h_max = 256
local abs = math.abs
local biases = {[0] = {[0] = 1}}
local t = 1
local function grow(grid,t)
local old = {}
local new_count = 0
for x,_ in pairs(grid) do for y,__ in pairs(_) do
table.insert(old,{x,y})
end end
for _,pos in pairs(old) do
local x,y = pos[1],pos[2]
local bias = grid[x][y]
for dx=-1,1,1 do for dy=-1,1,1 do
local a,b = x+dx, y+dy
if (math.random() > 0.9) and (abs(a) < w_max) and (abs(b) < h_max) then
grid[a] = grid[a] or {}
if not grid[a][b] then
grid[a][b] = 1 - (t/tiles)
new_count = new_count + 1
if (new_count+t) == tiles then return new_count end
end
end
end end
end
return new_count
end
repeat
t = t + grow(biases,t)
until t >= tiles
local pos = game.player.position
local total_bias = 0
for x,_ in pairs(biases) do for y,bias in pairs(_) do
total_bias = total_bias + bias
end end
for x,_ in pairs(biases) do for y,bias in pairs(_) do
game.player.surface.create_entity{
name = name,
amount = amount * (bias/total_bias),
force = 'neutral',
position = {pos.x+x,pos.y+y},
}
end end
- Attachments
-
- blob.jpg (92.74 KiB) Viewed 33911 times
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Command to spawn a naturally-looking ore patch
Yep, looks better than a square. Thank you.
Re: Command to spawn a naturally-looking ore patch
I know, I know, I'm necro-ing an old thread.
I just wanted to say thanks for the script - it's very useful! It's great to use when I add a mod that adds a resource after I've started a game.
I just wanted to say thanks for the script - it's very useful! It's great to use when I add a mod that adds a resource after I've started a game.
Re: Command to spawn a naturally-looking ore patch
Awesome. Parameterized and all! Thank you for leaving such an awesome script for Ore generationeradicator wrote: ↑Sun Jun 30, 2019 6:49 pm Gosh. I've never done ore patch generation, but here's a crude, ugly and inefficient code bit that generates a circular-ish-shaped ore blob at your current position. You can tune the tile count, total amount and ore type at the top.
Code: Select all
/c local name = 'iron-ore' local amount = 50000000 local tiles = 4000 local w_max = 256 local h_max = 256 local abs = math.abs local biases = {[0] = {[0] = 1}} local t = 1 local function grow(grid,t) local old = {} local new_count = 0 for x,_ in pairs(grid) do for y,__ in pairs(_) do table.insert(old,{x,y}) end end for _,pos in pairs(old) do local x,y = pos[1],pos[2] local bias = grid[x][y] for dx=-1,1,1 do for dy=-1,1,1 do local a,b = x+dx, y+dy if (math.random() > 0.9) and (abs(a) < w_max) and (abs(b) < h_max) then grid[a] = grid[a] or {} if not grid[a][b] then grid[a][b] = 1 - (t/tiles) new_count = new_count + 1 if (new_count+t) == tiles then return new_count end end end end end end return new_count end repeat t = t + grow(biases,t) until t >= tiles local pos = game.player.position local total_bias = 0 for x,_ in pairs(biases) do for y,bias in pairs(_) do total_bias = total_bias + bias end end for x,_ in pairs(biases) do for y,bias in pairs(_) do game.player.surface.create_entity{ name = name, amount = amount * (bias/total_bias), force = 'neutral', position = {pos.x+x,pos.y+y}, } end end