begintownscript;

variables;
short ranpc,blabber,tport,emery,pcs,rectx;
short talk;

body;

beginstate 0;

	change_blocked(6,17,1);
	change_blocked(7,17,1);
	change_blocked(8,17,1);

break;

beginstate 1;
break;

beginstate START_STATE;
break;

beginstate 10;
	move_to_new_town(14,18,19);
break;

beginstate 11;
	if(get_flag(32,0) < 1){
		message_dialog("As you boldly stride onto the final floor of Fortress Grenze, you see a room designed to impress visitors; indeed, it is quite impressive.","The room is lit up by a magical crystal, revealing rare paintings and tremendous statues.  The statues portray a man of large build, sporting a tremendous blade.");
		message_dialog("You aren't sure who this person is, but he has a scraggly and bearded face, loose clothes, and an undeveloped physique","In one statue, he is smiling.  In the other, he is scowling.  It's a bizarre setup, who could have thought of it?");
		set_flag(32,0,1);
	}
break;

beginstate 12;
	if(get_flag(32,0) < 2){
		message_dialog("You come upon the dining room for Trahison and his lieutenants.  The view is amazing!","The food they get is probably of equivalent scrumptiousness, but there's none on the table for you to partake of at the moment.");
		set_flag(32,0,2);
	}
break;

beginstate 13;
	if(get_flag(32,0) < 3){

		if(get_flag(75,0) == 0){
			talk = 14;
		}
		else{
			talk = get_flag(75,0);
		}

		set_total_visibility(1);
		relocate_character(0,7,17);
		relocate_character(1,7,18);
		relocate_character(2,7,19);
		relocate_character(3,7,20);
		set_character_facing(1000,0);
		force_view_center(10,16);
		activate_hidden_group(4);
		if(get_flag(30,0) == 1){
			activate_hidden_group(3);
		}
		if(get_flag(30,0) == 2){
			activate_hidden_group(2);
		}
		force_instant_terrain_redraw();
		pause(5);

		if(party_size() > 1)
			text_bubble_on_char(38,"Greetings, Specialists!");
		if(party_size() == 1)
			text_bubble_on_char(38,"Greetings, Specialist!");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"Enough talking.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"Time to die.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"Fools, let me finish!");
		force_instant_terrain_redraw();
		pause(talk);

		reset_dialog();
		add_dialog_str(0,"Let him continue talking?",0);
		add_dialog_choice(0,"Attack.");
		add_dialog_choice(1,"Let him go on.");
		blabber = run_dialog(0);
		if(blabber == 1){
			set_state_continue(20);
			end();
		}

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"Do you realize");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"that for you to do");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"anything, you must have");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"the approval of Leader?");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"So?  Why do you care?");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"I want my freedom.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"I want to be free");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"from Leader's iron grip.");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"But with freedom,");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"you no longer know");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"what is right and wrong.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"What's right and wrong");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"is what you make of it.");
		force_instant_terrain_redraw();
		pause(talk);

		reset_dialog();
		add_dialog_str(0,"You respond:",0);
		add_dialog_choice(0,"Attack.");
		add_dialog_choice(1,"We deem you to be wrong.  What say you then?");
		add_dialog_choice(2,"Your lack of a way and the merits therein justify us too.");
		blabber = run_dialog(1);
		if(blabber == 1){
			set_state_continue(20);
			end();
		}
		if(blabber == 2){
			set_state_continue(21);
			end();
		}
		if(blabber == 3){
			set_state_continue(22);
			end();
		}
	}
break;

beginstate 14;

	if(get_flag(33,0) == 30){ // CHANGE BACK TO 30
		message_dialog("Damn!  The barriers placed here by Trahison haven't fallen with his death.  The magic in these must be strong and resilient.","Unfortunately, you are now bereft of ways by which you can escape.  There's no way you can survive the fall, and you can't slip around the barriers...");
		play_sound(95);
		reset_dialog();
		if(party_size() > 1)
			add_dialog_str(0,"Suddenly, a serene, familiar voice echoes in your head.  _Specialists.  Congratulations on dispelling the myths of ambiguity._",0);
		if(party_size() == 1)
			add_dialog_str(0,"Suddenly, a serene, familiar voice echoes in your head.  _Specialist.  Congratulations on dispelling the myths of ambiguity._",0);
		add_dialog_str(1,"You remember the voice.  It's the voice of the two shades in the Catacombs, the voice of the one who called himself Emery.",0);
		add_dialog_str(2,"_We can speak later.  For now, it would be best were we to meet in friendlier territory.  Oh, and by the way, step away from the barrier._",0);
		add_dialog_str(3,"The air around the Barrier begins to hum gently at first, then stronger.  You can feel the magic concentrating in the air.",0);
		add_dialog_choice(0,"What's happening...?");
		emery = run_dialog(1);
		force_view_center(14,25);
		force_instant_terrain_redraw();
		play_sound(25);
		pause(5);

		put_boom_on_space(14,25,0,0);
		set_terrain(14,25,0);
		set_floor(14,25,89);
		activate_hidden_group(8);
		force_instant_terrain_redraw();
		run_animation_sound(152);
		pause(5);

		erase_char(41);
		force_view_center(char_loc_x(0),char_loc_y(0));
		force_instant_terrain_redraw();
		pause(5);

		message_dialog("That was incredible!  The lightning bolt struck the barrier, dispelling it instantly.  You can now escape this place!","Whoever or whatever this Emery person is, you're just grateful that you aren't his enemy.  He clearly has power to burn.");
		set_flag(33,0,31);
		set_terrain(19,17,475);
		set_terrain(19,18,475);
		set_terrain(19,19,475);
	}

break;

beginstate 15;

	if(get_flag(33,0) == 31){
		set_total_visibility(1);
		force_view_center(24,24);
		force_instant_terrain_redraw();
		pause(5);

		play_sound(25);
		pause(5);

		put_boom_on_space(24,24,0,0);
		set_terrain(24,24,0);
		set_floor(24,24,89);
		activate_hidden_group(11);
		force_instant_terrain_redraw();
		run_animation_sound(152);
		pause(5);

		erase_char(42);
		force_instant_terrain_redraw();
		pause(5);

		set_terrain(24,24,268);
		put_boom_on_space(24,24,2,0);
		force_instant_terrain_redraw();
		run_animation_sound(10);
		pause(5);

		play_sound(95);
		pause(5);

		reset_dialog();
		add_dialog_str(0,"The voice in your head.",0);
		add_dialog_str(1,"_I trust you see the portal.  You will not be leaving Fortress Grenze the same way that you entered._",0);
		add_dialog_str(2,"_Come.  We will have a discussion in my house.  I trust you have no reservations to that._",0);
		add_dialog_str(3,"He chuckles.  _Well, of course I trust you.  Hypnotized never lie...  But anyway, please step into the portal._",0);
		add_dialog_choice(0,"How strange.");
		emery = run_dialog(1);
		set_flag(33,0,32);

		set_total_visibility(0);
		force_view_center(char_loc_x(0),char_loc_y(0));
		force_instant_terrain_redraw();
		pause(2);
	}

break;

beginstate 16;

	if(get_flag(33,0) >= 30){
		message_dialog("There are barriers here.  Unlike those before which were dispelled by Emery, these remain steadfastly erect as you approach.","These were likely by Emery himself, in order to assure your cooperation in using the portal.  It appears that you have no other choice after all.");
	}

break;

beginstate 17;

	if(get_flag(33,0) >= 30){
		reset_dialog_preset_options(3);
		emery = run_dialog(0);
		if(emery == 1){
			block_entry(1);
			end();
		}
		else{
			pcs = 0;
			while(pcs < 4){
				if(char_ok(pcs) == TRUE){
					put_boom_on_char(pcs,2,0);
					relocate_character(pcs,5,5);
				}
				pcs = pcs + 1;
			}
			set_total_visibility(1);
			force_instant_terrain_redraw();
			run_animation_sound(10);
			move_to_new_town(17,9,8);
		}
	}

break;

beginstate 20;

		if(get_flag(75,0) == 0){
			talk = 14;
		}
		else{
			talk = get_flag(75,0);
		}

		pause(talk);
		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"This is the ballroom,");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"and today you dance");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"with the Grim Reaper!");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		set_character_facing(38,6);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(38,13,12);
		force_view_center(13,12);
		force_instant_terrain_redraw();
		pause(5);

		relocate_character(38,14,12);
		force_view_center(14,12);
		force_instant_terrain_redraw();
		pause(5);

		if(get_flag(30,0) == 1){
			relocate_character(38,15,11);
			force_view_center(15,11);
			force_instant_terrain_redraw();
			pause(5);

			relocate_character(38,16,10);
			force_view_center(16,10);
			force_instant_terrain_redraw();
			pause(5);

			relocate_character(38,17,9);
			force_view_center(17,9);
			force_instant_terrain_redraw();
			pause(5);

			relocate_character(38,18,10);
			force_view_center(18,10);
			set_character_facing(38,4);
			force_instant_terrain_redraw();
			pause(5);

			relocate_character(38,18,11);
			force_view_center(18,11);
			set_character_facing(38,2);
			force_instant_terrain_redraw();
			pause(5);
		}
		if(get_flag(30,0) == 2){
			relocate_character(38,15,12);
			force_view_center(15,12);
			force_instant_terrain_redraw();
			pause(5);

			relocate_character(38,16,12);
			force_view_center(16,12);
			force_instant_terrain_redraw();
			pause(5);

			relocate_character(38,17,13);
			force_view_center(17,13);
			force_instant_terrain_redraw();
			pause(5);

			relocate_character(38,18,12);
			force_view_center(18,12);
			set_character_facing(38,0);
			force_instant_terrain_redraw();
			pause(5);

			relocate_character(38,18,11);
			force_view_center(18,11);
			set_character_facing(38,2);
			force_instant_terrain_redraw();
			pause(5);
		}

		force_view_center(12,13);
		force_instant_terrain_redraw();
		pause(5);

		activate_hidden_group(1);
		tport = 11;
		while(tport <= 37){
			put_boom_on_char(tport,2,0);
			tport = (tport + 1);
		}
		force_instant_terrain_redraw();
		run_animation_sound(10);
		pause(5);

		force_view_center(7,17);
		set_total_visibility(0);
		force_instant_terrain_redraw();
		pause(5);
		block_entry(1);
		set_terrain(14,25,475);
		set_terrain(14,24,475);
		set_terrain(14,26,475);
		set_flag(32,0,3);

		change_blocked(6,17,0);
		change_blocked(7,17,0);
		change_blocked(8,17,0);


break;

beginstate 21;

		if(get_flag(75,0) == 0){
			talk = 14;
		}
		else{
			talk = get_flag(75,0);
		}

		pause(talk);
		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"You say I'm wrong?");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"So what?");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"Then don't we have");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"the freedom to kill you?");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"No!  That's not what I mean.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"Let all beliefs thrive.");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"So now, Trahison,");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"You too preach rules?");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"No, I'm saying that...");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"...");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"What ARE you saying,");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"ex-General Trahison?");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"...fine!  Very well!");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"No rules at all.");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"Excellent.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"We'll be killing you,");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"assuming you're okay with that.");
		force_instant_terrain_redraw();
		pause(talk + 5);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"...!");
		force_instant_terrain_redraw();
		pause(talk);

		set_state_continue(23);
		end();
break;

beginstate 22;

		if(get_flag(75,0) == 0){
			talk = 14;
		}
		else{
			talk = get_flag(75,0);
		}

		pause(10);
		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"You speak nonsense.");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"The lack of a way");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"produces the viability");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"for a way to emerge.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		ranpc = random_party_member();
		text_bubble_on_char(ranpc,"Moreso, the fortification");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"of the lack of a way");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"is intrinsically a way.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"Wh...  What?");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"But my way and Leader's,");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"They're totally different!");
		force_instant_terrain_redraw();
		pause(talk);

		ranpc = random_party_member();
		text_bubble_on_char(38,"");
		text_bubble_on_char(ranpc,"You don't get it.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"Assume you believe");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"in nothing, whereas I");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(ranpc,"believe in something...");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(ranpc,"");
		text_bubble_on_char(38,"Enough!  Enough, already!");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"Do you not recognize");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"That Leader is a forceful");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"despot, whereas a");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"freedom fighter isn't?");
		force_instant_terrain_redraw();
		pause(talk);

		set_state_continue(23);
		end();
break;

beginstate 23;

		if(get_flag(75,0) == 0){
			talk = 14;
		}
		else{
			talk = get_flag(75,0);
		}

		pause(10);
		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"You don't understand!");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"You'll never understand!");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(38,"");
		text_bubble_on_char(38,"Enough of this.");
		force_instant_terrain_redraw();
		pause(talk);

		set_state_continue(20);
		end();
break;
