grid map tables
table: map
A map, if you think about the paper kind, is a representation of a real place. In this case, the digital map is actually where our digital actors move about. For our purposes, a map is just a collection of tiles that are connected to each other. For example, the first floor of a building could be one map, and the second floor is a different map. Points on each map might "connect" via a stairwell, for instance. These connections are how you travel between maps, but the maps themselves don't actually having to fit together spatially. For instance, the city map might be a different scale as the interior of buildings. Scale need only be consistent in the tiles of the same map.
DROP TABLE IF EXISTS map; CREATE TABLE map ( id int(10) unsigned NOT NULL AUTO_INCREMENT, description varchar(255), PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
table: tile
A tile is the smallest measurement of a map. This isn't exactly true because the details of what makes up a tile are left out of the database design on purposes. That way, the tile can be swapped out for a different one. I'm building 8x8 inch squares, but it could just as easily be hexagons. The exact details regarding an item's location can be found in the nounLocation table.
DROP TABLE IF EXISTS tile; CREATE TABLE tile ( id int(10) unsigned NOT NULL AUTO_INCREMENT, mapId int(10) unsigned, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
table: tileLocation
This table is how tiles are connected. It divides the map into quadrants. At its lowest level, the leaf boolean is set to true to show that the four quadrants are tiles. When the leaf boolean is set to false, the quadrants refer to other tileLocations. So, if a tile is an 8x8 space, the smallest tileLocation combines four of these to describe a 16x16 space. The next level would combine four of those to make a 32x32 space, and so on. Tiles are only assigned when there's something in them, so arbitrarily shaped maps can be described without wasting must space in the database.
DROP TABLE IF EXISTS tileLocation; CREATE TABLE tileLocation ( id int(10) unsigned NOT NULL AUTO_INCREMENT, mapId int(10) unsigned, leaf int(1), aId int(10) unsigned, bId int(10) unsigned, cId int(10) unsigned, dId int(10) unsigned, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;