#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 timed_event_p_proc;
procedure whoami;

variable once_only := 1;
variable Test;
variable bonus;
variable failure;

import variable locker_ptr;


procedure start
begin
	if (once_only) then begin
		once_only := 0;
		locker_ptr := self_obj;
	end
	if (script_action == timed_event_proc) then begin
		call timed_event_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_skill_on_proc) then begin
					call use_skill_on_p_proc;
				end
			end
		end
	end
end

procedure use_p_proc
begin
	if (source_obj == dude_obj) then begin
		bonus := -35;
		failure := 1;
		if (metarule(16, 0) > 1) then begin
			set_map_var(19, 2);
		end
		else begin
			if (source_obj == dude_obj) then begin
				if (using_skill(dude_obj, 8)) then begin
					Test := roll_vs_skill(dude_obj, 8, bonus);
					if (is_success(Test)) then begin
						failure := 0;
					end
					else begin
						failure := 1;
					end
					if (has_skill(dude_obj, 8) < 40) then begin
						failure := 1;
					end
				end
			end
			if (failure) then begin
				display_msg(message_str(SCRIPT_RHOMBUS, 204));
				set_map_var(19, 2);
			end
			else begin
				display_msg(message_str(SCRIPT_RHOMBUS, 205));
			end
		end
		add_timer_event(self_obj, game_ticks(1), 1);
	end
end

procedure pickup_p_proc
begin
	call use_p_proc;
end

procedure use_skill_on_p_proc
begin
	if (action_being_used == 9) then begin
		display_msg(message_str(SCRIPT_RHOMBUS, 208));
	end
end

procedure timed_event_p_proc
begin
	if (not(combat_is_initialized)) then begin
		obj_close(self_obj);
	end
end

procedure whoami
begin
	locker_ptr := self_obj;
end