Can I limit where ores can spawn? Or hook into on_chunk_generated handler?

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

Moderators: orzelek, Dark

mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Can I limit where ores can spawn? Or hook into on_chunk_generated handler?

Post by mrvn »

I'm playing around with providing custom elevation functions to generate fractal maps like this:
h-tree.png
h-tree.png (202.23 KiB) Viewed 2852 times
map.png
map.png (93.53 KiB) Viewed 2852 times
This is a very regular map with squares for building and paths between the squares. This is all done with an elevation function, so no on_chunk_generated event handling and RSO works with it.

The problem for me is that resources should be limited to the squares. Is there something I can change to make the paths between squares off-limit for ore generation? Can I override or provide some noise function that defines where ore can be placed?

Alternatively can I disable all ore generation and instead call RSO and ask it to generate ores in a region (x1, y1)-(x2,y2) according to it's internal rules for random resource type, size and richness?


Secondly for some types doing this with an elevation function is killing the game (the above Fractal makes a preview take 45s instead of 2s and is on the border of playable). So some maps have to be generated with on_chunk_generated. How do I make sure my mod runs before RSO to create the land/water? Is there a hook in RSO where I can register a callback that is run before ore generation? Otherwise I would have to change ROS to depend on my mod.

Also is there a second callback to be called after ore generation so I can do map alterations that would depend on ore locations? I know that I can do by depending on RSO. But I can only do one: before or after, not both.
orzelek
Smart Inserter
Smart Inserter
Posts: 3923
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Can I limit where ores can spawn? Or hook into on_chunk_generated handler?

Post by orzelek »

Currently RSO is cheating a lot (at leasts thats what I think the result is). Basically RSO will check chunks that might not be generated yet and I'm not sure what game does then.
For the scenario when you are not using on chunk generated this would work without problems since it should still work as is.
If you'd like to make your own chunk generated then only viable solution would be to tell RSO to generated ores in certain area and/or place with given parameters. And you would need to generate all the relevant terrain before hand so that RSO can check it for collisions with water etc.

I think that currently easiest way would be do completely disable what RSO does and then make an interface that would accept a region and generate what is needed inside it. It would still be quite a bit of work I think and since I'm not actively developing RSO I'm not sure if I'd like to go with it.
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Can I limit where ores can spawn? Or hook into on_chunk_generated handler?

Post by mrvn »

I've looked at the code a bit. RSO already has a concept of regions but they are simply squares and a region is identified by {floor(x / size), floor(y / size)}. When a chunk for a new region is generated ROS rolls the dice and places some amount of ores at some locations inside the region. If it hits uncharted chunks then it tells the game to generate them.

So if I add a public API to override the identification of regions and picking a random chunk in a region I think I can really make RSO place ores where my mods wants them.
orzelek
Smart Inserter
Smart Inserter
Posts: 3923
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Can I limit where ores can spawn? Or hook into on_chunk_generated handler?

Post by orzelek »

mrvn wrote: Sat Sep 10, 2022 8:55 pm I've looked at the code a bit. RSO already has a concept of regions but they are simply squares and a region is identified by {floor(x / size), floor(y / size)}. When a chunk for a new region is generated ROS rolls the dice and places some amount of ores at some locations inside the region. If it hits uncharted chunks then it tells the game to generate them.

So if I add a public API to override the identification of regions and picking a random chunk in a region I think I can really make RSO place ores where my mods wants them.
Hmm I think you have it overly simplified a bit. And I'm not sure how to handle if regions would become not square.
And AFAIK I don't generate chunkcs explicitly other then for multiplayer starting location.
And I don't recall any checking of chunks if they are generated - it tries to check for ore space and counts on the fact that game seems to response reasonably.
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Can I limit where ores can spawn? Or hook into on_chunk_generated handler?

Post by mrvn »

orzelek wrote: Mon Sep 12, 2022 5:46 pm
mrvn wrote: Sat Sep 10, 2022 8:55 pm I've looked at the code a bit. RSO already has a concept of regions but they are simply squares and a region is identified by {floor(x / size), floor(y / size)}. When a chunk for a new region is generated ROS rolls the dice and places some amount of ores at some locations inside the region. If it hits uncharted chunks then it tells the game to generate them.

So if I add a public API to override the identification of regions and picking a random chunk in a region I think I can really make RSO place ores where my mods wants them.
Hmm I think you have it overly simplified a bit. And I'm not sure how to handle if regions would become not square.
And AFAIK I don't generate chunkcs explicitly other then for multiplayer starting location.
And I don't recall any checking of chunks if they are generated - it tries to check for ore space and counts on the fact that game seems to response reasonably.
I believe it is that simple, seems to work so far anyway. Abstracting away what a region was easy by looking for places it divides by the region size. I have ores on my islands and none of the connecting ways between them now.

The chunk generating might just be for multiplayer starting positions. I just remember seeing the call to generate chunks. The rest might happen automatic when the code checks if a neighbor chunk has water or ore and the game will trigger the chunk generation automatically due to that access. Don't know, it works, better not look to close or it might break. :)
orzelek
Smart Inserter
Smart Inserter
Posts: 3923
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Can I limit where ores can spawn? Or hook into on_chunk_generated handler?

Post by orzelek »

mrvn wrote: Mon Sep 12, 2022 8:09 pm
orzelek wrote: Mon Sep 12, 2022 5:46 pm
mrvn wrote: Sat Sep 10, 2022 8:55 pm I've looked at the code a bit. RSO already has a concept of regions but they are simply squares and a region is identified by {floor(x / size), floor(y / size)}. When a chunk for a new region is generated ROS rolls the dice and places some amount of ores at some locations inside the region. If it hits uncharted chunks then it tells the game to generate them.

So if I add a public API to override the identification of regions and picking a random chunk in a region I think I can really make RSO place ores where my mods wants them.
Hmm I think you have it overly simplified a bit. And I'm not sure how to handle if regions would become not square.
And AFAIK I don't generate chunkcs explicitly other then for multiplayer starting location.
And I don't recall any checking of chunks if they are generated - it tries to check for ore space and counts on the fact that game seems to response reasonably.
I believe it is that simple, seems to work so far anyway. Abstracting away what a region was easy by looking for places it divides by the region size. I have ores on my islands and none of the connecting ways between them now.

The chunk generating might just be for multiplayer starting positions. I just remember seeing the call to generate chunks. The rest might happen automatic when the code checks if a neighbor chunk has water or ore and the game will trigger the chunk generation automatically due to that access. Don't know, it works, better not look to close or it might break. :)
Did you edit it with callbacks or just added the code?
I'm not sure how to do actual callbacks in modding API. Is it just events that you send and check if there was an answer?

Making proper API sounds a bit of a pain with required validation and testing of that. If you could edit RSO using your mod for testing I would just include it? That at least takes care of testing part.
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Can I limit where ores can spawn? Or hook into on_chunk_generated handler?

Post by mrvn »

Just added my own abstraction to the code. Didn't want to implement the remote API before I knew the idea would work at all.
Post Reply

Return to “Resource Spawner Overhaul”