#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure critter_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure ScSupMut0;
procedure ScSupMut1;
procedure ScSupMut2;
procedure ScSupMut3;
procedure combat;

variable herebefore1;
variable hostile1;
variable initialized1;


procedure start
begin
if (not(initialized1)) 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_NORMAL);
    initialized1 := 1;
  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
      else begin
        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
          end
        end
      end
    end
  end
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 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_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

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

procedure pickup_p_proc
begin
  hostile1 := 1;
end

procedure talk_p_proc
begin
  script_overrides;
  if (herebefore1) then begin
    call ScSupMut3;
  end
  else begin
    herebefore1 := 1;
    start_gdialog(SCRIPT_SCSUPMUT, self_obj, 4, -1, -1);
    gsay_start;
    call ScSupMut0;
    gsay_end;
    end_dialogue;
  end
end

procedure ScSupMut0
begin
  gsay_reply(SCRIPT_SCSUPMUT, 101);
  giq_option(-3, SCRIPT_SCSUPMUT, 102, combat, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_SCSUPMUT, 103, combat, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_SCSUPMUT, 104, ScSupMut1, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_SCSUPMUT, 105, combat, NEUTRAL_REACTION);
end

procedure ScSupMut1
begin
  gsay_reply(SCRIPT_SCSUPMUT, 106);
  giq_option(4, SCRIPT_SCSUPMUT, 107, combat, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_SCSUPMUT, 108, ScSupMut2, NEUTRAL_REACTION);
  giq_option(4, SCRIPT_SCSUPMUT, 109, combat, NEUTRAL_REACTION);
end

procedure ScSupMut2
begin
  gsay_message(SCRIPT_SCSUPMUT, 110, NEUTRAL_REACTION);
end

procedure ScSupMut3
begin
  float_msg(self_obj, message_str(SCRIPT_SCSUPMUT, 111), FLOAT_MSG_NORMAL);
end

procedure combat
begin
  hostile1 := 1;
end