// .txt

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 5;
short last_abil;
short counter = 0;
short r1,r2;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

//	set_name(,"");

	add_range_to_group(15,21,1);
	set_boss_level(30001,1);
	set_attack_bonus(30001,30);
	set_name(21,"Clodeca-Tel");
	
	set_crime_tolerance(max_crime);

	set_obj_act_at_dist(30,1);

	if (gf(0,16) > 0)
		set_terrain(0,43,45,229);
	if (gf(0,17) > 0)
		set_terrain(0,28,42,229);
	if (gf(0,6) > 0) {
		set_terrain(1,3,29,0);
		set_terrain(1,3,32,0);
		set_terrain(1,5,46,0);
		set_terrain(1,5,50,0);
		}
		
		sf(0,15,1);
	sf(0,5,0);
	
	add_range_to_group(34,37,3);
	set_name(30003,"Abandoned Sentinel");
	set_level(30003,28);
	set_aggression(30003,50);

	set_name(33,"Gavaw-Te");
	set_boss_level(33,1);
	set_new_abil(33,20);
	alter_stat(33,28,6);
	
	if (gf(0,7) == 0)
		sf(0,19,0);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;

	if ((gf(0,15) == 2) && (num_chars_in_group(2) == 0))
		sf(0,15,0);
		
	if ((gf(0,16) == 0) && (party_dist_to_spot(43,45) <= 3) && (on_which_layer() == 0)) {
		sf(0,16,1);
		
		set_terrain(0,43,45,229);
		
		set_char_status(30000,0,-12);
		set_char_status(30000,1,-12);
		set_char_status(30000,8,-12);
		
		spawn_creature(0);
		spawn_creature(1);
		spawn_creature(2);
		spawn_creature(3);
		
		begin_talk_mode(10);
		}
	if ((gf(0,17) == 0) && (party_dist_to_spot(28,42) <= 3) && (on_which_layer() == 0)) {
		sf(0,17,1);
		
		set_terrain(0,28,42,229);
		
		set_char_status(30000,0,-12);
		set_char_status(30000,1,-12);
		set_char_status(30000,8,-12);
		
		spawn_creature(4);
		spawn_creature(5);
		spawn_creature(6);
		spawn_creature(7);
		
		begin_talk_mode(10);
		}
	
	// EVENT STUFF
	if ((gf(0,19) < 2) && (gf(0,7) == 0) && (on_which_layer() == 1) && (party_within_dist(30,26,3))) {
		sf(0,20,0);
		
		if (gf(0,19) == 0) {
			sf(0,19,2);
			talk_no_exit(50);
			}
			else {
				sf(0,19,2);
				talk_no_exit(19);
				}
		}
	if ((gf(0,20) > 3) && (gf(0,19) == 2)) {
		sf(0,19,3);
		begin_talk_mode(16);
		}
		else {
			if ((gf(0,20) > 6) && (gf(0,19) == 3)) {
				sf(0,19,4);

				set_resistance(46,0,0);
				set_resistance(46,1,0);
				set_resistance(46,2,0);
				set_resistance(46,4,0);
				set_resistance(46,5,0);
				set_resistance(46,6,0);
				set_walk_speed(46,1);
				set_char_unkillable(46,0);
				clean_off_particles(46);
				
				begin_talk_mode(17);
				}
			}
		
	if (((gf(0,19) == 2) || (gf(0,19) == 3)) && (party_within_dist(30,26,4) == FALSE)) {
		erase_char(38);
		erase_char(39);
		erase_char(40);
		erase_char(41);
		erase_char(42);
		erase_char(43);
		erase_char(44);
		erase_char(45);
		sf(0,19,1);
		begin_talk_mode(15);
		}
	
	//
	
	if ((get_crime_level() >= max_crime) && (im_hostile == 0)) {
		make_zone_hostile();
		im_hostile = 1;
		sf(0,13,1);
		}
		
	if (char_ok(21) == FALSE)
		sf(0,11,1);

	if (gf(0,13) == 0) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(21,"Help has come.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(21,"I am grateful.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(21,"I would help Avernum.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(21,"Is a dark place.");
		}

	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(0,19) > 1) {
			counter = counter + 1;
			
			// orbs
			if (gf(0,19) < 4) {
				if (char_ok(44) == FALSE) {
					print_str_color("Dagas-Ihrno creates a fiery magical orb.",2);
					spawn_creature(44);
				
					place_particle_num(44,1,1,8);
					set_summon_level(44,1);
					}
					else if (char_ok(45) == FALSE) {
						print_str_color("Dagas-Ihrno creates a fiery magical orb.",2);
						spawn_creature(45);
				
						place_particle_num(45,1,1,8);
						set_summon_level(45,1);
						}
				}
				
			// vahnavaoi
			if ((counter == 1) && (gf(0,19) > 1)) {
				r1 = get_ran(1,0,5);
				if (char_ok(38 + r1))
					r1 = get_ran(1,0,5);
				if (char_ok(38 + r1) == FALSE) {
					print_str_color("Rentar-Ihrno's magical machinery spits out the ghost of",2);
					print_str_color("  a vahnatai warrior.",2);
					spawn_creature(38 + r1);
					//r2 = get_ran(1,0,2);
					//if (r2 == 0)
					//	set_new_abil(38 + r1,11);
					//if (r2 == 1)
					//	set_new_abil(38 + r1,15);
					//if (r2 == 2)
					//	set_new_abil(38 + r1,16);
					play_sound(136);						
					place_particle_num(38 + r1,1,1,8);
					set_summon_level(38 + r1,1);
					}
				}
				
			if (counter == 4)
				counter = 0;
			}
		}
break;

beginstate 10;
break;

beginstate 11;
break;

beginstate 12;
break;

beginstate 13;
break;

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