// TOWN SCRIPT
//    Town 3: Pergamos - Part 3

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
// 3, 5 = solved Apollyon's puzzle
// 3, 6 = puzzle counter
// 3, 7 = count to wait before asking next riddle if missed
// 3, 9 = conv flag
// 3, 10 = conv flag

begintownscript;

variables;

short choice, i, y;
string mline;

body;

beginstate INIT_STATE;
	turn_off_training(1);
	set_crime_tolerance(3);

	set_name(8, "Laurie");
	set_char_dialogue_pic(8, 1947, 0);
	set_name(9, "Nancy");
	set_char_dialogue_pic(9, 523, 0);
	set_name(10, "Apollyon");
	set_char_dialogue_pic(10, 527, 0);
	set_name(11, "Julie");
	set_char_dialogue_pic(11, 520, 0);
	set_name(15, "Phil");
	set_char_dialogue_pic(15, 1957, 0);
	set_name(17, "Wren");
	set_char_dialogue_pic(17, 524, 0);

	// non-conversation npcs
	set_name(18, "Townsman");

	// setup (secret) door, if open
	if (get_flag(50, 4) > 0) {
		set_terrain(22, 16, 21);
	}

	// make it so the party is blocked in Apollyon's place
	change_blocked(27, 15, 1);
	change_blocked(27, 16, 1);
	change_blocked(27, 17, 1);
break;

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

beginstate START_STATE;
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(6, "Do not steal.");
		}
		else {
			text_bubble_on_char(6, "We'll see if you do.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(7, "Be careful.");
		}
		else {
			text_bubble_on_char(7, "Be safe.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		i = get_ran(1, 0, 100);
		if (i  < 33) {
			text_bubble_on_char(8, "Keep it down!");
		}
		else if (i < 66) {
			text_bubble_on_char(8, "Be quiet!");
		}
		else {
			text_bubble_on_char(8, "Shhh!");
		}
	}
	if (get_ran(1, 0, 100) < 3) {
		text_bubble_on_char(9, "Visitors must sign in.");
	}

	// one timer
	if ((get_flag(3, 1) == 0) && (get_flag(50, 10) > 0)) {
		set_flag(3, 1, 1);
		reset_dialog();
		add_dialog_str(0, "Blowing ahead of you on the ground, is a sheet a paper with some words inked on it.", 0);
		add_dialog_str(1, "You pick it up, curious.  It's a note and the note reads:", 0);
		add_dialog_str(2, "Between two stones lies the door, starting the path to home.", 10);
		add_dialog_str(3, "Somehow it seems important to you.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(1);
	}
break;

beginstate 10;
	block_entry(1);
	y = char_loc_y(0) - 1;
	move_to_new_town(2, 61, y); // mid = 25
break;

beginstate 11;
	teleport_party(6, 45, 1);
break;

beginstate 12;
	block_entry(1);
	move_to_new_town(1, 61, 61);
break;

beginstate 13;
	turn_off_training(0);
break;

beginstate 14;
	turn_off_training(1);
break;

beginstate 15;
	block_entry(1);
	move_to_new_town(4, 26, 2);
break;

beginstate 16;
	// set_flag(50, 1, 1);
	set_state_continue(11);
break;

beginstate 17;
	if ((get_flag(100, 0) > 0) && (get_flag(3, 0) == 0)) {
		// naked - not allowed in library
		block_entry(1);
		play_sound(41);
		reset_dialog();
		add_dialog_str(0, "The librarian stops you from entering.", 0);
		add_dialog_str(1, "_You must put on some clothes to enter here._ she says.", 0);
		add_dialog_str(2, "You can see other patrons chuckling at your nakedness behind her.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(0);
	}
	else {
		block_entry(0);
		set_flag(3, 0, 1);
	}
break;

beginstate 18;
	// allows for removing clothes within library...
	set_flag(3, 0, 0);
break;

beginstate 19;
	message_dialog("The bookshelves are full of books on self help.", "You leaf through a few and pick up some good hints.");
break;

beginstate 20;
	message_dialog("The bookshelves are full of books on home repair.", "You don't have home, so the books aren't much help.");
break;

beginstate 21;
	message_dialog("The bookshelves are full of adventure stories.", "Some seem pretty exciting, but you have no time to read them.");
break;

beginstate 22;
	message_dialog("The bookshelves are full of romance novels.", "Somehow, you know the stories won't match the cover art.");
break;

beginstate 23;
	message_dialog("The bookshelves are full of history texts.", "You can learn a lot about the area with more time.");
break;

beginstate 24;
	message_dialog("The bookshelves are full of science volumes.", "Something good to read just before bed.");
break;

beginstate 25;
	if (get_flag(3, 2) == 0) {
		clear_buffer();
		if (get_flag(3, 3) > 0)
			append_string("Nancy ");
		else
			append_string("The receptionist ");
		append_string("calls you back before you can step behind the counter.");
		get_buffer_text(mline);
		play_sound(162);
		message_dialog(mline, "'All visitors must sign in first before entering.' she says.");
		block_entry(1);
	}
	else {
		block_entry(0);
	}
break;

beginstate 26;
	if (get_flag(3, 2) > 0) {
		clear_buffer();
		if (get_flag(3, 3) > 0)
			append_string("Nancy ");
		else
			append_string("The receptionist ");
		append_string("calls you back before you can step out the door.");
		get_buffer_text(mline);
		play_sound(162);
		message_dialog(mline, "'All visitors must sign out when leaving.' she says.");
		block_entry(1);
	}
	else {
		set_flag(3, 4, 0);
		block_entry(0);
	}
break;

beginstate 27;
	if ((get_flag(100, 0) > 0) && (get_flag(3, 4) == 0)) {
		// naked - not allowed in school
		clear_buffer();
		if (get_flag(3, 3) > 0)
			append_string("Nancy ");
		else
			append_string("The receptionist ");
		append_string("stops you before you can enter the door.");
		get_buffer_text(mline);
		play_sound(162);
		message_dialog(mline, "'You must put on clothes before entering.' she says angrily.");
		block_entry(1);
	}
	else {
		set_flag(3, 4, 1);
		block_entry(0);
	}
break;

beginstate 28;
	if (get_flag(3, 7) > 0) {
		inc_flag(3, 7, -1);
	}
	if (get_flag(3, 5) == 0) {
		block_entry(1);
		reset_dialog();
		add_dialog_str(0, "You can't seem to go through the door.  Something is holding you back.", 0);
		add_dialog_str(1, "In the room in front of you, you see a shadowy figure standing between two pillars.", 0);
		add_dialog_str(2, "He fixes a cold, unblinking stare at you, freezing you to the bone.", 0);
		if (get_flag(3, 7) == 0) {
			add_dialog_str(3, "'Speak to me when you are ready to proceed.' the man intones.", 0);
		}
		else {
			add_dialog_str(3, "He doesn't seem to be ready to speak to you yet, perhaps you should come back later.", 0);
		}
		add_dialog_choice(0, "Ok");
		choice = run_dialog(1);
	}
	else {
		block_entry(0);
		if (get_flag(3, 8) == 0) {
			set_flag(3, 8, 1);
			message_dialog("Apollyon stands mute as you walk by him.", "You are glad his cold stare is straight ahead, and not directed at you.");
		}
	}
break;

beginstate 29;
	set_flag(50, 4, 0);
	set_terrain(22, 16, 5);
break;
