// TOWN SCRIPT
//    Town 9: Hatherond

// 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;
// This state called whenever this town is entered.
		set_state_continue(12);
		set_state_continue(32);
break;

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

beginstate START_STATE;
	if (get_current_tick() % 2 == 0) 
		set_state_continue(29);
break;

beginstate 10;
	if (get_flag(9,1) == 250)
		end();
	set_flag(9,1,250);
	set_state_continue(11);
break;

beginstate 11;
	message_dialog("With an ominous clang, the gates slam shut behind you. City guards pour out from streets and alleyways, converging upon you rapidly.",
	  "The trap has been sprung.");
	set_state_continue(13);
break;

beginstate 12;
	if (get_flag(9,2) == 250)
		end();
	message_dialog("The guards nod to you as you pass. Evidently, your descriptions have not been spread around. Time to locate Aeschere and complete your mission.","");
	set_flag(9,2,250);
break;

beginstate 13;
	make_town_hostile();
	set_state_continue(14);
break;

beginstate 14;
	activate_hidden_group(1);
	set_state_continue(15);
break;

beginstate 15;
	flip_terrain(4,31);
	flip_terrain(4,32);
	flip_terrain(4,33);
	flip_terrain(31,5);
	flip_terrain(32,5);
	flip_terrain(33,5);
	flip_terrain(60,31);
	flip_terrain(60,32);
	flip_terrain(60,33);
	flip_terrain(31,61);
	flip_terrain(32,61);
	flip_terrain(33,61);
break;

beginstate 18;
	if (has_special_item(2) > 0)
		set_state_continue(20);
	set_state_continue(19);
break;

beginstate 19;
	message_dialog("A large pillar has been set here. A vertical slot is cut into it as though for a lever, but there's none to be found.","");
	block_entry(1);
break;

beginstate 20;
	reset_dialog();
	add_dialog_str(0,"A large pillar has been set here. A vertical slot is cut into it as though for a lever, but there's none to be found. The top and bottom of the slot are slightly enlargened, as though something is to be inserted.",0);
	add_dialog_str(1,"The brass key you found could conceivably fit into the slot. Do you insert it?",0);
	add_dialog_choice(0,"OK.");
	add_dialog_choice(1,"Insert.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(22);
	set_state_continue(21);
break;

beginstate 21;
	block_entry(1);
break;

beginstate 22;
	message_dialog("The key snaps into the slot. You slide it down gradually. When it hits the bottom, there is a click. With a clank and rattle, the city gates open.",
	  "However, with the key in position, you can't take it out again. If you're going to leave, you had better do it soon.");
	change_spec_item(2,-1);
	set_state_continue(30);
break;

beginstate 23;
	if (get_flag(9,3) == 250)
		end();
	message_dialog("Searching quickly through the racks, you find one object of interest: a long brass key.","");
	change_spec_item(2,1);
	set_flag(9,3,250);
break;

beginstate 24;
	if (get_flag(9,4) == 250)
		end();
	set_flag(9,4,250);
	activate_hidden_group(2);
	set_state_continue(25);
break;

beginstate 25;
	reset_dialog();
	add_dialog_str(0,"Standing on the far side of the room, clothed in all grey, is harbor master Finn. Several battle-ready guards stand with him as he glares at you. The sapphire upon his wooden staff glows faintly.",0);
	add_dialog_str(1,"_You have outstayed your welcome here, probing too far outside your domain. I know not your master nor your true purposes, but it must end. If you seek Aeschere, you shall not find him here, nor shall you now reach Hetware._",0);
	add_dialog_str(2,"He raises his staff, and the gem's glow intensifies. The guards around him charge.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(26);
break;

beginstate 26;
break;

beginstate 27;
	if (get_flag(9,4) != 250)
		end();
	print_str_color("Finn casts an unknown spell: Chain Lightning.",1);	
	set_state_continue(28);
break;

beginstate 28;
	i = 0;
	while (i < 6) {
		r1 = get_ran(6,1,6);
		damage_char(i,r1 + 10,3);
		i = i + 1;
		}
break;

beginstate 29;
	if (get_flag(9,8) == 0)
	set_state_continue(27);
break;

beginstate 30;
	set_flag(9,5,1);
	set_state_continue(15);
break;

beginstate 31;
	reset_dialog();
	add_dialog_str(0,"All valuables have been taken out of the drawer. All you find is a scroll.",0);
	add_dialog_str(1,"TO MY MERCENARY FRIENDS -",0);
	add_dialog_str(2,"     Do not think your motives to be beyond my guess. I have left Hatherond, and do not think to come back in a hurry. Seek me in Hetware if you wish, and we shall have a long talk. No swords, no spells. None from you, and none from me.",0);
	add_dialog_str(3,"     Do not be Dracan's tool. He has no more respect for you than for a game piece, and is using you thusly. We have much in common, and could better strive together to a more glorious future instead of thwarting each other's efforts.",0);
	add_dialog_str(4,"     Harbour Master Finn will likely have arranged for your capture. I cannot give you my city key, but he would certainly have one in his quarters. Be wary: Finn has powers of craft beyond those of any ordinary man.",0);
	add_dialog_str(5,"          HUMBLY - AESCHERE",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
break;

beginstate 32;
	if (get_flag(9,5) >= 1)
		set_state_continue(33);
break;

beginstate 33;
	make_town_hostile();
break;

beginstate 34;
	if (get_flag(9,5) >= 1)
		set_state_continue(35);
break;

beginstate 35;
	if (get_flag(298,4) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"As you exit the city, you are intercepted by several mounted Seawyrm agents, who help you fight off some limited pursuit from the city guard. The battle finished, they turn to you.",0);
	add_dialog_str(1,"_Return to Ingusi immediately. We will open a tunnel in Hetware, where Aeschere has fled. First, make the report._",0);
	add_dialog_str(2,"The voice you recognize as Rauling's. Before you have the chance to ask any further questions, they've already ridden off.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(298,4,250);
break;

beginstate 36;
	message_dialog("You strike down Finn. There is a brief, uncomfortable pause as you prepare for a curse. You blink, and blink again. But there is none.","");
break;

beginstate 37;
	message_dialog("You shuffle through Finn's desk, hoping to find something useful. Disappointingly, all that's here are ledgers and contracts and the like. Even if you understood them, they wouldn't be of much use.","");
break;

beginstate 38;
	if (get_flag(9,4) == 250)
		end();
	message_dialog("If the entire city is hostile, you should be especially careful here, near Finn's office.","He never did like you anyway.");
break;


