// TOWN SCRIPT
//    Town 7: Hetware

// 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_name(6,"Thrytho");
			set_name(7,"Malbeth");
			set_name(8,"Unferth");
			set_name(9,"Withergyld");
			set_name(10,"Weohstan");
			set_name(12,"Hnaef");
			set_name(13,"Wealsing");
			set_state_continue(29);
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;
	message_dialog("The pillar is impaled by dozens of arrows. Looks like someone's been using it for target practice.","");
break;

beginstate 11;
	if (get_flag(100,0) == 7) 
	set_state_continue(31);
break;

beginstate 13;
	if (get_flag(20,6) == 1) 
	end();
	if (has_special_item(3) > 0)
		set_state_continue(15);
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(0,"You take out the log that you took from the Seawyrm outpost, and show it to him. Skimming over the pages quickly, he gives you a strange look for a brief moment, then finishes and raises his head.",0);
	add_dialog_str(1,"_I suppose this can be translated shortly. I require but 400... Gold, isn't that what you call it? 400 gold. No more, no less. Do you accept?_",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	choice = run_dialog(1);
	if (choice == 1)
		set_state_continue(16);
	if (choice == 2)
		end();
break;

beginstate 16;
	if (coins_amount() >= 400) {
		change_coins(-400);
		set_state_continue(18);
		}
	set_state_continue(17);
break;

beginstate 17;
	message_dialog("He frowns. _I may not be familiar with your currency, but I can count worths. 400 'gold', no less._","");
break;

beginstate 18;
	message_dialog("Unferth attends to other matters.","");
	set_flag(20,6,1);
	set_flag(100,0,14);
	set_state_continue(30);
break;

beginstate 20;
	if (get_flag(100,0) == 6)
		set_state_continue(21);
break;

beginstate 21;
	activate_hidden_group(1);
break;

beginstate 23;
	if (get_flag(100,0) == 17)
		set_state_continue(24);
	set_state_continue(25);
break;

beginstate 24;
	message_dialog("His face looks enormously strained. _The last doom awaits us all. Go to Scyld. There is no time to waste._","");
break;

beginstate 25;
	if (get_flag(100,0) >= 4)
		set_state_continue(27);
	set_state_continue(26);
break;

beginstate 26;
	message_dialog("_You have yet a long path ahead. Do what you are told, and do not doubt, for unsurety is the root of cowardice._","");
break;

beginstate 27;
	if (get_flag(100,0) == 7)
		set_state_continue(28);
break;

beginstate 28;
	message_dialog("He sighs. _You have a grim task to accomplish. Whether to finish it or not is your choice, but even the wise cannot see all ends._","");
break;

beginstate 29;
	if (get_flag(195,2) == 250) {
		set_state_continue(33);		
		end();
}	
	reset_dialog();
	add_dialog_str(0,"Set by a calm bay, the small town of Hetware has neither bustle nor arms, instead radiating a comfortable mildness. Bright fields of crops lie on the town's perimeters, and short stone buildings are typical of the architecture.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(195,2,250);
break;

beginstate 30;
	reset_dialog();
	add_dialog_str(0,"You stand by for around a hour or so as he works on the log. The atmosphere is rather stale as he works soundlessly, with only the scratch of pen on parchment breaking through.",0);
	add_dialog_str(1,"Then he finishes. Handing both the original and the translated copy to you without so much as a straight glance, he returns to other work.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
break;

beginstate 31;
	block_entry(1);
	if (get_flag(7,2) == 250)
	set_state_continue(32);
	
	else {
	reset_dialog();
	add_dialog_str(0,"Shuffling about in the rubble, you find a concealed stairway leading downward.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_terrain(11,39,377);
	set_flag(7,2,250);
	set_state_continue(32);
}
break;

beginstate 32;
	block_entry(1);
	add_dialog_str(0,"You find a stairway leading downward.",0);
	add_dialog_choice(0,"Leave");
	add_dialog_choice(1,"Descend the stairway");
		choice = run_dialog(0);
	if (choice == 2) {
		move_to_new_town(8,12,38);
		end();
}
break;

beginstate 33;
	if (get_flag(7,2) == 250)
	set_terrain(11,39,377);
break;

