begintownscript;

variables;
short lever1;
short lever2;
short button1;
short kuroapproach;
short vamp1;
short harold1;
short tome1;
short portal;

body;

beginstate 0;
	set_name(30,"Harold");
	set_char_dialogue_pic(30,541,0);
	set_name(37,"Valzgoth");
	set_char_dialogue_pic(37,545,0);
break;

beginstate 1;
break;

beginstate START_STATE;
break;

beginstate 10;
	if(get_flag(20,0) < 185){
		if(is_combat() == 1){
			block_entry(1);
			end();
		}
		set_terrain(24,7,26);
		set_terrain(24,6,0);
		set_terrain(24,5,0);
		set_height(24,5,18);
		play_sound(106);
		play_sound(99);
		message_dialog("You look behind you, and suddenly, the gate slams shut and the stairs descend into the ground!","Whatever Kurojutsu is planning, he plans to finish it with your death.");
		set_flag(20,0,185);
	}
break;

beginstate 11;
	if(get_flag(20,0) == 185){
		activate_hidden_group(1);
		put_effect_on_space(23,7,1,5,0);
		put_effect_on_space(25,7,1,5,0);
		put_effect_on_space(23,15,1,5,0);
		put_effect_on_space(25,15,1,5,0);
		force_instant_terrain_redraw();
		run_animation_sound(152);
		print_str_color("Suddenly, four skeletons appear in a burst of flames!",3);
		set_flag(20,0,190);
	}
break;

beginstate 12;
	if(get_flag(25,5) == 0){
		large_draw_pic_dialog(554,"How horrid...");
		message_dialog("Now you know where Kurojutsu is getting his vampires from.","He must have kidnapped many people and used his dark powers to turn them into fellow undead.  He must be stopped before more innocents are subverted.");
		set_flag(25,5,1);
	}
break;

beginstate 13;
	if(get_flag(25,6) == 0){
		message_dialog("Eww.  In this stuffy passage, you can see exactly what Kurojutsu plans to do to you.","Hopefully, you will fare better than these poor sods did.");
		set_flag(25,6,1);
	}
break;

beginstate 14;
	if(get_flag(26,5) == 0){
		message_dialog("You enter this small torturing chamber.  On the table are sharp objects, most likely used to give a slow, painful death to whoever earns Kurojutsu's dislike.","In a cell, you find a corpse hunched against the wall.  You almost jump out of your skin when it stands up.");
		message_dialog("_D...  don't hurt me!_","You lower your weapons, confused.  It doesn't seem to be hostile towards you yet.");
		set_flag(26,5,1);
	}
break;

beginstate 15;
	if(get_flag(26,6) == 0){
		set_terrain(8,14,0);
		set_terrain(9,14,0);
		put_effect_on_space(8,14,5,3,1);
		put_effect_on_space(9,14,5,3,1);
		force_instant_terrain_redraw();
		run_animation_sound(102);
		message_dialog("As you step over these runes, they blow up, smothering you in a Repel Spirit spell.","Thankfully, you are not undead yet, so the enchantment leaves you unfazed.");
		set_flag(26,6,1);
	}
break;

beginstate 16;
	if(get_flag(26,6) == 1){
		message_dialog("As you enter this room, there is a wight on a platform, sitting by a set of controls.  You had no idea that Wights sat, much less worked on electronics.","Even stranger is the fact that it has yet to attack you.  In fact, it doesn't even notice you.");
		set_flag(26,6,2);
	}
break;

beginstate 17;
	if(get_flag(26,6) > 3){
		message_dialog("Since you jammed the gates in this level open, this lever has been disabled.","");
		end();
	}
	reset_dialog_preset_options(2);
	lever1 = run_dialog(0);
	if (lever1 == 1)
		end();
	flip_terrain(13,25);
	flip_terrain(10,31);
	play_sound(106);
	play_sound(99);
	print_str_color("You hear the sounds of chains and grinding gears.",2);
	if(get_flag(26,6) == 2 && get_flag(46,2) == 0){
		play_sound(37);
		message_dialog("As you pull the lever, Valzgoth sighs and presses a button on his control panel.  You hear the platform across from you begin humming.","Humming, just like the time you were descending through the tunnel...");
		force_view_center(16,24);
		put_boom_on_space(16,23,4,0);
		put_boom_on_space(17,23,4,0);
		put_boom_on_space(18,24,4,0);
		put_boom_on_space(18,25,4,0);
		put_boom_on_space(17,26,4,0);
		put_boom_on_space(16,26,4,0);
		put_boom_on_space(15,25,4,0);
		put_boom_on_space(15,24,4,0);
		run_animation_sound(54);
		activate_hidden_group(2);
		put_boom_on_space(16,23,2,0);
		put_boom_on_space(17,23,2,0);
		put_boom_on_space(18,24,2,0);
		put_boom_on_space(18,25,2,0);
		put_boom_on_space(17,26,2,0);
		put_boom_on_space(16,26,2,0);
		put_boom_on_space(15,25,2,0);
		put_boom_on_space(15,24,2,0);
		put_boom_on_space(16,24,2,0);
		put_boom_on_space(17,24,2,0);
		put_boom_on_space(17,25,2,0);
		put_boom_on_space(16,25,2,0);
		force_instant_terrain_redraw();
		run_animation_sound(10);
		message_dialog("A large group of undead teleports onto the platform.  Valzgoth himself, however, keeps on typing on his machine as if nothing had just happened.","");
		set_flag(26,6,3);
	}
break;

beginstate 20;
	if(get_flag(26,6) > 3){
		message_dialog("Since you jammed the gates in this level open, this lever has been disabled.","");
		end();
	}
	reset_dialog_preset_options(2);
	lever2 = run_dialog(0);
	if (lever2 == 1)
		end();
	set_terrain(16,42,375);
	set_terrain(10,31,30);
	set_terrain(38,10,30);
	set_terrain(40,10,30);
	set_terrain(42,10,30);
	set_terrain(24,7,30);
	set_terrain(35,25,31);
	set_terrain(11,35,0);
	set_terrain(12,35,0);
	set_terrain(11,36,0);
	set_terrain(12,36,0);
	set_terrain(11,37,0);
	set_terrain(12,37,0);
	play_sound(106);
	play_sound(99);
	print_str_color("You hear the sounds of chains and grinding gears.",2);
	set_flag(26,6,4);
break;

beginstate 21;
	reset_dialog();
	add_dialog_str(0,"There is a panel with buttons on it here, not entirely dissimilar from the one Valzgoth was using.  This one, however, is far simpler.  The buttons are clearly labeled.",0);
	add_dialog_str(1,"This device, if labeled correctly, is set to control power supply and the gates opening and closing.",0);
	add_dialog_str(2,"Of course, since you jammed all of the gates open, the buttons controlling the gates in this facility have been dimmed out.  Only a few buttons remain active:",0);
	if(get_flag(39,2) == 0){
		add_dialog_str(3,"The button controlling the power supply into something called _RSP Devices_ is currently LIT.",0);
	}
	else{
		add_dialog_str(3,"The button controlling the power supply into something called _RSP Devices_ is currently UNLIT.",0);
	}
	if(char_ok(4) == 1){
		add_dialog_str(4,"Harold looks at you and says, _Hey, I'd turn that off if I were you._",0);
	}
	add_dialog_choice(0,"Leave the controls alone.");
	add_dialog_choice(1,"Press the button.");
	button1 = run_dialog(1);
	if(button1 == 1)
		end();
	if(get_flag(39,2) == 0){
		set_flag(39,2,1); //1 = OFF
	}
	else{
		set_flag(39,2,0);
	}
break;

beginstate 22;
	message_dialog("There is a trapdoor here, presumably leading to further cellars filled with corpses.  What makes you assume this is two things:","The first thing is the stench, and the second thing is the growling and shuffling of undead.  You leave the trapdoor alone.");
	block_entry(1);
break;

beginstate 23;
	if(get_flag(40,2) == 0){ //bracket open tier 1
		reset_dialog();
		add_dialog_str(0,"Kurojutsu...!",0);
		add_dialog_str(1,"The vile vampire and Hana are sitting at the far end of this hall.  They both sit back in their chairs relaxed, waiting for you to make the first move.",0);
		add_dialog_str(2,"Perhaps they have a trap of some sort set up...",0);
		add_dialog_choice(0,"Hold your ground.");
		add_dialog_choice(1,"Charge!");
		kuroapproach = run_dialog(1);
		if(kuroapproach == 1){ //bracket open tier 2
			message_dialog("Both Hana and Kurojutsu glance at you smugly as you back off.  Yet, they make no motion to stop you.  Yet.","");
			block_entry(1);
			end();
		} //bracket close t2
		else{ //bracket open t2
			if(is_combat() == 1){
				block_entry(1);
				end();
			}
			activate_hidden_group(18);
			march_party(24,19);
			force_view_center(24,19);
			force_instant_terrain_redraw();
			pause(10);

			march_party(24,20);
			force_view_center(24,20);
			force_instant_terrain_redraw();
			pause(10);

			march_party(24,21);
			force_view_center(24,21);
			force_instant_terrain_redraw();
			pause(10);

			march_party(24,22);
			force_view_center(24,22);
			force_instant_terrain_redraw();
			pause(10);

			march_party(24,23);
			force_view_center(24,23);
			force_instant_terrain_redraw();
			pause(10);

			march_party(24,24);
			force_view_center(24,24);
			force_instant_terrain_redraw();
			pause(10);

			march_party(24,25);
			force_view_center(24,25);
			force_instant_terrain_redraw();
			pause(10);

			reset_dialog();
			add_dialog_str(0,"Kurojutsu glares down at you with a fang-filled grin as you approach his dais.",0);
			add_dialog_str(1,"_So, have the cogs of the machine come to slice the abusers up into itty-bitty pieces?_  He chuckles.  _You think you're doing a service by killing us?_",0);
			add_dialog_str(2,"Hana shakes her head at you with a smug, toothy grin.  _Poor children, you adventurers are...  Do you honestly think that killing us will stop the suffering in the world?_",0);
			add_dialog_str(3,"Ten men without power who want to change the world can't fight one man with power, and women?  Phaugh, us gals are always being trodded down upon.  The poor, non-humans, the huddled masses that the Empire refuses to take care of.",0);
			add_dialog_str(4,"In the end, it's worthless to try to aim for a higher sense of morality.  There is none.  One lives for one's self, that's the way it is, and that's the way it will be.",0);
			add_dialog_choice(0,"That's not true!");
			vamp1 = run_dialog(1);
			if(char_ok(4) == 1){ //bot3
				large_draw_pic_dialog(555,"You're wrong, Kurojutsu!");
				reset_dialog();
			add_dialog_str(0,"_You...  You don't seem to get it.  There is kindness in all beings, a spark of the divine!  No being is completely evil, even you show love for your precious one._",0);
			add_dialog_str(1,"_The lines between right and wrong are always blurred.  We mortals have no way to determine right and wrong, much less whether there is a right or wrong._",0);
			add_dialog_str(2,"_That said, I can't believe that one like yourself who can value another life such as Hana's could honestly find it moral to indiscriminately kill others._",0);
			add_dialog_str(4,"_By recognizing the value of human life, you have set a moral code that you break willingly.  You are a hypocrite!_",0);
			add_dialog_str(5,"_Stop this immediately.  It's in your hands._",0);
			add_dialog_str(6,"You had no idea that Harold could be this eloquent.  Perhaps his ambivalent exterior was just a facade after all.",0);
			add_dialog_choice(0,"OK.");
			harold1 = run_dialog(1);
			message_dialog("Kurojutsu seems unfazed by the dramatic speech.  At first he begins giggling inanely to himself, but soon he is laughing heartily.  _Harold, you old dog, you!  That was brilliant._","_Dramatic, climactic, and utterly worthless.  Then again, I suppose we all needed some comic relief.  At my behest, enjoy dying for a world that hasn't cared about your death for over a hundred years!_");
			} //bct3
		message_dialog("Kurojutsu stands triumphantly with his hands at his waist, giddy and excited as if he has already beaten you.  _Enough chit-chat._","_Now, detestable cogs of the cannibalistic machine, witness my secret weapon..._");
		large_draw_pic_dialog(551,"The Remote Summoning Platform!");
		if(get_flag(39,2) == 1){ //bot3
			play_sound(43);
			message_dialog("Kurojutsu seems surprised, to say the least.  His jaw drops and his eyes open up wide.  His face would have most likely turned white if it weren't already.","_D...  Damn you!  How did you manage to de-activate the RSP?_");
			message_dialog("Your feeling of elation, however, is short-lived.  Kurojutsu himself is still a powerful Vampire, as is Hana.","While the demonic duo no longer have their allies to depend upon, they still have each other.  Admittedly, that's still quite a handful.");
		} //bct3
		else{ //bot3
			activate_hidden_group(19);
			put_boom_on_space(20,20,2,0);
			put_boom_on_space(21,20,2,0);
			put_boom_on_space(20,21,2,0);
			put_boom_on_space(21,21,2,0);
			put_boom_on_space(27,20,2,0);
			put_boom_on_space(28,20,2,0);
			put_boom_on_space(27,21,2,0);
			put_boom_on_space(28,21,2,0);
			put_boom_on_space(20,25,2,0);
			put_boom_on_space(21,25,2,0);
			put_boom_on_space(20,26,2,0);
			put_boom_on_space(21,26,2,0);
			put_boom_on_space(27,25,2,0);
			put_boom_on_space(28,25,2,0);
			put_boom_on_space(27,26,2,0);
			put_boom_on_space(28,26,2,0);
			force_instant_terrain_redraw();
			run_animation_sound(10);
			message_dialog("Suddenly, a crack team of insanely powerful undead appear on the pedestals, just like they did in the tunnel you used in order to reach this place!","There's no reasonable way you will be able to defeat them.");
			print_str_color("HINT: While it's still technically possible to win,",1);
			print_str_color("a level 1-6 party will NOT be able to take on these monsters.",1);
			print_str_color("You are advised to back up to an earlier save.",1);
		} //bct3
	}
	set_flag(40,2,1);
	block_entry(1);
}
break;

beginstate 24;

if(get_flag(40,2) != 1)
end();
print_str_color("You musn't run away!",2);
block_entry(1);

break;

beginstate 25;
	if(get_flag(56,2) >= 1)
	end();
	message_dialog("This must be the chambers of Hana and Kurojutsu.  It's an elegant set-up, to say the least.","Kurojutsu may have had a point, the evenings spent in these chambers must have been consistently more enjoyable than wading through goblin innards and trudging through caves...");
	message_dialog("You shake your head.  _No,_ you tell yourself.  Kurojutsu was morally out of line, no two ways about it.","But who makes the morals?");
	set_flag(56,2,1);
break;

beginstate 26;
	if(get_flag(56,2) >= 2)
	end();
	message_dialog("This library is not like most kept by vampires.  At first glance, you expect there to be dangerous tomes about summoning demons here.","Instead, you find romance novels, sonnets, and other heavily romantic texts.  Some are even written by Kurojutsu himself.");
	set_flag(56,2,2);
break;

beginstate 27;
	reset_dialog();
	add_dialog_str(0,"There is a large, spell tome here.  It most likely has to do with necromancy, but you could read it if you like.",0);
	add_dialog_choice(0,"Leave the book alone.");
	add_dialog_choice(1,"Read it.");
	tome1 = run_dialog(1);
	if(tome1 == 1)
		end();
	if (get_skill_total(42) > 5){
		message_dialog("The book contains dangerous knowledge about the manipulation of shades, the non-corporeal undead.  It describes their make-up, how to summon them, and how to dispel them.","Members of your party who know Summon Shade or Repel Spirit now know it at a much higher level.");
		if (char_ok(0)) {
			if(get_spell_level(0,1,4) == 1)
				change_spell_level(0,1,4,2);
			if(get_spell_level(0,1,4) == 2)
				change_spell_level(0,1,4,1);
			if(get_spell_level(0,1,6) == 1)
				change_spell_level(0,1,6,1);
		}
		if (char_ok(1)) {
			if(get_spell_level(1,1,4) == 1)
				change_spell_level(1,1,4,2);
			if(get_spell_level(1,1,4) == 2)
				change_spell_level(1,1,4,1);
			if(get_spell_level(1,1,6) == 1)
				change_spell_level(1,1,6,1);
		}
		if (char_ok(2)) {
			if(get_spell_level(2,1,4) == 1)
				change_spell_level(2,1,4,2);
			if(get_spell_level(2,1,4) == 2)
				change_spell_level(2,1,4,1);
			if(get_spell_level(2,1,6) == 1)
				change_spell_level(2,1,6,1);
		}
		if (char_ok(3)) {
			if(get_spell_level(3,1,4) == 1)
				change_spell_level(3,1,4,2);
			if(get_spell_level(3,1,4) == 2)
				change_spell_level(3,1,4,1);
			if(get_spell_level(3,1,6) == 1)
				change_spell_level(3,1,6,1);
		}
	if(get_flag(38,2) == 2)
		print_str("Harold cannot learn spells.");
	}
	else{
		message_dialog("The book contains dangerous knowledge about the manipulation of shades, the non-corporeal undead.  It describes their make-up, how to summon them, and how to dispel them.","Unfortunately, you can't understand the rituals described in the book.  Perhaps more Rune Reading skill would help.");
	}
break;

beginstate 28;
	reset_dialog_preset_options(3);
	portal = run_dialog(0);
	if(portal == 1)
		end();
	teleport_party(40,40,0);
break;

beginstate 29;
	if(get_flag(78,2) > 0)
		end();
	message_dialog("You enter this room and see a pair of Vampires playing cards at a table, and one standing at a bar.  They appear to be in a state of partial torpor.  Is this what Vampires do when they're exhausted?","They glance at you sluggishly as you enter the room, but otherwise pay you no heed.  Vampires, like humans, must have down times when they just don't want to fight humans.");
	set_flag(78,2,1);
break;