In order to use autotile_lib, you need to first define a series of autotile_rules.
var
list/autotile_rules = list(
"rule"=list("id"=1)
)
turf.autotile_icon is a runtime icon that the turf will attempt to swap to. Provided that this is not null, the object will automatically swap to this icon file immediately upon creation. If the turf has an autotile_rule, and the icon_state is non-null, any turf swapping icons at creation using autotile_icon will have its icon-state reset to null. Autotile_icon should only be set if you need a turf to use a different icon for the map editor than in-game. Autotiles that have a non-null icon_state will not attempt to show their autotile state. This is to allow the placement of autotiles in the map editor that don't obey the joining rules at initialization, but will respond to neighbor changes at runtime.
turf.autotile_rule is the rule for joining a turf will use. The default of null won't use any rules. When set to a string, it will use the rule in global.autotile_rules by that name.
turf.join_id is the join_id for this turf. Autotile rules in the global.autotile_rules list are a list of join_ids that an autotile_rule will pair with. join_id is null by default, which means nothing will join with this turf. If set to a string, and that string matches a nearby autotile, this turf will be used for joining with that autotile.
turf.autotile_flags This variable stores the current state of nearby joins.
turf.autotile_reduce This variable determines which reduction algorithm to apply to the raw at256 format stored in autotile_flags. Whenever an autotile's join states are updated, this reduction algorithm is run against autotile_flags to get an icon_state to show. Three formats are currently supported, 15, 47, and 256. This defaults to 47. More reduction algorithms may be added in the future.
NORTH = 1
SOUTH = 2
EAST = 4
WEST = 8
NORTHEAST = 16
SOUTHEAST = 32
SOUTHWEST = 64
NORTHWEST = 128
This raw value is only stored. It isn't really used for anything longterm. It is reduced using a reduction algorithm to reduce it from at256 format to at47 format. These reduction algorithms can be accessed using at256_reduce47() or at256_reduce15().
turf.New() New() is overridden by this library on turfs. All turfs, even if they don't have an autotile rule look at their neighbors to determine their icon state.
turf.UpdateAutotile(Dir,turf/tile) This function performs an autotile update. if Dir and tile are supplied, this tile will attempt to update according to that direction (relative to self) using the autotile information stored on the tile supplied. If the arguments are left blank, however, all 8 tiles surrounding this one are tested and autotile_flags is updated.
Generating autotiles:
Autotile blanks must be in a DMI, and must be in this format:
![](http://imgur.com/tPICeFQ.png)
This is a standard RPGMaker XP autotile format that's widely used across the web. The top-left tile is state 0, where nothing joins this tile. The top-right tile is all four join corners (state 15). The bottom group of 9 tiles are the outer edge states, the center of which is state 255.
This DMI can be animated using the DMI editor. The converter will preserve that animation in each individual tile.
Include the autotile library in your project and then compile and run the project in DEBUG mode.
The client verb GenAutotile() can be called from the command line. It will ask you to supply an icon to cut into the autotile47 format. It will perform the conversion and then ask you to save the resulting autotile icon somewhere on your hard drive. You can then use this icon file in your project.
Please note that this autotile library doesn't care about the tile size, so if you want to generate an autotile for a specific icon size, the icon must be exactly 3x4 tiles for that final icon size. You can cut up icons taller than your target autotile to create 3/4ths projection cubes too, but the formatting for that can be somewhat difficult to get right.
Special notes:
If you override turf/New(), you need to make certain that you call ..() to ensure that the autotile is updated. You should never, ever, ever under any circumstances sleep() in turf/New(), or it will break EVERYTHING. If you find yourself tempted to spawn() in turf/New(), you should look up StdLib::datum/PostInit().
You can manually set an object's icon_state in the map editor, and it will override pre-init autotiling. Any subsequent calls to UpdateAutotile() will override this map-set icon_state.
Supported formats:
At256 stores 256 unique states per autotile icon. This format will be used rarely.
(Image not available)
At47 stores 47 unique states per autotile icon.
![](https://i.imgur.com/d7KzNdt.png)
At15 stores 16 unique states per autotile icon.
![](https://i.imgur.com/L1gDRMy.png)
I've mocked up a template for the library, in case anyone wishes to make their own. The template fits a 32x32 map, but scale to your liking!