begintownscript;

variables;
short choice = 0;

body;

beginstate 0; //INIT_STATE
	if(get_flag(2,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you descend deeper into the nest, you hear less and less scribbling. Also, the air feels a bit thicker.",0);
		add_dialog_str(1,"Maybe the chitrachs have all left.",0);
		run_dialog(1);
		set_flag(2,0,1);
		}
	if(get_flag(2,10) == 1) {
		set_terrain(14,24,394);
		set_terrain(14,25,394);
		set_terrain(14,26,394);
		}
break;

beginstate 1; //EXIT_STATE
break;

beginstate 2; //START_STATE
	//Checking for the lead pc each turn... not necessary here
	//pc_counter = 0;
	//while(char_ok(pc_counter) == 0) {
	//	pc_counter = pc_counter + 1;
	//	}
	//lead_char = pc_counter;
break;

beginstate 9; //slope back up
	if(is_combat() == 1) {
		block_entry(1);
		end();
		}
	choice = 0;
	reset_dialog();
	add_dialog_str(0,"The tunnel slopes up sharply here. Do you continue moving forward?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	choice = run_dialog(1);
	if(choice == 2)
		block_entry(1);
	else
		move_to_new_town(1,8,28);
break;

beginstate 15; //trench - east side center trench
	if(get_flag(2,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"The air coming up from this crevice is unusually moist and warm. This is probably what allows the few plants clinging to the edges of the crevice to survive down here.",0);
		add_dialog_str(1,"While it's reassuring that it's at least possible for things to survive down here, the crevice still presents a significant barrier to you getting out of here.",0);
		run_dialog(1);
		set_flag(2,1,1);
		}
	if(get_flag(2,2) == 0) {
		block_entry(1);
		put_effect_on_space(29,22,5,3,1);
		put_effect_on_space(29,23,5,3,1);
		run_animation_sound(75);
		pause(2);
		activate_hidden_group(1);
		force_instant_terrain_redraw();
		pause(5);
		reset_dialog();
		add_dialog_str(0,"Two more of the dark clouds rise up out of the crevice. Again, you're not sure how it's possible, but they look angry.",0);
		run_dialog(1);
		set_flag(2,2,1);
		}
break;

beginstate 16; //trench - west side center trench
	if(get_flag(2,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"The air coming up from this crevice is unusually moist and warm. This is probably what allows the few plants clinging to the edges of the crevice to survive down here.",0);
		add_dialog_str(1,"While it's reassuring that it's at least possible for things to survive down here, the crevice still presents a significant barrier to you getting out of here.",0);
		run_dialog(1);
		set_flag(2,1,1);
		}
	if(get_flag(2,3) == 0) {
		block_entry(1);
		put_effect_on_space(24,25,5,3,1);
		put_effect_on_space(25,23,5,3,1);
		run_animation_sound(75);
		pause(2);
		activate_hidden_group(2);
		force_instant_terrain_redraw();
		pause(5);
		reset_dialog();
		add_dialog_str(0,"Two more of the dark clouds rise up out of the crevice. Again, you're not sure how it's possible, but they look angry.",0);
		run_dialog(1);
		set_flag(2,3,1);
		}
break;

beginstate 17; //trench - south side south trench
	if(get_flag(2,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"The air coming up from this crevice is unusually moist and warm. This is probably what allows the few plants clinging to the edges of the crevice to survive down here.",0);
		add_dialog_str(1,"While it's reassuring that it's at least possible for things to survive down here, the crevice still presents a significant barrier to you getting out of here.",0);
		run_dialog(1);
		set_flag(2,1,1);
		}
	if(get_flag(2,5) == 0) {
		block_entry(1);
		put_effect_on_space(27,38,5,3,1);
		put_effect_on_space(29,38,5,3,1);
		run_animation_sound(75);
		pause(2);
		activate_hidden_group(3);
		force_instant_terrain_redraw();
		pause(5);
		reset_dialog();
		add_dialog_str(0,"Two more of the dark clouds rise up out of the crevice. Again, you're not sure how it's possible, but they look angry.",0);
		run_dialog(1);
		set_flag(2,5,1);
		}
break;

beginstate 18; //trench - north side south trench
	if(get_flag(2,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"The air coming up from this crevice is unusually moist and warm. This is probably what allows the few plants clinging to the edges of the crevice to survive down here.",0);
		add_dialog_str(1,"While it's reassuring that it's at least possible for things to survive down here, the crevice still presents a significant barrier to you getting out of here.",0);
		run_dialog(1);
		set_flag(2,1,1);
		}
	if(get_flag(2,4) == 0) {
		block_entry(1);
		put_effect_on_space(25,34,5,3,1);
		put_effect_on_space(26,33,5,3,1);
		run_animation_sound(75);
		pause(2);
		activate_hidden_group(4);
		force_instant_terrain_redraw();
		pause(5);
		reset_dialog();
		add_dialog_str(0,"Two more of the dark clouds rise up out of the crevice. Again, you're not sure how it's possible, but they look angry.",0);
		run_dialog(1);
		set_flag(2,4,1);
		}
break;

beginstate 20; //dead chitrachs defending nest
	if(get_flag(2,6) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"There's a couple of dead chitrachs back by this cluster of nests. It almost looks like they died trying to defend their nests.",0);
	add_dialog_str(1,"If the puddles of slime are any indication, that attempt failed.",0);
	run_dialog(1);
	set_flag(2,6,1);
break;

beginstate 25; //massacred larva
	if(get_flag(2,7) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"This is gruesome. This chamber is virtually coated in slime, probably from slain chitrach larvae.",0);
	add_dialog_str(1,"It looks as if one chitrach put up some resistance to its young being eaten. Clearly, it failed.",0);
	run_dialog(1);
	set_flag(2,7,1);
break;

beginstate 30; //mist trap, n tunnel
	if(get_flag(2,8) == 1)
		end();
	message_dialog("You feel a strange breeze flow through the tunnel.","");
	pause(7);
	put_effect_on_space(30,11,5,3,1);
	run_animation_sound(75);
	block_entry(1);
	activate_hidden_group(5);
	force_instant_terrain_redraw();
	pause(5);
	set_flag(2,8,1);
break;

beginstate 31; //mist trap, se tunnel
	if(get_flag(2,9) == 1)
		end();
	message_dialog("You feel a strange breeze flow through the tunnel.","");
	pause(7);
	put_effect_on_space(34,34,5,3,1);
	run_animation_sound(75);
	block_entry(1);
	activate_hidden_group(6);
	force_instant_terrain_redraw();
	pause(5);
	set_flag(2,9,1);
break;

beginstate 40; //approach the next downslope
	if(get_flag(2,10) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"You're starting to lose hope. The further this tunnel goes down, the farther you are from civilization. At this point, you're probably just making your eventual grave harder to find.",0);
	add_dialog_str(1,"And then, you hear a voice.",0);
	add_dialog_str(2,"_That's it... give up now._",20);
	add_dialog_str(3,"You spin around to look for the voice's source...",0);
	run_dialog(1);
	pause(3);
	set_character_facing(0,2);
	set_character_facing(1,0);
	set_character_facing(2,4);
	set_character_facing(3,6);
	force_instant_terrain_redraw();
	pause(3);
	set_character_facing(0,4);
	set_character_facing(1,2);
	set_character_facing(2,6);
	set_character_facing(3,0);
	force_instant_terrain_redraw();
	pause(3);
	set_character_facing(0,6);
	set_character_facing(1,4);
	set_character_facing(2,0);
	set_character_facing(3,2);
	force_instant_terrain_redraw();
	pause(3);
	set_character_facing(0,0);
	set_character_facing(1,6);
	set_character_facing(2,2);
	set_character_facing(3,4);
	force_instant_terrain_redraw();
	pause(5);
	put_effect_on_space(14,24,5,7,1);
	put_effect_on_space(14,25,5,7,1);
	put_effect_on_space(14,26,5,7,1);
	set_terrain(14,24,394);
	set_terrain(14,25,394);
	set_terrain(14,26,394);
	run_animation_sound(75);
	pause(3);
	reset_dialog();
	add_dialog_str(0,"A wall of mist appears to block you into the chamber. Fortunately, it doesn't move to attack you.",0);
	add_dialog_str(1,"It looks like your only option is to press forward.",0);
	run_dialog(1);
	set_flag(2,10,1);
break;

beginstate 41; //pushing against the mist
	if((get_flag(20,2) == 0) && (get_flag(2,10) == 1)) {
		reset_dialog();
		add_dialog_str(0,"You push against the mist, and find that it doesn't yield. It doesn't seem to be the same kind of mist that attacked you before, but it's similar enough to worry you.",0);
		run_dialog(1);
		set_flag(20,2,1);
		end();
		}
break;

beginstate 50; //downslope
	if(is_combat() == 1) {
		block_entry(1);
		end();
		}
	choice = 0;
	reset_dialog();
	add_dialog_str(0,"The tunnel slopes down sharply here. Do you continue moving forward?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	choice = run_dialog(1);
	if(choice == 2)
		block_entry(1);
	else
		move_to_new_town(3,40,10);
break;