// Town 15: Khar-Grav
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
turn_off_training(1);
set_level(6,80);
set_name(6,"Nolagh-Khar");
set_name(30,"Hidden Ghost");
set_name(65,"Nothass");
put_object_on_space(42,17,6);

set_level(70,40);
set_level(71,40);
set_level(72,40);
set_level(73,45);
set_name(73,"Boarag");

char_give_item(34,466); // Elemental Pants

if (get_flag(14,11) == 1)
	set_terrain(50,1,388);

if (get_flag(16,12) == 1)
	set_terrain(50,12,388);

if (get_flag(15,21) == 1)
	erase_char(6);

if (get_flag(15,28) == 1)
	erase_char(65);

if (get_flag(15,25) == 1)
	erase_char(30);

if (get_flag(15,0) == 0)
	{force_instant_terrain_redraw();
	message_dialog("You proceed deeper into the demon lair. The growls and screams are much more distant now, and you get the feeling that you're entering a very different area. Some powerful machinery is at work here, and you can hear it.","You can hear some activity to the west, but almost nothing to the north. There are few (if any) demons north of here.");
	set_flag(15,0,1);
	}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
if ((get_flag(250,4) == 1) && (has_item(451) == 0))
	{message_dialog("You can't just leave Phaedra behind. You must take her with you to the guardpost immediately or she will die.","");
	block_entry(1);
	end();
	}

	reset_dialog();
	add_dialog_str(0,"There is a small, dark passage here. Do you wish to walk down it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Walk down the passage.");
	choice = run_dialog(1);
	if (choice == 1)
		block_entry(1);
	if (choice == 2)
		move_to_new_town(14,51,5);
break;

beginstate 11;
if (get_flag(250,4) == 1) // Phaedra dead
	{add_dialog_str(0,"There is a trapdoor here. However, you can't go down through it: Phaedra needs you to bring her back to the guardpost.",0);
	dummy = run_dialog(1);
	block_entry(1);
	end();
	}

	reset_dialog();
	add_dialog_str(0,"There is a trapdoor here. Do you wish to open it and descend to a lower level?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Descend.");
	choice = run_dialog(1);
	if (choice == 1)
		block_entry(1);
	if (choice == 2)
		move_to_new_town(16,30,28);
break;

beginstate 12;
if (get_flag(15,1) != 0)
	end();
	
	message_dialog("You hear the sounds of demon guards patrolling near here. You keep your hands close to your weapons, as you may have to fight some difficult combats in this direction.","");
	set_flag(15,1,1);
break;

beginstate 13;
if (get_flag(15,2) != 0)
	end();
	
	message_dialog("The demons have left this house alone. You think you can tell why. Judging by the blast marks outside and the powerful feel of magical energy from the inside, you guess the former inhabitant of this house laid a protective spell on it before he left.","Fortunately, you do not come with hostile intent, so you are safe from the spell.");
	set_flag(15,2,1);
break;

beginstate 14;
	message_dialog("This is the dead body of a vicious-looking demon. It has been here for some years, but evidently demon corpses decay slowly.","It appears to have been thrown rather forcefully from the door to the south, possibly in an explosion.");
break;

beginstate 15;
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	if (char_loc_x(i) >= 41)
		end();
	
	reset_dialog();
	add_dialog_str(0,"Looking in this room, you can see the source of the protective magic: several glowing magic runes. You have nothing to fear here: demons cannot enter.",0);
	add_dialog_str(1,"That means you could get some uninterrupted rest, if you would like. What do you do?",0);
	add_dialog_choice(0,"Don't rest.");
	add_dialog_choice(1,"Rest.");
	if (run_dialog(1) == 2)
		{revive_party();
		set_ticks_forward(5000);
		}
break;

beginstate 16;
	if (get_flag(250,2) == 0)
		message_dialog("There is an open book here with an ancient, complex script that you can't read.","");

	if (get_flag(250,2) == 1)
		{message_dialog("This book is in the Ancient Bahssikavan script, and you can read some of it. It appears to be a journal! You read a part of the first entry on the open page.","_We are leaving. Some are remaining behind to defend the city from the demons, but many of us will go. The quake opened a tunnel in the east, and we will investigate it. Some say it leads to the homeland, but I am skeptical._");
		set_flag(15,4,1); }

	if (get_flag(250,2) == 2)
		{reset_dialog();
		add_dialog_str(0,"This book is in the Ancient Bahssikavan script, and you can read much of it. It appears to be a journal! You read the first entry on the open page.",0);
		add_dialog_str(1,"_The tremors from the quake have finally ended. Bahssikava lies in ruins. Entire sections of the city are cut off from all communication. We still have no idea what has happened to the North.",0);
		add_dialog_str(2,"_The demons that have been invading from the southern tunnels are breaking our defenses. The river is drying up, and they will cross it soon. When that happens, our city will be overrun.",0);
		add_dialog_str(3,"_We are leaving. Some are remaining behind to defend the city from the demons, but many of us will go. The quake opened a tunnel in the east, and we will investigate it. Some say it leads to the homeland, but I am skeptical.",0);
		add_dialog_str(4,"_Would the gods truly mask such kindness with such cruelty?_",0);
		add_dialog_str(5,"That is the final entry.",0);
		set_flag(15,4,run_dialog(1) + 1);
		}
break;

beginstate 17;
if (get_flag(15,5) != 0)
	end();
	
	message_dialog("This house was clearly at one time a luxury home, conveniently located and equipped with all the most expensive features. It has since been trashed by demons.","By the sound of it, they're not done here, either.");
	set_flag(15,5,1);
break;

beginstate 18;
	if (get_flag(250,2) == 0)
		message_dialog("There is an open book here with an ancient, complex script that you can't read.","");

	if (get_flag(250,2) == 1)
		{message_dialog("This book is in the Ancient Bahssikavan script, and you can read some of it. It's a diary! You read a part of the first entry on the open page.","_The ceiling is falling down. I went down to the river, and it's so small! Half of it is blocked up 'cuz of the rocks that fell down. Mommy says we can't live here anymore with the river so small, so we have to leave._");
		set_flag(15,6,1); }

	if (get_flag(250,2) == 2)
		{reset_dialog();
		add_dialog_str(0,"This book is in the Ancient Bahssikavan script, and you can read it. It's a diary, written in a child's hand! You read a part of the first entry on the open page.",0);
		add_dialog_str(1,"_Mommy says we have to leave. She says the gods are punishing us for trying to break through the door to the homeland. She says the cavequake was a sign from the gods that we need to be punished more before we can go home.",0);
		add_dialog_str(2,"_But the ceiling is falling down. I went down to the river, and it's so small! Half of it is blocked up 'cuz of the rocks that fell down. Mommy says we can't live here anymore with the river so small, so we have to leave.",0);
		add_dialog_str(3,"_She says there's a tunnel to the east that the quake opened up. We're gonna walk down it and see where it goes. We can only bring what we can carry, so I have to leave you behind, Diary._",0);
		add_dialog_str(4,"That is the final entry.",0);
		set_flag(15,6,run_dialog(1) + 1);
		}
break;

beginstate 19;
if (get_flag(15,7) != 0)
	end();
	
	message_dialog("Whatever this room was originally used for, it has since been violated in some horrific manner. There appears to have been an explosion at some point, and wreckage is all that is left.","");
	set_flag(15,7,1);
break;

beginstate 20;
if (get_flag(15,8) != 0)
	end();
	
	reset_dialog_preset_options(1);
	add_dialog_str(0,"The long-dead body of a slith lies here. A quick search reveals a shiny ring!",0);
	choice = run_dialog(1);
	if (choice == 2)
		set_flag(15,8,reward_give(279));
break;

beginstate 21;
	reset_dialog();
	add_dialog_str(0,"There is a small, simple pool of purple water here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Drink some.");
	add_dialog_choice(2,"Wash yourself.");
	choice = run_dialog(1);
	if (choice == 2)
		message_dialog("The water tastes bitter. You can't tell if anything happens.","");
	if (choice == 3)
		{message_dialog("The water is cold and soothing. You can't tell if anything happens, though.","");
		set_flag(15,9,1); }
break;

beginstate 22;
	reset_dialog();
	add_dialog_str(0,"There is a small, simple pool of blue water here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Drink some.");
	add_dialog_choice(2,"Wash yourself.");
	choice = run_dialog(1);
	if (choice == 2)
		message_dialog("The water tastes bitter. You can't tell if anything happens.","");
	if (choice == 3)
		{message_dialog("The water is cold and soothing. You can't tell if anything happens, though.","");
		if (get_flag(15,9) == 1)
			set_flag(15,9,2);
		else
			set_flag(15,9,0);
		}
break;

beginstate 23;
	reset_dialog();
	add_dialog_str(0,"There is a small, simple pool of light blue water here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Drink some.");
	add_dialog_choice(2,"Wash yourself.");
	choice = run_dialog(1);
	if (choice == 2)
		message_dialog("The water tastes bitter. You can't tell if anything happens.","");
	if (choice == 3)
		{message_dialog("The water is cold and soothing. You can't tell if anything happens, though.","");
		if (get_flag(15,9) == 2)
			set_flag(15,9,3);
		else
			set_flag(15,9,0);
		}
break;

beginstate 24;
	reset_dialog();
	add_dialog_str(0,"You find a small, simple control panel with three buttons. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Press one.");
	choice = run_dialog(1);
	if (choice == 1)
		end();
		
	reset_dialog();
	add_dialog_str(0,"Which one?",0);
	add_dialog_choice(0,"The first one.");
	add_dialog_choice(1,"The second one.");
	add_dialog_choice(2,"The third one.");
	choice = run_dialog(1);
	if (choice == 1)
		flip_terrain(42,19);
	if (choice == 2)
		flip_terrain(42,20);
	if (choice == 3)
		flip_terrain(42,21);
break;

beginstate 25;
if (get_flag(15,10) != 0)
	end();
	
	if (get_terrain(44,23) == 70)
		message_dialog("The wall right here looks cracked and damaged, almost as if you could break right through it.","");
	set_flag(15,10,1);
break;

beginstate 26;
if (get_flag(15,11) != 0)
	end();
	
	message_dialog("Before you is a huge building. It was once a Bahssikavan mansion, but now it has been seized by demons. It is clear that this is the home of Nolagh-Khar, the demon whom you are here to fight.","If he is strong enough to control all of these demons, Nolagh-Khar must be very strong indeed. Fighting him unprepared would be utter suicide. You briefly review what you've done in Bahssikava.");
	i = 0;
	reset_dialog();
	if (get_flag(14,11) == 1)
		{if (get_flag(16,12) != 0)
			{add_dialog_str(0,"You have completely disrupted the power supply in this area. Whatever Nolagh-Khar intended to do with that energy, he no longer can do.",0);
			i = i + 2;
			}
		else
			{add_dialog_str(0,"You damaged a power crystal that presumably supplied him vital energy.",0);
			i = i + 1; }
		}
	else
		if (get_flag(16,12) != 0)
			{add_dialog_str(0,"You disrupted the power supply in this area from the area below Khar-Grav.",0);
			i = i + 1;
			}
	if (get_flag(14,21) == 1)
		{add_dialog_str(2,"You freed the souls of several imprisoned slithzerikai ghosts. They promised to help you in the fight against the demon lord.",0);
		i = i + 1; }
	if (character_in_party(1410) > 0)
		{add_dialog_str(3,"You gained the aid of Ithik, a living slith from nearby, who has been by your side since you freed him.",0);
		i = i + 1; }
	else
		if (get_flag(14,29) == 1)
			{add_dialog_str(3,"You freed several living sliths from a prison cell, and they seemed enthusiastically grateful. They may help you in the future.",0);
			i = i + 1; }
	if (get_flag(214,0) == 1)
		{add_dialog_str(4,"You freed several imps that were stuck mining. They agreed to help you in the final combat against Nolagh-Khar.",0);
		i = i + 1; }
	if (get_flag(13,6)) // has freed mining ghosts
		{add_dialog_str(5,"You freed the mining slith ghosts far to the southeast, who promised to give you their aid when you attacked the demon lord.",0);
		i = i + 1; }
	if (i == 0)
		add_dialog_str(0,"You've done nothing, really. You're just charging in against the demon lord blindly. This is probably not a good idea.",0);
	set_flag(15,11,run_dialog(1));
	if (i == 0)
		end();
	if (i <= 2)
		message_dialog("And that's it, really. The demon overlord's holdings are vast, and he is probably quite powerful. It may be hard to defeat him with what little you have done.","");
	if ((i > 2) && (i < 5))
		message_dialog("And that's not an inconsiderable amount. However, the demon lord's holdings are vast, and he is probably quite powerful. It may be easier to fight him if you weaken him further or gain more allies.","");
	if (i >= 5)
		message_dialog("You have many allies and have damaged his power greatly. You should be able to challenge him in open combat now. However, he still surely has many guards, and getting to him will not be easy.","");
break;

beginstate 27;
if (get_flag(15,12) != 0)
	end();
	
	message_dialog("For some reason, the demons left this library alone when they took over the place. There must be something interesting in here.","");
	set_flag(15,12,1);
break;

beginstate 28;
	if (get_flag(15,13) != 0)
		{message_dialog("You skim over the book again, but there is nothing left to learn. You have learned everything about Arcane Summon that this book has to teach.","");
		end(); }
	
	if (get_flag(250,2) == 0)
		end();
	
	message_dialog("You find the book that is surely the reason that this library was spared. Written in Bahssikavan script is a description of the finer points of casting the spell Arcane Summon.","");
	j = 0;
	i = 0;
	while (i <= 3)
	{if (get_stat(i,11) >= 15)
		{change_spell_level(i,0,17,1);
		print_named_str(i,"learns a level of Arcane Summon.");
		j = 1;
		}
	i = i + 1;
	}
	if (j == 0)
		message_dialog("Unfortunately, no one in your party is skilled enough to learn the spell.","");
	else
		set_flag(15,13,1);
break;

beginstate 29;
	message_dialog("Evidently this is where Nolagh-Khar sleeps.","");
break;

beginstate 30;
if (get_flag(15,14) != 0)
	end();
	
	message_dialog("You step out into the lava floor, expecting to get burned badly. To your surprise, it is warm to the touch, but not uncomfortably hot.","Across the room from you, there is a complicated set of machines. It draws your attention unescapably.");
	set_flag(15,14,1);
break;

beginstate 31;
if (get_flag(15,15) != 0)
	end();
	
	message_dialog("As you open this door, you see a room filled with lava! This must be a demon's room, possibly the chambers of Nolagh-Khar himself.","If that is so, these rooms must be extraordinarily dangerous, but they also may contain something useful.");
	set_flag(15,15,1);
break;

beginstate 32;
	reset_dialog();
	add_dialog_str(0,"In front of you is a machine of tremendous power. It vibrates with energy constantly. You could feel the awesome power of this machine even from across the room. Surely it must do something spectacular.",0);
	add_dialog_str(1,"There appears to be a place to put your hands, which would connect you to the machine. The handprints are much larger than yours, as they are a demon's, but using them might still work.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Place your hands in the indents in the machine.");
	choice = run_dialog(1);
	if (choice == 1)
		end();
	
	message_dialog("The moment that you do this, you feel a tremendous amount of power run through your body. Magic the likes of which you could not even previously begin to imagine courses through your veins as if it were your birthright.","You feel power, true power, and you begin to scream with the ecstasy of the magic.");
	
	if (character_in_party(906) == 4)
		{text_bubble_on_char(4,"I don't think you should...");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		}
		
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
		
	text_bubble_on_char(4,"");
	put_boom_on_space(23,14,0,2);
	put_boom_on_space(23,14,0,2);
	run_animation_sound(5);
	pause(1 * get_flag(250,8));
	
	put_boom_on_space(23,14,0,2);
	put_boom_on_space(23,14,0,2);
	run_animation_sound(5);
	pause(1 * get_flag(250,8));
	
	if (character_in_party(906) == 4)
		{text_bubble_on_char(4,"Um...");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		}
		
	text_bubble_on_char(4,"");
	put_boom_on_space(23,14,0,2);
	put_boom_on_space(23,14,0,2);
	run_animation_sound(5);
	pause(1 * get_flag(250,8));
	
	put_boom_on_space(23,14,0,2);
	put_boom_on_space(23,14,0,2);
	run_animation_sound(5);
	pause(1 * get_flag(250,8));
	
	if (character_in_party(906) == 4)
		{text_bubble_on_char(4,"be doing that.");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		}
		
	text_bubble_on_char(4,"");
	text_bubble_on_char(i,"I can feel the POWER!");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	force_instant_terrain_redraw();
	message_dialog("But then, something goes wrong. You're not a demon. Your anatomy is different from a demon's. The power goes the wrong directions, the wrong ways, turns your body inside out.","");

	put_boom_on_space(23,14,0,2);
	put_boom_on_space(23,14,0,2);
	run_animation_sound(5);
	pause(1 * get_flag(250,8));
	
	put_boom_on_char(i,1,0);
	run_animation_sound(51);
	
	kill_char(i,2,0);
	i = 4;
	if (character_in_party(1410) == 4)
		i = 3;
	while (char_ok(i) == 0)
		{i = i - 1; }
	text_bubble_on_char(i,"Uh oh.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	message_dialog("With power running completely out of control, the machine explodes!","");
	
	put_boom_on_space(23,14,0,2);
	put_boom_on_space(23,14,0,2);
	run_animation_sound(5);
	pause(1 * get_flag(250,8));
	
	put_boom_on_space(23,14,0,2);
	put_boom_on_space(23,14,0,2);
	run_animation_sound(5);
	pause(1 * get_flag(250,8));
	
	kill_char(1000,2,0);
break;

beginstate 33;
	reset_dialog();
	add_dialog_str(0,"As you step inside the ring of runes, you feel the strange urge to kneel before this altar. The magical energy here is palpable. Surely you could absorb some of it if you paid it the proper respects.",0);
	add_dialog_str(1,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Kneel and worship.");
	choice = run_dialog(1);
	if (choice == 1)
		end();
		
	message_dialog("You kneel before the altar, groveling before the awesome might of the dark deities for whom the shrine is dedicated. You feel their response.","");

	put_boom_on_space(29,9,1,3);
	put_boom_on_space(30,9,1,3);
	run_animation_sound(51);
	pause(1 * get_flag(250,8));
	
	put_boom_on_space(29,9,1,3);
	put_boom_on_space(30,9,1,3);
	run_animation_sound(51);
	pause(1 * get_flag(250,8));
	
	put_boom_on_space(29,9,1,3);
	put_boom_on_space(30,9,1,3);
	run_animation_sound(51);
	pause(1 * get_flag(250,8));
	
	message_dialog("It is not a happy one. You die screaming.","");
	kill_char(1000,2,0);
break;

beginstate 34;
	reset_dialog_preset_options(7);
	choice = run_dialog(1);
	if (choice == 1)
		end();
	
	change_char_energy(1000,-500);
	set_party_status(13,100,0);
	message_dialog("This book details demonic rituals and unholy incantations. As you read, you find yourself drawn in, so that you can't stop until you've finished. You realize only at that point that you've been murmuring aloud.","You don't feel very well after reading this book.");
break;

beginstate 35;
if (get_flag(15,16) != 0)
	end();
	
	message_dialog("The room before you appears to be the throne room of Nolagh-Khar. It is massive and filled with many, many demons. They haven't noticed you yet, but if you move any farther, they might.","You keep your hands close to your weapons. Proceeding farther this way means that you'll be faced with a big fight.");
	set_flag(15,16,1);
break;

beginstate 36;
if (get_flag(15,18) != 0)
	end();
	
	message_dialog("This is apparently a demon's bedroom. It is rather nicer than one might expect, especially with the potted plant to your right and the painting on the left. Apparently demons, cold-blooded killers, enjoy bright colors and live green things.","Either that, or they just never bothered to redecorate after taking the rooms over from the sliths.");
	set_flag(15,18,1);
break;

beginstate 37;
if (get_flag(15,19) != 0)
	end();
	
	reset_dialog_preset_options(1);
	add_dialog_str(0,"This appears to be the body of a slith who hid in this secret passage when the demons came to Bahssikava. Not much more than bones is left, but they are perfectly intact; this slith probably died of starvation, not of violence.",0);
	add_dialog_str(1,"On one of the slith's fingers is a shiny ring. What do you do?",0);
	choice = run_dialog(1);
	if (choice == 2)
		set_flag(15,19,reward_give(274));
break;

beginstate 38;
if (get_flag(15,20) != 0)
	end();
	
	set_flag(15,20,1);
	message_dialog("You charge deeper into Nolagh-Khar's throne room, fighting off enemies at all sides.","");
	i = 0;
	
	if (get_flag(14,21)) // has freed ghosts from crystal prison
		{i = i + 1;
		j = 37;
		activate_hidden_group(4);
		force_instant_terrain_redraw();
		message_dialog("Suddenly, several of the ghosts you freed from the crystal prison start flowing through the walls! They join in the combat, helping you!","");
		}
		
	if (get_flag(14,29)) // has freed living sliths
		{i = i + 1;
		activate_hidden_group(1);
		k = k + 3;
		force_instant_terrain_redraw();
		clear_buffer();
		if (i > 1)
			append_string("Also,");
		else
			append_string("Suddenly,");
		append_string(" a number of the living sliths you freed from the prison in the southeast appear in the hallways behind you!");
		if (character_in_party(1410) > 0)
			append_string(" Ithik calls to them, and they come to fight beside you, too.");
		else
			append_string(" You weren't quite sure what good it would do, but they are here to help you now.");
		get_buffer_text(dlgstr);
		message_dialog(dlgstr,"");
		}
		
	if (get_flag(214,0)) // has freed imps
		{i = i + 1;
		activate_hidden_group(2);
		k = k + 1;
		force_instant_terrain_redraw();
		j = 20;
		while (j <= 25)
			{set_char_status(j,3,20,0,0);
			j = j + 1; }
		message_dialog("And then Boarag appears in the hallway! The imps have all begun fighting on your side, but now Boarag's appearance clearly lifts their spirits. They will fight better now.","");
		play_sound(12);
		}
		
	if (get_flag(13,6)) // has freed mining ghosts
		{i = i + 1;
		j = 38;
		while (j <= 46)
			{place_monster(j,1,249,1);
			j = j + 2;
			k = k + 1; }
		// Make the ghosts friendly -- this is probably not the best way to do
		// it, but whatever; it works.
		l = 119;
		while (l > 5)
			{if (creature_type(l) == 249)
				set_attitude(l,3);
			l = l - 1;
			}
		force_instant_terrain_redraw();
		if (i > 3)
			message_dialog("And to top it all off, some of the ghosts that you freed from the mine flow through the north wall, too! They join in the fighting on your side!","");
		else
			message_dialog("Then some of the ghosts that you freed from the mine flow through the north wall! They join in the fighting on your side!","");
		}
		
	if (i == 0)
		{message_dialog("Unfortunately, you are badly outnumbered. This fight will not be easy.","The imps look upset about having to fight you, but they do anyway. You might have been able to gain their help, if only you had explored more.");
		end();
		}

	reset_dialog();
	if ((i >= 1) && (i <= 2))
		add_dialog_str(0,"Nolagh-Khar roars in fury at the reinforcements that have joined you. They are not many, but they are enough to change the complexion of the fight.",0);
	else
		add_dialog_str(0,"Nolagh-Khar roars in fury at the reinforcements that have joined you. There are a significant many of them, and they are enough to turn the tide of this combat.",0);
	if (get_flag(14,11))
		{if (get_flag(16,12))
			add_dialog_str(1,"Worse, his power is completely shut down. He waves his hands angrily as if he expects lightning to shoot from them, but nothing happens. He growls and draws his weapons instead.",0);
		else
			add_dialog_str(1,"Worse, his power is significantly reduced. He points his hands at an enemy and lightning shoots from them. When the enemy is still alive after the attack, he roars even louder in apparent frustration.",0);
		}
	else
		add_dialog_str(1,"However, his obviously phenomenal magical powers are still completely intact. The power sources near him glow with an infernal light, and he raises his hands to cause destruction.",0);
	add_dialog_str(2,"Now you have drawn the dread lord's attention, and this fight may get a lot harder.",0);
	alert_char(6);
break;

beginstate 39;
	toggle_quest(4,0);
	set_flag(15,21,1);
	j = char_loc_x(6);
	k = char_loc_y(6);
	message_dialog("The demon lord falls, slain by his many wounds. As he dies, the tremendous energy that powered his body goes completely wild, striking out those whose life energies were connected to and powered by his.","");
	l = 0;
	i = 7;
	while (i <= 19)
		{if (char_ok(i))
			{put_jagged_zap(j,k,char_loc_x(i),char_loc_y(j),0);
			put_boom_on_char(i,6,0);
			run_animation_sound(102);
			kill_char(i,2,0);
			award_party_xp(20,45);
			}
		i = i + 1;
		}
		
	put_jagged_zap(j,k,18,59,0);
	put_jagged_zap(j,k,4,36,0);
	put_jagged_zap(j,k,9,1,0);
	put_jagged_zap(j,k,32,59,0);
	put_jagged_zap(j,k,60,59,0);
	run_animation_sound(102);
	pause(1 * get_flag(250,8));
	
	erase_char(6);
	award_party_xp(300,80);
	
	message_dialog("You are dazed from the explosion. You shake your head, trying to clear it.","Before you have time to think or react, a ghost teleports into the room!");
	
	i = 49;
	while (i < 56)
		{j = 15;
		while (j < 18)
			{set_floor(i,j,255);
			set_terrain(i,j,0);
			j = j + 1;
			}
		i = i + 1;
		}
	
	force_view_center(50,6);
	set_total_visibility(1);
	force_instant_terrain_redraw();
	
	activate_hidden_group(3);
	put_boom_on_char(74,2,0);
	run_animation_sound(163);
	pause(1 * get_flag(250,8));
	
	if (party_size() == 1)
		text_bubble_on_char(74,"Adventurer!");
	else
		text_bubble_on_char(74,"Adventurers!");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"My name is Voss.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"I was once a leader in Bahssikava.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"When you began to fight Nolagh-Khar,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"I led an attack on the mines");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"to the west.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"We won an overwhelming victory.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"The demons who have been slavemasters");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"of both the Bahssikavans and the imps");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"are no more.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"We owe our freedom to you.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"Please, come with us");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"through the secret passage");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"in the east wall of this room");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"so that we can talk");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"and you can receive");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	text_bubble_on_char(74,"the gratitude of Bahssikava.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));
	
	text_bubble_on_char(74,"");
	force_instant_terrain_redraw();
	
	if (character_in_party(1410) > 0)
		{i = character_in_party(1410);
		
		force_view_center(char_loc_x(i),char_loc_y(i));
		force_instant_terrain_redraw();
		pause(10);
		
		text_bubble_on_char(i,"I must go with them.");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		
		text_bubble_on_char(i,"");
		text_bubble_on_char(i,"Working with you has been good.");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		
		text_bubble_on_char(i,"");
		text_bubble_on_char(i,"Come east and we will talk more.");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		
		text_bubble_on_char(i,"");
		text_bubble_on_char(i,"I will tell you how living sliths");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		
		text_bubble_on_char(i,"");
		text_bubble_on_char(i,"came to Ancient Bahssikava,");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		
		text_bubble_on_char(i,"");
		text_bubble_on_char(i,"which has only known ghosts and demons");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		
		text_bubble_on_char(i,"");
		text_bubble_on_char(i,"for years and decades.");
		force_instant_terrain_redraw();
		pause(6 * get_flag(250,8));
		
		text_bubble_on_char(i,"");
		set_flag(15,22,remove_char_from_party(1410));
		force_view_center(48,4);
		force_instant_terrain_redraw();
		}
	
	message_dialog("_Remember,_ the ghost chief says, _the secret passage is in the east wall of this room. Come to us, and we will give you the reward that you have earned._","With that, everyone disappears!");
	i = 6;
	while (i < 120)
		{if (char_ok(i))
			{put_boom_on_char(i,2,0);
			erase_char(i);
			}
		i = i + 1;
		}
	run_animation_sound(163);
	
	i = 1;
	while (i <= 13)
		{put_boom_on_space(52,i,1,0);
		set_terrain(52,i,0);
		i = i + 1;
		}
	run_animation_sound(51);
	
	set_total_visibility(0);
	force_instant_terrain_redraw();
break;

beginstate 40;
if (get_flag(15,21) == 0)
	end();
	
	block_entry(1);
	message_dialog("You are tempted to go back out this way and explore Ancient Bahssikava more, but the ghosts told you to go through a secret passage in the east wall. You turn back.","");
break;

beginstate 41;
if (get_flag(250,4) == 1) // Phaedra dead
	{add_dialog_str(0,"There is a sharply slanting slope down this way. However, you can't go down it: Phaedra needs you to bring her back to the guardpost.",0);
	dummy = run_dialog(1);
	block_entry(1);
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"There is a sharply slanting slope down this way. Do you wish to walk down it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Descend.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		move_to_new_town(17,32,32);
break;

beginstate 42;
	block_entry(1);
	message_dialog("You momentarily consider heading back down to the small basement to see what else is down there, but you decide against it. Better to proceed onward.","");
break;

beginstate 43;
if (get_flag(250,4) == 1) // Phaedra dead
	{add_dialog_str(0,"The passage turns sharply east here. However, you can't go down it: Phaedra needs you to bring her back to the guardpost.",0);
	dummy = run_dialog(1);
	block_entry(1);
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"The passage turns sharply east here. Do you wish to walk down it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Proceed east.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		{set_town_status(6,3);
		set_flag(15,23,1);
		move_to_new_town(6,4,37);
		}
break;

beginstate 44;
	message_dialog("The dark demon lord falls, mortally wounded. As he does, the altar that has been bubbling with acid settles down. It seems to have lost its dark magic.","");
	award_party_xp(200,50);
	set_flag(15,24,1);
break;

beginstate 45;
	if (get_flag(250,2) == 0)
		message_dialog("There's a book here written a script that you can't read. It looks pretty, but it doesn't help you much.","");

	if (get_flag(250,2) == 1)
		message_dialog("There's a book here written in the Bahssikavan language that you've partly learned. You can understand some of it! You read over the bit that you can follow.","_Temple in morning. Preacher reminds us of our sins and need for penance. School follows. Teacher tells us to study more. Play in afternoon. Latoss and I get in trouble for sneaking into mansion. Dinner. Then chores and sleep. Then tomorrow same. Sigh._");

	if (get_flag(250,2) == 2)
		{reset_dialog();
		add_dialog_str(0,"There's a book here written in the Bahssikavan language that you've partly learned. You can understand some of it! You read over the bit that you can follow.",0);
		add_dialog_str(1,"_Temple in morning. Preacher reminds us of our sins and need for penance. School follows. Teacher tells us to study more. Play in afternoon. Latoss and I get in trouble for sneaking into mansion. Dinner. Then chores and sleep. Then tomorrow same. Sigh._",0);
		add_dialog_str(2,"The next day: _Father says that they will make an attempt on the great steel doors tomorrow! I'd been hoping for a change, and now he says that we will try again to get back to the homeland! I will be extra good until then so the gods will forgive us._",0);
		add_dialog_str(3,"The next day: _Bad bad all bad we have to leave no time to write anything must go demons everywhere must go go go bad bad go bad go...._ It cuts off there, the writing scrawled halfway across the page.",0);
		dummy = run_dialog(1);
		}
break;

beginstate 46;
if (get_flag(15,26) == 0)
	{set_flag(15,26,1);
	message_dialog("You step inside an abandoned Bahssikavan house that was clearly nice when it was inhabited. You can still see the decorations on the doors and the ornate molding; it hasn't been damaged too much by the demons.","");
	}
break;

beginstate 47;
if (get_flag(15,27) == 0)
	{set_flag(15,27,1);
	message_dialog("Inside this room, you find a slith ghost! He motions for you to come forward and speak to him.","");
	}
break;

beginstate 48;
	message_dialog("There is nothing interesting on these shelves.","");
break;

beginstate 49;
if (get_flag(15,29) != 0)
	end();

if (character_in_party(906) < 0)
	end();
	
	set_flag(15,29,1);
	block_entry(1);
	march_party(58,2);
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	j = character_in_party(906);
	text_bubble_on_char(j,"Interesting.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(i,"What, Phaedra?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(j,"Oh, it's nothing.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(i,"No, really, what is it?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(j,"Well...");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"I just noticed that");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"this catastrophe they talked about,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"cavequakes and demons invading,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"happened sixty years ago.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(i,"So?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(j,"Well, that was the same time");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"as when Sss-Thoss summoned Grah-Hoth.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(i,"What's your point?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(j,"Just that the Bahssikavans");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"blamed themselves for the catastrophe,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"but it might not have been");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"their fault at all.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"The demons might not really have been");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"punishment from the gods,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"but just an unfortunate coincidence.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	force_instant_terrain_redraw();
	
	message_dialog("Phaedra is right, but you don't suppose it matters. There's nothing you can do about it now: all the ghosts are gone, and you couldn't tell anyone even if you wanted to.","You must simply journey onward.");
	
break;

beginstate 50;
if (has_special_item(9))
	end();
	
	change_spec_item(9,1);
	message_dialog("In this desk, you find a small brass key. You pocket it.","");
break;

beginstate 51;
	message_dialog("You begin the Ritual of Sanctification on Nolagh-Khar's personal altar, hoping that the tremendous might of this powerful ritual will defeat the evil enchantment on it and purify this place.","Unfortunately, you are horribly mistaken.");

	i = 0;
	while (i <= 5)
		{if (char_ok(i))
			{put_jagged_zap(23,14,char_loc_x(i),char_loc_y(i),2);
			put_boom_on_char(i,6,0);
			}
		i = i + 1; }
	run_animation_sound(65);
	kill_char(1000,2,0);
break;