// TOWN SCRIPT
//    Town 22: On the Dacgban

// 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 g,i,j,k,r1,choice;

body;

beginstate INIT_STATE;
		set_state_continue(14);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	inc_flag(22,8,1);
	g = get_flag(22,8) % 10;	
//	print_big_str("The value of flag 22,8 is now ",get_flag(22,8),".");
//	print_big_str("The value of flag g is now ",g,".");
	if (g == 0)
	set_state_continue(15);
break;

beginstate 10;
	block_entry(1);
	message_dialog("You scramble out of the ship as it sinks rapidly behind you.",
	  "");
	set_flag(22,0,1);
	set_flag(100,0,13);
	block_entry(1);
	move_to_new_town(19,37,22);
	end();
break;

beginstate 13;
	message_dialog("The lower level is completely flooded. There's no way you can get back down there.","");
	block_entry(1);
break;

beginstate 14;
message_dialog("You're on the top level, but still far from safety. The water engulfs the entire lower level, threatening to plunge the ship into the depths at any moment.","There are still a few on the ship. None of them look willing to lend you a hand.");
break;

beginstate 15;
	if (get_flag(22,8) == 10)
	message_dialog("The ship is almost completely sunken. You had better get out before you go down with it.","");
	if (get_flag(22,8) == 20)	
		set_state_continue(17);
break;

beginstate 17;
	message_dialog("With a violent crash, you are buried under the falling mast as the Dacgban dives to the bottom of the bay.","");
	i = 0;
	while (i < 6) {
			kill_char(i,2,0);
		i = i + 1;
		}
break;

beginstate 19;
	if (get_flag(22,2) == 250)
		end();
	reset_dialog_preset_options(1);
	add_dialog_str(0,"Someone left here in a hurry, casting off a pair of heavy gauntlets. It's yours for the taking.",0);
	choice = run_dialog(1);
	if (choice == 2) {
		set_flag(22,2,250);
		(reward_give(386) 
		}
break;

