// Town 26: Fekhthen
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	change_blocked(12,1,1);
	change_blocked(12,2,1);
	change_blocked(11,1,1);
	change_blocked(11,2,1);
	change_blocked(10,1,1);
	change_blocked(10,2,1);
	change_blocked(9,2,1);
	change_blocked(10,3,1);
	change_blocked(9,3,1);
	change_blocked(10,4,1);
	change_blocked(9,4,1);
	change_blocked(10,5,1);
	change_blocked(9,5,1);
	change_blocked(10,6,1);
	change_blocked(9,6,1);
	change_blocked(10,7,1);
	change_blocked(9,7,1);
	change_blocked(10,8,1);
	change_blocked(9,8,1);
	change_blocked(9,9,1);
	change_blocked(8,8,1);
	change_blocked(8,9,1);
	change_blocked(7,8,1);
	change_blocked(7,9,1);
	change_blocked(7,10,1);
	change_blocked(6,9,1);
	change_blocked(6,10,1);
	change_blocked(5,9,1);
	change_blocked(5,10,1);
	change_blocked(4,9,1);
	change_blocked(4,10,1);
	change_blocked(3,9,1);
	change_blocked(3,10,1);
	change_blocked(2,9,1);
	change_blocked(2,10,1);
	change_blocked(1,9,1);
	change_blocked(1,10,1);
	
	add_range_to_group(12,16,1);
	set_special_ability(1001,33);
	add_range_to_group(22,32,2);
	add_range_to_group(33,50,3);
	add_char_to_group(6,3);
	set_special_ability(47,13);
	set_special_ability(48,13);
	set_special_ability(49,13);
	set_special_ability(50,13);
	
	set_name(6,"Old One-Eye");
	
	if (get_flag(26,7) == 1)
		make_town_hostile();
	
	if (get_flag(26,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(26,0,1);
		message_dialog("You descend to the third level of the slime pit, and suddenly, from your vantage point, you can see the remains of an old city! The crops grown here were so strong that you can make out distinctive breeds even now, after hundreds of years.","Presumably here you will find the tapestry you seek.");
		}
	
	if (has_special_item(2) > 0)
		set_terrain(40,3,0);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
if (get_terrain(40,3) == 502) {
	reset_dialog_preset_options(1);
	add_dialog_str(0,"You reach the tapestry about which Kass told you. It is woven with a golden thread, rendering the ancient slith design more colorfully and more precisely than any previous tapestry you've seen. It is beautiful.",0);
	add_dialog_str(1,"What do you wish to do?",0);
	if (run_dialog(1) == 2) {
		change_spec_item(2,1);
		set_flag(24,1,1);
		set_terrain(40,3,0);
		if (get_flag(26,5) == 0) {
			make_town_hostile();
			set_flag(26,7,1);
			}
		message_dialog("You take the tapestry. Now all that remains is to escape this pit and return to the camp.","");
		}
	}
break;

beginstate 11;
	reset_dialog();
	add_dialog_str(0,"The ground slopes sharply up here. Do you climb up it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb up it.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		move_to_new_town(25,3,3);
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0,"Protected from the slimes by runes, the book on this pedestal is untouched by the decay that has obliterated everything else in this town. One page is still legible, and a second page is stuffed in the book, presumably from another book entirely.",0);
	add_dialog_str(1,"Reading strange old books can be dangerous: they can carry curses or other terrible effects. However, they can also have great secrets recorded within.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Attempt to read the first page.");
	add_dialog_choice(2,"Attempt to read the second page.");
	choice = run_dialog(1);
	if (choice == 2) {
		reset_dialog();
		add_dialog_str(0,"It's a message from the city council! It describes briefly the arguments over abandoning the town, which was apparently under attack from slimes. Clearly the pro-abandonment side won, and so did the slimes.",0);
		add_dialog_str(1,"It adds, _I, Panakoss, have recorded these things in order that they may not be forgotten. Fekhthen, the home of my ancestors for generations, has been lost because neither Thassaka nor Manikoss was willing to send help to defeat the slimes._",0);
		add_dialog_str(2,"He concludes ominously, _Nis lazhisi kekois tesonis biteenekh poleni, Rhekhoon Khalthaase thenein pefeireth._ That is, unless the cities will be more generous to the nearby towns, the Empire of Khalthas will be destroyed utterly.",0);
		add_dialog_str(3,"The message is dated from just over two-hundred fifty years ago.",0);
		run_dialog(1);
		}
	if (choice == 3) {
		reset_dialog();
		if (get_flag(26,1) == 0) {
			// Requires Arcane Lore of 25.
			if (get_skill_total(42) >= 25) {
				set_flag(26,1,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(293,1) == 0) // flag for spell
					add_dialog_str(1,"The book describes an interesting new spell, one that deadens an enemy's muscles. (You learn a level of Paralyze.)",0);
				else
					add_dialog_str(1,"The page describes how to cast Paralyze more efficiently. You read over it carefully.",0);
				inc_flag(292,8,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 read the page on Paralyze again, but you don't learn anything new from it.","");
		}
break;

beginstate 13;
	if (get_flag(26,2) == 0) {
		set_flag(26,2,1);
		message_dialog("This library, despite some cracks and dust from centuries without maintenance, is still mostly intact. The scrolls on the shelves are decayed significantly, which means that few will be readable, but something may yet remain that is useful.","");
		}
break;

beginstate 14;
if (get_flag(26,3) == 0) {
	reset_dialog();
	add_dialog_str(0,"Amidst the many decayed papyrus scrolls and primitive books on the shelves, you find one that seems still intact! 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 it alone.");
	add_dialog_choice(1,"Attempt to read it.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		// Requires Arcane Lore of 25.
		if (get_skill_total(42) >= 25) {
			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);
			// Requires some skill in the spell already.
			if (get_flag(292,2) > 0) {
				set_flag(26,3,1);
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast Poison in the most efficient fashion possible. You read over it carefully.",0);
				set_flag(292,2,3); // flag for spell
				}
			else
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast a complex spell, Poison, in a very efficient manner. Unfortunately, you are completely unfamiliar with the spell, so it is too hard for you to understand.",0);
			run_dialog(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 Poison again, but you don't learn anything new from it.","");
break;

beginstate 15;
	if (get_flag(26,4) == 0) {
		set_flag(26,4,1);
		message_dialog("You step inside a large throne room, which is filled with slimes of many different kinds. Oddly enough, they aren't attacking you yet. They watch you closely, but the biggest one, the one at the end of the room, motions with a tentacle to hold back.","Apparently these slimes are peaceful. Or something.");
		}
break;