begintownscript;

variables;
short emery,beds,pcs,cont,resting,tome,learning,llevel;

body;

beginstate 0;

	set_total_visibility(0);

	pcs = 3;
	cont = 1;
	while(pcs >= 1 && cont > 0){
		beds = (9 - pcs);
		if(party_size() <= pcs){
			set_terrain(beds,6,0);
		}
		else{
			cont = 0;
		}
		pcs = pcs - 1;
	}
	force_instant_terrain_redraw();

	if(get_flag(34,0) == 0){
		reset_dialog();
		add_dialog_str(0,"After recovering from momentary nausea, you take a quick glance at your surroundings.  You seem to be in a bedroom of sorts.",0);
		add_dialog_str(1,"There are enough beds for all of you.  Emery, whoever he is, has likely been expecting you.",0);
		add_dialog_str(2,"The walls around you look odd.  They are made of a simple, smooth substance, but have wires and lights inlaid in various portions.  The effect is slightly unnerving.",0);
		add_dialog_str(3,"You have no idea what the purpose of a structure like this is.  Hopefully, you will get some answers soon.",0);
		emery = run_dialog(1);
		set_flag(34,0,1);
	}

break;

beginstate 1;
break;

beginstate START_STATE;
break;

beginstate 10;

	if(get_flag(34,0) == 1){
		message_dialog("This appears to be a household of some sort.  A household of esoteric decor to be certain, but a residence nevertheless.  Is this where the man calling himself Emery lives, then?","As you look out of some of the windows on the far side of the house, you notice something bizarre.  This house exists in a void of sorts:  There is nothing but darkness beyond its threshold.");
		set_flag(34,0,2);
	}

break;

beginstate 11;

	if(get_flag(34,0) == 2){
		reset_dialog();
		add_dialog_str(0,"As you walk into the main foyer of the household, you see a man sitting idly at a table.  He turns his head to you as you approach and smiles cordially.",0);
		add_dialog_str(1,"He looks well-kempt, but not regal as much as you'd expect.  His garments are loose-fitting, but large enough to fit his physique.",0);
		add_dialog_str(2,"His build is something of an anomaly.  There's plenty of it, but it's not that of a corpulent or muscular human being.  His physical prowess remains ambiguous at best, but his presence and power are undeniable.",0);
		add_dialog_str(3,"He has a sword at his belt.  It is long and thick, and its sheath is covers the shaft, but leaves the hilt exposed.  Put bluntly, it's gargantuan.",0);
		if(party_size() > 1)
			add_dialog_str(4,"The man himself is staring at you politely.  Finally, to break the silence, he says, _Greetings, Specialists.  I believe that we've already met in varying situations._",0);
		if(party_size() == 1)
			add_dialog_str(4,"The man himself is staring at you politely.  Finally, to break the silence, he says, _Greetings, Specialist.  I believe that we've already met in varying situations._",0);
		add_dialog_str(5,"His voice is the same which you heard in your head.  It's also the same as the two shades from the Catacombs.  _Call me Emery J. Bishop.  I believe that we have things to discuss._",0);
		emery = run_dialog(1);
		message_dialog("So.  This is the man of whom you have heard so much about.","He's not particularly intimidating in person.  If anyone can clarify things, he's the one.");
		set_flag(34,0,3);
	}
break;

beginstate 12;

	if(get_flag(70,2) >= 40){
		reset_dialog();
		add_dialog_str(0,"There are enough beds here for all of you.  If you wanted to, you could fall asleep on them.",0);
		add_dialog_choice(0,"Get some rest.");
		add_dialog_choice(1,"Stay awake for a while.");
		resting = run_dialog(0);
		if(resting == 2)
			end();
		message_dialog("You fall asleep the moment your head hits the pillows.","You relax and rest up, and wake up refreshed in the morning.");
		revive_party();
		move_to_new_town(19,13,16);
	}

break;

beginstate 13;

	reset_dialog_preset_options(7);
	tome = run_dialog(0);
	if(tome == 1)
		end();
	if(get_skill_total(42) >= 25){
		message_dialog("This book has plenty of knowledge on how to create and manipulate illusions.  This portion of the book involves creating illusions to damage your foes.","Everyone in your party with a mage spells level high enough can now cast Create Illusions at level ten.");
		learning = 0;
		while(learning < 4){
			if(char_ok(learning) == TRUE){
				if(get_stat(learning,11) >= 6){
			llevel = (10 - get_spell_level(learning,0,8));
			change_spell_level(learning,0,8,llevel);
				}
			}
			learning = learning + 1;
		}
	}
	else{
		message_dialog("You open the book and begin reading.  Unfortunately, you are wholly lost by the techniques used therein.","Perhaps more knowledge of arcane lore would help.");
	}
break;

beginstate 14;

	reset_dialog_preset_options(7);
	tome = run_dialog(0);
	if(tome == 1)
		end();
	if(get_skill_total(42) >= 35){
		message_dialog("This book has plenty of knowledge on how to create and manipulate illusions.  This portion of the book involves creating illusions to coerce foes into fighting for you.","Everyone in your party with a priest spells level high enough can now cast Control Foes at level 6.");
		learning = 0;
		while(learning < 4){
			if(char_ok(learning) == TRUE){
				if(get_stat(learning,12) >= 6){
			llevel = (6 - get_spell_level(learning,1,14));
			change_spell_level(learning,1,14,llevel);
				}
			}
			learning = learning + 1;
		}
	}
	else{
		message_dialog("You open the book and begin reading.  Unfortunately, you are wholly lost by the techniques used therein.","Perhaps more knowledge of arcane lore would help.");
	}
break;