#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure description_p_proc;
procedure spatial_p_proc;
procedure use_skill_on_p_proc;

variable fired;

import variable removal_ptr;


procedure start
begin
	if (script_action == description_proc) then begin
		call description_p_proc;
	end
	else begin
		if (script_action == spatial_proc) then begin
			call spatial_p_proc;
		end
		else begin
			if (script_action == use_skill_on_proc) then begin
				call use_skill_on_p_proc;
			end
		end
	end
end

procedure description_p_proc
begin
	variable LVar0 := 0;
	script_overrides;
	if (not(local_var(0))) then begin
		if (is_success(do_check(dude_obj, 1, has_trait(0, dude_obj, 0) - 3))) then begin
			LVar0 := message_str(SCRIPT_VLASER, 101);
			if (is_success(roll_vs_skill(dude_obj, 11, 0))) then begin
				LVar0 := LVar0 + message_str(SCRIPT_VLASER, 102);
			end
			set_local_var(0, 1);
		end
		else begin
			LVar0 := 0;
		end
	end
	else begin
		LVar0 := message_str(SCRIPT_VLASER, 101);
	end
	if (LVar0 != 0) then begin
		display_msg(LVar0);
	end
end

procedure spatial_p_proc
begin
	if (fired) then begin
		if (tile_num(source_obj) != tile_num(self_obj)) then begin
			fired := 0;
		end
	end
	else begin
		if (map_var(7) == 1) then begin
			if (map_var(9) == 0) then begin
				display_msg(message_str(SCRIPT_VLASER, 100));
				critter_dmg(source_obj, random(10, 20), 1);
				fired := 1;
			end
		end
	end
end

procedure use_skill_on_p_proc
begin
	if (action_being_used == 11) then begin
		if (local_var(0) == 1) then begin
			script_overrides;
			if (is_success(roll_vs_skill(source_obj, 11, 0))) then begin
				display_msg(message_str(SCRIPT_VLASER, 103));
				set_map_var(9, 1);
				move_to(self_obj, 7000, 0);
				removal_ptr := self_obj;
			end
			else begin
				display_msg(message_str(SCRIPT_VLASER, 104));
			end
		end
	end
end