// .txt

beginzonescript;

variables;

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

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

//	set_name(,"");
//	add_range_to_group(,,groupn);

	set_crime_tolerance(max_crime);

	set_obj_act_at_dist(4285,1);
	set_obj_act_at_dist(4286,1);
	set_obj_act_at_dist(4287,1);
	set_obj_act_at_dist(4288,1);
	set_obj_act_at_dist(4289,1);

	set_obj_act_at_dist(4156,1);
	set_obj_act_at_dist(4157,1);
	
	if (gf(23,2) > 0)
		sf(23,10,1);
	
	if (gf(167,20) > 0)
		kill_object(4175,1);	
	
	set_name(2491,"Kelhem of Many Eyes");
	set_boss_level(2491,1);
	
	if (gf(23,15) == 1) {
		spawn_creature(2520);
		spawn_creature(2521);
		spawn_creature(2522);
		spawn_creature(2523);
		spawn_creature(2524);
		spawn_creature(2525);
		
		add_range_to_group(2520,2525,24);
		}
		
	if ((gf(23,15) > 1) && (gf(23,12) == 0) && (gf(23,13) == 0))
		sf(23,15,0);

	if (gf(23,15) >= 11) {
		set_terrain(1,587,97,1);
		set_terrain(1,588,97,0);
		set_terrain(1,589,97,0);
		set_terrain(1,590,97,0);
		set_terrain(1,591,97,0);
		set_terrain(1,592,97,0);
		set_terrain(1,593,97,1);
		}
	sf(22,23,0);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if (gf(23,12) > 0)
		sf(23,26,1);
	if (gf(23,13) > 0)
		sf(23,26,1);
		
	if ((get_crime_level() >= max_crime) && (im_hostile == 0)) {
		make_zone_hostile();
		im_hostile = 1;
		erase_char(2492);
		sf(23,10,1);
		sf(23,12,0);
		sf(23,13,1);
		sf(23,16,1);
		}

	// some raider advances happen here, like moving whole group up or downstairs
	if (gf(23,16) == 0) {
		if ((gf(23,15) == 5) && (on_which_layer() == 0)) {
			sf(23,15,6);
			erase_char(30024);

			spawn_creature(2526);
			spawn_creature(2527);
			spawn_creature(2528);
			spawn_creature(2529);
			spawn_creature(2530);
			spawn_creature(2531);
			add_range_to_group(2526,2531,24);
			
			print_str_color("The soldiers descend through a trapdoor.",3);
			}
		if ((gf(23,15) == 19) && (on_which_layer() == 1)) {
			sf(23,15,20);
			if (char_ok(2526)) {
				spawn_creature(2520);
				erase_char(2526);
				}
			if (char_ok(2527)) {
				spawn_creature(2521);
				erase_char(2527);
				}
			if (char_ok(2528)) {
				spawn_creature(2522);
				erase_char(2528);
				}
			if (char_ok(2529)) {
				spawn_creature(2523);
				erase_char(2529);
				}
			if (char_ok(2530)) {
				spawn_creature(2524);
				erase_char(2530);
				}
			if (char_ok(2531)) {
				spawn_creature(2525);
				erase_char(2531);
				}
			force_reloc = 1;
		
			add_range_to_group(2520,2525,24);

			print_str_color("The soldiers go upstairs.",3);
			}
		}
	if ((force_reloc == 1) && (on_which_layer() == 0)) {
		force_reloc = 0;
		
			if (char_ok(2520)) {

				relocate_char(2520,619,109,0);
				}
			if (char_ok(2521)) {
				relocate_char(2521,618,110,0);
				}
			if (char_ok(2522)) {
				relocate_char(2522,620,110,0);
				}
			if (char_ok(2523)) {
				relocate_char(2523,619,111,0);
				}
			if (char_ok(2524)) {
				relocate_char(2524,618,112,0);
				}
			if (char_ok(2525)) {
				relocate_char(2525,620,112,0);
				}
		
		}
		
	// if (gf(,) == 0) {
	//if (get_ran(1,0,100) < 10)
	//	give_char_text_bubble(,"");
	//	}

	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();
		
		if ((gf(22,23) > 0) && (gf(22,23) < 100)) {
			inc_flag(22,23,1);
			if (gf(22,23) == 6) {
				if (gf(23,13) == 0) {
					sf(23,15,13);
					sf(22,22,1);
					force_char_status(30024,5,0);
					set_attitude(30024,3);
					set_new_abil(30024,0);
					begin_talk_mode(44);
					}
				}
			}
		}
break;

beginstate 10;
	set_terrain_string_range("The sign says - Infirmary.",1);
break;

beginstate 11;
	set_terrain_string_range("The sign says - Alchemical Workshop. Metallurgy.",1);
break;

beginstate 12;
	set_terrain_string_range("The sign says - THE DRACO ARMS.",1);
break;

beginstate 13;
	if (gf(23,19) == 0)
		set_terrain_string_range("You can hear scratching. It's coming from nearby, but you're not sure where.",1);
break;

beginstate 14;
break;

beginstate 15;
break;

beginstate 16;
break;

beginstate 17;
break;

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