Command to spawn a naturally-looking ore patch

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

Moderators: Dark, orzelek

Post Reply
YunoAloe
Long Handed Inserter
Long Handed Inserter
Posts: 94
Joined: Tue Mar 12, 2019 9:22 pm
Contact:

Command to spawn a naturally-looking ore patch

Post by YunoAloe »

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?

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

Re: Command to spawn a naturally-looking ore patch

Post by orzelek »

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?
RSO only spawns those automatically based on random rolls. There is no interface to spawn certain ore patch at specific location.
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.

YunoAloe
Long Handed Inserter
Long Handed Inserter
Posts: 94
Joined: Tue Mar 12, 2019 9:22 pm
Contact:

Re: Command to spawn a naturally-looking ore patch

Post by YunoAloe »

orzelek wrote:
Sun Jun 30, 2019 4:05 pm
Question is what do you mean by naturally looking ore patch - RSO can only spawn ones similar to what it generates already.
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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 4049
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Command to spawn a naturally-looking ore patch

Post by eradicator »

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
blob.jpg (92.74 KiB) Viewed 1448 times
Author of: Hand Crank Generator, Screenshot Hotkey 2.0, /sudo
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

YunoAloe
Long Handed Inserter
Long Handed Inserter
Posts: 94
Joined: Tue Mar 12, 2019 9:22 pm
Contact:

Re: Command to spawn a naturally-looking ore patch

Post by YunoAloe »

Yep, looks better than a square. :) Thank you.

Post Reply

Return to “Resource Spawner Overhaul”

Who is online

Users browsing this forum: No registered users