#include <define.h>

//#define NAME                    SCRIPT_

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



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

import variable removal_ptr;

variable triggered;
variable test;


procedure start
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

procedure spatial_p_proc
begin
	if (source_obj == dude_obj) then begin
		if (tile_num(dude_obj) != tile_num(self_obj)) then begin
			triggered := 0;
		end
		else begin
			if (triggered == 0) then begin
				triggered := 1;
				if ((art_anim(obj_art_fid(dude_obj)) == 1) and is_success(do_check(dude_obj, 1, 0)) and is_success(do_check(dude_obj, 5, 0))) then begin
					display_msg(message_str(SCRIPT_VMONOWIR, 100));
					set_map_var(13, 1);
				end
				else begin
					display_msg(message_str(SCRIPT_VMONOWIR, 101));
					if (art_anim(obj_art_fid(dude_obj)) == 1) then begin
						critter_dmg(dude_obj, random(10, 20), 1);
					end
					else begin
						critter_dmg(dude_obj, random(15, 30), 1);
					end
					if (not(is_success(do_check(dude_obj, 6, 0)))) then begin
						if (random(0, 1)) then begin
							display_msg(message_str(SCRIPT_VMONOWIR, 102));
							critter_injure(dude_obj, 8);
						end
						else begin
							display_msg(message_str(SCRIPT_VMONOWIR, 103));
							critter_injure(dude_obj, 4);
						end
					end
				end
			end
		end
	end
end

procedure use_skill_on_p_proc
begin
	if ((map_var(7) == 1) and (map_var(13) == 0)) then begin
		script_overrides;
		if (is_success(roll_vs_skill(dude_obj, 11, -20))) then begin
			display_msg(message_str(SCRIPT_VMONOWIR, 104));
			set_map_var(13, 1);
			move_to(self_obj, 7000, 0);
			removal_ptr := self_obj;
		end
		else begin
			if (is_critical(test)) then begin
				display_msg(message_str(SCRIPT_VMONOWIR, 106));
				critter_dmg(dude_obj, 1, 1);
			end
			else begin
				display_msg(message_str(SCRIPT_VMONOWIR, 105));
			end
		end
	end
end