// TOWN SCRIPT
//    Town 13: Skane

// 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,"Sorali");
	set_name(7,"Sain");
	set_name(9,"Uzskag");			
	set_name(10,"Rlv'vos");						
	set_name(11,"Sepin");	
	set_name(13,"Boatskeeper");			
	set_crime_tolerance(1);
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("Sorali, leader of the Skane pirates, is felled. A quick search reveals a set of keys for the docks.",
	  "[You have acquired a Special Item.]");
	change_spec_item(6,1);
	set_state_continue(31);	
break;

beginstate 11;
	if (has_special_item(46) > 0)
		set_state_continue(12);
break;

beginstate 12;
	if (get_flag(13,2) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"You walk into Sorali's hall. Peering at you from the other side of the long table, the pirate appears tense. Shaking somewhat, he rises and prepares to speak. He is interrupted before a single word can come out of his mouth.",0);
	add_dialog_str(1,"_Skane is no longer yours, brigand. We will not allow it. You cannot hide now._ Freawaru looks to you, and motions you in. Sorali's guards stand in alarm. The pirate himself, however, only narrows his eyes.",0);
	add_dialog_str(2,"Then he draws something from his sleeve. It's a small, dim mirror.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(13,2,250);
	set_state_continue(13);
break;

beginstate 13;
	change_spec_item(46,-1);
	make_town_hostile();
	activate_hidden_group(1);
	set_flag(113,0,1);
break;

beginstate 17;
	if (has_special_item(6) > 0)
		set_state_continue(18);
	set_state_continue(19);
break;

beginstate 18;
	reset_dialog();
	add_dialog_str(0,"You find a lock mechanism on the wall here. With your dock keys, you should be able to operate it without too much trouble.",0);
	add_dialog_choice(0,"OK.");
	add_dialog_choice(1,"Pull.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(21);
	set_state_continue(20);
break;

beginstate 19;
	message_dialog("You find a lock mechanism on the wall here. A lock without keys isn't too useful to you, though, so you leave it happily alone.","");
break;

beginstate 20;
	message_dialog("You leave the mechanism alone.","");
break;

beginstate 21;
message_dialog("With a grinding crank, you activate the gates to the docks.","");
	flip_terrain(9,50);
	flip_terrain(9,51);
break;

beginstate 23;
	if (has_special_item(6) > 0)
	set_flag(13,0,14);
break;

beginstate 24;
	if (has_special_item(6) > 0)
		set_state_continue(25);
	set_state_continue(26);
break;

beginstate 25;
	reset_dialog();
	add_dialog_str(0,"You find a lock mechanism on the wall here. With your dock keys, you should be able to operate it without too much trouble.",0);
	add_dialog_choice(0,"OK.");
	add_dialog_choice(1,"Pull.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(28);
	set_state_continue(27);
break;

beginstate 26;
	message_dialog("You find a lock mechanism on the wall here. A lock without keys isn't too useful to you, though, so you leave it happily alone.","");
break;

beginstate 27;
	message_dialog("You leave the mechanism alone.","");
break;

beginstate 28;
message_dialog("With a grinding crank, you activate the gates to the east exit.","");
	flip_terrain(47,31);
	flip_terrain(47,32);
	flip_terrain(47,33);
	flip_terrain(53,31);
	flip_terrain(53,32);
	flip_terrain(53,33);
break;

beginstate 30;
	if (get_attitude(6) < 10)
	end();
	set_state_continue(31);	
break;

beginstate 31;
if (get_flag(13,9) == 250)
		end();
	set_town_status(13,2);
	print_str_color("You hear an alarm sound, then gates slam shut",1);
	flip_terrain(47,31);
	flip_terrain(47,32);
	flip_terrain(47,33);
	flip_terrain(53,31);
	flip_terrain(53,32);
	flip_terrain(53,33);
	set_flag(13,9,250);
break;