beginoutdoorscript;

variables;
short choice = 0;

body;

beginstate 0; //INIT_STATE
break;

beginstate 1; //EXIT_STATE
break;

beginstate 2; //START_STATE
break;

beginstate 9; //funnel toward blocked exit
	if(get_flag(10,0) < 2) {
		block_entry(1);
		reset_dialog();
		add_dialog_str(0,"Where are you going? Go check that exit before something blocks it off!",0);
		run_dialog(1);
		}
break;

beginstate 10; //blocked exit
	if(get_flag(10,0) == 2)
		end();

	reset_dialog();
	add_dialog_str(0,"You struggle to find words as you see your best means of escape buried by rubble. Most of the words were probably better left unsaid, but you still spend a few minutes swearing at the rocks.",0);
	add_dialog_str(1,"Since the rocks don't seem to be listening, you should try and find another way out.",0);
	run_dialog(1);
	set_flag(10,0,2);
break;

beginstate 11; //guiding
	if(get_flag(10,0) > 0)
		end();
	reset_dialog();
	add_dialog_str(0,"Well, this is it. Time to cross your fingers and hope you can get out of here.",0);
	run_dialog(1);
	set_flag(10,0,1);
break;

beginstate 12; //east exit collapsed
	if(get_flag(10,1) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"Well, this exit doesn't look like it'll be of any help either.",0);
	run_dialog(1);
	set_flag(10,1,1);
break;

beginstate 13; //west exit collapsed
	if(get_flag(10,2) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"Well, this exit doesn't look like it'll be of any help either.",0);
	run_dialog(1);
	set_flag(10,2,1);
break;

beginstate 20; //chitrachs
	choice = 0;
	reset_dialog();
	if(get_flag(10,3) == 0) {
		add_dialog_str(0,"A band of chitrachs is wandering through the caves here. They seem nervous, if that's possible for what is essentially a giant cockroach.",0);
		add_dialog_str(1,"When they notice you, they start to skitter away. Very unusual.",0);
		add_dialog_str(2,"You could rid the cave of some pests, or let the jittery insects get away. What do you do?",0);
		}
	else
		add_dialog_str(0,"The chitrachs are still here, and still seem a bit frightened.",0);
	add_dialog_choice(0,"Attack!");
	add_dialog_choice(1,"Let them go.");
	choice = run_dialog(1);
	if(choice == 2) {
		outdoor_enc_result(1);
		message_dialog("The group of chitrachs quickly skitters away.","");
		set_flag(10,3,1);
		}
break;

beginstate 21; //beat chitrachs
	message_dialog("Well that was odd... they didn't even seem to want to eat you, like a normal chitrach would.","");
	set_flag(10,3,2);
break;

beginstate 25; //mushroom patch
	if(get_flag(10,4) == 1) {
		message_dialog("The mushrooms haven't regrown yet. Somehow, you have a feeling that if you wait for them to grow back, you'll die from starvation first.","");
		end();
		}
	reset_dialog();
	add_dialog_str(0,"Well, this is somewhat fortunate. These mushrooms are definitely edible, and since you might actually be trapped down here, it couldn't hurt to harvest some of them.",0);
	add_dialog_str(1,"Looks like you'll eat for at least one more day.",0);
	run_dialog(1);
	reward_give(5);
	reward_give(5);
	reward_give(5);
	reward_give(5);
	set_flag(10,4,1);
break;

beginstate 30; //approach chitrach cave
	if(get_flag(10,5) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"Well, it's beginning to look like you only have one option left. Chitrach are known to dig massive tunnel systems, and some mages propose that most of Avernum's caves are connected by them.",0);
	add_dialog_str(1,"Granted, this particular nest doesn't look all that impressive, and the fact that it looks like this area used to be a quarry of sorts for the sunken city makes you doubt the tunnels' security.",0);
	add_dialog_str(2,"Still, it's probably your best shot at this point. Killing chitrachs may not be the most enjoyable task, but it sure as hell beats starving to death.",0);
	run_dialog(1);

	if(get_highest_skill(16) > 5) {
		reset_dialog();
		add_dialog_str(0,"Thanks to your Nature Lore skill, you notice something about the chitrach tracks around this nest. Nearly all of them are leading away from the nest. It's almost as if they were fleeing it.",0);
		run_dialog(1);
		set_flag(20,0,1);
		}
	set_flag(10,5,1);
break;