#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure look_at_p_proc;
procedure use_p_proc;
procedure use_obj_on_p_proc;
procedure use_skill_on_p_proc;
procedure alert;

import variable Katja_ptr;

procedure damage_p_proc;


procedure start
begin
	if (script_action == look_at_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_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

procedure look_at_p_proc
begin
	set_map_var(3, self_obj);
end

procedure use_p_proc
begin
	script_overrides;
	if (source_obj == Katja_ptr) then begin
		obj_unlock(self_obj);
		float_msg(Katja_ptr, message_str(SCRIPT_KATJA, 172), FLOAT_MSG_NORMAL);
	end
	else begin
		if (not(obj_is_locked(self_obj))) then begin
			load_map(31, 12);
		end
		else begin
			if ((map_var(1) == 1) or (global_var(GVAR_WATER_CHIP_14) == 1)) then begin
				display_msg(message_str(SCRIPT_MBOUT2IN, 101));
				obj_unlock(self_obj);
			end
			else begin
				display_msg(message_str(SCRIPT_MBOUT2IN, 100));
			end
		end
	end
end

procedure use_obj_on_p_proc
begin
	if (obj_pid(obj_being_used_with) == 77) then begin
		if (not(obj_is_locked(self_obj))) then begin
			script_overrides;
			display_msg(message_str(SCRIPT_MBOUT2IN, 102));
		end
		else begin
			if (is_success(roll_vs_skill(dude_obj, 9, -40))) then begin
				script_overrides;
				display_msg(message_str(SCRIPT_MBOUT2IN, 103));
				obj_unlock(self_obj);
				display_msg(message_str(SCRIPT_GENCHAT, 103) + "65" + message_str(SCRIPT_GENCHAT, 104));
				give_exp_points(65);
			end
			else begin
				script_overrides;
				display_msg(message_str(SCRIPT_MBOUT2IN, 104));
				set_local_var(0, local_var(0) + 1);
			end
		end
	end
	call alert;
end

procedure use_skill_on_p_proc
begin
	if (action_being_used == 9) then begin
		if (not(obj_is_locked(self_obj))) then begin
			display_msg(message_str(SCRIPT_MBOUT2IN, 102));
		end
		else begin
			if (is_success(roll_vs_skill(dude_obj, 9, -60))) then begin
				script_overrides;
				obj_unlock(self_obj);
				display_msg(message_str(SCRIPT_MBOUT2IN, 103));
				give_exp_points(85);
				display_msg(message_str(SCRIPT_GENCHAT, 103) + "85" + message_str(SCRIPT_GENCHAT, 104));
			end
			else begin
				script_overrides;
				display_msg(message_str(SCRIPT_MBOUT2IN, 105));
				set_local_var(0, local_var(0) + 1);
			end
		end
	end
	call alert;
end

procedure alert
begin
	if (local_var(0) > 2) then begin
		set_global_var(GVAR_VATS_ALERT, 1);
	end
end

procedure damage_p_proc
begin
	set_local_var(0, local_var(0) + 1);
	display_msg(message_str(SCRIPT_MBOUT2IN, 106));
	call alert;
end