display-name: "Games/Ancients I: Deathwatch"
meta: {"Working": "Images and very initial levels"}

palette: "palette.pal"

if (file.name like "*.pal")
{
	palette
	{
		format: "R6G6B6"
		size: 256
	}			
}

if (file.name == "splat.bin")
{
	data(2) unknown

	unsigned16 width
	unsigned16 height
	image
	{
		format: "I8"
	}

	data(file.remaining-bytes) unknown //there's something else here, but no idea what it is
}

if (file.name == "ground.bin")
{
	data(4) unknown

	loop(4)
	{
		unsigned16 width
		unsigned16 height
		image
		{
			format: "I8"
		}
	}
}

if (file.name like "*.bin" and (file.name != "backup.bin") and (file.name != "reg.bin"))
{
	data(2) unknown
	image-layout-width: 320
	image-layout
	{
		loop while (file.remaining-bytes > 0)
		{
			unsigned16 width-in-bytes
			unsigned16 height
			image
			{
				format: "I8"
				width:  width-in-bytes / 8
			}
		}	
	}
}

if (file.name like "*.bmp")
{
	image
	{
		format: "I8"
		width: 320
		height: 200
	}
}

if (file.name like "walls?.b?n")
{
	data(32) unknown

	needDivide: false

	at 32
	{
		unsigned16 widthTest
		if (widthTest != 13)
		{
			needDivide = true
		}
	}

	image-layout-width: 320
	image-layout
	{
		loop (17)
		{
			if (needDivide == true)
			{
				unsigned16 width-in-bytes
				width: width-in-bytes / 8
			}
			else
			{
				unsigned16 width
			}

			unsigned16 height

			image
			{
				format: "I8"
			}
		}
	}
}

if (file.name like "map?.dta")
{
	folder: "Levels"

	unsigned16 width
	unsigned16 height

	encrypted [file.remaining-bytes] "AncientsLevel"
	{
		image
		{
			format: "I8"
		}
	}
}

function AncientsLevel
{
	counter: 0

	loop while (file.remaining-bytes > 0)
	{
		read unsigned8 tile
		if (counter % 2 == 0)
		{
			write unsigned8 tile
		}

		counter = counter + 1
	}
}

if (file.name like ["*.ttt", "*.wds", "reg.bin"])
{
	text
}

if (file.name == "arm.dta")
{
	folder: "Data"

	loop while (file.remaining-bytes > 0)
	{	
		property-list
		{			
			fixed-string(18) name
			unsigned16 unk1
			unsigned16 value
			unsigned16 unk3
			unsigned32 unk4	
			unsigned16 unk5
			unsigned16 unk6
		}
	}
}

if (file.name == "items.dta")
{
	folder: "Data"

	loop while (file.remaining-bytes > 0)
	{	
		property-list
		{			
			fixed-string(16) name
			unsigned16 unk1
			unsigned16 unk2
			unsigned16 value
			unsigned16 damage	
			unsigned32 unk5
			unsigned16 unk6
			unsigned16 unk7
		}
	}
}


if (file.name == "mondata.dta")
{
	folder: "Data"

	loop while (file.remaining-bytes > 0)
	{	
		property-list
		{			
			fixed-string(16) name
			unsigned16 unk1
			unsigned16 unk2
			unsigned16 unk3
			unsigned16 unk4	
			unsigned16 unk5
			unsigned16 unk6
			unsigned32 unk7
			unsigned16 unk8	
			unsigned16 unk9
			unsigned16 unk10
			unsigned16 unk11	
			unsigned16 unk12
			unsigned16 unk13
			unsigned16 unk14
		}
	}
}

if (file.name == "priest.dta")
{
	folder: "Data"

	loop while (file.remaining-bytes > 0)
	{	
		property-list
		{			
			fixed-string(16) name
			unsigned16 unk1
			unsigned16 unk2
			unsigned16 mp-cost
			unsigned16 unk4
			unsigned32 unk5	
			unsigned16 unk5
		}
	}
}

if (file.name like "spells.dta")
{
	folder: "Data"
	loop while (file.remaining-bytes > 0)
	{
		property-list
		{
			fixed-string(16) name
			unsigned16 unk1
			unsigned16 unk2
			unsigned16 mp-cost
			unsigned16 unk4	
			unsigned16 unk5
			unsigned32 unk6
		}
	}
}