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(0,0) == 0) {
		force_instant_terrain_redraw();
		pause(3);
		reset_dialog();
		add_dialog_str(0,"The rest of the Golden Egret looks a lot like it did when you arrived, just a bit more crowded.",0);
		add_dialog_str(1,"You really should leave for the Cathedral of Winds to find out about your quest. Then again, nobody would mind if you grabbed a decent meal before you head out...",0);
		run_dialog(1);
		set_flag(0,0,1);
	}

	add_range_to_group(10,13,1);
	set_name(1001,"Traveler");

	add_range_to_group(8,9,2);
	add_char_to_group(16,2);
	set_name(16,"Soldier");
	set_name(8,"Captain");
	set_name(9,"Soldier");
	set_level(1002,25);

	set_name(7,"Anthony");
	set_level(7,15);
	set_char_dialogue_pic(7,1945,0);
	set_name(14,"Ryan");
	set_char_dialogue_pic(14,1957,0);
	set_name(15,"Alexa");
	set_char_dialogue_pic(15,1960,0);
	set_name(18,"Mayor Rusk");
	set_char_dialogue_pic(18,1961,0);
	set_name(17,"Helen");
	set_char_dialogue_pic(17,1951,0);
	set_name(19,"Johann");
	set_char_dialogue_pic(19,1962,0);
	set_name(21,"Rebecca");
	set_char_dialogue_pic(21,1950,0);
	set_name(20,"Nathan");
	set_char_dialogue_pic(20,1922,0);
	if(get_flag(0,17) >= 3)
		erase_char(20);

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 up. Do you ascend?",0);
	add_dialog_choice(0,"No.");
	add_dialog_choice(1,"Yes.");
	choice = run_dialog(1);
	
	if(choice == 2)
		move_to_new_town(2,12,18);
	else
		block_entry(1);

break;

beginstate 11; //supply closet

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

	force_instant_terrain_redraw();
	pause(3);

	reset_dialog();
	add_dialog_str(0,"This seems to be a supply closet. You doubt that anything here will be of use to you.",0);
	run_dialog(1);

	set_flag(0,28,1);
break;

beginstate 12; //the kitchen

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

	force_instant_terrain_redraw();
	pause(3);

	reset_dialog();
	add_dialog_str(0,"This seems to be the inn's kitchen. Food lies on just about every horizontal surface in the room. Anthony must really have his hands full.",0);
	run_dialog(1);

	set_flag(0,29,1);
break;


beginstate 20; //leave the inn without paying the tab (magicdoor trigger)

	if(get_flag(0,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you try to leave the inn, the doors shut in your face. You look around, trying to figure out what happened, and you just see Anthony, the innkeeper, smiling at you.",0);
		add_dialog_str(1,"_I believe you owe me money,_ he says.",0);
		add_dialog_str(2,"You kind of wish that you knew how he did that.",0);
		run_dialog(1);
		block_entry(1);
		end();
	}
break;

beginstate 21; //leave the inn, for real

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

	reset_dialog();
	add_dialog_str(0,"As you leave the Golden Egret, you get your first really good look at the town of Stratton.",0);
	add_dialog_str(1,"It's quiet. Then again, the majority of towns in Empire lands are peaceful and quiet right up until the point where adventurers show up.",0);
	run_dialog(1);

	set_flag(0,18,1);

break;

beginstate 25; //the fountain

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

	reset_dialog();
	if(get_flag(1,1) == 0) {
		add_dialog_str(0,"This fountain doesn't quite seem normal. It probably has something to do with the fact that the stone from which it was hewn. It actually glows.",0);
		add_dialog_str(1,"You can actually feel the energy radiating off of it. It feels very positive, almost holy.",0);
		}
	else
		add_dialog_str(0,"This fountain looks and feels very similar to what you saw in the cathedral's gardens. Perhaps they were built by the same architect.",0);
	run_dialog(1);

	set_flag(0,19,1);

break;

beginstate 30; //the bazaar

	if(get_flag(0,17) == 4) {
		reset_dialog();
		add_dialog_str(0,"That's odd... Nathan isn't back yet. Maybe he actually did retire off the treasure.",0);
		run_dialog(1);
		set_flag(0,17,5);
		}

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

	reset_dialog();
	add_dialog_str(0,"Inside this building, three merchants have set up shop. It looks a bit crowded, but none of the merchants seem bothered by it.",0);
	run_dialog(1);

	set_flag(0,20,1);

break;

beginstate 35; //the well

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

	reset_dialog();
	add_dialog_str(0,"This is a well, very similar to other wells you've seen in your journeys. It's a stone-lined hole in the ground with water at the bottom.",0);
	add_dialog_str(1,"All in all, it's not very interesting.",0);
	run_dialog(1);

	set_flag(0,21,1);

break;

beginstate 40; //entering Nathan's house (door script trigger)

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


	force_instant_terrain_redraw();
	pause(3);

	reset_dialog();
	add_dialog_str(0,"As you open the door to this house, the first thing you notice is the huge piles of junk everywhere. It seems like there's one of everything in here.",0);
	if(get_flag(0,16) == 1)
		add_dialog_str(1,"This must be Nathan's house.",0);
	else
		add_dialog_str(1,"Whoever owns this house must be a serious packrat.",0);
	run_dialog(1);

	set_flag(0,22,1);

break;

beginstate 41; //breaking into Nathan's room (door script trigger)

	if(get_flag(0,22) >= 2)
		end();

	force_instant_terrain_redraw();
	pause(3);

	reset_dialog();
	add_dialog_str(0,"Huh. For all the effort it took to open that door, this room is fairly nondescript. Just a bed, a battered wooden box, and a basket.",0);
	add_dialog_str(1,"This is a bit of a disappointment.",0);
	run_dialog(1);

	set_flag(0,22,2);

break;

beginstate 42; //the box 'o stuff (specobj trigger)

	if(get_flag(0,22) >= 3)
		end();

	reset_dialog();
	add_dialog_str(0,"You carefully open the box, fearing traps. None go off, leaving you alone with the treasure inside. It's a packrat's dream, with a veritable cornucopia of weird items inside.",0);
	run_dialog(1);

	set_flag(0,22,3);

break;

beginstate 45; //the mayor's room (door trigger)

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

	force_instant_terrain_redraw();
	pause(3);

	reset_dialog();
	add_dialog_str(0,"You open this door, not really expecting to find anything interesting. Instead, you find a tired-looking Empire official at a desk covered in papers.",0);
	add_dialog_str(1,"If you've learned anything in your travels, it's that this man is probably the mayor of Stratton.",0);
	run_dialog(1);

	set_flag(0,23,1);

break;

beginstate 50; //entering Helen's shop

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

	reset_dialog();
	add_dialog_str(0,"Walking into this building, you are immediately hit with a wave of scent. It feels like you're being bludgeoned to death by a large sack of highly fragrant herbs.",0);
	run_dialog(1);

	set_flag(0,24,1);

break;

beginstate 55; //bookshelf in Alexa's house

	reset_dialog();
	if(get_flag(0,25) == 0) {
		add_dialog_str(0,"You skim this bookshelf, hoping to find a scroll tube, or at least an interesting title. All you find is a thick tome labeled _Research Notes_. It's too big and bulky to take it with you.",0);
		set_flag(0,25,1);
		}
	else
		add_dialog_str(1,"The tome of research notes is still here.",0);
	add_dialog_str(1,"Do you read it?",0);
	add_dialog_choice(0,"No.");
	add_dialog_choice(1,"Yes.");
	choice = run_dialog(1);

	if(choice == 2) {
		reset_dialog();	
		add_dialog_str(0,"You flip through the book, which describes a series of magical experiments with amber-preserved insect remains.",0);
		add_dialog_str(1,"It seems that the goal was to magically recreate long-dead insects, but each trial just produced an oversized, sickly-looking lizard.",0);
		add_dialog_str(2,"Nearly every entry in the book is a failure, accompanied by long rants about how the state of magic today. All in all, not very interesting reading.",0);
		run_dialog(1);
		}

break;