Auto-generated map for Metal Gear 1

Page 1/2
| 2

By Bas Wijnen

Supporter (11)

Bas Wijnen's picture

11-07-2018, 16:09

When I built the Metal Gear randomizer (which randomizes objects but keeps the game finishable), I wrote a script to generate the map structure and locations of objects in the game. I was bored, so I extended the script to create map images. Everything in the maps is generated from the ROM: the characters for both the map and the objects, and also the palette they use.

I also added some info into the maps, because I could. Every screen has a white number in the upper left corner; that's the screen's id. Every exit (other than rooms that just connect) shows the room it is an exit to, and the type of exit; if the type is a number, that's the card you need to open it. In brackets means the door auto-closes. Those exits are really entries, so some places have multiple numbers below each other: those are the places where you can come from when entering the screen here.

Some notable things:

  • There is a uniform in the room next to the bulldozer (b1). You always already have it when you get there, so you cannot find this in the game (without cheating).
  • The ditch is shorter than the desert, but the screens in building 3 are connected (so you can look left/right with the binoculars and see them). This produces an error message in my generator, and results in a gap in the ditch in the image.
  • The first elevator (f0) has the same exits as the top ladder screen. This means that if you would somehow manage to go up through the ceiling, you should immediately go the the ending. I don't think it's possible to do this in the game. I had to override the screen's exits in my script or it would mess up the output.
  • The first and second floor use the same tile set, but with a different palette. Pretty clever way to get more variation in the game, and it costs almost no space in the ROM.

So unfortunately no shocking new findings, like a new room that had not been discovered before (I did find one in MoG when I did a similar project there: there is a room in the source which is entirely filled with wall, has no entries or exits, and has an id which places it in the mirror location of the room with the cross).

If you want to see the code, check out The generated images are in the floors/ directory.

Let me know what you think about it.

Login or register to post comments

By Pencioner

Hero (611)

Pencioner's picture

11-07-2018, 18:32

Looks very interesting. Such a nice and complete reverse engineering!

Btw, could the collected information and knowledge be used to create a complete alternative map for MG? Smile I think you might want to support mapmakers with some scripting tools if there will be some demand for that Wink

By Bas Wijnen

Supporter (11)

Bas Wijnen's picture

13-07-2018, 08:41

Thanks! I suppose that would be possible, but a little more information would be needed. My script doesn't look at enemies at all, so you could change the floors, but it wouldn't affect the placement of enemies. I've also not looked at how walls are detected; it's possible that they just follow the tiles that are used, but possibly that would also need to be found.

And finally, there are some special things that are bound to the room id. For example, which rooms are dark without the flashlight. That shouldn't be a problem, but it's something to take into account when doing this.

By Metalion

Paladin (954)

Metalion's picture

13-07-2018, 10:58

I'm very interested about the MG structure.

How are the rooms coded ?
What is the MG map system ?


By Bas Wijnen

Supporter (11)

Bas Wijnen's picture

13-07-2018, 19:08

Every room has several arrays of data linked to it; most of them are shared by many rooms and every room just picks one.

  • The palette; which palette a room has in encoded from 0x8b40 in page 4,5,6 (0xab40 in the rom). It has 1 nybble per screen, so there is a maximum of 16 palettes. But 0xa, 0xb and 0xf are not used.
  • The tile set. Some tiles are the same for all rooms (lift and electric floor panels, boxes), the rest is per room. I made a list of all 8 of them, with a note about what they are used for, in charsets.txt.
  • The pattern set. The rooms are stored as a list of 4x4 tile patterns. Which patterns are available is stored in a place pointed by 0x6000+2*room (0x1a000 in the rom). Those patterns do not appear to be shared between rooms.
  • Which patterns are used for each tile block in the room. This is only an 8x6 array. It's also not shared between rooms, obviously.
  • Exits to other rooms (N, S, W, E)
  • "Doors" (anything which is marked in yellow on the images)
  • Objects in that room (only for rooms above 0x7a and below 0xdb; outside that range objects are impossible).
  • Presumably enemies; I haven't tried to find that list.

I think that's it; all the details are in mkmap, which generates all the images. If you're interested in my thoughts, you can read mg-asm-analysis.txt. They're my notes while I was working on it. I didn't write them for anyone else to understand, but you may find them interesting, so I put them online. Smile

By Vampier

Prophet (2162)

Vampier's picture

13-07-2018, 20:25

When i was working on the metal gear overlay for openMSX to assist with a speed-run i reverse engineered quite some parts of the game.

Hidden power switch:

Big boss big budget security investment:

Big boss low budget security:

Soldiers that know they are about to die:

Broken Bridge:

Nope not today:

Time to check the inventory:

By Guillian

Prophet (3129)

Guillian's picture

14-07-2018, 12:48

Nice work!

Bas Wijnen wrote:
  • Presumably enemies; I haven't tried to find that list.

If my notes are right, in the English version:
- Enemies/actors are set in Bank0:55F0
- Enemies/actors index is in Bank5:9560
- Enemy/actors room data structure:
db number of enemies
db idEnemy
dw coordinates


Bank5:907E ActorsRoom001:  db 3
Bank5:907F                 db ID_GUARD_MED
Bank5:9080                 dw 40B0h
Bank5:9082                 db ID_GUARD_SLOW
Bank5:9083                 dw 5050h
Bank5:9085                 db ID_GUARD_MED
Bank5:9086                 dw 0C018h

By Randam

Paladin (828)

Randam's picture

14-07-2018, 14:18

Would be really awesome if a random MG game could be generated. That would make the game so much more challenging to replay (including random MG destruction sequence, so you actually have to get the sequence).

By Bas Wijnen

Supporter (11)

Bas Wijnen's picture

14-07-2018, 14:28

In the git repository I linked in the original post is a script (mgrandom) which randomizes the item locations. It makes sure all the items can be found, but it is possible to do it wrong (for example, you must not pick up the silencer until you have killed the guys that are supposed to drop it, because once you have it they will no longer be there, so you would be unable to get the item that they drop).

It's annoying that you cannot see which card you pick up. Because of this, I normally cheat and rewind OpenMSX if I accidentally pick up card 7 or 8. Most of the time, it wouldn't have been a problem, because Mr Arnold and Coward Duck would just drop ammo or a ration (which are the majority of the objects).

Randomizing the destruction sequence would of course be possible, but I don't think it adds that much to it. While playing random games, I found that I always needed to go everywhere anyway to make sure I'm not missing important objects.

I also started to make a randomizer for the Maze of Galious, but that is much less interesting. It just means you have to explore the entire castle before entering world 1. And that while doing that, you'll have almost no health. So it's certainly more challenging, but not so much a search for objects as it is in Metal Gear. Perhaps for MoG the more interesting randomization wouldn't be the objects, but the locations of the world doors...

By Pencioner

Hero (611)

Pencioner's picture

14-07-2018, 14:30

I don't think making the random map generated on MSX is really easy (if possible) - i was thinking more towards anybody generating map and rom with help of scrips on PC, and then playing on MSX.

By Manuel

Ascended (14378)

Manuel's picture

14-07-2018, 14:55

Or in MoG, randmize everything except the first Great Key and/or halo.

Page 1/2
| 2
My MSX profile