#include <define.h>

//#define NAME                    SCRIPT_

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



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


procedure start
begin
	if (script_action == look_at_proc) then begin
		call look_at_p_proc;
	end
	else begin
		if (script_action == use_proc) then begin
			call use_p_proc;
		end
		else begin
			if (script_action == pickup_proc) then begin
				call pickup_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
				end
			end
		end
	end
end

procedure use_p_proc
begin
	if (local_var(0) == 0) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_LOCKER, 100));
	end
end

procedure pickup_p_proc
begin
	call use_p_proc;
end

procedure use_skill_on_p_proc
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	LVar1 := action_being_used;
	LVar0 := roll_vs_skill(dude_obj, 9, -20);
	if (LVar1 == 9) then begin
		script_overrides;
		if (is_success(LVar0)) then begin
			set_local_var(0, 1);
			display_msg(message_str(SCRIPT_LOCKER, 102));
		end
		else begin
			display_msg(message_str(SCRIPT_LOCKER, 103));
		end
	end
end

procedure use_obj_on_p_proc
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	LVar0 := obj_being_used_with;
	LVar1 := roll_vs_skill(dude_obj, 9, 0);
	if (obj_pid(LVar0) == 84) then begin
		script_overrides;
		if (is_success(LVar1)) then begin
			set_local_var(0, 1);
			display_msg(message_str(SCRIPT_LOCKER, 102));
		end
		else begin
			if (is_critical(LVar1)) then begin
				rm_obj_from_inven(dude_obj, LVar0);
				destroy_object(LVar0);
				display_msg(message_str(SCRIPT_LOCKER, 101));
			end
			else begin
				display_msg(message_str(SCRIPT_LOCKER, 103));
			end
		end
	end
end

procedure look_at_p_proc
begin
	if (local_var(0) == 0) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_LOCKER, 100));
	end
end