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

// 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:
//  2, 4 = crop 1 planted
//  2, 5 =  "" 2 ""
//  2, 6 =  "" 3 ""
//  2, 7 =  "" 4 ""
//  2, 8 =  "" 5 ""
//  2, 11 - conversation flag
//  2, 12 -  " " " " " " " "

begintownscript;

variables;

short choice, x, y, fl, c, d;

body;

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

	set_name(6, "Farmer Wormwood");
	set_char_dialogue_pic(6, 1962, 0);
	set_name(15, "Mayor Don Brate");
	set_char_dialogue_pic(15, 1949, 0);
	set_name(16, "Stan");
	set_char_dialogue_pic(16, 1946, 0);
	set_name(17, "Chester");
	set_char_dialogue_pic(17, 1958, 0);
	set_name(18, "Jesse");
	set_char_dialogue_pic(18, 1954, 0);
	set_name(19, "Jim");
	set_char_dialogue_pic(19, 1960, 0);
	set_name(20, "Zoltan");
	set_char_dialogue_pic(20, 525, 0);
	set_name(21, "Cathy");
	set_char_dialogue_pic(21, 528, 0);
	set_name(24, "Clarke");
	set_char_dialogue_pic(24, 1922, 0);
	set_name(25, "Lynn");
	set_char_dialogue_pic(25, 522, 0);
	set_name(26, "Barbara");
	set_char_dialogue_pic(26, 529, 0);
	set_name(27, "Eddie");
	set_char_dialogue_pic(27, 530, 0);
	set_name(35, "Dave");
	set_char_dialogue_pic(35, 1956, 0);
	set_name(36, "Andi");
	set_char_dialogue_pic(36, 1959, 0);
	set_name(37, "Amos");
	set_char_dialogue_pic(37, 526, 0);
	// non-conversation npc
	set_name(38, "Townswoman");
	set_name(39, "Townsman");
	set_name(40, "Townsman");
	set_name(41, "Townsman");
	set_name(42, "Townswoman");
	set_name(43, "Townsman");
	set_name(44, "Townsman");
	set_name(45, "Townswoman");
	set_name(46, "Townswoman");

	// set up crops (if planted)
	if (get_flag(2, 4) > 0) {
		set_terrain(57, 33, 283);
	}
	if (get_flag(2, 5) > 0) {
		set_terrain(59, 41, 283);
	}
	if (get_flag(2, 6) > 0) {
		set_terrain(60, 41, 283);
	}
	if (get_flag(2, 7) > 0) {
		set_terrain(58, 45, 283);
	}
	if (get_flag(2, 8) > 0) {
		set_terrain(58, 51, 283);
	}
break;

beginstate EXIT_STATE;
	// Always called when the town is left.
	set_flag(2, 10, 0);
break;

beginstate START_STATE;
	if (get_flag(2, 10) == 0) {
		set_flag(2, 10, 1);
		// increment start hint counter...
		if (get_flag(50, 11) < 6) {
			inc_flag(50, 11, 1);
		}
		if ((get_flag(50, 5) == 0) && (get_flag(50, 11) == 5)) {
			// give hint of where to start
			message_dialog("You suddenly hear a voice in your head saying 'Read some books in the library Luke.'", "It fades away saying the same phrase over and over again.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(7, "We will catch you.");
		}
		else {
			text_bubble_on_char(7, "Stay on lawful path.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(8, "Don't commit crimes.");
		}
		else {
			text_bubble_on_char(8, "Respect others.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(9, "Hello.");
		}
		else {
			text_bubble_on_char(9, "We see all.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(10, "Keep on moving.");
		}
		else {
			text_bubble_on_char(10, "Loitering's not allowed.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(11, "Be careful.");
		}
		else {
			text_bubble_on_char(11, "Watch your stuff.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(12, "I see you.");
		}
		else {
			text_bubble_on_char(12, "Howdy.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(13, "Watcha up to?");
		}
		else {
			text_bubble_on_char(13, "Be polite.");
		}
	}
	if (get_ran(1, 0, 100) < 5) {
		if (get_ran(1, 0, 100) < 50) {
			text_bubble_on_char(14, "Hmmmph!");
		}
		else {
			text_bubble_on_char(14, "Move along now.");
		}
	}
	if (get_ran(1, 0, 100) < 3) {
		text_bubble_on_char(17, "Sweet!");
	}
	if (get_ran(1, 0, 100) < 3) {
		text_bubble_on_char(18, "Dude!");
	}
	if (get_ran(1, 0, 100) < 3) {
		text_bubble_on_char(31, "Woof Woof");
	}
	if (get_ran(1, 0, 100) < 4) {
		c = get_ran(1, 32, 34);
		d = get_ran(1, 1, 100);
		if (d < 33) {
			text_bubble_on_char(c, "Cluck Cluck");
		}
		else if (d < 66) {
			text_bubble_on_char(c, "Cock-a-doodle-do");
		}
		else {
			text_bubble_on_char(c, "Squawk");
		}
	}
break;

beginstate 10;
	block_entry(1);
	y = char_loc_y(0);
	move_to_new_town(0, 45, y); // mid = 15
break;

beginstate 11;
	block_entry(1);
	y = char_loc_y(0);
	move_to_new_town(0, 45, y); // mid = 40
break;

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

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

beginstate 14;
	block_entry(1);
	y = char_loc_y(0) + 1;
	move_to_new_town(3, 3, y); // mid = 25
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(0, "A small collection plate sits upon the top of the pedestal.", 0);
	add_dialog_str(1, "A sign at the bottom says simply _Donations._", 0);
	add_dialog_str(2, "Do you:", 0);
	add_dialog_choice(0, "Throw in a few coins (5)");
	add_dialog_choice(1, "Leave");
	choice = run_dialog(1);
	if (choice == 1) {
		if (pay_coins(5) > 0) {
			play_sound(38);
			inc_flag(2, 0, 1);
			if (get_flag(2, 0) == 5) {
				set_flag(2, 0, 0);
				if (get_flag(2, 1) == 0) {
					set_flag(2, 1, 1);
					pause(8);
					play_sound(-9);
					message_dialog("You hear a load click from somewhere in the building.", "You can't tell where it came from.");
					award_party_xp(250, 25);
				}
			}
		}
		else {
			print_str_color("You don't have enough money for the donation.", 1);
		}
	}
break;

beginstate 16;
	if (get_flag(2, 2) == 0) {
		set_flag(2, 2, 1);
		reset_dialog();
		add_dialog_str(0, "Ahead of you are several, large statues and sculptures.", 0);
		add_dialog_str(1, "They appear to have been created from multiple materials.", 0);
		add_dialog_str(2, "Some even appear to be made of gold and embedded with jewels.", 0);
		add_dialog_str(3, "Others appear to be made of stone, possibly painted in bright colors.", 0);
		choice = run_dialog(1);
	}
break;

beginstate 17;
	// statue enabled
	if ((get_flag(2, 3) == 0) && (get_flag(50, 5) > 0)) {
		reset_dialog();
		add_dialog_str(0, "In the base of the statue, you notice a handle protuding from a small, concealed door.", 0);
		add_dialog_str(1, "The book was correct, by 'giving' 5 times, the _Lady of Life_ will 'give' you a reward.", 0);
		add_dialog_str(2, "Do you:", 0);
		add_dialog_choice(0, "Open door");
		add_dialog_choice(1, "Leave");
		choice = run_dialog(1);
		if (choice == 1) {
			set_flag(2, 3, 1);
			message_dialog("You lean over and open the door.", "Hidden in the statue is a bronze key, which you take.");
			change_spec_item(1, 1);
			award_party_xp(250, 25);
		}
	}
break;

beginstate 18;
	if ((get_flag(50, 8) > 0) && (get_flag(2, fl) == 0) && (has_item(318))) {
		// plant crop
		block_entry(1);
		reset_dialog();
		add_dialog_str(0, "You toil in the soil for a period of time to get the crop in.", 0);
		add_dialog_str(1, "You finish with a feeling of a job well done.", 0);
		add_dialog_str(2, "Another piece of the farmers field is now complete.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(0);
		inc_flag(50, 8, 1);
		set_flag(2, fl, 1);
		set_terrain(x, y, 283);
		set_ticks_forward(500);
	}
	else {
		block_entry(0);
	}
break;

beginstate 19;
	x = 57;
	y = 33;
	fl = 4;
	set_state_continue(18);
break;

beginstate 20;
	x = 59;
	y = 41;
	fl = 5;
	set_state_continue(18);
break;

beginstate 21;
	x = 60;
	y = 41;
	fl = 6;
	set_state_continue(18);
break;

beginstate 22;
	x = 58;
	y = 45;
	fl = 7;
	set_state_continue(18);
break;

beginstate 23;
	x = 58;
	y = 51;
	fl = 8;
	set_state_continue(18);
break;

beginstate 24;
	message_dialog("The bookshelves are full of town records and ledgers.", "Not much interesting here.");
break;

beginstate 25;
	message_dialog("The bookshelf is full of personal logs and journals.", "The mayor really does keep detailed notes of everything.");
break;

beginstate 26;
	message_dialog("The bookshelf is full of rental records and tax papers.", "There doesn't seem to be a secret code or anything else here.");
break;

beginstate 27;
	message_dialog("The bookshelf is full of maintenance records for the apartments.", "They must of been built cheap, because they sure need a lot of maintenance.");
break;

beginstate 28;
	if (get_flag(2, 9) == 0) {
		set_flag(2, 9, 1);
		reset_dialog();
		add_dialog_str(0, "The smoke filled parlor doesn't seem to have a lot of patrons in it.", 0);
		add_dialog_str(1, "A table with dice on it is just inside the door with a bored stickman sitting at it.", 0);
		add_dialog_str(2, "There is another table with a man idly shuffling cards in the corner.", 0);
		add_dialog_str(3, "They each beckon you as your eyes meet theirs, showing you the empty chair in front of themselves.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(0);
	}
break;

beginstate 29;
	if (get_flag(2, 13) == 0) {
		set_flag(2, 13, 1);
		reset_dialog();
		add_dialog_str(0, "As your eyes adjust to the light in the museum, you see a pedestal with a collection plate for donations straight in front of you.", 0);
		add_dialog_str(1, "You can see a large room with a lot of statues to the left.", 0);
		add_dialog_str(2, "Interestingly, there don't seem to be any guards around.", 0);
		choice = run_dialog(1);
	}
break;
