Mirrored Map? help request

Post all other topics which do not belong to any other category.
JohnyDL
Filter Inserter
Filter Inserter
Posts: 535
Joined: Fri May 16, 2014 3:44 pm
Contact:

Mirrored Map? help request

Post by JohnyDL »

I want to make a map that's reflected or rotated about a central axis, kind of don't mind if it's a 180degree rotation or a pure left/right or up/down reflection with things being as random as normal in the other directions, I'd like to make a team vs that team thing in 0.15 and want it to be as fair as possible, a quick hunt through mods for map tools and google search didn't help so here's to crowd power.
Neemys
Filter Inserter
Filter Inserter
Posts: 461
Joined: Sat Apr 09, 2016 6:16 pm
Contact:

Re: Mirrored Map? help request

Post by Neemys »

to make a mirrored map, you will need lua script either by mods or by custom scenario.

The code for each solution is the same.

I don't have a complete ready code for that but it will be roughly that :

Code: Select all

game.onevent(defines.events.onchunkgenerated, function(event) 
   --if chunk is left side of map, do nothing
   --if chunk is rigth side of map, take each ground tile of the left side at same y coordinate but negative x and apply them to the chunk (see how some world generation mods work here to see how it is done). (take into account for when there is concrete or other placeable tile, so the ground tile is hidden under them), also take care for when the same chunk on the other side is not generated
end
Want more space restriction ? Or maybe you want to be forced to use train for other thing than ore and oil ? Try Building Platform Mod !
torne
Filter Inserter
Filter Inserter
Posts: 355
Joined: Sun Jan 01, 2017 11:54 am
Contact:

Re: Mirrored Map? help request

Post by torne »

That approach won't really work - if the chunk on one side was already generated and team A already explored it and mined all the resources there, then when team B reach the corresponding chunk it won't have any resources on it :)
sparr
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Mirrored Map? help request

Post by sparr »

Maintain a global table that remembers the contents of any generated chunk that hasn't yet been mirrored.

When either side discovers a new chunk, if it's in the table then mirror it over whatever they just explored and remove it from the table. If it's not then put what they just explored/generated in the table to be mirrored when the other team explores their equivalent chunk.
JohnyDL
Filter Inserter
Filter Inserter
Posts: 535
Joined: Fri May 16, 2014 3:44 pm
Contact:

Re: Mirrored Map? help request

Post by JohnyDL »

I guess it could be done by If chunk is x<0 generate chunk (-x,y) at position (x,y) it doesn't have to be the same positions (though one side of the map will look messed up doing it that way) though I'm not a Lua/modding expert

I could also pregenerate the world a huge amount and then after say 1000 chunks it doesn't really matter, the teams are either exploring that far and will go until they find what they want or they're not and it doesn't matter

Or generate both sides at the same time even if they're not explored by both teams
torne
Filter Inserter
Filter Inserter
Posts: 355
Joined: Sun Jan 01, 2017 11:54 am
Contact:

Re: Mirrored Map? help request

Post by torne »

I think both those approaches will lead to a patchwork map where some chunks are copied from left to right and some are copied from right to left, or will result in the contents of chunks changing after they've been generated.

If you get the event for the generation of a chunk on the left side, you can request generation of the corresponding chunk on the right side, and then when you get the event that it's been generated you can copy the left chunk to the right chunk. But if you get the event for the right side first, you'd want to request generation of the left side, and *then* copy the left side to the right side. Whether anyone would notice the chunk change I'm not sure; they get generated when they're still out of view, so that might be okay?

It would definitely be easier for this to be implemented inside the game engine, though. It should be very straightforward to just have the actual mapgen algorithm mirror one or both axes to produce a map with two identical sides or four identical corners, and while it would potentially look slightly odd along the axes it would still "join up" neatly with no discontinuities. Maybe a good feature request for PVP games?
Neemys
Filter Inserter
Filter Inserter
Posts: 461
Joined: Sat Apr 09, 2016 6:16 pm
Contact:

Re: Mirrored Map? help request

Post by Neemys »

torne wrote:That approach won't really work - if the chunk on one side was already generated and team A already explored it and mined all the resources there, then when team B reach the corresponding chunk it won't have any resources on it :)
Yeah I wrote this answer quickly as I were not home. I think about it a later the problem when other team edit the chunk, better keep a table or generate rigth chunk when left chunk are generated (you can generated unrevealed chunk).

don't know if the OP can do lua though.
Want more space restriction ? Or maybe you want to be forced to use train for other thing than ore and oil ? Try Building Platform Mod !
JohnyDL
Filter Inserter
Filter Inserter
Posts: 535
Joined: Fri May 16, 2014 3:44 pm
Contact:

Re: Mirrored Map? help request

Post by JohnyDL »

I can do a little programming but this is way out of my depth I think, event listeners and interupts is way way beyond me I can write pseudo code though and having had the input (and been told it hasn't been done already) I've come up with this

Code: Select all

GenerateMapChunk(X, Y)
  //is original or reflection
  if X < 0
    //if it the original chunk isn't there make it
    if !Chunk(-X,Y).Exists 
      GenerateMapChunk(-X,Y)
    end
    //give the reflection the general properties of the original
    Chunk(X,Y) = Chunk(-X,Y)
    //reverse the tiles so left becomes right and right becomes left
    foreach Tile(x,y) in Chunk(-X,Y)
      set variables Chunk(X,Y).tile(chunkWidth-(x+1),y) to tile(X,Y)
    end
  else
    //is original generate as normal
    GameFunction.GenerateMapChunk(X,Y)
  end
end
which I know has a Lua like quality to it but it needs to override the built in function and be run constantly and probably put in a mod to work, so I might give up and go to the request a mod/game feature fora thought it'd be 'Oh there's already a tool for that go to obscure location' but never mind thanks anyways :)
torne
Filter Inserter
Filter Inserter
Posts: 355
Joined: Sun Jan 01, 2017 11:54 am
Contact:

Re: Mirrored Map? help request

Post by torne »

It's a bit more tricky than that because the "generate chunk" function in the game doesn't do it right away; it just puts it in a queue for the game to process when it has time. So, you can't do this as a single function that executes in a straightforward sequence - you have to just ask to generate the other chunk and then exit, and then separately listen for the event about that other chunk's generation having completed.

This is what I meant when I said it will result in the contents of chunks changing after they've been generated: if you're traveling fast in a car into ungenerated territory on the side of the map that's the "target" for the mirroring, then what might happen is that the game generates a new chunk, the mod function runs, it discovers the "source" chunk hasn't been generated yet and asks for it to be generated, but before the game has generated the "source" chunk to copy, the player might have already reached the point where the "target" chunk is visible on screen, and so the player might actually see the "old" unmirrored version before it changes. I think this probably can only happen if the player is traveling pretty fast, though?
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2174
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Mirrored Map? help request

Post by Ranakastrasz »

http://lua-api.factorio.com/latest/even ... _generated

Not seeing the issue myself, admittedly.

if you enable sandbox-god mode, via the sandbox scenerio, and rush to the edge, its just partly unloaded/undrawn mess, rather than nothing. However, if a script exists that changes the generation, it shows that mess, until it loads, at which point, in vanilla, it just becomes more detailed, has ore and trees and whatever added, and so on. With the Factorio-world mod, however, it changes to the generated stuff.

Actually, you should steal code from that mod, thinking on it.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
torne
Filter Inserter
Filter Inserter
Posts: 355
Joined: Sun Jan 01, 2017 11:54 am
Contact:

Re: Mirrored Map? help request

Post by torne »

Not sure what you mean by "mess", but I think you're missing my point. It's fine if a script uses on_chunk_generated to replace the contents of the chunk with something determined by that script; presumably the game doesn't show the chunk to the player until the event is done being processed by mods? The problem here is that if you get an on_chunk_generated event for chunk (-100, 100) and your mirroring algorithm wants to make that chunk a mirrored copy of whatever is in chunk (100, 100) (i.e. mirroring about the Y axis), then you have to ask the game to generate chunk (100,100) before you can do it. This means you need to return from the on_chunk_generated function for (-100, 100), at which point the game might show the contents of that chunk to the player. You can't do the mirroring until you get the *subsequent* on_chunk_generated for (100, 100), which might not be right away.
sparr
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Mirrored Map? help request

Post by sparr »

I'm working on a mod to do this.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2174
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Mirrored Map? help request

Post by Ranakastrasz »

I am pretty sure you can force the game to load a chunk. Hence, yes, it should occur at the same time.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
torne
Filter Inserter
Filter Inserter
Posts: 355
Joined: Sun Jan 01, 2017 11:54 am
Contact:

Re: Mirrored Map? help request

Post by torne »

You can call request_to_generate_chunks but when I experimented with this while writing a different mod, it seems like it doesn't always happen immediately.
sparr
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Mirrored Map? help request

Post by sparr »

https://mods.factorio.com/mods/sparr/world-mirror

It's functional and usable, but not perfect yet. By default it will mirror left/right. There's an option to mirror top/bottom as well. Also it offsets the mirroring by 4 chunks (configurable). Without the offset, the starting resources/water get wiped out too often.

Known problems: does not mirror decoratives. misbehaves if you cause conflicting chunk generation requests at the same time.
JohnyDL
Filter Inserter
Filter Inserter
Posts: 535
Joined: Fri May 16, 2014 3:44 pm
Contact:

Re: Mirrored Map? help request

Post by JohnyDL »

Thanks a lot this seems to work wonders but can I turn the debug off? and I've found a small bug with y-axis flip
Attachments
Capture.PNG
Capture.PNG (123.59 KiB) Viewed 4419 times
sparr
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Mirrored Map? help request

Post by sparr »

JohnyDL wrote:Thanks a lot this seems to work wonders but can I turn the debug off? and I've found a small bug with y-axis flip
Sorry about the debug output. I'll have it turned off in the next release.

Regarding that error, I have no idea what would cause that. I've posted elsewhere in the forums about it. I would recommend investigating if you are using any other mods that create new entity types that might be poorly defined around the movement property.
sparr
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Mirrored Map? help request

Post by sparr »

Fixed the debug output and that error. Uploaded v0.15.1 to the mod portal. Let me know if you have other problems?
JohnyDL
Filter Inserter
Filter Inserter
Posts: 535
Joined: Fri May 16, 2014 3:44 pm
Contact:

Re: Mirrored Map? help request

Post by JohnyDL »

Thanks a lot using it now in a world not had any issues at all :)
JohnyDL
Filter Inserter
Filter Inserter
Posts: 535
Joined: Fri May 16, 2014 3:44 pm
Contact:

Re: Mirrored Map? help request

Post by JohnyDL »

getting a few odd things happen as I explore a little more, Ore and trees reflect perfectly never seen a problem there and terrain looks like it mirrors completely correctly but I don't know if you can tell from the map but water ends up with shallows on the chunk boundaries probably where deep water is copied into a chunk where land is bordering it, it doesn't seem that spawners copy at all (although that might be cause I have expansion turned off on this world) and biters if they copy don't always copy (they mirrored partly south east to south west, and less so south west to north west but none ended up in the north east quadrant don't know where they'd be copied from) and finally that huge 4 chunk strip on the right is unexplorable I've walked right up to it and not been able to go there, like maps with limited height and width
Attachments
Capture.PNG
Capture.PNG (168.84 KiB) Viewed 4290 times
Post Reply

Return to “General discussion”