// TOWN SPECIAL ENCOUNTERS
//    Town 16: Garzahd's Fortress

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 200;
short last_abil;
short counter = 0;
short set_ter = 0;

//123456 789 10

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

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

	sf(16,20,1);
	if (gf(16,11) == 0)
		sf(16,8,0);
	if (gf(16,11) > 0)
		set_terrain(0,59,2,0);
		
	sf(16,19,100);
	sf(16,18,0);
	
	set_aggression(30001,50);
	
	set_level(30002,30);
	set_attack_bonus(30002,20);
	change_max_health(30002,100);
	set_aggression(30002,50);

	set_attack_bonus(30003,20);
	change_max_health(30003,100);
	set_aggression(30003,50);

	set_aggression(30004,30);

	set_level(30005,30);
	set_attack_bonus(30005,20);
	change_max_health(30005,100);
	set_aggression(30005,50);

	set_level(30006,30);
	set_attack_bonus(30006,20);
	change_max_health(30006,100);
	set_aggression(30006,50);

	set_name(1629,"Eternal Archivist");
	set_boss_level(1629,1);
	
	set_level(30007,28);
	set_attack_bonus(30007,20);
	change_max_health(30007,100);
	set_aggression(30007,40);

	set_level(30008,28);
	set_attack_bonus(30008,20);
	change_max_health(30008,100);

	set_level(30009,28);
	set_attack_bonus(30009,20);
	change_max_health(30009,100);

	set_attack_bonus(30010,10);
	change_max_health(30010,50);
	
	set_crime_tolerance(max_crime);

	break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	if ((gf(16,1) == 0) && ((party_within_dist(7,36,7)) || (party_within_dist(22,50,7)))) {
		sf(16,1,1);
		sf(16,20,0);
		ok_dlog(26,2);
		}
		
	if (gf(16,4) == 1) { // erase some demons
		erase_char(30007);
		}
	if (gf(16,5) == 1) { // erase some more demons
		erase_char(30008);
		erase_char(30009);
		}
		
	if (gf(16,25) == 1) {
		sf(16,25,2);
		
		ok_dlog(63,2);
		}
		
	if (gf(16,26) == 1) {
		sf(16,26,2);
		
		ok_dlog(66,2);
		}
		
	if (gf(16,27) == 1) {
		sf(16,27,2);
		
		ok_dlog(75,2);
		}
		
	if (gf(16,28) == 1) {
		sf(16,28,2);
		
		ok_dlog(78,3);
		}
		
	if ((char_ok(1603)) && (get_level(1603) < 30))
		set_level(1603,30);
	if ((char_ok(1606)) && (get_level(1606) < 30))
		set_level(1606,30);

	if ((gf(16,16) > 0) && (gf(16,11) == 0))
		run_special(18);
		
	if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_town()) && (tick_difference(last_abil,get_current_tick()) > 0))) {
		last_abil = get_current_tick();
		
		if (gf(16,18) > 1) {
			inc_flag(16,18,-1);
			if (gf(16,18) == 1) {
				set_terrain(0,59,2,0);
				ok_dlog(82,3);
				}
			}
		}
break;

beginstate 10;
break;

beginstate 11;
break;

beginstate 12;
break;

beginstate 13;
break;

beginstate 14;
break;

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

