Jump to content
  • 1

A Simple Map Modification System


Hiraeth

Question

Introduction:

Hello everyone,

With the addition of mod support, the game has been looking and sounding a lot better. Updated battle sprites, new music, and better icons have allowed the game to expand in extraordinary ways! That said, I believe that the best possible step forward (in terms of mod support) would be to allow map modifications to occur. Below this introduction I have laid out a possible design for a viable-yet-simple map modification system, along with inspiration and reasoning behind its features and structure.

 

Understanding the ROM Engine's Map System:

A strong point of this map modification design is to present data to the client in a similar (if not same) format that it would be read from the ROM. By doing this, the PokeMMO developers can focus more on the mod implementation than changing old code to work with it. To clarify, the developers should not have to rewrite their whole map rendering engine just to allow for map modifications. With map data being presented in a similar format, the developers shouldn't have to change much in their current engine.

So how is the data presented in the ROM? For the technical minded, my reference can be found here. I will elaborate regardless.

 

How are maps identified?

Inside of the ROM, there is a psuedo-filesystem that holds all maps and their data. Inside of this filesystem, there are many banks (which can be visualized as folders) of maps files. For a visual representation of this, see the screenshot below taken from a popular GBA map editor:

[spoiler]fqlOzz0.jpg[/spoiler]

As you can see, each map is labeled by its bank (or folder) ID and by its place in the list. For example, Pallet Town is in bank 3 and it is the first map (making its ID 0). This identifier will be used with modded map naming conventions, but we will get to that later.

 

How is each map file organized?

Well, I'm glad you asked! The map file consists of a header and a footer; together these structures hold all of the map's data. I will break it down and only include the information that will be modifiable -- I will not include information on movement permissions, surrounding maps, or whether or not Flash is needed for example.

 

Header information:

  • The music ID for this map
  • No more editable data (to my knowledge) in the header due to the data's fragile nature (surrounding maps, scripts, event data)

Footer Information:

  • The tilesets to use for this map
  • The layout of the tiles in the map
  • The border tiles to use
  • The width and height of the border (in Fire Red only, borders are always 2x2 in Emerald)

For information on how tilesets and tilemaps work, see the below copypasta:

[spoiler]

  • tile is a small image, usually rectangular or isometric, that acts like a puzzle piece of art for building larger images.
  • map is a grouping of tiles put together to create a (hopefully) visually appealing "section" (like a level or area).
  • Tile-based refers to the method of building levels in a game. The code will layout tiles in specific locations to cover the intended area.[/spoiler]

 

Digging Deeper: How are the tiles laid out?

In the ROM, there is a collection of numbers that layout where each tile goes on the map. Each one of these numbers corresponds to a single tile in the tilesets. I don't really know how to explain this, so I will try giving an example below.

 

1, 1, 1, 1, 1,

1, 1, 1, 1, 1,

1, 1, 1, 1, 1,

1, 1, 2, 1, 1

 

If we were to assume 1 was short grass and 2 was tall grass, the map would look like this:

F7An9JV.png

 

Now that we know the structure and data needed...

We can now begin to base the structure of the map modification system around information we know. 

 

Map Modification Design and Implementation:

There are many things to consider when devising a map modification system. How easily can maps be modified? Which information is editable to the average user? How resource-intensive will this be on users' systems who mod other resources? How/when are maps flushed? What file formats are used? The list goes on. I will try my best to answer all of these questions below.
 
Which map editor do we use?
Rather than making the developers write a new map editor (which would slow development), I think it would be best to use a popular editor that supports everything that we need. With that said, I propose that we use Tiled Map Editor when map editing. This map editor allows for layers, 16x16 tiles, any number of tilesets, and tile IDs are presented in a similar format that they are presented in the ROM. The best part about Tiled is that there are not restrictions on what you can build (in terms of color and looks). Maps from the ROM are restricted in terms of colors and number of tiles, but that isn't the case with Tiled.
 
How will the map files be structured?
Luckily, Tiled uses its own file type with the .tmx extension (an XML-like filetype) and it is pretty straight-forward. That said, I will guide you guys through its format through example.
 
Including header & Footer information:
Miscellaneous map properties can be added to a map file through the editor. It is a simple process and it gives us space to list information such as the music ID and border information for the map. I will give an example below.
[spoiler]
<map version="1.0" orientation="orthogonal" width="5" height="4" tilewidth="16" tileheight="16">
	<properties>
		<property name="musicID" value="7">
		<property name="borderWidth" value="2">
		<property name="borderHeight" value="2">
		<property name="borderTileIDs" value="0,1,1,0">
	</properties>
</map> 
[/spoiler]
 
Adding tilesets to the map:
Tilesets are simple PNG images which are split into 16x16 tiles by the editor. Each tileset has a beginning ID and image location in its declaration. I don't really know how to explain the 'beginning ID', but I will try. The first tileset will begin with ID 1, and if it has 73 tiles then the next tileset will start with a beginning ID of 74. This basically allows the editor to differentiate tiles of many tilesets by ID. So how does this look in the map file?
[spoiler]
<map version="1.0" orientation="orthogonal" width="5" height="4" tilewidth="16" tileheight="16">
	<tileset firstgid="1" name="anynamereally" tileWidth="16" tileHeight="16">
		<image source="tilesets/ts1.png" width="128" height="512"/>
	</tileset>
</map> 
Keep in mind that the tileset width and height are in pixels, not tiles. Other tileset information can be given, but they aren't really needed for our purpose.
[/spoiler]
 
Implementing layers & tile structure:
Tiled supports any number of layers, however I believe we will need to stick to 2 due to how the current rendering engine works. We will need a layer that the player walks on, and a layer that covers the player. In each layer, a list of tile IDs is given to layout the structure of all tiles on that layer. See below for an example.
[spoiler]
<map version="1.0" orientation="orthogonal" width="5" height="4" tilewidth="16" tileheight="16">
	<layer name="bottom" width="5" height="4">
		<data>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="2"/>
			<tile gid="1"/>
			<tile gid="1"/>
		</data>
	</layer>
	
	</layer name="top" width="5" height="4">
		<data>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
		</data>
	</layer>
</map> 
Note: Tile data can be compressed using gzip, zlib, and CSV to save a lot of space. In this example however, I listed them in XML-format to get the point across.
[/spoiler]
 
Using the tile IDs of the map we made in the ROM earlier, we have just recreated that map! All of this map data is on the bottom layer since the player walks on grass, and the top layer is empty in this example.
 
Tile properties can also be listed! Perhaps the PokeMMO client can use tile properties to determine if the player should walk over both layers of a tile, whether or not a grass (or sand) animation should occur on that tile, ect.
 
The full example map file:
[spoiler]
<map version="1.0" orientation="orthogonal" width="5" height="4" tilewidth="16" tileheight="16">
	<properties>
		<property name="musicID" value="7">
		<property name="borderWidth" value="2">
		<property name="borderHeight" value="2">
		<property name="borderTileIDs" value="0,1,1,0">
	</properties>
	
	<tileset firstgid="1" name="anynamereally" tileWidth="16" tileHeight="16">
		<image source="tilesets/ts1.png" width="128" height="512"/> <!-- width and height in pixels -->
	</tileset>
	
	<layer name="bottom" width="5" height="4">
		<data>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="1"/>
			<tile gid="2"/>
			<tile gid="1"/>
			<tile gid="1"/>
		</data>
	</layer>
	
	</layer name="top" width="5" height="4">
		<data>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
			<tile gid="0"/>
		</data>
	</layer>
</map> 
[/spoiler]
 
How and when should the maps be dumped?
With PokeMMO mod development growing rapidly, I think it is silly that all resources are dumped to file at once. My proposal is to give us the option to dump specific resources (battle sprites, music data, map data) to avoid taxing on systems. There are over 1000 Pokemon sprites in the game, many music files, and over 500 maps (per region to my knowledge). 
 
Once that feature is in effect, dumping the maps shouldn't be too hard. The client can dump its data into .tmx format as shown above, and tilesets can be placed into the /tilesets/ folder. Computers are fast, so I don't see the dumping taking more than 2 minutes.
 

Conclusion:

As you can see, by utilizing the Tiled Map Editor and keeping the ROM structures in mind, we can easily mod maps (in theory). Below I have linked a bunch of beautiful Pokemon-like maps that have been made using this editor to get you guys are psyched as I am.  ;)

 

 

[spoiler]map_004_by_the_red_ex-d8xd7ey.png

old_map___one_by_the_red_ex-d5qwtkl.png

gd___tileset___br_uuml_ckengeb_auml_ude_[/spoiler]

 

This is still just a suggestion, so give me feedback. At the time of posting, it is 5:00 AM so I probably missed something or didn't clarify on something enough. Let me know if you don't understand something, see a flaw, or want to help. I'm sure we can figure this out. In the end, the point of this thread is to find a way to allow map modifications; a way to shape the world around our characters without restrictions.

Edited by Hiraeth
Link to comment

4 answers to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.