// turret.txt - Only exists to create creatures. Never moves or attacks. 
// 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 i,target;

body;

beginstate INIT_STATE;
	set_walk_speed(ME,0);
	break;

beginstate DEAD_STATE;
	// Set the appropriate stuff done flag for this character being dead
	if ((get_memory_cell(4) != 0) || (get_memory_cell(5) != 0))
		inc_flag(get_memory_cell(4),get_memory_cell(5),1);
break;

beginstate START_STATE; 
	if (who_shot_me() >= 0) {
		if ((get_memory_cell(0) != 0) || (get_memory_cell(1) != 0)) {
			if (get_attitude(ME) == 4)
				set_attitude(ME,10);
			set_flag(get_memory_cell(0),get_memory_cell(1),0);
			}

		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if ((get_memory_cell(0) != 0) || (get_memory_cell(1) != 0)) {
		if (get_flag(get_memory_cell(0),get_memory_cell(1)) > 0) {
			if (get_attitude(ME) >= 10) {
				set_attitude(ME,4);
				end();
				}
			}
			else if (get_flag(get_memory_cell(0),get_memory_cell(1)) == 0) {
				if (get_attitude(ME) == 4)
					set_attitude(ME,10);
				}
		}
		
	if (get_foe_target(ME,10,0)) {
		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if ((get_memory_cell(0) != 0) || (get_memory_cell(1) != 0)) {
		if (get_flag(get_memory_cell(0),get_memory_cell(1)) > 0) {
			if (get_attitude(ME) >= 10)
				set_attitude(ME,4);
			set_foe_target(ME,-1);
			set_state(START_STATE);
			}
		}

	if (target_ok() == FALSE)
		set_state(START_STATE);
	if (dist_to_char(get_target()) > 8) {
			set_foe_target(ME,-1);
			set_state(START_STATE);
		}
		
	do_attack();

	turret_heal();
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;