// Town 6: Ancient Bahssikava
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
turn_off_training(1);
set_name(10,"Khassper");
set_name(32,"Khassper");
set_crime_tolerance(2);

add_char_to_group(6,1);
add_char_to_group(7,1);
add_char_to_group(8,1);
add_char_to_group(9,1);
add_char_to_group(11,1);
add_char_to_group(12,1);
add_char_to_group(13,1);
add_char_to_group(14,1);
add_char_to_group(15,1);
add_char_to_group(16,1);

add_char_to_group(17,2);
add_char_to_group(23,2);
add_char_to_group(24,2);
add_char_to_group(25,2);
add_char_to_group(26,2);
add_char_to_group(27,2);
add_char_to_group(28,2);

change_blocked(41,14,1);
change_blocked(42,14,1);
change_blocked(41,15,1);
change_blocked(42,15,1);

if (get_flag(6,17) == 0)
	{change_blocked(20,24,1);
	change_blocked(20,25,1);
	change_blocked(21,25,1);
	change_blocked(25,25,1);
	change_blocked(26,25,1);
	change_blocked(26,24,1);
	
	change_blocked(26,26,1);
	change_blocked(25,26,1);
	change_blocked(24,25,1);
	change_blocked(23,25,1);
	change_blocked(22,25,1);
	change_blocked(21,26,1);
	change_blocked(20,26,1);
	}
	
if (get_flag(15,22) == 2)
	{change_blocked(36,11,1);
	change_blocked(36,12,1);
	change_blocked(36,13,1);
	change_blocked(35,11,1);
	change_blocked(35,12,1);
	change_blocked(35,13,1);
	}

if (get_flag(6,20) >= 3)
	{set_terrain(22,26,231);
	set_terrain(23,26,276);
	set_terrain(24,26,231);
	}

if (get_flag(15,23) != 1)
	force_instant_terrain_redraw();

if (get_flag(6,0) == 0)
	{message_dialog("Far from the intense heat of the upper levels, this area is very, very cold. The air is extremely still, but it is tense. Some dark magic is at work here.","You also notice that the tracks of Empire soldiers continue into this area. They made it this far.");
	set_flag(6,0,1); }
	
if (get_flag(15,23) != 1)
	end();
	
	set_flag(15,23,2);
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	
	relocate_character(0,0,45);
	relocate_character(1,0,44);
	relocate_character(2,0,43);
	relocate_character(3,0,42);
	relocate_character(4,0,41);
	force_view_center(5,45);
	march_party(1,45);
	force_instant_terrain_redraw();
	
	message_dialog("You squeeze through a small hole in this wall that you would never have noticed from the other side.","");

	while (char_on_loc(1,45) >= 0)
		{march_party(char_loc_x(i) + 1,char_loc_y(i));
		force_view_center(char_loc_x(i),char_loc_y(i));
		force_instant_terrain_redraw();
		pause(2 * get_flag(250,8));
		}
	
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	if (get_ran(1,0,100) < 7)
		text_bubble_on_char(10,"Sss.");
	if (get_ran(1,0,100) < 7)
		text_bubble_on_char(10,"Hss.");
		
	if (get_flag(6,10) == 1)
		if (get_flag(6,25) == 0) {
			set_flag(6,25,1);
			message_dialog("In the moments after the ghost screamed, you begin to feel powerful magic at work in the southwest. Some kind of dark enchantment has been activated, and you may have to hurry to deal with it.","Judging by the increasingly many screams of ghosts, you'd guess that unless you get to the source soon, the number of ghosts will grow out of control very soon.");
			}
		
if (get_flag(6,13) != 1)
	end();
	
	message_dialog("The ghost begins speaking again.","");

	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"Seventeen years ago,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"soldiers came from the higher caves.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"They called themselves 'dervishes.'");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(0,"The Empire!");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(0,"");
	text_bubble_on_char(2,"We've seen their bodies everywhere.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(2,"");
	text_bubble_on_char(2,"We were wondering why.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(2,"");
	text_bubble_on_char(10,"I do not know this 'Empire.'");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"Whoever they are,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"they have already paid in full.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(0,"But what did they do?");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(0,"");
	text_bubble_on_char(10,"Terrible, terrible things.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	message_dialog("_When they arrived in Bahssikava, they were already covered in slith blood. I know not from where, but the scent of death was on them._","_They began to disturb this town, the resting place of the souls of many sliths._");

	place_monster(39,12,175,2);
	set_character_facing(86,2);
	place_monster(37,12,175,2);
	set_character_facing(87,6);
	place_monster(40,13,175,2);
	set_character_facing(88,0);
	place_monster(40,10,175,2);
	set_character_facing(89,4);
	place_monster(36,13,175,2);
	set_character_facing(90,6);
	place_monster(34,11,175,2);
	set_character_facing(91,6);
	place_monster(42,16,175,2);
	set_character_facing(92,0);
	place_monster(39,8,16,2);
	set_character_facing(93,4);

	force_view_center(39,12);
	set_total_visibility(1);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	text_bubble_on_char(86,"You have your orders!");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"If it's not human,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"kill it!");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(86,"");
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	i = 86;
	while (i <= 93)
		{set_character_pose(i,2);
		i = i + 1; }
	play_sound(18);
	force_instant_terrain_redraw();

	relocate_character(93,31,5);
	set_character_facing(93,6);
	relocate_character(92,31,7);
	set_character_facing(92,6);
	relocate_character(91,32,7);
	set_character_facing(91,6);
	relocate_character(90,33,7);
	set_character_facing(90,6);

	set_terrain(32,5,0);
	set_terrain(32,4,0);
	set_terrain(34,4,0);
	set_terrain(36,4,0);
	set_terrain(31,3,0);
	set_terrain(33,3,41);
	set_terrain(34,3,0);
	set_terrain(36,3,0);
	set_terrain(32,2,0);
	set_terrain(33,2,41);
	set_terrain(34,2,241);
	set_terrain(31,1,0);
	set_terrain(33,1,41);
	set_terrain(34,1,0);

	message_dialog("_They broke into homes..._","");

	force_view_center(32,3);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	set_character_pose(93,1);
	put_jagged_zap(31,5,33,2,0);
	put_boom_on_space(33,3,1,0);
	put_boom_on_space(33,2,1,0);
	put_boom_on_space(33,1,1,0);
	run_animation_sound(51);

	set_character_pose(93,2);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	set_character_pose(93,1);
	put_jagged_zap(31,5,33,2,0);
	put_boom_on_space(33,3,1,0);
	put_boom_on_space(33,2,1,0);
	put_boom_on_space(33,1,1,0);
	run_animation_sound(51);

	set_character_pose(93,2);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	set_terrain(32,5,138);
	set_terrain(32,4,137);
	set_terrain(34,4,137);
	set_terrain(36,4,241);
	set_terrain(31,3,138);
	set_terrain(33,3,138);
	set_terrain(34,3,138);
	set_terrain(36,3,137);
	set_terrain(32,2,137);
	set_terrain(33,2,137);
	set_terrain(34,2,0);
	set_terrain(31,1,138);
	set_terrain(33,1,137);
	set_terrain(34,1,138);

	set_character_pose(93,1);
	put_jagged_zap(31,5,33,2,0);
	put_boom_on_space(33,3,1,0);
	put_boom_on_space(33,2,1,0);
	put_boom_on_space(33,1,1,0);
	run_animation_sound(51);

	set_height(28,27,5);
	set_height(29,27,5);
	set_height(30,27,5);
	set_height(28,28,5);
	set_height(29,28,5);
	set_height(30,28,5);
	set_height(28,29,5);
	set_height(29,29,5);
	set_height(30,29,5);
	set_height(28,30,5);
	set_height(29,30,5);
	set_height(30,30,5);

	set_terrain(28,27,0);
	set_terrain(29,27,0);
	set_terrain(30,27,0);
	set_terrain(28,28,0);
	set_terrain(29,28,0);
	set_terrain(30,28,0);
	set_terrain(28,29,0);
	set_terrain(29,29,0);
	set_terrain(30,29,0);
	set_terrain(28,30,0);
	set_terrain(29,30,0);
	set_terrain(30,30,0);

	relocate_character(86,33,33);
	set_character_facing(86,4);
	relocate_character(87,31,28);
	set_character_facing(87,2);
	relocate_character(88,31,29);
	set_character_facing(88,2);
	relocate_character(89,31,30);
	set_character_facing(89,2);

	message_dialog("_... disturbed graves..._","");

	force_view_center(33,31);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	text_bubble_on_char(87,"*dig*");
	force_instant_terrain_redraw();
	play_sound(-120);
	pause(2 * get_flag(250,8));

	text_bubble_on_char(87,"");
	text_bubble_on_char(88,"*dig*");
	force_instant_terrain_redraw();
	play_sound(-120);
	pause(2 * get_flag(250,8));

	text_bubble_on_char(88,"");
	text_bubble_on_char(89,"*dig*");
	force_instant_terrain_redraw();
	play_sound(-120);
	pause(2 * get_flag(250,8));

	text_bubble_on_char(89,"");
	text_bubble_on_char(87,"*dig*");
	force_instant_terrain_redraw();
	play_sound(-120);
	pause(2 * get_flag(250,8));

	text_bubble_on_char(87,"");
	text_bubble_on_char(88,"*dig*");
	force_instant_terrain_redraw();
	play_sound(-120);
	pause(2 * get_flag(250,8));

	text_bubble_on_char(88,"");
	text_bubble_on_char(89,"*dig*");
	force_instant_terrain_redraw();
	play_sound(-120);
	pause(2 * get_flag(250,8));

	text_bubble_on_char(89,"");
	force_instant_terrain_redraw();

	set_height(28,27,4);
	set_height(29,27,4);
	set_height(30,27,4);
	set_height(28,28,4);
	set_height(29,28,4);
	set_height(30,28,4);
	set_height(28,29,4);
	set_height(29,29,4);
	set_height(30,29,4);
	set_height(28,30,4);
	set_height(29,30,4);
	set_height(30,30,4);

	set_terrain(28,27,114);
	set_terrain(29,27,112);
	set_terrain(30,27,117);
	set_terrain(28,28,106);
	set_terrain(29,28,262);
	set_terrain(30,28,110);
	set_terrain(28,29,106);
	set_terrain(29,29,262);
	set_terrain(30,29,110);
	set_terrain(28,30,115);
	set_terrain(29,30,108);
	set_terrain(30,30,116);

	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));

	text_bubble_on_char(86,"What are you waiting for?");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"Open it!");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(86,"");
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	relocate_character(87,30,29);
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));

	play_sound(45);
	pause(2 * get_flag(250,8));

	set_character_facing(87,0);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	relocate_character(87,30,28);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	set_character_facing(87,2);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	play_sound(45);
	pause(2 * get_flag(250,8));

	set_character_facing(87,4);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	text_bubble_on_char(87,"There's some coins in here.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(87,"");
	text_bubble_on_char(87,"Weird looking ones.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(87,"");
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	set_terrain(4,28,276);

	relocate_character(86,4,27);
	set_character_facing(86,4);
	relocate_character(87,2,25);
	set_character_facing(87,4);
	relocate_character(88,5,24);
	set_character_facing(88,4);
	relocate_character(89,6,27);
	set_character_facing(89,4);
	relocate_character(93,1,27);
	set_character_facing(93,4);
	set_character_pose(87,0);
	set_character_pose(88,0);
	set_character_pose(89,0);
	set_character_pose(93,0);

	message_dialog("_... and defaced holy altars._","");

	force_view_center(2,23); // change
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	text_bubble_on_char(93,"Sir, I'm not sure that's such a...");
	force_instant_terrain_redraw();
	pause(7 * get_flag(250,8));

	text_bubble_on_char(93,"");
	set_character_pose(86,1);
	put_effect_on_space(4,28,9,1,2);
	run_animation_sound(69);
	pause(2 * get_flag(250,8));

	set_character_pose(86,2);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	set_character_pose(86,1);
	put_effect_on_space(4,28,9,1,2);
	run_animation_sound(69);
	pause(2 * get_flag(250,8));

	set_character_pose(86,2);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	set_terrain(4,28,277);
	put_boom_on_space(4,28,3,0);
	run_animation_sound(25);
	pause(1 * get_flag(250,8));

	text_bubble_on_char(93,"... good idea.");
	force_instant_terrain_redraw();
	pause(7 * get_flag(250,8));

	text_bubble_on_char(93,"");
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	place_monster(3,27,118,2);
	place_monster(5,27,118,2);
	place_monster(3,25,118,2);
	set_character_facing(96,2);
	force_instant_terrain_redraw();
	play_sound(97);
	pause(6 * get_flag(250,8));

	relocate_character(10,7,31);
	set_character_facing(10,4);
	relocate_character(0,6,32);
	set_character_facing(0,0);
	relocate_character(1,6,33);
	set_character_facing(1,0);
	relocate_character(2,6,34);
	set_character_facing(2,0);
	relocate_character(3,6,35);
	set_character_facing(3,0);

	set_total_visibility(0);
	force_view_center(6,32);

	text_bubble_on_char(10,"They awoke the vengeance");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"of the spirits of Bahssikava.");
	force_instant_terrain_redraw();
	pause(7 * get_flag(250,8));

	text_bubble_on_char(10,"");
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));

	text_bubble_on_char(10,"They were destroyed.");
	force_instant_terrain_redraw();
	pause(7 * get_flag(250,8));

	text_bubble_on_char(10,"");
	force_instant_terrain_redraw();
	pause(1 * get_flag(250,8));

	text_bubble_on_char(10,"And that is why");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"you can still see their bodies");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"in the corners of these caves.");
	force_instant_terrain_redraw();
	pause(7 * get_flag(250,8));

	text_bubble_on_char(10,"");
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	if (get_flag(6,17) == 0)
		message_dialog("_The ghosts are here because the soldiers activated a curse. They are here to inflict vengeance on all living things who intrude._","He gives you a long look. _Including you._");
	else
		message_dialog("_The ghosts were here because the soldiers activated a curse. They are here to inflict vengeance on all living things who intrude._","He adds, _Fortunately, though, you've ended the curse._");

	i = 86;
	while (i <= 100)
		{erase_char(i);
		i = i + 1; }

	set_flag(6,13,2);
	
break;

beginstate 10;
if (get_flag(6,1) == 0)
	{message_dialog("This was clearly someone's house. Judging by the painting on the wall, it was a slith's house. It has been empty for quite some time, but everything is still in good repair.","It almost looks as if the residents just stepped out for the moment. You can't see any signs of them having taken anything with them.");
	set_flag(6,1,1); }
break;

beginstate 11;
	message_dialog("The books here are all ancient beyond your reckoning. They are in a strange script that you don't recognize.","Some are illustrated, and you can pick up enough from the pictures to know that they tell stories of great heroes, terrible villains, and incredible deeds by beings of awesome power.");
break;

beginstate 12;
if (get_flag(6,2) == 0)
	{message_dialog("There is a small lake here. It has pale cave fish swimming in it. This must have been the family's source of food. It appears that they shared it with a neighboring family.","In the intervening years since the families left, the fish have reverted to a more wild state. You can see them fighting with each other and swimming back to hide in their home crevices.");
	set_flag(6,2,1); }
break;

beginstate 13;
	message_dialog("This box contains the bones of some fish. Presumably they were caught and then left here when the families abandoned their homes.","");
break;

beginstate 14;
if (get_flag(6,3) == 0)
	{message_dialog("Now, this is peculiar. This room is in considerable disarray. A chair was clearly tossed from one side to the other.","An Empire soldier lays dead at your feet, and through the open door blows icy, chilling air. Whatever caused this destruction must be beyond that door.");
	set_flag(6,3,1); }
break;

beginstate 15;
	set_char_script_mode(6,3);
	set_char_script_mode(11,3);
	set_char_script_mode(12,3);
	set_char_script_mode(15,3);
	set_char_script_mode(16,3);
break;

beginstate 16;
	reset_dialog();
	if (get_flag(250,2) == 0)
		add_dialog_str(0,"This book is written in a script you can't read. The pictures make the story quite clear, though. The story is about a giant red slith who slew many monsters and demons.",0);
	if ((get_flag(250,2) == 1) || (get_flag(250,2) == 2))
		add_dialog_str(0,"This book is written in the ancient Bahssikavan script you partly learned. You can't really understand it, but the pictures make the story quite clear, though. The story is about a giant red slith who slew many monsters and demons.",0);
	if (get_flag(250,2) < 3)
		add_dialog_str(1,"It seems to focus on one particular event. The slith hero journeyed a very long way to a cave in the high mountains, where he battled a fierce crimson dragon and spoke with a shimmery godlike being.",0);
	else
		{add_dialog_str(0,"This book is written in the ancient Bahssikavan script in which you have become completely fluent! You read over a few of the pages, following along with the beautiful illustrations.",0);
		clear_buffer();
		append_string("The story is about a giant red slith named Khalthas, ");
		if (has_item(457))
			append_string("whose spear you carry, and ");
		append_string("whose greatest accomplishment was slaying a mighty crimson dragon named Mahanyakshetra.");
		get_buffer_text(dlgstr);
		add_dialog_str(1,dlgstr,0);
		add_dialog_str(2,"Just after he slew the dragon, a shimmering goddess appeared to him and discoursed at great length on religious issues, such as the immortality of the soul, the importance of duty and honor, and the reward for true goodness.",0);
		add_dialog_str(3,"Midway through reading this, you realize that you are reading a rendition intended for a child. It contains partial quotes of poetry in a strange, beautiful meter, with explanations following.",0);
		add_dialog_str(4,"You can only be reading a simplification of a vast epic poem written by sliths. Only fragments are here, but you can tell that it was a great work. Written by sliths!",0);
		add_dialog_str(5,"Eventually, after paging through it a bit more but finding nothing to enlighten you further, you move on.",0);
		}
	dummy = run_dialog(1);
break;

beginstate 17;
	reset_dialog();
	add_dialog_str(0,"There is a sign above this pool that you can't read, but it also has a picture of a slith washing its hands.",0);
	add_dialog_str(1,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Wash your hands.");
	choice = run_dialog(1);
	if (choice == 2)
		{message_dialog("You wash your hands in the water. It is pleasant and soothing, especially after your battle with the undead, but you don't detect any other effects.","");
		set_flag(6,4,1); }
break;

beginstate 18;
if (get_flag(6,5) == 0)
	{message_dialog("As you step through these doors, a warm feeling washes over you. This temple is not infected with the undead curse that haunts the rest of this area.","For the first time since you arrived among these ancient buildings, you can't see the blood of Empire soldiers. Apparently they never came in here.");
	set_flag(6,5,1); }
break;

beginstate 19;
if (get_flag(6,8) == 0)
	{message_dialog("What you see as you round this corner is astonishing. The remains of many, many Empire soldiers lie here in various states of disrepair. All of them appear to be running back the way you came.","By the markings on their uniforms, several of these soldiers were dervishes in life. Whatever killed them must be extraordinarily strong.");
	set_flag(6,8,1); }
break;

beginstate 20;
if (get_flag(6,7) == 0)
	{message_dialog("What a mess! It looks as though there was a cave-in here at some point, and part of this tunnel is now blocked off.","");
	set_flag(6,7,1); }
break;

beginstate 21;
	message_dialog("This Empire soldier cowered in this corner before he was shredded to death by the slith ghosts.","His armor, like all of the others', is damaged beyond repair. You leave the body alone.");
break;

beginstate 22;
if ((get_flag(6,11) == 0) && (get_flag(6,6) == 1))
	{reset_dialog();
	add_dialog_str(0,"You open the box and find and energy elixir. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Take it.");
	choice = run_dialog(1);
	if (choice == 2)
		set_flag(6,11,reward_give(231));
	}
else
	message_dialog("You try to lift the lid of this box, but you can't. It won't budge.","");
break;

beginstate 23;
if (has_special_item(2) == 0)
	{change_spec_item(2,1);
	message_dialog("You find a small, black key. You pocket it.",""); }
break;

beginstate 24;
	message_dialog("If there ever was anything in this box, it has long since been taken away.","");
break;

beginstate 25;
	message_dialog("There is an open book here. You can't read a word of the strange, ancient script.","");
break;

beginstate 26;
if ((is_combat() == 1) || (get_flag(6,12) == 1))
	end();
	else
	{reset_dialog();
	add_dialog_str(0,"You step into a room in the library. It contains many, many books, some rotten, some probably still readable, if only you could understand the script in which they are written.",0);
	if (get_flag(1,19) == 1)
		add_dialog_str(1,"Phaedra was right. The sliths who came through Lost Bahssikava were extremely advanced. The very fact that they would have this library confirms that.",0);
	else
		add_dialog_str(1,"These sliths were far more advanced than the ones with whom you are familiar in Avernum today. This library's existence is a sure sign of that.",0);
	add_dialog_str(2,"There's no point in searching the all of the shelves. Your chances of finding something that you could use in here are negligible.",0);
	dummy = run_dialog(1);
	set_flag(6,12,1);
	}
break;

beginstate 27;
	message_dialog("These coffins have both been looted.","");
break;

beginstate 28;
if (is_combat() == 1) {
	message_dialog("You can't go this way in combat.","");
	block_entry(1);
	end();
	}
	
if (get_flag(6,24) != 1)
	move_to_new_town(3,15,45);
else
	{message_dialog("You make your way through the deeps under the newer Bahssikava all the way back to the guardpost. This causes something of a stir when you get back there, because everyone has passed the threshold of the steel doors by now and no one has been let back.","");
	set_flag(9,13,1);
	move_to_new_town(9,21,10);
	}
break;

beginstate 29;
if (get_flag(6,23) == 0)
	{activate_hidden_group(1);
	set_flag(6,23,1); }
break;

beginstate 30;
if (get_flag(6,26) != 0)
	end();
	
	clear_buffer();
	append_string("You open the box and find a small metal triangle inside");
	if (get_flag(6,15) == 1)
		append_string(", exactly as the friendly ghost in the shrine told you that you would");
	if (has_special_item(1) == 1)
		append_string(". It matches precisely the other triangle you have");
	if (has_special_item(1) > 1)
		append_string(". It matches precisely the other triangles you have");
	append_string(".");
	get_buffer_text(box);
	add_dialog_str(0,box,0);
	add_dialog_str(1,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Take it.");
	choice = run_dialog(1);
	if (choice == 2)
		{set_flag(6,26,1);
		message_dialog("You pocket the metal triangle.","");
		change_spec_item(1,1);
		if (has_special_item(1) > 1)
			print_big_str("You now have ",has_special_item(1)," metal triangles.");
		else
			print_str("You now have 1 metal triangle."); }
break;

beginstate 31;
if (get_flag(6,16) == 0)
	{message_dialog("These three Empire soldiers were trying to flee the library in a different direction than the main group. They reached this door, which has a sturdy-looking lock on it, and against this door, they were shredded.","The sight turns your stomach. You don't look at them for too long.");
	set_flag(6,16,1); }
break;

beginstate 32;
if (get_flag(6,17) == 1)
	end();
	else
	{activate_hidden_group(2);
	put_boom_on_char(29,6,0);
	put_boom_on_char(30,6,0);
	put_boom_on_char(31,6,0);
	run_animation_sound(165);
	pause(1 * get_flag(250,8));
	change_blocked(20,24,0);
	change_blocked(20,25,0);
	change_blocked(21,25,0);
	change_blocked(25,25,0);
	change_blocked(26,25,0);
	change_blocked(26,24,0);
	change_blocked(26,26,0);
	change_blocked(25,26,0);
	change_blocked(24,25,0);
	change_blocked(23,25,0);
	change_blocked(22,25,0);
	change_blocked(21,26,0);
	change_blocked(20,26,0);
	message_dialog("Huge blasts of energy explode all around the room! Three sliths that glow with a strange, celestial light appear and attack you.","");
	set_flag(6,17,1);
	}
break;

beginstate 33;
if (get_flag(6,18) == 0)
	{message_dialog("You enter what appears to be an ancient slith temple. The air is sharp and bitter, not like the usually moist and humid caves of Avernum.","Your skin tingles. There is magic here, although you can't detect what it is.");
	set_flag(6,18,1); }
break;

beginstate 34;
if ((is_combat()) || (get_flag(6,19) == 1))
	end();
	else
	{message_dialog("Now that you have time to look around carefully, you notice that the southwest wall looks rather thin and insubstantial, as if you could just walk right through it.","");
	set_flag(6,19,1); }
break;

beginstate 35;
	reset_dialog_preset_options(9);
	choice = run_dialog(1);
	if (choice == 2)
		move_to_new_town(7,4,62);
	else
		block_entry(1);
break;

beginstate 36;
	inc_flag(6,20,1);
	if (get_flag(6,20) < 3)
		end();
	set_terrain(22,26,231);
	set_terrain(23,26,276);
	set_terrain(24,26,231);
	put_boom_on_space(22,26,3,0);
	put_boom_on_space(23,26,3,0);
	put_boom_on_space(24,26,3,0);
	run_animation_sound(60);
	
	clear_buffer();
	if (get_flag(6,10) == 2)
		append_string("The entire area starts to feel brighter. You have lifted the curse that the Empire brought to the library and temple of Ancient Bahssikava.");
	else
		append_string("The temple feels less dark and dangerous, but the air still feels tense. The curse that the Empire caused here is still active.");
	get_buffer_text(dlgstr);
	message_dialog("The pall on this room lifts as you kill the last avatar. This altar and this room are no longer dangerous.",dlgstr);
	if (get_flag(6,10) == 2)
		award_party_xp(50,get_level(0));
break;

beginstate 37;
	set_char_script_mode(6,2);
	set_char_script_mode(11,2);
	set_char_script_mode(12,2);
	set_char_script_mode(15,2);
	set_char_script_mode(16,2);
break;

beginstate 38;
	set_char_script_mode(17,3);
	set_char_script_mode(23,3);
	set_char_script_mode(24,3);
	set_char_script_mode(25,3);
	set_char_script_mode(26,3);
	set_char_script_mode(27,3);
	set_char_script_mode(28,3);
break;

beginstate 39;
	set_char_script_mode(17,2);
	set_char_script_mode(23,2);
	set_char_script_mode(24,2);
	set_char_script_mode(25,2);
	set_char_script_mode(26,2);
	set_char_script_mode(27,2);
	set_char_script_mode(28,2);
break;

beginstate 40;
	message_dialog("All of the dark energy around this altar swirls in a terrible vortex. It is suffocating. You continue performing the ritual, though, and hoping that it will work.","And it does!");
break;

beginstate 41;
if (get_flag(15,21) == 1)
	{block_entry(1);
	message_dialog("You shouldn't go this way. It just leads back to the Catacombs, and going north is a far more direct way of getting back to the Guardpost.","");
	}
break;

beginstate 42;
if (get_flag(15,21) >= 1)
	{block_entry(1);
	message_dialog("_Don't go in there,_ a ghostly voice says in your mind. _Sss. Nothing to see anymore._","You respectfully back away.");
	}
break;

beginstate 43;
if ((get_flag(15,21) >= 1) && (get_flag(6,24) == 0))
	{block_entry(1);
	message_dialog("_Stop there,_ the ghost says. _We talk before you leave. Sss._","");
	}
break;

beginstate 44;
if (get_flag(6,10) == 1)
	{block_entry(1);
	message_dialog("Based on the sound of ghost activity to the west, it would probably be a bad idea to explore a new area without taking care of what is back there. You turn around.","");
	}
break;