begintownscript;

variables;
short choice = 0;
short pc_counter = 0;
short lead_char = 0;
short insanity = 0;
string runestep;
short icex = 0;
short icey = 0;
short icecount = 0;
string crystal;

body;

beginstate 0; //INIT_STATE
	set_crime_tolerance(2);

	set_name(6,"Felix");

	if(get_flag(8,16) == 4) {
		set_terrain(49,5,137);
		set_terrain(49,14,4);
		set_terrain_memory_cell(8,4,1);
		activate_hidden_group(19);
		add_range_to_group(48,51,6);
		add_char_to_group(39,6);
		}
	else if(get_flag(8,16) == 5)
		set_terrain(49,5,137);
	if(get_flag(0,17) >= 3) {
		set_terrain(49,5,137);
		set_terrain(49,14,4);
		set_terrain_memory_cell(8,4,1);
		activate_hidden_group(19);
		add_range_to_group(48,51,6);
		add_char_to_group(39,6);
		}

	if(get_flag(8,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you descend into the cathedral's catacombs for the first time, a cold wind swirls around you. You're starting to get used to these freak gusts, but they're still a bit unnerving.",0);
		add_dialog_str(1,"Unsurprisingly, the catacombs aren't lit very well. In this room, the room is illuminated by a lone brazier sitting in the corner. Every so often, it sputters.",0);
		run_dialog(1);
		set_flag(8,0,1);
		}

	if(get_flag(8,8) == 2)
		set_terrain(28,52,388);

	if(get_flag(50,0) == 1)
		erase_char(6);

	if(get_flag(50,1) == 1) {
		activate_hidden_group(10);
		force_instant_terrain_redraw();
		if(get_flag(11,10) == 2)
			set_name(35, "Robert Paulsen");
		if(get_flag(8,13) == 2)
			set_name(43, "Mother Reese");
		}

break;


beginstate 1; //EXIT_STATE

break;


beginstate 2; //START_STATE

	erase_text_bubbles();
	if((char_ok(35) == 1) && (get_ran(1,1,6) > 4) && (get_flag(11,10) == 2))
		text_bubble_on_char(35,"My name is Robert Paulsen...");
	force_instant_terrain_redraw();

	if((get_flag(8,16) == 4) && (num_chars_in_group(6) == 0)) {
		reset_dialog();
		add_dialog_str(0,"With the spirits defeated, the feel of magic in the air fades away. Luckily, the door to the chamber has also reappeared.",0);
		run_dialog(1);
		set_terrain(49,14,16);
		force_instant_terrain_redraw();
		//if(get_terrain(49,14) == 16)
		//	print_str("Test");
		set_flag(8,16,5);
		}

	pc_counter = 0;
	while(char_ok(pc_counter) == 0) {
		pc_counter = pc_counter + 1;
		}
	lead_char = pc_counter;

	//counter for going insane
	if((get_flag(8,5) > 1) && (get_flag(50,0) == 0)) {
		if((char_loc_x(lead_char) > 32) || (char_loc_y(lead_char) > 37)) {
			insanity = insanity + 1;
			}
		else if(insanity != 0) {
			insanity = 0;
			if(party_size() == 1)
				print_str_color("Your mind feels clear again.",2);
			else
				print_str_color("Your minds feel clear again.",2);
			}

		}
	//insanity checks
	if(insanity == 60) {
		reset_dialog();
		add_dialog_str(0,"It's getting much harder to think straight. You think you can keep going for a while, but you should definitely try to finish your mission before the pressure becomes too great.",0);
		run_dialog(1);
		}
	if(insanity == 90) {
		reset_dialog();
		add_dialog_str(0,"You're starting to hear voices, just quiet enough that you can't hear what they're saying. In any case, you're not sure that you'd want to know what they're saying.",0);
		add_dialog_str(1,"It would definitely be a good idea to either get out of here, or complete your mission. And quickly.",0);
		run_dialog(1);
		}
	if(insanity == 110) {
		reset_dialog();
		add_dialog_str(0,"The voices are getting louder and more distinct. Most of them speak in incoherent tongues, but a few are saying very, very unpleasant things in languages you can understand.",0);
		add_dialog_str(1,"You want to get out of here, but you're not sure you can think straight enough to find your way out anymore.",0);
		run_dialog(1);
		}
	if(insanity == 120) {
		reset_dialog();
		add_dialog_str(0,"The voices are drowning out your thoughts, and you begin to stumble. You end up on the floor after your legs collapse under you.",0);
		add_dialog_str(1,"You start to see blue motes of light around you, and a few indistinct shapes at the edge of your vision. Then, you black out, alone in the catacombs.",0);
		run_dialog(1);
		kill_char(1000,2,0);
		}

	icecount = 0;
	while(icecount < 4) {
		icex = get_ran(1,0,10) + 30;
		icey = get_ran(1,0,8) + 48;
		put_field_on_space(icex, icey, 4);
		icecount = icecount + 1;
		}

break;

beginstate 10; //stairs back up

	reset_dialog();
	add_dialog_str(0,"These stairs lead back up to the ground floor of the cathedral. Do you ascend?",0);
	add_dialog_choice(0,"No.");
	add_dialog_choice(1,"Yes.");
	choice = run_dialog(1);
	
	if(choice == 2)
		move_to_new_town(1,28,28);
	else
		block_entry(1);

break;

beginstate 11; //blank tombstone

	message_dialog("This tombstone is blank. It's probably a spare.","");

break;

beginstate 20; //crossing the first rune

	if(get_flag(8,2) == 0) {
		message_dialog("As you stare into the dark catacombs ahead of you, you realize that you don't know what you're supposed to be doing down here.","You should figure that out before you venture any further.");
		block_entry(1);
		end();
		}

	if(get_flag(8,5) > 0)
		end();

	reset_dialog();
	add_dialog_str(0,"The second your feet cross this rune, an icy blast of air nearly knocks them out from under you. Clearly, the ghosts intend to give you a warm welcome.",0);
	add_dialog_str(1,"You can hear voices coming from further down the hallway. None of them sound particularly hostile, but you should be prepared for anything.",0);
	play_sound(-75);
	run_dialog(1);
	set_flag(8,5,1);

break;

beginstate 21; //up the hall

	if(get_flag(8,5) > 1)
		end();

	reset_dialog();
	if(party_size() == 1) {
		add_dialog_str(0,"As you continue up the hall, you start to feel a bit unbalanced, as if something is rooting around in your brain.",0);
		add_dialog_str(1,"Whatever it is, it's painful, and you should try to complete your mission before it wrecks your mind.",0);
		}
	else {
		add_dialog_str(0,"As you continue up the hall, you all start to feel a bit unbalanced, as if something is rooting around in your brains.",0);
		add_dialog_str(1,"Whatever it is, it's painful, and you should try to complete your mission before it wrecks your minds.",0);
		}
	run_dialog(1);
	set_flag(8,5,2);

break;

beginstate 22; //the door & runes

	if((get_flag(8,9) == 2) && (get_flag(8,6) != 1)) {
		message_dialog("Hm. That's odd. You remember crossing these runes without disturbing them at all, yet they now appear to be scuffed and scratched.","Regardless of what caused it, it's not good.");
		set_flag(8,9,3);
		}
	else if(get_flag(8,9) == 2)
		set_flag(8,9,3);

	if(get_flag(8,5) > 2)
		end();
	
	reset_dialog();
	add_dialog_str(0,"As you approach the door to the tomb Felix told you about, you notice the incredibly intricate glowing runes that surround it.",0);
	clear_buffer();
	append_string("Realizing that you don't really have any choice other than crossing the runes, ");
	if(party_size() != 1) {
		append_char_name(lead_char);
		append_string(" carefully tries to step across.");
		}
	else
		append_string("you carefully try to step across.");
	get_buffer_text(runestep);
	add_dialog_str(1,runestep,0);
	if((char_has_trait(lead_char,12) == 1) || (char_has_trait(lead_char,14) == 1) || (char_has_trait(lead_char,10) == 1) || (get_stat(lead_char,1) <= 4) || (get_stat(lead_char,18) == 0)) {
		clear_buffer();
		append_string("Regrettably, ");
		if(party_size() != 1) {
			append_char_name(lead_char);
			append_string(" mis-steps and scratches out part of the runes. Hopefully it won't matter, but it still feels like a bad start.");
			}
		else
			append_string(" you mis-step and scratch out part of the runes. Hopefully it won't matter, but it still feels like a bad start.");
		get_buffer_text(runestep);
		add_dialog_str(2,runestep,0);
		set_flag(8,6,1);
		}
	else {
		clear_buffer();
		append_string("Fortunately, ");
		if(party_size() != 1) {
			append_char_name(lead_char);
			append_string(" avoids damaging the runes, and now the rest of you can cross with a secure knowledge of where to step.");
			}
		else
			append_string("you avoid damaging the runes, and now you know how to cross them safely.");
		get_buffer_text(runestep);
		add_dialog_str(2,runestep,0);
		}
	run_dialog(1);
	set_flag(8,5,3);

break;


beginstate 30; //entering the tomb

	if(get_flag(8,7) == 1)
		end();

	force_instant_terrain_redraw();
	pause(2);
	put_effect_on_space(41,52,0,4,1);
	put_effect_on_space(40,53,0,4,1);
	put_effect_on_space(40,52,0,4,1);
	put_effect_on_space(40,51,0,4,1);
	run_animation_sound(75);
	damage_near_loc(41,52,50,6,5);

	reset_dialog();
	add_dialog_str(0,"The second you open the door, a biting cold wind slices through you. Inside, you can see snowflakes blowing around.",0);
	add_dialog_str(1,"This is clearly not good.",0);
	run_dialog(1);

	set_flag(8,7,1);

break;

beginstate 31; //unmarked graves

	if(get_flag(8,8) == 1)
		end();

	reset_dialog();
	add_dialog_str(0,"Now that you can see the graves through the swirling snowflakes, you're a little surprised to find that none of the graves are marked.",0);
	add_dialog_str(1,"If what Felix said was right, they're soldiers. You can't help but wonder why the Empire would fail to honor their fallen. Not to mention why the soldiers are buried here.",0);
	run_dialog(1);

	set_flag(8,8,1);

break;


beginstate 35; //swapping the crystal

	if(get_flag(8,9) == 2) {
		print_str_color("The machine has gone dark.",2);
		end();
		}

	reset_dialog();
	if(get_flag(8,9) == 0) {
		add_dialog_str(0,"You can feel the waves of magic being exuded by this machine. It feels unpleasant, but not as unpleasant as the atmosphere everywhere else down here.",0);
		add_dialog_str(1,"Near the top of the machine, there's a slot with a crystal in it. If Felix told you correctly, you need to switch the crystal out for the one he gave you.",0);
		set_flag(8,9,1);
		}
	else
		add_dialog_str(0,"The machine is still here.",0);
	add_dialog_str(2,"Do you swap the crystals?",0);
	if(has_item(445) == 1) {
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No, not yet.");
		}
	else
		add_dialog_choice(1,"Erm... what crystal?");
	choice = run_dialog(1);

	if(choice == 1)
		set_state_continue(36);
	else
		message_dialog("You leave the machine alone.","");

break;

beginstate 32; //block the graves
	block_entry(1);
break;

beginstate 36; //LETTING THE GHOSTS OUT!!!

	if(get_flag(50,0) > 0) {
		print_str("The machine is unresponsive.");
		end();
		}

	set_flag(8,9,2);
	set_flag(50,0,1);

	play_sound(126);
	pause(5);
	play_sound(-7);
	set_terrain(28,52,388);
	force_instant_terrain_redraw();
	toggle_quest(4,0);
	pause(2);
	reset_dialog();
	add_dialog_str(0,"Carefully, you pull the crystal out of the machine. Strangely enough, the crystal is burning hot, and you nearly drop it. The machine flickers and dims.",0);
	if(party_size() == 1)
		add_dialog_str(1,"You barely manage to get the new crystal out of your pack before...",0);
	else {
		clear_buffer();
		pc_counter = 0;
		while((char_has_item(pc_counter, 445) == 0) && (pc_counter < 4)) {
			pc_counter = pc_counter + 1;
			}
		append_char_name(pc_counter);
		append_string(" barely manages to get the new crystal out before...");
		get_buffer_text(crystal);
		add_dialog_str(1,crystal,0);
		}
	run_dialog(1);

	force_view_center(34,52);
	force_instant_terrain_redraw();
	pause(3);
	activate_hidden_group(1);

	//fix groups
	add_char_to_group(13,1);
	add_char_to_group(9,1);
	add_char_to_group(23,1);
	add_char_to_group(14,1);
	add_char_to_group(19,1);
	add_char_to_group(17,1);
	add_char_to_group(28,2);
	add_char_to_group(29,2);

	play_sound(-165);
	set_character_pose(1001,14);
	force_instant_terrain_redraw();
	pause(1);
	activate_hidden_group(2);

	//fix groups
	add_char_to_group(12,2);
	add_char_to_group(15,2);
	add_char_to_group(8,2);
	add_char_to_group(27,2);
	add_char_to_group(18,2);
	add_char_to_group(21,2);
	add_char_to_group(24,2);
	add_char_to_group(11,2);

	set_character_pose(1001,13);
	set_character_pose(1002,14);
	force_instant_terrain_redraw();
	pause(1);
	activate_hidden_group(3);

	//fix groups
	add_char_to_group(26,3);
	add_char_to_group(30,3);
	add_char_to_group(25,3);
	add_char_to_group(16,3);
	add_char_to_group(7,3);
	add_char_to_group(10,3);
	add_char_to_group(20,3);
	add_char_to_group(22,3);

	set_character_pose(1001,12);
	set_character_pose(1002,13);
	set_character_pose(1003,14);
	force_instant_terrain_redraw();
	pause(1);
	set_character_pose(1001,11);
	set_character_pose(1002,12);
	set_character_pose(1003,13);
	force_instant_terrain_redraw();
	pause(1);
	set_character_pose(1001,0);
	set_character_pose(1002,11);
	set_character_pose(1003,12);
	force_instant_terrain_redraw();
	pause(1);
	set_character_pose(1002,0);
	set_character_pose(1003,11);
	force_instant_terrain_redraw();
	pause(1);
	set_character_pose(1003,0);
	force_instant_terrain_redraw();

	pause(3);
	reset_dialog();
	add_dialog_str(0,"Wow. This is definitely not what you were hoping would happen.",0);
	add_dialog_str(1,"You're used to seeing ghosts and shades appear in vague, distorted forms of their living selves. This is new, and just a little frightening.",0);
	add_dialog_str(2,"One of the ghosts stirs...",0);
	run_dialog(1);

	pause(3);
	text_bubble_on_char(26,"Mages, disarm!");
	force_instant_terrain_redraw();
	pause(15);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(3);
	set_character_facing(17,2);
	set_character_pose(17,2);
	set_character_facing(21,2);
	set_character_pose(21,2);
	force_instant_terrain_redraw();
	pause(3);
	set_character_pose(17,1);
	set_character_pose(21,1);
	put_effect_on_char(pc_counter,4,4,1);
	put_jagged_zap(35,50,char_loc_x(pc_counter), char_loc_y(pc_counter),4);
	put_jagged_zap(35,54,char_loc_x(pc_counter), char_loc_y(pc_counter),4);
	run_animation_sound(89);
	pause(1);
	message_dialog("Somehow, the ghosts' blasts didn't harm you. However, you soon realize that the crystal Felix gave you has been reduced to a fine powder.","Looks like you're going to have to find another way to deal with this.");
	take_item(445);
	set_character_pose(17,0);
	set_character_pose(21,0);
	force_instant_terrain_redraw();
	pause(3);
	text_bubble_on_char(26,"Move out!");
	force_instant_terrain_redraw();
	pause(15);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(3);
	put_boom_on_char(7,5,0);
	put_boom_on_char(10,5,0);
	put_boom_on_char(13,5,0);
	put_boom_on_char(16,5,0);
	put_boom_on_char(19,5,0);
	put_boom_on_char(22,5,0);
	put_boom_on_char(25,5,0);
	put_boom_on_char(28,5,0);
	erase_char(1001);
	run_animation_sound(52);
	put_boom_on_char(8,5,0);
	put_boom_on_char(11,5,0);
	put_boom_on_char(14,5,0);
	put_boom_on_char(17,5,0);
	put_boom_on_char(20,5,0);
	put_boom_on_char(23,5,0);
	put_boom_on_char(26,5,0);
	put_boom_on_char(29,5,0);
	erase_char(1002);
	run_animation_sound(52);
	put_boom_on_char(9,5,0);
	put_boom_on_char(12,5,0);
	put_boom_on_char(15,5,0);
	put_boom_on_char(18,5,0);
	put_boom_on_char(21,5,0);
	put_boom_on_char(24,5,0);
	put_boom_on_char(27,5,0);
	put_boom_on_char(30,5,0);
	erase_char(1003);
	run_animation_sound(52);
	force_instant_terrain_redraw();
	pause(5);
	force_view_center(char_loc_x(lead_char),char_loc_y(lead_char));

	erase_char(6);

	activate_hidden_group(10);
	force_instant_terrain_redraw();
	pause(5);
	reset_dialog();
	add_dialog_str(0,"Well, this is a problem. The ghosts are free of their tomb, and they've disappeared to... well, somewhere. And it's still really cold in here.",0);
	add_dialog_str(1,"On the other hand, it seems that the oppressive atmosphere that filled the catacombs has lifted, making it possible to hear your thoughts again.",0);
	add_dialog_str(2,"However, you also think that you can hear faint voices echoing from somewhere in the catacombs. Perhaps not all of the ghosts have left yet.",0);
	insanity = 0;
	run_dialog(1);
	

break;

beginstate 37; //cutscene & fight

	if(get_flag(8,9) != 3)
		end();

	set_flag(8,9,4);
	message_dialog("You feel yet another cold breeze blowing up the passageway at you.","");

	pause(5);

	put_boom_on_space(46,52,5,0);
	activate_hidden_group(5);
	if(get_flag(8,6) == 1) {
		put_boom_on_space(45,52,5,0);
		put_boom_on_space(45,51,5,0);
		put_boom_on_space(45,53,5,0);
		activate_hidden_group(4);
		}
	set_character_pose(31,14);
	set_character_pose(32,14);
	set_character_pose(33,14);
	set_character_pose(34,14);
	run_animation_sound(52);
	play_sound(-165);
	pause(1);
	set_character_pose(31,13);
	set_character_pose(32,13);
	set_character_pose(33,13);
	set_character_pose(34,13);
	force_instant_terrain_redraw();
	pause(1);
	set_character_pose(31,12);
	set_character_pose(32,12);
	set_character_pose(33,12);
	set_character_pose(34,12);
	force_instant_terrain_redraw();
	pause(1);
	set_character_pose(31,11);
	set_character_pose(32,11);
	set_character_pose(33,11);
	set_character_pose(34,11);
	force_instant_terrain_redraw();
	pause(1);
	set_character_pose(31,0);
	set_character_pose(32,0);
	set_character_pose(33,0);
	set_character_pose(34,0);
	force_instant_terrain_redraw();

	pause(3);

	reset_dialog();
	if(get_flag(8,6) != 1) {
		add_dialog_str(0,"The ghost stares through you for a while. Then, it speaks.",0);
		add_dialog_str(1,"_Three of my men were disrupted trying to break through those runes. Rest assured that if they had survived, they would have greeted you now._",0);
		add_dialog_str(2,"_But as it stands now, my men are busy throughout the cathedral. Do not interfere with our work, or we will crush you like worms._",0);
		}
	else {
		add_dialog_str(0,"The ghosts stand there for a while at what probably passes for attention in the afterlife. Then, the one who looks to be a dead captain speaks.",0);
		add_dialog_str(1,"_I'd like to thank you for scratching out these runes. It made our movements much easier,_ the ghost says, smiling.",0);
		add_dialog_str(2,"_Now, the rest of my men are busy throughout the cathedral. And to make sure that you do not interfere with us, I leave you with my guards._",0);
		}
	run_dialog(1);
	
	pause(5);
	put_boom_on_char(31,5,0);
	erase_char(31);
	run_animation_sound(52);

	if(get_flag(8,6) == 1) {
		reset_dialog();
		add_dialog_str(0,"And with that, the captain departs, leaving you with a few snarling shades of Empire soldiers.",0);
		add_dialog_str(1,"Apparently, they also have weapons in the afterlife. In any case, the soldiers draw swords and take a step towards you.",0);
		run_dialog(1);
		set_attitude(32,10);
		set_attitude(33,10);
		set_attitude(34,10);
		}
	else
		message_dialog("With that, the captain departs. You just hope that you're finally alone down here.","");

break;

beginstate 38; //teh Ÿber-cutscene

	if(get_flag(8,9) != 4)
		end();

	play_sound(162); //odd chime sound

	reset_dialog();
	if(party_size() == 1) {
		add_dialog_str(0,"You hear a voice in your head. It's not the same as the captain who spoke to you before, but someone who sounds a bit calmer...",0);
		add_dialog_str(1,"_Friend, wait a moment. Before you act rashly, you must know our story._",0);
		}
	else {
		add_dialog_str(0,"You hear a voice in your heads. It's not the same as the captain who spoke to you before, but someone who sounds a bit calmer...",0);
		add_dialog_str(1,"_Friends, wait a moment. Before you act rashly, you must know our story._",0);
		}
	add_dialog_str(2,"A series of images swirls before you...",0);
	run_dialog(1);

	pause(5);

	force_view_center(10,10);
	force_instant_terrain_redraw();
	play_sound(10);

	reset_dialog();
	add_dialog_str(0,"The voice returns. _It was during the Avernum War. Our regiment had just been deployed to the caves, and we were assigned a mission to attack Fort Draco._",0);
	add_dialog_str(1,"_We snuck through giant-infested lands, and we were nearly upon the fort..._",0);
	run_dialog(1);

	pause(1);
	set_total_visibility(1);
	force_instant_terrain_redraw();

	pause(4);
	force_view_center(11,10);
	set_terrain(9,10,0);
	set_terrain(10,10,103);
	set_terrain(11,10,105);
	set_terrain(12,10,104);
	play_sound(-49); //footstep
	play_sound(-47); //foot + gravel
	play_sound(-50); //footstep2
	pause(1);
	play_sound(-49);
	play_sound(-50);
	force_instant_terrain_redraw();
	pause(4);
	force_view_center(12,10);
	set_terrain(10,10,0);
	set_terrain(11,10,103);
	set_terrain(12,10,105);
	set_terrain(13,10,104);
	play_sound(-49);
	play_sound(-50);
	play_sound(-47);
	pause(1);
	play_sound(-50);
	play_sound(-47);
	force_instant_terrain_redraw();
	pause(4);
	force_view_center(13,10);
	set_terrain(11,10,0);
	set_terrain(12,10,103);
	set_terrain(13,10,105);
	set_terrain(14,10,104);
	play_sound(-49);
	play_sound(-47); //foot + gravel
	play_sound(-50);
	pause(1);
	play_sound(-50);
	play_sound(-49);
	play_sound(-47);
	force_instant_terrain_redraw();
	reset_dialog();
	add_dialog_str(0,"_We paused before a split in the tunnel because one of the mages felt something. So we crouched down and waited for an attack._",0);
	add_dialog_str(1,"_Suddenly, we felt the damp air crackle, and bolts of static started discharging off our armor and weapons._",0);
	run_dialog(1);

	pause(1);
	put_sparkles_on_space(13,10,11,12);
	put_sparkles_on_space(13,9,11,12);
	run_animation_sound(164); //lightning strike
	put_sparkles_on_space(13,10,11,12);
	put_sparkles_on_space(13,9,11,12);
	run_animation_sound(164); //lightning strike
	put_effect_on_space(13,10,1,12,1);
	put_effect_on_space(13,9,1,12,1);
	set_terrain(13,10,121);
	set_terrain(13,9,121);
	run_animation_sound(169); //gassy boom
	pause(1);
	play_sound(-21); //dead female
	play_sound(-31);
	pause(1);
	play_sound(-29); //hurt male
	play_sound(-84); //dead male
	play_sound(-31); //misc death
	play_sound(13); //party death

	pause(10);
	reset_dialog();
	add_dialog_str(0,"_A massive barrier suddenly filled the cave, effectively cutting the force in two. Some unlucky souls were caught at the edge of the barrier, and were instantly reduced to ash._",0);
	add_dialog_str(1,"_But a group of us were caught literally within the barrier, where the air was quickly consumed by the expanding flames. We died a painful, sudden death._",0);
	add_dialog_str(2,"_As a result, the mission was compromised. The troops caught on the Fort Draco side wound up lost in the caves, and were eventually ambushed by adventurers._",0);
	add_dialog_str(3,"_The others fought their way back through giant lands, and eventually to the Tower of Eldiran. They informed the commanders of our failure while we sat outside our bodies and waited._",0);
	run_dialog(1);
	
	set_total_visibility(0);
	force_instant_terrain_redraw();
	pause(2);
	message_dialog("_Soon after the barrier fell, a squad of soldiers came from the east and retrieved our bodies, those that remained._","");
	
	set_total_visibility(1);
	force_view_center(10,54);
	force_instant_terrain_redraw();
	pause(10);

	reset_dialog();
	add_dialog_str(0,"_As our spirits hung around our bodies, we heard from the soldiers transporting us that the Empire refused to acknowledge the attack it had attempted._",0);
	add_dialog_str(1,"_To that end, we were buried in this cathedral, and shortly after that our strength failed and we faded away. We do not know what happened between then and now._",0);
	run_dialog(1);

	pause(3);

	force_view_center(char_loc_x(lead_char),char_loc_y(lead_char));
	set_total_visibility(0);
	force_instant_terrain_redraw();

	pause(5);

	reset_dialog();
	add_dialog_str(0,"The images depart, but the voice remains.",0);
	add_dialog_str(1,"_Now, we have risen again for reasons we cannot understand. When the priests came to deal with us, we learned from them that the Empire still refuses to acknowledge our sacrifice._",0);
	add_dialog_str(2,"_When we tried to explain our story to the priests, they told us that they had been charged with our confinement, and we were to be held here forever._",0);
	add_dialog_str(3,"_Our only wish is to escape, so that we might right the wrong committed by the Empire. You can help us in this goal, but I have said too much for now._",0);
	add_dialog_str(4,"_If we find you useful, you will be contacted again. Otherwise, we hope that you stay out of our way._",0);
	run_dialog(1);

	pause(3);

	reset_dialog();
	if(party_size() == 1)
		add_dialog_str(0,"The voice fades from your mind, leaving an odd echo.",0);
	else
		add_dialog_str(0,"The voice fades from your minds, leaving an odd echo.",0);
	run_dialog(1);

	set_flag(8,9,5);


break;


beginstate 40; //felix is gone

	if((get_flag(8,10) > 0) || (get_flag(50,0) == 0))
		end();

	reset_dialog();
	add_dialog_str(0,"Nearing the steps that lead out of the catacombs, you notice that Felix is absent.",0);
	add_dialog_str(1,"You wish he hadn't kept the floors so clean, so that you could've at least checked for footprints.",0);
	run_dialog(1);
	set_flag(8,10,1);

break;


beginstate 50; //chamber w/ crying ghost

	if((get_flag(50,1) == 1) || (get_flag(8,11) == 1))
		end();

	reset_dialog();
	add_dialog_str(0,"You hear the sound of crying coming from within this chamber.",0);
	run_dialog(1);
	set_flag(8,11,1);

break;

beginstate 51; //chamber with insubstantial ghost

	if((get_flag(8,15) == 1) || (get_flag(50,1) == 1))
		end();

	reset_dialog();
	add_dialog_str(0,"That's odd... you feel the presence of a ghost, but there's nothing in here. The presence feels weak, which means the ghost is weak.",0);
	add_dialog_str(1,"Perhaps it doesn't have the strength to materialize.",0);
	run_dialog(1);

	set_flag(8,15,1);

break;



beginstate 70; //the spirit's chamber runes

	if(get_flag(0,17) == 3)  {
		reset_dialog();
		add_dialog_str(0,"Huh. That's odd... you definitely remember there being a door here. Perhaps Nathan had something to do with this.",0);
		run_dialog(1);
		set_flag(0,17,4);
		}

	if(get_flag(8,16) > 0)
		end();

	reset_dialog();
	if(get_highest_skill(42) < 25)
		add_dialog_str(0,"These are some incredibly complex runes. In fact, they are so intricate that you suspect that they are only there for decoration.",0);
	else {
		add_dialog_str(0,"You recognize these runes as containment runes. Their intricacy suggests that something incredibly powerful is either being kept in or out of this room. It might be wise to stay out.",0);
		set_flag(8,17,1);
		}
	add_dialog_str(1,"Either way, they're fairly easy to step over without rubbing them out. No reason to take any chances.",0);
	run_dialog(1);

	set_flag(8,16,1);

break;

beginstate 71; //the tomb

	if(get_flag(8,16) > 1)
		end();

	reset_dialog();
	add_dialog_str(0,"As you step into this chamber, you find a gracefully-arched and surprisingly well-lit tomb. A sarcophagus sits atop a raised platform.",0);
	if(get_flag(8,17) == 1)
		add_dialog_str(1,"You're starting to get the feeling that you're being watched. And after seeing those runes, that's not good.",0);
	else
		add_dialog_str(1,"You're starting to get the feeling that you're being watched.",0);
	run_dialog(1);

	set_flag(8,16,2);


break;

beginstate 72; //the sarcophagus

	if(get_flag(8,16) > 3)
		end();

	reset_dialog();
	if(get_flag(8,16) < 3) {
		set_flag(8,16,3);
		add_dialog_str(0,"This ornately-carved sarcophagus is surprisingly easy to open. However, the contents are even more surprising.",0);
		add_dialog_str(1,"Treasure. Lots and lots of it. The sarcophagus is practically overflowing with it, ranging from golden coins to goblets to strange crystals.",0);
		if(get_flag(0,17) >= 1)
			add_dialog_str(2,"This is almost definitely the treasure that Nathan in Stratton told you about. You could tell him about the treasure, or just take it for yourself.",0);
		add_dialog_str(3,"As you look at it, the feeling that you're being watched gets more intense. What do you do?",0);
		}
	else 
		add_dialog_str(0,"The treasure is still here for the taking, though you can't shake the feeling that there's something in the chamber with you. What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Take the treasure.");
	choice = run_dialog(1);
	if(choice == 1)
		end();
	else {
		clear_quest(2);
		
		change_coins(4000);
		reward_give(203);
		reward_give(204);
		reward_give(203);
		reward_give(204);
		reward_give(203);
		reward_give(204);
		reward_give(204);
		reward_give(204);
		reward_give(205);
		reward_give(205);
		reward_give(205);
		reward_give(208);
		reward_give(210);
		reward_give(212);
		reward_give(326);
		reward_give(326);
		reward_give(327);
		reward_give(328);
		reward_give(420);
		reward_give(420);
		reward_give(202);
		reward_give(202);
		reward_give(202);
		reward_give(167);
		reward_give(167);

		reset_dialog();
		add_dialog_str(0,"As you greedily scoop treasure from the sarcophagus, that nervous feeling of being watched intensifies. Soon, the case is empty, and you begin to edge nervously toward the door.",0);
		run_dialog(1);
		pause(5);
		play_sound(-108);
		set_flag(8,16,4);
		set_terrain(49,5,137);
		set_terrain(49,14,4);
		force_instant_terrain_redraw();
		pause(15);
		reset_dialog();
		add_dialog_str(0,"Without warning, the sarcophagus crumbles into a pile of rubble and dust, and the air is suddenly filled with the crisp crackle of magic.",0);
		add_dialog_str(1,"As you begin to worry, you glance towards the door, only to see that it has disappeared, only to be replaced by a solid wall. This can't be good.",0);
		run_dialog(1);
		pause(10);
		activate_hidden_group(19);
		add_range_to_group(48,51,6);
		//erase_char(1006);
		add_char_to_group(39,6);
		put_boom_on_space(49,5,3,0);
		run_animation_sound(95);
		pause(15);

		reset_dialog();
		add_dialog_str(0,"A ghost appears in front of you, practically pulsing with magical energy. You don't need anything else to see that it's angry.",0);
		if(get_flag(8,17) == 1)
			add_dialog_str(1,"Well, at least you know what the runes were keeping in.",0);
		run_dialog(1);
		}

break;


//coffins
beginstate 100; //coffin at 55,43

	reset_dialog();
	add_dialog_str(0,"Inscribed on the coffin, you see:",0);
	add_dialog_str(1,"Mother Melissa Reese, 547-595. Devoted priestess of the church, defended Stratton during the Parnosa Offensive.",10);
	run_dialog(1);

	if(get_flag(8,13) == 0)
		set_flag(8,13,1);

break;

beginstate 101; //coffin at 37,28 (Robert Paulsen's)

	reset_dialog();
	add_dialog_str(0,"This coffin's inscription seems to have been worn away by drops of water falling from the ceiling, judging from the small pool of water that has collected on its lid.",0);
	run_dialog(1);

break;


beginstate 102; //coffin at 37,40 (crying ghost's)

	reset_dialog();
	add_dialog_str(0,"This coffin has no name inscribed on it. Instead, a single word adorns the lid:",0);
	add_dialog_str(1,"Beloved",10);
	run_dialog(1);

break;


beginstate 103; //coffin at 43,40 (faded ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Joel Harrison, 498-561. Devoted father.",10);
	run_dialog(1);

break;

beginstate 104; //coffin at 43,28 (faded ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Brittany Freal, 487-533. Loving wife.",10);
	run_dialog(1);

break;

beginstate 105; //coffin at 43,22 (gibbering ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Xavier Berke, 492-523. His sacrifice was not in vain.",10);
	run_dialog(1);

break;

beginstate 106; //coffin at 55,19 (gibbering ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Melanie Othos, 509-571. Bested three gremlins in combat before the rest arrived.",10);
	run_dialog(1);

break;

beginstate 107; //coffin at 55,25 (aimless ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Jonathan Norris, 584-611. Wanderer for life. May his travels span the earth.",10);
	run_dialog(1);

break;

beginstate 108; //coffin at 55,31 (faded ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Maurice Yolin, 641-695. Gone but not forgotten.",10);
	run_dialog(1);

break;

beginstate 109; //coffin at 55,37 (angry ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Elric Matthews, 603-712. An inspiring teacher, an exemplary mage, and short-tempered chess player. May his memory live on.",10);
	run_dialog(1);

break;

beginstate 110; //coffin at 55,49 (faded ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Hubert Rankin, 599-641. Died defending his family from goblins. An incredible father right up to the bitter end.",10);
	run_dialog(1);

break;

beginstate 111; //coffin at 43,46 (aimless ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Sgt. Henry Woolington, 623-659. Served for twenty years, fought in battle of Woodsmuir. May he one day rally the troops of heaven like he did on earth.",10);
	run_dialog(1);

break;

beginstate 112; //coffin at 47,58 (no ghost)

	reset_dialog();
	add_dialog_str(0,"This coffin's lid bears a brief inscription:",0);
	add_dialog_str(1,"Mayor William Kemper, 431-509. Aided in the funding of the cathedral, and lived to see its spires completed. Died protecting imperial documents from rebels.",10);
	run_dialog(1);

break;