// Town 2: Bahssikava Tunnels
begintownscript;

variables;


short dummy,i,j;
string dlgstr;

body;

beginstate INIT_STATE;

turn_off_training(1);
set_crime_tolerance(2);

set_level(9,50);

if (get_flag(2,13) == 0)
	{change_blocked(30,41,1);
	change_blocked(31,41,1);
	change_blocked(30,40,1);
	change_blocked(31,40,1);
	change_blocked(30,39,1);
	change_blocked(31,39,1);
	}
	
if (get_flag(2,15) == 0)
	{change_blocked(42,29,1);
	change_blocked(43,29,1);
	change_blocked(44,29,1);
	change_blocked(42,30,1);
	change_blocked(43,30,1);
	change_blocked(44,30,1);
	change_blocked(43,31,1);
	change_blocked(44,31,1);
	}

if (get_flag(2,0) == 0)
	{force_instant_terrain_redraw();
	message_dialog("You enter the tunnels underneath Lost Bahssikava for the first time. You feel some strange magic in the air, although you can't quite place it. It makes you feel very strange, though, as if you were losing your mind."," The air is getting hotter, too.");
	set_flag(2,0,1); }

if (get_flag(5,0) != 1)
	{erase_char(15);
	end(); }
	
	set_flag(5,0,2);
	relocate_character(0,3,35);
	relocate_character(1,4,35);
	relocate_character(2,5,35);
	relocate_character(3,6,35);
	set_character_facing(0,2);
	set_character_facing(1,2);
	set_character_facing(2,2);
	set_character_facing(3,2);
	force_instant_terrain_redraw();

	message_dialog("You walk down the passage. Kass is waiting for you below.","");

	text_bubble_on_char(15,"Continue seeking the steel doors.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"Do not worry about");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"the battle above;");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"another warrior more or less");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"will not matter up there,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"but if you can clear");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"the way to the doors,");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"the whole situation will change.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"I will wait above");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"for your return.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	relocate_character(15,2,36);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	relocate_character(15,3,36);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	relocate_character(15,4,36);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	relocate_character(15,5,36);
	force_instant_terrain_redraw();
	pause(3 * get_flag(250,8));

	set_character_facing(15,0);
	text_bubble_on_char(15,"Good luck.");
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,8));

	text_bubble_on_char(15,"");
	set_character_facing(15,4);
	force_instant_terrain_redraw();
	pause(2 * get_flag(250,8));

	erase_char(15);
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	force_view_center(char_loc_x(i),char_loc_y(i));
	force_instant_terrain_redraw();

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
// If the party has sanctified the altar and killed the drake lord, give them a
// one-time message, after combat is over.
if (get_flag(2,15) < 2)
	end();
if (get_flag(2,18) < 1)
	end();
if (is_combat())
	end();
if (get_flag(2,19) != 0)
	end();
	
	set_flag(2,19,1);
	reset_dialog();
	add_dialog_str(0,"Finally, with the altar destroyed and the Drake Lord slain, you have a moment to look around and think.",0);
	if (party_size() > 1) {
		add_dialog_str(1,"Your companion who lost control and attacked you looks rather sheepish. _I... I'm sorry._ The words come tumbling out unarranged. _I don't know what came over me. I just... lost it. I heard things, voices, and...._ A pained shrug. _I don't know._",0);
		add_dialog_str(2,"You know that you will not soon get over the image of your companion's face filled with hatred and the feelings associated with fighting one whom you previously trusted with your life.",0);
		}
	else {
		add_dialog_str(1,"The angry, hating feelings have died down, but they are still there. Whatever that altar awoke in you, it was not created by the altar. It was there already; the altar just brought it to the surface.",0);
		add_dialog_str(1,"You know that you will not soon forget the sensation of battling yourself. You journey alone, and if you cannot even trust yourself, then there is no one left whom you can trust.",0);
		}
	set_flag(2,19,run_dialog(1));
break;

beginstate 10;
	move_to_new_town(1,41,41);
break;

beginstate 11;
	move_to_new_town(3,4,12);
break;

beginstate 12;
	message_dialog("The remains of a collapsed bridge float here. You can't cross.","");
break;

beginstate 13;
if (get_flag(2,1) == 1)
	end();
	
	message_dialog("This bridge is old. Very old. And it has definitely not been maintained. In fact, it looks as though some pieces have fallen into the water fairly recently.","Looking to the north, you notice that the other bridge has suffered a worse fate. It may be tricky getting around down here if all the bridges are this bad.");
	set_flag(2,1,1);
break;

beginstate 14;
	if (get_flag(2,15) == 0)
		set_flag(2,15,1);
	change_blocked(42,29,0);
	change_blocked(43,29,0);
	change_blocked(44,29,0);
	change_blocked(42,30,0);
	change_blocked(43,30,0);
	change_blocked(44,30,0);
	change_blocked(43,31,0);
	change_blocked(44,31,0);
break;

beginstate 15;
if (get_flag(2,14) == 1)
	end();
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	set_flag(2,14,1);
	clear_buffer();
	append_string("As you keep walking this way, the feeling of magic grows considerably stronger. ");
	if (party_size() > 1) {
		append_string("You look at ");
		append_char_name(i);
		append_string(" and notice that your party's leader's face is contorted and straining. The expression on the face you are seeing does not look good.");
		get_buffer_text(dlgstr);
		message_dialog(dlgstr,"If you continue down this passage, what you are seeing may get much worse. Whatever is causing this must be doing it in order to attack you while you are weak. You should proceed with your weapons drawn and ready in your hands.");
		}
	else {
		reset_dialog();
		add_dialog_str(0,"As you walk down this passage, you feel strange voices speaking in your head, whispering bizarre things. These voices make you angry, make you feel things you've never felt before. You feel violently destructive... destructive towards yourself.",0);
		add_dialog_str(1,"You are not quite able to control yourself, as if each of your hands were controlled by a different entity and these two entities hated each other.",0);
		add_dialog_str(2,"You can hardly contain this strange rage. You feel as though you are fighting a battle with yourself, and you are certain that this feeling will become very literal momentarily.",0);
		add_dialog_str(3,"You can't sense what is causing these strange, self-destructive feelings, but if you are to survive your journey through these tunnels, you had better find it soon, before you rend yourself limb from limb.",0);
		add_dialog_str(4,"With what is left of your sanity, you reason that whatever is causing this must be doing it in order to attack you while you are weak. You should proceed with your weapons drawn and ready in your hands.",0);
		dummy = run_dialog(1);
		}
break;

beginstate 16;
if (get_flag(2,16) != 0)
	end();
// Do nothing if the party isn't a singleton but the lead character triggered
// this.
if (party_size() > 1) {
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	j = i + 1;
	while (char_ok(j) == 0)
		{j = j + 1; }
	if (((char_loc_y(i) == 17) || (char_loc_y(i) == 15)) && (char_loc_y(j) > 25))
		end();
	}
	
	set_flag(2,16,1);
	message_dialog("The thick aura of magic is strangling you. It feels like pure, concentrated evil, as if the very essence of the greatest and most terrible of all the vices, hate, were distilled and concentrated into a gas that smothers you.","You feel sluggish under the weight of the foulness.");
	
	// If the party is a singleton, slow him. If not, slow all but the lead
	// character.
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	if (party_size() > 1)
		i = i + 1;
	while (i < 6) {
		set_char_status(i,3,-25,1,0);
		i = i + 1;
		}
	play_sound(7);
	print_str("You are slowed.");
break;

beginstate 17;
if (get_flag(2,17) != 0)
	end();
	
	set_flag(2,17,1);
	message_dialog("You are approaching the source of the powerful magic that is having such a powerful effect on you. You hear loud hissing, much like the drakes that you've been fighting but considerably bigger.","");
break;

beginstate 18;
	set_flag(2,18,1);
	if (get_flag(2,15) < 2)
		message_dialog("You kill the Drake Lord, but the terrible magic is still completely active. It seems to be centered around the dark altar.","");
	else
		message_dialog("You kill the Drake Lord! His mighty body falls to the ground, lifeless.","");
break;

beginstate 19;
if (get_flag(2,6) == 1)
	end();
	else
	{message_dialog("Someone left a boat here. Like everything else around here, it hasn't been touched in many years, so it is old and creaky. Still, it should be able to carry you.","");
	set_flag(2,6,1); }
break;

beginstate 20;
if (get_flag(2,7) == 1)
	end();
	else
	{message_dialog("There was a cave-in here recently. You can't pass.","");
	set_flag(2,7,1); }
break;

beginstate 21;
	message_dialog("You can't be completely sure why, but this body has been better preserved than the others. You can still see the wounds.","The drakes clearly made no effort to eat this slith. They were destroying an intruder, not feeding. They are intelligent and territorial beasts.");
break;

beginstate 22;
	move_to_new_town(5,27,59);
break;

beginstate 23;
	if (get_flag(2,8) == 1)
	end();
	else
	{message_dialog("This cavern contains several slith skeletons. One body is slightly intact. The rest have long since decayed into yellowed bones.","The area is filled with blast marks, probably from a battle with drakes. Presumably this is where part of Legare's doomed expedition met its end.");
	set_flag(2,8,1); }
break;

beginstate 24;
	if (get_flag(2,9) == 1)
	end();
	else
	{message_dialog("It appears that this was once a secret passage. It has long since caved in.","");
	set_flag(2,9,1); }
break;

beginstate 25;
	if (get_flag(2,10) == 1)
	end();
	else
	{message_dialog("It looks as though there was a massive cave-in here a few months ago. As you look farther, you see the remains of someone's habitation.","This must have been where Legare spent his twenty years of isolation.");
	set_flag(2,10,1); }
break;

beginstate 26;
	if (get_flag(3,6) < 1)
		{set_flag(3,6,1);
		move_to_new_town(3,19,28); }
	move_to_new_town(3,19,28);
break;

beginstate 27;
	if (get_flag(2,11) == 1)
	end();
	else
	{reset_dialog();
	add_dialog_str(0,"Now, this is peculiar. In this cave, you can see two distinct episodes. First, there are fragments of bones from long, long ago that are so decomposed that they are hardly recognizable.",0);
	add_dialog_str(1,"But second, you can see that the Empire was here much more recently. They left their mark, and indeed, one of their soldiers died here. The cause of death is not clear, but they took his weapons and armor and left his body and some personal trappings.",0);
	add_dialog_str(2,"What could the Empire have been doing down here? And how far did they go?",0);
	dummy = run_dialog(1);
	set_flag(2,11,1); }
break;

beginstate 28;
	if (get_flag(2,12) == 1)
	end();
	else
	{message_dialog("Some bones lie here. You can't tell from what kind of creature they come, because they are too old and damaged.","");
	set_flag(2,12,1); }
break;

beginstate 29;
	message_dialog("The bridge here is still broken. You can't cross.","");
break;

beginstate 30;
	message_dialog("From far away, you can hear a loud rustling, as if a large beast has just begun to move. From the sound of it, you have disturbed something big in these tunnels, and it's coming right towards you.","");
break;

beginstate 31;
if (get_flag(2,13) != 0)
	end();
	
	change_blocked(30,41,0);
	change_blocked(31,41,0);
	change_blocked(30,40,0);
	change_blocked(31,40,0);
	change_blocked(30,39,0);
	change_blocked(31,39,0);
	set_flag(2,13,1);
	activate_hidden_group(1);
	play_sound(122);
	message_dialog("As you walk down this passage, a group of strange, red-hot slimes fall from the ceiling around you! They do not look too sturdy, but they are quite warm, and they could burn you badly.","They mindlessly swarm you.");
break;

beginstate 32;
if (get_flag(2,20) != 0)
	end();
if (get_flag(2,15) < 2)
	end();
if (get_flag(2,18) < 1)
	end();
	
	reset_dialog();
	add_dialog_str(0,"As you walk through the entrance to this terrible room, you give it a long look. You can't tell much about the identity of the Drake Lord, but he must have been here for a while to have built an altar like that and imbued it with so much magic.",0);
	add_dialog_str(1,"You may never know who this Drake Lord was or why he created so much hatred, but at least you've caused the magic to leave this place. You can only hope that the rest of the journey to the steel gates is less eventful.",0);
	add_dialog_str(2,"It is no wonder that the Bahssikavans didn't want to come down this way if they sensed that kind of magic ahead of them.",0);
	set_flag(2,20,run_dialog(1));
break;