#include <define.h>

//#define NAME                    SCRIPT_

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



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

variable test;


procedure start
begin
	if (script_action == description_proc) then begin
		call description_p_proc;
	end
	else begin
		if (script_action == map_enter_proc) then begin
			call map_enter_p_proc;
		end
		else 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
				end
			end
		end
	end
end

procedure description_p_proc
begin
	script_overrides;
	display_msg(message_str(SCRIPT_VCONDOOR, 100));
end

procedure map_enter_p_proc
begin
	obj_lock(self_obj);
end

procedure use_p_proc
begin
	if (obj_is_locked(self_obj)) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_VCONDOOR, 101));
	end
end

procedure use_obj_on_p_proc
begin
	if (obj_being_used_with == 77) then begin
		script_overrides;
		if (not(obj_is_locked(self_obj))) then begin
			display_msg(message_str(SCRIPT_VCONDOOR, 104));
		end
		else begin
			test := roll_vs_skill(dude_obj, 9, 0);
			if (is_success(test)) then begin
				display_msg(message_str(SCRIPT_VCONDOOR, 102));
				obj_unlock(self_obj);
			end
			else begin
				if (is_critical(test)) then begin
					display_msg(message_str(SCRIPT_VCONDOOR, 103));
					jam_lock(self_obj);
				end
				else begin
					display_msg(message_str(SCRIPT_VCONDOOR, 106));
				end
			end
		end
	end
end

procedure use_skill_on_p_proc
begin
	if (action_being_used == 9) then begin
		script_overrides;
		if (not(obj_is_locked(self_obj))) then begin
			display_msg(message_str(SCRIPT_VCONDOOR, 104));
		end
		else begin
			test := roll_vs_skill(source_obj, action_being_used, -20);
			if (is_success(test)) then begin
				display_msg(message_str(SCRIPT_VCONDOOR, 102));
				obj_unlock(self_obj);
			end
			else begin
				if (is_critical(test)) then begin
					display_msg(message_str(SCRIPT_VCONDOOR, 103));
					jam_lock(self_obj);
				end
				else begin
					display_msg(message_str(SCRIPT_VCONDOOR, 105));
				end
			end
		end
	end
end