// dlg.txt

begintalkscript;

variables;

short i;

begintalknode 1;
	state = -1;
	nextstate = -1;
	condition = get_sdf(167,5) == 0;
	question = "special";
	text1 = "You step into the Tower Colony. This is the core of magical research in Avernum, and it has been since the earliest days. Once, it was called the Tower of Magi. Then a huge magical disaster destroyed it, almost taking Avernum with it.";
	text2 = "Since then, it has been rebuilt. A smaller tower is to the southwest. Several separate facilities are located to the northeast.";
	text3 = "There is so much history. You imagine for a moment you can see the smoke, smell the sulfur and ozone in the air, see the terrified guards and apprentices scurrying about.";
	text4 = "And then you realize that it isn't your imagination. The whole colony is on a state of constant, worried alert. Some of the walls on the second floor of the tower bear recent cracks, and wisps of smoke come out.";
	text5 = "The disaster that recently befell Avernum was not restricted to the Great Portal.";
	action = SET_SDF 167 5 1;

begintalknode 2;
	state = -1;
	nextstate = -1;
	condition = get_sdf(167,6) == 0;
	question = "special";
	text1 = "You step into the main tower of the colony. You are surprised to see that, despite all the chaos taking place over your head (and the rumbling you can hear through the stone), business down here is taking place mostly as normal.";
	text2 = "Apprentices are studying. Workshops are active. Mages continue their research, not being diverted from the task of dealing with the Blight and repairing the Great Portal.";
	text3 = "The main difference, apart from the smoke and noise, is that there are a lot of soldiers around, alert in case something nasty comes downstairs.";
	text4 = "In these chaotic circumstances, nobody seems to notice your presence.";
	action = SET_SDF 167 6 1;

begintalknode 3;
	state = -1;
	nextstate = -1;
	condition = get_sdf(167,7) == 0;
	question = "special";
	text1 = "You climb the stairs and enter the chaos of the second floor. The air is stiflingly hot and reeks of sulfur. You hear constant hisses and roars, as the pests that infest the level prey on each other.";
	text2 = "You immediately sense a powerful magical presence, constant and malevolent. It's ... It's to the northwest. It's not moving. It just waits."; 
	action = SET_SDF 167 7 1;

begintalknode 4;
	state = -1;
	nextstate = -1;
	condition = get_sdf(167,8) == 0;
	question = "special";
	text1 = "At the end of this corridor, you can see the heart of the disturbance. There is a magical device there ... A huge crystal on a metal pedestal. It glows with a strange light, yellow, bright, and healthy.";
	text2 = "The device lists at a slight angle, and the light flickers. Some of its energy is being drawn into a faint portal next to it. And, standing between the two, there is a huge demon. A true lord of the dark realms. A haakai.";
	text3 = "Tendrils of energy link the foul beast to both the portal and the glowing machine. It seems to be trying to emerge into our world, but something is holding it back. It is fighting through, little by little.";
	text4 = "Then the horror sees you. It lets out a furious shriek. _Hsss! Hsssss! You will not send me back!_ Then it waves a hand. It is unable to fit through the fissure into your world, but it can send its minions.";
	text5 = "With a flash of light, a pair of infernals appears before the demon. The minions of the haakai lumber down the hall toward you.";
	action = SET_SDF 167 8 1;
	code =
		activate_hidden_group(44);
	break;


begintalknode 5;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The obelisk says:";
	text2 = "  TOWER COLONY";

begintalknode 6;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The obelisk says:";
	text2 = "  TOWER COLONY";
	text3 = "  Service entrance.";
	
begintalknode 7;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "This is the tear in reality that the demon is trying to escape through. It is too unstable for you to consider using it. Even if it didn't lead to somewhere completely horrible.";

begintalknode 8;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "When you try to descend the stairway, the ground lurches under your feet. The cavequake cracks the walls around you. A cloud of dust and stone chips showers you from above.";
	text2 = "You look down the stairway and see a cloud of fire, filling your escape route.";
	text3 = "You aren't sure whether you are being held here by X or the demon lord. Doesn't matter. Someone really doesn't want you to leave.";

begintalknode 9;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The research taking place here involved studying all sorts of unique and unusual monsters. This withered hulk of once-living flesh, for example, still bears the broken shackles that were used to hold it in place.";
	text2 = "When it sees you, it extends a pointing finger and lets out a long, bone-chilling howl. Despite all of the heat, you find yourself feeling extremely cold. Its eyes glow blue, and they still possess a sharp, malevolent intelligence.";
	text3 = "Why anyone would go to the trouble of catching this thing, boxing it up, and bringing it to a civilized area, you have no idea. In life, it must have been quite powerful. As it lurches toward you, you see that this power remains.";

//

begintalknode 10; // portal papers
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "Happily, the handful of notes and journals resting on this pedestal survived the recent devastation.";
	text2 = "You look through them and locate the sheaf of notes Kelner described. It is a thin binder of sheets of vellum, covered with diagrams, formulae, and sketches of crystal pillars.";
	text3 = "The recent bursts of heat have left it only slightly singed. You put it in your pack.";
	text4 = "They are all obscure, and the heat has left most of them singed to the point of unreadability. You leave them.";
	code =
		clear_strings();
		as(1);
		if ((gf(167,16) == 0) && (gf(167,17) == 1)) {
			sf(167,16,1);
			as(2); as(3);
			set_spec_item(12,1);
			}
			else as(4);
	break;
	
begintalknode 11;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The Tower of Magi is famed for the depth and quality of its magical tomes unmatched in all of Avernum. You have had the good fortune to gain access to one of them.";
	text2 = "It is a complex tome, but you have mastered sufficient magical arcana to comprehend it. You learn a holy ritual that will protect you from blows in battle. (Your skill with the spell Ward of Steel increases.)";
	text3 = "You browse through the book a bit more, but you don't learn anything new.";
	text4 = "Sadly, these tomes, while priceless, are terribly complicated. You browse through the book, but you can't understand any of it. You don't know enough magical lore. (Improve your Arcane Lore skill to understand books like these.)";
	code =
		if (gf(166,24) == 0) {
			rs(3);
			if (get_stat_total(13) < 7)
				rs(2);
				else {
					rs(4);
					sf(166,24,1);
					alter_stat(30000,72,1);
					}
			}
			else {
				rs(1); rs(2); rs(4);
				}
	break;
	
begintalknode 12;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The Tower of Magi is famed for the depth and quality of its magical tomes unmatched in all of Avernum. You have had the good fortune to gain access to one of them.";
	text2 = "It is a complex tome, but you have mastered sufficient magical arcana to comprehend it. You learn a spell that will summon powerful allies to aid you. (Your skill with the spell Arcane Summon increases.)";
	text3 = "You browse through the book a bit more, but you don't learn anything new.";
	text4 = "Sadly, these tomes, while priceless, are terribly complicated. You browse through the book, but you can't understand any of it. You don't know enough magical lore. (Improve your Arcane Lore skill to understand books like these.)";
	code =
		if (gf(166,25) == 0) {
			rs(3);
			if (get_stat_total(13) < 11)
				rs(2);
				else {
					rs(4);
					sf(166,25,1);
					alter_stat(30000,57,1);
					}
			}
			else {
				rs(1); rs(2); rs(4);
				}
	break;
	
begintalknode 13;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The Tower of Magi is famed for the depth and quality of its magical tomes unmatched in all of Avernum. You have had the good fortune to gain access to one of them.";
	text2 = "It is a complex tome, but you have mastered sufficient magical arcana to comprehend it. You learn a spell that will summon allies to aid you. (Your skill with the spell Summon Aid increases.)";
	text3 = "You browse through the book a bit more, but you don't learn anything new.";
	text4 = "Sadly, these tomes, while priceless, are terribly complicated. You browse through the book, but you can't understand any of it. You don't know enough magical lore. (Improve your Arcane Lore skill to understand books like these.)";
	code =
		if (gf(166,26) == 0) {
			rs(3);
			if (get_stat_total(13) < 8)
				rs(2);
				else {
					rs(4);
					sf(166,26,1);
					alter_stat(30000,54,1);
					}
			}
			else {
				rs(1); rs(2); rs(4);
				}
	break;

begintalknode 14;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The Tower of Magi is famed for the depth and quality of its magical tomes unmatched in all of Avernum. You have had the good fortune to gain access to one of them.";
	text2 = "It is a complex tome, but you have mastered sufficient magical arcana to comprehend it. You learn a holy ritual that will heal even the most grievous wounds of nearby allies. (Your skill with the spell Divine Restoration increases.)";
	text3 = "You browse through the book a bit more, but you don't learn anything new.";
	text4 = "Sadly, these tomes, while priceless, are terribly complicated. You browse through the book, but you can't understand any of it. You don't know enough magical lore. (Improve your Arcane Lore skill to understand books like these.)";
	code =
		if (gf(166,27) == 0) {
			rs(3);
			if (get_stat_total(13) < 12)
				rs(2);
				else {
					rs(4);
					sf(166,27,1);
					alter_stat(30000,78,1);
					}
			}
			else {
				rs(1); rs(2); rs(4);
				}
	break;

begintalknode 15;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The Tower of Magi is famed for the depth and quality of its magical tomes unmatched in all of Avernum. You have had the good fortune to gain access to one of them.";
	text2 = "It is a complex tome, but you have mastered sufficient magical arcana to comprehend it. You learn a rare and highly sought-after spell that can disrupt nearby magical barriers. (Your skill with the spell Dispel Barrier increases.)";
	text3 = "You browse through the book a bit more, but you don't learn anything new.";
	text4 = "Sadly, these tomes, while priceless, are terribly complicated. You browse through the book, but you can't understand any of it. You don't know enough magical lore. (Improve your Arcane Lore skill to understand books like these.)";
	code =
		if (gf(166,28) == 0) {
			rs(3);
			if (get_stat_total(13) < 8)
				rs(2);
				else {
					rs(4);
					sf(166,28,1);
					alter_stat(30000,53,1);
					}
			}
			else {
				rs(1); rs(2); rs(4);
				}
	break;


begintalknode 16;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "";
	text1 = "You flip through Djokov's book of recipes. Most of it makes no sense to you. The first page, however, has a simple list:";
	text2 = "  Length of Cavewood + Flawless Crystal + Energetic Herbs = Fiery Wand";
	text3 = "  Length of Cavewood + Flawless Crystal + Mandrake Root = Terror Wand";
	text4 = "  Length of Cavewood + Focusing Crystal + Ruby + Mandrake Root = Null Wand";
	text5 = "  Length of Cavewood + Focusing Crystal + Eyestalks + Mandrake Root = Sparkling Wand";
	
begintalknode 17;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "There are always a lot of Avernite soldiers stationed at the Tower Colony. It is one of the least desired postings. The presence of so many wizards in one place leads to a lot of highly justified paranoia.";
	text2 = "You don't learn anything from them except that there was recently a disaster and the second floor of the main tower is highly dangerous. But you'd already kind of guessed that.";
	
begintalknode 18;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "This is one of the Tower Colony's young apprentices. As is traditional, they are all under a vow of silence. This spares the higher ranked mages the need to listen to a lot of screaming.";

begintalknode 19;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "These apprentices are practicing their spells. They fling bolts of fire at the targets to the south. Sometimes, they hit. You keep a safe distance.";

begintalknode 20;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "There is currently a class in progress here. You don't interrupt it.";

// HAAKAI ENC

begintalknode 21;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The mighty haakai points at you and mutters a spell. Motes of blackness fly from his claw, float to your head, and settle in.";
	text2 = "And then terror consumes you.";
	text3 = "Nightmares fill your vision, horrors even greater than what you face now. The victim of the haakai's spell is consumed with fear, all-encompassing, all-consuming. You feel faint and weak. Your heart shudders in your chest.";
	text4 = "The death curse is upon you. For the victim, nothing can be done.";
	text5 = "The death curse is upon you. If nothing is done, it will soon be the end.";
	code =
		if (gf(167,19) > 0)
			rs(4);
			else rs(5);
	break;
	
begintalknode 22;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "You hear X chanting in the distance, trying to call and channel awesome levels of magical power. You hear him curse loudly, his distant resolve finally breaking under the strain.";
	text2 = "_The demon! Not weak enough! Strike it! Wear it down!_";
	text3 = "The demon howls, _Come servants! Hunt the intruders! Smite them!_ It begins to cast its own spell. The need to concentrate on summoning its power leaves it distracted.";
	code =
		sf(167,19,2);
	break;
	
begintalknode 23;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The mighty haakai, trapped between this world and the next, is starting to waver under your blows. _No. I will not go! I will emerge! I will make a new kingdom of darkness in these lands! Taste the true measure of my power!_";
	text2 = "A whirlwind begins to form in the chamber. Lightning arcs from wall to wall, searing everything near the foul creature. The demon is distracted by the need to control the spell.";
	text3 = "X shouts, _Yes! It is weakening! Do more of what you are doing!_ He resumes his spell.";
	code =
		sf(167,19,3);
	break;
	
begintalknode 24;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "You try to search the body at the demon's feet. It waves a hand, and a wave of force knocks you back. _No,_ it roars. _That fool is my prey. I claim him._";
	text2 = "You search the body. He was an Avernite warrior. He was brave and strong, and he bore arms and armor of the highest quality. However, he fell prey to the demon's terror spell.";
	text3 = "The hero's armor was melted and destroyed by a mighty bolt of fire, but three items are still intact. There is a shield, a charm, and a sword.";
	text4 = "You recognize the sword. Any soldier of Avernum would. It is the legendary blade Demonslayer. And now you hold it in your hand.";
	text5 = "You recognize the sword. Any soldier of Avernum would. It is the legendary blade Demonslayer. However, it has a long crack in the blade. The blow that felled this hero damaged the blade as well.";
	text6 = "The crack runs up its entire length. It will be probably be impossible to repair it.";
	text7 = "You inspect the body. It is still unchanged. Hopefully, someone will be able to come up soon and bear it away for a hero's burial.";
	code =
		clear_strings();
		if ((gf(167,19) < 2) && (gf(167,18) == 0))
			as(1);
			else if (gf(167,27) > 0)
				as(7);
				else {
					as(2); as(3);
					reward_give(129);
					reward_give(376);
					sf(167,27,1);
					if (gf(167,18) > 0) {
						as(5); as(6);
						reward_give(305);
						}
						else {
							as(4);
							reward_give(304);
							}
					}
	break;
	
begintalknode 25;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "X gives the anvil a little kick, examines the goo that was once a demon lord, and nods. _A good start. Needs work. Maybe more efficient ..._ And then he looks up.";
	text2 = "The portal that was next to the demon begins to flicker. On the other side, you can faintly see a strange world. Not this one, not infernal. Just ... Your eyes can't really process it. It seems to fold in on itself.";
	text3 = "X says, _That looks interesting. I think I am done here. You may have what remains in my chambers. Time to go. Somewhere else._ He looks at you. _I should say something wise now._";
	text4 = "He shrugs. Then he turns and walks into the portal. It fades away.";
	text5 = "The demon is purged. X is gone. You are alone.";
	code =
		sf(166,22,1);
		kill_object(30162,1);
		erase_char(18110);
	break;
	
begintalknode 26;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "Your final blow strikes true. The demon reels before your assault. _No, little pest. I am a haakai, a lord of the infernal realms. I will not be beaten so easily. Watch! See how little your efforts mean to me!_";
	text2 = "The demon raises one hand and makes a gesture. In an instant, all of his wounds disappear.";
	text3 = "He raises the other hand and makes a fist. A long crack appears in the blade of Demonslayer, running down its entire length.ÊIt will be probably be impossible to repair it.";
	text4 = "The haakai laughs. _See! I was just playing with you! Now you must face your doom. Now there is no hope. Now ... What?_";
	text5 = "He looks up. Suspended in the air above him, you see an enormous anvil. It hangs there, motionless, glowing majestically. And then it falls.";
	text6 = "The haakai has studied the arts of war for millennia, but it never bothered to learn a defensive move for this eventuality. The anvil smashes it into a thick, red paste, dotted with scales.";
	text7 = "X begins to walk forward slowly toward the wreckage.";
	code =
		erase_char(18105);
		sf(167,18,1);
		sf(167,19,0);
		sf(167,4,6);
		erase_char(18106);
		erase_char(18107);
		erase_char(18108);
		erase_char(18109);
		set_walk_speed(18110,24);
		award_party_xp(500,40);
		set_object_blockage(30226,1);
		set_object_icon(30226,4);
		if (party_has_item(304)) {
			take_item(304);
			reward_give(305);
			}
			else rs(3);
	break;
	
begintalknode 27;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "You hear two cries, one of agony and one of victory. The wizard X has fallen in battle.";
	text2 = "Without X to control it, the power of the spell he was casting flies out unrestrained. It tears apart the bonds holding the haakai in place.";
	text3 = "An enormous fiery explosion tears off the entire top half off the tower. Everyone inside the building, except for the haakai is killed. Alas, you are among the fallen.";
	code =
		erase_char(30000);
	break;

begintalknode 28;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "You see a hideous worm slithering down one of the upper hallways. It leaves a thin layer of slime behind it, which hisses and spits and eats away at the stone. The creature's movements have burned a deep rut into the floor of the hallway.";
	text2 = "The worm appears to lack eyes. It is entirely blind. Perhaps, if you maintain a safe distance from these hideous creatures, you might be able to evade them.";

begintalknode 29;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "__";

// Kelner

begintalknode 30;
	state = -1;
	nextstate = 30;
	condition = 1;
	question = "Name";
	text1 = "There is an old, withered wizard sitting at this chair. He must have a position of some importance ... He wears a narrow sash across his chest, similar to what mayors wear. His skin has the waxy look that wizards get at an unnatural age.";
	text2 = "He looks you over and gives you a weary smile, as if he's been through all of this before. _Welcome, soldier. I am Kelner, the head administrator of this colony. I asked the Castle for assistance. I hope that you are it._";
	text3 = "_This is a dark time for the Tower Colony. We have had some very embarrassing mishaps. Still, I hope that things can be tidied up before the problems spread._";
	text5 = "Kelner fingers his sash and says, _Do you need anything else? If something would make you more effective, don't hesitate to ask._";
	text6 = "His skin is deeply wrinkled and unnaturally dry. Every movement seems to take an effort. Wizards, barring accidents, tend to die only when they will it. But Kelner doesn't seem far from that point.";
	action = INTRO;

begintalknode 31;
	state = 30;
	nextstate = 31;
	condition = 1;
	question = "You are in charge here?";
	text1 = "Kelner lets out a long, drawn out sigh. _Yes. Yes, I am. It feels like I've never left here. In fact, I don't think I have. I was a student, then a researcher, then ..._ He looks down at the sash. _This._";
	text2 = "_I remember the Tower of Magi. I was there when we lost it. And then I helped to rebuild it, in a newer form. Newer and safer, or so we thought._";

begintalknode 32;
	state = 30;
	nextstate = -1;
	condition = 1;
	question = "Can you teach me some magic?";
	text1 = "He chuckles. _Well, that takes me back. No, I have not taken on a student in many years. I am done with that. Find Agass-Ess, in the tower. If you are polite and respectful, she might give you a few lessons._";

begintalknode 33;
	state = 30;
	nextstate = 35;
	condition = 1;
	question = "What is going on inside the main tower?";
	text1 = "_A new disaster. We were developing something we call a Sunspire. It had the potential to be a way to grow different sorts of food here in the underworld._";
	text2 = "_However, when the Great Portal was disrupted, it sent a wave of energy through Avernum. It disrupted the Sunspire, which was always an experimental device, and caused ... problems._";
	text3 = "_And now, because of what has happened, we can't reach the records we need. Terrible luck. As usual._";
	text4 = "_We need to reach the Sunspire and get it under control, but the raw magic leaking from it has attracted a haakai. As long as it is there, we cannot reclaim the tower._";
	text5 = "_Fortunately, we are slowly regaining control of the Sunspire. Soon, the upper level can be reclaimed, cleaned up, and returned to functionality._";
	code =
		rs(3); rs(4); rs(5);
		if (gf(167,17) > 3)
			as(5);
			else if (gf(167,17) > 1)
			as(4);
			else as(3);
	break;
	
begintalknode 34;
	state = 30;
	nextstate = 36;
	condition = (gf(177,4) == 1 || gf(170,1) > 14) && gf(167,17) < 2;
	question = "I am here to help you recover some records.";
	text1 = "Kelner nods. _I thought so. The Castle was ... Well, not prompt. But faster than it has been in the past to send help._";
	text2 = "_Yes, we have some papers here, notes from when the Great Portal was last restored, back in the Time of Shades. I think they will be very helpful for restoring it now._";
	text3 = "_However, they might not still exist. They were in one of the storerooms upstairs, and there has been some ... tumult up there. I need you to  go upstairs, and find the library storerooms. Then hunt for and hopefully recover the notes._";
	code = 
		set_flag(167,17,1);
		toggle_quest(51,1);
	break;
	
begintalknode 35;
	state = 30;
	nextstate = -1;
	condition = gf(167,17) == 1 && has_spec_item(12);
	question = "I found the records you needed. (Give them to Kelner.)";
	text1 = "He takes the sheaf of notes and inspects them. _Yes ... Yes. The correct papers. Intact. Complete. Legible. Marvelous. This is truly a stroke of good fortune._";
	text2 = "He goes upstairs and soon returns with a package. He hands it to you, wincing. You open it and find a filthy pair of greaves. _Something we were experimenting on. A reward. We're done with them. Not useful to us, but they might help you._";
	text3 = "He thinks. _Also, I will unlock one of the chambers upstairs. Feel free to consult the spellbook within._";
	text4 = "_You have done very well. You should report your success to the Castle. They will want to hear of it quickly. And, later, should you gain some more experience, I may have another task for you._";
	code = 
		set_flag(167,17,2);
		sf(167,1,1);
		toggle_quest(51,3);
		award_party_xp(400,16);
		reward_give(357);
		set_spec_item(12,-1);
		sf(166,18,1);
	break;		
	
begintalknode 36;
	state = 30;
	nextstate = 41;
	condition = gf(167,17) == 3 || gf(167,17) == 2;
	question = "What else would you like for me to do?";
	text1 = "Kelner shakes his head. _I hesitate to ask, for it is an extremely difficult task. Far, far more dangerous than what I asked you to do before._";

begintalknode 37;
	state = 30;
	nextstate = -1;
	condition = gf(167,17) == 3 && gf(167,18) > 0;
	question = "The demon has been destroyed. (Tell the tale.)";
	text1 = "Kelner nods. _There is not one soul in the Tower Colony who did not instantly sense its departure from this realm. And 'X' is gone as well. That is ... I am sadder than I thought I would be._";
	text2 = "_I hope you were able to recover the body of the lost hero. You may keep any trinkets you recovered. And Demonslayer too, if you wish. It has a good reputation, but it never seems to be that useful._";
	text3 = "_I hope that will be reward enough for your accomplishment._ He thinks. _Also, I will unlock one of the chambers upstairs. Feel free to consult the spellbook within._";
	text4 = "_Now I must return to work. The upper floor must be reclaimed, cleaned, and returned to its purpose. We must resume our research, trying to find a way to help Avernum._";
	code = 
		set_flag(167,17,4);
		toggle_quest(52,3);
		sf(166,19,1);
		award_party_xp(400,35);
	break;
	
begintalknode 38;
	state = 30;
	nextstate = 40;
	condition = gf(167,2) == 4;
	question = "Can I do any more work for you?";
	text1 = "Kelner shakes his head. _No. I am ... I have been here so many years. I am tired. One way or another, Avernum is ... changing. And I must change too. I must find a new purpose, in this realm or beyond._";
	text2 = "_You have done much for me, reclaiming the colony, enabling me to feel peace. To know I will not leave work undone. I thank you._";

begintalknode 39;
	state = 40;
	nextstate = -1;
	condition = 1;
	question = "You are going? Who will replace you?";
	text1 = "_Going? Yes. I will soon ... go. And I do not think I will be replaced. There will be magic in Avernum, but it will be a wilder sort. I think, somehow, I will be the last leader of the Tower of Magi._";
	text2 = "He smiles sadly. _And, considering the disasters that have befallen this place, that might not be a bad thing._";

begintalknode 40;
	state = 31;
	nextstate = 32;
	condition = 1;
	question = "Tell me about the Tower of Magi.";
	text1 = "_It was a glorious thing, the heart of Avernum's power, for a while. Then one of the Triad, Archmage Linda, she ... She made an error. Created a portal. Lost control of it._";
	text2 = "_We were able to regain control, but it was a near thing. Much of Avernum could have been destroyed had we not controlled the portal. Oh, how many of our problems have been caused by those portals?_";

begintalknode 41;
	state = 32;
	nextstate = -1;
	condition = 1;
	question = "What was the Triad?";
	text1 = "_The Tower of Magi was ruled by a council of three wizards. They served to magnify the eccentricities of the others. Now it is led by one mage, under the strict and close supervision of the Castle._";
	text2 = "_For long stretches, the mage in charge has been me._";
	
begintalknode 42;
	state = 31;
	nextstate = -1;
	condition = 1;
	question = "Tell me about the Tower Colony.";
	text1 = "_Once the rubble of the Tower of Magi cooled, the wizards of Avernum instantly began to plan a new home, where they could work and collaborate. The Castle was worried by this. Understandably, considering the disaster._";
	text2 = "_In the end, they let us rebuild here. A place to teach and to study, carefully watched by the Castle. Apparently, not carefully enough._";

begintalknode 43;
	state = 31;
	nextstate = 33;
	condition = 1;
	question = "The Tower Colony was not safe after all?";
	text1 = "_Magical research is never a safe thing. We are, after all, only mortals, prone to mistakes, dealing with great amounts of power._";
	text2 = "_But we did not expect such a confluence of disasters, and we were working very hard in unison toward one goal._";

begintalknode 44;
	state = 33;
	nextstate = -1;
	condition = 1;
	question = "What goal?";
	text1 = "_To find a way to avoid famine. To cure the Blight, or create a mushroom resistant to it, or to find a new food source that would sustain Avernum._";
	text2 = "_Despite tireless effort, we had no success, and now this latest disaster has delayed the work. Perhaps completely._";
	
begintalknode 45;
	state = 35;
	nextstate = -1;
	condition = 1;
	question = "What was the Sunspire going to do?";
	text1 = "_It would be a source of power and light similar to that of the actual sun, on the surface. If it could be created and produce enough power, it might enable us to grow actual plants besides mushrooms._";
	text2 = "_I am not educated on the details. Sage Ardella can tell you more._";

begintalknode 46;
	state = 35;
	nextstate = -1;
	condition = gf(167,17) < 4;
	question = "Is the Sunspire dangerous to me?";
	text1 = "_The spire itself? Probably not. I set limits for the amount of power that could be channeled into it. Had it not, this disaster might have been far worse._";
	text2 = "_Of course, the demon that has shackled itself to the device carries certain risks. I would suggest maintaining a safe distance._";

begintalknode 47;
	state = 35;
	nextstate = -1;
	condition = gf(167,17) < 4;
	question = "Where is the Sunspire?";
	text1 = "_In the second floor on the main tower, in the center. There are four main hallways that lead to it. Keep far away from it, unless you want to deal with the demon. It is extremely dangerous._";
	text2 = "";

begintalknode 48;
	state = 35;
	nextstate = -1;
	condition = 1;
	question = "What will happen if the Sunspire is not repaired?";
	text1 = "_That is a fair question. Perhaps nothing. Perhaps it will draw more demons. Perhaps a large explosion._";
	text2 = "_Fortunately, I do not think it is likely to destroy all of Avernum. It will leave most of our people to starve in peace._";

begintalknode 49;
	state = 30;
	nextstate = -1;
	condition = gf(177,4) == 0 && gf(170,1) <= 14;
	question = "You are in need of some help?";
	text1 = "Kelner looks confused. _What? You mean you don't ... Ah. I thought you were sent from the Castle to help me. If you aren't sure that you are supposed to be here, you should go back there and talk to your commanding officer._";

begintalknode 50;
	state = 36;
	nextstate = -1;
	condition = 1;
	question = "And these papers will enable us to repair the portal?";
	text1 = "Kelner laughs dryly. _No. They will make repairing the portal slightly less impossible. They contain instructions. The raw materials will still be terribly difficult to obtain._";

begintalknode 51;
	state = 36;
	nextstate = -1;
	condition = 1;
	question = "Where is the library?";
	text1 = "_Just to the east, after you go upstairs. However, there is a lot of rubble and escaped creatures blocking the way. Getting there may be difficult._";
	
begintalknode 52;
	state = 36;
	nextstate = 37;
	condition = 1;
	question = "What should I know about conditions upstairs?";
	text1 = "_That there are wild experiments wandering loose, and a deadly haakai is held imprisoned in the center of the level. It is a lot of ugliness in very short quarters._";
	text2 = "_I can't give you much advice for how to maneuver, but I know someone who can._";
	
begintalknode 53;
	state = 37;
	nextstate = -1;
	condition = 1;
	question = "Who?";
	text1 = "_Speak with Sage Ardella. Her office is in the tower. She can tell you more about the haakai and the Sunspire._";
	
begintalknode 54;
	state = 41;
	nextstate = 40;
	condition = gf(167,17) == 2;
	question = "Oh. Never mind.";
	text1 = "_A wise choice. What else do you want to discuss?_";
	
begintalknode 55;
	state = 41;
	nextstate = 42;
	condition = 1;
	question = "I am not afraid. Go on.";
	text1 = "_Well, the papers are recovered, but the demon remains. It is an extremely powerful creature. Our mages haven't been able to budge it. The hero we sent upstairs was defeated. We don't have enough soldiers to face it._";
	text2 = "_We need a new hero to help us confront and defeat the foul haakai. Alas, its defenses seem impenetrable._";
	code = 
		set_flag(167,17,3);
		toggle_quest(52,1);
	break;	
	
begintalknode 56;
	state = 42;
	nextstate = -1;
	condition = 1;
	question = "Tell me about the first hero.";
	text1 = "_Captain Abradon. One of the finest warriors in Avernum, equipped with protective magical gear, enchanted armor, and the mighty blade Demonslayer. He went and dueled with the haakai._";
	text2 = "_It was a glorious battle, but, in the end, he fell._";
	
begintalknode 57;
	state = 42;
	nextstate = 43;
	condition = 1;
	question = "How am I going to be able to beat the haakai?";
	text1 = "_It is a true puzzle. I am out of ideas, but I know one who is not._";
	
begintalknode 58;
	state = 43;
	nextstate = -1;
	condition = 1;
	question = "Who?";
	text1 = "_The archmage 'X'. An ... eccentric sort. Once of the Triad. Very old. Loyal to Avernum, to the extent that he still has emotions we can comprehend. He is in the southern tower._";
	text2 = "_He believes that he can, with help, dispatch the demon. You should consult with him._";



// X

begintalknode 70;
	state = -1;
	nextstate = 70;
	condition = 1;
	question = "Name";
	text1 = "You meet 'X' the enchanter, one of Avernum's most famed, mysterious figures. Impossibly old, extremely powerful, highly eccentric, probably mad.";
	text2 = "He looks like a bundle of bones, held together by a thin layer of skin and a heavy web of magic. His eyes are bright and distant. A tiny bit of his mind is concentrating on you. The rest is wandering realms unimaginable.";
	text3 = "X says, _The soldier. The visitor. Another young hope. So many. Perhaps helpful. Perhaps I can help. Even X must eat. Yes. State your query._";
	text5 = "X stares at a point somewhere behind your head and chuckles. _Are you important? Or just destined to be bones on a forgotten road? Ask your questions, then go discover the answer._";
	action = INTRO;

begintalknode 71;
	state = 70;
	nextstate = 71;
	condition = 1;
	question = "Where are you from?";
	text1 = "_From surface. From sun. In Avernum in early days. Helped build it. Helped make mushrooms that die. So many years. So many turnings of absent sun. Too long._";

begintalknode 72;
	state = 71;
	nextstate = -1;
	condition = 1;
	question = "You were there at the founding of Avernum?";
	text1 = "_Mighty wizard. On surface. Power struggle. Was on side that lost. With lost Erika. With old Solberg. With lost Patrick and Rone. Sent to underworld._";
	text2 = "_Great mistake for Empire to make, I think._";

begintalknode 73;
	state = 71;
	nextstate = -1;
	condition = 1;
	question = "How old are you?";
	text1 = "He looks down at his skeletal hand. For a moment, he seems more lich than human. _Old._";

begintalknode 74;
	state = 71;
	nextstate = 72;
	condition = 1;
	question = "You made the mushrooms we grow?";
	text1 = "_Not make. Helped make. Was there. Gave advice. Saw process. Understand it._";

begintalknode 75;
	state = 72;
	nextstate = -1;
	condition = 1;
	question = "Can you make a new sort of mushroom for us to eat?";
	text1 = "_No. Not specialty. Strain has reached end of use. Been remade and extended as far as it can go. This is not first Blight. Not first time mushroom needed to be reworked. Is only last Blight. Is exhausted._";
	text2 = "He shakes his head. For a moment, you see a twinge of emotion on his face. _Is unfortunate. Thought this might happen. Hoped I was wrong. Was not._";

begintalknode 76;
	state = 70;
	nextstate = -1;
	condition = gf(167,4) < 4;
	question = "Can you teach me magic?";
	text1 = "He looks you over. _You don't have strength. Can't withstand such power. Work for me. Help me in tasks. Gain power gradually. With time, I will share secrets with you. I hope you survive them._";

begintalknode 77;
	state = 70;
	nextstate = -1;
	condition = gf(167,4) >= 4;
	question = "Can you teach me magic?";
	text1 = "You conclude your business.";	
	code = 
		begin_shop_mode("X",
		  "X will share with you some of the more powerful and dangerous known magical rituals.",
		  43,5,0);	
	break;
	
begintalknode 78;
	state = 70;
	nextstate = 73;
	condition = gf(167,4) < 2;
	question = "Is there anything I can do for you?";
	text1 = "_Yes. I wish to hire a young warrior. I was working on my great magic. The secret to the spell of power. I have worked a lifetime to unlock it. So close. But my testing ground is ... soiled._";
	text2 = "_There is a pest in the testing ground. Left from the last, failed test. Get rid of it._";
	code = 
		set_flag(167,4,1);
		toggle_quest(91,1);
	mark_quest_dest(868,677,0,91);
	break;

begintalknode 79;
	state = 73;
	nextstate = 74;
	condition = 1;
	question = "What is the great magic you are trying to create?";
	text1 = "_A true spell of power. It would create a rain of anvils. And drop them on the foe. From a great distance. Truly glorious. Massive and stylish destruction._";

begintalknode 80;
	state = 74;
	nextstate = 73;
	condition = 1;
	question = "Um. What?";
	text1 = "_The anvil contains within it a pure, awesome power. Of destruction. An anvil falling from the sky. Is there nothing more majestic. More deadly. Only I have the skill to unleash this power._";
	text2 = "Seems crazy to you. But, well, he is the wizard after all.";

begintalknode 81;
	state = 73;
	nextstate = -1;
	condition = 1;
	question = "Where is the testing ground?";
	text1 = "_To the north of the colony. Do not fear. The creature is but an imp. A pest. No real threat. I hope._";

begintalknode 82;
	state = 73;
	nextstate = -1;
	condition = 1;
	question = "Why don't you destroy the thing yourself?";
	text1 = "_I command awesome power, but it is stored within a fragile shell. One blow and it all might ... fly free._";

begintalknode 83;
	state = 70;
	nextstate = -1;
	condition = gf(167,4) == 1 && gf(153,5) > 0;
	question = "I have rid you of the demon in the testing grounds.";
	text1 = "He nods. _Then. The old anvils will be cleared. I can begin the next test. It is good._";
	text2 = "_A door upstairs is unlocked. A spell for you. A reward._";
	text3 = "_But work remains. On spell. I need help. Still._";
	code = 
		set_flag(167,4,2);
		toggle_quest(91,3);
		award_party_xp(400,16);
		sf(166,20,1);
	break;	
	
begintalknode 84;
	state = 70;
	nextstate = 75;
	condition = gf(167,4) == 2 || gf(167,4) == 3;
	question = "Is there anything else I can do to help you create your spell?";
	text1 = "_Long ago, I needed anvil. Perfect anvil. A model. In Fort Draco. Sent warriors to find it. They did. I studied it. I thought it would not help. I see now I was wrong. It had the proper shape._";
	text2 = "_Now I need it. Need Fort Draco anvil. Here. Very difficult. Fort Draco very far away. Deep in enemy lands._";
	text3 = "He pulls from his desk a metal disk. It has runes etched on it. He hands it to you.";
	text4 = "_If you are in Fort Draco. If you find an old anvil. With an elegant, promising shape. Place the token upon it. That is all._";
	code = 
		set_flag(167,4,3);
		toggle_quest(92,1);
		if (has_spec_item(28))
			rs(3);
			else set_spec_item(28,1);
	break;
	
begintalknode 85;
	state = 75;
	nextstate = -1;
	condition = 1;
	question = "How will I recognize the anvil?";
	text1 = "_It has a shape conducive to the flow of magic energy. And it is large. I think that is clear enough._";

begintalknode 86;
	state = 75;
	nextstate = -1;
	condition = 1;
	question = "How will I reach Fort Draco?";
	text1 = "_It is far to the north. Do not fear. You have the traveling spirit. You may well find yourself there. One day._";

begintalknode 87;
	state = 75;
	nextstate = -1;
	condition = 1;
	question = "You've studied this anvil before?";
	text1 = "_Long ago. Long, long ago. But I did not have it brought here. My great mistake. Cost me many years._";

begintalknode 88;
	state = 70;
	nextstate = -1;
	condition = gf(167,4) == 3 && gf(167,20) > 0;
	question = "So. Did you get the anvil safely?";
	text1 = "_I did. I completed the study. I sketched. I planned. I reworked my spell. I think I may have succeeded. Now one step remains. Testing. But a proper test. Yes. Hmm. What to test it on ..._";
	text2 = "He snaps back from his reverie. _You are here. You have done much. A reward. You have earned it. A door upstairs is unlocked. Study the magic. Learn. Grow. And, if you wish, I will teach you. Other spells. Least I can do._";
	code = 
		set_flag(167,4,4);
		toggle_quest(92,3);
		award_party_xp(400,25);
		sf(166,21,1);
	break;	

begintalknode 89;
	state = 70;
	nextstate = -1;
	condition = gf(167,4) == 4;
	question = "Anything else I can do for you?";
	text1 = "_We shall see. We shall see._";

begintalknode 90;
	state = 70;
	nextstate = -1;
	condition = gf(167,17) == 3 && gf(167,4) < 4;
	question = "Kelner said that you have a way to destroy the demon. Is this true?";
	text1 = "_Not true. I have an idea. Nothing I can actually do. Not yet._";
	text2 = "_I have tasks. Perform them for me. When they are done, then I can act._";

begintalknode 91;
	state = 70;
	nextstate = -1;
	condition = gf(167,17) == 3 && gf(167,4) >= 4;
	question = "Kelner said that you have a way to destroy the demon. Is this true?";
	text1 = "Suddenly, unexpectedly, he rises. _Yes. Yes. It is time. Time for my destiny. I go upstairs to confront the demon. With your help. Not alone._";
	text2 = "_When you are ready, follow me upstairs. I will be in the northern pool chamber, ready for a great battle. We will protect each other. We will banish the demon._";
	text3 = "And, without wasting any more time on actual explanation, X sweeps out of the room. He moves pretty fast for an old guy.";
	action = END_TALK;
	code =
		sf(167,4,5);
		erase_char(18037);
		spawn_creature(18110);
	break;

// Sage Ardella

begintalknode 110;
	state = -1;
	nextstate = 110;
	condition = 1;
	question = "Name";
	text1 = "There is a middle-aged mage sitting at this desk. She is clearly exhausted. You doubt she's had a good night's sleep in weeks. She keeps herself going with strong tea, force of will, and awareness of the fiery disaster upstairs.";
	text2 = "She looks up at you with bleary eyes. _I am Sage Ardella,_ she says. _I am the ... I supervise the experiments upstairs._ Where, you assume, the fire is.";
	text3 = "_Who are you? What do you want?_";
	text5 = "Sage Ardella looks up at you and mutters something incomprehensible. Her eyelids flutter shut for just a moment. Then a loud rumbling noise from upstairs snaps them open again.";
	action = INTRO;

begintalknode 111;
	state = 110;
	nextstate = -1;
	condition = gf(167,17) == 0;
	question = "You supervise everything happening upstairs?";
	text1 = "_Well, I ... Wait. Who are you? I am busy. If you're helping Kelner, I'll talk to you. Otherwise ... Too busy. Go away._";
	action = END_TALK;
	
begintalknode 112;
	state = 110;
	nextstate = -1;
	condition = gf(167,17) > 0 && gf(167,21) == 0;
	question = "I am working for Kelner.";
	text1 = "You explain why you were sent here. She nods. _More help. Good. Need more help. Stretched very thin here. As I said, I oversee the experiments upstairs._";
	text2 = "_I approve the experiments. I get the mages supplies. I have the waste hauled away. And now I am trying to control the disaster. I can give you advice, if you have to go up there. About the Sunspire. And the demon._";
	code =
		sf(167,21,1);
	break;
	
begintalknode 113;
	state = 110;
	nextstate = 111;
	condition = gf(167,21) > 0;
	question = "What sort of experiments happened up there?";
	text1 = "_Development of new spells. New potions. New flora and fauna. This tower has a glorious history of making creatures that make life in Avernum possible._";
	text2 = "_Of course, all work up there is approved first._";
	
begintalknode 114;
	state = 110;
	nextstate = 112;
	condition = gf(167,21) > 0 && gf(167,3) < 2;
	question = "You said that you have the waste hauled away? What do you mean?";
	text1 = "_Often spells and alchemical work result in waste. Slime. Muck. Failed potions. A lot of it poisonous. It has to go somewhere. I take care of that._";
	text2 = "She thinks. _Actually, if you have time, there is a way you can help me. When passing by._";
	
begintalknode 115;
	state = 110;
	nextstate = 114;
	condition = gf(167,21) > 0;
	question = "Tell me about the Sunspire.";
	text1 = "_It was a glorious idea. It truly was. It would use a modified sort of portal magic to draw the light of the sun from the surface into the underworld. It was even beginning to work, until its flaw became clear._";
	text2 = "_But, before we could take it apart ..._ She shakes her head. _The disaster._";
	
begintalknode 116;
	state = 110;
	nextstate = 116;
	condition = gf(167,21) > 0 && gf(167,17) < 4;
	question = "Tell me about the demon.";
	text1 = "_It is a haakai. I am one of the few who have seen it and lived. It shouted its name. Veknok Mindbreaker, if you are curious. Then it tried to come through into our world, but it could not break through._";
	text2 = "_Sadly, its smaller servants could. They are what caused much of the damage._";
	text3 = "_If you go upstairs, you should avoid the creature._";
	
begintalknode 117;
	state = 111;
	nextstate = -1;
	condition = 1;
	question = "What sort of things have been made here?";
	text1 = "_The glowing moss on the ceiling. The mushrooms that, until the Blight came, fed us all. New sorts of lizards. And so on._ She nods off. You nudge her awake.";
	text2 = "_Sorry. And we have tried to create new sorts of flora that are resistant to the Blight. And new ways to feed people. Like the Sunspire. No luck._";
	
begintalknode 118;
	state = 111;
	nextstate = -1;
	condition = 1;
	question = "Were you in charge of approving the work?";
	text1 = "_Yes. But don't blame me for this disaster. Everything was safe as possible. And, even now, the disaster is restrained to a small area._";
	text2 = "_It is not my fault that there was a massive surge of energy from the Great Portal that disrupted everything. _";
	
begintalknode 119;
	state = 111;
	nextstate = -1;
	condition = 1;
	question = "What caused the disaster?";
	text1 = "_The Great Portal. When it ruptured, it sent a shockwave of uncontrolled energy coursing through all of southern Avernum. They even felt it up in Silvar._";
	text2 = "_The day before that disaster, everything was calm. Then, Floom!_ She waves her hands wildly in the air.";
	
begintalknode 120;
	state = 112;
	nextstate = 110;
	condition = gf(167,3) == 0;
	question = "Sorry. I'm really busy.";
	text1 = "_Of course. Of course. All that muck can look after itself for a while. Never mind._";
	
begintalknode 121;
	state = 112;
	nextstate = 113;
	condition = 1;
	question = "Maybe I can help.";
	text1 = "_Well, there is an ogre colony to the northwest. There has been, on and off, for many years. We drive them out, they come back. Anyway, I thought, why not put them to use?_";
	text2 = "_So I have been sending them the waste. And paying them. And they guard it. I just need to send someone to check it occasionally, to make sure it doesn't leak. That's all I need. Just for you to poke your head in._";
	code = 
		set_flag(167,3,1);
		toggle_quest(93,1);
	break;	
	
begintalknode 122;
	state = 113;
	nextstate = -1;
	condition = 1;
	question = "How exactly will I get to the stuff?";
	text1 = "_Go to the ogre tribe and find the chief. He can take you there. Just be ... polite. They're temperamental creatures._";
	
begintalknode 123;
	state = 113;
	nextstate = -1;
	condition = 1;
	question = "What happens if it's not stored correctly?";
	text1 = "_It can be ugly. There was an old school of magic on the surface once. Was closed down, but a bunch of waste was left behind. It leaked out into the soil around the school. And ..._";
	text2 = "She sighs. _It was not good for the people who tried to live around there. Not something we want to repeat here._";
	
begintalknode 124;
	state = 110;
	nextstate = -1;
	condition = gf(167,3) == 1 && gf(152,2) > 0;
	question = "I saw the waste storage room. (Describe it.)";
	text1 = "_Bah! Are ogres good for nothing? Move some barrels into a cave. Don't break them. That is all. How hard is that?_";
	text2 = "_Well, I thank you for the help. Now we can send agents to collect and dispose of the stuff as quickly as possible._ There is a deep rumbling sound upstairs. _Which may not be that quick._";
	text3 = "She rewards you with a pair of leather boots, dyed green. _A reward for your effort._";
	text4 = "_Also, you might wish to check the job board. I am going to place a posting there regarding a certain treacherous ogre._";
	code = 
		set_flag(167,3,2);
		toggle_quest(93,3);
		award_party_xp(400,16);
		reward_give(147);
	break;		
	
begintalknode 125;
	state = 114;
	nextstate = -1;
	condition = 1;
	question = "What good would the sunlight do?";
	text1 = "_Apart from the obvious aesthetic qualities, it would enable us to grow a far wider range of crops down here._";
	
begintalknode 126;
	state = 114;
	nextstate = -1;
	condition = 1;
	question = "What was the device's flaw?";
	text1 = "She lets out an enormous yawn. _Portal energy tends to draw shades. And demons. The Sunspire was no different. When you are a farmer trying to grow oats or whatever, constant demon attacks are not what you want._";
	
begintalknode 127;
	state = 114;
	nextstate = -1;
	condition = 1;
	question = "Is it dangerous now?";
	text1 = "_Not really. It is the smallest and most stable of portals. It lets out sunlight. That is all. The only danger is in what it attracts. Has attracted._";
	text2 = "_When it cracked, something changed in it. I don't understand it, but that pulse of energy is what drew the haakai._";	
	
begintalknode 128;
	state = 116;
	nextstate = -1;
	condition = 1;
	question = "Where is the haakai?";
	text1 = "_It is in the center of the level, next to the wreckage of the Sunspire. And the portal it is trying to open. It seems to be shackled to both. Until it can make the portal large enough, it can't get through._";
	text2 = "_If you stay away from the center, you can avoid it. It is harder to avoid its servants. My scouts say that those disgusting worms patrol the four corridors leading into the center._";
	text3 = "_They seem to be linked to their master. They don't go much farther than those corridors. They are nasty, but you might be able to avoid them if you watch for their patrols._";
	
begintalknode 129;
	state = 116;
	nextstate = -1;
	condition = 1;
	question = "Why can't I attack it?";
	text1 = "_You can. But you will die. It can cloud your mind with fear, such overwhelming terror that you can die from the sheer force of it._";
	text2 = "_Just stay away. That's my advice._";

begintalknode 130;
	state = 116;
	nextstate = -1;
	condition = 1;
	question = "How can it be destroyed?";
	text1 = "_Happily, that is one problem that has not been left to me. Kelner is in charge of that._";

// Agass-Ess

begintalknode 135;
	state = -1;
	nextstate = 130;
	condition = 1;
	question = "Name";
	text1 = "It takes a lot more than a giant, explosive disaster to get time off for the apprentices of the Tower Colony. You meet the head instructor of the school of magic here. She is an aged, hunched over slithzerikai.";
	text2 = "She looks you over with cold, appraising eyes. _Ahssss. Potential. I see potential. You are not the first soldiersss here. Not the first to come for training. I am Agass-Ess._";
	text5 = "Agass-Ess inspects you, evaluating everything about you, your equipment, your muscles, your posture. You start to feel self-conscious.";
	text6 = "_Hssss. More training? What do you wish to know?_";
	action = INTRO;
	
begintalknode 136;
	state = 130;
	nextstate = 131;
	condition = 1;
	question = "Tell me about the school of magic.";
	text1 = "_This is one of few placesss in Avernum where wizardsss are trained. But it hasss great prestige. Some even came from the surface to study here._";
	text2 = "_We lack the librariesss and staff of schoolsss on the surface. But we have other advantagesss._";
	
begintalknode 137;
	state = 131;
	nextstate = -1;
	condition = 1;
	question = "Where else can one learn to be a wizard?";
	text1 = "_Now, only Patrick's Tower. There were other placesss before, like the Northern Islesss. Then the Slith Horde came._";
	
begintalknode 138;
	state = 131;
	nextstate = -1;
	condition = 1;
	question = "Why is the school still open?";
	text1 = "She casts her eyes to the ceiling and lets out a short, derisive hiss. _Thisss? Close because of thisss? Magesss must be able to study and concentrate even when all around isss disaster. Thisss, now, is nothing._";
	
begintalknode 139;
	state = 131;
	nextstate = -1;
	condition = 1;
	question = "Why would someone come from the surface to study?";
	text1 = "_On the surface, to a student of magic, the Empire gives many limitsss. Down here, in Avernum? Very few limitsss. Fewer books to learn from, but much more to learn._";
	
begintalknode 140;
	state = 130;
	nextstate = 132;
	condition = 1;
	question = "What can you teach me?";
	text1 = "_Ahssss ... Many spellsss. Valuable spellsss. I would help those who fight for thisss land. Especially against the Slith Horde._";
	text2 = "_I am one of the few who even share knowledge about magical barriersss. Their creation. And destruction._";
	
begintalknode 141;
	state = 132;
	nextstate = -1;
	condition = 1;
	question = "You hate the Slith Horde?";
	text1 = "_All civilized slithzerikai do. For they hate usss even more. They reserve their greatest tormentsss for those like me who work with the humansss._";
	
begintalknode 142;
	state = 132;
	nextstate = 133;
	condition = gf(167,2) < 2;
	question = "Can you teach me to destroy magical barriers?";
	text1 = "_Sssss. I can. It is a rare secret, closely guarded, but you may need it. But such a secret isss never given. Only earned._";
	
begintalknode 143;
	state = 133;
	nextstate = 134;
	condition = 1;
	question = "How can I earn it?";
	text1 = "_You have been to the Great Portal? Before the destruction, perhapsss? Well, there are papersss there. That we need. On the portal, on itsss repair, and on other thingsss._";
	text2 = "_Demonsss from the portal make itsss recovery difficult. I sent some to get them. They opened the way, but were slain._";
	text3 = "_Go to the Great Portal. Find the papersss. Bring them to me. But be warned. The demonspawn are likely to be very powerful. Very, very dangerousss. You should be sure to grow in experience before you face them._";
	code = 
		set_flag(167,2,1);
		toggle_quest(53,1);
	break;	
	
begintalknode 144;
	state = 134;
	nextstate = -1;
	condition = 1;
	question = "Where are they?";
	text1 = "She describes them to you. _They are in the library there. In the tunnelsss under the portal. To get them, you may need to passss some pests, called by the portal. It may be dangerousss._";
	text2 = "_Do thisss, and my secretsss are yoursss._";
	
begintalknode 145;
	state = 130;
	nextstate = -1;
	condition = gf(167,2) == 1 && has_spec_item(11);
	question = "I recovered your papers. (Give them.)";
	text1 = "She takes the sheaf of notes and inspects them. _Yesss. Little by little, we reassemble the knowledge we need to rebuild the Great Portal. It was carelessss to let it scatter. Now it comesss together._";
	text2 = "_Now you may train. Learn. The secretsss of barriersss will be yoursss. And, I think, I will charge less for the techniques I teach._";
	code = 
		set_flag(167,2,2);
		toggle_quest(53,3);
		award_party_xp(400,20);
	break;		
	
begintalknode 146;
	state = 130;
	nextstate = 135;
	condition = 1;
	question = "I would like to be trained.";
	text1 = "_Yesss. I can teach you many spellsss. Powerful magicsss. And certain other techniques, for efficiency and power._";
	
begintalknode 147;
	state = 135;
	nextstate = -1;
	condition = 1;
	question = "What spells can you teach me?";
	text1 = "You conclude your training.";	
	code = 
		begin_shop_mode("Agass-Ess",
		  "Agass-Ess can teach a wide range of spells.",
		  44,3,0);	
	break;	
begintalknode 148;
	state = 135;
	nextstate = -1;
	condition = 1;
	question = "What techniques can you teach me?";
	text1 = "You conclude your training.";	
	code = 
		if (gf(167,2) > 1)
		begin_shop_mode("Agass-Ess",
		  "Agass-Ess can teach a wide range of magical techniques. Because you helped her, this training is cheaper now.",
		  45,3,0);	
		else begin_shop_mode("Agass-Ess",
		  "Agass-Ess can teach a wide range of magical techniques. This training is very expensive.",
		  45,6,0);	
	break;	
	
begintalknode 149;
	state = 135;
	nextstate = -1;
	condition = gf(167,2) > 1;
	question = "I want to learn how to dispel barriers.";
	text1 = "You conclude your training.";	
	code = 
		begin_shop_mode("Agass-Ess",
		  "Agass-Ess can teach you how to dispel magical barriers. This is rare and valuable knowledge.",
		  46,1,0);	
	break;	
	
begintalknode 150;
	state = 135;
	nextstate = 130;
	condition = 1;
	question = "I don't need to learn anything else.";
	text1 = "_Ahssss. All right._";
		
	
begintalknode 151;
	state = 134;
	nextstate = -1;
	condition = 1;
	question = "Is there anything else I should know?";
	text1 = "_Only that fighting demonsss, in great numbersss, is dangerousss. Only the most skilled and experienced should try such a thing._ Agass-Ess looks at you skeptically. _Perhapsss you are not ready._";
	
// Djokov

begintalknode 154;
	state = -1;
	nextstate = 150;
	condition = 1;
	question = "Name";
	text1 = "When magical research and training gets intense enough, it requires an alchemist to be nearby and on call all the time. Sure, there are the explosions and horrible odors, but sacrifices do have to be made.";
	text2 = "The Tower Colony's resident alchemist limps up to greet you. _Yes. Yes. Welcome, soldier. Kelner has placed orders that I am to help all of Avernum's brave warriors._";
	text3 = "_I am Djokov. If you need potions or custom work, come trade with me. I am also tasked to obtain extra supplies for the tower, if you have anything to sell._";
	text5 = "Djokov constantly tends to his bubbling pots. He frequently crumbles dried herbs into them or uses a spoon to scrape scum off the tops. _Sorry. This all requires constant attention._";
	action = INTRO;

begintalknode 155;
	state = 150;
	nextstate = 151;
	condition = 1;
	question = "What sort of things do you make here?";
	text1 = "_Well, the obvious things. Potions for healing and blessing. Wands. Scroll ink._";
	text2 = "_But there are other things I do, too. Alchemical work._";
	
begintalknode 156;
	state = 151;
	nextstate = -1;
	condition = 1;
	question = "Where do you get your ingredients?";
	text1 = "_Gathering of rare and precious magical herbs is a major source of wealth for Avernum. The foragers go out and return laden with ingredients of all sorts._";
	text2 = "_Some of them went up the Great Portal. Others come here._";
	
begintalknode 157;
	state = 151;
	nextstate = -1;
	condition = 1;
	question = "What else do alchemists do?";
	text1 = "_I make cleaning solvents and substances to purify metal. I make acids and poultices. And drinks to cure headaches. Magical researchers get lots of headaches._";
	
begintalknode 158;
	state = 150;
	nextstate = -1;
	condition = 1;
	question = "Can I buy a potion or two?";
	text1 = "You conclude your business.";	
	code = 
		begin_shop_mode("Djokov's Potions",
		  "Djokov spends a lot of his time making potions for soldiers and adventurers.",
		  47,4,0);	
	break;
	
begintalknode 159;
	state = 150;
	nextstate = -1;
	condition = 1;
	question = "I have something that might be useful to the tower. Want to buy it?";
	text1 = "You conclude your business.";	
	code = 
		begin_sell_mode();
	break;
	
begintalknode 160;
	state = 150;
	nextstate = 152;
	condition = 1;
	question = "Can you do any custom work for me?";
	text1 = "_I would be happy to. My specialty is wands. I can make all sorts of them. Of course, you will need to provide the materials._";
	text2 = "He points at a thick book on a pedestal by the west wall. _I've made notes of what I can make, and what I will need. Please consult that before you waste any of your time._";

	
begintalknode 161;
	state = 152;
	nextstate = -1;
	condition = num_of_item(60) > 0 && num_of_item(291) > 0 && num_of_item(214) > 0;
	question = "Can you make a Fiery Wand for me? (Give a stick, a flawless crystal, and energetic herbs.)";
	text1 = "_Excellent. Another job to do. Stand back. I have to work quickly._ He takes the components, examines them, nods his approval, and starts to attach the crystal to the stick. As he works, he mutters spells under his breath.";
	text2 = "The herbs become a gummy concoction, which helps to hold the crystal to the stick. He uses an athame to etch symbols into the wood. His work is remarkably fast and precise. And, before much time passes, he presents you with a simple wand.";
	code = 
		take_item(60);
		take_item(291);
		take_item(214);
		reward_give(97);
	break;
	
begintalknode 162;
	state = 152;
	nextstate = -1;
	condition = num_of_item(60) > 0 && num_of_item(293) > 0 && num_of_item(214) > 0;
	question = "Can you make a Terror Wand for me? (Give a stick, a flawless crystal, and mandrake root.)";
	text1 = "_Excellent. Another job to do. Stand back. I have to work quickly._ He takes the components, examines them, nods his approval, and starts to attach the crystal to the stick. As he works, he mutters spells under his breath.";
	text2 = "The herbs become a gummy concoction, which helps to hold the crystal to the stick. He uses an athame to etch symbols into the wood. His work is remarkably fast and precise. And, before much time passes, he presents you with a simple wand.";
	code = 
		take_item(60);
		take_item(293);
		take_item(214);
		reward_give(99);
	break;
	
begintalknode 163;
	state = 152;
	nextstate = -1;
	condition = num_of_item(60) > 0 && num_of_item(293) > 0 && num_of_item(295) > 0 && num_of_item(9) > 0;
	question = "Can you make a Null Wand for me? (Give a stick, a focusing crystal, a ruby, and mandrake root.)";
	text1 = "_Excellent. Another job to do. Stand back. I have to work quickly._ He takes the components, examines them, nods his approval, and starts to attach the crystal to the stick. As he works, he mutters spells under his breath.";
	text2 = "The herbs become a gummy concoction, which helps to hold the crystal to the stick. He uses an athame to etch symbols into the wood. His work is remarkably fast and precise. And, before much time passes, he presents you with a simple wand.";
	code = 
		take_item(60);
		take_item(293);
		take_item(295);
		take_item(9);
		reward_give(100);
	break;
	
begintalknode 164;
	state = 152;
	nextstate = -1;
	condition = num_of_item(60) > 0 && num_of_item(293) > 0 && num_of_item(295) > 0 && num_of_item(438) > 0;
	question = "Can you make a Sparkling Wand for me? (Give a stick, a focusing crystal, gazer eyestalks, and mandrake root.)";
	text1 = "_Excellent. Another job to do. Stand back. I have to work quickly._ He takes the components, examines them, nods his approval, and starts to attach the crystal to the stick. As he works, he mutters spells under his breath.";
	text2 = "The herbs become a gummy concoction, which helps to hold the crystal to the stick. He uses an athame to etch symbols into the wood. His work is remarkably fast and precise. And, before much time passes, he presents you with a simple wand.";
	code = 
		take_item(60);
		take_item(293);
		take_item(295);
		take_item(438);
		reward_give(102);
	break;
	
begintalknode 165;
	state = 152;
	nextstate = 150;
	condition = 1;
	question = "I don't need anything.";
	text1 = "_All right. I know the components for my wands can be difficult to find._";
	
begintalknode 166;
	state = 150;
	nextstate = -1;
	condition = 1;
	question = "I don't need anything else.";
	text1 = "He nods to you. _Good day, then._ He returns to dealing with his bubbling pots.";
	action = END_TALK;

// Captain Bahgdatis

begintalknode 170;
	state = -1;
	nextstate = 170;
	condition = 1;
	question = "Name";
	text1 = "There is an old soldier sitting in this office, kept separate from the main tower. He leans back in his chair, listens to the constant rumbles and crashes coming from the tower, and looks miserable.";
	text2 = "He is obviously not one of the mages. Although he wears a captain's insignia, he isn't actually a warrior. He stands to greet you.";
	text3 = "_Captain Bahgdatis. Welcome. Always glad to see another soldier here. Not that it ever helps when dealing with these madmen._";
	text5 = "Captain Bahgdatis reclines in his chair and listens to the chaos outside. Whatever his primary job is, he makes it clear that he's completely given up.";
	action = INTRO;

begintalknode 171;
	state = 170;
	nextstate = 171;
	condition = 1;
	question = "What do you do here?";
	text1 = "_I am the official Castle liaison to the Tower Colony. My task is to watch the experiments taking place here, question the mages frequently, and generally watch for anything that might reproduce the disasters of past decades._";
	
begintalknode 172;
	state = 171;
	nextstate = -1;
	condition = 1;
	question = "So you answer to the Castle?";
	text1 = "_I do. They ask me how things are going. I say that they are under control. And then everything blows up, and I drink._";
	text2 = "";

begintalknode 173;
	state = 171;
	nextstate = 172;
	condition = 1;
	question = "What is the current status here?";
	text1 = "You hear an explosion, coming from the main tower. The ground vibrates slightly under your feet.";
	text2 = "_Not well,_ he says dryly. _The disaster I was put here to prevent occurred. Now I can only stand back and wait for them to repair it._";
	
begintalknode 174;
	state = 172;
	nextstate = -1;
	condition = 1;
	question = "Did you know about the experiment that went wrong?";
	text1 = "_You mean the Sunspire? Yes, I knew all about it. Except for everything they didn't tell me. Like, say, the risks._";
	
begintalknode 175;
	state = 172;
	nextstate = -1;
	condition = 1;
	question = "So the disaster is partly your fault.";
	text1 = "_That is what the Castle believes, I am sure. But there is only one of me, and many mages, and things happen quickly, and they lie to me. Yes! Imagine that! Wizards, lying in order to get to do whatever they want._";
	text2 = "_I finally feel comfortable doing what I've long wanted to do. Just give up. Ahhh. It feels marvelous._";
	
begintalknode 176;
	state = 170;
	nextstate = 173;
	condition = 1;
	question = "Can I do any work for you?";
	text1 = "_Perhaps. I do have jobs around here. Mainly involving cleaning up the messes the wizards make, before they cause real harm._";
	
begintalknode 177;
	state = 173;
	nextstate = -1;
	condition = 1;
	question = "So what should I do?";
	text1 = "_Watch the job board. Outside Kelner's office. That's where I post the jobs, so that passing mercenaries can profit. You don't think they give me actual soldiers to command, do you? Hah!_";
	
begintalknode 178;
	state = 170;
	nextstate = -1;
	condition = 1;
	question = "What do you think of the Tower Colony?";
	text1 = "_It contains two sorts of wizards. Brilliant workers who are doing all they can to save and aid Avernum. And crazed madmen who could, with one bad decision, destroy us all._";
	text2 = "_Sadly, all mages here belong to both categories._";

// X upstairs

begintalknode 190;
	state = -1;
	nextstate = 190;
	condition = 1;
	question = "Name";
	text1 = "Once again, you meet the archmage X. He is in the midst of the ruins of the second floor, oblivious to the chaos around him. Before you got here, he appears to have blasted some of the demon's irritating slime worms to bits.";
	text2 = "When you enter, he is blessing the three basins in this room. They are starting to glow slightly. When that work is done, he turns to you.";
	text3 = "_Ah. You are here. Good. Is time. Yes. I can begin the spell. You must protect me. Yes. I think you know what you must do._ And yet, you don't feel you know what you must do at all.";
	text5 = "X continues to concentrate and summon his powers. He occasionally checks the enchantments on the basins to make sure that they are holding.";
	text6 = "_Is close to time. You need to be ready. Yes? Ready?_";
	action = INTRO;
	code =
		sf(166,23,1);
	break;
	
begintalknode 191;
	state = 190;
	nextstate = -1;
	condition = 1;
	question = "You are going to destroy the demon?";
	text1 = "_My spell. My spell is ready. At last. I think. I hope. Very embarrassing if it is not._";
	
begintalknode 192;
	state = 190;
	nextstate = -1;
	condition = 1;
	question = "Why are you blessing those basins?";
	text1 = "_The demon clouds the mind. Fatally. Marvelous spell. I admire it. But it must be countered._";
	text2 = "_The basins contain power. I just activate them. The fluid, when it comes, brings clarity. Yes. Clarity. When your mind is clouded, drink. But not too often. I can only fill the pools so many times._";
	text3 = "_There are also other basins near here._ He points to the east. _You may revive yourself there if needed._";
	
begintalknode 193;
	state = 190;
	nextstate = -1;
	condition = 1;
	question = "What spell are you going to use?";
	text1 = "_The end of my work. So many years of work._";
	
begintalknode 194;
	state = 190;
	nextstate = 191;
	condition = 1;
	question = "What do I need to do?";
	text1 = "_The demon must be weak. The spell is strong, but not so strong. Fight the demon. Distract it. Drink when your mind is shrinking._";
	text2 = "_Use the blade if you can reach it. Is a good blade. Was wasted before. Can use it now._";
	text3 = "_Say when ready to fight the demon. But be sure you are ready. Once battle begins, no escape until victory._";
	
begintalknode 195;
	state = 191;
	nextstate = -1;
	condition = 1;
	question = "I'm not ready yet.";
	text1 = "_Go. Be ready. You must strike fast, when it is time._";
	action = END_TALK;
	
begintalknode 196;
	state = 191;
	nextstate = -1;
	condition = 1;
	question = "I am ready. Begin your spell.";
	text1 = "X nods. _At last. Sweet success. Sweet vindication._ He points at one of the basins and mutters a word of command. An inch of sparkling crystal water appears in the bottom. _Only drink when you need._";
	text2 = "_Now. It is time. Battle the demon. Weaken it._ He begins to chant softly. Your hair stands on end. He is beginning his spell.";
	text3 = "Down the hall, you hear the haakai bellow a challenge. Waves of heat and sulfurous gas fill the air. The whole tower begins to shake. The haakai starts to create servants, to destroy X before he can finish the spell.";
	action = END_TALK;
	code =
		sf(167,19,1);
		sf(167,23,1);
		heal_char(18105,3000);
	break;
	
begintalknode 210;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The sign says:";
	text2 = "  TOWER ADMINISTRATOR";

begintalknode 211;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The sign says, simply:";
	text2 = "  X";

begintalknode 212;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The sign says, simply:";
	text2 = "  CASTLE LIAISON";

begintalknode 213;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "special";
	text1 = "The sign says, simply:";
	text2 = "  Apprentice Quarters";
	
////

begintalknode 299;
	state = -1;
	nextstate = -1;
	condition = 1;
	question = "";
	text1 = "Unfortunately for you, the Tower of Magi is the worst possible place to begin a life of crime. Between the surplus of wizards and the large number of soldiers summoned here, you are soon overwhelmed and subdued.";
	text2 = "You are jailed in Fort Remote. By the time you are able to get free, the multiple disasters that afflict Avernum have doomed you and all around you.";	
	code =
		erase_char(30000);
	break;
