#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_stuff;
procedure coverend;
procedure cover00;
procedure cover01;
procedure cover01a;

variable damage;
variable testa;
variable bonus;
//variable dude_tile;
variable OPEN;


procedure start
begin
variable LVar0 := 0;
  if (script_action == use_proc) then begin
    script_overrides;
    call do_stuff;
  end
end

procedure do_stuff
begin
  OPEN := map_var(local_var(0));
  if (OPEN == 1) then begin
    call cover00;
  end
  else begin
    call cover01;
  end
end

procedure coverend
begin
end

procedure cover00
begin
  set_map_var(local_var(0), 0);
  display_msg(message_str(SCRIPT_COVER, 100));
  //dude_tile := tile_num(dude_obj);
end

procedure cover01
begin
  bonus := 3 - local_var(0);
  testa := do_check(dude_obj, 0, bonus);
  call cover01a;
end

procedure cover01a
begin
  if (is_success(testa)) then begin
    set_local_var(0, 0);
    set_map_var(local_var(0), 1);
    display_msg(message_str(SCRIPT_COVER, 101));
  end
  else begin
    set_local_var(0, local_var(0) + 1);
    if (is_critical(testa)) then begin
      display_msg(message_str(SCRIPT_COVER, 102));
      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_COVER, 103));
    end
  end
end