begintownscript;

variables;
short lever1;
short timer = 0;

body;

beginstate 0;
	if(get_flag(20,0) == 150){
		message_dialog("Before you is a long, descending tunnel.  From what you can see, it goes a long way down.  You will most likely emerge underground, if you emerge at all.","");
		set_flag(20,0,155);
	}
	if(get_flag(20,0) > 160){
		set_terrain(6,42,0);
		set_terrain(8,42,0);
		set_terrain(10,42,0);
		set_terrain(12,42,0);
		set_terrain(13,40,0);
		set_terrain(12,39,0);
		set_terrain(10,38,0);
		set_terrain(9,40,0);
		set_terrain(8,39,0);
		set_terrain(6,40,0);
		set_terrain(6,46,0);
		set_terrain(7,47,0);
		set_terrain(8,47,0);
		set_terrain(9,48,0);
		set_terrain(10,46,0);
		set_terrain(12,46,0);
		activate_hidden_group(4);
	}
	if(get_flag(20,0) > 165){
		set_terrain(18,13,375);
		set_terrain(21,13,67);
		set_terrain(16,10,0);
		set_terrain(15,10,0);
		set_terrain(14,11,0);
		set_terrain(14,12,0);
		set_terrain(14,13,0);
		set_terrain(14,14,0);
		set_terrain(14,15,0);
		set_terrain(15,16,0);
		set_terrain(16,16,0);
		activate_hidden_group(5);
	}
	if(get_flag(20,0) > 170){
		set_terrain(21,13,63);
	}
break;

beginstate 1;
break;

beginstate START_STATE;
//	if(get_flag(20,0) == 175){
//		if(timer = 7){
//		put_boom_on_space(43,10,2,0);
//		put_boom_on_space(44,10,2,0);
//		put_boom_on_space(44,11,2,0);
//		put_boom_on_space(43,11,2,0);
//		activate_hidden_group(3);
//		force_instant_terrain_redraw();
//		run_animation_sound(10);
//		message_dialog("Too late.","");
//		set_flag(20,0,180);
//		}
//		else{
//		timer = timer + 1;
//		}
//	}
break;

beginstate 10;
	move_to_new_town(2,22,10);
	break;

beginstate 11;
	if(get_flag(20,0) == 155){
		message_dialog("Nobody in sight.  You suspected that Kurojutsu would place some of his servants here to stop you, but that doesn't seem to be the case.","Nevertheless, you keep a careful watch for any potential ambushes.");
		set_flag(20,0,160);
	}
break;

beginstate 12;
	if(get_flag(20,0) == 160){
		set_terrain(6,42,0);
		set_terrain(8,42,0);
		set_terrain(10,42,0);
		set_terrain(12,42,0);
		set_terrain(13,40,0);
		set_terrain(12,39,0);
		set_terrain(10,38,0);
		set_terrain(9,40,0);
		set_terrain(8,39,0);
		set_terrain(6,40,0);
		set_terrain(6,46,0);
		set_terrain(7,47,0);
		set_terrain(8,47,0);
		set_terrain(9,48,0);
		set_terrain(10,46,0);
		set_terrain(12,46,0);
		activate_hidden_group(1);
		activate_hidden_group(4);
		force_instant_terrain_redraw();
		put_boom_on_space(6,42,0,0);
		put_boom_on_space(8,42,0,0);
		put_boom_on_space(10,42,0,0);
		put_boom_on_space(12,42,0,0);
		run_animation_sound(5);
		change_char_health(1000,-10);
		message_dialog("Oh no...","As you cross over the runes, they explode, damaging you severely.  In addition, the corpses littered about this cave slowly come to life, ready to make you join their ilk.");
		set_flag(20,0,165);
		}
	break;

beginstate 13;
	if(get_flag(20,0) == 165){
		reset_dialog_preset_options(2);
		lever1 = run_dialog(0);
		if (lever1 == 1)
		end();
		set_terrain(18,13,375);
		set_terrain(21,13,67);
		set_terrain(16,10,0);
		set_terrain(15,10,0);
		set_terrain(14,11,0);
		set_terrain(14,12,0);
		set_terrain(14,13,0);
		set_terrain(14,14,0);
		set_terrain(14,15,0);
		set_terrain(15,16,0);
		set_terrain(16,16,0);
		activate_hidden_group(2);
		activate_hidden_group(5);
		set_flag(20,0,170);
		play_sound(106);
		play_sound(99);
		print_str_color("You hear the sounds of chains and grinding gears.",2);
	}
	else{
	message_dialog("The lever has locked into place, and you don't have the time (or the desire) to force it back to its original position.","");
	}
break;

beginstate 14;
	if(get_flag(20,0) == 170){
		if(is_combat() == 1){
			block_entry(1);
			end();
		}
		message_dialog("As you approach this large, complicated dais, you hear a gentle humming in the air.  The four crystal pillars begin to glow slightly.  Perhaps Kurojutsu is controlling a ritual from afar.","Suddenly, the humming stops with a great climax, and...");
		force_instant_terrain_redraw();
		pause(10);
		put_boom_on_space(46,9,4,0);
		put_boom_on_space(45,8,4,0);
		put_boom_on_space(42,8,4,0);
		put_boom_on_space(41,9,4,0);
		put_boom_on_space(41,12,4,0);
		put_boom_on_space(42,13,4,0);
		put_boom_on_space(45,13,4,0);
		put_boom_on_space(46,12,4,0);
		run_animation_sound(54);
		pause(10);
		put_boom_on_space(43,10,2,0);
		put_boom_on_space(44,10,2,0);
		put_boom_on_space(44,11,2,0);
		put_boom_on_space(43,11,2,0);
		activate_hidden_group(3);
		force_instant_terrain_redraw();
		run_animation_sound(10);
		message_dialog("A small cadre of powerful undead suddenly appear on the pedestal!","This is bad.  This is definitely not good.");
		force_instant_terrain_redraw();
		set_terrain(21,13,63);
		set_flag(20,0,175);
		block_entry(1);
	}
break;

beginstate 15;
	if(get_flag(20,0) > 170){
		message_dialog("The portcullis here has been closed behind you.  You're trapped, with nowhere to go but onward.","");
	}
break;