// spawner.txt - Only exists to create creatures. Never moves or attacks. 
// If it sees a foe, it summons a creature. Does so at most once every 3 rounds.
// Cells 0 - 3 - Numbers of creatures to spawn. if 0, no use.
// Cell 4,5 - Stuff done flag to set when spawner is killed. If both are 0, no 
// flag set.
// Cell 6 - talking cell

begincreaturescript;

variables;

short r1;
short last_spawn;

body;

beginstate INIT_STATE;
	set_walk_speed(ME,0);
	last_spawn = get_current_tick();
	break;

beginstate DEAD_STATE;
	if ((get_memory_cell(4) != 0) || (get_memory_cell(5) != 0))
		set_flag(get_memory_cell(4),get_memory_cell(5),1);
break;

beginstate START_STATE; 
	// see if target is visible
	get_foe_target(ME,12,0);
	
	if ((target_ok()) && (dist_to_party() <= 12)) {
		if ((tick_difference(last_spawn,get_current_tick()) > 2) && 
		  ((get_ran(1,0,100) < 60) || (friends_nearby(4) == 0))) {
			r1 = get_ran(1,0,3);
			if (get_memory_cell(r1) > 0) {
				if (summon_creature(get_memory_cell(r1))) {
					print_named_str(ME,"creates a new foe!");
					set_summon_level(get_memory_cell(r1),1);
					place_particle_num(get_memory_cell(r1),1,1,8);
					run_char_animation(3,1,50);	
					pc_heard_sound_delay(161,100);						
					
					last_spawn = get_current_tick();
					

					}
				}
			}
		}
break;

beginstate TALKING_STATE;
	if (get_memory_cell(6) == 0) {
		print_str("Talking: It doesn't respond. It can't talk.");
		end();
		}
	begin_talk_mode(get_memory_cell(6));
break;