begintownscript;

variables;
short bmessage,pcs,enemies_lvl,rctx;

body;

beginstate INIT_STATE;

	if(get_flag(26,0) == 37){
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"Anthony turns to you and begins whispering.  _Now listen, we have to be incredibly careful here._",0);
		add_dialog_str(1,"_This place isn't very crowded, but there's a large and very powerful group of nephilim sitting in the main gallery here.  I'd suggest avoiding them._",0);
		add_dialog_str(2,"_Fortunately, I know some secret passages here, including the locations of some of the blasting material.  I have a plan that just might work._",0);
		add_dialog_str(3,"_Since this cave doesn't conduct sound from above very well, they're probably unawares of what went on above.  This is good, since we'll be able to open up the gates down here without their being ready._",0);
		add_dialog_str(4,"_Still, it's imperative that they not see us.  They won't be looking for us, but if we're found, then I trust you realize that it will be curtains.  Let's go._",0);
		add_dialog_choice(0,"Sure thing, Anthony.");
		bmessage = run_dialog(1);
		set_flag(26,0,38);
	}

	enemies_lvl = 6;
	while(enemies_lvl <= 21){
		if(char_ok(enemies_lvl) == TRUE){
			set_level(enemies_lvl,35);
		}
		enemies_lvl = (enemies_lvl + 1);
	}

	if(get_flag(59,0) >= 2){
		set_terrain(17,20,21);
		set_terrain(17,21,21);
	}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

	if(get_flag(56,0) == 1 && get_flag(57,0) == 0){
		pcs = 0;
		while(pcs <= 3 && get_flag(57,0) == 0){
			if(char_ok(pcs) == TRUE){
				if(get_energy(pcs) < get_flag((51 + pcs),0)){
					enemies_lvl = 6;
					while(enemies_lvl <= 21){
set_attitude(enemies_lvl,10);
enemies_lvl = (enemies_lvl + 1);
					}
					set_flag(57,0,1);
					message_dialog("No!  The nephils have noticed the spell you cast.  You can hear them grabbing their weapons and heading in your direction.","All in all, that was likely a relatively poor decision.");
					remove_char_from_party(700);
					message_dialog("_Well, you sure did it this time!  I can't take these guys...  I'm good at running, so I hope you are too!  I'll see you at the exit._","Anthony quickly pulls his cape over his light armor and begins dashing off in another direction.");
				}
				set_flag((51 + pcs),0,get_energy(pcs));
			}
			pcs = (pcs + 1);
		}

		if(is_combat() == 1 && get_flag(57,0) == 0){
			enemies_lvl = 6;
			while(enemies_lvl <= 21){
				set_attitude(enemies_lvl,10);
				enemies_lvl = (enemies_lvl + 1);
			}
			message_dialog("No!  The nephils have noticed you unsheathing your swords.  You can hear them grabbing their weapons and heading in your direction.","All in all, that was likely a relatively poor decision.");
			remove_char_from_party(700);
			message_dialog("_Well, you sure did it this time!  I can't take these guys...  I'm good at running, so I hope you are too!  I'll see you at the exit._","Anthony quickly pulls his cape over his light armor and begins dashing off in another direction.");
			set_flag(57,0,1);
		}
	}

break;

beginstate 10;

	move_to_new_town((1 + get_flag(99,5)),16,17);

break;

beginstate 11;

	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}

	if(get_flag(70,0) == 1){
		message_dialog("_Psst!  We're back in the danger zone, so act accordingly._","");
	}
	if(get_flag(70,0) == 0){
		reset_dialog();
		add_dialog_str(0,"_Psst!  Hey!  We're getting really close to 'em now.  You can almost see the flickering lights of their campfire.  Now, you're going to have to be incredibly careful from here on out.  Speak only in whispers._",0);
		add_dialog_str(1,"_We aren't exposed visibly, but we are exposed audibly.  Keep your voice down whenever possible because of this, alright?  And do NOT take out your swords.  We aren't here for combat._",0);
		add_dialog_str(2,"_Also, do not cast any spells of any size, shape or sort.  They will hear it, and will attack immediately when and if they do._",0);
		add_dialog_str(3,"_I will warn you when we are getting too close by putting a palm on your back.  When I do that, stop.  Do not continue.  If I'm right and you proceed past that point, we will likely be attacked._",0);
		add_dialog_str(4,"_Do you understand?_",0);
		add_dialog_choice(0,"Yeah.");
		bmessage = run_dialog(1);
		set_flag(70,0,1);
	}
	set_flag(56,0,1);

	pcs = 0;
	while(pcs <= 3){
		if(char_ok(pcs) == TRUE){
			set_flag((51 + pcs),0,get_energy(pcs));
		}
		pcs = (pcs + 1);
	}

break;

beginstate 12;

	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}

	if(character_in_party(700) == FALSE){
		message_dialog("_Anthony said he'd meet you at the exit...  You may not get another chance like this, to sneak into nephil territory.  You had best meet him there.","");
		block_entry(1);
		end();
	}

	if(get_flag(56,0) == 1){
		message_dialog("Anthony turns to you.  _Psst, we seem to be out of their hearing range again.  Don't goof off, but it's okay if you want to take a deep breath and relax.","");
		set_flag(56,0,0);
	}

break;

beginstate 13;

	if(get_flag(57,0) == 0){
		reset_dialog();
		add_dialog_str(0,"Suddenly, you feel a palm on your back.  It's Anthony's.",0);
		add_dialog_choice(0,"Stop.");
		add_dialog_choice(1,"Keep going.");
		bmessage = run_dialog(0);

		if(bmessage == 1){
			block_entry(1);
			end();
		}

		message_dialog("Anthony's palm disappears as he slinks away.  _Psst...  Meet me at the exit._  Meanwhile, a bunch of heavily-armed nephilim are turning their heads towards you.","This will be bad.");
		remove_char_from_party(700);
		enemies_lvl = 6;
		while(enemies_lvl <= 21){
			set_attitude(enemies_lvl,10);
			enemies_lvl = (enemies_lvl + 1);
		}
		set_flag(57,0,1);
	}

break;

beginstate 14;

	if(get_flag(58,0) == 0 && get_flag(57,0) == 0){
		message_dialog("Suddenly, in the darkness, you stumble upon some stalagmites.  Anthony leans up to you.","_Psst!  We can't clear this way without drawing too much attention.  Maybe if we can sneak by them by hugging the edge of the gallery, though...  Remember, a palm on your back means trouble._");
		set_flag(58,0,1);
	}

break;

beginstate 15;

	if(get_flag(59,0) == 0 && get_flag(57,0) == 0){
		message_dialog("Anthony lightly grasps your shoulder and points west.  _Psst- Over there.  Blasting caps.  Side passage._","He is especially difficult to hear due to the proximity of the nephilim and thereby the intensity of his voice.");
		set_flag(59,0,1);
	}

break;

beginstate 16;

	if(get_flag(59,0) == 1 && get_flag(57,0) == 0){
		message_dialog("_Psst...  This wall's a secret passage.  Inside, there's a lever.  Crank it._","");
		set_terrain(17,20,21);
		set_terrain(17,21,21);
		set_flag(59,0,2);
	}

break;

beginstate 17;

	if(get_flag(57,0) > 0){
		message_dialog("The lever to set off the blasting caps is still here.  Unfortunately for you, it has a locking mechanism, and Malachai's key does not work.","Anthony must still have the key- which is bad, since he is supposedly waiting for you.");
		block_entry(1);
	}
	if(get_flag(57,0) == 0){
		reset_dialog();
		add_dialog_str(0,"Anthony pulls out a key from his pocket.",0);
		add_dialog_str(1,"_This is the key that will allow you to pull the lever and set off the explosives at the end of the corridor we walked out of.  They should be able to give us a quick route of escape._",0);
		add_dialog_str(2,"_Let me know if I should set them off._",0);
		add_dialog_choice(0,"Not yet.");
		add_dialog_choice(1,"Go ahead.");
		bmessage = run_dialog(1);

		if(bmessage == 1)
			message_dialog("Anthony puts the key in the locking mechanism and flips the switch.  Was he even listening to you?  Hmm- probably not.","");

		play_sound(9);
		play_sound(99);
		play_sound(169);
		play_sound(5);
		play_sound(169);
		kill_char(20,3,0);
		play_sound(108);
		play_sound(108);
		play_sound(108);
		play_sound(108);

		set_terrain(18,15,137);
		set_terrain(19,15,137);
		set_terrain(18,16,137);
		set_terrain(19,16,137);
		set_terrain(18,17,137);
		set_terrain(19,17,137);
		erase_char(21);
		activate_hidden_group(1);
		remove_char_from_party(700);
		force_instant_terrain_redraw();

		message_dialog("Everybody in the cave had to have heard that.  Fortunately, you're fine.  Unfortunately, the nephils in the gallery were also likely not harmed.","Running would be a very good idea right now.  Anthony agrees- which is why, in the chaos of the explosion, he managed to get out before you.  You should follow him.");

		enemies_lvl = 6;
		while(enemies_lvl <= 21){
			if(char_ok(enemies_lvl) == TRUE)
				set_attitude(enemies_lvl,10);
			enemies_lvl = (enemies_lvl + 1);
		}
		set_flag(57,0,1);
	}

break;

beginstate 18;

	if(is_combat() == 1){
		block_entry(1);
		end();
	}

	message_dialog("Finally!  This is it- the end of the line!","Anthony said he would be waiting here.  Time to put in one last piece of effort and make it to him.");

	march_party(17,12);
	force_view_center(17,12);
	if(party_size() == 1){
		set_terrain(17,12,41);
		text_bubble_on_char(0,"Woah!");
		force_instant_terrain_redraw();
		play_sound(99);
		pause(6);
		text_bubble_on_char(0,"");
	}
	force_instant_terrain_redraw();
	pause(2);

	march_party(16,12);
	force_view_center(16,12);
	if(party_size() == 2){
		set_terrain(17,12,41);
		text_bubble_on_char(0,"Woah!");
		force_instant_terrain_redraw();
		play_sound(99);
		pause(6);
		text_bubble_on_char(0,"");
	}
	force_instant_terrain_redraw();
	pause(2);

	march_party(15,12);
	force_view_center(15,12);
	if(party_size() == 3){
		set_terrain(17,12,41);
		text_bubble_on_char(0,"Woah!");
		force_instant_terrain_redraw();
		play_sound(99);
		pause(6);
		text_bubble_on_char(0,"");
	}
	if(party_size() == 1){
		set_terrain(17,12,39);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);
	}
	force_instant_terrain_redraw();
	pause(2);

	march_party(14,11);
	force_view_center(14,11);
	if(party_size() == 4){
		set_terrain(17,12,41);
		text_bubble_on_char(0,"Woah!");
		force_instant_terrain_redraw();
		play_sound(99);
		pause(6);
		text_bubble_on_char(0,"");
	}
	if(party_size() == 2){
		set_terrain(16,12,39);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);
	}
	force_instant_terrain_redraw();
	pause(2);

	march_party(13,10);
	force_view_center(13,10);
	if(party_size() == 3){
		set_terrain(16,12,39);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);
	}
	force_instant_terrain_redraw();
	pause(2);

	march_party(12,9);
	force_view_center(12,9);
	if(party_size() == 4){
		set_terrain(16,12,39);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);
	}
	force_instant_terrain_redraw();
	pause(6);

	relocate_character(23,15,9);
	force_instant_terrain_redraw();
	pause(8);

	reset_dialog();
	add_dialog_str(0,"_Hey, I see you made it!  Good going._",0);
	add_dialog_str(1,"Oh...  So it was Anthony who closed those walls behind you.",0);
	add_dialog_str(2,"_Guess what?  We can relax now.  I've just sealed the nephils in the mines.  There's a secret passage that leads to the locking mechanism on their side, but they won't be able to open it without a key like mine._",0);
	add_dialog_str(3,"_So...  Take a deep breath.  We just got through the easiest part._",0);
	add_dialog_choice(0,"What's the next part of your plan?");
	bmessage = run_dialog(1);

	reset_dialog();
	add_dialog_str(0,"_I'm glad you asked.  See, I used to be in charge of reconnaissance, so I know how well-guarded the jagged, rocky terrain we're going to have to go through is._",0);
	add_dialog_str(1,"_It's almost ironclad-tough to sneak through their checkpoint, but there's a pathway that the nephils don't patrol that I am mostly sure will lead us to the rear of their fortress- you know, behind the majority of their soldiers._",0);
	add_dialog_str(2,"_So, are you ready?_",0);
	add_dialog_choice(0,"Mmm.  Yeah.");
	bmessage = run_dialog(1);

	add_char_to_party(23);

	block_entry(1);

break;

