// OUTDOOR SECTION SCRIPT
//    Section: X = 0, Y = 8: Strange Cave

beginoutdoorscript;

variables;

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

body;

beginstate INIT_STATE;
// This state called whenever this section is loaded into memory.
break;

beginstate START_STATE;
// Starting state of the section, called every turn the party 
// stands inside this section until you change the state.
	if (get_flag(208,0) == 1)
		set_terrain(30,25,458);
break;

beginstate 10;
if (get_skill_total(16) < 21) {
	message_dialog("The ground here is lumpy. Odd.","(Your Nature Lore isn't high enough for you to know what this means.)");
	end();
	}
	
if (get_terrain(30,25) == 396) {
	reset_dialog();
	add_dialog_str(0,"The ground here is lumpy and turned over. Your Nature Lore detects that someone must have buried something here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Dig.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		add_dialog_str(0,"You find a small, pretty ring. You can't see anything special about it. It must have had some value for someone to have buried it like this, though.",0);
		if (reward_give(493) == 1) { // Ring of Clarity
			set_flag(208,0,1);
			set_terrain(30,25,458);
			add_dialog_str(1,"You pack away your discovery.",0);
			}
		else
			add_dialog_str(1,"Unfortunately, you can't carry what you've found, so you leave it buried there.",0);
		run_dialog(1);
		}
	}
break;

beginstate 11;
if (get_flag(208,1) == 0) {
	reset_dialog();
	add_dialog_str(0,"You find the body of a slith. The bones are not so old as to have been from the early classical period; this slith may have died not many years ago. The cause of death is hard to tell, though.",0);
	add_dialog_str(1,"You look at his body, and you discover a small, rune-covered book. Opening it, you realize that it is a spellbook! Part of it is still legible, too.",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 26.
		if (get_skill_total(42) >= 26) {
			set_flag(208,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(292,6) == 0) // flag for spell
				add_dialog_str(1,"The book describes an interesting new spell, one that greatly confuses the mind of your enemy, making it less able to think clearly. (You learn a level of Destroy Mind.)",0);
			else
				add_dialog_str(1,"It's a spellbook describing how to cast Destroy Mind more efficiently. You read over it carefully.",0);
			inc_flag(292,6,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 Destroy Mind again, but you don't learn anything new from it.","");
break;