What is the best way to copy and paste a surface?

Place to get help with not working mods / modding interface.
Post Reply
AlienX
Fast Inserter
Fast Inserter
Posts: 103
Joined: Wed May 17, 2017 7:13 pm
Contact:

What is the best way to copy and paste a surface?

Post by AlienX »

Hi all,
I am a bit new with the Factorio API, but not new to programming/scripting.

I wish to create a base surface for a scenario, that when the win condition or lose condition is met, the "base" surface is copied to a new "playing" surface (aka, restart the game again without the need to restart the server and change the save file)

As I understand it, the only way I currently see to be able to do this is to generate a new surface using the same map settings as the base, and use baseSurface.find_entities(), loop through these and re-place them onto the newly created surface.

Is this the best way of doing this or does Factorio already have some built in functionality to copy and paste a whole surface to another?

SyncViews
Filter Inserter
Filter Inserter
Posts: 295
Joined: Thu Apr 21, 2016 3:17 pm
Contact:

Re: What is the best way to copy and paste a surface?

Post by SyncViews »

Would also need to consider any trees, biters, etc. that need to be removed from the freshly generated surface.

I don't think there is any way to straight copy, you either have find_entity + create_entity, or you can make a blueprint (either manually in advance, or create_blueprint) and place it (build_blueprint), but then you need to "revive" all the placed ghosts (on_entity_built or find_entity would work)

Daid
Fast Inserter
Fast Inserter
Posts: 163
Joined: Sun Jul 03, 2016 7:42 am
Contact:

Re: What is the best way to copy and paste a surface?

Post by Daid »

Create a new surface on start, with specific MapGenSettings, especially the "seed" is important here. Move all the players to this surface on connect.

Then when you are done, create a new surface with these same settings, move all the players to it, and delete the original surface? Same MapGenSettings will provide the same map every time.

(You simply don't use the 'nauvis' surface, as you cannot delete that one)

AlienX
Fast Inserter
Fast Inserter
Posts: 103
Joined: Wed May 17, 2017 7:13 pm
Contact:

Re: What is the best way to copy and paste a surface?

Post by AlienX »

Hi Daid,
While this will generate the same surface map layout, it will not copy entities that are created on the map :(

Let's say my map had a pre-built base in it, nothing fancy, just some turrets, walls and belts - i want these to be copied each time, my current idea of baseSurface.find_entities() is most likely the only method of achieving this.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: What is the best way to copy and paste a surface?

Post by Nexela »

I just have to ask why? as in why copy the surface and everything on it if you are not changing anything?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: What is the best way to copy and paste a surface?

Post by darkfrei »

On init save all entities to table and read from it for items placing.

AlienX
Fast Inserter
Fast Inserter
Posts: 103
Joined: Wed May 17, 2017 7:13 pm
Contact:

Re: What is the best way to copy and paste a surface?

Post by AlienX »

Nexela wrote:I just have to ask why? as in why copy the surface and everything on it if you are not changing anything?
I have this idea in my head to create a game mode that resets itself whenever it's won or failed, because of this i want the same starting area to be spawned from the "baseSurface" every time, including any entities that I place down in the map editor, such as drills, belts, power poles etc.

These entities can be moved, deleted or killed by either aliens or players during play, thus the base surface must be considered an immutable object

darkfrei wrote:On init save all entities to table and read from it for items placing.
I will give this a go, thank you.

Post Reply

Return to “Modding help”