// TOWN SPECIAL ENCOUNTERS
//    Town 13: Erika's Tower

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 200;
short last_abil;
short last_abil2;
short counter = 0;
short set_ter = 0;
short i,j;

body;

//1234 6 89

beginstate INIT_STATE;
	last_abil = get_current_tick();
	last_abil2 = get_current_tick();

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

	set_aggression(30001,70);
	set_aggression(30002,70);
	set_aggression(30003,50);
	set_aggression(30004,70);
	
	set_personality_name(260,"Erika");

	set_name(1304,"Empire Infiltrator");
	set_name(1306,"Empire Infiltrator");
	set_name(1307,"Empire Infiltrator");
	set_name(1308,"Empire Infiltrator");
	set_level(30008,25);
	
	if (gf(13,28) > 0)
		erase_char(30008);
		
	set_crime_tolerance(max_crime);

	break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	if (gf(13,27) == 1) {
		sf(13,27,2);
		activate_hidden_group(9);
		set_level(30006,22 + difficulty() * 2);
		set_attack_bonus(30006,5 + difficulty() * 5);
		if (difficulty() > 1)
			set_new_abil(30006,12);
		}
	
	if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_town()) && (tick_difference(last_abil,get_current_tick()) > 4))) {
		last_abil = get_current_tick();
		
		sf(13,26,0);
		
		if ((gf(13,22) == 0) && (gf(13,20) > 0)) {


			inc_flag(13,21,-1);
			if (gf(13,21) < 1) {
				sf(13,20,0);
				ok_dlog(55,1);
				}
			}
		if ((gf(13,25) == 0) && (gf(13,23) > 0)) {


			inc_flag(13,24,-1);
			if (gf(13,24) < 1) {
				sf(13,23,0);
				ok_dlog(55,1);
				}
			}
		
		}
	
	if (((is_combat()) && (tick_difference(last_abil2,get_current_tick()) > 0)) || ((is_town()) && (tick_difference(last_abil2,get_current_tick()) > 0))) {
		last_abil2 = get_current_tick();
		
		
		if ((gf(13,22) == 0) && (gf(13,20) > 0)) {
				i = 14; j = 25;
				while (i < 17) {
					while (j < 39) {
						make_field(0,i,j,0);
						j = j + 1;
						}
					j = 25;
					
					i = i + 1;
					}

			}
		if ((gf(13,25) == 0) && (gf(13,23) > 0)) {
				i = 26; j = 11;
				while (i < 41) {
					while (j < 14) {
						make_field(0,i,j,1);
						j = j + 1;
						}
					j = 11;
					
					i = i + 1;
					}


			}
		
		}
	if (gf(13,14) == 0) {
		if (get_ran(1,0,100) < 30)
			give_char_text_bubble(1311,"You're finally here.");
		if (get_ran(1,0,100) < 30)
			give_char_text_bubble(1311,"You kept me waiting.");
		}
	if (gf(13,14) > 0) {
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(1311,"So much to do.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(1311,"The vahnatai are dangerous.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(1311,"The Abyss is lost.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(1311,"Trust is foolish.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(1311,"One war after another.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(1311,"It is a long journey.");
		if (get_ran(1,0,100) < 10)
			give_char_text_bubble(1311,"We need allies.");
		}
break;

beginstate 10;
	sf(13,22,1);
break;

beginstate 11;
	if ((gf(13,20) > 0) && (gf(13,22) == 0) && (char_ok(1342) == FALSE)) {
		play_sound(171);	
		spawn_creature(1342);
		place_particle_num(1342,1,1,8);
		set_level(1342,10 + difficulty() * 7);
		set_summon_level(1342,1);
		}
break;

beginstate 12;
	sf(13,25,1);
break;

beginstate 13;
	if (gf(13,1) == 0) {
		sf(13,1,1);
		ok_dlog(59,3);
		if (difficulty() > 0)
			set_char_status(random_group_member(0),35,5);
		activate_hidden_group(5);
		
		set_name(1351,"Cultist Haveral");
		set_level(1351,28);
		set_boss_level(1351,1);
		set_name(1352,"Infiltrator Hafu");
		set_level(1352,28);
		set_boss_level(1352,1);
		
		}
break;

beginstate 14;
break;

beginstate 16;
	if ((gf(13,23) > 0) && (gf(13,25) == 0) && (char_ok(1343) == FALSE)) {
		play_sound(171);	
		spawn_creature(1343);
		place_particle_num(1343,1,1,8);
		set_level(1343,20 + difficulty() * 3);
		if (difficulty() > 1)
			set_new_abil(1343,14);
		set_summon_level(1343,1);
		}
break;

beginstate 17;
	if ((gf(13,23) > 0) && (gf(13,25) == 0) && (char_ok(1345) == FALSE)) {
		play_sound(171);	
		spawn_creature(1345);
		place_particle_num(1345,1,1,8);
		set_level(1345,20 + difficulty() * 3);
		if (difficulty() > 1)
			set_new_abil(1345,14);
		set_summon_level(1345,1);
		}
break;

beginstate 18;
	if ((gf(13,23) > 0) && (gf(13,25) == 0) && (char_ok(1346) == FALSE)) {
		play_sound(171);	
		spawn_creature(1346);
		place_particle_num(1346,1,1,8);
		set_level(1346,20 + difficulty() * 3);
		if (difficulty() > 1)
			set_new_abil(1346,14);
		set_summon_level(1346,1);
		}
break;

beginstate 19;
	if ((gf(13,23) > 0) && (gf(13,25) == 0) && (char_ok(1347) == FALSE)) {
		play_sound(171);	
		spawn_creature(1347);
		place_particle_num(1347,1,1,8);
		set_level(1347,20 + difficulty() * 3);
		if (difficulty() > 1)
			set_new_abil(1347,14);
		set_summon_level(1347,1);
		}
break;

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

