begintownscript;

variables;

	short i,j;
	string text;
body;

beginstate INIT_STATE;
	if(get_flag(1,3) == 2){
		set_terrain(5,5,0);
		set_terrain(5,25,0);
	}
break;

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

beginstate START_STATE;
	
break;

beginstate 10;
	teleport_party(31,14,1);
break;

beginstate 11;
	teleport_party(30,34,1);
break;

beginstate 12;
	teleport_party(14,5,1);
break;

beginstate 13;
	teleport_party(39,6,1);
break;

beginstate 14;
	i=6;
	while(i<=13){
		set_floor(14,i,71);
		set_terrain(14,i,1);
		set_height(14,i,1);
		i = i + 1;
	}
break;

beginstate 15;
	i=6;
	while(i<=13){
		set_floor(14,i,95);
		set_terrain(14,i,295);
		set_height(14,i,23 + i);
		i = i + 1;
	}
break;

beginstate 16;
	teleport_party(5,34,1);
	set_character_facing(0,4);
break;

beginstate 17;
	teleport_party(5,13,1);
break;

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

beginstate 19;
	if(get_flag(1,2) == 0){
		message_dialog("On one of the steps a glint of light catches your eye. You look closely, and find a ring, which you pick up. It looks like silver, and the workmanship is quite fine. It has an ampersand symbol in place of a stone.","Seeing the ring sets you thinking about your purpose here. Are you perhaps an adventurer, seeking treasure in an ancient tomb? But then surely if you were an adventurer you would be better equipped and have some idea what you are doing.");
		char_give_item(0,206);
		set_flag(1,2,1);
	}
break;

beginstate 20;
	if(get_flag(1,3) < 2){
		reset_dialog_preset_options(0);
		if(get_flag(1,3) == 0){
			add_dialog_str(0,"There is an ampersand scawled on this bit of the wall. It is done in chalk, and looks very recent. Of course with no weather down here, who knows how long a chalk drawing might last?",0);
			add_dialog_str(1,"You could rub out the symbol if you wanted to.",0);
			set_flag(1,3,1);
		}
		else if(get_flag(1,3) == 1){
			clear_buffer();
			append_string("You walk past a chalked ampersand.");
			if(get_flag(1,14)<2)
				append_string(" You have a strange urge to erase it.");
			get_buffer_text(text);
			add_dialog_str(0,text,0);
		}
		add_dialog_choice(0,"Leave it alone");
		add_dialog_choice(1,"Erase it");
		i = run_dialog(1);
		if(i == 2){
			message_dialog("You rub out the symbol.","");
			set_flag(1,3,2);
			inc_flag(10,1,1);
			set_terrain(5,5,0);
			set_terrain(5,25,0);
			if(get_flag(10,1)>=3){
				i = get_current_tick() + get_ran(1,100,150);
				set_flag(10,2,i/256);
				set_flag(10,3,i%256);
			}
		}
	}
	else if((get_flag(1,3)==2) && (char_has_item(0,445))){
		reset_dialog_preset_options(0);
		add_dialog_str(0,"Since you have chalk now, you could restore this ampersand that you erased.",0);
		if(get_flag(1,14)>=2)
			add_dialog_str(1,"Given your suspicions about how these symbols relate to your fading out, you think you'd better draw it back.",0);
		add_dialog_choice(0,"Redraw the ampersand");
		add_dialog_choice(1,"Leave it alone");
		i = run_dialog(1);
		if(i == 1){
			message_dialog("You carefully redraw the ampersand.","");
			set_flag(1,3,1);
			inc_flag(10,1,-1);
			set_terrain(5,5,358);
			set_terrain(5,25,358);
			if(get_flag(10,1)==3)
				message_dialog("You feel a bit more solid now, as though you won't fade out completely. You're still not quite back to normal, though.","");
			else if(get_flag(10,1)==2)
				message_dialog("Now you finally feel fully solid again.","");
		}
	}
break;