#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure combat;
procedure critter_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure special_end;
procedure raejoin;
procedure raetym;
procedure rae00;
procedure rae00a;
procedure rae00b;
procedure rae01;
procedure rae01a;
procedure rae02;
procedure rae03;
procedure rae03a;
procedure rae03b;
procedure rae03c;
procedure rae04;
procedure rae04a;
procedure rae04b;
procedure rae04c;
procedure rae05;
procedure rae05a;
procedure rae05b;
procedure rae06;
procedure rae06a;
procedure rae06b;
procedure rae06c;
procedure rae07;
procedure rae07a;
procedure rae07b;
procedure rae07c;
procedure rae08;
procedure rae08a;
procedure rae08b;
procedure rae08c;
procedure rae09;
procedure rae10;
procedure rae10a;
procedure rae11;
procedure rae11a;
procedure rae11b;
procedure rae12;
procedure rae13;
procedure rae13a;
procedure rae13b;
procedure rae13c;
procedure rae14;
procedure dialog_end;

variable hostile1;
variable Only_Once := 1;
variable movie;

procedure Get_Reaction;
procedure React_To_Level;
procedure Level_To_React;
procedure Up_React;
procedure Down_React;
procedure Bottom_React;
procedure Top_React;
procedure Big_Up_React;
procedure Big_Down_React;
procedure Up_React_Level;
procedure Down_React_Level;
procedure Goodbyes;

variable exit_line;


procedure start
begin
if (Only_Once) then begin
    Only_Once := 0;
    critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 44);
  end
  if (script_action == look_at_proc) then begin
    call look_at_p_proc;
  end
  else begin
    if (script_action == pickup_proc) then begin
      call pickup_p_proc;
    end
    else begin
      if (script_action == talk_proc) then begin
        call talk_p_proc;
      end
      else begin
        if (script_action == timed_event_proc) then begin
          if (tile_distance_objs(dude_obj, self_obj) < 6) then begin
            call combat;
          end
        end
        else begin
          if (script_action == critter_proc) then begin
            call critter_p_proc;
          end
          else begin
            if (script_action == destroy_proc) then begin
              call destroy_p_proc;
            end
          end
        end
      end
    end
  end
end

procedure combat
begin
  hostile1 := 1;
end

procedure critter_p_proc
begin
  if (hostile1) then begin
    hostile1 := 0;
    attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
  end
end

procedure pickup_p_proc
begin
  if (source_obj == dude_obj) then begin
    hostile1 := 1;
  end
end

procedure talk_p_proc
begin
  call Get_Reaction;
  start_gdialog(SCRIPT_GIDEON, self_obj, 4, -1, -1);
  gsay_start;
  if (local_var(4) == 0) then begin
    call rae00;
  end
  else begin
    call rae01;
  end
  set_local_var(4, 1);
  gsay_end;
  end_dialogue;
  if (movie == 1) then begin
    play_gmovie(MOVIE_CATHEXP);
    metarule(13, 0);
  end
end

procedure destroy_p_proc
begin
  if (source_obj == dude_obj) then begin
    if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_GOOD_MONSTER) > (2 * global_var(GVAR_BAD_MONSTER))) or (global_var(GVAR_BERSERKER_REPUTATION) == 1))) then begin
      set_global_var(GVAR_BERSERKER_REPUTATION, 1);
      set_global_var(GVAR_CHAMPION_REPUTATION, 0);
    end
    if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_BAD_MONSTER) > (3 * global_var(GVAR_GOOD_MONSTER))) or (global_var(GVAR_CHAMPION_REPUTATION) == 1))) then begin
      set_global_var(GVAR_CHAMPION_REPUTATION, 1);
      set_global_var(GVAR_BERSERKER_REPUTATION, 0);
    end
    set_global_var(GVAR_GOOD_MONSTER, global_var(GVAR_GOOD_MONSTER) + 1);
    if ((global_var(GVAR_GOOD_MONSTER) % 2) == 0) then begin
      set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) - 1);
    end
  end
end

procedure look_at_p_proc
begin
  script_overrides;
  display_msg(message_str(SCRIPT_GIDEON, 100));
end

procedure special_end
begin
  movie := 1;
end

procedure raejoin
begin
end

procedure raetym
begin
  add_timer_event(self_obj, game_ticks(15), 1);
end

procedure rae00
begin
  gsay_reply(SCRIPT_GIDEON, 102);
  giq_option(7, SCRIPT_GIDEON, 103, rae02, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 104, rae00a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 105, rae00b, NEUTRAL_REACTION);
  if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_GOOD_MONSTER) > (2 * global_var(GVAR_BAD_MONSTER))) or (global_var(GVAR_BERSERKER_REPUTATION) == 1))) then begin
    giq_option(4, SCRIPT_GIDEON, 106, combat, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_GIDEON, 107, dialog_end, NEUTRAL_REACTION);
  giq_option(-3, SCRIPT_GIDEON, 108, dialog_end, NEUTRAL_REACTION);
end

procedure rae00a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call rae08;
  end
  else begin
    call rae12;
  end
end

procedure rae00b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae02;
  end
  else begin
    call rae12;
  end
end

procedure rae01
begin
  gsay_reply(SCRIPT_GIDEON, 109);
  giq_option(7, SCRIPT_GIDEON, 110, rae01a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 111, dialog_end, NEUTRAL_REACTION);
  if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_GOOD_MONSTER) > (2 * global_var(GVAR_BAD_MONSTER))) or (global_var(GVAR_BERSERKER_REPUTATION) == 1))) then begin
    giq_option(4, SCRIPT_GIDEON, 112, combat, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_GIDEON, 113, rae02, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 114, dialog_end, NEUTRAL_REACTION);
end

procedure rae01a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae03;
  end
  else begin
    call rae05;
  end
end

procedure rae02
begin
  gsay_reply(SCRIPT_GIDEON, 115);
  giq_option(8, SCRIPT_GIDEON, 116, rae03, NEUTRAL_REACTION);
  giq_option(7, SCRIPT_GIDEON, 117, rae03, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 118, rae04, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 119, rae08, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 120, rae05, NEUTRAL_REACTION);
end

procedure rae03
begin
  gsay_reply(SCRIPT_GIDEON, 121);
  giq_option(8, SCRIPT_GIDEON, 122, rae04, NEUTRAL_REACTION);
  giq_option(7, SCRIPT_GIDEON, 123, rae03a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 124, rae03b, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 125, rae03c, NEUTRAL_REACTION);
end

procedure rae03a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call rae04;
  end
  else begin
    call rae08;
  end
end

procedure rae03b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -30))) then begin
    call rae05;
  end
  else begin
    call rae08;
  end
end

procedure rae03c
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -30))) then begin
    call rae08;
  end
  else begin
    call rae12;
  end
end

procedure rae04
begin
  gsay_reply(SCRIPT_GIDEON, 126);
  giq_option(8, SCRIPT_GIDEON, 127, rae04a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 128, rae12, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 129, rae04b, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 130, rae04c, NEUTRAL_REACTION);
end

procedure rae04a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call rae05;
  end
  else begin
    call rae08;
  end
end

procedure rae04b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae05;
  end
  else begin
    call rae08;
  end
end

procedure rae04c
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae08;
  end
  else begin
    call rae12;
  end
end

procedure rae05
begin
  gsay_reply(SCRIPT_GIDEON, 131);
  giq_option(9, SCRIPT_GIDEON, 132, rae06, NEUTRAL_REACTION);
  giq_option(8, SCRIPT_GIDEON, 133, rae05a, NEUTRAL_REACTION);
  if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_GOOD_MONSTER) > (2 * global_var(GVAR_BAD_MONSTER))) or (global_var(GVAR_BERSERKER_REPUTATION) == 1))) then begin
    giq_option(4, SCRIPT_GIDEON, 134, combat, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_GIDEON, 135, rae05b, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 136, rae07, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 137, dialog_end, NEUTRAL_REACTION);
end

procedure rae05a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call rae08;
  end
  else begin
    call rae12;
  end
end

procedure rae05b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -25))) then begin
    call rae06;
  end
  else begin
    call rae12;
  end
end

procedure rae06
begin
  gsay_reply(SCRIPT_GIDEON, 138);
  giq_option(9, SCRIPT_GIDEON, 139, rae07, NEUTRAL_REACTION);
  giq_option(7, SCRIPT_GIDEON, 140, rae06a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 141, rae06b, NEUTRAL_REACTION);
  if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_GOOD_MONSTER) > (2 * global_var(GVAR_BAD_MONSTER))) or (global_var(GVAR_BERSERKER_REPUTATION) == 1))) then begin
    giq_option(4, SCRIPT_GIDEON, 142, rae06c, NEUTRAL_REACTION);
  end
end

procedure rae06a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call rae11;
  end
  else begin
    call rae12;
  end
end

procedure rae06b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae11;
  end
  else begin
    call rae08;
  end
end

procedure rae06c
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -25))) then begin
    call rae09;
  end
  else begin
    call rae12;
  end
end

procedure rae07
begin
  gsay_reply(SCRIPT_GIDEON, 143);
  giq_option(9, SCRIPT_GIDEON, 144, rae11, NEUTRAL_REACTION);
  giq_option(7, SCRIPT_GIDEON, 145, rae08, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 146, rae07a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 147, rae07b, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 148, rae07c, NEUTRAL_REACTION);
end

procedure rae07a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call rae08;
  end
  else begin
    call rae12;
  end
end

procedure rae07b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae10;
  end
  else begin
    call rae12;
  end
end

procedure rae07c
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call dialog_end;
  end
  else begin
    call rae12;
  end
end

procedure rae08
begin
  gsay_reply(SCRIPT_GIDEON, 149);
  giq_option(8, SCRIPT_GIDEON, 150, rae13, NEUTRAL_REACTION);
  giq_option(7, SCRIPT_GIDEON, 151, rae08a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 152, rae08b, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 153, rae08c, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 154, dialog_end, NEUTRAL_REACTION);
end

procedure rae08a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call rae09;
  end
  else begin
    call rae10;
  end
end

procedure rae08b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae11;
  end
  else begin
    call rae12;
  end
end

procedure rae08c
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -30))) then begin
    call rae13;
  end
  else begin
    call rae12;
  end
end

procedure rae09
begin
  gsay_message(SCRIPT_GIDEON, 155, NEUTRAL_REACTION);
  call raejoin;
end

procedure rae10
begin
  gsay_reply(SCRIPT_GIDEON, 156);
  giq_option(4, SCRIPT_GIDEON, 157, dialog_end, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 158, rae10a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 159, rae11, NEUTRAL_REACTION);
end

procedure rae10a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -30))) then begin
    call rae09;
  end
  else begin
    call rae12;
  end
end

procedure rae11
begin
  gsay_reply(SCRIPT_GIDEON, 160);
  giq_option(9, SCRIPT_GIDEON, 161, rae13, NEUTRAL_REACTION);
  giq_option(7, SCRIPT_GIDEON, 162, rae11a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 163, rae11b, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 164, dialog_end, NEUTRAL_REACTION);
end

procedure rae11a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae13;
  end
  else begin
    call rae08;
  end
end

procedure rae11b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -30))) then begin
    call rae13;
  end
  else begin
    call rae12;
  end
end

procedure rae12
begin
  gsay_message(SCRIPT_GIDEON, 165, NEUTRAL_REACTION);
  call raetym;
end

procedure rae13
begin
  gsay_reply(SCRIPT_GIDEON, 166);
  giq_option(9, SCRIPT_GIDEON, 167, rae14, NEUTRAL_REACTION);
  giq_option(7, SCRIPT_GIDEON, 168, rae13a, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 169, rae13b, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 170, dialog_end, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 171, rae13c, NEUTRAL_REACTION);
end

procedure rae13a
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae14;
  end
  else begin
    call rae09;
  end
end

procedure rae13b
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call rae09;
  end
  else begin
    call rae12;
  end
end

procedure rae13c
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -30))) then begin
    call rae14;
  end
  else begin
    call rae12;
  end
end

procedure rae14
begin
  gsay_reply(SCRIPT_GIDEON, 172);
  giq_option(4, SCRIPT_GIDEON, 173, special_end, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_GIDEON, 174, rae09, NEUTRAL_REACTION);
end

procedure dialog_end
begin
end

procedure Get_Reaction
begin
  if (local_var(2) == 0) then begin
    set_local_var(0, 50);
    set_local_var(1, 2);
    set_local_var(2, 1);
    set_local_var(0, local_var(0) + (5 * get_critter_stat(dude_obj, 3)) - 25);
    set_local_var(0, local_var(0) + (10 * has_trait(0, dude_obj, 10)));
    if (has_trait(0, dude_obj, 39)) then begin
      if (global_var(GVAR_PLAYER_REPUTATION) > 0) then begin
        set_local_var(0, local_var(0) + global_var(GVAR_PLAYER_REPUTATION));
      end
      else begin
        set_local_var(0, local_var(0) - global_var(GVAR_PLAYER_REPUTATION));
      end
    end
    else begin
      if (local_var(3) == 1) then begin
        set_local_var(0, local_var(0) - global_var(GVAR_PLAYER_REPUTATION));
      end
      else begin
        set_local_var(0, local_var(0) + global_var(GVAR_PLAYER_REPUTATION));
      end
    end
    if (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) then begin
      set_local_var(0, local_var(0) - 30);
    end
    if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_BAD_MONSTER) > (3 * global_var(GVAR_GOOD_MONSTER))) or (global_var(GVAR_CHAMPION_REPUTATION) == 1))) then begin
      set_local_var(0, local_var(0) + 20);
    end
    if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_GOOD_MONSTER) > (2 * global_var(GVAR_BAD_MONSTER))) or (global_var(GVAR_BERSERKER_REPUTATION) == 1))) then begin
      set_local_var(0, local_var(0) - 20);
    end
    call React_To_Level;
  end
end

procedure React_To_Level
begin
  if (local_var(0) <= 25) then begin
    set_local_var(1, 1);
  end
  else begin
    if (local_var(0) <= 75) then begin
      set_local_var(1, 2);
    end
    else begin
      set_local_var(1, 3);
    end
  end
end

procedure Level_To_React
begin
  if (local_var(1) == 1) then begin
    set_local_var(0, random(1, 25));
  end
  else begin
    if (local_var(1) == 2) then begin
      set_local_var(0, random(26, 75));
    end
    else begin
      set_local_var(0, random(76, 100));
    end
  end
end

procedure Up_React
begin
  set_local_var(0, local_var(0) + 10);
  call React_To_Level;
end

procedure Down_React
begin
  set_local_var(0, local_var(0) - 10);
  call React_To_Level;
end

procedure Bottom_React
begin
  set_local_var(1, 1);
  set_local_var(0, 1);
end

procedure Top_React
begin
  set_local_var(0, 100);
  set_local_var(1, 3);
end

procedure Big_Up_React
begin
  set_local_var(0, local_var(0) + 25);
  call React_To_Level;
end

procedure Big_Down_React
begin
  set_local_var(0, local_var(0) - 25);
  call React_To_Level;
end

procedure Up_React_Level
begin
  set_local_var(1, local_var(1) + 1);
  if (local_var(1) > 3) then begin
    set_local_var(1, 3);
  end
  call Level_To_React;
end

procedure Down_React_Level
begin
  set_local_var(1, local_var(1) - 1);
  if (local_var(1) < 1) then begin
    set_local_var(1, 1);
  end
  call Level_To_React;
end

procedure Goodbyes
begin
  exit_line := message_str(SCRIPT_MODREACT, random(100, 105));
end