Shartak internals – Maps and movement

The map for Shartak is held in a database table with over 140,000 rows in it. Each row corresponds to a single location on the map, also called a tile. The initial island map was generated automatically based on a simple bitmap image with varying colours for the different terrain types. Since 2005 there have been many changes to it, most of which are done by manually editing the table one row at a time. Bear in mind that this system is probably not the best way to do it, but it works for Shartak and allows for some interesting map layouts if I ever need them.

The main columns in the table are id, name, x, y, z, inside, but there are obviously others for the description, terrain type, signs, searching and additional icons to name a few.

Each tile has x and y co-ordinates which can be mapped to the GPS co-ordinates in-game, where x is east-west and y is north-south. This is used to represent each level within the map – for example all the camps and most of the jungle is on the same level. The levels are represented by the z value. Zero is ground level, increasing the value goes up (e.g. to the mountain top) and decreasing it goes down (e.g. into the tunnels).

Every character has their own set of co-ordinates and moving around on a single level is simply adding or subtracting 1 from the x or y values. In order to move up or down, the same thing applies to the z value. Assuming (0,0,0) is at the edge of the mountain, you can move north to (0,1,0), west to (-1,0,0) or up to (0,0,1).

Sounds simple so far doesn’t it – that’s because it is. The whole x,y,z co-ordinate system is pretty standard, but you’re probably wondering about huts or caves and that’s where things start to get a bit more complicated.

An inside hut tile occupies the same x,y,z co-ordinate as the tile that it’s located on so this is where things start to get complicated. Each tile also has an ‘inside’ value which differentiates inside the hut from outside the hut. Most of the jungle, camp and water tiles have the default inside value of zero.

If the previous example (0,0,0) was actually in the middle of a camp and there’s a hut icon, then rather than going up, we need to add another value ‘inside’ to the co-ordinates to make it (0,0,0,0) and you could probably go inside to (0,0,0,1). What about a second hut on the same tile (as we have in a few places)? It would simply be (0,0,0,2). The 1 and 2 for the ‘inside’ value can be any value except ‘0’ which has a special meaning of “outside”, or ’99’ which is used as a special value by the ‘enter’ column described next.

One of the additional columns is called ‘enter’ and this determines whether you can enter a particular tile from the current one. If it’s set to 0, you can’t go inside even if there’s a tile with the same x,y,z values but a different inside value. The special value of 99 means you can leave the current tile and return to the outermost tile (inside=0) if the current tile has an inside value greater than zero. If the current tile has an inside value equal to zero and enter is 99, you can enter any other tiles with the same x,y,z values but a non-zero inside value. If ‘enter’ has any other value, you can only go to a tile with an ‘inside’ value that matches the ‘enter’ value. We cheat a little and say that if the inside value is lower, you’re going out (Leave), and if it’s higher, you’re going in (Enter).

How about an example to try and illustrate this?

name x y z inside enter
Dalpok 0 0 0 0 99
Hut 1 0 0 0 1 99
Hut 2 0 0 0 2 99

If we’re stood in Dalpok, we would see two buttons – “Enter Hut 1” and “Enter Hut 2”. If we enter Hut 1, we would then see “Leave Hut 1” and likewise for Hut 2.

If Dalpok has an enter value of ‘1’ and Hut 1 has an enter value of ‘2’, you could only enter Hut 1 directly from outside, but once inside Hut 1, you would see “Leave Hut 1” and “Enter Hut 2” – a hut within a hut! If you then entered Hut 2, you would be able to leave it and jump straight outside! To fix this, set the enter value for Hut 2 to be ‘1’ and you can then only leave as far as Hut 1. This example works better if you rename Hut 2 to be “store room” then you get a store room within a hut.

The enter/inside combinations allow us to have two huts on adjacent tiles, but you are unable to go from inside one hut to inside the other hut without first going back outside. Simply make sure adjacent (including diagonally) huts have different inside values and it prevents this from happening. There are a couple of places, particularly in the caves within Rakmogak where we have several adjacent inside locations to form a tunnel. This is achieved using enter=0 for the middle locations but not for the ends so once you venture into the tunnel you have to continue to the other end or go back the way you came.

The tunnels under the island generally have a z value of -2 and where they break out to the surface there are locations that fill the gap between z=0 and z=-2 and allow vertical movement.

This is a brief overview of the map system within Shartak and there are actually other features used with things like the ghostship to allow moving locations that don’t actually move (just the entrance/exits change!)

Published by

Simon

You can also find me on Google+, Twitter and Facebook.