display-name: "Games/Math Rescue"
meta: {"Working": "Images"}

if (file.name like "mr?.1")
{
	data(128) unknown
	file
	{
		unsigned8 unknown
		fixed-string(11) name
		unsigned16 unknown
		unsigned32 offset
		unsigned32 size
		unsigned32 unknown

		if (name like ["static*.mr", "chars*.mr", "benny*.mr"])
		{
			transparent-index: 11
		}
		else if (name like "apogee*.mr")
		{
			transparent-index: 5
		}

		interpret-as "image-PCX"
	} while (file.position < first-offset)
}

if (file.name like ["mr?.2", "mr?.3"])
{
	text
}

if (file.name like ["mr?.4", "mr?.5", "mr?.6", "mr?.7"])
{
	folder: "Music"
}

if (file.name like "mr?.8")
{
	interpret-as "archive-SND_DOS"
}

if (file.name like "mr?.d*")
{
	folder: "Demos"
}

if (file.name like "mr*.s*")
{
	folder: "Levels"

	unsigned16 width
	unsigned16 height
	unsigned16 level-bg-ega
	unsigned16 bg-tileset
	unsigned16 backdrop

	unsigned16 start-x
	unsigned16 start-y

	unsigned16 end-x
	unsigned16 end-y

	unsigned16 gruzzle-count
	unsigned16[gruzzle-count * 2] gruzzle-coords

	unsigned16 drip-count
	unsigned16[drip-count * 3] drips

	unsigned16 slime-count
	unsigned16[slime-count * 2] slimes

	unsigned16 book-count
	unsigned16[book-count * 2] books

	unsigned16 truck-count
	unsigned16[truck-count * 4] trucks

	unsigned16 teleporter-count
	unsigned16[teleporter-count * 4] teleporters

	unsigned16 anim-count
	unsigned16[anim-count * 2] anims

	unsigned16 fgtile-count
	unsigned16[fgtile-count * 2] fgtiles

	level
	{
		grid-x: 16
		grid-y: 16

		compressed[file.remaining-bytes] "WordRescueRLE"
		{
			level-layer
			{
				data-type: "unsigned8"
				ignore-tile: 0xFF
				layer-image: "mr1.1\\back" + bg-tileset + "   .mr"
			}
		}

		//TODO: attribute layer
	}
}