ID:1356227
 
Some credit goes to Ter13 here for helping discover some neater ways to get around inside DM

This is useful for when you need to quickly grab a lot of turfs. Its faster than any of the other conventional methods...

var/list/turfs = block(locate(1, 1, 1), locate(world.maxx, world.maxy, world.maxz))
/*
block returns a linear array of turfs

the order and flow of how these turfs are arranged is:
1,1,1 = first turf bottom left hand corner of z layer 1 located at index 1
as index increases...
go left to right per row, x = 1 to world.maxx then increase y to next column
repeat until end of z level, increase z level start over at 1,1,new_z

so if "i" is an index from 0 to turfs.len - 1, then:
ix = 1 + round(i % maxx)
iy = 1 + round(i / maxy)
iz = 1 + round(i / (maxx * maxy))

to find the index:
index = 1 + (ix - 1) + (iy - 1) * maxx + (iz - 1) * maxx * maxy

so to get the turf at 3,7,4:
world.maxx is 10, world.maxy is 10, world.maxz is 10
turfs is a list of all turfs in the world

the_turf = turfs[1 + (3 - 1) + (7 - 1) * 10 + (4 - 1) * 10 * 10]
*/


One use-case would be a procedural generator that needs to set a lot of turfs to new types. Conventional methods would require you to call locate() per turf in order to get the "loc" that new() requires. With this trick, you could bypass calling locate in the process altogether...

new /turf/grass(turfs[index])


Another example would be saving every turf in the world simply by assigning a single "id number" to each type, iterating through every turf returned by block, and then writing each number to the file sequentially. When loading, you could determine the x y and z of said turf simply by the position of the id within the file, then:

ix = 1 + round(i % maxx)
iy = 1 + round(i / maxy)
iz = 1 + round(i / (maxx * maxy))
You might want to mention what we found out about the order in which New() is called on turfs at world startup.

I was thinking, that turfs would instantiate from the bottom-left to the top-right, 1,1,1 being the first turf to call New().

Turns out, I was wrong, as it seems to go in the opposite direction, top-right to bottom-left.

Block, however, seems to work sensibly.