begintownscript;

variables;
short i;
short controls;
short bmessage,talk;

body;

beginstate 0;

	set_crime_tolerance(5);

	set_char_dialogue_pic(7,402,0);
	set_char_dialogue_pic(8,401,0);

	if(get_flag(4,0) >= 1)
		set_terrain(14,14,138);

	if(get_flag(5,0) >= 1)
		erase_char(8);

	if(get_flag(5,0) == 0)
		set_terrain(13,12,40);
	if(get_flag(5,0) >= 1)
		set_terrain(13,12,56);

	if(get_flag(23,0) >= 9){
		erase_char(7);
	}

	set_name(9,"Menage");
	set_name(10,"Artigiano");
	set_name(46,"Dandy Dobson");
	set_name(59,"Alexander");

	if(get_flag(65,0) == 1){
		activate_hidden_group(6);
		set_name(59,"Alexander");
	}

break;

beginstate 1;
break;

beginstate START_STATE;

	if(get_crime_level() > 0){
		message_dialog("You are sitting in the middle of a fortress lined with lasers and stuffed with the nation's most elite soldiers.  All of these things are now hostile to you.","You are restrained, imprisoned, and killed slowly and painfully.");
		kill_char(1000,3,0);
	}

break;

beginstate 10;
	if(get_flag(1,0) == 0){
		if(get_flag(2,0) == 0)
			message_dialog("Remember, there is a key in the chest here which will open one of the storerooms on this level.","Considering how dangerous your mission could be, you had better take advantage of Leader's generosity.");
		large_draw_pic_dialog(415,"Helpful Advice:");
		message_dialog("Also, Cloud of Blades has been DISABLED in this scenario!","You will not be able to use or train in Cloud of Blades, although all levels of it you entered the scenario will be restored to you when you leave if you do not leave by way of the Character Editor.");
		set_flag(1,0,1);
	}
break;

// CHEST node, place things here
beginstate 11;
	if(get_flag(2,0) == 0){
		set_flag(2,0,1);
		change_spec_item(20,1);
		message_dialog("In the chest here, you find a solid, iron key.  With it, there is a small note saying, _Use this for the storehouse.  Goods for your mission are inside._","After reading the terse quip, you pocket the item.  This should come in handy.");
	}

break;

beginstate 12;
	if(get_flag(3,0) == 0){
		set_flag(3,0,1);
		message_dialog("That's strange- there's a secret passage up here, with a stairway leading up.  Where could it lead to?","Perhaps you should investigate.");
	}
break;

beginstate 13;
	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}
	if(get_flag(3,0) == 1){
		set_flag(3,0,2);
		message_dialog("The stairway here leads to the surface.  But why would there be a secret entrance into Schwertschrein?","Regardless, this could come in handy later.");
	}
	move_to_new_town(3,7,7);
break;

beginstate 14;
	if(get_flag(4,0) == 0 && get_flag(23,0) <= 8){
		message_dialog("Up ahead, you see General Moerder in the training room.  She's the most diabolical general in Leader's army, capable of killing anyone in a one-on-one duel.  Right now, she looks heavily damaged, but she is smirking as usual.","Then, her sword begins to glow...");

		if(get_flag(75,0) == 0){
			talk = 14;
		}
		else{
			talk = get_flag(75,0);
		}

		set_total_visibility(1);
		force_view_center(14,16);
		force_instant_terrain_redraw();
		pause(3);
		set_character_pose(7,2);
		text_bubble_on_char(7,"Notangriff!");
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(7,"");
		set_height(14,15,7);
		set_height(14,14,7);
		force_instant_terrain_redraw();
		play_sound(51);
		play_sound(48);
		pause(1);

		text_bubble_on_char(7,"Schnellangriff!");
		force_instant_terrain_redraw();
		pause(3);

		text_bubble_on_char(7,"");
		put_effect_on_char(7,10,4,0);
		run_animation_sound(12);
		pause(3);

		set_character_pose(7,1);
		put_boom_on_space(14,14,4,0);
		force_instant_terrain_redraw();
		run_animation_sound(54);
		pause(3);

		text_bubble_on_char(7,"Obskurangriff!");
		set_character_pose(7,2);
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(7,"");
		put_effect_on_char(7,8,4,0);
		run_animation_sound(12);
		pause(3);

		set_character_pose(7,1);
		put_boom_on_space(14,14,7,0);
		force_instant_terrain_redraw();
		run_animation_sound(54);
		pause(3);

		text_bubble_on_char(7,"Magieangriff!");
		set_character_pose(7,2);
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(7,"");
		put_effect_on_char(7,2,4,0);
		run_animation_sound(12);
		pause(3);

		set_character_pose(7,1);
		put_boom_on_space(14,14,6,0);
		force_instant_terrain_redraw();
		run_animation_sound(54);
		pause(3);

		text_bubble_on_char(7,"Todesangriff!");
		set_character_pose(7,2);
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(7,"");
		put_effect_on_char(7,5,4,0);
		run_animation_sound(12);
		pause(3);

		set_character_pose(7,1);
		put_boom_on_space(14,14,3,0);
		set_terrain(14,14,138);
		force_instant_terrain_redraw();
		run_animation_sound(54);
		pause(3);

		set_character_pose(7,0);
		set_total_visibility(0);
		set_height(14,15,5);
		set_height(14,14,5);
		force_instant_terrain_redraw();

		message_dialog("That was amazing!  You've never SEEN such skill before in your life.","Needless to say, the dummy is totally obliterated.");
		set_flag(4,0,1);
	}
break;

beginstate 15;
	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}
	move_to_new_town(3,27,40);
break;

beginstate 16;
	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}
	move_to_new_town(3,37,40);
break;

beginstate 17;
	if(get_flag(5,0) == 0){
		if(party_size() > 1)
			message_dialog("You enter the main meeting hall, where Leader and the generals of North Canopy meet and discuss strategy.  Leader eyes you as you enter.","_You!_ he exclaims.  _You are the specialists I summoned.  I am glad to see you here, especially on such short notice.  We have much to discuss.  Come closer._");
		if(party_size() == 1)
			message_dialog("You enter the main meeting hall, where Leader and the generals of North Canopy meet and discuss strategy.  Leader eyes you as you enter.","_You!_ he exclaims.  _You are the Specialist I summoned.  I am glad to see you here, especially on such short notice.  We have much to discuss.  Come closer._");
		set_flag(5,0,1);

		if(get_flag(75,0) == 0){
			talk = 14;
		}
		else{
			talk = get_flag(75,0);
		}

		relocate_character(0,32,20);
		relocate_character(1,32,19);
		relocate_character(2,32,18);
		relocate_character(3,32,17);
		force_view_center(32,20);
		force_instant_terrain_redraw();
		pause(3);

		march_party(32,21);
		force_view_center(32,21);
		force_instant_terrain_redraw();
		pause(3);

		march_party(31,21);
		force_view_center(31,21);
		force_instant_terrain_redraw();
		pause(3);

		march_party(30,21);
		force_view_center(30,21);
		force_instant_terrain_redraw();
		pause(3);

		march_party(29,22);
		force_view_center(29,22);
		force_instant_terrain_redraw();
		pause(3);

		march_party(29,23);
		force_view_center(29,23);
		force_instant_terrain_redraw();
		pause(3);

		march_party(29,24);
		force_view_center(29,24);
		force_instant_terrain_redraw();
		pause(3);

		march_party(29,25);
		force_view_center(29,25);
		force_instant_terrain_redraw();
		pause(3);

		march_party(29,26);
		force_view_center(29,26);
		force_instant_terrain_redraw();
		pause(3);

		march_party(29,27);
		force_view_center(29,27);
		force_instant_terrain_redraw();
		pause(3);

		set_character_facing(1000,6);
		force_instant_terrain_redraw();
		pause(3);

		i = random_party_member();
		text_bubble_on_char(i,"Leader, sir!");
		set_character_pose(1000,2);
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(i,"");
		i = random_party_member();
		if(party_size() > 1)
			text_bubble_on_char(i,"What would you have us do, sir?");
		if(party_size() == 1)
			text_bubble_on_char(i,"What would you have me do, sir?");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(i,"");
		text_bubble_on_char(8,"The bugbear menace");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"has troubled me");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"for some time now.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"Those humanoid swines");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"have strange idols");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"that look like this:");
		force_instant_terrain_redraw();
		pause(talk);

		force_view_center(32,21);
		force_instant_terrain_redraw();
		pause(3);

		set_terrain(30,21,198);
		set_terrain(31,21,198);
		set_terrain(32,21,198);
		set_terrain(33,21,198);
		set_terrain(34,21,198);
		put_boom_on_space(30,21,2,0);
		put_boom_on_space(31,21,2,0);
		put_boom_on_space(32,21,2,0);
		put_boom_on_space(33,21,2,0);
		put_boom_on_space(34,21,2,0);
		force_instant_terrain_redraw();
		run_animation_sound(10);
		pause((talk + 5));

		force_view_center(29,27);
		force_instant_terrain_redraw();
		pause(3);

		text_bubble_on_char(8,"");
		if(party_size() > 1)
			text_bubble_on_char(8,"I want YOU, Specialists,");
		if(party_size() == 1)
			text_bubble_on_char(8,"I want YOU, Specialist,");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"to demoralize these");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"inhuman curs by");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"raiding their village");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"to the west and");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"taking all nine of their");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"religious symbols.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"When your quest is");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"completed, bring the");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"religious symbols to");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"Machtschrein, north of here.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(8,"That is all.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(8,"");
		text_bubble_on_char(i,"");
		text_bubble_on_char(i,"Yes, sir!");
		set_character_pose(1000,1);
		force_instant_terrain_redraw();
		pause(talk);

		set_terrain(32,29,270);
		set_terrain(31,28,270);
		set_terrain(33,28,270);
		put_effect_on_space(32,29,10,4,0);
		put_effect_on_space(31,28,10,4,0);
		put_effect_on_space(33,28,10,4,0);
		set_character_pose(1000,0);
		set_character_pose(8,1);
		force_instant_terrain_redraw();
		run_animation();
		pause(5);

		erase_char(8);
		set_terrain(32,29,0);
		set_terrain(31,28,0);
		set_terrain(33,28,0);
		put_boom_on_space(32,28,2,0);
		set_terrain(30,21,0);
		set_terrain(31,21,0);
		set_terrain(32,21,0);
		set_terrain(33,21,0);
		set_terrain(34,21,0);
		force_instant_terrain_redraw();
		run_animation_sound(10);

		message_dialog("Leader, the all-knowing commander of Canopy, has given you orders.  To recap:","You are to raid the Bugbear village to the west of Schwertschrein.  There are nine odd religious symbols hanging therein.  You are to steal them.");
		toggle_quest(0,0);
		toggle_quest(1,1);
		text_bubble_on_char(i,"");
		block_entry(1);
		force_view_center(29,27);
		force_instant_terrain_redraw();

	}
break;

beginstate 18;

	if(get_flag(5,0) == 0){
		set_terrain(13,12,40);
	}
	else{
		set_terrain(13,12,56);
	}
break;

beginstate 19;

	if(get_flag(32,9) == 0 && town_status(4) < 2){
		reset_dialog();
		add_dialog_str(0,"This is the chest containing the blacksmith's work.  Clearly, stealing things which are inside of here would be BAD.",0);
		add_dialog_str(1,"On the other hand, that doesn't mean that  you can't take what's inside of here...",0);
		add_dialog_choice(0,"Leave it alone.");
		add_dialog_choice(1,"Rob them blind.");
		bmessage = run_dialog(0);
		if(bmessage == 1){
			block_entry(1);
			end();
		}
		else{
			message_dialog("Artigiano sees you doing this and shouts out to the guards.  Whoops.","In the meantime, however, the weapons are yours for the taking!  Unfortunately, you'll need them.");
			make_town_hostile();
			change_crime_level(1);
		}
	}
break;