#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 look_at_p_proc;
procedure use_skill_on_p_proc;
procedure use_obj_on_p_proc;
procedure chance;
procedure try_skill;
procedure fixed;
procedure failure;

variable Test;
variable temp;
variable bonus;
variable use_skill;


procedure start
begin
	bonus := 0;
	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 == 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
				else begin
					if (script_action == use_obj_on_proc) then begin
						call use_obj_on_p_proc;
					end
				end
			end
		end
	end
end

procedure use_p_proc
begin
	if (source_obj != dude_obj) then begin
	end
	else begin
		display_msg(message_str(SCRIPT_ARMOR, 101));
	end
end

procedure pickup_p_proc
begin
	call use_p_proc;
end

procedure look_at_p_proc
begin
	display_msg(message_str(SCRIPT_ARMOR, 100));
end

procedure use_skill_on_p_proc
begin
	use_skill := action_being_used;
	call try_skill;
end

procedure use_obj_on_p_proc
begin
	if (obj_pid(obj_being_used_with) == 75) then begin
		bonus := 10;
		use_skill := 13;
		call use_skill_on_p_proc;
	end
	else begin
		display_msg(message_str(SCRIPT_ARMOR, 105));
	end
end

procedure chance
begin
	Test := roll_vs_skill(dude_obj, 13, bonus);
	if (is_success(Test)) then begin
		call fixed;
	end
	else begin
		call failure;
	end
end

procedure try_skill
begin
	if (use_skill == 13) then begin
		if (global_var(GVAR_CALM_REBELS_7) > 1) then begin
			if (global_var(GVAR_CALM_REBELS_7) == 3) then begin
				if (has_skill(dude_obj, 13) < 75) then begin
					script_overrides;
					display_msg(message_str(SCRIPT_ARMOR, 103));
				end
				else begin
					call chance;
				end
			end
			else begin
				call chance;
			end
		end
		else begin
			script_overrides;
			display_msg(message_str(SCRIPT_ARMOR, 102));
		end
	end
	else begin
		script_overrides;
		display_msg(message_str(SCRIPT_ARMOR, 105));
	end
end

procedure fixed
begin
	script_overrides;
	set_global_var(GVAR_CALM_REBELS_7, 4);
	display_msg(message_str(SCRIPT_ARMOR, 104));
	create_object_sid(3, 22475, 0, -1);
	temp := 500;
	display_msg(message_str(SCRIPT_ARMOR, 107) + temp + message_str(SCRIPT_ARMOR, 108));
	give_exp_points(temp);
	destroy_object(self_obj);
end

procedure failure
begin
	script_overrides;
	set_global_var(GVAR_CALM_REBELS_7, 3);
	display_msg(message_str(SCRIPT_ARMOR, 106));
end