// Town 25: Slime Pit L2
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	add_range_to_group(6,8,4);
	add_range_to_group(10,11,4);
	add_range_to_group(14,18,1);
	set_special_ability(1001,19);
	add_range_to_group(21,26,2);
	set_special_ability(1002,27);
	add_range_to_group(27,39,3);
	set_special_ability(37,19);
	set_special_ability(38,19);
	set_special_ability(39,19);
	
	change_blocked(43,43,1);
	change_blocked(43,44,1);
	change_blocked(43,45,1);
	change_blocked(44,43,1);
	change_blocked(44,44,1);
	change_blocked(44,45,1);
	
	change_blocked(4,1,1);
	change_blocked(5,1,1);
	change_blocked(4,2,1);
	change_blocked(5,2,1);
	change_blocked(4,3,1);
	change_blocked(5,3,1);
	change_blocked(4,4,1);
	change_blocked(5,4,1);
	change_blocked(4,5,1);
	change_blocked(5,5,1);
	
	if (get_flag(25,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(25,0,1);
		message_dialog("You descend into the second level of the slime pit, and by now you are covered in acidic filth. Evidently a great variety of slimes can live together, here in the muck.","You press on, searching for the tapestry.");
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	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(24,42,44);
break;

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

beginstate 12;
if (get_flag(25,2) == 0) {
	reset_dialog();
	add_dialog_str(0,"There is a frozen body here of a very old slith. It hasn't been subject to the same sort of decay as the other ancient corpses you have found, since it has been kept cold all this time. He appears to have been killed by the slimes in this cave.",0);
	add_dialog_str(1,"He carries some miscellaneous notes, and, more importantly, a spellbook! 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 24.
		if (get_skill_total(42) >= 24) {
			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,18) > 0) {
				set_flag(25,2,1);
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast Bonechill in the most efficient fashion possible. You read over it carefully.",0);
				set_flag(292,18,3); // flag for spell
				}
			else
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast a complex spell, Bonechill, 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 Bonechill again, but you don't learn anything new from it.","");
break;

beginstate 13;
if (is_combat()) {
	message_dialog("There is a beautiful, holy-feeling altar here. However, in the middle of battle, you can do nothing with regard to it.","");
	end();
	}

if (get_flag(25,3) == 0) {
	reset_dialog();
	add_dialog_str(0,"There is a beautiful and ancient altar here. It radiates holy energy, keeping the slimes away. 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: _Bitakhaeth theifaathi lotha Althanazaariaathi nookh ritan hoorithatha koot sitkaat sakhotha._ That is: praise be to the goddess Althanazaria, who has kissed us and sanctified us with her grace.",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) {
		set_flag(25,3,1);
		reset_dialog();
		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,7) > 0)
			add_dialog_str(1,"The voice describes an interesting new spell, one that makes your enemies drowsy. (You learn a level of Sleep Foe.)",0);
		else
			add_dialog_str(1,"The voice describes how to cast Sleep Foe more efficiently. You listen to it carefully.",0);
		inc_flag(292,7,run_dialog(1));
		set_flag(292,0,1);
		}
	}
else {
	reset_dialog();
	add_dialog_str(0,"You return to the altar. What do you do?",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 14;
	if (get_flag(25,1) == 0) {
		set_flag(25,1,1);
		message_dialog("Down this passage, the floor is covered with ice, and there are a few magic runes, too. You imagine that this must be the creation of some ancient magic-user who has since moved out, since none of the slimes you have seen so far can handle real magic.","Or perhaps this creature still lives here. If so, you cannot hear it.");
		}
break;