#include <define.h>

//#define NAME                    SCRIPT_

#include <command.h>
//#include <ModReact.h>



procedure start;
#include <push.h>
procedure critter_p_proc;
procedure use_skill_on_p_proc;

variable hostile1;
variable initialized1;

import variable valid_target;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 34);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_ROBOTS);
		initialized1 := 1;
	end
	if (global_var(GVAR_DESTROY_VATS_1) == 2) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 85);
	end
	if (script_action == critter_proc) then begin
		call critter_p_proc;
	end
	else begin
		if (script_action == use_skill_on_proc) then begin
			call use_skill_on_p_proc;
		end
	end
end

procedure critter_p_proc
begin
	if (hostile1) then begin
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	if (global_var(GVAR_DESTROY_VATS_3) == 0) then begin
		if ((critter_state(self_obj) bwand 64) == 0) then begin
			critter_injure(self_obj, 64);
		end
	end
	if (global_var(GVAR_DESTROY_VATS_2) != 0) then begin
		if ((critter_state(self_obj) bwand 4) == 0) then begin
			critter_injure(self_obj, 4);
		end
	end
	if (global_var(GVAR_DESTROY_VATS_2) == 2) then begin
		if ((critter_state(self_obj) bwand 8) == 0) then begin
			critter_injure(self_obj, 8);
		end
	end
	if (global_var(GVAR_VATS_ALERT) == 1) then begin
		if (global_var(GVAR_DESTROY_VATS_1) == 0) then begin
			if (obj_can_see_obj(self_obj, dude_obj)) then begin
				hostile1 := 1;
			end
		end
		else begin
			if (global_var(GVAR_DESTROY_VATS_1) == 1) then begin
				if (obj_can_see_obj(self_obj, valid_target)) then begin
					attack_complex(valid_target, 0, 1, 0, 0, 30000, 0, 0);
				end
			end
			else begin
				if (global_var(GVAR_DESTROY_VATS_1) == 2) then begin
					if (obj_can_see_obj(self_obj, valid_target)) then begin
						attack_complex(valid_target, 0, 1, 0, 0, 30000, 0, 0);
					end
				end
				else begin
					if (global_var(GVAR_DESTROY_VATS_1) == 3) then begin
						if (obj_can_see_obj(self_obj, dude_obj)) then begin
							hostile1 := 1;
						end
						else begin
							if (obj_can_see_obj(self_obj, valid_target)) then begin
								attack_complex(valid_target, 0, 1, 0, 0, 30000, 0, 0);
							end
						end
					end
				end
			end
		end
		animate_move_obj_to_tile(self_obj, tile_num_in_direction(tile_num(self_obj), random(0, 5), random(1, 3)), ANIMATE_WALK);
	end
end

procedure use_skill_on_p_proc
begin
	if (action_being_used == 10) then begin
		script_overrides;
	end
end