// Town 9: Guardpost
begintownscript;

variables;

short choice,dummy,i,j;
string dlgstr;

body;

beginstate INIT_STATE;
set_name(6,"Kass");
set_char_dialogue_pic(6,533,0);
set_name(9,"Ethass");
set_char_dialogue_pic(9,534,0);
set_name(10,"Pithoss");
set_char_dialogue_pic(10,530,0);
set_name(11,"Legare");
set_char_dialogue_pic(11,1926,0);
set_char_dialogue_pic(12,535,0);
set_name(13,"Machrone");
set_char_dialogue_pic(25,535,0);
set_name(29,"Silthokh");

set_crime_tolerance(2);
enable_add_chars(1);

if ((char_ok(4)) || (char_ok(5)) || (has_item(451)))
	erase_char(25);
	
if (get_flag(250,5) == 2)
	set_terrain(4,19,12);

if (get_flag(11,0) != 0)
	erase_char(12);
	
if ((get_flag(12,6) == 1) && (get_flag(9,18) == 0))
	activate_hidden_group(2);
	
if (get_flag(10,4))
	{i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	relocate_character(0,8,37);
	relocate_character(1,8,38);
	relocate_character(2,8,39);
	relocate_character(3,7,39);
	relocate_character(4,7,38);
	set_character_facing(0,0);
	set_character_facing(1,0);
	set_character_facing(2,0);
	set_character_facing(3,6);
	set_character_facing(4,4);
	force_view_center(char_loc_x(i),char_loc_y(i));
	force_instant_terrain_redraw();
	set_flag(10,4,0);
	}
	
if (get_flag(9,13) == 1)
	{message_dialog("After a some quick talking, you manage to explain that you are the adventurers that Legare hired, not assassins sent by the priests of Gnass to kill Legare. They let you pass.","It appears that you have finally finished your sidequest. You have freed the spirits in Ancient Bahssikava, and you have returned to tell the tale. Now it's time to speak to Kass again about the details of your new mission.");
	set_flag(9,13,2);
	}

if (has_item(451))
	{activate_hidden_group(1);
	set_state_continue(22);
	}
	
if (get_flag(9,0))
	{activate_hidden_group(1);
	end();
	}
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	j = 3;
	while (char_ok(j) == 0)
		{j = j - 1; }
		
	set_floor(19,2,79);
	set_floor(20,2,79);
	set_floor(21,2,79);
	set_floor(22,2,79);
		
	set_terrain(20,3,14);
	set_terrain(21,3,14);
	
	set_terrain(20,14,26);
	set_terrain(21,14,26);
	
	set_terrain(20,19,137);
	set_terrain(21,19,138);
	set_terrain(20,20,433);
	set_terrain(21,20,433);
	set_terrain(20,21,138);
	set_terrain(21,21,138);
	
	relocate_character(0,21,4);
	relocate_character(1,21,3);
	relocate_character(2,21,2);
	relocate_character(3,21,1);
	
	set_character_facing(0,4);
	set_character_facing(1,4);
	set_character_facing(2,4);
	set_character_facing(3,4);
	
	// Legare and Kass
	place_monster(20,6,109,0);
	place_monster(21,6,36,0);
	
	set_character_facing(86,4);
	set_character_facing(87,4);
	
	force_view_center(21,4);
	
	force_instant_terrain_redraw();
	message_dialog("With completely silent awe inside you, you step through the doorway with Legare and Kass, fully expecting to find glorious, ancient slith cities on just the other side.","You don't find exactly that.");
	
	relocate_character(86,20,7);
	relocate_character(87,21,7);
	march_party(21,5);
	force_view_center(21,5);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(i,"What is this?");
	relocate_character(86,20,8);
	relocate_character(87,21,8);
	march_party(21,6);
	force_view_center(21,6);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(86,20,9);
	relocate_character(87,21,9);
	march_party(21,7);
	force_view_center(21,7);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(86,20,10);
	relocate_character(87,21,10);
	march_party(21,8);
	force_view_center(21,8);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(86,20,11);
	relocate_character(87,21,11);
	march_party(21,9);
	force_view_center(21,9);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(86,"It is an ancient guardpost.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	set_character_facing(86,2);
	set_character_facing(87,6);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(86,"The Goddess told me");
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,22,11);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,23,11);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,24,11);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"that we would find something like this.");
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,24,12);
	set_character_facing(87,4);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	set_character_facing(87,6);
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	set_character_facing(86,0);
	relocate_character(87,23,12);
	set_character_facing(87,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(86,"After they shut the steel doors,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"the sliths of the homeland");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"posted a guard here to make certain");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"that no one broke through.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"In those days,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"the Darklings were strong,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"and they might have even managed it");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"if the Bahssikavans had not rebelled");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"and fought them from the moment");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"that they stepped through those doors.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(87,"The sliths here were skilled.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"Look at the size of the windows.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"They are barely large enough");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"to shoot an arrow through.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"If the Darklings had broken through,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"the guards would have shot at them");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"without any fear of retaliation.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	relocate_character(86,20,10);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(86,20,9);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(86,20,8);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(86,"You may come through next, Phaedra.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"We could use a warrior's opinion.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	set_character_facing(86,4);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	place_monster(20,0,255,0);
	set_character_facing(88,4);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,22,12);
	relocate_character(88,20,1);
	relocate_character(86,20,9);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,21,12);
	relocate_character(88,20,2);
	relocate_character(86,20,10);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,20,12);
	relocate_character(88,20,3);
	relocate_character(86,20,11);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,19,12);
	relocate_character(88,20,4);
	set_character_facing(86,0);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	set_character_facing(87,4);
	relocate_character(88,20,5);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(87,"*strain*");
	relocate_character(88,20,6);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(88,20,7);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(88,20,8);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"*struggle*");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(87,"In fact, Phaedra,");
	set_character_facing(87,0);
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"we could use a warrior's strength.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"Will you turn this wheel?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	force_instant_terrain_redraw();
	
	clear_buffer();
	append_string("You take a good look at Phaedra. She does not look quite comfortable.");
	if (get_flag(1,7))
		append_string(" She was supposed to get out of here at the first sign of trouble. You wonder if being in the middle of a slith civil war counts as _trouble_ to her superiors in Fort Dranlon.");
	else
		append_string(" Perhaps it has something to do with being in the middle of a slith civil war.");
	get_buffer_text(dlgstr);
	message_dialog(dlgstr,"Still, at Kass's request, she flashes a grin and gives a confident chuckle.");
	
	text_bubble_on_char(88,"Sure thing, Kass.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(88,"");
	relocate_character(87,18,12);
	set_character_facing(87,2);
	relocate_character(88,20,9);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	set_character_facing(87,6);
	relocate_character(88,19,10);
	set_character_facing(88,3);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(88,19,11);
	set_character_facing(88,4);
	set_character_facing(86,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(88,19,12);
	set_character_facing(86,4);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(88,"*grunt*");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(88,"");
	text_bubble_on_char(88,"*strain*");
	force_instant_terrain_redraw();
	play_sound(-99);
	set_terrain(20,14,30);
	set_terrain(21,14,30);
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(88,"");
	text_bubble_on_char(88,"The gears could use some maintenance.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(88,"");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	set_character_facing(87,0);
	text_bubble_on_char(87,"Well, what are we waiting for?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"Let's go home!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	force_instant_terrain_redraw();
	
	message_dialog("Legare's expression darkens. You can't know exactly what is going through his mind -- reading him is hard -- but if you had to guess, you'd say he was worried.","About what? He just performed the single greatest miracle in the history of Avernum sliths.");

	text_bubble_on_char(86,"Yes, let's...");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"take a look around.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	march_party(21,10);
	force_view_center(21,10);
	relocate_character(86,20,12);
	relocate_character(87,19,12);
	relocate_character(88,20,11);
	set_character_facing(88,7);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	march_party(21,11);
	force_view_center(21,11);
	relocate_character(86,20,13);
	relocate_character(87,20,12);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	// Machrone
	place_monster(20,3,78,0);
	set_character_facing(89,4);
	text_bubble_on_char(89,"Ah, er, um, Legare?");
	force_instant_terrain_redraw();
	pause(3 * get_flag(250,8));
	
	set_character_facing(0,0);
	set_character_facing(1,0);
	set_character_facing(2,0);
	set_character_facing(3,0);
	set_character_facing(86,0);
	set_character_facing(87,0);
	set_character_facing(88,0);
	force_instant_terrain_redraw();
	pause(3 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(86,"Yes, Machrone?");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(89,"I was just wondering");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(89,"if I could, um, come with you");
	relocate_character(89,20,4);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(89,20,5);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(89,20,6);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(89,20,7);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(89,"and, you know, document your findings.");
	relocate_character(89,20,8);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(89,20,9);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(89,20,10);
	force_instant_terrain_redraw();
	pause(3 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(89,"History in the making and all that.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(87,"*sigh*");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	set_character_facing(86,6);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(86,"Do what you will.");
	set_character_facing(86,0);
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"Only do not get in the way.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(89,"Oh, you won't even notice me.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(89,"I'll be invisible, unobtrusive,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(89,"just a fly on the wall, and");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(87,"And while you're at it,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"SHUT UP.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(89,"Not a word. Not even a peep.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(89,"Not even the slightest squeak.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(89,"Not even...");
	force_instant_terrain_redraw();
	pause(3 * get_flag(250,8));
	
	text_bubble_on_char(89,"");
	text_bubble_on_char(89,"Ow!");
	set_character_pose(88,1);
	force_instant_terrain_redraw();
	play_sound(157);
	
	text_bubble_on_char(89,"");
	set_character_pose(88,0);
	force_instant_terrain_redraw();
	pause(7 * get_flag(250,8));
	
	text_bubble_on_char(87,"Thank you.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	set_character_facing(0,4);
	set_character_facing(1,4);
	set_character_facing(2,4);
	set_character_facing(3,4);
	set_character_facing(86,4);
	set_character_facing(87,4);
	set_character_facing(88,4);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	if (get_flag(1,6))
		text_bubble_on_char(88,"Exciting, isn't it?");
	march_party(21,12);
	force_view_center(21,12);
	relocate_character(88,20,12);
	relocate_character(89,20,11);
	relocate_character(86,20,14);
	relocate_character(87,21,14);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	march_party(21,13);
	force_view_center(21,13);
	relocate_character(88,20,13);
	relocate_character(89,20,12);
	relocate_character(86,20,15);
	relocate_character(87,21,15);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	march_party(21,14);
	force_view_center(21,14);
	relocate_character(88,20,14);
	relocate_character(89,20,12);
	relocate_character(86,20,16);
	relocate_character(87,21,16);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	if (get_flag(1,6))
		{text_bubble_on_char(88,"");
		if (get_flag(250,3) == 2)
			text_bubble_on_char(i,"Actually, I didn't want to be here.");
		else
			text_bubble_on_char(i,"Yeah!");
		}
	march_party(21,15);
	force_view_center(21,15);
	relocate_character(88,20,15);
	relocate_character(89,20,14);
	relocate_character(86,20,17);
	relocate_character(87,21,17);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	march_party(21,16);
	force_view_center(21,16);
	relocate_character(88,20,16);
	relocate_character(89,20,15);
	relocate_character(86,20,18);
	relocate_character(87,21,18);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	set_character_facing(87,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	if (get_flag(1,6))
		{text_bubble_on_char(i,"");
		if (get_flag(250,3) == 2)
			text_bubble_on_char(i,"This wasn't part of the deal.");
		else
			{if (party_size() == 1)
				text_bubble_on_char(i,"I volunteered for this.");
			else
				text_bubble_on_char(i,"We volunteered for this.");
			}
		}
	relocate_character(87,20,17);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,19,17);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	if (get_flag(1,6))
		text_bubble_on_char(i,"");
	relocate_character(87,18,18);
	force_view_center(20,16);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,17,18);
	force_view_center(19,16);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	relocate_character(87,16,18);
	force_view_center(18,16);
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));
	
	text_bubble_on_char(87,"The river just keeps going.");
	set_character_facing(87,6);
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"The bridge is the only way across,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"and since it is broken,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"we are stuck for the time being.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(87,"");
	text_bubble_on_char(86,"Indeed.");
	set_character_facing(86,2);
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"Allow everyone to pass the threshold.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	set_character_facing(86,0);
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"Adventurers, there is a room with beds");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"northwest of here.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"I suggest you get some rest.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"When you awake, find me.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(86,"");
	
	force_view_center(3,3);
	force_instant_terrain_redraw();
	
	reset_dialog();
	add_dialog_str(0,"You sleep deeply for many hours. Your dreams are filled with bizarre images of slithzerikai, humans, and vahnatai working side-by-side to create powerful machines greater than any the Empire or Avernum have ever seen.",0);

	clear_buffer();
	append_string("You wake up, thinking.");
	if (get_flag(250,0) < 4) // no sliths in party
		append_string(" None of you can really understand what these sliths are going through. Being exiled from the surface recently is different: you know of your homeland, and you know you were cast out unjustly. Sliths know the opposite.");
	if (get_flag(250,0) == 4) // all sliths in party
		append_string(" It is hard not to think that you were born for this. There are not many slith adventurers, and Legare must have heard of you somehow and picked you out specifically for that reason."); 
	if ((get_flag(250,0) > 4) && (get_flag(251,3) > 1)) // some sliths in party
		{append_string(" You can hardly imagine what this mission means to your slith comrades. Being exiled from the surface recently is different: you know of your homeland, and you know you were cast out unjustly. Sliths know the opposite.");
		}
	if ((get_flag(250,0) > 4) && (get_flag(251,3) == 1)) // one slith in party
		append_string(" You can hardly imagine what this mission means to your slith comrade. Being exiled from the surface recently is different: you know of your homeland, and you know you were cast out unjustly. Sliths know the opposite.");
	get_buffer_text(dlgstr);
	add_dialog_str(1,dlgstr,0);
	
	if (get_flag(250,0) > 4)
		if (get_flag(251,3) > 0)
			{clear_buffer();
			append_string("Also, if you reach the homeland, what will happen? Will ");
			if (get_flag(251,3) > 1)
				append_string("they");
			else
				append_string("your companion");
			append_string(" stay there? Will you return to Avernum with ");
			append_number(get_flag(251,3));
			append_string(" fewer party member");
			if (get_flag(251,3) > 1)
				append_string("s");
			append_string("?");
			get_buffer_text(dlgstr);
			add_dialog_str(2,dlgstr,0);
			}
	
	clear_buffer();
	append_string("You continue to think this over until ");
	if (party_size() > 1)
		append_string("your companions wake up.");
	else
		append_string("it is time to rise.");
	append_string(" Then you push the thoughts aside for the time being. It is time to meet with Legare and find out what the next stage of your quest will be.");
	get_buffer_text(dlgstr);
	add_dialog_str(3,dlgstr,0);
	dummy = run_dialog(1);
	
	relocate_character(0,5,9);
	relocate_character(1,6,9);
	relocate_character(2,7,9);
	relocate_character(3,8,9);
	set_character_facing(0,2);
	set_character_facing(1,2);
	set_character_facing(2,2);
	set_character_facing(3,2);
	
	erase_char(86);
	erase_char(87);
	erase_char(88);
	erase_char(89);
	
	activate_hidden_group(1);

	set_terrain(20,3,10);
	set_terrain(21,3,10);

	set_terrain(20,19,299);
	set_terrain(21,19,299);
	set_terrain(20,20,299);
	set_terrain(21,20,299);
	set_terrain(20,21,299);
	set_terrain(21,21,299);
	
	set_floor(19,2,101);
	set_floor(20,2,101);
	set_floor(21,2,101);
	set_floor(22,2,101);

	force_view_center(5,9);
	force_instant_terrain_redraw();
	set_flag(9,0,1);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
// This is where text bubbles go
break;

beginstate 10;
if (get_flag(9,1))
	end();
	
	message_dialog("There are some old and withering crops here. These are strange, foreign-looking mushrooms, but they were probably nutritious. This must have been the food source for the guardpost.","");
	set_flag(9,1,1);
break;

beginstate 11;
	block_entry(1);
	message_dialog("When you try to walk back into the deeps under Bahssikava, the guards stop you. _No one can pass,_ one of them says. _The Prophet's orders are to keep everyone away from the doors, including you._","");
break;

beginstate 12;
if (get_flag(9,2))
	end();
	
	message_dialog("This bridge has been rebuilt recently. It looks as though the other side was once farther away than it is now. The river must have been wider when this guardpost was inhabited.","Looking closer, you can see that the other side is noticeably dug out for several paces, evidence of ancient water flow across that land.");
	set_flag(9,2,1);
break;

beginstate 13;
reset_dialog_preset_options(8);
choice = run_dialog(1);
if (choice == 2)
	{play_sound(99);
	flip_terrain(20,14);
	flip_terrain(21,14);
	}
break;

beginstate 14;
if (get_flag(250,2) == 0)
	{message_dialog("You can't read this sign.","");
	end(); }
	
	message_dialog("You think this sign says, _Office,_ or something to that effect.","");
break;

beginstate 15;
if (get_flag(9,4))
	end();
	
	message_dialog("This is a simple, pleasant shrine. Non-Darkling sliths are religious people, and evidently even here in the guardpost the sliths needed a small shrine.","");
	set_flag(9,4,1);
break;

beginstate 16;
if (get_flag(9,5))
	end();
	
	message_dialog("Phaedra and Machrone are sitting in this room playing chess. It's Machrone's move, and he seems to be thinking it over very, very carefully.","");
	set_flag(9,5,1);
break;

beginstate 17;
if ((get_flag(9,6) == 0) || (get_flag(9,11) == 1))
	{block_entry(1);
	message_dialog("When you try to walk along the river to the south, the guard stops you. _You cannot pass,_ he says. _Prophet's orders._","");
	}
break;

beginstate 18;
if (get_flag(9,8))
	end();
	
	message_dialog("This room looks like it used to be a garrison. Now the many sliths traveling with Legare stay here. None of them look like they want to talk to you.","");
	set_flag(9,8,1);
break;

beginstate 19;
	reset_dialog();
	add_dialog_str(0,"The path here narrows and follows the river for a ways. Do you wish to continue?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Keep following the river.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		{set_flag(9,9,1);
		move_to_new_town(10,8,9); }
break;

beginstate 20;
	reset_dialog();
	add_dialog_str(0,"You can rest here. Do you wish to?",0);
	add_dialog_choice(0,"Don't rest.");
	add_dialog_choice(1,"Rest.");
	if (run_dialog(1) == 2)
		{if (get_flag(9,17) != 2)
			{play_sound(20);
			force_view_center(23,11);
			force_instant_terrain_redraw();
			revive_party();
			set_ticks_forward(5000);
			relocate_character(0,5,9);
			relocate_character(1,6,9);
			relocate_character(2,7,9);
			relocate_character(3,8,9);
			set_character_facing(0,2);
			set_character_facing(1,2);
			set_character_facing(2,2);
			set_character_facing(3,2);
			force_view_center(5,9);
			force_instant_terrain_redraw();
			}
		else
			{reset_dialog();
			add_dialog_str(0,"You go to your room and sleep for what seems like an eternity. Your bodies recover their strength.",0);
			add_dialog_str(1,"Finally, Legare comes to you, and Phaedra is right behind him. _Hey,_ she says, smiling. _I'm better now. Let's go scout._",0);
			add_dialog_str(2,"_So,_ Legare says, _the path to the south does not lead to the homeland. We have had no luck clearing the path to the east. West is a wall. That leaves only the north. Phaedra says that it may be cleared. Your job is to scout._",0);
			add_dialog_str(3,"He nods to your friend. _Phaedra will fill in the details. Good luck._ He leaves, and Phaedra rejoins you.",0);
			dummy = run_dialog(1);
			
			activate_hidden_group(3);
			erase_char(28);
			
			revive_party();
			set_ticks_forward(5000);
			dummy = add_char_to_party(27);
			
			change_custom_abil_uses(0,1,1);
			change_custom_abil_uses(1,1,1);
			change_custom_abil_uses(2,1,1);
			change_custom_abil_uses(3,1,1);
			
			set_flag(250,4,2);
			set_flag(9,18,3);
			set_flag(9,11,1);
			toggle_quest(4,0); // unfinished
			toggle_quest(3,1); // begun
			}
		}
break;

beginstate 21;
	reset_dialog();
	add_dialog_str(0,"You have reached the boat to take you north up the river to scout for Legare. Do you wish to board it and travel north?",0); 
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Board and head north.");
	if (run_dialog(1) == 2)
		{play_sound(85);
		move_to_new_town(18,23,43);
		}
break;

beginstate 22;
	if (get_flag(9,15))
		{if (town_status(9) == 2)
			message_dialog("Unfortunately, because of your crimes, no one here at the guardpost will help you. You may be in serious trouble.","");
		else
			message_dialog("You seek out help for Phaedra. You find Legare.","");
		}
	else
		message_dialog("As soon as you arrive at the guardpost, you seek help for Phaedra. You find Legare.","");
	
	erase_char(15);
	activate_hidden_group(3);
	set_character_pose(27,14);
	
	relocate_character(0,4,19);
	relocate_character(1,4,18);
	relocate_character(2,4,17);
	relocate_character(3,4,16);
	set_character_facing(0,4);
	set_character_facing(1,4);
	set_character_facing(2,4);
	set_character_facing(3,4);
	
	force_view_center(4,19);
	force_instant_terrain_redraw();
	
	message_dialog("Legare takes you to the humble shrine on the west part of town. There he prays softly over Phaedra's unconscious body.","");

	take_item(451);

	text_bubble_on_char(28,"O goddess,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"please heal this fallen warrior.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	set_character_facing(28,0);
	text_bubble_on_char(28,"");
	
	if (get_flag(250,4) < 2)
		{text_bubble_on_char(28,"Her wounds are serious, but not fatal.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(28,"");
		text_bubble_on_char(28,"She will recover,");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		if (get_flag(250,4) == 1)
			{text_bubble_on_char(28,"");
			text_bubble_on_char(28,"and I will give you a choice:");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,8));
			
			text_bubble_on_char(28,"");
			text_bubble_on_char(28,"you may continue exploring Bahssikava");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,8));
			
			text_bubble_on_char(28,"");
			text_bubble_on_char(28,"while Phaedra recovers,");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,8));
			
			text_bubble_on_char(28,"");
			text_bubble_on_char(28,"which may be extremely challenging,");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,8));
			
			text_bubble_on_char(28,"");
			text_bubble_on_char(28,"or you may wait until she recovers");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,8));
			
			text_bubble_on_char(28,"");
			text_bubble_on_char(28,"and scout to the north with her.");
			force_instant_terrain_redraw();
			pause(5 * get_flag(250,8));
			
			text_bubble_on_char(28,"");
			force_instant_terrain_redraw();
			
			reset_dialog();
			add_dialog_str(0,"What do you say?",0);
			add_dialog_choice(0,"I want to keep exploring Bahssikava.");
			add_dialog_choice(1,"I want to scout north with her.");
			if (run_dialog(1) == 1)
				{text_bubble_on_char(28,"Fine.");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,8));
				
				text_bubble_on_char(28,"");
				text_bubble_on_char(28,"If you change your mind,");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,8));
				
				text_bubble_on_char(28,"");
				text_bubble_on_char(28,"talk to Kass.");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,8));
				
				text_bubble_on_char(28,"");
				force_instant_terrain_redraw();
				
				message_dialog("He carries Phaedra away, presumably to continue to tend for her elsewhere.","");
				
				set_flag(9,17,1);
				}
				
			else
				{text_bubble_on_char(28,"Fine.");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,8));
				
				text_bubble_on_char(28,"");
				text_bubble_on_char(28,"Go to your quarters and rest.");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,8));
				
				text_bubble_on_char(28,"");
				text_bubble_on_char(28,"I will get you when she is ready.");
				force_instant_terrain_redraw();
				pause(5 * get_flag(250,8));
				
				text_bubble_on_char(28,"");
				force_instant_terrain_redraw();
				
				force_view_center(28,43);
				force_instant_terrain_redraw();
				
				reset_dialog();
				add_dialog_str(0,"You go to your room and sleep for what seems like an eternity. Your bodies recover their strength.",0);
				add_dialog_str(1,"Finally, Legare comes to you, and Phaedra is right behind him. _Hey,_ she says, smiling. _I'm better now. Let's go scout._",0);
				add_dialog_str(2,"_So,_ Legare says, _the path to the south does not lead to the homeland. We have had no luck clearing the path to the east. West is a wall. That leaves only the north. Phaedra says that it may be cleared. Your job is to scout._",0);
				add_dialog_str(3,"He nods to your friend. _Phaedra will fill in the details. Good luck._ He leaves, and Phaedra rejoins you.",0);
				dummy = run_dialog(1);
				
				revive_party();
				set_ticks_forward(5000);
				dummy = add_char_to_party(27);
				set_character_pose(4,0);
				
				change_custom_abil_uses(0,1,1);
				change_custom_abil_uses(1,1,1);
				change_custom_abil_uses(2,1,1);
				change_custom_abil_uses(3,1,1);
				
				set_flag(9,11,1);
				toggle_quest(4,0); // unfinished
				toggle_quest(3,1); // begun
				
				relocate_character(0,5,9);
				relocate_character(1,6,9);
				relocate_character(2,7,9);
				relocate_character(3,8,9);
				set_character_facing(0,2);
				set_character_facing(1,2);
				set_character_facing(2,2);
				set_character_facing(3,2);
				
				i = 0;
				while (char_ok(i) == 0)
					{i = i + 1; }
				force_view_center(char_loc_x(i),char_loc_y(i));
				}
				
			if (char_ok(27))
				erase_char(27);
			erase_char(28);
			
			set_flag(250,4,2);
			force_instant_terrain_redraw();
			
			end();
			}
			
		text_bubble_on_char(28,"");
		text_bubble_on_char(28,"but not soon enough");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(28,"");
		text_bubble_on_char(28,"to continue with you on your mission.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(28,"");
		text_bubble_on_char(28,"You will have to go on without her.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(28,"");
		text_bubble_on_char(28,"I wish I could give you more aid,");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(28,"");
		text_bubble_on_char(28,"but I have nothing else.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(28,"");
		text_bubble_on_char(28,"Good luck, and continue scouting.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(28,"");
		force_instant_terrain_redraw();
		
		message_dialog("Legare bids you to leave. You do, and as you are walking away, you can't help but realize that this mission just got a lot harder.","");
		
		set_terrain(4,19,12);
		
		force_view_center(9,16);
		
		relocate_character(0,9,16);
		relocate_character(1,8,16);
		relocate_character(2,7,16);
		relocate_character(3,6,16);
		set_character_facing(0,6);
		set_character_facing(1,6);
		set_character_facing(2,6);
		set_character_facing(3,6);
		
		erase_char(27);
		erase_char(28);
			
		force_instant_terrain_redraw();
		set_flag(250,5,2);
		}
		
	text_bubble_on_char(28,"She is terribly injured,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"almost beyond my ability to heal.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"This aggravates the injury");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"that she had received");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"the first time you brought her back.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"I will tend to her");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"and hope for the best.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"You must continue on your mission");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"without her.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	text_bubble_on_char(28,"Good luck.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(28,"");
	force_instant_terrain_redraw();
		
	message_dialog("Legare bids you to leave. You do, and as you are walking away, you can't help but realize that this mission just got a lot harder.","");
		
	set_terrain(4,19,12);
		
	force_view_center(9,16);
		
	relocate_character(0,9,16);
	relocate_character(1,8,16);
	relocate_character(2,7,16);
	relocate_character(3,6,16);
	set_character_facing(0,6);
	set_character_facing(1,6);
	set_character_facing(2,6);
	set_character_facing(3,6);
		
	erase_char(27);
	erase_char(28);
			
	force_instant_terrain_redraw();
	set_flag(250,5,2);
	
break;

beginstate 23; // Legare's door
	block_entry(1);
	reset_dialog();
	// If the party has some legitimate business with Legare, let them talk to
	// him. Otherwise, he's praying.
	if (((get_flag(250,2) >= 2) && (get_flag(9,16) == 1)) || ((get_flag(9,13) >= 2) && (get_flag(9,14) == 0)))
		add_dialog_str(0,"You have reached Legare's door. What do you do?",0);
	else
		add_dialog_str(0,"You have reached Legare's door. It sounds like he's praying, though. You probably shouldn't bother him.",0);
	add_dialog_choice(0,"Leave.");
	if ((get_flag(250,2) >= 2) && (get_flag(9,16) == 1))
		add_dialog_choice(1,"Knock on his door and offer to translate for him.");
	else
		if ((get_flag(9,13) >= 2) && (get_flag(9,14) == 0))
			add_dialog_choice(1,"Knock on his door and ask him whether he's ever been through Ancient Bahssikava.");
	choice = run_dialog(1);
	if ((choice == 2) && ((get_flag(250,2) >= 2) && (get_flag(9,16) == 1)))
		{reset_dialog();
		clear_buffer();
		append_string("You knock on the door and Legare opens it. You say, _");
		if (party_size() > 1)
			append_string("We");
		else
			append_string("I");
		append_string(" heard that you were trying to translate an old text you found here. ");
		if (party_size() > 1)
			append_string("We");
		else
			append_string("I");
		append_string(" thought that ");
		if (party_size() > 1)
			append_string("we");
		else
			append_string("I");
		append_string(" might be able to help you._");
		get_buffer_text(dlgstr);
		add_dialog_str(0,dlgstr,0);
		add_dialog_str(1,"_You're welcome to try,_ he replies, ushering you in and handing you a book. _This was the one that I was working on most recently. The language is similar to that of the vahnatai, but not enough that I can understand it._",0);
		add_dialog_str(2,"You skim through it, looking for words that you know and finding not enough, but you keep reading, trying to get a feel for what it says.",0);
		add_dialog_str(3,"Suddenly you realize that it is a history book, and the reason that you can't understand much of it is that it contains many, many names!",0);
		add_dialog_str(4,"You pour over it with renewed interest. It seems to be a biography of Thsss, the original leader of the Darklings!",0);
		add_dialog_str(5,"You explain this to Legare, who is clearly fascinated. _I do not have time for you to teach me this language now,_ he says, _but I would be very interested to learn it someday._",0);
		set_flag(9,16,1 + run_dialog(1));
		
		message_dialog("_Still,_ he says, _I will hold on to this book. It will be important to know the information contained inside. To the sliths of the homeland, we are Thsss's children, and we should know what that means to them._","With that, he ushers you out of his room, thanking you again and shutting the door.");
		end();
		}
	if (choice == 2)
		{clear_buffer();
		append_string("You explain, _");
		if (party_size() > 1)
			append_string("We");
		else
			append_string("I");
		append_string(" talked to a ghost who saw you. Or someone who sounded like you. ");
		if (party_size() > 1)
			append_string("We");
		else
			append_string("I");
		append_string(" think._ You gulp nervously.");
		get_buffer_text(dlgstr);
		message_dialog("You knock on the door and Legare, a tall, imposing slith, opens it. You stammer out, _Did you... have you ever... did you go through Ancient Bahssikava a few months ago?_ He looks at you very strangely.",dlgstr);
		
		reset_dialog();
		add_dialog_str(0,"The Prophet straightens his back, bringing himself up to his full height. To your eyes he appears to grow taller, larger, stronger, and his expression more powerful.",0);
		add_dialog_str(1,"His eyes, blazing with the true passion of religious fervor, focus directly on you. His reptilian eyes, silver and alien, stare through you, as if he is trying to drill a hole in your face just by looking at you.",0);
		add_dialog_str(2,"_In darkness great, I wandered lost among the many tunnels under my known Bahssikava. Blind, I stumbled through cavernous reaches of which man and slith know not. I heard only the Goddess's infrequent voice amidst the screams of centuries of lost souls._",0);
		add_dialog_str(3,"_My steps may have traced out a path through the ancient caves of a lost Bahssikava, a Bahssikava of which I know little but that which I learned from the legends of my ancestors._",0);
		add_dialog_str(4,"_If I did indeed tread upon the hallowed ground of the centuries' womb of civilized slithdom, the Goddess who guided all of my thoughts did not see fit to grant to me the knowledge of the caves through which I journeyed._",0);
		add_dialog_str(5,"_Her whispered tones were, in this, silent. Thus, as you may discern, that I was indeed the sojourner whose presence was known to the ghost to whom you spoke is possible, but I have not the awareness of it._",0);
		set_flag(9,14,run_dialog(1));
		
		message_dialog("With that, he closes the door.","");
		}
break;