// Town 0: Parted River
begintownscript;

variables;

short choice,i,j,k;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	set_name(53,"Kass"); // type 36
	
	set_flag(0,0,1);
	
	march_party(17,23);
	march_party(16,23);
	march_party(15,23);
	march_party(14,23);
	
	i = 0;
	j = get_current_tick();
	force_instant_terrain_redraw();
	message_dialog("You stand between two walls of water, in the middle of utter chaos. Dozens of sliths around you are scurrying with frantic hisses, fleeing for their lives before the army that Gnass has brought. You call to mind your task in the clamor.","You must slow down the warriors of Gnass until Kass tells you that the expedition is clear of the river, and then you must yourselves flee.");
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE; // Ungodly numbers of sliths appear frequently.
	i = i + 1;
	if (i == 4) {
		activate_hidden_group(1);
		i = 1;
		}
	if (tick_difference(j,get_current_tick()) >= 6)
		if (get_flag(0,1) == 0) {
			set_flag(0,1,1);
			message_dialog("At the eastern end of the battle, Kass stands, waving the last stragglers out of the river bottom. _Fly! Fly from them!_ he shouts. _Do not fight! Run!_","Virtually all the friendly sliths around you quickly depart from the battle. You have only to hold your foes but a few moments longer.");
			k = 36;
			while (k <= 52) {
				erase_char(k);
				k = k + 1;
				}
			}
	if (tick_difference(j,get_current_tick()) >= 10)
		if (get_flag(0,2) == 0) {
			set_flag(0,2,1);
			
			text_bubble_on_char(53,"Done!");
			force_instant_terrain_redraw();
			pause(get_flag(290,0) * 4);
			
			text_bubble_on_char(53,"");
			force_instant_terrain_redraw();
			
			message_dialog("Kass shouts to you, _It is done! The others are safely across! Follow me up the shore!_ He casts a quick spell and dashes away to the east.","You see the walls of water to either side of you begin to quiver. You must leave with all possible haste.");
			set_char_status(1000,4,3,0,1);
			erase_char(53);
			}
	if (tick_difference(j,get_current_tick()) >= 13)
		if (get_flag(0,3) == 0) {
			set_flag(0,3,1);
			message_dialog("The walls of water begin to seep away. Water flows out the bottoms of them, soaking your feet. If you are not out of here very soon, you will surely drown.","");
			}
	if (tick_difference(j,get_current_tick()) >= 18) {
		message_dialog("The walls of water completely collapse, and you cannot get out in time. You drown alongside the misguided army of Gnass.","");
		kill_char(1000,2,0);
		}
break;

beginstate 10; // leaving town
	if (get_flag(0,2) == 0) {
		block_entry(1);
		message_dialog("_What are you doing?_ shouts Kass. _You must stand and fight until all our people are completely clear! You cannot run away!_","");
		}
	else
		move_to_new_town(3,11,13);
break;

beginstate 11;
	message_dialog("Badly wounded, Kass retreats away from the fighting, so that he can tell you when to go when the time comes but won't get killed in the meantime.","");
	erase_char(53);
break;