Jump to content

Generic tilesets - adding them through XML


Solver

Recommended Posts

So this is another feature that I've considered to be of high importance from the start, and now while the building refactor is being tested, I can get to work doing this. Currently, the tilesets are hardcoded and there is not really a way to add a new tileset to the game except Tundra, which is also in the code but simply not used.

What I want to do is of course to move the tilesets to XML, so that a tileset could easily be added. Merely something like this:

<Tileset> <Name>SkitsosBunker</Name> <Location>skitsos_bunker</Location></Tileset>

Simply a setup of a tileset name to be shown in-game, and the folder where the tiles are.

The location of individual tilesets on the world map is currently specified with a simple mask where each colour corresponds to a tileset. I don't particularly like it because it doesn't leave much room for probability-based tilesets. I would like to let modders specify regions where there's a mixed chance of different tilesets! So for instance:

<TilesetMask> <Colour>0xff00ff</Colour> <Tileset name="farm" chance="20" /> <Tileset name="industrial" chance="75" /> <Tileset name="forest" chance="5" /></TilesetMask>

Put it somewhere in Europe, and now aliens may crash in a city or in a farm, and occasionally in a forest. Because Europe isn't all factories and parking lots. Unless it's Nordrhein-Westfallen.

The main issue here is, how to keep modularity? If two people add different tilesets, they should not have to both repaint the tilemask to include the other guy's changes.

The immediate solution that comes to mind is to let each tileset specify a mask file of its own. It designates some areas for itself, and leaves other transparent so as not to affect them. Then for instance:

<Tileset> <Name>SkitsosBunker</Name> <Location>skitsos_bunker</Location> <MaskFile>skitsos_bunker_mask.png</MaskFile></Tileset>

any transparent areas in the specified png file are ignored, and any non-transparent areas are processed according to the code in TilesetMask tags. In this case, the existing mask file for the built-in tilesets could probably be split into such individual per-tileset transparent masks, and we could get rid of the default.

Thoughts?

Link to comment
Share on other sites

What I want to do is of course to move the tilesets to XML, so that a tileset could easily be added. Merely something like this:
<Tileset> <Name>SkitsosBunker</Name> <Location>skitsos_bunker</Location></Tileset>

Simply a setup of a tileset name to be shown in-game, and the folder where the tiles are.

I think the per-tileset XML file may not be necessary. The location is simply the directory the tileset is in, and the name cannot be in the tileset XML file, because it needs to allow translation (so it needs strings.xml addition and hoping translators translate it in their strings.xml - which will all work if both the tileset and translation are mods installed using the new modular system).

Similarly, for colors for the tileset it might be enough if the game specified a couple of colors for most common percentages and each tileset would have its tileset map done using these colors. Game code would combine it somehow together from all images. If tilesets specified their own colors, there might be clashes. And the tileset image can be a .png with a defined name in the tileset directory.

In this case, the existing mask file for the built-in tilesets could probably be split into such individual per-tileset transparent masks, and we could get rid of the default.

Only if the code deciding on a tileset to use will handle a possible unknown or transparent color (which may happen due to a mistake or somebody removing a stock tileset).

Link to comment
Share on other sites

The tileset specific masks sounds like a really good solution to me. The game could so with retaining a full version of the world map, though, so it can be used as a template for making the tileset masks (to be clear, this template wouldn't actually be used, but would be a starting point for making a new one so that you know you're putting stuff in the right places).

Link to comment
Share on other sites

I think the per-tileset XML file may not be necessary. The location is simply the directory the tileset is in, and the name cannot be in the tileset XML file, because it needs to allow translation (so it needs strings.xml addition and hoping translators translate it in their strings.xml - which will all work if both the tileset and translation are mods installed using the new modular system).

The Name parameter there is of course not the actual name that gets displayed but a key to strings.xml, just as with most other XML files. I like XML files because they are explicit. I don't want things suddenly loading just because there's a folder, and I want to disable things just in XML.

Only if the code deciding on a tileset to use will handle a possible unknown or transparent color (which may happen due to a mistake or somebody removing a stock tileset).

Well, why not? Having some kind of fallback condition for unknown values seems like basic design, of course the game should then do something and not just CTD.

Link to comment
Share on other sites

The Name parameter there is of course not the actual name that gets displayed but a key to strings.xml, just as with most other XML files.

Makes sense.

I like XML files because they are explicit. I don't want things suddenly loading just because there's a folder, and I want to disable things just in XML.

All things load just because they're there. Disabling can be done by disabling the mod, no need to edit anything manually.

Link to comment
Share on other sites

any transparent areas in the specified png file are ignored, and any non-transparent areas are processed according to the code in TilesetMask tags. In this case, the existing mask file for the built-in tilesets could probably be split into such individual per-tileset transparent masks, and we could get rid of the default.

Thoughts?

Not a bad idea at all. I'd make the per-tileset masks use an alpha-style weighting scheme; the closer to black the color value the higher the weight given to this tileset at that location. That way, you'd retain your random tileset per location idea while also allow easy modding interaction between two tilesets from separate mods that alter the same location.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...