#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure search;
procedure skills;

variable test;
variable test1;
variable test2;
variable test3;
variable use_skill;


procedure start
begin
	if (script_action == look_at_proc) then begin
		script_overrides;
		call search;
	end
	else begin
		if (script_action == use_skill_on_proc) then begin
			use_skill := action_being_used;
			script_overrides;
			call skills;
		end
		else begin
			if (script_action == use_proc) then begin
				if (global_var(GVAR_NECROP_WATER_PUMP_FIXED) != 2) then begin
					script_overrides;
					display_msg(message_str(SCRIPT_NH2OPUMP, 112));
				end
			end
			else begin
				if (script_action == use_obj_on_proc) then begin
					if (obj_pid(obj_being_used_with) == 98) then begin
						script_overrides;
						test2 := roll_vs_skill(dude_obj, 13, -5);
						if (is_success(test2)) then begin
							display_msg(message_str(SCRIPT_NH2OPUMP, 114));
							rm_obj_from_inven(dude_obj, obj_being_used_with);
							add_obj_to_inven(self_obj, obj_being_used_with);
							set_global_var(GVAR_NECROP_WATER_PUMP_FIXED, 2);
							set_global_var(GVAR_HUB_FILLER_30, 0);
							set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 1);
							give_exp_points(1000);
							display_msg(message_str(SCRIPT_NH2OPUMP, 118));
						end
						else begin
							if (is_critical(test2)) then begin
								display_msg(message_str(SCRIPT_NH2OPUMP, 115));
								game_time_advance(game_ticks(240));
								rm_obj_from_inven(dude_obj, obj_being_used_with);
								critter_dmg(dude_obj, 1, 0);
							end
							else begin
								display_msg(message_str(SCRIPT_NH2OPUMP, 116));
								game_time_advance(game_ticks(180));
							end
						end
					end
					else begin
						display_msg(message_str(SCRIPT_NH2OPUMP, 117));
					end
				end
			end
		end
	end
end

procedure search
begin
	test := do_check(dude_obj, 4, 0);
	if (global_var(GVAR_NECROP_WATER_PUMP_FIXED) == 2) then begin
		display_msg(message_str(SCRIPT_NH2OPUMP, 100));
	end
	else begin
		if (is_success(test)) then begin
			if (is_critical(test)) then begin
				display_msg(message_str(SCRIPT_NH2OPUMP, 101));
			end
			else begin
				display_msg(message_str(SCRIPT_NH2OPUMP, 102));
			end
		end
		else begin
			display_msg(message_str(SCRIPT_NH2OPUMP, 103));
		end
	end
end

procedure skills
begin
	test1 := roll_vs_skill(dude_obj, 12, -10);
	test2 := roll_vs_skill(dude_obj, 13, 0);
	test3 := roll_vs_skill(dude_obj, 12, -20);
	if (use_skill == 13) then begin
		if (is_success(test2)) then begin
			display_msg(message_str(SCRIPT_NH2OPUMP, 108));
		end
		else begin
			if (is_critical(test2)) then begin
				display_msg(message_str(SCRIPT_NH2OPUMP, 107));
			end
			else begin
				display_msg(message_str(SCRIPT_NH2OPUMP, 109));
			end
		end
	end
	else begin
		if (use_skill == 12) then begin
			if (is_success(test3)) then begin
				display_msg(message_str(SCRIPT_NH2OPUMP, 111));
			end
			else begin
				if (is_critical(test3)) then begin
					display_msg(message_str(SCRIPT_NH2OPUMP, 110));
				end
				else begin
					display_msg(message_str(SCRIPT_NH2OPUMP, 112));
				end
			end
		end
		else begin
			display_msg(message_str(SCRIPT_NH2OPUMP, 113));
		end
	end
end