// forcetalk.txt
// Exactly like basicnpc, but when party gets close, character hunts them down 
// and talks to them
// Memory Cells:
//   Cell 0 - How creature moves.
//     0 - If 0, wander randomly. 
//     1 - Stands still until a target appears.
//     2 - Completely immobile, even if target appears.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this 
//     is killed, set to 1. (Example: If cell 1 is 3 and cell 2 is 5, when
//     creature is killed, sets SDF(3,5) to 1.)
//   Cell 3 - Dialogue node to start with if talked to. if left at 0, this
//     character doesn't talk.
//   Cell 4,5 - Stuff done flag. Set to 1 if the character has hunted them down 
//     once.
//   Cell 6 - range to initiate talking, defaults to 14 if left at 1

begincreaturescript;

variables;

short i,target;
short final_run = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Empire Hostage");
	change_max_health(ME,40);
	set_courage(ME,0);
	
	if (my_id() == 16017)
		set_name(ME,"Envoy Udell");
	
	if (my_id() == 16018)
		set_name(ME,"Envoy Marieke");
	
	if (my_id() == 16019)
		set_name(ME,"Envoy Sklaer");
		
	if (gf(148,1) > 0)
		erase_char(ME);
	if (gf(148,13) >= 3)
		erase_char(ME);

	break;

beginstate DEAD_STATE;
	inc_flag(148,13,1);
	print_str_color("One of the hostages has fallen.",3);
	if (gf(148,13) == 3)
		begin_talk_mode(18);
break;

beginstate START_STATE; 
	if (gf(148,11) == 0) {
		end_combat_turn();
		end();
		}
		
	// Look for a target, attack it if visible
	get_foe_target(ME,12,0);

	if ((gf(148,14) == 0) && (gf(148,16) == 0) && (dist_to_nav_point(ME,6) <= 5)) {
		sf(148,14,1);
		activate_hidden_group(34);
		set_level(16023,13);
		set_name(16023,"Cultist Amla");
		erase_char(16024);
		
		begin_talk_mode(16);
		}

	if (gf(148,11) > 0) {
		if (final_run == 0) {
			if (dist_to_nav_point(ME,5) <= 10) {
				final_run = 1;
				print_str_color("One of the hostages runs for the exit.",3);
				}
				else {
					if (dist_to_party() < 6)
						fidget(ME,10);
						else approach_char(ME,30000,3);
					}
			}
			else {
				if (dist_to_nav_point(ME,5) <= 2) {
					erase_char(ME);
					award_party_xp(100,15);
					print_str_color("One of the hostages has escaped!",3);
					inc_flag(148,12,1);
					if (gf(148,1) == 0)
						begin_talk_mode(17);
					}
				approach_nav_point(ME,5,1);
				}
		}
		
	// if we're in combat and the above didn't give me anything to do, just
	// stop now. Otherwise, game will keep running script, and that eats up CPU time.
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;


beginstate TALKING_STATE;
	begin_talk_mode(19);
break;