begintownscript;

variables;

	short i,j;

body;

beginstate INIT_STATE;
	if(get_flag(1,11)==2){
		set_terrain(25,34,0);
		set_terrain(37,34,0);
	}
	if(get_flag(1,20)==1){
		set_height(46,13,13);
		set_height(45,13,12);
	}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	//teleport_party(58,43,1);
	if(get_flag(1,16)==1){
		if(get_flag(1,17)==0){
			message_dialog("All around you shades begin to rise up from the depths!", "");
			set_flag(1,17,1);
		}
		if(char_on_loc(40,46) == -1){
			set_height(40,45,9);
			set_floor(40,45,7);
			place_monster(40,45,22,0);
			j= char_on_loc(40,45);
			set_character_facing(j,4);
			i=436;
			while(i>=432){
				set_terrain(40,45,i);
			force_instant_terrain_redraw();
				pause(3);
				i = i - 1;
			}
			relocate_character(j,40,46);
			set_character_facing(j,6);
			force_instant_terrain_redraw();
			pause(1);
			set_floor(40,45,71);
			set_height(40,45,1);
		}
		if(char_on_loc(44,46) == -1){
			set_height(44,45,5);
			set_floor(44,45,7);
			place_monster(44,45,22,0);
			j= char_on_loc(44,45);
			set_character_facing(j,4);
			i=436;
			while(i>=432){
				set_terrain(44,45,i);
				force_instant_terrain_redraw();
				pause(3);
				i = i - 1;
			}
			relocate_character(j,44,46);
			set_character_facing(j,2);
			force_instant_terrain_redraw();
			pause(1);
			set_floor(44,45,71);
			set_height(44,45,1);
		}
	}
break;

beginstate 10;
	move_to_new_town(2,46,38);
break;

beginstate 11;
	i=2;
	while(i<=9){
		set_floor(10,i,71);
		set_terrain(10,i,1);
		set_height(10,i,1);
		i = i + 1;
	}
break;

beginstate 12;
	i=2;
	while(i<=9){
		set_floor(10,i,95);
		set_terrain(10,i,295);
		set_height(10,i,27 + i);
		i = i + 1;
	}
break;

beginstate 13;
	teleport_party(13,10,1);
	set_character_facing(0,4);
break;

beginstate 14;
	teleport_party(1,9,1);
break;

beginstate 15;
	teleport_party(34,1,1);
	if(get_flag(1,23)==0){
		relocate_character(0,33,2);
		set_terrain(34,1,440);
		force_instant_terrain_redraw();
		pause(1);
		put_item_on_spot(34,1,207);
		force_instant_terrain_redraw();
		pause(1);
		set_terrain(34,1,439);
		force_instant_terrain_redraw();
		pause(1);
		set_terrain(34,1,438);
		force_instant_terrain_redraw();
		pause(1);
		set_terrain(34,1,437);
		force_instant_terrain_redraw();
		play_sound(69);
		set_terrain(34,1,0);
		relocate_character(0,34,1);
		move_item_on_spot(34,1,-1,-1);
		put_item_on_spot(33,1,206);
		set_terrain(33,1,408);
		force_instant_terrain_redraw();
		pause(2);
		move_item_on_spot(33,1,-1,-1);
		put_item_on_spot(33,1,207);
		set_terrain(33,1,407);
		force_instant_terrain_redraw();
		pause(2);
		move_item_on_spot(33,1,-1,-1);
		move_item_on_spot(48,1,33,1);
		//put_item_on_spot(33,1,206);
		set_terrain(33,1,296);
		force_instant_terrain_redraw();
		play_sound(69);
		message_dialog("That nearly made you jump out of your skin, it was so sudden. At a glance this looks like the same ring that you fed into the slot higher up. The same one that made the shade appear.","Now the ring is back in your possesion, but you're not sure if you think that that's a good thing.");
		set_flag(1,23,1);
	}
break;

beginstate 16;
	teleport_party(22,2,1);
break;

beginstate 17;
	i=2;
	while(i<=9){
		set_floor(34,i,71);
		set_terrain(34,i,1);
		set_height(34,i,1);
		i = i + 1;
	}
break;

beginstate 18;
	i=2;
	while(i<=9){
		set_floor(34,i,95);
		set_terrain(34,i,295);
		set_height(34,i,27 + i);
		i = i + 1;
	}
break;

beginstate 19;
	teleport_party(37,10,1);
	set_character_facing(0,4);
break;

beginstate 20;
	teleport_party(25,9,1);
break;

beginstate 21;
	teleport_party(10,13,1);
break;

beginstate 22;
	teleport_party(46,2,1);
break;

beginstate 23;
	i=14;
	while(i<=21){
		set_floor(10,i,71);
		set_terrain(10,i,1);
		set_height(10,i,1);
		i = i + 1;
	}
break;

beginstate 24;
	i=14;
	while(i<=21){
		set_floor(10,i,95);
		set_terrain(10,i,295);
		set_height(10,i,15 + i);
		i = i + 1;
	}
break;

beginstate 25;
	teleport_party(13,22,1);
	set_character_facing(0,4);
break;

beginstate 26;
	teleport_party(1,21,1);
break;

beginstate 27;
	teleport_party(34,13,1);
break;

beginstate 28;
	teleport_party(22,14,1);
break;

beginstate 29;
	i=14;
	while(i<=21){
		set_floor(34,i,71);
		set_terrain(34,i,1);
		set_height(34,i,1);
		i = i + 1;
	}
break;

beginstate 30;
	i=14;
	while(i<=21){
		set_floor(34,i,95);
		set_terrain(34,i,295);
		set_height(34,i,15 + i);
		i = i + 1;
	}
break;

beginstate 31;
	teleport_party(37,22,1);
	set_character_facing(0,4);
break;

beginstate 32;
	teleport_party(25,21,1);
break;

beginstate 33;
	teleport_party(10,25,1);
break;

beginstate 34;
	teleport_party(46,14,1);
break;

beginstate 35;
	i=26;
	while(i<=33){
		set_floor(10,i,71);
		set_terrain(10,i,1);
		set_height(10,i,1);
		i = i + 1;
	}
break;

beginstate 36;
	i=26;
	while(i<=33){
		set_floor(10,i,95);
		set_terrain(10,i,295);
		set_height(10,i,3 + i);
		i = i + 1;
	}
break;

beginstate 37;
	teleport_party(13,34,1);
	set_character_facing(0,4);
break;

beginstate 38;
	teleport_party(1,33,1);
break;

beginstate 39;
	teleport_party(34,25,1);
break;

beginstate 40;
	teleport_party(22,26,1);
break;

beginstate 41;
	i=26;
	while(i<=33){
		set_floor(34,i,71);
		set_terrain(34,i,1);
		set_height(34,i,1);
		i = i + 1;
	}
break;

beginstate 42;
	i=26;
	while(i<=33){
		set_floor(34,i,95);
		set_terrain(34,i,295);
		set_height(34,i,3 + i);
		i = i + 1;
	}
break;

beginstate 43;
	teleport_party(38,34,1);
break;

beginstate 44;
	teleport_party(25,33,1);
break;

beginstate 45;
	teleport_party(10,37,1);
break;

beginstate 46;
	teleport_party(46,26,1);
break;

beginstate 47;
	i=38;
	while(i<=45){
		set_floor(10,i,71);
		set_terrain(10,i,1);
		set_height(10,i,1);
		i = i + 1;
	}
break;

beginstate 48;
	i=38;
	while(i<=45){
		set_floor(10,i,95);
		set_terrain(10,i,295);
		set_height(10,i,i - 9);
		i = i + 1;
	}
break;

beginstate 49;
	teleport_party(13,46,1);
	set_character_facing(0,4);
break;

beginstate 50;
	teleport_party(1,45,1);
break;

beginstate 51;
	teleport_party(34,37,1);
break;

beginstate 52;
	teleport_party(22,38,1);
break;

beginstate 53;
	i=38;
	while(i<=45){
		set_floor(34,i,71);
		set_terrain(34,i,1);
		set_height(34,i,1);
		i = i + 1;
	}
break;

beginstate 54;
	i=38;
	while(i<=45){
		set_floor(34,i,95);
		set_terrain(34,i,295);
		set_height(34,i,i - 9);
		i = i + 1;
	}
break;

beginstate 55;
	teleport_party(37,46,1);
	set_character_facing(0,4);
break;

beginstate 56;
	teleport_party(25,45,1);
break;

beginstate 57;
	if(get_flag(1,22)==0){
		set_flag(1,22,1);
		message_dialog("You stop to rest for a minute; you've been walking for a long time. You look up at the stairs you've come down, but there's really not much to see. Then, you notice that the whispering sounds are back.","They're definitely coming from below, and they seem to be repeating, _Ampersand, Ampersand!_ Then, they abruptly fade away. You feel quite unnerved.");
	}
break;

beginstate 58;
	if(get_flag(1,24)==0){
		message_dialog("Just wonderful. In front of you a magical force-field blocks the stairs. It even extends out above the seemingly bottomless drop, so there's not even chance you could climb around or over it.","Sure, climbing the stairs hasn't really been getting you anywhere as far as you can tell, but at least it feels like you're doing something, and to be blocked now is frustrating in the extreme.");
		set_flag(1,24,1);
	}
	if(get_flag(1,25)<2 && char_has_item(0,206)){
		reset_dialog_preset_options(0);
		if(get_flag(1,25)==0){
			add_dialog_str(0,"You remember that the last time there was an obstacle in your path the ring was the tool you needed to remove it.",0);
			add_dialog_str(1,"You look closely at the surface of the force-field, but there's nothing like the slot that the stone barricade had. But, you notice that the field is made of tiny, flowing runes. Taking out the ring, you notice that the patterns on it form similar runes.",0);
			set_flag(1,25,1);
		}
		else{
			add_dialog_str(0,"You're still sure that the ring has something to do with this barrier, and you have an urge to find a way past it. ",0);
		}
		add_dialog_choice(0,"Wave the ring at the force field");
		add_dialog_choice(1,"Try to put the ring into the force field");
		add_dialog_choice(2,"Keep the ring");
		i = run_dialog(1);
		if(i==1){
			message_dialog("You wave the ring in front of the field in every pattern you can think of, but the barrier stays firm. You think you might see the runes moving to follow the motion of the ring, though.","");
		}
		else if(i==2){
			message_dialog("You bring the ring against the surface of the barrier, and press it in. After a moment, it is pulled out of your grasp and inside the field, which begins to glow and unravel. ","As the barrier disintigrates, the ring is carried over the edge of the steps and around beneath you, out of sight.");
			take_all_of_item(206);
			force_instant_terrain_redraw();
			play_sound(53);
			pause(1);
			put_object_on_space(20,34,-1);
			force_instant_terrain_redraw();
			play_sound(53);
			pause(1);
			put_object_on_space(20,33,-1);
			force_instant_terrain_redraw();
			play_sound(53);
			pause(1);
			play_sound(53);
			pause(1);
			play_sound(53);
			pause(1);		
			message_dialog("The last of the runes fade into the air, leaving only a smell of ozone in their wake.","You've lost the ring again, but now you can proceed downward.");
			set_flag(1,25,2);
		}
	}
break;

beginstate 59;
	if(get_flag(1,26)==0){
		message_dialog("As you walk, a new thought comes to you: What if this is all some illusion or hallucination? That problem, you realize, it that it doesn't seem to matter; whether all this is 'real' or not, you certainly seem to be stuck with experiencing it.","");
		set_flag(1,26,1);
	}
break;

beginstate 60;
	if(get_flag(1,27)==0){
		message_dialog("The monotony of this situation is really getting to you. You pause, just to do something different, but it doesn't help. Neither does kicking the wall, although that hurts your foot. You're exhausted, chilly, and you have bruises and cuts all over.","You could just end it all; the edge of the stairs is only feet away. You almost want to, but a feeling you can't describe makes you draw away from the edge, turn, and go on, on down the stairs.");
		set_flag(1,27,1);
	}
break;

beginstate 61;
	if(get_flag(1,28)==0){
		message_dialog("You suddenly hear a voice, directly behind you say _Ampersand!_ You whirl wildly around, looking everywhere, but there is nothing moving nearby. It must have been your imagination, but it sounded so real.","");
		set_flag(1,28,1);
	}
break;

beginstate 62;
	if(get_flag(1,16)==0)
		set_flag(1,16,1);
break;

beginstate 63;
	if(get_flag(1,16)==1){
		block_entry(1);
		message_dialog("When you try to break free, another shade rises up in front of you and knocks you back.","");
		if(char_loc_x(0)>42)
			i = 45;
		else
			i = 39;
		place_monster(i,46,22,0);
	}
break;

beginstate 64;
	if(get_flag(1,29)==0){
		message_dialog("Again, you hear a voice speak, _Ampersand!_, but this time it isn't alone. You hear first a few voices then many, some whispering, some speaking noramlly, all sounding urgent. ","The sounds come from all directions, but there is no one there. Amid the cacophony of voices you race onward, wild terror in your heart. Then suddenly, there is total silence.");
		teleport_party(25,45,1);
		set_character_facing(0,4);
		set_flag(1,29,1);
	}
break;