// Town 37: Manikoss
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	change_blocked(22,4,1);
	change_blocked(41,47,1);
	change_blocked(9,40,1);
	change_blocked(50,17,1);
	
	if (get_flag(23,7)) {
		set_terrain(52,34,31);
		set_terrain(52,35,31);
		set_terrain(52,36,31);
		set_terrain(52,37,31);
		set_terrain(52,38,31);
		}
	
	if (get_flag(37,7) != 0)
		set_terrain(7,54,0);
	
	if (get_flag(37,6) != 0)
		set_terrain(45,7,0);
	
	if (get_flag(37,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(37,0,1);
		message_dialog("You approach this old slith city, named (judging by the sign on the wall) Manikoss. It has very large, thick walls (like Thassaka's). It looks a little run-down, so you guess that, unlike Thassaka, it hasn't been lived in for a long time.","That must mean that it's over-run with monsters.");
		}
break;

beginstate EXIT_STATE;
if (has_special_item(3) == 3)
	if (get_flag(37,8) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you walk out of Manikoss, you are struck by the way the mushrooms are growing around it. They suck the poison out from the ground, and only a short distance away from the city, the ground is just as good as ever. The river, likewise, is pristine.",0);
		add_dialog_str(1,"The plants here are purifying the land, and you can see that, someday, all will be as it once was, clean and unblemished. But for the time being, the city of Manikoss has destroyed itself through lack of planning or foresight.",0);
		add_dialog_str(2,"Another thing is striking, too. You have seen no sign of the demon-worshipping barbarian sliths anywhere near here, and the poison in Manikoss must be responsible. A failure to live sustainably did not help either side; it left a wasteland.",0);
		add_dialog_str(3,"Anyway, you have what you came for. It is time to return to the camp and bring Kass the trees for the temple.",0);
		set_flag(37,8,run_dialog(1));
		}
break;

beginstate START_STATE;
break;

beginstate 10;
	if (get_flag(37,1) == 0) {
		set_flag(37,1,1);
		message_dialog("As you enter Manikoss, you notice something strange: unlike the other ruins you have seen, this city has not been destroyed! There are no signs of monster attacks or large battles. It looks as though everyone just picked up and left.","There is a fair bit of decay and rot around, though. Something was clearly wrong here, although it is a little hard to tell what.");
		}
break;

beginstate 11;
	if (get_flag(37,2) == 0) {
		set_flag(37,2,1);
		message_dialog("From the center of this city, you can see clearly that it has been corrupted somehow. The ground itself pours forth some contagion, a poison so befouling that it has contaminated the entire city and killed it.","You cannot see the trees anywhere. They must be inside somewhere.");
		}
break;

beginstate 12;
	reset_dialog_preset_options(8);
	if (run_dialog(1) == 2) {
		flip_terrain(24,40);
		flip_terrain(25,40);
		flip_terrain(26,40);
		flip_terrain(24,42);
		flip_terrain(25,42);
		flip_terrain(26,42);
		}
break;

beginstate 13;
	message_dialog("This wheel with a chain is supposed to control the east gates, but it has rusted to complete immobility. How Talas got the gates open, you will never know.","");
break;

beginstate 14;
	message_dialog("The papyrus scrolls on this shelf have all decayed to illegibility.","");
break;

beginstate 15;
	reset_dialog_preset_options(9);
	if (run_dialog(1) == 2)
		move_to_new_town(38,23,4);
	else
		block_entry(1);
break;

beginstate 16;
if (get_flag(37,3) == 0) {
	reset_dialog();
	add_dialog_str(0,"Most of the papyrus scrolls on this shelf have rotted away, but there is one book that has survived. It is 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 26.
		if (get_skill_total(42) >= 26) {
			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,17) > 0) {
				set_flag(37,3,1);
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast Inferno in the most efficient fashion possible. You read over it carefully.",0);
				set_flag(292,17,3); // flag for spell
				}
			else
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast a complex spell, Inferno, 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 Inferno again, but you don't learn anything new from it.","");
break;

beginstate 17;
if (get_flag(37,4) == 0) {
	reset_dialog();
	add_dialog_str(0,"It has very old slith writing on it, written in the classical tongue of the sliths, contemporary with the Khalthanad.",0);
	add_dialog_str(1,"It says: _Herethet tet, Soothaanam theifam lothamon koot kaalokh tem polenem fakhithathookh divem._ That is: with this temple, we praise the goddess Sothana and the noble men who have made this city rich.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Pray at the altar.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		set_flag(37,4,1);
		add_dialog_str(0,"You offer a simple prayer in the most formal slith language you can manage. When you finish, a soft, feminine, sibilant voice begins speaking in your mind. It is describing how to cast a spell!",0);
		if (get_flag(292,3) > 0)
			add_dialog_str(1,"The voice describes an interesting new spell, one that covers your enemies with a terrible, venomous film. (You learn a level of Filth.)",0);
		else
			add_dialog_str(1,"The voice describes how to cast Filth more efficiently. You listen to it carefully.",0);
		inc_flag(292,3,run_dialog(1));
		set_flag(292,0,1);
		}
	}
else {
	reset_dialog();
	add_dialog_str(0,"You return to the altar of Sothana.",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Pray at the altar again.");
	if (run_dialog(1) == 2)
		message_dialog("You pray at the altar again. You feel good about yourself, but nothing else happens.","");
	}
break;

beginstate 18;
	reset_dialog_preset_options(9);
	if (run_dialog(1) == 2)
		move_to_new_town(38,40,49);
	else
		block_entry(1);
break;

beginstate 19;
	reset_dialog_preset_options(9);
	if (run_dialog(1) == 2)
		move_to_new_town(38,8,40);
	else
		block_entry(1);
break;

beginstate 20;
	reset_dialog_preset_options(9);
	if (run_dialog(1) == 2)
		move_to_new_town(38,49,17);
	else
		block_entry(1);
break;

beginstate 21;
	if (get_flag(37,5) == 0) {
		message_dialog("This door is barred from this side. You remove the obstruction. You will be able to pass freely through this door now.","");
		set_flag(37,5,1);
		}
break;

beginstate 22;
	if (get_terrain(45,7) == 397) {
		reset_dialog();
		add_dialog_str(0,"This is one of the trees you've been sent to find. It grows like a surface tree, even here in the indoors, without even cavelight or fungus or much else. It must truly be blessed by a god or some powerful magic.",0);
		add_dialog_str(1,"What do you do?",0);
		add_dialog_choice(0,"Leave.");
		add_dialog_choice(1,"Take it.");
		if (run_dialog(1) == 2) {
			message_dialog("The tree is surprisingly light and easy to manipulate. It will not encumber you much as you walk around.","");
			set_terrain(45,7,0);
			set_flag(37,6,1);
			change_spec_item(3,1);
			}
		}
break;

beginstate 23;
	if (get_terrain(7,54) == 397) {
		reset_dialog();
		add_dialog_str(0,"This is one of the trees you've been sent to find. It grows like a surface tree, even in the pale cavelight. It must truly be blessed by a god or some powerful magic.",0);
		add_dialog_str(1,"What do you do?",0);
		add_dialog_choice(0,"Leave.");
		add_dialog_choice(1,"Take it.");
		if (run_dialog(1) == 2) {
			message_dialog("The tree is surprisingly light and easy to manipulate. It will not encumber you much as you walk around.","");
			set_terrain(7,54,0);
			set_flag(37,7,1);
			change_spec_item(3,1);
			}
		}
break;

beginstate 24;
	reset_dialog();
	add_dialog_str(0,"In this desk, you find a small book with what appear to be curses written in it. They start small, wishing poor luck upon various neighbors for various slights: _May Patha be barren this season, for she walks haughtily and spurned my affection._",0);
	add_dialog_str(1,"But slowly they grow more intense: _I pray to the god Anthalak that Nokten sicken and waste slowly into death,_ _Let Anthalak grant that Tamnoss bleed inside until he recedes from life,_ and _That Patha, who affronted me again, die, Anthalak grant._",0);
	add_dialog_str(2,"Soon the pages are covered with prayers to the dark god Anthalak, the lord of the misshapen and horrific. It seems that his prayers worked, too, because he records with glee that birth defects increased sharply after he began his worship.",0);
	add_dialog_str(3,"Of course, that may have been around the same time as when the poisons began to seep into everything, which would suggest a more physical cause.",0);
	add_dialog_str(4,"This slith records that others left as the poisons grew overwhelming, but he refused, believing that a true follower of the god would not be harmed. If that is his body in the corner, he was sorely mistaken.",0);
	run_dialog(1);
break;

beginstate 25;
	message_dialog("This slith is terribly warped and misshapen. He died perhaps some decades ago, and you can see that his bones are already grinding to dust: he was surely not very healthy when he died.","The awfully contorted position in which he lies suggests an excruciatingly painful death, too.");
break;