Autojoining

by Foomer
A library that makes it easy to create autojoining turfs or objects using 13, 16 or 47 states.
ID:80487
 
The purpose of this library is to make it easy to autojoin tiles using 13, 16 and 47-state autojoining. Most everything is already setup for you when you include the library, all you really need to do is decide which turf types are going to be joined and in what way.

NOTE: This library is intended for STATIC objects, such as terrain or decorations, NOT for things that will be moving around, like blobs.

Each atom gets a new variable called 'autojoin', which can be set to either 13, 16 or 47 depending on the kind of joining that you want for that object.

turf/cave_walls
icon = 'cave_walls.dmi'
icon_state = "13"
autojoin = 13

Aside from that, all that's left is to determine what each object wants to join to. Do they join with the edge of the map? Do they join to other objects of their own type? Do they join to objects with a specific attribute? You can decide what each object joins to by overriding the atom.JoinMatch(direction) function, like this:

turf/river
icon_state = "river.dmi"
icon_state = "16"
autojoin = 16

JoinMatch(direction)
var/step = get_step(src, direction)

// Return 1 if you want to join with the edge.
if(!step)
return 1

// Do you want to join with turfs of same type?
if(step.type == src.type)
return 1

// Join with other turfs using the 'water' attribute.
if(findtext(step.attributes, "water"))
return 1

// Don't join with anything.
return 0

You can also view Autojoining.dm to see how the default JoinMatch function is arranged.

Once you've decided which objects will be autojoining and which other objects they'll be joining to, then you're all set and the library will take care of the rest.
Very cool. I notice some odd behavior with the 13-state graphics but it looks like its just because of quick and dirty icons.

http://www.byond.com/members/Tsfreaks/files/asdf.PNG

I assume you know this. Very cool. I will most certainly find uses for this.
That's in the nature of how 13-state autojoining works. It needs to be done in 2x2 clumps that never join by the corners. This is mostly designed for use in games that have opacity and you don't want players to be able to see what's on the other side of the autojoining wall.
Okay, here's an example. Suppose you have the map setup using 13-state tiles. The player only sees a wall of rock, and cannot tell that there is actually a secret passage leading to a cave on the other side. This necessitates 2x2 sections, which are joined automatically.

http://files.byondhome.com/Foomer/libraries/ 13state_example.png

In that screen shot, what the player sees is on left, and what's actually there is on the right. If the tiles were not used in 2x2 sections, then the player would be able to discern from the icon states that there's an open area on the other side of the wall.
Very interesting!
Thanks for this, Foomer.
Download link is broken Q_Q