/*
 * Copyright (c) 2017, L. Adamson
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *    
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * The views and conclusions contained in the software and documentation are those
 * of the authors and should not be interpreted as representing official policies,
 * either expressed or implied, of L. Adamson or DizzyDragon.net.
 * 
 */

//package labyrinth.refmaterial.tools;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.PrintStream;
//
//import labyrinth.refmaterial.decoders.DecodedDungeon;
//import labyrinth.refmaterial.decoders.DecodedDungeon.DecodedSpc;
//import labyrinth.refmaterial.decoders.DecodedDungeon.DecodedWall;
//import labyrinth.refmaterial.decoders.DndDecoder;
//import labyrinth.refmaterial.decoders.vmsdnd.VmsDndDecoder;
//
//
//public class ExtractGrimrock2Maps
//{
//	public static void main( String[] args ) throws FileNotFoundException
//	{
//		DndDecoder vmsDecoder = new VmsDndDecoder();
//		// DndDecoder unixDecoder = new UnixDndDecoder();
//		
//		// dumpMap( vmsDecoder.getDungeon("LAMORTE"), "Lamorte" );
//		// dumpMap( vmsDecoder.getDungeon("SJKII"), "The Cavern" );
//		// dumpMap( vmsDecoder.getDungeon("SVHENK'S LAIR"), "Svhenk's Lair" );
//		// dumpMap( vmsDecoder.getDungeon("TELENGARD"), "Telengard" );
//		// dumpMap( vmsDecoder.getDungeon("WARREN"), "The Warren" );
//		// dumpMap( unixDecoder.getDungeon("Crestwood"), "Crestwood" );
//		
//		DecodedDungeon telengard = vmsDecoder.getDungeon( "TELENGARD" );
//		
//		System.out.print( telengard.getName()+".." );
//		PrintStream out;
//		File dungeonFile = new File( "Maps/Grimrock/dungeon.lua" );
//		dungeonFile.getParentFile().mkdirs();
//		out = new PrintStream( new FileOutputStream( dungeonFile ) );
//		for( int level=1; level<=20; level++ )
//		{
//			System.out.print( level+".." );
//			out.println( getLevel(telengard,level) );
//		}
//		out.close();
//		System.out.println( "Done!" );
//	}
//	
//	private static String getLevel( DecodedDungeon dungeon, int level )
//	{
//		if( !dungeon.isValidLevel( level ) )
//			return "";
//		
//		StringBuilder sb = new StringBuilder();
//		
//		sb.append( "--- " + dungeon.getName() + ", Level " + level + " ---\n" );
//		sb.append( "\n" );
//		sb.append( "newMap{\n" );
//		sb.append( "\tname = \""+dungeon.getName()+" L"+String.format( "%02d", level )+"\",\n" );
//		sb.append( "\twidth = 32,\n" );
//		sb.append( "\theight = 32,\n" );
//		sb.append( "\tlevelCoord = {0,0,1},\n" );
//		sb.append( "\tambientTrack = \"dungeon\",\n" );
//		sb.append( "\ttiles = {\n" );
//		sb.append( "\t\t\"dungeon_floor\",\n" );
//		sb.append( "\t\t\"dungeon_wall\",\n" );
//		sb.append( "\t}\n" );
//		sb.append( "}\n" );
//		sb.append( "\n" );
//		sb.append( "loadLayer(\"tiles\", {\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "\t2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\n" );
//		sb.append( "})\n" );
//		sb.append( "\n" );
//		
//		if( level == 1 )
//			sb.append( "spawn(\"starting_location\","+(dungeon.getStartX()+1)+","+(dungeon.getStartY()+1)+",2,0,\""+dungeon.getName()+"_starting_location\")\n" );
//		
//		for( int y=1; y<=20; y++ )
//		{
//			for( int x=1; x<=20; x++ )
//			{
//				if( dungeon.isValidRoom( x-1, y-1, level ) )
//				{
//					DecodedWall northWall = dungeon.getNorthWall( x-1, y-1, level );
//					DecodedWall westWall = dungeon.getWestWall( x-1, y-1, level );
//					DecodedSpc spc = dungeon.getSpc( x-1, y-1, level );
//					
//					if( northWall == DecodedWall.DOOR )
//					{
//						// Spawn north door.
//						sb.append( "spawn(\"dungeon_door_wooden\","+x+","+y+",0,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_northDoor_"+x+"_"+y+"\")\n" );
//						sb.append( dungeon.getName()+"_L"+String.format("%02d",level)+"_northDoor_"+x+"_"+y+".door:setPullChain(true)\n" );
//					}
//					else if( northWall == DecodedWall.BLOCKED )
//					{
//						// Spawn north wall object.
//						sb.append( "spawn(\"dungeon_secret_door\","+x+","+y+",0,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_northWall_"+x+"_"+y+"\")\n" );
//					}
//					else if( northWall == DecodedWall.SECRET_DOOR  )
//					{
//						// Spawn north secret door object.
//						sb.append( "spawn(\"dungeon_secret_door\","+x+","+y+",0,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_northSecretDoor_"+x+"_"+y+"\")\n" );
//						sb.append( dungeon.getName()+"_L"+String.format("%02d",level)+"_northSecretDoor_"+x+"_"+y+".door:disable()\n" );
//					}
//					else if( northWall == DecodedWall.CLEAR  )
//					{
//						// It's a clear wall.  Do nothing.
//					}
//					else
//					{
//						throw new RuntimeException( "Unimplemented WALL "+westWall );
//					}
//					
//					if( westWall == DecodedWall.DOOR )
//					{
//						// Spawn west door.
//						sb.append( "spawn(\"dungeon_door_wooden\","+x+","+y+",3,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_westDoor_"+x+"_"+y+"\")\n" );
//						sb.append( dungeon.getName()+"_L"+String.format("%02d",level)+"_westDoor_"+x+"_"+y+".door:setPullChain(true)\n" );
//					}
//					else if( westWall == DecodedWall.BLOCKED )
//					{
//						// Spawn north wall object.
//						sb.append( "spawn(\"dungeon_secret_door\","+x+","+y+",3,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_westWall_"+x+"_"+y+"\")\n" );
//					}
//					else if( westWall == DecodedWall.SECRET_DOOR  )
//					{
//						// Spawn north secret door object.
//						sb.append( "spawn(\"dungeon_secret_door\","+x+","+y+",3,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_westSecretDoor_"+x+"_"+y+"\")\n" );
//						sb.append( dungeon.getName()+"_L"+String.format("%02d",level)+"_westSecretDoor_"+x+"_"+y+".door:disable()\n" );
//					}
//					else if( westWall == DecodedWall.CLEAR  )
//					{
//						// It's a clear wall.  Do nothing.
//					}
//					else
//					{
//						throw new RuntimeException( "Unimplemented WALL "+westWall );
//					}
//					
//					// Spawn pillar (if needed)
//					if( northWall != DecodedWall.CLEAR || westWall != DecodedWall.CLEAR || dungeon.getNorthWall(x-2,y-1,level) != DecodedWall.CLEAR  || dungeon.getWestWall(x-1,y-2,level) != DecodedWall.CLEAR )
//					{
//						sb.append( "spawn(\"dungeon_pillar\","+x+","+y+",0,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_pillar_"+x+"_"+y+"\")\n" );
//					}
//					
//					if( spc == DecodedSpc.NOTHING )
//					{
////						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.STAIR_DOWN )
//					{
//						sb.append( "spawn(\"dungeon_stairs_down\","+x+","+y+",0,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_spcStairDown_"+x+"_"+y+"\")\n" );
//					}
//					else if( spc == DecodedSpc.STAIR_UP )
//					{
//						sb.append( "spawn(\"dungeon_stairs_up\","+x+","+y+",0,0,\""+dungeon.getName()+"_L"+String.format("%02d",level)+"_spcStairUp_"+x+"_"+y+"\")\n" );
//					}
//					else if( spc == DecodedSpc.STAIR_SPIRAL )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.EXC )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.PIT )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.TPT )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.FNT )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.ALT )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.DGN )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.DGO )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.ORB )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.ELV )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.THR )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.TRV )
//					{
//						sb.append( "\n" );
//					}
//					else if( spc == DecodedSpc.RCK )
//					{
//						sb.append( "\n" );
//					}
//					else
//					{
//						throw new RuntimeException( "Unimplemented SPC "+spc );
//					}
//				}
//				else
//				{
//					// Invalid Room.
//					// FIXME: This needs to be reflected in the pixmap thingy above!
//				}
//			}
//			// Spawn blocked wall at end of row.
//			sb.append( "spawn(\"dungeon_secret_door\","+21+","+y+",3,0,\""+dungeon.getName()+"_westWall_"+21+"_"+y+"\")\n" );
//			sb.append( "spawn(\"dungeon_pillar\","+21+","+y+",0,0,\""+dungeon.getName()+"_pillar_"+21+"_"+y+"\")\n" );
//		}
//		// FIXME Spawn blocked row at bottom of map.
//		for( int x=1; x<=20; x++ )
//		{
//			sb.append( "spawn(\"dungeon_secret_door\","+x+","+21+",0,0,\""+dungeon.getName()+"_northWall_"+x+"_"+21+"\")\n" );
//			sb.append( "spawn(\"dungeon_pillar\","+x+","+21+",0,0,\""+dungeon.getName()+"_pillar_"+x+"_"+21+"\")\n" );
//		}
//		sb.append( "spawn(\"dungeon_pillar\","+21+","+21+",0,0,\""+dungeon.getName()+"_pillar_"+21+"_"+21+"\")\n" );
//		
//		return sb.toString();
//	}
//	
//	private ExtractGrimrock2Maps()
//	{
//	}
//}
