#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure gameover;
procedure do_dialogue;
procedure Critter_Action;
procedure harryleave;
procedure harryend;
procedure harrycbt;
procedure harryturn;
procedure harryextra;
procedure surprise;
procedure harrytime;
procedure harrytime2;
procedure harry00;
procedure harry00a;
procedure harry00b;
procedure harry00_2;
procedure harry00_3;
procedure harry01;
procedure harry02;
procedure harry03;
procedure harry03_2;
procedure harry03_5;
procedure harry04;
procedure harry05;
procedure harry06;
procedure harry07;
procedure harry07b;
procedure harry08;
procedure harry08_2;
procedure harry09;
procedure harry10;
procedure harry11;
procedure harry12;
procedure harry12_2;
procedure harry12_3;
procedure harry13;
procedure harry13_2;
procedure harry14;
procedure harry14_2;
procedure harry15;
procedure harry16;
procedure harry17;
procedure harry18;
procedure harry19;
procedure harry19_2;
procedure harry20;
procedure harry21;
procedure harry22;
procedure harry23;
procedure harry24;
procedure harry25;
procedure harry26;
procedure harry27;
procedure harry200;
procedure harry201;
procedure harry202;
procedure harry203;
procedure harry204;
procedure harry205;
procedure harry206;
procedure harry207;
procedure harry300;
procedure harry301;
procedure harry302;
procedure harry303;
procedure harry304;
procedure harry305;
procedure harry306;
procedure harry307;
procedure harry308;
procedure pickup_p_proc;
procedure harryxxx;

variable Hostile;
variable init_teams;
variable noevent;
variable loopcount;

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 (not(init_teams)) then begin
    critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 34);
    critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_SUPER_MUTANT_NECRO);
    set_local_var(5, 0);
    init_teams := 1;
  end
  if (script_action == talk_proc) then begin
    if (global_var(GVAR_DESTROY_MASTER_2) == 0) then begin
      call do_dialogue;
    end
    else begin
      display_msg(message_str(SCRIPT_HARRY, 193));
    end
  end
  else begin
    if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
      script_overrides;
      display_msg(message_str(SCRIPT_HARRY, 100));
    end
    else begin
      if (script_action == timed_event_proc) then begin
        if (obj_can_see_obj(self_obj, dude_obj)) then begin
          if (fixed_param == 1) then begin
            call harry07b;
          end
          else begin
            if (fixed_param == 2) then begin
              call harry21;
            end
          end
        end
      end
      else begin
        if (script_action == pickup_proc) then begin
          call pickup_p_proc;
        end
        else begin
          if (script_action == critter_proc) then begin
            if (obj_can_see_obj(self_obj, dude_obj) and (tile_distance_objs(self_obj, dude_obj) < 8)) then begin
              if (local_var(4) == 0) then begin
                dialogue_system_enter;
              end
              else begin
                call Critter_Action;
              end
            end
            else begin
              call Critter_Action;
            end
          end
          else begin
            if (script_action == destroy_proc) then begin
              set_global_var(GVAR_SUPER_MUTANTS_KILLED, global_var(GVAR_SUPER_MUTANTS_KILLED) + 1);
              if (global_var(GVAR_SUPER_MUTANTS_KILLED) > global_var(GVAR_MAX_MUTANTS)) then begin
                set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 3);
                set_global_var(GVAR_NECROP_MUTANTS_KILLED, 2);
                set_global_var(GVAR_HUB_FILLER_28, game_time / (10 * 60 * 60 * 24));
              end
              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_BAD_MONSTER, global_var(GVAR_BAD_MONSTER) + 1);
                if ((global_var(GVAR_BAD_MONSTER) % 6) == 0) then begin
                  set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 1);
                end
              end
            end
          end
        end
      end
    end
  end
end

procedure gameover
begin
  gsay_message(SCRIPT_HARRY, 191, NEUTRAL_REACTION);
end

procedure do_dialogue
begin
  call Get_Reaction;
  start_gdialog(SCRIPT_HARRY, self_obj, 4, HEAD_HARRY, BACKGROUND_NECROPOLIS);
  gsay_start;
  if (local_var(4)) then begin
    if (local_var(1) >= 2) then begin
      call harry19;
    end
    else begin
      call harry11;
    end
  end
  else begin
    set_local_var(4, 1);
    if (global_var(GVAR_VATS_BLOWN)) then begin
      call harry26;
    end
    else begin
      if (global_var(GVAR_PLAYER_CAPTURED) == 1) then begin
        call harry23;
      end
      else begin
        if (global_var(GVAR_SUPER_MUTANTS_KILLED) > 0) then begin
          call harry18;
        end
        else begin
          if ((local_var(1) >= 2) and (Hostile == 0)) then begin
            if (is_success(do_check(dude_obj, 3, 0)) and (dude_is_female)) then begin
              call harry12;
            end
            else begin
              call harry00;
            end
          end
          else begin
            call harry07;
          end
        end
      end
    end
  end
  gsay_end;
  end_dialogue;
end

procedure Critter_Action
begin
  if (Hostile > 0) then begin
    Hostile := 0;
    attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
  end
  else begin
    if ((global_var(GVAR_DESTROY_MASTER_2) == 1) and (tile_num(self_obj) != 15507)) then begin
      animate_move_obj_to_tile(self_obj, 15507, ANIMATE_WALK);
    end
    else begin
      if ((global_var(GVAR_DESTROY_MASTER_2) == 1) and (tile_num(self_obj) == 15507)) then begin
        set_global_var(GVAR_DESTROY_MASTER_2, 2);
      end
      else begin
        if ((global_var(GVAR_DESTROY_MASTER_2) == 2) and (tile_num(self_obj) != 12536)) then begin
          animate_move_obj_to_tile(self_obj, 12536, ANIMATE_WALK);
        end
        else begin
          if ((tile_num(self_obj) == 12536) and (global_var(GVAR_DESTROY_MASTER_2) == 2)) then begin
            set_obj_visibility(self_obj, 1);
          end
        end
      end
    end
  end
end

procedure harryleave
begin
  set_global_var(GVAR_DESTROY_MASTER_2, 1);
end

procedure harryend
begin
end

procedure harrycbt
begin
  Hostile := 1;
end

procedure harryturn
begin
  Hostile := 1;
end

procedure harryextra
begin
  Hostile := 1;
end

procedure surprise
begin
  Hostile := 1;
end

procedure harrytime
begin
  add_timer_event(self_obj, game_ticks(30), 1);
end

procedure harrytime2
begin
  add_timer_event(self_obj, game_ticks(30), 2);
end

procedure harry00
begin
  gsay_reply(SCRIPT_HARRY, 101);
  giq_option(5, SCRIPT_HARRY, 102, harry00_2, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 103, harry00_3, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 104, harry02, BAD_REACTION);
  giq_option(-3, SCRIPT_HARRY, 105, harry00a, NEUTRAL_REACTION);
end

procedure harry00a
begin
  gsay_reply(SCRIPT_HARRY, 106);
  giq_option(-3, SCRIPT_HARRY, 107, harry00b, NEUTRAL_REACTION);
end

procedure harry00b
begin
  gsay_reply(SCRIPT_HARRY, 108);
  giq_option(-3, SCRIPT_HARRY, 109, harry02, NEUTRAL_REACTION);
end

procedure harry00_2
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -10))) then begin
    call harry01;
  end
  else begin
    call harry02;
  end
end

procedure harry00_3
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call harry20;
  end
  else begin
    call harry02;
  end
end

procedure harry01
begin
  gsay_reply(SCRIPT_HARRY, 110);
  giq_option(5, SCRIPT_HARRY, 111, harry02, NEUTRAL_REACTION);
  giq_option(5, SCRIPT_HARRY, 112, harry04, NEUTRAL_REACTION);
end

procedure harry02
begin
  gsay_reply(SCRIPT_HARRY, 113);
  giq_option(4, SCRIPT_HARRY, 114, harry03, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 115, harrycbt, BAD_REACTION);
end

procedure harry03
begin
  gsay_reply(SCRIPT_HARRY, 116);
  giq_option(4, SCRIPT_HARRY, 117, harry03_2, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 118, harry03_5, NEUTRAL_REACTION);
end

procedure harry03_2
begin
  if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
    call harry04;
  end
  else begin
    call harry05;
  end
end

procedure harry03_5
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -20))) then begin
    call harry06;
  end
  else begin
    call harry07;
  end
end

procedure harry04
begin
  gsay_reply(SCRIPT_HARRY, 119);
  giq_option(4, SCRIPT_HARRY, 120, harry08, NEUTRAL_REACTION);
  if (global_var(GVAR_VATS_BLOWN) != 1) then begin
    giq_option(4, SCRIPT_HARRY, 121, harryxxx, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_HARRY, 122, harryturn, NEUTRAL_REACTION);
end

procedure harry05
begin
  gsay_reply(SCRIPT_HARRY, 123);
  if (global_var(GVAR_VATS_BLOWN) != 1) then begin
    giq_option(4, SCRIPT_HARRY, 192, harryxxx, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_HARRY, 191, harrycbt, NEUTRAL_REACTION);
end

procedure harry06
begin
  gsay_message(SCRIPT_HARRY, 124, NEUTRAL_REACTION);
  call harrytime;
end

procedure harry07
begin
  gsay_message(SCRIPT_HARRY, 125, BAD_REACTION);
  call harrycbt;
end

procedure harry07b
begin
  float_msg(self_obj, message_str(SCRIPT_HARRY, 125), FLOAT_MSG_RED);
  call harrycbt;
end

procedure harry08
begin
  gsay_reply(SCRIPT_HARRY, 126);
  giq_option(4, SCRIPT_HARRY, 127, harry09, BAD_REACTION);
  giq_option(4, SCRIPT_HARRY, 128, harry08_2, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 129, harry07, NEUTRAL_REACTION);
end

procedure harry08_2
begin
  if (is_success(roll_vs_skill(dude_obj, 14, -30))) then begin
    call harry10;
  end
  else begin
    call harry09;
  end
end

procedure harry09
begin
  gsay_message(SCRIPT_HARRY, 130, BAD_REACTION);
  call harrycbt;
end

procedure harry10
begin
  gsay_message(SCRIPT_HARRY, 131, NEUTRAL_REACTION);
  call harrytime;
end

procedure harry11
begin
  gsay_message(SCRIPT_HARRY, 132, BAD_REACTION);
  call harrycbt;
end

procedure harry12
begin
  gsay_reply(SCRIPT_HARRY, 133);
  giq_option(4, SCRIPT_HARRY, 134, harry12_2, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 135, harry12_3, NEUTRAL_REACTION);
  giq_option(-3, SCRIPT_HARRY, 105, harry00a, NEUTRAL_REACTION);
end

procedure harry12_2
begin
  if (is_success(do_check(dude_obj, 3, 1))) then begin
    call harry13;
  end
  else begin
    call harry14;
  end
end

procedure harry12_3
begin
  if (is_success(do_check(dude_obj, 3, 2))) then begin
    call harry17;
  end
  else begin
    call harry14;
  end
end

procedure harry13
begin
  gsay_reply(SCRIPT_HARRY, 136);
  giq_option(4, SCRIPT_HARRY, 137, harry13_2, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 138, harry14, NEUTRAL_REACTION);
end

procedure harry13_2
begin
  if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
    call harry16;
  end
  else begin
    call harry14;
  end
end

procedure harry14
begin
  gsay_reply(SCRIPT_HARRY, 139);
  if (global_var(GVAR_VATS_BLOWN) != 1) then begin
    giq_option(4, SCRIPT_HARRY, 121, harryxxx, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_HARRY, 140, harry14_2, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 141, harryturn, BAD_REACTION);
end

procedure harry14_2
begin
  if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
    call harry15;
  end
  else begin
    call harry07;
  end
end

procedure harry15
begin
  gsay_message(SCRIPT_HARRY, 142, NEUTRAL_REACTION);
  call harrytime;
end

procedure harry16
begin
  gsay_message(SCRIPT_HARRY, 143, NEUTRAL_REACTION);
  call harrytime;
end

procedure harry17
begin
  gsay_reply(SCRIPT_HARRY, 144);
  giq_option(4, SCRIPT_HARRY, 145, surprise, BAD_REACTION);
  giq_option(4, SCRIPT_HARRY, 146, harry14, NEUTRAL_REACTION);
end

procedure harry18
begin
  gsay_message(SCRIPT_HARRY, 147, BAD_REACTION);
  call harrycbt;
end

procedure harry19
begin
  gsay_reply(SCRIPT_HARRY, 148);
  if (global_var(GVAR_VATS_BLOWN) != 1) then begin
    giq_option(4, SCRIPT_HARRY, 149, harry22, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_HARRY, 150, harry19_2, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_HARRY, 151, harrycbt, BAD_REACTION);
  giq_option(-3, SCRIPT_HARRY, 105, harry00a, NEUTRAL_REACTION);
end

procedure harry19_2
begin
  if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
    call harry20;
  end
  else begin
    call harry07;
  end
end

procedure harry20
begin
  gsay_message(SCRIPT_HARRY, 152, NEUTRAL_REACTION);
  call harrytime2;
end

procedure harry21
begin
  float_msg(self_obj, message_str(SCRIPT_HARRY, 153), FLOAT_MSG_RED);
  call harrycbt;
end

procedure harry22
begin
  gsay_message(SCRIPT_HARRY, 154, BAD_REACTION);
  call harryxxx;
end

procedure harry23
begin
  gsay_reply(SCRIPT_HARRY, 155);
  giq_option(5, SCRIPT_HARRY, 156, harry24, NEUTRAL_REACTION);
  if (global_var(GVAR_VATS_BLOWN) != 1) then begin
    giq_option(4, SCRIPT_HARRY, 121, harryxxx, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_HARRY, 157, harry25, BAD_REACTION);
end

procedure harry24
begin
  gsay_message(SCRIPT_HARRY, 158, NEUTRAL_REACTION);
  if (global_var(GVAR_VATS_BLOWN) != 1) then begin
    giq_option(4, SCRIPT_HARRY, 121, harryxxx, NEUTRAL_REACTION);
  end
  giq_option(4, SCRIPT_HARRY, 191, harrycbt, NEUTRAL_REACTION);
end

procedure harry25
begin
  gsay_message(SCRIPT_HARRY, 159, BAD_REACTION);
  call harrycbt;
end

procedure harry26
begin
  gsay_reply(SCRIPT_HARRY, 160);
  giq_option(4, SCRIPT_HARRY, 161, harryturn, BAD_REACTION);
  giq_option(4, SCRIPT_HARRY, 162, harry27, GOOD_REACTION);
  giq_option(-3, SCRIPT_HARRY, 163, harry27, NEUTRAL_REACTION);
end

procedure harry27
begin
  gsay_reply(SCRIPT_HARRY, 164);
  giq_option(4, SCRIPT_HARRY, 165, harryturn, BAD_REACTION);
  giq_option(4, SCRIPT_HARRY, 166, harryleave, NEUTRAL_REACTION);
  giq_option(-3, SCRIPT_HARRY, 167, harryleave, NEUTRAL_REACTION);
end

procedure harry200
begin
  gsay_message(SCRIPT_HARRY, 168, NEUTRAL_REACTION);
end

procedure harry201
begin
  gsay_message(SCRIPT_HARRY, 169, NEUTRAL_REACTION);
end

procedure harry202
begin
  gsay_message(SCRIPT_HARRY, 170, NEUTRAL_REACTION);
end

procedure harry203
begin
  gsay_message(SCRIPT_HARRY, 171, NEUTRAL_REACTION);
end

procedure harry204
begin
  gsay_message(SCRIPT_HARRY, 172, NEUTRAL_REACTION);
end

procedure harry205
begin
  gsay_message(SCRIPT_HARRY, 173, NEUTRAL_REACTION);
end

procedure harry206
begin
  gsay_message(SCRIPT_HARRY, 174, NEUTRAL_REACTION);
end

procedure harry207
begin
  gsay_message(SCRIPT_HARRY, 175, NEUTRAL_REACTION);
end

procedure harry300
begin
  gsay_message(SCRIPT_HARRY, 176, NEUTRAL_REACTION);
end

procedure harry301
begin
  gsay_message(SCRIPT_HARRY, 177, NEUTRAL_REACTION);
end

procedure harry302
begin
  gsay_message(SCRIPT_HARRY, 178, NEUTRAL_REACTION);
end

procedure harry303
begin
  gsay_message(SCRIPT_HARRY, 179, NEUTRAL_REACTION);
end

procedure harry304
begin
  gsay_message(SCRIPT_HARRY, 180, NEUTRAL_REACTION);
end

procedure harry305
begin
  gsay_message(SCRIPT_HARRY, 181, NEUTRAL_REACTION);
end

procedure harry306
begin
  gsay_message(SCRIPT_HARRY, 182, NEUTRAL_REACTION);
end

procedure harry307
begin
  gsay_message(SCRIPT_HARRY, 183, NEUTRAL_REACTION);
end

procedure harry308
begin
  gsay_message(SCRIPT_HARRY, 184, NEUTRAL_REACTION);
end

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

procedure harryxxx
begin
  game_time_advance(game_ticks(2 * 604800));
  set_global_var(GVAR_ENTERING_VATS_HOW, 2);
  load_map(32, 5);
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
