#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure pre_dialogue;
procedure mutan00;
procedure mutan01;
procedure mutan02;
procedure mutan03;
procedure mutan03a;
procedure mutan04;
procedure mutan05;
procedure mutan05a;
procedure mutan05b;
procedure mutan06;
procedure mutan07;
procedure mutan08;
procedure mutan08a;
procedure mutan08b;
procedure mutan09;
procedure mutan10;
procedure mutan11;
procedure mutan11a;
procedure mutan12;
procedure mutan13;
procedure mutan13a;
procedure mutan13b;
procedure mutan14;
procedure mutan15;
procedure mutanend;
procedure mutancbt;

variable HOSTILE;
variable only_once := 1;
variable Weapons;
variable DISGUISED;
variable again;
variable rndx;

import variable signal_mutants;

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, 34);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_SUPER_MUTANT_AGGRESSIVE);
	end
	else begin
		if (script_action == damage_proc) then begin
			if (global_var(GVAR_ENEMY_VAULT_13) == 0) then begin
				set_global_var(GVAR_ENEMY_VAULT_13, 1);
			end
		end
		else begin
			if (script_action == talk_proc) then begin
				call pre_dialogue;
			end
			else begin
				if (script_action == pickup_proc) then begin
					HOSTILE := 1;
				end
			end
		end
	end
	if (script_action == critter_proc) then begin
		if (HOSTILE) then begin
			HOSTILE := 0;
			attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
		end
		else begin
			if (signal_mutants == 1) then begin
				signal_mutants := 0;
				call mutancbt;
			end
			else begin
				if (obj_can_see_obj(self_obj, dude_obj)) then begin
					if ((obj_item_subtype(critter_inven_obj(dude_obj, 1)) == 3) or (obj_item_subtype(critter_inven_obj(dude_obj, 2)) == 3)) then begin
						if (Weapons == 0) then begin
							Weapons := 1;
							if (tile_distance_objs(self_obj, dude_obj) < 6) then begin
								dialogue_system_enter;
							end
						end
					end
					DISGUISED := 0;
					if (obj_pid(critter_inven_obj(dude_obj, 0)) == 113) then begin
						if (metarule(16, 0) > 1) then begin
							DISGUISED := 0;
						end
						else begin
							DISGUISED := 1;
						end
					end
					if ((DISGUISED == 0) and (again == 0)) then begin
						if (tile_distance_objs(self_obj, dude_obj) < 6) then begin
							again := 1;
							dialogue_system_enter;
						end
					end
				end
			end
		end
	end
	else begin
		if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
			script_overrides;
		end
		else begin
			if (script_action == destroy_proc) then 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
		end
	end
end

procedure do_dialogue
begin
	set_local_var(3, 1);
	call Get_Reaction;
	start_gdialog(SCRIPT_GENMUTAN, self_obj, 4, -1, -1);
	gsay_start;
	if (Weapons == 1) then begin
		call mutan01;
	end
	else begin
		if (local_var(4)) then begin
			call mutan13;
		end
		else begin
			set_local_var(4, 1);
			call mutan05;
		end
	end
	gsay_end;
	end_dialogue;
end

procedure pre_dialogue
begin
	if (obj_pid(critter_inven_obj(dude_obj, 0)) == 113) then begin
		if (metarule(16, 0) > 1) then begin
			DISGUISED := 0;
		end
		else begin
			DISGUISED := 1;
		end
	end
	if (Weapons == 1) then begin
		if (DISGUISED) then begin
			call do_dialogue;
		end
		else begin
			call mutan00;
		end
	end
	else begin
		if (DISGUISED) then begin
			call do_dialogue;
		end
		else begin
			call mutan00;
		end
	end
end

procedure mutan00
begin
	rndx := random(1, 8);
	if (rndx < 5) then begin
		if (rndx == 1) then begin
			float_msg(self_obj, message_str(SCRIPT_GENMUTAN, 100), FLOAT_MSG_RED);
		end
		else begin
			if (rndx == 2) then begin
				float_msg(self_obj, message_str(SCRIPT_GENMUTAN, 101), FLOAT_MSG_RED);
			end
			else begin
				if (rndx == 3) then begin
					float_msg(self_obj, message_str(SCRIPT_GENMUTAN, 102), FLOAT_MSG_RED);
				end
				else begin
					if (rndx == 4) then begin
						float_msg(self_obj, message_str(SCRIPT_GENMUTAN, 103), FLOAT_MSG_RED);
					end
				end
			end
		end
	end
	call mutancbt;
end

procedure mutan01
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GENMUTAN, 104);
	end
	else begin
		gsay_reply(SCRIPT_GENMUTAN, 105);
	end
	giq_option(4, SCRIPT_GENMUTAN, 107, mutan02, BAD_REACTION);
	giq_option(6, SCRIPT_GENMUTAN, 108, mutan03, NEUTRAL_REACTION);
	giq_option(9, SCRIPT_GENMUTAN, 109, mutan04, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_GENMUTAN, 106, mutan02, BAD_REACTION);
end

procedure mutan02
begin
	gsay_message(SCRIPT_GENMUTAN, 110, BAD_REACTION);
	call mutancbt;
end

procedure mutan03
begin
	gsay_reply(SCRIPT_GENMUTAN, 111);
	giq_option(6, SCRIPT_GENMUTAN, 112, mutan03a, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_GENMUTAN, 113, mutancbt, BAD_REACTION);
end

procedure mutan03a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call mutan04;
	end
	else begin
		call mutan02;
	end
end

procedure mutan04
begin
	gsay_message(SCRIPT_GENMUTAN, 114, NEUTRAL_REACTION);
	set_local_var(5, 1);
end

procedure mutan05
begin
	if (dude_is_male) then begin
		gsay_reply(SCRIPT_GENMUTAN, 115);
	end
	else begin
		gsay_reply(SCRIPT_GENMUTAN, 116);
	end
	giq_option(4, SCRIPT_GENMUTAN, 118, mutan05a, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_GENMUTAN, 119, mutan05b, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_GENMUTAN, 106, mutan06, NEUTRAL_REACTION);
end

procedure mutan05a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call mutan08;
	end
	else begin
		call mutan07;
	end
end

procedure mutan05b
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call mutan10;
	end
	else begin
		call mutan11;
	end
end

procedure mutan06
begin
	gsay_message(SCRIPT_GENMUTAN, 120, NEUTRAL_REACTION);
	set_local_var(5, 1);
end

procedure mutan07
begin
	gsay_message(SCRIPT_GENMUTAN, 121, BAD_REACTION);
	call mutancbt;
end

procedure mutan08
begin
	gsay_reply(SCRIPT_GENMUTAN, 122);
	giq_option(4, SCRIPT_GENMUTAN, 123, mutan08a, 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_GENMUTAN, 124, mutancbt, BAD_REACTION);
	end
	giq_option(7, SCRIPT_GENMUTAN, 125, mutan08b, NEUTRAL_REACTION);
end

procedure mutan08a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call mutan04;
	end
	else begin
		call mutan07;
	end
end

procedure mutan08b
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 20))) then begin
		call mutan04;
	end
	else begin
		call mutan09;
	end
end

procedure mutan09
begin
	gsay_message(SCRIPT_GENMUTAN, 126, BAD_REACTION);
	call mutancbt;
end

procedure mutan10
begin
	gsay_message(SCRIPT_GENMUTAN, 127, NEUTRAL_REACTION);
	set_local_var(5, 1);
end

procedure mutan11
begin
	gsay_reply(SCRIPT_GENMUTAN, 128);
	giq_option(6, SCRIPT_GENMUTAN, 129, mutan11a, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_GENMUTAN, 130, mutancbt, BAD_REACTION);
end

procedure mutan11a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call mutan12;
	end
	else begin
		call mutan09;
	end
end

procedure mutan12
begin
	gsay_message(SCRIPT_GENMUTAN, 131, NEUTRAL_REACTION);
	set_local_var(5, 1);
end

procedure mutan13
begin
	gsay_reply(SCRIPT_GENMUTAN, 132);
	giq_option(4, SCRIPT_GENMUTAN, 134, mutancbt, BAD_REACTION);
	giq_option(4, SCRIPT_GENMUTAN, 135, mutan13a, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_GENMUTAN, 136, mutan13b, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_GENMUTAN, 133, mutan14, BAD_REACTION);
end

procedure mutan13a
begin
	if (is_success(do_check(dude_obj, 6, 0))) then begin
		call mutan12;
	end
	else begin
		call mutan09;
	end
end

procedure mutan13b
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 20))) then begin
		call mutan10;
	end
	else begin
		call mutan11;
	end
end

procedure mutan14
begin
	gsay_message(SCRIPT_GENMUTAN, 137, BAD_REACTION);
	call mutancbt;
end

procedure mutan15
begin
	rndx := random(1, 3);
	if (rndx == 1) then begin
		gsay_message(SCRIPT_GENMUTAN, 138, NEUTRAL_REACTION);
	end
	else begin
		if (rndx == 2) then begin
			gsay_message(SCRIPT_GENMUTAN, 139, NEUTRAL_REACTION);
		end
		else begin
			if (rndx == 3) then begin
				gsay_message(SCRIPT_GENMUTAN, 140, NEUTRAL_REACTION);
			end
		end
	end
end

procedure mutanend
begin
end

procedure mutancbt
begin
	HOSTILE := 1;
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