begintownscript;

variables;
short choice;

body;

beginstate INIT_STATE;
	if(party_size() >= 2)
		relocate_character(0,18,14);
		relocate_character(1,18,15);
	if(party_size() >= 3)
		relocate_character(2,18,13);
	if(party_size() >= 4)
		relocate_character(3,19,15);

	set_character_facing(1000,2);
	force_view_center(18,14);
	force_instant_terrain_redraw();
break;

beginstate START_STATE;
	if(get_flag(2,0) == 0){
		message_dialog("Hovered over a large and bubbling cauldron, the necromancer does not notice you at first.  He stands in the center of a very sinister looking room, lined with skulls and lava.","");

		reset_dialog();
		add_dialog_str(0,"_Is that the lift I hear?_ he utters, still fixated on his work.",0);
		add_dialog_str(1,"_If that's you Quincy, I hope you've cleaned the storerooms as I commanded.  I assume that's the only reason you'd interrupt me from my work._",0);
		add_dialog_str(2,"He looks up, and nearly falls over in surprise.",0);
		add_dialog_str(3,"_YOU!_",0);
		add_dialog_str(4,"He pulls himself up straight, and glares at you menacingly.",0);
		add_dialog_str(5,"_So you've come to finish me off, have you?  I should have murdered you when I had the chance._",0);
		add_dialog_choice(0,"Pity, but it is not I who shall be dead this day.");
		choice = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"The necromancer laughs heartily.",0);
		if(party_size() == 1)
			add_dialog_str(1,"_You are correct, of course.  When I am done flaying the soul from your body, it will serve me well for all eternity.  As for what's left, it can go straight to hell!_",0);
		if(party_size() > 1)
			add_dialog_str(1,"_You are correct, of course.  When I am done flaying the souls from your bodies, they will serve me well for all eternity.  As for what's left, it can go straight to hell!_",0);
		add_dialog_str(2,"His laughter suddenly stops and is replaced by chanting.  Before you can react, the scattered bones that litter the floor begin to manifest themselves into sinister shapes.",0);
		add_dialog_choice(0,"We shall see, foolish wizard.");
		choice = run_dialog(1);

		set_character_pose(6,1);
		force_instant_terrain_redraw();

		put_sparkles_on_char(6,1,7);
		run_animation_sound(-25);

		pause(4);

		activate_hidden_group(1);

		put_boom_on_space(15,13,7,0);
		put_boom_on_space(16,14,7,0);
		put_boom_on_space(16,16,7,0);
		put_boom_on_space(13,16,7,0);
		run_animation_sound(75);

		pause(4);

		set_character_pose(6,0);
		force_instant_terrain_redraw();

		set_flag(2,0,1);
		}

		if(get_flag(2,1) == 1){
			message_dialog("Now that the necromancer is dead, it's time to leave this tower.","");
			set_flag(2,1,2);
			}
break;

beginstate 10;
	if(get_flag(2,1) == 2){
		message_dialog("Suddenly, the tower begins to shake.  What could be happening?","");
		set_total_visibility(1);
		force_view_center(16,15);
		force_instant_terrain_redraw();

		pause(4);

		put_boom_on_space(16,15,6,0);
		run_animation_sound(90);

		pause(8);

		put_boom_on_space(16,15,1,1);
		put_boom_on_space(16,15,1,1);
		put_boom_on_space(16,15,1,1);
		put_boom_on_space(16,15,1,1);
		put_boom_on_space(16,15,1,1);
		put_boom_on_space(16,15,1,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		put_boom_on_space(16,15,0,1);
		run_animation_sound(-152);

		set_terrain(16,15,137);
		set_floor(16,15,89);

		activate_hidden_group(2);

		set_character_pose(12,1);
		text_bubble_on_char(12,"RAHHHHH!");
		force_instant_terrain_redraw();

		pause(8);

		set_character_pose(12,0);
		text_bubble_on_char(12,"");
		force_instant_terrain_redraw();

		pause(8);

		text_bubble_on_char(12,"Ha ha!");
		force_instant_terrain_redraw();

		pause(16);

		text_bubble_on_char(12,"");
		text_bubble_on_char(12,"HA HA HA!");
		force_instant_terrain_redraw();

		pause(24);

		text_bubble_on_char(12,"");
		force_instant_terrain_redraw();

		large_draw_pic_dialog(307,"MUAHAHAHAHAHA!");

		if(party_size() == 1)
			message_dialog("_At last, I am free,_ shouts the large demon. _That foolish necromancer should have known never to cross me._","Turning his gaze towards you, he calls, _Now, I suppose, the would-be adventurer who rid me of that foul prison would require that I reward him.  Yes, that would be the proper thing to do._");
		if(party_size() > 1)
			message_dialog("_At last, I am free,_ shouts the large demon. _That foolish necromancer should have known never to cross me._","Turning his gaze towards you, he calls, _Now, I suppose, the would-be adventurers who rid me of that foul prison would require that I reward them.  Yes, that would be the proper thing to do._");

		large_draw_pic_dialog(308,".....");

		message_dialog("_However, I think I'll kill you instead!  Muah ha ha ha!  Prepare yourself!_","The demon lumbers towards you, menace in his eyes - your doom is at hand!");

		large_draw_pic_dialog(309,"_OH NO!_");

		play_sound(-152);
		large_draw_pic_dialog(310,"KABLOOOOIE!!!");

		kill_char(12,2,0);

		message_dialog("And then he exploded, and the world was saved.  The necromancer's soul can now move on peacefully to the afterlife.  The tower is gone too because it also exploded.","THE TOWER EXPLODED!?");

		set_flag(2,1,3);

		set_total_visibility(0);
		force_instant_terrain_redraw();

		move_to_new_town(5,16,16);
		}
		else{
			print_str("Can't turn back now!");
			block_entry(1);
			}

break;

beginstate EXIT_STATE;
break;