// .txt

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 5;
short last_abil;
short counter = 0;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

//	set_name(,"");

	add_range_to_group(664,671,1);
	add_range_to_group(672,679,2);
	add_range_to_group(680,687,3);
	if (gf(170,8) > 0)
		erase_char(30003);

	add_range_to_group(688,695,4);
	set_name(30004,"Soldier of Avernum");
	set_name(688,"Commander Matos");
	set_boss_level(688,1);
	set_name(696,"Captain Khatessa");
	set_boss_level(696,1);

	set_name(699,"Oliver");
	
	set_obj_act_at_dist(1110,1);
	set_obj_act_at_dist(1111,1);
	set_obj_act_at_dist(1112,1);
	set_obj_act_at_dist(1113,1);
	
	// FAIL
	if ((gf(6,13) == 3) && (gf(6,1) == 0)) {
		sf(6,9,1);
		erase_char(30004);
		erase_char(696);
		erase_char(697);
		erase_char(698);
		erase_char(699);
		}
		
	sf(6,12,0);
	if (gf(6,13) > 1)
		sf(6,13,1);

	
	set_crime_tolerance(max_crime);

	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if ((gf(6,1) == 0) && (num_chars_in_group(1) == 0) && (num_chars_in_group(2) == 0) && (num_chars_in_group(3) == 0)) {
		sf(6,1,1);
		if (gf(6,13) == 3)
			sf(6,14,1);
		sf(6,13,4);
		award_party_xp(500,40);
		begin_talk_mode(295);
		}
	if (gf(6,1) > 0) // make suregates open
		sf(6,10,1);
		
	if (gf(6,1) > 0)
		sf(6,11,1);
	
	if ((get_crime_level() >= max_crime) && (im_hostile == 0)) {
		sf(6,2,1);
		make_zone_hostile();
		im_hostile = 1;
		}
	
	if ((gf(6,2) == 0) && (gf(6,13) != 3)) {
		if ((get_ran(1,0,100) < 10) && (gf(6,1) == 0))
			give_char_text_bubble(688,"We need help.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) == 0))
			give_char_text_bubble(688,"We don't have much time.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) == 0))
			give_char_text_bubble(688,"Our time will come soon.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) > 0))
			give_char_text_bubble(688,"Now we can strike back.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) > 0))
			give_char_text_bubble(688,"We thank you.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) > 0))
			give_char_text_bubble(688,"Perhaps we can survive.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) == 0))
			give_char_text_bubble(696,"Talk to the commander.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) == 0))
			give_char_text_bubble(696,"Ahssss.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) == 0))
			give_char_text_bubble(696,"Maintain discipline!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(698,"I can heal you.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(698,"You may rest here.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) == 0))
			give_char_text_bubble(698,"We will die with honor.");
		if ((get_ran(1,0,100) < 10) && (gf(6,1) > 0))
			give_char_text_bubble(698,"We will take the fight to them.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(699,"I can trade with you.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(699,"What is the point?");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(699,"We'll all die here.");
		}

	//if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_group()) && (tick_difference(last_abil,get_current_tick()) > 5))) {
	//	last_abil = get_current_tick();
	//	}
break;

beginstate 10;
	set_terrain_string_range("It looks like the slithzerikai burrowed a tunnel into this storeroom and then were driven back. The tunnel was collapsed.",1);
break;


beginstate 11;
	set_terrain_string_range("The sign says - Barracks.",1);
break;

beginstate 12;
	set_terrain_string_range("The sign says - Barracks. Captain's Office.",1);
break;

beginstate 13;
	set_terrain_string_range("The sign says - Holding Cell. OCCUPIED.",1);
break;

beginstate 14;
	set_terrain_string_range("The sign says - Special Gear Storage. Authorized Soldiers Only!",1);
break;

beginstate 15;
	if ((gf(6,1) > 0) && (gf(6,2) == 0)) {
		if (revive_party()) {
			print_str_color("Passing through the Fort Monastery gates heals your wounds",2);
			print_str_color("  and restores your spell energy.",2);
			}
		}
break;


beginstate 16;
	set_terrain_string_range("The sign says - Storage. Taking gear or food without permission will result in flogging!",1);
break;

beginstate 17;
	sf(6,12,0);
break;

beginstate 18;
	sf(6,7,1);
break;

beginstate 19;
	set_terrain_string_range("The sign says - Battlemage Winant.",1);
break;

//	print_str("");
//	set_terrain_string_range(".",1);
//	set_terrain_string_range("The sign says - .",1);
