// .txt

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 3;
short last_abil;
short counter = 0;
short i;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

	spawn_creature(3274);
	spawn_creature(3277);
	
	set_name(3245,"Overbye");

	set_name(3246,"Juoza");
	set_level(3246,10);
	set_courage(3246,0);
	
	set_name(3247,"Goodwife Bebe");
	set_name(3248,"Incantor Oenslager");
	set_boss_level(3248,1);

	set_name(3250,"Barghan Guard");
	set_level(3250,30);
	set_name(3263,"Barghan Guard");
	set_level(3263,30);
	set_name(3286,"Barghan Guard");
	set_level(3286,30);


	add_range_to_group(3264,3268,49);
	add_range_to_group(3269,3273,50);
	set_name(30049,"Barghan Farmer");
	set_courage(30049,0);
	set_name(30050,"Barghan Farmer");
	set_courage(30050,0);
	
	set_crime_tolerance(max_crime);

	sf(30,4,0);

	if (gf(170,10) == 0) {
		i = 3274;
		while (i < 3296) {
			if ((char_ok(i) == FALSE) && (get_ran(1,0,100) < 20)) {
				spawn_creature(i);
				if (gf(30,12) < 20)
					inc_flag(30,12,1);
					else set_summon_level(i,1);
				}
			i = i + 1;
			}
		}

	set_name(3298,"Bedroom Sentinel");
	set_name(3299,"Bedroom Sentinel");
	set_name(3300,"Bedroom Sentinel");
	set_level(3298,32);
	set_level(3299,32);
	set_level(3300,32);
	set_attack_bonus(3298,10);
	set_attack_bonus(3299,10);
	set_attack_bonus(3300,10);

	set_name(3301,"Imprisoned Daemon");
	set_boss_level(3301,1);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if ((gf(30,15) > 2) && (gf(30,1) == 0))
		begin_talk_mode(2);
		
	if ((gf(30,11) > 0) && (gf(30,10) == 0)) {
		change_crime_level(26,5);
		}
		
	if (gf(30,10) > 0) {
		if (party_dist_to_spot(145,147) > 10)
			erase_char(3245);
		if (party_dist_to_spot(155,139) > 10)
			erase_char(3247);
		}
		
	if ((get_crime_level() >= max_crime) && (im_hostile == 0)) {
		sf(30,10,1);
		make_zone_hostile();
		im_hostile = 1;
		}

	if (gf(30,10) == 0) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3245,"I collect items.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3245,"What ... What do you want?");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3245,"A ... beautiful collection.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3246,"You will sleep here.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3246,"Tear up your field.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3246,"You will raise lizards.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3246,"You will plant trees.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3246,"Lord Farrar commands it.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3247,"A customer?");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3247,"Come have a drink!");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3247,"I will serve you.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3248,"Hum hmmmm.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3248,"How goes Avernum?");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3248,"My workshop is humble.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(3248,"Do you need training?");

		}

	if (get_quest_status(193) == 2)
		sf(30,20,1);
		
	//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;
	alert_char(3280);
	alert_char(3281);
	alert_char(3282);
break;

beginstate 11;
	set_terrain_string_range("The sign says - Overbye. Rare items.",1);
break;

beginstate 12;
	set_terrain_string_range("The sign says - The Barghan Refuge.",1);
break;

beginstate 13;
	set_terrain_string_range("The sign says - Escape Tunnel. Warning! Traps!.",1);
break;


beginstate 30;
	if (gf(30,10) == 0) {
		if (revive_party()) {
			print_str_color("Entering or leaving Bargha heals your wounds",2);
			print_str_color("  and restores your spell energy.",2);
			}
		}
break;

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