// Town 24: Slime Pit L1
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	add_range_to_group(38,43,1);
	add_range_to_group(44,47,2);
	set_special_ability(1002,19);
	set_level(1002,85);
	
	add_range_to_group(48,54,3);
	set_special_ability(52,28);
	
	change_blocked(44,43,1);
	change_blocked(44,44,1);
	change_blocked(44,45,1);
	change_blocked(45,43,1);
	change_blocked(45,44,1);
	change_blocked(45,45,1);
	
	if (get_flag(24,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(24,0,1);
		message_dialog("You enter what appears to be a slime pit, a home of semi-sentient slime monsters. Acidic filth covers everything, and the ground itself oozes poison. Mushrooms grow everywhere, and there are some items hidden in them here and there.","Odd. The slimes are intelligent enough to hoard items? Well, everything else in these caves has been more advanced than its counterpart in Avernum, so the slimes may as well be, too.");
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	if (get_flag(24,2) == 0) {
		set_flag(24,2,1);
		message_dialog("This magic rune was apparently hastily drawn by the creature whose body lies beyond. It does no harm to you; it must be designed to keep out the slimes or other evil creatures.","");
		}
break;

beginstate 11;
if (get_flag(24,3) == 0) {
	reset_dialog();
	add_dialog_str(0,"This ancient skeleton appears to be that of a slith. He must have died back in this corner after drawing the protection rune to save his body from defilement.",0);
	add_dialog_str(1,"Little remains of him except 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) {
		// Requires Arcane Lore of 25.
		if (get_skill_total(42) >= 25) {
			set_flag(24,3,1);
			message_dialog("The book is written in a strange rune script, but fortunately, due to your knowledge of Arcane Lore, you can read it.","It's a spellbook describing how to cast Curing and Fireblast more efficiently. You read over it carefully.");
			change_spell_level(0,1,1,1);
			change_spell_level(1,1,1,1);
			change_spell_level(2,1,1,1);
			change_spell_level(3,1,1,1);
			change_spell_level(0,0,16,1);
			change_spell_level(1,0,16,1);
			change_spell_level(2,0,16,1);
			change_spell_level(3,0,16,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 Curing and Fireblast again, but you don't learn anything new from it.","");
break;

beginstate 12;
if (get_flag(24,4) == 0) {
	reset_dialog();
	add_dialog_str(0,"Hidden in the mushrooms is a spellbook! It contains two pages that are still legible after years of decomposition in the acidic and poisonous muck.",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 the first page.");
	add_dialog_choice(2,"Attempt to read the second page.");
	choice = run_dialog(1);
	if (choice == 2) {
		message_dialog("You struggle to read the difficult language, which is obscure and jargon-laden. You feel yourself getting a headache, and then your stomach feels ill. The weakness spreads throughout your whole body.","You close the book, but it's too late: you feel terrible. (You have acquired a Dread Curse.)");
		alter_stat(1000,31,2);
		}
	if (choice == 3) {
		reset_dialog();
		// Requires Arcane Lore of 24.
		if (get_skill_total(42) >= 24) {
			set_flag(24,4,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 page describes an interesting new spell, one that hides you from your enemies. (You learn a level of Sanctuary.)",0);
			else
				add_dialog_str(1,"The page describes describing how to cast Sanctuary more efficiently. You read over it carefully.",0);
			inc_flag(293,1,run_dialog(1)); // flag for spell
			set_flag(293,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 Sanctuary again, but you don't learn anything new from it.","");
break;

beginstate 13;
	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(25,45,45);
break;

beginstate 14;
if (get_flag(24,5) == 0) {
	reset_dialog();
	add_dialog_str(0,"This very old dead body is not even recognizable. You can't tell if this is a vahnatai, a slith, a berekh, a demon, or something else. However, you can tell that it has a spellbook with one page that is still legible.",0);
	add_dialog_str(1,"Reading the spellbook may be very dangerous. The creature may have died from casting the spell, which may be cursed, or if the creature is a demon, the spell may do horrible things. Then again, it may be quite powerfully useful.",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) {
			set_flag(24,5,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,4) == 0) // flag for spell
				add_dialog_str(1,"The book describes two interesting new spells, which store and then summon your enemies. (You learn a level of Capture Soul and of Recall Soul.)",0);
			else
				add_dialog_str(1,"It's a spellbook describing how to cast Capture Soul and Recall Soul more efficiently. You read over it carefully.",0);
			inc_flag(292,4,run_dialog(1)); // flag for spell
			inc_flag(292,5,1);
			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 Capture Soul and Recall Soul again, but you don't learn anything new from it.","");
break;