begintownscript;

variables;
short choice = 0;

body;

beginstate 0; //INIT_STATE
	if(get_flag(1,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"The nest looks like any other crack in the cave wall, but for the well-worn ground near the entrance.",0);
		add_dialog_str(1,"Fortunately for you, it looks like some of the same glowing crystal is dimly lighting the tunnels.",0);
		run_dialog(1);
		set_flag(1,0,1);
		}
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;

	//check for all chitrachs being dead
	if((get_flag(1,1) == 1) && (num_chars_in_group(1) == 0)) {
		set_flag(1,1,2);
		reset_dialog();
		add_dialog_str(0,"Well, that was odd. The chitrachs didn't seem that interested in fighting. In fact, it seemed more like they were trying to get past you.",0);
		run_dialog(1);
		}
	if((get_flag(1,2) == 1) && (char_ok(13) == 0)) {
		reset_dialog();
		add_dialog_str(0,"Interesting. The mist just kind of vanished. Not a trace left.",0);
		add_dialog_str(1,"At least your path is pretty clear now. You'll have to go further down and just hope that the nest leads you somewhere friendly. Though by the look of things, that's a long shot.",0);
		run_dialog(1);
		set_flag(1,2,2);
		}
break;

beginstate 10; //enter and get ambushed
	if(get_flag(1,1) > 0)
		end();
	play_sound(120);
	reset_dialog();
	add_dialog_str(0,"As you approach the entrance of the nest, you hear a loud scrabbling sound. Before you can react, a group of chitrachs rushes out at you.",0);
	run_dialog(1);
	activate_hidden_group(1);
	add_range_to_group(6,9,1);
	set_flag(1,1,1);

break;

beginstate 30; //before descending
	if(get_flag(1,2) > 0)
		end();
	reset_dialog();
	add_dialog_str(0,"You're beginning to wonder exactly what has these chitrachs so frightened. Probably the cavequake. But whatever it is, you're not complaining.",0);
	add_dialog_str(1,"What's that phrase... _The enemy of my enemy is my friend,_ or something like that.",0);
	add_dialog_str(2,"While you try and remember exactly how that phrase went, you hear a strange hissing sound.",0);
	run_dialog(1);
	pause(2);
	play_sound(42);
	pause(5);
	activate_hidden_group(2);
	force_instant_terrain_redraw();
	pause(5);
	relocate_character(13,6,28);
	put_effect_on_space(5,28,5,3,1);
	force_instant_terrain_redraw();
	run_animation();
	pause(5);
	relocate_character(13,7,28);
	put_effect_on_space(6,28,5,3,1);
	force_instant_terrain_redraw();
	run_animation();
	pause(2);
	relocate_character(13,8,28);
	put_effect_on_space(7,28,5,3,1);
	force_instant_terrain_redraw();
	run_animation();
	pause(15);

	reset_dialog();
	add_dialog_str(0,"Odd. The air around this... thing looks a bit darker than in the rest of the tunnel. Then again, you might just be hallucinating.",0);
	add_dialog_str(1,"Normally you wouldn't say this about a cloud, but it looks a bit hostile. Perhaps even malevolent. Either way, you're better off getting rid of it.",0);
	run_dialog(1);
	
	set_flag(1,2,1);
break;

beginstate 35; //ramp down
	if(is_combat() == 1) {
		block_entry(1);
		end();
		}
	if(get_flag(1,1) == 1) {
		block_entry(1);
		message_dialog("You should probably take care of the dark mist before you think about heading further down.","");
		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(2,39,23);
break;