// TOWN SCRIPT
//    Town 6: Ingusi (L2)

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
	set_name(6,"Dracan");
		set_state_continue(49);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 10;
	block_entry(1);
	reset_dialog_preset_options(5);
	choice = run_dialog(0);
	if (choice == 2) {
		move_to_new_town(5,35,34);
		end();
		}
break;

beginstate 13;
	reset_dialog();
	add_dialog_str(0,"The figure rises. Fires leap up, enveloping the hall in an eerie crimson glow. Turning westward, he stretches an arm towards the wall. A shadowy image is cast against it. You recognize it as Hatherond, heart of the Wolvish Realm.",0);
	add_dialog_str(1,"_Lacceu Hatherond. You have been there already,_ the voice echoes. _There dwells Aeschere, our chiefest enemy, the mover of events against us. He has set you free once. No, do not boast of your talents and your swords. Your escape was not chance._",0);
	add_dialog_str(2,"The figure turns and bends his unseen gaze upon you. _That was a meticulous trap. We have our suspicions. We shall hold them now, and not yet fall to Aeschere's games. But enough. This is your task._ With a sudden snap, the image disappears.",0);
	add_dialog_str(3,"_You must bring about Aeschere's demise. Our people cannot hope to disguise as a member of the populace. You can, and that is why you were brought here. Go to Hatherond again. Strike, and leave.",0);
	add_dialog_str(4," Do not let him escape. We have our rewards, but we have also our punishments._",0);
	add_dialog_str(5,"The figure seats himself again, and the fires die down.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(14);
break;

beginstate 14;
	set_flag(100,0,5);
	set_state_continue(15);
break;

beginstate 15;
	set_flag(9,0,8);
break;

beginstate 16;
	if (get_flag(100,0) == 6)
		set_state_continue(18);
	set_state_continue(17);
break;

beginstate 17;
	if (get_flag(100,0) == 7)
		set_state_continue(33);
break;

beginstate 18;
	reset_dialog();
	add_dialog_str(0,"The fires burn intensely as Dracan stares at you. You feel a probing thought within your minds. Warding it off almost irresistably, you fall back. The thought bores even further... then ends.",0);
	add_dialog_str(1,"Dracan's voice echoes around you. _Whither have you been, mercenaries? Blood has been spilled in Hatherond, but Aeschere escaped. You should have been there sooner. Well that it is not disastrous. You know where he has gone.",0);
	add_dialog_str(2," Track him down and dispose of him. Do not listen to his ramblings. Do not return before your task is accomplished. We await your success with a generous reward._",0);
	add_dialog_str(3,"The fires die down again.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(32);
break;

beginstate 19;
	if (get_flag(9,5) >= 1)
		set_state_continue(20);
break;

beginstate 20;
	if (get_flag(100,0) < 7)
		set_state_continue(21);
break;

beginstate 21;
	if (get_flag(100,0) < 6)
		set_state_continue(23);
	set_state_continue(22);
break;

beginstate 22;
	if (get_flag(6,9) == 250)
		end();
	message_dialog("A cloaked shape brushes by you in the darkness. By the time you try to stop it, it's already gone past you. A chase in this darkness would be rather futile.",
	  "You hear footsteps going down the stairway, then silence.");
	set_flag(6,9,250);
break;

beginstate 23;
	message_dialog("You are stopped by a barrier. You get the feeling that it might be invisible, but it really doesn't matter if it's visible or not - you can hardly see your own hands in front of you anyway.",
	  "Voices are conversing in the room beyond. From this distance, you can't hear much. Perhaps you should find a good place to listen, somewhere near here.");
	block_entry(1);
break;

beginstate 24;
	if (get_terrain(23,16) == 234)
		set_state_continue(25);
	set_state_continue(27);
break;

beginstate 25;
	message_dialog("With a slight nudge, the bookshelf gives way to a hidden niche.","Because of the niche, the wall here is much thinner than the other parts of the tower.");
	set_terrain(23,16,0);
	set_state_continue(27);	
break;

beginstate 27;
	if (get_flag(9,5) >= 1)
		set_state_continue(29);
	set_state_continue(28);
break;

beginstate 28;
	message_dialog("You don't find anything particularly interesting though.","");
break;

beginstate 29;
	if (get_flag(100,0) < 6)
		set_state_continue(30);
break;

beginstate 30;
	set_flag(100,0,6);
	set_state_continue(31);
break;

beginstate 31;
	reset_dialog();
	add_dialog_str(0,"You put your ears to the eastern wall, and try to listen to the voices on the other side. With some luck, you're able to make out small portions of the conversation. Clearly, Dracan is speaking with the unmistakeable echo. But the other...",0);
	add_dialog_str(1,"_... excellent tactical decision, my lord. But ... against the wall? ... repercussions on the strategic ... to the Falcon._ That's about as much you can clearly understand. The voice sounds awfully familiar, however.",0);
	add_dialog_str(2,"Dracan speaks. _Faro pvalhas a-uin. Perhaps. Perhaps not, not yet. We have need for their further testing. We have word now that they return from Hatherond with blood on their hands. We want out of them not battle-lust, but loyalty._",0);
	add_dialog_str(3,"_... wisdom. I shall ... converse. They ... under Hetware ... and test them. I do not ... difficulty. However, if I may ask ... for I deem ... Hengest ... blindness. Scyld ... and too Freawaru ... soon._",0);
	add_dialog_str(4,"There is a long pause. Then Dracan speaks again. _Laehaan Aeschere. Your proposals have been considered. Leave for Hetware, and I shall send them to you ere long. Be swift yet careful with tests -- we must move soon, but it must not be false. Go._",0);
	add_dialog_str(5,"It seems that you have a confirmation as to the identity of the other speaker.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
break;

beginstate 32;
	set_flag(100,0,7);
	set_state_continue(34);
break;

beginstate 33;
	message_dialog("_Hae acgann. If there are no reports, then depart._","");
break;

beginstate 34;
	set_flag(8,9,1);
break;

beginstate 35;
	if (get_terrain(22,17) == 234)
		set_state_continue(36);
break;

beginstate 36;
	message_dialog("You feel in the darkness that the dust around the base of this shelf is less than around others, and is furthermore swept in a circular trail. You push on the shelf, expecting it to turn around, but it doesn't.",
	  "Perhaps it responds to some password.");
	set_state_continue(37);
break;

beginstate 37;
	get_text_response("You Respond:");
		check_text_response_match("only");
		 if (got_text_match())
			set_state_continue(39);
	set_state_continue(38);
break;

beginstate 38;
	message_dialog("Well, nothing happens. Maybe it doesn't respond to some password after all.","");
	block_entry(1);
break;

beginstate 39;
	message_dialog("Silently, the bookshelf slides open.","");	
	set_terrain(22,17,0);
break;

beginstate 40;
	if (get_skill_total(42) >= 11)
		set_state_continue(41);
break;

beginstate 41;
	message_dialog("The book bound on this pedestal is covered with a myriad of unfamiliar runes. Thankfully, with sufficient lore, you can decipher a very small part of it.","It contains the mage spell Capture Mind.");
	i = 0;
	while (i < 6) {
		if (char_ok(i)) {
			if (get_spell_level(i,0,11) <= 1)
					change_spell_level(i,0,11,1);
			else 
				print_named_str(i,"cannot learn any more of this spell.");
			}
		i = i + 1;
}
break;

beginstate 42;
	reset_dialog();
	add_dialog_str(0,"A dark pool rests calmly in the gloom.",0);
	add_dialog_choice(0,"OK.");
	add_dialog_choice(1,"Drink.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(43);
break;

beginstate 43;
	if (get_flag(106,5) >= 2)
		set_state_continue(44);
	if (get_flag(106,5) < 1)
		set_state_continue(47);
	set_state_continue(45);
break;

beginstate 44;
	message_dialog("The liquid burns!","");
	i = 0;
	while (i < 6) {
		if (char_ok(i)) {
			set_char_status(i,7,8,0,1);
			}
		i = i + 1;
		}
break;

beginstate 45;
	message_dialog("The liquid is warm going down.","");
	inc_flag(106,5,1);
	i = 0;
	while (i < 6) {
		if (char_ok(i)) {
			change_char_energy(i,20);
			}
		i = i + 1;
		}
break;

beginstate 47;
	inc_flag(106,5,1);
	set_state_continue(48);
break;

beginstate 48;
	message_dialog("The liquid is chill going down.","");
	i = 0;
	while (i < 6) {
		if (char_ok(i)) {
			if (get_ran(1,0,100) < 75) {
				alter_stat(i,2,2);
				print_named_str(i,"increases in Intelligence.");				
			}
			}
		i = i + 1;
		}
break;

beginstate 49;
	if (get_flag(80,9) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"A dark pall seems to be laid over the top level of the tower. You feel vaguely disoriented, as though you aren't really standing on firm ground. Yet along with the swaying that you feel with your senses, everything appears to be standing still.",0);
	add_dialog_str(1,"Above all, though, you feel something wholly unnatural about this place, as though it should not be here.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(80,9,250);
break;

beginstate 50;
	if (get_skill_total(42) >= 13)
		set_state_continue(51);
	set_state_continue(52);
break;

beginstate 51;
	message_dialog("The scrolls dictate the proper procedures for reciting a prayer to bring forth potent spiritual fire. You recognize Divine Fire.","");
	i = 0;
	while (i < 6) {
		if (char_ok(i)) {
			if (get_spell_level(i,1,13) <= 2)
					change_spell_level(i,1,13,1);
			else 
				print_named_str(i,"cannot learn any more of this spell.");
			}
		i = i + 1;
}
break;

beginstate 52;
	message_dialog("The scrolls dictate the proper procedures for reciting a prayer. You can't quite understand them.","");
break;

beginstate 53;
	if (get_skill_total(42) >= 12)
		set_state_continue(54);
	set_state_continue(55);
break;

beginstate 54;
	message_dialog("The incantations of a simple yet useful mage spell is set forth on some loose pages, it is called Simulacrum.","");
	i = 0;
	while (i < 6) {
		if (char_ok(i)) {
			if (get_spell_level(i,0,12) <= 1)
					change_spell_level(i,0,12,1);
			else 
				print_named_str(i,"cannot learn any more of this spell.");
			}
		i = i + 1;
}
break;

beginstate 55;
	message_dialog("The incantations of a mage spell is set forth on some loose pages. You can't understand all of it, however.","");
break;

