#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_stuff;
procedure ladderend;
procedure ladder00;
procedure ladder01;
procedure ladder01a;

variable testa;
variable testb;
variable bonus;
variable damage;
variable manhole_open;


procedure start
begin
	if (script_action == use_proc) then begin
		script_overrides;
		call do_stuff;
	end
end

procedure do_stuff
begin
	manhole_open := map_var(local_var(0));
	if (manhole_open) then begin
		call ladder00;
	end
	else begin
		call ladder01;
	end
end

procedure ladderend
begin
end

procedure ladder00
begin
	move_to(dude_obj, local_var(1), local_var(2));
end

procedure ladder01
begin
	bonus := 1 - local_var(0);
	testa := do_check(dude_obj, 0, bonus);
	call ladder01a;
end

procedure ladder01a
begin
	if (is_success(testa)) then begin
		set_local_var(0, 0);
		display_msg(message_str(SCRIPT_LADDER, 100));
		call ladder00;
	end
	else begin
		set_local_var(0, local_var(0) + 1);
		if (is_critical(testa)) then begin
			display_msg(message_str(SCRIPT_LADDER, 101));
			damage := random(1, 6) - 4;
			if (damage < 1) then begin
				damage := 1;
			end
			critter_dmg(dude_obj, damage, 0);
		end
		else begin
			display_msg(message_str(SCRIPT_LADDER, 102));
			testb := do_check(dude_obj, 5, 0);
			if (is_success(testb)) then begin
				display_msg(message_str(SCRIPT_LADDER, 103));
			end
			else begin
				display_msg(message_str(SCRIPT_LADDER, 104));
			end
		end
	end
end