Tutorial 4: Tileset Addons
This tutorial will show you how to build tileset support into your mod, as well as explain some simple procedures for porting existing tilesets to Rubble.
For details on how to use the templates mentioned here see the "Base Templates" documentation that comes with Rubble.
So you want your cool new mod to support tilesets other than the default? Good thing Rubble goes out of its way to make that easy.
There are 4 core templates that provide support for tilesets:
{#TILE;<ID>;<DEFAULT>}
{SET_TILE;<ID>;<TILE>}
{#COLOR;<ID>;<DEFAULT>}
{SET_COLOR;<ID>;<COLOR>}
(The SET_XXX templates insert a entry in the tile or color dictionary that is later retrieved by the #TILE or #COLOR template with the same <ID>, if no entry for <ID> is present in the dictionary <DEFAULT> is used.)
These templates are a little cumbersome to use but you don't have to. All the specialized SHARED_OBJECT templates will detect tile and color information in their contents and automatically inserts calls to #TILE and #COLOR.
This means that you do not need explicit calls to #TILE or #COLOR as plants, inorganics, tools, and material definitions are handled automatically (while creatures have some tile information included, no tileset that I know of modifies this data).
With #TILE and #COLOR handled, all you really need to worry about is SET_TILE and SET_COLOR. If you are adding support for a brand new tileset, the easiest way is to use #WRITE_TILESET. #WRITE_TILESET is a developer template that makes a list of all calls to #TILE and #COLOR and generates a file containing the corresponding calls to SET_TILE and SET_COLOR.
You would then edit the file generated by #WRITE_TILESET to change the tile numbers and colors to match what you tileset needs.
If you already have raws there is a shortcut you can use that will cut the time needed by a considerable amount. To put it simply you do a quick hack job of inserting the SHARED_OBJECT templates, then generate a temporary addon consisting of the edited raws with the last file containing a call to our friend #WRITE_TILESET.
THIS PROCEDURE IS ONLY FOR CASES WHERE YOU ALREADY HAVE A FULL SET OF RAWS FOR YOUR TILESET! It is, IMHO, much easier to generate a default tileset addon and then edit that than it is to edit the full raws.
These instructions are written with the assumption that you are using Notepad++, if you are using another editor you will have to make sure it is capable of regular expression search and replace operations.
First make a new folder in you addons directory, this will be temporary, so name it anything you want.
Now copy all the raw files that your tileset modified to your new temporary addon, you want only the changed files.
Next add a file named something like "zzz_write_tileset.rbl" and add this line to that file: {#WRITE_TILESET;./tileset.rbl}
Now open all the inorganic material files, to speed things up it's best to have them all open at once.
Open the search/replace dialog and make sure the "Regular expression" radio button is checked.
Then enter the following search text: "\[INORGANIC:([^:\]]+)\]"
And this a the replacement: "}{SHARED_INORGANIC;$1;"
Now go ahead and hit "Replace All in All Opened Documents".
One last step: go through each file and remove the first '}' and add a '}' to the end of the file.
Now follow the above steps for plant, item, and material template files using the following search/replace pairs:
"\[PLANT:([^:\]]+)\]" -> "}{SHARED_PLANT;$1;"
"\[ITEM_([^:\]]+)
[^:\]]+)\]" -> "}{SHARED_ITEM;$1;$2;"
"\[MATERIAL_TEMPLATE:([^:\]]+)\]" -> "}{SHARED_MATERIAL_TEMPLATE;$1;"
Now generate the raws, activating ONLY your temporary addon, "Base/Templates", and "Base/Clear", the generated raws are useless, what you want is the file "tileset.rbl" that should be in your current working directory (generally the directory containing "rubble.exe").
Once you have your tileset.rbl file ready to go (however you got it) create a new addon and add the tileset.rbl file as well as your tileset's font image.
To install you tileset image all you need to do is add a call to INSTALL_TILESHEET to the top of you tileset.rbl file, for example:
{INSTALL_TILESHEET;test_16x16.png}
Now for editing the init files. Rubble provides a set of templates specifically for editing the tileset related init settings found in "d_init.txt".
To set the "font" (eg the tilesheet) you use the SET_FULLSCREEN_TILESHEET and SET_WINDOWED_TILESHEET templates. (Both templates also set the font to be used in graphical mode)
To set things like track tiles you use OPEN_D_INIT, EDIT_D_INIT, CLOSE_D_INIT, and D_INIT_TO_DEFAULTS. The following example makes pillars look like smooth floors
{OPEN_D_INIT}
{EDIT_D_INIT;PILLAR_TILE;'+'}
{CLOSE_D_INIT}
Note that CLOSE_D_INIT will set ALL tileset related init settings to their defaults unless a call to EDIT_D_INIT has explicitly set that value! This is so that it is easy to reset values changed by other tilesets you may have installed before.
If you use all default init settings all you need to do is call D_INIT_TO_DEFAULTS to make sure an different tileset didn't clobber your settings.