// TOWN DIALOGUE SCRIPT
//    Town 3: Tower of Magi

begintalkscript;

variables;

short i,j,k,r1,choice;


begintalknode;
	tag = 1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The guards of the Tower of Magi are not wizards. They are elite soldiers chosen for the ability to hang out around weird wizards and their creations for long periods of time without totally freaking out.";
	text2 = "They are eager to speak with a normal soldier. You trade stories for a while. They are flatteringly amazed by your travels in vahnatai lands.";
	text3 = "They are eager to speak with you until they realize that you have Magi Clearance. This makes you just another eccentric oddball in their eyes. You chat for a bit, but it's awkward.";
	code =
		if (has_spec_item(25))
			rs(2);
			else rs(3);
	break;
	
begintalknode;
	tag = 7;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "You flip through the book. It is very well worn, as if it's been carried a long way. The recipes inside are written in code, so that you can't steal Pygryn's alchemical knowledge. The ingredients are, however, plain to read:";
	text2 = "  Healing Elixir - Graymold, Healing Herbs.";
	text3 = "  Curing Elixir - Graymold, Healing Herbs.";
	text4 = "  Energy Elixir - Graymold, Healing Herbs, Energetic Herbs.";
	text5 = "  Armor Elixir - Graymold, Spiritual Herbs, Energetic Herbs.";
	
// Vincent

begintalknode;
	tag = 10;
	state = -1;
	nextstate = 1;
	question = "Vincent";
	text1 = "There is a wrinkled, wiry human sitting behind the counter. He deftly and effortlessly mixes a variety of bubbling, hissing concoctions. _Welcome to my shop. Call me Vincent._";
	text5 = "Vincent continues to work on his potions. He occasionally shoots you a glance, watching carefully in case you express an interest in buying something.";
	action = INTRO;

begintalknode;
	state = 1;
	nextstate = 2;
	question = "_What are you cooking?_";
	text1 = "_Oh, well, I prepare and sell scrolls and potions. You can buy some, if you want!_";

begintalknode;
	state = 2;
	nextstate = 3;
	question = "_Is it difficult work?_";
	text1 = "_Tricky mostly, but the mages here can't get enough of my work! When an experiment goes wrong, it's my healing potions that help cure the horrible, agonizing damage._";
	text2 = "He sighs. _It can be difficult to get ingredients, though._";

begintalknode;
	state = 3;
	nextstate = -1;
	condition = gf(3,14) <= 1;
	question = "_Any way I can help?_";
	text1 = "_I suppose. Most of the ingredients I can find by myself. However, I really could use a black drake fang. Some rare drakes in the northern islands occasionally grow a single tooth of a material like onyx. Bring one to me, and I can help you in return._";
	action = SET_SDF 3 14 1;
	code =
		toggle_quest(12,1);
	break;
	
begintalknode;
	state = 1;
	nextstate = -1;
	question = "_Can I purchase some of your wares?_";
	text1 = "You conclude your business.";
	code =
		begin_shop_mode("Vincent's Potions","The Tower of Magi is one of Avernum's key sources of quality potions.",38,3,3);
	break;

	
begintalknode;
	state = 1;
	nextstate = -1;
	condition = gf(3,14) == 1 && has_spec_item(27) > 0;
	question = "_I have a black drake fang for you._ (Give it to him.)";
	code =
	run_hardcode(18);
	break;
	
begintalknode;
	state = 1;
	nextstate = -1;
	condition = 1;
	question = "_Can you make custom potions for me?_";
	text1 = "_I am too busy, but Pygryn can help._ He points at the other woman in the workshop.";

begintalknode;
	state = 1;
	nextstate = -1;
	condition = 1;
	question = "_I don't need any potions._";
	text1 = "_And I hope you keep not needing them in the future!_";
	action = END_TALK;
	
// Pygryn

begintalknode;
	tag = 30;
	state = -1;
	nextstate = 28;
	question = "Pygryn";
	text1 = "A large woman with close-cropped hair and a confident mien sits behind the counter. Books are stacked on either side of her, and a set of well-used alchemical equipment is close to hand.";
	text2 = "_I am Pygryn the sage._ She gives you an imperious look. _My skills are considerable, and I will put them at your disposal._";
	text5 = "Pygryn continues to work on her alchemy, chopping herbs and consulting crumbling grimoires.";
	action = INTRO;

begintalknode;
	state = 28;
	nextstate = 29;
	question = "_Exactly what services do you offer?_";
	text1 = "She makes a small grunting noise, annoyed by the interruption. _I sell knowledge._";

begintalknode;
	state = 29;
	nextstate = -1;
	question = "_What sort of knowledge do you sell?_";
	text1 = "_The way to create powerful potions, put at your disposal. You must provide the ingredients, of course. My time is valuable._";

begintalknode;
	state = 28;
	nextstate = 30;
	question = "_Can you make a potion for me?_";
	text1 = "_This is my purpose. The book in the corner will tell you the ingredients I need._";


begintalknode ;
	state = 30;
	nextstate = -1;
	condition = party_has_item(289) && party_has_item(292);
	question = "_Can you make a Healing Elixir for me?_ (Give graymold and healing herbs.)";
	text1 = "Pygryn smiles. _It will not be a challenge._";
	text2 = "She takes the herbs and nervously begins her chopping, boiling, and straining. She works slowly, and drops of sweat prick out on her forehead.";
	text3 = "This effort results in eventual success. She presents a clay jug to you, stoppered with wax. _Healing Elixir! I hope it has the desired effect._";
	action = REUSABLE;
	code = 
		inc_flag(190,7,1);
		take_num_of_item(289,1);
		take_num_of_item(292,1);
		reward_give(226);
		play_sound(22);
	break;

begintalknode ;
	state = 30;
	nextstate = -1;
	condition = party_has_item(289) && party_has_item(292);
	question = "_Can you make a Curing Elixir for me?_ (Give graymold and healing herbs.)";
	text1 = "Pygryn smiles. _It will not be a challenge._";
	text2 = "She takes the herbs and nervously begins her chopping, boiling, and straining. She works slowly, and drops of sweat prick out on her forehead.";
	text3 = "This effort results in eventual success. She presents a clay jug to you, stoppered with wax. _Curing Elixir! I hope it has the desired effect._";
	action = REUSABLE;
	code = 
		inc_flag(190,7,1);
		take_num_of_item(289,1);
		take_num_of_item(292,1);
		reward_give(227);
		play_sound(22);
	break;	
	
begintalknode ;
	state = 30;
	nextstate = -1;
	condition = party_has_item(289) && party_has_item(291) && party_has_item(292);
	question = "_Can you make an Energy Elixir for me?_ (Give graymold, healing herbs, and energetic herbs.)";
	text1 = "Pygryn smiles weakly. _Concentrating that much power in a flask is a challenge, I admit. Happily, I am up to the task._";
	text2 = "She takes the herbs and nervously begins her chopping, boiling, and straining. She works slowly, and drops of sweat prick out on her forehead.";
	text3 = "This effort eventually results in success. She presents a clay jug to you, stoppered with wax. _Energy Elixir! I hope it has the desired effect._";
	action = REUSABLE;
	code = 
		inc_flag(190,7,1);
		take_num_of_item(289,1);
		take_num_of_item(291,1);
		take_num_of_item(292,1);
		reward_give(229);
		play_sound(22);
	break;

begintalknode ;
	state = 30;
	nextstate = -1;
	condition = party_has_item(290) && party_has_item(291) && party_has_item(292);
	question = "_Can you make an Armor Elixir for me?_ (Give graymold, spiritual herbs, and energetic herbs.)";
	text1 = "Pygryn smiles weakly. _Concentrating that much power in a flask is a challenge, I admit. Happily, I am up to the task._";
	text2 = "She takes the herbs and nervously begins her chopping, boiling, and straining. She works slowly, and drops of sweat prick out on her forehead.";
	text3 = "This effort eventually results in success. She presents a clay jug to you, stoppered with wax. _Armor Elixir! I hope it has the desired effect._";
	action = REUSABLE;
	code = 
		inc_flag(190,7,1);
		take_num_of_item(290,1);
		take_num_of_item(291,1);
		take_num_of_item(292,1);
		reward_give(230);
		play_sound(22);
	break;

begintalknode ;
	state = 30;
	nextstate = 7;
	condition = 1;
	question = "_I don't need any potions._";
	text1 = "_All right. I had better return to my standing orders, then._ She turns back to a small, bubbling pot. It starts to boil over, but a quick adjustment prevents an explosive disaster.";
	action = END_TALK;
	

// Brantford

begintalknode;
	tag = 50;
	state = -1;
	nextstate = 55;
	question = "Brantford";
	text1 = "You must lean over and look between the counters to find the shop's proprietor. He's back there all right, a tiny gnome of a mage, lost among piles of items, both treasures and worthless knick-knacks.";
	text2 = "When he sees you, he walks out and grins at you. _I'm Brantford. Let me know if I can help you with anything._";
	text5 = "Brantford watches you cannily, ready to swoop in when you show the slightest interest in spending money. The dust from all this junk makes you sneeze constantly.";
	action = INTRO;

begintalknode;
	state = 55;
	nextstate = 56;
	question = "_Exactly what do you do?_";
	text1 = "_I deal in miscellany! Bric-a-brac of all descriptions. My stock changes every day, every minute even! You can purchase something you like, or sell me something you don't! You have but to ask._";

begintalknode;
	state = 56;
	nextstate = -1;
	question = "_Is there much call for stuff around here?_";
	text1 = "_Down in Avernum, quality equipment is hard to find. Or any equipment at all._";
	text2 = "_That's why people come to me. I have a good eye for junk! I'll pay a fair price for any of your goods. If you know what it is, that is._";


begintalknode;
	state = 55;
	nextstate = -1;
	question = "_Let's do some trading._";
	text1 = "You conclude your business.";
	code =
		begin_shop_mode("Brantford's Junk","Brantford collects objects and then sells them. Most of his stock is utterly useless. And gross.",39,3,3);
	break;

begintalknode;
	state = 55;
	nextstate = -1;
	condition = 1;
	question = "_I would like to sell something._";
	text1 = "You conclude your business.";	
	code = 
		begin_sell_mode();
	break;

begintalknode;
	state = 55;
	nextstate = -1;
	condition = 1;
	question = "_I don't need anything._";
	text1 = "_All right. Come back if you have anything to sell. I'll buy anything! Even if it's terrible!_";
	action = END_TALK;
	
// Mother Clarisse

begintalknode;
	tag = 70;
	state = -1;
	nextstate = 82;
	question = "Mother Clarisse";
	text1 = "You meet an elderly woman in clean, elegant robes. Snowy white hair flows down her back. She wanders around the temple, seemingly hearing divine voices you can't begin to detect.";
	text2 = "She turns to you. _Welcome to the Temple of the Path of the True Way, child. I am Mother Clarisse._";
	text5 = "Mother Clarisse tends to you. She asks questions about your travels, watching for a way that she can help you.";
	action = INTRO;

begintalknode;
	state = 82;
	nextstate = 83;
	question = "_Tell me about this fine temple._";
	text1 = "She shakes her head sadly. _I watch over this beautiful temple while its younger guardians fight the war. Don't fear. I can give you the same education. I would just prefer to take part in more quiet contemplation._";

begintalknode;
	state = 83;
	nextstate = -1;
	question = "_Contemplating what?_";
	text1 = "_When the Empire threw me down here, I thought I would waste away the rest of my years in boredom and squalor. Instead, I began to learn, and fight. It is tiring and painful, but I don't mind somehow._";
	text2 = "_But I swear to you, before I die, I would give anything to live in quiet times._";
	
begintalknode;
	state = 82;
	nextstate = 84;
	condition = 1;
	question = "_The Path of the True Way?_";
	text1 = "_Yes. We are those who seek to reach the True Way. Beyond this world, beyond what we know. We wish to reach beyond and learn the secrets of those who dwell there._";


begintalknode;
	state = 84;
	nextstate = -1;
	condition = 1;
	question = "_Those who dwell there? You mean demons?_";
	text1 = "_No. I mean, yes, demons are out there, but we seek their opposite, those who offer kindness and wisdom._";
	text2 = "_We have never found them. We just keep finding more demons. But we are ever-seeking._";
	
begintalknode;
	state = 84;
	nextstate = 85;
	condition = 1;
	question = "_Are there others in the tower who tread that path?_";
	text1 = "She frowns. _Too few. The wizards are always looking for ways to subdue dark powers. King Micah wants me here, to try to guide them onto a wiser path._";
	text2 = "_In that way, we have been failures._";

begintalknode;
	state = 85;
	nextstate = -1;
	condition = 1;
	question = "_Tell me more._";
	text1 = "_Recently, the Archmage Linda, of the Triad, called an infernal of great power to this place. It was only repelled with the aid of several brave adventurers. Since then, we have doubled our efforts to curb the enthusiasm of the wizards._";
	
begintalknode;
	state = 82;
	nextstate = -1;
	question = "_Can you teach me any rituals?_";
	text1 = "You conclude your business.";
	code =
		begin_shop_mode("Clarisse's Spells","Clarisse will share with you a series of powerful rituals, all provided for the defense of Avernum.",40,5,3);
	break;

begintalknode;
	state = 82;
	nextstate = -1;
	condition = gf(41,14) > 0 && dread_curse(0) == 0;
	question = "_Do you know how to heal people who are suffering a terrible curse?_";
	text1 = "_Yes, I can. Even when it is deserved, I strongly dislike curses. I think they are unjust, and too easy to misuse. Fortunately, I see that you have no such curse. I am pleased._";

begintalknode;
	state = 82;
	nextstate = 87;
	condition = dread_curse(0) > 0;
	question = "_Do you know how to heal people who are suffering a terrible curse?_";
	text1 = "_Yes, I can. Even when it is deserved, I strongly dislike curses. I think they are unjust, and too easy to misuse._ She looks at you closely, sighs, and shakes her head. _I see that you have such a curse. I hope you are guilty of no wrongdoing._";
	text2 = "_The ritual is very involved. It requires rare, expensive components. I will need 1000 coins and a mandrake root._";
	
begintalknode;
	state = 87;
	nextstate = 82;
	condition = 1;
	question = "_I can't afford that._";
	text1 = "_Then you must experience justice for a longer time._";
	
begintalknode;
	state = 87;
	nextstate = 82;
	condition = party_has_item(293) && coins_amount() >= 500;
	question = "_All right._ Give root and money.";
	text1 = "She takes the components and begins to cast a very long, powerful, draining spell.";
	text2 = "You feel faint. You almost fall over. Then, sweat beading on her face, she completes the spell. You feel the weight of the curse lifted from you, but you feel very drained.";
	code =
		dread_curse(1);
		take_item(293);
		change_coins(-500);
	break;
	
begintalknode;
	state = 82;
	nextstate = 86;
	condition = gf(41,15) == 1 && gf(41,14) == 0;
	question = "_I'm trying to figure out how to remove a Dread Curse. Do you know?_";
	text1 = "She sighs. _Yes, I know how to remove a Dread Curse, though, to be honest, I have found that such curses are more often deserved than not._ (You take note of this.)";
	action = SET_SDF 41 14 1;

begintalknode;
	state = 86;
	nextstate = -1;
	condition = 1;
	question = "_Can you teach me how to do it?_";
	text1 = "_First, you must spend decades in a condition of ascetic purity. No offense, but you are not there yet. You follow a valid, different path._";
	
begintalknode;
	state = 82;
	nextstate = -1;
	condition = 1;
	question = "_I need to go._";
	text1 = "_Of course. May you always travel the True Way._";
	action = END_TALK;
	
// X

begintalknode;
	tag = 90;
	state = -1;
	nextstate = 109;
	question = "X";
	text1 = "There is a highly deranged and disconnected man sitting at this desk. Fortunately, he doesn't seem very dangerous. At the moment.";
	text2 = "He's clearly a wizard of the tower, and his robes are a rich, deep purple. You ask his name. He says, _X._ His voice is soft and distracted.";
	text5 = "X sits at the end of the table, lost in thought. Occasionally, he emits a crazy little laugh. He must be a very powerful wizard. He's clearly crazy enough.";
	action = INTRO;

begintalknode;
	state = 109;
	nextstate = 110;
	question = "_Excuse me. What are you researching?_";
	text1 = "He looks around, as if looking for spies. Then he turns to you. _I'm looking for a spell that will drop an anvil on someone far away. I'd have it by now, if the Triad didn't keep pulling me away._";

begintalknode;
	state = 110;
	nextstate = -1;
	question = "_What is the Triad?_";
	text1 = "_There are three of us who run the tower. And we try to do it as little as possible. Now go away!_";
	
begintalknode;
	state = 110;
	nextstate = 111;
	question = "_Dropping anvils on people. Sounds useful._";
	text1 = "_I'm still working on it. I may be able to get it someday. Very useful for hurting the Empire. And people I don't like._ He gets angry. _But I keep getting distracted. I keep having to teach people! It's frustrating!_";

begintalknode;
	state = 111;
	nextstate = -1;
	question = "_Teaching can be difficult, I suppose._";
	text1 = "He starts twitching horribly. _It's enough to make me want to disintegrate somebody!_ He calms down. _Don't worry. Not you. Just everyone else._";

begintalknode;
	state = 111;
	nextstate = 109;
	question = "_What spells do you teach?_";
	text1 = "He looks at you angrily. _People want to buy spells all the time! I teach them, for the good of Avernum, but damn! It gets to where I have to hide back here to get any work done. You don't want to purchase spells, do you?_";
	text2 = "He has a neurotic gleam in his eye.";
	action = SET_SDF 4 28 1;

begintalknode;
	state = 109;
	nextstate = 112;
	condition = 1;
	question = "_Do you fight for Avernum?_";
	text1 = "_No, but I teach those who do. It is convenient to do so. You keep enemies far from me._";

begintalknode;
	state = 112;
	nextstate = -1;
	condition = 1;
	question = "_Enemies?_";
	text1 = "_Garzahd, and the other pitiful, jealous, subservient mages of the Empire._";

begintalknode;
	state = 112;
	nextstate = -1;
	condition = 1;
	question = "_What will you do if the enemies reach you?_";
	text1 = "_I don't know. Probably disappear and never be seen again._";
	
begintalknode;
	state = 109;
	nextstate = -1;
	condition = gf(4,28) > 0 && has_spec_item(25) == 0;
	question = "_If you don't mind too much, I want to learn a few spells._";
	text1 = "'X' starts to respond, but then something occurs to him. _You have Magi Clearance, don't you? Some bureaucratic nonsense?_ You say that you don't. _Oh. You should go to The Castle and get that._";
	text2 = "_I don't care, of course, but if I help you without it, people will come and annoy me._";
	
begintalknode;
	state = 109;
	nextstate = -1;
	condition = gf(4,28) > 0 && has_spec_item(25) > 0;
	question = "_If you don't mind too much, I want to learn a few spells._";
	text1 = "You conclude your business.";
	code =
		begin_shop_mode("'X' ","'X' is crazy, but he knows many effective spells.",41,6,3);
	break;
	
begintalknode;
	state = 109;
	nextstate = -1;
	condition = 1;
	question = "_I'll be going now._";
	text1 = "He mutters, _I can't miss you if you won't go away._";
	action = END_TALK;

// Kayannan

begintalknode;
	tag = 110;
	state = -1;
	nextstate = 136;
	question = "Kayannan";
	text1 = "You meet a young, heavily-built woman in mage's robes. She carries around a cavewood staff with iron caps. From the way she holds it, you guess that it's more to hit people than for physical support.";
	text2 = "She introduces herself. _I'm Kayannan. I am an instructor of the Tower of Magi._";
	text5 = "Kayannan taps her staff impatiently against her foot while she waits for you to say something else. _I am happy to help soldiers, but I do have classes to teach._";
	action = INTRO;

begintalknode;
	state = 136;
	nextstate = 137;
	question = "_Nice staff. Do you work in the Tower?_";
	text1 = "_Thanks, I never go anywhere without it. I'm a teacher here. I should be at the front, but there you go._";

begintalknode;
	state = 137;
	nextstate = 136;
	question = "_What are you teaching?_";
	text1 = "_I drill the youngsters in spells as fast as I can, so they can go fight. I also teach magery to those with the money to buy the knowledge._";

begintalknode;
	state = 137;
	nextstate = -1;
	question = "_What's the situation at the front?_";
	text1 = "_The Empire has no shortage of mages. I'm working day and night to help even the numbers out. But sometimes, I do wish I could go fight!_";

begintalknode;
	state = 136;
	nextstate = 138;
	question = "_How does one become a full-time student here?_";
	text1 = "_One must show magical aptitude at an early age. And, of course, survive the manifestations of that aptitude._";
	text2 = "_Very similar to the Empire, and yet very different._";
	
begintalknode;
	state = 138;
	nextstate = -1;
	condition = 1;
	question = "_How is it different?_";
	text1 = "_The surface only allows one to learn magic after a long period of proving loyalty to the Empire. Learning magic in secret results in banishment to Avernum. That is how I came to be here._";

begintalknode;
	state = 136;
	nextstate = -1;
	question = "_Can you teach me any spells?_";
	text1 = "You conclude your business.";
	code =
		begin_shop_mode("Kayannan's Spells","Kayannan can teach a host of efficient, mid-tier spells.",42,4,3);
	break;

begintalknode;
	state = 136;
	nextstate = -1;
	condition = 1;
	question = "_I don't need anything._";
	text1 = "She nods, smiles, and rushes off to teach a class.";
	action = END_TALK;
	
// Vidrain

begintalknode;
	tag = 130;
	state = -1;
	nextstate = 163;
	question = "Vidrain";
	text1 = "You startle an aging magic user, lost in thought. He looks very relieved when he sees you aren't about to kill him. You ask his name. He says, in a weak voice, _Vidrain. Maintainer of the portal._";
	text5 = "Vidrain paces around, lost in thought. He must do a lot of his magical thinking while wandering aimlessly. Sometimes, he mutters, _The portal. So unstable._";
	action = INTRO;

begintalknode;
	state = 163;
	nextstate = 164;
	question = "_Sorry I startled you._";
	text1 = "_Just being jumpy. At the moment._";

begintalknode;
	state = 164;
	nextstate = 165;
	question = "_Why are you jumpy?_";
	text1 = "He seems to be only half there. _Being near the portal does that to you, I'm afraid. And then there're the demons._";

begintalknode;
	state = 165;
	nextstate = -1;
	question = "_Demons? Where?_";
	text1 = "_After the portal was up for a while, a few demons came through it. They're in there now, and we don't have the strength here at the moment to flush them out. Nothing we can do until we get it._";
	text3 = "_Well, you wiped out the first bunch of demons, and thank you very much. But there will be more, and someday all the wards won't hold them in!_";
	action = DEP_ON_SDF 3 9 0;

begintalknode;
	state = 163;
	nextstate = 166;
	question = "_Tell me about the portal._";
	text1 = "_Hmm. I suppose you have the clearance to know. We have a controllable teleporter! It could be a huge weapon against the Empire. We could send attackers anywhere down here, and maybe even on the surface._ ";
	text2 = "_Unfortunately, it's not happening yet, because using it is tricky._";

begintalknode;
	state = 166;
	nextstate = 167;
	question = "_What makes the teleporter tricky to use?_";
	text1 = "He twitches. _It works off coordinates, but the coordinates are hard to calculate. You call them out when you step in and you get sent somewhere. But figuring out what to call so you don't end up in solid rock is hard!_";
	
begintalknode;
	state = 167;
	nextstate = -1;
	question = "_Have you calculated any coordinates yet?_";
	text1 = "_We know a few of them, but not enough to do much at the moment. The coordinates are three syllables, each three letters long._";

begintalknode;
	state = 167;
	nextstate = -1;
	question = "_How can I control the portal?_";
	text1 = "_Find coordinates. The sets of letters. In a place where we have found them, we write them on pillars. We have done this in most of the large towns. Look around for the obelisks._";
	
begintalknode;
	state = 163;
	nextstate = 168;
	condition = has_spec_item(25) == 0;
	question = "_Can I use the portal?_";
	text1 = "_Not yet. You need to get Magi Clearance first. It is a requirement of the Crown._";
	code =
		toggle_quest(119,1);
	break;
	
begintalknode;
	state = 168;
	nextstate = -1;
	condition = 1;
	question = "_How do I do that?_";
	text1 = "_Travel west to The Castle. Find the official you apply to for better clearance. I think, based on what you have been through, they will be happy to help._";
	
begintalknode;
	state = 163;
	nextstate = -1;
	condition = has_spec_item(25) > 0;
	question = "_Can I start to use the portal?_";
	text1 = "_Yes. Go to the core of the Tower of Magi. Step within while saying the desired coordinates. Hopefully, you will survive._";
	code =
		sf(190,2,1);
	break;
	
// Mahdavi

begintalknode;
	tag = 150;
	state = -1;
	nextstate = 190;
	question = "Mahdavi";
	text1 = "You meet a short woman with dark skin and a radiant smile, sitting at a desk heaped with scrolls, records, and letters from The Castle. Her raven black hair disappears into a rich, purple velvet robe.";
	text2 = "She stands to greet you. _I am Mahdavi, of the Triad. It's good to have skilled soldiers here. It is particularly important to have you here. There is much that needs to be done._";
	text5 = "Mahdavi looks at you attentively. She is very pleased to have soldiers here. _What else do you need?_";
	text6 = "_Great works still need to be done, if Avernum is to survive._";
	text7 = "_You have done much for us, and I will help you however I can._";
	action = INTRO;
	code =
		if (gf(8,3) < 4)
			rs(7);
			else rs(6);
	break;
	
begintalknode;
	state = 190;
	nextstate = 191;
	question = "_What do you do here in the Tower?_";
	text1 = "_My Triad responsibilities, in part. I am a member of the Triad. Solberg, X, and I are the three wizards in charge of the Tower of Magi. Currently, I am pondering a great threat to Avernum._";
	text3 = "_My Triad responsibilities, in part. I am a member of the Triad. Solberg, X, and I are in charge of this tower. Now that you have destroyed the portal, I can concentrate on the battle against the Empire. It is a great relief._";
	action = DEP_ON_SDF 3 8 3;

begintalknode;
	state = 191;
	nextstate = 192;
	question = "_Where are the other Triad members?_";
	text1 = "_Solberg is long absent. Since I am sure that you are loyal to Avernum, I feel safe telling you that he lives in a tower in northeast Avernum._";
	text2 = "_As for X, well, he is a strange fellow. He is hiding out in one of the libraries in the tower. He tends to avoid students._";

begintalknode;
	state = 192;
	nextstate = -1;
	question = "_Why is Solberg so far away?_";
	text1 = "_Some years ago, a demon took up residence here. Brave adventurers helped us dispatch it. Solberg hid from it in his tower, southwest of Formello. Once the demon was gone, he tried to return, but Empire assassins trapped him there._";
	text2 = "_I wish he was here. We could all use his wisdom._";

begintalknode;
	state = 190;
	nextstate = 193;
	condition = gf(3,8) <= 3;
	question = "_What needs to be done?_";
	text1 = "Mahdavi tries to look calm, but you can see the concern in her eyes. _The Empire has not destroyed Avernum for one reason: it takes great energy to teleport its raiders down here. The invasion has been slow, but their leader Garzahd has a plan to speed it up._";
	text2 = "_We know now that they are building a mass teleporter, to flood us with troops. If it is completed, we are all doomed, every one of us._";
	text3 = "_We need a group of soldiers who can find out where this portal is and how to destroy it. If you are willing, I can guide you._";
	
begintalknode;
	state = 193;
	nextstate = 190;
	condition = gf(3,8) <= 0;
	question = "_I have more pressing concerns right now._";
	text1 = "_I know you have much to do, so I will not press you. However, when you have time, you should be sure to return to me. This task is desperately important, and it must be completed._";
	
begintalknode;
	state = 193;
	nextstate = 190;
	condition = gf(3,8) <= 0;
	question = "_I will destroy the Empire teleporter._";
	text1 = "__";
	code =
		toggle_quest(118,3);
		run_hardcode(114);
	break;

begintalknode;
	state = 190;
	nextstate = -1;
	condition = gf(3,8) >= 1 && gf(3,8) <= 3;
	question = "_What should I do next to destroy the portal?_";
	code =
	run_hardcode(114);
	break;

begintalknode;
	state = 190;
	nextstate = 198;
	condition = gf(3,8) == 1 && gf(82,6) == 0;
	question = "_I will go find Pyrn. Any idea of where I should look first?_";
	text1 = "_He left the Tower some years ago, but his bedroom is right next door._ She points to the east. _He told me that he left directions to find him in his dresser. Or on his dresser._";
	text2 = "_He said to see the directions, you needed to do this ..._ She makes a quick series of hand motions. (You take note of them.) _Using them, you should get the information you'll need to find him._";
	action = SET_SDF 3 6 1;

begintalknode;
	state = 198;
	nextstate = -1;
	condition = gf(3,25) > 0;
	question = "_I did that. I found a note that said 'Ell Pit Esk.'_";
	text1 = "_Ah. That is a set of instructions for the Tower Portal. Go to the other side of this tier and speak with Vidrain. He will tell you how to use the portal._";

begintalknode;
	state = 190;
	nextstate = -1;
	condition = gf(3,8) == 2;
	question = "_Where should we look to find out where the portal is? Near Fort Dranlon, you said?_";
	text1 = "_The Empire has a nest of mages in a tower built north of Fort Dranlon. They call it the Tower of Elderan. It was a spy we put there who found out that the Empire was building the portal. Then, alas, the spy died. Badly._";
	text2 = "_Still, there should be information there, just waiting for you to find it._";

begintalknode;
	state = 190;
	nextstate = -1;
	condition = gf(3,8) == 4;
	question = "_I have destroyed the Empire portal._";
	text1 = "Mahdavi steps back, overcome with relief. _Wonderful! You may, and I am being careful not to overstate the case here, you may have saved Avernum. You have done a great thing for us all._";
	text2 = "_I would like to give you a small reward for your efforts. I know that there are two tomes in the libraries, bound in gold leaf and green leather. If you can track them down, read them. They will be very useful._";
	action = SET_SDF 3 8 5;
	code =
		toggle_quest(120,3);
		toggle_quest(124,3);
		award_party_xp(800,25);
	break;
	
begintalknode;
	state = 190;
	nextstate = 195;
	condition = gf(4,27) <= 1 && gf(82,6) > 0 && has_spec_item(23) == 0 && gf(3,8) < 4;
	question = "_Pyrn's papers mentioned something about an onyx scepter._";
	text1 = "_Really? That old thing? It actually has a use? Fascinating._";
	text2 = "_I think it was traded away a few years ago to the dragon Sulfras. Her lair is in the tunnels to the west of Fort Remote. I think you should probably go get it back._";
	code =
		sf(4,27,1);
		toggle_quest(124,1);
	break;

begintalknode;
	state = 195;
	nextstate = -1;
	condition = 1;
	question = "_You don't know what the scepter could do?_";
	text1 = "_Well, we didn't. Now we do. It can repair unstable portals, apparently._";

begintalknode;
	state = 195;
	nextstate = -1;
	condition = 1;
	question = "_Tell me about Sulfras._";
	text1 = "_She is the most powerful dragon in Avernum. We have maintained neutral relations with her for years. Since the Empire invasion, she has been out of contact with us. It will be very interesting to learn what happened to her._";
	
begintalknode;
	state = 190;
	nextstate = 195;
	condition = gf(4,27) == 1 && has_spec_item(23) > 0 && gf(3,8) < 4;
	question = "_I recovered the onyx scepter._";
	text1 = "_I am glad to hear it. If what you learned in Pyrn's tower is true, it will be extremely useful._";
	code =
		sf(4,27,2);
		toggle_quest(124,3);
	break;
	
begintalknode;
	state = 190;
	nextstate = -1;
	condition = gf(3,8) >= 5;
	question = "_Anything else I should do with the Empire portal?_";
	text1 = "_Not for now. Hopefully, we can end the war before they can rebuild it. In the meantime, be sure to search the libraries for the green bound books. They contain powerful knowledge._";

// Suzanne

begintalknode;
	tag = 170;
	state = -1;
	nextstate = 217;
	question = "Suzanne";
	text1 = "You meet one of the tower's mages. She wanders through this garden, inspecting (and occasionally battling and defeating) the experimental plants.";
	text2 = "She doesn't look pleased that you are bothering her. _I am Suzanne. What do you want?_";
	text5 = "Suzanne stares at you.";
	action = INTRO;

begintalknode;
	state = 217;
	nextstate = 220;
	condition = 1;
	question = "_Tell me about this garden._";
	text1 = "_Every plant that keeps Avernum alive, the glowing fungus, the high-yield mushrooms, all of them were developed here._";
	text2 = "_We can never stop improving, though. Every year, we must create better mushrooms._";

begintalknode;
	state = 220;
	nextstate = -1;
	condition = 1;
	question = "_Why?_";
	text1 = "_Humans were not meant to live in caves. Avernum can only provide the food to feed so many, and our population is always increasing._";
	text2 = "_If there is ever a problem with the mushrooms we rely on, it could be a disaster. I will make sure we are ready._";

begintalknode;
	state = 217;
	nextstate = 218;
	question = "_What is your job here?_";
	text1 = "She sighs. _I'm supposed to be teaching people to do magical research, especially on flora._";
	text2 = "_Tracking down ingredients. Alchemy. That sort of thing. I'm very busy. You can help me if you want. Or you could leave and let me think about my experiment._";

begintalknode;
	state = 218;
	nextstate = 219;
	question = "_What are you experimenting on?_";
	text1 = "_An augmentation to make lichen more resistant to heat. Nothing you would understand or care about. Something involving fire lizard eggs, which nobody seems to be able to find. I really need one. That's all._";
	text3 = "_Fire lizard eggs, as I'm sure you know. I think I can use them to make an effective, fire-retardant lichen. For wood walls and such. No luck so far, but, if I could succeed, it'd be an ugly surprise for the Empire._";
	action = DEP_ON_SDF 3 12 1;

begintalknode;
	state = 219;
	nextstate = 221;
	condition = gf(3,12) <= 1;
	question = "_Would you like me to find you a fire lizard egg?_";
	text1 = "_You think you can find one? Well, if you bring me a fire lizard egg, I will make it worth your while. Bring it to me. And don't let it break!_";
	action = SET_SDF 3 12 1;
	code =
		toggle_quest(25,1);
	break;
	
begintalknode;
	state = 221;
	nextstate = -1;
	condition = 1;
	question = "_Any suggestions for where to look?_";
	text1 = "_Somewhere where fire lizards live, I suppose. I heard some promising rumors about the caves north of the Lair of Motrax._";
	
begintalknode;
	state = 217;
	nextstate = -1;
	condition = gf(3,12) == 1 && party_has_item(487) > 0;
	question = "_I found a fire lizard egg for you._ (Give it to her.)";
	text1 = "Suzanne";
	code =
	run_hardcode(115);
	break;

begintalknode;
	state = 217;
	nextstate = -1;
	condition = gf(3,12) > 1;
	question = "_Do you need any other components?_";
	text1 = "_Not right now. I am still working with the egg you brought me. Please leave me be._ She wanders off, lost in thought.";
	action = END_TALK;

// Nathan

begintalknode;
	tag = 190;
	state = -1;
	nextstate = 244;
	question = "Nathan";
	text1 = "You meet a mage's apprentice. He rises to greet you. _Welcome. I am Nathan._ He is allowed to speak. He must be an advanced apprentice.";
	text2 = "_Come in. Sit down. We can talk about goings on in the world. It's very nice to have someone to talk to. It is. It really, really is._";
	text5 = "Nathan gets chatty. _Any other way I can help you? It's nice to have visitors. We don't get them. Very often. It's very nice to have someone to talk to. Especially after my years of silence as an apprentice._";
	action = INTRO;

begintalknode;
	state = 244;
	nextstate = -1;
	condition = gf(4,26) > 0;
	question = "_I'd like to know more about that portal you mentioned._";
	text1 = "_Aaaah! No! You'll get me in trouble! Look. Talk to Vidrain. Second tier of the tower. He'll tell you what you need to know. The portal is super-useful, if it doesn't kill you. Don't say I sent you._";
	text2 = "_OK? Um, you'd better go. Sorry. Bye._";
	action = END_TALK;

begintalknode;
	state = 244;
	nextstate = 245;
	question = "_Uhh, OK. So what do you do here?_";
	text1 = "_I'm an apprentice here. Close to graduation. I can speak, and spend my time teaching. It's nice being able to talk. I missed talking so much. But I can do it now. It's wonderful. I'm trying to get it out of my system, before I go to work on research._";

begintalknode;
	state = 245;
	nextstate = 246;
	question = "_What are you researching?_";
	text1 = "_I was going to go fight, but they decided it would be better if I helped develop new powerful spells and things instead. It's fascinating work. There's a lot I can tell you about it. I probably won't. Not now anyway. But it's very interesting!_";
	text2 = "_I'd like to work on the portal! That would be the most interesting and useful thing, I think!_";

begintalknode;
	state = 246;
	nextstate = -1;
	question = "_Can you tell me anything about the portal?_";
	text1 = "_The portal, yes! They've made a big portal, and it's in the tower now, and if you know the right incantation, it can send you everywhere and anywhere in Avernum! We're all talking about it! Well, all of us that are allowed to speak!_";
	text2 = "He suddenly stops, looking nervous. _Oh. I think I wasn't supposed to talk about the portal. Don't tell anyone, OK? Um, I'd better go. Sorry. Bye._";
	action = END_TALK;
	code =
		sf(4,26,1);
	break;
	
// Vincent

begintalknode;
	tag = 210;
	state = -1;
	nextstate = 271;
	question = "Vincent";
	text1 = "You meet a young man in mage's robes. He walks up and shakes your hand. _I'm Kelner, the tower secretary. Glad to see you're up and about._";
	text2 = "This is one of the men who questioned you after you teleported back. _Hope you've adjusted well to life back in Avernum. Ready to get back to work. Help us out, and so on._";
	text5 = "Kelner is still here and still friendly. _Anything else I can help you with? I'd really like to help, if possible. Thanks to your deal with the vahnatai, you've really become rather important._";
	action = INTRO;

begintalknode;
	state = 271;
	nextstate = 272;
	question = "_What does a secretary do?_";
	text1 = "_Right now, I'm writing a message to send to Solberg, telling him of your exploits among the vahnatai. As secretary, I'm the liaison between the Tower and the Avernum government. I write letters, pacify bureaucrats, and pass on orders._";

begintalknode;
	state = 272;
	nextstate = 273;
	question = "_What sort of orders?_";
	text1 = "_Occasionally, the bureaucrats have something tricky and magical they need done. Then they tell me about it and stick me with finding someone to do the dirty work. Or bloody work._";
	text2 = "_So. If you ever are in need of a mission, just ask._";

begintalknode;
	state = 272;
	nextstate = -1;
	question = "_Who is Solberg?_";
	text1 = "_He's a member of the Triad, but trapped in his tower far to the north. And he's a good friend of mine. I hope this letter can get to him. I'm not allowed to tell you more, I'm afraid._";

begintalknode;
	state = 271;
	nextstate = 274;
	condition = gf(3,13) <= 1;
	question = "_How can I help you out?_";
	text1 = "_There is something you can do. There is a serpent cult situated to the northeast. If you can slay its high priest, report back to me and I will put in a word to get you a higher clearance. It is the best I can do._";
	text2 = "_Alas, we know little about the cult. Aid us, and I will do my best to make your life easier._";
	code =
		toggle_quest(26,1);
		sf(3,13,1);
	break;
	
begintalknode;
	state = 274;
	nextstate = -1;
	condition = gf(3,13) <= 1;
	question = "_What has the cult been up to?_";
	text1 = "_Some months ago, a patrol traveling the tunnels to the northeast disappeared. Then another, then another. Spies and magical scrying revealed a band of renegade sliths, led by a powerful high priest, running some sort of perverse snake temple up there._";
	text2 = "_They're dangerous, and we need them removed. Period._";
	
begintalknode;
	state = 271;
	nextstate = -1;
	condition = gf(3,13) == 1 && gf(36,14) >= 1;
	question = "_I destroyed the serpent cult, as you asked. Their evil high priest will bother you no more._";
	code =
	run_hardcode(113);
	break;

begintalknode;
	state = 271;
	nextstate = 275;
	question = "_Have you always been the secretary here?_";
	text1 = "_No. Once, I was a lowly student. Then the archmage Linda summoned a powerful demon here. We could hold it, but we couldn't control it. We were all in great danger._";
	text2 = "_I found adventurers and helped them dispatch the creature. As a reward, I was promoted to this post._";

begintalknode;
	state = 275;
	nextstate = -1;
	question = "_What happened to Linda?_";
	text1 = "He shudders. _I prefer not to talk of her. She has been taken far away. She is trying to worm her way back into the Tower of Magi, but I'm doing everything I can to prevent it. Giving her a chance to do such harm again would be madness._";

begintalknode;
	state = 271;
	nextstate = -1;
	condition = gf(3,8) == 0;
	question = "_I got a note from someone named Mahdavi. She wanted us to come see her._";
	text1 = "_Ah, yes. She was very eager to speak with you. She is of the Triad, the three mages who lead the tower. Her chambers are on the second tier._";
	text2 = "_To get there, leave my office, walk east to the fountain. Go up the stairs to the north, and then west. Second door on the left._";

begintalknode;
	state = 271;
	nextstate = 276;
	question = "_I would like to return to vahnatai lands._";
	text1 = "_I am not surprised. The portal you arrived through is in the southeast corner of the tower._";

begintalknode;
	state = 276;
	nextstate = -1;
	condition = 1;
	question = "_Has anyone else been using it?_";
	text1 = "_There are high-level negotiations going on between King Micah and Olgai. I am not important enough to know a single thing about them._";

// Piglet

begintalknode;
	tag = 230;
	state = -1;
	nextstate = 298;
	question = "Elrad";
	text1 = "A young mage in the robes of an apprentice looks at you with interest. You ask his name. He traces out the word _Elrad_ with his finger on the wall.";
	text5 = "Elrad silently smiles at you.";
	action = INTRO;

begintalknode;
	state = 298;
	nextstate = 299;
	question = "_What's your job?_";
	text1 = "He points at his robes.";

begintalknode;
	state = 299;
	nextstate = -1;
	question = "_Oh. I see. And you can't talk, right?_";
	text1 = "He shrugs resignedly. Then he smiles, bows, and walks away.";
	action = END_TALK;

// Brantford

begintalknode;
	tag = 250;
	state = -1;
	nextstate = 325;
	question = "Brantford";
	text1 = "You meet a young woman in the robes of an apprentice. She smiles at you quietly. All first year students in the Tower of Magi are forbidden to speak.";
	text5 = "This young apprentice smiles and shakes her head.";
	action = INTRO;

begintalknode;
	state = 325;
	nextstate = 326;
	question = "_Hi there!_";
	text1 = "She almost starts to say something, and then stops herself and looks at you with irritation.";

begintalknode;
	state = 326;
	nextstate = -1;
	question = "_Can you talk?_";
	text1 = "She looks irritated that you're talking to her. She turns away before you can trick her into saying anything.";
	action = END_TALK;

