#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 goto0;
procedure goto1;
procedure goto2;
procedure goto3;
procedure goto4;
procedure goto5;
procedure goto6;
procedure goto7;
procedure combat;
procedure gotoend;

variable rndx;
variable Hostile;
variable ONLY_ONCE := 1;


procedure start
begin
	if (ONLY_ONCE) then begin
		ONLY_ONCE := 0;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 34);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_SUPER_MUTANT_SGT);
	end
	else begin
		if (script_action == critter_proc) then begin
			call critter_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

procedure critter_p_proc
begin
	if (Hostile) then begin
		Hostile := 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;
	if (rndx == 0) then begin
		rndx := random(100, 109);
	end
	display_msg(message_str(SCRIPT_THSUPMUT, rndx));
end

procedure pickup_p_proc
begin
	Hostile := 1;
end

procedure talk_p_proc
begin
	script_overrides;
	start_gdialog(SCRIPT_THSUPMUT, self_obj, 4, -1, -1);
	gsay_start;
	if (local_var(0)) then begin
		call goto7;
	end
	else begin
		call goto0;
	end
	gsay_end;
	end_dialogue;
end

procedure goto0
begin
	set_local_var(0, 1);
	gsay_reply(SCRIPT_THSUPMUT, 110);
	giq_option(-3, SCRIPT_THSUPMUT, 111, goto1, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_THSUPMUT, 112, combat, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_THSUPMUT, 113, goto2, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_THSUPMUT, 114, goto3, NEUTRAL_REACTION);
end

procedure goto1
begin
	gsay_message(SCRIPT_THSUPMUT, 115, NEUTRAL_REACTION);
	call combat;
end

procedure goto2
begin
	gsay_message(SCRIPT_THSUPMUT, 116, NEUTRAL_REACTION);
	call combat;
end

procedure goto3
begin
	gsay_reply(SCRIPT_THSUPMUT, 117);
	giq_option(6, SCRIPT_THSUPMUT, 118, goto4, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_THSUPMUT, 119, goto6, NEUTRAL_REACTION);
end

procedure goto4
begin
	gsay_reply(SCRIPT_THSUPMUT, 120);
	giq_option(6, SCRIPT_THSUPMUT, 121, combat, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_THSUPMUT, 122, combat, NEUTRAL_REACTION);
	giq_option(8, SCRIPT_THSUPMUT, 123, goto5, NEUTRAL_REACTION);
end

procedure goto5
begin
	gsay_reply(SCRIPT_THSUPMUT, 124);
	giq_option(8, SCRIPT_THSUPMUT, 125, combat, NEUTRAL_REACTION);
	giq_option(8, SCRIPT_THSUPMUT, 126, combat, NEUTRAL_REACTION);
end

procedure goto6
begin
	gsay_message(SCRIPT_THSUPMUT, 127, NEUTRAL_REACTION);
	call combat;
end

procedure goto7
begin
	gsay_message(SCRIPT_THSUPMUT, 128, NEUTRAL_REACTION);
	call combat;
end

procedure combat
begin
	Hostile := 1;
end

procedure gotoend
begin
end