// Town 54: The Third Level
begintownscript;

variables;

short choice,i,j,k;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	change_blocked(1,57,1);
	change_blocked(2,57,1);
	change_blocked(3,57,1);
	change_blocked(4,57,1);
	change_blocked(5,57,1);
	change_blocked(6,57,1);
	change_blocked(6,58,1);
	change_blocked(6,59,1);
	change_blocked(6,60,1);
	change_blocked(6,62,1);
	change_blocked(5,62,1);
	change_blocked(4,62,1);
	change_blocked(3,62,1);
	change_blocked(2,62,1);
	change_blocked(1,62,1);
	change_blocked(1,61,1);
	change_blocked(1,60,1);
	change_blocked(1,59,1);
	change_blocked(1,58,1);
	
	change_blocked(57,57,1);
	change_blocked(58,57,1);
	change_blocked(59,57,1);
	change_blocked(60,57,1);
	change_blocked(61,57,1);
	change_blocked(62,57,1);
	change_blocked(62,58,1);
	change_blocked(62,59,1);
	change_blocked(62,60,1);
	change_blocked(62,61,1);
	change_blocked(62,62,1);
	change_blocked(61,62,1);
	change_blocked(60,62,1);
	change_blocked(59,62,1);
	change_blocked(58,62,1);
	change_blocked(57,62,1);
	change_blocked(57,61,1);
	change_blocked(57,59,1);
	change_blocked(57,58,1);
	
	change_blocked(2,59,1);
	change_blocked(2,60,1);
	change_blocked(2,61,1);
	change_blocked(3,59,1);
	change_blocked(3,60,1);
	change_blocked(3,61,1);
	
	change_blocked(60,59,1);
	change_blocked(60,60,1);
	change_blocked(60,61,1);
	change_blocked(61,59,1);
	change_blocked(61,60,1);
	change_blocked(61,61,1);
	
	change_blocked(38,5,1);
	change_blocked(39,5,1);
	change_blocked(40,5,1);
	change_blocked(38,6,1);
	change_blocked(39,6,1);
	change_blocked(40,6,1);
	change_blocked(38,7,1);
	change_blocked(39,7,1);
	change_blocked(40,7,1);
	
	add_range_to_group(6,14,1);
	set_level(1001,66);
	char_give_item(28,264);
	set_name(39,"Velner");
	set_name(44,"Nemurr");
	set_name(76,"Laghash");
	
	if (get_flag(54,10)) {
		erase_char(40);
		erase_char(39);
		}
	
	if (get_flag(54,0) == 0) {
		force_instant_terrain_redraw();
		message_dialog("You teleport onto a small island in the midst of lava. Towering over you is an enormous castle, a monstrous growth perched on the ledge just above your head like some bird of prey ready to strike.","Between you and this castle are a few unpleasant-looking living balls of fire.");
		set_flag(54,0,1);
		}
	
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
if (is_combat() == 0)
	end();
if (character_in_party(105) < 0)
	end();
	
	if (get_ran(1,1,3) == 1) {
		i = get_ran(1,1,7);
		if (i == 1) {
			heal_char(1000,get_ran(10,10,30));
			put_effect_on_char(0,4,1,2);
			put_effect_on_char(1,4,1,2);
			put_effect_on_char(2,4,1,2);
			put_effect_on_char(3,4,1,2);
			put_effect_on_char(4,4,1,2);
			print_str_color("Phaedra heals the party!",2);
			run_animation_sound(24);
			}
		j = get_ran(1,0,3);
		if (i == 2) {
			heal_char(j,get_ran(10,30,50));
			put_effect_on_char(j,4,1,2);
			clear_buffer();
			append_string("Phaedra heals ");
			append_char_name(j);
			append_string("!");
			get_buffer_text(dlgstr);
			print_str_color(dlgstr,2);
			run_animation_sound(24);
			}
		if (i >= 3) {
			clear_buffer();
			append_string("Phaedra blesses ");
			append_char_name(j);
			append_string("!");
			get_buffer_text(dlgstr);
			print_str_color(dlgstr,2);
			}
		if (i == 3) {
			set_char_status(j,5,20,0,1); // Magic Resistant
			put_effect_on_char(j,4,1,2);
			run_animation_sound(4);
			}
		if (i == 4) {
			set_char_status(j,4,5,0,1); // Invulnerable
			put_effect_on_char(j,8,1,2);
			run_animation_sound(25);
			}
		if (i == 5) {
			set_char_status(j,16,10,0,1); // Divinely Touched
			put_effect_on_char(j,7,1,2);
			run_animation_sound(60);
			}
		if (i == 6) {
			set_char_status(j,17,20,0,1); // Resistant
			put_effect_on_char(j,10,1,2);
			run_animation_sound(166);
			}
		if (i == 7) {
			set_char_status(j,22,20,0,1); // Regenerating
			put_effect_on_char(j,5,1,2);
			run_animation_sound(24);
			}
		}
break;

beginstate 10;
	reset_dialog_preset_options(3);
	if (run_dialog(1) == 2)
		move_to_new_town(49,4,3);
	else
		block_entry(1);
break;

beginstate 11;
	reset_dialog_preset_options(3);
	if (run_dialog(1) == 2)
		move_to_new_town(48,41,6);
	else
		block_entry(1);
break;

beginstate 12;
	reset_dialog_preset_options(5);
	if (run_dialog(1) == 2)
		move_to_new_town(55,24,42);
	else
		block_entry(1);
break;

beginstate 13;
	reset_dialog_preset_options(8);
	if (run_dialog(1) == 2) {
		flip_terrain(38,15);
		flip_terrain(39,15);
		flip_terrain(40,15);
		}
	else
		block_entry(1);
break;

beginstate 14;
	reset_dialog_preset_options(8);
	if (run_dialog(1) == 2) {
		flip_terrain(47,35);
		flip_terrain(48,35);
		}
	else
		block_entry(1);
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(0,"The pillar here radiates magical energy. You cannot immediately tell what kind of energy it is, but you are sure that if you touch it, something will happen. Whether that would be good or not remains to be seen.",0);
	add_dialog_str(1,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Touch it.");
	if (run_dialog(1) == 2) {
		revive_party();
		play_sound(60);
		message_dialog("A tremendous amount of healing magical energy pours into you. You are restored!","");
		}
break;

beginstate 16;
	reset_dialog_preset_options(8);
	if (run_dialog(1) == 2) {
		flip_terrain(38,40);
		flip_terrain(39,40);
		flip_terrain(40,40);
		}
	else
		block_entry(1);
break;

beginstate 17;
	reset_dialog_preset_options(8);
	if (run_dialog(1) == 2) {
		flip_terrain(17,33);
		flip_terrain(17,34);
		flip_terrain(17,35);
		}
	else
		block_entry(1);
break;

beginstate 18;
	if (get_flag(54,1) == 0) {
		message_dialog("You step into this room, and you are immediately struck by the two-fold appearance: it appears at once to be a bedroom and a torture chamber. A bed and a small dresser are on one side, the bed recently slept-in, proof that someone lives here even now.","On the other side, though, is a freshly slain body, so mutilated that its origin is indistinct, bloodstains, and a dummy used for dagger-throwing practice. What kind of monster would want this in his own bedroom?");
		set_flag(54,1,1);
		}
break;

beginstate 19;
	message_dialog("This body is so badly mutilated that you can't even tell what it once was.","");
break;

beginstate 20;
if (get_flag(54,2) == 0) {
	reset_dialog();
	add_dialog_str(0,"Buried in this nest here is a spellbook! One of the creatures that live here must have secretly taken it from one of the magicians and stored it, out of instinct, in its nest.",0);
	add_dialog_str(1,"The book has ghoulish scribbles all across the front cover. Some look very much like the ancient slith word _Kithunon_: danger!",0);
	add_dialog_str(2,"Reading strange spellbooks can be dangerous: they can carry curses or other terrible effects. However, they can also have great spells recorded within.",0);
	add_dialog_str(3,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Attempt to read it.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		// Requires Arcane Lore of 28.
		if (get_skill_total(42) >= 28) {
			set_flag(54,2,1);
			add_dialog_str(0,"The book is written in a strange rune script, but fortunately, due to your knowledge of Arcane Lore, you can read it.",0);
			if (get_flag(292,14) == 0) // flag for spell
				add_dialog_str(1,"The book describes an interesting new spell, one that blasts all enemies in sight with terrible, damaging energy. (You learn a level of Death Knell.)",0);
			else
				add_dialog_str(1,"It's a spellbook describing how to cast Death Knell more efficiently. You read over it carefully.",0);
			inc_flag(292,14,run_dialog(1)); // flag for spell
			set_flag(292,0,1);
			}
		else
			message_dialog("The book is written in a strange rune script, and unfortunately, you can't read it. Perhaps if you knew more about Arcane Lore, you would be able to.","");
		}
	}
else
	message_dialog("You find the book on Death Knell again, but you don't learn anything new from it.","");
break;

beginstate 21;
if (get_flag(54,3) == 1)
	message_dialog("You find the cursed book again, but you don't read it this time.","");
else {
	reset_dialog();
	add_dialog_str(0,"On these shelves, you find a small, rune-covered book. It appears to be a spellbook!",0);
	add_dialog_str(1,"Reading strange spellbooks can be dangerous: they can carry curses or other terrible effects. However, they can also have great spells recorded within.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Read it.");
	if (run_dialog(1) == 2) {
		set_flag(54,3,1);
		message_dialog("You begin reading. The book describes some of the unholy rituals performed in the temple to the north, ghastly sacrifices of innocents in the name of unhallowed bloodlust.","As you read, you feel yourself reciting words imbedded between the lines on the page. The book is cursed! Before you can get very far, you cast the book away, but it is too late: you feel weak and frail. (You have received a Dread Curse.)");
		alter_stat(1000,31,3);
		}
	}
break;

beginstate 22;
	if (get_flag(54,4) == 0) {
		message_dialog("You notice as you pass this way that there is no way to open the gates from this side. Presumably the people who live upstairs rely on someone in the guard room to open the gates for them. However, you can't do the same.","That means that it's very likely that, if you go up this way, someone will close the gates behind you and you will not be able to get back out.");
		set_flag(54,4,1);
		}
break;

beginstate 23;
	if (get_flag(54,5) == 0) {
		message_dialog("You enter this monstrous fortification, and you can hear very little. The halls are quiet.","The sign on the wall says, _Nghathlaghzhanthe Basrheekhoon_: Castle of Nathaganth. You are in the home of the darkest god in the entire slith pantheon, the lord of all evil and bringer of ill. You begin to sweat from the unnatural heat.");
		set_flag(54,5,1);
		}
break;

beginstate 24;
	reset_dialog();
	add_dialog_str(0,"This book details the experiments that went on in this room. Apparently the vahnatai here were interested in the very essence of life and how to change it, seeking to create new and more dangerous life forms for battle.",0);
	add_dialog_str(1,"Their failures were gruesome, but their successes were even more so. They created twisted being that hungered only for destruction, strange fire-breathing lizards, terrible giant scorpions, and intelligent tentacled land-octopuses.",0);
	add_dialog_str(2,"Apparently their latest creations, war-wolves, are housed beyond the gates to the south, and one note gets your interest: _The damn beasts have stolen one of our most powerful spellbooks. We must retrieve it once we find a way to subdue the creatures._",0);
	run_dialog(1);
break;

beginstate 25;
	if (get_flag(54,13) == 0) {
		message_dialog("In this room, there is a smithy. You can see raw iron and metals, waiting to be forged into weapons and armor. However, this is Nathaganth's smithy: weapons, after they are forged, are blessed with the dark god's touch.","This appears to involve unspeakable rites performed on the altar in the south.");
		set_flag(54,13,1);
		}
break;

beginstate 26;
if (get_flag(54,7) < 3) {
	block_entry(1);
	message_dialog("You attempt to approach this dark altar, but you cannot. A deep, dark, sibilant voice whispers in your mind, _First you must come from the light into the darkness._","");
	}
else {
	reset_dialog();
	add_dialog_str(0,"You approach this dark altar. What do you do?",0);
	add_dialog_choice(0,"Nothing.");
	add_dialog_choice(1,"Kneel and worship.");
	if (run_dialog(1) == 2) {
		message_dialog("You fall to your knees and worship at the bloody altar of Nathaganth. Your prayers draw the attention of the dark god, however, and before you are finished speaking, you are surrounded by his guards. They slaughter you mercilessly.","");
		kill_char(1000,2,0);
		}
	}
break;

beginstate 27;
	reset_dialog();
	add_dialog_str(0,"There is a small, simple pool of light blue water here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Drink some.");
	add_dialog_choice(2,"Wash yourself.");
	choice = run_dialog(1);
	if (choice == 2)
		message_dialog("The water tastes bitter. You can't tell if anything happens, though.","");
	if (choice == 3) {
		message_dialog("The water is cold and soothing. You can't tell if anything happens, though.","");
		set_flag(54,7,1);
		}
break;

beginstate 28;
	reset_dialog();
	add_dialog_str(0,"There is a small, simple pool of blue water here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Drink some.");
	add_dialog_choice(2,"Wash yourself.");
	choice = run_dialog(1);
	if (choice == 2)
		message_dialog("The water tastes bitter. You can't tell if anything happens, though.","");
	if (choice == 3) {
		message_dialog("The water is cold and soothing. You can't tell if anything happens, though.","");
		if (get_flag(54,7) == 1)
			inc_flag(54,7,1);
		else
			set_flag(54,7,0);
		}
break;

beginstate 29;
	reset_dialog();
	add_dialog_str(0,"There is a small, simple pool of purple water here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Drink some.");
	add_dialog_choice(2,"Wash yourself.");
	choice = run_dialog(1);
	if (choice == 2)
		message_dialog("The water tastes bitter. You can't tell if anything happens, though.","");
	if (choice == 3) {
		message_dialog("The water is cold and soothing. You can't tell if anything happens, though.","");
		if (get_flag(54,7) == 2)
			inc_flag(54,7,1);
		else
			set_flag(54,7,0);
		}
break;

beginstate 30;
	if (get_flag(54,8) == 0) {
		message_dialog("Back here are two very scared-looking humans. They glance at you furtively while stirring their cooking pots.","");
		set_flag(54,8,1);
		}
break;

beginstate 31;
	message_dialog("This magnificent dark warrior finally collapses under his various injuries. Lying on top of his body, his shield gleams in the torchlight.","You hear a faint noise from the kitchen to the east.");
	set_flag(54,11,1);
break;

beginstate 32;
	reset_dialog();
	add_dialog_str(0,"This appears to be a seeing stone of some sort. You look into it and see images from far away.",0);
	add_dialog_str(1,"First you see Gnass, where Pathass has returned from his defeat at Vasskolis. He seems calmer, now, and you can see dismantling the rigid theocracy he has installed. He is retiring from public life, and you know he will live quietly from now on.",0);
	add_dialog_str(2,"Next you see some caverns deep under Avernum, where many barbarian sliths, formerly followers of Sss-Thsss, are gathering into a greater force than ever before. Ominously, they appear to be training together for a coming war.",0);
	add_dialog_str(3,"Then you see Thassaka, the last stronghold of civilization in the north, fighting off another attack of barbarians. They are strong enough to repulse them again, but for how much longer?",0);
	add_dialog_str(4,"You see flashes of everywhere where sliths inhabit, and the troubles and progress in each place, except the one place where you have not been: Khitaloss, in the center of the homeland. You have yet to see what is going on there.",0);
	run_dialog(1);
break;