#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure use_p_proc;
procedure use_obj_on_p_proc;
procedure use_skill_on_p_proc;
procedure damage_p_proc;

import variable Field1d_Ptr;


procedure start
begin
	if (script_action == use_proc) then begin
		call use_p_proc;
	end
	else begin
		if (script_action == use_obj_on_proc) then begin
			call use_obj_on_p_proc;
		end
		else begin
			if (script_action == use_skill_on_proc) then begin
				call use_skill_on_p_proc;
			end
			else begin
				if (script_action == damage_proc) then begin
					call damage_p_proc;
				end
			end
		end
	end
end

procedure use_p_proc
begin
	script_overrides;
	display_msg(message_str(SCRIPT_EMITER1A, 100));
end

procedure use_obj_on_p_proc
begin
	variable LVar0 := 0;
	LVar0 := obj_pid(obj_being_used_with);
	if (local_var(0) == 0) then begin
		if (LVar0 == 75) then begin
			script_overrides;
			if (is_success(roll_vs_skill(dude_obj, 13, 0))) then begin
				if (map_var(17) == 1) then begin
					set_obj_visibility(Field1d_Ptr, 1);
					display_msg(message_str(SCRIPT_EMITER1A, 103));
					give_exp_points(50);
					set_map_var(17, 0);
				end
				else begin
					set_obj_visibility(Field1d_Ptr, 0);
					display_msg(message_str(SCRIPT_EMITER1A, 105));
					set_map_var(17, 1);
				end
			end
			else begin
				display_msg(message_str(SCRIPT_EMITER1A, 104));
			end
		end
	end
end

procedure use_skill_on_p_proc
begin
	variable LVar0 := 0;
	LVar0 := action_being_used;
	if (local_var(0) == 0) then begin
		if (LVar0 == 13) then begin
			script_overrides;
			if (is_success(roll_vs_skill(dude_obj, 13, -20))) then begin
				if (map_var(17) == 1) then begin
					display_msg(message_str(SCRIPT_EMITER1A, 103));
					set_obj_visibility(Field1d_Ptr, 1);
					give_exp_points(50);
					set_map_var(17, 0);
				end
				else begin
					set_obj_visibility(Field1d_Ptr, 0);
					display_msg(message_str(SCRIPT_EMITER1A, 105));
					set_map_var(17, 1);
				end
			end
			else begin
				display_msg(message_str(SCRIPT_EMITER1A, 104));
			end
		end
	end
end

procedure damage_p_proc
begin
	if (is_success(roll_vs_skill(dude_obj, 11, 0))) then begin
		set_local_var(0, 1);
		destroy_object(Field1d_Ptr);
		display_msg(message_str(SCRIPT_EMITER1A, 102));
	end
	else begin
		set_map_var(17, 0);
		set_obj_visibility(self_obj, 1);
		display_msg(message_str(SCRIPT_EMITER1A, 101));
	end
end