#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure description_p_proc;
procedure use_p_proc;
procedure pickup_p_proc;
procedure use_skill_on_p_proc;
procedure secret;

import variable J_Door_Ptr;

variable use_skill;
variable Door_Test;


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

procedure description_p_proc
begin
	script_overrides;
	display_msg(message_str(SCRIPT_BOOKCASE, 200));
end

procedure use_p_proc
begin
	script_overrides;
	if ((local_var(0) == 1) or (Door_Test == 1)) then begin
		display_msg(message_str(SCRIPT_BOOKCASE, 104));
		use_obj(J_Door_Ptr);
	end
	else begin
		display_msg(message_str(SCRIPT_BOOKCASE, 101));
	end
end

procedure pickup_p_proc
begin
	script_overrides;
end

procedure use_skill_on_p_proc
begin
	use_skill := action_being_used;
	if ((local_var(0) == 0) and (Door_Test == 0)) then begin
		if (use_skill == 9) then begin
			script_overrides;
			if (is_success(roll_vs_skill(dude_obj, 9, 0))) then begin
				set_local_var(0, 1);
				Door_Test := 1;
				display_msg(message_str(SCRIPT_BOOKCASE, 102));
			end
			else begin
				display_msg(message_str(SCRIPT_BOOKCASE, 105));
			end
		end
		else begin
			if (use_skill == 11) then begin
				script_overrides;
				if (is_success(roll_vs_skill(dude_obj, 11, 0))) then begin
					set_local_var(0, 1);
					Door_Test := 1;
					display_msg(message_str(SCRIPT_BOOKCASE, 102));
				end
				else begin
					display_msg(message_str(SCRIPT_BOOKCASE, 105));
				end
			end
			else begin
				display_msg(message_str(SCRIPT_BOOKCASE, 103));
			end
		end
	end
	else begin
		display_msg(message_str(SCRIPT_BOOKCASE, 103));
	end
end

procedure secret
begin
	set_local_var(0, 1);
	display_msg(message_str(SCRIPT_BOOKCASE, 102));
end