begintownscript;

variables;
short choice = 0;
short pc_counter = 0;
short lead_char = 0;

body;

beginstate 0; //INIT_STATE
	set_crime_tolerance(2);
	enable_add_new_chars(1);
	if(get_flag(2,2) == 0) {
		set_ticks_forward(625);
		set_flag(2,2,1);
	}
	set_crime_tolerance(2);
	set_name(6,"Traveler");
	set_name(7,"Traveler");
	set_name(8,"Soldier");
	set_level(6,5);
	set_level(7,5);
	set_level(8,10);
	set_character_pose(8,14);
	force_instant_terrain_redraw();
break;


beginstate 1; //EXIT_STATE

break;


beginstate 2; //START_STATE
	pc_counter = 0;
	while(char_ok(pc_counter) == 0) {
		pc_counter = pc_counter + 1;
		}
	lead_char = pc_counter;

break;

beginstate 10; //stairs

	reset_dialog();
	add_dialog_str(0,"This set of stairs leads down. Do you descend?",0);
	add_dialog_choice(0,"No.");
	add_dialog_choice(1,"Yes.");
	choice = run_dialog(1);
	
	if(choice == 2)
		move_to_new_town(0,12,16);
	else
		block_entry(1);

break;


beginstate 15; //leaving the room (door trigger)

	if(get_flag(2,2) > 1)
		end();

	force_instant_terrain_redraw();
	pause(6);
	reset_dialog();
	add_dialog_str(0,"Refreshed after your long journey, you finally get a good look at the Golden Egret. The floors are well-swept, the carpet is clean, and the cockroaches seem polite.",0);
	add_dialog_str(1,"Now you can go find out why you've been brought here.",0);
	run_dialog(1);
	set_flag(2,2,2);

break;


beginstate 20; //room with passed out soldier (door trigger)

	if(get_flag(2,3) == 1)
		end();

	force_instant_terrain_redraw();
	pause(4);
	reset_dialog();
	add_dialog_str(0,"Hm... that's odd. Somebody's unconscious on the floor of this room, and it looks like a soldier.",0);
	add_dialog_str(1,"Perhaps you should see if he's alive.",0);
	run_dialog(1);
	set_flag(2,3,1);

break;


beginstate 25; //N room, trying to sleep

	//don't even bother if you haven't settled the tab
	if(get_flag(0,1) != 1)
		end();

	//don't even bother if you haven't payed for the room
	if(get_flag(2,4) != 1)
		end();

	reset_dialog();
	add_dialog_str(0,"This room looks very comfortable, and now that you've paid for it, you know you won't be disturbed.",0);
	add_dialog_str(1,"Do you sleep?",0);
	add_dialog_choice(0,"No.");
	add_dialog_choice(1,"Yes.");
	choice = run_dialog(1);
	if(choice == 2) {
		pause(3);
		force_view_center(47,47);
		force_instant_terrain_redraw();
		play_sound(-96);
		pause(15);
		relocate_character(0,11,11);
		relocate_character(1,12,11);
		relocate_character(2,13,11);
		relocate_character(3,14,11);
		force_view_center(11,11);
		block_entry(1);
		force_instant_terrain_redraw();
		message_dialog("You awake after a few hours, refreshed and ready to go kill stuff.","");
		set_flag(2,4,0);
		set_ticks_forward(1000);
		heal_char(1000,300);
		restore_energy_char(1000,150);
	}

break;

beginstate 26; //central room, try to sleep

	//don't even bother if you haven't settled the tab
	if(get_flag(0,1) != 1)
		end();

	
	//don't even bother if you haven't payed for the room
	if(get_flag(2,4) != 1)
		end();

	reset_dialog();
	add_dialog_str(0,"This room looks very comfortable, and now that you've paid for it, you know you won't be disturbed.",0);
	add_dialog_str(1,"Do you sleep?",0);
	add_dialog_choice(0,"No.");
	add_dialog_choice(1,"Yes.");
	choice = run_dialog(1);
	if(choice == 2) {
		pause(3);
		force_view_center(47,47);
		force_instant_terrain_redraw();
		play_sound(-96);
		pause(15);
		relocate_character(0,11,14);
		relocate_character(1,12,14);
		relocate_character(2,13,14);
		relocate_character(3,14,14);
		force_view_center(11,14);
		block_entry(1);
		force_instant_terrain_redraw();
		message_dialog("You awake after a few hours, refreshed and ready to go kill stuff.","");
		set_flag(2,4,0);
		set_ticks_forward(1000);
		heal_char(1000,300);
		restore_energy_char(1000,150);
	}

break;


beginstate 27; //try to sleep in south room

	if(get_flag(0,1) != 1)
		end();

	if(get_flag(2,5) == 1)
		end();

	if(get_flag(2,4) != 1)
		end();

	reset_dialog();
	add_dialog_str(0,"Hm... with the sleeping drunk on the floor, you probably won't be able to sleep in here.",0);
	run_dialog(1);
	set_flag(2,5,1);

break;