#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure use_p_proc;
procedure look_at_p_proc;
procedure use_obj_on_p_proc;
procedure use_skill_p_proc;
procedure map_update_p_proc;
procedure map_enter_p_proc;
procedure damage_p_proc;

import variable J_Door_Ptr;

variable cantopen;


procedure start
begin
	if (script_action == map_enter_proc) then begin
		call map_enter_p_proc;
	end
	else begin
		if ((script_action == look_at_proc) or (script_action == description_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 == use_skill_on_proc) then begin
					call use_skill_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 == damage_proc) then begin
							call damage_p_proc;
						end
						else begin
							if (script_action == timed_event_proc) then begin
								if (not(combat_is_initialized)) then begin
									obj_close(self_obj);
								end
							end
							else begin
								if (script_action == map_update_proc) then begin
									call map_update_p_proc;
								end
							end
						end
					end
				end
			end
		end
	end
end

procedure use_p_proc
begin
	cantopen := 0;
	if (source_obj == dude_obj) then begin
		cantopen := 1;
		if (tile_num(dude_obj) == 27913) then begin
			cantopen := 0;
		end
		else begin
			if (tile_num(dude_obj) == 28113) then begin
				cantopen := 0;
			end
			else begin
				if (tile_num(dude_obj) == 28313) then begin
					cantopen := 0;
				end
			end
		end
	end
	if ((local_var(0) == 0) and cantopen) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_DOOR, 104));
	end
	add_timer_event(self_obj, game_ticks(20), 1);
end

procedure look_at_p_proc
begin
	script_overrides;
	display_msg(message_str(SCRIPT_DOOR, 201));
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, 20);
	if (obj_pid(LVar0) == 84) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_DOOR, 200));
	end
end

procedure use_skill_p_proc
begin
	script_overrides;
	display_msg(message_str(SCRIPT_DOOR, 200));
end

procedure map_update_p_proc
begin
	J_Door_Ptr := self_obj;
end

procedure map_enter_p_proc
begin
	J_Door_Ptr := self_obj;
end

procedure damage_p_proc
begin
	set_obj_visibility(self_obj, 1);
	set_local_var(1, 1);
end