begintownscript;

variables;
short dynamite,bmessage;

body;

beginstate 0;

	if(get_flag(9,0) >= 1){
		set_terrain(24,24,0);
		set_height(24,24,1);
		set_floor(24,24,71);
	}

	add_char_to_group(14,1);
	add_char_to_group(15,1);
	add_char_to_group(16,1);
	add_char_to_group(17,1);
	add_char_to_group(18,1);
	add_char_to_group(19,1);
	add_char_to_group(20,1);
	add_char_to_group(21,1);
	add_char_to_group(22,1);
	add_char_to_group(23,1);
	add_char_to_group(24,1);
	add_char_to_group(25,1);
	add_char_to_group(26,1);

	add_char_to_group(31,2);
	add_char_to_group(32,2);
	add_char_to_group(33,2);
	add_char_to_group(34,2);
	add_char_to_group(35,2);
	add_char_to_group(36,2);
	add_char_to_group(37,2);
	add_char_to_group(38,2);

	add_char_to_group(30,3);
	add_char_to_group(39,3);
	add_char_to_group(40,3);
	add_char_to_group(41,3);
	add_char_to_group(42,3);
	add_char_to_group(43,3);
	add_char_to_group(44,3);
	add_char_to_group(45,3);
	add_char_to_group(46,3);
	add_char_to_group(47,3);
	add_char_to_group(48,3);
	add_char_to_group(49,3);
	add_char_to_group(50,3);
	add_char_to_group(51,3);

	if(get_flag(58,0) == 0){
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"You almost get a pang of nostalgia.",0);
		add_dialog_str(1,"When you were studying at Kedalvasser, it was here where, after having snuck past the village gates, you marched into the city, slew a few guards at the city's entrance, and left.",0);
		add_dialog_str(2,"You were given an immediate graduation and special training thereafter.  And look at you now.",0);
		add_dialog_str(3,"Now, you've come back to complete the work you started.",0);
		bmessage = run_dialog(1);
		set_flag(58,0,1);
	}

break;

beginstate 1;
break;

beginstate START_STATE;
break;

beginstate 10;
	move_to_new_town(2,6,44);
break;

beginstate 11;
	move_to_new_town(2,18,30);
break;

beginstate 12;
	move_to_new_town(2,30,30);
break;

beginstate 13;
	move_to_new_town(2,35,23);
break;

beginstate 14;
	move_to_new_town(2,36,41);
break;

beginstate 15;
	if(get_flag(11,0) == 0){
		message_dialog("The plateau here is raised substantially higher than the rest of the village.  Based on how high it is, it must hold symbolic importance to the Bugbears.","Fortunately, it is currently unoccupied.  From the blood on the ground, the Bugbears must use this as some sort of initiation ground for warriors.");
		set_flag(11,0,1);
	}
break;

beginstate 16;
	if(get_flag(9,0) == 0 && get_flag(10,0) >= 1){  //1
		if(has_special_item(40) >= 1){  //2
			reset_dialog();
			add_dialog_str(0,"The ground here is weak.  How it has stood firmly for so long is beyond you, but yet it still stands.",0);
			add_dialog_str(1,"While you can't see any way to make the ground crumble by physical or magical means, you do have a heap of dynamite, which if not effective at getting something done, is still loads of fun.",0);
			add_dialog_choice(0,"Blow it up!");
			add_dialog_choice(1,"Leave it be.");
			dynamite = run_dialog(1);
			if(dynamite == 2)
				end();
			message_dialog("You take a liberal portion of dynamite that you have collected, place it on the ground, and set the fuse.","After having reached a suitable distance, you turn towards the pillar and wait anxiously...");
			relocate_character(0,24,20);
			relocate_character(1,23,20);
			relocate_character(2,25,20);
			relocate_character(3,22,20);
			relocate_character(4,26,20);
			force_view_center(24,23);
			force_instant_terrain_redraw();
			pause(10);

			set_terrain(24,24,0);
			set_height(24,24,1);
			set_floor(24,24,71);
			put_boom_on_space(23,24,1,0);
			put_boom_on_space(25,24,1,0);
			put_boom_on_space(24,23,1,0);
			put_boom_on_space(24,25,1,0);
			force_instant_terrain_redraw();
			run_animation_sound(152);

			message_dialog("Success!  The dynamite sends the pillar a whopping two inches into the air, but shatters the ground beneath it completely.","The pillar slides down smoothly to the floor below, and falls with a satisfying _Thwap!_.");
			message_dialog("It then strikes you that what you just did was loud, brash, and most certainly attention-grabbing.","You are reminded of this fact, unfortunately, by two powerful-looking warriors climbing up to the platform.");

			set_total_visibility(1);
			force_view_center(24,26);
			activate_hidden_group(1);
			force_instant_terrain_redraw();
			pause(4);

			relocate_character(52,25,29);
			relocate_character(53,23,29);
			force_instant_terrain_redraw();
			pause(4);

			relocate_character(52,25,28);
			relocate_character(53,23,28);
			force_instant_terrain_redraw();
			pause(4);

			relocate_character(52,25,27);
			relocate_character(53,23,27);
			force_instant_terrain_redraw();
			pause(4);

			set_character_facing(52,4);
			set_character_facing(53,4);
			force_instant_terrain_redraw();
			pause(4);

			set_character_pose(52,1);
			set_character_pose(53,1);
			set_terrain(23,29,475);
			set_terrain(24,29,475);
			set_terrain(25,29,475);
			put_effect_on_space(23,29,8,4,0);
			put_effect_on_space(24,29,8,4,0);
			put_effect_on_space(25,29,8,4,0);
			force_instant_terrain_redraw();
			run_animation_sound(90);
			pause(5);

			set_character_facing(52,0);
			set_character_facing(53,0);
			set_character_pose(52,2);
			set_character_pose(53,2);
			force_instant_terrain_redraw();
			pause(5);

			erase_char(52);
			erase_char(53);
			activate_hidden_group(2);
			put_boom_on_space(25,27,4,0);
			put_boom_on_space(23,27,4,0);
			force_instant_terrain_redraw();
			run_animation_sound(102);
			pause(4);

			message_dialog("Where did they go?  They summoned up odd-looking barriers, faced you, but then suddenly disappeared.  Strange...","You suspect that they are quite alive and well, and also that you have a significant battle ahead of you.  But how can you hit an enemy that you can't see?");
			set_total_visibility(0);
			set_flag(9,0,1);
			change_spec_item(40,-1);
			block_entry(1);
			force_view_center(24,20);
			force_instant_terrain_redraw();

		}

		else{
			message_dialog("The ground here is weak.  How it has stood firmly for so long is beyond you, but yet it still stands.","Unfortunately, the ground is quite solid, and it doesn't look like you have the means to break it apart.  Yet.");
		}
}
break;