
begincreaturescript;

variables;

short i,target;
short party_sighted = 0;

body;

beginstate INIT_STATE;
	if (get_memory_cell(0) == 2)
		set_mobility(ME,0);
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (select_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
		
	// Have I been hit? Strike back!
	if (who_hit_me() >= 0) {
		set_target(ME,who_hit_me());
		do_attack();
		set_state(3);
		}
		
	// Otherwise, just peacefully move around. Go back to start, if I'm too far
	// from where I started.
	if (can_see_char(1000))
		party_sighted = 1;
	if ((get_flag(10,17) == 0) && (dist_to_party() <= 6) && (party_sighted > 0)) {
		if (dist_to_party() <= 1) {
			set_flag(10,17,1);
			begin_talk_mode(1);
			}
			else approach_char(ME,random_group_member(0),2);
		}
		else if (my_dist_from_start() >= 1) {
			return_to_start(ME,0);
			}


	// 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 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate TALKING_STATE;
	begin_talk_mode(1);
break;